Patch_GameScript_HoverItem.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using GadgetCore;
  2. using GadgetCore.API;
  3. using GadgetCore.Util;
  4. using HarmonyLib;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Reflection;
  8. using System.Reflection.Emit;
  9. namespace ItemLevelExtension.Patches
  10. {
  11. internal class MaxLevelGetter
  12. {
  13. public static int MaxLevel { get => Core.settingMaxItemLevel; }
  14. }
  15. [HarmonyPatch(typeof(PatchMethods))]
  16. [HarmonyPatch("HoverItem")]
  17. [HarmonyGadget("ItemLevelExtension")]
  18. public static class Patch_PatchMethods_HoverItem
  19. {
  20. [HarmonyTranspiler]
  21. public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator gen)
  22. {
  23. var p = TranspilerHelper.CreateProcessor(instructions, gen);
  24. var ilRefs = p.FindAllRefsByInsn(new CodeInstruction(OpCodes.Ldc_I4_S, 10));
  25. MethodInfo getValue = typeof(MaxLevelGetter).GetProperty("MaxLevel").GetGetMethod();
  26. foreach (var ilRef in ilRefs)
  27. {
  28. //p.InjectInsn(ilRef, new CodeInstruction(OpCodes.Ldc_I4_S, 12), false);
  29. p.InjectInsn(ilRef, new CodeInstruction(OpCodes.Call, getValue), false);
  30. }
  31. return p.Insns;
  32. }
  33. }
  34. }