Patch_GameScript_HoverRecipeSelect.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using HarmonyLib;
  2. using GadgetCore.API;
  3. using UnityEngine;
  4. using System.Collections;
  5. using System.Reflection;
  6. using System.Collections.Generic;
  7. using System.Globalization;
  8. using GadgetCore;
  9. namespace RecipeMenuCore.Patches
  10. {
  11. [HarmonyPatch(typeof(GameScript))]
  12. [HarmonyPatch("HoverRecipeSelect")]
  13. [HarmonyGadget("RecipeMenuCore")]
  14. public static class Patch_GameScript_HoverRecipeSelect
  15. {
  16. [HarmonyPrefix]
  17. public static bool Prefix(GameScript __instance, int id, int ___craftType, ref int ___curRecipePage, GameObject ___itemexpbar, GameObject[] ___aspectObj, TextMesh ___itemName,
  18. GameObject ___hoverItem, TextMesh[] ___itemStat, GameObject ___txtStats, TextMesh ___itemDesc, Material ___hoverItemMat2, Material ___hoverItemMat1, GameObject ___hoverDroid,
  19. TextMesh[] ___txtHoverStat, TextMesh ___txtHoverStatInfo, TextMesh[] ___itemAspect, TextMesh ___itemLevel, GameObject[] ___recipeLock)
  20. {
  21. if (!Core.settingUseDialog)
  22. return true;
  23. if (___craftType == 0 || ___craftType == 1 || ___craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID()
  24. || CraftTypeHelper.IsCraftTypeRegisteredAsCustom(___craftType))
  25. {
  26. if (id >= 12 || ___recipeLock[id].active)
  27. {
  28. ___hoverItem.SetActive(false);
  29. return false;
  30. }
  31. }
  32. var item = new Item(GetItemId(__instance, id, ___craftType, ___curRecipePage), 1, 0, 0, 0, new int[3], new int[3]);
  33. var itemInfo = ItemRegistry.GetItem(item.id);
  34. PatchMethods.HoverItem(item);
  35. ___txtHoverStat[0].text = string.Empty;
  36. ___txtHoverStat[1].text = ___txtHoverStat[0].text;
  37. ___txtHoverStatInfo.text = string.Empty;
  38. ___aspectObj[0].SetActive(false);
  39. ___aspectObj[1].SetActive(false);
  40. ___aspectObj[2].SetActive(false);
  41. ___itemAspect[0].text = string.Empty;
  42. ___itemAspect[1].text = string.Empty;
  43. ___itemAspect[2].text = string.Empty;
  44. ___itemLevel.text = string.Empty;
  45. if (item.id > 0)
  46. {
  47. ___itemDesc.text = GenerateDescription(itemInfo);
  48. bool hasStats = false;
  49. int[] gearBaseStats = ItemRegistry.GetItem(item.id).Stats.GetStatArray();
  50. for (int i = 0; i < 6; i++)
  51. {
  52. if (gearBaseStats[i] > 0)
  53. {
  54. hasStats = true;
  55. }
  56. }
  57. ___txtStats.SetActive(hasStats);
  58. ___hoverItem.SetActive(true);
  59. if (hasStats)
  60. ___hoverItem.GetComponent<Renderer>().material = hoverItem;
  61. else
  62. ___hoverItem.GetComponent<Renderer>().material = ___hoverItemMat1;
  63. }
  64. else
  65. {
  66. ___hoverItem.SetActive(false);
  67. }
  68. return false;
  69. }
  70. private static Material hoverItem = new Material(Shader.Find("Unlit/Transparent"))
  71. {
  72. mainTexture = GadgetCoreAPI.LoadTexture2D("hoverItem.png")
  73. };
  74. private static string GenerateDescription(ItemInfo item)
  75. {
  76. if ((item.GetID() >= 1000 && item.GetID() < 1000 + 6)
  77. || (item.GetID() >= 1012 && item.GetID() < 1012 + 3 * 6))
  78. return "";
  79. var desc = item.Desc;
  80. if (desc == null || desc.Length <= 0)
  81. {
  82. float[] ws = item.WeaponScaling;
  83. if (ws != null)
  84. {
  85. string o = "";
  86. for (int i = 0; i < ws.Length; i++)
  87. {
  88. if (ws[i] > 0)
  89. {
  90. string type = i == 0 ? "VIT" : i == 1 ? "STR" : i == 2 ? "DEX" : i == 3 ? "TEC" : i == 4 ? "MAG" : "FTH";
  91. o += "DMG x" + (ws[i] >= 1 ? ws[i].ToString(CultureInfo.InvariantCulture) : "1/" + (1 / ws[i])).ToString(CultureInfo.InvariantCulture) + " " + type + "\n";
  92. }
  93. }
  94. return o;
  95. }
  96. }
  97. return desc;
  98. }
  99. private static int GetItemId(GameScript __instance, int index, int craftType, int curRecipePage)
  100. {
  101. if (index >= 12)
  102. {
  103. if (craftType == 2 && curRecipePage >= 6)
  104. return Core.pageUltimateForgeInfoList[curRecipePage - 6].GetRecipePageEntries()[(index - 12) / 3].ItemIdExtension[(index - 12) % 3];
  105. return CalculateUltimaleWeapon((index - 12) % (3 * 6), (index - 12) / (3 * 6) + curRecipePage * 2);
  106. }
  107. if (craftType == 0 && curRecipePage >= 6)
  108. return Core.pageGearForgeInfoList[curRecipePage - 6].GetRecipePageEntries()[index].ItemIdBase;
  109. else if (craftType == 1 && curRecipePage >= 2)
  110. return Core.pageAlchemyStationInfoList[curRecipePage - 2].GetRecipePageEntries()[index].ItemIdBase;
  111. else if (craftType == 2 && curRecipePage >= 6)
  112. return Core.pageUltimateForgeInfoList[curRecipePage - 6].GetRecipePageEntries()[index].ItemIdBase;
  113. else if (craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
  114. return Core.pageUniversalCrafterInfoList[curRecipePage].GetRecipePageEntries()[index].ItemIdBase;
  115. else if (CraftTypeHelper.IsCraftTypeRegisteredAsCustom(craftType))
  116. {
  117. string s = CraftTypeHelper.GetNameFromCraftTypeRegisteredAsCustom(craftType);
  118. if (!Core.pageCustomCrafterInfoLists[s][curRecipePage].GetRecipePageEntries()[index].IsReverse)
  119. return Core.pageCustomCrafterInfoLists[s][curRecipePage].GetRecipePageEntries()[index].ItemIdBase;
  120. else
  121. return Core.pageCustomCrafterInfoLists[s][curRecipePage].GetRecipePageEntries()[index].ItemIds[0];
  122. }
  123. else if (craftType == 0 && curRecipePage < 6 && Core.pageGearForgeInfoListVanilla[curRecipePage] != null)
  124. return Core.pageGearForgeInfoListVanilla[curRecipePage].GetRecipePageEntries()[index].ItemIdBase;
  125. else if (craftType == 1 && curRecipePage < 2 && Core.pageAlchemyStationInfoListVanilla[curRecipePage] != null)
  126. return Core.pageAlchemyStationInfoListVanilla[curRecipePage].GetRecipePageEntries()[index].ItemIdBase;
  127. else if (craftType == 2 && curRecipePage < 6 && Core.pageUltimateForgeInfoListVanilla[curRecipePage] != null)
  128. return Core.pageUltimateForgeInfoListVanilla[curRecipePage].GetRecipePageEntries()[index].ItemIdBase;
  129. return __instance.GetRecipeItem(curRecipePage, index).id;
  130. }
  131. private static int CalculateUltimaleWeapon(int index, int page)
  132. {
  133. if (page == 0)
  134. return 312 + index;
  135. if (page == 1)
  136. return 362 + index;
  137. if (page == 2)
  138. return 412 + index;
  139. if (page == 3)
  140. return 462 + index;
  141. if (page == 4)
  142. return 512 + index;
  143. if (page == 5)
  144. return 562 + index;
  145. if (page == 6) //shield
  146. return 612 + index;
  147. if (page == 7) //droid
  148. return 1012 + index;
  149. if (page == 8) //helmet 1
  150. return 750 + index;
  151. if (page == 9) //helmet 2
  152. return 768 + index;
  153. if (page == 10) //armor 1
  154. return 850 + index;
  155. if (page == 11) //armor 2
  156. return 868 + index;
  157. return 0;
  158. }
  159. }
  160. }