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

###
# Torchlight
# send your bug reports to vv221@dotslashplay.it
###

script_version=20260321.1

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='torchlight-1'
GAME_NAME='Torchlight'

ARCHIVE_BASE_1_NAME='setup_torchlight_1.15(a)_(23675).exe'
ARCHIVE_BASE_1_MD5='a29e51f55aae740f4046d227d33fa64b'
ARCHIVE_BASE_1_TYPE='innosetup'
ARCHIVE_BASE_1_SIZE='453318'
ARCHIVE_BASE_1_VERSION='1.15-gog23675'
ARCHIVE_BASE_1_URL='https://www.gog.com/game/torchlight'

ARCHIVE_BASE_0_NAME='setup_torchlight_2.0.0.12.exe'
ARCHIVE_BASE_0_MD5='4b721e1b3da90f170d66f42e60a3fece'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_SIZE='460000'
ARCHIVE_BASE_0_VERSION='1.15-gog2.0.0.12'

CONTENT_PATH_DEFAULT='.'
CONTENT_PATH_DEFAULT_0='app'
CONTENT_GAME_BIN_FILES='
Plugins.cfg
resources.cfg
Torchlight.exe'
# Torchlight.exe requirements
CONTENT_LIBS_BIN_FILES='
OgreMain.dll
fmodex.dll
ParticleUniverse.dll
CEGUIBase.dll
OgreGUIRenderer.dll'
# The game crashes on launch if any of the following libraries is missing.
CONTENT_LIBS0_BIN_FILES='
RenderSystem_Direct3D9.dll
Plugin_ParticleFX.dll
Plugin_CgProgramManager.dll
Plugin_OctreeSceneManager.dll'
# Plugin_CgProgramManager.dll requirements
CONTENT_LIBS1_BIN_FILES='
cg.dll'
# The game crashes before reaching the initial loading screen if any of the following libraries is missig.
CONTENT_LIBS2_BIN_FILES='
CEGUIExpatParser.dll
CEGUIFalagardWRBase.dll'
CONTENT_GAME_DATA_FILES='
icons
music
programs
logo.bmp
BuildVer.txt
Pak.zip'
CONTENT_DOC_DATA_FILES='
TorchlightManual.pdf'

WINE_PERSISTENT_DIRECTORIES='
users/${USER}/AppData/Roaming/runic games/torchlight'

APP_MAIN_EXE='Torchlight.exe'
APP_MAIN_ICON='Torchlight.ico'

PACKAGES_LIST='
PKG_BIN
PKG_DATA'

PKG_BIN_ARCH='32'
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'
content_inclusion_default

# Write launchers.

# 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
print_instructions

# Clean up.

working_directory_cleanup

exit 0
