Skip to main content

Demo recording and playback

Verified via reverse engineering

The recorder, its key binding and the three file layouts are traced in Dunia.dll and checked against the two demos FC2BenchmarkTool.exe ships. See the overview for binary identification.

Tried in a running game

GOG v1.03. Firing toggle_recording as an action started and stopped the recorder, which wrote all three files. Numpad 8 itself was not pressed. Actions fired from outside the terminal's list, as DevTools' are, are not in the .npl.

-benchmark playback with the shipped demo loaded at the demo's first position and quit cleanly about 10 s after launch, without the run being seen to play. Why was not looked into.

The benchmark's two "Playback" demos, Action Scene and Demo Ranch, are not camera paths. They are input recordings made in ordinary gameplay by a recorder that is still in the retail engine: a save of the starting state, the player's input actions frame by frame, and the player's transform frame by frame.

Recording​

The input signal toggle_recording (CRC32 0x72543291) starts and stops the recorder. Retail data binds it in the common_system action map of config\inputactionmapcommon.xml, next to the QA dump keys:

<Binding input="kb:numpad8" action="press" signal="toggle_recording"/>

The input handler (at 0x1071b485) compares the signal against that hash, passes two further checks that are not identified, and calls the toggle FUN_1067b6f0. The toggle does nothing unless the byte DAT_10f9a2b8 is set; it is 1 in the shipped image, and only playback mode clears it.

Starting a recording shows Recording Playback... on screen and writes three files with one base name, Playback YYYY-MM-DD HH-MM-SS, under <dir>\Benchmarks\Playbacks\, where <dir> is the path string at DAT_10ff0e94 + 0x94. Playback resolves demo names through GameFileUtils::GenerateRelativeFileName mode 1, Benchmarks\Playbacks\, the same function that puts saves under Documents\My Games\Far Cry 2\, so both are expected to meet in Documents\My Games\Far Cry 2\Benchmarks\Playbacks\:

FileWrittenContents
.bsavonce, at the starta save of the current game state
.nplevery framethe input actions fired that frame
.pplevery framethe player's position and two angle triples

Pressing the key again stops the recording, and that press is itself recorded as the last entry in the .npl. The recorder also stops itself from the game-mode update and from the per-frame recording handler, under conditions that are not identified.

Playback​

-benchmark playback loads a demo by its base name:

FarCry2.exe -benchmark playback -world world1 -benchmarkinputname "<name>"

-world is required only to pass the harness's usage check. The other benchmark flags (-benchmarkloop, -benchmarkfixedframerate, -benchmarkdisableai) apply as usual. FC2BenchmarkTool.exe names its demos Demo_CPU and Playback_Demo, and carries both as embedded .NET resources (Benchmark.Demo_CPU.bsav and so on).

Playback setup (FUN_1067ba60) clears the recording gate, opens the .ppl for reading and hands the .npl to its reader. On each playback event the per-frame handler (FUN_1067be90) reads one .ppl record and writes it back onto the player: position through the entity, the two angle triples into the pawn's data at +0x38 and +0x44. The player is therefore held on the recorded path, while the .npl supplies what the player did.

Where a demo meets the input​

0x104F1440 is the terminal's input pass, __thiscall with two stack arguments (RET 8). Each frame it has the action map turn raw input into a list of CActionValues, 0x14 bytes each. If the recorder is on it writes the list to the .npl (0x10587540); if a demo is playing it adds that frame's entries to the list (0x10587770). Then it hands every entry to the object at the terminal's +0x0C, through that object's first virtual method, with a flag that is true unless the terminal changed mode during the pass.

So an action fired at that object after the pass reaches the same listeners a binding does. mods/DevTools/src/engine/actions.cpp does this, for DevTools' remote control.

.bsav​

The first two sections of a .sav, followed directly by the embedded .fcb (FCbn at 0x57 in both shipped demos). There is no thumbnail.

OffsetSizeValue in both shipped demos
0x004u32 10
0x044u32 0x63af73f3
0x08123 floats, the start position (matches the first .ppl record)
0x144+6length-prefixed "world1"
0x1E4+13length-prefixed "Marty_Alencar"
0x2F123 × u32: 1, 0, 1

.npl​

u32 frameCount rewritten when the recording stops
f32 unknown 449.94 in Demo_CPU, 1372.31 in Playback_Demo
frame[frameCount]:
u32 entryCount 0 for a frame with no input
entry[entryCount]:
u32 signal CRC32 of the action-map signal name
u32 type 1 = one f32 follows, 2 = two f32 follow
f32 value[type]

Both shipped demos parse to the last byte with this layout, and their frame counts match the header. The signals they contain:

SignalDemo_CPUPlayback_Demo
look (type 2)606748
move (type 2)5846
startshooting / stopshooting–2 / 2
cycleweapon–2
throw_grenade22
toggle_recording11

.ppl​

A flat array of 36-byte records, one per frame, no header: frameCount - 1 records in both shipped demos.

OffsetSizeField
0x0012position (3 floats)
0x0C12angle triple, pawn data +0x38 (+0x54 when bit 4 of its flags is set)
0x1812angle triple, pawn data +0x44

Unknowns​

  • Whether Numpad 8 reaches the handler in retail, since the common_system map may not be active, and what the handler's two extra checks test.
  • Why -benchmark playback quit without playing the demo in the one launch tried.
  • What the 30 fps lock does while recording or playing. Both starts call 0x1029B250 with 30, -1, the value the -benchmarkfixedframerate lock uses.
  • How faithfully AI, physics and other randomness replay. Only the player is held to the recording.
  • The .npl header float, the .bsav u32 at 0x04, and what separates the two angle triples.