Skip to content

Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit

fix(gamefix): keep the ROCKSTAR_SHIM backup whole and the shim in shared game folders (#2322)

Raystorms7716bb0d577e
diff --git a/docs/GAMEFIXES.md b/docs/GAMEFIXES.md
index 423a80d..88aed15 100644
--- a/docs/GAMEFIXES.md
+++ b/docs/GAMEFIXES.md
@@ -58,7 +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` |
+| `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, except in a game folder another launch (another macOS user's too) is still using. 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/dylib/feats/compat_run.sh b/dylib/feats/compat_run.sh
index 930bc90..02137a5 100755
--- a/dylib/feats/compat_run.sh
+++ b/dylib/feats/compat_run.sh
@@ -916,30 +916,84 @@ rockstar_shim_copy() {
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.
+# Opens fd $1 on the lock file $2, created readable by every macOS user sharing the folder:
+# read-write when it can be (some network volumes lock only a writable fd), else read-only.
+# The exclusive create never makes a file through a link another user puts there, and a
+# link is never opened. The checks make the exec certain to work, since a failed one ends
+# the script. No `command exec`: after one, bash 3.2 spins forever on exit.
+rockstar_shim_lock_fd() {
+ [ -e "$2" ] || [ -L "$2" ] || (umask 022; set -C; : > "$2") 2>/dev/null || true
+ [ -f "$2" ] && [ ! -L "$2" ] && [ -r "$2" ] || return 1
+ if [ -w "$2" ]; then eval "exec $1>> \"\$2\""; else eval "exec $1< \"\$2\""; fi
+}
+
+# A launch that stages the shim holds an .inuse file in the game folder locked until it
+# ends, so a launch by another macOS user sharing the folder can tell the shim is in use.
+# Only lockf's EX_TEMPFAIL (75) means a holder; a file it cannot open or lock says nothing.
+rockstar_shim_in_use() {
+ for held in "$1"/.bridgeplay-rockstar-shim.*.inuse; do
+ [ -f "$held" ] && [ ! -L "$held" ] || continue
+ rc=0
+ /usr/bin/lockf -k -n -s -t 0 "$held" true 2>/dev/null || rc=$?
+ [ "$rc" != 75 ] || return 0
+ done
+ return 1
+}
+
+# Stages, removes or restores version.dll in Social Club and the game folder. The first lock
+# is per macOS user. Several users can share the game folder, so it also gets a lock of its
+# own, taken only when the folder has something of the shim's in it. A volume that cannot
+# hold that lock falls back to the per-user one. Exits 3 when another launch held it.
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
+ game=${STEAM_COMPAT_INSTALL_PATH:-}
+ lock="$game/.bridgeplay-rockstar-shim.lock"
+ game_locked=0
+ busy=0
+ if [ -z "$game" ] || [ ! -d "$game" ]; then
+ game=""
+ elif [ "$shim_wanted" = 1 ] || [ -f "$lock" ] || [ -e "$game/version.dll.bridgeplay-orig" ] \
+ || [ -L "$game/version.dll.bridgeplay-orig" ] || rockstar_shim_copy "$shim/version.dll" "$game/version.dll"; then
+ rc=1
+ if rockstar_shim_lock_fd 7 "$lock"; then rc=0; /usr/bin/lockf -s -t 30 7 || rc=$?; fi
+ if [ "$rc" = 0 ]; then
+ game_locked=1
+ elif [ "$rc" = 75 ]; then
+ graphics_log "rockstar-shim: another launch holds the lock on $game, left alone"
+ game=""
+ busy=1
+ else
+ graphics_log "rockstar-shim: could not lock $game, only this macOS user's launches take turns there"
+ fi
+ else
+ game=""
+ fi
+ for dir in "$social_club" "$game"; do
[ -n "$dir" ] && [ -d "$dir" ] || continue
target="$dir/version.dll"
saved="$dir/version.dll.bridgeplay-orig"
+ is_shim=0
+ ! rockstar_shim_copy "$shim/version.dll" "$target" || is_shim=1
+ # A launch of an older build killed between claiming the backup name and the move
+ # left it empty, with the game's own file still in place. One still claiming it now
+ # made it moments ago.
+ if [ -f "$saved" ] && [ ! -L "$saved" ] && [ ! -s "$saved" ] \
+ && { [ -e "$target" ] || [ -L "$target" ]; } && [ "$is_shim" = 0 ] \
+ && [ -n "$(find "$saved" -prune -mmin +1 2>/dev/null)" ]; then
+ rm -f "$saved" 2>> "$log" && graphics_log "rockstar-shim: removed an empty version.dll.bridgeplay-orig from $dir"
+ fi
if [ "$shim_wanted" = 1 ]; then
moved=0
- if { [ -e "$target" ] || [ -L "$target" ]; } && ! rockstar_shim_copy "$shim/version.dll" "$target"; then
+ if { [ -e "$target" ] || [ -L "$target" ]; } && [ "$is_shim" = 0 ]; 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"
+ # One rename: a killed launch leaves the file under one name or the other, never
+ # an empty backup. Without the folder's lock another user's launch could rename a
+ # file over it, so then the game's own file stays.
+ if { [ "$dir" = "$game" ] && [ "$game_locked" = 0 ]; } || ! mv "$target" "$saved" 2>> "$log"; then
graphics_log "rockstar-shim: could not set aside the version.dll in $dir, left alone"
continue
fi
@@ -949,10 +1003,17 @@ rockstar_shim_folders() {
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
+ elif [ "$dir" = "$game" ]; then
+ # Other macOS users' launches read it too.
+ chmod a+r "$target" 2>/dev/null || true
fi
continue
fi
- if rockstar_shim_copy "$shim/version.dll" "$target"; then
+ if rockstar_shim_in_use "$dir"; then
+ graphics_log "rockstar-shim: another launch is using the version.dll in $dir, left alone"
+ continue
+ fi
+ if [ "$is_shim" = 1 ]; then
rm -f "$target" 2>> "$log" && graphics_log "rockstar-shim: removed version.dll from $dir"
fi
if [ -e "$saved" ] || [ -L "$saved" ]; then
@@ -963,6 +1024,7 @@ rockstar_shim_folders() {
fi
fi
done
+ [ "$busy" = 0 ] || exit 3
exit 0
)
}
@@ -972,7 +1034,7 @@ rockstar_shim_folders() {
# 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.
+# staged copy is removed and that file put back, unless another launch is using the folder.
stage_rockstar_shim() {
shim="$backend_root/rockstar-shim/x86_64-windows"
social_club="$WINEPREFIX/drive_c/Program Files/Rockstar Games/Social Club"
@@ -983,13 +1045,30 @@ stage_rockstar_shim() {
# Helpers (verb run) leave the game's files as they are.
return 0
fi
+ # Held before staging, so no other launch can take the shim out between the two, and kept
+ # from the game's launch, so it ends with this script. One per macOS user and prefix, so
+ # two prefixes on one game each hold their own.
+ if [ "$shim_wanted" = 1 ] && [ -d "${STEAM_COMPAT_INSTALL_PATH:-}" ]; then
+ inuse="$STEAM_COMPAT_INSTALL_PATH/.bridgeplay-rockstar-shim.$(id -u)-$(printf '%s' "${STEAM_COMPAT_DATA_PATH:-}" | cksum | cut -d ' ' -f 1)"
+ # A mark the previous launch of this prefix still holds while it shuts down sends this
+ # launch to a second one.
+ if ! { rockstar_shim_lock_fd 5 "$inuse.inuse" && /usr/bin/lockf -s -t 1 5; } \
+ && ! { rockstar_shim_lock_fd 5 "$inuse-2.inuse" && /usr/bin/lockf -s -t 5 5; }; then
+ graphics_log "rockstar-shim: could not mark the game folder in use"
+ fi
+ 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"
+ folders=0
+ rockstar_shim_folders || folders=$?
+ [ "$folders" != 1 ] || 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
+ # No shim of any build in the game folder, nothing there for other launches to leave
+ # alone. A folder another launch is staging keeps the mark.
+ [ "$folders" = 3 ] || rockstar_shim_copy "$shim/version.dll" "${STEAM_COMPAT_INSTALL_PATH:-}/version.dll" || exec 5>&-
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
@@ -3147,7 +3226,7 @@ np_started=$(date +%s)
np_terminated=0
launch_step start
if [ "${NOTPROTON_LAUNCH_SERVICES:-0}" = "1" ]; then
- open -n -W -a "$loader_app" "$@" >> "$log" 2>&1 &
+ open -n -W -a "$loader_app" "$@" >> "$log" 2>&1 5>&- &
else
# A bundle started by `open` is its own TCC responsible process, so every game
# needed a separate Input Monitoring grant before controllers worked. Started
@@ -3176,10 +3255,10 @@ else
done
echo "launching bundle directly so input permission stays with Steam" >> "$log" 2>&1 || true
env -i HOME="$HOME" USER="$USER" LOGNAME="$LOGNAME" SHELL="$SHELL" TMPDIR="$TMPDIR" \
- __CF_USER_TEXT_ENCODING="$__CF_USER_TEXT_ENCODING" "$@" >> "$log" 2>&1 &
+ __CF_USER_TEXT_ENCODING="$__CF_USER_TEXT_ENCODING" "$@" >> "$log" 2>&1 5>&- &
fi
open_pid=$!
-/usr/bin/caffeinate -d -i -w "$open_pid" >> "$log" 2>&1 &
+/usr/bin/caffeinate -d -i -w "$open_pid" >> "$log" 2>&1 5>&- &
status=0
wait "$open_pid" || status=$?
launch_step ended
diff --git a/dylib/tests/gamefixescheck.sh b/dylib/tests/gamefixescheck.sh
index 8a3e089..c1ce255 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 rockstar_shim_copy rockstar_shim_folders stage_rockstar_shim compose_dll_overrides; do
+ activate_backend record_backend rockstar_shim_copy rockstar_shim_lock_fd rockstar_shim_in_use rockstar_shim_folders stage_rockstar_shim compose_dll_overrides; do
body=$(sed -n "/^$name() {\$/,/^}\$/p" "$SRC")
[ -n "$body" ] || { echo "FAIL: $name not found in $SRC"; exit 1; }
functions="$functions
@@ -693,6 +693,13 @@ 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"
+# After a `command exec`, bash 3.2 (macOS /bin/sh) spins forever on exit.
+is "the run script never uses command exec" "0" \
+ "$(grep -v '^[[:space:]]*#' "$SRC" | grep -c 'command exec' || true)"
+# The game, its env -i start and caffeinate outlive staging; holding fd 5 they would keep the
+# ROCKSTAR_SHIM in-use mark after the run script ends.
+is "the game's launch does not inherit the in-use mark" "3" "$(grep -c '>> "$log" 2>&1 5>&- &$' "$SRC" || true)"
+
echo "== ROCKSTAR_SHIM stages rockstar-shim/ next to Social Club and the game"
rockstar_case() {
new_case
@@ -739,13 +746,18 @@ 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")"
+is "and a folder with nothing of the shim's gets no lock file" "no" \
+ "$([ -e "$case_dir/game/.bridgeplay-rockstar-shim.lock" ] && echo yes || echo no)"
echo "== ROCKSTAR_SHIM keeps a version.dll the game already had"
rockstar_case
printf 'a mod loader\n' > "$case_dir/game/version.dll"
+orig_inode=$(stat -f %i "$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 "by a rename, so a killed launch cannot leave an empty backup" "$orig_inode" \
+ "$(stat -f %i "$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"
@@ -793,6 +805,54 @@ 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"
+has "after falling back to this user's lock" "could not lock $case_dir/game, only this macOS user's launches take turns there" "$case_dir/log"
+rockstar_case
+printf 'a mod loader\n' > "$case_dir/game/version.dll"
+ln -s /dev/null "$case_dir/game/.bridgeplay-rockstar-shim.lock"
+user_conf 'BACKEND=dxvk' 'ROCKSTAR_SHIM=1'
+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"
+is "without the game folder's lock the game's own version.dll is not moved" "a mod loader|no" \
+ "$(cat "$case_dir/game/version.dll")|$([ -e "$case_dir/game/version.dll.bridgeplay-orig" ] && echo yes || echo no)"
+
+# An older build killed between claiming the backup name and the move left it empty.
+rockstar_case
+printf 'a mod loader\n' > "$case_dir/game/version.dll"
+: > "$case_dir/game/version.dll.bridgeplay-orig"
+touch -t 202601010000 "$case_dir/game/version.dll.bridgeplay-orig"
+user_conf 'BACKEND=dxvk' 'ROCKSTAR_SHIM=1'
+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"
+is "an empty backup does not keep the shim off" "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)"
+has "and is logged" "removed an empty version.dll.bridgeplay-orig from $case_dir/game" "$case_dir/log"
+user_conf 'BACKEND=dxvk'
+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"
+is "and the game's own version.dll comes back after it" "a mod loader|no" \
+ "$(cat "$case_dir/game/version.dll")|$([ -e "$case_dir/game/version.dll.bridgeplay-orig" ] && echo yes || echo no)"
+rockstar_case
+printf 'a mod loader\n' > "$case_dir/game/version.dll"
+: > "$case_dir/game/version.dll.bridgeplay-orig"
+touch -t 202601010000 "$case_dir/game/version.dll.bridgeplay-orig"
+user_conf 'BACKEND=dxvk'
+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"
+is "without the key an empty backup goes and the game's own file stays" "a mod loader|no" \
+ "$(cat "$case_dir/game/version.dll")|$([ -e "$case_dir/game/version.dll.bridgeplay-orig" ] && echo yes || echo no)"
+rockstar_case
+printf 'a mod loader\n' > "$case_dir/game/version.dll"
+: > "$case_dir/game/version.dll.bridgeplay-orig"
+user_conf 'BACKEND=dxvk' 'ROCKSTAR_SHIM=1'
+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"
+is "an empty backup an older build is claiming right now is left to it" "a mod loader|yes" \
+ "$(cat "$case_dir/game/version.dll")|$([ -e "$case_dir/game/version.dll.bridgeplay-orig" ] && echo yes || echo no)"
+rockstar_case
+: > "$case_dir/game/version.dll"
+user_conf 'BACKEND=dxvk' 'ROCKSTAR_SHIM=1'
+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"
+touch -t 202601010000 "$case_dir/game/version.dll.bridgeplay-orig"
+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"
+user_conf 'BACKEND=dxvk'
+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"
+is "an empty version.dll of the game's own is set aside and put back" "yes|0|no" \
+ "$([ -f "$case_dir/game/version.dll" ] && echo yes || echo no)|$(stat -f %z "$case_dir/game/version.dll" 2>/dev/null)|$([ -e "$case_dir/game/version.dll.bridgeplay-orig" ] && echo yes || echo no)"
# Another launch holds the lock for two seconds and notes the game folder as it lets go.
rockstar_case
@@ -808,6 +868,76 @@ is "a launch leaves the folder alone while another holds the lock" "a mod loader
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)"
+# Another macOS user's launch holds the game folder's own lock.
+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/game/.bridgeplay-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 waits for the game folder's lock too" "a mod loader" "$(cat "$case_dir/held" 2>/dev/null)"
+
+echo "== ROCKSTAR_SHIM leaves the shim to a launch still using it"
+rockstar_case
+printf 'a mod loader\n' > "$case_dir/game/version.dll"
+user_conf 'BACKEND=dxvk' 'ROCKSTAR_SHIM=1'
+# Another prefix of this macOS user holds its own mark on the game folder.
+mark() { echo "$case_dir/game/.bridgeplay-rockstar-shim.$(id -u)-$(printf '%s' "$1" | cksum | cut -d ' ' -f 1).inuse"; }
+/usr/bin/lockf -k "$(mark "$case_dir/other-data")" sleep 3 &
+holder=$!
+sleep 0.5
+(umask 077; rockstar_launch waitforexitandrun "$case_dir/game/game.exe")
+inuse=$(mark "$case_dir/data")
+is "a launch that stages the shim marks the game folder in use, per user and prefix" "yes" \
+ "$([ -f "$inuse" ] && echo yes || echo no)"
+is "next to another prefix's mark of the same user" "no" \
+ "$(grep -qF 'could not mark the game folder in use' "$case_dir/log" && echo yes || echo no)"
+is "and its lock files and staged shim are readable by other macOS users" "-rw-r--r--|-rw-r--r--|-rw-r--r--" \
+ "$(stat -f %Sp "$inuse")|$(stat -f %Sp "$case_dir/game/.bridgeplay-rockstar-shim.lock")|$(stat -f %Sp "$case_dir/game/version.dll")"
+wait "$holder"
+# Another macOS user's session is still running and holds its in-use file.
+/usr/bin/lockf -k "$case_dir/game/.bridgeplay-rockstar-shim.4243.inuse" sleep 3 &
+holder=$!
+sleep 0.5
+user_conf 'BACKEND=dxvk'
+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"
+is "a launch without the key leaves the shim while another session uses it" "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)"
+has "and says so" "another launch is using the version.dll in $case_dir/game, left alone" "$case_dir/log"
+is "Social Club is the launch's own and is still cleaned" "no" "$([ -e "$social/version.dll" ] && echo yes || echo no)"
+wait "$holder"
+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"
+is "once that session ends the game's own version.dll is back" "a mod loader|no" \
+ "$(cat "$case_dir/game/version.dll")|$([ -e "$case_dir/game/version.dll.bridgeplay-orig" ] && echo yes || echo no)"
+rockstar_case
+user_conf 'BACKEND=dxvk' 'ROCKSTAR_SHIM=1'
+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"
+: > "$case_dir/game/.bridgeplay-rockstar-shim.4244.inuse"
+chmod 000 "$case_dir/game/.bridgeplay-rockstar-shim.4244.inuse"
+user_conf 'BACKEND=dxvk'
+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"
+chmod 600 "$case_dir/game/.bridgeplay-rockstar-shim.4244.inuse"
+is "a mark that cannot be opened does not keep the shim in" "no" "$([ -e "$case_dir/game/version.dll" ] && echo yes || echo no)"
+rockstar_case
+/usr/bin/lockf -k "$(mark "$case_dir/data")" sleep 3 &
+holder=$!
+sleep 0.5
+user_conf 'BACKEND=dxvk' 'ROCKSTAR_SHIM=1'
+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"
+wait "$holder"
+is "a mark a leftover process holds sends the launch to a second one" "no|1" \
+ "$(grep -qF 'could not mark the game folder in use' "$case_dir/log" && echo yes || echo no)|$([ -f "$(mark "$case_dir/data" | sed 's/\.inuse$//')-2.inuse" ] && echo 1 || echo 0)"
+rockstar_case
+ln -s "$case_dir/outside-lock" "$case_dir/game/.bridgeplay-rockstar-shim.lock"
+ln -s "$case_dir/outside-mark" "$(mark "$case_dir/data")"
+user_conf 'BACKEND=dxvk' 'ROCKSTAR_SHIM=1'
+rockstar_launch waitforexitandrun "$case_dir/game/game.exe"
+is "lock files that are links create nothing where they point" "no|no" \
+ "$([ -e "$case_dir/outside-lock" ] && echo yes || echo no)|$([ -e "$case_dir/outside-mark" ] && echo yes || echo no)"
+
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"
diff --git a/rockstar-shim/README.md b/rockstar-shim/README.md
index a189159..5c4959e 100644
--- a/rockstar-shim/README.md
+++ b/rockstar-shim/README.md
@@ -7,7 +7,9 @@ exe, never into `system32`, and the run script adds `version=n,b`. Every export
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
+when the key is off or the engine has no shim. Several macOS users can share a game folder, so
+it gets `.bridgeplay-rockstar-shim.lock`, and each launch that stages the shim holds an
+`.inuse` file there until its launch ends; while one is held, the shim stays. 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.