Загрузка данных
#include <Windows.h>
#include <cmath>
#include <Psapi.h>
#include <dwmapi.h>
#pragma comment(lib, "Psapi.lib")
#pragma comment(lib, "dwmapi.lib")
#define OFFSET_DW_LOCAL_PLAYER 0x1A29B8
#define OFFSET_DW_ENTITY_LIST 0x1A2A78
#define OFFSET_M_I_HEALTH 0xF8
#define OFFSET_M_I_TEAM_NUM 0xF0
#define OFFSET_M_VEC_ORIGIN 0x130
#define OFFSET_M_VEC_VIEW_OFFSET 0x104
#define OFFSET_VIEW_MATRIX 0x12EAF0
HANDLE processHandle;
DWORD clientBase;
HWND gameWindow, overlayWindow;
struct Vector3 { float x, y, z; };
DWORD GetLocalPlayerAddr() {
DWORD addr;
ReadProcessMemory(processHandle, (LPCVOID)(clientBase + OFFSET_DW_LOCAL_PLAYER), &addr, sizeof(DWORD), NULL);
return addr;
}
Vector3 ReadVector3(DWORD address, int offset) {
Vector3 result;
ReadProcessMemory(processHandle, (LPCVOID)(address + offset), &result, sizeof(Vector3), NULL);
return result;
}
int ReadInt(DWORD address, int offset) {
int value;
ReadProcessMemory(processHandle, (LPCVOID)(address + offset), &value, sizeof(int), NULL);
return value;
}
float ReadFloat(DWORD address, int offset) {
float value;
ReadProcessMemory(processHandle, (LPCVOID)(address + offset), &value, sizeof(float), NULL);
return value;
}
bool WorldToScreen(Vector3 worldPos, Vector3& screenPos, float viewMatrix[16], int screenW, int screenH) {
float w = viewMatrix[12] * worldPos.x + viewMatrix[13] * worldPos.y + viewMatrix[14] * worldPos.z + viewMatrix[15];
if (w < 0.01f) return false;
float x = viewMatrix[0] * worldPos.x + viewMatrix[1] * worldPos.y + viewMatrix[2] * worldPos.z + viewMatrix[3];
float y = viewMatrix[4] * worldPos.x + viewMatrix[5] * worldPos.y + viewMatrix[6] * worldPos.z + viewMatrix[7];
screenPos.x = (screenW / 2) * (1 + x / w);
screenPos.y = (screenH / 2) * (1 - y / w);
return true;
}
void ReadViewMatrix(float viewMatrix[16]) {
for (int i = 0; i < 16; i++) {
viewMatrix[i] = ReadFloat(clientBase, OFFSET_VIEW_MATRIX + i * 4);
}
}
LRESULT CALLBACK OverlayWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
RECT rect;
GetClientRect(hwnd, &rect);
int screenW = rect.right - rect.left;
int screenH = rect.bottom - rect.top;
HBRUSH bgBrush = CreateSolidBrush(RGB(0, 0, 0));
FillRect(hdc, &rect, bgBrush);
DeleteObject(bgBrush);
float viewMatrix[16];
ReadViewMatrix(viewMatrix);
DWORD localPlayer = GetLocalPlayerAddr();
if (localPlayer) {
int localTeam = ReadInt(localPlayer, OFFSET_M_I_TEAM_NUM);
for (int i = 1; i <= 32; i++) {
DWORD entity;
ReadProcessMemory(processHandle, (LPCVOID)(clientBase + OFFSET_DW_ENTITY_LIST + i * 4), &entity, sizeof(DWORD), NULL);
if (!entity) continue;
int entityTeam = ReadInt(entity, OFFSET_M_I_TEAM_NUM);
if (entityTeam == localTeam) continue;
int health = ReadInt(entity, OFFSET_M_I_HEALTH);
if (health <= 0) continue;
Vector3 entityPos = ReadVector3(entity, OFFSET_M_VEC_ORIGIN);
entityPos.z += 60.0f;
Vector3 screenPos;
if (WorldToScreen(entityPos, screenPos, viewMatrix, screenW, screenH)) {
HPEN pen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
SelectObject(hdc, pen);
HBRUSH brush = CreateSolidBrush(RGB(255, 0, 0));
SelectObject(hdc, brush);
Rectangle(hdc, screenPos.x - 10, screenPos.y - 10, screenPos.x + 10, screenPos.y + 10);
DeleteObject(pen);
DeleteObject(brush);
}
}
}
EndPaint(hwnd, &ps);
break;
}
case WM_ERASEBKGND:
return 1;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
void CreateOverlay() {
WNDCLASSEX wc = {};
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = OverlayWndProc;
wc.hInstance = GetModuleHandle(NULL);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
wc.lpszClassName = L"OverlayClass";
RegisterClassEx(&wc);
RECT gameRect;
GetWindowRect(gameWindow, &gameRect);
overlayWindow = CreateWindowEx(
WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_LAYERED,
L"OverlayClass", L"ESP Overlay",
WS_POPUP,
gameRect.left, gameRect.top, gameRect.right - gameRect.left, gameRect.bottom - gameRect.top,
NULL, NULL, GetModuleHandle(NULL), NULL);
SetLayeredWindowAttributes(overlayWindow, RGB(0, 0, 0), 0, LWA_COLORKEY);
ShowWindow(overlayWindow, SW_SHOW);
}
int main() {
gameWindow = FindWindowA(NULL, "Counter-Strike");
if (!gameWindow) { MessageBoxA(NULL, "CS 1.6 не найдена", "Ошибка", MB_OK); return 1; }
DWORD pid;
GetWindowThreadProcessId(gameWindow, &pid);
processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
HMODULE modules[1024];
DWORD needed;
EnumProcessModules(processHandle, modules, sizeof(modules), &needed);
clientBase = 0;
for (unsigned int i = 0; i < needed / sizeof(HMODULE); i++) {
char name[256];
GetModuleBaseNameA(processHandle, modules[i], name, sizeof(name));
if (strcmp(name, "hw.dll") == 0) clientBase = (DWORD)modules[i];
}
if (!clientBase) { MessageBoxA(NULL, "hw.dll не найден", "Ошибка", MB_OK); return 1; }
CreateOverlay();
MSG msg;
while (true) {
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
InvalidateRect(overlayWindow, NULL, TRUE);
UpdateWindow(overlayWindow);
Sleep(16);
}
return 0;
}