Decompiled source of LightPlugin v2.7.0

LightPlugin.dll

Decompiled 8 months ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using Bounce.Singletons;
using Bounce.Unmanaged;
using Newtonsoft.Json;
using RadialUI;
using TMPro;
using UnityEngine;
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: AssemblyTitle("LightPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LightPlugin")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("LightPlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("2.7.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("2.7.0.0")]
namespace LordAshes;

[BepInPlugin("org.lordashes.plugins.light", "Light Plug-In", "2.7.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class LightPlugin : BaseUnityPlugin
{
	public static class Utility
	{
		public static bool isBoardLoaded()
		{
			return SimpleSingletonBehaviour<CameraController>.HasInstance && SingletonStateMBehaviour<BoardSessionManager, State<BoardSessionManager>>.HasInstance && !BoardSessionManager.IsLoading;
		}

		public static Guid GuidFromString(string input)
		{
			using MD5 mD = MD5.Create();
			byte[] b = mD.ComputeHash(Encoding.Default.GetBytes(input));
			return new Guid(b);
		}

		public static GameObject GetBaseLoader(CreatureGuid cid)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				CreatureBoardAsset val = null;
				CreaturePresenter.TryGetAsset(cid, ref val);
				if ((Object)(object)val != (Object)null)
				{
					Transform match = null;
					Traverse(((Component)val).transform, "BaseLoader", 0, 10, ref match);
					if ((Object)(object)match != (Object)null)
					{
						Debug.Log((object)("Light Plug-In: Base Loader '" + ((Object)match.GetChild(0)).name + "' Found"));
						return ((Component)match.GetChild(0)).gameObject;
					}
					Debug.LogWarning((object)"Light Plug-In: Could Not Find Base Loader");
					return null;
				}
				return null;
			}
			catch
			{
				return null;
			}
		}

		public static GameObject GetAssetLoader(CreatureGuid cid)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				CreatureBoardAsset val = null;
				CreaturePresenter.TryGetAsset(cid, ref val);
				if ((Object)(object)val != (Object)null)
				{
					Transform match = null;
					Traverse(((Component)val).transform, "AssetLoader", 0, 10, ref match);
					if ((Object)(object)match != (Object)null)
					{
						Debug.Log((object)("Light Plug-In: Asset Loader '" + ((Object)match.GetChild(0)).name + "' Found"));
						return ((Component)match.GetChild(0)).gameObject;
					}
					Debug.LogWarning((object)"Light Plug-In: Could Not Find Asset Loader");
					return null;
				}
				return null;
			}
			catch
			{
				return null;
			}
		}

		public static void Traverse(Transform root, string seek, int depth, int depthMax, ref Transform match)
		{
			try
			{
				if ((Object)(object)match != (Object)null)
				{
					return;
				}
				if (((Object)root).name == seek)
				{
					match = root;
					return;
				}
				foreach (Transform item in ExtensionMethods.Children(root))
				{
					if (depth < depthMax)
					{
						Traverse(item, seek, depth + 1, depthMax, ref match);
					}
				}
			}
			catch
			{
			}
		}

		public static float ParseFloat(string value)
		{
			return float.Parse(value, CultureInfo.InvariantCulture);
		}

		public static string GetCreatureName(string nameBlock)
		{
			if (nameBlock == null)
			{
				return "(Unknown)";
			}
			if (!nameBlock.Contains("<size=0>"))
			{
				return nameBlock;
			}
			return nameBlock.Substring(0, nameBlock.IndexOf("<size=0>")).Trim();
		}

		public static void PostOnMainPage(MemberInfo plugin)
		{
			SceneManager.sceneLoaded += delegate(Scene scene, LoadSceneMode mode)
			{
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Expected O, but got Unknown
				try
				{
					if (((Scene)(ref scene)).name == "UI")
					{
						TextMeshProUGUI uITextByName = GetUITextByName("BETA");
						if (Object.op_Implicit((Object)(object)uITextByName))
						{
							((TMP_Text)uITextByName).text = "INJECTED BUILD - unstable mods";
						}
					}
					else
					{
						TextMeshProUGUI uITextByName2 = GetUITextByName("TextMeshPro Text");
						if (Object.op_Implicit((Object)(object)uITextByName2))
						{
							BepInPlugin val = (BepInPlugin)Attribute.GetCustomAttribute(plugin, typeof(BepInPlugin));
							if (((TMP_Text)uITextByName2).text.EndsWith("</size>"))
							{
								((TMP_Text)uITextByName2).text = ((TMP_Text)uITextByName2).text + "\n\nMods Currently Installed:\n";
							}
							TextMeshProUGUI val2 = uITextByName2;
							((TMP_Text)val2).text = ((TMP_Text)val2).text + "\nLord Ashes' " + val.Name + " - " + val.Version;
						}
					}
				}
				catch (Exception ex)
				{
					Debug.Log((object)ex);
				}
			};
		}

		private static TextMeshProUGUI GetUITextByName(string name)
		{
			TextMeshProUGUI[] array = Object.FindObjectsOfType<TextMeshProUGUI>();
			for (int i = 0; i < array.Length; i++)
			{
				if (((Object)array[i]).name == name)
				{
					return array[i];
				}
			}
			return null;
		}
	}

	public enum SubscriptionState
	{
		unsubscribed,
		waiting,
		subscribed
	}

	public class F3
	{
		public float x { get; set; } = 0f;


		public float y { get; set; } = 0f;


		public float z { get; set; } = 0f;


		public F3()
		{
		}

		public F3(float x, float y, float z)
		{
			this.x = x;
			this.y = y;
			this.z = z;
		}

		public Vector3 ToVector3()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(x, y, z);
		}

		public Vector3 ToVector3FromTalespireToUnity()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(x, z, y);
		}
	}

	public class LightBehaviour
	{
		public bool flicker { get; set; } = false;


		public float intensityMin { get; set; } = 0f;


		public float intensityMax { get; set; } = 0f;


		public float deltaMax { get; set; } = 0f;


		public bool sight { get; set; } = false;


		public bool hiddenBase { get; set; } = false;

	}

	public class LightMenu
	{
		public string iconName { get; set; } = "Light.png";


		public bool onlyGM { get; set; } = false;


		public string menuNode { get; set; } = "";


		public string menuLink { get; set; } = "";

	}

	public class LightProperties
	{
		public LightType type { get; set; } = (LightType)0;


		public Color color { get; set; } = Color.FromArgb(255, 255, 255, 255);


		public float range { get; set; } = 3.5f;


		public float spotAngle { get; set; } = 25f;


		public LightShadows shadows { get; set; } = (LightShadows)2;

	}

	public class LightSpecs
	{
		public string name { get; set; } = "Light";


		public LightProperties specs { get; set; } = new LightProperties();


		public F3 position { get; set; } = null;


		public F3 rotation { get; set; } = null;


		public LightBehaviour behaviour { get; set; } = new LightBehaviour();


		public LightMenu menu { get; set; } = new LightMenu();

	}

	public class LegacyLightSpecs
	{
		public string name { get; set; } = "Light";


		public LightType lightType { get; set; } = (LightType)2;


		public LightShadows shadowType { get; set; } = (LightShadows)2;


		public string iconName { get; set; } = "Light.png";


		public float intensity { get; set; } = 0.01f;


		public Color color { get; set; } = Color.FromArgb(255, 255, 128);


		public float range { get; set; } = 2f;


		public string pos { get; set; } = "0,0.75,0";


		public string rot { get; set; } = "90,0,0";


		public float spotAngle { get; set; } = 15f;


		public bool flicker { get; set; } = false;


		public float intensityMin { get; set; } = 0f;


		public float deltaMax { get; set; } = 0f;


		public bool sight { get; set; } = false;


		public bool hiddenBase { get; set; } = false;


		public bool onlyGM { get; set; } = false;


		public string menuNode { get; set; } = "";


		public string menuLink { get; set; } = "";

	}

	public const string Name = "Light Plug-In";

	public const string Guid = "org.lordashes.plugins.light";

	public const string Version = "2.7.0.0";

	public const string Author = "Lord Ashes";

	public static string configLocation = "";

	public static Dictionary<string, LightSpecs> lights = new Dictionary<string, LightSpecs>();

	private GuiMenu menu = new GuiMenu();

	private static float intensityMultiplier = 300f;

	private int flickerSequencer = 0;

	private int flickerSteps = 20;

	private SubscriptionState subscription = SubscriptionState.unsubscribed;

	private static LightPlugin self = null;

	private static ConcurrentQueue<DatumChange[]> backlog = new ConcurrentQueue<DatumChange[]>();

	private ConfigEntry<KeyboardShortcut> triggerManualApply { get; set; }

	private ConfigEntry<KeyboardShortcut> triggerRereadConfig { get; set; }

	private ConfigEntry<float> subscriptionDelay { get; set; }

	private MenuStyle menuStyle { get; set; }

	private Color menuLinkColor { get; set; }

	private Color menuSelectionColor { get; set; }

	public void RadialMenuRequest(CreatureGuid cid, NGuid rid, string lightName)
	{
		if (lightName == "None")
		{
			Debug.Log((object)"Light Plugin: Requesting No Light");
			AssetDataPlugin.ClearInfo(((object)(NGuid)(ref rid)).ToString(), "org.lordashes.plugins.light", false);
		}
		else if (lights.ContainsKey(lightName))
		{
			AssetDataPlugin.SetInfo(((object)(NGuid)(ref rid)).ToString(), "org.lordashes.plugins.light", lightName, false);
		}
		else
		{
			Debug.Log((object)("Light Plugin: Don't Seem To Have A '" + lightName + "' Light"));
		}
	}

	public void LightRequest(DatumChange change)
	{
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Invalid comparison between Unknown and I4
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f1: 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)
		Debug.Log((object)"Light Plugin: Changes Received");
		if (subscription != SubscriptionState.subscribed)
		{
			Debug.Log((object)"Light Plugin: Addings Changes To Backlog");
			backlog.Enqueue((DatumChange[])(object)new DatumChange[1] { change });
			return;
		}
		string[] obj = new string[11]
		{
			"Light Plugin: Change '", null, null, null, null, null, null, null, null, null,
			null
		};
		ChangeAction action = change.action;
		obj[1] = ((object)(ChangeAction)(ref action)).ToString();
		obj[2] = "' for '";
		obj[3] = change.source;
		obj[4] = "' from '";
		obj[5] = change.previous?.ToString();
		obj[6] = "' To '";
		obj[7] = change.value?.ToString();
		obj[8] = "' (";
		obj[9] = change.key;
		obj[10] = ")";
		Debug.Log((object)string.Concat(obj));
		bool flag = true;
		if ((int)change.action != 1)
		{
			flag = !lights[change.value.ToString()].behaviour.sight || LocalClient.CanControlCreature(new CreatureGuid(change.source));
			Debug.Log((object)("Light Plugin: Processing A '" + change.value?.ToString() + "' Light Request (Sight Light: " + lights[change.value.ToString()].behaviour.sight + " | Controlled: " + LocalClient.CanControlCreature(new CreatureGuid(change.source)) + " => " + flag + ")"));
			if (flag)
			{
				ProcessRequest(new CreatureGuid(change.source), change.value.ToString());
			}
		}
		else
		{
			flag = !(change.previous.ToString() != "") || !lights[change.previous.ToString()].behaviour.sight || LocalClient.CanControlCreature(new CreatureGuid(change.source));
			Debug.Log((object)("Light Plugin: Processing A No Light Request (Sight Light: " + ((change.previous.ToString() != "") ? lights[change.previous.ToString()].behaviour.sight.ToString() : "N/A") + " | Controlled: " + LocalClient.CanControlCreature(new CreatureGuid(change.source)) + " => " + flag + ")"));
			if (flag)
			{
				ProcessRequest(new CreatureGuid(change.source), "");
			}
		}
	}

	private void ProcessRequest(CreatureGuid cid, string lightName)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		if (lightName != "")
		{
			ProcessLightRequest(cid, lights[lightName]);
		}
		else
		{
			ProcessLightRequest(cid, null);
		}
	}

	private void ProcessLightRequest(CreatureGuid cid, LightSpecs ls)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Expected O, but got Unknown
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		//IL_0255: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_0276: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0335: Unknown result type (might be due to invalid IL or missing references)
		//IL_0379: Unknown result type (might be due to invalid IL or missing references)
		//IL_037e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0382: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0406: Unknown result type (might be due to invalid IL or missing references)
		CreatureBoardAsset val = default(CreatureBoardAsset);
		CreaturePresenter.TryGetAsset(cid, ref val);
		if (ls != null)
		{
			GameObject val2 = null;
			GameObject[] array = Object.FindObjectsOfType<GameObject>();
			foreach (GameObject val3 in array)
			{
				if (((Object)val3).name.StartsWith("Effect:Light:") && ((Object)val3).name.EndsWith(((object)(CreatureGuid)(ref cid)).ToString()))
				{
					val2 = val3;
					break;
				}
			}
			if ((Object)(object)val2 == (Object)null)
			{
				Debug.Log((object)"Light Plugin: Creating New Light Socket");
				val2 = new GameObject("Effect:Light:" + ((object)(CreatureGuid)(ref cid)).ToString());
				((Object)val2).name = "Effect:Light:" + ((object)(CreatureGuid)(ref cid)).ToString();
			}
			Light val4 = val2.GetComponent<Light>();
			if ((Object)(object)val4 == (Object)null)
			{
				Debug.Log((object)"Light Plugin: Creating New Light");
				val4 = val2.AddComponent<Light>();
				((Object)val4).name = "Effect:Light:" + ((object)(CreatureGuid)(ref cid)).ToString();
			}
			Debug.Log((object)("Light Plugin: Applying:\r\n" + JsonConvert.SerializeObject((object)ls)));
			Debug.Log((object)"Light Plugin: Adjusting The Light");
			((Object)val4).name = "Effect:Light:" + ls.name + ":" + ((object)(CreatureGuid)(ref cid)).ToString();
			val4.intensity = ls.behaviour.intensityMax;
			val4.type = ls.specs.type;
			val4.color = new Color((float)(int)ls.specs.color.R / 255f, (float)(int)ls.specs.color.G / 255f, (float)(int)ls.specs.color.B / 255f, (float)(int)ls.specs.color.A / 255f);
			val4.range = ls.specs.range;
			val4.spotAngle = ls.specs.spotAngle;
			val4.shadows = ls.specs.shadows;
			Debug.Log((object)("Light Plugin: Color = " + Convert.ToString(val4.color)));
			val2.transform.position = Utility.GetBaseLoader(val.CreatureId).transform.position;
			val2.transform.SetParent(Utility.GetBaseLoader(val.CreatureId).transform);
			Debug.Log((object)("Light Plugin: Secured Light To Base (Pos: " + Convert.ToString(val2.transform.position) + ", Rot: " + Convert.ToString(val2.transform.eulerAngles) + ")"));
			Debug.Log((object)("Light Plugin: Light Offset (Pos: " + JsonConvert.SerializeObject((object)ls.position) + ", Rot: " + JsonConvert.SerializeObject((object)ls.rotation) + ")"));
			val2.transform.localPosition = ls.position.ToVector3FromTalespireToUnity();
			Transform transform = val2.transform;
			Quaternion val5 = Quaternion.Euler(ls.rotation.x - 90f, ls.rotation.y + 180f, ls.rotation.z + 180f);
			transform.localEulerAngles = ((Quaternion)(ref val5)).eulerAngles;
			Debug.Log((object)("Light Plugin: Adjusting Light Position (Pos: " + Convert.ToString(val2.transform.localPosition) + ", Rot: " + Convert.ToString(val2.transform.localEulerAngles) + ")"));
			if (ls.behaviour.hiddenBase)
			{
				CreatureManager.SetCreatureExplicitHideState(val.CreatureId, true);
				CreatureManager.SetCreatureName(val.CreatureId, "<color=red>");
			}
			Debug.Log((object)"Light Plugin: Light Ready");
			return;
		}
		Debug.Log((object)"Light Plugin: Extinguishing Light");
		GameObject val6 = null;
		GameObject[] array2 = Object.FindObjectsOfType<GameObject>();
		foreach (GameObject val7 in array2)
		{
			if (((Object)val7).name.StartsWith("Effect:Light:") && ((Object)val7).name.EndsWith(((object)(CreatureGuid)(ref cid)).ToString()))
			{
				val6 = val7;
				break;
			}
		}
		if ((Object)(object)val6 != (Object)null)
		{
			Object.Destroy((Object)(object)val6);
		}
		Debug.Log((object)"Light Plugin: Light Removed");
	}

	private void Awake()
	{
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0255: Unknown result type (might be due to invalid IL or missing references)
		//IL_025a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: Unknown result type (might be due to invalid IL or missing references)
		//IL_028c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b7: Expected O, but got Unknown
		//IL_034f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0354: Unknown result type (might be due to invalid IL or missing references)
		//IL_035b: Expected O, but got Unknown
		//IL_04af: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e0: Expected O, but got Unknown
		//IL_040e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0435: Unknown result type (might be due to invalid IL or missing references)
		//IL_043f: Expected O, but got Unknown
		self = this;
		Debug.Log((object)("Light Plugin: " + ((object)this).GetType().AssemblyQualifiedName + " Is Active."));
		flickerSteps = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "Updates per flicker update", 20, (ConfigDescription)null).Value;
		menuStyle = ((BaseUnityPlugin)this).Config.Bind<MenuStyle>("Settings", "GUI menu style", (MenuStyle)0, (ConfigDescription)null).Value;
		menuLinkColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Settings", "GUI menu link color", Color.black, (ConfigDescription)null).Value;
		menuSelectionColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Settings", "GUI menu selection color", Color.gray, (ConfigDescription)null).Value;
		subscriptionDelay = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Startup light application delay", 10f, (ConfigDescription)null);
		triggerManualApply = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Manual re-apply of lights", new KeyboardShortcut((KeyCode)114, (KeyCode[])(object)new KeyCode[1] { (KeyCode)305 }), (ConfigDescription)null);
		triggerRereadConfig = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Reread lights configuration", new KeyboardShortcut((KeyCode)108, (KeyCode[])(object)new KeyCode[1] { (KeyCode)305 }), (ConfigDescription)null);
		ReadConfiguration(ref lights);
		Debug.Log((object)"Light Plugin: Detecting Usage Of Sub-Menus");
		bool flag = false;
		foreach (LightSpecs value in lights.Values)
		{
			if (value.menu.menuNode != "")
			{
				flag = true;
				break;
			}
		}
		if (flag)
		{
			Debug.Log((object)"Light Plugin: Using GUI Menus With Hierarchy.");
			Debug.Log((object)"Light Plugin: Adding Extinguish Light Option");
			LightSpecs lightSpecs = new LightSpecs
			{
				name = "None",
				menu = new LightMenu
				{
					iconName = "None.png",
					menuNode = "Root"
				}
			};
			if (lights.ContainsKey(lightSpecs.name))
			{
				lights.Remove(lightSpecs.name);
			}
			lights.Add(lightSpecs.name, lightSpecs);
			Debug.Log((object)"Light Plugin: Adding Light Options");
			RadialUIPlugin.AddCustomButtonOnCharacter("org.lordashes.plugins.light", new ItemArgs
			{
				Title = "Light",
				Icon = Image.LoadSprite("Light.png", (CacheType)999),
				Action = delegate
				{
					Debug.Log((object)"Light Plugin: Opening GUI Menu");
					menu.Open("Root", (Action<string>)LightSelectionHandler);
				},
				CloseMenuOnActivate = true
			}, (Func<NGuid, NGuid, bool>)((NGuid guid1, NGuid guid2) => true));
			foreach (LightSpecs value2 in lights.Values)
			{
				if (menu.GetNode(value2.menu.menuNode) == null)
				{
					Debug.Log((object)("Light Plugin: Making Node '" + value2.menu.menuNode + "' For '" + value2.name + "'"));
					MenuNode val = new MenuNode(value2.menu.menuNode, (IMenuItem[])(object)new IMenuItem[0], menuStyle);
					menu.AddNode(val);
				}
				if (value2.menu.menuLink != "")
				{
					Debug.Log((object)("Light Plugin: Adding Link '" + value2.menu.menuLink + "' To Node '" + value2.menu.menuNode + "' For '" + value2.name + "'"));
					menu.GetNode(value2.menu.menuNode).AddLink(new MenuLink(value2.menu.menuLink, value2.name, menuLinkColor, Image.LoadTexture(value2.menu.iconName, (CacheType)999), value2.menu.onlyGM));
				}
				else
				{
					Debug.Log((object)("Light Plugin: Adding Selection '" + value2.name + "' To Node '" + value2.menu.menuNode + "'"));
					menu.GetNode(value2.menu.menuNode).AddSelection(new MenuSelection(value2.name, value2.name, menuSelectionColor, Image.LoadTexture(value2.menu.iconName, (CacheType)999), value2.menu.onlyGM));
					Debug.Log((object)"Light Plugin: Adding To Light Dictionary");
				}
			}
		}
		else
		{
			Debug.Log((object)"Light Plugin: Using Flat Radial Menu.");
			Debug.Log((object)"Light Plugin: Adding Extinguish Light Option");
			LightSpecs lightSpecs2 = new LightSpecs
			{
				name = "None",
				menu = new LightMenu
				{
					iconName = "None.png"
				}
			};
			if (lights.ContainsKey(lightSpecs2.name))
			{
				lights.Remove(lightSpecs2.name);
			}
			lights.Add(lightSpecs2.name, lightSpecs2);
			Debug.Log((object)"Light Plugin: Adding Light Options");
			RadialSubmenu.EnsureMainMenuItem("org.lordashes.plugins.light", (MenuType)1, "Light", Image.LoadSprite("Light.png", (CacheType)999));
			foreach (LightSpecs light in lights.Values)
			{
				RadialSubmenu.CreateSubMenuItem("org.lordashes.plugins.light", light.name, Image.LoadSprite(light.menu.iconName, (CacheType)999), (Action<CreatureGuid, string, MapMenuItem>)delegate(CreatureGuid cid, string s, MapMenuItem mmi)
				{
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					//IL_0008: Unknown result type (might be due to invalid IL or missing references)
					RadialMenuRequest(cid, RadialUIPlugin.GetLastRadialTargetCreature(), light.name);
				}, true, (Func<bool>)delegate
				{
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					bool isInGmMode = LocalClient.IsInGmMode;
					return (LocalClient.CanControlCreature(new CreatureGuid(RadialUIPlugin.GetLastRadialTargetCreature())) && (isInGmMode || !light.menu.onlyGM)) ? true : false;
				});
			}
		}
		AssetDataPlugin.Subscribe("org.lordashes.plugins.light", (Action<DatumChange>)LightRequest);
		Utility.PostOnMainPage(((object)this).GetType());
	}

	private IEnumerator DelayLightSubscription(float delay)
	{
		Debug.Log((object)"Light Plugin: Delaying Light Message Processing");
		subscription = SubscriptionState.waiting;
		yield return (object)new WaitForSeconds(delay);
		if (subscription == SubscriptionState.waiting)
		{
			Debug.Log((object)"Light Plugin: Start Light Message Processing");
			subscription = SubscriptionState.subscribed;
		}
	}

	private void LightSelectionHandler(string lightName)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		RadialMenuRequest(LocalClient.SelectedCreatureId, RadialUIPlugin.GetLastRadialTargetCreature(), lightName);
	}

	private void Update()
	{
		//IL_0344: Unknown result type (might be due to invalid IL or missing references)
		//IL_0349: Unknown result type (might be due to invalid IL or missing references)
		//IL_0376: Unknown result type (might be due to invalid IL or missing references)
		//IL_037b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
		if (Utility.isBoardLoaded())
		{
			if (subscription == SubscriptionState.unsubscribed)
			{
				subscription = SubscriptionState.waiting;
				Debug.Log((object)"Light Plugin: Board Loaded");
				((MonoBehaviour)self).StartCoroutine(DelayLightSubscription(subscriptionDelay.Value));
			}
			if (backlog.Count > 0 && subscription == SubscriptionState.subscribed)
			{
				Debug.Log((object)("Light Plugin: Backlog=" + backlog.Count + ". Processing..."));
				DatumChange[] result = null;
				if (backlog.TryDequeue(out result))
				{
					DatumChange[] array = result;
					foreach (DatumChange change in array)
					{
						LightRequest(change);
					}
				}
			}
			flickerSequencer++;
			if (flickerSequencer >= flickerSteps)
			{
				flickerSequencer = 0;
			}
			if (flickerSequencer == 0)
			{
				foreach (CreatureBoardAsset item in (IEnumerable<CreatureBoardAsset>)CreaturePresenter.GetTempReadOnlyViewOfAllCreatureAssets())
				{
					Light componentInChildren = ((Component)item).GetComponentInChildren<Light>();
					if ((Object)(object)componentInChildren != (Object)null && ((Object)componentInChildren).name.StartsWith("Effect:Light:"))
					{
						string text = ((Object)componentInChildren).name.Substring("Effect:Light:".Length);
						text = text.Substring(0, text.IndexOf(":"));
						if (lights.ContainsKey(text) && lights[text].behaviour.flicker)
						{
							Random random = new Random();
							float num = random.Next(0, 100);
							float intensity = num / 100f * (lights[text].behaviour.intensityMax - lights[text].behaviour.intensityMin) + lights[text].behaviour.intensityMin;
							componentInChildren.intensity = intensity;
							float num2 = lights[text].behaviour.deltaMax * (float)random.Next(0, 100) / 100f;
							float num3 = lights[text].behaviour.deltaMax * (float)random.Next(0, 100) / 100f;
							((Component)componentInChildren).transform.localPosition = new Vector3(lights[text].position.x + num2, lights[text].position.y, lights[text].position.z + num3);
						}
					}
				}
			}
		}
		else if (!Utility.isBoardLoaded() && subscription != 0)
		{
			Debug.Log((object)"Light Plugin: Board Unloaded");
			subscription = SubscriptionState.unsubscribed;
		}
		KeyboardShortcut value = triggerManualApply.Value;
		if (((KeyboardShortcut)(ref value)).IsUp())
		{
			Debug.Log((object)"Light Plugin: Manual Re-Apply");
			AssetDataPlugin.Reset("org.lordashes.plugins.light");
		}
		value = triggerRereadConfig.Value;
		if (((KeyboardShortcut)(ref value)).IsUp())
		{
			Debug.Log((object)"Light Plugin: Reread Configuration");
			ReadConfiguration(ref lights);
		}
	}

	private void OnGUI()
	{
		menu.Draw();
	}

	public static void ReadConfiguration(ref Dictionary<string, LightSpecs> lights)
	{
		//IL_026f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
		lights.Clear();
		Debug.Log((object)"Light Plugin: Deserialize JSON Light File.");
		if (File.Exists("LightSpecs.json"))
		{
			Debug.Log((object)"Light Plugin: Found Light Specs Configuration");
			configLocation = File.Find("LightSpecs.json", (CacheType)999)[0];
			string text = File.ReadAllText(configLocation, (CacheType)999);
			List<LightSpecs> list = JsonConvert.DeserializeObject<List<LightSpecs>>(text);
			{
				foreach (LightSpecs item in list)
				{
					lights.Add(item.name, item);
					Debug.Log((object)("Light Plugin:\r\n" + JsonConvert.SerializeObject((object)item)));
				}
				return;
			}
		}
		if (File.Exists("LightTypes.json"))
		{
			Debug.Log((object)"Light Plugin: Found Light Type Configuration");
			configLocation = File.Find("LightTypes.json", (CacheType)999)[0];
			string text2 = File.ReadAllText(configLocation, (CacheType)999);
			List<LegacyLightSpecs> list2 = JsonConvert.DeserializeObject<List<LegacyLightSpecs>>(text2);
			foreach (LegacyLightSpecs item2 in list2)
			{
				string[] array = item2.pos.Split(new char[1] { ',' });
				string[] array2 = item2.rot.Split(new char[1] { ',' });
				LightSpecs lightSpecs = new LightSpecs
				{
					behaviour = new LightBehaviour
					{
						deltaMax = item2.deltaMax,
						flicker = item2.flicker,
						hiddenBase = item2.hiddenBase,
						intensityMax = item2.intensity * intensityMultiplier,
						intensityMin = item2.intensityMin * intensityMultiplier,
						sight = item2.sight
					},
					menu = new LightMenu
					{
						iconName = item2.iconName,
						menuLink = item2.menuLink,
						menuNode = item2.menuNode,
						onlyGM = item2.onlyGM
					},
					name = item2.name,
					position = new F3(Utility.ParseFloat(array[0]), Utility.ParseFloat(array[1]), Utility.ParseFloat(array[2])),
					rotation = new F3(Utility.ParseFloat(array2[0]), Utility.ParseFloat(array2[1]), Utility.ParseFloat(array2[2])),
					specs = new LightProperties
					{
						type = item2.lightType,
						color = item2.color,
						range = item2.range,
						spotAngle = item2.spotAngle,
						shadows = item2.shadowType
					}
				};
				lights.Add(lightSpecs.name, lightSpecs);
			}
			File.WriteAllText(File.Find("LightTypes.json", (CacheType)999)[0].Replace("LightTypes.json", "LightSpecs.json"), JsonConvert.SerializeObject((object)lights.Values, (Formatting)1), (CacheType)999);
		}
		else
		{
			Debug.Log((object)"Light Plugin: Missing Light Configuration");
			Environment.Exit(0);
		}
	}

	public static void UpdateLight(CreatureGuid holder, LightSpecs ls)
	{
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		if (!lights.ContainsKey(ls.name))
		{
			lights.Add(ls.name, ls);
			RadialSubmenu.CreateSubMenuItem("org.lordashes.plugins.light", ls.name, Image.LoadSprite(ls.menu.iconName, (CacheType)999), (Action<CreatureGuid, string, MapMenuItem>)delegate(CreatureGuid cid, string s, MapMenuItem mmi)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				self.RadialMenuRequest(cid, RadialUIPlugin.GetLastRadialTargetCreature(), ls.name);
			}, true, (Func<bool>)delegate
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				bool isInGmMode = LocalClient.IsInGmMode;
				return (LocalClient.CanControlCreature(new CreatureGuid(RadialUIPlugin.GetLastRadialTargetCreature())) && (isInGmMode || !ls.menu.onlyGM)) ? true : false;
			});
		}
		else
		{
			lights[ls.name] = ls;
		}
		self.ProcessLightRequest(holder, ls);
	}
}