Patch_GameScript_RefreshRecipeUnlock.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. [HarmonyPrefix]
  15. public static bool Prefix(GameScript __instance, int ___craftType, int ___curRecipePage, GameObject ___ultLocksObj, GameObject ___recipeButtons,
  16. GameObject[] ___recipeLock, GameObject[] ___ultLocks, int[,] ___ultLocksUnlocked)
  17. {
  18. if (___craftType == 0 || ___craftType == 1 || ___craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
  19. {
  20. for (int i = 0; i < 12; i++)
  21. {
  22. ___recipeButtons.transform.GetChild(i).gameObject.SetActive(true);
  23. }
  24. }
  25. var hoverElements = ___ultLocksObj.transform.parent.Find("hoverElements").gameObject;
  26. hoverElements.SetActive(false);
  27. if (___craftType == 2 && ___curRecipePage < 6 && Core.pageUltimateForgeInfoListVanilla[___curRecipePage] == null)
  28. {
  29. hoverElements.SetActive(true);
  30. for (int i = 0; i < 36; i++)
  31. {
  32. if (___ultLocksUnlocked[___curRecipePage, i] == 0)
  33. {
  34. hoverElements.transform.GetChild(i).gameObject.SetActive(false);
  35. }
  36. else
  37. {
  38. hoverElements.transform.GetChild(i).gameObject.SetActive(true);
  39. }
  40. }
  41. }
  42. if (___craftType == 0 && (___curRecipePage >= 6 || Core.pageGearForgeInfoListVanilla[___curRecipePage] != null))
  43. {
  44. ___ultLocksObj.SetActive(false);
  45. ___recipeButtons.SetActive(true);
  46. var page = ___curRecipePage >= 6 ? Core.pageGearForgeInfoList[___curRecipePage - 6] : Core.pageGearForgeInfoListVanilla[___curRecipePage];
  47. for (int i = 0; i < 12; i++)
  48. {
  49. if (page.GetRecipePageEntries().Length > i)
  50. {
  51. int itemID = page.GetRecipePageEntries()[i].ItemIdBase;
  52. if (__instance.RecipeCraftedAlready(itemID, page.GetRecipePageEntries()[i].MinAmount))
  53. ___recipeLock[i].SetActive(false);
  54. else
  55. ___recipeLock[i].SetActive(true);
  56. }
  57. else
  58. {
  59. ___recipeLock[i].SetActive(false);
  60. ___recipeButtons.transform.GetChild(i).gameObject.SetActive(false);
  61. }
  62. }
  63. return false;
  64. }
  65. else if (___craftType == 1 && (___curRecipePage >=2 || Core.pageAlchemyStationInfoListVanilla[___curRecipePage] != null))
  66. {
  67. ___ultLocksObj.SetActive(false);
  68. ___recipeButtons.SetActive(true);
  69. var page = ___curRecipePage >= 6 ? Core.pageAlchemyStationInfoList[___curRecipePage - 2] : Core.pageAlchemyStationInfoListVanilla[___curRecipePage];
  70. for (int i = 0; i < 12; i++)
  71. {
  72. if (page.GetRecipePageEntries().Length > i)
  73. {
  74. int itemID = page.GetRecipePageEntries()[i].ItemIdBase;
  75. if (__instance.RecipeCraftedAlready(itemID, page.GetRecipePageEntries()[i].MinAmount))
  76. ___recipeLock[i].SetActive(false);
  77. else
  78. ___recipeLock[i].SetActive(true);
  79. }
  80. else
  81. {
  82. ___recipeLock[i].SetActive(false);
  83. ___recipeButtons.transform.GetChild(i).gameObject.SetActive(false);
  84. }
  85. }
  86. return false;
  87. }
  88. else if (___craftType == 2 && (___curRecipePage >= 6 || Core.pageUltimateForgeInfoListVanilla[___curRecipePage] != null))
  89. {
  90. hoverElements.SetActive(true);
  91. ___ultLocksObj.SetActive(true);
  92. ___recipeButtons.SetActive(false);
  93. var page = ___curRecipePage >= 6 ? Core.pageUltimateForgeInfoList[___curRecipePage - 6] : Core.pageUltimateForgeInfoListVanilla[___curRecipePage];
  94. for (int i = 0; i < 36; i++)
  95. {
  96. if (i < 12)
  97. {
  98. ___recipeLock[i].SetActive(false);
  99. }
  100. if (page.GetRecipePageEntries().Length > i / 3)
  101. {
  102. int itemID = page.GetRecipePageEntries()[i / 3].ItemIdExtension[i % 3];
  103. if (__instance.RecipeCraftedAlready(itemID, 1))
  104. {
  105. ___ultLocks[i].SetActive(false);
  106. hoverElements.transform.GetChild(i).gameObject.SetActive(true);
  107. }
  108. else
  109. {
  110. ___ultLocks[i].SetActive(true);
  111. hoverElements.transform.GetChild(i).gameObject.SetActive(false);
  112. }
  113. }
  114. else
  115. {
  116. ___ultLocks[i].SetActive(false);
  117. hoverElements.transform.GetChild(i).gameObject.SetActive(false);
  118. }
  119. }
  120. return false;
  121. }
  122. else if (___craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
  123. {
  124. ___ultLocksObj.SetActive(false);
  125. ___recipeButtons.SetActive(true);
  126. var page = Core.pageUniversalCrafterInfoList[___curRecipePage];
  127. for (int i = 0; i < 12; i++)
  128. {
  129. if (page.GetRecipePageEntries().Length > i)
  130. {
  131. int itemID = page.GetRecipePageEntries()[i].ItemIdBase;
  132. if (((CraftMenuInfo)MenuRegistry.Singleton["Gadget Core:Crafter Menu"]).IsRecipeUnlocked(itemID))
  133. ___recipeLock[i].SetActive(false);
  134. else
  135. ___recipeLock[i].SetActive(true);
  136. }
  137. else
  138. {
  139. ___recipeLock[i].SetActive(false);
  140. ___recipeButtons.transform.GetChild(i).gameObject.SetActive(false);
  141. }
  142. }
  143. return false;
  144. }
  145. return true;
  146. }
  147. }
  148. }