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

###
# Pathfinder: Kingmaker
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260511.1

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='pathfinder-kingmaker'
GAME_NAME='Pathfinder: Kingmaker'

ARCHIVE_BASE_0_NAME='pathfinder_kingmaker_2_1_5d_41987.sh'
ARCHIVE_BASE_0_MD5='e17d6ff3c5f06c326ddd047c181eab27'
ARCHIVE_BASE_0_SIZE='35073163'
ARCHIVE_BASE_0_VERSION='2.1.5d-gog41987'

UNITY3D_NAME='Kingmaker'
UNITY3D_PLUGINS='
libAkConvolutionReverb.so
libAkFlanger.so
libAkSoundEngine.so
libAkStereoDelay.so
libAkTremolo.so
ScreenSelector.so'

CONTENT_PATH_DEFAULT='data/noarch/game'
CONTENT_GAME_DATA_ASSETS_1_FILES="
${UNITY3D_NAME}_Data/sharedassets[1-3]*"
CONTENT_GAME_DATA_ASSETS_2_FILES="
${UNITY3D_NAME}_Data/sharedassets[4-9]*"
CONTENT_GAME_DATA_BUNDLES_1_FILES="
${UNITY3D_NAME}_Data/StreamingAssets/Bundles/[a-n]*"
CONTENT_GAME_DATA_BUNDLES_2_FILES="
${UNITY3D_NAME}_Data/StreamingAssets/Bundles/[m-z]*"
# TODO: Build dedicated per-language localisation packages.

PACKAGES_LIST='
PKG_BIN
PKG_DATA_ASSETS_1
PKG_DATA_ASSETS_2
PKG_DATA_BUNDLES_1
PKG_DATA_BUNDLES_2
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
libgdk_pixbuf-2.0.so.0
libglib-2.0.so.0
libgobject-2.0.so.0
libgtk-x11-2.0.so.0
libm.so.6
libpthread.so.0
librt.so.1
libSDL2-2.0.so.0
libstdc++.so.6
libz.so.1'

PKG_DATA_ID="${GAME_ID}-data"
PKG_DATA_DESCRIPTION='data'
PKG_DATA_DEPENDENCIES_SIBLINGS='
PKG_DATA_ASSETS_1
PKG_DATA_ASSETS_2
PKG_DATA_BUNDLES_1
PKG_DATA_BUNDLES_2'
# Easier upgrades from pre-20260510.5 packages
PKG_DATA_PROVIDES='
pathfinder-kingmaker-data-shared-assets
pathfinder-kingmaker-data-streaming-assets-audio
pathfinder-kingmaker-data-streaming-assets-bundles-resource
pathfinder-kingmaker-data-streaming-assets-bundles-companion
pathfinder-kingmaker-data-streaming-assets-bundles-shaders
pathfinder-kingmaker-data-streaming-assets-localization'

PKG_DATA_ASSETS_ID="${PKG_DATA_ID}-assets"
PKG_DATA_ASSETS_1_ID="${PKG_DATA_ASSETS_ID}-1"
PKG_DATA_ASSETS_2_ID="${PKG_DATA_ASSETS_ID}-2"
PKG_DATA_ASSETS_DESCRIPTION="${PKG_DATA_DESCRIPTION} - assets"
PKG_DATA_ASSETS_1_DESCRIPTION="${PKG_DATA_ASSETS_DESCRIPTION} 1/2"
PKG_DATA_ASSETS_2_DESCRIPTION="${PKG_DATA_ASSETS_DESCRIPTION} 2/2"

PKG_DATA_BUNDLES_ID="${PKG_DATA_ID}-bundles"
PKG_DATA_BUNDLES_1_ID="${PKG_DATA_BUNDLES_ID}-1"
PKG_DATA_BUNDLES_2_ID="${PKG_DATA_BUNDLES_ID}-2"
PKG_DATA_BUNDLES_DESCRIPTION="${PKG_DATA_DESCRIPTION} - bundles"
PKG_DATA_BUNDLES_1_DESCRIPTION="${PKG_DATA_BUNDLES_DESCRIPTION} 1/2"
PKG_DATA_BUNDLES_2_DESCRIPTION="${PKG_DATA_BUNDLES_DESCRIPTION} 2/2"

# 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

# Use a standard name for the game binary.

mv \
	"$(path_archive_contents)/Kingmaker.exe" \
	"$(path_archive_contents)/$(unity3d_name)" \

# 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
