proxy.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using com.bbbirder.injection;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Reflection;
  6. using System.Runtime.CompilerServices;
  7. using UnityEngine;
  8. public class FirstPatch
  9. {
  10. // the field to be overwrited to original method
  11. static Action<string> RawLog;
  12. public delegate void func();
  13. static void Logxxx(string msg)
  14. {
  15. Debug.Log("xxxxxxxxxxxxx:"+msg);
  16. RawLog.Invoke(msg);
  17. }
  18. static Func<int> bar_raw;
  19. static int NoArg()
  20. {
  21. var rt = bar_raw();
  22. Debug.Log("no arg:"+rt);
  23. return rt;
  24. }
  25. static int buff_1101()
  26. {
  27. Debug.Log("buff_1101 actived");
  28. return 1;
  29. }
  30. static void dummy(string msg) { }
  31. static BindingFlags bindingFlags = 0
  32. | BindingFlags.Public
  33. | BindingFlags.NonPublic
  34. | BindingFlags.Static
  35. ;
  36. internal class MethodReplacer : IInjection
  37. {
  38. // implement method: ProvideInjections
  39. public IEnumerable<InjectionInfo> ProvideInjections()
  40. {
  41. var target = typeof(Battle.PseudocodeSet).GetMethod(nameof(Battle.PseudocodeSet.foo));
  42. var replace = typeof(FirstPatch).GetMethod(nameof(Logxxx), bindingFlags);
  43. yield return InjectionInfo.Create(
  44. target, replace,
  45. f => RawLog = (Action<string>)f // save origin method to FirstPatch.RawLog
  46. );
  47. yield return InjectionInfo.Create<Func<int>>(
  48. Battle.PseudocodeSet.bar,
  49. FirstPatch.NoArg,
  50. f => bar_raw = f
  51. );
  52. var buff_1101_func = typeof(FirstPatch).GetMethod(nameof(buff_1101), bindingFlags);
  53. yield return InjectionInfo.Create(
  54. typeof(Battle.PseudocodeSet),
  55. nameof(FirstPatch.buff_1101),
  56. buff_1101_func
  57. );
  58. }
  59. }
  60. }