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
use anyhow::Result;
use clap::{Parser, Subcommand};
use oliver::{DEFAULT_APP_DATA_DIR, Settings};
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 {
/// 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),
/// 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,
}
#[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 output file to pack the mod into.
#[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::Parse(Parse { paths, verbose }) => Settings::parse(paths, verbose),
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 main() -> ExitCode {
match run() {
Ok(()) => ExitCode::SUCCESS,
Err(e) => {
eprintln!("{e}");
ExitCode::FAILURE
}
}
}