Fix Steam game exit detection and return

This commit is contained in:
EnzoDLofi committed 2026-11-13 22:16:13 -04:00
1 parent 9eca06d92e
commit 7dc9d342e3
3 files changed
+56 -5

No files matched your search

@@ -1633,8 +1633,13 @@ class SessionService : Service() {
if (token != gameExitWatchToken || gen != sessionGen || !SessionState.running ||
SessionState.stopRequested || SessionState.mode != MODE_STEAM ||
!SessionPrefs.returnAfterGame(this) || SessionState.gameId != gameId ||
pendingSteamGameId != null || SteamGameProcess.running()) {
Log.i(TAG, "keeping Steam open after $gameId: another game is running or queued")
pendingSteamGameId != null) {
return@postDelayed
}
if (SteamGameProcess.running()) {
Log.i(TAG, "another Steam game is still running after $gameId; checking again")
returnAfterGame(gameId, gen, token)
return@postDelayed
}
@@ -18,18 +18,39 @@ object SteamGameProcess {
runCatching { File(p, "cmdline").readBytes() }
.getOrNull()?.let(::matches) == true
} == true
private fun steamAppIdForGameId(gameId: String): String? {
if (gameId.isEmpty() || !gameId.all(Char::isDigit)) return null
val numericId = gameId.toULongOrNull() ?: return null
val appId = if (numericId > UInt.MAX_VALUE.toULong()) {
numericId shr 32
} else {
numericId
}
return appId.takeIf { it != 0uL }?.toString()
}
fun matches(cmdline: ByteArray, gameId: String): Boolean {
if (gameId.isEmpty() || !gameId.all(Char::isDigit)) return false
val expectedAppId = steamAppIdForGameId(gameId) ?: return false
val args = String(cmdline).split('\u0000')
for (i in args.indices) {
if (args[i] == "SteamLaunch") {
val appId = args.getOrNull(i + 1)
?.takeIf { it.startsWith("AppId=") }
?.removePrefix("AppId=")
if (appId == gameId) return true
if (appId == expectedAppId) return true
}
if (args[i] == "-applaunch" &&
args.getOrNull(i + 1) == expectedAppId
) {
return true
}
if (args[i] == "-applaunch" && args.getOrNull(i + 1) == gameId) return true
}
return false
}