-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtweaks.py
477 lines (427 loc) · 13.8 KB
/
tweaks.py
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2019-2021 Patryk Obara <[email protected]>
"""
Game-specific tweaks and workarounds
"""
import os
import pathlib
import re
import zipfile
import confgen
import toolbox
import xdg
from log import log_err
from winpathlib import to_posix_path
# There are several tweaks, that can be specified in TWEAKS_DB:
#
# download - describe files to download on the first start
# install - name the function in tweaks module to finalise game installation
# midi - see documentation for get_midi_preset
# conf - dictionary of values to inject to DOSBox configuration
# commands - replace command line parameters used by specific game
TWEAKS_DB = {
# The Ultimate DOOM
'steam:2280': {
'midi': 'auto',
},
# Final DOOM
'steam:2290': {
'midi': 'auto',
},
# DOOM II: Hell on Earth
'steam:2300': {
'midi': 'auto',
},
# Quake
'steam:2310': {
'commands': {
r'.*': {
'args': ['-c', 'mount C .',
'-c', 'C:',
'-c', 'quake.exe -nocdaudio',
'-c', 'exit'],
},
},
},
# HeXen: Beyond Heretic
'steam:2360': {
'midi': 'auto',
},
# HeXen: Deathkings of the Dark Citadel
'steam:2370': {
'midi': 'auto',
'download': {
'dkpatch.zip': {
'txt': 'Original Patch 1.1',
'url': 'http://www.gamers.org/pub/games/idgames/idstuff/hexen/dkpatch.zip', # noqa pylint: disable=line-too-long
},
},
'install': 'install_hexen_dk',
'commands': {
r'.*': {
'args': ['-c', 'mount C "base"',
'-c', 'C:',
'-c', 'PATCH.EXE',
'-c', 'HEXENDK.EXE',
'-c', 'exit'],
},
},
},
# Heretic: Shadow of the Serpent Riders
'steam:2390': {
'midi': 'auto',
},
# X-COM: Terror from the Deep
'steam:7650': {
'midi': 'auto',
'conf': {
'render': {'force_aspect': 'false'},
},
},
# X-COM: UFO Defence / UFO: Enemy Unknown
'steam:7760': {
'midi': 'auto',
'conf': {
'render': {'force_aspect': 'false'},
},
},
# Master Levels for DOOM II
'steam:9160': {
'midi': 'auto',
},
# STAR WARS™ - Dark Forces
'steam:32400': {
'midi': 'auto',
},
# Fallout: A Post Nuclear Role Playing Game
'steam:38400': {
'download': {
'dos32a-912.zip': {
'txt': 'DOS/32 Advanced DOS Extender',
'url': 'http://download.narechk.net/dos32a-912-bin.zip',
},
'SETUP40.ZIP': {
'txt': 'HMI Sound Setup',
'url': 'http://www.r-t-c-m.com/knowledge-base/downloads-rtcm/tekwar-tools/SETUP40.ZIP', # noqa pylint: disable=line-too-long
},
'fallout_patch_1_1_dos.zip': {
'txt': 'Fallout patch 1.1 for DOS',
'url': 'http://www.nma-fallout.com/resources/fallout-official-v1-1-patch-dos.49/download?version=50', # noqa pylint: disable=line-too-long
},
},
'install': 'install_fallout',
'commands': {
r'.*': {
'args': ['FALLOUT.EXE', '-exit'],
},
},
},
# Earthworm Jim
'steam:38480': {
'commands': {
r'.*': {
'args': ['-conf', 'ewj1.conf'],
},
},
},
# Earthworm Jim 2
'steam:38490': {
'commands': {
r'.*': {
'args': ['-conf', 'ewj2.conf'],
},
},
},
# Retro City Rampage™ DX
'steam:204630': {
'install': 'install_retro_city_rampage',
'conf': {
'render': {'force_aspect': 'false'},
},
'commands': {
r'.*': {
'args': ['RCR486/RCR.EXE', '-exit'],
},
},
},
# STAR WARS™ - X-Wing Special Edition
'steam:354430': {
'midi': 'auto',
},
# Shadow Warrior (Classic)
'steam:358400': {
'install': 'install_shadow_warrior',
'midi': 'disable',
'commands': {
r'.*Shadow Warrior - Dos.bat': {
'args': ['-conf', 'Shadow Warrior\\SW.conf', '-noautoexec',
'-c', 'mount C "Shadow Warrior"',
'-c', 'imgmount D "Shadow Warrior\\shadow.cue" -t iso',
'-c', 'C:',
'-c', 'SwDOS.exe',
'-c', 'exit'],
},
},
},
# Super 3D Noah's Ark
'steam:371180': {
'midi': 'disable',
'commands': {
r'.*': {
'args': ['noah3dos.exe', '-exit'],
},
},
},
# System Shock: Classic
'steam:410700': {
'midi': 'auto',
},
# Tomb Raider I
# As of 0.74-2, upstream DOSBox does not support GLide acceleration.
# This tweak starts the game without hardware acceleration.
'steam:224960': {
'commands': {
r'.*': {
'args': ['-conf', 'dosboxtr.conf', '-noautoexec',
'-c', 'mount C .',
'-c', 'imgmount D GAME.DAT -t iso -fs iso',
'-c', 'C:',
'-c', 'cd TOMBRAID',
'-c', 'TOMBNO~1.EXE',
'-c', 'exit'],
},
},
},
# Duke Nukem 3D (Classic)
'steam:225140': {
'midi': 'auto',
'commands': {
r'.*bin/dosbox/dosbox\.exe': {
'args': ['-conf', 'dosbox.conf', '-noautoexec',
'-c', 'mount C .',
'-c', 'C:',
'-c', 'DUKE3D.EXE',
'-c', 'exit'],
},
},
},
# Jagged Alliance Gold
# Jagged Alliance Deadly Games
'steam:283270': {
'midi': 'auto',
},
# King's Table - The Legend of Ragnarok
'steam:719310': {
'midi': 'auto',
},
# MegaRace
#
# This game uses different .conf files depending on game language.
# TODO provide fallback mechanism for missing .conf files or glob support
#
'steam:730580': {
'midi': 'disable',
'conf': {
'sblaster': {'force_irq': '5'},
},
'commands': {
r'.*': {
'args': ['Megarace.bat'],
},
},
},
# MegaRace 2
'steam:733760': {
'midi': 'disable',
'commands': {
r'.*': {
'args': ['-conf', 'dosboxmegarace2.conf', '-noautoexec',
'-c', 'mount C .',
'-c', 'mount D . -t cdrom',
'-c', 'C:',
'-c', 'MEGARACE.EXE',
'-c', 'exit'],
},
},
},
# Leisure Suit Larry 1
'steam:763970': {
'commands': {
r'.*': {
'args': ['-c', 'mount C .',
'-c', 'C:',
'-c', 'call SIERRA',
'-c', 'exit'],
},
},
},
# Leisure Suit Larry 2
'steam:765840': {
'commands': {
r'.*': {
'args': ['SCIV.EXE', '-exit'],
},
},
},
# Leisure Suit Larry 3
'steam:765850': {
'commands': {
r'.*': {
'args': ['SCIV.EXE', '-exit'],
},
},
},
# Leisure Suit Larry 5
'steam:765860': {
'commands': {
r'.*': {
'args': ['SCIDHUV.EXE', '-exit'],
},
},
},
# Lords of the Realm
'steam:254920': {
'commands': {
r'.*': {
'args': ['-c', 'mount C "../../Lords of the Realm I"',
'-c', 'C:',
'-c', 'lords.exe',
'-c', 'exit'],
},
},
},
} # yapf: disable
def command_tweak_needed(app_id):
"""Return true if game's command line needs to be changed."""
return app_id in TWEAKS_DB and 'commands' in TWEAKS_DB[app_id]
def download_tweak_needed(app_id):
"""Return true if game needs to be download something for installation."""
return app_id in TWEAKS_DB and 'download' in TWEAKS_DB[app_id]
def install_tweak_needed(app_id):
"""Return true if game needs to be installed before start."""
return app_id in TWEAKS_DB and 'install' in TWEAKS_DB[app_id]
def tweak_command(app_id, cmd_line):
"""Convert command line based on TWEAKS_DB."""
assert len(cmd_line) >= 1
orig_cmd = ' '.join(cmd_line)
exec_replacements = TWEAKS_DB[app_id]['commands']
for expr, replacement in exec_replacements.items():
exe_pattern = re.compile(expr)
if exe_pattern.match(orig_cmd):
if 'args' in replacement:
return replacement['args']
raise KeyError
log_err('no suitable tweak found for:', cmd_line)
return cmd_line[1:]
def install(app_id):
"""Call specific install function."""
function_name = TWEAKS_DB[app_id]['install']
installf = globals()[function_name]
return installf()
def get_conf_tweak(app_id):
"""Return dictionary used to overwrite publisher-supplied defaults.
Use this tweak for games, where defaults are clearly wrong.
"""
if app_id not in TWEAKS_DB:
return {}
if 'conf' not in TWEAKS_DB[app_id]:
return {}
return TWEAKS_DB[app_id]['conf']
def get_midi_preset(app_id):
"""Return MIDI preset for given AppID.
Possible return values:
enable - (default) turn on software midi synthesizer
disable - game does not support midi at all
auto - pre-configure game to automatically turn midi on/off depending
on user preference
"""
if toolbox.enabled_in_env('BOXTRON_NO_MIDI_PRESET', 'SDOS_NO_MIDI_PRESET'):
return 'enable'
if app_id not in TWEAKS_DB:
return 'enable'
if 'midi' not in TWEAKS_DB[app_id]:
return 'enable'
return TWEAKS_DB[app_id]['midi']
# Normally, Steam is changing working dir to the sub-directory of game
# installation dir (which is specified by the game publisher) and then runs
# command as an absolute path.
#
# If Steam fails to chdir into the correct directory before running the game
# (which might happen - either as a result of Steam bug or publisher submitting
# broken path), then Boxtron and DOSBox are going to fail because .conf files
# will not be in their expected location.
#
def check_cwd(command_line):
"""Test if current working directory is appropriate to launch the game.
Returns (False, path) if all .conf files referenced in dosbox command line
can be found (path is the same as current working dir in such case).
Returns (True, path) if all .conf files can be found in path, and path
is not a working dir (changing dir is required).
Returns (False, None) if .conf files couldn't be found at all.
"""
prog, args = command_line[0], command_line[1:]
prog_path = pathlib.PurePosixPath(prog)
if not prog_path.is_absolute():
return False, None
dbox_args = confgen.parse_dosbox_arguments(args) # throws RuntimeException
conf_paths = (dbox_args.conf or [])
def paths_found():
return all(to_posix_path(p, strict=False) for p in conf_paths)
if paths_found():
return False, os.getcwd()
orig_cwd = os.getcwd()
prefix = str(prog_path)
while True:
prefix, _ = os.path.split(prefix)
os.chdir(prefix)
if paths_found():
os.chdir(orig_cwd)
return True, prefix
if prefix in (os.path.expanduser('~'), '/'):
break
os.chdir(orig_cwd)
return False, None
def install_test_42():
"""Dummy install function for testing purposes."""
return 42
def install_retro_city_rampage():
"""Install Retro City Rampage™ DX DOS version.
It is bundled with the Steam version, just needs to be unpacked.
"""
if not os.path.isfile('other/RCR486_MS-DOS.zip'):
toolbox.unzip('RetroCityRampage486_MS-DOS_v1.0.zip', 'other')
if not os.path.isfile('RCR486/RCR.EXE'):
toolbox.unzip('other/RCR486_MS-DOS.zip', 'RCR486')
def install_shadow_warrior():
"""Rename broken file causing crash for Shadow Warrior Classic (358400).
"""
path = 'Shadow Warrior/SWP.cfg'
if os.path.isfile(path):
os.rename(path, path + '.bak')
def install_fallout():
"""Unpack patch file to get Fallout DOS binary.
Assumes, that patch was already downloaded and placed in the cache.
"""
if not os.path.isfile('DOS4GW.EXE_'):
with zipfile.ZipFile(xdg.cached_file('dos32a-912.zip'), 'r') as arch:
arch.extract('binw/dos32a.exe')
os.rename('binw/dos32a.exe', 'DOS4GW.EXE')
os.rmdir('binw')
if not os.path.isfile('HMIDET.386') or not os.path.isfile('HMIDRV.386'):
with zipfile.ZipFile(xdg.cached_file('SETUP40.ZIP'), 'r') as arch:
arch.extract('HMIDET.386')
arch.extract('HMIDRV.386')
if not os.path.isfile('FALLOUT.EXE'):
cache_file = xdg.cached_file('fallout_patch_1_1_dos.zip')
toolbox.unzip(cache_file, 'patch_1_1_dos')
toolbox.unzip('patch_1_1_dos/FALL11.ZIP', '.')
rpatch = [
'file:fallout.cfg',
r's:/(art_cache_size=)(\d+)/\g<1>5/',
]
toolbox.apply_resource_patch(rpatch)
def install_hexen_dk():
"""Fix music in HeXen: Deathkings of the Dark Citadel"""
digest = 'ea5e34c9f7eb677c593f125a0c45db2aaf2d98b8f6e9d50bd683a655aeec531f'
if toolbox.sha256sum('base/HEXDD.WAD') != digest:
toolbox.unzip(xdg.cached_file('dkpatch.zip'), 'base')