Base class has method, child inherited it. How can i patch this method throught child
using HarmonyLib;
namespace TestHarmony.VirtualMethodPatching
{
class Program
{
static void Main(string[] args)
{
Harmony harmony = new(nameof(TestHarmony));
harmony.PatchAll(typeof(Program).Assembly);
Subclass instance = new();
instance.OnDestroy();
Console.ReadKey();
}
}
public class Subclass : BaseClass
{
// Has OnDestroy() that calls BaseClass.OnDestroy() as default behaviour
}
public class BaseClass
{
public virtual void OnDestroy()
{
Console.WriteLine("BaseClass");
}
}
// It's trying to patch OnDestroy method of Subclass which is BaseClass.OnDestroy
[HarmonyPatch(typeof(Subclass))]
[HarmonyPatch("OnDestroy")]
static class LocationPatch
{
public static void Prefix()
{
Console.WriteLine("Prefix");
}
}
}
Base class has method, child inherited it. How can i patch this method throught child