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

add fast mode

This commit is contained in:
Robin Appelman 2017-03-07 18:16:55 +01:00
commit e9349d178e
9 changed files with 91 additions and 70 deletions

View file

@ -37,7 +37,8 @@ export class Packet extends Parser {
const type = this.stream.readBits(6);
if (type !== 0) {
if (Packet.parsers[type]) {
let packet = Packet.parsers[type].call(this, this.stream, this.match);
const skip = this.skippedPackets.indexOf(type) !== -1;
const packet = Packet.parsers[type].call(this, this.stream, this.match, skip);
packets.push(packet);
} else {
throw new Error('Unknown packet type ' + type + " just parsed a " + PacketType[lastPacketType]);
@ -86,7 +87,7 @@ export class Packet extends Parser {
};
}
enum PacketType {
export enum PacketType {
file = 2,
netTick = 3,
stringCmd = 4,

View file

@ -1,7 +1,8 @@
import {BitStream} from 'bit-buffer';
import {Match} from '../../Data/Match';
import {Packet} from "../../Data/Packet";
import {SendTable} from "../../Data/SendTable";
import {MessageType} from "../../Parser";
import {PacketType} from "./Packet";
export abstract class Parser {
type: any;
@ -9,14 +10,16 @@ export abstract class Parser {
stream: BitStream;
length: number;
match: Match;
skippedPackets: PacketType[];
constructor(type, tick, stream, length, match) {
this.type = type;
this.tick = tick;
this.stream = stream;
this.length = length;//length in bytes
this.match = match;
constructor(type: MessageType, tick: number, stream: BitStream, length: number, match: Match, skippedPacket: PacketType[] = []) {
this.type = type;
this.tick = tick;
this.stream = stream;
this.length = length;//length in bytes
this.match = match;
this.skippedPackets = skippedPacket;
}
abstract parse():Packet[]|string;
abstract parse(): Packet[]|string;
}

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): PacketEntitiesPacket { //26: packetEntities
export function PacketEntities(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
@ -74,38 +74,41 @@ export function PacketEntities(stream: BitStream, match: Match): PacketEntitiesP
let entityId = -1;
const receivedEntities: PacketEntity[] = [];
for (let i = 0; i < updatedEntries; i++) {
const diff = readUBitVar(stream);
entityId += 1 + diff;
const pvs = readPVSType(stream);
if (pvs === PVS.ENTER) {
const packetEntity = readEnterPVS(stream, entityId, match);
applyEntityUpdate(packetEntity, match.getSendTable(packetEntity.serverClass.dataTable), stream);
const removedEntityIds: number[] = [];
if (updatedBaseLine) {
const newBaseLine: SendProp[] = [];
newBaseLine.concat(packetEntity.props);
match.baseLineCache[packetEntity.serverClass.id] = packetEntity.clone();
}
packetEntity.inPVS = true;
receivedEntities.push(packetEntity);
} else if (pvs === PVS.PRESERVE) {
const packetEntity = getPacketEntityForExisting(entityId, match, pvs);
applyEntityUpdate(packetEntity, match.getSendTable(packetEntity.serverClass.dataTable), stream);
receivedEntities.push(packetEntity);
} else {
if(match.entityClasses[entityId]) {
const packetEntity = getPacketEntityForExisting(entityId, match, pvs);
if (!skip) {
for (let i = 0; i < updatedEntries; i++) {
const diff = readUBitVar(stream);
entityId += 1 + diff;
const pvs = readPVSType(stream);
if (pvs === PVS.ENTER) {
const packetEntity = readEnterPVS(stream, entityId, match);
applyEntityUpdate(packetEntity, match.getSendTable(packetEntity.serverClass.dataTable), stream);
if (updatedBaseLine) {
const newBaseLine: SendProp[] = [];
newBaseLine.concat(packetEntity.props);
match.baseLineCache[packetEntity.serverClass.id] = packetEntity.clone();
}
packetEntity.inPVS = true;
receivedEntities.push(packetEntity);
} else if (pvs === PVS.PRESERVE) {
const packetEntity = getPacketEntityForExisting(entityId, match, pvs);
applyEntityUpdate(packetEntity, match.getSendTable(packetEntity.serverClass.dataTable), stream);
receivedEntities.push(packetEntity);
} else {
if (match.entityClasses[entityId]) {
const packetEntity = getPacketEntityForExisting(entityId, match, pvs);
receivedEntities.push(packetEntity);
}
}
}
}
const removedEntityIds: number[] = [];
if (isDelta) {
while (stream.readBoolean()) {
const entityId = stream.readBits(11);
removedEntityIds.push(entityId);
if (isDelta) {
while (stream.readBoolean()) {
const entityId = stream.readBits(11);
removedEntityIds.push(entityId);
}
}
}

View file

@ -2,5 +2,5 @@ import {Packet} from "../../Data/Packet";
import {BitStream} from 'bit-buffer';
import {Match} from "../../Data/Match";
export type Parser = (stream: BitStream, match?: Match) => Packet;
export type Parser = (stream: BitStream, match?: Match, skip: boolean = false) => Packet;
export type PacketParserMap = {[id: number]: Parser};

View file

@ -4,35 +4,37 @@ import {Match} from "../../Data/Match";
import {PacketEntity, PVS} from "../../Data/PacketEntity";
import {applyEntityUpdate} from "../EntityDecoder";
export function TempEntities(stream: BitStream, match: Match): TempEntitiesPacket { // 10: classInfo
export function TempEntities(stream: BitStream, match: Match, skip: boolean = false): TempEntitiesPacket { // 10: classInfo
const entityCount = stream.readBits(8);
const length = readVarInt(stream);
const end = stream.index + length;
let entity: PacketEntity|null = null;
let entities: PacketEntity[] = [];
for (let i = 0; i < entityCount; i++) {
const delay = (stream.readBoolean()) ? stream.readUint8() / 100 : 0; //unused it seems
if (stream.readBoolean()) {
const classId = stream.readBits(match.classBits);
const serverClass = match.serverClasses[classId - 1];
// no clue why the -1 but it works
// maybe because world (id=0) can never be temp
// but it's not like the -1 saves any space
const sendTable = match.getSendTable(serverClass.dataTable);
entity = new PacketEntity(serverClass, 0, PVS.ENTER);
applyEntityUpdate(entity, sendTable, stream);
entities.push(entity);
} else {
if (entity) {
applyEntityUpdate(entity, match.getSendTable(entity.serverClass.dataTable), stream);
if (!skip) {
for (let i = 0; i < entityCount; i++) {
const delay = (stream.readBoolean()) ? stream.readUint8() / 100 : 0; //unused it seems
if (stream.readBoolean()) {
const classId = stream.readBits(match.classBits);
const serverClass = match.serverClasses[classId - 1];
// no clue why the -1 but it works
// maybe because world (id=0) can never be temp
// but it's not like the -1 saves any space
const sendTable = match.getSendTable(serverClass.dataTable);
entity = new PacketEntity(serverClass, 0, PVS.ENTER);
applyEntityUpdate(entity, sendTable, stream);
entities.push(entity);
} else {
throw new Error("no entity set to update");
if (entity) {
applyEntityUpdate(entity, match.getSendTable(entity.serverClass.dataTable), stream);
} else {
throw new Error("no entity set to update");
}
}
}
}
if (end - stream.index > 8) {
throw new Error("unexpected content after TempEntities");
if (end - stream.index > 8) {
throw new Error("unexpected content after TempEntities");
}
}
stream.index = end;