How do you replace a method with parameters at runtime using Harmony in c#?
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With