Skip to content

armgit / soju

Public Imported from GitHub
0

Play Windows games on Apple Silicon Macs. Free, open-source app that installs the official Battle.net, Steam, Epic and GOG launchers and lists your games in one library.

Steam: DirectX 12 games go to the GPTK mode by themselves; exit codes in play counts (#183)

Mikek09238c791369
diff --git a/scripts/game-library.py b/scripts/game-library.py
index 99ba1e1617a..d116f45cff7 100644
--- a/scripts/game-library.py
+++ b/scripts/game-library.py
@@ -25,6 +25,41 @@ FOLDERS = {'steam': 'steam-bottle', 'epic': 'epic-bottle',
# Diablo II: Resurrected, whose loader needs GPTK's libd3dshared. Order of the Sinking Star
# asks for Direct3D feature level 12_0 and shows an error window under the Direct3D 11 setup (#171).
STEAM_GPTK_GAMES = {'2357570', '2536520', '499170'}
+# Any other Steam game whose store page asks for DirectX 12 at minimum gets the same treatment: in the
+# Direct3D 11 setup such games close within a minute (Order of the Sinking Star said so in a window, #171;
+# Resident Evil 4, Dead Island 2 and Hogwarts Legacy closed at once in the play counts, 2026-11-23).
+# The answer is kept per game in steam-dx12.json, so the store is asked once.
+STEAM_STORE = 'https://store.steampowered.com/api/appdetails?appids={}&filters=basic,pc_requirements'
+
+
+def needs_dx12(base, uid, fetch=None):
+ """True when Steam's store lists DirectX 12 under the minimum requirements of this game."""
+ cache = Path(base) / 'steam-dx12.json'
+ try: known = json.loads(cache.read_text())
+ except (OSError, ValueError): known = {}
+ if uid in known: return bool(known[uid])
+ try:
+ if fetch is None:
+ import urllib.request
+ req = urllib.request.Request(STEAM_STORE.format(uid), headers={'user-agent': 'soju'})
+ with urllib.request.urlopen(req, timeout=5) as res: body = res.read().decode('utf-8', 'replace')
+ else:
+ body = fetch(uid)
+ data = json.loads(body).get(uid, {})
+ if not data.get('success'): return False
+ info = data.get('data') if isinstance(data.get('data'), dict) else {}
+ req = info.get('pc_requirements') or {}
+ minimum = req.get('minimum', '') if isinstance(req, dict) else ''
+ found = re.search(r'DirectX:?\s*(?:</strong>)?\s*(?:Version\s*)?(\d+)', minimum, re.I)
+ answer = bool(found and int(found.group(1)) >= 12)
+ except Exception:
+ return False # offline or the store did not answer: start the game as before, ask again next time
+ known[uid] = answer
+ try:
+ cache.write_text(json.dumps(known)); os.chmod(cache, 0o600)
+ except OSError: pass
+ return answer
+
# Installed by Steam itself, not games: Steamworks Common Redistributables.
STEAM_TOOLS = {'228980'}
CLIENTS = {
@@ -426,7 +461,9 @@ class Library:
return ['/bin/bash', str(Path(__file__).resolve().parent / 'play.sh'), game['platform']] + args
if not game['install_path']: raise ValueError('This game is owned but not installed. Open its launcher to install it.')
if game['issue']: raise ValueError(game['issue'])
- if game.get('gptk'): return ['/bin/bash', str(root / 'steam-gptk.sh'), 'play'] + game['arguments']
+ if game.get('gptk') or (game['platform'] == 'steam' and self.folders['steam'] == 'steam-bottle'
+ and needs_dx12(self.base, game_id.split(':', 1)[1])):
+ return ['/bin/bash', str(root / 'steam-gptk.sh'), 'play'] + game['arguments']
return ['/bin/bash', str(root / 'play.sh'), game['platform']] + game['arguments']
diff --git a/scripts/play-stats.py b/scripts/play-stats.py
index d2827220a29..73071f60620 100755
--- a/scripts/play-stats.py
+++ b/scripts/play-stats.py
@@ -171,7 +171,8 @@ def log_marks(game, launcher):
out = {}
paths = [logs / ("game-" + game.replace(":", "-") + ".log"), logs / ("desktop-" + launcher + ".log")]
if launcher == "steam": # Steam's own log of each start, in whichever bottle it runs from
- paths += [BASE / b / "drive_c/Program Files (x86)/Steam/logs/console_log.txt" for b in ("steam-bottle", "steam-gptk-bottle")]
+ paths += [BASE / b / "drive_c/Program Files (x86)/Steam/logs" / f for b in ("steam-bottle", "steam-gptk-bottle")
+ for f in ("console_log.txt", "gameprocess_log.txt")]
for path in paths:
try:
st = path.stat()
@@ -250,6 +251,11 @@ def reason(started, minutes, marks, found, path, launcher="", game=""):
kind, step = steam_launch.outcome(text, game.split(":", 1)[1])
if kind in ("error", "waiting", "updating"):
word, name = "steam_" + kind, SAFE.sub("", step)[:40]
+ else:
+ # Steam started it: how the game's process ended, as Steam saw it ("exit code -1073741819" is a crash).
+ codes = re.findall(r"AppID %s no longer tracking PID \d+, exit code (-?\d+)" % re.escape(game.split(":", 1)[1]), text)
+ if codes:
+ word, name = "steam_exit", "exit_" + codes[-1][:20]
except Exception:
pass
if not word and launcher == "battlenet" and ":" in game and isinstance(marks, dict) and marks.get("_t"):
diff --git a/site-worker/stats.js b/site-worker/stats.js
index e6536c1b205..b477d12e01d 100644
--- a/site-worker/stats.js
+++ b/site-worker/stats.js
@@ -22,7 +22,7 @@ const SCHEMA = [
];
const RESULTS = new Set(["ran", "quick_exit", "no_start"]);
// Why a start did not run, as the Mac read it from its own launch log: one word, one name, and the game's anti-cheat.
-const WHY = new Set(["crash", "missing_dll", "graphics", "memory", "dotnet", "launcher_open", "launcher_closed", "steam_error", "steam_waiting", "steam_updating", "bnet_launched", "bnet_session", "bnet_updating", "bnet_signin"]);
+const WHY = new Set(["crash", "missing_dll", "graphics", "memory", "dotnet", "launcher_open", "launcher_closed", "steam_error", "steam_waiting", "steam_updating", "bnet_launched", "bnet_session", "bnet_updating", "bnet_signin", "steam_exit"]);
const AC = new Set(["eac", "battleye", "vanguard", "gameguard", "xigncode", "punkbuster"]);
const name = (v) => { const s = text(v, 40); return /^[A-Za-z0-9._+-]*$/.test(s) ? s : ""; };
const HOW = new Set(["soju", "steam"]);
diff --git a/tests/test_play_stats.py b/tests/test_play_stats.py
index 8c02aac9b3a..77684e49325 100644
--- a/tests/test_play_stats.py
+++ b/tests/test_play_stats.py
@@ -184,6 +184,15 @@ class PlayStats(unittest.TestCase):
with open(log, 'a') as f: f.write(mine)
self.assertEqual(ps.reason(True, 0, marks, found, game), {'why': 'missing_dll', 'detail': 'vcruntime140.dll', 'ac': 'eac'})
self.assertEqual(ps.reason(True, 5, marks, found, game), {})
+ # Steam started it and it closed: the exit code Steam saw goes along.
+ with tempfile.TemporaryDirectory() as d2, mock.patch.object(ps, 'BASE', Path(d2)):
+ logs2 = Path(d2) / 'steam-bottle/drive_c/Program Files (x86)/Steam/logs'
+ logs2.mkdir(parents=True)
+ gp = logs2 / 'gameprocess_log.txt'
+ gp.write_text('[t] AppID 70 no longer tracking PID 5, exit code 0\n')
+ marks = ps.log_marks('steam:70', 'steam')
+ with open(gp, 'a') as f: f.write('[t] AppID 70 no longer tracking PID 9, exit code -1073741819\n')
+ self.assertEqual(ps.reason(True, 0, marks, [], None, 'steam', 'steam:70'), {'why': 'steam_exit', 'detail': 'exit_-1073741819'})
# A game that never appeared and left nothing in the log: say whether its store was still open.
self.assertEqual(ps.launcher_state('battlenet', 'c:\\program files (x86)\\battle.net\\battle.net.exe --exec=launch osi'), 'launcher_open')
self.assertEqual(ps.launcher_state('battlenet', 'something else'), 'launcher_closed')
diff --git a/tests/test_steam_gptk.py b/tests/test_steam_gptk.py
index f592dd2180a..cabfc096f0b 100644
--- a/tests/test_steam_gptk.py
+++ b/tests/test_steam_gptk.py
@@ -63,6 +63,20 @@ class SteamGPTKTests(unittest.TestCase):
self.assertEqual(lib.command('steam:2357570')[1:], [str(ROOT / 'scripts/steam-gptk.sh'), 'play', 'steam://rungameid/2357570'])
self.assertEqual(lib.command('steam:70')[1:], [str(ROOT / 'scripts/play.sh'), 'steam', 'steam://rungameid/70'])
+ def test_a_game_whose_store_page_asks_for_directx_12_goes_to_the_gptk_mode(self):
+ calls = []
+ def fetch(uid):
+ calls.append(uid)
+ dx = {'2050650': '12', '70': '9'}.get(uid)
+ if dx is None: return '{"%s": {"success": false}}' % uid
+ return '{"%s": {"success": true, "data": {"pc_requirements": {"minimum": "<li><strong>DirectX:</strong> Version %s<br></li>"}}}}' % (uid, dx)
+ self.assertTrue(library.needs_dx12(self.base, '2050650', fetch))
+ self.assertFalse(library.needs_dx12(self.base, '70', fetch))
+ self.assertFalse(library.needs_dx12(self.base, '1', fetch))
+ self.assertTrue(library.needs_dx12(self.base, '2050650', fetch)) # asked once, then kept
+ self.assertEqual(calls.count('2050650'), 1)
+ self.assertFalse(library.needs_dx12(self.base, '3', lambda uid: (_ for _ in ()).throw(OSError('offline'))))
+
def test_turning_the_mode_on_brings_over_games_installed_since(self):
self.put('steam-bottle/' + CLIENT); self.put('steam-gptk-bottle/' + CLIENT)
apps = 'drive_c/Program Files (x86)/Steam/steamapps'