Decompiled source of CloseShipDoors v0.0.1

CloseShipDoors.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
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.Game;
using CG.Ship.Hull;
using CG.Space;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
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("CloseShipDoors")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Template")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CloseShipDoors")]
[assembly: AssemblyTitle("CloseShipDoors")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 CloseShipDoors
{
	[HarmonyPatch(typeof(AbstractDoor))]
	internal class AbstractDoorPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("set_IsOpen")]
		private static void IsOpen(AbstractDoor __instance, bool value)
		{
			if (!PhotonNetwork.IsMasterClient || !value)
			{
				return;
			}
			if (!(__instance is AirlockDoor) && Configs.interiorDoorsConfig.Value)
			{
				Tools.DelayDoUnique((object)__instance, (Action)delegate
				{
					__instance.SetOpen(false);
				}, (double)Configs.delayConfig.Value);
			}
			if (__instance is AirlockDoor && Configs.airlockDoorsConfig.Value)
			{
				Tools.DelayDoUnique((object)__instance, (Action)delegate
				{
					__instance.SetOpen(false);
				}, (double)(Configs.delayConfig.Value + 1000));
			}
		}

		internal static void CloseAllDoors()
		{
			ClientGame current = ClientGame.Current;
			if (current == null)
			{
				return;
			}
			AbstractPlayerControlledShip playerShip = current.PlayerShip;
			if (playerShip == null)
			{
				return;
			}
			AbstractDoor[] componentsInChildren = ((Component)playerShip).GetComponentsInChildren<AbstractDoor>();
			if (componentsInChildren != null)
			{
				CollectionExtensions.Do<AbstractDoor>((IEnumerable<AbstractDoor>)componentsInChildren, (Action<AbstractDoor>)delegate(AbstractDoor door)
				{
					IsOpen(door, door.IsOpen);
				});
			}
		}
	}
	internal static class MyPluginInfo
	{
		internal const string PLUGIN_GUID = "id107.closeshipdoors";

		internal const string PLUGIN_NAME = "CloseShipDoors";

		internal const string PLUGIN_VERSION = "0.0.1";
	}
	[BepInPlugin("id107.closeshipdoors", "CloseShipDoors", "0.0.1")]
	[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;
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "id107.closeshipdoors");
			Configs.Load(this);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin id107.closeshipdoors is loaded!");
		}
	}
	internal class Configs
	{
		internal static ConfigEntry<int> delayConfig;

		internal static ConfigEntry<bool> interiorDoorsConfig;

		internal static ConfigEntry<bool> airlockDoorsConfig;

		internal static void Load(BepinPlugin plugin)
		{
			delayConfig = ((BaseUnityPlugin)plugin).Config.Bind<int>("CloseShipDoors", "delayMs", 3000, (ConfigDescription)null);
			interiorDoorsConfig = ((BaseUnityPlugin)plugin).Config.Bind<bool>("CloseShipDoors", "includeInteriorDoors", true, (ConfigDescription)null);
			airlockDoorsConfig = ((BaseUnityPlugin)plugin).Config.Bind<bool>("CloseShipDoors", "includeAirlocks", true, (ConfigDescription)null);
		}
	}
	internal class GUI : ModSettingsMenu
	{
		public override string Name()
		{
			return "Close Ship Doors";
		}

		public override void Draw()
		{
			GUITools.DrawTextField<int>("Delay (ms)", ref Configs.delayConfig, 80f);
			if (GUITools.DrawCheckbox("Include interior doors", ref Configs.interiorDoorsConfig))
			{
				AbstractDoorPatch.CloseAllDoors();
			}
			if (GUITools.DrawCheckbox("Include airlock doors", ref Configs.airlockDoorsConfig))
			{
				AbstractDoorPatch.CloseAllDoors();
			}
		}
	}
	public class VoidManagerPlugin : VoidPlugin
	{
		public override MultiplayerType MPType => (MultiplayerType)4;

		public override string Author => "18107";

		public override string Description => "Closes ship doors a short time after they are opened";

		public VoidManagerPlugin()
		{
			Events.Instance.MasterClientSwitched += delegate
			{
				AbstractDoorPatch.CloseAllDoors();
			};
		}
	}
}