1
0
Fork 0
mirror of https://github.com/demostf/demo.js synced 2026-06-04 00:54:14 +02:00

go trough an entire demo without errors

seemingly working entity parsing
This commit is contained in:
Robin Appelman 2017-02-11 16:47:19 +01:00
commit 1c33058cb4
4 changed files with 19 additions and 17 deletions

View file

@ -3,14 +3,20 @@ import {BitStream} from "bit-buffer";
import {SendProp} from "../Data/SendProp"; import {SendProp} from "../Data/SendProp";
import {SendPropParser} from "./SendPropParser"; import {SendPropParser} from "./SendPropParser";
import {readUBitVar} from "./readBitVar"; 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; let index = -1;
const allProps = entity.sendTable.flattenedProps; const allProps = sendTable.flattenedProps;
let lastProps:SendProp[] = [];
while ((index = readFieldIndex(stream, index)) != -1) { while ((index = readFieldIndex(stream, index)) != -1) {
if (index >= 4096 || index > allProps.length) { if (index >= 4096 || index > allProps.length) {
throw new Error('prop index out of bounds while applying update for ' + entity.sendTable.name + ' got ' + index console.log(lastProps[lastProps.length - 1]);
+ ' proptype only has ' + allProps.length + ' properties'); 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]; const propDefinition = allProps[index];
@ -18,7 +24,7 @@ export function applyEntityUpdate(entity: Entity, stream: BitStream): Entity {
const prop = existingProp ? existingProp : new SendProp(propDefinition); const prop = existingProp ? existingProp : new SendProp(propDefinition);
prop.value = SendPropParser.decode(propDefinition, stream); prop.value = SendPropParser.decode(propDefinition, stream);
// console.log(entity.props.length, prop); lastProps.push(prop);
if (!existingProp) { if (!existingProp) {
entity.props.push(prop); entity.props.push(prop);

View file

@ -35,17 +35,16 @@ function readPVSType(stream: BitStream): PVS {
function readEnterPVS(stream: BitStream, entityId: number, match: Match, baseLine: number): Entity { function readEnterPVS(stream: BitStream, entityId: number, match: Match, baseLine: number): Entity {
// https://github.com/PazerOP/DemoLib/blob/5f9467650f942a4a70f9ec689eadcd3e0a051956/TF2Net/NetMessages/NetPacketEntitiesMessage.cs#L198 // https://github.com/PazerOP/DemoLib/blob/5f9467650f942a4a70f9ec689eadcd3e0a051956/TF2Net/NetMessages/NetPacketEntitiesMessage.cs#L198
const serverClass = match.serverClasses[stream.readBits(match.classBits)]; const serverClass = match.serverClasses[stream.readBits(match.classBits)];
// console.log(serverClass);
const sendTable = match.getSendTable(serverClass.dataTable); const sendTable = match.getSendTable(serverClass.dataTable);
const serialNumber = stream.readBits(10); const serialNumber = stream.readBits(10);
if (!sendTable) { if (!sendTable) {
throw new Error('Unknown SendTable for serverclass'); throw new Error('Unknown SendTable for serverclass');
} }
let entity = match.entities[entityId]; // if (match.entities[entityId]) {
if (!entity) { // console.log('overwriting entity');
entity = new Entity(serverClass, sendTable, entityId, serialNumber); // }
} const entity = new Entity(serverClass, sendTable, entityId, serialNumber);
const decodedBaseLine = match.instanceBaselines[baseLine][entityId]; const decodedBaseLine = match.instanceBaselines[baseLine][entityId];
if (decodedBaseLine) { if (decodedBaseLine) {
@ -59,9 +58,9 @@ function readEnterPVS(stream: BitStream, entityId: number, match: Match, baseLin
const staticBaseLine = match.staticBaseLines[serverClass.id]; const staticBaseLine = match.staticBaseLines[serverClass.id];
if (staticBaseLine) { if (staticBaseLine) {
staticBaseLine.index = 0; staticBaseLine.index = 0;
applyEntityUpdate(entity, staticBaseLine); applyEntityUpdate(entity, staticBaseLine, sendTable);
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, ' + staticBaseLine.bitsLeft + ' bits left'); // 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); const diff = readUBitVar(stream);
entityId += 1 + diff; entityId += 1 + diff;
const pvs = readPVSType(stream); const pvs = readPVSType(stream);
console.log("entity: " + entityId, ", pvs " + PVS[pvs]);
if (pvs === PVS.ENTER) { if (pvs === PVS.ENTER) {
const entity = readEnterPVS(stream, entityId, match, baseLine); const entity = readEnterPVS(stream, entityId, match, baseLine);
console.log('got entity');
applyEntityUpdate(entity, stream); applyEntityUpdate(entity, stream);
match.entities[entityId] = entity; match.entities[entityId] = entity;

View file

@ -18,7 +18,6 @@ export function UpdateStringTable(stream: BitStream, match: Match): Packet { //
} }
const table = match.stringTables[tableId]; const table = match.stringTables[tableId];
console.log('update table ' + table.name);
parseStringTable(data, table, changedEntries, match); parseStringTable(data, table, changedEntries, match);
return { return {

View file

@ -139,8 +139,8 @@ export class SendPropParser {
} else { } else {
value = stream.readBits(14) + 1; value = stream.readBits(14) + 1;
if (value < (1 << 11)) { if (value < (1 << 11)) {
console.log(propDefinition, value); // console.log(propDefinition, value);
throw new Error("Something's fishy..."); // throw new Error("Something's fishy...");
} }
} }
} }