|
| 1 | +--- |
| 2 | +title: "Attach a Debugger to Timberborn" |
| 3 | +description: A comprehensive guide to making mods for Timberborn |
| 4 | +date: 2025-03-13 |
| 5 | +tags: mods timberborn guide modding debugging |
| 6 | +--- |
| 7 | + |
| 8 | +[Home](../) / [Modding Guide](./) / Attach a Debugger to Timberborn |
| 9 | + |
| 10 | +**This guide can be done totally thanks to `normanr`. All credits go to him. I just made a few changes to make it easier to follow. Parts of this guide is from [dnSpy's guide](https://github.com/dnSpy/dnSpy/wiki/Debugging-Unity-Games#turning-a-release-build-into-a-debug-build) and [Let's Play with Fire Wiki](https://wiki.fireundubh.com/unity/turning-a-release-build-into-a-debug-build).** |
| 11 | + |
| 12 | +This short guide will show you how to attach a debugger to Timberborn and debug the game code or your mods using DnSpy and Visual Studio. |
| 13 | + |
| 14 | +- With dnSpy, you can debug the game code using the game's assemblies (DLLs) or ripped assemblies from AssetRipper. |
| 15 | +- With Visual Studio, you can debug your mod code. |
| 16 | + |
| 17 | +# Installation guide |
| 18 | + |
| 19 | +1. Determine and install the Unity version the game is using: |
| 20 | + - Right click on the Timberborn executable and select `Properties`. Go to the `Details` tab and look for `Product version`. For example at the time of writing, the version is `6000.0.36f1`. |
| 21 | + |
| 22 | + - Go to [Unity Download Archive]( https://unity.com/releases/editor/archive) and download the corresponding version (you don't actually need to run it, just need some files from it). |
| 23 | + |
| 24 | +> **Tip:** while waiting for the download and installation, you should make a backup of your game's folder. |
| 25 | +I myself even create Git repository for the game folder, then create a branch called `dev-build` so I can easily switch between the dev build and the normal game because the Dev build does have a lot of dev UI that are not useful when you are not debugging the game. |
| 26 | + |
| 27 | +2. Go to this folder you just installed, `Unity 6000.0.36f1\Editor\Data\PlaybackEngines\windowsstandalonesupport\Variations\win64_player_development_mono`: |
| 28 | + - Copy the content of the `Data` folder over to your game's `Timberborn_Data` folder, overwriting everything. |
| 29 | + - Copy `WindowsPlayer.exe` + `UnityPlayer.dll` to your game's folder (where `Timberborn.exe` is). Rename or delete the original `Timberborn.exe` then rename `WindowsPlayer.exe` to `Timberborn.exe`. |
| 30 | + |
| 31 | +3. Edit `Timberborn_Data\boot.config` and add these two lines: |
| 32 | + |
| 33 | +```ini |
| 34 | +wait-for-managed-debugger=1 |
| 35 | +player-connection-debug=1 |
| 36 | +``` |
| 37 | + |
| 38 | +4. (Optional) If you want to use Visual Studio, make sure you have "Game development with Unity" installed. You can check this in Visual Studio Installer. |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | +That's it. If you use my tip above, now you can make a commit into the new branch `dev-build` and you can switch between the dev build and the normal game easily. |
| 43 | + |
| 44 | +# Debugging with DnSpy |
| 45 | + |
| 46 | +You can either use `Start` command or `Attach to Unity` command in DnSpy. Then you simply load the game's DLLs (either directly from the game folder or from AssetRipper) and you can put breakpoints and debug the game code. |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +For example, I put a breakpoint at `Timberborn.BlockSystem.BlockObjectFactory.CreateUnfinished` for when I want to know what happens when I build a building: |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | +# Debugging with Visual Studio |
| 55 | + |
| 56 | +> **Note:** in order to debug your mod's code, make sure you built your mod with embedded Debug symbols. You need this in your `csproj` file: |
| 57 | +
|
| 58 | +```xml |
| 59 | +<PropertyGroup> |
| 60 | + <!-- Others code --> |
| 61 | + <DebugSymbols>true</DebugSymbols> |
| 62 | + <DebugType>embedded</DebugType> |
| 63 | +</PropertyGroup> |
| 64 | +``` |
| 65 | + |
| 66 | +Then when the game run, you can click `Debug > Attach Unity Debugger` in Visual Studio and select the `Timberborn.exe` process. You can put breakpoints in your mod's code and debug it like a normal C# project. |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | +--- |
| 71 | + |
| 72 | +[Back to Modding Guide](./) |
0 commit comments