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

###
# Pillars of Eternity expansions:
# - Kickstarter item
# - Kickstarter pet
# - Pre-order item and pet
# - The White March, Part 1
# - The White March, Part 2
# - Deadfire Pack
# send your bug reports to vv221@dotslashplay.it
###

script_version=20260411.2

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='pillars-of-eternity-1'
GAME_NAME='Pillars of Eternity'

EXPANSION_ID_TIER1BACKER='kickstarter-item'
EXPANSION_NAME_TIER1BACKER='Kickstarter item'

EXPANSION_ID_TIER2BACKER='kickstarter-pet'
EXPANSION_NAME_TIER2BACKER='Kickstarter pet'

EXPANSION_ID_PREORDER='preorder-content'
EXPANSION_NAME_PREORDER='Pre-order item and pet'

EXPANSION_ID_TWM1='the-white-march-part-1'
EXPANSION_NAME_TWM1='The White March Part Ⅰ'

EXPANSION_ID_TWM2='the-white-march-part-2'
EXPANSION_NAME_TWM2='The White March Part Ⅱ'

EXPANSION_ID_DEADFIRE='deadfire-pack'
EXPANSION_NAME_DEADFIRE='Deadfire Pack'

# Kickstarter item

ARCHIVE_BASE_TIER1BACKER_3_NAME='pillars_of_eternity_kickstarter_item_3_9_3_88783_89970.sh'
ARCHIVE_BASE_TIER1BACKER_3_MD5='90ebb0616bf13c8840ecd7026b700fc9'
ARCHIVE_BASE_TIER1BACKER_3_SIZE='971'
ARCHIVE_BASE_TIER1BACKER_3_VERSION='3.9.3.88783-gog89970'

ARCHIVE_BASE_TIER1BACKER_2_NAME='pillars_of_eternity_kickstarter_item_3_8_0_88149_85633.sh'
ARCHIVE_BASE_TIER1BACKER_2_MD5='89b14ee2a9497afc1a546192b3de5b5b'
ARCHIVE_BASE_TIER1BACKER_2_SIZE='971'
ARCHIVE_BASE_TIER1BACKER_2_VERSION='3.8.0.88149-gog85633'

ARCHIVE_BASE_TIER1BACKER_1_NAME='pillars_of_eternity_kickstarter_item_3_8_0_87535_80946.sh'
ARCHIVE_BASE_TIER1BACKER_1_MD5='67b7ae65b7c1502e37110b7f4402a19f'
ARCHIVE_BASE_TIER1BACKER_1_SIZE='971'
ARCHIVE_BASE_TIER1BACKER_1_VERSION='3.8.0.87535-gog80946'

ARCHIVE_BASE_TIER1BACKER_0_NAME='gog_pillars_of_eternity_kickstarter_item_dlc_2.0.0.2.sh'
ARCHIVE_BASE_TIER1BACKER_0_MD5='b4c29ae17c87956471f2d76d8931a4e5'
ARCHIVE_BASE_TIER1BACKER_0_SIZE='924'
ARCHIVE_BASE_TIER1BACKER_0_VERSION='1.0-gog2.0.0.2'

# Kickstarter pet

ARCHIVE_BASE_TIER2BACKER_3_NAME='pillars_of_eternity_kickstarter_pet_3_9_3_88783_89970.sh'
ARCHIVE_BASE_TIER2BACKER_3_MD5='887303d0d464d61750fb9de9169c8f00'
ARCHIVE_BASE_TIER2BACKER_3_SIZE='978'
ARCHIVE_BASE_TIER2BACKER_3_VERSION='3.9.3.88783-gog89970'

ARCHIVE_BASE_TIER2BACKER_2_NAME='pillars_of_eternity_kickstarter_pet_3_8_0_88149_85633.sh'
ARCHIVE_BASE_TIER2BACKER_2_MD5='4011745c101d3df071e6a359ff6f499b'
ARCHIVE_BASE_TIER2BACKER_2_SIZE='978'
ARCHIVE_BASE_TIER2BACKER_2_VERSION='3.8.0.88149-gog85633'

ARCHIVE_BASE_TIER2BACKER_1_NAME='pillars_of_eternity_kickstarter_pet_3_8_0_87535_80946.sh'
ARCHIVE_BASE_TIER2BACKER_1_MD5='f5ee7919aaf466d45c12689a4de327e9'
ARCHIVE_BASE_TIER2BACKER_1_SIZE='978'
ARCHIVE_BASE_TIER2BACKER_1_VERSION='3.8.0.87535-gog80946'

ARCHIVE_BASE_TIER2BACKER_0_NAME='gog_pillars_of_eternity_kickstarter_pet_dlc_2.0.0.2.sh'
ARCHIVE_BASE_TIER2BACKER_0_MD5='3653fc2a98ef578335f89b607f0b7968'
ARCHIVE_BASE_TIER2BACKER_0_SIZE='924'
ARCHIVE_BASE_TIER2BACKER_0_VERSION='1.0-gog2.0.0.2'

# Pre-order item and pet

ARCHIVE_BASE_PREORDER_3_NAME='pillars_of_eternity_preorder_item_and_pet_3_9_3_88783_89970.sh'
ARCHIVE_BASE_PREORDER_3_MD5='7d9272afbb052137d1e3f0efc5c2ad6e'
ARCHIVE_BASE_PREORDER_3_SIZE='963'
ARCHIVE_BASE_PREORDER_3_VERSION='3.9.3.88783-gog89970'

ARCHIVE_BASE_PREORDER_2_NAME='pillars_of_eternity_preorder_item_and_pet_3_8_0_88149_85633.sh'
ARCHIVE_BASE_PREORDER_2_MD5='7bced964b41788b3c066fd58a9fbb58d'
ARCHIVE_BASE_PREORDER_2_SIZE='963'
ARCHIVE_BASE_PREORDER_2_VERSION='3.8.0.88149-gog85633'

ARCHIVE_BASE_PREORDER_1_NAME='pillars_of_eternity_preorder_item_and_pet_3_8_0_87535_80946.sh'
ARCHIVE_BASE_PREORDER_1_MD5='ad7a6c20a937f76a356e1613495c43c0'
ARCHIVE_BASE_PREORDER_1_SIZE='963'
ARCHIVE_BASE_PREORDER_1_VERSION='3.8.0.87535-gog80946'

ARCHIVE_BASE_PREORDER_0_NAME='gog_pillars_of_eternity_preorder_item_and_pet_dlc_2.0.0.2.sh'
ARCHIVE_BASE_PREORDER_0_MD5='b86ad866acb62937d2127407e4beab19'
ARCHIVE_BASE_PREORDER_0_SIZE='924'
ARCHIVE_BASE_PREORDER_0_VERSION='1.0-gog2.0.0.2'

# The White March, Part 1

ARCHIVE_BASE_TWM1_6_NAME='pillars_of_eternity_the_white_march_part_1_3_9_3_88783_89970.sh'
ARCHIVE_BASE_TWM1_6_MD5='d49032f5f7233f83173dace17a4d7c1d'
ARCHIVE_BASE_TWM1_6_SIZE='7569365'
ARCHIVE_BASE_TWM1_6_VERSION='3.9.3.88783-gog89970'
ARCHIVE_BASE_TWM1_6_URL='https://www.gog.com/game/pillars_of_eternity_the_white_march_part_1'

ARCHIVE_BASE_TWM1_5_NAME='pillars_of_eternity_the_white_march_part_1_3_8_0_88149_85633.sh'
ARCHIVE_BASE_TWM1_5_MD5='13a423d8622a3251aefc0a6254e1421c'
ARCHIVE_BASE_TWM1_5_SIZE='7564726'
ARCHIVE_BASE_TWM1_5_VERSION='3.8.0.88149-gog85633'

ARCHIVE_BASE_TWM1_4_NAME='pillars_of_eternity_the_white_march_part_1_3_8_0_87535_80946.sh'
ARCHIVE_BASE_TWM1_4_MD5='ad2218672a0aba7ee0a30b73eefc81dd'
ARCHIVE_BASE_TWM1_4_SIZE='7564726'
ARCHIVE_BASE_TWM1_4_VERSION='3.8.0.87535-gog80946'

ARCHIVE_BASE_TWM1_3_NAME='pillars_of_eternity_white_march_part_1_dlc_en_3_07_0_1318_17464.sh'
ARCHIVE_BASE_TWM1_3_MD5='cc72f59ee20238ff05c47646b4618f01'
ARCHIVE_BASE_TWM1_3_SIZE='5507108'
ARCHIVE_BASE_TWM1_3_VERSION='3.7.0.1318-gog17464'

ARCHIVE_BASE_TWM1_2_NAME='pillars_of_eternity_white_march_part_1_dlc_en_3_07_16598.sh'
ARCHIVE_BASE_TWM1_2_MD5='054b6af430da1ed2635b9c6b4ed56866'
ARCHIVE_BASE_TWM1_2_SIZE='5500000'
ARCHIVE_BASE_TWM1_2_VERSION='3.7.0.1284-gog16598'

ARCHIVE_BASE_TWM1_1_NAME='gog_pillars_of_eternity_white_march_part_1_dlc_2.10.0.12.sh'
ARCHIVE_BASE_TWM1_1_MD5='8fafcb549fffd2de24f381a85e859622'
ARCHIVE_BASE_TWM1_1_SIZE='5500000'
ARCHIVE_BASE_TWM1_1_VERSION='3.06.0.1254-gog2.10.0.12'

ARCHIVE_BASE_TWM1_0_NAME='gog_pillars_of_eternity_white_march_part_1_dlc_2.9.0.11.sh'
ARCHIVE_BASE_TWM1_0_MD5='98424615626c82ed723860d421f187b6'
ARCHIVE_BASE_TWM1_0_SIZE='5500000'
ARCHIVE_BASE_TWM1_0_VERSION='3.05.0.1186-gog2.9.0.11'

# The White March, Part 2

ARCHIVE_BASE_TWM2_6_NAME='pillars_of_eternity_the_white_march_part_2_3_9_3_88783_89970.sh'
ARCHIVE_BASE_TWM2_6_MD5='f0637dfad49a2033540187c11d31066b'
ARCHIVE_BASE_TWM2_6_SIZE='6849256'
ARCHIVE_BASE_TWM2_6_VERSION='3.9.3.88783-gog89970'
ARCHIVE_BASE_TWM2_6_URL='https://www.gog.com/game/pillars_of_eternity_the_white_march_part_2'

ARCHIVE_BASE_TWM2_5_NAME='pillars_of_eternity_the_white_march_part_2_3_8_0_88149_85633.sh'
ARCHIVE_BASE_TWM2_5_MD5='90a7c82b7dab1939af91110b87248015'
ARCHIVE_BASE_TWM2_5_SIZE='6845084'
ARCHIVE_BASE_TWM2_5_VERSION='3.8.0.88149-gog85633'

ARCHIVE_BASE_TWM2_4_NAME='pillars_of_eternity_the_white_march_part_2_3_8_0_87535_80946.sh'
ARCHIVE_BASE_TWM2_4_MD5='b64f8528243197aaec1a6a99fb43e728'
ARCHIVE_BASE_TWM2_4_SIZE='6845084'
ARCHIVE_BASE_TWM2_4_VERSION='3.8.0.87535-gog80946'

ARCHIVE_BASE_TWM2_3_NAME='pillars_of_eternity_white_march_part_2_dlc_en_3_07_0_1318_17464.sh'
ARCHIVE_BASE_TWM2_3_MD5='03067ebdd878cc16c283f63ddf015e90'
ARCHIVE_BASE_TWM2_3_SIZE='4360158'
ARCHIVE_BASE_TWM2_3_VERSION='3.7.0.1318-gog17464'

ARCHIVE_BASE_TWM2_2_NAME='pillars_of_eternity_white_march_part_2_dlc_en_3_07_16598.sh'
ARCHIVE_BASE_TWM2_2_MD5='db3a345b2b2782e2ad075dd32567f303'
ARCHIVE_BASE_TWM2_2_SIZE='4300000'
ARCHIVE_BASE_TWM2_2_VERSION='3.7.0.1284-gog16598'

ARCHIVE_BASE_TWM2_1_NAME='gog_pillars_of_eternity_white_march_part_2_dlc_2.6.0.7.sh'
ARCHIVE_BASE_TWM2_1_MD5='fdc1446661a358961379fbec24c44680'
ARCHIVE_BASE_TWM2_1_SIZE='4400000'
ARCHIVE_BASE_TWM2_1_VERSION='3.06.1254-gog2.6.0.7'

ARCHIVE_BASE_TWM2_0_NAME='gog_pillars_of_eternity_white_march_part_2_dlc_2.5.0.6.sh'
ARCHIVE_BASE_TWM2_0_MD5='483d4b8cc046a07ec91a6306d3409e23'
ARCHIVE_BASE_TWM2_0_SIZE='4400000'
ARCHIVE_BASE_TWM2_0_VERSION='3.05.1186-gog2.5.0.6'

# Deadfire Pack

ARCHIVE_BASE_DEADFIRE_5_NAME='pillars_of_eternity_deadfire_pack_3_9_3_88783_89970.sh'
ARCHIVE_BASE_DEADFIRE_5_MD5='be6ba4a581039eb765c5900edfe547c7'
ARCHIVE_BASE_DEADFIRE_5_SIZE='74014'
ARCHIVE_BASE_DEADFIRE_5_VERSION='3.9.3.88783-gog89970'
ARCHIVE_BASE_DEADFIRE_5_URL='https://www.gog.com/game/pillars_of_eternity_deadfire_pack'

ARCHIVE_BASE_DEADFIRE_4_NAME='pillars_of_eternity_deadfire_pack_3_8_0_88149_85633.sh'
ARCHIVE_BASE_DEADFIRE_4_MD5='5cb48dd4e262a46c9fc74ee760d0325e'
ARCHIVE_BASE_DEADFIRE_4_SIZE='73988'
ARCHIVE_BASE_DEADFIRE_4_VERSION='3.8.0.88149-gog85633'

ARCHIVE_BASE_DEADFIRE_3_NAME='pillars_of_eternity_deadfire_pack_3_8_0_87535_80946.sh'
ARCHIVE_BASE_DEADFIRE_3_MD5='ece6e59bc5bd1f59498140d3a4f1fb74'
ARCHIVE_BASE_DEADFIRE_3_SIZE='73988'
ARCHIVE_BASE_DEADFIRE_3_VERSION='3.8.0.87535-gog80946'

ARCHIVE_BASE_DEADFIRE_2_NAME='pillars_of_eternity_deadfire_pack_dlc_en_3_07_0_1318_20099.sh'
ARCHIVE_BASE_DEADFIRE_2_MD5='da315aba26784e55aa51139cebb7f9d2'
ARCHIVE_BASE_DEADFIRE_2_SIZE='922'
ARCHIVE_BASE_DEADFIRE_2_VERSION='3.07.0.1318-gog20099'

ARCHIVE_BASE_DEADFIRE_1_NAME='pillars_of_eternity_deadfire_pack_dlc_en_3_07_0_1318_17462.sh'
ARCHIVE_BASE_DEADFIRE_1_MD5='021362da5912dc8a3e47473e97726f7f'
ARCHIVE_BASE_DEADFIRE_1_SIZE='1300'
ARCHIVE_BASE_DEADFIRE_1_VERSION='3.07.0.1318-gog17462'

ARCHIVE_BASE_DEADFIRE_0_NAME='pillars_of_eternity_deadfire_pack_dlc_en_3_07_16380.sh'
ARCHIVE_BASE_DEADFIRE_0_MD5='2fc0dc21648953be1c571e28b1e3d002'
ARCHIVE_BASE_DEADFIRE_0_SIZE='1300'
ARCHIVE_BASE_DEADFIRE_0_VERSION='3.07-gog16380'

CONTENT_PATH_DEFAULT='data/noarch/game'
CONTENT_GAME_MAIN_FILES='
PillarsOfEternity_Data'
CONTENT_GAME_MAIN_FILES_TIER1BACKER='
PillarsOfEternity_Data/assetbundles/prefabs/objectbundle/tier1backer*'
CONTENT_GAME_MAIN_FILES_TIER2BACKER='
PillarsOfEternity_Data/assetbundles/prefabs/objectbundle/tier2backer*'
CONTENT_GAME_MAIN_FILES_PREORDER='
PillarsOfEternity_Data/assetbundles/prefabs/objectbundle/tier1preorder*'

PKG_PARENT_ID="$GAME_ID"
PKG_TWM1_ID="${GAME_ID}-${EXPANSION_ID_TWM1}"

PKG_MAIN_DEPENDENCIES_SIBLINGS='
PKG_PARENT'
PKG_MAIN_DEPENDENCIES_SIBLINGS_TWM2="$PKG_MAIN_DEPENDENCIES_SIBLINGS
PKG_TWM1"

# 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 '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
case "$(current_archive)" in
	# The White March, Part 2 - Remove files already provided by a dependency.
	('ARCHIVE_BASE_TWM2_'*)
		rm --force \
			"$(path_archive_contents)/PillarsOfEternity_Data/assetbundles/prefabs/objectbundle/px1_cre_blight_ice_terror" \
			"$(path_archive_contents)/PillarsOfEternity_Data/assetbundles/prefabs/objectbundle/px1_cre_blight_ice_terror.unity3d"
	;;
	# Deadfire Pack - Fix a typo in a file path.
	('ARCHIVE_BASE_DEADFIRE_'*)
		if [ -e "$(path_archive_contents)/PillarsOfEternity_data" ]; then
			mv \
				"$(path_archive_contents)/PillarsOfEternity_data" \
				"$(path_archive_contents)/PillarsOfEternity_Data"
		fi
	;;
esac

# Include game data.

content_inclusion_default

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
