dao
Everything in DAOLib: the game’s classes and the library’s parts, each in a namespace of its own.
Declared in dao/Frame.h, dao/GameModes.h, dao/Log.h, dao/Module.h, dao/ObjectId.h, dao/Plugin.h, dao/SafeRead.h, dao/String.h, dao/Structures.h, dao/TypeName.h.
Classes
| Class | |
|---|---|
| CameraController | The controller of the camera in explore and combat mode: what the camera follows, where it looks, and the zoom the player has set. |
| CCArea | An area of the world. |
| CCCreature | A creature: a party member, or anyone else who fights, talks or walks. |
| CCItem | An item. None of its fields are wrapped yet. |
| CClientExoApp | The game’s client application object. You never construct one: call Get() for the game’s. |
| CCModule | The module: the game being played, which holds the areas. |
| CCObject | An object in the world: a creature, placeable, waypoint or item. |
| CCPlaceable | A placeable: a door, chest, lever or other usable thing in the world. |
| CCWayPoint | A waypoint: a marked point in an area, which can also be a map pin. |
| CDataArrays | The parameter lists that an effect, an event or a command carries, read and written by index. |
| CGameEffect | A script’s effect or itemproperty, with its parameters (CDataArrays). |
| CGameObject | Any game object; the base of every object class in this file. |
| Command | A command queued on an object (CCObject::QueueCommand). |
| CScriptEvent | A script’s event, with its parameters (CDataArrays). |
| CScriptLocation | A script’s location: a position and an orientation in an area. |
| Detour | A detour on one of the game’s functions, placed with Microsoft Detours. |
| Field | A field of type T, reached from an object through a path of Depth offsets. |
| GameModeController | The controller that holds the game’s modes and switches between them. |
| GameModeExplore | Explore mode, which combat mode is built on. |
| ItemPossessor | An object’s inventory (CGameObject::AsItemPossessor). Its layout is not yet known. |
| LoaderInfo | What the loader passes to DAOLib_Load. |
| Opaque | The base of the engine types in this file. |
| Patch | Bytes of the game’s exe written over in place, only where they are what the plugin expects. |
| Resource | A script’s resource: the name of a file the game loads, which a script writes as R”gen00fl_dog.utc”. |
| SceneCamera | The game’s scene camera, which the CameraController drives: its position, its angles around the point it looks at (the focus), and its zoom. |
| SEffectsHolder | The effects on an object (CGameObject::AsEffectsHolder). Its layout is not yet known. |
| Vector | A script’s vector: three floats. |
| WString | A std::wstring with the memory layout the game uses (MSVC 2005’s, see dao/core/Msvc8.h). |
Type aliases
LoadFn
using LoadFn = bool(__cdecl *)(const LoaderInfo *)
The type of DAOLib_Load, the function a plugin exports.
The loader calls it once, from the executable’s entry point, before any game code has run. It runs on the process’s main thread, which is not the game thread (dao/Frame.h). A detour placed here is therefore in place before the game first calls the hooked function. No game object exists yet, so place hooks but read nothing from the game. Return false to refuse to load; the loader logs the refusal and carries on.
ObjectId
using ObjectId = std::uint32_t
The id of an engine object. It is the same number a script’s object holds.
Enumerations
EngineStructure
enum class EngineStructure : std::int32_t
The engine structures, with the same numbers script.ldf gives them.
| Value | |
|---|---|
Event = 0 |
|
Location = 1 |
|
Command = 2 |
|
Effect = 3 |
|
ItemProperty = 4 |
also a CGameEffect: copying either makes a 0x7C-byte object |
Player = 5 |
GameMode
enum class GameMode : std::int32_t
The game’s modes, with the same numbers as the scripts’ GM_* constants.
The comment on each names the engine class that runs it.
| Value | |
|---|---|
Explore = 0 |
GameModeExplore. |
Combat = 1 |
GameModeCombat. |
Dead = 2 |
GameModeDead. |
Gui = 3 |
GameModeGUI: a menu screen over the game. |
Dialog = 4 |
GameModeDialog. |
Cutscene = 5 |
GameModeCutscene. |
FlyCam = 6 |
GameModeFlyCam. |
Fixed = 7 |
GameModeFixed. |
Pregame = 8 |
GameModePregame: the main menu when the game starts. |
Loading = 9 |
GameModeLoading. |
Movie = 10 |
GameModeMovie. |
CharGen = 11 |
GameModeCharGen: character creation, and sometimes the main menu. |
PartyPicker = 12 |
GameModePartyPicker. |
Functions
At()
T * At(AddressId id)
Returns a pointer into the game for an ID from dao/Addresses.h, or null if the running build does not have it.
CompleteObject()
const void * CompleteObject(const void *object)
Returns the start of the whole object, given a pointer to one of its base classes, using the offset stored in the vtable’s type information.
A pointer the game passes around can point at a base class inside a larger object, and then the object’s fields are not where the pointer points.
Returns null if the pointer is null, or the object’s vtable or its type information lies outside the exe’s image
DecoratedTypeName()
std::string_view DecoratedTypeName(const void *object)
Returns the decorated class name of an object, such as “.?AVFoo@Bar@@”.
It is safe to call on any pointer, even one to freed memory: every read is checked.
Returns an empty view if the pointer is null, or if the object, its vtable or its type information lies outside the exe’s image, which means the object has no vtable or is not an object at all
FrameCount()
std::uint64_t FrameCount()
Returns how many frames have run since the first callback was added.
FrameThreadId()
std::uint32_t FrameThreadId()
Returns the ID of the game thread, the one the last frame ran on; 0 before the first frame.
Global()
T Global(AddressId id)
Reads a global the game keeps, such as the application’s or the GUI manager’s pointer.
Returns its value, or T{} (null for a pointer) if the running build has no address for it
LogDirectory()
std::filesystem::path LogDirectory()
Returns the folder logs are written to: <Documents>\BioWare\Dragon Age\daolib, or the same path under the temporary folder if the Documents folder cannot be found.
This function does not create the folder.
OnFrame()
void OnFrame(std::function<void()> callback)
Adds a callback to run once per frame, just before the game’s update.
Call it when the plugin loads or later. Callbacks also run while the game is paused.
| Parameter | |
|---|---|
callback |
runs inside the frame, so keep it short and never block |
OpenLog()
void OpenLog(std::string_view name)
Opens <name>.log in LogDirectory() and makes it this DLL’s default spdlog logger.
The previous run’s file is kept as <name>.previous.log, one generation. The first line says which log level is in effect. Call it once per DLL; later calls do nothing. Lines are written by a background thread, so logging never waits for the disk: warnings and errors are written at once, other lines within kLogLatency. If a second copy of the game is started while one is running, it writes <name>.<process id>.log instead (OwnsLogs).
| Parameter | |
|---|---|
name |
the start of the file name, usually the plugin’s name |
OwnsLogs()
bool OwnsLogs()
Returns whether this game has the plain file names in LogDirectory(): <name>.log, and with it any file a plugin keeps beside the logs under a name of its own.
Every DLL of a game gets the same answer, at any time for as long as the game runs, before or after OpenLog. A named instance has a log folder of its own and is the first game in it.
Returns true for the first game running in its log folder; false for one started while that one runs, which OpenLog gives <name>.<process id>.log, and which should name its own files by its process id too
TryCopy()
bool TryCopy(void *out, std::uintptr_t address, std::size_t size) noexcept
Copies size bytes from address to out.
Returns false if any byte could not be read; out is then left in an unspecified state
TryRead()
std::optional<T> TryRead(std::uintptr_t address) noexcept
Reads a T from address.
T must be trivially copyable.
Returns nullopt if any byte could not be read
TypeName()
std::string TypeName(const void *object)
Returns the undecorated class name of an object, such as “Bar::Foo”.
A template’s name is left decorated rather than guessed at.
Returns an empty string in the same cases as DecoratedTypeName
Utf8()
std::string Utf8(std::wstring_view text)
Converts UTF-16 text, which the game uses, to UTF-8, for example for a log.
Wide()
std::wstring Wide(std::string_view text)
Converts UTF-8 text, a Flash movie’s for one, to UTF-16.
Variables
kInvalidObject
constexpr ObjectId kInvalidObject = 0xFFFFFFFF
The id that names no object, the scripts’ OBJECT_INVALID.
kLoadExportName
constexpr const char * kLoadExportName = "DAOLib_Load"
the exported function’s name
kLogLatency
constexpr std::chrono::milliseconds kLogLatency{250}
The longest a log line waits in memory before it is written to its file.
Wait this long before reading another DLL’s log for its latest lines.
kPluginApiVersion
constexpr std::uint32_t kPluginApiVersion = 2
The version of this contract.
A plugin should refuse to load when LoaderInfo::apiVersion differs from the version it was built with.