mirror of
https://github.com/redstrate/Physis.git
synced 2025-04-20 11:47:46 +00:00
Fix yet more clippy warnings
This commit is contained in:
parent
79e6f20d86
commit
6e50f03cd9
11 changed files with 56 additions and 51 deletions
|
@ -34,7 +34,7 @@ impl ConfigFile {
|
||||||
|
|
||||||
let mut current_category: Option<String> = None;
|
let mut current_category: Option<String> = None;
|
||||||
|
|
||||||
for line in reader.lines().flatten() {
|
for line in reader.lines().map_while(Result::ok) {
|
||||||
if !line.is_empty() && line != "\0" {
|
if !line.is_empty() && line != "\0" {
|
||||||
if line.contains('<') || line.contains('>') {
|
if line.contains('<') || line.contains('>') {
|
||||||
// Category
|
// Category
|
||||||
|
|
12
src/dat.rs
12
src/dat.rs
|
@ -221,9 +221,7 @@ impl DatFile {
|
||||||
|
|
||||||
/// Reads a standard file block.
|
/// Reads a standard file block.
|
||||||
fn read_standard_file(&mut self, offset: u64, file_info: &FileInfo) -> Option<ByteBuffer> {
|
fn read_standard_file(&mut self, offset: u64, file_info: &FileInfo) -> Option<ByteBuffer> {
|
||||||
let Some(standard_file_info) = file_info.standard_info.as_ref() else {
|
let standard_file_info = file_info.standard_info.as_ref()?;
|
||||||
return None;
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut blocks: Vec<Block> = Vec::with_capacity(standard_file_info.num_blocks as usize);
|
let mut blocks: Vec<Block> = Vec::with_capacity(standard_file_info.num_blocks as usize);
|
||||||
|
|
||||||
|
@ -251,9 +249,7 @@ impl DatFile {
|
||||||
/// Reads a model file block.
|
/// Reads a model file block.
|
||||||
#[cfg(feature = "visual_data")]
|
#[cfg(feature = "visual_data")]
|
||||||
fn read_model_file(&mut self, offset: u64, file_info: &FileInfo) -> Option<ByteBuffer> {
|
fn read_model_file(&mut self, offset: u64, file_info: &FileInfo) -> Option<ByteBuffer> {
|
||||||
let Some(model_file_info) = file_info.model_info.as_ref() else {
|
let model_file_info = file_info.model_info.as_ref()?;
|
||||||
return None;
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut buffer = Cursor::new(Vec::new());
|
let mut buffer = Cursor::new(Vec::new());
|
||||||
|
|
||||||
|
@ -401,9 +397,7 @@ impl DatFile {
|
||||||
|
|
||||||
/// Reads a texture file block.
|
/// Reads a texture file block.
|
||||||
fn read_texture_file(&mut self, offset: u64, file_info: &FileInfo) -> Option<ByteBuffer> {
|
fn read_texture_file(&mut self, offset: u64, file_info: &FileInfo) -> Option<ByteBuffer> {
|
||||||
let Some(texture_file_info) = file_info.texture_info.as_ref() else {
|
let texture_file_info = file_info.texture_info.as_ref()?;
|
||||||
return None;
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut data: Vec<u8> = Vec::with_capacity(file_info.file_size as usize);
|
let mut data: Vec<u8> = Vec::with_capacity(file_info.file_size as usize);
|
||||||
|
|
||||||
|
|
|
@ -13,15 +13,13 @@ fn from_u16(from: &mut [u16]) -> &[u8] {
|
||||||
unsafe { std::slice::from_raw_parts(ptr, len) }
|
unsafe { std::slice::from_raw_parts(ptr, len) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_needle(installer_file: &Vec<u8>, needle: &str) -> Option<String> {
|
fn find_needle(installer_file: &[u8], needle: &str) -> Option<String> {
|
||||||
let mut needle: Vec<u16> = needle.encode_utf16().collect();
|
let mut needle: Vec<u16> = needle.encode_utf16().collect();
|
||||||
let bytes = from_u16(&mut needle);
|
let bytes = from_u16(&mut needle);
|
||||||
|
|
||||||
let Some(mut position) = installer_file
|
let mut position = installer_file
|
||||||
.windows(bytes.len())
|
.windows(bytes.len())
|
||||||
.position(|window| window == bytes) else {
|
.position(|window| window == bytes)?;
|
||||||
return None;
|
|
||||||
};
|
|
||||||
|
|
||||||
let parse_char_at_position = |position: usize| {
|
let parse_char_at_position = |position: usize| {
|
||||||
let upper = installer_file[position];
|
let upper = installer_file[position];
|
||||||
|
|
|
@ -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::unnecessary_fallible_conversions)] // This wrongly trips on binrw code
|
||||||
|
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
|
||||||
use binrw::BinRead;
|
use binrw::BinRead;
|
||||||
|
|
|
@ -24,7 +24,7 @@ impl EXL {
|
||||||
let cursor = Cursor::new(buffer);
|
let cursor = Cursor::new(buffer);
|
||||||
let reader = BufReader::new(cursor);
|
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 Some((name, value)) = line.split_once(',') {
|
||||||
if let Ok(parsed_value) = value.parse() {
|
if let Ok(parsed_value) = value.parse() {
|
||||||
if name == "EXLT" {
|
if name == "EXLT" {
|
||||||
|
|
51
src/lgb.rs
51
src/lgb.rs
|
@ -36,7 +36,7 @@ enum LayerEntryType
|
||||||
#[brw(magic = 0x3i32)]
|
#[brw(magic = 0x3i32)]
|
||||||
LayLight,
|
LayLight,
|
||||||
#[brw(magic = 0x4i32)]
|
#[brw(magic = 0x4i32)]
|
||||||
VFX,
|
Vfx,
|
||||||
#[brw(magic = 0x5i32)]
|
#[brw(magic = 0x5i32)]
|
||||||
PositionMarker,
|
PositionMarker,
|
||||||
#[brw(magic = 0x6i32)]
|
#[brw(magic = 0x6i32)]
|
||||||
|
@ -76,7 +76,7 @@ enum LayerEntryType
|
||||||
Weapon = 0x27, //
|
Weapon = 0x27, //
|
||||||
PopRange = 0x28, // //
|
PopRange = 0x28, // //
|
||||||
ExitRange = 0x29, // //
|
ExitRange = 0x29, // //
|
||||||
LVB = 0x2A,
|
Lvb = 0x2A,
|
||||||
MapRange = 0x2B, // //
|
MapRange = 0x2B, // //
|
||||||
NaviMeshRange = 0x2C, // //
|
NaviMeshRange = 0x2C, // //
|
||||||
EventObject = 0x2D, // //
|
EventObject = 0x2D, // //
|
||||||
|
@ -141,10 +141,10 @@ enum RotationState
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
enum TransformState
|
enum TransformState
|
||||||
{
|
{
|
||||||
TransformStatePlay = 0x0,
|
Play = 0x0,
|
||||||
TransformStateStop = 0x1,
|
Stop = 0x1,
|
||||||
TransformStateReplay = 0x2,
|
Replay = 0x2,
|
||||||
TransformStateReset = 0x3,
|
Reset = 0x3,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
|
@ -152,10 +152,10 @@ enum TransformState
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
enum ColourState
|
enum ColourState
|
||||||
{
|
{
|
||||||
ColorStatePlay = 0x0,
|
Play = 0x0,
|
||||||
ColorStateStop = 0x1,
|
Stop = 0x1,
|
||||||
ColorStateReplay = 0x2,
|
Replay = 0x2,
|
||||||
ColorStateReset = 0x3,
|
Reset = 0x3,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
|
@ -163,12 +163,12 @@ enum ColourState
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
enum TriggerBoxShape
|
enum TriggerBoxShape
|
||||||
{
|
{
|
||||||
TriggerBoxShapeBox = 0x1,
|
Box = 0x1,
|
||||||
TriggerBoxShapeSphere = 0x2,
|
Sphere = 0x2,
|
||||||
TriggerBoxShapeCylinder = 0x3,
|
Cylinder = 0x3,
|
||||||
TriggerBoxShapeBoard = 0x4,
|
Board = 0x4,
|
||||||
TriggerBoxShapeMesh = 0x5,
|
Mesh = 0x5,
|
||||||
TriggerBoxShapeBoardBothSides = 0x6,
|
BoardBothSides = 0x6,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
|
@ -220,9 +220,9 @@ enum PositionMarkerType
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
enum EnvSetShape
|
enum EnvSetShape
|
||||||
{
|
{
|
||||||
EnvShapeEllipsoid = 0x1,
|
Ellipsoid = 0x1,
|
||||||
EnvShapeCuboid = 0x2,
|
Cuboid = 0x2,
|
||||||
EnvShapeCylinder = 0x3,
|
Cylinder = 0x3,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
|
@ -262,7 +262,7 @@ enum PopType
|
||||||
#[br(magic = 0x1u8)]
|
#[br(magic = 0x1u8)]
|
||||||
PC = 0x1,
|
PC = 0x1,
|
||||||
#[br(magic = 0x2u8)]
|
#[br(magic = 0x2u8)]
|
||||||
NPC,
|
Npc,
|
||||||
#[br(magic = 0x3u8)]
|
#[br(magic = 0x3u8)]
|
||||||
Content,
|
Content,
|
||||||
}
|
}
|
||||||
|
@ -405,6 +405,7 @@ enum SoundEffectType
|
||||||
#[binread]
|
#[binread]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[br(little)]
|
#[br(little)]
|
||||||
|
#[allow(dead_code)] // most of the fields are unused at the moment
|
||||||
struct LayerHeader {
|
struct LayerHeader {
|
||||||
layer_id: u32,
|
layer_id: u32,
|
||||||
name_offset: u32,
|
name_offset: u32,
|
||||||
|
@ -424,9 +425,7 @@ struct LayerHeader {
|
||||||
is_housing: u8,
|
is_housing: u8,
|
||||||
version_mask: u16,
|
version_mask: u16,
|
||||||
|
|
||||||
#[br(temp)]
|
#[br(pad_before = 4)]
|
||||||
padding: u32,
|
|
||||||
|
|
||||||
ob_set_referenced_list: i32,
|
ob_set_referenced_list: i32,
|
||||||
ob_set_referenced_list_count: i32,
|
ob_set_referenced_list_count: i32,
|
||||||
ob_set_enable_referenced_list: i32,
|
ob_set_enable_referenced_list: i32,
|
||||||
|
@ -436,6 +435,7 @@ struct LayerHeader {
|
||||||
#[binread]
|
#[binread]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[br(little)]
|
#[br(little)]
|
||||||
|
#[allow(dead_code)] // most of the fields are unused at the moment
|
||||||
struct LayerSetReferencedList {
|
struct LayerSetReferencedList {
|
||||||
referenced_type: LayerSetReferencedType,
|
referenced_type: LayerSetReferencedType,
|
||||||
layer_sets: i32,
|
layer_sets: i32,
|
||||||
|
@ -445,6 +445,7 @@ struct LayerSetReferencedList {
|
||||||
#[binread]
|
#[binread]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[br(little)]
|
#[br(little)]
|
||||||
|
#[allow(dead_code)] // most of the fields are unused at the moment
|
||||||
struct LgbHeader {
|
struct LgbHeader {
|
||||||
#[br(count = 4)]
|
#[br(count = 4)]
|
||||||
file_id: Vec<u8>,
|
file_id: Vec<u8>,
|
||||||
|
@ -455,6 +456,7 @@ struct LgbHeader {
|
||||||
#[binread]
|
#[binread]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[br(little)]
|
#[br(little)]
|
||||||
|
#[allow(dead_code)] // most of the fields are unused at the moment
|
||||||
struct LayerChunk {
|
struct LayerChunk {
|
||||||
#[br(count = 4)]
|
#[br(count = 4)]
|
||||||
chunk_id: Vec<u8>,
|
chunk_id: Vec<u8>,
|
||||||
|
@ -468,6 +470,7 @@ struct LayerChunk {
|
||||||
#[binread]
|
#[binread]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[br(little)]
|
#[br(little)]
|
||||||
|
#[allow(dead_code)] // most of the fields are unused at the moment
|
||||||
struct InstanceObject {
|
struct InstanceObject {
|
||||||
asset_type: LayerEntryType,
|
asset_type: LayerEntryType,
|
||||||
instance_id: u32,
|
instance_id: u32,
|
||||||
|
@ -513,7 +516,7 @@ impl Layer {
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor.seek(SeekFrom::Start(old_pos + header.layer_set_referenced_list_offset as u64)).unwrap();
|
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 {
|
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();
|
cursor.seek(SeekFrom::Start(old_pos + header.instance_object_offset as u64 + instance_offsets[i as usize] as u64)).unwrap();
|
||||||
|
|
|
@ -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::unnecessary_fallible_conversions)] // This wrongly trips on binrw code
|
||||||
|
|
||||||
use std::io::{Cursor, Seek, SeekFrom};
|
use std::io::{Cursor, Seek, SeekFrom};
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
|
|
||||||
|
@ -1002,6 +1004,7 @@ impl MDL {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
VertexUsage::Tangent => {
|
VertexUsage::Tangent => {
|
||||||
|
#[allow(clippy::match_single_binding)] // TODO
|
||||||
match element.vertex_type {
|
match element.vertex_type {
|
||||||
/*VertexType::ByteFloat4 => {
|
/*VertexType::ByteFloat4 => {
|
||||||
MDL::write_tangent(&mut cursor, &vert.binormal).ok()?;
|
MDL::write_tangent(&mut cursor, &vert.binormal).ok()?;
|
||||||
|
|
|
@ -69,6 +69,7 @@ impl MDL {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)] // We will eventually use this
|
||||||
pub(crate) fn write_half2<T: BinWriterExt>(cursor: &mut T, vec: &[f32; 2]) -> BinResult<()> {
|
pub(crate) fn write_half2<T: BinWriterExt>(cursor: &mut T, vec: &[f32; 2]) -> BinResult<()> {
|
||||||
cursor.write_le::<[u16; 2]>(&[
|
cursor.write_le::<[u16; 2]>(&[
|
||||||
f16::from_f32(vec[0]).to_bits(),
|
f16::from_f32(vec[0]).to_bits(),
|
||||||
|
|
|
@ -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::unnecessary_fallible_conversions)] // This wrongly trips on binrw code
|
||||||
|
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
|
||||||
use binrw::{BinRead, binrw};
|
use binrw::{BinRead, binrw};
|
||||||
|
@ -195,11 +197,11 @@ impl Material {
|
||||||
for _ in 0..mat_data.file_header.texture_count {
|
for _ in 0..mat_data.file_header.texture_count {
|
||||||
let mut string = String::new();
|
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' {
|
while next_char != '\0' {
|
||||||
string.push(next_char);
|
string.push(next_char);
|
||||||
offset += 1;
|
offset += 1;
|
||||||
next_char = mat_data.strings[offset as usize] as char;
|
next_char = mat_data.strings[offset] as char;
|
||||||
}
|
}
|
||||||
|
|
||||||
texture_paths.push(string);
|
texture_paths.push(string);
|
||||||
|
@ -216,7 +218,7 @@ impl Material {
|
||||||
while next_char != '\0' {
|
while next_char != '\0' {
|
||||||
shader_package_name.push(next_char);
|
shader_package_name.push(next_char);
|
||||||
offset += 1;
|
offset += 1;
|
||||||
next_char = mat_data.strings[offset as usize] as char;
|
next_char = mat_data.strings[offset] as char;
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(Material {
|
Some(Material {
|
||||||
|
|
|
@ -464,7 +464,7 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> {
|
||||||
fs::create_dir_all(left)?;
|
fs::create_dir_all(left)?;
|
||||||
|
|
||||||
let mut new_file =
|
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))?;
|
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 =
|
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(
|
write_empty_file_block_at(
|
||||||
&new_file,
|
&new_file,
|
||||||
|
@ -501,7 +501,7 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> {
|
||||||
fs::create_dir_all(left)?;
|
fs::create_dir_all(left)?;
|
||||||
|
|
||||||
let new_file =
|
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(
|
write_empty_file_block_at(
|
||||||
&new_file,
|
&new_file,
|
||||||
|
@ -531,6 +531,7 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> {
|
||||||
let mut new_file = OpenOptions::new()
|
let mut new_file = OpenOptions::new()
|
||||||
.write(true)
|
.write(true)
|
||||||
.create(true)
|
.create(true)
|
||||||
|
.truncate(false)
|
||||||
.open(file_path)?;
|
.open(file_path)?;
|
||||||
|
|
||||||
if header.header_kind != TargetHeaderKind::Version {
|
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()
|
let new_file = OpenOptions::new()
|
||||||
.write(true)
|
.write(true)
|
||||||
.create(true)
|
.create(true)
|
||||||
|
.truncate(false)
|
||||||
.open(&file_path);
|
.open(&file_path);
|
||||||
|
|
||||||
if let Ok(mut file) = new_file {
|
if let Ok(mut file) = new_file {
|
||||||
|
|
|
@ -142,11 +142,11 @@ impl Texture {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decode(src: &[u8], width: usize, height: usize, decode_func: DecodeFunction) -> Vec<u8> {
|
fn decode(src: &[u8], width: usize, height: usize, decode_func: DecodeFunction) -> Vec<u8> {
|
||||||
let mut image: Vec<u32> = vec![0; (width * height) as usize];
|
let mut image: Vec<u32> = vec![0; width * height];
|
||||||
decode_func(
|
decode_func(
|
||||||
&src,
|
src,
|
||||||
width as usize,
|
width,
|
||||||
height as usize,
|
height,
|
||||||
&mut image,
|
&mut image,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
Loading…
Add table
Reference in a new issue