I know I need to lear C++...
Ah, here is my DirectX.cpp and .h
DirectX.cpp
[php]#include "DirectX.h"
#include "Menu.h"
oReset pReset;
oPresent pPresent;
cDirectx Directx;
LPDIRECT3DDEVICE9 g_pDevice = 0;
void refont( LPDIRECT3DDEVICE9 pDevice)
{
if (g_pDevice != pDevice)
{
g_pDevice = pDevice;
try
{
if (Directx.pFont != 0)
Directx.pFont->Release();
} catch (...) {}
Directx.pFont = 0;
D3DXCreateFont(pDevice, 15, 0, 350, 0, 0, DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS, PROOF_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial", &Directx.pFont );
}
if (g_pDevice != pDevice)
{
g_pDevice = pDevice;
try
{
if (Directx.pFont2 != 0)
Directx.pFont2->Release();
} catch (...) {}
Directx.pFont2 = 0;
D3DXCreateFont(pDevice, 18, 0, 700, 0, 0, DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS, PROOF_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial Black", &Directx.pFont2 );
}
}
void cDirectx:
rawTri(LPDIRECT3DDEVICE9 dev, int x, int y, int w, int h, DWORD Color)
{
D3DRECT BarRect = { x, y, x + w, y + h };
dev->Clear(1, &BarRect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, Color, 0, 0);
}
void cDirectx:
rawString(int x, int y, DWORD color, LPD3DXFONT g_pFont, const char *fmt, ...)
{
RECT FontPos = { x, y, x + 120, y + 16 };
char buf[1024] = {'\0'};
va_list va_alist;
va_start(va_alist, fmt);
vsprintf_s(buf, fmt, va_alist);
va_end(va_alist);
g_pFont->DrawText(NULL, buf, -1, &FontPos, DT_NOCLIP, color);
}
//Credits to Azorbix i think
HRESULT cDirectx::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;
}
HRESULT WINAPI gellReset(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters )
{
Sprite->OnLostDevice();
Directx.pFont->OnLostDevice();
Directx.pFont2->OnLostDevice();
HRESULT hRet = pReset(pDevice, pPresentationParameters);
Sprite->OnResetDevice();
Directx.pFont->OnResetDevice();
Directx.pFont2->OnResetDevice();
return hRet;
}
HRESULT WINAPI gellPresent(LPDIRECT3DDEVICE9 pDevice, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion)
{
Base.RenderFrame(pDevice);
return pPresent(pDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
}
void cDirectx::Hook(void)
{
DWORD Reset = Base.GetPointer(16);
DWORD Present = Base.GetPointer(17);
pReset = (oReset) DetourCreate(( BYTE* )Reset, ( BYTE* )gellReset );
pPresent = (oPresent) DetourCreate(( BYTE* )Present, ( BYTE* )gellPresent );
}
[/php]
DirectX.h
[php]#ifndef __DIRECTX_H__
#define __DIRECTX_H__
#pragma once
#include "Files.h"
typedef HRESULT ( WINAPI* oPresent ) ( LPDIRECT3DDEVICE9 pDevice, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion);
typedef HRESULT ( WINAPI* oReset )( LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters );
class cDirectx{
public:
LPD3DXFONT pFont;
LPD3DXFONT pFont2;
void Hook(void);
void DrawTri(LPDIRECT3DDEVICE9 dev, int x, int y, int w, int h, DWORD Color);
void DrawString(int x, int y, DWORD color, LPD3DXFONT g_pFont, const char *fmt, ...);
HRESULT GenerateTexture(IDirect3DDevice9 *pD3Ddev, IDirect3DTexture9 **ppD3Dtex, DWORD colour32);
};
extern cDirectx Directx;
#endif
[/php]