use released parser

This commit is contained in:
Robin Appelman 2021-07-24 19:28:06 +02:00
commit ef10a22acd
3 changed files with 17 additions and 94 deletions

View file

@ -11,9 +11,9 @@ crate-type = ["cdylib", "rlib"]
default = ["console_error_panic_hook"]
[dependencies]
bitbuffer = "0.9"
tf-demo-parser = { version = "0.2.6", path = "../tf-demo-parser" }
wasm-bindgen = "0.2.63"
bitbuffer = "0.10"
tf-demo-parser = "0.3"
wasm-bindgen = "0.2"
web-sys = { version = "0.3", features = ["console"] }
# The `console_error_panic_hook` crate provides better debugging of panics by

View file

@ -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>
<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>
</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.
- `wasm-pack build`
- `cd www && npm run build`

View file

@ -1,20 +1,13 @@
use wasm_bindgen::prelude::*;
use tf_demo_parser::{Demo};
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::message::Message;
use bitbuffer::{BitWriteStream, LittleEndian, BitRead, BitWrite};
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
// allocator.
#[cfg(feature = "wee_alloc")]
@ -35,7 +28,6 @@ fn set_panic_hook() {
#[wasm_bindgen]
pub fn unlock(input: &[u8]) -> Vec<u8> {
set_panic_hook();
log!("got {} bytes", input.len());
let mut out_buffer = Vec::with_capacity(input.len());
{
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();
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);
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()
.map(|mut msg| {
match &mut msg {
Message::ServerInfo(info) => {
message_packet
.messages
.iter_mut()
.for_each(|msg| if let Message::ServerInfo(info) = msg {
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
.encode(&mut out_stream, &handler.state_handler)
.unwrap();