Decompiled source of OfflineRaidGuard v0.2.3

OfflineRaidGuard.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Bloodstone.API;
using Bloody.Core;
using Bloody.Core.API.v1;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using OfflineRaidGuard.Utils;
using ProjectM;
using ProjectM.CastleBuilding;
using ProjectM.Gameplay.Systems;
using ProjectM.Network;
using ProjectM.Scripting;
using Stunlock.Core;
using Unity.Collections;
using Unity.Entities;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("SkyTech6")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Only allow raiding when the defenders (user-specific or clan) are online.")]
[assembly: AssemblyFileVersion("0.2.3.0")]
[assembly: AssemblyInformationalVersion("0.2.3+1.Branch.master.Sha.82eceb6566e5f74c2ed6a6e465fda5eaa0e521c9")]
[assembly: AssemblyProduct("OfflineRaidGuard")]
[assembly: AssemblyTitle("OfflineRaidGuard")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.3.0")]
[module: UnverifiableCode]
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.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace OfflineRaidGuard
{
	public static class ECSExtensions
	{
		private static EntityManager EntityManager => VWorld.Server.EntityManager;

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

		public static DynamicBuffer<T> ReadBuffer<T>(this Entity entity) where T : struct
		{
			//IL_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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			PrefabCollectionSystem prefabCollectionSystem = Core.SystemsCore.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 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("OfflineRaidGuard", "OfflineRaidGuard", "0.2.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[Reloadable]
	public class Plugin : BasePlugin, IRunOnInitialized
	{
		private Harmony harmony;

		public static ConfigEntry<bool> EnableMod;

		public static ConfigEntry<bool> FactorAllies;

		public static ConfigEntry<int> MaxAllyCacheAge;

		public static bool isInitialized;

		public static ManualLogSource Logger;

		private static World _serverWorld;

		public static SystemsCore SystemsCore;

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

		public static bool IsServer => VWorld.IsServer;

		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 void InitConfig()
		{
			EnableMod = ((BasePlugin)this).Config.Bind<bool>("Config", "Enable Mod", true, "Enable/disable the mod.");
			FactorAllies = ((BasePlugin)this).Config.Bind<bool>("Config", "Factor in Ally Status", true, "Include the besieged player allies online status before blocking siege.");
			MaxAllyCacheAge = ((BasePlugin)this).Config.Bind<int>("Config", "Max Ally Cache Age", 300, "Max age of the besieged player allies cache in seconds.\nIf the cache age is older than specified, the cache will be renewed.\nDon't set this too short as allies gathering process can slightly impact your server performance.\nThis cache is only for allies gathering, their online/offline status is updated instantly.");
		}

		public override void Load()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			InitConfig();
			Logger = ((BasePlugin)this).Log;
			harmony = new Harmony("OfflineRaidGuard");
			harmony.PatchAll();
			EventsHandlerSystem.OnInitialize += new OnGameDataInitializedEventHandler(GameDataOnInitialize);
			EventsHandlerSystem.OnDestroy += new OnGameDataDestroyedEventHandler(GameDataOnDestroy);
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("OfflineRaidGuard");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log.LogInfo(val);
		}

		public override bool Unload()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			EventsHandlerSystem.OnInitialize -= new OnGameDataInitializedEventHandler(GameDataOnInitialize);
			EventsHandlerSystem.OnDestroy -= new OnGameDataDestroyedEventHandler(GameDataOnDestroy);
			((BasePlugin)this).Config.Clear();
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			return true;
		}

		public void OnGameInitialized()
		{
			_ = VWorld.IsServer;
		}

		private static void GameDataOnInitialize(World world)
		{
			SystemsCore = Core.SystemsCore;
			Helper.GetServerGameManager(out Helper.SGM);
			isInitialized = true;
		}

		private static void GameDataOnDestroy()
		{
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "OfflineRaidGuard";

		public const string PLUGIN_NAME = "OfflineRaidGuard";

		public const string PLUGIN_VERSION = "0.2.3";
	}
}
namespace OfflineRaidGuard.Utils
{
	public static class Cache
	{
		public static Dictionary<Entity, Entity> PlyonOwnerCache = new Dictionary<Entity, Entity>();

		public static Dictionary<Entity, PlayerGroup> AlliesCache = new Dictionary<Entity, PlayerGroup>();
	}
	public static class Helper
	{
		public static ServerGameManager SGM;

		public static bool GetServerGameManager(out ServerGameManager sgm)
		{
			//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)
			sgm = Plugin.Server.GetExistingSystemManaged<ServerScriptMapper>()._ServerGameManager;
			return true;
		}

		public static int GetAllies(Entity CharacterEntity, out List<Entity> Group)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_002b: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_005c: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			Group = new List<Entity>();
			EntityManager entityManager = Plugin.Server.EntityManager;
			EntityQuery val = ((EntityManager)(ref entityManager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<User>() });
			Enumerator<Entity> enumerator = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)).GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				if (!((Entity)(ref current)).Equals(CharacterEntity) && ((ServerGameManager)(ref SGM)).IsAllies(CharacterEntity, current))
				{
					Group.Add(current);
				}
			}
			return Group.Count;
		}

		public static PrefabGUID GetPrefabGUID(Entity entity)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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)
			EntityManager entityManager = Plugin.Server.EntityManager;
			try
			{
				return ((EntityManager)(ref entityManager)).GetComponentData<PrefabGUID>(entity);
			}
			catch
			{
				return new PrefabGUID(0);
			}
		}

		public static string GetPrefabName(PrefabGUID hashCode)
		{
			//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_0029: Unknown result type (might be due to invalid IL or missing references)
			PrefabCollectionSystem existingSystemManaged = Plugin.Server.GetExistingSystemManaged<PrefabCollectionSystem>();
			string result = "Nonexistent";
			if (((PrefabGUID)(ref hashCode)).GuidHash == 0)
			{
				return result;
			}
			try
			{
				Entity val = ((PrefabLookupMap)(ref ((PrefabCollectionSystem_Base)existingSystemManaged).PrefabLookupMap))[hashCode];
				return ((object)(Entity)(ref val)).ToString();
			}
			catch
			{
				return "NoPrefabName";
			}
		}
	}
	public struct PlayerGroup
	{
		public int AllyCount { get; set; }

		public List<Entity> Allies { get; set; }

		public DateTime TimeStamp { get; set; }

		public PlayerGroup(int allyCount = 0, List<Entity> allies = null, DateTime timeStamp = default(DateTime))
		{
			AllyCount = allyCount;
			Allies = allies;
			TimeStamp = timeStamp;
		}
	}
}
namespace OfflineRaidGuard.Models
{
	public class Player
	{
		public ulong PlatformId { get; set; }

		public string? CharacterName { get; set; }

		public bool IsConnected { get; set; }

		public Entity UserEntity { get; set; }

		public Entity CharEntity { get; set; }

		public Player()
		{
		}

		public Player(ulong PlatformId, string? CharacterName, bool isConnected, Entity userEntity, Entity charEntity)
		{
			//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)
			this.PlatformId = PlatformId;
			this.CharacterName = CharacterName;
			IsConnected = isConnected;
			UserEntity = userEntity;
			CharEntity = charEntity;
		}
	}
}
namespace OfflineRaidGuard.Hooks
{
	[HarmonyPatch]
	internal class StatChange
	{
		[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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Invalid comparison between Unknown and I4
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: 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_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: 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_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: 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 (!Plugin.EnableMod.Value)
					{
						continue;
					}
					DealDamageEvent val2 = current.Read<DealDamageEvent>();
					if (((int)val2.MainType != 0 && (int)val2.MainType != 1) || !val2.Target.TryGetComponent<CastleHeartConnection>(out CastleHeartConnection componentData) || !componentData.CastleHeartEntity._Entity.TryGetComponent<CastleHeart>(out CastleHeart componentData2) || !((Enum)componentData2.State).HasFlag((Enum)(object)(CastleHeartState)1) || !componentData.CastleHeartEntity._Entity.TryGetComponent<UserOwner>(out UserOwner componentData3) || !componentData3.Owner._Entity.TryGetComponent<User>(out User componentData4))
					{
						continue;
					}
					EntityManager entityManager = VWorld.Server.EntityManager;
					Entity val3 = (((EntityManager)(ref entityManager)).Exists(componentData4.ClanEntity._Entity) ? componentData4.ClanEntity._Entity : Entity.Null);
					if (Plugin.FactorAllies.Value && !((Entity)(ref val3)).Equals(Entity.Null))
					{
						Enumerator<SyncToUserBuffer> enumerator2 = componentData4.ClanEntity._Entity.ReadBuffer<SyncToUserBuffer>().GetEnumerator();
						while (enumerator2.MoveNext())
						{
							if (enumerator2.Current.UserEntity.TryGetComponent<User>(out User componentData5) && !componentData5.IsConnected)
							{
								_ = componentData5.TimeLastConnected;
								_ = Plugin.MaxAllyCacheAge.Value;
							}
						}
					}
					if (!componentData4.IsConnected && componentData4.TimeLastConnected >= Plugin.MaxAllyCacheAge.Value)
					{
						entityManager = VWorld.Server.EntityManager;
						((EntityManager)(ref entityManager)).DestroyEntity(current);
					}
				}
			}
			catch (Exception)
			{
			}
			finally
			{
				val.Dispose();
			}
		}

		private static PlayerGroup GetAllies(Entity characterEntity)
		{
			//IL_0005: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			if (!Cache.AlliesCache.TryGetValue(characterEntity, out var value) || (DateTime.Now - value.TimeStamp).TotalSeconds > (double)Plugin.MaxAllyCacheAge.Value)
			{
				List<Entity> Group;
				int allies = Helper.GetAllies(characterEntity, out Group);
				PlayerGroup playerGroup = default(PlayerGroup);
				playerGroup.AllyCount = allies;
				playerGroup.Allies = Group;
				playerGroup.TimeStamp = DateTime.Now;
				value = playerGroup;
				Cache.AlliesCache[characterEntity] = value;
			}
			return value;
		}
	}
}