BepInEx / Il2CppInterop

A tool interoperate between CoreCLR and Il2Cpp at runtime
GNU Lesser General Public License v3.0
185 stars 59 forks source link

Assembly injection #93

Open limoka opened 1 year ago

limoka commented 1 year ago

This PR allows users classes to be injected into assembly with the same name as their mod assembly, instead of InjectedMonoTypes. There are two benefits from this:

  1. Users can declare their assemblies in Unity Editor using asmdefs or use custom precompiled assemblies
  2. Because types exist in the correct assembly according to il2cpp runtime, any code which checks assembly will work correctly. For example Burst runtime checks assembly name, so with this change adding custom Bursted code becomes possible.

The changes are backwards compatible. Despite the classes now being defined in the mod assembly, they will still correctly deserialize because we inject classes into every assembly that exists.

To implement this I had to determine a list of possible assemblies very early, so plugins folder scanning is performed. Also I needed to modify contents of ScriptingAssemblies.json file in the game Data folder, because Unity seems to get a list of assemblies from there. A backup of original is created.

I have implemented IAT hooking, so no files are modified now. Assembly scanning now should be performed by mod loader by adding AssemblyInjectorComponent.

I have tested these changes on Core Keeper Unity 2021.3.14.