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.

Diablo Immortal: loads finish, with the D3DCompiler the game ships (#224)

Mikek9b51e2fbe480
diff --git a/scripts/own-d3dcompiler.sh b/scripts/own-d3dcompiler.sh
new file mode 100755
index 00000000000..f95e162534b
--- /dev/null
+++ b/scripts/own-d3dcompiler.sh
@@ -0,0 +1,27 @@
+#!/usr/bin/env bash
+# Make games that compile shaders while they load use the D3DCompiler they ship.
+#
+# CrossOver's Wine loads its own d3dcompiler_47.dll even when the game has Microsoft's next
+# to its exe. Diablo Immortal compiles its shaders with it when entering the world; with
+# Wine's compiler next to none come out (LocalData/Cache3/LocalShaders/compiled.dx11 stays
+# near 17 KB instead of 300 KB) and the game waits on the loading screen at 100% for good,
+# at a few percent CPU (#221, seen on M4 Pro and M5). With the game's own DLL the world
+# opens in under half a minute.
+#
+# own-d3dcompiler.sh needs WINEPREFIX and ENGINE (and the Wine environment of play.sh)
+#
+# A key that already exists is left alone, so a value set by hand stays. Reads user.reg
+# instead of asking Wine, so a start that has nothing to add costs no Wine process.
+set -u
+GAMES="DiabloImmortal.exe"
+DLLS="d3dcompiler_47 d3dcompiler_43"
+[ -n "${WINEPREFIX:-}" ] && [ -x "${ENGINE:-}/bin/wine" ] || exit 0
+for exe in $GAMES; do
+ if grep -qiF "[Software\\\\Wine\\\\AppDefaults\\\\$exe\\\\DllOverrides]" "$WINEPREFIX/user.reg" 2>/dev/null; then
+ continue
+ fi
+ for dll in $DLLS; do
+ "$ENGINE/bin/wine" reg add "HKCU\\Software\\Wine\\AppDefaults\\$exe\\DllOverrides" /v "$dll" /t REG_SZ /d native /f >/dev/null 2>&1 || true
+ done
+done
+exit 0
diff --git a/scripts/play.sh b/scripts/play.sh
index f806383d1f1..0f923445111 100755
--- a/scripts/play.sh
+++ b/scripts/play.sh
@@ -212,6 +212,8 @@ case "$MODE" in
# spawns a separate GPU process that dies on init and the frameless main
# window stays fully transparent (Dock icon, no window). See docs/DIAGNOSIS.md.
start_reaper
+ # Diablo Immortal stops on its loading screen with Wine's own d3dcompiler (#221): give it the one it ships.
+ ENGINE="$ENGINE" bash "$(dirname "${BASH_SOURCE[0]}")/own-d3dcompiler.sh" || true
# By default Battle.net exits when its window is closed (same as Windows).
# With Settings > "When I close the app" set to the tray (Client.HideOnClose),
# the window hides instead; a Dock-icon click then starts a second
diff --git a/tests/test_own_d3dcompiler.py b/tests/test_own_d3dcompiler.py
new file mode 100644
index 00000000000..2126d0734ee
--- /dev/null
+++ b/tests/test_own_d3dcompiler.py
@@ -0,0 +1,48 @@
+import os
+import subprocess
+import tempfile
+import unittest
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parent.parent
+SCRIPT = ROOT / "scripts/own-d3dcompiler.sh"
+KEY = "HKCU\\Software\\Wine\\AppDefaults\\DiabloImmortal.exe\\DllOverrides"
+
+
+class OwnD3DCompilerTests(unittest.TestCase):
+ def run_script(self, user_reg=None):
+ tmp = tempfile.TemporaryDirectory(); self.addCleanup(tmp.cleanup)
+ root = Path(tmp.name); bottle = root / "bottle"; engine = root / "engine"
+ (engine / "bin").mkdir(parents=True); bottle.mkdir()
+ calls = root / "calls"
+ wine = engine / "bin/wine"
+ wine.write_text('#!/bin/sh\nprintf "%s\\n" "$*" >> "' + str(calls) + '"\n'); wine.chmod(0o755)
+ if user_reg is not None:
+ (bottle / "user.reg").write_text(user_reg)
+ env = dict(os.environ, WINEPREFIX=str(bottle), ENGINE=str(engine))
+ done = subprocess.run(["bash", str(SCRIPT)], env=env, capture_output=True, text=True)
+ self.assertEqual(done.returncode, 0, done.stderr)
+ return calls.read_text().splitlines() if calls.exists() else []
+
+ def test_adds_the_games_own_compilers_once(self):
+ expected = ["reg add " + KEY + " /v " + dll + " /t REG_SZ /d native /f" for dll in ("d3dcompiler_47", "d3dcompiler_43")]
+ self.assertEqual(self.run_script(), expected)
+ self.assertEqual(self.run_script("WINE REGISTRY Version 2\n\n[Software\\\\Wine\\\\Fonts] 1\n"), expected)
+
+ def test_an_existing_key_is_left_alone_and_wine_is_not_started(self):
+ reg = ("WINE REGISTRY Version 2\n\n[Software\\\\Wine\\\\AppDefaults\\\\DiabloImmortal.exe\\\\DllOverrides] 1795672426\n"
+ '"d3dcompiler_47"="builtin"\n')
+ self.assertEqual(self.run_script(reg), [])
+
+ def test_no_engine_or_bottle_is_not_an_error(self):
+ done = subprocess.run(["bash", str(SCRIPT)], env={"PATH": os.environ["PATH"]}, capture_output=True, text=True)
+ self.assertEqual(done.returncode, 0)
+
+ def test_battle_net_starts_run_it(self):
+ text = (ROOT / "scripts/play.sh").read_text()
+ battlenet = text[text.index(" battlenet) #"):text.index(" d2r) ")]
+ self.assertIn("own-d3dcompiler.sh", battlenet)
+
+
+if __name__ == "__main__":
+ unittest.main()