Decompiled source of ChatService v2.9.0

ChatServicePlugin.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using Bounce.ManagedCollections;
using Bounce.Singletons;
using Bounce.Unmanaged;
using Dice;
using GameChat.UI;
using HarmonyLib;
using Newtonsoft.Json;
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("ChatServicePlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ChatServicePlugin")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("ChatServicePlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("2.9.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("2.9.0.0")]
namespace LordAshes;

[BepInPlugin("org.lordashes.plugins.chatservice", "Chat Service Plug-In", "2.9.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class ChatServicePlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(UIChatMessageManager), "AddChatMessage")]
	public static class PatchAddChatMessage
	{
		public static bool Prefix(ref string creatureName, Texture2D icon, ref string chatMessage, IChatFocusable focus = null)
		{
			LoggingPlugin.LogDebug("Chat Service Plugin: AddEventMessage Patch");
			string text = creatureName;
			ApplyAliases(ref chatMessage);
			ProcessMessage(ref creatureName, ref chatMessage);
			if (chatMessage == null || (chatMessage.Trim() == "" && creatureName == text))
			{
				return false;
			}
			if (logFileNamePrefix.Value.Trim() != "")
			{
				LogChatMessage(creatureName, chatMessage);
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(UIChatMessageManager), "AddEventMessage")]
	public static class PatchAddEventMessage
	{
		public static bool Prefix(ref string title, ref string message, IChatFocusable focus = null)
		{
			LoggingPlugin.LogDebug("Chat Service Plugin: AddEventMessage Patch");
			string text = title;
			ApplyAliases(ref message);
			ProcessMessage(ref title, ref message);
			if (message == null || (message.Trim() == "" && title == text))
			{
				return false;
			}
			if (logFileNamePrefix.Value.Trim() != "")
			{
				LogEventMessage(title, message);
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(UIChatMessageManager), "AddDiceResultMessage")]
	public static class PatchAddDiceResultMessage
	{
		public static bool Prefix(RollResults diceResult, ResultsOrigin origin, ClientGuid sender, bool hidden, IChatFocusable focus = null)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (logFileNamePrefix.Value.Trim() != "")
			{
				LogDiceResult(diceResult, sender, hidden);
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(ChatInputBoardTool), "Begin")]
	public static class PatchBegin
	{
		public static void Postfix()
		{
			LoggingPlugin.LogDebug("Chat Service Plugin: Chat Entry Begin Prefix");
			SetSpeaker();
		}
	}

	[HarmonyPatch(typeof(CreatureBoardAsset), "Speak")]
	public static class PatchSpeak
	{
		public static bool Prefix(string text)
		{
			return !CheckIfHandlersApply(text);
		}
	}

	public static class PatchAssistant
	{
		public static object GetProperty(object instance, string propertyName)
		{
			Type type = instance.GetType();
			foreach (PropertyInfo runtimeProperty in type.GetRuntimeProperties())
			{
				if (runtimeProperty.Name.Contains(propertyName))
				{
					return runtimeProperty.GetValue(instance);
				}
			}
			PropertyInfo[] properties = type.GetProperties();
			foreach (PropertyInfo propertyInfo in properties)
			{
				if (propertyInfo.Name.Contains(propertyName))
				{
					return propertyInfo.GetValue(instance);
				}
			}
			return null;
		}

		public static void SetProperty(object instance, string propertyName, object value)
		{
			Type type = instance.GetType();
			foreach (PropertyInfo runtimeProperty in type.GetRuntimeProperties())
			{
				if (runtimeProperty.Name.Contains(propertyName))
				{
					runtimeProperty.SetValue(instance, value);
					return;
				}
			}
			PropertyInfo[] properties = type.GetProperties();
			foreach (PropertyInfo propertyInfo in properties)
			{
				if (propertyInfo.Name.Contains(propertyName))
				{
					propertyInfo.SetValue(instance, value);
					break;
				}
			}
		}

		public static object GetField(object instance, string fieldName)
		{
			Type type = instance.GetType();
			foreach (FieldInfo runtimeField in type.GetRuntimeFields())
			{
				if (runtimeField.Name.Contains(fieldName))
				{
					return runtimeField.GetValue(instance);
				}
			}
			FieldInfo[] fields = type.GetFields();
			foreach (FieldInfo fieldInfo in fields)
			{
				if (fieldInfo.Name.Contains(fieldName))
				{
					return fieldInfo.GetValue(instance);
				}
			}
			return null;
		}

		public static void SetField(object instance, string fieldName, object value)
		{
			Type type = instance.GetType();
			foreach (FieldInfo runtimeField in type.GetRuntimeFields())
			{
				if (runtimeField.Name.Contains(fieldName))
				{
					runtimeField.SetValue(instance, value);
					return;
				}
			}
			FieldInfo[] fields = type.GetFields();
			foreach (FieldInfo fieldInfo in fields)
			{
				if (fieldInfo.Name.Contains(fieldName))
				{
					fieldInfo.SetValue(instance, value);
					break;
				}
			}
		}

		public static object UseMethod(object instance, string methodName, object[] parameters)
		{
			Type type = instance.GetType();
			foreach (MethodInfo runtimeMethod in type.GetRuntimeMethods())
			{
				if (runtimeMethod.Name.Contains(methodName))
				{
					return runtimeMethod.Invoke(instance, parameters);
				}
			}
			MethodInfo[] methods = type.GetMethods();
			foreach (MethodInfo methodInfo in methods)
			{
				if (methodInfo.Name.Contains(methodName))
				{
					return methodInfo.Invoke(instance, parameters);
				}
			}
			return null;
		}
	}

	public enum ChatSource
	{
		gm = 0,
		player = 1,
		creature = 2,
		hideVolume = 3,
		other = 888,
		anonymous = 999
	}

	public enum DiagnosticSelection
	{
		none = 0,
		low = 1,
		high = 2,
		ultra = 999,
		debug = 999
	}

	public static class ChatMessageService
	{
		public static void AddHandler(string key, Func<string, string, SourceRole, string> callback)
		{
			LoggingPlugin.LogDebug("Chat Service Plugin: Added Subscription To " + key);
			chatMessgeServiceHandlers.Add(key, callback);
		}

		public static void RemoveHandler(string key)
		{
			LoggingPlugin.LogDebug("Chat Service Plugin: Removed Subscription To " + key);
			chatMessgeServiceHandlers.Remove(key);
		}

		public static bool CheckHandler(string key)
		{
			LoggingPlugin.LogDebug("Chat Service Plugin: Check If Handler '" + key + "' Is Registered");
			return chatMessgeServiceHandlers.ContainsKey(key);
		}

		public static void SendMessage(string message, NGuid source)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			LoggingPlugin.LogDebug("Chat Service Plugin: Sending " + message + " (signature " + ((object)(NGuid)(ref source)).ToString() + ")");
			ChatManager.SendChatMessageToBoard(message, source, (float3?)null, false);
		}
	}

	public static class SDIM
	{
		public enum InvokeResult
		{
			success,
			missingFile,
			missingMethod,
			invalidParameters
		}

		public static object InvokeReturn;

		public static InvokeResult InvokeMethod(string pluginFile, string methodName, object[] parameters)
		{
			InvokeReturn = null;
			Type type = FindPlugin(pluginFile);
			if (type == null)
			{
				LoggingPlugin.LogWarning("Chat Service Plugin: SDIM: Missing File. Ignorning Soft Dependency Functionality.");
				return InvokeResult.missingFile;
			}
			MethodInfo method = type.GetMethod(methodName);
			if (method == null)
			{
				LoggingPlugin.LogWarning("Chat Service Plugin: SDIM: Missing Method. Ignorning Soft Dependency Functionality.");
				return InvokeResult.missingMethod;
			}
			try
			{
				InvokeReturn = method.Invoke(null, parameters);
				return InvokeResult.success;
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("Chat Service Plugin: SDIM: Failed Invoke: " + ex?.ToString() + ". Ignorning Soft Dependency Functionality."));
				return InvokeResult.invalidParameters;
			}
		}

		private static Type FindPlugin(string pluginFile)
		{
			LoggingPlugin.LogDebug("Chat Service Plugin: SDIM: Looking For " + Paths.PluginPath + "/" + pluginFile);
			if (File.Exists(Paths.PluginPath + "/" + pluginFile))
			{
				Assembly assembly = Assembly.LoadFrom(Paths.PluginPath + "/" + pluginFile);
				LoggingPlugin.LogTrace("Chat Service Plugin: SDIM: Assembly = " + Convert.ToString(assembly));
				if (assembly == null)
				{
					return null;
				}
				Type[] types = assembly.GetTypes();
				foreach (Type type in types)
				{
					LoggingPlugin.LogTrace("Chat Service Plugin: SDIM: Seeking 'BaseUnityPlugin' Type. Found '" + type.ToString() + "'. IsSubclassOf = " + type.IsSubclassOf(typeof(BaseUnityPlugin)));
					if (type.IsSubclassOf(typeof(BaseUnityPlugin)))
					{
						return type;
					}
				}
			}
			else
			{
				LoggingPlugin.LogDebug("Chat Service Plugin: SDIM: " + Paths.PluginPath + "/" + pluginFile + " Not Installed");
			}
			return null;
		}
	}

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

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

		public static GameObject GetBaseLoader(CreatureGuid cid)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				CreatureBoardAsset val = null;
				CreaturePresenter.TryGetAsset(cid, ref val);
				if ((Object)(object)val != (Object)null)
				{
					Transform match = null;
					Traverse(((Component)val).transform, "BaseLoader", 0, 10, ref match);
					if ((Object)(object)match != (Object)null)
					{
						Debug.Log((object)("Log Chat Plugin: Base Loader '" + ((Object)match.GetChild(0)).name + "' Found"));
						return ((Component)match.GetChild(0)).gameObject;
					}
					Debug.LogWarning((object)"Log Chat 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)("Log Chat Plugin: Asset Loader '" + ((Object)match.GetChild(0)).name + "' Found"));
						return ((Component)match.GetChild(0)).gameObject;
					}
					Debug.LogWarning((object)"Log Chat 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 const string Name = "Chat Service Plug-In";

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

	public const string Version = "2.9.0.0";

	public const string Author = "Lord Ashes";

	private static Dictionary<string, Func<string, string, SourceRole, string>> chatMessgeServiceHandlers = new Dictionary<string, Func<string, string, SourceRole, string>>();

	private static object padlock = new object();

	private static string logFileName = "";

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

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

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

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

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

	private static ConfigEntry<bool> logFileUseTimestamps { get; set; }

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

	private static void ApplyAliases(ref string message)
	{
		foreach (KeyValuePair<string, string> alias in aliases)
		{
			LoggingPlugin.LogTrace("Chat Service Plugin: ApplyAliases: Replacing '" + alias.Key + "' with '" + alias.Value + "'");
			message = message.Replace("/" + alias.Key, "/" + alias.Value);
		}
		LoggingPlugin.LogDebug("Chat Service Plugin: ApplyAliases: Alias Message = '" + message + "'");
	}

	private static void ProcessMessage(ref string title, ref string message)
	{
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		string name = title;
		LoggingPlugin.LogTrace("Chat Service Plugin: ParseMessage: Title = '" + Convert.ToString(title) + "' Message = '" + Convert.ToString(message) + "'");
		if (message.StartsWith("[") && message.Contains("]"))
		{
			title = message.Substring(1);
			title = title.Substring(0, title.IndexOf("]"));
			message = message.Substring(message.IndexOf("]") + 1).Trim();
			LoggingPlugin.LogTrace("Chat Service Plugin: ParseMessage: Header Adjustment: Title = '" + Convert.ToString(title) + "' Message = '" + Convert.ToString(message) + "'");
		}
		bool flag;
		do
		{
			flag = false;
			foreach (KeyValuePair<string, Func<string, string, SourceRole, string>> chatMessgeServiceHandler in chatMessgeServiceHandlers)
			{
				LoggingPlugin.LogTrace("Chat Service Plugin: ParseMessage: Found Handler '" + chatMessgeServiceHandler.Key + "'");
				if (message.StartsWith(chatMessgeServiceHandler.Key))
				{
					LoggingPlugin.LogTrace("Chat Service Plugin: ParseMessage: Applying Handler '" + chatMessgeServiceHandler.Key + "'");
					try
					{
						message = chatMessgeServiceHandler.Value(message, title, FindSource(name));
					}
					catch (Exception ex)
					{
						Debug.LogWarning((object)("Chat Service Plugin: ParseMessage: Exception In Handler: " + ex.Message));
						Debug.LogException(ex);
						message = "";
					}
					LoggingPlugin.LogTrace("Chat Service Plugin: ParseMessage: Post Handler: Title = '" + Convert.ToString(title) + "' Message = '" + Convert.ToString(message) + "'");
					if (message == null || message.Trim() == "")
					{
						return;
					}
					flag = true;
					break;
				}
			}
		}
		while (flag);
	}

	private static bool CheckIfHandlersApply(string message)
	{
		foreach (KeyValuePair<string, Func<string, string, SourceRole, string>> chatMessgeServiceHandler in chatMessgeServiceHandlers)
		{
			LoggingPlugin.LogTrace("Chat Service Plugin: CheckIfHandlersApply: Handler: '" + chatMessgeServiceHandler.Key + "'");
			if (message.StartsWith(chatMessgeServiceHandler.Key))
			{
				LoggingPlugin.LogTrace("Chat Service Plugin: CheckIfHandlersApply: Message Uses '" + chatMessgeServiceHandler.Key + "' Handler");
				return true;
			}
		}
		LoggingPlugin.LogTrace("Chat Service Plugin: CheckIfHandlersApply: Message Does Not Use Any Handler");
		return false;
	}

	private static SourceRole FindSource(string name)
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: 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_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		if (name == null || name == "" || name.ToUpper() == "ANONYMOUS")
		{
			return (SourceRole)999;
		}
		foreach (CreatureBoardAsset item in (IEnumerable<CreatureBoardAsset>)CreaturePresenter.GetTempReadOnlyViewOfAllCreatureAssets())
		{
			try
			{
				if ((Object)(object)item != (Object)null && item.Name != null && item.Name.StartsWith(name))
				{
					return (SourceRole)2;
				}
			}
			catch
			{
			}
		}
		foreach (KeyValuePair<PlayerGuid, PlayerInfo> item2 in CampaignSessionManager.PlayersInfo)
		{
			try
			{
				if (CampaignSessionManager.GetPlayerName(item2.Key) == name)
				{
					if (item2.Value.Rights.CanGm)
					{
						return (SourceRole)0;
					}
					return (SourceRole)1;
				}
			}
			catch
			{
			}
		}
		return (SourceRole)888;
	}

	private void Awake()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Expected O, but got Unknown
		//IL_0206: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0216: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0232: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Expected O, but got Unknown
		//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d3: Invalid comparison between Unknown and I4
		LoggingPlugin.SetLogLevel(((BaseUnityPlugin)this).Config.Bind<DiagnosticLevel>("Settings", "Log Diagnostic Level", (DiagnosticLevel)3, (ConfigDescription)null).Value);
		string[] obj2 = new string[5]
		{
			"Chat Service Plugin: ",
			((object)this).GetType().AssemblyQualifiedName,
			" Active. (Diagnostics=",
			null,
			null
		};
		DiagnosticLevel logLevel = LoggingPlugin.GetLogLevel();
		obj2[3] = ((object)(DiagnosticLevel)(ref logLevel)).ToString();
		obj2[4] = ")";
		LoggingPlugin.LogInfo(string.Concat(obj2));
		timestampStyle = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "Timestamp Style", "font-size: 8pt; font-weight: normal; background-color: #454545;", (ConfigDescription)null);
		headerStyle = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "Header Style", "font-size: 16pt; font-weight: bold; background-color: #555555;", (ConfigDescription)null);
		contentStyle = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "Content Style", "font-size: 12pt; font-weight: normal; background-color: #656565;", (ConfigDescription)null);
		logFileNamePrefix = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "Chat Log File Name (Or Empty For Off)", "", (ConfigDescription)null);
		logFileUseTimestamps = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Use Timestamp Log Filenames", true, (ConfigDescription)null);
		ignoreChatServicesList = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "List Of Chat Services To Not Log", "/org.lordashes.plugins.assetdata|", (ConfigDescription)null);
		if (logFileNamePrefix.Value.Trim() != "")
		{
			logFileName = logFileNamePrefix.Value.Trim() + (logFileUseTimestamps.Value ? ("_" + DateTime.UtcNow.ToString("yyyy.MM.dd_HH.mm.ss")) : "") + ".html";
			LoggingPlugin.LogDebug("Chat Service Plugin: Chat Log using " + logFileName);
			File.WriteAllText(logFileName, "<HTML>\r\n  <BODY>\r\n");
		}
		Harmony val = new Harmony("org.lordashes.plugins.chatservice");
		val.PatchAll();
		if (!((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Add Deselect Option", true, (ConfigDescription)null).Value)
		{
			return;
		}
		LoggingPlugin.LogTrace("Chat Service Plugin: Creating Deselect Character Menu Option.");
		ItemArgs val2 = new ItemArgs
		{
			Title = "Deselect",
			Icon = Image.LoadSprite("Deselect.png", (CacheType)999),
			CloseMenuOnActivate = true,
			Action = delegate
			{
				//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_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
				LoggingPlugin.LogTrace("Chat Service Plugin: Deselecting All Assets");
				foreach (CreatureBoardAsset item in (IEnumerable<CreatureBoardAsset>)CreaturePresenter.GetTempReadOnlyViewOfAllCreatureAssets())
				{
					item.Deselect();
				}
				LoggingPlugin.LogTrace("Chat Service Plugin: Updating LocalClient SelectedCreatureId");
				PropertyInfo[] properties = typeof(LocalClient).GetProperties();
				foreach (PropertyInfo propertyInfo in properties)
				{
					if (propertyInfo.Name == "SelectedCreatureId")
					{
						LoggingPlugin.LogTrace("Chat Service Plugin: Found SelectedCreatureId. Updating...");
						propertyInfo.SetValue(null, (object)default(CreatureGuid));
					}
					else
					{
						LoggingPlugin.LogTrace("Chat Service Plugin: Found '" + propertyInfo.Name + "'");
					}
				}
				LoggingPlugin.LogTrace("Chat Service Plugin: Updating ChatInputBoardTool _selectedCreature");
				ChatInputBoardTool instance = Object.FindObjectOfType<ChatInputBoardTool>();
				try
				{
					PatchAssistant.SetField(instance, "_selectedCreature", null);
				}
				catch
				{
				}
				SetSpeaker();
			}
		};
		if (SDIM.InvokeMethod("HolloFox_TS-RadialUIPlugin/RadialUI.dll", "AddCustomButtonOnCharacter", new object[3] { "org.lordashes.plugins.chatservice", val2, null }) == SDIM.InvokeResult.success)
		{
			LoggingPlugin.LogDebug("Chat Service Plugin: Adding Deselect Character Menu Option.");
		}
		else
		{
			LoggingPlugin.LogDebug("Chat Service Plugin: RadialUI Plugin Not Available");
		}
		if (!File.Exists("Chat_Service_Aliases.json"))
		{
			return;
		}
		aliases = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText("Chat_Service_Aliases.json", (CacheType)999));
		if ((int)LoggingPlugin.GetLogLevel() < 4)
		{
			return;
		}
		foreach (KeyValuePair<string, string> alias in aliases)
		{
			LoggingPlugin.LogDebug("Chat Service Plugin: Adding Alias '/" + alias.Key + "' => '/" + alias.Value + "'");
		}
	}

	public static void SetSpeaker()
	{
		//IL_000f: 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_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Expected O, but got Unknown
		try
		{
			string text = "Someone";
			CreatureBoardAsset val = null;
			LoggingPlugin.LogTrace("Chat Service Plugin: Selected Characeter = " + Convert.ToString(LocalClient.SelectedCreatureId));
			CreaturePresenter.TryGetAsset(LocalClient.SelectedCreatureId, ref val);
			if ((Object)(object)val != (Object)null)
			{
				LoggingPlugin.LogTrace("Chat Service Plugin: Setting Speaker Via Character Name");
				text = val.Name;
				if (text.Contains("<"))
				{
					text = text.Substring(0, text.IndexOf("<"));
				}
			}
			else
			{
				LoggingPlugin.LogTrace("Chat Service Plugin: Setting Speaker Via Player Name");
				text = CampaignSessionManager.GetPlayerName(LocalPlayer.Id);
			}
			ChatInputBoardTool val2 = Object.FindObjectOfType<ChatInputBoardTool>();
			if ((Object)(object)val2 != (Object)null)
			{
				UIChatInputField val3 = (UIChatInputField)PatchAssistant.GetField(val2, "_input");
				if ((Object)(object)val3 != (Object)null)
				{
					val3.UpdateSpeaker(text);
					LoggingPlugin.LogDebug("Chat Service Plugin: Speaker Set To " + text);
				}
			}
		}
		catch (Exception)
		{
		}
	}

	public static void LogChatMessage(string creatureName, string chatMessage, string directive = "")
	{
		if (chatMessage.Trim() != "")
		{
			string text = "    <DIV Width=480 Style=\"Width: 480px; border-style: solid;\">\r\n";
			text = text + "      <DIV Width=480 Id=Header Style=\"Width: 480px;" + timestampStyle.Value + "\">&nbsp;&nbsp;&nbsp;" + DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss") + "</DIV>\r\n";
			text = text + "      <DIV Width=480 Id=Header Style=\"Width: 480px;" + headerStyle.Value + "\">&nbsp;&nbsp;&nbsp;" + creatureName + "</DIV>\r\n";
			if (directive != "")
			{
				text = text + "      <DIV Width=480 Id=Header Style=\"Width: 480px;" + timestampStyle.Value + "\">&nbsp;&nbsp;&nbsp;Operation: " + directive + "</DIV>\r\n";
			}
			text = text + "      <DIV Width=480 Id=Content Style=\"Width: 480px;" + contentStyle.Value + "\">&nbsp;&nbsp;&nbsp;" + chatMessage + "</DIV>\r\n";
			text += "    </DIV><BR>\r\n";
			lock (padlock)
			{
				File.AppendAllText(logFileName, text);
			}
		}
	}

	public static void LogEventMessage(string title, string message, string directive = "")
	{
		if (message.Trim() != "")
		{
			string text = "    <DIV Width=480 Style=\"Width: 480px; border-style: solid;\">\r\n";
			text = text + "      <DIV Width=480 Id=Header Style=\"Width: 480px;" + timestampStyle.Value + "\">&nbsp;&nbsp;&nbsp;" + DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss") + "</DIV>\r\n";
			text = text + "      <DIV Width=480 Id=Header Style=\"Width: 480px;" + headerStyle.Value + "\">&nbsp;&nbsp;&nbsp;" + title + "</DIV>\r\n";
			if (directive != "")
			{
				text = text + "      <DIV Width=480 Id=Header Style=\"Width: 480px;" + timestampStyle.Value + "\">&nbsp;&nbsp;&nbsp;Operation: " + directive + "</DIV>\r\n";
			}
			text = text + "      <DIV Width=480 Id=Content Style=\"Width: 480px;" + contentStyle.Value + "\">&nbsp;&nbsp;&nbsp;" + message + "</DIV>\r\n";
			text += "    </DIV><BR>\r\n";
			lock (padlock)
			{
				File.AppendAllText(logFileName, text);
			}
		}
	}

	public static void LogDiceResult(RollResults diceResult, ClientGuid sender, bool hidden)
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: 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)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: 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_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		//IL_022e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		string text = "";
		int num = 0;
		int num2 = 0;
		int num3 = 0;
		int num4 = 0;
		int num5 = 0;
		int num6 = 0;
		PlayerGuid val = default(PlayerGuid);
		int num7 = default(int);
		BoardSessionManager.ClientsPlayerGuids.TryGetValueIndex(sender, ref val, ref num7);
		string text2 = "    <DIV Width=480 Style=\"Width: 480px; border-style: solid;\">\r\n";
		text2 = text2 + "      <DIV Width=480 Id=Header Style=\"Width: 480px;" + timestampStyle.Value + "\">&nbsp;&nbsp;&nbsp;" + DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss") + "</DIV>\r\n";
		text2 = text2 + "      <DIV Width=480 Id=Header Style=\"Width: 480px;" + headerStyle.Value + "\">&nbsp;&nbsp;&nbsp;" + CampaignSessionManager.GetPlayerName(val) + "</DIV>\r\n";
		int num8 = 0;
		Enumerator<RollGroup> enumerator = diceResult.ResultsGroups.GetEnumerator();
		try
		{
			RollOperation val2 = default(RollOperation);
			RollResult val3 = default(RollResult);
			RollValue val4 = default(RollValue);
			while (enumerator.MoveNext())
			{
				RollGroup current = enumerator.Current;
				num8++;
				num = 0;
				num2 = 0;
				num3 = 0;
				num4 = 0;
				if (current.Name != null && Convert.ToString(current.Name).Trim() != "")
				{
					text2 = text2 + "      <DIV Width=480 Id=Header Style=\"Width: 480px;" + headerStyle.Value + "\">&nbsp;&nbsp;&nbsp;" + current.Name + "</DIV>\r\n";
				}
				((RollOperand)(ref current.Result)).Get(ref val2, ref val3, ref val4);
				num4 = (((int)val2.Operator == 0) ? 1 : (-1));
				num5 = 0;
				Enumerator<RollOperand> enumerator2 = val2.Operands.GetEnumerator();
				try
				{
					while (enumerator2.MoveNext())
					{
						RollOperand current2 = enumerator2.Current;
						((RollOperand)(ref current2)).Get(ref val2, ref val3, ref val4);
						if (((DieKind)(ref val3.Kind)).RegisteredName == "<unknown>")
						{
							num3 = val4.Value * num4;
							continue;
						}
						num = val3.Results.Length;
						num2 = int.Parse(((DieKind)(ref val3.Kind)).RegisteredName.Substring(1));
						text = num + "D" + num2 + "{#}=[";
						Enumerator<short> enumerator3 = val3.Results.GetEnumerator();
						try
						{
							while (enumerator3.MoveNext())
							{
								short current3 = enumerator3.Current;
								text = text + current3 + ",";
								num5 += current3;
							}
						}
						finally
						{
							((IDisposable)enumerator3).Dispose();
						}
						text = text.Substring(0, text.Length - 1) + "]";
					}
				}
				finally
				{
					((IDisposable)enumerator2).Dispose();
				}
				num5 += num3;
				num6 += num5;
				text = text.Replace("{#}", ((num3 >= 0) ? "+" : "") + num3);
				text2 = text2 + "      <DIV Width=480 Id=Header Style=\"Width: 480px;" + contentStyle.Value + "\">&nbsp;&nbsp;&nbsp;" + text + "=" + num5 + "</DIV>\r\n";
			}
		}
		finally
		{
			((IDisposable)enumerator).Dispose();
		}
		if (num8 > 1)
		{
			text2 = text2 + "      <DIV Width=480 Id=Header Style=\"Width: 480px;" + contentStyle.Value + "\">&nbsp;&nbsp;&nbsp;<B>Total: " + num6 + "</b></DIV>\r\n";
		}
		text2 += "    </DIV><BR>\r\n";
		lock (padlock)
		{
			File.AppendAllText(logFileName, text2);
		}
	}
}

plugins/SourceRole.dll

Decompiled a month ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("SourceRole")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SourceRole")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("08b45a92-bf19-40cb-9712-436e153d8fcf")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Talespire;

public enum SourceRole
{
	gm = 0,
	player = 1,
	creature = 2,
	hideVolume = 3,
	other = 888,
	anonymous = 999
}