1
0
Fork 0
mirror of https://codeberg.org/demostf/parser.git synced 2026-06-03 10:14:06 +02:00
Parsing of tf2 demo files
  • Rust 99.8%
  • Nix 0.2%
Find a file
2022-04-09 18:14:13 +02:00
.github/workflows release ci 2022-01-23 14:31:47 +01:00
benches minor iai bench improvement 2021-07-18 20:16:14 +02:00
codegen generate propname mapping 2022-04-09 18:14:13 +02:00
examples add list of props 2022-04-03 15:16:08 +02:00
fuzz fixes 2020-03-05 23:34:05 +01:00
smoker smoker fixes 2020-01-29 22:53:04 +01:00
src actually cleanup instance baselines 2022-04-09 14:48:34 +02:00
test_data update expected data 2022-04-03 15:33:57 +02:00
tests Fix typos in 7 files: cased variants of sigon -> signon 2022-01-27 21:39:58 -06:00
.gitignore remove the need to allocate all messages in a packet 2020-12-06 19:30:54 +01:00
Cargo.lock 0.4.0 2022-02-09 16:16:17 +01:00
Cargo.toml 0.4.0 2022-02-09 16:16:17 +01:00
pgo_build.sh first prop flattening version 2019-08-10 19:38:42 +02:00
README.md readme 2021-07-24 16:46:12 +02:00
rustig.toml check for panicing code in ci 2019-08-11 13:57:20 +02:00
schema.json Fix typos in 7 files: cased variants of sigon -> signon 2022-01-27 21:39:58 -06:00

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()?;