Files
DroidDeck/tools/tests/test_store_launch_ea.py
T
Kurt Himebauch 123c431b8e feat(ea, ubisoft): cloud saves and a kept Ubisoft Denuvo token (#2824)
* feat(ubisoft): keep Denuvo game tokens per account and product until the game invalidates them

* feat(ubisoft): sync cloud saves through Ubisoft's cloud save service

* fix(xbox): turning cloud saves off passes the offline mode the game save runtime reads

* fix(ubisoft): Ubisoft games list their shared prefix, so they get a saves and cloud tab

* feat(ea): sync cloud saves through EA's cloud sync service

* fix(ea): sync at EA launch and exit, keep one rule snapshot, and check the cloud copy under the write lock

* fix(ubisoft): exact slot versions, scoped save export, and a Denuvo cache bound to its account

* fix(ea): fresh rules per sync, checksums required, backup before restore, and sign-in shown on the saves tab

* fix(ubisoft): launch-time sync on the shared prefix, saves scoped to the game, and Denuvo bound to each launch's account

* fix(ea): back up only the saves a restore replaces, refuse truncated manifests, and need a master title id

* fix(ubisoft): treat a slot whose bytes changed since the last sync as a conflict before uploading over it

* fix(ea): one resolved save folder per sync, refuse case collisions, and walk each folder once

* fix(ubisoft): sync only identified slots, keep live saves and backups safe, and tie a pending eviction to its account

* fix(cloud): a forced download fetches every saved conflict and keeps the ones it could not write

* test(ea): keep the cloud save cases in EaTest

* fix(ubisoft): report only written slots, keep drift conflicts, read whole headers, and never rename a named eviction

* fix(ea): keep real save folders in the inventory, back up any restored file, refuse duplicate or malformed cloud listings

* fix(cloud): commit Ubisoft slots one at a time and stop on a newer cloud write, name skipped and blocked slots, keep unsent conflicts

* fix(ubisoft): acknowledge an invalidation only once its marker is published and never serve a kept token after it

* fix(cloud): a cloud request the launcher cannot write still starts the game and keeps the exit upload

* fix(cloud): scope Ubisoft sync state to the account and product, compare alike slots, keep committed progress, and name partial slots

* fix(ea): ask for sign-in after a rejected refresh, upload saves reached through folder aliases

* fix(cloud): a launch that stops waiting for the cloud download claims it back, so no save is written once the game starts

* fix(ubisoft): name the account in an invalidation marker and never hold the token lock across a pipe write

* fix(ea): only invalid_grant asks for sign-in again, and case collisions count only among synced saves

* test(epic): let the launcher's ask doubles take the claim flag

* fix(ea): apply save rules in their order, match bare patterns inside the save folder, and resolve LocalLow and install folders

* fix(ubisoft): stamp a fresh identifier into a new save that has none, so it can sync

* fix(ubisoft): answer a burn ticket request as unavailable instead of leaving the game waiting

* fix(cloud): read EA manifests with the XML parser, clear conflicts whose sides match, and bound the claim and stall tests
2026-11-18 18:32:06 -05:00

176 lines
9.9 KiB
Python

import base64
import importlib.machinery
import importlib.util
import json
from pathlib import Path
import tempfile
import unittest
from unittest.mock import patch
BIN = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin'
loader = importlib.machinery.SourceFileLoader('droiddeck_store_launch_ea', str(BIN / 'droiddeck-store-launch'))
spec = importlib.util.spec_from_loader(loader.name, loader)
store = importlib.util.module_from_spec(spec)
loader.exec_module(store)
class EaHook(unittest.TestCase):
def test_wmi_output_reads_the_value_under_the_header(self):
text = 'Manufacturer \r\r\nThe Wine Project \r\r\n\r\r\n'
self.assertEqual(store.wmi_value(text), 'The Wine Project')
self.assertEqual(store.wmi_value(store.decode_output('Name\r\nFEX CPU\r\n'.encode('utf-16'))), 'FEX CPU')
self.assertEqual(store.wmi_value(''), '')
def test_registry_points_the_game_keys_at_the_install_folder(self):
sidecar = {'id': 'Origin.OFR.50.0001', 'title': 'Mass Effect 3', 'extra': {'registry': json.dumps([
[r'HKEY_LOCAL_MACHINE\SOFTWARE\EA Games\Game', 'Install Dir'],
[r'HKLM\SOFTWARE\Respawn\Titanfall2', 'Install Dir'],
[r'HKEY_CLASSES_ROOT\x', 'y'],
])}}
entries = store.ea_registry_entries(Path('/root/Games/Stores/EA/Game'), sidecar)
self.assertIn((r'HKEY_LOCAL_MACHINE\SOFTWARE\Origin', 'ClientPath', store.EA_CLIENT), entries)
game = [e for e in entries if e[1] == 'Install Dir']
self.assertEqual([e[0] for e in game], [r'HKEY_LOCAL_MACHINE\SOFTWARE\EA Games\Game', r'HKEY_LOCAL_MACHINE\SOFTWARE\Respawn\Titanfall2'])
self.assertEqual(game[0][2], 'Z:' + '\\'.join(['', 'root', 'Games', 'Stores', 'EA', 'Game', '']))
self.assertIn((r'HKEY_LOCAL_MACHINE\SOFTWARE\EA Games\Game', 'DisplayName', 'Mass Effect 3'), entries)
self.assertIn((r'HKEY_LOCAL_MACHINE\SOFTWARE\Respawn\Titanfall2', 'DisplayName', 'Mass Effect 3'), entries)
def test_the_games_exe_maps_to_its_launcher_only(self):
with tempfile.TemporaryDirectory() as tmp:
folder = Path(tmp) / 'Game'
(folder / 'bin').mkdir(parents=True)
for name in ('bin/Game.exe', 'bin/Other.exe', store.LAUNCHER):
(folder / name).write_text('x')
sidecar = {'store': 'ea', 'id': 'Origin.OFR.50.1', 'exe': 'bin/Game.exe', 'launcher': store.LAUNCHER}
(folder / store.SIDECAR).write_text(json.dumps(sidecar))
self.assertEqual(store.store_launcher(str(folder / 'bin/Game.exe')), str(folder / store.LAUNCHER))
self.assertEqual(store.store_launcher(str(folder / 'bin/game.exe')), str(folder / store.LAUNCHER))
self.assertIsNone(store.store_launcher(str(folder / 'bin/Other.exe')))
self.assertIsNone(store.store_launcher(str(Path(tmp) / 'Elsewhere.exe')))
(folder / store.SIDECAR).write_text(json.dumps(dict(sidecar, launcher='')))
self.assertIsNone(store.store_launcher(str(folder / 'bin/Game.exe')))
def test_a_symlinked_or_deep_exe_still_finds_its_launcher(self):
with tempfile.TemporaryDirectory() as tmp:
folder = Path(tmp) / 'Game'
deep = folder / 'a/b/c/d/e/f'
deep.mkdir(parents=True)
(deep / 'Game.exe').write_text('x')
(folder / store.LAUNCHER).write_text('x')
sidecar = {'store': 'ea', 'id': 'Origin.OFR.50.1', 'exe': 'a/b/c/d/e/f/Game.exe', 'launcher': store.LAUNCHER}
(folder / store.SIDECAR).write_text(json.dumps(sidecar))
link = Path(tmp) / 'x/y/z/Link.exe'
link.parent.mkdir(parents=True)
link.symlink_to(deep / 'Game.exe')
expected = str(folder.resolve() / store.LAUNCHER)
self.assertEqual(store.store_launcher(str(deep / 'Game.exe')), expected)
self.assertEqual(store.store_launcher(str(link)), expected)
self.assertIsNone(store.find_store_game([str(deep / 'Game.exe')]))
def test_a_symlinked_exe_finds_the_sidecar_beside_the_link(self):
with tempfile.TemporaryDirectory() as tmp:
outside = Path(tmp) / 'Real/Game.exe'
outside.parent.mkdir()
outside.write_text('x')
folder = Path(tmp) / 'Game'
folder.mkdir()
(folder / store.LAUNCHER).write_text('x')
(folder / 'Game.exe').symlink_to(outside)
sidecar = {'store': 'ea', 'id': 'Origin.OFR.50.1', 'exe': 'Game.exe', 'launcher': store.LAUNCHER}
(folder / store.SIDECAR).write_text(json.dumps(sidecar))
self.assertEqual(store.store_launcher(str(folder / 'Game.exe')), str(folder / store.LAUNCHER))
self.assertIsNone(store.store_launcher(str(outside)))
def test_legacy_games_are_registered_by_content_id(self):
sidecar = {'id': 'Origin.OFR.50.0005237', 'title': 'Mass Effect 3 (2012)',
'extra': {'contentIds': '71073,71183, bad id', 'displayName': 'Mass Effect 3', 'locale': 'fr_FR'}}
entries = store.ea_registry_entries(Path('/root/Games/ME3'), sidecar)
key = r'HKEY_LOCAL_MACHINE\SOFTWARE\Origin Games' + '\\'
self.assertIn((key + '71073', 'DisplayName', 'Mass Effect 3'), entries)
self.assertIn((key + '71183', 'Locale', 'fr_FR'), entries)
self.assertFalse(any('bad id' in e[0] for e in entries))
def test_cpuid_probe_is_a_32_bit_console_program(self):
import struct
exe = store.cpuid_exe()
self.assertEqual(exe[:2], b'MZ')
self.assertEqual(exe[0x40:0x44], b'PE\0\0')
self.assertEqual(struct.unpack_from('<H', exe, 0x44)[0], 0x14C)
self.assertEqual(struct.unpack_from('<H', exe, 0x58)[0], 0x10B)
self.assertEqual(struct.unpack_from('<H', exe, 0x58 + 68)[0], 3)
self.assertIn(b'KERNEL32.dll', exe)
self.assertEqual(len(exe), 0x400)
def test_origin_stub_is_a_windowless_program_installed_once(self):
import struct
exe = store.origin_stub_exe()
self.assertEqual(exe[:2], b'MZ')
self.assertEqual(struct.unpack_from('<H', exe, 0x58 + 68)[0], 2)
self.assertIn(b'Sleep', exe)
self.assertEqual(exe[0x208:0x20A], b'\xeb\xf6')
with tempfile.TemporaryDirectory() as tmp:
self.assertEqual(store.install_origin_stub(tmp), 'written')
self.assertEqual(store.install_origin_stub(tmp), 'ready')
self.assertTrue((Path(tmp) / 'pfx/drive_c/Program Files (x86)/Origin/Origin.exe').is_file())
self.assertTrue(store.EA_CLIENT.endswith('Origin.exe'))
def test_cpuid_output_is_decoded_as_the_game_sees_it(self):
raw = bytes.fromhex('1600000047656e756e74656c696e654961060a00000805000f23d882fffb8b27436f727465782d4135323000000000000000000000000000000000000000000000000000000000000000000000000000')
self.assertEqual(store.cpuid_values(raw), {'cpuVendor': 'GenuineIntel', 'cpuEax': '000A0661', 'cpuEdx': '278BFBFF',
'cpuEcx': '82d8230f', 'cpuBrand': 'Cortex-A520'})
self.assertEqual(store.cpuid_values(b''), {})
def test_touchup_arguments_fill_locale_and_folder(self):
install = r'Z:\root\My Game'
args = store.touchup_args('-locale {locale} -installPath "{installLocation}" /silent', 'fr_FR', install)
self.assertEqual(args, ['-locale', 'fr_FR', '-installPath', install, '/silent'])
def test_licences_stay_inside_the_prefix(self):
with tempfile.TemporaryDirectory() as tmp:
data = base64.b64encode(b'licence').decode()
written = store.write_licenses(tmp, [
{'path': 'ProgramData/Electronic Arts/EA Services/License/X.dlf', 'data': data},
{'path': '../escape.dlf', 'data': data},
{'path': '/abs.dlf', 'data': data},
])
self.assertEqual(written, 1)
self.assertEqual((Path(tmp) / 'pfx/drive_c/ProgramData/Electronic Arts/EA Services/License/X.dlf').read_bytes(), b'licence')
def test_prepare_asks_the_app_and_writes_the_licence(self):
with tempfile.TemporaryDirectory() as tmp:
compat = Path(tmp) / 'compat'
(compat / 'pfx').mkdir(parents=True)
(compat / 'pfx/user.reg').write_text('')
probe = {key: 'x' for key in store.EA_PROBE_FIELDS}
(compat / 'pfx' / store.EA_HARDWARE).write_text(json.dumps(probe))
folder = Path(tmp) / 'game'
folder.mkdir()
asked = {}
def fake_ask(channel, request, timeout=5.0, claim=False):
asked.update(request)
return {'ok': True, 'lsx': True, 'license': 'ok v4', 'licenses': [{'path': 'ProgramData/L/x.dlf', 'data': base64.b64encode(b'z').decode()}]}
with patch.object(store, 'ask', fake_ask), patch.object(store, 'ea_registry', lambda *a, **k: 'ready'), \
patch.object(store, 'ea_touchup', lambda *a, **k: 'none'), patch.dict('os.environ', {'DD_STORE_PROTON': ''}):
store.prepare_ea(folder, {'id': 'Origin.OFR.1'}, str(compat), str(Path(tmp) / 'launch'))
self.assertEqual(asked['op'], 'ea-prepare')
self.assertEqual(asked['hardware'], probe)
self.assertEqual((compat / 'pfx/drive_c/ProgramData/L/x.dlf').read_bytes(), b'z')
def test_an_incomplete_cached_probe_is_probed_again(self):
with tempfile.TemporaryDirectory() as tmp:
pfx = Path(tmp) / 'pfx'
pfx.mkdir()
partial = {key: 'x' for key in store.EA_PROBE_FIELDS if key != 'osInstallDate'}
(pfx / store.EA_HARDWARE).write_text(json.dumps(partial))
self.assertFalse(store.probe_complete(partial))
self.assertEqual(store.ea_hardware(tmp, ''), ({}, 'no-proton'))
whole = dict(partial, osInstallDate='20261108')
(pfx / store.EA_HARDWARE).write_text(json.dumps(whole))
self.assertEqual(store.ea_hardware(tmp, ''), (whole, 'cached'))
if __name__ == '__main__':
unittest.main()