Skip to content

Commit

Permalink
Separate enabled key into separate key
Browse files Browse the repository at this point in the history
  • Loading branch information
MolotovCherry committed Nov 17, 2024
1 parent ed42c60 commit 5c0bf1c
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 81 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 21 additions & 27 deletions assets-autostart/INSTRUCTIONS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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\<user>\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 <bg3_root>/bin or <bg3_root>/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\<user>\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\<user>\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 <bg3_root>/bin or <bg3_root>/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\<user>\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

Expand Down
16 changes: 8 additions & 8 deletions assets-injector/INSTRUCTIONS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 8 additions & 8 deletions assets-watcher/INSTRUCTIONS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 3 additions & 4 deletions crates/loader/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
}
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}
Expand Down
42 changes: 10 additions & 32 deletions crates/shared/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,58 +18,36 @@ 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<String>,
/// Whether to show cli window
pub cli: bool,
}

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<String>),
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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/yabg3nml/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
}
Expand Down

0 comments on commit 5c0bf1c

Please sign in to comment.