1
0
mirror of https://github.com/narzoul/DDrawCompat synced 2024-12-30 08:55:36 +01:00

Assume ddsCaps is valid even if DDSD_CAPS is not set

DirectDraw seems to assume the DDSD_CAPS flag is always set in CreateSurface.
This flag even has a comment in ddraw.h mentioning it's "default".

Some games set ddsCaps members without explicitly setting the DDSD_CAPS flag,
which causes DDrawCompat to incorrectly detect some capabilities. These checks
now always assume the ddsCaps member is valid even if DDSD_CAPS is not set.

Fixes a crash when launching Rogue Spear, mentioned in issue #2.
This commit is contained in:
narzoul 2016-06-12 16:31:59 +02:00
parent b9b4a2aafd
commit 78bc5c0ee3
2 changed files with 4 additions and 8 deletions

View File

@ -107,7 +107,6 @@ HRESULT STDMETHODCALLTYPE CompatDirectDraw<TDirectDraw>::CreateSurface(
HRESULT result = DD_OK;
const bool isPrimary = lpDDSurfaceDesc &&
(lpDDSurfaceDesc->dwFlags & DDSD_CAPS) &&
(lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE);
if (isPrimary)
@ -120,8 +119,7 @@ HRESULT STDMETHODCALLTYPE CompatDirectDraw<TDirectDraw>::CreateSurface(
if (lpDDSurfaceDesc &&
(lpDDSurfaceDesc->dwFlags & DDSD_WIDTH) &&
(lpDDSurfaceDesc->dwFlags & DDSD_HEIGHT) &&
!((lpDDSurfaceDesc->dwFlags & DDSD_CAPS) &&
(lpDDSurfaceDesc->ddsCaps.dwCaps & (DDSCAPS_ALPHA | DDSCAPS_ZBUFFER))))
!(lpDDSurfaceDesc->ddsCaps.dwCaps & (DDSCAPS_ALPHA | DDSCAPS_ZBUFFER)))
{
CompatPtr<IDirectDraw7> dd(Compat::queryInterface<IDirectDraw7>(This));
auto dm = CompatDisplayMode::getDisplayMode(*dd);
@ -132,9 +130,8 @@ HRESULT STDMETHODCALLTYPE CompatDirectDraw<TDirectDraw>::CreateSurface(
desc.dwFlags |= DDSD_PIXELFORMAT;
desc.ddpfPixelFormat = dm.ddpfPixelFormat;
}
if (!((desc.dwFlags & DDSD_CAPS) &&
(desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_OVERLAY | DDSCAPS_TEXTURE |
DDSCAPS_FRONTBUFFER | DDSCAPS_BACKBUFFER))))
if (!(desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_OVERLAY | DDSCAPS_TEXTURE |
DDSCAPS_FRONTBUFFER | DDSCAPS_BACKBUFFER)))
{
desc.dwFlags |= DDSD_CAPS;
desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;

View File

@ -21,8 +21,7 @@ namespace
void fixSurfacePtr(CompatRef<IDirectDrawSurface7> surface, const DDSURFACEDESC2& desc)
{
if ((desc.dwFlags & DDSD_CAPS) && (desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY) ||
0 == desc.dwWidth || 0 == desc.dwHeight)
if ((desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY) || 0 == desc.dwWidth || 0 == desc.dwHeight)
{
return;
}