1
0
Fork 0
mirror of https://github.com/demostf/demo.js synced 2026-06-04 09:04:13 +02:00

some minor refactoring to prepare for re-encoding

This commit is contained in:
Robin Appelman 2017-08-12 00:52:04 +02:00
commit 69386f7d60
18 changed files with 121 additions and 122 deletions

View file

@ -22,9 +22,9 @@ function getCoord(stream) {
}
function getVecCoord(stream): Vector {
const hasX = !!stream.readBits(1);
const hasY = !!stream.readBits(1);
const hasZ = !!stream.readBits(1);
const hasX = stream.readBoolean();
const hasY = stream.readBoolean();
const hasZ = stream.readBoolean();
return {
x: hasX ? getCoord(stream) : 0,
y: hasY ? getCoord(stream) : 0,
@ -32,7 +32,7 @@ function getVecCoord(stream): Vector {
};
}
export function BSPDecal(stream: BitStream): BSPDecalPacket { // 21: BSPDecal
export function ParseBSPDecal(stream: BitStream): BSPDecalPacket { // 21: ParseBSPDecal
let modelIndex = 0;
let entIndex = 0;
const position = getVecCoord(stream);

View file

@ -2,7 +2,7 @@ import {BitStream} from 'bit-buffer';
import {ClassInfoPacket} from '../../Data/Packet';
import {logBase2} from '../../Math';
export function ClassInfo(stream: BitStream): ClassInfoPacket { // 10: classInfo
export function ParseClassInfo(stream: BitStream): ClassInfoPacket { // 10: classInfo
const count = stream.readBits(16);
const create = stream.readBoolean();
const entries: any[] = [];

View file

@ -1,10 +1,10 @@
import {BitStream} from 'bit-buffer';
import {CmdKeyValuesPacket} from '../../Data/Packet';
export function CmdKeyValues(stream: BitStream): CmdKeyValuesPacket {
// 'length{32}data{$length}'
export function ParseCmdKeyValues(stream: BitStream): CmdKeyValuesPacket {
const length = stream.readUint32();
const data = stream.readBitStream(length);
// 'length{32}data{$length}'
return {
packetType: 'cmdKeyValues',
length,

View file

@ -8,7 +8,7 @@ import {Match} from '../../Data/Match';
import {StringTable} from '../../Data/StringTable';
import {parseStringTable} from '../StringTableParser';
export function CreateStringTable(stream: BitStream, match: Match): StringTablePacket { // 12: createStringTable
export function ParseCreateStringTable(stream: BitStream, match: Match): StringTablePacket { // 12: createStringTable
const tableName = stream.readASCIIString();
const maxEntries = stream.readUint16();
const encodeBits = logBase2(maxEntries);

View file

@ -6,6 +6,9 @@ import {EntityMessagePacket} from '../../Data/Packet';
const baseParser = make('entityMessage', 'index{11}classId{9}length{11}data{$length}');
export function EntityMessage(stream: BitStream, match: Match): EntityMessagePacket { // 24: entityMessage
return baseParser(stream) as EntityMessagePacket; // todo parse data further?
export function ParseEntityMessage(stream: BitStream, match: Match): EntityMessagePacket { // 24: entityMessage
const basePacketData: EntityMessagePacket = baseParser(stream) as EntityMessagePacket;
// entity messages seem pretty unimportant, they are unreliable messages and from testing only the "clear decals"
// message seems to be used in practice, probably safe to just leave as is
return basePacketData; // todo parse data further?
}

View file

@ -45,7 +45,7 @@ function getGameEventValue(stream: BitStream, entry: GameEventEntry): GameEventV
}
}
export function GameEvent(stream: BitStream, match: Match): GameEventPacket { // 25: game event
export function ParseGameEvent(stream: BitStream, match: Match): GameEventPacket { // 25: game event
const length = stream.readBits(11);
const end = stream.index + length;
const eventId = stream.readBits(9);

View file

@ -3,7 +3,7 @@ import {GameEventDefinitionMap, GameEventEntry} from '../../Data/GameEvent';
import {Match} from '../../Data/Match';
import {GameEventListPacket} from '../../Data/Packet';
export function GameEventList(stream: BitStream, match: Match): GameEventListPacket { // 30: gameEventList
export function ParseGameEventList(stream: BitStream, match: Match): GameEventListPacket { // 30: gameEventList
// list of game events and parameters
const numEvents = stream.readBits(9);
const length = stream.readBits(20);

View file

@ -1,7 +1,7 @@
import {BitStream} from 'bit-buffer';
import {MenuPacket} from '../../Data/Packet';
export function Menu(stream: BitStream): MenuPacket {
export function ParseMenu(stream: BitStream): MenuPacket {
const type = stream.readUint16();
const length = stream.readUint16();
const data = stream.readBitStream(length * 8); // length is in bytes

View file

@ -58,7 +58,7 @@ function getPacketEntityForExisting(entityId: number, match: Match, pvs: PVS) {
return new PacketEntity(serverClass, entityId, pvs);
}
export function PacketEntities(stream: BitStream, match: Match, skip: boolean = false): PacketEntitiesPacket { // 26: packetEntities
export function ParsePacketEntities(stream: BitStream, match: Match, skip: boolean = false): PacketEntitiesPacket { // 26: packetEntities
// https://github.com/skadistats/smoke/blob/master/smoke/replay/handler/svc_packetentities.pyx
// https://github.com/StatsHelix/demoinfo/blob/3d28ea917c3d44d987b98bb8f976f1a3fcc19821/DemoInfo/DP/Handler/PacketEntitesHandler.cs
// https://github.com/StatsHelix/demoinfo/blob/3d28ea917c3d44d987b98bb8f976f1a3fcc19821/DemoInfo/DP/Entity.cs

View file

@ -1,7 +1,7 @@
import {BitStream} from 'bit-buffer';
import {ParseSoundsPacket} from '../../Data/Packet';
export function ParseSounds(stream: BitStream): ParseSoundsPacket { // 17: parseSounds
export function ParseParseSounds(stream: BitStream): ParseSoundsPacket { // 17: parseSounds
const reliable = stream.readBoolean();
const num = (reliable) ? 1 : stream.readUint8();
const length = (reliable) ? stream.readUint8() : stream.readUint16();

View file

@ -1,7 +1,7 @@
import {BitStream} from 'bit-buffer';
import {SetConVarPacket} from '../../Data/Packet';
export function SetConVar(stream: BitStream): SetConVarPacket { // 5: setconvar
export function ParseSetConVar(stream: BitStream): SetConVarPacket { // 5: setconvar
const count = stream.readBits(8);
const vars: {[key: string]: string} = {};
for (let i = 0; i < count; i++) {

View file

@ -4,7 +4,7 @@ import {TempEntitiesPacket} from '../../Data/Packet';
import {PacketEntity, PVS} from '../../Data/PacketEntity';
import {applyEntityUpdate} from '../EntityDecoder';
export function TempEntities(stream: BitStream, match: Match, skip: boolean = false): TempEntitiesPacket { // 10: classInfo
export function ParseTempEntities(stream: BitStream, match: Match, skip: boolean = false): TempEntitiesPacket { // 10: classInfo
const entityCount = stream.readBits(8);
const length = readVarInt(stream);
const end = stream.index + length;

View file

@ -3,7 +3,7 @@ import {Match} from '../../Data/Match';
import {StringTablePacket} from '../../Data/Packet';
import {parseStringTable} from '../StringTableParser';
export function UpdateStringTable(stream: BitStream, match: Match): StringTablePacket { // 12: updateStringTable
export function ParseUpdateStringTable(stream: BitStream, match: Match): StringTablePacket { // 12: updateStringTable
const tableId = stream.readBits(5);
const multipleChanged = stream.readBoolean();

View file

@ -4,64 +4,64 @@ import {SayText2} from '../UserMessage/SayText2';
import {make} from './ParserGenerator';
enum UserMessageType {
Geiger = 0,
Train = 1,
HudText = 2,
SayText = 3,
SayText2 = 4,
TextMsg = 5,
ResetHUD = 6,
GameTitle = 7,
ItemPickup = 8,
ShowMenu = 9,
Shake = 10,
Fade = 11,
VGUIMenu = 12,
Rumble = 13,
CloseCaption = 14,
SendAudio = 15,
VoiceMask = 16,
RequestState = 17,
Damage = 18,
HintText = 19,
KeyHintText = 20,
HudMsg = 21,
AmmoDenied = 22,
AchievementEvent = 23,
UpdateRadar = 24,
VoiceSubtitle = 25,
HudNotify = 26,
HudNotifyCustom = 27,
PlayerStatsUpdate = 28,
PlayerIgnited = 29,
PlayerIgnitedInv = 30,
HudArenaNotify = 31,
UpdateAchievement = 32,
TrainingMsg = 33,
TrainingObjective = 34,
DamageDodged = 35,
PlayerJarated = 36,
PlayerExtinguished = 37,
PlayerJaratedFade = 38,
Geiger = 0,
Train = 1,
HudText = 2,
SayText = 3,
SayText2 = 4,
TextMsg = 5,
ResetHUD = 6,
GameTitle = 7,
ItemPickup = 8,
ShowMenu = 9,
Shake = 10,
Fade = 11,
VGUIMenu = 12,
Rumble = 13,
CloseCaption = 14,
SendAudio = 15,
VoiceMask = 16,
RequestState = 17,
Damage = 18,
HintText = 19,
KeyHintText = 20,
HudMsg = 21,
AmmoDenied = 22,
AchievementEvent = 23,
UpdateRadar = 24,
VoiceSubtitle = 25,
HudNotify = 26,
HudNotifyCustom = 27,
PlayerStatsUpdate = 28,
PlayerIgnited = 29,
PlayerIgnitedInv = 30,
HudArenaNotify = 31,
UpdateAchievement = 32,
TrainingMsg = 33,
TrainingObjective = 34,
DamageDodged = 35,
PlayerJarated = 36,
PlayerExtinguished = 37,
PlayerJaratedFade = 38,
PlayerShieldBlocked = 39,
BreakModel = 40,
CheapBreakModel = 41,
BreakModel_Pumpkin = 42,
BreakModel = 40,
CheapBreakModel = 41,
BreakModel_Pumpkin = 42,
BreakModelRocketDud = 43,
CallVoteFailed = 44,
VoteStart = 45,
VotePass = 46,
VoteFailed = 47,
VoteSetup = 48,
PlayerBonusPoints = 49,
SpawnFlyingBird = 50,
PlayerGodRayEffect = 51,
SPHapWeapEvent = 52,
HapDmg = 53,
HapPunch = 54,
HapSetDrag = 55,
HapSet = 56,
HapMeleeContact = 57,
CallVoteFailed = 44,
VoteStart = 45,
VotePass = 46,
VoteFailed = 47,
VoteSetup = 48,
PlayerBonusPoints = 49,
SpawnFlyingBird = 50,
PlayerGodRayEffect = 51,
SPHapWeapEvent = 52,
HapDmg = 53,
HapPunch = 54,
HapSetDrag = 55,
HapSet = 56,
HapMeleeContact = 57,
}
const userMessageParsers = {
@ -69,19 +69,14 @@ const userMessageParsers = {
5: make('textMsg', 'destType{8}text{s}'),
};
export function UserMessage(stream: BitStream): UserMessagePacket { // 23: user message
const type = stream.readBits(8);
export function ParseUserMessage(stream: BitStream): UserMessagePacket { // 23: user message
const type = stream.readBits(8);
const length = stream.readBits(11);
const pos = stream.index;
let result;
if (userMessageParsers[type]) {
result = userMessageParsers[type](stream);
} else {
result = {
packetType: 'unknownUserMessage',
type,
};
}
stream.index = pos + length;
return result;
const messageData = stream.readBitStream(length);
return userMessageParsers[type] ? userMessageParsers[type](messageData) : {
packetType: 'unknownUserMessage',
type,
data: messageData,
};
}

View file

@ -1,7 +1,7 @@
import {BitStream} from 'bit-buffer';
import {VoiceDataPacket} from '../../Data/Packet';
export function VoiceData(stream: BitStream): VoiceDataPacket {
export function ParseVoiceData(stream: BitStream): VoiceDataPacket {
// 'client{8}proximity{8}length{16}_{$length}'
const client = stream.readUint8();
const proximity = stream.readUint8();

View file

@ -1,7 +1,7 @@
import {BitStream} from 'bit-buffer';
import {VoiceInitPacket} from '../../Data/Packet';
export function VoiceInit(stream: BitStream): VoiceInitPacket {
export function ParseVoiceInit(stream: BitStream): VoiceInitPacket {
const codec = stream.readASCIIString();
const quality = stream.readUint8();
// no clue, from 2017-2-14 update