summaryrefslogtreecommitdiff
path: root/games-fps/ut2004-data/ut2004-data-3369.ebuild
blob: 91590aa4cde9ee8301d16e42dc264bad7fbe9664 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# Copyright 1999-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

CDROM_OPTIONAL="yes"
inherit cdrom check-reqs multiprocessing portability

DESCRIPTION="Data files for Unreal Tournament 2004"
HOMEPAGE="https://liandri.beyondunreal.com/Unreal_Tournament_2004"
GOG=( "setup_unreal_tournament_2004_1.0_(18947).exe" "setup_unreal_tournament_2004_1.0_(18947)-1.bin" )
SRC_URI="
	!cdinstall? ( !gog? ( fetch+https://files.oldunreal.net/UT2004.ISO -> UT2004.iso ) )
	gog? ( ${GOG[*]} )
	megapack? ( fetch+https://unreal-archive-files-na.s3.ca-east-tor.io.cloud.ovh.net/managed/Unreal%20Tournament%202004/patches-updates/bonus-packs/ut2004megapack-linux.tar.bz2 )
"
S="${WORKDIR}"

LICENSE="Epic-TOS" # See metadata.xml for the legal background.
SLOT="0"
KEYWORDS="~amd64 ~arm64"
IUSE="megapack doc gog l10n_de l10n_es l10n_fr l10n_it l10n_ko"
RESTRICT="bindist gog? ( fetch ) mirror"
REQUIRED_USE="
	?? ( cdinstall gog )
	!cdinstall? ( !megapack )
"

UT_DEPEND=">=games-fps/ut2004-3374_pre23"

BDEPEND="
	${UT_DEPEND}
	gog? ( app-arch/innoextract )
	!gog? (
		app-arch/libarchive
		app-arch/unshield
	)
"
RDEPEND="
	${UT_DEPEND}
	!games-fps/ut2004-bonuspack-ece
	!games-fps/ut2004-bonuspack-mega
	!games-server/ut2004-ded
"

# Assuming the OldUnreal ISO.
CHECKREQS_DISK_BUILD="15G"

pkg_nofetch() {
	einfo "Please download ${GOG[0]} and"
	einfo "${GOG[1]} from GOG and move them"
	einfo "to your distfiles directory. Note that you can no longer buy this"
	einfo "game from GOG, so disable USE=\"gog\" to use OldUnreal's free ISO if"
	einfo "you don't already own the game."
}

locale_mismatch() {
	case "${1}" in
		*.det|*.det_*|4_UT2004_*_German*) ! use l10n_de ;;
		*.est|*.est_*|4_UT2004_*_Spanish) ! use l10n_es ;;
		*.frt|*.frt_*|4_UT2004_*_French)  ! use l10n_fr ;;
		*.itt|*.itt_*|4_UT2004_*_Italian) ! use l10n_it ;;
		*.kot|*.kot_*) ! use l10n_ko ;;
		*) return 1 ;;
	esac
}

src_unpack() {
	if use gog; then
		innoextract --extract "${DISTDIR}/${GOG[0]}" || die
		return
	elif use cdinstall; then
		ewarn "It is no longer necessary to install this from CD or DVD. Please"
		ewarn "disable USE=\"cdinstall\" if you would prefer to download the game for"
		ewarn "free. Note that the free download lacks localised audio and some"
		ewarn "localised text."
		echo
	else
		# We might as well handle a downloaded ISO and a user-provided ISO the
		# same way through cdrom.eclass.
		CD_ROOT="${DISTDIR}/UT2004.iso"
	fi

	# No really, Midway.tga is *not* on the Midway DVD.
	# The German Midway DVD doesn't include UT99.

	cdrom_get_cds \
		Manuals/UnrealTournament_English.pdf:autorund/unreal.ico:AutoRunData/Midway.tga:CD6/Sounds/TauntPack.det_uax.uz2:linux-installer.sh:System/UT2004.ini \
		::::Textures/2K4Fonts.utx.uz2:Textures/2K4Fonts.utx.uz2 \
		::::Textures/ONSDeadVehicles-TX.utx.uz2:Textures/ONSDeadVehicles-TX.utx.uz2 \
		::::StaticMeshes/AlienTech.usx.uz2:StaticMeshes/AlienTech.usx.uz2 \
		::::Speech/ons.xml:Speech/ons.xml \
		:::::Sounds/TauntPack.det_uax.uz2

	case ${CDROM_SET} in
		0) einfo "Found Midway Unreal Anthology DVD" ;;
		1) einfo "Found German Midway Unreal Anthology DVD" ;;
		2) einfo "Found OldUnreal UT2004 DVD" ;;
		3) einfo "Found UT2004 DVD (original or Editor's Choice Edition)" ;;
		4) einfo "Found UT2004 CD 1 of 5" ;;
		5) einfo "Found UT2004 CD 1 of 6" ;;
	esac

	case ${CDROM_SET} in
		3|4|5)
			if ! use megapack; then
				die "Your installation source lacks the Mega Pack. Please enable USE=\"megapack\" to download it."
			fi ;;
		*)
			if use megapack; then
				ewarn "Enabling USE=\"megapack\" just downloads an unnecessary file with"
				ewarn "this installation source. Please disable it."
			fi ;;
	esac

	local group dir cdnum
	case ${CDROM_SET} in
		0|1)
			# Symlinks for unshield. These files need to be in the same
			# directory but on the disk, they are not for some reason.
			ln -snf "${CDROM_ROOT}"/{Disk1/data1.hdr,Disk*/data*.cab} "${T}"/ || die

			for group in $(unshield g "${T}"/data1.cab || die); do
				case ${group} in
					4_UT2004_Benchmark|4_UT2004_EXE|4_UT2004_Manual_*|4_UT2004_Web) continue ;;
					4_UT2004_*) : ;;
					*) continue ;;
				esac
				locale_mismatch "${group}" && continue
				unshield -g "${group}" x "${T}"/data1.cab || die
			done

			for dir in 4_UT2004_*; do
				mv -v "${dir}" "${dir#4_UT2004_}" || die
			done

			for dir in *_*/; do
				mkdir -p "${dir%_*}" || die
				tar -C "${dir}" --remove-files -cf - . | tar -C "${dir%_*}" -xvf - || die
			done
			;;

		2)
			# Symlinks for unshield. These files need to be in the same
			# directory but on the disk, they are not for some reason.
			ln -snf "${CDROM_ROOT}"/{Disk1/data1.hdr,Disk*/data*.cab} "${T}"/ || die

			for group in $(unshield g "${T}"/data1.cab || die); do
				case ${group} in
					All_Benchmark|All_Web) continue ;;
					All_*|English_Sounds_Speech_System_Help|US_License.int) : ;;
					*) continue ;;
				esac
				unshield -g "${group}" x "${T}"/data1.cab || die
			done

			for dir in All_*; do
				mv -v "${dir}" "${dir#All_}" || die
			done

			mkdir -p Sounds Speech System Help || die
			mv -v UT2004.EXE/* US_License.int/* System/ || die
			for dir in English_Sounds_Speech_System_Help/*/; do
				mv -v "${dir}"/* "${dir#*/}" || die
			done
			;;

		3)
			for cdnum in {1..6}; do
				tar -C "${CDROM_ROOT}/CD${cdnum}" --mode=u+w -cf - . | tar -xvf - || die
			done
			;;

		4|5)
			tar -C "${CDROM_ROOT}" --mode=u+w -cf - . | tar -xvf - || die
			for cdnum in $(seq 2 $((CDROM_SET + 1))); do
				cdrom_load_next_cd
				tar -C "${CDROM_ROOT}" --mode=u+w -cf - . | tar -xvf - || die
			done
			;;
	esac

	case ${CDROM_SET} in
		3|4|5)
			# Some disks compress most of the files. The engine has the
			# decompresser. Annoyingly, it logs to the engine's directory.
			addpredict "${BROOT}"/opt/ut2004
			ls */*.uz2 | xargs -P "$(get_makeopts_jobs)" -ti ut2004-ucc decompress "${PWD}"/{} -nohomedir >/dev/null || die
			rm -v */*.uz2 || die

			# Install the Mega Pack where necessary for parity between different
			# installation sources. This includes the ECE content but *not* the
			# XP Bonus Maps (ONS-Aridoom and ONS-Ascendancy). The latter were
			# never released as part of the game and OldUnreal does not include
			# them in its installation.
			tar --strip-components=1 -jxvf "${DISTDIR}"/ut2004megapack-linux.tar.bz2 || die
		;;
	esac
}

src_install() {
	local dir file

	if use doc; then
		case ${CDROM_SET} in
			0|1)
				newdoc "${CDROM_ROOT}"/Manuals/UT2004_English.pdf Manual.pdf
				use l10n_de && newdoc "${CDROM_ROOT}"/Manuals/UT2004_German.pdf Manual_de.pdf
				use l10n_es && newdoc "${CDROM_ROOT}"/Manuals/UT2004_Spanish.pdf Manual_es.pdf
				use l10n_fr && newdoc "${CDROM_ROOT}"/Manuals/Français/UT2004.pdf Manual_fr.pdf
				use l10n_it && newdoc "${CDROM_ROOT}"/Manuals/UT2004_Italian.pdf Manual_it.pdf ;;
			2) dodoc "${CDROM_ROOT}"/Manual.pdf ;;
			3) dodoc "${CDROM_ROOT}"/CD1/Manual/Manual.pdf ;;
			*) dodoc Manual/Manual.pdf ;;
		esac
	fi

	# Drop unwanted localisation files.
	while read -r file; do
		if locale_mismatch "${file}"; then
			rm -v "${file}" || die
		fi
	done < <(find -type f)

	# The OldUnreal patches currently lack localisation files for French,
	# Italian, and Korean even though some editions did include these. Move them
	# from System to SystemLocalized as recommended, but only if each has an
	# equivalent English (.int) file. Also match the casing of the English
	# filename for sanity and to avoid duplicates.
	(
		shopt -s extglob nocaseglob nullglob || die
		local lang match
		for lang in fr it ko; do
			mkdir -p SystemLocalized/${lang}t || die
			for file in System/*.${lang}t; do
				file=${file#*/}
				eval "match=( \"${BROOT}\"/opt/ut2004/SystemLocalized/int/?(${file%.*}.int) )"
				if [[ -n ${match[0]} ]]; then
					match=${match[0]##*/}
					mv -v "System/${file}" "SystemLocalized/${lang}t/${match%.int}.${lang}t" || die
				fi
			done
		done
	)

	insinto /opt/ut2004
	doins -r SystemLocalized

	# Drop any other non-localisation files not included in our listings for
	# cleanliness and consistency between installation sources. These listings
	# are (mostly) based on OldUnreal's installation.
	for file in "${FILESDIR}"/listings/*; do
		dir=${file##*/}
		find "${dir}" -type f ! -name "*.*_uax" | grep -Fxvf <(sed "s:^:${dir}/:" "${file}") | xargs -r rm -v -- || die
	done

	# https://github.com/OldUnreal/UT2004Patches/issues/514
	# We could regenerate the cache for the entire base game, but it's awkward,
	# so just cover the missing BP2 maps in a separate file.
	ut2004-ucc exportcache -mod=Gentoo Maps/*-BP2-*.ut2 || die
	mv -v System/{CacheRecords,BP2}.ucl || die

	for file in "${FILESDIR}"/listings/*; do
		doins -r "${file##*/}"
	done

	for dir in CSVs Logs Results; do
		keepdir /opt/ut2004/Benchmark/${dir}
	done
}