#!/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 (species packs):
# - Plantoids
# - Humanoids
# - Lithoids
# - Necroids
# - Aquatics
# - Toxoids
# send your bug reports to vv221@dotslashplay.it
###

script_version=20260116.4

PLAYIT_COMPATIBILITY_LEVEL='2.34'

GAME_ID='stellaris'
GAME_NAME='Stellaris'

EXPANSION_ID_PLANTOID='plantoid'
EXPANSION_NAME_PLANTOID='Plantoids Species Pack'

EXPANSION_ID_HUMANOIDS='humanoids'
EXPANSION_NAME_HUMANOIDS='Humanoids Species Pack'

EXPANSION_ID_LITHOIDS='lithoids'
EXPANSION_NAME_LITHOIDS='Lithoids Species Pack'

EXPANSION_ID_NECROIDS='necroids'
EXPANSION_NAME_NECROIDS='Necroids Species Pack'

EXPANSION_ID_AQUATICS='aquatics'
EXPANSION_NAME_AQUATICS='Aquatics Species Pack'

EXPANSION_ID_TOXOIDS='toxoids'
EXPANSION_NAME_TOXOIDS='Toxoids Species Pack'

## Plantoids

ARCHIVE_BASE_PLANTOID_4_NAME='stellaris_plantoids_species_pack_4_2_4_87179.sh'
ARCHIVE_BASE_PLANTOID_4_MD5='3aeb981bb594457ca3f554a2e943a525'
ARCHIVE_BASE_PLANTOID_4_SIZE='837'
ARCHIVE_BASE_PLANTOID_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_PLANTOID_4_URL='https://www.gog.com/game/stellaris_plantoids_species_pack'

ARCHIVE_BASE_PLANTOID_3_NAME='stellaris_plantoids_species_pack_4_1_7_86266.sh'
ARCHIVE_BASE_PLANTOID_3_MD5='da964d39609360f339e6b26046eef659'
ARCHIVE_BASE_PLANTOID_3_SIZE='837'
ARCHIVE_BASE_PLANTOID_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_PLANTOID_2_NAME='stellaris_plantoids_species_pack_4_0_23_84679.sh'
ARCHIVE_BASE_PLANTOID_2_MD5='d70d05409ff2c28ed9a770705945d4cc'
ARCHIVE_BASE_PLANTOID_2_SIZE='837'
ARCHIVE_BASE_PLANTOID_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_PLANTOID_1_NAME='stellaris_plantoids_species_pack_3_14_1592653_81105.sh'
ARCHIVE_BASE_PLANTOID_1_MD5='f2096d98d49833c1f900cd91b427b99d'
ARCHIVE_BASE_PLANTOID_1_SIZE='837'
ARCHIVE_BASE_PLANTOID_1_VERSION='3.14.1592653-gog81105'

ARCHIVE_BASE_PLANTOID_0_NAME='stellaris_plantoids_species_pack_2_8_1_2_42827.sh'
ARCHIVE_BASE_PLANTOID_0_MD5='6512a887b13a3a781a6556f58be1928f'
ARCHIVE_BASE_PLANTOID_0_SIZE='1400'
ARCHIVE_BASE_PLANTOID_0_VERSION='2.8.1.2-gog42827'

## Humanoids

ARCHIVE_BASE_HUMANOIDS_4_NAME='stellaris_humanoids_species_pack_4_2_4_87179.sh'
ARCHIVE_BASE_HUMANOIDS_4_MD5='ec9b6817c6facdb3c59a2510b0bdcbb2'
ARCHIVE_BASE_HUMANOIDS_4_SIZE='84675'
ARCHIVE_BASE_HUMANOIDS_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_HUMANOIDS_4_URL='https://www.gog.com/game/stellaris_humanoids_species_pack'

ARCHIVE_BASE_HUMANOIDS_3_NAME='stellaris_humanoids_species_pack_4_1_7_86266.sh'
ARCHIVE_BASE_HUMANOIDS_3_MD5='346e685e6fb7ea72defef76c9147a875'
ARCHIVE_BASE_HUMANOIDS_3_SIZE='84675'
ARCHIVE_BASE_HUMANOIDS_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_HUMANOIDS_2_NAME='stellaris_humanoids_species_pack_4_0_23_84679.sh'
ARCHIVE_BASE_HUMANOIDS_2_MD5='2f24f9d1cceb67be64f932452c705c34'
ARCHIVE_BASE_HUMANOIDS_2_SIZE='84675'
ARCHIVE_BASE_HUMANOIDS_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_HUMANOIDS_1_NAME='stellaris_humanoids_species_pack_3_14_1592653_81105.sh'
ARCHIVE_BASE_HUMANOIDS_1_MD5='b0ca9dba864d8726f822b03749cc680c'
ARCHIVE_BASE_HUMANOIDS_1_SIZE='84675'
ARCHIVE_BASE_HUMANOIDS_1_VERSION='3.14.1592653-gog81105'

ARCHIVE_BASE_HUMANOIDS_0_NAME='stellaris_humanoids_species_pack_2_8_1_2_42827.sh'
ARCHIVE_BASE_HUMANOIDS_0_MD5='1aa665250b1d26f5529ee22c1ba36e8d'
ARCHIVE_BASE_HUMANOIDS_0_SIZE='120000'
ARCHIVE_BASE_HUMANOIDS_0_VERSION='2.8.1.2-gog42827'

## Lithoids

ARCHIVE_BASE_LITHOIDS_4_NAME='stellaris_lithoids_species_pack_4_2_4_87179.sh'
ARCHIVE_BASE_LITHOIDS_4_MD5='99c5fcc15d7e8400e049c837cd2ccbe0'
ARCHIVE_BASE_LITHOIDS_4_SIZE='25612'
ARCHIVE_BASE_LITHOIDS_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_LITHOIDS_4_URL='https://www.gog.com/game/stellaris_lithoids_species_pack'

ARCHIVE_BASE_LITHOIDS_3_NAME='stellaris_lithoids_species_pack_4_1_7_86266.sh'
ARCHIVE_BASE_LITHOIDS_3_MD5='c78d3a9acde2188800455c96e272e52e'
ARCHIVE_BASE_LITHOIDS_3_SIZE='25612'
ARCHIVE_BASE_LITHOIDS_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_LITHOIDS_2_NAME='stellaris_lithoids_species_pack_4_0_23_84679.sh'
ARCHIVE_BASE_LITHOIDS_2_MD5='15878fe6dfb2d5e9d8828f250666b5b9'
ARCHIVE_BASE_LITHOIDS_2_SIZE='25612'
ARCHIVE_BASE_LITHOIDS_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_LITHOIDS_1_NAME='stellaris_lithoids_species_pack_3_14_1592653_81105.sh'
ARCHIVE_BASE_LITHOIDS_1_MD5='61bc2f350ab85060fa192a4ab9d0449f'
ARCHIVE_BASE_LITHOIDS_1_SIZE='25612'
ARCHIVE_BASE_LITHOIDS_1_VERSION='3.14.1592653-gog81105'

ARCHIVE_BASE_LITHOIDS_0_NAME='stellaris_lithoids_species_pack_2_8_1_2_42827.sh'
ARCHIVE_BASE_LITHOIDS_0_MD5='8939eff1f210fff7dddef479a7bac685'
ARCHIVE_BASE_LITHOIDS_0_SIZE='54000'
ARCHIVE_BASE_LITHOIDS_0_VERSION='2.8.1.2-gog42827'

## Necroids

ARCHIVE_BASE_NECROIDS_4_NAME='stellaris_necroids_species_pack_4_2_4_87179.sh'
ARCHIVE_BASE_NECROIDS_4_MD5='1dfabab4650059a553ab28198281f7a7'
ARCHIVE_BASE_NECROIDS_4_SIZE='24881'
ARCHIVE_BASE_NECROIDS_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_NECROIDS_4_URL='https://www.gog.com/game/stellaris_necroids_species_pack'

ARCHIVE_BASE_NECROIDS_3_NAME='stellaris_necroids_species_pack_4_1_7_86266.sh'
ARCHIVE_BASE_NECROIDS_3_MD5='e6088f1ade97f4687d493b11950d1123'
ARCHIVE_BASE_NECROIDS_3_SIZE='24881'
ARCHIVE_BASE_NECROIDS_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_NECROIDS_2_NAME='stellaris_necroids_species_pack_4_0_23_84679.sh'
ARCHIVE_BASE_NECROIDS_2_MD5='92999234cfe7eb8b4cb44c4db34d83cb'
ARCHIVE_BASE_NECROIDS_2_SIZE='24881'
ARCHIVE_BASE_NECROIDS_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_NECROIDS_1_NAME='stellaris_necroids_species_pack_3_14_1592653_81105.sh'
ARCHIVE_BASE_NECROIDS_1_MD5='5725e03dc497001f9837877ea2beff8d'
ARCHIVE_BASE_NECROIDS_1_SIZE='24881'
ARCHIVE_BASE_NECROIDS_1_VERSION='3.14.1592653-gog81105'

## Aquatics

ARCHIVE_BASE_AQUATICS_4_NAME='stellaris_aquatics_species_pack_4_2_4_87179.sh'
ARCHIVE_BASE_AQUATICS_4_MD5='50bfc0bcdde6d1a00d7b2313cf1d8145'
ARCHIVE_BASE_AQUATICS_4_SIZE='29883'
ARCHIVE_BASE_AQUATICS_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_AQUATICS_4_URL='https://www.gog.com/game/stellaris_aquatics_species_pack'

ARCHIVE_BASE_AQUATICS_3_NAME='stellaris_aquatics_species_pack_4_1_7_86266.sh'
ARCHIVE_BASE_AQUATICS_3_MD5='d53e18b0df2241c89cb3cac289e03543'
ARCHIVE_BASE_AQUATICS_3_SIZE='29883'
ARCHIVE_BASE_AQUATICS_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_AQUATICS_2_NAME='stellaris_aquatics_species_pack_4_0_23_84679.sh'
ARCHIVE_BASE_AQUATICS_2_MD5='1afeabca087501eae22ce82015866966'
ARCHIVE_BASE_AQUATICS_2_SIZE='29883'
ARCHIVE_BASE_AQUATICS_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_AQUATICS_1_NAME='stellaris_aquatics_species_pack_3_14_1592653_81105.sh'
ARCHIVE_BASE_AQUATICS_1_MD5='1eda07287d1d1fe6bf6cefcf2c142d8e'
ARCHIVE_BASE_AQUATICS_1_SIZE='29883'
ARCHIVE_BASE_AQUATICS_1_VERSION='3.14.1592653-gog81105'

## Toxoids

ARCHIVE_BASE_TOXOIDS_4_NAME='stellaris_toxoids_species_pack_4_2_4_87179.sh'
ARCHIVE_BASE_TOXOIDS_4_MD5='2217b35bbdea45dcdd27bddb5615b13f'
ARCHIVE_BASE_TOXOIDS_4_SIZE='21991'
ARCHIVE_BASE_TOXOIDS_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_TOXOIDS_4_URL='https://www.gog.com/game/stellaris_toxoids_species_pack'

ARCHIVE_BASE_TOXOIDS_3_NAME='stellaris_toxoids_species_pack_4_1_7_86266.sh'
ARCHIVE_BASE_TOXOIDS_3_MD5='b13f2b899f909e54389a093234813d38'
ARCHIVE_BASE_TOXOIDS_3_SIZE='21991'
ARCHIVE_BASE_TOXOIDS_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_TOXOIDS_2_NAME='stellaris_toxoids_species_pack_4_0_23_84679.sh'
ARCHIVE_BASE_TOXOIDS_2_MD5='5959517aa87e401b89e3dad77fc6fca5'
ARCHIVE_BASE_TOXOIDS_2_SIZE='21991'
ARCHIVE_BASE_TOXOIDS_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_TOXOIDS_1_NAME='stellaris_toxoids_species_pack_3_14_1592653_81105.sh'
ARCHIVE_BASE_TOXOIDS_1_MD5='80a09c9500cd8afa5b1a3b0135a64223'
ARCHIVE_BASE_TOXOIDS_1_SIZE='21991'
ARCHIVE_BASE_TOXOIDS_1_VERSION='3.14.1592653-gog81105'

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
