Patch_GameScript_RefreshRecipe.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using HarmonyLib;
  2. using GadgetCore.API;
  3. using UnityEngine;
  4. using System.Collections;
  5. namespace VendingMachine.Patches
  6. {
  7. [HarmonyPatch(typeof(GameScript))]
  8. [HarmonyPatch("RefreshRecipe")]
  9. [HarmonyGadget("VendingMachine")]
  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";
  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";
  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) + "/7";
  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 != 2 || ___curRecipePage <= 5)
  35. {
  36. __instance.menuRecipe.GetComponent<Renderer>().material = (Material)Resources.Load(string.Concat(new object[] { "mat/r", ___curRecipePage, "t", ___craftType }));
  37. }
  38. else
  39. {
  40. __instance.txtRecipeName[0].text = "Rings";
  41. __instance.menuRecipe.GetComponent<Renderer>().material = new Material(Shader.Find("Unlit/Transparent"))
  42. {
  43. mainTexture = GadgetCoreAPI.LoadTexture2D("recipesEmpty.png")
  44. };
  45. }
  46. __instance.RefreshRecipeUnlock();
  47. return false;
  48. }
  49. }
  50. }