mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
parse world boundary
This commit is contained in:
parent
58852ffac7
commit
4a8745250f
6 changed files with 39 additions and 14 deletions
0
bin/analyse.js
Normal file → Executable file
0
bin/analyse.js
Normal file → Executable file
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "tf2-demo",
|
"name": "tf2-demo",
|
||||||
"description": "A parser for TF2 demo files",
|
"description": "A parser for TF2 demo files",
|
||||||
"version": "0.2.5",
|
"version": "1.0.0",
|
||||||
"bin": {
|
"bin": {
|
||||||
"demo-analyse": "./bin/analyse.js"
|
"demo-analyse": "./bin/analyse.js"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -27,5 +27,14 @@ export class Entity {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getProperty(originTable: string, name: string) {
|
||||||
|
for (const prop of this.props) {
|
||||||
|
if (prop.definition.ownerTableName === originTable && prop.definition.name === name) {
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error('Property not found in entity');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ import {SendProp} from "./SendProp";
|
||||||
import {GameEventDefinitionMap} from "./GameEvent";
|
import {GameEventDefinitionMap} from "./GameEvent";
|
||||||
import {BitStream} from "bit-buffer";
|
import {BitStream} from "bit-buffer";
|
||||||
import {UserInfo} from "./UserInfo";
|
import {UserInfo} from "./UserInfo";
|
||||||
|
import {World} from "./World";
|
||||||
|
import {Vector} from "./Vector";
|
||||||
export class Match {
|
export class Match {
|
||||||
tick: number;
|
tick: number;
|
||||||
chat: any[];
|
chat: any[];
|
||||||
|
|
@ -21,6 +23,7 @@ export class Match {
|
||||||
instanceBaselines: SendProp[][][];
|
instanceBaselines: SendProp[][][];
|
||||||
staticBaseLines: BitStream[];
|
staticBaseLines: BitStream[];
|
||||||
eventDefinitions: GameEventDefinitionMap;
|
eventDefinitions: GameEventDefinitionMap;
|
||||||
|
world: World;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.tick = 0;
|
this.tick = 0;
|
||||||
|
|
@ -38,6 +41,10 @@ export class Match {
|
||||||
this.instanceBaselines = [[], []];
|
this.instanceBaselines = [[], []];
|
||||||
this.staticBaseLines = [];
|
this.staticBaseLines = [];
|
||||||
this.eventDefinitions = {};
|
this.eventDefinitions = {};
|
||||||
|
this.world = {
|
||||||
|
boundaryMin: {x: 0, y: 0, z: 0},
|
||||||
|
boundaryMax: {x: 0, y: 0, z: 0}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getSendTable(name) {
|
getSendTable(name) {
|
||||||
|
|
@ -73,11 +80,8 @@ export class Match {
|
||||||
switch (packet.packetType) {
|
switch (packet.packetType) {
|
||||||
case 'packetEntities':
|
case 'packetEntities':
|
||||||
for (const entity of this.entities) {
|
for (const entity of this.entities) {
|
||||||
if (entity && entity.serverClass.name === 'CTFPlayer') {
|
if (entity) {
|
||||||
// console.log(entity.props.map((prop: SendProp) => {
|
this.handleEntity(entity);
|
||||||
// return prop.definition.ownerTableName + '.' + prop.definition.name;
|
|
||||||
// }));
|
|
||||||
// console.log(this.getUserInfoForEntity(entity).name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -194,4 +198,13 @@ export class Match {
|
||||||
get classBits() {
|
get classBits() {
|
||||||
return Math.ceil(Math.log(this.serverClasses.length) * Math.LOG2E)
|
return Math.ceil(Math.log(this.serverClasses.length) * Math.LOG2E)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleEntity(entity: Entity) {
|
||||||
|
switch (entity.serverClass.name) {
|
||||||
|
case 'CWorld':
|
||||||
|
this.world.boundaryMin = <Vector>entity.getProperty('DT_WORLD', 'm_WorldMins').value;
|
||||||
|
this.world.boundaryMax = <Vector>entity.getProperty('DT_WORLD', 'm_WorldMaxs').value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
5
src/Data/World.ts
Normal file
5
src/Data/World.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
import {Vector} from "./Vector";
|
||||||
|
export interface World {
|
||||||
|
boundaryMin: Vector;
|
||||||
|
boundaryMax: Vector;
|
||||||
|
}
|
||||||
|
|
@ -58,10 +58,8 @@ export class Parser extends EventEmitter {
|
||||||
const message = this.readMessage(this.stream, this.match);
|
const message = this.readMessage(this.stream, this.match);
|
||||||
if (message instanceof MessageParser) {
|
if (message instanceof MessageParser) {
|
||||||
this.handleMessage(message);
|
this.handleMessage(message);
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return !!message;
|
||||||
}
|
}
|
||||||
|
|
||||||
parseMessage(data: BitStream, type: MessageType, tick: number, length: number, match: Match): MessageParser {
|
parseMessage(data: BitStream, type: MessageType, tick: number, length: number, match: Match): MessageParser {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue