Skip to content
This repository has been archived by the owner on Sep 15, 2022. It is now read-only.

Debugging

spacehamster edited this page Feb 24, 2021 · 10 revisions

Enable line numbers in stack traces

Line numbers in mod assemblies for kingmaker can be enabled with the following steps:

  • Build assemblies with portable debugging symbols
  • 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 debug mono-2.0-bdwgc.dll

Dumping patched functions to file

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", "");

Debugging Kingmaker with DnSpy

  • 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 debug mono-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 called DNSPY_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.

Clone this wiki locally