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

###
# Bombshell
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260415.5

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='bombshell'
GAME_NAME='Bombshell'

ARCHIVE_BASE_0_NAME='setup_bombshell__1.2.10466(ion_furry)_(34762).exe'
ARCHIVE_BASE_0_MD5='05b5188629b378360154420be32296aa'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_PART1_NAME='setup_bombshell__1.2.10466(ion_furry)_(34762)-1.bin'
ARCHIVE_BASE_0_PART1_MD5='9a779d8df62ca33c5215ac7f3403f999'
ARCHIVE_BASE_0_PART2_NAME='setup_bombshell__1.2.10466(ion_furry)_(34762)-2.bin'
ARCHIVE_BASE_0_PART2_MD5='186058e6d9058ed65ffaf4382ce8a1a0'
ARCHIVE_BASE_0_SIZE='9100000'
ARCHIVE_BASE_0_VERSION='1.2.10466-gog34762'
ARCHIVE_BASE_0_URL='https://www.gog.com/game/bombshell'

GAME_ENGINE='unrealengine3'

CONTENT_PATH_DEFAULT='.'
# TODO: Drop unused libraries.
CONTENT_LIBS_BIN_FILES='
Binaries/Win64/AgentInterface.dll
Binaries/Win64/APEX_ClothingCHECKED_x64.dll
Binaries/Win64/APEX_ClothingGPUCHECKED_x64.dll
Binaries/Win64/APEX_ClothingGPUPROFILE_x64.dll
Binaries/Win64/APEX_ClothingPROFILE_x64.dll
Binaries/Win64/APEX_DestructibleCHECKED_x64.dll
Binaries/Win64/APEX_DestructiblePROFILE_x64.dll
Binaries/Win64/ApexFrameworkCHECKED_x64.dll
Binaries/Win64/ApexFrameworkPROFILE_x64.dll
Binaries/Win64/APEX_LegacyCHECKED_x64.dll
Binaries/Win64/APEX_LegacyPROFILE_x64.dll
Binaries/Win64/APEX_ParticlesCHECKED_x64.dll
Binaries/Win64/APEX_ParticlesPROFILE_x64.dll
Binaries/Win64/APEX_TurbulenceFSCHECKED_x64.dll
Binaries/Win64/APEX_TurbulenceFSPROFILE_x64.dll
Binaries/Win64/atc_api.dll
Binaries/Win64/bink2w64.dll
Binaries/Win64/cudart64_60.dll
Binaries/Win64/EasyHook64.dll
Binaries/Win64/FxGraphLayout_x64.dll
Binaries/Win64/Galaxy64.dll
Binaries/Win64/GalaxyPeer64.dll
Binaries/Win64/GFSDK_PSM.win64.dll
Binaries/Win64/GFSDK_SSAO.win64.dll
Binaries/Win64/GFSDK_TXAA_AlphaPreserve.win64.dll
Binaries/Win64/GFSDK_TXAA_AlphaResolve.win64.dll
Binaries/Win64/GFSDK_TXAA.win64.dll
Binaries/Win64/GRB_1_x64.dll
Binaries/Win64/libapexeditorwidgets_x64_profile.dll
Binaries/Win64/libogg_64.dll
Binaries/Win64/libresample_x64.dll
Binaries/Win64/libvorbis_64.dll
Binaries/Win64/libvorbisfile_64.dll
Binaries/Win64/nvToolsExt64_1.dll
Binaries/Win64/nvtt_64.dll
Binaries/Win64/NxCharacter64.dll
Binaries/Win64/PhysX3GpuCHECKED_x64.dll
Binaries/Win64/PhysX3GpuPROFILE_x64.dll
Binaries/Win64/PhysXCooking64.dll
Binaries/Win64/PhysXCore64.dll
Binaries/Win64/PhysXDevice64.dll
Binaries/Win64/PhysXExtensions64.dll
Binaries/Win64/PhysXLoader64.dll
Binaries/Win64/tbbmalloc.dll
Binaries/Win64/WindowsTools_x64.dll
Binaries/Win64/wxmsw28u_adv_vc_custom_64.dll
Binaries/Win64/wxmsw28u_aui_vc_custom_64.dll
Binaries/Win64/wxmsw28u_core_vc_custom_64.dll
Binaries/Win64/wxmsw28u_html_vc_custom_64.dll
Binaries/Win64/wxmsw28u_richtext_vc_custom_64.dll
Binaries/Win64/wxmsw28u_vc_custom_64.dll
Binaries/Win64/wxmsw28u_xml_vc_custom_64.dll
Binaries/Win64/wxmsw28u_xrc_vc_custom_64.dll'
CONTENT_GAME_BIN_FILES='
Engine
Binaries/Win64/Bombshell.exe'
CONTENT_GAME_DATA_FILES='
ShellGame'
CONTENT_DOC_DATA_PATH='Help'
CONTENT_DOC_DATA_FILES='
GDF_FieldManual.pdf'

WINE_PERSISTENT_DIRECTORIES='
users/${USER}/Documents/My Games/Bombshell/ShellGame/Save'
WINE_WINEPREFIX_TWEAKS='mono'

APP_MAIN_EXE='Binaries/Win64/Bombshell.exe'
APP_MAIN_ICON_WRESTOOL_OPTIONS='--type=14 --name=117'
# The application type must be set explicitly,
# or it would be wrongly guessed as a Mono one.
APP_MAIN_TYPE='wine'

PACKAGES_LIST='
PKG_BIN
PKG_DATA'

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

PKG_BIN_ARCH='64'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_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 '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

# Include game data.

content_inclusion_icons 'PKG_DATA'
content_inclusion_default

# Write launchers.

# Install shipped libraries.
wineprefix_init_custom() {
	cat <<- EOF
	# Install shipped libraries.
	PATH_LIBRARIES_SYSTEM='$(path_libraries)'
	EOF
	cat <<- 'EOF'
	find "$PATH_LIBRARIES_SYSTEM" -iname '*.dll' | while read -r dll_source; do
		dll_destination="${PATH_PREFIX}${dll_source#"${PATH_LIBRARIES_SYSTEM}"}"
	    mkdir --parents "$(dirname "$dll_destination")"
	    ln --symbolic --force "$dll_source" "$dll_destination"
	done
	EOF
}

launchers_generation

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
