GTProxy is built with a modular, event-driven architecture that separates concerns into distinct subsystems. This design enables clean packet interception, modification, and extensibility through Lua scripting.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.
Architectural Overview
The proxy operates as a man-in-the-middle between the Growtopia client and server, managing bidirectional packet flow and providing hooks for inspection and modification.Core Module
Thecore::Core class (/home/daytona/workspace/source/src/core/core.hpp:18) serves as the application’s central orchestrator, managing all major subsystems:
Key Responsibilities
Lifecycle Management
Initializes and coordinates all subsystems, manages the main event loop
Event Dispatching
Owns the central event dispatcher that all components use for communication
Resource Ownership
Manages lifetime of network connections, handlers, and scripting engine
Configuration
Loads and provides access to proxy configuration settings
Network Module
The network layer consists of two main components that handle connections using the ENet library:Server Component
Thenetwork::Server (/home/daytona/workspace/source/src/network/server.hpp:11) listens for incoming connections from the Growtopia client:
Client Component
Thenetwork::Client (/home/daytona/workspace/source/src/network/client.hpp:13) connects to the actual Growtopia server:
Both components inherit from
IConnection interface, allowing them to be used interchangeably for forwarding packets.Connection Flow
- Client Connects: Growtopia client connects to GTProxy’s server (default port 17091)
- Server Forward: GTProxy’s client connects to the real Growtopia server
- Bidirectional Flow: Packets flow through both connections with event dispatching
- Disconnect Handling: Either side disconnecting triggers cleanup of both connections
Packet Module
The packet system handles encoding, decoding, and routing of Growtopia network messages. See Packet System for details.Core Components
- PacketDecoder (/home/daytona/workspace/source/src/packet/packet_decoder.hpp:14): Parses raw bytes into structured packet objects
- PacketRegistry (/home/daytona/workspace/source/src/packet/packet_registry.hpp:26): Factory pattern for creating packet instances
- PacketHelper (/home/daytona/workspace/source/src/packet/packet_helper.hpp:90): Serializes packets back to bytes for transmission
- Payload Types: Variant-based payload system supporting Text, Game, Variant, and Raw formats
Packet Types
GTProxy supports four payload categories:| Type | Description | Example Use Case |
|---|---|---|
| TextPayload | Text-based messages using key-value pairs | Login requests, action commands |
| GamePayload | Binary game update packets | Player movement, tile changes |
| VariantPayload | Function calls with typed arguments | OnSpawn, OnRemove events |
| RawPayload | Unprocessed binary data | Pass-through for unknown packets |
Event System
GTProxy uses theeventpp library to implement a priority-based event dispatcher. See Event System for complete details.
Event Dispatcher
Theevent::Dispatcher (/home/daytona/workspace/source/src/event/event.hpp:231) manages all event subscriptions and dispatching:
Event Types
Core events defined in/home/daytona/workspace/source/src/event/event.hpp:27:
Handler Module
Handlers subscribe to events and implement the proxy’s core logic:ConnectionHandler
Manages the connection lifecycle, coordinating when the client connects to/disconnects from the server.ForwardingHandler
TheForwardingHandler (/home/daytona/workspace/source/src/core/handlers/forwarding_handler.hpp:9) routes packets between client and server:
ClientBoundPacket and ServerBoundPacket events and forwards them to the appropriate destination unless canceled by another handler.
WorldHandler
Manages world state, tracking tiles, objects, and player position based on packets flowing through the proxy.Scripting Module
The scripting system uses Lua (via sol2) to expose GTProxy functionality to user scripts.LuaEngine
Thescripting::LuaEngine (/home/daytona/workspace/source/src/scripting/lua_engine.hpp:12) manages the Lua runtime:
Binding Modules
Each binding module exposes specific functionality to Lua:- EventBindings: Register event listeners from Lua
- PacketBindings: Create and modify packets
- CommandBindings: Register custom commands
- LoggerBindings: Logging functions
- PlayerBindings: Access player state
- WorldBindings: Access world state
- SchedulerBindings: Schedule delayed/periodic tasks
- ItemBindings: Query item database
ScriptEventBridge
Bridges C++ events to Lua callbacks, allowing scripts to listen to packet events and connection events.ScriptScheduler
Provides async task scheduling to Lua scripts, wrapping the core scheduler.Scheduler Module
Thecore::Scheduler (/home/daytona/workspace/source/src/core/scheduler.hpp:34) provides thread-safe task scheduling:
Task Priorities
The scheduler uses a worker thread pool (default:
hardware_concurrency) and a separate timer thread for delayed execution.Utilities Module
Shared utilities used across the codebase:ByteStream
Theutils::ByteStream (/home/daytona/workspace/source/src/utils/byte_stream.hpp:9) provides binary serialization:
Other Utilities
- TextParse: Parses key-value text format used by Growtopia
- Singleton: Thread-safe singleton template
- Hash: Hashing utilities (Proton hash for Growtopia strings)
- Random: Random number generation
- Network: Network utilities (DNS resolution)
Data Flow Example
Here’s how a packet flows through the system:Initialization Sequence
On startup, thecore::Core constructor initializes subsystems in this order:
- Load configuration
- Create event dispatcher
- Initialize scheduler with worker threads
- Create network server (listening on proxy port)
- Create network client (for outbound connections)
- Initialize web server (for HTTP API)
- Set up event handlers (connection, forwarding, world)
- Initialize Lua engine and load bindings
- Load user scripts from
scripts/directory - Start command handler for console input
Thread Safety
GTProxy uses multiple threads:- Main Thread: Runs the core event loop and network service
- Scheduler Worker Threads: Execute scheduled tasks (default: CPU core count)
- Scheduler Timer Thread: Manages delayed task execution
- Web Server Threads: Handle HTTP requests (if enabled)
Next Steps
Packet System
Learn how packets are decoded and encoded
Event System
Understand the event-driven architecture
Lua Scripting
Start writing Lua scripts for GTProxy
Building from Source
Build and develop GTProxy