How opentibiabr/otclient works
1. What this repository is
OTClient Redemption is a cross-platform Tibia/OTServ client. Its architecture is split between a native C++ engine and a large Lua-driven UI/game layer. The repo is not a server; it is the client runtime plus content, scripts, and some helper server-side scripts bundled with certain modules.
2. Top-level runtime shape
Startup begins in src/main.cpp, then flows through the framework/application layer into Lua bootstrap files like init.lua, meta.lua, otclientrc.lua, and data/setup.otml. Those files define the initial module set, configuration, feature flags, and asset paths. The app then loads modules dynamically rather than hardwiring most UI/game behavior into C++.
3. Native C++ core vs scripted client layer
The src/framework and src/client trees implement the engine: windowing, rendering, audio, networking, resource loading, Lua binding, and game object models. The modules/ tree implements the actual product features in Lua/OTUI/OTML. This is the main architectural boundary: C++ provides services and game primitives; Lua modules compose the visible client behavior.
4. Framework subsystems
The framework is organized by capability:
- core: application lifecycle, events, timers, module manager, config, resource management
- graphics: OpenGL rendering, textures, shaders, framebuffers, fonts, particles
- sound: sound sources, channels, OGG playback
- net: TCP/HTTP/Web connections, packets, login/game protocols, recorder
- ui: widget/layout system and text/HTML handling
- luaengine: binding C++ objects/functions into Lua
- platform: OS-specific windows and mobile/browser backends
These subsystems are shared by both generic UI modules and game-specific modules.
5. Game model and protocol layer
src/client contains the client-side game domain model: players, creatures, items, containers, map, minimap, outfits, towns, effects, missiles, paperdolls, etc. Networking is centered on protocolgame and related packet parsing/sending code. The client maintains local game state from server messages and pushes player actions back through protocol senders.
6. Module system as the composition layer
modules/modulelib, modules/corelib, modules/gamelib, and the many modules/game_* folders form the modular application shell. Modules are declared with .otmod files and typically pair Lua logic with .otui layouts and optional styles/assets. The module manager loads these at runtime, enabling features such as battle, console, inventory, market, cyclopedia, store, minimap, hotkeys, and more.
7. UI and asset description format
The client uses OTUI/OTML as the primary UI/layout/config format, with some HTML/CSS support for richer panels. Visual assets live under data/images, fonts under data/fonts, styles under data/styles, and localized strings under data/locales. This means many screens are data-driven and skinnable rather than hardcoded in native code.
8. Input, interaction, and HUD behavior
Keyboard, mouse, joystick, and mobile input are abstracted by the framework and then consumed by modules such as hotkeys, action bars, terminal, and game interface. The HUD and in-game widgets are composed from Lua modules and custom UI widgets in both src/client and modules/game_*. This is where user actions are translated into protocol commands and client-side state changes.
9. Protocol and compatibility boundaries
The client supports multiple Tibia/OTServ protocol families, including older releases and newer protobuf-based variants. That compatibility lives across src/client/protocol*, src/protobuf, and feature toggles in data/setup.otml plus Lua feature modules. The architecture is therefore version-adaptive: many UI and gameplay modules branch on protocol features instead of assuming one server version.
10. Platform-specific front ends
There are dedicated platform layers for desktop, Android, and browser/WebAssembly.
- Android lives under android/ with a Kotlin activity, native input bridge, and APK packaging assets.
- Browser support is under browser/ with Emscripten-related overlays, shell, and triplet/tooling.
- Desktop support is handled through the native windowing backends in src/framework/platform.
The same module/data model is reused across these targets where possible.
11. Content packs and special feature modules
Several subsystems are effectively “feature bundles” implemented as modules: action bars, battle, analyzer, cyclopedia, shop/store, wheel of destiny, attached effects, shaders, reward wall, quick loot, tasks, and bot tooling. Some of these also include serverSIDE scripts or API helper files, indicating the client sometimes ships companion scripts for specific server integrations or web endpoints.
12. Build, packaging, and CI
The repo is built with CMake/CMake presets on desktop, Gradle for Android, Dockerfiles for containerized builds, and Emscripten-oriented browser packaging. GitHub Actions cover Windows, Ubuntu, browser, Docker, and tests. This makes the architecture multi-target and tooling-heavy, but the runtime design remains the same: native engine + Lua modules + external assets/config.
13. External integrations
Material integrations include Discord RPC, HTTP/HTTPS/WebSocket support, updater API hooks, and optional encryption/build-time toggles. The client can also talk to external web services for status/update functionality and to game servers for protocol/game data. These are optional edges around the core client, not central dependencies.
14. How to draw the architecture
The clean diagram should show: startup/config/bootstrap on the left; native engine core in the center; Lua module and UI layer above it; game protocol/networking and game-state model as the main runtime data path; assets/styles/locales feeding the UI; and platform-specific launchers around the edges for desktop, Android, and browser. The major boundary is C++ service layer vs Lua-driven feature composition.
Main entry points: application.cpp App Core · modulemanager.cpp ModuleMgr · battle.otmod Game Features · interface.otmod Interface
Components 24
Bootstrap
Startup, config, and module loading
Native Engine
C++ runtime services and game model
- App Core · Application lifecycle and module orchestration
src/framework/core/application.cpp - ModuleMgr · Loads and coordinates runtime modules
src/framework/core/modulemanager.cpp - Resources · Resource loading and unzip/archive access
src/framework/core/resourcemanager.cpp - UI Core · Native widget, layout, and text handling
src/framework/ui/uimanager.cpp - Graphics · OpenGL rendering, textures, shaders, and fonts
src/framework/graphics/graphics.cpp - Sound · Sound channels, sources, and playback
src/framework/sound/soundmanager.cpp - Network · Connections, packets, HTTP, and web sockets
src/framework/net/protocol.cpp - Lua Bindings · Binds C++ objects and functions into Lua
src/framework/luaengine/luainterface.cpp - Game Model · Client-side objects, map, items, creatures, and player state
src/client/game.cpp - Game Protocol · Parses and sends gameplay packets
src/client/protocolgame.cpp
Lua Modules
Composable UI and gameplay features
- Core Lib · Shared Lua utilities, input, HTTP, and UI primitives
modules/corelib/corelib.otmod - Game Lib · Lua-facing game abstractions and helpers
modules/gamelib/gamelib.otmod - Interface · Main game HUD and widget composition
modules/game_interface/interface.otmod - Game Features · Feature modules such as battle, console, inventory, market, minimap, and store
modules/game_battle/battle.otmod - Startup · Module bootstrap sequence and initial runtime setup
modules/startup/startup.otmod - Mods · Optional client features and bundled add-ons
mods/game_bot/bot.otmod
Content
Assets, styles, locales, and setup
- Assets · Images, fonts, sounds, styles, and locales
data/images
Connections 30
- Main → App Core: starts · Native entry boots the application runtime
- Main → Init Lua: loads · Startup hands off to Lua bootstrap
- Init Lua → Meta: imports · Bootstrap metadata is layered early
- Init Lua → Setup: reads · Initial configuration and feature flags
- App Core → ModuleMgr: manages · Application coordinates runtime modules
- App Core → Resources: uses · Application accesses packaged assets and files
- App Core → UI Core: hosts · UI system is attached to the app loop
- App Core → Graphics: renders · Graphics subsystem drives presentation
- App Core → Sound: plays · Audio subsystem provides sound playback
- App Core → Network: connects · Networking services support server communication
- App Core → Lua Bindings: binds · Lua integration exposes engine APIs
- ModuleMgr → Core Lib: loads · Core Lua foundation is loaded first
- ModuleMgr → Game Lib: loads · Game abstractions build on core services
- ModuleMgr → Startup: loads · Startup module assembles initial client state
- ModuleMgr → Interface: loads · Main interface module composes the HUD
- ModuleMgr → Game Features: loads · Feature packs are activated dynamically
- ModuleMgr → Mods: loads · Optional bundled mods extend the client
- Game Lib → Game Model: maps to · Lua domain helpers wrap native game state
- Game Lib → Game Protocol: drives · Lua gameplay logic depends on protocol flow
- Interface → UI Core: builds on · Lua UI is rendered by the native widget system
- Interface → Assets: skins · Layouts and visuals consume packaged content
- Game Features → Game Model: observes · Modules react to local game state
- Game Features → Game Protocol: sends · User actions become protocol commands
- Game Features → Assets: uses · Feature screens use shared styles and images
- Game Protocol → Network: encodes · Game protocol rides on native networking
- Game Model → Game Protocol: updates from · Server messages update local client state
- Assets → Interface: feeds · Content provides UI skinning and localization
- Android → App Core: launches · Android front end starts the same runtime
- Browser → App Core: hosts · Browser packaging targets the same client core
- Build → Main: builds · Desktop build compiles the native entry and engine