Decompiled source of ChatRollPlugin v2.3.0

ChatRollPlugin.dll

Decompiled 8 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using Bounce.Unmanaged;
using Talespire;
using Unity.Mathematics;
using UnityEngine;

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

[BepInPlugin("org.lordashes.plugins.chatroll", "Chat Roll Plug-In", "2.3.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class ChatRollPlugin : BaseUnityPlugin
{
	public const string Name = "Chat Roll Plug-In";

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

	public const string Version = "2.3.0.0";

	private void Awake()
	{
		Debug.Log((object)"Chat Roll Plugin: Active.");
		ChatMessageService.AddHandler("/r ", (Func<string, string, SourceRole, string>)delegate(string roll, string roller, SourceRole source)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			NGuid val4 = CheckSingleSource(roller, source);
			if (val4 != NGuid.Empty)
			{
				Dictionary<string, string> dictionary4 = ResolveRoll(roll, roller);
				string text6 = "<size=20>" + dictionary4["Roll"] + "= <size=20>(" + dictionary4["Expanded"] + ") = <size=32>" + dictionary4["Total"];
				ChatManager.SendChatMessageToBoard(text6, val4, (float3?)null, false);
			}
			return null;
		});
		ChatMessageService.AddHandler("/rn ", (Func<string, string, SourceRole, string>)delegate(string roll, string roller, SourceRole source)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			roll = roll.Substring(roll.IndexOf(" ") + 1);
			string text4 = roll.Substring(0, roll.IndexOf(" ")).Trim();
			roll = roll.Substring(roll.IndexOf(" ") + 1);
			NGuid val3 = CheckSingleSource(roller, source);
			if (val3 != NGuid.Empty)
			{
				Dictionary<string, string> dictionary3 = ResolveRoll("/r " + roll, roller);
				string text5 = "<size=32>" + text4 + ": <size=20>" + dictionary3["Roll"] + "= <size=20>(" + dictionary3["Expanded"] + ") = <size=32>" + dictionary3["Total"];
				ChatManager.SendChatMessageToBoard(text5, val3, (float3?)null, false);
			}
			return null;
		});
		ChatMessageService.AddHandler("/gr ", (Func<string, string, SourceRole, string>)delegate(string roll, string roller, SourceRole source)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			NGuid val2 = CheckSingleSource(roller, source);
			if (val2 != NGuid.Empty)
			{
				Dictionary<string, string> dictionary2 = ResolveRoll(roll, roller);
				string text3 = "/w " + CampaignSessionManager.GetPlayerName(FindGM()) + " <size=20>" + dictionary2["Roll"] + "= <size=20>(" + dictionary2["Expanded"] + ") = <size=32>" + dictionary2["Total"];
				ChatManager.SendChatMessageToBoard(text3, val2, (float3?)null, false);
			}
			return null;
		});
		ChatMessageService.AddHandler("/grn ", (Func<string, string, SourceRole, string>)delegate(string roll, string roller, SourceRole source)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			roll = roll.Substring(roll.IndexOf(" ") + 1);
			string text = roll.Substring(0, roll.IndexOf(" ")).Trim();
			roll = roll.Substring(roll.IndexOf(" ") + 1);
			NGuid val = CheckSingleSource(roller, source);
			if (val != NGuid.Empty)
			{
				Dictionary<string, string> dictionary = ResolveRoll("/r " + roll, roller);
				string text2 = "/w " + CampaignSessionManager.GetPlayerName(FindGM()) + " <size=32>" + text + ": <size=20>" + dictionary["Roll"] + "= <size=20>(" + dictionary["Expanded"] + ") = <size=32>" + dictionary["Total"];
				ChatManager.SendChatMessageToBoard(text2, val, (float3?)null, false);
			}
			return null;
		});
		((MonoBehaviour)this).StartCoroutine("CheckForWhisperImplementation");
	}

	private IEnumerator CheckForWhisperImplementation()
	{
		yield return (object)new WaitForSeconds(5f);
		if (!ChatMessageService.CheckHandler("/w "))
		{
			Debug.LogWarning((object)"Chat Roll Plugin: Missing Chat Whisper Plugin. Roll Modes /gr and /grn Will Not Function Correctly");
		}
	}

	private NGuid CheckSingleSource(string roller, SourceRole source)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: 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_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Invalid comparison between Unknown and I4
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: 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_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Invalid comparison between Unknown and I4
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		NGuid result = NGuid.Empty;
		if (roller == ".")
		{
			result = LocalPlayer.Id.Value;
		}
		else if ((int)source > 1)
		{
			if ((int)source == 2)
			{
				foreach (CreatureBoardAsset item in (IEnumerable<CreatureBoardAsset>)CreaturePresenter.GetTempReadOnlyViewOfAllCreatureAssets())
				{
					if (item.Name.StartsWith(roller))
					{
						if (LocalClient.CanControlCreature(item.CreatureId))
						{
							result = item.CreatureId.Value;
						}
						break;
					}
				}
			}
		}
		else if (CampaignSessionManager.GetPlayerName(LocalPlayer.Id) == roller)
		{
			result = LocalPlayer.Id.Value;
		}
		return result;
	}

	private Dictionary<string, string> ResolveRoll(string roll, string roller)
	{
		try
		{
			Debug.Log((object)("Roll: " + roll + " by " + roller));
			Random random = new Random();
			roll = roll.Substring(roll.IndexOf(" ") + 1).Trim();
			roll = "0+" + roll + "+0";
			roll = roll.ToUpper();
			string text = roll;
			string text2 = text;
			while (roll.Contains("D"))
			{
				int num = 0;
				int num2 = roll.IndexOf("D");
				int num3 = num2 - 1;
				int num4 = num2 + 1;
				while ("0123456789".Contains(roll.Substring(num3, 1)))
				{
					num3--;
					if (num3 == 0)
					{
						break;
					}
				}
				while ("0123456789".Contains(roll.Substring(num4, 1)))
				{
					num4++;
					if (num4 > roll.Length)
					{
						break;
					}
				}
				int num5 = int.Parse(roll.Substring(num3 + 1, num2 - (num3 + 1)));
				int num6 = int.Parse(roll.Substring(num2 + 1, num4 - (num2 + 1)));
				string text3 = "[";
				for (int i = 0; i < num5; i++)
				{
					int num7 = random.Next(1, num6 + 1);
					text3 = text3 + num7 + ",";
					num += num7;
				}
				roll = roll.Substring(0, num3 + 1) + num + roll.Substring(num4);
				text3 = text3.Substring(0, text3.Length - 1) + "]";
				int num8 = text2.IndexOf(num5 + "D" + num6);
				text2 = text2.Substring(0, num8) + text3 + text2.Substring(num8 + (num5 + "D" + num6).Length);
			}
			DataTable dataTable = new DataTable();
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			dictionary.Add("Roll", text.Substring(2).Substring(0, text.Substring(2).Length - 2));
			dictionary.Add("Total", dataTable.Compute(roll, null).ToString());
			dictionary.Add("Expanded", text2.Substring(2).Substring(0, text2.Substring(2).Length - 2));
			return dictionary;
		}
		catch (Exception ex)
		{
			Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
			dictionary2.Add("Roll", roll.Substring(2).Substring(0, roll.Substring(2).Length - 2));
			dictionary2.Add("Total", roll.Substring(2).Substring(0, roll.Substring(2).Length - 2));
			dictionary2.Add("Expanded", ex.Message);
			return dictionary2;
		}
	}

	private PlayerGuid FindGM()
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		foreach (KeyValuePair<PlayerGuid, PlayerInfo> item in CampaignSessionManager.PlayersInfo)
		{
			if (item.Value.Rights.CanGm)
			{
				return item.Key;
			}
		}
		throw new Exception("Unable To Find Player With GM Rights");
	}
}