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

###
# The Incredible Adventures of Van Helsing
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260709.2

PLAYIT_COMPATIBILITY_LEVEL=2.35

GAME_ID='van-helsing-final-cut'
GAME_NAME='The Incredible Adventures of Van Helsing: Final Cut'

ARCHIVE_BASE_0_NAME='setup_the_incredible_adventures_of_van_helsing_-_final_cut_1.1.0b_(b)_(23988).exe'
ARCHIVE_BASE_0_MD5=11823fff68df72308f3f8ba8f9dfa820
ARCHIVE_BASE_0_TYPE=innosetup
ARCHIVE_BASE_0_PART1_NAME='setup_the_incredible_adventures_of_van_helsing_-_final_cut_1.1.0b_(b)_(23988)-1.bin'
ARCHIVE_BASE_0_PART1_MD5=07fcaf654ce6cfb9026d1e6e40b06bf3
ARCHIVE_BASE_0_PART2_NAME='setup_the_incredible_adventures_of_van_helsing_-_final_cut_1.1.0b_(b)_(23988)-2.bin'
ARCHIVE_BASE_0_PART2_MD5=de5281e71e9d68bb196da32c09048ec9
ARCHIVE_BASE_0_PART3_NAME='setup_the_incredible_adventures_of_van_helsing_-_final_cut_1.1.0b_(b)_(23988)-3.bin'
ARCHIVE_BASE_0_PART3_MD5=721981718e036fb2fb4e848543241be7
ARCHIVE_BASE_0_PART4_NAME='setup_the_incredible_adventures_of_van_helsing_-_final_cut_1.1.0b_(b)_(23988)-4.bin'
ARCHIVE_BASE_0_PART4_MD5=dc7981e674f6400d1919d56b735854fd
ARCHIVE_BASE_0_PART5_NAME='setup_the_incredible_adventures_of_van_helsing_-_final_cut_1.1.0b_(b)_(23988)-5.bin'
ARCHIVE_BASE_0_PART5_MD5=0d9cec82a419c8abb5a7a414817e1446
ARCHIVE_BASE_0_SIZE=35870060
ARCHIVE_BASE_0_VERSION=1.1.0b-1

CONTENT_PATH_DEFAULT='.'
CONTENT_GAME_MAIN_FILES='
VanHelsing_x64.exe'
# VanHelsing_x64.exe requirements
CONTENT_LIBS_MAIN_FILES='
PhysX3_x64.dll
PhysX3Common_x64.dll
PhysX3Cooking_x64.dll
Galaxy64.dll'
CONTENT_GAME0_MAIN_FILES='
Cfg
CgShaders
CommonTextures
Effects
Models
Terrains
Textures
UI'
CONTENT_GAME1_MAIN_FILES='
Sounds/Ambient
Sounds/effects
Sounds/General
Sounds/Misc
Sounds/Music
Sounds/Options
Sounds/Shrines
Sounds/Skills
Sounds/Soldiers
Sounds/Soldiers_low
Sounds/Touchdown
Sounds/TreasureChests
Sounds/sample.ogg'
# TODO: Can videos be moved to a dedicated package?
CONTENT_GAME2_MAIN_FILES='
Sounds/Languages/ENG
Videos/ENG/*.ogg
Videos/ENG/*.webm'
CONTENT_GAME_L10N_FR_FILES='
Strings/French
UI/LoadingScreens/FR
Videos/FR/*.srt'
CONTENT_GAME_L10N_EN_FILES='
Strings/Eng
UI/LoadingScreens/ENG
Videos/ENG/*.srt'

WINE_PERSISTENT_DIRECTORIES='
users/${USER}/Documents/NeocoreGames/Van Helsing Final Cut'
WINE_REGEDIT_PERSISTENT_KEYS='
HKEY_CURRENT_USER\Software\NeoCore Games\Van Helsing Final Cut'
WINE_REGISTRY_INIT_L10N_FR='
[HKEY_CURRENT_USER\Software\NeoCore Games\Van Helsing Final Cut]
"Language"="FR"
'
WINE_REGISTRY_INIT_L10N_EN='
[HKEY_CURRENT_USER\Software\NeoCore Games\Van Helsing Final Cut]
"Language"="eng"
'

APP_MAIN_EXE='VanHelsing_x64.exe'

PACKAGES_LIST='
PKG_MAIN
PKG_L10N_FR
PKG_L10N_EN'

PKG_MAIN_ARCH=64
PKG_MAIN_DEPENDENCIES_SIBLINGS='
PKG_L10N'
PKG_MAIN_DEPENDENCIES_GSTREAMER_PLUGINS='
deinterlace
video/x-ms-asf'
# Easier upgrades from pre-20260709.1 packages
PKG_MAIN_PROVIDES='
van-helsing-final-cut-data
van-helsing-final-cut-terrains-1
van-helsing-final-cut-terrains-2
van-helsing-final-cut-terrains-3'
# Easier upgrades from pre-20251115.1 packages
PKG_MAIN_PROVIDES="$PKG_MAIN_PROVIDES
van-helsing-final-cut-l10n-common"

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

# 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
. "$PLAYIT_LIB2"

# Run default initialisation actions.

initialization_default "$@"

# Extract game data.

archive_extraction_default

# Create some empty files.
# TODO: Are they required?

touch \
	"$(path_archive_contents)/Cfg/Skills/Monster/__gargoyle_zuhanas_effect.cfg" \
	"$(path_archive_contents)/Cfg/Soldier/02_Normal_ranged/ATD_inkmachine_generalis.cfg"

# Include game data.

content_inclusion_icons
content_inclusion_default

# Write the localisations configuration.

languages_xml=$(path_game_data)/Strings/languages.xml
# French
cat > "$(package_path PKG_L10N_FR)${languages_xml}" << EOF
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<Root>
	<LanguageName>
		<FR>French</FR>
	</LanguageName>
	<Languages>FR</Languages>
</Root>
EOF
# English
cat > "$(package_path PKG_L10N_EN)${languages_xml}" << EOF
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<Root>
	<LanguageName>
		<eng>English</eng>
	</LanguageName>
	<Languages>eng</Languages>
</Root>
EOF

# Write launchers.

# Set localisation of first launch.
for package in \
	PKG_L10N_FR \
	PKG_L10N_EN
do (
	set_current_package $package
	wine_registry_script_write $package
) done
wine_registry_script_write() { return 0; }
# A dummy value is set to trigger the integration of the registry script in the generated launcher.
WINE_REGISTRY_INIT='whatever'

# Install shipped libraries.
wineprefix_init_custom() {
	cat <<- EOF
	# Install shipped libraries.
	ln --force --symbolic $(path_libraries)/* "\${PATH_PREFIX}"
	EOF
}

launchers_generation

# Build packages.

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

# Clean up.

working_directory_cleanup

exit 0
