mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 16:10:36 +00:00
fix(bindings): follow 4.3.4's bindings, modified clicks and key state
Modified clicks: IsModifiedClick, GetModifiedClick, SetModifiedClick, GetNumModifiedClickActions and GetModifiedClickAction, with 4.3.4's <ModifiedClick> Bindings.xml node and its 18 defaults. Each binding set loads, saves and copies them through co-hooks on the engine's own binding-set steps, in 4.3.4's "modifiedclick" file lines. [mod:] asks IsModifiedClick, as 4.3.4's macro conditions do. Direct actions run as 4.3.4's ExecKey runs them: SPELL / ITEM / MACRO on key release through 1.12's spellbook, item and macro functions, cast at you for SELFCAST and at your focus for FOCUSCAST; CLICK sends the frame a mouse down and up, with 4.3.4's virtual-click button logic built from the button's own methods. RunBinding no longer runs them. While a key binding runs, its own modifiers count as released for every modifier read, the engine's IsKeyDown included. Overrides follow 4.3.4: two lists per key, checked inside the key lookup at both of 1.12's lookup steps; GetBindingAction takes checkOverride; isPriority is loose; "" removes; the owner must be a frame. ActionButtonUseKeyDown (default 0) and 4.3.4's action-button key handlers, ported onto 1.12's bars.
This commit is contained in:
+78
-3
@@ -14,9 +14,11 @@
|
||||
#include "input/Modifier.h"
|
||||
|
||||
#include "Game.h"
|
||||
#include "Offsets.h"
|
||||
#include "event/Custom.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
@@ -81,6 +83,11 @@ constexpr const char *kModifierStateChanged = "MODIFIER_STATE_CHANGED";
|
||||
const Event::Custom::AutoReserve _reserveModifierStateChanged{kModifierStateChanged};
|
||||
|
||||
uint32_t g_modifierMask = 0;
|
||||
|
||||
// 4.3.4's m_keyStateOverride / m_heldModifiers (see KeyStateOverride).
|
||||
bool g_overrideActive = false;
|
||||
uint32_t g_overrideMask = 0;
|
||||
|
||||
HHOOK g_msgHook = nullptr;
|
||||
HHOOK g_wndProcHook = nullptr;
|
||||
|
||||
@@ -113,17 +120,38 @@ void SetBit(int bitIdx, bool down) {
|
||||
|
||||
template <int BitIdx>
|
||||
int __fastcall Script_IsKeyDown(void *L) {
|
||||
const bool down = (g_modifierMask & (1u << BitIdx)) != 0;
|
||||
const bool down = (CurrentMask() & (1u << BitIdx)) != 0;
|
||||
PushDown(L, down);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int __fastcall Script_IsModifierKeyDown(void *L) {
|
||||
const bool down = (g_modifierMask & MASK_ANY_MODIFIER) != 0;
|
||||
const bool down = (CurrentMask() & MASK_ANY_MODIFIER) != 0;
|
||||
PushDown(L, down);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// The engine's IsKeyDown for shift / ctrl / alt (0 / 1 / 2) answers from the
|
||||
// override while a binding runs, as 4.3.4's does — so IsShiftKeyDown & co. and
|
||||
// every engine modifier read agree with the L/R functions above.
|
||||
using IsKeyDown_t = int(__fastcall *)(int which);
|
||||
IsKeyDown_t g_isKeyDownOriginal = nullptr;
|
||||
|
||||
int __fastcall IsKeyDown_h(int which) {
|
||||
if (!g_overrideActive)
|
||||
return g_isKeyDownOriginal(which);
|
||||
static const uint32_t kPairs[3] = {(1u << BIT_LSHIFT) | (1u << BIT_RSHIFT),
|
||||
(1u << BIT_LCTRL) | (1u << BIT_RCTRL),
|
||||
(1u << BIT_LALT) | (1u << BIT_RALT)};
|
||||
if (which < 0 || which > 2)
|
||||
return g_isKeyDownOriginal(which);
|
||||
return (g_overrideMask & kPairs[which]) != 0;
|
||||
}
|
||||
|
||||
const Game::HookAutoRegister _isKeyDownHook{Offsets::FUN_GAMEUI_IS_KEY_DOWN,
|
||||
reinterpret_cast<void *>(&IsKeyDown_h),
|
||||
reinterpret_cast<void **>(&g_isKeyDownOriginal)};
|
||||
|
||||
// Decode the L/R bit position from a key message.
|
||||
// - `VK_SHIFT` (the merged virtual key the OS sends for either key)
|
||||
// resolves via `MapVirtualKeyA(scancode, MAPVK_VSC_TO_VK_EX)` —
|
||||
@@ -244,7 +272,54 @@ const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
||||
} // namespace
|
||||
|
||||
uint32_t CurrentMask() {
|
||||
return g_modifierMask;
|
||||
return g_overrideActive ? g_overrideMask : g_modifierMask;
|
||||
}
|
||||
|
||||
uint32_t ParseModifiers(const char *&text) {
|
||||
static const struct {
|
||||
const char *name;
|
||||
uint32_t bits;
|
||||
} kNames[] = {
|
||||
{"LSHIFT", 1u << BIT_LSHIFT},
|
||||
{"RSHIFT", 1u << BIT_RSHIFT},
|
||||
{"SHIFT", (1u << BIT_LSHIFT) | (1u << BIT_RSHIFT)},
|
||||
{"LCTRL", 1u << BIT_LCTRL},
|
||||
{"RCTRL", 1u << BIT_RCTRL},
|
||||
{"CTRL", (1u << BIT_LCTRL) | (1u << BIT_RCTRL)},
|
||||
{"LALT", 1u << BIT_LALT},
|
||||
{"RALT", 1u << BIT_RALT},
|
||||
{"ALT", (1u << BIT_LALT) | (1u << BIT_RALT)},
|
||||
};
|
||||
uint32_t modifiers = 0;
|
||||
while (*text != '\0') {
|
||||
bool matched = false;
|
||||
for (const auto &entry : kNames) {
|
||||
const size_t length = std::strlen(entry.name);
|
||||
if (_strnicmp(text, entry.name, length) == 0) {
|
||||
modifiers |= entry.bits;
|
||||
text += length;
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!matched)
|
||||
break;
|
||||
if (*text == '-')
|
||||
++text;
|
||||
}
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
KeyStateOverride::KeyStateOverride(const char *boundKey)
|
||||
: m_wasActive(g_overrideActive), m_previousMask(g_overrideMask) {
|
||||
const char *rest = boundKey != nullptr ? boundKey : "";
|
||||
g_overrideMask = g_modifierMask & ~ParseModifiers(rest);
|
||||
g_overrideActive = true;
|
||||
}
|
||||
|
||||
KeyStateOverride::~KeyStateOverride() {
|
||||
g_overrideActive = m_wasActive;
|
||||
g_overrideMask = m_previousMask;
|
||||
}
|
||||
|
||||
} // namespace Input::Modifier
|
||||
|
||||
Reference in New Issue
Block a user