Advertisement
Guest User

hDirectX.cpp

a guest
Nov 5th, 2013
768
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.40 KB | None | 0 0
  1. #include "hDirectX.h"
  2. #include "HackProcess.h"
  3.  
  4. IDirect3D9Ex* p_Object = 0;
  5. IDirect3DDevice9Ex* p_Device = 0;
  6. D3DPRESENT_PARAMETERS p_Params;
  7.  
  8. ID3DXLine* p_Line;
  9. ID3DXFont* pFontSmall = 0;
  10.  
  11. CHackProcess fProcess;
  12.  
  13. //ESP VARS
  14. int NumOfPlayers = 32;
  15. const DWORD Player_Base = 0x55DB34;
  16. const DWORD dw_mTeamOffset = 0x98;//client
  17. const DWORD dw_Health = 0x90;//client
  18. const DWORD dw_Pos = 0x25C;//client
  19. const DWORD EntityPlayer_Base = 0x56B3E4;
  20. const DWORD EntityLoopDistance = 0x10;
  21. const DWORD dw_Dormant = 0x17A;
  22. const DWORD dw_Lifestate = 0x8F;
  23. const DWORD dw_vMatrix = 0x5A5730;
  24.  
  25. typedef struct
  26. {
  27.     float flMatrix [4][4];
  28. }WorldToScreenMatrix_t;
  29. float Get3dDistance(float * myCoords, float * enemyCoords)
  30. {
  31.     return sqrt(
  32.         pow(double(enemyCoords[0] - myCoords[0]), 2.0) +
  33.         pow(double(enemyCoords[1] - myCoords[1]), 2.0) +
  34.         pow(double(enemyCoords[2] - myCoords[2]), 2.0));
  35. }
  36. struct MyPlayer_t  
  37. {
  38.     DWORD CLocalPlayer;
  39.     int Team;
  40.     int Health;
  41.     WorldToScreenMatrix_t WorldToScreenMatrix;
  42.     float Position[3];
  43.     void ReadInformation()
  44.     {
  45.         // Reading CLocalPlayer Pointer to our "CLocalPlayer" DWORD.
  46.         ReadProcessMemory (fProcess.__HandleProcess, (PBYTE*)(fProcess.__dwordClient + Player_Base), &CLocalPlayer, sizeof(DWORD), 0);
  47.         // Reading out our Team to our "Team" Varible.
  48.         ReadProcessMemory (fProcess.__HandleProcess, (PBYTE*)(CLocalPlayer + dw_mTeamOffset), &Team, sizeof(int), 0);
  49.         // Reading out our Health to our "Health" Varible.    
  50.         ReadProcessMemory (fProcess.__HandleProcess, (PBYTE*)(CLocalPlayer + dw_Health), &Health, sizeof(int), 0);
  51.         // Reading out our Position to our "Position" Varible.
  52.         ReadProcessMemory (fProcess.__HandleProcess, (PBYTE*)(CLocalPlayer + dw_Pos), &Position, sizeof(float[3]), 0);
  53.  
  54.         ReadProcessMemory (fProcess.__HandleProcess, (PBYTE*)(fProcess.__dwordEngine + dw_vMatrix), &WorldToScreenMatrix, sizeof(WorldToScreenMatrix), 0);
  55.     }
  56. }MyPlayer;
  57.  
  58.  
  59. struct PlayerList_t
  60. {
  61.     DWORD CBaseEntity;
  62.     int Team;
  63.     int Health;
  64.     int Alive;
  65.     int Dormant;
  66.     float Position[3];
  67.     char Name[39];
  68.  
  69.     void ReadInformation(int Player)
  70.     {
  71.         // Reading CBaseEntity Pointer to our "CBaseEntity" DWORD + Current Player in the loop. 0x10 is the CBaseEntity List Size
  72.         //"client.dll"+00545204 //0x571A5204
  73.         ReadProcessMemory (fProcess.__HandleProcess, (PBYTE*)(fProcess.__dwordClient + EntityPlayer_Base  + (Player * EntityLoopDistance)),&CBaseEntity, sizeof(DWORD), 0);
  74.         // Reading out our Team to our "Team" Varible.
  75.         ReadProcessMemory (fProcess.__HandleProcess, (PBYTE*)(CBaseEntity + dw_mTeamOffset), &Team, sizeof(int), 0);
  76.         // Reading out our Health to our "Health" Varible.    
  77.         ReadProcessMemory (fProcess.__HandleProcess, (PBYTE*)(CBaseEntity + dw_Health), &Health, sizeof(int), 0);
  78.         // Reading out our Position to our "Position" Varible.
  79.         ReadProcessMemory (fProcess.__HandleProcess, (PBYTE*)(CBaseEntity + dw_Pos), &Position, sizeof(float[3]), 0);
  80.  
  81.         //Alive
  82.         ReadProcessMemory (fProcess.__HandleProcess, (PBYTE*)(CBaseEntity + dw_Lifestate), &Alive, sizeof(int), 0);
  83.  
  84.         //Dormant
  85.         ReadProcessMemory (fProcess.__HandleProcess, (PBYTE*)(CBaseEntity + dw_Dormant), &Dormant, sizeof(int), 0);
  86.     }
  87. }PlayerList[32];
  88.  
  89.  
  90. bool WorldToScreen(float * from, float * to)
  91. {
  92.     float w = 0.0f;
  93.  
  94.     to[0] = MyPlayer.WorldToScreenMatrix.flMatrix[0][0] * from[0] + MyPlayer.WorldToScreenMatrix.flMatrix[0][1] * from[1] + MyPlayer.WorldToScreenMatrix.flMatrix[0][2] * from[2] + MyPlayer.WorldToScreenMatrix.flMatrix[0][3];
  95.     to[1] = MyPlayer.WorldToScreenMatrix.flMatrix[1][0] * from[0] + MyPlayer.WorldToScreenMatrix.flMatrix[1][1] * from[1] + MyPlayer.WorldToScreenMatrix.flMatrix[1][2] * from[2] + MyPlayer.WorldToScreenMatrix.flMatrix[1][3];
  96.     w = MyPlayer.WorldToScreenMatrix.flMatrix[3][0] * from[0] + MyPlayer.WorldToScreenMatrix.flMatrix[3][1] * from[1] + MyPlayer.WorldToScreenMatrix.flMatrix[3][2] * from[2] + MyPlayer.WorldToScreenMatrix.flMatrix[3][3];
  97.  
  98.     if(w < 0.01f)
  99.         return false;
  100.  
  101.     float invw = 1.0f / w;
  102.     to[0] *= invw;
  103.     to[1] *= invw;
  104.  
  105.     int width = (int)(tSize.right - tSize.left);
  106.     int height = (int)(tSize.bottom - tSize.top);
  107.  
  108.     float x = width/2;
  109.     float y = height/2;
  110.  
  111.     x += 0.5 * to[0] * width + 0.5;
  112.     y -= 0.5 * to[1] * height + 0.5;
  113.  
  114.     to[0] = x+ tSize.left;
  115.     to[1] = y+ tSize.top ;
  116.  
  117.     return true;
  118. }
  119.  
  120. int DirectXInit(HWND hWnd)
  121. {
  122.  
  123.     if(FAILED(Direct3DCreate9Ex(D3D_SDK_VERSION, &p_Object)))
  124.         exit(1);
  125.  
  126.     ZeroMemory(&p_Params, sizeof(p_Params));    
  127.     p_Params.Windowed = TRUE;  
  128.     p_Params.SwapEffect = D3DSWAPEFFECT_DISCARD;    
  129.     p_Params.hDeviceWindow = hWnd;    
  130.     p_Params.MultiSampleQuality   = D3DMULTISAMPLE_NONE;
  131.     p_Params.BackBufferFormat = D3DFMT_A8R8G8B8 ;    
  132.     p_Params.BackBufferWidth = Width;    
  133.     p_Params.BackBufferHeight = Height;    
  134.     p_Params.EnableAutoDepthStencil = TRUE;
  135.     p_Params.AutoDepthStencilFormat = D3DFMT_D16;
  136.  
  137.     if(FAILED(p_Object->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &p_Params, 0, &p_Device)))
  138.         exit(1);
  139.  
  140.     if(!p_Line)
  141.         D3DXCreateLine(p_Device, &p_Line);
  142.  
  143.     D3DXCreateFont(p_Device, 18, 0, 0, 0, false, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Calibri", &pFontSmall);
  144.  
  145.     return 0;
  146. }
  147.  
  148. void DrawESP(int x, int y, float distance)
  149. {
  150.     int width = 15000/distance;
  151.     int height = 50000/distance;
  152.     DrawBox(x-(width/2), y-height-10, width, height, 1, 255, 0, 0, 255);
  153. }
  154.  
  155. int Render()
  156. {
  157.     p_Device->Clear(0, 0, D3DCLEAR_TARGET, 0, 1.0f, 0);
  158.     p_Device->BeginScene();
  159.  
  160.     if(tWnd == GetForegroundWindow())
  161.     {
  162.         fProcess.RunProcess();
  163.         for(int i = 0; i < NumOfPlayers; i ++)
  164.     {
  165.         PlayerList[i].ReadInformation(i);
  166.  
  167.       /*  if(PlayerList[i].Health < 1)
  168.             continue;
  169.  
  170.         //if(PlayerList[i].Dormant = 0)
  171.             //continue;
  172.  
  173.         if(PlayerList[i].Alive < 1)
  174.             continue;
  175.  
  176.         if(PlayerList[i].Team == 2)
  177.             continue;*/
  178.            
  179.         if(PlayerList[i].Health < 2)
  180.             continue;
  181.  
  182.         if(PlayerList[i].Team == MyPlayer.Team)
  183.             continue;
  184.  
  185.         float EnemyXY[3];
  186.  
  187.         if(WorldToScreen(PlayerList[i].Position, EnemyXY) || PlayerList[i].Team != MyPlayer.Team)
  188.         {
  189.             DrawESP(EnemyXY[0] - tSize.left, EnemyXY[1] - tSize.top, Get3dDistance(MyPlayer.Position, PlayerList[i].Position));
  190.         }
  191.     }
  192.  
  193.     }
  194.  
  195.     p_Device->EndScene();
  196.     p_Device->PresentEx(0, 0, 0, 0, 0);
  197.     return 0;
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement