Skip to content

dnSpy Debugging

Geoffrey Horsington edited this page Aug 1, 2018 · 10 revisions

Debugging with dnSpy

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.

Setting up BepInEx

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:

  1. Build latest BepInEx from source. You must build the following projects:

    • BepInEx
    • BepInEx.Bootstrap
    • BepInEx.Patcher
  2. Place fresh BepInEx.dll, 0Harmony.dll and Mono.Cecil.dll to <Game Root>/BepInEx/core

  3. Place BepInEx.Patcher.exe into the game's root folder

  4. Run BepInEx.Patcher.exe. This will patch game's UnityEngine.dll and place BepInEx.Bootstrap.dll into the game's Managed folder.

  5. Modify doorstop_config.ini as follows:

    enabled=false

Setting up dnSpy

  1. Download the latest version of dnSpy and an appropritate version of Unity-debugging package
  2. 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 original mono.dll with it
  3. Open dnSpy and open the plugin DLL (from BepInEx folder) you want to debug. Additionally, open game's own assemblies to debug (from Managed folder)
  4. Set up appropriate breakpoints
  5. Open Debug > Start Debugging dialogue
  6. 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.

Reverting back to original BepInEx

When you don't want to debug anymore, you can revert back to the original game installation as follows:

  1. Restore mono.dll to the original version

  2. From every Managed folder found in the game's root (or its subfolders), remove BepInEx.Bootstrap.dll and restore UnityEngine.dll.bak

  3. Edit doorstop_config.ini as follows:

    enabled=true