Skip to content
Plugins

Writing your first Plugin

How a Plugin is laid out, what plugin.toml holds, how the engine orders Plugins at boot, and the C# entry points in EvilEngine.Api.


A Plugin is Evil Engine’s own kind of mod: a folder with a manifest, and optionally a C# half built against EvilEngine.Api. This page covers what exists today.

First, where things stand. The engine finds every installed Plugin at boot, reads its manifest, checks what it needs and works out the load order, naming the reason for everything it refuses. It reads every resolved Plugin’s Records/ and serves its Content/, so a Plugin of records and files already changes the game, as the power bar shows. When a session starts, its server loads every resolved Plugin’s C# half that runs on the server, in load order, and unloads them when it ends. The client doesn’t run Plugin code yet, and the only part of the engine a Plugin reaches beyond sharing APIs is registering weapons and their behaviours (Making weapons). The engine ships two Plugins of its own this way: evil.source, which gives Garry’s Mod’s Half-Life 2 weapons, and evil.weapons, whose generic firearm, launcher, melee and beam any weapon record can pick.

Where Plugins live

Each Plugin is a folder holding a plugin.toml, directly inside one of two places:

  • The engine’s own plugins/ folder beside the executable. When you run from the repository, .build/plugins stands in for it.
  • The player’s own user://plugins/. On Linux that’s ~/.local/share/godot/app_userdata/Evil Engine/plugins/.

The engine’s folder is read first. If two Plugins have the same id, the first one found is used and the clash is listed as a problem, so a Plugin dropped into user data can’t replace one the engine ships.

evil.fungus/
  plugin.toml
  Records/
  Content/
  Code/evil.fungus.dll

Records and content

Every .toml under Records/ is read at boot, in path order, after the mounted games’ records, and every record in it is named in your Plugin’s namespace: [barsegment."barsegment/tick"] in mybar is mybar:barsegment/tick. A file that doesn’t read, or that holds map, sky, person or liquid records (which only come from mounted games yet), is left out with its reason in the boot transcript, and the rest still load. A record can’t change another namespace’s record yet; it builds on one through its base instead.

Content/ is served under your namespace too, so mybar:fonts/mono.ttf is Content/fonts/mono.ttf. Images, fonts, sounds and text tables convert from it as they do from a mounted game.

plugin.toml

The manifest is TOML. It’s parsed, never run, so the engine can check it before trusting anything in the folder. A key it doesn’t know is an error that names the key, so a typo can’t quietly drop a requirement.

id = "evil.fungus"
name = "Evil Fungus"
version = "2.0.0"
api = 1
code = "Code/evil.fungus.dll"

[needs]
"evil.claims" = "^1"

[wants]
"evil.crawlers" = "^1"

[exports."evil.fungus"]
version = "1.0.0"
realm = "server"
functions = ["Nearest", "Feed"]
Key What it is
id Required. Lowercase letters, digits, ., _ and -. It’s the namespace of every id the Plugin names.
name, version Required. version is major.minor.patch.
api Required. The Plugin API major it was written for. This engine has 1, and anything else is refused.
code The C# assembly, a .dll path inside the folder.
needs, wants APIs this Plugin uses, by name, with a version range.
exports APIs it provides, each with a version, an optional realm ("server", "client" or "menu") and its functions.
[[mounts]] Games every player needs mounted: game, and optionally parts, platforms and builds.
breaks Plugins, with version ranges, it can’t run beside.
after, before Plugin ids to load after or before, for order alone.
global true asks for global mode.
phases Tick phases it owns, each starting with <id>:, like skate3.skating:solve.
side "both" (the default), "client" or "server".

Version ranges are ^1 (1.0.0 up to but not including 2.0.0), ^0.3 (0.3.x), * for anything, or an exact version.

global, phases and side are read and checked, but nothing acts on them yet.

How the boot resolves Plugins

Dependencies are on APIs, not on Plugins: anything that exports evil.claims at a version in range satisfies a needs of it. At boot each Plugin is checked, and refused with a reason when:

  • its api isn’t 1,
  • a mount it lists isn’t open, with the reason told apart: no adapter installed for that game, the game not mounted, or mounted but missing a part,
  • it breaks a Plugin that’s installed at a version in range, which refuses both,
  • its code DLL isn’t in its folder, or any DLL in that folder references a Godot assembly or EvilEngine.Host,
  • an API it needs isn’t exported by any Plugin that’s still loadable, which can refuse a chain of Plugins in turn,
  • it’s on a load order cycle through needs, wants, after or before.

What’s left is ordered by depth: every Plugin comes after the Plugins that export what it needs or wants, after the ones it lists in after and before the ones it lists in before, with ties broken by id. The boot transcript prints Resolved Plugin <id> <version> for each one in order and a warning for each refusal, and the line under the main menu’s buttons counts them.

The C# half

The C# half is a class library targeting net10.0 that references EvilEngine.Api. There’s no published package or template yet, so build it against the project in the repository. It can’t reference Godot or EvilEngine.Host, and the engine checks every DLL in the code folder for that before anything loads.

The entry point is the one public class that implements IPlugin. The host’s loader looks for exactly one such type in the code DLL and creates it with its parameterless constructor, in a collectible load context of its own, once per session. A DLL that doesn’t load, or a Load that throws, leaves your Plugin out of that session, with a server: note saying why.

using EvilEngine.Api;

namespace EvilFungus;

public sealed class Fungus : IPlugin
{
    private PluginContext? context;

    public void Load(PluginContext context)
    {
        this.context = context;
        if (context.Realm == Realm.Server)
            context.Export("evil.fungus", new FungusApi());
    }

    public void Unload()
    {
        context = null;
    }
}
  • Load gets a PluginContext for one realm. Everything goes through it, so keep it rather than reaching for statics.
  • Unload is for anything outside the engine you opened yourself. Drop your references into the engine there, so the load context can be collected.
  • Realm is Server or Client.
  • Weapons registers the weapons your Plugin gives, by their weapon records, while it loads.
  • Content gives a ContentHandle for converted content by id. A Plugin never opens a mount’s files itself.

Sharing an API between Plugins

Export and Import are the only way between Plugins. Declare what you export under [exports] and what you use under needs or wants, then:

var claims = context.Import<IClaims>("evil.claims");

A needs API is there or your Plugin doesn’t load, so you can count on it. A wants API may be missing, so check for null.

Each Plugin’s code loads into its own load context, and only the engine’s assemblies are shared between them. A type declared in another Plugin’s DLL isn’t the same type in yours, so keep that in mind when you pick the type you import as.

The menu realm

No Plugin code runs in the menus, Lua or C#: the main menu and pause menu run the engine’s own code alone. A Plugin will reach them through data instead, records and pages of its own, never code.