#!/bin/sh
# SPDX-License-Identifier: ACSL
# SPDX-FileCopyrightText: © 2023 Antoine Le Gonidec <vv221@dotslashplay.it>
set -o errexit

###
# Grim Dawn expansions:
# - Ashes of Malmouth
# - Forgotten Gods
# send your bug reports to vv221@dotslashplay.it
###

script_version=20260321.1

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='grim-dawn'
GAME_NAME='Grim Dawn'

EXPANSION_ID_ASHES='ashes-of-malmouth'
EXPANSION_NAME_ASHES='Ashes of Malmouth'

EXPANSION_ID_GODS='forgotten-gods'
EXPANSION_NAME_GODS='Forgotten Gods'

# Ashes of Malmouth

ARCHIVE_BASE_ASHES_2_NAME='setup_grim_dawn_-_ashes_of_malmouth_1.2.1.6_(83443).exe'
ARCHIVE_BASE_ASHES_2_MD5='a864a83f2cb516a61447b863ddb9cba2'
ARCHIVE_BASE_ASHES_2_TYPE='innosetup'
ARCHIVE_BASE_ASHES_2_PART1_NAME='setup_grim_dawn_-_ashes_of_malmouth_1.2.1.6_(83443)-1.bin'
ARCHIVE_BASE_ASHES_2_PART1_MD5='7606fc0c108f29903f7f345cc2104f54'
ARCHIVE_BASE_ASHES_2_SIZE='2510736'
ARCHIVE_BASE_ASHES_2_VERSION='1.2.1.6-gog83443'
ARCHIVE_BASE_ASHES_2_URL='https://www.gog.com/game/grim_dawn_ashes_of_malmouth'

ARCHIVE_BASE_ASHES_1_NAME='setup_grim_dawn_-_ashes_of_malmouth_1.2.0.5a_(71558).exe'
ARCHIVE_BASE_ASHES_1_MD5='459923324f4f32779885fe03f192fe3a'
ARCHIVE_BASE_ASHES_1_TYPE='innosetup'
ARCHIVE_BASE_ASHES_1_PART1_NAME='setup_grim_dawn_-_ashes_of_malmouth_1.2.0.5a_(71558)-1.bin'
ARCHIVE_BASE_ASHES_1_PART1_MD5='11d3e5371bb3b9ecceb0a72b99671a24'
ARCHIVE_BASE_ASHES_1_SIZE='2508049'
ARCHIVE_BASE_ASHES_1_VERSION='1.2.0.5a-gog71558'

ARCHIVE_BASE_ASHES_0_NAME='setup_grim_dawn_-_ashes_of_malmouth_1.1.9.8_(65199).exe'
ARCHIVE_BASE_ASHES_0_MD5='0754f567005ecc7d758d905992e5d7f7'
ARCHIVE_BASE_ASHES_0_TYPE='innosetup'
ARCHIVE_BASE_ASHES_0_PART1_NAME='setup_grim_dawn_-_ashes_of_malmouth_1.1.9.8_(65199)-1.bin'
ARCHIVE_BASE_ASHES_0_PART1_MD5='49bc0c617d4ab9415298994ba4a085b8'
ARCHIVE_BASE_ASHES_0_SIZE='2506744'
ARCHIVE_BASE_ASHES_0_VERSION='1.1.9.8-gog65199'

# Forgotten Gods

ARCHIVE_BASE_GODS_2_NAME='setup_grim_dawn_-_forgotten_gods_1.2.1.6_(83443).exe'
ARCHIVE_BASE_GODS_2_MD5='e5d06e83f98bc4ed5b72bb7cb26dc0e7'
ARCHIVE_BASE_GODS_2_TYPE='innosetup'
ARCHIVE_BASE_GODS_2_PART1_NAME='setup_grim_dawn_-_forgotten_gods_1.2.1.6_(83443)-1.bin'
ARCHIVE_BASE_GODS_2_PART1_MD5='db9410df05b03a5f682e62660fbafc7b'
ARCHIVE_BASE_GODS_2_SIZE='3221530'
ARCHIVE_BASE_GODS_2_VERSION='1.2.1.6-gog83443'
ARCHIVE_BASE_GODS_2_URL='https://www.gog.com/game/grim_dawn_forgotten_gods'

ARCHIVE_BASE_GODS_1_NAME='setup_grim_dawn_-_forgotten_gods_1.2.0.5a_(71558).exe'
ARCHIVE_BASE_GODS_1_MD5='f4e80fca2102e244a47a218171c0f336'
ARCHIVE_BASE_GODS_1_TYPE='innosetup'
ARCHIVE_BASE_GODS_1_PART1_NAME='setup_grim_dawn_-_forgotten_gods_1.2.0.5a_(71558)-1.bin'
ARCHIVE_BASE_GODS_1_PART1_MD5='3199f7442939194091a2d534553b8007'
ARCHIVE_BASE_GODS_1_SIZE='3220483'
ARCHIVE_BASE_GODS_1_VERSION='1.2.0.5a-gog71558'

ARCHIVE_BASE_GODS_0_NAME='setup_grim_dawn_-_forgotten_gods_1.1.9.8_(65199).exe'
ARCHIVE_BASE_GODS_0_MD5='6615eb32a355092c4d0173457f701e31'
ARCHIVE_BASE_GODS_0_TYPE='innosetup'
ARCHIVE_BASE_GODS_0_PART1_NAME='setup_grim_dawn_-_forgotten_gods_1.1.9.8_(65199)-1.bin'
ARCHIVE_BASE_GODS_0_PART1_MD5='55ac480dee30aa6cfa6a8b466f521406'
ARCHIVE_BASE_GODS_0_SIZE='3220672'
ARCHIVE_BASE_GODS_0_VERSION='1.1.9.8-gog65199'

CONTENT_PATH_DEFAULT='.'
CONTENT_GAME_MAIN_FILES='
gdx?
survivalmode?'

PKG_PARENT_ID="$GAME_ID"

PKG_ASH_ID="${GAME_ID}-${EXPANSION_ID_ASHES}"

PKG_MAIN_DEPENDENCIES_SIBLINGS='
PKG_PARENT'
PKG_MAIN_DEPENDENCIES_SIBLINGS_GODS="$PKG_MAIN_DEPENDENCIES_SIBLINGS
PKG_ASH"

# Load common functions.

if [ -z "$PLAYIT_LIB2" ]; then
	for playit_lib_dir in \
		"$PWD" \
		"${HOME}/.local/lib/play.it" \
		'/usr/local/lib/play.it' \
		'/usr/lib/play.it'
	do
		playit_lib_path="${playit_lib_dir}/libplayit.sh.2"
		if [ -e "$playit_lib_path" ]; then
			PLAYIT_LIB2="$playit_lib_path"
			break
		fi
	done
fi
if [ -z "$PLAYIT_LIB2" ]; then
	printf '\n\033[1;31mError:\033[0m\n'
	printf 'libplayit.sh.2 not found.\n'
	exit 1
fi
# shellcheck source=libplayit.sh.2
. "$PLAYIT_LIB2"

# Run default initialisation actions.

initialization_default "$@"

# Extract game data.

archive_extraction_default

# Include game data.

content_inclusion_default

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
