From 2eb3f8fb041552d65e8d5d613df12570dec1ecaf Mon Sep 17 00:00:00 2001 From: Elisha Riedlinger Date: Sat, 8 Aug 2020 23:29:01 -0700 Subject: [PATCH] Additional checking --- Dllmain/BuildNo.rc | 2 +- ddraw/AddressLookupTable.h | 27 +++++++++++---------------- ddraw/IDirectDrawSurfaceX.cpp | 14 +++++++++++--- ddraw/IDirectDrawX.cpp | 5 +++-- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/Dllmain/BuildNo.rc b/Dllmain/BuildNo.rc index 4014b729..7ab09010 100644 --- a/Dllmain/BuildNo.rc +++ b/Dllmain/BuildNo.rc @@ -1 +1 @@ -#define BUILD_NUMBER 6386 +#define BUILD_NUMBER 6387 diff --git a/ddraw/AddressLookupTable.h b/ddraw/AddressLookupTable.h index f19c4b44..762cd2ac 100644 --- a/ddraw/AddressLookupTable.h +++ b/ddraw/AddressLookupTable.h @@ -308,15 +308,13 @@ class AddressLookupTableDdraw return false; } - for (UINT CacheIndex = 0 ; CacheIndex < MaxIndex; CacheIndex++) - { - auto it = std::find_if(g_map[CacheIndex].begin(), g_map[CacheIndex].end(), - [=](auto Map) -> bool { return Map.second == Wrapper; }); + constexpr UINT CacheIndex = AddressCacheIndex::CacheIndex; + auto it = std::find_if(g_map[CacheIndex].begin(), g_map[CacheIndex].end(), + [=](auto Map) -> bool { return Map.second == Wrapper; }); - if (it != std::end(g_map[CacheIndex])) - { - return true; - } + if (it != std::end(g_map[CacheIndex])) + { + return true; } return false; @@ -330,15 +328,12 @@ class AddressLookupTableDdraw return false; } - constexpr UINT Index = AddressCacheIndex::CacheIndex; - for (UINT CacheIndex = 0; CacheIndex < MaxIndex; CacheIndex++) - { - auto it = g_map[CacheIndex].find(Proxy); + constexpr UINT CacheIndex = AddressCacheIndex::CacheIndex; + auto it = g_map[CacheIndex].find(Proxy); - if (it != std::end(g_map[CacheIndex])) - { - return true; - } + if (it != std::end(g_map[CacheIndex])) + { + return true; } return false; diff --git a/ddraw/IDirectDrawSurfaceX.cpp b/ddraw/IDirectDrawSurfaceX.cpp index 7466c19e..56467db1 100644 --- a/ddraw/IDirectDrawSurfaceX.cpp +++ b/ddraw/IDirectDrawSurfaceX.cpp @@ -352,10 +352,14 @@ HRESULT m_IDirectDrawSurfaceX::Blt(LPRECT lpDestRect, LPDIRECTDRAWSURFACE7 lpDDS } else { - if (!ProxyAddressLookupTable.IsValidWrapperAddress((m_IDirectDrawSurface*)lpDDSrcSurfaceX)) + if (!ProxyAddressLookupTable.IsValidWrapperAddress((m_IDirectDrawSurface*)lpDDSrcSurfaceX) && + !ProxyAddressLookupTable.IsValidWrapperAddress((m_IDirectDrawSurface2*)lpDDSrcSurfaceX) && + !ProxyAddressLookupTable.IsValidWrapperAddress((m_IDirectDrawSurface3*)lpDDSrcSurfaceX) && + !ProxyAddressLookupTable.IsValidWrapperAddress((m_IDirectDrawSurface4*)lpDDSrcSurfaceX) && + !ProxyAddressLookupTable.IsValidWrapperAddress((m_IDirectDrawSurface7*)lpDDSrcSurfaceX)) { LOG_LIMIT(100, __FUNCTION__ << " Error: could not find source surface!"); - return DD_OK; + return DD_OK; // Just return OK } lpDDSrcSurfaceX->QueryInterface(IID_GetInterfaceX, (LPVOID*)&lpDDSrcSurfaceX); @@ -450,7 +454,11 @@ HRESULT m_IDirectDrawSurfaceX::Blt(LPRECT lpDestRect, LPDIRECTDRAWSURFACE7 lpDDS if (lpDDSrcSurface) { // Check if source Surface exists - if (!ProxyAddressLookupTable.IsValidWrapperAddress((m_IDirectDrawSurface*)lpDDSrcSurface)) + if (!ProxyAddressLookupTable.IsValidWrapperAddress((m_IDirectDrawSurface*)lpDDSrcSurface) && + !ProxyAddressLookupTable.IsValidWrapperAddress((m_IDirectDrawSurface2*)lpDDSrcSurface) && + !ProxyAddressLookupTable.IsValidWrapperAddress((m_IDirectDrawSurface3*)lpDDSrcSurface) && + !ProxyAddressLookupTable.IsValidWrapperAddress((m_IDirectDrawSurface4*)lpDDSrcSurface) && + !ProxyAddressLookupTable.IsValidWrapperAddress((m_IDirectDrawSurface7*)lpDDSrcSurface)) { LOG_LIMIT(100, __FUNCTION__ << " Error: could not find source surface!"); return DD_OK; // Just return OK diff --git a/ddraw/IDirectDrawX.cpp b/ddraw/IDirectDrawX.cpp index bfbb6127..36b3aecc 100644 --- a/ddraw/IDirectDrawX.cpp +++ b/ddraw/IDirectDrawX.cpp @@ -407,7 +407,7 @@ HRESULT m_IDirectDrawX::CreateSurface2(LPDDSURFACEDESC2 lpDDSurfaceDesc2, LPDIRE // Setup d3d9 device if (!d3d9Device) { - if ((!displayWidth || !displayHeight) && lpDDSurfaceDesc2->dwWidth && lpDDSurfaceDesc2->dwHeight) + if ((!displayWidth || !displayHeight) && (lpDDSurfaceDesc2->dwFlags & (DDSD_WIDTH | DDSD_HEIGHT)) && lpDDSurfaceDesc2->dwWidth && lpDDSurfaceDesc2->dwHeight) { displayWidth = lpDDSurfaceDesc2->dwWidth; displayHeight = lpDDSurfaceDesc2->dwHeight; @@ -1137,7 +1137,8 @@ LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam) if (it != std::end(g_hookmap)) { m_IDirectDrawX *lpDDraw = it->second; - if (lpDDraw && ProxyAddressLookupTable.IsValidWrapperAddress(lpDDraw)) + if (lpDDraw && (ProxyAddressLookupTable.IsValidWrapperAddress(lpDDraw) || + ProxyAddressLookupTable.IsValidProxyAddress(lpDDraw))) { lpDDraw->SetCooperativeLevel(hWnd, DDSCL_NORMAL); }