### C++: ZLib Installation and Configuration in Visual Studio Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/6/04.md Provides a step-by-step guide on installing the ZLib library and configuring a Visual Studio project to use it. This involves setting additional include directories for header files and additional library directories for the .lib file, as well as specifying the zlib.lib file in additional dependencies. ```c++ #include // ... other code ... // Example usage of zlib functions would follow here. // For instance, to compress data: // uLongf compressed_size = compressBound(uncompressed_size); // Bytef* compressed_data = new Bytef[compressed_size]; // compress(compressed_data, &compressed_size, uncompressed_data, uncompressed_size); // To decompress data: // uLongf decompressed_size = ...; // Bytef* decompressed_data = new Bytef[decompressed_size]; // uncompress(decompressed_data, &decompressed_size, compressed_data, compressed_size); ``` -------------------------------- ### Install Boxstarter and VM Setup Script (PowerShell) Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/1/04.md This snippet installs the Boxstarter utility and then executes a remote script to configure VM settings and install essential game hacking tools like Cheat Engine, x64dbg, and Chocolatey. It requires PowerShell to run. ```powershell . { iwr -useb https://boxstarter.org/bootstrapper.ps1 } | iex; Get-Boxstarter -Force ``` ```powershell Install-BoxstarterPackage -PackageName https://raw.githubusercontent.com/GameHackingAcademy/vmsetup/master/vmsetup.txt -DisableReboots ``` -------------------------------- ### Install Compression Tools (PowerShell) Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/6/03.md Installs Cmder, a Windows terminal emulator, and the gzip compression utility using Chocolatey. These tools are necessary for manipulating and analyzing compressed files. ```powershell choco install cmder -y choco install gzip -y ``` -------------------------------- ### Installing and Launching x64dbg Debugger (PowerShell) Source: https://context7.com/gamehackingacademy/gamehackingacademy.github.io/llms.txt Provides commands to install the portable version of x64dbg using Chocolatey on Windows and specifies the path to launch the 32-bit debugger executable. ```powershell # Install x64dbg via Chocolatey choco install x64dbg.portable -y # Launch 32-bit debugger C:\ProgramData\chocolatey\lib\x64dbg.portable\tools\release\x32\x32dbg.exe ``` -------------------------------- ### Complete Process Opening and Memory Reading Example Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/3/02.md A complete C++ example demonstrating how to find a window, get its process ID, open a handle to the process with all access rights, and read a DWORD value from a specific memory address using Windows API functions. ```c++ #include int main(int argc, char** argv) { // Find the window handle HWND wesnoth_window = FindWindowA(NULL, "The Battle for Wesnoth - 1.14.9"); // Get the process ID from the window handle DWORD process_id = 0; GetWindowThreadProcessId(wesnoth_window, &process_id); // Open a handle to the process with all access rights HANDLE wesnoth_process = OpenProcess(PROCESS_ALL_ACCESS, TRUE, process_id); // Read a DWORD value from a specific memory address DWORD gold_value = 0; DWORD bytes_read = 0; // 0x017EECB8 is a placeholder address and may need to be found dynamically. ReadProcessMemory(wesnoth_process, (LPCVOID)0x017EECB8, &gold_value, sizeof(gold_value), &bytes_read); // Close the process handle when done (important for resource management) CloseHandle(wesnoth_process); return 0; } ``` -------------------------------- ### Install 7zip with Powershell Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/8/03.md This command installs the 7zip utility using the OneGet package manager. This is a prerequisite for easily manipulating the pk3 archive files. ```powershell cinst 7zip ``` -------------------------------- ### Drawing Order Example Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/5/03.md Illustrates the typical order of drawing elements in a game scene. This sequence can lead to player models being obscured by level geometry when depth testing is enabled. ```c++ draw_player(); draw_guns(); draw_doors(); draw_level_walls(); ``` -------------------------------- ### DLL Entry Point and Hook Setup in C++ Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/4/04.md This C++ code demonstrates the basic structure of a DLL's entry point (DllMain) and the process of setting up hooks for game functions. It includes obtaining the module handle, calculating hook addresses, and modifying memory protection to inject jump instructions. ```c++ #include BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { DWORD old_protect; if (fdwReason == DLL_PROCESS_ATTACH) { //hooking code } return true; } HANDLE flare_base; DWORD mouse_call_address; DWORD mouse_return_address; DWORD player_call_address; DWORD player_return_address; DWORD loop_call_address; DWORD loop_return_address; ... if (fdwReason == DLL_PROCESS_ATTACH) { //hooking code flare_base = GetModuleHandle(L"flare.exe"); // mouse hook mouse_call_address = (DWORD)flare_base + 0x54210; unsigned char* hook_location = (unsigned char*)((DWORD)flare_base + 0xECBC8); mouse_return_address = (DWORD)hook_location + 5; VirtualProtect((void*)hook_location, 5, PAGE_EXECUTE_READWRITE, &old_protect); *hook_location = 0xE9; *(DWORD*)(hook_location + 1) = (DWORD)&mouse_codecave - ((DWORD)hook_location + 5); // player hook player_call_address = (DWORD)flare_base + 0x20840; hook_location = (unsigned char*)((DWORD)flare_base + 0xCAC4); player_return_address = (DWORD)hook_location + 5; VirtualProtect((void*)hook_location, 5, PAGE_EXECUTE_READWRITE, &old_protect); *hook_location = 0xE9; *(DWORD*)(hook_location + 1) = (DWORD)&player_codecave - ((DWORD)hook_location + 5); // game loop hook loop_call_address = (DWORD)flare_base + 0x6B180; hook_location = (unsigned char*)((DWORD)flare_base + 0x6BA94); loop_return_address = (DWORD)hook_location + 5; VirtualProtect((void*)hook_location, 5, PAGE_EXECUTE_READWRITE, &old_protect); *hook_location = 0xE9; *(DWORD*)(hook_location + 1) = (DWORD)&loop_codecave - ((DWORD)hook_location + 5); } CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)injected_thread, NULL, 0, NULL); ``` -------------------------------- ### Install Wesnoth and HxD Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/7/02.md Installs specific versions of the Wesnoth game client and the HxD hex editor using Chocolatey. These tools are used for analyzing game executables and their memory. ```powershell choco install wesnoth --version=1.14.12 -y choco install hxd ``` -------------------------------- ### Assembly Function Call and Return Example Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/2/05.md A basic x86 assembly example demonstrating the 'call' instruction to invoke a function and the 'retn' instruction to return control. This illustrates the fundamental mechanism for function invocation and execution flow in low-level code. ```assembly main: mov eax, 0 call increase_eax mov ebx, eax increase_eax: add eax, 1 mov ecx, eax retn ``` -------------------------------- ### DLL Injection Thread Initialization - C++ Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/5/03.md This C++ code snippet demonstrates how to initiate a new thread when a DLL is injected into a process. It uses CreateThread to start a new thread that will handle the hooking logic, ensuring that the main thread is not blocked. This is crucial for dynamically loaded libraries like OpenGL. ```c++ if (fdwReason == DLL_PROCESS_ATTACH) { CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)injected_thread, NULL, 0, NULL); } ``` -------------------------------- ### Find Wesnoth Module Information Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/7/02.md This C++ code extends the previous example by finding the base address and size of the 'wesnoth.exe' module within the running process. It uses `CreateToolhelp32Snapshot` with `TH32CS_SNAPMODULE` to iterate through the process's modules and identify the target executable's memory region. ```c++ if (wcscmp(pe32.szExeFile, L"wesnoth.exe") == 0) { HANDLE process = OpenProcess(PROCESS_ALL_ACCESS, true, pe32.th32ProcessID); HANDLE module_snapshot = 0; MODULEENTRY32 me32; me32.dwSize = sizeof(MODULEENTRY32); module_snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pe32.th32ProcessID); Module32First(module_snapshot, &me32); do { if (wcscmp(me32.szModule, L"wesnoth.exe") == 0) { break; } } while (Module32Next(module_snapshot, &me32)); CloseHandle(process); break; } ``` -------------------------------- ### C++: Include ZLib Header Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/6/04.md Demonstrates how to include the ZLib header file in a C++ project after setting up the necessary include paths in Visual Studio. This allows access to ZLib's compression and decompression functions. ```c++ #include ``` -------------------------------- ### Map Tile Visibility Initialization in C++ Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/4/02.md Illustrates a typical game logic pattern where all map tiles are initially set to an invisible state before processing unit movements. This ensures a clean slate for determining visibility based on unit proximity. ```c++ for(tile in map) { map[tile] = 0 } ``` -------------------------------- ### Install The Battle for Wesnoth using Chocolatey Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/1/05.md This command installs version 1.14.9 of 'The Battle for Wesnoth' using Chocolatey, a package manager for Windows. Ensure Powershell is run as an administrator before executing. ```powershell choco install wesnoth --version=1.14.9 -y ``` -------------------------------- ### Install Paint.NET - PowerShell Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/8/04.md This PowerShell command is used to install the Paint.NET image editing software. Paint.NET is recommended for modifying game graphics, such as sprite sheets, due to its user-friendly interface and capabilities. ```powershell cinst paint.net ``` -------------------------------- ### Sending Initial Chat Message Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/6/04.md This C++ code shows how to send an initial chat message to a server upon connecting. It constructs a message packet in the Wesnoth format, specifying the message content, room, and sender. The `send_data` function is then used to compress and transmit this message over the `ConnectSocket`. ```c++ const unsigned char first_message[] = "[message]\nmessage=\"ChatBot connected\"\nroom=\"lobby\"\nsender=\"ChatBot\"\n[/message]"; send_data(first_message, sizeof(first_message), ConnectSocket); ``` -------------------------------- ### Install Visual Studio 2019 Community Edition Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/3/02.md Installs the Visual Studio 2019 Community Edition IDE using Chocolatey. This IDE provides the necessary compiler and linker for C++ development. ```powershell choco install visualstudio2019community ``` -------------------------------- ### Accessing Enemy Data in Memory (C++) Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/5/06.md This snippet demonstrates how to access the first enemy's data from memory. It assumes a predefined structure for 'Player' and uses DWORD pointers to navigate the game's memory addresses. Ensure the base addresses are correct for your target game. ```c++ DWORD* enemy_list = (DWORD*)(0x50F4F8); DWORD* enemy_offset = (DWORD*)(*enemy_list + 4); Player* enemy = (Player*)(*enemy_offset); ``` -------------------------------- ### Memory Scanning Workflow and Installation (Cheat Engine) Source: https://context7.com/gamehackingacademy/gamehackingacademy.github.io/llms.txt Outlines the step-by-step process for using Cheat Engine to scan and locate values in a game's RAM. Includes instructions for installing Cheat Engine using Chocolatey on Windows. ```plaintext # Cheat Engine scanning workflow 1. Start game and note current value (e.g., gold = 100) 2. Open Cheat Engine, attach to game process 3. Enter "100" in Value field, click "First Scan" 4. Return to game, change value (spend gold, now = 75) 5. Enter "75" in Value field, click "Next Scan" 6. Repeat until single address remains 7. Add address to list, modify value to desired amount # Installing Cheat Engine via Chocolatey (Windows) choco install cheatengine -y ``` -------------------------------- ### Reading Compressed Data from File Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/6/04.md This C++ code demonstrates how to read the compressed data from the 'packet.gz' file created by the `send_data` function. It opens the file in binary read mode (`"rb"`), reads its content into a buffer, and then closes the file. This prepares the compressed data to be included in a network packet. ```c++ #define DEFAULT_BUFLEN 512 ... FILE* temp_file = NULL; fopen_s(&temp_file, "packet.gz", "rb"); if (temp_file) { size_t compress_len = 0; unsigned char buffer[DEFAULT_BUFLEN] = { 0 }; compress_len = fread(buffer, 1, sizeof(buffer), temp_file); fclose(temp_file); } ``` -------------------------------- ### World to Screen Coordinate Equations (C++) Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/5/09.md Demonstrates the mathematical equations used to represent the relationship between world coordinates and screen coordinates. It highlights the need for a dynamic offset (S) that can be positive or negative, leading to the introduction of variables A (enemy offset) and F (scaling factor) for accurate calculation. ```c++ 512 = 512 + S 100 = 512 + S 1000 = 512 + S ``` ```c++ 512 = 512 + (A * F) 100 = 512 + (A * F) 1000 = 512 + (A * F) ``` -------------------------------- ### Get Process Identifier using CreateToolhelp32Snapshot (C++) Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/7/01.md This C++ code snippet demonstrates how to use the CreateToolhelp32Snapshot API to get a snapshot of all running processes. It initializes a PROCESSENTRY32 structure and uses Process32First and Process32Next to iterate through the process list, which is a prerequisite for finding a specific process's ID. ```c++ #include #include int main(int argc, char** argv) { HANDLE snapshot = 0; PROCESSENTRY32 pe32 = { 0 }; pe32.dwSize = sizeof(PROCESSENTRY32); snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); Process32First(snapshot, &pe32); do { } while (Process32Next(snapshot, &pe32)); return 0; } ``` -------------------------------- ### C++: Example of Game Code Modification (Conceptual) Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/2/07.md This snippet represents a conceptual example of game code modification, illustrating the original instructions at a hooking location before modification. It shows the opcodes and corresponding assembly instructions that will be overwritten to insert a jump to a code cave. Understanding these original instructions is key to ensuring a stable modification. ```assembly opcode instruction ---------------------------------------- 8B01 mov eax, dword ptr ds:[ecx] 8D7426 00 lea esi, dword ptr ds:[esi] FF50 28 call dword ptr ds:[eax+28] B0 01 mov al,1 ``` -------------------------------- ### C++: Conditional Compilation for ZLib Headers Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/6/04.md Illustrates conditional compilation directives often found in ZLib source code, specifically checking for the presence of 'sys/types.h' and 'unistd.h' which are common in Unix-like systems. This snippet highlights potential cross-platform considerations or build configurations. ```c++ #if 1 /* HAVE_UNISTD_H -- this line is updated by ./configure */ # include /* for off_t */ # include /* for SEEK_* and off_t */ #endif ``` -------------------------------- ### Get Current Player Count Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/5/06.md Retrieves the memory address that holds the current number of players in the game. This value is essential for iterating through the enemy list accurately. ```c++ int* current_players = (int*)(0x50F500); ``` -------------------------------- ### Execute Memory Scan (PowerShell) Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/7/03.md Example command to execute the compiled memory scanner program. It initiates a search for the value 75. ```powershell MemoryScanner.exe search 75 ``` -------------------------------- ### Constructing and Sending a Network Packet Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/6/04.md This C++ snippet shows how to construct a network packet containing compressed data. It first copies the size of the compressed data into the first 4 bytes of a packet buffer (specifically at offset +3 for a DWORD) and then copies the compressed data itself into the buffer. Finally, it sends the constructed packet over the provided socket `s`. ```c++ unsigned char buff_packet[DEFAULT_BUFLEN] = { 0 }; memcpy(buff_packet + 3, &compress_len, sizeof(compress_len)); memcpy(buff_packet + 4, buffer, compress_len); int iResult = send(s, (const char*)buff_packet, compress_len + 4, 0); printf("Bytes Sent: %ld\n", iResult); ``` -------------------------------- ### Create Gzip Compressed File (Shell) Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/6/03.md Creates a gzip compressed version of a file named 'test.txt'. The 'gzip' command compresses the file and, by default, removes the original file. ```shell gzip test.txt ``` -------------------------------- ### Get Menu Item State Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/5/10.md A C++ member function that returns a string 'On' or 'Off' based on the boolean state of a menu item. It takes an integer index representing the item. ```c++ const char* Menu::get_state(int item) { return item_enabled[item] ? "On" : "Off"; } ``` -------------------------------- ### Waiting for OpenGL Module Load - C++ Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/5/03.md This C++ code illustrates a common pattern for waiting until a dynamic library, such as opengl32.dll, is loaded into the process. It uses an infinite loop that repeatedly calls GetModuleHandle to check for the module's presence. A short sleep is included to prevent excessive CPU usage while waiting. ```c++ HMODULE openGLHandle = NULL; void injected_thread() { while (true) { if (openGLHandle == NULL) { openGLHandle = GetModuleHandle(L"opengl32.dll"); } ... Sleep(1); } } ``` -------------------------------- ### Get Remote Thread Exit Code using GetExitCodeThread Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/7/01.md Retrieves the termination status of a specified thread. This function is typically called after WaitForSingleObject to determine if the remote thread executed successfully. ```c++ DWORD exitCode; GetExitCodeThread(thread, &exitCode); ``` -------------------------------- ### Sending Version Packet Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/6/04.md This C++ code demonstrates sending a version packet to a server using the `send_data` function. It defines a version string in the Wesnoth format and then calls `send_data` to compress and transmit this string over the `ConnectSocket`. This is part of establishing a connection or communicating client information. ```c++ const unsigned char version[] = "[version]\nversion=\"1.14.9\"\n[/version]"; send_data(version, sizeof(version), ConnectSocket); ``` -------------------------------- ### Declare Arrays for Multiple Enemies and Player Count - C++ Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/5/09.md Defines constants and global arrays to store the coordinates and names of multiple enemies, along with a pointer to the current number of players. This setup allows for dynamic tracking of up to MAX_PLAYERS. ```c++ #define MAX_PLAYERS 32 DWORD x_values[MAX_PLAYERS] = { 0 }; DWORD y_values[MAX_PLAYERS] = { 0 }; char* names[MAX_PLAYERS] = { NULL }; int* current_players; ``` -------------------------------- ### Decompress and Read Data in C++ Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/6/04.md Opens a compressed file ('packet_recv.gz'), reads its decompressed content into a buffer, prints the decompressed data to standard output, and then closes the file. It utilizes the zlib library functions `gzopen`, `gzread`, and `gzclose`. ```c++ gzFile temp_data_in = gzopen("packet_recv.gz", "rb"); unsigned char decompressed_data[DEFAULT_BUFLEN] = { 0 }; gzread(temp_data_in, decompressed_data, DEFAULT_BUFLEN); fwrite(decompressed_data, 1, DEFAULT_BUFLEN, stdout); gzclose(temp_data_in); ``` -------------------------------- ### Main Loop Integration - C++ Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/7/04.md An example of how the `decode_operand` function can be integrated into a main decoding loop. It shows how to call the function after identifying an opcode (e.g., 0x1 for ADD) and incrementing the instruction pointer accordingly. ```c++ case 0x1: printf("ADD "); i++; i += decode_operand(buffer, i); break; ``` -------------------------------- ### Map Player Base Address in C++ Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/5/06.md Demonstrates how to map the game's player base address to a C++ Player structure pointer. It involves obtaining a pointer to the player's base address in memory and then dereferencing it to assign to the Player structure pointer. ```c++ Player *player = NULL; DWORD *player_offset = (DWORD*)(0x509B74); player = (Player*)(*player_offset); ``` -------------------------------- ### Function Prologue and Epilogue (Assembly) Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/2/02.md Shows the standard instructions for setting up a function's stack frame (prologue) and restoring the previous stack frame upon function exit (epilogue). The prologue typically involves pushing the base pointer, moving the stack pointer, and allocating space. The epilogue uses 'leave' and 'ret' to clean up. ```assembly push ebp mov ebp, esp sub esp, ... ... leave ret ``` -------------------------------- ### Example C++ to Assembly Conversion Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/7/04.md Demonstrates how a simple C++ variable assignment can be translated into different assembly code sequences for an x86 processor. This highlights the role of compilers in choosing specific instruction forms and lengths. ```cpp int x = 2; // Possible assembly conversions: // mov [x], 2 // or // mov eax, 2 // mov [x], eax ``` -------------------------------- ### Packet Structure Example (C++) Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/6/01.md Demonstrates a simplified C++ representation of a network packet's structure, including source, destination, and data fields. This illustrates how information is organized for transmission in multiplayer games. ```c++ source: player destination: server data: hello ``` ```c++ source: player destination: server data: f1 ``` -------------------------------- ### Create Bzip2 Compressed File (Shell) Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/6/03.md Creates a bzip2 compressed version of a file named 'test.txt'. The 'bzip2' command compresses the file and, by default, removes the original file. ```shell bzip2 test.txt ``` -------------------------------- ### Setting glDepthRange Function Pointer Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/5/03.md Demonstrates how to obtain a function pointer for the OpenGL glDepthRange function using GetProcAddress. This is necessary to dynamically call OpenGL functions in a game. ```c++ void (__stdcall* glDepthRange)(double, double) = NULL; ... glDepthRange = (void(__stdcall*)(double, double))GetProcAddress(openGLHandle, "glDepthRange"); ``` -------------------------------- ### Get LoadLibraryA Address using GetModuleHandle and GetProcAddress Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/7/01.md Obtains the memory address of the LoadLibraryA function, which resides in kernel32.dll. GetModuleHandle retrieves a handle to kernel32.dll, and GetProcAddress uses this handle to find the address of the specified function. ```c++ HMODULE kernel32base = GetModuleHandle(L"kernel32.dll"); // ... later in the code ... (LPTHREAD_START_ROUTINE)GetProcAddress(kernel32base, "LoadLibraryA") ``` -------------------------------- ### Get Process ID using GetWindowThreadProcessId Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/3/02.md Retrieves the process identifier of the thread that created the specified window. It requires a window handle and a pointer to a DWORD to store the process ID. This is a prerequisite for opening the process. ```c++ #include // ... after getting wesnoth_window ... DWORD process_id = 0; GetWindowThreadProcessId(wesnoth_window, &process_id); ``` -------------------------------- ### Multiplayer Packet Analysis: Wireshark and C++ TCP Client Source: https://context7.com/gamehackingacademy/gamehackingacademy.github.io/llms.txt Demonstrates analyzing multiplayer game traffic using Wireshark and provides a basic C++ TCP client example for connecting to a game server and sending packets. This is useful for understanding game communication protocols and developing custom clients or emulators. Requires Winsock library. ```text # Capture game traffic with Wireshark 1. Start Wireshark, select network interface 2. Apply filter: ip.addr == 3. Start game and connect to server 4. Analyze captured packets # Example Wesnoth packet structure (WML format) [version] version="1.14.9" [/version] # Sending packets programmatically const unsigned char version[] = "[version]\nversion=\"1.14.9\"\n[/version]"; send(socket, version, sizeof(version), 0); ``` ```c++ // Basic TCP client for game server communication #include #pragma comment(lib, "ws2_32.lib") int main() { WSADATA wsaData; WSAStartup(MAKEWORD(2, 2), &wsaData); SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); struct sockaddr_in serverAddr; serverAddr.sin_family = AF_INET; serverAddr.sin_port = htons(15000); // Wesnoth default port serverAddr.sin_addr.s_addr = inet_addr("server.wesnoth.org"); connect(sock, (struct sockaddr*)&serverAddr, sizeof(serverAddr)); // Send handshake/version packet char packet[] = "[version]\nversion=\"1.14.9\"\n[/version]"; send(sock, packet, strlen(packet), 0); closesocket(sock); WSACleanup(); return 0; } ``` -------------------------------- ### Remove Argument Check for Winsock Client (C++) Source: https://github.com/gamehackingacademy/gamehackingacademy.github.io/blob/master/_pages/6/02.md This C++ code snippet shows how to remove the command-line argument check from a Winsock client example. This modification is useful when the server's address and port are hardcoded or managed differently, simplifying the client's startup process. ```c++ if (argc != 2) { printf("usage: %s server-name\n", argv[0]); return 1; } ```