Skip to content

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

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.sh
index 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 -eu
here="$(cd "$(dirname "$0")" && pwd)"
@@ -28,12 +28,11 @@ if [ ! -f "$MANIFEST" ]; then
exit 1
fi
-# 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.c
index 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 this
NP_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.c
index 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.h
index 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.sh
index 0e2f51a..26cf77c 100755
--- a/dylib/feats/compat_run.sh
+++ b/dylib/feats/compat_run.sh
@@ -237,7 +237,8 @@ fi
echo "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_} ;;
esac
value=${line#*=}
diff --git a/dylib/resolver/anchor.c b/dylib/resolver/anchor.c
index 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.h
index 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 string
NP_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 load
NP_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 kinds
uintptr_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 match
int nth_xref;
diff --git a/dylib/tests/envcheck.sh b/dylib/tests/envcheck.sh
index 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'b
c|unset" "$(mapped "BRIDGEPLAY_RETINA=a'b
c")"
+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 ]; then
echo "==> envcheck: all assertions hold"
else
diff --git a/dylib/tests/gamefixescheck.sh b/dylib/tests/gamefixescheck.sh
index 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 BRIDGEPLAY
is "NOTPROTON_ wins when both spellings are set" "0" "$(got NOTPROTON_RETINA)"
new_case
full_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.swift
index 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.c
index 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: // Input
parse_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_t
const 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.sh
index 79ab143..39544e0 100755
--- a/native-shim/tests/run.sh
+++ b/native-shim/tests/run.sh
@@ -4,7 +4,7 @@ set -eu
here=$(cd "$(dirname "$0")" && pwd)
out=${TMPDIR:-/tmp}/np_hid_profile_tests
clang -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.c
index 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:b0
np_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.py
index 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.
"""