Add TargetMethod() to Affinity
Useful to getting types that are not available at compile time Adding TargetMethods() too would be nice https://harmony.pardeike.net/articles/patching-auxilary.html#auxilary-patch-methods
Could you provide an example of how you'd want this to look like with the Affinity system?
Adding a [AffinityTargetMethod] attribute to complement [HarmonyTargetMethod]
Instead of needing to specific method to patch from [AffinityPatch], call a method that returns what method to patch.
[HarmonyTargetMethod]
private static MethodBase CalculateMethod()
[AffinityTargetMethod]
private MethodBase CalculateMethod()
An example is where you need to target a private type
[AffinityPostfix]
[AffinityPatch(typeof(BeatmapObjectsInTimeRowProcessor.SliderTailData), "GetCopy")]
// not possible, as this is a private class
private void Postfix()
[AffinityTargetMethod]
private MethodBase TargetMethod()
{
Type type = Type.GetType("BeatmapObjectsInTimeRowProcessor+SliderTailData,BeatmapCore");
return AccessTools.Method(type, "GetCopy");
}
[AffinityPostfix]
private void Postfix()
What about when you want multiple target methods for different affinity patches? How do you think they should be distinguished?
Following how Harmony does it: only allow one target method for a class and disallow using individual annotations with [AffinityTargetMethod]
https://github.com/BepInEx/HarmonyX/blob/master/Harmony/Public/PatchClassProcessor.cs#L142
[AffinityTargetMethod]
private MethodBase TargetMethod()
{
return AccessTools.Method(typeof(something), "something");
}
[AffinityPostfix]
[AffinityPatch(typeof(something), "something")]
// invalid to use this while [AffinityTargetMethod] defined and will throw
private void Postfix()