[Mono-dev] Unity - patching methods
Ivo Smits
Ivo at UFO-Net.nl
Sun Jan 22 12:41:31 UTC 2017
Hi Andreas,
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.
--
Ivo
Op 21-1-2017 om 13:46 schreef pardeike:
> Hi,
> I am trying to replace methods during runtime. Lots of existing ways do this
> by
> simply inserting a jump at assembler level from the original to the new
> method.
> 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
> expert
> in when mono jitts its methods and vaguely know about trampolines and it
> looks
> 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
> gives
> 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
> experienced
> developer but just not familiar with the specific area. I can read c# and c
> and
> tried to understand the mono repository code and will continue to do so. I
> though
> it would be nice to ask in parallel here.
>
> Thanks,
> Andreas
>
> 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
> http://lists.dot.net/mailman/listinfo/mono-devel-list
More information about the Mono-devel-list
mailing list