mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
simple parser for menu
This commit is contained in:
parent
344d76fb97
commit
70bdf0257e
4 changed files with 48 additions and 16 deletions
|
|
@ -5,7 +5,6 @@ import {EncodeClassInfo, ParseClassInfo} from '../Packet/ClassInfo';
|
|||
import {EncodeCreateStringTable, ParseCreateStringTable} from '../Packet/CreateStringTable';
|
||||
import {ParseGameEvent} from '../Packet/GameEvent';
|
||||
import {EncodeGameEventList, ParseGameEventList} from '../Packet/GameEventList';
|
||||
import {ParseMenu} from '../Packet/Menu';
|
||||
import {ParsePacketEntities} from '../Packet/PacketEntities';
|
||||
import {PacketParserMap, voidEncoder} from '../Packet/Parser';
|
||||
import {EncodeParseSounds, ParseParseSounds} from '../Packet/ParseSounds';
|
||||
|
|
@ -53,7 +52,7 @@ export class Packet extends Parser {
|
|||
26: {parser: ParsePacketEntities, encoder: voidEncoder},
|
||||
27: {parser: ParseTempEntities, encoder: voidEncoder},
|
||||
28: make('preFetch', 'index{14}'),
|
||||
29: {parser: ParseMenu, encoder: voidEncoder},
|
||||
29: make('menu', 'type{u16}length{u16}data{$length*8}'),
|
||||
30: {parser: ParseGameEventList, encoder: EncodeGameEventList},
|
||||
31: make('getCvarValue', 'cookie{32}value{s}'),
|
||||
32: make('cmdKeyValues', 'length{32}data{$length}'),
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
import {BitStream} from 'bit-buffer';
|
||||
import {MenuPacket} from '../../Data/Packet';
|
||||
|
||||
export function ParseMenu(stream: BitStream): MenuPacket {
|
||||
const type = stream.readUint16();
|
||||
const length = stream.readUint16();
|
||||
const data = stream.readBitStream(length * 8); // length is in bytes
|
||||
return {
|
||||
packetType: 'menu',
|
||||
type,
|
||||
length,
|
||||
data,
|
||||
};
|
||||
}
|
||||
|
|
@ -47,6 +47,9 @@ function readItem(stream: BitStream, description: string, data) {
|
|||
} else if (description[0] === 'u') {
|
||||
const length = parseInt(description.substr(1), 10);
|
||||
return stream.readBits(length);
|
||||
} else if (description[0] === '$' && description.substr(description.length - 2) === '*8') {
|
||||
const variable = description.substr(1, description.length - 3);
|
||||
return stream.readBitStream(data[variable] * 8);
|
||||
} else if (description[0] === '$') {
|
||||
const variable = description.substr(1);
|
||||
return stream.readBitStream(data[variable]);
|
||||
|
|
@ -70,6 +73,9 @@ function writeItem(stream: BitStream, description: string, data, value: boolean
|
|||
} else if (description[0] === 'u') {
|
||||
const length = parseInt(description.substr(1), 10);
|
||||
return stream.writeBits(value as number, length);
|
||||
} else if (description[0] === '$' && description.substr(description.length - 2) === '*8') {
|
||||
const variable = description.substr(1, description.length - 3);
|
||||
return stream.writeBitStream(value as BitStream, data[variable] * 8);
|
||||
} else if (description[0] === '$') {
|
||||
const variable = description.substr(1);
|
||||
return stream.writeBitStream(value as BitStream, data[variable]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue