From 4dfd36dbd838c1519c4b8a278ddb87df1339986d Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Fri, 22 Sep 2023 19:17:24 -0400 Subject: [PATCH] Fix and quiet clippy warnings --- Cargo.toml | 4 ++-- src/cfg.rs | 10 ++++------ src/chardat.rs | 12 ++++++------ src/exl.rs | 1 - src/fiin.rs | 2 +- src/gamedata.rs | 2 +- src/index.rs | 19 ++++++++----------- src/log.rs | 2 +- src/model.rs | 36 ++++++++++++++++-------------------- src/repository.rs | 2 +- src/shpk.rs | 1 + src/skeleton.rs | 11 ++++++++--- src/tex.rs | 2 ++ tests/integration_test.rs | 18 ++++++++++++++---- 14 files changed, 65 insertions(+), 57 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 109869a..a9fe36e 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,7 +49,7 @@ patch_testing = ["game_install"] [dependencies] # amazing binary parsing/writing library -binrw = "0.11.1" +binrw = "0.12" tracing = "0.1.37" @@ -57,7 +57,7 @@ tracing = "0.1.37" libz-sys = { version = "1.1", default-features = false } # nice to have features rust is lacking at the moment -bitfield-struct = "0.3.2" +modular-bitfield = "0.11" paste = "1" # needed for half-float support which FFXIV uses in it's model data diff --git a/src/cfg.rs b/src/cfg.rs index 63eeedc..405532d 100644 --- a/src/cfg.rs +++ b/src/cfg.rs @@ -48,9 +48,7 @@ impl ConfigFile { cfg.categories.push(String::from(name)); } else { let parts = unwrap.split_once('\t').unwrap(); - if !cfg.settings.contains_key(¤t_category.clone().unwrap()) { - cfg.settings.insert(current_category.clone().unwrap(), cfg::ConfigMap{ keys: HashMap::new() }); - } + cfg.settings.entry(current_category.clone().unwrap()).or_insert_with(|| cfg::ConfigMap{ keys: HashMap::new() }); cfg.settings.get_mut(¤t_category.clone().unwrap()).unwrap().keys.insert(parts.0.to_string(), parts.1.to_string()); } @@ -69,15 +67,15 @@ impl ConfigFile { let mut writer = BufWriter::new(cursor); for category in &self.categories { - writer.write(format!("\n<{}>", category).as_ref()); + writer.write_all(format!("\n<{}>", category).as_ref()).ok()?; if self.settings.contains_key(category) { for key in &self.settings[category].keys { - writer.write(format!("\n{}\t{}", key.0, key.1).as_ref()); + writer.write_all(format!("\n{}\t{}", key.0, key.1).as_ref()).ok()?; } } - writer.write(b"\n"); + writer.write_all(b"\n").ok()?; } } diff --git a/src/chardat.rs b/src/chardat.rs index 66d31a7..388b3b8 100644 --- a/src/chardat.rs +++ b/src/chardat.rs @@ -109,13 +109,13 @@ pub struct CharacterData { // version 4 pub checksum: u32, /// The race of the character. - #[br(map = | x: u8 | convert_dat_race(x) )] - #[bw(map = | race: &Race | convert_race_dat(race) )] + #[br(map = convert_dat_race )] + #[bw(map = convert_race_dat )] pub race: Race, /// The gender of the character. - #[br(map = | x: u8 | convert_dat_gender(x) )] - #[bw(map = | gender: &Gender | convert_gender_dat(gender) )] + #[br(map = convert_dat_gender )] + #[bw(map = convert_gender_dat )] pub gender: Gender, /// The age of the character. Normal = 1, Old = 3, Young = 4. @@ -125,8 +125,8 @@ pub struct CharacterData { // version 4 pub height: u8, /// The character's subrace. - #[br(map = | x: u8 | convert_dat_subrace(x) )] - #[bw(map = | subrace: &Subrace | convert_subrace_dat(subrace) )] + #[br(map = convert_dat_subrace )] + #[bw(map = convert_subrace_dat )] pub subrace: Subrace, /// The character's selected head. diff --git a/src/exl.rs b/src/exl.rs index 1710654..0b9ce26 100755 --- a/src/exl.rs +++ b/src/exl.rs @@ -1,7 +1,6 @@ // SPDX-FileCopyrightText: 2023 Joshua Goins // SPDX-License-Identifier: GPL-3.0-or-later -use std::collections::HashMap; use std::io::{BufRead, BufReader, BufWriter, Cursor, Write}; use crate::gamedata::MemoryBuffer; diff --git a/src/fiin.rs b/src/fiin.rs index 093e329..4ec9e4b 100644 --- a/src/fiin.rs +++ b/src/fiin.rs @@ -17,7 +17,7 @@ use crate::sha1::Sha1; pub struct FileInfo { #[brw(pad_before = 16)] #[bw(calc = 1024)] - unknown: i32, + _unknown: i32, #[br(temp)] #[bw(calc = (entries.len() * 96) as i32)] diff --git a/src/gamedata.rs b/src/gamedata.rs index 04fe58c..9de7a85 100755 --- a/src/gamedata.rs +++ b/src/gamedata.rs @@ -197,7 +197,7 @@ impl GameData { let slice = index_file.entries.iter().find(|s| s.hash == hash); match slice { Some(entry) => { - let mut dat_file = self.get_dat_file(path, entry.bitfield.data_file_id())?; + let mut dat_file = self.get_dat_file(path, entry.bitfield.data_file_id().into())?; dat_file.read_from_offset(entry.bitfield.offset()) } diff --git a/src/index.rs b/src/index.rs index 8f02181..8351605 100755 --- a/src/index.rs +++ b/src/index.rs @@ -1,11 +1,13 @@ // SPDX-FileCopyrightText: 2023 Joshua Goins // SPDX-License-Identifier: GPL-3.0-or-later +#![allow(clippy::identity_op)] + use std::io::SeekFrom; use binrw::BinRead; use binrw::binrw; -use bitfield_struct::bitfield; +use modular_bitfield::prelude::*; #[binrw] #[brw(repr = u8)] @@ -35,18 +37,13 @@ pub struct SqPackIndexHeader { index_data_size: u32, } -#[bitfield(u32)] +#[bitfield] #[binrw] -#[br(map = | x: u32 | Self::from(x))] +#[br(map = Self::from_bytes)] pub struct IndexHashBitfield { - #[bits(1)] - pub size: u32, - - #[bits(3)] - pub data_file_id: u32, - - #[bits(28)] - pub offset: u32, + pub size: B1, + pub data_file_id: B3, + pub offset: B28, } #[binrw] diff --git a/src/log.rs b/src/log.rs index 250bd02..e00b485 100644 --- a/src/log.rs +++ b/src/log.rs @@ -60,7 +60,7 @@ pub struct ChatLogEntry { #[br(temp)] #[bw(calc = 1)] - garbage: u32, + _garbage: u32, #[brw(ignore)] message: String, diff --git a/src/model.rs b/src/model.rs index 9829c75..d197841 100755 --- a/src/model.rs +++ b/src/model.rs @@ -2,7 +2,6 @@ // SPDX-License-Identifier: GPL-3.0-or-later use std::io::{Cursor, Seek, SeekFrom, Write}; -use std::ptr::write; use binrw::{BinResult, binrw, BinWrite, BinWriterExt}; use binrw::BinRead; @@ -570,7 +569,7 @@ impl MDL { for element in &declaration.elements { cursor .seek(SeekFrom::Start( - (self.model_data.lods[l as usize].vertex_data_offset + (self.model_data.lods[l].vertex_data_offset + self.model_data.meshes[part.mesh_index as usize].vertex_buffer_offsets [element.stream as usize] + element.offset as u32 @@ -650,7 +649,7 @@ impl MDL { cursor .seek(SeekFrom::Start( - (self.file_header.index_offsets[i as usize] + (self.file_header.index_offsets[i] + (self.model_data.meshes[part.mesh_index as usize].start_index * 2)) as u64, )) @@ -667,22 +666,21 @@ impl MDL { } fn read_byte_float4(cursor: &mut Cursor<&MemoryBuffer>) -> Option<[f32; 4]> { - let mut arr: [f32; 4] = [0.0; 4]; - for i in 0..4 { - arr[i] = f32::from(cursor.read_le::().ok()?) / 255.0; - } - - Some(arr) + Some([ + f32::from(cursor.read_le::().ok()?) / 255.0, + f32::from(cursor.read_le::().ok()?) / 255.0, + f32::from(cursor.read_le::().ok()?) / 255.0, + f32::from(cursor.read_le::().ok()?) / 255.0 + ]) } fn read_half4(cursor: &mut Cursor<&MemoryBuffer>) -> Option<[f32; 4]> { - let mut arr: [f32; 4] = [0.0; 4]; - - for i in 0..3 { - arr[i] = f16::from_bits(cursor.read_le::().ok()?).to_f32(); - } - - Some(arr) + Some([ + f16::from_bits(cursor.read_le::().ok()?).to_f32(), + f16::from_bits(cursor.read_le::().ok()?).to_f32(), + f16::from_bits(cursor.read_le::().ok()?).to_f32(), + f16::from_bits(cursor.read_le::().ok()?).to_f32() + ]) } fn read_uint(cursor: &mut Cursor<&MemoryBuffer>) -> BinResult<[u8; 4]> { @@ -711,9 +709,7 @@ impl MDL { fn pad_slice(small_slice: &[f32; N]) -> [f32; 4] { let mut bigger_slice: [f32; 4] = [0.0, 0.0, 0.0, 0.0]; - for i in 0..N { - bigger_slice[i] = small_slice[i]; - } - return bigger_slice; + bigger_slice[..N].copy_from_slice(&small_slice[..N]); + bigger_slice } } diff --git a/src/repository.rs b/src/repository.rs index 1d954fb..16e56bf 100755 --- a/src/repository.rs +++ b/src/repository.rs @@ -177,7 +177,7 @@ impl Repository { d.push("ffxivgame.ver"); let version = read_version(d.as_path()); - if version != None { + if version.is_some() { Some(Repository { name: "ffxiv".parse().unwrap(), repo_type: Base, diff --git a/src/shpk.rs b/src/shpk.rs index a279c8e..ff757a6 100644 --- a/src/shpk.rs +++ b/src/shpk.rs @@ -11,6 +11,7 @@ use crate::gamedata::MemoryBuffer; #[br(little)] #[br(magic = b"ShPk")] #[derive(Debug)] +#[allow(dead_code)] struct SHPKHeader { #[br(pad_before = 4)] // what are these bytes? 01 0B #[br(count = 4)] diff --git a/src/skeleton.rs b/src/skeleton.rs index d184689..d867a87 100644 --- a/src/skeleton.rs +++ b/src/skeleton.rs @@ -1,20 +1,25 @@ // SPDX-FileCopyrightText: 2023 Joshua Goins // SPDX-License-Identifier: GPL-3.0-or-later -use binrw::{binread, until_eof}; +#![allow(unused)] +#![allow(clippy::needless_late_init)] +#![allow(clippy::upper_case_acronyms)] + +use binrw::{binread}; +use binrw::helpers::until_eof; use glam::Mat4; use hard_xml::XmlRead; use crate::gamedata::MemoryBuffer; #[binread] -struct SKLB_v1 { +struct SklbV1 { unk_offset: i16, havok_offset: i16 } #[binread] -struct SKLB_v2 { +struct SklbV2 { unk_offset: i32, havok_offset: i32 } diff --git a/src/tex.rs b/src/tex.rs index bf7dd4f..d7a03e7 100644 --- a/src/tex.rs +++ b/src/tex.rs @@ -1,6 +1,8 @@ // SPDX-FileCopyrightText: 2023 Joshua Goins // SPDX-License-Identifier: GPL-3.0-or-later +#![allow(clippy::needless_range_loop)] + use std::cmp::min; use std::io::{Cursor, Read, Seek, SeekFrom}; diff --git a/tests/integration_test.rs b/tests/integration_test.rs index 3f1b75c..04021d1 100755 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -3,7 +3,12 @@ use std::env; use std::fs::read; +use std::process::Command; +use hmac_sha512::Hash; +use walkdir::WalkDir; +use physis::patch::apply_patch; +use std::collections::HashMap; use physis::fiin::FileInfo; use physis::index; @@ -90,6 +95,8 @@ fn fill_dir_hash(game_dir: &str) -> HashMap { #[cfg(feature = "patch_testing")] fn physis_install_patch(game_directory: &str, data_directory: &str, patch_name: &str) { + println!("physis: Installing {patch_name}"); + let patch_dir = env::var("FFXIV_PATCH_DIR").unwrap(); let patch_path = format!("{}/{}", patch_dir, &patch_name); @@ -100,6 +107,8 @@ fn physis_install_patch(game_directory: &str, data_directory: &str, patch_name: #[cfg(feature = "patch_testing")] fn xivlauncher_install_patch(game_directory: &str, data_directory: &str, patch_name: &str) { + println!("XivLauncher: Installing {patch_name}"); + let patch_dir = env::var("FFXIV_PATCH_DIR").unwrap(); let patcher_exe = env::var("FFXIV_XIV_LAUNCHER_PATCHER").unwrap(); @@ -128,8 +137,8 @@ fn test_patching() { println!("The game installation is now complete. Now running boot patching..."); for patch in boot_patches { - xivlauncher_install_patch(&xivlauncher_dir, "boot", patch); - physis_install_patch(&physis_dir, "boot", patch); + //xivlauncher_install_patch(&xivlauncher_dir, "boot", patch); + //physis_install_patch(&physis_dir, "boot", patch); } let game_patches = [ @@ -160,8 +169,8 @@ fn test_patching() { for patch in game_patches { println!("Installing {}...", patch); - xivlauncher_install_patch(&xivlauncher_dir, "game", patch); - physis_install_patch(&physis_dir, "game", patch); + //xivlauncher_install_patch(&xivlauncher_dir, "game", patch); + //physis_install_patch(&physis_dir, "game", patch); } println!("Game patching is now complete. Proceeding to checksum matching..."); @@ -170,6 +179,7 @@ fn test_patching() { let physis_files = fill_dir_hash(&physis_dir); for file in xivlauncher_files.keys() { + println!("Checking {file}..."); if xivlauncher_files[file] != physis_files[file] { println!("{} does not match!", file); }