Welcome to a tut made by AeroSkinn.
This is full writed by me AeroSkinn.
If you leech please include credits:
Karrka -> Base
Detours ->Croner
AeroSkinn -> Teacher
First we start with the basic menu:
Create in C++: Detour Filter
[CENTER]ADE32.h
Code:
#ifndef __ADE32_H__
#define __ADE32_H__
#define C_ERROR 0xFFFFFFFF
#define C_ADDR1 0x00000001
#define C_ADDR2 0x00000002
#define C_ADDR4 0x00000004
#define C_LOCK 0x00000008
#define C_67 0x00000010
#define C_66 0x00000020
#define C_REP 0x00000040
#define C_SEG 0x00000080
#define C_ANYPREFIX (C_66+C_67+C_LOCK+C_REP+C_SEG)
#define C_DATA1 0x00000100
#define C_DATA2 0x00000200
#define C_DATA4 0x00000400
#define C_SIB 0x00000800
#define C_ADDR67 0x00001000
#define C_DATA66 0x00002000
#define C_MODRM 0x00004000
#define C_BAD 0x00008000
#define C_OPCODE2 0x00010000
#define C_REL 0x00020000
#define C_STOP 0x00040000
#pragma pack(push)
#pragma pack(1)
struct disasm_struct
{
BYTE disasm_defaddr; // 00
BYTE disasm_defdata; // 01
DWORD disasm_len; // 02 03 04 05
DWORD disasm_flag; // 06 07 08 09
DWORD disasm_addrsize; // 0A 0B 0C 0D
DWORD disasm_datasize; // 0E 0F 10 11
BYTE disasm_rep; // 12
BYTE disasm_seg; // 13
BYTE disasm_opcode; // 14
BYTE disasm_opcode2; // 15
BYTE disasm_modrm; // 16
BYTE disasm_sib; // 17
union
{
BYTE disasm_addr_b[8]; // 18 19 1A 1B 1C 1D 1E 1F
WORD disasm_addr_w[4];
DWORD disasm_addr_d[2];
char disasm_addr_c[8];
short disasm_addr_s[4];
long disasm_addr_l[2];
};
union
{
BYTE disasm_data_b[8]; // 20 21 22 23 24 25 26 27
WORD disasm_data_w[4];
DWORD disasm_data_d[2];
char disasm_data_c[8];
short disasm_data_s[4];
long disasm_data_l[2];
};
}; // disasm_struct
#pragma pack(pop)
int disasm(BYTE* opcode0, disasm_struct* diza);
int oplen(BYTE* opcode);
#endif // __ADE32_H__
detour.h
Code:
#define JUNK_CODE_ONE \
__asm{push eax} \
__asm{xor eax, eax} \
__asm{setpo al} \
__asm{push edx} \
__asm{xor edx, eax} \
__asm{sal edx, 2} \
__asm{xchg eax, edx} \
__asm{pop edx} \
__asm{or eax, ecx} \
__asm{pop eax}
DWORD DetourMePleaseImNice( DWORD SrcVA, DWORD DstVA, DWORD Size )
{
DWORD DetourVA, dwProtect, i;
#define SIZEOF_MOVEAX_JMPEAX 7
JUNK_CODE_ONE
if ( SrcVA && DstVA && Size >= SIZEOF_MOVEAX_JMPEAX )
{
JUNK_CODE_ONE
DetourVA = (DWORD)VirtualAlloc( NULL, Size + SIZEOF_MOVEAX_JMPEAX, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if ( DetourVA && VirtualProtectEx(GetCurrentProcess(),(void*)SrcVA, Size, PAGE_READWRITE, &dwProtect ))
{
JUNK_CODE_ONE
for ( i=0; i < Size; i++ ) {
JUNK_CODE_ONE
*(BYTE*)( DetourVA + i ) = *(BYTE*)( SrcVA + i );
JUNK_CODE_ONE
}
JUNK_CODE_ONE
*(BYTE*)( DetourVA + Size + 0 ) = 0xB8;
JUNK_CODE_ONE
*(DWORD*)( DetourVA + Size + 1 ) = ( SrcVA + Size );
JUNK_CODE_ONE
*(WORD*)( DetourVA + Size + 5 ) = 0xE0FF;
JUNK_CODE_ONE
*(BYTE*)( SrcVA + 0 ) = 0xB8;
JUNK_CODE_ONE
*(DWORD*)( SrcVA + 1 ) = ( DstVA );
JUNK_CODE_ONE
*(WORD*)( SrcVA + 5 ) = 0xE0FF;
JUNK_CODE_ONE
VirtualProtectEx(GetCurrentProcess(),(void*)SrcVA, Size, dwProtect, &dwProtect );
JUNK_CODE_ONE
VirtualProtectEx(GetCurrentProcess(),(void*)DetourVA, Size + SIZEOF_MOVEAX_JMPEAX, PAGE_EXECUTE_READ, &dwProtect);
JUNK_CODE_ONE
return DetourVA;
}
}
return 0;
}
DWORD DetourCreateE9( DWORD SrcVA, DWORD DstVA, DWORD Size )
{
DWORD DetourVA, dwProtect, i;
#define SIZEOF_JMP_REL 5
if ( SrcVA && DstVA && Size >= SIZEOF_JMP_REL )
{
DetourVA = (DWORD) VirtualAlloc(
NULL, Size + SIZEOF_JMP_REL,
MEM_COMMIT, PAGE_EXECUTE_READWRITE );
if ( DetourVA && VirtualProtect( (VOID*)SrcVA, Size, PAGE_EXECUTE_READWRITE, &dwProtect ) )
{
for ( i=0; i < Size; i++ ) {
*(BYTE*)( DetourVA + i ) = *(BYTE*)( SrcVA + i );
}
*(BYTE*)( DetourVA + Size + 0 ) = 0xE9;
*(DWORD*)( DetourVA + Size + 1 ) = ( SrcVA - DetourVA - SIZEOF_JMP_REL );
*(BYTE*)( SrcVA + 0 ) = 0xE9;
*(DWORD*)( SrcVA + 1 ) = ( DstVA - SrcVA - SIZEOF_JMP_REL );
VirtualProtect( (VOID*)SrcVA, Size, dwProtect, &dwProtect );
VirtualProtect( (VOID*)DetourVA, Size +
SIZEOF_JMP_REL, PAGE_EXECUTE_READ, &dwProtect );
return DetourVA;
}
}
return (0);
}
pattern.h
Code:
BOOL bCompare(const BYTE* pData, const BYTE* bMask, const char* szMask)
{
for(;*szMask;++szMask,++pData,++bMask)
if(*szMask=='x' && *pData!=*bMask)
return false;
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;
}
StdAfx.h
Code:
#if!defined __STDAFX_H__
#define __STDAFX_H__
#define WIN32_LEAN_AND_MEAN
#pragma comment(lib,"d3dx9.lib")
#include <windows.h>
#include <winsock.h>
#include <d3dx9.h>
#include <d3d9.h>
#endif
d3dfont.h
Code:
#ifndef _D3DFONT_H_
#define _D3DFONT_H_
#include <tchar.h>
#include <d3d9.h>
// Font creation flags
#define D3DFONT_BOLD 0x0001
#define D3DFONT_ITALIC 0x0002
#define D3DFONT_ZENABLE 0x0004
// Font rendering flags
#define D3DFONT_CENTERED 0x0001
#define D3DFONT_TWOSIDED 0x0002
#define D3DFONT_FILTERED 0x0004
#define D3DFONT_RIGHT 0x0008 // non standard feature
#define D3DFONT_SHADOW 0x0010 // non standard feature
//-----------------------------------------------------------------------------
// Name: class CD3DFont
// Desc: Texture-based font class for doing text in a 3D scene.
//-----------------------------------------------------------------------------
class CD3DFont
{
TCHAR m_strFontName[80]; // Font properties
DWORD m_dwFontHeight;
DWORD m_dwFontFlags;
LPDIRECT3DDEVICE9 m_pd3dDevice; // A D3DDevice used for rendering
LPDIRECT3DTEXTURE9 m_pTexture; // The d3d texture for this font
LPDIRECT3DVERTEXBUFFER9 m_pVB; // VertexBuffer for rendering text
DWORD m_dwTexWidth; // Texture dimensions
DWORD m_dwTexHeight;
FLOAT m_fTextScale;
FLOAT m_fTexCoords[128-32][4];
DWORD m_dwSpacing; // Character pixel spacing per side
// Stateblocks for setting and restoring render states
LPDIRECT3DSTATEBLOCK9 m_pStateBlockSaved;
LPDIRECT3DSTATEBLOCK9 m_pStateBlockDrawText;
public:
// 2D and 3D text drawing functions
HRESULT DrawText( FLOAT x, FLOAT y, DWORD dwColor,
const TCHAR* strText, DWORD dwFlags=0L );
HRESULT DrawTextScaled( FLOAT x, FLOAT y, FLOAT z,
FLOAT fXScale, FLOAT fYScale, DWORD dwColor,
const TCHAR* strText, DWORD dwFlags=0L );
HRESULT Render3DText( const TCHAR* strText, DWORD dwFlags=0L );
// Function to get extent of text
HRESULT GetTextExtent( const TCHAR* strText, SIZE* pSize );
// Initializing and destroying device-dependent objects
HRESULT InitDeviceObjects( LPDIRECT3DDEVICE9 pd3dDevice );
HRESULT RestoreDeviceObjects();
HRESULT InvalidateDeviceObjects();
HRESULT DeleteDeviceObjects();
// Constructor / destructor
CD3DFont( const TCHAR* strFontName, DWORD dwHeight, DWORD dwFlags=0L );
~CD3DFont();
};
#endif// _D3DFONT_H_
hsmethode.h
Code:
#pragma warning(disable:4102)
int.h
main.h
Code:
#ifndef _MAIN_H_
#define _MAIN_H_
typedef HRESULT ( WINAPI* oPresent ) ( LPDIRECT3DDEVICE9 pDevice, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion);
oPresent pPresent;
typedef HRESULT (WINAPI* oReset) (LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters);
oReset pReset;
typedef HRESULT (WINAPI* oDrawIndexedPrimitive) (LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE Type, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount);
oDrawIndexedPrimitive pDrawIndexedPrimitive;
typedef HRESULT (WINAPI* oEndScene) (LPDIRECT3DDEVICE9 pDevice);
oEndScene pEndScene;
PVOID D3Ddiscover(void *tbl, int size)
{
HWND hWnd;
void *pInterface=0 ;
D3DPRESENT_PARAMETERS d3dpp;
if ((hWnd=CreateWindowEx(NULL,WC_DIALOG,"",WS_OVERLAPPED,0,0,50,50,NULL,NULL,NULL,NULL))==NULL) return 0;
ShowWindow(hWnd, SW_HIDE);
LPDIRECT3D9 pD3D;
LPDIRECT3DDEVICE9 pD3Ddev;
if ((pD3D = Direct3DCreate9(D3D_SDK_VERSION))!=NULL)
{
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferWidth = d3dpp.BackBufferHeight = 600;
pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&pD3Ddev);
if (pD3Ddev)
{
pInterface = (PDWORD)*(DWORD *)pD3Ddev;
memcpy(tbl,(void *)pInterface,size);
pD3Ddev->Release();
}
pD3D->Release();
}
DestroyWindow(hWnd);
return pInterface;
}
#endif// _MAIN_H_
color.h
Code:
#ifndef _COLOR_H_
#define _COLOR_H_
#define WHITE D3DCOLOR_ARGB(255, 255, 255, 255)
#define RED D3DCOLOR_ARGB(255, 255, 000, 000)
#define GREEN D3DCOLOR_ARGB(175, 000, 230, 000)
#define BLUE D3DCOLOR_ARGB(255, 000, 000, 255)
#define BLACK D3DCOLOR_ARGB(128, 000, 000, 000)
//#define BLACK D3DCOLOR_ARGB(255, 000, 000, 000)
#define BLACK2 D3DCOLOR_ARGB(255, 000, 000, 000)
#define PURPLE D3DCOLOR_ARGB(255, 125, 000, 255)
#define GREY D3DCOLOR_ARGB(128, 128, 128, 128)
#define YELLOW D3DCOLOR_ARGB(255, 255, 255, 000)
#define ORANGE D3DCOLOR_ARGB(255, 255, 125, 000)
#define CYAN D3DCOLOR_ARGB(255, 000, 139 ,200)
#define PINK D3DCOLOR_ARGB(255,255,192,203)
//#define BlackTrans D3DCOLOR_ARGB(175,000,000,000)
#define BlackTrans D3DCOLOR_ARGB(128, 0, 0, 0)
#define GhostWHITE D3DCOLOR_ARGB(175, 175, 175, 175)
#define GhostRED D3DCOLOR_ARGB(175, 100, 000, 000)
#define GhostCYANS D3DCOLOR_ARGB(175,000,255,255);
#define GhostGREEN D3DCOLOR_ARGB(175, 000, 175, 000)
#define GhostBLUE D3DCOLOR_ARGB(175, 000, 000, 175)
#define GhostBLACK D3DCOLOR_ARGB(70, 000, 000, 000)
#define GhostBLACK D3DCOLOR_ARGB(45, 000, 000, 100)
#define GhostPURPLE D3DCOLOR_ARGB(175, 60, 000, 175)
#define GhostGREY D3DCOLOR_ARGB(175, 59, 59, 59)
#define GhostYELLOW D3DCOLOR_ARGB(175, 175, 175, 000)
#define GhostORANGE D3DCOLOR_ARGB(175, 175, 175, 000)
#define GhostCYAN D3DCOLOR_ARGB(175, 000, 64 ,200)
#define GhostPINK D3DCOLOR_ARGB(175,175,91,117)
#define BlackMenuz D3DCOLOR_ARGB(125,0,0,0)
#define Brent D3DCOLOR_ARGB(128,246,64,132)
#endif // _COLOR_H_
d3dmenu.h
Code:
#ifndef _D3DMENU_H_
#define _D3DMENU_H_
#include <windows.h>
#include "d3dfont.h"
#include <d3dx9.h>
#include "Color.h"
#define MENUFOLDER 1
#define MENUTEXT 2
#define MENUITEM 3
#define SUBFOLDER 4
#define White D3DCOLOR_ARGB(255,255,255,255)
#define Red D3DCOLOR_ARGB(255,255,0,0)
#define Green D3DCOLOR_ARGB(255,0,255,0)
#define Blue D3DCOLOR_ARGB(255,0,0,255)
#define Black D3DCOLOR_ARGB(255,0,0,0)
#define Purple D3DCOLOR_ARGB(255,125,0,255)
#define Grey D3DCOLOR_ARGB(255,128,128,128)
#define Yellow D3DCOLOR_ARGB(255,255,255,0)
#define Orange D3DCOLOR_ARGB(255,255,140,0)
#define Cyan D3DCOLOR_ARGB(255,0,139,200)
#define Pink D3DCOLOR_ARGB(255,255,192,203)
#define LightBlue D3DCOLOR_ARGB(255, 66, 180, 230)
#define Brent D3DCOLOR_ARGB(128,246,64,132)
#define menu_on Blue
#define menu_off White
#define menu_folder Red
#define menu_text Brent
#define menu_current Green
typedef struct
{
int typ;
char *txt;
char **opt;
int *var;
int maxval;
}tMENU;
class D3DMenu
{
public:
D3DMenu(char *Name=0, int maxentries=130, int maxwidth=300)
{
title = Name;
maxitems = maxentries;
cur = noitems = visible = 0;
x = 28;
y = 30;
totwidth = ofs = maxwidth;
height = 12;
titleheight = totheight = height+4;
col_group = menu_folder;
col_text = menu_text;
col_off = menu_off;
col_on = menu_on;
col_current = menu_current;
MENU=(tMENU **)malloc(4*maxitems);
for (int i=0; i<maxitems; i++) MENU[i]=(tMENU *)malloc(sizeof(tMENU));
}
~D3DMenu(){
for (int i=0; i<maxitems; i++) free(MENU[i]);
free(MENU);
}
DWORD col_title;
DWORD col_group;
DWORD col_group1;
DWORD col_text;
DWORD col_off;
DWORD col_on;
DWORD col_current;
int x,y;
int totwidth,totheight;
int height;
int titleheight;
int ofs;
int max_x, max_y;
int m_x,m_y;
int m_lm, m_rm;
char *title;
int cur;
int noitems;
int visible;
int moving;
tMENU **MENU;
// Load Save Menu
void Save(char* szSection, char* szKey, int iValue);
int Load(char* szSection, char* szKey, int iDefaultValue);
void AddItem (char *txt, int *var, char **opt, int maxvalue=2, int typ=MENUITEM);
void AddGroup (char *txt, int *var, char **opt, int maxvalue=2);
void AddSubb (char *txt, int *var, char **opt, int maxvalue=2);
void AddText (char *txt, char *opt="");
void Show (ID3DXFont *pFont1,LPDIRECT3DDEVICE9 pDevice);
void Nav (void);
void CheckTitleMove(int rm,int mx, int my);
void DrawTextC(int x,int y,DWORD color,char *text, ID3DXFont* pFont);
private:
int maxitems;
int dx,dy;
int FindItem(void);
};
#endif// _D3DMENU_H_
addies.h
Code:
#include <math.h>
#define HackFuctions(Type,Adr,Vaule) *(Type*)(Adr) = Vaule;
#define WARROCK decrypt("`j{[xlt")
ADE32.cpp
Code:
// ADE32 version 2.02c -- C edition
#define WIN32_LEAN_AND_MEAN
#define WIN32_EXTRA_LEAN
#include <windows.h>
#include "ADE32.h"
DWORD ade32_table[512] = {
/* 00 */ C_MODRM,
/* 01 */ C_MODRM,
/* 02 */ C_MODRM,
/* 03 */ C_MODRM,
/* 04 */ C_DATA1,
/* 05 */ C_DATA66,
/* 06 */ C_BAD,
/* 07 */ C_BAD,
/* 08 */ C_MODRM,
/* 09 */ C_MODRM,
/* 0A */ C_MODRM,
/* 0B */ C_MODRM,
/* 0C */ C_DATA1,
/* 0D */ C_DATA66,
/* 0E */ C_BAD,
/* 0F */ C_OPCODE2,
/* 10 */ C_MODRM+C_BAD,
/* 11 */ C_MODRM,
/* 12 */ C_MODRM+C_BAD,
/* 13 */ C_MODRM,
/* 14 */ C_DATA1+C_BAD,
/* 15 */ C_DATA66+C_BAD,
/* 16 */ C_BAD,
/* 17 */ C_BAD,
/* 18 */ C_MODRM+C_BAD,
/* 19 */ C_MODRM,
/* 1A */ C_MODRM,
/* 1B */ C_MODRM,
/* 1C */ C_DATA1+C_BAD,
/* 1D */ C_DATA66+C_BAD,
/* 1E */ C_BAD,
/* 1F */ C_BAD,
/* 20 */ C_MODRM,
/* 21 */ C_MODRM,
/* 22 */ C_MODRM,
/* 23 */ C_MODRM,
/* 24 */ C_DATA1,
/* 25 */ C_DATA66,
/* 26 */ C_SEG+C_BAD,
/* 27 */ C_BAD,
/* 28 */ C_MODRM,
/* 29 */ C_MODRM,
/* 2A */ C_MODRM,
/* 2B */ C_MODRM,
/* 2C */ C_DATA1,
/* 2D */ C_DATA66,
/* 2E */ C_SEG+C_BAD,
/* 2F */ C_BAD,
/* 30 */ C_MODRM,
/* 31 */ C_MODRM,
/* 32 */ C_MODRM,
/* 33 */ C_MODRM,
/* 34 */ C_DATA1,
/* 35 */ C_DATA66,
/* 36 */ C_SEG+C_BAD,
/* 37 */ C_BAD,
/* 38 */ C_MODRM,
/* 39 */ C_MODRM,
/* 3A */ C_MODRM,
/* 3B */ C_MODRM,
/* 3C */ C_DATA1,
/* 3D */ C_DATA66,
/* 3E */ C_SEG+C_BAD,
/* 3F */ C_BAD,
/* 40 */ 0,
/* 41 */ 0,
/* 42 */ 0,
/* 43 */ 0,
/* 44 */ C_BAD,
/* 45 */ 0,
/* 46 */ 0,
/* 47 */ 0,
/* 48 */ 0,
/* 49 */ 0,
/* 4A */ 0,
/* 4B */ 0,
/* 4C */ C_BAD,
/* 4D */ 0,
/* 4E */ 0,
/* 4F */ 0,
/* 50 */ 0,
/* 51 */ 0,
/* 52 */ 0,
/* 53 */ 0,
/* 54 */ 0,
/* 55 */ 0,
/* 56 */ 0,
/* 57 */ 0,
/* 58 */ 0,
/* 59 */ 0,
/* 5A */ 0,
/* 5B */ 0,
/* 5C */ C_BAD,
/* 5D */ 0,
/* 5E */ 0,
/* 5F */ 0,
/* 60 */ C_BAD,
/* 61 */ C_BAD,
/* 62 */ C_MODRM+C_BAD,
/* 63 */ C_MODRM+C_BAD,
/* 64 */ C_SEG,
/* 65 */ C_SEG+C_BAD,
/* 66 */ C_66,
/* 67 */ C_67,
/* 68 */ C_DATA66,
/* 69 */ C_MODRM+C_DATA66,
/* 6A */ C_DATA1,
/* 6B */ C_MODRM+C_DATA1,
/* 6C */ C_BAD,
/* 6D */ C_BAD,
/* 6E */ C_BAD,
/* 6F */ C_BAD,
/* 70 */ C_DATA1+C_REL+C_BAD,
/* 71 */ C_DATA1+C_REL+C_BAD,
/* 72 */ C_DATA1+C_REL,
/* 73 */ C_DATA1+C_REL,
/* 74 */ C_DATA1+C_REL,
/* 75 */ C_DATA1+C_REL,
/* 76 */ C_DATA1+C_REL,
/* 77 */ C_DATA1+C_REL,
/* 78 */ C_DATA1+C_REL,
/* 79 */ C_DATA1+C_REL,
/* 7A */ C_DATA1+C_REL+C_BAD,
/* 7B */ C_DATA1+C_REL+C_BAD,
/* 7C */ C_DATA1+C_REL,
/* 7D */ C_DATA1+C_REL,
/* 7E */ C_DATA1+C_REL,
/* 7F */ C_DATA1+C_REL,
/* 80 */ C_MODRM+C_DATA1,
/* 81 */ C_MODRM+C_DATA66,
/* 82 */ C_MODRM+C_DATA1+C_BAD,
/* 83 */ C_MODRM+C_DATA1,
/* 84 */ C_MODRM,
/* 85 */ C_MODRM,
/* 86 */ C_MODRM,
/* 87 */ C_MODRM,
/* 88 */ C_MODRM,
/* 89 */ C_MODRM,
/* 8A */ C_MODRM,
/* 8B */ C_MODRM,
/* 8C */ C_MODRM+C_BAD,
/* 8D */ C_MODRM,
/* 8E */ C_MODRM+C_BAD,
/* 8F */ C_MODRM,
/* 90 */ 0,
/* 91 */ 0,
/* 92 */ 0,
/* 93 */ C_BAD,
/* 94 */ C_BAD,
/* 95 */ C_BAD,
/* 96 */ C_BAD,
/* 97 */ C_BAD,
/* 98 */ C_BAD,
/* 99 */ 0,
/* 9A */ C_DATA66+C_DATA2+C_BAD,
/* 9B */ 0,
/* 9C */ C_BAD,
/* 9D */ C_BAD,
/* 9E */ C_BAD,
/* 9F */ C_BAD,
/* A0 */ C_ADDR67,
/* A1 */ C_ADDR67,
/* A2 */ C_ADDR67,
/* A3 */ C_ADDR67,
/* A4 */ 0,
/* A5 */ 0,
/* A6 */ 0,
/* A7 */ 0,
/* A8 */ C_DATA1,
/* A9 */ C_DATA66,
/* AA */ 0,
/* AB */ 0,
/* AC */ 0,
/* AD */ C_BAD,
/* AE */ 0,
/* AF */ C_BAD,
/* B0 */ C_DATA1,
/* B1 */ C_DATA1,
/* B2 */ C_DATA1,
/* B3 */ C_DATA1,
/* B4 */ C_DATA1,
/* B5 */ C_DATA1,
/* B6 */ C_DATA1+C_BAD,
/* B7 */ C_DATA1+C_BAD,
/* B8 */ C_DATA66,
/* B9 */ C_DATA66,
/* BA */ C_DATA66,
/* BB */ C_DATA66,
/* BC */ C_DATA66+C_BAD,
/* BD */ C_DATA66,
/* BE */ C_DATA66,
/* BF */ C_DATA66,
/* C0 */ C_MODRM+C_DATA1,
/* C1 */ C_MODRM+C_DATA1,
/* C2 */ C_DATA2+C_STOP,
/* C3 */ C_STOP,
/* C4 */ C_MODRM+C_BAD,
/* C5 */ C_MODRM+C_BAD,
/* C6 */ C_MODRM+C_DATA1,
/* C7 */ C_MODRM+C_DATA66,
/* C8 */ C_DATA2+C_DATA1,
/* C9 */ 0,
/* CA */ C_DATA2+C_STOP+C_BAD,
/* CB */ C_STOP+C_BAD,
/* CC */ C_BAD,
/* CD */ C_BAD,
/* CE */ C_BAD,
/* CF */ C_STOP+C_BAD,
/* D0 */ C_MODRM,
/* D1 */ C_MODRM,
/* D2 */ C_MODRM,
/* D3 */ C_MODRM,
/* D4 */ C_DATA1+C_BAD,
/* D5 */ C_DATA1+C_BAD,
/* D6 */ C_BAD,
/* D7 */ C_BAD,
/* D8 */ C_MODRM,
/* D9 */ C_MODRM,
/* DA */ C_MODRM,
/* DB */ C_MODRM,
/* DC */ C_MODRM,
/* DD */ C_MODRM,
/* DE */ C_MODRM,
/* DF */ C_MODRM,
/* E0 */ C_DATA1+C_REL+C_BAD,
/* E1 */ C_DATA1+C_REL+C_BAD,
/* E2 */ C_DATA1+C_REL,
/* E3 */ C_DATA1+C_REL,
/* E4 */ C_DATA1+C_BAD,
/* E5 */ C_DATA1+C_BAD,
/* E6 */ C_DATA1+C_BAD,
/* E7 */ C_DATA1+C_BAD,
/* E8 */ C_DATA66+C_REL,
/* E9 */ C_DATA66+C_REL+C_STOP,
/* EA */ C_DATA66+C_DATA2+C_BAD,
/* EB */ C_DATA1+C_REL+C_STOP,
/* EC */ C_BAD,
/* ED */ C_BAD,
/* EE */ C_BAD,
/* EF */ C_BAD,
/* F0 */ C_LOCK+C_BAD,
/* F1 */ C_BAD,
/* F2 */ C_REP,
/* F3 */ C_REP,
/* F4 */ C_BAD,
/* F5 */ C_BAD,
/* F6 */ C_MODRM,
/* F7 */ C_MODRM,
/* F8 */ 0,
/* F9 */ 0,
/* FA */ C_BAD,
/* FB */ C_BAD,
/* FC */ 0,
/* FD */ 0,
/* FE */ C_MODRM,
/* FF */ C_MODRM,
/* 00 */ C_MODRM,
/* 01 */ C_MODRM,
/* 02 */ C_MODRM,
/* 03 */ C_MODRM,
/* 04 */ C_ERROR,
/* 05 */ C_ERROR,
/* 06 */ 0,
/* 07 */ C_ERROR,
/* 08 */ 0,
/* 09 */ 0,
/* 0A */ 0,
/* 0B */ 0,
/* 0C */ C_ERROR,
/* 0D */ C_ERROR,
/* 0E */ C_ERROR,
/* 0F */ C_ERROR,
/* 10 */ C_ERROR,
/* 11 */ C_ERROR,
/* 12 */ C_ERROR,
/* 13 */ C_ERROR,
/* 14 */ C_ERROR,
/* 15 */ C_ERROR,
/* 16 */ C_ERROR,
/* 17 */ C_ERROR,
/* 18 */ C_ERROR,
/* 19 */ C_ERROR,
/* 1A */ C_ERROR,
/* 1B */ C_ERROR,
/* 1C */ C_ERROR,
/* 1D */ C_ERROR,
/* 1E */ C_ERROR,
/* 1F */ C_ERROR,
/* 20 */ C_ERROR,
/* 21 */ C_ERROR,
/* 22 */ C_ERROR,
/* 23 */ C_ERROR,
/* 24 */ C_ERROR,
/* 25 */ C_ERROR,
/* 26 */ C_ERROR,
/* 27 */ C_ERROR,
/* 28 */ C_ERROR,
/* 29 */ C_ERROR,
/* 2A */ C_ERROR,
/* 2B */ C_ERROR,
/* 2C */ C_ERROR,
/* 2D */ C_ERROR,
/* 2E */ C_ERROR,
/* 2F */ C_ERROR,
/* 30 */ C_ERROR,
/* 31 */ C_ERROR,
/* 32 */ C_ERROR,
/* 33 */ C_ERROR,
/* 34 */ C_ERROR,
/* 35 */ C_ERROR,
/* 36 */ C_ERROR,
/* 37 */ C_ERROR,
/* 38 */ C_ERROR,
/* 39 */ C_ERROR,
/* 3A */ C_ERROR,
/* 3B */ C_ERROR,
/* 3C */ C_ERROR,
/* 3D */ C_ERROR,
/* 3E */ C_ERROR,
/* 3F */ C_ERROR,
/* 40 */ C_ERROR,
/* 41 */ C_ERROR,
/* 42 */ C_ERROR,
/* 43 */ C_ERROR,
/* 44 */ C_ERROR,
/* 45 */ C_ERROR,
/* 46 */ C_ERROR,
/* 47 */ C_ERROR,
/* 48 */ C_ERROR,
/* 49 */ C_ERROR,
/* 4A */ C_ERROR,
/* 4B */ C_ERROR,
/* 4C */ C_ERROR,
/* 4D */ C_ERROR,
/* 4E */ C_ERROR,
/* 4F */ C_ERROR,
/* 50 */ C_ERROR,
/* 51 */ C_ERROR,
/* 52 */ C_ERROR,
/* 53 */ C_ERROR,
/* 54 */ C_ERROR,
/* 55 */ C_ERROR,
/* 56 */ C_ERROR,
/* 57 */ C_ERROR,
/* 58 */ C_ERROR,
/* 59 */ C_ERROR,
/* 5A */ C_ERROR,
/* 5B */ C_ERROR,
/* 5C */ C_ERROR,
/* 5D */ C_ERROR,
/* 5E */ C_ERROR,
/* 5F */ C_ERROR,
/* 60 */ C_ERROR,
/* 61 */ C_ERROR,
/* 62 */ C_ERROR,
/* 63 */ C_ERROR,
/* 64 */ C_ERROR,
/* 65 */ C_ERROR,
/* 66 */ C_ERROR,
/* 67 */ C_ERROR,
/* 68 */ C_ERROR,
/* 69 */ C_ERROR,
/* 6A */ C_ERROR,
/* 6B */ C_ERROR,
/* 6C */ C_ERROR,
/* 6D */ C_ERROR,
/* 6E */ C_ERROR,
/* 6F */ C_ERROR,
/* 70 */ C_ERROR,
/* 71 */ C_ERROR,
/* 72 */ C_ERROR,
/* 73 */ C_ERROR,
/* 74 */ C_ERROR,
/* 75 */ C_ERROR,
/* 76 */ C_ERROR,
/* 77 */ C_ERROR,
/* 78 */ C_ERROR,
/* 79 */ C_ERROR,
/* 7A */ C_ERROR,
/* 7B */ C_ERROR,
/* 7C */ C_ERROR,
/* 7D */ C_ERROR,
/* 7E */ C_ERROR,
/* 7F */ C_ERROR,
/* 80 */ C_DATA66+C_REL,
/* 81 */ C_DATA66+C_REL,
/* 82 */ C_DATA66+C_REL,
/* 83 */ C_DATA66+C_REL,
/* 84 */ C_DATA66+C_REL,
/* 85 */ C_DATA66+C_REL,
/* 86 */ C_DATA66+C_REL,
/* 87 */ C_DATA66+C_REL,
/* 88 */ C_DATA66+C_REL,
/* 89 */ C_DATA66+C_REL,
/* 8A */ C_DATA66+C_REL,
/* 8B */ C_DATA66+C_REL,
/* 8C */ C_DATA66+C_REL,
/* 8D */ C_DATA66+C_REL,
/* 8E */ C_DATA66+C_REL,
/* 8F */ C_DATA66+C_REL,
/* 90 */ C_MODRM,
/* 91 */ C_MODRM,
/* 92 */ C_MODRM,
/* 93 */ C_MODRM,
/* 94 */ C_MODRM,
/* 95 */ C_MODRM,
/* 96 */ C_MODRM,
/* 97 */ C_MODRM,
/* 98 */ C_MODRM,
/* 99 */ C_MODRM,
/* 9A */ C_MODRM,
/* 9B */ C_MODRM,
/* 9C */ C_MODRM,
/* 9D */ C_MODRM,
/* 9E */ C_MODRM,
/* 9F */ C_MODRM,
/* A0 */ 0,
/* A1 */ 0,
/* A2 */ 0,
/* A3 */ C_MODRM,
/* A4 */ C_MODRM+C_DATA1,
/* A5 */ C_MODRM,
/* A6 */ C_ERROR,
/* A7 */ C_ERROR,
/* A8 */ 0,
/* A9 */ 0,
/* AA */ 0,
/* AB */ C_MODRM,
/* AC */ C_MODRM+C_DATA1,
/* AD */ C_MODRM,
/* AE */ C_ERROR,
/* AF */ C_MODRM,
/* B0 */ C_MODRM,
/* B1 */ C_MODRM,
/* B2 */ C_MODRM,
/* B3 */ C_MODRM,
/* B4 */ C_MODRM,
/* B5 */ C_MODRM,
/* B6 */ C_MODRM,
/* B7 */ C_MODRM,
/* B8 */ C_ERROR,
/* B9 */ C_ERROR,
/* BA */ C_MODRM+C_DATA1,
/* BB */ C_MODRM,
/* BC */ C_MODRM,
/* BD */ C_MODRM,
/* BE */ C_MODRM,
/* BF */ C_MODRM,
/* C0 */ C_MODRM,
/* C1 */ C_MODRM,
/* C2 */ C_ERROR,
/* C3 */ C_ERROR,
/* C4 */ C_ERROR,
/* C5 */ C_ERROR,
/* C6 */ C_ERROR,
/* C7 */ C_ERROR,
/* C8 */ 0,
/* C9 */ 0,
/* CA */ 0,
/* CB */ 0,
/* CC */ 0,
/* CD */ C_DATA1,
/* CE */ 0,
/* CF */ 0,
/* D0 */ C_ERROR,
/* D1 */ C_ERROR,
/* D2 */ C_ERROR,
/* D3 */ C_ERROR,
/* D4 */ C_ERROR,
/* D5 */ C_ERROR,
/* D6 */ C_ERROR,
/* D7 */ C_ERROR,
/* D8 */ C_ERROR,
/* D9 */ C_ERROR,
/* DA */ C_ERROR,
/* DB */ C_ERROR,
/* DC */ C_ERROR,
/* DD */ C_ERROR,
/* DE */ C_ERROR,
/* DF */ C_ERROR,
/* E0 */ C_ERROR,
/* E1 */ C_ERROR,
/* E2 */ C_ERROR,
/* E3 */ C_ERROR,
/* E4 */ C_ERROR,
/* E5 */ C_ERROR,
/* E6 */ C_ERROR,
/* E7 */ C_ERROR,
/* E8 */ C_ERROR,
/* E9 */ C_ERROR,
/* EA */ C_ERROR,
/* EB */ C_ERROR,
/* EC */ C_ERROR,
/* ED */ C_ERROR,
/* EE */ C_ERROR,
/* EF */ C_ERROR,
/* F0 */ C_ERROR,
/* F1 */ C_ERROR,
/* F2 */ C_ERROR,
/* F3 */ C_ERROR,
/* F4 */ C_ERROR,
/* F5 */ C_ERROR,
/* F6 */ C_ERROR,
/* F7 */ C_ERROR,
/* F8 */ C_ERROR,
/* F9 */ C_ERROR,
/* FA */ C_ERROR,
/* FB */ C_ERROR,
/* FC */ C_ERROR,
/* FD */ C_ERROR,
/* FE */ C_ERROR,
/* FF */ C_ERROR
}; // ade32_table[]
int disasm(BYTE* opcode0, disasm_struct* diza)
{
BYTE* opcode = opcode0;
memset(diza, 0x00, sizeof(disasm_struct));
diza->disasm_defdata = 4;
diza->disasm_defaddr = 4;
if(*(WORD*)opcode == 0x0000)
return 0;
if(*(WORD*)opcode == 0xFFFF)
return 0;
DWORD flag = 0;
repeat_prefix:
BYTE c = *opcode++;
DWORD t = ade32_table[ c ];
if(t & C_ANYPREFIX)
{
if(flag & t)
return 0;
flag |= t;
if(t & C_67)
diza->disasm_defaddr ^= 2^4;
else if(t & C_66)
diza->disasm_defdata ^= 2^4;
else if(t & C_SEG)
diza->disasm_seg = c;
else if(t & C_REP)
diza->disasm_rep = c;
// LOCK
goto repeat_prefix;
} // C_ANYPREFIX
flag |= t;
diza->disasm_opcode = c;
if(c == 0x0F)
{
c = *opcode++;
diza->disasm_opcode2 = c;
flag |= ade32_table[256+c]; // 2nd flagtable half
if(flag == C_ERROR)
return 0;
}
else if(c == 0xF7)
{
if(((*opcode) & 0x38) == 0)
flag |= C_DATA66;
}
else if(c == 0xF6)
{
if(((*opcode) & 0x38) == 0)
flag |= C_DATA1;
}
else if(c == 0xCD)
{
if(*opcode == 0x20)
flag |= C_DATA4;
}
if(flag & C_MODRM)
{
c = *opcode++;
diza->disasm_modrm = c;
if(((c & 0x38) == 0x20) && (diza->disasm_opcode == 0xFF))
flag |= C_STOP;
BYTE mod = c & 0xC0;
BYTE rm = c & 0x07;
if(mod != 0xC0)
{
if(diza->disasm_defaddr == 4)
{
if(rm == 4)
{
flag |= C_SIB;
c = *opcode++;
diza->disasm_sib = c;
rm = c & 0x07;
}
if(mod == 0x40)
flag |= C_ADDR1;
else if(mod == 0x80)
flag |= C_ADDR4;
else if (rm == 5)
flag |= C_ADDR4;
}
else
{ // MODRM 16-bit
if(mod == 0x40)
flag |= C_ADDR1;
else if(mod == 0x80)
flag |= C_ADDR2;
else if(rm == 6)
flag |= C_ADDR2;
}
}
} // C_MODRM
diza->disasm_flag = flag;
DWORD a = flag & (C_ADDR1 | C_ADDR2 | C_ADDR4);
DWORD d = (flag & (C_DATA1 | C_DATA2 | C_DATA4)) >> 8;
if(flag & C_ADDR67)
a += diza->disasm_defaddr;
if(flag & C_DATA66)
d += diza->disasm_defdata;
diza->disasm_addrsize = a;
diza->disasm_datasize = d;
DWORD i;
for(i = 0; i < a; i++)
diza->disasm_addr_b[i] = *opcode++;
for(i = 0; i < d; i++)
diza->disasm_data_b[i] = *opcode++;
diza->disasm_len = opcode - opcode0;
return diza->disasm_len;
} // disasm()
int oplen(BYTE *opcode)
{
disasm_struct diza;
memset(&diza,0,sizeof(diza));
disasm((BYTE*)opcode,&diza);
if((diza.disasm_flag == C_ERROR) || ((diza.disasm_flag&C_STOP) == C_STOP) || ((diza.disasm_flag&C_REL)==C_REL) || ((diza.disasm_flag&C_BAD)==C_BAD))
return -1;
return diza.disasm_len;
}
StdAfx.cpp
Code:
#include "StdAfx.h"
d3dfont.cpp
Code:
#include <stdio.h>
#include <tchar.h>
#include <d3dx9.h>
#include "d3dfont.h"
//-----------------------------------------------------------------------------
// Custom vertex types for rendering text
//-----------------------------------------------------------------------------
#define MAX_NUM_VERTICES 50*6
struct FONT2DVERTEX { D3DXVECTOR4 p; DWORD color; FLOAT tu, tv; };
struct FONT3DVERTEX { D3DXVECTOR3 p; D3DXVECTOR3 n; FLOAT tu, tv; };
#define D3DFVF_FONT2DVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1)
#define D3DFVF_FONT3DVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1)
inline FONT2DVERTEX InitFont2DVertex( const D3DXVECTOR4& p, D3DCOLOR color,
FLOAT tu, FLOAT tv )
{
FONT2DVERTEX v; v.p = p; v.color = color; v.tu = tu; v.tv = tv;
return v;
}
inline FONT3DVERTEX InitFont3DVertex( const D3DXVECTOR3& p, const D3DXVECTOR3& n,
FLOAT tu, FLOAT tv )
{
FONT3DVERTEX v; v.p = p; v.n = n; v.tu = tu; v.tv = tv;
return v;
}
//-----------------------------------------------------------------------------
// Name: CD3DFont()
// Desc: Font class constructor
//-----------------------------------------------------------------------------
CD3DFont::CD3DFont( const TCHAR* strFontName, DWORD dwHeight, DWORD dwFlags )
{
_***ncpy( m_strFontName, strFontName, sizeof(m_strFontName) / sizeof(TCHAR) );
m_strFontName[sizeof(m_strFontName) / sizeof(TCHAR) - 1] = _T('\0');
m_dwFontHeight = dwHeight;
m_dwFontFlags = dwFlags;
m_dwSpacing = 0;
m_pd3dDevice = NULL;
m_pTexture = NULL;
m_pVB = NULL;
m_pStateBlockSaved = NULL;
m_pStateBlockDrawText = NULL;
}
//-----------------------------------------------------------------------------
// Name: ~CD3DFont()
// Desc: Font class destructor
//-----------------------------------------------------------------------------
CD3DFont::~CD3DFont()
{
InvalidateDeviceObjects();
DeleteDeviceObjects();
}
//-----------------------------------------------------------------------------
// Name: InitDeviceObjects()
// Desc: Initializes device-dependent objects, including the vertex buffer used
// for rendering text and the texture map which stores the font image.
//-----------------------------------------------------------------------------
HRESULT CD3DFont::InitDeviceObjects( LPDIRECT3DDEVICE9 pd3dDevice )
{
HRESULT hr;
// Keep a local copy of the device
m_pd3dDevice = pd3dDevice;
// Establish the font and texture size
m_fTextScale = 1.0f; // Draw fonts into texture without scaling
// Large fonts need larger textures
if( m_dwFontHeight > 60 )
m_dwTexWidth = m_dwTexHeight = 2048;
else if( m_dwFontHeight > 30 )
m_dwTexWidth = m_dwTexHeight = 1024;
else if( m_dwFontHeight > 15 )
m_dwTexWidth = m_dwTexHeight = 512;
else
m_dwTexWidth = m_dwTexHeight = 256;
// If requested texture is too big, use a smaller texture and smaller font,
// and scale up when rendering.
D3DCAPS9 d3dCaps;
m_pd3dDevice->GetDeviceCaps( &d3dCaps );
if( m_dwTexWidth > d3dCaps.MaxTextureWidth )
{
m_fTextScale = (FLOAT)d3dCaps.MaxTextureWidth / (FLOAT)m_dwTexWidth;
m_dwTexWidth = m_dwTexHeight = d3dCaps.MaxTextureWidth;
}
// Create a new texture for the font
hr = m_pd3dDevice->CreateTexture( m_dwTexWidth, m_dwTexHeight, 1,
0, D3DFMT_A4R4G4B4,
D3DPOOL_MANAGED, &m_pTexture, NULL );
if( FAILED(hr) )
return hr;
// Prepare to create a bitmap
DWORD* pBitmapBits;
BITMAPINFO bmi;
ZeroMemory( &bmi.bmiHeader, sizeof(BITMAPINFOHEADER) );
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = (int)m_dwTexWidth;
bmi.bmiHeader.biHeight = -(int)m_dwTexHeight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biBitCount = 32;
// Create a DC and a bitmap for the font
HDC hDC = CreateCompatibleDC( NULL );
HBITMAP hbmBitmap = CreateDIBSection( hDC, &bmi, DIB_RGB_COLORS,
(void**)&pBitmapBits, NULL, 0 );
SetMapMode( hDC, MM_TEXT );
// Create a font. By specifying ANTIALIASED_QUALITY, we might get an
// antialiased font, but this is not guaranteed.
INT nHeight = -MulDiv( m_dwFontHeight,
(INT)(GetDeviceCaps(hDC, LOGPIXELSY) * m_fTextScale), 72 );
DWORD dwBold = (m_dwFontFlags&D3DFONT_BOLD) ? FW_BOLD : FW_NORMAL;
DWORD dwItalic = (m_dwFontFlags&D3DFONT_ITALIC) ? TRUE : FALSE;
HFONT hFont = CreateFont( nHeight, 0, 0, 0, dwBold, dwItalic,
FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
VARIABLE_PITCH, m_strFontName );
if( NULL==hFont )
return E_FAIL;
SelectObject( hDC, hbmBitmap );
SelectObject( hDC, hFont );
// Set text properties
SetTextColor( hDC, RGB(255,255,255) );
SetBkColor( hDC, 0x00000000 );
SetTextAlign( hDC, TA_TOP );
// Loop through all printable character and output them to the bitmap..
// Meanwhile, keep track of the corresponding tex coords for each character.
DWORD x = 0;
DWORD y = 0;
TCHAR str[2] = _T("x");
SIZE size;
// Calculate the spacing between characters based on line height
GetTextExtentPoint32( hDC, TEXT(" "), 1, &size );
x = m_dwSpacing = (DWORD) ceil(size.cy * 0.3f);
for( TCHAR c=32; c<127; c++ )
{
str[0] = c;
GetTextExtentPoint32( hDC, str, 1, &size );
if( (DWORD)(x + size.cx + m_dwSpacing) > m_dwTexWidth )
{
x = m_dwSpacing;
y += size.cy+1;
}
ExtTextOut( hDC, x+0, y+0, ETO_OPAQUE, NULL, str, 1, NULL );
m_fTexCoords[c-32][0] = ((FLOAT)(x + 0 - m_dwSpacing))/m_dwTexWidth;
m_fTexCoords[c-32][1] = ((FLOAT)(y + 0 + 0 ))/m_dwTexHeight;
m_fTexCoords[c-32][2] = ((FLOAT)(x + size.cx + m_dwSpacing))/m_dwTexWidth;
m_fTexCoords[c-32][3] = ((FLOAT)(y + size.cy + 0 ))/m_dwTexHeight;
x += size.cx + (2 * m_dwSpacing);
}
// Lock the surface and write the alpha values for the set pixels
D3DLOCKED_RECT d3dlr;
m_pTexture->LockRect( 0, &d3dlr, 0, 0 );
BYTE* pDstRow = (BYTE*)d3dlr.pBits;
WORD* pDst16;
BYTE bAlpha; // 4-bit measure of pixel intensity
for( y=0; y < m_dwTexHeight; y++ )
{
pDst16 = (WORD*)pDstRow;
for( x=0; x < m_dwTexWidth; x++ )
{
bAlpha = (BYTE)((pBitmapBits[m_dwTexWidth*y + x] & 0xff) >> 4);
if (bAlpha > 0)
{
*pDst16++ = (WORD) ((bAlpha << 12) | 0x0fff);
}
else
{
*pDst16++ = 0x0000;
}
}
pDstRow += d3dlr.Pitch;
}
// Done updating texture, so clean up used objects
m_pTexture->UnlockRect(0);
DeleteObject( hbmBitmap );
DeleteDC( hDC );
DeleteObject( hFont );
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: RestoreDeviceObjects()
// Desc:
//-----------------------------------------------------------------------------
HRESULT CD3DFont::RestoreDeviceObjects()
{
HRESULT hr;
// Create vertex buffer for the letters
int vertexSize = max( sizeof(FONT2DVERTEX), sizeof(FONT3DVERTEX ) );
if( FAILED( hr = m_pd3dDevice->CreateVertexBuffer( MAX_NUM_VERTICES * vertexSize,
D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, 0,
D3DPOOL_DEFAULT, &m_pVB, NULL ) ) )
{
return hr;
}
// Create the state blocks for rendering text
for( UINT which=0; which<2; which++ )
{
m_pd3dDevice->BeginStateBlock();
m_pd3dDevice->SetTexture( 0, m_pTexture );
if ( D3DFONT_ZENABLE & m_dwFontFlags )
m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
else
m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
m_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
m_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
m_pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );
m_pd3dDevice->SetRenderState( D3DRS_ALPHAREF, 0x08 );
m_pd3dDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL );
m_pd3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );
m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );
m_pd3dDevice->SetRenderState( D3DRS_STENCILENABLE, FALSE );
m_pd3dDevice->SetRenderState( D3DRS_CLIPPING, TRUE );
m_pd3dDevice->SetRenderState( D3DRS_CLIPPLANEENABLE, FALSE );
m_pd3dDevice->SetRenderState( D3DRS_VERTEXBLEND, D3DVBF_DISABLE );
m_pd3dDevice->SetRenderState( D3DRS_INDEXEDVERTEXBLENDENABLE, FALSE );
m_pd3dDevice->SetRenderState( D3DRS_FOGENABLE, FALSE );
m_pd3dDevice->SetRenderState( D3DRS_COLORWRITEENABLE,
D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN |
D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
m_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );
m_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE );
if( which==0 )
m_pd3dDevice->EndStateBlock( &m_pStateBlockSaved );
else
m_pd3dDevice->EndStateBlock( &m_pStateBlockDrawText );
}
return S_OK;
}
#define SAFE_RELEASE(p) if (p) { free(p); p=NULL; }
//-----------------------------------------------------------------------------
// Name: InvalidateDeviceObjects()
// Desc: Destroys all device-dependent objects
//-----------------------------------------------------------------------------
HRESULT CD3DFont::InvalidateDeviceObjects()
{
SAFE_RELEASE( m_pVB );
SAFE_RELEASE( m_pStateBlockSaved );
SAFE_RELEASE( m_pStateBlockDrawText );
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: DeleteDeviceObjects()
// Desc: Destroys all device-dependent objects
//-----------------------------------------------------------------------------
HRESULT CD3DFont::DeleteDeviceObjects()
{
SAFE_RELEASE( m_pTexture );
m_pd3dDevice = NULL;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: GetTextExtent()
// Desc: Get the dimensions of a text string
//-----------------------------------------------------------------------------
HRESULT CD3DFont::GetTextExtent( const TCHAR* strText, SIZE* pSize )
{
if( NULL==strText || NULL==pSize )
return E_FAIL;
FLOAT fRowWidth = 0.0f;
FLOAT fRowHeight = (m_fTexCoords[0][3]-m_fTexCoords[0][1])*m_dwTexHeight;
FLOAT fWidth = 0.0f;
FLOAT fHeight = fRowHeight;
while( *strText )
{
TCHAR c = *strText++;
if( c == _T('\n') )
{
fRowWidth = 0.0f;
fHeight += fRowHeight;
}
if( (c-32) < 0 || (c-32) >= 128-32 )
continue;
FLOAT tx1 = m_fTexCoords[c-32][0];
FLOAT tx2 = m_fTexCoords[c-32][2];
fRowWidth += (tx2-tx1)*m_dwTexWidth - 2*m_dwSpacing;
if( fRowWidth > fWidth )
fWidth = fRowWidth;
}
pSize->cx = (int)fWidth;
pSize->cy = (int)fHeight;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: DrawText()
// Desc: Draws 2D text. Note that sx and sy are in pixels
//-----------------------------------------------------------------------------
HRESULT CD3DFont::DrawText( FLOAT sx, FLOAT sy, DWORD dwColor,
const TCHAR* strText, DWORD dwFlags )
{
if( m_pd3dDevice == NULL )
return E_FAIL;
// Setup renderstate
m_pStateBlockSaved->Capture();
m_pStateBlockDrawText->Apply();
m_pd3dDevice->SetFVF( D3DFVF_FONT2DVERTEX );
m_pd3dDevice->SetPixelShader( NULL );
m_pd3dDevice->SetStreamSource( 0, m_pVB, 0, sizeof(FONT2DVERTEX) );
// Set filter states
if( dwFlags & D3DFONT_FILTERED )
{
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
}
if( dwFlags & D3DFONT_RIGHT ) {
SIZE sz;
GetTextExtent( strText, &sz );
sx -= (FLOAT)sz.cx;
} else if( dwFlags & D3DFONT_CENTERED ) {
SIZE sz;
GetTextExtent( strText, &sz );
sx -= (FLOAT)sz.cx/2.0f;
}
// Adjust for character spacing
sx -= m_dwSpacing;
FLOAT fStartX = sx;
// Fill vertex buffer
FONT2DVERTEX* pVertices = NULL;
DWORD dwNumTriangles = 0;
m_pVB->Lock( 0, 0, (void**)&pVertices, D3DLOCK_DISCARD );
while( *strText )
{
TCHAR c = *strText++;
if( c == _T('\n') )
{
sx = fStartX;
sy += (m_fTexCoords[0][3]-m_fTexCoords[0][1])*m_dwTexHeight;
}
if( (c-32) < 0 || (c-32) >= 128-32 )
continue;
FLOAT tx1 = m_fTexCoords[c-32][0];
FLOAT ty1 = m_fTexCoords[c-32][1];
FLOAT tx2 = m_fTexCoords[c-32][2];
FLOAT ty2 = m_fTexCoords[c-32][3];
FLOAT w = (tx2-tx1) * m_dwTexWidth / m_fTextScale;
FLOAT h = (ty2-ty1) * m_dwTexHeight / m_fTextScale;
if( c != _T(' ') )
{
*pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+0-0.5f,sy+h-0.5f,0.9f,1.0f), dwColor, tx1, ty2 );
*pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+0-0.5f,sy+0-0.5f,0.9f,1.0f), dwColor, tx1, ty1 );
*pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+w-0.5f,sy+h-0.5f,0.9f,1.0f), dwColor, tx2, ty2 );
*pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+w-0.5f,sy+0-0.5f,0.9f,1.0f), dwColor, tx2, ty1 );
*pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+w-0.5f,sy+h-0.5f,0.9f,1.0f), dwColor, tx2, ty2 );
*pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+0-0.5f,sy+0-0.5f,0.9f,1.0f), dwColor, tx1, ty1 );
dwNumTriangles += 2;
if( dwNumTriangles*3 > (MAX_NUM_VERTICES-6) )
{
// Unlock, render, and relock the vertex buffer
m_pVB->Unlock();
m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
pVertices = NULL;
m_pVB->Lock( 0, 0, (void**)&pVertices, D3DLOCK_DISCARD );
dwNumTriangles = 0L;
}
}
sx += w - (2 * m_dwSpacing);
}
// Unlock and render the vertex buffer
m_pVB->Unlock();
if( dwNumTriangles > 0 )
m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
// Restore the modified renderstates
m_pStateBlockSaved->Apply();
return S_OK;
}
Part II
main.cpp
Code:
//D3D Functions by N4n033 hacks and bypass and detours written in ASM by skinnlaw.
#include <d3d9.h>
#include <d3dx9.h>
#include <windows.h>
#include <stdio.h>
#include <fstream>
#include "main.h"
#include <time.h>
#include "byte.h"
#include "ShellApi.h"
#include "hsmethode.h"
#include "detour.h"
#include "d3dmenu.h"
#include "addies.h"
#include "int.h"
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
UINT m_Stride;
UINT OffsetInBytes;
ID3DXFont* pFont;
LPDIRECT3DVERTEXBUFFER9 StreamData;
D3DMenu *SkinnLaw = NULL;
LPDIRECT3DDEVICE9 pDevice = 0;
LPDIRECT3DTEXTURE9 aRed,aGreen,aBlue,aYellow,aPurple,aPink,aOrange,aGrey,aCyan,aBlack,aWhite,bRed,bGreen,bBlue,bPurple,bPink,bOrange,bYellow,bBlack,bWhite;
char* sFolder [] = { " | + | "," | - | " };
char* sOnOff [] = { "[ OFF ]","[ ON ]" };
//compare two string len
bool cmpstrlen(const char* str1,const char* str2)
{
int len1,len2;
len1 = strlen(str1);
len2 = strlen(str2);
if(len1 != len2)
return false;
return true;
}
void* WriteMEM( void* pvADRess, const void* pvBuffer, size_t stLen )
{
MEMORY_BASIC_INFORMATION mbi;
VirtualQuery( pvADRess, &mbi, sizeof( mbi ) );
VirtualProtect( mbi.BaseAddress, mbi.RegionSize, PAGE_EXECUTE_READWRITE, &mbi.Protect );
void* pvRetn = memcpy( pvADRess, pvBuffer, stLen );
VirtualProtect( mbi.BaseAddress, mbi.RegionSize, mbi.Protect, &mbi.Protect );
FlushInstructionCache( GetCurrentProcess( ), pvADRess, stLen );
return pvRetn;
}
void WriteAsm( void* pxADRess, BYTE *code, int size )
{
unsigned long Protection;
VirtualProtect((void*)pxADRess, size, PAGE_READWRITE, &Protection);
memcpy((void*)pxADRess, (const void*)code, size);
VirtualProtect((void*)pxADRess, size, Protection, 0);
}
void WriteMemory(PVOID ADRess, void* val, int bytes)
{
DWORD d, ds;
VirtualProtect(ADRess, bytes, PAGE_EXECUTE_READWRITE, &d);
memcpy(ADRess, val, bytes);
VirtualProtect(ADRess,bytes,d,&ds);
}
void MakeLong(int adr , long x)
{
unsigned long size;
VirtualProtect((void*)adr, sizeof(x), PAGE_READWRITE, &size);
memcpy((void*)adr, &x , sizeof(x));
VirtualProtect((void*)adr, sizeof(x), size, 0);
}
//some macro
#define writebyte(addy,value) *(BYTE*)addy = value;
#define writefloat(addy,value) *(float*)addy = value;
#define writedouble(addy,value) *(double*)addy = value;
#define writelong(addy,value) *(long*)addy = value;
#define writeint(addy,value) *(int*)addy = value;
#define writedword(addy,value) *(DWORD*)addy = value;
/************************************/
/* Create and draw menu */
/************************************/
// int //
// menu//
void BuildMenu(void)
{
SkinnLaw->AddGroup("->Group1",&mi.item1,sFolder);
if(mi.item1)
{
SkinnLaw->AddText("Hooked by SkinnLaw");
}
}
void DrawBox(int x, int y, int w, int h, D3DCOLOR Color,LPDIRECT3DDEVICE9 pDevice)
{
struct Vertex {
float x,y,z,ht;
DWORD Color;
};
DWORD ColorBG;
Vertex V[8];
V[0].Color = V[1].Color = V[2].Color = V[3].Color = Color;
V[0].z = V[1].z = V[2].z = V[3].z = 0.0f;
V[0].ht = V[1].ht = V[2].ht = V[3].ht = 0.0f;
V[0].x = V[1].x = (float)x;
V[0].y = V[2].y = (float)(y + h);
V[1].y = V[3].y = (float)y;
V[2].x = V[3].x = (float)(x + w);
pDevice->SetTexture(0, NULL);
pDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,V,sizeof(Vertex));
}
void DrawBox_s(LPDIRECT3DDEVICE9 pDevice , int x, int y, int w, int h, DWORD Color)
{
D3DRECT rec;
rec.x1 = x;
rec.x2 = x + w;
rec.y1 = y;
rec.y2 = y + h;
pDevice->Clear( 1, &rec, D3DCLEAR_TARGET, Color, 0, 0 );
}
void DrawRectangle(int x, int y, int w, int h, int s, DWORD Color, LPDIRECT3DDEVICE9 pDevice)
{
DrawBox_s(pDevice, x, y, w, s, Color);
DrawBox_s(pDevice, x, y, s, h, Color);
DrawBox_s(pDevice, (x+w), y, s, h, Color);
DrawBox_s(pDevice, x, (y+h), w+s, s, Color);
}
void DrawMenu(LPDIRECT3DDEVICE9 pDevice)
{
if (!SkinnLaw)
{
SkinnLaw = new D3DMenu("<-SkinnLaw Public Hook->",130,300);
SkinnLaw->visible=1;
SkinnLaw->col_title = Green;
}else{
if (!SkinnLaw->noitems)BuildMenu();
if (SkinnLaw->visible==1)
{
if(SkinnLaw->visible==1){
/*DrawSprite(pDevice);*/
}
if(CH_BC==0)
{
DrawBox((float)13,(float)22,(float)160,(float)21,BlackTrans,pDevice);
DrawBox((float)13,(float)43,(float)160,(float)SkinnLaw->noitems*SkinnLaw->height+12,BlackTrans,pDevice);// Grey
}
if(CH_BC==1)
{
DrawBox((float)13,(float)22,(float)160,(float)21,GREEN,pDevice);
DrawBox((float)13,(float)55,(float)162,(float)SkinnLaw->noitems*SkinnLaw->height+12,GREY,pDevice);
}
if(CH_BC==2)
{
DrawBox((float)13,(float)22,(float)162,(float)21,GREEN,pDevice);
DrawBox((float)13,(float)43,(float)162,(float)SkinnLaw->noitems*SkinnLaw->height+12,GhostGREEN,pDevice);
}
if(CH_BC==3)
{
DrawBox((float)13,(float)22,(float)162,(float)21,GhostRED,pDevice);
DrawBox((float)13,(float)43,(float)162,(float)SkinnLaw->noitems*SkinnLaw->height+12,GhostRED,pDevice);
}
if(CH_BC==4)
{
DrawBox((float)13,(float)22,(float)162,(float)21,GhostPURPLE,pDevice);
DrawBox((float)13,(float)43,(float)162,(float)SkinnLaw->noitems*SkinnLaw->height+12,GhostPURPLE,pDevice);
}
{ "OFF","Red","Green","Blue","Yellow","Purple","Pink","Black","Cyan","White" ;};
if(CH_BC==5)
{
DrawBox((float)13,(float)22,(float)162,(float)21,GhostYELLOW,pDevice);
DrawBox((float)13,(float)43,(float)162,(float)SkinnLaw->noitems*SkinnLaw->height+12,GhostYELLOW,pDevice);
}
if(CH_BC==6)
{
DrawBox((float)13,(float)22,(float)162,(float)21,GhostPINK,pDevice);
DrawBox((float)13,(float)43,(float)162,(float)SkinnLaw->noitems*SkinnLaw->height+12,GhostPINK,pDevice);
}
if(CH_BC==7)
{
DrawBox((float)13,(float)22,(float)162,(float)21,BlackTrans,pDevice);
DrawBox((float)13,(float)43,(float)162,(float)SkinnLaw->noitems*SkinnLaw->height+12,BlackTrans,pDevice);
}
if(CH_BC==7)
{
DrawBox((float)13,(float)22,(float)162,(float)21,Red,pDevice);
DrawBox((float)13,(float)43,(float)162,(float)SkinnLaw->noitems*SkinnLaw->height+12,Blue,pDevice);
}
if(CH_BC==8)
{
DrawBox((float)13,(float)22,(float)162,(float)21,GhostRED,pDevice);
DrawBox((float)13,(float)43,(float)162,(float)SkinnLaw->noitems*SkinnLaw->height+12,GhostRED,pDevice);
}
DrawRectangle((float)13,22,(float)162,(float)21,1,GhostBLUE,pDevice);
DrawRectangle((float)13,43,(float)162,(float)SkinnLaw->noitems*SkinnLaw->height+12,1,GhostBLUE,pDevice);
}
SkinnLaw->Show(pFont,pDevice);
SkinnLaw->Nav();
}
}
void HackThread(void)
{
//put hacks here
}
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;
}
HRESULT __stdcall myPresent ( LPDIRECT3DDEVICE9 pDevice, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion)
{
if(!Create)
{
D3DXCreateFont(pDevice, 14, 0, FW_HEAVY, 0, FALSE, DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS, DEFAULT_QUALITY, /*DEFAULT_PITCH | */FF_DONTCARE, TEXT("Arial Rounded MT"), &pFont );
if(pFont == NULL)D3DXCreateFont(pDevice, 14, 0, FW_HEAVY, 0, FALSE, DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS, DEFAULT_QUALITY, /*DEFAULT_PITCH | */FF_DONTCARE, TEXT("Arial"), &pFont );
Create = true;
}
if( pFont == NULL )
pFont->OnLostDevice();
else
DrawMenu(pDevice);
DrawMenu(pDevice);
pFont->OnLostDevice();
pFont->OnResetDevice();
HackThread();
if(Color)
{
GenerateTexture(pDevice, &aRed, Red);
GenerateTexture(pDevice, &aYellow, Yellow);
GenerateTexture(pDevice, &aGreen, Green);
GenerateTexture(pDevice, &aBlue, Blue);
GenerateTexture(pDevice, &aPurple, Purple);
GenerateTexture(pDevice, &aPink, Pink);
GenerateTexture(pDevice, &aOrange, Orange);
GenerateTexture(pDevice, &aBlack, Black);
GenerateTexture(pDevice, &aWhite, White);
GenerateTexture(pDevice, &aGrey, Grey);
GenerateTexture(pDevice, &aCyan, Cyan);
Color = 0;
}
return pPresent(pDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
}
HRESULT WINAPI myEndScene (LPDIRECT3DDEVICE9 pDevice)
{
return pEndScene(pDevice);
}
HRESULT WINAPI myDrawIndexedPrimitive(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE Type, UINT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount)
{
_asm pushad;
LPDIRECT3DVERTEXBUFFER9 Stream_Data;
UINT Offset = 0;
UINT m_Stride = 0;
if(pDevice->GetStreamSource(0, &Stream_Data, &Offset, &m_Stride) == D3D_OK)
Stream_Data->Release();
_asm popad;
return pDrawIndexedPrimitive(pDevice, Type, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
}
DWORD* FindDevice(DWORD Base)
{
for(long i= 0,n = 0; i < 0x128000; i++ )
{
if(*(BYTE *)(Base+i+0x00)==0xC7)n++;
if(*(BYTE *)(Base+i+0x01)==0x06)n++;
if(*(BYTE *)(Base+i+0x06)==0x89)n++;
if(*(BYTE *)(Base+i+0x07)==0x86)n++;
if(*(BYTE *)(Base+i+0x0C)==0x89)n++;
if(*(BYTE *)(Base+i+0x0D)==0x86)n++;
if(n == 6) return (DWORD*)
(Base + i + 2);n = 0;
}
return(0);
}
#define RESET 16
#define PRESENT 17
#define DRAWINDEXEDPRIMITIVE 82
#define DETOUR_MAX_SRCH_OPLEN 64
//
#define RESET 16
#define PRESENT 17
#define DRAWINDEXEDPRIMITIVE 82
#define O_N_E 1
#define SLEEP123 Sleep
#define DIPUNHOOKTIME 98000
bool bCompare(const BYTE* pData, const BYTE* bMask, const char* szMask)
{
for(;*szMask;++szMask,++pData,++bMask)
if(*szMask=='x' && *pData!=*bMask )
return false;
return (*szMask) == NULL;
}
DWORD FindPattern(DWORD dwADRess,DWORD dwLen,BYTE *bMask,char * szMask)
{
for(DWORD i=0; i < dwLen; i++)
if( bCompare( (BYTE*)( dwADRess+i ),bMask,szMask) )
return (DWORD)(dwADRess+i);
return 0;
}
HRESULT WINAPI myReset (LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters )
{
pFont->OnLostDevice();
HRESULT hRet = pReset(pDevice, pPresentationParameters);
pFont->OnResetDevice();
return hRet;
}
DWORD GetADRessPtr(int index)
{
DWORD* VTableStart = 0;
DWORD dwDevicePointer = FindPattern((DWORD)GetModuleHandle("d3d9.dll"), 0x1280000, (PBYTE)"\xC7\x06\x00\x00\x00\x00\x89\x86\x00\x00\x00\x00\x89\x86", "xx????xx????xx");
memcpy(&VTableStart, (void*)(dwDevicePointer+2), 4);
return VTableStart[index];
}
int Hook()
{
HINSTANCE hInstance;
DWORD VTable[105];
hInstance = 0;
do {
hInstance = GetModuleHandle("d3d9.dll");
if (!hInstance)
Sleep(50);
}while(!hInstance);
if (D3Ddiscover((VOID *)&VTable[0],420)==0) return 0;
{
pReset = (oReset)DetourCreateE9((DWORD)VTable[RESET], (DWORD)myReset,12);
pPresent = (oPresent)DetourCreateE9((DWORD)VTable[PRESENT], (DWORD)myPresent,12);
while(8)
{
if(memcmp((void *)VTable[82],(void*)"\x8B\xFF",2) == 0 )
{
pDrawIndexedPrimitive = (oDrawIndexedPrimitive)DetourMePleaseImNice((DWORD)VTable[82], (DWORD)myDrawIndexedPrimitive,12);
}
Sleep(500);//wont paste ...
}
}
}
///************************************///
//* ATTACH DLL TO PROCESS *//
/************************************/
BOOL WINAPI DllMain(HMODULE hDll, DWORD dwReason, LPVOID lpReserved)
{
if (dwReason==DLL_PROCESS_ATTACH)
{
MessageBoxA(NULL, "Coded by SkinnLaw", "WwW.MPGH.NeT", MB_OK);
void Loop(void);
HideModule(hDll);
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)Hook, NULL, NULL, NULL);
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved);
}
return true;
}
d3dmenu.cpp
Code:
#include "Color.h"
#include "d3dmenu.h"
#include "stdio.h"
/************************************/
/* menu stuff */
/************************************/
char file[255];
extern int mouse_enabled;
extern int drunk_enabled;
//extern void DrawBox( int x, int y, int w, int h, D3DCOLOR Color,LPDIRECT3DDEVICE9 pDevice);
extern void DrawRectangle(int x, int y, int w, int h, int s, DWORD Color, LPDIRECT3DDEVICE9 pDevice);
void D3DMenu::AddItem(char *txt, int *var, char **opt, int maxval, int typ)
{
if (noitems>=(maxitems-3)) return;
MENU[noitems]->typ=typ;
MENU[noitems]->txt=txt;
MENU[noitems]->opt=opt;
MENU[noitems]->var=var;
MENU[noitems]->maxval=maxval;
noitems++;
totheight=(noitems*height)+titleheight;
}
void D3DMenu::AddGroup(char *txt, int *var, char **opt, int maxval)
{
AddItem(txt, var, opt, maxval, MENUFOLDER);
}
void D3DMenu::AddSubb(char *txt, int *var, char **opt, int maxval)
{
AddItem(txt, var, opt, maxval, SUBFOLDER);
}
void D3DMenu::AddText(char *txt, char *opt)
{
AddItem(txt,0,(char **)opt,0,MENUTEXT);
}
void DrawTextR(int x,int y,DWORD color,char *text, ID3DXFont* pFont)
{
RECT rect;
SetRect( &rect, x, y, x, y );
pFont->DrawTextA(NULL,text,-1,&rect, DT_RIGHT|DT_NOCLIP, color );
}
void DrawTextL(int x,int y,DWORD color,char *text, ID3DXFont* pFont)
{
RECT rect;
SetRect( &rect, x, y, x, y );
pFont->DrawTextA(NULL,text,-1,&rect, DT_LEFT|DT_NOCLIP, color );
}
void D3DMenu::DrawTextC(int x,int y,DWORD color,char *text, ID3DXFont* pFont)
{
RECT rect;
SetRect( &rect, x, y, x, y );
pFont->DrawTextA(NULL,text,-1,&rect, DT_CENTER|DT_NOCLIP, color );
}
void D3DMenu::Save(char* szSection, char* szKey, int iValue)
{
char szValue[255];
sprintf(szValue, "%d", iValue);
WritePrivateProfileString(szSection, szKey, szValue, file);
}
int D3DMenu::Load(char* szSection, char* szKey, int iDefaultValue)
{
int iResult = GetPrivateProfileInt(szSection, szKey, iDefaultValue, file);
return iResult;
}
void D3DMenu::Show(ID3DXFont *pFont,LPDIRECT3DDEVICE9 pDevice)
{
int i,val,cy;
DWORD color;
DWORD ColorQ;
if (!visible)
return;
max_x=x+143;
max_y=y+totheight;
cy=y;
if (title)
{
DrawTextC((float)(x+totwidth/3) - 31, (float)cy - 5, col_title, title, pFont);
cy+=titleheight;
}
for(i=0; i<noitems; i++)
{
if(MENU[i]->typ==MENUTEXT)
{
DrawTextL(x, cy, White,MENU[i]->txt, pFont);
if(MENU[i]->opt)
{
DrawTextR((float)(x+ofs), (float)cy, color,(char *)MENU[i]->opt, pFont);
}
}else{
val=(MENU[i]->var)?(*MENU[i]->var):0;
if (m_x>=x && m_x<max_x && m_y>=cy && m_y<(cy+height))
color = Orange;
else
if (i==cur)
color = col_current;
else
if (MENU[i]->typ==MENUFOLDER)
color=col_group;
else
if (MENU[i]->typ==SUBFOLDER)
color=(val)?col_on:col_off;
else
color=(val)?col_on:col_off;
if(val>0)
{
ColorQ = Green;
}else{
ColorQ = Red;
}
DrawTextL((float)x,(float)cy, color,MENU[i]->txt, pFont);
if (MENU[i]->opt)
{
//DrawRectangle((float)17,(float)cy + 4.5,7,7,1,Blue,pDevice);
DrawTextR((float)(x+143),(float)cy, color,(char *)MENU[i]->opt[val], pFont);
}
}
cy+=height;
}
}
int D3DMenu::FindItem(void)
{
if (m_x<=x || m_x>=max_x || m_y<=y || m_y>=max_y) return -1;
if ( (m_y-y) > titleheight) {
int row = (m_y - y - titleheight) / height;
if (MENU[row]->typ==MENUTEXT || MENU[row]->var==0) return -1;
return row;
}
return 999;
}
void D3DMenu::CheckTitleMove(int rm,int mx, int my)
{
m_x=mx;
m_y=my;
if (rm && FindItem()==999)
{
moving=(!moving);
dx=m_x - x;
dy=m_y - y;
} else if (moving && FindItem()!=999)
moving=0;
}
void D3DMenu::Nav(void)
{
if (GetAsyncKeyState(VK_INSERT)&1) visible=(!visible);
if (!visible)
return;
if (GetAsyncKeyState(VK_CONTROL)) {
if (GetAsyncKeyState(VK_UP) &1);
if (GetAsyncKeyState(VK_DOWN) &1);
if (GetAsyncKeyState(VK_LEFT) &1);
if (GetAsyncKeyState(VK_RIGHT)&1);
} else {
if (GetAsyncKeyState(VK_UP)&1) {
do {
cur--;
if (cur<0) cur=noitems-1;
} while (MENU[cur]->typ==MENUTEXT);
} else if (GetAsyncKeyState(VK_DOWN)&1) {
do {
cur++;
if (cur==noitems) cur=0;
} while (MENU[cur]->typ==MENUTEXT);
} else {
POINT mpos;
int pos=cur;
int dir=0;
if (GetAsyncKeyState(VK_LEFT )&1 && MENU[cur]->var && *MENU[cur]->var > 0 ) dir=-1;
if (GetAsyncKeyState(VK_RIGHT)&1 && MENU[cur]->var && *MENU[cur]->var < (MENU[cur]->maxval-1) ) dir=1;
if (dir==0 && (mouse_enabled==1)) {
GetCursorPos(&mpos);
ScreenToClient(GetForegroundWindow(),&mpos);
m_x=mpos.x;
m_y=mpos.y;
m_lm = GetAsyncKeyState(VK_LBUTTON )&1;
m_rm = GetAsyncKeyState(VK_RBUTTON )&1;
if((m_lm || m_rm) && (pos=FindItem())!= -1)
{
if (pos!=999) {
if (m_rm && *MENU[pos]->var>0) dir=-1;
if (m_lm && *MENU[pos]->var<(MENU[pos]->maxval-1)) dir=1;
} else if (m_rm) {
moving=(!moving);
dx=m_x - x;
dy=m_y - y;
}
}
}
if (dir) {
*MENU[pos]->var += dir;
if (MENU[pos]->typ==MENUFOLDER) noitems=0;
if (MENU[pos]->typ==SUBFOLDER) noitems=0;
}
}
}
}
Thanks this took my some hours..
-AeroSkinn.