Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.13 KB | None | 0 0
  1. #include <windows.h>
  2. #include <TlHelp32.h>
  3. #include <iostream>
  4.  
  5. typedef unsigned char uint8_t;
  6.  
  7. template <typename T, size_t N>
  8.  
  9. size_t countof(T(&array)[N])
  10. {
  11.     return N;
  12. }
  13.  
  14. DWORD dwLocalPlayer;
  15. DWORD dwEntityList;  
  16. DWORD dwGlow;        
  17.  
  18. DWORD dwTeam = 0xF0;
  19. DWORD dwDormant = 0xE9;
  20.  
  21. struct PModule
  22. {
  23.     DWORD dwBase;
  24.     DWORD dwSize;
  25. };
  26.  
  27. class process
  28. {
  29.  
  30. public:
  31.     bool Attach(char* pName, DWORD rights)
  32.     {
  33.         HANDLE handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
  34.         PROCESSENTRY32 entry;
  35.         entry.dwSize = sizeof(entry);
  36.  
  37.         do
  38.             if (!strcmp(entry.szExeFile, pName)) {
  39.                 pID = entry.th32ProcessID;
  40.                 CloseHandle(handle);
  41.                 _process = OpenProcess(rights, false, pID);
  42.                 return true;
  43.             }
  44.         while (Process32Next(handle, &entry));
  45.         return false;
  46.     }
  47.     PModule GetModule(char* moduleName) {
  48.         HANDLE module = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pID);
  49.         MODULEENTRY32 mEntry;
  50.         mEntry.dwSize = sizeof(mEntry);
  51.  
  52.         do {
  53.             if (!strcmp(mEntry.szModule, (LPSTR)moduleName)) {
  54.                 CloseHandle(module);
  55.  
  56.                 PModule mod = { (DWORD)mEntry.hModule, mEntry.modBaseSize };
  57.                 return mod;
  58.             }
  59.         } while (Module32Next(module, &mEntry));
  60.  
  61.         PModule mod = { (DWORD)false, (DWORD)false };
  62.         return mod;
  63.     }
  64.  
  65.     template <class T>
  66.     T Read(DWORD addr) {
  67.         T _read;
  68.         ReadProcessMemory(_process, (LPVOID)addr, &_read, sizeof(T), NULL);
  69.         return _read;
  70.     }
  71.     template <class T>
  72.     void Write(DWORD addr, T val) {
  73.         WriteProcessMemory(_process, (LPVOID)addr, &val, sizeof(T), NULL);
  74.     }
  75.  
  76.     DWORD FindPattern(DWORD start, DWORD size, const char* sig, const char* mask) {
  77.         BYTE* data = new BYTE[size];
  78.  
  79.         unsigned long bytesRead;
  80.         if (!ReadProcessMemory(_process, (LPVOID)start, data, size, &bytesRead)) {
  81.             return NULL;
  82.         }
  83.  
  84.         for (DWORD i = 0; i < size; i++) {
  85.             if (DataCompare((const BYTE*)(data + i), (const BYTE*)sig, mask)) {
  86.                 return start + i;
  87.             }
  88.         }
  89.         return NULL;
  90.     }
  91.  
  92.     DWORD FindPatternArray(DWORD start, DWORD size, const char* mask, int count, ...) {
  93.         char* sig = new char[count + 1];
  94.         va_list ap;
  95.         va_start(ap, count);
  96.         for (int i = 0; i < count; i++) {
  97.             char read = va_arg(ap, char);
  98.             sig[i] = read;
  99.         }
  100.         va_end(ap);
  101.         sig[count] = '\0';
  102.         return FindPattern(start, size, sig, mask);
  103.     }
  104.  
  105.  
  106. private:
  107.     HANDLE _process;
  108.     DWORD pID;
  109.     bool DataCompare(const BYTE* pData, const BYTE* pMask, const char* pszMask) {
  110.         for (; *pszMask; ++pszMask, ++pData, ++pMask) {
  111.             if (*pszMask == 'x' && *pData != *pMask) {
  112.                 return false;
  113.             }
  114.         }
  115.         return (*pszMask == NULL);
  116.     }
  117. };
  118.  
  119. /* Glow Object structure in csgo */
  120. struct glow_t
  121. {
  122.     DWORD dwBase;
  123.     float r;
  124.     float g;
  125.     float b;
  126.     float a;
  127.     uint8_t unk1[16];
  128.     bool m_bRenderWhenOccluded;
  129.     bool m_bRenderWhenUnoccluded;
  130.     bool m_bFullBloom;
  131.     uint8_t unk2[10];
  132. };
  133.  
  134. /* Entity structure in csgo */
  135. struct Entity
  136. {
  137.     DWORD dwBase;
  138.     int team;
  139.     bool is_dormant;
  140. };
  141.  
  142. /* Player structure in csgo */
  143. struct Player
  144. {
  145.     DWORD dwBase;
  146.     bool isDormant;
  147. };
  148.  
  149. process memory;
  150. process _modClient;
  151. process* mem;
  152. PModule modClient;
  153.  
  154. int iFriendlies;
  155. int iEnemies;
  156.  
  157. Entity entEnemies[32];
  158. Entity entFriendlies[32];
  159. Entity me;
  160.  
  161. void update_entity_data(Entity* e, DWORD dwBase)
  162. {
  163.     int dormant = memory.Read<int>(dwBase + dwDormant);
  164.     e->dwBase = dwBase;
  165.     e->team = memory.Read<int>(dwBase + dwTeam);
  166.     e->is_dormant = dormant == 1;
  167. }
  168. /* Get Pointer To Client.dll*/
  169. PModule* GetClientModule() {
  170.     if (modClient.dwBase == 0 && modClient.dwSize == 0) {
  171.         modClient = memory.GetModule("client.dll");
  172.     }
  173.     return &modClient;
  174. }
  175.  
  176. Entity* GetEntityByBase(DWORD dwBase) {
  177.  
  178.     for (int i = 0; i < iFriendlies; i++) {
  179.         if (dwBase == entFriendlies[i].dwBase) {
  180.             return &entFriendlies[i];
  181.         }
  182.     }
  183.     for (int i = 0; i < iEnemies; i++) {
  184.         if (dwBase == entEnemies[i].dwBase) {
  185.             return &entEnemies[i];
  186.         }
  187.     }
  188.     return nullptr;
  189. }
  190.  
  191. /* offset updating class, that uses patterns to find memory addresses */
  192. class offset
  193. {
  194. private:
  195.     static void update_local_player() {
  196.         DWORD lpStart = mem->FindPatternArray(modClient.dwBase, modClient.dwSize, "xxx????xx????xxxxx?", 19, 0x8D, 0x34, 0x85, 0x0, 0x0, 0x0, 0x0, 0x89, 0x15, 0x0, 0x0, 0x0, 0x0, 0x8B, 0x41, 0x8, 0x8B, 0x48, 0x0);
  197.         DWORD lpP1 = mem->Read<DWORD>(lpStart + 3);
  198.         BYTE lpP2 = mem->Read<BYTE>(lpStart + 18);
  199.         dwLocalPlayer = (lpP1 + lpP2) - modClient.dwBase;
  200.     }
  201.  
  202.     static void update_entity_list() {
  203.         DWORD elStart = mem->FindPatternArray(modClient.dwBase, modClient.dwSize, "x????xx?xxx", 11, 0x5, 0x0, 0x0, 0x0, 0x0, 0xC1, 0xE9, 0x0, 0x39, 0x48, 0x4);
  204.         DWORD elP1 = mem->Read<DWORD>(elStart + 1);
  205.         BYTE elP2 = mem->Read<BYTE>(elStart + 7);
  206.         dwEntityList = (elP1 + elP2) - modClient.dwBase;
  207.     }
  208.  
  209.     static void update_glow() {
  210.         DWORD gpStart = mem->FindPatternArray(modClient.dwBase, modClient.dwSize, "xx????x????xxx????xx????xx", 27, 0x8D, 0x8F, 0, 0, 0, 0, 0xA1, 0, 0, 0, 0, 0xC7, 0x4, 0x2, 0, 0, 0, 0, 0x89, 0x35, 0x0, 0x0, 0x0, 0x0, 0x8B, 0x51);
  211.         dwGlow = mem->Read<DWORD>(gpStart + 7) - modClient.dwBase;
  212.     }
  213. public:
  214.     static void get_offset(process* m) {
  215.         mem = m;
  216.         modClient = mem->GetModule("client.dll");
  217.         update_local_player();
  218.         update_entity_list();
  219.         update_glow();
  220.     }
  221.  
  222.     //constantly scanning & updating our offsets
  223.     static DWORD WINAPI scan_offsets(LPVOID PARAM)
  224.     {
  225.         Entity players[64];
  226.         while (true) {
  227.             DWORD playerBase = memory.Read<DWORD>(GetClientModule()->dwBase + dwLocalPlayer);
  228.             int cp = 0;
  229.  
  230.             update_entity_data(&me, playerBase);
  231.             for (int i = 1; i < 64; i++) {
  232.                 DWORD entBase = memory.Read<DWORD>((GetClientModule()->dwBase + dwEntityList) + i * 0x10);
  233.  
  234.                 if (entBase == NULL)
  235.                     continue;
  236.  
  237.                 update_entity_data(&players[cp], entBase);
  238.  
  239.                 cp++;
  240.             }
  241.  
  242.             int cf = 0, ce = 0;
  243.  
  244.             for (int i = 0; i < cp; i++) {
  245.                 if (players[i].team == me.team) {
  246.                     entFriendlies[cf] = players[i];
  247.                     cf++;
  248.                 }
  249.                 else {
  250.                     entEnemies[ce] = players[i];
  251.                     ce++;
  252.                 }
  253.             }
  254.             iEnemies = ce;
  255.             iFriendlies = cf;
  256.         }
  257.     }
  258. };
  259.  
  260.  
  261. class virtualesp
  262. {
  263. private:
  264.     static void glow_player(DWORD mObj, float r, float g, float b)
  265.     {
  266.         memory.Write<float>(mObj + 0x4, r);
  267.         memory.Write<float>(mObj + 0x8, g);
  268.         memory.Write<float>(mObj + 0xC, b);
  269.         memory.Write<float>(mObj + 0x10, 1.0f);
  270.         memory.Write<BOOL>(mObj + 0x24, true);
  271.         memory.Write<BOOL>(mObj + 0x25, false);
  272.     }
  273.  
  274.     static float SanitizeColor(int value)
  275.     {
  276.         if (value > 255) value = 255;
  277.         if (value < 0) value = 0;
  278.         return (float)value / 255;
  279.     }
  280. public:
  281.     static void start_engine() {
  282.         while (!memory.Attach("csgo.exe", PROCESS_ALL_ACCESS)) {
  283.             Sleep(100);
  284.         }
  285.         do {
  286.             Sleep(1000);
  287.             offset::get_offset(&memory);
  288.         } while (dwLocalPlayer < 65535);
  289.         CreateThread(NULL, NULL, &offset::scan_offsets, NULL, NULL, NULL);
  290.     }
  291.  
  292.     static unsigned long __stdcall esp_thread(void*)
  293.     {
  294.         int objectCount;
  295.         DWORD pointerToGlow;
  296.         Entity* Player = NULL;
  297.         float Friend = SanitizeColor(100);
  298.         float Enemy = SanitizeColor(140);
  299.  
  300.         while (true)
  301.         {
  302.             pointerToGlow = memory.Read<DWORD>(GetClientModule()->dwBase + dwGlow);
  303.             objectCount = memory.Read<DWORD>(GetClientModule()->dwBase + dwGlow + 0x4);
  304.             if (pointerToGlow != NULL && objectCount > 0)
  305.             {
  306.                 for (int i = 0; i < objectCount; i++)
  307.                 {
  308.                     DWORD mObj = pointerToGlow + i * sizeof(glow_t);
  309.                     glow_t glowObject = memory.Read<glow_t>(mObj);
  310.                     Player = GetEntityByBase(glowObject.dwBase);
  311.  
  312.                     if (glowObject.dwBase == NULL || Player == nullptr || Player->is_dormant) {
  313.                         continue;
  314.                     }
  315.                     if (me.team == Player->team) {
  316.                         glow_player(mObj, 0, 0, Friend);
  317.                     }
  318.                     else {
  319.                         glow_player(mObj, Enemy, 0, 0);
  320.                     }
  321.                 }
  322.             }
  323.         }
  324.         return EXIT_SUCCESS;
  325.     }
  326. };
  327.  
  328.  
  329. int main()
  330. {
  331.     bool enabled = false;
  332.     HANDLE ESP = NULL;
  333.  
  334.     virtualesp::start_engine();
  335.     std::cout << "F1 to toggle ESP!" << std::endl;
  336.     while (TRUE)
  337.     {
  338.         if (GetAsyncKeyState(VK_F1) & 1) {
  339.             enabled = !enabled;
  340.             if (enabled) {
  341.                 std::cout << "ESP: on" << std::endl;
  342.                 ESP = CreateThread(NULL, NULL, &virtualesp::esp_thread, NULL, NULL, NULL);
  343.             }
  344.             else {
  345.                 std::cout << "ESP: off" << std::endl;
  346.                 TerminateThread(ESP, 0);
  347.                 CloseHandle(ESP);
  348.             }
  349.         }
  350.     }
  351. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement