Skip to content

Commit

Permalink
Force emulation for certain system memory surfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Dec 7, 2024
1 parent a97b945 commit 5b49bfb
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 4 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 7365
#define BUILD_NUMBER 7366
7 changes: 4 additions & 3 deletions ddraw/IDirectDrawSurfaceX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2637,12 +2637,13 @@ HRESULT m_IDirectDrawSurfaceX::Lock2(LPRECT lpDestRect, LPDDSURFACEDESC2 lpDDSur
}

// If primary surface and palette surface and created via Lock() then mark as created by lock to emulate surface (eg. Diablo)
if (IsPrimarySurface() && ShouldEmulate == SC_NOT_CREATED && surfaceDesc2.dwFlags == DDSD_CAPS)
if (ShouldEmulate == SC_NOT_CREATED && !IsSurfaceTexture() && surfaceDesc2.dwBackBufferCount == 0 && (surfaceDesc2.ddsCaps.dwCaps & DDSCAPS_FLIP) == 0 &&
((surfaceDesc2.ddsCaps.dwCaps == DDSCAPS_SYSTEMMEMORY && IsDisplayResolution(surfaceDesc2.dwWidth, surfaceDesc2.dwHeight))) ||
(surfaceDesc2.dwFlags == DDSD_CAPS && IsPrimarySurface()))
{
UpdateSurfaceDesc();

if (surfaceDesc2.ddpfPixelFormat.dwRGBBitCount == 8 && (surfaceDesc2.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY) &&
surfaceDesc2.dwBackBufferCount == 0 && (surfaceDesc2.ddsCaps.dwCaps & DDSCAPS_FLIP) == 0)
if (surfaceDesc2.ddpfPixelFormat.dwRGBBitCount == 8 || surfaceDesc2.ddsCaps.dwCaps == DDSCAPS_SYSTEMMEMORY)
{
ShouldEmulate = SC_FORCE_EMULATED;
}
Expand Down
23 changes: 23 additions & 0 deletions ddraw/IDirectDrawTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,29 @@

#include "ddraw.h"

// For storing resolution list
std::vector<std::pair<DWORD, DWORD>> CashedDisplayResolutions;

void AddDisplayResolution(DWORD Width, DWORD Height)
{
if (!IsDisplayResolution(Width, Height))
{
CashedDisplayResolutions.push_back({ Width, Height });
}
}

bool IsDisplayResolution(DWORD Width, DWORD Height)
{
for (const auto& entry : CashedDisplayResolutions)
{
if (entry.first == Width && entry.second == Height)
{
return true;
}
}
return false;
}

bool DoRectsMatch(const RECT& lhs, const RECT& rhs)
{
return lhs.left == rhs.left && lhs.top == rhs.top &&
Expand Down
2 changes: 2 additions & 0 deletions ddraw/IDirectDrawTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ static constexpr DWORD DDS_HEADER_FLAGS_PITCH = 0x00000008;

static constexpr DWORD MaxPaletteSize = 256;

void AddDisplayResolution(DWORD Width, DWORD Height);
bool IsDisplayResolution(DWORD Width, DWORD Height);
bool DoRectsMatch(const RECT& lhs, const RECT& rhs);
bool GetOverlappingRect(const RECT& rect1, const RECT& rect2, RECT& outOverlapRect);
void ConvertSurfaceDesc(DDSURFACEDESC &Desc, DDSURFACEDESC2 &Desc2);
Expand Down
3 changes: 3 additions & 0 deletions ddraw/IDirectDrawX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,9 @@ HRESULT m_IDirectDrawX::EnumDisplayModes2(DWORD dwFlags, LPDDSURFACEDESC2 lpDDSu
break;
}

// Add resolution to global list
AddDisplayResolution(d3ddispmode.Width, d3ddispmode.Height);

// Loop through each bit count
for (DWORD bpMode : {8, 16, 32})
{
Expand Down
13 changes: 13 additions & 0 deletions ddraw/Versions/IDirectDrawSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,19 @@ HRESULT m_IDirectDrawSurface::GetSurfaceDesc(LPDDSURFACEDESC a)
{
if (!ProxyInterface)
{
if (a)
{
if (a->dwSize == sizeof(DDSURFACEDESC))
{
ZeroMemory(a, sizeof(DDSURFACEDESC));
a->dwSize = sizeof(DDSURFACEDESC);
}
else if (a->dwSize == sizeof(DDSURFACEDESC2))
{
ZeroMemory(a, sizeof(DDSURFACEDESC2));
a->dwSize = sizeof(DDSURFACEDESC);
}
}
return DDERR_INVALIDOBJECT;
}
return ProxyInterface->GetSurfaceDesc(a, MipMapLevel, DirectXVersion);
Expand Down
13 changes: 13 additions & 0 deletions ddraw/Versions/IDirectDrawSurface2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,19 @@ HRESULT m_IDirectDrawSurface2::GetSurfaceDesc(LPDDSURFACEDESC a)
{
if (!ProxyInterface)
{
if (a)
{
if (a->dwSize == sizeof(DDSURFACEDESC))
{
ZeroMemory(a, sizeof(DDSURFACEDESC));
a->dwSize = sizeof(DDSURFACEDESC);
}
else if (a->dwSize == sizeof(DDSURFACEDESC2))
{
ZeroMemory(a, sizeof(DDSURFACEDESC2));
a->dwSize = sizeof(DDSURFACEDESC);
}
}
return DDERR_INVALIDOBJECT;
}
return ProxyInterface->GetSurfaceDesc(a, MipMapLevel, DirectXVersion);
Expand Down
13 changes: 13 additions & 0 deletions ddraw/Versions/IDirectDrawSurface3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,19 @@ HRESULT m_IDirectDrawSurface3::GetSurfaceDesc(LPDDSURFACEDESC a)
{
if (!ProxyInterface)
{
if (a)
{
if (a->dwSize == sizeof(DDSURFACEDESC))
{
ZeroMemory(a, sizeof(DDSURFACEDESC));
a->dwSize = sizeof(DDSURFACEDESC);
}
else if (a->dwSize == sizeof(DDSURFACEDESC2))
{
ZeroMemory(a, sizeof(DDSURFACEDESC2));
a->dwSize = sizeof(DDSURFACEDESC);
}
}
return DDERR_INVALIDOBJECT;
}
return ProxyInterface->GetSurfaceDesc(a, MipMapLevel, DirectXVersion);
Expand Down
13 changes: 13 additions & 0 deletions ddraw/Versions/IDirectDrawSurface4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,19 @@ HRESULT m_IDirectDrawSurface4::GetSurfaceDesc(LPDDSURFACEDESC2 a)
{
if (!ProxyInterface)
{
if (a)
{
if (a->dwSize == sizeof(DDSURFACEDESC))
{
ZeroMemory(a, sizeof(DDSURFACEDESC));
a->dwSize = sizeof(DDSURFACEDESC);
}
else if (a->dwSize == sizeof(DDSURFACEDESC2))
{
ZeroMemory(a, sizeof(DDSURFACEDESC2));
a->dwSize = sizeof(DDSURFACEDESC);
}
}
return DDERR_INVALIDOBJECT;
}
return ProxyInterface->GetSurfaceDesc2(a, MipMapLevel, DirectXVersion);
Expand Down
13 changes: 13 additions & 0 deletions ddraw/Versions/IDirectDrawSurface7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,19 @@ HRESULT m_IDirectDrawSurface7::GetSurfaceDesc(LPDDSURFACEDESC2 a)
{
if (!ProxyInterface)
{
if (a)
{
if (a->dwSize == sizeof(DDSURFACEDESC))
{
ZeroMemory(a, sizeof(DDSURFACEDESC));
a->dwSize = sizeof(DDSURFACEDESC);
}
else if (a->dwSize == sizeof(DDSURFACEDESC2))
{
ZeroMemory(a, sizeof(DDSURFACEDESC2));
a->dwSize = sizeof(DDSURFACEDESC);
}
}
return DDERR_INVALIDOBJECT;
}
return ProxyInterface->GetSurfaceDesc2(a, MipMapLevel, DirectXVersion);
Expand Down

0 comments on commit 5b49bfb

Please sign in to comment.