From 810854ad9329e3c57dfdedf4400110fde7ca7f14 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Thu, 23 Jul 2026 16:49:19 -0400 Subject: [PATCH 1/2] Keep config.yaml EmulatorJS defaults active after user setting changes EmulatorJS' preGetSetting short-circuits to the saved-settings localStorage object once any setting or control was changed, returning undefined for every key the user never touched. That silently dropped the config.yaml defaults passed via EJS_defaultOptions (webgl2Enabled, rewindEnabled, core options) while the settings menu still displayed them as active. Trap the EJS_emulator assignment and patch the instance so unsaved keys fall back to the defaults per-setting, then recompute the values the constructor captured before the patch could take effect. Co-Authored-By: Claude Fable 5 --- .../src/views/Player/EmulatorJS/Player.vue | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/frontend/src/views/Player/EmulatorJS/Player.vue b/frontend/src/views/Player/EmulatorJS/Player.vue index 71ba448f4..ab3ec46de 100644 --- a/frontend/src/views/Player/EmulatorJS/Player.vue +++ b/frontend/src/views/Player/EmulatorJS/Player.vue @@ -190,6 +190,51 @@ window.EJS_disableAutoUnload = EJS_DISABLE_AUTO_UNLOAD; window.EJS_disableBatchBootup = EJS_DISABLE_BATCH_BOOTUP; if (EJS_CACHE_LIMIT !== null) window.EJS_CacheLimit = EJS_CACHE_LIMIT; +// EmulatorJS' preGetSetting short-circuits to the saved-settings object once +// ANY setting or control was changed, returning undefined for every key the +// user never touched and silently dropping the config.yaml defaults passed +// via EJS_defaultOptions. Patch the instance so unsaved keys still fall back +// to the defaults, and recompute the values the constructor captured before +// the patch could take effect. +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function installDefaultOptionsFallback(emulator: any) { + if (emulator.__rommSettingsPatched) return; + emulator.__rommSettingsPatched = true; + + const originalPreGetSetting = emulator.preGetSetting.bind(emulator); + emulator.preGetSetting = (setting: string) => { + const value = originalPreGetSetting(setting); + if (value !== undefined && value !== null) return value; + const defaults = emulator.config?.defaultOptions ?? {}; + return defaults[setting] !== undefined ? defaults[setting] : null; + }; + + emulator.rewindEnabled = + emulator.preGetSetting("rewindEnabled") === "enabled"; + if (![0, 1, 2, 3].includes(emulator.config?.videoRotation)) { + emulator.videoRotation = emulator.preGetSetting("videoRotation") || 0; + } + const webgl2Setting = emulator.preGetSetting("webgl2Enabled"); + if (webgl2Setting === "disabled" || !emulator.supportsWebgl2) { + emulator.webgl2Enabled = false; + } else if (webgl2Setting === "enabled") { + emulator.webgl2Enabled = true; + } else { + emulator.webgl2Enabled = null; + } +} + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +let ejsEmulatorInstance: any; +Object.defineProperty(window, "EJS_emulator", { + configurable: true, + get: () => ejsEmulatorInstance, + set: (value) => { + ejsEmulatorInstance = value; + if (value) installDefaultOptionsFallback(value); + }, +}); + onMounted(() => { window.scrollTo(0, 0); if (props.bios) { From 6d5c4acf863f72d9c94986201fb7e592b7036461 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Thu, 23 Jul 2026 19:30:42 -0400 Subject: [PATCH 2/2] cleanup --- .../src/views/Player/EmulatorJS/Player.vue | 75 ++++++++----------- 1 file changed, 30 insertions(+), 45 deletions(-) diff --git a/frontend/src/views/Player/EmulatorJS/Player.vue b/frontend/src/views/Player/EmulatorJS/Player.vue index ab3ec46de..4fc50d727 100644 --- a/frontend/src/views/Player/EmulatorJS/Player.vue +++ b/frontend/src/views/Player/EmulatorJS/Player.vue @@ -190,51 +190,6 @@ window.EJS_disableAutoUnload = EJS_DISABLE_AUTO_UNLOAD; window.EJS_disableBatchBootup = EJS_DISABLE_BATCH_BOOTUP; if (EJS_CACHE_LIMIT !== null) window.EJS_CacheLimit = EJS_CACHE_LIMIT; -// EmulatorJS' preGetSetting short-circuits to the saved-settings object once -// ANY setting or control was changed, returning undefined for every key the -// user never touched and silently dropping the config.yaml defaults passed -// via EJS_defaultOptions. Patch the instance so unsaved keys still fall back -// to the defaults, and recompute the values the constructor captured before -// the patch could take effect. -// eslint-disable-next-line @typescript-eslint/no-explicit-any -function installDefaultOptionsFallback(emulator: any) { - if (emulator.__rommSettingsPatched) return; - emulator.__rommSettingsPatched = true; - - const originalPreGetSetting = emulator.preGetSetting.bind(emulator); - emulator.preGetSetting = (setting: string) => { - const value = originalPreGetSetting(setting); - if (value !== undefined && value !== null) return value; - const defaults = emulator.config?.defaultOptions ?? {}; - return defaults[setting] !== undefined ? defaults[setting] : null; - }; - - emulator.rewindEnabled = - emulator.preGetSetting("rewindEnabled") === "enabled"; - if (![0, 1, 2, 3].includes(emulator.config?.videoRotation)) { - emulator.videoRotation = emulator.preGetSetting("videoRotation") || 0; - } - const webgl2Setting = emulator.preGetSetting("webgl2Enabled"); - if (webgl2Setting === "disabled" || !emulator.supportsWebgl2) { - emulator.webgl2Enabled = false; - } else if (webgl2Setting === "enabled") { - emulator.webgl2Enabled = true; - } else { - emulator.webgl2Enabled = null; - } -} - -// eslint-disable-next-line @typescript-eslint/no-explicit-any -let ejsEmulatorInstance: any; -Object.defineProperty(window, "EJS_emulator", { - configurable: true, - get: () => ejsEmulatorInstance, - set: (value) => { - ejsEmulatorInstance = value; - if (value) installDefaultOptionsFallback(value); - }, -}); - onMounted(() => { window.scrollTo(0, 0); if (props.bios) { @@ -434,6 +389,36 @@ window.EJS_onGameStart = async () => { // emulator's own start hook keeps the flag true for any entry point. playing.value = true; + // Patch the instance so unsaved keys still fall back to config defaults. + const originalPreGetSetting = window.EJS_emulator?.preGetSetting.bind( + window.EJS_emulator, + ); + if (window.EJS_emulator) { + window.EJS_emulator.preGetSetting = (setting: string) => { + const value = originalPreGetSetting(setting); + if (value !== undefined && value !== null) return value; + const defaults = window.EJS_emulator.config?.defaultOptions ?? {}; + return defaults[setting] !== undefined ? defaults[setting] : null; + }; + + window.EJS_emulator.rewindEnabled = + window.EJS_emulator.preGetSetting("rewindEnabled") === "enabled"; + + if (![0, 1, 2, 3].includes(window.EJS_emulator.config?.videoRotation)) { + window.EJS_emulator.videoRotation = + window.EJS_emulator.preGetSetting("videoRotation") || 0; + } + + const webgl2Setting = window.EJS_emulator.preGetSetting("webgl2Enabled"); + if (webgl2Setting === "disabled" || !window.EJS_emulator.supportsWebgl2) { + window.EJS_emulator.webgl2Enabled = false; + } else if (webgl2Setting === "enabled") { + window.EJS_emulator.webgl2Enabled = true; + } else { + window.EJS_emulator.webgl2Enabled = null; + } + } + // Install netplay overrides synchronously, before any await below, so they // are in place before room polling or a Create/Join action can start. const netplay = window.EJS_emulator?.netplay;