Ludeon Forums

Ludeon Forums

  • April 18, 2021, 05:24:00 PM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [Tool](1.1) Use Visual Studio 2019 to debug your own mods  (Read 1859 times)

CuteLasty

  • Muffalo
  • *
  • Posts: 2
  • Refugee
    • View Profile
[Tool](1.1) Use Visual Studio 2019 to debug your own mods
« on: April 10, 2020, 01:15:07 AM »

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.
« Last Edit: April 10, 2020, 02:59:04 AM by CuteLasty »
Logged

abrenneke

  • Muffalo
  • *
  • Posts: 1
  • Refugee
    • View Profile
Re: [Tool](1.1) Use Visual Studio 2019 to debug your own mods
« Reply #1 on: August 05, 2020, 02:34:23 AM »

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

Kiame

  • Planetologist
  • ****
  • Posts: 1453
  • Refugee
    • View Profile
Re: [Tool](1.1) Use Visual Studio 2019 to debug your own mods
« Reply #2 on: August 12, 2020, 01:33:07 AM »

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
« Last Edit: August 13, 2020, 12:59:01 AM by Kiame »
Logged

Kiame

  • Planetologist
  • ****
  • Posts: 1453
  • Refugee
    • View Profile
Re: [Tool](1.1) Use Visual Studio 2019 to debug your own mods
« Reply #3 on: August 13, 2020, 03:05:52 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...
« Last Edit: August 13, 2020, 04:12:36 AM by Kiame »
Logged