From dae2b3af0c8257c7595d50c0c6c97e76c6e4b3f1 Mon Sep 17 00:00:00 2001 From: ProfLander <1253239+ProfLander@users.noreply.github.com.> Date: Thu, 11 Sep 2025 07:53:29 +0100 Subject: [PATCH 1/2] Fix options menu MAVs on localization change --- gamedata/scripts/aaaa_script_fixes_mp.script | 49 ++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/gamedata/scripts/aaaa_script_fixes_mp.script b/gamedata/scripts/aaaa_script_fixes_mp.script index dc5d564ef..e63e6113f 100644 --- a/gamedata/scripts/aaaa_script_fixes_mp.script +++ b/gamedata/scripts/aaaa_script_fixes_mp.script @@ -615,3 +615,52 @@ end function smart_terrain.se_smart_terrain:task() return self.smart_alife_task end + +-- Lander: +-- Prevent ui_options.UIOptions from addressing self.owner (the main menu) +-- after localization reload. This causes MAVs, as the main menu gets xr_delete'd +-- and replaced with a fresh instance before option change callbacks finish running + +--- Localization reload flag +local loc_reloaded = false + +--- Patch `func_localization` to set the reload flag +local old_funct = ui_options.func_localization +function ui_options.func_localization(...) + loc_reloaded = true + return old_funct(...) +end + +--- Replace the copy emplaced in `ui_options.options` +local found_other = false +for _,group in ipairs(ui_options.options) do + if group.id == "other" then + found_other = true + local found_loc = false + for _,control in ipairs(group.gr) do + if control.id == "localization" then + found_loc = true + control.functor[1] = ui_options.func_localization + break + end + end + if not found_loc then + printf("~ Failed to monkey-patch ui_options functor: Missing 'localization' option") + end + break + end +end +if not found_other then + printf("~ Failed to monkey-patch ui_options functor: Missing 'other' group") +end + +--- Patch `UIOptions:On_Cancel` to reset the reload flag and early-return if it is set +local old_cancel = ui_options.UIOptions.On_Cancel +function ui_options.UIOptions.On_Cancel(self, ...) + if loc_reloaded then + loc_reloaded = false + self.owner = nil + else + return old_cancel(self, ...) + end +end From d44f3ba109d7aaeec892014be11d570af4a9cd12 Mon Sep 17 00:00:00 2001 From: ProfLander <1253239+ProfLander@users.noreply.github.com.> Date: Thu, 11 Sep 2025 19:04:15 +0100 Subject: [PATCH 2/2] Move options MAV fix to `_g_patches`, remove `ui_options.options` manipulation --- gamedata/scripts/_g_patches.script | 28 ++++++++++- gamedata/scripts/aaaa_script_fixes_mp.script | 49 -------------------- 2 files changed, 27 insertions(+), 50 deletions(-) diff --git a/gamedata/scripts/_g_patches.script b/gamedata/scripts/_g_patches.script index 00b759f97..274c244bb 100644 --- a/gamedata/scripts/_g_patches.script +++ b/gamedata/scripts/_g_patches.script @@ -690,4 +690,30 @@ _G.log = function(str) if DebuggerMode then LuaPanda.printToVSCode(str,1,2) end -end \ No newline at end of file +end + +-- Lander: +-- Prevent ui_options.UIOptions from addressing self.owner (the main menu) +-- after localization reload. This causes MAVs, as the main menu gets xr_delete'd +-- and replaced with a fresh instance before option change callbacks finish running. + +--- Localization reload flag +local loc_reloaded = false + +--- Patch `func_localization` to set the reload flag +local old_funct = ui_options.func_localization +function ui_options.func_localization(...) + loc_reloaded = true + return old_funct(...) +end + +--- Patch `UIOptions:On_Cancel` to reset the reload flag and early-return if it is set +local old_cancel = ui_options.UIOptions.On_Cancel +function ui_options.UIOptions.On_Cancel(self, ...) + if loc_reloaded then + loc_reloaded = false + self.owner = nil + else + return old_cancel(self, ...) + end +end diff --git a/gamedata/scripts/aaaa_script_fixes_mp.script b/gamedata/scripts/aaaa_script_fixes_mp.script index e63e6113f..dc5d564ef 100644 --- a/gamedata/scripts/aaaa_script_fixes_mp.script +++ b/gamedata/scripts/aaaa_script_fixes_mp.script @@ -615,52 +615,3 @@ end function smart_terrain.se_smart_terrain:task() return self.smart_alife_task end - --- Lander: --- Prevent ui_options.UIOptions from addressing self.owner (the main menu) --- after localization reload. This causes MAVs, as the main menu gets xr_delete'd --- and replaced with a fresh instance before option change callbacks finish running - ---- Localization reload flag -local loc_reloaded = false - ---- Patch `func_localization` to set the reload flag -local old_funct = ui_options.func_localization -function ui_options.func_localization(...) - loc_reloaded = true - return old_funct(...) -end - ---- Replace the copy emplaced in `ui_options.options` -local found_other = false -for _,group in ipairs(ui_options.options) do - if group.id == "other" then - found_other = true - local found_loc = false - for _,control in ipairs(group.gr) do - if control.id == "localization" then - found_loc = true - control.functor[1] = ui_options.func_localization - break - end - end - if not found_loc then - printf("~ Failed to monkey-patch ui_options functor: Missing 'localization' option") - end - break - end -end -if not found_other then - printf("~ Failed to monkey-patch ui_options functor: Missing 'other' group") -end - ---- Patch `UIOptions:On_Cancel` to reset the reload flag and early-return if it is set -local old_cancel = ui_options.UIOptions.On_Cancel -function ui_options.UIOptions.On_Cancel(self, ...) - if loc_reloaded then - loc_reloaded = false - self.owner = nil - else - return old_cancel(self, ...) - end -end