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
Add support for running multiple versions of CrossOver as separate compatibility tools.
NotProtonNoteeb20ca0367f
diff --git a/app/Sources/NotProtonApp/Model/PrefixTools.swift b/app/Sources/NotProtonApp/Model/PrefixTools.swiftindex 10dd2bb..1a4e4f2 100644--- a/app/Sources/NotProtonApp/Model/PrefixTools.swift+++ b/app/Sources/NotProtonApp/Model/PrefixTools.swift@@ -19,6 +19,7 @@ enum WineTool: String, CaseIterable, Sendable {}}+// What compat_run.sh writes to notproton-build when a tool first runs a prefix.struct PrefixBuildRecord: Sendable, Equatable {let build: Stringlet display: String?diff --git a/app/Sources/NotProtonApp/Support/SupportPaths.swift b/app/Sources/NotProtonApp/Support/SupportPaths.swiftindex c7724f9..64f12c2 100644--- a/app/Sources/NotProtonApp/Support/SupportPaths.swift+++ b/app/Sources/NotProtonApp/Support/SupportPaths.swift@@ -39,6 +39,7 @@ enum SupportPaths {static var deployedVersion: URL { support.appending(path: "dylib.version") }+ // Read by the dylib at Steam launch, in np_compat_load_tool_list.static var toolList: URL { support.appending(path: "tools") }static func runnerRoot(forBuild build: String, runners: URL = SupportPaths.runners) -> URL {diff --git a/app/Tests/NotProtonAppTests/PrefixToolsTests.swift b/app/Tests/NotProtonAppTests/PrefixToolsTests.swiftindex b33bb9c..6cf03f6 100644--- a/app/Tests/NotProtonAppTests/PrefixToolsTests.swift+++ b/app/Tests/NotProtonAppTests/PrefixToolsTests.swift@@ -272,15 +272,21 @@ struct PrefixToolsTests {@Test("Only the pass that launches the game shows the alert")func alertSkipsTheEvaluatorPass() throws {let source = try Self.compatSource()- let gate = try #require(source.range(of: #"if [ "$verb" != run ]; then"#))+ let helper = try #require(source.range(of: "show_alert() {\n"))+ let gate = try #require(source.range(of: #" [ "$verb" != run ] || return 0"#))let alert = try #require(source.range(of: "display alert"))- let closing = try #require(- source.range(of: " fi\n", range: alert.upperBound..<source.endIndex))- let refusal = try #require(source.range(of: " exit 1\n"))+ #expect(helper.upperBound == gate.lowerBound)#expect(gate.upperBound < alert.lowerBound)- #expect(alert.upperBound < closing.lowerBound)- #expect(closing.upperBound <= refusal.lowerBound)+ #expect(source.ranges(of: "osascript").count == 1, "an alert bypasses show_alert")++ let calls = source.ranges(of: " show_alert \"")+ #expect(!calls.isEmpty)+ for call in calls {+ let rest = source[call.upperBound...]+ let line = try #require(rest.firstIndex(of: "\n"))+ #expect(rest[line...].hasPrefix("\n exit 1\n") || rest[line...].hasPrefix("\n exit 1\n"))+ }}@Test("The Rosetta flavor takes the x86_64 tree on a runner that has both")diff --git a/dylib/core/loader.c b/dylib/core/loader.cindex 49de7e3..0280ea2 100644--- a/dylib/core/loader.c+++ b/dylib/core/loader.c@@ -198,9 +198,6 @@ static void *install_thread(void *unused) {return NULL;}- // Registers compatibility tool.- np_compat_ensure_tool_manifest();-int total = 0;int installed = np_hooks_install_all(mh, slide, &resolved, &total);@@ -260,6 +257,9 @@ static void np_init(void) {np_log_platform_overrides();np_compat_export_tools_path();+ // Steam scans compatibilitytools.d at startup, so the tool directories have to exist+ // before that occurs.+ np_compat_ensure_tool_manifest();np_hooks_spawn_install();if (pthread_create(&g_install, NULL, install_thread, NULL) == 0)diff --git a/dylib/feats/compat.c b/dylib/feats/compat.cindex 2b613b1..15e95c4 100644--- a/dylib/feats/compat.c+++ b/dylib/feats/compat.c@@ -3,6 +3,7 @@#include "../util/log.h"#include "../util/file.h"+#include <dirent.h>#include <stdint.h>#include <stdio.h>#include <stdlib.h>@@ -14,10 +15,6 @@// the tool's name contains "proton" so without a match every AutoCloud rule silently// skips the app.#define TOOL_DIR_NAME "notproton"-#define TOOL_DIR_NAME_ROSETTA "notproton-fex-rosetta"-#define TOOL_DISPLAY_FEX "CrossOver Preview (FEX)"-#define TOOL_DISPLAY_ROSETTA "CrossOver Preview (Rosetta)"-#define TOOL_DISPLAY_ROSETTA_ONLY "CrossOver Preview (Rosetta build)"#define COMPAT_MANAGER_ENABLED_OFF 0x7B0#define COMPAT_TOOL_STRIDE 0x130@@ -293,50 +290,150 @@ void np_compat_export_tools_path(void) {tools_dir);}-static int has_fex_runner(void) {- const char *home = np_home_dir();- if (!home) return 0;+#define TOOL_LIST_MAX 8- char base[512];- snprintf(base, sizeof(base),- "%s/Library/Application Support/notproton/runners/current", home);+typedef struct {+ char name[64];+ char build[64];+ char flavor[16];+ char display[96];+ char dir[640];+} tool_entry_t;- char path[768];- snprintf(path, sizeof(path),- "%s/lib/wine/aarch64-unix/wine.app/Contents/MacOS/wine", base);- if (access(path, X_OK) != 0) return 0;+static tool_entry_t g_tools[TOOL_LIST_MAX];+static int g_tool_count;+static int g_tool_list_present;- snprintf(path, sizeof(path), "%s/CrossOver-Hosted Application/wineserver-arm64", base);- return access(path, X_OK) == 0;+static int is_token(const char *s, const char *extra) {+ if (!*s) return 0;+ for (; *s; s++) {+ if ((*s >= 'a' && *s <= 'z') || (*s >= 'A' && *s <= 'Z') || (*s >= '0' && *s <= '9'))+ continue;+ if (!strchr(extra, *s)) return 0;+ }+ return 1;}-static const char *primary_display_name(void) {- return has_fex_runner() ? TOOL_DISPLAY_FEX : TOOL_DISPLAY_ROSETTA_ONLY;+static int is_display(const char *s) {+ if (!*s) return 0;+ for (; *s; s++)+ if (*s == '"' || *s == '\\' || (unsigned char)*s < 0x20) return 0;+ return 1;}-static int write_tool(const char *tools_dir, const char *name,- const char *display, const char *flavor) {- char tool_dir[640];- snprintf(tool_dir, sizeof(tool_dir), "%s/%s", tools_dir, name);+static int parse_tool_line(char *line, tool_entry_t *out) {+ char *field[4];+ int n = 0;+ char *save = NULL;+ for (char *tok = strtok_r(line, "\t", &save); tok && n < 4;+ tok = strtok_r(NULL, "\t", &save))+ field[n++] = tok;+ if (n != 4) return 0;++ if (strncmp(field[0], TOOL_DIR_NAME, strlen(TOOL_DIR_NAME)) != 0+ || !is_token(field[0], "._-") || !is_token(field[1], ".-")+ || (strcmp(field[2], "fex") != 0 && strcmp(field[2], "rosetta") != 0)+ || !is_display(field[3]))+ return 0;+ if (strlen(field[0]) >= sizeof(out->name) || strlen(field[1]) >= sizeof(out->build)+ || strlen(field[3]) >= sizeof(out->display))+ return 0;++ snprintf(out->name, sizeof(out->name), "%s", field[0]);+ snprintf(out->build, sizeof(out->build), "%s", field[1]);+ snprintf(out->flavor, sizeof(out->flavor), "%s", field[2]);+ snprintf(out->display, sizeof(out->display), "%s", field[3]);+ return 1;+}++int np_compat_load_tool_list(const char *path, const char *tools_dir) {+ g_tool_count = 0;+ g_tool_list_present = 0;++ FILE *f = fopen(path, "r");+ if (!f) {+ NP_WARN("np_compat_load_tool_list: %s is missing, so no build has a tool "+ "until NotProton sets one up", path);+ return 0;+ }+ g_tool_list_present = 1;++ char line[512];+ int lineno = 0;+ while (fgets(line, sizeof(line), f)) {+ lineno++;+ line[strcspn(line, "\r\n")] = '\0';+ if (!line[0]) continue;++ tool_entry_t entry;+ if (!parse_tool_line(line, &entry)) {+ NP_WARN("np_compat_load_tool_list: %s line %d is not a tool, skipped",+ path, lineno);+ continue;+ }++ int taken = 0;+ for (int i = 0; i < g_tool_count; i++)+ taken |= strcmp(g_tools[i].name, entry.name) == 0;+ if (taken) {+ NP_WARN("np_compat_load_tool_list: %s is listed twice, the later line "+ "(build %s) is skipped", entry.name, entry.build);+ continue;+ }+ if (g_tool_count == TOOL_LIST_MAX) {+ NP_WARN("np_compat_load_tool_list: more than %d tools listed, %s skipped",+ TOOL_LIST_MAX, entry.name);+ continue;+ }++ snprintf(entry.dir, sizeof(entry.dir), "%s/%s", tools_dir, entry.name);+ g_tools[g_tool_count++] = entry;+ }+ fclose(f);+ return g_tool_count;+}++static int tools_dir_path(char *out, size_t size) {+ const char *home = np_home_dir();+ if (!home) return -1;+ snprintf(out, size, "%s/Library/Application Support/Steam/compatibilitytools.d", home);+ return 0;+}- if (ensure_dir(tool_dir) != 0) {- NP_WARN("np_compat_ensure_tool_manifest: cannot create %s", tool_dir);+static void load_tool_list_once(void) {+ static int loaded = 0;+ if (loaded) return;+ loaded = 1;++ const char *home = np_home_dir();+ char tools_dir[512];+ if (!home || tools_dir_path(tools_dir, sizeof(tools_dir)) != 0) return;++ char path[512];+ snprintf(path, sizeof(path), "%s/Library/Application Support/notproton/tools", home);+ np_compat_load_tool_list(path, tools_dir);+}++static int write_tool(const tool_entry_t *tool) {+ if (ensure_dir(tool->dir) != 0) {+ NP_WARN("np_compat_ensure_tool_manifest: cannot create %s", tool->dir);return -1;}char declaration[512];- snprintf(declaration, sizeof(declaration), TOOL_DECLARATION_FMT, name, display);+ snprintf(declaration, sizeof(declaration), TOOL_DECLARATION_FMT,+ tool->name, tool->display);char path[768];int wrote = 0;// Rewritten every launch so field changes take effect. A rescan replaces it in// place rather than adding a second copy.- snprintf(path, sizeof(path), "%s/compatibilitytool.vdf", tool_dir);+ snprintf(path, sizeof(path), "%s/compatibilitytool.vdf", tool->dir);if (write_file(path, declaration, 0) == 0) wrote++;else NP_WARN("np_compat_ensure_tool_manifest: failed to write %s", path);- snprintf(path, sizeof(path), "%s/toolmanifest.vdf", tool_dir);+ snprintf(path, sizeof(path), "%s/toolmanifest.vdf", tool->dir);if (access(path, F_OK) != 0) {if (write_file(path, TOOL_MANIFEST, 0) == 0) wrote++;else NP_WARN("np_compat_ensure_tool_manifest: failed to write %s", path);@@ -344,32 +441,55 @@ static int write_tool(const char *tools_dir, const char *name,// The run script is the shim this project owns and updates, so rewrite it// every launch rather than leaving a stale copy behind.- snprintf(path, sizeof(path), "%s/run", tool_dir);+ snprintf(path, sizeof(path), "%s/run", tool->dir);if (write_file(path, RUN_SCRIPT, 1) == 0) wrote++;else NP_WARN("np_compat_ensure_tool_manifest: failed to write %s", path);- char flavor_line[32];- snprintf(flavor_line, sizeof(flavor_line), "%s\n", flavor);- snprintf(path, sizeof(path), "%s/flavor", tool_dir);- if (write_file(path, flavor_line, 0) == 0) wrote++;+ char line[80];+ snprintf(line, sizeof(line), "%s\n", tool->flavor);+ snprintf(path, sizeof(path), "%s/flavor", tool->dir);+ if (write_file(path, line, 0) == 0) wrote++;+ else NP_WARN("np_compat_ensure_tool_manifest: failed to write %s", path);++ snprintf(line, sizeof(line), "%s\n", tool->build);+ snprintf(path, sizeof(path), "%s/build", tool->dir);+ if (write_file(path, line, 0) == 0) wrote++;else NP_WARN("np_compat_ensure_tool_manifest: failed to write %s", path);if (wrote > 0)- NP_LOG("np_compat_ensure_tool_manifest: wrote %d file(s) to %s", wrote, tool_dir);+ NP_LOG("np_compat_ensure_tool_manifest: wrote %d file(s) to %s", wrote, tool->dir);return 0;}+#define RUN_SCRIPT_MARK "\n# notproton CrossOver compatibility tool shim\n"++static int written_here(const char *tool_dir) {+ char path[768];+ snprintf(path, sizeof(path), "%s/flavor", tool_dir);+ if (access(path, F_OK) == 0) return 1;++ snprintf(path, sizeof(path), "%s/run", tool_dir);+ FILE *f = fopen(path, "r");+ if (!f) return 0;+ char head[128];+ size_t got = fread(head, 1, sizeof(head) - 1, f);+ fclose(f);+ head[got] = '\0';+ return strstr(head, RUN_SCRIPT_MARK) != NULL;+}+static void remove_tool(const char *tools_dir, const char *name) {char tool_dir[640];snprintf(tool_dir, sizeof(tool_dir), "%s/%s", tools_dir, name);- if (access(tool_dir, F_OK) != 0) return;+ if (!written_here(tool_dir)) return;++ char path[768];static const char *const files[] = {- "compatibilitytool.vdf", "toolmanifest.vdf", "run", "flavor",+ "compatibilitytool.vdf", "toolmanifest.vdf", "run", "flavor", "build",};- char path[768];for (size_t i = 0; i < sizeof(files) / sizeof(files[0]); i++) {snprintf(path, sizeof(path), "%s/%s", tool_dir, files[i]);unlink(path);@@ -377,54 +497,72 @@ static void remove_tool(const char *tools_dir, const char *name) {if (rmdir(tool_dir) == 0)NP_LOG("np_compat_ensure_tool_manifest: removed %s", tool_dir);+ else+ NP_WARN("np_compat_ensure_tool_manifest: %s holds files this did not write, "+ "so it stays", tool_dir);}-int np_compat_ensure_tool_manifest(void) {- const char *home = np_home_dir();- if (!home) return -1;+static int is_listed(const char *name) {+ for (int i = 0; i < g_tool_count; i++)+ if (strcmp(g_tools[i].name, name) == 0) return 1;+ return 0;+}++static void remove_unlisted_tools(const char *tools_dir) {+ DIR *dir = opendir(tools_dir);+ if (!dir) return;++ struct dirent *e;+ while ((e = readdir(dir)) != NULL) {+ if (strncmp(e->d_name, TOOL_DIR_NAME, strlen(TOOL_DIR_NAME)) != 0) continue;+ if (is_listed(e->d_name)) continue;+ remove_tool(tools_dir, e->d_name);+ }+ closedir(dir);+}+int np_compat_ensure_tool_manifest(void) {char tools_dir[512];- snprintf(tools_dir, sizeof(tools_dir),- "%s/Library/Application Support/Steam/compatibilitytools.d", home);+ if (tools_dir_path(tools_dir, sizeof(tools_dir)) != 0) return -1;if (ensure_dir(tools_dir) != 0) {NP_WARN("np_compat_ensure_tool_manifest: cannot create %s", tools_dir);return -1;}- int fex = has_fex_runner();+ load_tool_list_once();- if (write_tool(tools_dir, TOOL_DIR_NAME,- fex ? TOOL_DISPLAY_FEX : TOOL_DISPLAY_ROSETTA_ONLY,- fex ? "fex" : "rosetta") != 0)- return -1;+ if (!g_tool_list_present) return 0;- if (fex)- write_tool(tools_dir, TOOL_DIR_NAME_ROSETTA, TOOL_DISPLAY_ROSETTA, "rosetta");- else- remove_tool(tools_dir, TOOL_DIR_NAME_ROSETTA);+ int failed = 0;+ for (int i = 0; i < g_tool_count; i++)+ failed |= write_tool(&g_tools[i]) != 0;- return 0;+ remove_unlisted_tools(tools_dir);+ return failed ? -1 : 0;}const char *np_compat_tool_dir(void) {- static char dir[512];+ static char dir[640];static int resolved = 0;if (resolved)return dir[0] ? dir : NULL;resolved = 1;+ load_tool_list_once();- const char *home = np_home_dir();- if (!home) {+ if (g_tool_count > 0) {+ snprintf(dir, sizeof(dir), "%s", g_tools[0].dir);+ return dir;+ }++ char tools_dir[512];+ if (tools_dir_path(tools_dir, sizeof(tools_dir)) != 0) {dir[0] = '\0';return NULL;}-- snprintf(dir, sizeof(dir),- "%s/Library/Application Support/Steam/compatibilitytools.d/%s",- home, TOOL_DIR_NAME);+ snprintf(dir, sizeof(dir), "%s/%s", tools_dir, TOOL_DIR_NAME);return dir;}@@ -559,6 +697,29 @@ void *np_compat_manager(void) {return g_manager;}+static void *find_tool(void *compat_mgr, const char *wanted) {+ uint8_t *base = (uint8_t *)compat_mgr;+ uint8_t *array = *(uint8_t **)(base + COMPAT_MANAGER_TOOL_ARRAY_OFF);+ uint32_t count = *(uint32_t *)(base + COMPAT_MANAGER_TOOL_COUNT_OFF);+ if (!array || count > COMPAT_MANAGER_TOOLS_MAX) {+ // Once, because Steam walks this for every windows-only app as the library+ // redraws and a count this wrong does not correct itself.+ static const char once = 0;+ if (np_log_first_hit(&once, 0))+ NP_ERR("np_compat_registered_tool: the manager reports %u tool(s) at %p, "+ "which is not a list this reads", count, (const void *)array);+ return NULL;+ }++ for (uint32_t i = 0; i < count; i++) {+ uint8_t *entry = array + (size_t)i * np_compat_tool_stride();+ const char *name = *(const char **)(entry + COMPAT_TOOL_NAME_OFF);+ if (name && strcmp(name, wanted) == 0)+ return entry;+ }+ return NULL;+}+void np_compat_register_crossover(void *compat_mgr) {static int registered = 0;@@ -569,68 +730,55 @@ void np_compat_register_crossover(void *compat_mgr) {if (registered || !compat_mgr || !g_yld_register_tool)return;-- // The compatibilitytools.d scan registers this tool from disk at client startup,- // so any session that found the manifest there already holds an entry and a- // second one is a duplicate under the same name. Only the first session after an- // install, when the manifest did not exist to be scanned, has nothing to find.- if (np_compat_registered_tool(compat_mgr)) {- registered = 1;- NP_LOG("np_compat_register_crossover: %s already registered from disk, "- "skipping the runtime entry", TOOL_DIR_NAME);- return;- }+ registered = 1;+ load_tool_list_once();// YldRegisterTool copies a whole entry out of this buffer and keeps the string- // pointers as-is, which is why the strings are static and why the buffer carries- // headroom for a client that inserted a field. to_oslist=macos passes the- // registration gate, from_oslist=windows intersects the app mask so the dropdown- // keeps it, and appid 0 marks a manager-local tool the resolver routes to the- // local run script.- static uint8_t tool[COMPAT_TOOL_STRIDE + 64];- memset(tool, 0, sizeof(tool));-- static const char name[] = TOOL_DIR_NAME;- const char *display = primary_display_name();+ // pointers as-is, which is why the strings live in g_tools and why each buffer+ // carries headroom for a client that inserted a field. to_oslist=macos passes+ // the registration gate, from_oslist=windows intersects the app mask so the+ // dropdown keeps it, and appid 0 marks a manager-local tool the resolver routes+ // to the local run script.+ static uint8_t buffers[TOOL_LIST_MAX][COMPAT_TOOL_STRIDE + 64];static const char from_oslist[] = "windows";static const char to_oslist[] = "macos";- *(uint32_t *)(tool + COMPAT_TOOL_FLAGS_OFF) = COMPAT_TOOL_FLAG_NO_APP;- *(const char **)(tool + COMPAT_TOOL_NAME_OFF) = name;- *(const char **)(tool + COMPAT_TOOL_DISPLAY_OFF) = display;- *(const char **)(tool + np_compat_tool_off(COMPAT_TOOL_INSTALL_OFF)) =- np_compat_tool_dir();- *(uint32_t *)(tool + np_compat_tool_off(COMPAT_TOOL_APPID_OFF)) = 0;- *(const char **)(tool + np_compat_tool_off(COMPAT_TOOL_FROM_OSLIST_OFF)) = from_oslist;- *(const char **)(tool + np_compat_tool_off(COMPAT_TOOL_TO_OSLIST_OFF)) = to_oslist;+ for (int i = 0; i < g_tool_count; i++) {+ const tool_entry_t *t = &g_tools[i];- registered = 1;- g_yld_register_tool(compat_mgr, tool);- NP_LOG("np_compat_register_crossover: registered %s into manager 0x%llx",- name, (unsigned long long)(uintptr_t)compat_mgr);+ if (find_tool(compat_mgr, t->name)) {+ NP_LOG("np_compat_register_crossover: %s already registered from disk, "+ "skipping the runtime entry", t->name);+ continue;+ }++ uint8_t *tool = buffers[i];+ memset(tool, 0, sizeof(buffers[i]));+ *(uint32_t *)(tool + COMPAT_TOOL_FLAGS_OFF) = COMPAT_TOOL_FLAG_NO_APP;+ *(const char **)(tool + COMPAT_TOOL_NAME_OFF) = t->name;+ *(const char **)(tool + COMPAT_TOOL_DISPLAY_OFF) = t->display;+ *(const char **)(tool + np_compat_tool_off(COMPAT_TOOL_INSTALL_OFF)) = t->dir;+ *(uint32_t *)(tool + np_compat_tool_off(COMPAT_TOOL_APPID_OFF)) = 0;+ *(const char **)(tool + np_compat_tool_off(COMPAT_TOOL_FROM_OSLIST_OFF)) = from_oslist;+ *(const char **)(tool + np_compat_tool_off(COMPAT_TOOL_TO_OSLIST_OFF)) = to_oslist;++ g_yld_register_tool(compat_mgr, tool);+ NP_LOG("np_compat_register_crossover: registered %s (build %s) into manager 0x%llx",+ t->name, t->build, (unsigned long long)(uintptr_t)compat_mgr);+ }}void *np_compat_registered_tool(void *compat_mgr) {if (!compat_mgr)return NULL;- uint8_t *base = (uint8_t *)compat_mgr;- uint8_t *array = *(uint8_t **)(base + COMPAT_MANAGER_TOOL_ARRAY_OFF);- uint32_t count = *(uint32_t *)(base + COMPAT_MANAGER_TOOL_COUNT_OFF);- if (!array || count > COMPAT_MANAGER_TOOLS_MAX) {- // Once, because Steam walks this for every windows-only app as the library- // redraws and a count this wrong does not correct itself.- static const char once = 0;- if (np_log_first_hit(&once, 0))- NP_ERR("np_compat_registered_tool: the manager reports %u tool(s) at %p, "- "which is not a list this reads", count, (const void *)array);- return NULL;- }+ load_tool_list_once();+ if (g_tool_count == 0)+ return find_tool(compat_mgr, TOOL_DIR_NAME);- for (uint32_t i = 0; i < count; i++) {- uint8_t *entry = array + (size_t)i * np_compat_tool_stride();- const char *name = *(const char **)(entry + COMPAT_TOOL_NAME_OFF);- if (name && strcmp(name, TOOL_DIR_NAME) == 0)+ for (int i = 0; i < g_tool_count; i++) {+ void *entry = find_tool(compat_mgr, g_tools[i].name);+ if (entry)return entry;}return NULL;diff --git a/dylib/feats/compat.h b/dylib/feats/compat.hindex d49b131..9ce2aaf 100644--- a/dylib/feats/compat.h+++ b/dylib/feats/compat.h@@ -53,6 +53,12 @@ size_t np_compat_tool_stride(void);// initial one exists (setenv can free the environ the client is reading).void np_compat_export_tools_path(void);+// Reads the app's tool list into g_tools, skipping lines that do not parse. Returns the+// number of tools kept.+int np_compat_load_tool_list(const char *path, const char *tools_dir);++// Writes a directory for every tool in the app's list and removes the directories of tools+// no longer in it.int np_compat_ensure_tool_manifest(void);void np_compat_force_enable(void *compat_mgr);@@ -99,7 +105,7 @@ void np_compat_map_tool(void *compat_mgr, uint32_t appid, const char *tool_name)// CCompatManager::YldRegisterTool, resolved at install time.void np_compat_set_register_fn(uintptr_t yld_register_tool);-// Registers CrossOver into the given manager once. The local+// Registers every tool in the app's list into the given manager once. The local// compatibilitytools.d scan uses a different instance than the dropdown reads// and does not run on every launch, so this registers into the right one.void np_compat_register_crossover(void *compat_mgr);@@ -109,12 +115,11 @@ void np_compat_register_crossover(void *compat_mgr);// scan builds a different instance).void *np_compat_manager(void);-// The registered CrossOver tool entry in the manager array, or NULL.+// The first tool in the app's list the manager holds, or NULL.// Manager-owned. Callers read fields without taking ownership.void *np_compat_registered_tool(void *compat_mgr);-// Absolute path to the local CrossOver tool directory, or NULL. Resolved once-// and cached.+// Absolute path to the directory of the first tool in the app's list, or NULL.const char *np_compat_tool_dir(void);// Command line template for the tool's toolmanifest.vdf commandline value.diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.shindex 545578b..e1ba6f6 100755--- a/dylib/feats/compat_run.sh+++ b/dylib/feats/compat_run.sh@@ -8,6 +8,23 @@ shift || true# hook_launch.c passes the launch options through a shell before this script runs, matching# Linux Steam. A NAME=value option placed ahead of %command% is an environment variable,# and anything after %command% is a launch argument passed to the game.+# Options saved before the panel wrote %command% arrive after the game instead of ahead of it.+launch_env=""+argc=$#+argi=0+while [ "$argi" -lt "$argc" ]; do+ arg="$1"+ shift+ case "$arg" in+ CX_GRAPHICS*=*|D3DM_*=*|DXMT_*=*|DXVK_*=*|MTL_*=*|NOTPROTON_*=*|ROSETTA_*=*|WINE*=*)+ # shellcheck disable=SC2163 # arg is a NAME=VALUE pair, which export takes as an assignment+ export "$arg"+ launch_env="$launch_env $arg"+ ;;+ *) set -- "$@" "$arg" ;;+ esac+ argi=$((argi + 1))+donelaunch_args="$*"case "$verb" in@@ -17,17 +34,26 @@ case "$verb" in;;esac-CX_ROOT="$HOME/Library/Application Support/notproton/runners/current"-export CX_ROOT+np_support="$HOME/Library/Application Support/notproton"# cxcompatdb resolves its database through CX_HOME and logs an error for# every module loaded without it :(export CX_HOME="$HOME/Library/Application Support/CrossOver"np_flavor=""+np_build=""CDPATH=''np_tool_dir=$(cd -- "$(dirname -- "$0")" 2>/dev/null && pwd) || np_tool_dir=""if [ -n "$np_tool_dir" ] && [ -r "$np_tool_dir/flavor" ]; thenread -r np_flavor < "$np_tool_dir/flavor" || np_flavor=""fi+if [ -n "$np_tool_dir" ] && [ -r "$np_tool_dir/build" ]; then+ read -r np_build < "$np_tool_dir/build" || np_build=""+fi+case "$np_build" in *[!A-Za-z0-9.-]*) np_build="" ;; esac+np_display=$(sed -n 's/.*"display_name"[[:space:]]*"\(.*\)".*/\1/p' \+ "$np_tool_dir/compatibilitytool.vdf" 2>/dev/null | head -1) || np_display=""+[ -n "$np_display" ] || np_display="CrossOver build ${np_build:-unknown}"+CX_ROOT="$np_support/runners/crossover-$np_build/CrossOver"+export CX_ROOTwine_unix="$CX_ROOT/lib/wine/aarch64-unix"WINELOADER="$wine_unix/wine.app/Contents/MacOS/wine"@@ -107,6 +133,20 @@ tool_name() {esac}+# Steam passes "run" for helpers such as install scripts, which get no dialog.+show_alert() {+ [ "$verb" != run ] || return 0+ osascript >/dev/null 2>&1 <<APPLESCRIPT || true+display alert "$1" message "$2" as critical+APPLESCRIPT+}++# A quote or backslash in the text would end the AppleScript string early.+alert_safe() {+ # shellcheck disable=SC1003 # the pair deletes a literal backslash, not a quote+ printf '%s' "$1" | tr -d '"\\'+}+refuse_foreign_prefix() {case "${wine_unix##*/}" inaarch64-unix) want=aa64 ;;@@ -115,13 +155,53 @@ refuse_foreign_prefix() {have=$(prefix_machine) || return 0[ "$have" = "$want" ] && return 0echo "=== prefix ntdll is $have and this compatibility tool wants $want, rebuild the prefix in NotProton ===" >> "$log" 2>&1 || true+ show_alert "This game needs its prefix rebuilt" "This game originally ran under $(tool_name "$have"), but $(tool_name "$want") is present now. The prefix needs to be rebuilt in NotProton in order to run the game. You will not lose game saves by rebuilding the prefix."+ exit 1+}- if [ "$verb" != run ]; then- osascript >/dev/null 2>&1 <<APPLESCRIPT || true-display alert "This game needs its prefix rebuilt" message "This game originally ran under $(tool_name "$have"), but $(tool_name "$want") is present now. The prefix needs to be rebuilt in NotProton in order to run the game. You will not lose game saves by rebuilding the prefix." as critical-APPLESCRIPT+last_wine_build() {+ updated_file="$STEAM_COMPAT_DATA_PATH/pfx/.update-timestamp"+ [ -r "$updated_file" ] || return 0+ read -r updated _ < "$updated_file" || true+ case "$updated" in '' | *[!0-9]*) return 0 ;; esac+ [ "$updated" = "$(stat -f %m "$CX_ROOT/share/wine/wine.inf" 2>/dev/null)" ] && return 0+ had_build=other+ had_display="another version of CrossOver"+ for inf in "$np_support"/runners/crossover-*/CrossOver/share/wine/wine.inf; do+ [ "$(stat -f %m "$inf" 2>/dev/null)" = "$updated" ] || continue+ had_build=${inf#"$np_support/runners/crossover-"}+ had_build=${had_build%%/*}+ had_display=$(awk -F '\t' -v b="$had_build" '$2 == b { print $4; exit }' \+ "$np_support/tools" 2>/dev/null) || had_display=""+ break+ done+}++refuse_other_build() {+ record="$STEAM_COMPAT_DATA_PATH/notproton-build"+ had_build=""+ had_display=""+ if [ -r "$record" ]; then+ {+ read -r had_build || true+ read -r had_display || true+ } < "$record"+ else+ last_wine_buildfi- exit 1+ if [ -n "$had_build" ] && [ "$had_build" != "$np_build" ]; then+ echo "=== prefix was last run by build $had_build and this compatibility tool runs $np_build, rebuild the prefix in NotProton ===" >> "$log" 2>&1 || true+ had_display=$(alert_safe "${had_display:-CrossOver build $had_build}")+ show_alert "This game needs its prefix rebuilt" "This game's prefix was last run by $had_display, and this compatibility tool runs $(alert_safe "$np_display"). Rebuild the prefix in NotProton to run it here, or pick $had_display again in the game's Compatibility settings. You will not lose game saves by rebuilding the prefix."+ exit 1+ fi+}++claim_prefix() {+ [ -r "$STEAM_COMPAT_DATA_PATH/notproton-build" ] \+ || echo "=== prefix claimed by build $np_build ===" >> "$log" 2>&1 || true+ printf '%s\n%s\n' "$np_build" "$np_display" > "$STEAM_COMPAT_DATA_PATH/notproton-build" 2>/dev/null \+ || echo "=== could not record build $np_build in the prefix ===" >> "$log" 2>&1 || true}# Steam cloud relatedmerge_user_dir() {@@ -269,6 +349,14 @@ lay_out_proton_profile() {fi}+stage_step="runner check"+if [ -z "$np_build" ] || [ ! -d "$CX_ROOT/lib/wine" ]; then+ echo "=== build ${np_build:-(none recorded)} behind this compatibility tool is not set up, set it up in NotProton ===" >> "$log" 2>&1 || true+ show_alert "CrossOver is not set up" "The CrossOver build behind $(alert_safe "$np_display") is not set up. Set it up in NotProton, or pick another compatibility tool for this game."+ exit 1+fi+echo "runner: build $np_build ($np_display) at $CX_ROOT" >> "$log" 2>&1 || true+if [ -n "$STEAM_COMPAT_DATA_PATH" ]; thenexport WINEPREFIX="$STEAM_COMPAT_DATA_PATH/pfx"mkdir -p "$WINEPREFIX"@@ -282,8 +370,11 @@ if [ -n "$STEAM_COMPAT_DATA_PATH" ]; thenexport WINEMSYNC="${WINEMSYNC:-0}"printf '%s' "$WINEMSYNC" \> "$STEAM_COMPAT_DATA_PATH/notproton-msync" 2>/dev/null || true+ stage_step="prefix build check"+ refuse_other_buildstage_step="prefix arch check"refuse_foreign_prefix+ claim_prefixecho "sync: WINEMSYNC=$WINEMSYNC from $msync_from" >> "$log" 2>&1 || true"$WINESERVER" -k >> "$log" 2>&1 || truestage_step="profile layout"@@ -304,15 +395,15 @@ if [ -n "$STEAM_COMPAT_DATA_PATH" ]; then"$WINELOADER" reg add 'HKLM\Software\Classes\steam\shell\open\command' /ve /t REG_SZ /d '"C:\Program Files (x86)\Steam\steam.exe" "%1"' /f >> "$log" 2>&1 || truefi-bridge_src="$HOME/Library/Application Support/notproton/bridge"+bridge_src="$np_support/bridge"prefix_steam="$WINEPREFIX/drive_c/Program Files (x86)/Steam"verify_runner() {- if [ ! -d "$bridge_src/wine" ]; then- echo "=== no patched ntdll in the bridge, run NotProton ===" >> "$log" 2>&1 || true+ if [ ! -d "$bridge_src/wine/$np_build" ]; then+ echo "=== no patched ntdll for build $np_build in the bridge, set it up in NotProton ===" >> "$log" 2>&1 || truereturnfifor arch in x86_64-windows i386-windows aarch64-windows; do- staged="$bridge_src/wine/$arch/ntdll.dll"+ staged="$bridge_src/wine/$np_build/$arch/ntdll.dll"live="$CX_ROOT/lib/wine/$arch/ntdll.dll"[ -f "$staged" ] || continueif [ ! -f "$live" ]; then@@ -414,6 +505,7 @@ fiexport WINEDEBUG="${WINEDEBUG:-err+all,fixme-all}"trap - EXITecho "launch_args=$launch_args" >> "$log" 2>&1 || true+[ -z "$launch_env" ] || echo "launch_env=$launch_env" >> "$log" 2>&1 || trueecho "=== launching ($verb): $WINELOADER $* ===" >> "$log" 2>&1 || truetarget="$1"diff --git a/dylib/tests/buildcheck.sh b/dylib/tests/buildcheck.shnew file mode 100644index 0000000..013232c--- /dev/null+++ b/dylib/tests/buildcheck.sh@@ -0,0 +1,88 @@+#!/bin/sh+# shellcheck disable=SC2034,SC2154+set -e+SRC="${1:-$(dirname "$0")/../feats/compat_run.sh}"+[ -f "$SRC" ] || { echo "buildcheck: $SRC not present, skipped"; exit 0; }++extract() { sed -n "/^$1() {\$/,/^}\$/p" "$SRC"; }+functions=""+for name in alert_safe last_wine_build refuse_other_build claim_prefix; do+ body=$(extract "$name")+ [ -n "$body" ] || { echo "FAIL: $name not found in $SRC"; exit 1; }+ functions="$functions+$body"+done++work=$(mktemp -d)+trap 'rm -rf "$work"' EXIT++np_support="$work/support"+clone() {+ inf="$np_support/runners/crossover-$1/CrossOver/share/wine/wine.inf"+ mkdir -p "$(dirname "$inf")"+ : > "$inf"+ touch -t "$2" "$inf"+}+clone 26.3.0.39832 202607151200+clone 27.0.0.40921-fex 202608211200+printf 'notproton\t27.0.0.40921-fex\tfex\tCrossOver Preview (FEX)\nnotproton-26.3\t26.3.0.39832\trosetta\tCrossOver 26.3\n' \+ > "$np_support/tools"+mtime() { stat -f %m "$np_support/runners/crossover-$1/CrossOver/share/wine/wine.inf"; }++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; }++launch() {+ build=$1 updated=$2 record=$3+ data=$(mktemp -d "$work/compatdata.XXXXXX")+ mkdir -p "$data/pfx"+ [ -z "$updated" ] || printf '%s\n' "$updated" > "$data/pfx/.update-timestamp"+ [ -z "$record" ] || printf '%s' "$record" > "$data/notproton-build"+ (+ STEAM_COMPAT_DATA_PATH=$data+ np_build=$build+ np_display="display of $build"+ CX_ROOT="$np_support/runners/crossover-$build/CrossOver"+ log=/dev/null+ # shellcheck disable=SC2329 # called by the extracted refusal+ show_alert() { printf 'alert: %s\n' "$2"; }+ eval "$functions"+ refuse_other_build+ claim_prefix+ ) > "$data/out" 2>&1 && status=0 || status=$?+ echo "status=$status"+ grep -o 'last run by [^,]*' "$data/out" || true+ [ ! -f "$data/notproton-build" ] || head -1 "$data/notproton-build"+}++echo "== prefixes from before the record =="+is "a fresh prefix is claimed" "status=0+26.3.0.39832" "$(launch 26.3.0.39832 "" "")"+is "a prefix this build last updated is claimed" "status=0+26.3.0.39832" "$(launch 26.3.0.39832 "$(mtime 26.3.0.39832)" "")"+is "a prefix another clone updated is refused and named" "status=1+last run by CrossOver Preview (FEX)" "$(launch 26.3.0.39832 "$(mtime 27.0.0.40921-fex)" "")"+is "a prefix no clone updated is refused" "status=1+last run by another version of CrossOver" "$(launch 26.3.0.39832 1 "")"+is "updates the user disabled say nothing, so the prefix is claimed" "status=0+26.3.0.39832" "$(launch 26.3.0.39832 disable "")"++echo "== prefixes with a record =="+is "the record wins over the Wine that updated the prefix" "status=0+27.0.0.40921-fex" "$(launch 27.0.0.40921-fex "$(mtime 26.3.0.39832)" "27.0.0.40921-fex+CrossOver Preview (FEX)+")"+is "a record for another build is refused" "status=1+last run by CrossOver Preview (FEX)+27.0.0.40921-fex" "$(launch 26.3.0.39832 "" "27.0.0.40921-fex+CrossOver Preview (FEX)+")"++if [ "$fails" -eq 0 ]; then+ echo "==> buildcheck: all assertions hold"+else+ echo "==> buildcheck: $fails failed"+ exit 1+fidiff --git a/dylib/tests/compatcheck.c b/dylib/tests/compatcheck.cindex c44427e..0aafc0f 100644--- a/dylib/tests/compatcheck.c+++ b/dylib/tests/compatcheck.c@@ -149,7 +149,7 @@ static void enabled_cases(void) {// A manager holding `count` entries, the one at `named_slot` carrying the tool name.static uint8_t manager[0x400];-static uint8_t entries[8 * (COMPAT_TOOL_STRIDE + 64)];+static uint8_t entries[COMPAT_MANAGER_TOOLS_MAX * (COMPAT_TOOL_STRIDE + 64)];static void *build_manager(uint32_t count, int named_slot) {memset(manager, 0, sizeof manager);@@ -193,6 +193,101 @@ static void manager_cases(void) {g_tool_shift = 0;}+static void tool_list_cases(void) {+ static const char path[] = "out/compatcheck-tools";+ FILE *f = fopen(path, "w");+ if (!f) {+ check(0, "the tool list fixture can be written");+ return;+ }+ fputs("notproton\t27.0.0.40921-fex\tfex\tCrossOver Preview (FEX)\n"+ "notproton-fex-rosetta\t27.0.0.40921-fex\trosetta\tCrossOver Preview (Rosetta)\n"+ "notproton-26.3\t26.3.0.39832\trosetta\tCrossOver 26.3\n"+ "notproton\t26.3.0.39832\trosetta\tDuplicate\n"+ "proton-other\t1\trosetta\tForeign\n"+ "notproton-x\t1\tarm\tBad flavor\n"+ "notproton-q\t1\trosetta\tQuote\"d\n"+ "notproton-short\t1\trosetta\n"+ "\n", f);+ fclose(f);++ int kept = np_compat_load_tool_list(path, "/tools");+ unlink(path);++ check(kept == 3, "only well-formed, unique, notproton-named lines are kept");+ check(strcmp(g_tools[0].name, "notproton") == 0+ && strcmp(g_tools[0].flavor, "fex") == 0, "the first line stays first");+ check(strcmp(g_tools[2].build, "26.3.0.39832") == 0+ && strcmp(g_tools[2].dir, "/tools/notproton-26.3") == 0,+ "each tool carries its build and directory");++ uint8_t *mgr = build_manager(3, -1);+ *(const char **)(entries + np_compat_tool_stride() + COMPAT_TOOL_NAME_OFF) = "notproton-26.3";+ check(np_compat_registered_tool(mgr) == entries + np_compat_tool_stride(),+ "the most preferred tool the manager holds is the default");+ *(const char **)(entries + COMPAT_TOOL_NAME_OFF) = "notproton";+ check(np_compat_registered_tool(mgr) == entries,+ "the first listed tool wins when the manager holds it");++ check(np_compat_load_tool_list("out/compatcheck-missing", "/tools") == 0+ && !g_tool_list_present, "a missing list keeps no tools and says so");+}++static int put(const char *dir, const char *name, const char *text) {+ char path[768];+ snprintf(path, sizeof(path), "%s/%s", dir, name);+ FILE *f = fopen(path, "w");+ if (!f) return -1;+ fputs(text, f);+ return fclose(f);+}++static int exists(const char *path) {+ return access(path, F_OK) == 0;+}++static void stale_tool_cases(void) {+ char root[] = "out/compatcheck-toolsd.XXXXXX";+ if (!mkdtemp(root)) {+ check(0, "the tools directory fixture can be made");+ return;+ }+ char current[700], legacy[700], user[700], lookalike[700];+ snprintf(current, sizeof(current), "%s/notproton-26.3", root);+ snprintf(legacy, sizeof(legacy), "%s/notproton", root);+ snprintf(user, sizeof(user), "%s/notproton-mine", root);+ snprintf(lookalike, sizeof(lookalike), "%s/notproton-copy", root);+ const char *dirs[] = { current, legacy, user, lookalike };+ for (size_t i = 0; i < 4; i++) mkdir(dirs[i], 0755);++ put(current, "flavor", "rosetta\n");+ put(current, "run", "#!/bin/sh\n# notproton CrossOver compatibility tool shim\n");+ put(legacy, "run", "#!/bin/sh\n# notproton CrossOver compatibility tool shim\nset -e\n");+ put(legacy, "toolmanifest.vdf", "\"manifest\" {}\n");+ put(legacy, "compatibilitytool.vdf", "\"compatibilitytools\" {}\n");+ put(user, "run", "#!/bin/sh\nexec my-wine \"$@\"\n");+ put(lookalike, "run", "#!/bin/sh\n# notproton CrossOver compatibility tool shim\n");+ put(lookalike, "notes.txt", "mine\n");++ g_tool_count = 0;+ remove_unlisted_tools(root);++ check(!exists(current), "an unlisted tool with a flavor file is removed");+ check(!exists(legacy), "the single-tool dylib's directory is removed");+ check(exists(user), "a notproton directory the user wrote stays");+ char notes[768];+ snprintf(notes, sizeof(notes), "%s/notes.txt", lookalike);+ check(exists(notes), "files this project did not write stay with their directory");++ remove(notes);+ char path[768];+ snprintf(path, sizeof(path), "%s/run", user);+ remove(path);+ rmdir(user);+ rmdir(lookalike);+ rmdir(root);+}+static uint32_t stub_platforms_value;static uint32_t stub_platforms(void *mgr, uint32_t appid) {(void)mgr; (void)appid;@@ -272,6 +367,8 @@ int main(void) {oslist_cases();enabled_cases();manager_cases();+ tool_list_cases();+ stale_tool_cases();installed_fn_cases();if (failures) {diff --git a/dylib/tests/envcheck.sh b/dylib/tests/envcheck.shindex e75b40c..403717d 100755--- a/dylib/tests/envcheck.sh+++ b/dylib/tests/envcheck.sh@@ -36,6 +36,23 @@ WINEDLLOVERRIDES="lsteamclient=n"eval "$overrides_line"is "trio outranks user" "lsteamclient=n;steamclient=n;steamclient64=n;lsteamclient=b" "$WINEDLLOVERRIDES"+echo "== options saved without %command% =="+promote=$(sed -n '/^launch_env=""$/,/^launch_args="\$\*"$/p' "$SRC")+[ -n "$promote" ] || { echo "FAIL: the trailing option loop not found"; exit 1; }+trailing() {+ (+ set -- "$@"+ eval "$promote"+ printf '%s|%s|%s|%s' "${CX_GRAPHICS_BACKEND:-}" "${WINEMSYNC:-}" "$#" "$launch_args"+ )+}+is "known assignments leave the game's arguments" "dxmt|1|2|/g/game.exe -novid" \+ "$(trailing /g/game.exe CX_GRAPHICS_BACKEND=dxmt -novid WINEMSYNC=1)"+is "other assignments stay the game's" "||3|/g/game.exe +map=e1m1 P=1" \+ "$(trailing /g/game.exe +map=e1m1 P=1)"+is "a path with spaces stays one argument" "||1|/g/My Game/game.exe" \+ "$(trailing "/g/My Game/game.exe")"+if [ "$fails" -eq 0 ]; thenecho "==> envcheck: all assertions hold"else