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

###
# Pillars of Eternity
# send your bug reports to vv221@dotslashplay.it
###

script_version=20260411.3

PLAYIT_COMPATIBILITY_LEVEL='2.35'

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

ARCHIVE_BASE_2_NAME='pillars_of_eternity_3_9_3_88783_89970.sh'
ARCHIVE_BASE_2_MD5='13967d58c100a63625c428a34faef359'
ARCHIVE_BASE_2_SIZE='17103656'
ARCHIVE_BASE_2_VERSION='3.9.3.88783-gog89970'
ARCHIVE_BASE_2_URL='https://www.gog.com/game/pillars_of_eternity_hero_edition'

ARCHIVE_BASE_1_NAME='pillars_of_eternity_3_8_0_88149_85633.sh'
ARCHIVE_BASE_1_MD5='a705c83007448bf33941924be2c3ac57'
ARCHIVE_BASE_1_SIZE='17022011'
ARCHIVE_BASE_1_VERSION='3.8.0.88149-gog85633'

ARCHIVE_BASE_0_NAME='pillars_of_eternity_3_8_0_87535_80946.sh'
ARCHIVE_BASE_0_MD5='805f0a9f9d467937ae52cb33c5aa7515'
ARCHIVE_BASE_0_SIZE='17022011'
ARCHIVE_BASE_0_VERSION='3.8.0.87535-gog80946'

ARCHIVE_BASE_OLD_3_NAME='pillars_of_eternity_en_3_07_0_1318_17461.sh'
ARCHIVE_BASE_OLD_3_MD5='57164ad0cbc53d188dde0b38e7491916'
ARCHIVE_BASE_OLD_3_SIZE='14801525'
ARCHIVE_BASE_OLD_3_VERSION='3.7.0.1318-gog17461'

ARCHIVE_BASE_OLD_2_NAME='pillars_of_eternity_en_3_07_16405.sh'
ARCHIVE_BASE_OLD_2_MD5='e4271b5e72f1ecc9fbbc4d90937ede05'
ARCHIVE_BASE_OLD_2_SIZE='15000000'
ARCHIVE_BASE_OLD_2_VERSION='3.7.0.1284-gog16405'

ARCHIVE_BASE_OLD_1_NAME='gog_pillars_of_eternity_2.16.0.20.sh'
ARCHIVE_BASE_OLD_1_MD5='0d21cf95bda070bdbfbe3e79f8fc32d6'
ARCHIVE_BASE_OLD_1_SIZE='15000000'
ARCHIVE_BASE_OLD_1_VERSION='3.06.1254-gog2.16.0.20'

ARCHIVE_BASE_OLD_0_NAME='gog_pillars_of_eternity_2.15.0.19.sh'
ARCHIVE_BASE_OLD_0_MD5='2000052541abb1ef8a644049734e8526'
ARCHIVE_BASE_OLD_0_SIZE='15000000'
ARCHIVE_BASE_OLD_0_VERSION='3.05.1186-gog2.15.0.19'

UNITY3D_NAME='PillarsOfEternity'
UNITY3D_PLUGINS_OLD='
ScreenSelector.so'

CONTENT_PATH_DEFAULT='data/noarch/game'
CONTENT_GAME_DATA_AREAS_FILES="
${UNITY3D_NAME}_Data/assetbundles/st_ar_*"
CONTENT_DOC_DATA_RELATIVE_PATH='Docs'
CONTENT_DOC_DATA_FILES='
pe-game-manual.pdf
OFL.TXT
readme.txt'

PACKAGES_LIST='
PKG_BIN
PKG_DATA_AREAS
PKG_DATA'

PKG_BIN_ARCH='64'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_DATA'
PKG_BIN_DEPENDENCIES_LIBRARIES='
libc.so.6
libdl.so.2
libgcc_s.so.1
libm.so.6
libpthread.so.0
librt.so.1
libz.so.1'
PKG_BIN_DEPENDENCIES_LIBRARIES_OLD='
libc.so.6
libdl.so.2
libgcc_s.so.1
libgdk_pixbuf-2.0.so.0
libglib-2.0.so.0
libGL.so.1
libGLU.so.1
libgobject-2.0.so.0
libgtk-x11-2.0.so.0
libm.so.6
libpthread.so.0
librt.so.1
libstdc++.so.6
libX11.so.6
libXcursor.so.1'

PKG_DATA_ID="${GAME_ID}-data"
PKG_DATA_DESCRIPTION='data'
PKG_DATA_DEPENDENCIES_SIBLINGS='
PKG_DATA_AREAS'

PKG_DATA_AREAS_ID="${PKG_DATA_ID}-areas"
PKG_DATA_AREAS_DESCRIPTION="$PKG_DATA_DESCRIPTION - areas"

# 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

# Prevent inclusion of Steam library.

case "$(current_archive)" in
	('ARCHIVE_BASE_OLD_'*)
		# These builds already rely on UNITY3D_PLUGINS.
	;;
	(*)
		rm --recursive "$(path_archive_contents)/$(unity3d_name)_Data/Plugins"
	;;
esac

# Include game data.

content_inclusion_icons 'PKG_DATA'
content_inclusion_default

# Write launchers.

launchers_generation

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
