Decompiled source of CrimsonDice v1.0.0

CrimsonDice.dll

Decompiled 4 days 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.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using CrimsonDice.Services;
using CrimsonDice.Structs;
using CrimsonDice.Utilities;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Text;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Network;
using ProjectM.Physics;
using ProjectM.Shared;
using Stunlock.Core;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
using VampireCommandFramework;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("CrimsonDice")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Roll dice in local chat to resolve disputes!")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+Branch.master.Sha.3348495444b1419e049dd62d6fbc3c82f7625b66.3348495444b1419e049dd62d6fbc3c82f7625b66")]
[assembly: AssemblyProduct("CrimsonDice")]
[assembly: AssemblyTitle("CrimsonDice")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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;
		}
	}
}
namespace CrimsonDice
{
	internal static class Core
	{
		public static bool hasInitialized = false;

		private static MonoBehaviour monoBehaviour;

		public static World Server { get; } = GetServerWorld() ?? throw new Exception("There is no Server world (yet)...");


		public static EntityManager EntityManager => Server.EntityManager;

		public static DiceService DiceService { get; internal set; }

		public static PlayerService PlayerService { get; internal set; }

		public static void Initialize()
		{
			if (!hasInitialized)
			{
				DiceService = new DiceService();
				PlayerService = new PlayerService();
				hasInitialized = true;
			}
		}

		private static World GetServerWorld()
		{
			return ((IEnumerable<World>)World.s_AllWorlds.ToArray()).FirstOrDefault((Func<World, bool>)((World world) => world.Name == "Server"));
		}

		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("CrimsonDice");
				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);
			}
		}
	}
	public static class Extensions
	{
		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;
		}

		public static void Dump(this Entity entity, string filePath)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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_004b: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			File.AppendAllText(filePath, "--------------------------------------------------" + Environment.NewLine);
			File.AppendAllText(filePath, "Dumping components of " + ((object)(Entity)(ref entity)).ToString() + ":" + Environment.NewLine);
			EntityManager entityManager = Core.Server.EntityManager;
			Enumerator<ComponentType> enumerator = ((EntityManager)(ref entityManager)).GetComponentTypes(entity, (Allocator)2).GetEnumerator();
			while (enumerator.MoveNext())
			{
				ComponentType current = enumerator.Current;
				File.AppendAllText(filePath, ((object)(ComponentType)(ref current)).ToString() + Environment.NewLine);
			}
			File.AppendAllText(filePath, "--------------------------------------------------" + Environment.NewLine);
			File.AppendAllText(filePath, DumpEntity(entity));
		}

		private static string DumpEntity(Entity entity, bool fullDump = true)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			StringBuilder val = new StringBuilder();
			EntityDebuggingUtility.DumpEntity(Core.Server, entity, fullDump, val);
			return ((Object)val).ToString();
		}

		public static void DestroyWithReason(this Entity entity)
		{
			//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_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_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)
			EntityManager entityManager = Core.EntityManager;
			((EntityManager)(ref entityManager)).AddComponent<Disabled>(entity);
			DestroyUtility.CreateDestroyEvent(Core.EntityManager, entity, (DestroyReason)0, (DestroyDebugReason)32);
			DestroyUtility.Destroy(Core.EntityManager, entity, (DestroyDebugReason)0, (string)null, 0);
		}

		public static bool Exists(this Entity entity)
		{
			//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)
			EntityManager entityManager = Core.EntityManager;
			return ((EntityManager)(ref entityManager)).Exists(entity);
		}

		public static bool Disabled(this Entity entity)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return entity.Has<Disabled>();
		}
	}
	[BepInPlugin("CrimsonDice", "CrimsonDice", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		private Harmony _harmony;

		public static Plugin Instance { get; private set; }

		public static Harmony Harmony => Instance._harmony;

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

		public static Settings Settings { get; private set; }

		public override void Load()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			Instance = this;
			Settings = default(Settings);
			Settings.InitConfig();
			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>("CrimsonDice");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log.LogInfo(val);
			_harmony = new Harmony("CrimsonDice");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			CommandRegistry.RegisterAll();
		}

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

		public const string PLUGIN_NAME = "CrimsonDice";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace CrimsonDice.Utilities
{
	public static class ChatUtilities
	{
		public static void SystemSendLocal(User user, float3 translation, string message)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_0040: 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_0058: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			float num = 40f;
			float2 val = default(float2);
			((float2)(ref val))..ctor(translation.x, translation.z);
			foreach (Entity user2 in PlayerService.GetUsers())
			{
				User val2 = user2.Read<User>();
				if (!((User)(ref val2)).Equals(user) && user2.TryGetComponent<LocalToWorld>(out LocalToWorld componentData) && math.distance(new float2(((LocalToWorld)(ref componentData)).Position.x, ((LocalToWorld)(ref componentData)).Position.z), val) <= num)
				{
					ServerChatUtils.SendSystemMessageToClient(Core.EntityManager, user2.Read<User>(), message);
				}
			}
		}

		public static void SystemSendTeam(User user, string message)
		{
			//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_005c: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			foreach (Entity item in (from x in PlayerService.GetUsers(includeDisabled: true)
				where x.Read<User>().ClanEntity._Entity.Has<ClanTeam>()
				select x).ToList().Where(delegate(Entity x)
			{
				//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_001e: Unknown result type (might be due to invalid IL or missing references)
				User val2 = x.Read<User>();
				return ((Entity)(ref val2.ClanEntity._Entity)).Equals(user.ClanEntity._Entity);
			}).ToList())
			{
				User val = item.Read<User>();
				if (!((User)(ref val)).Equals(user))
				{
					ServerChatUtils.SendSystemMessageToClient(Core.EntityManager, item.Read<User>(), message);
				}
			}
		}

		public static void SystemSendWhisper(User user, User target, string message)
		{
		}
	}
}
namespace CrimsonDice.Structs
{
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	public readonly struct Settings
	{
		private static readonly List<string> OrderedSections = new List<string> { "Config" };

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

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

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

		public static void InitConfig()
		{
			ToggleMod = InitConfigEntry(OrderedSections[0], "Toggle", defaultValue: true, "If true the mod will be usable; otherwise it will be disabled.");
			ResultColor = InitConfigEntry(OrderedSections[0], "ResultColor", "#34C6EB", "The color displayed for the player's roll sum.");
			AllowInGlobal = InitConfigEntry(OrderedSections[0], "AllowInGlobal", defaultValue: false, "If set to true, people will be able to roll dice in Global chat.");
			ReorderConfigSections();
		}

		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, "CrimsonDice.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, "CrimsonDice.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 CrimsonDice.Services
{
	internal class DiceService
	{
		public static List<int> ValidDice;

		public DiceService()
		{
			ValidDice = new List<int> { 4, 6, 8, 10, 12, 20, 100 };
		}

		public static bool IsValidDie(int die)
		{
			return ValidDice.Contains(die);
		}

		public static int RollDie(int die)
		{
			return new Random().Next(1, die + 1);
		}

		public static int RollDice(int die, int count)
		{
			int num = 0;
			for (int i = 0; i < count; i++)
			{
				num += RollDie(die);
			}
			return num;
		}

		public static bool ValidateHandOfDice(string hand, out int die, out int amount)
		{
			die = 0;
			amount = 0;
			if (string.IsNullOrEmpty(hand))
			{
				return false;
			}
			if (!hand.Contains('d'))
			{
				return false;
			}
			string[] array = hand.ToLower().Split('d');
			if (array.Length != 2)
			{
				return false;
			}
			if (!int.TryParse(array[0], out amount) || !int.TryParse(array[1], out die))
			{
				return false;
			}
			if (amount <= 0)
			{
				return false;
			}
			return IsValidDie(die);
		}
	}
	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 CrimsonDice.Patches
{
	[HarmonyPatch(typeof(SpawnTeamSystem_OnPersistenceLoad), "OnUpdate")]
	public static class InitializationPatch
	{
		[HarmonyPostfix]
		public static void OneShot_AfterLoad_InitializationPatch()
		{
			Core.Initialize();
			Plugin.Harmony.Unpatch((MethodBase)typeof(SpawnTeamSystem_OnPersistenceLoad).GetMethod("OnUpdate"), typeof(InitializationPatch).GetMethod("OneShot_AfterLoad_InitializationPatch"));
		}
	}
}
namespace CrimsonDice.Commands
{
	[CommandGroup("dice", null)]
	internal static class DiceCommands
	{
		[Command("roll", "r", null, "Roll dice", null, false)]
		public static void Roll(ChatCommandContext ctx, string dies = "1d20")
		{
			//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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Invalid comparison between Unknown and I4
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Invalid comparison between Unknown and I4
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			ChatMessageType type = ctx.Event.Type;
			if (((object)(ChatMessageType)(ref type)).Equals((object)(ChatMessageType)3))
			{
				ctx.Reply("Dice rolling is not allowed in Whispers.");
				return;
			}
			if (((object)(ChatMessageType)(ref type)).Equals((object)(ChatMessageType)0) && !Settings.AllowInGlobal.Value)
			{
				ctx.Reply("Dice rolling is disabled in Global chat.");
				return;
			}
			if (!DiceService.ValidateHandOfDice(dies, out var die, out var amount))
			{
				ctx.Reply("Invalid dice format. Use the format '{count}d{dieSides}' from the follow options: d4, d6, d8, d10, d12, d20, d100");
				return;
			}
			int value = DiceService.RollDice(die, amount);
			User user = ctx.User;
			string text = $"{user.CharacterName} rolled {amount}d{die} = <color={Settings.ResultColor.Value}>{value}</color>.";
			if ((int)type != 0)
			{
				text = "[{channel.ToString()}] " + text;
				if ((int)type != 2)
				{
					if ((int)type == 4)
					{
						LocalToWorld val = ctx.Event.SenderCharacterEntity.Read<LocalToWorld>();
						float3 position = ((LocalToWorld)(ref val)).Position;
						ChatUtilities.SystemSendLocal(user, position, text);
					}
				}
				else
				{
					ChatUtilities.SystemSendTeam(user, text);
				}
				ServerChatUtils.SendSystemMessageToClient(Core.EntityManager, user, $"You rolled <color={Settings.ResultColor.Value}>{value}</color>.");
			}
			else
			{
				ServerChatUtils.SendSystemMessageToAllClients(Core.EntityManager, text);
			}
			ctx.Event.Cancel();
		}
	}
}