Code:
// Includes
#include <d3d9.h>
#include <d3dx9.h>
#include <dwmapi.h> // Desktop Windows Manager, only on Vista / Win7
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <fcntl.h>
#include <math.h>
//---------------------------------------------------------------------------
// Import libraries to link with
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
#pragma comment(lib, "dwmapi.lib")
#define CALIBRATING 0
#define DEBUG_HQ 0
#define MOTION 0
// Global colors - change as you want to customize your version
// format is 0xAARRGGBB: AA alpha (0=transparent, FF=opaque), RR red, GG green, BB blue
#define ARGB_TRANS 0x00000000 // 100% alpha
#define COLOR_FRIEND 0x800000FF // blue
#define COLOR_ENEMY 0xFFC00000 // dark red
#define COLOR_DEAD 0x80444444 // dead body, the player is watching killcam
#define COLOR_SENTRY 0x8000B050 // green
#define COLOR_EXPLOSIVE 0x407F7F7F // yellow
// colors for mini-map
#define MAP_COLOR_FRIEND 0xFF4444FF
#define MAP_COLOR_ENEMY 0XFFFF4444
#define MAP_COLOR_ENEMY_COLDBLOODED 0XFFFFBF44
#define MAP_COLOR_SENTRY 0xFF00B050 // green
#define MAP_COLOR_EXPLOSIVE 0xFFFFFF00 // yellow
// Game offsets - to be changed for new COD6 builds
#define REFDEF 0x85B6F0
#define ENTITY 0x8F3CA8
#define CLIENTINFO 0x8E77B0
#define CG 0x7F0F78
#define CGS_T 0x7ED3B8
#define ISINGAME 0x7F0F88
#define VIEWANGLEY 0xB2F8D0
#define PLAYERMAX 18 // number of players to loop in
#define ENTITIESMAX 2048 // total number of entities present
#define M_PI 3.1415f
// players poses
#define FLAGS_CROUCHED 0x0004
#define FLAGS_PRONE 0x0008
#define FLAGS_FIRING 0x0200
// Structs
// originally in classes.h
class Vector
{
public:
Vector() { x = y = z = 0.0f; }
Vector(float X, float Y, float Z) { x = X; y = Y; z = Z; }
Vector(const Vector &v) { x = v.x; y = v.y; z = v.z; }
float length() { return sqrt(x*x+y*y+z*z); }
void substract(Vector sub) { x-=sub.x; y -= sub.y; z -= sub.z; }
float dotproduct(Vector dot) { return (x*dot.x+y*dot.y+z*dot.z); }
void normalize() { float l = 1/length(); x *= l; y *= l; z *= l; }
float vectodegree(Vector to) { return ((180.0f/3.1415f)*(asinf(dotproduct(to)))); }
Vector RotateX(Vector in, float angle) { float a,c,s; Vector out; a = (float) (angle * M_PI/180); c = (float) cos(a); s = (float) sin(a); out.x = in.x; out.y = c*in.y - s*in.z; out.z = s*in.y + c*in.z; return out; }
Vector RotateY(Vector in, float angle) { float a,c,s; Vector out; a = (float) (angle * M_PI/180); c = (float) cos(a); s = (float) sin(a); out.x = c*in.x + s*in.z; out.y = in.y; out.z = -s*in.x + c*in.z; return out; }
Vector RotateZ(Vector in, float angle) { float a,c,s; Vector out; a = (float) (angle * M_PI/180); c = (float) cos(a); s = (float) sin(a); out.x = c*in.x - s*in.y; out.y = s*in.x + c*in.y; out.z = in.z; return out; }
void nullvec() { x = y = z = 0; }
void operator = (const float *farray) { x = farray[0]; y = farray[1]; z = farray[2]; }
void operator = (const float &val) { x = y = z = val; }
float operator [] (unsigned int element) { switch(element) { case 1: return y; case 2: return z; default: return x; } }
Vector operator + (const Vector& add) const { return Vector(x+add.x,y+add.y,z+add.z); }
void operator += (const Vector& add) { x += add.x; y += add.y; z += add.z; }
Vector operator - (const Vector& sub) const { return Vector(x-sub.x,y-sub.y,z-sub.z); }
void operator -= (const Vector& sub) { x -= sub.x; y -= sub.y; z -= sub.z; }
Vector operator * (const float mul) const { return Vector(x*mul,y*mul,z*mul); }
void operator *= (const float mul) { x *= mul; y *= mul; z *= mul; }
Vector operator / (const float mul) const { return Vector(x/mul,y/mul,z/mul); }
void operator /= (const float mul) { x /= mul; y /= mul; z /= mul; }
bool operator == (const Vector& eqal) { return ((x == eqal.x) && (y == eqal.y) && (z == eqal.z)); }
bool operator != (const Vector& eqal) { return ((x != eqal.x) && (y != eqal.y) && (z != eqal.z)); }
bool operator > (const Vector& eqal) { return ((x > eqal.x) && (y > eqal.y) && (z > eqal.z)); }
bool operator < (const Vector& eqal) { return ((x < eqal.x) && (y < eqal.y) && (z < eqal.z)); }
bool operator >= (const Vector& eqal) { return ((x >= eqal.x) && (y >= eqal.y) && (z >= eqal.z)); }
bool operator <= (const Vector& eqal) { return ((x <= eqal.x) && (y <= eqal.y) && (z <= eqal.z)); }
float x;
float y;
float z;
};
class MW2_View_Y
{
public:
Vector Recoil; // 0x0000
char _p00[24]; // 0x000C
Vector viewAngles; // 0x0024
char _p01[16]; // 0x0030
float AngleY; // 0x0040
float AngleX; // 0x0044
};
class MW2_CG_T
{
public:
__int32 ClientNumber;//0x0000
char unknown4[72]; //0x0004
__int32 Health; //0x004C
};
class MW2_RefDef_T
{
public:
char unknown1[8];
__int32 ScreenX; //0x0000
__int32 ScreenY; //0x0004
float fov_x; //0x0008
float fov_y; //0x000C
Vector Origin; //0x0010
Vector ViewAxis[3]; //0x0014
char unknown24[16200]; //0x0018
Vector rdViewAngles; //0x3F60
};
class MW2_ClientInfo_T
{
public:
char Unknown1[12];
char Name[16]; //0x000C
__int32 Team; //0x001C
__int32 Team2; //0x0020
char unknown36[8]; //0x0024
__int32 perk; //0x002C
char unknown48[16]; //0x0030
char BodyModel[64]; //0x0040
char HeadModel[64]; //0x0080
char WeaponModel[64]; //0x00C0
char WeaponModel2[64]; //0x0100
char WeaponExplosive[64]; //0x0140
char unknown372[552]; //0x0180
__int32 Pose; //0x03A8
char unknown936[96]; //0x03AC
__int32 pose2; //0x040C
char unknown1028[284]; //0x0410
};
class MW2_Entity_T
{
public:
__int16 unknown0; //0x0000
__int8 Valid; //0x0002
char unknown4[21]; //0x0003
Vector Origin; //0x0018
char unknown36[72]; //0x0024
__int32 Pose; //0x006C
char unknown109[12]; //0x0070
float fPitch; //0x007C
float fYaw; //0x0080
float fRoll; //0x0084
char unknown136[84]; //0x0088
__int32 ClientNumber; //0x00DC
__int32 EntityType; //0x00E0
__int8 PlayerPose; //0x00E4
__int8 Shooting; //0x00E5
__int8 Zoomed; //0x00E6
char unknown231[193]; //0x00E7
__int16 WeaponNum; //0x01A8
char unknown426[50]; //0x01AA
__int32 IsAlive; //0x01DC
char unknown480[36]; //0x01E0
};
enum entity_type_t
{
ET_GENERAL = 0,
ET_PLAYER = 1,
ET_PLAYER_CORPSE = 2,
ET_ITEM = 3,
ET_EXPLOSIVE = 4,
ET_INVISIBLE = 5,
ET_SCRIPTMOVER = 6,
ET_SOUND_BLEND = 7,
ET_FX = 8,
ET_LOOP_FX = 9,
ET_PRIMARY_LIGHT = 10,
ET_TURRET = 11,
ET_HELICOPTER = 12,
ET_PLANE = 13,
ET_VEHICLE = 14,
ET_VEHICLE_COLLMAP = 15,
ET_VEHICLE_CORPSE = 16,
ET_VEHICLE_SPAWNER = 17
};
class cPlayerInfo
{
public:
COLORREF color;
};
// globals read from COD6
int my_team;
//int viewstatus;
int kills;
int deaths;
int lastkills = 0;
int lastdeaths = 0;
int killcount;
cPlayerInfo player[PLAYERMAX];
DWORD IsInGame;
MW2_ClientInfo_T mw2_clientinfo[PLAYERMAX];
MW2_Entity_T mw2_entities[ENTITIESMAX]; // get a copy of entities
MW2_View_Y mw2_view;
MW2_RefDef_T refdef;
MW2_CG_T CG_T;
long gTicks = 0;
int mouse_move_x = 0;
int mouse_move_y = 0;
int wndpos[2] = {0, 0};
// Globals
wchar_t status[512] = L"waiting"; //status message to display
WCHAR *g_wcpAppName = APPNAME;
INT g_iWidth = 800;
INT g_iHeight = 600;
MARGINS g_mgDWMMargins = {-1, -1, -1, -1};
IDirect3D9Ex *g_pD3D = NULL;
IDirect3DDevice9Ex *g_pD3DDevice = NULL;
ID3DXLine *line = NULL;
ID3DXLine *back_line = NULL;
ID3DXLine *chrosshair_line= NULL;
ID3DXFont *g_font = NULL;
ID3DXFont *g_killstreak_font = NULL;
//ID3DXFont *g_kills_font = NULL;
HANDLE ConsolehWnd
HANDLE mw2_process = NULL;
DWORD mw2_pid = 0;
HWND mw2_hwnd = NULL;
int resolution[2];
int screencenter[2];
int mouse_center[2];
int border_x, border_y;
bool init_ok = FALSE;
//===========================================================================
//---------------------------------------------------------------------------
int MinDist( float dists[] );
bool FindAngle( Vector target, Vector player, float *ftraj_angle, float range );
void DrawString(int x, int y, COLORREF color, bool center, char* text);
void DrawBox(int x, int y, int w, int h, COLORREF color);
bool WorldToScreen(const Vector &WorldLocation, float *fScreenX, float *fScreenY);
void ReadGame();
void Esp();
void CrossHair();
void Render();
void DisplayStatus();
void Toggles();
//---------------------------------------------------------------------------
Vector viewangles;
// toggles for Fn keys
#define FN_TOGGLES 3
bool Fn[FN_TOGGLES] = {
true, true, // F1 F2
true // F3 F4
};
wchar_t* Fn_label[FN_TOGGLES] = {
L"crosshair", // F1
L"box esp", // F2
L"status" // F3
};
bool aimbot = true;
bool boxEsp = true;
bool crosshair = true;
//---------------------------------------------------------------------------
// Render()
//
// Render the scene to the back buffer
VOID Render(VOID)
{
gTicks++;
// Sanity check
if(g_pD3DDevice == NULL) return;
// Clear the back buffer and z buffer to transparent
g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, ARGB_TRANS, 1.0f, 0);
// Render scene
if (SUCCEEDED(g_pD3DDevice->BeginScene()))
{
if (init_ok) // if everything is correctly initialised
{
IsInGame = 0;
ReadGame(); // read all structures in memory
Toggles();
Esp(); // draw game overlay
Aimbot();
CrossHair();
DisplayStatus();
}
g_pD3DDevice->EndScene();
}
// Update display
g_pD3DDevice->PresentEx(NULL, NULL, NULL, NULL, NULL);
}
//---------------------------------------------------------------------------
// WinMain()
//
// Program entry point
//---------------------------------------------------------------------------
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, INT)
{
HWND hWnd = NULL;
MSG uMsg;
HRESULT hr;
//----------Enabling the Console Window----------//
AllocConsole();
ConsolehWnd = GetStdHandle(STD_OUTPUT_HANDLE);
int hCrt = _open_osfhandle((long) ConsolehWnd, _O_TEXT);
FILE* hf_out = _fdopen(hCrt, "w");
setvbuf(hf_out, NULL, _IONBF, 1);
*stdout = *hf_out;
HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
hCrt = _open_osfhandle((long) handle_in, _O_TEXT);
FILE* hf_in = _fdopen(hCrt, "r");
setvbuf(hf_in, NULL, _IONBF, 128);
*stdin = *hf_in;
//------------------------------------------------//
CreateMutex(0,false,MUTEXNAME );
if(GetLastError())
{
MessageBox(0,L"External BoxESP is already running!",L"Error",MB_ICONERROR);
return 0;
}
WaitForLoad();
WNDCLASSEX wc = {sizeof(WNDCLASSEX), // cbSize
NULL, // style
WindowProc, // lpfnWndProc
NULL, // cbClsExtra
NULL, // cbWndExtra
hInstance, // hInstance
LoadIcon(NULL, IDI_APPLICATION), // hIcon
LoadCursor(NULL, IDC_ARROW), // hCursor
NULL, // hbrBackground
NULL, // lpszMenuName
g_wcpAppName, // lpszClassName
LoadIcon(NULL, IDI_APPLICATION)};// hIconSm
RegisterClassEx(&wc);
hWnd = CreateWindowEx(WS_EX_TOPMOST | WS_EX_COMPOSITED | WS_EX_TRANSPARENT | WS_EX_LAYERED,
g_wcpAppName, // lpClassName
g_wcpAppName, // lpWindowName
WS_POPUP, // dwStyle
CW_USEDEFAULT, CW_USEDEFAULT, // x, y
g_iWidth, g_iHeight, // nWidth, nHeight
NULL, // hWndParent
NULL, // hMenu
hInstance, // hInstance
NULL); // lpParam
// Extend glass to cover whole window
hr = DwmExtendFrameIntoClientArea(hWnd, &g_mgDWMMargins);
if (SUCCEEDED(D3DStartup(hWnd)))
{
// Show the window
ShowWindow(hWnd, SW_SHOWDEFAULT);
UpdateWindow(hWnd);
// Enter main loop
while(TRUE)
{
// Check for a message
if(PeekMessage(&uMsg, NULL, 0, 0, PM_REMOVE))
{
// Check if the message is WM_QUIT
if(uMsg.message == WM_QUIT)
{
// Break out of main loop
break;
}
// Pump the message
TranslateMessage(&uMsg);
DispatchMessage(&uMsg);
}
// Check if we need initialization
if (mw2_hwnd == NULL) {
mw2_hwnd = FindWindow(NULL,L"Modern Warfare 2");
if (mw2_hwnd != NULL)
swprintf_s(status, L"app found\n");
}
if ((mw2_hwnd != NULL) && (mw2_pid == 0)) {
GetWindowThreadProcessId(mw2_hwnd,&mw2_pid);
}
if ((mw2_process == NULL) && (mw2_pid != 0)) {
mw2_process = OpenProcess(PROCESS_VM_READ,false,mw2_pid);
}
if (mw2_process != NULL) {
if ((!init_ok) || ((gTicks % 20) == 0)) {
RECT client_rect;
GetClientRect(mw2_hwnd, &client_rect);
resolution[0] = client_rect.right;
resolution[1] = client_rect.bottom;
screencenter[0] = resolution[0]/2;
screencenter[1] = resolution[1]/2;
RECT bounding_rect;
GetWindowRect(mw2_hwnd,&bounding_rect);
mouse_center[0] = (bounding_rect.right - bounding_rect.left) / 2;
mouse_center[1] = (bounding_rect.bottom - bounding_rect.top) / 2;
border_x = ::GetSystemMetrics(SM_CXBORDER);
border_y = ::GetSystemMetrics(SM_CYCAPTION);
if (init_ok) {
if ((wndpos[0] != bounding_rect.left) || (wndpos[1] != bounding_rect.top)) {
MoveWindow(hWnd, bounding_rect.left,bounding_rect.top, resolution[0],resolution[1],false);
wndpos[0] = bounding_rect.left;
wndpos[1] = bounding_rect.top;
}
} else {
if ((bounding_rect.left == 0) && (bounding_rect.top == 0)) {
// we force a 1 pixel move, otherwise the window is not resized (bug?)
MoveWindow(hWnd, -1, -1, resolution[0],resolution[1],false);
}
MoveWindow(hWnd, bounding_rect.left,bounding_rect.top, resolution[0],resolution[1],false);
wndpos[0] = bounding_rect.left;
wndpos[1] = bounding_rect.top;
D3DShutdown();
D3DStartup(hWnd);
}
init_ok = true;
}
}
Render();
if ((init_ok) && ((gTicks % 10) == 0)) { // check only every 10 frames
if (FindWindow(NULL,L"Modern Warfare 2") == NULL) {
SendMessage(hWnd, WM_CLOSE, NULL, NULL); // quit if game is closed
}
}
}
}
// Shutdown Direct3D
D3DShutdown();
// Exit application
return 0;
}
//---------------------------------------------------------------------------
void AngleVectors(const Vector &angles, Vector *forward, Vector *right, Vector *up)
{
float angle;
static float sr, sp, sy, cr, cp, cy, cpi = (M_PI*2/360);
angle = angles.y * cpi;
sy = sin(angle);
cy = cos(angle);
angle = angles.x * cpi;
sp = sin(angle);
cp = cos(angle);
angle = angles.z * cpi;
sr = sin(angle);
cr = cos(angle);
if(forward)
{
forward->x = cp*cy;
forward->y = cp*sy;
forward->z = -sp;
}
if(right)
{
right->x = (-1*sr*sp*cy+-1*cr*-sy);
right->y = (-1*sr*sp*sy+-1*cr*cy);
right->z = -1*sr*cp;
}
if(up)
{
up->x = (cr*sp*cy+-sr*-sy);
up->y = (cr*sp*sy+-sr*cy);
up->z = cr*cp;
}
}
//---------------------------------------------------------------------------
bool WorldToScreen(const Vector &WorldLocation, float *fScreenX, float *fScreenY)
{
Vector vLocal, vTransForm, vForward, vRight, vUpward;
AngleVectors(viewangles,&vForward,&vRight,&vUpward);
vLocal = WorldLocation - refdef.Origin;
vTransForm.x = vLocal.dotproduct(vRight);
vTransForm.y = vLocal.dotproduct(vUpward);
vTransForm.z = vLocal.dotproduct(vForward);
if (vTransForm.z < 0.01)
return false;
*fScreenX = screencenter[0] + (screencenter[0]/vTransForm.z * (1/refdef.fov_x)) * vTransForm.x;
*fScreenY = screencenter[1] - (screencenter[1]/vTransForm.z * (1/refdef.fov_y)) * vTransForm.y;
return true;
}
//---------------------------------------------------------------------------
void DrawBox(float x, float y, float w, float h, COLORREF color)
{
x += border_x;
y += border_y;
D3DXVECTOR2 points[5];
points[0] = D3DXVECTOR2(x, y);
points[1] = D3DXVECTOR2(x+w, y);
points[2] = D3DXVECTOR2(x+w, y+h);
points[3] = D3DXVECTOR2(x, y+h);
points[4] = D3DXVECTOR2(x, y);
line->Draw(points, 5, color);
}
//---------------------------------------------------------------------------
void ReadGame()
{
ReadProcessMemory(mw2_process,(PVOID)ISINGAME,&IsInGame,4,NULL);
if (IsInGame)
{
ReadProcessMemory(mw2_process,(PVOID)(CG),&CG_T,sizeof(MW2_CG_T),NULL);
ReadProcessMemory(mw2_process,(PVOID)(REFDEF),&refdef,sizeof(MW2_RefDef_T),NULL);
ReadProcessMemory(mw2_process,(PVOID)(VIEWANGLEY-0x40),&mw2_view,sizeof(mw2_view), NULL);
viewangles = mw2_view.viewAngles;
ReadProcessMemory(mw2_process,(PVOID)ENTITY,mw2_entities,sizeof(mw2_entities),NULL);
ReadProcessMemory(mw2_process,(PVOID)CLIENTINFO,mw2_clientinfo,sizeof(mw2_clientinfo),NULL);
for(int i = 0; i < PLAYERMAX; i++)
{
if (CG_T.ClientNumber == mw2_entities[i].ClientNumber) {
my_team = mw2_clientinfo[i].Team;
break;
}
}
}
}
void Esp()
{
float drawx, drawy;
bool enemy;
float ScreenX, ScreenY;
if (!IsInGame)
return;
for(int i = 0; i < ENTITIESMAX; i++)
{
if ((i < PLAYERMAX) && (mw2_entities[i].EntityType == ET_PLAYER)
&& mw2_entities[i].Valid && mw2_entities[i].IsAlive
&& (CG_T.ClientNumber != mw2_entities[i].ClientNumber)) //Check if the CG Client is the EntityClient ?????
{
enemy = false;
if (mw2_entities[i].IsAlive & 0x0001)
{
if ( ((mw2_clientinfo[i].Team == 1) || (mw2_clientinfo[i].Team == 2)) && (mw2_clientinfo[i].Team == my_team) )// same team
player[i].color = COLOR_ENEMY;
else{
enemy = true;
player[i].color = COLOR_FRIEND;
}
} else
player[i].color = COLOR_DEAD;
if (WorldToScreen(mw2_entities[i].Origin, &ScreenX, &ScreenY))
{
// player[i].Origin is at the players foot
float headX, headY;
Vector head = mw2_entities[i].Origin;
head.z += 60;
WorldToScreen(head, &headX, &headY);
drawy = ScreenY - headY;
if (drawy < 10) // minimal size of the box
drawy = 10;
if (mw2_entities[i].Pose & FLAGS_CROUCHED)
{
drawy /= 1.5f;
drawx = drawy / 1.5f; // w/h ratio
}
else if (mw2_entities[i].Pose & FLAGS_PRONE)
{
drawy /= 3.f;
drawx = drawy * 2.f; // w/h ratio
}
else
drawx = drawy / 2.75f; // standing up
if (Fn[1]) { // F2 box
DrawBox(ScreenX-(drawx/2),ScreenY,drawx,-drawy,player[i].color);
}
}
} else if ((mw2_entities[i].EntityType == ET_TURRET) || (mw2_entities[i].EntityType == ET_EXPLOSIVE)) {
if (mw2_entities[i].IsAlive & 0x01) {
COLORREF color = (mw2_entities[i].EntityType == ET_TURRET) ? COLOR_SENTRY : COLOR_EXPLOSIVE;
if (WorldToScreen(mw2_entities[i].Origin, &ScreenX, &ScreenY))
{
if (mw2_entities[i].EntityType == ET_TURRET)
{
float headX, headY;
Vector head = mw2_entities[i].Origin;
head.z += 20;
WorldToScreen(head, &headX, &headY);
drawy = ScreenY - headY;
if (drawy < 5) // minimal size of the box
drawy = 5;
drawx = drawy / 2.75f;
DrawBox(ScreenX-(drawx/2),ScreenY,drawx,-drawy,color);
}
}
}
} else if (mw2_entities[i].EntityType == ET_SCRIPTMOVER) {
// HQ?
if (DEBUG_HQ) {
if (WorldToScreen(mw2_entities[i].Origin, &ScreenX, &ScreenY)) {
char str[128];
sprintf_s(str, "%i/%i/%i", i, mw2_entities[i].IsAlive, mw2_entities[i].unknown0);
DrawString(ScreenX,ScreenY,0x7FFFFFFF,str, g_font);
}
}
}
}
}