#!/bin/sh
# SPDX-License-Identifier: BSD-2-Clause
# SPDX-FileCopyrightText: © 2020 BetaRays <array@dotslashplay.it>
# SPDX-FileCopyrightText: © 2020 Antoine Le Gonidec <vv221@dotslashplay.it>
# SPDX-FileCopyrightText: © 2026 Locynaeh <contact@locynaeh.fr>
set -o errexit

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

script_version=20260514.1

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='celeste'
GAME_NAME='Celeste'

ARCHIVE_BASE_2_NAME='celeste-linux.zip'
ARCHIVE_BASE_2_MD5='300820953d5799746633f1c84cb6049c'
ARCHIVE_BASE_2_SIZE='1176905'
ARCHIVE_BASE_2_VERSION='1.4.0.0-itch.2025.02.07'
ARCHIVE_BASE_2_URL='https://maddymakesgamesinc.itch.io/celeste'

ARCHIVE_BASE_1_NAME='celeste-linux.zip'
ARCHIVE_BASE_1_MD5='518ea69d60079109a2575d428eff8a53'
ARCHIVE_BASE_1_SIZE='1176905'
ARCHIVE_BASE_1_VERSION='1.4.0.0-itch.2021.03.29'

ARCHIVE_BASE_0_NAME='celeste-linux.zip'
ARCHIVE_BASE_0_MD5='b27c983b95b2a2a35a272b7ecd94cbc2'
ARCHIVE_BASE_0_SIZE='1400000'
ARCHIVE_BASE_0_VERSION='1.3.1.2-itch'

CONTENT_PATH_DEFAULT='.'
CONTENT_LIBS_LIBS_PATH='lib64'
CONTENT_LIBS_LIBS_FILES='
libfmod.so.10
libfmodstudio.so.10
libfmod_SDL.so
libFNA3D.so.0'
CONTENT_GAME_MAIN_FILES='
Content
Celeste.exe
Celeste.exe.config
Celeste.png
gamecontrollerdb.txt
Celeste.Content.dll
FNA.dll
FNA.dll.config
FNA3D.dll'

APP_MAIN_EXE='Celeste.exe'
APP_MAIN_ICON='Celeste.png'

PACKAGES_LIST='
PKG_MAIN
PKG_LIBS'

PKG_MAIN_DEPENDENCIES_SIBLINGS='
PKG_LIBS'
PKG_MAIN_DEPENDENCIES_LIBRARIES='
libGL.so.1
libSDL2-2.0.so.0
libSDL2_image-2.0.so.0'
PKG_MAIN_DEPENDENCIES_MONO_LIBRARIES='
mscorlib.dll
Mono.Posix.dll
Mono.Security.dll
System.dll
System.Configuration.dll
System.Core.dll
System.Data.dll
System.Drawing.dll
System.Numerics.dll
System.Runtime.Serialization.dll
System.Security.dll
System.Xml.dll
System.Xml.Linq.dll'

PKG_LIBS_ID="${GAME_ID}-libs"
PKG_LIBS_ARCH='64'
PKG_LIBS_DEPENDENCIES_LIBRARIES='
libc.so.6
libdl.so.2
libm.so.6
libpthread.so.0
librt.so.1
libSDL2-2.0.so.0
libstdc++.so.6'

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

# Write launchers.

# Shipped libraries expect an executable stack.
game_exec_line() {
	cat <<- 'EOF'
	GLIBC_TUNABLES=glibc.rtld.execstack=2 mono Celeste.exe "$@"
	EOF
}

launchers_generation

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
