mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
fix parsing var int properties
This commit is contained in:
parent
a5bfe128ed
commit
4d40fd4109
3 changed files with 9 additions and 19 deletions
|
|
@ -62,7 +62,7 @@ function readEnterPVS(stream: BitStream, entityId: number, match: Match, baseLin
|
||||||
applyEntityUpdate(entity, staticBaseLine);
|
applyEntityUpdate(entity, staticBaseLine);
|
||||||
if (staticBaseLine.bitsLeft > 7) {
|
if (staticBaseLine.bitsLeft > 7) {
|
||||||
console.log(staticBaseLine.length, staticBaseLine.index);
|
console.log(staticBaseLine.length, staticBaseLine.index);
|
||||||
throw new Error('Unexpected data left at the end of staticBaseline, ' + stream.bitsLeft + ' bits left');
|
throw new Error('Unexpected data left at the end of staticBaseline, ' + staticBaseLine.bitsLeft + ' bits left');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,21 +2,7 @@ import {SendPropDefinition, SendPropType, SendPropFlag} from '../Data/SendPropDe
|
||||||
import {Vector} from "../Data/Vector";
|
import {Vector} from "../Data/Vector";
|
||||||
import {BitStream} from "bit-buffer";
|
import {BitStream} from "bit-buffer";
|
||||||
import {SendPropValue, SendPropArrayValue} from "../Data/SendProp";
|
import {SendPropValue, SendPropArrayValue} from "../Data/SendProp";
|
||||||
|
import {readVarInt} from "./readBitVar";
|
||||||
|
|
||||||
const readBitVar = function (stream: BitStream, signed: boolean): number {
|
|
||||||
switch (stream.readBits(2)) {
|
|
||||||
case 0:
|
|
||||||
return stream.readBits(4, signed);
|
|
||||||
case 1:
|
|
||||||
return stream.readBits(8, signed);
|
|
||||||
case 2:
|
|
||||||
return stream.readBits(12, signed);
|
|
||||||
case 3:
|
|
||||||
return stream.readBits(32, signed);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
export class SendPropParser {
|
export class SendPropParser {
|
||||||
static decode(propDefinition: SendPropDefinition, stream: BitStream): SendPropValue {
|
static decode(propDefinition: SendPropDefinition, stream: BitStream): SendPropValue {
|
||||||
|
|
@ -39,7 +25,7 @@ export class SendPropParser {
|
||||||
|
|
||||||
static readInt(propDefinition: SendPropDefinition, stream: BitStream) {
|
static readInt(propDefinition: SendPropDefinition, stream: BitStream) {
|
||||||
if (propDefinition.hasFlag(SendPropFlag.SPROP_VARINT)) {
|
if (propDefinition.hasFlag(SendPropFlag.SPROP_VARINT)) {
|
||||||
return readBitVar(stream, !propDefinition.hasFlag(SendPropFlag.SPROP_UNSIGNED));
|
return readVarInt(stream, !propDefinition.hasFlag(SendPropFlag.SPROP_UNSIGNED));
|
||||||
} else {
|
} else {
|
||||||
return stream.readBits(propDefinition.bitCount, !propDefinition.hasFlag(SendPropFlag.SPROP_UNSIGNED));
|
return stream.readBits(propDefinition.bitCount, !propDefinition.hasFlag(SendPropFlag.SPROP_UNSIGNED));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ export function readBitVar(stream: BitStream, signed?: boolean): number {
|
||||||
export const readUBitVar = readBitVar;
|
export const readUBitVar = readBitVar;
|
||||||
|
|
||||||
|
|
||||||
export function readVarInt(stream: BitStream) {
|
export function readVarInt(stream: BitStream, signed:boolean = false) {
|
||||||
let result = 0;
|
let result = 0;
|
||||||
for (let i = 0; i < 35; i += 7) {
|
for (let i = 0; i < 35; i += 7) {
|
||||||
const byte = stream.readBits(8);
|
const byte = stream.readBits(8);
|
||||||
|
|
@ -28,5 +28,9 @@ export function readVarInt(stream: BitStream) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (signed) {
|
||||||
|
return ((result >> 1) ^ -(result & 1));
|
||||||
|
} else {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue