<commit_before>#include <windows.h>
#include <stdio.h>
#include <psapi.h>
#include <string.h>
#include <time.h>

#define WINDOWNAME "Counter-Strike: Global Offensive"
#define PLRSZ 0x18
#define SERVERDLL "server.dll"

const DWORD plr_num_addr = 0x5DE6CCB8;
const DWORD plr_num_offset = 0x93CCB8;
const DWORD plr_list_offset = 0x0089944C;
const DWORD hp_offset = 0x214;
const DWORD coords_offset = 0x1D0;
DWORD server_dll_base;
HANDLE get_process_handle();
BOOL read_bytes(PCVOID addr, int num, void* buf);
HANDLE hProcess;

int main(int argc, char** argv)
{
	HANDLE h = get_process_handle();
    hProcess = h;
	DWORD addr = server_dll_base + plr_list_offset;
	printf("player list offset: %08X\n", addr);
	int players_on_map, i, hp;
	float coords[3];
	DWORD plr_addr;
	read_bytes((PCVOID)addr, 4, &plr_addr);
	printf("players list addr: %08X\n", plr_addr);
	for (;;Sleep(500)) {
		system("cls");
		printf("tick\n");
		read_bytes((PCVOID)(server_dll_base + plr_num_offset), 4, 
				&players_on_map);
		printf("players on the map: %d\n", players_on_map);
		for (i = 0; i < players_on_map; i++) {
			read_bytes((PCVOID)(addr+i*PLRSZ), 4, &plr_addr);
			read_bytes((PCVOID)(plr_addr + hp_offset), 4, &hp);
			read_bytes((PCVOID)(plr_addr + coords_offset), 12, &coords);
			printf("player %d health: %d (%g:%g:%g)\n", i, hp,
					coords[0], coords[1], coords[2]);
		}
	}
	CloseHandle(h);
    return 0;
}

HANDLE get_process_handle()
{
	HANDLE h = 0;
	DWORD pid = 0;
	HWND hWnd = FindWindow(NULL, WINDOWNAME);
	if (hWnd == NULL) {
		printf("FindWindow failed, %08X\n", GetLastError());
		return h;
	}
	printf("hWnd = %08X\n", hWnd);
	GetWindowThreadProcessId(hWnd, &pid);
	h = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, pid);
	if (h == NULL) {
		printf("OpenProcess failed, %08X\n", GetLastError());
		return h;
	}
	printf("process handle = %08X\n", h);
	HMODULE hMods[1024];
	int i;
	if (EnumProcessModules(h, hMods, sizeof(hMods), &pid) == FALSE) {
		printf("enumprocessmodules failed, %08X\n", GetLastError());
	} else {
	    for (i = 0; i < (pid / sizeof(HMODULE)); i++) {
		    TCHAR szModName[MAX_PATH];
		    if (GetModuleFileNameEx(h, hMods[i], szModName,
					sizeof(szModName)/sizeof(TCHAR))) { 
				if (strstr(szModName, SERVERDLL) != NULL) {
					printf("server.dll base: %08X\n", hMods[i]);
					server_dll_base = (DWORD)hMods[i];
				}
			}
		}
	}	
	return h;
}

BOOL read_bytes(PCVOID addr, int num, void* buf)
{
	SIZE_T sz = 0;
    BOOL r = ReadProcessMemory(hProcess, addr, buf, num, &sz);
	if (r == FALSE || sz == 0) {
        printf("RPM error, %08X\n", GetLastError());
		return FALSE;
	}
	return TRUE;
}<commit_msg>code cleanup<commit_after>#include <windows.h>
#include <stdio.h>
#include <psapi.h>
#include <string.h>
#include <time.h>

#define WINDOWNAME "Counter-Strike: Global Offensive"
#define PLRSZ 0x18
#define SERVERDLL "server.dll"

const DWORD plr_num_offset = 0x93CCB8;
const DWORD plr_list_offset = 0x0089944C;
const DWORD hp_offset = 0x214;
const DWORD coords_offset = 0x1D0;

DWORD server_dll_base;
HANDLE hProcess;

HANDLE get_process_handle();
int read_bytes(PCVOID addr, int num, void* buf);
void esp();

int main(int argc, char** argv)
{
	hProcess = get_process_handle();
	esp();
	CloseHandle(hProcess);
    return 0;
}

void esp()
{
	int players_on_map, i, hp;
	float coords[3];
	DWORD plr_addr;
	DWORD addr = server_dll_base + plr_list_offset;
	read_bytes((PCVOID)addr, 4, &plr_addr);
	for (;;Sleep(100)) {
		system("cls");
		read_bytes((PCVOID)(server_dll_base + plr_num_offset), 4,
				&players_on_map);
		printf("players on the map: %d\n", players_on_map);
		for (i = 0; i < players_on_map; i++) {
			read_bytes((PCVOID)(addr + i*PLRSZ), 4, &plr_addr);
			read_bytes((PCVOID)(plr_addr + hp_offset), 4, &hp);
			read_bytes((PCVOID)(plr_addr + coords_offset), 12, &coords);
			printf("player %d health: %d (%g:%g:%g)\n", i, hp,
					coords[0], coords[1], coords[2]);
		}
	}
}

HANDLE get_process_handle()
{
	HANDLE h = 0;
	DWORD pid = 0;
	HWND hWnd = FindWindow(0, WINDOWNAME);
	if (hWnd == 0) {
		printf("FindWindow failed, %08X\n", GetLastError());
		return h;
	}
	printf("hWnd = %08X\n", hWnd);
	GetWindowThreadProcessId(hWnd, &pid);
	h = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, pid);
	if (h == 0) {
		printf("OpenProcess failed, %08X\n", GetLastError());
		return h;
	}
	printf("process handle = %08X\n", h);
	HMODULE hMods[1024];
	int i;
	if (EnumProcessModules(h, hMods, sizeof(hMods), &pid) == FALSE) {
		printf("enumprocessmodules failed, %08X\n", GetLastError());
	} else {
	    for (i = 0; i < (pid / sizeof(HMODULE)); i++) {
		    TCHAR szModName[MAX_PATH];
		    if (GetModuleFileNameEx(h, hMods[i], szModName,
					sizeof(szModName)/sizeof(TCHAR))) { 
				if (strstr(szModName, SERVERDLL) != NULL) {
					printf("server.dll base: %08X\n", hMods[i]);
					server_dll_base = (DWORD)hMods[i];
				}
			}
		}
	}	
	return h;
}

int read_bytes(PCVOID addr, int num, void* buf)
{
	SIZE_T sz = 0;
    int r = ReadProcessMemory(hProcess, addr, buf, num, &sz);
	if (r == 0 || sz == 0) {
        printf("RPM error, %08X\n", GetLastError());
		return 0;
	}
	return 1;
}
{'fraction_non_alphanumeric': 0.16368584758942456, 'fraction_numerical': 0.026438569206842923, 'mean_word_length': 4.467587672688629, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '426450', 'n_tokens_mistral': 2342, 'n_tokens_neox': 2119, 'n_words': 485}