Decompiled source of ChatWhisper v1.5.0

ChatWhisperPlugin.dll

Decompiled 8 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Talespire;
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("ChatWhisperPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ChatWhisperPlugin")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("ChatWhisperPlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("1.5.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.5.0.0")]
namespace LordAshes;

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

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

	public const string Version = "1.5.0.0";

	private static ConfigEntry<string> whisperIdentifier;

	private static ConfigEntry<bool> logDiagnostics;

	private void Awake()
	{
		Debug.Log((object)"Chat Whisper Plugin: Active.");
		whisperIdentifier = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "Whisper message suffix", "<size=16>(Whisper)</size>", (ConfigDescription)null);
		logDiagnostics = ((BaseUnityPlugin)this).Config.Bind<bool>("Troubleshooting", "Log extra diagnostic information", false, (ConfigDescription)null);
		ChatMessageService.AddHandler("/w ", (Func<string, string, SourceRole, string>)delegate(string chatMessage, string sender, SourceRole source)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			if (chatMessage.StartsWith("/w"))
			{
				chatMessage = chatMessage.Substring(2).Trim() + " ";
				string text2 = chatMessage.Substring(0, chatMessage.IndexOf(" "));
				text2 = text2.Replace("\u00a0", " ");
				if (text2 == ".")
				{
					text2 = CampaignSessionManager.GetPlayerName(LocalPlayer.Id);
				}
				if (text2 == ".." || text2.ToUpper() == "GM")
				{
					text2 = FindGMs()[0];
				}
				if (!isValidPlayerName(text2) && isSelf(sender))
				{
					SystemMessage.DisplayInfoText("Chat Whisper Plugin:\r\nInvalid Whisper Name\r\n" + text2, 2.5f);
					return null;
				}
				chatMessage = chatMessage.Substring(chatMessage.IndexOf(" ") + 1);
				Debug.Log((object)("Chat Whisper Plugin: Whisper From '" + sender + "' To '" + text2 + "' (Received By '" + CampaignSessionManager.GetPlayerName(LocalPlayer.Id) + "')"));
				if (CampaignSessionManager.GetPlayerName(LocalPlayer.Id).ToUpper() != text2.ToUpper())
				{
					return null;
				}
				chatMessage += whisperIdentifier.Value;
			}
			return chatMessage;
		});
		ChatMessageService.AddHandler("/w! ", (Func<string, string, SourceRole, string>)delegate(string chatMessage, string sender, SourceRole source)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			if (chatMessage.StartsWith("/w!"))
			{
				chatMessage = chatMessage.Substring(3).Trim() + " ";
				string text = chatMessage.Substring(0, chatMessage.IndexOf(" "));
				if (text == ".")
				{
					text = CampaignSessionManager.GetPlayerName(LocalPlayer.Id);
				}
				if (text == ".." || text.ToUpper() == "GM")
				{
					text = FindGMs()[0];
				}
				if (!isValidPlayerName(text) && isSelf(sender))
				{
					SystemMessage.DisplayInfoText("Chat Whisper Plugin:\r\nInvalid Whisper Name\r\n" + text, 2.5f);
					return null;
				}
				chatMessage = chatMessage.Substring(chatMessage.IndexOf(" ") + 1);
				Debug.Log((object)("Chat Whisper Plugin: Whisper From '" + sender + "' To Everyone But '" + text + "' (Received By '" + CampaignSessionManager.GetPlayerName(LocalPlayer.Id) + "')"));
				if (CampaignSessionManager.GetPlayerName(LocalPlayer.Id).ToUpper() == text.ToUpper())
				{
					return null;
				}
				chatMessage += whisperIdentifier.Value;
			}
			return chatMessage;
		});
	}

	public static List<string> FindGMs()
	{
		//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_002e: 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_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Invalid comparison between Unknown and I4
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		List<string> list = new List<string>();
		ClientMode val = default(ClientMode);
		foreach (PlayerGuid key in CampaignSessionManager.PlayersInfo.Keys)
		{
			List<ClientGuid> list2 = new List<ClientGuid>();
			if (!BoardSessionManager.PlayersClientsGuids.TryGetValue(key, ref list2))
			{
				continue;
			}
			int count = list2.Count;
			for (int i = 0; i < count; i++)
			{
				if (BoardSessionManager.ClientsModes.TryGetValue(list2[i], ref val) && (int)val == 2)
				{
					list.Add(CampaignSessionManager.GetPlayerName(key));
				}
			}
		}
		return (list.Count > 0) ? list : new List<string> { "None" };
	}

	public static bool isValidPlayerName(string name)
	{
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: 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)
		//IL_0025: 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_0031: Unknown result type (might be due to invalid IL or missing references)
		if (logDiagnostics.Value)
		{
			foreach (PlayerGuid key in CampaignSessionManager.PlayersInfo.Keys)
			{
				Debug.Log((object)("Chat Whisper Plugin: Available Whisper Name '" + CampaignSessionManager.GetPlayerName(key) + "'"));
			}
		}
		foreach (PlayerGuid key2 in CampaignSessionManager.PlayersInfo.Keys)
		{
			if (CampaignSessionManager.GetPlayerName(key2).ToUpper() == name.ToUpper())
			{
				if (logDiagnostics.Value)
				{
					Debug.Log((object)("Chat Whisper Plugin: Player Name '" + name + "' Found"));
				}
				return true;
			}
		}
		if (logDiagnostics.Value)
		{
			Debug.Log((object)("Chat Whisper Plugin: Player Name '" + name + "' Not Found"));
		}
		return false;
	}

	public static bool isSelf(string sender)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_021a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0221: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		if (logDiagnostics.Value)
		{
			Debug.Log((object)("Chat Whisper Plugin: Sender = " + GetCreatureName(sender)));
		}
		if (CampaignSessionManager.GetPlayerName(LocalPlayer.Id).ToUpper() == GetCreatureName(sender).ToUpper())
		{
			if (logDiagnostics.Value)
			{
				Debug.Log((object)("Chat Whisper Plugin: Sender = " + GetCreatureName(sender) + ", Player = " + CampaignSessionManager.GetPlayerName(LocalPlayer.Id) + ", Is Sender = True"));
			}
			return true;
		}
		if (logDiagnostics.Value)
		{
			Debug.Log((object)("Chat Whisper Plugin: Sender = " + GetCreatureName(sender) + ", Player = " + CampaignSessionManager.GetPlayerName(LocalPlayer.Id) + ", Is Sender = False"));
		}
		foreach (CreatureBoardAsset item in (IEnumerable<CreatureBoardAsset>)CreaturePresenter.GetTempReadOnlyViewOfAllCreatureAssets())
		{
			if (GetCreatureName(item.Name) == GetCreatureName(sender) && CreatureManager.ClientHasControlOfCreature(LocalClient.Id, item.CreatureId))
			{
				if (logDiagnostics.Value)
				{
					Debug.Log((object)("Chat Whisper Plugin: Sender = " + GetCreatureName(sender) + ", Creature = " + GetCreatureName(item.Name) + ", Is Owned = " + CreatureManager.ClientHasControlOfCreature(LocalClient.Id, item.CreatureId) + ", Is Sender = True"));
				}
				return true;
			}
			if (logDiagnostics.Value)
			{
				Debug.Log((object)("Chat Whisper Plugin: Sender = " + GetCreatureName(sender) + ", Creature = " + GetCreatureName(item.Name) + ", Is Owned = " + CreatureManager.ClientHasControlOfCreature(LocalClient.Id, item.CreatureId) + ", Is Sender = False"));
			}
		}
		if (logDiagnostics.Value)
		{
			Debug.Log((object)("Chat Whisper Plugin: Sender = " + GetCreatureName(sender) + ", Is Sender = False"));
		}
		return false;
	}

	public static string GetCreatureName(string name)
	{
		if (name.IndexOf("<") > -1)
		{
			name = name.Substring(0, name.IndexOf("<"));
		}
		return name.Trim();
	}
}