Decompiled source of CrimsonClans v1.2.5

CrimsonClans.dll

Decompiled 5 days 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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using CrimsonClans.Services;
using CrimsonClans.Structs;
using CrimsonClans.Utilities;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Gameplay.Clan;
using ProjectM.Gameplay.Systems;
using ProjectM.Network;
using Stunlock.Core;
using Unity.Collections;
using Unity.Entities;
using VAMP;
using VAMP.Services;
using VAMP.Utilities;
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("CrimsonClans")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Extension to Clans: Hearts per Clan and more!")]
[assembly: AssemblyFileVersion("1.2.5.0")]
[assembly: AssemblyInformationalVersion("1.2.5+1.Branch.master.Sha.f7c680286d6412fd13798509c02f4925a23ebf8b.f7c680286d6412fd13798509c02f4925a23ebf8b")]
[assembly: AssemblyProduct("CrimsonClans")]
[assembly: AssemblyTitle("CrimsonClans")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CrimsonClans
{
	[BepInPlugin("CrimsonClans", "CrimsonClans", "1.2.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, "CrimsonClans");

		internal static Plugin Instance { get; private set; }

		public static Settings Settings { get; private set; }

		public static Harmony Haromy => Instance._harmony;

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

		public static Database DB { get; private set; }

		public override void Load()
		{
			Instance = this;
			Settings = default(Settings);
			_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			Settings.InitConfig();
			CommandRegistry.RegisterAll();
			Events.OnCoreLoaded = (Action)Delegate.Combine(Events.OnCoreLoaded, new Action(Loaded));
		}

		public void Loaded()
		{
			DB = new Database();
		}

		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 = "CrimsonClans";

		public const string PLUGIN_NAME = "CrimsonClans";

		public const string PLUGIN_VERSION = "1.2.5";
	}
}
namespace CrimsonClans.Utilities
{
	public static class RaidTime
	{
		private static readonly List<DayOfWeek> WeekendDays = new List<DayOfWeek>(2)
		{
			DayOfWeek.Saturday,
			DayOfWeek.Sunday
		};

		private static ServerGameSettings serverGameSettings;

		public static bool IsRaidTimeNow()
		{
			return IsRaidTime(DateTime.Now);
		}

		public static bool IsRaidTime(DateTime dateTime)
		{
			//IL_0020: 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: Expected I4, but got Unknown
			if (serverGameSettings == null)
			{
				serverGameSettings = Core.Server.GetExistingSystemManaged<ServerGameSettingsSystem>()._Settings;
			}
			CastleDamageMode castleDamageMode = serverGameSettings.CastleDamageMode;
			switch ((int)castleDamageMode)
			{
			case 0:
				return false;
			case 1:
				return true;
			case 2:
			{
				PlayerInteractionSettings playerInteractionSettings = serverGameSettings.PlayerInteractionSettings;
				StartEndTimeData window = (IsWeekend(dateTime) ? playerInteractionSettings.VSCastleWeekendTime : playerInteractionSettings.VSCastleWeekdayTime);
				return IsInWindow(dateTime, window);
			}
			default:
				return false;
			}
		}

		private static bool IsWeekend(DateTime dateTime)
		{
			return WeekendDays.Contains(dateTime.DayOfWeek);
		}

		private static bool IsInWindow(DateTime dateTime, StartEndTimeData window)
		{
			TimeSpan timeOfDay = dateTime.TimeOfDay;
			TimeSpan timeSpan = new TimeSpan(window.StartHour, window.StartMinute, 0).Subtract(TimeSpan.FromMinutes(Settings.PreRaidBuffer.Value));
			TimeSpan timeSpan2 = new TimeSpan(window.EndHour, window.EndMinute, 0).Add(TimeSpan.FromMinutes(Settings.PostRaidBuffer.Value));
			if (timeOfDay >= timeSpan)
			{
				return timeOfDay < timeSpan2;
			}
			return false;
		}
	}
}
namespace CrimsonClans.Structs
{
	public class Database
	{
		public static string JoinCooldownPath = Path.Combine(Plugin.ConfigFiles, "joincooldowns.json");

		public List<Cooldown> Cooldowns { get; set; }

		public Database()
		{
			CreateFiles();
			LoadFiles();
		}

		private void LoadFiles()
		{
			string text = "";
			if (Settings.LeaveCooldown.Value > 0)
			{
				text = File.ReadAllText(JoinCooldownPath);
				Cooldowns = JsonSerializer.Deserialize<List<Cooldown>>(text);
			}
		}

		private static void CreateFiles()
		{
			if (!File.Exists(JoinCooldownPath) && Settings.LeaveCooldown.Value > 0)
			{
				string contents = JsonSerializer.Serialize(new List<(ulong, DateTime)>());
				File.WriteAllText(JoinCooldownPath, contents);
			}
		}

		public static void SaveFiles()
		{
			string contents = JsonSerializer.Serialize(Plugin.DB.Cooldowns);
			File.WriteAllText(JoinCooldownPath, contents);
		}
	}
	[Serializable]
	public struct Cooldown
	{
		public ulong PlayerId { get; set; }

		public DateTime Time { get; set; }

		public Cooldown(ulong playerId, DateTime time)
		{
			PlayerId = playerId;
			Time = time;
		}
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	public readonly struct Settings
	{
		public static ConfigEntry<bool> LockInvite;

		public static ConfigEntry<bool> LockCreate;

		public static ConfigEntry<bool> LockLeave;

		public static ConfigEntry<bool> LockKick;

		public static ConfigEntry<bool> LockEdit;

		public static ConfigEntry<int> PreRaidBuffer;

		public static ConfigEntry<int> PostRaidBuffer;

		public static ConfigEntry<int> LeaveCooldown;

		public static ConfigEntry<bool> KickCooldown;

		public static ConfigEntry<bool> ModHeartsPerClan;

		public static ConfigEntry<int> HeartsPerClan;

		public static ConfigEntry<bool> ModHeartsPerUser;

		public static ConfigEntry<int> HeartsPerUser;

		private static readonly List<string> OrderedSections = new List<string> { "General", "Raid Time - Buffers", "Raid Time - Ability Locks", "Cooldowns" };

		private static readonly List<string> directoryPaths = new List<string>(1) { Plugin.ConfigFiles };

		public static void InitConfig()
		{
			foreach (string directoryPath in directoryPaths)
			{
				CreateDirectories(directoryPath);
			}
			ModHeartsPerClan = InitConfigEntry(OrderedSections[0], "ToggleHeartsPerClan", defaultValue: false, "If true, the mod will manage the hearts per clan system. Please set the server setting to a higher value than HeartsPerClan or have server limit by user.");
			HeartsPerClan = InitConfigEntry(OrderedSections[0], "HeartsPerClan", 1, "The amount of castle hearts a clan can have.");
			ModHeartsPerUser = InitConfigEntry(OrderedSections[0], "ToggleHeartsPerUser", defaultValue: false, "If true, the mod will manage the hearts per user system. Please set the server setting to a higher value than HeartsPerUser or have server limit by clan.");
			HeartsPerUser = InitConfigEntry(OrderedSections[0], "HeartsPerUser", 1, "The amount of castle hearts a user can have.");
			PreRaidBuffer = InitConfigEntry(OrderedSections[1], "PreRaidBufferMins", 30, "The number of minutes prior to the raid window to lock clan operation.");
			PostRaidBuffer = InitConfigEntry(OrderedSections[1], "PostRaidBufferMins", 0, "The number of minutes past the raid window to lock clan operation.");
			LockInvite = InitConfigEntry(OrderedSections[2], "Invite", defaultValue: true, "If this is set to true, clans will be unable to invite players to their clan during raid time.");
			LockCreate = InitConfigEntry(OrderedSections[2], "Create", defaultValue: true, "If this is set to true, clans will be unable to be created during raid time.");
			LockEdit = InitConfigEntry(OrderedSections[2], "Edit", defaultValue: true, "If this is set to true, clans will be unable to change their details during raid time.");
			LockKick = InitConfigEntry(OrderedSections[2], "Kick", defaultValue: false, "If this is set to true, clans will be unable to kick players from the clan during raid time.");
			LockLeave = InitConfigEntry(OrderedSections[2], "Leave", defaultValue: false, "If this is set to true, players will be unable to leave clans during raid time.");
			LeaveCooldown = InitConfigEntry(OrderedSections[3], "JoinCooldown", 0, "The number of minutes that a player must wait to join a clan after leaving a prior clan.");
			KickCooldown = InitConfigEntry(OrderedSections[3], "KickCooldown", defaultValue: false, "If this is set to true, being kicked from a clan will apply a join cooldown to a player as if they left the clan on their own.");
			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, "CrimsonClans.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);
			}
		}

		private static void ReorderConfigSections()
		{
			string path = Path.Combine(Paths.ConfigPath, "CrimsonClans.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 CrimsonClans.Services
{
	public static class CastleService
	{
		public static bool CanPlaceHeart(Entity character)
		{
			//IL_000c: 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)
			if (Settings.ModHeartsPerUser.Value && CountUserHearts(character) >= Settings.HeartsPerUser.Value)
			{
				return false;
			}
			if (Settings.ModHeartsPerClan.Value)
			{
				return CountTeamHearts(character) < Settings.HeartsPerClan.Value;
			}
			return true;
		}

		public static bool CanJoinClan(Entity character, Entity clan)
		{
			//IL_000c: 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_0013: Unknown result type (might be due to invalid IL or missing references)
			if (Settings.ModHeartsPerClan.Value)
			{
				return CountUserHearts(character) + CountTeamHearts(EntityUtil.Read<TeamData>(clan).TeamValue) <= Settings.HeartsPerClan.Value;
			}
			return true;
		}

		public static int CountTeamHearts(int teamValue)
		{
			//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_0010: 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_001a: 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_0025: 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_0035: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			NativeArray<Entity> val = ((EntityQuery)(ref CastleHeartService.CastleHeartQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			int num = 0;
			Enumerator<Entity> enumerator = val.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				if (EntityUtil.Exists(current) && EntityUtil.Has<Team>(current) && EntityUtil.Read<Team>(current).Value.Equals(teamValue))
				{
					num++;
				}
			}
			val.Dispose();
			return num;
		}

		public static int CountTeamHearts(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_0012: 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)
			EntityManager entityManager = Core.EntityManager;
			if (!((EntityManager)(ref entityManager)).HasComponent<Team>(entity))
			{
				return 0;
			}
			return CountTeamHearts(EntityUtil.Read<Team>(entity).Value);
		}

		public static int CountUserHearts(User user)
		{
			//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_0010: 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_001a: 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_0025: 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_0035: 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_003b: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_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_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_0065: Unknown result type (might be due to invalid IL or missing references)
			NativeArray<Entity> val = ((EntityQuery)(ref CastleHeartService.CastleHeartQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			int num = 0;
			Enumerator<Entity> enumerator = val.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				if (!EntityUtil.Exists(current) || !EntityUtil.Has<UserOwner>(current))
				{
					continue;
				}
				UserOwner val2 = EntityUtil.Read<UserOwner>(current);
				if (EntityUtil.Exists(val2.Owner._Entity))
				{
					User val3 = EntityUtil.Read<User>(val2.Owner._Entity);
					if (((User)(ref user)).Equals(val3))
					{
						num++;
					}
				}
			}
			return num;
		}

		public static int CountUserHearts(Entity entity)
		{
			//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_0010: 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_001a: 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_0027: 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_0030: 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_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_0042: 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_0053: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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)
			//IL_006e: 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_0074: 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)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			NativeArray<Entity> val = ((EntityQuery)(ref CastleHeartService.CastleHeartQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			int num = 0;
			Enumerator<Entity> enumerator = val.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				if (!EntityUtil.Exists(current) || !EntityUtil.Has<UserOwner>(current))
				{
					continue;
				}
				UserOwner val2 = EntityUtil.Read<UserOwner>(current);
				if (!EntityUtil.Exists(val2.Owner._Entity))
				{
					continue;
				}
				User val3 = EntityUtil.Read<User>(val2.Owner._Entity);
				if (!EntityUtil.Has<PlayerCharacter>(entity))
				{
					continue;
				}
				PlayerCharacter val4 = EntityUtil.Read<PlayerCharacter>(entity);
				if (EntityUtil.Has<User>(val4.UserEntity))
				{
					User val5 = EntityUtil.Read<User>(val4.UserEntity);
					if (((User)(ref val5)).Equals(val3))
					{
						num++;
					}
				}
			}
			return num;
		}
	}
}
namespace CrimsonClans.Patches
{
	[HarmonyPatch(typeof(CastleHeartEventSystem), "OnUpdate")]
	internal class CastleHeartEventSystemPatch
	{
		public static void Prefix(CastleHeartEventSystem __instance)
		{
			//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_000a: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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_002a: 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_0040: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_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_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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Invalid comparison between Unknown and I4
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			EntityQuery castleHeartInteractEventQuery = __instance._CastleHeartInteractEventQuery;
			NativeArray<Entity> val = ((EntityQuery)(ref castleHeartInteractEventQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			Enumerator<Entity> enumerator = val.GetEnumerator();
			Entity val4 = default(Entity);
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				if (!EntityUtil.Exists(current) || !EntityUtil.Has<CastleHeartInteractEvent>(current) || !EntityUtil.Has<FromCharacter>(current))
				{
					continue;
				}
				CastleHeartInteractEvent val2 = EntityUtil.Read<CastleHeartInteractEvent>(current);
				FromCharacter val3 = EntityUtil.Read<FromCharacter>(current);
				if (!EntityUtil.Exists(val3.User) || !EntityUtil.Has<User>(val3.User) || (int)val2.EventType != 3)
				{
					continue;
				}
				if (CastleHeartService.TryGetByID(val2.CastleHeart, ref val4) && EntityUtil.Has<UserOwner>(val4))
				{
					UserOwner val5 = EntityUtil.Read<UserOwner>(val4);
					if (!((Entity)(ref val5.Owner._Entity)).Equals(Entity.Null) && EntityUtil.Read<User>(EntityUtil.Read<UserOwner>(val4).Owner._Entity) == EntityUtil.Read<User>(val3.User))
					{
						continue;
					}
				}
				if (!CastleService.CanPlaceHeart(val3.Character))
				{
					ChatUtil.SystemSendUser(EntityUtil.Read<User>(val3.User), "You or your clan have reached the maximum number of castle hearts.");
					EntityUtil.DestroyWithReason(current);
				}
			}
			val.Dispose();
		}
	}
	[HarmonyPatch(typeof(ClanSystem_Server), "OnUpdate")]
	internal class ClanSystemServerPatch
	{
		public static void Prefix(ClanSystem_Server __instance)
		{
			//IL_0009: 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_0037: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			(EntityQuery, string)[] array = new(EntityQuery, string)[6]
			{
				(__instance._InvitePlayerToClanQuery, "Invite"),
				(__instance._ClanInviteResponseQuery, "Response"),
				(__instance._KickRequestQuery, "Kick"),
				(__instance._CreateClanEventQuery, "Create"),
				(__instance._LeaveClanEventQuery, "Leave"),
				(__instance._EditClanEventQuery, "Edit")
			};
			for (int i = 0; i < array.Length; i++)
			{
				(EntityQuery, string) tuple = array[i];
				EntityQuery item = tuple.Item1;
				string item2 = tuple.Item2;
				NativeArray<Entity> val = ((EntityQuery)(ref item)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
				Enumerator<Entity> enumerator = val.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					if (!HandleRaidWindow(current, item2) && !HandleLeaveCooldown(current, item2))
					{
						HandleJoinResponseWithCooldown(current, item2);
					}
				}
				val.Dispose();
			}
		}

		private static bool HandleRaidWindow(Entity entity, string type)
		{
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			if (type == "Invite" && !Settings.LockInvite.Value)
			{
				return false;
			}
			if (type == "Response" && !Settings.LockInvite.Value)
			{
				return false;
			}
			if (type == "Kick" && !Settings.LockKick.Value)
			{
				return false;
			}
			if (type == "Create" && !Settings.LockCreate.Value)
			{
				return false;
			}
			if (type == "Leave" && !Settings.LockLeave.Value)
			{
				return false;
			}
			if (type == "Edit" && !Settings.LockEdit.Value)
			{
				return false;
			}
			if (RaidTime.IsRaidTimeNow())
			{
				Cancel(entity, "The Clan " + type + " ability is disabled during the raid window.");
				return true;
			}
			return false;
		}

		private static bool HandleLeaveCooldown(Entity entity, string type)
		{
			//IL_002b: 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_0036: 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)
			//IL_00e3: 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_005b: 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_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)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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_0076: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			if (type == "Leave" || type == "Kick")
			{
				if (Settings.LeaveCooldown.Value == 0)
				{
					return false;
				}
				User val = EntityUtil.Read<User>(EntityUtil.Read<FromCharacter>(entity).User);
				if (type == "Kick")
				{
					if (!Settings.KickCooldown.Value)
					{
						return false;
					}
					Kick_Request val2 = EntityUtil.Read<Kick_Request>(entity);
					EntityManager entityManager = Core.EntityManager;
					DynamicBuffer<ClanMemberStatus> buffer = ((EntityManager)(ref entityManager)).GetBuffer<ClanMemberStatus>(val.ClanEntity._Entity, false);
					entityManager = Core.EntityManager;
					DynamicBuffer<SyncToUserBuffer> buffer2 = ((EntityManager)(ref entityManager)).GetBuffer<SyncToUserBuffer>(val.ClanEntity._Entity, false);
					for (int i = 0; i < buffer.Length; i++)
					{
						if (buffer[i].UserIndex == val2.TargetUserIndex)
						{
							val = EntityUtil.Read<User>(buffer2[i].UserEntity);
							break;
						}
					}
				}
				Plugin.DB.Cooldowns.Add(new Cooldown(val.PlatformId, DateTime.Now.AddMinutes(Settings.LeaveCooldown.Value)));
				Database.SaveFiles();
				return true;
			}
			return false;
		}

		private static bool HandleJoinResponseWithCooldown(Entity entity, string type)
		{
			//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_001b: 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_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_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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			if (type != "Response")
			{
				return false;
			}
			ClanInviteResponse val = EntityUtil.Read<ClanInviteResponse>(entity);
			if (!((object)(InviteRequestResponse)(ref val.Response)).Equals((object)(InviteRequestResponse)1))
			{
				return false;
			}
			FromCharacter val2 = EntityUtil.Read<FromCharacter>(entity);
			User user = EntityUtil.Read<User>(val2.User);
			if (Settings.LeaveCooldown.Value != 0 && Plugin.DB.Cooldowns.Exists((Cooldown x) => x.PlayerId == user.PlatformId && x.Time > DateTime.Now))
			{
				Cancel(entity, "You are on cooldown from joining a clan for " + FormatRemainder(Plugin.DB.Cooldowns.First((Cooldown x) => x.PlayerId == user.PlatformId && x.Time > DateTime.Now).Time - DateTime.Now) + ".");
				return true;
			}
			Entity byNetworkId = ClanService.GetByNetworkId(val.ClanId);
			if (((Entity)(ref byNetworkId)).Equals(Entity.Null))
			{
				return false;
			}
			if (!CastleService.CanJoinClan(val2.Character, byNetworkId))
			{
				Cancel(entity, "Joining the clan would result in exceeding the maximum number of castle hearts.");
				return true;
			}
			return false;
		}

		private static void Cancel(Entity entity, string cancelReason)
		{
			//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_0009: 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_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_0017: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = Core.EntityManager;
			FromCharacter componentData = ((EntityManager)(ref entityManager)).GetComponentData<FromCharacter>(entity);
			entityManager = Core.EntityManager;
			ChatUtil.SystemSendUser(((EntityManager)(ref entityManager)).GetComponentData<User>(componentData.User), cancelReason);
			EntityUtil.DestroyWithReason(entity);
		}

		private static string FormatRemainder(TimeSpan remainder)
		{
			string text = string.Empty;
			if (remainder.Days > 0)
			{
				text += $"{remainder.Days} {((remainder.Days == 1) ? "day" : "days")}, ";
			}
			if (remainder.Hours > 0)
			{
				text += $"{remainder.Hours} {((remainder.Hours == 1) ? "hour" : "hours")}, ";
			}
			if (remainder.Minutes > 0)
			{
				text += $"{remainder.Minutes} {((remainder.Minutes == 1) ? "minute" : "minutes")}, ";
			}
			if (remainder.Seconds > 0)
			{
				text += $"{remainder.Seconds} {((remainder.Seconds == 1) ? "second" : "seconds")}";
			}
			if (text.EndsWith(", "))
			{
				text = text.Substring(0, text.Length - 2);
			}
			return text;
		}
	}
	[HarmonyPatch(typeof(PlaceTileModelSystem), "OnUpdate")]
	internal class PlaceTileModelSystemPatch
	{
		public static void Prefix(PlaceTileModelSystem __instance)
		{
			//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_000a: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_0037: 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_0044: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			EntityQuery buildTileQuery = __instance._BuildTileQuery;
			NativeArray<Entity> val = ((EntityQuery)(ref buildTileQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			Enumerator<Entity> enumerator = val.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				if (EntityUtil.Read<BuildTileModelEvent>(current).PrefabGuid == new PrefabGUID(-485210554))
				{
					FromCharacter val2 = EntityUtil.Read<FromCharacter>(current);
					User val3 = EntityUtil.Read<User>(val2.User);
					if (!CastleService.CanPlaceHeart(val2.Character))
					{
						ChatUtil.SystemSendUser(val3, "You or your clan have reached the maximum number of castle hearts.");
						EntityUtil.DestroyWithReason(current);
					}
				}
			}
			val.Dispose();
		}
	}
}
namespace CrimsonClans.Commands
{
	[CommandGroup("clans", null)]
	internal static class AdminCommands
	{
		[Command("overlimit", "limit", null, null, null, true)]
		public static void OverLimit(ChatCommandContext ctx, bool force = false)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: 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_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			if (Settings.ModHeartsPerClan.Value || force)
			{
				List<ClanTeam> list = new List<ClanTeam>();
				foreach (Entity item in ClanService.GetAll())
				{
					if (CastleService.CountTeamHearts(item) > Settings.HeartsPerClan.Value)
					{
						list.Add(EntityUtil.Read<ClanTeam>(item));
					}
				}
				if (list.Count > 0)
				{
					ctx.Reply("Clans Over Limit:\n" + string.Join(", ", list.Select((ClanTeam x) => ((object)(FixedString64Bytes)(ref x.Name)).ToString())) + ".");
				}
				else
				{
					ctx.Reply("No clans over limit.");
				}
			}
			if (!(Settings.ModHeartsPerUser.Value || force))
			{
				return;
			}
			List<User> list2 = new List<User>();
			foreach (User item2 in from x in GetAllUsers()
				select EntityUtil.Read<User>(x))
			{
				if (CastleService.CountUserHearts(item2) > Settings.HeartsPerUser.Value)
				{
					list2.Add(item2);
				}
			}
			if (list2.Count > 0)
			{
				ctx.Reply("Users Over Limit:\n" + string.Join(", ", list2.Select((User x) => ((object)(FixedString64Bytes)(ref x.CharacterName)).ToString())) + ".");
			}
			else
			{
				ctx.Reply("No users over limit.");
			}
		}

		public static IEnumerable<Entity> GetAllUsers()
		{
			ComponentType[] array = (ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<User>() };
			EntityManager entityManager = Core.EntityManager;
			EntityQuery val = ((EntityManager)(ref entityManager)).CreateEntityQuery(array);
			Enumerator<Entity> enumerator = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)).GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				entityManager = Core.EntityManager;
				if (((EntityManager)(ref entityManager)).Exists(current))
				{
					yield return current;
				}
			}
		}
	}
}