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): launch option NOTPROTON_ENV_<NAME> sets any env var for the game (upstream #219)
raymondchinsd80b27d26522
diff --git a/AGENTS.md b/AGENTS.mdindex 042c28a..82b22f0 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -61,7 +61,7 @@ The checks the workflows run (`make -s <target>`):- **C and shell suites:** `sigcheck`, `callscheck`, `webpatch-fixtures`, `peicon-fixtures`,`panel-behavior`, `spawn-env`, `activatecheck`, `compatcheck`, `compatsvc-check`,`shortcutcheck`, `launch-shell`, `envcheck`, `buildcheck`, `settingscheck`, `routecheck`,- `bridgecheck`, `gamedrivecheck`, `launchercheck`, `seedcheck`, `gamefixescheck`, `versioncheck`, `cicheck`,+ `bridgecheck`, `envpasscheck`, `gamedrivecheck`, `launchercheck`, `seedcheck`, `gamefixescheck`, `versioncheck`, `cicheck`,`compat-reported-check`- **Hardware-free device checks:** `game-host-check`, `dualsense-check`, `steam-rumble-check`diff --git a/Makefile b/Makefileindex 2b15b21..18e2a2b 100644--- a/Makefile+++ b/Makefile@@ -73,7 +73,7 @@ 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 shortcutcheck scriptcheck envcheck buildcheck settingscheck routecheck bridgecheck gamedrivecheck \+ compatsvc-check shortcutcheck scriptcheck envcheck buildcheck settingscheck routecheck bridgecheck envpasscheck gamedrivecheck \gamefixescheck launchercheck padcheck launch-shell activatecheck stamp-check versioncheck cicheck compat-reported-check FORCEAPP_PAYLOAD := app/Sources/BridgeplayApp/Resources/payload@@ -130,6 +130,10 @@ bridgecheck:@if [ ! -f dylib/tests/bridgecheck.sh ]; then $(call SKIP,bridgecheck,dylib/tests/bridgecheck.sh); exit 0; fi; \sh dylib/tests/bridgecheck.sh dylib/feats/compat_run.sh+envpasscheck:+ @if [ ! -f dylib/tests/envpasscheck.sh ]; then $(call SKIP,envpasscheck,dylib/tests/envpasscheck.sh); exit 0; fi; \+ sh dylib/tests/envpasscheck.sh dylib/feats/compat_run.sh+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@@ -913,7 +917,7 @@ native-shim-tests:CI_CHECKS := mincheck l10ncheck \sigcheck callscheck webpatch-fixtures peicon-fixtures panel-behavior spawn-env \activatecheck compatcheck compatsvc-check shortcutcheck launch-shell envcheck \- buildcheck settingscheck routecheck bridgecheck gamedrivecheck launchercheck \+ buildcheck settingscheck routecheck bridgecheck envpasscheck gamedrivecheck launchercheck \seedcheck gamefixescheck versioncheck cicheck padcheck compat-reported-check np-native-tests native-shim-tests \app-tests native-installercheck game-host-check dualsense-check steam-rumble-checkdiff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.shindex 82cab58..dbd9830 100755--- a/dylib/feats/compat_run.sh+++ b/dylib/feats/compat_run.sh@@ -2403,6 +2403,27 @@ for name in $(env | LC_ALL=C sed -nE 's/^(CX_APPLEGPTK_LIBD3DSHARED_PATH|SDL_GAM# shellcheck disable=SC2154 # eval assigns value on the line aboveset -- --env "$name=$value" "$@"done++# Anything this script does not know by name. A launch option NOTPROTON_ENV_FOO=bar gives+# the game FOO=bar, which is the only per-game way to set one, and Wine and the graphics+# layers take far more than the prefixes above.+np_env_reserved="CX_ROOT CX_HOME HOME PATH WINEPREFIX WINELOADER WINESERVER WINEDLLPATH \+WINEDLLOVERRIDES STEAM_COMPAT_DATA_PATH STEAM_COMPAT_INSTALL_PATH NOTPROTON_GAME_CWD \+STEAM_COMPAT_CLIENT_INSTALL_PATH STEAM_COMPAT_APP_ID STEAM_DYLD_INSERT_LIBRARIES"+np_env_passed=$(env | LC_ALL=C sed -nE 's/^NOTPROTON_ENV_([A-Za-z_][A-Za-z0-9_]*)=.*/\1/p' \+ | LC_ALL=C sort)+for name in $np_env_passed; do+ case " $np_env_reserved " in+ *" $name "*)+ echo "=== NOTPROTON_ENV_$name would replace a setting this launch sets itself, ignored ===" \+ >> "$log" 2>&1 || true+ continue ;;+ esac+ eval "value=\$NOTPROTON_ENV_$name"+ export "$name=$value"+ set -- --env "$name=$value" "$@"+ echo "=== NOTPROTON_ENV_$name sets $name ===" >> "$log" 2>&1 || true+doneset -- \--env NOTPROTON_RUMBLE_LIBRARY="${NOTPROTON_RUMBLE_LIBRARY:-}" \--env NOTPROTON_STEAM_RUMBLE="${NOTPROTON_STEAM_RUMBLE:-}" \diff --git a/dylib/tests/envpasscheck.sh b/dylib/tests/envpasscheck.shnew file mode 100755index 0000000..dbaeb5a--- /dev/null+++ b/dylib/tests/envpasscheck.sh@@ -0,0 +1,53 @@+#!/bin/sh+# A launch option named NOTPROTON_ENV_FOO reaches the game as FOO, except where that+# would replace something the launch sets for itself.+set -e+SRC="${1:-$(dirname "$0")/../feats/compat_run.sh}"+[ -f "$SRC" ] || { echo "envpasscheck: $SRC not present, skipped"; exit 0; }++block=$(sed -n '/^np_env_reserved=/,/^done$/p' "$SRC")+case "$block" in+ *NOTPROTON_ENV_*) ;;+ *) echo "FAIL: the passthrough loop was not found in $SRC"; exit 1 ;;+esac++work=$(mktemp -d)+trap 'rm -rf "$work"' EXIT+printf '%s\n' "$block" > "$work/block.sh"++# Runs the loop with a given environment and prints the --env arguments it added.+forwarded() {+ # shellcheck disable=SC2016 # the block expands inside the child shell, not here+ env -i PATH="$PATH" log=/dev/null "$@" \+ sh -c 'w=$1; set --; . "$w/block.sh"; printf "%s\n" "$@"' sh "$work" |+ sed -e '/^--env$/d' -e '/^$/d' | LC_ALL=C sort | tr '\n' ' '+}++fail=0+ok() { if [ "$2" = "$3" ]; then echo " ok $1"; else+ echo " FAIL $1 (want [$3], got [$2])"; fail=1; fi; }++ok "nothing set forwards nothing" "$(forwarded)" ""+ok "one option reaches the game under its own name" \+ "$(forwarded NOTPROTON_ENV_FRAMESCOPE_HZ=60)" "FRAMESCOPE_HZ=60 "+ok "several are each forwarded" \+ "$(forwarded NOTPROTON_ENV_A_ONE=1 NOTPROTON_ENV_B_TWO=2)" "A_ONE=1 B_TWO=2 "+ok "a value with spaces survives" \+ "$(forwarded NOTPROTON_ENV_MSG='two words')" "MSG=two words "+ok "an empty value is still passed" "$(forwarded NOTPROTON_ENV_EMPTY=)" "EMPTY= "++# The launch sets these itself; letting a game replace them breaks it in ways that look+# like NotProton is at fault.+for reserved in CX_ROOT WINEPREFIX PATH STEAM_DYLD_INSERT_LIBRARIES WINEDLLOVERRIDES; do+ ok "$reserved is refused" "$(forwarded "NOTPROTON_ENV_$reserved=x")" ""+done+ok "a refusal does not stop the rest" \+ "$(forwarded NOTPROTON_ENV_CX_ROOT=x NOTPROTON_ENV_KEEP=yes)" "KEEP=yes "++# The name comes out of a sed capture, so anything that is not a C identifier never+# reaches the eval below it.+ok "a name with a dash is not matched" "$(forwarded 'NOTPROTON_ENV_BAD-NAME=x')" ""+ok "the bare prefix is not matched" "$(forwarded 'NOTPROTON_ENV_=x')" ""++[ "$fail" -eq 0 ] || exit 1+echo "==> envpasscheck: launch options reach the game, reserved names do not"