3

How do you replace a method with parameters at runtime using Harmony in c#?

Filburt
  • 17,626
  • 12
  • 64
  • 115
jj5
  • 31
  • 1
  • 2

1 Answers1

3

There are multiple ways of replacing a method with Harmony. The most common one is adding a prefix that returns false and therefore skips the original.

Example:

// 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;
}
Andreas Pardeike
  • 4,622
  • 1
  • 17
  • 27