From f62d6f652970fbbe50847a4a536d32d1b3a28555 Mon Sep 17 00:00:00 2001 From: chihya72 Date: Thu, 6 Aug 2026 02:00:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=20windowsPlatform.cpp=20?= =?UTF-8?q?=E7=9A=84=E9=9D=9E=E5=BF=85=E8=A6=81=E6=94=B9=E5=8A=A8=EF=BC=8C?= =?UTF-8?q?=E8=81=9A=E7=84=A6=E7=9B=B8=E6=9C=BA=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/windowsPlatform.cpp | 39 ++------------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/src/windowsPlatform.cpp b/src/windowsPlatform.cpp index 03df0e1..018b7a3 100644 --- a/src/windowsPlatform.cpp +++ b/src/windowsPlatform.cpp @@ -437,45 +437,10 @@ namespace GakumasLocal::WinHooks { return CallWindowProc(g_pfnOldWndProc, hWnd, uMsg, wParam, lParam); } - HWND FindUnityWindow() { - const auto currentProcessId = GetCurrentProcessId(); - HWND candidate = nullptr; - - // 优先按进程 ID 匹配本进程的 Unity 窗口,避免 3.0.0 修改窗口标题后找不到 - while ((candidate = FindWindowExW(nullptr, candidate, L"UnityWndClass", nullptr)) != nullptr) { - DWORD windowProcessId = 0; - GetWindowThreadProcessId(candidate, &windowProcessId); - if (windowProcessId == currentProcessId) { - return candidate; - } - } - - return FindWindowW(L"UnityWndClass", L"gakumas"); - } - void InstallWndProcHook() { - HWND hWnd = nullptr; - - // 等待游戏窗口出现(最多约 5 秒),避免窗口创建前安装失败 - for (int i = 0; i < 50 && !hWnd; ++i) { - hWnd = FindUnityWindow(); - if (!hWnd) { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } - } - - if (!hWnd) { - GakumasLocal::Log::Error("InstallWndProcHook: Unity window not found."); - return; - } - + auto hWnd = FindWindowW(L"UnityWndClass", L"gakumas"); g_pfnOldWndProc = (WNDPROC)GetWindowLongPtr(hWnd, GWLP_WNDPROC); - if (!g_pfnOldWndProc) { - GakumasLocal::Log::Error("InstallWndProcHook: GetWindowLongPtr failed."); - return; - } - SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)WndProcCallback); - + SetWindowLongPtr(FindWindowW(L"UnityWndClass", L"gakumas"), GWLP_WNDPROC, (LONG_PTR)WndProcCallback); // 添加可调整大小的边框和最大化按钮 LONG style = GetWindowLong(hWnd, GWL_STYLE); style |= WS_THICKFRAME | WS_MAXIMIZEBOX;