| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using com.bbbirder.injection;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Reflection;
- using System.Runtime.CompilerServices;
- using UnityEngine;
- public class FirstPatch
- {
- // the field to be overwrited to original method
- static Action<string> RawLog;
- public delegate void func();
- static void Logxxx(string msg)
- {
- Debug.Log("xxxxxxxxxxxxx:"+msg);
- RawLog.Invoke(msg);
- }
- static Func<int> bar_raw;
- static int NoArg()
- {
- var rt = bar_raw();
- Debug.Log("no arg:"+rt);
- return rt;
- }
- static int buff_1101()
- {
- Debug.Log("buff_1101 actived");
- return 1;
- }
- static void dummy(string msg) { }
- static BindingFlags bindingFlags = 0
- | BindingFlags.Public
- | BindingFlags.NonPublic
- | BindingFlags.Static
- ;
- internal class MethodReplacer : IInjection
- {
- // implement method: ProvideInjections
- public IEnumerable<InjectionInfo> ProvideInjections()
- {
- var target = typeof(Battle.PseudocodeSet).GetMethod(nameof(Battle.PseudocodeSet.foo));
- var replace = typeof(FirstPatch).GetMethod(nameof(Logxxx), bindingFlags);
- yield return InjectionInfo.Create(
- target, replace,
- f => RawLog = (Action<string>)f // save origin method to FirstPatch.RawLog
- );
- yield return InjectionInfo.Create<Func<int>>(
- Battle.PseudocodeSet.bar,
- FirstPatch.NoArg,
- f => bar_raw = f
- );
- var buff_1101_func = typeof(FirstPatch).GetMethod(nameof(buff_1101), bindingFlags);
- yield return InjectionInfo.Create(
- typeof(Battle.PseudocodeSet),
- nameof(FirstPatch.buff_1101),
- buff_1101_func
- );
- }
- }
- }
|