Comments (7)
Latest master has support for MethodBase __originalMethod
from harmony.
Might be even better to allow passing some sort of arbitrary context object to provide a global state between calls to detour methods (like __state parameter allows preserving context inside a single method call, that new global state object will persist between calls and will be created together with the patch), what do you think?
from harmony.
I'm trying to do some profiler which starts a Stopwatch on the prefix and stops given Stopwatch on the postfix, to log its result and the method name. The prefix and postfix only have __instance and __state (__state = StopWatch) parameters and can be used for any method. But currently I can not use the same Prefix/Postfix for all methods, because I can not get the current patched methods name (except maybe some "hacky" way using StackTrace, which returns MethodName_PatchX; then using Regex to remove the _PatchX part. But this does not work for methods with overloads).
I'm not sure if that is possible using the context you described.
from harmony.
This conflicts with multiple assemblies patching the same method. Harmony must work across assembly boundaries and in order to have cumulative patches it serializes and deserializes patches to rebuild the final replacement method from all existing patches every time someone adds a new patch to the original.
So holding state for one particular original method consistently seems kind of hard and would require serialization of the data structures. It might even be that someone patches after you and thus your patch becomes part of their assembly and cannot handle its own types anymore since TypeA is not assignable from TypeA if they are from different assemblies.
My best guess would be to have the unchanging MethodBase from the original method as an injection parameter and you would need to have your own way to look up that in your own state. It could be called “MethodBase __original”.
from harmony.
I have already tried to add such a parameter, but it seems like its a bit tricky
from harmony.
A simple option would be to use the already provided Transpiler patch function. It can have the original method parameter as a parameter. It also has the advantage that you will get less overhead because you can implement your measurements without subroutine calls and that might save you some execution time too (depending on how time critical your patched methods are).
from harmony.
Thank you!
from harmony.
Related Issues (20)
- Native async patching is not available in .NET Standard or .NET HOT 2
- Can I use Transpiler to modify a readonly(const) value in .cctor? HOT 2
- When patching a compiler generated method from a nested class, how do I declare the __instance property? HOT 1
- How to patch a override method using Transpiler HOT 1
- IReadOnly<T> class for read-only all propertiest of type T HOT 1
- Make it easier to get an enumeration of inner types HOT 1
- harmony is not compatible with .net 8 . HOT 16
- Crash when accessing patched method through interface HOT 8
- Failed to patch DateTime.Now with .net 7.0 HOT 2
- AccessTools.Constructor behaving unexpectedly HOT 2
- Reverse patch for private class? HOT 2
- Is it possible to patch ALL the methods/properties/... in the given assembly/scope for the sake of ad-hoc execution logging? HOT 2
- Is it possible to apply all, but specified, patches? Alternative solution to [HarmonyPatchCategory] for Harmony < v2.3? HOT 1
- InvalidProgramException in Stride/Godot HOT 4
- Is it possible to insert a delegate into IL code? HOT 1
- Add strongname to make all projects can use this library HOT 2
- Seemingly random NOP invalid IL errors HOT 4
- Correct way to patch TWindow GetWindow<TWindow>() HOT 1
- Release a new prerelease for the updated Mono.Cecil
- Error in exported Godot Engine build when attempting to patch method 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.