mirror of
https://github.com/demostf/povunlock.git
synced 2026-06-03 22:14:11 +02:00
initial
This commit is contained in:
parent
30293d021a
commit
5c04a7892d
2 changed files with 55 additions and 7 deletions
|
|
@ -11,6 +11,8 @@ crate-type = ["cdylib", "rlib"]
|
||||||
default = ["console_error_panic_hook"]
|
default = ["console_error_panic_hook"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
bitbuffer = "0.9"
|
||||||
|
tf-demo-parser = { version = "0.2.6", path = "../tf-demo-parser" }
|
||||||
wasm-bindgen = "0.2.63"
|
wasm-bindgen = "0.2.63"
|
||||||
|
|
||||||
# The `console_error_panic_hook` crate provides better debugging of panics by
|
# The `console_error_panic_hook` crate provides better debugging of panics by
|
||||||
|
|
|
||||||
58
src/lib.rs
58
src/lib.rs
|
|
@ -1,6 +1,13 @@
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
use tf_demo_parser::{Demo, MessageType};
|
||||||
|
use tf_demo_parser::demo::header::Header;
|
||||||
|
use tf_demo_parser::demo::parser::{RawPacketStream, DemoHandler, NullHandler, Encode};
|
||||||
|
use tf_demo_parser::demo::packet::{Packet, PacketType};
|
||||||
|
use tf_demo_parser::demo::message::Message;
|
||||||
|
use std::error::Error;
|
||||||
|
use bitbuffer::{BitWriteStream, LittleEndian, BitRead, BitWrite};
|
||||||
|
|
||||||
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
|
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
|
||||||
// allocator.
|
// allocator.
|
||||||
|
|
@ -9,11 +16,50 @@ use wasm_bindgen::prelude::*;
|
||||||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
pub fn unlock(input: &[u8]) -> Vec<u8> {
|
||||||
fn alert(s: &str);
|
let mut out_buffer = Vec::with_capacity(input.len());
|
||||||
}
|
{
|
||||||
|
let mut out_stream = BitWriteStream::new(&mut out_buffer, LittleEndian);
|
||||||
|
|
||||||
#[wasm_bindgen]
|
let demo = Demo::new(&input);
|
||||||
pub fn greet() {
|
let mut stream = demo.get_stream();
|
||||||
alert("Hello, povunlock!");
|
let header = Header::read(&mut stream).unwrap();
|
||||||
|
header.write(&mut out_stream).unwrap();
|
||||||
|
|
||||||
|
let mut packets = RawPacketStream::new(stream.clone());
|
||||||
|
let mut handler = DemoHandler::parse_all_with_analyser(NullHandler);
|
||||||
|
handler.handle_header(&header);
|
||||||
|
|
||||||
|
while let Some(mut packet) = packets.next(&handler.state_handler).unwrap() {
|
||||||
|
match &mut packet {
|
||||||
|
Packet::Sigon(message_packet) | Packet::Message(message_packet) => {
|
||||||
|
message_packet.meta.view_angles = Default::default();
|
||||||
|
let messages = std::mem::take(&mut message_packet.messages);
|
||||||
|
let messages = messages
|
||||||
|
.into_iter()
|
||||||
|
.filter(|msg| msg.get_message_type() != MessageType::SetView)
|
||||||
|
.map(|mut msg| {
|
||||||
|
match &mut msg {
|
||||||
|
Message::ServerInfo(info) => {
|
||||||
|
info.stv = true;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
msg
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
message_packet.messages = messages;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if packet.packet_type() != PacketType::ConsoleCmd {
|
||||||
|
packet
|
||||||
|
.encode(&mut out_stream, &handler.state_handler)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
handler.handle_packet(packet).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out_buffer
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue