Skip to content

Commit

Permalink
Add ValidatePixelShader, ValidateVertexShader and DebugSetMute exports (
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterSnowfall authored Oct 14, 2024
1 parent 52a36f0 commit b5d8458
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
3 changes: 3 additions & 0 deletions res/d3d8.def
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
EXPORTS
ValidatePixelShader
ValidateVertexShader
DebugSetMute
Direct3DCreate8
114 changes: 114 additions & 0 deletions source/d3d8to9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,120 @@ PFN_D3DXLoadSurfaceFromSurface D3DXLoadSurfaceFromSurface = nullptr;
std::ofstream LOG;
#endif

extern "C" HRESULT WINAPI ValidatePixelShader(const DWORD* pPixelShader, const D3DCAPS8* pCaps, BOOL ReturnErrors, char** pErrorsString)
{
#ifndef D3D8TO9NOLOG
LOG << "Redirecting '" << "ValidatePixelShader " << "(" << pPixelShader << ", " << pCaps << ", " << ReturnErrors << ", " << pErrorsString << ")' ..." << std::endl;
#endif

HRESULT hr = E_FAIL;
char* errorMessage = "";

if (!pPixelShader)
{
errorMessage = "Invalid code pointer.\n";
}
else
{
switch (*pPixelShader)
{
case D3DPS_VERSION(1, 0):
case D3DPS_VERSION(1, 1):
case D3DPS_VERSION(1, 2):
case D3DPS_VERSION(1, 3):
case D3DPS_VERSION(1, 4):
if (pCaps && *pPixelShader > pCaps->PixelShaderVersion)
{
errorMessage = "Shader version not supported by caps.\n";
break;
}
hr = S_OK;
break;

default:
errorMessage = "Unsupported shader version.\n";
}
}

if (!ReturnErrors)
{
errorMessage = "";
}

if (pErrorsString)
{
const size_t size = strlen(errorMessage) + 1;

*pErrorsString = (char*) HeapAlloc(GetProcessHeap(), 0, size);
if (*pErrorsString)
{
memcpy(*pErrorsString, errorMessage, size);
}
}

return hr;
}

extern "C" HRESULT WINAPI ValidateVertexShader(const DWORD* pVertexShader, const DWORD* pVertexDecl, const D3DCAPS8* pCaps, BOOL ReturnErrors, char** pErrorsString)
{
UNREFERENCED_PARAMETER(pVertexDecl);

#ifndef D3D8TO9NOLOG
LOG << "Redirecting '" << "ValidateVertexShader " << "(" << pVertexShader << ", " << pVertexDecl << ", " << pCaps << ", " << ReturnErrors << ", " << pErrorsString << ")' ..." << std::endl;
#endif

HRESULT hr = E_FAIL;
char* errorMessage = "";

if (!pVertexShader)
{
errorMessage = "Invalid code pointer.\n";
}
else
{
switch (*pVertexShader)
{
case D3DVS_VERSION(1, 0):
case D3DVS_VERSION(1, 1):
if (pCaps && *pVertexShader > pCaps->VertexShaderVersion)
{
errorMessage = "Shader version not supported by caps.\n";
break;
}
hr = S_OK;
break;

default:
errorMessage = "Unsupported shader version.\n";
}
}

if (!ReturnErrors)
{
errorMessage = "";
}

if (pErrorsString)
{
const size_t size = strlen(errorMessage) + 1;

*pErrorsString = (char*) HeapAlloc(GetProcessHeap(), 0, size);
if (*pErrorsString)
{
memcpy(*pErrorsString, errorMessage, size);
}
}

return hr;
}

extern "C" void WINAPI DebugSetMute()
{
#ifndef D3D8TO9NOLOG
LOG << "Redirecting '" << "DebugSetMute ()" << "'..." << std::endl;
#endif
}

extern "C" IDirect3D8 *WINAPI Direct3DCreate8(UINT SDKVersion)
{
#ifndef D3D8TO9NOLOG
Expand Down

0 comments on commit b5d8458

Please sign in to comment.