1 Commits

Author SHA1 Message Date
5000d8885e binrw generic struct tech 2025-09-26 17:32:39 -07:00
6 changed files with 273 additions and 809 deletions

48
Cargo.lock generated
View File

@@ -10,9 +10,9 @@ checksum = "3d62b7694a562cdf5a74227903507c56ab2cc8bdd1f781ed5cb4cf9c9f810bfc"
[[package]]
name = "binrw"
version = "0.15.0"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81419ff39e6ed10a92a7f125290859776ced35d9a08a665ae40b23e7ca702f30"
checksum = "7d4bca59c20d6f40c2cc0802afbe1e788b89096f61bdf7aeea6bf00f10c2909b"
dependencies = [
"array-init",
"binrw_derive",
@@ -21,9 +21,9 @@ dependencies = [
[[package]]
name = "binrw_derive"
version = "0.15.0"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "376404e55ec40d0d6f8b4b7df3f87b87954bd987f0cf9a7207ea3b6ea5c9add4"
checksum = "d8ba42866ce5bced2645bfa15e97eef2c62d2bdb530510538de8dd3d04efff3c"
dependencies = [
"either",
"owo-colors",
@@ -34,15 +34,15 @@ dependencies = [
[[package]]
name = "bitflags"
version = "2.10.0"
version = "2.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"
checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"
[[package]]
name = "bytemuck"
version = "1.24.0"
version = "1.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fbdf580320f38b612e485521afda1ee26d10cc9884efaaa750d383e13e3c5f4"
checksum = "b6b1fc10dbac614ebc03540c9dbd60e83887fda27794998c6528f1782047d540"
[[package]]
name = "either"
@@ -50,53 +50,43 @@ version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
[[package]]
name = "itertools"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285"
dependencies = [
"either",
]
[[package]]
name = "owo-colors"
version = "4.2.3"
version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c6901729fa79e91a0913333229e9ca5dc725089d1c363b2f4b4760709dc4a52"
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
[[package]]
name = "proc-macro2"
version = "1.0.103"
version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.42"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
"proc-macro2",
]
[[package]]
name = "strafesnet_roblox_bot_file"
version = "0.9.4"
version = "0.3.1"
dependencies = [
"binrw",
"bitflags",
"itertools",
]
[[package]]
name = "syn"
version = "2.0.111"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
@@ -105,6 +95,6 @@ dependencies = [
[[package]]
name = "unicode-ident"
version = "1.0.22"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"

View File

@@ -1,13 +1,8 @@
[package]
name = "strafesnet_roblox_bot_file"
version = "0.9.4"
edition = "2024"
version = "0.3.1"
edition = "2021"
[dependencies]
binrw = "0.15.0"
binrw = "0.14.1"
bitflags = "2.6.0"
itertools = { version = "0.14.0", optional = true }
[features]
default = ["itertools"]
itertools = ["dep:itertools"]

View File

@@ -3,45 +3,30 @@ Roblox Bhop/Surf Bot File Format
## Example
Read the whole file and print each position:
```rust
use strafesnet_roblox_bot_file::v0::read_all_to_block;
use strafesnet_roblox_bot_file::{File,TimedBlockId};
let file=std::fs::read("bot_file")?;
let mut input=std::io::Cursor::new(file);
let file=std::fs::File::open("bot_file")?;
let input=std::io::BufReader::new(file);
let mut bot_file=File::new(input)?;
let block=read_all_to_block(&mut input)?;
// read the whole file
let block=bot_file.read_all()?;
for output_event in &block.output_events{
println!("{:?}",output_event.event.position);
// or do data streaming block by block
for &TimedBlockId{time,block_id} in &bot_file.header.offline_blocks_timeline{
// header is immutably borrowed
// while data is mutably borrowed
let block_info=bot_file.header.block_info(block_id)?;
let block=bot_file.data.read_block_info(block_info)?;
// offline blocks include the following event types:
// World, Gravity, Run, Camera, Setting
}
```
Or decode individual blocks using block location info:
```rust
use strafesnet_roblox_bot_file::v0::{Block,BlockTimelines,FileHeader};
let file=std::fs::read("bot_file")?;
let mut input=std::io::Cursor::new(file);
// FileHeader is the first 16 bytes of the file.
let header=FileHeader::from_reader(&mut input)?;
// BlockTimelines is an index of the blocks within the file.
let timelines=BlockTimelines::from_reader(&header,&mut input)?;
// offline blocks include the following event types:
// World, Gravity, Run, Camera, Setting
for timed in timelines.offline_blocks(){
let block_info=timelines.block_info(timed.event)?;
let block_reader=block_info.take_seek(&mut input)?;
let block=Block::from_reader(block_reader)?;
}
// realtime blocks include the following event types:
// Input, Output, Sound
for timed in timelines.realtime_blocks(){
let block_info=timelines.block_info(timed.event)?;
let block_reader=block_info.take_seek(&mut input)?;
let block=Block::from_reader(block_reader)?;
for &TimedBlockId{time,block_id} in &bot_file.header.realtime_blocks_timeline{
let block_info=bot_file.header.block_info(block_id)?;
let block=bot_file.data.read_block_info(block_info)?;
// realtime blocks include the following event types:
// Input, Output, Sound
}
```

View File

@@ -1,5 +1,3 @@
pub use binrw::Error as BinrwError;
pub mod v0;
#[cfg(test)]

View File

@@ -1,41 +1,43 @@
use crate::v0;
use crate::v0::{Block,BlockTimelines,FileHeader};
use crate::v0::{Error,File,Timed};
#[test]
fn deserialize_manual()->Result<(),binrw::Error>{
let file=std::fs::read("files/bhop_marble_7cf33a64-7120-4514-b9fa-4fe29d9523d").unwrap();
let mut input=std::io::Cursor::new(file);
let header=FileHeader::from_reader(&mut input)?;
let timelines=BlockTimelines::from_reader(&header,&mut input)?;
for block in timelines.offline_blocks(){
let block_info=timelines.block_info(block.event).unwrap();
let block_reader=block_info.take_seek(&mut input)?;
let _block=Block::from_reader(block_reader)?;
fn _1()->Result<(),Error>{
let file=std::fs::File::open("files/bhop_marble_7cf33a64-7120-4514-b9fa-4fe29d9523d").unwrap();
let input=std::io::BufReader::new(file);
let mut bot_file=File::new(input).unwrap();
println!("header={:?}",bot_file.header);
for &Timed{time,event:block_id} in &bot_file.header.offline_blocks_timeline{
println!("offline time={} block_id={:?}",time,block_id);
let block_info=bot_file.header.block_info(block_id)?;
let _block=bot_file.data.read_block_info(block_info)?;
// offline blocks include the following event types:
// World, Gravity, Run, Camera, Setting
}
for block in timelines.realtime_blocks(){
let block_info=timelines.block_info(block.event).unwrap();
let block_reader=block_info.take_seek(&mut input)?;
let _block=Block::from_reader(block_reader)?;
for &Timed{time,event:block_id} in &bot_file.header.realtime_blocks_timeline{
println!("realtime time={} block_id={:?}",time,block_id);
let block_info=bot_file.header.block_info(block_id)?;
let _block=bot_file.data.read_block_info(block_info)?;
// realtime blocks include the following event types:
// Input, Output, Sound
}
Ok(())
}
#[test]
fn deserialize_all()->Result<(),v0::Error>{
let file=std::fs::read("files/bhop_marble_7cf33a64-7120-4514-b9fa-4fe29d9523d").unwrap();
let _block=v0::read_all_to_block(std::io::Cursor::new(file))?;
fn _2()->Result<(),Error>{
let file=std::fs::File::open("files/bhop_marble_7cf33a64-7120-4514-b9fa-4fe29d9523d").unwrap();
let input=std::io::BufReader::new(file);
let t0=std::time::Instant::now();
let mut bot_file=File::new(input).unwrap();
let _block=bot_file.read_all()?;
println!("{:?}",t0.elapsed());
Ok(())
}
#[test]
#[cfg(feature="itertools")]
fn serialize_round_trip()->Result<(),binrw::Error>{
let file=std::fs::read("files/bhop_marble_7cf33a64-7120-4514-b9fa-4fe29d9523d").unwrap();
let block=v0::read_all_to_block(std::io::Cursor::new(file.as_slice())).unwrap();
let mut data=Vec::with_capacity(file.len());
v0::serialize(&block,&mut std::io::Cursor::new(&mut data))?;
// TODO: It encodes, but is it equal? Test something! PartialEq?
Ok(())
}
// TODO: file serialization test

906
src/v0.rs

File diff suppressed because it is too large Load Diff