mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
improve sayText2
This commit is contained in:
parent
9cb24b9a74
commit
50fd4beb3f
1 changed files with 141 additions and 100 deletions
43
packet.js
43
packet.js
|
|
@ -2,6 +2,9 @@ var ParserGenerator = require('./parsergenerator');
|
||||||
var StringTable = require('./stringtable');
|
var StringTable = require('./stringtable');
|
||||||
var PacketStringTable = require('./packetstringtable');
|
var PacketStringTable = require('./packetstringtable');
|
||||||
|
|
||||||
|
// https://code.google.com/p/coldemoplayer/source/browse/branches/2.0/compLexity+Demo+Player/CDP.Source/Messages/?r=219
|
||||||
|
// https://github.com/TimePath/hl2-toolkit/tree/master/src/main/java/com/timepath/hl2/io/demo
|
||||||
|
|
||||||
function logBase2(num) {
|
function logBase2(num) {
|
||||||
var result = 0;
|
var result = 0;
|
||||||
while ((num >>= 1) != 0) {
|
while ((num >>= 1) != 0) {
|
||||||
|
|
@ -372,7 +375,45 @@ Packet.parsers = {
|
||||||
};
|
};
|
||||||
|
|
||||||
Packet.userMessageParsers = {
|
Packet.userMessageParsers = {
|
||||||
4: ParserGenerator.make('sayText2', 'client{8}raw{8}kind{s}from{s}text{s}'),
|
4: function (stream) {
|
||||||
|
var client = stream.readBits(8);
|
||||||
|
var raw = stream.readBits(8);
|
||||||
|
var pos = stream._index;
|
||||||
|
var from, text, kind, arg1, arg2;
|
||||||
|
if (stream.readBits(8) === 1) {
|
||||||
|
var first = stream.readBits(8);
|
||||||
|
if (first === 7) {
|
||||||
|
var color = stream.readASCIIString(6);
|
||||||
|
} else {
|
||||||
|
stream._index = pos + 8;
|
||||||
|
}
|
||||||
|
text = stream.readASCIIString();
|
||||||
|
if (text.substr(0, 6) === '*DEAD*') {
|
||||||
|
// grave talk is in the format '*DEAD* \u0003$from\u0001: $text'
|
||||||
|
var start = text.indexOf('\u0003');
|
||||||
|
var end = text.indexOf('\u0001');
|
||||||
|
from = text.substr(start + 1, end - start - 1);
|
||||||
|
text = text.substr(end + 5);
|
||||||
|
kind = 'TF_Chat_AllDead';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
stream._index = pos;
|
||||||
|
kind = stream.readASCIIString();
|
||||||
|
from = stream.readASCIIString();
|
||||||
|
text = stream.readASCIIString();
|
||||||
|
stream.readASCIIString();
|
||||||
|
stream.readASCIIString();
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
packetType: 'sayText2',
|
||||||
|
client : client,
|
||||||
|
raw : raw,
|
||||||
|
kind : kind,
|
||||||
|
from : from,
|
||||||
|
text : text
|
||||||
|
}
|
||||||
|
},
|
||||||
|
//4: ParserGenerator.make('sayText2', 'client{8}raw{8}kind{s}from{s}text{s}arg1{s}arg2{s}'),
|
||||||
5: ParserGenerator.make('textMsg', 'destType{8}text{s}')
|
5: ParserGenerator.make('textMsg', 'destType{8}text{s}')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue