Useful D3D9/C++ Info, Functions, Cham Alternations, and more!
Here is a list of useful D3D9 Functions, info, and other misc items.
If you would like to add a function, post it below(with credits) and I will add it in here! Also, if I missed any credits, please say so, so that I can add them!
This post actually has enough info for you to make your own D3D9 Base.
Enjoy!
D3D9 vTable Values(Credits to Str1k3r21):
Code:
QueryInterface // 0 AddRef // 1 Release // 2 TestCooperativeLevel // 3 GetAvailableTextureMem // 4 EvictManagedResources // 5 GetDirect3D // 6 GetDeviceCaps // 7 GetDisplayMode // 8 GetCreationParameters // 9 SetCursorProperties // 10 SetCursorPosition // 11 ShowCursor // 12 CreateAdditionalSwapChain // 13 GetSwapChain // 14 GetNumberOfSwapChains // 15 Reset // 16 Present // 17 GetBackBuffer // 18 GetRasterStatus // 19 SetDialogBoxMode // 20 SetGammaRamp // 21 GetGammaRamp // 22 CreateTexture // 23 CreateVolumeTexture // 24 CreateCubeTexture // 25 CreateVertexBuffer // 26 CreateIndexBuffer // 27 CreateRenderTarget // 28 CreateDepthStencilSurface // 29 UpdateSurface // 30 UpdateTexture // 31 GetRenderTargetData // 32 GetFrontBufferData // 33 StretchRect // 34 ColorFill // 35 CreateOffscreenPlainSurface // 36 SetRenderTarget // 37 GetRenderTarget // 38 SetDepthStencilSurface // 39 GetDepthStencilSurface // 40 BeginScene // 41 EndScene // 42 Clear // 43 SetTransform // 44 GetTransform // 45 MultiplyTransform // 46 SetViewport // 47 GetViewport // 48 SetMaterial // 49 GetMaterial // 50 SetLight // 51 GetLight // 52 LightEnable // 53 GetLightEnable // 54 SetClipPlane // 55 GetClipPlane // 56 SetRenderState // 57 GetRenderState // 58 CreateStateBlock // 59 BeginStateBlock // 60 EndStateBlock // 61 SetClipStatus // 62 GetClipStatus // 63 GetTexture // 64 SetTexture // 65 GetTextureStageState // 66 SetTextureStageState // 67 GetSamplerState // 68 SetSamplerState // 69 ValidateDevice // 70 SetPaletteEntries // 71 GetPaletteEntries // 72 SetCurrentTexturePalette // 73 GetCurrentTexturePalette // 74 SetScissorRect // 75 GetScissorRect // 76 SetSoftwareVertexProcessing // 77 GetSoftwareVertexProcessing // 78 SetNPatchMode // 79 GetNPatchMode // 80 DrawPrimitive // 81 DrawIndexedPrimitive // 82 DrawPrimitiveUP // 83 DrawIndexedPrimitiveUP // 84 ProcessVertices // 85 CreateVertexDeclaration // 86 SetVertexDeclaration // 87 GetVertexDeclaration // 88 SetFVF // 89 GetFVF // 90 CreateVertexShader // 91 SetVertexShader // 92 GetVertexShader // 93 SetVertexShaderConstantF // 94 GetVertexShaderConstantF // 95 SetVertexShaderConstantI // 96 GetVertexShaderConstantI // 97 SetVertexShaderConstantB // 98 GetVertexShaderConstantB // 99 SetStreamSource // 100 GetStreamSource // 101 SetStreamSourceFreq // 102 GetStreamSourceFreq // 103 SetIndices // 104 GetIndices // 105 CreatePixelShader // 106 SetPixelShader // 107 GetPixelShader // 108 SetPixelShaderConstantF // 109 GetPixelShaderConstantF // 110 SetPixelShaderConstantI // 111 GetPixelShaderConstantI // 112 SetPixelShaderConstantB // 113 GetPixelShaderConstantB // 114 DrawRectPatch // 115 DrawTriPatch // 116 DeletePatch // 117 CreateQuery // 118
Code:
//Colors are A,R,G,B meaning alpha(opacity), red, green, blue D3DCOLOR RED = D3DCOLOR_ARGB(255, 255, 0, 0); D3DCOLOR GREEN = D3DCOLOR_ARGB(255, 0, 255, 0); D3DCOLOR BLUE = D3DCOLOR_ARGB(255, 0, 0, 255); D3DCOLOR WHITE = D3DCOLOR_ARGB(255, 255, 255, 255); D3DCOLOR BLACK = D3DCOLOR_ARGB(255, 0, 0, 0); D3DCOLOR YELLOW = D3DCOLOR_ARGB(255, 255, 255, 0); D3DCOLOR TEAL = D3DCOLOR_ARGB(255, 0, 255, 255); D3DCOLOR PINK = D3DCOLOR_ARGB(255, 255, 240, 0); D3DCOLOR ORANGE = D3DCOLOR_ARGB(255, 255, 132, 0); D3DCOLOR LIME = D3DCOLOR_ARGB(255, 198, 255, 0); D3DCOLOR SKY BLUE = D3DCOLOR_ARGB(255, 0, 180, 255); D3DCOLOR MAROON = D3DCOLOR_ARGB(255, 142, 30, 0); D3DCOLOR LGRAY = D3DCOLOR_ARGB(255, 174, 174, 174); //Light Gray D3DCOLOR DGRAY = D3DCOLOR_ARGB(255, 71, 65, 64); //Dark Gray D3DCOLOR BROWN = D3DCOLOR_ARGB(255, 77, 46, 38); D3DCOLOR SHIT = D3DCOLOR_ARGB(255, 74, 38, 38); //Shit and brown aint much different
Generate Texture Function(Credits to Azorbix):
Code:
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;
}
Code:
typedef HRESULT (WINAPI* oEndScene)(LPDIRECT3DDEVICE9 pDevice); oEndScene pEndScene;
Code:
HRESULT WINAPI EndScene(LPDIRECT3DDEVICE9 pDevice)
{
return pEndScene(pDevice);
}
Reset(vTable 16):
Code:
typedef HRESULT ( WINAPI* oReset )( LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters ); oReset pReset;
Code:
HRESULT WINAPI Reset(IDirect3DDevice9* pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters )
{
return pReset(pDevice, pPresentationParameters);
}
Code:
typedef HRESULT (WINAPI* oDIP)(LPDIRECT3DDEVICE9 pDevice,D3DPRIMITIVETYPE,int,UINT,UINT,UINT,UINT); oDIP pDIP;
Code:
HRESULT WINAPI DIP(LPDIRECT3DDEVICE9 pDevice,D3DPRIMITIVETYPE Type,int BaseVertexIndex,UINT MinIndex,UINT NumVertices,UINT StartIndex,UINT PrimCount)
{
return pDIP(pDevice, Type, BaseVertexIndex, MinIndex, NumVertices, StartIndex, PrimCount);
}
Find Pattern Function(Credits to d0m1n1c):
Code:
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;
}
Detour Create Function(Credits to Azorbix):
Code:
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);
}
Code:
D3DXCreateTextureFromFileInMemory(pDevice,imagebytes,size,LPDIRECT3DTEXTURE9);
Code:
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);
}
Code:
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 );
}
Code:
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 );
}
Code:
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 );
}
Draw CrossHair Function(Credits To ac1d_bUrn(giving it to me)):
Code:
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);
}
Draw Healthbar Function(Credits To Crash for Coding it, ac1d_bUrn, he gave it to me to add to the list)
Code:
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);
}
Moving Your Menu to Mouse Coordinates On Button(Credits to Zanza):
Code:
int MoveMenu;
if(GetAsyncKeyState(VK_DELETE)) MoveMenu = (!MoveMenu);
if( MoveMenu ) {
POINT myCursor;
GetCursorPos(&myCursor); // get the cursor position.
if(GetAsyncKeyState(VK_LBUTTON)) {
menu.x = myCursor.x; // set the x of your menu to the cursor x position.
menu.y = myCursor.y; // set the y of your menu to the cursor y position.
}
}
Code:
D3DMATERIAL9 GenerateMaterial(int r, int g, int b){
D3DMATERIAL9 myMaterial;
D3DCOLORVALUE myColor;
myColor.a = 255;
myColor.r = (float)r / 255;
myColor.g = (float)g / 255;
myColor.b = (float)b / 255;
myMaterial.Ambient = myColor;
myMaterial.Diffuse = myColor;
myMaterial.Emissive = myColor;
myMaterial.Specular = myColor;
return myMaterial;
}
Light Chams(Credits to Kernel, modified for D3D9 by CodeDemon):
Code:
void SetLightChams(float A, float R, float G, float B, IDirect3DDevice9 *pDevice)
{
D3DMATERIAL9 pMaterial;
ZeroMemory(&pMaterial, sizeof(D3DMATERIAL9));
pDevice->SetRenderState(D3DRS_LIGHTING, TRUE); //Enable Lighting
//Ambient
pMaterial.Ambient.a = (A/255);
pMaterial.Ambient.r = (R/255);
pMaterial.Ambient.g = (G/255);
pMaterial.Ambient.b = (B/255);
//Diffuse
pMaterial.Diffuse.a = (A/255);
pMaterial.Diffuse.r = (R/255);
pMaterial.Diffuse.g = (G/255);
pMaterial.Diffuse.b = (B/255);
//Specular
pMaterial.Specular.a = (A/255);
pMaterial.Specular.r = (R/255);
pMaterial.Specular.g = (G/255);
pMaterial.Specular.b = (B/255);
pDevice->SetMaterial(&pMaterial);
}
Code:
//ZBUFFER OFF(Any Real Coder would know what this is! ) SetLightChams(255,255,0,0, pDevice); pDIP; //ZBUFFER ON SetLightChams(255,0,0,255, pDevice);

Overlay Chams/No Texture Chams(Credits to Pheron):
Code:
//ZBUFFER OFF pDevice->SetRenderState(D3DRS_LIGHTING, true); pDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_FLAT); pDevice->SetRenderState(D3DRS_FOGENABLE, false); pDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_ARGB(255,255,0,0)); pDIP; //ZBUFFER ON pDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_ARGB(255,0,255,0));

Ghost Chams(Credits to Jeff):
Code:
pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,true); pDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVDESTCOLOR); pDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_INVSRCCOLOR); //ZBUFFER OFF pDIP; pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,true); pDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVDESTCOLOR); pDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_INVSRCCOLOR); //ZBUFFER ON

Phantom Chams(Credits to Jeff):
Code:
pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,true); pDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVDESTCOLOR); pDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_INVSRCALPHA); //ZBUFFER OFF pDIP; pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,true); pDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVDESTCOLOR); pDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_INVSRCALPHA); //ZBUFFER ON





the dip bypass.

