Really easy way to attach a debugger to your mod. Easily togglable, no modifications to Unity Mono or HK needed
(techniques stolen borrowed/adapted from BepInEx and RoR2 documentation)
- Install Unity Doorstop. Find the release for your OS and extract it next to your game files in the Hollow Knight folder (the files should be adjacent to your executable).
- Set up your Doorstop configuration. I've included mine here; on Windows you can just paste that in the same directory.
On linux/macos you'll either need to modify the parameters in run.sh (recommended) or provide these options as command
line arguments to run.sh. You can use the included ini file as reference, the options are roughly 1:1.
- Note that you can point the target_assembly to any DLL, including a custom doorstop entry point if you choose. However, Doorstop runs very early in the runtime, before most Unity types are loaded, and will choke if you accidentally or intentionally reference one - there's not a ton useful you can do with it.
- Run the game. On Windows, start the game normally. Doorstop will inject itself automatically; you can disable it by changing
enabled=false
in the config file. On linux/mac, use run.sh as specified by the documentation in that file. - Attach a Unity debugger of your choosing and do some debugging.
- Visual Studio: install the unity workload following these instructions. The debugger can be attached from Debug -> Attach Unity Debugger -> Input IP and input the connection details as defined by your Doorstop config. Optionally, install the RoR2 UnityModExtension which can be configured in Tools -> Options -> Unity Mod and provides a convenience function to start the game and attach the debugger.
- dnSpy: Go to Debug -> Start Debugging. For "Debug Engine," select "Unity (connect)." Input the connection details as defined by your Doorstop config.