-
Notifications
You must be signed in to change notification settings - Fork 5
[Tutorial] Setting Up Your Mod Project
- Download Visual Studio. You may use another version of VS, or another IDE like JetBrains Rider. However, it must support
.NET 6as 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 Tools2019 or later installed with the Individual Component underSDKs, libraries, and frameworksnamedVisual Studio SDK Build Tools Coreinstalled.
- 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.
- 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! - Copy the contents of the Refs.zip to the
/Refsfolder 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- Rename the Skeleton Project folder to the name of your mod.
- 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/Refshave be found successfully. - Rename the
MyModName.slnfile to the name of your mod. IE:ModdingToolkit.sln. - Open the
.slnSolution file. In your IDE, you will need to do the following for all.csprojfiles:
- Assets.csproj
- LinuxClient.csproj
- LinuxServer.csproj
- OSXClient.csproj
- OSXServer.csproj
- WindowsClient.csproj
- WindowsServer.csproj- A. Open the Project Configuration for the
.csprojfile by right-clicking and selectingProperties. - B. Change the
AssemblyNameto the name of your mod WITHOUT SPACES OR SPECIAL CHARACTERS. Example:ModdingToolkit - C. Change the
Root Namespaceto either your mod's Assembly Name or mod's short version without spaces in plain English. Example:ModdingToolkit.
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.
- 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.
- 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
.slnfile 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.
\
You will have to do the following for the Build.props file found in the main project directory:
-
Open the file in your Text Editor or IDE of choice.
-
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>- Change the
ModDeployDirvalue from..\LUATRAMA_DEBUG_LOCALMODS_MYMODDIR\to the path to your mod's folder in the/LocalModsfolder for LuaCsForBarotrauma fromPart 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
Clientplugin or theServerplugin (IE. Client-side or Server-side ONLY mod), then you must delete all projects that end withServer. 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.
- Replace
MyModNamewith 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
ModNameorPackageName.LibraryNamefor libraries, IE:ModdingToolkit.GUI.
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.exeorBarotrauma.dll, name itClient. - B. The other should target
DedicatedServer.exeorDedicatedServer.dlland name itServer.
Follow the link;
- For Jetbrains Rider IDE (what I use).
- For Visual Studio 2022 IDE.
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.
- Open
<ProjectDirectory>/Assets/RunConfig.cfgit 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>- Add a
Dependenciessection/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>- 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>