mirror of
https://github.com/demostf/povunlock.git
synced 2026-06-03 22:14:11 +02:00
use released parser
This commit is contained in:
parent
bd25c22586
commit
ef10a22acd
3 changed files with 17 additions and 94 deletions
|
|
@ -11,9 +11,9 @@ crate-type = ["cdylib", "rlib"]
|
||||||
default = ["console_error_panic_hook"]
|
default = ["console_error_panic_hook"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitbuffer = "0.9"
|
bitbuffer = "0.10"
|
||||||
tf-demo-parser = { version = "0.2.6", path = "../tf-demo-parser" }
|
tf-demo-parser = "0.3"
|
||||||
wasm-bindgen = "0.2.63"
|
wasm-bindgen = "0.2"
|
||||||
web-sys = { version = "0.3", features = ["console"] }
|
web-sys = { version = "0.3", features = ["console"] }
|
||||||
|
|
||||||
# The `console_error_panic_hook` crate provides better debugging of panics by
|
# The `console_error_panic_hook` crate provides better debugging of panics by
|
||||||
|
|
|
||||||
71
README.md
71
README.md
|
|
@ -1,69 +1,8 @@
|
||||||
<div align="center">
|
# POV Unlock
|
||||||
|
|
||||||
<h1><code>wasm-pack-template</code></h1>
|
Unlock camera in POV demos
|
||||||
|
|
||||||
<strong>A template for kick starting a Rust and WebAssembly project using <a href="https://github.com/rustwasm/wasm-pack">wasm-pack</a>.</strong>
|
## Building
|
||||||
|
|
||||||
<p>
|
- `wasm-pack build`
|
||||||
<a href="https://travis-ci.org/rustwasm/wasm-pack-template"><img src="https://img.shields.io/travis/rustwasm/wasm-pack-template.svg?style=flat-square" alt="Build Status" /></a>
|
- `cd www && npm run build`
|
||||||
</p>
|
|
||||||
|
|
||||||
<h3>
|
|
||||||
<a href="https://rustwasm.github.io/docs/wasm-pack/tutorials/npm-browser-packages/index.html">Tutorial</a>
|
|
||||||
<span> | </span>
|
|
||||||
<a href="https://discordapp.com/channels/442252698964721669/443151097398296587">Chat</a>
|
|
||||||
</h3>
|
|
||||||
|
|
||||||
<sub>Built with 🦀🕸 by <a href="https://rustwasm.github.io/">The Rust and WebAssembly Working Group</a></sub>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
## About
|
|
||||||
|
|
||||||
[**📚 Read this template tutorial! 📚**][template-docs]
|
|
||||||
|
|
||||||
This template is designed for compiling Rust libraries into WebAssembly and
|
|
||||||
publishing the resulting package to NPM.
|
|
||||||
|
|
||||||
Be sure to check out [other `wasm-pack` tutorials online][tutorials] for other
|
|
||||||
templates and usages of `wasm-pack`.
|
|
||||||
|
|
||||||
[tutorials]: https://rustwasm.github.io/docs/wasm-pack/tutorials/index.html
|
|
||||||
[template-docs]: https://rustwasm.github.io/docs/wasm-pack/tutorials/npm-browser-packages/index.html
|
|
||||||
|
|
||||||
## 🚴 Usage
|
|
||||||
|
|
||||||
### 🐑 Use `cargo generate` to Clone this Template
|
|
||||||
|
|
||||||
[Learn more about `cargo generate` here.](https://github.com/ashleygwilliams/cargo-generate)
|
|
||||||
|
|
||||||
```
|
|
||||||
cargo generate --git https://github.com/rustwasm/wasm-pack-template.git --name my-project
|
|
||||||
cd my-project
|
|
||||||
```
|
|
||||||
|
|
||||||
### 🛠️ Build with `wasm-pack build`
|
|
||||||
|
|
||||||
```
|
|
||||||
wasm-pack build
|
|
||||||
```
|
|
||||||
|
|
||||||
### 🔬 Test in Headless Browsers with `wasm-pack test`
|
|
||||||
|
|
||||||
```
|
|
||||||
wasm-pack test --headless --firefox
|
|
||||||
```
|
|
||||||
|
|
||||||
### 🎁 Publish to NPM with `wasm-pack publish`
|
|
||||||
|
|
||||||
```
|
|
||||||
wasm-pack publish
|
|
||||||
```
|
|
||||||
|
|
||||||
## 🔋 Batteries Included
|
|
||||||
|
|
||||||
* [`wasm-bindgen`](https://github.com/rustwasm/wasm-bindgen) for communicating
|
|
||||||
between WebAssembly and JavaScript.
|
|
||||||
* [`console_error_panic_hook`](https://github.com/rustwasm/console_error_panic_hook)
|
|
||||||
for logging panic messages to the developer console.
|
|
||||||
* [`wee_alloc`](https://github.com/rustwasm/wee_alloc), an allocator optimized
|
|
||||||
for small code size.
|
|
||||||
34
src/lib.rs
34
src/lib.rs
|
|
@ -1,20 +1,13 @@
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
use tf_demo_parser::{Demo};
|
use tf_demo_parser::{Demo};
|
||||||
use tf_demo_parser::demo::header::Header;
|
use tf_demo_parser::demo::header::Header;
|
||||||
use tf_demo_parser::demo::parser::{RawPacketStream, DemoHandler, NullHandler, Encode};
|
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};
|
||||||
|
|
||||||
extern crate web_sys;
|
extern crate web_sys;
|
||||||
|
|
||||||
// A macro to provide `println!(..)`-style syntax for `console.log` logging.
|
|
||||||
macro_rules! log {
|
|
||||||
( $( $t:tt )* ) => {
|
|
||||||
web_sys::console::log_1(&format!( $( $t )* ).into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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.
|
||||||
#[cfg(feature = "wee_alloc")]
|
#[cfg(feature = "wee_alloc")]
|
||||||
|
|
@ -35,7 +28,6 @@ fn set_panic_hook() {
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn unlock(input: &[u8]) -> Vec<u8> {
|
pub fn unlock(input: &[u8]) -> Vec<u8> {
|
||||||
set_panic_hook();
|
set_panic_hook();
|
||||||
log!("got {} bytes", input.len());
|
|
||||||
let mut out_buffer = Vec::with_capacity(input.len());
|
let mut out_buffer = Vec::with_capacity(input.len());
|
||||||
{
|
{
|
||||||
let mut out_stream = BitWriteStream::new(&mut out_buffer, LittleEndian);
|
let mut out_stream = BitWriteStream::new(&mut out_buffer, LittleEndian);
|
||||||
|
|
@ -46,32 +38,24 @@ pub fn unlock(input: &[u8]) -> Vec<u8> {
|
||||||
header.write(&mut out_stream).unwrap();
|
header.write(&mut out_stream).unwrap();
|
||||||
|
|
||||||
let mut packets = RawPacketStream::new(stream.clone());
|
let mut packets = RawPacketStream::new(stream.clone());
|
||||||
let mut handler = DemoHandler::parse_all_with_analyser(NullHandler);
|
let mut handler = DemoHandler::default();
|
||||||
handler.handle_header(&header);
|
handler.handle_header(&header);
|
||||||
|
|
||||||
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::Sigon(message_packet) | Packet::Message(message_packet) => {
|
Packet::Sigon(message_packet) | Packet::Message(message_packet) => {
|
||||||
message_packet.meta.view_angles = Default::default();
|
message_packet.meta.view_angles = Default::default();
|
||||||
let messages = std::mem::take(&mut message_packet.messages);
|
message_packet
|
||||||
let messages = messages
|
.messages
|
||||||
.into_iter()
|
.iter_mut()
|
||||||
.map(|mut msg| {
|
.for_each(|msg| if let Message::ServerInfo(info) = msg {
|
||||||
match &mut msg {
|
info.stv = true;
|
||||||
Message::ServerInfo(info) => {
|
});
|
||||||
info.stv = true;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
};
|
|
||||||
msg
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
message_packet.messages = messages;
|
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if packet.packet_type() != PacketType::ConsoleCmd {
|
if packet.packet_type() != PacketType::ConsoleCmd && packet.packet_type() != PacketType::UserCmd {
|
||||||
packet
|
packet
|
||||||
.encode(&mut out_stream, &handler.state_handler)
|
.encode(&mut out_stream, &handler.state_handler)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue