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

###
# Knights of Pen and Paper
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260714.1

PLAYIT_COMPATIBILITY_LEVEL=2.35

GAME_ID=knights-of-pen-and-paper
GAME_NAME='Knights of Pen and Paper'

ARCHIVE_BASE_0_NAME='gog_knights_of_pen_and_paper_1_edition_2.0.0.1.sh'
ARCHIVE_BASE_0_MD5=1f387b78bfe426b9396715fbfe3499b9
ARCHIVE_BASE_0_VERSION=2.34c-1
ARCHIVE_BASE_0_SIZE=114575

UNITY3D_NAME='knightspp'
UNITY3D_PLUGINS='
ScreenSelector.so'
# Without libCSteamworks.so, characters can not be added.
# DllNotFoundException: CSteamworks
#   at (wrapper managed-to-native) Steamworks.NativeMethods:SteamAPI_InitSafe ()
#   at Steamworks.SteamAPI.Init () [0x00000] in <filename unknown>:0
#   at SteamworksManager.Initialize () [0x00000] in <filename unknown>:0
#   at SteamworksManager.SetStat (System.String stat, Int32 currValue) [0x00000] in <filename unknown>:0
#   at KoPPAchievement.setAchievementValue (System.String id, Int32 aValue) [0x00000] in <filename unknown>:0
#   at KoPPAchievement.report (System.String id, Int32 aValue) [0x00000] in <filename unknown>:0
#   at GameManager.SpendGold (Int32 amount) [0x00000] in <filename unknown>:0
#   at NewPlayerScreen.ConfirmAddPlayer () [0x00000] in <filename unknown>:0
UNITY3D_PLUGINS="$UNITY3D_PLUGINS
libCSteamworks.so
libsteam_api.so"

CONTENT_PATH_DEFAULT='data/noarch/game'
CONTENT_GAME_COMMON_FILES='
knightspp_Data/Managed/Assembly-CSharp.dll'

PACKAGES_LIST='
PKG_BIN
PKG_COMMON
PKG_DATA'

PKG_BIN_ARCH=32
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_COMMON
PKG_DATA'
PKG_BIN_DEPENDENCIES_LIBRARIES='
libc.so.6
libdl.so.2
libgcc_s.so.1
libGL.so.1
libGLU.so.1
libm.so.6
libpthread.so.0
librt.so.1
libstdc++.so.6
libX11.so.6
libXcursor.so.1'
# ScreenSelector.so
PKG_BIN_DEPENDENCIES_LIBRARIES="$PKG_BIN_DEPENDENCIES_LIBRARIES
libc.so.6
libdl.so.2
libgcc_s.so.1
libgdk_pixbuf-2.0.so.0
libglib-2.0.so.0
libgobject-2.0.so.0
libgtk-x11-2.0.so.0
libstdc++.so.6"
# Steam libraries
PKG_BIN_DEPENDENCIES_LIBRARIES="$PKG_BIN_DEPENDENCIES_LIBRARIES
libc.so.6
libdl.so.2
libgcc_s.so.1
libm.so.6
libpthread.so.0
libstdc++.so.6"

PKG_COMMON_ID=${GAME_ID}-common
PKG_COMMON_DESCRIPTION='Game data overridden by the Deluxier Edition'

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
. "$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
