Decompiled source of Lights Out v1.3.0

plugins/LightsOut/LightsOut.dll

Decompiled 4 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PrefabLightMapBaker;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LightsOut")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("Lights Out")]
[assembly: AssemblyTitle("LightsOut")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 class Patches
	{
		[HarmonyPatch(typeof(CL_Initializer), "Awake")]
		[HarmonyPostfix]
		public static void InitializerAwake()
		{
			Material[] array = Resources.FindObjectsOfTypeAll<Material>();
			foreach (Material val in array)
			{
				if (((Object)val.shader).name.StartsWith("Dark Machine/SHDR_Base"))
				{
					if (val.HasFloat("_Bright"))
					{
						val.SetFloat("_Bright", 0f);
					}
					if (val.HasTexture("_Emission"))
					{
						val.SetTexture("_Emission", (Texture)(object)Texture2D.blackTexture);
					}
					if (val.HasFloat("_EmissionMultiplier"))
					{
						val.SetFloat("_EmissionMultiplier", 0f);
					}
					if (val.HasFloat("_Emission"))
					{
						val.SetFloat("_Emission", 0f);
					}
					if (val.HasFloat("_Shimmer"))
					{
						val.SetFloat("_Shimmer", 0f);
					}
					if (val.HasFloat("_ShimmerOver"))
					{
						val.SetFloat("_ShimmerOver", 0f);
					}
					if (val.HasFloat("_ShimmerTextureMix"))
					{
						val.SetFloat("_ShimmerTextureMix", 1f);
					}
				}
			}
			Plugin.Logger.LogInfo((object)"Materials patched");
		}

		[HarmonyPatch(typeof(FXManager), "UpdateHandholdMaterialSettings")]
		[HarmonyPostfix]
		public static void FXManagerUpdate(ref List<Material> ___handholdMaterials)
		{
			if (___handholdMaterials == null)
			{
				return;
			}
			foreach (Material ___handholdMaterial in ___handholdMaterials)
			{
				if (((Object)___handholdMaterial.shader).name.StartsWith("Dark Machine/SHDR_Base"))
				{
					if (___handholdMaterial.HasFloat("_EmissionMultiplier"))
					{
						___handholdMaterial.SetFloat("_EmissionMultiplier", 0f);
					}
					if (___handholdMaterial.HasFloat("_Emission"))
					{
						___handholdMaterial.SetFloat("_Emission", 0f);
					}
					if (___handholdMaterial.HasFloat("_Shimmer"))
					{
						___handholdMaterial.SetFloat("_Shimmer", 0f);
					}
					if (___handholdMaterial.HasFloat("_ShimmerOver"))
					{
						___handholdMaterial.SetFloat("_ShimmerOver", 0f);
					}
					if (___handholdMaterial.HasFloat("_ShimmerTextureMix"))
					{
						___handholdMaterial.SetFloat("_ShimmerTextureMix", 1f);
					}
				}
			}
		}

		[HarmonyPatch(typeof(FXManager), "Update")]
		[HarmonyPostfix]
		public static void FXManagerUpdate(ref FXZoneStore ___regionFX)
		{
			//IL_0007: 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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			___regionFX.data.minCol = Color.clear;
			___regionFX.data.fog = Color.black;
			___regionFX.data.fogTop = Color.black;
			___regionFX.data.worldBright = 0f;
			___regionFX.data.entityBright = 0f;
		}

		[HarmonyPatch(typeof(FX_Zone), "Start")]
		[HarmonyPrefix]
		public static void FXZoneStart(FX_Zone __instance)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			__instance.fxData.minCol = Color.clear;
			__instance.fxData.fog = Color.black;
			__instance.fxData.fogTop = Color.black;
			__instance.fxData.worldBright = 0f;
			__instance.fxData.entityBright = 0f;
		}

		public static void RemoveFog(GameObject obj)
		{
			MeshRenderer[] componentsInChildren = obj.GetComponentsInChildren<MeshRenderer>(true);
			foreach (MeshRenderer val in componentsInChildren)
			{
				if (((Renderer)val).materials.Length <= 1 && (((Object)((Renderer)val).material).name.Contains("Fog") || ((Object)((Renderer)val).material).name.Contains("fog")))
				{
					Object.Destroy((Object)(object)val);
				}
			}
		}

		public static void PatchLevel(GameObject level)
		{
			CL_Lamp[] componentsInChildren = level.GetComponentsInChildren<CL_Lamp>(true);
			foreach (CL_Lamp val in componentsInChildren)
			{
				if (!((Object)(object)((Component)val).GetComponentInParent<Item_Object>(true) != (Object)null) && !((Object)(object)((Component)val).GetComponentInParent<ENV_LightningDischarge>(true) != (Object)null))
				{
					val.lampActive = false;
					((Behaviour)val).enabled = false;
					val.range = 0f;
					val.intensity = 0f;
				}
			}
			RemoveFog(level.gameObject);
		}

		[HarmonyPatch(typeof(M_Level), "OnSpawn")]
		[HarmonyPostfix]
		public static void LevelOnSpawn(M_Level __instance)
		{
			PatchLevel(((Component)__instance).gameObject);
		}

		[HarmonyPatch(typeof(MenuManager), "SelectMenuBackground")]
		[HarmonyPostfix]
		public static void MenuSelectBackground(MenuManager __instance)
		{
			PatchLevel(((Component)__instance).gameObject);
		}

		[HarmonyPatch(typeof(SessionEventModule_Weather), "Initialize")]
		[HarmonyPostfix]
		public static void WeatherInitialize(ref GameObject ___weatherObject)
		{
			if (!((Object)(object)___weatherObject == (Object)null))
			{
				RemoveFog(___weatherObject);
			}
		}

		[HarmonyPatch(typeof(Item_Object_Flashlight), "Start")]
		[HarmonyPostfix]
		public static void FlashlightStart(Item_Object_Flashlight __instance)
		{
			if (!(((Item_Object)__instance).itemData.prefabName != "Item_Flashlight"))
			{
				__instance.lamp.range = 35f;
				__instance.lamp.curRange = 35f;
				__instance.lamp.angle = 100f;
			}
		}

		[HarmonyPatch(typeof(Item_Object_Flashlight), "Execute")]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> FlashlightExecute(IEnumerable<CodeInstruction> instructions)
		{
			FieldInfo intensityField = typeof(CL_Lamp).GetField("intensity");
			foreach (CodeInstruction instruction in instructions)
			{
				if (instruction.opcode == OpCodes.Stfld && CodeInstructionExtensions.StoresField(instruction, intensityField))
				{
					yield return new CodeInstruction(OpCodes.Ldc_R4, (object)0.9f);
					yield return new CodeInstruction(OpCodes.Mul, (object)null);
				}
				yield return instruction;
			}
		}

		[HarmonyPatch(typeof(ItemExecutionModule_Lamp), "Execute")]
		[HarmonyPostfix]
		public static void ModuleLampExecute(ItemExecutionModule_Lamp __instance)
		{
			if (!((Object)(object)__instance.lampObject == (Object)null) && !(((Object)((Component)__instance.lampObject).gameObject).name != "Headlamp_Lamp"))
			{
				__instance.lampObject.range = 24f;
				__instance.lampObject.curRange = 24f;
			}
		}

		[HarmonyPatch(typeof(Projectile), "Start")]
		[HarmonyPrefix]
		public static void FlareStart(Projectile __instance)
		{
			if (!(__instance.damageType != "flare"))
			{
				CL_Lamp componentInChildren = ((Component)__instance).GetComponentInChildren<CL_Lamp>(true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					componentInChildren.range *= 2f;
					componentInChildren.curRange *= 2f;
				}
			}
		}

		[HarmonyPatch(typeof(ftLightmapsStorage), "Start")]
		[HarmonyPatch(typeof(Utils), "CombineLightmaps")]
		[HarmonyPostfix]
		public static void LightmapsStorageStart()
		{
			LightmapSettings.lightmaps = Enumerable.Repeat<LightmapData>(Plugin.black, LightmapSettings.lightmaps.Length).ToArray();
		}
	}
	[BepInPlugin("LightsOut", "Lights Out", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		public static LightmapData black;

		private void Awake()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Harmony.CreateAndPatchAll(typeof(Patches), (string)null);
			Logger.LogInfo((object)"Patches applied");
			black = new LightmapData
			{
				lightmapColor = Texture2D.blackTexture
			};
			SceneManager.sceneLoaded += delegate
			{
				Patches.LightmapsStorageStart();
			};
			Logger.LogInfo((object)"Dark lightmap created");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "LightsOut";

		public const string PLUGIN_NAME = "Lights Out";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}