-
Автор темы
- #1
Код:
Помогите пж, только начал изучать эту тему
C++:
#include <iostream>
#include <windows.h>
#include <TlHelp32.h>
#include <io.h>
#include <fcntl.h>
namespace offsets {
constexpr std::ptrdiff_t dwEntityList = 0x19D1A98;
constexpr std::ptrdiff_t dwGlowManager = 0x1A2EEA0;
constexpr std::ptrdiff_t dwLocalPlayerPawn = 0x1836BB8;
constexpr std::ptrdiff_t m_iTeamNum = 0x971;
constexpr std::ptrdiff_t m_bDormant = 0x231;
}
DWORD GetProcessIdByName(const wchar_t* processName) {
PROCESSENTRY32 processEntry = { sizeof(PROCESSENTRY32) };
HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (Process32First(hProcessSnap, &processEntry)) {
do {
if (!_wcsicmp(processEntry.szExeFile, processName)) {
CloseHandle(hProcessSnap);
return processEntry.th32ProcessID;
}
} while (Process32Next(hProcessSnap, &processEntry));
}
CloseHandle(hProcessSnap);
return 0;
}
HANDLE GetHandleToProcess(DWORD processId) {
return OpenProcess(PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION, FALSE, processId);
}
uintptr_t GetModuleBaseAddress(DWORD processId, const wchar_t* modName) {
uintptr_t modBaseAddr = 0;
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, processId);
if (hSnap != INVALID_HANDLE_VALUE) {
MODULEENTRY32 modEntry;
modEntry.dwSize = sizeof(modEntry);
if (Module32First(hSnap, &modEntry)) {
do {
if (!_wcsicmp(modEntry.szModule, modName)) {
modBaseAddr = (uintptr_t)modEntry.modBaseAddr;
break;
}
} while (Module32Next(hSnap, &modEntry));
}
}
CloseHandle(hSnap);
return modBaseAddr;
}
int main() {
SetConsoleOutputCP(CP_UTF8);
_setmode(_fileno(stdout), _O_U8TEXT);
const wchar_t* processName = L"cs2.exe";
DWORD processId = GetProcessIdByName(processName);
if (processId == 0) {
std::wcerr << L"Процесс игры не найден!" << std::endl;
return 1;
}
HANDLE hProcess = GetHandleToProcess(processId);
if (!hProcess) {
std::wcerr << L"Не удалось открыть процесс!" << std::endl;
return 1;
}
uintptr_t clientModuleBase = GetModuleBaseAddress(processId, L"client.dll");
if (clientModuleBase == 0) {
std::wcerr << L"Не удалось найти базовый адрес client.dll!" << std::endl;
return 1;
}
std::wcout << L"Процесс игры найден и открыт. PID: " << processId << std::endl;
std::wcout << L"Базовый адрес client.dll: 0x" << std::hex << clientModuleBase << std::endl;
while (true) {
uintptr_t glowManagerAddr = 0;
uintptr_t localPlayerPawnAddr = 0;
if (!ReadProcessMemory(hProcess, (BYTE*)(clientModuleBase + offsets::dwGlowManager), &glowManagerAddr, sizeof(glowManagerAddr), nullptr)) {
std::wcerr << L"Не удалось прочитать адрес GlowManager!" << std::endl;
continue;
}
if (!ReadProcessMemory(hProcess, (BYTE*)(clientModuleBase + offsets::dwLocalPlayerPawn), &localPlayerPawnAddr, sizeof(localPlayerPawnAddr), nullptr)) {
std::wcerr << L"Не удалось прочитать адрес LocalPlayerPawn!" << std::endl;
continue;
}
int localPlayerTeam = 0;
ReadProcessMemory(hProcess, (BYTE*)(localPlayerPawnAddr + offsets::m_iTeamNum), &localPlayerTeam, sizeof(localPlayerTeam), nullptr);
std::wcout << L"Local Player Team: " << localPlayerTeam << std::endl;
for (int i = 0; i < 64; ++i) {
uintptr_t entityAddr = 0;
if (!ReadProcessMemory(hProcess, (BYTE*)(clientModuleBase + offsets::dwEntityList + i * 0x10), &entityAddr, sizeof(entityAddr), nullptr)) {
continue;
}
bool isDormant = false;
ReadProcessMemory(hProcess, (BYTE*)(entityAddr + offsets::m_bDormant), &isDormant, sizeof(isDormant), nullptr);
if (isDormant) {
continue;
}
int entityTeam = 0;
ReadProcessMemory(hProcess, (BYTE*)(entityAddr + offsets::m_iTeamNum), &entityTeam, sizeof(entityTeam), nullptr);
std::wcout << L"Entity " << i << L" Team: " << entityTeam << std::endl;
if (entityTeam != localPlayerTeam) {
float glowColor[4] = { 1.0f, 0.0f, 0.0f, 1.0f };
if (!WriteProcessMemory(hProcess, (BYTE*)(glowManagerAddr + (i * 0x38) + 0x8), &glowColor, sizeof(glowColor), nullptr)) {
std::wcerr << L"Ошибка записи GlowColor для сущности " << i << std::endl;
}
bool glowEnable = true;
if (!WriteProcessMemory(hProcess, (BYTE*)(glowManagerAddr + (i * 0x38) + 0x27), &glowEnable, sizeof(glowEnable), nullptr)) {
std::wcerr << L"Ошибка записи GlowEnable для сущности " << i << std::endl;
}
}
}
Sleep(1000);
}
CloseHandle(hProcess);
return 0;
}