Загрузка данных


#include <Windows.h>
#include <cmath>
#include <Psapi.h>

#pragma comment(lib, "Psapi.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_VIEW_MATRIX 0x12EAF0

HANDLE hProcess;
DWORD clientBase;
HWND gameWnd;

struct Vec3 { float x, y, z; };

DWORD GetLocal() {
    DWORD addr;
    ReadProcessMemory(hProcess, (LPCVOID)(clientBase + OFFSET_DW_LOCAL_PLAYER), &addr, 4, NULL);
    return addr;
}

int GetHealth(DWORD entity) {
    int hp;
    ReadProcessMemory(hProcess, (LPCVOID)(entity + OFFSET_M_I_HEALTH), &hp, 4, NULL);
    return hp;
}

int GetTeam(DWORD entity) {
    int team;
    ReadProcessMemory(hProcess, (LPCVOID)(entity + OFFSET_M_I_TEAM_NUM), &team, 4, NULL);
    return team;
}

Vec3 GetOrigin(DWORD entity) {
    Vec3 pos;
    ReadProcessMemory(hProcess, (LPCVOID)(entity + OFFSET_M_VEC_ORIGIN), &pos, 12, NULL);
    return pos;
}

bool WorldToScreen(Vec3 world, float* matrix, int w, int h, float& sx, float& sy) {
    float x = matrix[0] * world.x + matrix[1] * world.y + matrix[2] * world.z + matrix[3];
    float y = matrix[4] * world.x + matrix[5] * world.y + matrix[6] * world.z + matrix[7];
    float ww = matrix[12] * world.x + matrix[13] * world.y + matrix[14] * world.z + matrix[15];
    if (ww < 0.01f) return false;
    sx = (w / 2) * (1 + x / ww);
    sy = (h / 2) * (1 - y / ww);
    return true;
}

void GetViewMatrix(float* mat) {
    for (int i = 0; i < 16; i++)
        ReadProcessMemory(hProcess, (LPCVOID)(clientBase + OFFSET_VIEW_MATRIX + i * 4), &mat[i], 4, NULL);
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
    switch (msg) {
    case WM_PAINT: {
        PAINTSTRUCT ps;
        HDC hdc = BeginPaint(hwnd, &ps);
        RECT rc;
        GetClientRect(hwnd, &rc);
        int w = rc.right - rc.left, h = rc.bottom - rc.top;
        
        // Чёрный фон
        HBRUSH black = CreateSolidBrush(RGB(0, 0, 0));
        FillRect(hdc, &rc, black);
        DeleteObject(black);
        
        // Матрица
        float viewMatrix[16];
        GetViewMatrix(viewMatrix);
        
        DWORD local = GetLocal();
        if (local) {
            int localTeam = GetTeam(local);
            for (int i = 1; i <= 32; i++) {
                DWORD entity;
                ReadProcessMemory(hProcess, (LPCVOID)(clientBase + OFFSET_DW_ENTITY_LIST + i * 4), &entity, 4, NULL);
                if (!entity) continue;
                if (GetTeam(entity) == localTeam) continue;
                if (GetHealth(entity) <= 0) continue;
                
                Vec3 pos = GetOrigin(entity);
                pos.z += 60.0f; // голова
                
                float sx, sy;
                if (WorldToScreen(pos, viewMatrix, w, h, sx, sy)) {
                    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, sx - 10, sy - 10, sx + 10, sy + 10);
                    DeleteObject(pen);
                    DeleteObject(brush);
                }
            }
        }
        
        EndPaint(hwnd, &ps);
        break;
    }
    case WM_ERASEBKGND:
        return 1;
    }
    return DefWindowProc(hwnd, msg, wp, lp);
}

int main() {
    gameWnd = FindWindowA(NULL, "Counter-Strike");
    if (!gameWnd) { MessageBoxA(0, "CS 1.6 не найдена", "Ошибка", 0); return 1; }
    
    DWORD pid;
    GetWindowThreadProcessId(gameWnd, &pid);
    hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
    
    HMODULE mods[1024];
    DWORD needed;
    EnumProcessModules(hProcess, mods, sizeof(mods), &needed);
    for (unsigned i = 0; i < needed / sizeof(HMODULE); i++) {
        char name[256];
        GetModuleBaseNameA(hProcess, mods[i], name, sizeof(name));
        if (strcmp(name, "hw.dll") == 0) clientBase = (DWORD)mods[i];
    }
    
    if (!clientBase) { MessageBoxA(0, "hw.dll не найден", "Ошибка", 0); return 1; }
    
    // Создаём окно поверх игры
    WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_HREDRAW | CS_VREDRAW, WndProc, 0, 0, GetModuleHandle(0), 0, 0, (HBRUSH)GetStockObject(BLACK_BRUSH), 0, L"Overlay", 0 };
    RegisterClassEx(&wc);
    
    RECT rc;
    GetWindowRect(gameWnd, &rc);
    HWND ovWnd = CreateWindowEx(WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_LAYERED, L"Overlay", L"ESP", WS_POPUP, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, 0, 0, GetModuleHandle(0), 0);
    SetLayeredWindowAttributes(ovWnd, RGB(0, 0, 0), 0, LWA_COLORKEY);
    ShowWindow(ovWnd, SW_SHOW);
    
    // Цикл сообщений
    MSG msg;
    while (true) {
        while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        InvalidateRect(ovWnd, 0, TRUE);
        Sleep(16);
    }
    
    return 0;
}