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
feat(run): per-game gamefixes and selectable graphics backends
raymondchins17ece91dabdb
diff --git a/.github/workflows/app.yml b/.github/workflows/app.ymlindex f824be8..8d9dcaf 100644--- a/.github/workflows/app.yml+++ b/.github/workflows/app.yml@@ -109,6 +109,7 @@ jobs:make -s bridgecheckmake -s gamedrivecheckmake -s seedcheck+ make -s gamefixescheck- name: Run the Swift testsrun: make -s app-testsdiff --git a/Makefile b/Makefileindex 7138d9d..12ad57e 100644--- a/Makefile+++ b/Makefile@@ -64,7 +64,8 @@ DEPS := $(OBJS:.o=.d)tests-list overlay-shim overlay-shim-install overlay-shim-tests \overlay-shim-bench iconmaker icon \appinfo helpers-install ntdll-resolve bridge runcheck compatcheck \- compatsvc-check scriptcheck envcheck buildcheck settingscheck routecheck bridgecheck gamedrivecheck launch-shell FORCE+ compatsvc-check scriptcheck envcheck buildcheck settingscheck routecheck bridgecheck gamedrivecheck \+ gamefixescheck launch-shell FORCEAPP_PAYLOAD := app/Sources/NotProtonApp/Resources/payload@@ -120,6 +121,10 @@ gamedrivecheck:@if [ ! -f dylib/tests/gamedrivecheck.sh ]; then $(call SKIP,gamedrivecheck,dylib/tests/gamedrivecheck.sh); exit 0; fi; \sh dylib/tests/gamedrivecheck.sh dylib/feats/compat_run.sh+gamefixescheck:+ @if [ ! -f dylib/tests/gamefixescheck.sh ]; then $(call SKIP,gamefixescheck,dylib/tests/gamefixescheck.sh); exit 0; fi; \+ sh dylib/tests/gamefixescheck.sh dylib/feats/compat_run.sh+# runcheck owns compat_run.sh, whose warnings wait for a change that can move# the embedded __text baselineSCRIPTS := $(shell git ls-files '*.sh' 2>/dev/null | grep -v '^dylib/feats/compat_run\.sh$$')diff --git a/docs/GAMEFIXES.md b/docs/GAMEFIXES.mdnew file mode 100644index 0000000..a02c5f8--- /dev/null+++ b/docs/GAMEFIXES.md@@ -0,0 +1,90 @@+# Per-game fixes and graphics backends++The `run` script reads two optional files for each game, named after its Steam app id:++1. `~/Library/Application Support/notproton/gamefixes-default/<appid>.conf`, shipped with NotProton+2. `~/Library/Application Support/notproton/gamefixes/<appid>.conf`, your own++The later file wins per key. A variable you set in the game's Steam launch options+(`NAME=value %command%`) wins over both files.++## Format++One `KEY=VALUE` per line. Blank lines and lines starting with `#` are ignored, and so is+whitespace around a line. There are no inline comments: everything after the first `=`+is the value. The files are never run as shell code. A line is rejected, and the rejection+logged, when:++- the key is not on the list below+- the value contains a backtick, `$(`, a quote or a control character, or is over 1024 characters++| Key | Values | Effect |+| --- | --- | --- |+| `BACKEND` | `dxmt`, `dxvk`, `wined3d`, `d3dmetal` | Graphics backend, see below |+| `ARGS` | space-separated arguments of `A-Za-z0-9_+./:=,-` | Added to the game's command line after the launch options' own arguments. Ignored for installers and other helpers |+| `DLLOVERRIDES` | Wine syntax, e.g. `dinput8=n,b;xinput1_3=n` | Added to `WINEDLLOVERRIDES` after the backend's entries and before the launch options' |+| `MSYNC` | `0`, `1` | `1` turns msync on when the engine supports it; `0` turns it off |+| `RETINA` | `0`, `1` | Same as `NOTPROTON_RETINA` (High Resolution) |+| `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 |++Wine uses the last entry for a DLL in `WINEDLLOVERRIDES`. The order is: backend, then+`DLLOVERRIDES`, then the launch options, then the Steam client DLLs, which always come last.++## Graphics backends++| Name | What runs D3D10/11 | D3D12 |+| --- | --- | --- |+| `dxmt` | DXMT (Metal), the default | does not work |+| `dxvk` | DXVK-macOS (MoltenVK); Wine's own `dxgi` stays builtin | vkd3d |+| `wined3d` | Wine's own DLLs | vkd3d |+| `d3dmetal` | Apple D3DMetal, only on engines that ship it | D3DMetal |++The backend is picked in this order:++1. `NOTPROTON_BACKEND=<name>` in the launch options+2. `CX_GRAPHICS_BACKEND` in the launch options, which the Steam panel's Graphics menu sets.+ Any case is accepted. `d3dmetal`, `dxmt` and `dxvk` map to themselves, and `wined3d`,+ `opengl` and `wine` map to `wined3d`. Other values are logged and ignored+3. `BACKEND=` in a conf file+4. Auto-detect. If the game's `.exe` imports `d3d12.dll` in its PE import table, the game+ gets `wined3d`. Otherwise it gets `dxmt`. Delay-loaded and `LoadLibrary` imports do not+ count, and neither does a file that does not parse as a PE+5. `dxmt`++A backend the engine lacks falls back: `dxvk` → `dxmt` → `wined3d`, and `d3dmetal` → `dxmt`.+Engines without `lib/notproton-backends` have their graphics DLLs built in. They show the+backend `dxmt-builtin` and do not swap anything.++The chosen backend's DLLs are copied into the prefix's `system32` and `syswow64` and set+to `n,b`. Every other DLL that any backend ships is set to `b`. When you switch backends, a+copy left behind by another backend is replaced with Wine's own. `d3dmetal` also sets+`CX_GRAPHICS_BACKEND=d3dmetal`. The run log+(`notproton-run.log`) shows each decision. The `notproton-backend` file in the game's+compatdata folder has the current backend and why it was picked.++## Examples++An Unreal game that defaults to D3D12, moved onto its D3D11 renderer under DXVK:++```+BACKEND=dxvk+ARGS=-dx11+DXVK_HUD=fps+```++A game that needs native input DLLs and verbose loader logs:++```+DLLOVERRIDES=dinput8=n,b;xinput1_3=n,b+WINEDEBUG=+loaddll+```++A DXMT game with MetalFX, msync off and High Resolution on:++```+BACKEND=dxmt+DXMT_METALFX_SPATIAL_SWAPCHAIN=1+MSYNC=0+RETINA=1+```diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.shindex dc877f3..d0f1e7e 100755--- a/dylib/feats/compat_run.sh+++ b/dylib/feats/compat_run.sh@@ -105,6 +105,468 @@ case "$app_id" in ''|0) app_id=$(basename "$STEAM_COMPAT_DATA_PATH" 2>/dev/null)case "$app_id" in ''|*[!0-9]*) app_id=0 ;; esacecho "app_id=$app_id (STEAM_COMPAT_APP_ID=$STEAM_COMPAT_APP_ID)" >> "$log" 2>&1 || true+# Per-game fixes: the shipped gamefixes-default/<appid>.conf, then the user's+# gamefixes/<appid>.conf, the later file winning per key. KEY=VALUE lines are checked+# against an allow-list and never sourced, and the launch options win over both files.+gamefix_keys=""+gamefix_backend=""+gamefix_dlloverrides=""+gamefix_msync=""+gamefix_args=""++gamefix_log() {+ echo "gamefix: $*" >> "$log" 2>&1 || true+}++# Wine syntax: name[,name...]=[n|b|n,b|b,n|d] entries joined by semicolons.+valid_dll_overrides() {+ rest=$1+ [ -n "$rest" ] || return 1+ while [ -n "$rest" ]; do+ entry=${rest%%;*}+ case "$rest" in *';'*) rest=${rest#*;} ;; *) rest="" ;; esac+ [ -n "$entry" ] || continue+ case "$entry" in *=*) ;; *) return 1 ;; esac+ case "${entry%%=*}" in ''|,*|*,|*,,*|*[!A-Za-z0-9_.,+-]*) return 1 ;; esac+ case "${entry#*=}" in ''|n|b|d|n,b|b,n) ;; *) return 1 ;; esac+ done+}++# Prints why a pair is refused, and nothing when it is allowed.+gamefix_reason() {+ # shellcheck disable=SC2016 # the patterns match these characters literally+ case "$2" in+ *'`'*|*'$('*|*'"'*|*"'"*) echo "a backtick, \$( or a quote in the value"; return 0 ;;+ *[[:cntrl:]]*) echo "a control character in the value"; return 0 ;;+ esac+ if [ "${#2}" -gt 1024 ]; then echo "a value over 1024 characters"; return 0; fi+ case "$1" in+ BACKEND)+ case "$2" in dxmt|dxvk|wined3d|d3dmetal) ;; *) echo "not dxmt, dxvk, wined3d or d3dmetal" ;; esac ;;+ MSYNC|RETINA)+ case "$2" in 0|1) ;; *) echo "not 0 or 1" ;; esac ;;+ DLLOVERRIDES)+ valid_dll_overrides "$2" || echo "not Wine override syntax" ;;+ ARGS)+ # Space-separated arguments, each of A-Za-z0-9_+./:=,- only, so none can glob or quote.+ case "$2" in *[!A-Za-z0-9_+./:=,\ -]*) echo "an argument with characters outside A-Za-z0-9_+./:=,-" ;; esac ;;+ MTL_HUD_ENABLED|WINEDEBUG|WINE_LARGE_ADDRESS_AWARE|WINE_CPU_TOPOLOGY) ;;+ DXMT_?*|DXVK_?*|MVK_?*|VKD3D_?*|D3DM_?*|STAGING_?*) ;;+ *) echo "not on the allow-list" ;;+ esac+}++gamefix_read() {+ [ -f "$1" ] || return 0+ if [ ! -r "$1" ] || [ "$(stat -f %z "$1" 2>/dev/null || echo 0)" -gt 65536 ]; then+ gamefix_log "$2 conf $1 is unreadable or over 64 KiB, ignored"+ return 0+ fi+ gamefix_log "reading the $2 conf $1"+ lineno=0+ while IFS= read -r line || [ -n "$line" ]; do+ lineno=$((lineno + 1))+ while :; do case "$line" in [[:space:]]*) line=${line#?} ;; *) break ;; esac; done+ while :; do case "$line" in *[[:space:]]) line=${line%?} ;; *) break ;; esac; done+ case "$line" in ''|'#'*) continue ;; esac+ key=${line%%=*}+ case "$line" in+ [A-Z]*=*) case "$key" in *[!A-Z0-9_]*) key="" ;; esac ;;+ *) key="" ;;+ esac+ if [ -z "$key" ]; then+ gamefix_log "$2 conf line $lineno rejected: not KEY=VALUE"+ continue+ fi+ value=${line#*=}+ reason=$(gamefix_reason "$key" "$value")+ if [ -n "$reason" ]; then+ gamefix_log "$2 conf line $lineno rejected $key: $reason"+ continue+ fi+ case " $gamefix_keys " in+ *" $key "*) gamefix_log "$2 conf line $lineno replaces the earlier $key" ;;+ *) gamefix_keys="${gamefix_keys:+$gamefix_keys }$key" ;;+ esac+ # key is [A-Z0-9_] only, so the eval names a variable and copies the value verbatim+ eval "gamefix_value_$key=\$value gamefix_from_$key=\$2"+ done < "$1"+}++gamefix_apply_env() {+ eval "launch_set=\${$1+x}"+ if [ -n "$launch_set" ]; then+ gamefix_log "$1 kept from the launch options, the $3 conf value is not applied"+ else+ export "$1=$2"+ gamefix_log "applied $1=$2 from the $3 conf"+ fi+}++load_gamefixes() {+ case "$app_id" in ''|0) return 0 ;; esac+ gamefix_read "$np_support/gamefixes-default/$app_id.conf" default+ gamefix_read "$np_support/gamefixes/$app_id.conf" user+ for key in $gamefix_keys; do+ eval "value=\$gamefix_value_$key from=\$gamefix_from_$key"+ # shellcheck disable=SC2154 # eval assigns from on the line above+ case "$key" in+ BACKEND) gamefix_backend=$value; gamefix_log "BACKEND=$value from the $from conf" ;;+ DLLOVERRIDES) gamefix_dlloverrides=$value+ gamefix_log "DLLOVERRIDES=$value from the $from conf, launch options still win per DLL" ;;+ MSYNC) gamefix_msync=$value; gamefix_log "MSYNC=$value from the $from conf" ;;+ ARGS)+ if [ "$verb" = waitforexitandrun ]; then+ gamefix_args=$value+ gamefix_log "ARGS=$value from the $from conf, added after the launch options' arguments"+ else+ gamefix_log "ARGS not applied, $verb is not the game launch"+ fi ;;+ RETINA) gamefix_apply_env NOTPROTON_RETINA "$value" "$from" ;;+ *) gamefix_apply_env "$key" "$value" "$from" ;;+ esac+ done+}++# Launch options > gamefix MSYNC > an engine with msync > the prefix's last choice > off.+resolve_msync() {+ msync_from=environment+ [ -z "$WINEMSYNC" ] || return 0+ engine_msync=0+ [ ! -e "$CX_ROOT/.notproton-msync" ] || engine_msync=1+ case "$gamefix_msync" in+ 0) WINEMSYNC=0; msync_from=gamefix; return 0 ;;+ 1)+ if [ "$engine_msync" -eq 1 ]; then WINEMSYNC=1; msync_from=gamefix; return 0; fi+ gamefix_log "MSYNC=1 not applied, the engine has no .notproton-msync" ;;+ esac+ if [ "$engine_msync" -eq 1 ]; then WINEMSYNC=1; msync_from=engine; return 0; fi+ if [ -r "$STEAM_COMPAT_DATA_PATH/notproton-msync" ]; then+ WINEMSYNC=$(tr -d ' \t\n' \+ < "$STEAM_COMPAT_DATA_PATH/notproton-msync" 2>/dev/null || true)+ msync_from=carried-over+ fi+ [ -n "$WINEMSYNC" ] || msync_from=default+}++# Graphics backends. The engine keeps Wine's own dxgi/d3d11/d3d10core/d3d12 in lib/wine and+# ships the alternatives under lib/notproton-backends/<name>/<arch>-windows. An engine+# without that folder bakes its DLLs into lib/wine, so nothing is swapped there.+backend_root="$CX_ROOT/lib/notproton-backends"+backend=""+backend_from=""+backend_overrides=""++graphics_log() {+ echo "graphics: $*" >> "$log" 2>&1 || true+}++# The lower-case module names of the DLLs in one backend folder, winemetal left to lib/wine.+backend_dlls() {+ for f in "$1"/*.[dD][lL][lL]; do+ [ -f "$f" ] || continue+ name=${f##*/}+ name=$(printf '%s' "${name%.*}" | tr '[:upper:]' '[:lower:]')+ case "$name" in ''|*[!a-z0-9_]*|winemetal) continue ;; esac+ printf '%s\n' "$name"+ done+}++# Every DLL some backend ships, so a copy one of them left in the prefix can be overridden.+managed_dlls() {+ {+ printf '%s\n' dxgi d3d11 d3d10core+ for dir in "$backend_root"/*/x86_64-windows "$backend_root"/*/i386-windows; do+ [ ! -d "$dir" ] || backend_dlls "$dir"+ done+ } | sort -u+}++backend_available() {+ case "$1" in+ wined3d) return 0 ;;+ d3dmetal) [ -f "$backend_root/d3dmetal.enabled" ] ;;+ dxmt|dxvk) [ -n "$(backend_dlls "$backend_root/$1/x86_64-windows")" ] ;;+ *) return 1 ;;+ esac+}++backend_record() {+ record="$STEAM_COMPAT_DATA_PATH/notproton-backend"+ [ -n "$STEAM_COMPAT_DATA_PATH" ] && [ -f "$record" ] && [ ! -L "$record" ] || return 1+ recorded=$(sed -n 1p "$record" 2>/dev/null) || return 1+ case "$recorded" in+ dxmt|dxvk|wined3d|d3dmetal|dxmt-builtin) printf '%s' "$recorded" ;;+ *) return 1 ;;+ esac+}++# One little-endian unsigned word of 1, 2 or 4 bytes, inside the file only.+pe_word() {+ [ "$2" -ge 0 ] && [ $(($2 + $3)) -le "$pe_size" ] || return 1+ word=$(od -A n -t "u$3" -j "$2" -N "$3" "$1" 2>/dev/null | tr -d ' \n')+ case "$word" in ''|*[!0-9]*) return 1 ;; esac+ printf '%s' "$word"+}++# Count 4-byte words, all of them inside the file, space-separated.+pe_words() {+ [ "$2" -ge 0 ] && [ $(($2 + $3 * 4)) -le "$pe_size" ] || return 1+ od -A n -v -t u4 -j "$2" -N $(($3 * 4)) "$1" 2>/dev/null | tr -s ' \n' ' '+}++# The file offset of an RVA, from the section table words in pe_sections.+pe_rva_offset() {+ rva=$1+ # shellcheck disable=SC2086 # the table is a list of numbers and has to split+ set -- $pe_sections+ while [ "$#" -ge 10 ]; do+ span=$3+ [ "$5" -le "$span" ] || span=$5+ if [ "$rva" -ge "$4" ] && [ "$rva" -lt $(($4 + span)) ]; then+ [ $((rva - $4)) -lt "$5" ] || return 1+ offset=$((rva - $4 + $6))+ [ "$offset" -lt "$pe_size" ] || return 1+ printf '%s' "$offset"+ return 0+ fi+ shift 10+ done+ return 1+}++# A game whose exe imports d3d12.dll is D3D12, which needs Wine's own dxgi (vkd3d), since+# DXMT's dxgi refuses swap chains for devices it did not make. Only the static import+# table counts, and anything that does not parse as a PE detects nothing.+imports_d3d12() {+ pe=$1+ [ -f "$pe" ] || return 1+ pe_size=$(stat -f %z "$pe" 2>/dev/null) || return 1+ [ "$(od -A n -t x1 -N 2 "$pe" 2>/dev/null | tr -d ' \n')" = 4d5a ] || return 1+ header=$(pe_word "$pe" 60 4) || return 1+ [ "$(od -A n -t x1 -j "$header" -N 4 "$pe" 2>/dev/null | tr -d ' \n')" = 50450000 ] || return 1+ section_count=$(pe_word "$pe" $((header + 6)) 2) || return 1+ optional_size=$(pe_word "$pe" $((header + 20)) 2) || return 1+ optional=$((header + 24))+ case "$(pe_word "$pe" "$optional" 2)" in+ 267) directories=$((optional + 96)) ;;+ 523) directories=$((optional + 112)) ;;+ *) return 1 ;;+ esac+ directory_count=$(pe_word "$pe" $((directories - 4)) 4) || return 1+ [ "$directory_count" -ge 2 ] && [ $((directories + 16)) -le $((optional + optional_size)) ] || return 1+ import_rva=$(pe_word "$pe" $((directories + 8)) 4) || return 1+ [ "$import_rva" -gt 0 ] && [ "$section_count" -ge 1 ] && [ "$section_count" -le 96 ] || return 1+ pe_sections=$(pe_words "$pe" $((optional + optional_size)) $((section_count * 10))) || return 1+ imports=$(pe_rva_offset "$import_rva") || return 1+ descriptors=$(((pe_size - imports) / 20))+ [ "$descriptors" -le 512 ] || descriptors=512+ [ "$descriptors" -ge 1 ] || return 1+ table=$(pe_words "$pe" "$imports" $((descriptors * 5))) || return 1+ # shellcheck disable=SC2086 # the table is a list of numbers and has to split+ set -- $table+ while [ "$#" -ge 5 ]; do+ [ "$1$4$5" != 000 ] || return 1+ if [ "$4" -gt 0 ] && name_at=$(pe_rva_offset "$4"); then+ module=$(dd if="$pe" bs=1 skip="$name_at" count=16 2>/dev/null \+ | LC_ALL=C tr '\0' '\n' | head -n 1 | LC_ALL=C tr '[:upper:]' '[:lower:]')+ [ "$module" != d3d12.dll ] || return 0+ fi+ shift 5+ done+ return 1+}++# NOTPROTON_BACKEND > CX_GRAPHICS_BACKEND > gamefix BACKEND > auto-detect > dxmt, then down+# to what the engine has.+select_backend() {+ wanted=""+ backend_from=""+ if [ ! -d "$backend_root" ]; then+ backend=dxmt-builtin+ backend_from="legacy engine layout, no lib/notproton-backends"+ if [ -n "${NOTPROTON_BACKEND:-}$gamefix_backend" ]; then+ graphics_log "requested backend ${NOTPROTON_BACKEND:-$gamefix_backend} ignored, the engine bakes its graphics DLLs into lib/wine"+ fi+ return 0+ fi+ case "${NOTPROTON_BACKEND:-}" in+ '') ;;+ dxmt|dxvk|wined3d|d3dmetal)+ wanted=$NOTPROTON_BACKEND+ backend_from="NOTPROTON_BACKEND in the launch options" ;;+ *) graphics_log "NOTPROTON_BACKEND is not dxmt, dxvk, wined3d or d3dmetal, ignored" ;;+ esac+ # The Steam panel's Graphics menu writes CX_GRAPHICS_BACKEND.+ if [ -z "$wanted" ] && [ -n "${CX_GRAPHICS_BACKEND:-}" ]; then+ case "$(printf '%s' "$CX_GRAPHICS_BACKEND" | tr '[:upper:]' '[:lower:]')" in+ d3dmetal) wanted=d3dmetal ;;+ dxmt) wanted=dxmt ;;+ dxvk) wanted=dxvk ;;+ wined3d|opengl|wine) wanted=wined3d ;;+ *) graphics_log "CX_GRAPHICS_BACKEND is not a backend this engine maps, ignored" ;;+ esac+ [ -z "$wanted" ] || backend_from="CX_GRAPHICS_BACKEND in the launch options"+ fi+ if [ -z "$wanted" ] && [ -n "$gamefix_backend" ]; then+ wanted=$gamefix_backend+ backend_from="BACKEND in the gamefix conf"+ fi+ # A helper has no game to inspect, so it keeps what the game last ran with.+ if [ -z "$wanted" ] && [ "$verb" != waitforexitandrun ] \+ && recorded=$(backend_record) && [ "$recorded" != dxmt-builtin ]; then+ wanted=$recorded+ backend_from="carried over from the last launch"+ fi+ if [ -z "$wanted" ] && [ "$verb" = waitforexitandrun ] && [ -f "$1" ]; then+ if imports_d3d12 "$1"; then+ wanted=wined3d+ backend_from="auto-detected, the game imports d3d12.dll"+ else+ wanted=dxmt+ backend_from="auto-detected, the game does not import d3d12.dll"+ fi+ fi+ if [ -z "$wanted" ]; then+ wanted=dxmt+ backend_from=default+ fi+ backend=$wanted+ while ! backend_available "$backend"; do+ case "$backend" in+ d3dmetal) why="no d3dmetal.enabled marker"; next=dxmt ;;+ dxvk) why="no x86_64 DLLs in notproton-backends/dxvk"; next=dxmt ;;+ *) why="no x86_64 DLLs in notproton-backends/$backend"; next=wined3d ;;+ esac+ graphics_log "$backend is not available ($why), falling back to $next"+ backend_from="$backend_from, fell back from $backend"+ backend=$next+ done+}++# Returns 0 when the destination already matches or was replaced.+stage_backend_file() {+ [ -f "$1" ] && [ ! -d "$2" ] || return 1+ if [ -f "$2" ] && [ ! -L "$2" ] \+ && [ "$(stat -f %z "$1" 2>/dev/null)" = "$(stat -f %z "$2" 2>/dev/null)" ] \+ && cmp -s "$1" "$2"; then+ return 0+ fi+ staging="$2.notproton.$$"+ rm -f "$staging" 2>/dev/null || true+ if { cp -c -f "$1" "$staging" 2>/dev/null || cp -f "$1" "$staging" 2>> "$log"; } \+ && mv -f "$staging" "$2" 2>> "$log"; then+ graphics_log "staged ${1#"$CX_ROOT/"} as ${2#"$WINEPREFIX/"}"+ return 0+ fi+ rm -f "$staging" 2>/dev/null || true+ return 1+}++# A prefix copy identical to some backend's DLL was put there by a launch, so it goes+# back to Wine's own. Anything else in the prefix is left alone.+restore_stock_dll() {+ [ -f "$3" ] && [ ! -L "$3" ] || return 0+ stock="$CX_ROOT/lib/wine/$1/$2.dll"+ [ -f "$stock" ] || return 0+ ! cmp -s "$stock" "$3" || return 0+ for theirs in "$backend_root"/*/"$1"/*.[dD][lL][lL]; do+ [ -f "$theirs" ] || continue+ base=${theirs##*/}+ [ "$(printf '%s' "${base%.*}" | tr '[:upper:]' '[:lower:]')" = "$2" ] || continue+ if cmp -s "$theirs" "$3"; then+ stage_backend_file "$stock" "$3"+ return+ fi+ done+ return 0+}++# Copies the chosen backend's DLLs into the prefix and sets them native, and sets every+# other DLL a backend could have left there builtin.+activate_backend() {+ backend_overrides=""+ [ "$backend" != dxmt-builtin ] || return 0+ managed=$(managed_dlls)+ shipped=""+ case "$backend" in+ dxmt|dxvk) shipped=$({ backend_dlls "$backend_root/$backend/x86_64-windows"+ backend_dlls "$backend_root/$backend/i386-windows"; } | sort -u | tr '\n' ' ') ;;+ esac+ staging_failed=0+ for pair in x86_64-windows:system32 i386-windows:syswow64; do+ arch=${pair%%:*}+ dir="$WINEPREFIX/drive_c/windows/${pair##*:}"+ [ -n "$WINEPREFIX" ] && [ -d "$dir" ] || continue+ ships=""+ case "$backend" in+ dxmt|dxvk) ships=$(backend_dlls "$backend_root/$backend/$arch" | tr '\n' ' ') ;;+ esac+ for name in $managed; do+ case " $ships " in+ *" $name "*)+ if ! stage_backend_file "$backend_root/$backend/$arch/$name.dll" "$dir/$name.dll"; then+ graphics_log "could not stage $backend $arch/$name.dll into the prefix"+ staging_failed=1+ fi ;;+ *)+ restore_stock_dll "$arch" "$name" "$dir/$name.dll" \+ || graphics_log "could not restore Wine's $arch/$name.dll in the prefix" ;;+ esac+ done+ done+ if [ "$staging_failed" -eq 1 ]; then+ graphics_log "$backend could not be staged, falling back to wined3d"+ backend=wined3d+ backend_from="$backend_from, fell back after staging failed"+ activate_backend+ return+ fi+ native=""+ builtin=""+ for name in $managed; do+ case " $shipped " in+ *" $name "*) native="${native:+$native,}$name" ;;+ *) builtin="${builtin:+$builtin,}$name" ;;+ esac+ done+ backend_overrides="${native:+$native=n,b}"+ [ -z "$builtin" ] || backend_overrides="${backend_overrides:+$backend_overrides;}$builtin=b"+ if [ "$backend" = d3dmetal ]; then+ if [ -n "${CX_GRAPHICS_BACKEND:-}" ] && [ "$CX_GRAPHICS_BACKEND" != d3dmetal ]; then+ graphics_log "CX_GRAPHICS_BACKEND=$CX_GRAPHICS_BACKEND replaced by d3dmetal"+ fi+ export CX_GRAPHICS_BACKEND=d3dmetal+ fi+}++record_backend() {+ [ -n "$STEAM_COMPAT_DATA_PATH" ] || return 0+ record="$STEAM_COMPAT_DATA_PATH/notproton-backend"+ [ ! -L "$record" ] || return 0+ previous=$(backend_record) || previous=""+ if [ -n "$previous" ] && [ "$previous" != "$backend" ]; then+ graphics_log "backend switched from $previous to $backend"+ fi+ if ! { printf '%s\n%s\n' "$backend" "$backend_from" > "$record.new" \+ && mv -f "$record.new" "$record"; } 2>/dev/null; then+ rm -f "$record.new" 2>/dev/null || true+ graphics_log "could not record the backend in $record"+ fi+}++# Last entry wins: backend, then the gamefix conf, then the launch options.+compose_dll_overrides() {+ composed=$backend_overrides+ for part in "$gamefix_dlloverrides" "${WINEDLLOVERRIDES:-}"; do+ [ -n "$part" ] || continue+ composed="${composed:+$composed;}$part"+ done+ [ -z "$composed" ] || export WINEDLLOVERRIDES="$composed"+}++load_gamefixes || true+# Steam does not set SteamAppId or SteamGameId for helpers like the install-script# evaluator. If they are set, SteamAPI_Init registers the helper as the running game so the# real launch fails with AppError_16. Not applicable to non-Steam shortcuts, which come in@@ -883,13 +1345,7 @@ if [ -n "$STEAM_COMPAT_DATA_PATH" ]; thenexport WINEPREFIX="$STEAM_COMPAT_DATA_PATH/pfx"stage_step="prefix lock"prepare_prefix_directory- msync_from=environment- if [ -z "$WINEMSYNC" ] && [ -r "$STEAM_COMPAT_DATA_PATH/notproton-msync" ]; then- WINEMSYNC=$(tr -d ' \t\n' \- < "$STEAM_COMPAT_DATA_PATH/notproton-msync" 2>/dev/null || true)- msync_from=carried-over- fi- [ -n "$WINEMSYNC" ] || msync_from=default+ resolve_msyncexport WINEMSYNC="${WINEMSYNC:-0}"printf '%s' "$WINEMSYNC" \> "$STEAM_COMPAT_DATA_PATH/notproton-msync" 2>/dev/null || true@@ -917,6 +1373,14 @@ if [ -n "$STEAM_COMPAT_DATA_PATH" ]; thenmap_game_drivefi+stage_step="graphics backend"+select_backend "$1"+activate_backend || true+record_backend || true+graphics_log "backend=$backend ($backend_from)"+compose_dll_overrides+[ -z "$backend_overrides" ] || graphics_log "backend overrides $backend_overrides"+bridge_src="$np_support/bridge"prefix_steam="$WINEPREFIX/drive_c/Program Files (x86)/Steam"verify_runner() {@@ -1374,13 +1838,18 @@ terminate() {trap terminate TERM INT HUPgame_cwd="$(pwd)"+if [ -n "$gamefix_args" ]; then+ # shellcheck disable=SC2086 # ARGS tokens hold no spaces or glob characters and have to split+ set -- "$@" $gamefix_args+ echo "gamefix: game arguments are now: $*" >> "$log" 2>&1 || true+fiif [ -n "$STEAM_DYLD_INSERT_LIBRARIES" ]; thenecho "=== overlay injected from $STEAM_DYLD_INSERT_LIBRARIES ===" >> "$log" 2>&1 || trueelseecho "=== client staged no overlay renderer, overlay disabled ===" >> "$log" 2>&1 || truefiset -- --args "$shim_exe" "$@"-for name in $(env | sed -nE 's/^(CX_APPLEGPTK_LIBD3DSHARED_PATH|Steam[A-Za-z0-9]*|(CX_GRAPHICS|D3DM_|DXMT_|DXVK_|MTL_|ROSETTA_)[A-Z0-9_]*)=.*/\1/p'); do+for name in $(env | sed -nE 's/^(CX_APPLEGPTK_LIBD3DSHARED_PATH|WINE_LARGE_ADDRESS_AWARE|WINE_CPU_TOPOLOGY|Steam[A-Za-z0-9]*|(CX_GRAPHICS|D3DM_|DXMT_|DXVK_|MVK_|VKD3D_|STAGING_|MTL_|ROSETTA_)[A-Z0-9_]*)=.*/\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.shnew file mode 100644index 0000000..71c22f1--- /dev/null+++ b/dylib/tests/gamefixescheck.sh@@ -0,0 +1,433 @@+#!/bin/sh+# shellcheck disable=SC2016 # the sh -ec programs expand their own variables+set -e+SRC="${1:-$(dirname "$0")/../feats/compat_run.sh}"+[ -f "$SRC" ] || { echo "gamefixescheck: $SRC not present, skipped"; exit 0; }++functions=""+for name in gamefix_log valid_dll_overrides gamefix_reason gamefix_read gamefix_apply_env \+ load_gamefixes resolve_msync graphics_log 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+ body=$(sed -n "/^$name() {\$/,/^}\$/p" "$SRC")+ [ -n "$body" ] || { echo "FAIL: $name not found in $SRC"; exit 1; }+ functions="$functions+$body"+done+bridge_line=$(grep 'export WINEDLLOVERRIDES=' "$SRC" | grep 'lsteamclient=b' | sed 's/^[[:space:]]*//')+[ -n "$bridge_line" ] || { echo "FAIL: the bridge WINEDLLOVERRIDES line not found"; exit 1; }+forward=$(sed -n '/^for name in $(env /,/^done$/p' "$SRC")+[ -n "$forward" ] || { echo "FAIL: the launcher environment loop not found"; exit 1; }+append_args=$(sed -n '/^if \[ -n "\$gamefix_args" \]; then$/,/^fi$/p' "$SRC")+[ -n "$append_args" ] || { echo "FAIL: the ARGS append not found"; exit 1; }++work=$(mktemp -d)+trap 'rm -rf "$work"' EXIT++fails=0+ok() { printf ' ok %s\n' "$1"; }+bad() { printf ' FAIL %s\n want [%s]\n got [%s]\n' "$1" "$2" "$3"; fails=$((fails + 1)); }+is() { if [ "$2" = "$3" ]; then ok "$1"; else bad "$1" "$2" "$3"; fi; }+has() { if grep -qF -- "$2" "$3"; then ok "$1"; else bad "$1" "a line with $2" "$(cat "$3")"; fi; }+lacks() { if grep -qF -- "$2" "$3"; then bad "$1" "no line with $2" "$(cat "$3")"; else ok "$1"; fi; }++# A fresh compatdata, support folder and engine per case. LAYOUT is a list of+# backend/arch/name.dll files, "legacy" for no notproton-backends folder.+case_dir=""+new_case() {+ case_dir=$(mktemp -d "$work/case.XXXXXX")+ mkdir -p "$case_dir/support/gamefixes-default" "$case_dir/support/gamefixes" \+ "$case_dir/data/pfx/drive_c/windows/system32" "$case_dir/data/pfx/drive_c/windows/syswow64" \+ "$case_dir/game"+ for arch in x86_64-windows i386-windows; do+ mkdir -p "$case_dir/engine/lib/wine/$arch"+ for dll in dxgi d3d11 d3d10core d3d12 d3d9; do+ printf 'stock %s %s\n' "$arch" "$dll" > "$case_dir/engine/lib/wine/$arch/$dll.dll"+ done+ done+ : > "$case_dir/log"+ printf 'MZ plain d3d11 game\n' > "$case_dir/game/game.exe"+}+engine() {+ for file in "$@"; do+ case "$file" in+ d3dmetal.enabled) mkdir -p "$case_dir/engine/lib/notproton-backends"+ : > "$case_dir/engine/lib/notproton-backends/d3dmetal.enabled" ;;+ msync) : > "$case_dir/engine/.notproton-msync" ;;+ empty) mkdir -p "$case_dir/engine/lib/notproton-backends" ;;+ *) mkdir -p "$case_dir/engine/lib/notproton-backends/${file%/*}"+ printf 'backend %s\n' "$file" > "$case_dir/engine/lib/notproton-backends/$file" ;;+ esac+ done+}+full_engine() {+ engine dxmt/x86_64-windows/dxgi.dll dxmt/x86_64-windows/d3d11.dll \+ dxmt/x86_64-windows/d3d10core.dll dxmt/x86_64-windows/winemetal.dll \+ dxvk/x86_64-windows/d3d11.dll dxvk/x86_64-windows/d3d10core.dll \+ dxvk/i386-windows/d3d11.dll dxvk/i386-windows/d3d10core.dll+}+default_conf() { printf '%s\n' "$@" > "$case_dir/support/gamefixes-default/4242.conf"; }+user_conf() { printf '%s\n' "$@" > "$case_dir/support/gamefixes/4242.conf"; }+sys() { cat "$case_dir/data/pfx/drive_c/windows/$1/$2.dll" 2>/dev/null || echo missing; }++# Runs the script's sequence: conf, msync, backend, overrides, bridge trio. ENV holds the+# launch options. Prints KEY=value lines for the outcome.+launch() {+ verb=$1+ target=$2+ shift 2+ env -i PATH="$PATH" HOME="$HOME" "$@" \+ functions="$functions" bridge_line="$bridge_line" \+ app_id=4242 verb="$verb" log="$case_dir/log" \+ np_support="$case_dir/support" CX_ROOT="$case_dir/engine" \+ STEAM_COMPAT_DATA_PATH="$case_dir/data" WINEPREFIX="$case_dir/data/pfx" \+ sh -ec '+ eval "$functions"+ gamefix_keys="" gamefix_backend="" gamefix_dlloverrides="" gamefix_msync="" gamefix_args=""+ backend_root="$CX_ROOT/lib/notproton-backends"+ load_gamefixes || true+ resolve_msync+ export WINEMSYNC="${WINEMSYNC:-0}"+ select_backend "$1"+ activate_backend || true+ record_backend || true+ graphics_log "backend=$backend ($backend_from)"+ compose_dll_overrides+ eval "$bridge_line"+ for v in backend WINEDLLOVERRIDES WINEMSYNC msync_from NOTPROTON_RETINA CX_GRAPHICS_BACKEND \+ DXVK_HUD VKD3D_CONFIG WINEDEBUG MTL_HUD_ENABLED gamefix_args; do+ eval "printf \"%s=%s\\n\" \$v \"\${$v-<unset>}\""+ done+ ' launch "$target" > "$case_dir/out" 2>&1 || echo "launch exited $?" >> "$case_dir/out"+}+got() { sed -n "s/^$1=//p" "$case_dir/out"; }+trio="steamclient=n;steamclient64=n;lsteamclient=b"++# Minimal PE images: one .rdata section at RVA 0x1000 (file 0x200) holding the import+# descriptors, KERNEL32.dll at file 0x300 and the string D3D12.dll at file 0x310. "import"+# lists D3D12.dll as a second descriptor, "string" only carries the string.+le() {+ v=$1 n=$2 bytes=""+ while [ "$n" -gt 0 ]; do+ bytes="$bytes$(printf '\\%03o' $((v & 255)))"+ v=$((v >> 8)) n=$((n - 1))+ done+ printf '%s' "$bytes"+}+put() {+ # shellcheck disable=SC2059 # the escapes are the bytes to write+ printf "$3" | dd of="$1" bs=1 seek="$2" conv=notrunc 2>/dev/null+}+pe_fixture() {+ dd if=/dev/zero of="$1" bs=1024 count=1 2>/dev/null+ put "$1" 0 'MZ'+ put "$1" 60 "$(le 64 4)"+ put "$1" 64 'PE\000\000'+ put "$1" 68 "$(le 34404 2)"+ put "$1" 70 "$(le 1 2)"+ if [ "$2" = 64 ]; then osize=240 magic=523 dirs=200; else osize=224 magic=267 dirs=184; fi+ put "$1" 84 "$(le "$osize" 2)"+ put "$1" 88 "$(le "$magic" 2)"+ put "$1" $((dirs - 4)) "$(le 16 4)"+ put "$1" $((dirs + 8)) "$(le 4096 4)"+ put "$1" $((dirs + 12)) "$(le 60 4)"+ sec=$((88 + osize))+ put "$1" "$sec" '.rdata'+ put "$1" $((sec + 8)) "$(le 512 4)"+ put "$1" $((sec + 12)) "$(le 4096 4)"+ put "$1" $((sec + 16)) "$(le 512 4)"+ put "$1" $((sec + 20)) "$(le 512 4)"+ put "$1" 524 "$(le 4352 4)"+ put "$1" 528 "$(le 4480 4)"+ put "$1" 768 'KERNEL32.dll\000'+ put "$1" 784 'D3D12.dll\000'+ if [ "$3" = import ]; then+ put "$1" 544 "$(le 4368 4)"+ put "$1" 548 "$(le 4488 4)"+ fi+}++echo "== parser: allow-list and rejections"+new_case+full_engine+default_conf '# shipped fix' '' ' DXVK_HUD=fps ' "VKD3D_CONFIG=dxr$(printf '\r')" \+ 'WINEDEBUG=-all' 'PATH=/evil' 'DYLD_INSERT_LIBRARIES=/evil.dylib' 'lower=1' 'no equals sign' \+ "DXMT_A=\$(touch $case_dir/pwned)" 'DXMT_B=`touch pwned`' 'DXMT_C="quoted"' "DXMT_D='single'" \+ 'BACKEND=vulkan' 'MSYNC=2' 'RETINA=yes' 'DLLOVERRIDES=dxgi=native' 'DLLOVERRIDES=;=n' \+ 'DXMT_=1' 'MTL_HUD_ENABLED=1'+launch waitforexitandrun "$case_dir/game/game.exe"+is "a padded value is trimmed" "fps" "$(got DXVK_HUD)"+is "a CRLF line ends cleanly" "dxr" "$(got VKD3D_CONFIG)"+is "WINEDEBUG is allowed" "-all" "$(got WINEDEBUG)"+is "MTL_HUD_ENABLED is allowed" "1" "$(got MTL_HUD_ENABLED)"+is "PATH is not on the allow-list" "0" "$(grep -c '^PATH=/evil' "$case_dir/out" || true)"+has "PATH is logged as rejected" "line 6 rejected PATH: not on the allow-list" "$case_dir/log"+has "DYLD_INSERT_LIBRARIES is rejected" "rejected DYLD_INSERT_LIBRARIES: not on the allow-list" "$case_dir/log"+has "a lower-case key is rejected" "line 8 rejected: not KEY=VALUE" "$case_dir/log"+has "a line without = is rejected" "line 9 rejected: not KEY=VALUE" "$case_dir/log"+has "\$( is rejected" "rejected DXMT_A: a backtick" "$case_dir/log"+is "and never runs" "no" "$([ -e "$case_dir/pwned" ] && echo yes || echo no)"+has "a backtick is rejected" "rejected DXMT_B: a backtick" "$case_dir/log"+has "double quotes are rejected" "rejected DXMT_C: a backtick" "$case_dir/log"+has "single quotes are rejected" "rejected DXMT_D: a backtick" "$case_dir/log"+has "an unknown backend is rejected" "rejected BACKEND: not dxmt, dxvk, wined3d or d3dmetal" "$case_dir/log"+has "MSYNC must be 0 or 1" "rejected MSYNC: not 0 or 1" "$case_dir/log"+has "RETINA must be 0 or 1" "rejected RETINA: not 0 or 1" "$case_dir/log"+has "a bad override order is rejected" "line 17 rejected DLLOVERRIDES: not Wine override syntax" "$case_dir/log"+has "an override without a name is rejected" "line 18 rejected DLLOVERRIDES: not Wine override syntax" "$case_dir/log"+has "a bare prefix is not a variable" "rejected DXMT_: not on the allow-list" "$case_dir/log"+has "applied values are logged" "applied DXVK_HUD=fps from the default conf" "$case_dir/log"++echo "== precedence: launch options > user conf > default conf > auto > default"+new_case+full_engine+default_conf 'DXVK_HUD=1' 'BACKEND=dxmt' 'WINEDEBUG=+loaddll' 'DLLOVERRIDES=xinput1_3=n,b;dinput8=n,b'+user_conf 'DXVK_HUD=fps' 'BACKEND=dxvk' 'DLLOVERRIDES=dinput8=b'+launch waitforexitandrun "$case_dir/game/game.exe" WINEDEBUG=-all+is "user conf beats default conf" "fps" "$(got DXVK_HUD)"+is "launch options beat both confs" "-all" "$(got WINEDEBUG)"+has "the kept launch option is logged" "WINEDEBUG kept from the launch options, the default conf value is not applied" "$case_dir/log"+has "the user conf replacing a key is logged" "user conf line 1 replaces the earlier DXVK_HUD" "$case_dir/log"+is "user conf BACKEND beats default conf BACKEND" "dxvk" "$(got backend)"+is "the later file wins DLLOVERRIDES whole" \+ "d3d10core,d3d11=n,b;dxgi=b;dinput8=b;$trio" "$(got WINEDLLOVERRIDES)"+new_case+full_engine+user_conf 'BACKEND=dxvk' 'DLLOVERRIDES=dinput8=n,b;dxgi=n'+launch waitforexitandrun "$case_dir/game/game.exe" NOTPROTON_BACKEND=wined3d WINEDLLOVERRIDES='dinput8=b'+is "NOTPROTON_BACKEND beats the conf" "wined3d" "$(got backend)"+is "overrides run backend, conf, launch options, then the Steam trio" \+ "d3d10core,d3d11,dxgi=b;dinput8=n,b;dxgi=n;dinput8=b;$trio" "$(got WINEDLLOVERRIDES)"+new_case+full_engine+default_conf 'BACKEND=dxvk'+pe_fixture "$case_dir/game/game.exe" 64 import+launch waitforexitandrun "$case_dir/game/game.exe"+is "a conf BACKEND beats auto-detection" "dxvk" "$(got backend)"+new_case+full_engine+launch waitforexitandrun "$case_dir/game/game.exe" NOTPROTON_BACKEND=metal+is "an invalid NOTPROTON_BACKEND falls through to auto" "dxmt" "$(got backend)"+has "and is logged" "NOTPROTON_BACKEND is not dxmt, dxvk, wined3d or d3dmetal, ignored" "$case_dir/log"++echo "== auto-detect reads the import table"+new_case+full_engine+pe_fixture "$case_dir/game/game.exe" 64 import+launch waitforexitandrun "$case_dir/game/game.exe"+is "a PE32+ game importing D3D12.dll gets wined3d" "wined3d" "$(got backend)"+has "the reason is logged" "auto-detected, the game imports d3d12.dll" "$case_dir/log"+pe_fixture "$case_dir/game/game.exe" 32 import+launch waitforexitandrun "$case_dir/game/game.exe"+is "so does a PE32 game" "wined3d" "$(got backend)"+pe_fixture "$case_dir/game/game.exe" 64 string+launch waitforexitandrun "$case_dir/game/game.exe"+is "the string d3d12.dll in .rdata alone does not count" "dxmt" "$(got backend)"+pe_fixture "$case_dir/game/game.exe" 32 string+launch waitforexitandrun "$case_dir/game/game.exe"+is "nor in a PE32 game" "dxmt" "$(got backend)"+pe_fixture "$case_dir/game/game.exe" 64 import+dd if="$case_dir/game/game.exe" of="$case_dir/game/cut.exe" bs=600 count=1 2>/dev/null+launch waitforexitandrun "$case_dir/game/cut.exe"+is "an import name cut off by a short file detects nothing" "dxmt" "$(got backend)"+dd if="$case_dir/game/game.exe" of="$case_dir/game/cut.exe" bs=100 count=1 2>/dev/null+launch waitforexitandrun "$case_dir/game/cut.exe"+is "a header cut off detects nothing" "dxmt" "$(got backend)"+put "$case_dir/game/game.exe" 60 "$(le 4000000000 4)"+launch waitforexitandrun "$case_dir/game/game.exe"+is "a PE header offset past the end detects nothing" "dxmt" "$(got backend)"+printf 'MZ\0\0kernel32.dll\0D3D12.DLL\0' > "$case_dir/game/game.exe"+launch waitforexitandrun "$case_dir/game/game.exe"+is "an MZ file that is no PE detects nothing" "dxmt" "$(got backend)"+pe_fixture "$case_dir/game/game.exe" 64 string+pe_fixture "$case_dir/game/Engine.dll" 64 import+launch waitforexitandrun "$case_dir/game/game.exe"+is "a DLL beside the game does not count" "dxmt" "$(got backend)"+new_case+full_engine+pe_fixture "$case_dir/game/game.exe" 64 import+launch waitforexitandrun "$case_dir/game/game.exe" NOTPROTON_BACKEND=dxmt+is "NOTPROTON_BACKEND beats auto-detection" "dxmt" "$(got backend)"+new_case+full_engine+launch waitforexitandrun 'steam://rungameid/4242'+is "a target that is no file gets the default" "dxmt" "$(got backend)"+has "logged as default" "backend=dxmt (default)" "$case_dir/log"+new_case+full_engine+pe_fixture "$case_dir/game/game.exe" 64 import+launch waitforexitandrun "$case_dir/game/game.exe"+launch run "$case_dir/game/iscriptevaluator.exe"+is "a helper keeps the backend the game last ran with" "wined3d" "$(got backend)"++echo "== the Steam panel's CX_GRAPHICS_BACKEND"+new_case+full_engine+engine d3dmetal.enabled+user_conf 'BACKEND=dxmt'+for pair in D3DMetal:d3dmetal dxmt:dxmt DXVK:dxvk wined3d:wined3d OpenGL:wined3d wine:wined3d; do+ launch waitforexitandrun "$case_dir/game/game.exe" CX_GRAPHICS_BACKEND="${pair%%:*}"+ is "CX_GRAPHICS_BACKEND=${pair%%:*} beats the conf as ${pair#*:}" "${pair#*:}" "$(got backend)"+done+launch waitforexitandrun "$case_dir/game/game.exe" CX_GRAPHICS_BACKEND=D3DMetal+is "d3dmetal still exports the lower-case name" "d3dmetal" "$(got CX_GRAPHICS_BACKEND)"+launch waitforexitandrun "$case_dir/game/game.exe" CX_GRAPHICS_BACKEND=vulkan+is "an unknown value falls through to the conf" "dxmt" "$(got backend)"+has "and is logged" "CX_GRAPHICS_BACKEND is not a backend this engine maps, ignored" "$case_dir/log"+launch waitforexitandrun "$case_dir/game/game.exe" CX_GRAPHICS_BACKEND=+is "an empty value falls through to the conf" "dxmt" "$(got backend)"+launch waitforexitandrun "$case_dir/game/game.exe" CX_GRAPHICS_BACKEND=dxvk NOTPROTON_BACKEND=wined3d+is "NOTPROTON_BACKEND beats CX_GRAPHICS_BACKEND" "wined3d" "$(got backend)"++echo "== fallback when the engine lacks a backend"+new_case+engine dxmt/x86_64-windows/dxgi.dll dxmt/x86_64-windows/d3d11.dll dxmt/x86_64-windows/d3d10core.dll+launch waitforexitandrun "$case_dir/game/game.exe" NOTPROTON_BACKEND=dxvk+is "dxvk falls back to dxmt" "dxmt" "$(got backend)"+has "with the reason" "dxvk is not available (no x86_64 DLLs in notproton-backends/dxvk), falling back to dxmt" "$case_dir/log"+new_case+engine empty+launch waitforexitandrun "$case_dir/game/game.exe" NOTPROTON_BACKEND=dxvk+is "dxvk falls through dxmt to wined3d" "wined3d" "$(got backend)"+new_case+engine dxvk/x86_64-windows/d3d11.dll+launch waitforexitandrun "$case_dir/game/game.exe"+is "the dxmt default falls back to wined3d" "wined3d" "$(got backend)"+new_case+full_engine+launch waitforexitandrun "$case_dir/game/game.exe" NOTPROTON_BACKEND=d3dmetal+is "d3dmetal without the marker falls back to dxmt" "dxmt" "$(got backend)"+is "and leaves CX_GRAPHICS_BACKEND alone" "<unset>" "$(got CX_GRAPHICS_BACKEND)"+new_case+full_engine+engine d3dmetal.enabled+launch waitforexitandrun "$case_dir/game/game.exe" NOTPROTON_BACKEND=d3dmetal+is "d3dmetal with the marker" "d3dmetal" "$(got backend)"+is "selects D3DMetal in the engine" "d3dmetal" "$(got CX_GRAPHICS_BACKEND)"+is "and keeps every backend DLL builtin" "d3d10core,d3d11,dxgi=b;$trio" "$(got WINEDLLOVERRIDES)"+launch waitforexitandrun "$case_dir/game/game.exe" NOTPROTON_BACKEND=d3dmetal CX_GRAPHICS_BACKEND=dxmt+is "NOTPROTON_BACKEND=d3dmetal sets CX_GRAPHICS_BACKEND over the panel's" "d3dmetal" "$(got CX_GRAPHICS_BACKEND)"+has "and says so" "CX_GRAPHICS_BACKEND=dxmt replaced by d3dmetal" "$case_dir/log"++echo "== legacy layout"+new_case+user_conf 'BACKEND=dxvk' 'DLLOVERRIDES=dinput8=n,b'+cp "$case_dir/engine/lib/wine/x86_64-windows/dxgi.dll" "$case_dir/data/pfx/drive_c/windows/system32/dxgi.dll"+launch waitforexitandrun "$case_dir/game/game.exe"+is "the backend is the baked-in one" "dxmt-builtin" "$(got backend)"+is "only the conf and the trio reach the overrides" "dinput8=n,b;$trio" "$(got WINEDLLOVERRIDES)"+is "nothing is copied" "stock x86_64-windows dxgi" "$(sys system32 dxgi)"+has "the ignored request is logged" "requested backend dxvk ignored" "$case_dir/log"+is "the state file records it" "dxmt-builtin" "$(sed -n 1p "$case_dir/data/notproton-backend")"++echo "== activation and switching"+new_case+full_engine+launch waitforexitandrun "$case_dir/game/game.exe"+is "dxmt sets what it ships native" "d3d10core,d3d11,dxgi=n,b;$trio" "$(got WINEDLLOVERRIDES)"+is "dxmt dxgi is in system32" "backend dxmt/x86_64-windows/dxgi.dll" "$(sys system32 dxgi)"+is "winemetal stays with Wine" "missing" "$(sys system32 winemetal)"+is "dxmt has no i386, syswow64 is untouched" "missing" "$(sys syswow64 dxgi)"+is "the state file records dxmt" "dxmt" "$(sed -n 1p "$case_dir/data/notproton-backend")"+: > "$case_dir/log"+launch waitforexitandrun "$case_dir/game/game.exe"+lacks "a second launch copies nothing" "staged" "$case_dir/log"+launch waitforexitandrun "$case_dir/game/game.exe" NOTPROTON_BACKEND=dxvk+is "dxvk sets only d3d11 and d3d10core native, dxgi stays Wine's" \+ "d3d10core,d3d11=n,b;dxgi=b;$trio" "$(got WINEDLLOVERRIDES)"+is "the stale dxmt dxgi goes back to Wine's" "stock x86_64-windows dxgi" "$(sys system32 dxgi)"+is "dxvk d3d11 replaces dxmt's" "backend dxvk/x86_64-windows/d3d11.dll" "$(sys system32 d3d11)"+is "dxvk i386 lands in syswow64" "backend dxvk/i386-windows/d3d11.dll" "$(sys syswow64 d3d11)"+has "the switch is logged" "backend switched from dxmt to dxvk" "$case_dir/log"+launch waitforexitandrun "$case_dir/game/game.exe"+is "back on dxmt, the stale i386 dxvk d3d11 goes back to Wine's" "stock i386-windows d3d11" "$(sys syswow64 d3d11)"+launch waitforexitandrun "$case_dir/game/game.exe" NOTPROTON_BACKEND=wined3d+is "wined3d keeps every backend DLL builtin" "d3d10core,d3d11,dxgi=b;$trio" "$(got WINEDLLOVERRIDES)"+is "and puts Wine's dxgi back" "stock x86_64-windows dxgi" "$(sys system32 dxgi)"+is "and Wine's d3d11" "stock x86_64-windows d3d11" "$(sys system32 d3d11)"+printf 'user reshade\n' > "$case_dir/data/pfx/drive_c/windows/system32/dxgi.dll"+launch waitforexitandrun "$case_dir/game/game.exe" NOTPROTON_BACKEND=wined3d+is "a DLL the user put there is left alone" "user reshade" "$(sys system32 dxgi)"+new_case+full_engine+chmod 500 "$case_dir/data/pfx/drive_c/windows/system32"+launch waitforexitandrun "$case_dir/game/game.exe"+chmod 700 "$case_dir/data/pfx/drive_c/windows/system32"+is "a backend that cannot be staged falls back to wined3d" "wined3d" "$(got backend)"+has "with the reason" "dxmt could not be staged, falling back to wined3d" "$case_dir/log"++echo "== msync"+new_case+full_engine+launch waitforexitandrun "$case_dir/game/game.exe"+is "the free engine keeps msync off" "0 default" "$(got WINEMSYNC) $(got msync_from)"+new_case+full_engine+engine msync+launch waitforexitandrun "$case_dir/game/game.exe"+is "an engine with msync turns it on" "1 engine" "$(got WINEMSYNC) $(got msync_from)"+printf 0 > "$case_dir/data/notproton-msync"+launch waitforexitandrun "$case_dir/game/game.exe"+is "over an older carried-over 0" "1 engine" "$(got WINEMSYNC) $(got msync_from)"+user_conf 'MSYNC=0'+launch waitforexitandrun "$case_dir/game/game.exe"+is "a conf MSYNC=0 turns it off" "0 gamefix" "$(got WINEMSYNC) $(got msync_from)"+launch waitforexitandrun "$case_dir/game/game.exe" WINEMSYNC=1+is "launch options beat the conf" "1 environment" "$(got WINEMSYNC) $(got msync_from)"+new_case+full_engine+user_conf 'MSYNC=1'+printf 1 > "$case_dir/data/notproton-msync"+launch waitforexitandrun "$case_dir/game/game.exe"+is "without the marker a conf MSYNC=1 keeps the carried-over value" "1 carried-over" "$(got WINEMSYNC) $(got msync_from)"+has "and says why" "MSYNC=1 not applied, the engine has no .notproton-msync" "$case_dir/log"++echo "== ARGS"+new_case+full_engine+default_conf 'ARGS=-dx12'+user_conf 'ARGS=-dx11 -windowed +exec=autoexec.cfg'+launch waitforexitandrun "$case_dir/game/game.exe"+is "the user conf ARGS wins" "-dx11 -windowed +exec=autoexec.cfg" "$(got gamefix_args)"+launch run "$case_dir/game/iscriptevaluator.exe"+is "helpers get no ARGS" "" "$(got gamefix_args)"+has "and the log says so" "ARGS not applied, run is not the game launch" "$case_dir/log"+for bad_args in '-dx11 ;reboot' '-a *' '-a $HOME' '-a|b' '-a&' '-a>b' '-a\b' '-a?'; do+ new_case+ full_engine+ user_conf "ARGS=$bad_args"+ launch waitforexitandrun "$case_dir/game/game.exe"+ is "ARGS=$bad_args is rejected" "" "$(got gamefix_args)"+ has "and logged" "rejected ARGS: an argument with characters outside" "$case_dir/log"+done+out=$(gamefix_args='-dx11 -windowed +exec=autoexec.cfg' log=/dev/null append_args="$append_args" \+ sh -ec 'eval "$append_args"; printf "[%s]" "$@"' sh /g/game.exe -novid 'two words')+is "ARGS come after the launch options' own arguments, split on spaces" \+ "[/g/game.exe][-novid][two words][-dx11][-windowed][+exec=autoexec.cfg]" "$out"+out=$(gamefix_args='' log=/dev/null append_args="$append_args" \+ sh -ec 'eval "$append_args"; printf "[%s]" "$@"' sh /g/game.exe -novid)+is "no ARGS leaves the command line alone" "[/g/game.exe][-novid]" "$out"++echo "== RETINA"+new_case+full_engine+user_conf 'RETINA=1'+launch waitforexitandrun "$case_dir/game/game.exe"+is "RETINA maps to NOTPROTON_RETINA" "1" "$(got NOTPROTON_RETINA)"+launch waitforexitandrun "$case_dir/game/game.exe" NOTPROTON_RETINA=0+is "the High Resolution launch option wins" "0" "$(got NOTPROTON_RETINA)"++echo "== the launcher receives the allow-listed variables"+set --+out=$(env -i PATH="$PATH" forward="$forward" VKD3D_CONFIG=dxr MVK_CONFIG_LOG_LEVEL=1 \+ STAGING_SHARED_MEMORY=1 WINE_CPU_TOPOLOGY=4:0,1,2,3 WINE_LARGE_ADDRESS_AWARE=1 \+ DXVK_HUD=fps NOTPROTON_UNRELATED=1 sh -c 'set --; eval "$forward"; printf "%s\n" "$@"' | grep -v '^--env$' | sort | tr '\n' ' ')+is "VKD3D_, MVK_, STAGING_ and WINE_ topology variables are forwarded" \+ "DXVK_HUD=fps MVK_CONFIG_LOG_LEVEL=1 STAGING_SHARED_MEMORY=1 VKD3D_CONFIG=dxr WINE_CPU_TOPOLOGY=4:0,1,2,3 WINE_LARGE_ADDRESS_AWARE=1 " "$out"++if [ "$fails" -eq 0 ]; then+ echo "==> gamefixescheck: all assertions hold"+else+ echo "==> gamefixescheck: $fails failed"+ exit 1+fi