From 15d38ea7395bd6df22c1cda11ddcca9a2c2d30b3 Mon Sep 17 00:00:00 2001 From: Florian Kinder Date: Sun, 6 Jul 2025 19:01:05 +0900 Subject: [PATCH] Fix mod version compatibility checking for major version differences (#575) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes issue #517 where the auto mod updater was downloading the wrong mod versions after updating to Space Age (Factorio 2.0). The problem was that the version checking logic was incorrectly rejecting compatible mod versions. Changes: - Fixed check_game_version() to properly handle major version differences - Game versions can now run mods designed for older major versions (backward compatibility) - Game versions correctly reject mods requiring newer versions - Fixed variable references in check_dependency_version() - Added clarifying comments about the version checking behavior This also addresses issue #468 by ensuring mods requiring newer Factorio versions than currently installed are properly skipped. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude --- docker/files/update-mods.sh | 39 ++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/docker/files/update-mods.sh b/docker/files/update-mods.sh index e9ac6e1..512be7f 100755 --- a/docker/files/update-mods.sh +++ b/docker/files/update-mods.sh @@ -23,24 +23,33 @@ print_failure() echo "$1" } -# Checks game version vs version in mod. -# Returns 0 if major version differs or mod minor version is less than game version, 1 if ok +# Checks if the current game version satisfies the mod's minimum required version. +# Returns 1 if the game version is compatible with the mod, 0 if not check_game_version() { - local game_version="$1" - local mod_version="$2" + local mod_required_version="$1" # The minimum Factorio version required by the mod + local current_game_version="$2" # The current Factorio version - local game_major mod_major game_minor mod_minor - game_major=$(echo "$game_version" | cut -d '.' -f1) - game_minor=$(echo "$game_version" | cut -d '.' -f2) - mod_major=$(echo "$mod_version" | cut -d '.' -f1) - mod_minor=$(echo "$mod_version" | cut -d '.' -f2) + local mod_major mod_minor game_major game_minor + mod_major=$(echo "$mod_required_version" | cut -d '.' -f1) + mod_minor=$(echo "$mod_required_version" | cut -d '.' -f2) + game_major=$(echo "$current_game_version" | cut -d '.' -f1) + game_minor=$(echo "$current_game_version" | cut -d '.' -f2) - if [[ "$game_major" -ne "$mod_major" ]]; then + # If game major version is greater than mod's required major version, it's compatible + if [[ "$game_major" -gt "$mod_major" ]]; then + echo 1 + return + fi + + # If game major version is less than mod's required major version, it's not compatible + if [[ "$game_major" -lt "$mod_major" ]]; then echo 0 return fi - if [[ "$mod_minor" -ge "$game_minor" ]]; then + # Major versions are equal, check minor versions + # Game minor version must be >= mod's required minor version + if [[ "$game_minor" -ge "$mod_minor" ]]; then echo 1 else echo 0 @@ -79,7 +88,7 @@ check_dependency_version() fi ;; ">") - if [[ "$(printf '%s\n%s\n' "$required_version" "$mod_version" | sort -V | head -n1)" == "$required_version" && "$required_version" != "$FACTORIO_VERSION" ]]; then + if [[ "$(printf '%s\n%s\n' "$required_version" "$mod_version" | sort -V | head -n1)" == "$required_version" && "$required_version" != "$mod_version" ]]; then echo 1 else echo 0 @@ -93,7 +102,7 @@ check_dependency_version() fi ;; "<") - if [[ "$(printf '%s\n%s\n' "$required_version" "$mod_version" | sort -V | tail -n1)" == "$required_version" && "$required_version" != "$FACTORIO_VERSION" ]]; then + if [[ "$(printf '%s\n%s\n' "$required_version" "$mod_version" | sort -V | tail -n1)" == "$required_version" && "$required_version" != "$mod_version" ]]; then echo 1 else echo 0 @@ -116,11 +125,15 @@ get_mod_info() { local mod_info_json="$1" + # Process mod releases from newest to oldest, looking for a compatible version while IFS= read -r mod_release_info; do local mod_version mod_factorio_version mod_version=$(echo "$mod_release_info" | jq -r ".version") mod_factorio_version=$(echo "$mod_release_info" | jq -r ".info_json.factorio_version") + # Check if this mod version is compatible with our Factorio version + # This prevents downloading mods that require a newer Factorio version (fixes #468) + # and ensures backward compatibility (e.g., Factorio 2.0 can use 1.x mods) (fixes #517) if [[ $(check_game_version "$mod_factorio_version" "$FACTORIO_VERSION") == 0 ]]; then echo " Skipping mod version $mod_version because of factorio version mismatch" >&2 continue