Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit
Swift apple-silicond3dmetaldxmtdxvkgame-porting-toolkitgptkmac-gamingmacosmetalfxrosetta-2steamsteam-playwinewinecx
fix(gamefix): run GTA V Legacy and the Rockstar Games Launcher on WineCX (#2114)
Gilang51707a6b669a
diff --git a/NOTICE b/NOTICEindex dca2954..4778cc4 100644--- a/NOTICE+++ b/NOTICE@@ -86,6 +86,13 @@ below for the current archive's name and sha256).All files above are in app/Sources/BridgeplayApp/Resources/. The engine's ntdllis patched at setup with detours built from ntdll-patch/ (detour*.bin in thesame folder). nvapi64-shim.dll is Bridgeplay's own code, built from nvapi-shim/.+version-rockstar-shim.dll is Bridgeplay's own code, built from rockstar-shim/.+dxgi-dxvk-macos-1.10.3.dll is x64/dxgi.dll from DXVK-macOS 1.10.3+(dxvk-macOS-async-v1.10.3-20230507.tar.gz from+https://github.com/Gcenx/DXVK-macOS/releases/tag/v1.10.3-20230507, sha256+f67d99d0a8eeedd7d406b283a3df9f939b5965acb00efcb33d0c6235c195a516), unmodified,+zlib/libpng license (Copyright (c) 2017-2021 Philip Rebohle, (c) 2019-2021+Joshua Ashton; LICENSE in that repository; the tarball carries no license text).Shipped in the one-click installer (Bridgeplay-Installer.zip)-------------------------------------------------------------diff --git a/app/Package.swift b/app/Package.swiftindex 1e49495..1757b37 100644--- a/app/Package.swift+++ b/app/Package.swift@@ -65,6 +65,8 @@ let package = Package(.copy("Resources/d3dx11_43-winecx-11.17-i386.dll"),.copy("Resources/d3dx11_42-winecx-11.17.dll"),.copy("Resources/d3dx11_42-winecx-11.17-i386.dll"),+ .copy("Resources/version-rockstar-shim.dll"),+ .copy("Resources/dxgi-dxvk-macos-1.10.3.dll"),.copy("Resources/libSDL2-2.0.0.dylib"),.copy("Resources/detour2-41073.bin"),.copy("Resources/detour32-41073.bin"),diff --git a/app/Sources/BridgeplayApp/Model/FreeEngineWinecx.swift b/app/Sources/BridgeplayApp/Model/FreeEngineWinecx.swiftindex 36e68fb..5ae09d7 100644--- a/app/Sources/BridgeplayApp/Model/FreeEngineWinecx.swift+++ b/app/Sources/BridgeplayApp/Model/FreeEngineWinecx.swift@@ -76,6 +76,10 @@ struct WinecxRelease: Sendable {// games that turn features off under Wine (hide-wine-exports-patch/,// NOTPROTON_HIDE_WINE_EXPORTS). Empty where the runtime's own are kept.let loader: [WinecxBundledFile]+ // rockstar-shim/: a version.dll the run script stages next to SocialClubHelper.exe and the+ // game for ROCKSTAR_SHIM=1 (GTA V Legacy), and DXVK's dxgi as dxgx.dll, which that shim+ // hands GTA5.exe on the dxvk backend. Empty where it is not shipped.+ let rockstar: [WinecxBundledFile]// The runner build this release unpacks to, keyed by its pinned loader, and the ntdll// detours for it (NtdllPatcher.byBuild).let runner: RunnerBuild@@ -225,6 +229,16 @@ enum FreeEngineWinecx {path: "lib/wine/x86_64-windows/kernelbase.dll",sha256: "4d55600b204724046567688ca96132e49e53af1baac7a362f3e2bf285f669a8a"),],+ // version.dll: rockstar-shim/build.sh. dxgx.dll: x64/dxgi.dll of DXVK-macOS+ // v1.10.3-20230507, whose d3d11.dll is byte-identical to the repack's above.+ rockstar: [+ WinecxBundledFile(resource: "version-rockstar-shim", ext: "dll",+ path: "lib/notproton-backends/rockstar-shim/x86_64-windows/version.dll",+ sha256: "deedb5d799330a3e274fe5cc7f569536280a2420543ef12145fcaa8fcbb7f6d4"),+ WinecxBundledFile(resource: "dxgi-dxvk-macos-1.10.3", ext: "dll",+ path: "lib/notproton-backends/rockstar-shim/x86_64-windows/dxgx.dll",+ sha256: "e74f5c985fe98f38f1a096258ef35d62e03a64df7096837965c7383e3cfe153d"),+ ],runner: RunnerBuild(bundleVersion: "winecx-11.17",releaseVersion: "WineCX 11.17",@@ -316,6 +330,7 @@ enum FreeEngineWinecx {audio: [],d3dx: [],loader: [],+ rockstar: [],// The hash-pinned loader is what makes it free, so a CrossOver install can never be// taken for it.runner: RunnerBuild(@@ -408,7 +423,7 @@ enum FreeEngineWinecx {// checks them, since they are either Wine's own or links into a Game Porting Toolkit.static func expectedFiles(_ release: WinecxRelease = current) -> [String: String] {var table: [String: String] = [FreeEngine.macDriverPath: release.macDriver]- for file in release.gamepad + release.network + release.nvidia + release.audio + release.d3dx + release.loader { table[file.path] = file.sha256 }+ for file in release.gamepad + release.network + release.nvidia + release.audio + release.d3dx + release.loader + release.rockstar { table[file.path] = file.sha256 }for file in release.backends { table["\(backendsPath)/\(file.destination)"] = file.sha256 }for path in release.renderer.files.keys {table[release.renderer.installPath(of: path)] = release.renderer.installedHash(of: path)@@ -497,7 +512,7 @@ enum FreeEngineWinecx {try fm.createDirectory(at: root.deletingLastPathComponent(), withIntermediateDirectories: true)try fm.moveItem(at: wine, to: root)try FreeEngine.installMacDriver(root: root, build: release.build, sha256: release.macDriver, step: step)- try installBundled(release.gamepad + release.network + release.nvidia + release.audio + release.d3dx + release.loader, root: root)+ try installBundled(release.gamepad + release.network + release.nvidia + release.audio + release.d3dx + release.loader + release.rockstar, root: root)let libraries = wine.deletingLastPathComponent()for file in release.backends {diff --git a/app/Sources/BridgeplayApp/Resources/dxgi-dxvk-macos-1.10.3.dll b/app/Sources/BridgeplayApp/Resources/dxgi-dxvk-macos-1.10.3.dllnew file mode 100755index 0000000..554d8c2Binary files /dev/null and b/app/Sources/BridgeplayApp/Resources/dxgi-dxvk-macos-1.10.3.dll differdiff --git a/app/Sources/BridgeplayApp/Resources/version-rockstar-shim.dll b/app/Sources/BridgeplayApp/Resources/version-rockstar-shim.dllnew file mode 100755index 0000000..83a5bbdBinary files /dev/null and b/app/Sources/BridgeplayApp/Resources/version-rockstar-shim.dll differdiff --git a/app/Tests/BridgeplayAppTests/FreeEngineWinecxTests.swift b/app/Tests/BridgeplayAppTests/FreeEngineWinecxTests.swiftindex d4670f4..815cf10 100644--- a/app/Tests/BridgeplayAppTests/FreeEngineWinecxTests.swift+++ b/app/Tests/BridgeplayAppTests/FreeEngineWinecxTests.swift@@ -275,6 +275,24 @@ struct FreeEngineWinecxTests {}}+ // rockstar-shim: 11.17 ships the shim and DXVK's dxgi beside the backends, outside any+ // backend folder the run script stages into system32.+ @Test("rockstar-shim ships with the app and is pinned for 11.17",+ arguments: FreeEngineWinecx.releases.map(\.build))+ func rockstar(id: String) throws {+ let release = try #require(FreeEngineWinecx.release(build: id))+ let expected: Set<String> = release.build == "winecx-11.17"+ ? ["lib/notproton-backends/rockstar-shim/x86_64-windows/version.dll",+ "lib/notproton-backends/rockstar-shim/x86_64-windows/dxgx.dll"] : []+ #expect(Set(release.rockstar.map(\.path)) == expected)+ let table = FreeEngineWinecx.expectedFiles(release)+ for file in release.rockstar {+ let bundled = try #require(Bundle.module.url(forResource: file.resource, withExtension: file.ext))+ #expect(Digest.sha256IfPresent(bundled) == file.sha256, "\(file.resource)")+ #expect(table[file.path] == file.sha256, "\(file.path)")+ }+ }+@Test("Each free engine is current, outdated or missing on its own pins")func perEngineState() throws {let winehqBuild = try #require(SupportedRunners.build(id: FreeEngine.current.build))diff --git a/docs/GAMEFIXES.md b/docs/GAMEFIXES.mdindex c8c5c65..423a80d 100644--- a/docs/GAMEFIXES.md+++ b/docs/GAMEFIXES.md@@ -58,6 +58,7 @@ logged, when:| `STDOUT_NULL` | `0`, `1` | `1` starts the game without a stdout handle, as Steam on Windows does. Source 2 treats any stdout as a console build (`Plat_IsConsoleApplication`) and then skips NGX, so Deadlock offers no DLSS || `VSYNC` | `0`, `1` | `1` makes the game's Metal layer wait for the display even when the game turns vsync off, like forcing vsync in the NVIDIA control panel. For games that lock vsync off with frame generation on (Resident Evil Requiem) and tear above the refresh rate || `HIDE_WINE_EXPORTS` | `0`, `1` | `1` makes `GetProcAddress` fail for ntdll's `wine_*` exports on the WineCX 11.17 engine (`hide-wine-exports-patch/`), like Wine Staging's `HideWineExports`. For games that turn features off under Wine: The Witcher 3 5.0 skips NVIDIA Streamline, so no DLSS |+| `ROCKSTAR_SHIM` | `0`, `1` | `1` stages `rockstar-shim/`'s `version.dll` next to `SocialClubHelper.exe` (`C:\Program Files\Rockstar Games\Social Club`) and next to the game's exe at the game launch, and adds `version=n,b`. It makes the Rockstar Games Launcher's CEF windows draw on winemac and, on `dxvk`, gives GTA5.exe DXVK's dxgi instead of D3DMetal's (`NOTPROTON_ROCKSTAR_DXGI`). A `version.dll` the folder already had (a mod loader) is moved to `version.dll.bridgeplay-orig` first. Without the key, or on an engine without the shim, staged copies are removed and that file is put back. WineCX 11.17 only; GTA V Legacy's `gamefixes/271590.conf` sets it. Details in `rockstar-shim/README.md` || `DXMT_*`, `DXVK_*`, `MVK_*`, `VKD3D_*`, `D3DM_*`, `STAGING_*` | any | Exported as is || `MTL_HUD_ENABLED`, `WINEDEBUG`, `WINE_LARGE_ADDRESS_AWARE`, `WINE_CPU_TOPOLOGY` | any | Exported as is || `CX_FWD_COMPAT_GL_CTX` | any | Exported as is: WineCX's switch for forward-compatible OpenGL contexts, for testing OpenGL (`wined3d`) games |diff --git a/docs/WINECX.md b/docs/WINECX.mdindex 0fd71d8..3778fbd 100644--- a/docs/WINECX.md+++ b/docs/WINECX.md@@ -449,6 +449,8 @@ rebuilt Mach-O file needs its line there updated too; `SignedPinTests` fails unt| `d3dx11_43-winecx-11.17-i386.dll` | `d3dx11-patch/` | `dd4dd351f2a5880c9848d5ccf4944a0b5e7622bb7fb196544115b1f9c92d749c` | `FreeEngineWinecx.v1117.d3dx` || `d3dx11_42-winecx-11.17.dll` | `d3dx11-patch/` | `3d97e1de9000a78e27eb5c90d0ab9b36d54fd350760063da27226d22c90c8e1b` | `FreeEngineWinecx.v1117.d3dx` || `d3dx11_42-winecx-11.17-i386.dll` | `d3dx11-patch/` | `85075f8b4f30f1a993238a0d6ab772a3a3df6c031e87ee9401c4367a527cd57c` | `FreeEngineWinecx.v1117.d3dx` |+| `version-rockstar-shim.dll` | `rockstar-shim/` | `deedb5d799330a3e274fe5cc7f569536280a2420543ef12145fcaa8fcbb7f6d4` | `FreeEngineWinecx.v1117.rockstar` |+| `dxgi-dxvk-macos-1.10.3.dll` | DXVK-macOS v1.10.3-20230507 `x64/dxgi.dll`, unmodified | `e74f5c985fe98f38f1a096258ef35d62e03a64df7096837965c7383e3cfe153d` | `FreeEngineWinecx.v1117.rockstar` || `winemac-winecx-11.17.so` | `winemac-patch/winecx-11.17-d3dmetal-retina.patch` | `aa192f846ad15d56de200fc92752eaf2d455700846ae2cf1ccc7b27b535f1c00` | `FreeEngineWinecx.v1117.macDriver` || `winebus-winecx-11.17.so` | Controllers (SDL2 build) | `6223c035c824c90708abbc3e733f8d1d6ed6b8b4e9a3e1a5c813493ceba50473` | `FreeEngineWinecx.v1117.gamepad` || `winebus-winecx-11.17.sys` | `winebus-patch/` | `da108d1c3788fa32807ef08c4d26d8a89812c230317ffa7ba5111e126bda607c` | `FreeEngineWinecx.v1117.gamepad` |diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.shindex 5e60550..930bc90 100755--- a/dylib/feats/compat_run.sh+++ b/dylib/feats/compat_run.sh@@ -384,6 +384,7 @@ gamefix_msync=""gamefix_nvapi=""gamefix_dlss_fg=""gamefix_args=""+gamefix_rockstar_shim=""gamefix_log() {echo "gamefix: $*" >> "$log" 2>&1 || true@@ -414,7 +415,7 @@ gamefix_reason() {case "$1" inBACKEND)case "$2" in dxmt|dxvk|wined3d|d3dmetal) ;; *) echo "not dxmt, dxvk, wined3d or d3dmetal" ;; esac ;;- MSYNC|RETINA|NVAPI|DLSS_FG|STDOUT_NULL|VSYNC|HIDE_WINE_EXPORTS|FRAMEGEN_UI|FRAMEGEN_FALLBACK|STEAMDECK)+ MSYNC|RETINA|NVAPI|DLSS_FG|STDOUT_NULL|VSYNC|HIDE_WINE_EXPORTS|FRAMEGEN_UI|FRAMEGEN_FALLBACK|STEAMDECK|ROCKSTAR_SHIM)case "$2" in 0|1) ;; *) echo "not 0 or 1" ;; esac ;;FRAMEGEN)# 1 is the 2x of the first release.@@ -504,6 +505,7 @@ load_gamefixes() {MSYNC) gamefix_msync=$value; gamefix_log "MSYNC=$value from the $from conf" ;;NVAPI) gamefix_nvapi=$value; gamefix_log "NVAPI=$value from the $from conf" ;;DLSS_FG) gamefix_dlss_fg=$value; gamefix_log "DLSS_FG=$value from the $from conf" ;;+ ROCKSTAR_SHIM) gamefix_rockstar_shim=$value; gamefix_log "ROCKSTAR_SHIM=$value from the $from conf" ;;STDOUT_NULL) gamefix_apply_env NOTPROTON_STDOUT_NULL "$value" "$from" ;;VSYNC) gamefix_apply_env NOTPROTON_VSYNC "$value" "$from" ;;HIDE_WINE_EXPORTS) gamefix_apply_env NOTPROTON_HIDE_WINE_EXPORTS "$value" "$from" ;;@@ -583,8 +585,9 @@ managed_dlls() {printf '%s\n' dxgi d3d11 d3d10core! d3dmetal_engine || printf '%s\n' d3d10 d3d12for dir in "$backend_root"/*/x86_64-windows "$backend_root"/*/i386-windows; do- # nvapi-shim is not a Direct3D backend; its nvapi64 is handled with NVAPI below.- case "$dir" in "$backend_root"/wine-stock/*|"$backend_root"/nvapi-shim/*) continue ;; esac+ # nvapi-shim and rockstar-shim are not Direct3D backends; their DLLs are handled with+ # NVAPI and ROCKSTAR_SHIM below.+ case "$dir" in "$backend_root"/wine-stock/*|"$backend_root"/nvapi-shim/*|"$backend_root"/rockstar-shim/*) continue ;; esac[ ! -d "$dir" ] || backend_dlls "$dir"done} | sort -u@@ -790,7 +793,7 @@ restore_stock_dll() {[ -f "$stock" ] && [ ! -L "$stock" ] || return 0! cmp -s "$stock" "$3" || return 0for theirs in "$backend_root"/*/"$1"/*.[dD][lL][lL]; do- case "$theirs" in "$backend_root"/wine-stock/*|"$backend_root"/nvapi-shim/*) continue ;; esac+ case "$theirs" in "$backend_root"/wine-stock/*|"$backend_root"/nvapi-shim/*|"$backend_root"/rockstar-shim/*) continue ;; esac[ -f "$theirs" ] || continuebase=${theirs##*/}[ "$(printf '%s' "${base%.*}" | tr '[:upper:]' '[:lower:]')" = "$2" ] || continue@@ -906,6 +909,96 @@ activate_backend() {fi}+# A copy some launch staged, from this engine's shim or another engine's build: every build+# carries the "rockstar-shim: " log prefix, which no other version.dll has.+rockstar_shim_copy() {+ [ -f "$2" ] && [ ! -L "$2" ] || return 1+ cmp -s "$1" "$2" || LC_ALL=C grep -qaF 'rockstar-shim: ' "$2"+}++# Stages, removes or restores version.dll in Social Club and the game folder. The lock is per+# macOS user, on the boot volume, so it works whatever volume the game is on.+rockstar_shim_folders() {+ (+ exec 6>> "$np_support/.rockstar-shim.lock" && /usr/bin/lockf -s -t 30 6 || exit 1+ for dir in "$social_club" "${STEAM_COMPAT_INSTALL_PATH:-}"; do+ [ -n "$dir" ] && [ -d "$dir" ] || continue+ target="$dir/version.dll"+ saved="$dir/version.dll.bridgeplay-orig"+ if [ "$shim_wanted" = 1 ]; then+ moved=0+ if { [ -e "$target" ] || [ -L "$target" ]; } && ! rockstar_shim_copy "$shim/version.dll" "$target"; then+ if [ -e "$saved" ] || [ -L "$saved" ]; then+ graphics_log "rockstar-shim: $dir has its own version.dll and a version.dll.bridgeplay-orig, both left alone"+ continue+ fi+ # The backup name is claimed with an exclusive create, so of two macOS users'+ # launches sharing this folder only one moves the file there.+ if ! (set -C; : > "$saved") 2>/dev/null; then+ graphics_log "rockstar-shim: could not set aside the version.dll in $dir, left alone"+ continue+ fi+ if ! mv -f "$target" "$saved" 2>> "$log"; then+ rm -f "$saved"+ graphics_log "rockstar-shim: could not set aside the version.dll in $dir, left alone"+ continue+ fi+ moved=1+ graphics_log "rockstar-shim: moved the version.dll in $dir to version.dll.bridgeplay-orig"+ fi+ if ! stage_backend_file "$shim/version.dll" "$target"; then+ graphics_log "rockstar-shim: could not stage version.dll into $dir"+ [ "$moved" = 0 ] || mv "$saved" "$target" 2>> "$log" || true+ fi+ continue+ fi+ if rockstar_shim_copy "$shim/version.dll" "$target"; then+ rm -f "$target" 2>> "$log" && graphics_log "rockstar-shim: removed version.dll from $dir"+ fi+ if [ -e "$saved" ] || [ -L "$saved" ]; then+ if [ -e "$target" ] || [ -L "$target" ]; then+ graphics_log "rockstar-shim: $dir has a new version.dll, version.dll.bridgeplay-orig left alone"+ elif mv "$saved" "$target" 2>> "$log"; then+ graphics_log "rockstar-shim: put the version.dll in $dir back"+ fi+ fi+ done+ exit 0+ )+}++# Rockstar Games Launcher and GTA V Legacy (ROCKSTAR_SHIM=1, rockstar-shim/): a version.dll+# next to SocialClubHelper.exe makes the launcher's CEF windows draw on winemac, and the one+# next to the game hands GTA5.exe DXVK's dxgi on the dxvk backend. The game folder only ever+# gets version.dll. A version.dll of the game's own (a mod loader) is moved to+# version.dll.bridgeplay-orig first. Without the key, or on an engine without the shim, the+# staged copy is removed and that file put back.+stage_rockstar_shim() {+ shim="$backend_root/rockstar-shim/x86_64-windows"+ social_club="$WINEPREFIX/drive_c/Program Files/Rockstar Games/Social Club"+ shim_wanted=0+ if [ "$gamefix_rockstar_shim" = 1 ] && [ "$verb" = waitforexitandrun ]; then+ [ ! -f "$shim/version.dll" ] || shim_wanted=1+ elif [ "$gamefix_rockstar_shim" = 1 ]; then+ # Helpers (verb run) leave the game's files as they are.+ return 0+ fi+ # Launches that share a folder (two prefixes on one game) take turns, so one cannot undo+ # a move or a restore the other is making.+ rockstar_shim_folders || graphics_log "rockstar-shim: could not take the lock, version.dll left as it is"+ if [ "$shim_wanted" = 0 ]; then+ [ "$gamefix_rockstar_shim" != 1 ] || graphics_log "rockstar-shim: not in this engine, ROCKSTAR_SHIM=1 does nothing"+ return 0+ fi+ gamefix_dlloverrides="${gamefix_dlloverrides:+$gamefix_dlloverrides;}version=n,b"+ # dxgx.dll is DXVK's dxgi under a name the backend's dxgi=b does not cover.+ if [ "$backend" = dxvk ] && [ -f "$shim/dxgx.dll" ]; then+ NOTPROTON_ROCKSTAR_DXGI="Z:$(printf '%s' "$shim/dxgx.dll" | tr / '\134')"+ export NOTPROTON_ROCKSTAR_DXGI+ graphics_log "rockstar-shim: GTA5.exe gets DXVK's dxgi"+ fi+}+record_backend() {[ -n "$STEAM_COMPAT_DATA_PATH" ] || return 0record="$STEAM_COMPAT_DATA_PATH/notproton-backend"@@ -2539,6 +2632,7 @@ stage_step="graphics backend"select_backend "$1"activate_backend || truerecord_backend || true+stage_rockstar_shim || true# An engine without lib/notproton-backends (CrossOver) picks its graphics itself, from# CX_GRAPHICS_BACKEND, so the log names that choice, not the dxmt-builtin placeholder.if [ "$backend" = dxmt-builtin ]; then@@ -3006,7 +3100,7 @@ elseecho "=== client staged no overlay renderer, overlay disabled ===" >> "$log" 2>&1 || truefiset -- --args "$shim_exe" "$@"-for name in $(env | LC_ALL=C sed -nE 's/^(CX_APPLEGPTK_LIBD3DSHARED_PATH|SDL_GAMECONTROLLERCONFIG(_FILE)?|SDL_JOYSTICK_MFI|WINE_LARGE_ADDRESS_AWARE|WINE_CPU_TOPOLOGY|CX_FWD_COMPAT_GL_CTX|Steam[A-Za-z0-9]*|(CX_GRAPHICS|D3DM_|DXMT_|DXVK_|FEX_|MVK_|VKD3D_|STAGING_|MTL_|ROSETTA_)[A-Z0-9_]*|NOTPROTON_FRAMEGEN(_[A-Z]+)?|NOTPROTON_NGX_SIGNER|NOTPROTON_NVAPI_DRIVER|NOTPROTON_DRIVER_VERSION|NOTPROTON_STDOUT_NULL|NOTPROTON_VSYNC|NOTPROTON_HIDE_WINE_EXPORTS|CX_ACTIVE_GRAPHICS_BACKEND)=.*/\1/p'); do+for name in $(env | LC_ALL=C sed -nE 's/^(CX_APPLEGPTK_LIBD3DSHARED_PATH|SDL_GAMECONTROLLERCONFIG(_FILE)?|SDL_JOYSTICK_MFI|WINE_LARGE_ADDRESS_AWARE|WINE_CPU_TOPOLOGY|CX_FWD_COMPAT_GL_CTX|Steam[A-Za-z0-9]*|(CX_GRAPHICS|D3DM_|DXMT_|DXVK_|FEX_|MVK_|VKD3D_|STAGING_|MTL_|ROSETTA_)[A-Z0-9_]*|NOTPROTON_FRAMEGEN(_[A-Z]+)?|NOTPROTON_NGX_SIGNER|NOTPROTON_NVAPI_DRIVER|NOTPROTON_DRIVER_VERSION|NOTPROTON_STDOUT_NULL|NOTPROTON_VSYNC|NOTPROTON_HIDE_WINE_EXPORTS|NOTPROTON_ROCKSTAR_DXGI|CX_ACTIVE_GRAPHICS_BACKEND)=.*/\1/p'); doeval "value=\$$name"# shellcheck disable=SC2154 # eval assigns value on the line aboveset -- --env "$name=$value" "$@"diff --git a/dylib/tests/gamefixescheck.sh b/dylib/tests/gamefixescheck.shindex 4b1a22c..8a3e089 100644--- a/dylib/tests/gamefixescheck.sh+++ b/dylib/tests/gamefixescheck.sh@@ -8,7 +8,7 @@ functions=""for name in gamefix_log valid_dll_overrides gamefix_reason gamefix_read gamefix_apply_env \load_gamefixes resolve_msync graphics_log d3dmetal_engine backend_dlls managed_dlls backend_available \backend_record pe_word pe_words pe_rva_offset imports_d3d12 select_backend stage_backend_file restore_stock_dll \- activate_backend record_backend compose_dll_overrides; do+ activate_backend record_backend rockstar_shim_copy rockstar_shim_folders stage_rockstar_shim compose_dll_overrides; dobody=$(sed -n "/^$name() {\$/,/^}\$/p" "$SRC")[ -n "$body" ] || { echo "FAIL: $name not found in $SRC"; exit 1; }functions="$functions@@ -103,7 +103,7 @@ launch() {sh -ec 'eval "$public_names"eval "$functions"- gamefix_keys="" gamefix_backend="" gamefix_dlloverrides="" gamefix_msync="" gamefix_nvapi="" gamefix_dlss_fg="" gamefix_args=""+ gamefix_keys="" gamefix_backend="" gamefix_dlloverrides="" gamefix_msync="" gamefix_nvapi="" gamefix_dlss_fg="" gamefix_args="" gamefix_rockstar_shim=""backend_root="$CX_ROOT/lib/notproton-backends"load_gamefixes || trueresolve_msync@@ -111,12 +111,13 @@ launch() {select_backend "$1"activate_backend || truerecord_backend || true+ stage_rockstar_shim || truegraphics_log "backend=$backend ($backend_from)"compose_dll_overrideseval "$bridge_line"for v in backend WINEDLLOVERRIDES WINEMSYNC msync_from NOTPROTON_RETINA NOTPROTON_FRAMEGEN \NOTPROTON_FRAMEGEN_QUALITY NOTPROTON_FRAMEGEN_UI NOTPROTON_FRAMEGEN_FALLBACK NOTPROTON_FRAMEGEN_ENGINE CX_GRAPHICS_BACKEND \- DXVK_HUD VKD3D_CONFIG WINEDEBUG MTL_HUD_ENABLED D3DM_VENDOR_ID D3DM_DEVICE_ID D3DM_DEVICE_DESCRIPTION NOTPROTON_NGX_SIGNER NOTPROTON_DRIVER_VERSION CX_ACTIVE_GRAPHICS_BACKEND NOTPROTON_VSYNC NOTPROTON_HIDE_WINE_EXPORTS CX_FWD_COMPAT_GL_CTX gamefix_args PATH DYLD_INSERT_LIBRARIES; do+ DXVK_HUD VKD3D_CONFIG WINEDEBUG MTL_HUD_ENABLED D3DM_VENDOR_ID D3DM_DEVICE_ID D3DM_DEVICE_DESCRIPTION NOTPROTON_NGX_SIGNER NOTPROTON_DRIVER_VERSION CX_ACTIVE_GRAPHICS_BACKEND NOTPROTON_VSYNC NOTPROTON_HIDE_WINE_EXPORTS NOTPROTON_ROCKSTAR_DXGI CX_FWD_COMPAT_GL_CTX gamefix_args PATH DYLD_INSERT_LIBRARIES; doeval "printf \"%s=%s\\n\" \$v \"\${$v-<unset>}\""done' launch "$target" > "$case_dir/out" 2>&1 || bad "the launch sequence ran to the end" "exit 0" "exit $? $(tail -1 "$case_dir/out")"@@ -692,6 +693,162 @@ launch waitforexitandrun "$case_dir/game/game.exe"is "a global d3dmetal on an engine without it falls back" "dxmt" "$(got backend)"has "the fallback names the global layer" "BACKEND in the global conf, fell back from d3dmetal" "$case_dir/log"+echo "== ROCKSTAR_SHIM stages rockstar-shim/ next to Social Club and the game"+rockstar_case() {+ new_case+ full_engine+ engine rockstar-shim/x86_64-windows/version.dll rockstar-shim/x86_64-windows/dxgx.dll+ mkdir -p "$case_dir/data/pfx/drive_c/Program Files/Rockstar Games/Social Club"+ shim_src="$case_dir/engine/lib/notproton-backends/rockstar-shim/x86_64-windows"+ # Every build carries its log prefix, which is how a copy from another engine is known.+ printf 'MZ this build rockstar-shim: DXVK dxgi is dxgi.dll\n' > "$shim_src/version.dll"+ social="$case_dir/data/pfx/drive_c/Program Files/Rockstar Games/Social Club"+}+# The run script reads the game folder from STEAM_COMPAT_INSTALL_PATH.+rockstar_launch() {+ launch "$@" STEAM_COMPAT_INSTALL_PATH="$case_dir/game"+}+rockstar_case+user_conf 'BACKEND=dxvk' 'ROCKSTAR_SHIM=1'+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"+is "version.dll is staged next to SocialClubHelper.exe" "yes" \+ "$(cmp -s "$shim_src/version.dll" "$social/version.dll" && echo yes || echo no)"+is "version.dll is staged next to the game" "yes" \+ "$(cmp -s "$shim_src/version.dll" "$case_dir/game/version.dll" && echo yes || echo no)"+is "only version.dll goes into the game folder" "no" "$([ -e "$case_dir/game/dxgx.dll" ] && echo yes || echo no)"+case "$(got WINEDLLOVERRIDES)" in *';version=n,b'*) v=yes ;; *) v=no ;; esac+is "version=n,b is added to the overrides" "yes" "$v"+case "$(got WINEDLLOVERRIDES)" in *dxgx*|*'version=b'*) v=yes ;; *) v=no ;; esac+is "rockstar-shim's DLLs are not treated as backend DLLs" "no" "$v"+case "$(got NOTPROTON_ROCKSTAR_DXGI)" in "Z:\\"*"\\rockstar-shim\\x86_64-windows\\dxgx.dll") v=yes ;; *) v=no ;; esac+is "on dxvk GTA5.exe is pointed at DXVK's dxgi" "yes" "$v"+is "system32 gets no version.dll" "no" "$([ -e "$case_dir/data/pfx/drive_c/windows/system32/version.dll" ] && echo yes || echo no)"++user_conf 'BACKEND=dxvk'+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"+is "without the key the staged copy leaves Social Club" "no" "$([ -e "$social/version.dll" ] && echo yes || echo no)"+is "without the key the staged copy leaves the game folder" "no" "$([ -e "$case_dir/game/version.dll" ] && echo yes || echo no)"+case "$(got WINEDLLOVERRIDES)" in *version=*) v=yes ;; *) v=no ;; esac+is "without the key version is not overridden" "no" "$v"++is "no backup is made when the game had no version.dll" "no" \+ "$([ -e "$case_dir/game/version.dll.bridgeplay-orig" ] && echo yes || echo no)"++rockstar_case+printf 'a game of its own\n' > "$case_dir/game/version.dll"+user_conf 'BACKEND=dxvk'+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"+is "a version.dll that is not the shim is left alone" "a game of its own" "$(cat "$case_dir/game/version.dll")"++echo "== ROCKSTAR_SHIM keeps a version.dll the game already had"+rockstar_case+printf 'a mod loader\n' > "$case_dir/game/version.dll"+user_conf 'BACKEND=dxvk' 'ROCKSTAR_SHIM=1'+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"+is "the game's own version.dll is set aside" "a mod loader" "$(cat "$case_dir/game/version.dll.bridgeplay-orig" 2>/dev/null)"+is "and the shim takes its place" "yes" \+ "$(cmp -s "$shim_src/version.dll" "$case_dir/game/version.dll" && echo yes || echo no)"+has "the move is logged" "moved the version.dll in $case_dir/game to version.dll.bridgeplay-orig" "$case_dir/log"+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"+is "a second launch keeps the backup" "a mod loader" "$(cat "$case_dir/game/version.dll.bridgeplay-orig" 2>/dev/null)"+user_conf 'BACKEND=dxvk'+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"+is "without the key the game's own version.dll is back" "a mod loader" "$(cat "$case_dir/game/version.dll")"+is "and the backup is gone" "no" "$([ -e "$case_dir/game/version.dll.bridgeplay-orig" ] && echo yes || echo no)"++rockstar_case+printf 'a mod loader\n' > "$case_dir/game/version.dll"+user_conf 'BACKEND=dxvk' 'ROCKSTAR_SHIM=1'+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"+rm -rf "$case_dir/engine/lib/notproton-backends/rockstar-shim"+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"+is "on an engine without the shim the game's own version.dll is back" "a mod loader" "$(cat "$case_dir/game/version.dll")"+is "and the backup is gone too" "no" "$([ -e "$case_dir/game/version.dll.bridgeplay-orig" ] && echo yes || echo no)"++rockstar_case+printf 'a mod loader\n' > "$case_dir/game/version.dll"+user_conf 'BACKEND=dxvk' 'ROCKSTAR_SHIM=1'+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"+printf 'a newer mod loader\n' > "$case_dir/game/version.dll"+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"+is "a version.dll put in after the backup is not replaced" "a newer mod loader" "$(cat "$case_dir/game/version.dll")"+is "nor is the backup" "a mod loader" "$(cat "$case_dir/game/version.dll.bridgeplay-orig" 2>/dev/null)"+user_conf 'BACKEND=dxvk'+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"+is "without the key both stay" "a newer mod loader|a mod loader" \+ "$(cat "$case_dir/game/version.dll")|$(cat "$case_dir/game/version.dll.bridgeplay-orig" 2>/dev/null)"++rockstar_case+printf 'a mod loader\n' > "$case_dir/game/version.dll"+user_conf 'BACKEND=dxvk' 'ROCKSTAR_SHIM=1'+rockstar_launch run "$case_dir/game/game.exe"+is "helpers (verb run) do not move the game's own version.dll" "a mod loader" "$(cat "$case_dir/game/version.dll")"++rockstar_case+printf 'a mod loader\n' > "$case_dir/game/version.dll"+chmod 555 "$case_dir/game"+user_conf 'BACKEND=dxvk' 'ROCKSTAR_SHIM=1'+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"+chmod 755 "$case_dir/game"+is "a folder the backup cannot go into keeps its own version.dll" "a mod loader|no" \+ "$(cat "$case_dir/game/version.dll")|$([ -e "$case_dir/game/version.dll.bridgeplay-orig" ] && echo yes || echo no)"+has "and says so" "could not set aside the version.dll in $case_dir/game, left alone" "$case_dir/log"++# Another launch holds the lock for two seconds and notes the game folder as it lets go.+rockstar_case+printf 'a mod loader\n' > "$case_dir/game/version.dll"+user_conf 'BACKEND=dxvk' 'ROCKSTAR_SHIM=1'+/usr/bin/lockf -k "$case_dir/support/.rockstar-shim.lock" \+ sh -c 'sleep 2; cat "$1" > "$2"' sh "$case_dir/game/version.dll" "$case_dir/held" &+holder=$!+sleep 0.5+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"+wait "$holder"+is "a launch leaves the folder alone while another holds the lock" "a mod loader" "$(cat "$case_dir/held" 2>/dev/null)"+is "and stages the shim once it is free" "yes|a mod loader" \+ "$(cmp -s "$shim_src/version.dll" "$case_dir/game/version.dll" && echo yes || echo no)|$(cat "$case_dir/game/version.dll.bridgeplay-orig" 2>/dev/null)"++echo "== ROCKSTAR_SHIM removes a copy another engine staged"+rockstar_case+printf 'MZ older build rockstar-shim: CEF browser composites in process\n' > "$social/version.dll"+cp "$social/version.dll" "$case_dir/game/version.dll"+user_conf 'BACKEND=dxvk' 'ROCKSTAR_SHIM=1'+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"+is "an older shim build is updated, not backed up" "yes|no" \+ "$(cmp -s "$shim_src/version.dll" "$case_dir/game/version.dll" && echo yes || echo no)|$([ -e "$case_dir/game/version.dll.bridgeplay-orig" ] && echo yes || echo no)"+rockstar_case+printf 'MZ older build rockstar-shim: CEF browser composites in process\n' > "$social/version.dll"+cp "$social/version.dll" "$case_dir/game/version.dll"+rm -rf "$case_dir/engine/lib/notproton-backends/rockstar-shim"+user_conf 'BACKEND=dxvk' 'ROCKSTAR_SHIM=1'+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"+is "an engine without the shim removes the copy in Social Club" "no" "$([ -e "$social/version.dll" ] && echo yes || echo no)"+is "and the copy in the game folder" "no" "$([ -e "$case_dir/game/version.dll" ] && echo yes || echo no)"+rockstar_case+printf 'MZ older build rockstar-shim: CEF browser composites in process\n' > "$case_dir/game/version.dll"+user_conf 'BACKEND=dxvk'+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"+is "without the key an older shim build is removed" "no" "$([ -e "$case_dir/game/version.dll" ] && echo yes || echo no)"++rockstar_case+user_conf 'BACKEND=dxmt' 'ROCKSTAR_SHIM=1'+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"+is "off dxvk there is no DXVK dxgi to hand over" "<unset>" "$(got NOTPROTON_ROCKSTAR_DXGI)"+is "off dxvk the CEF fix is still staged" "yes" "$([ -e "$social/version.dll" ] && echo yes || echo no)"++rockstar_case+user_conf 'BACKEND=dxvk' 'ROCKSTAR_SHIM=1'+rockstar_launch run "$case_dir/game/game.exe"+is "helpers (verb run) stage nothing" "no" "$([ -e "$social/version.dll" ] && echo yes || echo no)"++new_case+full_engine+user_conf 'BACKEND=dxvk' 'ROCKSTAR_SHIM=1'+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"+has "an engine without rockstar-shim says so" "rockstar-shim: not in this engine" "$case_dir/log"+case "$(got WINEDLLOVERRIDES)" in *version=*) v=yes ;; *) v=no ;; esac+is "and adds no override" "no" "$v"+if [ "$fails" -eq 0 ]; thenecho "==> gamefixescheck: all assertions hold"elsediff --git a/gamefixes/271590.conf b/gamefixes/271590.confnew file mode 100644index 0000000..8866c55--- /dev/null+++ b/gamefixes/271590.conf@@ -0,0 +1,10 @@+# Grand Theft Auto V Legacy (271590)+# Evidence: test run on WineCX 11.17, Apple M2, macOS 27.2, 2026-11-01. The Rockstar Games Launcher's+# Direct2D needs DXGID3D10CreateDevice, which D3DMetal's dxgi lacks ("failed to initialize"); DXMT+# crashes it and wined3d fails the same way, so the game runs on DXVK. ROCKSTAR_SHIM=1 (rockstar-shim/)+# makes the launcher's CEF windows draw and hands GTA5.exe DXVK's dxgi.+# BattlEye (GTA5_BE.exe) needs a Windows kernel driver and stops at "Updating...". -nobattleye starts+# GTA5.exe without it: story mode only, GTA Online needs BattlEye.+BACKEND=dxvk+ROCKSTAR_SHIM=1+ARGS=-nobattleyediff --git a/rockstar-shim/.gitignore b/rockstar-shim/.gitignorenew file mode 100644index 0000000..c6d5d19--- /dev/null+++ b/rockstar-shim/.gitignore@@ -0,0 +1 @@+version.dlldiff --git a/rockstar-shim/README.md b/rockstar-shim/README.mdnew file mode 100644index 0000000..a189159--- /dev/null+++ b/rockstar-shim/README.md@@ -0,0 +1,64 @@+# rockstar-shim++`version.dll` for the Rockstar Games Launcher and GTA V Legacy, staged by the run script when a+game's conf says `ROCKSTAR_SHIM=1` (`gamefixes/271590.conf`). It goes next to+`SocialClubHelper.exe` (`C:\Program Files\Rockstar Games\Social Club`) and next to the game's+exe, never into `system32`, and the run script adds `version=n,b`. Every export forwards to+kernelbase/kernel32. `DllMain` acts in two processes and nowhere else.++A `version.dll` already in either folder is moved to `version.dll.bridgeplay-orig` and put back+when the key is off or the engine has no shim. The run script knows a staged copy, from this+build or another engine's, by the `rockstar-shim: ` prefix of its log messages, so keep that+string in every build.++## SocialClubHelper.exe: blank launcher windows++The launcher's windows (sign-in, main window, error pages) are CEF child windows owned by the+CEF browser process, while Chromium's GPU/viz process paints them. A `WINEDEBUG=+win` trace+showed the other process calling `NtUserGetDCEx` on the browser's `Chrome_WidgetWin_1` hundreds+of times; on winemac a process cannot draw into another process's window, so the windows stay+blank (macOS reports them on screen, alpha 1). The shim appends+`--in-process-gpu --disable-gpu --disable-gpu-compositing --disable-software-rasterizer` to the+browser process's command line (not to `--type=` subprocesses), so it composites in software+into its own window. `--in-process-gpu` alone crashed the browser when ANGLE failed in process+("Main browser connection lost", launcher code 161). Without `--disable-software-rasterizer`+(the switch Social Club's own `-scNoSoftwareRasterizer` adds) the in-process GPU thread still+starts SwiftShader, and about one launch in seven never created the browser window ("Timed+out waiting for browser window"); with it, 6 of 6 did, in about 5 s.++Wine's kernelbase keeps its own copy of the command line: `GetCommandLineW` is+`mov rax, [rip+disp32]; ret` reading `command_lineW`. The shim points that variable at the new+string as well, and leaves it alone if the instruction pattern differs.++The launcher starts CEF with the game folder as working directory. `SetDllDirectoryW(L"")`+keeps a d3d11 or dxgi in that folder out of CEF's DLL search; without it CEF loaded one and+timed out ("timed out loading both its online and offline content").++## GTA5.exe: DXVK's dxgi++On WineCX with D3DMetal enabled, the dxvk backend's `dxgi=b` gave GTA5.exe CrossOver's D3DMetal+dxgi (a 16 MB `PE-Wine` module in `winedbg`'s `info share`, beside DXVK's d3d11 and the+`d3dmetal` Mach-O). The DXVK repack ships no dxgi. GTA V creates its own DXGI factory and gives its+adapter to DXVK's d3d11, which then calls `DXGIFactory::CreateSwapChain` in D3DMetal; that fails+(`E_FAIL`) and the game deadlocks in its exception handler holding a critical section+(`winedbg` backtrace). A global `dxgi=n,b` with DXVK's dxgi broke the launcher's CEF.++The run script exports `NOTPROTON_ROCKSTAR_DXGI`, the Windows path of DXVK's dxgi shipped as+`rockstar-shim/x86_64-windows/dxgx.dll` (another name, so `dxgi=b` does not apply). In GTA5.exe+the shim loads it and registers it as `dxgi.dll`: it renames `BaseDllName` and moves the entry's+`HashLinks` to the bucket of the new name. The bucket array is private to ntdll; the shim finds+it from the other modules' bucket heads and uses the hash variant (Windows 8+, 7, first letter)+whose buckets line up for every loaded module, or changes nothing. Later+`LoadLibrary`/`GetModuleHandle("dxgi.dll")` then return DXVK's dxgi, and DXVK's d3d11 binds to it.++## Build++ rockstar-shim/build.sh # needs x86_64-w64-mingw32-gcc (brew install mingw-w64)++The build is reproducible (no timestamp, no build id). Copy `version.dll` to+`app/Sources/BridgeplayApp/Resources/version-rockstar-shim.dll` and update its sha256 in+`FreeEngineWinecx.swift`. `dxgx.dll` is `x64/dxgi.dll` from+`dxvk-macOS-async-v1.10.3-20230507.tar.gz`+(https://github.com/Gcenx/DXVK-macOS/releases/tag/v1.10.3-20230507), the release whose d3d11.dll+is byte-identical to the repack's the engine already uses; it ships as+`app/Sources/BridgeplayApp/Resources/dxgi-dxvk-macos-1.10.3.dll`.diff --git a/rockstar-shim/build.sh b/rockstar-shim/build.shnew file mode 100755index 0000000..aef6bff--- /dev/null+++ b/rockstar-shim/build.sh@@ -0,0 +1,10 @@+#!/bin/sh+# Builds rockstar-shim/version.dll (x86_64 PE, no Wine builtin marker, so the copies next to+# SocialClubHelper.exe and the game load as native under version=n,b).+set -eu+cd "$(dirname "$0")"+x86_64-w64-mingw32-gcc -O1 -shared -s -nostdlib -e DllMain -fno-builtin \+ -fno-tree-loop-distribute-patterns -Wall -Wextra -Wno-unused-parameter \+ -Wl,--no-insert-timestamp -Wl,--build-id=none -Wl,--enable-stdcall-fixup \+ -o version.dll version_shim.c version.def -lkernel32+shasum -a 256 version.dlldiff --git a/rockstar-shim/version.def b/rockstar-shim/version.defnew file mode 100644index 0000000..7abe16e--- /dev/null+++ b/rockstar-shim/version.def@@ -0,0 +1,18 @@+LIBRARY version.dll+EXPORTS+GetFileVersionInfoA=kernelbase.GetFileVersionInfoA+GetFileVersionInfoExA=kernelbase.GetFileVersionInfoExA+GetFileVersionInfoExW=kernelbase.GetFileVersionInfoExW+GetFileVersionInfoSizeA=kernelbase.GetFileVersionInfoSizeA+GetFileVersionInfoSizeExA=kernelbase.GetFileVersionInfoSizeExA+GetFileVersionInfoSizeExW=kernelbase.GetFileVersionInfoSizeExW+GetFileVersionInfoSizeW=kernelbase.GetFileVersionInfoSizeW+GetFileVersionInfoW=kernelbase.GetFileVersionInfoW+VerFindFileA=shim_VerFindFileA+VerFindFileW=shim_VerFindFileW+VerInstallFileA=shim_VerInstallFileA+VerInstallFileW=shim_VerInstallFileW+VerLanguageNameA=kernel32.VerLanguageNameA+VerLanguageNameW=kernel32.VerLanguageNameW+VerQueryValueA=kernelbase.VerQueryValueA+VerQueryValueW=kernelbase.VerQueryValueWdiff --git a/rockstar-shim/version_shim.c b/rockstar-shim/version_shim.cnew file mode 100644index 0000000..b58eb4e--- /dev/null+++ b/rockstar-shim/version_shim.c@@ -0,0 +1,228 @@+/*+ * version.dll for the Rockstar Games Launcher and GTA V Legacy (gamefix ROCKSTAR_SHIM=1).+ * The run script copies it next to SocialClubHelper.exe and next to the game's exe, and+ * sets version=n,b. Every export forwards to kernelbase/kernel32; DllMain does one job+ * per process and nothing in any other process:+ *+ * SocialClubHelper.exe (CEF): the launcher's sign-in and main windows are child windows+ * that Chromium's GPU/viz process paints from another process. A winemac process cannot+ * draw into another process's window, so they stay blank. The CEF browser process gets+ * --in-process-gpu --disable-gpu --disable-gpu-compositing --disable-software-rasterizer,+ * so it composites in software into its own window and starts no SwiftShader in process+ * (which sometimes kept the window from being created). Wine's kernelbase caches the command line (GetCommandLineW reads+ * command_lineW), so that copy is pointed at the new one too. The launcher also starts+ * CEF with the game folder as working directory; SetDllDirectoryW(L"") keeps a d3d11 or+ * dxgi there out of CEF's DLL search.+ *+ * GTA5.exe on DXVK: the game makes its own DXGI factory and passes its adapter to d3d11.+ * On WineCX "dxgi.dll" is CrossOver's D3DMetal dxgi, whose CreateSwapChain fails for+ * DXVK's device, and the game deadlocks in its exception handler. NOTPROTON_ROCKSTAR_DXGI+ * names DXVK's dxgi under another file name (dxgx.dll, so the dxgi=b override does not+ * apply to it). It is loaded and registered in the loader as dxgi.dll: BaseDllName is+ * renamed and the entry moved to the hash bucket of its new name, so later+ * LoadLibrary/GetModuleHandle("dxgi.dll") return it.+ *+ * Messages go to OutputDebugString (WINEDEBUG=+debugstr).+ */+#include <windows.h>+#include <winternl.h>++static void say(const char *msg)+{+ OutputDebugStringA(msg);+}++static void copy_bytes(void *d, const void *s, SIZE_T n)+{+ char *dd = d;+ const char *ss = s;+ while (n--) *dd++ = *ss++;+}++static int has_substr(const WCHAR *s, SIZE_T len, const WCHAR *pat)+{+ SIZE_T i, j;+ for (i = 0; i < len; i++)+ {+ for (j = 0; pat[j] && i + j < len && s[i + j] == pat[j]; j++) ;+ if (!pat[j]) return 1;+ }+ return 0;+}++static int exe_is(const WCHAR *name)+{+ WCHAR path[MAX_PATH];+ DWORD n = GetModuleFileNameW(NULL, path, MAX_PATH);+ if (!n || n >= MAX_PATH) return 0;+ while (n && path[n - 1] != '\\') n--;+ return !lstrcmpiW(path + n, name);+}++/* --- SocialClubHelper.exe --- */++static const WCHAR cef_switches[] = L" --in-process-gpu --disable-gpu --disable-gpu-compositing --disable-software-rasterizer";++/* Wine's GetCommandLineW is "mov rax, [rip+disp32]; ret". Anything else is left alone. */+static int point_kernelbase_cache(WCHAR *buf)+{+ HMODULE kb = GetModuleHandleW(L"kernelbase.dll");+ const unsigned char *fn;+ int disp;++ if (!kb) return 0;+ fn = (const unsigned char *)GetProcAddress(kb, "GetCommandLineW");+ if (!fn || fn[0] != 0x48 || fn[1] != 0x8b || fn[2] != 0x05 || fn[7] != 0xc3) return 0;+ copy_bytes(&disp, fn + 3, sizeof(disp));+ *(WCHAR **)(fn + 7 + disp) = buf;+ return 1;+}++static void cef_browser_switches(void)+{+ PEB *peb = (PEB *)__readgsqword(0x60);+ UNICODE_STRING *cl = &peb->ProcessParameters->CommandLine;+ USHORT extra = sizeof(cef_switches) - sizeof(WCHAR);+ WCHAR *buf;++ if (!cl->Buffer) return;+ /* Renderers, utilities and the GPU process carry --type=; only the browser is changed. */+ if (has_substr(cl->Buffer, cl->Length / sizeof(WCHAR), L"--type=")) return;+ if (has_substr(cl->Buffer, cl->Length / sizeof(WCHAR), L"--in-process-gpu")) return;+ if ((ULONG)cl->Length + extra + sizeof(WCHAR) > 0xfffe) return;+ buf = HeapAlloc(GetProcessHeap(), 0, cl->Length + extra + sizeof(WCHAR));+ if (!buf) return;+ copy_bytes(buf, cl->Buffer, cl->Length);+ copy_bytes((char *)buf + cl->Length, cef_switches, sizeof(cef_switches));+ cl->Buffer = buf;+ cl->Length += extra;+ cl->MaximumLength = cl->Length + sizeof(WCHAR);+ say(point_kernelbase_cache(buf) ? "rockstar-shim: CEF browser composites in process\n"+ : "rockstar-shim: GetCommandLineW not recognised, CEF switches only in the PEB\n");+}++/* --- GTA5.exe --- */++struct ldr_entry+{+ LIST_ENTRY InLoadOrderLinks;+ LIST_ENTRY InMemoryOrderLinks;+ LIST_ENTRY InInitializationOrderLinks;+ void *DllBase;+ void *EntryPoint;+ ULONG SizeOfImage;+ UNICODE_STRING FullDllName;+ UNICODE_STRING BaseDllName;+ ULONG Flags;+ SHORT LoadCount;+ SHORT TlsIndex;+ LIST_ENTRY HashLinks;+};++#define HASH_MAP_SIZE 32++static WCHAR up(WCHAR c) { return (c >= 'a' && c <= 'z') ? c - 32 : c; }++/* kind 0: Windows 8+ (and Wine), 1: Windows 7, 2: older, first letter. */+static ULONG name_hash(const UNICODE_STRING *n, int kind)+{+ ULONG h = 0, i, len = n->Length / sizeof(WCHAR);+ if (kind == 2) return len ? (ULONG)(up(n->Buffer[0]) - 'A') & (HASH_MAP_SIZE - 1) : 0;+ for (i = 0; i < len; i++) h = h * (kind == 0 ? 65599 : 0x1003f) + up(n->Buffer[i]);+ return h & (HASH_MAP_SIZE - 1);+}++static int is_module_hash_node(LIST_ENTRY *mods, LIST_ENTRY *node)+{+ LIST_ENTRY *e;+ for (e = mods->Flink; e != mods; e = e->Flink)+ if (&CONTAINING_RECORD(e, struct ldr_entry, InLoadOrderLinks)->HashLinks == node) return 1;+ return 0;+}++/* The bucket array is private to ntdll. Each module's HashLinks ring holds one node that is+ * not a module: its bucket head. The hash variant whose buckets line up for every module+ * gives the array; with none, nothing is changed. Runs under the loader lock (DllMain). */+static int rehash_entry(struct ldr_entry *target)+{+ PEB *peb = (PEB *)__readgsqword(0x60);+ LIST_ENTRY *mods = (LIST_ENTRY *)((char *)peb->Ldr + 0x10); /* InLoadOrderModuleList */+ LIST_ENTRY *e, *n, *table = NULL;+ int kind;++ for (kind = 0; kind < 3 && !table; kind++)+ {+ LIST_ENTRY *base = NULL;+ int ok = 1, seen = 0;+ for (e = mods->Flink; e != mods && ok; e = e->Flink)+ {+ struct ldr_entry *m = CONTAINING_RECORD(e, struct ldr_entry, InLoadOrderLinks);+ LIST_ENTRY *b;+ if (m == target || !m->BaseDllName.Buffer || !m->HashLinks.Flink) continue;+ for (n = m->HashLinks.Flink; n != &m->HashLinks && is_module_hash_node(mods, n); n = n->Flink) ;+ if (n == &m->HashLinks) { ok = 0; break; }+ b = n - name_hash(&m->BaseDllName, kind);+ if (!base) base = b;+ else if (b != base) ok = 0;+ seen++;+ }+ if (ok && seen > 3) table = base;+ }+ if (!table) return 0;+ kind--;+ target->HashLinks.Blink->Flink = target->HashLinks.Flink;+ target->HashLinks.Flink->Blink = target->HashLinks.Blink;+ n = table + name_hash(&target->BaseDllName, kind);+ target->HashLinks.Flink = n;+ target->HashLinks.Blink = n->Blink;+ n->Blink->Flink = &target->HashLinks;+ n->Blink = &target->HashLinks;+ return 1;+}++static WCHAR dxgi_name[] = L"dxgi.dll";++static void gta_dxvk_dxgi(void)+{+ WCHAR path[MAX_PATH];+ DWORD n = GetEnvironmentVariableW(L"NOTPROTON_ROCKSTAR_DXGI", path, MAX_PATH);+ PEB *peb = (PEB *)__readgsqword(0x60);+ LIST_ENTRY *mods = (LIST_ENTRY *)((char *)peb->Ldr + 0x10), *e;+ HMODULE h;++ if (!n || n >= MAX_PATH) return; /* not on DXVK */+ if (GetModuleHandleW(L"dxgi.dll")) { say("rockstar-shim: dxgi.dll already loaded\n"); return; }+ if (!(h = LoadLibraryW(path))) { say("rockstar-shim: DXVK dxgi did not load\n"); return; }+ for (e = mods->Flink; e != mods; e = e->Flink)+ {+ struct ldr_entry *m = CONTAINING_RECORD(e, struct ldr_entry, InLoadOrderLinks);+ if (m->DllBase != h) continue;+ m->BaseDllName.Buffer = dxgi_name;+ m->BaseDllName.Length = sizeof(dxgi_name) - sizeof(WCHAR);+ m->BaseDllName.MaximumLength = sizeof(dxgi_name);+ if (!rehash_entry(m)) say("rockstar-shim: loader hash table not found\n");+ say(GetModuleHandleW(L"dxgi.dll") == h ? "rockstar-shim: DXVK dxgi is dxgi.dll\n"+ : "rockstar-shim: dxgi.dll does not resolve to DXVK dxgi\n");+ return;+ }+}++BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved)+{+ if (reason != DLL_PROCESS_ATTACH) return TRUE;+ DisableThreadLibraryCalls(inst);+ if (exe_is(L"SocialClubHelper.exe"))+ {+ SetDllDirectoryW(L"");+ cef_browser_switches();+ }+ else if (exe_is(L"GTA5.exe"))+ gta_dxvk_dxgi();+ return TRUE;+}++/* Not in kernelbase; nothing the shim sits next to imports them. */+DWORD WINAPI shim_VerFindFileA(DWORD f, LPCSTR a, LPCSTR b, LPCSTR c, LPSTR d, PUINT e, LPSTR g, PUINT h) { return 0; }+DWORD WINAPI shim_VerFindFileW(DWORD f, LPCWSTR a, LPCWSTR b, LPCWSTR c, LPWSTR d, PUINT e, LPWSTR g, PUINT h) { return 0; }+DWORD WINAPI shim_VerInstallFileA(DWORD f, LPCSTR a, LPCSTR b, LPCSTR c, LPCSTR d, LPCSTR e, LPSTR g, PUINT h) { return VIF_CANNOTREADSRC; }+DWORD WINAPI shim_VerInstallFileW(DWORD f, LPCWSTR a, LPCWSTR b, LPCWSTR c, LPCWSTR d, LPCWSTR e, LPWSTR g, PUINT h) { return VIF_CANNOTREADSRC; }