Creating a mod - MaxWasUnavailable/SailwindModRepository GitHub Wiki

Getting Access to required DLLs

First, you going to need to have access to 0Harmony.dll and UnityModManager.dll that is within %Game Folder%/Sailwind_Data/Managed/UnityModManager.
You will also need to get access to Assembly-CSharp.dll, which is located in %Game Folder%/Sailwind_Data/Managed, here you will also get access to any other DLL you may need to mod the game.

Creating the C# Project

This tutorial will use Visual Studio as the IDE, so if you are using a different IDE, be sure to do the equivalent on your IDE.

Create a new project, with the Class Library (.Net Framework) template.

When the project opens, you will see something along of this.

Rename Class1.cs to Main.cs and rename the class to be Main as well, and make the class static.

Adding References

You will now need to add references to 0Harmony.dll, UnityModManager.dll and Assembly-CSharp.dll.
Right-click on References on the right, and click Add Reference.


It will open this window, now click on Browse... at the bottom and navigate to your %Game Folder%/Sailwind_Data/Managed folder.


Select the Assembly-CSharp.dll and click Add, then click on Browse... again and now go into UnityModManager Folder and select 0Harmony.dll and UnityModManager.dll and click Add.

Creating Mod

First, we got to create a few static variables.
Create a boolean called enabled, this will help track if the mod is enabled or disabled.
Then, create a variable of type UnityModManager.ModEntry (you may need to import UnityModManagerNet), and call it mod.

In your Main.cs create a public static bool Load(UnityModManager.ModEntry modEntry) function, this will be your entry method.
Inside that function, we got to tell Harmony to patch our mod into the game, it is simple to do so, just do

new Harmony(modEntry.Info.Id).PatchAll(Assembly.GetExecutingAssembly());

Afterwards, we got to assign our mod variable to the modEntry parameter, and return true.
We still need to tell the mod when it is disabled or enabled, for this, create a new static function called OnToggle that returns a boolean and has a UnityModManager.ModEntry and boolean as its parameters.
In this function, assign enabled to the boolean parameter and return true.

public static bool OnToggle(UnityModManager.ModEntry modEntry, bool value) {
    enabled = value;
    return true;
}

Back in the Load function, we now got to assign the modEntry.OnToggle to our function.

If you have been following this tutorial correctly, your code should look something like this.

public static class Main {
    public static bool Load(UnityModManager.ModEntry modEntry) {
        new Harmony(modEntry.Info.Id).PatchAll(Assembly.GetExecutingAssembly());

        mod = modEntry;

        modEntry.OnToggle = OnToggle;

        return true;
    }

    public static bool OnToggle(UnityModManager.ModEntry modEntry, bool value) {
        enabled = value;
        return true;
    }

    public static bool enabled;
    public static UnityModManager.ModEntry mod;
}

Now, before compiling your code, make sure that the build configuration is set to Release.
You will then find the compiled DLL inside the bin folder, and release folder, it should have the same name as your project.

Having the game recognise your mod

We still got a few more things to do before the game can recognise your mod.
Go to your Mods folder and create a new folder with the name of your mod.
Inside, create a info.json file with at least the required fields shown below.

{
  "Id": "TestMod", - Required
  "DisplayName": "Test Mod", - Required
  "Author": "username", - Required
  "Version": "1.2.3.4", - Required
  "ManagerVersion": "0.24.0.0", - Required
  "AssemblyName": "TestMod.dll", - Required
  "EntryMethod": "TestMod.Main.Load", - Required
  "GameVersion": "1.0", - Optional
  "Requirements": ["SomeMod", "AnotherMod"], - Optional
  "LoadAfter": ["SomeMod", "AnotherMod"], - Optional
  "HomePage": "https://www.google.com", - Optional
  "Repository": "https://github.com/MaxWasUnavailable/SailwindModRepository", - Optional
  "Tags": ["Test", "Weather", "Overhaul"], - Optional
  "Incompatible": ["YetAnotherMod"], - Optional
  "ModloaderRequired": true, - Optional
  "Description": "This is a generic description." - Optional
}

The Id can be whatever, but it is recommended that it is the same as your DLL name.
DisplayName is the name that will display inside the game and in the Sailwind Mod Manager.
Author is pretty self-explanatory, put your name here.
The Version is the version of your mod.
It is recommended to keep the ManagerVersion as it is already "0.24.0.0", as this related to the version of UMM.
AssemblyName will be the name of your DLL.
EntryMethod is the path to the Load function inside your DLL, this is usually %namespace%.Main.Load, %namespace% being the namespace your Main class is located in.


And now your mod will be loaded into the game.

What Next

Modding Sailwind uses Harmony to patch functions, you can look at what you can do by looking at the source code of different mods and by looking at the documentation of Harmony https://harmony.pardeike.net/articles/intro.html

⚠️ **GitHub.com Fallback** ⚠️