Skip to content

[Tutorial] Setting Up Your Mod Project

MapleWheels edited this page Nov 15, 2023 · 8 revisions

For Developers : Setting Up Your CS Project for Development


Part 1: General Project Setup

  1. Download Visual Studio. You may use another version of VS, or another IDE like JetBrains Rider. However, it must support .NET 6 as a platform/SDK target and there is no guarantee that the project will function as expected, although there should be little issue.
  • Important: You must have Visual Studio Build Tools 2019 or later installed with the Individual Component under SDKs, libraries, and frameworks named Visual Studio SDK Build Tools Core installed.
  1. Git Clone or Download the following:
  • Refs.zip: This contains all references used in the project. Choose the one from the latest release on the Github repo.
  • VSProjectSkeleton: This contains the skeleton project that we will be using as the basis for this tutorial. Most things that need to be setup have already been done.
  • If you do not have Git Tools installed, it is recommended that you get familiar with them as it makes life easier and is required for Part 2 (optional). Download and install it.
  1. Extract the VS Project Skeleton to a folder that you are working out of.
    -- IMPORTANT: This folder should NOT be in your Barotrauma/Luatruama local mods folder!
  2. Copy the contents of the Refs.zip to the /Refs folder in the VS Skeleton Project. Your project should then have the below structure.
./MyModName.sln
./.gitignore
./README.txt
./Build.props

=== Assets Here ===
./Assets
----/Content/ <<=== Your Non-CSharp Content Goes Here (including Lua, XML)!
Ex:----/Lua/...
Ex:----/Items/...
----/filelist.xml
----/RunConfig.xml

=== Client CSharp Code Here ===
./ClientProject
----/ClientSource/...
----/LinuxClient.csproj
----/OSXClient.csproj
----/WindowsClient.csproj

=== Server CSharp Code Here ===
./ServerProject
----/ServerSource/...
----/LinuxServer.csproj
----/OSXServer.csproj
----/WindowsServer.csproj

=== Shared CSharp Code Here ===
./SharedProject
----/SharedSource/...

./Refs
----/Linux/Barotrauma.dll
----/Linux/DedicatedServer.dll
----/Windows/Barotrauma.dll
----/Windows/DedicatedServer.dll
----/OSX/Barotrauma.dll
----/OSX/DedicatedServer.dll
----/0Harmony.dll
----/Farseer.NetStandard.dll
----/Lidgren.NetStandard.dll
----/Mono.Cecil.dll
----/MonoGame.Framework.Linux.NetStandard.dll
----/MonoGame.Framework.MacOS.NetStandard.dll
----/MonoGame.Framework.Windows.NetStandard.dll
----/MonoMod.Common.dll
----/MoonSharp.Interpreter.dll
----/XNATypes.dll
  1. Rename the Skeleton Project folder to the name of your mod.
  2. Open up the Solution file (.sln) from the Skeleton Project in Visual Studio. Just verify that there are not errors related to "Unable to find Reference", this means that all assemblies in /Refs have be found successfully.
  3. Rename the MyModName.sln file to the name of your mod. IE: ModdingToolkit.sln.
  4. Open the .sln Solution file. In your IDE, you will need to do the following for all .csproj files:
- Assets.csproj
- LinuxClient.csproj
- LinuxServer.csproj
- OSXClient.csproj
- OSXServer.csproj
- WindowsClient.csproj
- WindowsServer.csproj
  • A. Open the Project Configuration for the .csproj file by right-clicking and selecting Properties.
  • B. Change the AssemblyName to the name of your mod WITHOUT SPACES OR SPECIAL CHARACTERS. Example: ModdingToolkit
  • C. Change the Root Namespace to either your mod's Assembly Name or mod's short version without spaces in plain English. Example: ModdingToolkit.

Part 2 (Optional, Recommended): Setting up a debug build of LuaCsForBarotrauma

This will give us a debug build of LuaCsForBarotrauma. A debug build gives us access to many tools as well as the DEBUG symbol for writing test/print code that will not be run in the release version.

  1. Clone the LuaCsForBarotrauma repository to your local drive. If you do not have Git Tools installed, please download and install it.
  • Important: When cloning, use the command git clone --recurse-submodules --remote-submodules https://github.com/evilfactory/LuaCsForBarotrauma.git. This will download the submodules automatically.
  1. Open up the LuaCs Solution in your IDE based on your Operating System, one of:
- WindowsSolution.sln
- MacSolution.sln
- LinuxSolution.sln

-- NOTE: This tutorial assumes that you are using the WindowsSolution.sln. For other platforms, the naming of files may be slightly different (MacXXX, LinuxXXX, where 'XXX' is either "Client" or "Server").

3. In the Project Settings for WindowsClient and WindowsServer, you want to change the Platform Target from Any CPU to x64. This is necessary for OpenAL code to build successfully.

4. Build the whole Solution (Build -> Build Solution). This will create the necessary dependencies from libraries and make sure that there are no errors at this point.

5. For both the WindowsClient and WindowsServer projects, set their output/build type to DEBUG (should be in a drop-down menu at the top next to a green play button).

6. Select Build Solution. This will generate Debug builds for use. This debug build will now exist in ./Barotrauma/bin/DebugXXX/net6.0/ where XXX is based on your Solution choice. IE. ./Barotrauma/bin/DebugWindows/net6.0.

7. Make the local folder in Barotrauma/LocalMods/ for your mod:

  • A. Navigate into the Client Debug Build folder (or game folder if you are coming from Part 3, Step 3) and then into /LocalMods.
  • B. CREATE a folder with the name of your mod. Ideally, it should match the name of your .sln file with the extension.
  • C. COPY the path to this directory (with your mod) and save it in a sticky note or .txt file. We will be using it shortly.
    \

Part 3: Setting up MSBuild to Copy Files into Local Mods.

You will have to do the following for the Build.props file found in the main project directory:

  1. Open the file in your Text Editor or IDE of choice.

  2. Locate the line ModDeployDir, IE:

<PropertyGroup>
    <!-- IMPORTANT: Should point to <Barotrauma_Install>\LocalMods\<MyModName>\ -->
    <!-- IMPORTANT: ModDeplyDir Path must end with '\' -->
    <ModDeployDir>..\LUATRAMA_DEBUG_LOCALMODS_MYMODDIR\</ModDeployDir>
    <!-- IMPORTANT: Avoid the use of special (IE: / : ; , \ < > ?) (periods "." are good) and non-english characters in the AssemblyName.-->
    <AssemblyName>MyModName</AssemblyName>
</PropertyGroup>
  1. Change the ModDeployDir value from ..\LUATRAMA_DEBUG_LOCALMODS_MYMODDIR\ to the path to your mod's folder in the /LocalMods folder for LuaCsForBarotrauma from Part 2, Step 7.
  • IMPORTANT: The value must end with / or \ . IE: \LocalMods\ModdingToolkit\.
  • Note: If you did not complete Part 2, then complete only Part 2, Step 7 but use your vanilla Barotrauma installation location instead.
  • Note: If you do not want either the Client plugin or the Server plugin (IE. Client-side or Server-side ONLY mod), then you must delete all projects that end with Server. Example: LinuxServer, WindowsServer. Warning, this is generally irreversible and will require you to setup new Cs Projects if you want a client in the future.
  1. Replace MyModName with a valid assembly name, this should be similar to your mod name but does not need to match. This name should:
  • Not include spaces.
  • Not include special characters except periods ( . ), which are allowed.
  • Use english characters.
  • Recommended: Follow the convention of ModName or PackageName.LibraryName for libraries, IE: ModdingToolkit.GUI.

Part 4: Adding Launch Configurations for Debug-Mode Barotrauma Client and Server to the IDE.

This part makes life very easy and gives you access to Edit and Continue. It'll let you Debug your build as you go and launch Barotrauma from the IDE. Note that this is IDE-specific so please follow the links for your IDE while doing the below:
-- Make two launch options;

  • A. One should target Barotrauma.exe or Barotrauma.dll, name it Client.
  • B. The other should target DedicatedServer.exe or DedicatedServer.dll and name it Server.

Follow the link;


(Optional) Part 5: Adding Script Dependencies

This part is optional and only to be used if your mod relies on the assemblies/code from another mod to run/compile. This will allow you to add Script/Code ContentPackages as dependencies to make sure they load first.

  1. Open <ProjectDirectory>/Assets/RunConfig.cfg it should look like this:
<?xml version="1.0" encoding="utf-8"?>
<RunConfig>
    <!--Options: "None" / "Forced" (always) / "Standard" (when enabled)-->
    <Server>Standard</Server>
    <Client>Standard</Client>
</RunConfig>
  1. Add a Dependencies section/node/element:
<?xml version="1.0" encoding="utf-8"?>
<RunConfig>
    <!--Options: "None" / "Forced" (always) / "Standard" (when enabled)-->
    <Server>Standard</Server>
    <Client>Standard</Client>
    <Dependencies>
     
    </Dependencies>
</RunConfig>
  1. Add the STEAMID or Name of your dependencies surrounded by <Dependency></Dependency> elements as follows:
  • <PackageName>Name</PackageName> for name matching
<?xml version="1.0" encoding="utf-8"?>
<RunConfig>
    <!--Options: "None" / "Forced" (always) / "Standard" (when enabled)-->
    <Server>Standard</Server>
    <Client>Standard</Client>
    <Dependencies>
        <Dependency>
            <!-- You do not need both of these, the SteamWorkshopId is usually enough -->
            <SteamWorkshopId><!--ID goes here--></SteamWorkshopId>
            <PackageName<!--Name goes here-->></PackageName>
        </Dependency>
    </Dependencies>
</RunConfig>