D3D9 Test [EndScene don't work]

Posts 1–4 of 4 · Page 1 of 1
D3D9 Test [EndScene don't work]
Hey guys i have a problem with the endscene...

That's my code:

Code:
#pragma once
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
#include <windows.h>
#include <cstdio>
#include <d3d9.h>
#include <d3dx9.h>

typedef HRESULT(__stdcall* EndScene_t)(LPDIRECT3DDEVICE9);
EndScene_t pEndScene;

void *DetourFunc(BYTE *src, const BYTE *dst, const int len) // credits to *************
{
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);
}

const D3DCOLOR txtPink = D3DCOLOR_ARGB(255, 255, 0, 255); // Alpha, Rot, Grün, Blau

void DrawRect (LPDIRECT3DDEVICE9 Device_t, int X, int Y, int L, int H, D3DCOLOR color)
{
D3DRECT rect = {X, Y, X+L, Y+H};
Device_t->Clear(1, &rect, D3DCLEAR_TARGET, color, 0, 0); // bei Google gibt’s näheres
}








HRESULT __stdcall hkEndScene(LPDIRECT3DDEVICE9 pDevice) 
{
	DrawRect ( pDevice, 10, 10, 200, 200, txtPink);
	return pEndScene(pDevice);
}

void InitHook()
{
	HMODULE hModule = NULL;
	while( !hModule )
	{
		hModule = GetModuleHandleA( "d3d9.dll" ); // Handle zur DLL holen
		Sleep( 100 ); // 100ms warten
	}
	pEndScene = ( EndScene_t )DetourFunc((PBYTE) 0x71a8d507,(PBYTE)hkEndScene, 5);
}

int WINAPI DllMain(HINSTANCE hInst,DWORD reason,LPVOID reserved)
{
 switch(reason)
 {
 case DLL_PROCESS_ATTACH:
	CreateThread(0, 0, (LPTHREAD_START_ROUTINE) InitHook, 0, 0, 0);
 break;
 }
 return true;
}

I use the detourfunction from *************.
why this doesnt work, I TESTED IT ON A D3D9 TEST ENVIRONMENT

The whole problem is the rect wont drawn
This address is incorrect EndScene ...
Code:
pEndScene = ( EndScene_t )DetourFunc((PBYTE) 0x71a8d507,(PBYTE)hkEndScene, 5);
Using a static address like this for hooking EndScene is your problem. Given that you are just copy pasting is probably the other part of the problem.
Quote Originally Posted by atom0s View Post
Code:
pEndScene = ( EndScene_t )DetourFunc((PBYTE) 0x71a8d507,(PBYTE)hkEndScene, 5);
Using a static address like this for hooking EndScene is your problem. Given that you are just copy pasting is probably the other part of the problem.
Its already solve I use now vTables
Posts 1–4 of 4 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us