Patch_GameScript_RefreshRecipe.cs 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using HarmonyLib;
  2. using GadgetCore.API;
  3. using UnityEngine;
  4. using System.Collections;
  5. namespace RecipeMenuCore.Patches
  6. {
  7. [HarmonyPatch(typeof(GameScript))]
  8. [HarmonyPatch("RefreshRecipe")]
  9. [HarmonyGadget("RecipeMenuCore")]
  10. public static class Patch_GameScript_RefreshRecipe
  11. {
  12. [HarmonyPrefix]
  13. public static bool Prefix(GameScript __instance, int ___craftType, int ___curRecipePage)
  14. {
  15. if (___craftType == 0)
  16. {
  17. __instance.txtRecipeName[0].text = string.Empty + __instance.GetRecipeName0(___curRecipePage);
  18. __instance.txtRecipeUnlocked[0].text = "Page " + (___curRecipePage + 1) + "/" + (6 + Core.pageGearForgeInfoList.Count);
  19. }
  20. else if (___craftType == 1)
  21. {
  22. __instance.txtRecipeName[0].text = string.Empty + __instance.GetRecipeName1(___curRecipePage);
  23. __instance.txtRecipeUnlocked[0].text = "Page " + (___curRecipePage + 1) + "/" + (2 + Core.pageAlchemyStationInfoList.Count);
  24. }
  25. else if (___craftType == 2)
  26. {
  27. __instance.txtRecipeName[0].text = string.Empty + __instance.GetRecipeName2(___curRecipePage);
  28. __instance.txtRecipeUnlocked[0].text = "Page " + (___curRecipePage + 1) + "/" + (6 + Core.pageUltimateForgeInfoList.Count);
  29. }
  30. else if (___craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
  31. {
  32. __instance.txtRecipeName[0].text = string.Empty + __instance.GetRecipeName2(___curRecipePage);
  33. __instance.txtRecipeUnlocked[0].text = "Page " + (___curRecipePage + 1) + "/" + (Core.pageUniversalCrafterInfoList.Count);
  34. }
  35. __instance.txtRecipeUnlocked[0].gameObject.GetComponent<Animation>().Play();
  36. __instance.txtRecipeName[0].gameObject.GetComponent<Animation>().Play();
  37. __instance.txtRecipeName[1].text = __instance.txtRecipeName[0].text;
  38. __instance.txtRecipeUnlocked[1].text = __instance.txtRecipeUnlocked[0].text;
  39. if ((___craftType != 0 || (___curRecipePage <= 5 && Core.pageGearForgeInfoListVanilla[___curRecipePage] == null))
  40. && (___craftType != 1 || (___curRecipePage <= 1 && Core.pageAlchemyStationInfoListVanilla[___curRecipePage] == null))
  41. && (___craftType != 2 || (___curRecipePage <= 5 && Core.pageUltimateForgeInfoListVanilla[___curRecipePage] == null))
  42. && (___craftType != MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID()))
  43. {
  44. __instance.menuRecipe.GetComponent<Renderer>().material = (Material)Resources.Load(string.Concat(new object[] { "mat/r", ___curRecipePage, "t", ___craftType }));
  45. }
  46. else
  47. {
  48. if (___craftType == 0)
  49. {
  50. var page = ___curRecipePage >= 6 ? Core.pageGearForgeInfoList[___curRecipePage - 6] : Core.pageGearForgeInfoListVanilla[___curRecipePage];
  51. __instance.txtRecipeName[0].text = page.Title;
  52. __instance.txtRecipeName[1].text = __instance.txtRecipeName[0].text;
  53. __instance.menuRecipe.GetComponent<Renderer>().material = page.Mat;
  54. }
  55. else if (___craftType == 1)
  56. {
  57. var page = ___curRecipePage >= 2 ? Core.pageAlchemyStationInfoList[___curRecipePage - 2] : Core.pageAlchemyStationInfoListVanilla[___curRecipePage];
  58. __instance.txtRecipeName[0].text = page.Title;
  59. __instance.txtRecipeName[1].text = __instance.txtRecipeName[0].text;
  60. __instance.menuRecipe.GetComponent<Renderer>().material = page.Mat;
  61. }
  62. else if (___craftType == 2)
  63. {
  64. var page = ___curRecipePage >= 6 ? Core.pageUltimateForgeInfoList[___curRecipePage - 6] : Core.pageUltimateForgeInfoListVanilla[___curRecipePage];
  65. __instance.txtRecipeName[0].text = page.Title;
  66. __instance.txtRecipeName[1].text = __instance.txtRecipeName[0].text;
  67. __instance.menuRecipe.GetComponent<Renderer>().material = page.Mat;
  68. }
  69. else if (___craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
  70. {
  71. var page = Core.pageUniversalCrafterInfoList[___curRecipePage];
  72. __instance.txtRecipeName[0].text = page.Title;
  73. __instance.txtRecipeName[1].text = __instance.txtRecipeName[0].text;
  74. __instance.menuRecipe.GetComponent<Renderer>().material = page.Mat;
  75. }
  76. }
  77. __instance.RefreshRecipeUnlock();
  78. return false;
  79. }
  80. [HarmonyPostfix]
  81. [HarmonyAfter("URP.URP.gadget")]
  82. public static void Postfix(GameScript __instance, int ___curRecipePage, int ___craftType)
  83. {
  84. if (___curRecipePage == 1 && ___craftType == 1 && Core.pageAlchemyStationInfoListVanilla[1] != null)
  85. {
  86. var page = Core.pageAlchemyStationInfoListVanilla[1];
  87. __instance.menuRecipe.GetComponent<Renderer>().material = page.Mat;
  88. }
  89. }
  90. }
  91. }