From d848fe6f170f4fb8eb17c38fa48413aee451e108 Mon Sep 17 00:00:00 2001 From: Lexi Date: Wed, 3 Jan 2024 19:22:31 -0500 Subject: [PATCH] Add a toggleable control range module --- .../Patches/PartComponentModule_CommandPatch.cs | 13 +++++++------ src/WMCCModules/WMCCModulesPlugin.cs | 8 ++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/WMCCModules/Patches/PartComponentModule_CommandPatch.cs b/src/WMCCModules/Patches/PartComponentModule_CommandPatch.cs index 818b187..cce1c79 100644 --- a/src/WMCCModules/Patches/PartComponentModule_CommandPatch.cs +++ b/src/WMCCModules/Patches/PartComponentModule_CommandPatch.cs @@ -10,13 +10,14 @@ namespace WMCCModules.Patches; public class PartComponentModule_CommandPatch { [HarmonyPatch(nameof(PartComponentModule_Command.UpdateControlStatus))] - [HarmonyPrefix] - public static bool UpdateControlStatus(PartComponentModule_Command __instance) + [HarmonyPostfix] + public static void UpdateControlStatus(PartComponentModule_Command __instance) { - if (!__instance.Part.Modules.TryGetValue(typeof(PartComponentModule_ControlRange), out var comp)) return true; + if (!WMCCModulesPlugin.Instance.EnableControlRange.Value) return; + if (!__instance.Part.Modules.TryGetValue(typeof(PartComponentModule_ControlRange), out var comp)) return; var mcr = comp as PartComponentModule_ControlRange; - if (mcr!.DataControlRange == null || mcr.DataControlRange.Controllable) return true; - __instance.dataCommand.controlStatus.SetValue(CommandControlState.NoCommNetConnection); - return false; + if (mcr!.DataControlRange == null || mcr.DataControlRange.Controllable) return; + if (__instance.dataCommand.controlStatus.GetValue() == CommandControlState.FullyFunctional) + __instance.dataCommand.controlStatus.SetValue(CommandControlState.Hibernating); } } \ No newline at end of file diff --git a/src/WMCCModules/WMCCModulesPlugin.cs b/src/WMCCModules/WMCCModulesPlugin.cs index 64ddcdc..bffa327 100644 --- a/src/WMCCModules/WMCCModulesPlugin.cs +++ b/src/WMCCModules/WMCCModulesPlugin.cs @@ -1,7 +1,9 @@ using BepInEx; +using BepInEx.Configuration; using HarmonyLib; using JetBrains.Annotations; using SpaceWarp; +using SpaceWarp.API.Configuration; using SpaceWarp.API.Mods; using WMCCModules.Patches; @@ -18,6 +20,12 @@ public class WMCCModulesPlugin : BaseSpaceWarpPlugin // Singleton instance of the plugin class [PublicAPI] public static WMCCModulesPlugin Instance { get; set; } + public ConfigValue EnableControlRange; + private void Start() + { + EnableControlRange = new ConfigValue(SWConfiguration.Bind("Module Settings", "Enable Control Range", true, + "Enable the control range module (what forces you to lose control in certain situations until you unlock a certain tech node)")); + } /// /// Runs when the mod is first initialized.