dao::Patch
class
Bytes of the game’s exe written over in place, only where they are what the plugin expects.
// The order the engine tries a model's levels of detail in, for each level asked for.
constexpr std::array<std::int32_t, 16> kVanilla = {0, 1, 2, 3, 1, 0, 2, 3, 2, 1, 0, 3, 3, 2, 1, 0};
constexpr std::array<std::int32_t, 16> kFull = {0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3};
dao::Patch g_order;
g_order.Apply({dao::addr::kModelLodOrder, 0}, kVanilla, kFull);
Apply from DAOLib_Load, before the game’s code runs: the bytes are written one at a time, so a thread reading them meanwhile can see half the change. Later, only bytes no thread is reading. The destructor puts the bytes back, silently, if they are still the replacement.
Declared in dao/Patch.h.
Functions
Apply()
bool Apply(Module::Place at, const T &expected, const T &replacement)
Writes replacement at a place in the exe, if the bytes there are expected.
| Parameter | |
|---|---|
at |
an ID from dao/Addresses.h, and how many bytes past its address |
expected |
the bytes as they are in the build, any trivially copyable value: an int, a std::array of bytes or of ints |
replacement |
what to write, of the same type |
Returns true if written. False, with nothing changed and a warning logged, if this patch is already applied, the running build has no such ID, the bytes there are not expected (a build that differs, or another plugin’s patch), or the memory could not be written.
ApplyAt()
bool ApplyAt(std::uintptr_t address, const T &expected, const T &replacement)
Writes replacement at an address, if the bytes there are expected: memory with no ID, such as another module’s.
Returns as Apply does.
IsApplied()
bool IsApplied() const
Returns true while the replacement is in place.
operator=()
Patch & operator=(const Patch &)=delete
Patch()
Patch()=default
Patch()
Patch(const Patch &)=delete
Revert()
bool Revert()
Puts back the bytes the patch wrote over.
Returns true if they are back, or nothing was applied. False, with the bytes left and a warning logged, if they are no longer the replacement: something else wrote them since.
~Patch()
~Patch()