ioncodes / dnpatch

.NET Patcher library using dnlib
MIT License
313 stars 48 forks source link

Adding instructions #18

Closed erherhh4herh closed 7 years ago

erherhh4herh commented 7 years ago

This is probably a stupid question, but does Patcher.Patch() add instructions to a method body at a given index without replacing the entire thing? If not, how would I do so?

Also, when I do this: what it should do: http://i.imgur.com/NTUPHRd.png (calls static method in the default namespace from another assembly) in code: http://i.imgur.com/fNsbefL.png

I get this error: "Error: dnlib.DotNet.Writer.ModuleWriterException: Error calculating max stack value."

Any help is greatly appreciated, erherhh4herh.

ioncodes commented 7 years ago

As for the first question: That's not implemented, it will be added later, I'm pretty busy atm. Please make a new issue with that feature request. A little workaround would be to get the methodbody and loop through the instructions and insert new instructions after reaching the point where you want to inject opcodes. Then add the other opcodes again. Create a target from that, and call .Patch() and it will overwrite it.

As for the second question: I need more information about the issue. Can you refer me to that project?

erherhh4herh commented 7 years ago

It's adding a hook to a modding api dll i created to a script in the game Subnautica (unity engine game). It accesses a DLL containing the entry point which is in the default namespace, so all i had to do in dnspy was add a reference to the dll and then bam, it gave me those instructions (with the methodbody C# editor). Can't really send you the scripts for legal reasons, but it shouldn't be a problem since i found another way to do things. Thank you for your help, though!

ioncodes commented 7 years ago

Ok, I will close this Issue then...