#include <Windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
void Main()
{
}
DWORD * FindDevice(VOID)//Finds the Device on Injection
{
DWORD Base = (DWORD)LoadLibraryW(L"d3d9.dll");
for(DWORD i = 0; i < 0x128000; i++ )
{
if ( (*(BYTE *)(Base+i+0x00))==0xC7
&& (*(BYTE *)(Base+i+0x01))==0x06
&& (*(BYTE *)(Base+i+0x06))==0x89
&& (*(BYTE *)(Base+i+0x07))==0x86
&& (*(BYTE *)(Base+i+0x0C))==0x89
&& (*(BYTE *)(Base+i+0x0D))==0x86 )
return (DWORD *)(Base + i + 2);
}
return NULL;
}
typedef HRESULT(WINAPI *tPresent)(LPDIRECT3DDEVICE9 pDevice, const RECT *a, const RECT *b, HWND c, const RGNDATA *d);
tPresent oPresent;
HRESULT WINAPI Present(LPDIRECT3DDEVICE9 pDevice, const RECT *a, const RECT *b, HWND c, const RGNDATA *d)
{
_asm pushad
Main();
_asm popad;
return oPresent(pDevice, a, b, c, d);
}
void* DetourFunction( BYTE* source, const BYTE* destination, const int length )
{
BYTE* jmp = ( BYTE* ) malloc( length + 5 );
DWORD dwBack;
VirtualProtect( source, length, PAGE_EXECUTE_READWRITE, &dwBack );
memcpy( jmp, source, length );
jmp += length;
jmp[ 0 ] = 0xE9;
*( DWORD* ) ( jmp + 1 ) = ( DWORD ) ( source + length - jmp ) - 5;
source[ 0 ] = 0xE9;
*( DWORD* ) ( source + 1 ) = ( DWORD ) ( destination - source ) - 5;
for( int i = 5; i < length; i++ )
{
source[ i ] = 0x90;
}
VirtualProtect( source, length, dwBack, &dwBack );
return( jmp - length );
}
void PresentHook(void)
{
DWORD* VtablePtr = FindDevice();
DWORD* VTable;
*(DWORD*)&VTable = *(DWORD*)VtablePtr;
if(VtablePtr)
{
oPresent = ( tPresent ) DetourFunction((BYTE*)VTable[17], (BYTE*)&Present,5);
}
}
bool IsGameReady()
{
if(GetModuleHandle(L"WarRock.exe") != NULL
&& GetModuleHandle(L"d3d9.dll") != NULL);
return true;
return false;
}
DWORD WINAPI Hook(LPVOID)
{
while(!IsGameReady())
Sleep(250);
PresentHook();
return 0;
}
BOOL APIENTRY DllMain ( HMODULE hDll, DWORD dwReason, LPVOID lpReserved )
{
DisableThreadLibraryCalls(hDll);
if(dwReason == DLL_PROCESS_ATTACH) {
CreateThread(NULL, NULL,(LPTHREAD_START_ROUTINE)Hook, NULL, NULL, NULL);
}
return true;
}