# IGameAdapter interface

> Recognises one game's install and plans how it mounts. An adapter registers one per game with AddGame.

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

```csharp
public interface IGameAdapter
```

Recognises one game's install and plans how it mounts. An adapter registers one per game with [AddGame](/docs/api/adaptercontext#addgame).

When the engine reads a location, a pointer's folder or a picked disc image, every registered game adapter's [Probe](#probe) gets the same read-only tree. Each that recognises it says which game, platform and build it is. If none does, the engine looks inside the archives at the top of the tree with the registered containers and probes those, up to three levels deep. When the game opens, at boot from a saved pointer or when the player ticks it in the main menu, [Open](#open) plans the mount's layers and parts.

One location can hold more than one game. Steam's Quake folder holds the original in `id1/` and the rerelease in `rerelease/`, so `QuakeGame` and `QuakeRereleaseGame` both recognise it and one pointer mounts both.

## Members

### Game (property)

```csharp
string Game { get; }
```

The game's name, such as `quake` or `gmod`. It has to be in `games` in the adapter's `adapter.toml`, or [AddGame](/docs/api/adaptercontext#addgame) throws. It's the first part of every mount id the adapter returns and the namespace its content converts under, so `quake` content is `quake:...`.

### Platforms (property)

```csharp
IReadOnlyList<Platform> Platforms { get; }
```

The platforms this adapter reads the game on, as `Platform` values with an id, a byte order and a case rule. Quake and every PC game here use `PcPlatform.Platform` from the `pc` adapter: id `pc`, little-endian, case-insensitive.

Nothing in the host reads this list yet. What counts is the platform in the `MountId` your probe returns.

### Probe (method)

```csharp
MountProbe? Probe(IFileSource tree)
```

Looks at a tree and returns a `MountProbe` if it's this game, or `null` if it isn't.

A probe names the mount with a `MountId` of game, platform and build, like `quake/pc/1.06`, and a `ProbeStatus`: `Known`, or `UnknownVariant` for the game at a build the adapter doesn't have a version for, `NeedsKey` for one it can't read without a key, and `Damaged`. Add `Evidence`, short lines saying what the probe saw, which the boot prints, and any `Externals` the game reads from outside its own folder, which the host resolves before it calls [Open](#open).

Probes run on every location the engine reads, so read as little as you can: a couple of headers or a version file, not the whole install. Return `null` rather than throwing, since the host doesn't catch exceptions from a probe. When several games match the same tree, `Known` probes rank first, then higher `Confidence`.

Quake's original edition tells its build from where `PAK0.PAK` and `PAK1.PAK` keep their directories:

```csharp
public MountProbe? Probe(IFileSource tree)
{
    if (tree.Exists(QuakeRereleaseGame.Kpf) || Header(tree, Pak0) is not { } first)
        return null;
    var evidence = new List<string> { $"{Pak0}'s directory is at {first.Offset} for {first.Length} bytes" };
    var second = Header(tree, Pak1);
    if (second is not null)
        evidence.Add($"{Pak1}'s directory is at {second.Value.Offset} for {second.Value.Length} bytes");
    if (second is null || !Labels.TryGetValue((first, second.Value), out var label))
    {
        evidence.Add(second is null
            ? $"there's no {Pak1}, as a shareware copy has none, so the build is unknown"
            : "that pair isn't one the adapter has a version for, so the build is unknown");
        return new MountProbe(new MountId(Game, Pc.Id, "unknown"), ProbeStatus.UnknownVariant, tree)
            { Evidence = evidence, Externals = SteamClaims.Externals };
    }

    evidence.Add($"that pair is the registered {label}");
    return new MountProbe(new MountId(Game, Pc.Id, label), ProbeStatus.Known, tree)
        { Evidence = evidence, Externals = SteamClaims.Externals };
}
```

### Open (method)

```csharp
MountPlan Open(MountProbe probe, Externals externals)
```

Plans the mount from your own probe and the resolved externals, and returns a `MountPlan`. The mount core builds the mount from the plan, so `Open` describes and doesn't read more than it needs to.

The plan holds the case rule for paths and:

- `Layers`, each a `LayerPlan` with a name, a role and a source: a tree, a container inside a tree (opened lazily, and placed at a folder with `At`), a host folder or another mount. The first layer wins when two hold the same path, as a game's own search order does.
- `Parts`, the named pieces of the game a Plugin can require on their own, each with the files that define it for fingerprinting.
- `BuildFiles`, the files that fingerprint the build as a whole.
- `Requires`, other mounts this one needs open.
- `Records`, the record sets the host reads at boot, such as `records/maps` for the map picker.
- `Text`, the text tables the host reads for the game's own strings.
- `Notes`, shown on the game's card in the main menu. Say there what was left out and why.

Throw `MountException` when the game can't be mounted. The pointer is reported as failed with your message, and every other game still mounts.
