Decompiled source of CustomDicePack v3.0.0

CustomDicePackPlugin.dll

Decompiled a year ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using BepInEx;
using BepInEx.Configuration;
using Bounce.ManagedCollections;
using Bounce.Singletons;
using GameChat.UI;
using HarmonyLib;
using Newtonsoft.Json;
using TMPro;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CustomDicePackPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CustomDicePackPlugin")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("CustomDicePackPlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("3.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("3.0.0.0")]
namespace LordAshes;

[BepInPlugin("org.lordashes.plugins.customdicepack", "Custom Dice Pack Plug-In", "3.0.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class CustomDicePackPlugin : BaseUnityPlugin
{
	public class VisualPart
	{
		public string type { get; set; }

		public GameObject reference { get; set; }
	}

	private class Patches
	{
		[HarmonyPatch(typeof(LocalConnectionManager), "ProcessDiceUrl")]
		public static class PatchProcessTaleSpireUrl
		{
			public static bool Prefix(string[] urlParts)
			{
				if (urlParts[0].ToUpper() == "DICE")
				{
					urlParts[1] = HttpUtility.UrlDecode(urlParts[1]);
					if (urlParts[1].Contains("#"))
					{
						string text = "";
						string text2 = "";
						string text3 = "";
						if (urlParts[1].Contains(":"))
						{
							text = urlParts[1].Substring(0, urlParts[1].IndexOf(":"));
							text2 = urlParts[1].Substring(urlParts[1].IndexOf(":") + 1);
							text3 = text2.Substring(text2.IndexOf("#") + 1);
							text2 = text2.Substring(0, text2.IndexOf("#"));
						}
						else
						{
							text = "";
							text2 = urlParts[1].Substring(0, urlParts[1].IndexOf("#"));
							text3 = urlParts[1].Substring(urlParts[1].IndexOf("#") + 1);
						}
						urlParts[1] = text + "<size=0>" + text3 + ":" + text2;
						activeCustomization = text3;
						expecting = uint.Parse(text2.Substring(0, text2.ToUpper().IndexOf("D")));
					}
					if (diagnostics.Value >= DiagnosticLevel.debug)
					{
						Debug.Log((object)("Custom Dice Pack Plug-In: Adjusted Talespire Protocol Request: " + HttpUtility.UrlDecode(JsonConvert.SerializeObject((object)urlParts)) + " (Expecting = " + expecting + ")"));
					}
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Die), "Spawn")]
		public static class PatchSpawn
		{
			public static void Postfix(DieKind kind, float3 pos, quaternion rot, RollId rollId, byte groupId, bool gmOnlyDie, bool showResult, ref Die __result)
			{
				//IL_017c: 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_01c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
				if (diagnostics.Value >= DiagnosticLevel.debug)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Die Spawn (Expecting " + expecting + " For Customization)"));
				}
				if (expecting != 0)
				{
					if (activeCustomization == "")
					{
						throw new Exception("Expecting With No Active Customization Set");
					}
					lock (padlock)
					{
						expecting--;
					}
					if (diagnostics.Value >= DiagnosticLevel.ultra)
					{
						Debug.Log((object)"Custom Dice Pack Plug-In: Getting Customization Information");
					}
					CustomDiceInfo customDiceInfo = customDice[activeCustomization];
					if (diagnostics.Value >= DiagnosticLevel.ultra)
					{
						Debug.Log((object)("Custom Dice Pack Plug-In: Loading Custom Dice Asset Bundle File '" + customDiceInfo.dicePack + "'"));
					}
					AssetBundle val = AssetBundle.LoadFromFile(File.Find(customDiceInfo.dicePack, (CacheType)999)[0]);
					if (diagnostics.Value >= DiagnosticLevel.ultra)
					{
						Debug.Log((object)("Custom Dice Pack Plug-In: Creating Prefab '" + customDiceInfo.diceBase + "'"));
					}
					GameObject val2 = val.LoadAsset<GameObject>(customDiceInfo.diceBase);
					if (diagnostics.Value >= DiagnosticLevel.ultra)
					{
						Debug.Log((object)"Custom Dice Pack Plug-In: Creating Prefab Instance");
					}
					GameObject val3 = Object.Instantiate<GameObject>(val2, Vector3.zero, Quaternion.identity);
					if (diagnostics.Value >= DiagnosticLevel.ultra)
					{
						Debug.Log((object)"Custom Dice Pack Plug-In: Positioning Instance");
					}
					val3.transform.position = ((Component)__result).gameObject.transform.position;
					val3.transform.rotation = ((Component)__result).gameObject.transform.rotation;
					if (diagnostics.Value >= DiagnosticLevel.ultra)
					{
						Debug.Log((object)"Custom Dice Pack Plug-In: Parenting Instance");
					}
					val3.transform.SetParent(((Component)__result).gameObject.transform);
					if (diagnostics.Value >= DiagnosticLevel.ultra)
					{
						Debug.Log((object)"Custom Dice Pack Plug-In: Cleanup");
					}
					Object.Destroy((Object)(object)val2);
					val.Unload(false);
					if (diagnostics.Value >= DiagnosticLevel.ultra)
					{
						Debug.Log((object)"Custom Dice Pack Plug-In: Applying Texture");
					}
					Renderer component = val3.GetComponent<Renderer>();
					component.material.mainTexture = (Texture)(object)Image.LoadTexture(customDiceInfo.diceTexture, (CacheType)999);
				}
			}
		}

		[HarmonyPatch(typeof(UIChatMessageManager), "AddDiceResultMessage")]
		public static class PatchAddDiceResultMessage
		{
			public static bool Prefix(RollResults diceResult, ResultsOrigin origin, ClientGuid sender, ref bool hidden)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: 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)
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				bool flag = false;
				Enumerator<RollResultsGroup> enumerator = diceResult.ResultsGroups.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						RollResultsGroup current = enumerator.Current;
						if (current.Name != null && current.Name.Contains("<size=0>="))
						{
							flag = true;
						}
					}
				}
				finally
				{
					((IDisposable)enumerator).Dispose();
				}
				if (diagnostics.Value >= DiagnosticLevel.debug)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Process Chat Dice Result (isSummary=" + flag + ", showDiceRolls=" + showDiceRolls.Value.ToString() + ", showDiceSummary=" + showDiceSummary.Value.ToString() + ")"));
				}
				if ((flag && showDiceSummary.Value == ShowDiceResult.hidden) || (!flag && showDiceRolls.Value == ShowDiceResult.hidden))
				{
					hidden = true;
				}
				else
				{
					hidden = false;
				}
				return (flag && showDiceSummary.Value != 0) || (!flag && showDiceRolls.Value != ShowDiceResult.none);
			}
		}

		[HarmonyPatch(typeof(UIDiceRollResult), "DisplayResult")]
		public static class PatchDisplayResult
		{
			public static bool Prefix(RollResults rollResultData, ClientGuid sender)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: 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)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: 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)
				Enumerator<RollResultsGroup> enumerator = rollResultData.ResultsGroups.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						RollResultsGroup current = enumerator.Current;
						string text = ((current.Name == null) ? "(None)" : current.Name);
						Debug.Log((object)("Custom Dice Pack Plug-In: Display Result: Group Name = '" + text + "'"));
						if (text.Contains("<size=0>="))
						{
							Debug.Log((object)"Custom Dice Pack Plug-In: Display Result: Supressing Display Result For Summary");
							return false;
						}
					}
				}
				finally
				{
					((IDisposable)enumerator).Dispose();
				}
				Debug.Log((object)"Custom Dice Pack Plug-In: Display Result: Allowing Display Result For Result Roll");
				return true;
			}

			public static void Postfix(RollResults rollResultData, ClientGuid sender)
			{
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: 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_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				if (diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)"Custom Dice Pack Plug-In: Display Result: Executing Postfix");
				}
				string text = "";
				Enumerator<RollResultsGroup> enumerator = rollResultData.ResultsGroups.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						RollResultsGroup current = enumerator.Current;
						string text2 = ((current.Name == null) ? "(None)" : current.Name);
						if (text2.Contains("<size=0>"))
						{
							text = text2.Substring(current.Name.IndexOf("<size=0>") + "<size=0>".Length);
							break;
						}
					}
				}
				finally
				{
					((IDisposable)enumerator).Dispose();
				}
				if (diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Display Result: Customization = '" + text + "'"));
				}
				if (!text.StartsWith("=") && text != "")
				{
					CustomizeDisplay(text);
				}
			}
		}
	}

	private class SimpleDiceResult
	{
		public string customization { get; set; } = "";


		public int count { get; set; } = 0;


		public int icon { get; set; } = 0;

	}

	public static class Utility
	{
		public static bool isBoardLoaded()
		{
			return SimpleSingletonBehaviour<CameraController>.HasInstance && SingletonStateMBehaviour<BoardSessionManager, State<BoardSessionManager>>.HasInstance && !BoardSessionManager.IsLoading;
		}

		public static bool StrictKeyCheck(KeyboardShortcut check)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			if (!((KeyboardShortcut)(ref check)).IsUp())
			{
				return false;
			}
			KeyCode[] array = new KeyCode[6];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			KeyCode[] array2 = (KeyCode[])(object)array;
			foreach (KeyCode val in array2)
			{
				if (Input.GetKey(val) != ((KeyboardShortcut)(ref check)).Modifiers.Contains(val))
				{
					return false;
				}
			}
			return true;
		}

		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)("Custom Dice Pack Plug-In: Base Loader '" + ((Object)match.GetChild(0)).name + "' Found"));
						return ((Component)match.GetChild(0)).gameObject;
					}
					Debug.LogWarning((object)"Custom Dice Pack Plugin: 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)("Custom Dice Pack Plug-In: Asset Loader '" + ((Object)match.GetChild(0)).name + "' Found"));
						return ((Component)match.GetChild(0)).gameObject;
					}
					Debug.LogWarning((object)"Custom Dice Pack Plugin: 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 DiagnosticLevel
	{
		none,
		error,
		warning,
		info,
		debug,
		ultra
	}

	public enum ShowDiceResult
	{
		none,
		hidden,
		normal
	}

	public enum ShowDiceResultStyle
	{
		text,
		image
	}

	public class CustomDiceInfo
	{
		public string dicePack { get; set; } = "basedice";


		public string diceBase { get; set; } = "d4";


		public string diceCollection { get; set; } = "Lava";


		public string diceTexture { get; set; } = "D4_Lava.png";


		public int diceModifier { get; set; } = 1;


		public Dictionary<string, string> sides { get; set; } = new Dictionary<string, string>();


		public Dictionary<string, string> images { get; set; } = new Dictionary<string, string>();


		public Dictionary<string, Texture2D> textures { get; set; } = new Dictionary<string, Texture2D>();

	}

	private static Texture2D baseTexture = Image.LoadTexture("org.lordashes.plugins.customdicepack.baseIconTexture.png", (CacheType)999);

	private Dictionary<string, SimpleDiceResult> rollResults = new Dictionary<string, SimpleDiceResult>();

	private static GuiMenu customDiceTrayMenu = null;

	private static string customDiceTrayMenuNode = "";

	public const string Name = "Custom Dice Pack Plug-In";

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

	public const string Version = "3.0.0.0";

	private static BaseUnityPlugin _self;

	private static object padlock = new object();

	public static string activeCustomization = "";

	public static uint expecting = 0u;

	public static bool cooldownActive = false;

	public static float cooldownTime = 0.1f;

	private static Dictionary<string, Texture2D> defaultIcons = new Dictionary<string, Texture2D>();

	public static Dictionary<string, CustomDiceInfo> customDice = new Dictionary<string, CustomDiceInfo>();

	private static ConfigEntry<DiagnosticLevel> diagnostics { get; set; }

	private static ConfigEntry<MenuStyle> diceTrayStyle { get; set; }

	public static ConfigEntry<ShowDiceResult> showDiceRolls { get; set; }

	public static ConfigEntry<ShowDiceResult> showDiceSummary { get; set; }

	public static ConfigEntry<ShowDiceResultStyle> showDiceRollsStyle { get; set; }

	public static ConfigEntry<float> checkInterval { get; set; }

	public static ConfigEntry<float> delayChatCustomization { get; set; }

	public static ConfigEntry<float> delayDisplayCustomization { get; set; }

	public static ConfigEntry<KeyboardShortcut> triggerOpenCustomDiceTray { get; set; }

	public static void CustomizeChat()
	{
		if (diagnostics.Value >= DiagnosticLevel.ultra)
		{
			Debug.Log((object)"Custom Dice Pack Plug-In: Customize Chat");
		}
		bool flag = true;
		GameObject[] array = (from g in Object.FindObjectsOfType<GameObject>()
			where ((Object)g).name.Contains("ChatSection(Clone)")
			select g).ToArray();
		foreach (GameObject val in array)
		{
			flag = true;
			if (diagnostics.Value >= DiagnosticLevel.ultra)
			{
				Debug.Log((object)("Custom Dice Pack Plug-In: Chat Customization: Found ChatSection(Clone) With " + val.transform.childCount + " Sections"));
			}
			foreach (Transform item in ExtensionMethods.Children(val.transform))
			{
				if (diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Process Chat Section With " + ((Component)item).gameObject.GetComponentsInChildren<TextMeshProUGUI>().Count() + " Text Parts"));
				}
				if (((Component)item).gameObject.GetComponentsInChildren<TextMeshProUGUI>().Count() <= 0)
				{
					continue;
				}
				List<VisualPart> list = new List<VisualPart>();
				Transform parent = ((Component)((Component)item).gameObject.GetComponentsInChildren<TextMeshProUGUI>().ElementAt(1)).gameObject.transform.parent;
				for (int j = 0; j < ExtensionMethods.Children(parent).Count(); j++)
				{
					if (((Object)parent.GetChild(j)).name.Contains("Header"))
					{
						list.Add(new VisualPart
						{
							type = "Header",
							reference = ((Component)parent.GetChild(j)).gameObject
						});
					}
					else if (((Object)parent.GetChild(j)).name.Contains("Rolled"))
					{
						list.Add(new VisualPart
						{
							type = "Header",
							reference = ((Component)parent.GetChild(j)).gameObject
						});
					}
					else if (((Object)parent.GetChild(j)).name.Contains("SingleDiceResult"))
					{
						list.Add(new VisualPart
						{
							type = "Result",
							reference = ((Component)parent.GetChild(j)).gameObject
						});
					}
					else if (((Object)parent.GetChild(j)).name.Contains("Operator"))
					{
						list.Add(new VisualPart
						{
							type = "Operator",
							reference = ((Component)parent.GetChild(j)).gameObject
						});
					}
					else if (((Object)parent.GetChild(j)).name.Contains("Total"))
					{
						list.Add(new VisualPart
						{
							type = "Total",
							reference = ((Component)parent.GetChild(j)).gameObject
						});
					}
				}
				bool flag2 = false;
				for (int num = list.Count() - 1; num >= 0; num--)
				{
					if (list[num].type == "Total")
					{
						if (!flag2)
						{
							flag2 = true;
						}
						else
						{
							list[num].type = "Mod";
							flag2 = false;
						}
					}
				}
				CustomizeChatSection(list);
			}
		}
		if (!flag)
		{
			Debug.Log((object)"Custom Dice Pack Plug-In: Chat Section Not Fouind");
		}
	}

	public static void CustomizeChatSection(List<VisualPart> parts)
	{
		string text = "";
		bool flag = false;
		bool flag2 = false;
		TextMeshProUGUI componentInChildren = parts.ElementAt(0).reference.GetComponentInChildren<TextMeshProUGUI>();
		if ((Object)(object)componentInChildren != (Object)null && ((TMP_Text)componentInChildren).text != null && ((TMP_Text)componentInChildren).text.Contains("<size=0>"))
		{
			text = ((TMP_Text)componentInChildren).text.Substring(((TMP_Text)componentInChildren).text.IndexOf("<size=0>") + "<size=0>".Length);
		}
		if (text.StartsWith("="))
		{
			flag = true;
			text = text.Substring(1);
		}
		int result = 0;
		try
		{
			if (text == "")
			{
				flag2 = true;
			}
			else if (customDice.ContainsKey(text) && customDice[text].sides.Count > 0 && int.TryParse(customDice[text].sides.ElementAt(0).Value, out result))
			{
				flag2 = true;
			}
		}
		catch
		{
		}
		if (diagnostics.Value >= DiagnosticLevel.ultra)
		{
			Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Customization=" + text + ", isSummary=" + flag + ", isNumeric=" + flag2 + " (Test with " + ((text != "" && customDice.ContainsKey(text)) ? customDice[text].sides.ElementAt(0).Value : "N/A") + ")"));
		}
		switch (((text != "") ? "C" : "-") + (flag ? "S" : "-") + (flag2 ? "N" : "-"))
		{
		case "CSN":
		case "CS-":
		case "-SN":
		case "-S-":
			CustomizeChatSectionCustomSummary(text, parts);
			break;
		case "C-N":
		case "--N":
			CustomizeChatSectionCustomNonSummaryNumeric(text, parts);
			break;
		case "C--":
		case "---":
			CustomizeChatSectionCustomNonSummaryNonNumeric(text, parts);
			break;
		}
	}

	private static void CustomizeChatSectionCustomSummary(string customization, List<VisualPart> parts)
	{
		if (diagnostics.Value >= DiagnosticLevel.ultra)
		{
			Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Customizing Summary Section (Customization = '" + customization + "')"));
		}
		string text = "";
		foreach (VisualPart part in parts)
		{
			TextMeshProUGUI componentInChildren = part.reference.GetComponentInChildren<TextMeshProUGUI>();
			switch (part.type)
			{
			case "Header":
				if (((TMP_Text)componentInChildren).text != null && ((TMP_Text)componentInChildren).text.Contains("\u00a0"))
				{
					Debug.Log((object)"Custom Dice Pack Plug-In: Customize Chat: Previously Completed. Skip.");
					return;
				}
				if (((TMP_Text)componentInChildren).text.StartsWith("Rolled "))
				{
					((TMP_Text)componentInChildren).text = ((TMP_Text)componentInChildren).text.Substring("Rolled ".Length);
				}
				if (((TMP_Text)componentInChildren).text.StartsWith("And "))
				{
					((TMP_Text)componentInChildren).text = ((TMP_Text)componentInChildren).text.Substring("And ".Length);
				}
				text = ((TMP_Text)componentInChildren).text;
				if (text.Contains("<size=0>"))
				{
					text = text.Substring(0, text.IndexOf("<size=0>"));
				}
				((TMP_Text)componentInChildren).text = "\u00a0";
				if (diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Header Element (Section Name = '" + text + "', Customization = '" + customization + "')"));
				}
				break;
			case "Result":
			{
				if (diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Result Element (Customization = '" + customization + "')"));
				}
				RawImage componentInChildren2 = part.reference.GetComponentInChildren<RawImage>();
				if ((Object)(object)componentInChildren2 != (Object)null && customDice.ContainsKey(customization) && customDice[customization].sides.ContainsKey(((TMP_Text)componentInChildren).text) && customDice[customization].textures.ContainsKey(customDice[customization].sides[((TMP_Text)componentInChildren).text]))
				{
					if (diagnostics.Value >= DiagnosticLevel.ultra)
					{
						Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Result Element: Using Side Based Icon '" + customDice[customization].sides[((TMP_Text)componentInChildren).text] + "' (Customization = '" + customization + "')"));
					}
					componentInChildren2.texture = (Texture)(object)customDice[customization].textures[customDice[customization].sides[((TMP_Text)componentInChildren).text]];
				}
				else if ((Object)(object)componentInChildren2 != (Object)null && customDice.ContainsKey(customization) && customDice[customization].textures.ContainsKey("base"))
				{
					if (diagnostics.Value >= DiagnosticLevel.ultra)
					{
						Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Result Element: Using Base Icon (Customization = '" + customization + "')"));
					}
					componentInChildren2.texture = (Texture)(object)customDice[customization].textures["base"];
				}
				else if ((Object)(object)componentInChildren2 != (Object)null)
				{
					if (diagnostics.Value >= DiagnosticLevel.ultra)
					{
						Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Result Element: Using Default Icon (Customization = '" + customization + "')"));
					}
					componentInChildren2.texture = (Texture)(object)baseTexture;
				}
				if (((TMP_Text)componentInChildren).text != null)
				{
					((TMP_Text)componentInChildren).text = "";
				}
				break;
			}
			case "Operator":
				if (diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)"Custom Dice Pack Plug-In: Customize Chat: Operator Element: Clear Text");
				}
				if (((TMP_Text)componentInChildren).text != null)
				{
					((TMP_Text)componentInChildren).text = "";
				}
				break;
			case "Mod":
				if (diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)"Custom Dice Pack Plug-In: Customize Chat: Operator Element: Keep Text");
				}
				break;
			case "Total":
				if (diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Operator Element: Change To '" + text + "'"));
				}
				if (((TMP_Text)componentInChildren).text != null)
				{
					((TMP_Text)componentInChildren).text = text;
				}
				break;
			}
		}
	}

	private static void CustomizeChatSectionCustomNonSummaryNumeric(string customization, List<VisualPart> parts)
	{
		if (diagnostics.Value >= DiagnosticLevel.ultra)
		{
			Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Customizing Numeric NonSummary Section (Customization = '" + customization + "')"));
		}
		string text = "";
		int num = 0;
		foreach (VisualPart part in parts)
		{
			TextMeshProUGUI componentInChildren = part.reference.GetComponentInChildren<TextMeshProUGUI>();
			switch (part.type)
			{
			case "Header":
				if (diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)"Custom Dice Pack Plug-In: Customize Chat: Header Element: No Action");
				}
				if (((TMP_Text)componentInChildren).text != null && ((TMP_Text)componentInChildren).text.Contains("\u00a0"))
				{
					Debug.Log((object)"Custom Dice Pack Plug-In: Customize Chat: Previously Completed. Skip.");
					return;
				}
				if (((TMP_Text)componentInChildren).text != null && ((TMP_Text)componentInChildren).text.Contains("<size=0>"))
				{
					((TMP_Text)componentInChildren).text = ((TMP_Text)componentInChildren).text.Substring(0, ((TMP_Text)componentInChildren).text.IndexOf("<size=0>")) + "\u00a0";
				}
				if (((TMP_Text)componentInChildren).text.StartsWith("Rolled "))
				{
					((TMP_Text)componentInChildren).text = ((TMP_Text)componentInChildren).text.Substring("Rolled ".Length);
				}
				break;
			case "Result":
			{
				if (diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Result Element (Customization = '" + customization + "')"));
				}
				RawImage componentInChildren2 = part.reference.GetComponentInChildren<RawImage>();
				if ((Object)(object)componentInChildren2 != (Object)null && customDice.ContainsKey(customization) && customDice[customization].sides.ContainsKey(((TMP_Text)componentInChildren).text) && customDice[customization].textures.ContainsKey(customDice[customization].sides[((TMP_Text)componentInChildren).text]))
				{
					if (diagnostics.Value >= DiagnosticLevel.ultra)
					{
						Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Result Element: Using Side Based Icon '" + customDice[customization].sides[((TMP_Text)componentInChildren).text] + "' (Customization = '" + customization + "')"));
					}
					componentInChildren2.texture = (Texture)(object)customDice[customization].textures[customDice[customization].sides[((TMP_Text)componentInChildren).text]];
				}
				else if ((Object)(object)componentInChildren2 != (Object)null && customDice.ContainsKey(customization) && customDice[customization].textures.ContainsKey("base"))
				{
					if (diagnostics.Value >= DiagnosticLevel.ultra)
					{
						Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Result Element: Using Base Icon (Customization = '" + customization + "')"));
					}
					componentInChildren2.texture = (Texture)(object)customDice[customization].textures["base"];
				}
				else if ((Object)(object)componentInChildren2 != (Object)null && diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Result Element: Keeping Core Die Icon (Customization = '" + customization + "')"));
				}
				if (customDice.ContainsKey(customization) && customDice[customization].sides.ContainsKey(((TMP_Text)componentInChildren).text))
				{
					((TMP_Text)componentInChildren).text = customDice[customization].sides[((TMP_Text)componentInChildren).text];
				}
				int result = 0;
				int.TryParse(((TMP_Text)componentInChildren).text, out result);
				num += result;
				if (diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Result Element: Modifying Total By " + result + " To " + num + " (Customization = '" + customization + "')"));
				}
				break;
			}
			case "Operator":
				if (diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Operator Element: Clear Text (Customization = '" + customization + "')"));
				}
				if (((TMP_Text)componentInChildren).text != null)
				{
					text = ((TMP_Text)componentInChildren).text;
				}
				break;
			case "Mod":
			{
				int result2 = 0;
				int.TryParse(((TMP_Text)componentInChildren).text, out result2);
				if (text == "-")
				{
					result2 *= -1;
				}
				num += result2;
				if (diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Result Element: Modifying Total By Mod " + result2 + " To " + num + " (Customization = '" + customization + "')"));
				}
				break;
			}
			case "Total":
				if (diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Total Element: Setting Total To " + num + " (Customization = '" + customization + "')"));
				}
				if (((TMP_Text)componentInChildren).text != null)
				{
					((TMP_Text)componentInChildren).text = num.ToString();
				}
				break;
			}
		}
	}

	private static void CustomizeChatSectionCustomNonSummaryNonNumeric(string customization, List<VisualPart> parts)
	{
		if (diagnostics.Value >= DiagnosticLevel.ultra)
		{
			Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Customizing NonNumeric NonSummary Section (Customization = '" + customization + "')"));
		}
		foreach (VisualPart part in parts)
		{
			TextMeshProUGUI componentInChildren = part.reference.GetComponentInChildren<TextMeshProUGUI>();
			switch (part.type)
			{
			case "Header":
				if (diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)"Custom Dice Pack Plug-In: Customize Chat: Header Element: No Action");
				}
				if (((TMP_Text)componentInChildren).text != null && ((TMP_Text)componentInChildren).text.Contains("\u00a0"))
				{
					Debug.Log((object)"Custom Dice Pack Plug-In: Customize Chat: Previously Completed. Skip.");
					return;
				}
				if (((TMP_Text)componentInChildren).text != null && ((TMP_Text)componentInChildren).text.Contains("<size=0>"))
				{
					((TMP_Text)componentInChildren).text = ((TMP_Text)componentInChildren).text.Substring(0, ((TMP_Text)componentInChildren).text.IndexOf("<size=0>")) + "\u00a0";
				}
				break;
			case "Result":
			{
				if (diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Result Element (Customization = '" + customization + "')"));
				}
				RawImage componentInChildren2 = part.reference.GetComponentInChildren<RawImage>();
				if ((Object)(object)componentInChildren2 != (Object)null && customDice.ContainsKey(customization) && customDice[customization].sides.ContainsKey(((TMP_Text)componentInChildren).text) && customDice[customization].textures.ContainsKey(customDice[customization].sides[((TMP_Text)componentInChildren).text]))
				{
					if (diagnostics.Value >= DiagnosticLevel.ultra)
					{
						Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Result Element: Using Side Based Icon '" + customDice[customization].sides[((TMP_Text)componentInChildren).text] + "' (Customization = '" + customization + "')"));
					}
					componentInChildren2.texture = (Texture)(object)customDice[customization].textures[customDice[customization].sides[((TMP_Text)componentInChildren).text]];
				}
				else if ((Object)(object)componentInChildren2 != (Object)null && customDice.ContainsKey(customization) && customDice[customization].textures.ContainsKey("base"))
				{
					if (diagnostics.Value >= DiagnosticLevel.ultra)
					{
						Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Result Element: Using Base Icon (Customization = '" + customization + "')"));
					}
					componentInChildren2.texture = (Texture)(object)customDice[customization].textures["base"];
				}
				else if ((Object)(object)componentInChildren2 != (Object)null && diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Result Element: Keeping Core Die Icon (Customization = '" + customization + "')"));
				}
				break;
			}
			case "Operator":
				if (diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Operator Element: Clear Text (Customization = '" + customization + "')"));
				}
				if (((TMP_Text)componentInChildren).text != null)
				{
					((TMP_Text)componentInChildren).text = "";
				}
				break;
			case "Mod":
				if (diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Mod Element: Clear Text (Customization = '" + customization + "')"));
				}
				if (((TMP_Text)componentInChildren).text != null)
				{
					((TMP_Text)componentInChildren).text = "";
				}
				break;
			case "Total":
				if (diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Customize Chat: Total Element: Clear Text (Customization = '" + customization + "')"));
				}
				if (((TMP_Text)componentInChildren).text != null)
				{
					((TMP_Text)componentInChildren).text = "";
				}
				break;
			}
		}
	}

	public static void CustomizeDisplay(string customization)
	{
		if (diagnostics.Value >= DiagnosticLevel.ultra)
		{
			Debug.Log((object)("Custom Dice Pack Plug-In: Customize Display (Customization='" + customization + "')"));
		}
		if (customization == "" || !customDice.ContainsKey(customization))
		{
			return;
		}
		try
		{
			Transform val = null;
			bool flag = false;
			foreach (Transform item in ExtensionMethods.Children((from g in Object.FindObjectsOfType<GameObject>()
				where ((Object)g).name == "Roll"
				select g).ElementAt(0).transform))
			{
				if (diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Customize Display: Found '" + ((Object)item).name + "' (Active: " + ((Component)item).gameObject.activeSelf + ")"));
				}
				if (((Component)item).gameObject.activeSelf)
				{
					val = item;
				}
				if (((Component)item).gameObject.activeSelf && ((Object)item).name.Contains("Multi"))
				{
					flag = true;
				}
			}
			if (flag)
			{
				if ((from g in Object.FindObjectsOfType<GameObject>()
					where ((Object)g).name == "Root"
					select g).Count() > 0)
				{
					if (diagnostics.Value >= DiagnosticLevel.ultra)
					{
						Debug.Log((object)"Custom Dice Pack Plug-In: Customize Display: Setting Multi Parent Via Root");
					}
					val = (from g in Object.FindObjectsOfType<GameObject>()
						where ((Object)g).name == "Root"
						select g).ElementAt(0).transform;
				}
				else
				{
					if (diagnostics.Value >= DiagnosticLevel.ultra)
					{
						Debug.Log((object)"Custom Dice Pack Plug-In: Customize Display: Setting Multi Parent Via Parent Of Text");
					}
					val = ((Component)((Component)val).GetComponentInChildren<TextMeshProUGUI>()).gameObject.transform.parent;
				}
			}
			bool flag2 = true;
			if ((Object)(object)val != (Object)null && customDice[customization].sides.Count() > 0)
			{
				int result = 0;
				if (!int.TryParse(customDice[customization].sides.ElementAt(0).Value, out result))
				{
					flag2 = false;
				}
			}
			int num = 0;
			string text = "";
			foreach (Transform item2 in ExtensionMethods.Children(val))
			{
				if (diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Customize Display: Found '" + ((Object)item2).name + "' (Customization='" + customization + "', IsNumeric='" + flag2 + "', IsMulti='" + flag + "')"));
				}
				TextMeshProUGUI componentInChildren = ((Component)item2).GetComponentInChildren<TextMeshProUGUI>();
				if (((Object)item2).name.Contains("SingleDiceResult"))
				{
					if (flag2)
					{
						if (diagnostics.Value >= DiagnosticLevel.ultra)
						{
							Debug.Log((object)"Custom Dice Pack Plug-In: Customize Display: Result: Numeric Result Found.");
						}
						if (customDice[customization].sides.ContainsKey(((TMP_Text)componentInChildren).text))
						{
							((TMP_Text)componentInChildren).text = customDice[customization].sides[((TMP_Text)componentInChildren).text];
							if (diagnostics.Value >= DiagnosticLevel.ultra)
							{
								Debug.Log((object)("Custom Dice Pack Plug-In: Customize Display: Result: Updating Numeric Value To " + ((TMP_Text)componentInChildren).text));
							}
						}
						num += int.Parse(((TMP_Text)componentInChildren).text);
						if (diagnostics.Value >= DiagnosticLevel.ultra)
						{
							Debug.Log((object)("Custom Dice Pack Plug-In: Customize Display: Result: Running Total " + num));
						}
						continue;
					}
					if (diagnostics.Value >= DiagnosticLevel.ultra)
					{
						Debug.Log((object)"Custom Dice Pack Plug-In: Customize Display: Result: Non-Numeric Result Found.");
					}
					RawImage componentInChildren2 = ((Component)item2).GetComponentInChildren<RawImage>();
					if (customDice[customization].sides.ContainsKey(((TMP_Text)componentInChildren).text) && customDice[customization].textures.ContainsKey(customDice[customization].sides[((TMP_Text)componentInChildren).text]))
					{
						if (diagnostics.Value >= DiagnosticLevel.ultra)
						{
							Debug.Log((object)("Custom Dice Pack Plug-In: Customize Display: Result: Using Side Based Image Of " + customDice[customization].sides[((TMP_Text)componentInChildren).text]));
						}
						componentInChildren2.texture = (Texture)(object)customDice[customization].textures[customDice[customization].sides[((TMP_Text)componentInChildren).text]];
					}
					else if (customDice[customization].textures.ContainsKey("base"))
					{
						if (diagnostics.Value >= DiagnosticLevel.ultra)
						{
							Debug.Log((object)"Custom Dice Pack Plug-In: Customize Display: Result: Using Based Image");
						}
						componentInChildren2.texture = (Texture)(object)customDice[customization].textures["base"];
					}
					else
					{
						if (diagnostics.Value >= DiagnosticLevel.ultra)
						{
							Debug.Log((object)"Custom Dice Pack Plug-In: Customize Display: Result: Using Default Image");
						}
						componentInChildren2.texture = (Texture)(object)baseTexture;
					}
				}
				else if (((Object)item2).name.Contains("Operator"))
				{
					if (flag2)
					{
						if (diagnostics.Value >= DiagnosticLevel.ultra)
						{
							Debug.Log((object)"Custom Dice Pack Plug-In: Customize Display: Operator: Numeric Result Found.");
						}
						if (((TMP_Text)componentInChildren).text == "+" || ((TMP_Text)componentInChildren).text == "+" || ((TMP_Text)componentInChildren).text == "=")
						{
							text = ((TMP_Text)componentInChildren).text;
							if (diagnostics.Value >= DiagnosticLevel.ultra)
							{
								Debug.Log((object)("Custom Dice Pack Plug-In: Customize Display: Operator: Storing Operation " + text));
							}
							continue;
						}
						if (diagnostics.Value >= DiagnosticLevel.ultra)
						{
							Debug.Log((object)("Custom Dice Pack Plug-In: Customize Display: Operator: Processing " + text + ((TMP_Text)componentInChildren).text));
						}
						if (text == "+")
						{
							num += int.Parse(((TMP_Text)componentInChildren).text);
						}
						if (text == "-")
						{
							num -= int.Parse(((TMP_Text)componentInChildren).text);
						}
					}
					else
					{
						if (diagnostics.Value >= DiagnosticLevel.ultra)
						{
							Debug.Log((object)"Custom Dice Pack Plug-In: Customize Display: Operator: Non-Numeric Result Found.");
						}
						((TMP_Text)componentInChildren).text = "";
					}
				}
				else
				{
					if (!((Object)item2).name.Contains("Total"))
					{
						continue;
					}
					if (flag2)
					{
						if (diagnostics.Value >= DiagnosticLevel.ultra)
						{
							Debug.Log((object)"Custom Dice Pack Plug-In: Customize Display: Total: Numeric Result Found.");
						}
						((TMP_Text)componentInChildren).text = num.ToString();
					}
					else
					{
						if (diagnostics.Value >= DiagnosticLevel.ultra)
						{
							Debug.Log((object)"Custom Dice Pack Plug-In: Customize Display: Total: Non-Numeric Result Found.");
						}
						((TMP_Text)componentInChildren).text = "";
					}
				}
			}
		}
		catch (Exception ex)
		{
			if (diagnostics.Value >= DiagnosticLevel.error)
			{
				Debug.LogWarning((object)("Custom Dice Pack Plug-In: Unable To Get Display Result Reference. (" + ex.Message + ")"));
			}
		}
	}

	private void rollResultsHandler(string evt)
	{
		if (diagnostics.Value >= DiagnosticLevel.debug)
		{
			Debug.Log((object)("Custom Dice Pack Plug-In: Event: " + evt));
		}
		evt = evt.Substring(evt.IndexOf("\"payload\":") + "\"payload\":".Length);
		string text = "";
		string text2 = "+";
		string text3 = "0";
		string text4 = "";
		if (evt.IndexOf("\"name\":\"") > -1)
		{
			text = evt.Substring(evt.IndexOf("\"name\":\"") + "\"name\":\"".Length).Trim();
			text = text.Substring(0, text.IndexOf("\""));
			if (text.IndexOf("<size=0>") > -1)
			{
				text4 = text.Substring(text.IndexOf("<size=0>") + "<size=0>".Length);
				text = text.Substring(0, text.IndexOf("<size=0>"));
			}
			else
			{
				text4 = "";
			}
		}
		if (evt.IndexOf("\"operator\":\"") > -1)
		{
			text2 = evt.Substring(evt.IndexOf("\"operator\":\"") + "\"operator\":\"".Length).Trim();
			text2 = text2.Substring(0, text2.IndexOf("\""));
			if (evt.IndexOf("\"value\":") > -1)
			{
				text3 = evt.Substring(evt.IndexOf("\"value\":") + "\"value\":".Length).Trim();
				text3 = text2 + text3.Substring(0, text3.IndexOf("}"));
			}
			else
			{
				text3 = "+0";
			}
		}
		string text5 = evt.Substring(evt.IndexOf("\"results\":") + "\"results\":".Length);
		text5 = text5.Substring(0, text5.IndexOf("}")).Replace("[", "").Replace("]", "")
			.Trim();
		if (diagnostics.Value >= DiagnosticLevel.ultra)
		{
			Debug.Log((object)("Custom Dice Pack Plug-In: Name = '" + text + "'"));
		}
		if (diagnostics.Value >= DiagnosticLevel.ultra)
		{
			Debug.Log((object)("Custom Dice Pack Plug-In: Mod = '" + text3 + "'"));
		}
		if (diagnostics.Value >= DiagnosticLevel.ultra)
		{
			Debug.Log((object)("Custom Dice Pack Plug-In: Customization = '" + text4 + "'"));
		}
		if (text.Trim() == "")
		{
			text = "Roll";
		}
		if (text3.Trim() == "+" || text3.Trim() == "-")
		{
			text3 = "+0";
		}
		int num = 0;
		string[] array = text5.Split(new char[1] { ',' });
		foreach (string text6 in array)
		{
			num++;
			if (text4 != "")
			{
				if (diagnostics.Value >= DiagnosticLevel.debug)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Processing Custom Die Property List '" + customDice[text4].sides[text6] + "'"));
				}
				string[] array2 = customDice[text4].sides[text6].Split(new char[1] { ',' });
				foreach (string text7 in array2)
				{
					int result = 1;
					if (diagnostics.Value >= DiagnosticLevel.ultra)
					{
						Debug.Log((object)("Custom Dice Pack Plug-In: Checking If '" + text7 + "' Is Numeric"));
					}
					if (int.TryParse(text7, out result))
					{
						if (!rollResults.ContainsKey(text))
						{
							if (diagnostics.Value >= DiagnosticLevel.ultra)
							{
								Debug.Log((object)("Custom Dice Pack Plug-In: Custom Die Side Is Numeric. Setting '" + text + "' To " + result));
							}
							rollResults.Add(text, new SimpleDiceResult
							{
								count = result,
								icon = 0,
								customization = text4
							});
						}
						else
						{
							if (diagnostics.Value >= DiagnosticLevel.ultra)
							{
								Debug.Log((object)("Custom Dice Pack Plug-In: Custom Die Side Is Numeric. Increasing '" + text + "' By " + result));
							}
							rollResults[text].count += result;
							rollResults[text].customization = text4;
						}
						if (num == 1)
						{
							if (diagnostics.Value >= DiagnosticLevel.ultra)
							{
								Debug.Log((object)("Custom Dice Pack Plug-In: Custom Die Side Is Numeric. Adding Modifier " + text3));
							}
							rollResults[text].count += int.Parse(text3);
						}
						continue;
					}
					if (!rollResults.ContainsKey(text7))
					{
						if (diagnostics.Value >= DiagnosticLevel.ultra)
						{
							Debug.Log((object)("Custom Dice Pack Plug-In: Custom Die Side Is Not Numeric. Setting '" + text7 + "' To " + (1 + int.Parse(text3))));
						}
						rollResults.Add(text7, new SimpleDiceResult
						{
							count = 1 + int.Parse(text3),
							customization = text4
						});
						foreach (KeyValuePair<string, string> side in customDice[text4].sides)
						{
							if (side.Value == text7)
							{
								rollResults[text7].icon = int.Parse(side.Key);
								break;
							}
						}
						continue;
					}
					if (diagnostics.Value >= DiagnosticLevel.ultra)
					{
						Debug.Log((object)("Custom Dice Pack Plug-In: Custom Die Side Is Not Numeric. Increasing '" + text7 + "' By " + (1 + int.Parse(text3))));
					}
					rollResults[text7].count += 1 + int.Parse(text3);
					rollResults[text7].customization = text4;
					if (rollResults[text7].icon != 0)
					{
						continue;
					}
					foreach (KeyValuePair<string, string> side2 in customDice[text4].sides)
					{
						if (side2.Value == text7)
						{
							rollResults[text7].icon = int.Parse(side2.Key);
							break;
						}
					}
				}
				continue;
			}
			if (diagnostics.Value >= DiagnosticLevel.ultra)
			{
				Debug.Log((object)("Custom Dice Pack Plug-In: Processing Regular Die Contribution To '" + text + "'"));
			}
			if (diagnostics.Value >= DiagnosticLevel.ultra)
			{
				Debug.Log((object)("Custom Dice Pack Plug-In: Regular Die Side Is Numeric. Increasing '" + text + "' By " + int.Parse(text6)));
			}
			if (!rollResults.ContainsKey(text))
			{
				rollResults.Add(text, new SimpleDiceResult
				{
					count = int.Parse(text6),
					icon = 0,
					customization = text4
				});
			}
			else
			{
				rollResults[text].count += int.Parse(text6);
			}
			if (num == 1)
			{
				if (diagnostics.Value >= DiagnosticLevel.ultra)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Regular Die Side Is Numeric. Adding Modifier " + text3));
				}
				rollResults[text].count += int.Parse(text3);
			}
		}
		if (diagnostics.Value >= DiagnosticLevel.ultra)
		{
			Debug.Log((object)("Custom Dice Pack Plug-In: Results Stack: " + JsonConvert.SerializeObject((object)rollResults)));
		}
		if (!cooldownActive)
		{
			((MonoBehaviour)_self).StartCoroutine(CoolDown(cooldownTime));
		}
	}

	private IEnumerator CoolDown(float cooldownTime)
	{
		cooldownActive = true;
		yield return (object)new WaitForSeconds(cooldownTime);
		string js3 = "TS.extra.sendSimpleDiceResult([";
		foreach (KeyValuePair<string, SimpleDiceResult> entry in rollResults)
		{
			js3 = js3 + "{ 'name': '" + entry.Key + "<size=0>=" + entry.Value.customization + "', 'roll': '1D20+" + entry.Value.count + "', 'results': [" + entry.Value.icon + "] },";
		}
		js3 = js3.Substring(0, js3.Length - 1);
		js3 += "],false,false);";
		cooldownActive = false;
		if (diagnostics.Value >= DiagnosticLevel.ultra)
		{
			Debug.Log((object)("Custom Dice Pack Plug-In: Generating Summary Command: " + js3));
		}
		SymbioteApiPlugin.Symbiote_API(js3);
		rollResults.Clear();
	}

	private void OnGUI()
	{
		if (customDiceTrayMenu != null)
		{
			customDiceTrayMenuNode = customDiceTrayMenu.GetCurrentNode().name;
			customDiceTrayMenu.Draw();
		}
	}

	private static void OpenCustomDiceTray()
	{
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Expected O, but got Unknown
		//IL_032e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0333: Unknown result type (might be due to invalid IL or missing references)
		//IL_0341: Unknown result type (might be due to invalid IL or missing references)
		//IL_0342: Unknown result type (might be due to invalid IL or missing references)
		//IL_034d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: 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_0492: Unknown result type (might be due to invalid IL or missing references)
		//IL_049c: Expected O, but got Unknown
		//IL_039d: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d3: Expected O, but got Unknown
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Expected O, but got Unknown
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Expected O, but got Unknown
		//IL_0200: Unknown result type (might be due to invalid IL or missing references)
		//IL_0236: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0247: Unknown result type (might be due to invalid IL or missing references)
		//IL_025d: 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_0276: Expected O, but got Unknown
		//IL_02a2: 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)
		//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ee: Expected O, but got Unknown
		if (diagnostics.Value >= DiagnosticLevel.debug)
		{
			Debug.Log((object)"Custom Dice Pack Plug-In: Building Custom Dice Tray");
		}
		Dictionary<string, MenuNode> dictionary = new Dictionary<string, MenuNode>();
		if (diagnostics.Value >= DiagnosticLevel.debug)
		{
			Debug.Log((object)"Custom Dice Pack Plug-In: Building Root Node");
		}
		dictionary.Add("Root", null);
		MenuNode val = new MenuNode();
		foreach (KeyValuePair<string, CustomDiceInfo> customDie in customDice)
		{
			string text = ((customDie.Value.diceCollection != "") ? customDie.Value.diceCollection : "Default");
			if (!dictionary.ContainsKey(text))
			{
				if (diagnostics.Value >= DiagnosticLevel.debug)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Adding Collection Link '" + text + "'"));
				}
				val.AddLink(new MenuLink
				{
					title = text,
					color = Color.white,
					icon = (customDie.Value.images.ContainsKey("collection") ? Image.LoadTexture(customDie.Value.images["collection"], (CacheType)999) : Image.LoadTexture("CustomDiceCollection.png", (CacheType)999)),
					gmOnly = false,
					link = text
				});
				if (diagnostics.Value >= DiagnosticLevel.debug)
				{
					Debug.Log((object)"Custom Dice Pack Plug-In: Setting Menu Style");
				}
				val.style = diceTrayStyle.Value;
				if (diagnostics.Value >= DiagnosticLevel.debug)
				{
					Debug.Log((object)"Custom Dice Pack Plug-In: Creating New Menu Node");
				}
				dictionary.Add(text, new MenuNode());
				if (diagnostics.Value >= DiagnosticLevel.debug)
				{
					Debug.Log((object)"Custom Dice Pack Plug-In: Setting Menu Node Tray Style");
				}
				dictionary[text].style = diceTrayStyle.Value;
				if (diagnostics.Value >= DiagnosticLevel.debug)
				{
					Debug.Log((object)"Custom Dice Pack Plug-In: Creating Menu Selection For Cancel");
				}
				dictionary[text].AddSelection(new MenuSelection
				{
					title = "Cancel",
					icon = Image.LoadTexture("CustomDiceCancel.png", (CacheType)999),
					gmOnly = false,
					selection = "Cancel"
				});
				if (diagnostics.Value >= DiagnosticLevel.debug)
				{
					Debug.Log((object)"Custom Dice Pack Plug-In: Creating Menu Selection For Back");
				}
				dictionary[text].AddLink(new MenuLink
				{
					title = "Back",
					color = Color.white,
					icon = Image.LoadTexture("CustomDiceBack.png", (CacheType)999),
					gmOnly = false,
					link = "Root"
				});
			}
			if (diagnostics.Value >= DiagnosticLevel.debug)
			{
				Debug.Log((object)("Custom Dice Pack Plug-In: Adding Dice Collection '" + text + "' Die " + customDie.Key));
			}
			dictionary[text].AddSelection(new MenuSelection
			{
				title = customDie.Key,
				color = Color.white,
				icon = (customDie.Value.images.ContainsKey("icon") ? Image.LoadTexture(customDie.Value.images["icon"], (CacheType)999) : Image.LoadTexture("CustomDie.png", (CacheType)999)),
				gmOnly = false,
				selection = "1" + customDie.Value.diceBase + "#" + customDie.Key
			});
		}
		if (diagnostics.Value >= DiagnosticLevel.debug)
		{
			Debug.Log((object)"Custom Dice Pack Plug-In: Setting Root Node");
		}
		dictionary["Root"] = val;
		if (diagnostics.Value >= DiagnosticLevel.debug)
		{
			Debug.Log((object)"Custom Dice Pack Plug-In: Creating Root Node Cancel");
		}
		dictionary["Root"].AddSelection("Cancel", "Cancel", Image.LoadTexture("CustomDiceCancel.png", (CacheType)999));
		if (diagnostics.Value >= DiagnosticLevel.debug)
		{
			Debug.Log((object)"Custom Dice Pack Plug-In: Creating GUI Menu");
		}
		customDiceTrayMenu = new GuiMenu();
		if (diagnostics.Value >= DiagnosticLevel.debug)
		{
			Debug.Log((object)"Custom Dice Pack Plug-In: Addding Menu Nodes To GUI Menu");
		}
		foreach (KeyValuePair<string, MenuNode> item in dictionary)
		{
			IMenuItem[] items = item.Value.GetItems();
			foreach (IMenuItem val2 in items)
			{
				if (diagnostics.Value >= DiagnosticLevel.debug)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Node '" + item.Key + "' has '" + val2.title));
				}
				if (diagnostics.Value >= DiagnosticLevel.debug)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Node '" + item.Key + "' is '" + JsonConvert.SerializeObject((object)item.Value)));
				}
			}
			item.Value.name = item.Key;
			customDiceTrayMenu.AddNode(item.Value);
		}
		if (diagnostics.Value >= DiagnosticLevel.debug)
		{
			Debug.Log((object)"Custom Dice Pack Plug-In: Opening Custom Dice Tray");
		}
		if (diagnostics.Value >= DiagnosticLevel.debug)
		{
			Debug.Log((object)"Custom Dice Pack Plug-In: Adding Menu Callbacks");
		}
		customDiceTrayMenu.Open("Root", (Action<string>)delegate(string selection)
		{
			if (selection == "Cancel")
			{
				if (diagnostics.Value >= DiagnosticLevel.debug)
				{
					Debug.Log((object)"Custom Dice Pack Plug-In: Closing Custom Dice Tray");
				}
				customDiceTrayMenu.Close();
				customDiceTrayMenu = null;
			}
			else
			{
				if (diagnostics.Value >= DiagnosticLevel.debug)
				{
					Debug.Log((object)("Custom Dice Pack Plug-In: Spawning Selection " + selection));
				}
				if (Input.GetKey((KeyCode)304))
				{
					SystemMessage.AskForTextInput("Custom Dice", "How Many Dice?", "OK", (Action<string>)delegate(string s)
					{
						Process process2 = new Process();
						process2.StartInfo = new ProcessStartInfo
						{
							FileName = "talespire://dice/" + s + selection.Substring(1),
							UseShellExecute = true,
							CreateNoWindow = true
						};
						process2.Start();
					}, (Action)null, "Cancel", (Action)null, "001");
				}
				else
				{
					Process process = new Process();
					process.StartInfo = new ProcessStartInfo
					{
						FileName = "talespire://dice/" + selection,
						UseShellExecute = true,
						CreateNoWindow = true
					};
					process.Start();
				}
				customDiceTrayMenu.Open(customDiceTrayMenuNode);
			}
		});
	}

	private void Awake()
	{
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0359: Unknown result type (might be due to invalid IL or missing references)
		//IL_035f: Expected O, but got Unknown
		_self = (BaseUnityPlugin)(object)this;
		diagnostics = ((BaseUnityPlugin)this).Config.Bind<DiagnosticLevel>("Settings", "Include Diagnostics In Logs", DiagnosticLevel.info, (ConfigDescription)null);
		Debug.Log((object)("Custom Dice Pack Plug-In: " + ((object)this).GetType().AssemblyQualifiedName + " Active. (Diagnostics=" + diagnostics.Value.ToString() + ")"));
		triggerOpenCustomDiceTray = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Open Custom Dice Menu", new KeyboardShortcut((KeyCode)292, Array.Empty<KeyCode>()), (ConfigDescription)null);
		diceTrayStyle = ((BaseUnityPlugin)this).Config.Bind<MenuStyle>("Settings", "Dice Tray Style", (MenuStyle)1, (ConfigDescription)null);
		showDiceRolls = ((BaseUnityPlugin)this).Config.Bind<ShowDiceResult>("Settings", "Show Dice Rolls", ShowDiceResult.hidden, (ConfigDescription)null);
		showDiceSummary = ((BaseUnityPlugin)this).Config.Bind<ShowDiceResult>("Settings", "Show Dice Summary", ShowDiceResult.normal, (ConfigDescription)null);
		showDiceRollsStyle = ((BaseUnityPlugin)this).Config.Bind<ShowDiceResultStyle>("Settings", "Show Dice Rolls Style", ShowDiceResultStyle.text, (ConfigDescription)null);
		checkInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Interval For Detecting Chat Changes", 3f, (ConfigDescription)null);
		delayChatCustomization = ((BaseUnityPlugin)this).Config.Bind<float>("Tweaks", "Delay For Chat Customiztion", 0.25f, (ConfigDescription)null);
		delayDisplayCustomization = ((BaseUnityPlugin)this).Config.Bind<float>("Tweaks", "Delay For Display Customization", 0.25f, (ConfigDescription)null);
		foreach (string item in from s in File.Find("org.lordashes.plugins.customdicepack", (CacheType)999)
			where s.Contains("org.lordashes.plugins.customdicepack/")
			select s)
		{
			if (diagnostics.Value >= DiagnosticLevel.debug)
			{
				Debug.Log((object)("Custom Dice Pack Plug-In: Loading Default Icon '" + Path.GetFileNameWithoutExtension(item) + "' From '" + item + "'"));
			}
			defaultIcons.Add(Path.GetFileNameWithoutExtension(item), Image.LoadTexture(item, (CacheType)999));
		}
		customDice = JsonConvert.DeserializeObject<Dictionary<string, CustomDiceInfo>>(File.ReadAllText("CustomDicePacks.json", (CacheType)999));
		foreach (KeyValuePair<string, CustomDiceInfo> customDie in customDice)
		{
			foreach (KeyValuePair<string, string> image in customDie.Value.images)
			{
				if (!image.Key.StartsWith("tex"))
				{
					if (diagnostics.Value >= DiagnosticLevel.debug)
					{
						Debug.Log((object)("Custom Dice Pack Plug-In: Loading Custon Image Texture '" + image.Value.ToString() + "'"));
					}
					customDie.Value.textures.Add(image.Key, Image.LoadTexture(image.Value.ToString(), (CacheType)999));
				}
			}
		}
		Harmony val = new Harmony("org.lordashes.plugins.customdicepack");
		val.PatchAll();
		SymbioteApiPlugin.Initialized((Action)delegate
		{
			if (diagnostics.Value >= DiagnosticLevel.ultra)
			{
				Debug.Log((object)"Custom Dice Pack Plug-In: Symbiote API Initialized");
			}
			SymbioteApiPlugin.Subscribe(new List<string> { "rollResults" }, (Action<string>)rollResultsHandler);
		});
		if (Type.GetType("LordAshes.ProximityRollerPlugin, ProximityRollerPlugin") == null)
		{
			cooldownTime = 0.1f;
			if (diagnostics.Value >= DiagnosticLevel.info)
			{
				Debug.Log((object)("Custom Dice Pack Plug-In: Proximity Roller Plugin Not Detected. Setting cooldown to " + cooldownTime));
			}
		}
		else
		{
			cooldownTime = 1.25f;
			if (diagnostics.Value >= DiagnosticLevel.debug)
			{
				Debug.Log((object)("Custom Dice Pack Plug-In: Proximity Roller Plugin Detected. Setting cooldown to " + cooldownTime));
			}
			(from m in Type.GetType("LordAshes.ProximityRollerPlugin, ProximityRollerPlugin").GetRuntimeMethods()
				where m.Name == "Summarize"
				select m).ElementAt(0).Invoke(null, new object[1] { false });
		}
		((MonoBehaviour)_self).StartCoroutine(UpdateChatCustomization(checkInterval.Value));
		Utility.PostOnMainPage(((object)this).GetType());
	}

	private void Update()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKey((KeyCode)304))
		{
			return;
		}
		KeyboardShortcut value = triggerOpenCustomDiceTray.Value;
		if (((KeyboardShortcut)(ref value)).IsUp())
		{
			if (diagnostics.Value >= DiagnosticLevel.ultra)
			{
				Debug.Log((object)"Custom Dice Pack Plug-In: Opening Custom Dice Menu");
			}
			OpenCustomDiceTray();
		}
	}

	private IEnumerator UpdateChatCustomization(float checkInterval)
	{
		while (true)
		{
			yield return (object)new WaitForSeconds(checkInterval);
			if (Utility.isBoardLoaded())
			{
				CustomizeChat();
			}
		}
	}
}