Patch_GameScript_MultiPachSlots.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using GadgetCore.API;
  2. using GadgetCore.Util;
  3. using HarmonyLib;
  4. using System.Collections.Generic;
  5. using System.Reflection;
  6. using System.Reflection.Emit;
  7. using UnityEngine;
  8. namespace StorageExpansion.Patches
  9. {
  10. internal class SlotsPerPageGetter
  11. {
  12. public static int SlotsPerPage { get => Core.settingAmountSlots; }
  13. }
  14. [HarmonyPatch()]
  15. [HarmonyGadget("StorageExpansion")]
  16. public static class Patch_GameScript_MultiPachSlots
  17. {
  18. [HarmonyTargetMethods]
  19. static IEnumerable<MethodBase> TargetMethods()
  20. {
  21. yield return AccessTools.Method(typeof(GameScript), "Update");
  22. yield return AccessTools.Method(typeof(GameScript), "PlaceItemStorage");
  23. yield return AccessTools.Method(typeof(GameScript), "PlaceOneItemStorage");
  24. yield return AccessTools.Method(typeof(GameScript), "SelectItemStorage");
  25. //yield return AccessTools.Method(typeof(GameScript), "ShiftClickStorage");
  26. //yield return AccessTools.Method(typeof(GameScript), "ShiftClick");
  27. yield return AccessTools.Method(typeof(GameScript), "SplitItemStorage");
  28. yield return AccessTools.Method(typeof(GameScript), "CombineItemStorage");
  29. yield return AccessTools.Method(typeof(GameScript), "SwapItemStorage");
  30. //yield return AccessTools.Method(typeof(GameScript), "RefreshSlotStorage");
  31. yield return AccessTools.Method(typeof(GameScript), "HoverItemStorage");
  32. yield return AccessTools.Method(typeof(GadgetCoreAPI).Assembly.GetType("GadgetCore.Patches.Patch_GameScript_RefreshSlotStorage"), "Prefix");
  33. yield return AccessTools.Method(typeof(GadgetCoreAPI).Assembly.GetType("GadgetCore.Patches.Patch_GameScript_RefreshSlotStorage"), "Postfix");
  34. yield return AccessTools.Method(typeof(GadgetCoreAPI).Assembly.GetType("GadgetCore.Patches.Patch_GameScript_ShiftClick"), "Prefix");
  35. yield return AccessTools.Method(typeof(GadgetCoreAPI).Assembly.GetType("GadgetCore.Patches.Patch_GameScript_HoverItemStorage"), "Prefix");
  36. yield return AccessTools.Method(typeof(GadgetCoreAPI).Assembly.GetType("GadgetCore.Patches.Patch_GameScript_CombineItemStorage"), "Prefix");
  37. yield return AccessTools.Method(typeof(GadgetCoreAPI).Assembly.GetType("GadgetCore.Patches.Patch_GameScript_PlaceOneItemStorage"), "Prefix");
  38. yield return AccessTools.Method(typeof(GadgetCoreAPI).Assembly.GetType("GadgetCore.Patches.Patch_GameScript_SplitItemStorage"), "Prefix");
  39. yield return AccessTools.Method(typeof(GadgetCoreAPI).Assembly.GetType("GadgetCore.Patches.Patch_GameScript_ShiftClickStorage"), "Prefix");
  40. yield return AccessTools.Method(typeof(GadgetCoreAPI).Assembly.GetType("GadgetCore.Patches.Patch_GameScript_RefreshStoragePage"), "Prefix");
  41. //yield return AccessTools.Method("GadgetCore.Patches.Patch_GameScript_RefreshStoragePage:Prefix");
  42. }
  43. [HarmonyTranspiler]
  44. public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator gen)
  45. {
  46. var p = TranspilerHelper.CreateProcessor(instructions, gen);
  47. var ilRefs = p.FindAllRefsByInsn(new CodeInstruction(OpCodes.Ldc_I4_S, 30));
  48. MethodInfo getValue = typeof(SlotsPerPageGetter).GetProperty("SlotsPerPage").GetGetMethod();
  49. foreach (var ilRef in ilRefs)
  50. {
  51. p.InjectInsn(ilRef, new CodeInstruction(OpCodes.Call, getValue), false);
  52. }
  53. return p.Insns;
  54. }
  55. }
  56. }