D3D EndScene Hook dont work

Posts 1–9 of 9 · Page 1 of 1
D3D EndScene Hook dont work
Hey, this is the source of purple.d1amonds d3d9 Hook Tutorial.
I inject the .dll in the wow process, but nothing happend. Can anyone say me where the error is please ? The .dll is successfully loading, i have test it with a messagebox.

Code:
#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;
}


Thanks

N1GHTLIFE
Just a guess, could be other errors as well:

Code:
hModule = GetModuleHandleA("d3d9.dll");
Maybe it hasnt loaded when you inject. Try:

Code:
while(!hModule){
hModule = GetModuleHandleA("d3d9.dll");
}
Thanks for answer, but the .dll loaded successfully , i tried it with a messagebox at the end of the InitHook function .

Regards
is it possible that wow don´t use d3d9 ? It whoud be nice if anyone of you can test it with another game

offtopic: Where is the Edit button ?! ;D

Regards.
You're not drawing the rect


you confuse me , how do you mean this ? I draw the rect in the hooked endscene funktion:

Code:
bool hkEndScene(LPDIRECT3DDEVICE9 pDevice){

const D3DCOLOR txtPink = D3DCOLOR_ARGB(255,255, 0, 255);

DrawRect( pDevice, 10, 10, 200, 200, txtPink);

return pEndScene(pDevice);

 }
Or not oO ?

Regards
Quote Originally Posted by inmate View Post


you confuse me , how do you mean this ? I draw the rect in the hooked endscene funktion:

Code:
bool hkEndScene(LPDIRECT3DDEVICE9 pDevice){

const D3DCOLOR txtPink = D3DCOLOR_ARGB(255,255, 0, 255);

DrawRect( pDevice, 10, 10, 200, 200, txtPink);

return pEndScene(pDevice);

 }
Or not oO ?

Regards
This is the drawrect you use:
Code:
void DrawRect(LPDIRECT3DDEVICE9 Device_t, int X, int Y, int L, int H, D3DCOLOR color)
{

	D3DRECT rect = {X,Y,X+L,Y+H};

}
All that does is a make D3DRECT rect with the width/length height and stuff, not actually draw it.

Here's are DrawRect and DrawFilledRect that I use(written from memory, i'll check for you later)

Code:
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
}
Call InitializeD3DCrap() somewhere after the device has been made(and only once), then you can use DrawRect and DrawFilledRect
Quote Originally Posted by inmate View Post


you confuse me , how do you mean this ? I draw the rect in the hooked endscene funktion:

Code:
bool hkEndScene(LPDIRECT3DDEVICE9 pDevice){

const D3DCOLOR txtPink = D3DCOLOR_ARGB(255,255, 0, 255);

DrawRect( pDevice, 10, 10, 200, 200, txtPink);

return pEndScene(pDevice);

 }
Or not oO ?

Regards
You need to make your DrawRect Function sir .
Ahhh damn ok i understand

Okay hmm but why is this don´t work:

Code:
#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;
}
I think the messagebox must be pop up. but it dont work :-/...
Posts 1–9 of 9 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us