fixed low level mouse hook lag

This commit is contained in:
EricPlayZ
2024-12-30 20:39:03 +02:00
parent 427b60f9ba
commit cd0ae09639
4 changed files with 24 additions and 15 deletions

View File

@ -226,7 +226,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalLibraryDirectories>deps\MinHook\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>DbgHelp.lib;Version.lib;libMinHook-x64-v141-md.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>DbgHelp.lib;Version.lib;libMinHook-x64-v141-mdd.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
<ImportLibrary />
<AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
<AssemblyDebug>true</AssemblyDebug>

View File

@ -183,7 +183,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalLibraryDirectories>..\EGameSDK\deps\MinHook\lib;deps\freetype\lib;..\$(PlatformShortName)\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>DbgHelp.lib;Version.lib;EGameSDK.lib;libMinHook-x64-v141-md.lib;freetype-md.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>DbgHelp.lib;Version.lib;EGameSDK.lib;libMinHook-x64-v141-mdd.lib;freetype-md.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
<ImportLibrary />
<AdditionalOptions>/NOIMPLIB /NOEXP %(AdditionalOptions)</AdditionalOptions>
<AssemblyDebug>true</AssemblyDebug>

View File

@ -48,7 +48,7 @@ namespace EGT::ImGui_impl {
EGSDK::Engine::CInput* pCInput = EGSDK::Engine::CInput::Get();
if (!pCInput)
return CallWindowProc(oWndProc, hwnd, uMsg, wParam, lParam);
return CallWindowProcA(oWndProc, hwnd, uMsg, wParam, lParam);
ImGui::GetIO().MouseDrawCursor = !Menu::hasSeenChangelog.GetValue() || Menu::firstTimeRunning.GetValue() || Menu::menuToggle.GetValue();
ImGui_ImplWin32_WndProcHandler(hwnd, uMsg, wParam, lParam);
@ -68,7 +68,7 @@ namespace EGT::ImGui_impl {
pCInput->UnlockGameInput();
}
return CallWindowProc(oWndProc, hwnd, uMsg, wParam, lParam);
return CallWindowProcA(oWndProc, hwnd, uMsg, wParam, lParam);
}
static LRESULT CALLBACK hkMouseProc(int nCode, WPARAM wParam, LPARAM lParam) {
@ -108,12 +108,12 @@ namespace EGT::ImGui_impl {
return CallNextHookEx(oMouseProc, nCode, wParam, lParam);
}
void MouseHkMsgLoop() {
static void MouseHkMsgLoop() {
MSG msg{};
while (true) {
if (oMouseProc && GetMessage(&msg, NULL, 0, 0)) {
while (oMouseProc) {
if (oMouseProc && GetMessageA(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
DispatchMessageA(&msg);
}
}
}
@ -122,9 +122,18 @@ namespace EGT::ImGui_impl {
if (oMouseProc)
return;
oMouseProc = SetWindowsHookEx(WH_MOUSE_LL, hkMouseProc, GetModuleHandle(nullptr), 0);
if (!oMouseProc)
SPDLOG_ERROR("Failed to enable low level mouse hook; mouse input-related functions (such as FreeCam speed changing through the scrollwheel) may not work");
std::thread([]() {
if (oMouseProc)
return;
oMouseProc = SetWindowsHookExA(WH_MOUSE_LL, hkMouseProc, GetModuleHandleA(nullptr), 0);
if (!oMouseProc) {
SPDLOG_ERROR("Failed to enable low level mouse hook; mouse input-related functions (such as FreeCam speed changing through the scrollwheel) may not work");
return;
}
MouseHkMsgLoop();
}).detach();
}
void DisableMouseHook() {
if (!oMouseProc)
@ -136,10 +145,10 @@ namespace EGT::ImGui_impl {
void Init(HWND hwnd) {
gHwnd = hwnd;
oWndProc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)hkWindowProc);
Menu::Debug::disableLowLevelMouseHook ? DisableMouseHook() : EnableMouseHook();
oWndProc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)hkWindowProc);
std::thread([]() { MouseHkMsgLoop(); }).detach();
if (!Menu::Debug::disableLowLevelMouseHook)
EnableMouseHook();
}
}
}

View File

@ -423,7 +423,7 @@ namespace EGT::Menu {
ImGui::EndDisabled();
}
}
void HandleDialogs() {
static void HandleDialogs() {
if (ImGuiFileDialog::Instance()->Display("ChooseSCRPath", ImGuiWindowFlags_NoCollapse, ImVec2(600.0f, 400.0f))) {
if (ImGuiFileDialog::Instance()->IsOk()) {
const std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath();