#parser #demo #tf2 #tf

bin+lib tf-demo-parser

parser for tf2 demo files

13 unstable releases (3 breaking)

0.4.0 Feb 11, 2022
0.3.3 Aug 1, 2021
0.3.2 Jul 27, 2021
0.2.6 Jul 11, 2021
0.1.0 Nov 29, 2020
Download history 15/week @ 2022-01-20 10/week @ 2022-01-27 6/week @ 2022-02-03 29/week @ 2022-02-10 22/week @ 2022-02-17 8/week @ 2022-02-24 7/week @ 2022-03-03 18/week @ 2022-03-10 81/week @ 2022-03-17 5/week @ 2022-03-24 7/week @ 2022-03-31 9/week @ 2022-04-07 9/week @ 2022-04-14 6/week @ 2022-04-21 123/week @ 2022-04-28 106/week @ 2022-05-05

244 downloads per month

MIT/Apache

740KB
18K SLoC

TF Demo Parser

Build Status

Parsing of tf2 demo files

Building

This project is build using rust and requires cargo and friends, see the rust website for how to get started.

Once rust is setup building is as simple as

cargo build --release

which will place the binary at target/release/parse_demo

Usage

Basic usage is as simple as parse_demo demofile.dem which will output a "summary" of the demo file in JSON format.

Advanced usage

Loop trough every packet

use bitbuffer::BitRead;
use main_error::MainError;
use std::fs;
use tf_demo_parser::demo::header::Header;
use tf_demo_parser::demo::parser::{DemoHandler, RawPacketStream};
use tf_demo_parser::Demo;

fn main() -> Result<(), MainError> {
    let file = fs::read("demofile.dem")?;

    let demo = Demo::new(&file);
    let mut handler = DemoHandler::default();

    let mut stream = demo.get_stream();
    let header = Header::read(&mut stream)?;
    handler.handle_header(&header);

    let mut packets = RawPacketStream::new(stream);

    while let Some(packet) = packets.next(&handler.state_handler)? {
        handler.handle_packet(packet).unwrap();
    }
    assert_eq!(false, packets.incomplete);

    Ok(())
}

Handle demo data with a custom analyser

Sometimes it's easier to create a custom Analyser to handle the demo data as it comes along.

See src/demo/parser/analyser.rs for an example.
Once you have a custom analyser you can use it with:

DemoParser::new_all_with_analyser(demo.get_stream(), CustomAnalyser::new());
let (header, state) = parser.parse()?;

Dependencies

~5.5–8MB
~152K SLoC