@@ -1,150 +1,152 @@
|
||||
# Helldivers 2 Mod Manager CLI
|
||||
|
||||
Helldivers 2 Mod Manager CLI is a command line interface for managing Helldivers 2 mods. Since there is no Linux mod manager available and I like being a nerd by using CLI tools instead of GUIs, this project was born.
|
||||
|
||||
- [Helldivers 2 Mod Manager CLI](#helldivers-2-mod-manager-cli)
|
||||
- [Installation](#installation)
|
||||
- [Usage](#usage)
|
||||
- [Available commands](#available-commands)
|
||||
- [Basic usage](#basic-usage)
|
||||
- [Install a mod](#install-a-mod)
|
||||
- [Uninstall a mod](#uninstall-a-mod)
|
||||
- [Enable/disable mods](#enabledisable-mods)
|
||||
- [List installed mods](#list-installed-mods)
|
||||
- [Compatibility](#compatibility)
|
||||
- [Advanced usage](#advanced-usage)
|
||||
- [Shortcuts](#shortcuts)
|
||||
- [Exporting and importing](#exporting-and-importing)
|
||||
- [Resetting all installed mods](#resetting-all-installed-mods)
|
||||
- [Database location and details](#database-location-and-details)
|
||||
- [Contributing](#contributing)
|
||||
- [Planned features](#planned-features)
|
||||
|
||||
## Installation
|
||||
|
||||
To install/update Helldivers 2 Mod Manager CLI run the following command in your terminal:
|
||||
|
||||
```bash
|
||||
bash -c "$(curl -fsSL https://raw.githubusercontent.com/v4n00/h2mm-cli/refs/heads/master/install.sh)"
|
||||
```
|
||||
|
||||
Running this script will require sudo permissions. **DO NOT TRUST** random scripts from the internet. If you want to review the script before running it, check out the mod repository for yourself.
|
||||
|
||||
## Usage
|
||||
|
||||
The script gets added to `/usr/local/bin/h2mm` and can be used by running `h2mm` in your shell, which will show the help message explaining how to use the script.
|
||||
|
||||
```bash
|
||||
h2mm
|
||||
```
|
||||
|
||||
### Available commands
|
||||
|
||||
- `install` - Install a mod with files
|
||||
- `uninstall` - Uninstall a mod by name
|
||||
- `list` - List all installed mods
|
||||
- `enable` - Enable a mod by name
|
||||
- `disable` - Disable a mod by name
|
||||
- `export` - Export installed mods to a zip file
|
||||
- `import` - Import mods from a zip file
|
||||
- `reset` - Reset all installed mods
|
||||
- `help` - Display the help message
|
||||
|
||||
### Basic usage
|
||||
|
||||
#### Install a mod
|
||||
|
||||
```bash
|
||||
h2mm install /path/to/mod.zip
|
||||
h2mm install /path/to/mod/files
|
||||
h2mm install -n "Example mod" mod.patch_0 mod.patch_0.stream # -n is mandatory when using files
|
||||
h2mm install -n "Example mod" mod* # using a wildcard to include all files
|
||||
```
|
||||
|
||||
> Currently, if the mod has more than 1 variant, you need to install the one you want by unarchiving it separately.
|
||||
|
||||
#### Uninstall a mod
|
||||
|
||||
```bash
|
||||
h2mm uninstall "Example mod"
|
||||
h2mm uninstall -i 1 # uninstall mod with index 1
|
||||
```
|
||||
|
||||
#### Enable/disable mods
|
||||
|
||||
```bash
|
||||
h2mm enable "Example mod"
|
||||
h2mm enable -i 1 # enable mod with index 1
|
||||
h2mm disable "Example mod"
|
||||
h2mm disable -i 1 # disable mod with index 1
|
||||
```
|
||||
|
||||
#### List installed mods
|
||||
|
||||
```bash
|
||||
h2mm list
|
||||
```
|
||||
|
||||
## Compatibility
|
||||
|
||||
The script is developed and tested on Arch Linux, but it should work on other Linux distributions as well. If you encounter any issues, please open an issue on the repository.
|
||||
|
||||
Status of other platforms:
|
||||
|
||||
- Linux :white_check_mark:
|
||||
- Steam Deck - untested (should work) :grey_question:
|
||||
- WSL :white_check_mark:
|
||||
|
||||
> The script works on WSL, but you need to specify the path to the Helldivers 2 mods directory manually, to find your Windows partition head to `/mnt/` and from there go to your Helldivers 2 data directory, on a typical install it should be on `/mnt/c/Program\ Files\ \(x86\)/Steam/steamapps/common/Helldivers\ 2/data`. You also need to have `unzip` installed, which can be done by running `sudo apt install unzip`.
|
||||
|
||||
## Advanced usage
|
||||
|
||||
### Shortcuts
|
||||
|
||||
You can use the short form of commands to save some time. The shortcuts are:
|
||||
|
||||
- `i` for `install`
|
||||
- `u` for `uninstall`
|
||||
- `e` for `enable`
|
||||
- `d` for `disable`
|
||||
- `l` for `list`
|
||||
- `ex` for `export`
|
||||
- `im` for `import`
|
||||
- `r` for `reset`
|
||||
|
||||
### Exporting and importing
|
||||
|
||||
You can export all installed mods to a zip file and import mods from the same file. This can be useful for sharing mods with others or for backing up your mods. The zip file will be saved in the current directory.
|
||||
|
||||
```bash
|
||||
h2mm export modpack1.zip
|
||||
h2mm import modpack2.zip
|
||||
```
|
||||
|
||||
### Resetting all installed mods
|
||||
|
||||
You can reset all installed mods by running the following command. This will remove all installed mods and the database, in case things go wild.
|
||||
|
||||
```bash
|
||||
h2mm reset
|
||||
```
|
||||
|
||||
### Database location and details
|
||||
|
||||
The database is stored in the `Helldivers 2` install directory, under the `data` folder with the name `mods.csv`, where the mods are also installed. The database is a simple CSV file which you can use to manually manage mods if needed, you can mostly use it to rename or reorder mods.
|
||||
|
||||
## Contributing
|
||||
|
||||
Feel free to contribute to this project by creating a pull request or opening an issue.
|
||||
|
||||
## Planned features
|
||||
|
||||
- [x] Check for mod updates
|
||||
- [x] Enable/disable mods
|
||||
- [ ] Install mods in batches
|
||||
- [ ] Easier way to change mod presets
|
||||
- [ ] Find a way to make use of `manifest.json` and simplify installing variants
|
||||
- [x] [DEV] Change to `.tar.gz` for exporting and importing
|
||||
- [x] [DEV] Provide fixes for breaking updates
|
||||
- [ ] [DEV] Optimize code - throw errors in 1 line
|
||||
- [ ] [DEV] Rewrite some code to be more readable
|
||||
# Helldivers 2 Mod Manager CLI
|
||||
|
||||
Helldivers 2 Mod Manager CLI is a command line interface for managing Helldivers 2 mods. Since there is no Linux mod manager available and I like being a nerd by using CLI tools instead of GUIs, this project was born.
|
||||
|
||||
- [Helldivers 2 Mod Manager CLI](#helldivers-2-mod-manager-cli)
|
||||
- [Installation](#installation)
|
||||
- [Usage](#usage)
|
||||
- [Available commands](#available-commands)
|
||||
- [Basic usage](#basic-usage)
|
||||
- [Install mod(s)](#install-mods)
|
||||
- [Uninstall a mod](#uninstall-a-mod)
|
||||
- [Enable/disable mods](#enabledisable-mods)
|
||||
- [List installed mods](#list-installed-mods)
|
||||
- [Compatibility](#compatibility)
|
||||
- [Advanced usage](#advanced-usage)
|
||||
- [Shortcuts](#shortcuts)
|
||||
- [Exporting and importing](#exporting-and-importing)
|
||||
- [Resetting all installed mods](#resetting-all-installed-mods)
|
||||
- [Database location and details](#database-location-and-details)
|
||||
- [Contributing](#contributing)
|
||||
- [Planned features](#planned-features)
|
||||
|
||||
## Installation
|
||||
|
||||
To install/update Helldivers 2 Mod Manager CLI run the following command in your terminal:
|
||||
|
||||
```bash
|
||||
bash -c "$(curl -fsSL https://raw.githubusercontent.com/v4n00/h2mm-cli/refs/heads/master/install.sh)"
|
||||
```
|
||||
|
||||
Running this script will require sudo permissions. **DO NOT TRUST** random scripts from the internet. If you want to review the script before running it, check out the mod repository for yourself.
|
||||
|
||||
## Usage
|
||||
|
||||
The script gets added to `/usr/local/bin/h2mm` and can be used by running `h2mm` in your shell, which will show the help message explaining how to use the script.
|
||||
|
||||
```bash
|
||||
h2mm
|
||||
```
|
||||
|
||||
### Available commands
|
||||
|
||||
- `install` - Install a mod with files
|
||||
- `uninstall` - Uninstall a mod by name
|
||||
- `list` - List all installed mods
|
||||
- `enable` - Enable a mod by name
|
||||
- `disable` - Disable a mod by name
|
||||
- `export` - Export installed mods to a zip file
|
||||
- `import` - Import mods from a zip file
|
||||
- `reset` - Reset all installed mods
|
||||
- `help` - Display the help message
|
||||
|
||||
### Basic usage
|
||||
|
||||
#### Install mod(s)
|
||||
|
||||
```bash
|
||||
h2mm install /path/to/mod.zip
|
||||
h2mm install /path/to/mod/files
|
||||
h2mm install /path/to/mod.zip /path/to/mod2.zip /path/to/mod/files
|
||||
h2mm install -n "Example mod" mod.patch_0 mod.patch_0.stream # -n is mandatory when using files
|
||||
h2mm install -n "Example mod" mod* # using a wildcard to include all files
|
||||
```
|
||||
|
||||
> Currently, if the mod has more than 1 variant, you need to install the one you want by unarchiving it separately.
|
||||
|
||||
#### Uninstall a mod
|
||||
|
||||
```bash
|
||||
h2mm uninstall "Example mod"
|
||||
h2mm uninstall -i 1 # uninstall mod with index 1
|
||||
```
|
||||
|
||||
#### Enable/disable mods
|
||||
|
||||
```bash
|
||||
h2mm enable "Example mod"
|
||||
h2mm enable -i 1 # enable mod with index 1
|
||||
h2mm disable "Example mod"
|
||||
h2mm disable -i 1 # disable mod with index 1
|
||||
```
|
||||
|
||||
#### List installed mods
|
||||
|
||||
```bash
|
||||
h2mm list
|
||||
```
|
||||
|
||||
## Compatibility
|
||||
|
||||
The script is developed and tested on Arch Linux, but it should work on other Linux distributions as well. If you encounter any issues, please open an issue on the repository.
|
||||
|
||||
Status of platforms:
|
||||
|
||||
- Linux :white_check_mark:
|
||||
- Steam Deck - untested (should work) :grey_question:
|
||||
- WSL :white_check_mark:
|
||||
|
||||
> The script works on WSL, but you need to specify the path to the Helldivers 2 mods directory manually, to find your Windows partition head to `/mnt/` and from there go to your Helldivers 2 data directory, on a typical install it should be on `/mnt/c/Program\ Files\ \(x86\)/Steam/steamapps/common/Helldivers\ 2/data`. You also need to have `unzip` installed, which can be done by running `sudo apt install unzip`.
|
||||
|
||||
## Advanced usage
|
||||
|
||||
### Shortcuts
|
||||
|
||||
You can use the short form of commands to save some time. The shortcuts are:
|
||||
|
||||
- `i` for `install`
|
||||
- `u` for `uninstall`
|
||||
- `e` for `enable`
|
||||
- `d` for `disable`
|
||||
- `l` for `list`
|
||||
- `ex` for `export`
|
||||
- `im` for `import`
|
||||
- `r` for `reset`
|
||||
|
||||
### Exporting and importing
|
||||
|
||||
You can export all installed mods to a zip file and import mods from the same file. This can be useful for sharing mods with others or for backing up your mods. The zip file will be saved in the current directory.
|
||||
|
||||
```bash
|
||||
h2mm export modpack1.zip
|
||||
h2mm import modpack2.zip
|
||||
```
|
||||
|
||||
### Resetting all installed mods
|
||||
|
||||
You can reset all installed mods by running the following command. This will remove all installed mods and the database, in case things go wild.
|
||||
|
||||
```bash
|
||||
h2mm reset
|
||||
```
|
||||
|
||||
### Database location and details
|
||||
|
||||
The database is stored in the `Helldivers 2` install directory, under the `data` folder with the name `mods.csv`, where the mods are also installed. The database is a simple CSV file which you can use to manually manage mods if needed, you can mostly use it to rename or reorder mods.
|
||||
|
||||
## Contributing
|
||||
|
||||
Feel free to contribute to this project by creating a pull request or opening an issue.
|
||||
|
||||
## Planned features
|
||||
|
||||
- [x] Check for mod updates
|
||||
- [x] Enable/disable mods
|
||||
- [x] Install mods in batches
|
||||
- [ ] Easier way to change mod presets
|
||||
- [ ] Find a way to make use of `manifest.json` and simplify installing variants
|
||||
- [x] [DEV] Change to `.tar.gz` for exporting and importing
|
||||
- [x] [DEV] Provide fixes for breaking updates
|
||||
- [x] [DEV] Optimize code - throw errors in 1 line
|
||||
- [ ] [DEV] Import/export treat breaking changes
|
||||
- [ ] [DEV] Rewrite some code to be more readable
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
VERSION="0.2.2"
|
||||
VERSION="0.2.4"
|
||||
|
||||
# --- Globals ---
|
||||
|
||||
@@ -20,19 +20,23 @@ REPO_URL="https://github.com/v4n00/h2mm-cli"
|
||||
# --- Utility Functions ---
|
||||
|
||||
function get_filename_without_path() {
|
||||
echo $(echo "$1" | awk -F/ '{print $NF}')
|
||||
echo "$1" | awk -F/ '{print $NF}'
|
||||
}
|
||||
|
||||
function get_basename() {
|
||||
echo $(get_filename_without_path "$1" | sed -E 's/\.+.*//')
|
||||
get_filename_without_path "$1" | sed -E 's/\.+.*//'
|
||||
}
|
||||
|
||||
function get_basename_with_patch_without_extension() {
|
||||
echo "$1" | sed -E "s/(.*[0-9]+).*/\1/"
|
||||
}
|
||||
|
||||
function get_extension() {
|
||||
echo $(get_filename_without_path "$1" | sed -E 's/.*patch_[0-9]+//')
|
||||
get_filename_without_path "$1" | sed -E 's/.*patch_[0-9]+//'
|
||||
}
|
||||
|
||||
function get_files_by_entry_from_db() {
|
||||
echo $(echo "$1" | cut -d',' -f4- | tr ',' ' ' | head -1)
|
||||
echo "$1" | cut -d',' -f4- | tr ',' ' ' | head -1
|
||||
}
|
||||
|
||||
function get_mod_name_and_index() {
|
||||
@@ -136,11 +140,12 @@ function display_install_help() {
|
||||
echo "Options:"
|
||||
echo " -n \"<mod_name>\" Name the mod yourself, inside double quotes."
|
||||
echo " <mod_files> Multiple mod files, accepts wildcards."
|
||||
echo " <mod_dir> Directory containing mod files."
|
||||
echo " <mod_zip> Zip file containing mod files."
|
||||
echo " <mod_dirs> Directory/directories containing mod files."
|
||||
echo " <mod_zips> Zip file(s) containing mod files."
|
||||
echo "Usage:"
|
||||
echo " h2mm install /path/to/mod.zip"
|
||||
echo " h2mm install /path/to/mod/files"
|
||||
echo " h2mm install /path/to/mod.zip /path/to/mod2.zip /path/to/mod/files"
|
||||
echo " h2mm install -n \"Example mod\" mod.patch_0 mod.patch_0.stream # -n is mandatory when using files"
|
||||
echo " h2mm install -n \"Example mod\" mod* # using a wildcard to include all files"
|
||||
echo "If the mod has more than 1 variant, you need to install the one you want by unarchiving it separately."
|
||||
@@ -368,8 +373,9 @@ function mod_reset() {
|
||||
|
||||
function mod_install() {
|
||||
local mod_name=""
|
||||
local mod_dir=""
|
||||
local mod_dir=()
|
||||
local mod_files=()
|
||||
local mod_zip=()
|
||||
|
||||
[[ $# -eq 0 ]] && { display_install_help; exit 0; }
|
||||
|
||||
@@ -384,9 +390,9 @@ function mod_install() {
|
||||
;;
|
||||
*)
|
||||
if [[ -f "$1" && "$1" == *.zip ]]; then
|
||||
mod_zip="$1"
|
||||
mod_zip+=("$1")
|
||||
elif [[ -d "$1" ]]; then
|
||||
mod_dir="$1"
|
||||
mod_dir+=("$1")
|
||||
else
|
||||
mod_files+=("$1")
|
||||
fi
|
||||
@@ -395,27 +401,55 @@ function mod_install() {
|
||||
esac
|
||||
done
|
||||
|
||||
# zip file containing mod files
|
||||
# edge case when there is a combination of mod zips and directories, call function for all zips and dirs
|
||||
if [[ ${mod_zip} && ${mod_dir} ]]; then
|
||||
mod_install "${mod_zip[@]}"
|
||||
mod_install "${mod_dir[@]}"
|
||||
|
||||
# reset arrays
|
||||
mod_zip=()
|
||||
mod_dir=()
|
||||
|
||||
# if there are no more arguments, exit
|
||||
[[ ${#mod_files[@]} -eq 0 ]] && exit 0
|
||||
fi
|
||||
|
||||
# if there's more than 1 zip, call recursively
|
||||
while [[ ${#mod_zip[@]} -gt 1 ]]; do
|
||||
mod_install "${mod_zip[0]}"
|
||||
mod_zip=("${mod_zip[@]:1}")
|
||||
done
|
||||
|
||||
# extract the zip file and pass it to mod dirs
|
||||
if [[ -n "$mod_zip" ]]; then
|
||||
command -v unzip &> /dev/null || { echo -e "${RED}Error${NC}: unzip package is not installed." >&2; exit 1; }
|
||||
|
||||
[[ ! -f "$mod_zip" ]] && { echo -e "${RED}Error${NC}: Zip file $mod_zip does not exist." >&2; exit 1; }
|
||||
|
||||
# check if mod name was provided, otherwise use the zip file name, get rid of .zip and version numbers
|
||||
# if the name is not specified, use the name of the directory, last sed for making nexusmods names not have numbers
|
||||
if [[ -z "$mod_name" ]]; then
|
||||
mod_name=$(basename "$mod_zip" | sed -E 's/\.zip//' | awk -F/ '{print $NF}' | sed -E 's/-[0-9]+-.*//')
|
||||
fi
|
||||
|
||||
mod_dir=$(mktemp -d)
|
||||
# mod_dir as a temporary directory
|
||||
mod_dir+=$(mktemp -d)
|
||||
unzip -qq "$mod_zip" -d "$mod_dir"
|
||||
fi
|
||||
|
||||
# if there's more than 1 directory, call recursively
|
||||
while [[ ${#mod_dir[@]} -gt 1 ]]; do
|
||||
mod_install "${mod_dir[0]}"
|
||||
mod_dir=("${mod_dir[@]:1}")
|
||||
done
|
||||
|
||||
# directory containing mod files
|
||||
if [[ -n "$mod_dir" ]]; then
|
||||
# verify directory exists
|
||||
[[ ! -d "$mod_dir" ]] && { echo -e "${RED}Error${NC}: Directory $mod_dir does not exist." >&2; exit 1; }
|
||||
|
||||
# read every file from the directory
|
||||
readarray -d '' mod_files < <(find "$mod_dir" -type f -name "*.patch_*" -print0)
|
||||
# if the name is not specified, use the name of the directory, last sed for making nexusmods names not have numbers
|
||||
if [[ -z "$mod_name" ]]; then
|
||||
mod_name=$(echo "$mod_dir" | sed 's:/*$::' | awk -F/ '{print $NF}' | sed -E 's/-[0-9]+-.*//')
|
||||
fi
|
||||
@@ -424,14 +458,9 @@ function mod_install() {
|
||||
# verify minimum information required
|
||||
[[ -z "$mod_name" || ${#mod_files[@]} -eq 0 ]] && { echo -e "${RED}Error${NC}: Mod name and files are required." >&2; exit 1; }
|
||||
|
||||
# verify mod files exist and is not directory
|
||||
# verify mod files exist
|
||||
for file in "${mod_files[@]}"; do
|
||||
if [[ ! -f "$file" ]]; then
|
||||
# if it isn't a file, check if it's a directory
|
||||
[[ ! -d "$file" ]] && { echo -e "${RED}Error${NC}: File $file does not exist." >&2; exit 1; }
|
||||
|
||||
mod_files=(${mod_files[@]/$file})
|
||||
fi
|
||||
[[ ! -f "$file" ]] && { echo -e "${RED}Error${NC}: Mod file $file does not exist." >&2; exit 1; }
|
||||
done
|
||||
|
||||
# hash table - in case multiple named files are needed for 1 mod install, store the patch count
|
||||
@@ -444,15 +473,17 @@ function mod_install() {
|
||||
for file in "${mod_files[@]}"; do
|
||||
base_name=$(get_basename "$file")
|
||||
patch_prefix="$MODS_DIR/${base_name}.patch_"
|
||||
count=$(ls "${patch_prefix}"* 2>/dev/null | grep -E '([0-9]+$)' 2>/dev/null | wc -l) # count installed patches
|
||||
# count already installed patches
|
||||
count=$(ls "${patch_prefix}"* 2>/dev/null | grep -E '([0-9]+$)' 2>/dev/null | wc -l)
|
||||
|
||||
# set patch count for file name
|
||||
# set patch count for file name if it doesn't exist yet
|
||||
if [[ -z "${patch_count[$file]+unset}" ]]; then
|
||||
patch_count["$file"]=$count
|
||||
fi
|
||||
# if the file has an extension (e.g. .stream, .gpu_resources), set the last patch number for the next step
|
||||
patch_count["$base_name"]=$count
|
||||
|
||||
# if the file has an extension, look for the last patch number and use that
|
||||
# if the file has an extension, look for the last patch number and use that, otherwise, the count will be wrong
|
||||
extension=$(get_extension "$file")
|
||||
if [[ -n "$extension" ]]; then
|
||||
target_file="${base_name}.patch_$((patch_count[$base_name] - 1))${extension}"
|
||||
@@ -495,56 +526,62 @@ function mod_uninstall() {
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z "$mod_name" && -z "$mod_index" ]]; then
|
||||
echo -e "${RED}Error${NC}: Mod name or index is required to uninstall." >&2
|
||||
exit 1
|
||||
fi
|
||||
[[ -z "$mod_name" && -z "$mod_index" ]] && { echo -e "${RED}Error${NC}: Mod name or index is required to uninstall." >&2; exit 1; }
|
||||
|
||||
# find mod files
|
||||
get_mod_name_and_index "$mod_name" "$mod_index"
|
||||
|
||||
# delete mod files
|
||||
files=$(get_files_by_entry_from_db "$entry")
|
||||
echo "$files"
|
||||
declare -A downgrades
|
||||
declare -A downgrades_versions
|
||||
declare -A downgrades_to_remove
|
||||
for file in $files; do
|
||||
if [[ ! -f "$MODS_DIR/$file" ]]; then
|
||||
echo -e "${RED}Error${NC}: Mod file $file does not exist." >&2
|
||||
exit 1
|
||||
else
|
||||
echo -e "Removing ${ORANGE}\$MODS_DIR/$file${NC}." >&2
|
||||
rm "$MODS_DIR/$file"
|
||||
[[ ! -f "$MODS_DIR/$file" ]] && { echo -e "${RED}Error${NC}: Mod file $file does not exist." >&2; exit 1; }
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo -e "${RED}Error${NC}: Could not remove mod file $file." >&2
|
||||
exit 1
|
||||
fi
|
||||
echo -e "Removing ${ORANGE}\$MODS_DIR/$file${NC}." >&2
|
||||
rm "$MODS_DIR/$file"
|
||||
|
||||
base_name=$(get_basename "$file")
|
||||
current_version=$(echo $file | grep -oP '(?<=patch_)\d+')
|
||||
downgrades["$base_name"]=$current_version
|
||||
fi
|
||||
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Could not remove mod file $file." >&2; exit 1; }
|
||||
|
||||
# save the basename for the files that were deleted into a hash table, so we can downgrade mods with greater version number
|
||||
# also depending on how many patches the mod has, we need to downgrade with more versions
|
||||
current_version=$(echo $file | grep -oP '(?<=patch_)\d+')
|
||||
base_name_with_patch=$(get_basename_with_patch_without_extension "$file")
|
||||
base_name=$(get_basename "$file")
|
||||
downgrades_versions["$base_name_with_patch"]=$current_version
|
||||
[[ -z "${downgrades_to_remove["$base_name"]+unset}" ]] && downgrades_to_remove["$base_name"]=$(echo $files | sed -E "s/(.*[0-9]+).*/\1/" | wc -l)
|
||||
done
|
||||
|
||||
# downgrade any necessary mods
|
||||
for file in "${!downgrades[@]}"; do
|
||||
# downgrade any necessary mods - it takes ~20 minutes to re-understand this code so I'm writing a comment here
|
||||
# for each base name, find all files that have the same base name, and are greater than the current version, and downgrade them
|
||||
# the downgrades_versions hash table stores the current version, so we can compare it with the version of the files
|
||||
# the downgrades_to_remove hash table stores the number of patches the mod has, so we can downgrade with more versions
|
||||
# for example, if we have:
|
||||
# mod 1: AAA.patch_0 AAA.patch_0.stream AAA.patch_1 AAA.patch_1.stream
|
||||
# mod 2: AAA.patch_2 AAA.patch_2.stream AAA.patch_3 AAA.patch_3.stream
|
||||
# mod 3: AAA.patch_4 AAA.patch_4.stream AAA.patch_5 AAA.patch_5.stream
|
||||
# if we remove mod 2, we need to downgrade mod 3 (which has version 4 and 5 > 3 (last patch removed)) by 2 versions,
|
||||
# the number 2 we get by counting the number of unique base names (without extensions like .stream, but with the .patch_[0-9]) in the files
|
||||
for base_name in "${!downgrades_to_remove[@]}"; do
|
||||
# find all files that have the same base name, and are greater than the current version, and downgrade them
|
||||
base_name=$(get_basename "$file")
|
||||
same_patches=$(ls "$MODS_DIR/${base_name}.patch_"* 2>/dev/null)
|
||||
IFS=$'\n' mods_to_remove=($(ls "$MODS_DIR/$base_name"* 2>/dev/null | sort -V)); unset IFS
|
||||
base_name_with_patch=$(get_basename_with_patch_without_extension "$file")
|
||||
|
||||
for patch in $same_patches; do
|
||||
patch=$(get_filename_without_path "$patch")
|
||||
patch_version=$(echo $patch | grep -oP '(?<=patch_)\d+')
|
||||
if [[ $patch_version -gt ${downgrades[$file]} ]]; then
|
||||
new_version=$((patch_version - downgrades[$base_name] - 1))
|
||||
extension=$(get_extension "$path")
|
||||
for mod in "${mods_to_remove[@]}"; do
|
||||
mod=$(get_filename_without_path "$mod")
|
||||
patch_version=$(echo $mod | grep -oP '(?<=patch_)\d+')
|
||||
if [[ $patch_version -gt ${downgrades_versions[$base_name_with_patch]} ]]; then
|
||||
new_version=$((patch_version - downgrades_to_remove["$base_name"] - 1))
|
||||
extension=$(get_extension "$mod")
|
||||
|
||||
new_patch="${base_name}.patch_${new_version}${extension}"
|
||||
mv "$MODS_DIR/$patch" "$MODS_DIR/$new_patch"
|
||||
echo -e "Downgraded ${ORANGE}$patch${NC} to ${GREEN}\$MODS_DIR/$new_patch${NC}." >&2
|
||||
mv "$MODS_DIR/$mod" "$MODS_DIR/$new_patch"
|
||||
|
||||
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Could not downgrade mod file $mod." >&2; exit 1; }
|
||||
echo -e "Downgraded ${ORANGE}$mod${NC} to ${GREEN}\$MODS_DIR/$new_patch${NC}." >&2
|
||||
|
||||
# save changes in database as well
|
||||
sed -i "s/$patch/$new_patch/" "$DB_FILE"
|
||||
sed -i "s/$mod/$new_patch/" "$DB_FILE"
|
||||
fi
|
||||
done
|
||||
done
|
||||
@@ -556,17 +593,12 @@ function mod_uninstall() {
|
||||
}
|
||||
|
||||
function mod_list() {
|
||||
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
||||
display_list_help
|
||||
exit 0
|
||||
fi
|
||||
[[ "$1" == "--help" || "$1" == "-h" ]] && { display_list_help; exit 0; }
|
||||
|
||||
if [[ ! -s "$DB_FILE" ]]; then
|
||||
echo "No mods installed."
|
||||
return
|
||||
fi
|
||||
[[ ! -s "$DB_FILE" ]] && { echo "No mods installed."; return; }
|
||||
|
||||
echo "Installed mods:" >&2
|
||||
|
||||
awk -v GREEN="$GREEN" -v RED="$RED" -v NC="$NC" -F, '{
|
||||
color = ($2 == "DISABLED") ? RED : GREEN;
|
||||
if (length($4) > 150) $4 = substr($4, 1, 147) "...";
|
||||
@@ -574,87 +606,66 @@ function mod_list() {
|
||||
}
|
||||
|
||||
function mod_export() {
|
||||
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
||||
display_export_help
|
||||
exit 0
|
||||
fi
|
||||
[[ "$1" == "--help" || "$1" == "-h" ]] && { display_export_help; exit 0; }
|
||||
|
||||
echo -ne "Archive file will be saved in the current directory ($(pwd)). Continue? (Y/n): "
|
||||
read -r confirm
|
||||
if [[ "$confirm" == "y" || "$confirm" == "Y" || "$confirm" = "" ]]; then
|
||||
# create a temporary directory to store the mods
|
||||
OUT_DIR=$(mktemp -d)
|
||||
MODS_EXPORT_DIR="$OUT_DIR/Helldivers 2 Mods"
|
||||
mkdir -p "$MODS_EXPORT_DIR"
|
||||
cp "$DB_FILE" "$MODS_EXPORT_DIR"
|
||||
|
||||
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Could not copy mods to target directory." >&2; exit 1; }
|
||||
|
||||
# copy all mod files to the export directory
|
||||
for file in $(ls "$MODS_DIR/" 2>/dev/null | grep -E 'patch_.*'); do
|
||||
cp "$MODS_DIR/$file" "$MODS_EXPORT_DIR"
|
||||
done
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo -e "${RED}Error${NC}: Could not export mods. Possibly because no mods are present." >&2
|
||||
exit 1
|
||||
fi
|
||||
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Could not export mods. Possibly because no mods are present." >&2; exit 1; }
|
||||
|
||||
# zip up the mods with the current date and time in the name
|
||||
current_path=$(pwd)
|
||||
archive_name="Helldivers_2_Mods_$(date +%Y-%m-%d_%H-%M-%S).tar.gz"
|
||||
tar -czf "$current_path/$archive_name" -C "$OUT_DIR" "Helldivers 2 Mods"
|
||||
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo -e "Mods exported to ${GREEN}$current_path/$archive_name${NC}." >&2
|
||||
else
|
||||
echo -e "${RED}Error${NC}: Failed to export mods." >&2
|
||||
fi
|
||||
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Failed to export mods." >&2; exit 1; }
|
||||
echo -e "Mods exported to ${GREEN}$current_path/$archive_name${NC}." >&2
|
||||
fi
|
||||
}
|
||||
|
||||
function mod_import() {
|
||||
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
||||
display_import_help
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ ! -f "$1" ]]; then
|
||||
echo -e "${RED}Error${NC}: File $1 does not exist." >&2
|
||||
exit 1
|
||||
fi
|
||||
[[ "$1" == "--help" || "$1" == "-h" ]] && { display_import_help; exit 0; }
|
||||
[[ ! -f "$1" ]] && { echo -e "${RED}Error${NC}: File $1 does not exist." >&2; exit 1; }
|
||||
|
||||
# reset mods before importing
|
||||
echo -e "Importing mods will ${RED}reset${NC} your mods." >&2
|
||||
mod_reset
|
||||
if [[ $? -eq 1 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
[[ $? -eq 1 ]] && exit 1
|
||||
|
||||
# extract in temp directory
|
||||
OUT_DIR=$(mktemp -d)
|
||||
tar -xzf "$1" -C "$OUT_DIR"
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo -e "${RED}Error${NC}: Could not import mods. Possibly because the zip file is invalid." >&2
|
||||
exit 1
|
||||
fi
|
||||
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Could not import mods. Possibly because the zip file is invalid." >&2; exit 1; }
|
||||
|
||||
MODS_EXPORT_DIR="$OUT_DIR/Helldivers 2 Mods"
|
||||
if [[ ! -d "$MODS_EXPORT_DIR" ]]; then
|
||||
echo -e "${RED}Error${NC}: Could not import mods. Possibly because the zip file is invalid." >&2
|
||||
exit 1
|
||||
fi
|
||||
[[ ! -d "$MODS_EXPORT_DIR" ]] && { echo -e "${RED}Error${NC}: Could not import mods. Possibly because the zip file is invalid." >&2; exit 1; }
|
||||
|
||||
# copy mods verbosely
|
||||
cp -v "$MODS_EXPORT_DIR"/* "$MODS_DIR"
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo -e "Mods imported ${GREEN}successfully${NC}." >&2
|
||||
else
|
||||
echo -e "${RED}Error${NC}: Failed to import mods." >&2
|
||||
fi
|
||||
|
||||
[[ $? -ne 0 ]] && { echo -e "${RED}Error${NC}: Failed to import mods." >&2; exit 1; }
|
||||
echo -e "Mods imported ${GREEN}successfully${NC}." >&2
|
||||
}
|
||||
|
||||
# --- Main ---
|
||||
|
||||
function main() {
|
||||
if [[ $# -lt 1 ]]; then
|
||||
display_help
|
||||
exit 1
|
||||
fi
|
||||
[[ $# -lt 1 ]] && { display_help; exit 1; }
|
||||
|
||||
command="$1"
|
||||
shift
|
||||
|
||||
+7
-1
@@ -56,6 +56,8 @@ if [[ -x "$(command -v $SCRIPT_NAME)" ]]; then
|
||||
|
||||
if [[ $latest_major -gt $installed_major ]]; then
|
||||
echo -e "${ORANGE}Warning:${NC} Major version upgrade detected."
|
||||
echo "Check out the changelogs here:"
|
||||
echo "https://github.com/v4n00/h2mm-cli/releases"
|
||||
echo "The script will proceed to upgrade ${SCRIPT_NAME} to avoid breaking changes."
|
||||
|
||||
# find hd2 path
|
||||
@@ -83,7 +85,11 @@ if [[ -x "$(command -v $SCRIPT_NAME)" ]]; then
|
||||
for ((i = installed_major + 1; i <= latest_major; i++)); do
|
||||
echo -e "Applying breaking changes patch for version $i."
|
||||
|
||||
[[ -n "${breaking_changes_patches[$i]}" ]] && eval $(echo "${breaking_changes_patches[$i]}" | sed "s:\$1:$game_dir:")
|
||||
if [[ -n "${breaking_changes_patches[$i]}" ]]; then
|
||||
eval $(echo "${breaking_changes_patches[$i]}" | sed "s:\$1:$game_dir:")
|
||||
else
|
||||
echo "No breaking changes for version $i."
|
||||
fi
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo -ne "${RED}Error:${NC} Failed to apply breaking changes patch for version $i. Do you want to continue? (Y/n): "
|
||||
read -er response
|
||||
|
||||
Reference in New Issue
Block a user