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(np-native): run a bundle's executable when Steam passes the .app itself
raymondchins2449857987ef
diff --git a/Makefile b/Makefileindex 5f19eba..353780b 100644--- a/Makefile+++ b/Makefile@@ -779,7 +779,7 @@ np-native: $(NP_NATIVE)$(NP_NATIVE): $(NP_NATIVE_SRC)@mkdir -p $(dir $@)$(CC) -arch arm64 -arch x86_64 -mmacosx-version-min=11.0 -std=c17 -O2 \- -Wall -Wextra -Werror $< -o $@+ -Wall -Wextra -Werror $< -framework CoreFoundation -o $@codesign -s - -f $@@echo "==> Built $@ ($$(lipo -archs $@))"diff --git a/native-launch/np-native.c b/native-launch/np-native.cindex d0c61ca..43f420f 100644--- a/native-launch/np-native.c+++ b/native-launch/np-native.c@@ -32,6 +32,7 @@* NAME=VALUE token) or a failed exec exits 127. A library that does not exist* is never put into DYLD_INSERT_LIBRARIES, since dyld would abort the game.*/+#include <CoreFoundation/CoreFoundation.h>#include <ctype.h>#include <errno.h>#include <limits.h>@@ -252,6 +253,34 @@ static int file_exists(const char *p)return stat(p, &st) == 0 && S_ISREG(st.st_mode);}+/* Steam passes some games (Chained Beasts 3569420) as the .app bundle rather+ * than its binary; a directory cannot be exec'd, so run the bundle's main+ * executable instead. NULL when prog is not a bundle with one. */+static char *bundle_executable(const char *prog)+{+ size_t n = strlen(prog);+ while (n > 1 && prog[n - 1] == '/')+ n--;+ struct stat st;+ if (n < 5 || strncasecmp(prog + n - 4, ".app", 4) != 0 ||+ stat(prog, &st) != 0 || !S_ISDIR(st.st_mode))+ return NULL;+ char *exe = NULL;+ CFURLRef url = CFURLCreateFromFileSystemRepresentation(NULL, (const UInt8 *)prog, (CFIndex)n, true);+ CFBundleRef bundle = url ? CFBundleCreate(NULL, url) : NULL;+ CFURLRef exe_url = bundle ? CFBundleCopyExecutableURL(bundle) : NULL;+ char buf[PATH_MAX];+ if (exe_url && CFURLGetFileSystemRepresentation(exe_url, true, (UInt8 *)buf, sizeof buf))+ exe = xstrdup(buf);+ if (exe_url)+ CFRelease(exe_url);+ if (bundle)+ CFRelease(bundle);+ if (url)+ CFRelease(url);+ return exe;+}+struct libs {char *v[MAX_LIBS];int n;@@ -343,6 +372,9 @@ int main(int argc, char **argv)}if (i >= argc || argv[i][0] == '\0')die("no program to run; usage: np-native [VAR=VALUE ...] %%command%% [args]");+ char *exe = bundle_executable(argv[i]);+ if (exe)+ argv[i] = exe;char *const *prog_argv = &argv[i];const char *prog = argv[i];diff --git a/native-launch/tests/run.sh b/native-launch/tests/run.shindex 9147b53..1f15b7f 100644--- a/native-launch/tests/run.sh+++ b/native-launch/tests/run.sh@@ -27,7 +27,7 @@ if [ $# -ge 1 ]; thenlauncher=$1elselauncher=$tmp/np-native- build "$src/np-native.c" -o "$launcher"+ build "$src/np-native.c" -framework CoreFoundation -o "$launcher"codesign -s - -f "$launcher" 2>/dev/nullfi[ -x "$launcher" ] || { echo "==> np-native-tests: no launcher at $launcher" >&2; exit 1; }@@ -158,6 +158,17 @@ run "DYLD_INSERT_LIBRARIES=$steamlib" -- NP_PAD_MODE=hid "$tmp/game.sh"expect_rc "script: exit 0" 0expect "script: STEAM_DYLD_ carries the composed list" "script STEAM_DYLD=$pad:$steamlib"+# Steam passes some games as the .app bundle itself (Chained Beasts 3569420)+mkdir -p "$tmp/Game.app/Contents/MacOS"+cp "$probe" "$tmp/Game.app/Contents/MacOS/Game"+cat >"$tmp/Game.app/Contents/Info.plist" <<'EOF'+<?xml version="1.0" encoding="UTF-8"?>+<plist version="1.0"><dict><key>CFBundleExecutable</key><string>Game</string></dict></plist>+EOF+run -- NP_PAD_MODE=off "$tmp/Game.app" -novid+expect_rc "bundle: exit 0" 0+expect "bundle: runs the bundle's executable, arm64" "arch=arm64" "arg1=-novid"+# --- architecture ----------------------------------------------------------(exec env -i HOME="$H" PATH=/usr/bin:/bin NP_NATIVE_LOG=1 NP_PAD_MODE=hid \"DYLD_INSERT_LIBRARIES=$steamlib" \