using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CG;
using CG.Client.Ship.Interactions;
using CG.Game;
using CG.Ship.Modules;
using CG.Space;
using Gameplay.Enhancements;
using Gameplay.Power;
using Gameplay.Ship;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using VoidManager;
using VoidManager.CustomGUI;
using VoidManager.MPModChecks;
using VoidManager.Progression;
using VoidManager.Utilities;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("AutomaticShipSystems")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.0.2.0")]
[assembly: AssemblyInformationalVersion("0.0.2+1c4dd32ea8cb3c0711f13f33afb4819fc6b71cbf")]
[assembly: AssemblyProduct("AutomaticShipSystems")]
[assembly: AssemblyTitle("Makes circuit breakers, thruster boosters, and trims self reset. Disables Progression.")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace AutomaticShipSystems
{
[BepInPlugin("18107.AutomaticShipSystems", "Automatic Ship Systems", "0.0.2")]
[BepInProcess("Void Crew.exe")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class BepinPlugin : BaseUnityPlugin
{
internal static ManualLogSource Log;
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
Configs.Load(this);
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "18107.AutomaticShipSystems");
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin 18107.AutomaticShipSystems is loaded!");
}
}
internal class Configs
{
internal static ConfigEntry<bool> CircuitBreakerConfig;
internal static ConfigEntry<bool> ThrusterBoosterConfig;
internal static ConfigEntry<bool> TrimConfig;
internal static ConfigEntry<double> CircuitBreakerDelay;
internal static ConfigEntry<double> ThrusterBoosterDelay;
internal static ConfigEntry<double> TrimDelay;
internal static void Load(BepinPlugin plugin)
{
CircuitBreakerConfig = ((BaseUnityPlugin)plugin).Config.Bind<bool>("AutomaticShipSystems", "CircuitBreakers", true, (ConfigDescription)null);
ThrusterBoosterConfig = ((BaseUnityPlugin)plugin).Config.Bind<bool>("AutomaticShipSystems", "ThrusterBooster", true, (ConfigDescription)null);
TrimConfig = ((BaseUnityPlugin)plugin).Config.Bind<bool>("AutomaticShipSystems", "Trim", true, (ConfigDescription)null);
CircuitBreakerDelay = ((BaseUnityPlugin)plugin).Config.Bind<double>("AutomaticShipSystems", "CircuitBreakersTimer", 30000.0, (ConfigDescription)null);
ThrusterBoosterDelay = ((BaseUnityPlugin)plugin).Config.Bind<double>("AutomaticShipSystems", "ThrusterBoosterTimer", 60000.0, (ConfigDescription)null);
TrimDelay = ((BaseUnityPlugin)plugin).Config.Bind<double>("AutomaticShipSystems", "TrimTimer", 300000.0, (ConfigDescription)null);
}
}
[HarmonyPatch(typeof(Enhancement))]
internal class EnhancementPatch
{
[HarmonyPrepare]
private static void HookEvents()
{
Configs.TrimConfig.SettingChanged += ToggleAutomaticTrims;
}
[HarmonyPostfix]
[HarmonyPatch("SetState")]
private static void SetState(Enhancement __instance, EnhancementState newState)
{
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Invalid comparison between Unknown and I4
if (!PhotonNetwork.IsMasterClient || !VoidManagerPlugin.ModEnabled || !Configs.TrimConfig.Value)
{
return;
}
ClientGame current = ClientGame.Current;
if (current == null)
{
return;
}
AbstractPlayerControlledShip playerShip = current.PlayerShip;
bool? obj;
if (playerShip == null)
{
obj = null;
}
else
{
Helm module = playerShip.GetModule<Helm>();
if (module == null)
{
obj = null;
}
else
{
ShipEngine engine = module.Engine;
obj = ((engine == null) ? null : ((Component)engine).GetComponentsInChildren<Enhancement>()?.Contains(__instance));
}
}
bool? flag = obj;
if (flag.GetValueOrDefault() && (int)newState == 0)
{
Tools.DelayDoUnique((object)__instance, (Action)delegate
{
ResetTrim(__instance);
}, Configs.TrimDelay.Value);
}
}
private static void ResetTrim(Enhancement trim)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Invalid comparison between Unknown and I4
if (PhotonNetwork.IsMasterClient && VoidManagerPlugin.ModEnabled && Game.PlayerShipExists && (int)((ChangeResponsive<EnhancementState>)(object)trim.CurrentState).Value == 0)
{
trim.RequestStateChange((EnhancementState)1, 1f);
}
}
internal static void ToggleAutomaticTrims(object sender, EventArgs e)
{
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Invalid comparison between Unknown and I4
if (!PhotonNetwork.IsMasterClient || !VoidManagerPlugin.ModEnabled)
{
return;
}
ClientGame current = ClientGame.Current;
object obj;
if (current == null)
{
obj = null;
}
else
{
AbstractPlayerControlledShip playerShip = current.PlayerShip;
if (playerShip == null)
{
obj = null;
}
else
{
Helm module = playerShip.GetModule<Helm>();
if (module == null)
{
obj = null;
}
else
{
ShipEngine engine = module.Engine;
obj = ((engine != null) ? ((Component)engine).GetComponentsInChildren<Enhancement>() : null);
}
}
}
Enhancement[] array = (Enhancement[])obj;
if (array == null || array.Length == 0)
{
return;
}
if (Configs.TrimConfig.Value)
{
Enhancement[] array2 = array;
foreach (Enhancement trim in array2)
{
if ((int)((ChangeResponsive<EnhancementState>)(object)trim.CurrentState).Value == 0)
{
Tools.DelayDoUnique((object)trim, (Action)delegate
{
ResetTrim(trim);
}, Configs.TrimDelay.Value);
}
}
}
else
{
Enhancement[] array3 = array;
foreach (Enhancement val in array3)
{
Tools.CancelDelayDoUnique((object)val);
}
}
}
}
internal class GUI : ModSettingsMenu
{
public override string Name()
{
return "Automatic Ship Systems";
}
public override void Draw()
{
GUILayout.Label("Timers in MS. 1000 is equal to 1 second.\n", Array.Empty<GUILayoutOption>());
GUITools.DrawCheckbox("Auto Circuit Breakers Enabled", ref Configs.CircuitBreakerConfig);
GUITools.DrawTextField<double>("Circut Breaker Timer", ref Configs.CircuitBreakerDelay, 80f);
GUILayout.Label(string.Empty, Array.Empty<GUILayoutOption>());
GUITools.DrawCheckbox("Auto Thruster Boosters Enabled", ref Configs.ThrusterBoosterConfig);
GUITools.DrawTextField<double>("Thruster Booster Timer", ref Configs.ThrusterBoosterDelay, 80f);
GUILayout.Label(string.Empty, Array.Empty<GUILayoutOption>());
GUITools.DrawCheckbox("Auto Trims Enabled", ref Configs.TrimConfig);
GUITools.DrawTextField<double>("Trim Timer", ref Configs.TrimDelay, 80f);
}
}
public class MyPluginInfo
{
public const string PLUGIN_GUID = "18107.AutomaticShipSystems";
public const string PLUGIN_NAME = "AutomaticShipSystems";
public const string USERS_PLUGIN_NAME = "Automatic Ship Systems";
public const string PLUGIN_VERSION = "0.0.2";
public const string PLUGIN_DESCRIPTION = "Makes circuit breakers, thruster boosters, and trims self reset. Disables Progression.";
public const string PLUGIN_ORIGINAL_AUTHOR = "18107";
public const string PLUGIN_AUTHORS = "18107, Dragon";
public const string PLUGIN_THUNDERSTORE_ID = "VoidCrewModdingTeam/Automatic_Ship_Systems";
}
[HarmonyPatch(typeof(PowerBreaker))]
internal class PowerBreakerPatch
{
[HarmonyPrepare]
private static void HookEvents()
{
Configs.CircuitBreakerConfig.SettingChanged += ToggleAutomaticBreakers;
}
[HarmonyPostfix]
[HarmonyPatch("OnPowerStateChange")]
private static void OnPowerStateChange(PowerBreaker __instance, bool isOn)
{
if (PhotonNetwork.IsMasterClient && VoidManagerPlugin.ModEnabled && !isOn && Configs.CircuitBreakerConfig.Value)
{
Tools.DelayDoUnique((object)__instance, (Action)delegate
{
ResetCircuitBreakers(__instance);
}, Configs.CircuitBreakerDelay.Value);
}
}
private static void ResetCircuitBreakers(PowerBreaker breaker)
{
if (PhotonNetwork.IsMasterClient && VoidManagerPlugin.ModEnabled && Game.PlayerShipExists)
{
((ChangeResponsive<bool>)(object)breaker.IsOn).RequestChange(true, false, (Action)null, (Action)null);
}
}
internal static void ToggleAutomaticBreakers(object sender, EventArgs e)
{
if (!PhotonNetwork.IsMasterClient || !VoidManagerPlugin.ModEnabled)
{
return;
}
ClientGame current = ClientGame.Current;
object obj;
if (current == null)
{
obj = null;
}
else
{
AbstractPlayerControlledShip playerShip = current.PlayerShip;
obj = ((playerShip == null) ? null : ((Component)playerShip).GetComponentInChildren<ProtectedPowerSystem>()?.Breakers);
}
List<PowerBreaker> list = (List<PowerBreaker>)obj;
if (list == null)
{
return;
}
if (Configs.CircuitBreakerConfig.Value)
{
foreach (PowerBreaker powerBreaker in list)
{
if (!((ChangeResponsive<bool>)(object)powerBreaker.IsOn).Value)
{
Tools.DelayDoUnique((object)powerBreaker, (Action)delegate
{
((ChangeResponsive<bool>)(object)powerBreaker.IsOn).RequestChange(true, false, (Action)null, (Action)null);
}, Configs.CircuitBreakerDelay.Value);
}
}
return;
}
foreach (PowerBreaker item in list)
{
Tools.CancelDelayDoUnique((object)item);
}
}
}
[HarmonyPatch(typeof(ThrusterBooster))]
internal class ThrusterBoosterPatch
{
private static readonly MethodInfo SetLeverPositionMethod = AccessTools.Method(typeof(Lever), "set_LeverPosition", (Type[])null, (Type[])null);
[HarmonyPrepare]
private static void HookEvents()
{
Configs.ThrusterBoosterConfig.SettingChanged += ToggleAutomaticThrusterBoosters;
}
[HarmonyPostfix]
[HarmonyPatch("ChangeState")]
private static void ChangeState(ThrusterBooster __instance, ThrusterBoosterState state)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
if (PhotonNetwork.IsMasterClient && VoidManagerPlugin.ModEnabled && (int)state == 0 && Configs.ThrusterBoosterConfig.Value)
{
Tools.DelayDoUnique((object)__instance, (Action)delegate
{
ChargeThrusterBooster(__instance);
}, Configs.ThrusterBoosterDelay.Value);
}
}
private static void ChargeThrusterBooster(ThrusterBooster booster)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Invalid comparison between Unknown and I4
if (PhotonNetwork.IsMasterClient && VoidManagerPlugin.ModEnabled && Game.PlayerShipExists && (int)booster.State == 0)
{
SetLeverPositionMethod.Invoke(booster.ChargeLever, new object[1] { 1f });
}
}
internal static void ToggleAutomaticThrusterBoosters(object sender, EventArgs e)
{
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Invalid comparison between Unknown and I4
if (!PhotonNetwork.IsMasterClient || !VoidManagerPlugin.ModEnabled)
{
return;
}
AbstractPlayerControlledShip playerShip = ClientGame.Current.PlayerShip;
object obj;
if (playerShip == null)
{
obj = null;
}
else
{
Transform transform = ((AbstractCloneStarObject)playerShip).Transform;
if (transform == null)
{
obj = null;
}
else
{
ThrusterBoosterController component = ((Component)transform).GetComponent<ThrusterBoosterController>();
obj = ((component != null) ? component.ThrusterBoosters : null);
}
}
List<ThrusterBooster> list = (List<ThrusterBooster>)obj;
if (list == null)
{
return;
}
if (Configs.ThrusterBoosterConfig.Value)
{
foreach (ThrusterBooster booster in list)
{
if ((int)booster.State == 0)
{
Tools.DelayDoUnique((object)booster, (Action)delegate
{
ChargeThrusterBooster(booster);
}, Configs.ThrusterBoosterDelay.Value);
}
}
return;
}
foreach (ThrusterBooster item in list)
{
Tools.CancelDelayDoUnique((object)item);
}
}
}
public class VoidManagerPlugin : VoidPlugin
{
public static bool ModEnabled;
public override MultiplayerType MPType => (MultiplayerType)14;
public override string Author => "18107, Dragon";
public override string Description => "Makes circuit breakers, thruster boosters, and trims self reset. Disables Progression.";
public override string ThunderstoreID => "VoidCrewModdingTeam/Automatic_Ship_Systems";
public VoidManagerPlugin()
{
Events.Instance.MasterClientSwitched += delegate
{
if (PhotonNetwork.IsMasterClient)
{
PowerBreakerPatch.ToggleAutomaticBreakers(null, null);
ThrusterBoosterPatch.ToggleAutomaticThrusterBoosters(null, null);
EnhancementPatch.ToggleAutomaticTrims(null, null);
}
};
}
internal static void Enable()
{
ModEnabled = true;
ProgressionHandler.DisableProgression("18107.AutomaticShipSystems");
}
public override SessionChangedReturn OnSessionChange(SessionChangedInput input)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected I4, but got Unknown
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
CallType callType = input.CallType;
CallType val = callType;
switch (val - 1)
{
case 1:
ModEnabled = false;
break;
case 0:
case 3:
{
Enable();
SessionChangedReturn result = default(SessionChangedReturn);
result.SetMod_Session = true;
return result;
}
}
return ((VoidPlugin)this).OnSessionChange(input);
}
}
}