diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 95d5a13d6e..5e65c46f03 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -259,6 +259,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { private val drawerGameInventory = GameProfileInventoryCache() private var drawerGameInventoryRevision = 0L private var drawerGameFexPresetSaving by mutableStateOf(false) + private var drawerGameNoSteamSaving by mutableStateOf(false) private val drawerGameProfileFollowState = GameProfileFollowState() private data class DrawerGameProfileRefresh( val followsSteam: Boolean, @@ -727,6 +728,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { onSelectedGameProfileRefresh = ::refreshDrawerGameProfile, gameFexPresetSaving = drawerGameFexPresetSaving, onGameFexPreset = ::setDrawerGameFexPreset, + gameNoSteamSaving = drawerGameNoSteamSaving, + onGameNoSteam = ::setDrawerGameNoSteam, onComponentSwap = { pid, comp, value -> swapDrawerComponent(pid, comp, value) }, onGameComponent = ::setDrawerGameComponent, )) @@ -984,6 +987,26 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { }, "drawer-game-fex-preset").start() } + private fun setDrawerGameNoSteam(appId: Long, on: Boolean) { + if (drawerGameNoSteamSaving) return + drawerGameNoSteamSaving = true + val name = drawerGameProfileRefresh.data?.profiles?.firstOrNull { it.first == appId }?.second ?: appId.toString() + Thread({ + val message = try { + GameEnvironmentStore.setGameNoSteam(this, appId.toString(), on) + getString(R.string.comp_game_saved_next, name) + } catch (error: Exception) { + Log.w(TAG, "Could not save Start without Steam for $appId", error) + getString(R.string.session_profile_save_failed, error.message ?: error.javaClass.simpleName) + } + uiHandler.post { + drawerGameNoSteamSaving = false + Toast.makeText(this, message, Toast.LENGTH_LONG).show() + refreshDrawerGameProfile() + } + }, "drawer-game-no-steam").start() + } + /** The session this screen is bringing up: the live one when re-attached, else the intent's. */ private fun loadingMode(): String = if (SessionState.running) SessionState.mode diff --git a/app/src/main/java/com/droiddeck/launcher/core/GameEnvironment.kt b/app/src/main/java/com/droiddeck/launcher/core/GameEnvironment.kt index e92da2e171..dc6483118b 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/GameEnvironment.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/GameEnvironment.kt @@ -44,6 +44,20 @@ object GameEnvironment { const val FORCE_SSBS = "DROIDDECK_FORCE_SSBS" + /** + * A game's Start without Steam: droiddeck-game-env launches it without Proton's steam.exe (umu's + * launch where the Proton has it, else runinprefix), for games that close right away. + */ + const val NO_STEAM = "DROIDDECK_NO_STEAM" + + fun gameNoSteam(config: Config, scope: String): Boolean = + scope.isNotEmpty() && config.games[scope]?.get(NO_STEAM)?.lowercase() in setOf("1", "on", "true", "yes") + + fun withGameNoSteam(config: Config, scope: String, on: Boolean): Config { + require(scope.isNotEmpty() && validScope(scope)) + return withScopeValue(config, scope, NO_STEAM, if (on) "1" else null) + } + fun effective(config: Config, preset: String, scope: String, forceSsbs: Boolean = false): Map = defaults(preset, forceSsbs) + config.shared + if (scope.isEmpty()) emptyMap() else config.games[scope].orEmpty() diff --git a/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt b/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt index fa0aa5071c..a87a6c0964 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt @@ -65,6 +65,13 @@ object GameEnvironmentStore { return config } + @Synchronized + fun setGameNoSteam(context: Context, scope: String, on: Boolean): GameEnvironment.Config { + val config = GameEnvironment.withGameNoSteam(read(context), scope, on) + save(context, config) + return config + } + @Synchronized fun publish(context: Context, config: GameEnvironment.Config = read(context)) { val resolved = config.copy(shared = GameEnvironment.defaults(SessionPrefs.fexPreset(context), SessionPrefs.forceSsbs(context)) + config.shared) diff --git a/app/src/main/java/com/droiddeck/launcher/session/SelectedGameProfile.kt b/app/src/main/java/com/droiddeck/launcher/session/SelectedGameProfile.kt index ddb21c6981..aef5064913 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SelectedGameProfile.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SelectedGameProfile.kt @@ -16,13 +16,16 @@ data class SelectedGameProfile( val componentFiles: Map, val environmentOverrides: Int, val windowsComponentNames: List, + /** Start without Steam (GameEnvironment.NO_STEAM) is on for this game. */ + val startWithoutSteam: Boolean = false, ) { val hasOverrides: Boolean get() = !fexPreset.inherited || !proton.inherited || components.values.any { !it.inherited } || environmentOverrides > 0 || - windowsComponentNames.isNotEmpty() + windowsComponentNames.isNotEmpty() || + startWithoutSteam companion object { fun resolve( @@ -50,7 +53,9 @@ data class SelectedGameProfile( inherited = override == null, ) } - val otherEnvironment = environment.games[game.profileKey].orEmpty().keys - FexPreset.environmentKeys + // Start without Steam is a switch of its own on the Games page, listed by name. + val otherEnvironment = environment.games[game.profileKey].orEmpty().keys - FexPreset.environmentKeys - + GameEnvironment.NO_STEAM return SelectedGameProfile( appId = selectedAppId, name = game.name, @@ -64,6 +69,7 @@ data class SelectedGameProfile( componentFiles = gameComponents, environmentOverrides = otherEnvironment.size, windowsComponentNames = gameWindowsComponents.map(WinComponentNames::of), + startWithoutSteam = GameEnvironment.gameNoSteam(environment, game.profileKey), ) } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt index 678e6cbe1e..ab9eb30560 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt @@ -273,6 +273,9 @@ class DrawerActions( val onSelectedGameProfileRefresh: () -> Unit = {}, val gameFexPresetSaving: Boolean = false, val onGameFexPreset: (Long, String?) -> Unit = { _, _ -> }, + /** Saves the selected game's Start without Steam (GameEnvironment.NO_STEAM). */ + val gameNoSteamSaving: Boolean = false, + val onGameNoSteam: (Long, Boolean) -> Unit = { _, _ -> }, /** Swaps [value] ("orig:" or a stored package file) into a Proton's component. */ val onComponentSwap: (protonId: String, comp: String, value: String) -> Unit = { _, _, _ -> }, /** Saves a stored package for a game, or null to inherit that component from the Default profile. */ @@ -515,6 +518,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont TextureFilteringGroup(host, a) { key -> focus.track(page, key) } if (a.steam) SettingsGroup(stringResource(R.string.game_settings_title)) { DrawerFexPresetRow(host, a, focus.track(page, "fex")) + DrawerNoSteamRow(host, a, focus.track(page, "no-steam")) GameEnvironmentRow( modifier = focus.track(page, "game-env"), showHint = false, @@ -940,6 +944,17 @@ private fun DrawerFexPresetRow(host: MenuHost, a: DrawerActions, modifier: Modif } } +/** A game's Start without Steam; only with a game selected - the Default profile has no such switch. */ +@Composable +private fun DrawerNoSteamRow(host: MenuHost, a: DrawerActions, modifier: Modifier) { + val appId = a.selectedGameProfileId ?: return + val profile = a.selectedGameProfile?.takeIf { it.appId == appId } ?: return + ToggleRow( + host, "no-steam", stringResource(R.string.game_no_steam_title), stringResource(R.string.game_no_steam_detail), + profile.startWithoutSteam, enabled = !a.gameNoSteamSaving, chipModifier = modifier, + ) { on -> a.onGameNoSteam(appId, on) } +} + /** Texture filtering on the Games page: DXVK options for the next DirectX 9-11 launch. */ @Composable private fun TextureFilteringGroup(host: MenuHost, a: DrawerActions, track: (String) -> Modifier) { @@ -1028,6 +1043,9 @@ private fun SelectedGameProfileGroup(host: MenuHost, a: DrawerActions, track: (S ProfileSummaryRow(ComponentsManager.LABEL.getValue(component), profileValueLabel(value)) } } + if (profile.startWithoutSteam) { + ProfileSummaryRow(stringResource(R.string.game_no_steam_title), stringResource(R.string.game_no_steam_on)) + } if (profile.environmentOverrides > 0) { ProfileSummaryRow( stringResource(R.string.game_env_title), diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ce6d2a68c0..074d0f1d09 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -438,6 +438,9 @@ Runtime options Other per-game Proton, DXVK, VKD3D-Proton and synchronization environment options. %1$s\'s profile is saved for the next game launch. + Start without Steam + For a game that closes right away: starts it without Proton\'s Steam setup. Steam features such as the overlay are off for it. + On %1$s\'s Proton choice is saved and available in Steam now. %1$s\'s Proton choice is saved. Restart Steam before launching the game. %1$s cannot use the selected Proton on this device. diff --git a/app/src/test/java/com/droiddeck/launcher/session/SelectedGameProfileTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SelectedGameProfileTest.kt index 99209674fd..7955fde23b 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SelectedGameProfileTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SelectedGameProfileTest.kt @@ -71,6 +71,19 @@ class SelectedGameProfileTest { assertTrue(profile.hasOverrides) } + @Test fun startWithoutSteamIsListedByNameAndMakesProfileCustom() { + val environment = GameEnvironment.withGameNoSteam(GameEnvironment.Config(), game.profileKey, true) + val profile = resolve(environment = environment) + + assertTrue(profile!!.startWithoutSteam) + assertEquals(0, profile.environmentOverrides) + assertTrue(profile.hasOverrides) + + val off = GameEnvironment.withGameNoSteam(environment, game.profileKey, false) + assertFalse(resolve(environment = off)!!.startWithoutSteam) + assertEquals(emptyMap>(), off.games) + } + @Test fun unknownSelectedAppIsIgnored() { assertNull(resolve(selectedAppId = 42)) } diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env index 260b6f937d..454fb7e743 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env @@ -253,6 +253,36 @@ def force_ssbs(command, env): return env +def umu_capable(proton): + """Whether this Proton's script has umu's launch without Steam: GE-Proton, Proton-CachyOS and + DroidDeck-Proton run umu.exe in place of steam.exe when UMU_ID is set; Valve's Proton does not.""" + try: + with open(proton, encoding="utf-8", errors="replace") as source: + text = source.read() + except OSError: + return False + return "UMU_ID" in text and "umu.exe" in text + + +def start_without_steam(command, env, app_id): + """DROIDDECK_NO_STEAM=1 (a game's Start without Steam): launch the game without Proton's + steam.exe, for games that close right away because of what it sets up. A Proton with umu's + launch gets UMU_ID - Proton still sets up the prefix, and a Steam game keeps its protonfixes + under its own id; any other Proton runs the game straight in the prefix (runinprefix).""" + if env.get("DROIDDECK_NO_STEAM", "").lower() not in ("1", "on", "true", "yes"): + return command, env + if len(command) < 3 or command[1] != "waitforexitandrun": + return command, env + if umu_capable(command[0]): + if not env.get("UMU_ID"): + steam_game = app_id is not None and int(app_id) < 2**31 + env = dict(env, UMU_ID=app_id if steam_game else "0") + print("droiddeck-game-env: starting without Steam (umu.exe in place of steam.exe, UMU_ID=%s)" % env["UMU_ID"], file=sys.stderr) + return command, env + print("droiddeck-game-env: starting without Steam (this Proton has no umu launch: runinprefix)", file=sys.stderr) + return [command[0], "runinprefix"] + command[2:], env + + EVALUATOR_SCRIPT = re.compile(r"(?:^|[\\/])evaluatorscript_[0-9]+\.vdf$", re.IGNORECASE) @@ -309,6 +339,7 @@ def main(): except (OSError, ValueError, TypeError, AttributeError): print("droiddeck-game-env: invalid configuration; using inherited environment", file=sys.stderr) env = force_ssbs(command, env) + command, env = start_without_steam(command, env, app_id) sync = load_sync() launch, launch_env = select_sync(command, env, sync) if launch[0] != command[0]: diff --git a/tools/tests/test_game_environment.py b/tools/tests/test_game_environment.py index d6a2ee749c..6b2362faa6 100644 --- a/tools/tests/test_game_environment.py +++ b/tools/tests/test_game_environment.py @@ -688,6 +688,33 @@ if __name__ == "__main__": unittest.main() +class StartWithoutSteamTest(unittest.TestCase): + def test_start_without_steam_uses_umu_or_runinprefix_and_only_when_asked(self): + with tempfile.TemporaryDirectory() as tmp: + ge = Path(tmp) / "ge/proton" + ge.parent.mkdir() + ge.write_text('if "UMU_ID" in os.environ:\n argv = [wine, "c:\\\\windows\\\\system32\\\\umu.exe"]\n') + valve = Path(tmp) / "valve/proton" + valve.parent.mkdir() + valve.write_text('argv = [wine, "c:\\\\windows\\\\system32\\\\steam.exe"]\n') + start = MODULE["start_without_steam"] + game = [str(ge), "waitforexitandrun", "/games/Game.exe", "-windowed"] + self.assertEqual(start(game, {}, "3384071994"), (game, {})) + on = {"DROIDDECK_NO_STEAM": "1"} + # An added game (a shortcut id) has no Steam fixes: UMU_ID 0. The command is unchanged. + self.assertEqual(start(game, on, "3384071994"), (game, dict(on, UMU_ID="0"))) + # A Steam game keeps its protonfixes under its own id. + self.assertEqual(start(game, on, "570940")[1]["UMU_ID"], "570940") + # A UMU_ID the user set wins. + self.assertEqual(start(game, dict(on, UMU_ID="umu-1"), "570940")[1]["UMU_ID"], "umu-1") + # Valve's Proton has no umu launch: the game runs straight in the prefix. + plain = [str(valve)] + game[1:] + self.assertEqual(start(plain, on, "570940"), ([str(valve), "runinprefix", "/games/Game.exe", "-windowed"], on)) + # Only a game launch: the client's own runs and other verbs are left alone. + for other in ([str(ge), "run", "/x.exe"], [str(ge), "waitforexitandrun"], [str(valve), "getcompatpath", "/x"]): + self.assertEqual(start(other, on, "570940"), (other, on)) + + class ForceSsbsTest(unittest.TestCase): def test_libssbs_is_preloaded_only_when_asked_and_only_into_arm64_proton(self): with tempfile.TemporaryDirectory() as tmp: