Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TargetMethod() to Affinity #54

Open
Aeroluna opened this issue Aug 25, 2022 · 4 comments
Open

Add TargetMethod() to Affinity #54

Aeroluna opened this issue Aug 25, 2022 · 4 comments

Comments

@Aeroluna
Copy link
Contributor

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

@Auros
Copy link
Owner

Auros commented Aug 25, 2022

Could you provide an example of how you'd want this to look like with the Affinity system?

@Aeroluna
Copy link
Contributor Author

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()

@Auros
Copy link
Owner

Auros commented Aug 25, 2022

What about when you want multiple target methods for different affinity patches? How do you think they should be distinguished?

@Aeroluna
Copy link
Contributor Author

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants