Patch_GameScript_HoverRecipeSelect.cs 6.1 KB

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