diff --git a/AutomaticShipSystems/EnhancementPatch.cs b/AutomaticShipSystems/EnhancementPatch.cs index 3a1d41c..d39bedc 100644 --- a/AutomaticShipSystems/EnhancementPatch.cs +++ b/AutomaticShipSystems/EnhancementPatch.cs @@ -1,14 +1,10 @@ using CG.Game; using CG.Ship.Modules; using Gameplay.Enhancements; -using Gameplay.Ship; using HarmonyLib; using Photon.Pun; using System; -using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; using VoidManager.Utilities; namespace AutomaticShipSystems @@ -26,7 +22,7 @@ namespace AutomaticShipSystems [HarmonyPatch("SetState")] static void SetState(Enhancement __instance, EnhancementState newState) { - if (!PhotonNetwork.IsMasterClient) return; + if (!PhotonNetwork.IsMasterClient || !VoidManagerPlugin.ModEnabled) return; if (Configs.TrimConfig.Value && ClientGame.Current?.PlayerShip?.GetModule()?.Engine?.GetComponentsInChildren()?.Contains(__instance) == true && @@ -38,7 +34,7 @@ namespace AutomaticShipSystems private static void ResetTrim(Enhancement trim) { - if (!PhotonNetwork.IsMasterClient || !Tools.PlayerShipExists) return; + if (!PhotonNetwork.IsMasterClient || !VoidManagerPlugin.ModEnabled || !Game.PlayerShipExists) return; if (trim.CurrentState.Value == EnhancementState.Inactive) { @@ -48,7 +44,7 @@ namespace AutomaticShipSystems internal static void ToggleAutomaticTrims(object sender, EventArgs e) { - if (!PhotonNetwork.IsMasterClient) return; + if (!PhotonNetwork.IsMasterClient || !VoidManagerPlugin.ModEnabled) return; Enhancement[] trims = ClientGame.Current?.PlayerShip?.GetModule()?.Engine?.GetComponentsInChildren(); if (trims == null || trims.Length == 0) return; diff --git a/AutomaticShipSystems/PowerBreakerPatch.cs b/AutomaticShipSystems/PowerBreakerPatch.cs index 58cb712..22d0755 100644 --- a/AutomaticShipSystems/PowerBreakerPatch.cs +++ b/AutomaticShipSystems/PowerBreakerPatch.cs @@ -1,5 +1,5 @@ using CG.Game; -using Gameplay.PowerSystem; +using Gameplay.Power; using HarmonyLib; using Photon.Pun; using System; @@ -21,7 +21,7 @@ namespace AutomaticShipSystems [HarmonyPatch("OnPowerStateChange")] static void OnPowerStateChange(PowerBreaker __instance, bool isOn) { - if (!PhotonNetwork.IsMasterClient) return; + if (!PhotonNetwork.IsMasterClient || !VoidManagerPlugin.ModEnabled) return; if (!isOn && Configs.CircuitBreakerConfig.Value) { @@ -31,14 +31,14 @@ namespace AutomaticShipSystems private static void ResetCircuitBreakers(PowerBreaker breaker) { - if (!PhotonNetwork.IsMasterClient || !Tools.PlayerShipExists) return; + if (!PhotonNetwork.IsMasterClient || !VoidManagerPlugin.ModEnabled || !Game.PlayerShipExists) return; breaker.IsOn.RequestChange(true); } internal static void ToggleAutomaticBreakers(object sender, EventArgs e) { - if (!PhotonNetwork.IsMasterClient) return; + if (!PhotonNetwork.IsMasterClient || !VoidManagerPlugin.ModEnabled) return; List breakers = ClientGame.Current?.PlayerShip?.GetComponentInChildren()?.Breakers; if (breakers == null) return; diff --git a/AutomaticShipSystems/ThrusterBoosterPatch.cs b/AutomaticShipSystems/ThrusterBoosterPatch.cs index feed4fb..eb6fce5 100644 --- a/AutomaticShipSystems/ThrusterBoosterPatch.cs +++ b/AutomaticShipSystems/ThrusterBoosterPatch.cs @@ -25,7 +25,7 @@ namespace AutomaticShipSystems [HarmonyPatch("ChangeState")] static void ChangeState(ThrusterBooster __instance, ThrusterBoosterState state) { - if (!PhotonNetwork.IsMasterClient) return; + if (!PhotonNetwork.IsMasterClient || !VoidManagerPlugin.ModEnabled) return; if (state == ThrusterBoosterState.Off && Configs.ThrusterBoosterConfig.Value) { @@ -35,9 +35,9 @@ namespace AutomaticShipSystems private static void ChargeThrusterBooster(ThrusterBooster booster) { - if (!PhotonNetwork.IsMasterClient || !Tools.PlayerShipExists) return; + if (!PhotonNetwork.IsMasterClient || !VoidManagerPlugin.ModEnabled || !Game.PlayerShipExists) return; - if (booster.state == ThrusterBoosterState.Off) + if (booster.State == ThrusterBoosterState.Off) { SetLeverPositionMethod.Invoke(booster.ChargeLever, new object[] { 1f }); } @@ -45,7 +45,7 @@ namespace AutomaticShipSystems internal static void ToggleAutomaticThrusterBoosters(object sender, EventArgs e) { - if (!PhotonNetwork.IsMasterClient) return; + if (!PhotonNetwork.IsMasterClient || !VoidManagerPlugin.ModEnabled) return; List boosters = ClientGame.Current.PlayerShip?.Transform?.GetComponent()?.ThrusterBoosters; if (boosters == null) return; @@ -54,7 +54,7 @@ namespace AutomaticShipSystems { foreach (ThrusterBooster booster in boosters) { - if (booster.state == ThrusterBoosterState.Off) + if (booster.State == ThrusterBoosterState.Off) { Tools.DelayDoUnique(booster, () => ChargeThrusterBooster(booster), Configs.ThrusterBoosterDelay); } diff --git a/AutomaticShipSystems/VoidManagerPlugin.cs b/AutomaticShipSystems/VoidManagerPlugin.cs index 5637cd2..1f27768 100644 --- a/AutomaticShipSystems/VoidManagerPlugin.cs +++ b/AutomaticShipSystems/VoidManagerPlugin.cs @@ -1,13 +1,14 @@ using Photon.Pun; +using VoidManager; using VoidManager.MPModChecks; namespace AutomaticShipSystems { - public class VoidManagerPlugin : VoidManager.VoidPlugin + public class VoidManagerPlugin : VoidPlugin { public VoidManagerPlugin() { - VoidManager.Events.Instance.MasterClientSwitched += (_, _) => { + Events.Instance.MasterClientSwitched += (_, _) => { if (PhotonNetwork.IsMasterClient) { PowerBreakerPatch.ToggleAutomaticBreakers(null, null); @@ -23,5 +24,28 @@ namespace AutomaticShipSystems public override string Description => MyPluginInfo.PLUGIN_DESCRIPTION; public override string ThunderstoreID => MyPluginInfo.PLUGIN_THUNDERSTORE_ID; + + public static bool ModEnabled = false; + + internal static void Enable() + { + ModEnabled = true; + VoidManager.Progression.ProgressionHandler.DisableProgression(MyPluginInfo.PLUGIN_GUID); + } + + public override SessionChangedReturn OnSessionChange(SessionChangedInput input) + { + switch(input.CallType) + { + case CallType.Joining: + ModEnabled = false; + break; + case CallType.SessionEscalated: + case CallType.HostStartSession: + Enable(); + return new SessionChangedReturn() { SetMod_Session = true}; + } + return base.OnSessionChange(input); + } } }