From 291d43c31e43582432683bc2a32fea24b1286f26 Mon Sep 17 00:00:00 2001 From: blattersturm Date: Sat, 8 Jul 2023 01:59:58 +0200 Subject: [PATCH] fix(input/five): sniper zoom bug for scroll wheel Since the mouse scroll delta stuff, sniper zoom with a mouse wheel would either be zoomed all the way in, or all the way out, as apparently this 'other' value derived from dZ is a count of scroll intervals. Technically this should be accumulated from partial scrolls still but to fix the regression we just make it divide by 120 as integer again. Smooth scrolling from the delta axis has still been confirmed to work. --- .../src/PatchMouseScrollDelta.cpp | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/code/components/rage-input-five/src/PatchMouseScrollDelta.cpp b/code/components/rage-input-five/src/PatchMouseScrollDelta.cpp index f1d77b6969..aed3e55dcc 100644 --- a/code/components/rage-input-five/src/PatchMouseScrollDelta.cpp +++ b/code/components/rage-input-five/src/PatchMouseScrollDelta.cpp @@ -50,6 +50,44 @@ void DoPatchMouseScrollDelta() hook::jump(location, patch.GetCode()); } + // int 'stacking' for non-float parts (breaks sniper zoom otherwise) + { + static struct : jitasm::Frontend + { + uintptr_t dZAddr = 0; + uintptr_t returnAddr = 0; + + virtual void InternalMain() override + { + // eax = *dZAddr + mov(rax, dZAddr); + mov(eax, dword_ptr[rax]); + + // ecx = 120 + mov(ecx, 120); + + // rax = (int64_t)eax + cdq(); + + // rax /= ecx + idiv(ecx); + + // r8d = eax + mov(r8d, eax); + + // return + mov(rax, returnAddr); + jmp(rax); + } + } patch; + + auto location = hook::get_pattern("41 89 7E 20 44 8B 05", 4); + patch.returnAddr = (uintptr_t)(location + 7); + patch.dZAddr = hook::get_address(location, 3, 7); + hook::nop(location, 7); + hook::jump(location, patch.GetCode()); + } + // adding / 120.0 to CGalleryMenu // 1st