【发布时间】:2020-07-27 07:09:23
【问题描述】:
如何在c#中使用Harmony在运行时用参数替换方法?
【问题讨论】:
如何在c#中使用Harmony在运行时用参数替换方法?
【问题讨论】:
有多种方法可以用 Harmony 替换方法。最常见的是添加返回 false 的前缀,因此会跳过原始前缀。
例子:
// this is the original method you want to replace
class TheClass {
string TheOriginal(int foo, List<string> bar) { … }
}
// I will skip the basic setup of Harmony and only show you the prefix
static bool Prefix(int foo, List<string> bar, ref string __result, TheClass __instance)
{
// access “this” in the original
__instance.SomeOtherMethod();
// use originals input parameters
Log(bar);
// return your own result
__result = ”…”;
// return false to skip the original
return false;
}
【讨论】: