pardeike / Harmony

A library for patching, replacing and decorating .NET and Mono methods during runtime
https://www.patreon.com/pardeike
MIT License
5.28k stars 492 forks source link

Can this inject code on any unity game? #60

Closed i30817 closed 6 years ago

i30817 commented 6 years ago

I'm looking to mod shadowrun returns on a 'semi-portable' way. I did the hack i wanted before by injecting IL code into the assembly (with a tool i forget), but then changed version of the game from windows to linux (and it updated) and it all got lost, and i was tired of editing those methods one at a time in a that awful language.

As far as i can tell this is almost ideal... except it doesn't have a example of how to hook into a commercial unity game dll that is not prepared part of your project already, afaict (that's the vibe i get from the Rimworld examples, might be wrong).

Is there some general crossplatform injection loader i'm missing?

erdelf commented 6 years ago

Not the author, but take a look at dnspy, it allows you to edit an assembly in c#. And yeah, rimworld loads mod dlls by itself. As far as I know, harmony doesn't have an injection loader by itself.

Author is currently in Africa and doesn't have internet for most of this month.

i30817 commented 6 years ago

Actually, this project looks promising: https://github.com/HearthSim/UnityHook

It apparently has a class dedicated exclusively to direct the library to the games assemblies on various platform specific locations. Unfortunately it only runs code after function returns apparently while i pretty much need to run it on arguments (replace a argument to be specific). Could be a source of ideas for a injection framework.

erdelf commented 6 years ago

You could use that to insert a call that loads yours and harmony's dlls very early.

Trojaner commented 6 years ago

Harmony works with Unity on Linux and Windows (tested with .Net subset 3.5, I dont know if it will work with 4.6 too)

pardeike commented 6 years ago

The purpose of Harmony is to patch code. I leave injecting the initial code into applications to someone else.