Skip to content

Open-source Xbox-inspired desktop launcher for Xodus on Linux

TypeScript

[source-only] fix(launch): run Play through the runtime Proton session

Nexus Maintainer5b2adc8f5adc
diff --git a/src/main/game-launch.test.ts b/src/main/game-launch.test.ts
index bedb6e2..796bd46 100644
--- a/src/main/game-launch.test.ts
+++ b/src/main/game-launch.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
-import { gameLaunchArguments, preparedGameWine } from './game-launch.js';
+import { gameLaunchArguments, launchEnvironmentForRuntime, preparedGameWine } from './game-launch.js';
import { LINUX_RUN_PATCH } from './backend.js';
describe('generic package launch', () => {
@@ -44,3 +44,22 @@ describe('generic package launch', () => {
expect(() => gameLaunchArguments({ path: '/package' }, '/wine', '', LINUX_RUN_PATCH)).toThrow('manifest has no launch executable');
});
});
+
+describe('runtime launch environment', () => {
+ it('replaces inherited Proton-only settings for a Proton session and leaves a standalone Wine alone', () => {
+ // A shell leftover must not replace the runtime's own values when Proton runs.
+ expect(launchEnvironmentForRuntime(
+ { WINEDLLOVERRIDES: 'dxgi=b', WINE_LARGE_ADDRESS_AWARE: '0', KEEP: '1' }, true))
+ .toEqual({ KEEP: '1' });
+ // A standalone custom Wine keeps exactly the environment it has always received.
+ const standalone = { WINEDLLOVERRIDES: 'dxgi=b', WINE_LARGE_ADDRESS_AWARE: '0', KEEP: '1' };
+ expect(launchEnvironmentForRuntime(standalone, false)).toBe(standalone);
+ expect(standalone).toEqual({ WINEDLLOVERRIDES: 'dxgi=b', WINE_LARGE_ADDRESS_AWARE: '0', KEEP: '1' });
+ });
+ it('leaves launch-option precedence to the wrapper above the runtime command', () => {
+ // The wrapper applies the game's launch options after this environment, so the
+ // user's WINEDLLOVERRIDES still wins for Play (covered in proton.test.ts).
+ const environment = launchEnvironmentForRuntime({ WINEDLLOVERRIDES: 'dxgi=b' }, true);
+ expect(environment.WINEDLLOVERRIDES).toBeUndefined();
+ });
+});
diff --git a/src/main/game-launch.ts b/src/main/game-launch.ts
index 624bb50..5da784a 100644
--- a/src/main/game-launch.ts
+++ b/src/main/game-launch.ts
@@ -28,3 +28,20 @@ export function gameLaunchArguments(
if (offline) args.push('--offline');
return args;
}
+
+/**
+ * Proton reads WINEDLLOVERRIDES and WINE_LARGE_ADDRESS_AWARE from the process
+ * environment, so a shell leftover must not replace the runtime's own values.
+ * Only a Proton session takes over these two settings: a standalone Wine keeps the
+ * inherited environment it has always received, and a game's launch options still
+ * set both above the Proton session command.
+ */
+export function launchEnvironmentForRuntime(
+ environment: NodeJS.ProcessEnv,
+ protonSession: boolean,
+): NodeJS.ProcessEnv {
+ if (!protonSession) return environment;
+ delete environment.WINEDLLOVERRIDES;
+ delete environment.WINE_LARGE_ADDRESS_AWARE;
+ return environment;
+}
diff --git a/src/main/index.ts b/src/main/index.ts
index ff8aca4..566e6ad 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -40,7 +40,7 @@ import { inspectGameDirectory, StateStore } from './store.js';
import { inspectStartupLibrary } from './startup-library.js';
import { hasIncompleteUpdate, INCOMPLETE_UPDATE_MESSAGE } from './installation-state.js';
import { RuntimeManager, type RuntimeSettingsReservation } from './runtime.js';
-import { prepareProtonRunner, syncPrefixUserLocale, syncUnrealCultureGameIni } from './proton.js';
+import { prepareProtonRunner, protonOptionalComponentNotices, syncPrefixUserLocale, syncUnrealCultureGameIni } from './proton.js';
import { layoutOfWine } from './proton-layout.js';
import { accountCacheKey } from './offline-identity.js';
import { applyOfflinePermissions, assertOfflineAccessReady, bindOfflineAccess, licenseCacheDirectory, offlineAccessRevoked, revokeOfflineAccess, type OfflineRevocation } from './offline-access.js';
@@ -54,7 +54,8 @@ import { deleteGameDirectory } from './game-delete.js';
import { spawnGameProcess, type GameProcess } from './game-process.js';
import { gameLocaleEnvironment, installedGameLocales, installedGameTitleId, supportedGameLocale } from './game-locale.js';
import { antiCheatEnvironment } from './anti-cheat.js';
-import { gameLaunchArguments, preparedGameWine } from './game-launch.js';
+import { gameLaunchArguments, launchEnvironmentForRuntime, preparedGameWine } from './game-launch.js';
+import { parseLaunchOptions } from '../shared/launch-tools.js';
import { ConnectivityMonitor } from './connectivity.js';
import { prepareGameWrapper, type GameWrapper } from './game-wrapper.js';
import { normalizeLaunchTools } from '../shared/launch-tools.js';
@@ -1373,10 +1374,21 @@ async function prepareGameLaunch(id: string, steam?: SteamGameContext): Promise<
const legacyPrefixRoot = runtimeContext.legacyPrefixRoot;
const compatibilityDataPath = runtimeContext.compatibilityDataPath;
const steamRoot = path.join(app.getPath('home'), '.steam', 'root');
- launchWrapper = await prepareGameWrapper(wine, game.launchTools, path.join(dataRoot, 'launch-wrappers'), launchEnvironment, game.path);
- const protonRunner = await prepareProtonRunner(wine, compatibilityDataPath, steamRoot, launchWrapper.command, store.settings.shaderCacheLimitGiB);
+ const protonRunner = await prepareProtonRunner(wine, compatibilityDataPath, steamRoot, store.settings.shaderCacheLimitGiB);
const wineCommand = protonRunner?.command ?? wine;
- args[2] = preparedGameWine(protonRunner, launchWrapper.command);
+ // Play goes through the runtime's Proton session when one is available, so
+ // the runtime's own launch options (for example PROTON_USE_OPTISCALER) are
+ // processed. Game tools and launch options wrap that command, exactly like
+ // Steam's %command%.
+ launchWrapper = await prepareGameWrapper(preparedGameWine(protonRunner, wine), game.launchTools, path.join(dataRoot, 'launch-wrappers'), launchEnvironment, game.path);
+ args[2] = launchWrapper.command;
+ if (protonRunner) {
+ // The optional component is selected by the game's launch options, not by
+ // the inherited environment.
+ const launchOptionsEnvironment = parseLaunchOptions(game.launchTools?.launchOptions ?? '').environment;
+ for (const notice of await protonOptionalComponentNotices({ ...launchEnvironment, ...launchOptionsEnvironment },
+ protonRunner.protonRoot, compatibilityDataPath, offlineLaunch)) addGameLog(notice);
+ }
if (inspected.vcRedistEncrypted) {
if (!protonRunner) throw new Error('This encrypted VC++ prerequisite requires a Proton prefix. Select Xodus Runtime in Settings.');
const installed = await installedVcRuntimeVersion(path.join(compatibilityDataPath, 'pfx'));
@@ -1385,9 +1397,9 @@ async function prepareGameLaunch(id: string, steam?: SteamGameContext): Promise<
}
addGameLog(`VC++ runtime ${installed} verified; launching the original package executable from a temporary decrypted launch view.`);
}
- const environment = antiCheatEnvironment(gameLocaleEnvironment(gameWindowEnvironment(gameLoggingEnvironment(protonRunner
+ const environment = launchEnvironmentForRuntime(antiCheatEnvironment(gameLocaleEnvironment(gameWindowEnvironment(gameLoggingEnvironment(protonRunner
? launchEnvironment
- : { ...launchEnvironment, WINEPREFIX: legacyPrefixRoot, WINEARCH: 'win64' }, verboseLogs)), locale));
+ : { ...launchEnvironment, WINEPREFIX: legacyPrefixRoot, WINEARCH: 'win64' }, verboseLogs)), locale)), Boolean(protonRunner));
if (process.platform === 'linux' && shortcuts.available) {
try {
const png = await loadShortcutIcon({ coverDataUrl: inspected.coverDataUrl ?? game.coverDataUrl }, bytes => {
@@ -1600,7 +1612,7 @@ async function installGameVcRuntime(id: string): Promise<void> {
preparationControllers.set(operationId, controller);
try {
const compatibilityDataPath = runtimeContext.compatibilityDataPath;
- const protonRunner = await prepareProtonRunner(wine, compatibilityDataPath, path.join(app.getPath('home'), '.steam', 'root'), undefined, store.settings.shaderCacheLimitGiB);
+ const protonRunner = await prepareProtonRunner(wine, compatibilityDataPath, path.join(app.getPath('home'), '.steam', 'root'), store.settings.shaderCacheLimitGiB);
if (!protonRunner) throw new Error('VC++ installation requires a full Proton runtime, not a standalone Wine binary.');
const prefix = path.join(compatibilityDataPath, 'pfx');
const previous = await installedVcRuntimeVersion(prefix);
diff --git a/src/main/proton-session.test.ts b/src/main/proton-session.test.ts
new file mode 100644
index 0000000..ea0234f
--- /dev/null
+++ b/src/main/proton-session.test.ts
@@ -0,0 +1,217 @@
+import { execFile as execFileCallback } from 'node:child_process';
+import { createHash } from 'node:crypto';
+import { copyFile, mkdir, mkdtemp, readFile, readdir, rm, stat, writeFile } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import path from 'node:path';
+import { promisify } from 'node:util';
+import { afterAll, describe, expect, it } from 'vitest';
+import { prepareProtonRunner, protonOptionalComponentNotices } from './proton.js';
+import { prepareGameWrapper } from './game-wrapper.js';
+import { defaultLaunchTools } from '../shared/launch-tools.js';
+
+// End-to-end fixture for the Play command of a real runtime payload. It is
+// guarded because it needs a built Nexus runtime directory:
+// XODUS_CACHYOS_PAYLOAD=<.../nexus-runtime-cachyos-...> CachyOS family
+// XODUS_STANDARD_PAYLOAD=<.../nexus-runtime-...> Standard family
+// XODUS_PROTON_FIXTURE_CACHE_DIR=<cache> optional isolated upscaler cache.
+// The fixture never touches a user prefix, cache or home directory: every run
+// uses a private compatibility directory, private HOME and a private cache, and
+// temporary roots come from TMPDIR.
+const execFile = promisify(execFileCallback);
+const cachyos = process.env.XODUS_CACHYOS_PAYLOAD;
+const standard = process.env.XODUS_STANDARD_PAYLOAD;
+const fixtureCache = process.env.XODUS_PROTON_FIXTURE_CACHE_DIR;
+const created: string[] = [];
+
+afterAll(async () => {
+ await Promise.all(created.splice(0).map((directory) => rm(directory, { recursive: true, force: true })));
+});
+
+interface Session {
+ root: string;
+ compatibilityDataPath: string;
+ runner: NonNullable<Awaited<ReturnType<typeof prepareProtonRunner>>>;
+ wrapper: { command: string };
+ stdout: string;
+ output: string;
+}
+
+async function session(payload: string, launchOptions: string, reusedRoot?: string): Promise<Session> {
+ const root = reusedRoot ?? await mkdtemp(path.join(tmpdir(), 'nexus-proton-session-'));
+ if (!reusedRoot) created.push(root);
+ const compatibilityDataPath = path.join(root, 'compat');
+ const home = path.join(root, 'home');
+ const cache = fixtureCache ?? path.join(root, 'cache');
+ await mkdir(home, { recursive: true });
+ await mkdir(cache, { recursive: true });
+ // prepareProtonRunner initializes the prefix with the runtime's own Proton
+ // session, which inherits the launcher process environment. Point HOME and the
+ // cache at this fixture root for that call so no user cache is written.
+ const previousHome = process.env.HOME, previousCache = process.env.XDG_CACHE_HOME;
+ process.env.HOME = home;
+ process.env.XDG_CACHE_HOME = cache;
+ let runner;
+ try {
+ runner = await prepareProtonRunner(path.join(payload, 'files/bin/wine'), compatibilityDataPath,
+ path.join(root, 'steam'), 4);
+ } finally {
+ if (previousHome === undefined) delete process.env.HOME; else process.env.HOME = previousHome;
+ if (previousCache === undefined) delete process.env.XDG_CACHE_HOME; else process.env.XDG_CACHE_HOME = previousCache;
+ }
+ expect(runner).toBeDefined();
+ if (!runner) throw new Error('payload is not a Proton runtime');
+ const wrapper = await prepareGameWrapper(runner.launchCommand,
+ { ...defaultLaunchTools, launchOptions }, path.join(root, 'wrappers'));
+ const childEnvironment = {
+ ...process.env,
+ HOME: home,
+ XDG_CACHE_HOME: cache,
+ // A stale shell configuration must never win over the runtime environment.
+ WINEPREFIX: '/wrong/prefix',
+ WINEDLLOVERRIDES: 'dxgi=b;stale=1',
+ UMU_ID: 'stale-umu',
+ };
+ let stdout = '', stderr = '';
+ try {
+ ({ stdout, stderr } = await execFile(wrapper.command, ['cmd', '/c', 'set'], {
+ env: childEnvironment, maxBuffer: 16 * 1024 * 1024, timeout: 900_000,
+ }));
+ } catch (error) {
+ const failure = error as Error & { stdout?: string; stderr?: string };
+ failure.message = `${failure.message}\n${failure.stdout ?? ''}\n${failure.stderr ?? ''}`;
+ throw error;
+ }
+ return { root, compatibilityDataPath, runner, wrapper, stdout, output: stdout + stderr };
+}
+
+function environmentOf(stdout: string): Map<string, string> {
+ const values = new Map<string, string>();
+ for (const line of stdout.split(/\r?\n/)) {
+ const match = line.match(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/);
+ if (match) values.set(match[1], match[2]);
+ }
+ return values;
+}
+
+async function deployedPayload(compatibilityDataPath: string) {
+ const directory = path.join(compatibilityDataPath, 'pfx/drive_c/windows/system32/umu');
+ let names: string[] = [];
+ try { names = (await readdir(directory)).sort(); } catch { names = []; }
+ const files: Record<string, { size: number; magic: string }> = {};
+ for (const name of names) {
+ const file = path.join(directory, name);
+ const info = await stat(file);
+ if (!info.isFile()) continue;
+ const head = await readFile(file).then((bytes) => bytes.subarray(0, 2).toString('latin1'), () => '');
+ files[name] = { size: info.size, magic: head };
+ }
+ return files;
+}
+
+function expectNoIntegrityFailure(output: string) {
+ // "Failed to validate optiscaler files" is the normal cold-prefix message
+ // before the payload is installed. Real integrity failures must not appear.
+ expect(output).not.toMatch(/CRIT: MD5 mismatch/);
+ expect(output).not.toMatch(/Failed to download/);
+ expect(output).not.toMatch(/Failed to extract/);
+}
+
+describe.skipIf(!cachyos)('CachyOS Play command with a real payload', () => {
+ it('runs the runtime Proton session, deploys the requested component and keeps the managed prefix', async () => {
+ const { compatibilityDataPath, runner, wrapper, stdout, output } = await session(cachyos!, 'PROTON_USE_OPTISCALER=1 %command%');
+ const environment = environmentOf(stdout);
+ expect(wrapper.command).not.toBe(runner.launchCommand);
+ expect(environment.get('WINEPREFIX')?.replace(/\/$/, '')).toBe(path.join(compatibilityDataPath, 'pfx'));
+ expect(output).toContain('Setting up optiscaler version');
+ expect(environment.get('WINE_OPTISCALER_NAME')).toBe('dxgi.dll');
+ expect(output).not.toContain('umu.exe');
+ // The hook variable alone is not success: the payload must really be installed.
+ expectNoIntegrityFailure(output);
+ const files = await deployedPayload(compatibilityDataPath);
+ for (const name of ['OptiScaler.dll', 'OptiScaler.ini', 'fakenvapi.dll']) {
+ expect(files[name], `${name} must be deployed`).toBeDefined();
+ expect(files[name].size).toBeGreaterThan(0);
+ }
+ expect(files['OptiScaler.dll'].magic).toBe('MZ');
+ }, 900_000);
+
+ it('starts the same game without the optional component when the option is absent', async () => {
+ const { compatibilityDataPath, stdout, output } = await session(cachyos!, '%command%');
+ const environment = environmentOf(stdout);
+ expect(environment.get('WINEPREFIX')?.replace(/\/$/, '')).toBe(path.join(compatibilityDataPath, 'pfx'));
+ expect(environment.has('WINE_OPTISCALER_NAME')).toBe(false);
+ expect(output).not.toContain('Setting up optiscaler version');
+ expect(await deployedPayload(compatibilityDataPath)).toEqual({});
+ }, 900_000);
+
+ it('reports the optional component honestly before the first launch', async () => {
+ const root = await mkdtemp(path.join(tmpdir(), 'nexus-proton-session-')); created.push(root);
+ const notices = await protonOptionalComponentNotices(
+ { PROTON_USE_OPTISCALER: '1' }, path.join(cachyos!, ''), path.join(root, 'compat'), true);
+ expect(notices).toHaveLength(1);
+ expect(notices[0]).not.toMatch(/will be downloaded|is active|verified/i);
+ expect(notices[0]).toContain('offline');
+ }, 900_000);
+
+ it('preserves the Nexus overlay component across a second Proton session', async () => {
+ const first = await session(cachyos!, 'PROTON_USE_OPTISCALER=1 %command%');
+ const overlay = path.join(first.compatibilityDataPath, 'pfx/drive_c/windows/system32/windows.web.dll');
+ await copyFile(path.join(cachyos!, 'files/lib/wine/x86_64-windows/windows.web.dll'), overlay);
+ const digest = createHash('sha256').update(await readFile(overlay)).digest('hex');
+ const second = await session(cachyos!, 'PROTON_USE_OPTISCALER=1 %command%', first.root);
+ expect(second.compatibilityDataPath).toBe(first.compatibilityDataPath);
+ expect(createHash('sha256').update(await readFile(overlay)).digest('hex')).toBe(digest);
+ expect(environmentOf(second.stdout).get('WINE_OPTISCALER_NAME')).toBe('dxgi.dll');
+ expectNoIntegrityFailure(second.output);
+ }, 1_800_000);
+
+ it('starts an absolute Unix executable with spaces and quoted arguments through the Proton session', async () => {
+ const { root, runner, wrapper } = await session(cachyos!, '%command%');
+ const directory = path.join(root, 'game dir with spaces');
+ await mkdir(directory, { recursive: true });
+ const executable = path.join(directory, 'game cmd.exe');
+ await copyFile(path.join(cachyos!, 'files/lib/wine/x86_64-windows/cmd.exe'), executable);
+ const childEnvironment = {
+ ...process.env,
+ HOME: path.join(root, 'home'),
+ XDG_CACHE_HOME: fixtureCache ?? path.join(root, 'cache'),
+ WINEPREFIX: '/wrong/prefix',
+ UMU_ID: 'stale-umu',
+ };
+ // The backend always passes an absolute Unix executable path; Proton must
+ // still start the runtime Wine, not umu.exe or steam.exe, and keep argv.
+ const { stdout, stderr } = await execFile(wrapper.command,
+ [executable, '/c', 'echo', 'alpha', '"beta gamma"', 'delta'],
+ { env: childEnvironment, maxBuffer: 8 * 1024 * 1024, timeout: 900_000 });
+ // Wine's cmd re-quotes the echoed remainder, so the space-preserving
+ // argument is asserted by content: a split would yield "beta" and "gamma"
+ // as separate tokens, and the executable would never have started at all if
+ // the route had fallen back to umu.exe or steam.exe.
+ expect(stdout).toContain('alpha');
+ expect(stdout).toContain('beta gamma');
+ expect(stdout.trimEnd().endsWith('delta')).toBe(true);
+ expect(`${stdout}${stderr}`).not.toContain('umu.exe');
+ // Stop keeps using the exact bare runtime Wine command captured at launch.
+ expect(runner.stopPrefix.command).toBe(runner.command);
+ const stopScript = await readFile(runner.command, 'utf8');
+ const launchScript = await readFile(runner.launchCommand, 'utf8');
+ expect(stopScript).toContain('--nexus-stop-prefix');
+ expect(stopScript).not.toContain(' run "$@"');
+ expect(launchScript).toContain(' run "$@"');
+ // wineserver -k exits 1 when no server is running; that is its own idle
+ // status, not a launcher failure, so both codes are accepted here.
+ const stopped = await execFile(runner.stopPrefix.command, runner.stopPrefix.args,
+ { env: childEnvironment, timeout: 120_000 }).catch((error: { code?: number }) => ({ code: error.code }));
+ expect([0, 1]).toContain((stopped as { code?: number }).code ?? 0);
+ }, 1_800_000);
+});
+
+describe.skipIf(!standard)('Standard Play command with a real payload', () => {
+ it('runs the runtime Proton session without the CachyOS upscaler hook', async () => {
+ const { compatibilityDataPath, stdout } = await session(standard!, 'PROTON_USE_OPTISCALER=1 %command%');
+ const environment = environmentOf(stdout);
+ expect(environment.get('WINEPREFIX')?.replace(/\/$/, '')).toBe(path.join(compatibilityDataPath, 'pfx'));
+ expect(environment.has('WINE_OPTISCALER_NAME')).toBe(false);
+ expect(await deployedPayload(compatibilityDataPath)).toEqual({});
+ }, 900_000);
+});
diff --git a/src/main/proton.test.ts b/src/main/proton.test.ts
index 0873f1b..86e5374 100644
--- a/src/main/proton.test.ts
+++ b/src/main/proton.test.ts
@@ -5,9 +5,9 @@ import { tmpdir } from 'node:os';
import path from 'node:path';
import { promisify } from 'node:util';
import { afterEach, describe, expect, it } from 'vitest';
-import { fexEnvironment, managedUnrealCultureGameIni, prefixUserLocale, prepareProtonRunner, syncPrefixUserLocale, syncUnrealCultureGameIni } from './proton.js';
+import { fexEnvironment, managedUnrealCultureGameIni, prefixUserLocale, prepareProtonRunner, protonOptionalComponentNotices, syncPrefixUserLocale, syncUnrealCultureGameIni } from './proton.js';
import { prepareGameWrapper } from './game-wrapper.js';
-import { defaultLaunchTools } from '../shared/launch-tools.js';
+import { defaultLaunchTools, parseLaunchOptions } from '../shared/launch-tools.js';
import { preparedGameWine } from './game-launch.js';
const created: string[] = [];
@@ -131,32 +131,45 @@ describe('prepareProtonRunner', () => {
await expect(prepareProtonRunner(wine, compat, path.join(root, 'steam'))).rejects.toThrow('dxgi.dll checksum');
for (const name of modules) expect(await readFile(path.join(system32, name), 'utf8')).toBe(`previous ${name}`);
});
- it.each([false, true])('keeps the prefix and applies game tools only to Play (tools enabled: %s)', async (withTools) => {
+ it.each([false, true])('routes Play through the Proton session and wraps that command with game tools (tools enabled: %s)', async (withTools) => {
const root=await mkdtemp(path.join(tmpdir(),'nexus-proton-game-tools-')); created.push(root);
const runtime=path.join(root,"runtime's directory"), wine=path.join(runtime,'files/bin/wine'), compat=path.join(root,'compat');
await mkdir(path.dirname(wine),{recursive:true}); await mkdir(path.join(runtime,'files/share/default_pfx'),{recursive:true});
const system32=path.join(compat,'pfx/drive_c/windows/system32'); await mkdir(system32,{recursive:true});
for(const name of ['libvkd3d-utils-1.dll','dxgi.dll','d3d12.dll']) await writeFile(path.join(system32,name),'ready');
await writeFile(path.join(system32,'wined3d.dll'),'unmanaged shader module');
- await writeFile(path.join(runtime,'proton'),'#!/bin/sh\nexit 0\n'); await chmod(path.join(runtime,'proton'),0o700);
- await writeFile(wine,'#!/bin/sh\nprintf "%s\\n" "$WINEDLLOVERRIDES" "$DXVK_HUD" "$WINEPREFIX" "$ESPEAK_DATA_PATH"; printf "<%s>\\n" "$@"; printf "<controller:%s:%s>\\n" "$PROTON_DISABLE_HIDRAW" "$SteamGameId"\n'); await chmod(wine,0o700);
+ // The fixture Proton session starts the target exactly like the real script:
+ // wine plus the remaining argv, with the session environment inherited.
+ await writeFile(path.join(runtime,'proton'),`#!/bin/sh\n[ "$1" = run ] && shift\nexec '${wine.replaceAll("'",`'"'"'`)}' "$@"\n`); await chmod(path.join(runtime,'proton'),0o700);
+ await writeFile(wine,'#!/bin/sh\nprintf "%s\\n" "$WINEDLLOVERRIDES" "$DXVK_HUD" "$WINEPREFIX" "$ESPEAK_DATA_PATH"; printf "<%s>\\n" "$@"; printf "<controller:%s:%s>\\n" "$PROTON_DISABLE_HIDRAW" "$SteamGameId"; printf "steam-context:%s\\n" "${UMU_ID-unset}"\n'); await chmod(wine,0o700);
await writeFile(path.join(runtime,'files/bin/wineserver'),'#!/bin/sh\nexit 0\n'); await chmod(path.join(runtime,'files/bin/wineserver'),0o700);
- const wrapper=await prepareGameWrapper(wine,withTools ? {...defaultLaunchTools,launchOptions:'WINEDLLOVERRIDES="dxgi=n,b;winhttp=b" DXVK_HUD=fps %command% --launcher-skip'} : undefined,path.join(root,'wrappers'));
- const runner=(await prepareProtonRunner(wine,compat,path.join(root,'steam'),wrapper.command))!;
+ const runner=(await prepareProtonRunner(wine,compat,path.join(root,'steam')))!;
expect(await readFile(path.join(system32,'wined3d.dll'),'utf8')).toBe('unmanaged shader module');
+ // Play always goes through the runtime's Proton session; the game tools and
+ // the %command% launch options wrap that command, like Steam does.
+ expect(runner.launchCommand).toBe(path.join(compat,'xodus-proton-game'));
+ const launchScript=await readFile(runner.launchCommand,'utf8');
+ const quotedProton=`'${path.join(runtime,'proton').replaceAll("'",`'"'"'`)}'`;
+ expect(launchScript).toContain(`${quotedProton} run "$@"`);
+ expect(launchScript).toContain(`export STEAM_COMPAT_DATA_PATH='${compat}'`);
+ expect(launchScript).toContain("export UMU_ID='xodus-nexus'");
+ expect(launchScript).toContain('nexus_game_command="Z:$1"');
+ // Internal prefix operations and Stop keep the bare Wine command.
const setup=await execFile(runner.command,['setup']);
expect(setup.stdout).not.toContain('fps'); expect(setup.stdout).not.toContain('--launcher-skip');
expect(setup.stdout.split('\n')).toContain(path.join(runtime,'files/share'));
- const game=await execFile(preparedGameWine(runner, wrapper.command),['actual game.exe'], { env: { ...process.env, WINEPREFIX: '', ESPEAK_DATA_PATH: '/wrong/host/data', PROTON_DISABLE_HIDRAW: '0x054c/0x0ce6', SteamGameId: '16968485195965530112' } });
+ const wrapper=await prepareGameWrapper(runner.launchCommand,withTools ? {...defaultLaunchTools,launchOptions:'WINEDLLOVERRIDES="dxgi=n,b;winhttp=b" DXVK_HUD=fps %command% --launcher-skip'} : undefined,path.join(root,'wrappers'));
+ const game=await execFile(wrapper.command,['actual game.exe'], { env: { ...process.env, WINEPREFIX: '', ESPEAK_DATA_PATH: '/wrong/host/data', PROTON_DISABLE_HIDRAW: '0x054c/0x0ce6', SteamGameId: '16968485195965530112', UMU_ID: 'stale-steam-context' } });
expect(game.stdout).toContain(path.join(compat,'pfx'));
expect(game.stdout.split('\n')).toContain(path.join(runtime,'files/share'));
expect(game.stdout).not.toContain('/wrong/host/data');
+ expect(game.stdout).toContain('steam-context:xodus-nexus');
expect(game.stdout).toContain('<controller:0x054c/0x0ce6:16968485195965530112>');
if (withTools) {
expect(game.stdout).toContain(`dxgi=n,b;winhttp=b\nfps\n${path.join(compat,'pfx')}`);
expect(game.stdout).toContain('<actual game.exe>\n<--launcher-skip>');
} else {
- expect(runner.launchCommand).toBeUndefined();
+ expect(wrapper.command).toBe(runner.launchCommand);
expect(game.stdout).toContain('<actual game.exe>');
expect(game.stdout).not.toContain('fps');
}
@@ -639,3 +652,63 @@ describe('managedUnrealCultureGameIni', () => {
expect(untouched.manual).toBe(true);
});
});
+
+describe('protonOptionalComponentNotices', () => {
+ async function runtime(root: string, capable: boolean): Promise<string> {
+ const protonRoot = path.join(root, 'runtime');
+ await mkdir(path.join(protonRoot, 'files/share/default_pfx'), { recursive: true });
+ if (capable) {
+ await mkdir(path.join(protonRoot, 'protonfixes'), { recursive: true });
+ await writeFile(path.join(protonRoot, 'protonfixes/upscalers.py'), '# fixture integration\n');
+ }
+ return protonRoot;
+ }
+ const compat = (root: string) => path.join(root, 'compat');
+
+ it('reports an already prepared optional component without claiming a download', async () => {
+ const root = await mkdtemp(path.join(tmpdir(), 'nexus-proton-component-')); created.push(root);
+ const protonRoot = await runtime(root, true);
+ await mkdir(path.join(compat(root), 'pfx/drive_c/windows/system32/umu'), { recursive: true });
+ await writeFile(path.join(compat(root), 'pfx/drive_c/windows/system32/umu/OptiScaler.dll'), 'payload');
+ const notices = await protonOptionalComponentNotices({ PROTON_USE_OPTISCALER: '1' }, protonRoot, compat(root), false);
+ expect(notices).toEqual(['OptiScaler files are present in this Proton prefix; the runtime verifies them at launch.']);
+ });
+
+ it('states honestly that an offline first launch leaves the component inactive', async () => {
+ const root = await mkdtemp(path.join(tmpdir(), 'nexus-proton-component-')); created.push(root);
+ const protonRoot = await runtime(root, true);
+ const notices = await protonOptionalComponentNotices({ PROTON_USE_OPTISCALER: '1' }, protonRoot, compat(root), true);
+ expect(notices).toHaveLength(1);
+ expect(notices[0]).toContain('files are not present in this Proton prefix yet');
+ expect(notices[0]).toContain('can only use an already downloaded component');
+ expect(notices[0]).toContain('stays inactive');
+ });
+
+ it('explains the first-use download on an online launch and keeps the game start honest', async () => {
+ const root = await mkdtemp(path.join(tmpdir(), 'nexus-proton-component-')); created.push(root);
+ const protonRoot = await runtime(root, true);
+ const notices = await protonOptionalComponentNotices({ PROTON_USE_OPTISCALER: '1' }, protonRoot, compat(root), false);
+ expect(notices).toHaveLength(1);
+ expect(notices[0]).toContain('prepared by the CachyOS Proton session on first use');
+ expect(notices[0]).toContain('the game still starts without OptiScaler');
+ });
+
+ it('is driven by the parsed launch options of the game', async () => {
+ const root = await mkdtemp(path.join(tmpdir(), 'nexus-proton-component-')); created.push(root);
+ const protonRoot = await runtime(root, true);
+ const environment = parseLaunchOptions('PROTON_USE_OPTISCALER=1 %command%').environment;
+ const notices = await protonOptionalComponentNotices(environment, protonRoot, compat(root), false);
+ expect(notices).toHaveLength(1);
+ expect(notices[0]).toContain('OptiScaler');
+ });
+
+ it('stays silent without the option, for a disabled value and for runtimes without the integration', async () => {
+ const root = await mkdtemp(path.join(tmpdir(), 'nexus-proton-component-')); created.push(root);
+ const capable = await runtime(root, true);
+ expect(await protonOptionalComponentNotices({}, capable, compat(root), false)).toEqual([]);
+ expect(await protonOptionalComponentNotices({ PROTON_USE_OPTISCALER: '0' }, capable, compat(root), false)).toEqual([]);
+ expect(await protonOptionalComponentNotices({ PROTON_USE_OPTISCALER: '' }, capable, compat(root), false)).toEqual([]);
+ const plain = await runtime(path.join(root, 'plain'), false);
+ expect(await protonOptionalComponentNotices({ PROTON_USE_OPTISCALER: '1' }, plain, path.join(root, 'plain', 'compat'), false)).toEqual([]);
+ });
+});
diff --git a/src/main/proton.ts b/src/main/proton.ts
index db6058c..4557415 100644
--- a/src/main/proton.ts
+++ b/src/main/proton.ts
@@ -16,11 +16,54 @@ function shellQuote(value: string): string {
export interface ProtonRunner {
command: string;
- launchCommand?: string;
+ launchCommand: string;
compatibilityDataPath: string;
+ protonRoot: string;
stopPrefix: { command: string; args: string[] };
}
+// Optional Proton components (CachyOS) are prepared by the runtime's own
+// `proton` session, which downloads them on first use from the public
+// proton-upscalers component index. The launcher must say so honestly instead of
+// implying they are always present.
+const PROTON_OPTIONAL_COMPONENTS = [
+ { environment: 'PROTON_USE_OPTISCALER', label: 'OptiScaler', payload: 'drive_c/windows/system32/umu/OptiScaler.dll' },
+] as const;
+
+function protonComponentEnabled(value: string | undefined): boolean {
+ return value !== undefined && value.trim() !== '' && value.trim() !== '0';
+}
+
+/**
+ * Reports how a launch option that asks for an optional Proton component will be
+ * served. The CachyOS Proton session deploys the payload into the managed prefix
+ * and exports WINE_OPTISCALER_NAME; without the payload (for example an offline
+ * first launch) the game still starts and the component stays inactive.
+ * Nothing is claimed for runtimes that do not ship the upscaler integration.
+ */
+export async function protonOptionalComponentNotices(
+ environment: NodeJS.ProcessEnv | Record<string, string | undefined>,
+ protonRoot: string,
+ compatibilityDataPath: string,
+ offline: boolean,
+): Promise<string[]> {
+ let capable = true;
+ try { await fs.access(path.join(protonRoot, 'protonfixes', 'upscalers.py'), constants.R_OK); }
+ catch { capable = false; }
+ if (!capable) return [];
+ const notices: string[] = [];
+ for (const component of PROTON_OPTIONAL_COMPONENTS) {
+ if (!protonComponentEnabled(environment[component.environment])) continue;
+ let prepared = true;
+ try { await fs.access(path.join(compatibilityDataPath, 'pfx', component.payload), constants.R_OK); }
+ catch { prepared = false; }
+ if (prepared) notices.push(`${component.label} files are present in this Proton prefix; the runtime verifies them at launch.`);
+ else if (offline) notices.push(`${component.label} files are not present in this Proton prefix yet. This launch is offline, so it can only use an already downloaded component; without one ${component.label} stays inactive.`);
+ else notices.push(`${component.label} files are prepared by the CachyOS Proton session on first use. If that download fails, the game still starts without ${component.label}.`);
+ }
+ return notices;
+}
+
const REQUIRED_PREFIX_FILES = [
'drive_c/windows/system32/libvkd3d-utils-1.dll',
'drive_c/windows/system32/dxgi.dll',
@@ -393,7 +436,6 @@ export async function prepareProtonRunner(
winePath: string,
compatibilityDataPath: string,
steamRoot: string,
- gameWineCommand = winePath,
shaderCacheLimitGiB = DEFAULT_SHADER_CACHE_GIB,
): Promise<ProtonRunner | undefined> {
const cacheLimits = shaderCacheLimits(shaderCacheLimitGiB);
@@ -507,8 +549,11 @@ export async function prepareProtonRunner(
'fi',
];
const runner = path.join(compatibilityDataPath, 'xodus-proton-wine');
- const temporary = `${runner}.tmp-${process.pid}`;
- const makeScript = (launchWine: string) => [
+ const launchScript = path.join(compatibilityDataPath, 'xodus-proton-game');
+ const wineOverrides = `dxgi=n;d3d11=n;d3d10core=n;d3d9=n;d3d12=n;d3d12core=n${http2Runtime ? ';winhttp=b;libnghttp2=n' : ''}${dxvkRuntime ? ';d3d8=n' : ''}`;
+ // Play keeps the user's launch-option value for these two managed settings,
+ // exactly like the previous layering where the game wrapper sat below Wine.
+ const sharedScript = (launchLines: string[], extraExports: string[] = [], overridable = false) => [
'#!/bin/sh',
`export WINEPREFIX=${shellQuote(path.join(compatibilityDataPath, 'pfx'))}`,
"export WINEARCH='win64'",
@@ -525,8 +570,9 @@ export async function prepareProtonRunner(
`export MEDIACONV_BLANK_VIDEO_FILE=${shellQuote(path.join(files, 'share', 'media', 'blank.mkv'))}`,
`export MEDIACONV_BLANK_AUDIO_FILE=${shellQuote(path.join(files, 'share', 'media', 'blank.ptna'))}`,
`export PATH=${shellQuote(executablePath)}`,
- `export WINEDLLOVERRIDES='dxgi=n;d3d11=n;d3d10core=n;d3d9=n;d3d12=n;d3d12core=n${http2Runtime ? ';winhttp=b;libnghttp2=n' : ''}${dxvkRuntime ? ';d3d8=n' : ''}'`,
- "export WINE_LARGE_ADDRESS_AWARE='1'",
+ ...(overridable
+ ? [...defaultEnvironment('WINEDLLOVERRIDES', wineOverrides), ...defaultEnvironment('WINE_LARGE_ADDRESS_AWARE', '1')]
+ : [`export WINEDLLOVERRIDES=${shellQuote(wineOverrides)}`, "export WINE_LARGE_ADDRESS_AWARE='1'"]),
// Preserve each explicit setting, including disabled/empty values. Limits
// apply only when selecting our managed driver directory, not a custom one.
...defaultEnvironment('VKD3D_SHADER_CACHE_PATH', shaderCaches.vkd3d),
@@ -551,31 +597,53 @@ export async function prepareProtonRunner(
'if [ "${1:-}" = "--nexus-stop-prefix" ]; then',
` exec ${shellQuote(wineserver)} -k`,
'fi',
+ // FEX inspects the first .exe argument as a host path, so it runs before the
+ // Play command rewrites a Unix executable into the prefix Z: form below.
...fexEnvironment(path.join(compatibilityDataPath, 'proton-fex-config.json'), path.join(files, 'lib', 'wine', 'i386-windows', 'xgameruntime.dll')),
+ ...extraExports,
// Launchers (including EAC) may finish before the game they spawned.
// Keep Xodus and its temporary launch view/account service alive until
// the isolated game prefix has no remaining Wine processes.
`if [ ! -x ${shellQuote(wineserver)} ]; then`,
- ` exec ${shellQuote(launchWine)} "$@"`,
+ ...launchLines.map((line) => ` exec ${line}`),
'fi',
'launch_status=0',
- `${shellQuote(launchWine)} "$@" || launch_status=$?`,
+ ...launchLines.map((line) => `${line} || launch_status=$?`),
'wait_status=0',
`${shellQuote(wineserver)} -w || wait_status=$?`,
'if [ "$launch_status" -ne 0 ]; then exit "$launch_status"; fi',
'exit "$wait_status"',
'',
].join('\n');
- await fs.writeFile(temporary, makeScript(winePath), { mode: 0o700 });
+ // Internal prefix operations and Stop keep using the runtime's Wine directly.
+ const temporary = `${runner}.tmp-${process.pid}`;
+ await fs.writeFile(temporary, sharedScript([`${shellQuote(winePath)} "$@"`]), { mode: 0o700 });
await fs.rename(temporary, runner);
await fs.chmod(runner, 0o700);
- let launchCommand: string | undefined;
- if (gameWineCommand !== winePath) {
- launchCommand = path.join(compatibilityDataPath, 'xodus-proton-game');
- const temporaryLaunch = `${launchCommand}.tmp-${process.pid}`;
- await fs.writeFile(temporaryLaunch, makeScript(gameWineCommand), { mode: 0o700 });
- await fs.rename(temporaryLaunch, launchCommand);
- await fs.chmod(launchCommand, 0o700);
- }
- return { command: runner, ...(launchCommand ? { launchCommand } : {}), compatibilityDataPath, stopPrefix: { command: runner, args: ['--nexus-stop-prefix'] } };
+ // Play goes through the runtime's Proton session so its per-launch setup runs:
+ // Proton derives the prefix from STEAM_COMPAT_DATA_PATH (the same managed
+ // prefix), applies its environment and protonfixes, and processes the Proton
+ // launch options of that runtime, for example PROTON_USE_OPTISCALER, before it
+ // starts the game. Launch options still arrive in this process environment.
+ const temporaryLaunch = `${launchScript}.tmp-${process.pid}`;
+ await fs.writeFile(temporaryLaunch, sharedScript([`${shellQuote(proton)} run "$@"`], [
+ `export STEAM_COMPAT_DATA_PATH=${shellQuote(compatibilityDataPath)}`,
+ `export STEAM_COMPAT_CLIENT_INSTALL_PATH=${shellQuote(steamRoot)}`,
+ // Proton's session selects its launch route from UMU_ID, UMU_USE_STEAM and
+ // whether the executable argument is a Unix path: with UMU_ID unset it runs
+ // steam.exe, and a leading "/" selects umu.exe. Nexus starts the runtime's own
+ // Wine with the command the backend prepared, so pin the plain-Wine route.
+ "export UMU_ID='xodus-nexus'",
+ "export UMU_USE_STEAM='0'",
+ 'case "${1:-}" in',
+ ' /*)',
+ ' nexus_game_command="Z:$1"',
+ ' shift',
+ ' set -- "$nexus_game_command" "$@"',
+ ' ;;',
+ 'esac',
+ ], true), { mode: 0o700 });
+ await fs.rename(temporaryLaunch, launchScript);
+ await fs.chmod(launchScript, 0o700);
+ return { command: runner, launchCommand: launchScript, compatibilityDataPath, protonRoot, stopPrefix: { command: runner, args: ['--nexus-stop-prefix'] } };
}
diff --git a/src/shared/launch-tools.test.ts b/src/shared/launch-tools.test.ts
index 3fb1c37..cd5a143 100644
--- a/src/shared/launch-tools.test.ts
+++ b/src/shared/launch-tools.test.ts
@@ -34,3 +34,18 @@ it('keeps older controller settings intact and validates the optional DualShock
expect(normalizeLaunchTools(defaultLaunchTools).dualShock4Compatibility).toBeUndefined();
expect(()=>normalizeLaunchTools({...defaultLaunchTools,dualShock4Compatibility:'yes'})).toThrow('DualShock 4');
});
+
+it('places the Proton optional component options before %command% as plain environment assignments', () => {
+ // The exact form a Proton user writes for CachyOS OptiScaler: environment
+ // assignments, %command% as its own word, and nothing after it.
+ expect(parseLaunchOptions('PROTON_USE_OPTISCALER=1 %command%')).toEqual({
+ environment: { PROTON_USE_OPTISCALER: '1' }, prefix: [], gameArgs: [],
+ });
+ // The assignment is only accepted before %command%; a bare argument keeps its
+ // position as a game argument instead of silently becoming an environment entry.
+ expect(parseLaunchOptions('%command% PROTON_USE_OPTISCALER=1')).toEqual({
+ environment: {}, prefix: [], gameArgs: ['PROTON_USE_OPTISCALER=1'],
+ });
+ expect(normalizeLaunchTools({ ...defaultLaunchTools, launchOptions: ' PROTON_USE_OPTISCALER=1 %command% ' }).launchOptions)
+ .toBe('PROTON_USE_OPTISCALER=1 %command%');
+});