Patch_GameScript_RefreshRecipe.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. else if (CraftTypeHelper.IsCraftTypeRegisteredAsCustom(___craftType))
  36. {
  37. string s = CraftTypeHelper.GetNameFromCraftTypeRegisteredAsCustom(___craftType);
  38. __instance.txtRecipeName[0].text = string.Empty + __instance.GetRecipeName2(___curRecipePage);
  39. __instance.txtRecipeUnlocked[0].text = "Page " + (___curRecipePage + 1) + "/" + (Core.pageCustomCrafterInfoLists[s].Count);
  40. }
  41. __instance.txtRecipeUnlocked[0].gameObject.GetComponent<Animation>().Play();
  42. __instance.txtRecipeName[0].gameObject.GetComponent<Animation>().Play();
  43. __instance.txtRecipeName[1].text = __instance.txtRecipeName[0].text;
  44. __instance.txtRecipeUnlocked[1].text = __instance.txtRecipeUnlocked[0].text;
  45. if ((___craftType != 0 || (___curRecipePage <= 5 && Core.pageGearForgeInfoListVanilla[___curRecipePage] == null))
  46. && (___craftType != 1 || (___curRecipePage <= 1 && Core.pageAlchemyStationInfoListVanilla[___curRecipePage] == null))
  47. && (___craftType != 2 || (___curRecipePage <= 5 && Core.pageUltimateForgeInfoListVanilla[___curRecipePage] == null))
  48. && (___craftType != MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
  49. && (!CraftTypeHelper.IsCraftTypeRegisteredAsCustom(___craftType)))
  50. {
  51. __instance.menuRecipe.GetComponent<Renderer>().material = (Material)Resources.Load(string.Concat(new object[] { "mat/r", ___curRecipePage, "t", ___craftType }));
  52. }
  53. else
  54. {
  55. if (___craftType == 0)
  56. {
  57. var page = ___curRecipePage >= 6 ? Core.pageGearForgeInfoList[___curRecipePage - 6] : Core.pageGearForgeInfoListVanilla[___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 == 1)
  63. {
  64. var page = ___curRecipePage >= 2 ? Core.pageAlchemyStationInfoList[___curRecipePage - 2] : Core.pageAlchemyStationInfoListVanilla[___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 == 2)
  70. {
  71. var page = ___curRecipePage >= 6 ? Core.pageUltimateForgeInfoList[___curRecipePage - 6] : Core.pageUltimateForgeInfoListVanilla[___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. else if (___craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
  77. {
  78. var page = Core.pageUniversalCrafterInfoList[___curRecipePage];
  79. __instance.txtRecipeName[0].text = page.Title;
  80. __instance.txtRecipeName[1].text = __instance.txtRecipeName[0].text;
  81. __instance.menuRecipe.GetComponent<Renderer>().material = page.Mat;
  82. }
  83. else if (CraftTypeHelper.IsCraftTypeRegisteredAsCustom(___craftType))
  84. {
  85. string s = CraftTypeHelper.GetNameFromCraftTypeRegisteredAsCustom(___craftType);
  86. var page = Core.pageCustomCrafterInfoLists[s][___curRecipePage];
  87. __instance.txtRecipeName[0].text = page.Title;
  88. __instance.txtRecipeName[1].text = __instance.txtRecipeName[0].text;
  89. __instance.menuRecipe.GetComponent<Renderer>().material = page.Mat;
  90. }
  91. }
  92. __instance.RefreshRecipeUnlock();
  93. return false;
  94. }
  95. [HarmonyPostfix]
  96. [HarmonyAfter("URP.URP.gadget")]
  97. public static void Postfix(GameScript __instance, int ___curRecipePage, int ___craftType)
  98. {
  99. if (___curRecipePage == 1 && ___craftType == 1 && Core.pageAlchemyStationInfoListVanilla[1] != null)
  100. {
  101. var page = Core.pageAlchemyStationInfoListVanilla[1];
  102. __instance.menuRecipe.GetComponent<Renderer>().material = page.Mat;
  103. }
  104. }
  105. }
  106. }