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

    Class DemoBuffer

    Internal demo buffer. Implements various bitstream read/write tools.

    Index

    Constructors

    Properties

    bytes: Uint8Array

    File byte buffer.

    cursor: number = 0

    Bit (not byte!) cursor, indicating where the "read head" is. All next* methods increment this value when reading.

    Methods

    • Reads the value of the bit at the given position.

      Parameters

      • at: number

        Absolute bit address.

      Returns number

      Bit value - 0 or 1.

    • Reads one unsigned byte (8 bits) starting from the given position.

      Parameters

      • at: number

        Absoulute bit address.

      Returns number

      Byte value - [0; 255].

    • Reads a byte buffer in the given bit range.

      Parameters

      • from: number

        Start of range (bits, inclusive).

      • to: number

        End of range (bits, not inclusive).

      Returns Uint8Array

      Byte array containing data from within the specified range.

    • Reads an ASCII string in the given bit range.

      Parameters

      • from: number

        Absolute bit address.

      • size: number

        Length in bits.

      Returns string

      Parsed ASCII string.

    • Reads an ASCII string in the given bit range, keeping only the part before any null characters.

      Parameters

      • from: number

        Absolute bit address.

      • size: number

        Length in bits.

      Returns string

      Parsed ASCII string.

    • Reads a null-terminated ASCII string.

      Parameters

      • from: number

        Absolute bit address.

      Returns string

      Parsed ASCII string.

    • Reads an unsigned integer of arbitrary bit width.

      Parameters

      • from: number

        Absolute bit address.

      • size: number

        Bit width (size in bits) of the integer.

      Returns number

      Parsed integer value.

    • Reads a signed integer of arbitrary bit width.

      Parameters

      • from: number

        Absolute bit address.

      • size: number

        Bit width (size in bits) of the integer.

      Returns number

      Parsed signed integer value.

    • Reads a 32-bit floating point value.

      Parameters

      • from: number

        Absolute bit address.

      Returns number

      Parsed float value.

    • Reads a 64-bit floating point value.

      Parameters

      • from: number

        Absolute bit address.

      Returns number

      Parsed float value.

    • Reads a byte buffer starting from the cursor, and moves the cursor past it.

      Parameters

      • size: number

        Size in bits.

      Returns Uint8Array

      Byte array containing data from within the specified range.

    • Reads an ASCII string of the specified length at the cursor, and moves the cursor past it.

      Parameters

      • size: number

        Length in bits.

      Returns string

      Parsed ASCII string.

    • Reads an ASCII string of the specified length at the cursor, keeping only the part before any null characters, and moves the cursor past it.

      Parameters

      • size: number

        Length in bits.

      Returns string

      Parsed ASCII string.

    • Reads a null-terminated ASCII string at the cursor, and moves the cursor past it.

      Returns string

      Parsed ASCII string.

    • Reads an unsigned integer of arbitrary bit width at the cursor, and moves the cursor past it.

      Parameters

      • size: number

        Bit width (size in bits) of the integer.

      Returns number

      Parsed integer value.

    • Reads a signed integer of arbitrary bit width at the cursor, and moves the cursor past it.

      Parameters

      • size: number

        Bit width (size in bits) of the integer.

      Returns number

      Parsed signed integer value.

    • Reads a variable-length unsigned integer at the cursor, and moves the cursor past it.

      Returns number

      Parsed integer value.

    • Reads the next index in a sequence of properties using a variable-length encoding, and moves the cursor past it.

      Parameters

      • lastIndex: number

        Preceding index value, -1 to start an iteration.

      • newScheme: boolean

        Whether to use the "new" parsing scheme. Pretty much always true for Portal 2 demos.

      Returns number

      The next index in the sequence.

    • Finds the index of the most significant set bit in the input integer.

      Parameters

      • i: number

        Integer value.

      Returns number

      Index of the most significant set bit.

    • Modifies the buffer to set a bit at the given address.

      Parameters

      • at: number

        Absolute bit address.

      • value: number | boolean

        Value to write - 0 or 1.

      Returns void

    • Modifies the buffer to write an unsigned integer at the given address.

      Parameters

      • from: number

        Absolute bit address.

      • size: number

        Bit width (size in bits) of the integer.

      • value: number

        Value to write.

      Returns void

    • Modifies the buffer to write a signed integer at the given address.

      Parameters

      • from: number

        Absolute bit address.

      • size: number

        Bit width (size in bits) of the integer.

      • value: number

        Value to write.

      Returns void

    • Modifies the buffer to write a 32-bit floating point number at the given address.

      Parameters

      • from: number

        Absolute bit address.

      • value: number

        Value to write.

      Returns void