D3D AIM CSS
By: SOH
Credits: aBnet/UC/GD/MPH/Sandaasu
Game: Counter Strike Source
Date: January 11 , 2014

AIM.h
Code:
#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>

#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")

#define D3DGetPixel( dwBits, scry, scrx, BPPIXEL, iPitch ) \
	(PDWORD)( (dwBits) + ( ( (scry) * (iPitch) ) + ( (scrx) * ( (BPPIXEL) / 8 ) ) ) )

#define D3D_RELEASE(D3D_PTR) if( D3D_PTR )\
	{ D3D_PTR->Release( ); D3D_PTR	= NULL; }

//#define DEBUG_STRETCHRECT
#define TRIGGER_D3D
#define AIM_D3D

typedef struct _ENTITIES{
	LONG X;
	LONG Y;
	LONG High;
	LONG Low;
	DWORD Count;
}ENTITIES,*PENTITIES;

/* Surface Description */
typedef struct _D3DSURFACE_DESC_EX
{
    UINT				Format;
    UINT				Type;
    DWORD         Usage;
    UINT             Pool;

    UINT				MultiSampleType;
    DWORD         MultiSampleQuality;
    UINT             Width;
    UINT             Height;
} D3DSURFACE_DESC_EX;

VOID WINAPI AimPresent( LPDIRECT3DDEVICE9 pDev );
VOID WINAPI AimReset( LPDIRECT3DDEVICE9 pDevice );
BOOL WINAPI AimDrawPrim( LPDIRECT3DDEVICE9 pDevice, 
	D3DPRIMITIVETYPE Type, INT Base, UINT Min, UINT NumVertices, 
		UINT Start, UINT PrimitiveCount );
BOOL WINAPI GenTex( LPDIRECT3DDEVICE9 pDev, 
		LPDIRECT3DTEXTURE9 * ppD3Dtex, DWORD Color );
MAIN.h
Code:
#define _CRT_SECURE_NO_WARNINGS

#include <windows.h>
#include <stdio.h>
#include "AIM.h"
#include <d3d9.h>
#include <d3dx9.h>

#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")

VOID WINAPI HkD3D( PDWORD vTable );

extern HRESULT (WINAPI* pDrawPrim)
	(LPDIRECT3DDEVICE9, D3DPRIMITIVETYPE, INT, 
		UINT, UINT, UINT, UINT);

extern HRESULT (WINAPI* pClear)(LPDIRECT3DDEVICE9 pDevice9,DWORD Count,CONST 
	D3DRECT* pRects,DWORD Flags,D3DCOLOR Color,float Z,DWORD Stencil);
MODELS.h
Code:
#define TE_DX8 ( Stride == 64 && ( PHOENIX_DX8 || ARCTIC_DX8 || ELITE_DX8 || GUERILLA_DX8 ) )
#define CTE_DX8 ( Stride == 64 && ( GSG9_DX8 || GIGN_DX8 || GIGN_DX8_MASK || SAS_DX8 || SEAL_DX8 ) )
#define TE ( Stride == 32 && ( PHOENIX || ELITE || ARCTIC || GUERILLA ) )
#define CTE ( Stride == 32 && ( GIGN || GIGN_MASK || SAS || GSG9 || SEAL ) )
#define C4 ( ( Stride == 32 || Stride == 64 ) && NumVertices == 758 && PrimitiveCount == 462 )

#define GIGN_MASK (( NumVertices == 41 && PrimitiveCount == 50 ) || \
( NumVertices == 20 && PrimitiveCount == 18 ) || \
( NumVertices == 16 && PrimitiveCount == 14 ) || \
( NumVertices == 11 && PrimitiveCount == 9 ) || \
( NumVertices == 10 && PrimitiveCount == 8 ))

#define GIGN ((NumVertices == 324 && PrimitiveCount == 372) || \
(NumVertices == 466 && PrimitiveCount == 550) || \
(NumVertices == 811 && PrimitiveCount == 989) || \
(NumVertices == 1404 && PrimitiveCount == 1919) || \
(NumVertices == 3304 && PrimitiveCount == 5003) || \
(NumVertices == 2196 && PrimitiveCount == 3061))

#define GIGN_DX8_MASK (( NumVertices == 20 && PrimitiveCount == 18 ) || \
( NumVertices == 16 && PrimitiveCount == 14 ) || \
( NumVertices == 11 && PrimitiveCount == 9 ) || \
( NumVertices == 10 && PrimitiveCount == 8 ) || \
( NumVertices == 41 && PrimitiveCount == 50 ))

#define GIGN_DX8 (( NumVertices == 3473 && PrimitiveCount == 3147 ) || \
( NumVertices == 3473 && PrimitiveCount == 923 ) || \
( NumVertices == 3473 && PrimitiveCount == 408 ) || \
( NumVertices == 3473 && PrimitiveCount == 475 ) || \
( NumVertices == 3473 && PrimitiveCount == 50 ) || \
( NumVertices == 2331 && PrimitiveCount == 1676 ) || \
( NumVertices == 2331 && PrimitiveCount == 940 ) || \
( NumVertices == 2331 && PrimitiveCount == 439 ) || \
( NumVertices == 2331 && PrimitiveCount == 6 ) || \
( NumVertices == 1493 && PrimitiveCount == 1265 ) || \
( NumVertices == 1493 && PrimitiveCount == 485 ) || \
( NumVertices == 1493 && PrimitiveCount == 169 ) || \
( NumVertices == 811 && PrimitiveCount == 989 ) || \
( NumVertices == 466 && PrimitiveCount == 550 ) || \
( NumVertices == 324 && PrimitiveCount == 372 ))

#define SAS ((NumVertices == 2245 && PrimitiveCount == 2998) || \
(NumVertices == 3417 && PrimitiveCount == 5030) || \
(NumVertices == 1498 && PrimitiveCount == 1822) || \
(NumVertices == 929 && PrimitiveCount == 1007) || \
(NumVertices == 499 && PrimitiveCount == 533) || \
(NumVertices == 409 && PrimitiveCount == 433))

#define SAS_DX8 (( NumVertices == 2337 && PrimitiveCount == 1774 ) || \
( NumVertices == 2337 && PrimitiveCount == 846 ) || \
( NumVertices == 2337 && PrimitiveCount == 378 ) || \
( NumVertices == 3573 && PrimitiveCount == 703 ) || \
( NumVertices == 3573 && PrimitiveCount == 891 ) || \
( NumVertices == 3573 && PrimitiveCount == 2754 ) || \
( NumVertices == 3573 && PrimitiveCount == 682 ) || \
( NumVertices == 1562 && PrimitiveCount == 1411 ) || \
( NumVertices == 1562 && PrimitiveCount == 359 ) || \
( NumVertices == 1562 && PrimitiveCount == 52 ) || \
( NumVertices == 929 && PrimitiveCount == 1007 ) || \
( NumVertices == 499 && PrimitiveCount == 533 ) || \
( NumVertices == 409 && PrimitiveCount == 433 ))

#define GSG9 ((NumVertices == 1424 && PrimitiveCount == 1858) || \
(NumVertices == 2130 && PrimitiveCount == 3004) || \
(NumVertices == 814 && PrimitiveCount == 945) || \
(NumVertices == 3206 && PrimitiveCount == 4872) || \
(NumVertices == 475 && PrimitiveCount == 510) || \
(NumVertices == 343 && PrimitiveCount == 344))

#define GSG9_DX8 (( NumVertices == 3380 && PrimitiveCount == 3300 ) || \
( NumVertices == 3380 && PrimitiveCount == 766 ) || \
( NumVertices == 3380 && PrimitiveCount == 357 ) || \
( NumVertices == 3380 && PrimitiveCount == 432 ) || \
( NumVertices == 3380 && PrimitiveCount == 17 ) || \
( NumVertices == 2260 && PrimitiveCount == 1376 ) || \
( NumVertices == 2260 && PrimitiveCount == 1263 ) || \
( NumVertices == 2260 && PrimitiveCount == 360 ) || \
( NumVertices == 2260 && PrimitiveCount == 5 ) || \
( NumVertices == 1487 && PrimitiveCount == 1083 ) || \
( NumVertices == 1487 && PrimitiveCount == 658 ) || \
( NumVertices == 1487 && PrimitiveCount == 117 ) || \
( NumVertices == 814 && PrimitiveCount == 945 ) || \
( NumVertices == 475 && PrimitiveCount == 510 ) || \
( NumVertices == 2260 && PrimitiveCount == 5 ) || \
( NumVertices == 343 && PrimitiveCount == 344 ))

#define SEAL ((NumVertices == 2487 && PrimitiveCount == 3006) || \
(NumVertices == 1609 && PrimitiveCount == 1794) || \
(NumVertices == 3887 && PrimitiveCount == 4974) || \
(NumVertices == 899 && PrimitiveCount == 910) || \
(NumVertices == 513 && PrimitiveCount == 451) || \
(NumVertices == 369 && PrimitiveCount == 297))

#define SEAL_DX8 (( NumVertices == 3973 && PrimitiveCount == 3443 ) || \
( NumVertices == 3973 && PrimitiveCount == 701 ) || \
( NumVertices == 3973 && PrimitiveCount == 607 ) || \
( NumVertices == 3973 && PrimitiveCount == 223 ) || \
( NumVertices == 2587 && PrimitiveCount == 2075 ) || \
( NumVertices == 2587 && PrimitiveCount == 622 ) || \
( NumVertices == 2587 && PrimitiveCount == 309 ) || \
( NumVertices == 513 && PrimitiveCount == 451 ) || \
( NumVertices == 369 && PrimitiveCount == 297 ) || \
( NumVertices == 1677 && PrimitiveCount == 1264 ) || \
( NumVertices == 1677 && PrimitiveCount == 487 ) || \
( NumVertices == 1677 && PrimitiveCount == 43 ) || \
( NumVertices == 899 && PrimitiveCount == 910 ))

#define PHOENIX ((NumVertices == 2274 && PrimitiveCount == 3070) || \
(NumVertices == 3265 && PrimitiveCount == 5015) || \
(NumVertices == 1510 && PrimitiveCount == 1871) || \
(NumVertices == 873 && PrimitiveCount == 986) || \
(NumVertices == 563 && PrimitiveCount == 590) || \
(NumVertices == 368 && PrimitiveCount == 377))

#define PHOENIX_DX8 (( NumVertices == 3349 && PrimitiveCount == 3596 ) || \
( NumVertices == 3349 && PrimitiveCount == 725 ) || \
( NumVertices == 3349 && PrimitiveCount == 625 ) || \
( NumVertices == 3349 && PrimitiveCount == 69 ) || \
( NumVertices == 873 && PrimitiveCount == 986 ) || \
( NumVertices == 1584 && PrimitiveCount == 1211 ) || \
( NumVertices == 1584 && PrimitiveCount == 420 ) || \
( NumVertices == 1584 && PrimitiveCount == 240 ) || \
( NumVertices == 2375 && PrimitiveCount == 2114 ) || \
( NumVertices == 2375 && PrimitiveCount == 578 ) || \
( NumVertices == 2375 && PrimitiveCount == 378 ) || \
( NumVertices == 368 && PrimitiveCount == 377 ) || \
( NumVertices == 563 && PrimitiveCount == 590 ))

#define ELITE ((NumVertices == 1992 && PrimitiveCount == 2996) || \
(NumVertices == 3087 && PrimitiveCount == 4911) || \
(NumVertices == 735 && PrimitiveCount == 899) || \
(NumVertices == 1311 && PrimitiveCount == 1812) || \
(NumVertices == 454 && PrimitiveCount == 519) || \
(NumVertices == 323 && PrimitiveCount == 338))

#define ELITE_DX8 (( NumVertices == 3248 && PrimitiveCount == 1758 ) || \
( NumVertices == 3248 && PrimitiveCount == 2340 ) || \
( NumVertices == 3248 && PrimitiveCount == 611 ) || \
( NumVertices == 3248 && PrimitiveCount == 154 ) || \
( NumVertices == 3248 && PrimitiveCount == 48 ) || \
( NumVertices == 2119 && PrimitiveCount == 1607 ) || \
( NumVertices == 2119 && PrimitiveCount == 779 ) || \
( NumVertices == 2119 && PrimitiveCount == 599 ) || \
( NumVertices == 2119 && PrimitiveCount == 11 ) || \
( NumVertices == 1375 && PrimitiveCount == 1189 ) || \
( NumVertices == 1375 && PrimitiveCount == 460 ) || \
( NumVertices == 1375 && PrimitiveCount == 163 ) || \
( NumVertices == 735 && PrimitiveCount == 899 ) || \
( NumVertices == 454 && PrimitiveCount == 519 ) || \
( NumVertices == 323 && PrimitiveCount == 338 ))

#define ARCTIC ((NumVertices == 1488 && PrimitiveCount == 1819) || \
(NumVertices == 2292 && PrimitiveCount == 3015) || \
(NumVertices == 3210 && PrimitiveCount == 4503) || \
(NumVertices == 408 && PrimitiveCount == 344) || \
(NumVertices == 835 && PrimitiveCount == 899) || \
(NumVertices == 554 && PrimitiveCount == 509))

#define ARCTIC_DX8 (( NumVertices == 3319 && PrimitiveCount == 2871 ) || \
( NumVertices == 3319 && PrimitiveCount == 773 ) || \
( NumVertices == 3319 && PrimitiveCount == 663 ) || \
( NumVertices == 3319 && PrimitiveCount == 196 ) || \
( NumVertices == 2412 && PrimitiveCount == 1614 ) || \
( NumVertices == 2412 && PrimitiveCount == 891 ) || \
( NumVertices == 2412 && PrimitiveCount == 490 ) || \
( NumVertices == 2412 && PrimitiveCount == 20 ) || \
( NumVertices == 1564 && PrimitiveCount == 1194 ) || \
( NumVertices == 1564 && PrimitiveCount == 381 ) || \
( NumVertices == 1564 && PrimitiveCount == 244 ) || \
( NumVertices == 835 && PrimitiveCount == 899 ) || \
( NumVertices == 554 && PrimitiveCount == 509 ) || \
( NumVertices == 408 && PrimitiveCount == 344 ))

#define GUERILLA ((NumVertices == 1588 && PrimitiveCount == 2013) || \
(NumVertices == 2261 && PrimitiveCount == 3003) || \
(NumVertices == 3561 && PrimitiveCount == 5066) || \
(NumVertices == 911 && PrimitiveCount == 996) || \
(NumVertices == 526 && PrimitiveCount == 594) || \
(NumVertices == 389 && PrimitiveCount == 386))

#define GUERILLA_DX8 (( NumVertices == 3676 && PrimitiveCount == 3184 ) || \
( NumVertices == 2373 && PrimitiveCount == 1794 ) || \
( NumVertices == 1699 && PrimitiveCount == 1312 ) || \
( NumVertices == 911 && PrimitiveCount == 996 ) || \
( NumVertices == 526 && PrimitiveCount == 594 ) || \
( NumVertices == 389 && PrimitiveCount == 386 ))
AIM.cpp
Code:
#include "Main.h"
#include "Models.h"

#define D3DSDEX D3DSURFACE_DESC_EX
#define D3DSD D3DSURFACE_DESC

/*
	D3D AIM CSS
	By: SOH
	Credits: aBnet/UC/GD/MPH/Sandaasu
	Game: Counter Strike Source
	Date: January 11 , 2014

	F12 - Enable remove dead bodies
	F11 - Aim through
	F10 - Choose team to target
	F9 - Choose aim spot (1 - 3)
	F8 - Increase FOV Size
	F7 - Decrease FOV Size
	F6 - Wall hack
	F5 - Enable trigger
	F4 - Enable aim
	F3 - Enable esp
	F2 - Enable fov
	F1 - Enable Draw fov

	Mouse1/Mouse4/Mouse5  - Aim key
	Trigger bot presses Mouse1 for attack... xD
*/

CHAR STR[MAX_PATH]									= {NULL};
LONG ScreenHeightHalf								= NULL;
LONG ScreenWidthHalf									= NULL;

FLOAT FScrSizeX											= 0.0f;
FLOAT FScrSizeY											= 0.0f;
LONG ScrSizeX											= 0;
LONG ScrSizeY											= 0;

BOOL BDepth												= FALSE;
BOOL BAimThr											= FALSE;
BOOL BFiring												= FALSE;

BOOL Wall													= FALSE;
BOOL TriggerOn											= FALSE;
BOOL AimOn												= FALSE;
BOOL EspOn												= FALSE;
BOOL FOVOn												= FALSE;
BOOL FOVDrawOn										= FALSE;
BOOL RemDeadOn										= FALSE;

INT iTeam													= 1;
DWORD TrigTime										= 0;
INT AimSpot												= 1;
INT FOVSize												= 150;

PDWORD LabelTable										= NULL;
PDWORD LabelBuffer									= NULL;
PENTITIES Entities										= NULL;

D3DVIEWPORT9 VP										= {NULL};

LPDIRECT3DSURFACE9 pRender					= NULL;
LPDIRECT3DSURFACE9 pStencil						= NULL;
LPDIRECT3DSURFACE9 pAimRender				= NULL;
LPDIRECT3DSURFACE9 pAim							= NULL;
LPDIRECT3DSURFACE9 pOff							= NULL;
LPDIRECT3DSURFACE9 pMapRender				= NULL;
LPDIRECT3DSURFACE9 pVisibleRender			= NULL;
LPDIRECT3DSURFACE9 pBlankStencil				= NULL;

LPDIRECT3DSURFACE9 pTrig						= NULL;
LPDIRECT3DSURFACE9 pTrigOff					= NULL;

LPDIRECT3DSURFACE9 pVis							= NULL;
LPDIRECT3DSURFACE9 pVisOff						= NULL;

LPDIRECT3DTEXTURE9 Blue							= NULL;		
LPDIRECT3DTEXTURE9 Red							= NULL;		
LPDIRECT3DTEXTURE9 Green						= NULL;		
LPDIRECT3DTEXTURE9 Orange						= NULL;	
LPDIRECT3DTEXTURE9 Pink							= NULL;		
LPDIRECT3DTEXTURE9 Yellow						= NULL;	

LPD3DXFONT pFont										= NULL;
DWORD clientdll											= NULL;
RECT FOV													= {NULL};

VOID WINAPI CreateSurface( LPDIRECT3DDEVICE9 pDevice )
{
	if( !pRender || !pStencil || !pAim || !pOff || 
		!pTrig || !pTrigOff || !pAimRender || !pMapRender || 
			!pVisibleRender || !pBlankStencil || !pVis || !pVisOff )
	{
		LPDIRECT3DSURFACE9 pRen						= NULL;
		LPDIRECT3DSURFACE9 pSten					= NULL;

		FScrSizeX						= (FLOAT)VP.Width / 400.0f;
		FScrSizeY						= (FLOAT)VP.Height / 300.0f;

		ScrSizeX						= LONG((FLOAT)VP.Width / FScrSizeX);
		ScrSizeY						= LONG((FLOAT)VP.Height / FScrSizeY);

		D3DSURFACE_DESC RDESC;
		D3DSURFACE_DESC SDESC;

		memset( &RDESC, 0, sizeof(D3DSURFACE_DESC) );
		memset( &SDESC, 0, sizeof(D3DSURFACE_DESC) );

		if( pDevice->GetRenderTarget( 0, &pRen ) == D3D_OK )
		if( pRen->GetDesc( &RDESC ) == D3D_OK )
		{
			if( !pRender )
				pDevice->CreateRenderTarget( RDESC.Width, RDESC.Height,
					D3DFMT_A8R8G8B8, RDESC.MultiSampleType, RDESC.MultiSampleQuality,
						FALSE, &pRender, NULL);

			if( !pAimRender )
				pDevice->CreateRenderTarget( RDESC.Width, RDESC.Height,
					D3DFMT_A8R8G8B8, RDESC.MultiSampleType, RDESC.MultiSampleQuality,
						FALSE, &pAimRender, NULL);

			if( !pMapRender )
				pDevice->CreateRenderTarget( RDESC.Width, RDESC.Height,
					D3DFMT_A8R8G8B8, RDESC.MultiSampleType, RDESC.MultiSampleQuality,
						FALSE, &pMapRender, NULL);

			if( !pVisibleRender )
				pDevice->CreateRenderTarget( RDESC.Width, RDESC.Height,
					D3DFMT_A8R8G8B8, RDESC.MultiSampleType, RDESC.MultiSampleQuality,
						FALSE, &pVisibleRender, NULL);

			if( !pAim )
				pDevice->CreateRenderTarget( ScrSizeX, ScrSizeY, D3DFMT_A8R8G8B8, 
					D3DMULTISAMPLE_NONE, 0, FALSE, &pAim, NULL);

			if( !pVis )
				pDevice->CreateRenderTarget( ScrSizeX, ScrSizeY, D3DFMT_A8R8G8B8, 
					D3DMULTISAMPLE_NONE, 0, FALSE, &pVis, NULL);

			if( !pTrig )
				pDevice->CreateRenderTarget( 3, 3, D3DFMT_A8R8G8B8, 
					D3DMULTISAMPLE_NONE, 0, FALSE, &pTrig, NULL);
		}

		if( pDevice->GetDepthStencilSurface( &pSten ) == D3D_OK )
		if( pSten->GetDesc( &SDESC ) == D3D_OK )
		{
			if( !pStencil )
				pDevice->CreateDepthStencilSurface( SDESC.Width, SDESC.Height,
					SDESC.Format, SDESC.MultiSampleType, SDESC.MultiSampleQuality, 
						FALSE, &pStencil, NULL );

			if( !pBlankStencil )
				pDevice->CreateDepthStencilSurface( SDESC.Width, SDESC.Height,
					SDESC.Format, SDESC.MultiSampleType, SDESC.MultiSampleQuality, 
						FALSE, &pBlankStencil, NULL );
		}

		if( !pOff )
			pDevice->CreateOffscreenPlainSurface( ScrSizeX, ScrSizeY, 
				D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &pOff, NULL );

		if( !pTrigOff )
			pDevice->CreateOffscreenPlainSurface( 3, 3, D3DFMT_A8R8G8B8, 
				D3DPOOL_SYSTEMMEM, &pTrigOff, NULL );

		if( !pVisOff	 )
			pDevice->CreateOffscreenPlainSurface( ScrSizeX, ScrSizeY, 
				D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &pVisOff, NULL );

		D3D_RELEASE( pRen )
		D3D_RELEASE( pSten )
	}
}

VOID WINAPI SetDeadBodies( VOID )
{
	// cl_ragdoll_physics_enable 0
	if( !clientdll )
		clientdll							= (DWORD)GetModuleHandle( "client.dll" );
	else
	{
		if( RemDeadOn && *PINT(clientdll + 0x5960F0) )
			*PINT(clientdll + 0x5960F0)		= 0;
	}
}

BOOL WINAPI GetDepth( LPDIRECT3DDEVICE9 pDevice )
{
	if( !pStencil )
		return FALSE;

	LPDIRECT3DSURFACE9 pSten					= NULL;
	BOOL Result												= FALSE;

	if( pDevice->GetDepthStencilSurface( &pSten ) == D3D_OK )
	{
		if( SUCCEEDED(pDevice->StretchRect( pSten, NULL, pStencil, NULL, D3DTEXF_NONE )) )
		{
			if( pDevice->SetDepthStencilSurface( pStencil ) == D3D_OK )
			{
				pClear( pDevice, 0, NULL, D3DCLEAR_ZBUFFER , 
						D3DCOLOR_ARGB( 0, 0, 0, 0 ), 1.0f,  0 );

				pDevice->SetDepthStencilSurface( pSten );

				Result			= TRUE;
			}
		}
	}
	else
	{
		D3D_RELEASE( pSten )
		return FALSE;
	}

	D3D_RELEASE( pSten )

	return Result;
}

BOOL WINAPI IsVisible( LPDIRECT3DDEVICE9 pDevice, LONG X, LONG Y )
{
	if( !pVis || !pVisOff || !pVisibleRender )
		return FALSE;

	D3DLOCKED_RECT D3DLR	= {NULL};
	BOOL Result						= FALSE;
	LONG Max_X						= ScrSizeX - 1;
	LONG Max_Y						= ScrSizeY - 1;

	if( X > 0 && Y > 0 && X < Max_X && Y < Max_Y )
	{
		if( SUCCEEDED( pVisOff->LockRect( &D3DLR, 
			NULL, D3DLOCK_DISCARD )) )
		{
			PDWORD PIX		= (PDWORD)D3DGetPixel( ((DWORD)D3DLR.pBits), Y, X, 32, ( D3DLR.Pitch ) );

			if( *PIX )		Result		= TRUE;

			pVisOff->UnlockRect( );
		}
	}

	return Result;
}

BOOL WINAPI VisibleReady( LPDIRECT3DDEVICE9 pDevice )
{
	if( !pVis || !pVisOff || !pVisibleRender )
		return FALSE;

	if( SUCCEEDED(pDevice->StretchRect( pVisibleRender, NULL, 
		pVis, NULL, D3DTEXF_NONE )) )
	{
		if( SUCCEEDED(pDevice->GetRenderTargetData( pVis, pVisOff )) )
		{
			return TRUE;
		}
	}

	return FALSE;
}

BOOL WINAPI Trigger( LPDIRECT3DDEVICE9 pDevice )
{
	if( !pTrig || !pTrigOff || !pRender )
		return FALSE;

	D3DLOCKED_RECT D3DLR	= {NULL};
	BOOL Result		= FALSE;
	BOOL Fire			= FALSE;
	RECT RTR			= {ScreenWidthHalf - 1,ScreenHeightHalf - 1,
								ScreenWidthHalf + 1,ScreenHeightHalf + 1};

	if( SUCCEEDED(pDevice->StretchRect( pRender, &RTR, 
		pTrig, NULL, D3DTEXF_NONE )) )
	{
		if( SUCCEEDED(pDevice->GetRenderTargetData( pTrig, pTrigOff )) )
		{
			if( SUCCEEDED( pTrigOff->LockRect( &D3DLR, 
				NULL, D3DLOCK_DISCARD )) )
			{
				for( long y = 0;y < 3;y++ )
				{
					for( long x = 0;x < 3;x++ )
					{
						PDWORD Pixel		= D3DGetPixel( (DWORD)
							D3DLR.pBits, y, x, 32, D3DLR.Pitch );

						if( *Pixel ) Fire		= TRUE;
					}
				}
				pTrigOff->UnlockRect( );
				Result		= TRUE;
			}
		}
	}

	if( !( GetAsyncKeyState( VK_LBUTTON ) < 0 ) )
	{
		if( Fire ) 
		{		
			if( !BFiring )
			{
				mouse_event( MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 );
				mouse_event( MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 );

				TrigTime	= GetTickCount( );
				BFiring		= TRUE;
			}
			else
			{
				DWORD Span		= GetTickCount( ) - TrigTime;

				if( Span > 5 )
				{
					mouse_event( MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 );
					BFiring		= FALSE;
				}
			}
		}
		else
		{
			if( BFiring )
			{
				mouse_event( MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 );
				BFiring		= FALSE;
			}
		}
	}

	return Result;
}

VOID WINAPI ClearRenTarget( LPDIRECT3DDEVICE9 pDevice )
{
	if( pRender && pAimRender && pVisibleRender && 
		pMapRender && pStencil && pBlankStencil )
	{
		LPDIRECT3DSURFACE9 pRen					= NULL;
		LPDIRECT3DSURFACE9 pSten				= NULL;

		if( pDevice->GetRenderTarget( 0, &pRen ) == D3D_OK )
		{	

#ifdef DEBUG_STRETCHRECT
			RECT DebugA		= {(VP.Width - (VP.Width / 4)) - 10,
										10,VP.Width - 10,VP.Height / 4 + 10};

			pDevice->StretchRect( pRender, NULL, pRen, &DebugA, D3DTEXF_NONE );

			RECT DebugB		= {(VP.Width - (VP.Width / 4)) - 10,
										DebugA.bottom + 10,VP.Width - 10,(DebugA.bottom * 2) + 10};

			pDevice->StretchRect( pAimRender, NULL, pRen, &DebugB, D3DTEXF_NONE );
#endif

			if( pDevice->GetDepthStencilSurface( &pSten ) == D3D_OK )
			{
				pDevice->SetRenderTarget( 0, pRender );
				pDevice->SetDepthStencilSurface( pSten );

				pClear( pDevice, 0, NULL, D3DCLEAR_TARGET, 
					D3DCOLOR_ARGB( 0, 0, 0, 0 ), 1.0f,  0 ); 

				pDevice->SetRenderTarget( 0, pAimRender );
				pDevice->SetDepthStencilSurface( pSten );

				pClear( pDevice, 0, NULL, D3DCLEAR_TARGET, 
					D3DCOLOR_ARGB( 0, 0, 0, 0 ), 1.0f,  0 ); 

				pDevice->SetRenderTarget( 0, pVisibleRender );
				pDevice->SetDepthStencilSurface( pSten );

				pClear( pDevice, 0, NULL, D3DCLEAR_TARGET, 
					D3DCOLOR_ARGB( 0, 0, 0, 0 ), 1.0f,  0 ); 

				pDevice->SetRenderTarget( 0, pMapRender );
				pDevice->SetDepthStencilSurface( pStencil );

				pClear( pDevice, 0, NULL, D3DCLEAR_TARGET | 
					D3DCLEAR_STENCIL | D3DCLEAR_ZBUFFER , 
						D3DCOLOR_ARGB( 0, 0, 0, 0 ), 1.0f,  0 ); 

				pDevice->SetRenderTarget( 0, pMapRender );
				pDevice->SetDepthStencilSurface( pBlankStencil );

				pClear( pDevice, 0, NULL, D3DCLEAR_STENCIL | 
					D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 0, 0, 0 ), 1.0f,  0 ); 

				pDevice->SetRenderTarget( 0, pRen );
				pDevice->SetDepthStencilSurface( pSten );
			}
		}

		D3D_RELEASE( pSten )
		D3D_RELEASE( pRen )
	}
}

VOID WINAPI KeyState( VOID )
{
	if( GetAsyncKeyState( VK_F12 ) &1 )
		if( RemDeadOn ) RemDeadOn		= FALSE;
		else RemDeadOn							= TRUE;

	if( GetAsyncKeyState( VK_F11 ) &1 )
		if( BAimThr) BAimThr	= FALSE;
		else BAimThr		= TRUE;

	if( GetAsyncKeyState( VK_F10 ) &1 )
		if( iTeam < 2 ) iTeam++;
		else iTeam	= 1;

	if( GetAsyncKeyState( VK_F9 ) &1 )
		if( AimSpot < 3 ) AimSpot++;
		else AimSpot		= 1;

	if( GetAsyncKeyState( VK_F8 ) &1 )
		if( FOVSize < ScreenHeightHalf ) FOVSize+=10;
		else FOVSize		= 0;

	if( GetAsyncKeyState( VK_F7 ) &1 )
		if( FOVSize > 1 ) FOVSize-=10;
		else FOVSize		= ScreenHeightHalf - 1;

	if( GetAsyncKeyState( VK_F6 ) &1 )
		if( Wall ) Wall		= FALSE;
		else Wall			= TRUE;

	if( GetAsyncKeyState( VK_F5 ) &1 )
		if( TriggerOn ) TriggerOn		= FALSE;
		else TriggerOn					= TRUE;

	if( GetAsyncKeyState( VK_F4 ) &1 )
		if( AimOn ) AimOn		= FALSE;
		else AimOn					= TRUE;

	if( GetAsyncKeyState( VK_F3 ) &1 )
		if( EspOn ) EspOn		= FALSE;
		else EspOn					= TRUE;

	if( GetAsyncKeyState( VK_F2 ) &1 )
		if( FOVOn ) FOVOn		= FALSE;
		else FOVOn					= TRUE;

	if( GetAsyncKeyState( VK_F1 ) &1 )
		if( FOVDrawOn ) FOVDrawOn		= FALSE;
		else FOVDrawOn							= TRUE;
}

VOID WINAPI DrawFOV( LPDIRECT3DDEVICE9 pDev )
{
	if( !FOVOn || !FOVDrawOn )
		return;

	DWORD BoxColor			= D3DCOLOR_ARGB( 255, 255, 20, 20 );
	LONG X							= ScreenWidthHalf;
	LONG Y							= ScreenHeightHalf;
	LONG Size						= FOVSize;

	D3DRECT	R1		= { X - Size, Y - Size, 
									X + Size, Y - Size + 1 };

	pDev->Clear( 1, &R1, D3DCLEAR_TARGET, BoxColor, 1.0f,  0 );

	D3DRECT	R2		= { X - Size, Y + Size - 1, 
							X + Size, Y + Size };

	pDev->Clear( 1, &R2, D3DCLEAR_TARGET, BoxColor, 1.0f,  0 );

	D3DRECT	R3		= { X - Size, Y - Size, 
							X - Size + 1, Y + Size };

	pDev->Clear( 1, &R3, D3DCLEAR_TARGET, BoxColor, 1.0f,  0 );

	D3DRECT	R4		= { X + Size - 1, Y - Size, 
							X + Size, Y + Size };

	pDev->Clear( 1, &R4, D3DCLEAR_TARGET, BoxColor, 1.0f,  0 );
}

VOID WINAPI DrawESP( LPDIRECT3DDEVICE9 pDev, 
					LONG X, LONG Y, LONG Size, BOOL IsVis )
{
	if( !EspOn )
		return;

	DWORD BoxColor			= 0;

	if( !IsVis )
		BoxColor			= D3DCOLOR_ARGB( 255, 255, 255, 20 ); // Yellow
	else if( IsVis )
		BoxColor			= D3DCOLOR_ARGB( 255, 20, 255, 20 ); // Green

	D3DRECT	R1		= { X - Size, Y - Size, 
									X + Size, Y - Size + 1 };

	pDev->Clear( 1, &R1, D3DCLEAR_TARGET, BoxColor, 1.0f,  0 );

	D3DRECT	R2		= { X - Size, Y + Size - 1, 
							X + Size, Y + Size };

	pDev->Clear( 1, &R2, D3DCLEAR_TARGET, BoxColor, 1.0f,  0 );

	D3DRECT	R3		= { X - Size, Y - Size, 
							X - Size + 1, Y + Size };

	pDev->Clear( 1, &R3, D3DCLEAR_TARGET, BoxColor, 1.0f,  0 );

	D3DRECT	R4		= { X + Size - 1, Y - Size, 
							X + Size, Y + Size };

	pDev->Clear( 1, &R4, D3DCLEAR_TARGET, BoxColor, 1.0f,  0 );
}

DWORD WINAPI Get2DDistance( PLONG A, PLONG B )
{
	LONG DistanceX		= A[0] - B[0];
	LONG DistanceY		= A[1] - B[1];

	return (DWORD)sqrt( FLOAT(( DistanceX * DistanceX ) + ( DistanceY * DistanceY )) );
}

VOID WINAPI LabelPixel( PDWORD Buffer, LONG y, LONG x, INT iLabel, INT Pitch )
{
	PDWORD PX			= (PDWORD)D3DGetPixel( ((DWORD)Buffer), y, x, 32, ( Pitch ) );
	*PX						= iLabel;
}

BOOL WINAPI Aim( LPDIRECT3DDEVICE9 pDevice )
{
	if( !pAimRender || !pAim || !pOff )
		return FALSE;

	D3DLOCKED_RECT D3DLR	= {NULL};
	BOOL Result							= FALSE;
	LONG Label						= 1;
	LONG Objects						= 0;
	DWORD MaxDistance			= 0xFFFFFFFF;
	LONG AimX							= 0;
	LONG AimY							= 0;
	LONG Max_X							= ScrSizeX;
	LONG Max_Y							= ScrSizeY;
	LONG PiSize							= Max_X * 4;

	LONG ScreenCenter[2]			= {ScreenWidthHalf,ScreenHeightHalf};

	// The maximum number of blobs is given by an image filled 
	// with equally spaced single pixel blobs. 
	// http://www.labbookpages.co.uk/software/imgProc/blobDetection.html

	if( !LabelTable )
		LabelTable	= (PDWORD)malloc( (Max_X * Max_Y / 4) * sizeof(DWORD) );
	else
		memset( LabelTable, 0, (Max_X * Max_Y / 4) * sizeof(DWORD) );

	if( !Entities )
		Entities			= (PENTITIES)malloc( (Max_X * Max_Y / 4) * sizeof(PENTITIES) );
	else
		memset( Entities, 0, (Max_X * Max_Y / 4) * sizeof(PENTITIES) );

	if( !LabelBuffer )
		LabelBuffer		= (PDWORD)malloc( Max_X * Max_Y * 4 );
	else
		memset( LabelBuffer, 0, Max_X * Max_Y * 4 );

	if( !LabelTable || !Entities || !LabelBuffer )
		return FALSE;

	if( SUCCEEDED(pDevice->StretchRect( pAimRender, NULL, 
		pAim, NULL, D3DTEXF_NONE )) )
	{
		if( SUCCEEDED(pDevice->GetRenderTargetData( pAim, pOff )) )
		{
			if( SUCCEEDED( pOff->LockRect( &D3DLR, 
				NULL, D3DLOCK_DISCARD )) )
			{
				for( long y = 1;y < Max_Y - 1;y++ )
				{
					for( long x = 1;x < Max_X - 1;x++ )
					{
						PDWORD PRX				= (PDWORD)D3DGetPixel( ((DWORD)D3DLR.pBits), y, x,						32, ( D3DLR.Pitch ) );

						PDWORD PRA				= (PDWORD)D3DGetPixel( ((DWORD)D3DLR.pBits), (y - 1), (x - 1),		32, ( D3DLR.Pitch ) );
						PDWORD PRB				= (PDWORD)D3DGetPixel( ((DWORD)D3DLR.pBits), (y - 1), x,				32, ( D3DLR.Pitch ) );
						PDWORD PRC				= (PDWORD)D3DGetPixel( ((DWORD)D3DLR.pBits), (y - 1), (x + 1),	32, ( D3DLR.Pitch ) );
						PDWORD PRD				= (PDWORD)D3DGetPixel( ((DWORD)D3DLR.pBits), y, (x - 1),				32, ( D3DLR.Pitch ) );
						
						PDWORD PA					= (PDWORD)D3DGetPixel( ((DWORD)LabelBuffer), (y - 1), (x - 1),		32, ( PiSize ) );
						PDWORD PB					= (PDWORD)D3DGetPixel( ((DWORD)LabelBuffer), (y - 1), x,				32, ( PiSize ) );
						PDWORD PC					= (PDWORD)D3DGetPixel( ((DWORD)LabelBuffer), (y - 1), (x + 1),		32, ( PiSize ) );
						PDWORD PD					= (PDWORD)D3DGetPixel( ((DWORD)LabelBuffer), y, (x - 1),				32, ( PiSize ) );

						if( *PRX )
						{
							if( !*PA && !*PB && !*PC && !*PD )
							{
								LabelPixel( LabelBuffer, y, x, Label, PiSize );
								LabelTable[Label-1]	=	Label;
								Label++;
							}
							else
							{
								DWORD Num		=	0xFFFFFFFF;

								if( *PA && *PA <= Num )
									Num		= *PA;

								if( *PB && *PB <= Num )
									Num		= *PB;

								if( *PC && *PC <= Num )
									Num		= *PC;

								if( *PD && *PD <= Num )
									Num		= *PD;

								LabelPixel( LabelBuffer, y, x, Num, PiSize );

								if( *PA )
									LabelTable[*PA-1]	=	Num;

								if( *PB )
									LabelTable[*PB-1]	=	Num;

								if( *PC )
									LabelTable[*PC-1]	=	Num;

								if( *PD )
									LabelTable[*PD-1]	=	Num;
							}
						}
					}
				}

				pOff->UnlockRect( );
				Result		= TRUE;
			}
		}
	}

	if( Label > 1 )
	{
		for(long y = 1; y < Max_Y - 1; y++)
		{
			for(long x = 1; x < Max_X - 1; x++)
			{
				PDWORD PX					= (PDWORD)D3DGetPixel( ((DWORD)LabelBuffer), y, x, 32, ( PiSize ) );

				LONG LabelData			= *PX;

				if( LabelData && LabelData < Label )
				{
					while( 1 )
					{
						if( LabelData && LabelData < Label )
						{
							if( LabelData == LabelTable[LabelData-1] && LabelData < Label )
								break;
							else
							{
								LabelData		= LabelTable[LabelData-1];
							}
						}
					}

					if( y > Entities[LabelData-1].Low )
						Entities[LabelData-1].Low			= y;

					if( !Entities[LabelData-1].High )
						Entities[LabelData-1].High		= y;
					else
					{
						if( y < Entities[LabelData-1].High )
							Entities[LabelData-1].High	= y;
					}

					*PX									= LabelData;
					Entities[LabelData-1].X		+= x;
					Entities[LabelData-1].Y		+= y;
					Entities[LabelData-1].Count++;
					Objects++;
				}
			}
		}

		for( LONG i = 0;i < Objects;i++ )
		{
			if( i >= Label )
				break;

			LONG Count						= Entities[i].Count;
			LONG SCXY[2]					= {Entities[i].X,Entities[i].Y};
			LONG ESPX							= Entities[i].X;
			LONG ESPY							= Entities[i].Y;
			LONG VDist						= 0;

			if( Count && SCXY[0] && SCXY[1] )
			{
				if( Count > 1 )
				{
					SCXY[0]					/= Count;
					SCXY[1]					/= Count; // 3: Body ( no change :DDD )

					ESPX						/= Count; // ESP
					ESPY						/= Count;

					VDist						= SCXY[1] - Entities[i].High;

					if( VDist )
					{
						if( AimSpot == 1 )
							SCXY[1]				= (SCXY[1] - VDist) + (VDist/8); // 1: Head
						else if( AimSpot == 2 )
							SCXY[1]				-= (VDist/2); // 2: Chest
					}
				}

				BOOL IsVisESP			= IsVisible( pDevice, ESPX, ESPY );

				// Resizing ESP coords and drawing ESP ...
				ESPX							= LONG((FLOAT)ESPX * FScrSizeX);
				ESPY							= LONG((FLOAT)ESPY * FScrSizeY);

				DrawESP( pDevice, ESPX, ESPY, VDist, IsVisESP );

				// IsVisible before Resizing aim coords ...
				BOOL IsVis					= IsVisible( pDevice, SCXY[0], SCXY[1] );

				// Resizing aim coords here ...
				SCXY[0]						= LONG((FLOAT)SCXY[0] * FScrSizeX);
				SCXY[1]						= LONG((FLOAT)SCXY[1] * FScrSizeY);

				DWORD Distance			= Get2DDistance( ScreenCenter, SCXY );

				if( (IsVis && !BAimThr) || BAimThr )
				{
					if( ( SCXY[0] > FOV.left &&
						SCXY[0] < FOV.right &&
						SCXY[1] > FOV.top &&
						SCXY[1] < FOV.bottom && FOVOn ) || !FOVOn )
					{					
						if( Distance <= MaxDistance )
						{
							MaxDistance		= Distance;
							AimX					= SCXY[0];
							AimY					= SCXY[1];
						}
					}
				}
			}
		}

		if( AimX && AimY && MaxDistance != 0xFFFFFFFF && AimOn )
		{
			if( ( GetAsyncKeyState( VK_LBUTTON ) < 0 )		||
				( GetAsyncKeyState( VK_XBUTTON1 ) < 0 )	||
				( GetAsyncKeyState( VK_XBUTTON2 ) < 0 ) )
			{
				if(AimX > ScreenWidthHalf)				AimX	= +((AimX - ScreenWidthHalf)/4);
				else if(AimX < ScreenWidthHalf)		AimX	= -((ScreenWidthHalf - AimX)/4);
				else if(AimX == ScreenWidthHalf)		AimX	= 0L;
				if(AimY > ScreenHeightHalf)				AimY	= +((AimY - ScreenHeightHalf)/4);
				else if(AimY < ScreenHeightHalf)		AimY	= -((ScreenHeightHalf - AimY)/4);
				else if(AimY == ScreenHeightHalf)	AimY	= 0L;

				mouse_event( MOUSEEVENTF_MOVE, 
					AimX, AimY, NULL, NULL );

			}
		}
	}

	return Result;
}

VOID WINAPI CreateTextures( LPDIRECT3DDEVICE9 pDev )
{
	if( !Blue )		GenTex( pDev, &Blue, D3DCOLOR_ARGB( 255, 20, 20, 255 ) );
	if( !Red )		GenTex( pDev, &Red, D3DCOLOR_ARGB( 255, 255, 20, 20 ) );
	if( !Green )		GenTex( pDev, &Green, D3DCOLOR_ARGB( 255, 20, 255, 20 ) );
	if( !Orange )	GenTex( pDev, &Orange, D3DCOLOR_ARGB( 255, 255, 128, 20 ) );
	if( !Pink )		GenTex( pDev, &Pink, D3DCOLOR_ARGB( 255, 255, 20, 255 ) );
	if( !Yellow )	GenTex( pDev, &Yellow, D3DCOLOR_ARGB( 255, 255, 255, 20 ) );
}

VOID WINAPI AimPresent( LPDIRECT3DDEVICE9 pDev )
{
		pDev->GetViewport( &VP );

		ScreenWidthHalf					=	VP.Width / 2;
		ScreenHeightHalf					=	VP.Height / 2;

		FOV.left				= ScreenWidthHalf - FOVSize;
		FOV.top				= ScreenHeightHalf - FOVSize;
		FOV.right			= ScreenWidthHalf + FOVSize;
		FOV.bottom		= ScreenHeightHalf + FOVSize;

		CreateSurface( pDev );
		CreateTextures( pDev );
		DrawFOV( pDev );

		if( !pFont )
			D3DXCreateFontA( pDev, 16, 0, 700, 0, 0, 1, 0, 
				0, DEFAULT_PITCH | FF_DONTCARE, "Calibri", &pFont );

		D3DRECT CrssRctA = {ScreenWidthHalf,ScreenHeightHalf -  5,
										ScreenWidthHalf + 1,ScreenHeightHalf + 6};

		pClear( pDev, 1, &CrssRctA, D3DCLEAR_TARGET, 
			D3DCOLOR_ARGB( 255, 255, 20, 20 ), 1.0f,  0 );

		D3DRECT CrssRctB = {ScreenWidthHalf -  5,ScreenHeightHalf,
										ScreenWidthHalf + 6,ScreenHeightHalf + 1};

		pClear( pDev, 1, &CrssRctB, D3DCLEAR_TARGET, 
			D3DCOLOR_ARGB( 255, 255, 20, 20 ), 1.0f,  0 ); 

#ifdef TRIGGER_D3D
		if( TriggerOn )	Trigger( pDev );
#endif

#ifdef AIM_D3D
		if( AimOn || EspOn )
		{
			if( VisibleReady( pDev ) )
				Aim( pDev );
		}
#endif

		if( AimOn || EspOn || TriggerOn )
			ClearRenTarget( pDev );

		KeyState( );
		SetDeadBodies( );
}

VOID WINAPI AimReset( LPDIRECT3DDEVICE9 pDevice )
{
	D3D_RELEASE( pRender )
	D3D_RELEASE( pStencil )
	D3D_RELEASE( pAim )
	D3D_RELEASE( pOff )
	D3D_RELEASE( pTrig )
	D3D_RELEASE( pTrigOff )
	D3D_RELEASE( pAimRender )
	D3D_RELEASE( pMapRender )
	D3D_RELEASE( pFont )
	D3D_RELEASE( pVisibleRender )
	D3D_RELEASE( pBlankStencil )
	D3D_RELEASE( pVis )
	D3D_RELEASE( pVisOff )

	D3D_RELEASE( Blue )		
	D3D_RELEASE( Red )		
	D3D_RELEASE( Green )		
	D3D_RELEASE( Orange )	
	D3D_RELEASE( Pink )		
	D3D_RELEASE( Yellow )	
}

BOOL WINAPI AimDrawPrim( LPDIRECT3DDEVICE9 pDevice, 
	D3DPRIMITIVETYPE Type, INT Base, UINT Min, UINT NumVertices, 
		UINT Start, UINT PrimitiveCount )
{
	if( !pMapRender		|| !pStencil			|| !pVisibleRender	|| !pRender		|| 
		!pAimRender		|| !pBlankStencil || !Red					|| !Blue			|| 
		!Orange				|| !Green			|| !Pink					|| !Yellow )
		return FALSE;

	LPDIRECT3DVERTEXBUFFER9 Stream		= NULL;
	UINT Offset			= 0;
	UINT Stride			= 0;
	BOOL TeamTE			= FALSE;
	BOOL TeamCTE		= FALSE;
	BOOL TeamC4			= FALSE;

	if( pDevice->GetStreamSource( 0, &Stream, &Offset, &Stride ) == D3D_OK )
		Stream->Release( );

	if( TE_DX8 || TE )
		TeamTE			= TRUE;
	else if( CTE_DX8 || CTE )
		TeamCTE		= TRUE;
	else if( C4 )
		TeamC4			= TRUE;

	if( Stride == 48 || Stride == 80 )
	{
		LPDIRECT3DSURFACE9 pRen					= NULL;
		LPDIRECT3DSURFACE9 pSten				= NULL;
		D3DSDEX RDESC								= {0};

		if( pDevice->GetRenderTarget( 0, &pRen ) == D3D_OK )
		{
			if( pRen->GetDesc( (D3DSD*)&RDESC ) == D3D_OK )
			{
				if( RDESC.Width == VP.Width && RDESC.Height == VP.Height )
				{
					if( pDevice->GetDepthStencilSurface( &pSten ) == D3D_OK )
					{
						pDevice->SetRenderTarget( 0, pMapRender );
						pDevice->SetDepthStencilSurface( pStencil );
						pDevice->SetRenderState( D3DRS_ZENABLE, TRUE );

						pDrawPrim( pDevice, Type, Base, Min, 
							NumVertices, Start, PrimitiveCount );

						pDevice->SetRenderTarget( 0, pRen );
						pDevice->SetDepthStencilSurface( pSten );
						pDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
					}
				}
			}
		}

		D3D_RELEASE( pRen )
		D3D_RELEASE( pSten )
	}

	if( (iTeam == 1 && TeamTE) || 
		(iTeam == 2 && TeamCTE) )
	{
		LPDIRECT3DSURFACE9 pRen					= NULL;
		LPDIRECT3DSURFACE9 pSten				= NULL;
		D3DSDEX RDESC								= {0};

		if( pDevice->GetRenderTarget( 0, &pRen ) == D3D_OK )
		{
			if( pRen->GetDesc( (D3DSD*)&RDESC ) == D3D_OK )
			{
				if( RDESC.Width == VP.Width && RDESC.Height == VP.Height )
				{
					if( pDevice->GetDepthStencilSurface( &pSten ) == D3D_OK )
					{
						//////VISIBLE/////////////

						if( !BAimThr && ( AimOn || EspOn ) )
						{
							pDevice->SetRenderTarget( 0, pVisibleRender );
							pDevice->SetDepthStencilSurface( pStencil );
							pDevice->SetRenderState( D3DRS_ZENABLE, TRUE );

							pDrawPrim( pDevice, Type, Base, Min, 
								NumVertices, Start, PrimitiveCount );
						}

						//////TRIGGER/////////////

						if( TriggerOn )
						{
							pDevice->SetRenderTarget( 0, pRender );

							if( !BAimThr )
							{
								pDevice->SetDepthStencilSurface( pStencil );
								pDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
							}
							else
							{
								pDevice->SetDepthStencilSurface( pBlankStencil );
								pDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
							}

							pDrawPrim( pDevice, Type, Base, Min, 
								NumVertices, Start, PrimitiveCount );
						}

						//////AIM/ESP//////////////

						if( ( AimOn || EspOn ) )
						{
							pDevice->SetRenderTarget( 0, pAimRender );
							pDevice->SetDepthStencilSurface( pBlankStencil );
							pDevice->SetRenderState( D3DRS_ZENABLE, FALSE );

							pDrawPrim( pDevice, Type, Base, Min, 
								NumVertices, Start, PrimitiveCount );
						}

						/////////////////////////////

						pDevice->SetRenderTarget( 0, pRen );
						pDevice->SetDepthStencilSurface( pSten );
						pDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
					}
				}
			}
		}

		D3D_RELEASE( pSten )
		D3D_RELEASE( pRen )
	}

	if( Wall && ( TeamTE || TeamCTE || TeamC4 ) )
	{
		if( TeamCTE )
			pDevice->SetTexture( 0, Red );

		if( TeamTE )
			pDevice->SetTexture( 0, Blue );

		if( TeamC4 )
			pDevice->SetTexture( 0, Orange );

		pDevice->SetRenderState( D3DRS_ZENABLE, FALSE );

		pDrawPrim( pDevice, Type, Base, Min, 
			NumVertices, Start, PrimitiveCount );

		pDevice->SetRenderState( D3DRS_ZENABLE, TRUE );

		if( TeamCTE )
			pDevice->SetTexture( 0, Green );

		if( TeamTE )
			pDevice->SetTexture( 0, Pink );

		if( TeamC4 )
			pDevice->SetTexture( 0, Yellow );
	}

	return TRUE;
}

BOOL WINAPI GenTex( LPDIRECT3DDEVICE9 pDev, 
		LPDIRECT3DTEXTURE9 * ppD3Dtex, DWORD Color )
{
	D3DLOCKED_RECT d3dlr				= {NULL};
	IDirect3DTexture9 *	Temp		= NULL;

	if( FAILED( pDev->CreateTexture( 100, 100, 1, 0, D3DFMT_A8R8G8B8, 
		D3DPOOL_DEFAULT, ppD3Dtex, NULL ) ) ) 
		return FALSE;

	if( FAILED( pDev->CreateTexture( 100, 100, 1, 0, D3DFMT_A8R8G8B8, 
		D3DPOOL_SYSTEMMEM, &Temp, NULL ) ) ) 
	{
		D3D_RELEASE( (*ppD3Dtex) )
		return FALSE;
	}

	if( Temp->LockRect( 0, &d3dlr, 0, 0 ) == S_OK )
	{
		for( int i = 0;i < 100*100;i++ )
			((PDWORD)d3dlr.pBits)[i]		= Color;

		Temp->UnlockRect( 0 );

		pDev->UpdateTexture( Temp, *ppD3Dtex );
	}
	else
	{
		D3D_RELEASE( Temp )
		D3D_RELEASE( (*ppD3Dtex) )
		return FALSE;
	}

	D3D_RELEASE( Temp )

	return TRUE;
}
D3D.cpp
Code:
#include "Main.h"
#include "Models.h"

/*
	D3D AIM CSS
	By: SOH
	Credits: aBnet/UC/GD/MPH/Sandaasu
	Game: Counter Strike Source
	Date: January 11 , 2014

	F12 - Enable remove dead bodies
	F11 - Aim through
	F10 - Choose team to target
	F9 - Choose aim spot (1 - 3)
	F8 - Increase FOV Size
	F7 - Decrease FOV Size
	F6 - Wall hack
	F5 - Enable trigger
	F4 - Enable aim
	F3 - Enable esp
	F2 - Enable fov
	F1 - Enable Draw fov

	Mouse1/Mouse4/Mouse5  - Aim key
	Trigger bot presses Mouse1 for attack... xD
*/

HRESULT (WINAPI* pReset)(LPDIRECT3DDEVICE9, D3DPRESENT_PARAMETERS*);
HRESULT (WINAPI* pBegineScene)(LPDIRECT3DDEVICE9);
HRESULT (WINAPI* pDrawPrim)(LPDIRECT3DDEVICE9, D3DPRIMITIVETYPE, INT, UINT, UINT, UINT, UINT);
HRESULT (WINAPI* pEndScene)(LPDIRECT3DDEVICE9);
HRESULT (WINAPI* pClear)(LPDIRECT3DDEVICE9 pDevice9,DWORD Count,CONST 
	D3DRECT* pRects,DWORD Flags,D3DCOLOR Color,float Z,DWORD Stencil);
HRESULT (WINAPI* pPresent)( LPDIRECT3DDEVICE9 Device, 
	CONST RECT* pSourceRect, CONST RECT* pDestRect,
		HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion );

D3DVIEWPORT9 D3DVP		= {NULL};

HRESULT WINAPI DrawPrim( LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE Type, INT Base, 
                                           UINT Min, UINT NumVertices, UINT Start, UINT PrimitiveCount )
{
	AimDrawPrim( pDevice, Type, Base, Min, NumVertices, Start, PrimitiveCount );
	return pDrawPrim( pDevice, Type, Base, Min, NumVertices, Start, PrimitiveCount );
}

HRESULT WINAPI Reset( LPDIRECT3DDEVICE9 pDevice, 
					 D3DPRESENT_PARAMETERS* PPR )
{
	AimReset( pDevice );
	return pReset( pDevice, PPR );
}

HRESULT WINAPI BegineScene( LPDIRECT3DDEVICE9 pDev )
{
	return pBegineScene( pDev );
}

HRESULT WINAPI EndScene( LPDIRECT3DDEVICE9 pDev )
{
	pDev->GetViewport( &D3DVP );
	return pEndScene( pDev );
}

HRESULT WINAPI Clear( LPDIRECT3DDEVICE9 pDevice9, DWORD Count, 
	CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, 
		float Z, DWORD Stencil )
{
	return pClear( pDevice9, Count, pRects, Flags, 
					Color, Z, Stencil );
}

HRESULT WINAPI Present( LPDIRECT3DDEVICE9 Device, 
	CONST RECT* pSourceRect, CONST RECT* pDestRect,
		HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion )
{	
	AimPresent( Device );
	return pPresent( Device, pSourceRect, pDestRect, 
		hDestWindowOverride, pDirtyRegion );
}

VOID WINAPI HkD3D( PDWORD vTable )
{
	DWORD OLD;
	VirtualProtect( &vTable[0], 118 * 4, 0x40, &OLD );

	*(PDWORD)&pReset				= (DWORD)vTable[16];
	*(PDWORD)&pPresent				= (DWORD)vTable[17];
	*(PDWORD)&pBegineScene		= (DWORD)vTable[41];
	*(PDWORD)&pEndScene			= (DWORD)vTable[42];
	*(PDWORD)&pClear					= (DWORD)vTable[43];
	*(PDWORD)&pDrawPrim			= (DWORD)vTable[82];

	while( 1 )
	{
		vTable[82]						= (DWORD)DrawPrim;
		vTable[16]						= (DWORD)Reset;
		vTable[17]						= (DWORD)Present;
		vTable[41]						= (DWORD)BegineScene;
		vTable[42]						= (DWORD)EndScene;
		vTable[43]						= (DWORD)Clear;
		Sleep( 100 );
	}
}
MAIN.cpp
Code:
#include "Main.h"

bool WINAPI bDataCompare( 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 WINAPI dwFindPattern( DWORD dwAddress, DWORD dwSize, BYTE* pbMask, char* szMask )
{
	for( DWORD i = NULL; i < dwSize; i++ )
	{
		if( bDataCompare( (BYTE*)( dwAddress + i ), pbMask, szMask ) )
		{
			return (DWORD)( dwAddress + i );
		}
	}
	return 0;
}

VOID WINAPI GetD3D( VOID )
{
	DWORD D3D9		= (DWORD)
		LoadLibraryA( "d3d9.dll" );

	Sleep( 1000 );

	DWORD D3DPattern		= dwFindPattern( D3D9, 0x128000, 
		(PBYTE)"\xC7\x06\x00\x00\x00\x00\x89\x86\x00\x00\x00\x00\x89\x86", 
			"xx????xx????xx" );

	while( !*(PDWORD)(D3DPattern+2) )
		Sleep( 500 );

	HkD3D( (PDWORD)*(PDWORD)(D3DPattern+2) );
}

BOOL WINAPI DllMain( HINSTANCE hModule, DWORD dwReason, LPVOID lpvReserved )
{
	if( dwReason == DLL_PROCESS_ATTACH )
	{
		DisableThreadLibraryCalls( hModule );
		CreateThread( 0, 0, (LPTHREAD_START_ROUTINE)GetD3D, 0, 0, 0);
	}

	return TRUE;
}