mirror of
https://github.com/demostf/demo.js
synced 2026-06-03 16:44:12 +02:00
Add binary
This commit is contained in:
parent
7c8ad0cc36
commit
7402548783
7 changed files with 74 additions and 133 deletions
32
bin/analyse.js
Normal file
32
bin/analyse.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
var Demo = require('../demo');
|
||||
var fs = require('fs');
|
||||
var argv = require('minimist')(process.argv.slice(2), {boolean: true});
|
||||
|
||||
if (argv._.length !== 1) {
|
||||
console.log('Usage: "node analyse [--strings] [--dump] [--head] FILE"');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var echo = function (data) {
|
||||
var string = JSON.stringify(data, null, 2);
|
||||
console.log(string);
|
||||
};
|
||||
|
||||
fs.readFile(argv._[0], function (err, data) {
|
||||
if (err) throw err;
|
||||
var demo = Demo.fromNodeBuffer(data);
|
||||
var parser = demo.getParser();
|
||||
var head = parser.readHeader();
|
||||
if (argv.head) {
|
||||
echo(head);
|
||||
return;
|
||||
}
|
||||
var body = parser.parseBody();
|
||||
if (argv.dump) {
|
||||
echo(parser.packets);
|
||||
} else if (argv.strings) {
|
||||
echo(parser.strings);
|
||||
} else {
|
||||
echo(body);
|
||||
}
|
||||
});
|
||||
13
package.json
13
package.json
|
|
@ -1,5 +1,12 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"bit-buffer": "icewind1991/bit-buffer"
|
||||
}
|
||||
"name": "demos.js",
|
||||
"description": "A parser for TF2 demo files",
|
||||
"version": "0.1.0",
|
||||
"bin": {
|
||||
"demo-analyse": "./bin/analyse.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"bit-buffer": "icewind1991/bit-buffer",
|
||||
"minimist": "1.1.x"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
12
packet.js
12
packet.js
|
|
@ -31,6 +31,10 @@ Object.defineProperty(Packet.prototype, 'bitsLeft', {
|
|||
});
|
||||
|
||||
Packet.prototype.parse = function () {
|
||||
//var table = new PacketStringTable(this.stream);
|
||||
//table.searchIds();
|
||||
//return [];
|
||||
|
||||
var packets = [];
|
||||
while (this.bitsLeft > 6) { // last 6 bits for NOOP
|
||||
var type = this.stream.readBits(6);
|
||||
|
|
@ -138,6 +142,14 @@ Packet.parsers = {
|
|||
};
|
||||
},
|
||||
13: function (stream) {
|
||||
var stringTable = new PacketStringTable(stream);
|
||||
stringTable.parse();
|
||||
return {
|
||||
packetType: 'createStringTable',
|
||||
table : stringTable
|
||||
};
|
||||
|
||||
|
||||
var tableId = stream.readBits(5);
|
||||
var changeEntries = stream.readBits(1) ? stream.readBits(16) : 1;
|
||||
var length = stream.readBits(20);
|
||||
|
|
|
|||
|
|
@ -19,122 +19,7 @@ PacketStringTable.prototype.parse = function () {
|
|||
//todo
|
||||
// https://coldemoplayer.googlecode.com/svn/branches/2.0/code/plugins/CDP.Source/Messages/SvcCreateStringTable.cs
|
||||
|
||||
//while (true) {//skip untill userinfo
|
||||
// var pos = this.stream._index;
|
||||
// if (this.stream.readASCIIString() === 'userinfo') {
|
||||
// this.stream._index = pos;
|
||||
// console.log(pos);
|
||||
// break;
|
||||
// }
|
||||
// this.stream._index = pos + 1;
|
||||
//}
|
||||
//this.stream._index = 442393; // process
|
||||
//this.stream._index = 472495;
|
||||
|
||||
//this.name = this.stream.readASCIIString();
|
||||
//var maxEntries = this.stream.readBits(16);
|
||||
//var bits = logBase2(maxEntries);
|
||||
//this.numEntries = this.stream.readBits(bits + 1);
|
||||
//var length = this.stream.readBits(20);
|
||||
//var userDataFixedSize = this.stream.readBoolean(1);
|
||||
//var userSize = 0;
|
||||
//var userDataBits = 0;
|
||||
//if (userDataFixedSize) {
|
||||
// console.log('fixed');
|
||||
// userSize = this.stream.readBits(12);
|
||||
// userDataBits = this.stream.readBits(4);
|
||||
// console.log(userSize);
|
||||
// console.log(userDataBits);
|
||||
//}
|
||||
//
|
||||
//console.log('table: ' + this.name);
|
||||
//console.log('entries: ' + this.numEntries);
|
||||
|
||||
//var pos = this.stream._index;
|
||||
|
||||
var users = this.searchIds();
|
||||
//this.stream.index = pos + length;
|
||||
return users;
|
||||
|
||||
//start expermiment
|
||||
|
||||
//console.log(this.stream.readBits(2));
|
||||
this.stream.readBits(5 + 8 * 8);
|
||||
for (i = 0; i < 12; i++) {
|
||||
console.log(this.stream.readBits(8));
|
||||
}
|
||||
console.log(this.stream.readBits(2));
|
||||
console.log('name: ' + this.stream.readUTF8String());
|
||||
for (i = 0; i < 8; i++) {
|
||||
console.log(this.stream.readBits(8));
|
||||
}
|
||||
console.log('id: ' + this.stream.readUTF8String());
|
||||
console.log(this.stream.readBits(8));
|
||||
|
||||
console.log(this.stream.readUTF8String(32));
|
||||
// end TV
|
||||
// start icewind
|
||||
|
||||
for (i = 0; i < 12; i++) {
|
||||
console.log(this.stream.readBits(8));
|
||||
}
|
||||
console.log(this.stream.readBits(2));
|
||||
console.log('name: ' + this.stream.readUTF8String());
|
||||
for (i = 0; i < 7; i++) {
|
||||
console.log(this.stream.readBits(8));
|
||||
}
|
||||
console.log('id: ' + this.stream.readASCIIString(14));
|
||||
// end icewind
|
||||
// start gat
|
||||
|
||||
console.log(this.stream.readBits(8));
|
||||
console.log(this.stream.readUTF8String(32));
|
||||
//console.log(this.stream.readUTF8String());
|
||||
console.log(this.stream.readBits(8 * 9));
|
||||
console.log(this.stream.readBits(2));
|
||||
//console.log('name: ' + this.stream.readASCIIString());
|
||||
for (i = 0; i < 7; i++) {
|
||||
console.log(this.stream.readBits(8));
|
||||
}
|
||||
console.log('id: ' + this.stream.readASCIIString(14));
|
||||
//console.log(this.stream.readASCIIString());
|
||||
//console.log(this.stream.readASCIIString());
|
||||
//console.log(this.stream.readASCIIString());
|
||||
//console.log(this.stream.readBits(8));
|
||||
//console.log(this.stream.readASCIIString());
|
||||
//console.log(this.stream.readBits(2 + 8 * 14));
|
||||
//console.log(this.stream.readASCIIString());
|
||||
//console.log(this.stream.readBits(7 * 8));
|
||||
//console.log(this.stream.readASCIIString());
|
||||
//process.exit();
|
||||
|
||||
for (i = 0; i < this.numEntries; i++) {
|
||||
var pos = this.stream._index;
|
||||
var string = this.stream.readASCIIString();
|
||||
console.log('string: "' + string + '"');
|
||||
if (string.length > 4) {
|
||||
if (string.charCodeAt(2) > 128) {
|
||||
this.stream._index = pos;
|
||||
this.stream.readBits(1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.strings.push(string);
|
||||
|
||||
if (this.stream.readBits(1)) { //user data
|
||||
if (this.userDataFixedSize) {
|
||||
var userData = this.stream.readBits(this.userDataSizeBits)
|
||||
} else {
|
||||
bits = this.stream.readBits(14);
|
||||
userData = this.stream.readASCIIString(bits);
|
||||
}
|
||||
console.log('userdata: ' + userData);
|
||||
//console.log(this.stream.readBits(5));
|
||||
//stream.readBits(5);
|
||||
}
|
||||
|
||||
//this.strings.push(string);
|
||||
}
|
||||
return this.searchIds();
|
||||
};
|
||||
|
||||
PacketStringTable.prototype.parsePlayerInfo = function () {
|
||||
|
|
@ -146,11 +31,8 @@ PacketStringTable.prototype.searchIds = function () {
|
|||
var validChar = function (charCode) {
|
||||
return charCode === 91 || charCode === 93 || charCode === 58 || (charCode > 47 && charCode < 58); // [ ] : 0-9
|
||||
};
|
||||
|
||||
console.log('startSearch');
|
||||
console.log('length ' + this.stream._view._view.length);
|
||||
this.stream.readBits(9);
|
||||
var users = {};
|
||||
var numFound = 0;
|
||||
while (true) {
|
||||
var found = false;
|
||||
while (this.stream._index < ((this.stream._view._view.length - 1) * 8)) {
|
||||
|
|
@ -166,7 +48,10 @@ PacketStringTable.prototype.searchIds = function () {
|
|||
}
|
||||
}
|
||||
if (!found) {
|
||||
console.log(users);
|
||||
if (numFound) {
|
||||
//console.log(users);
|
||||
}
|
||||
this.stream._index = this.stream._view._view.length * 8;
|
||||
return users;
|
||||
}
|
||||
while (validChar(this.stream.readBits(8))) {
|
||||
|
|
@ -181,9 +66,8 @@ PacketStringTable.prototype.searchIds = function () {
|
|||
steamId += ']';
|
||||
}
|
||||
users[userId] = steamId;
|
||||
numFound++;
|
||||
}
|
||||
console.log(users);
|
||||
//process.exit();
|
||||
};
|
||||
|
||||
PacketStringTable.tables = [];
|
||||
|
|
|
|||
14
parser.js
14
parser.js
|
|
@ -7,12 +7,14 @@ var BitStream = require('bit-buffer').BitStream;
|
|||
var Parser = function (steam) {
|
||||
this.stream = steam;
|
||||
this.state = {
|
||||
chat : [],
|
||||
users : {},
|
||||
deaths: [],
|
||||
rounds: [],
|
||||
chat : [],
|
||||
users : {},
|
||||
deaths : [],
|
||||
rounds : [],
|
||||
intervalPerTick: 0
|
||||
};
|
||||
this.packets = [];
|
||||
this.strings = {};
|
||||
};
|
||||
|
||||
Parser.MessageType = {
|
||||
|
|
@ -49,6 +51,9 @@ Parser.prototype.parseBody = function () {
|
|||
var packets = message.parse();
|
||||
for (i = 0; i < packets.length; i++) {
|
||||
var packet = packets[i];
|
||||
if (packet) {
|
||||
this.packets.push(packet);
|
||||
}
|
||||
if (!packet) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -103,6 +108,7 @@ Parser.prototype.parseBody = function () {
|
|||
}
|
||||
}
|
||||
}
|
||||
this.strings = StringTable.tables;
|
||||
return this.state;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -12,12 +12,12 @@ Generator.make = function (name, string) {
|
|||
try {
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var value = Generator.readItem(stream, items[i][1], result);
|
||||
if(items[i][0] !== '_'){
|
||||
if (items[i][0] !== '_') {
|
||||
result[items[i][0]] = value;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
throw 'Failed reading pattern ' + string;
|
||||
throw 'Failed reading pattern ' + string + '. ' + e;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
2
test.js
2
test.js
|
|
@ -1,7 +1,7 @@
|
|||
var Demo = require('./demo');
|
||||
var fs = require('fs');
|
||||
|
||||
fs.readFile("upward.dem", function (err, data) {
|
||||
fs.readFile("process.dem", function (err, data) {
|
||||
if (err) throw err;
|
||||
var demo = Demo.fromNodeBuffer(data);
|
||||
var parser = demo.getParser();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue