Skip to content
EvilEngine.Api

PluginContext class

public abstract class PluginContext

A Plugin’s handle on the engine in one realm: its identity, which realm it’s in, the weapons it gives, the world’s physics, crosshairs and weapon selection, content by id, and the way to share an API with other Plugins.

It’s abstract, and the host gives each Plugin its own instance in Load. A session’s server realm does so today, as the session starts; nothing loads Plugin code in the client realm yet.

Assembly
EvilEngine.Api
Commit
4ff877b1

Members

Id property

public abstract string Id { get; }

The Plugin’s id, exactly as id in its plugin.toml. The manifest reader only accepts lowercase letters, digits, ., _ and -, and the id is the namespace of every namespace:object id the Plugin names.

Realm property

public abstract Realm Realm { get; }

The Realm this context belongs to. The plan is one Load and one context per realm a Plugin runs in, so a Plugin that runs on both sides checks this to decide what to set up.

Weapons property

public abstract IWeapons Weapons { get; }

This Plugin’s view of the realm’s IWeapons: register each weapon you give by its weapon record while you load, and it goes when you unload.

Damage property

public abstract IDamage Damage { get; }

This Plugin’s view of the realm’s IDamage: add deciders that change damage before it lands, like a game’s hit groups or armour. They go when you unload.

Npcs property

public abstract INpcs Npcs { get; }

This Plugin’s view of the realm’s INpcs: register each NPC class you give while you load, so a spawnable naming it spawns with its health. They go when you unload.

Agents property

public abstract IAgents Agents { get; }

This Plugin’s view of the realm’s IAgents: register each brain you give while you load, so an agent record naming it thinks with it. They go when you unload.

Physics property

public abstract IPhysicsWorld? Physics { get; }

This Plugin’s view of the session’s IPhysicsWorld, or null in a realm or session with no physics. It reads every body and the world’s gravity, but Remove takes out only bodies and joints this Plugin added, returning false for any other, and what it added goes when it unloads. A body added here is simulated and traced against, not drawn.

Crosshairs property

public abstract ICrosshairs? Crosshairs { get; }

This Plugin’s view of the session’s ICrosshairs, or null in a realm without one. Its layers are named for it: a layer’s source is <id>:<name>, so ctf:teams for the Plugin ctf, and setting or clearing any other source throws ArgumentException, so one Plugin never moves another’s layer. Its layers go when it unloads.

Selections property

public abstract ISelections? Selections { get; }

This Plugin’s view of the session’s ISelections, or null in a realm without one, its layers named and cleared up as Crosshairs’ are.

Content method

public abstract ContentHandle Content(ContentKind kind, ContentId id)

Returns a ContentHandle for converted content of a ContentKind (model, material, texture, sound, map and so on) under a ContentId, such as quake:id1/maps/e1m1. A Plugin doesn’t open a mount’s files itself: it names content by id, and the engine converts it.

Export method

public abstract void Export(string api, object implementation)

Publishes an object under an API name, such as "evil.fungus", for other Plugins to Import.

The manifest declares each export up front under [exports."<name>"], with a version, an optional realm ("server", "client" or "menu") and the functions it holds. The host reads those declarations when it resolves the load order: a Plugin that needs an API loads after the Plugins that export it. In a realm, the last Plugin to export a name is the one Import gives, and when it unloads, or fails to load, the export before it comes back. Nothing checks the object you pass against the declaration yet.

Import method

public abstract T? Import<T>(string api) where T : class

Returns the implementation another Plugin exported under an API name, as T, or null.

Declare the API in needs or wants in plugin.toml. A needs API that no loadable Plugin exports refuses your Plugin at boot, before any code would run, so a needs import can count on being there. A wants is optional, so be ready for null.

Each Plugin’s code loads into its own load context, and only the engine’s own assemblies are shared between them. A type declared in another Plugin’s DLL isn’t the same type in yours.