Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit
Swift apple-silicond3dmetaldxmtdxvkgame-porting-toolkitgptkmac-gamingmacosmetalfxrosetta-2steamsteam-playwinewinecx
fix(run): keep the Steam login out of the run log, and launch path fixes (#1920)
Raymond Chin59c0143c14e2
diff --git a/bridge/verify.sh b/bridge/verify.shindex c995df2..da735cf 100755--- a/bridge/verify.sh+++ b/bridge/verify.sh@@ -7,8 +7,8 @@# It also looks for old copies of the bridge next to it, and for bridge files left# in Steam Play prefixes.#-# The built files come from 'make bridge', the patched ntdlls from the Bridgeplay app,-# and the Valve files from fetch-valve.sh.+# The built files come from 'make bridge' and the Valve files from fetch-valve.sh. The app+# stages the patched ntdlls per build under wine/, so they are neither checked nor pruned.set -euhere="$(cd "$(dirname "$0")" && pwd)"@@ -28,12 +28,11 @@ if [ ! -f "$MANIFEST" ]; thenexit 1fi-# The patched ntdlls are listed with the built files.origin() {awk -v want="$1" '$1 == want { print $2 }' "$MANIFEST"}-built="$(origin built; origin patched)"+built="$(origin built)"valve="$(origin valve)"if [ -z "$built" ] || [ -z "$valve" ]; then@@ -69,9 +68,10 @@ report() {report "built here" "$built"report "from Valve" "$valve"-# grep exits 1 when there are no strays.+# grep exits 1 when there are no strays. wine/<build>/<arch>/ntdll.dll is live, and so is+# the wine/<arch> copy of 1.0 while a legacy tool still uses it.strays="$(cd "$BRIDGE_DIR" && { find . -mindepth 1 -type f | sed 's|^\./||' \- | grep -Fxv "$expected" || true; })"+ | grep -Fxv "$expected" | grep -Ev '^wine/.+/ntdll\.dll$' || true; })"unexpected=0[ -n "$strays" ] && unexpected="$(printf '%s\n' "$strays" | wc -l | tr -d ' ')"diff --git a/dylib/core/loader.c b/dylib/core/loader.cindex 1d0a689..725b40f 100644--- a/dylib/core/loader.c+++ b/dylib/core/loader.c@@ -117,7 +117,7 @@ static void install_steamui(np_sigdb_t *sigdb) {const struct mach_header_64 *mh = NULL;intptr_t slide = 0;- if (np_await_image(STEAMUI_DYLIB, WAIT_TIMEOUT_MS, &mh, &slide, NULL, 0) != 0) {+ if (np_await_image(STEAMUI_DYLIB, WAIT_TIMEOUT_MS, &mh, &slide) != 0) {NP_WARN("install_thread: %s absent after %d ms, its hooks stay off",STEAMUI_DYLIB, WAIT_TIMEOUT_MS);return;@@ -149,8 +149,7 @@ static void *install_thread(void *unused) {const struct mach_header_64 *mh = NULL;intptr_t slide = 0;- if (np_await_image(STEAMCLIENT_DYLIB, WAIT_TIMEOUT_MS, &mh, &slide,- NULL, 0) != 0) {+ if (np_await_image(STEAMCLIENT_DYLIB, WAIT_TIMEOUT_MS, &mh, &slide) != 0) {// The Steam bootstraper does thisNP_LOG("install_thread: %s absent after %d ms, hooks will install in the ""relaunched client", STEAMCLIENT_DYLIB, WAIT_TIMEOUT_MS);diff --git a/dylib/core/macho.c b/dylib/core/macho.cindex 1472fd2..3138d96 100644--- a/dylib/core/macho.c+++ b/dylib/core/macho.c@@ -23,8 +23,7 @@ static int image_index_by_name(const char *needle) {}int np_await_image(const char *name, int timeout_ms,- const struct mach_header_64 **out_mh, intptr_t *out_slide,- char *out_path, size_t path_size) {+ const struct mach_header_64 **out_mh, intptr_t *out_slide) {for (int waited = 0; waited < timeout_ms; waited += 100) {if (g_await_stop) return -1;@@ -32,13 +31,6 @@ int np_await_image(const char *name, int timeout_ms,if (idx >= 0) {*out_mh = (const struct mach_header_64 *)_dyld_get_image_header((uint32_t)idx);*out_slide = _dyld_get_image_vmaddr_slide((uint32_t)idx);- if (out_path && path_size) {- const char *p = _dyld_get_image_name((uint32_t)idx);- size_t len = strlen(p);- if (len >= path_size) len = path_size - 1;- memcpy(out_path, p, len);- out_path[len] = '\0';- }return 0;}usleep(100000);diff --git a/dylib/core/macho.h b/dylib/core/macho.hindex e7e4a71..b674d48 100644--- a/dylib/core/macho.h+++ b/dylib/core/macho.h@@ -6,8 +6,7 @@#include <mach-o/loader.h>int np_await_image(const char *name, int timeout_ms,- const struct mach_header_64 **out_mh, intptr_t *out_slide,- char *out_path, size_t path_size);+ const struct mach_header_64 **out_mh, intptr_t *out_slide);void np_await_stop(void);diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.shindex 0e2f51a..26cf77c 100755--- a/dylib/feats/compat_run.sh+++ b/dylib/feats/compat_run.sh@@ -237,7 +237,8 @@ fiecho "STEAM_COMPAT_INSTALL_PATH=$STEAM_COMPAT_INSTALL_PATH"echo "STEAM_COMPAT_APP_ID=$STEAM_COMPAT_APP_ID"echo "-- steam env passed through --"- env | grep -iE '^(Steam|SDL_)' | sort+ # Players attach this log to public issues, so the login name and video token stay out.+ env | grep -iE '^(Steam|SDL_)' | grep -ivE '^(SteamUser|SteamAppUser|STEAMVIDEOTOKEN)=' | sort[ -z "$np_dropped" ] || echo "ignored on arm64 Wine: $np_dropped"} >> "$log" 2>&1 || true@@ -459,7 +460,7 @@ gamefix_read() {fi# The keys that set a BRIDGEPLAY_ variable also take its full name: BRIDGEPLAY_RETINA=1 is RETINA=1.case "$key" in- BRIDGEPLAY_STDOUT_NULL|BRIDGEPLAY_VSYNC|BRIDGEPLAY_RETINA|BRIDGEPLAY_FRAMEGEN|BRIDGEPLAY_FRAMEGEN_?*)+ BRIDGEPLAY_STDOUT_NULL|BRIDGEPLAY_VSYNC|BRIDGEPLAY_HIDE_WINE_EXPORTS|BRIDGEPLAY_RETINA|BRIDGEPLAY_FRAMEGEN|BRIDGEPLAY_FRAMEGEN_?*)key=${key#BRIDGEPLAY_} ;;esacvalue=${line#*=}diff --git a/dylib/resolver/anchor.c b/dylib/resolver/anchor.cindex fd89a59..7f6f418 100644--- a/dylib/resolver/anchor.c+++ b/dylib/resolver/anchor.c@@ -533,10 +533,8 @@ uintptr_t np_locate_anchor(const struct mach_header_64 *mh, intptr_t slide,if (!ref) return 0;if (anchor->kind == NP_MATCH_INSN_AFTER_STRING) {- uint32_t opcode = anchor->insn ? anchor->insn : DEFAULT_INSN;- uint32_t opmask = anchor->insn_mask ? anchor->insn_mask : DEFAULT_INSN_MASK;int n = anchor->nth > 0 ? anchor->nth : 1;- return scan_for_insn(text_base, text_size, ref, opcode, opmask, n);+ return scan_for_insn(text_base, text_size, ref, DEFAULT_INSN, DEFAULT_INSN_MASK, n);}if (anchor->kind != NP_MATCH_STRING &&diff --git a/dylib/resolver/anchor.h b/dylib/resolver/anchor.hindex 917becc..bb003bb 100644--- a/dylib/resolver/anchor.h+++ b/dylib/resolver/anchor.h@@ -10,7 +10,7 @@ typedef enum {NP_MATCH_NONE = 0,NP_MATCH_STRING, // entry point that loads one unique C stringNP_MATCH_VTABLE_SLOT, // pointer parked at a fixed data address- NP_MATCH_INSN_AFTER_STRING, // the instruction one past the Nth chosen opcode,+ NP_MATCH_INSN_AFTER_STRING, // the instruction one past the Nth BLR,// counting from a string loadNP_MATCH_INSN_PAIR_IN_FN, // the sole adjacent opcode pair inside the function// a string reference identifies@@ -37,8 +37,6 @@ typedef struct {np_match_kind_t kind;char str[256]; // the referenced string, for the two string kindsuintptr_t va; // unslid data address of the vtable slot- uint32_t insn; // opcode bits to match against (0 selects BLR)- uint32_t insn_mask; // which opcode bits are significant (0 selects BLR)int nth; // 1-based index of the wanted opcode matchint nth_xref;diff --git a/dylib/tests/envcheck.sh b/dylib/tests/envcheck.shindex 28b52eb..66fbcf5 100755--- a/dylib/tests/envcheck.sh+++ b/dylib/tests/envcheck.sh@@ -194,6 +194,20 @@ is "a value holding a quote and a newline is copied as is" "a'bc|unset" "$(mapped "BRIDGEPLAY_RETINA=a'bc")"+echo "== the run log and the Steam login =="+logged=$(grep -F "env | grep -iE '^(Steam|SDL_)'" "$SRC" | strip)+[ -n "$logged" ] || { echo "FAIL: the Steam environment log line not found"; exit 1; }+# shellcheck disable=SC2016 # the inner sh expands it+run_log() { env -i PATH="$PATH" "$@" logged="$logged" sh -ec 'eval "$logged"'; }+is "the login name and video token stay out, the rest stays" "SDL_JOYSTICK_MFI=0+SteamAppId=4242+SteamGameId=4242" "$(run_log SteamUser=login SteamAppUser=login STEAMVIDEOTOKEN=1002 \+ SteamAppId=4242 SteamGameId=4242 SDL_JOYSTICK_MFI=0)"+is "a log with only those lines is empty, not a stopped script" "" "$(run_log SteamUser=login)"+# shellcheck disable=SC2016 # the inner sh expands them+is "the game still gets them" "login|1002" "$(env -i PATH="$PATH" SteamUser=login STEAMVIDEOTOKEN=1002 \+ logged="$logged" sh -ec 'eval "$logged" > /dev/null; printf "%s|%s" "$SteamUser" "$STEAMVIDEOTOKEN"')"+if [ "$fails" -eq 0 ]; thenecho "==> envcheck: all assertions hold"elsediff --git a/dylib/tests/gamefixescheck.sh b/dylib/tests/gamefixescheck.shindex ef83820..e553f06 100644--- a/dylib/tests/gamefixescheck.sh+++ b/dylib/tests/gamefixescheck.sh@@ -545,10 +545,11 @@ launch waitforexitandrun "$case_dir/game/game.exe" NOTPROTON_RETINA=0 BRIDGEPLAYis "NOTPROTON_ wins when both spellings are set" "0" "$(got NOTPROTON_RETINA)"new_casefull_engine-user_conf 'BRIDGEPLAY_RETINA=1' 'BRIDGEPLAY_FRAMEGEN=2' 'BRIDGEPLAY_BACKEND=dxvk'+user_conf 'BRIDGEPLAY_RETINA=1' 'BRIDGEPLAY_FRAMEGEN=2' 'BRIDGEPLAY_BACKEND=dxvk' 'BRIDGEPLAY_HIDE_WINE_EXPORTS=1'launch waitforexitandrun "$case_dir/game/game.exe"is "a conf key takes the BRIDGEPLAY_ name" "1" "$(got NOTPROTON_RETINA)"is "and so does FRAMEGEN" "2" "$(got NOTPROTON_FRAMEGEN)"+is "and so does HIDE_WINE_EXPORTS" "1" "$(got NOTPROTON_HIDE_WINE_EXPORTS)"has "BACKEND does not, it names no variable" "rejected BRIDGEPLAY_BACKEND: not on the allow-list" "$case_dir/log"echo "== FRAMEGEN"diff --git a/helpers/iconmaker.swift b/helpers/iconmaker.swiftindex cec00ee..b0daa01 100644--- a/helpers/iconmaker.swift+++ b/helpers/iconmaker.swift@@ -61,12 +61,7 @@ let sizes: [(side: Int, scale: Int, name: String)] = []let fm = FileManager.default-let iconsetURL: URL-if #available(macOS 13.0, *) {- iconsetURL = URL(filePath: outputPath + ".iconset")-} else {- iconsetURL = URL(fileURLWithPath: outputPath + ".iconset")-}+let iconsetURL = URL(filePath: outputPath + ".iconset")try? fm.removeItem(at: iconsetURL)try fm.createDirectory(at: iconsetURL, withIntermediateDirectories: true)@@ -110,12 +105,7 @@ for entry in sizes {exit(1)}- let fileURL: URL- if #available(macOS 13.0, *) {- fileURL = iconsetURL.appending(path: entry.name)- } else {- fileURL = iconsetURL.appendingPathComponent(entry.name)- }+ let fileURL = iconsetURL.appending(path: entry.name)try png.write(to: fileURL)}diff --git a/native-shim/hid_profile.c b/native-shim/hid_profile.cindex 6c592c7..67c7a55 100644--- a/native-shim/hid_profile.c+++ b/native-shim/hid_profile.c@@ -261,7 +261,7 @@ static void parse_descriptor(const uint8_t *d, size_t len, parse_result *o) {break;}} else if (type == 0) { // Main- uint8_t in_pad = depth > 0 && pad[depth - 1];+ uint8_t in_pad = depth > 0 && pad[(depth < MAX_DEPTH ? depth : MAX_DEPTH) - 1];switch (tag) {case 8: // Inputparse_input(o, &g, &l, u, in_pad, (uint32_t)bits[g.id & 0xff]);@@ -577,7 +577,7 @@ static int find_axis(const np_profile *p, uint16_t page, uint16_t usage) {// SDL "generic" style layout from the descriptor alone.static void apply_generic(np_profile *p) {- char m[512];+ char m[512] = "";size_t n = 0;#define ADD(...) n += (size_t)snprintf(m + n, n < sizeof m ? sizeof m - n : 0, __VA_ARGS__)int x = find_axis(p, PAGE_GD, 0x30), y = find_axis(p, PAGE_GD, 0x31);@@ -592,7 +592,6 @@ static void apply_generic(np_profile *p) {if (rx >= 0 && ry >= 0) { lt = rx; rt = ry; }} else if (rx >= 0 && ry >= 0) {ADD("rightx:a%d,righty:a%d,", rx, ry);- if (z >= 0 && rz >= 0) { lt = z; rt = rz; }}if (accel >= 0 && brake >= 0) { lt = brake; rt = accel; }if (lt >= 0) ADD("lefttrigger:a%d,righttrigger:a%d,", lt, rt);@@ -672,7 +671,8 @@ np_profile *np_profile_create_from_descriptor(const uint8_t *descriptor, size_tconst hid_element *e = &p->el[p->axes[i]];p->raw[p->axes[i]] = (int32_t)(((int64_t)e->lmin + e->lmax + 1) / 2);}- for (int i = 0; i < p->nhats; i++) p->raw[p->hats[i]] = p->el[p->hats[i]].lmax + 1;+ for (int i = 0; i < p->nhats; i++)+ p->raw[p->hats[i]] = (int32_t)((uint32_t)p->el[p->hats[i]].lmax + 1u);uint8_t guid[16];make_guid(guid, vendor, product, version, name);diff --git a/native-shim/tests/run.sh b/native-shim/tests/run.shindex 79ab143..39544e0 100755--- a/native-shim/tests/run.sh+++ b/native-shim/tests/run.sh@@ -4,7 +4,7 @@ set -euhere=$(cd "$(dirname "$0")" && pwd)out=${TMPDIR:-/tmp}/np_hid_profile_testsclang -arch arm64 -std=c11 -D_DARWIN_C_SOURCE -g -O1 -Wall -Wextra -Werror \- -fsanitize=address,undefined -fno-sanitize-recover=all \+ -fsanitize=address,undefined -fno-sanitize-recover=all -ftrivial-auto-var-init=pattern \-framework IOKit -framework CoreFoundation \-o "$out" "$here/../hid_profile.c" "$here/test_hid_profile.c""$out" "$here/fixtures"diff --git a/native-shim/tests/test_hid_profile.c b/native-shim/tests/test_hid_profile.cindex 204f950..e61c486 100644--- a/native-shim/tests/test_hid_profile.c+++ b/native-shim/tests/test_hid_profile.c@@ -223,6 +223,21 @@ static void test_generic(void) {CHECK(np_profile_decode(p, 0, up, sizeof up, &s));CHECK(s.buttons == (BTN(NP_BTN_B) | BTN(NP_BTN_DPAD_UP))); // a:b1,b:b0np_profile_free(p);++ // A Joystick with one Slider and no DB line: no standard control, so nothing is bound.+ static const uint8_t slider_desc[] = {+ 0x05, 0x01, 0x09, 0x04, 0xa1, 0x01,+ 0x09, 0x36, 0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 0x08, 0x95, 0x01, 0x81, 0x02,+ 0xc0,+ };+ p = np_profile_create_from_descriptor(slider_desc, sizeof slider_desc, 0x1234, 0x567b,+ 0x0100, "Handbrake");+ CHECK(p && !strcmp(np_profile_name(p), "Generic HID gamepad"));+ np_profile_counts(p, &axes, &buttons, &hats);+ CHECK(axes == 1 && buttons == 0 && hats == 0);+ uint8_t slider[1] = {0x40};+ CHECK(!np_profile_decode(p, 0, slider, sizeof slider, &s));+ np_profile_free(p);printf("ok generic DInput pad: default mapping, DB fallbacks\n");}@@ -321,6 +336,30 @@ static void test_left_alone(void) {uint8_t junk[300];for (size_t i = 0; i < sizeof junk; i++) junk[i] = (uint8_t)(i * 73 + 11);np_profile_free(np_profile_create_from_descriptor(junk, sizeof junk, 0x1111, 0x2222, 1, "x"));+ // Collections nested past the parser's 32 levels, then an axis: it stays in the pad.+ uint8_t deep[100] = {0x05, 0x01, 0x09, 0x05};+ size_t m = 4;+ for (int i = 0; i < 40; i++) { deep[m++] = 0xa1; deep[m++] = 0x01; }+ static const uint8_t deep_axis[] = {0x09, 0x30, 0x15, 0x00, 0x25, 0x7f, 0x75, 0x08, 0x95, 0x01, 0x81, 0x02};+ memcpy(deep + m, deep_axis, sizeof deep_axis);+ m += sizeof deep_axis;+ p = np_profile_create_from_descriptor(deep, m, 0x1111, 0x2222, 1, "Deep");+ CHECK(p);+ int axes, buttons, hats;+ np_profile_counts(p, &axes, &buttons, &hats);+ CHECK(axes == 1 && buttons == 0 && hats == 0);+ np_profile_free(p);+ // A hat whose Logical Maximum has no room above it.+ static const uint8_t wide_hat[] = {+ 0x05, 0x01, 0x09, 0x05, 0xa1, 0x01,+ 0x09, 0x39, 0x15, 0x00, 0x27, 0xff, 0xff, 0xff, 0x7f, 0x75, 0x20, 0x95, 0x01, 0x81, 0x42,+ 0xc0,+ };+ p = np_profile_create_from_descriptor(wide_hat, sizeof wide_hat, 0x1111, 0x2222, 1, "Wide");+ CHECK(p);+ np_profile_counts(p, &axes, &buttons, &hats);+ CHECK(axes == 0 && buttons == 0 && hats == 1);+ np_profile_free(p);printf("ok left alone: Sony, Microsoft, Nintendo, \"Xbox\", non-gamepads\n");}diff --git a/ntdll-patch/shimcheck.py b/ntdll-patch/shimcheck.pyindex eeef78b..fe2cf44 100755--- a/ntdll-patch/shimcheck.py+++ b/ntdll-patch/shimcheck.py@@ -212,7 +212,7 @@ def pinned(resolve_py):def string_end(t, k):- """If a Swift string literal starts at t[k], the index just past it, else None.+ r"""If a Swift string literal starts at t[k], the index just past it, else None.Handles raw (#"..."#), multi-line and interpolated ("\(f("x"))") strings."""