mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
bsp decal
This commit is contained in:
parent
d5cd7e0755
commit
0ec87d3471
4 changed files with 122 additions and 23 deletions
67
browser.js
67
browser.js
|
|
@ -553,9 +553,9 @@ Packet.parsers = {
|
||||||
|
|
||||||
|
|
||||||
for (var i = 0; i < numEntries; i++) {
|
for (var i = 0; i < numEntries; i++) {
|
||||||
//data.push(stream.readASCIIString());
|
data.push(stream.readASCIIString());
|
||||||
//stream.readBits(7);
|
stream.readBits(7);
|
||||||
//data.push(stream.readASCIIString());
|
data.push(stream.readASCIIString());
|
||||||
//console.log(stream.readBits(bits + 1));
|
//console.log(stream.readBits(bits + 1));
|
||||||
//stream.readBits(1);
|
//stream.readBits(1);
|
||||||
//data.push(stream.readASCIIString());
|
//data.push(stream.readASCIIString());
|
||||||
|
|
@ -576,10 +576,11 @@ Packet.parsers = {
|
||||||
var end = stream._index + length;
|
var end = stream._index + length;
|
||||||
stream.readBits(7);
|
stream.readBits(7);
|
||||||
var strings = [];
|
var strings = [];
|
||||||
//for (var i = 0; i < changeEntries; i++) {
|
for (var i = 0; i < changeEntries; i++) {
|
||||||
// // todo cleanup the 8/16 bits that get read in the string here
|
// // todo cleanup the 8/16 bits that get read in the string here
|
||||||
// strings.push(stream.readASCIIString());
|
strings.push(stream.readASCIIString());
|
||||||
//}
|
}
|
||||||
|
//console.log(strings);
|
||||||
stream._index = end;
|
stream._index = end;
|
||||||
//throw false;
|
//throw false;
|
||||||
return {
|
return {
|
||||||
|
|
@ -606,6 +607,51 @@ Packet.parsers = {
|
||||||
},
|
},
|
||||||
18: ParserGenerator.make('setView', 'index{11}'),
|
18: ParserGenerator.make('setView', 'index{11}'),
|
||||||
19: ParserGenerator.make('fixAngle', 'relative{b}x{16}y{16}z{16}'),
|
19: ParserGenerator.make('fixAngle', 'relative{b}x{16}y{16}z{16}'),
|
||||||
|
21: function (stream) {
|
||||||
|
var getCoord = function (stream) {
|
||||||
|
var hasInt = !!stream.readBits(1);
|
||||||
|
var hasFract = !!stream.readBits(1);
|
||||||
|
var value = 0;
|
||||||
|
if (hasInt || hasFract) {
|
||||||
|
var sign = !!stream.readBits(1);
|
||||||
|
if (hasInt) {
|
||||||
|
value += stream.readBits(14) + 1;
|
||||||
|
}
|
||||||
|
if (hasFract) {
|
||||||
|
value += stream.readBits(5) * (1 / 32);
|
||||||
|
}
|
||||||
|
if (sign) {
|
||||||
|
value = -value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
var getVecCoord = function (stream) {
|
||||||
|
var hasX = !!stream.readBits(1);
|
||||||
|
var hasY = !!stream.readBits(1);
|
||||||
|
var hasZ = !!stream.readBits(1);
|
||||||
|
return {
|
||||||
|
x: hasX ? getCoord(stream) : 0,
|
||||||
|
y: hasY ? getCoord(stream) : 0,
|
||||||
|
z: hasZ ? getCoord(stream) : 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var position = getVecCoord(stream);
|
||||||
|
var textureIndex = stream.readBits(9);
|
||||||
|
if (stream.readBits(1)) {
|
||||||
|
var entIndex = stream.readBits(11);
|
||||||
|
var modelIndex = stream.readBits(12);
|
||||||
|
}
|
||||||
|
var lowPriority = !!stream.readBits(1);
|
||||||
|
return {
|
||||||
|
packetType : 'BSPDecal',
|
||||||
|
postition : position,
|
||||||
|
textureIndex: textureIndex,
|
||||||
|
entIndex : entIndex,
|
||||||
|
modelIndex : modelIndex,
|
||||||
|
lowPriority : lowPriority
|
||||||
|
}
|
||||||
|
},
|
||||||
23: function (stream) {
|
23: function (stream) {
|
||||||
// user message
|
// user message
|
||||||
var type = stream.readBits(8);
|
var type = stream.readBits(8);
|
||||||
|
|
@ -660,6 +706,7 @@ Packet.parsers = {
|
||||||
},
|
},
|
||||||
27: ParserGenerator.make('tempEntities', 'count{8}length{17}data{$length}'),
|
27: ParserGenerator.make('tempEntities', 'count{8}length{17}data{$length}'),
|
||||||
28: ParserGenerator.make('preFetch', 'index{14}'),
|
28: ParserGenerator.make('preFetch', 'index{14}'),
|
||||||
|
29: ParserGenerator.make('menu', 'type{16}length{16}data{$length}data{$length}data{$length}data{$length}data{$length}data{$length}data{$length}'),//length*8
|
||||||
30: function (stream) {
|
30: function (stream) {
|
||||||
// list of game events and parameters
|
// list of game events and parameters
|
||||||
var numEvents = stream.readBits(9);
|
var numEvents = stream.readBits(9);
|
||||||
|
|
@ -690,7 +737,9 @@ Packet.parsers = {
|
||||||
packetType: 'gameEventList',
|
packetType: 'gameEventList',
|
||||||
events : events
|
events : events
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
31: ParserGenerator.make('getCvarValue', 'cookie{32}value{s}'),
|
||||||
|
32: ParserGenerator.make('cmdKeyValues', 'length{32}data{$length}')
|
||||||
};
|
};
|
||||||
|
|
||||||
Packet.userMessageParsers = {
|
Packet.userMessageParsers = {
|
||||||
|
|
@ -991,9 +1040,9 @@ StringTable.prototype.parse = function () {
|
||||||
}
|
}
|
||||||
tables[tableName] = entries;
|
tables[tableName] = entries;
|
||||||
if (this.stream.readBits(1)) {
|
if (this.stream.readBits(1)) {
|
||||||
console.log(this.stream.readASCIIString());
|
this.stream.readASCIIString();
|
||||||
if (this.stream.readBits(1)) {
|
if (this.stream.readBits(1)) {
|
||||||
//throw 'more extra data not implemted';
|
//throw 'more extra data not implemented';
|
||||||
var extraDataLength = this.stream.readBits(16);
|
var extraDataLength = this.stream.readBits(16);
|
||||||
this.stream.readBits(extraDataLength);
|
this.stream.readBits(extraDataLength);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
63
packet.js
63
packet.js
|
|
@ -139,9 +139,9 @@ Packet.parsers = {
|
||||||
|
|
||||||
|
|
||||||
for (var i = 0; i < numEntries; i++) {
|
for (var i = 0; i < numEntries; i++) {
|
||||||
//data.push(stream.readASCIIString());
|
data.push(stream.readASCIIString());
|
||||||
//stream.readBits(7);
|
stream.readBits(7);
|
||||||
//data.push(stream.readASCIIString());
|
data.push(stream.readASCIIString());
|
||||||
//console.log(stream.readBits(bits + 1));
|
//console.log(stream.readBits(bits + 1));
|
||||||
//stream.readBits(1);
|
//stream.readBits(1);
|
||||||
//data.push(stream.readASCIIString());
|
//data.push(stream.readASCIIString());
|
||||||
|
|
@ -162,10 +162,11 @@ Packet.parsers = {
|
||||||
var end = stream._index + length;
|
var end = stream._index + length;
|
||||||
stream.readBits(7);
|
stream.readBits(7);
|
||||||
var strings = [];
|
var strings = [];
|
||||||
//for (var i = 0; i < changeEntries; i++) {
|
for (var i = 0; i < changeEntries; i++) {
|
||||||
// // todo cleanup the 8/16 bits that get read in the string here
|
// // todo cleanup the 8/16 bits that get read in the string here
|
||||||
// strings.push(stream.readASCIIString());
|
strings.push(stream.readASCIIString());
|
||||||
//}
|
}
|
||||||
|
//console.log(strings);
|
||||||
stream._index = end;
|
stream._index = end;
|
||||||
//throw false;
|
//throw false;
|
||||||
return {
|
return {
|
||||||
|
|
@ -192,6 +193,51 @@ Packet.parsers = {
|
||||||
},
|
},
|
||||||
18: ParserGenerator.make('setView', 'index{11}'),
|
18: ParserGenerator.make('setView', 'index{11}'),
|
||||||
19: ParserGenerator.make('fixAngle', 'relative{b}x{16}y{16}z{16}'),
|
19: ParserGenerator.make('fixAngle', 'relative{b}x{16}y{16}z{16}'),
|
||||||
|
21: function (stream) {
|
||||||
|
var getCoord = function (stream) {
|
||||||
|
var hasInt = !!stream.readBits(1);
|
||||||
|
var hasFract = !!stream.readBits(1);
|
||||||
|
var value = 0;
|
||||||
|
if (hasInt || hasFract) {
|
||||||
|
var sign = !!stream.readBits(1);
|
||||||
|
if (hasInt) {
|
||||||
|
value += stream.readBits(14) + 1;
|
||||||
|
}
|
||||||
|
if (hasFract) {
|
||||||
|
value += stream.readBits(5) * (1 / 32);
|
||||||
|
}
|
||||||
|
if (sign) {
|
||||||
|
value = -value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
var getVecCoord = function (stream) {
|
||||||
|
var hasX = !!stream.readBits(1);
|
||||||
|
var hasY = !!stream.readBits(1);
|
||||||
|
var hasZ = !!stream.readBits(1);
|
||||||
|
return {
|
||||||
|
x: hasX ? getCoord(stream) : 0,
|
||||||
|
y: hasY ? getCoord(stream) : 0,
|
||||||
|
z: hasZ ? getCoord(stream) : 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var position = getVecCoord(stream);
|
||||||
|
var textureIndex = stream.readBits(9);
|
||||||
|
if (stream.readBits(1)) {
|
||||||
|
var entIndex = stream.readBits(11);
|
||||||
|
var modelIndex = stream.readBits(12);
|
||||||
|
}
|
||||||
|
var lowPriority = !!stream.readBits(1);
|
||||||
|
return {
|
||||||
|
packetType : 'BSPDecal',
|
||||||
|
postition : position,
|
||||||
|
textureIndex: textureIndex,
|
||||||
|
entIndex : entIndex,
|
||||||
|
modelIndex : modelIndex,
|
||||||
|
lowPriority : lowPriority
|
||||||
|
}
|
||||||
|
},
|
||||||
23: function (stream) {
|
23: function (stream) {
|
||||||
// user message
|
// user message
|
||||||
var type = stream.readBits(8);
|
var type = stream.readBits(8);
|
||||||
|
|
@ -246,6 +292,7 @@ Packet.parsers = {
|
||||||
},
|
},
|
||||||
27: ParserGenerator.make('tempEntities', 'count{8}length{17}data{$length}'),
|
27: ParserGenerator.make('tempEntities', 'count{8}length{17}data{$length}'),
|
||||||
28: ParserGenerator.make('preFetch', 'index{14}'),
|
28: ParserGenerator.make('preFetch', 'index{14}'),
|
||||||
|
29: ParserGenerator.make('menu', 'type{16}length{16}data{$length}data{$length}data{$length}data{$length}data{$length}data{$length}data{$length}'),//length*8
|
||||||
30: function (stream) {
|
30: function (stream) {
|
||||||
// list of game events and parameters
|
// list of game events and parameters
|
||||||
var numEvents = stream.readBits(9);
|
var numEvents = stream.readBits(9);
|
||||||
|
|
@ -276,7 +323,9 @@ Packet.parsers = {
|
||||||
packetType: 'gameEventList',
|
packetType: 'gameEventList',
|
||||||
events : events
|
events : events
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
31: ParserGenerator.make('getCvarValue', 'cookie{32}value{s}'),
|
||||||
|
32: ParserGenerator.make('cmdKeyValues', 'length{32}data{$length}')
|
||||||
};
|
};
|
||||||
|
|
||||||
Packet.userMessageParsers = {
|
Packet.userMessageParsers = {
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,9 @@ StringTable.prototype.parse = function () {
|
||||||
}
|
}
|
||||||
tables[tableName] = entries;
|
tables[tableName] = entries;
|
||||||
if (this.stream.readBits(1)) {
|
if (this.stream.readBits(1)) {
|
||||||
console.log(this.stream.readASCIIString());
|
this.stream.readASCIIString();
|
||||||
if (this.stream.readBits(1)) {
|
if (this.stream.readBits(1)) {
|
||||||
//throw 'more extra data not implemted';
|
//throw 'more extra data not implemented';
|
||||||
var extraDataLength = this.stream.readBits(16);
|
var extraDataLength = this.stream.readBits(16);
|
||||||
this.stream.readBits(extraDataLength);
|
this.stream.readBits(extraDataLength);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
3
test.js
3
test.js
|
|
@ -1,13 +1,14 @@
|
||||||
var Demo = require('./demo');
|
var Demo = require('./demo');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
fs.readFile("lake.dem", function (err, data) {
|
fs.readFile("upward.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();
|
||||||
var head = parser.readHeader();
|
var head = parser.readHeader();
|
||||||
//console.log(parser.readHeader());
|
//console.log(parser.readHeader());
|
||||||
//var message;
|
//var message;
|
||||||
|
//parser.parseBody()
|
||||||
console.log(parser.parseBody());
|
console.log(parser.parseBody());
|
||||||
//while (message = parser.readMessage()) {
|
//while (message = parser.readMessage()) {
|
||||||
// if (message.parse) {
|
// if (message.parse) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue