feat(ubisoft): Ubisoft Connect store with native sign-in, library, downloads and launch (#2322)

* feat(ubisoft): sign in to Ubisoft Connect and list the owned library

* feat(ubisoft): download games natively through Demux and Ubisoft's CDN

* fix(ubisoft): show the owned games on the store page

* fix(ctl): reach the agent bridge by broadcast when the shell has no content command

* feat(ubisoft): run Ubisoft games in one prefix with Ubisoft Connect installed and the game registered

* feat(ubisoft): launch games through a native stand-in for Ubisoft Connect's local service

* feat(ubisoft): document the launcher pipes, log why owned games have no download, drop the installer after extraction

* feat(ubisoft): Steam-owned Ubisoft games install through Steam, and the launch session carries the game's application id

* feat(ubisoft): answer Denuvo activations through Ubisoft's activation service and log unanswered pipe traffic

* feat(ubisoft): report installed chunks to the game and skip add-ons the account does not own

* fix(ubisoft): the overlay stays off, Ubisoft's install steps pick Windows components, and shared-prefix games keep their own settings

* fix(ubisoft): write the manifest's registry values, and pick the game's exe over Ubisoft's installer stubs

* fix(ubisoft): stream download slices, guard the launch hook, and keep per-game components in the shared prefix

* fix(ubisoft): direct launches in the shared prefix keep their own game id

* ci(ubisoft): build the launcher service after the prepared components are verified

* fix(ubisoft): verify reused files, drop syncs from a signed-out account, and clear activation requests before launch

* fix(ubisoft): fetch again a reused file whose slices cannot be checked
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-10 15:08:37 -05:00
1 parent d8ed02f2cf
commit 3c96df4ab1
49 files changed
+3960 -24

No files matched your search

@@ -17,12 +17,12 @@ SEED_REDISTS = "/usr/local/bin/droiddeck-seed-redists"
PACK_KEYS = ("WINESERVER", "BL_SYNC_PACK", "WINEESYNC", "PROTON_NO_ESYNC", "PROTON_NO_FSYNC")
def game_id(env):
prefix = env.get("STEAM_COMPAT_DATA_PATH", "").rstrip("/")
if not prefix:
return None
value = prefix.rsplit("/", 1)[-1]
if not re.fullmatch(r"-?[0-9]+", value):
# Prefixes several games share; the game itself is the Steam app being launched.
SHARED_PREFIXES = {"2929927072"}
def app_number(value):
if not re.fullmatch(r"-?[0-9]+", value or ""):
return None
number = int(value)
if not -(2**31) <= number < 2**32 or number == 0:
@@ -30,6 +30,26 @@ def game_id(env):
return str(number % 2**32)
def game_id(env):
prefix = env.get("STEAM_COMPAT_DATA_PATH", "").rstrip("/")
if not prefix:
return None
found = app_number(prefix.rsplit("/", 1)[-1])
if found in SHARED_PREFIXES:
return app_number(env.get("SteamAppId", "")) or shortcut_number(env.get("SteamGameId", "")) or found
return found
def shortcut_number(value):
"""The shortcut appid inside Steam's 64-bit shortcut game id `(appid << 32) | 0x02000000`."""
if not re.fullmatch(r"[0-9]{1,20}", value or ""):
return None
number = int(value)
if number >= 2**64 or number & 0xFFFFFFFF != 0x02000000:
return None
return app_number(str(number >> 32))
DOTNET_FEX = {
"FEX_TSOENABLED": "1",
"FEX_VECTORTSOENABLED": "1",
@@ -289,6 +289,218 @@ def exited(argv, code=0):
return 0
UBISOFT_DIR = "drive_c/Program Files (x86)/Ubisoft/Ubisoft Game Launcher"
UBISOFT_WINDOWS_DIR = "C:\\Program Files (x86)\\Ubisoft\\Ubisoft Game Launcher\\"
UBISOFT_INSTALLER_URL = "https://static3.cdn.ubi.com/orbit/launcher_installer/UbisoftConnectInstaller.exe"
UBISOFT_CACHE = Path("/root/.cache/droiddeck/ubisoft")
UBISOFT_LAUNCH = ".droiddeck-ubisoft.json"
UBISOFT_SERVICE = Path("/usr/local/lib/droiddeck-ubisoft/droiddeck-upc.exe")
UBISOFT_ASK_WAIT = 45.0
UBISOFT_EXTRACT_WAIT = 300
# Ubisoft's own game-side runtime from the Connect installer, unmodified: the API and aux DLLs the
# game's loader opens from InstallDir, the starter it re-executes into and its imports, and the overlay
# DLLs uplay_r1.dll loads even with the overlay off (its startup fails without them).
UBISOFT_RUNTIME = ("uplay_r1.dll", "uplay_r164.dll", "uplay_aux_r1.dll", "uplay_aux_r164.dll",
"uplay_r2.dll", "uplay_r264.dll", "ubiorbitapi_r2.dll", "ubiorbitapi_r264.dll",
"UbisoftGameLauncher.exe", "UbisoftGameLauncher64.exe", "discord-rpc.x86.dll",
"discord-rpc.x64.dll", "steam_api.dll", "steam_api64.dll", "overlay.dll", "overlay64.dll")
UBISOFT_VIEWS = ("[Software\\\\Ubisoft\\\\Launcher%s]", "[Software\\\\Wow6432Node\\\\Ubisoft\\\\Launcher%s]")
MIN_INSTALLER = 1 << 20
def ubisoft_runtime_dir(compat_data):
return Path(compat_data) / "pfx" / UBISOFT_DIR
def ubisoft_runtime_ready(compat_data):
folder = ubisoft_runtime_dir(compat_data)
return all((folder / name).is_file() for name in UBISOFT_RUNTIME)
def fetch_installer(url=UBISOFT_INSTALLER_URL, folder=UBISOFT_CACHE):
target = folder / "UbisoftConnectInstaller.exe"
if target.is_file() and target.stat().st_size >= MIN_INSTALLER:
return target
import urllib.request
folder.mkdir(parents=True, exist_ok=True)
part = target.with_name(target.name + ".part")
request = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
with urllib.request.urlopen(request, timeout=60) as reply, open(part, "wb") as out:
shutil.copyfileobj(reply, out)
if part.stat().st_size < MIN_INSTALLER:
part.unlink()
raise OSError("installer too small")
os.replace(part, target)
return target
def install_runtime(compat_data, wait=UBISOFT_EXTRACT_WAIT):
if ubisoft_runtime_ready(compat_data):
return "present"
if not (Path(compat_data) / "pfx").is_dir():
return "no-prefix"
try:
installer = fetch_installer()
except OSError as error:
return "download-failed-" + type(error).__name__
target = ubisoft_runtime_dir(compat_data)
target.mkdir(parents=True, exist_ok=True)
with tempfile.TemporaryDirectory(prefix="droiddeck-ubisoft-", dir=str(UBISOFT_CACHE)) as tmp:
try:
subprocess.run(["7z", "e", "-y", "-o" + tmp, str(installer)] + list(UBISOFT_RUNTIME), stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=wait)
except subprocess.TimeoutExpired:
return "extract-timeout"
except OSError:
return "no-7z"
missing = [name for name in UBISOFT_RUNTIME if not (Path(tmp) / name).is_file()]
if missing:
return "extract-missing-" + ",".join(missing)
for name in UBISOFT_RUNTIME:
shutil.copyfile(Path(tmp) / name, target / name)
if not ubisoft_runtime_ready(compat_data):
return "copy-failed"
try:
installer.unlink()
except OSError:
pass
return "installed"
def ubisoft_product(sidecar):
extra = sidecar.get("extra") if isinstance(sidecar.get("extra"), dict) else {}
try:
return int(str(extra.get("productId") or ""))
except ValueError:
return None
def ubisoft_install_dir(folder):
return windows_path(str(folder)).replace("\\", "/").rstrip("/") + "/"
def register_ubisoft(folder, product, compat_data):
reg = Path(compat_data) / "pfx" / "system.reg"
if not reg.is_file():
return "no-registry"
if not wait_for_server(reg.parent):
return "server-running"
for view in UBISOFT_VIEWS:
set_value(reg, view % "", "InstallDir", UBISOFT_WINDOWS_DIR)
set_value(reg, view % ("\\\\Installs\\\\%d" % product), "InstallDir", ubisoft_install_dir(folder))
return "registered %d" % product
UBISOFT_HIVES = {"HKEY_LOCAL_MACHINE": "system.reg", "HKEY_CURRENT_USER": "user.reg"}
def manifest_value(values, folder, language):
"""The value Connect writes for a manifest registry entry: the install folder, the entry for the
language being played, or the only entry there is."""
entries = [v for v in values if isinstance(v, dict)]
if not entries:
return None
names = [str(v.get("name") or "") for v in entries]
if "$INSTALL_DIR" in names:
return windows_path(str(folder)).rstrip("\\") + "\\"
for v in entries:
if str(v.get("value") or "").lower() == language.lower():
return str(v.get("value"))
prefix = language.split("-")[0].lower()
for v in entries:
if str(v.get("value") or "").lower().split("-")[0] == prefix:
return str(v.get("value"))
return str(entries[0].get("value") or entries[0].get("name") or "")
def apply_manifest_registry(compat_data, registry, folder, language):
written = 0
for item in registry or []:
if not isinstance(item, dict):
continue
path = str(item.get("key") or "").replace("/", "\\")
hive, _, rest = path.partition("\\")
target = UBISOFT_HIVES.get(hive.upper())
if not target or "\\" not in rest:
continue
subkey, _, name = rest.rpartition("\\")
value = manifest_value(item.get("values"), folder, language)
if value is None or not name:
continue
reg = Path(compat_data) / "pfx" / target
parts = subkey.split("\\")
views = [parts]
if target == "system.reg" and len(parts) > 1 and parts[0].lower() == "software" and parts[1].lower() != "wow6432node":
views.append(parts[:1] + ["Wow6432Node"] + parts[1:])
for view in views:
key = "[" + "\\\\".join(view) + "]"
if set_value(reg, key, name, value):
written += 1
return written
def ubisoft_launch(folder, sidecar, product, compat_data, answer):
"""The launch file droiddeck-upc.exe reads: the game, the account and this launch's ticket."""
account = answer.get("account") if isinstance(answer.get("account"), dict) else {}
user = str(account.get("userId") or "user")
saves = Path(compat_data) / "pfx" / "drive_c/users/steamuser/Saved Games/Ubisoft" / user / str(product)
saves.mkdir(parents=True, exist_ok=True)
exe = str(sidecar.get("exe") or "").replace("\\", "/")
workdir = folder / str(sidecar.get("workdir")) if sidecar.get("workdir") else folder
UBISOFT_CACHE.mkdir(parents=True, exist_ok=True)
return {
"productId": product,
"exe": windows_path(str(folder / exe)),
"args": " ".join(str(a) for a in sidecar.get("args") or []),
"workdir": windows_path(str(workdir)),
"account": account,
"ticket": str(answer.get("ticket") or ""),
"owned": [int(i) for i in answer.get("owned") or [] if str(i).isdigit()],
"products": [p for p in answer.get("products") or [] if isinstance(p, dict) and isinstance(p.get("id"), int)],
"appId": str(answer.get("appId") or ""),
"chunks": [c for c in answer.get("chunks") or [] if isinstance(c, dict) and isinstance(c.get("id"), int)],
"saves": "C:/users/steamuser/Saved Games/Ubisoft/%s/%d/" % (user, product),
"language": str(answer.get("language") or "en-US"),
"bridge": windows_path(str(UBISOFT_CACHE / ("bridge-%d" % product))),
"log": windows_path(str(UBISOFT_CACHE / ("upc-%d.log" % product))),
}
def prepare_ubisoft(folder, sidecar, compat_data, launch_dir, proton="", ask_app=None):
launch = folder / UBISOFT_LAUNCH
try:
launch.unlink()
except OSError:
pass
if not compat_data:
return "no-prefix"
product = ubisoft_product(sidecar)
if product is None:
return "no-product"
if not UBISOFT_SERVICE.is_file():
return "no-service"
made = create_prefix(compat_data, proton) if not (Path(compat_data) / "pfx/user.reg").is_file() else "present"
if made not in ("present", "created"):
return "prefix " + made
runtime = install_runtime(compat_data)
if not ubisoft_runtime_ready(compat_data):
return "runtime " + runtime
registry = register_ubisoft(folder, product, compat_data)
if not launch_dir:
return "runtime %s, %s, no-channel" % (runtime, registry)
answer = (ask_app or ask)(Path(launch_dir) / "stores", {"op": "ubisoft-launch", "store": "ubisoft", "id": str(sidecar.get("id"))},
timeout=UBISOFT_ASK_WAIT)
if not isinstance(answer, dict) or not answer.get("ok") or not answer.get("ticket"):
reason = "timeout" if answer is None else str(answer.get("reason") or "refused")
return "runtime %s, %s, session %s" % (runtime, registry, reason)
written = 0
if answer.get("registry") and wait_for_server(Path(compat_data) / "pfx"):
written = apply_manifest_registry(compat_data, answer.get("registry"), folder, str(answer.get("language") or "en-US"))
tmp = launch.with_name(launch.name + ".tmp")
tmp.write_text(json.dumps(ubisoft_launch(folder, sidecar, product, compat_data, answer)))
os.replace(tmp, launch)
return "runtime %s, %s, %d manifest value(s), session ready" % (runtime, registry, written)
COMET_DIR = Path("/usr/local/lib/droiddeck-comet")
@@ -1114,6 +1326,15 @@ def main(argv):
prepare_gog(sidecar, compat_data, launch_dir)
log("gog registry: " + apply_gog_registry(folder, compat_data, os.environ.get("BL_STORE_PROTON", "")))
log("gog support data: " + gog_support_data(folder, compat_data, os.environ.get("BL_STORE_PROTON", "")))
if store == "ubisoft":
try:
log("ubisoft %s: %s" % (game, prepare_ubisoft(folder, sidecar, compat_data, launch_dir, os.environ.get("BL_STORE_PROTON", ""))))
except OSError as e:
try:
(folder / UBISOFT_LAUNCH).unlink()
except OSError:
pass
log("ubisoft %s: not prepared (%s), starting directly" % (game, e))
if store == "epic":
handled = os.environ.get(EPIC_HANDLED) == "1" and (folder / EPIC_ARGS).is_file()
if not handled:
@@ -152,6 +152,13 @@ bl_components() {
else
cm_app=""
fi
if [ "$cm_app" = 2929927072 ] && [[ "${SteamAppId:-}" =~ ^[0-9]{1,10}$ ]] && (( 10#$SteamAppId > 0 && 10#$SteamAppId <= 4294967295 )); then
cm_app=$((10#$SteamAppId))
elif [ "$cm_app" = 2929927072 ] && [[ "${SteamGameId:-}" =~ ^[1-9][0-9]{9,19}$ ]] &&
{ [ ${#SteamGameId} -lt 20 ] || [[ ! "$SteamGameId" > 18446744073709551615 ]]; } &&
(( (10#$SteamGameId & 0xFFFFFFFF) == 0x02000000 && ((10#$SteamGameId >> 32) & 0xFFFFFFFF) != 0 )); then
cm_app=$(( (10#$SteamGameId >> 32) & 0xFFFFFFFF ))
fi
if [ -z "$cm_app" ]; then
echo "droiddeck-proton: components: invalid game prefix, left as it is" >&2
return 0