diff --git a/src/Hooks.cpp b/src/Hooks.cpp index a18bd8471..2e645828d 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -310,7 +310,7 @@ namespace Hooks { static LRESULT thunk(HWND a_hwnd, UINT a_msg, WPARAM a_wParam, LPARAM a_lParam) { - if (a_msg == WM_KILLFOCUS || a_msg == WM_SETFOCUS) { + if (a_msg == WM_KILLFOCUS) { Menu::GetSingleton()->OnFocusLost(); auto& io = ImGui::GetIO(); io.ClearInputKeys(); @@ -318,7 +318,19 @@ namespace Hooks } return func(a_hwnd, a_msg, a_wParam, a_lParam); } - static inline WNDPROC func; + static inline REL::Relocation func; + }; + + struct RegisterClassA_Hook + { + static ATOM thunk(WNDCLASSA* a_wndClass) + { + WndProcHandler_Hook::func = reinterpret_cast(a_wndClass->lpfnWndProc); + a_wndClass->lpfnWndProc = &WndProcHandler_Hook::thunk; + + return func(a_wndClass); + } + static inline REL::Relocation func; }; struct CreateRenderTarget_Main @@ -475,11 +487,7 @@ namespace Hooks stl::write_thunk_call(REL::RelocationID(75595, 77226).address() + REL::Relocate(0x50, 0x2BC)); logger::info("Hooking WndProcHandler"); - WndProcHandler_Hook::func = reinterpret_cast( - SetWindowLongPtrA( - RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().renderWindows[0].hWnd, - GWLP_WNDPROC, - reinterpret_cast(WndProcHandler_Hook::thunk))); + stl::write_thunk_call_6(REL::VariantID(75591, 77226, 0xDC4B90).address() + REL::VariantOffset(0x8E, 0x15C, 0x99).offset()); //logger::info("Hooking D3D11CreateDeviceAndSwapChain"); //*(FARPROC*)&ptrD3D11CreateDeviceAndSwapChain = GetProcAddress(GetModuleHandleA("d3d11.dll"), "D3D11CreateDeviceAndSwapChain");