mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 09:04:13 +02:00
go trough an entire demo without errors
seemingly working entity parsing
This commit is contained in:
parent
675bf59a74
commit
1c33058cb4
4 changed files with 19 additions and 17 deletions
|
|
@ -3,14 +3,20 @@ import {BitStream} from "bit-buffer";
|
|||
import {SendProp} from "../Data/SendProp";
|
||||
import {SendPropParser} from "./SendPropParser";
|
||||
import {readUBitVar} from "./readBitVar";
|
||||
import {SendTable} from "../Data/SendTable";
|
||||
|
||||
export function applyEntityUpdate(entity: Entity, stream: BitStream): Entity {
|
||||
export function applyEntityUpdate(entity: Entity, stream: BitStream, sendTable?: SendTable): Entity {
|
||||
if (!sendTable) {
|
||||
sendTable = entity.sendTable;
|
||||
}
|
||||
let index = -1;
|
||||
const allProps = entity.sendTable.flattenedProps;
|
||||
const allProps = sendTable.flattenedProps;
|
||||
let lastProps:SendProp[] = [];
|
||||
while ((index = readFieldIndex(stream, index)) != -1) {
|
||||
if (index >= 4096 || index > allProps.length) {
|
||||
throw new Error('prop index out of bounds while applying update for ' + entity.sendTable.name + ' got ' + index
|
||||
+ ' proptype only has ' + allProps.length + ' properties');
|
||||
console.log(lastProps[lastProps.length - 1]);
|
||||
throw new Error('prop index out of bounds while applying update for ' + sendTable.name + ' got ' + index
|
||||
+ ' property only has ' + allProps.length + ' properties');
|
||||
}
|
||||
|
||||
const propDefinition = allProps[index];
|
||||
|
|
@ -18,7 +24,7 @@ export function applyEntityUpdate(entity: Entity, stream: BitStream): Entity {
|
|||
|
||||
const prop = existingProp ? existingProp : new SendProp(propDefinition);
|
||||
prop.value = SendPropParser.decode(propDefinition, stream);
|
||||
// console.log(entity.props.length, prop);
|
||||
lastProps.push(prop);
|
||||
|
||||
if (!existingProp) {
|
||||
entity.props.push(prop);
|
||||
|
|
|
|||
|
|
@ -35,17 +35,16 @@ function readPVSType(stream: BitStream): PVS {
|
|||
function readEnterPVS(stream: BitStream, entityId: number, match: Match, baseLine: number): Entity {
|
||||
// https://github.com/PazerOP/DemoLib/blob/5f9467650f942a4a70f9ec689eadcd3e0a051956/TF2Net/NetMessages/NetPacketEntitiesMessage.cs#L198
|
||||
const serverClass = match.serverClasses[stream.readBits(match.classBits)];
|
||||
// console.log(serverClass);
|
||||
const sendTable = match.getSendTable(serverClass.dataTable);
|
||||
const serialNumber = stream.readBits(10);
|
||||
if (!sendTable) {
|
||||
throw new Error('Unknown SendTable for serverclass');
|
||||
}
|
||||
|
||||
let entity = match.entities[entityId];
|
||||
if (!entity) {
|
||||
entity = new Entity(serverClass, sendTable, entityId, serialNumber);
|
||||
}
|
||||
// if (match.entities[entityId]) {
|
||||
// console.log('overwriting entity');
|
||||
// }
|
||||
const entity = new Entity(serverClass, sendTable, entityId, serialNumber);
|
||||
|
||||
const decodedBaseLine = match.instanceBaselines[baseLine][entityId];
|
||||
if (decodedBaseLine) {
|
||||
|
|
@ -59,9 +58,9 @@ function readEnterPVS(stream: BitStream, entityId: number, match: Match, baseLin
|
|||
const staticBaseLine = match.staticBaseLines[serverClass.id];
|
||||
if (staticBaseLine) {
|
||||
staticBaseLine.index = 0;
|
||||
applyEntityUpdate(entity, staticBaseLine);
|
||||
applyEntityUpdate(entity, staticBaseLine, sendTable);
|
||||
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, ' + staticBaseLine.bitsLeft + ' bits left');
|
||||
}
|
||||
}
|
||||
|
|
@ -109,10 +108,8 @@ export function PacketEntities(stream: BitStream, match: Match): Packet { //26:
|
|||
const diff = readUBitVar(stream);
|
||||
entityId += 1 + diff;
|
||||
const pvs = readPVSType(stream);
|
||||
console.log("entity: " + entityId, ", pvs " + PVS[pvs]);
|
||||
if (pvs === PVS.ENTER) {
|
||||
const entity = readEnterPVS(stream, entityId, match, baseLine);
|
||||
console.log('got entity');
|
||||
applyEntityUpdate(entity, stream);
|
||||
match.entities[entityId] = entity;
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ export function UpdateStringTable(stream: BitStream, match: Match): Packet { //
|
|||
}
|
||||
|
||||
const table = match.stringTables[tableId];
|
||||
console.log('update table ' + table.name);
|
||||
parseStringTable(data, table, changedEntries, match);
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -139,8 +139,8 @@ export class SendPropParser {
|
|||
} else {
|
||||
value = stream.readBits(14) + 1;
|
||||
if (value < (1 << 11)) {
|
||||
console.log(propDefinition, value);
|
||||
throw new Error("Something's fishy...");
|
||||
// console.log(propDefinition, value);
|
||||
// throw new Error("Something's fishy...");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue