Patch_GameScript_RefreshRecipe.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using HarmonyLib;
  2. using GadgetCore.API;
  3. using UnityEngine;
  4. using System.Collections;
  5. namespace RecipeMenuCore.Patches
  6. {
  7. [HarmonyPatch(typeof(GameScript))]
  8. [HarmonyPatch("RefreshRecipe")]
  9. [HarmonyGadget("RecipeMenuCore")]
  10. public static class Patch_GameScript_RefreshRecipe
  11. {
  12. [HarmonyPrefix]
  13. public static bool Prefix(GameScript __instance, int ___craftType, int ___curRecipePage)
  14. {
  15. if (___craftType == 0)
  16. {
  17. __instance.txtRecipeName[0].text = string.Empty + __instance.GetRecipeName0(___curRecipePage);
  18. __instance.txtRecipeUnlocked[0].text = "Page " + (___curRecipePage + 1) + "/" + (6 + Core.pageGearForgeInfoList.Count);
  19. }
  20. else if (___craftType == 1)
  21. {
  22. __instance.txtRecipeName[0].text = string.Empty + __instance.GetRecipeName1(___curRecipePage);
  23. __instance.txtRecipeUnlocked[0].text = "Page " + (___curRecipePage + 1) + "/" + (2 + Core.pageAlchemyStationInfoList.Count);
  24. }
  25. else if (___craftType == 2)
  26. {
  27. __instance.txtRecipeName[0].text = string.Empty + __instance.GetRecipeName2(___curRecipePage);
  28. __instance.txtRecipeUnlocked[0].text = "Page " + (___curRecipePage + 1) + "/" + (6 + Core.pageUltimateForgeInfoList.Count);
  29. }
  30. __instance.txtRecipeUnlocked[0].gameObject.GetComponent<Animation>().Play();
  31. __instance.txtRecipeName[0].gameObject.GetComponent<Animation>().Play();
  32. __instance.txtRecipeName[1].text = __instance.txtRecipeName[0].text;
  33. __instance.txtRecipeUnlocked[1].text = __instance.txtRecipeUnlocked[0].text;
  34. if ((___craftType != 0 || (___curRecipePage <= 5 && Core.pageGearForgeInfoListVanilla[___curRecipePage] == null))
  35. && (___craftType != 1 || (___curRecipePage <= 1 && Core.pageAlchemyStationInfoListVanilla[___curRecipePage] == null))
  36. && (___craftType != 2 || (___curRecipePage <= 5 && Core.pageUltimateForgeInfoListVanilla[___curRecipePage] == null)))
  37. {
  38. __instance.menuRecipe.GetComponent<Renderer>().material = (Material)Resources.Load(string.Concat(new object[] { "mat/r", ___curRecipePage, "t", ___craftType }));
  39. }
  40. else
  41. {
  42. if (___craftType == 0)
  43. {
  44. var page = ___curRecipePage >= 6 ? Core.pageGearForgeInfoList[___curRecipePage - 6] : Core.pageGearForgeInfoListVanilla[___curRecipePage];
  45. __instance.txtRecipeName[0].text = page.Title;
  46. __instance.txtRecipeName[1].text = __instance.txtRecipeName[0].text;
  47. __instance.menuRecipe.GetComponent<Renderer>().material = page.Mat;
  48. }
  49. else if (___craftType == 1)
  50. {
  51. var page = ___curRecipePage >= 2 ? Core.pageAlchemyStationInfoList[___curRecipePage - 2] : Core.pageAlchemyStationInfoListVanilla[___curRecipePage];
  52. __instance.txtRecipeName[0].text = page.Title;
  53. __instance.txtRecipeName[1].text = __instance.txtRecipeName[0].text;
  54. __instance.menuRecipe.GetComponent<Renderer>().material = page.Mat;
  55. }
  56. else if (___craftType == 2)
  57. {
  58. var page = ___curRecipePage >= 6 ? Core.pageUltimateForgeInfoList[___curRecipePage - 6] : Core.pageUltimateForgeInfoListVanilla[___curRecipePage];
  59. __instance.txtRecipeName[0].text = page.Title;
  60. __instance.txtRecipeName[1].text = __instance.txtRecipeName[0].text;
  61. __instance.menuRecipe.GetComponent<Renderer>().material = page.Mat;
  62. }
  63. }
  64. __instance.RefreshRecipeUnlock();
  65. return false;
  66. }
  67. [HarmonyPostfix]
  68. [HarmonyAfter("URP.URP.gadget")]
  69. public static void Postfix(GameScript __instance, int ___curRecipePage, int ___craftType)
  70. {
  71. if (___curRecipePage == 1 && ___craftType == 1 && Core.pageAlchemyStationInfoListVanilla[1] != null)
  72. {
  73. var page = Core.pageAlchemyStationInfoListVanilla[1];
  74. __instance.menuRecipe.GetComponent<Renderer>().material = page.Mat;
  75. }
  76. }
  77. }
  78. }