using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using BepInEx;
using BepInEx.Configuration;
using Bounce.Singletons;
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("CharacterSheetsPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CharacterSheetsPlugin")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("CharacterSheetsPlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("2.4.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("2.4.0.0")]
namespace LordAshes;
[BepInPlugin("org.lordashes.plugins.charactersheets", "Character Sheets Plug-In", "2.4.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class CharacterSheetsPlugin : BaseUnityPlugin
{
public enum RollMode
{
ChatRollMode,
TalespireDice
}
public class Element
{
public string name { get; set; }
public Point position { get; set; }
public string text { get; set; } = "";
public float size { get; set; } = 12f;
public string roll { get; set; } = "";
public int width { get; set; } = -1;
}
public const string Guid = "org.lordashes.plugins.charactersheets";
public const string Version = "2.4.0.0";
private Dictionary<CreatureGuid, Dictionary<string, string>> replacements = new Dictionary<CreatureGuid, Dictionary<string, string>>();
private string edition = "Dnd5e".Replace(".", "");
private Form sheet = null;
private ConfigEntry<KeyboardShortcut> triggerKeyShow { get; set; }
private ConfigEntry<KeyboardShortcut> triggerKeyEdition { get; set; }
private ConfigEntry<string> contentFolder { get; set; }
private ConfigEntry<bool> keepOne { get; set; }
private void Awake()
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
Debug.Log((object)"Character Sheets Plugin: Active.");
triggerKeyShow = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Open Character Sheet", new KeyboardShortcut((KeyCode)111, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), (ConfigDescription)null);
triggerKeyEdition = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Change Edition", new KeyboardShortcut((KeyCode)105, (KeyCode[])(object)new KeyCode[1] { (KeyCode)305 }), (ConfigDescription)null);
edition = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "Default Edition", "Dnd5e", (ConfigDescription)null).Value;
keepOne = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Keep Only One Character Sheet Open", true, (ConfigDescription)null);
contentFolder = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "Content Folder", Paths.PluginPath + "/LordAshes-CharacterSheetsPlugin/CustomData/Misc/", (ConfigDescription)null);
RadialSubmenu.EnsureMainMenuItem("org.hollofox.plugins.RadialUIPlugin.Info", (MenuType)1, "Info", Image.LoadSprite("Images/Icons/Info.png", (CacheType)999));
RadialSubmenu.CreateSubMenuItem("org.hollofox.plugins.RadialUIPlugin.Info", "Character Sheet", Image.LoadSprite("Images/Icons/CharacterSheet.png", (CacheType)999), (Action<CreatureGuid, string, MapMenuItem>)Show, true, (Func<bool>)(() => LocalClient.HasControlOfCreature(new CreatureGuid(RadialUIPlugin.GetLastRadialTargetCreature()))));
StateDetection.Initialize(((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)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
if (!isBoardLoaded())
{
return;
}
KeyboardShortcut value = triggerKeyShow.Value;
if (((KeyboardShortcut)(ref value)).IsUp())
{
Show(LocalClient.SelectedCreatureId);
}
value = triggerKeyEdition.Value;
if (((KeyboardShortcut)(ref value)).IsUp())
{
SystemMessage.AskForTextInput("Edition", "Edition Name:", "Set", (Action<string>)delegate(string ed)
{
edition = ed;
}, (Action)null, "Cancel", (Action)null, edition);
}
}
private void Show(CreatureGuid cid, string menu, MapMenuItem mmi)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
Show(new CreatureGuid(RadialMenus.GetTargetCreatureId()));
}
private void Show(CreatureGuid cid)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
//IL_01ac: Expected O, but got Unknown
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Expected O, but got Unknown
//IL_0266: Unknown result type (might be due to invalid IL or missing references)
//IL_0292: Unknown result type (might be due to invalid IL or missing references)
//IL_027c: Unknown result type (might be due to invalid IL or missing references)
//IL_0480: Unknown result type (might be due to invalid IL or missing references)
//IL_0631: Unknown result type (might be due to invalid IL or missing references)
//IL_0638: Expected O, but got Unknown
//IL_0685: Unknown result type (might be due to invalid IL or missing references)
//IL_068f: Expected O, but got Unknown
//IL_06e2: Unknown result type (might be due to invalid IL or missing references)
Debug.Log((object)"Character Sheets Plugin: Creating Character Sheet...");
CreatureBoardAsset selected = null;
CreaturePresenter.TryGetAsset(cid, ref selected);
if ((Object)(object)selected != (Object)null)
{
Debug.Log((object)("Creating Character Sheet For '" + selected.Name + "'"));
if (sheet != null && keepOne.Value)
{
sheet.Close();
}
sheet = new Form();
((Control)sheet).Name = "Character Sheet: " + GetCreatureName(selected);
((Control)sheet).Text = "Character Sheet: " + GetCreatureName(selected);
string text = "";
try
{
try
{
text = File.Find("Images/" + edition + ".CharacterSheet.png", (CacheType)999)[0];
Debug.Log((object)("Character Sheets Plugin: Loading CharacterSheet Background from '" + text + "'"));
}
catch (Exception)
{
Debug.LogWarning((object)("Character Sheets Plugin: Unable to find 'Images/" + edition + ".CharacterSheet.png'. Using content folder."));
text = contentFolder.Value + "/../Images/" + edition + ".CharacterSheet.png";
Debug.Log((object)("Character Sheets Plugin: Loading CharacterSheet Background from '" + text + "'"));
}
}
catch (Exception ex2)
{
Debug.LogWarning((object)("Character Sheets Plugin: Unable to find 'Images/" + edition + ".CharacterSheet.png'"));
Debug.LogException(ex2);
return;
}
Image val = null;
try
{
val = (Image)new Bitmap(text);
Debug.Log((object)"Character Sheets Plugin: Background Image Loaded");
}
catch (Exception ex3)
{
Debug.LogWarning((object)("Character Sheets Plugin: Unable to load '" + text + "'"));
Debug.LogException(ex3);
return;
}
Debug.Log((object)"Character Sheets Plugin: Building Form");
((Control)sheet).BackgroundImage = val;
((Control)sheet).Width = val.Width + 15;
((Control)sheet).Height = val.Height + 30;
((Control)sheet).Left = (Screen.width - ((Control)sheet).Width) / 2;
((Control)sheet).Top = (Screen.height - ((Control)sheet).Height) / 2;
if (!replacements.ContainsKey(cid))
{
replacements.Add(cid, new Dictionary<string, string>());
}
else
{
replacements[cid].Clear();
}
try
{
try
{
text = File.Find("Misc/" + edition + "." + GetCreatureName(selected) + ".chs", (CacheType)999)[0];
Debug.Log((object)("Character Sheets Plugin: Loading CharacterSheet Data from '" + text + "'"));
}
catch (Exception)
{
Debug.LogWarning((object)("Character Sheets Plugin: Unable to find 'Misc/" + edition + "." + GetCreatureName(selected) + ".chs'. Using content folder."));
text = contentFolder.Value + edition + "." + GetCreatureName(selected) + ".chs";
Debug.Log((object)("Character Sheets Plugin: Loading CharacterSheet Data from '" + text + "'"));
}
}
catch (Exception ex5)
{
Debug.LogWarning((object)("Character Sheets Plugin: Unable to find 'Misc/" + edition + "." + GetCreatureName(selected) + ".chs'"));
Debug.LogException(ex5);
return;
}
string[] array = null;
try
{
array = File.ReadAllLines(text);
Debug.Log((object)("Character Sheets Plugin: Loaded CharacterSheet Data from '" + text + "'"));
}
catch (Exception ex6)
{
Debug.LogWarning((object)("Character Sheets Plugin: Unable to load '" + text + "'"));
Debug.LogException(ex6);
return;
}
string[] array2 = array;
foreach (string text2 in array2)
{
string[] array3 = text2.Split(new char[1] { '=' });
if (array3.Count() == 2)
{
replacements[cid].Add(array3[0], array3[1]);
}
}
try
{
try
{
text = File.Find("Misc/" + edition + ".CharacterSheetLayout.json", (CacheType)999)[0];
Debug.Log((object)("Character Sheets Plugin: Loading CharacterSheet Layout from '" + text + "'"));
}
catch (Exception)
{
Debug.LogWarning((object)("Character Sheets Plugin: Unable to find 'Misc/" + edition + ".CharacterSheetLayout.json'. Using content folder."));
text = contentFolder.Value + edition + ".CharacterSheetLayout.json";
Debug.Log((object)("Character Sheets Plugin: Loading CharacterSheet Layout from '" + text + "'"));
}
}
catch (Exception ex8)
{
Debug.LogWarning((object)("Character Sheets Plugin: Unable to find 'Misc/" + edition + ".CharacterSheetLayout.json'"));
Debug.LogException(ex8);
return;
}
string text3 = "";
try
{
text3 = File.ReadAllText(text);
Debug.Log((object)("Character Sheets Plugin: Loaded CharacterSheet Layout from '" + text + "'"));
}
catch (Exception ex9)
{
Debug.LogWarning((object)("Character Sheets Plugin: Unable to load '" + text + "'"));
Debug.LogException(ex9);
return;
}
Element[] array4 = null;
try
{
array4 = JsonConvert.DeserializeObject<Element[]>(text3);
Debug.Log((object)("Character Sheets Plugin: Understood CharacterSheet Layout from '" + text + "'"));
}
catch (Exception ex10)
{
Debug.LogWarning((object)("Character Sheets Plugin: Error In Json Encoding. Unable To Deserialize '" + text + "'"));
Debug.LogException(ex10);
return;
}
Debug.Log((object)"Character Sheets Plugin: Data Loaded. Building Form Contents.");
Element[] array5 = array4;
foreach (Element el in array5)
{
Label val2 = new Label();
((Control)val2).Left = el.position.X;
((Control)val2).Top = el.position.Y;
((Control)val2).Font = new Font("Courier New", el.size);
val2.TextAlign = (ContentAlignment)64;
((Control)val2).AutoSize = true;
((Control)val2).ForeColor = Color.FromArgb(255, 0, 0, 0);
((Control)val2).BackColor = Color.FromArgb(16, 30, 30, 30);
string text4 = el.name;
foreach (KeyValuePair<string, string> item in replacements[cid])
{
text4 = text4.Replace(item.Key, item.Value);
if (el.text.Contains("{"))
{
el.text = el.text.Replace(item.Key, item.Value);
}
if (item.Key.StartsWith("{USERSLOT"))
{
el.roll = el.roll.Replace(item.Key, item.Value);
}
}
((Control)val2).Click += delegate
{
LinkClick(el, selected);
};
((Control)val2).Enabled = true;
((Control)val2).Visible = true;
((Control)val2).AutoSize = true;
if (el.width <= 0)
{
((Control)val2).Text = el.text + text4;
}
else
{
int length = el.width - text4.Length;
((Control)val2).Text = (el.text + new string(' ', el.width)).Substring(0, length) + text4;
}
if (((Control)val2).Text.StartsWith("{USERSLOT"))
{
((Control)val2).Text = "";
}
((Control)sheet).Controls.Add((Control)(object)val2);
((Control)sheet).Enabled = true;
((Control)sheet).Visible = true;
((Control)sheet).Show();
((Control)sheet).SendToBack();
}
}
else
{
SystemMessage.DisplayInfoText("Character Sheet Plugin:\r\nPlease select a mini before using.", 2.5f);
}
}
private string GetCreatureName(CreatureBoardAsset asset)
{
string text = asset.Name;
if (text.Contains("<size=0>"))
{
text = text.Substring(0, text.IndexOf("<size=0>")).Trim();
}
return text;
}
private void LinkClick(Element el, CreatureBoardAsset cid)
{
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
try
{
if (el.roll.StartsWith("/"))
{
ChatManager.SendChatMessageToBoard(el.roll, cid.CreatureId.Value, (float3?)null, false);
return;
}
string text = "{" + el.roll + "}";
Debug.Log((object)("Character Sheet Plugin: Roll = " + text));
text = MakeReplacements(cid.CreatureId, "{" + el.roll + "}");
if (text == "{" + el.roll + "}")
{
text = MakeReplacements(cid.CreatureId, el.roll);
}
text = Combine(text);
Debug.Log((object)("Character Sheet Plugin: Rolling '" + el.text.Replace(" ", "\u00a0") + " " + text + "'"));
if (((BaseUnityPlugin)this).Config.Bind<RollMode>("Settings", "Roll Method", RollMode.ChatRollMode, (ConfigDescription)null).Value == RollMode.ChatRollMode)
{
Debug.Log((object)"Character Sheet Plugin: Processing Via Chat Roller");
ChatManager.SendChatMessageToBoard("/rn " + el.text.Replace(" ", "\u00a0") + " " + text, cid.CreatureId.Value, (float3?)null, false);
return;
}
Regex regex = new Regex("^[0-9]+D[0-9]+[\\+\\-][0-9]+[\\+\\-][0-9]+$");
Regex regex2 = new Regex("^[0-9]+D[0-9]+[\\+\\-][0-9]+$");
Regex regex3 = new Regex("^[0-9]+$");
if (regex.IsMatch(text))
{
SystemMessage.DisplayInfoText("Talespire Dice Protocol\r\nSupports Only One Modifier.", 2.5f);
SystemMessage.DisplayInfoText("Please Fix Character Sheet For '" + (cid.Name + "<").Substring(0, (cid.Name + "<").IndexOf("<")) + "'", 2.5f);
}
else if (regex2.IsMatch(text))
{
string text2 = "talespire://dice/" + el.text.Replace(" ", "\u00a0") + ":" + text;
Debug.Log((object)("Character Sheet Plugin: Processing Via Talespire Protocol = " + text2));
Process process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = text2,
Arguments = "",
CreateNoWindow = true
}
};
process.Start();
}
else if (regex3.IsMatch(text))
{
SystemMessage.DisplayInfoText("Selected Stat Is Static Not A Roll.", 2.5f);
SystemMessage.DisplayInfoText(((el.text.Trim() != "") ? el.text.Trim() : el.roll.Replace("{", "").Replace("}", "")) + " is " + text, 2.5f);
}
else
{
SystemMessage.DisplayInfoText("Roll '" + text + "' Not Supported.", 2.5f);
}
}
catch (Exception)
{
}
}
public string MakeReplacements(CreatureGuid cid, string expandedRoll)
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
while (expandedRoll.Contains("{"))
{
string text = expandedRoll.Substring(expandedRoll.IndexOf("{") + 1);
text = text.Substring(0, text.IndexOf("}"));
Debug.Log((object)("Character Sheet: Key = " + text));
bool flag = false;
foreach (KeyValuePair<string, string> item in replacements[cid])
{
Debug.Log((object)("Character Sheet: Key = '" + text + "' vs Stat '" + item.Key + "'"));
if (item.Key == text || item.Key == "{" + text + "}")
{
expandedRoll = expandedRoll.Replace("{" + text + "}", item.Value);
flag = true;
break;
}
}
expandedRoll = expandedRoll.Replace("+-", "-").Replace("-+", "-").Replace("++", "+")
.Replace("--", "-");
Debug.Log((object)("Character Sheet Plugin: Roll = " + expandedRoll));
if (!flag)
{
break;
}
}
return expandedRoll;
}
public string Combine(string formula)
{
try
{
Debug.Log((object)("Character Sheet Plugin: Pre-Combine Roll = " + formula));
if (formula.Contains("("))
{
string text = formula.Substring(0, formula.IndexOf("(") - 1);
string text2 = formula.Substring(formula.IndexOf("("));
text2 = text2.Substring(0, text2.IndexOf(")") + 1);
string text3 = formula.Substring(formula.IndexOf(")") + 1);
Debug.Log((object)("Character Sheet Plugin: Combinable Segment = " + text2));
DataTable dataTable = new DataTable();
string text4 = Convert.ToString(dataTable.Compute(text2, null));
Debug.Log((object)("Character Sheet Plugin: Combined Segment = " + text4));
formula = formula.Replace(text2, text4);
Debug.Log((object)("Character Sheet Plugin: Combined Roll = " + formula));
}
Debug.Log((object)("Character Sheet Plugin: Post-Combine Roll = " + formula));
}
catch (Exception ex)
{
Debug.Log((object)"Character Sheet Plugin: Exception");
Debug.LogException(ex);
}
return formula;
}
public bool isBoardLoaded()
{
return SimpleSingletonBehaviour<CameraController>.HasInstance && SingletonStateMBehaviour<BoardSessionManager, State<BoardSessionManager>>.HasInstance && !BoardSessionManager.IsLoading;
}
}
public static class StateDetection
{
public static void Initialize(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 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;
}
}