mirror of
https://github.com/demostf/demo.js
synced 2026-06-03 16:44:12 +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);
|
||||
if (staticBaseLine.bitsLeft > 7) {
|
||||
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 {BitStream} from "bit-buffer";
|
||||
import {SendPropValue, SendPropArrayValue} from "../Data/SendProp";
|
||||
|
||||
|
||||
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;
|
||||
};
|
||||
import {readVarInt} from "./readBitVar";
|
||||
|
||||
export class SendPropParser {
|
||||
static decode(propDefinition: SendPropDefinition, stream: BitStream): SendPropValue {
|
||||
|
|
@ -39,7 +25,7 @@ export class SendPropParser {
|
|||
|
||||
static readInt(propDefinition: SendPropDefinition, stream: BitStream) {
|
||||
if (propDefinition.hasFlag(SendPropFlag.SPROP_VARINT)) {
|
||||
return readBitVar(stream, !propDefinition.hasFlag(SendPropFlag.SPROP_UNSIGNED));
|
||||
return readVarInt(stream, !propDefinition.hasFlag(SendPropFlag.SPROP_UNSIGNED));
|
||||
} else {
|
||||
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 function readVarInt(stream: BitStream) {
|
||||
export function readVarInt(stream: BitStream, signed:boolean = false) {
|
||||
let result = 0;
|
||||
for (let i = 0; i < 35; i += 7) {
|
||||
const byte = stream.readBits(8);
|
||||
|
|
@ -28,5 +28,9 @@ export function readVarInt(stream: BitStream) {
|
|||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
if (signed) {
|
||||
return ((result >> 1) ^ -(result & 1));
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue