Device Pointer

Posts 16–24 of 24 · Page 2 of 2
O' Lawdy Can you post the whole Code
I already did...here it is again:
Code:
#include <windows.h>
#include "Detour.h"
#include <d3d9.h>

typedef HRESULT(__stdcall* Real_EndScene)(LPDIRECT3DDEVICE9);
Real_EndScene oEndScene = NULL;

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] = 0x90; //50
src[1] = 0x90; // 58
src[2] = 0xE9;
*(DWORD*)(&src[3]) = (DWORD)(dst - src) - 7;
for (int i=7; i<len; i++) src[i] = 0x90;
VirtualProtect(src, len, dwBack, &dwBack);
return (jmp-len);
}

HRESULT __stdcall hook_EndScene(LPDIRECT3DDEVICE9 pDevice)
{
	MessageBox(NULL,"Hooked","Hooked",MB_OK);
	pDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);
	return oEndScene(pDevice);
}

DWORD GetPointerDereference(int index)
{
	DWORD *DevicePointer = **(DWORD***)0x01C8ED88;
	return DevicePointer[index];
}

DWORD GetPointerInlineAssembly(int index)
{
	DWORD DevicePointer = 0x01C8ED88;
	__asm
	{
		mov eax,[DevicePointer]
		mov ebx,[eax]
		mov ecx,[ebx]
		mov eax,index
		mov ebx,4
		mul ebx
		mov edx,[ecx+eax]
		mov DevicePointer,edx
	}
return DevicePointer;
}

void Hook()
{
	while(!GetModuleHandle("d3d9.dll"))
	{
		Sleep(100);
	}
	while( *(DWORD*)0x01C8ED88 == 0)
	{
		Sleep(100);
	}
	oEndScene = (Real_EndScene)DetourFunc((PBYTE)GetPointerInlineAssembly(42),(PBYTE)hook_EndScene,5);
}

bool __stdcall DllMain(HINSTANCE hInstance,DWORD reason, void* useless)
{
if(reason == DLL_PROCESS_ATTACH)
	{
	CreateThread(0,0,(LPTHREAD_START_ROUTINE)Hook,0,0,0);
	}
if(reason == DLL_PROCESS_DETACH)
	{
	}
return true;
}
Hmmm... I think I know what's wrong. When you created the project did you have precompiled header checked?
Quote Originally Posted by whit View Post
i dont know who first thought of Hooking via Device Pionter
where did u get that code?
Quote Originally Posted by user590177 View Post


where did u get that code?
What do you mean where i got it ?
I typed it up myself
My project was empty.
I chose Empty Project

This code is copy and pasted from Void's tutorial. I want to get it to work first before I actually start learning from it.
I resolved the issue, please close.
Posts 16–24 of 24 · Page 2 of 2
This thread is closed for replies.

Tags for this Thread

None

Need help?