From 8c29265bb2dabbb63b95d9f4b58dc878a59bb23e Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 24 Oct 2017 23:12:18 +0200 Subject: [PATCH] fix handling of post pyro update demos --- src/Parser/Packet/GameEventList.ts | 12 +++++++----- src/Parser/Packet/VoiceInit.ts | 12 +++++++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Parser/Packet/GameEventList.ts b/src/Parser/Packet/GameEventList.ts index 927641a..cb7a1fe 100644 --- a/src/Parser/Packet/GameEventList.ts +++ b/src/Parser/Packet/GameEventList.ts @@ -6,19 +6,21 @@ import {GameEventListPacket} from '../../Data/Packet'; export function ParseGameEventList(stream: BitStream): GameEventListPacket { // 30: gameEventList // list of game events and parameters const numEvents = stream.readBits(9); + const length = stream.readBits(20); + const listData = stream.readBitStream(length); const eventList: Map> = new Map(); for (let i = 0; i < numEvents; i++) { - const id = stream.readBits(9); - const name = stream.readASCIIString() as GameEvent['name']; - let type = stream.readBits(3); + const id = listData.readBits(9); + const name = listData.readASCIIString() as GameEvent['name']; + let type = listData.readBits(3); const entries: GameEventEntry[] = []; while (type !== 0) { entries.push({ type, - name: stream.readASCIIString() + name: listData.readASCIIString() }); - type = stream.readBits(3); + type = listData.readBits(3); } eventList.set(id, { id, diff --git a/src/Parser/Packet/VoiceInit.ts b/src/Parser/Packet/VoiceInit.ts index 03c6385..5d7c172 100644 --- a/src/Parser/Packet/VoiceInit.ts +++ b/src/Parser/Packet/VoiceInit.ts @@ -6,7 +6,7 @@ export function ParseVoiceInit(stream: BitStream): VoiceInitPacket { const quality = stream.readUint8(); // no clue, from 2017-2-14 update - const extraData = (codec === 'vaudio_celt' && quality === 255) ? stream.readUint16() : 0; + const extraData = readExtraData(stream, codec, quality); return { packetType: 'voiceInit', @@ -16,6 +16,16 @@ export function ParseVoiceInit(stream: BitStream): VoiceInitPacket { }; } +function readExtraData(stream: BitStream, codec: string, quality: number) { + if (quality === 255) { + return stream.readUint16(); + } else if (codec === 'vaudio_celt') { + return 11025; + } else { + return 0; + } +} + export function EncodeVoiceInit(packet: VoiceInitPacket, stream: BitStream) { stream.writeASCIIString(packet.codec); stream.writeUint8(packet.quality);