sdp

Deno CI Release CD npm

sdp

Simple Source Engine demo parser. Try it out on StackBlitz!

Features

Examples

Read header only

Using Deno + TypeScript:

import { SourceDemoParser } from 'npm:@nekz/sdp';

const demo = SourceDemoParser.default()
    .setOptions({ messages: false })
    .parse(Deno.readFileSync('demo.dem'));

console.log(demo);

/*
    SourceDemo {
    demoFileStamp: 'HL2DEMO',
    demoProtocol: 3,
    networkProtocol: 15,
    serverName: 'localhost:0',
    clientName: 'Can\'t Even',
    mapName: 'testchmb_a_00',
    gameDirectory: 'portal',
    playbackTime: 3.944999933242798,
    playbackTicks: 263,
    playbackFrames: 253,
    signOnLength: 80641,
    messages: [] }
*/

Read UserCmd messages

Using Node + JavaScript:

import fs from 'node:fs';
import { DemoMessages, SourceDemoParser } from '@nekz/sdp';

const demo = SourceDemoParser.default()
    .setOptions({ userCmds: true })
    .parse(fs.readFileSync('demo.dem'));

const IN_JUMP = 1 << 1;

const registeredJumps = demo
    .findMessages(DemoMessages.UserCmd)
    .filter(({ userCmd }) => userCmd.buttons & IN_JUMP);

console.log('registered jumps:', registeredJumps.length);

/*
    registered jumps: 270
*/

Jump Stats

The examples directory contains more examples for Node and Deno.

View Origin

showcase.gif

Used in nekz.me/parser. Updated example can be found in examples/parser.html.

Credits

inolen/bit-buffer for BitStream and BitView. I ported it to TypeScript because Deno cannot bundle npm specifiers and any other bundler is not good enough. Also this port significantly improves typings which means less errors etc.

License

MIT License