This is an unlimited health hack I made for Call of Duty Black Ops in single player mode. It replaces a small section of assembly with no operation codes. I was wondering how my coding and commenting style are, and whether there is a better way to write this.
#include <Windows.h> #include <iostream> #include <TlHelp32.h> const char* PROCESS_NAME = "BlackOps.exe"; const unsigned short POLL_RATE = 100; const unsigned int HEALTH_ADDRESS_1 = 0x7DADD0; const char* HEALTH_1_OP_CODES = "\x89\x85\x84\x01\x00\x00"; const char* HEALTH_1_NEW_OP_CODES = "\x90\x90\x90\x90\x90\x90"; const unsigned short HEALTH_1_OP_CODE_LENGTH = 6; DWORD get_process_id_by_process_name(const char* process_name_) { PROCESSENTRY32 process_entry = {sizeof(PROCESSENTRY32)}; HANDLE processes_snapshot; DWORD process_id = 0; // search for the process name processes_snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (Process32First(processes_snapshot, &process_entry)) { do { if (!strcmp(process_entry.szExeFile, process_name_)) { process_id = process_entry.th32ProcessID; break; } } while (Process32Next(processes_snapshot, &process_entry)); } // clean up resources CloseHandle(processes_snapshot); return process_id; } int main(int argc_, char** argv_) { // get game process id std::cout << "Looking for game..." << std::endl; DWORD process_id = NULL; while (!process_id) { process_id = get_process_id_by_process_name(PROCESS_NAME); Sleep(POLL_RATE); } std::cout << "Game found." << std::endl; // open game handle HANDLE process_handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, process_id); if (process_handle) { std::cout << "Handle obtained to game" << std::endl; } else { std::cout << "Handle not obtained to game." << std::endl; exit(1); } bool hack_enabled = false; bool need_to_update_hack = false; bool need_to_update_screen = true; while (true) { if (need_to_update_screen) { system("cls"); std::cout << "[F8] - " << (hack_enabled ? "(on )" : "(off)") << " Health Hack" << std::endl; need_to_update_screen = false; } if (GetAsyncKeyState(VK_F8)) { hack_enabled = !hack_enabled; need_to_update_hack = true; need_to_update_screen = true; } if (hack_enabled && need_to_update_hack) { WriteProcessMemory(process_handle, (LPVOID)HEALTH_ADDRESS_1, HEALTH_1_NEW_OP_CODES, HEALTH_1_OP_CODE_LENGTH, NULL); need_to_update_hack = false; } else if (need_to_update_hack) { WriteProcessMemory(process_handle, (LPVOID)HEALTH_ADDRESS_1, HEALTH_1_OP_CODES, HEALTH_1_OP_CODE_LENGTH, NULL); need_to_update_hack = false; } Sleep(POLL_RATE); } }