#include "stdafx.h"
#include <windows.h>
#include <cstdio>
#include <d3d9.h>
#include <d3dx9.h>
typedef HRESULT(__stdcall* EndScene_t)(LPDIRECT3DDEVICE9);
EndScene_t pEndScene;
void DrawRect(LPDIRECT3DDEVICE9 Device_t, int X, int Y, int L, int H, D3DCOLOR color){
D3DRECT rect = {X,Y,X+L,Y+H};
}
bool hkEndScene(LPDIRECT3DDEVICE9 pDevice){
const D3DCOLOR txtPink = D3DCOLOR_ARGB(255,255, 0, 255);
DrawRect( pDevice, 10, 10, 200, 200, txtPink);
return pEndScene(pDevice);
}
void* DetourFunc(BYTE *src, const BYTE *dst, const int len)
{
BYTE *jmp = (BYTE*)malloc(len+5);
DWORD dwback;
VirtualProtect(src, len, PAGE_READWRITE, &dwback);
memcpy(jmp, src, len); jmp += len;
jmp[0] = 0xE9;
*(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;
src[0] = 0xE9;
*(DWORD*)(src+1) = (DWORD)(dst - src) - 5;
VirtualProtect(src, len, dwback, &dwback);
return (jmp-len);
}
void InitHook()
{
HMODULE hModule;
hModule = GetModuleHandleA("d3d9.dll");
unsigned dwBeginScene;
unsigned dwEndScene;
unsigned dwReset;
unsigned dwDrawIndexedPrimitive;
unsigned dwSetViewPort;
dwBeginScene = (DWORD)hModule + 0x87010;
dwEndScene = (DWORD)hModule + 0x871A0;
dwReset = (DWORD)hModule + 0x636B0;
dwDrawIndexedPrimitive = (DWORD)hModule + 0x88830;
dwSetViewPort = (DWORD)hModule + 0x82F70 ;
pEndScene = (EndScene_t)(DetourFunc((PBYTE)dwEndScene,(PBYTE)hkEndScene, 5));
MessageBoxA(NULL, "Funktion wurde aufgerufen","Done",NULL);
}
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, LPVOID lpvReserved)
{
if (fdwReason == DLL_PROCESS_ATTACH)
{
CreateThread(0,0,(LPTHREAD_START_ROUTINE) InitHook,0,0,0);
}
return TRUE;
}

hModule = GetModuleHandleA("d3d9.dll");
while(!hModule){
hModule = GetModuleHandleA("d3d9.dll");
}
.

bool hkEndScene(LPDIRECT3DDEVICE9 pDevice){
const D3DCOLOR txtPink = D3DCOLOR_ARGB(255,255, 0, 255);
DrawRect( pDevice, 10, 10, 200, 200, txtPink);
return pEndScene(pDevice);
}
void DrawRect(LPDIRECT3DDEVICE9 Device_t, int X, int Y, int L, int H, D3DCOLOR color)
{
D3DRECT rect = {X,Y,X+L,Y+H};
}
ID3DXLine *pLine = NULL;
void DrawRect(int X, int Y, int Width, int Height, D3DCOLOR col)
{
D3DXVECTOR2 rect[5] = { {X, Y}, {X+Width, Y}, {X+Width, Y+Height}, {X, Y+Height}, {X, Y}};
pLine->Begin();
pLine->Draw(rect, 5, col);
pLine->End();
}
void DrawFilledRect(int X, int Y, int Width, int Height, D3DCOLOR col)
{
D3DXVECTOR2 rect[2] = { {X+Width/2, Y}, {X+Width/2, Y+Height} };
pLine->SetWidth((float)Width);
pLine->Begin();
pLine->Draw(rect, 2, col);
pLine->End();
pLine->SetWidth(1.0f);
}
void InitializeD3DCrap(void)
{
D3DXCreateLine( pDevice, &pLine );
pLine->SetWidth(1.0f);
pLine->SetPattern(0xFFFFFFFF); //solid line
pLine->SetAntialias(false); //increases speed
pLine->SetGLLines(true); //increases speed
}

#include "stdafx.h"
#include <windows.h>
#include <cstdio>
#include <d3d9.h>
#include <d3dx9.h>
typedef HRESULT(__stdcall* EndScene_t)(LPDIRECT3DDEVICE9);
EndScene_t pEndScene;
bool hkEndScene(LPDIRECT3DDEVICE9 pDevice){
MessageBoxA(NULL, "function successfully called","Done",NULL); // <- This messagebox
return pEndScene(pDevice);
}
void* DetourFunc(BYTE *src, const BYTE *dst, const int len)
{
BYTE *jmp = (BYTE*)malloc(len+5);
DWORD dwback;
VirtualProtect(src, len, PAGE_READWRITE, &dwback);
memcpy(jmp, src, len); jmp += len;
jmp[0] = 0xE9;
*(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;
src[0] = 0xE9;
*(DWORD*)(src+1) = (DWORD)(dst - src) - 5;
VirtualProtect(src, len, dwback, &dwback);
return (jmp-len);
}
void InitHook()
{
HMODULE hModule;
hModule = GetModuleHandleA("d3d9.dll");
unsigned dwBeginScene;
unsigned dwEndScene;
unsigned dwReset;
unsigned dwDrawIndexedPrimitive;
unsigned dwSetViewPort;
dwBeginScene = (DWORD)hModule + 0x87010;
dwEndScene = (DWORD)hModule + 0x871A0;
dwReset = (DWORD)hModule + 0x636B0;
dwDrawIndexedPrimitive = (DWORD)hModule + 0x88830;
dwSetViewPort = (DWORD)hModule + 0x82F70 ;
pEndScene = (EndScene_t)(DetourFunc((PBYTE)dwEndScene,(PBYTE)hkEndScene, 5));
}
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, LPVOID lpvReserved)
{
if (fdwReason == DLL_PROCESS_ATTACH)
{
CreateThread(0,0,(LPTHREAD_START_ROUTINE) InitHook,0,0,0);
}
return TRUE;
}