varassembly=Assembly.GetExecutingAssembly();harmony.PatchAll(assembly);// or implying current assembly:harmony.PatchAll();
注解HarmonyPatch用法如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
publicclassOriginalCode{publicvoidTest(intcounter,stringname){// ...}}[HarmonyPatch(typeof(OriginalCode), nameof(OriginalCode.Test))]classPatch{staticvoidPrefix(intcounter,refstringname){FileLog.Log("counter = "+counter);// readname="test";// write with ref keyword}}
手动模式 一个一个函数找对应关系patch
1
2
3
4
5
6
7
8
9
10
11
// add null checks to the following lines, they are omitted for clarity// when possible, don't use string and instead use nameof(...)varoriginal=typeof(TheClass).GetMethod("TheMethod");varprefix=typeof(MyPatchClass1).GetMethod("SomeMethod");varpostfix=typeof(MyPatchClass2).GetMethod("SomeMethod");harmony.Patch(original,newHarmonyMethod(prefix),newHarmonyMethod(postfix));// You can use named arguments to specify certain patch types only:harmony.Patch(original,postfix:newHarmonyMethod(postfix));harmony.Patch(original,prefix:newHarmonyMethod(prefix),transpiler:newHarmonyMethod(transpiler));