mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
set local player viewangles from message metadata
This commit is contained in:
parent
1a2d9ab093
commit
f92070d7ca
4 changed files with 20 additions and 10 deletions
|
|
@ -3,7 +3,7 @@ const fs = require('fs');
|
|||
const argv = require('minimist')(process.argv.slice(2), {boolean: true});
|
||||
|
||||
if (argv._.length !== 1) {
|
||||
console.log('Usage: "node analyse [--strings] [--dump] [--head] [--event-list] [--create-event-definitions] FILE"');
|
||||
console.log('Usage: "node analyse [--strings] [--slow] [--dump] [--head] [--event-list] [--create-event-definitions] FILE"');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
|
@ -15,7 +15,7 @@ const echo = function (data) {
|
|||
fs.readFile(argv._[0], function (err, data) {
|
||||
if (err) throw err;
|
||||
const demo = Demo.fromNodeBuffer(data);
|
||||
const analyser = demo.getAnalyser(true);
|
||||
const analyser = demo.getAnalyser(!argv.slow);
|
||||
const head = analyser.getHeader();
|
||||
if (argv.head) {
|
||||
echo(head);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import {EventEmitter} from 'events';
|
||||
import {Header} from './Data/Header';
|
||||
import {Match} from './Data/Match';
|
||||
import {MessageType} from './Data/Message';
|
||||
import {Packet} from './Data/Packet';
|
||||
import {Parser} from './Parser';
|
||||
|
||||
|
|
@ -31,9 +32,13 @@ export class Analyser extends EventEmitter {
|
|||
}
|
||||
|
||||
public * getPackets(): IterableIterator<Packet> {
|
||||
for (const packet of this.parser.getPackets()) {
|
||||
this.match.handlePacket(packet);
|
||||
yield packet;
|
||||
for (const message of this.parser.getMessages()) {
|
||||
if (message.type === MessageType.Packet) {
|
||||
for (const packet of message.packets) {
|
||||
this.match.handlePacket(packet, message);
|
||||
yield packet;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import {handleSayText2} from '../PacketHandler/SayText2';
|
|||
import {Building} from './Building';
|
||||
import {Chat} from './Chat';
|
||||
import {Death} from './Death';
|
||||
import {PacketMessage} from './Message';
|
||||
import {Packet} from './Packet';
|
||||
import {EntityId, PacketEntity} from './PacketEntity';
|
||||
import {ParserState} from './ParserState';
|
||||
|
|
@ -67,10 +68,10 @@ export class Match {
|
|||
};
|
||||
}
|
||||
|
||||
public handlePacket(packet: Packet) {
|
||||
public handlePacket(packet: Packet, message: PacketMessage) {
|
||||
switch (packet.packetType) {
|
||||
case 'packetEntities':
|
||||
handlePacketEntities(packet, this);
|
||||
handlePacketEntities(packet, this, message);
|
||||
break;
|
||||
case 'netTick':
|
||||
if (this.startTick === 0) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {Building, Dispenser, Sentry, Teleporter} from '../Data/Building';
|
||||
import {Match} from '../Data/Match';
|
||||
import {PacketMessage} from '../Data/Message';
|
||||
import {PacketEntitiesPacket} from '../Data/Packet';
|
||||
import {PacketEntity, PVS} from '../Data/PacketEntity';
|
||||
import {ParserState} from '../Data/ParserState';
|
||||
|
|
@ -9,9 +10,9 @@ import {TeamNumber} from '../Data/Team';
|
|||
import {Vector} from '../Data/Vector';
|
||||
import {CWeaponMedigun, Weapon} from '../Data/Weapon';
|
||||
|
||||
export function handlePacketEntities(packet: PacketEntitiesPacket, match: Match) {
|
||||
export function handlePacketEntities(packet: PacketEntitiesPacket, match: Match, message: PacketMessage) {
|
||||
for (const entity of packet.entities) {
|
||||
handleEntity(entity, match);
|
||||
handleEntity(entity, match, message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -33,7 +34,7 @@ function saveEntity(packetEntity: PacketEntity, state: ParserState) {
|
|||
state.entityClasses.set(packetEntity.entityIndex, packetEntity.serverClass);
|
||||
}
|
||||
|
||||
function handleEntity(entity: PacketEntity, match: Match) {
|
||||
function handleEntity(entity: PacketEntity, match: Match, message: PacketMessage) {
|
||||
for (const prop of entity.props) {
|
||||
if (prop.definition.ownerTableName === 'DT_AttributeContainer' && prop.definition.name === 'm_hOuter') {
|
||||
if (!match.outerMap.has(prop.value as number)) {
|
||||
|
|
@ -119,6 +120,9 @@ function handleEntity(entity: PacketEntity, match: Match) {
|
|||
case 'DT_TFLocalPlayerExclusive.m_vecOrigin':
|
||||
player.position.x = (prop.value as Vector).x;
|
||||
player.position.y = (prop.value as Vector).y;
|
||||
|
||||
// set the view angles for the local player since that prop isn't send
|
||||
player.viewAngle = message.localViewAngles[0].y;
|
||||
break;
|
||||
case 'DT_TFNonLocalPlayerExclusive.m_vecOrigin':
|
||||
player.position.x = (prop.value as Vector).x;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue