MW2 Hooking
Ok, I have this working D3D Hook for MW2:
The red code, is the pointer to EndScene, which I obtained by opening d3d9.dll in my System32 folder. I attempted using the device pointer in Hell_Demon's tutorial. I found it, implemented it, and it crashed.
Is there a difference between using the DevicePointer and the EndScene address I found in the dll? When should I use a certain method?
Code:
#include <windows.h>
#include <d3d9.h>
#include "detours.h"
#pragma comment(lib,"detours.lib")
#pragma comment(lib,"d3d9.lib")
typedef HRESULT(__stdcall* Real_EndScene)(LPDIRECT3DDEVICE9);
Real_EndScene oEndScene = NULL;
const D3DCOLOR textRed = D3DCOLOR_ARGB(255, 255, 0, 0);
void DrawRect (LPDIRECT3DDEVICE9 pDevice, int X, int Y, int L, int H, D3DCOLOR color)
{
D3DRECT rect = {X, Y, X+L, Y+H};
pDevice->Clear(1, &rect, D3DCLEAR_TARGET, color, 0, 0);
}
HRESULT __stdcall hook_EndScene(LPDIRECT3DDEVICE9 pDevice)
{
DrawRect(pDevice, 10, 10, 20, 20, textRed);
return oEndScene(pDevice);
}
void Hook()
{
while(!GetModuleHandle("d3d9.dll"))
{
Sleep(100);
}
while( *(DWORD*)0x4FE571B0 == 0)
{
Sleep(100);
}
MessageBox(NULL,L"Hooked",L"Successful",0);
oEndScene = (Real_EndScene)DetourFunction((PBYTE)0x4FE571B0,(PBYTE)hook_EndScene);
}
bool __stdcall DllMain(HINSTANCE hInstance,DWORD reason, void* useless)
{
if(reason == DLL_PROCESS_ATTACH)
{
CreateThread(0,0,(LPTHREAD_START_ROUTINE)Hook,0,0,0);
}
if(reason == DLL_PROCESS_DETACH)
{
}
return true;
}
Is there a difference between using the DevicePointer and the EndScene address I found in the dll? When should I use a certain method?


