Decompiled source of AutoSuit v0.0.6

AutoSuit.dll

Decompiled 2 weeks ago
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.Client.Ship;
using CG.Game;
using CG.Game.Player;
using CG.Ship.Hull;
using Gameplay.Atmosphere;
using Gameplay.Utilities;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Opsive.UltimateCharacterController.Character.Abilities;
using Opsive.UltimateCharacterController.Traits;
using UnityEngine;
using VoidManager;
using VoidManager.CustomGUI;
using VoidManager.MPModChecks;
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("AutoSuit")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Automatically equips (or unequips) the suit when pressing the pressurize lever in the airlock. Client-side, Mod-session required to enable.")]
[assembly: AssemblyFileVersion("0.0.6.0")]
[assembly: AssemblyInformationalVersion("0.0.6+8db747b2f85e35a79653e4108f723c896b3382f1")]
[assembly: AssemblyProduct("AutoSuit")]
[assembly: AssemblyTitle("Automatically equips (or unequips) the suit when pressing the pressurize lever in the airlock. Client-side, Mod-session required to enable.")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.6.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 AutoSuit
{
	[HarmonyPatch(typeof(AirlockButtonPanel))]
	internal class AirlockButtonPanelPatch
	{
		private static readonly FieldInfo flyAbilityField = AccessTools.Field(typeof(JetpackItem), "_flyAbility");

		private static readonly FieldInfo OxygenDepositField = AccessTools.Field(typeof(LocalPlayer), "OxygenDeposit");

		[HarmonyPrefix]
		[HarmonyPatch("OnPressurizeButtonPressed")]
		private static void OnPressurizeButtonPressed(AirlockButtonPanel __instance, AirlockPressurizationType type, Airlock ____airlock)
		{
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Invalid comparison between Unknown and I4
			if (!VoidManagerPlugin.Enabled || !(((Object)__instance).name == "AirlockButtonPanel (1)") || ____airlock.IsPressurizing || ____airlock.airlockDoors.Any((AirlockDoor door) => ((AbstractDoor)door).IsOpen))
			{
				return;
			}
			ItemEquipper equipper = ((IEnumerable<ItemEquipper>)((Component)ClientGame.Current.PlayerShip).gameObject.GetComponentsInChildren<ItemEquipper>()).FirstOrDefault((Func<ItemEquipper, bool>)((ItemEquipper item) => ((Object)item).name == "JetpackRack"));
			if ((Object)(object)equipper == (Object)null)
			{
				return;
			}
			JetpackItem componentInChildren = ((Component)LocalPlayer.Instance).gameObject.GetComponentInChildren<JetpackItem>();
			FlyJetpack flyAbility = (FlyJetpack)flyAbilityField.GetValue(componentInChildren);
			ModifiableFloat jetpackOxygen = ((Player)LocalPlayer.Instance).JetpackOxygen;
			float value = ((ModifiablePrimitive<float, FloatModifier>)(object)jetpackOxygen).Value;
			if ((int)type == 0)
			{
				Tools.DelayDo((Action)CheckRemoveSuit, 1000.0);
				return;
			}
			FlyJetpack obj = flyAbility;
			if (obj == null || !((Ability)obj).Enabled)
			{
				equipper.ToggleEquippedItem();
			}
			void CheckRemoveSuit()
			{
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d1: Expected O, but got Unknown
				//IL_007f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0098: Unknown result type (might be due to invalid IL or missing references)
				if (____airlock.IsPressurizing)
				{
					Tools.DelayDo((Action)CheckRemoveSuit, 1000.0);
				}
				else
				{
					AtmosphereValues atmosphereData = ((Component)LocalPlayer.Instance).GetComponent<CharacterAtmosphericDataTracker>().AtmosphereData;
					FlyJetpack obj2 = flyAbility;
					if (obj2 != null && ((Ability)obj2).Enabled && (!Configs.KeepColdConfig.Value || atmosphereData.Temperature > -100f) && (!Configs.KeepHotConfig.Value || atmosphereData.Temperature < 100f) && (!Configs.KeepOxygenConfig.Value || atmosphereData.Oxygen > 0.02f))
					{
						equipper.ToggleEquippedItem();
						Attribute val = (Attribute)OxygenDepositField.GetValue(LocalPlayer.Instance);
						val.Value = val.MaxValue;
					}
				}
			}
		}
	}
	[BepInPlugin("18107.AutoSuit", "AutoSuit", "0.0.6")]
	[BepInProcess("Void Crew.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class BepinPlugin : BaseUnityPlugin
	{
		internal static BepinPlugin instance;

		internal static ManualLogSource Log;

		private void Awake()
		{
			instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			Configs.Load(this);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin 18107.AutoSuit is loaded!");
		}
	}
	public class VoidManagerPlugin : VoidPlugin
	{
		internal static bool Enabled = true;

		public override MultiplayerType MPType => (MultiplayerType)8;

		public override string Author => "18107";

		public override string Description => "Automatically equips (or unequips) the suit when pressing the pressurize lever in the airlock. Client-side, Mod-session required to enable.";

		public override SessionChangedReturn OnSessionChange(SessionChangedInput input)
		{
			//IL_0001: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			Enabled = input.IsHost || input.IsMod_Session;
			SessionChangedReturn result = default(SessionChangedReturn);
			result.SetMod_Session = true;
			return result;
		}
	}
	internal class Configs
	{
		internal static ConfigEntry<bool> KeepColdConfig;

		internal static ConfigEntry<bool> KeepHotConfig;

		internal static ConfigEntry<bool> KeepOxygenConfig;

		internal static void Load(BepinPlugin plugin)
		{
			KeepColdConfig = ((BaseUnityPlugin)plugin).Config.Bind<bool>("AutoSuit", "KeepOnWhenCold", true, (ConfigDescription)null);
			KeepHotConfig = ((BaseUnityPlugin)plugin).Config.Bind<bool>("AutoSuit", "KeepOnWhenHot", true, (ConfigDescription)null);
			KeepOxygenConfig = ((BaseUnityPlugin)plugin).Config.Bind<bool>("AutoSuit", "KeepOnWhenLowOxygen", true, (ConfigDescription)null);
		}
	}
	internal class GUI : ModSettingsMenu
	{
		public override string Name()
		{
			return "Auto Suit";
		}

		public override void Draw()
		{
			if (!VoidManagerPlugin.Enabled)
			{
				GUILayout.Label("<color=red><size=30><b>MOD IS DISABLED UNTIL SESSION IS MOD_SESSION TYPE</b></size></color>", Array.Empty<GUILayoutOption>());
			}
			GUITools.DrawCheckbox("Keep suit on when too cold", ref Configs.KeepColdConfig);
			GUITools.DrawCheckbox("Keep suit on when too hot", ref Configs.KeepHotConfig);
			GUITools.DrawCheckbox("Keep suit on when no oxygen present", ref Configs.KeepOxygenConfig);
		}
	}
	public class MyPluginInfo
	{
		public const string PLUGIN_GUID = "18107.AutoSuit";

		public const string PLUGIN_NAME = "AutoSuit";

		public const string USERS_PLUGIN_NAME = "AutoSuit";

		public const string PLUGIN_VERSION = "0.0.6";

		public const string PLUGIN_DESCRIPTION = "Automatically equips (or unequips) the suit when pressing the pressurize lever in the airlock. Client-side, Mod-session required to enable.";

		public const string PLUGIN_ORIGINAL_AUTHOR = "18107";

		public const string PLUGIN_AUTHORS = "18107";

		public const string PLUGIN_THUNDERSTORE_ID = "";
	}
}