Decompiled source of FeylightBloom v0.1.1

plugins/FeylightBloom/FeylightBloom.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("FeylightBloom")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1")]
[assembly: AssemblyProduct("FeylightBloom")]
[assembly: AssemblyTitle("FeylightBloom")]
[assembly: AssemblyVersion("0.1.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace FeylightBloom
{
	[BepInPlugin("smeagsmods.feylightbloom", "Feylight Bloom", "0.1.1")]
	public sealed class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(ZNetView), "Awake")]
		private class Spawn
		{
			[HarmonyPostfix]
			private static void Postfix(ZNetView __instance)
			{
				Attach(((Component)__instance).GetComponent<Piece>());
			}
		}

		public const string Id = "smeagsmods.feylightbloom";

		public static Plugin Instance;

		public ConfigEntry<bool> Active;

		public ConfigEntry<bool> IndividualBulbs;

		public ConfigEntry<float> Glow;

		public ConfigEntry<float> Illumination;

		public ConfigEntry<float> Reach;

		public ConfigEntry<int> Mode;

		private Harmony harmony;

		private bool initialized;

		private Panel panel;

		private float nextSelection;

		private readonly Dictionary<string, ConsoleCommand> owned = new Dictionary<string, ConsoleCommand>();

		public string ChatCommand { get; private set; } = "";

		private void Awake()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Expected O, but got Unknown
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Expected O, but got Unknown
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Expected O, but got Unknown
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Expected O, but got Unknown
			if ((int)SystemInfo.graphicsDeviceType != 4)
			{
				Instance = this;
				Active = ((BaseUnityPlugin)this).Config.Bind<bool>("Visuals", "Enabled", true, "Client-local fey lighting. False is exact vanilla; no world data is changed.");
				IndividualBulbs = ((BaseUnityPlugin)this).Config.Bind<bool>("Visuals", "IndividualBulbs", false, "Animate individual native bulbs on up to 8 nearest strings within 20m. Others retain whole-string effects. No added lights.");
				Glow = ((BaseUnityPlugin)this).Config.Bind<float>("Visuals", "Glow", 1.35f, new ConfigDescription("Bulb emission multiplier; independent of scene illumination.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 4f), Array.Empty<object>()));
				Illumination = ((BaseUnityPlugin)this).Config.Bind<float>("Visuals", "Illumination", 2f, new ConfigDescription("Shadowless scene light intensity. 0 disables added illumination.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 4f), Array.Empty<object>()));
				Reach = ((BaseUnityPlugin)this).Config.Bind<float>("Visuals", "Reach", 4f, new ConfigDescription("Added light range in metres.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 8f), Array.Empty<object>()));
				Mode = ((BaseUnityPlugin)this).Config.Bind<int>("Visuals", "Mode", 0, new ConfigDescription("0 Hearthglow; 1 Moonbreath; 2 Firefly Dance; 3 Wisp Waltz; 4 Starlit Shimmer.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 4), Array.Empty<object>()));
				panel = ((Component)this).gameObject.AddComponent<Panel>();
				harmony = new Harmony("smeagsmods.feylightbloom");
				harmony.PatchAll(typeof(Plugin).Assembly);
				initialized = true;
			}
		}

		private void Start()
		{
			RegisterCommands();
			ScanExisting();
		}

		private void OnEnable()
		{
			if (initialized)
			{
				RegisterCommands();
				ScanExisting();
			}
		}

		private void ScanExisting()
		{
			Piece[] array = Object.FindObjectsByType<Piece>((FindObjectsSortMode)0);
			foreach (Piece p in array)
			{
				Attach(p);
			}
		}

		public void Commit(bool active, float glow, float intensity, float range, int mode, bool? individual = null)
		{
			if (individual.HasValue)
			{
				IndividualBulbs.Value = individual.Value;
			}
			Active.Value = active;
			Glow.Value = BloomMath.Clamp(glow, 0f, 4f);
			Illumination.Value = BloomMath.Clamp(intensity, 0f, 4f);
			Reach.Value = BloomMath.Clamp(range, 1f, 8f);
			Mode.Value = Mathf.Clamp(mode, 0, 4);
			((BaseUnityPlugin)this).Config.Save();
			foreach (BloomString item in BloomString.Live)
			{
				if ((Object)(object)item != (Object)null)
				{
					item.Refresh();
				}
			}
			nextSelection = 0f;
		}

		public void RegisterCommands()
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			AccessTools.Method(typeof(Terminal), "InitTerminal", (Type[])null, (Type[])null).Invoke(null, null);
			Dictionary<string, ConsoleCommand> dictionary = (Dictionary<string, ConsoleCommand>)AccessTools.Field(typeof(Terminal), "commands").GetValue(null);
			string[] array = new string[2] { "feylightbloom", "fey" };
			foreach (string text in array)
			{
				if (dictionary.ContainsKey(text))
				{
					continue;
				}
				ConsoleCommand value = new ConsoleCommand(text, "Open client-local Feylight Bloom controls", (ConsoleEvent)delegate
				{
					if (((Behaviour)this).isActiveAndEnabled)
					{
						panel.Open();
					}
				}, false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
				owned[text] = value;
			}
			ChatCommand = ((owned.ContainsKey("fey") && dictionary.TryGetValue("fey", out var value2) && value2 == owned["fey"]) ? "/fey" : ((owned.ContainsKey("feylightbloom") && dictionary.TryGetValue("feylightbloom", out var value3) && value3 == owned["feylightbloom"]) ? "/feylightbloom" : ""));
			((BaseUnityPlugin)this).Logger.LogInfo((object)((ChatCommand.Length > 0) ? ("Controls: " + ChatCommand + "; registered commands are never replaced.") : "Both command names are occupied; controls unavailable, config remains usable."));
		}

		private void UnregisterCommands()
		{
			Dictionary<string, ConsoleCommand> dictionary = (Dictionary<string, ConsoleCommand>)AccessTools.Field(typeof(Terminal), "commands").GetValue(null);
			foreach (KeyValuePair<string, ConsoleCommand> item in owned)
			{
				if (dictionary.TryGetValue(item.Key, out var value) && value == item.Value)
				{
					dictionary.Remove(item.Key);
				}
			}
			owned.Clear();
		}

		private void Update()
		{
			if (initialized)
			{
				if (Time.unscaledTime >= nextSelection)
				{
					nextSelection = Time.unscaledTime + 0.5f;
					BloomString.SelectNearby();
				}
				BloomString.Animate(Time.time);
			}
		}

		public static void Attach(Piece p)
		{
			if (!((Object)(object)Instance == (Object)null) && ((Behaviour)Instance).isActiveAndEnabled && !((Object)(object)p == (Object)null) && !(((Object)p).name != "piece_FairylightGarland(Clone)"))
			{
				ZNetView component = ((Component)p).GetComponent<ZNetView>();
				if (!((Object)(object)component == (Object)null) && component.IsValid() && (Object)(object)((Component)p).GetComponent<BloomString>() == (Object)null)
				{
					((Component)p).gameObject.AddComponent<BloomString>();
				}
			}
		}

		private void OnDisable()
		{
			if (initialized)
			{
				panel?.Close();
				UnregisterCommands();
				BloomString.Shutdown();
			}
		}

		private void OnDestroy()
		{
			OnDisable();
			BloomString.DetachAll();
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			if ((Object)(object)panel != (Object)null)
			{
				Object.Destroy((Object)(object)panel);
			}
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}
	}
	public sealed class Panel : MonoBehaviour
	{
		[HarmonyPatch(typeof(Chat), "HasFocus")]
		private class Focus
		{
			[HarmonyPostfix]
			private static void Postfix(ref bool __result)
			{
				if (BlocksInput)
				{
					__result = true;
				}
			}
		}

		[HarmonyPatch(typeof(Chat), "Update")]
		private class ChatKeys
		{
			[HarmonyPrefix]
			private static bool Prefix()
			{
				return !BlocksInput;
			}
		}

		[HarmonyPatch(typeof(Player), "TakeInput")]
		private class Input
		{
			[HarmonyPostfix]
			private static void Postfix(ref bool __result)
			{
				if (BlocksInput)
				{
					__result = false;
				}
			}
		}

		[HarmonyPatch(typeof(Menu), "Update")]
		private class MenuKeys
		{
			[HarmonyPrefix]
			private static bool Prefix()
			{
				return !BlocksInput;
			}
		}

		[HarmonyPatch(typeof(GameCamera), "UpdateMouseCapture")]
		private class MouseCapture
		{
			[HarmonyPrefix]
			private static bool Prefix()
			{
				if (!BlocksInput)
				{
					return true;
				}
				ZCursor.LockState = (CursorLockMode)0;
				ZCursor.Show();
				return false;
			}
		}

		public static Panel Instance;

		private int closeFrame = -10;

		private int scene;

		private int mode;

		private float glow;

		private float intensity;

		private float reach;

		private bool individual;

		private GUIStyle label;

		private GUIStyle button;

		private GUIStyle title;

		private GUIStyle selector;

		private GUIStyle close;

		private GUIStyle checkOff;

		private GUIStyle checkOn;

		private static readonly Color Ink = new Color(0.9f, 0.94f, 0.79f);

		public bool IsOpen { get; private set; }

		public static bool BlocksInput => (Object)(object)Instance != (Object)null && (Instance.IsOpen || Time.frameCount <= Instance.closeFrame + 1);

		private void Awake()
		{
			Instance = this;
			Skin.Load();
			SceneManager.activeSceneChanged += SceneChanged;
		}

		private void SceneChanged(Scene a, Scene b)
		{
			Close();
		}

		public void Open()
		{
			//IL_0098: 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)
			if (!IsOpen && !((Object)(object)Player.m_localPlayer == (Object)null) && !((Object)(object)Plugin.Instance == (Object)null) && ((Behaviour)Plugin.Instance).isActiveAndEnabled)
			{
				Plugin instance = Plugin.Instance;
				glow = instance.Glow.Value;
				intensity = instance.Illumination.Value;
				reach = instance.Reach.Value;
				mode = instance.Mode.Value;
				individual = instance.IndividualBulbs.Value;
				Scene activeScene = SceneManager.GetActiveScene();
				scene = ((Scene)(ref activeScene)).handle;
				IsOpen = true;
				Chat instance2 = Chat.instance;
				if (instance2 != null)
				{
					instance2.Hide();
				}
			}
		}

		public void Close()
		{
			if (IsOpen)
			{
				IsOpen = false;
				closeFrame = Time.frameCount;
				GUIUtility.hotControl = 0;
			}
		}

		public void Select(float g, float i, float r, int m)
		{
			glow = BloomMath.Clamp(g, 0f, 4f);
			intensity = BloomMath.Clamp(i, 0f, 4f);
			reach = BloomMath.Clamp(r, 1f, 8f);
			mode = Mathf.Clamp(m, 0, 4);
		}

		public void SelectIndividual(bool value)
		{
			individual = value;
		}

		public void Apply()
		{
			Plugin.Instance.Commit(active: true, glow, intensity, reach, mode, individual);
			Close();
		}

		public void Vanilla()
		{
			Plugin.Instance.Commit(active: false, 1f, 2f, 4f, 0, false);
			Close();
		}

		private void Update()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if (!IsOpen)
			{
				return;
			}
			if (!((Object)(object)Player.m_localPlayer == (Object)null))
			{
				int num = scene;
				Scene activeScene = SceneManager.GetActiveScene();
				if (num == ((Scene)(ref activeScene)).handle && !ZInput.GetKeyDown((KeyCode)27, true))
				{
					return;
				}
			}
			Close();
		}

		private GUIStyle ButtonStyle(Texture2D texture)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val = new GUIStyle(button);
			val.padding = new RectOffset(3, 3, 2, 2);
			val.border = new RectOffset();
			GUIStyleState[] array = (GUIStyleState[])(object)new GUIStyleState[8] { val.normal, val.hover, val.active, val.focused, val.onNormal, val.onHover, val.onActive, val.onFocused };
			foreach (GUIStyleState val2 in array)
			{
				val2.background = texture;
				val2.textColor = Ink;
			}
			return val;
		}

		private void Styles()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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)
			//IL_006b: Expected O, but got Unknown
			//IL_0076: 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_0091: 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_00a7: Expected O, but got Unknown
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Expected O, but got Unknown
			if (label == null)
			{
				Font font = ((IEnumerable<Font>)Resources.FindObjectsOfTypeAll<Font>()).FirstOrDefault((Func<Font, bool>)((Font f) => ((Object)f).name.IndexOf("Averia", StringComparison.OrdinalIgnoreCase) >= 0));
				label = new GUIStyle(GUI.skin.label)
				{
					fontSize = 18,
					wordWrap = true,
					font = font
				};
				label.normal.textColor = Ink;
				button = new GUIStyle(GUI.skin.button)
				{
					fontSize = 18,
					font = font
				};
				button = ButtonStyle(Skin.Get("action-button"));
				selector = ButtonStyle(Skin.Get("mode-selector"));
				close = ButtonStyle(Skin.Get("close-button"));
				checkOff = ButtonStyle(Skin.Get("checkbox-off"));
				checkOn = ButtonStyle(Skin.Get("checkbox-on"));
				title = new GUIStyle(label)
				{
					fontSize = 34,
					alignment = (TextAnchor)4
				};
			}
		}

		private void OnGUI()
		{
			//IL_0448: Unknown result type (might be due to invalid IL or missing references)
			//IL_044f: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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_0089: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: 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_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_042e: Unknown result type (might be due to invalid IL or missing references)
			if (!IsOpen)
			{
				return;
			}
			Styles();
			Matrix4x4 matrix = GUI.matrix;
			Color color = GUI.color;
			int depth = GUI.depth;
			float num = Mathf.Min(1f, Mathf.Min((float)(Screen.width - 32) / 640f, (float)(Screen.height - 32) / 600f));
			GUI.matrix = Matrix4x4.TRS(new Vector3(((float)Screen.width - 640f * num) / 2f, ((float)Screen.height - 600f * num) / 2f, 0f), Quaternion.identity, new Vector3(num, num, 1f));
			GUI.depth = -100;
			try
			{
				GUI.color = Color.white;
				GUI.DrawTexture(new Rect(0f, 0f, 640f, 600f), (Texture)(object)(Skin.Get("panel-background") ?? Texture2D.whiteTexture));
				GUI.color = color;
				if ((Object)(object)Skin.Get("title-wordmark") != (Object)null)
				{
					GUI.DrawTexture(new Rect(96f, 24f, 448f, 72f), (Texture)(object)Skin.Get("title-wordmark"));
				}
				else
				{
					GUI.Label(new Rect(96f, 24f, 448f, 72f), "Feylight Bloom", title);
				}
				if (GUI.Button(new Rect(572f, 96f, 32f, 32f), "", close))
				{
					Close();
				}
				GUI.Label(new Rect(96f, 100f, 448f, 28f), "All fey strings - visible only to you", label);
				GUI.Label(new Rect(96f, 128f, 448f, 26f), "Lighting mode", label);
				if (GUI.Button(new Rect(96f, 158f, 448f, 40f), "‹   " + BloomMath.Names[mode] + "   ›", selector))
				{
					mode = (mode + 1) % 5;
				}
				SliderRow("Glow", ref glow, 0f, 4f, 208f, 240f, "×");
				SliderRow("Illumination", ref intensity, 0f, 4f, 288f, 320f, "");
				SliderRow("Reach", ref reach, 1f, 8f, 368f, 400f, " m");
				if (GUI.Button(new Rect(96f, 448f, 24f, 24f), "", individual ? checkOn : checkOff))
				{
					individual = !individual;
				}
				if (GUI.Button(new Rect(130f, 448f, 414f, 24f), "Individual bulbs (nearby)", label))
				{
					individual = !individual;
				}
				GUI.Label(new Rect(96f, 476f, 448f, 24f), "On: nearest 8 within 20m. Off: whole strings.", label);
				if (GUI.Button(new Rect(64f, 512f, 160f, 44f), "Vanilla", button))
				{
					Vanilla();
				}
				if (GUI.Button(new Rect(240f, 512f, 160f, 44f), "Cancel", button))
				{
					Close();
				}
				if (GUI.Button(new Rect(416f, 512f, 160f, 44f), "Apply", button))
				{
					Apply();
				}
				GUI.Label(new Rect(96f, 564f, 448f, 26f), "Escape closes without applying", label);
			}
			finally
			{
				GUI.matrix = matrix;
				GUI.color = color;
				GUI.depth = depth;
			}
		}

		private void SliderRow(string name, ref float value, float min, float max, float y, float trackY, string units)
		{
			//IL_0012: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_00c3: Invalid comparison between Unknown and I4
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Invalid comparison between Unknown and I4
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			GUI.Label(new Rect(96f, y, 448f, 28f), name + "   " + value.ToString("0.00") + units, label);
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(96f, trackY, 448f, 32f);
			int controlID = GUIUtility.GetControlID((int)trackY, (FocusType)2, val);
			Event current = Event.current;
			if ((int)current.type == 0 && current.button == 0 && ((Rect)(ref val)).Contains(current.mousePosition))
			{
				GUIUtility.hotControl = controlID;
				value = Mathf.Lerp(min, max, Mathf.InverseLerp(108f, 532f, current.mousePosition.x));
				current.Use();
			}
			if ((int)current.type == 3 && GUIUtility.hotControl == controlID)
			{
				value = Mathf.Lerp(min, max, Mathf.InverseLerp(108f, 532f, current.mousePosition.x));
				current.Use();
			}
			if ((int)current.type == 1 && GUIUtility.hotControl == controlID)
			{
				GUIUtility.hotControl = 0;
				current.Use();
			}
			GUI.DrawTexture(val, (Texture)(object)(Skin.Get("slider-track") ?? Texture2D.whiteTexture));
			GUI.DrawTexture(new Rect(Mathf.Lerp(108f, 532f, Mathf.InverseLerp(min, max, value)) - 12f, trackY - 4f, 24f, 40f), (Texture)(object)(Skin.Get("slider-thumb") ?? Texture2D.whiteTexture));
		}

		private void OnDisable()
		{
			Close();
		}

		private void OnDestroy()
		{
			Close();
			Skin.Dispose();
			SceneManager.activeSceneChanged -= SceneChanged;
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}
	}
	public sealed class BloomString : MonoBehaviour
	{
		public static readonly List<BloomString> Live = new List<BloomString>();

		private static readonly List<BloomString> Nearby = new List<BloomString>();

		private static readonly int Emission = Shader.PropertyToID("_EmissionColor");

		private static readonly FieldInfo BaseRange = AccessTools.Field(typeof(LightLod), "m_baseRange");

		private static readonly Comparison<BloomString> Compare = delegate(BloomString a, BloomString b)
		{
			int num = a.distance.CompareTo(b.distance);
			return (num == 0) ? ((Object)a).GetInstanceID().CompareTo(((Object)b).GetInstanceID()) : num;
		};

		private BulbVisual bulbs;

		private bool individualWanted;

		private Renderer[] renderers;

		private MaterialPropertyBlock[] original;

		private MaterialPropertyBlock[] working;

		private Color[] colors;

		private Light lamp;

		private LightLod ownedLod;

		private float originalIntensity;

		private float originalRange;

		private float phase;

		private float distance;

		private float lastGlow = -1f;

		private bool originalEnabled;

		private bool initialized;

		private bool modified;

		private bool chosen;

		private bool animate;

		private Color originalColor;

		private LightShadows originalShadows;

		public bool IndividualActive => bulbs != null && bulbs.Active;

		public Light NativeLight => lamp;

		public float Phase => phase;

		public bool Selected => chosen;

		private void Awake()
		{
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Invalid comparison between Unknown and I4
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Expected O, but got Unknown
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Expected O, but got Unknown
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: 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_019b: Unknown result type (might be due to invalid IL or missing references)
			if (((Component)this).GetComponent<Piece>()?.m_name != "$piece_fairylightgarland")
			{
				return;
			}
			string[] array = new string[4] { "new/default", "worn/default", "broken/default", "destruction/default" };
			renderers = (Renderer[])(object)new Renderer[4];
			original = (MaterialPropertyBlock[])(object)new MaterialPropertyBlock[4];
			working = (MaterialPropertyBlock[])(object)new MaterialPropertyBlock[4];
			colors = (Color[])(object)new Color[4];
			for (int i = 0; i < array.Length; i++)
			{
				Transform val = ((Component)this).transform.Find(array[i]);
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>();
				if ((Object)(object)component == (Object)null || ((Renderer)component).sharedMaterials.Length != 1 || ((Object)((Renderer)component).sharedMaterial).name != "ThistleGarland_Mat" || ((Object)((Renderer)component).sharedMaterial.shader).name != "Custom/Piece" || !((Renderer)component).sharedMaterial.HasProperty(Emission))
				{
					return;
				}
				renderers[i] = (Renderer)(object)component;
				original[i] = new MaterialPropertyBlock();
				working[i] = new MaterialPropertyBlock();
				((Renderer)component).GetPropertyBlock(original[i]);
				colors[i] = (original[i].HasColor(Emission) ? original[i].GetColor(Emission) : ((Renderer)component).sharedMaterial.GetColor(Emission));
			}
			Transform val2 = ((Component)this).transform.Find("Particle System");
			if (!((Object)(object)val2 == (Object)null))
			{
				lamp = ((Component)val2).GetComponent<Light>();
				if (!((Object)(object)lamp == (Object)null) && (int)lamp.type == 2 && ((Component)this).GetComponentsInChildren<Light>(true).Length == 1 && !((Object)(object)((Component)val2).GetComponent<LightLod>() != (Object)null))
				{
					originalIntensity = lamp.intensity;
					originalRange = lamp.range;
					originalEnabled = ((Behaviour)lamp).enabled;
					originalColor = lamp.color;
					originalShadows = lamp.shadows;
					Vector3 position = ((Component)this).transform.position;
					phase = BloomMath.PositionPhase(position.x, position.y, position.z);
					initialized = true;
					Live.Add(this);
					Refresh();
				}
			}
		}

		public void Refresh()
		{
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			if (!initialized)
			{
				return;
			}
			Plugin instance = Plugin.Instance;
			if (!((Behaviour)this).isActiveAndEnabled || (Object)(object)instance == (Object)null || !((Behaviour)instance).isActiveAndEnabled || !instance.Active.Value)
			{
				Restore();
				return;
			}
			modified = true;
			if (!instance.IndividualBulbs.Value || instance.Mode.Value == 0)
			{
				bulbs?.Unbind();
			}
			lastGlow = -1f;
			ApplyGlow(BloomMath.Clamp(instance.Glow.Value, 0f, 4f));
			if ((Object)(object)ownedLod == (Object)null)
			{
				lamp.range = BloomMath.Clamp(instance.Reach.Value, 1f, 8f);
				ownedLod = ((Component)lamp).gameObject.AddComponent<LightLod>();
				ownedLod.m_lightDistance = 32f;
				ownedLod.m_shadowLod = false;
			}
			BaseRange.SetValue(ownedLod, BloomMath.Clamp(instance.Reach.Value, 1f, 8f));
			lamp.shadows = (LightShadows)0;
			lamp.color = originalColor;
			lamp.intensity = BloomMath.Clamp(instance.Illumination.Value, 0f, 4f);
		}

		private void ApplyGlow(float factor)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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)
			if (lastGlow == factor)
			{
				return;
			}
			lastGlow = factor;
			for (int i = 0; i < renderers.Length; i++)
			{
				if ((Object)(object)renderers[i] != (Object)null)
				{
					renderers[i].GetPropertyBlock(working[i]);
					Color val = colors[i];
					val.r *= factor;
					val.g *= factor;
					val.b *= factor;
					working[i].SetColor(Emission, val);
					renderers[i].SetPropertyBlock(working[i]);
				}
			}
		}

		private void SetIndividual(bool value)
		{
			if (!value)
			{
				bulbs?.Unbind();
				return;
			}
			if (bulbs == null)
			{
				bulbs = new BulbVisual(renderers, colors);
			}
			bulbs.Bind();
		}

		public static void SelectNearby()
		{
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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_013c: 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_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			Nearby.Clear();
			Plugin instance = Plugin.Instance;
			if ((Object)(object)instance == (Object)null || !((Behaviour)instance).isActiveAndEnabled || !instance.Active.Value)
			{
				foreach (BloomString item in Live)
				{
					if ((Object)(object)item != (Object)null)
					{
						item.Restore();
					}
				}
				BulbMesh.DisposeAll();
				return;
			}
			Camera mainCamera = Utils.GetMainCamera();
			Vector3 val = (((Object)(object)mainCamera != (Object)null) ? ((Component)mainCamera).transform.position : (((Object)(object)Player.m_localPlayer != (Object)null) ? ((Component)Player.m_localPlayer).transform.position : Vector3.zero));
			foreach (BloomString item2 in Live)
			{
				if ((Object)(object)item2 == (Object)null)
				{
					continue;
				}
				if (!((Behaviour)item2).isActiveAndEnabled)
				{
					item2.Restore();
					continue;
				}
				if (!item2.modified)
				{
					item2.Refresh();
				}
				Vector3 val2 = ((Component)item2).transform.position - val;
				item2.distance = ((Vector3)(ref val2)).sqrMagnitude;
				item2.chosen = false;
				item2.animate = false;
				item2.individualWanted = false;
				if (((Behaviour)item2).isActiveAndEnabled && item2.distance < 1600f)
				{
					Nearby.Add(item2);
				}
			}
			Nearby.Sort(Compare);
			int num = 0;
			int num2 = 0;
			for (int i = 0; i < Nearby.Count; i++)
			{
				BloomString bloomString = Nearby[i];
				bloomString.animate = i < 64;
				bloomString.individualWanted = instance.IndividualBulbs.Value && instance.Mode.Value != 0 && bloomString.distance < 400f && num2 < 8;
				if (bloomString.individualWanted)
				{
					num2++;
				}
				bloomString.chosen = bloomString.distance < 1024f && num < 24 && instance.Illumination.Value > 0f;
				if (bloomString.chosen)
				{
					num++;
				}
			}
			foreach (BloomString item3 in Live)
			{
				if (!((Object)(object)item3 == (Object)null) && !((Object)(object)item3.lamp == (Object)null) && item3.modified)
				{
					item3.SetIndividual(item3.individualWanted);
					if ((Object)(object)item3.ownedLod != (Object)null)
					{
						((Behaviour)item3.ownedLod).enabled = item3.chosen;
					}
					if (!item3.chosen)
					{
						((Behaviour)item3.lamp).enabled = false;
					}
					if (!item3.animate)
					{
						item3.ApplyGlow(BloomMath.Clamp(instance.Glow.Value, 0f, 4f));
					}
				}
			}
		}

		public static void Animate(float time)
		{
			Plugin instance = Plugin.Instance;
			if ((Object)(object)instance == (Object)null || !((Behaviour)instance).isActiveAndEnabled || !instance.Active.Value)
			{
				return;
			}
			for (int i = 0; i < Nearby.Count && i < 64; i++)
			{
				BloomString bloomString = Nearby[i];
				if (!((Object)(object)bloomString == (Object)null) && bloomString.modified)
				{
					float num = BloomMath.Sample(instance.Mode.Value, time, bloomString.phase, 0f);
					bloomString.ApplyGlow(BloomMath.Clamp(instance.Glow.Value, 0f, 4f) * num);
					if (bloomString.IndividualActive)
					{
						num = bloomString.bulbs.Animate(time, bloomString.phase, instance.Mode.Value, BloomMath.Clamp(instance.Glow.Value, 0f, 4f));
					}
					if (bloomString.chosen && (Object)(object)bloomString.lamp != (Object)null)
					{
						bloomString.lamp.intensity = BloomMath.Clamp(instance.Illumination.Value, 0f, 4f) * (0.75f + 0.25f * num);
					}
				}
			}
		}

		public void Restore()
		{
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			if (!initialized || !modified)
			{
				return;
			}
			bulbs?.Unbind();
			bulbs = null;
			modified = false;
			lastGlow = -1f;
			chosen = false;
			animate = false;
			for (int i = 0; i < renderers.Length; i++)
			{
				if ((Object)(object)renderers[i] != (Object)null)
				{
					renderers[i].SetPropertyBlock(original[i].isEmpty ? null : original[i]);
				}
			}
			if ((Object)(object)ownedLod != (Object)null)
			{
				((Behaviour)ownedLod).enabled = false;
				Object.Destroy((Object)(object)ownedLod);
				ownedLod = null;
			}
			if ((Object)(object)lamp != (Object)null)
			{
				((Behaviour)lamp).enabled = originalEnabled;
				lamp.intensity = originalIntensity;
				lamp.range = originalRange;
				lamp.color = originalColor;
				lamp.shadows = originalShadows;
			}
		}

		public static void Shutdown()
		{
			Nearby.Clear();
			foreach (BloomString item in Live)
			{
				if ((Object)(object)item != (Object)null)
				{
					item.Restore();
				}
			}
			BulbMesh.DisposeAll();
		}

		public static void DetachAll()
		{
			Shutdown();
			BloomString[] array = Live.ToArray();
			foreach (BloomString bloomString in array)
			{
				if ((Object)(object)bloomString != (Object)null)
				{
					Object.Destroy((Object)(object)bloomString);
				}
			}
			Live.Clear();
		}

		private void OnDisable()
		{
			Restore();
		}

		private void OnDestroy()
		{
			Restore();
			Live.Remove(this);
			Nearby.Remove(this);
		}
	}
	public static class BloomMath
	{
		public static readonly string[] Names = new string[5] { "Hearthglow", "Moonbreath", "Firefly Dance", "Wisp Waltz", "Starlit Shimmer" };

		public static float Clamp(float x, float lo, float hi)
		{
			return (float.IsNaN(x) || float.IsInfinity(x)) ? lo : Math.Max(lo, Math.Min(hi, x));
		}

		public static float Sample(int mode, float t, float phase, float along)
		{
			switch (mode)
			{
			case 1:
				return 0.02f + 0.98f * (float)(0.5 + 0.5 * Math.Sin((double)t * 0.8 + (double)phase + (double)along * 3.14159265));
			case 2:
			{
				float num2 = (float)(0.5 + 0.5 * Math.Sin((double)t * (0.9 + 0.3 * Math.Sin(phase + along * 11f)) + (double)phase + (double)(along * 17f)));
				return 0.015f + 0.985f * num2 * num2 * num2 * num2;
			}
			case 3:
			{
				float num = (float)(0.5 + 0.5 * Math.Sin((double)t * 1.2 - (double)along * 6.2831853 + (double)phase));
				return 0.02f + 0.98f * num * num * num;
			}
			case 4:
				return 0.04f + 0.48f * (float)(1.0 + Math.Sin((double)t * 0.73 + (double)phase + (double)(along * 5f)) * Math.Sin((double)t * 1.09 + (double)(along * 9f)));
			default:
				return 1f;
			}
		}

		public static float PositionPhase(float x, float y, float z)
		{
			return (float)((Math.Sin((double)x * 12.9898 + (double)y * 37.719 + (double)z * 78.233) * 43758.5453 % 1.0 + 1.0) % 1.0 * 6.2831853);
		}
	}
	public sealed class BulbMesh
	{
		public Mesh Mesh;

		public float[] Along;

		private static readonly Dictionary<Mesh, BulbMesh> Cache = new Dictionary<Mesh, BulbMesh>();

		public static int CachedCount => Cache.Count;

		private static float Half(ushort h)
		{
			int num = (h >> 15) & 1;
			int num2 = (h >> 10) & 0x1F;
			int num3 = h & 0x3FF;
			float num4 = ((num2 == 0) ? ((float)((double)num3 * Math.Pow(2.0, -24.0))) : ((float)((1.0 + (double)num3 / 1024.0) * Math.Pow(2.0, num2 - 15))));
			return (num == 0) ? num4 : (0f - num4);
		}

		private static void Require(bool valid)
		{
			if (!valid)
			{
				throw new InvalidOperationException("Unsupported fey bulb mesh layout");
			}
		}

		public static BulbMesh Get(Mesh source)
		{
			if (Cache.TryGetValue(source, out var value))
			{
				return value;
			}
			try
			{
				value = Build(source);
				Cache[source] = value;
				return value;
			}
			catch (Exception ex)
			{
				Cache[source] = null;
				Debug.LogWarning((object)("Feylight Bloom: individual bulbs unavailable; retaining whole-string glow. " + ex.Message));
				return null;
			}
		}

		private static BulbMesh Build(Mesh source)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Invalid comparison between Unknown and I4
			//IL_003b: 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_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e4: Expected O, but got Unknown
			//IL_057f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0584: Unknown result type (might be due to invalid IL or missing references)
			//IL_0589: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d0: Unknown result type (might be due to invalid IL or missing references)
			Require((Object)(object)source != (Object)null && source.vertexCount == 1100 && source.subMeshCount == 1 && source.vertexBufferCount == 1 && source.GetVertexBufferStride(0) == 32 && (int)source.indexFormat == 0 && source.GetIndexCount(0) == 4272);
			Require((int)source.GetVertexAttributeFormat((VertexAttribute)0) == 0 && source.GetVertexAttributeOffset((VertexAttribute)0) == 0 && (int)source.GetVertexAttributeFormat((VertexAttribute)4) == 1 && source.GetVertexAttributeOffset((VertexAttribute)4) == 28);
			GraphicsBuffer vertexBuffer = source.GetVertexBuffer(0);
			byte[] vertices;
			try
			{
				vertices = new byte[vertexBuffer.count * vertexBuffer.stride];
				vertexBuffer.GetData((Array)vertices);
			}
			finally
			{
				((IDisposable)vertexBuffer)?.Dispose();
			}
			GraphicsBuffer indexBuffer = source.GetIndexBuffer();
			ushort[] array;
			try
			{
				array = new ushort[indexBuffer.count];
				indexBuffer.GetData((Array)array);
			}
			finally
			{
				((IDisposable)indexBuffer)?.Dispose();
			}
			Require(vertices.Length == 35200 && array.Length == 4272);
			int[] parents = Enumerable.Range(0, 1100).ToArray();
			Func<int, int> find = null;
			find = delegate(int i)
			{
				while (parents[i] != i)
				{
					parents[i] = parents[parents[i]];
					i = parents[i];
				}
				return i;
			};
			Action<int, int> action = delegate(int a, int b)
			{
				parents[find(a)] = find(b);
			};
			Dictionary<Vector3, int> dictionary = new Dictionary<Vector3, int>();
			Vector3 key = default(Vector3);
			for (int num = 0; num < 1100; num++)
			{
				((Vector3)(ref key))..ctor(BitConverter.ToSingle(vertices, num * 32), BitConverter.ToSingle(vertices, num * 32 + 4), BitConverter.ToSingle(vertices, num * 32 + 8));
				if (dictionary.TryGetValue(key, out var value))
				{
					action(num, value);
				}
				else
				{
					dictionary[key] = num;
				}
			}
			for (int num2 = 0; num2 < array.Length; num2 += 3)
			{
				Require(array[num2] < 1100 && array[num2 + 1] < 1100 && array[num2 + 2] < 1100);
				action(array[num2], array[num2 + 1]);
				action(array[num2], array[num2 + 2]);
			}
			Dictionary<int, List<int>> dictionary2 = new Dictionary<int, List<int>>();
			for (int num3 = 0; num3 < 1100; num3++)
			{
				float num4 = Half(BitConverter.ToUInt16(vertices, num3 * 32 + 28));
				float num5 = Half(BitConverter.ToUInt16(vertices, num3 * 32 + 30));
				if (!(num4 < 0.84f) && !(num4 > 1f) && !(num5 < 0.79f) && !(num5 > 1f))
				{
					int key2 = find(num3);
					if (!dictionary2.ContainsKey(key2))
					{
						dictionary2[key2] = new List<int>();
					}
					dictionary2[key2].Add(num3);
				}
			}
			Require(dictionary2.Count == 12 && dictionary2.Values.All((List<int> group) => group.Count == 14));
			KeyValuePair<int, List<int>>[] array2 = dictionary2.OrderBy((KeyValuePair<int, List<int>> pair) => pair.Value.Average((int i) => BitConverter.ToSingle(vertices, i * 32))).ToArray();
			float[] xs = array2.Select((KeyValuePair<int, List<int>> pair) => pair.Value.Average((int i) => BitConverter.ToSingle(vertices, i * 32))).ToArray();
			Dictionary<int, int> dictionary3 = new Dictionary<int, int>();
			for (int num6 = 0; num6 < 12; num6++)
			{
				dictionary3[array2[num6].Key] = num6 + 1;
			}
			List<ushort>[] array3 = (from _ in Enumerable.Range(0, 13)
				select new List<ushort>()).ToArray();
			for (int num7 = 0; num7 < array.Length; num7 += 3)
			{
				int value2;
				int num8 = (dictionary3.TryGetValue(find(array[num7]), out value2) ? value2 : 0);
				array3[num8].Add(array[num7]);
				array3[num8].Add(array[num7 + 1]);
				array3[num8].Add(array[num7 + 2]);
			}
			Require(array3.Skip(1).All((List<ushort> group) => group.Count == 36) && array3.Sum((List<ushort> group) => group.Count) == array.Length);
			Mesh val = null;
			try
			{
				val = new Mesh
				{
					name = "FeylightBloom_DerivedBulbs",
					hideFlags = (HideFlags)52
				};
				val.SetVertexBufferParams(1100, source.GetVertexAttributes());
				val.SetVertexBufferData<byte>(vertices, 0, 0, vertices.Length, 0, (MeshUpdateFlags)8);
				ushort[] array4 = array3.SelectMany((List<ushort> group) => group).ToArray();
				val.SetIndexBufferParams(array.Length, (IndexFormat)0);
				val.SetIndexBufferData<ushort>(array4, 0, 0, array4.Length, (MeshUpdateFlags)8);
				val.subMeshCount = 13;
				int num9 = 0;
				for (int num10 = 0; num10 < 13; num10++)
				{
					Mesh obj = val;
					int num11 = num10;
					SubMeshDescriptor val2 = new SubMeshDescriptor(num9, array3[num10].Count, (MeshTopology)0);
					((SubMeshDescriptor)(ref val2)).bounds = source.bounds;
					((SubMeshDescriptor)(ref val2)).vertexCount = source.vertexCount;
					obj.SetSubMesh(num11, val2, (MeshUpdateFlags)8);
					num9 += array3[num10].Count;
				}
				val.bounds = source.bounds;
				val.UploadMeshData(true);
				return new BulbMesh
				{
					Mesh = val,
					Along = xs.Select((float x) => Mathf.InverseLerp(xs[0], xs[11], x)).ToArray()
				};
			}
			catch
			{
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
				throw;
			}
		}

		public static void DisposeAll()
		{
			foreach (BulbMesh value in Cache.Values)
			{
				if ((Object)(object)value?.Mesh != (Object)null)
				{
					Object.Destroy((Object)(object)value.Mesh);
				}
			}
			Cache.Clear();
		}
	}
	public sealed class BulbVisual
	{
		private static readonly int Emission = Shader.PropertyToID("_EmissionColor");

		private readonly Renderer[] renderers;

		private readonly MeshFilter[] filters;

		private readonly Mesh[] originals;

		private readonly Material[][] materials;

		private readonly Material[][] splitMaterials;

		private readonly BulbMesh[] derived;

		private readonly MaterialPropertyBlock[][] blocks;

		private readonly MaterialPropertyBlock[] indexZero;

		private readonly Color[] colors;

		public bool Active { get; private set; }

		public bool Supported { get; private set; }

		public BulbVisual(Renderer[] targets, Color[] originalColors)
		{
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Expected O, but got Unknown
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Expected O, but got Unknown
			renderers = targets;
			colors = originalColors;
			filters = (MeshFilter[])(object)new MeshFilter[4];
			originals = (Mesh[])(object)new Mesh[4];
			materials = new Material[4][];
			splitMaterials = new Material[4][];
			derived = new BulbMesh[4];
			blocks = new MaterialPropertyBlock[4][];
			indexZero = (MaterialPropertyBlock[])(object)new MaterialPropertyBlock[4];
			for (int i = 0; i < 4; i++)
			{
				filters[i] = ((Component)targets[i]).GetComponent<MeshFilter>();
				if ((Object)(object)filters[i] == (Object)null)
				{
					return;
				}
				originals[i] = filters[i].sharedMesh;
				materials[i] = targets[i].sharedMaterials;
				if (materials[i].Length != 1)
				{
					return;
				}
				derived[i] = BulbMesh.Get(originals[i]);
				if (derived[i] == null)
				{
					return;
				}
				splitMaterials[i] = Enumerable.Repeat<Material>(materials[i][0], 13).ToArray();
				indexZero[i] = new MaterialPropertyBlock();
				targets[i].GetPropertyBlock(indexZero[i], 0);
				blocks[i] = (MaterialPropertyBlock[])(object)new MaterialPropertyBlock[12];
				for (int j = 0; j < 12; j++)
				{
					blocks[i][j] = new MaterialPropertyBlock();
				}
			}
			Supported = true;
		}

		public void Bind()
		{
			if (!Active && Supported)
			{
				for (int i = 0; i < 4; i++)
				{
					filters[i].sharedMesh = derived[i].Mesh;
					renderers[i].sharedMaterials = splitMaterials[i];
				}
				Active = true;
			}
		}

		public float Animate(float time, float phase, int mode, float glow)
		{
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f;
			for (int i = 0; i < 12; i++)
			{
				num += BloomMath.Sample(mode, time, phase, derived[0].Along[i]);
			}
			for (int j = 0; j < 4; j++)
			{
				Renderer val = renderers[j];
				if ((Object)(object)val == (Object)null || !val.enabled || !((Component)val).gameObject.activeInHierarchy)
				{
					continue;
				}
				for (int k = 0; k < 12; k++)
				{
					MaterialPropertyBlock val2 = blocks[j][k];
					if (indexZero[j].isEmpty)
					{
						val.GetPropertyBlock(val2);
					}
					else
					{
						val.GetPropertyBlock(val2, 0);
					}
					float num2 = glow * BloomMath.Sample(mode, time, phase, derived[j].Along[k]);
					Color val3 = colors[j];
					val3.r *= num2;
					val3.g *= num2;
					val3.b *= num2;
					val2.SetColor(Emission, val3);
					val.SetPropertyBlock(val2, k + 1);
				}
			}
			return num / 12f;
		}

		public void Unbind()
		{
			if (!Active)
			{
				return;
			}
			for (int i = 0; i < 4; i++)
			{
				if (!((Object)(object)renderers[i] == (Object)null) && !((Object)(object)filters[i] == (Object)null))
				{
					for (int j = 1; j <= 12; j++)
					{
						renderers[i].SetPropertyBlock((MaterialPropertyBlock)null, j);
					}
					filters[i].sharedMesh = originals[i];
					renderers[i].sharedMaterials = materials[i];
					renderers[i].SetPropertyBlock(indexZero[i].isEmpty ? null : indexZero[i], 0);
				}
			}
			Active = false;
		}
	}
	public static class Skin
	{
		private static readonly Dictionary<string, Texture2D> textures = new Dictionary<string, Texture2D>();

		public static int Count => textures.Count;

		public static Texture2D Get(string name)
		{
			Texture2D value;
			return textures.TryGetValue(name, out value) ? value : null;
		}

		public static void Load()
		{
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Expected O, but got Unknown
			if (textures.Count > 0)
			{
				return;
			}
			string[] array = new string[9] { "panel-background", "title-wordmark", "mode-selector", "slider-track", "slider-thumb", "action-button", "close-button", "checkbox-off", "checkbox-on" };
			foreach (string text in array)
			{
				Texture2D val = null;
				try
				{
					using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("FeylightBloom.Art." + text + ".png");
					if (stream == null)
					{
						throw new Exception("Missing embedded artwork " + text);
					}
					byte[] array2 = new byte[stream.Length];
					int num;
					for (int j = 0; j < array2.Length; j += num)
					{
						num = stream.Read(array2, j, array2.Length - j);
						if (num == 0)
						{
							throw new Exception("Incomplete artwork " + text);
						}
					}
					val = new Texture2D(2, 2, (TextureFormat)4, false);
					((Object)val).name = "FeylightBloom." + text;
					((Object)val).hideFlags = (HideFlags)61;
					if (!(bool)Assembly.Load("UnityEngine.ImageConversionModule").GetType("UnityEngine.ImageConversion", throwOnError: true).GetMethod("LoadImage", new Type[3]
					{
						typeof(Texture2D),
						typeof(byte[]),
						typeof(bool)
					})
						.Invoke(null, new object[3] { val, array2, true }))
					{
						throw new Exception("Invalid artwork " + text);
					}
					((Texture)val).wrapMode = (TextureWrapMode)1;
					((Texture)val).filterMode = (FilterMode)1;
					textures.Add(text, val);
				}
				catch (Exception ex)
				{
					if ((Object)(object)val != (Object)null)
					{
						Object.Destroy((Object)(object)val);
					}
					Debug.LogWarning((object)("Feylight Bloom: " + ex.Message));
				}
			}
		}

		public static void Dispose()
		{
			foreach (Texture2D value in textures.Values)
			{
				if ((Object)(object)value != (Object)null)
				{
					Object.Destroy((Object)(object)value);
				}
			}
			textures.Clear();
		}
	}
}