Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ZTzTopia/GTProxy/llms.txt
Use this file to discover all available pages before exploring further.
Getting Started
GTProxy is a C++23 network proxy for Growtopia that enables packet debugging and modification. This guide will help you understand the codebase structure and development workflow.Prerequisites
Before contributing, make sure you have:- Built GTProxy from source (see Building from Source)
- Familiarity with C++23 features
- Understanding of CMake and Conan package management
- Knowledge of network protocols and packet structures
Project Structure
Key Directories
src/core/ - Application Core
src/core/ - Application Core
Contains the main application logic, configuration management, logging setup, task scheduler, and built-in web server for metadata access.
src/network/ - Network Layer
src/network/ - Network Layer
Implements ENet-based client and server connections for handling Growtopia’s UDP networking protocol.
src/packet/ - Packet System
src/packet/ - Packet System
Defines packet types, encoding/decoding logic, and event handling. The
game/ subdirectory contains game-specific packet handlers, while message/ contains message packet types.src/scripting/ - Lua Scripting
src/scripting/ - Lua Scripting
Integrates Lua scripting using sol2. The
bindings/ directory contains C++ to Lua API bindings for extending proxy functionality.src/utils/ - Utilities
src/utils/ - Utilities
Common utilities including ByteStream for binary data manipulation, TextParse for string processing, hash functions, and random number generation.
Code Style Guidelines
Naming Conventions
Consistency is critical. Follow these naming conventions:| Element | Style | Example |
|---|---|---|
| Classes/Structs | PascalCase | Core, ByteStream, Config |
| Functions/Methods | snake_case | get_config, is_connected |
| Member variables | snake_case_ | config_, running_, peer_ |
| Local variables | snake_case | sleep_duration, packet_data |
| Enums (unscoped) | SCREAMING_SNAKE_CASE | NET_MESSAGE_UNKNOWN |
| Enum classes | PascalCase values | Result::Success, Result::Failed |
| Namespaces | lowercase | core, network, packet |
| Template params | PascalCase | LengthType, Func |
Header Guards
Always use#pragma once instead of traditional include guards:
Include Order
Organize includes in this order:- Own header (in .cpp files)
- Standard library headers (
<vector>,<string>,<memory>) - External library headers (
<enet/enet.h>,<spdlog/spdlog.h>) - Project headers with relative paths (
"../packet/packet_types.hpp")
Formatting
- Indentation: 4 spaces (no tabs)
- Braces: Same line for class/function declarations
- Brace initialization: Prefer
Type name{ value }overType name = value - Line length: No strict limit, but keep code readable
Types and Attributes
- Use
[[nodiscard]]on getters and functions where ignoring the return value is likely a bug - Use
finalon classes not intended for inheritance - Use
overrideon all virtual method overrides - Prefer
std::byteoverchar/unsigned charfor binary data - Prefer
std::span<const std::byte>for non-owning byte ranges - Prefer
std::string_viewfor non-owning string parameters - Use explicit integer types:
std::uint8_t,std::uint16_t,std::uint32_t
Error Handling
- Throw
std::runtime_errorwith brace initialization for fatal errors - Use early returns for error conditions
- Use
std::optionalfor fallible operations that may not have a value - Return
boolfor simple success/failure operations
Logging
Use spdlog for all logging. Available levels:trace, debug, info, warn, error.
Memory Management
- Use
std::unique_ptrfor exclusive ownership - Use
std::shared_ptronly when shared ownership is required - Use references for non-owning parameters
- Store references as member variables when lifetime is guaranteed
Testing
GTProxy uses Google Test for unit testing. Tests are located in thetests/ directory.
Running Tests
Writing Tests
Create test files following the patterntest_<module>.cpp:
Creating New Packet Structures
When implementing new packet types, follow these steps:Map Packet ID
Add the mapping to
VARIANT_FUNCTION_MAP (for variant strings) or GAME_PACKET_MAP (for game packets) in src/packet/packet_id.hpp:Lua Scripting
GTProxy supports Lua scripting for extending functionality. Scripts inscripts/ are loaded automatically at startup.
Adding or Updating Bindings
When creating new Lua bindings:- Create Test Script: Add
scripts/test_{feature_name}.luato verify functionality - Document API: Update
scripts/AGENTS.mdwith the new Lua API - Example Usage: Include example usage demonstrating common use cases
scripts/AGENTS.md in the source repository.
Build Configuration
CMake Options
The project uses CMake 3.24+ with the following key settings:- C Standard: C11
- C++ Standard: C++23 (required)
- Conan Integration: Automatic via
cmake/cmake-conan/conan_provider.cmake
Adding Dependencies
To add a new Conan dependency, editconanfile.py:
Next Steps
Building from Source
Learn how to build GTProxy from source
Troubleshooting
Find solutions to common development issues