Decompiled source of muzzleFlashOptimize v1.3.0

Zose_muzzleFlashOptimize.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Zose")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Optimize muzzle flash intensity and particle size during ADS")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Zose_muzzleFlashOptimize")]
[assembly: AssemblyTitle("Zose_muzzleFlashOptimize")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace Zose_muzzleFlashOptimize
{
	[BepInPlugin("com.zose.muzzleFlashOptimize", "Zose_muzzleFlashOptimize", "1.41.0")]
	public class EntryPoint : BasePlugin
	{
		public static ManualLogSource? Logger;

		private Harmony? _harmony;

		public override void Load()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			Logger = ((BasePlugin)this).Log;
			Settings.Initialize(((BasePlugin)this).Config);
			_harmony = new Harmony("com.zose.muzzleFlashOptimize");
			MuzzleFlashPatch.Apply(_harmony);
			Logger.LogInfo((object)"Zose_muzzleFlashOptimize v1.41.0 Initialized.");
		}
	}
	internal static class Logger
	{
		private static readonly ManualLogSource _Logger;

		static Logger()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			_Logger = new ManualLogSource("Zose_muzzleFlashOptimize");
			Logger.Sources.Add((ILogSource)(object)_Logger);
		}

		private static string Format(object msg)
		{
			return msg?.ToString() ?? "null";
		}

		public static void Info(BepInExInfoLogInterpolatedStringHandler handler)
		{
			_Logger.LogInfo(handler);
		}

		public static void Info(string str)
		{
			_Logger.LogMessage((object)str);
		}

		public static void Info(object data)
		{
			_Logger.LogMessage((object)Format(data));
		}

		public static void Debug(BepInExDebugLogInterpolatedStringHandler handler)
		{
			_Logger.LogDebug(handler);
		}

		public static void Debug(string str)
		{
			_Logger.LogDebug((object)str);
		}

		public static void Debug(object data)
		{
			_Logger.LogDebug((object)Format(data));
		}

		public static void Error(BepInExErrorLogInterpolatedStringHandler handler)
		{
			_Logger.LogError(handler);
		}

		public static void Error(string str)
		{
			_Logger.LogError((object)str);
		}

		public static void Error(object data)
		{
			_Logger.LogError((object)Format(data));
		}

		public static void Fatal(BepInExFatalLogInterpolatedStringHandler handler)
		{
			_Logger.LogFatal(handler);
		}

		public static void Fatal(string str)
		{
			_Logger.LogFatal((object)str);
		}

		public static void Fatal(object data)
		{
			_Logger.LogFatal((object)Format(data));
		}

		public static void Warn(BepInExWarningLogInterpolatedStringHandler handler)
		{
			_Logger.LogWarning(handler);
		}

		public static void Warn(string str)
		{
			_Logger.LogWarning((object)str);
		}

		public static void Warn(object data)
		{
			_Logger.LogWarning((object)Format(data));
		}
	}
	public static class MuzzleFlashPatch
	{
		private class MemberAccessor
		{
			private PropertyInfo? _prop;

			private FieldInfo? _field;

			public bool IsValid => _prop != null || _field != null;

			public MemberAccessor(Type type, string name)
			{
				_prop = AccessTools.Property(type, name);
				_field = AccessTools.Field(type, name);
			}

			public object? GetValue(object obj)
			{
				if (_prop != null)
				{
					return _prop.GetValue(obj);
				}
				if (_field != null)
				{
					return _field.GetValue(obj);
				}
				return null;
			}

			public void SetValue(object obj, object value)
			{
				if (_prop != null)
				{
					_prop.SetValue(obj, value);
				}
				else if (_field != null)
				{
					_field.SetValue(obj, value);
				}
			}
		}

		private class MuzzleCache
		{
			public readonly ParticleSystem[] Particles;

			public readonly Light[] Lights;

			private readonly Color _rawStartColor;

			private readonly Color _rawEndColor;

			private readonly float[] _shadowLightIntensities;

			private readonly Color[] _shadowLightColors;

			private readonly Color[] _shadowParticleColors;

			public MuzzleCache(MonoBehaviour instance)
			{
				//IL_009d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
				//IL_013b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0140: Unknown result type (might be due to invalid IL or missing references)
				Particles = Il2CppArrayBase<ParticleSystem>.op_Implicit(((Component)instance).GetComponentsInChildren<ParticleSystem>(true));
				Lights = Il2CppArrayBase<Light>.op_Implicit(((Component)instance).GetComponentsInChildren<Light>(true));
				_shadowLightIntensities = new float[Lights.Length];
				_shadowLightColors = (Color[])(object)new Color[Lights.Length];
				_shadowParticleColors = (Color[])(object)new Color[Particles.Length];
				object obj = _startColorAccessor?.GetValue(instance);
				object obj2 = _endColorAccessor?.GetValue(instance);
				_rawStartColor = ((obj is Color val) ? val : Color.white);
				_rawEndColor = ((obj2 is Color val2) ? val2 : Color.white);
				for (int i = 0; i < Lights.Length; i++)
				{
					_shadowLightIntensities[i] = Lights[i].intensity;
					_shadowLightColors[i] = Lights[i].color;
				}
				for (int j = 0; j < Particles.Length; j++)
				{
					_shadowParticleColors[j] = Particles[j].main.startColor.color;
				}
			}

			private Color ShiftColor(Color original, Color target)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0181: 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)
				//IL_018c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0190: Unknown result type (might be due to invalid IL or missing references)
				float num = default(float);
				float num2 = default(float);
				float num3 = default(float);
				Color.RGBToHSV(target, ref num, ref num2, ref num3);
				float r = original.r;
				float g = original.g;
				float b = original.b;
				float num4 = Mathf.Max(r, Mathf.Max(g, b));
				float num5 = Mathf.Min(r, Mathf.Min(g, b));
				float num6 = num4;
				float num7 = num4 - num5;
				float num8 = ((num4 == 0f) ? 0f : (num7 / num4));
				if (num2 < 0.01f)
				{
					num8 = 0f;
				}
				float num9 = num6 * num8;
				float num10 = num9 * (1f - Mathf.Abs(num * 6f % 2f - 1f));
				float num11 = num6 - num9;
				float num12 = 0f;
				float num13 = 0f;
				float num14 = 0f;
				int num15 = (int)Mathf.Floor(num * 6f) % 6;
				if (num15 < 0)
				{
					num15 += 6;
				}
				switch (num15)
				{
				case 0:
					num12 = num9;
					num13 = num10;
					num14 = 0f;
					break;
				case 1:
					num12 = num10;
					num13 = num9;
					num14 = 0f;
					break;
				case 2:
					num12 = 0f;
					num13 = num9;
					num14 = num10;
					break;
				case 3:
					num12 = 0f;
					num13 = num10;
					num14 = num9;
					break;
				case 4:
					num12 = num10;
					num13 = 0f;
					num14 = num9;
					break;
				case 5:
					num12 = num9;
					num13 = 0f;
					num14 = num10;
					break;
				}
				return new Color(num12 + num11, num13 + num11, num14 + num11, original.a);
			}

			public void Apply(MonoBehaviour instance, Color? activeColor, float b)
			{
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_0078: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: 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_0091: 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_0096: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_0188: Unknown result type (might be due to invalid IL or missing references)
				//IL_0194: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_026b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0262: Unknown result type (might be due to invalid IL or missing references)
				//IL_0270: Unknown result type (might be due to invalid IL or missing references)
				//IL_0274: Unknown result type (might be due to invalid IL or missing references)
				//IL_027b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0282: Unknown result type (might be due to invalid IL or missing references)
				//IL_029d: Unknown result type (might be due to invalid IL or missing references)
				bool flag = b < 0.001f;
				if (_startColorAccessor != null && _startColorAccessor.IsValid)
				{
					if (flag)
					{
						_startColorAccessor.SetValue(instance, Color.clear);
						_endColorAccessor?.SetValue(instance, Color.clear);
					}
					else
					{
						Color val = (activeColor.HasValue ? activeColor.Value : _rawStartColor);
						Color val2 = (activeColor.HasValue ? activeColor.Value : _rawEndColor);
						_startColorAccessor.SetValue(instance, (object)new Color(val.r, val.g, val.b, _rawStartColor.a * b));
						_endColorAccessor?.SetValue(instance, (object)new Color(val2.r, val2.g, val2.b, _rawEndColor.a * b));
					}
				}
				for (int i = 0; i < Lights.Length; i++)
				{
					Light val3 = Lights[i];
					if ((Object)(object)val3 == (Object)null)
					{
						continue;
					}
					if (flag)
					{
						((Behaviour)val3).enabled = false;
						continue;
					}
					if (!((Behaviour)val3).enabled)
					{
						((Behaviour)val3).enabled = true;
					}
					val3.intensity = _shadowLightIntensities[i] * b;
					if (activeColor.HasValue)
					{
						val3.color = new Color(activeColor.Value.r, activeColor.Value.g, activeColor.Value.b, _shadowLightColors[i].a);
					}
					else
					{
						val3.color = _shadowLightColors[i];
					}
				}
				for (int j = 0; j < Particles.Length; j++)
				{
					ParticleSystem val4 = Particles[j];
					if ((Object)(object)val4 == (Object)null)
					{
						continue;
					}
					if (flag)
					{
						if (val4.isPlaying)
						{
							val4.Stop(true, (ParticleSystemStopBehavior)0);
						}
						continue;
					}
					MainModule main = val4.main;
					Color val5 = (activeColor.HasValue ? activeColor.Value : _shadowParticleColors[j]);
					main.startColor = MinMaxGradient.op_Implicit(new Color(val5.r, val5.g, val5.b, _shadowParticleColors[j].a * b));
					if (!val4.isPlaying && ((Component)val4).gameObject.activeInHierarchy)
					{
						val4.Play();
					}
				}
			}

			public void Restore(MonoBehaviour instance)
			{
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
				if (_startColorAccessor != null && _startColorAccessor.IsValid)
				{
					_startColorAccessor.SetValue(instance, _rawStartColor);
					_endColorAccessor?.SetValue(instance, _rawEndColor);
				}
				for (int i = 0; i < Lights.Length; i++)
				{
					if ((Object)(object)Lights[i] != (Object)null)
					{
						Lights[i].intensity = _shadowLightIntensities[i];
						Lights[i].color = _shadowLightColors[i];
					}
				}
				for (int j = 0; j < Particles.Length; j++)
				{
					if ((Object)(object)Particles[j] != (Object)null)
					{
						MainModule main = Particles[j].main;
						main.startColor = MinMaxGradient.op_Implicit(_shadowParticleColors[j]);
					}
				}
			}
		}

		private static int _lastFrameProcessed = -1;

		private static float _cachedBrightness;

		private static Color? _cachedActiveColor;

		private static MemberAccessor? _startColorAccessor;

		private static MemberAccessor? _endColorAccessor;

		private static readonly Dictionary<IntPtr, MuzzleCache> _ptrCache = new Dictionary<IntPtr, MuzzleCache>();

		public static void Apply(Harmony harmony)
		{
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Expected O, but got Unknown
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Expected O, but got Unknown
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Expected O, but got Unknown
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Expected O, but got Unknown
			try
			{
				Type type = AccessTools.TypeByName("Gear.EX_SpriteMuzzleFlash") ?? AccessTools.TypeByName("EX_SpriteMuzzleFlash");
				if (type == null)
				{
					Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
					foreach (Assembly assembly in assemblies)
					{
						try
						{
							type = assembly.GetType("Gear.EX_SpriteMuzzleFlash") ?? assembly.GetType("EX_SpriteMuzzleFlash");
							if (type != null)
							{
								break;
							}
						}
						catch
						{
						}
					}
				}
				if (type == null)
				{
					ManualLogSource? logger = EntryPoint.Logger;
					if (logger != null)
					{
						logger.LogError((object)"CRITICAL: Could not find Gear.EX_SpriteMuzzleFlash type! Patching failed.");
					}
					return;
				}
				_startColorAccessor = new MemberAccessor(type, "m_startColor");
				_endColorAccessor = new MemberAccessor(type, "m_endColor");
				MethodInfo methodInfo = AccessTools.Method(type, "Update", (Type[])null, (Type[])null);
				if (methodInfo != null)
				{
					harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(MuzzleFlashPatch), "OnUpdatePrepare", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					ManualLogSource? logger2 = EntryPoint.Logger;
					if (logger2 != null)
					{
						logger2.LogInfo((object)"Successfully patched EX_SpriteMuzzleFlash.Update");
					}
				}
				MethodInfo methodInfo2 = AccessTools.Method(type, "OnDisable", (Type[])null, (Type[])null);
				if (methodInfo2 != null)
				{
					harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(MuzzleFlashPatch), "OnDisablePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					ManualLogSource? logger3 = EntryPoint.Logger;
					if (logger3 != null)
					{
						logger3.LogInfo((object)"Successfully patched EX_SpriteMuzzleFlash.OnDisable");
					}
				}
				MethodInfo methodInfo3 = AccessTools.Method(type, "OnDestroy", (Type[])null, (Type[])null);
				if (methodInfo3 != null)
				{
					harmony.Patch((MethodBase)methodInfo3, (HarmonyMethod)null, new HarmonyMethod(typeof(MuzzleFlashPatch), "OnDestroyPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger4 = EntryPoint.Logger;
				if (logger4 != null)
				{
					bool flag = default(bool);
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(16, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Patching error: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
					}
					logger4.LogError(val);
				}
			}
		}

		private static void OnDestroyPostfix(MonoBehaviour __instance)
		{
			if ((Object)(object)__instance != (Object)null)
			{
				_ptrCache.Remove(((Il2CppObjectBase)__instance).Pointer);
			}
		}

		private static void OnDisablePostfix(MonoBehaviour __instance)
		{
			if ((Object)(object)__instance != (Object)null && _ptrCache.TryGetValue(((Il2CppObjectBase)__instance).Pointer, out MuzzleCache value))
			{
				value.Restore(__instance);
			}
		}

		private static void UpdateGlobalState()
		{
			int frameCount = Time.frameCount;
			if (_lastFrameProcessed != frameCount)
			{
				_lastFrameProcessed = frameCount;
				Settings.CheckReload();
				_cachedBrightness = Settings.GetBrightness();
				_cachedActiveColor = Settings.GetActiveColor();
			}
		}

		private static void OnUpdatePrepare(MonoBehaviour __instance)
		{
			if (!((Object)(object)__instance == (Object)null))
			{
				UpdateGlobalState();
				if (!_ptrCache.TryGetValue(((Il2CppObjectBase)__instance).Pointer, out MuzzleCache value))
				{
					value = new MuzzleCache(__instance);
					_ptrCache[((Il2CppObjectBase)__instance).Pointer] = value;
				}
				value.Apply(__instance, _cachedActiveColor, _cachedBrightness);
			}
		}
	}
	public static class Settings
	{
		public enum ColorMode
		{
			Original,
			Custom,
			Incendiary,
			Plasma,
			Classic,
			Electric,
			Toxic
		}

		private static FileSystemWatcher? _watcher;

		private static volatile bool _needsReload;

		private static ConfigFile? _boundConfig;

		private static float _lastReloadTime;

		private static Color? _cachedColor;

		public static ConfigEntry<float>? MuzzleFlashBrightness { get; private set; }

		public static ConfigEntry<ColorMode>? FlashColorMode { get; private set; }

		public static ConfigEntry<string>? CustomHexColor { get; private set; }

		public static int ConfigVersion { get; private set; }

		public static void Initialize(ConfigFile config)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			_boundConfig = config;
			string text = "Visual Optimization";
			MuzzleFlashBrightness = config.Bind<float>(text, "Muzzle Brightness", 0.5f, new ConfigDescription("Intensity and transparency of the flash. (0.0 = Hidden, 1.0 = Original)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			string text2 = "Color Customization";
			FlashColorMode = config.Bind<ColorMode>(text2, "Color Mode", ColorMode.Original, "Select the visual style/color of the flash.");
			CustomHexColor = config.Bind<string>(text2, "Custom Hex Code", "#FFD700", "Custom color in #RRGGBB format. (Only used if Mode is 'Custom')");
			UpdateCachedColor();
			ConfigVersion++;
			SetupWatcher(config);
		}

		private static void UpdateCachedColor()
		{
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			if (FlashColorMode == null)
			{
				return;
			}
			switch (FlashColorMode.Value)
			{
			case ColorMode.Original:
				_cachedColor = null;
				break;
			case ColorMode.Custom:
			{
				string text = CustomHexColor?.Value ?? "#FFFFFF";
				if (!text.StartsWith("#"))
				{
					text = "#" + text;
				}
				Color value = default(Color);
				if (ColorUtility.TryParseHtmlString(text, ref value))
				{
					_cachedColor = value;
				}
				else
				{
					_cachedColor = Color.white;
				}
				break;
			}
			case ColorMode.Incendiary:
				_cachedColor = new Color(1f, 0.45f, 0.05f);
				break;
			case ColorMode.Plasma:
				_cachedColor = new Color(0.2f, 0.6f, 1f);
				break;
			case ColorMode.Classic:
				_cachedColor = new Color(1f, 0.8f, 0.3f);
				break;
			case ColorMode.Electric:
				_cachedColor = new Color(0f, 1f, 0.9f);
				break;
			case ColorMode.Toxic:
				_cachedColor = new Color(0.3f, 1f, 0.3f);
				break;
			default:
				_cachedColor = null;
				break;
			}
		}

		private static void SetupWatcher(ConfigFile config)
		{
			try
			{
				string directoryName = Path.GetDirectoryName(config.ConfigFilePath);
				string fileName = Path.GetFileName(config.ConfigFilePath);
				if (!string.IsNullOrEmpty(directoryName) && Directory.Exists(directoryName))
				{
					_watcher = new FileSystemWatcher(directoryName, fileName)
					{
						NotifyFilter = NotifyFilters.LastWrite,
						EnableRaisingEvents = true
					};
					_watcher.Changed += delegate
					{
						_needsReload = true;
					};
				}
			}
			catch
			{
			}
		}

		public static void CheckReload()
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			if (!_needsReload || _boundConfig == null || !(Time.time - _lastReloadTime > 0.5f))
			{
				return;
			}
			_needsReload = false;
			_lastReloadTime = Time.time;
			try
			{
				_boundConfig.Reload();
				UpdateCachedColor();
				ConfigVersion++;
				ManualLogSource logger = EntryPoint.Logger;
				if (logger != null)
				{
					bool flag = default(bool);
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(44, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[RELAY] Config successfully hot-reloaded at ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<DateTime>(DateTime.Now, "HH:mm:ss");
					}
					logger.LogInfo(val);
				}
			}
			catch (IOException)
			{
				_needsReload = true;
			}
			catch
			{
			}
		}

		public static float GetBrightness()
		{
			return Mathf.Clamp01(MuzzleFlashBrightness?.Value ?? 0.5f);
		}

		public static float GetScale()
		{
			return 1f;
		}

		public static Color? GetActiveColor()
		{
			return _cachedColor;
		}
	}
}