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

###
# Giants: Citizen Kabuto
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260317.3

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='giants-citizen-kabuto'
GAME_NAME='Giants: Citizen Kabuto'

ARCHIVE_BASE_0_NAME='setup_giants_2.1.0.4.exe'
ARCHIVE_BASE_0_MD5='33015108ece9e52b1f525880f0867e11'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_VERSION='1.4-gog2.1.0.4'
ARCHIVE_BASE_0_SIZE='1600000'
ARCHIVE_BASE_0_URL='https://www.gog.com/game/giants_citizen_kabuto'

CONTENT_PATH_DEFAULT='app'
CONTENT_GAME_BIN_FILES='
Giants.exe'
# TODO: Install libraries in a standard path.
# TODO: Drop unused libraries.
CONTENT_GAME0_BIN_FILES='
eaxman.dll
gs_ds.dll'
CONTENT_GAME1_BIN_RELATIVE_PATH='__support/dx7'
CONTENT_GAME1_BIN_FILES='
gg_dx7r.dll'
# TODO: The server should be moved to a dedicated package.
CONTENT_GAME2_BIN_FILES='
dedicated.exe'
CONTENT_GAME_L10N_FR_FILES='
StreamFrench'
CONTENT_GAME_L10N_EN_FILES='
StreamEnglish'
CONTENT_GAME_DATA_FILES='
Bin
Music
Stream'
CONTENT_DOC_DATA_FILES='
MANUAL.PDF
history.txt
ReadMe.txt'
CONTENT_DOC0_DATA_FILES='
readme_dedicated.txt'

USER_PERSISTENT_DIRECTORIES='
savegame'
USER_PERSISTENT_FILES='
*.ini'

# Set required registry keys.
# shellcheck disable=SC1003
WINE_REGISTRY_INIT='
[HKEY_CURRENT_USER\Software\PlanetMoon\Giants]
"1.00.000"=""
"DefPlayer"="Player"
"DestDir"="C:\\'"${GAME_ID}"'"
"SrcDir"="C:\\"

[HKEY_CURRENT_USER\Software\PlanetMoon\Giants\IDs\Player]
"GameOptions"=dword:00000bf3
"VideoDepth"=dword:00000020
"VideoDevGuid"=hex:e0,3d,e6,84,aa,46,cf,11,81,6f,00,00,c0,20,15,6e
"VideoDrvGuid"=hex:3e,1e,b7,d7,d5,41,cf,11,f3,73,25,a2,0e,c2,cd,35
'
WINE_REGISTRY_INIT_L10N_FR="${WINE_REGISTRY_INIT}"'
[HKEY_CURRENT_USER\Software\PlanetMoon\Giants]
"Language"="1036"
'
WINE_REGISTRY_INIT_L10N_EN="${WINE_REGISTRY_INIT}"'
[HKEY_CURRENT_USER\Software\PlanetMoon\Giants]
"Language"="9"
'

APP_MAIN_EXE='Giants.exe'
APP_MAIN_ICON='Giants.ico'

PACKAGES_LIST='
PKG_BIN
PKG_L10N_FR
PKG_L10N_EN
PKG_DATA'

PKG_BIN_ARCH='32'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_L10N
PKG_DATA'

PKG_L10N_ID="${GAME_ID}-l10n"
PKG_L10N_FR_ID="${PKG_L10N_ID}-fr"
PKG_L10N_EN_ID="${PKG_L10N_ID}-en"
PKG_L10N_PROVIDES="
$PKG_L10N_ID"
PKG_L10N_FR_DESCRIPTION='French localisation'
PKG_L10N_EN_DESCRIPTION='English localisation'

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

# 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

# Include game data.

content_inclusion_icons 'PKG_DATA'
content_inclusion_default

# Write launchers.

# Set language through Windows registry scripts.
for package in 'PKG_L10N_FR' 'PKG_L10N_EN'; do
	(
		# WINE_REGISTRY_INIT context support is broken.
		# (./play.it 2.35)
		set_current_package "$package"
		# shellcheck disable=SC2218
		wine_registry_script_write "$package"
	)
done
# Prevent the registry script from being written again in PKG_BIN.
wine_registry_script_write() { return 0; }

launchers_generation

# Build packages.

packages_generation
case "$(messages_language)" in
	('fr')
		lang_string='version %s :'
		lang_fr='française'
		lang_en='anglaise'
	;;
	('en'|*)
		lang_string='%s version:'
		lang_fr='French'
		lang_en='English'
	;;
esac
printf '\n'
printf "$lang_string" "$lang_fr"
print_instructions 'PKG_BIN' 'PKG_DATA' 'PKG_L10N_FR'
printf "$lang_string" "$lang_en"
print_instructions 'PKG_BIN' 'PKG_DATA' 'PKG_L10N_EN'

# Clean up.

working_directory_cleanup

exit 0
