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

###
# Mirror's Edge
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260521.6

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='mirrors-edge'
GAME_NAME='Mirrorʼs Edge'

ARCHIVE_BASE_2_NAME='setup_mirrors_edge_1.01_jpfix_(41238).exe'
ARCHIVE_BASE_2_MD5='58078b7594476adf72d58dc01e024327'
ARCHIVE_BASE_2_TYPE='innosetup'
ARCHIVE_BASE_2_PART1_NAME='setup_mirrors_edge_1.01_jpfix_(41238)-1.bin'
ARCHIVE_BASE_2_PART1_MD5='9a202aeca8eaa63d18c24fcdc62a7890'
ARCHIVE_BASE_2_PART2_NAME='setup_mirrors_edge_1.01_jpfix_(41238)-2.bin'
ARCHIVE_BASE_2_PART2_MD5='3ee19c143f7d85e5393fc51d705ed61c'
ARCHIVE_BASE_2_PART3_NAME='setup_mirrors_edge_1.01_jpfix_(41238)-3.bin'
ARCHIVE_BASE_2_PART3_MD5='2a961e5b6f2ce2ef42169c0a023e5c4c'
ARCHIVE_BASE_2_SIZE='12000000'
ARCHIVE_BASE_2_VERSION='1.01-gog41238'
ARCHIVE_BASE_2_URL='https://www.gog.com/game/mirrors_edge'

ARCHIVE_BASE_1_NAME='setup_mirrors_edge_1.01_(40566).exe'
ARCHIVE_BASE_1_MD5='f0faffb76a2b46c3aca8342265a5f41b'
ARCHIVE_BASE_1_TYPE='innosetup'
ARCHIVE_BASE_1_PART1_NAME='setup_mirrors_edge_1.01_(40566)-1.bin'
ARCHIVE_BASE_1_PART1_MD5='cdfea6d6412de910eae6748eeb6af54e'
ARCHIVE_BASE_1_PART2_NAME='setup_mirrors_edge_1.01_(40566)-2.bin'
ARCHIVE_BASE_1_PART2_MD5='6b4a66c9ac31c8c2f4e647957c64370a'
ARCHIVE_BASE_1_PART3_NAME='setup_mirrors_edge_1.01_(40566)-3.bin'
ARCHIVE_BASE_1_PART3_MD5='8529e17c8faa54be07219106ffe00774'
ARCHIVE_BASE_1_SIZE='12000000'
ARCHIVE_BASE_1_VERSION='1.01-gog40566'

ARCHIVE_BASE_0_NAME='setup_mirrors_edge_2.0.0.3.exe'
ARCHIVE_BASE_0_MD5='89381d67169f5c6f8f300e172a64f99c'
ARCHIVE_BASE_0_EXTRACTOR='innoextract'
ARCHIVE_BASE_0_EXTRACTOR_OPTIONS='--gog'
ARCHIVE_BASE_0_PART1_NAME='setup_mirrors_edge_2.0.0.3-1.bin'
ARCHIVE_BASE_0_PART1_MD5='406b99108e1edd17fc60435d1f2c27f9'
ARCHIVE_BASE_0_PART1_TYPE='rar'
ARCHIVE_BASE_0_PART2_NAME='setup_mirrors_edge_2.0.0.3-2.bin'
ARCHIVE_BASE_0_PART2_MD5='18f2bd62201904c8e98a4b805a90ab2d'
ARCHIVE_BASE_0_PART2_TYPE='rar'
ARCHIVE_BASE_0_SIZE='7700000'
ARCHIVE_BASE_0_VERSION='1.0-gog2.0.0.3'

GAME_ENGINE='unrealengine3'

CONTENT_PATH_DEFAULT='.'
CONTENT_PATH_DEFAULT_0='game'
CONTENT_GAME_BIN_FILES='
Binaries/MirrorsEdge.exe'
CONTENT_GAME0_BIN_FILES='
Engine/Config
Engine/Shaders'
# TODO: Drop unused libraries.
# TODO: Install libraries in a standard path.
CONTENT_GAME1_BIN_FILES='
Binaries/binkw32.dll
Binaries/DMCmdPortalClient.dll
Binaries/ILPointCloudLib.dll
Binaries/libresample.dll
Binaries/NxCharacter.dll
Binaries/NxCooking.dll
Binaries/ogg.dll
Binaries/OpenAL32.dll
Binaries/PhysXDevice.dll
Binaries/PhysXExtensions.dll
Binaries/PhysXLoader.dll
Binaries/PhysXLocal/PhysXLoader.dll
Binaries/vorbis.dll
Binaries/vorbisenc.dll
Binaries/vorbisfile.dll
Binaries/wrap_oal.dll
Binaries/wxmsw28u_adv_vc_custom.dll
Binaries/wxmsw28u_aui_vc_custom.dll
Binaries/wxmsw28u_core_vc_custom.dll
Binaries/wxmsw28ud_adv_vc_custom.dll
Binaries/wxmsw28ud_aui_vc_custom.dll
Binaries/wxmsw28u_dbgrid_vc_custom.dll
Binaries/wxmsw28ud_core_vc_custom.dll
Binaries/wxmsw28ud_dbgrid_vc_custom.dll
Binaries/wxmsw28ud_gl_vc_custom.dll
Binaries/wxmsw28ud_html_vc_custom.dll
Binaries/wxmsw28ud_media_vc_custom.dll
Binaries/wxmsw28ud_net_vc_custom.dll
Binaries/wxmsw28ud_odbc_vc_custom.dll
Binaries/wxmsw28ud_qa_vc_custom.dll
Binaries/wxmsw28ud_richtext_vc_custom.dll
Binaries/wxmsw28ud_vc_custom.dll
Binaries/wxmsw28ud_xml_vc_custom.dll
Binaries/wxmsw28ud_xrc_vc_custom.dll
Binaries/wxmsw28u_gl_vc_custom.dll
Binaries/wxmsw28u_html_vc_custom.dll
Binaries/wxmsw28u_media_vc_custom.dll
Binaries/wxmsw28u_net_vc_custom.dll
Binaries/wxmsw28u_odbc_vc_custom.dll
Binaries/wxmsw28u_qa_vc_custom.dll
Binaries/wxmsw28u_richtext_vc_custom.dll
Binaries/wxmsw28u_vc_custom.dll
Binaries/wxmsw28u_xml_vc_custom.dll
Binaries/wxmsw28u_xrc_vc_custom.dll'
# TODO: Check if the Steam library is required.
CONTENT_GAME2_BIN_FILES='
Binaries/steam_api.dll'
# TODO: Check if this .bak file is required.
CONTENT_GAME3_BIN_FILES='
Binaries/PhysXCore.bak'
CONTENT_GAME_L10N_FR_FILES='
Engine/Localization/FRA
TdGame/CookedPC/Audio/FRA
TdGame/Localization/FRA
TdGame/CookedPC/Startup_FRA.upk
TdGame/CookedPC/Ts_LOC_FRA.upk
TdGame/CookedPC/Maps/SP??/*_LOC_FRA.upk'
CONTENT_GAME_L10N_EN_FILES='
Engine/Localization/INT
TdGame/CookedPC/Audio/int
TdGame/Localization/int
TdGame/CookedPC/Startup_int.upk
TdGame/CookedPC/Ts_LOC_int.upk
TdGame/CookedPC/Maps/SP??/*_LOC_int.upk'
CONTENT_GAME_MAPS_FILES='
Entry.upk
*/*.me1
*/*.umap'
CONTENT_GAME_DATA_FILES='
TdGame/Config
TdGame/Movies
TdGame/Splash'
CONTENT_GAME0_DATA_FILES='
TdGame/CookedPC/Accessories
TdGame/CookedPC/Animations
TdGame/CookedPC/Audio
TdGame/CookedPC/Buildings
TdGame/CookedPC/Characters
TdGame/CookedPC/Core.u
TdGame/CookedPC/Editor
TdGame/CookedPC/Editor.u
TdGame/CookedPC/Effects
TdGame/CookedPC/Engine.u
TdGame/CookedPC/Fp.u
TdGame/CookedPC/GameFramework.u
TdGame/CookedPC/Ground
TdGame/CookedPC/Interiors
TdGame/CookedPC/IpDrv.u
TdGame/CookedPC/Lighting
TdGame/CookedPC/Materials
TdGame/CookedPC/Packages
TdGame/CookedPC/PhysicalMaterials
TdGame/CookedPC/Props
TdGame/CookedPC/Script
TdGame/CookedPC/TdEditor.u
TdGame/CookedPC/TdGame.u
TdGame/CookedPC/TdMenuContent.u
TdGame/CookedPC/TdMpContent.u
TdGame/CookedPC/TdSharedContent.u
TdGame/CookedPC/TdSpBossContent.u
TdGame/CookedPC/TdSpContent.u
TdGame/CookedPC/TdTTContent.u
TdGame/CookedPC/TdTuContent.u
TdGame/CookedPC/TimeTrial
TdGame/CookedPC/Tp.u
TdGame/CookedPC/Ts.u
TdGame/CookedPC/UI
TdGame/CookedPC/UnrealEd.u
TdGame/CookedPC/Vehicles
TdGame/CookedPC/Weapons'
CONTENT_GAME1_DATA_FILES='
TdGame/CookedPC/EditorMaterials.upk
TdGame/CookedPC/EditorMeshes.upk
TdGame/CookedPC/EditorResources.upk
TdGame/CookedPC/EngineFonts.upk
TdGame/CookedPC/EngineMaterials.upk
TdGame/CookedPC/Engine_MI_Shaders.upk
TdGame/CookedPC/EngineResources.upk
TdGame/CookedPC/EngineScenes.upk
TdGame/CookedPC/EngineVolumetrics.upk
TdGame/CookedPC/GlobalPersistentCookerData.upk
TdGame/CookedPC/GuidCache.upk
TdGame/CookedPC/NodeBuddies.upk
TdGame/CookedPC/RefShaderCache-PC-D3D-SM2.upk
TdGame/CookedPC/RefShaderCache-PC-D3D-SM3.upk
TdGame/CookedPC/RefShaderCache-PC-D3D-SM4.upk'

USER_PERSISTENT_DIRECTORIES='
TdGame/Config
TdGame/savefiles'

WINE_REGISTRY_INIT_L10N_FR='
[HKEY_LOCAL_MACHINE\Software\EA Games\Mirror'\''s Edge]
"Language"="French"
"Locale"="fr_FR"
'
WINE_REGISTRY_INIT_L10N_EN='
[HKEY_LOCAL_MACHINE\Software\EA Games\Mirror'\''s Edge]
"Language"="English (UK)"
"Locale"="en_UK"
'

APP_MAIN_EXE='Binaries/MirrorsEdge.exe'
APP_MAIN_ICON='ME_Icon.ico'

PACKAGES_LIST='
PKG_BIN
PKG_L10N_FR
PKG_L10N_EN
PKG_MAPS
PKG_DATA'

PKG_BIN_ARCH='32'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_L10N
PKG_MAPS
PKG_DATA'

PKG_L10N_ID="${GAME_ID}-l10n"
PKG_L10N_FR_ID="${PKG_L10N_ID}-fr"
PKG_L10N_EN_ID="${PKG_L10N_ID}-en"
PKG_L10N_PROVIDES="
$PKG_L10N_ID"
PKG_L10N_FR_DESCRIPTION='French localisation'
PKG_L10N_EN_DESCRIPTION='English localisation'

PKG_MAPS_ID="${GAME_ID}-maps"
PKG_MAPS_DESCRIPTION='maps'

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

# Install Windows native PhysX libraries. The game crashes on launch if they are not available.
# This is set here to avoid overriding the default verbs for Unreal Engine 3 games.

WINE_WINETRICKS_VERBS="$(wine_winetricks_verbs) physx"

# Write launchers.

for package in \
	'PKG_L10N_FR' \
	'PKG_L10N_EN'
do (
	set_current_package "$package"
	# shellcheck disable=SC2218
	wine_registry_script_write "$package"
) done
wine_registry_script_write() { return 0; }

# Set registry script to a dummy value to ensure its integration in the launcher.
WINE_REGISTRY_INIT='nothing'

launchers_generation

# Build packages.

packages_generation
case "$(messages_language)" in
	('fr')
		lang_string='version %s :'
		lang_fr='française'
		lang_en='anglaise'
	;;
	('en'|*)
		lang_string='%s version:'
		lang_fr='French'
		lang_en='English'
	;;
esac
printf '\n'
printf "$lang_string" "$lang_fr"
print_instructions 'PKG_BIN' 'PKG_DATA' 'PKG_MAPS' 'PKG_L10N_FR'
printf "$lang_string" "$lang_en"
print_instructions 'PKG_BIN' 'PKG_DATA' 'PKG_MAPS' 'PKG_L10N_EN'

# Clean up.

working_directory_cleanup

exit 0
