Decompiled source of FlashlightRework v2.0.0

plugins/FlashlightRework.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using PxntxrezStudio.RepoFlashlightRework;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("FlashlightRework")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FlashlightRework")]
[assembly: AssemblyTitle("FlashlightRework")]
[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;
		}
	}
}
[BepInPlugin("PxntxrezStudio.RepoFlashlightRework", "REPO Flashlight Rework", "2.0.0")]
public class FlashlightReworkPlugin : BaseUnityPlugin
{
	private Harmony _harmony;

	private void Awake()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		FlashlightConfig.Init(((BaseUnityPlugin)this).Config);
		_harmony = new Harmony("PxntxrezStudio.RepoFlashlightRework");
		_harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
	}
}
public static class Patch_FlashlightController_Start
{
	[HarmonyPatch(typeof(FlashlightController), "Start")]
	public static class Patch
	{
		public static void Postfix(FlashlightController __instance)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			PlayerAvatar playerAvatar = __instance.PlayerAvatar;
			if (getIsLocal.Invoke(playerAvatar))
			{
				if (!originalColors.ContainsKey(__instance))
				{
					originalColors[__instance] = __instance.spotlight.color;
				}
				TryStartFlicker(__instance);
			}
		}
	}

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

		private object <>2__current;

		public FlashlightController flashlight;

		private float <detectionRadius>5__2;

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

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

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

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

		private bool MoveNext()
		{
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Expected O, but got Unknown
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Expected O, but got Unknown
			Collider[] array;
			bool flag;
			Collider[] array2;
			float num2;
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<detectionRadius>5__2 = FlashlightConfig.FlickerDetectionRadius.Value;
				goto IL_003a;
			case 1:
				<>1__state = -1;
				goto IL_003a;
			case 2:
				<>1__state = -1;
				goto IL_003a;
			case 3:
			{
				<>1__state = -1;
				SetFlickerState(flashlight, enabled: true);
				float num = Random.Range(FlashlightConfig.FlickerIntervalMin.Value, FlashlightConfig.FlickerIntervalMax.Value);
				<>2__current = (object)new WaitForSeconds(num);
				<>1__state = 4;
				return true;
			}
			case 4:
				{
					<>1__state = -1;
					goto IL_003a;
				}
				IL_003a:
				if (!FlashlightConfig.EnableFlicker.Value || !flashlight.LightActive)
				{
					SetFlickerState(flashlight, flashlight.LightActive);
					<>2__current = (object)new WaitForSeconds(0.2f);
					<>1__state = 1;
					return true;
				}
				array = Physics.OverlapSphere(((Component)flashlight).transform.position, <detectionRadius>5__2);
				flag = false;
				array2 = array;
				for (int i = 0; i < array2.Length; i++)
				{
					if ((Object)(object)((Component)array2[i]).GetComponentInParent<EnemyChecklist>() != (Object)null)
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					if (!((Behaviour)flashlight.spotlight).enabled)
					{
						SetFlickerState(flashlight, enabled: true);
					}
					<>2__current = (object)new WaitForSeconds(0.5f);
					<>1__state = 2;
					return true;
				}
				SetFlickerState(flashlight, enabled: false);
				num2 = Random.Range(FlashlightConfig.FlickerDurationMin.Value, FlashlightConfig.FlickerDurationMax.Value);
				<>2__current = (object)new WaitForSeconds(num2);
				<>1__state = 3;
				return true;
			}
		}

		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 readonly FieldRef<PlayerAvatar, bool> getIsLocal = AccessTools.FieldRefAccess<PlayerAvatar, bool>("isLocal");

	public static readonly Dictionary<FlashlightController, Color> originalColors = new Dictionary<FlashlightController, Color>();

	private static readonly Dictionary<FlashlightController, Coroutine> activeFlickers = new Dictionary<FlashlightController, Coroutine>();

	public static void TryStartFlicker(FlashlightController flashlight)
	{
		if (!FlashlightConfig.EnableFlicker.Value)
		{
			StopFlicker(flashlight);
		}
		else if (!activeFlickers.ContainsKey(flashlight))
		{
			Coroutine value = ((MonoBehaviour)flashlight).StartCoroutine(FlickerCoroutine(flashlight));
			activeFlickers[flashlight] = value;
		}
	}

	public static void StopFlicker(FlashlightController flashlight)
	{
		if (activeFlickers.TryGetValue(flashlight, out var value))
		{
			((MonoBehaviour)flashlight).StopCoroutine(value);
			activeFlickers.Remove(flashlight);
		}
		if (!flashlight.LightActive)
		{
			((Behaviour)flashlight.spotlight).enabled = false;
			flashlight.halo.enabled = false;
		}
		else
		{
			((Behaviour)flashlight.spotlight).enabled = true;
			flashlight.halo.enabled = true;
		}
	}

	[IteratorStateMachine(typeof(<FlickerCoroutine>d__6))]
	public static IEnumerator FlickerCoroutine(FlashlightController flashlight)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <FlickerCoroutine>d__6(0)
		{
			flashlight = flashlight
		};
	}

	private static void SetFlickerState(FlashlightController flashlight, bool enabled)
	{
		((Behaviour)flashlight.spotlight).enabled = enabled;
		flashlight.halo.enabled = enabled;
		PlayerAvatar playerAvatar = flashlight.PlayerAvatar;
		if (!((Object)(object)playerAvatar == (Object)null) && !((Object)(object)playerAvatar.photonView == (Object)null) && playerAvatar.photonView.IsMine)
		{
			if ((Object)(object)((Component)playerAvatar).GetComponent<FlashlightRPCHandler>() == (Object)null)
			{
				Debug.LogWarning((object)"FlashlightRPCHandler not found! Adding it now...");
				((Component)playerAvatar).gameObject.AddComponent<FlashlightRPCHandler>();
			}
			playerAvatar.photonView.RPC("RPC_FlashlightFlicker", (RpcTarget)1, new object[1] { enabled });
		}
	}

	public static void OnFlickerSettingChanged()
	{
		FlashlightController[] array = Object.FindObjectsOfType<FlashlightController>();
		foreach (FlashlightController val in array)
		{
			PlayerAvatar playerAvatar = val.PlayerAvatar;
			if (getIsLocal.Invoke(playerAvatar))
			{
				if (FlashlightConfig.EnableFlicker.Value)
				{
					TryStartFlicker(val);
				}
				else
				{
					StopFlicker(val);
				}
			}
		}
	}
}
[HarmonyPatch(typeof(FlashlightController), "Update")]
internal static class Patch_FlashlightController_Update
{
	private static readonly FieldInfo fiCurrentState = AccessTools.Field(typeof(FlashlightController), "currentState");

	private static readonly FieldInfo fiStateTimer = AccessTools.Field(typeof(FlashlightController), "stateTimer");

	private static readonly FieldInfo fiIntroRotLerp = AccessTools.Field(typeof(FlashlightController), "introRotLerp");

	private static readonly FieldInfo fiIntroYLerp = AccessTools.Field(typeof(FlashlightController), "introYLerp");

	private static readonly FieldInfo fiActive = AccessTools.Field(typeof(FlashlightController), "active");

	private static readonly FieldRef<PlayerAvatar, bool> getIsLocal = AccessTools.FieldRefAccess<PlayerAvatar, bool>("isLocal");

	private static readonly FieldRef<PlayerAvatar, bool> getIsDisabled = AccessTools.FieldRefAccess<PlayerAvatar, bool>("isDisabled");

	private static readonly FieldInfo fiClick = AccessTools.Field(typeof(FlashlightController), "click");

	private static readonly Dictionary<FlashlightController, float> lastToggle = new Dictionary<FlashlightController, float>();

	private static readonly Dictionary<FlashlightController, bool> autoStarted = new Dictionary<FlashlightController, bool>();

	private static readonly Dictionary<FlashlightController, Color> syncedColors = new Dictionary<FlashlightController, Color>();

	private const float toggleCooldown = 1.3f;

	private static bool Prefix(FlashlightController __instance)
	{
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Invalid comparison between Unknown and I4
		//IL_0284: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: 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)
		PlayerAvatar playerAvatar = __instance.PlayerAvatar;
		if (getIsDisabled.Invoke(playerAvatar))
		{
			if (fiCurrentState.GetValue(__instance).ToString() != "Hidden")
			{
				fiCurrentState.SetValue(__instance, Enum.Parse(fiCurrentState.FieldType, "Hidden"));
				((Renderer)__instance.mesh).enabled = false;
				((Behaviour)__instance.spotlight).enabled = false;
				__instance.halo.enabled = false;
				__instance.LightActive = false;
				AccessTools.Field(typeof(FlashlightController), "hiddenScale").SetValue(__instance, 0f);
			}
			return false;
		}
		if (getIsLocal.Invoke(playerAvatar))
		{
			if (!autoStarted.ContainsKey(__instance) && (int)GameDirector.instance.currentState >= 2)
			{
				autoStarted[__instance] = true;
				SyncFlashlightState(__instance, turnOn: true);
			}
			float value;
			bool flag = !lastToggle.TryGetValue(__instance, out value) || Time.time - value >= 1.3f;
			if (Input.GetKeyDown(FlashlightConfig.GetKeyCode()) && flag)
			{
				lastToggle[__instance] = Time.time;
				bool turnOn = !__instance.LightActive;
				SyncFlashlightState(__instance, turnOn);
			}
			switch (fiCurrentState.GetValue(__instance).ToString())
			{
			case "Intro":
			case "LightOn":
			case "Idle":
				fiActive.SetValue(__instance, true);
				break;
			}
			ProcessFlashlightStates(__instance);
			UpdateFlashlightScale(__instance, playerAvatar);
			if (getIsLocal.Invoke(playerAvatar))
			{
				UpdateFlashlightColorLocal(__instance);
			}
			else
			{
				UpdateFlashlightColorSynced(__instance);
			}
			UpdateClickAnimation(__instance);
			return false;
		}
		if (!getIsLocal.Invoke(playerAvatar))
		{
			((Component)__instance).transform.position = __instance.FollowTransformClient.position;
			((Component)__instance).transform.rotation = __instance.FollowTransformClient.rotation;
			((Component)__instance).transform.localScale = __instance.FollowTransformClient.localScale;
			switch (fiCurrentState.GetValue(__instance).ToString())
			{
			case "Intro":
			case "LightOn":
			case "Idle":
				fiActive.SetValue(__instance, true);
				break;
			}
			ProcessFlashlightStates(__instance);
			float num = (float)AccessTools.Field(typeof(FlashlightController), "hiddenScale").GetValue(__instance);
			((Component)__instance).transform.localScale = __instance.FollowTransformClient.localScale * num;
			UpdateClickAnimation(__instance);
			UpdateFlashlightColorSynced(__instance);
			return false;
		}
		return true;
	}

	private static void UpdateFlashlightScale(FlashlightController flashlight, PlayerAvatar avatar)
	{
		//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_003a: 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)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		float num = (float)AccessTools.Field(typeof(FlashlightController), "hiddenScale").GetValue(flashlight);
		if (!getIsLocal.Invoke(avatar))
		{
			((Component)flashlight).transform.position = flashlight.FollowTransformClient.position;
			((Component)flashlight).transform.rotation = flashlight.FollowTransformClient.rotation;
			((Component)flashlight).transform.localScale = flashlight.FollowTransformClient.localScale * num;
		}
		else
		{
			((Component)flashlight).transform.localScale = Vector3.one * num;
		}
	}

	private static void ProcessFlashlightStates(FlashlightController flashlight)
	{
		switch (fiCurrentState.GetValue(flashlight).ToString())
		{
		case "Intro":
			CallMethod(flashlight, "Intro");
			break;
		case "LightOn":
			CallMethod(flashlight, "LightOn");
			break;
		case "Idle":
			CustomIdle(flashlight);
			break;
		case "LightOff":
			CallMethod(flashlight, "LightOff");
			break;
		case "Outro":
			CallMethod(flashlight, "Outro");
			break;
		case "Hidden":
			CustomHidden(flashlight);
			break;
		}
	}

	private static void CustomIdle(FlashlightController flashlight)
	{
	}

	private static void CustomHidden(FlashlightController flashlight)
	{
	}

	private static void CallMethod(FlashlightController flashlight, string methodName)
	{
		MethodInfo methodInfo = AccessTools.Method(typeof(FlashlightController), methodName, (Type[])null, (Type[])null);
		if (methodInfo != null)
		{
			methodInfo.Invoke(flashlight, null);
		}
	}

	private static void UpdateClickAnimation(FlashlightController flashlight)
	{
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Expected O, but got Unknown
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		FieldInfo fieldInfo = AccessTools.Field(typeof(FlashlightController), "clickLerp");
		FieldInfo fieldInfo2 = AccessTools.Field(typeof(FlashlightController), "clickSpeed");
		FieldInfo fieldInfo3 = AccessTools.Field(typeof(FlashlightController), "clickStrength");
		FieldInfo fieldInfo4 = AccessTools.Field(typeof(FlashlightController), "clickCurve");
		FieldInfo fieldInfo5 = AccessTools.Field(typeof(FlashlightController), "clickTransform");
		if ((bool)fiClick.GetValue(flashlight))
		{
			float num = (float)fieldInfo.GetValue(flashlight);
			float num2 = (float)fieldInfo2.GetValue(flashlight);
			float num3 = (float)fieldInfo3.GetValue(flashlight);
			AnimationCurve val = (AnimationCurve)fieldInfo4.GetValue(flashlight);
			Transform val2 = (Transform)fieldInfo5.GetValue(flashlight);
			float num4 = Mathf.LerpUnclamped(0f, num3, val.Evaluate(num));
			val2.localRotation = Quaternion.Euler(0f, 0f - num4, 0f);
			num += num2 * Time.deltaTime;
			num = Mathf.Clamp01(num);
			fieldInfo.SetValue(flashlight, num);
			if (num == 1f)
			{
				fieldInfo.SetValue(flashlight, 0f);
				fiClick.SetValue(flashlight, false);
			}
		}
	}

	private static void UpdateFlashlightColorLocal(FlashlightController flashlight)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: 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_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: 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_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: 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_0052: 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_005d: 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_0069: Unknown result type (might be due to invalid IL or missing references)
		if (!flashlight.LightActive)
		{
			return;
		}
		Color val;
		if (FlashlightConfig.UseCustomRGB.Value)
		{
			val = FlashlightConfig.GetColor();
		}
		else
		{
			if (!Patch_FlashlightController_Start.originalColors.TryGetValue(flashlight, out var value))
			{
				return;
			}
			val = value;
		}
		if (!syncedColors.TryGetValue(flashlight, out var value2) || Vector3.Distance(new Vector3(val.r, val.g, val.b), new Vector3(value2.r, value2.g, value2.b)) > 0.01f)
		{
			syncedColors[flashlight] = val;
			SyncFlashlightColor(flashlight, val);
		}
	}

	private static void UpdateFlashlightColorSynced(FlashlightController flashlight)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		if (flashlight.LightActive && syncedColors.TryGetValue(flashlight, out var value))
		{
			ApplyFlashlightColor(flashlight, value);
		}
	}

	private static void SyncFlashlightState(FlashlightController flashlight, bool turnOn)
	{
		PlayerAvatar playerAvatar = flashlight.PlayerAvatar;
		if ((Object)(object)playerAvatar == (Object)null || (Object)(object)playerAvatar.photonView == (Object)null)
		{
			ApplyFlashlightToggle(flashlight, turnOn);
		}
		else if (playerAvatar.photonView.IsMine)
		{
			playerAvatar.photonView.RPC("RPC_FlashlightToggle", (RpcTarget)0, new object[1] { turnOn });
		}
		else
		{
			ApplyFlashlightToggle(flashlight, turnOn);
		}
	}

	public static void ApplyFlashlightToggle(FlashlightController flashlight, bool turnOn)
	{
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		if (turnOn && !flashlight.LightActive)
		{
			fiCurrentState.SetValue(flashlight, Enum.Parse(fiCurrentState.FieldType, "Intro"));
			fiStateTimer.SetValue(flashlight, 1f);
			fiIntroRotLerp.SetValue(flashlight, 0f);
			fiIntroYLerp.SetValue(flashlight, 0f);
			fiClick.SetValue(flashlight, true);
		}
		else if (!turnOn && flashlight.LightActive)
		{
			fiCurrentState.SetValue(flashlight, Enum.Parse(fiCurrentState.FieldType, "LightOff"));
			fiStateTimer.SetValue(flashlight, 0.25f);
			fiClick.SetValue(flashlight, true);
			flashlight.lightOffAudio.Play(((Component)flashlight).transform.position, 1f, 1f, 1f, 1f);
		}
	}

	private static void SyncFlashlightColor(FlashlightController flashlight, Color color)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: 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)
		PlayerAvatar playerAvatar = flashlight.PlayerAvatar;
		if ((Object)(object)playerAvatar == (Object)null || (Object)(object)playerAvatar.photonView == (Object)null)
		{
			ApplyFlashlightColor(flashlight, color);
		}
		else if (playerAvatar.photonView.IsMine)
		{
			playerAvatar.photonView.RPC("RPC_FlashlightColor", (RpcTarget)0, new object[3] { color.r, color.g, color.b });
		}
		else
		{
			ApplyFlashlightColor(flashlight, color);
		}
	}

	public static void ApplyFlashlightColor(FlashlightController flashlight, Color color)
	{
		//IL_0006: 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)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		flashlight.spotlight.color = color;
		if ((Object)(object)flashlight.halo == (Object)null)
		{
			return;
		}
		Behaviour halo = flashlight.halo;
		Light val = (Light)(object)((halo is Light) ? halo : null);
		if ((Object)(object)val != (Object)null)
		{
			val.color = color;
			return;
		}
		GameObject gameObject = ((Component)flashlight.halo).gameObject;
		if ((Object)(object)gameObject != (Object)null)
		{
			val = gameObject.GetComponent<Light>();
			if ((Object)(object)val != (Object)null)
			{
				val.color = color;
			}
		}
	}

	public static void SetSyncedColor(FlashlightController flashlight, Color color)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		syncedColors[flashlight] = color;
	}
}
namespace PxntxrezStudio.RepoFlashlightRework
{
	public static class FlashlightConfig
	{
		public static ConfigEntry<int> LightColorRed;

		public static ConfigEntry<int> LightColorGreen;

		public static ConfigEntry<int> LightColorBlue;

		public static ConfigEntry<bool> UseCustomRGB;

		public static ConfigEntry<string> FlashlightToggleKey;

		public static ConfigEntry<bool> EnableFlicker;

		public static ConfigEntry<float> FlickerDetectionRadius;

		public static ConfigEntry<float> FlickerDurationMin;

		public static ConfigEntry<float> FlickerDurationMax;

		public static ConfigEntry<float> FlickerIntervalMin;

		public static ConfigEntry<float> FlickerIntervalMax;

		private static ConfigFile config;

		public static void Init(ConfigFile cfg)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Expected O, but got Unknown
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Expected O, but got Unknown
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Expected O, but got Unknown
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Expected O, but got Unknown
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Expected O, but got Unknown
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Expected O, but got Unknown
			config = cfg;
			UseCustomRGB = cfg.Bind<bool>("Light Color", "Use Custom RGB Color", false, "Enable or disable RGB color override");
			LightColorRed = cfg.Bind<int>("Light Color", "Red", 255, new ConfigDescription("Light Color Red", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 255), Array.Empty<object>()));
			LightColorGreen = cfg.Bind<int>("Light Color", "Green", 255, new ConfigDescription("Light Color Green", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 255), Array.Empty<object>()));
			LightColorBlue = cfg.Bind<int>("Light Color", "Blue", 255, new ConfigDescription("Light Color Blue", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 255), Array.Empty<object>()));
			FlashlightToggleKey = cfg.Bind<string>("Controls", "Toggle Key", "F", new ConfigDescription("Flashlight toggle key", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[20]
			{
				"F", "R", "T", "Y", "U", "I", "O", "P", "G", "H",
				"J", "K", "L", "Z", "X", "C", "V", "B", "N", "M"
			}), Array.Empty<object>()));
			EnableFlicker = cfg.Bind<bool>("Flicker Settings", "Enable Flicker", true, "Enable flickering when enemy is nearby");
			FlickerDetectionRadius = cfg.Bind<float>("Flicker Settings", "Detection Radius", 30f, new ConfigDescription("Radius in meters to detect enemies (default: 30)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 100f), Array.Empty<object>()));
			FlickerDurationMin = cfg.Bind<float>("Flicker Settings", "Flicker Duration Min", 0.1f, new ConfigDescription("Minimum time flashlight stays OFF during flicker (seconds)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 50f), Array.Empty<object>()));
			FlickerDurationMax = cfg.Bind<float>("Flicker Settings", "Flicker Duration Max", 0.5f, new ConfigDescription("Maximum time flashlight stays OFF during flicker (seconds)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 50f), Array.Empty<object>()));
			FlickerIntervalMin = cfg.Bind<float>("Flicker Settings", "Flicker Interval Min", 1f, new ConfigDescription("Minimum time between flickers (seconds)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 100f), Array.Empty<object>()));
			FlickerIntervalMax = cfg.Bind<float>("Flicker Settings", "Flicker Interval Max", 15f, new ConfigDescription("Maximum time between flickers (seconds)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 100f), Array.Empty<object>()));
			cfg.SettingChanged += OnConfigChanged;
		}

		private static void OnConfigChanged(object sender, SettingChangedEventArgs e)
		{
			if (e.ChangedSetting.Definition.Key == "Enable Flicker")
			{
				Patch_FlashlightController_Start.OnFlickerSettingChanged();
			}
		}

		public static KeyCode GetKeyCode()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (Enum.TryParse<KeyCode>(FlashlightToggleKey.Value.ToUpper(), out KeyCode result))
			{
				return result;
			}
			return (KeyCode)102;
		}

		public static Color GetColor()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			return new Color((float)LightColorRed.Value / 255f, (float)LightColorGreen.Value / 255f, (float)LightColorBlue.Value / 255f);
		}
	}
	public class FlashlightRPCHandler : MonoBehaviour
	{
		private PlayerAvatar playerAvatar;

		private FlashlightController flashlight;

		private void Awake()
		{
			playerAvatar = ((Component)this).GetComponent<PlayerAvatar>();
			if ((Object)(object)playerAvatar != (Object)null)
			{
				flashlight = playerAvatar.flashlightController;
			}
		}

		[PunRPC]
		public void RPC_FlashlightToggle(bool turnOn)
		{
			if ((Object)(object)flashlight == (Object)null)
			{
				if ((Object)(object)playerAvatar != (Object)null)
				{
					flashlight = playerAvatar.flashlightController;
				}
				if ((Object)(object)flashlight == (Object)null)
				{
					return;
				}
			}
			Patch_FlashlightController_Update.ApplyFlashlightToggle(flashlight, turnOn);
		}

		[PunRPC]
		public void RPC_FlashlightColor(float r, float g, float b)
		{
			//IL_004c: 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)
			if ((Object)(object)flashlight == (Object)null)
			{
				if ((Object)(object)playerAvatar != (Object)null)
				{
					flashlight = playerAvatar.flashlightController;
				}
				if ((Object)(object)flashlight == (Object)null)
				{
					return;
				}
			}
			Color color = default(Color);
			((Color)(ref color))..ctor(r, g, b);
			Patch_FlashlightController_Update.SetSyncedColor(flashlight, color);
			Patch_FlashlightController_Update.ApplyFlashlightColor(flashlight, color);
		}

		[PunRPC]
		public void RPC_FlashlightFlicker(bool enabled)
		{
			if ((Object)(object)flashlight == (Object)null)
			{
				if ((Object)(object)playerAvatar != (Object)null)
				{
					flashlight = playerAvatar.flashlightController;
				}
				if ((Object)(object)flashlight == (Object)null)
				{
					return;
				}
			}
			((Behaviour)flashlight.spotlight).enabled = enabled;
			flashlight.halo.enabled = enabled;
		}
	}
	[HarmonyPatch(typeof(PlayerAvatar), "Awake")]
	public static class Patch_PlayerAvatar_AddRPCHandler
	{
		private static void Postfix(PlayerAvatar __instance)
		{
			if ((Object)(object)((Component)__instance).GetComponent<FlashlightRPCHandler>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<FlashlightRPCHandler>();
				PhotonView photonView = __instance.photonView;
				Debug.Log((object)$"FlashlightRPCHandler added! (ViewID: {((photonView != null) ? new int?(photonView.ViewID) : null)})");
			}
		}
	}
}