Skip to content

Anatomy of a Mod

veesusmikelheir edited this page Jul 26, 2019 · 1 revision

Introduction

SRML mods have a very well defined structure behind them, and this page goes over that indepth.

The Mod DLL

This compiled .net binary contains all the code for your mod, pretty self explanatory.

modinfo.json

In order for a mod to be recognized by SRML it needs to have a file called modinfo.json, either as an embedded resource or in a folder with the dll. It contains data essential to SRML, such as the mod id, name, version, and dependencies.

{
  "id": "myfirstmod", // the internal ID SRML uses to refer to the mod
  "name": "My First Mod", // plaintext name for the mod
  "author": "veesus mikel heir", // author of the mod
  "description": "This is the first mod I have ever made!", // description of the mod
  "version": "1.0", // current version of the mod
  "dependencies": [ // hard dependencies for the mod, in the format [modid] [version]
    "another_mod 1.0"
  ],
  "load_after": [ // array of modids that your mod wants to be loaded after (if present, not a hard dependency)
    "colorful_slimes"
  ],
  "load_before": [ // array of modids that your mod wants to loaded before (if present, not a hard dependency)
    "gold_largos"
  ]
}

Here is a sample of a complete modinfo.json

The Entry Point

Every mod needs an entry point, which is where your mods code execution starts. Every mod assembly needs exactly one class extending IModEntryPoint or the abstract class ModEntryPoint Every mod has 3 loading steps available to it, PreLoad, Load, and PostLoad

PreLoad

This step is the primary registration step and is used for registering completely custom assets and objects. It is also the only step where you're able to add new values to enums. GameContext.Instance has not yet been set during this step, as it happens before GameContext.Awake, so be careful what you use.

Load

This step is a secondary loading step where you have access to GameContext.Instance, and can interact with vanilla game assets.

PostLoad

PostLoad is a tertiary loading step where all modded data is registered, and thus can be manipulated. Use this step for manipulating existing objects or assets.

Clone this wiki locally