【问题标题】:How to patch methods using harmony如何使用和谐修补方法
【发布时间】:2020-07-27 07:09:23
【问题描述】:

如何在c#中使用Harmony在运行时用参数替换方法?

【问题讨论】:

    标签: c# class patch mod


    【解决方案1】:

    有多种方法可以用 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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-03
      • 2010-12-01
      • 2016-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多