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
Preserve quoted launch options when editing CrossOver settings
Logandfe6495e9e23
diff --git a/Makefile b/Makefileindex 78d7b0a..d1fc6a2 100644--- a/Makefile+++ b/Makefile@@ -287,6 +287,7 @@ panel-behavior:$(PANEL_TESTS)/emit.c && \node $(PANEL_TESTS)/behavior.js $(OUT_DIR)/panel-emit && \node $(PANEL_TESTS)/switching.js $(OUT_DIR)/panel-emit && \+ node $(PANEL_TESTS)/launch-options.js $(OUT_DIR)/panel-emit && \echo "==> panel behavior: renders as expected, no stale arguments"CX_ROOT ?= /Applications/CrossOver Preview.appdiff --git a/dylib/feats/webpatch.c b/dylib/feats/webpatch.cindex 1aba96b..7a04ff7 100644--- a/dylib/feats/webpatch.c+++ b/dylib/feats/webpatch.c@@ -104,7 +104,28 @@ static int out_expand(np_out_t *o, const char *replace, const np_cap_t *caps) {return 1;}-// CrossOver options panel. Not in great shape, but it'll do+// Keep the original token spans when editing launch options. Decoding quotes is+// only for matching assignments, never for executing or rewriting game arguments.+// Removed assignments take their following whitespace so repeated edits do not+// accumulate separators. hook_launch.c runs the options through a shell, so only+// assignments before %command% are environment variables. Without %command%, Steam+// passes everything to the game, but leading assignments are still edited because+// earlier versions of this panel wrote them there. Shell operators, comments and+// unquoted line breaks would change what the shell runs, so they disable editing.+#define NP_CX_OPTION_TOKENS \+ "a=(()=>{const a=[];let i=0;while(i<o.length){" \+ "if(o[i]===\"\\n\")return null;if(/\\s/.test(o[i])){i++;continue}" \+ "const start=i;let v=\"\",q=0;" \+ "while(i<o.length){const c=o.charCodeAt(i);if(!q&&/\\s/.test(o[i]))break;" \+ "if(c===q){q=0;i++;continue}" \+ "if(!q&&(c===34||c===39)){q=c;i++;continue}" \+ "if(c===92&&q!==39){if(i+1===o.length)return null;" \+ "const n=o.charCodeAt(i+1);if(!q||n===34||n===92||n===36||n===96||n===10){" \+ "if(n!==10)v+=o[i+1];i+=2;continue}}" \+ "if(!q&&(/[;&|<>()`]/.test(o[i])||i===start&&o[i]===\"#\"))return null;v+=o[i++]}" \+ "if(q)return null;a.push({start,end:i,value:v})}return a})(),"++// CrossOver options panel.#define NP_CX_OPTIONS_CSS \"\".MSCXPanel{margin-top:10px}" \".MSCXPanel .MSCXRow{display:flex;flex-direction:row;padding:9px;margin:0;" \@@ -115,15 +136,23 @@ static int out_expand(np_out_t *o, const char *replace, const np_cap_t *caps) {#define NP_CX_OPTIONS_BODY(ARG, RT, BARREL) \ARG "=>{" \"const t=" ARG ".details,o=t.strLaunchOptions||\"\"," \- "g=k=>{const p=o.split(\" \").find(x=>x.indexOf(k+\"=\")===0);return p?p.slice(k.length+1):\"\"}," \- "s=ps=>{const a=o.split(\" \").filter(x=>x&&!ps.some(p=>x.indexOf(p[0]+\"=\")===0))," \- "v=ps.filter(p=>p[1]).map(p=>p[0]+\"=\"+p[1]);" \- "if(v.length&&a.indexOf(\"%command%\")<0)v.push(\"%command%\");" \- "const r=v.concat(a);" \- "SteamClient.Apps.SetAppLaunchOptions(t.unAppID," \- "1===r.length&&\"%command%\"===r[0]?\"\":r.join(\" \"))}," \+ NP_CX_OPTION_TOKENS \+ "cut=a?a.findIndex(x=>x.value===\"%command%\"):-1," \+ "lead=a?a.findIndex(x=>!/^[A-Za-z_]\\w*=/.test(o.slice(x.start,x.end))):-1," \+ "env=a&&(cut<0?[]:a.slice(0,cut))," \+ "ed=a&&(cut<0?a.slice(0,lead<0?a.length:lead):env)," \+ "g=k=>{const p=(env||[]).filter(x=>o.startsWith(k+\"=\",x.start)).pop();" \+ "return p?p.value.slice(k.length+1):\"\"}," \+ "s=ps=>{if(!a)return;let rest=\"\",end=0;" \+ "ed.forEach(x=>{if(ps.some(p=>o.startsWith(p[0]+\"=\",x.start))){" \+ "rest+=o.slice(end,x.start);end=x.end;" \+ "while(end<o.length&&/\\s/.test(o[end]))end++}});rest+=o.slice(end);" \+ "const added=ps.filter(p=>p[1]).map(p=>p[0]+\"=\"+p[1]).join(\" \");" \+ "if(added&&cut<0)rest=\"%command%\"+(rest?\" \"+rest:\"\");" \+ "const r=added?added+(rest?\" \"+rest:\"\"):rest;" \+ "SteamClient.Apps.SetAppLaunchOptions(t.unAppID,r.trim()===\"%command%\"?\"\":r)}," \"T=(ks,l,on,off)=>(0," RT ".jsx)(" BARREL ".Yh,{className:\"MSCXRow\",label:l," \- "checked:g(ks[0])===on," \+ "checked:g(ks[0])===on,disabled:!a," \"onChange:v=>s(ks.map(k=>[k,v?on:(off||\"\")]))},ks[0])," \"b=g(\"CX_GRAPHICS_BACKEND\")," \"dm=\"\"===b||\"d3dmetal\"===b," \@@ -145,8 +174,11 @@ static int out_expand(np_out_t *o, const char *replace, const np_cap_t *caps) {"&&!t.strCompatToolName)return null;" \"return(0," RT ".jsx)(\"div\",{className:\"MSCXPanel\",children:(0," RT ".jsxs)(" RT ".Fragment,{children:[" \"(0," RT ".jsx)(\"style\",{children:" NP_CX_OPTIONS_CSS "})," \+ "!a&&(0," RT ".jsx)(\"div\",{role:\"status\",children:" \+ "\"To edit CrossOver settings here, close any open quotes or escapes in Launch Options " \+ "and remove shell operators (; & | < > ( ) ` #) and line breaks.\"})," \"(0," RT ".jsxs)(" BARREL ".XY,{label:\"Graphics\",children:[" \- "(0," RT ".jsx)(" BARREL ".m,{rgOptions:B,selectedOption:b," \+ "(0," RT ".jsx)(" BARREL ".m,{rgOptions:B,selectedOption:b,disabled:!a," \"onChange:v=>s([[\"CX_GRAPHICS_BACKEND\",v.data]]" \".concat(\"\"===v.data||\"d3dmetal\"===v.data?[]:[[\"D3DM_ENABLE_METALFX\",\"\"]])" \".concat(\"\"===v.data||\"dxmt\"===v.data?[]:" \@@ -161,7 +193,7 @@ static int out_expand(np_out_t *o, const char *replace, const np_cap_t *caps) {"]},\"gfx\")," \"dx&&(0," RT ".jsx)(" BARREL ".XY," \"{label:\"MetalFX Upscaling (Samples from the resolution the game is set to)\"," \- "children:(0," RT ".jsx)(" BARREL ".m,{rgOptions:U," \+ "children:(0," RT ".jsx)(" BARREL ".m,{rgOptions:U,disabled:!a," \"selectedOption:sw?(0===cf.indexOf(F)?cf.slice(F.length):\"2.0\"):\"\"," \"onChange:v=>s(v.data?[[\"DXMT_METALFX_SPATIAL_SWAPCHAIN\",\"1\"],[\"DXMT_CONFIG\",F+v.data]]" \":[[\"DXMT_METALFX_SPATIAL_SWAPCHAIN\",\"\"],[\"DXMT_CONFIG\",\"\"]])})},\"usf\")" \diff --git a/dylib/tests/panel-behavior/behavior.js b/dylib/tests/panel-behavior/behavior.jsindex 3438f1c..47dadb6 100644--- a/dylib/tests/panel-behavior/behavior.js+++ b/dylib/tests/panel-behavior/behavior.js@@ -9,7 +9,8 @@ let failed = 0;for (const form of Object.keys(FORMS)) {const { render: P, written } = panel(emit, form);const t = runner(form);- const nodes = opts => walk(P({ details: details(opts) }));+ // Only assignments ahead of %command% are environment variables.+ const nodes = opts => walk(P({ details: details(opts + ' %command%') }));const toggles = ns => ns.filter(x => x.type === 'Toggle').map(x => x.props.label);const sections = ns => ns.filter(x => x.type === 'Section').map(x => x.props.label.split(' ')[0]);const last = () => (written.length ? written[written.length - 1].opts : '');diff --git a/dylib/tests/panel-behavior/launch-options.js b/dylib/tests/panel-behavior/launch-options.jsnew file mode 100644index 0000000..91519c6--- /dev/null+++ b/dylib/tests/panel-behavior/launch-options.js@@ -0,0 +1,115 @@+// Exercise the emitted panel against quoted assignments and game arguments.+'use strict';+const { panel, walk, details, runner, FORMS } = require('./harness');++const emit = process.argv[2];+if (!emit) { console.error('usage: launch-options.js <emit>'); process.exit(2); }++let failed = 0;+for (const form of Object.keys(FORMS)) {+ const { render: P, written } = panel(emit, form);+ const t = runner(form);+ const nodes = opts => walk(P({ details: details(opts) }));+ const last = () => written[written.length - 1].opts;+ const hud = opts => nodes(opts).find(x => x.props.label === 'Metal HUD');++ for (const assignment of ['MTL_HUD_ENABLED="1"', "MTL_HUD_ENABLED='1'",+ 'MTL_HUD_ENABLED=\\1']) {+ t.ok(hud(assignment + ' %command%').props.checked, `reads ${assignment}`);+ written.length = 0;+ hud(assignment + ' %command%').props.onChange(false);+ t.ok(last() === '', `removes the whole token ${assignment}`);+ }++ for (const tail of [+ 'WINEDEBUG="err+all, trace+seh" %command% --name "two words"',+ "DXMT_CONFIG='d3d11.foo=1 d3d11.bar=2' %command% --name 'two words'",+ 'WINEDEBUG=err+all,\\ trace+seh %command% --name two\\ words',+ 'MTL_HUD_ENABLED_EXTRA=1 %command% --title "MTL_HUD_ENABLED=0 extra"',+ 'DXMT_CONFIG="literal \\"quote\\" and \\\\slash" %command%',+ 'WINEDEBUG="$(touch /tmp/notproton-panel-must-not-run)" %command%',+ '\tWINEDEBUG="a b"\t%command%\t--name "two words" ',+ ]) {+ written.length = 0;+ hud(tail).props.onChange(true);+ t.ok(last() === 'MTL_HUD_ENABLED=1 ' + tail,+ `preserves unrelated text exactly: ${JSON.stringify(tail)}`);+ }++ // A shell only takes NAME=value as an assignment when the name is unquoted.+ t.ok(!hud('"MTL_HUD_ENABLED=1" %command%').props.checked, 'a quoted name is not an assignment');+ written.length = 0;+ hud('"MTL_HUD_ENABLED=0" %command%').props.onChange(true);+ t.ok(last() === 'MTL_HUD_ENABLED=1 "MTL_HUD_ENABLED=0" %command%', 'a quoted name is left alone');+ t.ok(!hud('%command% --title "MTL_HUD_ENABLED=1"').props.checked,+ 'game arguments do not set the toggle');+ written.length = 0;+ hud('').props.onChange(true);+ let repeated = last();+ for (let i = 0; i < 3; i++) {+ hud(repeated).props.onChange(false);+ repeated = last();+ t.ok(repeated === '', 'removing the only assignment leaves empty options');+ hud(repeated).props.onChange(true);+ repeated = last();+ t.ok(repeated === 'MTL_HUD_ENABLED=1 %command%',+ 'repeated edits do not accumulate whitespace');+ }++ const duplicates = 'MTL_HUD_ENABLED=1\tMTL_HUD_ENABLED="0" %command%';+ t.ok(!hud(duplicates).props.checked, 'the last assignment determines the toggle');+ written.length = 0;+ hud(duplicates).props.onChange(true);+ t.ok(last() === 'MTL_HUD_ENABLED=1 %command%', 'replaces all duplicate assignments');+ t.ok(!hud('MTL_HUD_ENABLED=1 MTL_HUD_ENABLED="" %command%').props.checked,+ 'an empty final assignment overrides earlier values');++ const backendOptions = 'CX_GRAPHICS_BACKEND="dxmt" DXMT_CONFIG="a=1 b=2" '+ + 'DXMT_METALFX_SPATIAL_SWAPCHAIN="1" %command% --title "a b"';+ written.length = 0;+ const backend = nodes(backendOptions).find(x => x.type === 'Dropdown');+ t.ok(backend.props.selectedOption === 'dxmt', 'reads a quoted backend');+ backend.props.onChange({ data: 'dxvk' });+ t.ok(last() === 'CX_GRAPHICS_BACKEND=dxvk %command% --title "a b"',+ 'switching removes whole quoted assignments and keeps game arguments');++ const upscaled = 'CX_GRAPHICS_BACKEND=dxmt DXMT_METALFX_SPATIAL_SWAPCHAIN="1" '+ + 'DXMT_CONFIG="d3d11.metalSpatialUpscaleFactor=1.5" %command%';+ t.ok(nodes(upscaled).filter(x => x.type === 'Dropdown')[1].props.selectedOption === '1.5',+ 'reads the factor from quoted DXMT_CONFIG');++ // Without %command%, Steam passes the options to the game as arguments.+ t.ok(!hud('MTL_HUD_ENABLED=1 -windowed').props.checked,+ 'assignments without %command% do not set the toggle');+ for (const [before, after] of [+ ['-windowed', 'MTL_HUD_ENABLED=1 %command% -windowed'],+ ['MTL_HUD_ENABLED=0 -windowed', 'MTL_HUD_ENABLED=1 %command% -windowed'],+ ['-windowed MTL_HUD_ENABLED=0', 'MTL_HUD_ENABLED=1 %command% -windowed MTL_HUD_ENABLED=0'],+ ]) {+ written.length = 0;+ hud(before).props.onChange(true);+ t.ok(last() === after, `adds %command% to ${JSON.stringify(before)}`);+ }+ written.length = 0;+ hud('MTL_HUD_ENABLED=1 -windowed').props.onChange(false);+ t.ok(last() === '-windowed', 'removes leading assignments written without %command%');++ for (const malformed of ['WINEDEBUG="unfinished', "--title 'unfinished", '--title trailing\\',+ 'WINEDEBUG=1; %command%', 'WINEDEBUG=1 %command% | tee log',+ 'WINEDEBUG=1\n%command%', '# WINEDEBUG=1 %command%',+ 'WINEDEBUG=`id` %command%', 'WINEDEBUG=1 %command% >log']) {+ written.length = 0;+ const ns = nodes(malformed);+ const controls = ns.filter(x => x.type === 'Toggle' || x.type === 'Dropdown');+ t.ok(controls.every(x => x.props.disabled), `disables edits for ${JSON.stringify(malformed)}`);+ t.ok(ns.some(x => x.props.role === 'status' && x.props.children.includes('Launch Options')),+ 'explains how to restore editing');+ controls.forEach(x => x.props.onChange(x.type === 'Toggle' ? true : { data: 'dxvk' }));+ t.ok(written.length === 0, 'callbacks leave malformed options untouched');+ }+ t.ok(nodes('WINEDEBUG="finished;" %command%').filter(x => x.type === 'Toggle' || x.type === 'Dropdown')+ .every(x => !x.props.disabled), 'editing resumes after quotes are closed');+ failed += t.failed;+}+console.log(failed ? `\n${failed} failure(s)` : '\nquoted launch options pass in both shapes');+process.exit(failed ? 1 : 0);