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

###
# Cats Hidden in Places:
# - Cats Hidden in Paris
# - Cats Hidden in Italy
# - Cats Hidden in Bali
# - Cats Hidden in Maple Hollow
# - Cats Hidden in Georgia
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260421.2

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID_PARIS='cats-hidden-in-paris'
GAME_NAME_PARIS='Cats Hidden in Paris'

GAME_ID_ITALY='cats-hidden-in-italy'
GAME_NAME_ITALY='Cats Hidden in Italy'

GAME_ID_BALI='cats-hidden-in-bali'
GAME_NAME_BALI='Cats Hidden in Bali'

GAME_ID_MAPLE='cats-hidden-in-maple-hollow'
GAME_NAME_MAPLE='Cats Hidden in Maple Hollow'

GAME_ID_GEORGIA='cats-hidden-in-georgia'
GAME_NAME_GEORGIA='Cats Hidden in Georgia'

# Cats Hidden in Paris

ARCHIVE_BASE_PARIS_0_NAME='setup_cats_hidden_in_paris_1.0_gog_dlc_fix6_(69829).exe'
ARCHIVE_BASE_PARIS_0_MD5='6b55ff57a52f1edd2990133737c870cd'
ARCHIVE_BASE_PARIS_0_TYPE='innosetup'
ARCHIVE_BASE_PARIS_0_SIZE='106572'
ARCHIVE_BASE_PARIS_0_VERSION='1.0-gog69829'
ARCHIVE_BASE_PARIS_0_URL='https://www.gog.com/game/cats_hidden_in_paris'

# Cats Hidden in Italy

ARCHIVE_BASE_ITALY_0_NAME='setup_cats_hidden_in_italy_1.0_gog_savefix_proper_(69657).exe'
ARCHIVE_BASE_ITALY_0_MD5='7564fdad50e6e655cb16bca17db30058'
ARCHIVE_BASE_ITALY_0_TYPE='innosetup'
ARCHIVE_BASE_ITALY_0_SIZE='102010'
ARCHIVE_BASE_ITALY_0_VERSION='1.0-gog69657'
ARCHIVE_BASE_ITALY_0_URL='https://www.gog.com/game/cats_hidden_in_italy'

# Cats Hidden in Bali

ARCHIVE_BASE_BALI_0_NAME='setup_cats_hidden_in_bali_1.0_gog_(69565).exe'
ARCHIVE_BASE_BALI_0_MD5='23ce61713a61919f9724a3377feca967'
ARCHIVE_BASE_BALI_0_TYPE='innosetup'
ARCHIVE_BASE_BALI_0_SIZE='104429'
ARCHIVE_BASE_BALI_0_VERSION='1.0-gog69565'
ARCHIVE_BASE_BALI_0_URL='https://www.gog.com/game/cats_hidden_in_bali'

# Cats Hidden in Maple Hollow

ARCHIVE_BASE_MAPLE_0_NAME='setup_cats_hidden_in_maple_hollow_1.0_gog_(69635).exe'
ARCHIVE_BASE_MAPLE_0_MD5='2a3c9c4b7bc81efd01d62e45cf8f43e3'
ARCHIVE_BASE_MAPLE_0_TYPE='innosetup'
ARCHIVE_BASE_MAPLE_0_SIZE='97744'
ARCHIVE_BASE_MAPLE_0_VERSION='1.0-gog69635'
ARCHIVE_BASE_MAPLE_0_URL='https://www.gog.com/game/cats_hidden_in_maple_hollow'

# Cats Hidden in Georgia

ARCHIVE_BASE_GEORGIA_0_NAME='setup_cats_hidden_in_georgia_0313_gog_(71893).exe'
ARCHIVE_BASE_GEORGIA_0_MD5='20dd463acabc0ad5cdaf0bfa958dfb4f'
ARCHIVE_BASE_GEORGIA_0_TYPE='innosetup'
ARCHIVE_BASE_GEORGIA_0_SIZE='120629'
ARCHIVE_BASE_GEORGIA_0_VERSION='0313-gog71893'
ARCHIVE_BASE_GEORGIA_0_URL='https://www.gog.com/game/cats_hidden_in_georgia'

CONTENT_PATH_DEFAULT='.'
CONTENT_GAME_BIN_FILES_PARIS='
Cats Hidden in Paris.exe'
CONTENT_GAME_BIN_FILES_ITALY='
Cats Hidden in Italy.exe'
CONTENT_GAME_BIN_FILES_BALI='
Cats Hidden in Bali.exe'
CONTENT_GAME_BIN_FILES_MAPLE='
Cats Hidden in Maple Hollow.exe'
CONTENT_GAME_BIN_FILES_GEORGIA='
Cats Hidden in Georgia.exe'
# TODO: Drop unused libraries.
# TODO: Install libraries in a standard path.
CONTENT_GAME0_BIN_FILES='
Modules/advapi32.dll
Modules/cctrans.dll
Modules/kernel32.dll
Modules/mmf2d3d8.dll
Modules/mmf2d3d9.dll
Modules/mmfs2.dll
Modules/user32.dll'
# TODO: Check if the Galaxy library is required.
CONTENT_GAME1_BIN_FILES='
Modules/Galaxy.dll'
# TODO: Check if the Steam library is required.
CONTENT_GAME2_BIN_FILES='
Modules/steam_api.dll'
CONTENT_GAME3_BIN_FILES='
Modules/*.sft
Modules/*.mfx
Modules/*.mvx'
CONTENT_GAME_DATA_FILES_PARIS='
Cats Hidden in Paris.dat'
CONTENT_GAME_DATA_FILES_ITALY='
Cats Hidden in Italy.dat'
CONTENT_GAME_DATA_FILES_BALI='
Cats Hidden in Bali.dat'
CONTENT_GAME_DATA_FILES_MAPLE='
Cats Hidden in Maple Hollow.dat'
CONTENT_GAME_DATA_FILES_GEORGIA='
Cats Hidden in Georgia.dat'
CONTENT_GAME0_DATA_FILES='
sounds'

WINE_PERSISTENT_DIRECTORIES_PARIS='
users/${USER}/AppData/Roaming/Cats Hidden in Paris'
WINE_PERSISTENT_DIRECTORIES_ITALY='
users/${USER}/AppData/Roaming/Cats Hidden in Italy'
WINE_PERSISTENT_DIRECTORIES_BALI='
users/${USER}/AppData/Roaming/Cats Hidden in Bali'
WINE_PERSISTENT_DIRECTORIES_MAPLE='
users/${USER}/AppData/Roaming/Cats Hidden in Maple Hollow'
WINE_PERSISTENT_DIRECTORIES_GEORGIA='
users/${USER}/AppData/Roaming/Cats Hidden in Georgia'

APP_MAIN_EXE_PARIS='Cats Hidden in Paris.exe'
APP_MAIN_EXE_ITALY='Cats Hidden in Italy.exe'
APP_MAIN_EXE_BALI='Cats Hidden in Bali.exe'
APP_MAIN_EXE_MAPLE='Cats Hidden in Maple Hollow.exe'
APP_MAIN_EXE_GEORGIA='Cats Hidden in Georgia.exe'

PACKAGES_LIST='
PKG_BIN
PKG_DATA'

PKG_BIN_ARCH='32'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_DATA'

PKG_DATA_ID_PARIS="${GAME_ID_PARIS}-data"
PKG_DATA_ID_ITALY="${GAME_ID_ITALY}-data"
PKG_DATA_ID_BALI="${GAME_ID_BALI}-data"
PKG_DATA_ID_MAPLE="${GAME_ID_MAPLE}-data"
PKG_DATA_ID_GEORGIA="${GAME_ID_GEORGIA}-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
