mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
parse deaths and strictly type packet types
This commit is contained in:
parent
1a71b65f12
commit
cb02fdee9b
18 changed files with 217 additions and 119 deletions
|
|
@ -85,7 +85,7 @@ export class Packet extends Parser {
|
|||
enum PacketType {
|
||||
file = 2,
|
||||
netTick = 3,
|
||||
stringSmd = 4,
|
||||
stringCmd = 4,
|
||||
setConVar = 5,
|
||||
sigOnState = 6,
|
||||
print = 7,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import {Packet} from "../../Data/Packet";
|
||||
import {BSPDecalPacket} from "../../Data/Packet";
|
||||
import {BitStream} from 'bit-buffer';
|
||||
import {Vector} from "../../Data/Vector";
|
||||
|
||||
const getCoord = function (stream) {
|
||||
const hasInt = !!stream.readBits(1);
|
||||
const hasInt = !!stream.readBits(1);
|
||||
const hasFract = !!stream.readBits(1);
|
||||
let value = 0;
|
||||
let value = 0;
|
||||
if (hasInt || hasFract) {
|
||||
const sign = !!stream.readBits(1);
|
||||
if (hasInt) {
|
||||
|
|
@ -20,7 +21,7 @@ const getCoord = function (stream) {
|
|||
return value;
|
||||
};
|
||||
|
||||
const getVecCoord = function (stream) {
|
||||
const getVecCoord = function (stream): Vector {
|
||||
const hasX = !!stream.readBits(1);
|
||||
const hasY = !!stream.readBits(1);
|
||||
const hasZ = !!stream.readBits(1);
|
||||
|
|
@ -31,21 +32,21 @@ const getVecCoord = function (stream) {
|
|||
}
|
||||
};
|
||||
|
||||
export function BSPDecal(stream: BitStream): Packet { // 21: BSPDecal
|
||||
export function BSPDecal(stream: BitStream): BSPDecalPacket { // 21: BSPDecal
|
||||
let modelIndex, entIndex;
|
||||
const position = getVecCoord(stream);
|
||||
const position = getVecCoord(stream);
|
||||
const textureIndex = stream.readBits(9);
|
||||
if (stream.readBits(1)) {
|
||||
entIndex = stream.readBits(11);
|
||||
entIndex = stream.readBits(11);
|
||||
modelIndex = stream.readBits(12);
|
||||
}
|
||||
const lowPriority = !!stream.readBits(1);
|
||||
const lowPriority = stream.readBoolean();
|
||||
return {
|
||||
packetType: 'bspDecal',
|
||||
position: position,
|
||||
packetType: 'bspDecal',
|
||||
position: position,
|
||||
textureIndex: textureIndex,
|
||||
entIndex: entIndex,
|
||||
modelIndex: modelIndex,
|
||||
lowPriority: lowPriority
|
||||
entIndex: entIndex,
|
||||
modelIndex: modelIndex,
|
||||
lowPriority: lowPriority
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
import {Packet} from "../../Data/Packet";
|
||||
import {ClassInfoPacket} from "../../Data/Packet";
|
||||
import {BitStream} from 'bit-buffer';
|
||||
import {logBase2} from '../../Math';
|
||||
|
||||
export function ClassInfo(stream: BitStream): Packet { // 10: classInfo
|
||||
const number = stream.readBits(16);
|
||||
const create = !!stream.readBits(1);
|
||||
export function ClassInfo(stream: BitStream): ClassInfoPacket { // 10: classInfo
|
||||
const number = stream.readBits(16);
|
||||
const create = stream.readBoolean();
|
||||
let entries: any[] = [];
|
||||
if (!create) {
|
||||
const bits = logBase2(number) + 1;
|
||||
for (let i = 0; i < number; i++) {
|
||||
const entry = {
|
||||
'classId': stream.readBits(bits),
|
||||
'className': stream.readASCIIString(),
|
||||
'classId': stream.readBits(bits),
|
||||
'className': stream.readASCIIString(),
|
||||
'dataTableName': stream.readASCIIString()
|
||||
};
|
||||
entries.push(entry);
|
||||
|
|
@ -19,8 +19,8 @@ export function ClassInfo(stream: BitStream): Packet { // 10: classInfo
|
|||
}
|
||||
return {
|
||||
'packetType': 'classInfo',
|
||||
number: number,
|
||||
create: create,
|
||||
entries: entries
|
||||
number: number,
|
||||
create: create,
|
||||
entries: entries
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,14 @@
|
|||
import {PacketStringTable} from './PacketStringTable';
|
||||
|
||||
import {Packet} from "../../Data/Packet";
|
||||
import {StringTablePacket} from "../../Data/Packet";
|
||||
import {BitStream} from 'bit-buffer';
|
||||
import {logBase2} from "../../Math";
|
||||
import {readBitVar, readVarInt} from "../readBitVar";
|
||||
import {readVarInt} from "../readBitVar";
|
||||
|
||||
import {uncompress} from "snappyjs";
|
||||
import {StringTable} from "../../Data/StringTable";
|
||||
import {parseStringTable} from "../StringTableParser";
|
||||
import {Match} from "../../Data/Match";
|
||||
|
||||
export function CreateStringTable(stream: BitStream, match: Match): Packet { // 12: createStringTable
|
||||
export function CreateStringTable(stream: BitStream, match: Match): StringTablePacket { // 12: createStringTable
|
||||
const tableName = stream.readASCIIString();
|
||||
const maxEntries = stream.readUint16();
|
||||
const encodeBits = logBase2(maxEntries);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import {make} from './ParserGenerator';
|
||||
|
||||
import {Packet} from "../../Data/Packet";
|
||||
import {EntityMessagePacket} from "../../Data/Packet";
|
||||
import {BitStream} from 'bit-buffer';
|
||||
|
||||
const baseParser = make('entityMessage', 'index{11}classId{9}length{11}data{$length}');
|
||||
|
||||
export function EntityMessage(stream:BitStream):Packet { // 24: entityMessage
|
||||
return baseParser(stream); //todo parse data further?
|
||||
export function EntityMessage(stream: BitStream): EntityMessagePacket { // 24: entityMessage
|
||||
return <EntityMessagePacket>baseParser(stream); //todo parse data further?
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {Packet} from "../../Data/Packet";
|
||||
import {GameEventPacket} from "../../Data/Packet";
|
||||
import {BitStream} from 'bit-buffer';
|
||||
import {
|
||||
GameEventType, GameEventValue, GameEventEntry, GameEventDefinition, GameEvent as IGameEvent,
|
||||
|
|
@ -6,9 +6,9 @@ import {
|
|||
} from "../../Data/GameEvent";
|
||||
import {Match} from "../../Data/Match";
|
||||
|
||||
const parseGameEvent = function (eventId: number, stream: BitStream, events: GameEventDefinitionMap): IGameEvent|null {
|
||||
const parseGameEvent = function (eventId: number, stream: BitStream, events: GameEventDefinitionMap): IGameEvent {
|
||||
if (!events[eventId]) {
|
||||
return null;
|
||||
throw new Error('unknown event type')
|
||||
}
|
||||
const eventDescription: GameEventDefinition = events[eventId];
|
||||
const values: GameEventValueMap = {};
|
||||
|
|
@ -47,7 +47,7 @@ const getGameEventValue = function (stream: BitStream, entry: GameEventEntry): G
|
|||
};
|
||||
|
||||
|
||||
export function GameEvent(stream: BitStream, match: Match): Packet { // 25: game event
|
||||
export function GameEvent(stream: BitStream, match: Match): GameEventPacket { // 25: game event
|
||||
const length = stream.readBits(11);
|
||||
const end = stream.index + length;
|
||||
const eventId = stream.readBits(9);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import {Packet} from "../../Data/Packet";
|
||||
import {GameEventListPacket} from "../../Data/Packet";
|
||||
import {BitStream} from 'bit-buffer';
|
||||
import {GameEventEntry, GameEventDefinitionMap} from "../../Data/GameEvent";
|
||||
import {Match} from "../../Data/Match";
|
||||
|
||||
export function GameEventList(stream: BitStream, match: Match): Packet { // 30: gameEventList
|
||||
export function GameEventList(stream: BitStream, match: Match): GameEventListPacket { // 30: gameEventList
|
||||
// list of game events and parameters
|
||||
const numEvents = stream.readBits(9);
|
||||
const length = stream.readBits(20);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
import {SendPropParser} from '../../Parser/SendPropParser';
|
||||
import {Entity} from '../../Data/Entity';
|
||||
import {SendProp} from '../../Data/SendProp';
|
||||
import {Packet} from "../../Data/Packet";
|
||||
import {PacketEntitiesPacket} from "../../Data/Packet";
|
||||
import {BitStream} from 'bit-buffer';
|
||||
import {GameEventDefinition} from "../../Data/GameEvent";
|
||||
import {Match} from "../../Data/Match";
|
||||
import {readUBitVar} from "../readBitVar";
|
||||
import {applyEntityUpdate} from "../EntityDecoder";
|
||||
|
|
@ -74,7 +72,7 @@ function readLeavePVS(match, entityId, shouldDelete) {
|
|||
}
|
||||
}
|
||||
|
||||
export function PacketEntities(stream: BitStream, match: Match): Packet { //26: packetEntities
|
||||
export function PacketEntities(stream: BitStream, match: Match): 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
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
import {BitStream} from "bit-buffer";
|
||||
import {Packet} from "../../Data/Packet";
|
||||
|
||||
export function PacketStringTable(stream: BitStream):Packet {
|
||||
//todo
|
||||
// https://coldemoplayer.googlecode.com/svn/branches/2.0/code/plugins/CDP.Source/Messages/SvcCreateStringTable.cs
|
||||
// throw new Error('packetstringtable not implemented');
|
||||
stream.index = stream.length; // no idea, skip to the end of the
|
||||
return {
|
||||
packetType: 'stringTableTODO'
|
||||
};
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import {Packet} from "../../Data/Packet";
|
||||
import {ParseSoundsPacket} from "../../Data/Packet";
|
||||
import {BitStream} from 'bit-buffer';
|
||||
|
||||
export function ParseSounds(stream: BitStream): Packet { // 17: parseSounds
|
||||
export function ParseSounds(stream: BitStream): ParseSoundsPacket { // 17: parseSounds
|
||||
const reliable = stream.readBoolean();
|
||||
const num = (reliable) ? 1 : stream.readUint8();
|
||||
const length = (reliable) ? stream.readUint8() : stream.readUint16();
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
import {Packet} from "../../Data/Packet";
|
||||
import {SetConVarPacket} from "../../Data/Packet";
|
||||
import {BitStream} from 'bit-buffer';
|
||||
|
||||
export function SetConVar(stream: BitStream): Packet { // 5: setconvar
|
||||
const count = stream.readBits(8);
|
||||
let vars = {};
|
||||
export function SetConVar(stream: BitStream): SetConVarPacket { // 5: setconvar
|
||||
const count = stream.readBits(8);
|
||||
let vars: {[key: string]: string} = {};
|
||||
for (let i = 0; i < count; i++) {
|
||||
vars[stream.readUTF8String()] = stream.readUTF8String();
|
||||
}
|
||||
return {
|
||||
packetType: 'setConVar',
|
||||
vars: vars
|
||||
vars: vars
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import {PacketStringTable} from './PacketStringTable';
|
||||
import {Packet} from "../../Data/Packet";
|
||||
import {StringTablePacket} from "../../Data/Packet";
|
||||
import {BitStream} from 'bit-buffer';
|
||||
import {Match} from "../../Data/Match";
|
||||
import {parseStringTable} from "../StringTableParser";
|
||||
|
||||
export function UpdateStringTable(stream: BitStream, match: Match): Packet { // 12: updateStringTable
|
||||
export function UpdateStringTable(stream: BitStream, match: Match): StringTablePacket { // 12: updateStringTable
|
||||
const tableId = stream.readBits(5);
|
||||
|
||||
const multipleChanged = stream.readBoolean();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {Packet} from "../../Data/Packet";
|
||||
import {UserMessagePacket} from "../../Data/Packet";
|
||||
import {BitStream} from 'bit-buffer';
|
||||
import {make} from './ParserGenerator';
|
||||
import {SayText2} from '../UserMessage/SayText2';
|
||||
|
|
@ -69,7 +69,7 @@ const userMessageParsers = {
|
|||
5: make('textMsg', 'destType{8}text{s}')
|
||||
};
|
||||
|
||||
export function UserMessage(stream: BitStream): Packet { // 23: user message
|
||||
export function UserMessage(stream: BitStream): UserMessagePacket { // 23: user message
|
||||
const type = stream.readBits(8);
|
||||
const length = stream.readBits(11);
|
||||
const pos = stream.index;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import {Packet} from "../../Data/Packet";
|
||||
import {SayText2Packet} from "../../Data/Packet";
|
||||
import {BitStream} from 'bit-buffer';
|
||||
|
||||
export function SayText2(stream: BitStream): Packet { // 4: SayText2
|
||||
export function SayText2(stream: BitStream): SayText2Packet { // 4: SayText2
|
||||
var client = stream.readBits(8);
|
||||
var raw = stream.readBits(8);
|
||||
var pos = stream.index;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue