Patch_GameScript_HoverRecipeSelect.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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("HoverRecipeSelect")]
  11. [HarmonyGadget("RecipeMenuCore")]
  12. public static class Patch_GameScript_HoverRecipeSelect
  13. {
  14. [HarmonyPrefix]
  15. public static bool Prefix(GameScript __instance, int id, int ___craftType, ref int ___curRecipePage, GameObject ___itemexpbar, Item[] ___storage, GameObject[] ___aspectObj, TextMesh ___itemName,
  16. GameObject ___hoverItem, TextMesh[] ___itemStat, GameObject ___txtStats, TextMesh ___itemDesc, Material ___hoverItemMat2, Material ___hoverItemMat1, GameObject ___hoverDroid,
  17. TextMesh[] ___txtHoverStat, TextMesh ___txtHoverStatInfo, TextMesh[] ___itemAspect, TextMesh ___itemLevel)
  18. {
  19. var item = new Item(GetItemId(id, ___craftType, ___curRecipePage), 1, 0, 0, 0, new int[3], new int[3]);
  20. var itemInfo = ItemRegistry.GetItem(item.id);
  21. ___txtHoverStat[0].text = string.Empty;
  22. ___txtHoverStat[1].text = ___txtHoverStat[0].text;
  23. ___txtHoverStatInfo.text = string.Empty;
  24. ___aspectObj[0].SetActive(false);
  25. ___aspectObj[1].SetActive(false);
  26. ___aspectObj[2].SetActive(false);
  27. ___itemAspect[0].text = string.Empty;
  28. ___itemAspect[1].text = string.Empty;
  29. ___itemAspect[2].text = string.Empty;
  30. ___itemLevel.text = string.Empty;
  31. if (Camera.main.ScreenToWorldPoint(Input.mousePosition).y < MenuScript.player.transform.position.y - 4.5f)
  32. ___hoverItem.transform.localPosition = new Vector3(5f, 0f, -4.55f);
  33. else
  34. ___hoverItem.transform.localPosition = new Vector3(5f, -4f, -4.55f);
  35. ___hoverDroid.SetActive(false);
  36. ___itemexpbar.SetActive(false);
  37. if (item.id > 0)
  38. {
  39. ___itemName.text = itemInfo.Name;
  40. ___itemName.color = Color.white;
  41. ___itemDesc.text = itemInfo.Desc;
  42. bool hasStats = false;
  43. int[] gearBaseStats = ItemRegistry.GetItem(item.id).Stats.GetStatArray();
  44. for (int i = 0; i < 6; i++)
  45. {
  46. if (gearBaseStats[i] > 0)
  47. {
  48. ___itemStat[i].text = "+" + gearBaseStats[i];
  49. hasStats = true;
  50. }
  51. else
  52. ___itemStat[i].text = string.Empty;
  53. }
  54. ___txtStats.SetActive(hasStats);
  55. ___hoverItem.SetActive(true);
  56. if (hasStats)
  57. ___hoverItem.GetComponent<Renderer>().material = hoverItem;
  58. else
  59. ___hoverItem.GetComponent<Renderer>().material = ___hoverItemMat1;
  60. }
  61. else
  62. {
  63. ___hoverItem.SetActive(false);
  64. }
  65. return false;
  66. }
  67. private static Material hoverItem = new Material(Shader.Find("Unlit/Transparent"))
  68. {
  69. mainTexture = GadgetCoreAPI.LoadTexture2D("hoverItem.png")
  70. };
  71. private static int GetItemId(int index, int craftType, int curRecipePage)
  72. {
  73. if (craftType == 0 && curRecipePage >= 6)
  74. {
  75. return Core.pageGearForgeInfoList[curRecipePage - 6].GetRecipePageEntries()[index].ItemIdBase;
  76. }
  77. else if (craftType == 1 && curRecipePage >= 2)
  78. {
  79. return Core.pageAlchemyStationInfoList[curRecipePage - 2].GetRecipePageEntries()[index].ItemIdBase;
  80. }
  81. else if (craftType == 2 && curRecipePage >= 6)
  82. {
  83. return Core.pageUltimateForgeInfoList[curRecipePage - 6].GetRecipePageEntries()[index].ItemIdBase;
  84. }
  85. return 1;
  86. }
  87. }
  88. }