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

Better player demo support

This commit is contained in:
Robin Appelman 2015-01-25 00:11:37 +01:00
commit f5f568df33
4 changed files with 38 additions and 22 deletions

View file

@ -7,7 +7,7 @@ var ConsoleCmd = function (type, tick, stream, length) {
ConsoleCmd.prototype.parse = function () { ConsoleCmd.prototype.parse = function () {
var cmd = this.stream.readASCIIString(); var cmd = this.stream.readASCIIString();
console.log("cmd " + cmd); //console.log("cmd " + cmd);
return cmd; return cmd;
}; };

View file

@ -78,8 +78,22 @@ Packet.getGameEventValue = function (stream, entry) {
Packet.parsers = { Packet.parsers = {
0 : function () { 0 : function () {
}, },
2 : ParserGenerator.make('file', 'transferId{32}fileName{s}requested{b}'),
3 : ParserGenerator.make('netTick', 'tick{32}frameTime{16}stdDev{16}'), 3 : ParserGenerator.make('netTick', 'tick{32}frameTime{16}stdDev{16}'),
4: ParserGenerator.make('stringCmd', 'command{s}'),
5 : function (stream) {
var count = stream.readBits(8);
var vars = {};
for (var i = 0; i < count; i++) {
vars[stream.readASCIIString()] = stream.readASCIIString();
}
return {
packetType: 'setConVar',
vars : vars
}
},
6 : ParserGenerator.make('sigOnState', 'state{8}count{32}'), 6 : ParserGenerator.make('sigOnState', 'state{8}count{32}'),
7 : ParserGenerator.make('print', 'value{s}'),
8 : ParserGenerator.make('serverInfo', 8 : ParserGenerator.make('serverInfo',
'version{16}serverCount{32}stv{b}dedicated{b}maxCrc{32}maxClasses{16}' + 'version{16}serverCount{32}stv{b}dedicated{b}maxCrc{32}maxClasses{16}' +
'mapHash{128}playerCount{8}maxPlayerCount{8}intervalPerTick{f32}platform{s1}' + 'mapHash{128}playerCount{8}maxPlayerCount{8}intervalPerTick{f32}platform{s1}' +

View file

@ -8,30 +8,32 @@ var StringTable = function (type, tick, stream, length) {
StringTable.prototype.parse = function () { StringTable.prototype.parse = function () {
var tableCount = this.stream.readBits(8); var tableCount = this.stream.readBits(8);
var tables = {}; var tables = {};
for (var i = 0; i < tableCount; i++) { try {
var entries = []; for (var i = 0; i < tableCount; i++) {
var tableName = this.stream.readASCIIString(); var entries = [];
var entryCount = this.stream.readBits(16); var tableName = this.stream.readASCIIString();
for (var j = 0; j < entryCount; j++) { var entryCount = this.stream.readBits(16);
var entry = { for (var j = 0; j < entryCount; j++) {
text: this.stream.readASCIIString() var entry = {
}; text: this.stream.readASCIIString()
if (this.stream.readBits(1)) { };
var extraDataLength = this.stream.readBits(16); if (this.stream.readBits(1)) {
entry.extraData = this.stream.readASCIIString(extraDataLength); var extraDataLength = this.stream.readBits(16);
entry.extraData = this.stream.readASCIIString(extraDataLength);
}
entries.push(entry);
} }
entries.push(entry); tables[tableName] = entries;
}
tables[tableName] = entries;
if (this.stream.readBits(1)) {
console.log(this.stream.readASCIIString());
if (this.stream.readBits(1)) { if (this.stream.readBits(1)) {
throw 'more extra data not implemted'; console.log(this.stream.readASCIIString());
var extraDataLength = this.stream.readBits(16); if (this.stream.readBits(1)) {
this.stream.readBits(extraDataLength); //throw 'more extra data not implemted';
var extraDataLength = this.stream.readBits(16);
this.stream.readBits(extraDataLength);
}
} }
} }
} }catch(e){}
//console.log(tables); //console.log(tables);
return [{ return [{
packetType: 'stringTable', packetType: 'stringTable',

View file

@ -1,7 +1,7 @@
var Demo = require('./demo'); var Demo = require('./demo');
var fs = require('fs'); var fs = require('fs');
fs.readFile("snakewater.dem", function (err, data) { fs.readFile("lake.dem", function (err, data) {
if (err) throw err; if (err) throw err;
var demo = Demo.fromNodeBuffer(data); var demo = Demo.fromNodeBuffer(data);
var parser = demo.getParser(); var parser = demo.getParser();