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 RawLog; public delegate void func(); static void Logxxx(string msg) { Debug.Log("xxxxxxxxxxxxx:"+msg); RawLog.Invoke(msg); } static Func 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 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)f // save origin method to FirstPatch.RawLog ); yield return InjectionInfo.Create>( 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 ); } } }