Modding:C Sharp Scripting: Difference between revisions

Jump to navigation Jump to search
First pass of formatting and instruction fixes
(→‎Mod Development Setups: correct one piece of information and add cleanup note)
(First pass of formatting and instruction fixes)
 
Line 5: Line 5:
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.
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==
==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://github.com/icsharpcode/ILSpy/releases ILSpy], [https://www.jetbrains.com/decompiler/ dotPeek], or [http://stackoverflow.com/questions/2646707/something-better-than-net-reflector one of various other decompilation tools] on <u>Caves of Qud\CoQ_Data\Managed\Assembly-CSharp.dll</u>
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://github.com/icsharpcode/ILSpy/releases ILSpy], [https://www.jetbrains.com/decompiler/ dotPeek], or [http://stackoverflow.com/questions/2646707/something-better-than-net-reflector one of various other decompilation tools] on <code>Caves of Qud\CoQ_Data\Managed\Assembly-CSharp.dll</code>


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


# Install Visual Studio: http://visualstudio.microsoft.com/vs/mac/
# 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)
#* Make sure you have the [https://download.visualstudio.microsoft.com/download/pr/19f39d7d-3296-4ed2-af75-f0190d074d43/84949e2b33ccdc6b7c51d5835df2844e/dotnet-sdk-2.2.301-osx-gs-x64.pkg .net Core SDK]
# Open up a terminal and install ilspycmd: dotnet tool install ilspycmd -g
# Open up a terminal and install ilspycmd: <code>dotnet tool install ilspycmd -g</code>
# Find the directory Caves of Qud is installed in - for Steam this is "$HOME/Library/Application Support/Steam/steamapps/common/Caves of Qud/CoQ.app"
# Find the directory Caves of Qud is installed in - for Steam this is <code>$HOME/Library/Application Support/Steam/steamapps/common/Caves of Qud/CoQ.app</code>
# Using the full path of the Assembly file, run the following in a terminal:
# Using the full path of the Assembly file, run the following in a terminal:
#* ilspycmd -p -o ~/Qud_Code "$HOME/Library/Application Support/Steam/steamapps/common/Caves of Qud/CoQ.app/Contents/Resources/Data/Managed/Assembly-CSharp.dll"
#* <code>ilspycmd -p -o ~/Qud_Code "$HOME/Library/Application Support/Steam/steamapps/common/Caves of Qud/CoQ.app/Contents/Resources/Data/Managed/Assembly-CSharp.dll"</code>
#* You can replace '~/Qud_Code' with any other directory, if you have a certain place you want to put it
#* You can replace <code>~/Qud_Code</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
# Open Visual Studio, then open the csproj file at ~/Qud_Code/Assembly-CSharp.csproj


== Mod Development Setups ==
== Mod Development Setups ==
Line 41: Line 41:


# On the Caves of Qud main menu, with Mouse Overlay UI toggled on, go to "Modding Utilities" and select "Write Mods.csproj File". This will automatically create an XML file describing the setup needed that VSCode can read.
# On the Caves of Qud main menu, with Mouse Overlay UI toggled on, go to "Modding Utilities" and select "Write Mods.csproj File". This will automatically create an XML file describing the setup needed that VSCode can read.
#Find the Mods.json file in your CoQ Saves folder.
#Find the Mods.csproj file in your CoQ save data folder. On Windows, this is located in <code>%UserProfile%\AppData\LocalLow\Freehold Games\CavesOfQud</code>.
#Move it to your main modding directory you intend to work from. It is not recommended that this be a mod folder itself, as that will include both this JSON and additional VSCode generated files in the mod itself - it is a better idea to keep mods in their own folders and place the JSON and other exterior files into a parent folder. If you want to keep your Mods folder tidy, you can create your individual Mod folder elsewhere and then create a hardlink/junction to that folder inside of the Mods folder.
#Move it to your main modding directory you intend to work from. It is not recommended that this be a mod folder itself, as that will include both this csproj file and additional VSCode-generated files in the mod itself - it is a better idea to keep mods in their own folders and place the Mods.csproj and other exterior files into a parent folder. If you want to keep your Mods folder tidy, you can create your individual Mod folder elsewhere and then create a hardlink/junction to that folder inside of the Mods folder.
#Open VSCode in the folder that contains the Mods.json, you should now be able to reference Qud namespaces, classes and methods from your own code. As this just links directly to the DLL's, however, you will only get metadata information about those classes and such, which tends to include function signatures, variable names and similar, but not the actual code within those functions. You can look at the actual code using a decompiler as mentioned above, or if you want your code to directly reference the decompiled code follow the optional step 5.
#Open VSCode in the folder that contains the Mods.csproj, you should now be able to reference Qud namespaces, classes and methods from your own code. As this just links directly to the DLLs, however, you will only get metadata information about those classes and such, which tends to include function signatures, variable names and similar, but not the actual code within those functions. You can look at the actual code using a decompiler as mentioned above, or if you want your code to directly reference the decompiled code follow the optional step 5.
#(Optional) In order to reference the decompiled code rather than the real DLL's, take save the decompiled code into a folder in the same directory as your mods then, to prevent conflicts, delete the "Assembly-CSharp.dll" line from your Mods.json. You will have to repeat this step each time the game updates if you want to be working with the most recent code, whereas the DLL links should stay updated.
#(Optional) In order to reference the decompiled code rather than the real DLLs, take save the decompiled code into a folder in the same directory as your mods then, to prevent conflicts, delete the "Assembly-CSharp.dll" line from your Mods.csproj. You will have to repeat this step each time the game updates if you want to be working with the most recent code, whereas the DLL links should stay updated. This is similar to the first two steps in the following section.


Note: I sometimes have issues with VSCode or Visual Studio attempting to pull in additional dependencies, which often leads to errors and are not necessary for Qud modding. I do not recommend clicking the "Resolve Dependencies" button if it appears, and if it does you may have to delete the generated ".vs" and "bin" folders in order to get it to work properly again.  
Note: I sometimes have issues with VSCode or Visual Studio attempting to pull in additional dependencies, which often leads to errors and are not necessary for Qud modding. I do not recommend clicking the "Resolve Dependencies" button if it appears, and if it does you may have to delete the generated ".vs" and "bin" folders in order to get it to work properly again.  
45

edits

Navigation menu