Decompiled source of RaidForge v3.0.0

RaidForge.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Text;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.CastleBuilding;
using ProjectM.Gameplay.Clan;
using ProjectM.Gameplay.Systems;
using ProjectM.Network;
using ProjectM.Scripting;
using RaidForge.Config;
using RaidForge.Core;
using RaidForge.Data;
using RaidForge.Services;
using RaidForge.Systems;
using RaidForge.Utils;
using Stunlock.Core;
using Stunlock.Network;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
using VampireCommandFramework;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("RaidForge")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Allows for flexible control over raid mechanics.")]
[assembly: AssemblyFileVersion("0.1.10.0")]
[assembly: AssemblyInformationalVersion("0.1.10+1.Branch.main.Sha.c33d0879382e1a0da34861ec55914ba7e637a80e")]
[assembly: AssemblyProduct("RaidForge")]
[assembly: AssemblyTitle("RaidForge")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.10.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RaidForge
{
	[BepInPlugin("raidforge", "RaidForge", "3.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		private Harmony _harmony;

		private ModUpdater _updaterComponent;

		private static ConfigFile _raidScheduleConfigFile;

		private static ConfigFile _golemSettingsConfigFile;

		private static ConfigFile _offlineProtectionConfigFile;

		private static ConfigFile _raidInterferenceConfigFile;

		private static ConfigFile _troubleshootingConfigFile;

		private static ConfigFile _optInRaidingConfigFile;

		private static ConfigFile _optInScheduleConfigFile;

		private static bool _onBootShardScanHasRun = false;

		private static int _initializationAttempts = 0;

		private const int MAX_INITIALIZATION_ATTEMPTS = 120;

		private static float _firstInitAttemptTimestamp = 0f;

		private const float MAX_INIT_WAIT_SECONDS = 600f;

		private static bool _firstAttemptTimestampSet = false;

		public static Plugin Instance { get; private set; }

		public static ManualLogSource Logger { get; private set; }

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


		public static bool ServerHasJustBooted { get; private set; } = true;


		public static bool IsAutoRaidCurrentlyActive => RaidSchedulingSystem.IsAutoRaidActive;

		public static List<RaidScheduleEntry> GetSchedule()
		{
			return (RaidConfig.Schedule == null) ? new List<RaidScheduleEntry>() : new List<RaidScheduleEntry>(RaidConfig.Schedule);
		}

		public static void NotifyPlayerHasConnectedThisSession()
		{
			if (ServerHasJustBooted)
			{
				ServerHasJustBooted = false;
			}
		}

		public override void Load()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Expected O, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Expected O, but got Unknown
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Expected O, but got Unknown
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Expected O, but got Unknown
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Expected O, but got Unknown
			Instance = this;
			ServerHasJustBooted = true;
			Logger = ((BasePlugin)this).Log;
			LoggingHelper.Initialize(Logger);
			string text = Path.Combine(Paths.ConfigPath, "RaidForge");
			Directory.CreateDirectory(text);
			_troubleshootingConfigFile = new ConfigFile(Path.Combine(text, "Troubleshooting.cfg"), true);
			_raidScheduleConfigFile = new ConfigFile(Path.Combine(text, "RaidScheduleAndGeneral.cfg"), true);
			_golemSettingsConfigFile = new ConfigFile(Path.Combine(text, "GolemSettings.cfg"), true);
			_offlineProtectionConfigFile = new ConfigFile(Path.Combine(text, "OfflineProtection.cfg"), true);
			_raidInterferenceConfigFile = new ConfigFile(Path.Combine(text, "RaidInterference.cfg"), true);
			_optInRaidingConfigFile = new ConfigFile(Path.Combine(text, "OptInRaiding.cfg"), true);
			_optInScheduleConfigFile = new ConfigFile(Path.Combine(text, "OptInSchedule.cfg"), true);
			bool flag = default(bool);
			try
			{
				TroubleshootingConfig.Initialize(_troubleshootingConfigFile);
				RaidConfig.Initialize(_raidScheduleConfigFile, Logger);
				GolemAutomationConfig.Initialize(_golemSettingsConfigFile, Logger);
				OfflineRaidProtectionConfig.Initialize(_offlineProtectionConfigFile);
				RaidInterferenceConfig.Initialize(_raidInterferenceConfigFile);
				OptInRaidingConfig.Initialize(_optInRaidingConfigFile);
				OptInScheduleConfig.Initialize(_optInScheduleConfigFile);
				RaidConfig.ParseSchedule();
				GolemAutomationConfig.ReloadAndParseAll();
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Logger;
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(23, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Error loading configs: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				logger.LogError(val);
			}
			_troubleshootingConfigFile.SettingChanged += OnConfigSettingChanged;
			_raidScheduleConfigFile.SettingChanged += OnConfigSettingChanged;
			_golemSettingsConfigFile.SettingChanged += OnConfigSettingChanged;
			_offlineProtectionConfigFile.SettingChanged += OnConfigSettingChanged;
			_raidInterferenceConfigFile.SettingChanged += OnConfigSettingChanged;
			_optInRaidingConfigFile.SettingChanged += OnConfigSettingChanged;
			_optInScheduleConfigFile.SettingChanged += OnConfigSettingChanged;
			try
			{
				_harmony = new Harmony("raidforge");
				_harmony.PatchAll(Assembly.GetExecutingAssembly());
			}
			catch (Exception ex2)
			{
				ManualLogSource logger2 = Logger;
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(25, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Harmony patching failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex2.Message);
				}
				logger2.LogError(val);
			}
			OfflineGraceService.Initialize();
			RaidInterferenceService.Initialize();
			try
			{
				CommandRegistry.RegisterAll();
			}
			catch (Exception ex3)
			{
				ManualLogSource logger3 = Logger;
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(29, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Command registration failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex3.Message);
				}
				logger3.LogError(val);
			}
			if (!ClassInjector.IsTypeRegisteredInIl2Cpp<ModUpdater>())
			{
				ClassInjector.RegisterTypeInIl2Cpp<ModUpdater>();
			}
			_updaterComponent = ((BasePlugin)this).AddComponent<ModUpdater>();
		}

		public static void AttemptInitializeCoreSystems()
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_0067: 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_0080: 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_012f: Unknown result type (might be due to invalid IL or missing references)
			if ((SystemsInitialized && _firstAttemptTimestampSet) || !VWorld.IsServerWorldReady())
			{
				return;
			}
			if (!_firstAttemptTimestampSet)
			{
				_firstInitAttemptTimestamp = Time.realtimeSinceStartup;
				_firstAttemptTimestampSet = true;
			}
			_initializationAttempts++;
			EntityManager entityManager = VWorld.EntityManager;
			if (entityManager == default(EntityManager))
			{
				return;
			}
			OwnershipCacheService.InitializeHeartOwnershipCache(entityManager);
			OwnershipCacheService.InitializeUserToClanCache(entityManager);
			OfflineGraceService.LoadOfflineStatesFromDisk(entityManager);
			bool flag = OwnershipCacheService.IsInitialScanAttemptedAndConsideredPopulated();
			bool flag2 = false;
			if (flag && _initializationAttempts > 1)
			{
				flag2 = true;
			}
			else if (Time.realtimeSinceStartup - _firstInitAttemptTimestamp > 600f)
			{
				flag2 = true;
			}
			else if (_initializationAttempts >= 120)
			{
				flag2 = true;
			}
			if (flag2)
			{
				if (OptInRaidingConfig.EnableOptInRaiding.Value && !OfflineRaidProtectionConfig.EnableOfflineRaidProtection.Value)
				{
					OptInRaidService.LoadStateFromDisk();
				}
				if (OfflineRaidProtectionConfig.EnableOfflineRaidProtection.Value)
				{
					ShardVulnerabilityService.LoadStateFromDisk();
				}
				SystemsInitialized = true;
				OfflineGraceService.EstablishInitialGracePeriodsOnBoot(entityManager);
				RaidSchedulingSystem.CheckScheduleAndToggleRaids(forceCheck: true);
				GolemAutomationSystem.CheckAutomation();
			}
		}

		public static void RunOnBootShardScanIfNeeded()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			if (!_onBootShardScanHasRun && SystemsInitialized)
			{
				PerformOnBootShardVulnerabilityScan(VWorld.EntityManager);
				_onBootShardScanHasRun = true;
			}
		}

		private static void PerformOnBootShardVulnerabilityScan(EntityManager em)
		{
			//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_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_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_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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_0061: 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_0065: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: 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)
			int num = 0;
			EntityQuery val = ((EntityManager)(ref em)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<User>() });
			NativeArray<Entity> val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			try
			{
				Enumerator<Entity> enumerator = val2.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					if (UserHelper.IsVulnerableDueToShard(em, current, out var _))
					{
						User componentData = ((EntityManager)(ref em)).GetComponentData<User>(current);
						Entity entity = componentData.ClanEntity._Entity;
						string persistentKey;
						string contextualName;
						if (entity.Exists() && ((EntityManager)(ref em)).HasComponent<ClanTeam>(entity))
						{
							persistentKey = PersistentKeyHelper.GetClanKey(em, entity);
							ClanTeam componentData2 = ((EntityManager)(ref em)).GetComponentData<ClanTeam>(entity);
							contextualName = ((object)(FixedString64Bytes)(ref componentData2.Name)).ToString();
						}
						else
						{
							persistentKey = PersistentKeyHelper.GetUserKey(componentData.PlatformId);
							contextualName = ((object)(FixedString64Bytes)(ref componentData.CharacterName)).ToString();
						}
						if (!ShardVulnerabilityService.IsVulnerable(persistentKey))
						{
							ShardVulnerabilityService.SetVulnerable(persistentKey, contextualName);
							num++;
						}
					}
				}
			}
			catch (Exception ex)
			{
				LoggingHelper.Error("An error occurred during the on-boot shard vulnerability scan.", ex);
			}
			finally
			{
				if (val2.IsCreated)
				{
					val2.Dispose();
				}
				((EntityQuery)(ref val)).Dispose();
			}
		}

		private void OnConfigSettingChanged(object sender, SettingChangedEventArgs e)
		{
			if (sender == _raidScheduleConfigFile)
			{
				RaidConfig.ParseSchedule();
				if (SystemsInitialized)
				{
					RaidSchedulingSystem.CheckScheduleAndToggleRaids(forceCheck: true);
				}
			}
			else if (sender == _golemSettingsConfigFile)
			{
				GolemAutomationConfig.ReloadAndParseAll();
				if (SystemsInitialized)
				{
					GolemAutomationSystem.ResetAutomationState();
					GolemAutomationSystem.CheckAutomation();
				}
			}
		}

		public static void ReloadAllConfigsAndRefreshSystems()
		{
			try
			{
				if (_troubleshootingConfigFile != null)
				{
					_troubleshootingConfigFile.Reload();
				}
				if (_raidScheduleConfigFile != null)
				{
					_raidScheduleConfigFile.Reload();
				}
				if (_golemSettingsConfigFile != null)
				{
					_golemSettingsConfigFile.Reload();
				}
				if (_offlineProtectionConfigFile != null)
				{
					_offlineProtectionConfigFile.Reload();
				}
				if (_raidInterferenceConfigFile != null)
				{
					_raidInterferenceConfigFile.Reload();
				}
				if (_optInRaidingConfigFile != null)
				{
					_optInRaidingConfigFile.Reload();
				}
				if (_optInScheduleConfigFile != null)
				{
					_optInScheduleConfigFile.Reload();
				}
				if (SystemsInitialized)
				{
					ShardVulnerabilityService.LoadStateFromDisk();
					OptInRaidService.LoadStateFromDisk();
				}
				RaidConfig.ParseSchedule();
				GolemAutomationConfig.ReloadAndParseAll();
				if (SystemsInitialized)
				{
					RaidSchedulingSystem.CheckScheduleAndToggleRaids(forceCheck: true);
					GolemAutomationSystem.ResetAutomationState();
					GolemAutomationSystem.CheckAutomation();
				}
			}
			catch (Exception ex)
			{
				LoggingHelper.Error("An error occurred during ReloadAllConfigsAndRefreshSystems.", ex);
			}
		}

		public static void TriggerReloadFromCommand()
		{
			ReloadAllConfigsAndRefreshSystems();
		}

		public static void TriggerGolemAutomationResetFromCommand()
		{
			if (SystemsInitialized)
			{
				GolemAutomationSystem.ResetAutomationState();
			}
		}

		public override bool Unload()
		{
			try
			{
				if (_troubleshootingConfigFile != null)
				{
					_troubleshootingConfigFile.SettingChanged -= OnConfigSettingChanged;
				}
				if (_raidScheduleConfigFile != null)
				{
					_raidScheduleConfigFile.SettingChanged -= OnConfigSettingChanged;
				}
				if (_golemSettingsConfigFile != null)
				{
					_golemSettingsConfigFile.SettingChanged -= OnConfigSettingChanged;
				}
				if (_offlineProtectionConfigFile != null)
				{
					_offlineProtectionConfigFile.SettingChanged -= OnConfigSettingChanged;
				}
				if (_raidInterferenceConfigFile != null)
				{
					_raidInterferenceConfigFile.SettingChanged -= OnConfigSettingChanged;
				}
				if (_optInRaidingConfigFile != null)
				{
					_optInRaidingConfigFile.SettingChanged -= OnConfigSettingChanged;
				}
				if (_optInScheduleConfigFile != null)
				{
					_optInScheduleConfigFile.SettingChanged -= OnConfigSettingChanged;
				}
				if ((Object)(object)_updaterComponent != (Object)null)
				{
					Object.Destroy((Object)(object)_updaterComponent);
					_updaterComponent = null;
				}
				try
				{
					CommandRegistry.UnregisterAssembly();
				}
				catch
				{
				}
				RaidInterferenceService.StopService();
				OfflineGraceService.Initialize();
				OwnershipCacheService.ClearAllCaches();
				Harmony harmony = _harmony;
				if (harmony != null)
				{
					harmony.UnpatchSelf();
				}
				SystemsInitialized = false;
				ServerHasJustBooted = true;
				_initializationAttempts = 0;
				_firstAttemptTimestampSet = false;
				_onBootShardScanHasRun = false;
			}
			catch
			{
				return false;
			}
			return true;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "RaidForge";

		public const string PLUGIN_NAME = "RaidForge";

		public const string PLUGIN_VERSION = "2.0.0";
	}
}
namespace RaidForge.Utils
{
	public static class ChatColors
	{
		public const string Error = "#FF4136";

		public const string Success = "#2ECC40";

		public const string Info = "#FFFFFF";

		public const string Warning = "#F00534";

		public const string Highlight = "#7FDBFF";

		public const string Accent = "#FFDC00";

		public const string Muted = "#AAAAAA";

		public static string Format(string message, string colorHex)
		{
			if (string.IsNullOrEmpty(colorHex))
			{
				return message;
			}
			return $"<color={colorHex}>{message}</color>";
		}

		public static string ErrorText(string message)
		{
			return Format(message, "#FF4136");
		}

		public static string SuccessText(string message)
		{
			return Format(message, "#2ECC40");
		}

		public static string InfoText(string message)
		{
			return Format(message, "#FFFFFF");
		}

		public static string WarningText(string message)
		{
			return Format(message, "#F00534");
		}

		public static string HighlightText(string message)
		{
			return Format(message, "#7FDBFF");
		}

		public static string AccentText(string message)
		{
			return Format(message, "#FFDC00");
		}

		public static string MutedText(string message)
		{
			return Format(message, "#AAAAAA");
		}
	}
	public static class ClanUtilities
	{
		public static bool TryGetClanEntityByNetworkId(EntityManager em, NetworkId clanNetworkId, out Entity foundClanEntity)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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_00e1: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_006e: 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)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: 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_0091: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			foundClanEntity = Entity.Null;
			NetworkId val = default(NetworkId);
			if (((NetworkId)(ref clanNetworkId)).Equals(val))
			{
				LoggingHelper.Debug("[ClanUtilities] TryGetClanEntityByNetworkId: provided clanNetworkId is default. Cannot find clan.");
				return false;
			}
			EntityQuery val2 = default(EntityQuery);
			NativeArray<Entity> val3 = default(NativeArray<Entity>);
			try
			{
				val2 = ((EntityManager)(ref em)).CreateEntityQuery((ComponentType[])(object)new ComponentType[2]
				{
					ComponentType.ReadOnly<ClanTeam>(),
					ComponentType.ReadOnly<NetworkId>()
				});
				val3 = ((EntityQuery)(ref val2)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)3));
				Enumerator<Entity> enumerator = val3.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					val = ((EntityManager)(ref em)).GetComponentData<NetworkId>(current);
					if (((NetworkId)(ref val)).Equals(clanNetworkId))
					{
						foundClanEntity = current;
						return true;
					}
				}
			}
			catch (Exception value)
			{
				LoggingHelper.Error($"[ClanUtilities] Exception in TryGetClanEntityByNetworkId for NetID {clanNetworkId}: {value}");
			}
			finally
			{
				if (val3.IsCreated)
				{
					val3.Dispose();
				}
				if (val2 != default(EntityQuery))
				{
					((EntityQuery)(ref val2)).Dispose();
				}
			}
			LoggingHelper.Debug($"[ClanUtilities] ClanEntity with NetworkId {clanNetworkId} not found.");
			return false;
		}
	}
	internal static class EntityExtensions
	{
		public delegate void WithRefHandler<T>(ref T item) where T : struct;

		private static EntityManager Em => VWorld.EntityManager;

		public static bool Exists(this Entity entity)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			int result;
			if (entity != Entity.Null)
			{
				EntityManager em = Em;
				result = (((EntityManager)(ref em)).Exists(entity) ? 1 : 0);
			}
			else
			{
				result = 0;
			}
			return (byte)result != 0;
		}

		public static bool Has<T>(this Entity entity) where T : struct
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: 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_0019: 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 == Entity.Null)
			{
				return false;
			}
			EntityManager em = Em;
			return ((EntityManager)(ref em)).HasComponent<T>(entity);
		}

		public static T Read<T>(this Entity entity) where T : struct
		{
			//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_0009: Unknown result type (might be due to invalid IL or missing references)
			EntityManager em = Em;
			return ((EntityManager)(ref em)).GetComponentData<T>(entity);
		}

		public static bool TryRead<T>(this Entity entity, out T component) where T : struct
		{
			//IL_0001: 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_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_0020: Unknown result type (might be due to invalid IL or missing references)
			if (entity.Exists() && entity.Has<T>())
			{
				EntityManager em = Em;
				component = ((EntityManager)(ref em)).GetComponentData<T>(entity);
				return true;
			}
			component = default(T);
			return false;
		}

		public static void Write<T>(this Entity entity, T data) where T : struct
		{
			//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_0009: Unknown result type (might be due to invalid IL or missing references)
			EntityManager em = Em;
			((EntityManager)(ref em)).SetComponentData<T>(entity, data);
		}

		public static void Add<T>(this Entity entity) where T : struct
		{
			//IL_0001: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if (entity.Exists() && !entity.Has<T>())
			{
				EntityManager em = Em;
				((EntityManager)(ref em)).AddComponent<T>(entity);
			}
		}

		public static void With<T>(this Entity entity, WithRefHandler<T> action) where T : struct
		{
			//IL_0001: 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_001b: 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)
			if (entity.Exists() && entity.Has<T>())
			{
				T item = entity.Read<T>();
				action(ref item);
				entity.Write(item);
			}
		}

		public static string Explore(this Entity entity)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_005e: 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)
			if (!entity.Exists())
			{
				return "Entity does not exist.";
			}
			StringBuilder val = new StringBuilder();
			try
			{
				if (VWorld.IsServerWorldReady())
				{
					EntityDebuggingUtility.DumpEntity(VWorld.Server, entity, true, val);
					return ((Object)val).ToString();
				}
				return $"Cannot explore entity {entity}: Server world not ready.";
			}
			catch (Exception ex)
			{
				return $"Error exploring entity {entity}: {ex.Message}";
			}
		}
	}
	public static class LoggingHelper
	{
		private static ManualLogSource _logger;

		private static bool IsVerboseLoggingGloballyEnabled => TroubleshootingConfig.EnableVerboseLogging?.Value ?? false;

		public static void Initialize(ManualLogSource logger)
		{
			_logger = logger;
			if (_logger == null)
			{
				Console.WriteLine("[RaidForge.LoggingHelper] CRITICAL: Logger passed to Initialize is null!");
			}
		}

		public static void Info(string message)
		{
			ManualLogSource logger = _logger;
			if (logger != null)
			{
				logger.LogInfo((object)message);
			}
		}

		public static void Warning(string message, Exception ex = null)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			if (_logger == null)
			{
				return;
			}
			if (ex != null)
			{
				ManualLogSource logger = _logger;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(14, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(message);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" | Exception: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.ToString());
				}
				logger.LogWarning(val);
			}
			else
			{
				_logger.LogWarning((object)message);
			}
		}

		public static void Error(string message, Exception ex = null)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			if (_logger == null)
			{
				Console.WriteLine("[RaidForge.LoggingHelper ERROR (logger not init)]: " + message + " " + ((ex != null) ? ex.ToString() : ""));
			}
			else if (ex != null)
			{
				ManualLogSource logger = _logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(14, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(message);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" | Exception: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.ToString());
				}
				logger.LogError(val);
			}
			else
			{
				_logger.LogError((object)message);
			}
		}

		public static void Debug(string message)
		{
			if (IsVerboseLoggingGloballyEnabled && _logger != null)
			{
				_logger.LogDebug((object)message);
			}
		}
	}
	public static class UserHelper
	{
		public static bool IsVulnerableDueToShard(EntityManager em, Entity userEntity, out string reason)
		{
			//IL_000a: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: 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_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: 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_0200: 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_00fd: 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_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			reason = "No shards found.";
			User val = default(User);
			if (!((EntityManager)(ref em)).Exists(userEntity) || !((EntityManager)(ref em)).TryGetComponentData<User>(userEntity, ref val))
			{
				return false;
			}
			Entity entity = val.LocalCharacter._Entity;
			if (entity.Exists() && HasSoulShardOnPerson(em, entity, out reason))
			{
				return true;
			}
			Entity entity2 = val.ClanEntity._Entity;
			HashSet<Entity> hashSet = new HashSet<Entity>();
			IReadOnlyDictionary<Entity, Entity> heartToOwnerCacheView = OwnershipCacheService.GetHeartToOwnerCacheView();
			foreach (KeyValuePair<Entity, Entity> item in heartToOwnerCacheView)
			{
				if (((EntityManager)(ref em)).Exists(item.Key) && ((EntityManager)(ref em)).Exists(item.Value))
				{
					bool flag = false;
					if (item.Value == userEntity)
					{
						flag = true;
					}
					if (!flag && entity2.Exists() && OwnershipCacheService.TryGetUserClan(item.Value, out var clanEntity) && clanEntity == entity2)
					{
						flag = true;
					}
					if (flag)
					{
						hashSet.Add(item.Key);
					}
				}
			}
			if (!hashSet.Any())
			{
				return false;
			}
			HashSet<PrefabGUID> hashSet2 = new HashSet<PrefabGUID>(PrefabData.PedestalToExpectedShardMap.Keys);
			EntityQuery val2 = ((EntityManager)(ref em)).CreateEntityQuery((ComponentType[])(object)new ComponentType[2]
			{
				ComponentType.ReadOnly<CastleHeartConnection>(),
				ComponentType.ReadOnly<PrefabGUID>()
			});
			NativeArray<Entity> val3 = ((EntityQuery)(ref val2)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			try
			{
				Enumerator<Entity> enumerator2 = val3.GetEnumerator();
				DynamicBuffer<AttachedBuffer> val4 = default(DynamicBuffer<AttachedBuffer>);
				PrefabGUID val5 = default(PrefabGUID);
				DynamicBuffer<InventoryBuffer> val6 = default(DynamicBuffer<InventoryBuffer>);
				while (enumerator2.MoveNext())
				{
					Entity current2 = enumerator2.Current;
					if (!hashSet.Contains(((EntityManager)(ref em)).GetComponentData<CastleHeartConnection>(current2).CastleHeartEntity._Entity) || !hashSet2.Contains(((EntityManager)(ref em)).GetComponentData<PrefabGUID>(current2)) || !((EntityManager)(ref em)).TryGetBuffer<AttachedBuffer>(current2, ref val4))
					{
						continue;
					}
					Enumerator<AttachedBuffer> enumerator3 = val4.GetEnumerator();
					while (enumerator3.MoveNext())
					{
						AttachedBuffer current3 = enumerator3.Current;
						Entity entity3 = current3.Entity;
						if (!entity3.Exists() || !((EntityManager)(ref em)).TryGetComponentData<PrefabGUID>(entity3, ref val5) || !(val5 == PrefabData.ExternalInventoryPrefab) || !((EntityManager)(ref em)).TryGetBuffer<InventoryBuffer>(entity3, ref val6))
						{
							continue;
						}
						Enumerator<InventoryBuffer> enumerator4 = val6.GetEnumerator();
						while (enumerator4.MoveNext())
						{
							InventoryBuffer current4 = enumerator4.Current;
							if (PrefabData.SoulShardPrefabGUIDs.Contains(current4.ItemType))
							{
								reason = $"a Soul Shard ({current4.ItemType}) was found inside a pedestal's inventory.";
								return true;
							}
						}
					}
				}
			}
			finally
			{
				if (val3.IsCreated)
				{
					val3.Dispose();
				}
				((EntityQuery)(ref val2)).Dispose();
			}
			return false;
		}

		public static bool HasSoulShardOnPerson(EntityManager em, Entity characterEntity, out string location)
		{
			//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_00a3: 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_00b2: 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_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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_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_00cf: 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_0045: 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_0051: 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_005f: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			location = "inventory";
			Entity val = default(Entity);
			if (InventoryUtilities.TryGetInventoryEntity<EntityManager>(em, characterEntity, ref val, 0) && ((EntityManager)(ref em)).HasComponent<InventoryBuffer>(val))
			{
				Enumerator<InventoryBuffer> enumerator = ((EntityManager)(ref em)).GetBuffer<InventoryBuffer>(val, false).GetEnumerator();
				PrefabGUID item = default(PrefabGUID);
				while (enumerator.MoveNext())
				{
					InventoryBuffer current = enumerator.Current;
					if (((EntityManager)(ref em)).Exists(current.ItemEntity._Entity) && ((EntityManager)(ref em)).TryGetComponentData<PrefabGUID>(current.ItemEntity._Entity, ref item) && PrefabData.SoulShardPrefabGUIDs.Contains(item))
					{
						return true;
					}
				}
			}
			Equipment val2 = default(Equipment);
			if (((EntityManager)(ref em)).TryGetComponentData<Equipment>(characterEntity, ref val2))
			{
				Entity entity = val2.GrimoireSlot.SlotEntity._Entity;
				PrefabGUID item2 = default(PrefabGUID);
				if (entity.Exists() && ((EntityManager)(ref em)).TryGetComponentData<PrefabGUID>(entity, ref item2) && PrefabData.SoulShardPrefabGUIDs.Contains(item2))
				{
					location = "equipped Grimoire";
					return true;
				}
			}
			return false;
		}

		public static bool FindUserEntity(EntityManager em, string identifier, out Entity userEntity, out User userData, out string characterName)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_00a3: 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_00b3: 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_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			userEntity = Entity.Null;
			userData = default(User);
			characterName = string.Empty;
			if (string.IsNullOrWhiteSpace(identifier))
			{
				return false;
			}
			EntityQuery val = ((EntityManager)(ref em)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<User>() });
			NativeArray<Entity> val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			try
			{
				ulong result;
				bool flag = ulong.TryParse(identifier, out result);
				Enumerator<Entity> enumerator = val2.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					if (!((EntityManager)(ref em)).Exists(current) || !((EntityManager)(ref em)).HasComponent<User>(current))
					{
						continue;
					}
					User componentData = ((EntityManager)(ref em)).GetComponentData<User>(current);
					if (flag)
					{
						if (componentData.PlatformId != result)
						{
							continue;
						}
						userEntity = current;
						userData = componentData;
						characterName = ((object)(FixedString64Bytes)(ref componentData.CharacterName)).ToString();
						return true;
					}
					string text = ((object)(FixedString64Bytes)(ref componentData.CharacterName)).ToString();
					if (!text.Equals(identifier, StringComparison.OrdinalIgnoreCase))
					{
						continue;
					}
					userEntity = current;
					userData = componentData;
					characterName = text;
					return true;
				}
			}
			finally
			{
				if (val2.IsCreated)
				{
					val2.Dispose();
				}
			}
			return false;
		}

		public static bool TryGetPlayerOwnerFromSource(EntityManager em, Entity sourceEntity, out Entity playerCharacterEntity, out Entity userEntity)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0019: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_005e: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			playerCharacterEntity = Entity.Null;
			userEntity = Entity.Null;
			if (!((EntityManager)(ref em)).Exists(sourceEntity))
			{
				return false;
			}
			if (((EntityManager)(ref em)).HasComponent<PlayerCharacter>(sourceEntity))
			{
				playerCharacterEntity = sourceEntity;
				PlayerCharacter val = default(PlayerCharacter);
				if (((EntityManager)(ref em)).TryGetComponentData<PlayerCharacter>(playerCharacterEntity, ref val))
				{
					userEntity = val.UserEntity;
					return ((EntityManager)(ref em)).Exists(userEntity);
				}
				return false;
			}
			if (((EntityManager)(ref em)).HasComponent<EntityOwner>(sourceEntity))
			{
				Entity owner = ((EntityManager)(ref em)).GetComponentData<EntityOwner>(sourceEntity).Owner;
				if (((EntityManager)(ref em)).Exists(owner) && ((EntityManager)(ref em)).HasComponent<PlayerCharacter>(owner))
				{
					playerCharacterEntity = owner;
					PlayerCharacter val2 = default(PlayerCharacter);
					if (((EntityManager)(ref em)).TryGetComponentData<PlayerCharacter>(playerCharacterEntity, ref val2))
					{
						userEntity = val2.UserEntity;
						return ((EntityManager)(ref em)).Exists(userEntity);
					}
					return false;
				}
			}
			return false;
		}

		public static bool IsAnyClanMemberOnline(EntityManager em, Entity clanEntity, Entity excludingUserEntity = default(Entity))
		{
			//IL_0003: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_005a: 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_0065: 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_0084: 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_0099: 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)
			if (!((EntityManager)(ref em)).Exists(clanEntity) || !((EntityManager)(ref em)).HasComponent<ClanTeam>(clanEntity))
			{
				return false;
			}
			NativeList<Entity> val = default(NativeList<Entity>);
			val..ctor(AllocatorHandle.op_Implicit((Allocator)2));
			try
			{
				TeamUtility.GetClanMembers(em, clanEntity, val);
				Enumerator<Entity> enumerator = val.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					if ((!(excludingUserEntity != default(Entity)) || !(current == excludingUserEntity)) && ((EntityManager)(ref em)).Exists(current) && ((EntityManager)(ref em)).HasComponent<User>(current))
					{
						User componentData = ((EntityManager)(ref em)).GetComponentData<User>(current);
						if (componentData.IsConnected)
						{
							return true;
						}
					}
				}
			}
			catch (Exception)
			{
			}
			finally
			{
				if (val.IsCreated)
				{
					val.Dispose();
				}
			}
			return false;
		}
	}
	internal static class VWorld
	{
		private static World _serverWorld;

		private static EntityManager _entityManager;

		public static World Server
		{
			get
			{
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				if (_serverWorld != null && _serverWorld.IsCreated)
				{
					return _serverWorld;
				}
				_serverWorld = GetWorld("Server");
				if (_serverWorld == null || !_serverWorld.IsCreated)
				{
					_entityManager = default(EntityManager);
					LoggingHelper.Error("VWorld: Server world is not available or not created. Subsequent calls may fail.");
					return null;
				}
				_entityManager = _serverWorld.EntityManager;
				return _serverWorld;
			}
		}

		public static EntityManager EntityManager
		{
			get
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: 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_0057: 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_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_007d: Unknown result type (might be due to invalid IL or missing references)
				if ((!(_entityManager == default(EntityManager)) && (_serverWorld == null || !_serverWorld.IsCreated || !(_entityManager != _serverWorld.EntityManager))) || Server != null)
				{
				}
				if (_entityManager == default(EntityManager))
				{
					LoggingHelper.Error("VWorld: EntityManager is not available. Ensure Server world is initialized.");
				}
				return _entityManager;
			}
		}

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

		public static bool IsServerWorldReady()
		{
			//IL_0014: 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)
			return Server != null && Server.IsCreated && EntityManager != default(EntityManager);
		}

		public static bool ZDateTime(out TimeZonedDateTime dt)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			dt = default(TimeZonedDateTime);
			return true;
		}

		public static bool GameBalanceSettings(out ServerGameBalanceSettings settings, Func<ServerGameBalanceSettings, ServerGameBalanceSettings> modify = null)
		{
			//IL_0002: 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_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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_0095: 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_009e: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			settings = default(ServerGameBalanceSettings);
			try
			{
				if (!IsServerWorldReady())
				{
					LoggingHelper.Error("VWorld.GameBalanceSettings: Server world or EntityManager not ready.");
					return false;
				}
				EntityManager entityManager = EntityManager;
				EntityQuery val = ((EntityManager)(ref entityManager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadWrite<ServerGameBalanceSettings>() });
				if (((EntityQuery)(ref val)).IsEmptyIgnoreFilter)
				{
					LoggingHelper.Error("VWorld.GameBalanceSettings: Could not find ServerGameBalanceSettings entity.");
					return false;
				}
				Entity singletonEntity = ((EntityQuery)(ref val)).GetSingletonEntity();
				ServerGameBalanceSettings componentData = ((EntityManager)(ref entityManager)).GetComponentData<ServerGameBalanceSettings>(singletonEntity);
				if (modify == null)
				{
					settings = componentData;
					return true;
				}
				ServerGameBalanceSettings val2 = modify(componentData);
				((EntityManager)(ref entityManager)).SetComponentData<ServerGameBalanceSettings>(singletonEntity, val2);
				settings = val2;
				return true;
			}
			catch (Exception ex)
			{
				LoggingHelper.Error("VWorld.GameBalanceSettings: Exception while accessing/modifying ServerGameBalanceSettings.", ex);
				return false;
			}
		}
	}
}
namespace RaidForge.Systems
{
	public static class GolemAutomationSystem
	{
		private static int _lastDayCheckedForSchedule = -1;

		private static SiegeWeaponHealth? _lastHealthSuccessfullySet = null;

		public static bool CheckAutomation()
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0437: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
			if (!VWorld.IsServerWorldReady())
			{
				ConfigEntry<bool> enableVerboseLogging = TroubleshootingConfig.EnableVerboseLogging;
				if (enableVerboseLogging != null && enableVerboseLogging.Value)
				{
					LoggingHelper.Debug("GolemAutomationSystem: Server world not ready. Golem automation check skipped.");
				}
				return false;
			}
			SiegeWeaponHealth? val = null;
			string value = "None";
			string text = GolemAutomationConfig.ManualSiegeWeaponHealthOverride?.Value;
			if (!string.IsNullOrEmpty(text))
			{
				if (Enum.TryParse<SiegeWeaponHealth>(text, ignoreCase: true, out SiegeWeaponHealth result))
				{
					val = result;
					value = "Manual Level Override ('" + text + "')";
					LoggingHelper.Debug("[GolemAutomationSystem] Manual SiegeWeaponHealth level override active: " + text + ".");
				}
				else
				{
					LoggingHelper.Warning("[GolemAutomationSystem] Invalid ManualSiegeWeaponHealthOverride value in config: '" + text + "'. It will be ignored.");
				}
			}
			if (!val.HasValue)
			{
				ConfigEntry<bool> enableDayBasedAutomation = GolemAutomationConfig.EnableDayBasedAutomation;
				if (enableDayBasedAutomation != null && enableDayBasedAutomation.Value)
				{
					if (!GolemAutomationConfig.ParsedStartDate.HasValue)
					{
						ConfigEntry<bool> enableVerboseLogging2 = TroubleshootingConfig.EnableVerboseLogging;
						if (enableVerboseLogging2 != null && enableVerboseLogging2.Value)
						{
							LoggingHelper.Debug("GolemAutomationSystem: Day-based automation enabled, but ServerStartDateForAutomation not parsed. Schedule skipped.");
						}
					}
					else
					{
						DateTime now = DateTime.Now;
						DateTime value2 = GolemAutomationConfig.ParsedStartDate.Value;
						int num = (int)Math.Floor((now - value2).TotalDays);
						if (num < 0)
						{
							num = 0;
						}
						LoggingHelper.Debug($"[GolemAutomationSystem] Evaluating day-based schedule for Day {num}. Last schedule check day: {_lastDayCheckedForSchedule}.");
						val = GolemAutomationConfig.GetScheduledHealthForDay(num);
						if (val.HasValue)
						{
							value = $"Day-Based Schedule (Day {num} -> Level {val.Value})";
							LoggingHelper.Debug($"[GolemAutomationSystem] Day-based schedule determined target: {val.Value}.");
						}
						else
						{
							LoggingHelper.Debug($"[GolemAutomationSystem] No day-based schedule entry found for Day {num}.");
						}
						_lastDayCheckedForSchedule = num;
					}
					goto IL_02d4;
				}
			}
			if (!val.HasValue)
			{
				LoggingHelper.Debug("[GolemAutomationSystem] No manual override set and day-based automation is disabled.");
			}
			goto IL_02d4;
			IL_02d4:
			if (val.HasValue)
			{
				if (!_lastHealthSuccessfullySet.HasValue || _lastHealthSuccessfullySet.Value != val.Value)
				{
					LoggingHelper.Info($"[GolemAutomationSystem] Attempting to set Golem Health to {val.Value} (Source: {value}).");
					if (SiegeWeaponSystem.SetSiegeWeaponHealth(val.Value))
					{
						_lastHealthSuccessfullySet = val.Value;
						LoggingHelper.Info($"[GolemAutomationSystem] Successfully set Golem Health to {val.Value}.");
					}
					else
					{
						LoggingHelper.Error($"[GolemAutomationSystem] FAILED to set Golem Health to {val.Value}.");
					}
				}
				else
				{
					LoggingHelper.Debug($"[GolemAutomationSystem] Golem Health {val.Value} (Source: {value}) is already what was last successfully set. No change needed.");
				}
			}
			else
			{
				LoggingHelper.Debug("[GolemAutomationSystem] No golem health change determined by overrides or active day-based schedule for today.");
			}
			return true;
		}

		public static void ResetAutomationState()
		{
			_lastDayCheckedForSchedule = -1;
			_lastHealthSuccessfullySet = null;
			LoggingHelper.Info("GolemAutomationSystem: State (last check day and last applied health) has been reset.");
		}
	}
	public static class RaidSchedulingSystem
	{
		private static bool _initialCheckPerformed;

		public static bool IsAutoRaidActive { get; private set; }

		public static bool CheckScheduleAndToggleRaids(bool forceCheck = false)
		{
			bool flag = forceCheck || !_initialCheckPerformed;
			if (!VWorld.IsServerWorldReady())
			{
				if (flag)
				{
					ConfigEntry<bool> enableVerboseLogging = TroubleshootingConfig.EnableVerboseLogging;
					if (enableVerboseLogging != null && enableVerboseLogging.Value)
					{
						LoggingHelper.Warning("RaidSchedulingSystem: Server world not ready yet for schedule check.");
					}
				}
				return false;
			}
			DateTime now = DateTime.Now;
			List<RaidScheduleEntry> schedule = RaidConfig.Schedule;
			if (schedule == null)
			{
				LoggingHelper.Error("RaidSchedulingSystem: Check FAILED - RaidConfig.Schedule is null. Raids will be treated as OFF by default.");
				if (IsAutoRaidActive)
				{
					LoggingHelper.Info("RaidSchedulingSystem: Turning raids OFF due to null schedule.");
					RaidToggleSystem.DisableRaids();
					IsAutoRaidActive = false;
				}
				return true;
			}
			bool flag2 = false;
			string value = "No matching schedule entry found.";
			foreach (RaidScheduleEntry item in schedule)
			{
				if (item.Day == now.DayOfWeek)
				{
					DateTime dateTime = now.Date + item.StartTime;
					DateTime dateTime2 = ((!(item.EndTime == TimeSpan.Zero) || !item.SpansMidnight) ? (item.SpansMidnight ? (now.Date.AddDays(1.0) + item.EndTime) : (now.Date + item.EndTime)) : now.Date.AddDays(1.0));
					if (now >= dateTime && now < dateTime2)
					{
						flag2 = true;
						string value2 = ((item.EndTime == TimeSpan.Zero && item.SpansMidnight) ? "24:00" : item.EndTime.ToString("hh\\:mm"));
						value = $"Active window: {item.Day} {item.StartTime:hh\\:mm} - {value2}";
						break;
					}
				}
				else if (item.SpansMidnight && item.Day == (DayOfWeek)((int)(now.DayOfWeek - 1 + 7) % 7))
				{
					DateTime dateTime = now.Date.AddDays(-1.0) + item.StartTime;
					DateTime dateTime2 = now.Date + item.EndTime;
					if (now >= dateTime && now < dateTime2)
					{
						flag2 = true;
						value = $"Active window (spanned from yesterday): {item.Day} {item.StartTime:hh\\:mm} - {item.EndTime:hh\\:mm}";
						break;
					}
				}
			}
			bool flag3 = flag2 != IsAutoRaidActive;
			if (flag3)
			{
				goto IL_0390;
			}
			if (flag)
			{
				ConfigEntry<bool> enableVerboseLogging2 = TroubleshootingConfig.EnableVerboseLogging;
				if (enableVerboseLogging2 != null && enableVerboseLogging2.Value)
				{
					goto IL_0390;
				}
			}
			goto IL_0415;
			IL_0390:
			LoggingHelper.Info($"RaidSchedulingSystem: Schedule check - Should be {(flag2 ? "ON" : "OFF")}. Reason: {value}. Current state: {IsAutoRaidActive}. Change needed: {flag3}");
			goto IL_0415;
			IL_0415:
			if (flag3)
			{
				LoggingHelper.Info(flag2 ? "RaidSchedulingSystem: Enabling raids (Scheduled)..." : "RaidSchedulingSystem: Disabling raids (Scheduled)...");
				if (flag2 ? RaidToggleSystem.EnableRaids() : RaidToggleSystem.DisableRaids())
				{
					IsAutoRaidActive = flag2;
					LoggingHelper.Info($"RaidSchedulingSystem: Raid state successfully changed to: {IsAutoRaidActive}");
				}
				else
				{
					LoggingHelper.Error($"RaidSchedulingSystem: FAILED to set CastleDamageMode. Raid state remains {IsAutoRaidActive}.");
				}
			}
			else if (flag)
			{
				ConfigEntry<bool> enableVerboseLogging3 = TroubleshootingConfig.EnableVerboseLogging;
				if (enableVerboseLogging3 != null && enableVerboseLogging3.Value)
				{
					LoggingHelper.Info($"RaidSchedulingSystem: Raid state ({IsAutoRaidActive}) matches desired state. No action needed.");
				}
			}
			if (!_initialCheckPerformed && VWorld.IsServerWorldReady())
			{
				_initialCheckPerformed = true;
				ConfigEntry<bool> enableVerboseLogging4 = TroubleshootingConfig.EnableVerboseLogging;
				if (enableVerboseLogging4 != null && enableVerboseLogging4.Value)
				{
					LoggingHelper.Info("RaidSchedulingSystem: Initial raid schedule check performed.");
				}
			}
			return true;
		}
	}
	public static class RaidToggleSystem
	{
		public static bool EnableRaids()
		{
			return SetCastleDamageMode((CastleDamageMode)1);
		}

		public static bool DisableRaids()
		{
			return SetCastleDamageMode((CastleDamageMode)2);
		}

		private static bool SetCastleDamageMode(CastleDamageMode newMode)
		{
			//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)
			try
			{
				if (VWorld.GameBalanceSettings(out var _, delegate(ServerGameBalanceSettings settings)
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					//IL_0002: 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_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_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_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_0029: Unknown result type (might be due to invalid IL or missing references)
					if (settings.CastleDamageMode == newMode)
					{
						return settings;
					}
					settings.CastleDamageMode = newMode;
					return settings;
				}))
				{
					return true;
				}
				return false;
			}
			catch (Exception)
			{
				return false;
			}
		}
	}
	public static class SiegeWeaponSystem
	{
		public static bool SetSiegeWeaponHealth(SiegeWeaponHealth newValue)
		{
			//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)
			try
			{
				if (VWorld.GameBalanceSettings(out var _, delegate(ServerGameBalanceSettings settings)
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					//IL_0002: 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_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_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_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_0029: Unknown result type (might be due to invalid IL or missing references)
					if (settings.SiegeWeaponHealth == newValue)
					{
						return settings;
					}
					settings.SiegeWeaponHealth = newValue;
					return settings;
				}))
				{
					return true;
				}
				return false;
			}
			catch (Exception)
			{
				return false;
			}
		}

		public static SiegeWeaponHealth? GetSiegeWeaponHealth()
		{
			//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)
			try
			{
				if (VWorld.GameBalanceSettings(out var settings))
				{
					return settings.SiegeWeaponHealth;
				}
				return null;
			}
			catch (Exception)
			{
				return null;
			}
		}
	}
}
namespace RaidForge.Services
{
	public class PersistedOfflineStateEntry
	{
		public string PersistentKey { get; set; }

		public long OfflineStartTimeTicks { get; set; }

		public string ContextualName { get; set; }
	}
	public static class PersistentKeyHelper
	{
		public static string GetUserKey(ulong platformId)
		{
			return $"user_{platformId}";
		}

		public static string GetClanKey(EntityManager em, Entity clanEntity)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: 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_0027: 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_003f: 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)
			if (clanEntity == Entity.Null || !((EntityManager)(ref em)).Exists(clanEntity))
			{
				return null;
			}
			if (((EntityManager)(ref em)).HasComponent<NetworkId>(clanEntity))
			{
				NetworkId componentData = ((EntityManager)(ref em)).GetComponentData<NetworkId>(clanEntity);
				if (!((NetworkId)(ref componentData)).Equals(default(NetworkId)))
				{
					string text = ((object)(NetworkId)(ref componentData)).ToString();
					return "clan_nid_" + text;
				}
			}
			return null;
		}
	}
	public static class OfflineGraceService
	{
		private static Dictionary<string, DateTime> _persistedOfflineStartTimes = new Dictionary<string, DateTime>();

		private static Dictionary<string, string> _persistedOfflineEntityNames = new Dictionary<string, string>();

		private static HashSet<string> _defaultOrpAtBootKeys = new HashSet<string>();

		private static readonly string DataSubfolder = "Data";

		private static readonly string OfflineStatesSaveFileName = "RaidForge_OfflineStates.csv";

		private static bool _dataLoadedFromDisk = false;

		private static readonly object _saveLock = new object();

		private static string GetSaveFilePath()
		{
			string text = Path.Combine(Paths.ConfigPath, "RaidForge", DataSubfolder);
			Directory.CreateDirectory(text);
			return Path.Combine(text, OfflineStatesSaveFileName);
		}

		public static void LoadOfflineStatesFromDisk(EntityManager entityManager)
		{
			if (_dataLoadedFromDisk)
			{
				return;
			}
			lock (_saveLock)
			{
				string saveFilePath = GetSaveFilePath();
				_persistedOfflineStartTimes.Clear();
				_persistedOfflineEntityNames.Clear();
				_defaultOrpAtBootKeys.Clear();
				if (!File.Exists(saveFilePath))
				{
					_dataLoadedFromDisk = true;
					return;
				}
				try
				{
					string[] source = File.ReadAllLines(saveFilePath);
					foreach (string item in source.Skip(1))
					{
						if (string.IsNullOrWhiteSpace(item))
						{
							continue;
						}
						string[] array = item.Split(',');
						if (array.Length >= 3)
						{
							string text = array[0].Trim();
							string value = array[2].Trim();
							if (!string.IsNullOrEmpty(text) && long.TryParse(array[1], out var result))
							{
								_persistedOfflineStartTimes[text] = new DateTime(result, DateTimeKind.Utc);
								_persistedOfflineEntityNames[text] = value;
							}
						}
					}
				}
				catch (Exception ex)
				{
					LoggingHelper.Error("Failed to load offline states from CSV.", ex);
				}
				_dataLoadedFromDisk = true;
			}
		}

		private static void SaveTimedOfflineStatesToDiskInternal()
		{
			if (!Plugin.SystemsInitialized && !_dataLoadedFromDisk)
			{
				return;
			}
			lock (_saveLock)
			{
				string saveFilePath = GetSaveFilePath();
				try
				{
					StringBuilder stringBuilder = new StringBuilder();
					stringBuilder.AppendLine("PersistentKey,OfflineStartTimeTicks,ContextualName");
					foreach (KeyValuePair<string, DateTime> persistedOfflineStartTime in _persistedOfflineStartTimes)
					{
						string key = persistedOfflineStartTime.Key;
						long ticks = persistedOfflineStartTime.Value.Ticks;
						string value;
						string value2 = (_persistedOfflineEntityNames.TryGetValue(key, out value) ? value : "NameNotFoundOnSave");
						StringBuilder stringBuilder2 = stringBuilder;
						StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(2, 3, stringBuilder2);
						handler.AppendFormatted(key);
						handler.AppendLiteral(",");
						handler.AppendFormatted(ticks);
						handler.AppendLiteral(",");
						handler.AppendFormatted(value2);
						stringBuilder2.AppendLine(ref handler);
					}
					File.WriteAllText(saveFilePath, stringBuilder.ToString());
				}
				catch (Exception ex)
				{
					LoggingHelper.Error("Failed to save offline states to CSV.", ex);
				}
			}
		}

		public static void Initialize()
		{
		}

		public static void MarkAsOffline(string persistentKey, DateTime offlineTimeUtc, string contextualName)
		{
			if (!string.IsNullOrEmpty(persistentKey))
			{
				_persistedOfflineStartTimes[persistentKey] = offlineTimeUtc;
				_persistedOfflineEntityNames[persistentKey] = contextualName;
				_defaultOrpAtBootKeys.Remove(persistentKey);
				SaveTimedOfflineStatesToDiskInternal();
			}
		}

		public static void MarkAsOnline(string persistentKey, string contextualName)
		{
			if (!string.IsNullOrEmpty(persistentKey))
			{
				bool flag = _persistedOfflineStartTimes.Remove(persistentKey);
				_persistedOfflineEntityNames.Remove(persistentKey);
				bool flag2 = _defaultOrpAtBootKeys.Remove(persistentKey);
				if ((flag || flag2) && flag)
				{
					SaveTimedOfflineStatesToDiskInternal();
				}
			}
		}

		public static bool TryGetOfflineStartTime(string persistentKey, out DateTime offlineStartTimeUtc)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			offlineStartTimeUtc = default(DateTime);
			if (string.IsNullOrEmpty(persistentKey))
			{
				return false;
			}
			if (!_dataLoadedFromDisk && Plugin.SystemsInitialized && VWorld.IsServerWorldReady())
			{
				LoadOfflineStatesFromDisk(VWorld.EntityManager);
			}
			return _persistedOfflineStartTimes.TryGetValue(persistentKey, out offlineStartTimeUtc);
		}

		public static bool IsUnderDefaultBootORP(string persistentKey)
		{
			if (string.IsNullOrEmpty(persistentKey))
			{
				return false;
			}
			return _defaultOrpAtBootKeys.Contains(persistentKey) && !_persistedOfflineStartTimes.ContainsKey(persistentKey);
		}

		public static void HandleUserDisconnected(EntityManager entityManager, Entity disconnectedUserEntity, bool isFromPersistenceLoadEvent_IGNORED)
		{
			//IL_0040: 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_0077: 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_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: 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_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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: 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_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			LoggingHelper.Debug("[ShardVulnerability] OfflineGraceService.HandleUserDisconnected has been called.");
			if (!Plugin.SystemsInitialized)
			{
				return;
			}
			ConfigEntry<bool> enableOfflineRaidProtection = OfflineRaidProtectionConfig.EnableOfflineRaidProtection;
			User val = default(User);
			if (enableOfflineRaidProtection == null || !enableOfflineRaidProtection.Value || !((EntityManager)(ref entityManager)).Exists(disconnectedUserEntity) || !((EntityManager)(ref entityManager)).TryGetComponentData<User>(disconnectedUserEntity, ref val))
			{
				return;
			}
			string text = ((object)(FixedString64Bytes)(ref val.CharacterName)).ToString();
			if (UserHelper.IsVulnerableDueToShard(entityManager, disconnectedUserEntity, out var reason))
			{
				string text2 = null;
				string text3 = text;
				Entity entity = val.ClanEntity._Entity;
				ClanTeam val2 = default(ClanTeam);
				if (entity.Exists() && ((EntityManager)(ref entityManager)).TryGetComponentData<ClanTeam>(entity, ref val2))
				{
					text2 = PersistentKeyHelper.GetClanKey(entityManager, entity);
					text3 = ((object)(FixedString64Bytes)(ref val2.Name)).ToString();
				}
				string persistentKey = text2 ?? PersistentKeyHelper.GetUserKey(val.PlatformId);
				string text4 = ((text2 != null) ? text3 : text);
				LoggingHelper.Debug("[ShardVulnerability] Vulnerability reason for '" + text4 + "': " + reason);
				ShardVulnerabilityService.SetVulnerable(persistentKey, text4);
				return;
			}
			LoggingHelper.Debug("[ShardVulnerability] No shard found for " + text + "'s team. Proceeding with normal ORP.");
			Entity entity2 = val.ClanEntity._Entity;
			DateTime utcNow = DateTime.UtcNow;
			if (entity2.Exists() && ((EntityManager)(ref entityManager)).HasComponent<ClanTeam>(entity2))
			{
				string clanKey = PersistentKeyHelper.GetClanKey(entityManager, entity2);
				if (!UserHelper.IsAnyClanMemberOnline(entityManager, entity2, disconnectedUserEntity))
				{
					ClanTeam componentData = ((EntityManager)(ref entityManager)).GetComponentData<ClanTeam>(entity2);
					string text5 = ((object)(FixedString64Bytes)(ref componentData.Name)).ToString();
					MarkAsOffline(clanKey, utcNow, text5 + " (last online: " + text + ")");
				}
			}
			else
			{
				string userKey = PersistentKeyHelper.GetUserKey(val.PlatformId);
				MarkAsOffline(userKey, utcNow, text);
			}
		}

		public static void HandleClanMemberDeparted(EntityManager entityManager, Entity userWhoLeft, Entity clanThatWasLeft, FixedString64Bytes userWhoLeftCharacterNameFs)
		{
			//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)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			string text = ((object)(FixedString64Bytes)(ref userWhoLeftCharacterNameFs)).ToString();
			if (!Plugin.SystemsInitialized)
			{
				return;
			}
			ConfigEntry<bool> enableOfflineRaidProtection = OfflineRaidProtectionConfig.EnableOfflineRaidProtection;
			if (enableOfflineRaidProtection != null && enableOfflineRaidProtection.Value && !(clanThatWasLeft == Entity.Null) && ((EntityManager)(ref entityManager)).Exists(clanThatWasLeft) && ((EntityManager)(ref entityManager)).HasComponent<ClanTeam>(clanThatWasLeft))
			{
				string clanKey = PersistentKeyHelper.GetClanKey(entityManager, clanThatWasLeft);
				if (!string.IsNullOrEmpty(clanKey) && !UserHelper.IsAnyClanMemberOnline(entityManager, clanThatWasLeft))
				{
					ClanTeam componentData = ((EntityManager)(ref entityManager)).GetComponentData<ClanTeam>(clanThatWasLeft);
					string text2 = ((object)(FixedString64Bytes)(ref componentData.Name)).ToString();
					MarkAsOffline(clanKey, DateTime.UtcNow, text2 + " (after " + text + " departed)");
				}
			}
		}

		public static void EstablishInitialGracePeriodsOnBoot(EntityManager entityManager)
		{
			//IL_0036: 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_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: 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_005e: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			if (!_dataLoadedFromDisk || !Plugin.SystemsInitialized)
			{
				return;
			}
			_defaultOrpAtBootKeys.Clear();
			EntityQuery val = default(EntityQuery);
			NativeArray<Entity> val2 = default(NativeArray<Entity>);
			try
			{
				val = ((EntityManager)(ref entityManager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<User>() });
				val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)3));
				Enumerator<Entity> enumerator = val2.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					if (((EntityManager)(ref entityManager)).HasComponent<User>(current))
					{
						User componentData = ((EntityManager)(ref entityManager)).GetComponentData<User>(current);
						string userKey = PersistentKeyHelper.GetUserKey(componentData.PlatformId);
						string text = ((object)(FixedString64Bytes)(ref componentData.CharacterName)).ToString();
						if (!_persistedOfflineStartTimes.ContainsKey(userKey) && _defaultOrpAtBootKeys.Add(userKey))
						{
							_persistedOfflineEntityNames[userKey] = text + " (Default Boot ORP - User)";
						}
					}
				}
			}
			catch (Exception)
			{
			}
			finally
			{
				if (val2.IsCreated)
				{
					val2.Dispose();
				}
			}
			EntityQuery val3 = default(EntityQuery);
			NativeArray<Entity> val4 = default(NativeArray<Entity>);
			try
			{
				val3 = ((EntityManager)(ref entityManager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<ClanTeam>() });
				val4 = ((EntityQuery)(ref val3)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)3));
				Enumerator<Entity> enumerator2 = val4.GetEnumerator();
				while (enumerator2.MoveNext())
				{
					Entity current2 = enumerator2.Current;
					string clanKey = PersistentKeyHelper.GetClanKey(entityManager, current2);
					if (!string.IsNullOrEmpty(clanKey) && !_persistedOfflineStartTimes.ContainsKey(clanKey) && !UserHelper.IsAnyClanMemberOnline(entityManager, current2) && _defaultOrpAtBootKeys.Add(clanKey))
					{
						ClanTeam componentData2 = ((EntityManager)(ref entityManager)).GetComponentData<ClanTeam>(current2);
						string text2 = ((object)(FixedString64Bytes)(ref componentData2.Name)).ToString();
						_persistedOfflineEntityNames[clanKey] = text2 + " (Default Boot ORP - Clan)";
					}
				}
			}
			catch (Exception)
			{
			}
			finally
			{
				if (val4.IsCreated)
				{
					val4.Dispose();
				}
			}
		}
	}
	public static class OfflineProtectionService
	{
		public static bool AreAllDefendersActuallyOffline(Entity castleHeartEntity, EntityManager entityManager)
		{
			//IL_0018: 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_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)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: 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_00b9: 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)
			if (!Plugin.SystemsInitialized)
			{
				return false;
			}
			if (!((EntityManager)(ref entityManager)).Exists(castleHeartEntity) || !((EntityManager)(ref entityManager)).HasComponent<UserOwner>(castleHeartEntity))
			{
				return false;
			}
			Entity entity = ((EntityManager)(ref entityManager)).GetComponentData<UserOwner>(castleHeartEntity).Owner._Entity;
			if (!((EntityManager)(ref entityManager)).Exists(entity) || !((EntityManager)(ref entityManager)).HasComponent<User>(entity))
			{
				return false;
			}
			User componentData = ((EntityManager)(ref entityManager)).GetComponentData<User>(entity);
			Entity clanEntity = Entity.Null;
			OwnershipCacheService.TryGetUserClan(entity, out clanEntity);
			if (clanEntity != Entity.Null && ((EntityManager)(ref entityManager)).Exists(clanEntity) && ((EntityManager)(ref entityManager)).HasComponent<ClanTeam>(clanEntity))
			{
				bool flag = UserHelper.IsAnyClanMemberOnline(entityManager, clanEntity);
				return !flag;
			}
			return !componentData.IsConnected;
		}

		public static bool IsBaseDecaying(Entity castleHeartEntity, EntityManager entityManager)
		{
			//IL_0003: 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_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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if (!((EntityManager)(ref entityManager)).Exists(castleHeartEntity) || !((EntityManager)(ref entityManager)).HasComponent<CastleHeart>(castleHeartEntity))
			{
				return true;
			}
			CastleHeart componentData = ((EntityManager)(ref entityManager)).GetComponentData<CastleHeart>(castleHeartEntity);
			if (componentData.FuelQuantity <= 0 || ((CastleHeart)(ref componentData)).IsDecaying())
			{
				return true;
			}
			return false;
		}
	}
	public static class OptInRaidService
	{
		private static Dictionary<string, DateTime> _optedInStates = new Dictionary<string, DateTime>();

		private static Dictionary<string, string> _optedInNames = new Dictionary<string, string>();

		private static readonly string DataSubfolder = "Data";

		private static readonly string SaveFileName = "RaidForge_OptInState.csv";

		private static readonly object _saveLock = new object();

		private static bool _dataLoaded = false;

		private static string GetSaveFilePath()
		{
			string text = Path.Combine(Paths.ConfigPath, "RaidForge", DataSubfolder);
			Directory.CreateDirectory(text);
			return Path.Combine(text, SaveFileName);
		}

		public static void LoadStateFromDisk()
		{
			if (_dataLoaded)
			{
				return;
			}
			lock (_saveLock)
			{
				string saveFilePath = GetSaveFilePath();
				_optedInStates.Clear();
				_optedInNames.Clear();
				if (!File.Exists(saveFilePath))
				{
					_dataLoaded = true;
					return;
				}
				try
				{
					string[] source = File.ReadAllLines(saveFilePath);
					foreach (string item in source.Skip(1))
					{
						if (string.IsNullOrWhiteSpace(item))
						{
							continue;
						}
						string[] array = item.Split(',');
						if (array.Length < 3)
						{
							continue;
						}
						string text = array[0];
						if (long.TryParse(array[1], out var result))
						{
							string value = array[2];
							if (!string.IsNullOrEmpty(text))
							{
								_optedInStates[text] = new DateTime(result, DateTimeKind.Utc);
								_optedInNames[text] = value;
							}
						}
					}
				}
				catch (Exception)
				{
				}
				_dataLoaded = true;
			}
		}

		private static void SaveStateToDisk()
		{
			lock (_saveLock)
			{
				string saveFilePath = GetSaveFilePath();
				try
				{
					StringBuilder stringBuilder = new StringBuilder();
					stringBuilder.AppendLine("PersistentKey,OptInTimestampTicks,ContextualName");
					foreach (KeyValuePair<string, DateTime> optedInState in _optedInStates)
					{
						string key = optedInState.Key;
						long ticks = optedInState.Value.Ticks;
						string value;
						string value2 = (_optedInNames.TryGetValue(key, out value) ? value : "Unknown");
						StringBuilder stringBuilder2 = stringBuilder;
						StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(2, 3, stringBuilder2);
						handler.AppendFormatted(key);
						handler.AppendLiteral(",");
						handler.AppendFormatted(ticks);
						handler.AppendLiteral(",");
						handler.AppendFormatted(value2);
						stringBuild