mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
add parsing of serverclasses from datatable
This commit is contained in:
parent
2579197ab6
commit
a619cd1404
2 changed files with 50 additions and 1 deletions
40
datatable.js
40
datatable.js
|
|
@ -11,6 +11,7 @@ DataTableParser.prototype.parse = function () {
|
|||
// https://github.com/LestaD/SourceEngine2007/blob/43a5c90a5ada1e69ca044595383be67f40b33c61/src_main/engine/dt_recv_eng.cpp#L310
|
||||
// https://github.com/PazerOP/DemoLib/blob/master/DemoLib/Commands/DemoDataTablesCommand.cs
|
||||
var tables = [];
|
||||
var i, j;
|
||||
while (this.stream.readBoolean()) {
|
||||
var needsDecoder = this.stream.readBoolean();
|
||||
var tableName = this.stream.readASCIIString();
|
||||
|
|
@ -19,7 +20,7 @@ DataTableParser.prototype.parse = function () {
|
|||
|
||||
// get props metadata
|
||||
var arrayElementProp;
|
||||
for (var i = 0; i < numProps; i++) {
|
||||
for (i = 0; i < numProps; i++) {
|
||||
var propType = this.stream.readBits(5);
|
||||
var propName = this.stream.readASCIIString();
|
||||
var nFlagsBits = 16; // might be 11 (old?), 13 (new?), 16(networked) or 17(??)
|
||||
|
|
@ -66,6 +67,37 @@ DataTableParser.prototype.parse = function () {
|
|||
tables.push(table);
|
||||
}
|
||||
this.match.sendTables = tables;
|
||||
|
||||
// link referenced tables
|
||||
for (i = 0; i < tables.length; i++) {
|
||||
for (j = 0; j < tables[i].props.length; j++) {
|
||||
if (tables[i].props[j].type === SendProp.types.DPT_DataTable) {
|
||||
tables[i].props[j].table = this.match.getSendTable(tables[i].props[j].excludeDTName);
|
||||
tables[i].props[j].excludeDTName = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var serverClasses = this.stream.readUint16(); // short
|
||||
if (serverClasses <= 0) {
|
||||
throw "expected one or more serverclasses";
|
||||
}
|
||||
|
||||
for (i = 0; i < serverClasses; i++) {
|
||||
var classId = this.stream.readUint16();
|
||||
if (classId > serverClasses) {
|
||||
throw "invalid class id";
|
||||
}
|
||||
var className = this.stream.readASCIIString();
|
||||
var dataTable = this.stream.readASCIIString();
|
||||
this.match.serverClasses.push(new ServerClass(classId, className, dataTable));
|
||||
}
|
||||
|
||||
var bitsLeft = (this.length * 8) - this.stream._index;
|
||||
if (bitsLeft > 7) {
|
||||
throw "unexpected remaining data in datatable (" + bitsLeft + " bits)";
|
||||
}
|
||||
|
||||
return tables;
|
||||
};
|
||||
|
||||
|
|
@ -143,6 +175,12 @@ SendProp.formatFlags = function (flags) {
|
|||
return names;
|
||||
};
|
||||
|
||||
var ServerClass = function (id, name, dataTable) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.dataTable = dataTable;
|
||||
};
|
||||
|
||||
function recvClassInfos(stream, needsDecoder) {
|
||||
|
||||
}
|
||||
|
|
|
|||
11
match.js
11
match.js
|
|
@ -8,6 +8,17 @@ var Match = function () {
|
|||
this.intervalPerTick = 0;
|
||||
this.entities = [];
|
||||
this.stringTables = [];
|
||||
this.sendTables = [];
|
||||
this.serverClasses = [];
|
||||
};
|
||||
|
||||
Match.prototype.getSendTable = function (name) {
|
||||
for (var i = 0; i < this.sendTables.length; i++) {
|
||||
if (this.sendTables[i].name === name) {
|
||||
return this.sendTables[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
Match.prototype.getState = function () {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue