From 94823a21e383f49d5ee7e9042121b86faf4c67bb Mon Sep 17 00:00:00 2001 From: modeco80 Date: Wed, 28 Jun 2023 19:27:15 -0400 Subject: [PATCH] chore(*): cargo fmt --- crates/jmmt/src/format/mod.rs | 22 +++++++++++----------- crates/jmmt/src/format/package.rs | 13 ++++++------- crates/jmmt/src/format/ps2_palette.rs | 4 ++-- crates/jmmt/src/hash/crc32.rs | 5 ++--- crates/jmmt/src/hash/filename.rs | 2 +- crates/jmmt/src/lzss/header.rs | 2 +- crates/jmmt/src/lzss/mod.rs | 3 +-- crates/jmmt/src/read/package_toc.rs | 10 ++++------ crates/jmmt/src/read/texture.rs | 2 +- crates/jmmt/src/util/mod.rs | 2 +- crates/jmrenamer/src/main.rs | 27 +++++++++++++++++++-------- crates/textool/src/main.rs | 2 +- 12 files changed, 50 insertions(+), 44 deletions(-) diff --git a/crates/jmmt/src/format/mod.rs b/crates/jmmt/src/format/mod.rs index 3a3de8d..cd59c12 100644 --- a/crates/jmmt/src/format/mod.rs +++ b/crates/jmmt/src/format/mod.rs @@ -3,8 +3,8 @@ pub mod package; pub mod package_toc; -pub mod ps2_texture; pub mod ps2_palette; +pub mod ps2_texture; /// A trait validatable format objects should implement. /// TODO: integrate this with some FourCC crate, or re-invent the wheel. @@ -13,25 +13,25 @@ pub trait Validatable { fn valid(&self) -> bool; } -/// Make a Rust [String] from a byte slice that came from a C string/structure. -/// +/// Make a Rust [String] from a byte slice that came from a C string/structure. +/// /// # Usage -/// +/// /// The byte slice has to be a valid UTF-8 string. /// (Note that in most cases, ASCII strings are valid UTF-8, so this isn't something you'll particularly /// have to worry about). -/// +/// /// # Safety -/// +/// /// This function does not directly make use of any unsafe Rust code. pub fn make_c_string(bytes: &[u8]) -> Option { - let bytes_without_null = match bytes.iter().position(|&b| b == 0) { - Some(ix) => &bytes[..ix], - None => bytes, - }; + let bytes_without_null = match bytes.iter().position(|&b| b == 0) { + Some(ix) => &bytes[..ix], + None => bytes, + }; match std::str::from_utf8(bytes_without_null).ok() { Some(string) => Some(String::from(string)), - None => None + None => None, } } diff --git a/crates/jmmt/src/format/package.rs b/crates/jmmt/src/format/package.rs index 1e4a1f1..a4ae19c 100644 --- a/crates/jmmt/src/format/package.rs +++ b/crates/jmmt/src/format/package.rs @@ -1,7 +1,7 @@ //! Package file format structures -use crate::lzss::header::LzssHeader; use super::Validatable; +use crate::lzss::header::LzssHeader; /// "EOF" header. The QuickBMS script uses this to seek to the PGRP entry. #[repr(C)] @@ -13,7 +13,7 @@ pub struct PackageEofHeader { pub stringtable_size: u32, /// Start offset of the [PackageGroup] in the package file. - pub header_start_offset: u32 + pub header_start_offset: u32, } /// A Package Group. I have no idea what this is yet @@ -29,12 +29,12 @@ pub struct PackageGroup { pub group_file_count: u32, /// Padding. Set to a fill of 0xCD. - pub pad: u32 + pub pad: u32, } impl PackageGroup { /// 'PGRP' - pub const VALID_FOURCC : u32 = 0x50524750; + pub const VALID_FOURCC: u32 = 0x50524750; } impl Validatable for PackageGroup { @@ -87,13 +87,12 @@ pub struct PackageFileChunk { pub file_uncompressed_size: u32, /// LZSS header. Only used if the file chunk is compressed. - pub lzss_header: LzssHeader + pub lzss_header: LzssHeader, } - impl PackageFileChunk { /// 'PFIL' - pub const VALID_FOURCC : u32 = 0x4C494650; + pub const VALID_FOURCC: u32 = 0x4C494650; pub fn is_compressed(&self) -> bool { // If the compressed size matches the uncompressed size diff --git a/crates/jmmt/src/format/ps2_palette.rs b/crates/jmmt/src/format/ps2_palette.rs index b501eae..672ef3f 100644 --- a/crates/jmmt/src/format/ps2_palette.rs +++ b/crates/jmmt/src/format/ps2_palette.rs @@ -17,12 +17,12 @@ pub struct Ps2PaletteHeader { pub data_start: u32, pub header_size: u32, - pub pad: [u32; 6] // reserved for game code, like .ps2_texture? + pub pad: [u32; 6], // reserved for game code, like .ps2_texture? } impl Ps2PaletteHeader { /// 'PAL1' - pub const VALID_FOURCC : u32 = 0x314c4150; + pub const VALID_FOURCC: u32 = 0x314c4150; } impl Validatable for Ps2PaletteHeader { diff --git a/crates/jmmt/src/hash/crc32.rs b/crates/jmmt/src/hash/crc32.rs index bc608ec..43c78a0 100644 --- a/crates/jmmt/src/hash/crc32.rs +++ b/crates/jmmt/src/hash/crc32.rs @@ -65,9 +65,8 @@ impl Crc32Hash { pub fn update_case_insensitive(&self, data: &[u8]) { for b in data.iter() { let old = self.state.take(); - self.state.set( - CRC32_TABLE[((old ^ (*b & !0x20) as u32) & 0xff) as usize] ^ (old >> 8), - ); + self.state + .set(CRC32_TABLE[((old ^ (*b & !0x20) as u32) & 0xff) as usize] ^ (old >> 8)); } } diff --git a/crates/jmmt/src/hash/filename.rs b/crates/jmmt/src/hash/filename.rs index 25b57cf..affb5e1 100644 --- a/crates/jmmt/src/hash/filename.rs +++ b/crates/jmmt/src/hash/filename.rs @@ -1,5 +1,5 @@ //! Utilities for making .DAT and .MET file names -//! +//! //! .DAT and .MET filenames are formatted like "{:X}.DAT" in fmt parlance. //! The name component is the CRC32 of the original filename. //! diff --git a/crates/jmmt/src/lzss/header.rs b/crates/jmmt/src/lzss/header.rs index b494f37..ebe1da3 100644 --- a/crates/jmmt/src/lzss/header.rs +++ b/crates/jmmt/src/lzss/header.rs @@ -1,5 +1,5 @@ -use std::mem::size_of; use crate::format::Validatable; +use std::mem::size_of; #[repr(C)] #[derive(Debug, Default)] diff --git a/crates/jmmt/src/lzss/mod.rs b/crates/jmmt/src/lzss/mod.rs index 3718c01..1405496 100644 --- a/crates/jmmt/src/lzss/mod.rs +++ b/crates/jmmt/src/lzss/mod.rs @@ -1,9 +1,8 @@ //! LZSS -// TODO: +// TODO: // - Port decompression code to Rust // - investigate using `lzss` crate? // - if we can't do that, investigate reimplementing compression based on `lzss` crate? pub mod header; - diff --git a/crates/jmmt/src/read/package_toc.rs b/crates/jmmt/src/read/package_toc.rs index f41acca..f4e8e02 100644 --- a/crates/jmmt/src/read/package_toc.rs +++ b/crates/jmmt/src/read/package_toc.rs @@ -1,10 +1,8 @@ use std::fs::File; use std::io::{Seek, SeekFrom}; -use std::path::{PathBuf}; +use std::path::PathBuf; -use crate::format::{ - package_toc::* -}; +use crate::format::package_toc::*; use binext::BinaryRead; use thiserror::Error; @@ -30,13 +28,13 @@ pub fn read_package_toc(path: PathBuf) -> Result> { let file_size = toc_file.seek(SeekFrom::End(0))?; toc_file.seek(SeekFrom::Start(0))?; - let vec_size : usize = file_size as usize / std::mem::size_of::(); + let vec_size: usize = file_size as usize / std::mem::size_of::(); if vec_size == 0 { return Err(Error::FileTooSmall); } - let mut vec : Vec = Vec::with_capacity(vec_size); + let mut vec: Vec = Vec::with_capacity(vec_size); for _ in 0..vec_size { vec.push(toc_file.read_binary::()?); diff --git a/crates/jmmt/src/read/texture.rs b/crates/jmmt/src/read/texture.rs index e8d8db7..949800e 100644 --- a/crates/jmmt/src/read/texture.rs +++ b/crates/jmmt/src/read/texture.rs @@ -91,7 +91,7 @@ impl Ps2TextureReader { ); } else { // this is a bad error to return here, but for now it works I guess - return Err(Error::InvalidHeader); + return Err(Error::InvalidHeader); } } None => { diff --git a/crates/jmmt/src/util/mod.rs b/crates/jmmt/src/util/mod.rs index fce52c2..e0c52d0 100644 --- a/crates/jmmt/src/util/mod.rs +++ b/crates/jmmt/src/util/mod.rs @@ -27,7 +27,7 @@ impl Ps2Rgba { r: ((value & 0x7C00) >> 7) as u8, g: ((value & 0x03E0) >> 2) as u8, b: ((value & 0x001F) << 3) as u8, - a: 255 + a: 255, }; } } diff --git a/crates/jmrenamer/src/main.rs b/crates/jmrenamer/src/main.rs index a85866d..3329b35 100644 --- a/crates/jmrenamer/src/main.rs +++ b/crates/jmrenamer/src/main.rs @@ -2,9 +2,9 @@ //! This program should be run in the root directory //! of an extracted (from image) copy of the game. -use std::{fs, path::Path}; use jmmt::hash::filename::*; -use jmmt::read::package_toc::{read_package_toc}; +use jmmt::read::package_toc::read_package_toc; +use std::{fs, path::Path}; // TODO: A mode that will re-name everything back? This wouldn't be too hard to implement @@ -21,14 +21,22 @@ fn main() { match read_package_toc(Path::new(package_toc_filename.as_str()).to_path_buf()) { Ok(toc) => { for toc_entry in toc { - let dat_src = format!("DATA/{}", dat_filename_from_hash(toc_entry.file_name_hash())); + let dat_src = format!( + "DATA/{}", + dat_filename_from_hash(toc_entry.file_name_hash()) + ); let src_path = Path::new(dat_src.as_str()); - let dat_clearname = format!("DATA/{}", toc_entry.file_name().expect("How did invalid ASCII get here?")); + let dat_clearname = format!( + "DATA/{}", + toc_entry + .file_name() + .expect("How did invalid ASCII get here?") + ); let dest_path = Path::new(dat_clearname.as_str()); - + if src_path.exists() { match fs::rename(src_path, dest_path) { - Ok(_) => {}, + Ok(_) => {} Err(error) => { println!("Error renaming {}: {}", src_path.display(), error); return (); @@ -38,8 +46,11 @@ fn main() { } } - match fs::rename(Path::new(package_toc_filename.as_str()), Path::new("DATA/package.toc")) { - Ok(_) => {}, + match fs::rename( + Path::new(package_toc_filename.as_str()), + Path::new("DATA/package.toc"), + ) { + Ok(_) => {} Err(error) => { println!("Error renaming TOC file: {}", error); return (); diff --git a/crates/textool/src/main.rs b/crates/textool/src/main.rs index f3b4d0b..534bf22 100644 --- a/crates/textool/src/main.rs +++ b/crates/textool/src/main.rs @@ -1,7 +1,7 @@ use clap::{Parser, Subcommand}; -use std::path::Path; use jmmt::read::texture::Ps2TextureReader; +use std::path::Path; #[derive(Parser)] #[command(author, version, about, long_about = None)]