Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assembly injection #93

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Conversation

limoka
Copy link
Contributor

@limoka limoka commented May 29, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants