Attributes and base class
An attribute is a label you put above your class in square brackets. ModInfo gives the mod its id, name and version, and ModDependency names a mod yours needs. Your class inherits from FrameworkMod, which gives you a log, settings and the other tools a mod needs.
ModInfoAttribute goes on your class, once
Put it on your class, once. The framework reads it to find your mod’s id and name, and FrameworkMod.Info gives it back to you.
public sealed class ModInfoAttribute : Attribute
{
public ModInfoAttribute(string id, string name, string version);
public string Id { get; }
public string Name { get; }
public string Version { get; }
}
| Method | Returns | What it does |
|---|---|---|
ModInfoAttribute(id, name, version) | ModInfoAttribute | Sets the id, name and version of your mod. |
| Property | Type | What it means |
|---|---|---|
Id | string | The mod’s id, such as example.myfirstmod. |
Name | string | The name shown in the Mods menu. |
Version | string | The mod’s version, such as 0.1.0. |
ModDependencyAttribute goes on your class, as many times as you need
Put one on your class for each mod it needs. The framework reads them to plan the load order, and skips your mod when one is missing or too old.
public sealed class ModDependencyAttribute : Attribute
{
public ModDependencyAttribute(string id);
public ModDependencyAttribute(string id, string minVersion);
public string Id { get; }
public string MinVersion { get; }
}
| Method | Returns | What it does |
|---|---|---|
ModDependencyAttribute(id) | ModDependencyAttribute | The mod must be there. |
ModDependencyAttribute(id, minVersion) | ModDependencyAttribute | The mod must be there and at least this version. |
| Property | Type | What it means |
|---|---|---|
Id | string | The id of the mod you need. |
MinVersion | string | The oldest version you accept. It is null when any version will do. |
FrameworkMod the class your mod inherits from
Your class inherits this to get the Log, Config and Mod properties. The framework calls OnLoad once.
public abstract class FrameworkMod : MonoBehaviour
{
public ModInfoAttribute Info { get; }
public CoreMod Mod { get; }
public CoreLog Log { get; }
public ModConfig Config { get; }
protected abstract void OnLoad();
}
| Method | Returns | What it does |
|---|---|---|
OnLoad() | void | The framework calls this once. Start your work here. |
| Property | Type | What it means |
|---|---|---|
Info | ModInfoAttribute | The ModInfo you wrote on your class. |
Mod | CoreMod | Your mod’s handle for save data, keybinds and game patches. |
Log | CoreLog | Writes to BepInEx\logs\<your id>.log. |
Config | ModConfig | Your mod’s settings, stored in BepInEx\config\<your id>.cfg. |
Things to know
Modis the handle you use for your mod’s saved data, keybinds and game patches.Mod.Key(...)gives a keybind, the same as for a BepInEx plugin. A framework mod gets its handle fromMod. It does not useCoreMod.For, which needs a BepInEx plugin. (CoreMod.For(BaseUnityPlugin)takes a BepInEx type, which a framework mod cannot reference.)