Skip to main content

Dunia.dll — The Lua-Exposed API Surface

Verified via reverse engineering

See the overview for binary identification, including the embedded Lua 4.1 (alpha) interpreter confirmation. This page covers what C++ exposes to Lua; see Domino Scripts for what the actual .lua script files built on top of it look like and cover.

The interpreter is Lua 4.1, so Lua 5's library is not there (proven): a console chunk calling ipairs fails with attempt to call global 'ipairs' (a nil value). Walk a table with a numeric for over a count kept by hand.

Every C++ function/method exposed to the embedded Lua interpreter goes through one choke point: RegisterLuaBinding(namespace_or_0, "Name", handlerPtr) (0x102aa850). namespace_or_0 == 0 registers a global Lua function callable from anywhere; a class-name string (e.g. "CBuddiesManager") registers a method scoped to that manager's Lua handle, typically obtained via a GetXxxManager() global first (several of which are themselves in the global list below, e.g. GetBuddiesManager, GetFCXMissionManager).

The ~260 call sites (every xref to 0x102aa850) sit in ~30 distinct registration functions, each corresponding to one exposed class or global batch. This is the authoritative map of the engine's Lua scripting surface — the source for SCRIPTS\MissionTools.lua and friends.

Global functions (namespace = 0, callable from anywhere)​

Entity/utility (0x10591120, 22 fns): GetInvalidEntityId, GetLocalPlayerId, GetEntityName, IsEntityLoaded, IsEntityValid, AttachAnchor, ValidateSyncAnim, GetEntityInPrefab, RemoveEntity, GetStringID, GetNoCaseStringID, PathID, SetPlayerActionMap, PushPlayerActionMap, PopPlayerActionMap, SendForceState, DrawTextToScreen, SetVisibility, one unnamed-string-literal binding, UnBind, GetGlobalString, GetGlobalNumber, SpawnEntityFromArchetype.

SpawnEntityFromArchetype(name, x, y, z, ax, ay, az) (FarCry2_server 0x093c2640) spawns the archetype named by its fully qualified hidName into the mission component's default layer, then SetPos and SetAngles it. The three angles are degrees, the third being yaw. It returns the new entity's id, or the invalid id when the name resolves to nothing. It does not find the ground: the entity starts exactly at z. The id reaches Lua as a decimal string, printed %llu by the binding (server 0x093c4550), so the invalid id reads 18446744073709551615 (proven).

Gameplay/mission scripting, batch 1 (0x109fc830, 70 fns — the single largest registration site, almost certainly backing SCRIPTS\MissionTools.lua): SpawnPickupMissionItem, AddWeapon, AddGadget, CameraShakeAndGamePadRumble, SpawnWeapon, RefillWeaponAmmo, RefillSyrettes, RemoveAllWeapon, RemoveAllGadget, RemoveAllInventory, SelectWeapon, DrawWeapon, HolsterWeapon, TeleportEntity, SpawnReinforcementScenario, SetLookAtTargetID, PlayAnimSimpleObject, PhoneCall, CanAccessMedicine, SendAchievementData, RemoveScriptCallback, ClearScriptCallbackID, GetMalariaPillCount, SetMalariaPillCount, StopMalariaBlackout, SetSicknessLevel, SetBaseInfamy, EnablePostFx, DisablePostFx, SwitchCamera, SetToScriptedCollisionGroup, SendPierceStimWithOrigin, SendPierceStimNoOrigin, LookAtTarget, StopLookatTarget, EnableWagerRegion, DisableWagerRegion, PlayEmotion, PopUpEndOfGame, PopUpInGameCredits, StartDefenceReversal, StopDefenceReversal, PopUpObjective, StartBargeAssault, StopBargeAssault, BargeBreakdown, BargeRepaired, BargeEnableZone, BargeDisableZone, StartBuddyBetrayal, BindToVehicleRide, UnbindFromVehicleRide, StartAnimalFollowPath, StopAnimalFollowPath, SetupVehicleFollowPath, StartVehicleFollowPath, StopVehicleFollowPath, EnableScriptedAIMode, DisableScriptedAIMode, ForceSocialRegionToCombat, EnableRadioBroadcast, StartTownEscape, StopTownEscape, StartDentalPlan, StopDentalPlan, StartJacksBuddy, StopJacksBuddy, GetClosestAutomaticPrefab, SetupDefenceRevesalMikesPlace, SetupBuddyHealth, EnableCheck.

Gameplay/mission scripting, batch 2 (0x10725120, 33 fns): AddScriptedSceneParticipant, RemoveScriptedSceneParticipant, GetFCXMissionManager, GetBuddiesManager, GetGameplayManager, GetFCXBarkManagerService, GetWeaponBazaar, EnableTutorial, SetScriptedDeath, StartDefoliantFX, GameChangeWorld, GameChangeWorldDefaultSpawnPoint, GetTriggerComponentContacts, SendPlayGame, KillPawnAgent, ChangeReinforcementRegionSpawnRate, OverrideMapTexture, GameStartStopAMBXScript, ChangeHealingPreference, StartDesertStorm, StopDesertStorm, SetUsableEntitySize, AddDiamonds, SetObjectiveState, AddOverrideDesertSetting, RemoveOverrideDesertSetting, AttachAnimationPackage, DetachAnimationPackage, DeleteEntityInTrigger, IsPartnerMissionUnlock, SendSomeoneTalkedEventToPlayer, BlockBuddyRescue, UnblockBuddyRescue, SetCinematicUIMode.

Sound (0x10629290, 2 fns): StartSoundMixingFromLua, StopSoundMixingFromLua.

Class-scoped methods (manager singletons, obtained via a GetXxx()/instance accessor)​

ClassMethod countMethods
CBuddiesManager34IsBuddyUnlocked, GetBuddyState, GetBuddyGender, IsBuddyAvailable, AssignBuddy, SpawnPrimaryBuddy, SpawnBuddy, GetBuddyList, GetBetrayedBuddyList, PositionSpawnedBuddy, RemoveBuddyFromWorld, MercyKilledBuddy, BetrayedBuddy, GetRescueBuddyEntityId, AddHistoryPointsToPrimaryBuddy, AddHistoryPointsToSidequestBuddy, SetSidequestMissionState, AddRescueBuddySpawnEventListener, RemoveRescueBuddySpawnEventListener, AddRescueBuddyChangedEventListener, RemoveRescueBuddyChangedEventListener, GetPrimaryBuddyName, CheatSetRescueBuddy, SetBuddyRescueActive, IsRescueBuddyAvailable, SetShowRescueBuddyInMenu, AddDefenceReversalEventListener, RemoveDefenceReversalEventListener, SetDefenceRevesalBetrayedBuddies, BypassSetPrimaryBuddy, BypassSetSecondaryBuddy, BypassSetBuddyUnlock, BypassSetBuddyHistoryPts, BypassSetBuddyLifeState
CFCXMissionManager22ActivateBuddyMission, SelectMission, GetMissionFaction, SetCurrentMission, MissionCompleted, GiveMissionReward, WasFactionBetrayed, BypassMissionCompleted, BypassLibraryMissionOffer, BypassSetLibraryMissionState, SetLibraryMissionState, HeardBriefing, SetGreetingHeard, GetGreeting, GetAcceptedMissionCount, GetSubvertedMissionCount, SetWinningFaction, GetWinningFactionPerAct, GetWinningFaction, AddMovieSequenceToUnload, NewJackalTapeFound, PartnerTapeFound
CDynamicEnvironmentManager16SetDepthOfFieldOverride, RemoveDepthOfFieldOverride, SetFogOverride, RemoveFogOverride, SetCloudOverride, RemoveCloudOverride, SetWindOverride, RemoveWindOverride, SetLightingOverride, RemoveLightingOverride, GetScriptedTimeOfDay, SetScriptedTimeOfDay, SetScriptedStormFactorOverride, RemoveScriptedStormFactorOverride, SetAdaptiveBloomOverride, RemoveAdaptiveBloomOverride
CDominoManager10SpawnDominoEntity, RemoveDominoEntity, RemoveCommandEventToEntity, SendCommandEventToEntity, SendCommandEventToEntity2, QueueCommandEventToEntity, QueueCommandEventToEntity2, SendRegisteredEventToEntity, TraceConnection, IsScriptAutorunEnabled
CGameMessageBoxHelper8CreateConfirmationMessageBox, CreateTutorialMessageBox, CreateCustomTutorialMessageBox, CreateFloatingTutorialMessageBox, CreateTutorialMessageBoxWithActionMap, CreateCustomTutorialMessageBoxWithActionMap, CreateFloatingTutorialMessageBoxWithActionMap, HideFloatingTutorialMessageBox
CScriptCallbackSystem8RegisterEventCallback, RegisterOnSpawnCallback, RegisterOnRemoveCallback, RemoveCallback, RemoveCallbacks, RegisterMessageListener, UnregisterMessageListener, BroadcastMessage
CFCXBarkManagerService4LoadMissionBarkBank, UnloadMissionBarkBank, RegisterMissionBankLoadedCallback, UnregisterMissionBankLoadedCallback
CBaseMission5IsEnabled, one unnamed-string-literal binding, Enable, Disable, SetState
CDominoDelayManager4CreateDelay, RemoveDelay, SetDelay, SendCommand
CDominoConsoleCommandManager2RegisterConsoleCommand, UnregisterConsoleCommand
CDominoSequenceManager2CreateListener, DeleteListener
CDominoBoxResource2RegisterBox, LoadResource
CDominoBoxInstance2CreateBox, GetParentEntity
CMusicManager3SetWorld, ChangeSet, PlayMusicFromLua
CDominoSoundManager1PlaySound
CMovieSystem1CommandSequence
CGameMissionMgr1GetMission
CFCXRegionManager1IsSafeHouseLocked
CFCXObjectiveHudManager1PushNewObjective
CDominoWaterLevelManager1SetWaterLevel
CTerrain1GetSector
CSector1SetWaterLevel
CEntityComponent1GetEntity
CVehicle1GetCurrentVehicle
CFCXGameplayManager1SetMapArmy
CJackalTapeManager1StopTape

Each of these manager classes also exposes a much larger set of plain data properties (not functions) through a separate, parallel reflection mechanism (FUN_1029b000/property-descriptor structs with GetNameHash("PropertyName", ...), visible interleaved in the same registration functions — e.g. CFCXMissionManager also exposes CurrentAct, MissionTime, InfMinCoefficient, etc. as readable/writable fields). Those are not listed here, but are readable from the same decompiled registration functions.

Writing Lua for the engine​

What the embedded Lua 4.1 (alpha) means for a script, all met while writing a scripted knockdown (seen in game):

  • There are no booleans. true and false are ordinary global names, so both are nil; true passed to a function arrives as nil. Only nil is false: 0 is true. A function that has to choose between two behaviours is clearer as two functions.
  • There is no pcall. The engine runs Domino callbacks in its own protected call, so an error in one is reported and the game goes on.
  • Bindings check the type. SetScriptedDeath (0x088A5210) acts only when given exactly one argument whose lua_tag is a number, so SetScriptedDeath(1) works and SetScriptedDeath(true) does nothing.
  • A callback object needs a _type. The engine calls back into a table passed to RegisterEventCallback or CDominoDelayManager:CreateDelay as Domino boxes are built, through the table's _type. A plain table must point _type at itself (T._type = T); without it the callback fails with "attempt to index a nil value" and the game exits (seen on GOG at Dunia.dll+0x2BE795).

Unknowns​

  • One registration call site (0x10738c38) sits outside any function Ghidra has identified as a Function object — needs a manual Disassemble+Create-Function pass in the GUI before it's readable via MCP. Every other one of the ~260 sites is covered above.