Decompiled source of Mods Communicator Chat Control v0.0.1

OutwardModsCommunicatorChatControl.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using OutwardModsCommunicator.EventBus;
using OutwardModsCommunicator.Managers;
using OutwardModsCommunicatorChatControl.Events;
using OutwardModsCommunicatorChatControl.Events.Publishers;
using OutwardModsCommunicatorChatControl.Utility.Enums;
using OutwardModsCommunicatorChatControl.Utility.Helpers;
using SideLoader;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("OutwardModsCommunicatorChatControl")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OutwardModsCommunicatorChatControl")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c5450fe0-edcf-483f-b9ea-4b1ef9d36da7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace OutwardModsCommunicatorChatControl
{
	[BepInPlugin("gymmed.mods_communicator_chat_control", "Mods Communicator Chat Control", "0.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class OMCCC : BaseUnityPlugin
	{
		public const string GUID = "gymmed.mods_communicator_chat_control";

		public const string NAME = "Mods Communicator Chat Control";

		public const string VERSION = "0.0.1";

		public static string prefix = "[Mods-Communicator-Chat-Control]";

		public const string EVENTS_LISTENER_GUID = "gymmed.mods_communicator_chat_control_*";

		internal static ManualLogSource Log;

		internal void Awake()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			LogMessage("Hello world from Mods Communicator Chat Control 0.0.1!");
			new Harmony("gymmed.mods_communicator_chat_control").PatchAll();
			EventBusPublisher.SendCommands();
		}

		internal void Update()
		{
		}

		public static void LogMessage(string message)
		{
			Log.LogMessage((object)(prefix + " " + message));
		}

		public static void LogStatusMessage(string message, ChatLogStatus status = ChatLogStatus.Info)
		{
			LogMessage($"[{status}] {message}");
		}

		public static void LogSL(string message)
		{
			SL.Log(prefix + " " + message);
		}

		public static string GetProjectLocation()
		{
			return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		}
	}
}
namespace OutwardModsCommunicatorChatControl.Utility.Helpers
{
	public static class CharacterHelpers
	{
		public static Character TryToFindOtherCharacterInLobby(Character mainCharacter, string otherCharName)
		{
			//IL_002b: 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)
			Character val = null;
			foreach (PlayerSystem item in Global.Lobby.PlayersInLobby)
			{
				val = item.ControlledCharacter;
				if ((Object)(object)val != (Object)null && val.UID != mainCharacter.UID && string.Equals(otherCharName, val.Name))
				{
					return val;
				}
			}
			return null;
		}

		public static Character TryToFindOtherCharacterInLobby(Character mainCharacter)
		{
			//IL_002b: 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)
			Character val = null;
			foreach (PlayerSystem item in Global.Lobby.PlayersInLobby)
			{
				val = item.ControlledCharacter;
				if ((Object)(object)val != (Object)null && val.UID != mainCharacter.UID)
				{
					return val;
				}
			}
			return val;
		}

		public static bool IsCharacterInDistance(Character firstCharacter, Character secondCharacter, float minimumDistance)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)firstCharacter).transform.position - ((Component)secondCharacter).transform.position;
			float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
			float num = minimumDistance * minimumDistance;
			if (sqrMagnitude > num)
			{
				return false;
			}
			return true;
		}

		public static bool HasManualMovement(Character character)
		{
			CharacterControl characterControl = character.CharacterControl;
			LocalCharacterControl val = (LocalCharacterControl)(object)((characterControl is LocalCharacterControl) ? characterControl : null);
			if (val == null)
			{
				return false;
			}
			if (((Vector2)(ref ((CharacterControl)val).m_moveInput)).sqrMagnitude > 0.01f)
			{
				return true;
			}
			return false;
		}
	}
	public static class ChatHelpers
	{
		public static void SendChatLog(ChatPanel panel, string message, ChatLogStatus status = ChatLogStatus.Info)
		{
			panel.ChatMessageReceived("System", ChatLogStatusHelper.GetChatLogText(message, status));
		}

		public static void SendChatLog(Character character, string message, ChatLogStatus status = ChatLogStatus.Info)
		{
			CharacterUI characterUI = character.CharacterUI;
			if ((Object)(object)((characterUI != null) ? characterUI.ChatPanel : null) == (Object)null)
			{
				OMCCC.LogMessage("ChatHelpers@SendChatLog provided character with missing chatPanel!");
			}
			else
			{
				SendChatLog(character.CharacterUI.ChatPanel, message, status);
			}
		}

		public static void SendChatOrLog(Character character, string message, ChatLogStatus status = ChatLogStatus.Info)
		{
			CharacterUI characterUI = character.CharacterUI;
			if ((Object)(object)((characterUI != null) ? characterUI.ChatPanel : null) == (Object)null)
			{
				OMCCC.LogStatusMessage(message, status);
			}
			else
			{
				SendChatLog(character.CharacterUI.ChatPanel, message, status);
			}
		}
	}
	public static class EventArgumentParser
	{
		private static readonly HashSet<Type> WhitelistedTypes = new HashSet<Type>
		{
			typeof(string),
			typeof(int),
			typeof(float),
			typeof(bool),
			typeof(double),
			typeof(long),
			typeof(decimal),
			typeof(char)
		};

		public static bool CanParse(Type type)
		{
			if (type == null)
			{
				return false;
			}
			if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
			{
				return CanParse(Nullable.GetUnderlyingType(type));
			}
			if (WhitelistedTypes.Contains(type))
			{
				return true;
			}
			if (type.IsEnum)
			{
				return true;
			}
			if (type.IsArray)
			{
				Type elementType = type.GetElementType();
				if (elementType != null)
				{
					return WhitelistedTypes.Contains(elementType);
				}
				return false;
			}
			if (type.IsGenericType)
			{
				Type genericTypeDefinition = type.GetGenericTypeDefinition();
				if (genericTypeDefinition == typeof(IEnumerable<>) || genericTypeDefinition == typeof(List<>))
				{
					Type[] genericArguments = type.GetGenericArguments();
					if (genericArguments.Length == 1 && WhitelistedTypes.Contains(genericArguments[0]))
					{
						return true;
					}
				}
			}
			return false;
		}

		public static bool IsEventPublishable(EventDefinition eventDef, out string unsupportedParam)
		{
			unsupportedParam = null;
			object obj;
			if (eventDef == null)
			{
				obj = null;
			}
			else
			{
				EventSchema schema = eventDef.Schema;
				obj = ((schema != null) ? schema.Fields : null);
			}
			if (obj == null)
			{
				return true;
			}
			foreach (KeyValuePair<string, Type> field in eventDef.Schema.Fields)
			{
				if (!CanParse(field.Value))
				{
					unsupportedParam = field.Key;
					return false;
				}
			}
			return true;
		}

		public static bool TryParse(Type targetType, string value, out object result)
		{
			result = null;
			if (value == null)
			{
				return false;
			}
			if (targetType.IsGenericType && targetType.GetGenericTypeDefinition() == typeof(Nullable<>))
			{
				if (TryParse(Nullable.GetUnderlyingType(targetType), value, out var result2))
				{
					result = result2;
					return true;
				}
				return false;
			}
			if (targetType == typeof(string))
			{
				result = value;
				return true;
			}
			if (targetType == typeof(int))
			{
				if (int.TryParse(value, out var result3))
				{
					result = result3;
					return true;
				}
				return false;
			}
			if (targetType == typeof(float))
			{
				if (float.TryParse(value, out var result4))
				{
					result = result4;
					return true;
				}
				return false;
			}
			if (targetType == typeof(double))
			{
				if (double.TryParse(value, out var result5))
				{
					result = result5;
					return true;
				}
				return false;
			}
			if (targetType == typeof(long))
			{
				if (long.TryParse(value, out var result6))
				{
					result = result6;
					return true;
				}
				return false;
			}
			if (targetType == typeof(decimal))
			{
				if (decimal.TryParse(value, out var result7))
				{
					result = result7;
					return true;
				}
				return false;
			}
			if (targetType == typeof(bool))
			{
				switch (value.ToLowerInvariant())
				{
				case "true":
				case "1":
				case "yes":
				case "on":
					result = true;
					return true;
				case "false":
				case "0":
				case "no":
				case "off":
					result = false;
					return true;
				default:
					return false;
				}
			}
			if (targetType == typeof(char))
			{
				if (char.TryParse(value, out var result8))
				{
					result = result8;
					return true;
				}
				return false;
			}
			if (targetType.IsEnum)
			{
				try
				{
					result = Enum.Parse(targetType, value, ignoreCase: true);
					return true;
				}
				catch
				{
					return false;
				}
			}
			if (targetType.IsArray)
			{
				Type elementType = targetType.GetElementType();
				if (elementType == null)
				{
					return false;
				}
				string[] array = value.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
				Array array2 = Array.CreateInstance(elementType, array.Length);
				for (int i = 0; i < array.Length; i++)
				{
					if (!TryParse(elementType, array[i], out var result9))
					{
						return false;
					}
					array2.SetValue(result9, i);
				}
				result = array2;
				return true;
			}
			if (targetType.IsGenericType)
			{
				Type[] genericArguments = targetType.GetGenericArguments();
				if (genericArguments.Length == 1 && WhitelistedTypes.Contains(genericArguments[0]))
				{
					Type type = genericArguments[0];
					string[] array3 = value.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
					IList list = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(type));
					for (int j = 0; j < array3.Length; j++)
					{
						if (!TryParse(type, array3[j], out var result10))
						{
							return false;
						}
						list.Add(result10);
					}
					result = list;
					return true;
				}
			}
			return false;
		}
	}
	public static class EventBusHelpers
	{
		public static IReadOnlyDictionary<string, Dictionary<string, EventDefinition>> GetRegisteredEvents()
		{
			return EventBus.GetRegisteredEvents();
		}

		public static bool TryGetEvent(string modNamespace, string eventName, out EventDefinition eventDef)
		{
			eventDef = null;
			IReadOnlyDictionary<string, Dictionary<string, EventDefinition>> registeredEvents = GetRegisteredEvents();
			if (registeredEvents == null)
			{
				return false;
			}
			if (!registeredEvents.TryGetValue(modNamespace, out var value))
			{
				return false;
			}
			return value.TryGetValue(eventName, out eventDef);
		}

		public static bool TryFindEvent(string eventName, out string foundNamespace, out EventDefinition eventDef)
		{
			eventDef = null;
			foundNamespace = null;
			IReadOnlyDictionary<string, Dictionary<string, EventDefinition>> registeredEvents = GetRegisteredEvents();
			if (registeredEvents == null)
			{
				return false;
			}
			foreach (KeyValuePair<string, Dictionary<string, EventDefinition>> item in registeredEvents)
			{
				if (item.Value.TryGetValue(eventName, out eventDef))
				{
					foundNamespace = item.Key;
					return true;
				}
			}
			return false;
		}

		public static void SendEventNotFound(ChatPanel panel, string modNamespace, string eventName)
		{
			ChatHelpers.SendChatLog(panel, "Event '" + eventName + "' not found in mod '" + modNamespace + "'", ChatLogStatus.Error);
		}

		public static void SendModNotFound(ChatPanel panel, string modNamespace)
		{
			ChatHelpers.SendChatLog(panel, "Mod '" + modNamespace + "' not found", ChatLogStatus.Error);
		}

		public static void SendMissingParams(ChatPanel panel)
		{
			ChatHelpers.SendChatLog(panel, "Missing --mod or --event parameter. Usage: /event --mod=<namespace> --event=<name>", ChatLogStatus.Warning);
		}

		public static void SendEventInfo(ChatPanel panel, string modNamespace, string eventName, EventDefinition eventDef)
		{
			ChatHelpers.SendChatLog(panel, modNamespace + "." + eventName, ChatLogStatus.Success);
			string text = (string.IsNullOrEmpty(eventDef.Description) ? "(no description)" : eventDef.Description);
			ChatHelpers.SendChatLog(panel, "Description: " + text);
			if (eventDef.Schema.Fields.Count > 0)
			{
				ChatHelpers.SendChatLog(panel, "Parameters:");
				{
					foreach (KeyValuePair<string, Type> field in eventDef.Schema.Fields)
					{
						string text2 = eventDef.Schema.GetDescription(field.Key) ?? "(no description)";
						ChatHelpers.SendChatLog(panel, "  - " + field.Key + " (" + GetTypeName(field.Value) + "): " + text2);
					}
					return;
				}
			}
			ChatHelpers.SendChatLog(panel, "No parameters defined.");
		}

		private static string GetTypeName(Type type)
		{
			if (type == null)
			{
				return "Unknown";
			}
			if (type.IsGenericType)
			{
				string obj = type.Name.Split(new char[1] { '`' })[0];
				string text = string.Join(", ", from t in type.GetGenericArguments()
					select t.Name);
				return obj + "<" + text + ">";
			}
			return type.Name;
		}
	}
}
namespace OutwardModsCommunicatorChatControl.Utility.Enums
{
	public enum ChatCommandsManagerParams
	{
		CommandName,
		CommandParameters,
		CommandAction,
		IsCheatCommand,
		CommandDescription,
		CommandRequiresDebugMode
	}
	public static class ChatCommandsManagerParamsHelper
	{
		private static readonly Dictionary<ChatCommandsManagerParams, (string key, Type type)> _registry = new Dictionary<ChatCommandsManagerParams, (string, Type)>
		{
			[ChatCommandsManagerParams.CommandName] = ("command", typeof(string)),
			[ChatCommandsManagerParams.CommandParameters] = ("parameters", typeof(Dictionary<string, (string, string)>)),
			[ChatCommandsManagerParams.CommandAction] = ("function", typeof(Action<Character, Dictionary<string, string>>)),
			[ChatCommandsManagerParams.IsCheatCommand] = ("isCheatCommand", typeof(bool)),
			[ChatCommandsManagerParams.CommandDescription] = ("description", typeof(string)),
			[ChatCommandsManagerParams.CommandRequiresDebugMode] = ("debugMode", typeof(bool))
		};

		public static (string key, Type type) Get(ChatCommandsManagerParams param)
		{
			return _registry[param];
		}
	}
	public enum ChatLogStatus
	{
		Info,
		Success,
		Warning,
		Error
	}
	public static class ChatLogStatusHelper
	{
		public static string GetChatLogText(string message, ChatLogStatus status = ChatLogStatus.Info)
		{
			//IL_0019: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			return status switch
			{
				ChatLogStatus.Success => Global.SetTextColor(message, Global.LIGHT_GREEN), 
				ChatLogStatus.Warning => Global.SetTextColor(message, Global.LIGHT_ORANGE), 
				ChatLogStatus.Error => "<color=#" + UnityEngineExtensions.ToHex(Global.LIGHT_RED) + ">" + message + "</color>", 
				_ => message, 
			};
		}
	}
}
namespace OutwardModsCommunicatorChatControl.Managers
{
	public class PathsManager
	{
		private static PathsManager _instance;

		public string configPath = "";

		public string xmlFilePath = "";

		public static PathsManager Instance
		{
			get
			{
				if (_instance == null)
				{
					_instance = new PathsManager();
				}
				return _instance;
			}
		}

		private PathsManager()
		{
			configPath = Path.Combine(PathsManager.ConfigPath, "Chat_Commands_Template");
			xmlFilePath = Path.Combine(configPath, "MyDocument.xml");
		}
	}
}
namespace OutwardModsCommunicatorChatControl.Events
{
	public static class EventBusPublisher
	{
		public const string Event_AddCommand = "ChatCommandsManager@AddChatCommand";

		public const string Event_RemoveCommand = "ChatCommandsManager@RemoveChatCommand";

		public const string ChatCommands_Listener = "gymmed.chat_commands_manager_*";

		public static void SendCommands()
		{
			ListEventsPublisher.SendListEventsCommand();
			GetEventPublisher.SendGetEventCommand();
			PublishEventPublisher.SendPublishCommand();
		}
	}
	public static class EventBusRegister
	{
		public static void RegisterEvents()
		{
		}
	}
	public static class EventBusSubscriber
	{
		public const string Event_AddedChatCommand = "ChatCommandsManager@AddChatCommand_After";

		public const string Event_RemovedChatCommand = "ChatCommandsManager@RemoveChatCommand_After";

		public static void AddSubscribers()
		{
			EventBus.Subscribe("gymmed.chat_commands_manager_*", "ChatCommandsManager@AddChatCommand_After", (Action<EventPayload>)AddedChatCommand);
			EventBus.Subscribe("gymmed.chat_commands_manager_*", "ChatCommandsManager@RemoveChatCommand_After", (Action<EventPayload>)RemovedChatCommand);
		}

		public static void AddedChatCommand(EventPayload payload)
		{
			if (payload != null)
			{
				(string, Type) tuple = ChatCommandsManagerParamsHelper.Get(ChatCommandsManagerParams.CommandName);
				payload.Get<string>(tuple.Item1, (string)null);
				OMCCC.LogMessage("Added command " + tuple.Item1);
			}
		}

		public static void RemovedChatCommand(EventPayload payload)
		{
			if (payload != null)
			{
				(string, Type) tuple = ChatCommandsManagerParamsHelper.Get(ChatCommandsManagerParams.CommandName);
				payload.Get<string>(tuple.Item1, (string)null);
				OMCCC.LogMessage("Removed command " + tuple.Item1);
			}
		}
	}
}
namespace OutwardModsCommunicatorChatControl.Events.Publishers
{
	public static class GetEventPublisher
	{
		public static void SendGetEventCommand()
		{
			//IL_000d: 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_002a: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			//IL_009f: Expected O, but got Unknown
			Action<Character, Dictionary<string, string>> value = TriggerFunction;
			EventPayload val = new EventPayload { };
			string item;
			((Dictionary<string, object>)val)[item] = "event";
			string item2 = ChatCommandsManagerParamsHelper.Get(ChatCommandsManagerParams.CommandParameters).key;
			((Dictionary<string, object>)val)[item2] = new Dictionary<string, (string, string)>
			{
				{
					"mod",
					("Mod namespace (optional if searching all mods).", null)
				},
				{
					"event",
					("Event name to look up.", null)
				}
			};
			string item3 = ChatCommandsManagerParamsHelper.Get(ChatCommandsManagerParams.CommandAction).key;
			((Dictionary<string, object>)val)[item3] = value;
			string item4 = ChatCommandsManagerParamsHelper.Get(ChatCommandsManagerParams.CommandDescription).key;
			((Dictionary<string, object>)val)[item4] = "Gets detailed information about a specific event.";
			EventPayload val2 = val;
			EventBus.Publish("gymmed.chat_commands_manager_*", "ChatCommandsManager@AddChatCommand", val2);
		}

		public static void TriggerFunction(Character caller, Dictionary<string, string> arguments)
		{
			object obj;
			if (caller == null)
			{
				obj = null;
			}
			else
			{
				CharacterUI characterUI = caller.CharacterUI;
				obj = ((characterUI != null) ? characterUI.ChatPanel : null);
			}
			ChatPanel val = (ChatPanel)obj;
			if ((Object)(object)val == (Object)null)
			{
				OMCCC.LogMessage("GetEventPublisher@TriggerFunction: No chat panel found");
				return;
			}
			arguments.TryGetValue("mod", out var value);
			arguments.TryGetValue("event", out var value2);
			if (string.IsNullOrEmpty(value2))
			{
				EventBusHelpers.SendMissingParams(val);
				return;
			}
			EventDefinition eventDef;
			string foundNamespace;
			if (!string.IsNullOrEmpty(value))
			{
				if (!EventBusHelpers.TryGetEvent(value, value2, out eventDef))
				{
					EventBusHelpers.SendEventNotFound(val, value, value2);
					return;
				}
				foundNamespace = value;
			}
			else if (!EventBusHelpers.TryFindEvent(value2, out foundNamespace, out eventDef))
			{
				ChatHelpers.SendChatLog(val, "Event '" + value2 + "' not found in any mod", ChatLogStatus.Error);
				return;
			}
			EventBusHelpers.SendEventInfo(val, foundNamespace, value2, eventDef);
		}
	}
	public static class ListEventsPublisher
	{
		public static void SendListEventsCommand()
		{
			//IL_000d: 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_002a: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			//IL_0073: Expected O, but got Unknown
			Action<Character, Dictionary<string, string>> value = TriggerFunction;
			EventPayload val = new EventPayload { };
			string item;
			((Dictionary<string, object>)val)[item] = "events";
			string item2 = ChatCommandsManagerParamsHelper.Get(ChatCommandsManagerParams.CommandParameters).key;
			((Dictionary<string, object>)val)[item2] = new Dictionary<string, (string, string)>();
			string item3 = ChatCommandsManagerParamsHelper.Get(ChatCommandsManagerParams.CommandAction).key;
			((Dictionary<string, object>)val)[item3] = value;
			string item4 = ChatCommandsManagerParamsHelper.Get(ChatCommandsManagerParams.CommandDescription).key;
			((Dictionary<string, object>)val)[item4] = "Lists all registered events from OutwardModsCommunicator.";
			EventPayload val2 = val;
			EventBus.Publish("gymmed.chat_commands_manager_*", "ChatCommandsManager@AddChatCommand", val2);
		}

		public static void TriggerFunction(Character caller, Dictionary<string, string> arguments)
		{
			object obj;
			if (caller == null)
			{
				obj = null;
			}
			else
			{
				CharacterUI characterUI = caller.CharacterUI;
				obj = ((characterUI != null) ? characterUI.ChatPanel : null);
			}
			ChatPanel val = (ChatPanel)obj;
			if ((Object)(object)val == (Object)null)
			{
				OMCCC.LogMessage("ListEventsPublisher@TriggerFunction: No chat panel found");
				return;
			}
			IReadOnlyDictionary<string, Dictionary<string, EventDefinition>> registeredEvents = EventBusHelpers.GetRegisteredEvents();
			if (registeredEvents == null || registeredEvents.Count == 0)
			{
				ChatHelpers.SendChatLog(val, "0 events registered");
				return;
			}
			int num = registeredEvents.Values.Sum((Dictionary<string, EventDefinition> modEvents) => modEvents.Count);
			ChatHelpers.SendChatLog(val, $"{num} events registered", ChatLogStatus.Success);
			foreach (KeyValuePair<string, Dictionary<string, EventDefinition>> item in registeredEvents)
			{
				ChatHelpers.SendChatLog(val, "Mod: " + item.Key);
				foreach (KeyValuePair<string, EventDefinition> item2 in item.Value)
				{
					string key = item2.Key;
					string text = (string.IsNullOrEmpty(item2.Value.Description) ? "(no description)" : item2.Value.Description);
					ChatHelpers.SendChatLog(val, "  - " + key + ": " + text);
				}
			}
		}
	}
	public static class PublishEventPublisher
	{
		public static void SendPublishCommand()
		{
			//IL_000d: 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_002a: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			//IL_00ba: Expected O, but got Unknown
			Action<Character, Dictionary<string, string>> value = TriggerFunction;
			EventPayload val = new EventPayload { };
			string item;
			((Dictionary<string, object>)val)[item] = "publish";
			string item2 = ChatCommandsManagerParamsHelper.Get(ChatCommandsManagerParams.CommandParameters).key;
			((Dictionary<string, object>)val)[item2] = new Dictionary<string, (string, string)>
			{
				{
					"mod",
					("Mod namespace (optional if searching all mods).", null)
				},
				{
					"event",
					("Event name.", null)
				}
			};
			string item3 = ChatCommandsManagerParamsHelper.Get(ChatCommandsManagerParams.CommandAction).key;
			((Dictionary<string, object>)val)[item3] = value;
			string item4 = ChatCommandsManagerParamsHelper.Get(ChatCommandsManagerParams.CommandDescription).key;
			((Dictionary<string, object>)val)[item4] = "Publishes an event to OutwardModsCommunicator. Requires debug mode.";
			string item5 = ChatCommandsManagerParamsHelper.Get(ChatCommandsManagerParams.CommandRequiresDebugMode).key;
			((Dictionary<string, object>)val)[item5] = true;
			EventPayload val2 = val;
			EventBus.Publish("gymmed.chat_commands_manager_*", "ChatCommandsManager@AddChatCommand", val2);
		}

		public static void TriggerFunction(Character caller, Dictionary<string, string> arguments)
		{
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			object obj;
			if (caller == null)
			{
				obj = null;
			}
			else
			{
				CharacterUI characterUI = caller.CharacterUI;
				obj = ((characterUI != null) ? characterUI.ChatPanel : null);
			}
			ChatPanel val = (ChatPanel)obj;
			if ((Object)(object)val == (Object)null)
			{
				OMCCC.LogMessage("PublishEventPublisher@TriggerFunction: No chat panel found");
				return;
			}
			arguments.TryGetValue("mod", out var value);
			arguments.TryGetValue("event", out var value2);
			if (string.IsNullOrEmpty(value2))
			{
				SendUsageError(val);
				return;
			}
			EventDefinition eventDef;
			string foundNamespace;
			if (!string.IsNullOrEmpty(value))
			{
				if (!EventBusHelpers.TryGetEvent(value, value2, out eventDef))
				{
					ChatHelpers.SendChatLog(val, "Event '" + value2 + "' not found in mod '" + value + "'", ChatLogStatus.Error);
					return;
				}
				foundNamespace = value;
			}
			else if (!EventBusHelpers.TryFindEvent(value2, out foundNamespace, out eventDef))
			{
				ChatHelpers.SendChatLog(val, "Event '" + value2 + "' not found in any mod", ChatLogStatus.Error);
				return;
			}
			EventPayload val2 = new EventPayload();
			List<string> list = new List<string>();
			EventSchema schema = eventDef.Schema;
			Dictionary<string, Type>.KeyCollection source = ((schema == null) ? null : schema.Fields?.Keys) ?? new Dictionary<string, Type>().Keys;
			foreach (KeyValuePair<string, string> argument in arguments)
			{
				string key = argument.Key;
				string value3 = argument.Value;
				if (!(key == "mod") && !(key == "event") && source.Contains(key))
				{
					Type type = eventDef.Schema.Fields[key];
					if (EventArgumentParser.TryParse(type, value3, out var result))
					{
						((Dictionary<string, object>)(object)val2)[key] = result;
						continue;
					}
					list.Add("Cannot parse '" + value3 + "' for parameter '" + key + "' as " + type.Name);
				}
			}
			if (list.Count > 0)
			{
				foreach (string item in list)
				{
					ChatHelpers.SendChatLog(val, item, ChatLogStatus.Error);
				}
				return;
			}
			EventBus.Publish(foundNamespace, value2, val2);
			ChatHelpers.SendChatLog(val, "Published event '" + foundNamespace + "." + value2 + "'", ChatLogStatus.Success);
		}

		private static void SendUsageError(ChatPanel panel)
		{
			ChatHelpers.SendChatLog(panel, "Missing --event parameter. Usage: /publish <mod> <event> [--param=value...]", ChatLogStatus.Warning);
		}
	}
}