Skip to content

Mod Support

shmellyorc edited this page Sep 12, 2026 · 4 revisions

Mod Support

VOID provides useful building blocks for modding, but it intentionally does not force one universal mod format or lifecycle on every game.

The strongest built-in pieces are:

  • mount priority for content overrides
  • loose-file and pack mounts
  • custom IMount implementations
  • custom asset types
  • [Discoverable] type discovery in loaded assemblies
  • InstanceHelper for runtime construction
  • the LibraryModAttribute marker

There is currently no built-in IMod interface, dependency resolver, workshop client, permission sandbox, or automatic DLL mod loader.

That means you can design the mod system that fits your game instead of adapting your game to one prescribed mod architecture.

Content-Only Mods

The simplest and safest form of modding is content replacement/addition through the asset mount system.

AssetManager searches mounts in priority order.

If two mounts contain the same virtual path, the earlier mount wins.

For example, imagine the base game contains:

Graphics/player.png

and a mod mount also contains:

Graphics/player.png

Put the mod mount first:

AssetManager.Instance.AddMountToStart(modMount);

Now normal game code still loads:

var player =
    AssetManager.Instance.Load<Texture>(
        "Graphics/player.png");

but the higher-priority mount can supply the replacement bytes.

The game code does not need a special "modded asset" path.

Pack-Based Content Mods

A .pack can act as an asset mount:

PackMount modPack =
    AssetManager.Instance.LoadPack(
        "Mods/MyContent.pack");

AssetManager.Instance.AddMountToStart(
    modPack);

For a lower-priority add-on that should not override base content:

AssetManager.Instance.AddMountToEnd(
    modPack);

Load all packs from a directory:

foreach (PackMount pack in
         AssetManager.Instance.LoadAllPacks("Mods"))
{
    AssetManager.Instance.AddMountToStart(pack);
}

Choose your ordering deliberately if several packs can override the same path.

Custom Mod Folders

If your game's mod layout needs behavior beyond the built-in mounts, implement IMount:

public sealed class MyModMount : IMount
{
    public string Name => "My Mod";

    public bool HasFile(string virtualPath)
    {
        // Resolve virtualPath inside your mod directory.
        return false;
    }

    public byte[] ReadFile(string virtualPath)
    {
        // Read and return the requested bytes.
        throw new FileNotFoundException(virtualPath);
    }
}

Register it:

AssetManager.Instance.AddMountToStart(
    new MyModMount());

This is enough to build Steam Workshop folders, zipped archives, network content, or another layout without changing the asset-loading code used by your game.

Data-Driven Mods

A useful pattern is to combine custom asset types with mounts.

For example, define a JSON-backed or binary item-definition asset, register it with AssetManager, then let mods provide more files of that type through their mounts.

Your game can then discover/load data from the virtual filesystem while keeping executable code out of the mod format.

Code Plugins / Code Mods

VOID's discovery helpers can support a code-plugin system after your code has loaded the assembly.

Define your own contract:

public interface IGamePlugin
{
    void Initialize();
    void Shutdown();
}

Plugin implementation:

[Discoverable(
    Name = "WeatherPlugin",
    Category = "Plugin")]
public sealed class WeatherPlugin : IGamePlugin
{
    public void Initialize()
    {
    }

    public void Shutdown()
    {
    }
}

After your plugin loader loads the assembly, refresh/scan:

InstanceHelper.RefreshAssemblies();
DiscoverableHelper.InvalidateCaches();

IReadOnlyList<Type> pluginTypes =
    DiscoverableHelper.FindAll<IGamePlugin>();

Construct them:

foreach (Type type in pluginTypes)
{
    IGamePlugin plugin =
        InstanceHelper.CreateInstanceFromType<IGamePlugin>(
            type,
            null);

    plugin?.Initialize();
}

Important Security Note

Loading an arbitrary .NET assembly gives that code the same process-level capabilities as other code in your game unless you build a sandbox/isolation boundary.

Do not treat [Discoverable], InstanceHelper, or LibraryModAttribute as a security system.

If your game accepts third-party code mods, define a clear trust model.

LibraryModAttribute

VOID includes this assembly marker:

[assembly: LibraryMod]

It can be used by a plugin/mod manager you create to identify an assembly intended to provide shared infrastructure rather than direct content.

The core engine currently does not automatically load, order, or resolve dependencies based on this attribute.

A Practical Mod Layout

One possible game-specific layout:

Mods/
├── BetterTrees/
│   ├── mod.json
│   └── Content/
│       └── Graphics/
│           └── trees.png
├── HardMode.pack
└── Plugins/
    └── MyTrustedPlugin.dll

Your game could choose to:

  1. read each mod.json
  2. create/mount its content source
  3. sort mounts by a priority from the manifest
  4. optionally load trusted plugin assemblies
  5. refresh the discovery/instance caches
  6. initialize your own IGamePlugin objects

VOID supplies the lower-level pieces. The policy and lifecycle remain yours.

What VOID Handles vs What Your Game Handles

VOID provides Your game decides
Asset mount ordering Mod manifest format
Pack mounts Enable/disable UI
Custom IMount Dependency rules
Discoverable types Plugin lifecycle
Dynamic instance construction Version compatibility
LibraryModAttribute marker DLL trust/security
Virtual paths Workshop/download integration

That separation keeps mod support flexible instead of baking one game's requirements into the engine.


Asset Management · Discoverable System · Instance Helper · Back to Home

Clone this wiki locally