From 6cbd057b18b08b8ad6d0f79db73d28ad287010e6 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Thu, 21 May 2026 13:18:35 -0400 Subject: [PATCH] Improve ImGui mouse blocking --- SharpPluginLoader.Core/Rendering/Renderer.cs | 21 +++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/SharpPluginLoader.Core/Rendering/Renderer.cs b/SharpPluginLoader.Core/Rendering/Renderer.cs index 4e8d2f6..39c66fc 100644 --- a/SharpPluginLoader.Core/Rendering/Renderer.cs +++ b/SharpPluginLoader.Core/Rendering/Renderer.cs @@ -271,22 +271,25 @@ Initializing Renderer with { // Zero mouse delta used for camera movement. MemoryUtil.GetRef(m + 0xFC) = 0L; // dX(int), dY(int). - MemoryUtil.GetRef(m + 0x188) = 0x0; // Mouse down menu. - MemoryUtil.GetRef(m + 0x108) = 0x0; // Mouse down combat. + MemoryUtil.GetRef(m + 0x108) = 0x0; // Combat. + MemoryUtil.GetRef(m + 0x188) = 0x0; // Menu. + MemoryUtil.GetRef(m + 0x194) = 0x0; // Dialogue. _lastUpdateHadFocus = true; } else if (anyHovered || _lastUpdateHadFocus) { // Block mouse1 clicks. Use _lastUpdateHadFocus to more consistently block // a click used to unfocus the ImGui window. - ref byte downMenu = ref MemoryUtil.GetRef(m + 0x188); - ref byte downCombat = ref MemoryUtil.GetRef(m + 0x108); - if ((downMenu & 0x1) == 0 && (downCombat & 0x1) == 0) // Wait for release. + ref byte m1Combat = ref MemoryUtil.GetRef(m + 0x108); + ref byte m1Menu = ref MemoryUtil.GetRef(m + 0x188); + ref byte m1Dialogue = ref MemoryUtil.GetRef(m + 0x194); + if ((m1Combat & 0x1) == 0 && (m1Menu & 0x1) == 0 && (m1Dialogue & 0x1) == 0) // Wait for release. { _lastUpdateHadFocus = false; } - downMenu &= 0xFE; - downCombat &= 0xFE; + m1Combat &= 0xFE; + m1Menu &= 0xFE; + m1Dialogue &= 0xFE; } }); } @@ -356,7 +359,7 @@ Initializing Renderer with _lastUpdateHadKeyboard = io.WantCaptureKeyboard || io.NavActive; if (_lastUpdateHadKeyboard) { - Unsafe.InitBlockUnaligned((byte*)state, 0, (uint)Marshal.SizeOf()); + NativeMemory.Clear((byte*)state, (nuint)Marshal.SizeOf()); } } }); @@ -588,9 +591,9 @@ private static nint GetCursorPositionHook(nint app, out Point pos) private delegate void MouseUpdateDelegate(nint sMhMouse); private static Hook _getCursorPositionHook = null!; private static Hook _mouseUpdateHook = null!; - private static bool _lastUpdateHadFocus = false; private delegate void KeyboardUpdateDelegate(nint sMhKeyboard, nint kbState); private static Hook _keyboardUpdateHook = null!; + private static bool _lastUpdateHadFocus = false; private static bool _lastUpdateHadKeyboard = false; private static Key? _waitForRelease = null; private static bool _showMenu = false;