[Mono-dev] Unity - patching methods
Ivo at UFO-Net.nl
Sun Jan 22 12:41:31 UTC 2017
One thing I found out is that when using
Marshal.GetDelegateForFunctionPointer, you need to keep a (managed)
reference to the delegate used to construct the function pointer around
as well. Otherwise the GC may clean up the delegate and the function
pointer will become invalid - although I did get a message informing me
that the handle had been cleaned instead of an immediate crash.
Op 21-1-2017 om 13:46 schreef pardeike:
> I am trying to replace methods during runtime. Lots of existing ways do this
> simply inserting a jump at assembler level from the original to the new
> I want to do this too but with the new method being a DynamicMethod (or a
> delegate to it).
> I did solve the IL part of it but testing it with a game (RimWorld) that
> uses Unity
> I find it crashes when I try my code with more than one method. I am no
> in when mono jitts its methods and vaguely know about trampolines and it
> like the memory area that you get with GetFunctionPtr() does change compared
> to when I write a jump to it into the original and that changed assembler
> me all sort of crashes. Interestingly, the other method using exactly the
> same way
> to patch it works.
> So any pointers, ideas or suggestions welcome. I am in general an
> developer but just not familiar with the specific area. I can read c# and c
> tried to understand the mono repository code and will continue to do so. I
> it would be nice to ask in parallel here.
> PS: my (not complete project) is here: https://github.com/pardeike/Harmony
> View this message in context: http://mono.1490590.n4.nabble.com/Unity-patching-methods-tp4669765.html
> Sent from the Mono - Dev mailing list archive at Nabble.com.
> Mono-devel-list mailing list
> Mono-devel-list at lists.dot.net
More information about the Mono-devel-list