mirror of
https://github.com/redstrate/Physis.git
synced 2025-04-20 03:37:47 +00:00
Fix and quiet clippy warnings
This commit is contained in:
parent
e18a242bcb
commit
4dfd36dbd8
14 changed files with 65 additions and 57 deletions
|
@ -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
|
||||
|
|
10
src/cfg.rs
10
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()?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::io::{BufRead, BufReader, BufWriter, Cursor, Write};
|
||||
|
||||
use crate::gamedata::MemoryBuffer;
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
|
19
src/index.rs
19
src/index.rs
|
@ -1,11 +1,13 @@
|
|||
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
||||
// 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]
|
||||
|
|
|
@ -60,7 +60,7 @@ pub struct ChatLogEntry {
|
|||
|
||||
#[br(temp)]
|
||||
#[bw(calc = 1)]
|
||||
garbage: u32,
|
||||
_garbage: u32,
|
||||
|
||||
#[brw(ignore)]
|
||||
message: String,
|
||||
|
|
36
src/model.rs
36
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::<u8>().ok()?) / 255.0;
|
||||
}
|
||||
|
||||
Some(arr)
|
||||
Some([
|
||||
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
|
||||
])
|
||||
}
|
||||
|
||||
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::<u16>().ok()?).to_f32();
|
||||
}
|
||||
|
||||
Some(arr)
|
||||
Some([
|
||||
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(),
|
||||
f16::from_bits(cursor.read_le::<u16>().ok()?).to_f32()
|
||||
])
|
||||
}
|
||||
|
||||
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] {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -1,20 +1,25 @@
|
|||
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
||||
// 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
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#![allow(clippy::needless_range_loop)]
|
||||
|
||||
use std::cmp::min;
|
||||
use std::io::{Cursor, Read, Seek, SeekFrom};
|
||||
|
||||
|
|
|
@ -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<String, [u8; 64]> {
|
|||
|
||||
#[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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue