mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
datatables wip
This commit is contained in:
parent
40877ddaf1
commit
9cb24b9a74
5 changed files with 101 additions and 65 deletions
15
datatable.js
Normal file
15
datatable.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
var DataTable = function (type, tick, stream, length) {
|
||||
this.type = type;
|
||||
this.tick = tick;
|
||||
this.stream = stream;
|
||||
this.length = length;//length in bytes
|
||||
};
|
||||
|
||||
DataTable.prototype.parse = function () {
|
||||
//while (this.stream.byteIndex < this.length) {
|
||||
//console.log(this.stream.readASCIIString());
|
||||
//}
|
||||
return [];
|
||||
};
|
||||
|
||||
module.exports = DataTable;
|
||||
85
packet.js
85
packet.js
|
|
@ -1,5 +1,6 @@
|
|||
var ParserGenerator = require('./parsergenerator');
|
||||
var StringTable = require('./stringtable');
|
||||
var PacketStringTable = require('./packetstringtable');
|
||||
|
||||
function logBase2 (num) {
|
||||
var result = 0;
|
||||
|
|
@ -44,7 +45,6 @@ Packet.parseGameEvent = function (eventId, stream) {
|
|||
return 'unknown';
|
||||
}
|
||||
var eventDescription = this.gameEventMap[eventId];
|
||||
//console.log(eventDescription);
|
||||
var values = {};
|
||||
for (var i = 0; i < eventDescription.entries.length; i++) {
|
||||
var entry = eventDescription.entries[i];
|
||||
|
|
@ -72,7 +72,9 @@ Packet.getGameEventValue = function (stream, entry) {
|
|||
case 6:
|
||||
return !!stream.readBits(1);
|
||||
case 7:
|
||||
return 'local value'
|
||||
return 'local value';
|
||||
default:
|
||||
throw 'invalid game event type';
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -127,7 +129,7 @@ Packet.parsers = {
|
|||
// https://coldemoplayer.googlecode.com/svn/branches/2.0/code/plugins/CDP.Source/Messages/SvcCreateStringTable.cs
|
||||
var name = stream.readASCIIString();
|
||||
var maxEntries = stream.readBits(16);
|
||||
var bits = Math.log(maxEntries) / Math.LN2;
|
||||
var bits = logBase2(maxEntries);
|
||||
var numEntries = stream.readBits(bits + 1);
|
||||
var length = stream.readBits(20);
|
||||
var userDataFixedSize = !!stream.readBits(1);
|
||||
|
|
@ -140,12 +142,32 @@ Packet.parsers = {
|
|||
var stringTable = new PacketStringTable(name, maxEntries, bits, userDataFixedSize, userSize || -1, userDataBits || -1, numEntries);
|
||||
stringTable.parse(stream);
|
||||
//console.log(stringTable);
|
||||
//console.log(stream.readBits(6));
|
||||
//console.log(stream.readASCIIString());
|
||||
//maxEntries = stream.readBits(16);
|
||||
//console.log(maxEntries);
|
||||
//bits = logBase2(maxEntries);
|
||||
//numEntries = stream.readBits(bits + 1);
|
||||
//console.log('entries: ' + numEntries);
|
||||
//console.log(stream.readBits(175));
|
||||
//for (var i = 0; i < numEntries; i++) {
|
||||
// console.log(stream.readBits(6));
|
||||
// console.log(stream.readASCIIString());
|
||||
//}
|
||||
//console.log(stream.readASCIIString());
|
||||
//console.log(stream.readASCIIString());
|
||||
//console.log();
|
||||
//console.log(length);
|
||||
//console.log(end - stream._index);
|
||||
//console.log();
|
||||
//throw false;
|
||||
|
||||
//if((end/8)> 50515){
|
||||
// console.log(stringTable);
|
||||
// throw 'found';
|
||||
//}
|
||||
//throw false;
|
||||
|
||||
stream._index = end;
|
||||
return {
|
||||
packetType: 'createStringTable',
|
||||
|
|
@ -195,8 +217,8 @@ Packet.parsers = {
|
|||
strings: strings
|
||||
}
|
||||
},
|
||||
14: ParserGenerator.make('voiceInit', 'coded{s}quality{8}'),
|
||||
15: ParserGenerator.make('voiceData', 'client{8}proximity{8}length{16}data{$length}'),
|
||||
14: ParserGenerator.make('voiceInit', 'codec{s}quality{8}'),
|
||||
15: ParserGenerator.make('voiceData', 'client{8}proximity{8}length{16}_{$length}'),
|
||||
17: function (stream) {
|
||||
var reliable = !!stream.readBits(1);
|
||||
var num = (reliable) ? 1 : stream.readBits(8);
|
||||
|
|
@ -269,6 +291,8 @@ Packet.parsers = {
|
|||
type: type
|
||||
}
|
||||
}
|
||||
console.log(result);
|
||||
console.log(((pos + length) - stream._index) + ' bits left');
|
||||
stream._index = pos + length;
|
||||
return result;
|
||||
},
|
||||
|
|
@ -285,6 +309,7 @@ Packet.parsers = {
|
|||
}
|
||||
},
|
||||
26: function (stream) {
|
||||
// todo
|
||||
var maxEntries = stream.readBits(11);
|
||||
var isDelta = !!stream.readBits(1);
|
||||
if (isDelta) {
|
||||
|
|
@ -412,54 +437,4 @@ var UserMessageType = {
|
|||
HapMeleeContact: 57
|
||||
};
|
||||
|
||||
var PacketStringTable = function (name, maxEntries, entryBits, userDataFixedSize, userDataSize, userDataSizeBits, numEntries) {
|
||||
this.name = name;
|
||||
this.maxEntries = maxEntries;
|
||||
this.entryBits = entryBits;
|
||||
this.userDataFixedSize = userDataFixedSize;
|
||||
this.userDataSize = userDataSize;
|
||||
this.userDataSizeBits = userDataSizeBits;
|
||||
this.numEntries = numEntries;
|
||||
this.id = PacketStringTable.tables.length;
|
||||
this.strings = [];
|
||||
PacketStringTable.tables.push(this);
|
||||
};
|
||||
|
||||
PacketStringTable.prototype.parse = function (stream) {
|
||||
var entryIndex, lastEntry = -1;
|
||||
for (var i = 0; i < this.numEntries; i++) {
|
||||
entryIndex = lastEntry + 1;
|
||||
this.strings.push(stream.readASCIIString());
|
||||
//if (!stream.readBits(1)) {
|
||||
// entryIndex = stream.readBits(this.entryBits);
|
||||
//}
|
||||
//lastEntry = entryIndex;
|
||||
//if (entryIndex < 0 || entryIndex >= this.maxEntries) {
|
||||
// throw 'invalid index';
|
||||
//}
|
||||
//var string = '';
|
||||
//if (stream.readBits(1)) {
|
||||
// if (stream.readBits(1)) {
|
||||
// throw 'substr not implented';
|
||||
// } else {
|
||||
// string = stream.readASCIIString();
|
||||
// }
|
||||
//}
|
||||
|
||||
if (stream.readBits(1)) { //user data
|
||||
if (this.userDataFixedSize) {
|
||||
var userData = stream.readBits(this.userDataSizeBits)
|
||||
} else {
|
||||
var bits = stream.readBits(14);
|
||||
userData = stream.readBits(bits);
|
||||
}
|
||||
console.log('userdata: ' + userData);
|
||||
}
|
||||
|
||||
//this.strings.push(string);
|
||||
}
|
||||
};
|
||||
|
||||
PacketStringTable.tables = [];
|
||||
|
||||
module.exports = Packet;
|
||||
|
|
|
|||
51
packetstringtable.js
Normal file
51
packetstringtable.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
var PacketStringTable = function (name, maxEntries, entryBits, userDataFixedSize, userDataSize, userDataSizeBits, numEntries) {
|
||||
this.name = name;
|
||||
this.maxEntries = maxEntries;
|
||||
this.entryBits = entryBits;
|
||||
this.userDataFixedSize = userDataFixedSize;
|
||||
this.userDataSize = userDataSize;
|
||||
this.userDataSizeBits = userDataSizeBits;
|
||||
this.numEntries = numEntries;
|
||||
this.id = PacketStringTable.tables.length;
|
||||
this.strings = [];
|
||||
PacketStringTable.tables.push(this);
|
||||
};
|
||||
|
||||
PacketStringTable.prototype.parse = function (stream) {
|
||||
var entryIndex, lastEntry = -1;
|
||||
for (var i = 0; i < this.numEntries; i++) {
|
||||
entryIndex = lastEntry + 1;
|
||||
this.strings.push(stream.readASCIIString());
|
||||
//if (!stream.readBits(1)) {
|
||||
// entryIndex = stream.readBits(this.entryBits);
|
||||
//}
|
||||
//lastEntry = entryIndex;
|
||||
//if (entryIndex < 0 || entryIndex >= this.maxEntries) {
|
||||
// throw 'invalid index';
|
||||
//}
|
||||
//var string = '';
|
||||
//if (stream.readBits(1)) {
|
||||
// if (stream.readBits(1)) {
|
||||
// throw 'substr not implented';
|
||||
// } else {
|
||||
// string = stream.readASCIIString();
|
||||
// }
|
||||
//}
|
||||
|
||||
if (stream.readBits(1)) { //user data
|
||||
if (this.userDataFixedSize) {
|
||||
var userData = stream.readBits(this.userDataSizeBits)
|
||||
} else {
|
||||
var bits = stream.readBits(14);
|
||||
userData = stream.readBits(bits);
|
||||
}
|
||||
console.log('userdata: ' + userData);
|
||||
}
|
||||
|
||||
//this.strings.push(string);
|
||||
}
|
||||
};
|
||||
|
||||
PacketStringTable.tables = [];
|
||||
|
||||
module.exports = PacketStringTable;
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
var Packet = require('./packet');
|
||||
var ConsoleCmd = require('./consolecmd');
|
||||
var StringTable = require('./stringtable');
|
||||
var DataTable = require('./datatable');
|
||||
var BitStream = require('bit-buffer').BitStream;
|
||||
|
||||
var Parser = function (steam) {
|
||||
|
|
@ -136,10 +137,10 @@ Parser.prototype.readMessage = function () {
|
|||
case Parser.MessageType.ConsoleCmd:
|
||||
return new ConsoleCmd(type, tick, data, length);
|
||||
case Parser.MessageType.UserCmd:
|
||||
console.log('usercmd');
|
||||
return true;
|
||||
case Parser.MessageType.DataTables:
|
||||
//console.log('datatable');
|
||||
return true;
|
||||
return new DataTable(type, tick, data, length);
|
||||
case Parser.MessageType.StringTables:
|
||||
return new StringTable(type, tick, data, length);
|
||||
default:
|
||||
|
|
|
|||
10
test.js
10
test.js
|
|
@ -7,12 +7,6 @@ fs.readFile("gully.dem", function (err, data) {
|
|||
var parser = demo.getParser();
|
||||
var head = parser.readHeader();
|
||||
//console.log(parser.readHeader());
|
||||
//var message;
|
||||
//parser.parseBody()
|
||||
console.log(parser.parseBody());
|
||||
//while (message = parser.readMessage()) {
|
||||
// if (message.parse) {
|
||||
// message.parse();
|
||||
// }
|
||||
//}
|
||||
parser.parseBody()
|
||||
//console.log(parser.parseBody());
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue