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

###
# Star Wars: Battlefront 2
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260416.2

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='star-wars-battlefront-2'
GAME_NAME='Star Wars: Battlefront II'

ARCHIVE_BASE_1_NAME='setup_star_wars_battlefront_ii_1.1_(10935).exe'
ARCHIVE_BASE_1_MD5='0b74c1d7cced6d6bde95605661b67673'
ARCHIVE_BASE_1_TYPE='innosetup'
ARCHIVE_BASE_1_PART1_NAME='setup_star_wars_battlefront_ii_1.1_(10935)-1.bin'
ARCHIVE_BASE_1_PART1_MD5='c7ad88e5eb89b3701dad3a6973d9918b'
ARCHIVE_BASE_1_PART2_NAME='setup_star_wars_battlefront_ii_1.1_(10935)-2.bin'
ARCHIVE_BASE_1_PART2_MD5='3a52d98aa43cb78fd661a656e5cf96a2'
ARCHIVE_BASE_1_SIZE='10000000'
ARCHIVE_BASE_1_VERSION='1.1-gog10935'
ARCHIVE_BASE_1_URL='https://www.gog.com/game/star_wars_battlefront_ii'

ARCHIVE_BASE_0_NAME='setup_star_wars_battlefront_ii_1.1_multiplayer_update_2_(17606).exe'
ARCHIVE_BASE_0_MD5='f482ec251067336d3b8211774b4c44f6'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_PART1_NAME='setup_star_wars_battlefront_ii_1.1_multiplayer_update_2_(17606)-1.bin'
ARCHIVE_BASE_0_PART1_MD5='c34b41f594e55b1522d8826f19cf958f'
ARCHIVE_BASE_0_PART2_NAME='setup_star_wars_battlefront_ii_1.1_multiplayer_update_2_(17606)-2.bin'
ARCHIVE_BASE_0_PART2_MD5='c9423f3983c67575c1c531e0d18e6a0f'
ARCHIVE_BASE_0_SIZE='11000000'
ARCHIVE_BASE_0_VERSION='1.1-gog17606'

ARCHIVE_OPTIONAL_ICONS_NAME='star-wars-battlefront-2_icons.tar.gz'
ARCHIVE_OPTIONAL_ICONS_MD5='322275011d37ac219f1c06c196477fa4'
ARCHIVE_OPTIONAL_ICONS_URL='http://downloads.dotslashplay.it/games/star-wars-battlefront-2/'
CONTENT_ICONS_PATH='.'
CONTENT_ICONS_FILES='
16x16
32x32'

CONTENT_PATH_DEFAULT='GameData'
CONTENT_GAME_BIN_FILES='
BattlefrontII.exe'
# TODO: Install libraries in a standard path.
# TODO: Drop unused libraries.
CONTENT_GAME0_BIN_FILES='
binkw32.dll
eax.dll
unicows.dll'
CONTENT_GAME_MOVIES_FILES='
data/_lvl_pc/movies'
CONTENT_GAME_DATA_FILES='
data'
CONTENT_DOC_DATA_PATH='.'
CONTENT_DOC_DATA_FILES='
Manual.pdf'

USER_PERSISTENT_DIRECTORIES='
SaveGames'
USER_PERSISTENT_FILES='
*.ini'

APP_MAIN_EXE='BattlefrontII.exe'

PACKAGES_LIST='
PKG_BIN
PKG_MOVIES
PKG_DATA'

PKG_BIN_ARCH='32'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_MOVIES
PKG_DATA'

PKG_MOVIES_ID="${GAME_ID}-movies"
PKG_MOVIES_DESCRIPTION='movies'

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.

launchers_generation

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
