Comments (7)
Did a bit of testing, and can confirm this is an issue in latest HarmonyX with a minimal example DSPMultiplePatchTest.zip
but there is a very notable distinction to make, which can be seen by looking at the patch classes.
[HarmonyPatch(typeof(UIEscMenu))]
public static class PatchesFail
{
[HarmonyPrefix]
[HarmonyPatch(nameof(UIEscMenu.OnButton5Click))]
[HarmonyPatch(nameof(UIEscMenu.OnButton6Click))]
public static void TestPrefix(MethodBase __originalMethod)
{
Class1.Logger.LogMessage($"This should fail for Quit Game (5) or Exit to Desktop (6): {__originalMethod.Name}");
}
}
[HarmonyPatch]
public static class PatchesSucceed
{
[HarmonyPrefix]
[HarmonyPatch(typeof(UIEscMenu), nameof(UIEscMenu.OnButton5Click))]
[HarmonyPatch(typeof(UIEscMenu), nameof(UIEscMenu.OnButton6Click))]
public static void TestPrefix(MethodBase __originalMethod)
{
Class1.Logger.LogMessage($"This should succeed for Quit Game (5) and Exit to Desktop (6): {__originalMethod.Name}");
}
}
The top fails, the bottom succeeds. This leads me to believe the error is somewhere in attribute merging, but I haven't gotten to narrowing it down yet.
from harmonyx.
Going to confirm here: the multitargeting syntax @Windows10CE shows in PatchesFail
was never intended for class patches.
While Harmony 2 does allow you to write class patches as shown in https://harmony.pardeike.net/articles/annotations.html#combining-annotations, it does not allow you to write multiple HarmonyPatch
attributes on the same method.
The syntax shown in the PatchesSucceed
is the new additional syntax for HarmonyX that was actually intended for everyone's use if you use method patching. If you specify multiple HarmonyPatch
attributes that include both type and method name, HarmonyX does not merge them but instead treats them as separate targets. Those are so-called "complete" patch targets.
Nevertheless, I don't see why one couldn't allow multitargeting in class patches provided that at least one of the two holds:
- There is
[HarmonyPatch(typeof(Foo))]
attribute on the type - There is
[HarmonyPatch(typeof(Foo), "Name")]
attribute on the method
I'll add this feature, test it and close the issue once it's fixed.
from harmonyx.
Alright, I've managed to track down where this came from, although I'm not entirely sure whether or not it's an actual bug or just poorly documented. The behavior comes from this line, where it confirms that each attribute is "complete" as defined by https://github.com/BepInEx/HarmonyX/wiki/Multitargeted-patches .
HarmonyX/Harmony/Internal/PatchModels.cs
Line 123 in c0f6004
I'm not sure how this worked in earlier versions of DSP, maybe it's been broken the whole time and just didn't throw an NRE previously? Whether or not it's a bug to try and be fixed is up to @ghorsington rather than me, if it's to be left as is I'll probably add more emphasis to the multi-patch wiki page about each attribute needing to be complete on it's own, with nothing coming from attributes on the patch class.
from harmonyx.
I'm not sure how this worked in earlier versions of DSP, maybe it's been broken the whole time and just didn't throw an NRE previously?
It definitely runs in 0.6.x, I just double-checked by throwing a log statement in there and it prints as expected.
If this isn't intended behavior it's fine then, but I think the format makes more sense than having to specify the type in each line and it worked well up until now.
from harmonyx.
The top version working was unintended I believe, the assumption always was that you provide all information in single attributes when multi-targeting.
from harmonyx.
Just reporting back because I didn't realize where that format came from, but it's actually from Harmony's documentation:
https://harmony.pardeike.net/articles/annotations.html#combining-annotations
from harmonyx.
The documentation is for the per-assembly patching method which is used in stock harmony, not per-type patching which is unique to harmonyx.
from harmonyx.
Related Issues (20)
- [Wiki] Typos in section 1.4 HOT 1
- [Wiki] Error using the provided postfix in section 1.4 HOT 1
- When will v2.11.0 be published on NuGet? HOT 2
- Android IL2CPP Support
- v2.11.0: patch with "ref string" on "static external" method produces garbage HOT 5
- Harmony doesn't work when path contains non-ANSI characters HOT 1
- How do I call a private function within a postpatch HOT 8
- How do I find the asset directory of stuff stored in a unity game? HOT 1
- Pass-through transpiler messes up leave labels in inner `MoveNext()` with `try/finally` block HOT 2
- IDK HOT 2
- Does it support NET6? HOT 1
- Label Jump HOT 2
- Empty Transpiler Causing Issues HOT 1
- How to override explicit interface methods? HOT 1
- When did it start to support net 7 or 8? HOT 1
- Cannot unpatch extern method patch
- Patching ref parameter with IL2Cpp results in invalid IL
- Usage with unity
- Empty Harmony Annotations Cause ArguementException: No Target Method Found HOT 2
- Skipping a patch when a method isnt found HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from harmonyx.