feat: EA store with sign-in, library, native downloads, updates and launch without the EA app (#2259)

* docs: research and plan for EA and Ubisoft stores

* feat(ea): EA store with sign-in, library, native downloads, updates and launch without the EA app

* perf(ea): fetch large archive records as parallel ranges

* fix(ea): register game display names

* fix(ea): license legacy EA Core games and harden the LSX endpoint

* fix(ea): run legacy Origin SDK games with a stand-in Origin process

* fix(ea): trust only the prepared game on LSX and stop stale library syncs

* fix(ea): close LSX sessions on stop and drop clients that never hand-shake

* fix(ea): require every hashed field before licensing or caching a probe

* fix(ea): trust one LSX session per launch

* fix(ea): serialize the library cache write with sign-out and rerun a skipped sync

* fix(ea): hand off library sync requests under one lock

* fix(ea): clear the sign-in before invalidating the library

* fix(ea): serialize sign-out with token refresh and with the library cache

* fix(ea): LSX trusts only verified peers, new launch closes old sessions, exit stops its own game

* fix(ea): LSX hides profile and presence from unverified peers

* fix(ea): LSX handshake has a fixed deadline and untrusted sessions yield their slot

* fix(ea): LSX never registers a client after its listener was stopped

* fix(ea): LSX evicts each untrusted session at most once

* fix(ea): LSX admission and eviction share one lock and keep the cap

* fix(ea): LSX trust promotion excludes eviction

* fix(ea): LSX launch generation guards restarts and drops results after shutdown

* fix(ea): LSX publishes launch state under the admission lock and tags accepts by generation

* fix(ea): LSX restarts rebind its listener and promotion checks the launch generation

* fix(ea): record why EA refuses a game licence in the store log

* chore(ea): log owned offers and the full licence refusal

* chore(ea): log the account's entitlements when no game licence is granted

* chore(ea): log legacy entitlements when no game licence is granted

* chore(ea): log only the refused game's own entitlements

* fix(ea): skip trial launchers flagged 1 and license games whose LSX peer Android cannot name
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-10 14:56:29 -05:00
1 parent 9bf638a3c4
commit d8ed02f2cf
46 files changed
+5284 -7

No files matched your search

@@ -5,6 +5,7 @@ import binascii
import json
import os
import re
import shlex
import shutil
import sys
import time
@@ -276,6 +277,10 @@ def exited(argv, code=0):
subprocess.run([EPIC_CLIENT, "exited", "--code", str(code)], stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, timeout=10)
except (OSError, subprocess.TimeoutExpired):
pass
if found is not None and launch_dir and str(found[1].get("store")) == "ea":
ask(Path(launch_dir) / "stores", {"op": "ea-exited", "store": "ea", "id": str(found[1].get("id"))}, timeout=1.0)
log("ea %s exited" % found[1].get("id"))
return 0
if found is None or not launch_dir or not cloud_on(found[1]):
return 0
store, game = str(found[1].get("store")), str(found[1].get("id"))
@@ -613,6 +618,344 @@ def apply_gog_registry(folder, compat_data, proton, timeout=90, installation=Non
return "import-failed" + note
EA_HARDWARE = ".droiddeck-ea-hw.json"
EA_CLIENT = "C:\\Program Files (x86)\\Origin\\Origin.exe"
EA_WMI = (
("boardManufacturer", "Win32_BaseBoard", "Manufacturer"),
("boardSerial", "Win32_BaseBoard", "SerialNumber"),
("biosManufacturer", "Win32_BIOS", "Manufacturer"),
("biosSerial", "Win32_BIOS", "SerialNumber"),
("osInstallDate", "Win32_OperatingSystem", "InstallDate"),
("osSerial", "Win32_OperatingSystem", "SerialNumber"),
("gpuPnpId", "Win32_VideoController", "PNPDeviceID"),
("cpuManufacturer", "Win32_Processor", "Manufacturer"),
("processorId", "Win32_Processor", "ProcessorId"),
("brand", "Win32_Processor", "Name"),
)
EA_ROOTS = {"HKLM": "HKEY_LOCAL_MACHINE", "HKCU": "HKEY_CURRENT_USER"}
def decode_output(data):
if data[:2] in (b"\xff\xfe", b"\xfe\xff") or (len(data) > 1 and data[1:2] == b"\x00"):
return data.decode("utf-16", "replace")
return data.decode("utf-8", "replace")
def wmi_value(text):
rows = [row.strip() for row in text.replace("\r", "\n").split("\n") if row.strip()]
return rows[1] if len(rows) > 1 else ""
CPUID_LEAVES = (0, 1, 0x80000002, 0x80000003, 0x80000004)
def cpuid_exe():
"""A 32-bit console program that writes the raw CPUID leaves an x86 game sees under the emulator."""
import struct
base, rva = 0x400000, 0x1000
buf, written = base + rva + 0x180, base + rva + 0x1D0
iat = base + rva + 0x138
code = b"\x53\x57\xbf" + struct.pack("<I", buf)
for leaf in CPUID_LEAVES:
code += b"\xb8" + struct.pack("<I", leaf) + b"\x31\xc9\x0f\xa2\x89\x07\x89\x5f\x04\x89\x4f\x08\x89\x57\x0c\x83\xc7\x10"
code += b"\x6a\xf5\xff\x15" + struct.pack("<I", iat)
code += b"\x6a\x00\x68" + struct.pack("<I", written) + b"\x6a\x50\x68" + struct.pack("<I", buf) + b"\x50\xff\x15" + struct.pack("<I", iat + 4)
code += b"\x6a\x00\xff\x15" + struct.pack("<I", iat + 8)
section = bytearray(0x200)
section[:len(code)] = code
names = [(0x148, b"GetStdHandle"), (0x158, b"WriteFile"), (0x164, b"ExitProcess")]
struct.pack_into("<IIIII", section, 0x100, rva + 0x128, 0, 0, rva + 0x172, rva + 0x138)
for i, (at, name) in enumerate(names):
struct.pack_into("<I", section, 0x128 + 4 * i, rva + at)
struct.pack_into("<I", section, 0x138 + 4 * i, rva + at)
section[at + 2:at + 2 + len(name)] = name
section[0x172:0x172 + 12] = b"KERNEL32.dll"
header = bytearray(0x200)
header[0:2] = b"MZ"
struct.pack_into("<I", header, 0x3C, 0x40)
header[0x40:0x44] = b"PE\0\0"
struct.pack_into("<HHIIIHH", header, 0x44, 0x14C, 1, 0, 0, 0, 0xE0, 0x0103)
opt = struct.pack("<HBBIIIIIIIIIHHHHHHIIIIHHIIIIII", 0x10B, 0, 0, 0x200, 0, 0, rva, rva, rva, base, 0x1000, 0x200,
4, 0, 0, 0, 4, 0, 0, 0x2000, 0x200, 0, 3, 0, 0x100000, 0x1000, 0x100000, 0x1000, 0, 16)
dirs = bytearray(128)
struct.pack_into("<II", dirs, 8, rva + 0x100, 40)
struct.pack_into("<II", dirs, 96, rva + 0x138, 16)
header[0x58:0x58 + 0xE0] = opt + bytes(dirs)
header[0x138:0x138 + 40] = struct.pack("<8sIIIIIIHHI", b".text", 0x1000, rva, 0x200, 0x200, 0, 0, 0, 0, 0xE0000060)
return bytes(header) + bytes(section)
EA_STUB_DIR = "Program Files (x86)/Origin"
EA_STUB = "C:\\Program Files (x86)\\Origin\\Origin.exe"
def origin_stub_exe():
"""A 32-bit program that only sleeps: the process older EA SDKs look for while a game runs."""
import struct
base, rva = 0x400000, 0x1000
iat = base + rva + 0x138
code = b"\x6a\xff\xff\x15" + struct.pack("<I", iat) + b"\xeb\xf6"
section = bytearray(0x200)
section[:len(code)] = code
struct.pack_into("<IIIII", section, 0x100, rva + 0x128, 0, 0, rva + 0x172, rva + 0x138)
struct.pack_into("<I", section, 0x128, rva + 0x148)
struct.pack_into("<I", section, 0x138, rva + 0x148)
section[0x14A:0x14A + 5] = b"Sleep"
section[0x172:0x172 + 12] = b"KERNEL32.dll"
header = bytearray(cpuid_exe()[:0x200])
struct.pack_into("<H", header, 0x58 + 68, 2)
return bytes(header) + bytes(section)
def install_origin_stub(compat_data):
if not compat_data:
return "no-prefix"
target = Path(compat_data) / "pfx/drive_c" / EA_STUB_DIR / "Origin.exe"
data = origin_stub_exe()
try:
if target.is_file() and target.read_bytes() == data:
return "ready"
target.parent.mkdir(parents=True, exist_ok=True)
target.write_bytes(data)
return "written"
except OSError:
return "failed"
def cpuid_values(raw):
import struct
if len(raw) < 80:
return {}
regs = [struct.unpack_from("<IIII", raw, 16 * i) for i in range(5)]
vendor = struct.pack("<III", regs[0][1], regs[0][3], regs[0][2]).split(b"\0")[0].decode("latin-1")
brand = b"".join(struct.pack("<IIII", *r) for r in regs[2:]).split(b"\0")[0].decode("latin-1")
return {"cpuVendor": vendor, "cpuEax": "%08X" % regs[1][0], "cpuEdx": "%08X" % regs[1][3],
"cpuEcx": "%08x" % regs[1][2], "cpuBrand": brand}
EA_PROBE_FIELDS = ("boardManufacturer", "biosManufacturer", "osInstallDate", "osSerial", "volumeSerial", "hostname",
"cpuVendor", "cpuEax", "cpuEdx", "cpuEcx")
def probe_complete(values):
return all(str(values.get(key) or "").strip() for key in EA_PROBE_FIELDS)
def ea_hardware(compat_data, proton, timeout=240):
pfx = Path(compat_data) / "pfx"
cache = pfx / EA_HARDWARE
try:
cached = json.loads(cache.read_text())
if isinstance(cached, dict) and probe_complete(cached):
return cached, "cached"
except (OSError, ValueError):
pass
if not proton or not Path(proton).is_file():
return {}, "no-proton"
values = {}
with tempfile.TemporaryDirectory(prefix="droiddeck-ea-") as tmp:
folder = Path(tmp)
lines = ["@echo off"]
for key, cls, prop in EA_WMI:
lines.append('wmic path %s get %s > "%s"' % (cls, prop, windows_path(str(folder / (key + ".txt")))))
lines.append('vol C: > "%s"' % windows_path(str(folder / "volume.txt")))
lines.append('hostname > "%s"' % windows_path(str(folder / "hostname.txt")))
(folder / "cpuid.exe").write_bytes(cpuid_exe())
lines.append('"%s" > "%s"' % (windows_path(str(folder / "cpuid.exe")), windows_path(str(folder / "cpuid.bin"))))
bat = folder / "probe.bat"
bat.write_bytes(("\r\n".join(lines) + "\r\n").encode())
try:
subprocess.run([proton, "run", "cmd.exe", "/d", "/c", windows_path(str(bat))], stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=timeout)
except subprocess.TimeoutExpired:
return {}, "timeout"
except OSError:
return {}, "failed"
for key, _, _ in EA_WMI:
try:
values[key] = wmi_value(decode_output((folder / (key + ".txt")).read_bytes()))
except OSError:
values[key] = ""
try:
found = re.search(r"([0-9A-Fa-f]{4})-([0-9A-Fa-f]{4})", decode_output((folder / "volume.txt").read_bytes()))
values["volumeSerial"] = (found.group(1) + found.group(2)).lower() if found else ""
except OSError:
values["volumeSerial"] = ""
try:
values["hostname"] = decode_output((folder / "hostname.txt").read_bytes()).strip().splitlines()[0].strip()
except (OSError, IndexError):
values["hostname"] = ""
try:
values.update(cpuid_values((folder / "cpuid.bin").read_bytes()))
except OSError:
pass
if probe_complete(values):
try:
cache.write_text(json.dumps(values))
except OSError:
pass
return values, "probed"
return values, "incomplete"
def ea_registry_entries(folder, sidecar):
install = windows_path(str(folder)).rstrip("\\") + "\\"
extra = sidecar.get("extra") if isinstance(sidecar.get("extra"), dict) else {}
title = str(extra.get("displayName") or sidecar.get("title") or folder.name).strip()
locale = str(extra.get("locale") or "en_US")
entries = [
("HKEY_LOCAL_MACHINE\\SOFTWARE\\Electronic Arts\\EA Desktop", "InstallSuccessful", "true"),
("HKEY_LOCAL_MACHINE\\SOFTWARE\\Electronic Arts\\Origin", "InstallSuccessful", "true"),
("HKEY_LOCAL_MACHINE\\SOFTWARE\\Electronic Arts\\Origin", "ClientPath", EA_CLIENT),
("HKEY_LOCAL_MACHINE\\SOFTWARE\\Origin", "ClientPath", EA_CLIENT),
]
for content in [c.strip() for c in str(extra.get("contentIds") or extra.get("contentId") or "").split(",")]:
if re.fullmatch(r"[A-Za-z0-9._-]{1,64}", content):
key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Origin Games\\" + content
entries += [(key, "DisplayName", title), (key, "Install Dir", install), (key, "Locale", locale)]
try:
keys = json.loads(extra.get("registry") or "[]")
except ValueError:
keys = []
for pair in keys if isinstance(keys, list) else []:
if not isinstance(pair, list) or len(pair) != 2:
continue
key, name = str(pair[0]), str(pair[1])
root, _, rest = key.partition("\\")
key = EA_ROOTS.get(root.upper(), root) + ("\\" + rest if rest else "")
if key.upper().startswith(("HKEY_LOCAL_MACHINE\\", "HKEY_CURRENT_USER\\")) and name and "\n" not in key + name:
entries.append((key, name, install))
if title:
entries.append((key, "DisplayName", title))
entries.append((key, "Locale", locale))
return entries
def ea_registry(folder, sidecar, compat_data, proton, timeout=90):
if not compat_data or not proton or not Path(proton).is_file():
return "no-proton"
pfx = Path(compat_data) / "pfx"
text = "Windows Registry Editor Version 5.00\r\n\r\n" + "".join(
'[%s]\r\n"%s"="%s"\r\n\r\n' % (key, reg_escape(name), reg_escape(value)) for key, name, value in ea_registry_entries(folder, sidecar))
stamp = hashlib.sha256(text.encode("utf-8")).hexdigest()
marker = pfx / (".droiddeck-ea-registry-" + re.sub(r"[^A-Za-z0-9._-]", "_", str(sidecar.get("id"))))
try:
if marker.is_file() and marker.read_text() == stamp and (pfx / "system.reg").is_file():
return "ready"
with tempfile.TemporaryDirectory(prefix="droiddeck-ea-") as tmp:
source = Path(tmp) / "registry.reg"
source.write_bytes(b"\xff\xfe" + text.encode("utf-16-le"))
executable = pfx / "drive_c/windows/system32/reg.exe"
for view in ("/reg:32", "/reg:64"):
run = subprocess.run([proton, "run", str(executable) if executable.is_file() else "reg.exe", "import", windows_path(str(source)), view],
stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=timeout)
if run.returncode:
return "import-failed"
marker.write_text(stamp)
return "written"
except subprocess.TimeoutExpired:
return "timeout"
except OSError:
return "import-failed"
def find_case(folder, relative):
current = Path(folder)
for part in [p for p in relative.replace("\\", "/").split("/") if p and p != "."]:
exact = current / part
if exact.exists():
current = exact
continue
try:
current = next(c for c in current.iterdir() if c.name.lower() == part.lower())
except (OSError, StopIteration):
return None
return current if current != Path(folder) else None
def touchup_args(raw, locale, install):
raw = raw.replace("{locale}", locale)
raw = raw.replace('"{installLocation}"', '"%s"' % install).replace("{installLocation}", install)
try:
return shlex.split(raw.replace("\\", "\\\\"))
except ValueError:
return raw.split()
def ea_touchup(folder, sidecar, compat_data, proton, timeout=900):
extra = sidecar.get("extra") if isinstance(sidecar.get("extra"), dict) else {}
relative = str(extra.get("touchup") or "")
if not relative:
return "none"
exe = find_case(folder, relative)
if exe is None or not exe.is_file():
return "missing"
if not compat_data or not proton or not Path(proton).is_file():
return "no-proton"
pfx = Path(compat_data) / "pfx"
stamp = str(sidecar.get("installVersion") or "") + " " + str(sidecar.get("installedAt") or "")
marker = pfx / (".droiddeck-ea-touchup-" + re.sub(r"[^A-Za-z0-9._-]", "_", str(sidecar.get("id"))))
try:
if marker.is_file() and marker.read_text() == stamp:
return "done"
except OSError:
pass
args = touchup_args(str(extra.get("touchupArgs") or ""), str(extra.get("locale") or "en_US"), windows_path(str(folder)).rstrip("\\"))
try:
run = subprocess.run([proton, "run", str(exe)] + args, cwd=str(exe.parent), stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=timeout)
result = "ok" if run.returncode == 0 else "exit-%d" % run.returncode
except subprocess.TimeoutExpired:
result = "timeout"
except OSError:
return "failed"
try:
marker.write_text(stamp)
except OSError:
pass
return result
def write_licenses(compat_data, licenses):
if not compat_data:
return 0
root = Path(compat_data) / "pfx/drive_c"
written = 0
for item in licenses or []:
relative = str(item.get("path") or "") if isinstance(item, dict) else ""
if not relative or relative.startswith("/") or ".." in relative.split("/"):
continue
target = root / relative
try:
target.parent.mkdir(parents=True, exist_ok=True)
target.write_bytes(base64.b64decode(item.get("data") or ""))
written += 1
except (OSError, binascii.Error):
pass
return written
def prepare_ea(folder, sidecar, compat_data, launch_dir):
game = str(sidecar.get("id"))
proton = os.environ.get("BL_STORE_PROTON", "")
made = create_prefix(compat_data, proton)
ready = made in ("present", "created") or (compat_data and (Path(compat_data) / "pfx/user.reg").is_file())
stub = install_origin_stub(compat_data) if ready else "no-prefix"
hardware, probe = ea_hardware(compat_data, proton) if ready else ({}, "no-prefix")
answer = None
if launch_dir:
answer = ask(Path(launch_dir) / "stores", {"op": "ea-prepare", "store": "ea", "id": game, "hardware": hardware}, timeout=40.0)
sidecar = sidecar_at(Path(folder)) or sidecar
log("ea %s prefix=%s stub=%s hardware=%s registry=%s touchup=%s" % (
game, made, stub, probe, ea_registry(folder, sidecar, compat_data, proton), ea_touchup(folder, sidecar, compat_data, proton)))
if answer is None:
log("ea %s session=no reason=%s" % (game, "timeout" if launch_dir else "no-channel"))
return
written = write_licenses(compat_data, answer.get("licenses"))
log("ea %s session=%s reason=%s lsx=%s licence=%s files=%d" % (
game, "yes" if answer.get("ok") else "no", answer.get("reason", ""), answer.get("lsx"), answer.get("license", ""), written))
def gog_support_actions(folder):
found = []
for script in sorted(Path(folder).glob(GOG_SCRIPTS)):
@@ -808,6 +1151,9 @@ def main(argv):
got = bool(answer.get("code"))
log("epic launch id=%s code=%s reason=%s" % (game, "yes" if got else "no", answer.get("reason", "")))
log("epic prefix=%s %s" % (prefix_id or "?", provision_prefix(compat_data)))
if store == "ea":
prepare_ea(folder, sidecar, compat_data, launch_dir)
return STORE_GAME
if not cloud_on(sidecar):
if store in CLOUD_STORES:
log("cloud %s %s down result=skipped reason=off" % (store, game))