diff --git a/Cargo.lock b/Cargo.lock index d2b7331..d5f2bfa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -79,7 +79,7 @@ checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" [[package]] name = "xc3-file-loader" -version = "1.3.0" +version = "1.3.1" dependencies = [ "skyline", ] diff --git a/Cargo.toml b/Cargo.toml index 1ad8fbc..67641d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "xc3-file-loader" -version = "1.3.0" +version = "1.3.1" authors = ["RoccoDev "] edition = "2021" license = "gpl-3.0" @@ -28,4 +28,4 @@ panic = "abort" [profile.release] panic = "abort" lto = true -strip = true \ No newline at end of file +strip = true diff --git a/src/hash.rs b/src/hash.rs index 9b96f50..33df925 100644 --- a/src/hash.rs +++ b/src/hash.rs @@ -41,12 +41,15 @@ pub struct IdentityHasher(u64); pub type PreHashedSet = std::collections::HashSet; -pub fn crc32(name: &str) -> u32 { +/// Calculates a CRC-32 hash of the given string, +/// converting any uppercase characters to lowercase beforehand. +pub fn crc32_lowercase(name: &str) -> u32 { if name.is_empty() { return 0; } let mut hash = 0u32; for b in name.bytes() { + let b = if (b'A'..=b'Z').contains(&b) { b + 32 } else { b }; let val = hash ^ b as u32; hash = (hash >> 8) ^ CRC_TABLE[val as usize & 0xff]; } diff --git a/src/loader.rs b/src/loader.rs index bc19662..57eed90 100644 --- a/src/loader.rs +++ b/src/loader.rs @@ -3,7 +3,7 @@ use std::borrow::Borrow; use std::ffi::{CStr, CString}; use std::mem::MaybeUninit; -use crate::hash::{crc32, PreHashedSet}; +use crate::hash::{crc32_lowercase, PreHashedSet}; /// Top-level paths to skip when matching romfs paths static TOP_LEVEL_BLACKLIST: [&str; 5] = ["bf3.ard", "bf3.arh", "movie", "sound", "skyline"]; @@ -36,7 +36,7 @@ impl FileLoader { } pub fn is_blocked(&self, file_name: &str) -> bool { - self.block_list.contains(&crc32(file_name)) + self.block_list.contains(&crc32_lowercase(file_name)) } unsafe fn import_dir(&mut self, path: &str, level: usize) -> Result<()> { @@ -88,7 +88,7 @@ impl FileLoader { fn register_file(&mut self, path: &str) { assert!(path.len() >= 4); // rom:/ let path = &path[4..]; - let hash = crc32(path); + let hash = crc32_lowercase(path); dbg_println!("[XC3-Files] Registering {path}"); if !self.block_list.insert(hash) { // The game also uses CRC-32 internally to cache resources. It's likely that