dnSpy Debugging
Due to the in-memory patching introduced in BepInEx 4.0, it is not possible to use dnSpy to debug plugins with the base installation of BepInEx. Instead, the developers must use the modified BepInEx.Patcher.exe
.
NOTE
The dnSpy-compatible BepInEx patcher does not support in-memory preloader patchers!
Thus, you can only debug normal plug-ins.
Currently, the new BepinEx.Patcher.exe
not available as a prebuilt binary. The developers must build the patcher from source manually.
To set up BepInEx to work with dnSpy debugger, do the following:
-
Build latest BepInEx from source. You must build the following projects:
BepInEx
BepInEx.Bootstrap
BepInEx.Patcher
-
Place fresh
BepInEx.dll
,0Harmony.dll
andMono.Cecil.dll
to<Game Root>/BepInEx/core
-
Place
BepInEx.Patcher.exe
into the game's root folder -
Run
BepInEx.Patcher.exe
. This will patch game'sUnityEngine.dll
and placeBepInEx.Bootstrap.dll
into the game'sManaged
folder. -
Modify
doorstop_config.ini
as follows:enabled=false
- Download the latest version of dnSpy and an appropritate version of Unity-debugging package
- From the downloaded Unity-debugging package, pick
mono.dll
that corresponds to the version of the game you want to debug and replace the game's originalmono.dll
with it - Open dnSpy and open the plugin DLL (from
BepInEx
folder) you want to debug. Additionally, open game's own assemblies to debug (fromManaged
folder) - Set up appropriate breakpoints
- Open
Debug > Start Debugging
dialogue - Select
Unity
as the Debug engine, select the game's EXE (not the launcher) and press OK to start debugging
If everything worked correctly, dnSpy will not time out in 30 seconds (or in whatever timeout time you configured) and will break on any breakpoint you set.
When you don't want to debug anymore, you can revert back to the original game installation as follows:
-
Restore
mono.dll
to the original version -
From every
Managed
folder found in the game's root (or its subfolders), removeBepInEx.Bootstrap.dll
and restoreUnityEngine.dll.bak
-
Edit
doorstop_config.ini
as follows:enabled=true