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.
HTML apple-siliconbattle-netcrossover-alternatived3dmetaldiablo-ii-resurrecteddxmtea-appepic-gamesgame-porting-toolkitgogmac-gamingmacosmacos-gamingrockstar-gamessteamubisoft-connectwhisky-alternativewindows-gameswinewine-wrapper
Steam games that need Direct3D 12 start by themselves (#172)
Mikek50a0235e0060
diff --git a/install.sh b/install.shindex 7eed0bc5243..03e7dc551ae 100644--- a/install.sh+++ b/install.sh@@ -99,7 +99,9 @@ EOTesacdonefi-for p in $PLATFORMS; do case " $ALL " in *" $p "*) ;; *) echo "Unknown platform: $p"; exit 1;; esac; done+# "engine" is not a launcher: SOJU_PLATFORMS=engine installs only the CX engine and Apple GPTK, for a Steam game+# that needs Direct3D 12 on a Mac that has Steam alone (scripts/steam-gptk.sh play).+for p in $PLATFORMS; do case " $ALL engine " in *" $p "*) ;; *) echo "Unknown platform: $p"; exit 1;; esac; done[ -n "${PLATFORMS// /}" ] || { echo "Nothing selected."; exit 64; }echo " Installing:$PLATFORMS"diff --git a/scripts/bottle-leftovers.sh b/scripts/bottle-leftovers.shold mode 100644new mode 100755diff --git a/scripts/d2r-macos.sh b/scripts/d2r-macos.shold mode 100644new mode 100755diff --git a/scripts/game-library.py b/scripts/game-library.pyindex 4f3ce7e8b95..99ba1e1617a 100644--- a/scripts/game-library.py+++ b/scripts/game-library.py@@ -22,8 +22,9 @@ from urllib.parse import quoteFOLDERS = {'steam': 'steam-bottle', 'epic': 'epic-bottle','battlenet': 'bottle', 'gog': 'gog-bottle', 'xbox': 'xbox-bottle'}# Steam games that stop without Apple GPTK (soju steam-gptk on): Overwatch 2, and-# Diablo II: Resurrected, whose loader needs GPTK's libd3dshared.-STEAM_GPTK_GAMES = {'2357570', '2536520'}+# 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'}# Installed by Steam itself, not games: Steamworks Common Redistributables.STEAM_TOOLS = {'228980'}CLIENTS = {@@ -177,13 +178,12 @@ class Library:issue = 'This game is on ' + drive + '. Connect the drive, then try again.'elif not ready: issue = 'Finish the installation or update in the official launcher.'elif not arguments: issue = 'Open the official launcher to play this title.'- elif platform == 'steam' and uid in STEAM_GPTK_GAMES and self.folders['steam'] == 'steam-bottle':- issue = ('This game needs Apple GPTK. In Stores, turn on "Overwatch and Diablo II mode" '- 'on the Steam card; Steam asks you to sign in once there, and the game shows up again.')+ # A Steam game that needs Apple GPTK while Steam is in its plain mode: Play switches the mode itself.+ gptk = issue is None and platform == 'steam' and uid in STEAM_GPTK_GAMES and self.folders['steam'] == 'steam-bottle'self.games[key] = dict(id=key, platform=platform, title=title.strip()[:300],install_path=str(location), artwork=artwork,issue=issue, arguments=arguments,- note=None if unplugged else anticheat_note(location))+ note=None if unplugged else anticheat_note(location), gptk=gptk)if location.is_symlink():# Moved to another drive with scripts/game-storage.py: say where it is.target = Path(os.readlink(location)).parts@@ -426,6 +426,7 @@ class Library:return ['/bin/bash', str(Path(__file__).resolve().parent / 'play.sh'), game['platform']] + argsif 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']return ['/bin/bash', str(root / 'play.sh'), game['platform']] + game['arguments']diff --git a/scripts/steam-gptk.sh b/scripts/steam-gptk.shindex 6a012f0fe9f..a46cc0e022a 100755--- a/scripts/steam-gptk.sh+++ b/scripts/steam-gptk.sh@@ -1,5 +1,5 @@#!/usr/bin/env bash-# soju steam-gptk on|off|status+# soju steam-gptk on|off|status|play <steam url>## "Steam with Apple GPTK": Steam and its games run on the CX engine with Apple's# Game Porting Toolkit (scripts/steam-gptk-engine.sh) instead of the private@@ -26,7 +26,48 @@ steam_running(){! python3 "$ROOT/scripts/steam-session.py" idle "$STEAM_WINE_ROOT" >/dev/null 2>&1}+# Games installed in the plain bottle since the GPTK bottle was made: bring them over (APFS clones, no extra+# space), so the library and Steam show the same games in both modes and nothing is downloaded twice.+sync_games(){+ local apps="drive_c/Program Files (x86)/Steam/steamapps" f name dir+ [ -d "$PLAIN/$apps" ] && [ -d "$GPTK/$apps" ] || return 0+ for f in "$PLAIN/$apps"/appmanifest_*.acf; do+ [ -f "$f" ] || continue+ name=$(basename "$f")+ [ ! -e "$GPTK/$apps/$name" ] || continue+ dir=$(sed -n 's/^[[:space:]]*"installdir"[[:space:]]*"\(.*\)"[[:space:]]*$/\1/p' "$f" | head -1)+ [ -n "$dir" ] && [ -d "$PLAIN/$apps/common/$dir" ] || continue+ case "$dir" in */*|*\\*|.|..) continue ;; esac+ mkdir -p "$GPTK/$apps/common"+ if [ ! -e "$GPTK/$apps/common/$dir" ]; then+ cp -Rc "$PLAIN/$apps/common/$dir" "$GPTK/$apps/common/$dir" 2>/dev/null || { rm -rf "$GPTK/$apps/common/$dir"; continue; }+ fi+ cp -c "$f" "$GPTK/$apps/$name" 2>/dev/null || cp "$f" "$GPTK/$apps/$name"+ echo "Brought over to the GPTK bottle: $dir"+ done+}+case "${1:-status}" in+ play) # Play for a game that needs Direct3D 12: whatever is missing for the GPTK mode is done first, then the game starts.+ shift+ if [ "$(bash "${BASH_SOURCE[0]}" status)" != on ]; then+ echo "This game needs Direct3D 12, so Steam switches to its Apple GPTK mode. This happens once; your other Steam games stay."+ if [ ! -x "$BASE/cx26-engine/bin/wine" ] || [ ! -f "$BASE/cx26-engine/lib/external/libd3dshared.dylib" ]; then+ echo "Downloading what that mode needs (the engine and Apple's Game Porting Toolkit, about 600 MB, once)"+ SOJU_PLATFORMS=engine SOJU_NONINTERACTIVE=1 bash "$ROOT/install.sh" </dev/null \+ || { echo "soju: the Direct3D 12 engine could not be installed. Check your connection and press Play again." >&2; exit 1; }+ [ -f "$BASE/cx26-engine/lib/external/libd3dshared.dylib" ] \+ || { echo "soju: Apple's Game Porting Toolkit could not be downloaded. In Stores, open Settings, Apple GPTK, Download and install, then press Play again." >&2; exit 1; }+ fi+ if steam_running; then+ echo "Closing Steam to switch"+ bash "$ROOT/scripts/play.sh" steam-kill >/dev/null 2>&1 || true+ for _ in $(seq 1 30); do steam_running || break; sleep 1; done+ fi+ bash "${BASH_SOURCE[0]}" on || exit 1+ fi+ exec bash "$ROOT/scripts/play.sh" steam "$@"+ ;;on)[ -f "$PLAIN/$CLIENT" ] || { echo "soju: install Steam first (Stores, or soju steam-install)" >&2; exit 1; }if steam_running; then echo "soju: quit Steam first (soju steam-kill)" >&2; exit 1; fi@@ -38,6 +79,8 @@ case "${1:-status}" in# The copy belongs to the other engine now; drop marks that only the Wine 11 setup reads.rm -f "$GPTK.new/.soju-steam-games" "$GPTK.new/.soju-auto-profiles.json"mv "$GPTK.new" "$GPTK"+ else+ sync_gamesfitouch "$FLAG"echo "Steam with Apple GPTK: on. Steam asks you to sign in once the first time."@@ -50,5 +93,5 @@ case "${1:-status}" instatus)if [ -f "$FLAG" ] && [ -f "$GPTK/$CLIENT" ]; then echo on; else echo off; fi;;- *) echo "usage: soju steam-gptk on|off|status" >&2; exit 64 ;;+ *) echo "usage: soju steam-gptk on|off|status|play <steam url>" >&2; exit 64 ;;esacdiff --git a/tests/test_steam_gptk.py b/tests/test_steam_gptk.pyindex 737b13c5c12..f592dd2180a 100644--- a/tests/test_steam_gptk.py+++ b/tests/test_steam_gptk.py@@ -57,8 +57,27 @@ class SteamGPTKTests(unittest.TestCase):(root / 'steamapps' / f'appmanifest_{uid}.acf').write_text(f'"AppState" {{ "appid" "{uid}" "name" "{folder}" "StateFlags" "4" "installdir" "{folder}" }}')lib = library.Library(self.base); lib.steam()- self.assertIn('Overwatch and Diablo II mode', lib.games['steam:2357570']['issue'])+ # No message to act on: Play itself switches Steam to the mode the game needs.+ self.assertIsNone(lib.games['steam:2357570']['issue'])self.assertIsNone(lib.games['steam:70']['issue'])+ 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_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'+ (self.base / 'steam-bottle' / apps / 'common/Sinking Star').mkdir(parents=True)+ (self.base / 'steam-bottle' / apps / 'common/Sinking Star/game.exe').write_text('x')+ (self.base / 'steam-bottle' / apps / 'appmanifest_499170.acf').write_text(+ '"AppState"\n{\n\t"appid"\t\t"499170"\n\t"installdir"\t\t"Sinking Star"\n}\n')+ (self.base / 'steam-gptk-bottle' / apps).mkdir(parents=True, exist_ok=True)+ text = (ROOT / 'scripts/steam-gptk.sh').read_text()+ body = text.split('sync_games(){', 1)[1].split('\n}\n', 1)[0]+ script = 'PLAIN=%r; GPTK=%r\nsync_games(){%s\n}\nsync_games\n' % (str(self.base / 'steam-bottle'), str(self.base / 'steam-gptk-bottle'), body)+ result = subprocess.run(['/bin/bash', '-c', script], capture_output=True, text=True)+ self.assertEqual(result.returncode, 0, result.stderr)+ self.assertTrue((self.base / 'steam-gptk-bottle' / apps / 'appmanifest_499170.acf').is_file())+ self.assertTrue((self.base / 'steam-gptk-bottle' / apps / 'common/Sinking Star/game.exe').is_file())def test_play_sh_picks_the_gptk_bottle(self):text = (ROOT / 'scripts/play.sh').read_text()