Debugging - NUCLEAR-BOMB/dig-or-die-mods GitHub Wiki
Debugging
[!NOTE] Guide based on BepInEx's "Debugging with dnSpy" article and dnSpyEx's "Debugging Unity Games" article
Turning the game into a debug build
First, the game's mono runtime has to be swapped to one that supports debugging with dnSpy.
Automated installation
-
Download Powershell script from
Install-BepInEx.ps1
In the top right, right click theRaw
button -
Open Powershell where you download the
Install-BepInEx.ps1
script
Go to the folder location and typepowershell.exe
on the address bar. -
Run the following command to execute script and install BepInEx with debug Mono:
.\Install-BepInEx.ps1 -InstallMonoDebug
[!IMPORTANT] If Powershell script execution is disable, start Windows Powershell with the "Run as Administrator" option and allow running unsigned scripts by entering:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Manual installation
You can download debug Mono packages of 5.x Unity version in liesauer/Unity-debugging-dlls Github Releases.
Open the downloaded Unity-debugging-5.x.zip
archive and go to Unity-debugging/unity-5.4.1/win32/
, there should be one file named mono.dll
.
Next, head to Dig or Die/DigOrDie_Data/Mono/
folder which should contain mono.dll
and etc/
.
Rename mono.dll
to mono.dll.old
.
Extract the mono.dll
from downloaded Unity-debugging-5.x.zip
archive into Dig or Die/DigOrDie_Data/Mono/
folder (it should contain mono.dll
, mono.dll.old
, etc/
).
Running the game via dnSpy
Open dnSpy and select Debug > Start Debugging (F5)
to open up the Debug Program dialog.
Change Debug engine to Unity (Connect)
. Leave field IP Address black and set Port to 55555
.
Finally, launch Dig or Die and press OK (in Debug Program dialog) to attach dnSpy to an already running game.
From there, you can do same things like in the normal debugger:
- Set breakpoints
- Inspect locals and type members
- Step into, step over, set more breakpoints (via the top bar)
- Modify values (in some cases)
[!IMPORTANT] If some of the plugins transpiled the method that you set breakpoint, it will never hit it.
There's a workaround how to debug a transpiled method: In
BepInEx.cfg
, in[Preloader]
section change theHarmonyBackend
key tocecil
value. Now, set breakpoint in a method which the transpiled one is going to call. Wait until it hit it and go up in the Call Stack (selectDebug > Windows > Call Stack
or pressCtrl+Alt+C
) into the transpiled method. The dnSpy detected new assembly, so you can how set breakpoints, step through instructions, etc.