HOOK D3D

Posts 1–2 of 2 · Page 1 of 1
HOOK D3D
Personnel, to hard to understand D3D.
how have someone explain to me step by step?
For example, create the device LPDIRECT9DDEVICE ..
and what do I do next?
How do I create a menu in the game PB?
Please first learn the D3D functions...
But when you think you can do anything with it here:

Code:
//EndScene
typedef HRESULT (WINAPI* oEndScene)(LPDIRECT3DDEVICE9 pDevice);
oEndScene pEndScene;

//DIP
typedef HRESULT (WINAPI* oDIP)(LPDIRECT3DDEVICE9 pDevice,D3DPRIMITIVETYPE,int,UINT,UINT,UINT,UINT); 
oDIP pDIP;


//useful functions
bool bCompare(const BYTE* pData, const BYTE* bMask, const char* szMask)
{
	for(;*szMask;++szMask,++pData,++bMask)
		if(*szMask=='x' && *pData!=*bMask)  
			return 0;
	return (*szMask) == NULL;
}

DWORD FindPattern(DWORD dwAddress,DWORD dwLen,BYTE *bMask,char * szMask)
{
	for(DWORD i=0; i<dwLen; i++)
		if (bCompare((BYTE*)(dwAddress+i),bMask,szMask))  
			return (DWORD)(dwAddress+i);
	return 0;
}



void *DetourCreate(BYTE *src, const BYTE *dst, const int len)
{
	BYTE *jmp = (BYTE*)malloc(len+5);
	DWORD dwBack;

	VirtualProtect(src, len, PAGE_EXECUTE_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;
	for (int i=5; i<len; i++)  src[i]=0x90;
	VirtualProtect(src, len, dwBack, &dwBack);
	return (jmp-len);
}



void PrintText(LPD3DXFONT Font, long x, long y, D3DCOLOR fontColor, char *text, ...)
{  
    RECT rct;    
    rct.left     = x - 1;    
    rct.right    = x + 1;    
    rct.top      = y - 1 ;    
    rct.bottom   = y + 1;  

    if(!text) { return; } 
    va_list va_alist; 
    char logbuf[256] = {0}; 
    va_start (va_alist, text); 
    _vsnprintf (logbuf+strlen(logbuf), sizeof(logbuf) - strlen(logbuf), text, va_alist); 
    va_end (va_alist); 
    RECT FontRect = { x, y, x, y }; 
    pFont->DrawText(NULL, logbuf, -1, &rct, DT_NOCLIP, fontColor);  
}



void FillRGB( int x, int y, int w, int h, D3DCOLOR color, IDirect3DDevice9* pDevice )
{
	D3DRECT rec = { x, y, x + w, y + h };
	pDevice->Clear( 1, &rec, D3DCLEAR_TARGET, color, 0, 0 );
}


void DrawBorder( int x, int y, int w, int h, int px, D3DCOLOR BorderColor, IDirect3DDevice9* pDevice )
{
	FillRGB( x, (y + h - px), w, px,	BorderColor, pDevice );
	FillRGB( x, y, px, h,				BorderColor, pDevice );
	FillRGB( x, y, w, px,				BorderColor, pDevice );
	FillRGB( (x + w - px), y, px, h,	BorderColor, pDevice );
}


void DrawBox( int x, int y, int w, int h, D3DCOLOR BoxColor, D3DCOLOR BorderColor, IDirect3DDevice9* pDevice )
{
	FillRGB( x, y, w, h,		BoxColor, pDevice );
	DrawBorder( x, y, w, h, 1,	BorderColor, pDevice );
}



void DrawCrosshair(LPDIRECT3DDEVICE9 pDevice, int size, int strong,  D3DCOLOR xcolor)
{
	int iCenterX = GetSystemMetrics( 0 ) / 2;
	int iCenterY = GetSystemMetrics( 1 ) / 2;
	if( iCenterX < 20 && iCenterY < 20 )
	{
		iCenterX = ( GetSystemMetrics( 0 ) / 2 );
		iCenterY = ( GetSystemMetrics( 1 ) / 2 );
	}
	D3DRECT rec2 = { iCenterX- size, iCenterY, iCenterX+ size, iCenterY+ strong};
	D3DRECT rec3 = { iCenterX, iCenterY- size, iCenterX+ strong,iCenterY+ size};
	pDevice->Clear(1, &rec2, D3DCLEAR_TARGET, xcolor, 1000,  0);
	pDevice->Clear(1, &rec3, D3DCLEAR_TARGET, xcolor, 100,  0);
}


void DrawHealthBar(int x, int y, int w, int h, D3DCOLOR color, D3DCOLOR BorderColor, int hp, int maxhp)
{
	FillRGB(x, y, ( hp / (double)maxhp ) * w, h, color, g_pDevice);
	DrawBorder(x, y, w, h, 1, BorderColor, g_pDevice);
}



HRESULT GenerateTexture(IDirect3DDevice9 *pD3Ddev, IDirect3DTexture9 **ppD3Dtex, DWORD colour32)
{
	if( FAILED(pD3Ddev->CreateTexture(8, 8, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, ppD3Dtex,NULL)) )
		return E_FAIL;
	
	WORD colour16 =	((WORD)((colour32>>28)&0xF)<<12)
			|(WORD)(((colour32>>20)&0xF)<<8)
			|(WORD)(((colour32>>12)&0xF)<<4)
			|(WORD)(((colour32>>4)&0xF)<<0);

	D3DLOCKED_RECT d3dlr;    
	(*ppD3Dtex)->LockRect(0, &d3dlr, 0, 0);
	WORD *pDst16 = (WORD*)d3dlr.pBits;

	for(int xy=0; xy < 8*8; xy++)
		*pDst16++ = colour16;

	(*ppD3Dtex)->UnlockRect(0);

	return S_OK;
}
Just use DrawBox and DrawBorder to make a Simple Menu...


Credits ac1d_bUrn
Posts 1–2 of 2 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us