Patch_GameScript_RefreshRecipeUnlock.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using HarmonyLib;
  2. using GadgetCore.API;
  3. using UnityEngine;
  4. using System.Collections;
  5. using System.Reflection;
  6. using System.Collections.Generic;
  7. namespace RecipeMenuCore.Patches
  8. {
  9. [HarmonyPatch(typeof(GameScript))]
  10. [HarmonyPatch("RefreshRecipeUnlock")]
  11. [HarmonyGadget("RecipeMenuCore")]
  12. public static class Patch_GameScript_RefreshRecipeUnlock
  13. {
  14. private static Material recipeLockSmall = new Material(Shader.Find("Unlit/Transparent"))
  15. {
  16. mainTexture = GadgetCoreAPI.LoadTexture2D("recipeLockSmall.png")
  17. };
  18. private static Material recipeLock = new Material(Shader.Find("Unlit/Transparent"))
  19. {
  20. mainTexture = GadgetCoreAPI.LoadTexture2D("recipeLock.png")
  21. };
  22. [HarmonyPrefix]
  23. public static bool Prefix(GameScript __instance, int ___craftType, int ___curRecipePage, GameObject ___ultLocksObj, GameObject ___recipeButtons,
  24. GameObject[] ___recipeLock, GameObject[] ___ultLocks, int[,] ___ultLocksUnlocked)
  25. {
  26. if (___craftType == 0 || ___craftType == 1 || ___craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
  27. {
  28. for (int i = 0; i < 12; i++)
  29. {
  30. ___recipeButtons.transform.GetChild(i).gameObject.SetActive(true);
  31. ___recipeLock[i].GetComponent<Renderer>().material = recipeLock;
  32. }
  33. }
  34. var hoverElements = ___ultLocksObj.transform.parent.Find("hoverElements").gameObject;
  35. hoverElements.SetActive(false);
  36. if (___craftType == 2 && ___curRecipePage < 6 && Core.pageUltimateForgeInfoListVanilla[___curRecipePage] == null)
  37. {
  38. hoverElements.SetActive(true);
  39. for (int i = 0; i < 36; i++)
  40. {
  41. if (___ultLocksUnlocked[___curRecipePage, i] == 0)
  42. {
  43. hoverElements.transform.GetChild(i).gameObject.SetActive(false);
  44. }
  45. else
  46. {
  47. hoverElements.transform.GetChild(i).gameObject.SetActive(true);
  48. }
  49. }
  50. }
  51. if (___craftType == 0 && (___curRecipePage >= 6 || Core.pageGearForgeInfoListVanilla[___curRecipePage] != null))
  52. {
  53. ___ultLocksObj.SetActive(false);
  54. ___recipeButtons.SetActive(true);
  55. var page = ___curRecipePage >= 6 ? Core.pageGearForgeInfoList[___curRecipePage - 6] : Core.pageGearForgeInfoListVanilla[___curRecipePage];
  56. for (int i = 0; i < 12; i++)
  57. {
  58. if (page.GetRecipePageEntries().Length > i)
  59. {
  60. int itemID = page.GetRecipePageEntries()[i].ItemIdBase;
  61. if (__instance.RecipeCraftedAlready(itemID, page.GetRecipePageEntries()[i].MinAmount))
  62. ___recipeLock[i].SetActive(false);
  63. else
  64. {
  65. if (page.GetRecipePageEntries()[i].AllwaysShowInput)
  66. ___recipeLock[i].GetComponent<Renderer>().material = recipeLockSmall;
  67. ___recipeLock[i].SetActive(true);
  68. }
  69. }
  70. else
  71. {
  72. ___recipeLock[i].SetActive(false);
  73. ___recipeButtons.transform.GetChild(i).gameObject.SetActive(false);
  74. }
  75. }
  76. return false;
  77. }
  78. else if (___craftType == 1 && (___curRecipePage >=2 || Core.pageAlchemyStationInfoListVanilla[___curRecipePage] != null))
  79. {
  80. ___ultLocksObj.SetActive(false);
  81. ___recipeButtons.SetActive(true);
  82. var page = ___curRecipePage >= 6 ? Core.pageAlchemyStationInfoList[___curRecipePage - 2] : Core.pageAlchemyStationInfoListVanilla[___curRecipePage];
  83. for (int i = 0; i < 12; i++)
  84. {
  85. if (page.GetRecipePageEntries().Length > i)
  86. {
  87. int itemID = page.GetRecipePageEntries()[i].ItemIdBase;
  88. if (__instance.RecipeCraftedAlready(itemID, page.GetRecipePageEntries()[i].MinAmount))
  89. ___recipeLock[i].SetActive(false);
  90. else
  91. {
  92. if (page.GetRecipePageEntries()[i].AllwaysShowInput)
  93. ___recipeLock[i].GetComponent<Renderer>().material = recipeLockSmall;
  94. ___recipeLock[i].SetActive(true);
  95. }
  96. }
  97. else
  98. {
  99. ___recipeLock[i].SetActive(false);
  100. ___recipeButtons.transform.GetChild(i).gameObject.SetActive(false);
  101. }
  102. }
  103. return false;
  104. }
  105. else if (___craftType == 2 && (___curRecipePage >= 6 || Core.pageUltimateForgeInfoListVanilla[___curRecipePage] != null))
  106. {
  107. hoverElements.SetActive(true);
  108. ___ultLocksObj.SetActive(true);
  109. ___recipeButtons.SetActive(false);
  110. var page = ___curRecipePage >= 6 ? Core.pageUltimateForgeInfoList[___curRecipePage - 6] : Core.pageUltimateForgeInfoListVanilla[___curRecipePage];
  111. for (int i = 0; i < 36; i++)
  112. {
  113. if (i < 12)
  114. {
  115. ___recipeLock[i].SetActive(false);
  116. }
  117. if (page.GetRecipePageEntries().Length > i / 3)
  118. {
  119. int itemID = page.GetRecipePageEntries()[i / 3].ItemIdExtension[i % 3];
  120. if (__instance.RecipeCraftedAlready(itemID, 1))
  121. {
  122. ___ultLocks[i].SetActive(false);
  123. hoverElements.transform.GetChild(i).gameObject.SetActive(true);
  124. }
  125. else
  126. {
  127. ___ultLocks[i].SetActive(true);
  128. hoverElements.transform.GetChild(i).gameObject.SetActive(false);
  129. }
  130. }
  131. else
  132. {
  133. ___ultLocks[i].SetActive(false);
  134. hoverElements.transform.GetChild(i).gameObject.SetActive(false);
  135. }
  136. }
  137. return false;
  138. }
  139. else if (___craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
  140. {
  141. ___ultLocksObj.SetActive(false);
  142. ___recipeButtons.SetActive(true);
  143. var page = Core.pageUniversalCrafterInfoList[___curRecipePage];
  144. for (int i = 0; i < 12; i++)
  145. {
  146. if (page.GetRecipePageEntries().Length > i)
  147. {
  148. int itemID = page.GetRecipePageEntries()[i].ItemIdBase;
  149. if (((CraftMenuInfo)MenuRegistry.Singleton["Gadget Core:Crafter Menu"]).IsRecipeUnlocked(itemID))
  150. ___recipeLock[i].SetActive(false);
  151. else
  152. {
  153. if (page.GetRecipePageEntries()[i].AllwaysShowInput)
  154. ___recipeLock[i].GetComponent<Renderer>().material = recipeLockSmall;
  155. ___recipeLock[i].SetActive(true);
  156. }
  157. }
  158. else
  159. {
  160. ___recipeLock[i].SetActive(false);
  161. ___recipeButtons.transform.GetChild(i).gameObject.SetActive(false);
  162. }
  163. }
  164. return false;
  165. }
  166. return true;
  167. }
  168. }
  169. }