diff --git a/Cargo.lock b/Cargo.lock index d633fd8..e022053 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1060,7 +1060,7 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "physis" version = "0.5.0" -source = "git+https://github.com/redstrate/physis#c0d3df99c36e1c3aedc8fd203192df556eddcc29" +source = "git+https://github.com/redstrate/physis#b3196219d2f4618383eba1c6c0a79a1a2dadf954" dependencies = [ "binrw", "bitflags", diff --git a/src/config.rs b/src/config.rs index ac6148c..808049c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -375,6 +375,10 @@ pub struct FilesystemConfig { /// If the directory is not specified, Kawari won't save file contents. #[serde(default)] pub unpack_path: String, + + /// Navimesh file directory. + #[serde(default)] + pub navimesh_path: String, } /// Global and all-encompassing config. diff --git a/src/world/zone.rs b/src/world/zone.rs index a0006eb..74c03a5 100644 --- a/src/world/zone.rs +++ b/src/world/zone.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use icarus::TerritoryType::TerritoryTypeSheet; use physis::{ common::Language, @@ -8,7 +10,10 @@ use physis::{ resource::Resource, }; -use crate::common::{GameData, TerritoryNameKind}; +use crate::{ + common::{GameData, TerritoryNameKind}, + config::get_config, +}; /// Represents a loaded zone #[derive(Default, Debug)] @@ -19,6 +24,7 @@ pub struct Zone { pub place_name: String, pub intended_use: u8, pub layer_groups: Vec, + pub navimesh_path: String, } impl Zone { @@ -43,6 +49,21 @@ impl Zone { let lgb_file = game_data.resource.read(&path).unwrap(); let lgb = Lvb::from_existing(&lgb_file).unwrap(); + for layer_set in &lgb.scns[0].unk3.unk2 { + // FIXME: this is wrong. I think there might be multiple, separate navimeshes in really big zones but I'm not sure yet. + zone.navimesh_path = layer_set.path_nvm.replace("/server/data/", "").to_string(); + } + + let config = get_config(); + if config.filesystem.navimesh_path.is_empty() { + tracing::warn!("Navimesh path is not set! Monsters will not function correctly!"); + } else { + let mut nvm_path = PathBuf::from(config.filesystem.navimesh_path); + nvm_path.push(&zone.navimesh_path); + + Self::load_navimesh(&nvm_path.to_str().unwrap()); + } + let mut load_lgb = |path: &str| -> Option { let lgb_file = game_data.resource.read(path)?; tracing::info!("Loading {path}"); @@ -116,4 +137,14 @@ impl Zone { None } + + // TODO: add better error handling here + fn load_navimesh(path: &str) -> Option<()> { + if !std::fs::exists(path).unwrap_or_default() { + tracing::warn!("Navimesh {path} does not exist, monsters will not function correctly!"); + return None; + } + + Some(()) + } }