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

fix some typings

This commit is contained in:
Robin Appelman 2017-02-12 16:32:38 +01:00
commit ba7ce734e3
7 changed files with 146 additions and 95 deletions

View file

@ -1,75 +1,77 @@
import {Parser} from './Parser';
import {StringTableEntry} from "../../Data/StringTable";
import {RemoteInfo} from "dgram";
import {StringTablePacket} from "../../Data/Packet";
export class StringTable extends Parser {
parse() {
parse(): StringTablePacket[] {
// we get the tables from the packets
return [{
packetType: 'stringTable',
tables: []
}];
// https://github.com/StatsHelix/demoinfo/blob/3d28ea917c3d44d987b98bb8f976f1a3fcc19821/DemoInfo/ST/StringTableParser.cs
const tableCount = this.stream.readUint8();
let tables = {};
let extraDataLength;
for (let i = 0; i < tableCount; i++) {
let entries:StringTableEntry[] = [];
const tableName = this.stream.readASCIIString();
const entryCount = this.stream.readUint16();
for (let j = 0; j < entryCount; j++) {
let entry;
try {
entry = {
text: this.stream.readUTF8String()
};
} catch (e) {
return [{
packetType: 'stringTable',
tables: tables
}];
}
if (this.stream.readBoolean()) {
extraDataLength = this.stream.readUint16();
if ((extraDataLength * 8) > this.stream.bitsLeft) {
// extradata to long, can't continue parsing the tables
// seems to happen in POV demos after the MyM update
return [{
packetType: 'stringTable',
tables: tables
}];
}
if (tableName === 'instancebaseline') {
this.match.staticBaseLines[parseInt(entry.text, 10)] = this.stream.readBitStream(8 * extraDataLength);
} else {
entry.extraData = this.readExtraData(extraDataLength);
}
}
entries.push(entry);
}
tables[tableName] = entries;
this.match.stringTables.push({
name: tableName,
entries: entries
});
if (this.stream.readBits(1)) {
this.stream.readASCIIString();
if (this.stream.readBits(1)) {
//throw 'more extra data not implemented';
extraDataLength = this.stream.readBits(16);
this.stream.readBits(extraDataLength);
}
}
}
return [{
packetType: 'stringTable',
tables: tables
}];
// const tableCount = this.stream.readUint8();
// let tables = {};
// let extraDataLength;
// for (let i = 0; i < tableCount; i++) {
// let entries: StringTableEntry[] = [];
// const tableName = this.stream.readASCIIString();
// const entryCount = this.stream.readUint16();
// for (let j = 0; j < entryCount; j++) {
// let entry;
// try {
// entry = {
// text: this.stream.readUTF8String()
// };
// } catch (e) {
// return [{
// packetType: 'stringTable',
// tables: tables
// }];
// }
// if (this.stream.readBoolean()) {
// extraDataLength = this.stream.readUint16();
// if ((extraDataLength * 8) > this.stream.bitsLeft) {
// // extradata to long, can't continue parsing the tables
// // seems to happen in POV demos after the MyM update
// return [{
// packetType: 'stringTable',
// tables: tables
// }];
// }
// if (tableName === 'instancebaseline') {
// this.match.staticBaseLines[parseInt(entry.text, 10)] = this.stream.readBitStream(8 * extraDataLength);
// } else {
// entry.extraData = this.readExtraData(extraDataLength);
// }
// }
// entries.push(entry);
// }
// tables[tableName] = entries;
// this.match.stringTables.push({
// name: tableName,
// entries: entries,
// maxEntries: 0
// });
// if (this.stream.readBits(1)) {
// this.stream.readASCIIString();
// if (this.stream.readBits(1)) {
// //throw 'more extra data not implemented';
// extraDataLength = this.stream.readBits(16);
// this.stream.readBits(extraDataLength);
// }
// }
// }
// return [{
// packetType: 'stringTable',
// tables: tables
// }];
}
readExtraData(length):string[] {
const end = this.stream.index + (length * 8);
let data:string[] = [];
readExtraData(length): string[] {
const end = this.stream.index + (length * 8);
let data: string[] = [];
//console.log(this.stream.readUTF8String());
data.push(this.stream.readUTF8String());
while (this.stream.index < end && this.stream.index < (this.stream.length - 7)) { // -7 because we need a full byte

View file

@ -1,11 +1,12 @@
import {Parser} from './Parser';
import {Packet} from "../../Data/Packet";
export function make(name: string, definition: string): Parser {
const parts = definition.substr(0, definition.length - 1).split('}');//remove leading } to prevent empty part
const items = parts.map(function (part) {
return part.split('{');
});
return function (stream) {
return function (stream):Packet {
let result = {
'packetType': name
};
@ -19,7 +20,7 @@ export function make(name: string, definition: string): Parser {
} catch (e) {
throw new Error('Failed reading pattern ' + definition + '. ' + e);
}
return result;
return <Packet>result;
}
}

View file

@ -80,7 +80,7 @@ export function UserMessage(stream: BitStream): UserMessagePacket { // 23: user
result = {
packetType: 'unknownUserMessage',
type: type
}
};
}
stream.index = pos + length;
return result;