From 83dc5f37e9180cf5310b7d0c0f636678dfaa7ce5 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Fri, 20 Nov 2026 11:40:17 -0500 Subject: [PATCH] fix(session): launching the running game again resumes it instead of asking Steam twice (#2940) * fix(session): launching the running game again resumes it instead of asking Steam twice A front end that resumes a suspended player by launching the same game again (Cocoon 3.07 does) made DroidDeck queue the game for Steam a second time, and Steam answered with "An error occurred while launching this game: Game already running" over the game. queueSteamGame now resumes the session and returns when the requested game is the current one and its process is running. A different game, or one that has exited, still goes to Steam as before. * fix(session): a relaunch during a pending freeze resumes too, and both game ID forms count as the same game --- .../droiddeck/launcher/session/SessionService.kt | 5 +++++ .../droiddeck/launcher/session/SteamGameProcess.kt | 7 +++++++ .../launcher/session/SteamGameProcessTest.kt | 13 +++++++++++++ 3 files changed, 25 insertions(+) diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt index 94664b469..285f6b7c0 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -1613,6 +1613,11 @@ class SessionService : Service() { return } val accepted = gameId!! + if (pendingSteamGameId == null && SteamGameProcess.alreadyRunning(accepted, SessionState.gameId)) { + Log.i(TAG, "game $accepted is already running; resuming it instead of launching it again") + if (SessionState.suspended || SessionState.suspending) resumeSession() + return + } if (!pendingSteamPreviousGamePending) { pendingSteamPreviousGameId = SessionState.gameId pendingSteamPreviousGamePending = true diff --git a/app/src/main/java/com/droiddeck/launcher/session/SteamGameProcess.kt b/app/src/main/java/com/droiddeck/launcher/session/SteamGameProcess.kt index 7a00553f3..6b7ecda60 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SteamGameProcess.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SteamGameProcess.kt @@ -61,4 +61,11 @@ object SteamGameProcess { runCatching { File(p, "cmdline").readBytes() } .getOrNull()?.let { matches(it, gameId) } == true } == true + + // A front end that resumes a player by launching the same game again would otherwise have Steam + // start it a second time, which Steam answers with "Game already running". + fun alreadyRunning(requested: String, current: String?, proc: File = File("/proc")): Boolean { + val appId = steamAppIdForGameId(requested) ?: return false + return appId == steamAppIdForGameId(current.orEmpty()) && running(requested, proc) + } } diff --git a/app/src/test/java/com/droiddeck/launcher/session/SteamGameProcessTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SteamGameProcessTest.kt index ae9b31d80..5e68b5fee 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SteamGameProcessTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SteamGameProcessTest.kt @@ -88,4 +88,17 @@ class SteamGameProcessTest { process("301", "reaper", "SteamLaunch", "AppId=351710", "--", "proton", "waitforexitandrun", "game.exe") assertTrue(SteamGameProcess.running("351710", proc)) } + + @Test fun onlyTheRunningCurrentGameCountsAsAlreadyRunning() { + val proc = tmp.newFolder("proc-relaunch") + File(proc, "200").apply { mkdirs() }.resolve("cmdline") + .writeBytes(cmdline("reaper", "SteamLaunch", "AppId=584400", "--", "proton", "waitforexitandrun", "SonicMania.exe")) + assertTrue(SteamGameProcess.alreadyRunning("584400", "584400", proc)) + assertFalse(SteamGameProcess.alreadyRunning("584400", "311340", proc)) + assertFalse(SteamGameProcess.alreadyRunning("311340", "311340", proc)) + assertFalse(SteamGameProcess.alreadyRunning("584400", null, proc)) + val shortcutId = ((584400uL shl 32) or 0x02000000uL).toString() + assertTrue(SteamGameProcess.alreadyRunning(shortcutId, "584400", proc)) + assertTrue(SteamGameProcess.alreadyRunning("584400", shortcutId, proc)) + } }