using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 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: 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]
[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 class Patches
{
[CompilerGenerated]
private sealed class <FlashlightExecute>d__8 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IEnumerator, IDisposable
{
private int <>1__state;
private CodeInstruction <>2__current;
private int <>l__initialThreadId;
private IEnumerable<CodeInstruction> instructions;
public IEnumerable<CodeInstruction> <>3__instructions;
private FieldInfo <intensityField>5__2;
private IEnumerator<CodeInstruction> <>7__wrap2;
private CodeInstruction <instruction>5__4;
CodeInstruction IEnumerator<CodeInstruction>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <FlashlightExecute>d__8(int <>1__state)
{
this.<>1__state = <>1__state;
<>l__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if (num == -3 || (uint)(num - 1) <= 2u)
{
try
{
}
finally
{
<>m__Finally1();
}
}
<intensityField>5__2 = null;
<>7__wrap2 = null;
<instruction>5__4 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Expected O, but got Unknown
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Expected O, but got Unknown
try
{
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<intensityField>5__2 = typeof(CL_Lamp).GetField("intensity");
<>7__wrap2 = instructions.GetEnumerator();
<>1__state = -3;
goto IL_0115;
case 1:
<>1__state = -3;
<>2__current = new CodeInstruction(OpCodes.Mul, (object)null);
<>1__state = 2;
return true;
case 2:
<>1__state = -3;
goto IL_00ef;
case 3:
{
<>1__state = -3;
<instruction>5__4 = null;
goto IL_0115;
}
IL_0115:
if (<>7__wrap2.MoveNext())
{
<instruction>5__4 = <>7__wrap2.Current;
if (<instruction>5__4.opcode == OpCodes.Stfld && CodeInstructionExtensions.StoresField(<instruction>5__4, <intensityField>5__2))
{
<>2__current = new CodeInstruction(OpCodes.Ldc_R4, (object)0.9f);
<>1__state = 1;
return true;
}
goto IL_00ef;
}
<>m__Finally1();
<>7__wrap2 = null;
return false;
IL_00ef:
<>2__current = <instruction>5__4;
<>1__state = 3;
return true;
}
}
catch
{
//try-fault
((IDisposable)this).Dispose();
throw;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
private void <>m__Finally1()
{
<>1__state = -1;
if (<>7__wrap2 != null)
{
<>7__wrap2.Dispose();
}
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
[DebuggerHidden]
IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
{
<FlashlightExecute>d__8 <FlashlightExecute>d__;
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
<FlashlightExecute>d__ = this;
}
else
{
<FlashlightExecute>d__ = new <FlashlightExecute>d__8(0);
}
<FlashlightExecute>d__.instructions = <>3__instructions;
return <FlashlightExecute>d__;
}
[DebuggerHidden]
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
}
}
[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 != "Dark Machine/SHDR_Base") && val.shader != Plugin.shader)
{
val.shader = Plugin.shader;
}
}
Plugin.Logger.LogInfo((object)"Materials patched");
}
[HarmonyPatch(typeof(FXManager), "FXRender")]
[HarmonyPrefix]
public static void FXManagerRender()
{
//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)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
FXManager.fxData.minCol = Color.clear;
FXManager.fxData.fog = Color.black;
FXManager.fxData.fogTop = Color.black;
if (!(FXManager.fxData.worldBright > 0f) || !((Object)(object)CL_EventManager.currentRegion != (Object)null) || (!(((Object)CL_EventManager.currentRegion).name == "Region_Abyss_Campaign") && !(((Object)CL_EventManager.currentRegion).name == "Region_Abyss_Endless")))
{
FXManager.fxData.worldBright = 0f;
FXManager.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(M_Level level)
{
CL_Lamp[] componentsInChildren = ((Component)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(((Component)level).gameObject);
}
[HarmonyPatch(typeof(M_Level), "OnSpawn")]
[HarmonyPostfix]
public static void LevelOnSpawn(M_Level __instance)
{
PatchLevel(__instance);
}
[HarmonyPatch(typeof(MenuManager), "SelectMenuBackground")]
[HarmonyPostfix]
public static void MenuSelectBackground(MenuManager __instance)
{
M_Level componentInChildren = ((Component)__instance).GetComponentInChildren<M_Level>();
if ((Object)(object)componentInChildren != (Object)null)
{
PatchLevel(componentInChildren);
}
}
[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;
}
}
[IteratorStateMachine(typeof(<FlashlightExecute>d__8))]
[HarmonyPatch(typeof(Item_Object_Flashlight), "Execute")]
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> FlashlightExecute(IEnumerable<CodeInstruction> instructions)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <FlashlightExecute>d__8(-2)
{
<>3__instructions = instructions
};
}
[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;
}
}
}
}
[BepInPlugin("LightsOut", "Lights Out", "1.1.0")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Logger;
public static AssetBundle bundle;
public static Shader shader;
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Harmony.CreateAndPatchAll(typeof(Patches), (string)null);
Logger.LogInfo((object)"Patches applied");
bundle = AssetBundle.LoadFromFile(Directory.GetFiles(Paths.PluginPath, "lights_out", SearchOption.AllDirectories).First());
Logger.LogInfo((object)"Asset bundle loaded");
shader = bundle.LoadAsset<Shader>("Dark Machine_SHDR_Base_Dark");
Logger.LogInfo((object)"Shader loaded");
}
}
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";
}
}