GithubHelp home page GithubHelp logo

demostf-parser's Introduction

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.

Passing the detailed_summary argument to the end of parse_demo will output a table with scoreboard information for all players who were ever on the server while the demo was being recorded. The player who created the demo will be highlighted in the output.

Advanced usage

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

demostf-parser's People

Contributors

icewind1991 avatar narcha avatar markddr avatar tails8521 avatar yep-tf2 avatar dalegaard avatar bitinha avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.