-
Notifications
You must be signed in to change notification settings - Fork 8
Mod Creation_C# Programming_Debugging Your Mods
The microsoft documentation says:
When you debug your app, it usually means that you are running your application with the debugger attached. When you do this, the debugger provides many ways to see what your code is doing while it runs. You can step through your code and look at the values stored in variables, you can set watches on variables to see when values change, you can examine the execution path of your code, see whether a branch of code is running, and so on. If this is the first time that you've tried to debug code, you might want to read Debugging for absolute beginners before going through this guide.
Debugging an R2ModMan profile is possible now, for instructions, ignore steps 1 thru 3, and instead follow the steps 1 thru 3 of the R2ModMan section.
- Install BepInEx from thunderstore
- Install doorstop 4
- Drag and drop as follow into your Risk of Rain 2 game folder It should replace a lot of files, press yes to all
- Open the
doorstop_config.ini
You can set the config like this
# If true, Mono debugger server will be enabled
debug_enabled=true
# When debug_enabled is true, this option specifies whether Doorstop should initialize the debugger server
# If you experience crashes when starting the debugger on debug UnityPlayer builds, try setting this to false
debug_start_server=true
# When debug_enabled is true, specifies the address to use for the debugger server
debug_address=127.0.0.1:55555
# If true and debug_enabled is true, Mono debugger server will suspend the game execution until a debugger is attached
debug_suspend=true
This will make doorstop suspend the game on start, open a debugging server at port 55555, allowing you to attach any debugger of your liking, you can use either VS, dnSpy or Rider.
Putting breakpoints inside game assemblies while using the Visual Studio Debugger is not possible currently, but works with dnSpy, please refer to the dnSpy section below on how to configure it.
Debugging an R2ModMan setup is possible, it just requires a different aproach:
- Install BepInEx from thunderstore
- Install this custom version of doorstopV4
-
- Drag and drop as follow into your R2ModMan profile folder It should replace a lot of files, press yes to all
Notice: Installing the custom version of Doorstop will cause the BepInEx GUI to not show up, it is recommended to modify
your BepInEx.cfg
's Logging.Console
's Enabled
to true, and setting BepInEx.GUI.cfg
's Settings
's Enable BepInEx GUI
to false
Continue as normal, following step 4 of the manual installation
-
Install Visual Studio Tools for Unity
-
Install UnityModExtension
-
Configure the Unity Mod Extension if needed by going in Tools -> Options
-
Press Debug -> Run Game and Start Debugging
Make sure the doorstop_config.ini
is setup like above, but with the debug_suspend=false
, since having it as true
doesn't seem to work with dnSpy
You'll need to setup the BepInEx.cfg so that it dumps game assemblies to folder, as there may be BepInEx patchers modifying the game assemblies.
In the BepInEx/config/BepInEx.cfg
, set to true the following entries: DumpAssemblies
, LoadDumpedAssemblies
and BreakBeforeLoadAssemblies
.
In dnSpy, make sure that the RoR2.dll that is in there is the assembly from BepInEx\DumpedAssemblies\Risk of Rain 2\RoR2.dll
Then, launch the game, attach with dnSpy through Debug -> Start Debugging -> Debug Engine: Unity (connect)
It should automatically breakpoint somewhere inside a BepInEx assembly, then you'll be able to put any breakpoint in the game assemblies