Modding:C Sharp Scripting

From Caves of Qud Wiki
Jump to navigation Jump to search
This page is about modding. See the modding overview for an abstract on modding.
This page is about modding. See the modding overview for an abstract on modding.

Overview

Caves of Qud loads a majority of it's content via reflection. You may add new files to it's database of reflectable objects by including .cs files in your mod. These files are compiled at runtime into an assembly and the type resolver will first check for types in the mod assembly before checking the Caves of Qud game assembly, thus you may add new types or override existing types by including classes with the right naming convention in your mod.

Since your mod runs with full privileges, users must approve mods each time they change, to allow any changes in code to be screened before they execute. This approval mechanism is currently only available via the overlay UI so it either must be enabled or mod approval must be disabled for scripting mods to work properly. If your mod scripts are not approved, no files in your mod will be loaded, to prevent definitions from not having the appropriate classes available in the mod's assembly.

Nosing Around

There's no official DLL to assemble against or open source project but if you want to dig around in the source code you can use https://www.jetbrains.com/decompiler/ or some other tool: http://stackoverflow.com/questions/2646707/something-better-than-net-reflector on Caves of Qud\CoQ_Data\Managed\Assembly-CSharp.dll

The XRL.World.Parts namespace contains all the part definitions in the game, so it's a good place to start digging.

Cross-Platform (Including Linux)

MonoDevelop, which is cross-platform (and in particular runs on Linux), comes with its own disassembly tool.

  1. Run MonoDevelop.
  2. Go to File→Open….
  3. Locate the abovementioned assembly file and open it. This will open the Assembly Browser.
  4. In the dropdown next to where it says "Language", select "C#".
  5. Now you can start digging in the disassembled C# source code by selecting some of the game's classes from the sidebar.

Working on Mac

Sometimes, Monodevelop/Visual Studio do not render the assembly properly when you munge in the raw DLL.

To get around this, use ILSpy to decompile the code:

  1. Install Visual Studio: http://visualstudio.microsoft.com/vs/mac/
  2. Open up a terminal and install ilspycmd: dotnet tool install ilspycmd -g
  3. Find the directory Caves of Qud is installed in - for Steam this is '~/Library/Application Support/Steam/steamapps/common/Caves of Qud/CoQ.app'
  4. Using the full path of the Assembly file, run the following in a terminal:
    • ilspycmd -p -o ~/Qud_Code ~/Library/Application Support/Steam/steamapps/common/Caves of Qud/CoQ.app/Contents/Resources/Data/Managed/Assembly-CSharp.dll
    • You can replace '~/Qud_Code' with any other directory, if you have a certain place you want to put it
  5. Open Visual Studio, then open the csproj file a ~/Qud_Code/Assembly-CSharp.csproj

Detailed Scripting Topics