Here is my hook.
Code:
//LoadLibrary("d3d9.dll");
D3DPRESENT_PARAMETERS d3dpp;
LPDIRECT3DDEVICE9 pd3dDevice;
IDirect3D9 *pd3dInterface = Direct3DCreate9(D3D_SDK_VERSION); //hooking Direct3DCreate9 to get the D3D9 interface pointer
ZeroMemory(&d3dpp,sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
HRESULT hr = pd3dInterface->CreateDevice( D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,GetForegroundWindow(),D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&pd3dDevice );
//hooking D3D9->CreateDevice to get the device pointer
LPDIRECT3DSWAPCHAIN9 pZdsd;
if (pd3dDevice->GetNumberOfSwapChains())
{
pd3dDevice->GetSwapChain(0,&pZdsd);
HookFunc(GetInterfaceFuncAddress((DWORD*)pZdsd,"%p",&IDirect3DDevice9::Present),SwapPresent)
SAFE_RELEASE(pZdsd)
}
HookFunc(GetInterfaceFuncAddress((DWORD*)pd3dDevice,"%p",&IDirect3DDevice9::Present),Present);
HookFunc(GetInterfaceFuncAddress((DWORD*)pd3dDevice,"%p",&IDirect3DDevice9::Reset),Reset)