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

parse some player info

This commit is contained in:
Robin Appelman 2017-02-11 20:33:13 +01:00
commit 1a71b65f12
4 changed files with 73 additions and 7 deletions

View file

@ -9,6 +9,7 @@ export class Entity {
serialNumber: number; serialNumber: number;
props: SendProp[]; props: SendProp[];
inPVS: boolean; inPVS: boolean;
updatedProps: SendProp[];
constructor(serverClass: ServerClass, sendTable: SendTable, entityIndex: number, serialNumber: number) { constructor(serverClass: ServerClass, sendTable: SendTable, entityIndex: number, serialNumber: number) {
this.serverClass = serverClass; this.serverClass = serverClass;
@ -17,6 +18,7 @@ export class Entity {
this.serialNumber = serialNumber; this.serialNumber = serialNumber;
this.props = []; this.props = [];
this.inPVS = false; this.inPVS = false;
this.updatedProps = [];
} }
getPropByDefinition(definition: SendPropDefinition) { getPropByDefinition(definition: SendPropDefinition) {

View file

@ -8,6 +8,7 @@ import {BitStream} from "bit-buffer";
import {UserInfo} from "./UserInfo"; import {UserInfo} from "./UserInfo";
import {World} from "./World"; import {World} from "./World";
import {Vector} from "./Vector"; import {Vector} from "./Vector";
import {Player} from "./Player";
export class Match { export class Match {
tick: number; tick: number;
chat: any[]; chat: any[];
@ -24,6 +25,8 @@ export class Match {
staticBaseLines: BitStream[]; staticBaseLines: BitStream[];
eventDefinitions: GameEventDefinitionMap; eventDefinitions: GameEventDefinitionMap;
world: World; world: World;
players: Player[];
playerMap: {[entityId: number]: Player};
constructor() { constructor() {
this.tick = 0; this.tick = 0;
@ -41,6 +44,8 @@ export class Match {
this.instanceBaselines = [[], []]; this.instanceBaselines = [[], []];
this.staticBaseLines = []; this.staticBaseLines = [];
this.eventDefinitions = {}; this.eventDefinitions = {};
this.players = [];
this.playerMap = {};
this.world = { this.world = {
boundaryMin: {x: 0, y: 0, z: 0}, boundaryMin: {x: 0, y: 0, z: 0},
boundaryMax: {x: 0, y: 0, z: 0} boundaryMax: {x: 0, y: 0, z: 0}
@ -107,15 +112,20 @@ export class Match {
if (table.name === 'userinfo') { if (table.name === 'userinfo') {
for (const userData of table.entries) { for (const userData of table.entries) {
if (userData.extraData) { if (userData.extraData) {
if (userData.extraData.bitsLeft > (32*8)) {
const name = userData.extraData.readUTF8String(32); const name = userData.extraData.readUTF8String(32);
const userId = userData.extraData.readUint32(); const userId = userData.extraData.readUint32();
const steamId = userData.extraData.readUTF8String(); const steamId = userData.extraData.readUTF8String();
if (steamId) {
const userState = this.getUserInfo(userId); const userState = this.getUserInfo(userId);
userState.name = name; userState.name = name;
userState.steamId = steamId; userState.steamId = steamId;
userState.entityId = parseInt(userData.text, 10) + 1; userState.entityId = parseInt(userData.text, 10) + 1;
} }
} }
}
}
} }
} }
break; break;
@ -153,10 +163,14 @@ export class Match {
case 'player_spawn': case 'player_spawn':
const userId = packet.event.values.userid; const userId = packet.event.values.userid;
const userState = this.getUserInfo(userId); const userState = this.getUserInfo(userId);
const player = this.playerMap[userState.entityId];
if (!userState.team) { //only register first spawn if (!userState.team) { //only register first spawn
userState.team = packet.event.values.team === 2 ? 'red' : 'blue' userState.team = packet.event.values.team === 2 ? 'red' : 'blue'
} }
const classId = packet.event.values.class; const classId = packet.event.values.class;
if (player) {
player.classId = classId;
}
if (!userState.classes[classId]) { if (!userState.classes[classId]) {
userState.classes[classId] = 0; userState.classes[classId] = 0;
} }
@ -205,6 +219,46 @@ export class Match {
this.world.boundaryMin = <Vector>entity.getProperty('DT_WORLD', 'm_WorldMins').value; this.world.boundaryMin = <Vector>entity.getProperty('DT_WORLD', 'm_WorldMins').value;
this.world.boundaryMax = <Vector>entity.getProperty('DT_WORLD', 'm_WorldMaxs').value; this.world.boundaryMax = <Vector>entity.getProperty('DT_WORLD', 'm_WorldMaxs').value;
break; break;
case 'CTFPlayer':
const player: Player = (this.playerMap[entity.entityIndex]) ? this.playerMap[entity.entityIndex] : {
user: this.getUserInfoForEntity(entity),
position: new Vector(0, 0, 0),
maxHealth: 0,
health: 0,
};
if (!this.playerMap[entity.entityIndex]) {
this.playerMap[entity.entityIndex] = player;
this.players.push(player);
}
for (const prop of entity.updatedProps) {
const propName = prop.definition.ownerTableName + '.' + prop.definition.name;
// console.log(propName, prop.value);
switch (propName) {
case 'DT_BasePlayer.m_iHealth':
player.health = <number>prop.value;
break;
case 'DT_BasePlayer.m_iMaxHealth':
player.maxHealth = <number>prop.value;
break;
case 'DT_TFLocalPlayerExclusive.m_vecOrigin':
player.position.x = (<Vector>prop.value).x;
player.position.y = (<Vector>prop.value).y;
break;
case 'DT_TFNonLocalPlayerExclusive.m_vecOrigin':
player.position.x = (<Vector>prop.value).x;
player.position.y = (<Vector>prop.value).y;
break;
case 'DT_TFLocalPlayerExclusive.m_vecOrigin[2]':
player.position.z = <number>prop.value;
break;
case 'DT_TFNonLocalPlayerExclusive.m_vecOrigin[2]':
player.position.z = <number>prop.value;
break;
} }
} }
}
entity.updatedProps = [];
}
} }

9
src/Data/Player.ts Normal file
View file

@ -0,0 +1,9 @@
import {UserInfo} from "./UserInfo";
import {Vector} from "./Vector";
export interface Player {
user: UserInfo;
position: Vector;
health: number;
maxHealth: number;
classId: number;
}

View file

@ -24,6 +24,7 @@ export function applyEntityUpdate(entity: Entity, stream: BitStream, sendTable?:
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);
entity.updatedProps.push(prop);
lastProps.push(prop); lastProps.push(prop);
if (!existingProp) { if (!existingProp) {