dao::Module
The running game executable, and turning the library’s address IDs into addresses in it.
Declared in dao/Module.h.
Classes
| Class | |
|---|---|
| CodeRange | The exe’s .text section in runtime addresses, as the half-open range [begin, end). |
| Place | A place in the exe’s code: an ID, and how many bytes past the ID’s address. |
Functions
Address()
std::uintptr_t Address(AddressId id)
Turns an ID from dao/Addresses.h into an address in the running process.
Returns 0 if the build is unknown or has no such ID; At() then returns null, and Detour::Attach refuses it
AddressFile()
std::filesystem::path AddressFile()
Returns the address file in use.
It is the one named for the exe’s header fields, or, when none is, the one of the known build whose code the exe has (MatchedByCode).
Returns an empty path if there is none
AddressFolder()
std::filesystem::path AddressFolder()
Returns the folder the running build’s address file was found in.
Returns an empty path if none was found
Base()
std::uintptr_t Base()
Returns the address the exe is loaded at.
Build()
std::optional<daoaddr::BuildInfo> Build()
Returns the four header fields the address library uses to identify a build: link stamp, image size, entry point and base.
Returns nullopt if the headers cannot be read or the exe is not 32-bit
Code()
std::optional<CodeRange> Code()
Returns the exe’s code section.
Returns nullopt if the section table cannot be read
Containing()
std::optional<Place> Containing(std::uintptr_t runtime)
Finds the ID at or below a runtime address in the exe, and how far past it the address is.
Given a hook’s _ReturnAddress(), this names the calling function by an ID that is the same in every build:
const auto caller = dao::Module::Containing(reinterpret_cast<std::uintptr_t>(_ReturnAddress()));
if (caller && caller->id == kTheScriptsAddCommand) ...
The offset is measured in the running build. It can differ from the GOG build’s in a function the library marks as changed.
Returns nullopt if the build is unknown, or the address is outside the exe, before its first ID, or farther past the nearest ID than any function is long
Find()
std::optional<daoaddr::Entry> Find(AddressId id)
Returns what the address library records about an ID in the running build: whether its code differs from the GOG build’s, and whether other IDs share its address.
Returns nullopt if the build is unknown or has no such ID
Fingerprint()
std::optional<core::Fingerprint> Fingerprint()
Reads the fingerprint of the loaded exe from its headers in memory.
Returns nullopt if the headers cannot be read
ImageAddress()
std::uint32_t ImageAddress(std::uintptr_t runtime)
Turns a runtime address into the running build’s own address, relative to the preferred base.
In the GOG build this is the same as Preferred.
Instance()
std::string Instance()
Returns the name of the instance this copy of the game is, as DAOLIB_INSTANCE asked for it and the loader took it, in lower case (dev/BUILDS.md).
Returns an empty string for the game as ever, which runs one at a time
IsKnownExecutable()
bool IsKnownExecutable()
Returns whether the address library has a file for the running build.
Check it before hooking or reading anything in the game.
Library()
const daoaddr::Library * Library()
Returns the address library’s file for the running build.
It is loaded on the first call.
Returns null if there is no file for this build, or the file’s header names a different build
MatchedByCode()
bool MatchedByCode()
Returns whether the address file in use was found by the exe’s code, not its headers: a repack of a known build (Steamless’ output, the Nexus “decrypted Steam” exe) whose code is that build’s.
The file’s own Library()->Build() is then the known build’s, not the exe’s.
OwnFolder()
std::filesystem::path OwnFolder()
Returns the folder of the DLL this copy of the library is linked into: a plugin’s own folder (daolib\plugins\<name>), or the loader’s.
Returns an empty path if the DLL cannot be found
Path()
std::filesystem::path Path()
Returns the full path of the exe on disk.
Preferred()
std::uint32_t Preferred(AddressId id)
Returns an ID’s address in the GOG build.
Returns 0 if the GOG build’s address file is missing or has no such ID
Preferred()
std::uint32_t Preferred(std::uintptr_t runtime)
Turns a runtime address in the exe into the matching address in the GOG build, the one that Ghidra, the logs and dao/Addresses.h use, whichever build is running.
Returns 0 if nothing in the GOG build matches the address, or the GOG build’s address file is missing. In the GOG build, or a build the library does not know, it returns ImageAddress(runtime).