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.

DLSS: works with a GPTK taken from CrossOver; Command-as-Ctrl keys are set before it (#193)

Mikek04f7336cad36
diff --git a/scripts/gptk-dlss.sh b/scripts/gptk-dlss.sh
index 0273713ebf8..f53c1d672bd 100644
--- a/scripts/gptk-dlss.sh
+++ b/scripts/gptk-dlss.sh
@@ -2,7 +2,7 @@
# gptk-dlss.sh <engine> <prefix>: make NVIDIA DLSS work in games through
# Apple's MetalFX (D3DMetal's NGX bridge). Run before every launch; it only
# writes when something is missing, and does nothing on an engine without
-# Apple's nvngx-on-metalfx shim (no GPTK, or a toolkit older than 3.0).
+# Apple's NGX shim (no GPTK, or a toolkit older than 3.0).
# Exit status 0 when the bridge is ready (the caller then sets
# D3DM_ENABLE_METALFX=1), 1 otherwise.
#
@@ -24,11 +24,16 @@
set -u
ENGINE="${1:?engine}"; PREFIX="${2:?prefix}"
W="$ENGINE/lib/wine/x86_64-windows"; U="$ENGINE/lib/wine/x86_64-unix"
-[ -f "$W/nvngx-on-metalfx.dll" ] && [ -f "$ENGINE/lib/external/libd3dshared.dylib" ] || exit 1
-
-if ! cmp -s "$W/nvngx-on-metalfx.dll" "$W/nvngx.dll" 2>/dev/null; then
- cp -f "$W/nvngx-on-metalfx.dll" "$W/nvngx.dll.new" && mv -f "$W/nvngx.dll.new" "$W/nvngx.dll" || exit 1
+[ -f "$ENGINE/lib/external/libd3dshared.dylib" ] || exit 1
+# Apple's own build only (its PE shims name D3DMetalDLLsBase): a toolkit dmg installs it as
+# nvngx-on-metalfx.dll, a payload taken from CrossOver (get-gptk.sh) as nvngx.dll already.
+apple() { [ -f "$1" ] && grep -q D3DMetalDLLsBase "$1" 2>/dev/null; }
+if apple "$W/nvngx-on-metalfx.dll"; then
+ if ! cmp -s "$W/nvngx-on-metalfx.dll" "$W/nvngx.dll" 2>/dev/null; then
+ cp -f "$W/nvngx-on-metalfx.dll" "$W/nvngx.dll.new" && mv -f "$W/nvngx.dll.new" "$W/nvngx.dll" || exit 1
+ fi
fi
+apple "$W/nvngx.dll" || exit 1
if [ "$(readlink "$U/nvngx.so" 2>/dev/null)" != ../../external/libd3dshared.dylib ]; then
rm -f "$U/nvngx.so"; ln -s ../../external/libd3dshared.dylib "$U/nvngx.so" || exit 1
fi
diff --git a/scripts/play.sh b/scripts/play.sh
index bd48c69d6af..3e3999aae90 100755
--- a/scripts/play.sh
+++ b/scripts/play.sh
@@ -108,7 +108,6 @@ export CX_ACTIVE_GRAPHICS_BACKEND=d3dmetal
export CX_GRAPHICS_BACKEND=d3dmetal
export CX_APPLEGPTK_LIBD3DSHARED_PATH="$ENGINE/lib/external/libd3dshared.dylib"
export DYLD_FALLBACK_LIBRARY_PATH="$ENGINE/lib:/usr/lib"
-case "$MODE" in battlenet|d2r|epic|gog|ea|rockstar|ubisoft) dlss_on ;; esac
# Agent signature-check fix: sync the signed exe into each versioned subfolder
BN="$WINEPREFIX/drive_c/Program Files (x86)/Battle.net"
@@ -152,6 +151,9 @@ case "$MODE" in *-kill|controllers) ;; *)
fi
fi ;;
esac
+# DLSS after the keys above: its first run starts the wineserver (wine reg), and the keys are written only while
+# no server runs.
+case "$MODE" in battlenet|d2r|epic|gog|ea|rockstar|ubisoft) dlss_on ;; esac
# Preflight for the CX engine modes: without the GPTK payload, or with a
# payload whose PE shims are missing (an engine refreshed by an older
diff --git a/tests/test_gptk_dlss.py b/tests/test_gptk_dlss.py
index 4374dde2ed6..e04845fa110 100644
--- a/tests/test_gptk_dlss.py
+++ b/tests/test_gptk_dlss.py
@@ -5,17 +5,18 @@ import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
+SHIM = b"MZ ... D3DMetalDLLsBase ... nvngx" # Apple's PE shims carry this build path
SCRIPT = ROOT / "scripts/gptk-dlss.sh"
-def fake_engine(base, shim=True):
+def fake_engine(base, shim=True, name="nvngx-on-metalfx.dll"):
eng = Path(base) / "engine"
(eng / "lib/wine/x86_64-windows").mkdir(parents=True)
(eng / "lib/wine/x86_64-unix").mkdir(parents=True)
(eng / "lib/external").mkdir(parents=True)
(eng / "lib/external/libd3dshared.dylib").write_bytes(b"dylib")
if shim:
- (eng / "lib/wine/x86_64-windows/nvngx-on-metalfx.dll").write_bytes(b"apple shim")
+ (eng / "lib/wine/x86_64-windows" / name).write_bytes(SHIM)
(eng / "bin").mkdir()
wine = eng / "bin/wine" # records its arguments instead of running Windows code
wine.write_text('#!/bin/sh\necho "$@" >> "$WINEPREFIX/wine-calls"\n'
@@ -38,8 +39,8 @@ class GptkDlssTests(unittest.TestCase):
(sys32 / "nvngx.dll").write_bytes(b"wine placeholder")
for _ in range(2): # the second run changes nothing
self.assertEqual(run(eng, prefix), 0)
- self.assertEqual((eng / "lib/wine/x86_64-windows/nvngx.dll").read_bytes(), b"apple shim")
- self.assertEqual((sys32 / "nvngx.dll").read_bytes(), b"apple shim")
+ self.assertEqual((eng / "lib/wine/x86_64-windows/nvngx.dll").read_bytes(), SHIM)
+ self.assertEqual((sys32 / "nvngx.dll").read_bytes(), SHIM)
so = eng / "lib/wine/x86_64-unix/nvngx.so"
# A copied unixlib looks for D3DMetal next to itself and aborts the process.
self.assertTrue(so.is_symlink())
@@ -58,6 +59,26 @@ class GptkDlssTests(unittest.TestCase):
self.assertEqual(run(eng, prefix), 0)
self.assertTrue((eng / "lib/wine/x86_64-unix/nvngx.so").is_symlink())
+ def test_a_payload_from_crossover_already_names_the_shim_nvngx(self):
+ with tempfile.TemporaryDirectory() as d:
+ eng = fake_engine(d, name="nvngx.dll")
+ prefix = Path(d) / "bottle"; prefix.mkdir()
+ (prefix / "system.reg").write_text("x\n")
+ sys32 = prefix / "drive_c/windows/system32"; sys32.mkdir(parents=True)
+ self.assertEqual(run(eng, prefix), 0)
+ self.assertEqual((sys32 / "nvngx.dll").read_bytes(), SHIM)
+ self.assertTrue((eng / "lib/wine/x86_64-unix/nvngx.so").is_symlink())
+
+ def test_an_nvngx_that_is_not_apples_is_left_alone(self):
+ with tempfile.TemporaryDirectory() as d:
+ eng = fake_engine(d, shim=False)
+ (eng / "lib/wine/x86_64-windows/nvngx.dll").write_bytes(b"wine placeholder")
+ prefix = Path(d) / "bottle"; prefix.mkdir()
+ (prefix / "system.reg").write_text("x\n")
+ self.assertEqual(run(eng, prefix), 1)
+ self.assertFalse((eng / "lib/wine/x86_64-unix/nvngx.so").exists())
+ self.assertFalse((prefix / "wine-calls").exists())
+
def test_without_apples_shim_nothing_is_touched(self):
with tempfile.TemporaryDirectory() as d:
eng = fake_engine(d, shim=False)
@@ -75,6 +96,8 @@ class GptkDlssTests(unittest.TestCase):
# It may start the bottle's wineserver; one started before WINEMSYNC=1 turns the launcher away.
call = text.index("dlss_on ;; esac")
self.assertLess(text.index("export WINEMSYNC=1"), call)
+ # ...and the Command-as-Ctrl keys are written only while no wineserver runs, so they go first.
+ self.assertLess(text.index('"LeftCommandIsCtrl"="y"'), call)
xbox = (ROOT / "scripts/xbox-wine.sh").read_text()
self.assertLess(xbox.index("WINEMSYNC"), xbox.index("gptk-dlss.sh"))
self.assertIn("D3DM_ENABLE_METALFX=1", xbox)