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");
Material value = Resources.FindObjectsOfTypeAll<Material>().First((Material x) => ((Object)x).name == "MAT_Invisible");
List<Material> list = new List<Material>();
Renderer[] array2 = Resources.FindObjectsOfTypeAll<Renderer>();
foreach (Renderer val2 in array2)
{
val2.GetSharedMaterials(list);
int num = 0;
for (int num2 = 0; num2 < list.Count; num2++)
{
if (Object.op_Implicit((Object)(object)list[num2]))
{
string text = ((Object)list[num2]).name.ToLowerInvariant();
if ((text.Contains("fog") || text.Contains("lightglow")) && (!text.Contains("distance") || !text.Contains("abyss")) && !text.Contains("hadal"))
{
list[num2] = value;
num++;
}
}
}
if (num > 0)
{
val2.SetSharedMaterials(list);
}
if (num == list.Count)
{
val2.enabled = false;
}
}
Plugin.Logger.LogInfo((object)"Renderers patched");
}
[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 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) && !((Object)(object)((Component)val).GetComponentInParent<Denizen>(true) != (Object)null) && !((Object)(object)((Component)val).GetComponentInParent<CL_Prop>(true) != (Object)null))
{
val.lampActive = false;
((Behaviour)val).enabled = false;
val.range = 0f;
val.intensity = 0f;
}
}
}
[HarmonyPatch(typeof(M_Level), "OnSpawn")]
[HarmonyPostfix]
public static void LevelOnSpawn(M_Level __instance)
{
PatchLevel(((Component)__instance).gameObject);
}
[HarmonyPatch(typeof(UT_ChamberLoader), "LoadChamber")]
[HarmonyPostfix]
public static void ChamberOnLoad(ref M_Chamber ___spawnedChamber)
{
PatchLevel(((Component)___spawnedChamber).gameObject);
}
[HarmonyPatch(typeof(MenuManager), "SelectMenuBackground")]
[HarmonyPostfix]
public static void MenuSelectBackground(MenuManager __instance)
{
PatchLevel(((Component)__instance).gameObject);
}
[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(Scene scene, LoadSceneMode mode)
{
Patches.LightmapsStorageStart();
if (!(((Scene)(ref scene)).name != "Playground"))
{
GameObject val = GameObject.Find("/World");
if (Object.op_Implicit((Object)(object)val))
{
Patches.PatchLevel(val);
}
}
};
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";
}
}