mirror of
https://github.com/demostf/demo.js
synced 2026-06-03 16:44:12 +02:00
add encoder for parseSounds
This commit is contained in:
parent
f360011ef4
commit
9406937f08
7 changed files with 255 additions and 15 deletions
|
|
@ -88,6 +88,7 @@ export interface ParseSoundsPacket {
|
|||
reliable: boolean;
|
||||
num: number;
|
||||
length: number;
|
||||
data: BitStream;
|
||||
}
|
||||
|
||||
export interface SetConVarPacket {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import {ParseGameEventList} from '../Packet/GameEventList';
|
|||
import {ParseMenu} from '../Packet/Menu';
|
||||
import {ParsePacketEntities} from '../Packet/PacketEntities';
|
||||
import {PacketParserMap, voidEncoder} from '../Packet/Parser';
|
||||
import {ParseParseSounds} from '../Packet/ParseSounds';
|
||||
import {EncodeParseSounds, ParseParseSounds} from '../Packet/ParseSounds';
|
||||
import {EncodeSetConVar, ParseSetConVar} from '../Packet/SetConVar';
|
||||
import {ParseTempEntities} from '../Packet/TempEntities';
|
||||
import {EncodeUpdateStringTable, ParseUpdateStringTable} from '../Packet/UpdateStringTable';
|
||||
|
|
@ -45,7 +45,7 @@ export class Packet extends Parser {
|
|||
13: {parser: ParseUpdateStringTable, encoder: EncodeUpdateStringTable},
|
||||
14: {parser: ParseVoiceInit, encoder: EncodeVoiceInit},
|
||||
15: {parser: ParseVoiceData, encoder: EncodeVoiceData},
|
||||
17: {parser: ParseParseSounds, encoder: voidEncoder},
|
||||
17: {parser: ParseParseSounds, encoder: EncodeParseSounds},
|
||||
18: make('setView', 'index{11}'),
|
||||
19: make('fixAngle', 'relative{b}x{16}y{16}z{16}'),
|
||||
21: {parser: ParseBSPDecal, encoder: voidEncoder},
|
||||
|
|
|
|||
|
|
@ -5,11 +5,27 @@ export function ParseParseSounds(stream: BitStream): ParseSoundsPacket { // 17:
|
|||
const reliable = stream.readBoolean();
|
||||
const num = (reliable) ? 1 : stream.readUint8();
|
||||
const length = (reliable) ? stream.readUint8() : stream.readUint16();
|
||||
stream.index += length;
|
||||
const data = stream.readBitStream(length);
|
||||
|
||||
return {
|
||||
packetType: 'parseSounds',
|
||||
reliable,
|
||||
num,
|
||||
length,
|
||||
data
|
||||
};
|
||||
}
|
||||
|
||||
export function EncodeParseSounds(packet: ParseSoundsPacket, stream: BitStream) {
|
||||
stream.writeBoolean(packet.reliable);
|
||||
if (packet.reliable) {
|
||||
stream.writeUint8(packet.length);
|
||||
} else {
|
||||
stream.writeUint8(packet.num);
|
||||
stream.writeUint16(packet.length);
|
||||
}
|
||||
|
||||
packet.data.index = 0;
|
||||
stream.writeBitStream(packet.data, packet.length);
|
||||
packet.data.index = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,4 @@ export function EncodeVoiceData(packet: VoiceDataPacket, stream: BitStream) {
|
|||
packet.data.index = 0;
|
||||
stream.writeBitStream(packet.data, packet.length);
|
||||
packet.data.index = 0;
|
||||
|
||||
const length = stream.index;
|
||||
|
||||
stream.index = 0;
|
||||
console.log(stream.readArrayBuffer(Math.ceil(length / 8)));
|
||||
}
|
||||
|
|
|
|||
219
src/tests/unit/Parser/Packet/ParseSoundsTest.ts
Normal file
219
src/tests/unit/Parser/Packet/ParseSoundsTest.ts
Normal file
|
|
@ -0,0 +1,219 @@
|
|||
import {BitStream} from 'bit-buffer';
|
||||
import {assertEncoder, assertParser, getStream} from './PacketTest';
|
||||
import {EncodeParseSounds, ParseParseSounds} from '../../../../Parser/Packet/ParseSounds';
|
||||
|
||||
const data = [
|
||||
18,
|
||||
122,
|
||||
5,
|
||||
142,
|
||||
169,
|
||||
43,
|
||||
224,
|
||||
223,
|
||||
63,
|
||||
24,
|
||||
8,
|
||||
3,
|
||||
126,
|
||||
17,
|
||||
248,
|
||||
53,
|
||||
0,
|
||||
36,
|
||||
5,
|
||||
115,
|
||||
140,
|
||||
159,
|
||||
241,
|
||||
236,
|
||||
67,
|
||||
128,
|
||||
39,
|
||||
200,
|
||||
47,
|
||||
2,
|
||||
71,
|
||||
169,
|
||||
15,
|
||||
1,
|
||||
30,
|
||||
145,
|
||||
0,
|
||||
184,
|
||||
104,
|
||||
24,
|
||||
103,
|
||||
98,
|
||||
197,
|
||||
175,
|
||||
0,
|
||||
191,
|
||||
3,
|
||||
0,
|
||||
252,
|
||||
215,
|
||||
140,
|
||||
153,
|
||||
209,
|
||||
237,
|
||||
67,
|
||||
128,
|
||||
89,
|
||||
2,
|
||||
0,
|
||||
254,
|
||||
25,
|
||||
198,
|
||||
196,
|
||||
152,
|
||||
246,
|
||||
33,
|
||||
192,
|
||||
14,
|
||||
228,
|
||||
24,
|
||||
129,
|
||||
99,
|
||||
206,
|
||||
135,
|
||||
0,
|
||||
203,
|
||||
3,
|
||||
0,
|
||||
4,
|
||||
143,
|
||||
35,
|
||||
205,
|
||||
243,
|
||||
4,
|
||||
73,
|
||||
70,
|
||||
219,
|
||||
136,
|
||||
245,
|
||||
33,
|
||||
0];
|
||||
const soundData = [
|
||||
199,
|
||||
212,
|
||||
21,
|
||||
240,
|
||||
239,
|
||||
31,
|
||||
12,
|
||||
132,
|
||||
1,
|
||||
191,
|
||||
8,
|
||||
252,
|
||||
26,
|
||||
0,
|
||||
146,
|
||||
130,
|
||||
57,
|
||||
198,
|
||||
207,
|
||||
120,
|
||||
246,
|
||||
33,
|
||||
192,
|
||||
19,
|
||||
228,
|
||||
23,
|
||||
129,
|
||||
163,
|
||||
212,
|
||||
135,
|
||||
0,
|
||||
143,
|
||||
72,
|
||||
0,
|
||||
92,
|
||||
52,
|
||||
140,
|
||||
51,
|
||||
177,
|
||||
226,
|
||||
87,
|
||||
128,
|
||||
223,
|
||||
1,
|
||||
0,
|
||||
254,
|
||||
107,
|
||||
198,
|
||||
204,
|
||||
232,
|
||||
246,
|
||||
33,
|
||||
192,
|
||||
44,
|
||||
1,
|
||||
0,
|
||||
255,
|
||||
12,
|
||||
99,
|
||||
98,
|
||||
76,
|
||||
251,
|
||||
16,
|
||||
96,
|
||||
7,
|
||||
114,
|
||||
140,
|
||||
192,
|
||||
49,
|
||||
231,
|
||||
67,
|
||||
128,
|
||||
229,
|
||||
1,
|
||||
0,
|
||||
130,
|
||||
199,
|
||||
145,
|
||||
230,
|
||||
121,
|
||||
130,
|
||||
36,
|
||||
163,
|
||||
109,
|
||||
196,
|
||||
250,
|
||||
16,
|
||||
0];
|
||||
const soundStream = getStream(soundData).readBitStream(726 - 25);
|
||||
|
||||
suite('ParseSounds', () => {
|
||||
test('Parse parseSounds', () => {
|
||||
soundStream.index = 0;
|
||||
assertParser(ParseParseSounds, getStream(data), {
|
||||
packetType: 'parseSounds',
|
||||
reliable: false,
|
||||
num: 9,
|
||||
length: 701,
|
||||
data: soundStream
|
||||
}, 726);
|
||||
});
|
||||
|
||||
test('Encode parseSounds', () => {
|
||||
soundStream.index = 0;
|
||||
assertEncoder(ParseParseSounds, EncodeParseSounds, {
|
||||
packetType: 'parseSounds',
|
||||
reliable: false,
|
||||
num: 9,
|
||||
length: 701,
|
||||
data: soundStream
|
||||
}, 726);
|
||||
|
||||
soundStream.index = 0;
|
||||
assertEncoder(ParseParseSounds, EncodeParseSounds, {
|
||||
packetType: 'parseSounds',
|
||||
reliable: true,
|
||||
num: 1,
|
||||
length: 15,
|
||||
data: soundStream.readBitStream(15)
|
||||
}, 24);
|
||||
});
|
||||
});
|
||||
|
|
@ -4,8 +4,8 @@ import {EncodeVoiceData, ParseVoiceData} from '../../../../Parser/Packet/VoiceDa
|
|||
|
||||
const data = [5, 18, 24, 0, 123, 219, 1];
|
||||
|
||||
suite('VoiceInit', () => {
|
||||
test('Parse voiceInit', () => {
|
||||
suite('VoiceData', () => {
|
||||
test('Parse voiceData', () => {
|
||||
assertParser(ParseVoiceData, getStream(data), {
|
||||
packetType: 'voiceData',
|
||||
client: '5',
|
||||
|
|
@ -15,7 +15,7 @@ suite('VoiceInit', () => {
|
|||
}, 56);
|
||||
});
|
||||
|
||||
test('Encode voiceInit', () => {
|
||||
test('Encode voiceData', () => {
|
||||
assertEncoder(ParseVoiceData, EncodeVoiceData, {
|
||||
packetType: 'voiceData',
|
||||
client: '5',
|
||||
|
|
|
|||
|
|
@ -49,16 +49,23 @@ function objEquiv(a, b, opts) {
|
|||
if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
|
||||
return false;
|
||||
// an identical 'prototype' property.
|
||||
if (a.prototype !== b.prototype) return false;
|
||||
if (a.prototype !== b.prototype) {
|
||||
return false;
|
||||
}
|
||||
//~~~I've managed to break Object.keys through screwy arguments passing.
|
||||
// Converting to array solves the problem.
|
||||
if (isBuffer(a)) {
|
||||
if (!isBuffer(b)) {
|
||||
return false;
|
||||
}
|
||||
if (a.length !== b.length) return false;
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (i = 0; i < a.length; i++) {
|
||||
if (a[i] !== b[i]) return false;
|
||||
if (a[i] !== b[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -66,7 +73,9 @@ function objEquiv(a, b, opts) {
|
|||
if (!isStream(b)) {
|
||||
return false;
|
||||
}
|
||||
if (a.length !== b.length) return false;
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
a.index = 0;
|
||||
b.index = 0;
|
||||
while (a.bitsLeft > 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue