From b65caf18d765e8dea4418c45c1ebf384b213ccb9 Mon Sep 17 00:00:00 2001 From: WinterSnowfall Date: Thu, 10 Oct 2024 21:23:56 +0300 Subject: [PATCH] Validate depth formats used with "IDirect3DDevice8::CopyRects" (#180) --- source/d3d8to9_device.cpp | 3 +++ source/d3d8types.cpp | 10 ++++++++++ source/d3d8types.hpp | 1 + 3 files changed, 14 insertions(+) diff --git a/source/d3d8to9_device.cpp b/source/d3d8to9_device.cpp index de2cf36..e4f82be 100644 --- a/source/d3d8to9_device.cpp +++ b/source/d3d8to9_device.cpp @@ -445,6 +445,9 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CopyRects(IDirect3DSurface8 *pSourceS if (SourceDesc.Format != DestinationDesc.Format) return D3DERR_INVALIDCALL; + if (IsDepthStencil(SourceDesc.Format)) + return D3DERR_INVALIDCALL; + HRESULT hr = D3DERR_INVALIDCALL; if (cRects == 0) diff --git a/source/d3d8types.cpp b/source/d3d8types.cpp index 7b962c0..c28b0af 100644 --- a/source/d3d8types.cpp +++ b/source/d3d8types.cpp @@ -15,6 +15,16 @@ bool SupportsPalettes() return hasPalette; } +bool IsDepthStencil(D3DFORMAT &Format) { + return Format == D3DFMT_D16_LOCKABLE + || Format == D3DFMT_D16 + || Format == D3DFMT_D32 + || Format == D3DFMT_D15S1 + || Format == D3DFMT_D24X4S4 + || Format == D3DFMT_D24S8 + || Format == D3DFMT_D24X8; +} + static UINT CalcTextureSize(UINT Width, UINT Height, UINT Depth, D3DFORMAT Format) { switch (static_cast(Format)) diff --git a/source/d3d8types.hpp b/source/d3d8types.hpp index 6d7b07d..9a2b128 100644 --- a/source/d3d8types.hpp +++ b/source/d3d8types.hpp @@ -192,6 +192,7 @@ struct D3DADAPTER_IDENTIFIER8 }; bool SupportsPalettes(); +bool IsDepthStencil(D3DFORMAT &format); void ConvertCaps(D3DCAPS9 &input, D3DCAPS8 &output); void ConvertVolumeDesc(D3DVOLUME_DESC &input, D3DVOLUME_DESC8 &output);