Stores: an Epic game signs in however it is launched

Metalstorm started from the Steam client's own Play button came up as a
guest: the exchange code was only minted when a launch began in the app.
The compat tool now runs droiddeck-store-launch on every real launch. It
finds the store launcher among Steam's arguments and, for an Epic game,
asks the app through the session's stores/req and stores/resp folders,
waiting up to five seconds. The app refreshes the token, mints the code
and writes it into the game's own folder; the code never crosses the
channel or the log. No answer and the game starts with its offline
identity; a code file older than five minutes is dropped first.

Every attempt logs epic launch id=... code=yes|no reason=...; a sign-in
that ran out dims the Epic chip and brings back the sign-in card.
This commit is contained in:
The412Banner committed 2026-10-08 23:18:20 -04:00
1 parent 64d5f92391
commit 78e4cb8369
13 files changed
+406 -18

No files matched your search

+123
View File
@@ -0,0 +1,123 @@
#!/usr/bin/python3
"""Before Proton starts a store game, asks the app for what that store needs at launch.
Run by droiddeck-proton / droiddeck-proton-wrap (steam-compatibility) for every real game launch,
whoever started it: the Games tab, a pinned shortcut, or the Steam client's own Play button. It
looks for the store launcher DroidDeck wrote (.droiddeck-launch.bat) among the arguments; beside it
.droiddeck-store.json says which store and game it is.
For an Epic game the game needs a fresh exchange code to sign in, which only the app can mint. The
request goes through files under $BL_LAUNCH_DIR/stores (the session root, the same path on both
sides):
req/<id>.json {"op": "epic-code", "store": "epic", "id": "<app name>"} (tmp + rename)
resp/<id>.json {"ok": true, "code": true|false, "reason": "..."}
The app writes .droiddeck-epic-code into the game's folder itself - the code never passes through
here - and the launcher .bat reads and deletes it. No answer within TIMEOUT seconds: the game starts
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.
droiddeck-store-launch <the arguments Steam gave the compat tool>
"""
import json
import os
import sys
import time
from pathlib import Path
LAUNCHER = ".droiddeck-launch.bat"
SIDECAR = ".droiddeck-store.json"
EPIC_CODE = ".droiddeck-epic-code"
TIMEOUT = 5.0
STALE_SECONDS = 300
def log(line):
print("droiddeck-store-launch: " + line, file=sys.stderr, flush=True)
def find_store_game(argv):
"""The (folder, sidecar) of the store launcher among [argv], or None when this is not one."""
for raw in argv:
arg = raw.strip().strip('"').strip("'")
if not arg.lower().endswith(LAUNCHER):
continue
folder = Path(arg.replace("\\", "/")).parent
try:
sidecar = json.loads((folder / SIDECAR).read_text())
except (OSError, ValueError):
continue
if not isinstance(sidecar, dict) or not sidecar.get("store") or not sidecar.get("id"):
continue
return folder, sidecar
return None
def drop_stale(folder, now=None):
"""Removes a code file older than STALE_SECONDS; True when one was removed."""
code = folder / EPIC_CODE
try:
if (now if now is not None else time.time()) - code.stat().st_mtime > STALE_SECONDS:
code.unlink()
return True
except OSError:
pass
return False
def ask(channel, request, timeout=TIMEOUT):
"""Writes [request] under channel/req and waits for channel/resp; the answer, or None on timeout."""
req_dir, resp_dir = channel / "req", channel / "resp"
req_dir.mkdir(parents=True, exist_ok=True)
resp_dir.mkdir(parents=True, exist_ok=True)
rid = "%d-%d" % (os.getpid(), int(time.time() * 1000))
tmp = req_dir / (rid + ".json.tmp")
tmp.write_text(json.dumps(request))
os.rename(tmp, req_dir / (rid + ".json"))
answer = resp_dir / (rid + ".json")
deadline = time.monotonic() + timeout
while time.monotonic() < deadline:
try:
value = json.loads(answer.read_text())
answer.unlink()
return value
except (OSError, ValueError):
time.sleep(0.05)
# Not answered: the request is withdrawn so a late app does not mint a code nobody reads.
try:
(req_dir / (rid + ".json")).unlink()
except OSError:
pass
return None
def main(argv):
found = find_store_game(argv)
if found is None:
return 0
folder, sidecar = found
store, game = str(sidecar.get("store")), str(sidecar.get("id"))
if store != "epic":
return 0
drop_stale(folder)
launch_dir = os.environ.get("BL_LAUNCH_DIR", "")
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})
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", "")))
return 0
if __name__ == "__main__":
try:
sys.exit(main(sys.argv[1:]))
except Exception as e: # never in the way of the launch
log("skipped: %s" % type(e).__name__)
sys.exit(0)
@@ -96,6 +96,18 @@ TOOL_MANIFEST_VDF = """"manifest"
# each package in use. A file that no longer matches - whatever changed it - is put back before
# Proton starts. Only for the Proton build the choice was made for: after a Steam update the build
# differs and the Proton's own new files are left alone until the user chooses again.
# A store game (GOG, Epic, Amazon) is started through the launcher .bat DroidDeck wrote beside it.
# An Epic game needs a fresh sign-in code, which only the app can mint: droiddeck-store-launch asks
# for it and the app writes it into the game's folder, so a launch from the client's own Play
# button signs in just as one from the app does. A real launch only; never in the way of it.
BL_STORE_SETUP = """
bl_store_launch() {
[ "${verb:-}" = waitforexitandrun ] || return 0
[ -x /usr/local/bin/droiddeck-store-launch ] || return 0
/usr/local/bin/droiddeck-store-launch "$@" || true
}
"""
BL_COMPONENTS_SETUP = """
bl_components() {
base=$1
@@ -332,6 +344,7 @@ if [ -n "$depot" ]; then
bl_game_cpus
bl_idtech3 "$@"
bl_libpath
bl_store_launch "$@"
exec ${BL_TASKSET:-} /usr/local/bin/droiddeck-game-env "$depot/proton" "$verb" "$@" "${BL_EXTRA_ARGS[@]}"
fi
echo "droiddeck-proton: no ARM64 Proton depot yet - the client downloads one as this tool's dependency; retry the launch once it has" >&2
@@ -346,7 +359,7 @@ def launcher_sh(sources=SOURCES):
# something else.
return (LAUNCHER_TEMPLATE % " ".join('"%s"' % n for n in sources)).replace(
"verb=$1; shift", "verb=$1; shift\n" + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP + BL_IDTECH3_SETUP
+ BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP, 1)
+ BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP + BL_STORE_SETUP, 1)
LAUNCHER_SH = launcher_sh()
@@ -390,6 +403,7 @@ bl_directaudio "$here"
bl_game_cpus
bl_idtech3 "$@"
bl_libpath
bl_store_launch "$@"
# Proton takes its base directory from dirname(sys.argv[0]) without resolving it, so it has to be
# started from its own tree.
exec ${BL_TASKSET:-} /usr/local/bin/droiddeck-game-env "$here/%s" "$verb" "$@" "${BL_EXTRA_ARGS[@]}"
@@ -619,7 +633,7 @@ def adopt_extras(tools):
body = (EXTRA_WRAPPER_SH % entry_point).replace(
'here=$(dirname "$0")',
'here=$(dirname "$0")\n' + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP + BL_IDTECH3_SETUP
+ BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP, 1)
+ BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP + BL_STORE_SETUP, 1)
write_changed(wrapper, body, 0o755)
write_changed(manifest, EXTRA_MANIFEST_VDF)
write_changed(compat_vdf, EXTRA_COMPAT_TOOL_VDF % (name, display_name(entry)))