Skip to content

Mod Creation_C# Programming_Debugging Your Mods

Nebby edited this page Jan 27, 2023 · 13 revisions

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.

General Setup

  1. Install BepInEx from thunderstore
  2. Install doorstop 4
  3. Drag and drop as follow into your Risk of Rain 2 game folder
    • If you want to debug an R2ModMan profile instead, drag and drop the contents of the Zip file into your r2modman profile

qsdqsd It should replace a lot of files, press yes to all 4. 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.

Notice: using the custom Doorstop version can cause issues with the BepInEx GUI that's bundled in RoR2BepInExPack, it is recommended to go into BepInEx's config (BepInEx\config\BepInEx.cfg) and set the Logging.Console's Enabled config to true, and setting BepInExGUI's config (BepInEx\config\BepInEx.GUI.cfg)'s Enable BepInEx GUI config to false

Visual Studio 2022

dnSpy

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

Clone this wiki locally