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.

M6 Macs: use Apple's GPTK 4.0 beta 3 (D3DMetal 3.0 does not start D2R there) (#205)

Mikek23b4cd525808
diff --git a/resources/gptk.json b/resources/gptk.json
index 58d9ad93945..7b987448ee3 100644
--- a/resources/gptk.json
+++ b/resources/gptk.json
@@ -13,5 +13,24 @@
"atidxx64.dll",
"nvapi64.dll",
"nvngx-on-metalfx.dll"
- ]
+ ],
+ "newer_chips": {
+ "min_chip": 6,
+ "why": "D3DMetal 3.0 does not start Diablo II: Resurrected on M6 Macs (macOS 27); 4.0 beta 3 does",
+ "version": "4.0 beta 3",
+ "source": "Apple's Evaluation environment for Windows games 4.0 beta 3, /redist folder unchanged (Soju component release gptk-4.0b3)",
+ "url": "https://github.com/BCD1210/soju/releases/download/gptk-4.0b3/soju-gptk-4.0b3.tar.xz",
+ "sha256": "55e6877bfbea1756d6f8d0a6af944d633a869f3d60ac0d7bc10ff763c31835d6",
+ "size": 16545788,
+ "prefix": "lib",
+ "shims": [
+ "d3d10.dll",
+ "d3d11.dll",
+ "d3d12.dll",
+ "d3d12core.dll",
+ "dxgi.dll",
+ "nvapi64.dll",
+ "nvngx-on-metalfx.dll"
+ ]
+ }
}
diff --git a/scripts/fetch-gptk.py b/scripts/fetch-gptk.py
index b69895689fd..4738287df16 100755
--- a/scripts/fetch-gptk.py
+++ b/scripts/fetch-gptk.py
@@ -9,11 +9,16 @@ them to get-gptk.sh, which installs nothing that is not signed by Apple (the Mac
or a known Apple build (the PE shims).
scripts/fetch-gptk.py download and install into $ENGINE
+ scripts/fetch-gptk.py --check exit 0 when $ENGINE already has every shim of the build this Mac uses
SOJU_GPTK_DOWNLOAD=0 callers skip this and ask for a dmg instead
+
+Macs with an M6 or newer chip get the build under "newer_chips" (4.0 beta 3): D3DMetal 3.0
+does not start Diablo II: Resurrected there.
"""
import hashlib
import json
import os
+import re
from pathlib import Path, PurePosixPath
import shutil
import subprocess
@@ -30,6 +35,37 @@ def digest(path):
for block in iter(lambda: f.read(1024 * 1024), b""): h.update(block)
return h.hexdigest()
+def chip_generation(brand=None):
+ """6 for "Apple M6 Pro", 0 when unknown (Intel, or sysctl missing)."""
+ if brand is None:
+ try:
+ brand = subprocess.run(["/usr/sbin/sysctl", "-n", "machdep.cpu.brand_string"],
+ capture_output=True, text=True).stdout
+ except OSError:
+ brand = ""
+ m = re.search(r"\bApple M(\d+)\b", brand or "")
+ return int(m.group(1)) if m else 0
+
+def choose(manifest, generation):
+ """The build for this Mac: the newer one on chips it names, else the default."""
+ newer = manifest.get("newer_chips")
+ if newer and generation >= newer["min_chip"]:
+ return newer
+ return manifest
+
+def installed(engine, build):
+ """Every shim of the build is in the engine and is one of Apple's (they all name D3DMetalDLLsBase)."""
+ pe = Path(engine) / "lib/wine/x86_64-windows"
+ if not (Path(engine) / "lib/external/libd3dshared.dylib").is_file():
+ return False
+ for shim in build["shims"]:
+ try:
+ if b"D3DMetalDLLsBase" not in (pe / shim).read_bytes():
+ return False
+ except OSError:
+ return False
+ return True
+
def wanted(name, manifest):
"""Path under the stage for an archive member Soju takes, else None."""
prefix = manifest["prefix"].rstrip("/") + "/"
@@ -76,12 +112,14 @@ def unpack(archive, stage, manifest):
raise ValueError("The archive is missing " + shim)
def main():
- manifest = json.loads(MANIFEST.read_text())
+ manifest = choose(json.loads(MANIFEST.read_text()), chip_generation())
base = Path(os.environ.get("SOJU_BASE", Path.home() / ".battlenet-macos"))
engine = Path(os.environ.get("ENGINE", base / "cx26-engine"))
if not (engine / "lib").is_dir():
print("Engine not found at %s. Install Battle.net, Epic or GOG first; that prepares the engine." % engine)
return 1
+ if "--check" in sys.argv[1:]:
+ return 0 if installed(engine, manifest) else 1
print("Downloading Apple's Game Porting Toolkit %s (%d MB)" % (manifest["version"], manifest["size"] // 1000000), flush=True)
base.mkdir(parents=True, exist_ok=True)
with tempfile.TemporaryDirectory(prefix=".gptk-download-", dir=base) as work:
diff --git a/scripts/update.sh b/scripts/update.sh
index 0c75d6333aa..c891dc53926 100755
--- a/scripts/update.sh
+++ b/scripts/update.sh
@@ -102,21 +102,19 @@ fi
# Engines set up from an older toolkit, or by an older Soju, can have only
# d3d11/d3d12/dxgi of Apple's shims. Games that look for the AMD and NVIDIA
# driver shims (Overwatch 2: "General Error 0xE0010110" without atidxx64.dll)
-# then stop at start. Fill in the rest from the pinned toolkit download.
+# then stop at start. Macs with an M6 or newer chip need the 4.0 beta 3 build
+# (D3DMetal 3.0 does not start D2R there). fetch-gptk.py --check knows which
+# build this Mac uses; fill in or replace from the pinned download.
complete_gptk(){
- local f missing=""
[ -f "$ENGINE/lib/external/libd3dshared.dylib" ] || return 0
[ "${SOJU_GPTK_DOWNLOAD:-1}" = 1 ] || return 0
- for f in atidxx64 nvapi64; do
- grep -q "D3DMetalDLLsBase" "$ENGINE/lib/wine/x86_64-windows/$f.dll" 2>/dev/null || missing="$missing $f"
- done
- [ -n "$missing" ] || return 0
+ ENGINE="$ENGINE" SOJU_BASE="$BASE" python3 "$ROOT/scripts/fetch-gptk.py" --check && return 0
if pgrep -x wineserver >/dev/null 2>&1; then
- echo " Apple GPTK is missing$missing.dll; close launchers and games and run soju update again to add them"
+ echo " Apple GPTK in the engine is incomplete or too old for this Mac; close launchers and games and run soju update again"
return 0
fi
- echo " adding Apple's GPTK driver shims ($missing )"
- ENGINE="$ENGINE" SOJU_BASE="$BASE" python3 "$ROOT/scripts/fetch-gptk.py" || echo " could not add them; games that need them may not start (soju gptk retries)"
+ echo " updating Apple's GPTK in the engine"
+ ENGINE="$ENGINE" SOJU_BASE="$BASE" python3 "$ROOT/scripts/fetch-gptk.py" || echo " could not update it; games that need it may not start (soju gptk retries)"
}
# Steam game voices: Wine decodes Windows Media Audio with GStreamer, which no
diff --git a/tests/test_fetch_gptk.py b/tests/test_fetch_gptk.py
index 08fd65cd48c..a3afb7fc49a 100644
--- a/tests/test_fetch_gptk.py
+++ b/tests/test_fetch_gptk.py
@@ -87,5 +87,50 @@ class FetchGptkTests(unittest.TestCase):
self.unpack([e for e in payload() if not e[0].endswith("dxgi.dll")])
+class BuildChoiceTests(unittest.TestCase):
+ def setUp(self):
+ import json
+ self.manifest = json.loads((ROOT / "resources/gptk.json").read_text())
+
+ def test_reads_the_chip_generation(self):
+ self.assertEqual(fetch_gptk.chip_generation("Apple M6 Pro"), 6)
+ self.assertEqual(fetch_gptk.chip_generation("Apple M4"), 4)
+ self.assertEqual(fetch_gptk.chip_generation("Apple M10 Max"), 10)
+ self.assertEqual(fetch_gptk.chip_generation("Intel(R) Core(TM) i9"), 0)
+ self.assertEqual(fetch_gptk.chip_generation(""), 0)
+
+ def test_m6_and_newer_get_the_beta_others_keep_3_0(self):
+ self.assertEqual(fetch_gptk.choose(self.manifest, 6)["version"], "4.0 beta 3")
+ self.assertEqual(fetch_gptk.choose(self.manifest, 7)["version"], "4.0 beta 3")
+ for gen in (0, 1, 4, 5):
+ self.assertEqual(fetch_gptk.choose(self.manifest, gen)["version"], "3.0")
+
+ def test_the_beta_build_is_pinned_like_the_default(self):
+ newer = self.manifest["newer_chips"]
+ self.assertTrue(newer["url"].startswith("https://github.com/BCD1210/soju/releases/download/"))
+ self.assertRegex(newer["sha256"], "^[0-9a-f]{64}$")
+ self.assertIn("d3d12core.dll", newer["shims"])
+ for shim in ("d3d11.dll", "d3d12.dll", "dxgi.dll"):
+ self.assertIn(shim, newer["shims"])
+ known = (ROOT / "scripts/get-gptk.sh").read_text()
+ self.assertIn("4.0 beta 3", known)
+
+ def test_installed_needs_every_shim_of_the_build(self):
+ tmp = tempfile.TemporaryDirectory(); self.addCleanup(tmp.cleanup)
+ engine = Path(tmp.name)
+ pe = engine / "lib/wine/x86_64-windows"; pe.mkdir(parents=True)
+ (engine / "lib/external").mkdir(parents=True)
+ (engine / "lib/external/libd3dshared.dylib").write_bytes(b"x")
+ build = {"shims": ["d3d12.dll", "d3d12core.dll"]}
+ (pe / "d3d12.dll").write_bytes(b"..D3DMetalDLLsBase..")
+ self.assertFalse(fetch_gptk.installed(engine, build))
+ (pe / "d3d12core.dll").write_bytes(b"wine's own")
+ self.assertFalse(fetch_gptk.installed(engine, build))
+ (pe / "d3d12core.dll").write_bytes(b"..D3DMetalDLLsBase..")
+ self.assertTrue(fetch_gptk.installed(engine, build))
+ (engine / "lib/external/libd3dshared.dylib").unlink()
+ self.assertFalse(fetch_gptk.installed(engine, build))
+
+
if __name__ == "__main__":
unittest.main()