diff --git a/Cargo.lock b/Cargo.lock index 87b5851..0dec543 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1053,7 +1053,7 @@ dependencies = [ [[package]] name = "native-plugin-lib" version = "0.1.0" -source = "git+https://github.com/MolotovCherry/Native-Plugin-Lib#0e9fb0739c7e42a8bfa559fef2a6b67040689e01" +source = "git+https://github.com/MolotovCherry/Native-Plugin-Lib#34c0b7eb18ea97cae6a7b0fb12cc1fe77b4862a0" dependencies = [ "eyre", "konst", diff --git a/assets-autostart/INSTRUCTIONS.txt b/assets-autostart/INSTRUCTIONS.txt index 9af51c7..c538992 100644 --- a/assets-autostart/INSTRUCTIONS.txt +++ b/assets-autostart/INSTRUCTIONS.txt @@ -50,37 +50,31 @@ together, including loader.dll. -------------------------- The first time you run a tool, it will: - - Generate a config.toml for you - - Check the `config.toml` file inside - `C:\Users\\AppData\Local\Larian Studios\Baldur's Gate 3\Plugins` - - If the game was installed to a non-standard path, you must adjust this path - to correct it. It needs to point to the game's root installation directory. - E.g. `C:\Program Files (x86)\Steam\steamapps\common\Baldurs Gate 3` - - If the tools are placed in /bin or /bin/subfolder, they - will detect the install root automatically, and install_root in config.toml - won't require configuring. - - Place any dll plugins you have inside - `C:\Users\\AppData\Local\Larian Studios\Baldur's Gate 3\Plugins` - - Remember, all NativeModLoader plugins are compatible! + - Generate a config.toml for you + - Check the `config.toml` file inside + `C:\Users\\AppData\Local\Larian Studios\Baldur's Gate 3\Plugins` + - If the game was installed to a non-standard path, you must adjust this path + to correct it. It needs to point to the game's root installation directory. + E.g. `C:\Program Files (x86)\Steam\steamapps\common\Baldurs Gate 3` + - If the tools are placed in /bin or /bin/subfolder, they + will detect the install root automatically, and install_root in config.toml + won't require configuring. + - Place any dll plugins you have inside + `C:\Users\\AppData\Local\Larian Studios\Baldur's Gate 3\Plugins` + - Remember, all NativeModLoader plugins are compatible! Using: - 1. Run your game as normal. It will automatically be patched. + 1. Run your game as normal. It will automatically be patched. -The `disabled` key accepts a boolean or array of strings. - - The array allows you to disable specific plugins with just the filename (no - extension). For example, if you have `FooBar.dll` and `FooBaz.dll` plugins, - they can be disabled with: - disabled = ["FooBar", "FooBaz"] +Disabling: + To disable a specific plugin, either move/delete the plugin dll, or set the + `[core]disabled` key to an array of plugin filenames (no extension). For example, + if you have `FooBar.dll` and `FooBaz.dll` plugins, they can be disabled with: + disabled = ["FooBar", "FooBaz"] - - If you want to globally disable plugins, you can use a boolean, or uninstall - the autostart tool: - disabled = true - -If you wish to disable a mod, add an entry without extension to the `disabled` key - - - If you wish to disable all plugins, either uninstall autostart tool, and then start - the game normally as you always do, or set the disabled key to: - disabled = true + To globally disable plugins, set the `[core]enabled` key to false, or uninstall + the autostart tool: + enabled = false Source code: https://github.com/MolotovCherry/Yet-Another-BG3-Native-Mod-Loader diff --git a/assets-injector/INSTRUCTIONS.txt b/assets-injector/INSTRUCTIONS.txt index 32ce6bc..60cd4ef 100644 --- a/assets-injector/INSTRUCTIONS.txt +++ b/assets-injector/INSTRUCTIONS.txt @@ -54,15 +54,15 @@ Using: starting the injector tool first, then the game after to fix this. As long as you start the game within 10 seconds, it'll work. -The `disabled` key accepts a boolean or array of strings. - - The array allows you to disable specific plugins with just the filename (no - extension). For example, if you have `FooBar.dll` and `FooBaz.dll` plugins, - they can be disabled with: - disabled = ["FooBar", "FooBaz"] +Disabling: + To disable a specific plugin, either move/delete the plugin dll, or set the + `[core]disabled` key to an array of plugin filenames (no extension). For example, + if you have `FooBar.dll` and `FooBaz.dll` plugins, they can be disabled with: + disabled = ["FooBar", "FooBaz"] - - If you want to globally disable plugins, you can use a boolean, or simply - don't start the injector tool: - disabled = true + To globally disable plugins, set the `[core]enabled` key to false, or simply + don't start the injector tool: + enabled = false Source code: https://github.com/MolotovCherry/Yet-Another-BG3-Native-Mod-Loader diff --git a/assets-watcher/INSTRUCTIONS.txt b/assets-watcher/INSTRUCTIONS.txt index 8ef9f80..7ae6c21 100644 --- a/assets-watcher/INSTRUCTIONS.txt +++ b/assets-watcher/INSTRUCTIONS.txt @@ -49,15 +49,15 @@ Using: 1. Run the watcher tool 2. When the game launches, it will auto-patch the game instance -The `disabled` key accepts a boolean or array of strings. - - The array allows you to disable specific plugins with just the filename (no - extension). For example, if you have `FooBar.dll` and `FooBaz.dll` plugins, - they can be disabled with: - disabled = ["FooBar", "FooBaz"] +Disabling: + To disable a specific plugin, either move/delete the plugin dll, or set the + `[core]disabled` key to an array of plugin filenames (no extension). For example, + if you have `FooBar.dll` and `FooBaz.dll` plugins, they can be disabled with: + disabled = ["FooBar", "FooBaz"] - - If you want to globally disable plugins, you can use a boolean, or simply - don't start the watcher tool: - disabled = true + To globally disable plugins, set the `[core]enabled` key to false, or simply + don't start the watcher tool: + enabled = false Source code: https://github.com/MolotovCherry/Yet-Another-BG3-Native-Mod-Loader diff --git a/crates/loader/src/loader.rs b/crates/loader/src/loader.rs index 393d08c..88bdc00 100644 --- a/crates/loader/src/loader.rs +++ b/crates/loader/src/loader.rs @@ -20,7 +20,7 @@ pub fn load_plugins() -> Result<()> { let plugins_dir = get_bg3_plugins_dir()?; let config = get_config()?; - if config.core.disabled.is_global_disabled() { + if !config.core.enabled { info!("Plugins are globally disabled. If you want to re-enable them, set [core]disabled in config.toml to false or []"); return Ok(()); } @@ -71,6 +71,7 @@ pub fn load_plugins() -> Result<()> { let name_formatted = { let data = native_plugin_lib::get_plugin_data(&path); + match data { Ok(guard) => { let data = guard.data(); @@ -91,9 +92,7 @@ pub fn load_plugins() -> Result<()> { } }; - let is_disabled = config.core.disabled.is_disabled(name); - - if is_disabled { + if config.core.is_plugin_disabled(name) { info!("Skipping disabled plugin {name_formatted}"); continue; } diff --git a/crates/shared/src/config.rs b/crates/shared/src/config.rs index 23be803..e9f0c7c 100644 --- a/crates/shared/src/config.rs +++ b/crates/shared/src/config.rs @@ -18,14 +18,16 @@ pub struct Config { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(default)] pub struct Core { + /// Whether plugins are globally enabled or not + pub enabled: bool, /// The game's root installation directory, /// e.g. C:\Program Files (x86)\Steam\steamapps\common\Baldurs Gate 3 pub install_root: PathBuf, - /// Whether to globally disable or which plugins to disable. + /// Which plugins to disable. /// Each entry is the plugins filename without extension /// Except for those in this list, all plugins are enabled by default /// e.g. FooBar.dll should have an entry for "FooBar" - pub disabled: Disabled, + pub disabled: Vec, /// Whether to show cli window pub cli: bool, } @@ -33,43 +35,19 @@ pub struct Core { impl Default for Core { fn default() -> Self { Self { + enabled: true, // the default location for most people install_root: r"C:\Program Files (x86)\Steam\steamapps\common\Baldurs Gate 3".into(), - disabled: Disabled::Global(false), + disabled: Vec::new(), cli: false, } } } -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(untagged)] -pub enum Disabled { - Plugins(Vec), - Global(bool), -} - -impl Default for Disabled { - fn default() -> Self { - Self::Global(false) - } -} - -impl Disabled { - #[inline] - pub fn is_global_disabled(&self) -> bool { - matches!(self, Self::Global(true)) - } - - #[inline] - pub fn is_disabled(&self, name: &str) -> bool { - match self { - Disabled::Plugins(plugins) => { - let name = UniCase::new(name); - plugins.iter().any(|p| UniCase::new(p) == name) - } - - Disabled::Global(d) => *d, - } +impl Core { + pub fn is_plugin_disabled(&self, name: &str) -> bool { + let name = UniCase::new(name); + self.disabled.iter().any(|p| UniCase::new(p) == name) } } diff --git a/crates/yabg3nml/src/loader.rs b/crates/yabg3nml/src/loader.rs index 5545b7d..5f301f6 100644 --- a/crates/yabg3nml/src/loader.rs +++ b/crates/yabg3nml/src/loader.rs @@ -49,7 +49,7 @@ pub fn run_loader( dirty_check: bool, wait_for_init: bool, ) -> Result<()> { - if config.core.disabled.is_global_disabled() { + if !config.core.enabled { info!("Plugins are globally disabled. If you want to re-enable them, set [core]disabled in config.toml to false or []"); return Ok(()); }