mirror of
https://github.com/redstrate/Physis.git
synced 2025-04-22 20:57:46 +00:00
Fix Clippy warnings and errors
This commit is contained in:
parent
75f88ba3b6
commit
c7184cb36f
11 changed files with 48 additions and 53 deletions
|
@ -23,9 +23,9 @@ fn fetch_data() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn criterion_benchmark(c: &mut Criterion) {
|
fn criterion_benchmark(c: &mut Criterion) {
|
||||||
c.bench_function("hash calc", |b| b.iter(|| bench_calculate_hash()));
|
c.bench_function("hash calc", |b| b.iter(bench_calculate_hash));
|
||||||
c.bench_function("gamedata reloading repositories", |b| b.iter(|| reload_repos()));
|
c.bench_function("gamedata reloading repositories", |b| b.iter(reload_repos));
|
||||||
c.bench_function("gamedata extract", |b| b.iter(|| fetch_data()));
|
c.bench_function("gamedata extract", |b| b.iter(fetch_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
criterion_group!(benches, criterion_benchmark);
|
criterion_group!(benches, criterion_benchmark);
|
||||||
|
|
|
@ -71,8 +71,8 @@ impl Blowfish {
|
||||||
|
|
||||||
let (l, r) = self.encrypt_pair(u32::from_le_bytes(l_bytes), u32::from_le_bytes(r_bytes));
|
let (l, r) = self.encrypt_pair(u32::from_le_bytes(l_bytes), u32::from_le_bytes(r_bytes));
|
||||||
|
|
||||||
cursor.write(u32::to_le_bytes(l).as_slice()).ok()?;
|
cursor.write_all(u32::to_le_bytes(l).as_slice()).ok()?;
|
||||||
cursor.write(u32::to_le_bytes(r).as_slice()).ok()?;
|
cursor.write_all(u32::to_le_bytes(r).as_slice()).ok()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(cursor.into_inner())
|
Some(cursor.into_inner())
|
||||||
|
@ -84,8 +84,7 @@ impl Blowfish {
|
||||||
padded_length = data.len() + (8 - (data.len() % 8));
|
padded_length = data.len() + (8 - (data.len() % 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut vec = Vec::with_capacity(padded_length);
|
let mut vec = vec![0; padded_length];
|
||||||
vec.resize(padded_length, 0);
|
|
||||||
vec[..data.len()].clone_from_slice(data);
|
vec[..data.len()].clone_from_slice(data);
|
||||||
|
|
||||||
vec
|
vec
|
||||||
|
@ -105,8 +104,8 @@ impl Blowfish {
|
||||||
|
|
||||||
let (l, r) = self.decrypt_pair(u32::from_le_bytes(l_bytes), u32::from_le_bytes(r_bytes));
|
let (l, r) = self.decrypt_pair(u32::from_le_bytes(l_bytes), u32::from_le_bytes(r_bytes));
|
||||||
|
|
||||||
cursor.write(u32::to_le_bytes(l).as_slice()).ok()?;
|
cursor.write_all(u32::to_le_bytes(l).as_slice()).ok()?;
|
||||||
cursor.write(u32::to_le_bytes(r).as_slice()).ok()?;
|
cursor.write_all(u32::to_le_bytes(r).as_slice()).ok()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(buffer)
|
Some(buffer)
|
||||||
|
@ -130,7 +129,7 @@ impl Blowfish {
|
||||||
l ^= self.f(r);
|
l ^= self.f(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (r ^ self.p[17], l ^ self.p[16]);
|
(r ^ self.p[17], l ^ self.p[16])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decrypt_pair(&self, mut l: u32, mut r: u32) -> (u32, u32) {
|
fn decrypt_pair(&self, mut l: u32, mut r: u32) -> (u32, u32) {
|
||||||
|
@ -141,6 +140,6 @@ impl Blowfish {
|
||||||
l ^= self.f(r);
|
l ^= self.f(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (r ^ self.p[0], l ^ self.p[1]);
|
(r ^ self.p[0], l ^ self.p[1])
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -252,7 +252,7 @@ impl DatFile {
|
||||||
let data = read_data_block(&self.file, *last_pos)
|
let data = read_data_block(&self.file, *last_pos)
|
||||||
.expect("Unable to read block data.");
|
.expect("Unable to read block data.");
|
||||||
// write to buffer
|
// write to buffer
|
||||||
buffer.write(data.as_slice()).ok()?;
|
buffer.write_all(data.as_slice()).ok()?;
|
||||||
|
|
||||||
self.file.seek(SeekFrom::Start(last_pos + (compressed_block_sizes[current_block as usize] as u64))).ok()?;
|
self.file.seek(SeekFrom::Start(last_pos + (compressed_block_sizes[current_block as usize] as u64))).ok()?;
|
||||||
current_block += 1;
|
current_block += 1;
|
||||||
|
@ -281,7 +281,7 @@ impl DatFile {
|
||||||
let data = read_data_block(&self.file, last_pos)
|
let data = read_data_block(&self.file, last_pos)
|
||||||
.expect("Unable to read raw model block!");
|
.expect("Unable to read raw model block!");
|
||||||
|
|
||||||
buffer.write(data.as_slice()).expect("Unable to write to memory buffer!");
|
buffer.write_all(data.as_slice()).expect("Unable to write to memory buffer!");
|
||||||
|
|
||||||
data_sizes[i] += data.len() as u32;
|
data_sizes[i] += data.len() as u32;
|
||||||
self.file.seek(SeekFrom::Start(last_pos + (compressed_block_sizes[current_block] as u64)))
|
self.file.seek(SeekFrom::Start(last_pos + (compressed_block_sizes[current_block] as u64)))
|
||||||
|
|
|
@ -74,7 +74,7 @@ impl EXD {
|
||||||
(bool_data & bit) == bit
|
(bool_data & bit) == bit
|
||||||
};
|
};
|
||||||
|
|
||||||
return match column.data_type {
|
match column.data_type {
|
||||||
ColumnDataType::String => {
|
ColumnDataType::String => {
|
||||||
let string_offset : u32 = Self::read_data_raw(cursor).unwrap();
|
let string_offset : u32 = Self::read_data_raw(cursor).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,6 @@ pub struct EXH {
|
||||||
|
|
||||||
impl EXH {
|
impl EXH {
|
||||||
pub fn from_existing(buffer : &MemoryBuffer) -> Option<EXH> {
|
pub fn from_existing(buffer : &MemoryBuffer) -> Option<EXH> {
|
||||||
Some(EXH::read(&mut Cursor::new(&buffer)).ok()?)
|
EXH::read(&mut Cursor::new(&buffer)).ok()
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -43,7 +43,7 @@ impl FileInfo {
|
||||||
/// Parses an existing FIIN file.
|
/// Parses an existing FIIN file.
|
||||||
pub fn from_existing(buffer : &MemoryBuffer) -> Option<FileInfo> {
|
pub fn from_existing(buffer : &MemoryBuffer) -> Option<FileInfo> {
|
||||||
let mut cursor = Cursor::new(buffer);
|
let mut cursor = Cursor::new(buffer);
|
||||||
Some(FileInfo::read(&mut cursor).ok()?)
|
FileInfo::read(&mut cursor).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new FileInfo structure from a list of filenames. These filenames must be present in
|
/// Creates a new FileInfo structure from a list of filenames. These filenames must be present in
|
||||||
|
|
|
@ -206,7 +206,7 @@ impl GameData {
|
||||||
|
|
||||||
let exd_file = self.extract(&exd_path).unwrap();
|
let exd_file = self.extract(&exd_path).unwrap();
|
||||||
|
|
||||||
EXD::from_existing(&exh, &exd_file)
|
EXD::from_existing(exh, &exd_file)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_patch(&self, patch_path : &str) -> Result<(), PatchError> {
|
pub fn apply_patch(&self, patch_path : &str) -> Result<(), PatchError> {
|
||||||
|
|
|
@ -83,9 +83,9 @@ pub fn install_game(installer_path : &str, game_directory : &str) -> Result<(),
|
||||||
let mut new_file = File::create(last_filename).unwrap();
|
let mut new_file = File::create(last_filename).unwrap();
|
||||||
|
|
||||||
if last_filename == "data1.hdr" {
|
if last_filename == "data1.hdr" {
|
||||||
new_file.write(&installer_file[last_position + 30..position - 42])?;
|
new_file.write_all(&installer_file[last_position + 30..position - 42])?;
|
||||||
} else {
|
} else {
|
||||||
new_file.write(&installer_file[last_position + 33..position - 42])?;
|
new_file.write_all(&installer_file[last_position + 33..position - 42])?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ pub fn install_game(installer_path : &str, game_directory : &str) -> Result<(),
|
||||||
|
|
||||||
let mut new_file = File::create(last_filename).unwrap();
|
let mut new_file = File::create(last_filename).unwrap();
|
||||||
|
|
||||||
new_file.write(&installer_file[last_position + 33..installer_file.len() - 42])?;
|
new_file.write_all(&installer_file[last_position + 33..installer_file.len() - 42])?;
|
||||||
|
|
||||||
fs::create_dir_all(format!("{game_directory}/boot"))?;
|
fs::create_dir_all(format!("{game_directory}/boot"))?;
|
||||||
fs::create_dir_all(format!("{game_directory}/game"))?;
|
fs::create_dir_all(format!("{game_directory}/game"))?;
|
||||||
|
|
38
src/patch.rs
38
src/patch.rs
|
@ -295,7 +295,7 @@ fn wipe(mut file : &File, length : i32) -> Result<(), PatchError> {
|
||||||
let mut length = length;
|
let mut length = length;
|
||||||
while length > 0 {
|
while length > 0 {
|
||||||
let num_bytes = min(WIPE_BUFFER.len() as i32, length);
|
let num_bytes = min(WIPE_BUFFER.len() as i32, length);
|
||||||
file.write(&WIPE_BUFFER[0..num_bytes as usize])?;
|
file.write_all(&WIPE_BUFFER[0..num_bytes as usize])?;
|
||||||
length -= num_bytes;
|
length -= num_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,19 +313,19 @@ fn write_empty_file_block_at(mut file : &File, offset : i32, block_number : i32)
|
||||||
file.seek(SeekFrom::Start(offset as u64))?;
|
file.seek(SeekFrom::Start(offset as u64))?;
|
||||||
|
|
||||||
let block_size : i32 = 1 << 7;
|
let block_size : i32 = 1 << 7;
|
||||||
file.write(block_size.to_le_bytes().as_slice())?;
|
file.write_all(block_size.to_le_bytes().as_slice())?;
|
||||||
|
|
||||||
let unknown : i32 = 0;
|
let unknown : i32 = 0;
|
||||||
file.write(unknown.to_le_bytes().as_slice())?;
|
file.write_all(unknown.to_le_bytes().as_slice())?;
|
||||||
|
|
||||||
let file_size : i32 = 0;
|
let file_size : i32 = 0;
|
||||||
file.write(file_size.to_le_bytes().as_slice())?;
|
file.write_all(file_size.to_le_bytes().as_slice())?;
|
||||||
|
|
||||||
let num_blocks : i32 = block_number - 1;
|
let num_blocks : i32 = block_number - 1;
|
||||||
file.write(num_blocks.to_le_bytes().as_slice())?;
|
file.write_all(num_blocks.to_le_bytes().as_slice())?;
|
||||||
|
|
||||||
let used_blocks : i32 = 0;
|
let used_blocks : i32 = 0;
|
||||||
file.write(used_blocks.to_le_bytes().as_slice())?;
|
file.write_all(used_blocks.to_le_bytes().as_slice())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -392,7 +392,7 @@ pub(crate) fn apply_patch(data_dir : &str, patch_path : &str) -> Result<(), Patc
|
||||||
ChunkType::Sqpk(pchunk) => {
|
ChunkType::Sqpk(pchunk) => {
|
||||||
match pchunk.operation {
|
match pchunk.operation {
|
||||||
SqpkOperation::AddData(add) => {
|
SqpkOperation::AddData(add) => {
|
||||||
let filename = get_dat_path(&target_info.as_ref().unwrap(), add.main_id, add.sub_id, add.file_id);
|
let filename = get_dat_path(target_info.as_ref().unwrap(), add.main_id, add.sub_id, add.file_id);
|
||||||
|
|
||||||
let (left, _) = filename.rsplit_once('/').unwrap();
|
let (left, _) = filename.rsplit_once('/').unwrap();
|
||||||
fs::create_dir_all(left)?;
|
fs::create_dir_all(left)?;
|
||||||
|
@ -404,37 +404,37 @@ pub(crate) fn apply_patch(data_dir : &str, patch_path : &str) -> Result<(), Patc
|
||||||
|
|
||||||
new_file.seek(SeekFrom::Start(add.block_offset as u64))?;
|
new_file.seek(SeekFrom::Start(add.block_offset as u64))?;
|
||||||
|
|
||||||
new_file.write(&*add.block_data)?;
|
new_file.write_all(&*add.block_data)?;
|
||||||
|
|
||||||
wipe(&mut new_file, add.block_delete_number)?;
|
wipe(&new_file, add.block_delete_number)?;
|
||||||
}
|
}
|
||||||
SqpkOperation::DeleteData(delete) => {
|
SqpkOperation::DeleteData(delete) => {
|
||||||
let filename = get_dat_path(&target_info.as_ref().unwrap(), delete.main_id, delete.sub_id, delete.file_id);
|
let filename = get_dat_path(target_info.as_ref().unwrap(), delete.main_id, delete.sub_id, delete.file_id);
|
||||||
|
|
||||||
let mut new_file = OpenOptions::new()
|
let new_file = OpenOptions::new()
|
||||||
.write(true)
|
.write(true)
|
||||||
.create(true)
|
.create(true)
|
||||||
.open(filename)?;
|
.open(filename)?;
|
||||||
|
|
||||||
write_empty_file_block_at(&mut new_file, delete.block_offset, delete.block_number)?;
|
write_empty_file_block_at(&new_file, delete.block_offset, delete.block_number)?;
|
||||||
}
|
}
|
||||||
SqpkOperation::ExpandData(expand) => {
|
SqpkOperation::ExpandData(expand) => {
|
||||||
let filename = get_dat_path(&target_info.as_ref().unwrap(), expand.main_id, expand.sub_id, expand.file_id);
|
let filename = get_dat_path(target_info.as_ref().unwrap(), expand.main_id, expand.sub_id, expand.file_id);
|
||||||
|
|
||||||
let (left, _) = filename.rsplit_once('/').unwrap();
|
let (left, _) = filename.rsplit_once('/').unwrap();
|
||||||
fs::create_dir_all(left)?;
|
fs::create_dir_all(left)?;
|
||||||
|
|
||||||
let mut new_file = OpenOptions::new()
|
let new_file = OpenOptions::new()
|
||||||
.write(true)
|
.write(true)
|
||||||
.create(true)
|
.create(true)
|
||||||
.open(filename)?;
|
.open(filename)?;
|
||||||
|
|
||||||
write_empty_file_block_at(&mut new_file, expand.block_offset, expand.block_number)?;
|
write_empty_file_block_at(&new_file, expand.block_offset, expand.block_number)?;
|
||||||
}
|
}
|
||||||
SqpkOperation::HeaderUpdate(header) => {
|
SqpkOperation::HeaderUpdate(header) => {
|
||||||
let file_path = match header.file_kind {
|
let file_path = match header.file_kind {
|
||||||
TargetFileKind::Dat => get_dat_path(&target_info.as_ref().unwrap(), header.main_id, header.sub_id, header.file_id),
|
TargetFileKind::Dat => get_dat_path(target_info.as_ref().unwrap(), header.main_id, header.sub_id, header.file_id),
|
||||||
TargetFileKind::Index => get_index_path(&target_info.as_ref().unwrap(), header.main_id, header.sub_id, header.file_id)
|
TargetFileKind::Index => get_index_path(target_info.as_ref().unwrap(), header.main_id, header.sub_id, header.file_id)
|
||||||
};
|
};
|
||||||
|
|
||||||
let (left, _) = file_path.rsplit_once('/')
|
let (left, _) = file_path.rsplit_once('/')
|
||||||
|
@ -450,7 +450,7 @@ pub(crate) fn apply_patch(data_dir : &str, patch_path : &str) -> Result<(), Patc
|
||||||
new_file.seek(SeekFrom::Start(1024))?;
|
new_file.seek(SeekFrom::Start(1024))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_file.write(&*header.header_data)?;
|
new_file.write_all(&*header.header_data)?;
|
||||||
}
|
}
|
||||||
SqpkOperation::FileOperation(fop) => {
|
SqpkOperation::FileOperation(fop) => {
|
||||||
match fop.operation {
|
match fop.operation {
|
||||||
|
@ -480,7 +480,7 @@ pub(crate) fn apply_patch(data_dir : &str, patch_path : &str) -> Result<(), Patc
|
||||||
.open(new_path)?;
|
.open(new_path)?;
|
||||||
|
|
||||||
new_file.seek(SeekFrom::Start(fop.offset as u64))?;
|
new_file.seek(SeekFrom::Start(fop.offset as u64))?;
|
||||||
new_file.write(&mut data)?;
|
new_file.write_all(&data)?;
|
||||||
}
|
}
|
||||||
SqpkFileOperation::DeleteFile => {
|
SqpkFileOperation::DeleteFile => {
|
||||||
let new_path = data_dir.to_owned() + "/" + &fop.path;
|
let new_path = data_dir.to_owned() + "/" + &fop.path;
|
||||||
|
|
|
@ -133,31 +133,27 @@ impl Repository {
|
||||||
|
|
||||||
let name = String::from(path.file_stem().unwrap().to_str().unwrap());
|
let name = String::from(path.file_stem().unwrap().to_str().unwrap());
|
||||||
|
|
||||||
let repo_type: RepositoryType;
|
let repo_type = if name == "ffxiv" {
|
||||||
|
Base
|
||||||
if name == "ffxiv" {
|
|
||||||
repo_type = Base;
|
|
||||||
} else {
|
} else {
|
||||||
repo_type = Expansion {
|
Expansion {
|
||||||
number: name[2..3].parse().unwrap()
|
number: name[2..3].parse().unwrap()
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
let version: Option<String>;
|
let version = if repo_type == Base {
|
||||||
|
|
||||||
if repo_type == Base {
|
|
||||||
let mut d = PathBuf::from(dir);
|
let mut d = PathBuf::from(dir);
|
||||||
d.pop();
|
d.pop();
|
||||||
d.pop();
|
d.pop();
|
||||||
d.push("ffxivgame.ver");
|
d.push("ffxivgame.ver");
|
||||||
|
|
||||||
version = read_version(d.as_path());
|
read_version(d.as_path())
|
||||||
} else {
|
} else {
|
||||||
let mut d = PathBuf::from(dir);
|
let mut d = PathBuf::from(dir);
|
||||||
d.push(format!("{}.ver", name));
|
d.push(format!("{}.ver", name));
|
||||||
|
|
||||||
version = read_version(d.as_path());
|
read_version(d.as_path())
|
||||||
}
|
};
|
||||||
|
|
||||||
if version == None {
|
if version == None {
|
||||||
return None;
|
return None;
|
||||||
|
|
|
@ -71,7 +71,7 @@ impl Skeleton {
|
||||||
content : String
|
content : String
|
||||||
}
|
}
|
||||||
|
|
||||||
let pak = HkPackfile::from_str(&mut std::str::from_utf8(&buffer).unwrap())
|
let pak = HkPackfile::from_str(std::str::from_utf8(buffer).unwrap())
|
||||||
.expect("Failed to parse sidecar file!");
|
.expect("Failed to parse sidecar file!");
|
||||||
|
|
||||||
// find the root level object
|
// find the root level object
|
||||||
|
@ -97,7 +97,7 @@ impl Skeleton {
|
||||||
string_repr.push(']');
|
string_repr.push(']');
|
||||||
|
|
||||||
// then we turn all of newlines into commas, except of course for the last one!
|
// then we turn all of newlines into commas, except of course for the last one!
|
||||||
string_repr = string_repr.replacen("\n", ",", string_repr.matches("\n").count() - 1);
|
string_repr = string_repr.replacen('\n', ",", string_repr.matches('\n').count() - 1);
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue