Patch_GameScript_InitializeGatherStorage.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using HarmonyLib;
  2. using GadgetCore.API;
  3. using UnityEngine;
  4. using System.Collections;
  5. using System.Reflection;
  6. namespace First.Patches
  7. {
  8. [HarmonyPatch(typeof(GameScript))]
  9. [HarmonyPatch("InitializeGatherStorage")]
  10. [HarmonyGadget("First")]
  11. public static class Patch_GameScript_InitializeGatherStorage
  12. {
  13. [HarmonyPrefix]
  14. public static bool Prefix(GameScript __instance)
  15. {
  16. int i;
  17. for (i = 0; i < 6; i++)
  18. {
  19. GameScript.shipDroid[i] = PreviewLabs.PlayerPrefs.GetInt("sd" + i);
  20. if (GameScript.shipDroid[i] > 5)
  21. {
  22. GameScript.shipDroid[i] = 5;
  23. }
  24. }
  25. if (GameScript.shipDroid[0] == 0)
  26. {
  27. GameScript.shipDroid[0] = 1;
  28. PreviewLabs.PlayerPrefs.SetInt("sd" + i, 1);
  29. }
  30. Item[] items = new Item[16];
  31. var field = typeof(GameScript).GetField("gatherStorage", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance);
  32. field.SetValue(__instance, items);
  33. for (i = 0; i < 16; i++)
  34. {
  35. items[i] = new Item(71, 2, 0, 0, 0, new int[3], new int[3]);
  36. }
  37. return false; // Return false to prevent the vanilla method from running.
  38. }
  39. /*
  40. [HarmonyPostfix]
  41. public static void Postfix(ClassName __instance)
  42. {
  43. // Add code to run after `MethodName` is called.
  44. }
  45. */
  46. }
  47. }