Skip to content

Commit

Permalink
chore: Fix "some" clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
cohaereo committed Dec 18, 2023
1 parent d0f081b commit a2b6d50
Show file tree
Hide file tree
Showing 39 changed files with 219 additions and 273 deletions.
4 changes: 2 additions & 2 deletions eurochef-edb/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl<T: BinRead> EXGeoHashArray<T> {
}

pub fn data(&self) -> &Vec<T> {
return &self.data;
&self.data
}
}

Expand Down Expand Up @@ -161,7 +161,7 @@ impl<T: BinRead> EXRelArray<T> {
}

pub fn data(&self) -> &Vec<T> {
return &self.data;
&self.data
}
}

Expand Down
14 changes: 5 additions & 9 deletions eurochef-edb/src/edb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ impl<R: Read + Seek + Sized> DatabaseReader for R {
let ptr: *mut EdbFile = transmute(self as *mut _);

// Check alignment and safety marker
if (transmute::<_, usize>(ptr) & 0x7) == 0
&& (*ptr).safety_marker == EdbFile::SAFETY_MARKER
{
Some(transmute(ptr))
if (ptr as usize & 0x7) == 0 && (*ptr).safety_marker == EdbFile::SAFETY_MARKER {
Some(&mut *ptr)
} else {
if cfg!(debug_assertions) {
warn!("Couldn't verify EdbFile marker and alignment!");
Expand Down Expand Up @@ -76,7 +74,7 @@ impl EdbFile {
));
}

if version < 182 || version > 263 {
if !(182..=263).contains(&version) {
return Err(crate::error::EurochefError::Unsupported(
crate::error::UnsupportedError::Version(version),
));
Expand Down Expand Up @@ -109,10 +107,8 @@ impl EdbFile {
pub fn add_reference(&mut self, file: Hashcode, reference: Hashcode) {
if file == u32::MAX || reference.is_local() {
self.add_reference_internal(reference);
} else {
if !self.external_references.contains(&(file, reference)) {
self.external_references.push((file, reference))
}
} else if !self.external_references.contains(&(file, reference)) {
self.external_references.push((file, reference))
}
}

Expand Down
2 changes: 1 addition & 1 deletion eurochef-edb/src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl EXGeoEntity {
EXGeoEntity::Mesh(e) => Some(&e.data.base),
EXGeoEntity::Split(e) => Some(&e.base),
EXGeoEntity::MapZone(e) => Some(&e.base),
EXGeoEntity::Instance(e) => Some(&e),
EXGeoEntity::Instance(e) => Some(e),
EXGeoEntity::UnknownType(_e) => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion eurochef-edb/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl BinRead for EXGeoTriggerEngineOptions {
let mut res: EXGeoTriggerEngineOptions = Default::default();

const FLAG_BASE: usize = 24;
if trig_flags.is_set(FLAG_BASE + 0) {
if trig_flags.is_set(FLAG_BASE) {
res.visual_object = Some(reader.read_type(endian)?);
}
if trig_flags.is_set(FLAG_BASE + 1) {
Expand Down
11 changes: 7 additions & 4 deletions eurochef-edb/src/versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub enum Platform {
}

pub fn transform_windows_path<P: AsRef<str>>(path: P) -> String {
path.as_ref().replace("\\", "/")
path.as_ref().replace('\\', "/")
}

impl Platform {
Expand All @@ -47,12 +47,15 @@ impl Platform {

// swy: the magic value is the four-byte GEOM tag, for big endian the G '0x47' shows first,
// otherwise it's the M (0x4D) of MOEG; looks reversed to humans, little-endian
let endian = if reader.read_ne::<u8>().ok()? == b'G' /* 0x47 */ {
let endian = if reader.read_ne::<u8>().ok()? == b'G'
/* 0x47 */
{
Endian::Big
} else { // 'M' /* 0x4D */
} else {
// 'M' /* 0x4D */
Endian::Little
};

reader.rewind().ok();
let header = reader.read_type::<EXGeoHeader>(endian).unwrap();

Expand Down
16 changes: 8 additions & 8 deletions eurochef-filelist/src/path.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
pub fn unscramble_filename_v7(file_index: u32, bytes: &mut [u8]) {
for i in 0..bytes.len() {
bytes[i] = (bytes[i] as u32)
for (i, b) in bytes.iter_mut().enumerate() {
*b = (*b as u32)
.wrapping_add(0x16)
.wrapping_sub(file_index)
.wrapping_sub(i as u32) as u8;

if bytes[i] == 0 {
if *b == 0 {
break;
}
}
}

// TODO: This should take a string and output a Cow<[u8]> to ensure null-termination
pub fn scramble_filename_v7(file_index: u32, bytes: &mut [u8]) {
for i in 0..bytes.len() {
bytes[i] = (bytes[i] as u32)
for (i, b) in bytes.iter_mut().enumerate() {
*b = (*b as u32)
.wrapping_sub(0x16)
.wrapping_add(file_index)
.wrapping_add(i as u32) as u8;
}
}

pub fn unscramble_filename_v10(file_index: u32, bytes: &mut [u8]) {
for i in 0..bytes.len() {
bytes[i] = (bytes[i] as u32)
for (i, b) in bytes.iter_mut().enumerate() {
*b = (*b as u32)
.wrapping_sub(0x6a)
.wrapping_sub(file_index * 4)
.wrapping_sub(i as u32 * 4) as u8;

if bytes[i] == 0 {
if *b == 0 {
break;
}
}
Expand Down
15 changes: 7 additions & 8 deletions eurochef-filelist/src/v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,15 @@ impl EXFileList4 {
}

// FIXME: If the strings arent encoded linearly this will be a bit inefficient
for (_, (start, end)) in filename_offsets
for (start, end) in filename_offsets
.iter()
.chain([res.header.filesize as u64].iter())
.tuple_windows()
.enumerate()
{
let size = end - start;
let mut data = vec![0u8; size as usize];
reader.seek(std::io::SeekFrom::Start(*start))?;
reader.read(&mut data)?;
reader.read_exact(&mut data)?;

let null_pos = data.iter().position(|&p| p == 0).unwrap_or(data.len());
res.filenames
Expand All @@ -64,16 +63,16 @@ impl EXFileList4 {
}
}

impl Into<UXFileList> for EXFileList4 {
fn into(self) -> UXFileList {
impl From<EXFileList4> for UXFileList {
fn from(val: EXFileList4) -> Self {
UXFileList {
num_filelists: None,
build_type: None,
endian: self.endian,
files: self
endian: val.endian,
files: val
.filenames
.into_iter()
.zip(self.header.fileinfo)
.zip(val.header.fileinfo)
.map(|(filename, info)| {
(
filename,
Expand Down
16 changes: 8 additions & 8 deletions eurochef-filelist/src/v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl EXFileList5 {
let size = end - start;
let mut data = vec![0u8; size as usize];
reader.seek(std::io::SeekFrom::Start(*start))?;
reader.read(&mut data)?;
reader.read_exact(&mut data)?;

if res.header.version >= 7 {
unscramble_filename_v7(i as u32, &mut data);
Expand All @@ -71,16 +71,16 @@ impl EXFileList5 {
}

// TODO: Make a trait for filelists bundling both the read and from/into functions so that they can be used genericly
impl Into<UXFileList> for EXFileList5 {
fn into(self) -> UXFileList {
impl From<EXFileList5> for UXFileList {
fn from(val: EXFileList5) -> Self {
UXFileList {
num_filelists: Some(self.header.num_filelists),
build_type: Some(self.header.build_type),
endian: self.endian,
files: self
num_filelists: Some(val.header.num_filelists),
build_type: Some(val.header.build_type),
endian: val.endian,
files: val
.filenames
.into_iter()
.zip(self.header.fileinfo)
.zip(val.header.fileinfo)
.map(|(filename, info)| {
(
filename,
Expand Down
16 changes: 8 additions & 8 deletions eurochef-filelist/src/v9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl EXFileList9 {
let size = end - start;
let mut data = vec![0u8; size as usize];
reader.seek(std::io::SeekFrom::Start(*start))?;
reader.read(&mut data)?;
reader.read_exact(&mut data)?;

if res.header.version >= 10 {
unscramble_filename_v10(i as u32, &mut data);
Expand All @@ -73,16 +73,16 @@ impl EXFileList9 {
}

// TODO: Make a trait for filelists bundling both the read and from/into functions so that they can be used genericly
impl Into<UXFileList> for EXFileList9 {
fn into(self) -> UXFileList {
impl From<EXFileList9> for UXFileList {
fn from(val: EXFileList9) -> Self {
UXFileList {
num_filelists: Some(self.header.num_filelists),
build_type: Some(self.header.build_type),
endian: self.endian,
files: self
num_filelists: Some(val.header.num_filelists),
build_type: Some(val.header.build_type),
endian: val.endian,
files: val
.filenames
.into_iter()
.zip(self.header.fileinfo)
.zip(val.header.fileinfo)
.map(|(filename, info)| {
(
filename,
Expand Down
16 changes: 6 additions & 10 deletions eurochef/cli/src/edb/animations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ pub fn execute_command(

let output_folder = output_folder.unwrap_or(format!(
"./entities/{}/",
Path::new(&filename)
.file_name()
.unwrap()
.to_string_lossy()
.to_string(),
Path::new(&filename).file_name().unwrap().to_string_lossy()
));
let output_folder = Path::new(&output_folder);

Expand Down Expand Up @@ -66,7 +62,7 @@ pub fn execute_command(
)
.unwrap()
.progress_chars("##-")
.tick_chars(&TICK_STRINGS),
.tick_chars(TICK_STRINGS),
);
pb.set_message("Extracting textures");

Expand All @@ -77,7 +73,7 @@ pub fn execute_command(
let _span_enter = _span.enter();

if let Ok(t) = it.data {
if t.frames.len() == 0 {
if t.frames.is_empty() {
error!("Skipping texture with no frames");
continue;
}
Expand Down Expand Up @@ -118,7 +114,7 @@ pub fn execute_command(
)
.unwrap()
.progress_chars("##-")
.tick_chars(&TICK_STRINGS),
.tick_chars(TICK_STRINGS),
);
pb.set_message("Extracting animskins");

Expand Down Expand Up @@ -190,7 +186,7 @@ pub fn execute_command(
}
}

if vertex_data.len() == 0 {
if vertex_data.is_empty() {
warn!(
"Processed entity doesnt have vertex data! (v={}/i={}/t={})",
vertex_data.len(),
Expand All @@ -199,7 +195,7 @@ pub fn execute_command(
);
}

if strips.len() <= 0 {
if strips.is_empty() {
continue;
}

Expand Down
18 changes: 7 additions & 11 deletions eurochef/cli/src/edb/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ pub fn execute_command(
) -> anyhow::Result<()> {
let output_folder = output_folder.unwrap_or(format!(
"./entities/{}/",
Path::new(&filename)
.file_name()
.unwrap()
.to_string_lossy()
.to_string(),
Path::new(&filename).file_name().unwrap().to_string_lossy()
));
let output_folder = Path::new(&output_folder);

Expand Down Expand Up @@ -92,7 +88,7 @@ pub fn execute_command(
)
.unwrap()
.progress_chars("##-")
.tick_chars(&TICK_STRINGS),
.tick_chars(TICK_STRINGS),
);
pb.set_message("Extracting textures");

Expand All @@ -103,7 +99,7 @@ pub fn execute_command(
let _span_enter = _span.enter();

if let Ok(t) = it.data {
if t.frames.len() == 0 {
if t.frames.is_empty() {
error!("Skipping texture with no frames");
continue;
}
Expand Down Expand Up @@ -164,7 +160,7 @@ pub fn execute_command(
)
.unwrap()
.progress_chars("##-")
.tick_chars(&TICK_STRINGS),
.tick_chars(TICK_STRINGS),
);
pb.set_message("Extracting entities");

Expand Down Expand Up @@ -210,7 +206,7 @@ pub fn execute_command(
continue;
}

if strips.len() <= 0 {
if strips.is_empty() {
warn!(
"Processed entity doesnt have tristrips! (v={}/i={}/t={})",
vertex_data.len(),
Expand All @@ -234,7 +230,7 @@ pub fn execute_command(
}
}

if vertex_data.len() == 0 {
if vertex_data.is_empty() {
warn!(
"Processed entity doesnt have vertex data! (v={}/i={}/t={})",
vertex_data.len(),
Expand All @@ -243,7 +239,7 @@ pub fn execute_command(
);
}

let mut gltf = gltf_export::create_mesh_scene(&ent_id);
let mut gltf = gltf_export::create_mesh_scene(ent_id);
gltf_export::add_mesh_to_scene(
&mut gltf,
&vertex_data,
Expand Down
Loading

0 comments on commit a2b6d50

Please sign in to comment.