Decompiled source of EmbeddedCharacterSheetPlugin v1.8.1

EmbeddedCharacterSheetPlugin.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Media;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using Bounce.Singletons;
using HarmonyLib;
using Newtonsoft.Json;
using RadialUI;
using TMPro;
using Unity.Mathematics;
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("EmbeddedCharacterSheetPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EmbeddedCharacterSheetPlugin")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("EmbeddedCharacterSheetPlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("1.8.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.8.1.0")]
namespace LordAshes;

[BepInPlugin("org.lordashes.plugins.embeddedcharactersheet", "Embedded Character Sheet Plugin", "1.8.1.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 EmbeddedCharacterSheetPlugin : BaseUnityPlugin
{
	public enum GuiElementType
	{
		legacy,
		button,
		layout
	}

	public class GuiLocation
	{
		public int x { get; set; } = 0;


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

	}

	public class GuiSize
	{
		public int w { get; set; } = 0;


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

	}

	public class GuiElement
	{
		[NonSerialized]
		public Texture2D _texture = null;

		[NonSerialized]
		public GUIStyle _style = new GUIStyle();

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


		public GuiElementType type { get; set; } = GuiElementType.button;


		public GuiLocation position { get; set; } = new GuiLocation();


		public GuiSize size { get; set; } = new GuiSize();


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


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


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


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


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


		public GuiElement()
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			_style.normal.textColor = defaultEntryTextColor.Value;
			_style.fontSize = defaultEntryTextSize.Value;
			_style.fontStyle = (FontStyle)0;
			_style.richText = false;
			_style.wordWrap = false;
		}
	}

	public class GuiLayout
	{
		public GuiLocation position = new GuiLocation
		{
			x = 10,
			y = 40
		};

		public GuiSize size = new GuiSize
		{
			w = Screen.width - 20,
			h = Screen.height - 20
		};

		public List<GuiElement> elements = new List<GuiElement>();

		public string background = "";

		[NonSerialized]
		public Texture2D _background = null;

		public GuiLayout Clone()
		{
			GuiLayout guiLayout = new GuiLayout();
			guiLayout.position = position;
			guiLayout.size = size;
			guiLayout.background = background;
			guiLayout._background = _background;
			foreach (GuiElement element in elements)
			{
				guiLayout.elements.Add(new GuiElement
				{
					id = element.id,
					type = element.type,
					position = element.position,
					size = element.size,
					style = element.style,
					name = element.name,
					content = element.content,
					target = element.target,
					roll = element.roll,
					_texture = element._texture,
					_style = element._style
				});
			}
			return guiLayout;
		}
	}

	public class CharacterData
	{
		[NonSerialized]
		public string _id = "";

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


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


		public string Formula(string roll)
		{
			return roll.Replace("{", "").Replace("}", "");
		}

		public string Evaluate(string roll)
		{
			if (logDiagnostics.Value)
			{
				Debug.Log((object)("Embedded Character Sheet Plugin: Evaluating Raw Roll '" + roll + "'"));
			}
			bool flag = true;
			int num = 0;
			while (flag)
			{
				num++;
				flag = false;
				foreach (KeyValuePair<string, string> stat in stats)
				{
					string text = roll;
					if (roll.Contains(stat.Key))
					{
						roll = roll.Replace(stat.Key, Evaluate(stat.Value));
						flag = true;
					}
				}
				if (logDiagnostics.Value)
				{
					Debug.Log((object)("Embedded Character Sheet Plugin: Evaluating Substituted Roll '" + roll + "'"));
				}
				if (num >= 10)
				{
					break;
				}
			}
			DataTable dataTable = new DataTable();
			string[] array = roll.Split(new char[1] { '/' });
			for (int i = 0; i < array.Length; i++)
			{
				if (logDiagnostics.Value)
				{
					Debug.Log((object)("Embedded Character Sheet Plugin: Computing '" + array[i].Replace("&", "/").Replace("÷", "/") + "'"));
				}
				object obj = null;
				try
				{
					obj = dataTable.Compute(array[i].Replace("&", "/").Replace("÷", "/"), "");
				}
				catch
				{
				}
				if (logDiagnostics.Value)
				{
					Debug.Log((object)("Embedded Character Sheet Plugin: Computation Result '" + Convert.ToString(obj) + "'"));
				}
				if (obj != null)
				{
					int result = 0;
					float result2 = 0f;
					if (int.TryParse(obj.ToString(), out result))
					{
						array[i] = result.ToString();
					}
					else if (float.TryParse(obj.ToString(), out result2))
					{
						array[i] = Math.Floor(result2).ToString();
					}
				}
			}
			roll = string.Join("/", array);
			if (logDiagnostics.Value)
			{
				Debug.Log((object)("Embedded Character Sheet Plugin: Roll Result '" + roll + "'"));
			}
			roll = roll.ColsolidateModifiers();
			if (logDiagnostics.Value)
			{
				Debug.Log((object)("Embedded Character Sheet Plugin: Roll Result After Consolidation Of Modifiers '" + roll + "'"));
			}
			return roll;
		}
	}

	[HarmonyPatch(typeof(UIDiceRollResult), "DisplayResult")]
	public static class PatchDisplayResult
	{
		public static bool Prefix(RollResults rollResultData, ClientGuid sender)
		{
			//IL_0010: 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)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < rollResultData.ResultsGroups.Length; i++)
			{
				if (rollResultData.ResultsGroups[i].Name != null && Convert.ToString(rollResultData.ResultsGroups[i]).Trim() != "")
				{
					Debug.Log((object)("Embedded Character Sheet Plugin: Roll Name '" + rollResultData.ResultsGroups[i].Name + "'"));
					if (rollResultData.ResultsGroups[i].Name.Contains("[") && rollResultData.ResultsGroups[i].Name.Contains("]"))
					{
						rollResultData.ResultsGroups[i] = new RollResultsGroup(rollResultData.ResultsGroups[i].Name.Substring(rollResultData.ResultsGroups[i].Name.IndexOf("]") + 1), rollResultData.ResultsGroups[i].Result);
					}
				}
			}
			return true;
		}
	}

	public static class Utility
	{
		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);
				}
			};
		}

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

		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 static string GetCreatureName(string name)
		{
			if (name.Contains("<"))
			{
				name = name.Substring(0, name.IndexOf("<"));
			}
			return name;
		}
	}

	public enum RollMethod
	{
		talespire_dice = 1,
		chat_roll
	}

	public const string Name = "Embedded Character Sheet Plugin";

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

	public const string Version = "1.8.1.0";

	public const string Author = "Lord Ashes";

	private bool characterSheetShowing = false;

	public static GuiLayout currentLayout = null;

	public static CharacterData currentData = null;

	public static Dictionary<string, GuiLayout> layouts = new Dictionary<string, GuiLayout>();

	public static Dictionary<string, CharacterData> data = new Dictionary<string, CharacterData>();

	public static Dictionary<string, Font> fonts = new Dictionary<string, Font>();

	public static string layoutTab = "";

	public static bool layoutSwitchInProgress = false;

	public static string selectedKey = "";

	public static string selectedValue = "";

	public static string selectedPrevious = "";

	public static float selectedTime = -1f;

	public static List<string> fastElementPatterns = new List<string>();

	private EmbeddedCharacterSheetPlugin _self = null;

	private ConfigEntry<RollMethod> rollMethod { get; set; }

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

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

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

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

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

	private ConfigEntry<bool> closeAfteRoll { get; set; }

	private ConfigEntry<bool> applyNameMod { get; set; }

	public static ConfigEntry<bool> logDiagnostics { get; set; }

	public static ConfigEntry<bool> logMousePointer { get; set; }

	private static ConfigEntry<Color> defaultEntryTextColor { get; set; }

	private static ConfigEntry<int> defaultEntryTextSize { get; set; }

	private static ConfigEntry<int> mousePointerVerticalOffset { get; set; }

	private static ConfigEntry<string> fastChangeElements { get; set; }

	private void Awake()
	{
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: 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_02ba: Expected O, but got Unknown
		_self = this;
		logDiagnostics = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Log Diagnostics To Log", true, (ConfigDescription)null);
		Debug.Log((object)("Embedded Character Sheet Plugin: " + ((object)this).GetType().AssemblyQualifiedName + " Active. Log Diagnostics = " + logDiagnostics.Value));
		triggerKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Toggle Character Sheet", new KeyboardShortcut((KeyCode)115, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), (ConfigDescription)null);
		triggerReset = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "You Know Nothing Jon Snow", new KeyboardShortcut((KeyCode)115, (KeyCode[])(object)new KeyCode[1] { (KeyCode)305 }), (ConfigDescription)null);
		triggerMousePosition = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Toggle Show Mouse Position", new KeyboardShortcut((KeyCode)115, (KeyCode[])(object)new KeyCode[1] { (KeyCode)307 }), (ConfigDescription)null);
		triggerValueDown = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Decrease Value", new KeyboardShortcut((KeyCode)44, Array.Empty<KeyCode>()), (ConfigDescription)null);
		triggerValueUp = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Increase Value", new KeyboardShortcut((KeyCode)46, Array.Empty<KeyCode>()), (ConfigDescription)null);
		rollMethod = ((BaseUnityPlugin)this).Config.Bind<RollMethod>("Settings", "Roll Method", RollMethod.talespire_dice, (ConfigDescription)null);
		closeAfteRoll = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Close Character Sheet After Roll", true, (ConfigDescription)null);
		applyNameMod = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Apply Name Mod On Roll Results In Chat", true, (ConfigDescription)null);
		logMousePointer = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Show Mouse Position", false, (ConfigDescription)null);
		mousePointerVerticalOffset = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "Pixel Height Of Top Toolbar", 38, (ConfigDescription)null);
		fastChangeElements = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "Comma Delimited Patterns Of Fast Change Elements", "*FastChange*", (ConfigDescription)null);
		defaultEntryTextColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Defaults", "Entry Text Color", Color.black, (ConfigDescription)null);
		defaultEntryTextSize = ((BaseUnityPlugin)this).Config.Bind<int>("Defaults", "Entry Text Size", 16, (ConfigDescription)null);
		RadialSubmenu.EnsureMainMenuItem("org.hollofox.plugins.RadialUIPlugin.Info", (MenuType)1, "Info", Image.LoadSprite("Icon.Info.png", (CacheType)999));
		RadialSubmenu.CreateSubMenuItem("org.hollofox.plugins.RadialUIPlugin.Info", "Character Sheet", Image.LoadSprite("Icon.CharacterSheet.png", (CacheType)999), (Action<CreatureGuid, string, MapMenuItem>)ToggleSheet, true, (Func<bool>)(() => LocalClient.HasControlOfCreature(new CreatureGuid(RadialUIPlugin.GetLastRadialTargetCreature()))));
		if (applyNameMod.Value)
		{
			Harmony val = new Harmony("org.lordashes.plugins.embeddedcharactersheet");
			val.PatchAll();
		}
		string[] array = fastChangeElements.Value.Split(new char[1] { ',' });
		foreach (string item in array)
		{
			fastElementPatterns.Add(item);
		}
		AssetDataPlugin.Subscribe("org.lordashes.plugins.embeddedcharactersheet", (Action<DatumChange>)RequestHandler, (Func<DatumChange, bool>)null);
		Utility.PostOnMainPage(((object)this).GetType());
	}

	private void Update()
	{
		//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_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: 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)
		if (Utility.isBoardLoaded())
		{
			KeyboardShortcut value = triggerKey.Value;
			if (((KeyboardShortcut)(ref value)).IsUp())
			{
				ToggleSheet(default(CreatureGuid), null, null);
			}
			value = triggerReset.Value;
			if (((KeyboardShortcut)(ref value)).IsUp())
			{
				SystemMessage.DisplayInfoText("Embedded Character Sheet Plugin:\r\nYou Know Nothing, Jon Snow", 2.5f);
				layouts.Clear();
				data.Clear();
				layoutTab = "";
				layoutSwitchInProgress = false;
			}
			value = triggerValueDown.Value;
			if (((KeyboardShortcut)(ref value)).IsUp())
			{
				Debug.Log((object)"Embedded Character Sheet Plugin: Requesting Element Value Decrease");
				ModifyValue(-1f);
			}
			value = triggerValueUp.Value;
			if (((KeyboardShortcut)(ref value)).IsUp())
			{
				Debug.Log((object)"Embedded Character Sheet Plugin: Requesting Element Value Increase");
				ModifyValue(1f);
			}
			value = triggerMousePosition.Value;
			if (((KeyboardShortcut)(ref value)).IsUp())
			{
				logMousePointer.Value = !logMousePointer.Value;
				Debug.Log((object)("Embedded Character Sheet Plugin: Toggled Show Mouse Position To " + logMousePointer.Value));
			}
		}
	}

	private void ToggleSheet(CreatureGuid arg1, string arg2, MapMenuItem arg3)
	{
		if (!characterSheetShowing)
		{
			Debug.Log((object)"Embedded Character Sheet Plugin: Toggling Embedded Character Sheet View To On");
			GetCharacterSheet();
		}
		else
		{
			Debug.Log((object)"Embedded Character Sheet Plugin: Toggling Embedded Character Sheet View To Off");
			currentData = null;
			currentLayout = null;
		}
		characterSheetShowing = !characterSheetShowing;
	}

	private void OnGUI()
	{
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		if (!characterSheetShowing)
		{
			return;
		}
		try
		{
			if ((Object)(object)currentLayout._background != (Object)null)
			{
				GUI.DrawTexture(new Rect((float)currentLayout.position.x, (float)currentLayout.position.y, (float)currentLayout.size.w, (float)currentLayout.size.h), (Texture)(object)currentLayout._background, (ScaleMode)0);
			}
			foreach (GuiElement element in currentLayout.elements)
			{
				switch (element.type)
				{
				case GuiElementType.legacy:
				case GuiElementType.button:
					ClickableButton(element, currentData);
					break;
				case GuiElementType.layout:
					ClickableLayout(element, currentData);
					break;
				}
			}
		}
		catch
		{
		}
		if (logMousePointer.Value)
		{
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(MouseManager.Position.x, (float)Screen.height - MouseManager.Position.y - (float)mousePointerVerticalOffset.Value);
			GUI.Label(new Rect(10f, 10f, 320f, 60f), val.x + "," + val.y);
		}
	}

	private void ClickableButton(GuiElement el, CharacterData data)
	{
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		bool flag = false;
		if ((Object)(object)el._texture != (Object)null)
		{
			if (GUI.Button(new Rect((float)(currentLayout.position.x + el.position.x), (float)(currentLayout.position.y + el.position.y), (float)el.size.w, (float)el.size.h), (Texture)(object)el._texture, el._style))
			{
				flag = true;
			}
		}
		else if (GUI.Button(new Rect((float)(currentLayout.position.x + el.position.x), (float)(currentLayout.position.y + el.position.y), (float)el.size.w, (float)el.size.h), el.content, el._style))
		{
			flag = true;
		}
		if (!flag)
		{
			return;
		}
		if (Input.GetMouseButtonUp(0))
		{
			if (logDiagnostics.Value)
			{
				Debug.Log((object)("Embedded Character Sheet Plugin: Roll Triggered. Name='" + el.target + "', Content='" + el.content + "', Target='" + el?.ToString() + "'"));
			}
			string text = ((el.name.Trim() != "") ? el.name : el.content);
			if (el.target.Trim() != "")
			{
				text = text + "\u00a0(" + el.target.Trim() + ")";
			}
			if (logDiagnostics.Value)
			{
				Debug.Log((object)("Embedded Character Sheet Plugin: Roll Name='" + text + "'"));
			}
			Roll(text, data.Evaluate(el.roll));
		}
		else if (Input.GetMouseButtonUp(2))
		{
			if (logDiagnostics.Value)
			{
				Debug.Log((object)"Embedded Character Sheet Plugin: Edit Triggered");
			}
			EditValue(el.roll);
		}
	}

	private void ClickableLayout(GuiElement el, CharacterData data)
	{
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		bool flag = false;
		if ((Object)(object)el._texture != (Object)null)
		{
			if (logDiagnostics.Value)
			{
				Debug.Log((object)("Embedded Character Sheet Plugin: Drawing Layout Texture '" + el.name + " (" + el.id + ")' at " + currentLayout.position.x + el.position.x + "," + currentLayout.position.y + el.position.y));
			}
			if (GUI.Button(new Rect((float)(currentLayout.position.x + el.position.x), (float)(currentLayout.position.y + el.position.y), (float)el.size.w, (float)el.size.h), (Texture)(object)el._texture, el._style))
			{
				flag = true;
			}
		}
		else
		{
			if (logDiagnostics.Value)
			{
				Debug.Log((object)("Embedded Character Sheet Plugin: Drawing Layout Text '" + el.name + " (" + el.id + ")' at " + currentLayout.position.x + el.position.x + "," + currentLayout.position.y + el.position.y));
			}
			if (GUI.Button(new Rect((float)(currentLayout.position.x + el.position.x), (float)(currentLayout.position.y + el.position.y), (float)el.size.w, (float)el.size.h), el.content, el._style))
			{
				flag = true;
			}
		}
		if (!flag)
		{
			return;
		}
		if (el.roll.Trim() == "")
		{
			if (logDiagnostics.Value)
			{
				Debug.Log((object)"Embedded Character Sheet Plugin: Switching Layout To Default");
			}
			layoutTab = "";
		}
		else
		{
			layoutTab = data.Evaluate(el.roll);
			if (logDiagnostics.Value)
			{
				Debug.Log((object)("Embedded Character Sheet Plugin: Switching Layout To Tab '" + layoutTab + "'"));
			}
		}
		GetCharacterSheet();
	}

	private void Roll(string content, string roll)
	{
		RollMethod value = this.rollMethod.Value;
		RollMethod rollMethod = value;
		if (rollMethod == RollMethod.chat_roll)
		{
			RollChatRoll(content, roll);
		}
		else
		{
			RollTalespire(content, roll);
		}
		if (closeAfteRoll.Value)
		{
			characterSheetShowing = false;
			currentData = null;
			currentLayout = null;
		}
	}

	private void RollChatRoll(string content, string rolls)
	{
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		string[] array = rolls.Split(new char[1] { '/' });
		foreach (string text in array)
		{
			try
			{
				Regex regex = new Regex("^(.+:([0-9]+[d|D][0-9]+([\\+|-][0-9]+)?)([\\+|-][0-9]+[d|D][0-9]+([\\+|-][0-9]+)?)*)(\\/.+:([0-9]+[d|D][0-9]+([\\+|-][0-9]+)?)([\\+|-][0-9]+[d|D][0-9]+([\\+|-][0-9]+)?)*)*$");
				string text2 = text;
				if (!text2.Contains(":"))
				{
					text2 = content + ":" + text2;
				}
				Debug.Log((object)("Embedded Character Sheet Plugin: Content: " + content + ", Roll: '" + text + "', ContentRoll: " + text2 + ", RegEx Match: " + regex.IsMatch(text2)));
				if (regex.IsMatch(text2))
				{
					ChatManager.SendChatMessageToBoard("/rn " + text2.Replace(":", " "), LocalClient.SelectedCreatureId.Value, (float3?)null, false);
					continue;
				}
				SystemMessage.DisplayInfoText(text2.Replace(":", " "), 2.5f);
				ChatManager.SendChatMessageToBoard(text2.Replace(":", " "), LocalClient.SelectedCreatureId.Value, (float3?)null, false);
			}
			catch
			{
				ChatManager.SendChatMessageToBoard(text, LocalClient.SelectedCreatureId.Value, (float3?)null, false);
			}
		}
	}

	private void RollTalespire(string content, string rolls)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		Debug.Log((object)("Embedded Character Sheet Plugin: Talespire Rolling '" + rolls + "'"));
		CreatureBoardAsset val = null;
		CreaturePresenter.TryGetAsset(LocalClient.SelectedCreatureId, ref val);
		string text = (((Object)(object)val != (Object)null) ? ("[" + Utility.GetCreatureName(val.Name) + "]") : "");
		try
		{
			string[] array = rolls.Split(new char[1] { '/' });
			foreach (string text2 in array)
			{
				Regex regex = new Regex("^(.+:([0-9]+[d|D][0-9]+([\\+|-][0-9]+)?)([\\+|-][0-9]+[d|D][0-9]+([\\+|-][0-9]+)?)*)(\\/.+:([0-9]+[d|D][0-9]+([\\+|-][0-9]+)?)([\\+|-][0-9]+[d|D][0-9]+([\\+|-][0-9]+)?)*)*$");
				string text3 = text2;
				if (!text3.Contains(":"))
				{
					text3 = content + ":" + text3;
				}
				Debug.Log((object)("Embedded Character Sheet Plugin: Content: " + content + ", Roll: '" + text2 + "', ContentRoll: " + text3 + ", RegEx Match: " + regex.IsMatch(text3)));
				if (regex.IsMatch(text3))
				{
					text = text + text3 + "/";
					continue;
				}
				SystemMessage.DisplayInfoText(text2, 2.5f);
				ChatManager.SendChatMessageToBoard(text2, LocalClient.SelectedCreatureId.Value, (float3?)null, false);
			}
		}
		catch
		{
			ChatManager.SendChatMessageToBoard(rolls, LocalClient.SelectedCreatureId.Value, (float3?)null, false);
		}
		if (text.EndsWith("/"))
		{
			text = text.Substring(0, text.Length - 1);
			Debug.Log((object)("Embedded Character Sheet Plugin: Executing \"talespire://dice/" + text + "\""));
			Process process = new Process();
			process.StartInfo = new ProcessStartInfo
			{
				FileName = "talespire://dice/" + text,
				Arguments = "",
				CreateNoWindow = true
			};
			process.Start();
		}
	}

	private void GetCharacterSheet()
	{
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		string json = "";
		if (layoutSwitchInProgress)
		{
			if (logDiagnostics.Value)
			{
				Debug.Log((object)"Embedded Character Sheet Plugin: Layout Switch In Progress. Ignoring Link Click");
			}
			SystemSounds.Beep.Play();
			SystemSounds.Beep.Play();
			SystemSounds.Beep.Play();
			return;
		}
		layoutSwitchInProgress = true;
		CreatureBoardAsset val = null;
		CreaturePresenter.TryGetAsset(LocalClient.SelectedCreatureId, ref val);
		if ((Object)(object)val != (Object)null)
		{
			try
			{
				string creatureName = Utility.GetCreatureName(val.Name);
				if (data.ContainsKey(creatureName))
				{
					if (logDiagnostics.Value)
					{
						Debug.Log((object)("Embedded Character Sheet Plugin: Using Cached Data For '" + creatureName + "'"));
					}
					currentData = data[creatureName];
				}
				else
				{
					if (logDiagnostics.Value)
					{
						Debug.Log((object)("Embedded Character Sheet Plugin: Looking For Data For '" + creatureName + "'"));
					}
					if (!File.Exists("EmbeddedCharacterSheet.Data." + creatureName + ".csd"))
					{
						if (logDiagnostics.Value)
						{
							Debug.Log((object)("Embedded Character Sheet Plugin: No Data File For '" + creatureName + "' Name 'EmbeddedCharacterSheet.Data." + creatureName + ".csd'"));
						}
						characterSheetShowing = false;
						currentData = null;
						currentLayout = null;
						return;
					}
					if (logDiagnostics.Value)
					{
						Debug.Log((object)("Embedded Character Sheet Plugin: Found 'EmbeddedCharacterSheet.Data." + creatureName + ".csd'"));
					}
					json = "{#EmbeddedCharacterSheet.Data." + creatureName + ".csd#}";
					LoadEmbeddedFiles(ref json, creatureName);
					currentData = JsonConvert.DeserializeObject<CharacterData>(json);
					currentData._id = creatureName;
					data.Add(creatureName, currentData);
				}
				if (layouts.ContainsKey(currentData.layout + layoutTab))
				{
					if (logDiagnostics.Value)
					{
						Debug.Log((object)("Embedded Character Sheet Plugin: Using Cached Layout For '" + currentData.layout + "'"));
					}
					currentLayout = layouts[currentData.layout + layoutTab].Clone();
					Debug.Log((object)("Embedded Character Sheet Plugin: Cached = " + JsonConvert.SerializeObject((object)currentLayout, (Formatting)1)));
				}
				else
				{
					if (logDiagnostics.Value)
					{
						Debug.Log((object)("Embedded Character Sheet Plugin: Looking For Layout For '" + currentData.layout + "'"));
					}
					if (!File.Exists("EmbeddedCharacterSheet.Layout." + currentData.layout + layoutTab + ".csl"))
					{
						Debug.LogWarning((object)("Embedded Character Sheet Plugin: No Layout File For 'EmbeddedCharacterSheet.Layout." + currentData.layout + layoutTab + ".csl'"));
						characterSheetShowing = false;
						currentData = null;
						currentLayout = null;
						return;
					}
					if (logDiagnostics.Value)
					{
						Debug.Log((object)("Embedded Character Sheet Plugin: Found 'EmbeddedCharacterSheet.Layout." + currentData.layout + layoutTab + ".csl'"));
					}
					json = "{#EmbeddedCharacterSheet.Layout." + currentData.layout + layoutTab + ".csl#}";
					LoadEmbeddedFiles(ref json, creatureName, currentData.layout + layoutTab);
					GuiLayout guiLayout = JsonConvert.DeserializeObject<GuiLayout>(json);
					if (logDiagnostics.Value)
					{
						Debug.Log((object)("Embedded Character Sheet Plugin: Loaded Layout '" + currentData.layout + layoutTab + "'"));
					}
					Debug.Log((object)("Embedded Character Sheet Plugin: Loaded = " + JsonConvert.SerializeObject((object)guiLayout, (Formatting)1)));
					if (guiLayout.background != "")
					{
						guiLayout._background = Image.LoadTexture(guiLayout.background, (CacheType)999);
					}
					bool flag = false;
					foreach (GuiElement element in guiLayout.elements)
					{
						if (element.style != null)
						{
							if (element.type == GuiElementType.legacy)
							{
								flag = true;
							}
							if (element.style.ToString().Trim() != "")
							{
								ReflectionObjectModifier.ApplyStyleCustomization(element._style, element.style);
							}
						}
					}
					if (flag)
					{
						SystemMessage.DisplayInfoText("Embedded Character Sheet:\r\nLayout Uses Legacy Type 0\r\nPlease Change To Type 1", 2.5f);
						Debug.LogWarning((object)"Embedded Character Sheet: Layout Uses Legacy 'Type 0' Element. Please Change To 'Type 1' For Future Compatibility.");
					}
					layouts.Add(currentData.layout + layoutTab, guiLayout);
					currentLayout = guiLayout.Clone();
				}
				foreach (GuiElement element2 in currentLayout.elements)
				{
					int num = 0;
					Debug.Log((object)("Embedded Character Sheet Plugin: Raw Element Content Is '" + element2.content + "'"));
					while (element2.content.Contains("{") || element2.content.Contains("+") || element2.content.Contains("-"))
					{
						element2.content = currentData.Evaluate(element2.content);
						element2.content = element2.content.Replace(" ", "\u00a0");
						element2.name = currentData.Evaluate(element2.name);
						element2.name = element2.name.Replace(" ", "\u00a0");
						element2.target = currentData.Evaluate(element2.target);
						element2.target = element2.target.Replace(" ", "\u00a0");
						num++;
						if (num >= 10)
						{
							break;
						}
					}
					Debug.Log((object)("Embedded Character Sheet Plugin: Evaluated Element Content Is '" + element2.content + "'"));
					if (element2.content.StartsWith("#") && element2.content.EndsWith("#") && (Object)(object)element2._texture == (Object)null)
					{
						Debug.Log((object)("Embedded Character Sheet Plugin: Loading Texture '" + element2.content.Replace("#", "") + "'"));
						element2._texture = Image.LoadTexture(element2.content.Replace("#", ""), (CacheType)999);
					}
				}
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)"Embedded Character Sheet Plugin: Exception In GetCharacterSheet");
				Debug.LogException(ex);
				Debug.Log((object)("JSON:\r\n" + json));
			}
		}
		Debug.Log((object)"Embedded Character Sheet Plugin: Building Character Sheet Complete");
		layoutSwitchInProgress = false;
	}

	private void LoadEmbeddedFiles(ref string json, string assetName = "", string layoutName = "")
	{
		while (json.Contains("{#"))
		{
			string text = json.Substring(json.IndexOf("{#"));
			text = text.Substring(0, text.IndexOf("#}") + 2);
			string text2 = text.Replace("{#", "").Replace("#}", "").Replace("{NAME}", assetName)
				.Replace("{LAYOUT}", "");
			Debug.Log((object)("Embedded Character Sheet Plugin: Replacing '" + text + "' With Embedded File '" + text2 + "' Contents"));
			try
			{
				string newValue = File.ReadAllText(text2, (CacheType)999);
				json = json.Replace(text, newValue);
			}
			catch
			{
				Debug.LogWarning((object)("Embedded Character Sheet Plugin: Unable To Load File '" + text2 + "'"));
				json = json.Replace(text, "");
			}
		}
	}

	private void EditValue(string shard)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		CreatureBoardAsset val = null;
		CreaturePresenter.TryGetAsset(LocalClient.SelectedCreatureId, ref val);
		string assetName = Utility.GetCreatureName(val.Name);
		string text = "EmbeddedCharacterSheet.Data." + Utility.GetCreatureName(val.Name) + ".csd";
		if (shard.Contains("{"))
		{
			string key = shard.Substring(shard.LastIndexOf("{"));
			key = key.Substring(0, key.LastIndexOf("}") + 1);
			string value = currentData.stats[key];
			SystemMessage.AskForTextInput(shard, key.Replace("{", "").Replace("}", "") + " Value:", 1, "Apply", (Action<string>)delegate(string newValue)
			{
				Debug.Log((object)("Embedded Character Sheet Plugin: Replacing Data Key '" + key + "' Value '" + value + "' With '" + newValue + "'"));
				AssetDataPlugin.SendInfo("org.lordashes.plugins.embeddedcharactersheet", assetName + "," + key + "," + value + "," + newValue);
			}, (Action)null, "Cancel", (Action)null, value);
		}
	}

	private void ModifyValue(float amount)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		Vector2 val = default(Vector2);
		foreach (GuiElement element in currentLayout.elements)
		{
			((Vector2)(ref val))..ctor(MouseManager.Position.x, (float)Screen.height - MouseManager.Position.y - (float)mousePointerVerticalOffset.Value);
			Debug.Log((object)("Embedded Character Sheet Plugin: Mouse At " + val.x + " vs " + element.position.x + "->" + (element.position.x + element.size.w) + ", " + val.y + " vs " + element.position.y + "->" + (element.position.y + element.size.h) + ", Content: " + element.content + ", Roll: " + element.roll));
			if (!(val.x >= (float)element.position.x) || !(val.x <= (float)(element.position.x + element.size.w)) || !(val.y >= (float)element.position.y) || !(val.y <= (float)(element.position.y + element.size.h)))
			{
				continue;
			}
			Debug.Log((object)("Embedded Character Sheet Plugin: Mouse Is Inside Element. Id = " + element.id + ", Content = " + element.content + ", Roll = " + element.roll));
			bool flag = false;
			foreach (string fastElementPattern in fastElementPatterns)
			{
				if (element.id.IsMatch(fastElementPattern))
				{
					flag = true;
					break;
				}
			}
			if (flag)
			{
				Debug.Log((object)("Embedded Character Sheet Plugin: Hover Element '" + element.id + "' Is A Fast Change Element"));
				float result = 0f;
				if (element.roll.Contains("{") && float.TryParse(element.content.Trim(), out result))
				{
					selectedKey = element.roll.Substring(element.roll.LastIndexOf("{"));
					selectedKey = selectedKey.Substring(0, selectedKey.LastIndexOf("}") + 1);
					selectedValue = currentData.stats[selectedKey];
					if (selectedTime < 0f)
					{
						selectedPrevious = selectedValue;
					}
					Debug.Log((object)("Embedded Character Sheet Plugin: Key = " + selectedKey + ", Value = " + selectedValue + "->" + (float.Parse(selectedValue) + amount)));
					selectedValue = (float.Parse(selectedValue) + amount).ToString();
					element.content = selectedValue;
					currentData.stats[selectedKey] = selectedValue;
				}
			}
			else
			{
				Debug.Log((object)("Embedded Character Sheet Plugin: Hover Element '" + element.id + "' Is Not A Fast Change Element"));
			}
		}
		if (selectedTime < 0f)
		{
			selectedTime = 10f;
			((MonoBehaviour)_self).StartCoroutine(DetectModificationEnd());
		}
		else
		{
			selectedTime = 10f;
		}
	}

	private static IEnumerator DetectModificationEnd()
	{
		while (selectedTime > 0f)
		{
			Debug.Log((object)("Embedded Character Sheet Plugin: Modify Timer = " + selectedTime));
			yield return (object)new WaitForSeconds(0.1f);
			selectedTime -= 1f;
		}
		selectedTime = -1f;
		CreatureBoardAsset asset = null;
		CreaturePresenter.TryGetAsset(LocalClient.SelectedCreatureId, ref asset);
		string[] obj = new string[8] { "Embedded Character Sheet Plugin: Distributing Update For Asset ", null, null, null, null, null, null, null };
		CreatureGuid creatureId = asset.CreatureId;
		obj[1] = ((object)(CreatureGuid)(ref creatureId)).ToString();
		obj[2] = " Key ";
		obj[3] = selectedKey;
		obj[4] = " From ";
		obj[5] = selectedPrevious;
		obj[6] = " To ";
		obj[7] = selectedValue;
		Debug.Log((object)string.Concat(obj));
		AssetDataPlugin.SendInfo("org.lordashes.plugins.embeddedcharactersheet", Utility.GetCreatureName(asset.Name) + "," + selectedKey + "," + selectedPrevious + "," + selectedValue);
	}

	private void RequestHandler(DatumChange change)
	{
		string[] array = change.value.ToString().Split(new char[1] { ',' });
		try
		{
			string text = File.Find("EmbeddedCharacterSheet.Data." + array[0] + ".csd", (CacheType)999)[0];
			string text2 = File.ReadAllText(text, (CacheType)999);
			text2 = text2.Replace("\"" + array[1] + "\": \"" + array[2] + "\"", "\"" + array[1] + "\": \"" + array[3] + "\"");
			File.WriteAllText(text, text2, (CacheType)999);
			Debug.Log((object)("Embedded Character Sheet Plugin: Replaced \"" + array[1] + "\": \"" + array[2] + "\" To \"" + array[1] + "\": \"" + array[3] + "\" In " + text));
			Debug.Log((object)("Embedded Character Sheet Plugin: Removing Cached Data For '" + array[0] + "'"));
			if (data.ContainsKey(array[0]))
			{
				data.Remove(array[0]);
			}
			Debug.Log((object)("Embedded Character Sheet Plugin: Removing Cached Layout '" + currentData.layout + layoutTab + "'"));
			if (layouts.ContainsKey(currentData.layout + layoutTab))
			{
				layouts.Remove(array[0]);
			}
			Debug.Log((object)("Embedded Character Sheet Plugin: Reloading Character Sheet For '" + array[0] + "'"));
			GetCharacterSheet();
		}
		catch (Exception)
		{
			Debug.Log((object)("Embedded Character Sheet Plugin: Device Does Not Have Character Sheet For '" + array[0] + "'"));
		}
	}
}
public static class ReflectionObjectModifier
{
	public static void ApplyStyleCustomization(object obj, string mods)
	{
		string[] array = mods.Split(new char[1] { '|' });
		if (array.Length == 0)
		{
			return;
		}
		string[] array2 = array;
		foreach (string text in array2)
		{
			if (EmbeddedCharacterSheetPlugin.logDiagnostics.Value)
			{
				Debug.Log((object)("Embedded Characater Sheet Plugin: Applying Style Customizations '" + text + "'"));
			}
			string key = text.Substring(0, text.IndexOf("="));
			string text2 = text.Substring(text.IndexOf("=") + 1);
			if (!text2.StartsWith("&") || !text2.EndsWith("&"))
			{
				Modify(obj, key, text2);
			}
		}
	}

	public static void Modify(object baseObj, string key, object value)
	{
		string text = "";
		if (key.Contains("."))
		{
			text = key.Substring(key.LastIndexOf(".") + 1);
			key = key.Substring(0, key.LastIndexOf("."));
		}
		else
		{
			text = key;
			key = "";
		}
		object parent = baseObj;
		if (key != "")
		{
			string[] array = key.Split(new char[1] { '.' });
			foreach (string childName in array)
			{
				parent = GetObject(parent, childName);
			}
		}
		SetValue(parent, text, value);
	}

	public static object GetObject(object parent, string childName)
	{
		try
		{
			Type type = parent.GetType();
			foreach (FieldInfo runtimeField in type.GetRuntimeFields())
			{
				if (runtimeField.Name == childName)
				{
					return runtimeField.GetValue(parent);
				}
			}
			foreach (PropertyInfo runtimeProperty in type.GetRuntimeProperties())
			{
				if (runtimeProperty.Name == childName)
				{
					return runtimeProperty.GetValue(parent);
				}
			}
			return null;
		}
		catch
		{
			Debug.LogWarning((object)("Embedded Characater Sheet Plugin: Error Getting '" + childName + "' Of '" + parent.ToString() + "'"));
			return null;
		}
	}

	public static void SetValue(object parent, string prop, object value)
	{
		try
		{
			Type type = parent.GetType();
			foreach (FieldInfo runtimeField in type.GetRuntimeFields())
			{
				if (runtimeField.Name == prop)
				{
					if (EmbeddedCharacterSheetPlugin.logDiagnostics.Value)
					{
						Debug.Log((object)("Embedded Characater Sheet Plugin: Setting Field (Type " + runtimeField.FieldType.Name + ") To " + value));
					}
					runtimeField.SetValue(parent, ConvertToType(value, runtimeField.FieldType));
					return;
				}
			}
			foreach (PropertyInfo runtimeProperty in type.GetRuntimeProperties())
			{
				if (runtimeProperty.Name == prop)
				{
					if (EmbeddedCharacterSheetPlugin.logDiagnostics.Value)
					{
						Debug.Log((object)("Embedded Characater Sheet Plugin: Setting Property (Type " + runtimeProperty.PropertyType.Name + ") To " + value));
					}
					runtimeProperty.SetValue(parent, ConvertToType(value, runtimeProperty.PropertyType));
					break;
				}
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("Embedded Characater Sheet Plugin: Error Setting Property '" + prop + "' To '" + value?.ToString() + "'"));
			Debug.LogException(ex);
		}
	}

	private static object ConvertToType(object value, Type type)
	{
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0291: Unknown result type (might be due to invalid IL or missing references)
		//IL_02de: Unknown result type (might be due to invalid IL or missing references)
		switch (type.Name)
		{
		case "String":
			return value.ToString();
		case "Color":
		{
			Color clear = Color.clear;
			if (!value.ToString().Contains(","))
			{
				ColorUtility.TryParseHtmlString(value.ToString(), ref clear);
				return clear;
			}
			string[] array = value.ToString().Split(new char[1] { ',' });
			return array.Length switch
			{
				1 => (object)new Color(float.Parse(array[0]) / 255f, 0f, 0f), 
				2 => (object)new Color(float.Parse(array[0]) / 255f, float.Parse(array[1]) / 255f, 0f), 
				3 => (object)new Color(float.Parse(array[0]) / 255f, float.Parse(array[1]) / 255f, float.Parse(array[2]) / 255f), 
				4 => (object)new Color(float.Parse(array[0]) / 255f, float.Parse(array[1]) / 255f, float.Parse(array[2]) / 255f, float.Parse(array[3]) / 255f), 
				_ => null, 
			};
		}
		case "Font":
			return null;
		case "Int16":
			return short.Parse(value.ToString());
		case "Int32":
			return int.Parse(value.ToString());
		case "Int64":
			return long.Parse(value.ToString());
		case "UInt16":
			return ushort.Parse(value.ToString());
		case "UInt32":
			return uint.Parse(value.ToString());
		case "UInt64":
			return ulong.Parse(value.ToString());
		case "Texture2D":
			return Image.LoadTexture(value.ToString(), (CacheType)999);
		default:
			try
			{
				foreach (MethodInfo runtimeMethod in type.GetRuntimeMethods())
				{
					if (runtimeMethod.Name == "Parse")
					{
						if (EmbeddedCharacterSheetPlugin.logDiagnostics.Value)
						{
							Debug.Log((object)("Embedded Characater Sheet Plugin: Attempting Conversion Of '" + value.ToString() + "' Using Parse Method Of '" + type.Name + "'"));
						}
						return runtimeMethod.Invoke(null, new object[1] { value.ToString() });
					}
				}
				int result = 0;
				if (int.TryParse(value.ToString(), out result))
				{
					if (EmbeddedCharacterSheetPlugin.logDiagnostics.Value)
					{
						Debug.Log((object)"Embedded Characater Sheet Plugin: Attempting Return As An Enum Int");
					}
					return result;
				}
				return value.ToString();
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)"Embedded Characater Sheet Plugin: Error In Parse Conversion");
				Debug.LogException(ex);
			}
			return value.ToString();
		}
	}
}
public static class ExtensionMethods
{
	public static bool IsMatch(this string str, string check)
	{
		string text = check;
		text = text.Replace("*", "\u00a0*").Replace("?", "\u00a0");
		text = text.Replace(".", "\\.");
		text = text.Replace("(", "\\(");
		text = text.Replace(")", "\\)");
		text = text.Replace("[", "\\[");
		text = text.Replace("]", "\\]");
		text = text.Replace("{", "\\{");
		text = text.Replace("}", "\\}");
		text = text.Replace("^", "\\^");
		text = text.Replace("$", "\\$");
		text = text.Replace("|", "\\|");
		text = text.Replace("?", "\\?");
		text = text.Replace("+", "\\+");
		text = text.Replace("+", "\\+");
		text = text.Replace("\u00a0", ".");
		text = "^" + text + "$";
		Debug.Log((object)("Embedded Character Sheet Plugin: Checking String '" + str + "' Against Pattern '" + check + "' Using Regex '" + text + "'"));
		return new Regex(text).IsMatch(str);
	}

	public static string ColsolidateModifiers(this string str)
	{
		Regex regex = new Regex("\\d+");
		MatchCollection matchCollection = regex.Matches(str);
		List<int> list = new List<int>();
		foreach (Match item in matchCollection)
		{
			if (item.Index == 0 || str.Substring(item.Index - 1, 1).ToUpper() != "D")
			{
				list.Add(int.Parse(item.Value));
			}
		}
		for (int i = 0; i < list.Count - 1; i++)
		{
			if (str.Contains(list[i] + "+" + list[i + 1]))
			{
				str = str.Replace(list[i] + "+" + list[i + 1], (list[i] + list[i + 1]).ToString());
			}
			if (str.Contains(list[i] + "-" + list[i + 1]))
			{
				str = str.Replace(list[i] + "-" + list[i + 1], (list[i] + list[i + 1]).ToString());
			}
		}
		return str;
	}
}