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
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-18 18:32:06 -05:00
1 parent 6ed281f78d
commit 123c431b8e
31 files changed
+1999 -132

No files matched your search

+4 -4
View File
@@ -1318,7 +1318,7 @@ class StoreLaunchClientTest(unittest.TestCase):
(self.folder / ".droiddeck-store.json").write_text(json.dumps(sidecar))
with mock.patch.dict(os.environ, {"DD_LAUNCH_DIR": str(self.tmp / "launch"), "STEAM_COMPAT_DATA_PATH": ""}), \
mock.patch.dict(S, {"client_wanted": lambda: calls.append("wanted") or True,
"ask": lambda channel, request, timeout=0: calls.append(request["op"]) or {"ok": True}}):
"ask": lambda channel, request, timeout=0, claim=False: calls.append(request["op"]) or {"ok": True}}):
S["main"]([str(self.folder / ".droiddeck-launch.bat")])
self.assertNotIn("wanted", calls)
self.assertNotIn("epic-code", calls)
@@ -1341,7 +1341,7 @@ class StoreLaunchClientTest(unittest.TestCase):
with mock.patch.dict(os.environ, env), \
mock.patch.dict(S, {"client_wanted": lambda: True,
"through_client": lambda folder, sidecar, timeout=0: calls.append("client") or "timeout",
"ask": lambda channel, request, timeout=0: calls.append(request["op"]) or {"ok": True, "code": True}}):
"ask": lambda channel, request, timeout=0, claim=False: calls.append(request["op"]) or {"ok": True, "code": True}}):
S["main"]([str(self.folder / ".droiddeck-launch.bat")])
self.assertEqual(["client", "epic-code", "cloud-down"], calls)
@@ -1356,7 +1356,7 @@ class StoreLaunchClientTest(unittest.TestCase):
(self.folder / ".droiddeck-epic-code").write_text("stale")
with mock.patch.dict(os.environ, {"DD_LAUNCH_DIR": str(self.tmp / "launch"), "STEAM_COMPAT_DATA_PATH": ""}), \
mock.patch.dict(S, {"client_wanted": lambda: True, "through_client": through,
"ask": lambda channel, request, timeout=0: calls.append(request["op"]) or {"ok": True}}):
"ask": lambda channel, request, timeout=0, claim=False: calls.append(request["op"]) or {"ok": True}}):
S["main"]([str(self.folder / ".droiddeck-launch.bat")])
self.assertEqual(["client", "cloud-down"], calls)
self.assertFalse((self.folder / ".droiddeck-epic-code").exists())
@@ -1368,7 +1368,7 @@ class StoreLaunchClientTest(unittest.TestCase):
with mock.patch.dict(os.environ, {"DD_LAUNCH_DIR": str(self.tmp / "launch"), "DROIDDECK_EPIC_HANDLED": "1",
"STEAM_COMPAT_DATA_PATH": ""}), \
mock.patch.dict(S, {"client_wanted": lambda: calls.append("wanted") or True,
"ask": lambda channel, request, timeout=0: calls.append(request["op"]) or {"ok": True}}):
"ask": lambda channel, request, timeout=0, claim=False: calls.append(request["op"]) or {"ok": True}}):
S["main"]([str(self.folder / ".droiddeck-launch.bat")])
self.assertEqual(["cloud-down"], calls)
self.assertTrue((self.folder / ".droiddeck-epic-args").exists())
+107 -2
View File
@@ -106,6 +106,62 @@ class Asking(unittest.TestCase):
self.assertIsNone(store.ask(channel, {'op': 'epic-code'}, timeout=0.2))
self.assertEqual([], list((channel / 'req').iterdir()))
def test_a_cloud_download_the_launcher_stops_waiting_for_loses_its_claim(self):
with tempfile.TemporaryDirectory() as root:
channel = Path(root) / 'stores'
taken = []
handed = threading.Event()
def app():
deadline = time.monotonic() + 5
while not taken and time.monotonic() < deadline:
for request in (channel / 'req').glob('*.json') if (channel / 'req').is_dir() else []:
target = channel / 'resp' / (request.stem + '.taken')
os.rename(request, target)
taken.append(target)
handed.set()
time.sleep(0.02)
t = threading.Thread(target=app, daemon=True)
t.start()
try:
self.assertIsNone(store.ask(channel, {'op': 'cloud-down'}, timeout=2.0, claim=True))
finally:
t.join(5)
self.assertTrue(handed.is_set(), 'the app never took the request')
with self.assertRaises(OSError):
os.rename(taken[0], taken[0].with_suffix('.writing'))
def test_a_claimed_cloud_download_is_waited_for(self):
with tempfile.TemporaryDirectory() as root:
channel = Path(root) / 'stores'
handed = threading.Event()
def app():
deadline = time.monotonic() + 5
while time.monotonic() < deadline:
names = list((channel / 'req').glob('*.json')) if (channel / 'req').is_dir() else []
if names:
handed.set()
writing = channel / 'resp' / (names[0].stem + '.writing')
os.rename(names[0], writing)
time.sleep(0.6)
tmp = channel / 'resp' / (names[0].name + '.tmp')
tmp.write_text(json.dumps({'ok': True, 'result': 'ok'}))
os.rename(tmp, channel / 'resp' / names[0].name)
writing.unlink()
return
time.sleep(0.02)
t = threading.Thread(target=app, daemon=True)
t.start()
try:
answer = store.ask(channel, {'op': 'cloud-down'}, timeout=0.2, claim=True)
finally:
t.join(5)
self.assertTrue(handed.is_set(), 'the app never took the request')
self.assertEqual({'ok': True, 'result': 'ok'}, answer)
def test_a_stale_code_is_dropped_before_asking(self):
with tempfile.TemporaryDirectory() as root:
folder = game(root)
@@ -214,7 +270,7 @@ class CloudHooks(unittest.TestCase):
try:
original = store.ask
asked = []
store.ask = lambda channel, request, timeout=5.0: asked.append((request, timeout)) or {'ok': True, 'files': 2, 'reason': 'ok'}
store.ask = lambda channel, request, timeout=5.0, claim=False: asked.append((request, timeout)) or {'ok': True, 'files': 2, 'reason': 'ok'}
self.assertEqual(store.STORE_GAME, store.main([bat]))
self.assertEqual(0, store.main(['--exited', bat]))
finally:
@@ -225,6 +281,55 @@ class CloudHooks(unittest.TestCase):
self.assertEqual(store.CLOUD_TIMEOUT, asked[1][1])
self.assertEqual('cloud-up', asked[2][0]['op'])
def test_a_cloud_request_that_cannot_be_written_still_starts_the_game_and_uploads_on_exit(self):
with tempfile.TemporaryDirectory() as root:
folder = game(root, store_id='ubisoft', ident='space-1')
sc = json.loads((folder / '.droiddeck-store.json').read_text()); sc['extra'] = {'productId': '109'}
(folder / '.droiddeck-store.json').write_text(json.dumps(sc))
bat = str(folder / '.droiddeck-launch.bat')
asked = []
def ask(channel, request, timeout=5.0, claim=False):
asked.append(request['op'])
if request['op'] in ('cloud-down', 'cloud-up'):
raise PermissionError(13, 'read-only')
return {'ok': True}
lines = []
with patch.dict(os.environ, {'DD_LAUNCH_DIR': str(Path(root) / 'session')}), patch.object(store, 'ask', side_effect=ask), patch.object(store, 'prepare_ubisoft', return_value='ready'), patch.object(store, 'create_prefix', return_value='present'), patch.object(store, 'log', side_effect=lines.append):
self.assertEqual(store.STORE_GAME, store.main([bat]))
self.assertEqual(0, store.main(['--exited', bat]))
self.assertEqual(['cloud-down', 'cloud-up'], [op for op in asked if op.startswith('cloud-')])
self.assertIn('cloud ubisoft space-1 down result=failed reason=PermissionError', lines)
self.assertIn('cloud ubisoft space-1 up not requested (PermissionError)', lines)
def test_an_ea_game_with_cloud_saves_asks_after_its_preparation_and_exit(self):
ident = 'Origin.OFR.50.0002694'
with tempfile.TemporaryDirectory() as root:
folder = game(root, store_id='ea', ident=ident)
bat = str(folder / '.droiddeck-launch.bat')
asked = []
env = {'DD_LAUNCH_DIR': str(Path(root) / 'session')}
record = lambda channel, request, timeout=5.0, claim=False: asked.append(request) or {'result': 'ok'}
with patch.dict(os.environ, env), \
patch.object(store, 'prepare_ea', side_effect=lambda *a: asked.append({'op': 'prepared'})), \
patch.object(store, 'create_prefix', side_effect=AssertionError('EA prepares its own prefix')), \
patch.object(store, 'ask', side_effect=record):
self.assertEqual(store.STORE_GAME, store.main([bat]))
self.assertEqual(['prepared', 'cloud-down'], [r['op'] for r in asked])
self.assertEqual({'op': 'cloud-down', 'store': 'ea', 'id': ident}, asked[1])
self.assertEqual(0, store.main(['--exited', bat]))
self.assertEqual(['ea-exited', 'cloud-up'], [r['op'] for r in asked[2:]])
self.assertEqual({'op': 'cloud-up', 'store': 'ea', 'id': ident}, asked[3])
sidecar = json.loads((folder / store.SIDECAR).read_text())
sidecar['cloud'] = False
(folder / store.SIDECAR).write_text(json.dumps(sidecar))
asked.clear()
with patch.dict(os.environ, env), patch.object(store, 'prepare_ea'), patch.object(store, 'ask', side_effect=record):
self.assertEqual(store.STORE_GAME, store.main([bat]))
self.assertEqual([], asked)
self.assertEqual(0, store.main(['--exited', bat]))
self.assertEqual(['ea-exited'], [r['op'] for r in asked])
def test_a_first_launch_creates_the_prefix_before_the_cloud_download(self):
with tempfile.TemporaryDirectory() as root:
folder = game(root, store_id='epic', ident='fa4240e5')
@@ -244,7 +349,7 @@ class CloudHooks(unittest.TestCase):
env = {'DD_LAUNCH_DIR': root, 'STEAM_COMPAT_DATA_PATH': str(compat), 'DD_STORE_PROTON': str(proton)}
with patch.dict(os.environ, env), patch.object(store.subprocess, 'run', side_effect=run), \
patch.object(store, 'ask', side_effect=lambda channel, request, timeout=5.0: order.append(request) or {'result': 'ok'}):
patch.object(store, 'ask', side_effect=lambda channel, request, timeout=5.0, claim=False: order.append(request) or {'result': 'ok'}):
self.assertEqual(store.STORE_GAME, store.main([str(folder / store.LAUNCHER)]))
self.assertEqual([str(proton), 'run', 'cmd.exe', '/d', '/c', 'exit'], order[0])
self.assertEqual({'op': 'cloud-down', 'store': 'epic', 'id': 'fa4240e5'}, order[-1])
+1 -1
View File
@@ -147,7 +147,7 @@ class EaHook(unittest.TestCase):
folder.mkdir()
asked = {}
def fake_ask(channel, request, timeout=5.0):
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()}]}