diff options
Diffstat (limited to 'src/rinput.c')
| -rw-r--r-- | src/rinput.c | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/src/rinput.c b/src/rinput.c index 850efee..a7ed1a4 100644 --- a/src/rinput.c +++ b/src/rinput.c @@ -61,10 +61,10 @@ static union { // space saving #define vtable_insys U.vtable_insys DEF_CVAR_UNREG(m_rawinput, "Use Raw Input for mouse input (SST reimplementation)", - 0, CON_ARCHIVE | CON_HIDDEN) + 0, CON_ARCHIVE | CON_INIT_HIDDEN) DEF_CVAR_MINMAX(sst_mouse_factor, "Number of hardware mouse counts per step", - 1, 1, 100, /*CON_ARCHIVE |*/ CON_HIDDEN) + 1, 1, 100, /*CON_ARCHIVE |*/ CON_INIT_HIDDEN) static ssize __stdcall inproc(void *wnd, uint msg, usize wp, ssize lp) { switch (msg) { @@ -126,8 +126,8 @@ static uint VCALLCONV hook_GetRawMouseAccumulators(void *this, int *x, int *y) { INIT { bool has_rawinput = !!con_findvar("m_rawinput"); if (has_rawinput) { - if (!has_vtidx_GetRawMouseAccumulators) return false; - if (!inputsystem) return false; + if (!has_vtidx_GetRawMouseAccumulators) return FEAT_INCOMPAT; + if (!inputsystem) return FEAT_INCOMPAT; vtable_insys = mem_loadptr(inputsystem); // XXX: this is kind of duping nosleep, but that won't always init... if_cold (!os_mprot(vtable_insys + vtidx_GetRawMouseAccumulators, @@ -180,22 +180,17 @@ INIT { goto ok; } - orig_GetCursorPos = (GetCursorPos_func)hook_inline((void *)&GetCursorPos, - (void *)&hook_GetCursorPos); - if_cold (!orig_GetCursorPos) { - errmsg_errorsys("couldn't hook %s", "GetCursorPos"); - goto e0; - } - orig_SetCursorPos = (SetCursorPos_func)hook_inline((void *)&SetCursorPos, - (void *)&hook_SetCursorPos); - if_cold (!orig_SetCursorPos) { - errmsg_errorsys("couldn't hook %s", "SetCursorPos"); - goto e1; - } + int err; + struct hook_inline_featsetup_ret h1 = hook_inline_featsetup( + (void *)GetCursorPos, (void **)&orig_GetCursorPos, "GetCursorPos"); + if_cold (err = h1.err) goto e0; + struct hook_inline_featsetup_ret h2 = hook_inline_featsetup( + (void *)SetCursorPos, (void **)&orig_SetCursorPos, "SetCursorPos"); + if_cold (err = h2.err) goto e0; inwin = CreateWindowExW(0, L"RInput", L"RInput", 0, 0, 0, 0, 0, 0, 0, 0, 0); if_cold (!inwin) { errmsg_errorsys("couldn't create input window"); - goto e2; + goto e0; } RAWINPUTDEVICE rd = { .hwndTarget = inwin, @@ -204,18 +199,22 @@ INIT { }; if_cold (!RegisterRawInputDevices(&rd, 1, sizeof(rd))) { errmsg_errorsys("couldn't create raw mouse device"); - goto e3; + err = FEAT_FAIL; + goto e1; } - -ok: m_rawinput->base.flags &= ~CON_HIDDEN; - sst_mouse_factor->base.flags &= ~CON_HIDDEN; + hook_inline_commit(h1.prologue, (void *)&hook_GetCursorPos); + hook_inline_commit(h2.prologue, (void *)&hook_SetCursorPos); + +ok: // XXX: this is a little tricky and a little clunky. we have registered + // m_rawinput above but sst_mouse_factor will get auto-registered after init + // returns, so the flags are different. + con_unhide(&m_rawinput->base); + sst_mouse_factor->base.flags &= ~CON_INIT_HIDDEN; return FEAT_OK; -e3: DestroyWindow(inwin); -e2: unhook_inline((void *)orig_SetCursorPos); -e1: unhook_inline((void *)orig_GetCursorPos); +e1: DestroyWindow(inwin); e0: UnregisterClassW(L"RInput", 0); - return FEAT_FAIL; + return err; } END { |
