Comments (6)
[HarmonyPatchAll]
was implemented in 99f922f. This completes this issue.
from harmony.
Interesting idea. As you said, a bit of a special case and I doubt how useful it would be for the average user. Also, don't forget that in order to allow multiple Harmony instances to patch the same methods, the shared state needs to be safe to serialize over assembly boundaries. Currently, I only refer to static patch methods as MethodBase is easily transferable. Once you get into other stateful matters it becomes tricky to implement.
But you're welcome to suggest a design that would work. Maybe a patch method that only gets (a possible null) object __instance
and a MethodBase __originalMethod
variable? Maybe even what some other Issue here lifted: a generic object[] __arguments
like this:
[HarmonyPatch(typeof(SomeClass))]
[HarmonyPatchAll]
static class MyPatches
{
static bool Prefix(object __instance, MethodBase __originalMethod, object[] __arguments)
{
// code
return false;
}
}
What do you think?
from harmony.
That's basically what I was thinking. Around Monday-Tuesday I'll have some time, I'll check out your code for annotating and see if I can make a pull request to match that interface (including postfix, but certainly not transpiler).
from harmony.
Got a basic working version, though a quick question came up:
There's an error thrown for trying to get an instance variable from static methods, meaning that patching all methods would almost never work with the __instance parameter, or we remove the error and just set the instance variable to null if the method is a static method and the __instance variable is requested. Which would you prefer?
The working null __instance variable code looks like:
if (patchParam.Name == INSTANCE_PARAM)
{
if (!isInstance)
Emitter.Emit(il, OpCodes.Ldnull);
else if (patchParam.ParameterType.IsByRef)
Emitter.Emit(il, OpCodes.Ldarga, 0); // probably won't work or will be useless
else
Emitter.Emit(il, OpCodes.Ldarg_0);
continue;
}
The last thing I want to add is the ability to allow something like:
[HarmonyPatchAll(BindingFlags.Public)]
Thoughts? Pull request should come in the next few days.
from harmony.
A few reflections:
-
null is fine and goes well with the Invoke() conventions users know
-
make sure you reuse/extend existing routines for argument handling but I wait until a pr - pretty sure you do that already
-
regarding the attribute: so far, the convention in Harmony was that it does not discriminate between public/private and I would love to continue to keep it that way. Adding a similar mechanic like TargetMethod (in plural though) would give special case users better control (i.e patching all public getters)
from harmony.
Added support for __originalMethod. Still left to implement [HarmonyPatchAll]
from harmony.
Related Issues (20)
- Patch on .net 7&8 throw TypeLoadException while debugging HOT 18
- Harmony 3.0: Utility Epic
- Investigate Testing the NuGet Package Directly HOT 3
- Add a Release Pipeline
- Hook exception: System.Exception: Cannot get result from void method System.Void HOT 2
- How to patch method of base class? HOT 1
- When applying a patch fails, the replacement's IL is not printed to the debug log HOT 2
- System.Exception: Parameter "xx" not found in method HOT 10
- SymbolExtensions does not resolve overriden method HOT 3
- can lib work in arm64? HOT 2
- Companion project promotion: Harmony Tools HOT 3
- PatchFunctions.UpdateWrapper NotImplementedException on MacOS HOT 11
- How do i change valuetype HOT 1
- Harmony.Patch() is a bit slow. HOT 2
- 'CORINFO_METHOD_INFO' from assembly 'System.Text.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. HOT 4
- I try to hook DateTime.UtcNow but it throw exception HOT 5
- x86 platform makes patch fail
- return type only support void and bool? why doesn't string work HOT 1
- Could not load type 'CORINFO_METHOD_INFO' from assembly 'System.Text.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. HOT 1
- "ref" keyword not allowed for "__runOriginal" HOT 5
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 harmony.