From c8e8bea1540f7954fe7430382bf88cb3c2f1b744 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 24 Nov 2024 14:52:31 +0100 Subject: [PATCH] Windows: remove extraneous code PostMessage hooks are no longer needed as we properly handle the messages when the imgui window procedure is running. The g_nWindowRect global is also no longer necessary because we now properly update the CGame's window size members as of commit 7ec1e679fd2676cde8e286812a0f5bec454f7d92. --- src/engine/sys_getmodes.cpp | 4 ---- src/windows/id3dx.cpp | 47 ------------------------------------- src/windows/id3dx.h | 5 ---- 3 files changed, 56 deletions(-) diff --git a/src/engine/sys_getmodes.cpp b/src/engine/sys_getmodes.cpp index f38de0e0..af493a2b 100644 --- a/src/engine/sys_getmodes.cpp +++ b/src/engine/sys_getmodes.cpp @@ -4,7 +4,6 @@ // //===========================================================================// #include "core/stdafx.h" -#include "windows/id3dx.h" #include "engine/sys_getmodes.h" #include "gameui/imgui_system.h" @@ -13,9 +12,6 @@ //----------------------------------------------------------------------------- bool HCVideoMode_Common__CreateGameWindow(int* pnRect) { - g_nWindowRect[0] = pnRect[0]; - g_nWindowRect[1] = pnRect[1]; - const bool ret = CVideoMode_Common__CreateGameWindow(pnRect); return ret; } diff --git a/src/windows/id3dx.cpp b/src/windows/id3dx.cpp index 77def155..3e065e6a 100644 --- a/src/windows/id3dx.cpp +++ b/src/windows/id3dx.cpp @@ -35,13 +35,6 @@ History: typedef BOOL(WINAPI* IPostMessageA)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); typedef BOOL(WINAPI* IPostMessageW)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); -/////////////////////////////////////////////////////////////////////////////////// -extern UINT g_nWindowRect[2] = { NULL, NULL }; - -/////////////////////////////////////////////////////////////////////////////////// -static IPostMessageA s_oPostMessageA = NULL; -static IPostMessageW s_oPostMessageW = NULL; - /////////////////////////////////////////////////////////////////////////////////// static IDXGIResizeBuffers s_fnResizeBuffers = NULL; static IDXGISwapChainPresent s_fnSwapChainPresent = NULL; @@ -58,30 +51,6 @@ LRESULT CALLBACK DXGIMsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) return DefWindowProc(hWnd, uMsg, wParam, lParam); } -//################################################################################# -// POST MESSAGE -//################################################################################# - -BOOL WINAPI HPostMessageA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) -{ - if (g_bBlockInput && Msg == WM_MOUSEMOVE) - { - return TRUE; - } - - return s_oPostMessageA(hWnd, Msg, wParam, lParam); -} - -BOOL WINAPI HPostMessageW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) -{ - if (g_bBlockInput && Msg == WM_MOUSEMOVE) - { - return TRUE; - } - - return s_oPostMessageW(hWnd, Msg, wParam, lParam); -} - //################################################################################# // IDXGI //################################################################################# @@ -134,9 +103,6 @@ HRESULT __stdcall Present(IDXGISwapChain* pSwapChain, UINT nSyncInterval, UINT n HRESULT __stdcall ResizeBuffers(IDXGISwapChain* pSwapChain, UINT nBufferCount, UINT nWidth, UINT nHeight, DXGI_FORMAT dxFormat, UINT nSwapChainFlags) { - g_nWindowRect[0] = nWidth; - g_nWindowRect[1] = nHeight; - /////////////////////////////////////////////////////////////////////////////// g_pGame->SetWindowSize(nWidth, nHeight); return s_fnResizeBuffers(pSwapChain, nBufferCount, nWidth, nHeight, dxFormat, nSwapChainFlags); @@ -321,20 +287,11 @@ bool PanelsVisible() void DirectX_Init() { - /////////////////////////////////////////////////////////////////////////////// - s_oPostMessageA = (IPostMessageA)DetourFindFunction("user32.dll", "PostMessageA"); - s_oPostMessageW = (IPostMessageW)DetourFindFunction("user32.dll", "PostMessageW"); - // Begin the detour transaction DetourTransactionBegin(); DetourUpdateThread(GetCurrentThread()); - // Hook PostMessage - DetourAttach(&(LPVOID&)s_oPostMessageA, (PBYTE)HPostMessageA); - DetourAttach(&(LPVOID&)s_oPostMessageW, (PBYTE)HPostMessageW); - // Hook SwapChain - DWORD_PTR* pSwapChainVtable = *reinterpret_cast(g_ppSwapChain[0]); int pIDX = static_cast(DXGISwapChainVTbl::Present); @@ -383,10 +340,6 @@ void DirectX_Shutdown() DetourTransactionBegin(); DetourUpdateThread(GetCurrentThread()); - // Unhook PostMessage - DetourDetach(&(LPVOID&)s_oPostMessageA, (PBYTE)HPostMessageA); - DetourDetach(&(LPVOID&)s_oPostMessageW, (PBYTE)HPostMessageW); - // Unhook SwapChain DetourDetach(&(LPVOID&)s_fnSwapChainPresent, (PBYTE)Present); DetourDetach(&(LPVOID&)s_fnResizeBuffers, (PBYTE)ResizeBuffers); diff --git a/src/windows/id3dx.h b/src/windows/id3dx.h index 6031b84b..3a9f9b57 100644 --- a/src/windows/id3dx.h +++ b/src/windows/id3dx.h @@ -12,17 +12,12 @@ extern HRESULT __stdcall Present(IDXGISwapChain* pSwapChain, UINT nSyncInterval, extern bool LoadTextureBuffer(unsigned char* buffer, int len, ID3D11ShaderResourceView** out_srv, int* out_width, int* out_height); extern void ResetInput(); -extern bool PanelsVisible(); ///////////////////////////////////////////////////////////////////////////// // Typedefs typedef HRESULT(__stdcall* IDXGISwapChainPresent)(IDXGISwapChain* pSwapChain, UINT nSyncInterval, UINT nFlags); typedef HRESULT(__stdcall* IDXGIResizeBuffers) (IDXGISwapChain* pSwapChain, UINT nBufferCount, UINT nWidth, UINT nHeight, DXGI_FORMAT dxFormat, UINT nSwapChainFlags); -///////////////////////////////////////////////////////////////////////////// -// Globals -extern UINT g_nWindowRect[2]; // TODO[ AMOS ]: Remove this in favor of CGame's window rect members??? - ///////////////////////////////////////////////////////////////////////////// // Enums enum class D3D11DeviceVTbl : short