dao::saves

A plugin’s own data kept with the game’s saves; listing saves, and saving or loading.

Declared in dao/Saves.h.

Classes

Class  
Slot One save slot of one character.

Enumerations

Kind

enum class Kind : std::int32_t

The kinds of save. The numbers are the engine’s own; the scripts have no constants for them.

Value  
Manual = 0 Slot_<n>: a save the player named, or a slot the player chose.
Auto = 1 AutoSave_<n>, numbered 1 to 4.
Quick = 2 QuickSave_<n>.
Other = 3 a fourth kind the engine accepts; the game does not appear to use it

Functions

Character()

std::wstring Character()

Returns the character that a save or load applies to now.

In the world, that is the character being played; at the main menu, it is the one last chosen in the load screen, or else the first.

Returns the folder name, or an empty string before the game has finished starting

Characters()

std::vector<std::wstring> Characters()

Returns the characters that have saves, by folder name, as the load screen lists them.

Call it on the game thread, at the main menu or in the world.

Returns the names, or an empty vector before the game has finished starting

ForceLoad()

bool ForceLoad()

Answers the game’s “requires the following content” dialog with Force Load, so the most recently requested save loads without that content.

Call it only while a load you just requested has not started, since the game loads whatever it was last asked to load. A save made after a forced load no longer has the missing content. This is meant for tools that drive the game, not for a plugin to decide on the player’s behalf.

Returns true if the game accepted the answer; false, with nothing sent, if no load was ever requested

List()

std::vector<Slot> List(std::wstring_view character)

Returns a character’s save slots: manual saves first, then autosaves, then quicksaves, each in order of number.

Parameter  
character the character’s folder name

Load()

bool Load(const Slot &save)

Loads a save, the same way the load screen does.

Call it on the game thread, at the main menu or in the world. OnGameLoaded runs once the world is loaded. If the save needs content the game does not have, loading stops at the game’s “requires the following content” dialog and goes no further until it is answered; see ForceLoad.

Parameter  
save the slot to load; an empty character means the one Character() returns

Returns true if the request went to the game, which may still refuse it (in a cutscene, for example); false, with no request made, if the slot holds no save, the game knows no such character, or the game has not finished starting

MostSlot()

constexpr std::int32_t MostSlot(Kind kind)

Returns the highest slot number the game saves to for a kind.

The lowest is 1, though the game also accepts a manual save to slot 0.

Name()

constexpr std::string_view Name(Kind kind)

Returns “manual”, “auto”, “quick” or “other”, for logging.

OnGameLoaded()

void OnGameLoaded(std::function<void(const std::optional<Slot> &loaded)> callback)

Registers a callback that runs each time a game starts in the world: a save loaded, or a new game.

Callbacks run on the game thread, one at a time, and must not throw. They run while the game mode still reads as loading; if you need the world in play, also wait for explore mode.

Parameter  
callback receives the slot the save came from, or nullopt for a new game

OnSaved()

void OnSaved(std::function<void(const Slot &saved)> callback)

Registers a callback that runs each time the game writes a save, once the save is written.

The save’s picture, screen.dds, is written after: a callback that reads the slot’s folder may find it missing or empty.

Callbacks run on the game thread, one at a time, so state shared with OnGameLoaded callbacks needs no lock. They must not throw.

Parameter  
callback receives the slot that was written

Save()

bool Save(Kind kind, std::int32_t slot=-1, std::wstring_view name={})

Saves the game, the same way the save screen does for a manual save and the quicksave key does for a quicksave.

Call it on the game thread. The save is written over the next few frames, and OnSaved runs once it is done.

Parameter  
slot the slot number, or -1 for the next free one; for a manual save, that is the current character’s lowest slot with no save in it
name the save’s name, shown in the load screen and used in its file name (its spaces dropped); if empty, the file is named “savegame”. A quicksave or an autosave keeps the game’s own, unnamed

Returns true if the game started the save; false where the game allows no saving (in combat or a cutscene), before the game has finished starting, or when all 500 manual slots are taken