diff --git a/src/cfg.rs b/src/cfg.rs index 8f20c89..3f30f64 100644 --- a/src/cfg.rs +++ b/src/cfg.rs @@ -34,7 +34,7 @@ impl ConfigFile { let mut current_category: Option = None; - for line in reader.lines().flatten() { + for line in reader.lines().map_while(Result::ok) { if !line.is_empty() && line != "\0" { if line.contains('<') || line.contains('>') { // Category diff --git a/src/dat.rs b/src/dat.rs index 0ef8049..3ce7d1d 100755 --- a/src/dat.rs +++ b/src/dat.rs @@ -221,9 +221,7 @@ impl DatFile { /// Reads a standard file block. fn read_standard_file(&mut self, offset: u64, file_info: &FileInfo) -> Option { - let Some(standard_file_info) = file_info.standard_info.as_ref() else { - return None; - }; + let standard_file_info = file_info.standard_info.as_ref()?; let mut blocks: Vec = Vec::with_capacity(standard_file_info.num_blocks as usize); @@ -251,9 +249,7 @@ impl DatFile { /// Reads a model file block. #[cfg(feature = "visual_data")] fn read_model_file(&mut self, offset: u64, file_info: &FileInfo) -> Option { - let Some(model_file_info) = file_info.model_info.as_ref() else { - return None; - }; + let model_file_info = file_info.model_info.as_ref()?; let mut buffer = Cursor::new(Vec::new()); @@ -401,9 +397,7 @@ impl DatFile { /// Reads a texture file block. fn read_texture_file(&mut self, offset: u64, file_info: &FileInfo) -> Option { - let Some(texture_file_info) = file_info.texture_info.as_ref() else { - return None; - }; + let texture_file_info = file_info.texture_info.as_ref()?; let mut data: Vec = Vec::with_capacity(file_info.file_size as usize); diff --git a/src/execlookup.rs b/src/execlookup.rs index e469844..632cf07 100644 --- a/src/execlookup.rs +++ b/src/execlookup.rs @@ -13,15 +13,13 @@ fn from_u16(from: &mut [u16]) -> &[u8] { unsafe { std::slice::from_raw_parts(ptr, len) } } -fn find_needle(installer_file: &Vec, needle: &str) -> Option { +fn find_needle(installer_file: &[u8], needle: &str) -> Option { let mut needle: Vec = needle.encode_utf16().collect(); let bytes = from_u16(&mut needle); - let Some(mut position) = installer_file + let mut position = installer_file .windows(bytes.len()) - .position(|window| window == bytes) else { - return None; - }; + .position(|window| window == bytes)?; let parse_char_at_position = |position: usize| { let upper = installer_file[position]; diff --git a/src/exh.rs b/src/exh.rs index 52fabf8..4f71be6 100644 --- a/src/exh.rs +++ b/src/exh.rs @@ -1,6 +1,8 @@ // SPDX-FileCopyrightText: 2023 Joshua Goins // SPDX-License-Identifier: GPL-3.0-or-later +#![allow(clippy::unnecessary_fallible_conversions)] // This wrongly trips on binrw code + use std::io::Cursor; use binrw::BinRead; diff --git a/src/exl.rs b/src/exl.rs index e86bbca..662c303 100755 --- a/src/exl.rs +++ b/src/exl.rs @@ -24,7 +24,7 @@ impl EXL { let cursor = Cursor::new(buffer); let reader = BufReader::new(cursor); - for line in reader.lines().flatten() { + for line in reader.lines().map_while(Result::ok) { if let Some((name, value)) = line.split_once(',') { if let Ok(parsed_value) = value.parse() { if name == "EXLT" { diff --git a/src/lgb.rs b/src/lgb.rs index 844ec0d..1f152a4 100644 --- a/src/lgb.rs +++ b/src/lgb.rs @@ -36,7 +36,7 @@ enum LayerEntryType #[brw(magic = 0x3i32)] LayLight, #[brw(magic = 0x4i32)] - VFX, + Vfx, #[brw(magic = 0x5i32)] PositionMarker, #[brw(magic = 0x6i32)] @@ -76,7 +76,7 @@ enum LayerEntryType Weapon = 0x27, // PopRange = 0x28, // // ExitRange = 0x29, // // - LVB = 0x2A, + Lvb = 0x2A, MapRange = 0x2B, // // NaviMeshRange = 0x2C, // // EventObject = 0x2D, // // @@ -141,10 +141,10 @@ enum RotationState #[derive(Debug, PartialEq)] enum TransformState { - TransformStatePlay = 0x0, - TransformStateStop = 0x1, - TransformStateReplay = 0x2, - TransformStateReset = 0x3, + Play = 0x0, + Stop = 0x1, + Replay = 0x2, + Reset = 0x3, } #[binrw] @@ -152,10 +152,10 @@ enum TransformState #[derive(Debug, PartialEq)] enum ColourState { - ColorStatePlay = 0x0, - ColorStateStop = 0x1, - ColorStateReplay = 0x2, - ColorStateReset = 0x3, + Play = 0x0, + Stop = 0x1, + Replay = 0x2, + Reset = 0x3, } #[binrw] @@ -163,12 +163,12 @@ enum ColourState #[derive(Debug, PartialEq)] enum TriggerBoxShape { - TriggerBoxShapeBox = 0x1, - TriggerBoxShapeSphere = 0x2, - TriggerBoxShapeCylinder = 0x3, - TriggerBoxShapeBoard = 0x4, - TriggerBoxShapeMesh = 0x5, - TriggerBoxShapeBoardBothSides = 0x6, + Box = 0x1, + Sphere = 0x2, + Cylinder = 0x3, + Board = 0x4, + Mesh = 0x5, + BoardBothSides = 0x6, } #[binrw] @@ -220,9 +220,9 @@ enum PositionMarkerType #[derive(Debug, PartialEq)] enum EnvSetShape { - EnvShapeEllipsoid = 0x1, - EnvShapeCuboid = 0x2, - EnvShapeCylinder = 0x3, + Ellipsoid = 0x1, + Cuboid = 0x2, + Cylinder = 0x3, } #[binrw] @@ -262,7 +262,7 @@ enum PopType #[br(magic = 0x1u8)] PC = 0x1, #[br(magic = 0x2u8)] - NPC, + Npc, #[br(magic = 0x3u8)] Content, } @@ -405,6 +405,7 @@ enum SoundEffectType #[binread] #[derive(Debug)] #[br(little)] +#[allow(dead_code)] // most of the fields are unused at the moment struct LayerHeader { layer_id: u32, name_offset: u32, @@ -423,10 +424,8 @@ struct LayerHeader { is_temporary: u8, is_housing: u8, version_mask: u16, - - #[br(temp)] - padding: u32, - + + #[br(pad_before = 4)] ob_set_referenced_list: i32, ob_set_referenced_list_count: i32, ob_set_enable_referenced_list: i32, @@ -436,6 +435,7 @@ struct LayerHeader { #[binread] #[derive(Debug)] #[br(little)] +#[allow(dead_code)] // most of the fields are unused at the moment struct LayerSetReferencedList { referenced_type: LayerSetReferencedType, layer_sets: i32, @@ -445,6 +445,7 @@ struct LayerSetReferencedList { #[binread] #[derive(Debug)] #[br(little)] +#[allow(dead_code)] // most of the fields are unused at the moment struct LgbHeader { #[br(count = 4)] file_id: Vec, @@ -455,6 +456,7 @@ struct LgbHeader { #[binread] #[derive(Debug)] #[br(little)] +#[allow(dead_code)] // most of the fields are unused at the moment struct LayerChunk { #[br(count = 4)] chunk_id: Vec, @@ -468,6 +470,7 @@ struct LayerChunk { #[binread] #[derive(Debug)] #[br(little)] +#[allow(dead_code)] // most of the fields are unused at the moment struct InstanceObject { asset_type: LayerEntryType, instance_id: u32, @@ -513,7 +516,7 @@ impl Layer { } cursor.seek(SeekFrom::Start(old_pos + header.layer_set_referenced_list_offset as u64)).unwrap(); - let referenced_list = LayerSetReferencedList::read(&mut cursor).unwrap(); + LayerSetReferencedList::read(&mut cursor).unwrap(); for i in 0..header.instance_object_count { cursor.seek(SeekFrom::Start(old_pos + header.instance_object_offset as u64 + instance_offsets[i as usize] as u64)).unwrap(); diff --git a/src/model.rs b/src/model.rs index eef6510..8822fdd 100755 --- a/src/model.rs +++ b/src/model.rs @@ -1,6 +1,8 @@ // SPDX-FileCopyrightText: 2023 Joshua Goins // SPDX-License-Identifier: GPL-3.0-or-later +#![allow(clippy::unnecessary_fallible_conversions)] // This wrongly trips on binrw code + use std::io::{Cursor, Seek, SeekFrom}; use std::mem::size_of; @@ -1002,6 +1004,7 @@ impl MDL { } } VertexUsage::Tangent => { + #[allow(clippy::match_single_binding)] // TODO match element.vertex_type { /*VertexType::ByteFloat4 => { MDL::write_tangent(&mut cursor, &vert.binormal).ok()?; diff --git a/src/model_file_operations.rs b/src/model_file_operations.rs index 6aaece3..73cf56b 100644 --- a/src/model_file_operations.rs +++ b/src/model_file_operations.rs @@ -69,6 +69,7 @@ impl MDL { ]) } + #[allow(dead_code)] // We will eventually use this pub(crate) fn write_half2(cursor: &mut T, vec: &[f32; 2]) -> BinResult<()> { cursor.write_le::<[u16; 2]>(&[ f16::from_f32(vec[0]).to_bits(), diff --git a/src/mtrl.rs b/src/mtrl.rs index ba3439d..0934dd2 100644 --- a/src/mtrl.rs +++ b/src/mtrl.rs @@ -1,6 +1,8 @@ // SPDX-FileCopyrightText: 2023 Joshua Goins // SPDX-License-Identifier: GPL-3.0-or-later +#![allow(clippy::unnecessary_fallible_conversions)] // This wrongly trips on binrw code + use std::io::Cursor; use binrw::{BinRead, binrw}; @@ -195,11 +197,11 @@ impl Material { for _ in 0..mat_data.file_header.texture_count { let mut string = String::new(); - let mut next_char = mat_data.strings[offset as usize] as char; + let mut next_char = mat_data.strings[offset] as char; while next_char != '\0' { string.push(next_char); offset += 1; - next_char = mat_data.strings[offset as usize] as char; + next_char = mat_data.strings[offset] as char; } texture_paths.push(string); @@ -216,7 +218,7 @@ impl Material { while next_char != '\0' { shader_package_name.push(next_char); offset += 1; - next_char = mat_data.strings[offset as usize] as char; + next_char = mat_data.strings[offset] as char; } Some(Material { diff --git a/src/patch.rs b/src/patch.rs index 1637ac4..b98bb44 100755 --- a/src/patch.rs +++ b/src/patch.rs @@ -464,7 +464,7 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> { fs::create_dir_all(left)?; let mut new_file = - OpenOptions::new().write(true).create(true).open(filename)?; + OpenOptions::new().write(true).create(true).truncate(false).open(filename)?; new_file.seek(SeekFrom::Start(add.block_offset as u64))?; @@ -481,7 +481,7 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> { ); let new_file = - OpenOptions::new().write(true).create(true).open(filename)?; + OpenOptions::new().write(true).create(true).truncate(false).open(filename)?; write_empty_file_block_at( &new_file, @@ -501,7 +501,7 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> { fs::create_dir_all(left)?; let new_file = - OpenOptions::new().write(true).create(true).open(filename)?; + OpenOptions::new().write(true).create(true).truncate(false).open(filename)?; write_empty_file_block_at( &new_file, @@ -531,6 +531,7 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> { let mut new_file = OpenOptions::new() .write(true) .create(true) + .truncate(false) .open(file_path)?; if header.header_kind != TargetHeaderKind::Version { @@ -563,6 +564,7 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> { let new_file = OpenOptions::new() .write(true) .create(true) + .truncate(false) .open(&file_path); if let Ok(mut file) = new_file { diff --git a/src/tex.rs b/src/tex.rs index 1f5730d..052083c 100644 --- a/src/tex.rs +++ b/src/tex.rs @@ -142,11 +142,11 @@ impl Texture { } fn decode(src: &[u8], width: usize, height: usize, decode_func: DecodeFunction) -> Vec { - let mut image: Vec = vec![0; (width * height) as usize]; + let mut image: Vec = vec![0; width * height]; decode_func( - &src, - width as usize, - height as usize, + src, + width, + height, &mut image, ) .unwrap();