mirror of
https://github.com/redstrate/Physis.git
synced 2025-07-20 07:47:45 +00:00
Begin adding support for UWB files
I'm not entirely sure what this is for yet, it's layout/level related.
This commit is contained in:
parent
5a5896a126
commit
f23ebd0597
2 changed files with 77 additions and 0 deletions
|
@ -137,6 +137,9 @@ pub mod stm;
|
||||||
/// Reading patch lists
|
/// Reading patch lists
|
||||||
pub mod patchlist;
|
pub mod patchlist;
|
||||||
|
|
||||||
|
/// Reading UWB files
|
||||||
|
pub mod uwb;
|
||||||
|
|
||||||
mod bcn;
|
mod bcn;
|
||||||
|
|
||||||
mod error;
|
mod error;
|
||||||
|
|
74
src/uwb.rs
Normal file
74
src/uwb.rs
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
// SPDX-FileCopyrightText: 2025 Joshua Goins <josh@redstrate.com>
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
use std::io::Cursor;
|
||||||
|
|
||||||
|
use crate::ByteBuffer;
|
||||||
|
use crate::ByteSpan;
|
||||||
|
use binrw::BinRead;
|
||||||
|
use binrw::BinWrite;
|
||||||
|
use binrw::binrw;
|
||||||
|
|
||||||
|
#[binrw]
|
||||||
|
#[derive(Debug)]
|
||||||
|
#[brw(little)]
|
||||||
|
#[brw(magic = b"UWB1")]
|
||||||
|
pub struct Uwb {
|
||||||
|
/// Including this header
|
||||||
|
pub file_size: u32,
|
||||||
|
/// Number of UWC's
|
||||||
|
#[br(temp)]
|
||||||
|
#[bw(calc = uwcs.len() as u32)]
|
||||||
|
uwc_count: u32,
|
||||||
|
#[br(count = uwc_count)]
|
||||||
|
pub uwcs: Vec<Uwc>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[binrw]
|
||||||
|
#[derive(Debug)]
|
||||||
|
#[brw(little)]
|
||||||
|
#[brw(magic = b"UWC1")]
|
||||||
|
pub struct Uwc {
|
||||||
|
/// Including this header
|
||||||
|
pub file_size: u32,
|
||||||
|
// TODO: figure out what this is
|
||||||
|
#[br(count = file_size - 8)]
|
||||||
|
pub unk1: Vec<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Uwb {
|
||||||
|
/// Reads an existing UWB file
|
||||||
|
pub fn from_existing(buffer: ByteSpan) -> Option<Self> {
|
||||||
|
let mut cursor = Cursor::new(buffer);
|
||||||
|
Uwb::read(&mut cursor).ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_to_buffer(&self) -> Option<ByteBuffer> {
|
||||||
|
let mut buffer = ByteBuffer::new();
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut cursor = Cursor::new(&mut buffer);
|
||||||
|
self.write_le(&mut cursor).ok()?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(buffer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use std::fs::read;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_invalid() {
|
||||||
|
let mut d = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||||
|
d.push("resources/tests");
|
||||||
|
d.push("random");
|
||||||
|
|
||||||
|
// Feeding it invalid data should not panic
|
||||||
|
Uwb::from_existing(&read(d).unwrap());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue