Unity Mod Manager
repository·master·Indexed 19 days ago
https://github.com/newman55/unity-mod-managerA framework for adding modding capabilities to Unity-based games. It enables the loading and management of mods through automated patching and injection techniques, supporting both Assembly Injection and Doorstop Proxy installation methods.
What's inside unity-mod-manager
- unity-mod-manager is a tool designed to add modding support to games built using the Unity engine. It facilitates the loading and management of mods by leveraging various patching and injection libraries.
Installation methods for Unity Mod Manager
masterUnity Mod Manager supports two primary installation methods to hook into a Unity game. The availability of these methods depends on the platform (Unix/Mac vs Windows) and whether a Doorstop proxy is already present:
- Assembly Injection (
InstallType.Assembly): Modifies the game's entry assembly to inject the manager. This is the standard method for Windows games. - Doorstop Proxy (
InstallType.DoorstopProxy): Uses a native DLL (winhttp.dllor architecture-specific variants) to intercept the game process and load the manager. This is often used when assembly injection is not feasible or preferred.
Note: On Unix-based platforms, the
DoorstopProxymethod is unavailable, and the system defaults toAssemblyinjection.- Assembly Injection (
Install Unity Mod Manager via the Install action
masterThe
Actions.Installworkflow performs a patch injection into a game assembly to enable Unity Mod Manager.Workflow steps:
- Backup: Creates backups of the target assembly, library destination paths, and game configuration.
- Assembly Patching:
- Locates the entry point of the target assembly.
- Injects the
UnityModManagerStarter.Startmethod into the assembly's entry point (either at the beginning or the end of the method body). - Writes the modified assembly back to the disk.
- Library Deployment: Copies required DLLs from
librarySourcePathstolibraryDestPaths. - Configuration: Exports game-specific configuration files using
selectedGame.ExportToGame().
If any step fails, the process attempts to restore the original files from the created backups.
// Conceptual representation of the Install logic flow if (action == Actions.Install) { Utils.MakeBackup(assemblyPath); Utils.MakeBackup(libraryDestPaths); // ... Injecting UnityModManagerStarter.Start into assemblyDef ... assemblyDef.Write(assemblyPath); DoactionLibraries(Actions.Install); DoactionGameConfig(Actions.Install); }Uninstall Unity Mod Manager via the Delete action
masterThe
Actions.Deleteworkflow removes the Unity Mod Manager patch and associated files from the game directory.Workflow steps:
- Detection: Identifies if the manager was installed using the legacy method (
UnityModManager.Start) or the newer method (UnityModManagerStarter.Start). - Instruction Removal: Locates the injected
Callinstruction at the assembly's entry point and removes it. - Type Removal: Removes the manager's type (e.g.,
UnityModManagerStarter) from the assembly. - File Cleanup:
- Deletes files in
libraryDestPaths. - Deletes any
.dllfiles found in themanagerPathdirectory. - Deletes the game configuration file located at
GameInfo.filepathInGame.
- Deletes files in
If the
writeflag is enabled, backups are created before modification and restored if an error occurs.// Conceptual representation of the Delete logic flow if (action == Actions.Delete) { // 1. Identify injected instruction (UnityModManager.Start or UnityModManagerStarter.Start) // 2. Remove instruction from methodDef.Body.Instructions // 3. Remove the manager type from assemblyDef.Types assemblyDef.Write(assemblyPath); DoactionLibraries(Actions.Delete); DoactionGameConfig(Actions.Delete); }- Detection: Identifies if the manager was installed using the legacy method (
Reference: Actions and LibIncParam flags
masterThe console uses bitwise flags to manage available user actions and library inclusion parameters during the installation process.
[Flags] enum Actions { Install = 1, Update = 2, Delete = 4, Restore = 8, Path = 16 } [Flags] enum LibIncParam { Normal = 0, Skip = 1, Minimal_lt_0_22 = 2, Harmony_2_2 = 4 }Manage library files and game configurations
masterThe CLI uses two internal helper methods to manage the side effects of installation and removal:
DoactionLibraries(Actions action)Handles the movement of DLLs required by the manager.
Actions.Install: Iterates throughlibraryDestPathsand copies files fromlibrarySourcePaths. It skips files if theLastWriteTimeUtcmatches the source.Actions.Delete: Deletes files atlibraryDestPathsand removes all*.dllfiles within themanagerPathdirectory.
DoactionGameConfig(Actions action)Handles the game-specific configuration files.
Actions.Install: CallsselectedGame.ExportToGame()to generate necessary config files (e.g.,Config.xml).Actions.Delete: Deletes the file located atGameInfo.filepathInGame.
Available commands in Unity Mod Manager Console
masterThe Unity Mod Manager Console provides a text-based interface to manage the installation of the manager into a Unity game. After selecting a game and verifying the path, you can perform the following actions using single-letter keys:
- I (Install): Installs the manager using the currently selected installation method (Assembly injection or Doorstop proxy).
- U (Update): Updates the existing installation to the current version of Unity Mod Manager.
- D (Delete): Removes the Unity Mod Manager files from the game directory.
- R (Restore): Restores the original game assembly if it was modified via assembly injection (requires the
.original_backup file to exist). - P (Path): Resets the game path selection to allow choosing a different game folder.
I. Install U. Update D. Delete R. Restore P. Path