Compile as Dll.
Inject with Winject into a game maker game.
[huge code]
[codebox]// d3dhook.cpp : Defines the entry point for the console application.
//
#define msg(text) MessageBoxW(0,text,L"D3DHOOK",0)
#include "stdafx.h"
#include <windows.h>
#include "define.h"
#include <detours.h>
#include <d3d8.h>
#pragma comment(lib,"detours.lib")
#pragma comment(lib,"d3d8.lib")
void HookCreateDevice();
void HookDirect3DCreate8();
IDirect3D8* g_interface;
IDirect3DDevice8* g_device;
IDirect3D8* (__stdcall *oDirect3DCreate8)(UINT version);
IDirect3D8* __stdcall hkDirect3DCreate8(UINT version)
{
__asm nop;
MessageBox(0,L"D3DCreate8 called -- d3dhook",L"D3DHOOK",0);
g_interface = oDirect3DCreate8(version);
HookCreateDevice();
return g_interface;
}
HRESULT (__stdcall *oCreateDevice)(IDirect3D8* me,UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DDevice8 **ppReturnedDeviceInterface);
HRESULT __stdcall hkCreateDevice(IDirect3D8* me,UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DDevice8 **ppReturnedDeviceInterface)
{
__asm nop;
MessageBox(0,L"CreateDevice()called! -- d3dhook",L"D3DHOOK",0);
HRESULT hr = oCreateDevice(me,Adapter,DeviceType,hFocusWindow,B
ehaviorFla
gs,pPresentationParameters,ppReturnedDeviceInterfa
c
e);
g_device = *ppReturnedDeviceInterface;
return hr;
}
void HookDirect3DCreate8()
{
MessageBox(0,L"HookingDirect3DCreate8",L"D3DHOOK",0);
oDirect3DCreate8 = (IDirect3D8 *(__stdcall *)(UINT))DetourFunction((PBYTE)GetProcAddress(Load
Library(L"d3d8.dll"),"Direct3DCreate8"),(PBYTE)hkDirect3DCreate8);
}
void HookCreateDevice()
{
MessageBox(0,L"Hooking CreateDevice() now",L"D3DHOOK",0);
DWORD* pdwNewInterface = (DWORD*)g_interface;
pdwNewInterface = (DWORD*)pdwNewInterface[0];
MessageBox(0,L"PEnter to Install Hook",L"",0);
oCreateDevice =(HRESULT (__stdcall *)(IDirect3D8 *,UINT,D3DDEVTYPE,HWND,DWORD,D3DPRESENT_PARAMETERS *,IDirect3DDevice8 **)) DetourFunction((PBYTE)pdwNewInterface[15],(PBYTE)h
kCreateDevice);
}
/*
*
*
*
* DLLMAIN
*
*
*
*/
bool __stdcall DllMain(HMODULE hHand,DWORD dwReason,LPVOID lpReserved)
{
switch(dwReason)
{
case DLL_PROCESS_ATTACH:
//DisableThreadLibraryCalls(hHand);
MessageBox(0,L"Hook Injected",L"D3DHOOK",0);
HookDirect3DCreate8();
//HookCreateDevice();
case DLL_PROCESS_DETACH:
//MessageBoxW(0,L"Exit",L"Exit",0);
GetForegroundWindow();
}
return TRUE;
}[/codebox]
[/huge code]
[Edit]Updated to use code-box
Edited by freaked, 24 February 2009 - 09:57 AM.