diff --git a/README.md b/README.md index f7b918e..9e4529f 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,11 @@ Unfortunately, several other tools, including SoraVoice and ED6Unpacker, expose these raw names, and so the filenames need to be converted to the proper format for use with LB-ARK. +To help with compatibility with such tools, LB-ARK accepts the +`$LB_ARK_SPACED_FILENAMES` environment variable. If this is nonempty, LB-ARK +will load 8.3 filenames as well. However, this is only intended for local +development; please do not release any mods requiring this to be set. + ## Usage To substitute a file inside an archive, place the substitute in diff --git a/src/lib.rs b/src/lib.rs index 4b13202..a0c019e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,6 +35,10 @@ mod hooks { } } +lazy_static::lazy_static! { + static ref SPACED_FILENAMES: bool = std::env::var("LB_DIR_SPACED_FILENAMES").is_ok_and(|a| !a.is_empty()); +} + #[instrument(skip_all)] fn init() { tracing::info!( @@ -42,10 +46,16 @@ fn init() { data = %DATA_DIR.display(), "init", ); + + if *SPACED_FILENAMES { + tracing::warn!("spaced filenames enabled"); + } + if !DATA_DIR.exists() { tracing::warn!("data dir does not exist, creating"); std::fs::create_dir_all(&*DATA_DIR).unwrap(); } + catch(plugin::init()); catch(init_lb_dir()); } @@ -138,10 +148,23 @@ fn get_redirect_file(fileid: u32, entry: &Entry) -> Option { } } - let dirnr = fileid >> 16; - let path = DATA_DIR.join(format!("ED6_DT{dirnr:02X}")).join(entry.name()); + let dir = DATA_DIR.join(format!("ED6_DT{:02X}", fileid >> 16)); + + let path = dir.join(entry.name()); tracing::debug!(path = %rel(&path), exists = path.exists(), "checking implicit override"); - path.exists().then_some(path) + if path.exists() { + return Some(path) + } + + if *SPACED_FILENAMES { + let path = dir.join(&*String::from_utf8_lossy(&entry.stored_name)); + tracing::debug!(path = %rel(&path), exists = path.exists(), "checking spaced implicit override"); + if path.exists() { + return Some(path) + } + } + + None } /// Reads a file into memory, compressing it if necessary.