Home

Awesome

<p align="center"> <img height="256" width="256" src="assets/img/icon.png"> </p> <h1 align="center">Unity Doorstop</h1>

GitHub Workflow Status nightly.link artifacts


Doorstop is a tool to execute managed .NET assemblies inside Unity as early as possible.

This is a total rewrite of UnityDoorstop 3. See list of breaking changes for more information.

Features

Unity runtime support

Doorstop supports executing .NET assemblies in both Unity Mono and Il2Cpp runtimes. Depending on the runtime the game uses, Doorstop tries to run your assembly as follows:

Building

Doorstop uses xmake to build the project. To build, run build.bat, build.ps1 or build.sh.

Available build options:

Note: Initial build times are usually slower because the build script automatically downloads and installs xmake.
On Unix, xmake is built directly from the source code.

Minimal injection example

To have Doorstop inject your code, create Entrypoint class into Doorstop namespace. Define a public static Start method in it:

using System.IO;

namespace Doorstop;

class Entrypoint
{
  public static void Start()
  {
      File.WriteAllText("doorstop_hello.log", "Hello from Unity!");
  }
}

You can then define any code you want in Start.

NOTE: On UnityMono, Doorstop bootstraps your assembly with a minimal number of assemblies and minimal configuration. This early execution allows for some interesting tricks, like redirecting the loading of some game assemblies. Bear also in mind that some of the Unity runtime is not initialized at such an early stage, limiting the code you can execute. You might need to appropriately pause the execution of your code until the moment you want to modify the game.

Doorstop environment variables

Doorstop sets some environment variables useful for code execution:

Environment variableDescription
DOORSTOP_INITIALIZEDAlways set to TRUE. Use to determine if your code is run via Doorstop.
DOORSTOP_INVOKE_DLL_PATHPath to the assembly executed by Doorstop relative to the current working directory.
DOORSTOP_PROCESS_PATHPath to the application executable where the injected assembly is run.
DOORSTOP_MANAGED_FOLDER_DIRUnityMono: Path to the game's Managed folder. Il2Cpp: Path to CoreCLR's base class library folder.
DOORSTOP_DLL_SEARCH_DIRSPaths where the runtime searchs assemblies from by default, separated by OS-specific separator (; on windows and : on *nix).
DOORSTOP_MONO_LIB_PATHOnly on UnityMono: Full path to the mono runtime library.

Debugging

Doorstop 4 supports debugging the assemblies in the runtime.

Debugging in UnityMono

To enable debugging, set debug_enabled to true and optionally change the debug server address via debug_address (see configuration options).
After launching the game, you may connect to the debugger using the server address (default is 127.0.0.1:10000).
By default, the game won't wait for the debugger to connect; you may change the behaviour with the debug_suspend option.

If you use dnSpy, you can use the Debug > Start Debugging > Debug engine > Unity option, automatically setting the correct debugging configuration.
Doorstop detects dnSpy and automatically enables debugging without any extra configuration.

Debugging in Il2Cpp

Debugging is automatically enabled in CoreCLR.

To start debugging, compile your DLL in debug mode (with embedded or portable symbols) and start the game with the debugger of your choice.
Alternatively, attach a debugger to the game once it is running. All standard CoreCLR debuggers should detect the CoreCLR runtime in the game.

Moreover, hot reloading is supported for Visual Studio, Rider and other debuggers with .NET 6 hot reloading feature enabled.

Note that you can only debug managed code! Because the game code is unmanaged (i.e. Il2Cpp), you cannot directly debug the actual game code. Consider using native debuggers like GDB and visual debugging tools like IDA or Ghidra to debug actual game code.

Doorstop configuration

Doorstop is highly configurable based on your needs and the environment you want to use. There are two ways to configure Doorstop: via config and CLI arguments.

Via configuration file

Refer to doorstop_config.ini (Windows) or run.sh for all available configuration options.

CLI arguments

The following CLI arguments are available on both *nix, and Windows builds:

All Doorstop arguments start with --doorstop- and always contain an argument. The arguments can be of the following type:

ArgumentDescription
--doorstop-enabled boolEnable or disable Doorstop.
--doorstop-redirect-output-log boolOnly on Windows: If true Unity's output log is redirected to <current folder>\output_log.txt
--doorstop-target-assembly stringPath to the assembly to load and execute.
--doorstop-boot-config-override stringOverrides the boot.config file path.
--doorstop-mono-dll-search-path-override stringOverrides default Mono DLL search path
--doorstop-mono-debug-enabled boolIf true, Mono debugger server will be enabled
--doorstop-mono-debug-suspend boolWhether to suspend the game execution until the debugger is attached.
--doorstop-mono-debug-address stringThe address to use for the Mono debugger server.
--doorstop-clr-corlib-dir stringPath to coreclr library that contains the CoreCLR runtime
--doorstop-clr-runtime-coreclr-path stringPath to the directory containing the managed core libraries for CoreCLR (mscorlib, System, etc.)

License

Doorstop 4 is licensed under LGPLv2.1. You can view the entire license here.
You can still access the source code to the original UnityDoorstop 3 source (licensed under CC0) from the legacy branch.