#include <Windows.h>
#include <stdio.h>
#include <TlHelp32.h>
#include <iostream>
#include <thread>
uint32_t get_process_id_by_name(const char *process_name)
{
HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL);
PROCESSENTRY32 pEntry;
pEntry.dwSize = sizeof (pEntry);
BOOL hRes = Process32First(hSnapShot, &pEntry);
while (hRes)
{
if (strcmp(pEntry.szExeFile, process_name) == 0)
{
return static_cast<uint32_t>(pEntry.th32ProcessID);
}
hRes = Process32Next(hSnapShot, &pEntry);
}
CloseHandle(hSnapShot);
return 0;
}
uintptr_t get_module_base(uint32_t process_id, const char* module_name)
{
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, process_id);
if (hSnapshot != INVALID_HANDLE_VALUE)
{
MODULEENTRY32 ModuleEntry32 = { 0 };
ModuleEntry32.dwSize = sizeof(MODULEENTRY32);
if (Module32First(hSnapshot, &ModuleEntry32))
{
do
{
if (strcmp(ModuleEntry32.szModule, module_name) == 0)
{
return reinterpret_cast<uintptr_t>(ModuleEntry32.modBaseAddr);
}
} while (Module32Next(hSnapshot, &ModuleEntry32));
}
CloseHandle(hSnapshot);
}
CloseHandle(hSnapshot);
return 0;
}
template<typename T>
T memory_read(HANDLE cs2_handle, uintptr_t address)
{
T val = T();
ReadProcessMemory(cs2_handle, (LPCVOID)address, &val, sizeof(T), NULL);
return val;
}
template<typename T>
void memory_write(HANDLE cs2_handle, uintptr_t address, T value)
{
WriteProcessMemory(cs2_handle, (LPVOID)address, &value, sizeof(T), NULL);
}
namespace offsets
{
ptrdiff_t p_entity_list = 0x17995C0;
ptrdiff_t m_h_player_pawn = 0x7BC;
ptrdiff_t m_fl_detected_by_enemy_sensor_time = 0x13C4;
}
int main(int argc, char* argv[])
{
SetConsoleTitleA("example");
uint32_t cs2_process_id = get_process_id_by_name("cs2.exe");
printf("cs2.exe has pid: %i\n", cs2_process_id);
if (!cs2_process_id)
printf("cs2.exe not found!\n");
HANDLE cs2_process_handle = OpenProcess(PROCESS_ALL_ACCESS, 0, cs2_process_id);
printf("cs2.exe process handle: 0x%lx\n", cs2_process_handle);
if (!cs2_process_handle)
printf("cs2.exe process handle is null!\n");
uintptr_t cs2_module_client = get_module_base(cs2_process_id, "client.dll");
printf("client.dll base address: 0x%llx\n", cs2_module_client);
if (!cs2_module_client)
printf("client.dll not found in cs2.exe!\n");
while (true)
{
static bool glow_enabled = false;
if (GetAsyncKeyState(VK_F1))
{
glow_enabled = !glow_enabled;
std::this_thread::sleep_for(std::chrono::milliseconds(150));
printf("status enabled: %s\n", glow_enabled ? "true" : "false");
}
for (int i = 1; i < 64; i++)
{
uintptr_t entity_list = memory_read<uintptr_t>(cs2_process_handle, cs2_module_client + offsets::p_entity_list);
if (!entity_list)
continue;
uintptr_t list_entry = memory_read<uintptr_t>(cs2_process_handle, entity_list + (8 * (i & 0x7FFF) >> 9) + 16);
if (!list_entry)
continue;
uintptr_t player = memory_read<uintptr_t>(cs2_process_handle, list_entry + 120 * (i & 0x1FF));
if (!player)
continue;
uint32_t player_pawn = memory_read<uint32_t>(cs2_process_handle, player + offsets::m_h_player_pawn);
uintptr_t list_entry2 = memory_read<uintptr_t>(cs2_process_handle, entity_list + 0x8 * ((player_pawn & 0x7FFF) >> 9) + 16);
if (!list_entry2)
continue;
uintptr_t p_cs_player_pawn = memory_read<uintptr_t>(cs2_process_handle, list_entry2 + 120 * (player_pawn & 0x1FF));
if (!p_cs_player_pawn)
continue;
if(!glow_enabled)
memory_write<float>(cs2_process_handle, p_cs_player_pawn + offsets::m_fl_detected_by_enemy_sensor_time, 0.f); // off
else
memory_write<float>(cs2_process_handle, p_cs_player_pawn + offsets::m_fl_detected_by_enemy_sensor_time, 86400.f); // on
}
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
system("pause");
return 0;
}