Debugging Subnautica
- Make sure you have the latest version of dnSpyEx installed.
- Swap Subnautica's release build
mono.dll
with dnSpy's patched version that can be debugged:- Download the debug mono dll here.
- Navigate to Subnautica's directory. Then go to
/MonoBleedingEdge/EmbedRuntime/
. - Rename your
mono-2.0-bdwgc.dll
withmono-2.0-bdwgc-old.dll
to avoid loosing the original one. - Swap out
MonoBleedingEdge/EmbedRuntime/mono-2.0-bdwgc.dll
with themono-2.0-bdwgc.dll
from the zip above.
- Start up Subnautica and dnSpy.
- While on the main menu, go to
Debug > Start Debugging
(or pressF5
) in dnSpy. - Select
Unity (Connect)
as the Debug engine - If DnsSpy debug environment variables are not set, provide
127.0.0.1
:5555
for the socket. Then press OK. - Once the bottom of dnSpy says "Running..." in orange, the debugger is now connected to Subnautica.
NOTE: By default the debug socket will listen on 127.0.0.1:5555, you can change this behavior by updating the environment variable called DNSPY_UNITY_DBG2
(Unity with .NET 4.x assemblies) :
--debugger-agent=transport=dt_socket,server=y,address=127.0.0.1:55555,suspend=n
--debugger-agent=transport=dt_socket,server=y,address=127.0.0.1:55555,suspend=n,no-hide-debugger
to enable detection of the debugger
To view the game's code:
- Go to
Debug > Windows > Modules
, findAssembly-CSharp.dll
and double click it.- NOTE: You can also debug through Nitrox's code by finding Nitrox modules after the patcher loads them in.
You can place breakpoints anywhere in any of the modules and the game will pause and show all local variables when the breakpoint is hit.
NOTE: It might take a few seconds for the debugger to connect to your game. Be careful when setting breakpoints and pausing the game for long periods of time when it's in multiplayer, because you will be disconnected from the server after you resume execution due to timeout (default timeout is 5m
if building Nitrox in DEBUG
mode). It's recommended to attach the debugger before you join a multiplayer server.