Modding:C Sharp Scripting: Difference between revisions

From Caves of Qud Wiki
Jump to navigation Jump to search
(add modding info box)
imported>Koboldunderlord
(add info on how to use ILSpy for developing on a Mac)
Line 18: Line 18:
# In the dropdown next to where it says "Language", select "C#".
# In the dropdown next to where it says "Language", select "C#".
# Now you can start digging in the disassembled C# source code by selecting some of the game's classes from the sidebar.
# 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:
# Install Visual Studio: http://visualstudio.microsoft.com/vs/mac/
#* Make sure you have the [.net Core SDK](https://download.visualstudio.microsoft.com/download/pr/19f39d7d-3296-4ed2-af75-f0190d074d43/84949e2b33ccdc6b7c51d5835df2844e/dotnet-sdk-2.2.301-osx-gs-x64.pkg)
# Find the directory Caves of Qud is installed in - for Steam this is '~/Library/Application Support/Steam/steamapps/common/Caves of Qud/CoQ.app'
# 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
# Open Visual Studio, then open the csproj file a ~/Qud_Code/Assembly-CSharp.csproj


==Detailed Scripting Topics==
==Detailed Scripting Topics==
* [[Modding: Creating New Mutations|Creating new mutations]]
* [[Modding: Creating New Mutations|Creating new mutations]]
* [[Modding: Activated Abilities|Adding active abilities]]
* [[Modding: Activated Abilities|Adding active abilities]]

Revision as of 05:38, 13 July 2019

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:

  1. Install Visual Studio: http://visualstudio.microsoft.com/vs/mac/
  2. Find the directory Caves of Qud is installed in - for Steam this is '~/Library/Application Support/Steam/steamapps/common/Caves of Qud/CoQ.app'
  3. 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
  4. Open Visual Studio, then open the csproj file a ~/Qud_Code/Assembly-CSharp.csproj


Detailed Scripting Topics