Setting up a mod - KittenAqua/TrainworksModdingTools GitHub Wiki
These wiki pages are deprecated and are outdated. Please find the newer tutorials here
If you haven't yet set up the Monster Train modloader, do that first, then come back.
Before you can begin adding content, you have to set up the mod to use the modloader.
Either copy the existing test mod or create a new Visual Studio project (C# .NET standard class library). The project must target netstandard2.0. You'll want to reference the following dlls from the MonsterTrain_Data/Managed folder in the game directory:
- Assembly-CSharp.dll (contains most of the game code)
- UnityEngine.dll (for various Unity things)
- UnityEngine.CoreModule.dll (for MonoBehaviours)
- Unity.Addressables.dll
Also reference the following dlls from the modloader (most likely at the following directory: C:\Program Files (x86)\Steam\steamapps\workshop\content\1102190\2187468759\BepInEx\core
):
- 0Harmony.dll
- BepInEx.dll
- BepInEx.Harmony.dll
And lastly, if you plan on making use of the Trainworks Modding Tools, reference its dll:
- TrainworksModdingTools.dll
Select all referenced dlls. Right click -> set Copy Local to "No" - this will prevent Visual Studio from copying the referenced dlls to your mod folder. If you do not do this, you will duplicate the referenced dlls for absolutely no reason. Though it won't actively break anything, it will take up more hard drive space.
Now we want to make it so that building the project will automatically place the dll in the workshop folder, so it doesn't need to be copied over manually every time you rebuild.
Unfortunately Visual Studio is slightly unkind to netstandard projects, so we'll need to edit the .csproj file manually.
Open the .csproj in your preferred text editor.
Find <OutputPath>
and change it to <OutDir>
. Inside the tag, change the path so it builds to a subfolder of the Monster Train workshop directory. Something like C:\Program Files (x86)\Steam\steamapps\workshop\content\1102190\MyMod\plugins
. Note that you need to have a plugins
folder, or the modloader won't acknowledge your mod.
Build the project, navigate to that folder, and confirm that everything looks like it should.
Now that Visual Studio's squared away, you need to actually add in the base code that'll get the modloader to load your mod. The Monster Train modloader is based on BepInEx; this tutorial assumes no prior knowledge, but if you've worked with it before then you probably already know how to set it up. For those who don't:
- Add the following statements to the top of your file:
using BepInEx;
using HarmonyLib;
- Create your mod class. It doesn't need an explicit constructor. Example:
public class TestPlugin : BaseUnityPlugin
{
}
- Add a few constants to the class. These are going to be useful (much) later. The ones below are examples; change them for your mod!
public const string GUID = "com.name.package.generic";
public const string NAME = "Test Plugin";
public const string VERSION = "0.1.0";
Note that the GUID must be unique, and if more than one plugin with the same GUID is found, only the highest version will be used.
- Add the following annotations before your class declaration:
-
[BepInPlugin(GUID, NAME, VERSION)]
<-- Specifies plugin metadata -
[BepInProcess("MonsterTrain.exe")]
<-- The main MonsterTrain executable -
[BepInProcess("MtLinkHandler.exe")]
<-- For when the game is opened from a link
Full example:
[BepInPlugin(GUID, NAME, VERSION)]
[BepInProcess("MonsterTrain.exe")]
[BepInProcess("MtLinkHandler.exe")]
public class TestPlugin : BaseUnityPlugin
{
public const string GUID = "com.name.package.generic";
public const string NAME = "Test Plugin";
public const string VERSION = "0.1.0";
}
Confirm that this builds, then launch the game and confirm that it is detecting and loading your plugin; if it is, it'll say so in the console or log.
Next: Modding Tools