Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - CuteLasty

#1
Tools / [Tool](1.1) Trace RimWorld Core Code
April 11, 2020, 03:21:52 AM
Prerequirement
Setup debug environment by my post:  [Tool](1.1) Use Visual Studio 2019 to debug your own mods

Decompile RIMWorld Core
I choose JetBrains' dotPeek, because it can generate PDB symbole file.
It's free tool, and you can download here: https://www.jetbrains.com/decompiler/download/

After installed, launch dotPeek.

Step1: Drag and drop RIMWorld\RimWorldWin64_Data\Managed\Assembly-CSharp.dll to dotPeek.
Step2-1: Select Assembly-CSharp on Assembly Explorer
Step2-2: Select menu File/Export to Project
Step2-3: Select export folder, and checked "Create *.pdb file" option
Step3: After export done, then copy [RIMWorld]\[Decompile_Folder]\Assembly-CSharp\Assembly-CSharp.pdb to [RIMWorld]\RimWorldWin64_Data\Managed

Now you can open the solution at [RIMWorld]\[Decompile_Folder]\Assembly-CSharp\Assembly-CSharp.sln by Visual Studio 2019, then attach to Unity debug to trace RIMWorld Core.

You can also trace your mod code at the same time.
#2
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.