Decompiled source of Creatures v1.0.1

meadworks.creatures.dll

Decompiled 29 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using HarmonyLib;
using MeadWorks.Core;
using MeadWorks.Creatures.Content;
using MeadWorks.UI;
using Microsoft.CodeAnalysis;
using SoftReferenceableAssets;
using SoftReferenceableAssets.SceneManagement;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_guiutils")]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("expDARE")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright (c) 2026 expDARE")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("meadworks.creatures")]
[assembly: AssemblyTitle("meadworks.creatures")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MeadWorks.Creatures
{
	public static class AllyOutgoingRules
	{
		public const float DeathRattleBonus = 0.2f;

		public const float DeathRattleSeconds = 10f;

		public const float DeathRattleRadius = 15f;

		public static float Multiplier(float rallyBonus, bool deathRattleActive)
		{
			float num = 1f;
			if (rallyBonus > 0f)
			{
				num *= 1f + rallyBonus;
			}
			if (deathRattleActive)
			{
				num *= 1.2f;
			}
			return num;
		}

		public static long Expiry(double nowSeconds, float durationSeconds)
		{
			if (double.IsNaN(nowSeconds) || nowSeconds <= 0.0 || float.IsNaN(durationSeconds) || durationSeconds <= 0f)
			{
				return 0L;
			}
			return (long)Math.Round((nowSeconds + (double)durationSeconds) * 1000.0);
		}

		public static long Later(long currentMillis, long offeredMillis)
		{
			if (offeredMillis <= currentMillis)
			{
				return currentMillis;
			}
			return offeredMillis;
		}

		public static bool Active(long untilMillis, double nowSeconds)
		{
			if (untilMillis > 0 && !double.IsNaN(nowSeconds) && nowSeconds > 0.0)
			{
				return nowSeconds * 1000.0 < (double)untilMillis;
			}
			return false;
		}

		public static bool HostGrant(bool host, long sender, long sourceOwner, bool hasDeathRattle, bool allies, double distanceSquared, float radius, bool alreadyGranted)
		{
			if (!host || sender == 0L || sourceOwner == 0L || sender != sourceOwner)
			{
				return false;
			}
			if (alreadyGranted || !hasDeathRattle || !allies)
			{
				return false;
			}
			if (float.IsNaN(radius) || radius <= 0f || double.IsNaN(distanceSquared) || distanceSquared < 0.0)
			{
				return false;
			}
			return distanceSquared <= (double)radius * (double)radius;
		}

		public static bool MayRelay(long sender, long serverPeer, long sourceOwner, bool hasDeathRattle, double distanceSquared, float radius)
		{
			if (sender == 0L || serverPeer == 0L || (sender != serverPeer && sender != sourceOwner))
			{
				return false;
			}
			if (!hasDeathRattle || float.IsNaN(radius) || radius <= 0f || double.IsNaN(distanceSquared) || distanceSquared < 0.0)
			{
				return false;
			}
			return distanceSquared <= (double)radius * (double)radius;
		}

		public static bool AcceptGrant(long sender, long serverPeer, bool owner)
		{
			if (owner && sender != 0L && serverPeer != 0L)
			{
				return sender == serverPeer;
			}
			return false;
		}
	}
	public sealed class AuraCarrierRules
	{
		private double _nextScan = double.NegativeInfinity;

		public bool TryRefresh(double now)
		{
			if (now < _nextScan)
			{
				return false;
			}
			_nextScan = now + 0.5;
			return true;
		}

		public void Invalidate()
		{
			_nextScan = double.NegativeInfinity;
		}

		public static bool CanCarry(int level, string[] decodedSelection)
		{
			if (level <= 0)
			{
				return false;
			}
			if (decodedSelection == null)
			{
				return true;
			}
			foreach (string text in decodedSelection)
			{
				if (text == null)
				{
					continue;
				}
				int length = text.Length;
				if (length != 3)
				{
					if (length != 4)
					{
						continue;
					}
					switch (text[3])
					{
					case '6':
						if (!(text == "M116"))
						{
							continue;
						}
						break;
					case '8':
						if (!(text == "M118"))
						{
							continue;
						}
						break;
					case '9':
						if (!(text == "M119"))
						{
							continue;
						}
						break;
					default:
						continue;
					}
				}
				else
				{
					switch (text[2])
					{
					case '7':
						if (!(text == "M57"))
						{
							continue;
						}
						break;
					case '8':
						if (!(text == "M58"))
						{
							continue;
						}
						break;
					case '0':
						if (!(text == "M60"))
						{
							continue;
						}
						break;
					case '1':
						if (!(text == "M61"))
						{
							continue;
						}
						break;
					case '3':
						if (!(text == "M63"))
						{
							continue;
						}
						break;
					case '4':
						if (!(text == "M64"))
						{
							continue;
						}
						break;
					case '5':
						if (!(text == "M65"))
						{
							continue;
						}
						break;
					default:
						continue;
					}
				}
				return true;
			}
			return false;
		}
	}
	public sealed class BossAdaptiveRules
	{
		public const int Types = 12;

		public const int Buckets = 10;

		public const double Window = 10.0;

		public const double Skew = 1.0;

		private const long Empty = long.MinValue;

		private readonly float[,] _sums = new float[10, 12];

		private readonly long[] _seconds = new long[10];

		public BossAdaptiveRules()
		{
			for (int i = 0; i < 10; i++)
			{
				_seconds[i] = long.MinValue;
			}
		}

		private static int Slot(long second)
		{
			return (int)((second % 10 + 10) % 10);
		}

		private void ClearSlot(int slot)
		{
			_seconds[slot] = long.MinValue;
			for (int i = 0; i < 12; i++)
			{
				_sums[slot, i] = 0f;
			}
		}

		private void Prune(double now)
		{
			for (int i = 0; i < 10; i++)
			{
				if (_seconds[i] != long.MinValue && ((double)_seconds[i] <= now - 10.0 || (double)_seconds[i] > now + 1.0))
				{
					ClearSlot(i);
				}
			}
		}

		public int Strongest(double now)
		{
			Prune(now);
			double[] array = new double[12];
			for (int i = 0; i < 10; i++)
			{
				for (int j = 0; j < 12; j++)
				{
					array[j] += _sums[i, j];
				}
			}
			int num = -1;
			for (int k = 0; k < array.Length; k++)
			{
				if (array[k] > 0.0 && (num < 0 || array[k] > array[num]))
				{
					num = k;
				}
			}
			return num;
		}

		public static float Factor(int type, int strongest)
		{
			if (type != strongest || strongest < 0)
			{
				return 1f;
			}
			return 0.8f;
		}

		public void Add(double now, float[] damage)
		{
			Prune(now);
			long num = (long)Math.Floor(now);
			int num2 = Slot(num);
			if (_seconds[num2] != num)
			{
				_seconds[num2] = num;
				for (int i = 0; i < 12; i++)
				{
					_sums[num2, i] = 0f;
				}
			}
			for (int j = 0; j < Math.Min(12, damage.Length); j++)
			{
				if (damage[j] > 0f && !float.IsInfinity(damage[j]) && !float.IsNaN(damage[j]))
				{
					_sums[num2, j] += damage[j];
				}
			}
		}

		private static string Hex(float value)
		{
			return BitConverter.ToInt32(BitConverter.GetBytes(value), 0).ToString("X8", CultureInfo.InvariantCulture);
		}

		private static bool TryHex(string text, out float value)
		{
			value = 0f;
			if (string.IsNullOrEmpty(text) || text.Length != 8 || !int.TryParse(text, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var result))
			{
				return false;
			}
			value = BitConverter.ToSingle(BitConverter.GetBytes(result), 0);
			if (!float.IsNaN(value))
			{
				return !float.IsInfinity(value);
			}
			return false;
		}

		public string Encode(double now)
		{
			Prune(now);
			StringBuilder stringBuilder = new StringBuilder();
			long num = (long)Math.Floor(now);
			for (int i = 0; i < 10; i++)
			{
				if (_seconds[i] == long.MinValue)
				{
					continue;
				}
				for (int j = 0; j < 12; j++)
				{
					float num2 = _sums[i, j];
					if (!(num2 <= 0f) && !float.IsNaN(num2) && !float.IsInfinity(num2))
					{
						if (stringBuilder.Length == 0)
						{
							stringBuilder.Append(num.ToString(CultureInfo.InvariantCulture)).Append(';');
						}
						stringBuilder.Append((_seconds[i] - num).ToString(CultureInfo.InvariantCulture)).Append('|').Append(j.ToString(CultureInfo.InvariantCulture))
							.Append('|')
							.Append(Hex(num2))
							.Append(';');
					}
				}
			}
			return stringBuilder.ToString();
		}

		public static BossAdaptiveRules Decode(string raw, double now)
		{
			BossAdaptiveRules bossAdaptiveRules = new BossAdaptiveRules();
			if (string.IsNullOrEmpty(raw))
			{
				return bossAdaptiveRules;
			}
			string[] array = raw.Split(new char[1] { ';' });
			if (array.Length < 2 || !long.TryParse(array[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result))
			{
				return bossAdaptiveRules;
			}
			for (int i = 1; i < array.Length; i++)
			{
				string[] array2 = array[i].Split(new char[1] { '|' });
				if (array2.Length != 3 || !long.TryParse(array2[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result2))
				{
					continue;
				}
				long num = result + result2;
				if ((double)num <= now - 10.0 || (double)num > now + 1.0 || !int.TryParse(array2[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result3) || result3 < 0 || result3 >= 12 || !TryHex(array2[2], out var value) || value <= 0f)
				{
					continue;
				}
				int num2 = Slot(num);
				if (bossAdaptiveRules._seconds[num2] != num)
				{
					bossAdaptiveRules._seconds[num2] = num;
					for (int j = 0; j < 12; j++)
					{
						bossAdaptiveRules._sums[num2, j] = 0f;
					}
				}
				bossAdaptiveRules._sums[num2, result3] += value;
			}
			return bossAdaptiveRules;
		}
	}
	public static class BossAspects
	{
		private sealed class AltarSummon
		{
			public long Owner;

			public int Prefab;

			public double Until;

			public string Selection;
		}

		private sealed class AltarInfo
		{
			public int Prefab;

			public int Stars;

			public float Delay;
		}

		private static class AltarPatches
		{
			[HarmonyPatch(typeof(OfferingBowl), "GetHoverText")]
			[HarmonyPostfix]
			[HarmonyAfter(new string[] { "expdare.meadworks.world.altarinventory" })]
			private static void Hover(OfferingBowl __instance, ref string __result)
			{
				//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_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_00b6: 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_00c3: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
				//IL_0100: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (!RotatingAltars || (Object)(object)ZNet.instance == (Object)null || (Object)(object)__instance.m_nview == (Object)null || !__instance.m_nview.IsValid() || __instance.IsBossSpawnQueued() || (Object)(object)__instance.m_bossPrefab == (Object)null)
					{
						return;
					}
					Character component = __instance.m_bossPrefab.GetComponent<Character>();
					if (component != null && component.IsBoss())
					{
						double timeSeconds = ZNet.instance.GetTimeSeconds();
						ZDOID uid = __instance.m_nview.GetZDO().m_uid;
						long num = BossAltarRules.Window(timeSeconds);
						int num2 = BossAltarRules.Remaining(timeSeconds);
						if (uid != _hoverAltar || num != _hoverWindow || _hoverHighlight != Theme.Accent)
						{
							string selection = AltarRoll(uid, __instance, timeSeconds);
							_hoverHighlight = Theme.Accent;
							_hoverAspects = BossAspectInfoRules.HoverPrefix(selection, ColorUtility.ToHtmlStringRGB(_hoverHighlight));
							_hoverRemaining = -1;
						}
						if (uid != _hoverAltar || num != _hoverWindow || num2 != _hoverRemaining)
						{
							_hoverAltar = uid;
							_hoverWindow = num;
							_hoverRemaining = num2;
							_hoverLine = ((_hoverAspects == null) ? null : (_hoverAspects + num2.ToString("00")));
						}
						if (_hoverLine != null)
						{
							__result += _hoverLine;
						}
					}
				}
				catch (Exception e)
				{
					Warn("altarhover", e);
				}
			}

			[HarmonyPatch(typeof(OfferingBowl), "InitiateSpawnBoss")]
			[HarmonyPrefix]
			private static void Pressed(OfferingBowl __instance, bool __runOriginal = true)
			{
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (__runOriginal && RotatingAltars && !((Object)(object)ZNet.instance == (Object)null) && !((Object)(object)__instance.m_nview == (Object)null) && __instance.m_nview.IsValid())
					{
						Register();
						ZRoutedRpc rpc = _rpc;
						if (rpc != null)
						{
							rpc.InvokeRoutedRPC(_rpc.GetServerPeerID(), "MW_CreaturesAltarPress", new object[2]
							{
								__instance.m_nview.GetZDO().m_uid,
								ZNet.instance.GetTimeSeconds()
							});
						}
					}
				}
				catch (Exception e)
				{
					Warn("altarpresssend", e);
				}
			}

			[HarmonyPatch(typeof(ZRoutedRpc), "RouteRPC")]
			[HarmonyPrefix]
			private static void Routed(RoutedRPCData __0)
			{
				Interaction(__0);
			}

			[HarmonyPatch(typeof(ZRoutedRpc), "HandleRoutedRPC")]
			[HarmonyPrefix]
			private static void Handled(RoutedRPCData __0)
			{
				Interaction(__0);
			}

			private static void Interaction(RoutedRPCData data)
			{
				//IL_002f: 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)
				if (Server && !((ZDOID)(ref data.m_targetZDO)).IsNone() && data.m_methodHash == SpawnBossHash)
				{
					ZDOMan instance = ZDOMan.instance;
					if (AltarBowl((instance != null) ? instance.GetZDO(data.m_targetZDO) : null) != null)
					{
						PruneAltars();
						AltarInteractions.Record(data.m_targetZDO, data.m_senderPeerID, Time.realtimeSinceStartupAsDouble);
					}
				}
			}

			[HarmonyPatch(typeof(OfferingBowl), "RPC_SpawnBoss")]
			[HarmonyPrefix]
			private static void Before(OfferingBowl __instance, out bool __state)
			{
				__state = __instance.IsBossSpawnQueued();
			}

			[HarmonyPatch(typeof(OfferingBowl), "RPC_SpawnBoss")]
			[HarmonyPostfix]
			private static void Started(OfferingBowl __instance, long senderId, bool __state)
			{
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (!(!RotatingAltars || __state) && __instance.IsBossSpawnQueued() && !((Object)(object)__instance.m_nview == (Object)null) && __instance.m_nview.IsOwner())
					{
						Register();
						ZRoutedRpc rpc = _rpc;
						if (rpc != null)
						{
							rpc.InvokeRoutedRPC(_rpc.GetServerPeerID(), "MW_CreaturesAltarStarted", new object[2]
							{
								__instance.m_nview.GetZDO().m_uid,
								senderId
							});
						}
					}
				}
				catch (Exception e)
				{
					Warn("altarqueue", e);
				}
			}

			[HarmonyPatch(typeof(OfferingBowl), "DelayedSpawnBoss")]
			[HarmonyPrefix]
			private static void Spawning(OfferingBowl __instance, out ZDOID __state)
			{
				//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_0026: 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_0038: Unknown result type (might be due to invalid IL or missing references)
				__state = _spawningAltar;
				_spawningAltar = (((Object)(object)__instance.m_nview != (Object)null && __instance.m_nview.IsValid()) ? __instance.m_nview.GetZDO().m_uid : ZDOID.None);
			}

			[HarmonyPatch(typeof(OfferingBowl), "DelayedSpawnBoss")]
			[HarmonyFinalizer]
			private static void Spawned(ZDOID __state)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				_spawningAltar = __state;
			}

			[HarmonyPatch(typeof(ZNetView), "Awake")]
			[HarmonyPostfix]
			[HarmonyPriority(800)]
			private static void Created(ZNetView __instance)
			{
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				if (CreatureSession.Allowed && !((ZDOID)(ref _spawningAltar)).IsNone() && __instance.IsValid() && __instance.IsOwner())
				{
					Character component = ((Component)__instance).GetComponent<Character>();
					if (component != null && component.IsBoss())
					{
						__instance.GetZDO().Set("meadworks.boss.altar", _spawningAltar);
					}
				}
			}
		}

		private static class ArenaPatches
		{
			[HarmonyPatch(typeof(Player), "UpdateEnvStatusEffects")]
			[HarmonyPrefix]
			private static void BeginEnvironment(Player __instance, out SEMan __state)
			{
				__state = _wintryWeather;
				_wintryWeather = null;
				try
				{
					if (WintryAffects(__instance) && WintryColdAllowed(__instance))
					{
						_wintryWeather = ((Character)__instance).GetSEMan();
					}
				}
				catch (Exception e)
				{
					Warn("wintry-weather", e);
				}
			}

			[HarmonyPatch(typeof(Player), "UpdateEnvStatusEffects")]
			[HarmonyFinalizer]
			private static Exception EndEnvironment(SEMan __state, Exception __exception)
			{
				_wintryWeather = __state;
				return __exception;
			}

			[HarmonyPatch(typeof(SEMan), "RemoveStatusEffect", new Type[]
			{
				typeof(int),
				typeof(bool)
			})]
			[HarmonyPrefix]
			private static bool KeepWintryCold(SEMan __instance, int nameHash, ref bool __result, bool __runOriginal = true)
			{
				if (!__runOriginal)
				{
					return false;
				}
				if (nameHash != SEMan.s_statusEffectCold || !BossAspectArenaRules.KeepCold(_wintryWeather == __instance, __instance.HaveStatusEffect(nameHash)))
				{
					return true;
				}
				__result = true;
				return false;
			}

			[HarmonyPatch(typeof(Player), "UpdateEnvStatusEffects")]
			[HarmonyPostfix]
			private static void Environment(Player __instance)
			{
				try
				{
					WintryEnvironment(__instance);
				}
				catch (Exception e)
				{
					Warn("wintry", e);
				}
			}

			[HarmonyPatch(typeof(Character), "OnDeath")]
			[HarmonyPrefix]
			private static void Died(Character __instance)
			{
				Gone(__instance);
			}

			[HarmonyPatch(typeof(Character), "OnDestroy")]
			[HarmonyPrefix]
			private static void Despawned(Character __instance)
			{
				Gone(__instance);
			}

			private static void Gone(Character c)
			{
				try
				{
					if (!((Object)(object)c == (Object)null) && (ArenaTicks.ContainsKey(c) || WarcallAllies.Contains(c) || c.IsBoss()))
					{
						RemoveArena(c);
					}
				}
				catch (Exception e)
				{
					Warn("arena-gone", e);
				}
			}

			[HarmonyPatch(typeof(ZNet), "StopAll")]
			[HarmonyPrefix]
			private static void Stopped()
			{
				ClearArena();
			}

			[HarmonyPatch(typeof(SEMan), "ModifyStaminaRegen")]
			[HarmonyPostfix]
			[HarmonyPriority(0)]
			private static void HexRegen(SEMan __instance, ref float staminaMultiplier)
			{
				try
				{
					Player localPlayer = Player.m_localPlayer;
					if (Owned((Character)(object)localPlayer) && ((Character)localPlayer).GetSEMan() == __instance)
					{
						ArenaHex arenaHex = __instance.GetStatusEffect(HexHash) as ArenaHex;
						if ((Object)(object)arenaHex != (Object)null && arenaHex.Active())
						{
							staminaMultiplier *= 0.5f;
						}
					}
				}
				catch (Exception e)
				{
					Warn("hex-regen", e);
				}
			}

			[HarmonyPatch(typeof(Character), "GetAttackSpeedFactorMovement")]
			[HarmonyPostfix]
			private static void WarcallMovement(Character __instance, ref float __result)
			{
				try
				{
					if (WarcallAllies.Count != 0 && WarcallAllies.Contains(__instance) && Owned(__instance))
					{
						ArenaWarcall arenaWarcall = __instance.GetSEMan().GetStatusEffect(WarcallHash) as ArenaWarcall;
						if ((Object)(object)arenaWarcall != (Object)null && arenaWarcall.Active())
						{
							__result *= 1.15f;
						}
					}
				}
				catch (Exception e)
				{
					Warn("warcall-movement", e);
				}
			}

			[HarmonyPatch(typeof(Humanoid), "GetAttackSpeedFactorMovement")]
			[HarmonyPostfix]
			private static void WarcallHumanoidMovement(Humanoid __instance, ref float __result)
			{
				WarcallMovement((Character)(object)__instance, ref __result);
			}

			[HarmonyPatch(typeof(MonsterAI), "UpdateTarget")]
			[HarmonyPostfix]
			private static void RallyTarget(MonsterAI __instance, ref bool canHearTarget, ref bool canSeeTarget)
			{
				try
				{
					if (WarcallAllies.Count != 0 && WarcallAllies.Contains(((BaseAI)__instance).m_character) && Owned(((BaseAI)__instance).m_character))
					{
						Character val = (((BaseAI)__instance).m_character.GetSEMan().GetStatusEffect(WarcallHash) as ArenaWarcall)?.Rally();
						if (!((Object)(object)val == (Object)null))
						{
							canHearTarget = true;
							canSeeTarget = ((BaseAI)__instance).CanSeeTarget(val);
						}
					}
				}
				catch (Exception e)
				{
					Warn("warcall-target", e);
				}
			}
		}

		private static class BonePlatedPatches
		{
			[HarmonyPatch(typeof(Character), "ApplyDamage")]
			[HarmonyPrefix]
			[HarmonyPriority(800)]
			private static void Incoming(Character __instance, HitData hit)
			{
				try
				{
					if (hit != null && Owned(__instance) && BossAspectRules.Has(Of(__instance), "BonePlated"))
					{
						BossBonePlatedRules.Scale(ref hit.m_damage.m_slash, ref hit.m_damage.m_pierce, ref hit.m_damage.m_blunt);
					}
				}
				catch (Exception e)
				{
					Warn("bone-plated", e);
				}
			}
		}

		private sealed class VisualState
		{
			public Vector3 Scale;
		}

		private static class CombatPatches
		{
			[HarmonyPatch(typeof(Character), "CustomFixedUpdate")]
			[HarmonyPostfix]
			private static void Updated(Character __instance, float dt)
			{
				try
				{
					Tick(__instance);
					TickGravityPlayer(__instance, dt);
				}
				catch (Exception e)
				{
					Warn("tick", e);
				}
			}

			[HarmonyPatch(typeof(Character), "OnDestroy")]
			[HarmonyPostfix]
			private static void Destroyed(Character __instance)
			{
				try
				{
					Visuals.Remove(__instance);
				}
				catch (Exception e)
				{
					Warn("visuals", e);
				}
			}

			[HarmonyPatch(typeof(Character), "SetupMaxHealth")]
			[HarmonyPostfix]
			private static void HealthSetup(Character __instance)
			{
				try
				{
					Refit(__instance);
				}
				catch (Exception e)
				{
					Warn("health", e);
				}
			}

			[HarmonyPatch(typeof(Character), "GetAttackSpeedFactorMovement")]
			[HarmonyPostfix]
			private static void Move(Character __instance, ref float __result)
			{
				try
				{
					__result *= BossAspectRules.Movement(Of(__instance));
				}
				catch (Exception e)
				{
					Warn("move", e);
				}
			}

			[HarmonyPatch(typeof(Humanoid), "GetAttackSpeedFactorMovement")]
			[HarmonyPostfix]
			private static void HumanoidMove(Humanoid __instance, ref float __result)
			{
				Move((Character)(object)__instance, ref __result);
			}

			[HarmonyPatch(typeof(Humanoid), "GetTimeSinceLastAttack")]
			[HarmonyPostfix]
			private static void AttackClock(Humanoid __instance, ref float __result)
			{
				try
				{
					__result *= BossAspectRules.AttackSpeed(Of((Character)(object)__instance), ((Character)__instance).GetHealthPercentage());
				}
				catch (Exception e)
				{
					Warn("clock", e);
				}
			}

			[HarmonyPatch(typeof(Character), "RPC_Damage")]
			[HarmonyPrefix]
			private static void Damage(Character __instance, HitData hit, out float __state)
			{
				__state = -1f;
				try
				{
					if (Owned(__instance) && hit != null)
					{
						Outgoing(hit, __instance);
						if (__instance.IsBoss())
						{
							__state = __instance.GetHealth();
						}
					}
				}
				catch (Exception e)
				{
					Warn("damage", e);
				}
			}

			[HarmonyPatch(typeof(WearNTear), "RPC_Damage")]
			[HarmonyPrefix]
			private static void Piece(HitData hit)
			{
				try
				{
					Outgoing(hit);
				}
				catch (Exception e)
				{
					Warn("piece", e);
				}
			}

			[HarmonyPatch(typeof(Destructible), "RPC_Damage")]
			[HarmonyPrefix]
			private static void Destructible(HitData hit)
			{
				Piece(hit);
			}

			[HarmonyPatch(typeof(Character), "ApplyDamage")]
			[HarmonyPrefix]
			private static void Incoming(Character __instance, HitData hit)
			{
				//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (!Owned(__instance) || !__instance.IsBoss() || hit == null || __instance.IsDead() || __instance.IsTeleporting() || __instance.InCutscene())
					{
						return;
					}
					string selection = Of(__instance);
					if (BossAspectRules.Has(selection, "Adaptive"))
					{
						Adaptive(__instance, hit);
					}
					((DamageTypes)(ref hit.m_damage)).Modify(BossAspectRules.Incoming(selection, Night));
					if (!BossAspectRules.Has(selection, "Shielded") || hit.GetTotalDamage() <= 0f)
					{
						return;
					}
					float shield = RefreshShield(__instance, selection);
					float num = (((Object)(object)Game.instance != (Object)null) ? (Game.instance.GetDifficultyDamageScaleEnemy(((Component)__instance).transform.position) * Game.m_playerDamageRate) : 1f);
					float num2 = hit.GetTotalDamage() * num;
					if (!(num2 <= 0f))
					{
						float num3 = BossAspectRules.Absorb(num2, ref shield);
						((DamageTypes)(ref hit.m_damage)).Modify(num3 / num2);
						ZDO zDO = __instance.m_nview.GetZDO();
						zDO.Set(ShieldKey, shield);
						if ((Object)(object)ZNet.instance != (Object)null)
						{
							zDO.Set(ShieldHitKey, ZNet.instance.GetTime().Ticks);
						}
					}
				}
				catch (Exception e)
				{
					Warn("incoming", e);
				}
			}

			[HarmonyPatch(typeof(Character), "RPC_Damage")]
			[HarmonyPostfix]
			private static void Reflect(Character __instance, HitData hit, float __state)
			{
				//IL_006a: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00db: 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_00e3: Expected O, but got Unknown
				try
				{
					if (!(__state < 0f) && Owned(__instance) && hit != null && hit.m_toolTier != short.MinValue)
					{
						RememberFixation(__instance, hit.GetAttacker(), Math.Max(0f, __state - __instance.GetHealth()));
						Character attacker = hit.GetAttacker();
						float difficultyScale = (((Object)(object)Game.instance == (Object)null || !Valid(attacker)) ? 1f : (Game.instance.GetDifficultyDamageScalePlayer(((Component)attacker).transform.position) * Game.m_enemyDamageRate));
						float num = BossAspectRules.Reflect(Of(__instance), hit.m_ranged, __state - __instance.GetHealth(), difficultyScale);
						if (!(num <= 0f) && Valid(attacker) && !((Object)(object)attacker == (Object)(object)__instance))
						{
							HitData val = new HitData
							{
								m_point = attacker.GetCenterPoint(),
								m_toolTier = short.MinValue,
								m_ranged = true,
								m_hitType = (HitType)1
							};
							val.m_damage.m_damage = num;
							val.SetAttacker(__instance);
							attacker.Damage(val);
						}
					}
				}
				catch (Exception e)
				{
					Warn("reflect", e);
				}
			}
		}

		private sealed class DeathThroesSeen
		{
		}

		private sealed class DeathThroesDriver : MonoBehaviour
		{
		}

		private static class DeathThroesPatches
		{
			[HarmonyPatch(typeof(Character), "OnDeath")]
			[HarmonyPrefix]
			private static void Dying(Character __instance)
			{
				try
				{
					if (Owned(__instance))
					{
						StartDeathThroes(__instance);
					}
				}
				catch (Exception e)
				{
					Warn("death-throes", e);
				}
			}

			[HarmonyPatch(typeof(ZNetScene), "OnZDODestroyed")]
			[HarmonyPrefix]
			private static void RemoteDeath(ZNetScene __instance, ZDO zdo)
			{
				try
				{
					if (Enabled && !((Object)(object)__instance == (Object)null) && zdo != null)
					{
						ZNetView val = __instance.FindInstance(zdo);
						if ((Object)(object)val != (Object)null)
						{
							StartDeathThroes(((Component)val).GetComponent<Character>());
						}
					}
				}
				catch (Exception e)
				{
					Warn("death-throes-remote", e);
				}
			}
		}

		private sealed class DevouredDeath
		{
			public ZDOID Id;
		}

		private static class DevourerPatches
		{
			[HarmonyPatch(typeof(Character), "OnDeath")]
			[HarmonyPrefix]
			private static void Dying(Character __instance)
			{
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0074: Expected O, but got Unknown
				//IL_007b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0082: Expected O, but got Unknown
				//IL_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (!Enabled || !Owned(__instance) || __instance.IsPlayer() || !__instance.IsDead())
					{
						return;
					}
					ZDO zDO = __instance.m_nview.GetZDO();
					if (Server)
					{
						DevourDeath(zDO);
						return;
					}
					ZRoutedRpc instance = ZRoutedRpc.instance;
					ZDOPeer val = ((instance == null || ZDOMan.instance == null) ? null : ZDOMan.instance.GetPeer(instance.GetServerPeerID()));
					if (val != null)
					{
						ZPackage val2 = new ZPackage();
						zDO.Serialize(val2);
						ZPackage val3 = new ZPackage();
						val3.Write(0);
						val3.Write(zDO.m_uid);
						val3.Write(zDO.OwnerRevision);
						val3.Write(zDO.DataRevision);
						val3.Write(zDO.GetOwner());
						val3.Write(zDO.GetPosition());
						val3.Write(val2);
						val3.Write(ZDOID.None);
						val.m_peer.m_rpc.Invoke("ZDOData", new object[1] { val3 });
					}
				}
				catch (Exception e)
				{
					Warn("devourer-death", e);
				}
			}

			[HarmonyPatch(typeof(ZNetScene), "OnZDODestroyed")]
			[HarmonyPrefix]
			private static void Destroyed(ZDO zdo)
			{
				try
				{
					DevourDeath(zdo);
				}
				catch (Exception e)
				{
					Warn("devourer-remote-death", e);
				}
			}
		}

		private static class DrainingPatches
		{
			[HarmonyPatch(typeof(Character), "ApplyDamage")]
			[HarmonyPrefix]
			private static void BeforeHit(Character __instance, HitData hit, out float __state)
			{
				__state = -1f;
				try
				{
					if (Owned(__instance) && __instance.IsPlayer() && hit != null && HasActive(hit.GetAttacker(), "Draining"))
					{
						__state = __instance.GetHealth();
					}
				}
				catch (Exception e)
				{
					Warn("draining-hit", e);
				}
			}

			[HarmonyPatch(typeof(Character), "ApplyDamage")]
			[HarmonyPostfix]
			private static void AfterHit(Character __instance, float __state)
			{
				try
				{
					if (!(__state <= 0f) && Owned(__instance))
					{
						float num = BossDrainingRules.Stamina(__state, __instance.GetHealth());
						if (num > 0f)
						{
							__instance.UseStamina(num);
						}
					}
				}
				catch (Exception e)
				{
					Warn("draining-stamina", e);
				}
			}
		}

		private sealed class StompSeen
		{
			public long Warning;

			public long Impact;
		}

		private static class EarthshakerPatches
		{
			[HarmonyPatch(typeof(Character), "IsStaggering")]
			[HarmonyPostfix]
			private static void Knocked(Character __instance, ref bool __result)
			{
				if (_knockedUntil > 0.0 && Enabled && (Object)(object)__instance == (Object)(object)Player.m_localPlayer && BossEarthshakerRules.Active(Now, _knockedUntil))
				{
					__result = true;
				}
			}
		}

		private sealed class EchoBudget
		{
			public double Start;

			public int Count;
		}

		private sealed class EchoAttack
		{
			public Attack Attack;

			public bool Projectile;

			public double Due;

			public long Stamp;

			public int Slot;
		}

		private struct SpawnScope
		{
			public ZDOID Parent;

			public bool Echo;
		}

		private static class EchoPatches
		{
			[HarmonyPatch(typeof(SpawnAbility), "Spawn")]
			[HarmonyPostfix]
			private static void Ability(SpawnAbility __instance, ref IEnumerator __result)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				SpawnScope spawnScope = new SpawnScope
				{
					Parent = _spawningBoss,
					Echo = _echoSpawning
				};
				if (((ZDOID)(ref spawnScope.Parent)).IsNone())
				{
					Character owner = __instance.m_owner;
					if (!Valid(owner))
					{
						return;
					}
					spawnScope.Parent = owner.m_nview.GetZDO().GetZDOID("meadworks.boss.spawn.parent");
					if (((ZDOID)(ref spawnScope.Parent)).IsNone())
					{
						return;
					}
					spawnScope.Echo = EchoSpawn(owner.m_nview.GetZDO());
				}
				__result = SpawnAbilitySteps(__instance, __result, spawnScope.Parent, spawnScope.Echo);
			}

			[HarmonyPatch(typeof(Attack), "FireProjectileBurst")]
			[HarmonyPostfix]
			private static void ProjectileAttack(Attack __instance)
			{
				QueueEcho(__instance, projectile: true);
			}

			[HarmonyPatch(typeof(Attack), "DoAreaAttack")]
			[HarmonyPostfix]
			private static void AreaAttack(Attack __instance)
			{
				QueueEcho(__instance, projectile: false);
			}

			private static void ChildAttack(Attack __instance, out SpawnScope __state)
			{
				EnterSpawn(((Object)(object)__instance.m_character == (Object)null) ? null : ((Character)__instance.m_character).m_nview, out __state);
			}

			private static void ChildAttackEnd(SpawnScope __state)
			{
				ExitSpawn(__state);
			}

			[HarmonyPatch(typeof(Projectile), "SpawnOnHit")]
			[HarmonyPrefix]
			private static void ProjectileChildren(Projectile __instance, out SpawnScope __state)
			{
				EnterSpawn(__instance.m_nview, out __state);
			}

			[HarmonyPatch(typeof(Projectile), "SpawnOnHit")]
			[HarmonyFinalizer]
			private static void ProjectileChildrenEnd(SpawnScope __state)
			{
				ExitSpawn(__state);
			}

			private static void AreaChildren(Aoe __instance, out SpawnScope __state)
			{
				EnterSpawn(__instance.m_nview, out __state);
			}

			private static void AreaChildrenEnd(SpawnScope __state)
			{
				ExitSpawn(__state);
			}

			[HarmonyPatch(typeof(Aoe), "GetDamage", new Type[] { typeof(int) })]
			[HarmonyPostfix]
			private static void AreaDamage(Aoe __instance, ref DamageTypes __result)
			{
				if ((Object)(object)__instance.m_nview != (Object)null && __instance.m_nview.IsValid() && EchoSpawn(__instance.m_nview.GetZDO()) && (!__instance.m_useAttackSettings || __instance.m_hitData == null))
				{
					((DamageTypes)(ref __result)).Modify(0.5f);
				}
			}

			[HarmonyPatch(typeof(Projectile), "Setup")]
			[HarmonyPostfix]
			private static void ProjectileDamage(Projectile __instance, HitData hitData)
			{
				if (hitData == null && (Object)(object)__instance.m_nview != (Object)null && __instance.m_nview.IsValid() && EchoSpawn(__instance.m_nview.GetZDO()))
				{
					((DamageTypes)(ref __instance.m_damage)).Modify(0.5f);
				}
			}
		}

		private sealed class EmberVisuals
		{
			public readonly GameObject[] Objects = (GameObject[])(object)new GameObject[8];

			public readonly long[] Stamps = new long[8];
		}

		private static class EncounterPatches
		{
			[HarmonyPatch(typeof(MonsterAI), "UpdateTarget")]
			[HarmonyPostfix]
			private static void Target(MonsterAI __instance, ref bool canHearTarget, ref bool canSeeTarget)
			{
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					Character character = ((BaseAI)__instance).m_character;
					if (!Owned(character) || !BossAspectRules.Has(Of(character), "Fixated"))
					{
						return;
					}
					ZDO zDO = character.m_nview.GetZDO();
					if (Now >= (double)zDO.GetLong(FixatedUntilKey, 0L) / 10000000.0 || (Object)(object)ZNetScene.instance == (Object)null)
					{
						return;
					}
					GameObject val = ZNetScene.instance.FindInstance(zDO.GetZDOID("meadworks.boss.fixated.target"));
					Player val2 = (((Object)(object)val == (Object)null) ? null : val.GetComponent<Player>());
					if (!((Object)(object)val2 == (Object)null) && !((Character)val2).IsDead())
					{
						bool flag = ((BaseAI)__instance).CanHearTarget((Character)(object)val2);
						bool flag2 = ((BaseAI)__instance).CanSeeTarget((Character)(object)val2);
						if (BossAspectRules.FixatedSenses(flag, flag2))
						{
							__instance.m_targetCreature = (Character)(object)val2;
							__instance.m_targetStatic = null;
							canHearTarget = flag;
							canSeeTarget = flag2;
							((BaseAI)__instance).SetTargetInfo(((Character)val2).GetZDOID());
						}
					}
				}
				catch (Exception e)
				{
					Warn("fixated", e);
				}
			}

			[HarmonyPatch(typeof(CharacterDrop), "GenerateDropList")]
			[HarmonyPostfix]
			[HarmonyPriority(800)]
			private static void AspectLoot(CharacterDrop __instance, List<KeyValuePair<GameObject, int>> __result)
			{
				//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f5: Invalid comparison between Unknown and I4
				try
				{
					if ((Object)(object)__instance == (Object)null || __result == null || __instance.m_drops == null)
					{
						return;
					}
					Character component = ((Component)__instance).GetComponent<Character>();
					if (!Owned(component) || !component.IsBoss())
					{
						return;
					}
					decimal num = BossAspectInfoRules.LootMultiplier(Of(component));
					if (num <= 1m)
					{
						return;
					}
					for (int i = 0; i < __result.Count; i++)
					{
						KeyValuePair<GameObject, int> entry = __result[i];
						if ((Object)(object)entry.Key == (Object)null || !__instance.m_drops.Exists((Drop drop) => drop != null && (Object)(object)drop.m_prefab == (Object)(object)entry.Key))
						{
							continue;
						}
						ItemDrop component2 = entry.Key.GetComponent<ItemDrop>();
						bool trophy = component2 != null && (int)(component2.m_itemData?.m_shared?.m_itemType).GetValueOrDefault() == 13;
						if (BossAspectInfoRules.CanMultiply(Utils.GetPrefabName(entry.Key), trophy))
						{
							__result[i] = new KeyValuePair<GameObject, int>(entry.Key, BossAspectInfoRules.Amount(entry.Value, num, () => Random.value));
						}
					}
				}
				catch (Exception e)
				{
					Warn("aspectloot", e);
				}
			}

			[HarmonyPatch(typeof(TeleportWorld), "Teleport")]
			[HarmonyPrefix]
			private static bool Portal(TeleportWorld __instance, Player player, bool __runOriginal = true)
			{
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				if (!__runOriginal)
				{
					return false;
				}
				try
				{
					if (!Enabled || !BlockPortal(((Component)__instance).transform.position))
					{
						return true;
					}
					if ((Object)(object)player != (Object)null)
					{
						((Character)player).Message((MessageType)2, "$msg_blockedbyboss", 0, (Sprite)null, false);
					}
					return false;
				}
				catch (Exception e)
				{
					Warn("portal", e);
					return true;
				}
			}
		}

		private sealed class GravityField
		{
			public Vector3 Point;

			public double Until;
		}

		private sealed class ArenaHex : StatusEffect
		{
			public Character Source;

			public double Until;

			public bool Active()
			{
				if (Owned(base.m_character) && !base.m_character.IsDead() && ArenaActive(Source, "Hexing"))
				{
					return BossAspectArenaRules.HexActive(Now, Until);
				}
				return false;
			}

			public override bool IsDone()
			{
				if (Active())
				{
					return ((StatusEffect)this).IsDone();
				}
				return true;
			}
		}

		private static class PhantomPatches
		{
			[HarmonyPatch(typeof(Character), "IsTeleporting")]
			[HarmonyPostfix]
			private static void Untargetable(Character __instance, ref bool __result)
			{
				try
				{
					if (Phased(__instance))
					{
						__result = true;
					}
				}
				catch (Exception e)
				{
					Warn("phase", e);
				}
			}

			[HarmonyPatch(typeof(BaseAI), "IsEnemy", new Type[]
			{
				typeof(Character),
				typeof(Character)
			})]
			[HarmonyPrefix]
			private static bool Target(Character b, ref bool __result, bool __runOriginal = true)
			{
				if (!__runOriginal)
				{
					return false;
				}
				try
				{
					if (!Phased(b))
					{
						return true;
					}
					__result = false;
					return false;
				}
				catch (Exception e)
				{
					Warn("phase-target", e);
					return true;
				}
			}
		}

		private static class AuthorityPatches
		{
			[HarmonyPatch(typeof(ZNet), "Awake")]
			[HarmonyPostfix]
			private static void Started()
			{
				try
				{
					Authority.Clear();
					ClearStars();
					ClearAltars();
					BossPrefabs.Clear();
					ClearCombat();
					Register();
				}
				catch (Exception e)
				{
					Warn("start", e);
				}
			}

			[HarmonyPatch(typeof(ZDOMan), "Load")]
			[HarmonyPostfix]
			private static void Loaded(ZDOMan __instance)
			{
				try
				{
					Import(__instance);
				}
				catch (Exception e)
				{
					Warn("load", e);
				}
			}

			[HarmonyPatch(typeof(ZDOMan), "LoadChunks")]
			[HarmonyPostfix]
			private static void LoadedChunks(ZDOMan __instance)
			{
				Loaded(__instance);
			}

			[HarmonyPatch(typeof(ZDO), "Deserialize")]
			[HarmonyPostfix]
			private static void Received(ZDO __instance)
			{
				try
				{
					Validate(__instance);
				}
				catch (Exception e)
				{
					Warn("validate", e);
				}
			}

			[HarmonyPatch(typeof(Character), "Awake")]
			[HarmonyPostfix]
			private static void Spawned(Character __instance)
			{
				//IL_0051: Unknown result type (might be due to invalid IL or missing references)
				//IL_0056: Unknown result type (might be due to invalid IL or missing references)
				//IL_005b: 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)
				try
				{
					if (CreatureSession.Allowed && !((Object)(object)__instance.m_nview == (Object)null) && __instance.m_nview.IsValid() && __instance.IsBoss())
					{
						ZDO zDO = __instance.m_nview.GetZDO();
						Ensure(zDO);
						if (__instance.m_nview.IsOwner() && zDO.GetVec3(PhantomAnchorKey, Vector3.zero) == Vector3.zero)
						{
							zDO.Set(PhantomAnchorKey, ((Component)__instance).transform.position);
						}
						Refit(__instance);
					}
				}
				catch (Exception e)
				{
					Warn("spawn", e);
				}
			}

			[HarmonyPatch(typeof(ZDOMan), "HandleDestroyedZDO")]
			[HarmonyPostfix]
			private static void Destroyed(ZDOID uid)
			{
				//IL_0005: 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_001c: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					Authority.Remove(uid);
					StarCounts.Remove(uid);
					CountedDeaths.Remove(uid);
				}
				catch (Exception e)
				{
					Warn("destroy", e);
				}
			}

			[HarmonyPatch(typeof(ZNet), "StopAll")]
			[HarmonyPostfix]
			private static void Stopped()
			{
				try
				{
					Authority.Clear();
					ClearStars();
					ClearAltars();
					BossPrefabs.Clear();
					ClearCombat();
					Unregister();
				}
				catch (Exception e)
				{
					Warn("stop", e);
				}
			}
		}

		private static class SpawnPatches
		{
			[HarmonyPatch(typeof(ZNetView), "ResetZDO")]
			[HarmonyPrefix]
			private static void Unloading(ZNetView __instance)
			{
				//IL_003d: 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_0056: 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)
				if (!__instance.IsValid())
				{
					return;
				}
				ZDO zDO = __instance.GetZDO();
				if (zDO.GetFloat(ZDOVars.s_health, 1f) <= 0f)
				{
					CleanupChildren(zDO.m_uid);
				}
				if (SpawnIndex.Entries.ContainsKey(zDO.m_uid))
				{
					ZDOMan instance = ZDOMan.instance;
					if (((instance != null) ? instance.GetZDO(zDO.m_uid) : null) == null)
					{
						Removed(zDO.m_uid);
					}
				}
			}

			[HarmonyPatch(typeof(Character), "Awake")]
			[HarmonyPrefix]
			private static void PrepareChild(Character __instance)
			{
				ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
				if (!((ZDOID)(ref _spawningBoss)).IsNone() || (!((Object)(object)component == (Object)null) && component.IsValid() && IsAspectSpawn(component.GetZDO())))
				{
					__instance.m_boss = false;
					__instance.m_defeatSetGlobalKey = "";
					__instance.m_dreamCinematic = "";
				}
			}

			[HarmonyPatch(typeof(ZNetView), "Awake")]
			[HarmonyPostfix]
			private static void Created(ZNetView __instance)
			{
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: 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)
				if (CreatureSession.Allowed && !((ZDOID)(ref _spawningBoss)).IsNone() && __instance.IsValid())
				{
					ZDO zDO = __instance.GetZDO();
					SpawnIndex.Add(zDO.m_uid, _spawningBoss);
					zDO.Set("meadworks.boss.spawn.parent", _spawningBoss);
					if ((Object)(object)((Component)__instance).GetComponent<Character>() != (Object)null)
					{
						zDO.Persistent = true;
						__instance.m_persistent = true;
					}
					if (_echoSpawning)
					{
						EchoSpawns.Add(zDO.m_uid);
						zDO.Set("meadworks.boss.spawn.echo", true);
					}
				}
			}

			[HarmonyPatch(typeof(Character), "OnDeath")]
			[HarmonyPrefix]
			[HarmonyPriority(800)]
			private static bool Dying(Character __instance, bool __runOriginal = true)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				if (!__runOriginal)
				{
					return false;
				}
				if (!Valid(__instance))
				{
					return true;
				}
				CleanupChildren(__instance.GetZDOID());
				if (!IsAspectSpawn(__instance.m_nview.GetZDO()))
				{
					return true;
				}
				if (Owned(__instance))
				{
					ZNetScene.instance.Destroy(((Component)__instance).gameObject);
				}
				return false;
			}

			[HarmonyPatch(typeof(Character), "OnDestroy")]
			[HarmonyPrefix]
			private static void Despawn(Character __instance)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: 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_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)
				if (!Valid(__instance))
				{
					return;
				}
				ZDOID zDOID = __instance.GetZDOID();
				if (__instance.IsDead())
				{
					CleanupChildren(zDOID);
				}
				if (SpawnIndex.Entries.ContainsKey(zDOID))
				{
					ZDOMan instance = ZDOMan.instance;
					if (((instance != null) ? instance.GetZDO(zDOID) : null) == null)
					{
						Removed(zDOID);
					}
				}
			}

			[HarmonyPatch(typeof(ZDOMan), "RemovePeer")]
			[HarmonyPrefix]
			private static void Disconnect(ZNetPeer netPeer)
			{
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: 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)
				if (!Server || ZDOMan.instance == null)
				{
					return;
				}
				foreach (ZDOID item in new HashSet<ZDOID>(SpawnIndex.Entries.Values))
				{
					if (ZDOMan.instance.GetZDO(item) == null)
					{
						CleanupChildren(item);
					}
				}
			}

			[HarmonyPatch(typeof(ZDOMan), "DestroyZDO")]
			[HarmonyPrefix]
			private static void Destroying(ZDO zdo)
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				if (zdo != null && zdo.IsOwner())
				{
					Removed(zdo.m_uid);
				}
			}

			[HarmonyPatch(typeof(ZDOMan), "HandleDestroyedZDO")]
			[HarmonyPrefix]
			private static void Removed(ZDOID uid)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: 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_002e: 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_0046: 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_005e: 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_0071: Unknown result type (might be due to invalid IL or missing references)
				CleanupChildren(uid);
				SpawnIndex.Remove(uid);
				Minions.Remove(uid);
				TwinUsed.Remove(uid);
				EchoSpawns.Remove(uid);
				SummonGrants.Remove(uid);
				EchoGrants.Remove(uid);
				EchoReceipts.Remove(uid);
				EchoBudgets.Remove(uid);
				TwinRequests.Remove(uid);
				ForgetTether(uid);
			}

			[HarmonyPatch(typeof(ZDO), "Deserialize")]
			[HarmonyPostfix]
			private static void ReceivedSpawn(ZDO __instance)
			{
				//IL_000d: 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_0060: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f3: 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_00d7: 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_011e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0102: Unknown result type (might be due to invalid IL or missing references)
				//IL_0163: Unknown result type (might be due to invalid IL or missing references)
				//IL_012e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0133: 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_014d: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
				if (Server && TwinUsed.Contains(__instance.m_uid))
				{
					ZDOExtraData.Set(__instance.m_uid, StringExtensionMethods.GetStableHashCode("meadworks.boss.twin.used"), 1);
				}
				if (!Server)
				{
					return;
				}
				if (__instance.GetFloat(ZDOVars.s_health, 1f) <= 0f)
				{
					CleanupChildren(__instance.m_uid);
				}
				if (EchoGrants.TryGetValue(__instance.m_uid, out var value))
				{
					for (int i = 0; i < value.Length; i++)
					{
						if (value[i] > 0)
						{
							ZDOExtraData.Set(__instance.m_uid, EchoGrantKeys[i], value[i]);
						}
					}
				}
				if (EchoBudgets.TryGetValue(__instance.m_uid, out var value2))
				{
					ZDOExtraData.Set(__instance.m_uid, EchoWindowKey, (long)(value2.Start * 10000000.0));
					ZDOExtraData.Set(__instance.m_uid, EchoCountKey, value2.Count);
				}
				if (SummonGrants.TryGetValue(__instance.m_uid, out var value3))
				{
					ZDOExtraData.Set(__instance.m_uid, SummonGrantKey, value3);
				}
				ZDOID zDOID = __instance.GetZDOID(SpawnParentHashes);
				if (!((ZDOID)(ref zDOID)).IsNone())
				{
					SpawnIndex.Add(__instance.m_uid, zDOID);
					if (__instance.GetBool("meadworks.boss.spawn.echo", false))
					{
						EchoSpawns.Add(__instance.m_uid);
					}
				}
				if (SpawnIndex.Entries.TryGetValue(__instance.m_uid, out var value4))
				{
					GameObject val = (((Object)(object)ZNetScene.instance == (Object)null) ? null : ZNetScene.instance.GetPrefab(__instance.GetPrefab()));
					if ((Object)(object)val != (Object)null && (Object)(object)val.GetComponent<Character>() != (Object)null)
					{
						__instance.Persistent = true;
					}
					KeyValuePair<int, int> spawnParentHashes = SpawnParentHashes;
					ZDOExtraData.Set(__instance.m_uid, spawnParentHashes.Key, ((ZDOID)(ref value4)).UserID);
					ZDOExtraData.Set(__instance.m_uid, spawnParentHashes.Value, (long)((ZDOID)(ref value4)).ID);
				}
			}

			[HarmonyPatch(typeof(ZDOMan), "GetSaveClonePerChunk")]
			[HarmonyPostfix]
			private static void FilterSave(ref List<Tuple<ChunkIndex, List<ZDO>>> __result)
			{
				if (!Server)
				{
					return;
				}
				foreach (Tuple<ChunkIndex, List<ZDO>> item in __result)
				{
					item.Item2.RemoveAll(IsAspectSpawn);
				}
			}

			[HarmonyPatch(typeof(ZDOMan), "PrepareSave")]
			[HarmonyPrefix]
			private static void BeforeSave()
			{
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				if (!Server || ZDOMan.instance == null)
				{
					return;
				}
				foreach (ZDOID item in TwinUsed)
				{
					if (ZDOMan.instance.GetZDO(item) != null)
					{
						ZDOExtraData.Set(item, StringExtensionMethods.GetStableHashCode("meadworks.boss.twin.used"), 1);
					}
				}
			}

			[HarmonyPatch(typeof(Character), "SetupMaxHealth")]
			[HarmonyPostfix]
			private static void CopyHealth(Character __instance)
			{
				if (Owned(__instance) && IsAspectSpawn(__instance.m_nview.GetZDO()))
				{
					float num = __instance.m_nview.GetZDO().GetFloat("meadworks.boss.twin.health", 0f);
					if (!(num <= 0f))
					{
						float healthPercentage = __instance.GetHealthPercentage();
						__instance.SetMaxHealth(num);
						__instance.SetHealth(num * healthPercentage);
					}
				}
			}

			[HarmonyPatch(typeof(ZNet), "StopAll")]
			[HarmonyPrefix]
			private static void Stop()
			{
				ClearSpawns();
			}
		}

		private static class SteadfastPatches
		{
			[HarmonyPatch(typeof(Character), "ApplyDamage")]
			[HarmonyPrefix]
			[HarmonyPriority(0)]
			private static void CapHit(Character __instance, HitData hit)
			{
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (hit != null && Owned(__instance) && BossAspectRules.Has(Of(__instance), "Steadfast"))
					{
						float difficultyScale = (((Object)(object)Game.instance == (Object)null) ? 1f : (Game.instance.GetDifficultyDamageScaleEnemy(((Component)__instance).transform.position) * Game.m_playerDamageRate));
						((DamageTypes)(ref hit.m_damage)).Modify(BossSteadfastRules.Scale(hit.GetTotalDamage(), __instance.GetMaxHealth(), difficultyScale));
					}
				}
				catch (Exception e)
				{
					Warn("steadfast", e);
				}
			}
		}

		private sealed class StormMarker
		{
			public ZDOID Boss;

			public GameObject Object;

			public Material Material;

			public double Until;
		}

		private sealed class SunderBlockState
		{
			public Humanoid Previous;

			public ItemData Shield;

			public float Durability;
		}

		private static class SunderingPatches
		{
			[HarmonyPatch(typeof(Humanoid), "BlockAttack")]
			[HarmonyPrefix]
			private static void Blocking(Humanoid __instance, HitData hit, out SunderBlockState __state)
			{
				__state = new SunderBlockState
				{
					Previous = _sunderingBlock
				};
				_sunderingBlock = null;
				try
				{
					if (Owned((Character)(object)__instance) && ((Character)__instance).IsPlayer() && hit != null && HasActive(hit.GetAttacker(), "Sundering"))
					{
						_sunderingBlock = __instance;
						__state.Shield = __instance.GetCurrentBlocker();
						if (__state.Shield != null)
						{
							__state.Durability = __state.Shield.m_durability;
						}
					}
				}
				catch (Exception e)
				{
					Warn("sundering-block", e);
				}
			}

			[HarmonyPatch(typeof(Player), "UseStamina")]
			[HarmonyPrefix]
			private static void BlockCost(Player __instance, ref float v)
			{
				v = BossSunderingRules.Stamina(v, (Object)(object)__instance == (Object)(object)_sunderingBlock);
			}

			[HarmonyPatch(typeof(Humanoid), "BlockAttack")]
			[HarmonyFinalizer]
			private static Exception Blocked(SunderBlockState __state, Exception __exception)
			{
				try
				{
					ItemData val = __state?.Shield;
					if (val != null && val.m_shared.m_useDurability)
					{
						val.m_durability -= BossSunderingRules.ExtraWear(__state.Durability, val.m_durability);
					}
				}
				catch (Exception e)
				{
					Warn("sundering-wear", e);
				}
				finally
				{
					_sunderingBlock = __state?.Previous;
				}
				return __exception;
			}
		}

		private struct Sent
		{
			public ZDOID Boss;

			public ZDOID Player;

			public double At;
		}

		private struct Tie
		{
			public ZDOID Boss;

			public ZDOID Player;

			public double Until;

			public double Admitted;
		}

		private sealed class TetherClock : MonoBehaviour
		{
			private void OnEnable()
			{
				((MonoBehaviour)this).InvokeRepeating("Tick", 1f, 1f);
			}

			private void Tick()
			{
				try
				{
					HostTickTethers();
				}
				catch (Exception e)
				{
					Warn("tether", e);
				}
			}

			private void OnDestroy()
			{
				((MonoBehaviour)this).CancelInvoke();
			}
		}

		private static class UnshakablePatches
		{
			[HarmonyPatch(typeof(Character), "RPC_Stagger")]
			[HarmonyPrefix]
			private static bool Stagger(Character __instance, bool __runOriginal = true)
			{
				if (!__runOriginal)
				{
					return false;
				}
				try
				{
					return BossUnshakableRules.AllowStagger(BossAspectRules.Has(Of(__instance), "Unshakable"));
				}
				catch (Exception e)
				{
					Warn("unshakable-stagger", e);
					return true;
				}
			}

			[HarmonyPatch(typeof(Character), "AddStaggerDamage")]
			[HarmonyPrefix]
			private static bool StaggerDamage(Character __instance, ref bool __result, bool __runOriginal = true)
			{
				if (!__runOriginal)
				{
					return false;
				}
				if (Stagger(__instance))
				{
					return true;
				}
				__result = false;
				return false;
			}

			[HarmonyPatch(typeof(Character), "ApplyPushback", new Type[]
			{
				typeof(Vector3),
				typeof(float)
			})]
			[HarmonyPrefix]
			private static void Push(Character __instance, ref float pushForce)
			{
				try
				{
					pushForce = BossUnshakableRules.Pushback(pushForce, BossAspectRules.Has(Of(__instance), "Unshakable"));
				}
				catch (Exception e)
				{
					Warn("unshakable-push", e);
				}
			}
		}

		private sealed class ArenaWarcall : StatusEffect
		{
			public Character Source;

			private Character _previousTarget;

			private Character _ralliedTarget;

			private StaticTarget _previousStatic;

			private bool _remembered;

			private bool _previousAlert;

			private double _nextPulse;

			public bool Active()
			{
				return WarcallActive(Source, base.m_character);
			}

			public override bool IsDone()
			{
				if (Active())
				{
					return ((StatusEffect)this).IsDone();
				}
				return true;
			}

			public override void ModifyAttack(SkillType skill, ref HitData hitData)
			{
				if (Active() && hitData != null)
				{
					((DamageTypes)(ref hitData.m_damage)).Modify(1.2f);
				}
			}

			public Character Rally()
			{
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_00de: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
				if (!Active() || (Object)(object)ZNetScene.instance == (Object)null)
				{
					return null;
				}
				GameObject val = ZNetScene.instance.FindInstance(Source.m_nview.GetZDO().GetZDOID("meadworks.boss.arena.target"));
				Character val2 = (((Object)(object)val == (Object)null) ? null : val.GetComponent<Character>());
				MonsterAI component = ((Component)base.m_character).GetComponent<MonsterAI>();
				if (!Valid(val2) || val2.IsDead() || (Object)(object)val2 == (Object)(object)base.m_character || (Object)(object)component == (Object)null || !((BaseAI)component).CanSeeTarget(val2))
				{
					return null;
				}
				if (!_remembered)
				{
					_previousTarget = component.m_targetCreature;
					_previousStatic = component.m_targetStatic;
					_previousAlert = ((BaseAI)component).IsAlerted();
					_remembered = true;
				}
				component.m_targetCreature = (_ralliedTarget = val2);
				component.m_targetStatic = null;
				component.m_lastKnownTargetPos = ((Component)val2).transform.position;
				component.m_timeSinceSensedTargetCreature = 0f;
				((BaseAI)component).SetTargetInfo(val2.GetZDOID());
				((BaseAI)component).SetAlerted(true);
				return val2;
			}

			public override void UpdateStatusEffect(float dt)
			{
				((StatusEffect)this).UpdateStatusEffect(dt);
				if (Active() && !(Now < _nextPulse))
				{
					_nextPulse = Now + 4.0;
					((StatusEffect)this).TriggerStartEffects();
				}
			}

			public override void Stop()
			{
				//IL_00c7: 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)
				WarcallAllies.Remove(base.m_character);
				MonsterAI val = (((Object)(object)base.m_character == (Object)null) ? null : ((Component)base.m_character).GetComponent<MonsterAI>());
				if (_remembered && Owned(base.m_character) && (Object)(object)val != (Object)null && (Object)(object)val.m_targetCreature == (Object)(object)_ralliedTarget)
				{
					val.m_targetCreature = (((Object)(object)_previousTarget != (Object)null && !_previousTarget.IsDead() && ((BaseAI)val).CanSeeTarget(_previousTarget)) ? _previousTarget : null);
					val.m_targetStatic = _previousStatic;
					((BaseAI)val).SetTargetInfo(Valid(val.m_targetCreature) ? val.m_targetCreature.GetZDOID() : ZDOID.None);
					((BaseAI)val).SetAlerted(_previousAlert);
				}
				((StatusEffect)this).Stop();
			}
		}

		private static class StarPatches
		{
			[HarmonyPatch(typeof(Character), "OnDeath")]
			[HarmonyPrefix]
			private static void Dying(Character __instance)
			{
				//IL_004c: 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_0094: Expected O, but got Unknown
				//IL_009b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a1: Expected O, but got Unknown
				//IL_00aa: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
				//IL_0132: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (!Owned(__instance) || !__instance.IsBoss() || !__instance.IsDead() || IsAspectSpawn(__instance.m_nview.GetZDO()))
					{
						return;
					}
					Register();
					if (Server)
					{
						ReceiveDeath(__instance.m_nview.GetZDO().GetOwner(), __instance.GetZDOID());
					}
					else if (_rpc != null)
					{
						ZDO zDO = __instance.m_nview.GetZDO();
						ZDOPeer peer = ZDOMan.instance.GetPeer(_rpc.GetServerPeerID());
						if (peer != null)
						{
							ZPackage val = new ZPackage();
							zDO.Serialize(val);
							ZPackage val2 = new ZPackage();
							val2.Write(0);
							val2.Write(zDO.m_uid);
							val2.Write(zDO.OwnerRevision);
							val2.Write(zDO.DataRevision);
							val2.Write(zDO.GetOwner());
							val2.Write(zDO.GetPosition());
							val2.Write(val);
							val2.Write(ZDOID.None);
							peer.m_peer.m_rpc.Invoke("ZDOData", new object[1] { val2 });
							_rpc.InvokeRoutedRPC(_rpc.GetServerPeerID(), "MW_CreaturesBossDeath", new object[1] { zDO.m_uid });
						}
					}
				}
				catch (Exception e)
				{
					Warn("deathsend", e);
				}
			}

			[HarmonyPatch(typeof(Character), "GetHoverName")]
			[HarmonyPostfix]
			private static void Name(Character __instance, ref string __result)
			{
				if (Valid(__instance) && __instance.IsBoss())
				{
					__result = BossStarRules.Name(__result, Stars(__instance.m_nview.GetZDO()));
				}
			}

			[HarmonyPatch(typeof(ZoneSystem), "RPC_SetGlobalKey")]
			[HarmonyPrefix]
			private static bool Key(long sender, string name, bool __runOriginal = true)
			{
				if (__runOriginal)
				{
					return BossStarRules.AcceptKey(sender, (ZRoutedRpc.instance == null) ? 0 : ZRoutedRpc.instance.GetServerPeerID(), name);
				}
				return false;
			}

			[HarmonyPatch(typeof(ZoneSystem), "RPC_RemoveGlobalKey")]
			[HarmonyPrefix]
			private static bool RemoveKey(long sender, string name, bool __runOriginal = true)
			{
				if (__runOriginal)
				{
					return Key(sender, name);
				}
				return false;
			}
		}

		private const string AltarStartedRpc = "MW_CreaturesAltarStarted";

		private const string AltarPressRpc = "MW_CreaturesAltarPress";

		private const string AltarKey = "meadworks.boss.altar";

		private static readonly int SpawnBossHash = StringExtensionMethods.GetStableHashCode("RPC_SpawnBoss");

		private static readonly Dictionary<ZDOID, AltarSummon> AltarSummons = new Dictionary<ZDOID, AltarSummon>();

		private static readonly List<ZDOID> ExpiredAltars = new List<ZDOID>();

		private static readonly BossAltarRules.Interactions<ZDOID> AltarInteractions = new BossAltarRules.Interactions<ZDOID>();

		private static readonly BossAltarRules.Interactions<ZDOID> AltarPresses = new BossAltarRules.Interactions<ZDOID>();

		private static Setting<bool> _altarChoice;

		private static ZDOID _spawningAltar;

		private static ZDOID _hoverAltar = ZDOID.None;

		private static long _hoverWindow = long.MinValue;

		private static int _hoverRemaining = -1;

		private static string _hoverAspects;

		private static string _hoverLine;

		private static Color _hoverHighlight;

		private static readonly int ArenaEngagedKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.arena.engaged");

		private const string ArenaTargetKey = "meadworks.boss.arena.target";

		private static readonly Dictionary<Character, double> ArenaTicks = new Dictionary<Character, double>();

		private static Character _wintrySource;

		private static Player _wintryPlayer;

		private static StatusEffect _wintryCold;

		private static StatusEffect _wintryWet;

		private static SEMan _wintryWeather;

		private static readonly int ShieldKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.shield");

		private static readonly int ShieldHitKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.shield.hit");

		private static readonly Dictionary<Character, VisualState> Visuals = new Dictionary<Character, VisualState>();

		private const short ReflectedToolTier = short.MinValue;

		private static ConditionalWeakTable<Character, DeathThroesSeen> DeathBursts = new ConditionalWeakTable<Character, DeathThroesSeen>();

		private static GameObject _deathThroesHost;

		private static ConditionalWeakTable<ZDO, DevouredDeath> Devoured = new ConditionalWeakTable<ZDO, DevouredDeath>();

		private static readonly int EarthshakerNextKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.earthshaker.next");

		private static readonly int EarthshakerDueKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.earthshaker.due");

		private static ConditionalWeakTable<Character, StompSeen> Stomps = new ConditionalWeakTable<Character, StompSeen>();

		private static double _knockedUntil;

		private const string EchoRpc = "MW_CreaturesBossEcho";

		private const int EchoSlots = 8;

		private static readonly int[] EchoPendingKeys = EchoKeys("pending");

		private static readonly int[] EchoGrantKeys = EchoKeys("grant");

		private static readonly Dictionary<ZDOID, long[]> EchoGrants = new Dictionary<ZDOID, long[]>();

		private static readonly Dictionary<ZDOID, long[]> EchoReceipts = new Dictionary<ZDOID, long[]>();

		private static readonly int EchoWindowKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.echo.window");

		private static readonly int EchoCountKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.echo.count");

		private static readonly Dictionary<ZDOID, EchoBudget> EchoBudgets = new Dictionary<ZDOID, EchoBudget>();

		private const string EchoSpawnKey = "meadworks.boss.spawn.echo";

		private static readonly Dictionary<ZDOID, List<EchoAttack>> Echoes = new Dictionary<ZDOID, List<EchoAttack>>();

		private static readonly HashSet<ZDOID> EchoSpawns = new HashSet<ZDOID>();

		private static readonly Dictionary<SpawnAbility, ZDOID> SpawnAbilities = new Dictionary<SpawnAbility, ZDOID>();

		private static bool _echoReplaying;

		private static bool _echoSpawning;

		private static readonly int EmberNextKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.ember.next");

		private static readonly int EmberHitKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.ember.hit");

		private static readonly int EmberLastKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.ember.last");

		private static readonly int EmberSlotKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.ember.slot");

		private static readonly int[] EmberPoints = EmberKeys("point");

		private static readonly int[] EmberUntils = EmberKeys("until");

		private static readonly int[] EmberElements = EmberKeys("element");

		private static readonly string[] EmberDonors = new string[3] { "vfx_Burning", "vfx_Freezing", "vfx_Poison" };

		private static readonly GameObject[] EmberTemplates = (GameObject[])(object)new GameObject[3];

		private static readonly Dictionary<Character, EmberVisuals> EmberObjects = new Dictionary<Character, EmberVisuals>();

		private static readonly int AdaptiveKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.adaptive");

		private const string FixatedTargetKey = "meadworks.boss.fixated.target";

		private static readonly int FixatedUntilKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.fixated.until");

		private static readonly int FixatedDamageKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.fixated.damage");

		private const string GravityRpc = "MW_CreaturesBossGravity";

		private static readonly int GravityNextKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.gravity.next");

		private static readonly int GravityUntilKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.gravity.until");

		private static readonly Dictionary<ZDOID, GravityField> GravityFields = new Dictionary<ZDOID, GravityField>();

		private static readonly List<KeyValuePair<ZDOID, GravityField>> GravityScratch = new List<KeyValuePair<ZDOID, GravityField>>();

		private const int GravityHitCap = 16;

		private static readonly RaycastHit[] GravityHits = (RaycastHit[])(object)new RaycastHit[16];

		private static readonly float[] GravityHitDistances = new float[16];

		private static readonly float[] GravityHitNormals = new float[16];

		private static int _gravityMask;

		private static int _sweepMask;

		private static int _sweepLayer = -1;

		private static readonly int HexNextKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.hex.next");

		private static readonly int HexUntilKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.hex.until");

		private const string HexTargetKey = "meadworks.boss.hex.target";

		private static readonly int HexHash = StringExtensionMethods.GetStableHashCode("MW_BossHex");

		private static ArenaHex _hexTemplate;

		private static readonly int MendingUsesKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.mending.uses");

		private static readonly int MendingSpentKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.mending.spent");

		private static readonly int MendingUntilKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.mending.until");

		private static readonly int MendingLastKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.mending.last");

		private static readonly int MendingQuietKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.mending.quiet");

		private static readonly int PhantomNextKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.phantom.next");

		private static readonly int PhantomUntilKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.phantom.until");

		internal static readonly int PhantomAnchorKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.anchor");

		private static int _solidMask;

		internal static readonly int SelectionKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.aspects");

		private const string StampRpc = "MW_CreaturesBossAspectsV2";

		private static readonly BossAspectAuthorityRules<ZDOID> Authority = new BossAspectAuthorityRules<ZDOID>();

		private static ConditionalWeakTable<ZDO, BossSelectionCacheRules> SelectionCache = new ConditionalWeakTable<ZDO, BossSelectionCacheRules>();

		private static readonly Dictionary<string, Setting<bool>> Switches = new Dictionary<string, Setting<bool>>();

		private static readonly Dictionary<int, bool> BossPrefabs = new Dictionary<int, bool>();

		private static Setting<bool> _on;

		private static Setting<bool> _starsOn;

		private static Setting<float> _slots;

		private static ZRoutedRpc _rpc;

		private const string SpawnParentKey = "meadworks.boss.spawn.parent";

		private static readonly KeyValuePair<int, int> SpawnParentHashes = ZDO.GetHashZDOID("meadworks.boss.spawn.parent");

		private const string SpawnRpc = "MW_CreaturesBossSpawn";

		private const string SpawnStampRpc = "MW_CreaturesBossSpawnStamp";

		private static readonly int SummonNextKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.summon.next");

		private static readonly int SummonGrantKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.summon.grant");

		private static readonly Dictionary<ZDOID, long> SummonGrants = new Dictionary<ZDOID, long>();

		private static readonly Dictionary<ZDOID, double> TwinRequests = new Dictionary<ZDOID, double>();

		private static readonly BossSpawnIndexRules<ZDOID> SpawnIndex = new BossSpawnIndexRules<ZDOID>();

		private static readonly Dictionary<ZDOID, HashSet<SpawnAbility>> ParentAbilities = new Dictionary<ZDOID, HashSet<SpawnAbility>>();

		private static readonly HashSet<ZDOID> Minions = new HashSet<ZDOID>();

		private static readonly HashSet<ZDOID> TwinUsed = new HashSet<ZDOID>();

		private const string TwinUsedKey = "meadworks.boss.twin.used";

		private const string TwinHealthKey = "meadworks.boss.twin.health";

		private static ZDOID _spawningBoss;

		private const string StormRpc = "MW_CreaturesBossStorm";

		private static readonly int StormNextKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.storm.next");

		private static readonly int[] StormDueKeys = StormKeys("due");

		private static readonly int[] StormPointKeys = StormKeys("point");

		private static readonly int[] StormDamageKeys = StormKeys("damage");

		private static readonly string[] StormPlayerKeys = new string[2] { "meadworks.boss.storm.player.0", "meadworks.boss.storm.player.1" };

		private static readonly List<StormMarker> StormMarkers = new List<StormMarker>();

		private static bool _stormMaterialResolved;

		private static Material _stormMaterialSource;

		[ThreadStatic]
		private static Humanoid _sunderingBlock;

		private const string TetherAdmitRpc = "MW_CreaturesBossTetherAdmit";

		private const string TetherTickRpc = "MW_CreaturesBossTetherTick";

		private static readonly List<Tie> Ties = new List<Tie>();

		private static readonly List<Sent> SentRecently = new List<Sent>();

		private static TetherClock _tetherClock;

		private static readonly int WarcallHash = StringExtensionMethods.GetStableHashCode("MW_BossWarcall");

		private static readonly HashSet<Character> WarcallAllies = new HashSet<Character>();

		private static ArenaWarcall _warcallTemplate;

		private static readonly int StarsKey = StringExtensionMethods.GetStableHashCode("meadworks.boss.stars");

		private const string DeathRpc = "MW_CreaturesBossDeath";

		private static readonly Dictionary<ZDOID, int> StarCounts = new Dictionary<ZDOID, int>();

		private static readonly HashSet<ZDOID> CountedDeaths = new HashSet<ZDOID>();

		private static bool RotatingAltars
		{
			get
			{
				if (Enabled && _altarChoice != null && _altarChoice.Value)
				{
					return _slots.Value >= 1f;
				}
				return false;
			}
		}

		private static bool Night
		{
			get
			{
				if ((Object)(object)EnvMan.instance != (Object)null)
				{
					return EnvMan.IsNight();
				}
				return false;
			}
		}

		private static double Now
		{
			get
			{
				if (!((Object)(object)ZNet.instance == (Object)null))
				{
					return (double)ZNet.instance.GetTime().Ticks / 10000000.0;
				}
				return 0.0;
			}
		}

		private static int GravityMask
		{
			get
			{
				if (_gravityMask == 0)
				{
					return _gravityMask = LayerMask.GetMask(new string[7] { "Default", "static_solid", "Default_small", "piece", "terrain", "blocker", "vehicle" });
				}
				return _gravityMask;
			}
		}

		private static int SolidMask
		{
			get
			{
				if (_solidMask != 0)
				{
					return _solidMask;
				}
				return _solidMask = LayerMask.GetMask(new string[5] { "Default", "static_solid", "Default_small", "piece", "terrain" });
			}
		}

		private static bool Server
		{
			get
			{
				if ((Object)(object)ZNet.instance != (Object)null)
				{
					return ZNet.instance.IsServer();
				}
				return false;
			}
		}

		public static bool Enabled
		{
			get
			{
				if (CreatureSession.Allowed && _on != null)
				{
					return _on.Value;
				}
				return false;
			}
		}

		private static void ClearAltars()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			AltarSummons.Clear();
			ExpiredAltars.Clear();
			AltarInteractions.Clear();
			AltarPresses.Clear();
			_spawningAltar = ZDOID.None;
		}

		private static void PruneAltars()
		{
			//IL_0043: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			ExpiredAltars.Clear();
			foreach (KeyValuePair<ZDOID, AltarSummon> altarSummon in AltarSummons)
			{
				if (Time.realtimeSinceStartupAsDouble > altarSummon.Value.Until + 30.0)
				{
					ExpiredAltars.Add(altarSummon.Key);
				}
			}
			foreach (ZDOID expiredAltar in ExpiredAltars)
			{
				AltarSummons.Remove(expiredAltar);
			}
			ExpiredAltars.Clear();
			AltarInteractions.Prune(Time.realtimeSinceStartupAsDouble);
			AltarPresses.Prune(ZNet.instance.GetTimeSeconds());
		}

		private static AltarInfo DescribeBowl(OfferingBowl bowl)
		{
			if (!((Object)(object)bowl == (Object)null) && !((Object)(object)bowl.m_bossPrefab == (Object)null))
			{
				Character component = bowl.m_bossPrefab.GetComponent<Character>();
				if (component != null && component.IsBoss())
				{
					return new AltarInfo
					{
						Prefab = StringExtensionMethods.GetStableHashCode(((Object)bowl.m_bossPrefab).name),
						Delay = bowl.m_spawnBossDelay,
						Stars = ((_starsOn != null && _starsOn.Value) ? WorldDefeats(bowl.m_bossPrefab) : 0)
					};
				}
			}
			return null;
		}

		private static AltarInfo AltarBowl(ZDO zdo)
		{
			ZNetScene scene = ZNetScene.instance;
			if (zdo == null || (Object)(object)scene == (Object)null)
			{
				return null;
			}
			GameObject prefab = scene.GetPrefab(zdo.GetPrefab());
			return BossAltarRules.ResolveBowl(delegate
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				GameObject obj = scene.FindInstance(zdo.m_uid);
				return DescribeBowl((obj != null) ? obj.GetComponentInChildren<OfferingBowl>(true) : null);
			}, () => DescribeBowl(((Object)(object)prefab == (Object)null) ? null : prefab.GetComponentInChildren<OfferingBowl>(true)), () => LocationBowl(zdo, prefab));
		}

		private static AltarInfo LocationBowl(ZDO zdo, GameObject prefab)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)prefab == (Object)null || (Object)(object)prefab.GetComponent<LocationProxy>() == (Object)null || (Object)(object)ZoneSystem.instance == (Object)null)
			{
				return null;
			}
			ZoneLocation location = ZoneSystem.instance.GetLocation(zdo.GetInt(ZDOVars.s_location, 0));
			if (location == null)
			{
				return null;
			}
			SoftReference<GameObject> prefab2 = location.m_prefab;
			prefab2.Load();
			try
			{
				return DescribeBowl(((Object)(object)prefab2.Asset == (Object)null) ? null : prefab2.Asset.GetComponentInChildren<OfferingBowl>(true));
			}
			finally
			{
				prefab2.Release();
			}
		}

		private static string AltarRoll(ZDOID altar, OfferingBowl bowl, double pressed)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return AltarRoll(altar, DescribeBowl(bowl), pressed);
		}

		private static string AltarRoll(ZDOID altar, AltarInfo bowl, double pressed)
		{
			return BossAltarRules.Roll(((ZDOID)(ref altar)).UserID, ((ZDOID)(ref altar)).ID, pressed, Mathf.RoundToInt(_slots.Value), bowl.Stars, AspectOn);
		}

		private static void AltarPressed(long sender, ZDOID altar, double pressed)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (Server && RotatingAltars && sender != 0L && ZDOMan.instance != null && BossAltarRules.PressTime(pressed, ZNet.instance.GetTimeSeconds()) && AltarBowl(ZDOMan.instance.GetZDO(altar)) != null)
				{
					PruneAltars();
					AltarPresses.Record(altar, sender, pressed);
				}
			}
			catch (Exception e)
			{
				Warn("altarpress", e);
			}
		}

		private static void AltarStarted(long sender, ZDOID altar, long summoner)
		{
			//IL_0024: 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_0062: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: 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_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!Server || !RotatingAltars || ZDOMan.instance == null)
				{
					return;
				}
				PruneAltars();
				ZDO zDO = ZDOMan.instance.GetZDO(altar);
				if (zDO == null || sender == 0L || sender != zDO.GetOwner() || AltarSummons.ContainsKey(altar) || AltarSummons.Count >= 256)
				{
					return;
				}
				double age;
				long relayed = AltarInteractions.Relayed(altar, summoner, Time.realtimeSinceStartupAsDouble, out age);
				if (!BossAltarRules.Summoner(sender, summoner, relayed, age))
				{
					return;
				}
				double timeSeconds = ZNet.instance.GetTimeSeconds();
				if (!AltarPresses.TryRead(altar, summoner, out var at) || !BossAltarRules.PressTime(at, timeSeconds))
				{
					return;
				}
				AltarInfo altarInfo = AltarBowl(zDO);
				if (altarInfo == null)
				{
					return;
				}
				bool flag = false;
				foreach (PlayerInfo player in ZNet.instance.GetPlayerList())
				{
					ZDO zDO2 = ZDOMan.instance.GetZDO(player.m_characterID);
					if (zDO2 != null && zDO2.GetOwner() == summoner && Vector3.Distance(zDO2.GetPosition(), zDO.GetPosition()) <= 30f)
					{
						flag = true;
					}
				}
				if (flag)
				{
					AltarSummons.Add(altar, new AltarSummon
					{
						Owner = sender,
						Prefab = altarInfo.Prefab,
						Selection = AltarRoll(altar, altarInfo, at),
						Until = Time.realtimeSinceStartupAsDouble + (double)Math.Max(0.1f, altarInfo.Delay)
					});
					AltarInteractions.Remove(altar, summoner);
					AltarPresses.Remove(altar, summoner);
				}
			}
			catch (Exception e)
			{
				Warn("altarstart", e);
			}
		}

		private static string RollBoss(ZDO boss)
		{
			//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_0042: 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)
			int slots = (Enabled ? BossAspectRules.Slots(Mathf.RoundToInt(_slots.Value), Stars(boss)) : 0);
			ZDOID zDOID = boss.GetZDOID("meadworks.boss.altar");
			if (!((ZDOID)(ref zDOID)).IsNone() && AltarSummons.TryGetValue(zDOID, out var value) && BossAltarRules.CanBind(boss.GetOwner(), value.Owner, boss.GetPrefab(), value.Prefab, Time.realtimeSinceStartupAsDouble, value.Until))
			{
				AltarSummons.Remove(zDOID);
				if (!RotatingAltars)
				{
					return BossAspectRules.Roll(slots, AspectOn, () => Random.value);
				}
				return value.Selection;
			}
			return BossAspectRules.Roll(slots, AspectOn, () => Random.value);
		}

		private static void InitArena()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			Harmony val = new Harmony("expdare.meadworks.creatures.bossaspectarena");
			val.PatchAll(typeof(ArenaPatches));
			LedgerTrack.Patch(val, "creatures boss arena aspects");
			Ledger.Add("creatures boss arena state", (Action)ClearArena);
		}

		private static bool ArenaActive(Character boss, string aspect)
		{
			if (Valid(boss) && !boss.IsDead() && HasActive(boss, aspect))
			{
				return boss.m_nview.GetZDO().GetBool(ArenaEngagedKey, false);
			}
			return false;
		}

		private static void TickArena(Character boss, string selection)
		{
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			if ((!BossAspectRules.Has(selection, "Wintry") && !BossAspectRules.Has(selection, "Hexing") && !BossAspectRules.Has(selection, "Warcaller") && !BossAspectRules.Has(selection, "EmberTrail")) || boss.IsDead())
			{
				if (ArenaTicks.ContainsKey(boss))
				{
					RemoveArena(boss);
				}
				return;
			}
			if (ArenaTicks.TryGetValue(boss, out var value) && Now < value)
			{
				return;
			}
			ArenaTicks[boss] = Now + 0.5;
			if (Owned(boss))
			{
				Character val = ((Component)boss).GetComponent<MonsterAI>()?.m_targetCreature;
				bool flag = (Object)(object)val != (Object)null && !val.IsDead();
				ZDO zDO = boss.m_nview.GetZDO();
				if (zDO.GetBool(ArenaEngagedKey, false) != flag)
				{
					zDO.Set(ArenaEngagedKey, flag);
				}
				ZDOID val2 = ((flag && Valid(val)) ? val.GetZDOID() : ZDOID.None);
				if (zDO.GetZDOID("meadworks.boss.arena.target") != val2)
				{
					zDO.Set("meadworks.boss.arena.target", val2);
				}
			}
			Player localPlayer = Player.m_localPlayer;
			if (Owned((Character)(object)localPlayer) && !((Character)localPlayer).IsDead() && ArenaActive(boss, "Wintry"))
			{
				Vector3 val3 = ((Component)localPlayer).transform.position - ((Component)boss).transform.position;
				if (BossAspectArenaRules.Wintry(engaged: true, nearFire: false, ((Vector3)(ref val3)).sqrMagnitude))
				{
					_wintrySource = boss;
					goto IL_0188;
				}
			}
			if ((Object)(object)_wintrySource == (Object)(object)boss)
			{
				_wintrySource = null;
			}
			goto IL_0188;
			IL_0188:
			TickHexing(boss);
			TickWarcaller(boss);
			TickEmber(boss);
		}

		private static void RemoveArena(Character boss)
		{
			ArenaTicks.Remove(boss);
			if ((Object)(object)_wintrySource == (Object)(object)boss)
			{
				_wintrySource = null;
			}
			ClearHexing(boss);
			ClearWarcaller(boss);
			ClearEmber(boss);
		}

		private static void ClearArena()
		{
			foreach (Character item in new List<Character>(ArenaTicks.Keys))
			{
				RemoveArena(item);
			}
			_wintrySource = null;
			ReleaseWintry();
			ClearHexing();
			ClearWarcaller();
			ClearEmber();
			_wintryWeather = null;
		}

		private static bool NaturallyWet(Player player)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (!((Character)player).IsSwimming())
			{
				if (EnvMan.IsWet() && !player.m_underRoof)
				{
					return !ShieldGenerator.IsInsideShield(((Component)player).transform.position);
				}
				return false;
			}
			return true;
		}

		private static void ReleaseWintry()
		{
			Player wintryPlayer = _wintryPlayer;
			if (Owned((Character)(object)wintryPlayer))
			{
				SEMan sEMan = ((Character)wintryPlayer).GetSEMan();
				if ((Object)(object)_wintryCold != (Object)null && sEMan.GetStatusEffect(SEMan.s_statusEffectCold) == _wintryCold)
				{
					sEMan.RemoveStatusEffect(_wintryCold, false);
				}
				if ((Object)(object)_wintryWet != (Object)null && sEMan.GetStatusEffect(SEMan.s_statusEffectWet) == _wintryWet && !NaturallyWet(wintryPlayer))
				{
					sEMan.RemoveStatusEffect(_wintryWet, false);
				}
			}
			_wintryPlayer = null;
			_wintryCold = (_wintryWet = null);
		}

		private static bool WintryAffects(Player player)
		{
			//IL_0035: 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)
			if (Owned((Character)(object)player) && !((Character)player).IsDead() && ArenaActive(_wintrySource, "Wintry"))
			{
				bool nearFire = player.m_nearFireTimer < 0.25f;
				Vector3 val = ((Component)player).transform.position - ((Component)_wintrySource).transform.position;
				return BossAspectArenaRules.Wintry(engaged: true, nearFire, ((Vector3)(ref val)).sqrMagnitude);
			}
			return false;
		}

		private static bool WintryColdAllowed(Player player)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_0014: Invalid comparison between Unknown and I4
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Invalid comparison between Unknown and I4
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Invalid comparison between Unknown and I4
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			DamageModifiers damageModifiers = ((Character)player).GetDamageModifiers((WeakSpot)null);
			DamageModifier modifier = ((DamageModifiers)(ref damageModifiers)).GetModifier((DamageType)64);
			if ((int)modifier != 1 && (int)modifier != 5 && (int)modifier != 7 && (int)modifier != 3)
			{
				return !Object.op_Implicit((Object)(object)EffectArea.IsPointInsideArea(((Component)player).transform.position, (Type)64, 1f));
			}
			return false;
		}

		private static void WintryEnvironment(Player player)
		{
			if (!Owned((Character)(object)player))
			{
				return;
			}
			if (!WintryAffects(player))
			{
				ReleaseWintry();
				return;
			}
			if ((Object)(object)_wintryPlayer != (Object)(object)player)
			{
				ReleaseWintry();
				_wintryPlayer = player;
			}
			SEMan sEMan = ((Character)player).GetSEMan();
			if (!sEMan.HaveStatusEffect(SEMan.s_statusEffectWet))
			{
				_wintryWet = sEMan.AddStatusEffect(SEMan.s_statusEffectWet, false, 0, 0f, (short)(-1));
			}
			StatusEffect statusEffect = sEMan.GetStatusEffect(SEMan.s_statusEffectWet);
			if (statusEffect == _wintryWet && statusEffect != null)
			{
				statusEffect.ResetTime();
			}
			if (WintryColdAllowed(player) && !sEMan.HaveStatusEffect(SEMan.s_statusEffectCold))
			{
				_wintryCold = sEMan.AddStatusEffect(SEMan.s_statusEffectCold, false, 0, 0f, (short)(-1));
			}
		}

		private static void InitBonePlated()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			Harmony val = new Harmony("expdare.meadworks.creatures.boneplated");
			val.PatchAll(typeof(BonePlatedPatches));
			LedgerTrack.Patch(val, "creatures bone plated");
		}

		private static void InitCombat()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			Harmony val = new Harmony("expdare.meadworks.creatures.bossaspectcombat");
			val.PatchAll(typeof(CombatPatches));
			LedgerTrack.Patch(val, "creatures boss aspect combat");
		}

		private static void ClearCombat()
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			ClearEarthshaker();
			ClearDeathThroes();
			ClearDevourer();
			ClearStorm();
			ClearGravity();
			ClearEcho();
			StopTetherClock();
			foreach (KeyValuePair<Character, VisualState> visual in Visuals)
			{
				try
				{
					Character key = visual.Key;
					if (!((Object)(object)key == (Object)null))
					{
						((Component)key).transform.localScale = visual.Value.Scale;
						if (Owned(key) && (Object)(object)key.m_zanim != (Object)null && (Object)(object)key.m_animator != (Object)null && BossAspectRules.ShouldSetAnimationSpeed(Of(key), key.m_animator.speed, 1f))
						{
							key.m_zanim.SetSpeed(1f);
						}
						Refit(key, restore: true);
					}
				}
				catch (Exception e)
				{
					Warn("restore", e);
				}
			}
			Visuals.Clear();
		}

		private static bool Valid(Character c)
		{
			if ((Object)(object)c != (Object)null && (Object)(object)c.m_nview != (Object)null)
			{
				return c.m_nview.IsValid();
			}
			return false;
		}

		private static bool Owned(Character c)
		{
			if (CreatureSession.Allowed && Valid(c))
			{
				return c.m_nview.IsOwner();
			}
			return false;
		}

		private static string Of(Character c)
		{
			if (!Valid(c) || !c.IsBoss())
			{
				return "";
			}
			return Selection(c.m_nview.GetZDO());
		}

		private static void Refit(Character c, bool restore = false)
		{
			if (Owned(c) && c.IsBoss() && !c.IsDead() && !IsAspectSpawn(c.m_nview.GetZDO()) && ((ZDOID)(ref _spawningBoss)).IsNone())
			{
				float num = c.GetMaxHealthBase() * (float)c.GetLevel() * (restore ? 1f : (BossAspectRules.Health(Of(c)) * BossStarRules.Health(Stars(c.m_nview.GetZDO()))));
				float maxHealth = c.GetMaxHealth();
				if (!Mathf.Approximately(maxHealth, num))
				{
					float health = EliteRules.RescaleHealth(c.GetHealth(), maxHealth, num);
					c.SetMaxHealth(num);
					c.SetHealth(health);
				}
			}
		}

		private static double Quiet(ZDO zdo)
		{
			long num = zdo.GetLong(ShieldHitKey, 0L);
			if (num != 0L && !((Object)(object)ZNet.instance == (Object)null))
			{
				return (double)(ZNet.instance.GetTime().Ticks - num) / 10000000.0;
			}
			return 0.0;
		}

		private static float RefreshShield(Character c, string selection)
		{
			ZDO zDO = c.m_nview.GetZDO();
			float num = zDO.GetFloat(ShieldKey, -1f);
			float num2 = BossAspectRules.Shield(BossAspectRules.ShieldCapacity(selection, c.GetMaxHealth()), num, Quiet(zDO));
			if (num2 != num)
			{
				zDO.Set(ShieldKey, num2);
			}
			return num2;
		}

		private static void Tick(Character c)
		{
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (!Valid(c) || !c.IsBoss())
			{
				return;
			}
			if (Server)
			{
				Ensure(c.m_nview.GetZDO());
			}
			string text = Of(c);
			TickSummoner(c, text);
			TickTwin(c, text);
			TickStorm(c, text);
			TickGravity(c, text);
			TickEcho(c, text);
			TickEarthshaker(c, text);