21 releases (4 breaking)

✓ Uses Rust 2018 edition

new 0.6.0 Nov 7, 2019
0.5.0 Sep 8, 2019
0.3.4 Jun 6, 2019
0.2.5 Sep 6, 2018
0.2.2 Mar 18, 2018

#25 in Parser tooling

Download history 10/week @ 2019-07-25 57/week @ 2019-08-01 81/week @ 2019-08-08 22/week @ 2019-08-15 29/week @ 2019-08-22 176/week @ 2019-08-29 137/week @ 2019-09-05 39/week @ 2019-09-12 314/week @ 2019-09-19 44/week @ 2019-09-26 86/week @ 2019-10-03 38/week @ 2019-10-10 222/week @ 2019-10-17 142/week @ 2019-10-24 76/week @ 2019-10-31

464 downloads per month

MIT license

175KB
3.5K SLoC

Boxcars

Build Status Build status Version

Looking for rrrocket (the commandline app that parses replays and outputs JSON for analysis)? It recently moved

Boxcars is a Rocket League replay parser library written in Rust, designed to be fast and safe: 10-100x faster than established parsers. Boxcars is extensively fuzzed to ensure potentially malicious user input is handled gracefully.

A key feature of boxcars is the ability to dictate what sections of the replay to parse. A replay is broken up into two main parts: the header (where tidbits like goals and scores are stored) and the network body, which contains positional, rotational, and speed data (among other attributes). Since the network data fluctuates between Rocket League patches and accounts for 99.8% of the parsing time, one can tell boxcars to skip the network data or ignore errors from the network data.

  • By skipping network data one can parse and aggregate thousands of replays in under a second to provide an immediate response to the user. Then a full parsing of the replay data can provide additional insights when given time.
  • By ignoring network data errors, boxcars can still provide details about newly patched replays based on the header.

Boxcars will also check for replay corruption on error, but this can be configured to always check for corruption or never check.

Serialization support is provided through serde.

Below is an example to output the replay structure to json:

use boxcars::{ParseError, Replay};
use std::error;
use std::fs;
use std::io::{self, Read};

fn parse_rl(data: &[u8]) -> Result<Replay, ParseError> {
    boxcars::ParserBuilder::new(data)
        .on_error_check_crc()
        .parse()
}

fn run(filename: &str) -> Result<(), Box<dyn error::Error>> {
    let filename = "assets/replays/good/rumble.replay";
    let buffer = fs::read(filename)?;
    let replay = parse_rl(&buffer)?;
    serde_json::to_writer(&mut io::stdout(), &replay)?;
    Ok(())
}

Benchmarks

To run the boxcar benchmarks:

cargo bench

# Or if you want to see if compiling for the
# given cpu eeks out tangible improvements:
# RUSTFLAGS="-C target-cpu=native" cargo bench

Since Boxcars allows you to pick and choose what to parse, below is a table with the following options and the estimated elapsed time.

Header Corruption Check Body Output JSON Elapsed
258 µs
18.5ms
18ms
93.5ms
93ms

Special Thanks

Special thanks needs to be given to everyone in the Rocket League community who figured out the replay format and all its intricacies. Boxcars wouldn't exist if it weren't for them. I heavily leaned on implementations in rattletrap and RocketLeagueReplayParser. One of those should be your go to Rocket League Replay tool, unless you need speed, as those implementations are more mature than boxcars.

Difference between rattletrap and boxcars

  • Rattletrap is a binary that ingests rocket league replays and outputs JSON, while boxcars is a lower level parsing library. Boxcars underpins Rrrocket, a cli binary that outputs JSON similar to Rattletrap
  • Rattletrap can roundtrip replays (convert them into JSON and then write them out back to a replay losslessly). Boxcars is focussed on parsing replays.
  • In part due to allowing roundtrip parsing, rattletrap JSON output is 2x larger than boxcars (rrrocket) even when accounting for output minification.

Below are some differences in the model:

rattletrap:

"properties": {
  "value": {
    "BuildID": {
      "kind": "IntProperty",
      "size": "4",
      "value": {
        "int": 1401925076
      }
    },
  }
}

boxcars:

"properties": {
  "BuildID": 1401925076
}

rattletrap:

"actor_id": {
  "limit": 2047,
  "value": 1
},

boxcars:

"actor_id": 1

rattletrap:

"value": {
  "spawned": {
    "class_name": "TAGame.GameEvent_Soccar_TA",
    "flag": true,
    "initialization": {
      "location": {
        "bias": 2,
        "size": {
          "limit": 21,
          "value": 0
        },
        "x": 0,
        "y": 0,
        "z": 0
      }
    },
    "name": "GRI_TA_1",
    "name_index": 0,
    "object_id": 85,
    "object_name": "Archetypes.GameEvent.GameEvent_Soccar"
  }
}

boxcars:

"actor_id": 1,
"name_id": 1,
"object_id": 85,
"initial_trajectory": {
  "location": {
    "bias": 2,
    "dx": 2,
    "dy": 2,
    "dz": 2
  },
  "rotation": null
}

While rattletrap provides convenience conversions, boxcars omit them in favor of a more raw view of the replay:

  • to derive object_name: replay.objects[x.object_id]
  • to derive name: replay.names[x.name_id]

The raw formula for calculating x,y,z from dx, dy, dz, and bias is:

x = dx - bias
y = dy - bias
z = dz - bias

So:

"location": {
  "bias": 4096,
  "dx": 6048,
  "dy": 1632,
  "dz": 4113
},

Would translate into

x: 1952
y: -2464
z: 17

Attribute updates:

rattletrap:

{
  "actor_id": {
    "limit": 2047,
    "value": 7
  },
  "value": {
    "updated": [
      {
        "id": {
          "limit": 98,
          "value": 34
        },
        "name": "Engine.PlayerReplicationInfo:PlayerName",
        "value": {
          "string": "Nadir"
        }
      }
    ]
  }
}

boxcars:

{
  "actor_id": 7,
  "stream_id": 34,
  "object_id": 161,
  "attribute": {
    "String": "Nadir"
  }
}

To derive rattletrap's name for the attribute use replay.objects[attribute.object_id]

Fuzzing

Boxcars contains a fuzzing suite. If you'd like to run it, first install cargo-fuzz

cargo install cargo-fuzz

There are several scenarios to fuzz (cargo fuzz list), and the best one to run is no-crc-body, due to all aspects of the replay being fuzzed without a crc check:

cargo +nightly fuzz run no-crc-body

Dependencies

~5.5MB
~162K SLoC