Skip to content

Commit

Permalink
Additional checking
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Aug 9, 2020
1 parent c25a930 commit 2eb3f8f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Dllmain/BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 6386
#define BUILD_NUMBER 6387
27 changes: 11 additions & 16 deletions ddraw/AddressLookupTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>::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;
Expand All @@ -330,15 +328,12 @@ class AddressLookupTableDdraw
return false;
}

constexpr UINT Index = AddressCacheIndex<T>::CacheIndex;
for (UINT CacheIndex = 0; CacheIndex < MaxIndex; CacheIndex++)
{
auto it = g_map[CacheIndex].find(Proxy);
constexpr UINT CacheIndex = AddressCacheIndex<T>::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;
Expand Down
14 changes: 11 additions & 3 deletions ddraw/IDirectDrawSurfaceX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions ddraw/IDirectDrawX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<m_IDirectDrawX>(lpDDraw)))
{
lpDDraw->SetCooperativeLevel(hWnd, DDSCL_NORMAL);
}
Expand Down

0 comments on commit 2eb3f8f

Please sign in to comment.