3 TraceDirect3DSwapChain9::TraceDirect3DSwapChain9(IDirect3DSwapChain9* pOriginal, IDirect3DDevice9* pDevice) {
4 m_pIDirect3DSwapChain9 = pOriginal; // store the pointer to original object
5 m_pIDirect3DDevice9 = pDevice;
8 TraceDirect3DSwapChain9::~TraceDirect3DSwapChain9(void) {
9 m_pIDirect3DSwapChain9 = NULL;
12 HRESULT TraceDirect3DSwapChain9::QueryInterface(REFIID riid, void** ppvObj) {
13 // check if original dll can provide interface. then send *our* address
16 HRESULT hRes = m_pIDirect3DSwapChain9->QueryInterface(riid, ppvObj);
18 if (hRes == NOERROR) {
25 ULONG TraceDirect3DSwapChain9::AddRef(void) {
26 return (m_pIDirect3DSwapChain9->AddRef());
29 ULONG TraceDirect3DSwapChain9::Release(void) {
30 // ATTENTION: This is a booby-trap ! Watch out !
31 // If we create our own sprites, surfaces, etc. (thus increasing the ref counter
32 // by external action), we need to delete that objects before calling the original
36 extern TraceDirect3DSwapChain9* gl_pmyIDirect3DSwapChain9;
38 // release/delete own objects
41 // Calling original function now
42 ULONG count = m_pIDirect3DSwapChain9->Release();
45 // now, the Original Object has deleted itself, so do we here
46 gl_pmyIDirect3DSwapChain9 = NULL;
47 delete (this); // destructor will be called automatically
53 HRESULT TraceDirect3DSwapChain9::Present(CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion,DWORD dwFlags)
55 // Some games use this one for presenting. They ignore the Device's present routine
57 // we may want to draw own things here before flipping surfaces
58 // ... draw own stuff ...
59 this->ShowWeAreHere();
61 // call original routine
62 HRESULT hres = m_pIDirect3DSwapChain9->Present(pSourceRect,pDestRect,hDestWindowOverride,pDirtyRegion,dwFlags);
67 HRESULT TraceDirect3DSwapChain9::GetFrontBufferData(IDirect3DSurface9* pDestSurface) {
68 return (m_pIDirect3DSwapChain9->GetFrontBufferData(pDestSurface));
71 HRESULT TraceDirect3DSwapChain9::GetBackBuffer(UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9** ppBackBuffer) {
72 return (m_pIDirect3DSwapChain9->GetBackBuffer(iBackBuffer, Type, ppBackBuffer));
75 HRESULT TraceDirect3DSwapChain9::GetRasterStatus(D3DRASTER_STATUS* pRasterStatus) {
76 return (m_pIDirect3DSwapChain9->GetRasterStatus(pRasterStatus));
79 HRESULT TraceDirect3DSwapChain9::GetDisplayMode(D3DDISPLAYMODE* pMode) {
80 return (m_pIDirect3DSwapChain9->GetDisplayMode(pMode));
83 HRESULT TraceDirect3DSwapChain9::GetDevice(IDirect3DDevice9** ppDevice) {
84 return (m_pIDirect3DSwapChain9->GetDevice(ppDevice));
87 HRESULT TraceDirect3DSwapChain9::GetPresentParameters(D3DPRESENT_PARAMETERS* pPresentationParameters) {
88 return (m_pIDirect3DSwapChain9->GetPresentParameters(pPresentationParameters));
91 // This is our test function
92 void TraceDirect3DSwapChain9::ShowWeAreHere(void) {
93 D3DRECT rec = { 100, 1, 150, 50 };
94 m_pIDirect3DDevice9->Clear(1, &rec, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 255, 255, 0), 0, 0);