mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 14:26:00 +00:00
fix: Start without Steam uses the launch options set in Steam's Properties (#1552)
* fix: Start without Steam uses the launch options set in Steam's Properties * fix: treat a malformed shortcuts.vdf as having no launch options
This commit is contained in:
1 parent
709c041b24
commit
9cecd528e8
4 files changed
+81
-3
No files matched your search
@@ -13,7 +13,8 @@ the STEAM_COMPAT_* environment - so its wrapper applies the game's settings, com
|
||||
--window keeps the program in the desktop's own window, drawn with WineD3D.
|
||||
--app starts one game without the Steam client (its Start without Steam): a Steam game's default
|
||||
Windows launch option from appinfo.vdf when no program is given, else the program in that
|
||||
shortcut's own prefix, started in --dir with the shortcut's launch options (--options).
|
||||
shortcut's own prefix, started in --dir with the shortcut's launch options (--options). Without
|
||||
--options it takes the launch options set in the client's Properties for that game or shortcut.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
@@ -230,6 +231,40 @@ def shortcut_entries(root):
|
||||
return entries
|
||||
|
||||
|
||||
def vdf_string(token):
|
||||
return re.sub(r'\\(.)', r'\1', token[1:-1]) if token.startswith('"') else ""
|
||||
|
||||
|
||||
def steam_options(app, root):
|
||||
"""The launch options the client keeps for a game (localconfig.vdf) or a shortcut (shortcuts.vdf)."""
|
||||
try:
|
||||
tool = runpy.run_path(os.path.join(BIN_DIR, "droiddeck-steam-shortcuts"))
|
||||
account = tool["account_dir"](root)
|
||||
if not account:
|
||||
return ""
|
||||
if int(app) >= STEAM_APP_LIMIT:
|
||||
with open(os.path.join(account, "config", "shortcuts.vdf"), "rb") as f:
|
||||
shortcuts = tool["parse"](f.read()).get("shortcuts", {})
|
||||
for value in shortcuts.values():
|
||||
if isinstance(value, dict) and (value.get("appid", value.get("AppId")) or 0) & 0xFFFFFFFF == int(app):
|
||||
options = value.get("LaunchOptions", value.get("launchoptions", ""))
|
||||
return options if isinstance(options, str) else ""
|
||||
return ""
|
||||
tokens = compat()["tokenize"](read_text(os.path.join(account, "config", "localconfig.vdf")) or "")
|
||||
start = compat()["find_block"](tokens, ["UserLocalConfigStore", "Software", "Valve", "Steam", "apps", app])
|
||||
if start is None:
|
||||
return ""
|
||||
end, depth = compat()["block_end"](tokens, start), 0
|
||||
for i in range(start + 1, end):
|
||||
if tokens[i] in ("{", "}"):
|
||||
depth += 1 if tokens[i] == "{" else -1
|
||||
elif depth == 0 and tokens[i].lower() == '"launchoptions"' and i + 1 < end:
|
||||
return vdf_string(tokens[i + 1])
|
||||
except (OSError, ValueError, IndexError, KeyError, TypeError, AttributeError, struct.error):
|
||||
pass
|
||||
return ""
|
||||
|
||||
|
||||
def shortcut(program, root):
|
||||
for appid, exe, start in shortcut_entries(root):
|
||||
if same_file(program, exe):
|
||||
@@ -372,7 +407,7 @@ def arguments(program, args):
|
||||
|
||||
def main(argv):
|
||||
window = False
|
||||
app, start, options = None, None, ""
|
||||
app, start, options = None, None, None
|
||||
while argv and argv[0].startswith("--"):
|
||||
option = argv.pop(0)
|
||||
if option == "--window":
|
||||
@@ -397,6 +432,8 @@ def main(argv):
|
||||
say("usage: droiddeck-proton-run [--window] PROGRAM [ARGS...]")
|
||||
return 2
|
||||
root = os.environ.get("STEAM_COMPAT_CLIENT_INSTALL_PATH") or STEAM_ROOT
|
||||
if options is None:
|
||||
options = steam_options(app, root) if app is not None else ""
|
||||
extra, args = split_options(options)
|
||||
if not argv:
|
||||
if int(app) >= STEAM_APP_LIMIT:
|
||||
|
||||
@@ -568,6 +568,43 @@ class ProtonRunTest(Temp):
|
||||
self.assertTrue((self.root / "steamapps/compatdata/2733369024").is_dir())
|
||||
self.assertEqual(dirs, [str(start)])
|
||||
|
||||
def write_account(self):
|
||||
self.write("Steam/config/loginusers.vdf",
|
||||
'"users"\n{\n\t"76561198352563669"\n\t{\n\t\t"MostRecent"\t\t"1"\n\t}\n}\n')
|
||||
return "Steam/userdata/392297941/config/"
|
||||
|
||||
def test_without_steam_and_options_a_game_takes_its_steam_launch_options(self):
|
||||
config = self.write_account()
|
||||
self.write(config + "localconfig.vdf", '"UserLocalConfigStore"\n{\n\t"Software"\n\t{\n\t\t"Valve"\n\t\t{\n'
|
||||
'\t\t\t"Steam"\n\t\t\t{\n\t\t\t\t"apps"\n\t\t\t\t{\n\t\t\t\t\t"413150"\n\t\t\t\t\t{\n'
|
||||
'\t\t\t\t\t\t"cloud"\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t"LaunchOptions"\t\t"-wrong"\n\t\t\t\t\t\t}\n'
|
||||
'\t\t\t\t\t\t"LaunchOptions"\t\t"DXVK_HUD=1 %command% -d3d9 \\"-name=Two Words\\""\n'
|
||||
'\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n')
|
||||
shortcuts = runpy.run_path(str(BIN / "droiddeck-steam-shortcuts"))
|
||||
self.write(config + "shortcuts.vdf", shortcuts["write"]({"shortcuts": {
|
||||
"0": {"appid": -1561598272, "AppName": "Batman", "LaunchOptions": "-d3d9"},
|
||||
"1": {"appid": -1, "AppName": "Other", "LaunchOptions": "-x"},
|
||||
}}))
|
||||
root = str(self.root)
|
||||
self.assertEqual(RUN["steam_options"]("413150", root), 'DXVK_HUD=1 %command% -d3d9 "-name=Two Words"')
|
||||
self.assertEqual(RUN["steam_options"]("2733369024", root), "-d3d9")
|
||||
self.assertEqual(RUN["steam_options"]("70", root), "")
|
||||
self.assertEqual(RUN["steam_options"]("2733369025", root), "")
|
||||
info = {"common": {"type": "Game"}, "config": {"launch": {
|
||||
"0": {"executable": "Game.exe", "type": "default", "config": {"oslist": "windows"}}}}}
|
||||
self.write("Steam/appcache/appinfo.vdf", appinfo({413150: info}))
|
||||
program = self.game("413150", "Some Game", "Game.exe")
|
||||
code, calls, _ = self.run_main(["--app", "413150"])
|
||||
self.assertIsNone(code)
|
||||
_, argv, env = calls[0]
|
||||
self.assertEqual(argv[1:], ["waitforexitandrun", str(program), "-d3d9", "-name=Two Words"])
|
||||
self.assertEqual(env["DXVK_HUD"], "1")
|
||||
bat = self.write("Games/GOG/Batman/Batman.exe", b"MZ")
|
||||
code, calls, _ = self.run_main(["--app", "2733369024", "--", str(bat)])
|
||||
self.assertEqual(calls[0][1][1:], ["waitforexitandrun", str(bat), "-d3d9"])
|
||||
code, calls, _ = self.run_main(["--app", "2733369024", "--options", "", "--", str(bat)])
|
||||
self.assertEqual(calls[0][1][1:], ["waitforexitandrun", str(bat)])
|
||||
|
||||
def test_launch_options_split_like_steam_does(self):
|
||||
split = RUN["split_options"]
|
||||
self.assertEqual(split(""), ({}, []))
|
||||
|
||||
Reference in new issue
Block a user