Skip to contents

Reads the demos of the Half-Life engine (GoldSrc): Half-Life, Counter-Strike 1.x and the other games built on it, demo protocol 5, from the engine versions of 2001 (network protocols 42 and 43) to the current one (48). A demo stores, with every network message the client received, the command the client was sending at that moment. Each such frame is one observation.

Usage

read_dem(
  path,
  analog = "raw",
  deadzone = NULL,
  triggers = "raw",
  aliases = TRUE,
  ...
)

Arguments

path

Recording file path.

analog

Stick representation: "raw" (default), "cardinal4", "cardinal8", "angle", or "angle+magnitude". A scalar applies to both sticks; c(left = "cardinal8", right = "angle") selects them independently. Cardinal modes add separate left/right logical direction columns. Continuous modes return numeric fields through stick_channels(). Original X/Y values remain in analog_channels() in every mode. Absent sticks add no columns.

deadzone

Radial threshold in centred axis half-range units, from zero to one. One value applies to both sticks; named left/right values are allowed. NULL uses the default of the controller, whichever emulator recorded it: 0.125 for the sticks of Nintendo's consoles (Nintendo 64, GameCube, Wii extensions, 3DS) and 0.25 for all other sticks. The first is close to the 15 of 128 units that the GameCube's controller library discards on each axis (PAD_Clamp in libogc). The second covers the resting position of a released PlayStation stick, up to about 32 of 128 units from the centre (psx-spx), and is close to the 7849 and 8689 of 32767 that Microsoft gives for the thumbsticks of PC gamepads (XInput). A game applies a threshold of its own, which the recording does not store; give that value to study one game. Neutral observations have no direction and an NA angle. Magnitude is kept.

triggers

"raw" (default) or "digital". For DTM, digital additionally projects each analogue trigger at 128/255 into separate L2/R2 columns. Hardware L/R click bits remain distinct from thresholded analogue triggers.

aliases

TRUE (default) places the controls of a recording under the shared IDs that button_layout() describes. With FALSE, a control that would be placed under another control's ID keeps the key of its source, so every control of the recording has a column of its own and no two are combined.

...

Reader-specific arguments, such as controller_order for M64 or DTM, or member for a recording inside a ZIP archive (see movie_members()).

Value

A replayr_movie with one player.

Details

player() returns the 16 actions of the command. They are what the game was asked to do, not keys: which key or mouse button is bound to an action is a setting of the player. The actions have action: identities of their own, shared with other games that record the same action; attack, use and jump are those of Doom-engine demos.

analog_channels() returns the movement the command asks for (forwardmove, sidemove, upmove), the view angles it asks for in degrees (view_pitch, view_yaw, view_roll), the impulse number, the selected weapon and the duration of the command in milliseconds (msec). The view angles are the player's aim as the client sends it: their change from one observation to the next is the turning asked for with the mouse or the turn keys. The game can also set them, for example when the player respawns.

movie$timing gives for each observation its section, the seconds and the frame number the demo stores (both count anew in every section), and whether it is a start frame of the loading section. Two network messages can arrive in one frame; they are two observations with one frame number. observation_time() runs on from section to section. movie$sections lists the sections of the demo, and movie$console_commands the console commands it recorded, among them the key actions (+jump, -jump).

A demo recorded by a broadcast proxy (HLTV) holds no commands of a player: every command in it is empty. The reader says so in a warning and in movie$header$playerCommands. A demo that was not closed or was cut short is read up to its last complete frame, with a warning. Demos of demo protocol 4, which the engines of early 2001 wrote, store no command with their frames and are refused. Quake and Source engine demos share the extension .dem and are other formats.

Examples

path <- system.file("extdata", "computers", "goldsrc-moves.dem", package = "replayr")
movie <- read_dem(path)
colSums(player(movie))
#>     action_attack       action_jump       action_duck    action_forward 
#>                 3                 4                 4                17 
#>       action_back        action_use     action_cancel  action_turn_left 
#>                 0                 0                 0                 0 
#> action_turn_right  action_move_left action_move_right    action_attack2 
#>                 0                 0                 4                 0 
#>        action_run     action_reload       action_alt1      action_score 
#>                 0                 0                 0                 0 
head(analog_channels(movie)[, c("forwardmove", "view_yaw")])
#>      forwardmove view_yaw
#> [1,]           0        0
#> [2,]           0        0
#> [3,]         400       90
#> [4,]         400       90
#> [5,]         400       90
#> [6,]         400       90