From 6338e33eba7ef8f74412f9cf3555710c68574855 Mon Sep 17 00:00:00 2001 From: Lexi Date: Tue, 7 Nov 2023 08:34:22 -0500 Subject: [PATCH] Reset bindings for campaign configuration when returning to main menu --- SpaceWarp.Core/SpaceWarpPlugin.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/SpaceWarp.Core/SpaceWarpPlugin.cs b/SpaceWarp.Core/SpaceWarpPlugin.cs index 985c9ae..966fece 100644 --- a/SpaceWarp.Core/SpaceWarpPlugin.cs +++ b/SpaceWarp.Core/SpaceWarpPlugin.cs @@ -9,7 +9,9 @@ using HarmonyLib; using I2.Loc; using JetBrains.Annotations; +using KSP.Game; using KSP.IO; +using KSP.Messages; using KSP.ScriptInterop.impl.moonsharp; using MoonSharp.Interpreter; using MoonSharp.Interpreter.Interop; @@ -40,7 +42,8 @@ public sealed class SpaceWarpPlugin : BaseSpaceWarpPlugin internal ScriptEnvironment GlobalLuaState; internal new static ManualLogSource Logger; - + + public SpaceWarpPlugin() { // Load the type forwarders @@ -111,6 +114,20 @@ public override void OnInitialized() { ModuleManager.InitializeAllModules(); SetupLuaState(); + Game.Messages.Subscribe(typeof(GameStateEnteredMessage), ResetToDefaults, false, true); + } + + private void ResetToDefaults(MessageCenterMessage msg) + { + var stateChange = msg as GameStateEnteredMessage; + if (stateChange!.StateBeingEntered != GameState.MainMenu) return; + foreach (var plugin in PluginList.AllEnabledAndActivePlugins) + { + if (plugin.SaveConfigFile != null && plugin.SaveConfigFile.Sections.Count > 0) + { + plugin.SaveConfigFile.ResetToDefaults(); + } + } } public override void OnPostInitialized()