-
Notifications
You must be signed in to change notification settings - Fork 1
Debugging
Line numbers in mod assemblies for kingmaker can be enabled with the following steps:
- Build assemblies with portable debugging symbols by opening project properties in the visual studio solution, navigating to build, opening the advanced tab and selecting
portable
from the debugging information dropdown. - The .pdb file generated by visual studio contains the debugging symbols needed to display line numbers and must be copied to the mod folder after every rebuild.
- Download the dnSpy debug mono runtime: 2018.4.10 for kingmaker, 2019.4.0 for wrath
- Replace
C:\Program Files (x86)\Steam\steamapps\common\Pathfinder Kingmaker\MonoBleedingEdge\EmbedRuntime\mono-2.0-bdwgc.dll
with the dnspy debugmono-2.0-bdwgc.dll
Functions patched with harmony can be dumped to a file for inspection with a decompiler. This is especially handy for checking that transpilers are applied correctly. This is done by setting environment variables as follows:
Environment.SetEnvironmentVariable("MONOMOD_DMD_TYPE", "cecil");
Environment.SetEnvironmentVariable("MONOMOD_DMD_DUMP", "./mmdump");
harmony.PatchAll();
Environment.SetEnvironmentVariable("MONOMOD_DMD_DUMP", "");
The game directory will be noted as [GameDir]. By Default it is C:\Program Files (x86)\Steam\steamapps\common\Pathfinder Kingmaker for kingmaker and C:\Program Files (x86)\Steam\steamapps\common\Pathfinder Second Adventure Demo for wrath of the righteous.
- Go https://unity3d.com/get-unity/download/archive download and install the correct version of unity. 2018.4.10 for kingmaker and 2019.4.0 for wrath.
- Either install unity or unpack the installer with 7zip.
- Navigate to
[UnityFolder]\Editor\Data\PlaybackEngines\windowsstandalonesupport\Variations\win64_development_mono\
and opy UnityPlayer.dll and WinPixEventRuntime.dll to [GameDir] and overwrite it. - Use text editor open [GameDir]\Kingmaker_Data\boot.config and add:
wait-for-managed-debugger=1
player-connection-debug=1
- Ensure Visual Studio 2019 is installed and contains .NET desktop development workload and Visual Studio Tools for Unity component. The Game development with Unity workload or the Unity Hub component is not required. Modifying workloads and components of an existing Visual Studio install can be done with Tools -> Get Tools and Features.
- Build assemblies with portable debugging symbols by opening project properties in the visual studio solution, navigating to build, opening the advanced tab and selecting
portable
from the debugging information dropdown. - Rebuild the mod and copy both the .dll and pdb to [GameDir]/Mods/[ModName]/
- Run [GameDir]/Kingmaker.exe, then you will see a dialog with message "You can attach a managed debugger now if you want"
- 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
<no name> Your_PC_Name Player 56593 PID:xxxx
Double click on it, then select ok on the debug dialog prompt to begin debugging.
- Download the dnSpy debug mono runtime: 2018.4.10 for kingmaker, 2019.4.0 for wrath
- Replace
C:\Program Files (x86)\Steam\steamapps\common\Pathfinder Kingmaker\MonoBleedingEdge\EmbedRuntime\mono-2.0-bdwgc.dll
with the dnspy debugmono-2.0-bdwgc.dll
- Open DnSpy and start debugging.
- Either go to Debug -> Start Debugging and select Unity debug engine
- Or choose
Unity (Connect)
to start debugging after the game has already been started. dnSpy's mono.dll will look for an environment variable calledDNSPY_UNITY_DBG
(Unity with .NET 2.0-3.5 assemblies) or DNSPY_UNITY_DBG2 (Unity with .NET 4.x assemblies).-
--debugger-agent=transport=dt_socket,server=y,address=127.0.0.1:55555,suspend=n
or -
--debugger-agent=transport=dt_socket,server=y,address=127.0.0.1:55555,suspend=n,no-hide-debugger
to enable detection of the debugger.
-
** Important note ** If dnSpy gives you garbled variables/other, it is highly suggested you try using Ilspy - dnSpy and Ilspy are not perfect and in some cases one or the other might work better.