diff --git a/Dllmain/BuildNo.rc b/Dllmain/BuildNo.rc index 21ce6d8c..13c72bd0 100644 --- a/Dllmain/BuildNo.rc +++ b/Dllmain/BuildNo.rc @@ -1 +1 @@ -#define BUILD_NUMBER 6850 +#define BUILD_NUMBER 6851 diff --git a/Utils/Utils.cpp b/Utils/Utils.cpp index 00d3397a..2a75b1ed 100644 --- a/Utils/Utils.cpp +++ b/Utils/Utils.cpp @@ -90,6 +90,7 @@ namespace Utils FARPROC pGetModuleFileNameW = nullptr; FARPROC p_CreateProcessA = nullptr; FARPROC p_CreateProcessW = nullptr; + WNDPROC OriginalWndProc = nullptr; std::vector custom_dll; // Used for custom dll's and asi plugins // Function declarations @@ -97,6 +98,7 @@ namespace Utils void InitializeASI(HMODULE hModule); void FindFiles(WIN32_FIND_DATA*); void *memmem(const void *l, size_t l_len, const void *s, size_t s_len); + LRESULT CALLBACK WndProcFilter(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); } // Execute a specified string @@ -926,3 +928,78 @@ DWORD Utils::GetVideoRam(UINT AdapterNo) return retSize; } +bool Utils::SetWndProcFilter(HWND hWnd) +{ + // Check window handle + if (!IsWindow(hWnd)) + { + Logging::Log() << __FUNCTION__ << " Error: hWnd invalid!"; + return false; + } + + // Check if WndProc is already overloaded + if (OriginalWndProc) + { + Logging::Log() << __FUNCTION__ << " Error: WndProc already overloaded!"; + return false; + } + + LOG_LIMIT(3, __FUNCTION__ << " Setting new WndProc " << hWnd); + + // Store existing WndProc + OriginalWndProc = (WNDPROC)GetWindowLong(hWnd, GWL_WNDPROC); + + // Set new WndProc + if (!OriginalWndProc || !SetWindowLong(hWnd, GWL_WNDPROC, (LONG)WndProcFilter)) + { + Logging::Log() << __FUNCTION__ << " Failed to overload WndProc!"; + OriginalWndProc = nullptr; + return false; + } + + return true; +} + +bool Utils::RestoreWndProcFilter(HWND hWnd) +{ + // Check window handle + if (!IsWindow(hWnd)) + { + Logging::Log() << __FUNCTION__ << " Error: hWnd invalid!"; + return false; + } + + // Check if WndProc is overloaded + if (!OriginalWndProc) + { + Logging::Log() << __FUNCTION__ << " Error: WndProc is not yet overloaded!"; + return false; + } + + // Get current WndProc + WNDPROC CurrentWndProc = (WNDPROC)GetWindowLong(hWnd, GWL_WNDPROC); + + // Check if WndProc is overloaded + if (CurrentWndProc != WndProcFilter) + { + Logging::Log() << __FUNCTION__ << " Error: WndProc does not match!"; + return false; + } + + // Resetting WndProc + if (!SetWindowLong(hWnd, GWL_WNDPROC, (LONG)OriginalWndProc)) + { + Logging::Log() << __FUNCTION__ << " Failed to reset WndProc"; + return false; + } + + OriginalWndProc = nullptr; + return true; +} + +LRESULT CALLBACK Utils::WndProcFilter(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + Logging::LogDebug() << __FUNCTION__ << " " << Logging::hex(uMsg); + + return DefWindowProc(hWnd, uMsg, wParam, lParam); +} diff --git a/Utils/Utils.h b/Utils/Utils.h index 3975feaf..706a3786 100644 --- a/Utils/Utils.h +++ b/Utils/Utils.h @@ -40,6 +40,8 @@ namespace Utils DWORD GetBitCount(HWND hWnd); DWORD GetWindowHeight(HWND hWnd); void DisableGameUX(); + bool SetWndProcFilter(HWND hWnd); + bool RestoreWndProcFilter(HWND hWnd); void GetScreenSize(HWND hwnd, LONG &screenWidth, LONG &screenHeight); void GetScreenSize(HWND hwnd, DWORD &screenWidth, DWORD &screenHeight); void GetDesktopRect(HWND hWnd, RECT& screenRect); diff --git a/d3d9/IDirect3D9Ex.cpp b/d3d9/IDirect3D9Ex.cpp index 5ffc4bce..fe4506ea 100644 --- a/d3d9/IDirect3D9Ex.cpp +++ b/d3d9/IDirect3D9Ex.cpp @@ -503,6 +503,12 @@ void UpdatePresentParameter(D3DPRESENT_PARAMETERS* pPresentationParameters, HWND { bool AnyChange = (LastBufferWidth != DeviceDetails.BufferWidth || LastBufferHeight != DeviceDetails.BufferHeight || LastDeviceWindow != DeviceDetails.DeviceWindow); + // Overload WndProc + if (Config.EnableWindowMode) + { + Utils::SetWndProcFilter(DeviceDetails.DeviceWindow); + } + // Adjust window RECT Rect; GetClientRect(DeviceDetails.DeviceWindow, &Rect); @@ -512,7 +518,7 @@ void UpdatePresentParameter(D3DPRESENT_PARAMETERS* pPresentationParameters, HWND } // Set fullscreen resolution - if (Config.FullscreenWindowMode && AnyChange) + if (AnyChange && Config.FullscreenWindowMode) { // Get monitor info MONITORINFOEX infoex = {}; @@ -528,11 +534,17 @@ void UpdatePresentParameter(D3DPRESENT_PARAMETERS* pPresentationParameters, HWND newSettings.dmPelsHeight = DeviceDetails.BufferHeight; newSettings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT; ChangeDisplaySettingsEx(bRet ? infoex.szDevice : nullptr, &newSettings, nullptr, CDS_FULLSCREEN, nullptr); - - // Peek messages to help prevent a "Not Responding" window - Utils::CheckMessageQueue(DeviceDetails.DeviceWindow); } } + + if (Config.EnableWindowMode) + { + // Resetting WndProc + Utils::RestoreWndProcFilter(DeviceDetails.DeviceWindow); + + // Peek messages to help prevent a "Not Responding" window + Utils::CheckMessageQueue(DeviceDetails.DeviceWindow); + } } } @@ -646,7 +658,4 @@ void AdjustWindow(HWND MainhWnd, LONG displayWidth, LONG displayHeight) SetWindowPos(MainhWnd, HWND_TOP, xLoc, yLoc, Rect.right, Rect.bottom, SWP_SHOWWINDOW | SWP_NOZORDER); } } - - // Peek messages to help prevent a "Not Responding" window - Utils::CheckMessageQueue(MainhWnd); } diff --git a/d3d9/IDirect3DDevice9Ex.cpp b/d3d9/IDirect3DDevice9Ex.cpp index d8a37fa6..cc233232 100644 --- a/d3d9/IDirect3DDevice9Ex.cpp +++ b/d3d9/IDirect3DDevice9Ex.cpp @@ -1158,7 +1158,7 @@ HRESULT m_IDirect3DDevice9Ex::Clear(DWORD Count, CONST D3DRECT *pRects, DWORD Fl { Logging::LogDebug() << __FUNCTION__ << " (" << this << ")"; - if (IsWindow(DeviceDetails.DeviceWindow) && (Config.FullscreenWindowMode || Config.EnableWindowMode)) + if (IsWindow(DeviceDetails.DeviceWindow) && Config.FullscreenWindowMode) { // Peek messages to help prevent a "Not Responding" window Utils::CheckMessageQueue(DeviceDetails.DeviceWindow); diff --git a/ddraw/IDirectDrawX.cpp b/ddraw/IDirectDrawX.cpp index c10dea2b..f31dea48 100644 --- a/ddraw/IDirectDrawX.cpp +++ b/ddraw/IDirectDrawX.cpp @@ -1652,7 +1652,7 @@ HRESULT m_IDirectDrawX::SetCooperativeLevel(HWND hWnd, DWORD dwFlags, DWORD Dire Exclusive.RefreshRate = DisplayMode.RefreshRate; } // Set device flags - Device.IsWindowed = (!ExclusiveMode || Config.EnableWindowMode || Config.FullscreenWindowMode); + Device.IsWindowed = (!ExclusiveMode || Config.EnableWindowMode); Device.AllowModeX = ((dwFlags & DDSCL_ALLOWMODEX) != 0); Device.MultiThreaded = ((dwFlags & DDSCL_MULTITHREADED) != 0); // The flag (DDSCL_FPUPRESERVE) is assumed by default in DirectX 6 and earlier. @@ -1743,9 +1743,6 @@ HRESULT m_IDirectDrawX::SetCooperativeLevel(HWND hWnd, DWORD dwFlags, DWORD Dire // Removing WS_CAPTION SetWindowLong(hWnd, GWL_STYLE, lStyle & ~WS_CAPTION); SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER); - - // Peek messages to help prevent a "Not Responding" window - Utils::CheckMessageQueue(hWnd); } } @@ -2359,7 +2356,7 @@ void m_IDirectDrawX::InitDdraw(DWORD DirectXVersion) // Mouse hook static bool EnableMouseHook = Config.DdrawEnableMouseHook && ((Config.DdrawUseNativeResolution || Config.DdrawOverrideWidth || Config.DdrawOverrideHeight) && - (!Config.EnableWindowMode || (Config.EnableWindowMode && Config.FullscreenWindowMode))); + (!Config.EnableWindowMode || Config.FullscreenWindowMode)); // Set mouse hook if (!MouseHook.m_hook && EnableMouseHook) @@ -3023,9 +3020,6 @@ HRESULT m_IDirectDrawX::CreateD3D9Device() SendMessage(hWnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)&winpos); SendMessage(hWnd, WM_MOVE, 0, MAKELPARAM(NewRect.left, NewRect.top)); SendMessage(hWnd, WM_SIZE, SIZE_RESTORED, MAKELPARAM(NewRect.right - NewRect.left, NewRect.bottom - NewRect.top)); - - // Peek messages to help prevent a "Not Responding" window - Utils::CheckMessageQueue(hWnd); } // Store display frequency