Skip to content

Event System

Kevin Bonnoron edited this page Nov 21, 2026 · 1 revision

Event System (cutscenes)

How scripted scenes run: the event manager and its sub-managers, the BDAT tables that describe each event, the command sequencer, the script commands (camera, character, effect, text), skipping and scrubbing, facial animation, depth of field, and how events connect to the game layer and to field gimmicks (Field-Gimmicks). Namespace event, folders src/application/BF2/event/ (E/ below), plugin/ (P/), rcha/ (R/), plus gf/game/event/ (GE/) and gf/data/ (GD/). Reading guide: Home. Snapshot: main at commit a313ecb66.

Coverage. About 5,465 of 5,741 event and gmk functions are matched. The big gaps in this area are the event manager's constructor and the body of the event loop (SeqManager::exec::update), the scene setup and start functions, the frame manager's update and the character command updates. They are listed at the end. Members named unknownXX carry inferred roles; the page says "inferred" when it leans on one.

Structure

  • event::Manager owns up to 64 sub-managers (FixedVector<IManager*, 64>) and forwards each phase to all of them (Manager::execMessage(MSG_TYPE)). There are 54 IManager subclasses: camera, character, object, frame, skip, text, todo (undo/redo), sequencer, resource, depth of field, environment, hide, quest, status, voice, BGM, SE, volume, movie, UI and others (E/*_manager.h). The constructor that registers them is not decompiled yet.
  • Phases broadcast to every sub-manager (MSG_TYPE, E/i_manager.h; values 1 to 4 and the stop/clear pairs are visible in Manager, the other labels are inferred from use): init begin (1), init load (3), init (4), setup scene (5), setup scene end (6), start scene (7), start page (8), end scene begin (9), end scene (10), stop (11), clear (12), clear post (13), update (14), update post (15), render (16), render post (17), tail (18), tail post (19).
  • Manager::update sends 14 then 15. When the sequencer's front command is the "play next" command, it sends 12 and 13 and calls clear(); if the sequencer reports a script load error (flag bit 0), the event ends with message 2. Manager::end() sends 11 once and returns false while the init-state bit 0 is set.
  • Memory and time. The event memory pool is 0x2300000 bytes (35 MiB) named "GfTalk", created in GfGameEvent::initialize. Event time runs at 30 frames per second (Manager::drawInfo computes minutes as frame / 1800 and seconds as frame % 1800 / 30). Manager::bkgHomeMenu pauses the CPU manager while the HOME menu is open.
  • Event scripts are .sb files named after the event (Manager::failureSkip prints failure skip!! [<name>.sb]). play_start creates script slot 2 from that name (SCOM_SCRIPT::create(2, name, false)) and raises the error flag if loading fails.
  • File suffixes the event resource helper appends (Extend, E/extend.cpp): .wimdo models, .arc, .anm, .eva and _eff.eva animations, .wiefb effects and _pack.wiefb, .wilgt lights, .nop and .acb audio, .lip and .wilip lip-sync, .evpa event packs, .sar, .webm movies. ResManager holds up to 512 items with up to 96 listeners each; a pack (.evpa) is loaded through fw::RenderResource::request and normal loading is held back while a pack loads.

From event id to scene: the BDAT tables

  • Lookup. SeqInfo::setup(id) (E/seq_info.cpp) iterates the EVT_listList sheet, reads the column listSeat (a sheet name per row), opens that sheet and finds the row whose id range contains the event id, then reads evtName. If the row's linkID is non-zero (and the event is not debug-played once), GfGameEvent::play appends _link to the event name.
  • Event id ranges (GfDataEvent, GD/gf_data_event.cpp): scenario events start at 10001 (604 ids), Blade-creation events at 19001 (58), Blade-quest events at 20707 (504). The event lists are the BDAT sheets EVT_LIST_BF, _BL, _QST01, _FEV01 and _TLK01. Save-worthy scenario events are a hard-coded list of about 230 ids (10001 to 10494).
  • Played flag. When the "event play end" notice fires, GfGameFlag::setLocal(1, 0x8a5f + index, 1) records that the event was played (up to 2000 flags, 100 per list); the index formula as written looks odd (top - event + list * 100) and is not explained. See Save-Data for the flag store.
  • Per-event columns read by SeqInfo::setup: state changes (chgStID, chgEdID), category, text (mstxt, text), weather, clock, clockStop, cloud; fades (opFadeOutEnable, opFadeOut, opFadeWait, opFadeInEnable, opFadeIn, opFadeColR/G/B and the ed* set); formations and BGM (stFormID, edFormID, opBgm, edBgm); hiding (hideNpc, hideEne, hideMob, hideMap); "outsiders" (outsiderOpt, outsiderEnable, outsiderType, outsiderX/Y/Z/R); chaining (nextID, linkID) and misc (jijiDisp, wpnDisp, colFilterNear, colFilterFar, voice). Optional, only when the column exists: nextIDtheater, envSeam, evtLight, hood (default 1), cssnd, centerForm, centerID, centerX/Y/Z, centerR (degrees, converted to radians). If the manager asks for a forced end fade and the row has none, the end fade becomes: out time 20, wait 0, black.
  • Categories. The category column indexes NONE, TEV, FEV, SEV, CS, MOV (0 to 5). Category 4 (a cutscene) mutes the SE categories with a 0.5 s fade while it plays (GfGameEvent::updateCsEventCategoryVolume). Category 1 does not freeze the field; other categories freeze game-object layers 3, 4 and 10 (ignoring event objects) and set event speed layer 1 to 0 (GfGameEvent::eventPlayerOff). Category 5 is inferred to be "capture" (SeqManager::checkCapture tests the linked event's category).

The sequencer

SeqManager (E/seq_manager.cpp) runs a CmdQueue<32> of commands. Each command returns wait (0), done (1) or next (2, run the following commands in parallel) (CmdQueue::update, E/cmd_queue.h); the queue drops its oldest item when full. The phases are fields of SeqManager:

  • Start side: play_start, play_next, start, start_fadeout, start_areajump, start_notice, start_loading, start_other, start_form, start_change, start_env_seam, start_weather, start_streaming0/1, start_capture_wait.
  • Body and end side: exec, exec_fadeout, exec_grass, end_change, end_eff, end_stream, end_wait, end_areajump, end_env_seam, end_fadewait, end_fadein, end_notice, end.

What the matched phase commands do:

  • start_notice, end_notice and end_wait call GfEvent::callEventPlay with the codes "event end wait" (8), "event end" (9) and "event play end" (10): the game layer is told through them (see below).
  • start_other creates "other%d" and "other_bl%d" copies of party drivers and Blades 1 to 3 when the object manager has fewer characters than requested, and waits for them to load.
  • start_weather applies clock, clockStop, and weather / cloud only when greater than 0 to EnvManager.
  • start_streaming0 (category 2 or above) reads the first seam point (seamless), then waits for movies, models and motions, and the CS sound to load unless fast skip is active. It waits at least 2 frames for capture events and while the seam map is reading or middle textures stream (each capped at 900 frames) and, if a flag is set, until gimmicks have finished popping (capped at 900 frames; see Field-Gimmicks).
  • start_areajump / end_areajump request a map jump (GfReqCommand::reqMapjump) and wait until it is done; start_change / end_change apply StatusManager::changeFromBdat(chg*ID) (end_change first plays a 30-frame event fade unless skipping).
  • exec_fadeout requests fade type 2 and a seamless volume fade, or a 30-frame skip fade when skipping. exec_grass is a "glass break" transition that runs until a given frame and fades in black on the end frame.
  • checkWait3D is true when play parameter 2 (the Blade id) and linkID are both 0; checkSyncBgm is false when the end fade-out is set or nextID == 0.

Not decompiled: SeqManager::exec::update (the event body loop, 0x710012b90c, 15,216 bytes), init (2,980), setupScene (6,068), startScene (8,764), end (2,212) and event::Manager::Manager (0x71001388c4, 9,728 bytes).

Script commands (plugins)

  • pluginRegist() (P/plugin_regist.cpp) registers the script command groups in order: builtin, thread, bdat, menu, aidata, wait, deb, sys, fld, party, ui, then about 20 event groups (Obj, Setup, Chara, Cam, Eff, Lgt, Post, Text, Sel, Status, Bgm, Se, Vol, Rand, Pay, Env, Mov, Map, Ui, Voice), then the battle AI group and the gimmick group. Only this registry and the camera, character, effect, object and text commands are defined in the source.
  • Each command is a factory that returns an ITodo (doit, undo, redo, a command name). Camera: CamMotion, CamPos, CamMovePos, CamTar, CamMoveTar, CamFov, CamMoveFov, CamRotZ, CamMoveRotZ, CamNearfar, CamCut, CamFollowPos, CamFollowTar. Character: CharaWalkPos, CharaLinerPos, CharaTurnRot, CharaLinerRot, CharaTgt, CharaSetIdle, CharaAction, CharaMotion, CharaMotionABC, CharaHead, CharaFacial, CharaTalk, CharaWink, CharaMount, CharaFade. Effect: EffectPlay, EffectCast, EffectMount, EffectKill, EffectAnim, EffectMove, EffectTurn, EffectScale, EffectColor. Object and text: SetActive and PlayText.
  • Commands act on the "active object" set by ScriptSetActive; objects form a tree (types inferred: tree, character, camera, effect, light), and most commands do nothing when the active object has the wrong type.
  • Undo and scrubbing. TodoManager keeps up to 128 TodoItems, each stamped with the frame it ran at. add executes at once and discards the redo tail; undoredo(frame, ...) rewinds or replays to a frame. This is how event scrubbing (skip left/right, FrameManager::shiftLeft/Right) works. The list is cleared on scene start and page change.
  • Script parameters. Param has 10 variables, CmdParam 11. Types: s32, f32, bool, string, user data; mixed int and float reads convert.
  • Placement. DataManager keeps a source and destination matrix pair per scene (setOffsetSrc/Des), so a scene authored once can be replayed at any world position and heading. PosAxis is the position reference of a script position (axes inferred: position, global position, "say" (the talker), character).
  • Easing curves (Curve::getValue, E/curve.cpp): 0 step (1.0 only at rate 1), 1 linear, 2 ease in-out Bézier (0,0,1,1), 3 ease-in (0,0,0.1,1), 4 ease-out (0,0.9,1,1), 5 weak ease-in (0,0,0.66,1), 6 weak ease-out (0,0.33,1,1). AnmBase is a keyframe base with up to 16 keys.

Frame, skip, text, quests

  • FrameManager tracks the current frame, a max frame (default 1000) and the skippable total. There are 17 pause types (inferred roles: wait, skip, select, quest, common UI, field skill, shop, payoff, reward, random talk, the special Blade pair's UI, minigame, new-game wait, two "stop 3D" types and a game-layer pause); pause() also requests a game pause for some of them and forwards the state to the sound, voice, movie and CPU managers. shiftFrame seeks to a key frame (up to 512 key frames with a cut flag).
  • SkipManager has flags for skip, skip volume and fast-skip enable. skip(true, frame) stops the movie and remembers an end frame (default 99999 when negative); it clears itself when the timeline reaches it.
  • Text (TextManager::play, E/text_manager.cpp): returns at once on fast skip or failure skip or when the text sheet is not loaded. Text comes from the event's message sheet (MstxtManager::getSeatID(label), getText(label)); a caption flag chooses caption or window. In "replace" mode the first two characters of the label are replaced by a name and the last character is set to 1 or 2 by mtRand(2). Labels ending in h pick a voice variant by StatusManager::getHomuriFlag(). A window text with life >= 1 locks the timeline at frame + life - 1 until the text has finished writing; delay, life and "delayBack" drive show, hide and stop, and the talker also gets auto-action, auto-talk and talk commands.
  • Random talk (RandCalc, E/rand_calc.cpp): from the FLD_randomTalk sheet it keeps rows whose type matches, drops rows whose talk0 / talk1 character is not in the scene, and picks one with mtRand(count); the timeline is paused with type 9 while it plays.
  • Quest and mercenary hooks: QuestManager::entry/setComp/disp pause the frame manager with type 3 while the quest UI is active; MercenariesManager::entryable sets mission flag 1 and finish creates SCOM_MISSION_COMPLETE.

Camera, depth of field, rcha

  • Focal length to field of view (CamUtil::toFov / toFocal): a 25.39 mm film width, fov = 2 * atan(25.39 / (2 * focal)) in degrees. EVT_nearfar is read by id (name, near, far).
  • CamManager holds up to 8 CamObj and 4 CamInterfaces. A CamObj has a field-camera mode, a script camera and a motion camera; defaults near 0.1, far 40000, FOV 40, roll 0. Each update pushes position, target, roll, FOV (clamped to a minimum of 5 degrees) and near/far into the interface, only while the stream delta is above 0 and not in free camera. Camera motions are .eva files.
  • Depth of field (DofManager, sheet EVT_dof): columns dist, range, pixel, lens, strength, blend, pixelLv, hlv, name; the simple mode reads foMin instead of dist and range. Defaults with no DOF: axis 1, range 5, focus minimum 0.1, pixel 5, lens 0.6, strength 4, blend 1. Axis 1 is the camera, axis 2 the current talker, axis 3 and above are character axis - 3; for a character the distance is camera-to-eye distance times the cosine against the camera direction.
  • rcha (animation tracks baked into resources): RchaNode has 48 tracks whose names are hashed with 32-bit FNV-1 (offset basis 0x811c9dc5, prime 0x1000193, up to 128 characters). RchaCam has 30 slots: translation, rotation and order, near, far, FOV, depth of field (enable, distance, range, pixel, lens, strength, blend, pixel level, hlv), motion blur (enable, strength, sub), shadow-map visibility, clock (enable and hour), weather (enable, type), fade, camera-light stop and near/far type. Defaults when a track is missing: FOV 30, near 0.1, far 80000, DOF distance 20, range 40, pixel 5, lens 0.6, strength 4, blend 1, blur strength 0.5, sub 0.1; the hour is clamped to 0 to 23.999998 and "enable" tracks mean "value above 0.9". CRchaEx (29 slots) carries per-character tracks (dummy, dynamics blend, weapon display and transform, mount, battle, foot effects, action id, face preset, eye type, object transform, aim target).

Characters in events

  • CharaObj embeds about 25 command objects and runs them on two 8-slot CmdQueues plus a 5-slot fade queue, with IK, dynamics, target, lens, weight, wink, effect and part updaters. Character types (inferred): 1 driver, 2 Blade, 3 NPC, 5 enemy.
  • Actions (sheet EVT_acttype; columns name, cmd0..2, stat0..2, statI): a play runs cmd0, starts state stat0, loops stat1, and finishes when stat2 reaches statI; life 0 or below loops forever; blend-in is disabled while skipping. Action row 22 (ACT_BATTLE) calls the weapon battle command for model types 0, 1, 2 and 5.
  • Idle, head, brow, eye, lip, wink have their own sheets (EVT_idletype, EVT_headtype with stat, name, blend, weight; EVT_browtype, EVT_eyetype with disableWink, EVT_liptype with disableTalkLip, EVT_winktype). Facial animation is built from weighted animation layers by CharaWeightPlayer (up to 12 simultaneous items). The facial asset of a character is found through CHR_Dr.EventAsset (drivers), CHR_Bl.EventAsset (Blades) or RSC_NpcList.EventAsset (NPCs), whose value indexes EVT_assetList (facialSeat, lensID). EVT_lens gives eye-lens limits (thMin/thMax/tvMin/tvMax scaled by 0.001, rhMin/rhMax/rvMin/rvMax in degrees).
  • Blinking (CharaWinkPlayer): idle blink every mtRand(60) + 90 frames (90 to 149); eyes stay closed 7 frames with a 4-frame blend.
  • Looking at a target (sheet EVT_aimmottype, 6 aim motions: up, down (non-spine), up, down (spine), left, right): CharaTarUtil::calcWeight turns the direction into yaw and pitch relative to the character's facing, wraps to ±π, clamps pitch to ±30° and yaw to ±90°, and normalises both to -1..1; CharaTarPlayerMot::update adds those as weights.
  • Walking (CharaWalkCalculator): accelerate, cruise, decelerate. Blend frames: walk 10, run 20. Top speed per frame: walk 0.056, run 0.259. Acceleration length at frame f is top * f / blend.
  • Scheduler: hand-offs between field and event for NPCs and party characters: field to event, event to idle, event to field (Scheduler::setup/play); NPCs additionally get turn, return, and (when holding an item) fade and item steps.

Link to the game layer

  • GfGameEvent owns the event manager, 128 event models (FixedList<GfEvtModel*, 128>), event BGM and SE. Each frame: manager->update(); tail(); render(); then the objects and BGM.
  • Notifications use GfEvent (up to 32 listeners): GEV 1 to 7 for the area jump steps, 8 to 10 event end wait, event end, event play end, 11 and 12 sequence start and end, 13 start frame, 14 and 15 player control free and lock. On code 9 the game enters the "play" state and takes control from the player; on 10 it sets the played flag, gives control back and runs GfPlayFactory::createEventAfterScript; on 11 it enters the "sequence" state; on 12 it resets the fade-in time (wait 0 s, fade 0.5 s by default) and clears temporary weather. gf::GF_STATE has 25 game states (for example 4 talk, 7 wait event, 14 map gimmick, 20 event, 22 chain attack, 23 arts movie).
  • Hiding. The event can hide world content by class: 26 display classes (EVTDISP_*, map 1, PC 3, Blade 4, enemy 5, NPC 6, mob 7, field object 9, PC weapon 10, enemy weapon 12, collection 16, salvage 17, precious 18, treasure box 19, jump 22, warp 23, damage effect 24, damage SE 25). Classes 16 and above go to gimmick types (GfGameUtil::setDispByGmkType); lower classes are applied per object with an event-hide id list of up to 1024 ids (type << 16 | bdat id). Individual gimmicks can be hidden by BDAT id and are restored when the scene ends (HideManager). OutsiderManager hides non-event actors and can hide a spherical area (defineFld).
  • Gimmicks start events: GmkEvent::beginEvent calls GfPlayFactory::createOneEventForGimmick; GmkKizunaTalk::onPlayerAccessed calls createOneEvent; GmkMapJump calls createMapjump (see Field-Gimmicks).

Not decompiled yet (notable)

Event manager core: Manager::Manager, SeqManager::exec::update, startScene, setupScene, init, end, start_form::update. Timing: FrameManager::update (0x7100125b40, 2,468), shiftLeft, shiftRight (2,876), TodoManager::insert. Camera: CamEvaPlayer::update (2,584), getCamLook_roll (2,980), CamFree::getViewMatrix, ManiManager::updateManipulate (0x71001066d4, 9,124). Characters: CharaObj::CharaObj (2,368), update, initModel, initModelStream (4,608), CharaPlayEva::update, CharaWalkPos::update, CharaWalkCalculator::calcPos, CharaSetTar::update, the talk, wink and facial play functions. Objects, resources and status: StatusManager::change (0x71000f7294, 7,344), SelectManager::play, BgmManager::play/update/clear, FormManager::replace, MdlstmData::getReplaceInfo.

See also

Field-Gimmicks, Engine-Overview, BDAT-Data, Save-Data

Clone this wiki locally