Decompiled source of LightsOut v0.2.0

LightsOut.dll

Decompiled 2 days 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 GeneralImprovements.Items;
using HarmonyLib;
using LightsOut.Patches;
using Microsoft.CodeAnalysis;
using MrovLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("LightsOut")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A template for Lethal Company")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0+a9191d7f6cfc8eb798d3c80b70cb479fde098976")]
[assembly: AssemblyProduct("LightsOut")]
[assembly: AssemblyTitle("LightsOut")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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 LightsOut
{
	internal class ConfigManager
	{
		public static ConfigFile configFile;

		internal static ConfigEntry<LoggingType> Debug { get; private set; }

		public static ConfigManager Instance { get; private set; }

		private ConfigManager(ConfigFile config)
		{
			configFile = config;
			Debug = configFile.Bind<LoggingType>("General", "Logging levels", (LoggingType)0, "Enable debug logging");
		}

		internal static void Init(ConfigFile config)
		{
			Instance = new ConfigManager(config);
		}
	}
	public static class LightSourceToggle
	{
		public static void Disable(GrabbableObject item, bool stopAudio = false)
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			if (!ShouldReturn(item))
			{
				((Logger)Plugin.debugLogger).LogDebug("Disabling light of " + item.itemProperties.itemName);
				CollectionExtensions.Do<Light>((IEnumerable<Light>)((Component)item).GetComponentsInChildren<Light>(), (Action<Light>)delegate(Light l)
				{
					((Behaviour)l).enabled = false;
				});
				if ("LungProp" == item.__getTypeName() && stopAudio)
				{
					((Logger)Plugin.debugLogger).LogDebug("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))
			{
				((Logger)Plugin.debugLogger).LogDebug("Enabling light of " + item.itemProperties.itemName);
				CollectionExtensions.Do<Light>((IEnumerable<Light>)((Component)item).GetComponentsInChildren<Light>(), (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)
			{
				((Logger)Plugin.debugLogger).LogDebug(item.__getTypeName() + " is not in ship room");
				return true;
			}
			if (item.__getTypeName() != "PhysicsProp" && item.__getTypeName() != "LungProp" && item.__getTypeName() != "ToggleableFancyLamp")
			{
				((Logger)Plugin.debugLogger).LogDebug(item.__getTypeName() + " is not a predefined type");
				return true;
			}
			if ((Object)(object)((Component)item).GetComponentInChildren<Light>() == (Object)null)
			{
				((Logger)Plugin.debugLogger).LogDebug(item.__getTypeName() + " has no light");
				return true;
			}
			return false;
		}
	}
	public class Logger : Logger
	{
		public override ManualLogSource LogSource { get; set; }

		public Logger(string SourceName, LoggingType defaultLoggingType = 1)
			: base(SourceName, defaultLoggingType)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			((Logger)this).ModName = SourceName;
			((Logger)this).LogSource = Logger.CreateLogSource("LightsOut");
			((Logger)this)._name = SourceName;
		}

		public override bool ShouldLog(LoggingType type)
		{
			//IL_0005: 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)
			return ConfigManager.Debug.Value >= type;
		}
	}
	[BepInPlugin("mrov.LightsOut", "LightsOut", "0.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource logger;

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

		internal static Logger debugLogger = new Logger("LightsOut", (LoggingType)1);

		private void Awake()
		{
			logger = ((BaseUnityPlugin)this).Logger;
			harmony.PatchAll();
			ConfigManager.Init(((BaseUnityPlugin)this).Config);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin mrov.LightsOut is loaded!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "mrov.LightsOut";

		public const string PLUGIN_NAME = "LightsOut";

		public const string PLUGIN_VERSION = "0.2.0";
	}
}
namespace LightsOut.Patches
{
	internal class GeneralImprovementsPatch
	{
		public static void DisableGILamp(GrabbableObject lamp)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			try
			{
				ToggleableFancyLamp val = (ToggleableFancyLamp)lamp;
				((GrabbableObject)val).ItemActivate(false, false);
				((GrabbableObject)val).isBeingUsed = false;
			}
			catch
			{
				((Logger)Plugin.debugLogger).LogWarning("Failed to disable GI lamp");
			}
		}

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

		[HarmonyPatch("GrabItem")]
		[HarmonyPostfix]
		public static void GrabClientRpc(GrabbableObject __instance)
		{
			((Logger)Plugin.debugLogger).LogDebug("GrabItem " + __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);
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}