mirror of
https://github.com/demostf/povunlock.git
synced 2026-06-03 22:14:11 +02:00
wip
This commit is contained in:
parent
5e374afa56
commit
9ed1c79766
4 changed files with 68 additions and 5 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -4,3 +4,4 @@ Cargo.lock
|
||||||
bin/
|
bin/
|
||||||
pkg/
|
pkg/
|
||||||
wasm-pack.log
|
wasm-pack.log
|
||||||
|
out.dem
|
||||||
15
Cargo.toml
15
Cargo.toml
|
|
@ -7,13 +7,17 @@ edition = "2018"
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib", "rlib"]
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "unlock"
|
||||||
|
path = "src/unlock.rs"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["console_error_panic_hook"]
|
default = ["console_error_panic_hook"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitbuffer = "0.10.5"
|
bitbuffer = "0.10.5"
|
||||||
tf-demo-parser = { version = "0.4", git = "https://github.com/demostf/parser" }
|
#tf-demo-parser = { version = "0.4", git = "https://github.com/demostf/parser" }
|
||||||
#tf-demo-parser = { version = "0.4", path = "../tf-demo-parser" }
|
tf-demo-parser = { version = "0.4", path = "../tf-demo-parser" }
|
||||||
wasm-bindgen = "0.2"
|
wasm-bindgen = "0.2"
|
||||||
web-sys = { version = "0.3", features = ["console"] }
|
web-sys = { version = "0.3", features = ["console"] }
|
||||||
|
|
||||||
|
|
@ -29,10 +33,13 @@ console_error_panic_hook = { version = "0.1.6", optional = true }
|
||||||
#
|
#
|
||||||
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.
|
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.
|
||||||
wee_alloc = { version = "0.4.5", optional = true }
|
wee_alloc = { version = "0.4.5", optional = true }
|
||||||
|
clap = { version = "3.1.9", features = ["derive"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
wasm-bindgen-test = "0.3.13"
|
wasm-bindgen-test = "0.3.13"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
# Tell `rustc` to optimize for small code size.
|
lto = true
|
||||||
opt-level = "s"
|
|
||||||
|
[profile.dev.package."*"]
|
||||||
|
opt-level = 3
|
||||||
38
src/lib.rs
38
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::packet::{Packet, PacketType};
|
||||||
use tf_demo_parser::demo::message::Message;
|
use tf_demo_parser::demo::message::Message;
|
||||||
use bitbuffer::{BitWriteStream, LittleEndian, BitRead, BitWrite};
|
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;
|
extern crate web_sys;
|
||||||
|
|
||||||
|
|
@ -25,6 +27,10 @@ fn set_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]
|
#[wasm_bindgen]
|
||||||
pub fn unlock(input: &[u8]) -> Vec<u8> {
|
pub fn unlock(input: &[u8]) -> Vec<u8> {
|
||||||
set_panic_hook();
|
set_panic_hook();
|
||||||
|
|
@ -41,9 +47,41 @@ pub fn unlock(input: &[u8]) -> Vec<u8> {
|
||||||
let mut handler = DemoHandler::default();
|
let mut handler = DemoHandler::default();
|
||||||
handler.handle_header(&header);
|
handler.handle_header(&header);
|
||||||
|
|
||||||
|
let mut local_player_entity_id = None;
|
||||||
|
|
||||||
while let Some(mut packet) = packets.next(&handler.state_handler).unwrap() {
|
while let Some(mut packet) = packets.next(&handler.state_handler).unwrap() {
|
||||||
match &mut packet {
|
match &mut packet {
|
||||||
Packet::Signon(message_packet) | Packet::Message(message_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.meta.view_angles = Default::default();
|
||||||
message_packet
|
message_packet
|
||||||
.messages
|
.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