mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
fix encoding string sendprops
This commit is contained in:
parent
9cc38d6b2d
commit
8fe977ff9f
4 changed files with 261 additions and 13 deletions
|
|
@ -68,9 +68,11 @@ export class SendPropEncoder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static writeString(value: string, stream: BitStream) {
|
public static writeString(value: string, stream: BitStream) {
|
||||||
// +1 for null
|
stream.writeBits(value.length, 9);
|
||||||
stream.writeBits(value.length + 1, 9);
|
if (value) {
|
||||||
stream.writeASCIIString(value);
|
// specify the length to exclude the null terminator
|
||||||
|
stream.writeASCIIString(value, value.length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static writeVector(value: Vector, propDefinition: SendPropDefinition, stream: BitStream) {
|
public static writeVector(value: Vector, propDefinition: SendPropDefinition, stream: BitStream) {
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,257 @@
|
||||||
import {BitStream} from 'bit-buffer';
|
import {BitStream} from 'bit-buffer';
|
||||||
import {readFileSync} from 'fs';
|
import {readFileSync} from 'fs';
|
||||||
import {SendProp, SendPropValue} from '../../../../Data/SendProp';
|
import {SendProp, SendPropValue} from '../../../../Data/SendProp';
|
||||||
import {SendPropType} from '../../../../Data/SendPropDefinition';
|
|
||||||
import {encodeEntityUpdate, getEntityUpdate} from '../../../../Parser/EntityDecoder';
|
import {encodeEntityUpdate, getEntityUpdate} from '../../../../Parser/EntityDecoder';
|
||||||
import {SendPropEncoder} from '../../../../Parser/SendPropEncoder';
|
import {SendPropEncoder} from '../../../../Parser/SendPropEncoder';
|
||||||
import {SendPropParser} from '../../../../Parser/SendPropParser';
|
import {SendPropParser} from '../../../../Parser/SendPropParser';
|
||||||
import {hydrateEntity, hydrateTable} from './hydrate';
|
import {hydrateEntity, hydrateTable} from './hydrate';
|
||||||
import {assertEncoder, assertParser, getStream} from './PacketTest';
|
import {assertEncoder, assertParser, assertReEncode, getStream} from './PacketTest';
|
||||||
|
|
||||||
// tslint:disable-next-line
|
const data = [9,
|
||||||
const data = [9, 128, 64, 64, 64, 64, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 36, 0, 64, 0, 1, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 136, 0, 128, 0, 0, 8, 0, 128, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 2, 64, 0, 32, 0, 16, 0, 32, 240, 255, 255, 255, 31, 0, 2, 32, 48, 0, 128, 0, 0, 4, 254, 255, 127, 224, 255, 255, 7, 254, 255, 127, 0, 8, 64, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 64, 64, 64, 64, 0, 32, 224, 136, 10, 248, 91, 2, 63, 18, 8, 40, 38, 3, 250, 163, 192, 126, 7, 2, 2, 0, 0, 0, 0, 1, 0, 0, 0, 128, 0, 0, 0, 224, 111, 0, 0, 0, 0, 32, 192, 129, 172, 140, 46, 44, 141, 237, 133, 172, 140, 46, 44, 141, 109, 14, 78, 46, 141, 174, 108, 238, 107, 46, 236, 174, 45, 141, 141, 45, 0];
|
128,
|
||||||
|
64,
|
||||||
|
64,
|
||||||
|
64,
|
||||||
|
64,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
16,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
8,
|
||||||
|
36,
|
||||||
|
0,
|
||||||
|
64,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
128,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
64,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
32,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
16,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
136,
|
||||||
|
0,
|
||||||
|
128,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
8,
|
||||||
|
0,
|
||||||
|
128,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
8,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
4,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
2,
|
||||||
|
64,
|
||||||
|
0,
|
||||||
|
32,
|
||||||
|
0,
|
||||||
|
16,
|
||||||
|
0,
|
||||||
|
32,
|
||||||
|
240,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
31,
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
32,
|
||||||
|
48,
|
||||||
|
0,
|
||||||
|
128,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
4,
|
||||||
|
254,
|
||||||
|
255,
|
||||||
|
127,
|
||||||
|
224,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
7,
|
||||||
|
254,
|
||||||
|
255,
|
||||||
|
127,
|
||||||
|
0,
|
||||||
|
8,
|
||||||
|
64,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
128,
|
||||||
|
0,
|
||||||
|
64,
|
||||||
|
64,
|
||||||
|
64,
|
||||||
|
64,
|
||||||
|
0,
|
||||||
|
32,
|
||||||
|
224,
|
||||||
|
136,
|
||||||
|
10,
|
||||||
|
248,
|
||||||
|
91,
|
||||||
|
2,
|
||||||
|
63,
|
||||||
|
18,
|
||||||
|
8,
|
||||||
|
40,
|
||||||
|
38,
|
||||||
|
3,
|
||||||
|
250,
|
||||||
|
163,
|
||||||
|
192,
|
||||||
|
126,
|
||||||
|
7,
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
128,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
224,
|
||||||
|
111,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
32,
|
||||||
|
192,
|
||||||
|
129,
|
||||||
|
172,
|
||||||
|
140,
|
||||||
|
46,
|
||||||
|
44,
|
||||||
|
141,
|
||||||
|
237,
|
||||||
|
133,
|
||||||
|
172,
|
||||||
|
140,
|
||||||
|
46,
|
||||||
|
44,
|
||||||
|
141,
|
||||||
|
109,
|
||||||
|
14,
|
||||||
|
78,
|
||||||
|
46,
|
||||||
|
141,
|
||||||
|
174,
|
||||||
|
108,
|
||||||
|
238,
|
||||||
|
107,
|
||||||
|
46,
|
||||||
|
236,
|
||||||
|
174,
|
||||||
|
45,
|
||||||
|
141,
|
||||||
|
141,
|
||||||
|
45,
|
||||||
|
0];
|
||||||
|
|
||||||
const entityData = JSON.parse(readFileSync(__dirname + '/../../../data/worldEntity.json', 'utf8'));
|
const entityData = JSON.parse(readFileSync(__dirname + '/../../../data/worldEntity.json', 'utf8'));
|
||||||
const sendTableData = JSON.parse(readFileSync(__dirname + '/../../../data/sendTableDTWorld.json', 'utf8'));
|
const sendTableData = JSON.parse(readFileSync(__dirname + '/../../../data/sendTableDTWorld.json', 'utf8'));
|
||||||
|
|
@ -49,7 +291,11 @@ suite('Entity Decoder', () => {
|
||||||
assertParser(decodeUpdate, getStream(data), entity.props, 1958);
|
assertParser(decodeUpdate, getStream(data), entity.props, 1958);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Encode userMessage', () => {
|
test('Encode entity update', () => {
|
||||||
assertEncoder(decodeUpdate, encodeUpdate, entity.props, 1966);
|
assertEncoder(decodeUpdate, encodeUpdate, entity.props, 1958);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Re-encode entity update', () => {
|
||||||
|
assertReEncode(decodeUpdate, encodeUpdate, getStream(data));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -219,6 +219,6 @@ suite('PacketEntities', () => {
|
||||||
delta: 0,
|
delta: 0,
|
||||||
maxEntries: 16,
|
maxEntries: 16,
|
||||||
entities: [hydrateEntity(playerEntityData)]
|
entities: [hydrateEntity(playerEntityData)]
|
||||||
}, 3576);
|
}, 3568);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -99,8 +99,8 @@ suite('SendPropEncoder', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('string', () => {
|
test('string', () => {
|
||||||
assertEncoder(readString, writeString, 'foobar', (7 * 8) + 9);
|
assertEncoder(readString, writeString, 'foobar', (6 * 8) + 9);
|
||||||
assertEncoder(readString, writeString, '', 8 + 9);
|
assertEncoder(readString, writeString, '', 9);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('array', () => {
|
test('array', () => {
|
||||||
|
|
@ -115,7 +115,7 @@ suite('SendPropEncoder', () => {
|
||||||
[1, 2, 3, 4, 5, 6, 7, 8, 9], 5 * 9 + 4);
|
[1, 2, 3, 4, 5, 6, 7, 8, 9], 5 * 9 + 4);
|
||||||
assertEncoder(arrayReader(SendPropType.DPT_String, 2),
|
assertEncoder(arrayReader(SendPropType.DPT_String, 2),
|
||||||
arrayWriter(SendPropType.DPT_String, 2),
|
arrayWriter(SendPropType.DPT_String, 2),
|
||||||
['foo', 'bar'], (4 * 8 + 9) * 2 + 2);
|
['foo', 'bar'], (3 * 8 + 9) * 2 + 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('floats', () => {
|
test('floats', () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue