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

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

script_version=20260414.1

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='ballisticng'
GAME_NAME='BallisticNG'

ARCHIVE_BASE_7_NAME='ballisticng_1_4_1_3_89966.sh'
ARCHIVE_BASE_7_MD5='3d6cb02350c7a93467d4e702560d6a96'
ARCHIVE_BASE_7_SIZE='3449398'
ARCHIVE_BASE_7_VERSION='1.4.1.3-gog89966'
ARCHIVE_BASE_7_URL='https://www.gog.com/game/ballisticng'

ARCHIVE_BASE_6_NAME='ballisticng_1_4_1_2_89013.sh'
ARCHIVE_BASE_6_MD5='3c0891e033e4efaa20b8f4af8f9218d5'
ARCHIVE_BASE_6_SIZE='3430475'
ARCHIVE_BASE_6_VERSION='1.4.1.2-gog89013'

ARCHIVE_BASE_5_NAME='ballisticng_1_4_1_1_87257.sh'
ARCHIVE_BASE_5_MD5='ee9ecebb26e5580d057d2ea1e897b66e'
ARCHIVE_BASE_5_SIZE='3430475'
ARCHIVE_BASE_5_VERSION='1.4.1.1-gog87257'

ARCHIVE_BASE_4_NAME='ballisticng_1_4_1b_86951.sh'
ARCHIVE_BASE_4_MD5='fe6e6d0cf71aef856bfbf1cddd8ac360'
ARCHIVE_BASE_4_SIZE='3430475'
ARCHIVE_BASE_4_VERSION='1.4.1b-gog86951'

ARCHIVE_BASE_3_NAME='ballisticng_1_4_1_86271.sh'
ARCHIVE_BASE_3_MD5='e50a92e232d519ba942e79c8b98652e4'
ARCHIVE_BASE_3_SIZE='3430475'
ARCHIVE_BASE_3_VERSION='1.4.1-gog86271'

ARCHIVE_BASE_2_NAME='ballisticng_1_4_0_1b_81954.sh'
ARCHIVE_BASE_2_MD5='3adf1cbf124a48baccb987473eec85ea'
ARCHIVE_BASE_2_SIZE='3381101'
ARCHIVE_BASE_2_VERSION='1.4.0.1b-gog81954'

ARCHIVE_BASE_1_NAME='ballisticng_1_4_0_1_81860.sh'
ARCHIVE_BASE_1_MD5='beedfb6afab94fc66783c12b805876df'
ARCHIVE_BASE_1_SIZE='3380551'
ARCHIVE_BASE_1_VERSION='1.4.0.1-gog81860'

ARCHIVE_BASE_0_NAME='ballisticng_1_3_3_1_69502.sh'
ARCHIVE_BASE_0_MD5='4fd3dd5695e9f94523bb699df024dbee'
ARCHIVE_BASE_0_SIZE='2749158'
ARCHIVE_BASE_0_VERSION='1.3.3.1-gog69502'

UNITY3D_NAME='BallisticNG'
UNITY3D_PLUGINS='
cimgui.so
libaudioplugin_phonon.so
libphonon.so'
# Starting with game version 1.4,
# the game no longer loads without the shipped Steam library.
UNITY3D_PLUGINS="$UNITY3D_PLUGINS
libsteam_api.so"

CONTENT_PATH_DEFAULT='data/noarch/game'
CONTENT_GAME_EXPANSION_TRACKS_FILES='
DLC/free extra tracks.cpd
DLC/free extra tracks.cps'
CONTENT_GAME_EXPANSION_VOICES_FILES='
User/Mods/Sounds/Legacy System Voices'
CONTENT_GAME_MODDING_FILES='
Modding'
CONTENT_DOC_DATA_FILES='
Legacy Track Creator Commands.txt'

USER_PERSISTENT_DIRECTORIES='
User'

PACKAGES_LIST='
PKG_BIN
PKG_EXPANSION_TRACKS
PKG_EXPANSION_VOICES
PKG_MODDING
PKG_DATA'

PKG_BIN_ARCH='64'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_DATA'
PKG_BIN_DEPENDENCIES_LIBRARIES='
libc.so.6
libdl.so.2
libgcc_s.so.1
libm.so.6
libpthread.so.0
librt.so.1
libstdc++.so.6
libz.so.1'

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

PKG_EXPANSION_TRACKS_ID="${GAME_ID}-expansion-free-extra-tracks"
PKG_EXPANSION_TRACKS_DESCRIPTION='expansion - free extra tracks'
PKG_EXPANSION_TRACKS_DEPENDENCIES_SIBLINGS='
PKG_BIN'

PKG_EXPANSION_VOICES_ID="${GAME_ID}-expansion-legacy-system-voices"
PKG_EXPANSION_VOICES_DESCRIPTION='expansion - legacy system voices'
PKG_EXPANSION_VOICES_DEPENDENCIES_SIBLINGS='
PKG_BIN'

PKG_MODDING_ID="${GAME_ID}-modding"
PKG_MODDING_DESCRIPTION='modding'
PKG_MODDING_DEPENDENCIES_SIBLINGS='
PKG_BIN'

# 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
