Patch_GameScript_HoverRecipeSelect.cs 5.6 KB

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