Decompiled source of CrimsonAlliance v0.3.0

CrimsonAlliance.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.Json;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using CrimsonAlliance;
using CrimsonAlliance.Services;
using CrimsonAlliance.Structs;
using CrimsonAlliance.Systems;
using CrimsonAlliance.Utilities;
using HarmonyLib;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Gameplay.Clan;
using ProjectM.Network;
using Unity.Collections;
using Unity.Entities;
using UnityEngine;
using VAMP;
using VAMP.Models;
using VAMP.Services;
using VAMP.Systems;
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("CrimsonAlliance")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Created with VRising.ModTemplate, you should edit this.")]
[assembly: AssemblyFileVersion("0.3.0.0")]
[assembly: AssemblyInformationalVersion("0.3.0+Branch.master.Sha.398a115ec0f7cfe028c8cc7e77871dbe9db210d5.398a115ec0f7cfe028c8cc7e77871dbe9db210d5")]
[assembly: AssemblyProduct("CrimsonAlliance")]
[assembly: AssemblyTitle("CrimsonAlliance")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.3.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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;
		}
	}
}
[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_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_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: 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_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		(EntityQuery, string)[] array = new(EntityQuery, string)[4]
		{
			(__instance._ClanInviteResponseQuery, "Response"),
			(__instance._KickRequestQuery, "Kick"),
			(__instance._CreateClanEventQuery, "Create"),
			(__instance._LeaveClanEventQuery, "Leave")
		};
		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())
			{
				Parse(enumerator.Current, item2);
			}
			val.Dispose();
		}
	}

	private static void Parse(Entity entity, string type)
	{
		//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_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_0048: 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_0051: 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_009f: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: 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)
		//IL_00c7: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		User val = EntityUtil.Read<User>(EntityUtil.Read<FromCharacter>(entity).User);
		EntityManager entityManager;
		switch (type)
		{
		default:
			_ = type == "Kick";
			break;
		case "Create":
			entityManager = Core.EntityManager;
			if (((EntityManager)(ref entityManager)).Exists(entity))
			{
				CreateClan_Request val5 = EntityUtil.Read<CreateClan_Request>(entity);
				if (ClanService.GetAllWithName(((FixedString64Bytes)(ref val5.ClanName)).Value).Count() > 0)
				{
					Cancel(entity, "Clan with the name \"" + ((FixedString64Bytes)(ref val5.ClanName)).Value + "\" already exists. Please choose a different name.");
				}
			}
			break;
		case "Leave":
		{
			LeaveClan val3 = EntityUtil.Read<LeaveClan>(entity);
			entityManager = Core.EntityManager;
			if (((EntityManager)(ref entityManager)).Exists(entity))
			{
				Entity val4 = default(Entity);
				ClanTeam clanId = ((!CastleHeartService.TryGetByID(val3.ClanId, ref val4)) ? EntityUtil.Read<ClanTeam>(val.ClanEntity._Entity) : EntityUtil.Read<ClanTeam>(val4));
				Plugin.AllianceService.NotifyPlayerLeftClan(val, clanId);
			}
			break;
		}
		case "Response":
		{
			ClanInviteResponse val2 = EntityUtil.Read<ClanInviteResponse>(entity);
			ref InviteRequestResponse response = ref val2.Response;
			object obj = (object)(InviteRequestResponse)1;
			((object)Unsafe.As<InviteRequestResponse, InviteRequestResponse>(ref response)/*cast due to .constrained prefix*/).Equals(obj);
			break;
		}
		}
	}

	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);
	}
}
public static class AllianceManagement
{
	public static void HandleClanAlliance(User ownerClan, string targetClan)
	{
		//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_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: 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_0027: Unknown result type (might be due to invalid IL or missing references)
		Entity clanEntity = ClanService.GetAllWithName(targetClan).FirstOrDefault();
		Guid clanGuid = EntityUtil.Read<ClanTeam>(ownerClan.ClanEntity._Entity).ClanGuid;
		InitializeAllianceIfNeeded(clanGuid);
		HandleAllianceAddition(clanEntity, clanGuid);
		Database.SaveClanAlliances();
	}

	private unsafe static void InitializeAllianceIfNeeded(Guid ownerClanGuid)
	{
		if (!Database.ClanAlliances.ContainsKey(((object)(*(Guid*)(&ownerClanGuid))/*cast due to .constrained prefix*/).ToString()))
		{
			Database.ClanAlliances[((object)(*(Guid*)(&ownerClanGuid))/*cast due to .constrained prefix*/).ToString()] = new HashSet<string> { ((object)(*(Guid*)(&ownerClanGuid))/*cast due to .constrained prefix*/).ToString() };
		}
	}

	private unsafe static void HandleAllianceAddition(Entity clanEntity, Guid ownerClanGuid)
	{
		//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)
		HashSet<string> hashSet = Database.ClanAlliances[((object)(*(Guid*)(&ownerClanGuid))/*cast due to .constrained prefix*/).ToString()];
		if (hashSet.Count < Settings.MaxAllianceSize.Value)
		{
			ClanTeam val = EntityUtil.Read<ClanTeam>(clanEntity);
			hashSet.Add(((object)(*(Guid*)(&val.ClanGuid))/*cast due to .constrained prefix*/).ToString());
		}
	}

	public unsafe static bool IsAllianceFull(User ownerClan)
	{
		//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_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)
		Guid clanGuid = EntityUtil.Read<ClanTeam>(ownerClan.ClanEntity._Entity).ClanGuid;
		if (Database.ClanAlliances.ContainsKey(((object)(*(Guid*)(&clanGuid))/*cast due to .constrained prefix*/).ToString()))
		{
			return Database.ClanAlliances[((object)(*(Guid*)(&clanGuid))/*cast due to .constrained prefix*/).ToString()].Count >= Settings.MaxAllianceSize.Value;
		}
		return false;
	}
}
namespace CrimsonLog.Hooks
{
	[HarmonyBefore(new string[] { "gg.deca.VampireCommandFramework" })]
	[HarmonyPatch(typeof(ChatMessageSystem), "OnUpdate")]
	public static class ChatMessageSystem_Patch
	{
		public static bool Prefix(ChatMessageSystem __instance)
		{
			//IL_0001: 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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//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_002b: 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_0032: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_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_004d: 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_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)
			//IL_0066: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Invalid comparison between Unknown and I4
			//IL_0095: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: 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_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			_ = __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);
				if (!((FixedString512Bytes)(ref componentData3.MessageText)).Value.StartsWith(".a") || (int)componentData3.MessageType != 2)
				{
					continue;
				}
				Player val2 = PlayerService.PlayerFromUser(componentData2);
				Entity clan = val2.Clan;
				if (!((Entity)(ref clan)).Equals(Entity.Null))
				{
					List<User> list = (from x in API.GetAlliedPlayers(val2.Clan)
						select EntityUtil.Read<User>(x)).ToList();
					if (list.Count <= 0)
					{
						EntityUtil.DestroyWithReason(current);
						ChatUtil.SystemSendUser(componentData2, "You do not have an alliance.");
						continue;
					}
					string value = ((FixedString512Bytes)(ref componentData3.MessageText)).Value;
					string value2 = value.Substring(2, value.Length - 2).Trim();
					ChatUtil.SystemSendUsers(list.ToArray(), $"<color={Settings.AllianceChatColor.Value}>[Alliance] {val2.FullName} {value2}</color>");
					EntityUtil.DestroyWithReason(current);
				}
			}
			val.Dispose();
			return true;
		}
	}
}
namespace CrimsonAlliance
{
	public static class API
	{
		public static void OverrideFriendlyFire()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			if (!Settings.FriendlyFireWorld.Value)
			{
				ManualLogSource logInstance = Plugin.LogInstance;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(40, 0, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Another mod has overrided friendly fire.");
				}
				logInstance.LogInfo(val);
			}
			Settings.FriendlyFireWorld.Value = true;
		}

		public unsafe static bool AreAllied(Guid clanGuid1, Guid clanGuid2)
		{
			//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_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_0015: 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)
			if (clanGuid1 == clanGuid2)
			{
				return true;
			}
			return Database.ClanAlliances.Values.Any((HashSet<string> set) => set.Contains(((object)(*(Guid*)(&clanGuid1))/*cast due to .constrained prefix*/).ToString()) && set.Contains(((object)(*(Guid*)(&clanGuid2))/*cast due to .constrained prefix*/).ToString()));
		}

		public static void AddAlliance(string ownerClanGuid, string targetClanGuid)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			if (!Database.ClanAlliances.ContainsKey(ownerClanGuid))
			{
				Database.ClanAlliances[ownerClanGuid] = new HashSet<string> { ownerClanGuid };
			}
			HashSet<string> alliance = Database.ClanAlliances[ownerClanGuid];
			Plugin.AllianceService.AddClanToAlliance(ClanService.GetByGUID(new Guid(targetClanGuid)), alliance);
		}

		public static List<Entity> GetAlliedPlayers(Entity clanEntity)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return Plugin.AllianceService.GetAllAllianceMembers(clanEntity);
		}

		public static List<string> GetAllianceClanNames(Entity clanEntity)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return Plugin.AllianceService.GetAllianceClanNames(clanEntity);
		}

		public static HashSet<string> GetClanAlliance(string clanGuid)
		{
			if (!Database.ClanAlliances.TryGetValue(clanGuid, out var value))
			{
				return new HashSet<string>();
			}
			return value;
		}

		public static bool ValidateAllianceEligibility(Entity clanEntity, User leaderUser)
		{
			//IL_0005: 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_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			AllianceService allianceService = Plugin.AllianceService;
			ClanTeam val = EntityUtil.Read<ClanTeam>(clanEntity);
			return allianceService.IsClanEligibleForAlliance(leaderUser, ((FixedString64Bytes)(ref val.Name)).Value);
		}

		public static bool HasMaxAllies(string clanGuid)
		{
			if (!Database.ClanAlliances.ContainsKey(clanGuid))
			{
				return false;
			}
			return Database.ClanAlliances[clanGuid].Count >= Settings.MaxAllianceSize.Value;
		}

		public static void RemoveAlliance(string ownerClanGuid, string targetClanGuid)
		{
			if (Database.ClanAlliances.TryGetValue(ownerClanGuid, out var value))
			{
				value.Remove(targetClanGuid);
			}
		}
	}
	[BepInPlugin("CrimsonAlliance", "CrimsonAlliance", "0.3.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[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, "CrimsonAlliance");

		internal static Plugin Instance { get; private set; }

		public static Settings Settings { get; private set; }

		public static Harmony Harmony => Instance._harmony;

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

		public static Database Database { get; internal set; }

		public static AllianceService AllianceService { get; internal set; }

		internal static ModTalkService ModTalkService { get; private set; }

		public static bool UsingCL { get; private set; } = false;

		public override void Load()
		{
			Instance = this;
			Settings = default(Settings);
			foreach (KeyValuePair<string, PluginInfo> plugin in ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins)
			{
				if (plugin.Value.Metadata.GUID.Equals("CrimsonLog"))
				{
					UsingCL = true;
				}
			}
			if (Settings.InitConfig())
			{
				_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
				CommandRegistry.RegisterAll();
				Events.OnCoreLoaded = (Action)Delegate.Combine(Events.OnCoreLoaded, new Action(Loaded));
			}
		}

		public void Loaded()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			Database = new Database();
			AllianceService = new AllianceService();
			ModTalkService = new ModTalkService();
			ManualLogSource logInstance = LogInstance;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(10, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("CrimsonAlliance");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.3.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("] loaded!");
			}
			logInstance.LogInfo(val);
		}

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

		public const string PLUGIN_NAME = "CrimsonAlliance";

		public const string PLUGIN_VERSION = "0.3.0";
	}
}
namespace CrimsonAlliance.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 CrimsonAlliance.Systems
{
	public static class AllianceInvites
	{
		public static List<InviteRequest> Open;

		public static void InitNeeded()
		{
			if (Open == null)
			{
				Open = new List<InviteRequest>();
			}
		}

		public static bool IsEligibleToSendInvite(User ownerId)
		{
			//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)
			InitNeeded();
			return !Open.Exists((InviteRequest x) => x.Inviter == ownerId);
		}

		public static bool IsEligibleToReceiveInvite(string clanName)
		{
			InitNeeded();
			return !Open.Exists((InviteRequest x) => x.InvitedClanName == clanName);
		}

		public static InviteRequest CreateInvite(User owner, Entity ownerClanEntity, string targetClanName, Entity targetClanEntity, User targetOwnerEntity)
		{
			//IL_000b: 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_0019: 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_0039: 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)
			InitNeeded();
			InviteRequest obj = new InviteRequest
			{
				Inviter = owner,
				InviterClanEntity = ownerClanEntity
			};
			ClanTeam val = EntityUtil.Read<ClanTeam>(ownerClanEntity);
			obj.InviterClanName = ((FixedString64Bytes)(ref val.Name)).Value;
			obj.InvitedClanName = targetClanName;
			obj.InvitedClanLeader = targetOwnerEntity;
			obj.InvitedClanEntity = targetClanEntity;
			InviteRequest inviteRequest = obj;
			Open.Add(inviteRequest);
			return inviteRequest;
		}

		public static void Cleanup()
		{
			InitNeeded();
			Open.Where((InviteRequest invite) => invite.IsExpired()).ToList().ForEach(delegate(InviteRequest invite)
			{
				//IL_0001: 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)
				ChatUtil.SystemSendUser(invite.Inviter, invite.ToInvitedExpiredString());
				ChatUtil.SystemSendUser(invite.InvitedClanLeader, invite.ToInvitedExpiredString());
				Open.Remove(invite);
			});
		}
	}
	public static class AllianceMembership
	{
		public static void ListPersonalAllianceClans(ChatCommandContext ctx, Dictionary<string, HashSet<string>> playerAlliances)
		{
			//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_0021: Unknown result type (might be due to invalid IL or missing references)
			Guid clanGuid = EntityUtil.Read<ClanTeam>(ctx.Event.User.ClanEntity._Entity).ClanGuid;
			string text = FormatClanList(GetClanAlliance(playerAlliances, clanGuid));
			ctx.Reply(text);
		}

		private unsafe static HashSet<string> GetClanAlliance(Dictionary<string, HashSet<string>> alliances, Guid clanId)
		{
			//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)
			if (!alliances.ContainsKey(((object)(*(Guid*)(&clanId))/*cast due to .constrained prefix*/).ToString()))
			{
				return alliances.FirstOrDefault((KeyValuePair<string, HashSet<string>> a) => a.Value.Contains(((object)(*(Guid*)(&clanId))/*cast due to .constrained prefix*/).ToString())).Value;
			}
			return alliances[((object)(*(Guid*)(&clanId))/*cast due to .constrained prefix*/).ToString()];
		}

		private static string FormatClanList(HashSet<string> clans)
		{
			if (clans == null || clans.Count <= 0)
			{
				return "No clans in alliance.";
			}
			return string.Join(", ", clans.Select((string clan) => "<color=green>" + clan + "</color>"));
		}

		public static void ListAllianceClansByName(ChatCommandContext ctx, string name, Dictionary<string, HashSet<string>> playerAlliances)
		{
			//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_000e: 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_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_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_0040: Unknown result type (might be due to invalid IL or missing references)
			Entity val = ClanService.GetAllWithName(name).FirstOrDefault();
			if (!((Entity)(ref val)).Equals(Entity.Null))
			{
				ClanTeam val2 = EntityUtil.Read<ClanTeam>(val);
				_ = ((FixedString64Bytes)(ref val2.Name)).Value;
				Guid clanGuid = EntityUtil.Read<ClanTeam>(val).ClanGuid;
				KeyValuePair<string, HashSet<string>> alliance = playerAlliances.FirstOrDefault((KeyValuePair<string, HashSet<string>> a) => a.Value.Contains(((object)Unsafe.As<Guid, Guid>(ref clanGuid)/*cast due to .constrained prefix*/).ToString()));
				if (alliance.Value != null)
				{
					string text = FormatAllianceDetails(alliance, playerAlliances);
					ctx.Reply(text);
				}
				else
				{
					ctx.Reply("No alliance found.");
				}
			}
			else
			{
				ctx.Reply("Clan not found.");
			}
		}

		private static string FormatAllianceDetails(KeyValuePair<string, HashSet<string>> alliance, Dictionary<string, HashSet<string>> playerAlliances)
		{
			//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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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_009f: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: 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)
			string text = "\n";
			foreach (string clan in alliance.Value)
			{
				Entity byGUID = ClanService.GetByGUID(new Guid(clan));
				if ((from x in (from x in PlayerService.GetCachedUsersOnline()
						where EntityUtil.Has<ClanTeam>(EntityUtil.Read<User>(x).ClanEntity._Entity)
						select x).ToList()
					where EntityUtil.Read<ClanTeam>(EntityUtil.Read<User>(x).ClanEntity._Entity).ClanGuid == new Guid(clan)
					select x).ToList().Count == 0)
				{
					return text;
				}
				int clanLeaderIndex = AllianceValidation.GetClanLeaderIndex(EntityUtil.ReadBuffer<ClanMemberStatus>(byGUID));
				User leaderUser = EntityUtil.Read<User>(EntityUtil.ReadBuffer<SyncToUserBuffer>(byGUID)[clanLeaderIndex].UserEntity);
				text += FormatClanMemberList(byGUID, clan, alliance.Key, leaderUser);
			}
			return text;
		}

		private static string FormatClanMemberList(Entity entity, string clan, string allianceKey, User leaderUser)
		{
			//IL_000d: 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_0013: 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)
			ClanTeam val = EntityUtil.Read<ClanTeam>(entity);
			string value = ((FixedString64Bytes)(ref val.Name)).Value;
			string text = "--- <color=#9cb730>" + value + "</color> ---\n";
			List<Entity> members = (from x in (from x in PlayerService.GetCachedUsersOnline()
					where EntityUtil.Has<ClanTeam>(EntityUtil.Read<User>(x).ClanEntity._Entity)
					select x).ToList()
				where EntityUtil.Read<ClanTeam>(EntityUtil.Read<User>(x).ClanEntity._Entity).ClanGuid == new Guid(clan)
				select x).ToList();
			return text + FormatMemberList(members, clan, allianceKey, leaderUser);
		}

		private static string FormatMemberList(List<Entity> members, string clan, string allianceKey, User leaderUser)
		{
			//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_0032: 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)
			string text = "";
			for (int i = 0; i < members.Count(); i++)
			{
				text += $"<color=#309CB7>{EntityUtil.Read<User>(members[i]).CharacterName}</color>";
				if (EntityUtil.Read<User>(members[i]) == leaderUser)
				{
					text += ((clan == allianceKey) ? "<color=#b7309c> [A]</color>" : "<color=#b7309c> [C]</color>");
				}
				if (i != members.Count - 1)
				{
					text += ", ";
				}
			}
			return text + "\n";
		}
	}
	public static class AllianceValidation
	{
		public static bool CheckClanLeadership(ChatCommandContext ctx, Entity ownerClanEntity)
		{
			//IL_0002: 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)
			if (((Entity)(ref ownerClanEntity)).Equals(Entity.Null))
			{
				return true;
			}
			ClanRole val = default(ClanRole);
			if (EntityUtil.TryGetComponent<ClanRole>(ctx.Event.SenderUserEntity, ref val))
			{
				ref ClanRoleEnum value = ref val.Value;
				object obj = (object)(ClanRoleEnum)2;
				return !((object)Unsafe.As<ClanRoleEnum, ClanRoleEnum>(ref value)/*cast due to .constrained prefix*/).Equals(obj);
			}
			return false;
		}

		public static int GetClanLeaderIndex(DynamicBuffer<ClanMemberStatus> clanBuffer)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < clanBuffer.Length; i++)
			{
				ClanMemberStatus val = clanBuffer[i];
				ref ClanRoleEnum clanRole = ref val.ClanRole;
				object obj = (object)(ClanRoleEnum)2;
				if (((object)Unsafe.As<ClanRoleEnum, ClanRoleEnum>(ref clanRole)/*cast due to .constrained prefix*/).Equals(obj))
				{
					return i;
				}
			}
			return -1;
		}

		public static User GetClanLeader(Entity clan)
		{
			//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_000c: 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_0012: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			int clanLeaderIndex = GetClanLeaderIndex(EntityUtil.ReadBuffer<ClanMemberStatus>(clan));
			return EntityUtil.Read<User>(EntityUtil.ReadBuffer<SyncToUserBuffer>(clan)[clanLeaderIndex].UserEntity);
		}

		public static bool ValidateTargetInput(ChatCommandContext ctx, string target, string name)
		{
			if (string.IsNullOrEmpty(target))
			{
				return true;
			}
			target = target.ToLower();
			switch (target)
			{
			default:
				ctx.Reply("You must specify whether you're targeting a clan or a player.");
				return false;
			case "clan":
			case "player":
			case "c":
			case "p":
				if (string.IsNullOrEmpty(name))
				{
					ctx.Reply("Missing name of target " + target);
					return false;
				}
				return true;
			}
		}

		public static string ResolvePlayerClanName(ChatCommandContext ctx, string playerName)
		{
			//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_001e: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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)
			Player val = default(Player);
			if (!PlayerService.TryFindByName(playerName, ref val))
			{
				ctx.Reply("Target player could not be found.");
				return null;
			}
			Entity user = val.User;
			if (!EntityUtil.Has<ClanTeam>(EntityUtil.Read<User>(user).ClanEntity._Entity))
			{
				ctx.Reply("Target player is not in a clan.");
				return null;
			}
			ClanTeam val2 = EntityUtil.Read<ClanTeam>(EntityUtil.Read<User>(user).ClanEntity._Entity);
			return ((FixedString64Bytes)(ref val2.Name)).Value;
		}
	}
}
namespace CrimsonAlliance.Structs
{
	public class Database
	{
		public static readonly JsonSerializerOptions prettyJsonOptions = new JsonSerializerOptions
		{
			WriteIndented = true,
			IncludeFields = true
		};

		public static string DisabledFile = Path.Combine(FilePaths.WipeData, "calliancees_disabled_invites.json");

		public static string AllianceFile = Path.Combine(FilePaths.WipeData, "calliances_alliancelist.json");

		public static List<ulong> Disabled;

		public static Dictionary<string, HashSet<string>> ClanAlliances = new Dictionary<string, HashSet<string>>();

		public Database()
		{
			LoadDatabases();
		}

		private static void LoadDatabases()
		{
			try
			{
				if (File.Exists(DisabledFile))
				{
					Disabled = JsonSerializer.Deserialize<List<ulong>>(File.ReadAllText(DisabledFile), prettyJsonOptions);
				}
				else
				{
					Disabled = new List<ulong>();
				}
			}
			catch
			{
				Disabled = new List<ulong>();
			}
			try
			{
				if (File.Exists(AllianceFile))
				{
					ClanAlliances = JsonSerializer.Deserialize<Dictionary<string, HashSet<string>>>(File.ReadAllText(AllianceFile), prettyJsonOptions);
				}
				else
				{
					ClanAlliances = new Dictionary<string, HashSet<string>>();
				}
			}
			catch
			{
				ClanAlliances = new Dictionary<string, HashSet<string>>();
			}
			Core.StartCoroutine(Clean());
		}

		private static IEnumerator Clean()
		{
			while (true)
			{
				yield return (object)new WaitForSeconds(10f);
				AllianceInvites.Cleanup();
				SaveDisabled();
			}
		}

		public static void SaveClanAlliances()
		{
			string contents = JsonSerializer.Serialize(ClanAlliances, prettyJsonOptions);
			File.WriteAllText(AllianceFile, contents);
		}

		public static void SaveDisabled()
		{
			string contents = JsonSerializer.Serialize(Disabled, prettyJsonOptions);
			File.WriteAllText(DisabledFile, contents);
		}
	}
	public class InviteRequest
	{
		public DateTime ExpiresAt = DateTime.Now.AddMinutes(Settings.InviteExpiration.Value);

		public User Inviter { get; set; }

		public Entity InviterClanEntity { get; set; }

		public string InviterClanName { get; set; }

		public string InvitedClanName { get; set; }

		public User InvitedClanLeader { get; set; }

		public Entity InvitedClanEntity { get; set; }

		public string ToInvitedString()
		{
			//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)
			return $"{Inviter.CharacterName} has invited you to join their alliance. Use \".alliance accept\" to join or \".alliance decline\" to reject.";
		}

		public string ToInviterString()
		{
			//IL_0032: 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)
			return $"You have invited {InvitedClanName} to join your alliance. The request was sent to their leader, {InvitedClanLeader.CharacterName}.";
		}

		public string InvitedResponseAcceptedString()
		{
			//IL_0019: 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)
			return $"You have accepted {Inviter.CharacterName}'s invitation to join their alliance.";
		}

		public string InvitedResponseDeniedString()
		{
			//IL_0019: 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)
			return $"You have declined {Inviter.CharacterName}'s invitation to join their alliance.";
		}

		public string InviterResponseAcceptedString()
		{
			return InvitedClanName + " has accepted the invitation to join your alliance.";
		}

		public string InviterResponseDeniedString()
		{
			return InvitedClanName + " has declined the invitation to join your alliance.";
		}

		public string ToInvitedExpiredString()
		{
			//IL_0019: 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)
			return $"Your invitation from {Inviter.CharacterName} to join an alliance has expired.";
		}

		public string ToInviterExpiredString()
		{
			return "Your invitation for " + InvitedClanName + " to join your alliance has expired.";
		}

		public bool IsExpired()
		{
			return ExpiresAt < DateTime.Now;
		}
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	public readonly struct Settings
	{
		public static ConfigEntry<int> PreRaidBuffer;

		public static ConfigEntry<int> PostRaidBuffer;

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

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

		public static ConfigEntry<int> MaxAllianceSize { get; private set; }

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

		public static ConfigEntry<int> InviteExpiration { get; private set; }

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

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

		public static bool InitConfig()
		{
			foreach (string directoryPath in directoryPaths)
			{
				CreateDirectories(directoryPath);
			}
			ToggleMod = InitConfigEntry("General", "ToggleMod", defaultValue: true, "Enable or disable the mod.");
			FriendlyFireWorld = InitConfigEntry("Alliance", "FriendlyFire", defaultValue: true, "False to prevent damage between players in alliance outside of raids, true to allow.");
			MaxAllianceSize = InitConfigEntry("Alliance", "MaxAllianceSize", 2, "The maximum number of clans allowed in an alliance.");
			InviteExpiration = InitConfigEntry("Alliance", "InviteExpiration", 5, "The number of minutes before an invite expires.");
			AllianceChatColor = InitConfigEntry("Alliance", "ChatColor", "#e8515e", "The color of the alliance chat messages.");
			if (InviteExpiration.Value < 1)
			{
				InviteExpiration.Value = 1;
			}
			LockOperations = InitConfigEntry("Alliance", "LockDuringRaidWindow", defaultValue: true, "Lock alliance operations during raid windows.");
			PreRaidBuffer = InitConfigEntry("Buffers", "PreRaidBufferMins", 30, "The number of minutes prior to the raid window to lock alliance operations.");
			PostRaidBuffer = InitConfigEntry("Buffers", "PostRaidBufferMins", 0, "The number of minutes past the raid window to lock alliance operations.");
			return ToggleMod.Value;
		}

		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, "CrimsonAlliance.cfg");
			ConfigEntry<T> val2 = default(ConfigEntry<T>);
			if (File.Exists(text) && new ConfigFile(text, true).TryGetEntry<T>(section, key, ref val2))
			{
				val.Value = val2.Value;
			}
			return val;
		}

		private static void CreateDirectories(string path)
		{
			if (!Directory.Exists(path))
			{
				Directory.CreateDirectory(path);
			}
		}
	}
}
namespace CrimsonAlliance.Services
{
	public class AllianceService
	{
		public unsafe bool AddClanToAlliance(Entity clanEntity, HashSet<string> alliance)
		{
			//IL_0014: 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)
			if (alliance.Count >= Settings.MaxAllianceSize.Value)
			{
				return false;
			}
			ClanTeam val = EntityUtil.Read<ClanTeam>(clanEntity);
			string item = ((object)(*(Guid*)(&val.ClanGuid))/*cast due to .constrained prefix*/).ToString();
			alliance.Add(item);
			Database.SaveClanAlliances();
			return true;
		}

		public unsafe bool RemoveClanFromAlliance(Entity clanEntity, HashSet<string> alliance)
		{
			//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 val = EntityUtil.Read<ClanTeam>(clanEntity);
			string guid = ((object)(*(Guid*)(&val.ClanGuid))/*cast due to .constrained prefix*/).ToString();
			return RemoveClanFromAlliance(guid, alliance);
		}

		public unsafe bool RemoveClanFromAlliance(string guid, HashSet<string> alliance)
		{
			//IL_0067: 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)
			string allianceOwnerGuid = Database.ClanAlliances.FirstOrDefault((KeyValuePair<string, HashSet<string>> x) => x.Value == alliance).Key;
			bool num = alliance.Remove(guid);
			if (num && alliance.Count == 1 && allianceOwnerGuid != null)
			{
				Entity anyClan = ClanService.GetAll().FirstOrDefault((Func<Entity, bool>)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)
					ClanTeam val = EntityUtil.Read<ClanTeam>(x);
					return ((object)(*(Guid*)(&val.ClanGuid))/*cast due to .constrained prefix*/).ToString() == allianceOwnerGuid;
				});
				NotifyAllianceDisbaned(anyClan);
				Database.ClanAlliances.Remove(allianceOwnerGuid);
				Database.SaveClanAlliances();
			}
			return num;
		}

		public unsafe List<Entity> GetAllAllianceMembers(Entity clanEntity)
		{
			//IL_000e: 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_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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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_0083: 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_0096: 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_009f: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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)
			List<Entity> list = new List<Entity>();
			if (((Entity)(ref clanEntity)).Equals(Entity.Null))
			{
				return list;
			}
			ClanTeam val = EntityUtil.Read<ClanTeam>(clanEntity);
			string clanGuid = ((object)(*(Guid*)(&val.ClanGuid))/*cast due to .constrained prefix*/).ToString();
			KeyValuePair<string, HashSet<string>> keyValuePair = Database.ClanAlliances.FirstOrDefault((KeyValuePair<string, HashSet<string>> a) => a.Value.Contains(clanGuid));
			if (keyValuePair.Value != null)
			{
				foreach (string item in keyValuePair.Value)
				{
					Entity byGUID = ClanService.GetByGUID(new Guid(item));
					if (((Entity)(ref byGUID)).Equals(Entity.Null))
					{
						continue;
					}
					Enumerator<SyncToUserBuffer> enumerator2 = EntityUtil.ReadBuffer<SyncToUserBuffer>(byGUID).GetEnumerator();
					while (enumerator2.MoveNext())
					{
						Entity userEntity = enumerator2.Current.UserEntity;
						if (!((Entity)(ref userEntity)).Equals(Entity.Null))
						{
							list.Add(userEntity);
						}
					}
				}
			}
			return list;
		}

		public bool IsClanEligibleForAlliance(User leaderUser, string clanName)
		{
			//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_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_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_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)
			Entity val = ClanService.GetAllWithName(clanName).FirstOrDefault((Func<Entity, bool>)((Entity x) => ClanService.GetClanLeader(x) == leaderUser));
			Guid guid = EntityUtil.Read<ClanTeam>(val).ClanGuid;
			if (Database.ClanAlliances.ContainsKey(((object)Unsafe.As<Guid, Guid>(ref guid)/*cast due to .constrained prefix*/).ToString()) || Database.ClanAlliances.Values.Any((HashSet<string> alliance) => alliance.Contains(((object)Unsafe.As<Guid, Guid>(ref guid)/*cast due to .constrained prefix*/).ToString())))
			{
				return false;
			}
			return true;
		}

		public unsafe List<string> GetAllianceClanNames(Entity clanEntity)
		{
			//IL_000e: 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_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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_007f: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			List<string> list = new List<string>();
			if (((Entity)(ref clanEntity)).Equals(Entity.Null))
			{
				return list;
			}
			ClanTeam val = EntityUtil.Read<ClanTeam>(clanEntity);
			string clanGuid = ((object)(*(Guid*)(&val.ClanGuid))/*cast due to .constrained prefix*/).ToString();
			KeyValuePair<string, HashSet<string>> keyValuePair = Database.ClanAlliances.FirstOrDefault((KeyValuePair<string, HashSet<string>> a) => a.Value.Contains(clanGuid));
			if (keyValuePair.Value != null)
			{
				foreach (string item in keyValuePair.Value)
				{
					Entity byGUID = ClanService.GetByGUID(new Guid(item));
					val = EntityUtil.Read<ClanTeam>(byGUID);
					list.Add(((FixedString64Bytes)(ref val.Name)).Value);
				}
			}
			return list;
		}

		public unsafe void NotifyPlayerLeftClan(User user, NetworkId clanId)
		{
			//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_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_0026: 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_002c: 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_0035: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			IEnumerable<Entity> all = ClanService.GetAll();
			Entity clan = Entity.Null;
			foreach (Entity item in all)
			{
				NetworkId val = EntityUtil.Read<NetworkId>(item);
				if (((NetworkId)(ref val)).Equals(clanId))
				{
					clan = item;
					break;
				}
			}
			if (((Entity)(ref clan)).Equals(Entity.Null))
			{
				return;
			}
			if ((from x in (from x in PlayerService.GetCachedUsersOnline()
					where EntityUtil.Has<ClanTeam>(EntityUtil.Read<User>(x).ClanEntity._Entity)
					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_0014: Unknown result type (might be due to invalid IL or missing references)
					User val2 = EntityUtil.Read<User>(x);
					return ((Entity)(ref val2.ClanEntity._Entity)).Equals(clan);
				})
				where EntityUtil.Read<User>(x).PlatformId != user.PlatformId
				select x).ToList().Count > 0)
			{
				foreach (Entity allAllianceMember in GetAllAllianceMembers(clan))
				{
					ChatUtil.SystemSendUser(EntityUtil.Read<User>(allAllianceMember), ((object)(*(FixedString64Bytes*)(&user.CharacterName))/*cast due to .constrained prefix*/).ToString() + " has left the alliance.");
				}
				return;
			}
			KeyValuePair<string, HashSet<string>> keyValuePair = Database.ClanAlliances.FirstOrDefault(delegate(KeyValuePair<string, HashSet<string>> a)
			{
				//IL_0008: 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_0012: Unknown result type (might be due to invalid IL or missing references)
				HashSet<string> value = a.Value;
				ClanTeam val2 = EntityUtil.Read<ClanTeam>(clan);
				return value.Contains(((object)(*(Guid*)(&val2.ClanGuid))/*cast due to .constrained prefix*/).ToString());
			});
			RemoveClanFromAlliance(clan, keyValuePair.Value);
		}

		public unsafe void NotifyPlayerLeftClan(User user, ClanTeam clanId)
		{
			//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_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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Expected O, but got Unknown
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Expected O, but got Unknown
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			ManualLogSource logInstance = Plugin.LogInstance;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(28, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("NotifyPlayerLeftClan: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((object)(*(FixedString64Bytes*)(&user.CharacterName))/*cast due to .constrained prefix*/).ToString());
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" left ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((FixedString64Bytes)(ref clanId.Name)).Value);
			}
			logInstance.LogInfo(val);
			List<Entity> list = (from x in (from x in PlayerService.GetCachedUsersOnline()
					where EntityUtil.Has<ClanTeam>(EntityUtil.Read<User>(x).ClanEntity._Entity)
					select x).ToList()
				where EntityUtil.Read<ClanTeam>(EntityUtil.Read<User>(x).ClanEntity._Entity).ClanGuid == clanId.ClanGuid
				where EntityUtil.Read<User>(x).PlatformId != user.PlatformId
				select x).ToList();
			ManualLogSource logInstance2 = Plugin.LogInstance;
			val = new BepInExInfoLogInterpolatedStringHandler(37, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("NotifyPlayerLeftClan: Members Count: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(list.Count);
			}
			logInstance2.LogInfo(val);
			if (!Database.ClanAlliances.Any((KeyValuePair<string, HashSet<string>> a) => a.Value.Contains(((object)(*(Guid*)(&clanId.ClanGuid))/*cast due to .constrained prefix*/).ToString())))
			{
				return;
			}
			if (list.Count > 0)
			{
				ManualLogSource logInstance3 = Plugin.LogInstance;
				val = new BepInExInfoLogInterpolatedStringHandler(71, 0, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("NotifyPlayerLeftClan: Members left in clan. Not removing from alliance.");
				}
				logInstance3.LogInfo(val);
				{
					foreach (Entity allAllianceMember in GetAllAllianceMembers(EntityUtil.Read<User>(list[0]).ClanEntity._Entity))
					{
						ChatUtil.SystemSendUser(EntityUtil.Read<User>(allAllianceMember), $"{user.CharacterName} has left the alliance.");
					}
					return;
				}
			}
			ManualLogSource logInstance4 = Plugin.LogInstance;
			val = new BepInExInfoLogInterpolatedStringHandler(70, 0, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("NotifyPlayerLeftClan: No members left in clan. Removing from alliance.");
			}
			logInstance4.LogInfo(val);
			KeyValuePair<string, HashSet<string>> keyValuePair = Database.ClanAlliances.FirstOrDefault((KeyValuePair<string, HashSet<string>> a) => a.Value.Contains(((object)(*(Guid*)(&clanId.ClanGuid))/*cast due to .constrained prefix*/).ToString()));
			if (keyValuePair.Value != null)
			{
				RemoveClanFromAlliance(((object)(*(Guid*)(&clanId.ClanGuid))/*cast due to .constrained prefix*/).ToString(), keyValuePair.Value);
			}
		}

		public unsafe void NotifyClanLeftAlliance(Entity clanEntity, HashSet<string> alliance)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			List<Entity> source = (from x in PlayerService.GetUsersOnline()
				where EntityUtil.Has<ClanTeam>(EntityUtil.Read<User>(x).ClanEntity._Entity)
				select x).ToList();
			IEnumerable<Entity> enumerable = source.Where(delegate(Entity x)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				HashSet<string> hashSet = alliance;
				ClanTeam val = EntityUtil.Read<ClanTeam>(EntityUtil.Read<User>(x).ClanEntity._Entity);
				return hashSet.Contains(((object)(*(Guid*)(&val.ClanGuid))/*cast due to .constrained prefix*/).ToString());
			});
			ClanTeam left = EntityUtil.Read<ClanTeam>(clanEntity);
			foreach (Entity item in enumerable)
			{
				if (EntityUtil.Has<User>(item))
				{
					ChatUtil.SystemSendUser(EntityUtil.Read<User>(item), "Clan " + ((FixedString64Bytes)(ref left.Name)).Value + " has left the alliance.");
				}
			}
			foreach (Entity item2 in source.Where((Entity x) => EntityUtil.Read<ClanTeam>(EntityUtil.Read<User>(x).ClanEntity._Entity).ClanGuid == left.ClanGuid).ToList())
			{
				ChatUtil.SystemSendUser(EntityUtil.Read<User>(item2), "Your clan has left the alliance.");
			}
		}

		public void NotifyAllianceDisbaned(Entity anyClan)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			foreach (Entity allAllianceMember in GetAllAllianceMembers(anyClan))
			{
				if (EntityUtil.Has<User>(allAllianceMember))
				{
					ChatUtil.SystemSendUser(EntityUtil.Read<User>(allAllianceMember), "Your alliance has been disbanded.");
				}
			}
		}

		public void NotifyAllianceKicked(Entity leavingClan, Entity ownerEntity)
		{
			//IL_0007: 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_0023: 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_0029: 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)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			List<Entity> allAllianceMembers = GetAllAllianceMembers(ownerEntity);
			ClanTeam kicked = EntityUtil.Read<ClanTeam>(leavingClan);
			foreach (Entity item in allAllianceMembers)
			{
				if (EntityUtil.Has<User>(item))
				{
					ChatUtil.SystemSendUser(EntityUtil.Read<User>(item), "Your clan has been kicked from the alliance.");
				}
			}
			foreach (Entity item2 in (from x in (from x in PlayerService.GetUsersOnline()
					where EntityUtil.Has<ClanTeam>(EntityUtil.Read<User>(x).ClanEntity._Entity)
					select x).ToList()
				where EntityUtil.Read<ClanTeam>(EntityUtil.Read<User>(x).ClanEntity._Entity).ClanGuid == kicked.ClanGuid
				select x).ToList())
			{
				ChatUtil.SystemSendUser(EntityUtil.Read<User>(item2), "Your clan has been kicked from the alliance.");
			}
		}
	}
	internal class ModTalkService
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static ModTalkDelegate <0>__HandleModTalk;
		}

		public ModTalkService()
		{
			//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_0021: Expected O, but got Unknown
			object obj = <>O.<0>__HandleModTalk;
			if (obj == null)
			{
				ModTalkDelegate val = HandleModTalk;
				<>O.<0>__HandleModTalk = val;
				obj = (object)val;
			}
			ModTalk.MessageReceived += (ModTalkDelegate)obj;
		}

		private static bool HandleModTalk(string identifier, object[] args = null, Action<object> callback = null)
		{
			if (!(identifier == "CrimsonAlliance.InAlliance"))
			{
				if (identifier == "CrimsonAlliance.GetClans")
				{
					return HandleGetClans(args, callback);
				}
				return false;
			}
			return HandleInAlliance(args, callback);
		}

		private static bool HandleInAlliance(object[] args, Action<object> callback)
		{
			if (args == null || args.Length == 0)
			{
				callback?.Invoke(false);
				return true;
			}
			try
			{
				string text = args[0].ToString();
				if (!Guid.TryParse(text, out var _))
				{
					callback?.Invoke(false);
					return true;
				}
				HashSet<string> clanAlliance = API.GetClanAlliance(text);
				bool flag = clanAlliance != null && clanAlliance.Count > 1;
				callback?.Invoke(flag);
				return true;
			}
			catch
			{
				callback?.Invoke(false);
				return true;
			}
		}

		private static bool HandleGetClans(object[] args, Action<object> callback)
		{
			//IL_008a: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			if (args == null || args.Length == 0)
			{
				callback?.Invoke(new string[0]);
				return true;
			}
			try
			{
				string text = args[0].ToString();
				if (!Guid.TryParse(text, out var _))
				{
					callback?.Invoke(new string[0]);
					return true;
				}
				HashSet<string> clanAlliance = API.GetClanAlliance(text);
				if (clanAlliance == null || clanAlliance.Count == 0)
				{
					callback?.Invoke(new string[0]);
					return true;
				}
				List<string> list = new List<string>();
				string text2 = null;
				foreach (string item in clanAlliance)
				{
					try
					{
						Entity byGUID = ClanService.GetByGUID(new Guid(item));
						if (!((Entity)(ref byGUID)).Equals(Entity.Null))
						{
							ClanTeam val = EntityUtil.Read<ClanTeam>(byGUID);
							string value = ((FixedString64Bytes)(ref val.Name)).Value;
							if (item == text || Database.ClanAlliances.ContainsKey(item))
							{
								text2 = value;
							}
							else
							{
								list.Add(value);
							}
						}
					}
					catch
					{
					}
				}
				List<string> list2 = new List<string>();
				if (!string.IsNullOrEmpty(text2))
				{
					list2.Add(text2);
				}
				list2.AddRange(list);
				callback?.Invoke(list2.ToArray());
				return true;
			}
			catch
			{
				callback?.Invoke(new string[0]);
				return true;
			}
		}
	}
}
namespace CrimsonAlliance.Commands
{
	[CommandGroup("alliance", "ally")]
	internal static class AllianceCommands
	{
		[Command("Invites", null, null, null, null, false)]
		public static void ToggleInvites(ChatCommandContext ctx, string toggle = "off")
		{
			//IL_00d0: 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)
			toggle = ValidateToggleInputs(toggle);
			if (toggle != "on" && toggle != "off")
			{
				ctx.Reply("Invalid input. Please enter 'on' or 'off'.");
				return;
			}
			if (Database.Disabled == null)
			{
				Database.Disabled = new List<ulong>();
			}
			if (Database.Disabled.Exists((ulong x) => x == ctx.User.PlatformId))
			{
				if (toggle == "on")
				{
					Database.Disabled.Remove(ctx.User.PlatformId);
					Database.SaveDisabled();
					ctx.Reply("Alliance Invites are now active.");
				}
				else
				{
					ctx.Reply("Alliance Invites are already disabled.");
				}
			}
			else if (toggle == "off")
			{
				Database.Disabled.Add(ctx.User.PlatformId);
				Database.SaveDisabled();
				ctx.Reply("Alliance Invites are now disabled.");
			}
			else
			{
				ctx.Reply("Alliance Invites are already active.");
			}
		}

		private static string ValidateToggleInputs(string toggle)
		{
			toggle = toggle.ToLower().Trim().Replace(" ", "");
			switch (toggle)
			{
			case "on":
			case "yes":
			case "true":
			case "active":
				toggle = "on";
				break;
			case "no":
			case "off":
			case "false":
			case "inactive":
				toggle = "off";
				break;
			}
			return toggle;
		}

		[Command("Invite", null, "\"(clan)\"", "Invites clan to alliance.", null, false)]
		public static void AllianceInviteCommand(ChatCommandContext ctx, string name)
		{
			//IL_002b: 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_003c: 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_0049: 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_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: 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_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			if (Settings.LockOperations.Value && RaidTime.IsRaidTimeNow())
			{
				ctx.Reply("Alliance operations are currently locked for raid time.");
				return;
			}
			_ = ctx.Event.User;
			Entity entity = ctx.Event.User.ClanEntity._Entity;
			if (((Entity)(ref entity)).Equals(Entity.Null))
			{
				ctx.Reply("You must join a clan to be apart of an alliance.");
				return;
			}
			if (AllianceValidation.CheckClanLeadership(ctx, entity))
			{
				ctx.Reply("You must be the leader of a clan to form an alliance.");
				return;
			}
			IEnumerable<Entity> allWithName = ClanService.GetAllWithName(name);
			if (allWithName.Count() > 1)
			{
				string text = "There are multiple clans with the name " + name + ". Please specify the clan you wish to invite by including the clan leader name.";
				foreach (Entity item in allWithName)
				{
					if (EntityUtil.Exists(item))
					{
						User clanLeader = AllianceValidation.GetClanLeader(item);
						text += $"\n.alliance invite {name} {clanLeader.CharacterName}";
					}
				}
				ctx.Reply(text);
				return;
			}
			Entity val = allWithName.First();
			if (((Entity)(ref val)).Equals(Entity.Null))
			{
				ctx.Reply("Clan not found.");
				return;
			}
			if (AllianceInvites.IsEligibleToSendInvite(ctx.Event.User))
			{
				ClanTeam val2 = EntityUtil.Read<ClanTeam>(entity);
				if (AllianceInvites.IsEligibleToReceiveInvite(((FixedString64Bytes)(ref val2.Name)).Value))
				{
					if (!AllianceInvites.IsEligibleToReceiveInvite(name))
					{
						ctx.Reply("You cannot invite a clan to an alliance while they have an open invite.");
						return;
					}
					User targetLeader = AllianceValidation.GetClanLeader(allWithName.First());
					if (!targetLeader.IsConnected)
					{
						ctx.Reply("The leader of the clan you attempted to invite is not online.");
						return;
					}
					if (Database.Disabled == null)
					{
						Database.Disabled = new List<ulong>();
					}
					if (Database.Disabled.Exists((ulong x) => x == targetLeader.PlatformId))
					{
						ctx.Reply("The clan you attempted to invite currently has invites disabled.");
						return;
					}
					InviteRequest inviteRequest = AllianceInvites.CreateInvite(ctx.Event.User, entity, name, allWithName.First(), targetLeader);
					ChatUtil.SystemSendUser(targetLeader, inviteRequest.ToInvitedString());
					ctx.Reply(inviteRequest.ToInviterString());
					return;
				}
			}
			ctx.Reply("You cannot invite a clan to an alliance while you have an open invite.");
		}

		[Command("Invite", null, "\"(clan)\"", "Invites clan to alliance.", null, false)]
		public static void AllianceInviteCommand(ChatCommandContext ctx, string name, string leader)
		{
			//IL_002b: 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_003c: 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_0049: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: 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_00c4: 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_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			if (Settings.LockOperations.Value && RaidTime.IsRaidTimeNow())
			{
				ctx.Reply("Alliance operations are currently locked for raid time.");
				return;
			}
			_ = ctx.Event.User;
			Entity entity = ctx.Event.User.ClanEntity._Entity;
			if (((Entity)(ref entity)).Equals(Entity.Null))
			{
				ctx.Reply("You must join a clan to be apart of an alliance.");
				return;
			}
			if (AllianceValidation.CheckClanLeadership(ctx, entity))
			{
				ctx.Reply("You must be the leader of a clan to form an alliance.");
				return;
			}
			IEnumerable<Entity> allWithName = ClanService.GetAllWithName(name);
			Entity val = Entity.Null;
			if (allWithName.Count() > 1)
			{
				_ = "There are multiple clans with the name " + name + ". Please specify the clan you wish to invite by including the clan leader name.";
				foreach (Entity item in allWithName)
				{
					if (EntityUtil.Exists(item))
					{
						User clanLeader = AllianceValidation.GetClanLeader(allWithName.First());
						if (((FixedString64Bytes)(ref clanLeader.CharacterName)).Value == leader)
						{
							val = item;
							break;
						}
					}
				}
			}
			if (((Entity)(ref val)).Equals(Entity.Null))
			{
				ctx.Reply("Clan not found.");
				return;
			}
			if (AllianceInvites.IsEligibleToSendInvite(ctx.Event.User))
			{
				ClanTeam val2 = EntityUtil.Read<ClanTeam>(entity);
				if (AllianceInvites.IsEligibleToReceiveInvite(((FixedString64Bytes)(ref val2.Name)).Value))
				{
					if (!AllianceInvites.IsEligibleToReceiveInvite(name))
					{
						ctx.Reply("You cannot invite a clan to an alliance while they have an open invite.");
						return;
					}
					User targetLeader = AllianceValidation.GetClanLeader(val);
					if (!targetLeader.IsConnected)
					{
						ctx.Reply("The leader of the clan you attempted to invite is not online.");
						return;
					}
					if (Database.Disabled == null)
					{
						Database.Disabled = new List<ulong>();
					}
					if (Database.Disabled.Exists((ulong x) => x == targetLeader.PlatformId))
					{
						ctx.Reply("The clan you attempted to invite currently has invites disabled.");
						return;
					}
					InviteRequest inviteRequest = AllianceInvites.CreateInvite(ctx.Event.User, entity, name, val, targetLeader);
					ChatUtil.SystemSendUser(targetLeader, inviteRequest.ToInvitedString());
					ctx.Reply(inviteRequest.ToInviterString());
					return;
				}
			}
			ctx.Reply("You cannot invite a clan to an alliance while you have an open invite.");
		}

		[Command("Accept", null, null, "Accepts alliance invite.", null, false)]
		public static void AllianceAcceptCommand(ChatCommandContext ctx)
		{
			//IL_0063: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			if (Settings.LockOperations.Value && RaidTime.IsRaidTimeNow())
			{
				ctx.Reply("Alliance operations are currently locked for raid time.");
				return;
			}
			InviteRequest inviteRequest = AllianceInvites.Open.FirstOrDefault((InviteRequest x) => x.InvitedClanLeader == ctx.Event.User);
			if (inviteRequest == null)
			{
				ctx.Reply("You do not have an open invite.");
				return;
			}
			if (AllianceValidation.CheckClanLeadership(ctx, inviteRequest.InviterClanEntity))
			{
				ctx.Reply("You must be the leader of a clan to accept an alliance invite.");
				return;
			}
			AllianceManagement.HandleClanAlliance(inviteRequest.Inviter, inviteRequest.InvitedClanName);
			ChatUtil.SystemSendUser(inviteRequest.Inviter, inviteRequest.InviterResponseAcceptedString());
			ctx.Reply(inviteRequest.InvitedResponseAcceptedString());
			AllianceInvites.Open.Remove(inviteRequest);
		}

		[Command("Decline", null, null, "Declines alliance invite.", null, false)]
		public static void AllianceDeclineCommand(ChatCommandContext ctx)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			InviteRequest inviteRequest = AllianceInvites.Open.FirstOrDefault((InviteRequest x) => x.InvitedClanLeader == ctx.Event.User);
			if (inviteRequest == null)
			{
				ctx.Reply("You do not have an open invite.");
				return;
			}
			ChatUtil.SystemSendUser(inviteRequest.Inviter, inviteRequest.InviterResponseDeniedString());
			ctx.Reply(inviteRequest.InvitedResponseDeniedString());
			AllianceInvites.Open.Remove(inviteRequest);
		}

		[Command("Kick", null, "\"(clan)\"", "Removes clan from alliance.", null, false)]
		public unsafe static void AllianceRemoveCommand(ChatCommandContext ctx, string name)
		{
			//IL_0025: 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_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_0080: 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_0086: 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_00ad: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			if (Settings.LockOperations.Value && RaidTime.IsRaidTimeNow())
			{
				ctx.Reply("Alliance operations are currently locked for raid time.");
				return;
			}
			_ = ctx.Event.User;
			Entity entity = ctx.Event.User.ClanEntity._Entity;
			ClanTeam val;
			if (AllianceValidation.CheckClanLeadership(ctx, entity))
			{
				Dictionary<string, HashSet<string>> clanAlliances = Database.ClanAlliances;
				val = EntityUtil.Read<ClanTeam>(entity);
				if (clanAlliances.ContainsKey(((object)(*(Guid*)(&val.ClanGuid))/*cast due to .constrained prefix*/).ToString()))
				{
					ctx.Reply("You must be leader of the alliance to kick clans.");
					return;
				}
			}
			Dictionary<string, HashSet<string>> clanAlliances2 = Database.ClanAlliances;
			val = EntityUtil.Read<ClanTeam>(entity);
			HashSet<string> alliance = clanAlliances2[((object)(*(Guid*)(&val.ClanGuid))/*cast due to .constrained prefix*/).ToString()];
			Entity val2 = ClanService.GetAllWithName(name).FirstOrDefault();
			if (!((Entity)(ref val2)).Equals(Entity.Null) && Plugin.AllianceService.RemoveClanFromAlliance(val2, alliance))
			{
				Plugin.AllianceService.NotifyAllianceKicked(val2, entity);
				Database.SaveClanAlliances();
			}
			else
			{
				ctx.Reply("Clan " + name + " not found.");
			}
		}

		[Command("Status", "me", null, "Displays your alliance status.", null, false)]
		public static void AllianceStatusCommand(ChatCommandContext ctx)
		{
			AllianceMembersCommand(ctx);
		}

		[Command("Members", null, "[player/clan \"name\"]", "Lists alliance members of your alliance or the alliance you are in or the members in the alliance of the clan entered if found.", null, false)]
		public static void AllianceMembersCommand(ChatCommandContext ctx, string target = "", string name = "")
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (!AllianceValidation.ValidateTargetInput(ctx, target, name))
			{
				return;
			}
			Entity entity = ctx.Event.User.ClanEntity._Entity;
			if (string.IsNullOrEmpty(name) && string.IsNullOrEmpty(target))
			{
				if (((Entity)(ref entity)).Equals(Entity.Null))
				{
					ctx.Reply("You must join a clan to be apart of an alliance.");
					return;
				}
				User user = ctx.Event.User;
				name = AllianceValidation.ResolvePlayerClanName(ctx, ((FixedString64Bytes)(ref user.CharacterName)).Value);
				target = "c";
				if (name == null)
				{
					return;
				}
			}
			string text = target.ToLower();
			if ((text == "player" || text == "p") ? true : false)
			{
				name = AllianceValidation.ResolvePlayerClanName(ctx, name);
				if (name == null)
				{
					return;
				}
			}
			AllianceMembership.ListAllianceClansByName(ctx, name, Database.ClanAlliances);
		}

		[Command("Disband", null, null, "Disbands alliance.", null, false)]
		public unsafe static void DisbandAllianceCommand(ChatCommandContext ctx)
		{
			//IL_0025: 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_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_005b: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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)
			if (Settings.LockOperations.Value && RaidTime.IsRaidTimeNow())
			{
				ctx.Reply("Alliance operations are currently locked for raid time.");
				return;
			}
			_ = ctx.Event.User;
			Entity entity = ctx.Event.User.ClanEntity._Entity;
			if (AllianceValidation.CheckClanLeadership(ctx, entity))
			{
				ctx.Reply("You must be leader of alliance to disband it.");
				return;
			}
			Dictionary<string, HashSet<string>> clanAlliances = Database.ClanAlliances;
			ClanTeam val = EntityUtil.Read<ClanTeam>(entity);
			if (!clanAlliances.ContainsKey(((object)(*(Guid*)(&val.ClanGuid))/*cast due to .constrained prefix*/).ToString()))
			{
				ctx.Reply("You must be leader of alliance to disband it.");
				return;
			}
			Plugin.AllianceService.NotifyAllianceDisbaned(entity);
			Dictionary<string, HashSet<string>> clanAlliances2 = Database.ClanAlliances;
			val = EntityUtil.Read<ClanTeam>(entity);
			clanAlliances2.Remove(((object)(*(Guid*)(&val.ClanGuid))/*cast due to .constrained prefix*/).ToString());
			Database.SaveClanAlliances();
		}

		[Command("Leave", null, null, "Leaves alliance if in one.", null, false)]
		public unsafe static void LeaveAllianceCommand(ChatCommandContext ctx)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_0067: 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_008a: 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_00ba: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: 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_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			if (Settings.LockOperations.Value && RaidTime.IsRaidTimeNow())
			{
				ctx.Reply("Alliance operations are currently locked for raid time.");
				return;
			}
			_ = ctx.Event.User;
			Entity ownerClanEntity = ctx.Event.User.ClanEntity._Entity;
			User user = ctx.Event.User;
			_ = ((FixedString64Bytes)(ref user.CharacterName)).Value;
			if (AllianceValidation.CheckClanLeadership(ctx, ownerClanEntity))
			{
				ctx.Reply("You must be the leader of a clan to leave an alliance.");
				return;
			}
			Dictionary<string, HashSet<string>> clanAlliances = Database.ClanAlliances;
			ClanTeam val = EntityUtil.Read<ClanTeam>(ownerClanEntity);
			if (clanAlliances.ContainsKey(((object)(*(Guid*)(&val.ClanGuid))/*cast due to .constrained prefix*/).ToString()))
			{
				ctx.Reply("Disbanding alliance.");
				Plugin.AllianceService.NotifyAllianceDisbaned(ownerClanEntity);
				Dictionary<string, HashSet<string>> clanAlliances2 = Database.ClanAlliances;
				val = EntityUtil.Read<ClanTeam>(ownerClanEntity);
				clanAlliances2.Remove(((object)(*(Guid*)(&val.ClanGuid))/*cast due to .constrained prefix*/).ToString());
				Database.SaveClanAlliances();
				return;
			}
			HashSet<string> hashSet = Database.ClanAlliances.Values.FirstOrDefault(delegate(HashSet<string> set)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				ClanTeam val2 = EntityUtil.Read<ClanTeam>(ownerClanEntity);
				return set.Contains(((object)(*(Guid*)(&val2.ClanGuid))/*cast due to .constrained prefix*/).ToString());
			});
			if (hashSet != null)
			{
				if (Plugin.AllianceService.RemoveClanFromAlliance(ownerClanEntity, hashSet))
				{
					Plugin.AllianceService.NotifyClanLeftAlliance(ownerClanEntity, hashSet);
					val = EntityUtil.Read<ClanTeam>(ownerClanEntity);
					ctx.Reply("<color=green>" + ((FixedString64Bytes)(ref val.Name)).Value + " was removed from the alliance.</color>");
				}
				else
				{
					ctx.Reply("Clan not found in the alliance.");
				}
			}
			else
			{
				ctx.Reply("Your clan is not in an alliance.");
			}
		}
	}
}