Decompiled source of LightsOut v0.1.3

LightsOut.dll

Decompiled 7 months 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.Bootstrap;
using BepInEx.Logging;
using GeneralImprovements.Items;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("LightsOut")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A template for Lethal Company")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyInformationalVersion("0.0.1+82f6959a27f90b65309bff6e0bf547925bffed1d")]
[assembly: AssemblyProduct("LightsOut")]
[assembly: AssemblyTitle("LightsOut")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.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 LightsOut
{
	public static class LightSourceToggle
	{
		public static void Disable(GrabbableObject item, bool stopAudio = false)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			if (!ShouldReturn(item))
			{
				Plugin.logger.LogDebug((object)("Disabling light of " + item.itemProperties.itemName));
				CollectionExtensions.Do<Light>((IEnumerable<Light>)((Component)item).GetComponentsInChildren<Light>().ToList(), (Action<Light>)delegate(Light l)
				{
					((Behaviour)l).enabled = false;
				});
				if ("LungProp" == item.__getTypeName() && stopAudio)
				{
					Plugin.logger.LogDebug((object)"Disabling sound of LungProp");
					LungProp val = (LungProp)item;
					val.isLungDocked = false;
					val.isLungDockedInElevator = false;
					val.isLungPowered = false;
					((Component)val).GetComponent<AudioSource>().Stop();
				}
				if (item.__getTypeName() == "ToggleableFancyLamp")
				{
					GeneralImprovementsPatch.DisableGILamp(item);
				}
			}
		}

		public static void Enable(GrabbableObject item)
		{
			if (!ShouldReturn(item))
			{
				Plugin.logger.LogDebug((object)("Enabling light of " + item.itemProperties.itemName));
				CollectionExtensions.Do<Light>((IEnumerable<Light>)((Component)item).GetComponentsInChildren<Light>().ToList(), (Action<Light>)delegate(Light l)
				{
					((Behaviour)l).enabled = true;
				});
				if (item.__getTypeName() == "ToggleableFancyLamp")
				{
					GeneralImprovementsPatch.EnableGILamp(item);
				}
			}
		}

		private static bool ShouldReturn(GrabbableObject item)
		{
			if (!item.isInShipRoom)
			{
				Plugin.logger.LogDebug((object)(item.__getTypeName() + " is not in ship room"));
				return true;
			}
			if ((Object)(object)((Component)item).GetComponentInChildren<Light>() == (Object)null)
			{
				Plugin.logger.LogDebug((object)(item.__getTypeName() + " has no light"));
				return true;
			}
			if (item.__getTypeName() != "PhysicsProp" && item.__getTypeName() != "LungProp" && item.__getTypeName() != "ToggleableFancyLamp")
			{
				Plugin.logger.LogDebug((object)(item.__getTypeName() + " is not a predefined type"));
				return true;
			}
			return false;
		}
	}
	internal class GeneralImprovementsPatch
	{
		public static void DisableGILamp(GrabbableObject lamp)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			try
			{
				ToggleableFancyLamp val = (ToggleableFancyLamp)lamp;
				((GrabbableObject)val).ItemActivate(false, false);
				((GrabbableObject)val).isBeingUsed = false;
			}
			catch
			{
				Plugin.logger.LogWarning((object)"Failed to disable GI lamp");
			}
		}

		public static void EnableGILamp(GrabbableObject lamp)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			try
			{
				ToggleableFancyLamp val = (ToggleableFancyLamp)lamp;
				((GrabbableObject)val).ItemActivate(true, false);
				((GrabbableObject)val).isBeingUsed = true;
			}
			catch
			{
				Plugin.logger.LogWarning((object)"Failed to enable GI lamp");
			}
		}
	}
	[HarmonyPatch(typeof(GrabbableObject))]
	public static class GrabbableObjectPatch
	{
		[HarmonyPatch("DiscardItemClientRpc")]
		[HarmonyPostfix]
		public static void DiscardItemClientRpc(GrabbableObject __instance)
		{
			Plugin.logger.LogDebug((object)("DiscardItemClientRpc " + __instance.itemProperties.itemName));
			if (__instance.isInShipRoom)
			{
				LightSourceToggle.Disable(__instance, stopAudio: true);
			}
		}

		[HarmonyPatch("DiscardItemOnClient")]
		[HarmonyPostfix]
		public static void DiscardItemOnClient(GrabbableObject __instance)
		{
			Plugin.logger.LogDebug((object)("DiscardItemOnClient " + __instance.itemProperties.itemName));
			if (__instance.isInShipRoom)
			{
				LightSourceToggle.Disable(__instance);
			}
		}

		[HarmonyPatch("GrabClientRpc")]
		[HarmonyPostfix]
		public static void GrabClientRpc(GrabbableObject __instance)
		{
			Plugin.logger.LogDebug((object)("GrabClientRpc " + __instance.itemProperties.itemName));
			LightSourceToggle.Enable(__instance);
		}

		[HarmonyPatch("GrabItemOnClient")]
		public static void GrabItemOnClient(GrabbableObject __instance)
		{
			Plugin.logger.LogDebug((object)("GrabItemOnClient " + __instance.itemProperties.itemName));
			LightSourceToggle.Enable(__instance);
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	public static class LoadItemPatch
	{
		[HarmonyPatch("LoadShipGrabbableItems")]
		[HarmonyPostfix]
		public static void ServerTurnOffLights(StartOfRound __instance)
		{
			GameObject val = GameObject.Find("/Environment/HangarShip");
			GrabbableObject[] componentsInChildren = val.GetComponentsInChildren<GrabbableObject>();
			GrabbableObject[] array = componentsInChildren;
			foreach (GrabbableObject item in array)
			{
				LightSourceToggle.Disable(item, stopAudio: true);
			}
		}

		[HarmonyPatch("SyncShipUnlockablesClientRpc")]
		[HarmonyPostfix]
		public static void ClientTurnOffLights(StartOfRound __instance)
		{
			GameObject val = GameObject.Find("/Environment/HangarShip");
			GrabbableObject[] componentsInChildren = val.GetComponentsInChildren<GrabbableObject>();
			GrabbableObject[] array = componentsInChildren;
			foreach (GrabbableObject item in array)
			{
				LightSourceToggle.Disable(item, stopAudio: true);
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	public static class SetShipReadyToLandPatch
	{
		[HarmonyPatch("SetShipReadyToLand")]
		[HarmonyPostfix]
		public static void TurnOffLights(StartOfRound __instance)
		{
			GameObject val = GameObject.Find("/Environment/HangarShip");
			GrabbableObject[] componentsInChildren = val.GetComponentsInChildren<GrabbableObject>();
			GrabbableObject[] array = componentsInChildren;
			foreach (GrabbableObject item in array)
			{
				LightSourceToggle.Disable(item, stopAudio: true);
			}
		}
	}
	[BepInPlugin("LightsOut", "LightsOut", "0.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource logger;

		private readonly Harmony harmony = new Harmony("LightsOut");

		internal static bool isGIPresent;

		private void Awake()
		{
			logger = ((BaseUnityPlugin)this).Logger;
			harmony.PatchAll();
			if (Chainloader.PluginInfos.ContainsKey("ShaosilGaming.GeneralImprovements"))
			{
				isGIPresent = true;
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin LightsOut is loaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LightsOut";

		public const string PLUGIN_NAME = "LightsOut";

		public const string PLUGIN_VERSION = "0.0.1";
	}
}