diff --git a/source/d3d8to9.hpp b/source/d3d8to9.hpp index 7180e63..29ffe0a 100644 --- a/source/d3d8to9.hpp +++ b/source/d3d8to9.hpp @@ -170,6 +170,7 @@ class Direct3DDevice8 : public IDirect3DDevice8 DWORD CurrentVertexShaderHandle = 0, CurrentPixelShaderHandle = 0; IDirect3DSurface9 *pCurrentRenderTarget = nullptr; bool PaletteFlag = false; + bool IsRecordingState = false; static constexpr size_t MAX_CLIP_PLANES = 6; float StoredClipPlanes[MAX_CLIP_PLANES][4] = {}; diff --git a/source/d3d8to9_device.cpp b/source/d3d8to9_device.cpp index 5498845..75d712d 100644 --- a/source/d3d8to9_device.cpp +++ b/source/d3d8to9_device.cpp @@ -801,17 +801,31 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetRenderState(D3DRENDERSTATETYPE Sta } HRESULT STDMETHODCALLTYPE Direct3DDevice8::BeginStateBlock() { - return ProxyInterface->BeginStateBlock(); + if (IsRecordingState) + return D3DERR_INVALIDCALL; + + HRESULT hr = ProxyInterface->BeginStateBlock(); + + if (SUCCEEDED(hr)) + IsRecordingState = true; + + return hr; } HRESULT STDMETHODCALLTYPE Direct3DDevice8::EndStateBlock(DWORD *pToken) { if (pToken == nullptr) return D3DERR_INVALIDCALL; + if (!IsRecordingState) + return D3DERR_INVALIDCALL; + HRESULT hr = ProxyInterface->EndStateBlock(reinterpret_cast(pToken)); if (SUCCEEDED(hr)) + { StateBlockTokens.insert(*pToken); + IsRecordingState = false; + } return hr; } @@ -820,6 +834,9 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::ApplyStateBlock(DWORD Token) if (Token == 0) return D3DERR_INVALIDCALL; + if (IsRecordingState) + return D3DERR_INVALIDCALL; + return reinterpret_cast(Token)->Apply(); } HRESULT STDMETHODCALLTYPE Direct3DDevice8::CaptureStateBlock(DWORD Token) @@ -827,6 +844,9 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CaptureStateBlock(DWORD Token) if (Token == 0) return D3DERR_INVALIDCALL; + if (IsRecordingState) + return D3DERR_INVALIDCALL; + return reinterpret_cast(Token)->Capture(); } HRESULT STDMETHODCALLTYPE Direct3DDevice8::DeleteStateBlock(DWORD Token) @@ -834,6 +854,9 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::DeleteStateBlock(DWORD Token) if (Token == 0) return D3DERR_INVALIDCALL; + if (IsRecordingState) + return D3DERR_INVALIDCALL; + reinterpret_cast(Token)->Release(); StateBlockTokens.erase(Token); @@ -849,6 +872,9 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateStateBlock(D3DSTATEBLOCKTYPE Ty if (pToken == nullptr) return D3DERR_INVALIDCALL; + if (IsRecordingState) + return D3DERR_INVALIDCALL; + HRESULT hr = ProxyInterface->CreateStateBlock(Type, reinterpret_cast(pToken)); if (SUCCEEDED(hr))