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(panel): keep conf defaults out of the chunk's source map comment and accept long tool names
raymondchins2c24d7d13d13
diff --git a/dylib/feats/webpatch.c b/dylib/feats/webpatch.cindex 8a67f54..74cd789 100644--- a/dylib/feats/webpatch.c+++ b/dylib/feats/webpatch.c@@ -232,6 +232,8 @@ static int out_expand(np_out_t *o, const char *replace, const np_cap_t *caps) {"children:(0," RT ".jsx)(" BARREL ".m,{rgOptions:U," \"selectedOption:sw?(U.find(u=>u.data&&+u.data===fn)||{data:String(fn)}).data:\"\"," \"onChange:v=>s([[\"DXMT_METALFX_SPATIAL_SWAPCHAIN\",v.data?\"1\":\"\"],[\"DXMT_CONFIG\",fx(v.data)]])})},\"usf\")," \+ "(0," RT ".jsx)(" BARREL ".XY,{label:\"Frame Generation (Experimental. Adds input lag)\",children:" \+ "T([\"NOTPROTON_FRAMEGEN\"],\"MetalFX frame interpolation (2x)\",\"1\",\"0\")},\"fgn\")," \"(0," RT ".jsx)(" BARREL ".XY,{label:\"Controllers (May break Steam Input. Not recommended)\",children:" \"T([\"NOTPROTON_RAW_CONTROLLERS\"],\"Let games read controllers directly\",\"1\",\"\")},\"ctl\")" \"]})})}"@@ -434,9 +436,10 @@ static const char *fx_panel_key(const char *key) {return NULL;}-static int fx_safe(const char *v) {+// Characters that go into a JSON string unescaped, up to max of them.+static int fx_word(const char *v, size_t max) {size_t n = strlen(v);- if (n > 16) return 0;+ if (n > max) return 0;for (; *v; v++)if (!((*v >= 'A' && *v <= 'Z') || (*v >= 'a' && *v <= 'z') ||(*v >= '0' && *v <= '9') || *v == '.' || *v == '_' || *v == '-'))@@ -444,6 +447,10 @@ static int fx_safe(const char *v) {return 1;}+// Values fit fx_pair_t.val. Tool names are longer ("notproton-winecx-11.17") and are+// bounded by the fallback name they are compared against instead.+static int fx_safe(const char *v) { return fx_word(v, 16); }+typedef struct { char key[32]; char val[20]; } fx_pair_t;typedef struct { fx_pair_t p[8]; size_t n; } fx_set_t;@@ -506,8 +513,10 @@ static int fx_build(char *buf, size_t cap) {char root[512], path[768];snprintf(root, sizeof(root), "%s/Library/Application Support/notproton", home);+ // Steam's chunks end in "//# sourceMappingURL=..." with no newline after it, so the+ // assignment starts a line of its own or the browser reads it as part of that comment.size_t len = 0;- int n = snprintf(buf, cap, ";globalThis.MSCXFx={\"g\":");+ int n = snprintf(buf, cap, "\n;globalThis.MSCXFx={\"g\":");if (n < 0 || (size_t)n >= cap) return 0;len = (size_t)n;@@ -564,7 +573,7 @@ static int fx_build(char *buf, size_t cap) {char *tab = strchr(line, '\t');if (!tab) continue;*tab = '\0';- if (!fx_safe(line)) continue;+ if (!*line || !fx_word(line, sizeof(g_fallback_tool) - 1)) continue;const char *ms = strstr(tab + 1, "msync") ? "1" : "0";int fallback = g_fallback_tool[0] && strcmp(line, g_fallback_tool) == 0;n = snprintf(buf + len, cap - len, "%s\"%s\":{\"WINEMSYNC\":\"%s\"}",@@ -661,7 +670,11 @@ char *np_webpatch_transform(const uint8_t *src, size_t src_len, size_t *out_len,if (shape) {char *fx = malloc(NP_FX_MAX);- int ok = !fx || !fx_build(fx, NP_FX_MAX) || out_put(&out, fx, strlen(fx));+ int built = fx && fx_build(fx, NP_FX_MAX);+ if (!built)+ NP_WARN("webpatch: [%s] conf defaults not handed to the panel, its toggles "+ "show launch options only", shape->name);+ int ok = !built || out_put(&out, fx, strlen(fx));free(fx);if (!ok) { free(out.buf); return NULL; }}diff --git a/dylib/tests/panel-behavior/effective.js b/dylib/tests/panel-behavior/effective.jsnew file mode 100644index 0000000..51fcc33--- /dev/null+++ b/dylib/tests/panel-behavior/effective.js@@ -0,0 +1,81 @@+// The conf defaults as the page receives them: the patched chunk is run the way Steam+// serves it, from a home laid out like a real install, and the panel then rendered+// against what that chunk defined.+'use strict';+const fs = require('fs');+const os = require('os');+const path = require('path');+const vm = require('vm');+const { execFileSync } = require('child_process');+const { panel, walk, details, runner, FORMS } = require('./harness');++const emit = process.argv[2];+if (!emit) { console.error('usage: effective.js <emit>'); process.exit(2); }++const home = fs.mkdtempSync(path.join(os.tmpdir(), 'np-effective-'));+const np = path.join(home, 'Library', 'Application Support', 'notproton');+const put = (rel, text) => {+ fs.mkdirSync(path.dirname(path.join(np, rel)), { recursive: true });+ fs.writeFileSync(path.join(np, rel), text);+};+put('gamefixes/default.conf',+ '# Global defaults for every game (lowest precedence: per-game confs and Steam launch options win).\n' ++ 'MTL_HUD_ENABLED=1\nRETINA=1\n' ++ '# Rosetta hides AVX/AVX2 unless asked; many games quit without it.\n' ++ 'ROSETTA_ADVERTISE_AVX=1\n' ++ '# Exposes DLSS through MetalFX (D3DMetal); only takes effect when DLSS is switched on in the game.\n' ++ 'D3DM_ENABLE_METALFX=1\n');+put('gamefixes-default/1888930.conf', 'ROSETTA_ADVERTISE_AVX=1\n');+// The first tool is the default one, and its name runs past the 16 characters a value may.+put('tools',+ 'notproton-winecx-11.17\twinecx-11.17\trosetta\tWineCX 11.17 (msync, D3DMetal)\n' ++ 'notproton-winecx\twinecx-11.15\trosetta\tWineCX 11.15 (msync, D3DMetal)\n' ++ 'notproton-winehq\twinehq-11.15\trosetta\tWineHQ 11.15 - Rosetta\n');++// Steam's chunks end in a source map comment with no newline after it.+const chunk = path.join(home, 'chunk.js');+const fixture = path.join(__dirname, '..', 'webpatch-fixtures', 'gates.forcetool.js');+const map = '//# sourceMappingURL=file:///home/buildbot/steamui/sourcemaps/chunk~2dcc5aaf7.js.map';+fs.writeFileSync(chunk, fs.readFileSync(fixture, 'utf8').replace(/\n$/, '') + map);++let failed = 0;+const t0 = runner('chunk');+let fx;+try {+ const out = execFileSync(emit, ['transform', chunk, 'notproton-winecx-11.17'],+ { encoding: 'utf8', env: Object.assign({}, process.env, { HOME: home }) });+ // Everything from the comment on is code the browser parses at the end of the chunk.+ const tail = out.slice(out.lastIndexOf(map));+ const ctx = vm.createContext({});+ vm.runInContext(tail, ctx);+ fx = ctx.MSCXFx;+} finally {+ fs.rmSync(home, { recursive: true, force: true });+}+t0.ok(fx !== undefined, 'the defaults survive the source map comment the chunk ends in');+t0.ok(!!(fx && fx.e && fx.e['notproton-winecx-11.17'] && fx.e['notproton-winecx-11.17'].WINEMSYNC === '1'),+ 'a tool name longer than a value still reaches the engine map');+t0.ok(!!(fx && fx.e && fx.e[''] && fx.e[''].WINEMSYNC === '1'), 'the default tool stands in for an unpinned game');+failed += t0.failed;++const LABELS = ['Metal HUD', 'DLSS', 'Advertise AVX2 to Rosetta', 'MSync', 'High Resolution',+ 'Let games read controllers directly'];+globalThis.MSCXFx = fx;+for (const form of Object.keys(FORMS)) {+ const { render: P } = panel(emit, form);+ const t = runner(form);+ const rows = over => walk(P({ details: details('', Object.assign({ unAppID: 1778820 }, over)) }))+ .filter(x => x.type === 'Toggle');+ const checked = over => rows(over).filter(x => x.props.checked).map(x => x.props.label);+ const on = checked({ strCompatToolName: '' });+ t.ok(LABELS.every(l => on.includes(l)),+ `a game on the default tool shows every conf and engine default on (${on.join(',')})`);+ t.ok(checked({ strCompatToolName: 'notproton-winecx-11.17' }).includes('MSync'),+ 'the default tool named outright reads MSync as on');+ t.ok(!checked({ strCompatToolName: 'notproton-winehq' }).includes('MSync'),+ 'a tool without msync reads MSync as off');+ failed += t.failed;+}+delete globalThis.MSCXFx;++if (failed) { console.error(`effective: ${failed} check(s) failed`); process.exit(1); }diff --git a/dylib/tests/panel-behavior/emit.c b/dylib/tests/panel-behavior/emit.cindex 2d4cbc2..1478629 100644--- a/dylib/tests/panel-behavior/emit.c+++ b/dylib/tests/panel-behavior/emit.c@@ -22,6 +22,25 @@ int main(int argc, char **argv) {fputs(NP_LAUNCH_MIGRATION, stdout);return 0;}- fputs("usage: emit component|statement|migration\n", stderr);+ // The chunk as Steam is served it, defaults included, read from $HOME like the hook.+ if (argc == 4 && strcmp(argv[1], "transform") == 0) {+ FILE *f = fopen(argv[2], "rb");+ if (!f) return 1;+ fseek(f, 0, SEEK_END);+ long n = ftell(f);+ rewind(f);+ uint8_t *src = malloc(n > 0 ? (size_t)n : 1);+ if (!src || fread(src, 1, (size_t)n, f) != (size_t)n) { fclose(f); return 1; }+ fclose(f);+ np_webpatch_set_fallback_tool(argv[3]);+ size_t out_len = 0;+ char *out = np_webpatch_transform(src, (size_t)n, &out_len, NULL);+ free(src);+ if (!out) return 1;+ fwrite(out, 1, out_len, stdout);+ free(out);+ return 0;+ }+ fputs("usage: emit component|statement|migration|transform <chunk> <fallback tool>\n", stderr);return 2;}