Public paste
MW2 HACK NOT PUBLIC
By: Maik Hack | Date: Sep 2 2010 17:21 | Format: None | Expires: never | Size: 43.1 KB | Hits: 1704

  1. // Credits Maikel233 You Have To Debug It To start
  2. // for maximum stealth, change the names below to something personal
  3. #define APPNAME         L"maik"
  4. #define MUTEXNAME       L"maik"
  5.  
  6. // Includes
  7. #include <d3d9.h>
  8. #include <d3dx9.h>
  9. #include <dwmapi.h>            
  10. #include <stdio.h>
  11. #include <math.h>
  12. //---------------------------------------------------------------------------
  13. // Import libraries to link with
  14. #pragma comment(lib, "d3d9.lib")
  15. #pragma comment(lib, "d3dx9.lib")
  16. #pragma comment(lib, "dwmapi.lib")
  17.  
  18. #define CALIBRATING             0
  19. #define DEBUG_HQ                0
  20. #define MOTION                  0
  21. // Global colors - change as you want to customize your version
  22. // format is 0xAARRGGBB: AA alpha (0=transparent, FF=opaque), RR red, GG green, BB blue
  23. #define ARGB_TRANS              0x00000000 // 100% alpha
  24. #define COLOR_FRIEND    0x800000FF // blue
  25. #define COLOR_ENEMY             0x80C00000 // dark red
  26. #define COLOR_ENEMY_COLDBLOODED         0x80FFBF00 // orange
  27. #define COLOR_DEAD              0x80444444 // dead body, the player is watching killcam
  28. #define COLOR_SENTRY    0x8000B050              // green
  29. #define COLOR_EXPLOSIVE 0x407F7F7F              // yellow
  30. // colors for mini-map
  31. #define MAP_COLOR_FRIEND        0xFF4444FF
  32. #define MAP_COLOR_ENEMY         0XFFFF4444
  33. #define MAP_COLOR_ENEMY_COLDBLOODED     0XFFFFBF44
  34. #define MAP_COLOR_SENTRY        0xFF00B050              // green
  35. #define MAP_COLOR_EXPLOSIVE     0xFFFFFF00              // yellow
  36.  
  37. // Game offsets - to be changed for new COD6 builds
  38. // these are for 1.0.184
  39. #define REFDEF 0x85F030
  40. #define ENTITY 0x8F7AF8
  41. #define CLIENTINFO 0x8EB2C8
  42. #define CG_T 0x7F49BC
  43. #define CGS_T 0x7F0CF8
  44.  
  45. #define ISINGAME 0x7F48C8
  46. #define VIEWANGLEY 0xB35A40
  47.  
  48. #define PLAYERMAX       18                      // number of players to loop in
  49. #define ENTITIESMAX     2048            // total number of entities present
  50.  
  51. #define M_PI                                    3.1415f
  52.  
  53. // players poses
  54. #define FLAGS_CROUCHED  0x0004
  55. #define FLAGS_PRONE             0x0008
  56. #define FLAGS_FIRING    0x0200
  57.  
  58. // Structs
  59. // originally in classes.h
  60. class Vector
  61. {
  62. public:
  63.         Vector() { x = y = z = 0.0f; }
  64.         Vector(float X, float Y, float Z) { x = X; y = Y; z = Z; }
  65.         Vector(const Vector &v) { x = v.x; y = v.y; z = v.z; }
  66.  
  67.         float length() { return sqrt(x*x+y*y+z*z); }
  68.         void substract(Vector sub) { x-=sub.x; y -= sub.y; z -= sub.z; }
  69.         float dotproduct(Vector dot) { return (x*dot.x+y*dot.y+z*dot.z); }
  70.         void normalize() { float l = 1/length(); x *= l; y *= l; z *= l; }
  71.         float vectodegree(Vector to) { return ((180.0f/3.1415f)*(asinf(dotproduct(to)))); }
  72.         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; }
  73.         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; }
  74.         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; }
  75.         void nullvec() { x = y = z = 0; }
  76.  
  77.         void operator = (const float *farray) { x = farray[0]; y = farray[1]; z = farray[2]; }
  78.         void operator = (const float &val) { x = y = z = val; }
  79.  
  80.         float operator [] (unsigned int element) { switch(element) { case 1: return y; case 2: return z; default: return x; } }
  81.  
  82.         Vector operator + (const Vector& add) const { return Vector(x+add.x,y+add.y,z+add.z); }
  83.         void operator += (const Vector& add) { x += add.x; y += add.y; z += add.z; }
  84.         Vector operator - (const Vector& sub) const     { return Vector(x-sub.x,y-sub.y,z-sub.z); }
  85.         void operator -= (const Vector& sub) { x -= sub.x; y -= sub.y; z -= sub.z; }
  86.         Vector operator * (const float mul) const { return Vector(x*mul,y*mul,z*mul); }
  87.         void operator *= (const float mul) { x *= mul; y *= mul; z *= mul; }
  88.         Vector operator / (const float mul) const { return Vector(x/mul,y/mul,z/mul); }
  89.         void operator /= (const float mul) { x /= mul; y /= mul; z /= mul; }
  90.  
  91.         bool operator == (const Vector& eqal) { return ((x == eqal.x) && (y == eqal.y) && (z == eqal.z)); }
  92.         bool operator != (const Vector& eqal) { return ((x != eqal.x) && (y != eqal.y) && (z != eqal.z)); }
  93.         bool operator > (const Vector& eqal) { return ((x > eqal.x) && (y > eqal.y) && (z > eqal.z)); }
  94.         bool operator < (const Vector& eqal) { return ((x < eqal.x) && (y < eqal.y) && (z < eqal.z)); }
  95.         bool operator >= (const Vector& eqal) { return ((x >= eqal.x) && (y >= eqal.y) && (z >= eqal.z)); }
  96.         bool operator <= (const Vector& eqal) { return ((x <= eqal.x) && (y <= eqal.y) && (z <= eqal.z)); }
  97.  
  98.         float x;
  99.         float y;
  100.         float z;
  101. };
  102.  
  103.  
  104. // from Big Dave
  105. class MW2_View_Y
  106. {
  107. public:
  108.         Vector       Recoil;            // 0x0000
  109.         char         _p00[24];          // 0x000C
  110.         Vector       viewAngles;        // 0x0024
  111.         char         _p01[16];          // 0x0030
  112.         float        AngleY;            // 0x0040
  113.         float        AngleX;            // 0x0044
  114. };
  115.  
  116.  
  117. class MW2_ClientInfo_T
  118. {
  119. public:
  120.         char    Unknown1[12];
  121.         char    name[16]; //0x000C  
  122.         __int32 team; //0x001C  
  123.         __int32 team2; //0x0020  
  124.         char    unknown36[8]; //0x0024
  125.         __int32 perk;                   //0x002C
  126.         char    unknown48[16]; //0x0030
  127.         char    BodyModel[64]; //0x0040  
  128.         char    HeadModel[64]; //0x0080  
  129.         char    WeaponModel[64]; //0x00C0  
  130.         char    WeaponModel2[64]; //0x0100  
  131.         char    WeaponExplosive[64]; //0x0140
  132.         char    unknown372[552]; //0x0180
  133.         __int32 pose; //0x03A8  
  134.         char    unknown936[96]; //0x03AC
  135.         __int32 pose2; //0x040C  
  136.         char    unknown1028[284]; //0x0410
  137. };
  138.  
  139. class MW2_Entity_T
  140. {
  141. public:
  142.         __int16         unknown0; //0x0000
  143.         __int16         valid; //0x0002  
  144.         char            unknown4[20]; //0x0003
  145.         Vector          pos; //0x0018  
  146.         char unknown36[72]; //0x0024
  147.         __int32         pose; //0x006C  
  148.         char            unknown109[12]; //0x0070
  149.         float           fPitch; //0x007C  
  150.         float           fYaw; //0x0080  
  151.         float           fRoll; //0x0084  
  152.         char            unknown136[84]; //0x0088
  153.         __int32         clientnum; //0x00DC
  154.         __int32         typ; //0x00E0  
  155.         __int8          PlayerPose; //0x00E4  
  156.         __int8          Shooting; //0x00E5  
  157.         __int8          Zoomed; //0x00E6  
  158.         char            unknown231[193]; //0x00E7
  159.         __int16         WeaponNum; //0x01A8  
  160.         char            unknown426[50]; //0x01AA
  161.         __int32         alive; //0x01DC
  162.         char            unknown480[36]; //0x01E0
  163. };
  164. enum entity_type_t
  165. {
  166.         ET_GENERAL            = 0,
  167.         ET_PLAYER            = 1,
  168.         ET_PLAYER_CORPSE    = 2,
  169.         ET_ITEM                = 3,
  170.         ET_EXPLOSIVE            = 4,
  171.         ET_INVISIBLE        = 5,
  172.         ET_SCRIPTMOVER        = 6,
  173.         ET_SOUND_BLEND        = 7,
  174.         ET_FX                = 8,
  175.         ET_LOOP_FX            = 9,
  176.         ET_PRIMARY_LIGHT    = 10,
  177.         ET_TURRET            = 11,
  178.         ET_HELICOPTER        = 12,
  179.         ET_PLANE            = 13,
  180.         ET_VEHICLE            = 14,
  181.         ET_VEHICLE_COLLMAP    = 15,
  182.         ET_VEHICLE_CORPSE    = 16,
  183.         ET_VEHICLE_SPAWNER    = 17
  184. };  
  185.  
  186. class cPlayerInfo
  187. {
  188. public:
  189.         COLORREF        color;
  190. };
  191.  
  192. // globals read from COD6
  193. int localclientnum, my_team;
  194. //int viewstatus;
  195. int kills;
  196. int deaths;
  197. int lastkills = 0;
  198. int lastdeaths = 0;
  199. int killcount;
  200.  
  201. cPlayerInfo                     player[PLAYERMAX];
  202. DWORD                           IsInGame;
  203. MW2_ClientInfo_T        mw2_clientinfo[PLAYERMAX];             
  204. MW2_Entity_T            mw2_entities[ENTITIESMAX];              // get a copy of entities
  205. MW2_View_Y                      mw2_view;
  206. long                            gTicks = 0;
  207.  
  208. int                                     mouse_move_x = 0;
  209. int                                     mouse_move_y = 0;
  210.  
  211. // Globals
  212. wchar_t status[512] = L"waiting";       //status message to display
  213.  
  214. WCHAR                   *g_wcpAppName   = APPNAME;                                      // App name
  215. INT                     g_iWidth                = 800;                                          // initial width
  216. INT                     g_iHeight               = 600;                                          // initial height
  217. MARGINS                 g_mgDWMMargins  = {-1, -1, -1, -1};                     // margins for DWM
  218. IDirect3D9Ex            *g_pD3D                 = NULL;                                         // Direct3D object
  219. IDirect3DDevice9Ex      *g_pD3DDevice   = NULL;                                         // Direct3D device
  220. ID3DXLine                               *line                   = NULL;                                         // Direct3D line for player box
  221. ID3DXLine                               *back_line              = NULL;                                         // Direct3D line for black background behind status text
  222. ID3DXLine                               *radar_line             = NULL;                                         // Direct3D line for black background behind status text
  223. ID3DXFont                               *g_font                 = NULL;                                         // Direct3D font for status display & player name
  224. ID3DXFont                               *g_killstreak_font = NULL;                                      // Direct3D font for displaying current killstreak
  225. //ID3DXFont                             *g_kills_font = NULL;                                           // Direct3D font for displaying current kills and deaths
  226.  
  227.  
  228. // from OSHeCoD6
  229. HANDLE                                  mw2_process             = NULL;                                         // COD6 process
  230. DWORD                                   mw2_pid                 = 0;                                            // COD6 process PID
  231. HWND                                    mw2_hwnd                = NULL;                                         // COD6 window
  232. int                                             resolution[2];                                                          // COD6 screen size
  233. int                                             screencenter[2];                                                        // COD6 screen center (local coordinates)
  234. int                                             mouse_center[2];                                                        // center for mouse movement
  235. int                                             border_x, border_y;                                                     // COD6 border size
  236.  
  237. bool                                    init_ok = FALSE;                                                        // is everything initialised?
  238. //===========================================================================
  239. //---------------------------------------------------------------------------
  240. void MouseMove( float x, float y );
  241. int MinDist( float dists[] );
  242. bool FindAngle( Vector target, Vector player, float *ftraj_angle, float range );
  243. void DrawString(int x, int y, COLORREF color, bool center, char* text);
  244. void DrawBox(int x, int y, int w, int h, COLORREF color);
  245. bool WorldToScreen(const Vector &WorldLocation, float *fScreenX, float *fScreenY);
  246. void ReadGame();
  247. void Esp();
  248. void Radar();
  249. void CrossHair();
  250. void Render();
  251. void Bot();
  252. void KillCounter();
  253. void DisplayStatus();
  254. void Toggles();
  255. void draw4Outline(float x1, float y1, float x2, float y2,
  256.                                   float x3, float y3, float x4, float y4, D3DCOLOR color);
  257. void fillRect(float x, float y, float w, float h, D3DCOLOR color);
  258. bool FindSlope(Vector *target, Vector *player, float vel, float *ftraj_slope);
  259. //---------------------------------------------------------------------------
  260. Vector mypos, viewangles;
  261. float fov[2];
  262. float grav = 322.f;                     // in 1/10th of feet/sē
  263. float tube_vel = 1550.f;        // which is 155 ft/s, or 47m/s
  264. float knife_vel = 900.f;        // which is 90 ft/s, or 27m/s
  265.  
  266. // toggles for Fn keys
  267. #define FN_TOGGLES              12
  268. bool    Fn[FN_TOGGLES] = {  true, true,                 // F1 F2
  269. false, true,            // F3 F4
  270. true, false,            // F5 F6
  271. false, false,           // F7 F8
  272. false, false,                   // F9 F10
  273. false, true };          // F11 F12
  274. wchar_t*        Fn_label[FN_TOGGLES] = {
  275.         L"radar",               // F1
  276.         L"box esp",             // F2
  277.         L"crosshair",   // F3
  278.         L"explosives",  // F4
  279.         L"aimbot",              // F5
  280.         L"tubebot",             // F6
  281.         L"knifebot",    // F7
  282.         L"autostab",    // F8
  283.         L"triggerbot",  // F9
  284.         L"",                    // F10
  285.         L"",                    // F11
  286.         L"status",              // F12
  287. };
  288.  
  289. // mini-map
  290. const float                             radar_size = 160.0f;            // size of the radar in pixels
  291. const float                             radar_offset = 20.0f;           // margin from top and right of the screen, in pixels
  292. // radar globals
  293. float                                   rx, ry;                                         // position x/y of mini-map
  294. float                                   rh, rw;                                         // size of mini-map
  295. //---------------------------------------------------------------------------
  296. // WindowProc()
  297. //
  298. // The main window message handler
  299. LRESULT WINAPI WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  300. {
  301.         switch(uMsg)
  302.         {
  303.         case WM_DESTROY:
  304.                 // Signal application to terminate
  305.                 PostQuitMessage(0);
  306.                 return 0;
  307.  
  308.         case WM_KEYDOWN:
  309.                 // If ESC has been pressed then signal window should close
  310.                 if (LOWORD(wParam) == VK_ESCAPE) SendMessage(hWnd, WM_CLOSE, NULL, NULL);
  311.                 break;
  312.  
  313.         case WM_ERASEBKGND:
  314.                 // We dont want to call render twice so just force Render() in WM_PAINT to be called
  315.                 SendMessage(hWnd, WM_PAINT, NULL, NULL);
  316.                 return TRUE;
  317.  
  318.         case WM_PAINT:
  319.                 // Force a render to keep the window updated
  320.                 //Render();             // not useful anymore
  321.                 return 0;
  322.         }
  323.  
  324.         return DefWindowProc(hWnd, uMsg, wParam, lParam);
  325. }
  326.  
  327. //---------------------------------------------------------------------------
  328. // drawPlayer - draws a sort of 2pix circle
  329. VOID drawPlayer(float x, float y, D3DCOLOR color)
  330. {
  331.         draw4Outline(x, y - 2,
  332.                 x + 2, y,
  333.                 x, y + 2,
  334.                 x - 2, y,
  335.                 color);
  336. }
  337. //---------------------------------------------------------------------------
  338. // D3DStartup()
  339. //
  340. // Initialise all Direct3D objects linked to the hWnd
  341. HRESULT D3DStartup(HWND hWnd)
  342. {
  343.         BOOL                  bCompOk             = FALSE;   // Is composition enabled?
  344.         D3DPRESENT_PARAMETERS pp;                            // Presentation prefs
  345.         DWORD                 msqAAQuality        = 0;       // Non-maskable quality
  346.  
  347.         HRESULT                           hr;
  348.  
  349.         // Make sure that DWM composition is enabled
  350.         DwmIsCompositionEnabled(&bCompOk);
  351.         if(!bCompOk) return E_FAIL;
  352.  
  353.         // Create a Direct3D object
  354.         hr = Direct3DCreate9Ex(D3D_SDK_VERSION, &g_pD3D);
  355.         if (FAILED(hr)) {
  356.                 swprintf_s(status, L"Error Direct3DCreate9Ex:%u", hr);
  357.                 MessageBox(0,status,L"Error",MB_ICONERROR);
  358.                 return E_FAIL;
  359.         }
  360.  
  361.         // Setup presentation parameters
  362.         ZeroMemory(&pp, sizeof(pp));
  363.         pp.Windowed            = TRUE;
  364.         pp.SwapEffect          = D3DSWAPEFFECT_DISCARD; // Required for multi sampling
  365.         pp.BackBufferFormat    = D3DFMT_A8R8G8B8;       // Back buffer format with alpha channel
  366.  
  367.         // Set highest quality non-maskable AA available or none if not
  368.         if (SUCCEEDED(g_pD3D->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT,
  369.                 D3DDEVTYPE_HAL,
  370.                 D3DFMT_A8R8G8B8,
  371.                 TRUE,
  372.                 D3DMULTISAMPLE_NONMASKABLE,
  373.                 &msqAAQuality
  374.                 )))
  375.         {
  376.                 // Set AA quality
  377.                 pp.MultiSampleType     = D3DMULTISAMPLE_NONMASKABLE;
  378.                 pp.MultiSampleQuality  = msqAAQuality - 1;
  379.         }
  380.         else
  381.         {
  382.                 // No AA
  383.                 pp.MultiSampleType     = D3DMULTISAMPLE_NONE;
  384.         }
  385.  
  386.         // Create a Direct3D device object
  387.         hr = g_pD3D->CreateDeviceEx(D3DADAPTER_DEFAULT,
  388.                 D3DDEVTYPE_HAL,
  389.                 hWnd,
  390.                 D3DCREATE_HARDWARE_VERTEXPROCESSING,
  391.                 &pp,
  392.                 NULL,
  393.                 &g_pD3DDevice
  394.                 );
  395.         if (FAILED(hr)) {
  396.                 swprintf_s(status, L"Error CreateDeviceEx:%u", hr);
  397.                 MessageBox(0,status,L"Error",MB_ICONERROR);
  398.                 return E_FAIL;
  399.         }
  400.  
  401.         hr=D3DXCreateFont(g_pD3DDevice,     //D3D Device
  402.                 14,                                                             //Font height
  403.                 0,                                                              //Font width
  404.                 FW_NORMAL,                                              //Font Weight
  405.                 1,                                                              //MipLevels
  406.                 false,                                                  //Italic
  407.                 DEFAULT_CHARSET,                                //CharSet
  408.                 OUT_DEFAULT_PRECIS,                             //OutputPrecision
  409.                 DEFAULT_QUALITY,                                //Quality
  410.                 DEFAULT_PITCH|FF_DONTCARE,              //PitchAndFamily
  411.                 L"Arial",                                               //pFacename,
  412.                 &g_font);                                               //ppFont
  413.  
  414.  
  415.         hr=D3DXCreateFont(g_pD3DDevice,     //D3D Device
  416.                 120,                                                            //Font height
  417.                 0,                                                              //Font width
  418.                 FW_BOLD,                                                //Font Weight
  419.                 2,                                                              //MipLevels
  420.                 false,                                                  //Italic
  421.                 DEFAULT_CHARSET,                                //CharSet
  422.                 OUT_DEFAULT_PRECIS,                             //OutputPrecision
  423.                 DEFAULT_QUALITY,                                //Quality
  424.                 DEFAULT_PITCH|FF_DONTCARE,              //PitchAndFamily
  425.                 L"Arial",                                               //pFacename,
  426.                 &g_killstreak_font);                    //ppFont
  427.  
  428.         //hr=D3DXCreateFont(g_pD3DDevice,     //D3D Device
  429.         //      36,                                                             //Font height
  430.         //      0,                                                              //Font width
  431.         //      FW_BOLD,                                                //Font Weight
  432.         //      1,                                                              //MipLevels
  433.         //      false,                                                  //Italic
  434.         //      DEFAULT_CHARSET,                                //CharSet
  435.         //      OUT_DEFAULT_PRECIS,                             //OutputPrecision
  436.         //      DEFAULT_QUALITY,                                //Quality
  437.         //      DEFAULT_PITCH|FF_DONTCARE,              //PitchAndFamily
  438.         //      L"Arial",                                               //pFacename,
  439.         //      &g_kills_font);                                 //ppFont
  440.         // Line used for player box
  441.         // Currently 3 pixels thick. Color is specified when drawing
  442.         if (FAILED(D3DXCreateLine(g_pD3DDevice, &line))) return E_FAIL;
  443.         line->SetWidth(3);  
  444.         line->SetPattern(0xffffffff);
  445.         line->SetAntialias(FALSE);
  446.  
  447.         // Line used to draw a black background under the status text (upper left corner of window)
  448.         // currently 20 pixels wide
  449.         if (FAILED(D3DXCreateLine(g_pD3DDevice, &back_line))) return E_FAIL;
  450.         back_line->SetWidth(20);  
  451.         back_line->SetPattern(0xffffffff);
  452.         back_line->SetAntialias(FALSE);
  453.  
  454.         // Line used to draw the mini radar
  455.         // currently 1 pixel wide
  456.         if (FAILED(D3DXCreateLine(g_pD3DDevice, &radar_line))) return E_FAIL;
  457.         radar_line->SetWidth(1.5f);  
  458.         radar_line->SetPattern(0xffffffff);
  459.         radar_line->SetAntialias(FALSE);
  460.  
  461.         return S_OK;
  462. }
  463.  
  464. //---------------------------------------------------------------------------
  465. // D3DShutdown()
  466. //
  467. // Release all created Direct3D objects
  468. VOID D3DShutdown(VOID)
  469. {
  470.         if (line != NULL) line->Release();
  471.         if (back_line != NULL) back_line->Release();
  472.         if (radar_line != NULL) radar_line->Release();
  473.         if (g_font != NULL) g_font->Release();
  474.         if (g_killstreak_font != NULL) g_killstreak_font->Release();
  475. //      if (g_kills_font != NULL) g_kills_font->Release();
  476.         if (g_pD3DDevice != NULL) g_pD3DDevice->Release();
  477.         if (g_pD3D != NULL) g_pD3D->Release();
  478. }
  479.  
  480. //---------------------------------------------------------------------------
  481. // Render()
  482. //
  483. // Render the scene to the back buffer
  484. VOID Render(VOID)
  485. {
  486.         gTicks++;
  487.  
  488.         // Sanity check
  489.         if(g_pD3DDevice == NULL) return;
  490.  
  491.         // Clear the back buffer and z buffer to transparent
  492.         g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, ARGB_TRANS, 1.0f, 0);
  493.  
  494.         // Render scene
  495.         if (SUCCEEDED(g_pD3DDevice->BeginScene()))
  496.         {
  497.  
  498.                 if (init_ok)            // if everything is correctly initialised
  499.                 {
  500.                         IsInGame = 0;
  501.                         ReadGame();             // read all structures in memory
  502.                         Toggles();
  503.                         Esp();                  // draw game overlay
  504.                         Radar();
  505.                         CrossHair();
  506.                         Bot();
  507.                         KillCounter();
  508.                         DisplayStatus();
  509.                 }
  510.  
  511.                 g_pD3DDevice->EndScene();
  512.         }
  513.  
  514.         // Update display
  515.         g_pD3DDevice->PresentEx(NULL, NULL, NULL, NULL, NULL);
  516. }
  517.  
  518.  
  519. //---------------------------------------------------------------------------
  520. // WinMain()
  521. //
  522. // Program entry point
  523. //---------------------------------------------------------------------------
  524. int                wndpos[2] = {0, 0};
  525. INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, INT)
  526. {
  527.         HWND       hWnd  = NULL;
  528.         MSG        uMsg;
  529.         HRESULT    hr;
  530.  
  531.         CreateMutex(0,false,MUTEXNAME );
  532.         if(GetLastError())
  533.         {
  534.                 MessageBox(0,L"External BoxESP is already running!",L"Error",MB_ICONERROR);
  535.                 return 0;
  536.         }
  537.  
  538.         WNDCLASSEX wc    = {sizeof(WNDCLASSEX),              // cbSize
  539.                 NULL,                            // style
  540.                 WindowProc,                      // lpfnWndProc
  541.                 NULL,                            // cbClsExtra
  542.                 NULL,                            // cbWndExtra
  543.                 hInstance,                       // hInstance
  544.                 LoadIcon(NULL, IDI_APPLICATION), // hIcon
  545.                 LoadCursor(NULL, IDC_ARROW),     // hCursor
  546.                 NULL,                            // hbrBackground
  547.                 NULL,                            // lpszMenuName
  548.                 g_wcpAppName,                    // lpszClassName
  549.                 LoadIcon(NULL, IDI_APPLICATION)};// hIconSm
  550.  
  551.         RegisterClassEx(&wc);
  552.         hWnd = CreateWindowEx(WS_EX_TOPMOST | WS_EX_COMPOSITED | WS_EX_TRANSPARENT | WS_EX_LAYERED,             // dwExStyle
  553.                 // WS_EX_COMPOSITED: for best performance in transparent mode
  554.                 // WS_EX_TOPMOST: always on top window
  555.                 // WS_EX_TRANSPARENT | WS_EX_LAYERED: click-through window
  556.                 g_wcpAppName,                 // lpClassName
  557.                 g_wcpAppName,                 // lpWindowName
  558.                 WS_POPUP,                               // dwStyle
  559.                 // dropped the WS_SIZEBOX, otherwise we have a "glow" background
  560.                 //WS_POPUP | WS_SIZEBOX,        // dwStyle
  561.                 CW_USEDEFAULT, CW_USEDEFAULT, // x, y
  562.                 g_iWidth, g_iHeight,          // nWidth, nHeight
  563.                 NULL,                         // hWndParent
  564.                 NULL,                         // hMenu
  565.                 hInstance,                    // hInstance
  566.                 NULL);                        // lpParam
  567.  
  568.         // Extend glass to cover whole window
  569.         hr = DwmExtendFrameIntoClientArea(hWnd, &g_mgDWMMargins);
  570.         /*      if (FAILED(hr)) {
  571.         swprintf_s(status, L"Error DwmExtendFrameIntoClientArea:%u", hr);
  572.         MessageBox(0,status,L"Error",MB_ICONERROR);
  573.         return E_FAIL;
  574.         }*/
  575.  
  576.         // Initialise Direct3D
  577.         if (SUCCEEDED(D3DStartup(hWnd)))
  578.         {
  579.                 // Show the window
  580.                 ShowWindow(hWnd, SW_SHOWDEFAULT);
  581.                 UpdateWindow(hWnd);
  582.  
  583.                 // Enter main loop
  584.                 while(TRUE)
  585.                 {
  586.                         // Check for a message
  587.                         if(PeekMessage(&uMsg, NULL, 0, 0, PM_REMOVE))
  588.                         {
  589.                                 // Check if the message is WM_QUIT
  590.                                 if(uMsg.message == WM_QUIT)
  591.                                 {
  592.                                         // Break out of main loop
  593.                                         break;
  594.                                 }
  595.  
  596.                                 // Pump the message
  597.                                 TranslateMessage(&uMsg);
  598.                                 DispatchMessage(&uMsg);
  599.                         }
  600.  
  601.                         // Check if we need initialization
  602.                         if (mw2_hwnd == NULL) {
  603.                                 mw2_hwnd = FindWindow(NULL,L"Modern Warfare 2");
  604.                                 if (mw2_hwnd != NULL)
  605.                                         swprintf_s(status, L"app foundn");
  606.                         }
  607.  
  608.                         if ((mw2_hwnd != NULL) && (mw2_pid == 0)) {
  609.                                 GetWindowThreadProcessId(mw2_hwnd,&mw2_pid);
  610.                         }
  611.                         if ((mw2_process == NULL) && (mw2_pid != 0)) {
  612.                                 mw2_process = OpenProcess(PROCESS_VM_READ,false,mw2_pid);
  613.                         }
  614.                         if (mw2_process != NULL) {
  615.                                 if ((!init_ok) || ((gTicks % 20) == 0)) {
  616.                                         RECT client_rect;
  617.                                         GetClientRect(mw2_hwnd, &client_rect);
  618.                                         resolution[0] = client_rect.right;
  619.                                         resolution[1] = client_rect.bottom;
  620.                                         screencenter[0] = resolution[0]/2;
  621.                                         screencenter[1] = resolution[1]/2;
  622.                                         RECT bounding_rect;
  623.                                         GetWindowRect(mw2_hwnd,&bounding_rect);
  624.                                         mouse_center[0] = (bounding_rect.right - bounding_rect.left) / 2;
  625.                                         mouse_center[1] = (bounding_rect.bottom - bounding_rect.top) / 2;
  626.                                         border_x = ::GetSystemMetrics(SM_CXBORDER);
  627.                                         border_y = ::GetSystemMetrics(SM_CYCAPTION);
  628.                                         swprintf_s(status, L"Resolution: %ux%u, pos; %ix%ix%ix%i, border: %ix%i",resolution[0],resolution[1],
  629.                                                 bounding_rect.left,bounding_rect.top,bounding_rect.right,bounding_rect.bottom,
  630.                                                 border_x, border_y);
  631.  
  632.                                         if (init_ok) {
  633.                                                 if ((wndpos[0] != bounding_rect.left) || (wndpos[1] != bounding_rect.top)) {
  634.                                                         MoveWindow(hWnd, bounding_rect.left,bounding_rect.top, resolution[0],resolution[1],false);
  635.                                                         wndpos[0] = bounding_rect.left;
  636.                                                         wndpos[1] = bounding_rect.top;
  637.                                                 }
  638.                                         } else {
  639.                                                 if ((bounding_rect.left == 0) && (bounding_rect.top == 0)) {
  640.                                                         // we force a 1 pixel move, otherwise the window is not resized (bug?)
  641.                                                         MoveWindow(hWnd, -1, -1, resolution[0],resolution[1],false);
  642.                                                 }
  643.                                                 MoveWindow(hWnd, bounding_rect.left,bounding_rect.top, resolution[0],resolution[1],false);
  644.                                                 wndpos[0] = bounding_rect.left;
  645.                                                 wndpos[1] = bounding_rect.top;
  646.  
  647.                                                 // calc mini-map pos
  648.                                                 rx = resolution[0]/2 - radar_size/2;
  649.                                                 ry = radar_offset + border_y;
  650.                                                 rh = rw = radar_size;
  651.  
  652.                                                 D3DShutdown();                  // we resized then window so we need to recreate all D3D objects
  653.                                                 D3DStartup(hWnd);
  654.                                         }
  655.  
  656.                                         init_ok = true;                         // off we go!
  657.                                 }
  658.                         }
  659.  
  660.                         Render();
  661.  
  662.                         if ((init_ok) && ((gTicks % 10) == 0)) {                // check only every 10 frames
  663.                                 if (FindWindow(NULL,L"Modern Warfare 2") == NULL) {
  664.                                         SendMessage(hWnd, WM_CLOSE, NULL, NULL);        // quit if game is closed
  665.                                 }
  666.                         }
  667.                 }
  668.         }
  669.  
  670.         // Shutdown Direct3D
  671.         D3DShutdown();
  672.  
  673.         // Exit application
  674.         return 0;
  675. }
  676.  
  677. //---------------------------------------------------------------------------
  678. void AngleVectors(const Vector &angles, Vector *forward, Vector *right, Vector *up)
  679. {
  680.         float angle;
  681.         static float sr, sp, sy, cr, cp, cy, cpi = (M_PI*2/360);
  682.  
  683.         angle = angles.y * cpi;
  684.         sy = sin(angle);
  685.         cy = cos(angle);
  686.         angle = angles.x * cpi;
  687.         sp = sin(angle);
  688.         cp = cos(angle);
  689.         angle = angles.z * cpi;
  690.         sr = sin(angle);
  691.         cr = cos(angle);
  692.  
  693.         if(forward)
  694.         {
  695.                 forward->x = cp*cy;
  696.                 forward->y = cp*sy;
  697.                 forward->z = -sp;
  698.         }
  699.  
  700.         if(right)
  701.         {
  702.                 right->x = (-1*sr*sp*cy+-1*cr*-sy);
  703.                 right->y = (-1*sr*sp*sy+-1*cr*cy);
  704.                 right->z = -1*sr*cp;
  705.         }
  706.  
  707.         if(up)
  708.         {
  709.                 up->x = (cr*sp*cy+-sr*-sy);
  710.                 up->y = (cr*sp*sy+-sr*cy);
  711.                 up->z = cr*cp;
  712.         }
  713. }
  714. //---------------------------------------------------------------------------
  715. bool WorldToScreen(const Vector &WorldLocation, float *fScreenX, float *fScreenY)
  716. {
  717.         Vector vLocal, vTransForm, vForward, vRight, vUpward;
  718.  
  719.         AngleVectors(viewangles,&vForward,&vRight,&vUpward);
  720.         vLocal = WorldLocation - mypos;
  721.  
  722.         vTransForm.x = vLocal.dotproduct(vRight);
  723.         vTransForm.y = vLocal.dotproduct(vUpward);
  724.         vTransForm.z = vLocal.dotproduct(vForward);
  725.  
  726.         if (vTransForm.z < 0.01)
  727.                 return false;
  728.  
  729.         *fScreenX = screencenter[0] + (screencenter[0]/vTransForm.z * (1/fov[0])) * vTransForm.x;
  730.         *fScreenY = screencenter[1] - (screencenter[1]/vTransForm.z * (1/fov[1])) * vTransForm.y;
  731.  
  732.         return true;
  733. }
  734. //---------------------------------------------------------------------------
  735. void DrawBox(float x, float y, float w, float h, COLORREF color)
  736. {
  737.         x += border_x;
  738.         y += border_y;
  739.  
  740.         D3DXVECTOR2 points[5];  
  741.         points[0] = D3DXVECTOR2(x,              y);  
  742.         points[1] = D3DXVECTOR2(x+w,    y);  
  743.         points[2] = D3DXVECTOR2(x+w,    y+h);  
  744.         points[3] = D3DXVECTOR2(x,              y+h);  
  745.         points[4] = D3DXVECTOR2(x,              y);  
  746.         line->Draw(points, 5, color);
  747. }//---------------------------------------------------------------------------
  748. void DrawClaymore(float x, float y)
  749. {
  750.         x += border_x;
  751.         y += border_y;
  752.         fillRect(x-8, y, 16, 16, 0x3FFF6666);
  753. }
  754.  
  755. //---------------------------------------------------------------------------
  756. void DrawString(float x, float y, COLORREF color, char* text, ID3DXFont *font)
  757. {
  758.         RECT font_rect;
  759.  
  760.         // char* to LPCWSTR
  761.         // http://www.codeguru.com/forum/showthread.php?t=231165
  762.         int a = lstrlenA(text);
  763.         BSTR unicodestr = SysAllocStringLen(NULL, a);
  764.         ::MultiByteToWideChar(CP_ACP, 0, text, a, unicodestr, a);
  765.         //... when done, free the BSTR
  766.  
  767.         SetRect(&font_rect, (int)x-150, (int)y-10, (int)x+150, (int)y+18);
  768.         int font_height=font->DrawText(NULL,        //pSprite
  769.                 unicodestr,  //pString
  770.                 -1,          //Count
  771.                 &font_rect,  //pRect
  772.                 DT_CENTER | DT_NOCLIP | DT_SINGLELINE,//Format = centered, no clip and force single line
  773.                 color); //Color
  774.  
  775.         ::SysFreeString(unicodestr);
  776. }
  777. //---------------------------------------------------------------------------
  778. bool IsInSpace( float x, float y )
  779. {
  780.         return ( ( x >= rx && y >= ry ) && ( x <= ( rx + rw ) && y <= ( ry + rh ) ) );
  781. }
  782.  
  783. void CalcPoint( Vector vec, float *nx, float *ny, float flRange )
  784. {
  785.         float fy = D3DXToRadian(viewangles.y);          // y is YAW
  786.         float fc = cos( fy );
  787.         float fs = sin( fy );
  788.  
  789.         float dx = vec[ 0 ] - mypos[0];
  790.         float dy = vec[ 1 ] - mypos[1];
  791.  
  792.         float px = dy * ( -fc ) + ( dx * fs );
  793.         float py = dx * ( -fc ) - ( dy * fs );
  794.  
  795.         float irrx = ( rx + ( rw / 2 ) ) + int( px / flRange );
  796.         float irry = ( ry + ( rh / 2 ) ) + int( py / flRange );
  797.  
  798.         // force on border of radar if off range
  799.         if (irrx < rx)                  irrx = rx;
  800.         if (irry < ry)                  irry = ry;
  801.         if (irrx > rx + rw)             irrx = rx + rw;
  802.         if (irry > ry + rh)             irry = ry + rh;
  803.  
  804.         *nx = irrx;
  805.         *ny = irry;
  806. }
  807. //---------------------------------------------------------------------------
  808. void KillCounter()
  809. {
  810.         char    kill_str[128];
  811.  
  812.         if (!IsInGame) {
  813.                 lastdeaths = deaths;
  814.                 lastkills = kills;
  815.                 killcount = 0;
  816.                 return;
  817.         }
  818.  
  819.         if (deaths != lastdeaths) {
  820.                 killcount = 0;
  821.                 lastdeaths = deaths;
  822.         }
  823.  
  824.         if (kills != lastkills) {
  825.                 killcount = killcount + (kills - lastkills);
  826.                 lastkills = kills;
  827.         }
  828.  
  829.         sprintf_s(kill_str, "%i", killcount);
  830.         DrawString((float) (resolution[0]-100),70,0x5FFFFFFF,kill_str, g_killstreak_font);
  831.         //sprintf_s(kill_str, "%i / %i", kills, deaths);
  832.         //DrawString(resolution[0]-100,40,0x7F7FFF7F,kill_str, g_kills_font);
  833. }
  834. //---------------------------------------------------------------------------
  835. void ReadGame()
  836. {
  837.         ReadProcessMemory(mw2_process,(PVOID)ISINGAME,&IsInGame,4,NULL);
  838.  
  839.         if (IsInGame)
  840.         {
  841.                 ReadProcessMemory(mw2_process,(PVOID)(0x00A0178C),&kills,4,NULL);
  842.                 ReadProcessMemory(mw2_process,(PVOID)(0x01B2B920),&deaths,4,NULL);
  843.                 //ReadProcessMemory(mw2_process,(PVOID)(0x00868758),&viewstatus,4,NULL);
  844.                 ReadProcessMemory(mw2_process,(PVOID)(CG_T),&localclientnum,4,NULL);
  845.                 ReadProcessMemory(mw2_process,(PVOID)(REFDEF+0x10),&fov,8,NULL);
  846.                 //ReadProcessMemory(mw2_process,(PVOID)(REFDEF+0x18),&mypos,12,NULL);
  847.                 ReadProcessMemory(mw2_process,(PVOID)(REFDEF+0x9904),&mypos,12,NULL);
  848.  
  849.                 //ReadProcessMemory(mw2_process,(PVOID)(REFDEF+0x3F90),&viewangles,12,NULL);
  850.  
  851.                 ReadProcessMemory(mw2_process,(PVOID)(VIEWANGLEY-0x40),&mw2_view,sizeof(mw2_view), NULL);
  852.                 viewangles = mw2_view.viewAngles;
  853.  
  854.                 ReadProcessMemory(mw2_process,(PVOID)ENTITY,mw2_entities,sizeof(mw2_entities),NULL);
  855.                 ReadProcessMemory(mw2_process,(PVOID)CLIENTINFO,mw2_clientinfo,sizeof(mw2_clientinfo),NULL);
  856.                 for(int i = 0; i < PLAYERMAX; i++)
  857.                 {
  858.                         if (localclientnum == mw2_entities[i].clientnum) {
  859.                                 my_team = mw2_clientinfo[i].team;
  860.                                 break;
  861.                         }
  862.                 }
  863.         }
  864. }
  865. //---------------------------------------------------------------------------
  866. void Toggles()
  867. {
  868.         static bool     Fn_last_state[FN_TOGGLES];
  869.  
  870.         for (int i=0; i<FN_TOGGLES; i++) {
  871.                 bool key = (GetAsyncKeyState(VK_F1 + i) & 0x8000) != 0;
  872.                 if (key && !(Fn_last_state[i])) {
  873.                         Fn[i] = !(Fn[i]);
  874.                 }
  875.                 Fn_last_state[i] = key;
  876.         }
  877. }
  878. //---------------------------------------------------------------------------
  879. void DisplayStatus()
  880. {
  881.         wchar_t final_status[512];      //status message to display
  882.         RECT font_rect;
  883.  
  884.  
  885.         SetRect(&font_rect,5,5,795,15);
  886.         // draw a black background behind text
  887.         D3DXVECTOR2 back_points[2];
  888.         back_points[0] = D3DXVECTOR2(0.0f, 10.0f);  
  889.         back_points[1] = D3DXVECTOR2(800.0f, 10.0f);  
  890.         back_line->Draw(back_points, 2, 0xFF000000);
  891.  
  892.         if (Fn[11]) {   // F12 status
  893.                 for (int i=0; i<FN_TOGGLES; i++) {
  894.                         COLORREF        color = Fn[i] ? 0xFFFFCC00 : 0xFF777777;
  895.                         font_rect.left = i*65 + 5;
  896.                         font_rect.right = i*65 + 70;
  897.                         swprintf_s(final_status, L"F%i %s", i+1, Fn_label[i]);
  898.                         int font_height=g_font->DrawText(NULL,        //pSprite
  899.                                 final_status,           //pString
  900.                                 -1,         //Count
  901.                                 &font_rect, //pRect
  902.                                 DT_LEFT|DT_NOCLIP,//Format,
  903.                                 color); //Color = white opaque
  904.                 }
  905.         } else if (wcslen(status) > 0) {
  906.                 // draw status text if non-empty
  907.  
  908.                 //swprintf_s(final_status, L"%s", status);
  909.                 swprintf_s(final_status, L"F12 %s, mouse_move=%ix%i, view=%.1f|%.1f|%.1f, pos=%.1f|%.1f|%.1f",
  910.                         status, mouse_move_x, mouse_move_y,
  911.                         viewangles.x, viewangles.y, viewangles.z,
  912.                         mypos.x, mypos.y, mypos.z);
  913.                 //swprintf_s(final_status, L"%s, mouve_move=%ix%i " , status, mouse_move_x, mouse_move_y,viewstatus,kills,deaths);
  914.  
  915.  
  916.                 // then draw text
  917.                 int font_height=g_font->DrawText(NULL,        //pSprite
  918.                         final_status,           //pString
  919.                         -1,         //Count
  920.                         &font_rect, //pRect
  921.                         DT_LEFT|DT_NOCLIP,//Format,
  922.                         0xFFFFFFFF); //Color = white opaque
  923.         }
  924. }
  925. //---------------------------------------------------------------------------
  926. void CrossHair()
  927. {
  928.         if (!IsInGame || !Fn[2])                // F3
  929.                 return;
  930.  
  931.         float x = screencenter[0] + border_x + 1.5f;
  932.         float y = screencenter[1] + border_y + 2.5f;
  933.         D3DXVECTOR2 points[2];
  934.  
  935.         points[0] = D3DXVECTOR2(x - 10,         y);
  936.         points[1] = D3DXVECTOR2(x + 10,         y);
  937.         radar_line->Draw(points, 2, 0xCCFF1111);
  938.         points[0] = D3DXVECTOR2(x,              y-10);
  939.         points[1] = D3DXVECTOR2(x,              y+10);
  940.         radar_line->Draw(points, 2, 0xCCFF1111);
  941. }
  942. //---------------------------------------------------------------------------
  943. void Esp()
  944. {
  945.         float drawx, drawy;
  946.         bool enemy;
  947.         float dist, ScreenX, ScreenY;
  948.  
  949.         if (!IsInGame)
  950.                 return;
  951.  
  952.         for(int i = 0; i < ENTITIESMAX; i++)
  953.         {
  954.                 //if ((mw2_entities[i].typ != ET_PLAYER) && (mw2_entities[i].typ != ET_TURRET) && (mw2_entities[i].typ != ET_EXPLOSIVE))
  955.                 //      continue;
  956.                 if ((i < PLAYERMAX) && (mw2_entities[i].typ == ET_PLAYER) && mw2_entities[i].valid && mw2_entities[i].alive && (localclientnum != mw2_entities[i].clientnum))
  957.                 {
  958.                         enemy = false;
  959.                         if (mw2_entities[i].alive & 0x0001)
  960.                         {
  961.                                 if ( ((mw2_clientinfo[i].team == 1) || (mw2_clientinfo[i].team == 2)) && (mw2_clientinfo[i].team == my_team) )          // same team
  962.                                         player[i].color = COLOR_FRIEND;
  963.                                 else{
  964.                                         enemy = true;
  965.                                         if (mw2_clientinfo[i].perk & 0x8000000)
  966.                                                 player[i].color = COLOR_ENEMY_COLDBLOODED;      // player has cold blood perk
  967.                                         else
  968.                                                 player[i].color = COLOR_ENEMY;
  969.                                 }
  970.                         } else
  971.                                 player[i].color = COLOR_DEAD;
  972.  
  973.                         dist = (mypos-mw2_entities[i].pos).length()/48;
  974.                         if (WorldToScreen(mw2_entities[i].pos, &ScreenX, &ScreenY))
  975.                         {
  976.                                 // player[i].pos is at the players foot
  977.                                 float headX, headY;
  978.                                 Vector head = mw2_entities[i].pos;
  979.                                 head.z += 60;   // eyepos of standing player
  980.                                 WorldToScreen(head, &headX, &headY);    // so we project to the screen coordinates
  981.                                 drawy = ScreenY - headY;       
  982.                                 if (drawy < 10)         // minimal size of the box
  983.                                         drawy = 10;
  984.                                 if (mw2_entities[i].pose & FLAGS_CROUCHED)
  985.                                 {
  986.                                         drawy /= 1.5f;
  987.                                         drawx = drawy / 1.5f;           // w/h ratio
  988.                                 }
  989.                                 else if (mw2_entities[i].pose & FLAGS_PRONE)
  990.                                 {
  991.                                         drawy /= 3.f;
  992.                                         drawx = drawy * 2.f;            // w/h ratio
  993.                                 }
  994.                                 else
  995.                                         drawx = drawy / 2.75f;          // standing up
  996.  
  997.                                 if (Fn[1]) {            // F2 box
  998.                                         DrawBox(ScreenX-(drawx/2),ScreenY,drawx,-drawy,player[i].color);       
  999.                                         DrawString(ScreenX+1,ScreenY-drawy+1,0x7F000000,mw2_clientinfo[i].name, g_font);
  1000.                                         DrawString(ScreenX,ScreenY-drawy,0x7FFFFFFF,mw2_clientinfo[i].name, g_font);
  1001.                                 }
  1002.  
  1003.                                 if (Fn[8] && (GetAsyncKeyState(VK_RBUTTON) & 0x8000)) {         // F9 triggerbot
  1004.                                         if(ScreenX < screencenter[0] + (drawx) && ScreenX > screencenter[0] - (drawx)){
  1005.                                                 if(ScreenY < screencenter[1] + (drawy) && ScreenY > screencenter[1] - (drawy)){
  1006.                                                         static long last_fire_tick = 0;
  1007.                                                         if (gTicks - last_fire_tick > 5) {
  1008.                                                                 last_fire_tick = gTicks;
  1009.                                                                 keybd_event((BYTE)VkKeyScan('H'),0x9e,0 , 0);
  1010.                                                                 keybd_event((BYTE)VkKeyScan('H'),0x9e, KEYEVENTF_KEYUP,0);
  1011.                                                         }
  1012.                                                 }
  1013.                                         }
  1014.                                 }
  1015.                         }
  1016.  
  1017.                         if (enemy && (dist < 3) && Fn[7]) {             // F8 autostab
  1018.                                 static long last_melee_tick;
  1019.                                 if (gTicks - last_melee_tick > 10) {
  1020.                                         last_melee_tick = gTicks;
  1021.                                         keybd_event(0x45, 0x12, NULL, NULL);
  1022.                                         keybd_event(0x45, 0x12, KEYEVENTF_KEYUP, NULL);
  1023.                                 }
  1024.                         }
  1025.  
  1026.                 } else if ((mw2_entities[i].typ == ET_TURRET) || (mw2_entities[i].typ == ET_EXPLOSIVE)) {
  1027.                         if (mw2_entities[i].alive & 0x01) {
  1028.                                 COLORREF color = (mw2_entities[i].typ == ET_TURRET) ? COLOR_SENTRY : COLOR_EXPLOSIVE;
  1029.                                 if (WorldToScreen(mw2_entities[i].pos, &ScreenX, &ScreenY))
  1030.                                 {
  1031.                                         if (mw2_entities[i].typ == ET_TURRET)
  1032.                                         {
  1033.                                                 float headX, headY;
  1034.                                                 Vector head = mw2_entities[i].pos;
  1035.                                                 head.z += 20;
  1036.                                                 WorldToScreen(head, &headX, &headY);
  1037.                                                 drawy = ScreenY - headY;
  1038.                                                 if (drawy < 5)          // minimal size of the box
  1039.                                                         drawy = 5;
  1040.                                                 drawx = drawy / 2.75f;
  1041.  
  1042.                                                 DrawBox(ScreenX-(drawx/2),ScreenY,drawx,-drawy,color); 
  1043.                                         } else {
  1044.                                                 if (Fn[3]) {            // F4 explo
  1045.                                                         DrawClaymore(ScreenX, ScreenY);
  1046.                                                 }
  1047.                                         }
  1048.                                 }
  1049.  
  1050.                         }
  1051.                 } else if (mw2_entities[i].typ == ET_SCRIPTMOVER) {
  1052.                         // HQ?
  1053.                         if (DEBUG_HQ) {
  1054.                                 if (WorldToScreen(mw2_entities[i].pos, &ScreenX, &ScreenY)) {
  1055.                                         char str[128];
  1056.                                         sprintf_s(str, "%i/%i/%i", i, mw2_entities[i].alive, mw2_entities[i].unknown0);
  1057.                                         DrawString(ScreenX,ScreenY,0x7FFFFFFF,str, g_font);
  1058.                                 }
  1059.                         }
  1060.                 }
  1061.         }
  1062. }
  1063. //---------------------------------------------------------------------------
  1064. void Radar()
  1065. {
  1066.         if (!IsInGame)
  1067.                 return;
  1068.  
  1069.         if (Fn[0]) {            // F1 radar
  1070.                 // Draw mini-map frame
  1071.                 fillRect(rx, ry, rw, rh, 0x44000000);
  1072.                 draw4Outline(rx, ry,
  1073.                         rx, ry + rh,
  1074.                         rx + rw, ry + rh,
  1075.                         rx + rw, ry,
  1076.                         0x800000FF);
  1077.  
  1078.                 drawPlayer(rx + rw/2, ry + rh/2, 0xFF00FF00);           // myself
  1079.  
  1080.                 for(int i = 0; i < PLAYERMAX; i++)
  1081.                 {
  1082.                         if ((mw2_entities[i].typ == ET_PLAYER) && mw2_entities[i].valid && (mw2_entities[i].alive & 0x0001) && (localclientnum != mw2_entities[i].clientnum))
  1083.                         {
  1084.                                 if ( ((mw2_clientinfo[i].team == 1) || (mw2_clientinfo[i].team == 2)) && (mw2_clientinfo[i].team == my_team) )          // same team
  1085.                                         player[i].color = MAP_COLOR_FRIEND;
  1086.                                 else{
  1087.                                         if (mw2_clientinfo[i].perk & 0x8000000)
  1088.                                                 player[i].color = MAP_COLOR_ENEMY_COLDBLOODED;  // player has cold blood perk
  1089.                                         else
  1090.                                                 player[i].color = MAP_COLOR_ENEMY;
  1091.                                 }
  1092.  
  1093.                                 float cx = 0, cy = 0;
  1094.  
  1095.                                 CalcPoint( mw2_entities[i].pos, &cx, &cy, 50.f );
  1096.                                 drawPlayer(cx, cy, player[i].color);
  1097.                         }
  1098.                 }
  1099.         }
  1100.         if (CALIBRATING)                // calibrating radar
  1101.         {
  1102.                 Vector target(0,0,0);
  1103.                 float cx = 0, cy = 0;
  1104.                 CalcPoint( target, &cx, &cy, 50.f );
  1105.                 drawPlayer(cx, cy, 0x7FFFFFFF);
  1106.         }
  1107. }
  1108. //===========================================================================
  1109. int             player_locked = -1;                     // >=0 if locked on a player, <0 otherwise
  1110. long    player_locked_ticks = 0;        // gTicks time when we locked on player
  1111.  
  1112. int             last_aimed_player = -1;
  1113. Vector  last_aimed_vector = Vector(0,0,0);
  1114.  
  1115. void Bot()
  1116. {
  1117.         float           screen_x, screen_y;
  1118.         float           angle_dist = -1;
  1119.         float           angle_x, angle_y;
  1120.         int                     aimed_player = -1;
  1121.         Vector          aimed_vector = Vector(0,0,0);
  1122.  
  1123.         if (!IsInGame) {
  1124.                 player_locked = -1;
  1125.                 return;
  1126.         }
  1127.  
  1128.         // following is the keys used for different aimbots
  1129.         bool            tube_key = Fn[5] && (GetAsyncKeyState(VK_HOME) & 0x8000);
  1130.         bool            knife_key = Fn[6] && ((GetAsyncKeyState(0X47) & 0x8000) || (GetAsyncKeyState(VK_MBUTTON) & 0x8000)); // 'G' key or middle button
  1131.         bool            aim_key = Fn[4] && ((GetAsyncKeyState(VK_RBUTTON) & 0x8000) || (GetAsyncKeyState(VK_END) & 0x8000));
  1132.  
  1133.         if ((player_locked >= 0) && !(mw2_entities[player_locked].alive & 0x01))
  1134.                 player_locked = -1;             // if player dead, cancel locked tracking
  1135.  
  1136.         if ((player_locked >= 0) && !tube_key && !knife_key && !aim_key)
  1137.                 player_locked = -1;             // tracking key released
  1138.  
  1139.         int start_index = 0, end_index = PLAYERMAX;
  1140.         if (player_locked >= 0) {       // if locked, we iterate only on the locked player
  1141.                 start_index = player_locked;
  1142.                 end_index = start_index + 1;
  1143.         }
  1144.         for (int i=start_index; i<end_index; i++)
  1145.         {
  1146.                 if ((mw2_entities[i].typ == ET_PLAYER) && mw2_entities[i].valid && (mw2_entities[i].alive & 0x0001) && (localclientnum != mw2_entities[i].clientnum))
  1147.                 {
  1148.                         Vector aim_target, foot;
  1149.  
  1150.                         if ( ((mw2_clientinfo[i].team == 1) || (mw2_clientinfo[i].team == 2)) && (mw2_clientinfo[i].team == my_team) )          // same team
  1151.                                 continue;               // same team
  1152.  
  1153.                         foot = mw2_entities[i].pos;
  1154.                         if (MOTION) {
  1155.                                 if (false) {            // motion compensation?
  1156.                                         foot = foot + (foot - last_aimed_vector);       // linear compensation, we are 1 frame ahead
  1157.                                 }
  1158.                         }
  1159.                         aim_target = foot;
  1160.                         if (tube_key) {
  1161.                                 // no correction, aim is foot
  1162.                         } else if (knife_key) {
  1163.                                 aim_target.z += 40;             // middle of bodey
  1164.                         } else {                                        // standard aiming
  1165.  
  1166.                                 if (mw2_entities[i].pose & FLAGS_CROUCHED)
  1167.                                         aim_target.z += 38;
  1168.                                 else if (mw2_entities[i].pose & FLAGS_PRONE)
  1169.                                         aim_target.z += 10;
  1170.                                 else
  1171.                                         aim_target.z += 48;             // eye is at 60, 48 is upper chest for easy kills
  1172.                                 // beware that 100% headshots will tweak your stats and
  1173.                                 // lead you to rooms full of cheaters
  1174.  
  1175.                         }
  1176.                         if (WorldToScreen(aim_target, &screen_x, &screen_y))
  1177.                         {
  1178.                                 float cur_angle_dist = (screen_x-screencenter[0])*(screen_x-screencenter[0]) + (screen_y-screencenter[1])*(screen_y-screencenter[1]);
  1179.                                 // cur_angle_dist is the squared distance in pixels between the target and the center of screen
  1180.                                 if ((cur_angle_dist > 1) && (cur_angle_dist < 200*200)) {
  1181.                                         if ((angle_dist < 0) || (cur_angle_dist < angle_dist)) {
  1182.                                                 // we sort out the closest to the center, independantly of the player distance
  1183.                                                 angle_dist = cur_angle_dist;
  1184.                                                 angle_x = screen_x - screencenter[0];   // required mouse movement for x
  1185.                                                 angle_y = screen_y - screencenter[1];   // required mouse movement for y
  1186.                                                 aimed_player = i;
  1187.                                                 aimed_vector = foot;
  1188.                                         }
  1189.                                 }
  1190.                         }
  1191.                 }
  1192.         } // for
  1193.         if ((player_locked >= 0) && !tube_key && !knife_key && (aimed_player < 0))
  1194.                 player_locked = -1;             // if player locked is off range, and not tube/knife, we release lock
  1195.  
  1196.         if ((angle_dist > 0) && (player_locked < 0)  && (tube_key || knife_key || aim_key)) {   // just starting a player lock sequence
  1197.                 player_locked = aimed_player;           //lock on player
  1198.                 player_locked_ticks = gTicks;           // take the timestamp of the lock
  1199.         }
  1200.  
  1201.         if (angle_dist > 0) {
  1202.                 //if ((player_locked < 0) && (angle_dist > 0)) {
  1203.                 // draw white spot on the targeted player
  1204.                 drawPlayer(screencenter[0] + border_x + angle_x, screencenter[1] + border_y + angle_y, 0x3FFFFFFF);
  1205.         }
  1206.  
  1207.         if (player_locked >= 0)
  1208.         {                                       // now calculating aiming
  1209.                 if (tube_key || knife_key) {
  1210.                         float slope;
  1211.                         float velocity = tube_vel;
  1212.  
  1213.                         Vector aim = mw2_entities[player_locked].pos;
  1214.                         if (knife_key) {
  1215.                                 velocity = knife_vel;
  1216.                                 aim.z += 40;            // middle of body
  1217.                         }
  1218.                         if (FindSlope(&aim, &mypos, velocity, &slope)) {
  1219.                                 aim.z = mypos.z + slope*(aim - mypos).length();
  1220.                                 if (WorldToScreen(aim, &screen_x, &screen_y))
  1221.                                 {
  1222.                                         angle_x = screen_x - screencenter[0] - 1;       // -1 to correct an apparent 1 pixel drift right
  1223.                                         angle_y = screen_y - screencenter[1];          
  1224.                                         MouseMove((angle_x / 3), (angle_y / 3));
  1225.                                 }
  1226.                         } else {
  1227.                                 player_locked = -1;     // if not reachable, drop the lock
  1228.                         }
  1229.                 } else if (aim_key) {
  1230.                         // aimbot is triggered through maintained right click or END key
  1231.  
  1232.                         // aiming is accelerated in time to better target moving players, otherwise you're
  1233.                         // always aiming behind the player
  1234.                         // dividing by 7 gives a rather natural while quick aiming
  1235.  
  1236.                         // see if we need to have quicker aim
  1237.                         float   aim_speed = 7;
  1238.  
  1239.                         if (gTicks - player_locked_ticks > 15)
  1240.                                 aim_speed = 4;          // more aggressive
  1241.                         if (gTicks - player_locked_ticks > 30)
  1242.                                 aim_speed = 2;          // really locked on player
  1243.                         if (gTicks - player_locked_ticks > 40)
  1244.                                 aim_speed = 1;
  1245.  
  1246.                         MouseMove((angle_x / aim_speed), (angle_y / aim_speed));
  1247.                 } else {
  1248.                         player_locked = -1;
  1249.                 }
  1250.         }
  1251.  
  1252.         if (CALIBRATING) { // used for calibrating the grenade speed.
  1253.                 Vector aim(0,0,0);
  1254.  
  1255.                 if (WorldToScreen(aim, &screen_x, &screen_y))
  1256.                         drawPlayer(border_x + screen_x, border_y + screen_y, 0xFFFF3333);
  1257.                 if (knife_key)
  1258.                 {
  1259.                         float slope;
  1260.                         if (FindSlope(&aim, &mypos, knife_vel, &slope)) {
  1261.                                 aim.z = mypos.z + slope*((aim - mypos).length());
  1262.                                 if (WorldToScreen(aim, &screen_x, &screen_y))
  1263.                                 {
  1264.                                         angle_x = screen_x - screencenter[0] -1;
  1265.                                         angle_y = screen_y - screencenter[1];          
  1266.                                         MouseMove((angle_x / 5), (angle_y / 5));
  1267.                                 }
  1268.                         }
  1269.                 }
  1270.         }
  1271.  
  1272.         if (MOTION) {
  1273.                 last_aimed_vector = aimed_vector;
  1274.         }
  1275. }
  1276. //===========================================================================
  1277. void draw4Outline(float x1, float y1, float x2, float y2,
  1278.                                   float x3, float y3, float x4, float y4, D3DCOLOR color)
  1279. {
  1280.         D3DXVECTOR2 points[5];  
  1281.  
  1282.         points[0] = D3DXVECTOR2(x1,             y1);  
  1283.         points[1] = D3DXVECTOR2(x2,             y2);  
  1284.         points[2] = D3DXVECTOR2(x3,             y3);  
  1285.         points[3] = D3DXVECTOR2(x4,             y4);  
  1286.         points[4] = D3DXVECTOR2(x1,             y1);  
  1287.         radar_line->Draw(points, 5, color);
  1288. }
  1289.  
  1290. //===========================================================================
  1291. void fillRect(float x, float y, float w, float h, D3DCOLOR color)
  1292. {
  1293.         D3DRECT r = { (int)x, (int)y, (int)(x + w), (int)(y + h)};
  1294.  
  1295.         g_pD3DDevice->Clear(1, &r, D3DCLEAR_TARGET, color, 0.0f, 0);
  1296. }
  1297. //===========================================================================
  1298. void MouseMove(float delta_x, float delta_y)
  1299. {
  1300.         mouse_move_x = (int) delta_x;
  1301.         mouse_move_y = (int) delta_y;
  1302.         double fScreenWidth   = ::GetSystemMetrics(SM_CXSCREEN)-1;
  1303.         double fScreenHeight  = ::GetSystemMetrics(SM_CYSCREEN)-1;
  1304.         double dx = 65535.0f / fScreenWidth;
  1305.         double dy = 65535.0f / fScreenHeight;
  1306.         double fx = (wndpos[0] + mouse_center[0] + delta_x) * dx;
  1307.         double fy = (wndpos[1] + mouse_center[1] + delta_y) * dy;
  1308.         INPUT  input;
  1309.         memset(&input, 0, sizeof(input));
  1310.         input.type      = INPUT_MOUSE;
  1311.         input.mi.dwFlags  = MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE;
  1312.         input.mi.dx = (long) fx;
  1313.         input.mi.dy = (long) fy;
  1314.         ::SendInput(1,&input,sizeof(input));
  1315. }
  1316. //===========================================================================
  1317. bool FindSlope(Vector *target, Vector *player, float vel, float *ftraj_slope)
  1318. {
  1319.        
  1320.         double  sq_vel = vel*vel;
  1321.         double  z = target->z - player->z;
  1322.         double  range = (*target - *player).length();
  1323.         double  discr = sq_vel*sq_vel - grav*grav*range*range - 2*grav*z*sq_vel;
  1324.  
  1325.         if( discr < 0 ) return false;           // not reachable, maybe too far
  1326.         if (GetKeyState(VK_CAPITAL) & 0x0001)           // CAPSLOCK
  1327.                 *ftraj_slope = (float) ( (sq_vel + sqrt(discr))/(grav*range +.000001f) );               // indirect
  1328.         else
  1329.                 *ftraj_slope = (float) ( (sq_vel - sqrt(discr))/(grav*range +.000001f) );               // direct
  1330.         return (*ftraj_slope < 10) && (*ftraj_slope > -10);             // ~85 degrees up or down max
  1331. }