diff --git a/Source/RP0/Harmony/Strategy.cs b/Source/RP0/Harmony/Strategy.cs index 389227d4cc2..5771c95c153 100644 --- a/Source/RP0/Harmony/Strategy.cs +++ b/Source/RP0/Harmony/Strategy.cs @@ -2,6 +2,7 @@ using Strategies; using RP0.Programs; using KSP.Localization; +using KSP.UI.Screens; namespace RP0.Harmony { @@ -104,5 +105,30 @@ internal static bool Prefix_Deactivate(Strategy __instance, ref bool __result) } return true; } + + // Fix strategies getting deactivated in Editor due to Planetarium time not getting updated on reverts + [HarmonyPrefix] + [HarmonyPatch("Update")] + internal static bool Prefix_Update(Strategy __instance) + { + if (__instance.LongestDuration != 0d && + __instance.dateActivated + __instance.LongestDuration <= Planetarium.GetUniversalTime()) + { + __instance.SendStateMessage(Strategy.cacheAutoLOC_304909, __instance.MessageDeactivatedMaxTime(), + MessageSystemButton.MessageButtonColor.ORANGE, MessageSystemButton.ButtonIcons.ALERT); + __instance.Deactivate(); + return false; + } + + __instance.OnUpdate(); + + int i = 0; + for (int count = __instance.effects.Count; i < count; i++) + { + __instance.effects[i].Update(); + } + + return false; + } } } \ No newline at end of file