[Tool](1.1) Use Visual Studio 2019 to debug your own mods

Started by CuteLasty, April 10, 2020, 01:15:07 AM

Previous topic - Next topic

CuteLasty

I will show you how to debug your mod C# code use Visual Studio 2019.

1. Check Unity version of the game you have.
Let's confirm the Look the [RIMWorld_Install_Path]\UnityPlayer.dll 's version information.
In this case, it use Unity 2019.2.17

2. Go https://unity3d.com/get-unity/download/archive download correct version of unity.
In this case, we need download 2019.2.17. Choose Unity Editor 64-bit, the download will start automatically.

3. After download done, use 7zip unpack file.
In this case, the filename is UnitySetup64-2019.2.17f1.exe.

4. Copy your RIMWorld Game to C:\RIMWorld_Debug

5. Locate to [UnpackFolder]\Editor\Data\PlaybackEngines\windowsstandalonesupport\Variations\win64_development_mono\
Copy UnityPlayer.dll and WinPixEventRuntime.dll to C:\RIMWorld_Debug and overwrite it.
Copy WindowsPlayer.exe to C:\RIMWorld_Debug, and rename to RimWorldWin64.exe

6. Delete Unpack Unity files. We no longer need them.

7. Use text editor open C:\RIMWorld_Debug\RimWorldWin64_Data\boot.config
Add:
wait-for-managed-debugger=1
player-connection-debug=1

8. Install Visual Studio 2019
Because I already installed VS2019 on my computer, I'm not sure what you need. I think you may need .Net desktop development Workloads.

The most important thing is, install Game development with Unity Wordloads, but you only need Visual Studio Tools for Unity. You don't need Optional Unity 2019.2 64-bit Editor, if you are not Unity developer.

9. After all 1-8 is done, then open you mod solution.
Set mod project properties (mouse right client on project name, at the bottom)

Build/Click Advance button/Change Output->Debugging information to Portable

10. Rebuild your mod, and place .dll and .pdb to C:\RIMWorld_Debug\Mods\your_mod\...

11. Run C:\RIMWorld_Debug\RimWorldWin64.exe, then you will see a dialog with message "You can attach a managed debugger now if you want"

12. Go to Visual Studio 2019, click menu Debug/Attach Unity Debugger
A "Select Unity instance" dialog will show you some thing like..

Project              Machine              Type    Port       Information
WindowsPlayer   Your_PC_Name   Player  56593    PID:xxxx

Double click on it, then attached to RIMWorld script debugger.

Now you can try to set break point on your mod code.

abrenneke

Thanks, this worked great! I'm even able to set breakpoints in the RimWorld code itself.

Kiame

Omg this would have saved me soooooooo many hours -_-

Thank you!

Edit:
For 1.2 i did also have to extract "WinPixEventRuntime.dll" from unity installer and put it in the RimWorld_Debug directory

Kiame

Quote from: abrenneke on August 05, 2020, 02:34:23 AM
Thanks, this worked great! I'm even able to set breakpoints in the RimWorld code itself.

Could you explain how you were able to debug the RimWorld code? I'm not sure how to w/o the pdb files for the RW dll

Edit:
Ah, using ilSpy, right click "Assembly-CSharp" in the left tree mapping and select "Generate Portable PDB"

Edit 2:
Hmm still no go. I've loaded the pdb file and have "Enable Just my Code" unchecked...

MechanoidHater

Upon starting the .exe file I get the "failed to load mono" error.