Patch_GameScript_UpgradeStorage.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using GadgetCore.API;
  2. using HarmonyLib;
  3. using UnityEngine;
  4. namespace StorageExpansion.Patches
  5. {
  6. [HarmonyPatch(typeof(GameScript))]
  7. [HarmonyPatch("UpgradeStorage")]
  8. [HarmonyGadget("StorageExpansion")]
  9. public static class Patch_GameScript_UpgradeStorage
  10. {
  11. [HarmonyPrefix]
  12. public static bool Prefix(GameScript __instance, ref int ___storageLevel)
  13. {
  14. if (___storageLevel < Core.settingAmountActualPages - 1)
  15. {
  16. int storageUpgradeCost = __instance.GetStorageUpgradeCost(___storageLevel);
  17. if (__instance.GetCredits() >= storageUpgradeCost)
  18. {
  19. __instance.RemoveCredits(storageUpgradeCost);
  20. ___storageLevel++;
  21. PreviewLabs.PlayerPrefs.SetInt("storageLevel", ___storageLevel);
  22. __instance.GetComponent<AudioSource>().PlayOneShot((AudioClip)Resources.Load("Au/chesthit2"), Menuu.soundLevel / 10f);
  23. Camera.main.GetComponent<Animation>().Play("craft");
  24. for (int i = 0; i < __instance.storageButton.Length; i++)
  25. {
  26. if (i <= ___storageLevel)
  27. {
  28. __instance.storageButton[i].GetComponent<Renderer>().enabled = false;
  29. }
  30. else
  31. {
  32. __instance.storageButton[i].GetComponent<Renderer>().enabled = true;
  33. }
  34. }
  35. int newStorageUpgradeCost = __instance.GetStorageUpgradeCost(___storageLevel);
  36. if (___storageLevel >= Core.settingAmountActualPages - 1)
  37. {
  38. __instance.txtStorageCost[0].text = "Max Lvl";
  39. __instance.txtStorageCost[1].text = "Max Lvl";
  40. }
  41. else
  42. {
  43. __instance.txtStorageCost[0].text = string.Empty + newStorageUpgradeCost;
  44. __instance.txtStorageCost[1].text = string.Empty + newStorageUpgradeCost;
  45. }
  46. }
  47. else
  48. {
  49. __instance.Error(3);
  50. }
  51. }
  52. return false;
  53. }
  54. }
  55. }