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

###
# Ravenous Devils
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260331.2

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='ravenous-devils'
GAME_NAME='Ravenous Devils'

ARCHIVE_BASE_1_NAME='setup_ravenous_devils_1.0.2_(64bit)_(59454).exe'
ARCHIVE_BASE_1_MD5='efe01e3e15054928ea1b91777d0481bf'
ARCHIVE_BASE_1_TYPE='innosetup'
ARCHIVE_BASE_1_SIZE='1800000'
ARCHIVE_BASE_1_VERSION='1.0.2-gog59454'
ARCHIVE_BASE_1_URL='https://www.gog.com/game/ravenous_devils'

ARCHIVE_BASE_0_NAME='setup_ravenous_devils_1.0.1_(64bit)_(55400).exe'
ARCHIVE_BASE_0_MD5='e18ae8a3932ebcfeaa742cd9f849af4c'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_SIZE='1800000'
ARCHIVE_BASE_0_VERSION='1.0.1-gog55400'

UNREALENGINE4_NAME='Ravenous_Devils'

CONTENT_PATH_DEFAULT='.'
# TODO: Drop unused libraries.
CONTENT_LIBS_BIN_FILES='
Engine/Binaries/ThirdParty/DbgHelp/dbghelp.dll
Engine/Binaries/ThirdParty/NVIDIA/GeForceNOW/Win64/GfnRuntimeSdk.dll
Engine/Binaries/ThirdParty/NVIDIA/NVaftermath/Win64/GFSDK_Aftermath_Lib.x64.dll
Engine/Binaries/ThirdParty/Ogg/Win64/VS2015/libogg_64.dll
Engine/Binaries/ThirdParty/OpenXR/win64/openxr_loader.dll
Engine/Binaries/ThirdParty/PhysX3/Win64/VS2015/ApexFramework_x64.dll
Engine/Binaries/ThirdParty/PhysX3/Win64/VS2015/APEX_Clothing_x64.dll
Engine/Binaries/ThirdParty/PhysX3/Win64/VS2015/APEX_Legacy_x64.dll
Engine/Binaries/ThirdParty/PhysX3/Win64/VS2015/NvCloth_x64.dll
Engine/Binaries/ThirdParty/PhysX3/Win64/VS2015/PhysX3_x64.dll
Engine/Binaries/ThirdParty/PhysX3/Win64/VS2015/PhysX3Common_x64.dll
Engine/Binaries/ThirdParty/PhysX3/Win64/VS2015/PhysX3Cooking_x64.dll
Engine/Binaries/ThirdParty/PhysX3/Win64/VS2015/PxFoundation_x64.dll
Engine/Binaries/ThirdParty/PhysX3/Win64/VS2015/PxPvdSDK_x64.dll
Engine/Binaries/ThirdParty/Vorbis/Win64/VS2015/libvorbis_64.dll
Engine/Binaries/ThirdParty/Vorbis/Win64/VS2015/libvorbisfile_64.dll
Engine/Binaries/ThirdParty/Windows/XAudio2_9/x64/xaudio2_9redist.dll'
CONTENT_LIBS0_BIN_FILES="
${UNREALENGINE4_NAME}/Binaries/Win64/OpenImageDenoise.dll
${UNREALENGINE4_NAME}/Binaries/Win64/tbb12.dll"
# TODO: Check if the Steam library is required.
CONTENT_LIBS1_BIN_FILES='
Engine/Binaries/ThirdParty/Steamworks/Steamv151/Win64/steam_api64.dll'
# TODO: Check if the Galaxy library is required.
CONTENT_LIBS2_BIN_FILES="
${UNREALENGINE4_NAME}/Plugins/OnlineSubsystemGOG/Source/ThirdParty/GalaxySDK/Libraries/Galaxy64.dll"

APP_MAIN_EXE='Ravenous_Devils.exe'

PACKAGES_LIST='
PKG_BIN
PKG_DATA'

PKG_BIN_ARCH='64'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_DATA'

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 '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'
# Prevent inclusion of unwanted libraries.
content_inclusion_default_libraries 'PKG_BIN'
rm --recursive \
	"$(path_archive_contents)/Engine/Binaries" \
	"$(path_archive_contents)/$(unrealengine4_name)/Plugins"
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
