diff --git a/Cargo.lock b/Cargo.lock index b0c88544..e6ebeedc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1788,6 +1788,14 @@ dependencies = [ "xxhash-rust", ] +[[package]] +name = "me3-mod-host-api" +version = "0.9.0" +dependencies = [ + "me3-launcher-attach-protocol", + "serde_json", +] + [[package]] name = "me3-mod-host-assets" version = "0.11.0" diff --git a/Cargo.toml b/Cargo.toml index 29f25f23..5a13606d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ members = [ "crates/mod-host-types", "crates/telemetry", "crates/xtask", - "crates/binary-analysis", + "crates/binary-analysis", "crates/mod-host-api", ] resolver = "2" diff --git a/crates/cli/src/config.rs b/crates/cli/src/config.rs index 1aca92b4..747ccf8d 100644 --- a/crates/cli/src/config.rs +++ b/crates/cli/src/config.rs @@ -41,6 +41,10 @@ pub struct Options { #[clap(long, help_heading = "Configuration", value_hint = clap::ValueHint::DirPath)] pub(crate) windows_binaries_dir: Option>, + /// Path to a directory used to store me3 log files. + #[clap(long, help_heading = "Configuration", value_hint = clap::ValueHint::DirPath)] + pub(crate) log_dir: Option>, + #[clap(skip)] #[serde(default)] pub(crate) game: BTreeMap, @@ -53,7 +57,10 @@ pub struct Config { impl Config { pub fn log_dir(&self) -> Option> { - self.known_dirs.data_dir().join("logs") + self.options + .log_dir + .clone() + .or_else(|| self.known_dirs.data_dir().join("logs")) } pub fn cache_dir(&self) -> Option> { @@ -107,6 +114,7 @@ impl Options { Self { crash_reporting: other.crash_reporting.or(self.crash_reporting), game: other.game.into_iter().chain(self.game).collect(), + log_dir: other.log_dir.or(self.log_dir), profile_dir: other.profile_dir.or(self.profile_dir), steam_dir: other.steam_dir.or(self.steam_dir), windows_binaries_dir: other.windows_binaries_dir.or(self.windows_binaries_dir), diff --git a/crates/mod-host-api/Cargo.toml b/crates/mod-host-api/Cargo.toml new file mode 100644 index 00000000..cb14a320 --- /dev/null +++ b/crates/mod-host-api/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "me3-mod-host-api" +version = "0.9.0" +edition.workspace = true +rust-version.workspace = true +repository.workspace = true +license.workspace = true + +[dependencies] +me3-launcher-attach-protocol.workspace = true +serde_json.workspace = true + +[lints] +workspace = true diff --git a/crates/mod-host-api/src/lib.rs b/crates/mod-host-api/src/lib.rs new file mode 100644 index 00000000..60db0f99 --- /dev/null +++ b/crates/mod-host-api/src/lib.rs @@ -0,0 +1,6 @@ +use me3_launcher_attach_protocol::AttachConfig; + +pub fn current_attach_config() -> Option { + let json_var = std::env::var("ME3_ATTACH_CONFIG").ok(); + json_var.map(|v| serde_json::from_str(&v).expect("mod host serialized invalid data")) +} diff --git a/crates/mod-host/src/lib.rs b/crates/mod-host/src/lib.rs index b495e130..5d38d2b6 100644 --- a/crates/mod-host/src/lib.rs +++ b/crates/mod-host/src/lib.rs @@ -70,6 +70,12 @@ fn on_attach(request: AttachRequest) -> AttachResult { me3_telemetry::install_error_handler(); let attach_config = Arc::new(request.config); + let attach_config_json = serde_json::to_string(&*attach_config)?; + + // SAFETY: only called on Windows + unsafe { + std::env::set_var("ME3_ATTACH_CONFIG", attach_config_json); + } let telemetry_vars: TelemetryVars = me3_env::deserialize_from_env()?;