chore(*): cargo fmt
This commit is contained in:
parent
15d438f294
commit
94823a21e3
|
@ -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.
|
||||
|
@ -32,6 +32,6 @@ pub fn make_c_string(bytes: &[u8]) -> Option<String> {
|
|||
|
||||
match std::str::from_utf8(bytes_without_null).ok() {
|
||||
Some(string) => Some(String::from(string)),
|
||||
None => None
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use std::mem::size_of;
|
||||
use crate::format::Validatable;
|
||||
use std::mem::size_of;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default)]
|
||||
|
|
|
@ -6,4 +6,3 @@
|
|||
// - if we can't do that, investigate reimplementing compression based on `lzss` crate?
|
||||
|
||||
pub mod header;
|
||||
|
||||
|
|
|
@ -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<Vec<PackageTocEntry>> {
|
|||
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::<PackageTocEntry>();
|
||||
let vec_size: usize = file_size as usize / std::mem::size_of::<PackageTocEntry>();
|
||||
|
||||
if vec_size == 0 {
|
||||
return Err(Error::FileTooSmall);
|
||||
}
|
||||
|
||||
let mut vec : Vec<PackageTocEntry> = Vec::with_capacity(vec_size);
|
||||
let mut vec: Vec<PackageTocEntry> = Vec::with_capacity(vec_size);
|
||||
|
||||
for _ in 0..vec_size {
|
||||
vec.push(toc_file.read_binary::<PackageTocEntry>()?);
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 ();
|
||||
|
|
|
@ -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)]
|
||||
|
|
Loading…
Reference in New Issue