# PluginContext class

> 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.

Namespace `EvilEngine.Api`, assembly `EvilEngine.Api`. Engine commit 4ff877b1.

```csharp
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](/docs/api/iplugin#load). A session's server realm does so today, as the session starts; nothing loads Plugin code in the client realm yet.

## Members

### Id (property)

```csharp
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)

```csharp
public abstract Realm Realm { get; }
```

The [Realm](/docs/api/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)

```csharp
public abstract IWeapons Weapons { get; }
```

This Plugin's view of the realm's [IWeapons](/docs/api/iweapons): register each weapon you give by its `weapon` record while you load, and it goes when you unload.

### Damage (property)

```csharp
public abstract IDamage Damage { get; }
```

This Plugin's view of the realm's [IDamage](/docs/api/idamage): add deciders that change [damage](/docs/api/damage) before it lands, like a game's hit groups or armour. They go when you unload.

### Npcs (property)

```csharp
public abstract INpcs Npcs { get; }
```

This Plugin's view of the realm's [INpcs](/docs/api/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)

```csharp
public abstract IAgents Agents { get; }
```

This Plugin's view of the realm's [IAgents](/docs/api/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)

```csharp
public abstract IPhysicsWorld? Physics { get; }
```

This Plugin's view of the session's [IPhysicsWorld](/docs/api/iphysicsworld), or `null` in a realm or session with no physics. It reads every body and the world's gravity, but [Remove](/docs/api/iphysicsworld#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)

```csharp
public abstract ICrosshairs? Crosshairs { get; }
```

This Plugin's view of the session's [ICrosshairs](/docs/api/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)

```csharp
public abstract ISelections? Selections { get; }
```

This Plugin's view of the session's [ISelections](/docs/api/iselections), or `null` in a realm without one, its layers named and cleared up as [Crosshairs](#crosshairs)' are.

### Content (method)

```csharp
public abstract ContentHandle Content(ContentKind kind, ContentId id)
```

Returns a [ContentHandle](/docs/api/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)

```csharp
public abstract void Export(string api, object implementation)
```

Publishes an object under an API name, such as `"evil.fungus"`, for other Plugins to [Import](#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](#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)

```csharp
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.
