From 97a0f1553f19f68571f0bc19c210644cb4d526e5 Mon Sep 17 00:00:00 2001 From: The412Banner Date: Thu, 8 Oct 2026 23:31:34 -0400 Subject: [PATCH] Stores: Epic games get the EOS overlay, and their web links open on Android Metalstorm's EOS sign-in asked for a one-time consent, could not load an overlay to show it, and fell back to a browser flow that never finished. Epic's own overlay component (the mechanism from Legendary's lfs/eos.py; credits in EpicOverlay.kt) is now downloaded once with the account's token into the runtime, after an Epic library sync or at the first launch that finds it missing. At each launch droiddeck-store-launch writes the one pointer, HKCU Software\Epic Games\EOS OverlayPath, into the game's prefix, appended to user.reg as the DirectAudio key is, and the app logs epic overlay installed= prefix=. Wine's browser is set to xdg-open, and on a game's PATH a small xdg-open hands http(s) addresses to the app, which opens them in Android's browser, so a device-code sign-in can be finished on the phone. --- .../launcher/session/SessionFiles.kt | 2 + .../launcher/stores/StoreLaunchRequests.kt | 22 ++++- .../launcher/stores/epic/EpicBackend.kt | 6 +- .../launcher/stores/epic/EpicOverlay.kt | 84 +++++++++++++++++++ docs/progress-log.md | 12 +++ .../usr/local/bin/droiddeck-store-launch | 73 +++++++++++++++- .../overlay/usr/local/bin/steam-compatibility | 4 + .../usr/local/lib/droiddeck/browser/xdg-open | 38 +++++++++ tools/tests/test_store_launch.py | 56 +++++++++++++ 9 files changed, 294 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/com/droiddeck/launcher/stores/epic/EpicOverlay.kt create mode 100755 tools/linuxfs/overlay/usr/local/lib/droiddeck/browser/xdg-open diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt index 80216a939a..4274ad23f8 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt @@ -62,6 +62,8 @@ object SessionFiles { "usr/local/bin/droiddeck-steam-shortcuts" to "usr/local/bin/droiddeck-steam-shortcuts", // Asks the app for an Epic game's sign-in code at launch, from the compat tool (StoreLaunchRequests). "usr/local/bin/droiddeck-store-launch" to "usr/local/bin/droiddeck-store-launch", + // A game's web links to Android's browser (winebrowser -> xdg-open), on game PATHs only. + "usr/local/lib/droiddeck/browser/xdg-open" to "usr/local/lib/droiddeck/browser/xdg-open", "usr/local/bin/droiddeck-steam-games" to "usr/local/bin/droiddeck-steam-games", "usr/local/bin/droiddeck-pad-defaults" to "usr/local/bin/droiddeck-pad-defaults", // Flatpak: the bwrap stand-in, the store's helper and setup, and the front end's launcher. diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoreLaunchRequests.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoreLaunchRequests.kt index 6d2c881bc0..56ab6503e5 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoreLaunchRequests.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoreLaunchRequests.kt @@ -58,7 +58,27 @@ object StoreLaunchRequests { "epic-code" -> { val id = request.optString("id") if (id.isEmpty()) JSONObject().put("ok", false).put("reason", "no-id") - else StoreLaunch.epicCode(app, id).let { JSONObject().put("ok", true).put("code", it.written).put("reason", it.reason) } + else { + val code = StoreLaunch.epicCode(app, id) + // The overlay is placed once and shared; the launch writes the prefix's pointer. + val overlay = com.droiddeck.launcher.stores.epic.EpicOverlay.installedVersion(app) + Log.i(TAG, "epic overlay installed=${overlay ?: "no"} prefix=${request.optString("prefix").ifEmpty { "?" }}") + if (overlay == null) com.droiddeck.launcher.stores.epic.EpicOverlay.ensureAsync(app) + JSONObject().put("ok", true).put("code", code.written).put("reason", code.reason).put("overlay", overlay ?: "") + } + } + // A browser a game opens inside the session (an EOS device sign-in, a store page): + // http(s) only, handed to Android's browser. + "open-url" -> { + val url = request.optString("url") + if (!(url.startsWith("https://") || url.startsWith("http://"))) JSONObject().put("ok", false).put("reason", "not-http") + else try { + app.startActivity(android.content.Intent(android.content.Intent.ACTION_VIEW, android.net.Uri.parse(url)).addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK)) + Log.i(TAG, "open-url: " + StoreLog.redactUrl(url)) + JSONObject().put("ok", true) + } catch (e: Exception) { + JSONObject().put("ok", false).put("reason", e.javaClass.simpleName) + } } else -> JSONObject().put("ok", false).put("reason", "unknown-op") } diff --git a/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicBackend.kt b/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicBackend.kt index 3b953f4321..85823bef0f 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicBackend.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicBackend.kt @@ -49,7 +49,11 @@ object EpicBackend : StoreBackend, EpicLaunchSupport { StoresState.post { StoresState.status.remove(store) when (result) { - is EpicLibrary.SyncResult.Ok -> { StoresState.library[store] = result.games.map { EpicLibrary.toCatalogItem(app, it) }; StoresState.problems.remove(store) } + is EpicLibrary.SyncResult.Ok -> { + StoresState.library[store] = result.games.map { EpicLibrary.toCatalogItem(app, it) }; StoresState.problems.remove(store) + // The EOS overlay, once, so a game's first launch already has it. + EpicOverlay.ensureAsync(app) + } is EpicLibrary.SyncResult.Failed -> StoresState.problems[store] = result.message EpicLibrary.SyncResult.NotLoggedIn -> StoresState.problems[store] = "Epic session expired: sign in again." EpicLibrary.SyncResult.Throttled -> if (!StoresState.library.containsKey(store)) StoresState.library[store] = cached.map { EpicLibrary.toCatalogItem(app, it) } diff --git a/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicOverlay.kt b/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicOverlay.kt new file mode 100644 index 0000000000..986185f77a --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicOverlay.kt @@ -0,0 +1,84 @@ +/* + * Epic Online Services (EOS) overlay provisioning for DroidDeck. + * + * Credits: the provisioning MECHANISM - download Epic's own overlay component + * ("EpicOnlineServicesOverlay") and point a game's bundled EOS SDK at it through a single HKCU + * registry value - comes from Legendary's legendary/lfs/eos.py, by way of The GameNative Team's + * work (https://github.com/utkarshdalal/GameNative) and Bannerlator's EpicOverlayManager. The Epic + * app identifiers, the registry key and the EOSOVH-Win64-Shipping.dll name are public facts from + * Epic / Legendary. Original implementation. + * + * Reference: https://github.com/derrod/legendary - legendary/lfs/eos.py + * Reference: https://github.com/utkarshdalal/GameNative + * + * Provision only: Epic's signed component is placed once, shared by every prefix, and each Epic + * game's prefix gets the one pointer (written by droiddeck-store-launch before Proton starts, where + * the prefix is known). The game's EOS SDK loads it itself - which is what lets a "corrective + * action" (a consent Epic wants once per product) show in game instead of waiting on a browser. + */ +package com.droiddeck.launcher.stores.epic + +import android.content.Context +import android.util.Log +import com.droiddeck.launcher.runtime.LinuxRuntime +import com.droiddeck.launcher.stores.StoresState +import java.io.File +import java.util.concurrent.atomic.AtomicBoolean + +object EpicOverlay { + private const val TAG = "EpicOverlay" + + // Epic's "EpicOnlineServicesOverlay" app (public, from Legendary). + private const val OVERLAY_APP = "98bc04bc842e4906993fd6d6644ffb8d" + private const val OVERLAY_NAMESPACE = "302e5ede476149b1bc3e4fe6ae45e50e" + private const val OVERLAY_CATALOG_ITEM = "cc15684f44d849e89e9bf4cec0508b68" + const val OVERLAY_DLL = "EOSOVH-Win64-Shipping.dll" + + /** Inside the session: `/root/.local/share/droiddeck/epic-overlay`, which every prefix reaches as Z:. droiddeck-store-launch names the same path. */ + const val GUEST_DIR = "/root/.local/share/droiddeck/epic-overlay" + private const val VERSION_FILE = "droiddeck-version" + + private val busy = AtomicBoolean(false) + + fun dir(context: Context): File = File(LinuxRuntime.rootDir(context), GUEST_DIR.removePrefix("/")) + + /** The installed overlay's build, or null when it is not there. */ + fun installedVersion(context: Context): String? { + val d = dir(context) + if (!File(d, OVERLAY_DLL).let { it.isFile && it.length() > 0 }) return null + return runCatching { File(d, VERSION_FILE).readText().trim() }.getOrNull()?.ifEmpty { null } ?: "unknown" + } + + /** Starts the download in the background when the overlay is missing; nothing when it is there or under way. */ + fun ensureAsync(context: Context) { + val app = context.applicationContext + if (installedVersion(app) != null || !busy.compareAndSet(false, true)) return + Thread({ + try { ensure(app) } finally { busy.set(false) } + }, "epic-overlay").start() + } + + /** Blocking: downloads Epic's overlay component when it is missing. True when it is in place afterwards. */ + fun ensure(context: Context): Boolean { + val app = context.applicationContext + if (installedVersion(app) != null) return true + return try { + val token = EpicCredentialStore.getValidAccessToken(app) ?: return false.also { Log.i(TAG, "overlay: not signed in") } + val manifest = EpicApiClient.getManifestApiJson(token, OVERLAY_NAMESPACE, OVERLAY_CATALOG_ITEM, OVERLAY_APP) + ?: return false.also { Log.w(TAG, "overlay: manifest not fetched") } + val target = dir(app).apply { mkdirs() } + StoresState.logLine("epic: fetching the EOS overlay") + val result = EpicDownloadManager.install(app, manifest, target.path, "", null, AtomicBoolean(false), object : EpicDownloadManager.Callback { + override fun onProgress(message: String, pct: Int) {} + override fun onLog(line: String) { StoresState.logLine(line) } + }) + val ok = result != null && File(target, OVERLAY_DLL).isFile + if (ok) File(target, VERSION_FILE).writeText(result!!.buildVersion.ifEmpty { "unknown" }) + Log.i(TAG, "overlay: " + if (ok) "installed ${result!!.buildVersion}" else "install did not produce $OVERLAY_DLL") + ok + } catch (e: Exception) { + Log.w(TAG, "overlay: ${e.javaClass.simpleName}: ${e.message}") + false + } + } +} diff --git a/docs/progress-log.md b/docs/progress-log.md index 9f78678bde..cd48bdb877 100644 --- a/docs/progress-log.md +++ b/docs/progress-log.md @@ -144,6 +144,18 @@ without it and Setup says "Stores engine not built"). (`token`, `__token__`, `f_token`, `hdnts`, access/refresh/id tokens, `code=`) and Authorization / Cookie headers are blanked outside URLs too. `StoreLogTest` covers a GOG secure link and an Epic Akamai URL. The engine's own logcat lines (tag `EpicNative` etc.) are written on the native side. +- **EOS overlay** (device: Metalstorm's EOS grant answered `corrective_action_required`, the overlay + was not configured, and EOS fell back to a browser flow that never finished). Epic's own overlay + component ("EpicOnlineServicesOverlay", the mechanism from Legendary's `lfs/eos.py`, credits in + `EpicOverlay.kt`) is downloaded once, with the Epic account's token, to + `/root/.local/share/droiddeck/epic-overlay` in the runtime - after an Epic library sync, or at the + first launch that finds it missing. `droiddeck-store-launch` then writes the one pointer, + `HKCU\Software\Epic Games\EOS` `OverlayPath` = that folder through Z:, into the game's prefix + (`STEAM_COMPAT_DATA_PATH/pfx/user.reg`, appended as DirectAudio's key is; a prefix Proton has not + created yet gets it on the next launch). Logged as `epic overlay installed= prefix=`. + A game's web links now open on Android: Wine's browser is set to xdg-open, and on a game's PATH + `/usr/local/lib/droiddeck/browser/xdg-open` hands http(s) addresses to the app, which opens them + with Android's browser - so a device-code sign-in can be finished on the phone. - **Epic sign-in from Steam's own Play button (device, Metalstorm "Guest Account"):** the game was started from the Steam client, so the app never minted its exchange code - the code was only written when a launch began in the app. Now the compat tool (`droiddeck-proton` and diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-store-launch b/tools/linuxfs/overlay/usr/local/bin/droiddeck-store-launch index 527b77ac92..7cb487f760 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-store-launch +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-store-launch @@ -18,6 +18,12 @@ here - and the launcher .bat reads and deletes it. No answer within TIMEOUT seco with its offline identity. A code file older than STALE_SECONDS is removed first, so a code left by an earlier launch is never used. +The game's prefix also gets the EOS overlay's pointer, HKCU\Software\Epic Games\EOS "OverlayPath" +(the mechanism from Legendary's lfs/eos.py), naming the one copy the app keeps at OVERLAY_DIR; with +it the game's EOS SDK can show Epic's own sign-in steps in game (a consent Epic asks for once per +product) instead of waiting on a browser. Wine's browser is pointed at xdg-open, which this +runtime's /usr/local/lib/droiddeck/browser/xdg-open hands to Android. + droiddeck-store-launch """ @@ -32,6 +38,10 @@ SIDECAR = ".droiddeck-store.json" EPIC_CODE = ".droiddeck-epic-code" TIMEOUT = 5.0 STALE_SECONDS = 300 +OVERLAY_DIR = "/root/.local/share/droiddeck/epic-overlay" +OVERLAY_DLL = "EOSOVH-Win64-Shipping.dll" +EOS_KEY = "[Software\\\\Epic Games\\\\EOS]" +BROWSER_KEY = "[Software\\\\Wine\\\\WineBrowser]" def log(line): @@ -93,6 +103,63 @@ def ask(channel, request, timeout=TIMEOUT): return None +def windows_path(unix): + """A guest path as Wine names it through Z: (the whole filesystem).""" + return "Z:" + unix.replace("/", "\\") + + +def reg_escape(value): + return value.replace("\\", "\\\\").replace('"', '\\"') + + +def set_value(reg, key, name, value, now=None): + """ + Appends `key` with `"name"="value"` to a prefix's user.reg unless the last word on it already + says so. Appended rather than edited in place, as DirectAudio's key is: Wine reads later sections + over earlier ones, and nothing of the file is rewritten under a wineserver that might hold it. + False when there is no user.reg yet (Proton creates the prefix after this; the next launch has it). + """ + if not reg.is_file(): + return False + line = '"%s"="%s"' % (name, reg_escape(value)) + inside, last = False, None + for row in reg.read_text(errors="replace").splitlines(): + if row.startswith("["): + inside = row.startswith(key + " ") or row == key + elif inside and row.startswith('"%s"=' % name): + last = row + if last == line: + return True + with open(reg, "a") as out: + out.write("\n%s %d\n%s\n" % (key, int(now if now is not None else time.time()), line)) + return True + + +def overlay_version(overlay_dir=OVERLAY_DIR): + """The overlay build the app placed, or None when it is not there.""" + d = Path(overlay_dir) + if not (d / OVERLAY_DLL).is_file(): + return None + try: + return (d / "droiddeck-version").read_text().strip() or "unknown" + except OSError: + return "unknown" + + +def provision_prefix(compat_data, overlay_dir=OVERLAY_DIR): + """The EOS overlay pointer and Wine's browser, in the game's prefix. Returns what was done.""" + if not compat_data: + return "no-prefix" + reg = Path(compat_data) / "pfx" / "user.reg" + if not reg.is_file(): + return "prefix-not-created" + set_value(reg, BROWSER_KEY, "Browsers", "xdg-open") + if overlay_version(overlay_dir) is None: + return "overlay-missing" + set_value(reg, EOS_KEY, "OverlayPath", windows_path(overlay_dir)) + return "overlay-set" + + def main(argv): found = find_store_game(argv) if found is None: @@ -106,12 +173,16 @@ def main(argv): if not launch_dir: log("epic launch id=%s code=no reason=no-channel" % game) return 0 - answer = ask(Path(launch_dir) / "stores", {"op": "epic-code", "store": store, "id": game}) + compat_data = os.environ.get("STEAM_COMPAT_DATA_PATH", "").rstrip("/") + prefix_id = os.path.basename(compat_data) if compat_data else "" + answer = ask(Path(launch_dir) / "stores", {"op": "epic-code", "store": store, "id": game, "prefix": prefix_id}) if answer is None: log("epic launch id=%s code=no reason=timeout" % game) else: got = bool(answer.get("code")) log("epic launch id=%s code=%s reason=%s" % (game, "yes" if got else "no", answer.get("reason", ""))) + done = provision_prefix(compat_data) + log("epic overlay installed=%s prefix=%s %s" % (overlay_version() or "no", prefix_id or "?", done)) return 0 diff --git a/tools/linuxfs/overlay/usr/local/bin/steam-compatibility b/tools/linuxfs/overlay/usr/local/bin/steam-compatibility index 96bcce6495..a2a9b542f2 100755 --- a/tools/linuxfs/overlay/usr/local/bin/steam-compatibility +++ b/tools/linuxfs/overlay/usr/local/bin/steam-compatibility @@ -103,6 +103,10 @@ TOOL_MANIFEST_VDF = """"manifest" BL_STORE_SETUP = """ bl_store_launch() { [ "${verb:-}" = waitforexitandrun ] || return 0 + # A web address the game opens (Wine's winebrowser runs xdg-open) goes to Android's browser. + if [ -x /usr/local/lib/droiddeck/browser/xdg-open ]; then + PATH="/usr/local/lib/droiddeck/browser:$PATH"; export PATH + fi [ -x /usr/local/bin/droiddeck-store-launch ] || return 0 /usr/local/bin/droiddeck-store-launch "$@" || true } diff --git a/tools/linuxfs/overlay/usr/local/lib/droiddeck/browser/xdg-open b/tools/linuxfs/overlay/usr/local/lib/droiddeck/browser/xdg-open new file mode 100755 index 0000000000..38cd300742 --- /dev/null +++ b/tools/linuxfs/overlay/usr/local/lib/droiddeck/browser/xdg-open @@ -0,0 +1,38 @@ +#!/usr/bin/python3 +"""xdg-open for games: a web address a game opens (Wine's winebrowser runs xdg-open) goes to +Android's browser through the app, so an EOS device sign-in or a store page can be finished on +the phone. On a game's PATH only (droiddeck-proton puts this directory first); anything that is not +http(s), or with no session channel, goes on to the system's own xdg-open.""" + +import json +import os +import sys +import time +from pathlib import Path + + +def hand_over(url, launch_dir): + req = Path(launch_dir) / "stores" / "req" + req.mkdir(parents=True, exist_ok=True) + rid = "url-%d-%d" % (os.getpid(), int(time.time() * 1000)) + tmp = req / (rid + ".json.tmp") + tmp.write_text(json.dumps({"op": "open-url", "url": url})) + os.rename(tmp, req / (rid + ".json")) + + +def main(argv): + url = argv[0] if argv else "" + launch_dir = os.environ.get("BL_LAUNCH_DIR", "") + if url.startswith(("https://", "http://")) and launch_dir: + hand_over(url, launch_dir) + return 0 + here = os.path.dirname(os.path.abspath(__file__)) + for d in os.environ.get("PATH", "").split(os.pathsep): + candidate = os.path.join(d, "xdg-open") + if os.path.abspath(d) != here and os.access(candidate, os.X_OK): + os.execv(candidate, [candidate] + argv) + return 1 + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:])) diff --git a/tools/tests/test_store_launch.py b/tools/tests/test_store_launch.py index cad02ac755..635e3b7331 100644 --- a/tools/tests/test_store_launch.py +++ b/tools/tests/test_store_launch.py @@ -23,6 +23,14 @@ def load(name): store = load('droiddeck-store-launch') + + +def load_path(path, name): + loader = importlib.machinery.SourceFileLoader(name, str(path)) + spec = importlib.util.spec_from_loader(name, loader) + module = importlib.util.module_from_spec(spec) + loader.exec_module(module) + return module compat = load('steam-compatibility') @@ -103,6 +111,54 @@ class Asking(unittest.TestCase): self.assertFalse(code.exists()) +class Prefix(unittest.TestCase): + def setUp(self): + self.tmp = tempfile.TemporaryDirectory() + root = Path(self.tmp.name) + self.compat = root / 'compatdata/3785150007' + (self.compat / 'pfx').mkdir(parents=True) + self.reg = self.compat / 'pfx/user.reg' + self.reg.write_text('WINE REGISTRY Version 2\n\n[Software\\\\Wine] 1\n"Version"="win10"\n') + self.overlay = root / 'epic-overlay' + self.overlay.mkdir() + + def tearDown(self): + self.tmp.cleanup() + + def test_the_overlay_pointer_names_the_shared_copy_through_z(self): + (self.overlay / store.OVERLAY_DLL).write_bytes(b'MZ') + (self.overlay / 'droiddeck-version').write_text('1.0.42') + self.assertEqual('overlay-set', store.provision_prefix(str(self.compat), str(self.overlay))) + text = self.reg.read_text() + self.assertIn('[Software\\\\Epic Games\\\\EOS] ', text) + self.assertIn('"OverlayPath"="Z:' + str(self.overlay).replace('/', '\\\\') + '"', text) + self.assertIn('"Browsers"="xdg-open"', text) + # A second launch adds nothing: the last word already says so. + store.provision_prefix(str(self.compat), str(self.overlay)) + self.assertEqual(text, self.reg.read_text()) + self.assertEqual('1.0.42', store.overlay_version(str(self.overlay))) + + def test_no_overlay_yet_or_no_prefix_yet(self): + self.assertEqual('overlay-missing', store.provision_prefix(str(self.compat), str(self.overlay))) + self.assertNotIn('OverlayPath', self.reg.read_text()) + self.assertEqual('prefix-not-created', store.provision_prefix(self.tmp.name + '/compatdata/1', str(self.overlay))) + self.assertEqual('no-prefix', store.provision_prefix('', str(self.overlay))) + + +class Browser(unittest.TestCase): + def test_a_web_address_is_handed_to_the_app(self): + xdg = load_path(BIN.parent / 'lib/droiddeck/browser/xdg-open', 'xdg_open') + with tempfile.TemporaryDirectory() as root: + os.environ['BL_LAUNCH_DIR'] = root + try: + self.assertEqual(0, xdg.main(['https://www.epicgames.com/activate'])) + finally: + del os.environ['BL_LAUNCH_DIR'] + reqs = list((Path(root) / 'stores/req').glob('*.json')) + self.assertEqual(1, len(reqs)) + self.assertEqual({'op': 'open-url', 'url': 'https://www.epicgames.com/activate'}, json.loads(reqs[0].read_text())) + + class Launchers(unittest.TestCase): def test_both_proton_launchers_ask_before_proton_starts(self): sh = compat.LAUNCHER_SH