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

Reformat code with rustfmt

This commit is contained in:
Joshua Goins 2022-10-20 11:45:55 -04:00
parent ab10cf4975
commit 67d2f035c3
7 changed files with 68 additions and 54 deletions

View file

@ -1,9 +1,9 @@
use crate::gamedata::MemoryBuffer; use crate::gamedata::MemoryBuffer;
use crate::model::ModelFileHeader; use crate::model::ModelFileHeader;
use crate::sqpack::read_data_block; use crate::sqpack::read_data_block;
use binrw::{BinReaderExt, binrw};
use binrw::BinRead; use binrw::BinRead;
use binrw::BinWrite; use binrw::BinWrite;
use binrw::{binrw, BinReaderExt};
use std::io::Write; use std::io::Write;
use std::io::{Cursor, Read, Seek, SeekFrom}; use std::io::{Cursor, Read, Seek, SeekFrom};

View file

@ -1,9 +1,9 @@
use crate::gamedata::MemoryBuffer; use crate::gamedata::MemoryBuffer;
use binrw::{binrw, BinrwNamedArgs, NullString};
use binrw::BinRead; use binrw::BinRead;
use binrw::{binrw, BinrwNamedArgs, NullString};
use std::ffi::CStr;
use std::fs::read; use std::fs::read;
use std::io::Cursor; use std::io::Cursor;
use std::ffi::CStr;
#[binrw] #[binrw]
#[brw(magic = b"FileInfo")] #[brw(magic = b"FileInfo")]
@ -72,9 +72,9 @@ impl FileInfo {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::fiin::FileInfo;
use std::fs::read; use std::fs::read;
use std::path::PathBuf; use std::path::PathBuf;
use crate::fiin::FileInfo;
fn common_setup() -> FileInfo { fn common_setup() -> FileInfo {
let mut d = PathBuf::from(env!("CARGO_MANIFEST_DIR")); let mut d = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
@ -88,11 +88,8 @@ mod tests {
fn basic_parsing() { fn basic_parsing() {
let fiin = common_setup(); let fiin = common_setup();
assert_eq!(fiin.entries[0].file_name, assert_eq!(fiin.entries[0].file_name, "test.txt");
"test.txt");
assert_eq!(fiin.entries[1].file_name, assert_eq!(fiin.entries[1].file_name, "test.exl");
"test.exl");
} }
} }

View file

@ -1,7 +1,7 @@
use crate::gamedata::MemoryBuffer; use crate::gamedata::MemoryBuffer;
use binrw::BinReaderExt;
use binrw::binrw; use binrw::binrw;
use binrw::BinRead; use binrw::BinRead;
use binrw::BinReaderExt;
use half::f16; use half::f16;
use std::io::{Cursor, Seek, SeekFrom}; use std::io::{Cursor, Seek, SeekFrom};
@ -411,10 +411,12 @@ impl MDL {
match element.vertex_usage { match element.vertex_usage {
VertexUsage::Position => { VertexUsage::Position => {
vertices[k as usize].position = cursor.read_le::<[f32; 3]>().ok()?; vertices[k as usize].position =
cursor.read_le::<[f32; 3]>().ok()?;
} }
VertexUsage::BlendWeights => { VertexUsage::BlendWeights => {
vertices[k as usize].bone_weight = cursor.read_le::<[f32; 4]>().ok()?; vertices[k as usize].bone_weight =
cursor.read_le::<[f32; 4]>().ok()?;
} }
VertexUsage::BlendIndices => { VertexUsage::BlendIndices => {
vertices[k as usize].bone_id = cursor.read_le::<[u8; 4]>().ok()?; vertices[k as usize].bone_id = cursor.read_le::<[u8; 4]>().ok()?;
@ -422,12 +424,14 @@ impl MDL {
VertexUsage::Normal => { VertexUsage::Normal => {
// TODO: normals are assumed to be half4 // TODO: normals are assumed to be half4
for i in 0..3 { for i in 0..3 {
vertices[k as usize].normal[i] = f16::from_bits(cursor.read_le::<u16>().ok()?).to_f32(); vertices[k as usize].normal[i] =
f16::from_bits(cursor.read_le::<u16>().ok()?).to_f32();
} }
} }
VertexUsage::UV => { VertexUsage::UV => {
for i in 0..2 { for i in 0..2 {
vertices[k as usize].uv[i] = f16::from_bits(cursor.read_le::<u16>().ok()?).to_f32(); vertices[k as usize].uv[i] =
f16::from_bits(cursor.read_le::<u16>().ok()?).to_f32();
} }
} }
VertexUsage::Tangent2 => {} VertexUsage::Tangent2 => {}

View file

@ -1,5 +1,5 @@
use crate::gamedata::MemoryBuffer; use crate::gamedata::MemoryBuffer;
use binrw::{BinRead, binrw}; use binrw::{binrw, BinRead};
use std::io::Cursor; use std::io::Cursor;
#[binrw] #[binrw]

View file

@ -163,7 +163,7 @@ enum SqpkFileOperation {
#[br(magic = b'D')] #[br(magic = b'D')]
DeleteFile, DeleteFile,
#[br(magic = b'M')] #[br(magic = b'M')]
MakeDirTree MakeDirTree,
} }
#[derive(BinRead, PartialEq, Debug)] #[derive(BinRead, PartialEq, Debug)]
@ -389,9 +389,14 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> {
get_platform_string(&target_info.platform), get_platform_string(&target_info.platform),
file_id file_id
); );
let path: PathBuf = [data_dir, "sqpack", &get_expansion_folder_sub(sub_id), &filename] let path: PathBuf = [
.iter() data_dir,
.collect(); "sqpack",
&get_expansion_folder_sub(sub_id),
&filename,
]
.iter()
.collect();
path.to_str().unwrap().to_string() path.to_str().unwrap().to_string()
}; };
@ -410,9 +415,14 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> {
filename += &*format!("{}", file_id); filename += &*format!("{}", file_id);
} }
let path: PathBuf = [data_dir, "sqpack", &get_expansion_folder_sub(sub_id), &filename] let path: PathBuf = [
.iter() data_dir,
.collect(); "sqpack",
&get_expansion_folder_sub(sub_id),
&filename,
]
.iter()
.collect();
path.to_str().unwrap().to_string() path.to_str().unwrap().to_string()
}; };
@ -531,8 +541,10 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> {
file.seek(SeekFrom::Current(4))?; file.seek(SeekFrom::Current(4))?;
// now apply the file! // now apply the file!
let mut new_file = let mut new_file = OpenOptions::new()
OpenOptions::new().write(true).create(true).open(file_path)?; .write(true)
.create(true)
.open(file_path)?;
if fop.offset == 0 { if fop.offset == 0 {
new_file.set_len(0)?; new_file.set_len(0)?;
@ -545,9 +557,10 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> {
fs::remove_file(file_path.as_str())?; fs::remove_file(file_path.as_str())?;
} }
SqpkFileOperation::RemoveAll => { SqpkFileOperation::RemoveAll => {
let path: PathBuf = [data_dir, "sqpack", &get_expansion_folder(fop.expansion_id)] let path: PathBuf =
.iter() [data_dir, "sqpack", &get_expansion_folder(fop.expansion_id)]
.collect(); .iter()
.collect();
if fs::read_dir(&path).is_ok() { if fs::read_dir(&path).is_ok() {
fs::remove_dir_all(&path)?; fs::remove_dir_all(&path)?;
@ -574,10 +587,10 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> {
} }
ChunkType::AddDirectory(_) => { ChunkType::AddDirectory(_) => {
println!("PATCH: NOP AddDirectory"); println!("PATCH: NOP AddDirectory");
}, }
ChunkType::DeleteDirectory(_) => { ChunkType::DeleteDirectory(_) => {
println!("PATCH: NOP DeleteDirectory"); println!("PATCH: NOP DeleteDirectory");
}, }
ChunkType::EndOfFile => { ChunkType::EndOfFile => {
return Ok(()); return Ok(());
} }

View file

@ -1,5 +1,5 @@
use crate::gamedata::MemoryBuffer; use crate::gamedata::MemoryBuffer;
use binrw::{binrw}; use binrw::binrw;
use binrw::BinRead; use binrw::BinRead;
use bitflags::bitflags; use bitflags::bitflags;
use std::cmp::min; use std::cmp::min;

View file

@ -1,13 +1,13 @@
use std::collections::HashMap; use hmac_sha512::Hash;
use physis::fiin::FileInfo;
use physis::index; use physis::index;
use physis::installer::install_game;
use physis::patch::apply_patch;
use std::collections::HashMap;
use std::env; use std::env;
use std::fs::read; use std::fs::read;
use std::process::Command; use std::process::Command;
use hmac_sha512::Hash;
use physis::installer::install_game;
use physis::patch::apply_patch;
use walkdir::WalkDir; use walkdir::WalkDir;
use physis::fiin::FileInfo;
#[test] #[test]
#[cfg_attr(not(feature = "retail_game_testing"), ignore)] #[cfg_attr(not(feature = "retail_game_testing"), ignore)]
@ -40,10 +40,8 @@ fn test_fiin() {
let fiin_path = format!("{game_dir}/boot/fileinfo.fiin"); let fiin_path = format!("{game_dir}/boot/fileinfo.fiin");
let fiin = FileInfo::from_existing(&read(fiin_path).unwrap()).unwrap(); let fiin = FileInfo::from_existing(&read(fiin_path).unwrap()).unwrap();
assert_eq!(fiin.entries[0].file_name, assert_eq!(fiin.entries[0].file_name, "steam_api.dll");
"steam_api.dll"); assert_eq!(fiin.entries[1].file_name, "steam_api64.dll");
assert_eq!(fiin.entries[1].file_name,
"steam_api64.dll");
} }
fn make_temp_install_dir(name: &str) -> String { fn make_temp_install_dir(name: &str) -> String {
@ -58,13 +56,15 @@ fn make_temp_install_dir(name: &str) -> String {
std::fs::create_dir_all(&game_dir).unwrap(); std::fs::create_dir_all(&game_dir).unwrap();
install_game(&installer_exe, game_dir.as_path().to_str().unwrap()).ok().unwrap(); install_game(&installer_exe, game_dir.as_path().to_str().unwrap())
.ok()
.unwrap();
game_dir.as_path().to_str().unwrap().parse().unwrap() game_dir.as_path().to_str().unwrap().parse().unwrap()
} }
fn fill_dir_hash(game_dir: &str) -> HashMap<String, [u8; 64]> { fn fill_dir_hash(game_dir: &str) -> HashMap<String, [u8; 64]> {
let mut file_hashes : HashMap<String, [u8; 64]> = HashMap::new(); let mut file_hashes: HashMap<String, [u8; 64]> = HashMap::new();
WalkDir::new(game_dir) WalkDir::new(game_dir)
.into_iter() .into_iter()
@ -81,12 +81,12 @@ fn fill_dir_hash(game_dir: &str) -> HashMap<String, [u8; 64]> {
rel_path = rel_path.strip_prefix(game_dir).unwrap(); rel_path = rel_path.strip_prefix(game_dir).unwrap();
file_hashes.insert(rel_path.to_str().unwrap().to_string(), sha); file_hashes.insert(rel_path.to_str().unwrap().to_string(), sha);
}); });
file_hashes file_hashes
} }
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) {
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);
@ -95,7 +95,7 @@ fn physis_install_patch(game_directory: &str, data_directory: &str, patch_name :
apply_patch(&data_dir, &patch_path).unwrap(); apply_patch(&data_dir, &patch_path).unwrap();
} }
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) {
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();
@ -104,10 +104,7 @@ fn xivlauncher_install_patch(game_directory: &str, data_directory: &str, patch_n
// TODO: check for windows systems // TODO: check for windows systems
Command::new("/usr/bin/wine") Command::new("/usr/bin/wine")
.args([&patcher_exe, .args([&patcher_exe, "install", &patch_path, &game_dir])
"install",
&patch_path,
&game_dir])
.output() .output()
.unwrap(); .unwrap();
} }
@ -120,8 +117,10 @@ fn test_patching() {
let physis_dir = make_temp_install_dir("game_test"); let physis_dir = make_temp_install_dir("game_test");
let xivlauncher_dir = make_temp_install_dir("game_test_xivlauncher"); let xivlauncher_dir = make_temp_install_dir("game_test_xivlauncher");
let boot_patches = ["boot/2022.03.25.0000.0001.patch", let boot_patches = [
"boot/2022.08.05.0000.0001.patch"]; "boot/2022.03.25.0000.0001.patch",
"boot/2022.08.05.0000.0001.patch",
];
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 {
@ -129,8 +128,8 @@ fn test_patching() {
physis_install_patch(&physis_dir, "boot", patch); physis_install_patch(&physis_dir, "boot", patch);
} }
let game_patches = let game_patches = [
["game/H2017.06.06.0000.0001a.patch", "game/H2017.06.06.0000.0001a.patch",
"game/H2017.06.06.0000.0001b.patch", "game/H2017.06.06.0000.0001b.patch",
"game/H2017.06.06.0000.0001c.patch", "game/H2017.06.06.0000.0001c.patch",
"game/H2017.06.06.0000.0001d.patch", "game/H2017.06.06.0000.0001d.patch",
@ -149,7 +148,8 @@ fn test_patching() {
"ex1/H2017.06.01.0000.0001a.patch", "ex1/H2017.06.01.0000.0001a.patch",
"ex1/H2017.06.01.0000.0001b.patch", "ex1/H2017.06.01.0000.0001b.patch",
"ex1/H2017.06.01.0000.0001c.patch", "ex1/H2017.06.01.0000.0001c.patch",
"ex1/H2017.06.01.0000.0001d.patch"]; "ex1/H2017.06.01.0000.0001d.patch",
];
println!("Boot patching is now complete. Now running game patching..."); println!("Boot patching is now complete. Now running game patching...");
@ -172,4 +172,4 @@ fn test_patching() {
} }
assert_eq!(physis_files, xivlauncher_files); assert_eq!(physis_files, xivlauncher_files);
} }