From 4759a01ef3f29c0c5f94b1aab0bcf4e3bf802cd9 Mon Sep 17 00:00:00 2001 From: l4nr3 <122608495+l4nr3@users.noreply.github.com> Date: Sun, 15 Nov 2026 17:37:43 +0300 Subject: [PATCH] feat(xbox): stage the PlayFab Game Saves save-folder proxy from the Nexus runtime (#2662) * feat(xbox): stage the PlayFab Game Saves save-folder proxy from the Nexus runtime Xbox titles that use PlayFab Game Saves, such as Forza Horizon 6, stop with "Initialization Failed" E:0-17 right after sign-in. The SDK's default provider needs Gaming Runtime save APIs that xgameruntime does not have, and its in-process provider needs a save folder the title never passes on Windows. xodus-nexus already builds a proxy for this into the runtime archive we pin (scripts/runtime-compat, MIT): it keeps the title's SDK as nexus_pgs_native.dll, sets ForceUseInprocGameSaves and passes the PersistentLocalStorage PlayFabGameSaves folder. runtime.py now takes it and its license from the archive, checked against runtime.lock.json, and droiddeck-xbox stages it before each launch when the game's PlayFabGameSave.dll has exactly the SDK's 40 exports. A game update that brings a new SDK replaces the kept copy; anything unknown is left alone. Unlike Nexus, no DLL override is set for the two DLLs: Wine has no builtin of either, and forcing them native-only made Forza Horizon 6 fail with E:0-0-4. * fix(xbox): check the whole PlayFab export table and never overwrite an unknown kept SDK The SDK and proxy checks now also require the export address table to hold exactly 40 functions, so a DLL with the same names plus an ordinal-only export is no longer taken for the SDK. Before copying a new SDK to nexus_pgs_native.dll, an existing file there must itself be a regular file holding the SDK; an unknown file or a link is left as it is. --- .../overlay/usr/local/bin/droiddeck-xbox | 172 +++++++++++++++++ tools/release/runtime_inputs.py | 3 +- tools/tests/test_xbox_launch.py | 181 ++++++++++++++++++ tools/xbox/runtime.lock.json | 10 + tools/xbox/runtime.py | 16 ++ 5 files changed, 381 insertions(+), 1 deletion(-) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-xbox b/tools/linuxfs/overlay/usr/local/bin/droiddeck-xbox index 304e126552..5a9f2578ca 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-xbox +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-xbox @@ -197,6 +197,172 @@ def wine(argv, source_env=None): pass +# PlayFab Game Saves picks its provider from the Gaming Runtime unless HKLM\SOFTWARE\Microsoft\GamingServices +# ForceUseInprocGameSaves is set, and its in-process provider needs a save folder the title never passes on Windows. +# The runtime has no GRTS saves, so titles such as Forza Horizon 6 stop with E:0-17. xodus-nexus ships a proxy +# (scripts/runtime-compat/playfab-save-folder.c, MIT) that keeps the title's own SDK as nexus_pgs_native.dll and +# supplies both; this stages it the same way. +PGS_PROXY = RUNTIME / 'compat' / 'PlayFabGameSave.dll' +PGS_NATIVE = 'nexus_pgs_native.dll' +PGS_EXPORTS = ( + 'PFGameSaveFilesAddUserWithUiAsync', 'PFGameSaveFilesAddUserWithUiResult', 'PFGameSaveFilesGetFolder', + 'PFGameSaveFilesGetFolderSize', 'PFGameSaveFilesGetRemainingQuota', 'PFGameSaveFilesGetSaveDescriptionForDebug', + 'PFGameSaveFilesGetSaveDescriptionSizeForDebug', 'PFGameSaveFilesGetStatsJsonForDebug', + 'PFGameSaveFilesGetStatsJsonSizeForDebug', 'PFGameSaveFilesInitialize', 'PFGameSaveFilesIsConnectedToCloud', + 'PFGameSaveFilesPauseUploadForDebug', 'PFGameSaveFilesResetCloudAsync', 'PFGameSaveFilesResetCloudResult', + 'PFGameSaveFilesResumeUploadForDebug', 'PFGameSaveFilesSetActiveDeviceChangedCallback', + 'PFGameSaveFilesSetActiveDevicePollForceChangeForDebug', 'PFGameSaveFilesSetActiveDevicePollIntervalForDebug', + 'PFGameSaveFilesSetForceNullPendingManifestForDebug', 'PFGameSaveFilesSetForceOutOfStorageErrorForDebug', + 'PFGameSaveFilesSetForceSyncFailedErrorForDebug', 'PFGameSaveFilesSetMockDataFolderForDebug', + 'PFGameSaveFilesSetMockDeviceIdForDebug', 'PFGameSaveFilesSetMockForceOfflineForDebug', + 'PFGameSaveFilesSetMockManifestOffsetForDebug', 'PFGameSaveFilesSetMockRootFolderForDebug', + 'PFGameSaveFilesSetSaveDescriptionAsync', 'PFGameSaveFilesSetSaveDescriptionResult', + 'PFGameSaveFilesSetUiActiveDeviceContentionResponse', 'PFGameSaveFilesSetUiCallbacks', + 'PFGameSaveFilesSetUiConflictResponse', 'PFGameSaveFilesSetUiOutOfStorageResponse', + 'PFGameSaveFilesSetUiProgressResponse', 'PFGameSaveFilesSetUiSyncFailedResponse', + 'PFGameSaveFilesSetWriteManifestsToDiskForDebug', 'PFGameSaveFilesUiProgressGetProgress', + 'PFGameSaveFilesUninitializeAsync', 'PFGameSaveFilesUninitializeResult', 'PFGameSaveFilesUploadWithUiAsync', + 'PFGameSaveFilesUploadWithUiResult', +) + + +def pe_exports(data): + """(export address table size, [(name, ordinal index, forwarder or None) for each named export]) of an x64 + PE image, or None. The table size also counts exports that have no name.""" + def u16(offset): + return int.from_bytes(data[offset:offset + 2], 'little') + + def u32(offset): + return int.from_bytes(data[offset:offset + 4], 'little') + + def string(offset): + end = data.find(b'\0', offset) + return None if offset is None or end < 0 else data[offset:end].decode('ascii', 'replace') + + if len(data) < 256 or data[:2] != b'MZ': + return None + pe = u32(60) + if data[pe:pe + 4] != b'PE\0\0' or u16(pe + 4) != 0x8664: + return None + count, optional_size = u16(pe + 6), u16(pe + 20) + optional = pe + 24 + if optional_size < 120 or u16(optional) != 0x20B or u32(optional + 108) < 1: + return None + sections = optional + optional_size + + def offset_of(address): + for index in range(count): + section = sections + index * 40 + start, size, raw = u32(section + 12), u32(section + 16), u32(section + 20) + if start <= address < start + size and raw + address - start < len(data): + return raw + address - start + return None + + directory_rva, directory_size = u32(optional + 112), u32(optional + 116) + directory = offset_of(directory_rva) + if directory is None or u32(directory + 16) != 1: + return None + functions, names = u32(directory + 20), u32(directory + 24) + function_table, name_table, ordinal_table = (offset_of(u32(directory + 28)), offset_of(u32(directory + 32)), + offset_of(u32(directory + 36))) + if None in (function_table, name_table, ordinal_table): + return None + exports = [] + for index in range(names): + name = string(offset_of(u32(name_table + 4 * index))) + ordinal = u16(ordinal_table + 2 * index) + address = u32(function_table + 4 * ordinal) if ordinal < functions else 0 + if name is None or not address: + return None + forward = string(offset_of(address)) if directory_rva <= address < directory_rva + directory_size else None + exports.append((name, ordinal, forward)) + return functions, exports + + +def playfab_sdk(data): + """The PlayFab Game Saves SDK the proxy was written for: exactly its 40 exports, all named, none forwarded.""" + parsed = pe_exports(data) + if parsed is None or parsed[0] != len(PGS_EXPORTS): + return False + exports = parsed[1] + return ([(name, ordinal) for name, ordinal, _ in exports] == list(zip(PGS_EXPORTS, range(len(PGS_EXPORTS)))) + and all(forward is None for _, _, forward in exports)) + + +def playfab_proxy(data): + """A save-folder proxy (this one or an earlier build): the same 40 exports, forwarding into nexus_pgs_native.""" + parsed = pe_exports(data) + if parsed is None or parsed[0] != len(PGS_EXPORTS): + return False + exports = parsed[1] + return ([name for name, _, _ in exports] == list(PGS_EXPORTS) + and any((forward or '').startswith(PGS_NATIVE[:-4] + '.') for _, _, forward in exports)) + + +def kept_sdk(native): + """True when nexus_pgs_native.dll is a regular file holding a recognised SDK.""" + return not native.is_symlink() and native.is_file() and playfab_sdk(native.read_bytes()) + + +def replace_file(directory, name, data): + descriptor, temporary = tempfile.mkstemp(prefix='.droiddeck-pgs-', dir=directory) + try: + with os.fdopen(descriptor, 'wb') as file: + file.write(data) + file.flush() + os.fsync(file.fileno()) + os.chmod(temporary, 0o644) + os.replace(temporary, Path(directory) / name) + except BaseException: + try: + os.unlink(temporary) + except OSError: + pass + raise + + +def stage_playfab_proxy(folder): + """Put the save-folder proxy in front of every PlayFab Game Saves SDK in the game folder. Returns how many.""" + try: + proxy = PGS_PROXY.read_bytes() + except OSError: + return 0 + staged = 0 + for root, _, files in os.walk(folder): + directory = Path(root) + for name in files: + if name.lower() != 'playfabgamesave.dll': + continue + path = directory / name + native = directory / PGS_NATIVE + try: + if path.is_symlink(): + continue + data = path.read_bytes() + if playfab_sdk(data): + # A first launch, or a game update that brought a new SDK: the update's copy becomes the native one, + # but only in place of nothing or of an earlier SDK copy, never over an unknown file or a link. + if os.path.lexists(native) and not kept_sdk(native): + print('droiddeck-xbox: unknown %s next to the PlayFab Game Saves SDK in %s; left unchanged' + % (PGS_NATIVE, directory), file=sys.stderr) + continue + replace_file(directory, PGS_NATIVE, data) + elif not playfab_proxy(data): + print('droiddeck-xbox: PlayFab Game Saves SDK with unknown exports in %s; left unchanged' % directory, + file=sys.stderr) + continue + elif not kept_sdk(native): + print('droiddeck-xbox: PlayFab save proxy without its SDK in %s; left unchanged' % directory, + file=sys.stderr) + continue + if data != proxy: + replace_file(directory, name, proxy) + staged += 1 + except OSError as error: + print('droiddeck-xbox: PlayFab save proxy not staged in %s (%s)' % (directory, error), file=sys.stderr) + return staged + + def renew_lease(ask, channel, product, lease, stopped): while not stopped.wait(15): response = ask(channel, {'op': 'xbox-renew', 'id': product, 'lease': lease}, timeout=10) @@ -255,6 +421,12 @@ def launch(command, env): pass if roots: owned_env['XODUS_CONTENT_ROOTS'] = ';'.join(roots) + # No DLL override for the proxy or the kept SDK: Wine has no builtin of either, so both load from the + # game folder as they are. Forcing them native-only (as Nexus does) made Forza Horizon 6 fail with E:0-0-4. + try: + stage_playfab_proxy(folder) + except Exception as error: + print('droiddeck-xbox: PlayFab save proxy skipped (%s)' % error, file=sys.stderr) return wine([reply['exe']], owned_env) finally: stopped.set() diff --git a/tools/release/runtime_inputs.py b/tools/release/runtime_inputs.py index 12ac22eabb..17b67722cf 100644 --- a/tools/release/runtime_inputs.py +++ b/tools/release/runtime_inputs.py @@ -109,7 +109,8 @@ def required(): ['comet', 'GalaxyCommunication.exe', 'update-permissions.exe', 'LICENSE', 'version']] paths += ['assets/linuxfs/usr/local/lib/droiddeck-xbox/' + name for name in ['xodus-cli', 'xodus-service', 'version', 'backend.lock.json', 'runtime.lock.json', 'LICENSE.xodus', 'LICENSE.nexus', 'LICENSE.LGPL-2.1', 'LICENSE.nghttp2', - 'windows/xgameruntime.dll', 'windows/winhttp.dll', 'windows/windows.web.dll', 'windows/twinapi.appcore.dll', 'windows/libnghttp2.dll']] + 'windows/xgameruntime.dll', 'windows/winhttp.dll', 'windows/windows.web.dll', 'windows/twinapi.appcore.dll', 'windows/libnghttp2.dll', + 'compat/PlayFabGameSave.dll', 'LICENSE.runtime-compat']] for driver in ['linux-wine11', 'linux-wine11-systhread']: paths += ['assets/directaudio/' + driver + '/' + name for name in ['aarch64-unix/winedirectaudio.so', 'aarch64-windows/winedirectaudio.drv', diff --git a/tools/tests/test_xbox_launch.py b/tools/tests/test_xbox_launch.py index 1701d6ea4b..76137248e6 100644 --- a/tools/tests/test_xbox_launch.py +++ b/tools/tests/test_xbox_launch.py @@ -211,3 +211,184 @@ class XboxLaunchTest(unittest.TestCase): with patch('subprocess.run', **outcome), patch('sys.stderr', new_callable=io.StringIO) as err: self.assertIsNone(xbox['register_classes']('/selected/proton', prefix, {})) self.assertIn('registration failed', err.getvalue()) + + +def pe_with_exports(names, forward=None, machine=0x8664, unnamed=0): + """A minimal x64 PE image whose export table names `names`; with `forward`, every export is forwarded there. + `unnamed` adds that many ordinal-only exports after the named ones.""" + rva, raw = 0x1000, 0x200 + functions = rva + 40 + name_pointers = functions + 4 * (len(names) + unnamed) + ordinals = name_pointers + 4 * len(names) + strings = ordinals + 2 * len(names) + blob = bytearray() + name_rvas, forward_rvas = [], [] + for name in names: + name_rvas.append(strings + len(blob)) + blob += name.encode() + b'\0' + for name in names: + forward_rvas.append(strings + len(blob)) + if forward: + blob += ('%s.%s' % (forward, name)).encode() + b'\0' + size = strings + len(blob) - rva + directory = bytearray(40) + directory[16:20] = (1).to_bytes(4, 'little') + directory[20:24] = (len(names) + unnamed).to_bytes(4, 'little') + directory[24:28] = len(names).to_bytes(4, 'little') + directory[28:32] = functions.to_bytes(4, 'little') + directory[32:36] = name_pointers.to_bytes(4, 'little') + directory[36:40] = ordinals.to_bytes(4, 'little') + section = bytearray(directory) + for index in range(len(names)): + section += (forward_rvas[index] if forward else 0x3000 + index).to_bytes(4, 'little') + for index in range(unnamed): + section += (0x4000 + index).to_bytes(4, 'little') + for value in name_rvas: + section += value.to_bytes(4, 'little') + for index in range(len(names)): + section += index.to_bytes(2, 'little') + section += blob + image = bytearray(raw) + image[:2] = b'MZ' + image[60:64] = (0x40).to_bytes(4, 'little') + image[0x40:0x44] = b'PE\0\0' + image[0x44:0x46] = machine.to_bytes(2, 'little') + image[0x46:0x48] = (1).to_bytes(2, 'little') + image[0x54:0x56] = (240).to_bytes(2, 'little') + optional = 0x58 + image[optional:optional + 2] = (0x20B).to_bytes(2, 'little') + image[optional + 108:optional + 112] = (16).to_bytes(4, 'little') + image[optional + 112:optional + 116] = rva.to_bytes(4, 'little') + image[optional + 116:optional + 120] = size.to_bytes(4, 'little') + header = optional + 240 + image[header + 8:header + 12] = len(section).to_bytes(4, 'little') + image[header + 12:header + 16] = rva.to_bytes(4, 'little') + image[header + 16:header + 20] = len(section).to_bytes(4, 'little') + image[header + 20:header + 24] = raw.to_bytes(4, 'little') + return bytes(image + section) + + +class PlayFabProxyTest(unittest.TestCase): + SDK = pe_with_exports(xbox['PGS_EXPORTS']) + NEWER_SDK = SDK + b'\0update' + PROXY = pe_with_exports(xbox['PGS_EXPORTS'], forward='nexus_pgs_native') + + def stage(self, root, proxy=PROXY): + runtime = Path(root) / 'runtime' + if proxy is not None: + (runtime / 'compat').mkdir(parents=True, exist_ok=True) + (runtime / 'compat/PlayFabGameSave.dll').write_bytes(proxy) + with patch.dict(xbox['stage_playfab_proxy'].__globals__, PGS_PROXY=runtime / 'compat/PlayFabGameSave.dll'), \ + patch('sys.stderr', new_callable=io.StringIO): + return xbox['stage_playfab_proxy'](Path(root) / 'game') + + def game(self, root, data, sub='Bin'): + folder = Path(root) / 'game' / sub + folder.mkdir(parents=True) + (folder / 'PlayFabGameSave.dll').write_bytes(data) + return folder + + def test_sdk_and_proxy_are_told_apart_by_their_exports(self): + self.assertTrue(xbox['playfab_sdk'](self.SDK)) + self.assertFalse(xbox['playfab_proxy'](self.SDK)) + self.assertTrue(xbox['playfab_proxy'](self.PROXY)) + self.assertFalse(xbox['playfab_sdk'](self.PROXY)) + other = pe_with_exports(list(xbox['PGS_EXPORTS'][:-1]) + ['PFGameSaveFilesSomethingNew']) + self.assertFalse(xbox['playfab_sdk'](other)) + self.assertFalse(xbox['playfab_sdk'](pe_with_exports(xbox['PGS_EXPORTS'], machine=0xAA64))) + self.assertIsNone(xbox['pe_exports'](b'not a pe image')) + self.assertEqual(xbox['pe_exports'](pe_with_exports(['A', 'B'], unnamed=1))[0], 3) + self.assertFalse(xbox['playfab_sdk'](pe_with_exports(xbox['PGS_EXPORTS'], unnamed=1))) + self.assertFalse(xbox['playfab_proxy'](pe_with_exports(xbox['PGS_EXPORTS'], forward='nexus_pgs_native', unnamed=1))) + + def test_first_launch_keeps_the_sdk_and_puts_the_proxy_in_front(self): + with tempfile.TemporaryDirectory() as root: + folder = self.game(root, self.SDK) + self.assertEqual(self.stage(root), 1) + self.assertEqual((folder / 'nexus_pgs_native.dll').read_bytes(), self.SDK) + self.assertEqual((folder / 'PlayFabGameSave.dll').read_bytes(), self.PROXY) + self.assertEqual(self.stage(root), 1) + self.assertEqual((folder / 'nexus_pgs_native.dll').read_bytes(), self.SDK) + self.assertEqual(sorted(path.name for path in folder.iterdir()), ['PlayFabGameSave.dll', 'nexus_pgs_native.dll']) + + def test_a_game_update_replaces_the_kept_sdk(self): + with tempfile.TemporaryDirectory() as root: + folder = self.game(root, self.SDK) + self.stage(root) + (folder / 'PlayFabGameSave.dll').write_bytes(self.NEWER_SDK) + self.assertEqual(self.stage(root), 1) + self.assertEqual((folder / 'nexus_pgs_native.dll').read_bytes(), self.NEWER_SDK) + self.assertEqual((folder / 'PlayFabGameSave.dll').read_bytes(), self.PROXY) + + def test_an_older_proxy_is_refreshed_only_while_its_sdk_is_there(self): + older = self.PROXY + b'\0older' + with tempfile.TemporaryDirectory() as root: + folder = self.game(root, older) + (folder / 'nexus_pgs_native.dll').write_bytes(self.SDK) + self.assertEqual(self.stage(root), 1) + self.assertEqual((folder / 'PlayFabGameSave.dll').read_bytes(), self.PROXY) + with tempfile.TemporaryDirectory() as root: + folder = self.game(root, older) + self.assertEqual(self.stage(root), 0) + self.assertEqual((folder / 'PlayFabGameSave.dll').read_bytes(), older) + + def test_an_unknown_file_or_link_in_place_of_the_kept_sdk_is_never_overwritten(self): + with tempfile.TemporaryDirectory() as root: + folder = self.game(root, self.SDK) + (folder / 'nexus_pgs_native.dll').write_bytes(b'MZ someone else') + self.assertEqual(self.stage(root), 0) + self.assertEqual((folder / 'nexus_pgs_native.dll').read_bytes(), b'MZ someone else') + self.assertEqual((folder / 'PlayFabGameSave.dll').read_bytes(), self.SDK) + with tempfile.TemporaryDirectory() as root: + folder = self.game(root, self.SDK) + target = Path(root) / 'elsewhere.dll' + target.write_bytes(self.SDK) + (folder / 'nexus_pgs_native.dll').symlink_to(target) + self.assertEqual(self.stage(root), 0) + self.assertTrue((folder / 'nexus_pgs_native.dll').is_symlink()) + self.assertEqual(target.read_bytes(), self.SDK) + self.assertEqual((folder / 'PlayFabGameSave.dll').read_bytes(), self.SDK) + + def test_unknown_sdk_symlinks_and_a_runtime_without_the_proxy_are_left_alone(self): + with tempfile.TemporaryDirectory() as root: + unknown = pe_with_exports(['PFGameSaveFilesInitialize']) + folder = self.game(root, unknown) + self.assertEqual(self.stage(root), 0) + self.assertEqual((folder / 'PlayFabGameSave.dll').read_bytes(), unknown) + self.assertFalse((folder / 'nexus_pgs_native.dll').exists()) + with tempfile.TemporaryDirectory() as root: + folder = self.game(root, self.SDK) + self.assertEqual(self.stage(root, proxy=None), 0) + self.assertEqual((folder / 'PlayFabGameSave.dll').read_bytes(), self.SDK) + with tempfile.TemporaryDirectory() as root: + target = Path(root) / 'elsewhere.dll' + target.write_bytes(self.SDK) + folder = Path(root) / 'game' + folder.mkdir() + (folder / 'PlayFabGameSave.dll').symlink_to(target) + self.assertEqual(self.stage(root), 0) + self.assertEqual(target.read_bytes(), self.SDK) + + def test_launch_stages_the_proxy_without_dll_overrides_and_survives_a_failure(self): + with tempfile.TemporaryDirectory() as root: + root = Path(root) + runtime = root / 'windows' + runtime.mkdir() + for name in xbox['DLLS']: + (runtime / name).touch() + store = {'find_store_game': lambda argv: (root, {'store': 'xbox', 'id': 'GAME'}), + 'ask': unittest.mock.Mock(return_value={'ok': True, 'socket': '/service', 'lease': 'lease-1', + 'exe': '/Game.exe'})} + wine = unittest.mock.Mock(return_value=0) + staged = [] + def failing(folder): + raise RuntimeError('unreadable game folder') + for stage in (lambda folder: staged.append(folder) or 1, failing): + wine.reset_mock() + with patch('runpy.run_path', return_value=store), patch('sys.stderr', new_callable=io.StringIO), \ + patch.dict(xbox['launch'].__globals__, RUNTIME=root, bridge=lambda path: (1, 'key', lambda: None), + wine=wine, stage_playfab_proxy=stage): + self.assertEqual(xbox['launch'](['/proton', 'waitforexitandrun', '/Game.exe'], + {'BL_LAUNCH_DIR': '/launch', 'WINEDLLOVERRIDES': 'd3d11=n'}), 0) + self.assertEqual(wine.call_args.args[1]['WINEDLLOVERRIDES'], 'd3d11=n') + self.assertEqual(staged, [root]) diff --git a/tools/xbox/runtime.lock.json b/tools/xbox/runtime.lock.json index eb3042fa45..e99520de78 100644 --- a/tools/xbox/runtime.lock.json +++ b/tools/xbox/runtime.lock.json @@ -14,5 +14,15 @@ "xgameruntime.dll": "060120e0ec6bccfbab516128315a0658b11d3e316f62a917c653daf1a1dd3e05", "winhttp.dll": "81e1da7a731d83fbd24dbe2fa2ecb8f155bd477a9f9b6f4cc3932063cc326c27", "wintypes.dll": "7d06083e3d8b3a7e11555a91e7918f11c7d444a74755d41c8d1990db3697c895" + }, + "compat": { + "files/share/xodus-nexus/compat/PlayFabGameSave.dll": [ + "compat/PlayFabGameSave.dll", + "29b1ab5e54b35e40ee5b376237f4ab642e1d0f3d7614e3e46208e9ad8a6e0a79" + ], + "files/share/doc/xodus-nexus-runtime/runtime-compat-LICENSE": [ + "LICENSE.runtime-compat", + "639b735fd2f65779b82c4aab471f1fcdf927e10e1c21250911f75d44d136ff11" + ] } } diff --git a/tools/xbox/runtime.py b/tools/xbox/runtime.py index 38bb102395..2cafe4a592 100755 --- a/tools/xbox/runtime.py +++ b/tools/xbox/runtime.py @@ -37,8 +37,22 @@ archive = download(lock['archive'], lock['sha512'], 'sha512') source = lock['source'] download(source['name'], source['sha256'], 'sha256') remaining = set(lock['dlls']) +# Prebuilt runtime-compat files from the same archive (MIT), placed next to windows/ in the pack: the +# PlayFab Game Saves save-folder proxy that droiddeck-xbox stages in front of a title's SDK, and its license. +compat = dict(lock.get('compat', {})) with tarfile.open(archive) as tar: for member in tar: + relative = member.name.partition('/')[2] + if relative in compat: + target, expected = compat.pop(relative) + if not member.isfile() or member.size > 32 * 1024 * 1024: + raise RuntimeError('Invalid Xbox runtime compatibility file') + data = tar.extractfile(member).read() + if hashlib.sha256(data).hexdigest() != expected: + raise RuntimeError('Xbox runtime compatibility file checksum mismatch') + (output.parent / target).parent.mkdir(parents=True, exist_ok=True) + (output.parent / target).write_bytes(data) + continue name = Path(member.name).name if '/files/lib/wine/x86_64-windows/' not in member.name or name not in remaining: continue @@ -53,3 +67,5 @@ with tarfile.open(archive) as tar: remaining.remove(name) if remaining: raise RuntimeError('Missing Xbox runtime modules') +if compat: + raise RuntimeError('Missing Xbox runtime compatibility files')