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 native Mac library filtering and add a Windows-only filter
Nils Schröder0c8ff84a9ee1
diff --git a/Makefile b/Makefileindex 327889f..4b9259b 100644--- a/Makefile+++ b/Makefile@@ -46,6 +46,7 @@ SRCS := \dylib/feats/compatsvc.c \dylib/feats/usershortcuts.c \dylib/feats/webpatch.c \+ dylib/feats/nativeplatform.c \dylib/feats/input_access.c \vendor/cJSON.c@@ -263,6 +264,12 @@ $(GATECHECK): dylib/tests/gatecheck.c dylib/feats/webpatch.c dylib/feats/webpatc@mkdir -p $(dir $@)$(TEST_CC) -O1 -o $@ dylib/tests/gatecheck.c+NATIVEPLATFORMCHECK := $(OUT_DIR)/nativeplatformcheck++$(NATIVEPLATFORMCHECK): dylib/tests/nativeplatformcheck.c dylib/feats/nativeplatform.c dylib/feats/nativeplatform.h dylib/util/file.c+ @mkdir -p $(dir $@)+ $(TEST_CC) -O1 -o $@ dylib/tests/nativeplatformcheck.c dylib/feats/nativeplatform.c dylib/util/file.c+webpatch-fixtures:@if [ ! -d $(WEBPATCH_FIXTURES) ] || [ ! -f dylib/tests/gatecheck.c ]; then \$(call SKIP,webpatch-fixtures,$(WEBPATCH_FIXTURES)); exit 0; fi; \@@ -282,7 +289,18 @@ webpatch-fixtures:if [ $$rc -ne 0 ]; then fail=1; fi; \done; \done; \+ for f in $(WEBPATCH_FIXTURES)/library.*.js; do \+ out=$$($(GATECHECK) --library "$$f" $$tmp/$$(basename $$f .js).out.js 2>&1) || { echo "$$out"; fail=1; }; \+ out=$$($(GATECHECK) --library-literal "$$f" $$tmp/$$(basename $$f .js).literal.out.js 2>&1) || { echo "$$out"; fail=1; }; \+ done; \+ out=$$($(GATECHECK) --older-filter $$tmp/library.older.out.js 2>&1) || { echo "$$out"; fail=1; }; \+ if [ $$fail -eq 0 ]; then \+ if command -v node >/dev/null 2>&1; then \+ node dylib/tests/library-filter/behavior.js $$tmp/library.*.out.js || fail=1; \+ else echo "==> library filter: node not found, skipped"; fi; \+ fi; \rm -rf $$tmp; \+ $(MAKE) -s $(NATIVEPLATFORMCHECK) && $(NATIVEPLATFORMCHECK) || fail=1; \if [ $$fail -ne 0 ]; then exit 1; fi; \echo "==> gate table and $$n webpatch fixtures: anchors intact, drift refused"diff --git a/app/Tests/NotProtonAppTests/AppInfoToolTests.swift b/app/Tests/NotProtonAppTests/AppInfoToolTests.swiftindex 34d09f2..ccb65c5 100644--- a/app/Tests/NotProtonAppTests/AppInfoToolTests.swift+++ b/app/Tests/NotProtonAppTests/AppInfoToolTests.swift@@ -96,6 +96,65 @@ struct AppInfoToolTests {return Data(file.bytes)}+ private static func platformEntry(+ _ appID: UInt32, _ oslist: String?, common: Bool = true, table: [String]? = nil+ ) -> [UInt8] {+ var kv = Cache()+ func key(_ name: String) {+ if let table { kv.u32(UInt32(table.firstIndex(of: name)!)) }+ else { kv.cstring(name) }+ }+ kv.bytes.append(0x00)+ key("appinfo")+ if common {+ kv.bytes.append(0x00)+ key("common")+ kv.bytes.append(0x01)+ key("name")+ kv.cstring("App \(appID)")+ if let oslist {+ kv.bytes.append(0x01)+ key("oslist")+ kv.cstring(oslist)+ }+ kv.bytes.append(0x08)+ }+ kv.bytes.append(contentsOf: [0x08, 0x08])+ return entry(appID: appID, keyData: kv.bytes)+ }++ private static func platforms(+ ended: Bool = true, firstSize: UInt32? = nil, stringTable: Bool = false+ ) -> Data {+ let table = stringTable ? ["appinfo", "common", "name", "oslist"] : nil+ var entries = Cache()+ var first = platformEntry(10, "windows,macos", table: table)+ if let firstSize {+ var size = Cache()+ size.u32(firstSize)+ first.replaceSubrange(4..<8, with: size.bytes)+ }+ entries.bytes.append(contentsOf: first)+ entries.bytes.append(contentsOf: platformEntry(20, "windows", table: table))+ entries.bytes.append(contentsOf: platformEntry(30, nil, table: table))+ entries.bytes.append(contentsOf: platformEntry(40, "linux", table: table))+ entries.bytes.append(contentsOf: platformEntry(50, "macos", table: table))+ entries.bytes.append(contentsOf: platformEntry(60, nil, common: false, table: table))+ if ended { entries.u32(0) }+ var file = Cache()+ file.u32(stringTable ? 0x0756_4429 : 0x0756_4428)+ file.u32(1)+ if let table {+ file.u64(UInt64(16 + entries.bytes.count))+ file.bytes.append(contentsOf: entries.bytes)+ file.u32(UInt32(table.count))+ for key in table { file.cstring(key) }+ } else {+ file.bytes.append(contentsOf: entries.bytes)+ }+ return Data(file.bytes)+ }+private func read(_ cache: Data, _ appID: String) throws -> CommandResult {let tool = try InstallPayload.locate().appinfolet path = URL.temporaryDirectory.appending(path: "np-appinfo-\(UUID().uuidString).vdf")@@ -149,6 +208,43 @@ struct AppInfoToolTests {#expect(result.stdout.isEmpty, "a caller reading key=value lines must get none")}+ @Test("--platforms lists Mac games, and Windows games including those with no oslist or a Mac build too",+ arguments: [false, true])+ func listsPlatforms(stringTable: Bool) throws {+ let result = try read(Self.platforms(stringTable: stringTable), "--platforms")++ #expect(result.status == 0)+ #expect(result.stdout == "mac=10,50\nwindows=10,20,30\n")+ }++ @Test("--platforms on a cache that stops early prints nothing and fails", arguments: [false, true])+ func refusesTruncatedPlatforms(stringTable: Bool) throws {+ let result = try read(Self.platforms(ended: false, stringTable: stringTable), "--platforms")++ #expect(result.status != 0)+ #expect(result.stdout.isEmpty, "a half list would hide the rest of the library")+ }++ @Test("--platforms rejects invalid entry sizes", arguments: [UInt32(1), 59, UInt32.max], [false, true])+ func refusesInvalidPlatformEntrySize(_ size: UInt32, stringTable: Bool) throws {+ let result = try read(Self.platforms(firstSize: size, stringTable: stringTable), "--platforms")++ #expect(result.status != 0)+ #expect(result.stdout.isEmpty)+ }++ @Test("An app cannot borrow its section terminator from outside its entry")+ func refusesKeysOutsideEntry() throws {+ var cache = Self.v28(appID: 2100)+ var size = Cache()+ size.u32(UInt32(cache.count - 8 - 8 - 4 - 1))+ cache.replaceSubrange(12..<16, with: size.bytes)+ let result = try read(cache, "2100")++ #expect(result.status != 0)+ #expect(result.stdout.isEmpty)+ }+@Test("A cache that is not a cache fails instead of printing garbage")func refusesUnparsableFile() throws {let result = try read(Data(repeating: 0xab, count: 4096), "2100")diff --git a/app/Tests/NotProtonAppTests/PrefixesModelTests.swift b/app/Tests/NotProtonAppTests/PrefixesModelTests.swiftindex 86185a5..eb8d89b 100644--- a/app/Tests/NotProtonAppTests/PrefixesModelTests.swift+++ b/app/Tests/NotProtonAppTests/PrefixesModelTests.swift@@ -679,19 +679,18 @@ struct PrefixesModelTests {#expect(model.busy.isEmpty)}- // What a live wineserver looks like: a socket directory named after the prefix's- // device and inode, with something holding a file open inside it for lsof to find.+ // The prefix lock keeps this test out of Wine's real socket directory.private func hold(_ prefix: WinePrefix) throws -> () -> Void {- let dir = try #require(PrefixStore.serverDirectory(of: prefix))- try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)- let socket = dir.appending(path: "socket")- try Data().write(to: socket)-- let handle = try FileHandle(forReadingFrom: socket)- return {- try? handle.close()- try? FileManager.default.removeItem(at: dir)+ let lock = prefix.root.appending(path: ".notproton-prefix.lock")+ let fd = open(lock.path, O_RDWR | O_CREAT | O_NOFOLLOW | O_CLOEXEC, 0o600)+ try #require(fd >= 0)+ do {+ try #require(flock(fd, LOCK_EX | LOCK_NB) == 0)+ } catch {+ close(fd)+ throw error}+ return { FileLock.release(fd) }}@Test("Deleting nothing is not an operation")diff --git a/dylib/feats/nativeplatform.c b/dylib/feats/nativeplatform.cnew file mode 100644index 0000000..70cc76d--- /dev/null+++ b/dylib/feats/nativeplatform.c@@ -0,0 +1,155 @@+// Mac and Windows app lists for the Steam macOS library filter+#include "nativeplatform.h"+#include "../util/file.h"+#include "../util/log.h"++#include <crt_externs.h>+#include <errno.h>+#include <fcntl.h>+#include <limits.h>+#include <poll.h>+#include <signal.h>+#include <spawn.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <sys/wait.h>+#include <time.h>+#include <unistd.h>++#define OUTPUT_MAX (4u << 20)++// sp.js is held up until this returns.+#define HELPER_TIMEOUT_MS 10000++static long long now_ms(void) {+ struct timespec ts;+ clock_gettime(CLOCK_MONOTONIC, &ts);+ return (long long)ts.tv_sec * 1000 + ts.tv_nsec / 1000000;+}++static char *read_output(int fd, pid_t pid) {+ char *buf = malloc(OUTPUT_MAX + 1);+ size_t len = 0;+ long long deadline = now_ms() + HELPER_TIMEOUT_MS;+ while (buf) {+ long long left = deadline - now_ms();+ struct pollfd p = { fd, POLLIN, 0 };+ int ready = left > 0 ? poll(&p, 1, (int)left) : 0;+ if (ready < 0 && errno == EINTR) continue;+ if (ready <= 0) {+ NP_WARN("nativeplatform: appinfo helper timed out");+ kill(pid, SIGKILL);+ free(buf);+ return NULL;+ }+ ssize_t n = read(fd, buf + len, OUTPUT_MAX - len);+ if (n < 0 && errno == EINTR) continue;+ if (n == 0) break;+ if (n < 0 || (len += (size_t)n) == OUTPUT_MAX) {+ kill(pid, SIGKILL);+ free(buf);+ return NULL;+ }+ }+ if (buf) buf[len] = '\0';+ return buf;+}++static char *run_helper(void) {+ const char *home = np_home_dir();+ if (!home) return NULL;+ char tool[PATH_MAX], vdf[PATH_MAX];+ np_support_path(tool, sizeof(tool), home, "appinfo");+ snprintf(vdf, sizeof(vdf), "%s/Library/Application Support/Steam/appcache/appinfo.vdf", home);++ int fds[2];+ if (pipe(fds) != 0) return NULL;+ fcntl(fds[0], F_SETFD, FD_CLOEXEC);+ fcntl(fds[1], F_SETFD, FD_CLOEXEC);++ posix_spawn_file_actions_t actions;+ posix_spawnattr_t attr;+ sigset_t none, all;+ sigemptyset(&none);+ sigfillset(&all);+ if (posix_spawn_file_actions_init(&actions) != 0) {+ close(fds[0]);+ close(fds[1]);+ return NULL;+ }+ if (posix_spawnattr_init(&attr) != 0) {+ posix_spawn_file_actions_destroy(&actions);+ close(fds[0]);+ close(fds[1]);+ return NULL;+ }+ posix_spawn_file_actions_addopen(&actions, STDIN_FILENO, "/dev/null", O_RDONLY, 0);+ posix_spawn_file_actions_adddup2(&actions, fds[1], STDOUT_FILENO);+ posix_spawn_file_actions_addopen(&actions, STDERR_FILENO, "/dev/null", O_WRONLY, 0);+ posix_spawnattr_setsigmask(&attr, &none);+ posix_spawnattr_setsigdefault(&attr, &all);+ posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_CLOEXEC_DEFAULT);+ char *argv[] = { tool, vdf, "--platforms", NULL };+ pid_t pid;+ int rc = posix_spawn(&pid, tool, &actions, &attr, argv, *_NSGetEnviron());+ posix_spawnattr_destroy(&attr);+ posix_spawn_file_actions_destroy(&actions);+ close(fds[1]);+ if (rc != 0) {+ close(fds[0]);+ NP_WARN("nativeplatform: cannot run %s (%d)", tool, rc);+ return NULL;+ }++ char *out = read_output(fds[0], pid);+ close(fds[0]);+ int status = 0;+ pid_t done;+ while ((done = waitpid(pid, &status, 0)) < 0 && errno == EINTR) {}+ if (done != pid || !WIFEXITED(status) || WEXITSTATUS(status) != 0) {+ if (out) NP_WARN("nativeplatform: appinfo helper failed (status %d)", status);+ free(out);+ return NULL;+ }+ return out;+}++static const char *take_list(const char **at, const char *key, size_t *len) {+ size_t key_len = strlen(key);+ if (strncmp(*at, key, key_len) != 0) return NULL;+ const char *list = *at + key_len;+ const char *p = list;+ while (*p >= '0' && *p <= '9') {+ while (*p >= '0' && *p <= '9') p++;+ if (*p != ',') break;+ if (p[1] < '0' || p[1] > '9') return NULL;+ p++;+ }+ if (*p != '\n') return NULL;+ *len = (size_t)(p - list);+ *at = p + 1;+ return list;+}++char *np_nativeplatform_javascript(void) {+ char *out = run_helper();+ if (!out) return NULL;+ const char *at = out;+ size_t mac_len = 0, windows_len = 0;+ const char *mac = take_list(&at, "mac=", &mac_len);+ const char *windows = mac ? take_list(&at, "windows=", &windows_len) : NULL;+ if (!windows || *at) {+ NP_WARN("nativeplatform: appinfo helper printed something unexpected");+ free(out);+ return NULL;+ }+ size_t cap = mac_len + windows_len + 128;+ char *js = malloc(cap);+ if (js)+ snprintf(js, cap,+ "window.__NOTPROTON_NATIVE_PLATFORM__={mac:new Set([%.*s]),windows:new Set([%.*s])};\n",+ (int)mac_len, mac, (int)windows_len, windows);+ free(out);+ return js;+}diff --git a/dylib/feats/nativeplatform.h b/dylib/feats/nativeplatform.hnew file mode 100644index 0000000..60be6d8--- /dev/null+++ b/dylib/feats/nativeplatform.h@@ -0,0 +1,7 @@+// Mac and Windows app lists for the Steam macOS library filter+#ifndef NOTPROTON_FEATS_NATIVEPLATFORM_H+#define NOTPROTON_FEATS_NATIVEPLATFORM_H++char *np_nativeplatform_javascript(void);++#endif // NOTPROTON_FEATS_NATIVEPLATFORM_Hdiff --git a/dylib/feats/webpatch.c b/dylib/feats/webpatch.cindex 18825ce..8f09a54 100644--- a/dylib/feats/webpatch.c+++ b/dylib/feats/webpatch.c@@ -1,5 +1,6 @@// Enables Steam Play in the UI/enables the Compatibility tab in game properties#include "webpatch.h"+#include "nativeplatform.h"#include "../util/log.h"#include <stdlib.h>@@ -91,6 +92,8 @@ static const char *marker_text(char c) {static size_t match_at(const char *src, size_t len, size_t pos,const char *find, np_cap_t *caps) {+ if (cap_index((unsigned char)find[0]) < 0 && !marker_text(find[0]) && src[pos] != find[0])+ return 0;for (int i = 0; i < NP_CAP_MAX; i++) { caps[i].at = NULL; caps[i].len = 0; }if (cap_index((unsigned char)find[0]) >= 0 && pos &&@@ -129,10 +132,27 @@ static size_t match_at(const char *src, size_t len, size_t pos,return s - pos;}+static void mark_start(unsigned char *can_start, const char *find) {+ if (marker_text(find[0])) {+ memset(can_start, 1, 256);+ } else if (cap_index((unsigned char)find[0]) >= 0) {+ for (int c = 0; c < 256; c++)+ if (is_ident_char((unsigned char)c) && !(c >= '0' && c <= '9')) can_start[c] = 1;+ } else {+ can_start[(unsigned char)find[0]] = 1;+ }+}+static size_t count_matches(const char *src, size_t len, const char *find) {np_cap_t caps[NP_CAP_MAX];- size_t n = 0;+ size_t n = 0, lit = 0;+ while (find[lit] && cap_index((unsigned char)find[lit]) < 0 && !marker_text(find[lit])) lit++;for (size_t i = 0; i < len; ) {+ if (lit) {+ const char *at = memmem(src + i, len - i, find, lit);+ if (!at) break;+ i = (size_t)(at - src);+ }size_t used = match_at(src, len, i, find, caps);if (used) { n++; i += used; } else i++;}@@ -255,6 +275,16 @@ static int out_expand(np_out_t *o, const char *replace, const np_cap_t *caps) {#define NP_IMAGE_FILES_LABEL NP_WEB_TEXT( \"Image Files (*.tga,*.png,*.exe)", "图像文件 (*.tga,*.png,*.exe)", "File immagine (*.tga,*.png,*.exe)")+#define NP_LIBRARY_WINDOWS_HINT NP_WEB_TEXT( \+ "Show only games that run on Windows and do not have a macOS version", \+ "Show only games that run on Windows and do not have a macOS version", \+ "Show only games that run on Windows and do not have a macOS version")++#define NP_LIBRARY_WINDOWS_SUMMARY NP_WEB_TEXT( \+ "Runs on Windows, no Mac OS version", \+ "Runs on Windows, no Mac OS version", \+ "Runs on Windows, no Mac OS version")+#define NP_CX_OPTIONS_CSS \"\".MSCXPanel{margin-top:10px}" \".MSCXPanel .MSCXRow{display:flex;flex-direction:row;padding:9px;margin:0;" \@@ -446,6 +476,18 @@ static const np_gate_t g_gates_selecttool[] = {NP_COMPAT_HINT, 1, 0 },};+#define NP_PLATFORM_LISTS "window.__NOTPROTON_NATIVE_PLATFORM__"+#define NP_MAC_64(APP) \+ "(" NP_PLATFORM_LISTS ".mac.has(" APP ".appid)&&!" APP ".most_available_per_client_data?.is_invalid_os_type)"+#define NP_MAC_CHECK(OS, APP) \+ "(0," OS ".Pr)()&&" NP_PLATFORM_LISTS ".mac.has(" APP ".appid)?!" APP \+ ".most_available_per_client_data?.is_invalid_os_type:(0," OS ".Pr)()&&" \+ NP_PLATFORM_LISTS ".windows.has(" APP ".appid)?!1:(0," OS ".Pr)()?" \+ APP ".is_available_on_current_platform&&!" APP ".most_available_per_client_data?.is_invalid_os_type:"+#define NP_WINDOWS_ONLY_CASE(OS, APP) \+ "case\"notprotonWindows\":return(0," OS ".Pr)()&&" NP_PLATFORM_LISTS ".windows.has(" APP ".appid)&&!" \+ NP_MAC_64(APP) ";"+static const np_gate_t g_fixes[] = {{ "(\"#AddNonSteam_Filter_Exe_MacOS\"),rFilePatterns:[\"*.app\"]","(\"#AddNonSteam_Filter_Exe_MacOS\"),rFilePatterns:[\"*.app\",\"*.exe\"]", 1, 0 },@@ -473,9 +515,78 @@ static const np_gate_t g_fixes[] = {1, 0 },{ "this.m_bServicesInitialized=!0,SteamClient.UI.NotifyAppInitialized()","this.m_bServicesInitialized=!0," NP_LAUNCH_MIGRATION ",SteamClient.UI.NotifyAppInitialized()", 1, 0 },+ // Pr means macOS, td means Windows.+ // Steam Play makes every game count as available, so the Apple filter goes by oslist.+ // Games missing from appinfo.vdf, and other platforms, keep Steam's check.+ // NotProton forces is_invalid_os_type to false, so 32-bit Mac games are found through the per-client copy.+ { "case " NP_C1 "." NP_C2 ":return!!(0," NP_C3 ".td)()||" NP_C4+ ".is_available_on_current_platform&&!" NP_C4 ".is_invalid_os_type;",+ NP_WINDOWS_ONLY_CASE(NP_C3, NP_C4) "case " NP_C1 "." NP_C2 ":return " NP_MAC_CHECK(NP_C3, NP_C4)+ "!!(0," NP_C3 ".td)()||" NP_C4 ".is_available_on_current_platform&&!" NP_C4 ".is_invalid_os_type;", 1, 0 },+ { "case " NP_C1 "." NP_C2 ":return(0," NP_C3 ".CI)()&&!(0," NP_C3 ".mP)()?"+ NP_C4 "(" NP_C5 "):(0," NP_C3 ".td)()?!0:" NP_C5+ ".is_available_on_current_platform&&!" NP_C5 ".is_invalid_os_type;",+ NP_WINDOWS_ONLY_CASE(NP_C3, NP_C5) "case " NP_C1 "." NP_C2 ":return " NP_MAC_CHECK(NP_C3, NP_C5)+ "(0," NP_C3 ".CI)()&&!(0," NP_C3 ".mP)()?" NP_C4 "(" NP_C5 "):(0,"+ NP_C3 ".td)()?!0:" NP_C5 ".is_available_on_current_platform&&!" NP_C5 ".is_invalid_os_type;", 1, 0 },};#define NP_FIX_COUNT (sizeof(g_fixes) / sizeof(g_fixes[0]))+#define NP_NATIVE_MAC_FILTER_FIX (NP_FIX_COUNT - 2)+#define NP_UPDATED_NATIVE_MAC_FILTER_FIX (NP_FIX_COUNT - 1)++static const np_gate_t g_library_filters[] = {+ // Library list and search+ { "if(!" NP_C1 "(" NP_C2 "[" NP_C3 ".W6]," NP_C4 "(" NP_C5 "))||!" NP_C1 "(" NP_C2 "[" NP_C3 ".sc],",+ "if(!(this.m_filterSpec.notprotonWindows?((npGroup,npCheck)=>{"+ "const npApple=npGroup.rgOptions.includes(" NP_C3 ".Pu);return " NP_C1 "({...npGroup,"+ "rgOptions:[...npGroup.rgOptions.filter(npOption=>npOption!==" NP_C3 ".Pu),\"notprotonWindows\"]},"+ "npOption=>npOption===\"notprotonWindows\"?npCheck(npOption)||npApple&&npCheck(" NP_C3 ".Pu):npCheck(npOption))"+ "})(" NP_C2 "[" NP_C3 ".W6]," NP_C4 "(" NP_C5 ")):" NP_C1 "(" NP_C2 "[" NP_C3 ".W6]," NP_C4 "(" NP_C5 ")))||!"+ NP_C1 "(" NP_C2 "[" NP_C3 ".sc],", 2, 0 },+ // Saved library filter+ { ",strSearchText:" NP_C1 "&&" NP_C1 ".strSearchText||\"\",filterGroups:",+ ",strSearchText:" NP_C1 "&&" NP_C1 ".strSearchText||\"\","+ "notprotonWindows:!!" NP_C1 "?.notprotonWindows,filterGroups:", 1, 0 },+ { "SelectOption(" NP_C1 "," NP_C2 "," NP_C3 "){let " NP_C4 "=this.m_filterSpec.filterGroups[" NP_C1 "].rgOptions;",+ "SelectOption(" NP_C1 "," NP_C2 "," NP_C3 "){if(" NP_C1 "===\"notprotonWindows\"){"+ "this.m_filterSpec.notprotonWindows=!!" NP_C3 ";return}let " NP_C4 "=this.m_filterSpec.filterGroups[" NP_C1 "].rgOptions;", 1, 0 },+ { "Reset(){this.m_filterSpec.strSearchText=\"\",",+ "Reset(){this.m_filterSpec.notprotonWindows=!1,this.m_filterSpec.strSearchText=\"\",", 1, 0 },+ { "get bIsEmpty(){return this.searchText.length==0&&",+ "get bIsEmpty(){return!this.m_filterSpec.notprotonWindows&&this.searchText.length==0&&", 1, 0 },+ { "let " NP_C1 "=this.GetSelectedOptions(" NP_C2 ".W6);" NP_C1 ".length>0&&" NP_C3 ".push(" NP_C1 ".map("+ NP_C4 "=>{if(" NP_C4 "==" NP_C2 ".Pu){",+ "let " NP_C1 "=this.GetSelectedOptions(" NP_C2 ".W6);this.m_filterSpec.notprotonWindows&&(" NP_C1 "=[..."+ NP_C1 ",\"notprotonWindows\"]);" NP_C1 ".length>0&&" NP_C3 ".push(" NP_C1 ".map(" NP_C4 "=>{if(" NP_C4+ "===\"notprotonWindows\")return " NP_LIBRARY_WINDOWS_SUMMARY ";if(" NP_C4 "==" NP_C2 ".Pu){", 1, 0 },+ // Library toolbar+ { "," NP_C1 "=" NP_C2 ".n6.currentAppFilter.BIsSelected(" NP_C3 ".W6," NP_C3 ".Pu);return(0,"+ NP_C4 ".jsxs)(\"div\",{className:" NP_C5 "().Bar,",+ "," NP_C1 "=" NP_C2 ".n6.currentAppFilter.BIsSelected(" NP_C3 ".W6," NP_C3 ".Pu),npStore=" NP_C2 ".n6,"+ "npWindows=!!" NP_C2 ".n6.currentAppFilter.m_filterSpec.notprotonWindows;return(0,"+ NP_C4 ".jsxs)(\"div\",{className:" NP_C5 "().Bar,", 1, 0 },+ { "children:[" NP_C1 "&&(0," NP_C2 ".jsxs)(" NP_C3 ".he,{direction:\"top\",nDelayShowMS:240,toolTipContent:" NP_C4+ "?\"#GameList_View_Platform_Linux\":\"#GameList_View_Platform_Apple\",className:(0," NP_C5 ".A)("+ NP_C6 "().CheckboxWithImage," NP_C7 "&&" NP_C6 "().Disabled," NP_C8 "&&" NP_C6 "().Active),onClick:()=>"+ NP_C7 "||" NP_C9 "(" NP_C10 ".W6," NP_C10 ".Pu,!" NP_C8 "),children:[" NP_C4 "&&(0," NP_C2 ".jsx)("+ NP_C11 ".Wy0,{}),!" NP_C4 "&&(0," NP_C2 ".jsx)(" NP_C11 ".kPc,{})]})",+ "children:["+ NP_C1 "&&!" NP_C4 "&&" NP_C11 ".Xz0&&(0," NP_C2 ".jsxs)(" NP_C3 ".he,{direction:\"top\",nDelayShowMS:240,"+ "toolTipContent:" NP_LIBRARY_WINDOWS_HINT ",className:(0," NP_C5 ".A)(" NP_C6 "().CheckboxWithImage,"+ NP_C7 "&&" NP_C6 "().Disabled,npWindows&&" NP_C6 "().Active),onClick:()=>" NP_C7+ "||npStore.SelectCollectionsAppFilterOption(\"notprotonWindows\",null,!npWindows),"+ "children:[(0," NP_C2 ".jsx)(\"style\",{children:\".\"+" NP_C6 "().CheckboxWithImage+"+ "\" .SVGIcon_WindowsLogo{width:13px;height:13px}.\"+" NP_C6 "().CheckboxWithImage+"+ "\" .SVGIcon_WindowsLogo rect{fill:inherit}\"}),(0," NP_C2 ".jsx)(" NP_C11 ".Xz0,{})]}),"+ NP_C1 "&&(0," NP_C2 ".jsxs)(" NP_C3 ".he,{direction:\"top\",nDelayShowMS:240,toolTipContent:" NP_C4+ "?\"#GameList_View_Platform_Linux\":\"#GameList_View_Platform_Apple\",className:(0," NP_C5 ".A)("+ NP_C6 "().CheckboxWithImage," NP_C7 "&&" NP_C6 "().Disabled," NP_C8 "&&" NP_C6 "().Active),onClick:()=>"+ NP_C7 "||" NP_C9 "(" NP_C10 ".W6," NP_C10 ".Pu,!" NP_C8 "),children:[" NP_C4 "&&(0," NP_C2 ".jsx)("+ NP_C11 ".Wy0,{}),!" NP_C4 "&&(0," NP_C2 ".jsx)(" NP_C11 ".kPc,{})]})", 1, 0 },+};+#define NP_LIBRARY_FILTER_COUNT (sizeof(g_library_filters) / sizeof(g_library_filters[0]))+typedef struct {const char *name;const char *probe;@@ -541,17 +652,33 @@ char *np_webpatch_transform(const uint8_t *src, size_t src_len, size_t *out_len,}int fix_on[NP_FIX_COUNT];size_t fix_live = 0;+ char *native_mac_js = NULL;for (size_t f = 0; f < NP_FIX_COUNT; f++) {size_t n = count_matches(s, src_len, g_fixes[f].find);fix_on[f] = n == (size_t)g_fixes[f].expect;+ if ((f == NP_NATIVE_MAC_FILTER_FIX || f == NP_UPDATED_NATIVE_MAC_FILTER_FIX) && fix_on[f]) {+ free(native_mac_js);+ native_mac_js = np_nativeplatform_javascript();+ }if (fix_on[f]) { fix_live++; continue; }if (n)NP_WARN("webpatch: fix %zu expected %d occurrence(s), found %zu; ""leaving it alone", f, g_fixes[f].expect, n);}+ if (!native_mac_js && (fix_on[NP_NATIVE_MAC_FILTER_FIX] || fix_on[NP_UPDATED_NATIVE_MAC_FILTER_FIX])) {+ NP_WARN("webpatch: no platform list from appinfo.vdf, the Apple filter stays stock");+ fix_live -= fix_on[NP_NATIVE_MAC_FILTER_FIX] + fix_on[NP_UPDATED_NATIVE_MAC_FILTER_FIX];+ fix_on[NP_NATIVE_MAC_FILTER_FIX] = fix_on[NP_UPDATED_NATIVE_MAC_FILTER_FIX] = 0;+ }+ int library_filter = fix_on[NP_NATIVE_MAC_FILTER_FIX] || fix_on[NP_UPDATED_NATIVE_MAC_FILTER_FIX];+ for (size_t g = 0; library_filter && g < NP_LIBRARY_FILTER_COUNT; g++)+ library_filter = count_matches(s, src_len, g_library_filters[g].find) ==+ (size_t)g_library_filters[g].expect;- if (!shape && !fix_live)+ if (!shape && !fix_live) {+ free(native_mac_js);return NULL; // Not the part carrying the compat UI.+ }int gate_on[NP_GATE_MAX] = {0};size_t gate_live = 0;@@ -576,13 +703,33 @@ char *np_webpatch_transform(const uint8_t *src, size_t src_len, size_t *out_len,if (drifted) {NP_ERR("webpatch: [%s] compat UI left unpatched, a Steam update moved the ""anchors", shape->name);+ free(native_mac_js);return NULL;}}np_out_t out = {0};np_cap_t caps[NP_CAP_MAX];+ if (native_mac_js && !out_put(&out, native_mac_js, strlen(native_mac_js))) {+ free(native_mac_js);+ return NULL;+ }+ free(native_mac_js);+ unsigned char can_start[256] = {0};+ for (size_t g = 0; shape && g < shape->count; g++)+ if (gate_on[g]) mark_start(can_start, shape->gates[g].find);+ for (size_t f = 0; f < NP_FIX_COUNT; f++)+ if (fix_on[f]) mark_start(can_start, g_fixes[f].find);+ for (size_t g = 0; library_filter && g < NP_LIBRARY_FILTER_COUNT; g++)+ mark_start(can_start, g_library_filters[g].find);for (size_t i = 0; i < src_len; ) {+ size_t plain = i;+ while (plain < src_len && !can_start[(unsigned char)s[plain]]) plain++;+ if (plain > i) {+ if (!out_put(&out, s + i, plain - i)) { free(out.buf); return NULL; }+ i = plain;+ continue;+ }const np_gate_t *hit = NULL;size_t used = 0;for (size_t g = 0; shape && g < shape->count; g++) {@@ -595,6 +742,10 @@ char *np_webpatch_transform(const uint8_t *src, size_t src_len, size_t *out_len,used = match_at(s, src_len, i, g_fixes[f].find, caps);if (used) { hit = &g_fixes[f]; break; }}+ for (size_t g = 0; !hit && library_filter && g < NP_LIBRARY_FILTER_COUNT; g++) {+ used = match_at(s, src_len, i, g_library_filters[g].find, caps);+ if (used) { hit = &g_library_filters[g]; break; }+ }int ok = hit ? out_expand(&out, hit->replace, caps): out_put(&out, s + i, 1);if (!ok) { free(out.buf); return NULL; }@@ -604,6 +755,7 @@ char *np_webpatch_transform(const uint8_t *src, size_t src_len, size_t *out_len,if (!out_reserve(&out, 0)) { free(out.buf); return NULL; }out.buf[out.len] = '\0';*out_len = out.len;+ if (library_filter) NP_LOG("webpatch: Windows library filter button added");NP_LOG("webpatch: [%s] %zu gates, %zu fixes applied",shape ? shape->name : "no compat UI", gate_live, fix_live);return out.buf;diff --git a/dylib/tests/gatecheck.c b/dylib/tests/gatecheck.cindex 9c2741d..2dc53c1 100644--- a/dylib/tests/gatecheck.c+++ b/dylib/tests/gatecheck.c@@ -12,6 +12,12 @@int np_log_level = NP_LVL_INFO;FILE *np_log_file;+static const char *g_platform_js;++char *np_nativeplatform_javascript(void) {+ return g_platform_js ? strdup(g_platform_js) : NULL;+}+static int g_wrong;static void wrong(const char *fmt, ...) {@@ -204,8 +210,16 @@ static void selfcheck(void) {f, g_shapes[sh].name, g);}- printf("%zu shapes, %zu gates, %zu fixes checked\n",- NP_SHAPE_COUNT, total, NP_FIX_COUNT);+ for (size_t g = 0; g < NP_LIBRARY_FILTER_COUNT; g++) {+ check_gate("library", g, &g_library_filters[g], g_library_filters, NP_LIBRARY_FILTER_COUNT);+ for (size_t f = 0; f < NP_FIX_COUNT; f++)+ if (strstr(g_fixes[f].find, g_library_filters[g].find) ||+ strstr(g_library_filters[g].find, g_fixes[f].find))+ wrong("fix %zu and library anchor %zu share an anchor", f, g);+ }++ printf("%zu shapes, %zu gates, %zu fixes, %zu library anchors checked\n",+ NP_SHAPE_COUNT, total, NP_FIX_COUNT, NP_LIBRARY_FILTER_COUNT);check_paths();}@@ -316,6 +330,48 @@ static int extract(const char *chunk, const char *out_path) {return 0;}+static const np_gate_t *library_anchor(size_t i) {+ return i < NP_LIBRARY_FILTER_COUNT ? &g_library_filters[i]+ : &g_fixes[NP_NATIVE_MAC_FILTER_FIX + i - NP_LIBRARY_FILTER_COUNT];+}+#define NP_LIBRARY_ANCHORS (NP_LIBRARY_FILTER_COUNT + 2)++static int extract_library(const char *chunk, const char *out_path) {+ size_t len = 0;+ uint8_t *buf = slurp(chunk, &len);+ if (!buf) { fprintf(stderr, "cannot read %s\n", chunk); return 1; }+ FILE *o = fopen(out_path, "wb");+ if (!o) { fprintf(stderr, "cannot write %s\n", out_path); free(buf); return 1; }++ const size_t pad = 160;+ np_cap_t caps[NP_CAP_MAX];+ size_t fixes = 0;+ for (size_t a = 0; a < NP_LIBRARY_ANCHORS; a++) {+ size_t hits = 0;+ for (size_t i = 0; i < len; ) {+ size_t used = match_at((const char *)buf, len, i, library_anchor(a)->find, caps);+ if (!used) { i++; continue; }+ size_t from = i > pad ? i - pad : 0;+ size_t to = i + used + pad < len ? i + used + pad : len;+ fwrite(buf + from, 1, to - from, o);+ fputs("\n", o);+ hits++;+ i += used;+ }+ if (a >= NP_LIBRARY_FILTER_COUNT) { fixes += hits; continue; }+ if (hits != (size_t)library_anchor(a)->expect) {+ fprintf(stderr, "library anchor %zu found %zu times in %s\n", a, hits, chunk);+ fclose(o); free(buf);+ return 1;+ }+ }+ fclose(o);+ free(buf);+ if (fixes != 1) { fprintf(stderr, "%zu filter fixes in %s\n", fixes, chunk); return 1; }+ printf("extracted fixture to %s\n", out_path);+ return 0;+}+static void check_optional_drift(const np_ui_shape_t *S, size_t g, const uint8_t *buf,size_t len, const int *applied) {char *copy = malloc(len + 1);@@ -346,9 +402,124 @@ static void check_optional_drift(const np_ui_shape_t *S, size_t g, const uint8_tfree(copy);}+static const char g_test_lists[] =+ "window.__NOTPROTON_NATIVE_PLATFORM__={mac:new Set([1,4]),windows:new Set([2,4])};\n";++static char *library_transform(const char *src, size_t len, size_t *out_len) {+ int saved = np_log_level;+ np_log_level = -1;+ char *out = np_webpatch_transform((const uint8_t *)src, len, out_len, NULL);+ np_log_level = saved;+ return out;+}++static int write_file(const char *path, const char *buf, size_t len) {+ FILE *o = fopen(path, "wb");+ if (!o) return 0;+ int ok = fwrite(buf, 1, len, o) == len;+ return fclose(o) == 0 && ok;+}++static void check_library(const char *path, const char *out_path, int literal_version) {+ size_t len = 0;+ uint8_t *buf = slurp(path, &len);+ if (!buf) { wrong("cannot read %s", path); return; }++ if (literal_version) {+ const char *prefix = "this.m_filterSpec={nFormatVersion:";+ char *version = strstr((char *)buf, prefix);+ if (version) version += strlen(prefix);+ char *end = version ? strchr(version, ',') : NULL;+ if (!end || end == version) { wrong("no constructor version in %s", path); free(buf); return; }+ size_t tail = len - (size_t)(end - (char *)buf);+ memmove(version + 1, end, tail + 1);+ *version = '2';+ len = (size_t)(version - (char *)buf) + 1 + tail;+ }++ g_platform_js = g_test_lists;+ size_t out_len = 0;+ char *out = library_transform((const char *)buf, len, &out_len);+ if (!out) {+ wrong("%s was not patched", path);+ } else {+ if (strncmp(out, g_test_lists, sizeof(g_test_lists) - 1) != 0)+ wrong("%s does not start with the platform lists", path);+ if (!strstr(out, "SelectCollectionsAppFilterOption(\"notprotonWindows\""))+ wrong("%s has no Windows button", path);+ for (size_t a = 0; a < NP_LIBRARY_ANCHORS; a++) {+ if (count_matches(out, out_len, library_anchor(a)->find))+ wrong("library anchor %zu survived in %s", a, path);+ }+ for (size_t g = 0; g < NP_LIBRARY_FILTER_COUNT; g++) {+ if (count_matches(out, out_len, g_library_filters[g].replace) != (size_t)g_library_filters[g].expect)+ wrong("library replacement %zu is missing from %s", g, path);+ }+ size_t again_len = 0;+ char *again = library_transform(out, out_len, &again_len);+ if (again) { wrong("%s was patched a second time", path); free(again); }+ if (out_path && !write_file(out_path, out, out_len)) wrong("cannot write %s", out_path);+ free(out);+ }++ g_platform_js = NULL;+ out = library_transform((const char *)buf, len, &out_len);+ if (out && (strstr(out, "__NOTPROTON") || strstr(out, "notprotonWindows")))+ wrong("%s got the Apple filter without platform lists", path);+ free(out);++ g_platform_js = g_test_lists;+ np_cap_t caps[NP_CAP_MAX];+ for (size_t g = 0; g < NP_LIBRARY_FILTER_COUNT; g++) {+ char *copy = malloc(len + 1);+ if (!copy) { wrong("out of memory"); break; }+ memcpy(copy, buf, len + 1);+ for (size_t i = 0; i < len; ) {+ size_t used = match_at(copy, len, i, g_library_filters[g].find, caps);+ if (!used) { i++; continue; }+ copy[i + used - 1] = '\x01';+ i += used;+ }+ out = library_transform(copy, len, &out_len);+ if (!out || strstr(out, "npWindows") || strstr(out, "m_filterSpec.notprotonWindows") ||+ !strstr(out, ".mac.has("))+ wrong("drift in library anchor %zu of %s left a partial filter", g, path);+ free(out);+ free(copy);+ }+ g_platform_js = NULL;+ free(buf);+}++static void check_older_filter(const char *out_path) {+ static const char source[] =+ "function Y(e){return t=>{switch(t){case L.Pu:return!!(0,P.td)()||"+ "e.is_available_on_current_platform&&!e.is_invalid_os_type;}}}";+ g_platform_js = g_test_lists;+ size_t out_len = 0;+ char *out = library_transform(source, sizeof(source) - 1, &out_len);+ g_platform_js = NULL;+ if (!out || !strstr(out, "case L.Pu:return (0,P.Pr)()&&window.__NOTPROTON_NATIVE_PLATFORM__.mac.has(e.appid)"))+ wrong("the older filter was not patched");+ else if (out_path && !write_file(out_path, out, out_len))+ wrong("cannot write %s", out_path);+ free(out);+}+int main(int argc, char **argv) {if (argc == 4 && strcmp(argv[1], "--extract") == 0)return extract(argv[2], argv[3]);+ if (argc == 4 && strcmp(argv[1], "--extract-library") == 0)+ return extract_library(argv[2], argv[3]);+ if ((argc == 3 || argc == 4) &&+ (strcmp(argv[1], "--library") == 0 || strcmp(argv[1], "--library-literal") == 0)) {+ check_library(argv[2], argc == 4 ? argv[3] : NULL, strcmp(argv[1], "--library-literal") == 0);+ return g_wrong;+ }+ if ((argc == 2 || argc == 3) && strcmp(argv[1], "--older-filter") == 0) {+ check_older_filter(argc == 3 ? argv[2] : NULL);+ return g_wrong;+ }if (argc < 2) {selfcheck(); check_captures(); check_fallback(); check_fex_tools();diff --git a/dylib/tests/library-filter/behavior.js b/dylib/tests/library-filter/behavior.jsnew file mode 100644index 0000000..894b906--- /dev/null+++ b/dylib/tests/library-filter/behavior.js@@ -0,0 +1,163 @@+// Runs the patched library filter and Windows button from gatecheck's output.+'use strict';+const fs = require('fs');+const path = require('path');++const files = process.argv.slice(2);+if (!files.length) { console.error('usage: behavior.js <patched.js>...'); process.exit(2); }++let failed = 0;+const ok = (name, cond, what) => {+ if (!cond) failed++;+ if (!cond || process.env.VERBOSE) console.log(` ${cond ? 'PASS' : 'FAIL'} [${name}] ${what}`);+};++function grab(src, re, what) {+ const m = re.exec(src);+ if (!m) throw new Error(`no ${what}`);+ return m;+}++const english = () => { globalThis.document = { documentElement: { lang: 'en' } }; };++function filter(src) {+ const head = grab(src, /case"notprotonWindows":return\(0,([\w$]+)\.Pr\)\(\)&&window\.__NOTPROTON_NATIVE_PLATFORM__\.windows\.has\(([\w$]+)\.appid\)/,+ 'filter fix');+ const apple = grab(src.slice(head.index), /;case ([\w$]+)\.([\w$]+):return /, 'Apple case');+ const end = src.indexOf('.is_invalid_os_type;', head.index + apple.index + apple[0].length);+ const stmt = src.slice(head.index, end + '.is_invalid_os_type;'.length);+ const [, platform, app] = head;+ const [, group, option] = apple;+ const device = /\.mP\)\(\)\?([\w$]+)\(/.exec(stmt);+ const run = new Function('window', group, platform, app, device ? device[1] : '__device', '__k',+ `switch(__k){${stmt}}`);+ return (key, win, os, a) => run(win, { [option]: 'Apple' }, os, a, () => 'device', key);+}++function lists(src) {+ const win = {};+ new Function('window', src.slice(0, src.indexOf('\n') + 1))(win);+ return win;+}++function check(file, name, t) {+ const src = fs.readFileSync(file, 'latin1');+ const win = lists(src);+ const run = filter(src);+ const mac = { Pr: () => true, td: () => false, CI: () => false, mP: () => false };+ const windows = { Pr: () => false, td: () => true, CI: () => false, mP: () => false };+ const app = (appid, { old = false, available = true } = {}) =>+ ({ appid, is_available_on_current_platform: available, is_invalid_os_type: false,+ most_available_per_client_data: { is_invalid_os_type: old } });+ const apple = (a, os = mac) => run('Apple', win, os, a);+ const wonly = (a, os = mac) => run('notprotonWindows', win, os, a);++ t(apple(app(1)) && !wonly(app(1)), 'a Mac game is under Apple only');+ t(!apple(app(2)) && wonly(app(2)), 'a Windows game is under Windows only');+ t(apple(app(4)) && !wonly(app(4)), 'a game with both builds is under Apple only');+ t(!apple(app(4, { old: true })) && wonly(app(4, { old: true })),+ 'a game whose Mac build is 32-bit is under Windows only');+ t(!apple(app(1, { old: true })) && !wonly(app(1, { old: true })),+ 'a 32-bit Mac game with no Windows build is under neither');+ t(apple(app(3)) && !apple(app(3, { available: false })) && !wonly(app(3)),+ "a game missing from appinfo.vdf gets Steam's answer under Apple and is not under Windows");+ t(!apple(app(3, { old: true })) && !wonly(app(3, { old: true })),+ 'a missing 32-bit Mac game stays excluded even though the top-level invalid flag is false');+ const otherPlatform = { ...mac, Pr: () => false };+ t(!apple({ ...app(3), is_invalid_os_type: true }, otherPlatform) && apple(app(3), otherPlatform),+ 'the fallback on other platforms still uses the original invalid flag');+ t(apple(app(2), windows) && !wonly(app(2), windows), "on Windows the filter is Steam's");++ if (!src.includes('SelectCollectionsAppFilterOption("notprotonWindows"')) return;++ grab(src, /filterGroups:\[([\w$]+)\(!0,([\w$]+)&&\2\.filterGroups\[0\]\),\1\(!1,\2&&\2\.filterGroups\[1\]\)/,+ "Steam's default intersection for the state group");+ const checks = [...src.matchAll(/if\(!(.+?)\|\|!([\w$]+)\(([\w$]+)\[([\w$]+)\.sc\],/g)];+ t(checks.length === 2, 'both matching paths include the platform check');+ for (const [, expr, match, groups, enums] of checks) {+ const [, predicate, argument] = grab(expr, /,([\w$]+)\(([\w$]+)\)\)\)*$/, 'platform predicate');+ const evaluate = new Function(match, groups, enums, predicate, argument, `return ${expr}`);+ const matches = (g, p) => !g.rgOptions.length || (g.bAcceptUnion ? g.rgOptions.some(p) : g.rgOptions.every(p));+ const test = (options, windowsOn, a, union = false) => {+ const state = [{ rgOptions: [], bAcceptUnion: true }, { rgOptions: options, bAcceptUnion: union }];+ const before = JSON.stringify(state);+ const result = evaluate.call({ m_filterSpec: { notprotonWindows: windowsOn } }, matches, state,+ { W6: 1, Pu: 'Apple' }, a => key => key === 'installed' ? !!a.installed : run(key, win, mac, a), a);+ t(JSON.stringify(state) === before, 'matching leaves the saved filter unchanged');+ return result;+ };+ for (const id of [1, 2, 4]) {+ t(test([], false, app(id)), 'neither platform button filters games');+ t(test(['Apple'], false, app(id)) === (id !== 2), 'Apple alone keeps its platform check');+ t(test([], true, app(id)) === (id === 2), 'Windows alone keeps its platform check');+ t(test(['Apple'], true, app(id)), 'both buttons show both platforms with the default intersection');+ t(test(['Apple'], true, app(id), true), 'both buttons show both platforms with a union');+ t(!test(['Apple', 'installed'], true, app(id)) &&+ test(['Apple', 'installed'], true, { ...app(id), installed: true }),+ 'installed stays an intersection with the combined platforms');+ }+ t(!test(['Apple'], true, app(3, { available: false })), 'neither platform admits an unavailable unknown game');+ t(test(['installed'], true, { ...app(1), installed: true }, true), 'other union options still admit games');+ }++ const saved = grab(src, /notprotonWindows:(!!([\w$]+)\?\.notprotonWindows),/, 'saved flag');+ const restore = new Function(saved[2], `return ${saved[1]}`);+ t(restore(undefined) === false && restore({}) === false && restore({ notprotonWindows: true }) === true,+ 'a saved filter brings the Windows button back');++ const select = grab(src, /SelectOption\(([\w$]+),([\w$]+),([\w$]+)\)\{(if\(\1==="notprotonWindows"\)\{this\.m_filterSpec\.notprotonWindows=!!\3;return\})/,+ 'option setter');+ const set = new Function(select[1], select[2], select[3], `${select[4]}return"steam"`);+ const self = { m_filterSpec: { notprotonWindows: false } };+ const r1 = set.call(self, 'notprotonWindows', null, true);+ const was = self.m_filterSpec.notprotonWindows;+ set.call(self, 'notprotonWindows', null, false);+ t(r1 === undefined && was === true && self.m_filterSpec.notprotonWindows === false &&+ set.call(self, 0, 'Apple', true) === 'steam', 'the Windows option toggles the flag and nothing else');++ t(/Reset\(\)\{this\.m_filterSpec\.notprotonWindows=!1,/.test(src), 'Reset turns the Windows button off');+ t(/get bIsEmpty\(\)\{return!this\.m_filterSpec\.notprotonWindows&&/.test(src),+ 'a filter with only Windows on does not count as empty');++ english();+ const summary = grab(src, /if\(([\w$]+)==="notprotonWindows"\)return (.*?);if\(\1==/, 'summary');+ t(new Function(`return ${summary[2]}`)() === 'Runs on Windows, no Mac OS version',+ 'the filter summary names the Windows filter');++ const button = grab(src, /children:\[(([\w$]+)&&!([\w$]+)&&([\w$]+)\.Xz0&&\(0,([\w$]+)\.jsxs\)\(([\w$]+)\.he,\{.*?\(0,\5\.jsx\)\(\4\.Xz0,\{\}\)\]\}\)),\2&&\(0,\5\.jsxs\)\(\6\.he,\{direction:"top",nDelayShowMS:240,toolTipContent:\3\?"#GameList_View_Platform_Linux"/,+ 'Windows button before Apple');+ const [, expr, shown, linux, icons, rt, tip] = button;+ const cls = /className:\(0,([\w$]+)\.A\)\(([\w$]+)\(\)\.CheckboxWithImage,([\w$]+)&&/.exec(expr);+ const draw = new Function(shown, linux, icons, rt, tip, cls[1], cls[2], cls[3], 'npWindows', 'npStore',+ `return ${expr}`);+ const press = ({ visible = true, onLinux = false, icon = true, disabled = false, active = false } = {}) => {+ const calls = [];+ const node = draw(visible, onLinux, icon ? { Xz0: 'Windows' } : {}, { jsx: (type, p) => ({ type, p }), jsxs: (type, p) => ({ type, p }) },+ { he: 'Tooltip' }, { A: (...c) => c.filter(Boolean).join(' ') },+ () => ({ CheckboxWithImage: 'box', Disabled: 'off', Active: 'on' }), disabled, active,+ { SelectCollectionsAppFilterOption: (...a) => calls.push(a) });+ if (node) node.p.onClick();+ return { node, calls };+ };+ const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);+ const lit = press({ active: true });+ t(same(press().calls, [['notprotonWindows', null, true]]) && same(lit.calls, [['notprotonWindows', null, false]]),+ 'a click toggles the Windows button');+ t(lit.node.p.className === 'box on' && press().node.p.className === 'box' &&+ lit.node.p.children[1].type === 'Windows' && lit.node.p.nDelayShowMS === 240 &&+ lit.node.p.children[0].type === 'style' &&+ lit.node.p.children[0].p.children === '.box .SVGIcon_WindowsLogo{width:13px;height:13px}.box .SVGIcon_WindowsLogo rect{fill:inherit}' &&+ lit.node.p.toolTipContent === 'Show only games that run on Windows and do not have a macOS version',+ "the Windows button looks and times like Steam's Apple button");+ t(press({ disabled: true }).calls.length === 0, 'a disabled Windows button does nothing');+ t(!press({ onLinux: true }).node && !press({ icon: false }).node && !press({ visible: false }).node,+ 'no Windows button on Linux, without the icon, or when Steam hides the Apple one');+}++for (const file of files) {+ const name = path.basename(file, '.out.js');+ const t = (cond, what) => ok(name, cond, what);+ try { check(file, name, t); } catch (e) { t(false, e.message); }+}+console.log(failed ? `\n${failed} failure(s)` : `==> library filter: ${files.length} patched files behave`);+process.exit(failed ? 1 : 0);diff --git a/dylib/tests/nativeplatformcheck.c b/dylib/tests/nativeplatformcheck.cnew file mode 100644index 0000000..87ade6c--- /dev/null+++ b/dylib/tests/nativeplatformcheck.c@@ -0,0 +1,73 @@+#include "../feats/nativeplatform.h"+#include "../util/file.h"+#include "../util/log.h"++#include <limits.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <sys/stat.h>+#include <unistd.h>++int np_log_level = -1;+FILE *np_log_file;++static int g_wrong;+static char g_tool[PATH_MAX];++static void helper(const char *script) {+ unlink(g_tool);+ if (!script) return;+ FILE *f = fopen(g_tool, "w");+ if (!f) { printf("WRONG: cannot write %s\n", g_tool); g_wrong = 1; return; }+ fprintf(f, "#!/bin/sh\n%s\n", script);+ fclose(f);+ chmod(g_tool, 0755);+}++static void expect(const char *what, const char *script, const char *want) {+ helper(script);+ char *got = np_nativeplatform_javascript();+ if (want ? !got || strcmp(got, want) != 0 : got != NULL) {+ printf("WRONG: %s gave %s\n", what, got ? got : "nothing");+ g_wrong = 1;+ }+ free(got);+}++int main(void) {+ char home[] = "/tmp/np-nativeplatform-XXXXXX";+ if (!mkdtemp(home)) { perror("mkdtemp"); return 1; }+ setenv("HOME", home, 1);+ np_support_path(g_tool, sizeof(g_tool), home, "appinfo");+ char dir[PATH_MAX];+ snprintf(dir, sizeof(dir), "%s/Library", home);+ mkdir(dir, 0755);+ snprintf(dir, sizeof(dir), "%s/Library/Application Support", home);+ mkdir(dir, 0755);+ snprintf(dir, sizeof(dir), "%s", g_tool);+ *strrchr(dir, '/') = '\0';+ mkdir(dir, 0755);++ expect("two lists", "[ \"$2\" = --platforms ] || exit 2\nprintf 'mac=20,30\\nwindows=10\\n'",+ "window.__NOTPROTON_NATIVE_PLATFORM__={mac:new Set([20,30]),windows:new Set([10])};\n");+ expect("empty lists", "printf 'mac=\\nwindows=\\n'",+ "window.__NOTPROTON_NATIVE_PLATFORM__={mac:new Set([]),windows:new Set([])};\n");+ expect("no helper", NULL, NULL);+ expect("a helper that fails", "printf 'mac=1\\nwindows=2\\n'; exit 1", NULL);+ expect("script in a list", "printf 'mac=1,2]);alert(1);//\\nwindows=\\n'", NULL);+ expect("a trailing comma", "printf 'mac=1,\\nwindows=2\\n'", NULL);+ expect("a swapped order", "printf 'windows=2\\nmac=1\\n'", NULL);+ expect("an extra line", "printf 'mac=1\\nwindows=2\\nlinux=3\\n'", NULL);+ expect("no newline at the end", "printf 'mac=1\\nwindows=2'", NULL);++ helper(NULL);+ rmdir(dir);+ snprintf(dir, sizeof(dir), "%s/Library/Application Support", home);+ rmdir(dir);+ snprintf(dir, sizeof(dir), "%s/Library", home);+ rmdir(dir);+ rmdir(home);+ if (!g_wrong) printf("==> nativeplatform: helper output checked, bad output refused\n");+ return g_wrong;+}diff --git a/dylib/tests/panel-behavior/emit.c b/dylib/tests/panel-behavior/emit.cindex 854ce3d..aff84c7 100644--- a/dylib/tests/panel-behavior/emit.c+++ b/dylib/tests/panel-behavior/emit.c@@ -9,6 +9,10 @@int np_log_level = 0;FILE *np_log_file = NULL;+char *np_nativeplatform_javascript(void) {+ return NULL;+}+static void put_panel(const char *body) {for (const char *p = body; *p; p++) {const char *text = marker_text(*p);diff --git a/dylib/tests/webpatch-fixtures/library.1790121765.js b/dylib/tests/webpatch-fixtures/library.1790121765.jsnew file mode 100644index 0000000..a907d71--- /dev/null+++ b/dylib/tests/webpatch-fixtures/library.1790121765.js@@ -0,0 +1,10 @@+on(we){this.m_filterSpec.filterGroups[we].bAcceptUnion=!this.m_filterSpec.filterGroups[we].bAcceptUnion}MatchesImpl(we){const fe=this.m_filterSpec.filterGroups;if(!q(fe[C.W6],We(we))||!q(fe[C.sc],be(we))||!q(fe[C.Kr],tt(we))||!q(fe[C.bp],Ye(we))||!q(fe[C.Tx],et(we))||!q(fe[C.vA],Me(we))||!q(fe[C.RB],Ne(we)))return!1;if(this.m_filterSpec.strSearchText){if+des(Fe)||we.sort_as.includes(Fe)||h(le,Fe)!==-1)}return!0}Matches(we){return this.MatchesImpl(we)}MatchesScoredImpl(we){const fe=this.m_filterSpec.filterGroups;if(!q(fe[C.W6],We(we))||!q(fe[C.sc],be(we))||!q(fe[C.Kr],tt(we))||!q(fe[C.bp],Ye(we))||!q(fe[C.Tx],et(we))||!q(fe[C.vA],Me(we))||!q(fe[C.RB],Ne(we))||we.BIsAppBlocked())return 0;if(this.m_filterSp+t pt=2,st=class Vu{m_filterSpec=void 0;constructor(we){(0,s.Gn)(this),we&&(we.filterGroups[2].rgOptions=we.filterGroups[2].rgOptions?.filter(fe=>fe!=C.eb)||[]),this.m_filterSpec={nFormatVersion:pt,strSearchText:we&&we.strSearchText||"",filterGroups:[k(!0,we&&we.filterGroups[0]),k(!1,we&&we.filterGroups[1]),k(!1,we&&we.filterGroups[2]),k(!1,we&&we.filterGroups[3]),k(!1,we&&we.filterGroups[4]),k(!1,we&&we.fi+>fe==we)}CheckForExclusiveOption(we,fe){he.forEach(Fe=>{Fe.group==we&&Fe.filters.includes(fe)&&Fe.filters.forEach(Ie=>{Ie!==fe&&this.SelectOption(we,Ie,!1)})})}SelectOption(we,fe,Fe){let le=this.m_filterSpec.filterGroups[we].rgOptions;if(we==C.sc){const Xe=fe;if(R(Xe)&&Fe&&(this.ClearSteamHWCompatOptions(le),Xe==C.eb))return}we==C.Tx&&Fe&&(E.O$.RefreshOwnedGames(fe),(0,S.L)("Library/AddFriend+e.filterGroups[4]),k(!1,we&&we.filterGroups[5]),k(!1,we&&we.filterGroups[6]),k(!1,we&&we.filterGroups[7]),k(!1,we&&we.filterGroups[8])],setSuggestions:new Set}}Reset(){this.m_filterSpec.strSearchText="",this.m_filterSpec.filterGroups.forEach(we=>we.rgOptions=[])}BIncludesTools(){const we=this.GetSelectedOptions(C.Wc);return!!we.find(fe=>fe==n.B7)||we.length==0}+).join(", "));let Ot=this.GetSelectedOptions(C.RB);return Ot.length>0&&we.push(Ot.map(yt=>(0,l.we)(`#Accessibility_Feature_${H(C.RB,yt)}`)).join(", ")),we}get bIsEmpty(){return this.searchText.length==0&&this.m_filterSpec.filterGroups.every(we=>we.rgOptions.length==0)}get searchText(){return this.m_filterSpec.strSearchText}SetSearchText(we){this.m_filterSpec.str+is.GetSelectedOptions(C.Wc);Fe.length>0&&Fe.length!=fe.length&&we.push(fe.filter(yt=>Fe.indexOf(yt)!==-1).map(yt=>(0,l.we)(Vu.LocalizeAppType(yt))).join(", "));let le=this.GetSelectedOptions(C.W6);le.length>0&&we.push(le.map(yt=>{if(yt==C.Pu){if((0,P.CI)())return(0,l.we)("#FilterElement_ValidPlatform_Linux");if((0,P.Pr)())return(0,l.we)("#FilterElement_ValidPlatform_MacOS")}return(0,l.we)("#FilterEle+.VQ,ja=i.n6.bIsGameListSortedByRecent,ra=i.n6.selectedGameListView!=i.GA,Ja=i.n6.currentAppFilter.BIsSelected(_s.W6,_s.Sr),Wa=!si,go=!(0,at.td)(),no=(0,at.CI)(),co=i.n6.currentAppFilter.BIsSelected(_s.W6,_s.Pu);return(0,e.jsxs)("div",{className:fo().Bar,children:[(0,e.jsx)(Mr.EN,{active:ms,children:(0,e.jsx)(s0,{closeModal:Vs})}),(0,e.jsxs)("div",{className:fo().SearchBar,ref:Ei,tabIndex:-1,children:[(0,e.jsxs)+ren:(0,e.jsx)(y.i3G,{angle:0})})]}),(0,e.jsx)("div",{className:fo().ViewFiltersBar,children:(0,e.jsxs)("div",{className:(0,p.A)(fo().Filters,Jn&&fo().Disabled),children:[go&&(0,e.jsxs)(ct.he,{direction:"top",nDelayShowMS:240,toolTipContent:no?"#GameList_View_Platform_Linux":"#GameList_View_Platform_Apple",className:(0,p.A)(fo().CheckboxWithImage,ra&&fo().Disabled,co&&fo().Active),onClick:()=>ra||c1(_s.W6,_s.Pu,!co),children:[no&&(0,e.jsx)(y.Wy0,{}),!no&&(0,e.jsx)(y.kPc,{})]}),(0,e.jsx)(ct.he,{direction:"top",nDelayShowMS:240,toolTipContent:"#GameList_View_SortByRecent",className:(0,p.A)(fo().CheckboxWithImage,Jn&&fo().Disabled,ja&&fo().Active),onClick:()=>Jn||l1(!ja),children:(0,e.jsx)(y.QHH,{})}),(0,e.jsx)(ct.m9,{direction:"+AppType!=n.em&&Ze.local_per_client_data&&!!Ze.local_per_client_data.installed;case C.zW:return Ze.rt_last_time_played>0;case C.jn:return!Ze.rt_last_time_played;case C.Pu:return(0,P.CI)()&&!(0,P.mP)()?Ce(Ze):(0,P.td)()?!0:Ze.is_available_on_current_platform&&!Ze.is_invalid_os_type;case C.fd:return e.tw.BIsAppPrivate(Ze.appid);default:return!1}}}function tt(Ze){return Ze.BHasStoreTag}function et(Ze){return we=>E.O$.GetOwnedGames(we).has(Zediff --git a/dylib/tests/webpatch-fixtures/library.1790904859.js b/dylib/tests/webpatch-fixtures/library.1790904859.jsnew file mode 100644index 0000000..8d366a1--- /dev/null+++ b/dylib/tests/webpatch-fixtures/library.1790904859.js@@ -0,0 +1,10 @@+on(Me){this.m_filterSpec.filterGroups[Me].bAcceptUnion=!this.m_filterSpec.filterGroups[Me].bAcceptUnion}MatchesImpl(Me){const ge=this.m_filterSpec.filterGroups;if(!q(ge[C.W6],Fe(Me))||!q(ge[C.sc],Ae(Me))||!q(ge[C.Kr],et(Me))||!q(ge[C.bp],Ze(Me))||!q(ge[C.Tx],$e(Me))||!q(ge[C.vA],Ie(Me))||!q(ge[C.RB],Ue(Me)))return!1;if(this.m_filterSpec.strSearchText){if+des(We)||Me.sort_as.includes(We)||g(ae,We)!==-1)}return!0}Matches(Me){return this.MatchesImpl(Me)}MatchesScoredImpl(Me){const ge=this.m_filterSpec.filterGroups;if(!q(ge[C.W6],Fe(Me))||!q(ge[C.sc],Ae(Me))||!q(ge[C.Kr],et(Me))||!q(ge[C.bp],Ze(Me))||!q(ge[C.Tx],$e(Me))||!q(ge[C.vA],Ie(Me))||!q(ge[C.RB],Ue(Me))||Me.BIsAppBlocked())return 0;if(this.m_filterSp+t At=2,at=class Mu{m_filterSpec=void 0;constructor(Me){(0,s.Gn)(this),Me&&(Me.filterGroups[2].rgOptions=Me.filterGroups[2].rgOptions?.filter(ge=>ge!=C.eb)||[]),this.m_filterSpec={nFormatVersion:At,strSearchText:Me&&Me.strSearchText||"",filterGroups:[H(!0,Me&&Me.filterGroups[0]),H(!1,Me&&Me.filterGroups[1]),H(!1,Me&&Me.filterGroups[2]),H(!1,Me&&Me.filterGroups[3]),H(!1,Me&&Me.filterGroups[4]),H(!1,Me&&Me.fi+>ge==Me)}CheckForExclusiveOption(Me,ge){fe.forEach(We=>{We.group==Me&&We.filters.includes(ge)&&We.filters.forEach(Ee=>{Ee!==ge&&this.SelectOption(Me,Ee,!1)})})}SelectOption(Me,ge,We){let ae=this.m_filterSpec.filterGroups[Me].rgOptions;if(Me==C.sc){const Xe=ge;if(U(Xe)&&We&&(this.ClearSteamHWCompatOptions(ae),Xe==C.eb))return}Me==C.Tx&&We&&(S.O$.RefreshOwnedGames(ge),(0,x.L)("Library/AddFriend+e.filterGroups[4]),H(!1,Me&&Me.filterGroups[5]),H(!1,Me&&Me.filterGroups[6]),H(!1,Me&&Me.filterGroups[7]),H(!1,Me&&Me.filterGroups[8])],setSuggestions:new Set}}Reset(){this.m_filterSpec.strSearchText="",this.m_filterSpec.filterGroups.forEach(Me=>Me.rgOptions=[])}BIncludesTools(){const Me=this.GetSelectedOptions(C.Wc);return!!Me.find(ge=>ge==n.B7)||Me.length==0}+).join(", "));let Tt=this.GetSelectedOptions(C.RB);return Tt.length>0&&Me.push(Tt.map(Mt=>(0,l.we)(`#Accessibility_Feature_${R(C.RB,Mt)}`)).join(", ")),Me}get bIsEmpty(){return this.searchText.length==0&&this.m_filterSpec.filterGroups.every(Me=>Me.rgOptions.length==0)}get searchText(){return this.m_filterSpec.strSearchText}SetSearchText(Me){this.m_filterSpec.str+is.GetSelectedOptions(C.Wc);We.length>0&&We.length!=ge.length&&Me.push(ge.filter(Mt=>We.indexOf(Mt)!==-1).map(Mt=>(0,l.we)(Mu.LocalizeAppType(Mt))).join(", "));let ae=this.GetSelectedOptions(C.W6);ae.length>0&&Me.push(ae.map(Mt=>{if(Mt==C.Pu){if((0,P.CI)())return(0,l.we)("#FilterElement_ValidPlatform_Linux");if((0,P.Pr)())return(0,l.we)("#FilterElement_ValidPlatform_MacOS")}return(0,l.we)("#FilterEle+.VQ,Ia=i.n6.bIsGameListSortedByRecent,Js=i.n6.selectedGameListView!=i.GA,Ha=i.n6.currentAppFilter.BIsSelected(Is.W6,Is.Sr),Ta=!ii,io=!(0,nt.td)(),Ya=(0,nt.CI)(),$a=i.n6.currentAppFilter.BIsSelected(Is.W6,Is.Pu);return(0,e.jsxs)("div",{className:ho().Bar,children:[(0,e.jsx)(Ir.EN,{active:Us,children:(0,e.jsx)(T0,{closeModal:Vs})}),(0,e.jsxs)("div",{className:ho().SearchBar,ref:Ii,tabIndex:-1,children:[(0,e.jsxs)+ren:(0,e.jsx)(y.i3G,{angle:0})})]}),(0,e.jsx)("div",{className:ho().ViewFiltersBar,children:(0,e.jsxs)("div",{className:(0,f.A)(ho().Filters,kn&&ho().Disabled),children:[io&&(0,e.jsxs)(lt.he,{direction:"top",nDelayShowMS:240,toolTipContent:Ya?"#GameList_View_Platform_Linux":"#GameList_View_Platform_Apple",className:(0,f.A)(ho().CheckboxWithImage,Js&&ho().Disabled,$a&&ho().Active),onClick:()=>Js||G1(Is.W6,Is.Pu,!$a),children:[Ya&&(0,e.jsx)(y.Wy0,{}),!Ya&&(0,e.jsx)(y.kPc,{})]}),(0,e.jsx)(lt.he,{direction:"top",nDelayShowMS:240,toolTipContent:"#GameList_View_SortByRecent",className:(0,f.A)(ho().CheckboxWithImage,kn&&ho().Disabled,Ia&&ho().Active),onClick:()=>kn||y1(!Ia),children:(0,e.jsx)(y.QHH,{})}),(0,e.jsx)(lt.m9,{direction:"+AppType!=n.em&&Qe.local_per_client_data&&!!Qe.local_per_client_data.installed;case C.zW:return Qe.rt_last_time_played>0;case C.jn:return!Qe.rt_last_time_played;case C.Pu:return(0,P.CI)()&&!(0,P.mP)()?Pe(Qe):(0,P.td)()?!0:Qe.is_available_on_current_platform&&!Qe.is_invalid_os_type;case C.fd:return e.tw.BIsAppPrivate(Qe.appid);default:return!1}}}function et(Qe){return Qe.BHasStoreTag}function $e(Qe){return Me=>S.O$.GetOwnedGames(Me).has(Qediff --git a/dylib/tests/webpatch-fixtures/library.1791918634.js b/dylib/tests/webpatch-fixtures/library.1791918634.jsnew file mode 100644index 0000000..66c2814--- /dev/null+++ b/dylib/tests/webpatch-fixtures/library.1791918634.js@@ -0,0 +1,10 @@+on(we){this.m_filterSpec.filterGroups[we].bAcceptUnion=!this.m_filterSpec.filterGroups[we].bAcceptUnion}MatchesImpl(we){const Ae=this.m_filterSpec.filterGroups;if(!$(Ae[L.W6],Se(we))||!$(Ae[L.sc],Pe(we))||!$(Ae[L.Kr],Ve(we))||!$(Ae[L.bp],mt(we))||!$(Ae[L.Tx],_e(we))||!$(Ae[L.vA],xe(we))||!$(Ae[L.RB],Ue(we)))return!1;if(this.m_filterSpec.strSearchText){if+des(Ne)||we.sort_as.includes(Ne)||g(le,Ne)!==-1)}return!0}Matches(we){return this.MatchesImpl(we)}MatchesScoredImpl(we){const Ae=this.m_filterSpec.filterGroups;if(!$(Ae[L.W6],Se(we))||!$(Ae[L.sc],Pe(we))||!$(Ae[L.Kr],Ve(we))||!$(Ae[L.bp],mt(we))||!$(Ae[L.Tx],_e(we))||!$(Ae[L.vA],xe(we))||!$(Ae[L.RB],Ue(we))||we.BIsAppBlocked())return 0;if(this.m_filterSp+t ut=2,rt=class Su{m_filterSpec=void 0;constructor(we){(0,s.Gn)(this),we&&(we.filterGroups[2].rgOptions=we.filterGroups[2].rgOptions?.filter(Ae=>Ae!=L.eb)||[]),this.m_filterSpec={nFormatVersion:ut,strSearchText:we&&we.strSearchText||"",filterGroups:[H(!0,we&&we.filterGroups[0]),H(!1,we&&we.filterGroups[1]),H(!1,we&&we.filterGroups[2]),H(!1,we&&we.filterGroups[3]),H(!1,we&&we.filterGroups[4]),H(!1,we&&we.fi+>Ae==we)}CheckForExclusiveOption(we,Ae){fe.forEach(Ne=>{Ne.group==we&&Ne.filters.includes(Ae)&&Ne.filters.forEach(Ee=>{Ee!==Ae&&this.SelectOption(we,Ee,!1)})})}SelectOption(we,Ae,Ne){let le=this.m_filterSpec.filterGroups[we].rgOptions;if(we==L.sc){const Xe=Ae;if(K(Xe)&&Ne&&(this.ClearSteamHWCompatOptions(le),Xe==L.eb))return}we==L.Tx&&Ne&&(S.O$.RefreshOwnedGames(Ae),(0,T.L)("Library/AddFriend+e.filterGroups[4]),H(!1,we&&we.filterGroups[5]),H(!1,we&&we.filterGroups[6]),H(!1,we&&we.filterGroups[7]),H(!1,we&&we.filterGroups[8])],setSuggestions:new Set}}Reset(){this.m_filterSpec.strSearchText="",this.m_filterSpec.filterGroups.forEach(we=>we.rgOptions=[])}BIncludesTools(){const we=this.GetSelectedOptions(L.Wc);return!!we.find(Ae=>Ae==n.B7)||we.length==0}+).join(", "));let Et=this.GetSelectedOptions(L.RB);return Et.length>0&&we.push(Et.map(wt=>(0,l.we)(`#Accessibility_Feature_${V(L.RB,wt)}`)).join(", ")),we}get bIsEmpty(){return this.searchText.length==0&&this.m_filterSpec.filterGroups.every(we=>we.rgOptions.length==0)}get searchText(){return this.m_filterSpec.strSearchText}SetSearchText(we){this.m_filterSpec.str+is.GetSelectedOptions(L.Wc);Ne.length>0&&Ne.length!=Ae.length&&we.push(Ae.filter(wt=>Ne.indexOf(wt)!==-1).map(wt=>(0,l.we)(Su.LocalizeAppType(wt))).join(", "));let le=this.GetSelectedOptions(L.W6);le.length>0&&we.push(le.map(wt=>{if(wt==L.Pu){if((0,P.CI)())return(0,l.we)("#FilterElement_ValidPlatform_Linux");if((0,P.Pr)())return(0,l.we)("#FilterElement_ValidPlatform_MacOS")}return(0,l.we)("#FilterEle+.VQ,ps=r.n6.bIsGameListSortedByRecent,ha=r.n6.selectedGameListView!=r.GA,fa=r.n6.currentAppFilter.BIsSelected(as.W6,as.Sr),$a=!Jr,Ua=!(0,tt.td)(),ka=(0,tt.CI)(),Io=r.n6.currentAppFilter.BIsSelected(as.W6,as.Pu);return(0,e.jsxs)("div",{className:go().Bar,children:[(0,e.jsx)(Tr.EN,{active:Ns,children:(0,e.jsx)(Vc,{closeModal:fs})}),(0,e.jsxs)("div",{className:go().SearchBar,ref:Si,tabIndex:-1,children:[(0,e.jsxs)+ren:(0,e.jsx)(y.i3G,{angle:0})})]}),(0,e.jsx)("div",{className:go().ViewFiltersBar,children:(0,e.jsxs)("div",{className:(0,p.A)(go().Filters,gs&&go().Disabled),children:[Ua&&(0,e.jsxs)(st.he,{direction:"top",nDelayShowMS:240,toolTipContent:ka?"#GameList_View_Platform_Linux":"#GameList_View_Platform_Apple",className:(0,p.A)(go().CheckboxWithImage,ha&&go().Disabled,Io&&go().Active),onClick:()=>ha||y1(as.W6,as.Pu,!Io),children:[ka&&(0,e.jsx)(y.Wy0,{}),!ka&&(0,e.jsx)(y.kPc,{})]}),(0,e.jsx)(st.he,{direction:"top",nDelayShowMS:240,toolTipContent:"#GameList_View_SortByRecent",className:(0,p.A)(go().CheckboxWithImage,gs&&go().Disabled,ps&&go().Active),onClick:()=>gs||K1(!ps),children:(0,e.jsx)(y.QHH,{})}),(0,e.jsx)(st.m9,{direction:"+AppType!=n.em&&Ke.local_per_client_data&&!!Ke.local_per_client_data.installed;case L.zW:return Ke.rt_last_time_played>0;case L.jn:return!Ke.rt_last_time_played;case L.Pu:return(0,P.CI)()&&!(0,P.mP)()?ke(Ke):(0,P.td)()?!0:Ke.is_available_on_current_platform&&!Ke.is_invalid_os_type;case L.fd:return e.tw.BIsAppPrivate(Ke.appid);default:return!1}}}function Ve(Ke){return Ke.BHasStoreTag}function _e(Ke){return we=>S.O$.GetOwnedGames(we).has(Kediff --git a/helpers/appinfo.swift b/helpers/appinfo.swiftindex 8f71286..feb9c61 100644--- a/helpers/appinfo.swift+++ b/helpers/appinfo.swift@@ -1,5 +1,6 @@// Reads Steam's appinfo.vdf cache and prints key=value metadata for one app on// stdout. Usage: appinfo <appinfo.vdf> <appid>.+// With --platforms instead of an appid it prints mac= and windows= appid lists.//// common/icon is a 32x32 thumbnail. common/clienticon is the real multi-res// icon, and the two hashes differ for most apps, so the icon cannot be@@ -9,8 +10,9 @@import Foundationlet args = CommandLine.arguments-guard args.count == 3, let wantAppID = UInt32(args[2]) else {- fputs("usage: appinfo <appinfo.vdf> <appid>\n", stderr)+let platforms = args.count == 3 && args[2] == "--platforms"+guard args.count == 3, platforms || UInt32(args[2]) != nil else {+ fputs("usage: appinfo <appinfo.vdf> <appid>|--platforms\n", stderr)exit(2)}@@ -36,15 +38,22 @@ indirect enum Value {struct Cursor {let b: [UInt8]var p: Int+ let end: Int++ init(b: [UInt8], p: Int, end: Int? = nil) {+ self.b = b+ self.p = p+ self.end = end ?? b.count+ }mutating func u8() throws -> UInt8 {- guard p < b.count else { throw VDFError.truncated }+ guard p < end else { throw VDFError.truncated }defer { p += 1 }return b[p]}mutating func u32() throws -> UInt32 {- guard p + 4 <= b.count else { throw VDFError.truncated }+ guard p + 4 <= end else { throw VDFError.truncated }defer { p += 4 }return UInt32(b[p]) | UInt32(b[p + 1]) << 8| UInt32(b[p + 2]) << 16 | UInt32(b[p + 3]) << 24@@ -53,7 +62,7 @@ struct Cursor {mutating func u64() throws -> UInt64 {var v: UInt64 = 0for i in 0..<8 {- guard p + i < b.count else { throw VDFError.truncated }+ guard p + i < end else { throw VDFError.truncated }v |= UInt64(b[p + i]) << (8 * UInt64(i))}p += 8@@ -63,8 +72,8 @@ struct Cursor {// Values and, before the string table existed, keys are NUL terminated.mutating func cstring() throws -> String {var end = p- while end < b.count && b[end] != 0 { end += 1 }- guard end < b.count else { throw VDFError.truncated }+ while end < self.end && b[end] != 0 { end += 1 }+ guard end < self.end else { throw VDFError.truncated }let s = String(decoding: b[p..<end], as: UTF8.self)p = end + 1return s@@ -73,8 +82,8 @@ struct Cursor {// A wide string ends at a NUL pair, not a single NUL.mutating func wcstring() throws -> String {var end = p- while end + 1 < b.count && !(b[end] == 0 && b[end + 1] == 0) { end += 2 }- guard end + 1 < b.count else { throw VDFError.truncated }+ while end + 1 < self.end && !(b[end] == 0 && b[end + 1] == 0) { end += 2 }+ guard end + 1 < self.end else { throw VDFError.truncated }var units: [UInt16] = []var i = pwhile i < end {@@ -86,7 +95,7 @@ struct Cursor {}mutating func skip(_ n: Int) throws {- guard p + n <= b.count else { throw VDFError.truncated }+ guard p + n <= end else { throw VDFError.truncated }p += n}}@@ -133,21 +142,24 @@ func readSection(_ c: inout Cursor, _ table: [String]?) throws -> [String: Value}}-func findApp(_ b: [UInt8], _ appID: UInt32) throws -> [String: Value]? {+// Returns false when the list runs out before the zero appid that ends it.+func forEachApp(_ b: [UInt8], _ visit: (UInt32, () throws -> [String: Value]) throws -> Bool) throws -> Bool {var head = Cursor(b: b, p: 0)let magic = try head.u32()_ = try head.u32()var table: [String]? = nilvar pos: Int+ var entriesEnd = b.count// The sha1 of the entry's own binary vdf arrived in v28, which moves the// start of the key data 20 bytes further into every app entry.var entryHeader = 60switch magic {case 0x0756_4429:let offset = try head.u64()- guard offset < UInt64(b.count) else { throw VDFError.truncated }+ guard offset >= 16, offset < UInt64(b.count) else { throw VDFError.truncated }table = try readStringTable(b, at: Int(offset))+ entriesEnd = Int(offset)pos = 16case 0x0756_4428:pos = 8@@ -158,25 +170,64 @@ func findApp(_ b: [UInt8], _ appID: UInt32) throws -> [String: Value]? {throw VDFError.unknownMagic(magic)}- while pos + 8 <= b.count {- var e = Cursor(b: b, p: pos)+ while pos + 4 <= entriesEnd {+ var e = Cursor(b: b, p: pos, end: entriesEnd)let id = try e.u32()- if id == 0 { return nil }+ if id == 0 { return true }let size = Int(try e.u32())- if id == appID {- var kv = Cursor(b: b, p: pos + 8 + entryHeader)+ guard size >= entryHeader, size <= entriesEnd - pos - 8 else { throw VDFError.truncated }+ let entryEnd = pos + 8 + size+ let start = pos + 8 + entryHeader+ let keys = { () throws -> [String: Value] in+ var kv = Cursor(b: b, p: start, end: entryEnd)let root = try readSection(&kv, table)// Each entry wraps its keys in one "appinfo" section.if case .section(let inner)? = root["appinfo"] { return inner }return root}- guard size > 0 else { throw VDFError.truncated }- pos = pos + 8 + size+ if try !visit(id, keys) { return true }+ pos = entryEnd+ }+ return false+}++func findApp(_ b: [UInt8], _ appID: UInt32) throws -> [String: Value]? {+ var found: [String: Value]?+ _ = try forEachApp(b) { id, keys in+ guard id == appID else { return true }+ found = try keys()+ return false+ }+ return found+}++// Steam treats an app without an oslist as Windows only.+// oslist can still say macos for a 32-bit build that no longer runs.+func printPlatforms(_ b: [UInt8]) throws {+ var mac: [UInt32] = []+ var windows: [UInt32] = []+ let complete = try forEachApp(b) { id, keys in+ guard case .section(let common)? = try keys()["common"] else { return true }+ guard case .string(let oslist)? = common["oslist"] else {+ windows.append(id)+ return true+ }+ let systems = oslist.split(separator: ",")+ if systems.contains("macos") { mac.append(id) }+ if systems.contains("windows") { windows.append(id) }+ return true}- return nil+ guard complete else { throw VDFError.truncated }+ print("mac=" + mac.map(String.init).joined(separator: ","))+ print("windows=" + windows.map(String.init).joined(separator: ","))}do {+ if platforms {+ try printPlatforms(bytes)+ exit(0)+ }+ let wantAppID = UInt32(args[2])!guard let app = try findApp(bytes, wantAppID) else {fputs("appinfo: no entry for appid \(wantAppID)\n", stderr)exit(1)