diff --git a/Dllmain/BuildNo.rc b/Dllmain/BuildNo.rc index a58289c7..52991c8e 100644 --- a/Dllmain/BuildNo.rc +++ b/Dllmain/BuildNo.rc @@ -1 +1 @@ -#define BUILD_NUMBER 7103 +#define BUILD_NUMBER 7104 diff --git a/d3d9/AddressLookupTable.h b/d3d9/AddressLookupTable.h index 0c8b88b7..ca348663 100644 --- a/d3d9/AddressLookupTable.h +++ b/d3d9/AddressLookupTable.h @@ -56,19 +56,69 @@ class AddressLookupTableD3d9 template <> struct AddressCacheIndex { static constexpr UINT CacheIndex = 15; }; - m_IDirect3DSwapChain9Ex *CreateInterface(void *Proxy, REFIID riid) + m_IDirect3D9Ex* CreateInterface(m_IDirect3D9Ex* Proxy, void*, REFIID riid) + { + return new m_IDirect3D9Ex(static_cast(Proxy), riid); + } + m_IDirect3DDevice9Ex* CreateInterface(m_IDirect3DDevice9Ex* Proxy, m_IDirect3D9Ex* Device, REFIID riid) + { + return new m_IDirect3DDevice9Ex(static_cast(Proxy), Device, riid); + } + m_IDirect3DCubeTexture9* CreateInterface(m_IDirect3DCubeTexture9* Proxy, void*, REFIID) + { + return new m_IDirect3DCubeTexture9(static_cast(Proxy), pDevice); + } + m_IDirect3DIndexBuffer9* CreateInterface(m_IDirect3DIndexBuffer9* Proxy, void*, REFIID) + { + return new m_IDirect3DIndexBuffer9(static_cast(Proxy), pDevice); + } + m_IDirect3DPixelShader9* CreateInterface(m_IDirect3DPixelShader9* Proxy, void*, REFIID) + { + return new m_IDirect3DPixelShader9(static_cast(Proxy), pDevice); + } + m_IDirect3DQuery9* CreateInterface(m_IDirect3DQuery9* Proxy, void*, REFIID) + { + return new m_IDirect3DQuery9(static_cast(Proxy), pDevice); + } + m_IDirect3DStateBlock9* CreateInterface(m_IDirect3DStateBlock9* Proxy, void*, REFIID) + { + return new m_IDirect3DStateBlock9(static_cast(Proxy), pDevice); + } + m_IDirect3DSurface9* CreateInterface(m_IDirect3DSurface9* Proxy, void*, REFIID) + { + return new m_IDirect3DSurface9(static_cast(Proxy), pDevice); + } + m_IDirect3DSwapChain9Ex* CreateInterface(m_IDirect3DSwapChain9Ex* Proxy, void*, REFIID riid) { return new m_IDirect3DSwapChain9Ex(static_cast(Proxy), pDevice, riid); } - - template - T *CreateInterface(void *Proxy) + m_IDirect3DTexture9* CreateInterface(m_IDirect3DTexture9* Proxy, void*, REFIID) + { + return new m_IDirect3DTexture9(static_cast(Proxy), pDevice); + } + m_IDirect3DVertexBuffer9* CreateInterface(m_IDirect3DVertexBuffer9* Proxy, void*, REFIID) + { + return new m_IDirect3DVertexBuffer9(static_cast(Proxy), pDevice); + } + m_IDirect3DVertexDeclaration9* CreateInterface(m_IDirect3DVertexDeclaration9* Proxy, void*, REFIID) + { + return new m_IDirect3DVertexDeclaration9(static_cast(Proxy), pDevice); + } + m_IDirect3DVertexShader9* CreateInterface(m_IDirect3DVertexShader9* Proxy, void*, REFIID) + { + return new m_IDirect3DVertexShader9(static_cast(Proxy), pDevice); + } + m_IDirect3DVolume9* CreateInterface(m_IDirect3DVolume9* Proxy, void*, REFIID) + { + return new m_IDirect3DVolume9(static_cast(Proxy), pDevice); + } + m_IDirect3DVolumeTexture9* CreateInterface(m_IDirect3DVolumeTexture9* Proxy, void*, REFIID) { - return new T(static_cast(Proxy), pDevice); + return new m_IDirect3DVolumeTexture9(static_cast(Proxy), pDevice); } - template - T *FindAddress(void *Proxy, REFIID riid = IID_IUnknown) + template + T *FindAddress(void* Proxy, D* Device, REFIID riid) { if (!Proxy) { @@ -83,14 +133,7 @@ class AddressLookupTableD3d9 return static_cast(it->second); } - if (riid == IID_IUnknown) - { - return CreateInterface(Proxy); - } - else - { - return (T*)CreateInterface(Proxy, riid); - } + return CreateInterface((T*)Proxy, Device, riid); } template diff --git a/d3d9/IDirect3D9Ex.cpp b/d3d9/IDirect3D9Ex.cpp index 64d4ebec..079e31a9 100644 --- a/d3d9/IDirect3D9Ex.cpp +++ b/d3d9/IDirect3D9Ex.cpp @@ -24,7 +24,7 @@ void AdjustWindow(HWND MainhWnd, LONG displayWidth, LONG displayHeight, bool isW HRESULT m_IDirect3D9Ex::QueryInterface(REFIID riid, void** ppvObj) { - Logging::LogDebug() << __FUNCTION__ << " (" << this << ")"; + Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid; if ((riid == IID_IUnknown || riid == WrapperID) && ppvObj) { @@ -35,7 +35,22 @@ HRESULT m_IDirect3D9Ex::QueryInterface(REFIID riid, void** ppvObj) return D3D_OK; } - return ProxyInterface->QueryInterface(riid, ppvObj); + HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj); + + if (SUCCEEDED(hr) && ppvObj) + { + if (riid == IID_IDirect3D9 || riid == IID_IDirect3D9Ex) + { + LOG_LIMIT(100, __FUNCTION__ << " Warning: creating a second wrapper interface: " << riid); + *ppvObj = ProxyAddressLookupTableDevice9.FindAddress(*ppvObj, nullptr, riid); + } + else + { + LOG_LIMIT(100, __FUNCTION__ << " Warning: not wrapping interface: " << riid); + } + } + + return hr; } ULONG m_IDirect3D9Ex::AddRef() @@ -280,7 +295,8 @@ HRESULT m_IDirect3D9Ex::CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND h DeviceDetails.DeviceMultiSampleType = pPresentationParameters->MultiSampleType; DeviceDetails.DeviceMultiSampleQuality = pPresentationParameters->MultiSampleQuality; - *ppReturnedDeviceInterface = new m_IDirect3DDevice9Ex((LPDIRECT3DDEVICE9EX)*ppReturnedDeviceInterface, this, IID_IDirect3DDevice9, DeviceDetails); + *ppReturnedDeviceInterface = new m_IDirect3DDevice9Ex((LPDIRECT3DDEVICE9EX)*ppReturnedDeviceInterface, this, IID_IDirect3DDevice9); + ((m_IDirect3DDevice9Ex*)(*ppReturnedDeviceInterface))->SetDeviceDetails(DeviceDetails); return D3D_OK; } @@ -350,7 +366,8 @@ HRESULT m_IDirect3D9Ex::CreateDeviceEx(THIS_ UINT Adapter, D3DDEVTYPE DeviceType DeviceDetails.DeviceMultiSampleType = pPresentationParameters->MultiSampleType; DeviceDetails.DeviceMultiSampleQuality = pPresentationParameters->MultiSampleQuality; - *ppReturnedDeviceInterface = new m_IDirect3DDevice9Ex(*ppReturnedDeviceInterface, this, IID_IDirect3DDevice9Ex, DeviceDetails); + *ppReturnedDeviceInterface = new m_IDirect3DDevice9Ex(*ppReturnedDeviceInterface, this, IID_IDirect3DDevice9Ex); + ((m_IDirect3DDevice9Ex*)(*ppReturnedDeviceInterface))->SetDeviceDetails(DeviceDetails); return D3D_OK; } diff --git a/d3d9/IDirect3D9Ex.h b/d3d9/IDirect3D9Ex.h index 980eeec1..d19d6c8c 100644 --- a/d3d9/IDirect3D9Ex.h +++ b/d3d9/IDirect3D9Ex.h @@ -1,6 +1,6 @@ #pragma once -class m_IDirect3D9Ex : public IDirect3D9Ex +class m_IDirect3D9Ex : public IDirect3D9Ex, public AddressLookupTableD3d9Object { private: LPDIRECT3D9 ProxyInterface; @@ -30,11 +30,15 @@ class m_IDirect3D9Ex : public IDirect3D9Ex ProxyInterfaceEx = pDirect3D; } + ProxyAddressLookupTableDevice9.SaveAddress(this, ProxyInterface); + LogAdapterNames(); } ~m_IDirect3D9Ex() { LOG_LIMIT(3, __FUNCTION__ << " (" << this << ")" << " deleting interface!"); + + ProxyAddressLookupTableDevice9.DeleteAddress(this); } /*** IUnknown methods ***/ diff --git a/d3d9/IDirect3DCubeTexture9.cpp b/d3d9/IDirect3DCubeTexture9.cpp index 22e02497..7bd045ab 100644 --- a/d3d9/IDirect3DCubeTexture9.cpp +++ b/d3d9/IDirect3DCubeTexture9.cpp @@ -18,7 +18,7 @@ HRESULT m_IDirect3DCubeTexture9::QueryInterface(THIS_ REFIID riid, void** ppvObj) { - Logging::LogDebug() << __FUNCTION__ << " (" << this << ")"; + Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid; if ((riid == IID_IDirect3DCubeTexture9 || riid == IID_IUnknown || riid == IID_IDirect3DResource9 || riid == IID_IDirect3DBaseTexture9) && ppvObj) { @@ -175,7 +175,7 @@ HRESULT m_IDirect3DCubeTexture9::GetCubeMapSurface(THIS_ D3DCUBEMAP_FACES FaceTy if (SUCCEEDED(hr) && ppCubeMapSurface) { - *ppCubeMapSurface = m_pDeviceEx->ProxyAddressLookupTable->FindAddress(*ppCubeMapSurface); + *ppCubeMapSurface = m_pDeviceEx->ProxyAddressLookupTable->FindAddress(*ppCubeMapSurface, m_pDeviceEx, IID_IDirect3DTexture9); } return hr; diff --git a/d3d9/IDirect3DDevice9Ex.cpp b/d3d9/IDirect3DDevice9Ex.cpp index 89bfe5f4..be76691a 100644 --- a/d3d9/IDirect3DDevice9Ex.cpp +++ b/d3d9/IDirect3DDevice9Ex.cpp @@ -26,7 +26,7 @@ DebugOverlay DOverlay; HRESULT m_IDirect3DDevice9Ex::QueryInterface(REFIID riid, void** ppvObj) { - Logging::LogDebug() << __FUNCTION__ << " (" << this << ")"; + Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid; if ((riid == IID_IUnknown || riid == WrapperID) && ppvObj) { @@ -39,9 +39,18 @@ HRESULT m_IDirect3DDevice9Ex::QueryInterface(REFIID riid, void** ppvObj) HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj); - if (SUCCEEDED(hr)) + if (SUCCEEDED(hr) && ppvObj) { - D3d9Wrapper::genericQueryInterface(riid, ppvObj, this); + if (riid == IID_IDirect3DDevice9 || riid == IID_IDirect3DDevice9Ex) + { + LOG_LIMIT(100, __FUNCTION__ << " Warning: creating a second wrapper interface: " << riid); + *ppvObj = ProxyAddressLookupTableDevice9.FindAddress(*ppvObj, m_pD3DEx, riid); + ((m_IDirect3DDevice9Ex*)(*ppvObj))->SetDeviceDetails(DeviceDetails); + } + else + { + D3d9Wrapper::genericQueryInterface(riid, ppvObj, this); + } } return hr; @@ -269,7 +278,7 @@ HRESULT m_IDirect3DDevice9Ex::CreateAdditionalSwapChain(D3DPRESENT_PARAMETERS *p { CopyMemory(pPresentationParameters, &d3dpp, sizeof(D3DPRESENT_PARAMETERS)); - *ppSwapChain = new m_IDirect3DSwapChain9Ex((IDirect3DSwapChain9Ex*)*ppSwapChain, this); + *ppSwapChain = new m_IDirect3DSwapChain9Ex((IDirect3DSwapChain9Ex*)*ppSwapChain, this, IID_IDirect3DSwapChain9); return D3D_OK; } @@ -498,7 +507,7 @@ HRESULT m_IDirect3DDevice9Ex::EndStateBlock(THIS_ IDirect3DStateBlock9** ppSB) if (SUCCEEDED(hr) && ppSB) { - *ppSB = ProxyAddressLookupTable->FindAddress(*ppSB); + *ppSB = ProxyAddressLookupTable->FindAddress(*ppSB, this, IID_IDirect3DStateBlock9); } return hr; @@ -533,7 +542,7 @@ HRESULT m_IDirect3DDevice9Ex::GetRenderTarget(THIS_ DWORD RenderTargetIndex, IDi if (SUCCEEDED(hr) && ppRenderTarget) { - *ppRenderTarget = ProxyAddressLookupTable->FindAddress(*ppRenderTarget); + *ppRenderTarget = ProxyAddressLookupTable->FindAddress(*ppRenderTarget, this, IID_IDirect3DSurface9); } return hr; @@ -636,7 +645,7 @@ HRESULT m_IDirect3DDevice9Ex::GetIndices(THIS_ IDirect3DIndexBuffer9** ppIndexDa if (SUCCEEDED(hr) && ppIndexData) { - *ppIndexData = ProxyAddressLookupTable->FindAddress(*ppIndexData); + *ppIndexData = ProxyAddressLookupTable->FindAddress(*ppIndexData, this, IID_IDirect3DIndexBuffer9); } return hr; @@ -829,7 +838,7 @@ HRESULT m_IDirect3DDevice9Ex::GetPixelShader(THIS_ IDirect3DPixelShader9** ppSha if (SUCCEEDED(hr) && ppShader) { - *ppShader = ProxyAddressLookupTable->FindAddress(*ppShader); + *ppShader = ProxyAddressLookupTable->FindAddress(*ppShader, this, IID_IDirect3DPixelShader9); } return hr; @@ -985,7 +994,7 @@ HRESULT m_IDirect3DDevice9Ex::GetStreamSource(THIS_ UINT StreamNumber, IDirect3D if (SUCCEEDED(hr) && ppStreamData) { - *ppStreamData = ProxyAddressLookupTable->FindAddress(*ppStreamData); + *ppStreamData = ProxyAddressLookupTable->FindAddress(*ppStreamData, this, IID_IDirect3DVertexBuffer9); } return hr; @@ -1011,7 +1020,7 @@ HRESULT m_IDirect3DDevice9Ex::GetBackBuffer(THIS_ UINT iSwapChain, UINT iBackBuf if (SUCCEEDED(hr) && ppBackBuffer) { - *ppBackBuffer = ProxyAddressLookupTable->FindAddress(*ppBackBuffer); + *ppBackBuffer = ProxyAddressLookupTable->FindAddress(*ppBackBuffer, this, IID_IDirect3DSurface9); } return hr; @@ -1025,7 +1034,7 @@ HRESULT m_IDirect3DDevice9Ex::GetDepthStencilSurface(IDirect3DSurface9 **ppZSten if (SUCCEEDED(hr) && ppZStencilSurface) { - *ppZStencilSurface = ProxyAddressLookupTable->FindAddress(*ppZStencilSurface); + *ppZStencilSurface = ProxyAddressLookupTable->FindAddress(*ppZStencilSurface, this, IID_IDirect3DSurface9); } return hr; @@ -1042,13 +1051,13 @@ HRESULT m_IDirect3DDevice9Ex::GetTexture(DWORD Stage, IDirect3DBaseTexture9 **pp switch ((*ppTexture)->GetType()) { case D3DRTYPE_TEXTURE: - *ppTexture = ProxyAddressLookupTable->FindAddress(*ppTexture); + *ppTexture = ProxyAddressLookupTable->FindAddress(*ppTexture, this, IID_IDirect3DTexture9); break; case D3DRTYPE_VOLUMETEXTURE: - *ppTexture = ProxyAddressLookupTable->FindAddress(*ppTexture); + *ppTexture = ProxyAddressLookupTable->FindAddress(*ppTexture, this, IID_IDirect3DVolumeTexture9); break; case D3DRTYPE_CUBETEXTURE: - *ppTexture = ProxyAddressLookupTable->FindAddress(*ppTexture); + *ppTexture = ProxyAddressLookupTable->FindAddress(*ppTexture, this, IID_IDirect3DCubeTexture9); break; default: return D3DERR_INVALIDCALL; @@ -1272,7 +1281,7 @@ HRESULT m_IDirect3DDevice9Ex::GetVertexShader(THIS_ IDirect3DVertexShader9** ppS if (SUCCEEDED(hr) && ppShader) { - *ppShader = ProxyAddressLookupTable->FindAddress(*ppShader); + *ppShader = ProxyAddressLookupTable->FindAddress(*ppShader, this, IID_IDirect3DVertexShader9); } return hr; @@ -1464,7 +1473,7 @@ HRESULT m_IDirect3DDevice9Ex::GetVertexDeclaration(THIS_ IDirect3DVertexDeclarat if (SUCCEEDED(hr) && ppDecl) { - *ppDecl = ProxyAddressLookupTable->FindAddress(*ppDecl); + *ppDecl = ProxyAddressLookupTable->FindAddress(*ppDecl, this, IID_IDirect3DVertexDeclaration9); } return hr; @@ -2045,7 +2054,7 @@ HRESULT m_IDirect3DDevice9Ex::GetSwapChain(THIS_ UINT iSwapChain, IDirect3DSwapC if (SUCCEEDED(hr)) { - *ppSwapChain = ProxyAddressLookupTable->FindAddress(*ppSwapChain); + *ppSwapChain = ProxyAddressLookupTable->FindAddress(*ppSwapChain, this, IID_IDirect3DSwapChain9); } return hr; diff --git a/d3d9/IDirect3DDevice9Ex.h b/d3d9/IDirect3DDevice9Ex.h index bb71bb6c..c5a144bc 100644 --- a/d3d9/IDirect3DDevice9Ex.h +++ b/d3d9/IDirect3DDevice9Ex.h @@ -2,7 +2,7 @@ #include "GDI\GDI.h" -class m_IDirect3DDevice9Ex : public IDirect3DDevice9Ex +class m_IDirect3DDevice9Ex : public IDirect3DDevice9Ex, public AddressLookupTableD3d9Object { private: LPDIRECT3DDEVICE9 ProxyInterface; @@ -51,27 +51,7 @@ class m_IDirect3DDevice9Ex : public IDirect3DDevice9Ex { return (ProxyInterfaceEx) ? ProxyInterfaceEx->ResetEx(pPresentationParameters, pFullscreenDisplayMode) : D3DERR_INVALIDCALL; } public: - m_IDirect3DDevice9Ex(LPDIRECT3DDEVICE9EX pDevice, m_IDirect3D9Ex* pD3D, REFIID DeviceID = IID_IUnknown) : ProxyInterface(pDevice), m_pD3DEx(pD3D), WrapperID(DeviceID) - { - if (WrapperID == IID_IUnknown) - { - Logging::Log() << "Warning: Creating interface " << __FUNCTION__ << " (" << this << ") with unknown IID"; - } - InitDirect3DDevice(pDevice); - } - m_IDirect3DDevice9Ex(LPDIRECT3DDEVICE9EX pDevice, m_IDirect3D9Ex* pD3D, REFIID DeviceID, DEVICEDETAILS NewDeviceDetails) : - ProxyInterface(pDevice), m_pD3DEx(pD3D), WrapperID(DeviceID), DeviceDetails(NewDeviceDetails) - { - InitDirect3DDevice(pDevice); - - // Check for SSAA - if (DeviceDetails.DeviceMultiSampleType && m_pD3DEx && - m_pD3DEx->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, 0, D3DRTYPE_SURFACE, (D3DFORMAT)MAKEFOURCC('S', 'S', 'A', 'A')) == S_OK) - { - SetSSAA = true; - } - } - void InitDirect3DDevice(LPDIRECT3DDEVICE9EX pDevice) + m_IDirect3DDevice9Ex(LPDIRECT3DDEVICE9EX pDevice, m_IDirect3D9Ex* pD3D, REFIID DeviceID) : ProxyInterface(pDevice), m_pD3DEx(pD3D), WrapperID(DeviceID) { LOG_LIMIT(3, "Creating interface " << __FUNCTION__ << " (" << this << ")"); @@ -83,6 +63,8 @@ class m_IDirect3DDevice9Ex : public IDirect3DDevice9Ex ReInitDevice(); ProxyAddressLookupTable = new AddressLookupTableD3d9(this); + + ProxyAddressLookupTableDevice9.SaveAddress(this, ProxyInterface); } ~m_IDirect3DDevice9Ex() { @@ -95,9 +77,22 @@ class m_IDirect3DDevice9Ex : public IDirect3DDevice9Ex } delete ProxyAddressLookupTable; + + ProxyAddressLookupTableDevice9.DeleteAddress(this); + } + void SetDeviceDetails(DEVICEDETAILS& NewDeviceDetails) + { + DeviceDetails = NewDeviceDetails; + + // Check for SSAA + if (DeviceDetails.DeviceMultiSampleType && m_pD3DEx && + m_pD3DEx->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, 0, D3DRTYPE_SURFACE, (D3DFORMAT)MAKEFOURCC('S', 'S', 'A', 'A')) == S_OK) + { + SetSSAA = true; + } } - AddressLookupTableD3d9 *ProxyAddressLookupTable; + AddressLookupTableD3d9 *ProxyAddressLookupTable = nullptr; /*** IUnknown methods ***/ STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj); diff --git a/d3d9/IDirect3DIndexBuffer9.cpp b/d3d9/IDirect3DIndexBuffer9.cpp index f0199694..acc3cb7a 100644 --- a/d3d9/IDirect3DIndexBuffer9.cpp +++ b/d3d9/IDirect3DIndexBuffer9.cpp @@ -18,7 +18,7 @@ HRESULT m_IDirect3DIndexBuffer9::QueryInterface(THIS_ REFIID riid, void** ppvObj) { - Logging::LogDebug() << __FUNCTION__ << " (" << this << ")"; + Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid; if ((riid == IID_IDirect3DIndexBuffer9 || riid == IID_IUnknown || riid == IID_IDirect3DResource9) && ppvObj) { diff --git a/d3d9/IDirect3DPixelShader9.cpp b/d3d9/IDirect3DPixelShader9.cpp index 433ae4d0..1761b164 100644 --- a/d3d9/IDirect3DPixelShader9.cpp +++ b/d3d9/IDirect3DPixelShader9.cpp @@ -18,7 +18,7 @@ HRESULT m_IDirect3DPixelShader9::QueryInterface(THIS_ REFIID riid, void** ppvObj) { - Logging::LogDebug() << __FUNCTION__ << " (" << this << ")"; + Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid; if ((riid == IID_IDirect3DPixelShader9 || riid == IID_IUnknown) && ppvObj) { diff --git a/d3d9/IDirect3DQuery9.cpp b/d3d9/IDirect3DQuery9.cpp index dd1360bf..a0aa8685 100644 --- a/d3d9/IDirect3DQuery9.cpp +++ b/d3d9/IDirect3DQuery9.cpp @@ -18,7 +18,7 @@ HRESULT m_IDirect3DQuery9::QueryInterface(THIS_ REFIID riid, void** ppvObj) { - Logging::LogDebug() << __FUNCTION__ << " (" << this << ")"; + Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid; if ((riid == IID_IDirect3DQuery9 || riid == IID_IUnknown) && ppvObj) { diff --git a/d3d9/IDirect3DStateBlock9.cpp b/d3d9/IDirect3DStateBlock9.cpp index 60db769e..a0e74278 100644 --- a/d3d9/IDirect3DStateBlock9.cpp +++ b/d3d9/IDirect3DStateBlock9.cpp @@ -18,7 +18,7 @@ HRESULT m_IDirect3DStateBlock9::QueryInterface(THIS_ REFIID riid, void** ppvObj) { - Logging::LogDebug() << __FUNCTION__ << " (" << this << ")"; + Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid; if ((riid == IID_IDirect3DStateBlock9 || riid == IID_IUnknown) && ppvObj) { diff --git a/d3d9/IDirect3DSurface9.cpp b/d3d9/IDirect3DSurface9.cpp index e75d9280..55cacc83 100644 --- a/d3d9/IDirect3DSurface9.cpp +++ b/d3d9/IDirect3DSurface9.cpp @@ -18,7 +18,7 @@ HRESULT m_IDirect3DSurface9::QueryInterface(THIS_ REFIID riid, void** ppvObj) { - Logging::LogDebug() << __FUNCTION__ << " (" << this << ")"; + Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid; if ((riid == IID_IDirect3DSurface9 || riid == IID_IUnknown || riid == IID_IDirect3DResource9) && ppvObj) { diff --git a/d3d9/IDirect3DSwapChain9Ex.cpp b/d3d9/IDirect3DSwapChain9Ex.cpp index b935bf53..f908303c 100644 --- a/d3d9/IDirect3DSwapChain9Ex.cpp +++ b/d3d9/IDirect3DSwapChain9Ex.cpp @@ -18,7 +18,7 @@ HRESULT m_IDirect3DSwapChain9Ex::QueryInterface(THIS_ REFIID riid, void** ppvObj) { - Logging::LogDebug() << __FUNCTION__ << " (" << this << ")"; + Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid; if ((riid == WrapperID || riid == IID_IUnknown) && ppvObj) { @@ -80,7 +80,7 @@ HRESULT m_IDirect3DSwapChain9Ex::GetBackBuffer(THIS_ UINT BackBuffer, D3DBACKBUF if (SUCCEEDED(hr) && ppBackBuffer) { - *ppBackBuffer = m_pDeviceEx->ProxyAddressLookupTable->FindAddress(*ppBackBuffer); + *ppBackBuffer = m_pDeviceEx->ProxyAddressLookupTable->FindAddress(*ppBackBuffer, m_pDeviceEx, IID_IDirect3DSurface9); } return hr; diff --git a/d3d9/IDirect3DSwapChain9Ex.h b/d3d9/IDirect3DSwapChain9Ex.h index 935b5484..75cd296f 100644 --- a/d3d9/IDirect3DSwapChain9Ex.h +++ b/d3d9/IDirect3DSwapChain9Ex.h @@ -9,7 +9,7 @@ class m_IDirect3DSwapChain9Ex : public IDirect3DSwapChain9Ex, public AddressLook REFIID WrapperID; public: - m_IDirect3DSwapChain9Ex(LPDIRECT3DSWAPCHAIN9EX pSwapChain9, m_IDirect3DDevice9Ex* pDevice, REFIID DeviceID = IID_IDirect3DSwapChain9) : ProxyInterface(pSwapChain9), m_pDeviceEx(pDevice), WrapperID(DeviceID) + m_IDirect3DSwapChain9Ex(LPDIRECT3DSWAPCHAIN9EX pSwapChain9, m_IDirect3DDevice9Ex* pDevice, REFIID DeviceID) : ProxyInterface(pSwapChain9), m_pDeviceEx(pDevice), WrapperID(DeviceID) { LOG_LIMIT(3, "Creating interface " << __FUNCTION__ << " (" << this << ")"); diff --git a/d3d9/IDirect3DTexture9.cpp b/d3d9/IDirect3DTexture9.cpp index 2711776f..d45b02c2 100644 --- a/d3d9/IDirect3DTexture9.cpp +++ b/d3d9/IDirect3DTexture9.cpp @@ -18,7 +18,7 @@ HRESULT m_IDirect3DTexture9::QueryInterface(THIS_ REFIID riid, void** ppvObj) { - Logging::LogDebug() << __FUNCTION__ << " (" << this << ")"; + Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid; if ((riid == IID_IDirect3DTexture9 || riid == IID_IUnknown || riid == IID_IDirect3DResource9 || riid == IID_IDirect3DBaseTexture9) && ppvObj) { @@ -175,7 +175,7 @@ HRESULT m_IDirect3DTexture9::GetSurfaceLevel(THIS_ UINT Level, IDirect3DSurface9 if (SUCCEEDED(hr) && ppSurfaceLevel) { - *ppSurfaceLevel = m_pDeviceEx->ProxyAddressLookupTable->FindAddress(*ppSurfaceLevel); + *ppSurfaceLevel = m_pDeviceEx->ProxyAddressLookupTable->FindAddress(*ppSurfaceLevel, m_pDeviceEx, IID_IDirect3DSurface9); } return hr; diff --git a/d3d9/IDirect3DVertexBuffer9.cpp b/d3d9/IDirect3DVertexBuffer9.cpp index e923ac34..97d8d7e8 100644 --- a/d3d9/IDirect3DVertexBuffer9.cpp +++ b/d3d9/IDirect3DVertexBuffer9.cpp @@ -18,7 +18,7 @@ HRESULT m_IDirect3DVertexBuffer9::QueryInterface(THIS_ REFIID riid, void** ppvObj) { - Logging::LogDebug() << __FUNCTION__ << " (" << this << ")"; + Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid; if ((riid == IID_IDirect3DVertexBuffer9 || riid == IID_IUnknown || riid == IID_IDirect3DResource9) && ppvObj) { diff --git a/d3d9/IDirect3DVertexDeclaration9.cpp b/d3d9/IDirect3DVertexDeclaration9.cpp index db7ee266..a04dfe31 100644 --- a/d3d9/IDirect3DVertexDeclaration9.cpp +++ b/d3d9/IDirect3DVertexDeclaration9.cpp @@ -18,7 +18,7 @@ HRESULT m_IDirect3DVertexDeclaration9::QueryInterface(THIS_ REFIID riid, void** ppvObj) { - Logging::LogDebug() << __FUNCTION__ << " (" << this << ")"; + Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid; if ((riid == IID_IDirect3DVertexDeclaration9 || riid == IID_IUnknown) && ppvObj) { diff --git a/d3d9/IDirect3DVertexShader9.cpp b/d3d9/IDirect3DVertexShader9.cpp index 8f860471..f1637601 100644 --- a/d3d9/IDirect3DVertexShader9.cpp +++ b/d3d9/IDirect3DVertexShader9.cpp @@ -18,7 +18,7 @@ HRESULT m_IDirect3DVertexShader9::QueryInterface(THIS_ REFIID riid, void** ppvObj) { - Logging::LogDebug() << __FUNCTION__ << " (" << this << ")"; + Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid; if ((riid == IID_IDirect3DVertexShader9 || riid == IID_IUnknown) && ppvObj) { diff --git a/d3d9/IDirect3DVolume9.cpp b/d3d9/IDirect3DVolume9.cpp index e0aadf17..63d2b53c 100644 --- a/d3d9/IDirect3DVolume9.cpp +++ b/d3d9/IDirect3DVolume9.cpp @@ -18,7 +18,7 @@ HRESULT m_IDirect3DVolume9::QueryInterface(THIS_ REFIID riid, void** ppvObj) { - Logging::LogDebug() << __FUNCTION__ << " (" << this << ")"; + Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid; if ((riid == IID_IDirect3DVolume9 || riid == IID_IUnknown) && ppvObj) { diff --git a/d3d9/IDirect3DVolumeTexture9.cpp b/d3d9/IDirect3DVolumeTexture9.cpp index 4dbe6bcc..296996ef 100644 --- a/d3d9/IDirect3DVolumeTexture9.cpp +++ b/d3d9/IDirect3DVolumeTexture9.cpp @@ -18,7 +18,7 @@ HRESULT m_IDirect3DVolumeTexture9::QueryInterface(THIS_ REFIID riid, void** ppvObj) { - Logging::LogDebug() << __FUNCTION__ << " (" << this << ")"; + Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid; if ((riid == IID_IDirect3DVolumeTexture9 || riid == IID_IUnknown || riid == IID_IDirect3DResource9 || riid == IID_IDirect3DBaseTexture9) && ppvObj) { @@ -175,7 +175,7 @@ HRESULT m_IDirect3DVolumeTexture9::GetVolumeLevel(THIS_ UINT Level, IDirect3DVol if (SUCCEEDED(hr) && ppVolumeLevel) { - *ppVolumeLevel = m_pDeviceEx->ProxyAddressLookupTable->FindAddress(*ppVolumeLevel); + *ppVolumeLevel = m_pDeviceEx->ProxyAddressLookupTable->FindAddress(*ppVolumeLevel, m_pDeviceEx, IID_IDirect3DVolume9); } return hr; diff --git a/d3d9/InterfaceQuery.cpp b/d3d9/InterfaceQuery.cpp index ac99f196..b7de65ef 100644 --- a/d3d9/InterfaceQuery.cpp +++ b/d3d9/InterfaceQuery.cpp @@ -20,44 +20,52 @@ void WINAPI D3d9Wrapper::genericQueryInterface(REFIID riid, LPVOID *ppvObj, m_ID { if (!ppvObj || !*ppvObj || !m_pDeviceEx) { + LOG_LIMIT(100, __FUNCTION__ << " Warning: not wrapping interface because of nullptr: " << riid); return; } if (riid == IID_IDirect3D9 || riid == IID_IDirect3D9Ex) { IDirect3D9 *pD3D9 = nullptr; - if (SUCCEEDED(m_pDeviceEx->GetDirect3D(&pD3D9)) && pD3D9) + if (SUCCEEDED(m_pDeviceEx->GetDirect3D(&pD3D9))) { - IDirect3D9 *pD3D9wrapper = nullptr; - if (SUCCEEDED(pD3D9->QueryInterface(riid, (LPVOID*)&pD3D9wrapper)) && pD3D9wrapper) + IDirect3D9* pD3D9Ex = nullptr; + if (SUCCEEDED(pD3D9->QueryInterface(riid, (LPVOID*)&pD3D9Ex))) { - pD3D9wrapper->Release(); + *ppvObj = pD3D9Ex; + pD3D9Ex->Release(); + pD3D9->Release(); + return; } pD3D9->Release(); - return; } + LOG_LIMIT(100, __FUNCTION__ << " Warning: not wrapping interface: " << riid); + return; } if (riid == IID_IDirect3DDevice9 || riid == IID_IDirect3DDevice9Ex) { IDirect3DDevice9 *pD3DDevice9 = nullptr; - if (SUCCEEDED(m_pDeviceEx->QueryInterface(riid, (LPVOID*)&pD3DDevice9)) && pD3DDevice9) + if (SUCCEEDED(m_pDeviceEx->QueryInterface(riid, (LPVOID*)&pD3DDevice9))) { + *ppvObj = pD3DDevice9; pD3DDevice9->Release(); + return; } + LOG_LIMIT(100, __FUNCTION__ << " Warning: not wrapping interface: " << riid); return; } if (riid == IID_IDirect3DSwapChain9 || riid == IID_IDirect3DSwapChain9Ex) { - *ppvObj = m_pDeviceEx->ProxyAddressLookupTable->FindAddress(*ppvObj, riid); + *ppvObj = m_pDeviceEx->ProxyAddressLookupTable->FindAddress(*ppvObj, m_pDeviceEx, riid); return; } #define QUERYINTERFACE(x) \ if (riid == IID_ ## x) \ { \ - *ppvObj = m_pDeviceEx->ProxyAddressLookupTable->FindAddress(*ppvObj); \ + *ppvObj = m_pDeviceEx->ProxyAddressLookupTable->FindAddress(*ppvObj, m_pDeviceEx, riid); \ return; \ } @@ -73,4 +81,6 @@ void WINAPI D3d9Wrapper::genericQueryInterface(REFIID riid, LPVOID *ppvObj, m_ID QUERYINTERFACE(IDirect3DVertexShader9); QUERYINTERFACE(IDirect3DVolume9); QUERYINTERFACE(IDirect3DVolumeTexture9); + + LOG_LIMIT(100, __FUNCTION__ << " Warning: not wrapping interface: " << riid); } diff --git a/d3d9/d3d9.cpp b/d3d9/d3d9.cpp index 95de6b90..4a92d7c0 100644 --- a/d3d9/d3d9.cpp +++ b/d3d9/d3d9.cpp @@ -27,6 +27,8 @@ namespace D3d9Wrapper using namespace D3d9Wrapper; +AddressLookupTableD3d9 ProxyAddressLookupTableDevice9(nullptr); + HMODULE GetSystemD3d9() { static HMODULE h_d3d9 = nullptr; diff --git a/d3d9/d3d9.h b/d3d9/d3d9.h index 2d9827f6..85c4b0c0 100644 --- a/d3d9/d3d9.h +++ b/d3d9/d3d9.h @@ -46,6 +46,8 @@ struct DEVICEDETAILS DWORD DeviceMultiSampleQuality = 0; }; +extern AddressLookupTableD3d9 ProxyAddressLookupTableDevice9; + DWORD UpdateBehaviorFlags(DWORD BehaviorFlags); void UpdatePresentParameter(D3DPRESENT_PARAMETERS* pPresentationParameters, HWND hFocusWindow, DEVICEDETAILS& DeviceDetails, bool ForceExclusiveFullscreen, bool SetWindow); void UpdatePresentParameterForMultisample(D3DPRESENT_PARAMETERS* pPresentationParameters, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD MultiSampleQuality);