Patch_GameScript_HoverRecipeSelect.cs 6.6 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. namespace RecipeMenuCore.Patches
  9. {
  10. [HarmonyPatch(typeof(GameScript))]
  11. [HarmonyPatch("HoverRecipeSelect")]
  12. [HarmonyGadget("RecipeMenuCore")]
  13. public static class Patch_GameScript_HoverRecipeSelect
  14. {
  15. [HarmonyPrefix]
  16. public static bool Prefix(GameScript __instance, int id, int ___craftType, ref int ___curRecipePage, GameObject ___itemexpbar, GameObject[] ___aspectObj, TextMesh ___itemName,
  17. GameObject ___hoverItem, TextMesh[] ___itemStat, GameObject ___txtStats, TextMesh ___itemDesc, Material ___hoverItemMat2, Material ___hoverItemMat1, GameObject ___hoverDroid,
  18. TextMesh[] ___txtHoverStat, TextMesh ___txtHoverStatInfo, TextMesh[] ___itemAspect, TextMesh ___itemLevel, GameObject[] ___recipeLock)
  19. {
  20. if (!Core.settingUseDialog)
  21. return true;
  22. if (___craftType == 0 || ___craftType == 1 || ___craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
  23. {
  24. if (id >= 12 || ___recipeLock[id].active)
  25. {
  26. ___hoverItem.SetActive(false);
  27. return false;
  28. }
  29. }
  30. var item = new Item(GetItemId(__instance, id, ___craftType, ___curRecipePage), 1, 0, 0, 0, new int[3], new int[3]);
  31. var itemInfo = ItemRegistry.GetItem(item.id);
  32. ___txtHoverStat[0].text = string.Empty;
  33. ___txtHoverStat[1].text = ___txtHoverStat[0].text;
  34. ___txtHoverStatInfo.text = string.Empty;
  35. ___aspectObj[0].SetActive(false);
  36. ___aspectObj[1].SetActive(false);
  37. ___aspectObj[2].SetActive(false);
  38. ___itemAspect[0].text = string.Empty;
  39. ___itemAspect[1].text = string.Empty;
  40. ___itemAspect[2].text = string.Empty;
  41. ___itemLevel.text = string.Empty;
  42. if (Camera.main.ScreenToWorldPoint(Input.mousePosition).y < MenuScript.player.transform.position.y - 4.5f)
  43. ___hoverItem.transform.localPosition = new Vector3(5f, 0f, -4.55f);
  44. else
  45. ___hoverItem.transform.localPosition = new Vector3(5f, -4f, -4.55f);
  46. ___hoverDroid.SetActive(false);
  47. ___itemexpbar.SetActive(false);
  48. if (item.id > 0)
  49. {
  50. ___itemName.text = itemInfo.Name;
  51. ___itemName.color = Color.white;
  52. ___itemDesc.text = GenerateDescription(itemInfo);
  53. bool hasStats = false;
  54. int[] gearBaseStats = ItemRegistry.GetItem(item.id).Stats.GetStatArray();
  55. for (int i = 0; i < 6; i++)
  56. {
  57. if (gearBaseStats[i] > 0)
  58. {
  59. ___itemStat[i].text = "+" + gearBaseStats[i];
  60. hasStats = true;
  61. }
  62. else
  63. ___itemStat[i].text = string.Empty;
  64. }
  65. ___txtStats.SetActive(hasStats);
  66. ___hoverItem.SetActive(true);
  67. if (hasStats)
  68. ___hoverItem.GetComponent<Renderer>().material = hoverItem;
  69. else
  70. ___hoverItem.GetComponent<Renderer>().material = ___hoverItemMat1;
  71. }
  72. else
  73. {
  74. ___hoverItem.SetActive(false);
  75. }
  76. return false;
  77. }
  78. private static Material hoverItem = new Material(Shader.Find("Unlit/Transparent"))
  79. {
  80. mainTexture = GadgetCoreAPI.LoadTexture2D("hoverItem.png")
  81. };
  82. private static string GenerateDescription(ItemInfo item)
  83. {
  84. if ((item.GetID() >= 1000 && item.GetID() < 1000 + 6)
  85. || (item.GetID() >= 1012 && item.GetID() < 1012 + 3 * 6))
  86. return "";
  87. var desc = item.Desc;
  88. if (desc == null || desc.Length <= 0)
  89. {
  90. float[] ws = item.WeaponScaling;
  91. if (ws != null)
  92. {
  93. string o = "";
  94. for (int i = 0; i < ws.Length; i++)
  95. {
  96. if (ws[i] > 0)
  97. {
  98. string type = i == 0 ? "VIT" : i == 1 ? "STR" : i == 2 ? "DEX" : i == 3 ? "TEC" : i == 4 ? "MAG" : "FTH";
  99. o += "DMG x" + (ws[i] >= 1 ? ws[i].ToString(CultureInfo.InvariantCulture) : "1/" + (1 / ws[i])).ToString(CultureInfo.InvariantCulture) + " " + type + "\n";
  100. }
  101. }
  102. return o;
  103. }
  104. }
  105. return desc;
  106. }
  107. private static int GetItemId(GameScript __instance, int index, int craftType, int curRecipePage)
  108. {
  109. if (index >= 12)
  110. {
  111. if (craftType == 2 && curRecipePage >= 6)
  112. return Core.pageUltimateForgeInfoList[curRecipePage - 6].GetRecipePageEntries()[(index - 12) / 3].ItemIdExtension[(index - 12) % 3];
  113. return CalculateUltimaleWeapon((index - 12) % (3 * 6), (index - 12) / (3 * 6) + curRecipePage * 2);
  114. }
  115. if (craftType == 0 && curRecipePage >= 6)
  116. return Core.pageGearForgeInfoList[curRecipePage - 6].GetRecipePageEntries()[index].ItemIdBase;
  117. else if (craftType == 1 && curRecipePage >= 2)
  118. return Core.pageAlchemyStationInfoList[curRecipePage - 2].GetRecipePageEntries()[index].ItemIdBase;
  119. else if (craftType == 2 && curRecipePage >= 6)
  120. return Core.pageUltimateForgeInfoList[curRecipePage - 6].GetRecipePageEntries()[index].ItemIdBase;
  121. else if (craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
  122. return Core.pageUniversalCrafterInfoList[curRecipePage].GetRecipePageEntries()[index].ItemIdBase;
  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. }