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

use both stringtable message and createstringtable packet

This commit is contained in:
Robin Appelman 2017-03-09 17:51:26 +01:00
commit 4af1c492dc
3 changed files with 58 additions and 61 deletions

View file

@ -4,6 +4,9 @@ import {StringTableEntry} from "../Data/StringTable";
export function handleStringTable(packet: StringTablePacket, match: Match) {
for (const table of packet.tables) {
if (!match.getStringTable(table.name)) {
match.stringTables.push(table);
}
if (table.name === 'userinfo') {
for (const userData of table.entries) {
if (userData.extraData) {

View file

@ -1,72 +1,67 @@
import {Parser} from './Parser';
import {StringTableEntry} from "../../Data/StringTable";
import {RemoteInfo} from "dgram";
import {StringTableEntry, StringTable as StringTableObject} from "../../Data/StringTable";
import {StringTablePacket} from "../../Data/Packet";
export class StringTable extends Parser {
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,
// 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
// tables: []
// }];
// https://github.com/StatsHelix/demoinfo/blob/3d28ea917c3d44d987b98bb8f976f1a3fcc19821/DemoInfo/ST/StringTableParser.cs
const tableCount = this.stream.readUint8();
let tables: StringTableObject[] = [];
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: StringTableEntry;
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
}];
}
entry.extraData = this.stream.readBitStream(extraDataLength * 8);
}
entries.push(entry);
}
const table: StringTableObject = {
entries,
name: tableName,
maxEntries: entryCount
};
tables.push(table);
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[] {

View file

@ -59,7 +59,6 @@ export function CreateStringTable(stream: BitStream, match: Match): StringTableP
parseStringTable(data, table, entityCount, match);
match.stringTables.push(table);
return {
packetType: 'stringTable',
tables: [table]