Tekken 3 update script added.
This commit is contained in:
1 parent
4886578fc5
commit
d5b688314c
5 files changed
+169
-16
No files matched your search
+109
-12
@@ -3,6 +3,7 @@
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import os
|
||||
from pathlib import Path, PurePosixPath
|
||||
import re
|
||||
import shutil
|
||||
@@ -16,7 +17,8 @@ from zipfile import BadZipFile, ZipFile
|
||||
PORT_COMMIT = "b6e941378ad03dbd834fef340bd8d90bae6e430b"
|
||||
PORT_EXE_HASH = "25d038f55d7a1c02a0e5bbcc97fe9b1738c8292198e7fa0d1b171b57129d18c0"
|
||||
SETUP_HASH = "c1e0430498b2f4212d7e04187e3ba822d3ac273de487cd35d93aa2ef823ac5aa"
|
||||
MOD_ARCHIVE_HASH = "bacaf33cda0ba615bffe4082a9b230cdb9d9f63327f78baf76dec9098381a1d6"
|
||||
MOD_ARCHIVE_HASH = "7aacee1ce376dff83823a6fc9c6717ad31e94cd37fa85551a3a8e8048e709646"
|
||||
PRISM_HASH = "7c7d09c8c7306e8e1a0c46d603ccb2a391c194c77843400c11b746e7dd56a467"
|
||||
USA_EXE_HASH = "fbda8b68e5799dbef4af39a161783bc670c15b0aa0e87dce65e210717da19b8c"
|
||||
TRACK_SIZES = (632532768, 27701856, 28042896)
|
||||
TRACK_NAMES = tuple(f"Tekken 3 (USA) (Track {trackNumber}).bin" for trackNumber in range(1, 4))
|
||||
@@ -74,6 +76,102 @@ def verify_hash(path, expectedHash):
|
||||
raise ValueError(f"{path.name} does not match the tested version. Remove the cached download and retry.")
|
||||
|
||||
|
||||
def write_manual(gameRoot):
|
||||
manualText = (
|
||||
"Tekken 3 Access under Wine\n\n"
|
||||
"Keyboard: Enter starts; arrows move; Z/A/X/S are Square/Triangle/Cross/Circle.\n"
|
||||
'Controller mode is enabled by default (p1_device = "auto"); connect your controller before launch.\n'
|
||||
'To play with the keyboard, set p1_device = "keyboard" in settings.toml and restart.\n'
|
||||
"The mod function keys work in either mode.\n"
|
||||
"Alt+F4 exits. Settings, memory cards and logs are in this game folder.\n"
|
||||
"AGM uses Prism's native Speech Dispatcher bridge for speech.\n"
|
||||
"The upstream manual follows.\n\n"
|
||||
)
|
||||
(gameRoot / "manual.txt").write_text(manualText + (gameRoot / "T3Access/README.txt").read_text())
|
||||
|
||||
|
||||
def check_game_stopped():
|
||||
for processPath in Path("/proc").iterdir():
|
||||
if not processPath.name.isdigit():
|
||||
continue
|
||||
try:
|
||||
if processPath.stat().st_uid != os.getuid():
|
||||
continue
|
||||
arguments = (processPath / "cmdline").read_bytes().split(b"\0")
|
||||
except (FileNotFoundError, ProcessLookupError, PermissionError):
|
||||
continue
|
||||
if any(argument.replace(b"\\", b"/").rsplit(b"/", 1)[-1].lower()
|
||||
in (b"tekken3.exe", b"play tekken 3 access.exe") for argument in arguments):
|
||||
raise ValueError("Close Tekken 3 and its access launcher before updating.")
|
||||
|
||||
|
||||
def validate_installation(destination):
|
||||
check_game_stopped()
|
||||
if destination.is_symlink():
|
||||
raise ValueError("The game directory must not be a symbolic link.")
|
||||
verify_hash(destination / "Tekken3.exe", PORT_EXE_HASH)
|
||||
for name in ("Play Tekken 3 Access.exe", "T3Access/T3Access.dll", "game_data/disc.cue", "settings.toml"):
|
||||
if not (destination / name).is_file():
|
||||
raise ValueError(f"The existing installation is missing {name}. Install Tekken 3 through AGM first.")
|
||||
|
||||
|
||||
def update_game(modArchive, destination):
|
||||
validate_installation(destination)
|
||||
verify_hash(modArchive, MOD_ARCHIVE_HASH)
|
||||
with tempfile.TemporaryDirectory(prefix=".tekken3-update-", dir=destination.parent) as temporaryDir:
|
||||
gameRoot = Path(temporaryDir) / "mod"
|
||||
gameRoot.mkdir()
|
||||
extract_archive(modArchive, gameRoot)
|
||||
for name in ("Play Tekken 3 Access.exe", "T3Access/T3Access.dll", "T3Access/README.txt"):
|
||||
if not (gameRoot / name).is_file():
|
||||
raise ValueError(f"The update is missing {name}.")
|
||||
verify_hash(gameRoot / "T3Access/prism.dll", PRISM_HASH)
|
||||
write_manual(gameRoot)
|
||||
relativeFiles = sorted(path.relative_to(gameRoot) for path in gameRoot.rglob("*") if path.is_file())
|
||||
for relativePath in relativeFiles:
|
||||
targetPath = destination / relativePath
|
||||
for path in (targetPath, *targetPath.parents):
|
||||
if path == destination.parent:
|
||||
break
|
||||
if path.is_symlink():
|
||||
raise ValueError(f"Update target must not be a symbolic link: {path}")
|
||||
if targetPath.exists() and not targetPath.is_file():
|
||||
raise ValueError(f"Update target is not a file: {targetPath}")
|
||||
for parentPath in targetPath.parents:
|
||||
if parentPath == destination:
|
||||
break
|
||||
if parentPath.exists() and not parentPath.is_dir():
|
||||
raise ValueError(f"Update target parent is not a directory: {parentPath}")
|
||||
backupRoot = Path(tempfile.mkdtemp(prefix=".tekken3-access-backup-", dir=destination.parent))
|
||||
for relativePath in relativeFiles:
|
||||
sourcePath = destination / relativePath
|
||||
if sourcePath.exists():
|
||||
backupPath = backupRoot / relativePath
|
||||
backupPath.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy2(sourcePath, backupPath)
|
||||
check_game_stopped()
|
||||
appliedFiles = []
|
||||
try:
|
||||
for relativePath in relativeFiles:
|
||||
targetPath = destination / relativePath
|
||||
targetPath.parent.mkdir(parents=True, exist_ok=True)
|
||||
(gameRoot / relativePath).replace(targetPath)
|
||||
appliedFiles.append(relativePath)
|
||||
except OSError as error:
|
||||
try:
|
||||
for relativePath in reversed(appliedFiles):
|
||||
targetPath = destination / relativePath
|
||||
backupPath = backupRoot / relativePath
|
||||
if backupPath.exists():
|
||||
shutil.copy2(backupPath, targetPath)
|
||||
else:
|
||||
targetPath.unlink()
|
||||
except OSError as restoreError:
|
||||
raise OSError(f"Update and restoration failed. Restore files from {backupRoot}. {restoreError}") from error
|
||||
raise OSError(f"Update failed; replaced files restored. Backup: {backupRoot}. {error}") from error
|
||||
print(f"Updated Tekken 3 Access to 1.0.1. Backup of replaced files: {backupRoot}")
|
||||
|
||||
|
||||
def install_game(discDir, portArchive, modArchive, destination):
|
||||
validate_disc(discDir)
|
||||
verify_hash(modArchive, MOD_ARCHIVE_HASH)
|
||||
@@ -94,17 +192,7 @@ def install_game(discDir, portArchive, modArchive, destination):
|
||||
settingsPath = gameRoot / "settings.toml"
|
||||
settingsText = settingsPath.read_text()
|
||||
settingsPath.write_text(settingsText.replace("fullscreen = 1", "fullscreen = 0").replace("supersampling = 3", "supersampling = 1").replace("window_width = 1920", "window_width = 960").replace('p1_device = "keyboard"', 'p1_device = "auto"'))
|
||||
manualText = (
|
||||
"Tekken 3 Access under Wine\n\n"
|
||||
"Keyboard: Enter starts; arrows move; Z/A/X/S are Square/Triangle/Cross/Circle.\n"
|
||||
'Controller mode is enabled (p1_device = "auto"); connect your controller before launch.\n'
|
||||
'To play with the keyboard, set p1_device = "keyboard" in settings.toml and restart.\n'
|
||||
"The mod function keys work in either mode.\n"
|
||||
"Alt+F4 exits. Settings, memory cards and logs are in this game folder.\n"
|
||||
"AGM uses Prism's native Speech Dispatcher bridge for speech.\n"
|
||||
"The upstream manual follows.\n\n"
|
||||
)
|
||||
(gameRoot / "manual.txt").write_text(manualText + (gameRoot / "T3Access/README.txt").read_text())
|
||||
write_manual(gameRoot)
|
||||
if destination.exists():
|
||||
destination.rmdir() # Only an empty destination is accepted above.
|
||||
gameRoot.rename(destination)
|
||||
@@ -116,6 +204,11 @@ def main():
|
||||
subparsers = parser.add_subparsers(dest="command", required=True)
|
||||
validateParser = subparsers.add_parser("validate-disc")
|
||||
validateParser.add_argument("discDir", type=Path)
|
||||
installedParser = subparsers.add_parser("validate-installation")
|
||||
installedParser.add_argument("destination", type=Path)
|
||||
updateParser = subparsers.add_parser("update")
|
||||
updateParser.add_argument("modArchive", type=Path)
|
||||
updateParser.add_argument("destination", type=Path)
|
||||
installParser = subparsers.add_parser("install")
|
||||
for name in ("discDir", "portArchive", "modArchive", "destination"):
|
||||
installParser.add_argument(name, type=Path)
|
||||
@@ -124,6 +217,10 @@ def main():
|
||||
if args.command == "validate-disc":
|
||||
validate_disc(args.discDir)
|
||||
print("Tekken 3 (USA) disc files validated.")
|
||||
elif args.command == "validate-installation":
|
||||
validate_installation(args.destination)
|
||||
elif args.command == "update":
|
||||
update_game(args.modArchive, args.destination)
|
||||
else:
|
||||
install_game(args.discDir, args.portArchive, args.modArchive, args.destination)
|
||||
except (OSError, ValueError, BadZipFile, subprocess.CalledProcessError) as error:
|
||||
|
||||
Reference in new issue
Block a user