Setting up a mod - brandonandzeus/Trainworks2 GitHub Wiki
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 game 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, 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.
Bepinex is configurable; if you want to view console messages while your plugin loads for debugging, you can enable this in Bepinex's config file.
This file should be located at C:\Program Files (x86)\Steam\steamapps\workshop\content\1102190\2187468759\BepInEx\config
The first 3 directories may be different depending on where Steam is installed, so take note of this.
Anywho, open Bepinex.cfg find this section and set it to True
## Enables showing a console for log output.
# Setting type: Boolean
# Default value: false
Enabled = true
Now, when you run the game, a command prompt will also come up. Take care not to wildly click at the console while the game is loading. This sometimes causes the Game to freeze up for some reason. You won't see the internal Monster Train logs with this, so if you do something really incorrect, you won't notice until you look at the logs Shiny Shoe provides.
To find the internal logs it should be located at <user>\AppData\LocalLow\Shiny Shoe\MonsterTrain
replacing user with Drive:\Users\Username in my case its C:\Users\Brandon\AppData\LocalLow\Shiny Shoe\MonsterTrain
anywho the file logfile.log should contain these logging messages.
Next: Modding Tools