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;