1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
use anyhow::Result;
use clap::{Parser, Subcommand};
use larian_formats::bg3::ModuleInfo;
use oliver::{Settings, DEFAULT_APP_DATA_DIR};
use std::{path::PathBuf, process::ExitCode};
#[derive(Debug, Parser)]
#[command(arg_required_else_help(true), author, version, about)]
struct Cli {
#[clap(subcommand)]
command: Command,
}
#[derive(Debug, Subcommand)]
enum Command {
/// Prints the raw XML contents of a mod file.
Dump(Dump),
/// Exports the currently installed mods and the mod order to single compressed file.
Export(Export),
/// Imports the mods from compressed file.
Import(Import),
/// Install one or more mods.
Install(Install),
/// List all mods currently installed use.
List(List),
/// Pack loose mod files into an archive loadable by the game.
Pack(Pack),
/// Print a summary of the contents in a given file.
Parse(Parse),
/// Uninstall one or more mods.
Uninstall(Uninstall),
/// Unpacks all of the files contained in a mod.
Unpack(Unpack),
}
#[derive(Debug, Parser)]
struct Dump {
/// Path to the file to dump.
///
/// The file must be either a .pak format in the LSPK format.
#[clap()]
path: PathBuf,
}
#[derive(Debug, Parser)]
struct Export {
#[clap(flatten)]
app_data_path: AppDataPath,
/// The file where the exported mod data should be written.
#[clap()]
destination: PathBuf,
}
#[derive(Debug, Parser)]
struct Import {
#[clap(flatten)]
app_data_path: AppDataPath,
/// The file where the exported mod data should be read.
#[clap()]
source: PathBuf,
}
#[derive(Debug, Parser)]
struct List {
#[clap(flatten)]
app_data_path: AppDataPath,
/// Indicate the order that the mods will be loaded by the game.
#[clap(long, short)]
order: bool,
}
#[derive(Debug, Parser)]
#[command(arg_required_else_help(true))]
struct Parse {
/// Paths to the files to summarize.
///
/// Each file must be either a .pak format in the LSPK format or a .lsf file.
#[clap()]
paths: Vec<PathBuf>,
/// Print extra information.
#[clap(long, short)]
verbose: bool,
}
#[derive(Debug, Parser)]
#[command(arg_required_else_help(true))]
struct Install {
/// Print extra information.
#[clap(long, short)]
verbose: bool,
/// Don't perform any actions, but validate whether command would succeed or not.
///
/// If `--verbose` is also specified, invoking with `--dry-run` will indicate the version of
/// any successfully updated addon.
#[clap(long, short = 'n')]
dry_run: bool,
/// Reinstall even if the same version is already installed.
#[clap(long, short)]
refresh: bool,
#[clap(flatten)]
app_data_path: AppDataPath,
/// Paths to the mod files to install. By default, this will only install mods if the version
/// is newer than the currently installed version (if any exists).
///
/// The mod file can be either a `.pak` file or a zip file containing a `.pak`.
#[clap()]
mod_file_paths: Vec<String>,
}
#[derive(Debug, Parser)]
#[command(arg_required_else_help(true))]
struct Uninstall {
/// Don't perform any actions, but validate whether command would succeed or not.
#[clap(long, short = 'n')]
dry_run: bool,
#[clap(flatten)]
app_data_path: AppDataPath,
/// Indexes of the mods in the order to uninstall.
#[clap()]
mod_indexes: Vec<usize>,
}
#[derive(Debug, Parser)]
#[command(arg_required_else_help(true))]
struct Pack {
/// Path to the directory containing loose mod files to pack.
#[clap()]
mod_files_root: PathBuf,
/// The name of the mod file to output.
///
/// If this is not specified, oliver will try to infer the name based on the location of the
/// meta.lsx file in the `Mods/` directory.
#[clap(long, short)]
destination: Option<PathBuf>,
}
#[derive(Debug, Parser)]
#[command(arg_required_else_help(true))]
struct Unpack {
/// The mod file to unpack.
#[clap()]
mod_file_path: PathBuf,
/// The directory to unpack the mod into.
#[clap(long, short)]
destination: Option<PathBuf>,
}
#[derive(Debug, Parser)]
struct AppDataPath {
/// Path to the `AppData` folder that contains the installation.
///
/// If you're not using Steam, this will likely be in your Wine prefix under
/// `drive_c/users/<username>/AppData`, where `<username>` is the name of your user.
///
/// This directory is expected to contain the file `modsettings.lsx` in the relative path
/// `Local/Larian Studios/Baldur's Gate 3/PlayerProfiles/Public/`.
#[clap(
long,
default_value_t = DEFAULT_APP_DATA_DIR.into()
)]
app_data_path: String,
}
fn run() -> Result<()> {
static_assertions_next::assert_cfg!(
target_os = "linux",
format!(
"This tool currently only supports Linux. If you're interested in using this on \
another platform, feel free to let me know by filing an issue at {}!",
env!("CARGO_PKG_REPOSTIORY")
)
);
match Cli::parse().command {
Command::Install(Install {
verbose,
dry_run,
refresh,
mod_file_paths,
app_data_path,
}) => Settings::with_app_data_dir(&app_data_path.app_data_path).install_all(
verbose,
dry_run,
refresh,
mod_file_paths,
),
Command::List(List {
order,
app_data_path,
}) => {
let settings = Settings::with_app_data_dir(&app_data_path.app_data_path);
if order {
print_ordered_mods(&settings)
} else {
print_unordered_mods(&settings)
}
}
Command::Parse(Parse { paths, verbose }) => Settings::parse(paths, verbose),
Command::Export(Export {
app_data_path,
destination,
}) => Settings::with_app_data_dir(&app_data_path.app_data_path).export(&destination),
Command::Import(Import {
app_data_path,
source,
}) => Settings::with_app_data_dir(&app_data_path.app_data_path).import(&source),
Command::Uninstall(Uninstall {
dry_run,
app_data_path,
mod_indexes,
}) => Settings::with_app_data_dir(&app_data_path.app_data_path)
.uninstall_all(dry_run, mod_indexes),
Command::Dump(Dump { path }) => Settings::dump(path),
Command::Pack(Pack {
mod_files_root,
destination,
}) => Settings::pack(mod_files_root, destination),
Command::Unpack(Unpack {
mod_file_path,
destination,
}) => Settings::unpack(mod_file_path, destination),
}
}
fn print_unordered_mods(settings: &Settings) -> Result<()> {
for ModuleInfo { name, uuid, .. } in settings.get_installed_mod_info()?.iter() {
println!("{uuid}: {name}");
}
Ok(())
}
fn print_ordered_mods(settings: &Settings) -> Result<()> {
let ordered_mods = settings.get_load_order()?;
let padding = ordered_mods
.order_len()
.checked_ilog10()
.and_then(|i| usize::try_from(i + 1).ok())
.unwrap_or_default();
for (i, info) in ordered_mods.ordered().enumerate() {
let ModuleInfo { name, uuid, .. } = info;
println!("{i:>padding$}. {uuid}: {name}");
}
if ordered_mods.has_extras() {
println!("\nMods not present in load order:");
for ModuleInfo { name, uuid, .. } in ordered_mods.extras() {
println!("?. {uuid} {name}");
}
}
Ok(())
}
fn main() -> ExitCode {
match run() {
Ok(()) => ExitCode::SUCCESS,
Err(e) => {
eprintln!("{e}");
ExitCode::FAILURE
}
}
}