#include <Windows.h> #include <sstream> #include <math.h> #include <iostream> #include <TlHelp32.h> #include <tchar.h>
#include <string> #include "csgo.h"
using namespace std;
DWORD dwLocalPlayer = 0xD8B2BC; DWORD dwEntityList = 0x4DA2F44; DWORD dwViewMatrix = 0x4D94844; DWORD m_dwBoneMatrix = 0x26A8;
DWORD zPosOffset = 0x140; DWORD yPosOffset = 0x13C; DWORD xPosOffset = 0x138; DWORD hPosOffset = 0x110; DWORD hpOffset = 0x100; DWORD m_iTeamNum = 0xF4; DWORD m_bDormant = 0xED; DWORD m_vecOrigin = 0x138;
HWND hwndCSGO;
DWORD gameModule;
HDC HDC_Desktop;
HBRUSH EnemyBrush;
HFONT Font;
RECT m_Rect;
HWND TargetWnd;
HWND Handle;
RECT windowRect;
HANDLE handle; DWORD pid;
COLORREF SnapLineCOLOR;
COLORREF TextCOLOR;
float Matrix[16];
struct Vec3 { float x, y, z; };
struct Vec4 { float x, y, z, w; };
struct Vec2 { float x, y; };
void SetupDrawing(HDC hDesktop, HWND handle) { HDC_Desktop = hDesktop; Handle = handle; EnemyBrush = CreateSolidBrush(RGB(255, 0, 0)); SnapLineCOLOR = RGB(0, 0, 255); TextCOLOR = RGB(0, 255, 0); }
void DrawFilledRect(int x, int y, int w, int h) { RECT rect = { x, y, x + w, y + h }; FillRect(HDC_Desktop, &rect, EnemyBrush); }
void DrawBorderBox(int x, int y, int w, int h, int thickness) {
DrawFilledRect(x, y, w, thickness);
DrawFilledRect(x, y, thickness, h);
DrawFilledRect((x + w), y, thickness, h);
DrawFilledRect(x, y + h, w + thickness, thickness); }
void DrawLine(float StartX, float StartY, float EndX, float EndY, COLORREF Pen) { HPEN hNPen = CreatePen(PS_SOLID, 2, Pen); HPEN hOPen = (HPEN)SelectObject(HDC_Desktop, hNPen); MoveToEx(HDC_Desktop, StartX, StartY, NULL); LineTo(HDC_Desktop, EndX, EndY); DeleteObject(SelectObject(HDC_Desktop, hOPen)); }
void DrawString(int x, int y, COLORREF color, const char* text) { SetTextAlign(HDC_Desktop, TA_CENTER | TA_NOUPDATECP); SetBkColor(HDC_Desktop, RGB(0, 0, 0)); SetBkMode(HDC_Desktop, TRANSPARENT); SetTextColor(HDC_Desktop, color);
SelectObject(HDC_Desktop, Font); TextOutA(HDC_Desktop, x, y, text, strlen(text)); DeleteObject(Font);
}
bool WorldToScreen(Vec3 pos, Vec2& screen, float matrix[16], int windowWidth, int windowHeight) { Vec4 clipCoords; clipCoords.x = pos.x * matrix[0] + pos.y * matrix[1] + pos.z * matrix[2] + matrix[3]; clipCoords.y = pos.x * matrix[4] + pos.y * matrix[5] + pos.z * matrix[6] + matrix[7]; clipCoords.z = pos.x * matrix[8] + pos.y * matrix[9] + pos.z * matrix[10] + matrix[11]; clipCoords.w = pos.x * matrix[12] + pos.y * matrix[13] + pos.z * matrix[14] + matrix[15];
if (clipCoords.w < 0.1f) return false;
Vec3 NDC; NDC.x = clipCoords.x / clipCoords.w; NDC.y = clipCoords.y / clipCoords.w; NDC.z = clipCoords.z / clipCoords.w;
screen.x = (windowWidth / 2 * NDC.x) + (NDC.x + windowWidth / 2); screen.y = -(windowHeight / 2 * NDC.y) + (NDC.y + windowHeight / 2); return true; }
DWORD GetProcId(const char* procName) { DWORD procId = 0; HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hSnap != INVALID_HANDLE_VALUE) { PROCESSENTRY32 procEntry; procEntry.dwSize = sizeof(procEntry);
if (Process32First(hSnap, &procEntry)) { do { if (strcmp(procName, procEntry.szExeFile) == 0) { procId = procEntry.th32ProcessID; break; } } while (Process32Next(hSnap, &procEntry));
} } CloseHandle(hSnap); return procId; }
uintptr_t GetModBase(DWORD ProcID, const char* ModuleName) { uintptr_t modbaseAddr = 0; HANDLE hsnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, ProcID); if (hsnap != INVALID_HANDLE_VALUE) { MODULEENTRY32 modEntry; modEntry.dwSize = sizeof(modEntry); if (Module32First(hsnap, &modEntry)) { do { if (strcmp(ModuleName, modEntry.szModule) == 0) { modbaseAddr = (uintptr_t)modEntry.modBaseAddr; break; } } while (Module32Next(hsnap, &modEntry)); } } CloseHandle(hsnap); return modbaseAddr; }
void MemStart() { TargetWnd = FindWindow(0, "Counter-Strike: Global Offensive"); HDC HDC_Desktop = GetDC(TargetWnd); SetupDrawing(HDC_Desktop, TargetWnd); GetWindowThreadProcessId(TargetWnd, &pid); handle = OpenProcess(PROCESS_ALL_ACCESS, 0, pid); GetClientRect(TargetWnd, &windowRect);
windowRect.bottom *= 1.25; windowRect.right *= 1.25;
}
int main() { MemStart(); DWORD processID = GetProcId("csgo.exe"); HANDLE processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processID); uintptr_t dllBaseAddress = 0; dllBaseAddress = GetModBase(processID, "client.dll"); if (processHandle != 0) { cout << "ProcessID: " << "0x" << hex << processID << endl;; cout << "Process access granted\n"; cout << "dllBaseAddress: " << "0x" << hex << dllBaseAddress <<endl; } else { cout << "Process access not granted " << endl; Sleep(5000); exit(1); } gameModule = dllBaseAddress; cout << "\n" << endl; cout << gameModule + dwLocalPlayer + zPosOffset << endl; cout << windowRect.left << endl;
DWORD ClocalPlayer; int m_fFlags = 0;
float x, y, z, hp;
char buf[100]; while (1) { ReadProcessMemory(processHandle, (PBYTE*)(dllBaseAddress + dwLocalPlayer), &ClocalPlayer, sizeof(DWORD), NULL); Vec2 vScreen = { 0,0 }; Vec2 vScreen_head = { 0,0 }; Vec2 vHead = { 0,0 };
Vec3 vecMine; ReadProcessMemory(processHandle, (BYTE*)(ClocalPlayer + xPosOffset), &vecMine.x, sizeof(float), NULL); ReadProcessMemory(processHandle, (BYTE*)(ClocalPlayer + yPosOffset), &vecMine.y, sizeof(float), NULL); ReadProcessMemory(processHandle, (BYTE*)(ClocalPlayer + zPosOffset), &vecMine.z, sizeof(float), NULL);
ReadProcessMemory(processHandle, (PBYTE*)(dllBaseAddress + dwViewMatrix), Matrix, sizeof(Matrix), NULL);
DrawString(100, 100, TextCOLOR, ("x: " + to_string(int(vecMine.x))).data()); DrawString(100, 120, TextCOLOR, ("y: " + to_string(int(vecMine.y))).data()); DrawString(100, 140, TextCOLOR, ("z: " + to_string(int(vecMine.z))).data()); DrawString(100, 200, TextCOLOR, ("r: " + to_string(windowRect.right)).data()); DrawString(100, 240, TextCOLOR, ("b: " + to_string(windowRect.bottom)).data());
int myTeam = 0; ReadProcessMemory(processHandle, (BYTE*)(ClocalPlayer + m_iTeamNum), &myTeam, sizeof(int), NULL);
DrawString(200, 200 + 16 * 20, TextCOLOR, ("阵营: " + to_string(int(myTeam))).data());
for (short int i = 0; i < 64; i++) { DWORD entity = NULL; ReadProcessMemory(processHandle, (DWORD*)(gameModule + dwEntityList + i * 0x10), &entity, sizeof(DWORD), NULL);
if (entity != NULL) { if (entity != ClocalPlayer) { int entityTeam = 0; ReadProcessMemory(processHandle, (int*)(entity + m_iTeamNum), &entityTeam, sizeof(int), NULL); Vec3 entityLocation = { 0,0,0, }; ReadProcessMemory(processHandle, (Vec3*)(entity + m_vecOrigin), &entityLocation, sizeof(Vec3), NULL); DWORD dwBoneMatrix = 0; ReadProcessMemory(processHandle, (DWORD*)(entity + m_dwBoneMatrix), &dwBoneMatrix, sizeof(DWORD), NULL);
DWORD health = 0; ReadProcessMemory(processHandle, (DWORD*)(entity + hpOffset), &health, sizeof(DWORD), NULL); int isDormat = 1; ReadProcessMemory(processHandle, (int*)(entity + m_bDormant), &isDormat, sizeof(int), NULL); float head = 0; ReadProcessMemory(processHandle, (float*)(entity + hPosOffset), &head, sizeof(float), NULL); Vec3 head_dwBoneMatrix = { entityLocation.x, entityLocation.y, entityLocation.z+head }; if (isDormat == 0) { if (health > 0) { if (WorldToScreen(entityLocation, vScreen, Matrix, windowRect.right, windowRect.bottom)) { float enemyHeadX = 0; ReadProcessMemory(processHandle, (float*)(dwBoneMatrix + 0x30 * 9 + 0x0C), &isDormat, sizeof(float), NULL); float enemyHeadY = 0; ReadProcessMemory(processHandle, (float*)(dwBoneMatrix + 0x30 * 9 + 0x1C), &isDormat, sizeof(float), NULL); float enemyHeadZ = 0; ReadProcessMemory(processHandle, (float*)(dwBoneMatrix + 0x30 * 9 + 0x2C), &isDormat, sizeof(float), NULL); Vec3 enemyHeadPos = { enemyHeadX, enemyHeadY, enemyHeadZ };
if (WorldToScreen(head_dwBoneMatrix, vHead, Matrix, windowRect.right, windowRect.bottom)) { float head = vHead.y - vScreen.y; float width = head / 1.8; float center = width / 2; if (myTeam == entityTeam) { EnemyBrush = CreateSolidBrush(RGB(000, 000, 255)); DrawBorderBox(vScreen.x - center, vScreen.y, width, head, 2); DrawBorderBox(vScreen.x - center, vScreen.y + head, width, head * 0.125, 2); DeleteObject(EnemyBrush); } else { EnemyBrush = CreateSolidBrush(RGB(0, 255, 67)); DrawBorderBox(vScreen.x - center, vScreen.y , width, head, 2); DeleteObject(EnemyBrush); EnemyBrush = CreateSolidBrush(RGB(255, 000, 000)); DrawBorderBox(vScreen.x - head * 0.125, vScreen.y+head, head * 0.125*2, head*0.125, 1); DrawLine(vHead.x, vHead.y, windowRect.right / 2, 0, RGB(255, 000, 000)); if (width) { DrawString(vScreen.x, vScreen.y + head / 2, RGB(245, 166, 35), (to_string(health)).data()); }
DeleteObject(EnemyBrush); }
} } } }
}
} } } return 0; }
|