mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 09:04:13 +02:00
final typescript conversion
This commit is contained in:
parent
94383f447f
commit
3b805be013
19 changed files with 440 additions and 518 deletions
|
|
@ -1,11 +1,10 @@
|
|||
import {PacketStringTable} from '../../packetstringtable';
|
||||
import {PacketStringTable} from './PacketStringTable';
|
||||
|
||||
import {Packet} from "../../Data/Packet";
|
||||
import {BitStream} from 'bit-buffer';
|
||||
|
||||
export function CreateStringTable(stream: BitStream): Packet { // 12: createStringTable
|
||||
const stringTable = new PacketStringTable(stream);
|
||||
const tables = stringTable.parse();
|
||||
const tables = PacketStringTable(stream);
|
||||
return {
|
||||
packetType: 'createStringTable',
|
||||
table: tables
|
||||
|
|
|
|||
|
|
@ -6,18 +6,18 @@ import {BitStream} from 'bit-buffer';
|
|||
import {GameEventDefinition} from "../../Data/GameEvent";
|
||||
import {Match} from "../../Data/Match";
|
||||
|
||||
var PVS = {
|
||||
PRESERVE: 0,
|
||||
ENTER: 1,
|
||||
LEAVE: 2,
|
||||
DELETE: 4
|
||||
};
|
||||
enum PVS {
|
||||
PRESERVE = 0,
|
||||
ENTER = 1,
|
||||
LEAVE = 2,
|
||||
DELETE = 4
|
||||
}
|
||||
|
||||
function readPVSType(stream) {
|
||||
function readPVSType(stream: BitStream): number {
|
||||
// https://github.com/skadistats/smoke/blob/a2954fbe2fa3936d64aee5b5567be294fef228e6/smoke/io/stream/entity.pyx#L24
|
||||
var pvs;
|
||||
var hi = stream.readBoolean();
|
||||
var low = stream.readBoolean();
|
||||
let pvs;
|
||||
const hi = stream.readBoolean();
|
||||
const low = stream.readBoolean();
|
||||
if (low && !hi) {
|
||||
pvs = PVS.ENTER;
|
||||
} else if (!(hi || low)) {
|
||||
|
|
@ -30,27 +30,33 @@ function readPVSType(stream) {
|
|||
return pvs;
|
||||
}
|
||||
|
||||
function readEnterPVS(stream, entityId, match, baseLine) {
|
||||
function readEnterPVS(stream: BitStream, entityId: number, match: Match, baseLine: number):Entity {
|
||||
// https://github.com/PazerOP/DemoLib/blob/5f9467650f942a4a70f9ec689eadcd3e0a051956/TF2Net/NetMessages/NetPacketEntitiesMessage.cs#L198
|
||||
var serverClass = match.serverClasses[stream.readBits(match.classBits)];
|
||||
const serverClass = match.serverClasses[stream.readBits(match.classBits)];
|
||||
console.log(serverClass);
|
||||
var sendTable = match.getSendTable(serverClass.dataTable);
|
||||
var serialNumber = stream.readBits(10);
|
||||
const sendTable = match.getSendTable(serverClass.dataTable);
|
||||
const serialNumber = stream.readBits(10);
|
||||
if (!sendTable) {
|
||||
throw new Error('Unknown SendTable for serverclass');
|
||||
}
|
||||
|
||||
var entity = (match.entities[entityId]) ? match.entities[entityId] : new Entity(serverClass, sendTable, entityId, serialNumber);
|
||||
let entity = match.entities[entityId];
|
||||
if (!entity) {
|
||||
entity = new Entity(serverClass, sendTable, entityId, serialNumber);
|
||||
}
|
||||
|
||||
var decodedBaseLine = match.instanceBaselines[baseLine][entityId];
|
||||
const decodedBaseLine = match.instanceBaselines[baseLine][entityId];
|
||||
if (decodedBaseLine) {
|
||||
for (var i = 0; i < decodedBaseLine.length; i++) {
|
||||
var newProp = decodedBaseLine[i];
|
||||
for (let i = 0; i < decodedBaseLine.length; i++) {
|
||||
const newProp = decodedBaseLine[i];
|
||||
if (!entity.getPropByDefinition(newProp.definition)) {
|
||||
entity.props.push(newProp.clone(entity));
|
||||
entity.props.push(newProp.clone());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var staticBaseLine = match.staticBaseLines[serverClass.id];
|
||||
const staticBaseLine = match.staticBaseLines[serverClass.id];
|
||||
if (staticBaseLine) {
|
||||
var streamStart = staticBaseLine._index;
|
||||
const streamStart = staticBaseLine._index;
|
||||
applyEntityUpdate(entity, staticBaseLine);
|
||||
staticBaseLine._index = streamStart;
|
||||
}
|
||||
|
|
@ -70,24 +76,20 @@ export function PacketEntities(stream: BitStream, events: GameEventDefinition[],
|
|||
// https://github.com/StatsHelix/demoinfo/blob/3d28ea917c3d44d987b98bb8f976f1a3fcc19821/DemoInfo/DP/Entity.cs
|
||||
// https://github.com/PazerOP/DemoLib/blob/5f9467650f942a4a70f9ec689eadcd3e0a051956/TF2Net/NetMessages/NetPacketEntitiesMessage.cs
|
||||
// todo
|
||||
var maxEntries = stream.readBits(11);
|
||||
var isDelta = !!stream.readBits(1);
|
||||
if (isDelta) {
|
||||
var delta = stream.readInt32();
|
||||
} else {
|
||||
delta = null;
|
||||
}
|
||||
var baseLine = stream.readBits(1);
|
||||
var updatedEntries = stream.readBits(11);
|
||||
var length = stream.readBits(20);
|
||||
var updatedBaseLine = stream.readBoolean();
|
||||
var end = stream._index + length;
|
||||
var entityId = -1;
|
||||
const maxEntries = stream.readBits(11);
|
||||
const isDelta = !!stream.readBits(1);
|
||||
const delta = (isDelta) ? stream.readInt32() : null;
|
||||
const baseLine = stream.readBits(1);
|
||||
const updatedEntries = stream.readBits(11);
|
||||
const length = stream.readBits(20);
|
||||
const updatedBaseLine = stream.readBoolean();
|
||||
const end = stream._index + length;
|
||||
let entityId = -1
|
||||
|
||||
stream._index = end;
|
||||
return {
|
||||
packetType: 'packetEntities',
|
||||
entities: entities
|
||||
entities: entities
|
||||
};
|
||||
|
||||
if (updatedBaseLine) {
|
||||
|
|
@ -100,29 +102,31 @@ export function PacketEntities(stream: BitStream, events: GameEventDefinition[],
|
|||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < updatedEntries; i++) {
|
||||
var diff = readUBitVar(stream);
|
||||
console.log(diff);
|
||||
for (let i = 0; i < updatedEntries; i++) {
|
||||
const diff = readUBitVar(stream);
|
||||
entityId += 1 + diff;
|
||||
var pvs = readPVSType(stream);
|
||||
const pvs = readPVSType(stream);
|
||||
if (pvs === PVS.ENTER) {
|
||||
var entity = readEnterPVS(stream, entityId, match, baseLine);
|
||||
const entity = readEnterPVS(stream, entityId, match, baseLine);
|
||||
applyEntityUpdate(entity, stream);
|
||||
match.entities[entityId] = entity;
|
||||
|
||||
if (updatedBaseLine) {
|
||||
match.instanceBaselines[baseLine][entityId] = [].concat(entity.props);
|
||||
const newBaseLine:SendProp[] = [];
|
||||
newBaseLine.concat(entity.props);
|
||||
match.instanceBaselines[baseLine][entityId] = newBaseLine;
|
||||
}
|
||||
entity.inPVS = true;
|
||||
} else if (pvs === PVS.PRESERVE) {
|
||||
entity = match.entities[entityId];
|
||||
if (!entity) {
|
||||
const entity = match.entities[entityId];
|
||||
if (entity) {
|
||||
applyEntityUpdate(entity, stream);
|
||||
} else {
|
||||
console.log(entityId, match.entities.length);
|
||||
throw new Error("unknown entity");
|
||||
}
|
||||
applyEntityUpdate(entity, stream);
|
||||
} else {
|
||||
entity = match.entities[entityId];
|
||||
const entity = match.entities[entityId];
|
||||
if (entity) {
|
||||
entity.inPVS = false;
|
||||
}
|
||||
|
|
@ -132,7 +136,7 @@ export function PacketEntities(stream: BitStream, events: GameEventDefinition[],
|
|||
|
||||
if (isDelta) {
|
||||
while (stream.readBoolean()) {
|
||||
var ent = stream.readBits(11);
|
||||
const ent = stream.readBits(11);
|
||||
match.entities[ent] = null;
|
||||
}
|
||||
}
|
||||
|
|
@ -140,29 +144,29 @@ export function PacketEntities(stream: BitStream, events: GameEventDefinition[],
|
|||
stream._index = end;
|
||||
return {
|
||||
packetType: 'packetEntities',
|
||||
entities: entities
|
||||
entities: entities
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
var readFieldIndex = function (stream, lastIndex) {
|
||||
const readFieldIndex = function (stream: BitStream, lastIndex: number): number {
|
||||
if (!stream.readBoolean()) {
|
||||
return -1;
|
||||
}
|
||||
var diff = readUBitVar(stream);
|
||||
const diff = readUBitVar(stream);
|
||||
return lastIndex + diff + 1;
|
||||
};
|
||||
|
||||
var applyEntityUpdate = function (entity, stream) {
|
||||
var index = -1;
|
||||
var allProps = entity.sendTable.flattenedProps;
|
||||
const applyEntityUpdate = function (entity: Entity, stream: BitStream): Entity {
|
||||
let index = -1;
|
||||
const allProps = entity.sendTable.flattenedProps;
|
||||
while ((index = readFieldIndex(stream, index)) != -1) {
|
||||
if (index > 4096) {
|
||||
throw new Error('prop index out of bounds');
|
||||
}
|
||||
console.log(index);
|
||||
var propDefinition = allProps[index];
|
||||
var existingProp = entity.getPropByDefinition(propDefinition);
|
||||
var prop;
|
||||
const propDefinition = allProps[index];
|
||||
const existingProp = entity.getPropByDefinition(propDefinition);
|
||||
let prop;
|
||||
if (existingProp) {
|
||||
prop = existingProp;
|
||||
} else {
|
||||
|
|
@ -178,7 +182,7 @@ var applyEntityUpdate = function (entity, stream) {
|
|||
return entity;
|
||||
};
|
||||
|
||||
var readUBitVar = function (stream) {
|
||||
const readUBitVar = function (stream: BitStream): number {
|
||||
switch (stream.readBits(2)) {
|
||||
case 0:
|
||||
return stream.readBits(4);
|
||||
|
|
@ -189,4 +193,5 @@ var readUBitVar = function (stream) {
|
|||
case 3:
|
||||
return stream.readBits(32);
|
||||
}
|
||||
throw new Error('Invalid var bit');
|
||||
};
|
||||
|
|
|
|||
11
src/Parser/Packet/PacketStringTable.ts
Normal file
11
src/Parser/Packet/PacketStringTable.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
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
|
||||
stream._index = stream._view._view.byteLength * 8;
|
||||
return {
|
||||
packetType: 'stringTableTODO'
|
||||
};
|
||||
}
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
import {PacketStringTable} from '../../packetstringtable';
|
||||
import {PacketStringTable} from './PacketStringTable';
|
||||
import {Packet} from "../../Data/Packet";
|
||||
import {BitStream} from 'bit-buffer';
|
||||
|
||||
export function UpdateStringTable(stream: BitStream): Packet { // 12: updateStringTable
|
||||
const stringTable = new PacketStringTable(stream);
|
||||
const tables = stringTable.parse();
|
||||
const tables = PacketStringTable(stream);
|
||||
return {
|
||||
packetType: 'updateStringTable',
|
||||
table: tables
|
||||
|
|
|
|||
|
|
@ -1,86 +1,87 @@
|
|||
import {Packet} from "../../Data/Packet";
|
||||
import {BitStream} from 'bit-buffer';
|
||||
import {make} from './ParserGenerator';
|
||||
import {SayText2} from '../UserMessage/SayText2';
|
||||
|
||||
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,
|
||||
PlayerShieldBlocked = 39,
|
||||
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
|
||||
}
|
||||
|
||||
const userMessageParsers = {
|
||||
4: require('../../handlers/userMessage/SayText2'),
|
||||
4: SayText2,
|
||||
5: make('textMsg', 'destType{8}text{s}')
|
||||
};
|
||||
|
||||
export function UserMessage(stream: BitStream): Packet { // 23: user message
|
||||
const type = stream.readBits(8);
|
||||
const type = stream.readBits(8);
|
||||
const length = stream.readBits(11);
|
||||
const pos = stream._index;
|
||||
const pos = stream._index;
|
||||
let result;
|
||||
if (userMessageParsers[type]) {
|
||||
result = userMessageParsers[type](stream);
|
||||
} else {
|
||||
result = {
|
||||
packetType: 'unknownUserMessage',
|
||||
type: type
|
||||
type: type
|
||||
}
|
||||
}
|
||||
stream._index = pos + length;
|
||||
return result;
|
||||
}
|
||||
|
||||
var 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,
|
||||
PlayerShieldBlocked: 39,
|
||||
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
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue