Skip to content

Mod class ​

Namespace Lustral · Assembly Lustral.Api

The base class of a mod's entry point. Lustral creates one instance of each mod and calls it on the game's main thread.

csharp
public abstract class Mod

Remarks ​

Info, Log, Harmony, Config, Events, Coroutines, Assets, Game and Mods are available from the constructor onward. Code outside the class, such as Harmony patches, can access them through a static reference to the instance, as in the project template.

Constructors ​

Mod() ​

csharp
protected Mod()

Properties ​

Assets ​

csharp
public ModAssets Assets { get; }

Loads Unity asset bundles shipped with the mod, on both Mono and IL2CPP: Assets.LoadBundle("Assets/ui.bundle"). Paths are relative to the mod's folder. Bundles can be loaded from OnGameReady onward.

Config ​

csharp
public ModConfig Config { get; }

The mod's settings file, Lustral/config/<id>.toml: Config.Bind<Settings>().

Coroutines ​

csharp
public Coroutines Coroutines { get; }

The mod's coroutines, which behave identically on Mono and IL2CPP: Coroutines.Start(Fade()). A coroutine is an iterator method that yields null, Wait values, other iterators or Unity yield instructions.

Events ​

csharp
public GameEvents Events { get; }

Scene and frame events.

Game ​

csharp
public GameInfo Game { get; }

The game's name, developer, version, Unity version, scripting backend and folder.

Harmony ​

csharp
public Harmony Harmony { get; }

A Harmony instance identified by the mod's ID: Harmony.PatchAll(typeof(MyMod).Assembly). If the mod fails to load, Lustral removes the patches applied through this instance. Crash reports use it to identify the mod that patched each method.

Info ​

csharp
public ModInfo Info { get; }

The mod's ID, name, version and folder, as declared in its manifest.

Log ​

csharp
public ILog Log { get; }

The mod's log. Messages are tagged with the mod's ID and may contain Unity rich text tags (see ILog).

Mods ​

csharp
public LoadedMods Mods { get; }

The mods loaded so far, in load order: Mods.IsLoaded("other.mod"). Dependencies and optional dependencies are loaded before the mods that depend on them, so an installed optional dependency is always in this list.

Methods ​

OnGameReady() ​

csharp
public virtual void OnGameReady();

Called once, after the game's first scene has loaded. Unity APIs can be used from this point on.

OnLoad() ​

csharp
public virtual void OnLoad();

Called once, before the game loads its first scene. Apply Harmony patches here. Unity APIs cannot be used yet.

OnShutdown() ​

csharp
public virtual void OnShutdown();

Called once when the game quits. Limit the work to short tasks such as saving state and closing files.

Mods are third-party software. Lustral does not verify their behavior and is not responsible for any damage they cause.