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

###
# Stellaris expansions (story packs):
# - Leviathans
# - Synthetic Dawn
# - Distant Stars
# - Ancient Relics
# - First Contact
# - Astral Planes
# - Grand Archive
# send your bug reports to vv221@dotslashplay.it
###

script_version=20260117.1

PLAYIT_COMPATIBILITY_LEVEL='2.34'

GAME_ID='stellaris'
GAME_NAME='Stellaris'

EXPANSION_ID_LEVIATHANS='leviathans'
EXPANSION_NAME_LEVIATHANS='Leviathans Story Pack'

EXPANSION_ID_DAWN='synthetic-dawn'
EXPANSION_NAME_DAWN='Synthetic Dawn Story Pack'

EXPANSION_ID_STARS='distant-stars'
EXPANSION_NAME_STARS='Distant Stars Story Pack'

EXPANSION_ID_RELICS='ancient-relics'
EXPANSION_NAME_RELICS='Ancient Relics Story Pack'

EXPANSION_ID_CONTACT='first-contact'
EXPANSION_NAME_CONTACT='First Contact Story Pack'

EXPANSION_ID_PLANES='astral-planes'
EXPANSION_NAME_PLANES='Astral Planes'

EXPANSION_ID_ARCHIVE='grand-archive'
EXPANSION_NAME_ARCHIVE='Grand Archive Story Pack'

## Leviathans

ARCHIVE_BASE_LEVIATHANS_4_NAME='stellaris_leviathans_story_pack_4_2_4_87179.sh'
ARCHIVE_BASE_LEVIATHANS_4_MD5='bea83f00f2c3e0f5c37e9597497efdec'
ARCHIVE_BASE_LEVIATHANS_4_SIZE='58426'
ARCHIVE_BASE_LEVIATHANS_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_LEVIATHANS_4_URL='https://www.gog.com/game/stellaris_leviathans_story_pack'

ARCHIVE_BASE_LEVIATHANS_3_NAME='stellaris_leviathans_story_pack_4_1_7_86266.sh'
ARCHIVE_BASE_LEVIATHANS_3_MD5='d5ded91911ba0894b5b901be43181de8'
ARCHIVE_BASE_LEVIATHANS_3_SIZE='58426'
ARCHIVE_BASE_LEVIATHANS_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_LEVIATHANS_2_NAME='stellaris_leviathans_story_pack_4_0_23_84679.sh'
ARCHIVE_BASE_LEVIATHANS_2_MD5='f715aa00eb279dcdfe9124ac6312dce1'
ARCHIVE_BASE_LEVIATHANS_2_SIZE='58426'
ARCHIVE_BASE_LEVIATHANS_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_LEVIATHANS_1_NAME='stellaris_leviathans_story_pack_3_14_1592653_81105.sh'
ARCHIVE_BASE_LEVIATHANS_1_MD5='9c18773594ff2456258e6b6716311b20'
ARCHIVE_BASE_LEVIATHANS_1_SIZE='58426'
ARCHIVE_BASE_LEVIATHANS_1_VERSION='3.14.1592653-gog81105'

ARCHIVE_BASE_LEVIATHANS_0_NAME='stellaris_leviathans_story_pack_2_8_1_2_42827.sh'
ARCHIVE_BASE_LEVIATHANS_0_MD5='05b6cc30fe6d39acf09087e7e02e2235'
ARCHIVE_BASE_LEVIATHANS_0_SIZE='59000'
ARCHIVE_BASE_LEVIATHANS_0_VERSION='2.8.1.2-gog42827'

## Synthetic Dawn

ARCHIVE_BASE_DAWN_4_NAME='stellaris_synthetic_dawn_story_pack_4_2_4_87179.sh'
ARCHIVE_BASE_DAWN_4_MD5='66cd2fa3feb3f40672ac98bb525866d9'
ARCHIVE_BASE_DAWN_4_SIZE='48245'
ARCHIVE_BASE_DAWN_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_DAWN_4_URL='https://www.gog.com/game/stellaris_synthetic_dawn_story_pack'

ARCHIVE_BASE_DAWN_3_NAME='stellaris_synthetic_dawn_story_pack_4_1_7_86266.sh'
ARCHIVE_BASE_DAWN_3_MD5='611270eb8c53629460682cdf7c4741a2'
ARCHIVE_BASE_DAWN_3_SIZE='48245'
ARCHIVE_BASE_DAWN_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_DAWN_2_NAME='stellaris_synthetic_dawn_story_pack_4_0_23_84679.sh'
ARCHIVE_BASE_DAWN_2_MD5='5aa0d16a6e0e0a0f022fa4b9e820150f'
ARCHIVE_BASE_DAWN_2_SIZE='48245'
ARCHIVE_BASE_DAWN_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_DAWN_1_NAME='stellaris_synthetic_dawn_story_pack_3_14_1592653_81105.sh'
ARCHIVE_BASE_DAWN_1_MD5='8da0b258eb5e670ecc758dc938e97878'
ARCHIVE_BASE_DAWN_1_SIZE='48245'
ARCHIVE_BASE_DAWN_1_VERSION='3.14.1592653-gog81105'

ARCHIVE_BASE_DAWN_0_NAME='stellaris_synthetic_dawn_story_pack_2_8_1_2_42827.sh'
ARCHIVE_BASE_DAWN_0_MD5='2bcad8721700e5a8203fd7fe90c6f03c'
ARCHIVE_BASE_DAWN_0_SIZE='49000'
ARCHIVE_BASE_DAWN_0_VERSION='2.8.1.2-gog42827'

## Distant Stars

ARCHIVE_BASE_STARS_4_NAME='stellaris_distant_stars_story_pack_4_2_4_87179.sh'
ARCHIVE_BASE_STARS_4_MD5='f074a54ca1d3a7e13b6f04ca5e31b119'
ARCHIVE_BASE_STARS_4_SIZE='20832'
ARCHIVE_BASE_STARS_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_STARS_4_URL='https://www.gog.com/game/stellaris_distant_stars_story_pack'

ARCHIVE_BASE_STARS_3_NAME='stellaris_distant_stars_story_pack_4_1_7_86266.sh'
ARCHIVE_BASE_STARS_3_MD5='385958d8febeed27983d44b7f9818d82'
ARCHIVE_BASE_STARS_3_SIZE='20832'
ARCHIVE_BASE_STARS_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_STARS_2_NAME='stellaris_distant_stars_story_pack_4_0_23_84679.sh'
ARCHIVE_BASE_STARS_2_MD5='1bc7353d68bdf3590f2e709956ed088d'
ARCHIVE_BASE_STARS_2_SIZE='20832'
ARCHIVE_BASE_STARS_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_STARS_1_NAME='stellaris_distant_stars_story_pack_3_14_1592653_81105.sh'
ARCHIVE_BASE_STARS_1_MD5='eb6a9ad65dd727662706598256581265'
ARCHIVE_BASE_STARS_1_SIZE='20832'
ARCHIVE_BASE_STARS_1_VERSION='3.14.1592653-gog81105'

ARCHIVE_BASE_STARS_0_NAME='stellaris_distant_stars_story_pack_2_8_1_2_42827.sh'
ARCHIVE_BASE_STARS_0_MD5='8f108b37713fee10394e1d63b34da83e'
ARCHIVE_BASE_STARS_0_SIZE='22000'
ARCHIVE_BASE_STARS_0_VERSION='2.8.1.2-gog42827'

## Ancient Relics

ARCHIVE_BASE_RELICS_4_NAME='stellaris_ancient_relics_4_2_4_87179.sh'
ARCHIVE_BASE_RELICS_4_MD5='b0dfa5a5f2db600daab0cbdd06686c07'
ARCHIVE_BASE_RELICS_4_SIZE='32739'
ARCHIVE_BASE_RELICS_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_RELICS_4_URL='https://www.gog.com/game/stellaris_ancient_relics_story_pack'

ARCHIVE_BASE_RELICS_3_NAME='stellaris_ancient_relics_4_1_7_86266.sh'
ARCHIVE_BASE_RELICS_3_MD5='28340a7bb369c1ff13f17d6eb92684ea'
ARCHIVE_BASE_RELICS_3_SIZE='32739'
ARCHIVE_BASE_RELICS_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_RELICS_2_NAME='stellaris_ancient_relics_4_0_23_84679.sh'
ARCHIVE_BASE_RELICS_2_MD5='164757e6b58f2f1ad756d173be445e42'
ARCHIVE_BASE_RELICS_2_SIZE='32739'
ARCHIVE_BASE_RELICS_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_RELICS_1_NAME='stellaris_ancient_relics_3_14_1592653_81105.sh'
ARCHIVE_BASE_RELICS_1_MD5='2ee7c8d5cb9e6d14af6ea68e269960e6'
ARCHIVE_BASE_RELICS_1_SIZE='32739'
ARCHIVE_BASE_RELICS_1_VERSION='3.14.1592653-gog81105'

ARCHIVE_BASE_RELICS_0_NAME='stellaris_ancient_relics_2_8_1_2_42827.sh'
ARCHIVE_BASE_RELICS_0_MD5='4d1fa824f08e2853bd7d81e5a5c57f3e'
ARCHIVE_BASE_RELICS_0_SIZE='34000'
ARCHIVE_BASE_RELICS_0_VERSION='2.8.1.2-gog42827'

## First Contact

ARCHIVE_BASE_CONTACT_4_NAME='stellaris_first_contact_story_pack_4_2_4_87179.sh'
ARCHIVE_BASE_CONTACT_4_MD5='4e9965bee6a6243daaaa11162cebedce'
ARCHIVE_BASE_CONTACT_4_SIZE='832'
ARCHIVE_BASE_CONTACT_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_CONTACT_4_URL='https://www.gog.com/game/stellaris_first_contact_story_pack'

ARCHIVE_BASE_CONTACT_3_NAME='stellaris_first_contact_story_pack_4_1_7_86266.sh'
ARCHIVE_BASE_CONTACT_3_MD5='4667442592b03564cf65722636ae7dff'
ARCHIVE_BASE_CONTACT_3_SIZE='832'
ARCHIVE_BASE_CONTACT_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_CONTACT_2_NAME='stellaris_first_contact_story_pack_4_0_23_84679.sh'
ARCHIVE_BASE_CONTACT_2_MD5='8138329a8b9d21f5208ea28fb6fc3390'
ARCHIVE_BASE_CONTACT_2_SIZE='832'
ARCHIVE_BASE_CONTACT_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_CONTACT_1_NAME='stellaris_first_contact_story_pack_3_14_1592653_81105.sh'
ARCHIVE_BASE_CONTACT_1_MD5='08a96e2468e6bf4530ea0a9dc966efe4'
ARCHIVE_BASE_CONTACT_1_SIZE='832'
ARCHIVE_BASE_CONTACT_1_VERSION='3.14.1592653-gog81105'

## Astral Planes

ARCHIVE_BASE_PLANES_4_NAME='stellaris_astral_planes_4_2_4_87179.sh'
ARCHIVE_BASE_PLANES_4_MD5='a660e0efb787e23609944542664b70c4'
ARCHIVE_BASE_PLANES_4_SIZE='46789'
ARCHIVE_BASE_PLANES_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_PLANES_4_URL='https://www.gog.com/game/stellaris_astral_planes'

ARCHIVE_BASE_PLANES_3_NAME='stellaris_astral_planes_4_1_7_86266.sh'
ARCHIVE_BASE_PLANES_3_MD5='3a30613469053692aa74cfa1e7c4f1b5'
ARCHIVE_BASE_PLANES_3_SIZE='46789'
ARCHIVE_BASE_PLANES_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_PLANES_2_NAME='stellaris_astral_planes_4_0_23_84679.sh'
ARCHIVE_BASE_PLANES_2_MD5='e34bcde8db82137627e7bccaca471be5'
ARCHIVE_BASE_PLANES_2_SIZE='46789'
ARCHIVE_BASE_PLANES_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_PLANES_1_NAME='stellaris_astral_planes_3_14_1592653_81105.sh'
ARCHIVE_BASE_PLANES_1_MD5='27e12dbda8a5734ec6bd94e6eda650d9'
ARCHIVE_BASE_PLANES_1_SIZE='46789'
ARCHIVE_BASE_PLANES_1_VERSION='3.14.1592653-gog81105'

## Grand Archive

ARCHIVE_BASE_ARCHIVE_4_NAME='stellaris_grand_archive_4_2_4_87179.sh'
ARCHIVE_BASE_ARCHIVE_4_MD5='8ade8bea52ef239fa5c4bdd79d0c060d'
ARCHIVE_BASE_ARCHIVE_4_SIZE='32742'
ARCHIVE_BASE_ARCHIVE_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_ARCHIVE_4_URL='https://www.gog.com/game/stellaris_grand_archive'

ARCHIVE_BASE_ARCHIVE_3_NAME='stellaris_grand_archive_4_2_2_86843.sh'
ARCHIVE_BASE_ARCHIVE_3_MD5='98379b2cefcc971f332963bdbf514347'
ARCHIVE_BASE_ARCHIVE_3_SIZE='32742'
ARCHIVE_BASE_ARCHIVE_3_VERSION='4.2.2-gog86843'

ARCHIVE_BASE_ARCHIVE_2_NAME='stellaris_grand_archive_4_1_3_85354.sh'
ARCHIVE_BASE_ARCHIVE_2_MD5='72882f69a388d7fbf66e384878004514'
ARCHIVE_BASE_ARCHIVE_2_SIZE='33060'
ARCHIVE_BASE_ARCHIVE_2_VERSION='4.1.3-gog85354'

CONTENT_PATH_DEFAULT='data/noarch/game'
CONTENT_GAME_MAIN_FILES='
dlc'

PKG_PARENT_ID="$GAME_ID"

PKG_MAIN_DEPENDENCIES_SIBLINGS='
PKG_PARENT'

# Load common functions.

## Scan library paths used by ./play.it ≥ 2.35.
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
## Scan library paths used by ./play.it < 2.35.
## This can go away when PLAYIT_COMPATIBILITY_LEVEL is bumped to 2.35 or higher.
if [ -z "$PLAYIT_LIB2" ]; then
	for playit_lib_dir in \
		"$PWD" \
		"${XDG_DATA_HOME:="${HOME}/.local/share"}/play.it" \
		'/usr/local/share/games/play.it' \
		'/usr/local/share/play.it' \
		'/usr/share/games/play.it' \
		'/usr/share/play.it'
	do
		playit_lib_path="${playit_lib_dir}/libplayit2.sh"
		if [ -e "$playit_lib_path" ]; then
			PLAYIT_LIB2="$playit_lib_path"
			break
		fi
	done
fi
## Error out if the library can not be found.
if [ -z "$PLAYIT_LIB2" ]; then
	printf '\n\033[1;31mError:\033[0m\n'
	printf 'libplayit2.sh not found.\n'
	exit 1
fi
# shellcheck source=libplayit2.sh
. "$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
