Hello,
I would first like to say that I have checked the forum for some time and also google so don't give me "google is your friend" and stuff like that.
I'm trying to hook EndScene function so that I can continue with calling of FrameBuffer etc. The problem I have is that my endscene hook never gets fired, I have tried alot of different codes from all kinds of sources including alot from this forum. I now ask for your help to sort this out.
I am kind of a noob in ASM and my code will probably hurt your eyes, if you can't stand it, press the back button and read another thread.
Heres my code:
Getting EndScene function from VTable:
Code:
void Memory::GetDirectX9EndScene(HWND hWnd)
{ // hWnd is my window I create inside my DLL and is valid.
D3DPRESENT_PARAMETERS d3dpp;
LPDIRECT3DDEVICE9 d3dDevice;
LPDIRECT3D9 d3d;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3d = Direct3DCreate9(D3D_SDK_VERSION);
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;
d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3dDevice);
pVTable = (u32*)*((u32*)d3dDevice); // unsigned int*
pEndScene = (void*)pVTable[42]; // void*
// I already know I don't clean up after myself but don't need you to tell me that :)
}
My hook function that never gets fired:
Code:
HRESULT WINAPI EndScene_Hook(IDirect3DDevice9 *pDevice)
{
MessageBox(0, "", "", MB_OK);
return EndScene_Orig(pDevice); // Yes, I know this isn't set to anything
}
How I try to install my hook:
Code:
bool Memory::InstallEndSceneHook()
{
BYTE* bCode = new BYTE[5];
memset(bCode, 0x90, 5);
DWORD dwFunc = (DWORD)EndScene_Hook - ((DWORD)pEndScene + 5);
bCode[0] = 0xE9; // JMP
*(DWORD*)&bCode[1] = dwFunc;
DWORD dwOld;
if(!VirtualProtect((void*)pEndScene, 5, PAGE_READWRITE, &dwOld))
return false;
memcpy((void*)pEndScene, (void*)bCode, 5);
VirtualProtect((void*)pEndScene, 5, dwOld, &dwOld);
return true;
}
Any help is very much appreciated
.