mirror of
https://github.com/demostf/povunlock.git
synced 2026-06-03 14:04:17 +02:00
wip
This commit is contained in:
parent
5e374afa56
commit
9ed1c79766
4 changed files with 68 additions and 5 deletions
40
src/lib.rs
40
src/lib.rs
|
|
@ -5,6 +5,8 @@ use tf_demo_parser::demo::parser::{RawPacketStream, DemoHandler, Encode};
|
|||
use tf_demo_parser::demo::packet::{Packet, PacketType};
|
||||
use tf_demo_parser::demo::message::Message;
|
||||
use bitbuffer::{BitWriteStream, LittleEndian, BitRead, BitWrite};
|
||||
use tf_demo_parser::demo::message::packetentities::PacketEntitiesMessage;
|
||||
use tf_demo_parser::demo::sendprop::{SendProp, SendPropIdentifier, SendPropValue};
|
||||
|
||||
extern crate web_sys;
|
||||
|
||||
|
|
@ -22,9 +24,13 @@ fn set_panic_hook() {
|
|||
// For more details see
|
||||
// https://github.com/rustwasm/console_error_panic_hook#readme
|
||||
#[cfg(feature = "console_error_panic_hook")]
|
||||
console_error_panic_hook::set_once();
|
||||
console_error_panic_hook::set_once();
|
||||
}
|
||||
|
||||
const LOCAL_PROP: SendPropIdentifier = SendPropIdentifier::new("DT_LocalPlayerExclusive", "m_nTickBase");
|
||||
const EYE_X_PROP: SendPropIdentifier = SendPropIdentifier::new("DT_TFLocalPlayerExclusive", "m_angEyeAngles[0]");
|
||||
const EYE_Y_PROP: SendPropIdentifier = SendPropIdentifier::new("DT_TFLocalPlayerExclusive", "m_angEyeAngles[1]");
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn unlock(input: &[u8]) -> Vec<u8> {
|
||||
set_panic_hook();
|
||||
|
|
@ -41,9 +47,41 @@ pub fn unlock(input: &[u8]) -> Vec<u8> {
|
|||
let mut handler = DemoHandler::default();
|
||||
handler.handle_header(&header);
|
||||
|
||||
let mut local_player_entity_id = None;
|
||||
|
||||
while let Some(mut packet) = packets.next(&handler.state_handler).unwrap() {
|
||||
match &mut packet {
|
||||
Packet::Signon(message_packet) | Packet::Message(message_packet) => {
|
||||
for msg in &mut message_packet
|
||||
.messages {
|
||||
if let Message::PacketEntities(PacketEntitiesMessage { entities, .. }) = msg {
|
||||
for entity in entities {
|
||||
if local_player_entity_id.is_none() && entity.get_prop_by_identifier(&LOCAL_PROP).is_some() {
|
||||
dbg!(entity.entity_index);
|
||||
local_player_entity_id = Some(entity.entity_index);
|
||||
}
|
||||
|
||||
if Some(entity.entity_index) == local_player_entity_id {
|
||||
let index_x = handler.state_handler.index_for_prop(entity.server_class, EYE_X_PROP).expect("index_x not found");
|
||||
let index_y = handler.state_handler.index_for_prop(entity.server_class, EYE_Y_PROP).expect("index_y not found");
|
||||
|
||||
entity.apply_update(&[
|
||||
SendProp {
|
||||
index: index_x,
|
||||
identifier: EYE_X_PROP,
|
||||
value: SendPropValue::Float(message_packet.meta.view_angles[0].local_angles.x),
|
||||
},
|
||||
SendProp {
|
||||
index: index_y,
|
||||
identifier: EYE_Y_PROP,
|
||||
value: SendPropValue::Float(message_packet.meta.view_angles[0].local_angles.y),
|
||||
},
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
message_packet.meta.view_angles = Default::default();
|
||||
message_packet
|
||||
.messages
|
||||
|
|
|
|||
17
src/unlock.rs
Normal file
17
src/unlock.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
use clap::Parser;
|
||||
use povunlock::unlock;
|
||||
use std::fs;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(author, version, about, long_about = None)]
|
||||
struct Args {
|
||||
/// Path to the source demo
|
||||
path: String,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = Args::parse();
|
||||
let file = fs::read(&args.path).unwrap();
|
||||
let output = unlock(&file);
|
||||
fs::write("out.dem", output).unwrap();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue