Engine Architecture & Main Loop
Traced live in FarCry2_server (the unstripped Linux dedicated-server binary — see
Overview for why it's the better-symbolized of the two programs in this project) via
GhidraMCP: decompilation + call-target disassembly, entry point outward. All addresses below are
FarCry2_server addresses (0x08/0x09/0x0a range), not Dunia.dll's.
A top-down map of how the engine boots and what runs every frame, stopping at the point where a
branch becomes "a specific gameplay/rendering system" rather than "engine plumbing." Individual
subsystems (physics, .fcb, .spk, Lua) get their own pages elsewhere in this section and in
file-formats; this page is the connective tissue between them.
Entry chain
main(argc, argv) 0x08276870
└─ RunGame(cmdline) 0x08278df0
└─ do {
InitDuniaEngine(cmdline,…) 0x08277830
g_gameFunctionProvider() — one indirect call, launcher-supplied callback
RunDuniaEngine() 0x08276e30
} while RunDuniaEngine() returns true
main just concatenates argv back into one string and hands it to RunGame. In RunGame's loop,
RunDuniaEngine returning true means "reinit and go again" — this is
the resolution-change/settings-apply/level-switch restart path, not just a one-shot run. Each
iteration is a full init → play → teardown cycle.
TickDuniaEngine (0x08276d00) and ShutdownDuniaEngine (0x08276e00) are the other two members of
this exported lifecycle API; both are thin wrappers (CXGame::Update() / Release()
respectively) — present for the editor's embedded-engine use case (the standalone map editor ticks the
engine itself rather than owning the loop), not called from this binary's own main.
Init (InitDuniaEngine)
Decompiles as ~600 lines, but almost all of it is inlined std::string construction (path-building
for MyGames/FarCry2/…) that Ghidra can't fold away — the actual sequence, in order:
Gear::StartEngine()— lowest-level bootstrap (memory/profiling instrumentation bracket; matchesGear::ShutDownEngine()at the very end of this same function, so it brackets init itself, not the whole process lifetime).CNomadPathsingleton constructed — resolves theMyGames/FarCry2/save-data root (see save-data-path).CFCXGameCmdLineParser— parses-dedicated,-norender,-editorpc,-borderless, and friends into globals consumed later in this same function.CCryEnginesingleton constructed;InitializeCore()thenInitializeEngineServices()— the generic engine core, confirming (alongside the Lua/Havok fingerprints in Overview) that Dunia's top-level class is still literally namedCCryEngine.CNomadNotificationManager,CGameErrorManagersingletons constructed.CFCXGameCmdLineParser::Process()— cmd line applied.CGamerProfileNativeconstructed and initialized (local profile, not network account).CCryEngine::Initialize()— the heavy init pass (as opposed to step 4's "core" init).CSoundConfig::ApplySettings().- If a renderer is present (
SceneRendererFacade::HasRenderer()— false on this dedicated-server build, so this whole block is dead code here but shared with the PC client): resolve thelow/medium/high/veryhigh/ultrahigh/optimalquality string to an enum and apply it viaCRenderConfig. - Unless a headless/no-sound flag is set:
CSoundCacheandCAllSoundssingletons constructed,CSoundBudget::SetBudget(0x80000). CXGame::CreateInstance()→CXGame::Init()— the FC2-specific game-session object (distinct from the genericCCryEngine; see "Two class families" below).MSAnim::LoadMoves()— animation move-set table load.CFcxAIconstructed — AI subsystem instance.VerifyParentalControlAccess()gate, thenCXGame::StartGame()— actually starts the session.
Steps 1–8 are generic-engine bring-up; 9–15 are FC2-game bring-up layered on top. The renderer/sound
gating (10–11) is the cleanest evidence in this function that client and dedicated-server builds share
one InitDuniaEngine, branching only on a handful of flags.
On the PC client, step 8's CCryEngine::Initialize (GOG 0x104C2D90) brings the subsystems up in
this order, with other managers interleaved between them (RE-verified on GOG):
- graphics
- network
- sound, honouring
-nosoundand-nosndocc - session
- AI
- the entity system
- physics
CWorld, the world loader- the
ConsoleCommandsconfig section, then the console commands - Massive's in-game advertising, last
The server's order differs: it creates CWorld last.
The main loop (CXGame::Run)
CXGame::Run(bool& outRestart) 0x08882ce0
while (!quitFlag) {
Update(this) — CXGame::Update, see below
elapsed = CHighPerfTimer::GetTimeValue() - frameStart
if (elapsed < targetFrameTime)
Gear::System::Sleep(targetFrameTime - elapsed) — frame limiter
}
Straightforward fixed-ish-rate loop with a sleep-based limiter. In this server binary render is called
inline from the same Update (see below), gated by HasRenderer(); the PC client hands each frame to
a render thread instead — see presentation and input.
CXGame::Update() — per-frame fan-out
CXGame::Update() 0x08882bc0
├─ CPerfProfiler::Capture(…) × 5 — profiling brackets around each phase below
├─ CMemMng::NewFrame() — per-frame arena/allocator reset
├─ CGame::Update(dt, flags) 0x092a4e10
│ ├─ UpdateOperations(dt, flags) — not expanded; FC2 gameplay-operation layer
│ └─ CNetGameControllerManager::Update()
├─ CCryEngine::Update(flags) 0x096a7ec0 — see table below
├─ CDynamicEnvironmentManager::Update() 0x09162730 — weather/time-of-day/fog/wind/sky simulation
└─ CCryEngine::Render() 0x096a6d50 — SceneRendererFacade::Render() iff HasRenderer()
CDynamicEnvironmentManager::Update is a large (~250-line) function but architecturally a leaf: it
drives CTimeOfDay, CSky, CEnvironmentFog, wind/rain evaluation, all self-contained under one
category ("environment simulation"), not fanning out to further subsystems.
CCryEngine::Update() — subsystem dispatch table
The real hub. Most calls are gated behind bits of an update-flags word (param_1 & this->mask), which
the running game operation supplies — see the update mask. Categorized:
| Category | Calls |
|---|---|
| Physics (Havok) | CPhysWorld::StartOfFrame, CPhysWorld::ProcessExplosions, CPhysWorld::TimeStep, CPhysWorldListener::Update |
| World / streaming | CWorld::Update, CWorld::UpdateSync, C3DEngine::PreUpdate, C3DEngine::Update, CDynamicEntityLimiter |
| Entities | CEntitySystem::Update (called twice — once pre-physics, once post-physics), CEntitySystem::DestroyCondemnedEntities |
| AI | CAIEngine::PreUpdate / PostUpdate (gated with the "Domino" flag, see below) |
| "Domino" mission/AI scripting | CDominoDelayManager::Update, CDominoSoundManager::Update, CDominoSequenceManager::Update — all under one flag bit alongside AI PreUpdate, confirming Domino is the Lua-backed mission-scripting layer named in the file manifest |
| Animation | MSAnim::Update |
| Ambient / vegetation | CDynamicAmbientUpdateManager::UpdatePrePhysics / UpdatePostPhysics, CAmbianceManager::Update, RTxcManager tick + PostUpdate — RTxcManager ("Real Tree" component manager) is what reads the .rtx vegetation files — see .rtx |
| Rendering-adjacent | CMovieSystem::Update (cutscenes), CDecalManager::Update, CSky/fog (via CDynamicEnvironmentManager), CBufferFrameID::Increment3DFrameID |
| Audio | GetSoundSystem()->Update() — CSoundSystem::Update, vtable +0x50, the game-side front of the DARE middleware; see audio runtime — and CSubtitleManager::Update |
| Networking | Echo::CNetEngine::Update (confirms Echo is the network-engine namespace), CSessionManager::Update, CCommandRequestManager::Update, CCommandManager::Update |
| Console / debug | CXConsole update, CDebugInfoManager::Update, CErrorImpl::Update, FatalError::Display() (polled — see threading below) |
| Async job join | CJobScheduler::Wait(...) + CParticlesSystemMgr::FinalizeUpdate() — the main thread blocks here for particle work queued on the job system |
| Game mode | CGameModeManager::Update / PostUpdate — SP vs. the CFCXGameMode{DeathMatch,CTF,TeamDeathMatch,VIP,Benchmark,Single,Editor} family |
Which subsystems a frame runs
The update-flags word is the flags of whichever game operation is running. UpdateState (GOG
0x100419E0) takes them from the operation, or from the first child of an operation container.
While the game is paused the tick replaces them with 0x1E53. The bits, as CEngine::Update
(GOG 0x104C2510) tests them (RE-verified on GOG):
| Bit | Gates |
|---|---|
0x1 | graphics |
0x2 | console |
0x4 | the physics step |
0x8 | Domino, AI pre- and post-update, the physics listener |
0x10 | movies |
0x20 | the two entity tick lists and RealTree |
0x80 | a flag passed on into CEngineCore::Update |
0x200 | subtitles |
0x400 | session |
0x800 | net |
So a paused frame keeps graphics, console, movies, subtitles, session and net running and stops physics, Domino, AI and the entity ticks.
The game clock
The clock is CTimer in the server's symbols; on GOG the instance is at 0x11555A60. Each tick
(GOG 0x10299360) does the following (RE-verified on GOG):
- The delta is clamped. The real delta is capped at a maximum,
0.1s by default. AsettingsvalueMaxDeltaTimecan change it (floored at0.001); no shipped config sets it. - Two deltas are kept. The clamped delta is kept at
+0x40, and that delta times a scale is the frame time at+0x38that the engine hands its subsystems. The scale (+0x50) is1.0and nothing but the constructor writes it. - Pausing stops game time, not the frame time. Game time at
+0x30advances only while the pause flag (+0x48) is clear.+0x38keeps updating while paused, butGetFrameTimereturns 0.
On the Linux server the same fields sit 4 bytes earlier. On Steam the clock is reached through the
pointer at 0x11606360, its tick is 0x1029B290, and the delta, the frame time, game time and the
scale are doubles.
A scale of 0 stops the world and keeps the frame. Physics steps only while the frame time is
above 0, so it stops, and AI, animation and game time stand still, while rendering and input go on.
A free camera then needs the real delta at +0x40 handed to its update; given it, it flies through
the frozen world. DevTools' pause does this, and a player dropped from 6 m hung in the air while
paused and fell once the scale was back (seen in game on GOG).
Physics substeps
CPhysicsSystem::Step (GOG 0x10480970) steps only when 0 < dt ≤ 1.0. CPhysWorld::Step
(0x1048FBF0) works in fixed 1/60 s substeps, at most 12 per call. The remainder carries
to the next frame, except when the cap is hit; then the extra time is dropped. Physics is given
the clock's frame time, which the 0.1 s clamp holds to six substeps at most, so neither guard is
reached with stock settings (RE-verified on GOG).
Two class families, not one
CGame/CXGame (generic-looking names) are the actual FC2-specific game-session layer, while
CCryEngine/C3DEngine/CWorld/CEntitySystem are the reusable engine core. A third, much larger
family — CFCXGame* (CFCXGameplayManager, CFCXGameModeDeathMatch, CFCXGameSoundService,
CFCXGameSettingsService, CFCXGameMessageService, CFCXGameStartOperation, …) — sits above both:
"FCX" reads as an internal Far Cry X codename layer for UI/game-mode/session-flow glue, distinct from
both the engine core and the low-level CGame update.
Middleware/subsystem namespaces identified from class names
| Prefix / namespace | Subsystem |
|---|---|
hk* (hkpConstraintQueryIn, hkSimpleContactConstraintData, …) | Havok physics (confirmed at binary level here beyond the evaluation-key string in Overview; hkpMultithreadingUtil also confirms Havok manages its own worker-thread pool independently of CJobScheduler) |
Echo::* | The network engine (Echo::CNetEngine, Echo::INetEvent, Echo::NetDiscoveryEvent) |
Domino* | Lua-backed mission/AI sequencing (delay/sound/sequence managers) |
Magma/CMagma* | UI system (CMagmaInputListener seen here; full .mgb binary format in file-formats/mgb) |
Agora* | Ubisoft's online services SDK (auth, connection tasks) |
*DemonWare* | Backend-as-a-service layer used for accounts/profiles/matchmaking (AccountDemonWareTask*) |
RTxc* | Vegetation ("Real Tree") LOD/rendering manager |
CFCX* | The FC2-specific game-mode/UI/session glue layer (see above) |
Background threads
The server's main loop itself is single-threaded (the PC client adds a render thread), but the engine
is not: the
named-thread call sites (InternalSetThreadName, which every one of these passes its own literal
name string to) give a fixed roster of long-lived worker threads:
| Thread class | Apparent role |
|---|---|
CPhysTimeStepThread | Havok physics step runs off the main thread; CPhysWorld::TimeStep in the main loop takes an IWhilePhysRunUpdate callback, i.e. AI PreUpdate is deliberately run while physics is stepping, then joined |
StreamingDevice | Async world/asset streaming from disk |
CRequestManagerDecompressionThread | Decompresses streamed archive data (LZO/zlib, off the main thread) |
CNetThread, CServerThread, CClientThread | Networking I/O (CServerThread/CClientThread both present even in the dedicated-server binary — likely shared source with the PC client) |
CVoiceThread | Voice chat encode/decode |
CJobScheduler (+ its CJobSchedulerThread pool) | Generic async job system; the main loop explicitly joins it once per frame for particle finalization, so at minimum CParticlesSystemMgr offloads work here |
CLoadingScreenImpl | Keeps the loading screen animating during a blocking level load on another thread (LoadGameFile/BlockingLoadGameFile/SaveGameFile also route through named-thread setup, i.e. save/load I/O is its own thread too) |
bdThread | Bink video decode (matches the Bink video format noted as out-of-scope/third-party in the file manifest) |
Havok internal pool (hkpMultithreadingUtil::initMultithreading/setNumThreads/addThread) | Havok manages its own worker threads separately from CJobScheduler |
The PC client names its threads with the same mechanism. The GOG Dunia.dll carries these
thread names:
RenderThread,RequestThread,StreamingThread,DecompressionThreadPhysTimeStep,LoadingScreen,CJobScheduler_%d,MassiveThreadVoiceThread,CTCPLayerThread,NetFileServerThread,CCommandManagerThread,NetThread,NetworkThread,RemoteObjectThreadGameFileLoadThreadandGameFileSaveThread, each with a blocking variantMovieFrameSaveThread,MovieFrameCompressThread,MovieFrameCopyThreadCMobileEventPollingThread,Gear::LeechThread
How many job workers there are comes from engine\settings\defaultthreadingconfig.xml, and the
patch copy overrides common's. Its JOB_THREADS asks for cores − 3, clamped to 0..1
(0x102B2370). So there is one worker on four or more cores and none below that. The same file
enables RENDER_THREAD and PHYSIC_TIMESTEP_THREAD and sets PHYSIC_THREADS to 0. All of this is
RE-verified on GOG and seen in data.
The jobs are not safe to run on two workers at once. With the count raised to 2, and to 6, a
player's game crashed at random in CEngineNomad::Unlock (Steam 0x1000E170) on a job worker,
called from the worker loop (0x102B25E6), with the lock pointer the worker had saved on its stack
overwritten. With the stock single worker it did not. Seen in a player's logs on Steam v1.03, not
reproduced here.
FatalError::IsSecondaryThreadWaitingForDisplay(), polled once per frame in CCryEngine::Update,
confirms the engine's crash/error-dialog path is deliberately thread-aware: a background thread can hit
a fatal error and hand off to the main thread to actually display it, rather than showing UI off-thread.
Subsystems, one level deeper
CEntitySystem::Update — entities tick via a dependency-graph job scheduler, not a loop
CEntitySystem::Update (0x09450080) is not a for each entity: entity->Update() loop. Per update
step (pre-physics / post-physics — the two flag values CEntitySystem::Update is called with from
CCryEngine::Update), it:
- Walks a cached per-entity task list —
IEntityTask*pointers, one per attachedCEntityComponent, rebuilt only when the entity's cache-dirty bit is set (CEntity::UpdateCacheTaskList,0x0943cc20, called withthis + 0x40bit0x40). Rebuilding sorts the component list by a priority value (vtable slot+0x7con each component) viastd::__introsort_loop, then recurses into attached child entities (CEntityProxy-linked), so a whole parent/child hierarchy's tasks land in one flat, priority-ordered list. - For each task, calls a "ready to run" check (vtable
+4). Tasks whose dependencies aren't satisfied yet are skipped and revisited; tasks that are ready but declared as needing to run off-thread get submitted toCJobScheduler::ScheduleJob; tasks that can run inline execute immediately on the main thread. - Loops polling
CJobScheduler::TryWaitAndPopAllDoneJobs/PopDoneJobWait, and for each job that completes, unblocks whatever downstream tasks were waiting on it — a textbook dependency-DAG scheduler — until the whole per-frame task graph for every entity has drained. - Finishes with
ProcessEntitiesToRespawn(0x0944f8a0) — respawn logic runs only once the entire entity task graph for that step is empty.
Practical read: an entity's .fcb-defined components (see .fcb) aren't
just data — each one that needs a per-frame tick apparently implements IEntityTask, and the engine is
free to run independent components of independent entities in parallel across CJobScheduler's worker
pool, joining only where a real dependency exists — so component update order is not safe to assume
deterministic or single-threaded.
RTxcManager — .rtx is a live vegetation simulation, not a static mesh
The RTxc*/RTxs* class family (RTxcManager, RTxcResource, CRTxEngineResource) is far richer
than a mesh format. The concrete component classes it manages:
| Class | Role |
|---|---|
RTxcSkeletonDyn / RTxcSkeletonRdr / RTxcSkeletonRdrUncompressed | The branch hierarchy — a dynamic (simulation) copy and a render copy, with a compressed and uncompressed render variant |
RTxcSimulation / RTxcSimulationHRT / RTxcSimulationPRT | Wind-sway physics simulation — two named techniques (HRT/PRT, not decoded) |
RTxcLOD | Level-of-detail selection |
RTxcDefoliantNode / RTxcDefoliantLeaf / RTxcDefoliantHLeaf | Per-leaf-cluster defoliation state — this is the binary-level confirmation of FC2's marketed "shoot the leaves off trees" foliage system |
RTxcRegenNode / RTxcRegenLeaf / RTxcRegenHLeaf | The inverse of defoliation — leaves regrowing over time |
RTxcDestruction, RTxsBrokenBranch | Branch-breaking state, with broken branches tracked as their own sub-objects |
RTxcFire | Burning state |
CRTxEngineResource (the loadable top-level resource — CreateInstance at 0x095bcd14 is its
factory) owns a hashtable of SRealtreeSound, keyed by an int event id — confirming individual trees
carry their own associated sounds (rustling, breaking, burning), tying this system directly into the
audio layer, not just rendering/physics. RTxcManager::LoadSkeletal spells the format's layout out
in full. The geometry half is decoded — see .rtx; the simulation state these
classes own is not.
Echo::CNetEngine — an object-replication network engine
Echo::CNetEngine::Update() (0x098f58e0) drives four subsystems in order: CNetObjectManager,
CNetChannelManager, COperationNotifier, CNetworkLog — each with its own RunMainUpdate(). The
surrounding class names sketch a fairly complete home-grown replication engine:
- Replicated objects:
Echo::CNetObject, keyed byEcho::CNetObjectId, managed byCNetObjectManager. - Typed, qualifier-based property serialization:
Echo::CNetDataNumber<T, EQualifiers>,Echo::CNetDataString,Echo::CNetDataNdBool— each networked field declares a qualifier enum, presumably controlling quantization/delta-compression per field. - Priority-ordered messaging:
Echo::CNetMessageRefsorted byEcho::DescendindMessageOrderComparison— a relevance/priority queue, highest-priority message first, the standard pattern for keeping bandwidth-limited replication responsive. - Per-connection packing:
Echo::CPackerConnection, and a sortedEcho::CProtocolEntryprotocol table (IsNetProtocolEntryLesserThan). - Voice:
Echo::CNetVoicePeerMessage— ties directly to theCVoiceThreadbackground thread listed above. - Async operations:
Echo::IOperation/COperationNotifier— connection/matchmaking-style operations that complete asynchronously and notify back intoRunMainUpdate.
The wire format and protocol are not decoded. The object-relevance/replication logic lives in
CNetObjectManager, and the per-field serialization in the Echo::CNetData* templates.
The CFCXGameMode* family — a thin FC2 layer over a generic engine strategy pattern
The "two class families" pattern holds one level deeper. CFCXGameModeSingle's
constructor is exactly:
CFCXGameModeSingle::CFCXGameModeSingle() {
CGameModeSingle::CGameModeSingle(this); // generic-engine base
vtable = &CFCXGameModeSingle_vtable;
CGameMode::SetID(this, ms_modeID); // registers this mode's CStringID
}
Every CFCXGameMode* (Single, DeathMatch, CTF, TeamDeathMatch, VIP, Benchmark, Editor)
follows the same shape: CFCXGameMode<X> : CGameMode<X> : CGameMode, registering its own string ID.
That ID is the hashtable key CGameModeManager's constructor reserves space for (see the main-loop
section above) — confirming game-mode selection is a factory-by-name lookup, not a switch statement.
CGameModeManager::Update itself is a one-line polymorphic delegation to whichever CGameMode is
currently active:
void CGameModeManager::Update(float dt) {
if (active) CGameMode::Update(activeMode);
}
All mode-specific behavior lives in the concrete subclass's override, not in the manager.
CFCXGameplayManager sits alongside this as a Lua-scriptable service (GetGameModeService<T> is a
service-locator template; SetMapArmy is directly callable from mission scripts via the
function-registry-adjacent script-binding pattern), rather than being part of
the mode-selection mechanism itself.
"Domino" — Lua loads through the same generic VFS as every other asset
Domino has a much larger class footprint than the three managers named in the main dispatch table. The family breaks down by role:
| Class(es) | Role |
|---|---|
CDominoManager | Central hub — spawns entities by script name (SpawnDominoEntity), reports IsScriptAutorunEnabled |
CDominoDelayManager / CDominoDelay | Timed callbacks — CreateDelay(seconds, ...), and on expiry calls straight into CScriptCallbackSystem::CallCallback (see below) |
CDominoSequenceManager / CDominoSequenceListener | Event-driven listeners (CreateListener) |
CDominoSoundManager / CDominoSound | Script-triggered sounds |
CDominoBoxInstance / CDominoBoxResource | "Domino Box" — mission-trigger-volume system (CreateBox, RegisterBox) |
CDominoComponent | Attaches Domino to an entity as a real per-frame update component — see below |
CTaskCheckDominoData / CTaskSendDominoEvent | One-shot event delivery — both derive from CTask, not IEntityTask (see below) |
CBrainDomino, CScannerDominoEvent | Direct integration points into the AI brain/sense system (see the AI section) |
CPawnBeautifierDominoPlayer, DominoPlayAnim/DominoCanActivateAnim/DominoInterruptAnim/ApplyNextDominoAnim | Script-driven animation overrides — how a mission script puts a character into a specific scripted pose/anim |
CDominoConsoleCommandManager | Scripts can register their own console commands |
CDominoWaterLevelManager | Scripted water-level changes (flood events, etc.) |
Every GenericFunctionToCall<...>/GenericFunctionToCall2<...> template instantiation over a
CDomino* member function (CreateDelay, CreateListener, SpawnDominoEntity,
RegisterConsoleCommand, LoadResource, …) is that method being wrapped for direct Lua callability —
this is the concrete binding mechanism behind the Lua API surface documented on
the Lua API page. For what the actual .lua script files built on top of this
binding layer look like — Domino is node-based visual scripting, not hand-written Lua, with
a ~115-node standard library and 832 authored mission graphs — see Domino
Scripts.
Two distinct ways Domino talks to an entity. CDominoComponent's constructor sets two vtable
pointers on itself (multiple inheritance) — consistent with it being both a CEntityComponent and an
IEntityTask, meaning it sits directly in the per-frame task graph documented above, for continuous
per-frame checks. CTaskSendDominoEvent/CTaskCheckDominoData, by contrast, derive from CTask (the
AI task-tree base — see below), not IEntityTask. Practical read: Domino delivers one-shot mission
events by producing tasks into the AI behavior-task system, the same mechanism that drives regular AI
behavior, rather than a separate ad-hoc RPC layer.
The patched-Lua question. lua_loadfile (0x09bd7850) — the actual interpreter entry point,
called from lua_dofile/luaB_loadfile — resolves its path via CFileManager::FileExists /
CFileManager::FileOpen. That's the same generic engine file-resolution path every other asset type
goes through; there is no Lua-specific or archive-only special case. This means the community
disagreement in Gotchas over whether a patched .lua file is honored at
runtime isn't really a question about Lua at all — it reduces to the same question that already governs
every other patched asset (see archives), and the negative
report is more plausibly explained by a wrong archive/path or a stale resource-cache entry than by the
engine special-casing script files.
In CDominoDelayManager::Update (0x093bf270), each expired CDominoDelay calls
CScriptCallbackSystem::CallCallback(...) directly — confirming a "delay" is literally a deferred
Lua function call, i.e. this is the concrete mechanism behind the reinforcement/respawn timers noted
in the file manifest.
CAIEngine — a classic sense/decide/plan/act architecture, group-aware
CAIEngine::PreUpdate/PostUpdate (0x09a4b460 and its counterpart) are themselves thin: gated by an
enabled flag and a reentrancy guard, then one virtual call out to whatever's stored in the engine — all
the real structure lives in what gets registered in CAIEngine's constructor, which is effectively the
AI subsystem's full bootstrap. Two class hierarchies, registered through the same
CFactory<T>::Register-by-CStringID factory pattern seen elsewhere (CGameModeManager, resource
types):
- AI objects:
CNomadObject → CAIObjectRoot → CAIObject → CAgent → {CDispatcher, CCollective}. Individual agents (presumably one per NPC) can belong to aCCollective(squad-level group AI) coordinated by aCDispatcher— group/squad behavior is a first-class part of the object model, not bolted on. - AI tasks:
CNomadObject → CTaskRoot → {CAction, CDecision, CScanner, CPlan → CBrain}— a textbook sense → decide → plan → act pipeline, withCBrainas the top-level per-agent orchestrator. This is exactly where the Domino integration points above attach:CBrainDomino(a brain variant) andCScannerDominoEvent(a scanner variant) let mission scripts inject behavior and perception events at the same level as the AI's own senses and decisions, not through a side channel.
Also registered here: CPersonalitySystem (very likely the code-side counterpart to the
enemy_archetypes.xml FOV/awareness tuning noted in
the file manifest and
Patrols), CAIDebugTool, CPathManager/CPathfinderNodePool
(pathfinding), and CNavMeshSectorResource, registered as a real streamed resource type
(CResourceManager::RegisterNewResourceType + StreamingManager::RegisterAllocCallBack, the same
pattern used for ordinary world-streamed data). That's the runtime loader for .nvm (see the file
manifest).
MSAnim — animation is a resource-registration hub, not a per-frame animator
MSAnim::Update (0x09b98460) is almost nothing: it advances a tick counter and a delta-time
accumulator. MSAnim's real substance is in its constructor, which — following the exact same
CFactory/CResourceManager::RegisterNewResourceType + StreamingManager::RegisterAllocCallBack
pattern seen for CAIEngine and CGameModeManager — registers a family of streamed animation resource
types: CMovementResource, CAnimationPackageResource, CAnimationResource, CSkeletonResource,
CFrankensteinPoseResource (procedural pose blending/assembly — the name is Dunia's own), and a facial
pair, CFaceActorResource/CFaceAnimResource (plus a CFaceAnimModel::LoadFacialConfig() call).
MSAnim is the asset/resource-type bootstrap for animation, not the thing that actually animates
anything per frame.
The actual per-frame work happens in CAnimationComponent — and it has the exact same dual-vtable
construction pattern as CDominoComponent, confirming it's a real CEntityComponent/
IEntityTask, sitting directly in the dependency-graph job scheduler documented under
CEntitySystem::Update above, not a separate animation "subsystem tick." Its constructor wires up its own internal mini pipeline of named callback stages —
PrePhysTree/PostPhysTree, PrePhysFacial/a matching facial stream, RegisterStreamUpdateMatrix/
GetCodeUpdateMatrix — each backed by its own CJobStreams instance (the same job-stream mechanism
CJobScheduler runs). Animation evaluation is itself split into pre-physics and post-physics job
stages — skeletal pose evaluation before the physics step, ragdoll/physics-driven displacement applied
back after it — with facial animation and matrix updates as their own parallel streams, rather than one
monolithic per-entity animate() call.
Locomotion decision-making (which move/animation state an entity should be in) is a separate concern
from playback: CMoveStateMachine (constructed per-entity via SetMoveStateMachine, queried by Domino
for things like whether an "interrupt" move state exists) sits on top of a more general
CGOStateMachineDriver/CGOStateMachineTrack framework — a generic named-state, named-transition
system used broadly for object behavior (not just animation), loaded from CStateMachineResource/
CStateMachineBlobResource. Locomotion is one instance of a general state-machine framework, not a
bespoke animation-only mechanism.
Weapons & inventory — strategy objects over data-driven properties, event-driven state
Inventory is a straightforward typed-item hierarchy: CInventory (the container, per pawn) holds
Gear::RefCountedPtr<CInventoryItem> entries (Gear:: — confirmed elsewhere as Dunia's low-level
runtime/utility layer, e.g. Gear::ThreadBase, Gear::AdaptiveLock — items are ref-counted at that same
foundational level). CInventoryItem specializes into CInventoryItemWeapon, CInventoryItemGadget
(→ CInventoryItemEquippedGadget/CInventoryItemEmbeddedGadget), CInventoryItemEquipment, and
CInventoryItemAmmoPouch. UI never touches inventory data directly — CInventoryViewPawn and
CInventoryViewWeapon are adapter/projection objects (one CInventoryViewWeapon is allocated directly
inside CWeapon's own constructor), the same "the UI layer only ever sees a view object, never the raw
system" shape as CFCXGameplayManager as a Lua-facing service.
Weapons compose a fire mode as a strategy object. CWeapon (: CEquipmentBase) doesn't hardcode
how it fires — CWeaponFireStrategy is a base class with one concrete subclass per fire-mode archetype:
CWeaponFireBulletStrategy, CWeaponFireFlameStrategy (flamethrower), CWeaponFireMeleeStrategy,
CWeaponFireMortarStrategy, CWeaponFireProjectileStrategy (rockets), CWeaponFireIEDStrategy
(improvised explosives). Each strategy has a matching *Properties class
(CWeaponFireBulletProperties, etc.) plus a shared CWeaponPropertiesCommon and a central
CWeaponsPropertiesRepository — this is the runtime-side counterpart of the .fcb-driven weapon
stat tuning documented in the file manifest
(41_WeaponProperties.xml.fcb): the strategy object is the behavior, the Properties object is the data
that parameterizes it, and they're deliberately factored apart.
Weapon state is event-driven, not polled. Reload isn't a flag, it's a sequence of distinct event
objects — CWeaponEventReload → CWeaponEventReloadDonePreConsumption (the point before ammo is
actually deducted, presumably where an abort is still possible) → CWeaponEventReloadDone, with a
parallel CWeaponEventReloadAbort. Weapon degradation (jamming) is modeled the same way:
CWeaponCanBreakEvent / CWeaponBrokeEvent — this is the binary-level confirmation of FC2's
weapon-degradation mechanic, implemented as explicit state-transition events rather than a hidden
durability counter. The Memento classes — CWeaponMemento, CWeaponControllerMemento,
CWeaponProjectileMemento, CWeaponProjectileControllerMemento, CWeaponIEDMemento — were first
read here as the weapon's save path. They are its network replication instead: CWeapon::ReadNetMemento
and WriteNetMemento are called from CWeaponNetworkComponent. A weapon saves through its registered
members like any other entity; see the component and property registry.
CWeaponBazaar (the arms-dealer/shop system, with UnlockItem exposed to Lua the same way
CFCXGameplayManager::SetMapArmy is) is the progression/economy layer sitting on top of all of the
above — a separate concern from how a weapon fires or persists.
World streaming — generic resources plus a declared dependency graph, half-invisible on this binary
Two limits: C3DEngine::PreUpdate is an empty stub on this build, and (per
Overview) rendering itself was compiled out entirely — so whatever actually decides
"which sectors are near the camera right now" on the real PC client, driven by view/visibility, isn't
present to trace here. What is traceable is everything underneath that decision.
StreamingManager itself is small and generic: a CStringID → allocator-callback hashtable. Every
resource-owning subsystem traced here — CAIEngine (workspace/navmesh sectors), MSAnim (movement/
skeleton/facial resources), RTxcManager — registers its own allocation callback into this one table
via StreamingManager::RegisterAllocCallBack. Streaming isn't a bespoke system per content type; it's
one generic allocation-callback registry that every content type plugs into, matching the same
CFactory<T>/CStringID-keyed pattern used for game modes, AI object types, and AI task types
elsewhere in the engine.
World content itself is organized into CWorldSector objects, which are ordinary entries in the same
generic CResourceManager every other resource type goes through (GetResource<CWorldSector>) — not a
separate bespoke loader. Loading one is driven by a declared resource-dependency graph
(BuildRsrcDep/LoadDep, referencing CWorldSector among other resource kinds) rather than purely
ad hoc runtime proximity queries, and each sector has a companion CSectorPreloadResource — a two-tier
preload list (a strict tier, plus a ms_enableRelaxed-gated wider/lower-priority tier) naming what else
should be resident while that sector is active. Practical read: streaming decides what to load through
declared per-sector dependency/preload manifests; the (render-coupled, not present here) visibility
system decides when.
Save/load — a generic reflection framework, not per-subsystem bespoke code
The top level is a straightforward async operation: CGameFilesService::DoLoadGameFile creates a
CGameFile descriptor and hands off to a CStorageDevice abstraction (a save-location abstraction —
memory card / disk / cloud — inherited from the multi-platform, console-oriented heritage even though
this build targets Linux), setting a state field rather than blocking. The handler names spell out an
explicit state machine: HandleOp_LoadGameFile_AutoLoad_SelectStorageDevice_Complete →
HandleOp_LoadGameFile_AutoLoad_Loading_Complete, the same completion-callback shape as the
Echo::IOperation/COperationNotifier async-operation pattern used in networking — save/load
is just another async operation on that same generic mechanism, not a special case.
Per entity, CPersistenceDB::RestoreEntity — past its hashtable bookkeeping (a fairly ordinary two-level entity-id → record lookup) — bottoms
out in one call: CNomadObjectDescriptor::LoadState(entity, serializableNode). CNomadObject is the
same base class found under the AI object hierarchy and AI task hierarchy in the CAIEngine
section above. Persistence isn't bespoke per-entity-class serialization code; it's one
generic reflection framework (ISerializableNode/CNomadObjectDescriptor) that anything built on
CNomadObject gets for free. What each entity class captures is whatever its
CNomadObjectDescriptor declares, the same mechanism every other reflectable object in the engine
uses, not hand-rolled per-class code; every class's list is in
the component and property registry.
Physics — Havok is linked directly, not wrapped behind a home-grown abstraction
CPhysWorld is a thin FC2-side facade (CPhysWorldImplBase → CPhysWorldImpl) directly over a
genuine, statically-linked, unmodified Havok Physics SDK — hkpWorld, hkpWorldObject,
hkpWorldOperationQueue (bodies are added/removed from the simulation through a deferred operation
queue, not mutated mid-step), hkpWorldCinfo, hkpWorldMaintenanceMgr are all real Havok classes, not
FC2 reimplementations. CPhysWorldThreadMemory/Impl is per-thread scratch memory, tied to the
CPhysTimeStepThread background thread — Havok's standard thread-local
allocation pattern. The facade/impl split (CPhysWorldImplBase abstract, CPhysWorldImpl the concrete
Havok-backed implementation) is the same generic-interface/concrete-backend layering used throughout
this codebase (CGame/CXGame, CGameMode/CFCXGameMode*) — Havok is just the backend slotted behind
it, not a special case.
Entities become physical the same way they get any other capability — a CEntityComponent fetched via
GetComponent<T>. CPhysComponent is the base, specialized by physical-object kind:
CCharacterPhysComponent (pawns), CRigidPhysComponent, CCompoundPhysComponent (multi-body/
destructible), CStaticPhysComponent/CStaticClusterPhysComponent (non-moving world geometry, the
cluster variant presumably batched for efficiency), and CVehicleWheeledPhysComponent/
CVehicleFloatingPhysComponent (cars vs. boats, as distinct specializations).
The unifying spine: CNomadObject
Decompiling CEntity::GetComponent<CPhysComponent>() surfaces its full ancestry:
CPhysComponent : CEntityComponent : CNomadObject. CNomadObject is also the root of the AI object hierarchy
(CAIObjectRoot → CAIObject → CAgent) and the AI task hierarchy
(CTaskRoot → {CAction, CDecision, CScanner, CPlan → CBrain}) documented under CAIEngine, and it's
what makes the generic persistence mechanism (CNomadObjectDescriptor::LoadState) possible at all.
The full GetComponent<T> instantiation list shows the breadth of what specializes
CEntityComponent/CNomadObject in practice: AI (CAIComponent, CFCXAIComponent), animation
(CAnimationComponent, CSimpleAnimationComponent), physics (the CPhysComponent family above),
graphics (CGraphicComponent, CBaseGraphicComponent, CCustomMaterialComponent), vegetation
(CRealtreeComponent — the entity-side hook for the RTxc* system documented above), vehicles/gadgets/
weapons (CGadget, CMountedWeapon, CWeapon), triggers and gameplay volumes
(CProximityTriggerComponent, CTriggerComponent, CFireRegionComponent, CCapturePoint,
CSafeHouseComponent, CMedicStation), counters/economy (CFCXCountersComponent*,
CEconomyComponent), and persistence itself (CPersistComponent — very likely the per-entity opt-in
marker for whether an instance gets a save record at all, the other open question in
savegame.md).
The practical shape of the whole engine: almost everything that isn't pure
engine-core plumbing is a CNomadObject. Entity components are one specialization of it, fetched by
name (CStringID) through GetComponent<T>, scheduled every frame through the dependency-graph job
system documented at the top of this page. AI objects and AI tasks are a second specialization, wired
through the same CFactory<T>-by-name registration pattern used for game modes and resource types.
Persistence works uniformly across all of it because it's one reflection mechanism operating on the
common base, not per-subsystem serialization code. The subsystems documented on this page — physics,
animation, AI, Domino, weapons, streaming — read as separate systems from the outside, but they're
consistently built as specializations of the same small set of patterns (CNomadObject composition,
CStringID-keyed factories, job-scheduled per-frame update), not independently-architected subsystems
that happen to coexist.