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

switch to base parser for entity message

This commit is contained in:
Robin Appelman 2017-09-01 21:39:37 +02:00
commit a0f471cf9a
4 changed files with 14 additions and 20 deletions

View file

@ -1,13 +0,0 @@
import {make} from './ParserGenerator';
import {BitStream} from 'bit-buffer';
import {Match} from '../../Data/Match';
import {EntityMessagePacket} from '../../Data/Packet';
const baseParser = make('entityMessage', 'index{11}classId{9}length{11}data{$length}');
export function ParseEntityMessage(stream: BitStream, match: Match): EntityMessagePacket { // 24: entityMessage
// entity messages seem pretty unimportant, they are unreliable messages and from testing only the "clear decals"
// message seems to be used in practice, probably safe to just leave as is
return baseParser.parser(stream) as EntityMessagePacket;
}

View file

@ -49,13 +49,13 @@ function readItem(stream: BitStream, description: string, data) {
return stream.readBits(length);
} else if (description[0] === '$') {
const variable = description.substr(1);
return stream.readBits(data[variable]);
return stream.readBitStream(data[variable]);
} else {
return stream.readBits(parseInt(description, 10), true);
}
}
function writeItem(stream: BitStream, description: string, data, value: boolean | string | number) {
function writeItem(stream: BitStream, description: string, data, value: boolean | string | number | BitStream) {
if (description[0] === 'b') {
return stream.writeBoolean(value as boolean);
} else if (description[0] === 's') {
@ -72,7 +72,7 @@ function writeItem(stream: BitStream, description: string, data, value: boolean
return stream.writeBits(value as number, length);
} else if (description[0] === '$') {
const variable = description.substr(1);
return stream.writeBits(value as number, data[variable]);
return stream.writeBitStream(value as BitStream, data[variable]);
} else {
return stream.writeBits(value as number, parseInt(description, 10));
}