Skip to content

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

feat(launch): warn before starting a game with kernel anti-cheat (#1531)

Raymond Chin1b30aabd74a3
diff --git a/AGENTS.md b/AGENTS.md
index d724677..90a83a8 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -79,7 +79,10 @@ the dylib into `Steam.app` and installs the signatures, fonts and helpers into
don't amend or reset the author; a rewrite keeps the original author or adds a
`Co-authored-by:` line and names the source commit or PR. New third-party code goes in
[NOTICE](NOTICE). See CONTRIBUTING.md.
-- **PR descriptions** are written by the contributor in their own words. Don't generate one.
+- **PR descriptions:** an agent may draft one, filling every section of
+ `.github/pull_request_template.md` with the checks actually run and what wasn't tested.
+ The contributor reviews it before the PR opens. Replies to people in issues, PRs and
+ discussions are written by a human, not generated.
- **Comments:** keep them short. Comment where the code is hard to follow, not where it is
obvious.
- **Run the checks your change touches** before opening a PR.
diff --git a/Makefile b/Makefile
index 0787c17..673bf4d 100644
--- a/Makefile
+++ b/Makefile
@@ -85,7 +85,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 prefixstate-check shortcutcheck scriptcheck envcheck buildcheck settingscheck routecheck bridgecheck envpasscheck prefixnotecheck powernotecheck exitcheck gamedrivecheck \
+ compatsvc-check prefixstate-check shortcutcheck scriptcheck envcheck buildcheck settingscheck routecheck bridgecheck envpasscheck prefixnotecheck powernotecheck exitcheck anticheatcheck gamedrivecheck \
gamefixescheck launchercheck padcheck launch-shell activatecheck stamp-check versioncheck cicheck compat-reported-check FORCE
APP_PAYLOAD := app/Sources/BridgeplayApp/Resources/payload
@@ -164,6 +164,10 @@ exitcheck:
@if [ ! -f dylib/tests/exitcheck.sh ]; then $(call SKIP,exitcheck,dylib/tests/exitcheck.sh); exit 0; fi; \
sh dylib/tests/exitcheck.sh dylib/feats/compat_run.sh
+anticheatcheck:
+ @if [ ! -f dylib/tests/anticheatcheck.sh ]; then $(call SKIP,anticheatcheck,dylib/tests/anticheatcheck.sh); exit 0; fi; \
+ sh dylib/tests/anticheatcheck.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
@@ -891,7 +895,7 @@ np-inventory-check:
CI_CHECKS := mincheck l10ncheck \
sigcheck callscheck np-test-batch-check webpatch-fixtures peicon-fixtures panel-behavior spawn-env \
activatecheck compat-reported-import-check compatcheck compatsvc-check prefixstate-check shortcutcheck launch-shell envcheck \
- buildcheck settingscheck routecheck bridgecheck envpasscheck prefixnotecheck powernotecheck exitcheck gamedrivecheck launchercheck \
+ buildcheck settingscheck routecheck bridgecheck envpasscheck prefixnotecheck powernotecheck exitcheck anticheatcheck gamedrivecheck launchercheck \
seedcheck gamefixescheck versioncheck cicheck padcheck compat-reported-check np-inventory-check np-native-tests native-shim-tests \
app-tests native-installercheck
diff --git a/app/Tests/BridgeplayAppTests/PrefixToolsTests.swift b/app/Tests/BridgeplayAppTests/PrefixToolsTests.swift
index e8f349f..9051d43 100644
--- a/app/Tests/BridgeplayAppTests/PrefixToolsTests.swift
+++ b/app/Tests/BridgeplayAppTests/PrefixToolsTests.swift
@@ -412,9 +412,11 @@ struct PrefixToolsTests {
#expect(helper.upperBound == gate.lowerBound)
#expect(gate.upperBound < alert.lowerBound)
// The first-launch notice uses osascript too, but as a notification, not an alert. The
- // rebuild failure alert and the rebuild prompt carry their own gates.
- #expect(source.ranges(of: "display alert").count == 2, "an alert bypasses show_alert")
- #expect(source.ranges(of: "osascript").count == 5)
+ // rebuild failure alert, the rebuild prompt and the anti-cheat prompt carry their own gates.
+ #expect(source.ranges(of: "display alert").count == 3, "an alert bypasses show_alert")
+ #expect(source.ranges(of: "osascript").count == 6)
+ let anticheat = try #require(source.range(of: "kernel_anticheat_notice() {\n"))
+ #expect(source[anticheat.upperBound...].hasPrefix(#" [ "$verb" = waitforexitandrun ] || return 0"#))
let rebuild = try #require(source.range(of: "rebuild_prefix() {"))
let prompt = try #require(source.range(of: "choice=$(osascript"))
#expect(source[rebuild.upperBound..<prompt.lowerBound].contains(#"[ "$verb" != run ] || { [ -n "$3" ] && return 0; exit 1; }"#))
diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.sh
index 042f6d6..14e8eb1 100755
--- a/dylib/feats/compat_run.sh
+++ b/dylib/feats/compat_run.sh
@@ -1094,6 +1094,75 @@ APPLESCRIPT
[ "$answer" != "Open Log" ] || { [ -f "$log" ] && [ ! -L "$log" ] && open -t "$log" >/dev/null 2>&1; } || true
}
+# Kernel anti-cheat needs a Windows driver, which Wine cannot load, so these games quit at
+# start. Prints the anti-cheat's name for one of its file names, nothing otherwise.
+kernel_anticheat_name() {
+ case "$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')" in
+ randgrid.sys) echo "Ricochet" ;;
+ xhunter1.sys) echo "XIGNCODE3" ;;
+ eaanticheat.installer.exe | eaanticheat.gameservicelauncher.exe) echo "EA Javelin" ;;
+ esac
+}
+
+# The first kernel anti-cheat in a game folder, as "Name (file)". Shallow, so a large
+# install does not hold up the launch.
+find_kernel_anticheat() {
+ [ -d "$1" ] || return 0
+ find "$1" -maxdepth 3 -type f \( -iname '*.sys' -o -iname 'eaanticheat.*.exe' \) 2>/dev/null |
+ while IFS= read -r ka_file; do
+ ka_name=$(kernel_anticheat_name "${ka_file##*/}")
+ [ -z "$ka_name" ] || { printf '%s (%s)\n' "$ka_name" "${ka_file##*/}"; break; }
+ done
+}
+
+# Seconds the anti-cheat prompt waits. Steam shows the game as running until it is answered.
+kernel_anticheat_wait=90
+
+# Asks before a launch that cannot work and that could get the account banned. Only Launch
+# Anyway goes ahead: Don't Launch, no answer in time or a dialog that cannot show all exit
+# before Wine or the prefix is touched.
+kernel_anticheat_notice() {
+ [ "$verb" = waitforexitandrun ] || return 0
+ ka_found=$(find_kernel_anticheat "$STEAM_COMPAT_INSTALL_PATH")
+ [ -n "$ka_found" ] || return 0
+ echo "anticheat: found kernel anti-cheat $ka_found, whose driver Wine cannot load" >> "$log" 2>&1 || true
+ ka_status=0
+ answer=$(osascript - "$ka_found" "$kernel_anticheat_wait" 8>&- 9>&- 2>> "$log" <<'APPLESCRIPT'
+on run argv
+ set answer to display alert "This game's anti-cheat can't run" message ("It uses " & (item 1 of argv) & ", kernel anti-cheat that needs a Windows driver. Wine cannot load it, so the game will most likely quit at start. Playing online with it is at your own risk.") as critical buttons {"Launch Anyway", "Don't Launch"} default button "Don't Launch" giving up after ((item 2 of argv) as integer)
+ if gave up of answer then return "gave up"
+ return button returned of answer
+end run
+APPLESCRIPT
+ ) || ka_status=$?
+ case "$ka_status:$answer" in
+ "0:Launch Anyway")
+ echo "anticheat: the player chose Launch Anyway" >> "$log" 2>&1 || true
+ return 0
+ ;;
+ "0:Don't Launch") ka_why="the player chose Don't Launch" ;;
+ "0:gave up") ka_why="no answer within ${kernel_anticheat_wait}s" ;;
+ 0:*) ka_why="the dialog returned no choice" ;;
+ *) ka_why="the dialog could not be shown (exit $ka_status)" ;;
+ esac
+ {
+ echo "=== not launched: kernel anti-cheat, $ka_why ==="
+ echo "=== exit summary: not launched, stopped before Wine started ==="
+ echo "=== exit cause: blocked: kernel anti-cheat $ka_found not confirmed, $ka_why ==="
+ } >> "$log" 2>&1 || true
+ exit 0
+}
+
+# The anti-cheat whose driver failed to load, from Wine's log.
+exit_anticheat() {
+ [ -f "$1" ] || return 0
+ grep -a -E 'err:(module:import_dll|ntoskrnl:ZwLoadDriver)' "$1" 2>/dev/null |
+ grep -a -o -i -E '[a-z0-9_.-]+\.sys' | while IFS= read -r ea_file; do
+ ea_name=$(kernel_anticheat_name "$ea_file")
+ [ -z "$ea_name" ] || { printf '%s (%s)\n' "$ea_name" "$ea_file"; break; }
+ done
+}
+
# Steam shows the game as running while this waits, and Stop kills the script's process
# group and children. A rebuild killed between its two renames leaves no pfx at all, so the
# app runs outside both: the inner subshell is reparented to launchd and the app calls
@@ -1372,6 +1441,8 @@ exit_summary() {
es_how="the game quit by itself"
fi
printf '=== exit summary: exit status %s after %s, %s ===\n' "$1" "$es_took" "$es_how"
+ es_anticheat=$(exit_anticheat "$4")
+ [ -z "$es_anticheat" ] || printf '=== exit cause: kernel anti-cheat %s could not load its Windows driver, which Wine cannot run, so the game will not start ===\n' "$es_anticheat"
exit_crash_lines "$4" | while IFS= read -r es_line; do
printf '=== exit cause: %s ===\n' "$es_line"
done
@@ -2271,6 +2342,8 @@ native_vc_runtime() {
}
if [ -n "$STEAM_COMPAT_DATA_PATH" ]; then
+ stage_step="anti-cheat check"
+ kernel_anticheat_notice
export WINEPREFIX="$STEAM_COMPAT_DATA_PATH/pfx"
stage_step="prefix lock"
prepare_prefix_directory
diff --git a/dylib/tests/anticheatcheck.sh b/dylib/tests/anticheatcheck.sh
new file mode 100644
index 0000000..c5d33d7
--- /dev/null
+++ b/dylib/tests/anticheatcheck.sh
@@ -0,0 +1,157 @@
+#!/bin/sh
+# anticheatcheck: the kernel anti-cheat scan of a game folder and the prompt before launch
+# (kernel_anticheat_notice in compat_run.sh). Only Launch Anyway may start the game.
+set -e
+SRC="${1:-$(dirname "$0")/../feats/compat_run.sh}"
+[ -f "$SRC" ] || { echo "anticheatcheck: $SRC not present, skipped"; exit 0; }
+
+extract() { sed -n "/^$1() {\$/,/^}\$/p" "$SRC"; }
+functions=$(grep '^kernel_anticheat_wait=' "$SRC") || { echo "FAIL: kernel_anticheat_wait not found in $SRC"; exit 1; }
+for name in kernel_anticheat_name find_kernel_anticheat kernel_anticheat_notice; do
+ body=$(extract "$name")
+ [ -n "$body" ] || { echo "FAIL: $name not found in $SRC"; exit 1; }
+ functions="$functions
+$body"
+done
+eval "$functions"
+# shellcheck disable=SC2154 # the eval above sets it from the run script
+wait_seconds=$kernel_anticheat_wait
+
+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() { case "$3" in *"$2"*) ok "$1" ;; *) bad "$1" "*$2*" "$3" ;; esac; }
+lacks() { case "$3" in *"$2"*) bad "$1" "no $2" "$3" ;; *) ok "$1" ;; esac; }
+
+echo "== scan =="
+game() { g="$work/game $1"; mkdir -p "$g"; printf '%s' "$g"; }
+put() { mkdir -p "$(dirname "$1")"; : > "$1"; }
+
+g=$(game ricochet); put "$g/Randgrid.sys"
+is "Ricochet beside the game" "Ricochet (Randgrid.sys)" "$(find_kernel_anticheat "$g")"
+g=$(game upper); put "$g/a/b/RANDGRID.SYS"
+is "any case, three folders down" "Ricochet (RANDGRID.SYS)" "$(find_kernel_anticheat "$g")"
+g=$(game deep); put "$g/a/b/c/Randgrid.sys"
+is "four folders down is not searched" "" "$(find_kernel_anticheat "$g")"
+g=$(game xigncode); put "$g/bin/xhunter1.sys"
+is "XIGNCODE3" "XIGNCODE3 (xhunter1.sys)" "$(find_kernel_anticheat "$g")"
+g=$(game javelin); put "$g/EAAntiCheat.GameServiceLauncher.exe"
+is "EA Javelin's launcher" "EA Javelin (EAAntiCheat.GameServiceLauncher.exe)" "$(find_kernel_anticheat "$g")"
+g=$(game javelin2); put "$g/__Installer/EAAntiCheat.Installer.exe"
+is "EA Javelin's installer" "EA Javelin (EAAntiCheat.Installer.exe)" "$(find_kernel_anticheat "$g")"
+g=$(game battleye); put "$g/BattlEye/BEDaisy.sys"; put "$g/BattlEye/BEService_x64.exe"
+is "BattlEye is left alone, BEDaisy.sys included" "" "$(find_kernel_anticheat "$g")"
+g=$(game vanguard); put "$g/vgk.sys"
+is "vgk.sys in a game folder is not Vanguard" "" "$(find_kernel_anticheat "$g")"
+g=$(game eac); put "$g/EasyAntiCheat/EasyAntiCheat_EOS_Setup.exe"; put "$g/drivers/other.sys"
+is "Easy Anti-Cheat and other drivers are left alone" "" "$(find_kernel_anticheat "$g")"
+g=$(game folder); mkdir -p "$g/Randgrid.sys"
+is "a folder named like a driver is not one" "" "$(find_kernel_anticheat "$g")"
+is "a missing game folder" "" "$(find_kernel_anticheat "$work/nowhere")"
+
+echo "== prompt =="
+ka_game=$(game prompt); put "$ka_game/Randgrid.sys"
+plain=$(game plain); put "$plain/game.exe"
+# prompt_case <name> <verb> <game folder> <stub|missing>: runs the notice under set -e as the
+# run script does, then "launched" when it returned. The stub answers $stub_out, $stub_rc.
+prompt_case() {
+ case_dir="$work/case $1"
+ mkdir -p "$case_dir"
+ (
+ set -e
+ # shellcheck disable=SC2034 # kernel_anticheat_notice reads them
+ verb=$2 STEAM_COMPAT_INSTALL_PATH=$3 log="$case_dir/bridgeplay-run.log"
+ if [ "$4" = missing ]; then
+ mkdir "$case_dir/bin"
+ for tool in find tr; do ln -s "$(command -v "$tool")" "$case_dir/bin/$tool"; done
+ PATH="$case_dir/bin"
+ else
+ # shellcheck disable=SC2329 # kernel_anticheat_notice runs this in place of the dialog
+ osascript() {
+ cat > "$case_dir/script"
+ shift
+ printf '%s\n' "$@" > "$case_dir/args"
+ [ -z "$stub_err" ] || echo "$stub_err" >&2
+ [ -z "$stub_out" ] || printf '%s\n' "$stub_out"
+ return "$stub_rc"
+ }
+ fi
+ kernel_anticheat_notice
+ echo launched > "$case_dir/launched"
+ ) && rc=0 || rc=$?
+ log=$(cat "$case_dir/bridgeplay-run.log" 2>/dev/null || true)
+ launched=$([ -f "$case_dir/launched" ] && echo yes || echo no)
+ asked=$([ -f "$case_dir/args" ] && echo yes || echo no)
+}
+answer() { stub_out=$1 stub_rc=${2:-0} stub_err=${3:-}; }
+
+answer "Don't Launch"
+prompt_case dont waitforexitandrun "$ka_game" stub
+is "Don't Launch: exits cleanly" 0 "$rc"
+is "Don't Launch: the game does not start" no "$launched"
+is "the dialog names the anti-cheat and the wait" "Ricochet (Randgrid.sys)
+$wait_seconds" "$(cat "$work/case dont/args")"
+has "the dialog gives up by itself" 'giving up after ((item 2 of argv) as integer)' "$(cat "$work/case dont/script")"
+has "giving up is told apart from a choice" 'if gave up of answer then return "gave up"' "$(cat "$work/case dont/script")"
+has "Don't Launch is the default" "default button \"Don't Launch\"" "$(cat "$work/case dont/script")"
+has "Don't Launch: logged" "=== not launched: kernel anti-cheat, the player chose Don't Launch ===" "$log"
+has "Don't Launch: exit cause" "=== exit cause: blocked: kernel anti-cheat Ricochet (Randgrid.sys) not confirmed, the player chose Don't Launch ===" "$log"
+
+answer "Launch Anyway"
+prompt_case anyway waitforexitandrun "$ka_game" stub
+is "Launch Anyway: the game starts" yes "$launched"
+has "Launch Anyway: logged" "anticheat: the player chose Launch Anyway" "$log"
+lacks "Launch Anyway: no exit cause" "exit cause" "$log"
+
+answer "gave up"
+prompt_case timeout waitforexitandrun "$ka_game" stub
+is "no answer in time: exits cleanly" 0 "$rc"
+is "no answer in time: the game does not start" no "$launched"
+has "no answer in time: logged" "=== not launched: kernel anti-cheat, no answer within ${wait_seconds}s ===" "$log"
+has "no answer in time: exit summary" "=== exit summary: not launched, stopped before Wine started ===" "$log"
+has "no answer in time: exit cause" "=== exit cause: blocked: kernel anti-cheat Ricochet (Randgrid.sys) not confirmed, no answer within ${wait_seconds}s ===" "$log"
+
+answer "" 1 "execution error: No user interaction allowed. (-1713)"
+prompt_case error waitforexitandrun "$ka_game" stub
+is "dialog error: exits cleanly" 0 "$rc"
+is "dialog error: the game does not start" no "$launched"
+has "dialog error: why" "=== not launched: kernel anti-cheat, the dialog could not be shown (exit 1) ===" "$log"
+has "dialog error: the error is kept" "No user interaction allowed. (-1713)" "$log"
+has "dialog error: exit cause" "=== exit cause: blocked: kernel anti-cheat Ricochet (Randgrid.sys) not confirmed, the dialog could not be shown (exit 1) ===" "$log"
+
+answer "" 0
+prompt_case empty waitforexitandrun "$ka_game" stub
+is "no choice returned: the game does not start" no "$launched"
+has "no choice returned: why" "=== not launched: kernel anti-cheat, the dialog returned no choice ===" "$log"
+
+prompt_case missing waitforexitandrun "$ka_game" missing
+is "no dialog tool: exits cleanly" 0 "$rc"
+is "no dialog tool: the game does not start" no "$launched"
+has "no dialog tool: why" "=== not launched: kernel anti-cheat, the dialog could not be shown (exit 127) ===" "$log"
+
+answer "Don't Launch"
+prompt_case helper run "$ka_game" stub
+is "Steam's helpers (verb run) are not asked" no "$asked"
+is "Steam's helpers still run" yes "$launched"
+prompt_case clean waitforexitandrun "$plain" stub
+is "a game without kernel anti-cheat is not asked" no "$asked"
+is "a game without kernel anti-cheat starts" yes "$launched"
+
+echo "== order =="
+# The prompt comes before anything that touches the prefix or starts Wine.
+notice_at=$(grep -n '^ kernel_anticheat_notice$' "$SRC" | cut -d: -f1)
+prefix_at=$(grep -n '^ export WINEPREFIX=' "$SRC" | head -1 | cut -d: -f1)
+lock_at=$(grep -n '^ prepare_prefix_directory$' "$SRC" | head -1 | cut -d: -f1)
+if [ -n "$notice_at" ] && [ -n "$prefix_at" ] && [ -n "$lock_at" ] \
+ && [ "$notice_at" -lt "$prefix_at" ] && [ "$notice_at" -lt "$lock_at" ]; then
+ ok "the prompt runs before the prefix is set or locked"
+else
+ bad "the prompt runs before the prefix is set or locked" "notice < $prefix_at, $lock_at" "${notice_at:-missing}"
+fi
+
+[ "$fails" -eq 0 ] || { echo "anticheatcheck: $fails failed"; exit 1; }
+echo "==> anticheatcheck: the kernel anti-cheat scan and prompt behave"
diff --git a/dylib/tests/exitcheck.sh b/dylib/tests/exitcheck.sh
index f3ac167..0e825c0 100644
--- a/dylib/tests/exitcheck.sh
+++ b/dylib/tests/exitcheck.sh
@@ -7,7 +7,7 @@ SRC="${1:-$(dirname "$0")/../feats/compat_run.sh}"
extract() { sed -n "/^$1() {\$/,/^}\$/p" "$SRC"; }
functions=""
-for name in exit_meaning exit_signal exit_crash_lines exit_summary; do
+for name in kernel_anticheat_name exit_anticheat exit_meaning exit_signal exit_crash_lines exit_summary; do
body=$(extract "$name")
[ -n "$body" ] || { echo "FAIL: $name not found in $SRC"; exit 1; }
functions="$functions
@@ -81,6 +81,20 @@ is "the first three crash lines follow the summary, then the crash handler" \
=== exit note: Wine started its crash handler, whose error dialog can sit behind the game ===" \
"$(summary 5 12 0 "$crash")"
+echo "== kernel anti-cheat =="
+cod="$work/cod.log"
+{
+ printf '01e0:err:module:import_dll Library ci.dll (which is needed by L"S:\\\\steamapps\\\\common\\\\Call of Duty HQ\\\\Randgrid.sys") not found\n'
+ printf '01e0:err:ntoskrnl:ZwLoadDriver failed to create driver L"\\\\Registry\\\\Machine\\\\System\\\\CurrentControlSet\\\\Services\\\\atvi-randgrid_sr": c0000142\n'
+} > "$cod"
+is "Ricochet's driver is named first (Call of Duty)" \
+ "=== exit summary: exit status 0 after 13s, the game quit by itself within a minute without an error code, usually after its own error message ===
+=== exit cause: kernel anti-cheat Ricochet (Randgrid.sys) could not load its Windows driver, which Wine cannot run, so the game will not start ===
+=== exit cause: 01e0:err:module:import_dll Library ci.dll (which is needed by L\"S:\\\\steamapps\\\\common\\\\Call of Duty HQ\\\\Randgrid.sys\") not found ===" \
+ "$(summary 0 13 0 "$cod")"
+printf '0024:err:ntoskrnl:ZwLoadDriver failed to create driver L"\\\\Driver\\\\winebth.sys": c00000e5\n' > "$work/winebth.log"
+is "Wine's own drivers are not anti-cheat" "" "$(exit_anticheat "$work/winebth.log")"
+
odd="$work/odd.log"
long=$(printf '%0400d' 0)
{