HelpD3D Hook error Compiling

Posts 1–7 of 7 · Page 1 of 1
D3D Hook error Compiling
maincpp
Code:
//-----------------------------------------------------------------------------------------------------------------------------------
/****************************************************************
Coded by: JoshRose
Type: D3D VTable Base Hook
Credits: Strife, R4z8r, Zoomgod, Roverturbo and MSDN. Thanks all
for helping me when i got stuck.
****************************************************************/
//----------------------------------------------------------------------------------------------------------------------------------
#include <windows.h>
//----------------------------------------------------------------------------------------------------------------------------------
#include "Main.h"
//-----------------------------------------------------------------------------------------------------------------------------------
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")
//-----------------------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
//-----------------------------------------------------------------------------------------------------------------------------------
#include <fstream>
//-----------------------------------------------------------------------------------------------------------------------------------
#include "detours.h"
#pragma comment(lib,"detours.lib")
//-----------------------------------------------------------------------------------------------------------------------------------
#include <d3d9.h>
#include <d3dx9.h>
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
//-----------------------------------------------------------------------------------------------------------------------------------
using namespace std;
//---------------------------------------------------------------------------------------------------------------------------------
#define HOOK(func,addy) o##func = (t##func)DetourFunction((PBYTE)addy,(PBYTE)hk##func) //Quick Hook using MS Detour
#define UNHOOK(func,addy) o##func = (t##func)DetourFunction((PBYTE)addy,(PBYTE)o##func) //Quick Unook using MS Detour
//---------------------------------------------------------------------------------------------------------------------------------
#define ES  0 //EndScene
#define DIP 1 //DrawIndexedPrimitive
#define RES 2 //Reset
#define BS	3 //Beginscene
//---------------------------------------------------------------------------------------------------------------------------------
LPDIRECT3DDEVICE9 npDevice; //pDevice is stored here so we can hook through the VTable
//---------------------------------------------------------------------------------------------------------------------------------
LPD3DXFONT      g_pFont = NULL; //D3D Font
LPD3DXLINE      g_pLine = NULL; //D3D Line
D3DVIEWPORT9    g_ViewPort; //ViewPort

LPDIRECT3DTEXTURE9 texBlack;
//---------------------------------------------------------------------------------------------------------------------------------
LPDIRECT3DVERTEXBUFFER9 Stream_Data;
UINT Offset = 0;
UINT Stride = 0;

bool	bXHair	= false;
bool	bChams	= false;

//---------------------------------------------------------------------------------------------------------------------------------
ofstream myfile; //Used for logging to a text file
//---------------------------------------------------------------------------------------------------------------------------------

typedef HRESULT (WINAPI* tEndScene)(LPDIRECT3DDEVICE9 pDevice);
tEndScene oEndScene = NULL;

typedef HRESULT (WINAPI* tDrawIndexedPrimitive)(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount);
tDrawIndexedPrimitive oDrawIndexedPrimitive = NULL;

typedef HRESULT(WINAPI* BeginScene_)(LPDIRECT3DDEVICE9 pDevice);
BeginScene_ oBeginScene;

typedef HRESULT(WINAPI* tReset)(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters);
tReset oReset = NULL;
//---------------------------------------------------------------------------------------------------------------------------------
PBYTE HookVTableFunction( PDWORD* dwVTable, PBYTE dwHook, INT Index )
{
    DWORD dwOld = 0;
    VirtualProtect((void*)((*dwVTable) + (Index*4) ), 4, PAGE_EXECUTE_READWRITE, &dwOld);

    PBYTE pOrig = ((PBYTE)(*dwVTable)[Index]);
    (*dwVTable)[Index] = (DWORD)dwHook;

    VirtualProtect((void*)((*dwVTable) + (Index*4)), 4, dwOld, &dwOld);

    return pOrig;
}
void DrawXHair(LPDIRECT3DDEVICE9 pDevice, D3DCOLOR col)
{
	 D3DVIEWPORT9 gViewPort;
	 pDevice->GetViewport(&gViewPort);
	 long ScreenCenterX = ( long )gViewPort.Width / 2;//Horizontal Position
     long ScreenCenterY = ( long )gViewPort.Height / 2;//Vertical Position
	 D3DRECT rec2 = {ScreenCenterX-10, ScreenCenterY, ScreenCenterX+ 10, ScreenCenterY+2};
     D3DRECT rec3 = {ScreenCenterX, ScreenCenterY-10, ScreenCenterX+ 2,ScreenCenterY+10};
								
	   pDevice->Clear(1, &rec2, D3DCLEAR_TARGET,col, 0,  0);
	   pDevice->Clear(1, &rec3, D3DCLEAR_TARGET,col, 0,  0);

}
 
//-----------------------------------------------------------------------------------------------------------------------------------

HRESULT WINAPI hkEndScene(LPDIRECT3DDEVICE9 pDevice)
{
    myfile << "EndScene is hooked\n";             //Check log
    while(!npDevice) {
        npDevice = pDevice;                       //Here we store pDevice so we can re-hook with a VTable hook later.
    }

                                                  
    if(g_pFont == NULL) D3DXCreateFontA(pDevice, 15, 0, FW_BOLD, 1, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Verdana", &g_pFont); //Create fonts
                                                  
    if(g_pLine == NULL) D3DXCreateLine(pDevice, &g_pLine); //Create lines

    pDevice->GetViewport(&g_ViewPort);
	
	if(GetAsyncKeyState(VK_DECIMAL)&1) 
{
	bXHair=!bXHair;
	bChams=!bChams;
}
	if( bXHair ){DrawXHair(pDevice,D3DCOLOR_XRGB( 255, 0, 0 ) );}

    return oEndScene(pDevice);
}
//---------------------------------------------------------------------------------------------------------------------------------
HRESULT WINAPI hkBeginScene(LPDIRECT3DDEVICE9 pDevice)
{
	myfile << "BeginScene is hooked\n";             //Check log
	
	if (bChams)
	{
		pDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE );
	}
	else
	{
		pDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE );
	}
	return oBeginScene(pDevice);
}
//---------------------------------------------------------------------------------------------------------------------------------
HRESULT WINAPI hkDrawIndexedPrimitive(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount)
{

    myfile << "DIP is hooked\n";                  //Check log
    if(pDevice->GetStreamSource(0, &Stream_Data, &Offset, &Stride) == D3D_OK)
        Stream_Data->Release();

    return oDrawIndexedPrimitive(pDevice, PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);

}
//---------------------------------------------------------------------------------------------------------------------------------
HRESULT WINAPI hkReset(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters)
{
    myfile << "Reset is hooked\n";                //Check log
    if( g_pFont )
        g_pFont->OnLostDevice();

    if( g_pLine )
        g_pLine->OnLostDevice();

    HRESULT iReturnValue = oReset(pDevice, pPresentationParameters);

    if(iReturnValue == D3D_OK) {

        if( g_pFont )
            g_pFont->OnResetDevice();

        if( g_pLine )
            g_pLine->OnResetDevice();
    }

    return iReturnValue;

}
//-----------------------------------------------------------------------------------------------------------------------------------
LRESULT CALLBACK MsgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam){return DefWindowProc(hwnd, uMsg, wParam, lParam);}
void DX_Init(DWORD* table)
{
    WNDCLASSEXA wc = {sizeof(WNDCLASSEX),CS_CLASSDC,MsgProc,0L,0L,GetModuleHandleA(NULL),NULL,NULL,NULL,NULL,"DX",NULL};
    RegisterClassExA(&wc);
    HWND hWnd = CreateWindowA("DX",NULL,WS_OVERLAPPEDWINDOW,100,100,300,300,GetDesktopWindow(),NULL,wc.hInstance,NULL);
    LPDIRECT3D9 pD3D = Direct3DCreate9( D3D_SDK_VERSION );
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory( &d3dpp, sizeof(d3dpp) );
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
    LPDIRECT3DDEVICE9 pd3dDevice;
    pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&pd3dDevice);
    DWORD* pVTable = (DWORD*)pd3dDevice;
    pVTable = (DWORD*)pVTable[0];

    table[ES]   = pVTable[42];                    //EndScene address
    table[DIP]  = pVTable[82];                    //DrawIndexedPrimitive address
    table[RES]  = pVTable[16];                    //Reset address
	table[BS]   = pVTable[41];                    //BeginScene address

    DestroyWindow(hWnd);
}
//------------------------------------------------------------------------------------------------------------------------------------
DWORD WINAPI VirtualMethodTableRepatchingLoopToCounterExtensionRepatching( LPVOID  Param )
{
    while(1) {
        Sleep(100);
        HookVTableFunction((PDWORD*)npDevice, (PBYTE)hkDrawIndexedPrimitive, 82); //Hook DrawIndexedPrimitive
        HookVTableFunction((PDWORD*)npDevice, (PBYTE)hkEndScene, 42); //Hook EndScene
        HookVTableFunction((PDWORD*)npDevice, (PBYTE)hkReset, 16); //Hook Reset
		HookVTableFunction((PDWORD*)npDevice, (PBYTE)hkBeginScene, 41); //Hook Beginscene

    }

    return 1;
}
//------------------------------------------------------------------------------------------------------------------------------------
bool hooked = false;
DWORD WINAPI LoopFunction( LPVOID lpParam  )
{

    while(1) {
        if( hooked == false) {
            DWORD VTable[3] = {0};

            while(GetModuleHandleA("d3d9.dll")==NULL) {
                Sleep(250);
            }

            DX_Init(VTable);
         HOOK(EndScene,VTable[ES]);            //Hook EndScene as a device discovery hook

            while(!npDevice) {
                Sleep(50); //Sleep until npDevice is not equal to NULL
            }
            UNHOOK(EndScene, VTable[ES]);         //Unhook as soon as we have a valid pointer to pDevice

            *(PDWORD)&oDrawIndexedPrimitive = VTable[DIP];
            *(PDWORD)&oEndScene				= VTable[ES];
            *(PDWORD)&oReset				= VTable[RES];
			*(PDWORD)&oBeginScene			= VTable[BS];

            CreateThread(NULL,0,&VirtualMethodTableRepatchingLoopToCounterExtensionRepatching,NULL,0,NULL); //Create hooking thread

            hooked = true;

            Sleep(200);

        }
    }
    return 0;
}
//------------------------------------------------------------------------------------------------------------------------------------
BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpvReserved)
{
    if(dwReason == DLL_PROCESS_ATTACH) {
        CreateThread(0, 0, LoopFunction, 0, 0, 0);
        myfile.open("c:\\D3DTest.log");
        myfile.clear();
        myfile << "----------Attached----------\n";
        myfile << "\n";
    }
    else if(dwReason == DLL_PROCESS_DETACH) {
        myfile << "----------Detached----------";
        myfile.close();
    }

    return TRUE;
}
error i get
Code:
1>------ Build started: Project: D3D MENU HACK, Configuration: Debug Win32 ------
1>  main.cpp
1>c:\users\keenny\documents\visual studio 2012\projects\d3d menu hack\d3d menu hack\main.cpp(223): error C3861: 'Detour': identifier not found
1>c:\users\keenny\documents\visual studio 2012\projects\d3d menu hack\d3d menu hack\main.cpp(228): error C3861: 'Detour': identifier not found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
where occurs
Code:
#define HOOK(func,addy) o##func = (t##func)DetourFunction((PBYTE)addy,(PBYTE)hk##func) //Quick Hook using MS Detour
#define UNHOOK(func,addy) o##func = (t##func)DetourFunction((PBYTE)addy,(PBYTE)o##func) //Quick Unook using MS Detour
Do you have everything properly set up with MS detours? You may need to include their location in your project settings. Also consider this is 3 years (or older) code and things might have changed by now if you are using a newer detour version.

Btw vtable hooks are detected I heard, you need to do midfunction hook.
Tente isso

detours.cpp
Code:
//GHBR - Creditos : Xpeeh, Luccss, Victor_Silent
//Whit(Base Original), Capevaldo, WE11ington

#include "Files.h"
#include "detours.h"

unsigned int iPointers[4] = {0xE9, 0x90, 0x68, 0xC3};

INT DetourASMlen(BYTE *src, INT minlen)
{
	__asm 
	{
		PUSHAD;
		NOP;
		MOV EAX, 1;
		NOP;
		POPAD;
	}

	INT i, len;

	__asm 
	{
		PUSHAD;
		NOP;
		MOV EAX, 1;
		NOP;
		POPAD;
	}

	for(len = 0; len < minlen; len += i) 
	{
		i = mlde32((VOID *)src);
		if(i <= 0)
			return 0;
		src += i;
	}

	__asm 
	{
		PUSHAD;
		NOP;
		MOV EAX, 1;
		NOP;
		POPAD;
	}

	return len;
}

VOID *DetourCreate(BYTE *src, CONST BYTE *dst, INT minlen)
{
	__asm 
	{
		PUSHAD;
		NOP;
		MOV EAX, 1;
		NOP;
		POPAD;
	}

	BYTE *jmp, *org;
	DWORD dwBack;
	INT len;

	__asm 
	{
		PUSHAD;
		NOP;
		MOV EAX, 1;
		NOP;
		POPAD;
	}

	len = DetourASMlen(src, (minlen < 6)?6:minlen);
	if(len == 0 && minlen >= 6)
		len = minlen;
	if(len == 0)
		return 0;

	__asm 
	{
		PUSHAD;
		NOP;
		MOV EAX, 1;
		NOP;
		POPAD;
	}

	org = jmp = (BYTE *)malloc(len + 5 + 1);
    jmp[0] = len;
    jmp++;

	__asm 
	{
		PUSHAD;
		NOP;
		MOV EAX, 1;
		NOP;
		POPAD;
	}
	
	VirtualProtect(src, len, PAGE_EXECUTE_READWRITE, &dwBack);
	memcpy(jmp, src, len);	
	jmp += len;
	jmp[0] = iPointers[0];
	*(DWORD *)(jmp + 1) = (DWORD)(src + len - jmp) - 5;
	
	__asm 
	{
		PUSHAD;
		NOP;
		MOV EAX, 1;
		NOP;
		POPAD;
	}

	src[0] = iPointers[2];
	*(DWORD *)(src + 1) = (DWORD)(dst);
	src[5] = iPointers[3];
	for(INT i = 6; i < len; i++)
		src[i] = iPointers[1];
	VirtualProtect(src, len, dwBack, &dwBack);

	__asm 
	{
		PUSHAD;
		NOP;
		MOV EAX, 1;
		NOP;
		POPAD;
	}
	
	return &org[1];
}

VOID DetourRemove(BYTE *src, BYTE *restore, INT len)
{
	DWORD dwBack;

	len = *(BYTE *)(restore - 1);

	VirtualProtect(src, len, PAGE_EXECUTE_READWRITE, &dwBack);
	memcpy(src, restore, len);
	restore[0] = iPointers[0];

	*(DWORD *)(restore + 1) = (DWORD)(src - restore) - 5;
	VirtualProtect(src, len, dwBack, &dwBack);
}

detours.h
Code:
//GHBR - Creditos : Xpeeh, Luccss, Victor_Silent
//Whit(Base Original), Capevaldo, WE11ington

#ifndef _DETOURS_H_
#define _DETOURS_H_

extern "C" INT __cdecl mlde32(VOID *codeptr);

INT   DetourLen(BYTE *src, INT minlen);
VOID *DetourCreate(BYTE *src, CONST BYTE *dst, CONST INT minlen = 0);
VOID  DetourRemove(BYTE *src, BYTE *restore, CONST INT len = 0);

#endif
Adicione os dois na base.
Quote Originally Posted by 6ixth View Post
Tente isso

detours.cpp
Code:
//GHBR - Creditos : Xpeeh, Luccss, Victor_Silent
//Whit(Base Original), Capevaldo, WE11ington

#include "Files.h"
#include "detours.h"

unsigned int iPointers[4] = {0xE9, 0x90, 0x68, 0xC3};

INT DetourASMlen(BYTE *src, INT minlen)
{
	__asm 
	{
		PUSHAD;
		NOP;
		MOV EAX, 1;
		NOP;
		POPAD;
	}

	INT i, len;

	__asm 
	{
		PUSHAD;
		NOP;
		MOV EAX, 1;
		NOP;
		POPAD;
	}

	for(len = 0; len < minlen; len += i) 
	{
		i = mlde32((VOID *)src);
		if(i <= 0)
			return 0;
		src += i;
	}

	__asm 
	{
		PUSHAD;
		NOP;
		MOV EAX, 1;
		NOP;
		POPAD;
	}

	return len;
}

VOID *DetourCreate(BYTE *src, CONST BYTE *dst, INT minlen)
{
	__asm 
	{
		PUSHAD;
		NOP;
		MOV EAX, 1;
		NOP;
		POPAD;
	}

	BYTE *jmp, *org;
	DWORD dwBack;
	INT len;

	__asm 
	{
		PUSHAD;
		NOP;
		MOV EAX, 1;
		NOP;
		POPAD;
	}

	len = DetourASMlen(src, (minlen < 6)?6:minlen);
	if(len == 0 && minlen >= 6)
		len = minlen;
	if(len == 0)
		return 0;

	__asm 
	{
		PUSHAD;
		NOP;
		MOV EAX, 1;
		NOP;
		POPAD;
	}

	org = jmp = (BYTE *)malloc(len + 5 + 1);
    jmp[0] = len;
    jmp++;

	__asm 
	{
		PUSHAD;
		NOP;
		MOV EAX, 1;
		NOP;
		POPAD;
	}
	
	VirtualProtect(src, len, PAGE_EXECUTE_READWRITE, &dwBack);
	memcpy(jmp, src, len);	
	jmp += len;
	jmp[0] = iPointers[0];
	*(DWORD *)(jmp + 1) = (DWORD)(src + len - jmp) - 5;
	
	__asm 
	{
		PUSHAD;
		NOP;
		MOV EAX, 1;
		NOP;
		POPAD;
	}

	src[0] = iPointers[2];
	*(DWORD *)(src + 1) = (DWORD)(dst);
	src[5] = iPointers[3];
	for(INT i = 6; i < len; i++)
		src[i] = iPointers[1];
	VirtualProtect(src, len, dwBack, &dwBack);

	__asm 
	{
		PUSHAD;
		NOP;
		MOV EAX, 1;
		NOP;
		POPAD;
	}
	
	return &org[1];
}

VOID DetourRemove(BYTE *src, BYTE *restore, INT len)
{
	DWORD dwBack;

	len = *(BYTE *)(restore - 1);

	VirtualProtect(src, len, PAGE_EXECUTE_READWRITE, &dwBack);
	memcpy(src, restore, len);
	restore[0] = iPointers[0];

	*(DWORD *)(restore + 1) = (DWORD)(src - restore) - 5;
	VirtualProtect(src, len, dwBack, &dwBack);
}

detours.h
Code:
//GHBR - Creditos : Xpeeh, Luccss, Victor_Silent
//Whit(Base Original), Capevaldo, WE11ington

#ifndef _DETOURS_H_
#define _DETOURS_H_

extern "C" INT __cdecl mlde32(VOID *codeptr);

INT   DetourLen(BYTE *src, INT minlen);
VOID *DetourCreate(BYTE *src, CONST BYTE *dst, CONST INT minlen = 0);
VOID  DetourRemove(BYTE *src, BYTE *restore, CONST INT len = 0);

#endif
Adicione os dois na base.
omg thanks man i owe you
Quote Originally Posted by super*eagle View Post
maincpp
Code:
//-----------------------------------------------------------------------------------------------------------------------------------
/****************************************************************
Coded by: JoshRose
Type: D3D VTable Base Hook
Credits: Strife, R4z8r, Zoomgod, Roverturbo and MSDN. Thanks all
for helping me when i got stuck.
****************************************************************/
//----------------------------------------------------------------------------------------------------------------------------------
#include <windows.h>
//----------------------------------------------------------------------------------------------------------------------------------
#include "Main.h"
//-----------------------------------------------------------------------------------------------------------------------------------
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")
//-----------------------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
//-----------------------------------------------------------------------------------------------------------------------------------
#include <fstream>
//-----------------------------------------------------------------------------------------------------------------------------------
#include "detours.h"
#pragma comment(lib,"detours.lib")
//-----------------------------------------------------------------------------------------------------------------------------------
#include <d3d9.h>
#include <d3dx9.h>
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
//-----------------------------------------------------------------------------------------------------------------------------------
using namespace std;
//---------------------------------------------------------------------------------------------------------------------------------
#define HOOK(func,addy) o##func = (t##func)DetourFunction((PBYTE)addy,(PBYTE)hk##func) //Quick Hook using MS Detour
#define UNHOOK(func,addy) o##func = (t##func)DetourFunction((PBYTE)addy,(PBYTE)o##func) //Quick Unook using MS Detour
//---------------------------------------------------------------------------------------------------------------------------------
#define ES  0 //EndScene
#define DIP 1 //DrawIndexedPrimitive
#define RES 2 //Reset
#define BS    3 //Beginscene
//---------------------------------------------------------------------------------------------------------------------------------
LPDIRECT3DDEVICE9 npDevice; //pDevice is stored here so we can hook through the VTable
//---------------------------------------------------------------------------------------------------------------------------------
LPD3DXFONT      g_pFont = NULL; //D3D Font
LPD3DXLINE      g_pLine = NULL; //D3D Line
D3DVIEWPORT9    g_ViewPort; //ViewPort

LPDIRECT3DTEXTURE9 texBlack;
//---------------------------------------------------------------------------------------------------------------------------------
LPDIRECT3DVERTEXBUFFER9 Stream_Data;
UINT Offset = 0;
UINT Stride = 0;

bool    bXHair    = false;
bool    bChams    = false;

//---------------------------------------------------------------------------------------------------------------------------------
ofstream myfile; //Used for logging to a text file
//---------------------------------------------------------------------------------------------------------------------------------

typedef HRESULT (WINAPI* tEndScene)(LPDIRECT3DDEVICE9 pDevice);
tEndScene oEndScene = NULL;

typedef HRESULT (WINAPI* tDrawIndexedPrimitive)(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount);
tDrawIndexedPrimitive oDrawIndexedPrimitive = NULL;

typedef HRESULT(WINAPI* BeginScene_)(LPDIRECT3DDEVICE9 pDevice);
BeginScene_ oBeginScene;

typedef HRESULT(WINAPI* tReset)(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters);
tReset oReset = NULL;
//---------------------------------------------------------------------------------------------------------------------------------
PBYTE HookVTableFunction( PDWORD* dwVTable, PBYTE dwHook, INT Index )
{
    DWORD dwOld = 0;
    VirtualProtect((void*)((*dwVTable) + (Index*4) ), 4, PAGE_EXECUTE_READWRITE, &dwOld);

    PBYTE pOrig = ((PBYTE)(*dwVTable)[Index]);
    (*dwVTable)[Index] = (DWORD)dwHook;

    VirtualProtect((void*)((*dwVTable) + (Index*4)), 4, dwOld, &dwOld);

    return pOrig;
}
void DrawXHair(LPDIRECT3DDEVICE9 pDevice, D3DCOLOR col)
{
     D3DVIEWPORT9 gViewPort;
     pDevice->GetViewport(&gViewPort);
     long ScreenCenterX = ( long )gViewPort.Width / 2;//Horizontal Position
     long ScreenCenterY = ( long )gViewPort.Height / 2;//Vertical Position
     D3DRECT rec2 = {ScreenCenterX-10, ScreenCenterY, ScreenCenterX+ 10, ScreenCenterY+2};
     D3DRECT rec3 = {ScreenCenterX, ScreenCenterY-10, ScreenCenterX+ 2,ScreenCenterY+10};
                                
       pDevice->Clear(1, &rec2, D3DCLEAR_TARGET,col, 0,  0);
       pDevice->Clear(1, &rec3, D3DCLEAR_TARGET,col, 0,  0);

}
 
//-----------------------------------------------------------------------------------------------------------------------------------

HRESULT WINAPI hkEndScene(LPDIRECT3DDEVICE9 pDevice)
{
    myfile << "EndScene is hooked\n";             //Check log
    while(!npDevice) {
        npDevice = pDevice;                       //Here we store pDevice so we can re-hook with a VTable hook later.
    }

                                                  
    if(g_pFont == NULL) D3DXCreateFontA(pDevice, 15, 0, FW_BOLD, 1, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Verdana", &g_pFont); //Create fonts
                                                  
    if(g_pLine == NULL) D3DXCreateLine(pDevice, &g_pLine); //Create lines

    pDevice->GetViewport(&g_ViewPort);
    
    if(GetAsyncKeyState(VK_DECIMAL)&1) 
{
    bXHair=!bXHair;
    bChams=!bChams;
}
    if( bXHair ){DrawXHair(pDevice,D3DCOLOR_XRGB( 255, 0, 0 ) );}

    return oEndScene(pDevice);
}
//---------------------------------------------------------------------------------------------------------------------------------
HRESULT WINAPI hkBeginScene(LPDIRECT3DDEVICE9 pDevice)
{
    myfile << "BeginScene is hooked\n";             //Check log
    
    if (bChams)
    {
        pDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE );
    }
    else
    {
        pDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE );
    }
    return oBeginScene(pDevice);
}
//---------------------------------------------------------------------------------------------------------------------------------
HRESULT WINAPI hkDrawIndexedPrimitive(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount)
{

    myfile << "DIP is hooked\n";                  //Check log
    if(pDevice->GetStreamSource(0, &Stream_Data, &Offset, &Stride) == D3D_OK)
        Stream_Data->Release();

    return oDrawIndexedPrimitive(pDevice, PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);

}
//---------------------------------------------------------------------------------------------------------------------------------
HRESULT WINAPI hkReset(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters)
{
    myfile << "Reset is hooked\n";                //Check log
    if( g_pFont )
        g_pFont->OnLostDevice();

    if( g_pLine )
        g_pLine->OnLostDevice();

    HRESULT iReturnValue = oReset(pDevice, pPresentationParameters);

    if(iReturnValue == D3D_OK) {

        if( g_pFont )
            g_pFont->OnResetDevice();

        if( g_pLine )
            g_pLine->OnResetDevice();
    }

    return iReturnValue;

}
//-----------------------------------------------------------------------------------------------------------------------------------
LRESULT CALLBACK MsgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam){return DefWindowProc(hwnd, uMsg, wParam, lParam);}
void DX_Init(DWORD* table)
{
    WNDCLASSEXA wc = {sizeof(WNDCLASSEX),CS_CLASSDC,MsgProc,0L,0L,GetModuleHandleA(NULL),NULL,NULL,NULL,NULL,"DX",NULL};
    RegisterClassExA(&wc);
    HWND hWnd = CreateWindowA("DX",NULL,WS_OVERLAPPEDWINDOW,100,100,300,300,GetDesktopWindow(),NULL,wc.hInstance,NULL);
    LPDIRECT3D9 pD3D = Direct3DCreate9( D3D_SDK_VERSION );
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory( &d3dpp, sizeof(d3dpp) );
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
    LPDIRECT3DDEVICE9 pd3dDevice;
    pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&pd3dDevice);
    DWORD* pVTable = (DWORD*)pd3dDevice;
    pVTable = (DWORD*)pVTable[0];

    table[ES]   = pVTable[42];                    //EndScene address
    table[DIP]  = pVTable[82];                    //DrawIndexedPrimitive address
    table[RES]  = pVTable[16];                    //Reset address
    table[BS]   = pVTable[41];                    //BeginScene address

    DestroyWindow(hWnd);
}
//------------------------------------------------------------------------------------------------------------------------------------
DWORD WINAPI VirtualMethodTableRepatchingLoopToCounterExtensionRepatching( LPVOID  Param )
{
    while(1) {
        Sleep(100);
        HookVTableFunction((PDWORD*)npDevice, (PBYTE)hkDrawIndexedPrimitive, 82); //Hook DrawIndexedPrimitive
        HookVTableFunction((PDWORD*)npDevice, (PBYTE)hkEndScene, 42); //Hook EndScene
        HookVTableFunction((PDWORD*)npDevice, (PBYTE)hkReset, 16); //Hook Reset
        HookVTableFunction((PDWORD*)npDevice, (PBYTE)hkBeginScene, 41); //Hook Beginscene

    }

    return 1;
}
//------------------------------------------------------------------------------------------------------------------------------------
bool hooked = false;
DWORD WINAPI LoopFunction( LPVOID lpParam  )
{

    while(1) {
        if( hooked == false) {
            DWORD VTable[3] = {0};

            while(GetModuleHandleA("d3d9.dll")==NULL) {
                Sleep(250);
            }

            DX_Init(VTable);
         HOOK(EndScene,VTable[ES]);            //Hook EndScene as a device discovery hook

            while(!npDevice) {
                Sleep(50); //Sleep until npDevice is not equal to NULL
            }
            UNHOOK(EndScene, VTable[ES]);         //Unhook as soon as we have a valid pointer to pDevice

            *(PDWORD)&oDrawIndexedPrimitive = VTable[DIP];
            *(PDWORD)&oEndScene                = VTable[ES];
            *(PDWORD)&oReset                = VTable[RES];
            *(PDWORD)&oBeginScene            = VTable[BS];

            CreateThread(NULL,0,&VirtualMethodTableRepatchingLoopToCounterExtensionRepatching,NULL,0,NULL); //Create hooking thread

            hooked = true;

            Sleep(200);

        }
    }
    return 0;
}
//------------------------------------------------------------------------------------------------------------------------------------
BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpvReserved)
{
    if(dwReason == DLL_PROCESS_ATTACH) {
        CreateThread(0, 0, LoopFunction, 0, 0, 0);
        myfile.open("c:\\D3DTest.log");
        myfile.clear();
        myfile << "----------Attached----------\n";
        myfile << "\n";
    }
    else if(dwReason == DLL_PROCESS_DETACH) {
        myfile << "----------Detached----------";
        myfile.close();
    }

    return TRUE;
}
error i get
Code:
1>------ Build started: Project: D3D MENU HACK, Configuration: Debug Win32 ------
1>  main.cpp
1>c:\users\keenny\documents\visual studio 2012\projects\d3d menu hack\d3d menu hack\main.cpp(223): error C3861: 'Detour': identifier not found
1>c:\users\keenny\documents\visual studio 2012\projects\d3d menu hack\d3d menu hack\main.cpp(228): error C3861: 'Detour': identifier not found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
where occurs
Code:
#define HOOK(func,addy) o##func = (t##func)DetourFunction((PBYTE)addy,(PBYTE)hk##func) //Quick Hook using MS Detour
#define UNHOOK(func,addy) o##func = (t##func)DetourFunction((PBYTE)addy,(PBYTE)o##func) //Quick Unook using MS Detour
Here is an Example:
Code:
Method1()
{
    CallThisShit(); //Error
}
CallThisShit()
{
   int i = 0;
}
The error that when you want to use the method, its currently dont exist.
to fix: replace the 2
[/CODE]
where occurs
Code:
#define HOOK(func,addy) o##func = (t##func)DetourFunction((PBYTE)addy,(PBYTE)hk##func) //Quick Hook using MS Detour
#define UNHOOK(func,addy) o##func =  (t##func)DetourFunction((PBYTE)addy,(PBYTE)o##func) //Quick Unook using  MS Detour
[/QUOTE]

Here is an Example:
Code:
CallThisShit()
{
   int i = 0;
}
Method1()
{
    CallThisShit(); //No error, cuz the CallThisShit already exist.
}
In you case, its a bit more complicated, you have to move the Detour() above, where you firstly want to use it.

Very simple error, i think you are C+P...
Quote Originally Posted by rabir007 View Post


Here is an Example:
Code:
Method1()
{
    CallThisShit(); //Error
}
CallThisShit()
{
   int i = 0;
}
The error that when you want to use the method, its currently dont exist.
to fix: replace the 2
[/CODE]
where occurs
Code:
#define HOOK(func,addy) o##func = (t##func)DetourFunction((PBYTE)addy,(PBYTE)hk##func) //Quick Hook using MS Detour
#define UNHOOK(func,addy) o##func =  (t##func)DetourFunction((PBYTE)addy,(PBYTE)o##func) //Quick Unook using  MS Detour


Here is an Example:
Code:
CallThisShit()
{
   int i = 0;
}
Method1()
{
    CallThisShit(); //No error, cuz the CallThisShit already exist.
}
In you case, its a bit more complicated, you have to move the Detour() above, where you firstly want to use it.

Very simple error, i think you are C+P...
[/QUOTE]
Lol no idiot , you are also an copy and paster.
He don't have detours that what was the problem
humm i do have detour how strange idiot
Posts 1–7 of 7 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

Talk with us