Decompiled source of CrimsonFAQ v1.0.0

CrimsonFAQ.dll

Decompiled 2 months ago
using System;
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 System.Text.Json;
using System.Text.Json.Serialization;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Bloodstone.API;
using Bloodstone.Hooks;
using CrimsonFAQ.Services;
using CrimsonFAQ.Structs;
using CrimsonFAQ.Systems;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Network;
using Unity.Collections;
using Unity.Entities;
using VampireCommandFramework;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("CrimsonFAQ")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("AutoResponder System")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+Branch.master.Sha.7b664d606f014f9d9b2ebc9d964db91fd3b1d076")]
[assembly: AssemblyProduct("CrimsonFAQ")]
[assembly: AssemblyTitle("CrimsonFAQ")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace CrimsonFAQ
{
	public static class ECSExtensions
	{
		private static EntityManager EntityManager => VWorld.Server.EntityManager;

		public unsafe static void Write<T>(this Entity entity, T componentData) where T : struct
		{
			//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_0039: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			byte[] array = StructureToByteArray(componentData);
			int num = Marshal.SizeOf<T>();
			fixed (byte* ptr = array)
			{
				EntityManager entityManager = EntityManager;
				((EntityManager)(ref entityManager)).SetComponentDataRaw(entity, val.TypeIndex, (void*)ptr, num);
			}
		}

		public static byte[] StructureToByteArray<T>(T structure) where T : struct
		{
			int num = Marshal.SizeOf(structure);
			byte[] array = new byte[num];
			IntPtr intPtr = Marshal.AllocHGlobal(num);
			Marshal.StructureToPtr(structure, intPtr, fDeleteOld: true);
			Marshal.Copy(intPtr, array, 0, num);
			Marshal.FreeHGlobal(intPtr);
			return array;
		}

		public unsafe static T Read<T>(this Entity entity) where T : struct
		{
			//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_0015: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = EntityManager;
			return Marshal.PtrToStructure<T>(new IntPtr(((EntityManager)(ref entityManager)).GetComponentDataRawRO(entity, val.TypeIndex)));
		}

		public static DynamicBuffer<T> ReadBuffer<T>(this Entity entity) where T : struct
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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)
			EntityManager entityManager = EntityManager;
			return ((EntityManager)(ref entityManager)).GetBuffer<T>(entity, false);
		}

		public static bool TryGetComponent<T>(this Entity entity, out T componentData) where T : struct
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			componentData = default(T);
			if (entity.Has<T>())
			{
				componentData = entity.Read<T>();
				return true;
			}
			return false;
		}

		public static bool Has<T>(this Entity entity)
		{
			//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_0015: 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)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = EntityManager;
			return ((EntityManager)(ref entityManager)).HasComponent(entity, val);
		}

		public static void Add<T>(this Entity entity)
		{
			//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_0015: 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)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = EntityManager;
			((EntityManager)(ref entityManager)).AddComponent(entity, val);
		}

		public static void Remove<T>(this Entity entity)
		{
			//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_0015: 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)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = EntityManager;
			((EntityManager)(ref entityManager)).RemoveComponent(entity, val);
		}
	}
	[BepInPlugin("CrimsonFAQ", "CrimsonFAQ", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin, IRunOnInitialized
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static ChatEventHandler <>9__23_0;

			internal void <Load>b__23_0(VChatEvent x)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Invalid comparison between Unknown and I4
				if ((int)x.Type != 5 && Settings.FAQ.Value)
				{
					Responder.Respond(x);
				}
			}
		}

		private Harmony _harmony;

		internal static Plugin Instance { get; private set; }

		public static Settings Settings { get; private set; }

		public static Harmony Harmony => Instance._harmony;

		public static ManualLogSource LogInstance => ((BasePlugin)Instance).Log;

		public static Database DB { get; internal set; }

		public static PlayerService PlayerService { get; private set; }

		public static string ConfigFiles => Path.Combine(Paths.ConfigPath, "CrimsonFAQ");

		public override void Load()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			Instance = this;
			Settings = default(Settings);
			Settings.InitConfig();
			if (!VWorld.IsServer)
			{
				((BasePlugin)this).Log.LogWarning((object)"This plugin is a server-only plugin");
			}
			_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			CommandRegistry.RegisterAll();
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("CrimsonFAQ");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log.LogInfo(val);
			DB = new Database();
			object obj = <>c.<>9__23_0;
			if (obj == null)
			{
				ChatEventHandler val2 = delegate(VChatEvent x)
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					//IL_0007: Invalid comparison between Unknown and I4
					if ((int)x.Type != 5 && Settings.FAQ.Value)
					{
						Responder.Respond(x);
					}
				};
				<>c.<>9__23_0 = val2;
				obj = (object)val2;
			}
			Chat.OnChatMessage += (ChatEventHandler)obj;
		}

		public override bool Unload()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			return true;
		}

		public void OnGameInitialized()
		{
			if (!VWorld.IsClient)
			{
				PlayerService = new PlayerService();
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "CrimsonFAQ";

		public const string PLUGIN_NAME = "CrimsonFAQ";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace CrimsonFAQ.Systems
{
	public class Database
	{
		public static string ResponsesFile = Path.Combine(Plugin.ConfigFiles, "responses.json");

		public static string TrustedFile = Path.Combine(Plugin.ConfigFiles, "trusted.json");

		public List<KeyResponse> Responses { get; set; }

		public List<string> Trusted { get; set; }

		public Database()
		{
			CreateDatabaseFiles();
			LoadDatabase();
		}

		public bool LoadDatabase()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			try
			{
				string json = File.ReadAllText(ResponsesFile);
				Responses = JsonSerializer.Deserialize<List<KeyResponse>>(json);
				ManualLogSource logInstance = Plugin.LogInstance;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(36, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Loaded Responses Database: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(Responses.Count);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" entries.");
				}
				logInstance.LogInfo(val);
				string json2 = File.ReadAllText(TrustedFile);
				Trusted = JsonSerializer.Deserialize<List<string>>(json2);
				ManualLogSource logInstance2 = Plugin.LogInstance;
				val = new BepInExInfoLogInterpolatedStringHandler(34, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Loaded Trusted Database: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(Trusted.Count);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" entries.");
				}
				logInstance2.LogInfo(val);
				return true;
			}
			catch (Exception ex)
			{
				Plugin.LogInstance.LogError((object)ex);
				return false;
			}
		}

		public void SaveDatabase()
		{
			string contents = JsonSerializer.Serialize(Trusted);
			File.WriteAllText(TrustedFile, contents);
		}

		public static void CreateDatabaseFiles()
		{
			if (!File.Exists(ResponsesFile))
			{
				List<KeyResponse> list = new List<KeyResponse>();
				KeyResponse item = new KeyResponse("discord", "Join our discord at discord.gg/RBPesMj", "discord link", isGlobal: true, 0, 30);
				list.Add(item);
				string contents = JsonSerializer.Serialize(list, new JsonSerializerOptions
				{
					WriteIndented = true
				});
				File.WriteAllText(ResponsesFile, contents);
			}
			if (!File.Exists(TrustedFile))
			{
				string contents2 = JsonSerializer.Serialize(new List<string>(), new JsonSerializerOptions
				{
					WriteIndented = true
				});
				File.WriteAllText(TrustedFile, contents2);
			}
		}

		public bool GetResponse(string key, out KeyResponse response)
		{
			response = null;
			if (Responses.Exists((KeyResponse x) => string.Equals(x.Key, key, StringComparison.OrdinalIgnoreCase)))
			{
				response = Responses.Find((KeyResponse x) => string.Equals(x.Key, key, StringComparison.OrdinalIgnoreCase));
				return true;
			}
			return false;
		}

		public bool IsTrusted(User user, int keyLevel)
		{
			//IL_0004: 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)
			if (keyLevel == 1 && (user.IsAdmin || Trusted.Contains(user.PlatformId.ToString())))
			{
				return true;
			}
			if (keyLevel == 2 && user.IsAdmin)
			{
				return true;
			}
			return false;
		}

		public bool AddTrusted(User user)
		{
			if (Trusted.Contains(user.PlatformId.ToString()))
			{
				return false;
			}
			Trusted.Add(user.PlatformId.ToString());
			SaveDatabase();
			return true;
		}

		public bool RemoveTrusted(User user)
		{
			if (!Trusted.Contains(user.PlatformId.ToString()))
			{
				return false;
			}
			Trusted.Remove(user.PlatformId.ToString());
			SaveDatabase();
			return true;
		}
	}
	public static class Responder
	{
		public static void Respond(VChatEvent message)
		{
			//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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			if (!message.Message.StartsWith(Settings.Prefix.Value))
			{
				return;
			}
			string key = message.Message.TrimStart(Settings.Prefix.Value[0]);
			if (!Plugin.DB.GetResponse(key, out var response))
			{
				return;
			}
			EntityManager entityManager = VWorld.Server.EntityManager;
			User val = message.SenderUserEntity.Read<User>();
			if (response.PermissionLevel > 0)
			{
				if (Plugin.DB.IsTrusted(val, response.PermissionLevel))
				{
					ServerChatUtils.SendSystemMessageToAllClients(entityManager, $"<color={Settings.HexResponse.Value}>{response.Response}</color>");
					response.GlobalLastUsed = DateTime.Now;
				}
			}
			else if (response.IsGlobal)
			{
				if ((DateTime.Now - response.GlobalLastUsed).TotalSeconds > (double)response.GlobalCooldownSeconds)
				{
					ServerChatUtils.SendSystemMessageToAllClients(entityManager, $"<color={Settings.HexResponse.Value}>{response.Response}</color>");
					response.GlobalLastUsed = DateTime.Now;
				}
				else
				{
					ServerChatUtils.SendSystemMessageToClient(entityManager, val, $"<color={Settings.HexResponse.Value}>{response.Response}</color>");
					message.Cancel();
				}
			}
			else
			{
				ServerChatUtils.SendSystemMessageToClient(entityManager, val, $"<color={Settings.HexResponse.Value}>{response.Response}</color>");
				message.Cancel();
			}
		}
	}
}
namespace CrimsonFAQ.Structs
{
	public class KeyResponse
	{
		[JsonPropertyName("Key")]
		public string Key { get; set; }

		[JsonPropertyName("Response")]
		public string Response { get; set; }

		[JsonPropertyName("Description")]
		public string Description { get; set; }

		[JsonPropertyName("IsGlobal")]
		public bool IsGlobal { get; set; }

		[JsonPropertyName("PermissionLevel")]
		public int PermissionLevel { get; set; }

		[JsonPropertyName("GlobalCooldownSeconds")]
		public int GlobalCooldownSeconds { get; set; }

		[JsonIgnore]
		public DateTime GlobalLastUsed { get; set; }

		public KeyResponse()
		{
			GlobalLastUsed = DateTime.MinValue;
		}

		[JsonConstructor]
		public KeyResponse(string key, string response, string description, bool isGlobal = false, int permissionLevel = 0, int globalCooldownSeconds = 0)
		{
			Key = key;
			Response = response;
			Description = description;
			IsGlobal = isGlobal;
			PermissionLevel = permissionLevel;
			GlobalCooldownSeconds = globalCooldownSeconds;
			GlobalLastUsed = DateTime.MinValue;
		}
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	public readonly struct Settings
	{
		private static readonly List<string> directoryPaths = new List<string> { Plugin.ConfigFiles };

		public static ConfigEntry<bool> FAQ { get; private set; }

		public static ConfigEntry<string> Prefix { get; private set; }

		public static ConfigEntry<string> HexKey { get; private set; }

		public static ConfigEntry<string> HexDescription { get; private set; }

		public static ConfigEntry<string> HexMisc { get; private set; }

		public static ConfigEntry<string> HexResponse { get; private set; }

		public static void InitConfig()
		{
			foreach (string directoryPath in directoryPaths)
			{
				CreateDirectories(directoryPath);
			}
			FAQ = InitConfigEntry("_Config", "FAQEnable", defaultValue: true, "Enable or disable the mod.");
			Prefix = InitConfigEntry("_Config", "Prefix", "?", "The prefix before information requests i.e. \"?discord\"");
			HexKey = InitConfigEntry("Response Colors", "KeyColor", "#9cb730", "The hex value color that will be displayed for keys in .faq list");
			HexDescription = InitConfigEntry("Response Colors", "DescriptionColor", "#309CB7", "The hex value color that will be displayed for descriptions in .faq list");
			HexMisc = InitConfigEntry("Response Colors", "MiscColor", "#b7309c", "The hex value color that will be used for formatting elements like the dash in .faq list");
			HexResponse = InitConfigEntry("Response Colors", "ResponseColor", "#9cb730", "The hex value color that will be used for responding to user key queries");
		}

		private static ConfigEntry<T> InitConfigEntry<T>(string section, string key, T defaultValue, string description)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			ConfigEntry<T> val = ((BasePlugin)Plugin.Instance).Config.Bind<T>(section, key, defaultValue, description);
			string text = Path.Combine(Paths.ConfigPath, "CrimsonFAQ.cfg");
			ConfigEntry<T> val2 = default(ConfigEntry<T>);
			if (File.Exists(text) && new ConfigFile(text, true).TryGetEntry<T>(section, key, ref val2))
			{
				val.Value = val2.Value;
			}
			return val;
		}

		private static void CreateDirectories(string path)
		{
			if (!Directory.Exists(path))
			{
				Directory.CreateDirectory(path);
			}
		}
	}
}
namespace CrimsonFAQ.Services
{
	public class PlayerService
	{
		private static readonly ComponentType[] UserComponent = (ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly(Il2CppType.Of<User>()) };

		private static EntityQuery ActiveUsersQuery;

		private static EntityQuery AllUsersQuery;

		public PlayerService()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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)
			//IL_0020: 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_0038: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = VWorld.Server.EntityManager;
			AllUsersQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)new EntityQueryDesc[1]
			{
				new EntityQueryDesc
				{
					All = Il2CppStructArray<ComponentType>.op_Implicit(UserComponent),
					Options = (EntityQueryOptions)2
				}
			});
			entityManager = VWorld.Server.EntityManager;
			ActiveUsersQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery(UserComponent);
		}

		public static IEnumerable<Entity> GetUsers(bool includeDisabled = false)
		{
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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_002e: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_0055: 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)
			List<Entity> list = new List<Entity>();
			bool flag = default(bool);
			try
			{
				NativeArray<Entity> val = (includeDisabled ? ((EntityQuery)(ref AllUsersQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)3)) : ((EntityQuery)(ref ActiveUsersQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)3)));
				try
				{
					Enumerator<Entity> enumerator = val.GetEnumerator();
					while (enumerator.MoveNext())
					{
						Entity current = enumerator.Current;
						EntityManager entityManager = VWorld.Server.EntityManager;
						if (((EntityManager)(ref entityManager)).Exists(current))
						{
							list.Add(current);
							continue;
						}
						ManualLogSource logInstance = Plugin.LogInstance;
						BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(39, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Entity ");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(current.Index);
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" does not exist in EntityManager");
						}
						logInstance.LogWarning(val2);
					}
					return list;
				}
				finally
				{
					val.Dispose();
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logInstance2 = Plugin.LogInstance;
				BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(19, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Error in GetUsers: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message);
				}
				logInstance2.LogError(val3);
				ManualLogSource logInstance3 = Plugin.LogInstance;
				val3 = new BepInExErrorLogInterpolatedStringHandler(13, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Stack trace: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.StackTrace);
				}
				logInstance3.LogError(val3);
				return Enumerable.Empty<Entity>();
			}
		}

		public static Entity GetUserByName(string playerName, bool includeDisabled = false)
		{
			//IL_0024: 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_003d: 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)
			Entity val = ((IEnumerable<Entity>)GetUsers(includeDisabled).ToList()).FirstOrDefault((Func<Entity, bool>)delegate(Entity entity)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//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)
				User val2 = entity.Read<User>();
				return ((FixedString64Bytes)(ref val2.CharacterName)).Value.ToLower() == playerName.ToLower();
			});
			if (!(val != Entity.Null))
			{
				return Entity.Null;
			}
			return val;
		}
	}
}
namespace CrimsonFAQ.Commands
{
	[CommandGroup("faq", null)]
	internal class Basic
	{
		[Command("list", "l", null, "shows the list of FAQ requests that can be queried", null, false)]
		public void ListFAQs(ChatCommandContext ctx)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			string text = "\n";
			if (Plugin.DB.Responses.Count == 0)
			{
				text += "There are no FAQs setup on the server.";
			}
			else
			{
				foreach (KeyResponse response in Plugin.DB.Responses)
				{
					if (response.PermissionLevel <= 0 || Plugin.DB.IsTrusted(ctx.User, response.PermissionLevel))
					{
						string value = ((!string.IsNullOrEmpty(response.Description)) ? $"<color={Settings.HexMisc.Value}>-</color> <color={Settings.HexDescription.Value}>{response.Description}</color>" : "");
						text += $"<color={Settings.HexKey.Value}>{Settings.Prefix.Value}{response.Key}</color> {value}\n";
					}
				}
			}
			ctx.Reply(text);
		}

		[Command("trust", "t", null, "adds a player to the list of trusted users", null, true)]
		public void AddTrusted(ChatCommandContext ctx, string playerName = "")
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_0036: 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)
			if (string.IsNullOrEmpty(playerName))
			{
				ctx.Reply("Must input a player name.");
			}
			Entity userByName = PlayerService.GetUserByName(playerName, includeDisabled: true);
			if (!((Entity)(ref userByName)).Equals(Entity.Null) && userByName.Has<User>())
			{
				if (Plugin.DB.AddTrusted(userByName.Read<User>()))
				{
					ctx.Reply(playerName + " added to trusted FAQ users.");
				}
				else
				{
					ctx.Reply(playerName + " is already a trusted user.");
				}
			}
			else
			{
				ctx.Reply("Unable to find player named " + playerName);
			}
		}

		[Command("untrust", "ut", null, "removes a player from the list of trusted users", null, true)]
		public void RemoveTrusted(ChatCommandContext ctx, string playerName = "")
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_0036: 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)
			if (string.IsNullOrEmpty(playerName))
			{
				ctx.Reply("Must input a player name.");
			}
			Entity userByName = PlayerService.GetUserByName(playerName, includeDisabled: true);
			if (!((Entity)(ref userByName)).Equals(Entity.Null) && userByName.Has<User>())
			{
				if (Plugin.DB.RemoveTrusted(userByName.Read<User>()))
				{
					ctx.Reply(playerName + " removed from trusted FAQ users.");
				}
				else
				{
					ctx.Reply(playerName + " is not in the trusted list");
				}
			}
			else
			{
				ctx.Reply("Unable to find player named " + playerName);
			}
		}

		[Command("reload", "r", null, "reloads the FAQ KeyResponse entries from json", null, true)]
		public void ReloadJSON(ChatCommandContext ctx)
		{
			KeyResponse[] source = Plugin.DB.Responses.ToArray();
			if (Plugin.DB.LoadDatabase())
			{
				List<KeyResponse> responses = Plugin.DB.Responses;
				int num = 0;
				foreach (KeyResponse newResponse in responses)
				{
					KeyResponse keyResponse = source.FirstOrDefault((KeyResponse r) => r.Key == newResponse.Key);
					if (keyResponse == null || !keyResponse.Equals(newResponse))
					{
						num++;
					}
				}
				ctx.Reply($"{num} responses loaded.");
			}
			else
			{
				ctx.Reply("Failed to retreive a valid collection from the responses.json file, please validate your formatting and values");
			}
		}
	}
}