Advertisement
AmbushedRaccoon

CS 1.6 C++ Cheat(notfinished)

Mar 20th, 2021
859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.35 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3.  
  4. #include <Windows.h>
  5. #include <TlHelp32.h>
  6.  
  7. #include <vector>
  8.  
  9. const char* cs_module_name = "hl.exe";
  10. const char* hw_module_name = "hw.dll";
  11. std::uint32_t players_offset = 0x12041DC;
  12. constexpr double Rad2Deg = 180.0 / 3.141592653589793238463;
  13.  
  14. std::uint32_t find_cs_pid()
  15. {
  16.     HANDLE process_snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  17.     if (process_snap == NULL)
  18.     {
  19.         throw std::exception("Process snap failed");
  20.     }
  21.     PROCESSENTRY32 pe{ sizeof pe };
  22.     Process32First(process_snap, &pe);
  23.     do
  24.     {
  25.         bool equal = std::string(pe.szExeFile) == cs_module_name;
  26.         if (equal)
  27.         {
  28.             return pe.th32ProcessID;
  29.         }
  30.     } while (Process32Next(process_snap, &pe));
  31.     return 0;
  32. }
  33.  
  34. std::uint32_t find_module_base(std::uint32_t p_id, std::string module_name)
  35. {
  36.     HANDLE modules_snap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, p_id);
  37.     if (modules_snap == NULL)
  38.     {
  39.         throw std::exception("Can't snap modules");
  40.     }
  41.     MODULEENTRY32 me{ sizeof(me) };
  42.     Module32First(modules_snap, &me);
  43.     do
  44.     {
  45.         if (module_name == me.szModule)
  46.         {
  47.             CloseHandle(modules_snap);
  48.             return reinterpret_cast<std::uint32_t>(me.modBaseAddr);
  49.         }
  50.     } while (Module32Next(modules_snap, &me));
  51.     CloseHandle(modules_snap);
  52.     return 0;
  53. }
  54.  
  55. struct Vector3
  56. {
  57.     float x;
  58.     float z;
  59.     float y;
  60. };
  61.  
  62. struct PlayerServerInfo
  63. {
  64.     Vector3 position;
  65.     bool isTerror;
  66. };
  67.  
  68. struct ReadBuffer
  69. {
  70.     std::uint8_t buffer[10];
  71. };
  72.  
  73. std::vector<PlayerServerInfo> find_players_position(HANDLE csProcess, std::uint32_t name_addr)
  74. {
  75.     char buffer[5];
  76.     std::vector<PlayerServerInfo> players;
  77.     do
  78.     {
  79.         if (ReadProcessMemory(csProcess, reinterpret_cast<void*>(name_addr), &buffer, sizeof buffer, NULL))
  80.         {
  81.             if (buffer[0] == '\\' && buffer[1] == 'n')
  82.             {
  83.                 PlayerServerInfo player;
  84.                 ReadBuffer buffer;
  85.                 if (ReadProcessMemory(csProcess, reinterpret_cast<void*>(name_addr + 388), &buffer, sizeof buffer, NULL))
  86.                 {
  87.                     std::cout << std::endl;
  88.                 }
  89.                 if (ReadProcessMemory(csProcess, reinterpret_cast<void*>(name_addr + 388), &player, sizeof player, NULL))
  90.                 {
  91.                     players.push_back(player);
  92.                     name_addr += 592;
  93.                     continue;
  94.                 }
  95.  
  96.             }
  97.         }
  98.         break;
  99.     } while (true);
  100.     return players;
  101. }
  102.  
  103. Vector3 find_player_position_server(HANDLE csProcess)
  104. {
  105.     const std::uint32_t position_offset = 0x108AAA8;
  106.     std::uint32_t module_base_addr = find_module_base(GetProcessId(csProcess), hw_module_name);
  107.     Vector3 position;
  108.     if (ReadProcessMemory(csProcess, reinterpret_cast<void*>(module_base_addr + position_offset), &position, sizeof position, NULL))
  109.     {
  110.         return position;
  111.     }
  112.     return {};
  113. }
  114.  
  115. int find_nearest_player_index(const std::vector<PlayerServerInfo>& positions, const Vector3& player_position)
  116. {
  117.     float min_distance = (std::numeric_limits<float>::max)();
  118.     int nearest_index = -1;
  119.     for (int i = 0; i < positions.size(); i++)
  120.     {
  121.         auto xSqr = (positions[i].position.x - player_position.x) * (positions[i].position.x - player_position.x);
  122.         auto zSqr = (positions[i].position.z - player_position.z) * (positions[i].position.z - player_position.z);
  123.         if (xSqr + zSqr < min_distance)
  124.         {
  125.             min_distance = xSqr + zSqr;
  126.             nearest_index = i;
  127.         }
  128.     }
  129.     return nearest_index;
  130. }
  131.  
  132. int main()
  133. {
  134.    
  135.  
  136.     std::cout << atan2f(92, 126) * (180.0 / 3.141592653589793238463) << std::endl;
  137.  
  138.     std::uint32_t pid = find_cs_pid();
  139.     HANDLE csProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
  140.     if (csProcess == NULL)
  141.     {
  142.         return 1;
  143.     }
  144.     std::uint32_t module_base_addr = find_module_base(pid, hw_module_name);
  145.     std::uint32_t name_addr = module_base_addr + players_offset;
  146.    
  147.     while (true)
  148.     {
  149.         auto positions = find_players_position(csProcess, name_addr);
  150.         auto position = find_player_position_server(csProcess);
  151.         int nearest_index = find_nearest_player_index(positions, position);
  152.        
  153.         if (nearest_index != -1)
  154.         {
  155.             Vector3 directionVector{};
  156.             directionVector.x = positions[nearest_index].position.x - position.x;
  157.             directionVector.y = positions[nearest_index].position.y - position.y;
  158.             directionVector.z = positions[nearest_index].position.z - position.z;
  159.             float yRotation = atan2f(directionVector.z, directionVector.x) * Rad2Deg;
  160.             float xRotation = -atan2f(directionVector.y, sqrtf(directionVector.z * directionVector.z + directionVector.x * directionVector.x)) * Rad2Deg;
  161.             if (yRotation < 0)
  162.             {
  163.                 yRotation = 360. + yRotation;
  164.             }
  165.             //hw.dll+108AA88
  166.             WriteProcessMemory(csProcess, reinterpret_cast<void*>(module_base_addr + 0x108AA88), &yRotation, sizeof yRotation, NULL);
  167.             WriteProcessMemory(csProcess, reinterpret_cast<void*>(module_base_addr + 0x108AA84), &xRotation, sizeof xRotation, NULL);
  168.  
  169.         }
  170.         Sleep(20);
  171.     }
  172.    
  173.  
  174.     return 0;
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement