Using the Trainworks Modding Tools - brandonandzeus/Trainworks2 GitHub Wiki

Using the Trainworks Modding Tools

If all you want to do is add new cards and clans, you may not even need to touch Harmony. The Monster Train Modding framework provides an easy way to add new content without jumping through hoops to get there. This tutorial will focus on setting up your project to use the framework, and future ones will discuss using its various features.

Referencing the Framework

The first thing you'll want to do is install the framework, if you haven't already. Get it from the Steam workshop.

Once it's done downloading, add its dll as a reference, the same way you added the Unity and BepInEx stuff when you first set up the project. Remember to set Copy Local to "No."

Using the Framework

The first thing you'll want to do is mark your plugin as depending on the framework. Add the following annotation to your plugin class, underneath the other ones: [BepInDependency("tools.modding.trainworks")]

Then, you'll want to add a using statement to the top of your file:

using Trainworks.Interfaces;

Have your plugin implement the IInitializable interface. All told, it'll probably end up looking something like this:

[BepInPlugin("com.name.package.generic", "Test Plugin", "0.1.0")]
[BepInProcess("MonsterTrain.exe")]
[BepInProcess("MtLinkHandler.exe")]
[BepInDependency("tools.modding.trainworks")]
public class TestPlugin : BaseUnityPlugin, IInitializable
{
    private void Awake()
    {
        var harmony = new Harmony("com.name.package.generic");
        harmony.PatchAll();
    }

    public void Initialize()
    {
    }
}

The Initialize() method will be called automatically once the modding framework's done setting itself up. If you do anything with the framework at all, you should do it out of the Initialize() method. Doing stuff in the Awake() method, as we did with Harmony, will probably crash your game.

Run the game. Check the logs to confirm that both your plugin and the modding framework are being loaded. Then move on to the next tutorial, where we'll discuss actually making use of it. Even if you are not interested in modifying existing cards, I recommend reading through it since it'll familiarize you somewhat with how Monster Train constructs its cards.

By the way, you can move the Harmony initialization stuff into the Initialize() method and delete Awake() now if you'd like. Even if you're not using any Harmony patches right now I'd recommend keeping it around since Harmony patches are very versatile and make testing much, much easier. You can remove it from your release build if you're still not using any by then.

Next: Modifying an Existing Card