Decompiled source of CrimsonChatFilter v1.0.5

CrimsonChatFilter.dll

Decompiled a week 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 System.Text.Json;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using CrimsonChatFilter.Services;
using CrimsonChatFilter.Structs;
using CrimsonChatFilter.Utils;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Network;
using ProjectM.Physics;
using ProjectM.Scripting;
using Stunlock.Core;
using Unity.Collections;
using Unity.Entities;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("CrimsonChatFilter")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Filter server chat!")]
[assembly: AssemblyFileVersion("1.0.5.0")]
[assembly: AssemblyInformationalVersion("1.0.5+Branch.master.Sha.54a6a961a2ca55d2a9841de43d0914209d201d59.54a6a961a2ca55d2a9841de43d0914209d201d59")]
[assembly: AssemblyProduct("CrimsonChatFilter")]
[assembly: AssemblyTitle("CrimsonChatFilter")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.5.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
internal static class Core
{
	private static MonoBehaviour monoBehaviour;

	public static bool _hasInitialized = false;

	public static World Server { get; } = GetWorld("Server") ?? throw new Exception("There is no Server world (yet). Did you install a server mod on the client?");


	public static EntityManager EntityManager { get; } = Server.EntityManager;


	public static GameDataSystem GameDataSystem { get; } = Server.GetExistingSystemManaged<GameDataSystem>();


	public static PrefabCollectionSystem PrefabCollectionSystem { get; internal set; }

	public static RelicDestroySystem RelicDestroySystem { get; internal set; }

	public static ServerScriptMapper ServerScriptMapper { get; internal set; }

	public static ServerGameManager ServerGameManager => ServerScriptMapper.GetServerGameManager();

	public static PlayerService PlayerService { get; internal set; }

	public static ServerGameSettingsSystem ServerGameSettingsSystem { get; internal set; }

	internal static void InitializeAfterLoaded()
	{
		if (!_hasInitialized)
		{
			PrefabCollectionSystem = Server.GetExistingSystemManaged<PrefabCollectionSystem>();
			RelicDestroySystem = Server.GetExistingSystemManaged<RelicDestroySystem>();
			ServerGameSettingsSystem = Server.GetExistingSystemManaged<ServerGameSettingsSystem>();
			ServerScriptMapper = Server.GetExistingSystemManaged<ServerScriptMapper>();
			PlayerService = new PlayerService();
			_hasInitialized = true;
		}
	}

	private static World GetWorld(string name)
	{
		Enumerator<World> enumerator = World.s_AllWorlds.GetEnumerator();
		while (enumerator.MoveNext())
		{
			World current = enumerator.Current;
			if (current.Name == name)
			{
				return current;
			}
		}
		return null;
	}

	public static Coroutine StartCoroutine(IEnumerator routine)
	{
		//IL_0012: 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)
		//IL_0027: Expected O, but got Unknown
		if ((Object)(object)monoBehaviour == (Object)null)
		{
			GameObject val = new GameObject("CrimsonShards");
			monoBehaviour = (MonoBehaviour)(object)val.AddComponent<IgnorePhysicsDebugSystem>();
			Object.DontDestroyOnLoad((Object)val);
		}
		return monoBehaviour.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(routine));
	}

	public static void StopCoroutine(Coroutine coroutine)
	{
		if (!((Object)(object)monoBehaviour == (Object)null))
		{
			monoBehaviour.StopCoroutine(coroutine);
		}
	}
}
namespace CrimsonChatFilter
{
	public static class ECSExtensions
	{
		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 = Core.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 = Core.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_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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)
			EntityManager entityManager = Core.Server.EntityManager;
			return ((EntityManager)(ref entityManager)).GetBuffer<T>(entity, 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 = Core.EntityManager;
			return ((EntityManager)(ref entityManager)).HasComponent(entity, val);
		}

		public static string LookupName(this PrefabGUID prefabGuid)
		{
			//IL_0011: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			PrefabCollectionSystem existingSystemManaged = Core.Server.GetExistingSystemManaged<PrefabCollectionSystem>();
			object obj;
			if (!existingSystemManaged.PrefabGuidToNameDictionary.ContainsKey(prefabGuid))
			{
				obj = "GUID Not Found";
			}
			else
			{
				string text = existingSystemManaged.PrefabGuidToNameDictionary[prefabGuid];
				PrefabGUID val = prefabGuid;
				obj = text + " " + ((object)(PrefabGUID)(ref val)).ToString();
			}
			return obj.ToString();
		}

		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 = Core.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 = Core.EntityManager;
			((EntityManager)(ref entityManager)).RemoveComponent(entity, val);
		}

		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;
		}
	}
	[BepInPlugin("CrimsonChatFilter", "CrimsonChatFilter", "1.0.5")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		private Harmony _harmony;

		public static readonly string ConfigFiles = Path.Combine(Paths.ConfigPath, "CrimsonChatFilter");

		public static bool LogLoaded = false;

		public static bool BanLoaded = false;

		public static Plugin Instance { get; private set; }

		public static Harmony Harmony => Instance._harmony;

		public static Settings Settings { get; private set; }

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

		public override void Load()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			Instance = this;
			Settings = default(Settings);
			Database.InitFiltered("filtered_words");
			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>("CrimsonChatFilter");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.5");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log.LogInfo(val);
			_harmony = new Harmony("CrimsonChatFilter");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			foreach (KeyValuePair<string, PluginInfo> plugin in ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins)
			{
				BepInPlugin metadata = plugin.Value.Metadata;
				if (metadata.GUID.Equals("CrimsonLog"))
				{
					LogLoaded = true;
				}
				else if (metadata.GUID.Equals("CrimsonBanned"))
				{
					BanLoaded = true;
				}
			}
			Settings.InitConfig();
		}

		public static void AddLog(string message, bool console = false)
		{
			if (LogLoaded && !console)
			{
				Type type = Type.GetType("CrimsonLog.Systems.Logger, CrimsonLog");
				if (type != null)
				{
					type.GetMethod("Record").Invoke(null, new object[3]
					{
						"Chat/Filter",
						"filter",
						message + "\n"
					});
					return;
				}
			}
			LogInstance.LogInfo((object)message);
		}

		public override bool Unload()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			return true;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "CrimsonChatFilter";

		public const string PLUGIN_NAME = "CrimsonChatFilter";

		public const string PLUGIN_VERSION = "1.0.5";
	}
}
namespace CrimsonChatFilter.Utils
{
	internal static class FilterString
	{
		public static List<string> FilteredWords;

		private static string addressFilter = ".[0-9]+[0-9][0-9].[0-9]+[0-9][0-9].[0-9]+[0-9][0-9].[0-9]+[0-9][0-9]*";

		private static string domainFilter = "\\bhttp:\\/\\/([^\\/]*)\\/([^\\s]*)";

		public static string Filter(this string input)
		{
			if (Settings.FILTER_URLS.Value)
			{
				input = Regex.Replace(input, addressFilter, "****", RegexOptions.IgnoreCase);
				input = Regex.Replace(input, domainFilter, "****", RegexOptions.IgnoreCase);
			}
			foreach (string filteredWord in FilteredWords)
			{
				string pattern = CreateRegexPattern(filteredWord);
				input = Regex.Replace(input, pattern, "****", RegexOptions.IgnoreCase);
			}
			return input;
		}

		public static bool ContainsFiltered(this string input)
		{
			if (Settings.FILTER_URLS.Value)
			{
				if (Regex.IsMatch(input, addressFilter))
				{
					return true;
				}
				if (Regex.IsMatch(input, domainFilter))
				{
					return true;
				}
			}
			foreach (string filteredWord in FilteredWords)
			{
				string pattern = CreateRegexPattern(filteredWord);
				if (Regex.IsMatch(input, pattern, RegexOptions.IgnoreCase))
				{
					return true;
				}
			}
			return false;
		}

		private static string CreateRegexPattern(string word)
		{
			string text = Regex.Escape(word).Replace("\\*", ".*");
			return "\\b" + text + "\\b";
		}
	}
}
namespace CrimsonChatFilter.Structs
{
	public class Database
	{
		private static Database INSTANCE;

		public string FilteredPath { get; set; }

		public Database(string _path, string _db)
		{
			FilteredPath = Path.Combine(_path, _db + ".json");
		}

		public static void InitFiltered(string db)
		{
			INSTANCE = new Database(Path.Combine(Paths.ConfigPath, "CrimsonChatFilter"), db);
			if (File.Exists(INSTANCE.FilteredPath))
			{
				FilterString.FilteredWords = JsonSerializer.Deserialize<List<string>>(File.ReadAllText(INSTANCE.FilteredPath));
			}
		}
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	public readonly struct Settings
	{
		public static readonly string CONFIG_PATH = Path.Combine(Paths.ConfigPath, "CrimsonChatFilter");

		private static readonly List<string> OrderedSections = new List<string> { "Config", "AutoMod" };

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

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

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

		public static void InitConfig()
		{
			WriteConfig();
			ENABLE_MOD = InitConfigEntry(OrderedSections[0], "EnableMod", defaultValue: true, "Enable or disable chat filtering");
			FULL_REMOVE = InitConfigEntry(OrderedSections[0], "FullRemove", defaultValue: false, "If enabled, others won't see the message, otherwise replaces filtered words with ****");
			FILTER_URLS = InitConfigEntry(OrderedSections[0], "FilterURLs", defaultValue: true, "Includes .com and server addresses in filter list");
			ReorderConfigSections();
		}

		public static void WriteConfig()
		{
			if (!Directory.Exists(CONFIG_PATH))
			{
				Directory.CreateDirectory(CONFIG_PATH);
			}
			if (!File.Exists(Path.Combine(CONFIG_PATH, "filtered_words.json")))
			{
				string contents = JsonSerializer.Serialize(GenerateTemplate(), new JsonSerializerOptions
				{
					WriteIndented = true
				});
				File.WriteAllText(Path.Combine(CONFIG_PATH, "filtered_words.json"), contents);
			}
		}

		private static List<string> GenerateTemplate()
		{
			return new List<string> { "coon", "jim crow", "nigger", "gook", "chink", "towelhead", "honky", "beaner", "spic" };
		}

		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, "CrimsonChatFilter.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 ReorderConfigSections()
		{
			string path = Path.Combine(Paths.ConfigPath, "CrimsonChatFilter.cfg");
			if (!File.Exists(path))
			{
				return;
			}
			List<string> list = File.ReadAllLines(path).ToList();
			Dictionary<string, List<string>> dictionary = new Dictionary<string, List<string>>();
			string text = "";
			foreach (string item in list)
			{
				if (item.StartsWith("["))
				{
					text = item.Trim('[', ']');
					dictionary[text] = new List<string> { item };
				}
				else if (!string.IsNullOrWhiteSpace(text))
				{
					dictionary[text].Add(item);
				}
			}
			using StreamWriter streamWriter = new StreamWriter(path, append: false);
			foreach (string orderedSection in OrderedSections)
			{
				if (!dictionary.ContainsKey(orderedSection))
				{
					continue;
				}
				foreach (string item2 in dictionary[orderedSection])
				{
					streamWriter.WriteLine(item2);
				}
				streamWriter.WriteLine();
			}
		}
	}
}
namespace CrimsonChatFilter.Services
{
	internal class PlayerService
	{
		private static readonly ComponentType[] UserComponent = (ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly(Il2CppType.Of<User>()) };

		private static readonly ComponentType[] ClanComponent = (ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly(Il2CppType.Of<ClanMemberStatus>()) };

		private static EntityQuery ActiveUsersQuery;

		private static EntityQuery AllUsersQuery;

		private static EntityQuery ClansQuery;

		public static Dictionary<string, Entity> playerCache = new Dictionary<string, Entity>();

		public PlayerService()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = Core.EntityManager;
			ActiveUsersQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery(UserComponent);
			entityManager = Core.EntityManager;
			AllUsersQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)new EntityQueryDesc[1]
			{
				new EntityQueryDesc
				{
					All = Il2CppStructArray<ComponentType>.op_Implicit(UserComponent),
					Options = (EntityQueryOptions)2
				}
			});
			entityManager = Core.EntityManager;
			ClansQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery(ClanComponent);
			Core.StartCoroutine(CacheUpdateLoop());
		}

		private static IEnumerator CacheUpdateLoop()
		{
			while (true)
			{
				yield return (object)new WaitForSeconds(60f);
				playerCache.Clear();
				playerCache = (from user in GetUsers().Select(delegate(Entity userEntity)
					{
						//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)
						//IL_0013: Unknown result type (might be due to invalid IL or missing references)
						User val = userEntity.Read<User>();
						return new
						{
							CharacterName = ((FixedString64Bytes)(ref val.CharacterName)).Value,
							Entity = userEntity
						};
					})
					group user by user.CharacterName into @group
					select @group.First()).ToDictionary(user => user.CharacterName, user => user.Entity);
			}
		}

		public static IEnumerable<Entity> GetUsers(bool includeDisabled = false)
		{
			NativeArray<Entity> userEntities = (includeDisabled ? ((EntityQuery)(ref AllUsersQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)3)) : ((EntityQuery)(ref ActiveUsersQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)3)));
			try
			{
				Enumerator<Entity> enumerator = userEntities.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					EntityManager entityManager = Core.EntityManager;
					if (((EntityManager)(ref entityManager)).Exists(current))
					{
						yield return current;
					}
				}
			}
			finally
			{
				userEntities.Dispose();
			}
		}

		public static IEnumerable<Entity> GetClans()
		{
			NativeArray<Entity> clanEntities = ((EntityQuery)(ref ClansQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)3));
			try
			{
				Enumerator<Entity> enumerator = clanEntities.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					EntityManager entityManager = Core.EntityManager;
					if (((EntityManager)(ref entityManager)).Exists(current))
					{
						yield return current;
					}
				}
			}
			finally
			{
				clanEntities.Dispose();
			}
		}

		public static Entity GetUserByName(string playerName, bool includeDisabled = false)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_0026: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			Entity val = GetUsers(includeDisabled).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;
		}

		public static Entity GetClanByName(string clanName)
		{
			//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_004d: 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_0060: 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)
			Entity val = ((IEnumerable<Entity>)(from x in GetClans()
				where x.ReadBuffer<SyncToUserBuffer>().Length > 0
				select x).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)
				ClanTeam val2 = entity.Read<ClanTeam>();
				return ((FixedString64Bytes)(ref val2.Name)).Value.ToLower() == clanName.ToLower();
			});
			if (!(val != Entity.Null))
			{
				return Entity.Null;
			}
			return val;
		}

		public static Entity GetClanByGUID(Guid clanGuid)
		{
			//IL_0007: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_0037: 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)
			Entity val = GetClans().FirstOrDefault((Func<Entity, bool>)((Entity entity) => entity.Read<ClanTeam>().ClanGuid == clanGuid));
			if (!(val != Entity.Null))
			{
				return Entity.Null;
			}
			return val;
		}
	}
}
namespace CrimsonChatFilter.Hooks
{
	[HarmonyPatch]
	public static class ChatMessageSystem_Patch
	{
		[HarmonyPatch(typeof(ChatMessageSystem), "OnUpdate")]
		[HarmonyPrefix]
		public static bool OnUpdate(ChatMessageSystem __instance)
		{
			//IL_000f: 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)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//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_002c: 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)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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)
			//IL_0045: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Invalid comparison between Unknown and I4
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: 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_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			if (!Settings.ENABLE_MOD.Value)
			{
				return true;
			}
			_ = __instance.__query_661171423_0;
			EntityQuery _query_661171423_ = __instance.__query_661171423_0;
			NativeArray<Entity> val = ((EntityQuery)(ref _query_661171423_)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			Enumerator<Entity> enumerator = val.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				EntityManager entityManager = ((ComponentSystemBase)__instance).EntityManager;
				FromCharacter componentData = ((EntityManager)(ref entityManager)).GetComponentData<FromCharacter>(current);
				entityManager = ((ComponentSystemBase)__instance).EntityManager;
				User componentData2 = ((EntityManager)(ref entityManager)).GetComponentData<User>(componentData.User);
				entityManager = ((ComponentSystemBase)__instance).EntityManager;
				ChatMessageEvent componentData3 = ((EntityManager)(ref entityManager)).GetComponentData<ChatMessageEvent>(current);
				string text = ((object)(FixedString512Bytes)(ref componentData3.MessageText)).ToString();
				if ((int)componentData3.MessageType != 5 && text.ContainsFiltered())
				{
					if (Settings.FULL_REMOVE.Value)
					{
						Plugin.AddLog($"REMOVED from {componentData2.CharacterName}: \"{text}\"");
						entityManager = ((ComponentSystemBase)__instance).EntityManager;
						((EntityManager)(ref entityManager)).DestroyEntity(current);
					}
					else
					{
						Plugin.AddLog($"CENSORED from {componentData2.CharacterName}: \"{text}\"");
						text = text.Filter();
						componentData3.MessageText = FixedString512Bytes.op_Implicit(text);
						entityManager = ((ComponentSystemBase)__instance).EntityManager;
						((EntityManager)(ref entityManager)).SetComponentData<ChatMessageEvent>(current, componentData3);
					}
				}
			}
			val.Dispose();
			return true;
		}
	}
}