From cd8a8034a123d094e3106811fee089cd393dc320 Mon Sep 17 00:00:00 2001 From: WinterSnowfall Date: Sat, 21 Sep 2024 16:57:05 +0300 Subject: [PATCH] Implement Direct3DDevice8::GetInfo --- source/d3d8to9_device.cpp | 67 ++++++++++++++++++++++++++++++++++++--- source/d3d8types.hpp | 20 ++++++++++++ 2 files changed, 82 insertions(+), 5 deletions(-) diff --git a/source/d3d8to9_device.cpp b/source/d3d8to9_device.cpp index c0086c3..41ca174 100644 --- a/source/d3d8to9_device.cpp +++ b/source/d3d8to9_device.cpp @@ -971,15 +971,72 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::ValidateDevice(DWORD *pNumPasses) } HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetInfo(DWORD DevInfoID, void *pDevInfoStruct, DWORD DevInfoStructSize) { - UNREFERENCED_PARAMETER(DevInfoID); - UNREFERENCED_PARAMETER(pDevInfoStruct); - UNREFERENCED_PARAMETER(DevInfoStructSize); - #ifndef D3D8TO9NOLOG LOG << "Redirecting '" << "IDirect3DDevice8::GetInfo" << "(" << this << ", " << DevInfoID << ", " << pDevInfoStruct << ", " << DevInfoStructSize << ")' ..." << std::endl; #endif - return S_FALSE; + if (pDevInfoStruct == nullptr || DevInfoStructSize == 0) + return D3DERR_INVALIDCALL; + + HRESULT hr; + IDirect3DQuery9 *pQuery = nullptr; + + switch (DevInfoID) + { + case 0: + case D3DDEVINFOID_TEXTUREMANAGER: + case D3DDEVINFOID_D3DTEXTUREMANAGER: + case D3DDEVINFOID_TEXTURING: + return E_FAIL; // Unsupported query IDs + + case D3DDEVINFOID_VCACHE: + hr = ProxyInterface->CreateQuery(D3DQUERYTYPE_VCACHE, &pQuery); + + if (FAILED(hr)) + { + if (DevInfoStructSize != sizeof(D3DDEVINFO_VCACHE)) + return D3DERR_INVALIDCALL; + + // The contents of pDevInfoStruct are zeroed before return + memset(pDevInfoStruct, 0, sizeof(D3DDEVINFO_VCACHE)); + return S_FALSE; + } + + break; + + case D3DDEVINFOID_RESOURCEMANAGER: + hr = ProxyInterface->CreateQuery(D3DQUERYTYPE_RESOURCEMANAGER, &pQuery); + break; + + case D3DDEVINFOID_VERTEXSTATS: + hr = ProxyInterface->CreateQuery(D3DQUERYTYPE_VERTEXSTATS, &pQuery); + break; + + default: // D3DDEVINFOID_UNKNOWN + return E_FAIL; + } + + if ((FAILED(hr))) + { + if (hr == D3DERR_NOTAVAILABLE) + { + return E_FAIL; + } + else + { + return S_FALSE; + } + } + + if (pQuery != nullptr) + { + pQuery->Issue(D3DISSUE_END); + hr = pQuery->GetData(pDevInfoStruct, DevInfoStructSize, D3DGETDATA_FLUSH); + + pQuery->Release(); + } + + return hr; } HRESULT STDMETHODCALLTYPE Direct3DDevice8::SetPaletteEntries(UINT PaletteNumber, const PALETTEENTRY *pEntries) { diff --git a/source/d3d8types.hpp b/source/d3d8types.hpp index 3598721..6d7b07d 100644 --- a/source/d3d8types.hpp +++ b/source/d3d8types.hpp @@ -69,6 +69,26 @@ struct IUnknown; #endif #define D3DPRASTERCAPS_ZBIAS 0x00004000L +// These aren't typically included in any of the MSVC headers +#ifndef D3DDEVINFOID_TEXTUREMANAGER +#define D3DDEVINFOID_TEXTUREMANAGER 1 +#endif +#ifndef D3DDEVINFOID_D3DTEXTUREMANAGER +#define D3DDEVINFOID_D3DTEXTUREMANAGER 2 +#endif +#ifndef D3DDEVINFOID_TEXTURING +#define D3DDEVINFOID_TEXTURING 3 +#endif +#ifndef D3DDEVINFOID_VCACHE +#define D3DDEVINFOID_VCACHE 4 +#endif +#ifndef D3DDEVINFOID_RESOURCEMANAGER +#define D3DDEVINFOID_RESOURCEMANAGER 5 +#endif +#ifndef D3DDEVINFOID_VERTEXSTATS +#define D3DDEVINFOID_VERTEXSTATS 6 +#endif + typedef D3DLIGHT9 D3DLIGHT8; typedef D3DMATERIAL9 D3DMATERIAL8; typedef D3DVIEWPORT9 D3DVIEWPORT8;