Table of Contents

Class DisposableCharacterStore

Namespace
Valheim.Testing.Game
Assembly
Valheim.Testing.Game.dll

The registered disposable test characters: a directory outside every game character folder holding one copy of each character and a manifest of their names and the game's player IDs. Registering is the one explicit step that declares a character disposable; staging a character for an owned client accepts only characters registered here, so pointing a test at a personal character file is refused rather than edited.

public sealed class DisposableCharacterStore
Inheritance
object
DisposableCharacterStore

Examples

Create the test character in Valheim, complete its first spawn, visit the fixture world, then save it locally. Register that characters_local file once; on a later run, open the store and get a fresh handle:

var store = DisposableCharacterStore.Create(storeDirectory);
store.Register("tester", localCharacterFile);

store = DisposableCharacterStore.Open(storeDirectory);
var character = store.Get("tester");

After the game saves this same character again, use Refresh(string, string) and then take a new handle with Get(string). The store must be outside the game's character folders. Copies keep the same player ID; they are not independent characters for simultaneous players.

Remarks

The player ID is the save's own identity and survives the game re-saving the character, so Refresh(string, string) can take a registered character's newer save (after it visited a world) but never swaps in a different character. A registration is not a security boundary against someone deliberately editing the manifest; it stops a run, an example or a plan from using a character nobody registered.

Fields

ManifestFile

The file name of this store's own manifest, inside Root.

public const string ManifestFile = "disposable-characters.json"

Field Value

string

Properties

Names

The registered names.

public IReadOnlyList<string> Names { get; }

Property Value

IReadOnlyList<string>

Root

The store's full path.

public string Root { get; }

Property Value

string

Methods

Create(string)

Creates an empty store in a new or empty directory outside the game's character folders.

public static DisposableCharacterStore Create(string directory)

Parameters

directory string

Returns

DisposableCharacterStore

Get(string)

A registered character, verified now: listed in the manifest, stored as a plain file, and still the same player.

public DisposableCharacter Get(string name)

Parameters

name string

Returns

DisposableCharacter

Open(string)

Opens an existing store; a directory without the store's manifest is refused.

public static DisposableCharacterStore Open(string directory)

Parameters

directory string

Returns

DisposableCharacterStore

Refresh(string, string)

Replaces a registered character's stored copy with a newer local save of the same character, for example after it has visited a fixture world. A save with a different player ID is refused and the stored copy is kept.

public DisposableCharacter Refresh(string name, string localCharacterFile)

Parameters

name string
localCharacterFile string

Returns

DisposableCharacter

Register(string, string)

Declares a local character disposable: copies its save into the store under name and records its player ID. The source must be a .fch in characters_local (never a Steam Cloud folder) and is not changed. Register only characters created for tests; the game still owns and may rewrite the local original.

public DisposableCharacter Register(string name, string localCharacterFile)

Parameters

name string
localCharacterFile string

Returns

DisposableCharacter

Registers(byte[])

Whether a save belongs to a registered character: its player ID is in the manifest and that entry's stored copy is a plain file of the same player. A listed entry whose copy is missing, linked or another character throws, as Get(string) does; so does any save format error.

public bool Registers(byte[] characterFile)

Parameters

characterFile byte[]

Returns

bool