Decompiled source of BlackPeakRemix v1.0.0

BlackPeakRemix.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("BlackPeakRemix")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BlackPeakRemix")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("1397A0FB-60D8-4C87-B299-266D00003F03")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 BlackPeakRemix
{
	public enum LanternState : byte
	{
		Omni,
		Flashlight
	}
	public enum BPR_SubType : byte
	{
		LanternSync,
		ConfigSync,
		ConfigRequest
	}
	public enum LanternColorMode
	{
		Original,
		FollowPlayer,
		Custom
	}
	[BepInPlugin("HnskNoah.BlackPeakRemix", "BlackPeakRemix", "1.0.0")]
	public class BlackPeakRemix : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <SyncDebounceRoutine>d__28 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public BlackPeakRemix <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <SyncDebounceRoutine>d__28(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Expected O, but got Unknown
				int num = <>1__state;
				BlackPeakRemix blackPeakRemix = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					Log.LogInfo((object)"[ConfigSync] Local config changed. Broadcasting to other players...");
					BroadcastConfigs();
					blackPeakRemix._syncDebounceCoroutine = null;
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public const string GUID = "HnskNoah.BlackPeakRemix";

		internal static ManualLogSource Log;

		public static ConfigEntry<float> ConfigStartHour;

		public static ConfigEntry<float> ConfigEndHour;

		public static ConfigEntry<float> ConfigDarknessMultiplier;

		public static ConfigEntry<float> ConfigIntensity;

		public static ConfigEntry<float> ConfigRange;

		public static ConfigEntry<KeyCode> ToggleKey;

		public static ConfigEntry<bool> ConfigMasterSwitch;

		public static ConfigEntry<bool> ConfigInfiniteFuel;

		public static ConfigEntry<bool> ConfigGhostFX;

		public static ConfigEntry<LanternColorMode> ConfigLanternMode;

		public static ConfigEntry<string> ConfigLanternHex;

		public static Color ActiveCustomColor = Color.cyan;

		public static float ActiveDarknessMultiplier;

		public static float ActiveIntensity;

		public static float ActiveRange;

		public static float ActiveStartHour;

		public static float ActiveEndHour;

		public static bool IsSyncingFromNet;

		private Coroutine _syncDebounceCoroutine;

		private const float SYNC_DEBOUNCE_DELAY = 1f;

		public const byte EVENT_BPR_MAIN = 148;

		public const int PROTOCOL_VERSION = 125;

		private void Awake()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			InitConfigs();
			UpdateActiveSettings();
			try
			{
				new Harmony("HnskNoah.BlackPeakRemix").PatchAll();
				Log.LogMessage((object)"BPR: Logic synchronized with native LightLanternRPC. All features restored.");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Harmony Patch Error: " + ex.Message));
			}
			Object.DontDestroyOnLoad((Object)(object)((Component)new GameObject("BPR_NetProxy").AddComponent<BPR_NetProxy>()).gameObject);
			SceneManager.sceneLoaded += delegate
			{
				Patch_CharacterSpawner_FirstSpawn.ResetSession();
			};
		}

		private void InitConfigs()
		{
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Expected O, but got Unknown
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Expected O, but got Unknown
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Expected O, but got Unknown
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Expected O, but got Unknown
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Expected O, but got Unknown
			ConfigMasterSwitch = ((BaseUnityPlugin)this).Config.Bind<bool>("Basic Settings", "插件总开关 (Master Switch)", true, "Enable or disable all features of this plugin.");
			ConfigInfiniteFuel = ((BaseUnityPlugin)this).Config.Bind<bool>("Basic Settings", "提灯无限燃料 (Lantern Infinite Fuel)", true, "Lock the lantern fuel level (Only works when Master Switch is ON).");
			ConfigLanternMode = ((BaseUnityPlugin)this).Config.Bind<LanternColorMode>("Basic Settings", "提灯颜色模式 (Lantern Color Mode)", LanternColorMode.FollowPlayer, "Logic for lantern color: Original (Yellow), FollowPlayer (Matches skin color), Custom (Use Hex below).");
			ConfigLanternHex = ((BaseUnityPlugin)this).Config.Bind<string>("Basic Settings", "自定义模式颜色码 (Custom Mode color hex)", "0066ff", "Enter a 6-digit hex color value (e.g., ff0000 for Red). Do not include '#'.");
			ToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Basic Settings", "模式切换按键 (Toggle Key)", (KeyCode)102, "Keyboard shortcut to toggle between Lantern and Flashlight mode.");
			ConfigGhostFX = ((BaseUnityPlugin)this).Config.Bind<bool>("Basic Settings", "幽灵视觉滤镜 (Ghost Vision Filter)", false, "Activate ghost night vision filter upon death.");
			ConfigStartHour = ((BaseUnityPlugin)this).Config.Bind<float>("Environment Settings", "黑暗开始时间 (Black Start Hour)", 5f, new ConfigDescription("The hour when black lighting effects begin (0-24).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 24f), Array.Empty<object>()));
			ConfigEndHour = ((BaseUnityPlugin)this).Config.Bind<float>("Environment Settings", "黑暗结束时间 (Black End Hour)", 21f, new ConfigDescription("The hour when black lighting effects end (0-24).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 24f), Array.Empty<object>()));
			ConfigDarknessMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Environment Settings", "黑暗亮度系数 (Darkness Intensity)", 0.05f, new ConfigDescription("Multiplier for night darkness. Smaller values are darker (0-0.15).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 0.15f), Array.Empty<object>()));
			ConfigIntensity = ((BaseUnityPlugin)this).Config.Bind<float>("Environment Settings", "提灯光照强度 (Light Intensity)", 12f, new ConfigDescription("The brightness intensity of the lantern/flashlight.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 30f), Array.Empty<object>()));
			ConfigRange = ((BaseUnityPlugin)this).Config.Bind<float>("Environment Settings", "手电筒照射距离 (Flashlight Range)", 80f, new ConfigDescription("The range of the light in Flashlight mode.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 200f), Array.Empty<object>()));
			ParseHexConfig();
			((BaseUnityPlugin)this).Config.SettingChanged += delegate
			{
				UpdateActiveSettings();
				if (!IsSyncingFromNet && PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient)
				{
					if (_syncDebounceCoroutine != null)
					{
						((MonoBehaviour)this).StopCoroutine(_syncDebounceCoroutine);
					}
					_syncDebounceCoroutine = ((MonoBehaviour)this).StartCoroutine(SyncDebounceRoutine());
					ParseHexConfig();
				}
			};
		}

		private void ParseHexConfig()
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			string text = ConfigLanternHex.Value.Trim();
			if (text.StartsWith("#"))
			{
				text = text.Substring(1);
			}
			if (text.Length > 6)
			{
				text = text.Substring(0, 6);
			}
			Color activeCustomColor = default(Color);
			if (ColorUtility.TryParseHtmlString("#" + text, ref activeCustomColor))
			{
				ActiveCustomColor = activeCustomColor;
				ActiveCustomColor.a = 1f;
			}
			else
			{
				Log.LogWarning((object)("[Config] Failed to parse hex color '" + text + "'. Falling back to default."));
				ActiveCustomColor = new Color(1f, 0.6f, 0.3f);
			}
		}

		public static void UpdateActiveSettings()
		{
			if (!PhotonNetwork.InRoom || PhotonNetwork.IsMasterClient)
			{
				ActiveDarknessMultiplier = ConfigDarknessMultiplier.Value;
				ActiveIntensity = ConfigIntensity.Value;
				ActiveRange = ConfigRange.Value;
				ActiveStartHour = ConfigStartHour.Value;
				ActiveEndHour = ConfigEndHour.Value;
			}
		}

		[IteratorStateMachine(typeof(<SyncDebounceRoutine>d__28))]
		private IEnumerator SyncDebounceRoutine()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <SyncDebounceRoutine>d__28(0)
			{
				<>4__this = this
			};
		}

		public static void BroadcastConfigs()
		{
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Expected O, but got Unknown
			if (PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient)
			{
				object[] array = new object[7]
				{
					125,
					(byte)1,
					ConfigDarknessMultiplier.Value,
					ConfigIntensity.Value,
					ConfigRange.Value,
					ConfigStartHour.Value,
					ConfigEndHour.Value
				};
				Log.LogInfo((object)$"[Network] Broadcasting Env Config: Multiplier={ConfigDarknessMultiplier.Value}");
				PhotonNetwork.RaiseEvent((byte)148, (object)array, new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)0
				}, SendOptions.SendReliable);
			}
		}

		private void Update()
		{
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			if (!ConfigMasterSwitch.Value || (Object)(object)Character.localCharacter == (Object)null)
			{
				return;
			}
			CharacterData data = Character.localCharacter.data;
			Item val = ((data != null) ? data.currentItem : null);
			if (!((Object)(object)val != (Object)null) || val.itemID != 42)
			{
				return;
			}
			LanternSyncHelper component = ((Component)val).GetComponent<LanternSyncHelper>();
			if (!((Object)(object)component == (Object)null))
			{
				Lantern component2 = ((Component)val).GetComponent<Lantern>();
				if ((bool)(typeof(Lantern).GetField("lit", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(component2) ?? ((object)false)) && Input.GetKeyDown(ToggleKey.Value))
				{
					component.localInstanceMode = ((component.localInstanceMode == LanternState.Omni) ? LanternState.Flashlight : LanternState.Omni);
					Log.LogDebug((object)$"[Input] 当前提灯切换模式: {component.localInstanceMode}");
				}
			}
		}
	}
	public class BPR_NetProxy : MonoBehaviourPunCallbacks, IOnEventCallback
	{
		public override void OnJoinedRoom()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			if (!PhotonNetwork.IsMasterClient)
			{
				object[] array = new object[2]
				{
					125,
					(byte)2
				};
				BlackPeakRemix.Log.LogInfo((object)"[Network] Joined room as client. Requesting config from Master...");
				PhotonNetwork.RaiseEvent((byte)148, (object)array, new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)2
				}, SendOptions.SendReliable);
			}
		}

		public void OnEvent(EventData e)
		{
			if (e == null || e.Code != 148 || !(e.CustomData is object[] array) || array.Length < 2)
			{
				return;
			}
			if (!(array[0] is int num) || num != 125)
			{
				BlackPeakRemix.Log.LogWarning((object)$"[Network] Received BPR message but version mismatch! Received: {array[0]}, Local: {125}");
				return;
			}
			switch ((BPR_SubType)(byte)array[1])
			{
			case BPR_SubType.ConfigSync:
				if (array.Length < 7)
				{
					BlackPeakRemix.Log.LogWarning((object)"[Network] Received ConfigSync but packet length is insufficient.");
					break;
				}
				BlackPeakRemix.IsSyncingFromNet = true;
				try
				{
					BlackPeakRemix.ActiveDarknessMultiplier = Convert.ToSingle(array[2]);
					BlackPeakRemix.ActiveIntensity = Convert.ToSingle(array[3]);
					BlackPeakRemix.ActiveRange = Convert.ToSingle(array[4]);
					BlackPeakRemix.ActiveStartHour = Convert.ToSingle(array[5]);
					BlackPeakRemix.ActiveEndHour = Convert.ToSingle(array[6]);
					BlackPeakRemix.Log.LogInfo((object)"[Network] Successfully synchronized environment parameters from Master.");
					break;
				}
				catch (Exception ex)
				{
					BlackPeakRemix.Log.LogError((object)("[Network] Error parsing synced config: " + ex.Message));
					break;
				}
				finally
				{
					BlackPeakRemix.IsSyncingFromNet = false;
				}
			case BPR_SubType.ConfigRequest:
				if (PhotonNetwork.IsMasterClient)
				{
					BlackPeakRemix.Log.LogInfo((object)$"[Network] Received config request from Player {e.Sender}. Broadcasting current settings...");
					BlackPeakRemix.BroadcastConfigs();
				}
				break;
			}
		}

		public override void OnEnable()
		{
			PhotonNetwork.AddCallbackTarget((object)this);
		}

		public override void OnDisable()
		{
			PhotonNetwork.RemoveCallbackTarget((object)this);
		}
	}
	public class LanternSyncHelper : MonoBehaviour, IOnEventCallback
	{
		private Lantern _lantern;

		private Light _light;

		private PhotonView _view;

		private float _smoothInt;

		private static FieldInfo _fLit;

		private Camera _cachedCamera;

		private LanternState _remoteMode;

		public LanternState localInstanceMode;

		private Quaternion _remoteRot = Quaternion.identity;

		private Quaternion _lastSentRot = Quaternion.identity;

		private LanternState _lastSentMode;

		private float _lastSyncTimestamp;

		public void Init(Lantern l)
		{
			_lantern = l;
			_light = l.lanternLight;
			_view = ((Component)l).GetComponent<PhotonView>();
			_fLit = typeof(Lantern).GetField("lit", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		}

		public void OnEvent(EventData photonEvent)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			if (photonEvent.Code == 148 && !((Object)(object)_view == (Object)null) && photonEvent.CustomData is object[] array && (int)array[0] == 125 && (byte)array[1] == 0 && (int)array[2] == _view.ViewID)
			{
				_remoteMode = (LanternState)(byte)array[3];
				if (array.Length >= 5)
				{
					_remoteRot = (Quaternion)array[4];
				}
			}
		}

		private void Update()
		{
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Invalid comparison between Unknown and I4
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)_light) || (Object)(object)_view == (Object)null || (Object)(object)_lantern == (Object)null)
			{
				return;
			}
			bool isMine = _view.IsMine;
			bool flag = (bool)(_fLit?.GetValue(_lantern) ?? ((object)false));
			_cachedCamera = Camera.main;
			if (isMine)
			{
				HandleLocalSync(flag);
			}
			if (!flag)
			{
				if (((Behaviour)_light).enabled)
				{
					((Behaviour)_light).enabled = false;
				}
				return;
			}
			if (!((Behaviour)_light).enabled)
			{
				((Behaviour)_light).enabled = true;
			}
			_smoothInt = Mathf.Lerp(_smoothInt, BlackPeakRemix.ActiveIntensity, Time.deltaTime * 5f);
			_light.intensity = _smoothInt;
			if ((isMine ? localInstanceMode : _remoteMode) == LanternState.Flashlight)
			{
				if ((int)_light.type != 0)
				{
					_light.type = (LightType)0;
				}
				_light.range = BlackPeakRemix.ActiveRange;
				_light.spotAngle = 45f;
				Quaternion val = ((!isMine) ? _remoteRot : (Object.op_Implicit((Object)(object)_cachedCamera) ? ((Component)_cachedCamera).transform.rotation : ((Component)this).transform.rotation));
				((Component)_light).transform.rotation = Quaternion.Slerp(((Component)_light).transform.rotation, val, Time.deltaTime * 10f);
			}
			else
			{
				if ((int)_light.type != 2)
				{
					_light.type = (LightType)2;
				}
				_light.range = 35f;
			}
		}

		private void HandleLocalSync(bool isLit)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			if (!PhotonNetwork.InRoom || _view.ViewID <= 0 || !isLit)
			{
				return;
			}
			float num = Time.time - _lastSyncTimestamp;
			LanternState lanternState = localInstanceMode;
			Quaternion val = (Object.op_Implicit((Object)(object)_cachedCamera) ? ((Component)_cachedCamera).transform.rotation : ((Component)this).transform.rotation);
			if (lanternState != _lastSentMode)
			{
				SendSyncPacket(lanternState, val, reliable: true);
				_lastSentMode = lanternState;
				_lastSentRot = val;
			}
			else if (lanternState == LanternState.Flashlight && !(num < 0.2f))
			{
				bool num2 = Quaternion.Angle(_lastSentRot, val) > 10f;
				bool flag = num > 1f && Quaternion.Angle(_lastSentRot, val) != 0f;
				if (num2 || flag)
				{
					SendSyncPacket(lanternState, val, reliable: false);
					_lastSentRot = val;
					_lastSyncTimestamp = Time.time;
				}
			}
		}

		private void SendSyncPacket(LanternState mode, Quaternion rot, bool reliable)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			object[] array = new object[5]
			{
				125,
				(byte)0,
				_view.ViewID,
				(byte)mode,
				rot
			};
			PhotonNetwork.RaiseEvent((byte)148, (object)array, new RaiseEventOptions
			{
				Receivers = (ReceiverGroup)0
			}, reliable ? SendOptions.SendReliable : SendOptions.SendUnreliable);
		}

		public void OnEnable()
		{
			PhotonNetwork.AddCallbackTarget((object)this);
		}

		public void OnDisable()
		{
			PhotonNetwork.RemoveCallbackTarget((object)this);
		}
	}
	[HarmonyPatch(typeof(Lantern), "Start")]
	internal static class Patch_Lantern_Init
	{
		private static void Postfix(Lantern __instance)
		{
			if (BlackPeakRemix.ConfigMasterSwitch.Value && ((int?)((Component)__instance).GetComponent<Item>()?.itemID).GetValueOrDefault() == 42 && (Object)(object)((Component)__instance).GetComponent<PhotonView>() != (Object)null)
			{
				((Component)__instance).gameObject.getOrAddComponent<LanternSyncHelper>().Init(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(Lantern))]
	internal static class Patch_Lantern_InfiniteFuel
	{
		private static bool IsNormalLantern(Lantern ln)
		{
			Item component = ((Component)ln).GetComponent<Item>();
			if ((Object)(object)component != (Object)null)
			{
				return component.itemID == 42;
			}
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("UpdateFuel")]
		private static bool PreUpdateFuel(Lantern __instance)
		{
			if (BlackPeakRemix.ConfigMasterSwitch.Value && BlackPeakRemix.ConfigInfiniteFuel.Value && IsNormalLantern(__instance))
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Campfire), "Update")]
	internal static class Patch_Campfire_Glow_Enhanced
	{
		private static void Postfix(Campfire __instance)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Invalid comparison between Unknown and I4
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			if (BlackPeakRemix.ConfigMasterSwitch.Value)
			{
				bool active = (int)__instance.state == 1;
				BPR_GlowController.ApplyGlow(((Component)__instance).gameObject, "BPR_CampfireLight_Enhanced", new Color(1f, 0.6f, 0.2f), 30f, 50f, active, new Vector3(0f, 3f, 0f), (LightShadows)2);
			}
		}
	}
	[HarmonyPatch(typeof(CharacterSpawner))]
	internal static class Patch_CharacterSpawner_FirstSpawn
	{
		[CompilerGenerated]
		private sealed class <DelayedGiveRoutine>d__2 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public float delay;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <DelayedGiveRoutine>d__2(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(delay);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if ((Object)(object)Character.localCharacter?.refs?.items != (Object)null)
					{
						CharacterItems items = Character.localCharacter.refs.items;
						MethodInfo methodInfo = AccessTools.Method(((object)items).GetType(), "SpawnItemInHand", (Type[])null, (Type[])null);
						if (methodInfo != null)
						{
							methodInfo.Invoke(items, new object[1] { "Lantern" });
							_hasGivenLanternThisSession = true;
							BlackPeakRemix.Log.LogInfo((object)"[AutoGive] First spawn detected. Lantern granted after delay.");
						}
					}
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <Postfix>d__1 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public IEnumerator __result;

			public CharacterSpawner __instance;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <Postfix>d__1(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (__result.MoveNext())
				{
					<>2__current = __result.Current;
					<>1__state = 1;
					return true;
				}
				if (!BlackPeakRemix.ConfigMasterSwitch.Value || _hasGivenLanternThisSession)
				{
					return false;
				}
				((MonoBehaviour)__instance).StartCoroutine(DelayedGiveRoutine(10f));
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static bool _hasGivenLanternThisSession;

		[IteratorStateMachine(typeof(<Postfix>d__1))]
		[HarmonyPostfix]
		[HarmonyPatch("SpawnLocalPlayer")]
		private static IEnumerator Postfix(IEnumerator __result, CharacterSpawner __instance)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <Postfix>d__1(0)
			{
				__result = __result,
				__instance = __instance
			};
		}

		[IteratorStateMachine(typeof(<DelayedGiveRoutine>d__2))]
		private static IEnumerator DelayedGiveRoutine(float delay)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DelayedGiveRoutine>d__2(0)
			{
				delay = delay
			};
		}

		public static void ResetSession()
		{
			_hasGivenLanternThisSession = false;
		}
	}
	[HarmonyPatch(typeof(Lantern), "Update")]
	internal static class Patch_Lantern_Visuals
	{
		[HarmonyPostfix]
		private static void Postfix(Lantern __instance)
		{
			if (BlackPeakRemix.ConfigMasterSwitch.Value)
			{
				LanternVisualController.UpdateLanternVisuals(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(PlayerGhost), "Update")]
	internal static class Patch_Character_GhostGlow
	{
		[HarmonyPostfix]
		private static void Postfix(PlayerGhost __instance)
		{
			//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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			if (BlackPeakRemix.ConfigMasterSwitch.Value && !((Object)(object)__instance.m_owner == (Object)null))
			{
				Color playerColor = __instance.m_owner.refs.customization.PlayerColor;
				BPR_GlowController.ApplyGlow(((Component)__instance).gameObject, "BPR_GhostGlow", playerColor, 8f, 5f, active: true, Vector3.up * 0.5f, (LightShadows)0);
			}
		}
	}
	[HarmonyPatch(typeof(Flare), "Update")]
	internal static class Patch_Flare_Visuals_Refined
	{
		[HarmonyPostfix]
		private static void Postfix(Flare __instance)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			if (BlackPeakRemix.ConfigMasterSwitch.Value)
			{
				bool value = ((ItemComponent)__instance).GetData<BoolItemData>((DataEntryKey)3).Value;
				BPR_GlowController.ApplyGlow(((Component)__instance).gameObject, "BPR_FlareLight", __instance.flareColor, BlackPeakRemix.ActiveIntensity * 1.5f, 45f, value, Vector3.zero, (LightShadows)0);
			}
		}
	}
	public static class LanternVisualController
	{
		public static void UpdateLanternVisuals(Lantern lantern)
		{
			if (!((Object)(object)lantern.lanternLight == (Object)null))
			{
				Item component = ((Component)lantern).GetComponent<Item>();
				if (!((Object)(object)component == (Object)null) && component.itemID == 42)
				{
					PhotonView component2 = ((Component)component).GetComponent<PhotonView>();
					HandleColorOwnership(lantern, component, component2);
					ApplySyncedColor(lantern);
				}
			}
		}

		private static void HandleColorOwnership(Lantern lantern, Item item, PhotonView pView)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)pView != (Object)null && pView.IsMine && (Object)(object)item.holderCharacter != (Object)null)
			{
				Color targetColorByConfig = GetTargetColorByConfig(item.holderCharacter);
				ColorItemData data = ((ItemComponent)lantern).GetData<ColorItemData>((DataEntryKey)9);
				if (data.Value != targetColorByConfig)
				{
					data.Value = targetColorByConfig;
				}
				lantern.lanternLight.shadows = (LightShadows)0;
			}
		}

		private static void ApplySyncedColor(Lantern lantern)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			if (((ItemComponent)lantern).HasData((DataEntryKey)9))
			{
				Color value = ((ItemComponent)lantern).GetData<ColorItemData>((DataEntryKey)9).Value;
				if (lantern.lanternLight.color != value)
				{
					lantern.lanternLight.color = value;
				}
			}
		}

		private static Color GetTargetColorByConfig(Character holder)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			return (Color)(BlackPeakRemix.ConfigLanternMode.Value switch
			{
				LanternColorMode.Original => new Color(1f, 0.6f, 0.3f), 
				LanternColorMode.Custom => BlackPeakRemix.ActiveCustomColor, 
				LanternColorMode.FollowPlayer => holder.refs.customization.PlayerColor, 
				_ => new Color(1f, 0.6f, 0.3f), 
			});
		}
	}
	public static class BPR_GlowController
	{
		public static void ApplyGlow(GameObject parent, string childName, Color color, float intensity, float range, bool active, Vector3 localPos, LightShadows shadowMode = 0)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			Transform obj = parent.transform.Find(childName);
			Light val = ((obj != null) ? ((Component)obj).GetComponent<Light>() : null);
			if (active)
			{
				if ((Object)(object)val == (Object)null)
				{
					GameObject val2 = new GameObject(childName);
					val2.transform.SetParent(parent.transform);
					val2.transform.localPosition = localPos;
					val = val2.AddComponent<Light>();
					val.type = (LightType)2;
				}
				((Behaviour)val).enabled = true;
				val.color = color;
				val.intensity = intensity;
				val.range = range;
				if (val.shadows != shadowMode)
				{
					val.shadows = shadowMode;
				}
			}
			else if ((Object)(object)val != (Object)null)
			{
				((Behaviour)val).enabled = false;
			}
		}
	}
	public static class BPR_Extensions
	{
		public static T getOrAddComponent<T>(this GameObject go) where T : Component
		{
			T val = go.GetComponent<T>();
			if (!Object.op_Implicit((Object)(object)val))
			{
				val = go.AddComponent<T>();
			}
			return val;
		}
	}
	public static class BPR_EnvironmentController
	{
		public static readonly int ID_Brightness = Shader.PropertyToID("brightness");

		public static readonly int ID_AmbienceStrength = Shader.PropertyToID("ambienceStrength");

		public static readonly int ID_AmbienceMin = Shader.PropertyToID("ambienceMin");

		public static readonly int ID_SkyTop = Shader.PropertyToID("SkyTopColor");

		public static readonly int ID_SkyMid = Shader.PropertyToID("SkyMidColor");

		public static readonly int ID_SkyBot = Shader.PropertyToID("SkyBottomColor");

		public static void ApplyNightEffect(DayNightManager manager, float ActiveDarkness, bool hasNightVision)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Clamp01(ActiveDarkness);
			if (hasNightVision && (num < 0.15f || Mathf.Approximately(num, 0.15f)))
			{
				num = (Mathf.Approximately(num, 0.15f) ? 0.18f : 0.15f);
			}
			if ((Object)(object)manager.sun != (Object)null)
			{
				manager.sun.intensity = num;
			}
			if ((Object)(object)manager.moon != (Object)null)
			{
				manager.moon.intensity = num * 0.5f;
			}
			Color globalColor = Shader.GetGlobalColor(ID_SkyMid);
			Color globalColor2 = Shader.GetGlobalColor(ID_SkyBot);
			Shader.SetGlobalColor(ID_SkyTop, Color.black);
			Shader.SetGlobalColor(ID_SkyMid, globalColor * 0.05f);
			Shader.SetGlobalColor(ID_SkyBot, globalColor2 * 0.05f);
			Shader.SetGlobalFloat(ID_Brightness, 1f);
			Shader.SetGlobalFloat(ID_AmbienceStrength, num);
			Shader.SetGlobalFloat(ID_AmbienceMin, hasNightVision ? 0.015f : 0.003f);
			RenderSettings.ambientLight = Color.Lerp(RenderSettings.ambientLight, globalColor, 0.4f) * num;
			RenderSettings.reflectionIntensity = num;
			RenderSettings.fog = true;
		}

		public static void RestoreDefault()
		{
			Shader.SetGlobalFloat(ID_Brightness, 1f);
			Shader.SetGlobalFloat(ID_AmbienceStrength, 1f);
			Shader.SetGlobalFloat(ID_AmbienceMin, 0.2f);
			RenderSettings.reflectionIntensity = 1f;
		}
	}
	[HarmonyPatch(typeof(DayNightManager), "Update")]
	internal static class Patch_DayNight_AdvancedDarkness
	{
		[HarmonyPostfix]
		private static void Postfix(DayNightManager __instance)
		{
			if (BlackPeakRemix.ConfigMasterSwitch.Value && !((Object)(object)__instance == (Object)null))
			{
				float timeOfDay = __instance.timeOfDay;
				float activeStartHour = BlackPeakRemix.ActiveStartHour;
				float activeEndHour = BlackPeakRemix.ActiveEndHour;
				bool num = ((!(activeStartHour > activeEndHour)) ? (timeOfDay >= activeStartHour && timeOfDay < activeEndHour) : (timeOfDay >= activeStartHour || timeOfDay < activeEndHour));
				bool flag = false;
				if ((Object)(object)Character.localCharacter != (Object)null)
				{
					flag = Character.localCharacter.IsGhost;
				}
				bool hasNightVision = flag || Patch_Binoculars_Vision.IsUsingBinoculars;
				if (num)
				{
					BPR_EnvironmentController.ApplyNightEffect(__instance, BlackPeakRemix.ActiveDarknessMultiplier, hasNightVision);
				}
				else
				{
					BPR_EnvironmentController.RestoreDefault();
				}
			}
		}
	}
	[HarmonyPatch(typeof(LightVolume), "SetShaderVars")]
	internal static class Patch_LightVolume_Guard
	{
		[HarmonyPrefix]
		private static void Prefix(LightVolume __instance)
		{
			if (!BlackPeakRemix.ConfigMasterSwitch.Value)
			{
				return;
			}
			float timeOfDay = DayNightManager.instance.timeOfDay;
			float activeStartHour = BlackPeakRemix.ActiveStartHour;
			float activeEndHour = BlackPeakRemix.ActiveEndHour;
			bool num = ((!(activeStartHour > activeEndHour)) ? (timeOfDay >= activeStartHour && timeOfDay < activeEndHour) : (timeOfDay >= activeStartHour || timeOfDay < activeEndHour));
			bool flag = false;
			if ((Object)(object)Character.localCharacter != (Object)null)
			{
				flag = Character.localCharacter.IsGhost;
			}
			bool flag2 = flag || Patch_Binoculars_Vision.IsUsingBinoculars;
			if (!num)
			{
				return;
			}
			float num2 = BlackPeakRemix.ActiveDarknessMultiplier;
			if (flag2)
			{
				if (num2 < 0.15f)
				{
					num2 = 0.15f;
				}
				else if (Mathf.Approximately(num2, 0.15f))
				{
					num2 = 0.18f;
				}
			}
			__instance.brightness = 1f;
			__instance.ambienceStrength = num2;
			__instance.ambienceMin = (flag2 ? 0.01f : 0f);
		}
	}
	[HarmonyPatch(typeof(GUIManager), "LateUpdate")]
	internal static class Patch_GUIManager_GhostFX
	{
		private static void Postfix(GUIManager __instance)
		{
			if (BlackPeakRemix.ConfigMasterSwitch.Value && BlackPeakRemix.ConfigGhostFX.Value && (Object)(object)Character.localCharacter != (Object)null && Character.localCharacter.IsGhost && (Object)(object)__instance.poisonSVFX != (Object)null)
			{
				__instance.poisonSVFX.Play(0.5f);
			}
		}
	}
	[HarmonyPatch(typeof(Action_ShowBinocularOverlay))]
	internal static class Patch_Binoculars_Vision
	{
		public static bool IsUsingBinoculars;

		[HarmonyPostfix]
		[HarmonyPatch("RunAction")]
		private static void PostfixRunAction(Action_ShowBinocularOverlay __instance)
		{
			if (!__instance.isProp)
			{
				IsUsingBinoculars = __instance.binocularsActive;
			}
		}
	}
}