diff --git a/src/Offsets.h b/src/Offsets.h index f437fde1..7d80e877 100644 --- a/src/Offsets.h +++ b/src/Offsets.h @@ -108,8 +108,11 @@ enum Offsets { // with FUN_XML_TREE_LOAD and loads every root ``; any other node // gets "Unknown node type %s in %s". Called for FrameXML's Bindings.xml // (0x00490018) and for each addon's (FUN_0051F240). + // The status is used only through `Add` (vtable +0xC), with at most two + // string arguments after the format. FUN_BINDINGS_LOAD_FILE = 0x004B6F70, VAR_BINDINGS_LOAD_STATUS = 0x00B7124C, + STR_BINDINGS_UNKNOWN_NODE = 0x00846FB4, // "Unknown node type %s in %s" (file bytes) // CGUIBindings::LoadBindings — `void __fastcall(int set, const char *text)`: // clears the set, then binds every `bind KEY COMMAND` line. Sources: // WTF\DefaultBindings.wtf into set 0 (FUN_004B62B0), then the account / diff --git a/src/bindings/ModifiedClick.cpp b/src/bindings/ModifiedClick.cpp index fdbcd63a..79c78825 100644 --- a/src/bindings/ModifiedClick.cpp +++ b/src/bindings/ModifiedClick.cpp @@ -21,8 +21,11 @@ // gains the modified-click half 4.3.4 has, through a co-hook on the step: // // - Load (Bindings.xml): `` defines -// an action and its default. The engine loader warns on the node it does -// not know; we register the actions from the same file first. +// an action and its default. We register the actions from the same file +// first. The engine's loop tests each root tag inline and logs "Unknown +// node type" for anything but ; 4.3.4's loop has a ModifiedClick +// branch there, so the loader runs with a status that drops exactly that +// warning for a ModifiedClick node and forwards everything else. // - LoadBindings (a binding file into a set): the set starts from the // defaults, then `modifiedclick BINDING ACTION` lines apply. // - SaveBindings: `modifiedclick` lines for every action not left at its @@ -40,6 +43,7 @@ #include "Game.h" #include "Offsets.h" #include "addons/EngineIO.h" +#include "baselib/Ascii.h" #include "frame/ClickEvents.h" #include "input/Modifier.h" #include "xml/FrameLoad.h" @@ -241,12 +245,36 @@ void LoadModifiedClicks(const char *path, void *status) { reinterpret_cast(Offsets::FUN_XML_TREE_FREE)(tree); } +// The status the engine loader is given: a CStatus whose only used slot, +// Add (vtable +0xC), forwards to the real status. Load passes at most two +// string arguments after the format, and Add is __cdecl, so taking exactly +// two is safe whatever the format consumes. +struct LoadStatus { + const void *const *vtable; + void *real; +}; + +void __cdecl LoadStatusAdd(LoadStatus *self, int level, const char *fmt, const char *a, + const char *b) { + if (fmt == reinterpret_cast(Offsets::STR_BINDINGS_UNKNOWN_NODE) && + a != nullptr && Ascii::EqualCI(a, "ModifiedClick")) + return; // a node this loader now knows (LoadModifiedClicks) + using Add_t = void(__cdecl *)(void *status, int level, const char *fmt, ...); + const void *vtable = Game::Read(self->real, 0); + Game::Read(vtable, Offsets::VTBL_XML_STATUS_ADD)(self->real, level, fmt, a, b); +} + +static_assert(Offsets::VTBL_XML_STATUS_ADD == 3 * sizeof(void *)); +const void *const kLoadStatusVtable[4] = {nullptr, nullptr, nullptr, + reinterpret_cast(&LoadStatusAdd)}; + int __fastcall LoadFile_h(void *mgr, void *edx, const char *path, void *md5, void *status) { + if (status == nullptr) + status = reinterpret_cast(Offsets::VAR_BINDINGS_LOAD_STATUS); if (path != nullptr) - LoadModifiedClicks(path, status != nullptr - ? status - : reinterpret_cast(Offsets::VAR_BINDINGS_LOAD_STATUS)); - return g_loadFileOriginal(mgr, edx, path, md5, status); + LoadModifiedClicks(path, status); + LoadStatus filtered{kLoadStatusVtable, status}; + return g_loadFileOriginal(mgr, edx, path, md5, &filtered); } // --- binding files: modifiedclick lines -----------------------------------