Skip to content

Commit 1bd9f79

Browse files
authored
Merge branch 'master' into fix/improve-aclrequest-detection
2 parents 0ab06a8 + 53097a6 commit 1bd9f79

File tree

10 files changed

+1531
-169
lines changed

10 files changed

+1531
-169
lines changed

Client/core/DXHook/CDirect3DEvents9.cpp

Lines changed: 1053 additions & 28 deletions
Large diffs are not rendered by default.

Client/core/DXHook/CDirect3DEvents9.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,45 @@ class CDirect3DEvents9
3434
static HRESULT DrawPrimitiveGuarded(IDirect3DDevice9* pDevice, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount);
3535
static HRESULT DrawIndexedPrimitiveGuarded(IDirect3DDevice9* pDevice, D3DPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT MinVertexIndex,
3636
UINT NumVertices, UINT startIndex, UINT primCount);
37+
static HRESULT DrawPrimitiveUPGuarded(IDirect3DDevice9* pDevice, D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount,
38+
CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride);
39+
static HRESULT DrawIndexedPrimitiveUPGuarded(IDirect3DDevice9* pDevice, D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertices,
40+
UINT PrimitiveCount, CONST void* pIndexData, D3DFORMAT IndexDataFormat,
41+
CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride);
42+
static HRESULT DrawRectPatchGuarded(IDirect3DDevice9* pDevice, UINT Handle, CONST float* pNumSegs,
43+
CONST D3DRECTPATCH_INFO* pRectPatchInfo);
44+
static HRESULT DrawTriPatchGuarded(IDirect3DDevice9* pDevice, UINT Handle, CONST float* pNumSegs,
45+
CONST D3DTRIPATCH_INFO* pTriPatchInfo);
46+
static HRESULT ProcessVerticesGuarded(IDirect3DDevice9* pDevice, UINT SrcStartIndex, UINT DestIndex, UINT VertexCount,
47+
IDirect3DVertexBuffer9* pDestBuffer, IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags);
48+
static HRESULT ClearGuarded(IDirect3DDevice9* pDevice, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil);
49+
static HRESULT ColorFillGuarded(IDirect3DDevice9* pDevice, IDirect3DSurface9* pSurface, CONST RECT* pRect, D3DCOLOR color);
50+
static HRESULT UpdateSurfaceGuarded(IDirect3DDevice9* pDevice, IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect,
51+
IDirect3DSurface9* pDestinationSurface, CONST POINT* pDestPoint);
52+
static HRESULT UpdateTextureGuarded(IDirect3DDevice9* pDevice, IDirect3DBaseTexture9* pSourceTexture,
53+
IDirect3DBaseTexture9* pDestinationTexture);
54+
static HRESULT GetRenderTargetDataGuarded(IDirect3DDevice9* pDevice, IDirect3DSurface9* pRenderTarget,
55+
IDirect3DSurface9* pDestSurface);
56+
static HRESULT GetFrontBufferDataGuarded(IDirect3DDevice9* pDevice, UINT iSwapChain, IDirect3DSurface9* pDestSurface);
57+
static HRESULT SetRenderTargetGuarded(IDirect3DDevice9* pDevice, DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget);
58+
static HRESULT SetDepthStencilSurfaceGuarded(IDirect3DDevice9* pDevice, IDirect3DSurface9* pNewZStencil);
59+
static HRESULT CreateAdditionalSwapChainGuarded(IDirect3DDevice9* pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters,
60+
IDirect3DSwapChain9** pSwapChain);
61+
static HRESULT CreateVolumeTextureGuarded(IDirect3DDevice9* pDevice, UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage,
62+
D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture9** ppVolumeTexture, HANDLE* pSharedHandle);
63+
static HRESULT CreateCubeTextureGuarded(IDirect3DDevice9* pDevice, UINT EdgeLength, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool,
64+
IDirect3DCubeTexture9** ppCubeTexture, HANDLE* pSharedHandle);
65+
static HRESULT CreateRenderTargetGuarded(IDirect3DDevice9* pDevice, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
66+
DWORD MultisampleQuality, BOOL Lockable, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle);
67+
static HRESULT CreateDepthStencilSurfaceGuarded(IDirect3DDevice9* pDevice, UINT Width, UINT Height, D3DFORMAT Format,
68+
D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Discard,
69+
IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle);
70+
static HRESULT CreateOffscreenPlainSurfaceGuarded(IDirect3DDevice9* pDevice, UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool,
71+
IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle);
72+
static HRESULT PresentGuarded(IDirect3DDevice9* pDevice, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride,
73+
CONST RGNDATA* pDirtyRegion);
74+
static bool IsDeviceOperational(IDirect3DDevice9* pDevice, bool* pbTemporarilyLost = nullptr,
75+
HRESULT* pHrCooperativeLevel = nullptr);
3776
static HRESULT CreateVertexBuffer(IDirect3DDevice9* pDevice, UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer9** ppVertexBuffer,
3877
HANDLE* pSharedHandle);
3978
static HRESULT CreateIndexBuffer(IDirect3DDevice9* pDevice, UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer9** ppIndexBuffer,

Client/core/DXHook/CProxyDirect3DDevice9.cpp

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ BOOL CProxyDirect3DDevice9::ShowCursor(BOOL bShow)
271271

272272
HRESULT CProxyDirect3DDevice9::CreateAdditionalSwapChain(D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain9** pSwapChain)
273273
{
274-
return m_pDevice->CreateAdditionalSwapChain(pPresentationParameters, pSwapChain);
274+
return CDirect3DEvents9::CreateAdditionalSwapChainGuarded(m_pDevice, pPresentationParameters, pSwapChain);
275275
}
276276

277277
HRESULT CProxyDirect3DDevice9::GetSwapChain(UINT iSwapChain, IDirect3DSwapChain9** pSwapChain)
@@ -499,18 +499,32 @@ HRESULT CProxyDirect3DDevice9::Reset(D3DPRESENT_PARAMETERS* pPresentationParamet
499499

500500
HRESULT CProxyDirect3DDevice9::Present(CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion)
501501
{
502-
CDirect3DEvents9::OnPresent(m_pDevice);
503-
504502
// Reset frame stat counters
505503
memset(&DeviceState.FrameStats, 0, sizeof(DeviceState.FrameStats));
506504

505+
bool bDeviceTemporarilyLost = false;
506+
HRESULT hrCoopLevel = D3DERR_INVALIDCALL;
507+
if (!CDirect3DEvents9::IsDeviceOperational(m_pDevice, &bDeviceTemporarilyLost, &hrCoopLevel))
508+
{
509+
if (bDeviceTemporarilyLost)
510+
WriteDebugEvent(SString("CProxyDirect3DDevice9::Present skipped due to device state: %08x", hrCoopLevel));
511+
else if (hrCoopLevel != D3D_OK)
512+
WriteDebugEvent(SString("CProxyDirect3DDevice9::Present unexpected cooperative level: %08x", hrCoopLevel));
513+
else
514+
WriteDebugEvent("CProxyDirect3DDevice9::Present invalid device state");
515+
516+
return (hrCoopLevel != D3D_OK) ? hrCoopLevel : D3DERR_INVALIDCALL;
517+
}
518+
519+
CDirect3DEvents9::OnPresent(m_pDevice);
520+
507521
// A fog flicker fix for some ATI cards
508522
D3DMATRIX projMatrix;
509523
m_pData->GetTransform(D3DTS_PROJECTION, &projMatrix);
510524
m_pDevice->SetTransform(D3DTS_PROJECTION, &projMatrix);
511525

512526
TIMING_GRAPH("Present");
513-
HRESULT hr = m_pDevice->Present(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
527+
HRESULT hr = CDirect3DEvents9::PresentGuarded(m_pDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
514528
TIMING_GRAPH("PostPresent");
515529
return hr;
516530
}
@@ -634,13 +648,13 @@ HRESULT CProxyDirect3DDevice9::CreateTexture(UINT Width, UINT Height, UINT Level
634648
HRESULT CProxyDirect3DDevice9::CreateVolumeTexture(UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool,
635649
IDirect3DVolumeTexture9** ppVolumeTexture, HANDLE* pSharedHandle)
636650
{
637-
return m_pDevice->CreateVolumeTexture(Width, Height, Depth, Levels, Usage, Format, Pool, ppVolumeTexture, pSharedHandle);
651+
return CDirect3DEvents9::CreateVolumeTextureGuarded(m_pDevice, Width, Height, Depth, Levels, Usage, Format, Pool, ppVolumeTexture, pSharedHandle);
638652
}
639653

640654
HRESULT CProxyDirect3DDevice9::CreateCubeTexture(UINT EdgeLength, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool,
641655
IDirect3DCubeTexture9** ppCubeTexture, HANDLE* pSharedHandle)
642656
{
643-
return m_pDevice->CreateCubeTexture(EdgeLength, Levels, Usage, Format, Pool, ppCubeTexture, pSharedHandle);
657+
return CDirect3DEvents9::CreateCubeTextureGuarded(m_pDevice, EdgeLength, Levels, Usage, Format, Pool, ppCubeTexture, pSharedHandle);
644658
}
645659

646660
HRESULT CProxyDirect3DDevice9::CreateVertexBuffer(UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer9** ppVertexBuffer,
@@ -658,57 +672,56 @@ HRESULT CProxyDirect3DDevice9::CreateIndexBuffer(UINT Length, DWORD Usage, D3DFO
658672
HRESULT CProxyDirect3DDevice9::CreateRenderTarget(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality,
659673
BOOL Lockable, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle)
660674
{
661-
return m_pDevice->CreateRenderTarget(Width, Height, Format, MultiSample, MultisampleQuality, Lockable, ppSurface, pSharedHandle);
675+
return CDirect3DEvents9::CreateRenderTargetGuarded(m_pDevice, Width, Height, Format, MultiSample, MultisampleQuality, Lockable, ppSurface, pSharedHandle);
662676
}
663677

664678
HRESULT CProxyDirect3DDevice9::CreateDepthStencilSurface(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality,
665679
BOOL Discard, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle)
666680
{
667-
return m_pDevice->CreateDepthStencilSurface(Width, Height, Format, MultiSample, MultisampleQuality, Discard, ppSurface, pSharedHandle);
681+
return CDirect3DEvents9::CreateDepthStencilSurfaceGuarded(m_pDevice, Width, Height, Format, MultiSample, MultisampleQuality, Discard, ppSurface, pSharedHandle);
668682
}
669683

670684
HRESULT CProxyDirect3DDevice9::UpdateSurface(IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface,
671685
CONST POINT* pDestPoint)
672686
{
673-
return m_pDevice->UpdateSurface(pSourceSurface, pSourceRect, pDestinationSurface, pDestPoint);
687+
return CDirect3DEvents9::UpdateSurfaceGuarded(m_pDevice, pSourceSurface, pSourceRect, pDestinationSurface, pDestPoint);
674688
}
675689

676690
HRESULT CProxyDirect3DDevice9::UpdateTexture(IDirect3DBaseTexture9* pSourceTexture, IDirect3DBaseTexture9* pDestinationTexture)
677691
{
678-
return m_pDevice->UpdateTexture(pSourceTexture, pDestinationTexture);
692+
return CDirect3DEvents9::UpdateTextureGuarded(m_pDevice, pSourceTexture, pDestinationTexture);
679693
}
680694

681695
HRESULT CProxyDirect3DDevice9::GetRenderTargetData(IDirect3DSurface9* pRenderTarget, IDirect3DSurface9* pDestSurface)
682696
{
683-
return m_pDevice->GetRenderTargetData(pRenderTarget, pDestSurface);
697+
return CDirect3DEvents9::GetRenderTargetDataGuarded(m_pDevice, pRenderTarget, pDestSurface);
684698
}
685699

686700
HRESULT CProxyDirect3DDevice9::GetFrontBufferData(UINT iSwapChain, IDirect3DSurface9* pDestSurface)
687701
{
688-
return m_pDevice->GetFrontBufferData(iSwapChain, pDestSurface);
702+
return CDirect3DEvents9::GetFrontBufferDataGuarded(m_pDevice, iSwapChain, pDestSurface);
689703
}
690704

691705
HRESULT CProxyDirect3DDevice9::StretchRect(IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface, CONST RECT* pDestRect,
692706
D3DTEXTUREFILTERTYPE Filter)
693707
{
694-
CGraphics::GetSingleton().GetRenderItemManager()->HandleStretchRect(pSourceSurface, pSourceRect, pDestSurface, pDestRect, Filter);
695-
return D3D_OK;
708+
return CGraphics::GetSingleton().GetRenderItemManager()->HandleStretchRect(pSourceSurface, pSourceRect, pDestSurface, pDestRect, Filter);
696709
}
697710

698711
HRESULT CProxyDirect3DDevice9::ColorFill(IDirect3DSurface9* pSurface, CONST RECT* pRect, D3DCOLOR color)
699712
{
700-
return m_pDevice->ColorFill(pSurface, pRect, color);
713+
return CDirect3DEvents9::ColorFillGuarded(m_pDevice, pSurface, pRect, color);
701714
}
702715

703716
HRESULT CProxyDirect3DDevice9::CreateOffscreenPlainSurface(UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9** ppSurface,
704717
HANDLE* pSharedHandle)
705718
{
706-
return m_pDevice->CreateOffscreenPlainSurface(Width, Height, Format, Pool, ppSurface, pSharedHandle);
719+
return CDirect3DEvents9::CreateOffscreenPlainSurfaceGuarded(m_pDevice, Width, Height, Format, Pool, ppSurface, pSharedHandle);
707720
}
708721

709722
HRESULT CProxyDirect3DDevice9::SetRenderTarget(DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget)
710723
{
711-
return m_pDevice->SetRenderTarget(RenderTargetIndex, pRenderTarget);
724+
return CDirect3DEvents9::SetRenderTargetGuarded(m_pDevice, RenderTargetIndex, pRenderTarget);
712725
}
713726

714727
HRESULT CProxyDirect3DDevice9::GetRenderTarget(DWORD RenderTargetIndex, IDirect3DSurface9** ppRenderTarget)
@@ -718,7 +731,7 @@ HRESULT CProxyDirect3DDevice9::GetRenderTarget(DWORD RenderTargetIndex, IDirect3
718731

719732
HRESULT CProxyDirect3DDevice9::SetDepthStencilSurface(IDirect3DSurface9* pNewZStencil)
720733
{
721-
return m_pDevice->SetDepthStencilSurface(pNewZStencil);
734+
return CDirect3DEvents9::SetDepthStencilSurfaceGuarded(m_pDevice, pNewZStencil);
722735
}
723736

724737
HRESULT CProxyDirect3DDevice9::GetDepthStencilSurface(IDirect3DSurface9** ppZStencilSurface)
@@ -774,7 +787,7 @@ HRESULT CProxyDirect3DDevice9::Clear(DWORD Count, CONST D3DRECT* pRects, DWORD F
774787
if (Flags & D3DCLEAR_ZBUFFER)
775788
CGraphics::GetSingleton().GetRenderItemManager()->SaveReadableDepthBuffer();
776789

777-
return m_pDevice->Clear(Count, pRects, Flags, Color, Z, Stencil);
790+
return CDirect3DEvents9::ClearGuarded(m_pDevice, Count, pRects, Flags, Color, Z, Stencil);
778791
}
779792

780793
HRESULT CProxyDirect3DDevice9::SetTransform(D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix)
@@ -1008,21 +1021,21 @@ HRESULT CProxyDirect3DDevice9::DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveTy
10081021
HRESULT CProxyDirect3DDevice9::DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, CONST void* pVertexStreamZeroData,
10091022
UINT VertexStreamZeroStride)
10101023
{
1011-
return m_pDevice->DrawPrimitiveUP(PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
1024+
return CDirect3DEvents9::DrawPrimitiveUPGuarded(m_pDevice, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
10121025
}
10131026

10141027
HRESULT CProxyDirect3DDevice9::DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertices, UINT PrimitiveCount,
10151028
CONST void* pIndexData, D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData,
10161029
UINT VertexStreamZeroStride)
10171030
{
1018-
return m_pDevice->DrawIndexedPrimitiveUP(PrimitiveType, MinVertexIndex, NumVertices, PrimitiveCount, pIndexData, IndexDataFormat, pVertexStreamZeroData,
1019-
VertexStreamZeroStride);
1031+
return CDirect3DEvents9::DrawIndexedPrimitiveUPGuarded(m_pDevice, PrimitiveType, MinVertexIndex, NumVertices, PrimitiveCount, pIndexData,
1032+
IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
10201033
}
10211034

10221035
HRESULT CProxyDirect3DDevice9::ProcessVertices(UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9* pDestBuffer,
10231036
IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags)
10241037
{
1025-
return m_pDevice->ProcessVertices(SrcStartIndex, DestIndex, VertexCount, pDestBuffer, pVertexDecl, Flags);
1038+
return CDirect3DEvents9::ProcessVerticesGuarded(m_pDevice, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, pVertexDecl, Flags);
10261039
}
10271040

10281041
HRESULT CProxyDirect3DDevice9::CreateVertexDeclaration(CONST D3DVERTEXELEMENT9* pVertexElements, IDirect3DVertexDeclaration9** ppDecl)
@@ -1182,12 +1195,12 @@ HRESULT CProxyDirect3DDevice9::GetPixelShaderConstantB(UINT StartRegister, BOOL*
11821195

11831196
HRESULT CProxyDirect3DDevice9::DrawRectPatch(UINT Handle, CONST float* pNumSegs, CONST D3DRECTPATCH_INFO* pRectPatchInfo)
11841197
{
1185-
return m_pDevice->DrawRectPatch(Handle, pNumSegs, pRectPatchInfo);
1198+
return CDirect3DEvents9::DrawRectPatchGuarded(m_pDevice, Handle, pNumSegs, pRectPatchInfo);
11861199
}
11871200

11881201
HRESULT CProxyDirect3DDevice9::DrawTriPatch(UINT Handle, CONST float* pNumSegs, CONST D3DTRIPATCH_INFO* pTriPatchInfo)
11891202
{
1190-
return m_pDevice->DrawTriPatch(Handle, pNumSegs, pTriPatchInfo);
1203+
return CDirect3DEvents9::DrawTriPatchGuarded(m_pDevice, Handle, pNumSegs, pTriPatchInfo);
11911204
}
11921205

11931206
HRESULT CProxyDirect3DDevice9::DeletePatch(UINT Handle)

0 commit comments

Comments
 (0)