Decompiled source of RaidGuard v1.0.2

RaidGuard.dll

Decompiled 4 months 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.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.CastleBuilding;
using ProjectM.Gameplay.Systems;
using ProjectM.Network;
using ProjectM.Physics;
using ProjectM.Scripting;
using RaidGuard.Services;
using Stunlock.Core;
using Stunlock.Network;
using Unity.Collections;
using Unity.Entities;
using Unity.Scenes;
using UnityEngine;
using VampireCommandFramework;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("RaidGuard")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+6697f4994765cc77e0fbf1ff5820cbca3d394676")]
[assembly: AssemblyProduct("RaidGuard")]
[assembly: AssemblyTitle("RaidGuard")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RaidGuard
{
	internal static class AllianceUtilities
	{
		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)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (((Entity)(ref ownerClanEntity)).Equals(Entity.Null))
			{
				return true;
			}
			Entity senderUserEntity = ctx.Event.SenderUserEntity;
			if (senderUserEntity.TryGetComponent<ClanRole>(out ClanRole componentData))
			{
				return !((object)(ClanRoleEnum)(ref componentData.Value)).Equals((object)(ClanRoleEnum)2);
			}
			return false;
		}

		public static void HandleClanAlliance(ChatCommandContext ctx, ulong ownerId, string name)
		{
			//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_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_002a: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			User user = ctx.Event.User;
			string value = ((FixedString64Bytes)(ref user.CharacterName)).Value;
			HashSet<string> ownerClanMembers = GetOwnerClanMembers(ctx.Event.User.ClanEntity._Entity);
			if (!Core.DataStructures.PlayerAlliances.ContainsKey(ownerId))
			{
				Core.DataStructures.PlayerAlliances[ownerId] = new HashSet<string>();
				HashSet<string> hashSet = Core.DataStructures.PlayerAlliances[ownerId];
				hashSet.Add(value);
				if (ownerClanMembers.Count > 0)
				{
					hashSet.UnionWith(ownerClanMembers);
				}
				Core.DataStructures.SavePlayerAlliances();
			}
			HashSet<string> alliance = Core.DataStructures.PlayerAlliances[ownerId];
			HashSet<string> members = new HashSet<string>();
			Entity clanByName = PlayerService.GetClanByName(name);
			if (((Entity)(ref clanByName)).Equals(Entity.Null))
			{
				ctx.Reply("Clan/leader not found...");
			}
			else if (TryAddClanMembers(ctx, ownerId, clanByName, members))
			{
				AddMembersToAlliance(ctx, alliance, members, ownerClanMembers);
			}
		}

		public static bool TryAddClanMembers(ChatCommandContext ctx, ulong ownerId, Entity clanEntity, HashSet<string> members)
		{
			//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_0007: 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)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0046: Unknown result type (might be due to invalid IL or missing references)
			DynamicBuffer<ClanMemberStatus> clanBuffer = clanEntity.ReadBuffer<ClanMemberStatus>();
			int clanLeaderIndex = GetClanLeaderIndex(clanBuffer);
			if (clanLeaderIndex == -1)
			{
				ctx.Reply("Couldn't find clan leader to verify consent.");
				return false;
			}
			DynamicBuffer<SyncToUserBuffer> val = clanEntity.ReadBuffer<SyncToUserBuffer>();
			for (int i = 0; i < val.Length; i++)
			{
				SyncToUserBuffer val2 = val[i];
				User leaderUser = val2.UserEntity.Read<User>();
				if (i == clanLeaderIndex && !IsLeaderEligibleForAlliance(leaderUser, ((FixedString64Bytes)(ref leaderUser.CharacterName)).Value))
				{
					ctx.Reply("Clan leader does not have alliances invites enabled.");
					return false;
				}
				members.Add(((FixedString64Bytes)(ref leaderUser.CharacterName)).Value);
			}
			return true;
		}

		public static HashSet<string> GetOwnerClanMembers(Entity ownerClanEntity)
		{
			//IL_0008: 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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			HashSet<string> hashSet = new HashSet<string>();
			if (!((Entity)(ref ownerClanEntity)).Equals(Entity.Null))
			{
				DynamicBuffer<SyncToUserBuffer> val = ownerClanEntity.ReadBuffer<SyncToUserBuffer>();
				for (int i = 0; i < val.Length; i++)
				{
					SyncToUserBuffer val2 = val[i];
					User val3 = val2.UserEntity.Read<User>();
					hashSet.Add(((FixedString64Bytes)(ref val3.CharacterName)).Value);
				}
			}
			return hashSet;
		}

		public static void RemoveClanFromAlliance(ChatCommandContext ctx, HashSet<string> alliance, string clanName)
		{
			//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_000f: 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)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			List<string> list = new List<string>();
			Entity clanByName = PlayerService.GetClanByName(clanName);
			if (((Entity)(ref clanByName)).Equals(Entity.Null))
			{
				ctx.Reply("Clan not found...");
				return;
			}
			foreach (string memberName in alliance)
			{
				string text = PlayerService.playerCache.Keys.FirstOrDefault((string key) => key.Equals(memberName, StringComparison.OrdinalIgnoreCase));
				if (!string.IsNullOrEmpty(text) && PlayerService.playerCache.TryGetValue(text, out var value))
				{
					Entity entity = value.Read<User>().ClanEntity._Entity;
					ClanTeam val = entity.Read<ClanTeam>();
					if (((FixedString64Bytes)(ref val.Name)).Value.Equals(clanName, StringComparison.OrdinalIgnoreCase))
					{
						alliance.Remove(memberName);
						list.Add(memberName);
					}
				}
			}
			string text2 = ((list.Count > 0) ? string.Join(", ", list.Select((string member) => "<color=green>" + member + "</color>")) : "No members from clan found to remove.");
			if (list.Count > 0)
			{
				text2 += " removed from alliance.";
			}
			ctx.Reply(text2);
			Core.DataStructures.SavePlayerAlliances();
		}

		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];
				if (((object)(ClanRoleEnum)(ref val.ClanRole)).Equals((object)(ClanRoleEnum)2))
				{
					return i;
				}
			}
			return -1;
		}

		public static bool IsLeaderEligibleForAlliance(User leaderUser, string leaderName)
		{
			//IL_0012: 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)
			if (Core.DataStructures.PlayerBools.TryGetValue(leaderUser.PlatformId, out var value) && value["AllianceInvites"] && !Core.DataStructures.PlayerAlliances.ContainsKey(leaderUser.PlatformId) && !Core.DataStructures.PlayerAlliances.Values.Any((HashSet<string> alliance) => alliance.Equals(leaderName)))
			{
				value["AllianceInvites"] = false;
				Core.DataStructures.SavePlayerBools();
				return true;
			}
			return false;
		}

		public static void AddMembersToAlliance(ChatCommandContext ctx, HashSet<string> alliance, HashSet<string> members, HashSet<string> ownerClanMembers)
		{
			int num = alliance.Count - ownerClanMembers.Count;
			if (members.Count > 0 && num + members.Count < Plugin.MaxAllianceSize.Value)
			{
				string text = string.Join(", ", members.Select((string member) => "<color=green>" + member + "</color>"));
				alliance.UnionWith(members);
				ctx.Reply(text + " were added to the alliance.");
				Core.DataStructures.SavePlayerAlliances();
			}
			else if (members.Count == 0)
			{
				ctx.Reply("Couldn't find any clan members to add.");
			}
			else
			{
				ctx.Reply("Alliance would exceed max size by adding found clan members.");
			}
		}

		public static void HandlePlayerAlliance(ChatCommandContext ctx, ulong ownerId, string name)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			string text = PlayerService.playerCache.Keys.FirstOrDefault((string key) => key.Equals(name, StringComparison.OrdinalIgnoreCase));
			if (!string.IsNullOrEmpty(text) && PlayerService.playerCache.TryGetValue(text, out var value))
			{
				if (((Entity)(ref value)).Equals(Entity.Null))
				{
					ctx.Reply("Player not found...");
					return;
				}
				User val = value.Read<User>();
				if (val.PlatformId == ownerId)
				{
					ctx.Reply("Player not found...");
					return;
				}
				string value2 = ((FixedString64Bytes)(ref val.CharacterName)).Value;
				if (IsPlayerEligibleForAlliance(val, value2))
				{
					HashSet<string> ownerClanMembers = GetOwnerClanMembers(ctx.Event.User.ClanEntity._Entity);
					if (ownerClanMembers.Count == 0)
					{
						User user = ctx.Event.User;
						ownerClanMembers.Add(((FixedString64Bytes)(ref user.CharacterName)).Value);
					}
					AddPlayerToAlliance(ctx, ownerId, value2, ownerClanMembers);
				}
				else
				{
					ctx.Reply("<color=green>" + value2 + "</color> does not have alliances enabled or is already in an alliance.");
				}
			}
			else
			{
				ctx.Reply("Player not found...");
			}
		}

		public static bool IsPlayerEligibleForAlliance(User foundUser, string playerName)
		{
			//IL_0012: 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)
			if (Core.DataStructures.PlayerBools.TryGetValue(foundUser.PlatformId, out var value) && value["AllianceInvites"] && !Core.DataStructures.PlayerAlliances.ContainsKey(foundUser.PlatformId) && !Core.DataStructures.PlayerAlliances.Values.Any((HashSet<string> alliance) => alliance.Equals(playerName)))
			{
				value["AllianceInvites"] = false;
				Core.DataStructures.SavePlayerBools();
				return true;
			}
			return false;
		}

		public static void AddPlayerToAlliance(ChatCommandContext ctx, ulong ownerId, string playerName, HashSet<string> ownerClanMembers)
		{
			//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)
			User user = ctx.Event.User;
			string value = ((FixedString64Bytes)(ref user.CharacterName)).Value;
			if (!Core.DataStructures.PlayerAlliances.ContainsKey(ownerId))
			{
				Core.DataStructures.PlayerAlliances[ownerId] = new HashSet<string>();
				HashSet<string> hashSet = Core.DataStructures.PlayerAlliances[ownerId];
				hashSet.Add(value);
				if (ownerClanMembers.Count > 0)
				{
					hashSet.UnionWith(ownerClanMembers);
				}
				Core.DataStructures.SavePlayerAlliances();
			}
			HashSet<string> hashSet2 = Core.DataStructures.PlayerAlliances[ownerId];
			int num = hashSet2.Count - ownerClanMembers.Count;
			if (num < Plugin.MaxAllianceSize.Value && !hashSet2.Contains(playerName))
			{
				hashSet2.Add(playerName);
				Core.DataStructures.SavePlayerAlliances();
				ctx.Reply("<color=green>" + playerName + "</color> added to alliance.");
			}
			else
			{
				ctx.Reply("Alliance is full or <color=green>" + playerName + "</color> is already in the alliance.");
			}
		}

		public static void RemovePlayerFromAlliance(ChatCommandContext ctx, HashSet<string> alliance, string playerName)
		{
			string playerKey = PlayerService.playerCache.Keys.FirstOrDefault((string key) => key.Equals(playerName, StringComparison.OrdinalIgnoreCase));
			if (!string.IsNullOrEmpty(playerKey) && alliance.FirstOrDefault((string n) => n.Equals(playerKey)) != null)
			{
				alliance.Remove(playerKey);
				Core.DataStructures.SavePlayerAlliances();
				string text = char.ToUpper(playerName[0]).ToString();
				string text2 = playerName;
				ctx.Reply("<color=green>" + text + text2.Substring(1, text2.Length - 1).ToLower() + "</color> removed from alliance.");
			}
			else
			{
				string text3 = char.ToUpper(playerName[0]).ToString();
				string text2 = playerName;
				ctx.Reply("<color=green>" + text3 + text2.Substring(1, text2.Length - 1).ToLower() + "</color> not found in alliance.");
			}
		}

		public static void ListPersonalAllianceMembers(ChatCommandContext ctx, Dictionary<ulong, HashSet<string>> playerAlliances)
		{
			//IL_000c: 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)
			ulong platformId = ctx.Event.User.PlatformId;
			User user = ctx.Event.User;
			string playerName = ((FixedString64Bytes)(ref user.CharacterName)).Value;
			HashSet<string> hashSet = (playerAlliances.ContainsKey(platformId) ? playerAlliances[platformId] : playerAlliances.Where((KeyValuePair<ulong, HashSet<string>> groupEntry) => groupEntry.Value.Contains(playerName)).SelectMany((KeyValuePair<ulong, HashSet<string>> groupEntry) => groupEntry.Value).ToHashSet());
			string text = ((hashSet.Count > 0) ? string.Join(", ", hashSet.Select((string member) => "<color=green>" + member + "</color>")) : "No members in alliance.");
			ctx.Reply(text);
		}

		public static void ListAllianceMembersByName(ChatCommandContext ctx, string name, Dictionary<ulong, HashSet<string>> playerAlliances)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			string text = PlayerService.playerCache.Keys.FirstOrDefault((string key) => key.Equals(name, StringComparison.OrdinalIgnoreCase));
			if (!string.IsNullOrEmpty(text) && PlayerService.playerCache.TryGetValue(text, out var value))
			{
				ulong platformId = value.Read<User>().PlatformId;
				User val = value.Read<User>();
				string playerName = ((FixedString64Bytes)(ref val.CharacterName)).Value;
				HashSet<string> hashSet = (playerAlliances.ContainsKey(platformId) ? playerAlliances[platformId] : playerAlliances.Where((KeyValuePair<ulong, HashSet<string>> groupEntry) => groupEntry.Value.Contains(playerName)).SelectMany((KeyValuePair<ulong, HashSet<string>> groupEntry) => groupEntry.Value).ToHashSet());
				string text2 = ((hashSet.Count > 0) ? string.Join(", ", hashSet.Select((string member) => "<color=green>" + member + "</color>")) : "No members in alliance.");
				ctx.Reply(text2);
				return;
			}
			foreach (KeyValuePair<ulong, HashSet<string>> playerAlliance in playerAlliances)
			{
				text = playerAlliance.Value.FirstOrDefault((string key) => key.Equals(name, StringComparison.OrdinalIgnoreCase));
				if (!string.IsNullOrEmpty(text))
				{
					string text3 = ((playerAlliance.Value.Count > 0) ? string.Join(", ", playerAlliance.Value.Select((string member) => "<color=green>" + member + "</color>")) : "No members in alliance.");
					ctx.Reply(text3);
					break;
				}
			}
		}
	}
	internal static class Core
	{
		public class DataStructures
		{
			private static readonly JsonSerializerOptions prettyJsonOptions = new JsonSerializerOptions
			{
				WriteIndented = true,
				IncludeFields = true
			};

			private static Dictionary<ulong, Dictionary<string, bool>> playerBools = new Dictionary<ulong, Dictionary<string, bool>>();

			private static Dictionary<ulong, HashSet<string>> playerAlliances = new Dictionary<ulong, HashSet<string>>();

			private static readonly Dictionary<string, string> filePaths = new Dictionary<string, string>
			{
				{
					"PlayerBools",
					JsonFiles.PlayerBoolsJson
				},
				{
					"PlayerAlliances",
					JsonFiles.PlayerAlliancesJson
				}
			};

			public static Dictionary<ulong, Dictionary<string, bool>> PlayerBools
			{
				get
				{
					return playerBools;
				}
				set
				{
					playerBools = value;
				}
			}

			public static Dictionary<ulong, HashSet<string>> PlayerAlliances
			{
				get
				{
					return playerAlliances;
				}
				set
				{
					playerAlliances = value;
				}
			}

			public static void LoadData<T>(ref Dictionary<ulong, T> dataStructure, string key)
			{
				//IL_009d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a4: Expected O, but got Unknown
				//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fc: Expected O, but got Unknown
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Expected O, but got Unknown
				string path = filePaths[key];
				bool flag = default(bool);
				if (!File.Exists(path))
				{
					File.Create(path).Dispose();
					dataStructure = new Dictionary<ulong, T>();
					ManualLogSource log = Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(34, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(key);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" file created as it did not exist.");
					}
					log.LogInfo(val);
					return;
				}
				try
				{
					string text = File.ReadAllText(path);
					if (string.IsNullOrWhiteSpace(text))
					{
						dataStructure = new Dictionary<ulong, T>();
						return;
					}
					Dictionary<ulong, T> dictionary = JsonSerializer.Deserialize<Dictionary<ulong, T>>(text, prettyJsonOptions);
					dataStructure = dictionary ?? new Dictionary<ulong, T>();
				}
				catch (IOException ex)
				{
					ManualLogSource log2 = Log;
					BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(31, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Error reading ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(key);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" data from file: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
					}
					log2.LogError(val2);
					dataStructure = new Dictionary<ulong, T>();
				}
				catch (JsonException ex2)
				{
					ManualLogSource log3 = Log;
					BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(47, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("JSON deserialization error when loading ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(key);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" data: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex2.Message);
					}
					log3.LogError(val2);
					dataStructure = new Dictionary<ulong, T>();
				}
			}

			public static void SaveData<T>(Dictionary<ulong, T> data, string key)
			{
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Expected O, but got Unknown
				//IL_0080: Unknown result type (might be due to invalid IL or missing references)
				//IL_0087: Expected O, but got Unknown
				string path = filePaths[key];
				bool flag = default(bool);
				try
				{
					string contents = JsonSerializer.Serialize(data, prettyJsonOptions);
					File.WriteAllText(path, contents);
				}
				catch (IOException ex)
				{
					ManualLogSource log = Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(31, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failed to write ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(key);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" data to file: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					log.LogInfo(val);
				}
				catch (JsonException ex2)
				{
					ManualLogSource log2 = Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(44, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("JSON serialization error when saving ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(key);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" data: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex2.Message);
					}
					log2.LogInfo(val);
				}
			}

			public static void LoadPlayerAlliances()
			{
				LoadData(ref playerAlliances, "PlayerAlliances");
			}

			public static void LoadPlayerBools()
			{
				LoadData(ref playerBools, "PlayerBools");
			}

			public static void SavePlayerAlliances()
			{
				SaveData(PlayerAlliances, "PlayerAlliances");
			}

			public static void SavePlayerBools()
			{
				SaveData(PlayerBools, "PlayerBools");
			}
		}

		public static class JsonFiles
		{
			public static readonly string PlayerAlliancesJson = Path.Combine(Plugin.PlayerAlliancesPath, "player_alliances.json");

			public static readonly string PlayerBoolsJson = Path.Combine(Plugin.PlayerAlliancesPath, "player_bools.json");
		}

		private static MonoBehaviour monoBehaviour;

		public static bool hasInitialized;

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


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


		public static PrefabCollectionSystem PrefabCollectionSystem { get; internal set; }

		public static ServerGameSettingsSystem ServerGameSettingsSystem { get; internal set; }

		public static ServerScriptMapper ServerScriptMapper { get; internal set; }

		public static DebugEventsSystem DebugEventsSystem { get; internal set; }

		public static PlayerService Players { get; } = new PlayerService();


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

		public static ServerGameSettings ServerGameSettings { get; internal set; }

		public static double ServerTime => ServerGameManager.ServerTime;

		public static ManualLogSource Log => Plugin.LogInstance;

		public static void Initialize()
		{
			if (!hasInitialized)
			{
				PrefabCollectionSystem = Server.GetExistingSystemManaged<PrefabCollectionSystem>();
				ServerGameSettingsSystem = Server.GetExistingSystemManaged<ServerGameSettingsSystem>();
				DebugEventsSystem = Server.GetExistingSystemManaged<DebugEventsSystem>();
				ServerScriptMapper = Server.GetExistingSystemManaged<ServerScriptMapper>();
				ServerGameSettings = Server.GetExistingSystemManaged<ServerGameSettingsSystem>()._Settings;
				hasInitialized = true;
			}
		}

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

		public static void StartCoroutine(IEnumerator routine)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if ((Object)(object)monoBehaviour == (Object)null)
			{
				GameObject val = new GameObject("RaidGuard");
				monoBehaviour = (MonoBehaviour)(object)val.AddComponent<IgnorePhysicsDebugSystem>();
				Object.DontDestroyOnLoad((Object)(object)val);
			}
			monoBehaviour.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(routine));
		}
	}
	public static class ECSExtensions
	{
		private static EntityManager EntityManager => Core.EntityManager;

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

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

		public unsafe static T Read<T>(this Entity entity) where T : struct
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = EntityManager;
			void* componentDataRawRO = ((EntityManager)(ref entityManager)).GetComponentDataRawRO(entity, val.TypeIndex);
			return Marshal.PtrToStructure<T>(new IntPtr(componentDataRawRO));
		}

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

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

		public static bool Has<T>(this Entity entity)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = EntityManager;
			return ((EntityManager)(ref entityManager)).HasComponent(entity, val);
		}

		public static string LookupName(this PrefabGUID prefabGUID)
		{
			//IL_000c: 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_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)
			PrefabCollectionSystem prefabCollectionSystem = Core.PrefabCollectionSystem;
			object obj;
			if (!prefabCollectionSystem.PrefabGuidToNameDictionary.ContainsKey(prefabGUID))
			{
				obj = "Guid Not Found";
			}
			else
			{
				string text = prefabCollectionSystem.PrefabGuidToNameDictionary[prefabGUID];
				PrefabGUID val = prefabGUID;
				obj = text + " " + ((object)(PrefabGUID)(ref val)).ToString();
			}
			return obj.ToString();
		}

		public static void LogComponentTypes(this Entity entity)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = EntityManager;
			Enumerator<ComponentType> enumerator = ((EntityManager)(ref entityManager)).GetComponentTypes(entity, (Allocator)2).GetEnumerator();
			Core.Log.LogInfo((object)"===");
			bool flag = default(bool);
			while (enumerator.MoveNext())
			{
				ComponentType current = enumerator.Current;
				ManualLogSource log = Core.Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(0, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ComponentType>(current);
				}
				log.LogInfo(val);
			}
			Core.Log.LogInfo((object)"===");
		}

		public static void Add<T>(this Entity entity)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = EntityManager;
			((EntityManager)(ref entityManager)).AddComponent(entity, val);
		}

		public static void Remove<T>(this Entity entity)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = EntityManager;
			((EntityManager)(ref entityManager)).RemoveComponent(entity, val);
		}
	}
	[BepInPlugin("io.zfolmt.RaidGuard", "RaidGuard", "1.0.2")]
	internal class Plugin : BasePlugin
	{
		private Harmony _harmony;

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

		public static readonly string PlayerAlliancesPath = Path.Combine(ConfigFiles, "Alliances");

		private static ConfigEntry<bool> _raidGuard;

		private static ConfigEntry<bool> _alliances;

		private static ConfigEntry<bool> _clanBasedAlliances;

		private static ConfigEntry<int> _maxAllianceSize;

		private static ConfigEntry<bool> _preventFriendlyFire;

		private static ConfigEntry<bool> _limitAssists;

		private static ConfigEntry<int> _allianceAssists;

		private static readonly List<string> directoryPaths = new List<string>(2) { ConfigFiles, PlayerAlliancesPath };

		internal static Plugin Instance { get; private set; }

		public static Harmony Harmony => Instance._harmony;

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

		public static ConfigEntry<bool> RaidGuard => _raidGuard;

		public static ConfigEntry<bool> Alliances => _alliances;

		public static ConfigEntry<int> MaxAllianceSize => _maxAllianceSize;

		public static ConfigEntry<bool> ClanBasedAlliances => _clanBasedAlliances;

		public static ConfigEntry<bool> PreventFriendlyFire => _preventFriendlyFire;

		public static ConfigEntry<bool> LimitAssists => _limitAssists;

		public static ConfigEntry<int> AllianceAssists => _allianceAssists;

		public override void Load()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			Instance = this;
			_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			InitConfig();
			CommandRegistry.RegisterAll();
			LoadAllData();
			ManualLogSource log = Core.Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(10, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("RaidGuard");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.2");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("] loaded!");
			}
			log.LogInfo(val);
		}

		private static void InitConfig()
		{
			foreach (string directoryPath in directoryPaths)
			{
				CreateDirectories(directoryPath);
			}
			_raidGuard = InitConfigEntry("Config", "RaidGuard", defaultValue: false, "Enable or disable the prevention of raid interference (only territory clan members and raiding clan members are allowed in territory for duration of the raid once breach by raiders is detected).");
			_alliances = InitConfigEntry("Config", "Alliances", defaultValue: false, "Enable or disable the ability to form alliances.");
			_clanBasedAlliances = InitConfigEntry("Config", "ClanBasedAlliances", defaultValue: false, "If true, clan leaders will decide if the entire clan participates in alliances. If false, it will be player-based. (Alliances must be enabled as well).");
			_preventFriendlyFire = InitConfigEntry("Config", "PreventFriendlyFire", defaultValue: false, "True to prevent damage between players in alliances, false to allow.");
			_maxAllianceSize = InitConfigEntry("Config", "MaxAllianceSize", 4, "The maximum number of players allowed in an alliance (clan members of founding alliance member are included automatically regardless if using clan-based alliances or not and do not count towards this number).");
			_limitAssists = InitConfigEntry("Config", "LimitAssists", defaultValue: false, "True to limit the number of assists during a raid (see below config option for how many allowed if this is set to true).");
			_allianceAssists = InitConfigEntry("Config", "AllianceAssists", 4, "The maximum number of alliance members that can enter a raided territory to assist (includes owning clan members. if this is 4 and 2 owning clan members are offline, then the first 2 alliance members to enter the territory can assist without taking damage from RaidGuard).");
		}

		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)
			//IL_0034: Expected O, but got Unknown
			ConfigEntry<T> val = ((BasePlugin)Instance).Config.Bind<T>(section, key, defaultValue, description);
			string text = Path.Combine(Paths.ConfigPath, "io.zfolmt.RaidGuard.cfg");
			if (File.Exists(text))
			{
				ConfigFile val2 = new ConfigFile(text, true);
				ConfigEntry<T> val3 = default(ConfigEntry<T>);
				if (val2.TryGetEntry<T>(section, key, ref val3))
				{
					val.Value = val3.Value;
				}
			}
			return val;
		}

		private static void CreateDirectories(string path)
		{
			if (!Directory.Exists(path))
			{
				Directory.CreateDirectory(path);
			}
		}

		public override bool Unload()
		{
			((BasePlugin)this).Config.Clear();
			_harmony.UnpatchSelf();
			return true;
		}

		private static void LoadAllData()
		{
			Core.DataStructures.LoadPlayerBools();
			if (Alliances.Value)
			{
				Core.DataStructures.LoadPlayerAlliances();
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "io.zfolmt.RaidGuard";

		public const string PLUGIN_NAME = "RaidGuard";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}
namespace RaidGuard.Services
{
	internal class PlayerService
	{
		private static readonly ComponentType[] UserComponent = (ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly(Il2CppType.Of<User>()) };

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

		private static EntityQuery ActiveUsersQuery;

		private static EntityQuery AllUsersQuery;

		private static EntityQuery ClansQuery;

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

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

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

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

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

		public static Entity GetUserByName(string playerName, bool includeDisabled = false)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			Entity val = GetUsers(includeDisabled).FirstOrDefault((Func<Entity, bool>)delegate(Entity entity)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				User val2 = entity.Read<User>();
				return ((FixedString64Bytes)(ref val2.CharacterName)).Value.ToLower() == playerName.ToLower();
			});
			if (!(val != Entity.Null))
			{
				return Entity.Null;
			}
			return val;
		}

		public static Entity GetClanByName(string clanName)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			Entity val = GetClans().FirstOrDefault((Func<Entity, bool>)delegate(Entity entity)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				ClanTeam val2 = entity.Read<ClanTeam>();
				return ((FixedString64Bytes)(ref val2.Name)).Value.ToLower() == clanName.ToLower();
			});
			if (!(val != Entity.Null))
			{
				return Entity.Null;
			}
			return val;
		}
	}
	internal class RaidService
	{
		private static readonly bool PlayerAlliances = Plugin.Alliances.Value;

		private static readonly bool LimitAssists = Plugin.LimitAssists.Value;

		private static readonly int Assists = Plugin.AllianceAssists.Value;

		private static readonly PrefabGUID debuff = new PrefabGUID(-1572696947);

		private static Dictionary<Entity, (HashSet<Entity> Allowed, List<Entity> AllowedAllies, List<Entity> AllowedRaiders, List<Entity> ActiveAllies, List<Entity> ActiveRaiders)> Participants = new Dictionary<Entity, (HashSet<Entity>, List<Entity>, List<Entity>, List<Entity>, List<Entity>)>();

		private static bool active = false;

		private static DateTime lastMessage = DateTime.MinValue;

		private static EntityManager EntityManager => Core.EntityManager;

		private static DebugEventsSystem DebugEventsSystem => Core.DebugEventsSystem;

		private static ServerGameManager ServerGameManager => Core.ServerGameManager;

		private static Dictionary<ulong, HashSet<string>> Alliances => Core.DataStructures.PlayerAlliances;

		public static void StartRaidMonitor(Entity raider, Entity breached)
		{
			//IL_0000: 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_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_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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			Entity heartEntity = (breached.Has<CastleHeartConnection>() ? breached.Read<CastleHeartConnection>().CastleHeartEntity._Entity : Entity.Null);
			if (!active)
			{
				Core.Log.LogInfo((object)"Starting raid monitor...");
				Participants.Clear();
				AddRaidParticipants(heartEntity, raider, breached);
				Core.StartCoroutine(RaidMonitor());
			}
			else if (active)
			{
				AddRaidParticipants(heartEntity, raider, breached);
			}
		}

		private static void AddRaidParticipants(Entity heartEntity, Entity raider, Entity breached)
		{
			//IL_0002: 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_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_001b: 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)
			if (!((Entity)(ref heartEntity)).Equals(Entity.Null))
			{
				Participants.TryAdd(heartEntity, (GetAllowedParticipants(raider, breached), GetAllowedAllies(breached), GetAllowedRaiders(raider), new List<Entity>(), new List<Entity>()));
			}
		}

		private static List<Entity> GetAllowedAllies(Entity breached)
		{
			//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)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			return GetEntities(breached.Read<CastleHeartConnection>().CastleHeartEntity._Entity.Read<UserOwner>().Owner._Entity);
		}

		private static List<Entity> GetAllowedRaiders(Entity raider)
		{
			//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)
			return GetEntities(raider.Read<PlayerCharacter>().UserEntity);
		}

		private static HashSet<Entity> GetAllowedParticipants(Entity raider, Entity breached)
		{
			//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_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_0022: 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)
			HashSet<Entity> hashSet = new HashSet<Entity>();
			hashSet.UnionWith(GetEntities(breached.Read<UserOwner>().Owner._Entity));
			hashSet.UnionWith(GetEntities(raider.Read<PlayerCharacter>().UserEntity));
			return hashSet;
		}

		private static List<Entity> GetEntities(Entity userEntity)
		{
			//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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_0040: 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_0055: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			HashSet<Entity> hashSet = new HashSet<Entity>();
			User val = userEntity.Read<User>();
			string playerName = ((FixedString64Bytes)(ref val.CharacterName)).Value;
			EntityManager entityManager = EntityManager;
			Entity entity = (((EntityManager)(ref entityManager)).Exists(val.ClanEntity._Entity) ? val.ClanEntity._Entity : Entity.Null);
			if (!((Entity)(ref entity)).Equals(Entity.Null))
			{
				DynamicBuffer<SyncToUserBuffer> val2 = entity.ReadBuffer<SyncToUserBuffer>();
				for (int i = 0; i < val2.Length; i++)
				{
					hashSet.Add(val2[i].UserEntity);
				}
			}
			else
			{
				hashSet.Add(userEntity);
			}
			if (PlayerAlliances && Alliances.Values.Any((HashSet<string> set) => set.Contains(playerName)))
			{
				Entity value;
				HashSet<Entity> other = (from name in Alliances.Where((KeyValuePair<ulong, HashSet<string>> groupEntry) => groupEntry.Value.Contains(playerName)).SelectMany((KeyValuePair<ulong, HashSet<string>> groupEntry) => groupEntry.Value)
					where PlayerService.playerCache.TryGetValue(name, out value)
					select PlayerService.playerCache[name]).ToHashSet();
				hashSet.UnionWith(other);
			}
			HashSet<Entity> hashSet2 = hashSet;
			List<Entity> list = new List<Entity>(hashSet2.Count);
			list.AddRange(hashSet2);
			return list;
		}

		private static IEnumerator RaidMonitor()
		{
			active = true;
			yield return null;
			while (Participants.Keys.Count != 0)
			{
				bool sendMessage = (DateTime.Now - lastMessage).TotalSeconds >= 10.0;
				Dictionary<Entity, (HashSet<Entity>, List<Entity>, List<Entity>, List<Entity>, List<Entity>)>.KeyCollection keys = Participants.Keys;
				List<Entity> list = new List<Entity>(keys.Count);
				list.AddRange(keys);
				List<Entity> heartEntities = list;
				foreach (KeyValuePair<string, Entity> item in PlayerService.playerCache)
				{
					Entity userEntity = item.Value;
					User val = userEntity.Read<User>();
					if (!val.IsConnected)
					{
						continue;
					}
					Entity character = val.LocalCharacter._Entity;
					if (character.TryGetComponent<TilePosition>(out TilePosition pos))
					{
						heartEntities.ForEach(delegate(Entity heartEntity)
						{
							//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_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)
							//IL_0015: Unknown result type (might be due to invalid IL or missing references)
							//IL_0044: Unknown result type (might be due to invalid IL or missing references)
							//IL_0050: Unknown result type (might be due to invalid IL or missing references)
							//IL_005d: 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_0093: 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_0297: Unknown result type (might be due to invalid IL or missing references)
							//IL_02a3: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
							//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
							//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
							//IL_019d: Unknown result type (might be due to invalid IL or missing references)
							//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
							//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
							//IL_00df: Unknown result type (might be due to invalid IL or missing references)
							//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
							//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
							//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
							//IL_02dd: 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_01c9: Unknown result type (might be due to invalid IL or missing references)
							//IL_0154: Unknown result type (might be due to invalid IL or missing references)
							//IL_0160: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
							//IL_010b: Unknown result type (might be due to invalid IL or missing references)
							//IL_0117: Unknown result type (might be due to invalid IL or missing references)
							//IL_030b: Unknown result type (might be due to invalid IL or missing references)
							//IL_0317: Unknown result type (might be due to invalid IL or missing references)
							//IL_023e: Unknown result type (might be due to invalid IL or missing references)
							//IL_024a: Unknown result type (might be due to invalid IL or missing references)
							//IL_01da: Unknown result type (might be due to invalid IL or missing references)
							//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
							//IL_01f5: 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_0177: Unknown result type (might be due to invalid IL or missing references)
							//IL_017d: 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_0134: Unknown result type (might be due to invalid IL or missing references)
							//IL_0261: Unknown result type (might be due to invalid IL or missing references)
							//IL_0267: Unknown result type (might be due to invalid IL or missing references)
							//IL_0218: Unknown result type (might be due to invalid IL or missing references)
							//IL_021e: Unknown result type (might be due to invalid IL or missing references)
							CastleHeart val2 = heartEntity.Read<CastleHeart>();
							if (!((CastleHeart)(ref val2)).IsSieged())
							{
								Participants.Remove(heartEntity);
							}
							else
							{
								CastleTerritory val3 = default(CastleTerritory);
								bool flag = CastleTerritoryExtensions.IsTileInTerritory(EntityManager, pos.Tile, ref val2.CastleTerritoryEntity, ref val3);
								if (flag && !Participants[heartEntity].Allowed.Contains(userEntity))
								{
									ApplyDebuff(character, userEntity, sendMessage, "You are not allowed in this territory during a raid.");
								}
								else if (flag && LimitAssists && Participants[heartEntity].Allowed.Contains(userEntity))
								{
									if (Participants[heartEntity].AllowedAllies.Contains(userEntity))
									{
										if (!Participants[heartEntity].ActiveAllies.Contains(userEntity))
										{
											Participants[heartEntity].ActiveAllies.Add(userEntity);
											if (Participants[heartEntity].ActiveAllies.IndexOf(userEntity) > Assists - 1)
											{
												ApplyDebuff(character, userEntity, sendMessage, "You are not allowed in this territory during a raid (maximum allied assists reached).");
											}
										}
										else if (Participants[heartEntity].ActiveAllies.IndexOf(userEntity) > Assists - 1)
										{
											ApplyDebuff(character, userEntity, sendMessage, "You are not allowed in this territory during a raid (maximum allied assists reached).");
										}
									}
									else if (Participants[heartEntity].AllowedRaiders.Contains(userEntity))
									{
										if (!Participants[heartEntity].ActiveRaiders.Contains(userEntity))
										{
											Participants[heartEntity].ActiveRaiders.Add(userEntity);
											if (Participants[heartEntity].ActiveRaiders.IndexOf(userEntity) > Assists - 1)
											{
												ApplyDebuff(character, userEntity, sendMessage, "You are not allowed in this territory during a raid (maximum raider assists reached).");
											}
										}
										else if (Participants[heartEntity].ActiveRaiders.IndexOf(userEntity) > Assists - 1)
										{
											ApplyDebuff(character, userEntity, sendMessage, "You are not allowed in this territory during a raid (maximum raider assists reached).");
										}
									}
								}
								else if (!flag && LimitAssists && Participants[heartEntity].Allowed.Contains(userEntity))
								{
									if (Participants[heartEntity].ActiveAllies.Contains(userEntity))
									{
										Participants[heartEntity].ActiveAllies.Remove(userEntity);
									}
									else if (Participants[heartEntity].ActiveRaiders.Contains(userEntity))
									{
										Participants[heartEntity].ActiveRaiders.Remove(userEntity);
									}
								}
							}
						});
					}
					yield return null;
				}
				if (sendMessage)
				{
					lastMessage = DateTime.Now;
				}
				yield return null;
			}
			active = false;
			Core.Log.LogInfo((object)"Stopping raid monitor...");
		}

		private static void ApplyDebuff(Entity character, Entity userEntity, bool sendMessage, string message)
		{
			//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_0011: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: 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_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_00a1: 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_00c8: 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_00d9: 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_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_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: 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)
			//IL_0114: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			ServerGameManager serverGameManager = ServerGameManager;
			PrefabGUID val = debuff;
			Entity val2 = default(Entity);
			if (!((ServerGameManager)(ref serverGameManager)).TryGetBuff(character, ((PrefabGUID)(ref val)).ToIdentifier(), ref val2))
			{
				ApplyBuffDebugEvent val3 = default(ApplyBuffDebugEvent);
				val3.BuffPrefabGUID = debuff;
				ApplyBuffDebugEvent val4 = val3;
				FromCharacter val5 = default(FromCharacter);
				val5.Character = character;
				val5.User = userEntity;
				FromCharacter val6 = val5;
				DebugEventsSystem.ApplyBuff(val6, val4);
				serverGameManager = ServerGameManager;
				val = debuff;
				Entity entity = default(Entity);
				if (((ServerGameManager)(ref serverGameManager)).TryGetBuff(character, ((PrefabGUID)(ref val)).ToIdentifier(), ref entity))
				{
					entity.Add<BlockHealBuff>();
					entity.Write<BlockHealBuff>(new BlockHealBuff
					{
						PercentageBlocked = 1f
					});
					if (entity.TryGetComponent<LifeTime>(out LifeTime componentData))
					{
						componentData.Duration = 60f;
						entity.Write<LifeTime>(componentData);
					}
					DynamicBuffer<CreateGameplayEventsOnTick> val7 = entity.ReadBuffer<CreateGameplayEventsOnTick>();
					CreateGameplayEventsOnTick val8 = val7[0];
					val8.MaxTicks = 60;
					val7[0] = val8;
					DynamicBuffer<DealDamageOnGameplayEvent> val9 = entity.ReadBuffer<DealDamageOnGameplayEvent>();
					DealDamageOnGameplayEvent val10 = val9[0];
					val10.DamageModifierPerHit *= 3f;
					val9[0] = val10;
				}
			}
			if (sendMessage)
			{
				ServerChatUtils.SendSystemMessageToClient(EntityManager, userEntity.Read<User>(), message);
			}
		}
	}
}
namespace RaidGuard.Patches
{
	[HarmonyPatch]
	internal static class DeathEventListenerSystemPatch
	{
		private static readonly PrefabGUID siegeGolem = new PrefabGUID(914043867);

		private static readonly bool RaidGuard = Plugin.RaidGuard.Value;

		[HarmonyPatch(typeof(DeathEventListenerSystem), "OnUpdate")]
		[HarmonyPostfix]
		private static void OnUpdatePostfix(DeathEventListenerSystem __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_0060: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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)
			EntityQuery deathEventQuery = __instance._DeathEventQuery;
			NativeArray<DeathEvent> val = ((EntityQuery)(ref deathEventQuery)).ToComponentDataArray<DeathEvent>(AllocatorHandle.op_Implicit((Allocator)2));
			try
			{
				Enumerator<DeathEvent> enumerator = val.GetEnumerator();
				Entity val3 = default(Entity);
				while (enumerator.MoveNext())
				{
					DeathEvent current = enumerator.Current;
					if (!Core.hasInitialized || !RaidGuard || !current.Died.Has<AnnounceCastleBreached>())
					{
						continue;
					}
					StatChangeReason statChangeReason = current.StatChangeReason;
					if (((object)(StatChangeReason)(ref statChangeReason)).Equals((object)(StatChangeReason)15))
					{
						ServerGameManager serverGameManager = Core.ServerGameManager;
						Entity killer = current.Killer;
						PrefabGUID val2 = siegeGolem;
						if (((ServerGameManager)(ref serverGameManager)).TryGetBuff(killer, ((PrefabGUID)(ref val2)).ToIdentifier(), ref val3))
						{
							RaidService.StartRaidMonitor(current.Killer, current.Died);
						}
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = Core.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(44, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Exited DeathEventListenerSystem hook early: ");
					((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<Exception>(ex);
				}
				log.LogInfo(val4);
			}
			finally
			{
				val.Dispose();
			}
		}
	}
	[HarmonyPatch]
	internal static class InitializationPatch
	{
		[HarmonyPatch(typeof(SceneSystem), "ShutdownStreamingSupport")]
		[HarmonyPostfix]
		private static void ShutdownStreamingSupportPostfix()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			Core.Initialize();
			if (Core.hasInitialized)
			{
				ManualLogSource log = Core.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(16, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("|");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("RaidGuard");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.2");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("] initialized|");
				}
				log.LogInfo(val);
				Plugin.Harmony.Unpatch((MethodBase)typeof(SceneSystem).GetMethod("ShutdownStreamingSupport"), typeof(InitializationPatch).GetMethod("OneShot_AfterLoad_InitializationPatch"));
			}
		}
	}
	[HarmonyPatch]
	internal static class ServerBootstrapSystemPatch
	{
		[HarmonyPatch(typeof(ServerBootstrapSystem), "OnUserConnected")]
		[HarmonyPostfix]
		private static void OnUserConnectedPostfix(ServerBootstrapSystem __instance, NetConnectionId netConnectionId)
		{
			//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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			int num = __instance._NetEndPointToApprovedUserIndex[netConnectionId];
			ServerClient val = ((Il2CppArrayBase<ServerClient>)(object)__instance._ApprovedUsersLookup)[num];
			Entity userEntity = val.UserEntity;
			EntityManager entityManager = ((ComponentSystemBase)__instance).EntityManager;
			User componentData = ((EntityManager)(ref entityManager)).GetComponentData<User>(userEntity);
			ulong platformId = componentData.PlatformId;
			if (Plugin.Alliances.Value && !Core.DataStructures.PlayerBools.ContainsKey(platformId))
			{
				Core.DataStructures.PlayerBools.Add(platformId, new Dictionary<string, bool> { { "AllianceInvites", false } });
				Core.DataStructures.SavePlayerBools();
			}
		}
	}
	[HarmonyPatch]
	internal static class StatChangeSystemPatches
	{
		private static readonly bool PlayerAlliances = Plugin.Alliances.Value;

		private static readonly bool PreventFriendlyFire = Plugin.PreventFriendlyFire.Value;

		[HarmonyPatch(typeof(DealDamageSystem), "OnUpdate")]
		[HarmonyPrefix]
		private static void OnUpdatePrefix(DealDamageSystem __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_003a: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Invalid comparison between Unknown and I4
			//IL_0066: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			EntityQuery query = __instance._Query;
			NativeArray<Entity> val = ((EntityQuery)(ref query)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)3));
			try
			{
				Enumerator<Entity> enumerator = val.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					if (!Core.hasInitialized)
					{
						continue;
					}
					DealDamageEvent val2 = current.Read<DealDamageEvent>();
					if (((int)val2.MainType == 0 || (int)val2.MainType == 1) && PlayerAlliances && PreventFriendlyFire && val2.Target.TryGetComponent<PlayerCharacter>(out PlayerCharacter componentData) && val2.SpellSource.TryGetComponent<EntityOwner>(out EntityOwner componentData2) && componentData2.Owner.TryGetComponent<PlayerCharacter>(out PlayerCharacter componentData3))
					{
						Dictionary<ulong, HashSet<string>> playerAlliances = Core.DataStructures.PlayerAlliances;
						string targetName = ((FixedString64Bytes)(ref componentData.Name)).Value;
						string sourceName = ((FixedString64Bytes)(ref componentData3.Name)).Value;
						ulong platformId = componentData3.UserEntity.Read<User>().PlatformId;
						if (playerAlliances.Values.Any((HashSet<string> set) => set.Contains(targetName) && set.Contains(sourceName)))
						{
							EntityManager entityManager = Core.EntityManager;
							((EntityManager)(ref entityManager)).DestroyEntity(current);
						}
					}
				}
			}
			catch (Exception ex)
			{
				Core.Log.LogInfo((object)ex);
			}
			finally
			{
				val.Dispose();
			}
		}
	}
}
namespace RaidGuard.Commands
{
	internal static class AllianceCommands
	{
		private static readonly bool PlayerAlliances = Plugin.Alliances.Value;

		private static readonly bool ClanAlliances = Plugin.ClanBasedAlliances.Value;

		[Command("toggleAllianceInvites", "ainvites", ".ainvites", "Toggles being able to be invited to an alliance. Allowed in raids of allied players and share exp if applicable.", null, false)]
		public static void ToggleAllianceInvitesCommand(ChatCommandContext ctx)
		{
			//IL_001f: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_0092: 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)
			if (!PlayerAlliances)
			{
				ctx.Reply("Alliances are not enabled.");
				return;
			}
			ulong platformId = ctx.Event.User.PlatformId;
			Entity entity = ctx.Event.User.ClanEntity._Entity;
			User user = ctx.Event.User;
			string name = ((FixedString64Bytes)(ref user.CharacterName)).Value;
			if (ClanAlliances && ((Entity)(ref entity)).Equals(Entity.Null))
			{
				ctx.Reply("You must be the leader of a clan to toggle alliance invites.");
				return;
			}
			if (ClanAlliances)
			{
				Entity senderUserEntity = ctx.Event.SenderUserEntity;
				if (senderUserEntity.TryGetComponent<ClanRole>(out ClanRole componentData) && !((object)(ClanRoleEnum)(ref componentData.Value)).Equals((object)(ClanRoleEnum)2))
				{
					ctx.Reply("You must be the leader of a clan to toggle alliance invites.");
					return;
				}
			}
			if (Core.DataStructures.PlayerAlliances.Any((KeyValuePair<ulong, HashSet<string>> kvp) => kvp.Value.Contains(name)))
			{
				ctx.Reply("You are already in an alliance. Leave or disband if owned before enabling invites.");
				return;
			}
			if (Core.DataStructures.PlayerBools.TryGetValue(platformId, out var value))
			{
				value["AllianceInvites"] = !value["AllianceInvites"];
			}
			Core.DataStructures.SavePlayerBools();
			ctx.Reply("Alliance invites " + (value["AllianceInvites"] ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + ".");
		}

		[Command("allianceAdd", "aa", ".aa [Player/Clan]", "Adds player/clan to alliance if invites are toggled (if clan based owner of clan must toggle).", null, false)]
		public static void AllianceAddCommand(ChatCommandContext ctx, string name)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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)
			if (!PlayerAlliances)
			{
				ctx.Reply("Alliances are not enabled.");
				return;
			}
			ulong platformId = ctx.Event.User.PlatformId;
			Entity entity = ctx.Event.User.ClanEntity._Entity;
			if (ClanAlliances)
			{
				if (AllianceUtilities.CheckClanLeadership(ctx, entity))
				{
					ctx.Reply("You must be the leader of a clan to form an alliance.");
				}
				else
				{
					AllianceUtilities.HandleClanAlliance(ctx, platformId, name);
				}
			}
			else
			{
				AllianceUtilities.HandlePlayerAlliance(ctx, platformId, name);
			}
		}

		[Command("allianceRemove", "ar", ".ar [Player/Clan]", "Removes player or clan from alliance.", null, false)]
		public static void AllianceRemoveCommand(ChatCommandContext ctx, string name)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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)
			if (!PlayerAlliances)
			{
				ctx.Reply("Alliances are not enabled.");
				return;
			}
			ulong platformId = ctx.Event.User.PlatformId;
			Entity entity = ctx.Event.User.ClanEntity._Entity;
			if (ClanAlliances && AllianceUtilities.CheckClanLeadership(ctx, entity))
			{
				ctx.Reply("You must be the leader of a clan to remove clans from an alliance.");
				return;
			}
			if (!Core.DataStructures.PlayerAlliances.ContainsKey(platformId))
			{
				ctx.Reply("You don't have an alliance.");
				return;
			}
			HashSet<string> alliance = Core.DataStructures.PlayerAlliances[platformId];
			if (ClanAlliances)
			{
				AllianceUtilities.RemoveClanFromAlliance(ctx, alliance, name);
			}
			else
			{
				AllianceUtilities.RemovePlayerFromAlliance(ctx, alliance, name);
			}
		}

		[Command("listAllianceMembers", "lam", ".lam [Player]", "Lists alliance members of your alliance or the alliance you are in or the members in the alliance of the player entered if found.", null, false)]
		public static void AllianceMembersCommand(ChatCommandContext ctx, string name = "")
		{
			if (!PlayerAlliances)
			{
				ctx.Reply("Alliances are not enabled.");
				return;
			}
			Dictionary<ulong, HashSet<string>> playerAlliances = Core.DataStructures.PlayerAlliances;
			if (string.IsNullOrEmpty(name))
			{
				AllianceUtilities.ListPersonalAllianceMembers(ctx, playerAlliances);
			}
			else
			{
				AllianceUtilities.ListAllianceMembersByName(ctx, name, playerAlliances);
			}
		}

		[Command("allianceDisband", "adisband", ".adisband", "Disbands alliance.", null, false)]
		public static void DisbandAllianceCommand(ChatCommandContext ctx)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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)
			if (!PlayerAlliances)
			{
				ctx.Reply("Alliances are not enabled.");
				return;
			}
			ulong platformId = ctx.Event.User.PlatformId;
			Entity entity = ctx.Event.User.ClanEntity._Entity;
			if (ClanAlliances && AllianceUtilities.CheckClanLeadership(ctx, entity))
			{
				ctx.Reply("You must be the leader of your clan to disband the alliance.");
				return;
			}
			if (!Core.DataStructures.PlayerAlliances.ContainsKey(platformId))
			{
				ctx.Reply("You don't have an alliance to disband.");
				return;
			}
			Core.DataStructures.PlayerAlliances.Remove(platformId);
			ctx.Reply("Alliance disbanded.");
			Core.DataStructures.SavePlayerAlliances();
		}

		[Command("leaveAlliance", "aleave", ".aleave", "Leaves alliance if in one.", null, false)]
		public static void LeaveAllianceCommand(ChatCommandContext ctx)
		{
			//IL_001f: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_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)
			if (!PlayerAlliances)
			{
				ctx.Reply("Alliances are not enabled.");
				return;
			}
			ulong platformId = ctx.Event.User.PlatformId;
			Entity entity = ctx.Event.User.ClanEntity._Entity;
			User user = ctx.Event.User;
			string playerName = ((FixedString64Bytes)(ref user.CharacterName)).Value;
			if (ClanAlliances && AllianceUtilities.CheckClanLeadership(ctx, entity))
			{
				ctx.Reply("You must be the leader of a clan to leave an alliance.");
			}
			else if (Core.DataStructures.PlayerAlliances.ContainsKey(platformId))
			{
				ctx.Reply("You can't leave your own alliance. Disband it instead.");
			}
			else if (ClanAlliances)
			{
				HashSet<string> hashSet = Core.DataStructures.PlayerAlliances.Values.FirstOrDefault((HashSet<string> set) => set.Contains(playerName));
				if (hashSet != null)
				{
					ClanTeam val = entity.Read<ClanTeam>();
					AllianceUtilities.RemoveClanFromAlliance(ctx, hashSet, ((FixedString64Bytes)(ref val.Name)).Value);
				}
				else
				{
					ctx.Reply("Your clan is not in an alliance.");
				}
			}
			else
			{
				HashSet<string> hashSet2 = Core.DataStructures.PlayerAlliances.Values.FirstOrDefault((HashSet<string> set) => set.Contains(playerName));
				if (hashSet2 != null)
				{
					AllianceUtilities.RemovePlayerFromAlliance(ctx, hashSet2, playerName);
				}
				else
				{
					ctx.Reply("You're not in an alliance.");
				}
			}
		}
	}
}