Scriptable Parser for Portal 2 Demos
    Preparing search index...

    Class Demo

    Represents a parsed Portal 2 demo. Manages state and data storage.

    Index

    Constructors

    • Constructs a representation of the demo file from a byte array. Immediately after being constructed, the object will contain only the header. For accessing other data, use events.

      Parameters

      • bytes: Uint8Array

        Buffer containing demo file data.

      • Optionalevents: {
            onTick?: (demo: Demo) => boolean | void | Promise<boolean | void>;
            onCommand?: (
                demo: Demo,
                command: string,
            ) => boolean | void | Promise<boolean | void>;
            onFinish?: (demo: Demo, success: boolean) => void;
        }

        Event handlers. Aside from onFinish, each of these may be asynchronous. If that's the case, demo parsing is paused until the returned promise is resolved.

        Event handlers must return a boolean. If it's true, demo parsing continues. If it's false, parsing stops and onFinish is called with success = false.

        Available events:

        • onTick is called once per server tick. In a single player game, odd ticks are skipped due to sv_alternateticks.
        • onCommand is called every time a console command is fired or a cvar is changed.
        • onFinish is called when the demo has finished parsing.

      Returns Demo

    Properties

    demoFileStamp: string

    File header, should be HL2DEMO. However, the parser never verifies this.

    demoProtocol: number

    Demo file protocol, should be 4 for Portal 2.

    networkProtocol: number

    Network protocol, should be 2001 for Portal 2.

    serverName: string

    The game server's address (and port). For a local game, should be localhost:27015.

    clientName: string

    Connecting client's username.

    mapName: string

    Name of the map file, with the extension and path omitted. For example, Triple Laser would be sp_a2_triple_laser.

    gameDirectory: string

    Name of the "mod folder" for this game, should be portal2.

    playbackTime: number

    Duration in seconds. Not exact, often deviates from speedrun timers.

    playbackTicks: number

    Duration in ticks. Not exact, often deviates from speedrun timers.

    playbackFrames: number

    Seems to be an alternateticks-aware tick count, i.e. roughly half of playbackTicks for single player.

    signOnLength: number

    Size of sign on data in bytes.

    messages: Message[]

    Array of messages found in the demo, in order of appearance.

    User-facing interface for the current state of the demo.

    Type Declaration

    User-friendly interface for the current state of the demo.

    • tick: number

      Current server tick. Reports only even numbers on single player games due to sv_alternateticks.

    • players: CmdInfo[]

      List of Message.CmdInfo objects, one for each player. "players" might be a bit of a misnomer, as what this really tracks is the camera that the demo follows.

    • entities: Entities | null

      The primary entity interface. Holds all entities available on the current tick, as well as methods for querying them. See Entity.Entities for more information.

    Internal bitstream buffer, seeked as the demo is parsed.

    dataTables: Map<string, DataTable> | null = null

    List of raw SendTables/DataTables found in the demo, indexed by table name.

    serverClasses: ServerClass[] | null = null

    List of server-side classes reported by the demo.

    stringTables: Map<string, StringTable> = ...

    String table data, mainly from the StringTables message.

    parserClasses: ParserClass[] | null = null

    Reconstructed server classes with properties.

    baselines: StaticBaseline[] = []

    Entity baselines, i.e. the "default" properties of each entity class.