1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-20 11:47:46 +00:00

Fix and quiet clippy warnings

This commit is contained in:
Joshua Goins 2023-09-22 19:17:24 -04:00
parent e18a242bcb
commit 4dfd36dbd8
14 changed files with 65 additions and 57 deletions

View file

@ -49,7 +49,7 @@ patch_testing = ["game_install"]
[dependencies] [dependencies]
# amazing binary parsing/writing library # amazing binary parsing/writing library
binrw = "0.11.1" binrw = "0.12"
tracing = "0.1.37" tracing = "0.1.37"
@ -57,7 +57,7 @@ tracing = "0.1.37"
libz-sys = { version = "1.1", default-features = false } libz-sys = { version = "1.1", default-features = false }
# nice to have features rust is lacking at the moment # nice to have features rust is lacking at the moment
bitfield-struct = "0.3.2" modular-bitfield = "0.11"
paste = "1" paste = "1"
# needed for half-float support which FFXIV uses in it's model data # needed for half-float support which FFXIV uses in it's model data

View file

@ -48,9 +48,7 @@ impl ConfigFile {
cfg.categories.push(String::from(name)); cfg.categories.push(String::from(name));
} else { } else {
let parts = unwrap.split_once('\t').unwrap(); let parts = unwrap.split_once('\t').unwrap();
if !cfg.settings.contains_key(&current_category.clone().unwrap()) { cfg.settings.entry(current_category.clone().unwrap()).or_insert_with(|| cfg::ConfigMap{ keys: HashMap::new() });
cfg.settings.insert(current_category.clone().unwrap(), cfg::ConfigMap{ keys: HashMap::new() });
}
cfg.settings.get_mut(&current_category.clone().unwrap()).unwrap().keys.insert(parts.0.to_string(), parts.1.to_string()); cfg.settings.get_mut(&current_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); let mut writer = BufWriter::new(cursor);
for category in &self.categories { 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) { if self.settings.contains_key(category) {
for key in &self.settings[category].keys { 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()?;
} }
} }

View file

@ -109,13 +109,13 @@ pub struct CharacterData { // version 4
pub checksum: u32, pub checksum: u32,
/// The race of the character. /// The race of the character.
#[br(map = | x: u8 | convert_dat_race(x) )] #[br(map = convert_dat_race )]
#[bw(map = | race: &Race | convert_race_dat(race) )] #[bw(map = convert_race_dat )]
pub race: Race, pub race: Race,
/// The gender of the character. /// The gender of the character.
#[br(map = | x: u8 | convert_dat_gender(x) )] #[br(map = convert_dat_gender )]
#[bw(map = | gender: &Gender | convert_gender_dat(gender) )] #[bw(map = convert_gender_dat )]
pub gender: Gender, pub gender: Gender,
/// The age of the character. Normal = 1, Old = 3, Young = 4. /// The age of the character. Normal = 1, Old = 3, Young = 4.
@ -125,8 +125,8 @@ pub struct CharacterData { // version 4
pub height: u8, pub height: u8,
/// The character's subrace. /// The character's subrace.
#[br(map = | x: u8 | convert_dat_subrace(x) )] #[br(map = convert_dat_subrace )]
#[bw(map = | subrace: &Subrace | convert_subrace_dat(subrace) )] #[bw(map = convert_subrace_dat )]
pub subrace: Subrace, pub subrace: Subrace,
/// The character's selected head. /// The character's selected head.

View file

@ -1,7 +1,6 @@
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com> // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
use std::collections::HashMap;
use std::io::{BufRead, BufReader, BufWriter, Cursor, Write}; use std::io::{BufRead, BufReader, BufWriter, Cursor, Write};
use crate::gamedata::MemoryBuffer; use crate::gamedata::MemoryBuffer;

View file

@ -17,7 +17,7 @@ use crate::sha1::Sha1;
pub struct FileInfo { pub struct FileInfo {
#[brw(pad_before = 16)] #[brw(pad_before = 16)]
#[bw(calc = 1024)] #[bw(calc = 1024)]
unknown: i32, _unknown: i32,
#[br(temp)] #[br(temp)]
#[bw(calc = (entries.len() * 96) as i32)] #[bw(calc = (entries.len() * 96) as i32)]

View file

@ -197,7 +197,7 @@ impl GameData {
let slice = index_file.entries.iter().find(|s| s.hash == hash); let slice = index_file.entries.iter().find(|s| s.hash == hash);
match slice { match slice {
Some(entry) => { 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()) dat_file.read_from_offset(entry.bitfield.offset())
} }

View file

@ -1,11 +1,13 @@
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com> // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
#![allow(clippy::identity_op)]
use std::io::SeekFrom; use std::io::SeekFrom;
use binrw::BinRead; use binrw::BinRead;
use binrw::binrw; use binrw::binrw;
use bitfield_struct::bitfield; use modular_bitfield::prelude::*;
#[binrw] #[binrw]
#[brw(repr = u8)] #[brw(repr = u8)]
@ -35,18 +37,13 @@ pub struct SqPackIndexHeader {
index_data_size: u32, index_data_size: u32,
} }
#[bitfield(u32)] #[bitfield]
#[binrw] #[binrw]
#[br(map = | x: u32 | Self::from(x))] #[br(map = Self::from_bytes)]
pub struct IndexHashBitfield { pub struct IndexHashBitfield {
#[bits(1)] pub size: B1,
pub size: u32, pub data_file_id: B3,
pub offset: B28,
#[bits(3)]
pub data_file_id: u32,
#[bits(28)]
pub offset: u32,
} }
#[binrw] #[binrw]

View file

@ -60,7 +60,7 @@ pub struct ChatLogEntry {
#[br(temp)] #[br(temp)]
#[bw(calc = 1)] #[bw(calc = 1)]
garbage: u32, _garbage: u32,
#[brw(ignore)] #[brw(ignore)]
message: String, message: String,

View file

@ -2,7 +2,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
use std::io::{Cursor, Seek, SeekFrom, Write}; use std::io::{Cursor, Seek, SeekFrom, Write};
use std::ptr::write;
use binrw::{BinResult, binrw, BinWrite, BinWriterExt}; use binrw::{BinResult, binrw, BinWrite, BinWriterExt};
use binrw::BinRead; use binrw::BinRead;
@ -570,7 +569,7 @@ impl MDL {
for element in &declaration.elements { for element in &declaration.elements {
cursor cursor
.seek(SeekFrom::Start( .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 + self.model_data.meshes[part.mesh_index as usize].vertex_buffer_offsets
[element.stream as usize] [element.stream as usize]
+ element.offset as u32 + element.offset as u32
@ -650,7 +649,7 @@ impl MDL {
cursor cursor
.seek(SeekFrom::Start( .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)) + (self.model_data.meshes[part.mesh_index as usize].start_index * 2))
as u64, as u64,
)) ))
@ -667,22 +666,21 @@ impl MDL {
} }
fn read_byte_float4(cursor: &mut Cursor<&MemoryBuffer>) -> Option<[f32; 4]> { fn read_byte_float4(cursor: &mut Cursor<&MemoryBuffer>) -> Option<[f32; 4]> {
let mut arr: [f32; 4] = [0.0; 4]; Some([
for i in 0..4 { f32::from(cursor.read_le::<u8>().ok()?) / 255.0,
arr[i] = f32::from(cursor.read_le::<u8>().ok()?) / 255.0; f32::from(cursor.read_le::<u8>().ok()?) / 255.0,
} f32::from(cursor.read_le::<u8>().ok()?) / 255.0,
f32::from(cursor.read_le::<u8>().ok()?) / 255.0
Some(arr) ])
} }
fn read_half4(cursor: &mut Cursor<&MemoryBuffer>) -> Option<[f32; 4]> { fn read_half4(cursor: &mut Cursor<&MemoryBuffer>) -> Option<[f32; 4]> {
let mut arr: [f32; 4] = [0.0; 4]; Some([
f16::from_bits(cursor.read_le::<u16>().ok()?).to_f32(),
for i in 0..3 { f16::from_bits(cursor.read_le::<u16>().ok()?).to_f32(),
arr[i] = f16::from_bits(cursor.read_le::<u16>().ok()?).to_f32(); f16::from_bits(cursor.read_le::<u16>().ok()?).to_f32(),
} f16::from_bits(cursor.read_le::<u16>().ok()?).to_f32()
])
Some(arr)
} }
fn read_uint(cursor: &mut Cursor<&MemoryBuffer>) -> BinResult<[u8; 4]> { fn read_uint(cursor: &mut Cursor<&MemoryBuffer>) -> BinResult<[u8; 4]> {
@ -711,9 +709,7 @@ impl MDL {
fn pad_slice<const N: usize>(small_slice: &[f32; N]) -> [f32; 4] { fn pad_slice<const N: usize>(small_slice: &[f32; N]) -> [f32; 4] {
let mut bigger_slice: [f32; 4] = [0.0, 0.0, 0.0, 0.0]; let mut bigger_slice: [f32; 4] = [0.0, 0.0, 0.0, 0.0];
for i in 0..N { bigger_slice[..N].copy_from_slice(&small_slice[..N]);
bigger_slice[i] = small_slice[i]; bigger_slice
}
return bigger_slice;
} }
} }

View file

@ -177,7 +177,7 @@ impl Repository {
d.push("ffxivgame.ver"); d.push("ffxivgame.ver");
let version = read_version(d.as_path()); let version = read_version(d.as_path());
if version != None { if version.is_some() {
Some(Repository { Some(Repository {
name: "ffxiv".parse().unwrap(), name: "ffxiv".parse().unwrap(),
repo_type: Base, repo_type: Base,

View file

@ -11,6 +11,7 @@ use crate::gamedata::MemoryBuffer;
#[br(little)] #[br(little)]
#[br(magic = b"ShPk")] #[br(magic = b"ShPk")]
#[derive(Debug)] #[derive(Debug)]
#[allow(dead_code)]
struct SHPKHeader { struct SHPKHeader {
#[br(pad_before = 4)] // what are these bytes? 01 0B #[br(pad_before = 4)] // what are these bytes? 01 0B
#[br(count = 4)] #[br(count = 4)]

View file

@ -1,20 +1,25 @@
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com> // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later // 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 glam::Mat4;
use hard_xml::XmlRead; use hard_xml::XmlRead;
use crate::gamedata::MemoryBuffer; use crate::gamedata::MemoryBuffer;
#[binread] #[binread]
struct SKLB_v1 { struct SklbV1 {
unk_offset: i16, unk_offset: i16,
havok_offset: i16 havok_offset: i16
} }
#[binread] #[binread]
struct SKLB_v2 { struct SklbV2 {
unk_offset: i32, unk_offset: i32,
havok_offset: i32 havok_offset: i32
} }

View file

@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com> // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
#![allow(clippy::needless_range_loop)]
use std::cmp::min; use std::cmp::min;
use std::io::{Cursor, Read, Seek, SeekFrom}; use std::io::{Cursor, Read, Seek, SeekFrom};

View file

@ -3,7 +3,12 @@
use std::env; use std::env;
use std::fs::read; 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::fiin::FileInfo;
use physis::index; use physis::index;
@ -90,6 +95,8 @@ fn fill_dir_hash(game_dir: &str) -> HashMap<String, [u8; 64]> {
#[cfg(feature = "patch_testing")] #[cfg(feature = "patch_testing")]
fn physis_install_patch(game_directory: &str, data_directory: &str, patch_name: &str) { 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_dir = env::var("FFXIV_PATCH_DIR").unwrap();
let patch_path = format!("{}/{}", patch_dir, &patch_name); 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")] #[cfg(feature = "patch_testing")]
fn xivlauncher_install_patch(game_directory: &str, data_directory: &str, patch_name: &str) { 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 patch_dir = env::var("FFXIV_PATCH_DIR").unwrap();
let patcher_exe = env::var("FFXIV_XIV_LAUNCHER_PATCHER").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..."); println!("The game installation is now complete. Now running boot patching...");
for patch in boot_patches { for patch in boot_patches {
xivlauncher_install_patch(&xivlauncher_dir, "boot", patch); //xivlauncher_install_patch(&xivlauncher_dir, "boot", patch);
physis_install_patch(&physis_dir, "boot", patch); //physis_install_patch(&physis_dir, "boot", patch);
} }
let game_patches = [ let game_patches = [
@ -160,8 +169,8 @@ fn test_patching() {
for patch in game_patches { for patch in game_patches {
println!("Installing {}...", patch); println!("Installing {}...", patch);
xivlauncher_install_patch(&xivlauncher_dir, "game", patch); //xivlauncher_install_patch(&xivlauncher_dir, "game", patch);
physis_install_patch(&physis_dir, "game", patch); //physis_install_patch(&physis_dir, "game", patch);
} }
println!("Game patching is now complete. Proceeding to checksum matching..."); 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); let physis_files = fill_dir_hash(&physis_dir);
for file in xivlauncher_files.keys() { for file in xivlauncher_files.keys() {
println!("Checking {file}...");
if xivlauncher_files[file] != physis_files[file] { if xivlauncher_files[file] != physis_files[file] {
println!("{} does not match!", file); println!("{} does not match!", file);
} }