Decompiled source of AcolyteRebalance v2.3.2

AcolyteRebalanceUnifiedCombat.dll

Decompiled 4 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
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.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using AcolyteRebalance;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates;
using EntityStates.Acolyte;
using EntityStates.Acolyte.Backpack;
using EntityStates.Acolyte.Weapon;
using EntityStates.LilReaper;
using EntityStates.LilReaper.Weapon;
using HarmonyLib;
using KinematicCharacterController;
using Microsoft.CodeAnalysis;
using RoR2;
using RoR2.AsyncManagement;
using RoR2.ContentManagement;
using RoR2.Items;
using RoR2.Networking;
using RoR2.Orbs;
using RoR2.Projectile;
using RoR2.Skills;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Networking;
using UnityEngine.Playables;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("AcolyteRebalanceUnifiedCombat")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("2.2.0")]
[assembly: AssemblyInformationalVersion("2.2.0")]
[assembly: AssemblyProduct("AcolyteRebalanceUnifiedCombat")]
[assembly: AssemblyTitle("AcolyteRebalanceUnifiedCombat")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.2.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace AcolyteRebalance
{
	internal sealed class Plugin : IDisposable
	{
		internal const float SacrificeCooldown = 7f;

		internal static Plugin Instance { get; private set; }

		internal static ManualLogSource Log { get; private set; }

		internal bool Validated { get; private set; }

		internal void Initialize(ManualLogSource logger, Harmony harmony)
		{
			Instance = this;
			Log = logger;
			CharacterBody.onBodyStartGlobal += OnBodyStart;
			RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(PatchLoadedSkills));
			try
			{
				harmony.PatchAll(typeof(Plugin).Assembly);
				Validated = SacrificeAgilePatch.Ready && SacrificeOrbDamagePatch.Ready && AcolytePassiveArmorPatch.Ready && HarvesterPrimaryPatch.Ready && HarvesterStormPatch.Ready && HarvesterEmpoweredStormPatch.Ready && BrandMoveSpeedPatch.Ready && GraceHealPatch.Ready;
				if (Validated)
				{
					Log.LogInfo((object)"Acolyte Rebalance patches applied.");
				}
				else
				{
					Log.LogError((object)"Acolyte Rebalance: one or more verified patch patterns were not found. Check the preceding errors; do not treat this installation as validated.");
				}
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Could not install Acolyte Rebalance patches: " + ex));
			}
		}

		public void Dispose()
		{
			CharacterBody.onBodyStartGlobal -= OnBodyStart;
			RoR2Application.onLoad = (Action)Delegate.Remove(RoR2Application.onLoad, new Action(PatchLoadedSkills));
		}

		internal static bool IsOriginalAcolyte(CharacterBody body)
		{
			if (IsAcolyteBody(body))
			{
				return body.baseNameToken == "ACOLYTE_BODY_NAME";
			}
			return false;
		}

		internal static bool IsAcolyteBody(CharacterBody body)
		{
			if ((Object)(object)body != (Object)null)
			{
				if (!(((Object)body).name == "AcolyteBody"))
				{
					return ((Object)body).name == "AcolyteBody(Clone)";
				}
				return true;
			}
			return false;
		}

		private void OnBodyStart(CharacterBody body)
		{
			if (IsOriginalAcolyte(body))
			{
				body.baseArmor = Settings.AcolyteArmor;
				body.RecalculateStats();
				PatchLoadedSkills();
			}
		}

		private void PatchLoadedSkills()
		{
			SkillDef[] array = Resources.FindObjectsOfTypeAll<SkillDef>();
			for (int i = 0; i < array.Length; i++)
			{
				PatchSkill(array[i]);
			}
		}

		internal static void RemoveKeyword(SkillDef def, string token)
		{
			string[] array = def.keywordTokens ?? Array.Empty<string>();
			if (Array.IndexOf(array, token) >= 0)
			{
				def.keywordTokens = Array.FindAll(array, (string k) => k != token);
			}
		}

		internal static void AddKeyword(SkillDef def, string token)
		{
			string[] array = def.keywordTokens ?? Array.Empty<string>();
			if (Array.IndexOf(array, token) < 0)
			{
				string[] array2 = new string[array.Length + 1];
				Array.Copy(array, array2, array.Length);
				array2[array.Length] = token;
				def.keywordTokens = array2;
			}
		}

		internal static void UtilityCards(SkillDef def)
		{
			if (!string.IsNullOrEmpty(def.skillDescriptionToken))
			{
				SkillTextPatch.UtilityDescriptionTokens.Add(def.skillDescriptionToken);
			}
			if (Settings.Classic202)
			{
				RemoveKeyword(def, "ACOLYTE_REBALANCE_KEYWORD_LUNGE");
				RemoveKeyword(def, "ACOLYTE_REBALANCE_KEYWORD_VORTEX");
			}
			else
			{
				AddKeyword(def, "ACOLYTE_REBALANCE_KEYWORD_LUNGE");
				AddKeyword(def, "ACOLYTE_REBALANCE_KEYWORD_VORTEX");
			}
		}

		internal static void PassiveCards(SkillDef def)
		{
			if (Settings.Classic202)
			{
				RemoveKeyword(def, "ACOLYTE_REBALANCE_KEYWORD_NOGRACE");
				AddKeyword(def, "ACOLYTE_REBALANCE_KEYWORD_NKUHANA");
			}
			else
			{
				RemoveKeyword(def, "ACOLYTE_REBALANCE_KEYWORD_NKUHANA");
				AddKeyword(def, "ACOLYTE_REBALANCE_KEYWORD_NOGRACE");
			}
		}

		internal static void PatchSkill(SkillDef def)
		{
			if ((Object)(object)def == (Object)null)
			{
				return;
			}
			Type stateType = ((SerializableEntityStateType)(ref def.activationState)).stateType;
			float num;
			switch (def.skillNameToken)
			{
			default:
				return;
			case "ACOLYTE_PRIMARY_NAME":
				if (stateType != typeof(BladeCombo))
				{
					return;
				}
				num = Settings.BladeSliceRecharge;
				break;
			case "ACOLYTE_UTILITY_NAME":
				if (stateType != typeof(BladeSling))
				{
					return;
				}
				num = Settings.BladeSlingCooldown;
				UtilityCards(def);
				break;
			case "ACOLYTE_UTILITY_ALT_NAME":
				if (stateType != typeof(ThrowJavelin))
				{
					return;
				}
				num = Settings.JavelinCooldown;
				UtilityCards(def);
				break;
			case "ACOLYTE_PASSIVE_NAME":
				PassiveCards(def);
				AddKeyword(def, "ACOLYTE_REBALANCE_KEYWORD_REAP_FAVOR");
				return;
			case "ACOLYTE_ALTPASSIVE_NAME":
				PassiveCards(def);
				AddKeyword(def, "ACOLYTE_REBALANCE_KEYWORD_REAP_GRACE");
				return;
			case "ACOLYTE_SPECIAL_NAME":
				if (stateType != typeof(AimSacrifice))
				{
					return;
				}
				def.cancelSprintingOnActivation = false;
				def.canceledFromSprinting = false;
				if (def.baseMaxStock != Settings.SacrificeCharges)
				{
					def.baseMaxStock = Settings.SacrificeCharges;
					if (Settings.Verbose)
					{
						Log.LogInfo((object)("Set " + def.skillName + " max stock to " + def.baseMaxStock + "."));
					}
				}
				def.attackSpeedBuffsRestockSpeed = false;
				RemoveKeyword(def, "KEYWORD_RAPID");
				RemoveKeyword(def, "KEYWORD_AGILE");
				AddKeyword(def, "ACOLYTE_REBALANCE_KEYWORD_CLAW");
				AddKeyword(def, "ACOLYTE_REBALANCE_KEYWORD_DASH");
				num = Settings.SacrificeCooldown;
				break;
			}
			if (Math.Abs(def.baseRechargeInterval - num) > 0.001f)
			{
				def.baseRechargeInterval = num;
				if (Settings.Verbose)
				{
					Log.LogInfo((object)("Set " + def.skillName + " base cooldown to " + num + " seconds."));
				}
			}
		}
	}
	[HarmonyPatch(typeof(GenericSkill), "AssignSkill")]
	internal static class AcolyteSkillAssignmentPatch
	{
		private static void Prefix(SkillDef newSkillDef)
		{
			Plugin.PatchSkill(newSkillDef);
		}

		private static void Postfix(GenericSkill __instance, SkillDef newSkillDef)
		{
			if (!((Object)(object)newSkillDef == (Object)null) && !(newSkillDef.skillNameToken != "ACOLYTE_PRIMARY_NAME") && !(((SerializableEntityStateType)(ref newSkillDef.activationState)).stateType != typeof(BladeCombo)) && Settings.Verbose)
			{
				Plugin.Log.LogInfo((object)("Blade Combo runtime assignment: " + newSkillDef.skillName + "; base=" + newSkillDef.baseRechargeInterval + "s; effective interval=" + __instance.GetFinalRechargeInterval() + "s; recharge rate=" + __instance.rechargeRate + ". Attack speed and cooldown modifiers remain active."));
			}
		}
	}
	[HarmonyPatch(typeof(AcolyteBodySwapController), "CacheFields")]
	internal static class AcolyteArmorCachePatch
	{
		private static void Prefix(AcolyteBodySwapController __instance)
		{
			CharacterBody component = ((Component)__instance).GetComponent<CharacterBody>();
			if (Plugin.IsOriginalAcolyte(component))
			{
				component.baseArmor = Settings.AcolyteArmor;
			}
		}
	}
	[HarmonyPatch(typeof(CharacterBody), "RecalculateStats")]
	internal static class AcolytePassiveArmorPatch
	{
		internal static bool Ready { get; private set; }

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Expected O, but got Unknown
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Invalid comparison between Unknown and I4
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a6: Expected O, but got Unknown
			List<CodeInstruction> list = PatchInstructions.Clone(instructions);
			FieldInfo objB = AccessTools.Field(typeof(Items), "ConvertHealingToAttackSpeed");
			MethodInfo methodInfo = AccessTools.Method(typeof(Inventory), "GetItemCountEffective", new Type[1] { typeof(ItemDef) }, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.PropertyGetter(typeof(CharacterBody), "armor");
			MethodInfo methodInfo3 = AccessTools.PropertySetter(typeof(CharacterBody), "armor");
			List<int> list2 = new List<int>();
			for (int i = 0; i + 2 < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Ldsfld && object.Equals(list[i].operand, objB) && CodeInstructionExtensions.Calls(list[i + 1], methodInfo) && LocalIndex(list[i + 2], load: false) >= 0)
				{
					list2.Add(LocalIndex(list[i + 2], load: false));
				}
			}
			List<int> list3 = new List<int>();
			if (list2.Count == 1)
			{
				for (int j = 0; j + 8 < list.Count; j++)
				{
					if (CodeInstructionExtensions.Calls(list[j], methodInfo2) && LocalIndex(list[j + 1], load: true) == list2[0] && list[j + 2].opcode == OpCodes.Ldc_I4_0 && (list[j + 3].opcode == OpCodes.Bgt || list[j + 3].opcode == OpCodes.Bgt_S) && IsFloat(list[j + 4], 0f) && (list[j + 5].opcode == OpCodes.Br || list[j + 5].opcode == OpCodes.Br_S) && IsFloat(list[j + 6], 20f) && list[j + 7].opcode == OpCodes.Add && CodeInstructionExtensions.Calls(list[j + 8], methodInfo3) && list[j + 3].operand is Label item && list[j + 6].labels.Contains(item) && list[j + 5].operand is Label item2 && list[j + 7].labels.Contains(item2))
					{
						list3.Add(j + 6);
					}
				}
			}
			Ready = false;
			if (list3.Count != 1)
			{
				Plugin.Log.LogError((object)"Armour correction disabled: expected one verified Favor armour contribution. Original stat calculation retained.");
				return list;
			}
			int num = list3[0];
			CodeInstruction val = new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(AcolytePassiveArmorPatch), "AdjustBonus", (Type[])null, (Type[])null));
			for (int num2 = list[num].blocks.Count - 1; num2 >= 0; num2--)
			{
				if ((int)list[num].blocks[num2].blockType == 5)
				{
					val.blocks.Insert(0, list[num].blocks[num2]);
					list[num].blocks.RemoveAt(num2);
				}
			}
			list.Insert(num + 1, new CodeInstruction(OpCodes.Ldarg_0, (object)null));
			list.Insert(num + 2, val);
			Ready = true;
			return list;
		}

		internal static float AdjustBonus(float original, CharacterBody body)
		{
			if (!Plugin.IsAcolyteBody(body))
			{
				return original;
			}
			AcolyteBodySwapController component = ((Component)body).GetComponent<AcolyteBodySwapController>();
			bool originalAcolyteForm = (((Object)(object)component != (Object)null) ? (!component.isReaperForm) : Plugin.IsOriginalAcolyte(body));
			return GameplayRules.PassiveArmorContribution(original, originalAcolyteForm);
		}

		private static bool IsFloat(CodeInstruction instruction, float value)
		{
			if (instruction.opcode == OpCodes.Ldc_R4)
			{
				return object.Equals(instruction.operand, value);
			}
			return false;
		}

		internal static int LocalIndex(CodeInstruction instruction, bool load)
		{
			OpCode opcode = instruction.opcode;
			if (load)
			{
				if (opcode == OpCodes.Ldloc_0)
				{
					return 0;
				}
				if (opcode == OpCodes.Ldloc_1)
				{
					return 1;
				}
				if (opcode == OpCodes.Ldloc_2)
				{
					return 2;
				}
				if (opcode == OpCodes.Ldloc_3)
				{
					return 3;
				}
				if (opcode != OpCodes.Ldloc && opcode != OpCodes.Ldloc_S)
				{
					return -1;
				}
			}
			else
			{
				if (opcode == OpCodes.Stloc_0)
				{
					return 0;
				}
				if (opcode == OpCodes.Stloc_1)
				{
					return 1;
				}
				if (opcode == OpCodes.Stloc_2)
				{
					return 2;
				}
				if (opcode == OpCodes.Stloc_3)
				{
					return 3;
				}
				if (opcode != OpCodes.Stloc && opcode != OpCodes.Stloc_S)
				{
					return -1;
				}
			}
			if (instruction.operand is LocalBuilder localBuilder)
			{
				return localBuilder.LocalIndex;
			}
			if (instruction.operand is LocalVariableInfo localVariableInfo)
			{
				return localVariableInfo.LocalIndex;
			}
			if (instruction.operand is byte || instruction.operand is ushort || instruction.operand is int)
			{
				return Convert.ToInt32(instruction.operand);
			}
			return -1;
		}
	}
	[HarmonyPatch(typeof(CharacterBody), "RecalculateStats")]
	internal static class BrandMoveSpeedPatch
	{
		internal const float Anchor = 0.84000003f;

		internal static BuffDef PinkBuff;

		internal static BuffDef RedBuff;

		internal static bool Ready { get; private set; }

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Expected O, but got Unknown
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Expected O, but got Unknown
			List<CodeInstruction> list = PatchInstructions.Clone(instructions);
			List<int> list2 = new List<int>();
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Ldc_R4 && object.Equals(list[i].operand, 0.84000003f))
				{
					list2.Add(i);
				}
			}
			int num = -1;
			if (list2.Count == 1)
			{
				for (int j = list2[0] + 1; j < list.Count && j <= list2[0] + 8; j++)
				{
					if (list[j].opcode == OpCodes.Add)
					{
						num = j;
						break;
					}
				}
			}
			Ready = false;
			if (num < 0 || AcolytePassiveArmorPatch.LocalIndex(list[num + 1], load: false) < 0)
			{
				Plugin.Log.LogError((object)"Brand movement speed disabled: expected one verified movement-speed term. Original stat calculation retained.");
				return list;
			}
			list.Insert(num + 1, new CodeInstruction(OpCodes.Ldarg_0, (object)null));
			list.Insert(num + 2, new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(BrandMoveSpeedPatch), "Bonus", (Type[])null, (Type[])null)));
			list.Insert(num + 3, new CodeInstruction(OpCodes.Add, (object)null));
			Ready = true;
			return list;
		}

		internal static float Bonus(CharacterBody body)
		{
			if ((Object)(object)body == (Object)null)
			{
				return 0f;
			}
			if ((Object)(object)RedBuff != (Object)null && body.HasBuff(RedBuff))
			{
				return Settings.RedBrandMoveSpeed;
			}
			if ((Object)(object)PinkBuff != (Object)null && body.HasBuff(PinkBuff))
			{
				return Settings.PinkBrandMoveSpeed;
			}
			return 0f;
		}
	}
	internal sealed class DirectDamageReceipt
	{
		private readonly object damageIdentity;

		private readonly object victimIdentity;

		private float calculatedDamage;

		private bool reported;

		private bool reportAccepted;

		private bool consumed;

		private readonly double healingFraction;

		internal bool Accepted => reportAccepted;

		internal DirectDamageReceipt(object damageIdentity, object victimIdentity, double healingFraction = 0.1)
		{
			this.damageIdentity = damageIdentity;
			this.victimIdentity = victimIdentity;
			this.healingFraction = healingFraction;
		}

		internal void ObserveReport(object damage, object victim, bool rejected, float reportedDamage)
		{
			if (damageIdentity == damage && victimIdentity == victim && !reported)
			{
				reported = true;
				reportAccepted = !rejected && Finite(reportedDamage) && reportedDamage > 0f;
				if (reportAccepted)
				{
					calculatedDamage = reportedDamage;
				}
			}
		}

		internal bool TryConsumeHealing(out float amount)
		{
			amount = 0f;
			if (consumed)
			{
				return false;
			}
			consumed = true;
			if (!reportAccepted)
			{
				return false;
			}
			amount = (float)((double)calculatedDamage * healingFraction);
			if (Finite(amount))
			{
				return amount > 0f;
			}
			return false;
		}

		private static bool Finite(float value)
		{
			if (!float.IsNaN(value))
			{
				return !float.IsInfinity(value);
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(BackpackActivate), "OnEnter")]
	internal static class EchoCooldownResetPatch
	{
		private static void Postfix(BackpackActivate __instance)
		{
			CharacterBody val = (Object.op_Implicit((Object)(object)((EntityState)__instance).outer) ? ((EntityState)__instance).outer.commonComponents.characterBody : null);
			if (!Plugin.IsAcolyteBody(val) || !Util.HasEffectiveAuthority(((Component)val).gameObject) || !Object.op_Implicit((Object)(object)val.skillLocator))
			{
				return;
			}
			val.skillLocator.ResetSkills();
			GenericSkill special = val.skillLocator.special;
			if (Object.op_Implicit((Object)(object)special) && Object.op_Implicit((Object)(object)special.baseSkill) && special.baseSkill.skillNameToken == "ACOLYTE_SPECIAL_NAME")
			{
				special.baseStock = special.GetBaseMaxStock();
			}
			if (Settings.Verbose)
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogInfo((object)("ECHO_ENTER all skill cooldowns reset; Sacrifice baseStock=" + (Object.op_Implicit((Object)(object)special) ? (special.baseStock + "/" + special.GetBaseMaxStock()) : "none") + " activeSkill=" + ((Object.op_Implicit((Object)(object)special) && Object.op_Implicit((Object)(object)special.skillDef)) ? special.skillDef.skillName : "none")));
				}
			}
		}
	}
	internal static class GameplayRules
	{
		internal static float PassiveArmorContribution(float original, bool originalAcolyteForm)
		{
			if (!originalAcolyteForm)
			{
				return original;
			}
			return 0f;
		}

		internal static bool ProtectUtilityTravel(bool server, bool alive, bool utilityDash, bool hasDestination, bool pendingExit, bool atDestination)
		{
			if (server && alive && utilityDash && hasDestination && !pendingExit)
			{
				return !atDestination;
			}
			return false;
		}
	}
	internal static class GraceAttackSpeed
	{
		internal const float Fraction = 0.5f;

		private static readonly Dictionary<CharacterBody, float> carry = new Dictionary<CharacterBody, float>();

		private static readonly Dictionary<CharacterBody, int> baseStacks = new Dictionary<CharacterBody, int>();

		private static FieldInfo timedBuffsField;

		private static BuffDef Buff => Buffs.AcoStealBackHealthBuff;

		internal static bool IsGrace(CharacterBody body)
		{
			if ((Object)(object)body != (Object)null && (Object)(object)body.inventory != (Object)null)
			{
				return body.inventory.GetItemCountEffective(Items.StealBackHealth) > 0;
			}
			return false;
		}

		internal static int FavorEquivalentCount(float heal, CharacterBody body)
		{
			if (heal <= Mathf.Epsilon || (Object)(object)body == (Object)null)
			{
				return 0;
			}
			float num = body.baseMaxHealth + body.levelMaxHealth * (body.level - 1f);
			if (num <= 0f)
			{
				return 0;
			}
			float num2 = heal / num * 100f * ConvertHealingToAttackSpeedBehavior.healPercentToAttackSpeedConversion;
			float num3 = (float)body.GetBuffCount(Buff) / 0.5f + num2 / 2f - 50f;
			float num4 = 1f + Mathf.Max(0f, num3 * 0.01f * 5f);
			float num5 = num2 / num4;
			if (num5 <= 1f && num2 > 1f)
			{
				num5 = 1f;
			}
			return Mathf.FloorToInt(num5);
		}

		internal static float Grant(HealthComponent health, float amount, bool nonRegen)
		{
			float result = health.GrantRegainableHealthServer(amount);
			try
			{
				CharacterBody val = (Object.op_Implicit((Object)(object)health) ? health.body : null);
				if (!nonRegen || !Plugin.IsAcolyteBody(val) || !IsGrace(val) || (Object)(object)Buff == (Object)null)
				{
					return result;
				}
				int num = FavorEquivalentCount(amount, val) + 1;
				carry.TryGetValue(val, out var value);
				value += (float)num * 0.5f;
				int num2 = Mathf.FloorToInt(value);
				carry[val] = value - (float)num2;
				for (int num3 = num2 - 1; num3 >= 0; num3--)
				{
					float num4 = Util.Remap((float)num3 / 0.5f, 0f, 100f, ConvertHealingToAttackSpeedBehavior.minBuffDuration, ConvertHealingToAttackSpeedBehavior.maxBuffDuration);
					val.AddTimedBuff(Buff, num4);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Grace attack speed skipped: " + ex.Message));
			}
			return result;
		}

		internal static void ServerTick()
		{
			if (!NetworkServer.active || (Object)(object)Buff == (Object)null)
			{
				baseStacks.Clear();
				carry.Clear();
				return;
			}
			ReadOnlyCollection<CharacterBody> readOnlyInstancesList = CharacterBody.readOnlyInstancesList;
			for (int i = 0; i < readOnlyInstancesList.Count; i++)
			{
				CharacterBody val = readOnlyInstancesList[i];
				if (Object.op_Implicit((Object)(object)val) && Plugin.IsAcolyteBody(val))
				{
					baseStacks.TryGetValue(val, out var j);
					int num;
					for (num = (IsGrace(val) ? Mathf.FloorToInt((float)FavorEquivalentCount(val.regen * 2.5f, val) * 0.5f) : 0); j < num; j++)
					{
						val.AddBuff(Buff);
					}
					while (j > num && val.GetBuffCount(Buff) > 0)
					{
						val.RemoveBuff(Buff);
						j--;
					}
					if (num == 0)
					{
						baseStacks.Remove(val);
					}
					else
					{
						baseStacks[val] = j;
					}
				}
			}
			Prune(baseStacks);
			Prune(carry);
		}

		private static void Prune<T>(Dictionary<CharacterBody, T> d)
		{
			if (d.Count == 0)
			{
				return;
			}
			List<CharacterBody> list = null;
			foreach (CharacterBody key in d.Keys)
			{
				if (!Object.op_Implicit((Object)(object)key))
				{
					(list ?? (list = new List<CharacterBody>())).Add(key);
				}
			}
			if (list == null)
			{
				return;
			}
			foreach (CharacterBody item in list)
			{
				d.Remove(item);
			}
		}

		internal static void Freeze(CharacterBody body, float deltaTime)
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			if (!Settings.Classic202 || !Plugin.IsAcolyteBody(body) || !IsGrace(body) || (Object)(object)Buff == (Object)null || deltaTime <= 0f || !Object.op_Implicit((Object)(object)body.healthComponent) || body.healthComponent.regainableHealth <= 0f)
			{
				return;
			}
			if (timedBuffsField == null)
			{
				timedBuffsField = AccessTools.Field(typeof(CharacterBody), "timedBuffs");
			}
			if (!(timedBuffsField?.GetValue(body) is List<TimedBuff> list))
			{
				return;
			}
			BuffIndex buffIndex = Buff.buffIndex;
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i] != null && list[i].buffIndex == buffIndex)
				{
					TimedBuff obj = list[i];
					obj.timer += deltaTime;
				}
			}
		}
	}
	[HarmonyPatch(typeof(HealthComponent), "Heal")]
	internal static class GraceHealPatch
	{
		internal static bool Ready { get; private set; }

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			List<CodeInstruction> list = PatchInstructions.Clone(instructions);
			MethodInfo methodInfo = AccessTools.Method(typeof(HealthComponent), "GrantRegainableHealthServer", (Type[])null, (Type[])null);
			List<int> list2 = new List<int>();
			for (int i = 0; i < list.Count; i++)
			{
				if (CodeInstructionExtensions.Calls(list[i], methodInfo))
				{
					list2.Add(i);
				}
			}
			Ready = false;
			if (methodInfo == null || list2.Count != 1)
			{
				Plugin.Log.LogError((object)"Grace attack speed disabled: expected one recoverable-health grant in Heal. Native Grace kept.");
				return list;
			}
			int num = list2[0];
			list.Insert(num, new CodeInstruction(OpCodes.Ldarg_3, (object)null));
			list[num + 1].opcode = OpCodes.Call;
			list[num + 1].operand = AccessTools.Method(typeof(GraceAttackSpeed), "Grant", (Type[])null, (Type[])null);
			Ready = true;
			return list;
		}
	}
	[HarmonyPatch(typeof(StealBackHealthBehaviour), "FixedUpdate")]
	internal static class GracePoolSpeedPatch
	{
		private static bool Prefix()
		{
			return false;
		}
	}
	[HarmonyPatch(typeof(CharacterBody), "UpdateBuffs")]
	internal static class GraceFreezePatch
	{
		private static void Prefix(CharacterBody __instance, float deltaTime)
		{
			try
			{
				GraceAttackSpeed.Freeze(__instance, deltaTime);
			}
			catch
			{
			}
		}
	}
	internal static class HarvesterBalance
	{
		internal const float BaseArmor = 60f;

		internal const float RecoveryCoefficient = 0.075f;

		internal const float PrimaryCoefficient = 2.5f;

		internal const float StormCoefficient = 2f;

		internal const float EmpoweredStormCoefficient = 5f;

		internal const float FullSoulDuration = 12f;

		internal static bool IsHarvester(CharacterBody body)
		{
			if (!Plugin.IsAcolyteBody(body))
			{
				return false;
			}
			AcolyteBodySwapController component = ((Component)body).GetComponent<AcolyteBodySwapController>();
			if ((Object)(object)component != (Object)null)
			{
				return component.isReaperForm;
			}
			return false;
		}

		internal static CharacterBody Body(EntityState state)
		{
			if (!((Object)(object)state.outer != (Object)null))
			{
				return null;
			}
			return ((Component)state.outer).GetComponent<CharacterBody>();
		}

		internal static float Primary(float original, SlashStorm state)
		{
			if (!IsHarvester(Body((EntityState)(object)state)))
			{
				return original;
			}
			return Settings.TorrentialCoefficient;
		}

		internal static float Storm(float original, SoulStorm state)
		{
			if (!IsHarvester(Body((EntityState)(object)state)))
			{
				return original;
			}
			return Settings.StormCoefficient;
		}

		internal static float EmpoweredStorm(float original, ReactivateSoulStorm state)
		{
			if (!IsHarvester(Body((EntityState)(object)state)))
			{
				return original;
			}
			return Settings.ReactivatedStormCoefficient;
		}

		internal static DamageTypeExtended WithoutPrimaryExecute(DamageTypeExtended original)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			return (DamageTypeExtended)(original & -3);
		}

		internal static IEnumerable<CodeInstruction> ReplaceCoefficient(IEnumerable<CodeInstruction> instructions, FieldInfo field, MethodInfo helper, out bool ready)
		{
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Invalid comparison between Unknown and I4
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Expected O, but got Unknown
			List<CodeInstruction> list = PatchInstructions.Clone(instructions);
			List<int> list2 = new List<int>();
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Ldsfld && object.Equals(list[i].operand, field))
				{
					list2.Add(i);
				}
			}
			ready = field != null && helper != null && list2.Count == 1;
			if (!ready)
			{
				Plugin.Log.LogError((object)("Harvester balance disabled for " + field?.ToString() + ": expected one coefficient load; original instructions retained."));
				return list;
			}
			int num = list2[0];
			CodeInstruction val = new CodeInstruction(OpCodes.Call, (object)helper);
			for (int num2 = list[num].blocks.Count - 1; num2 >= 0; num2--)
			{
				if ((int)list[num].blocks[num2].blockType == 5)
				{
					val.blocks.Insert(0, list[num].blocks[num2]);
					list[num].blocks.RemoveAt(num2);
				}
			}
			list.Insert(num + 1, new CodeInstruction(OpCodes.Ldarg_0, (object)null));
			list.Insert(num + 2, val);
			return list;
		}
	}
	[HarmonyPatch(typeof(AcolyteBodySwapController), "SwapBodyInternal")]
	internal static class HarvesterSwapBalancePatch
	{
		private static void Prefix(AcolyteBodySwapController __instance, ref float ___baseArmor)
		{
			if (Plugin.IsAcolyteBody(((Component)__instance).GetComponent<CharacterBody>()))
			{
				___baseArmor = Settings.HarvesterArmor;
				AcolyteFormController component = ((Component)__instance).GetComponent<AcolyteFormController>();
				if ((Object)(object)component != (Object)null)
				{
					component.regainPercentOfDealtDamageReaper = Settings.HarvesterRecovery;
				}
			}
		}
	}
	[HarmonyPatch(typeof(BaseBackpackState), "OnEnter")]
	internal static class HarvesterDurationPatch
	{
		private static void Prefix(BaseBackpackState __instance)
		{
			if (((object)__instance).GetType() == typeof(ReaperActivate) && Plugin.IsAcolyteBody(HarvesterBalance.Body((EntityState)(object)__instance)))
			{
				__instance.duration = Settings.LitanyDuration;
			}
		}
	}
	[HarmonyPatch(typeof(SlashStorm), "Fire")]
	internal static class HarvesterPrimaryPatch
	{
		internal static bool Ready { get; private set; }

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			bool ready;
			IEnumerable<CodeInstruction> result = HarvesterBalance.ReplaceCoefficient(instructions, AccessTools.Field(typeof(SlashStorm), "damageCoefficient"), AccessTools.Method(typeof(HarvesterBalance), "Primary", (Type[])null, (Type[])null), out ready);
			Ready = ready;
			return result;
		}
	}
	[HarmonyPatch(typeof(SoulStorm), "Fire")]
	internal static class HarvesterStormPatch
	{
		internal static bool Ready { get; private set; }

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			bool ready;
			IEnumerable<CodeInstruction> result = HarvesterBalance.ReplaceCoefficient(instructions, AccessTools.Field(typeof(SoulStorm), "projectileDamageCoefficient"), AccessTools.Method(typeof(HarvesterBalance), "Storm", (Type[])null, (Type[])null), out ready);
			Ready = ready;
			return result;
		}
	}
	[HarmonyPatch(typeof(ReactivateSoulStorm), "Fire")]
	internal static class HarvesterEmpoweredStormPatch
	{
		internal static bool Ready { get; private set; }

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			bool ready;
			IEnumerable<CodeInstruction> result = HarvesterBalance.ReplaceCoefficient(instructions, AccessTools.Field(typeof(ReactivateSoulStorm), "projectileDamageCoefficient"), AccessTools.Method(typeof(HarvesterBalance), "EmpoweredStorm", (Type[])null, (Type[])null), out ready);
			Ready = ready;
			return result;
		}
	}
	[HarmonyPatch(typeof(ProjectileController), "DispatchOnInitialized")]
	internal static class HarvesterPrimaryExecutePatch
	{
		private static void Prefix(ProjectileController __instance)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Invalid comparison between Unknown and I4
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = EntityStateGameObject.op_Implicit(SlashStorm.projectilePrefab);
			if ((Object)(object)val == (Object)null || (Object)(object)__instance.owner == (Object)null)
			{
				return;
			}
			int projectileIndex = ProjectileCatalog.GetProjectileIndex(val);
			if (projectileIndex >= 0 && __instance.catalogIndex == projectileIndex && Plugin.IsAcolyteBody(__instance.owner.GetComponent<CharacterBody>()))
			{
				ProjectileDamage component = ((Component)__instance).GetComponent<ProjectileDamage>();
				if (!((Object)(object)component == (Object)null) && (int)component.damageType.damageSource == 1)
				{
					DamageTypeCombo damageType = component.damageType;
					damageType.damageTypeExtended = HarvesterBalance.WithoutPrimaryExecute(damageType.damageTypeExtended);
					component.damageType = damageType;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Return), "OnEnter")]
	internal static class HarvesterExitRefundPatch
	{
		internal const int RedCharges = 2;

		internal const int PinkCharges = 1;

		internal static int Charges(CharacterBody body)
		{
			if ((Object)(object)body == (Object)null)
			{
				return 0;
			}
			if ((Object)(object)BrandMoveSpeedPatch.RedBuff != (Object)null && body.HasBuff(BrandMoveSpeedPatch.RedBuff))
			{
				return 2;
			}
			if ((Object)(object)BrandMoveSpeedPatch.PinkBuff != (Object)null && body.HasBuff(BrandMoveSpeedPatch.PinkBuff))
			{
				return 1;
			}
			return 0;
		}

		private static void Postfix(Return __instance)
		{
			try
			{
				CharacterBody val = (Object.op_Implicit((Object)(object)((EntityState)__instance).outer) ? ((Component)((EntityState)__instance).outer).GetComponent<CharacterBody>() : null);
				if (!Plugin.IsAcolyteBody(val) || !val.hasEffectiveAuthority || !Object.op_Implicit((Object)(object)val.skillLocator))
				{
					return;
				}
				GenericSkill special = val.skillLocator.special;
				if (!Object.op_Implicit((Object)(object)special))
				{
					return;
				}
				int num = Charges(val);
				int stock = special.stock;
				for (int i = 0; i < num; i++)
				{
					if ((Object)(object)special.skillDef == (Object)(object)special.baseSkill)
					{
						if (special.stock < special.maxStock)
						{
							special.AddOneStock();
						}
					}
					else
					{
						special.baseStock = Math.Min(special.baseStock + 1, special.GetBaseMaxStock());
					}
				}
				if (Settings.Verbose)
				{
					Plugin.Log.LogInfo((object)("HARVESTER_EXIT_REFUND charges=" + num + " stock " + stock + " -> " + special.stock + " baseStock=" + special.baseStock + " skill=" + (Object.op_Implicit((Object)(object)special.skillDef) ? special.skillDef.skillName : "?")));
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Harvester exit refund skipped: " + ex.Message));
			}
		}
	}
	internal static class SacrificeLifesteal
	{
		internal static Action<CharacterBody, CharacterBody, DamageInfo> NoGraceHook;

		private static readonly ConditionalWeakTable<DamageInfo, DirectDamageReceipt> pending = new ConditionalWeakTable<DamageInfo, DirectDamageReceipt>();

		internal static void ApplyOrbDamage(HealthComponent victim, DamageInfo info, GenericDamageOrb orb)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Invalid comparison between Unknown and I4
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Invalid comparison between Unknown and I4
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active || ((object)orb).GetType() != typeof(SacrificeOrb) || (int)info.dotIndex != -1 || info.delayedDamageSecondHalf || !((ProcChainMask)(ref info.procChainMask)).HasProc((ProcType)30) || (int)info.damageType.damageSource != 8 || pending.TryGetValue(info, out var _))
			{
				victim.TakeDamage(info);
				return;
			}
			CharacterBody val = (((Object)(object)info.attacker != (Object)null) ? info.attacker.GetComponent<CharacterBody>() : null);
			if (!Plugin.IsAcolyteBody(val))
			{
				victim.TakeDamage(info);
				return;
			}
			try
			{
				NoGraceHook?.Invoke(val, Object.op_Implicit((Object)(object)victim) ? victim.body : null, info);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("No Grace (Sacrifice) skipped: " + ex.Message));
			}
			DirectDamageReceipt receipt = new DirectDamageReceipt(info, victim, Settings.SacrificeLifesteal);
			pending.Add(info, receipt);
			Action<DamageReport> action = delegate(DamageReport report)
			{
				if (report != null && report.damageInfo == info && report.victim == victim)
				{
					receipt.ObserveReport(report.damageInfo, report.victim, report.damageInfo.rejected, report.damageDealt);
				}
			};
			GlobalEventManager.onServerDamageDealt += action;
			try
			{
				victim.TakeDamage(info);
			}
			finally
			{
				GlobalEventManager.onServerDamageDealt -= action;
				pending.Remove(info);
			}
			if (NetworkServer.active && !info.rejected && (Object)(object)val != (Object)null && (Object)(object)val.healthComponent != (Object)null && val.healthComponent.alive && receipt.TryConsumeHealing(out var amount))
			{
				val.healthComponent.Heal(amount, default(ProcChainMask), true);
			}
		}
	}
	[HarmonyPatch(typeof(GenericDamageOrb), "OnArrival")]
	internal static class SacrificeOrbDamagePatch
	{
		internal static bool Ready { get; private set; }

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = PatchInstructions.Clone(instructions);
			MethodInfo method = AccessTools.Method(typeof(HealthComponent), "TakeDamage", new Type[1] { typeof(DamageInfo) }, (Type[])null);
			List<int> list2 = PatchInstructions.FindCalls(list, method);
			Ready = false;
			if (list2.Count != 1)
			{
				Plugin.Log.LogError((object)("Sacrifice lifesteal disabled: expected one direct GenericDamageOrb.TakeDamage call, found " + list2.Count + "."));
				return list;
			}
			PatchInstructions.AddArgumentAndReplaceCall(list, list2[0], OpCodes.Ldarg_0, AccessTools.Method(typeof(SacrificeLifesteal), "ApplyOrbDamage", (Type[])null, (Type[])null));
			Ready = true;
			return list;
		}
	}
	[HarmonyPatch(typeof(Sacrifice), "FixedUpdate")]
	internal static class SacrificeAgilePatch
	{
		internal static bool Ready { get; private set; }

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = PatchInstructions.Clone(instructions);
			MethodInfo method = AccessTools.PropertySetter(typeof(CharacterBody), "isSprinting");
			List<int> list2 = PatchInstructions.FindCalls(list, method);
			Ready = false;
			if (list2.Count != 1 || list2[0] < 2 || list[list2[0] - 1].opcode != OpCodes.Ldc_I4_0 || !CodeInstructionExtensions.Calls(list[list2[0] - 2], AccessTools.PropertyGetter(typeof(EntityState), "characterBody")))
			{
				Plugin.Log.LogError((object)"Sacrifice Agile patch disabled: expected one characterBody.isSprinting = false pattern. Vanilla state is retained.");
				return list;
			}
			list[list2[0]].opcode = OpCodes.Call;
			list[list2[0]].operand = AccessTools.Method(typeof(SacrificeAgilePatch), "IgnoreForcedSprintOff", (Type[])null, (Type[])null);
			Ready = true;
			return list;
		}

		internal static void IgnoreForcedSprintOff(CharacterBody body, bool value)
		{
		}
	}
	internal static class PatchInstructions
	{
		internal static List<CodeInstruction> Clone(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>();
			foreach (CodeInstruction instruction in instructions)
			{
				list.Add(new CodeInstruction(instruction));
			}
			return list;
		}

		internal static List<int> FindCalls(List<CodeInstruction> code, MethodInfo method)
		{
			List<int> list = new List<int>();
			if (method == null)
			{
				return list;
			}
			for (int i = 0; i < code.Count; i++)
			{
				if (CodeInstructionExtensions.Calls(code[i], method))
				{
					list.Add(i);
				}
			}
			return list;
		}

		internal static bool FloatBefore(List<CodeInstruction> code, int call, float value)
		{
			if (call > 0 && code[call - 1].opcode == OpCodes.Ldc_R4)
			{
				return object.Equals(code[call - 1].operand, value);
			}
			return false;
		}

		internal static bool LoadsLocal(CodeInstruction instruction)
		{
			OpCode opcode = instruction.opcode;
			if (!(opcode == OpCodes.Ldloc) && !(opcode == OpCodes.Ldloc_S) && !(opcode == OpCodes.Ldloc_0) && !(opcode == OpCodes.Ldloc_1) && !(opcode == OpCodes.Ldloc_2))
			{
				return opcode == OpCodes.Ldloc_3;
			}
			return true;
		}

		internal static void AddArgumentAndReplaceCall(List<CodeInstruction> code, int index, OpCode argument, MethodInfo replacement)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Invalid comparison between Unknown and I4
			CodeInstruction val = code[index];
			CodeInstruction val2 = new CodeInstruction(argument, (object)null);
			val2.labels.AddRange(val.labels);
			val.labels.Clear();
			for (int num = val.blocks.Count - 1; num >= 0; num--)
			{
				if ((int)val.blocks[num].blockType != 5)
				{
					val2.blocks.Insert(0, val.blocks[num]);
					val.blocks.RemoveAt(num);
				}
			}
			val.opcode = OpCodes.Call;
			val.operand = replacement;
			code.Insert(index, val2);
		}
	}
	[HarmonyPatch(typeof(Sacrifice), "FireOrb")]
	internal static class SacrificeDamagePatch
	{
		private static void Prefix(Sacrifice __instance)
		{
			if (Plugin.IsAcolyteBody(((EntityState)__instance).outer.commonComponents.characterBody))
			{
				__instance.damageCoefficient = Settings.SacrificeCoefficient;
			}
		}
	}
	public static class Settings
	{
		internal static Func<float> armor;

		internal static Func<float> bladeSlice;

		internal static Func<float> bladeSling;

		internal static Func<float> javelin;

		internal static Func<float> sacrificeDamage;

		internal static Func<float> sacrificeCooldown;

		internal static Func<float> sacrificeLifesteal;

		internal static Func<int> sacrificeCharges;

		internal static Func<float> clawDamage;

		internal static Func<float> dashBurst;

		internal static Func<float> dashSlash;

		internal static Func<float> dashFinal;

		internal static Func<float> harvesterArmor;

		internal static Func<float> torrential;

		internal static Func<float> storm;

		internal static Func<float> stormReactivated;

		internal static Func<float> litany;

		internal static Func<float> harvesterRecovery;

		internal static Func<bool> verbose;

		internal static Func<float> lungeDamage;

		internal static Func<float> vortexDamage;

		internal static Func<bool> classic202;

		public const float DefaultLungeDamage = 200f;

		public const float DefaultVortexDamage = 400f;

		public const float DefaultLungeFirstDamage = 250f;

		internal static Func<float> lungeFirstDamage;

		public const float DefaultArmor = 20f;

		public const float DefaultBladeSlice = 5.5f;

		public const float DefaultBladeSling = 5.5f;

		public const float DefaultJavelin = 5.5f;

		public const float DefaultSacrificeDamage = 500f;

		public const float DefaultSacrificeCooldown = 7f;

		public const float DefaultSacrificeLifesteal = 10f;

		public const int DefaultSacrificeCharges = 2;

		public const float DefaultClawDamage = 800f;

		public const float DefaultDashBurst = 1200f;

		public const float DefaultDashSlash = 40f;

		public const float DefaultDashFinal = 440f;

		public const float DefaultHarvesterArmor = 60f;

		public const float DefaultTorrential = 250f;

		public const float DefaultStorm = 200f;

		public const float DefaultStormReactivated = 500f;

		public const float DefaultLitany = 12f;

		public const float DefaultHarvesterRecovery = 7.5f;

		internal static Func<float> pinkBrand;

		internal static Func<float> redBrand;

		internal static Func<float> pinkBrandSpeed;

		internal static Func<float> redBrandSpeed;

		public const float DefaultPinkBrand = 24f;

		public const float DefaultRedBrand = 38f;

		public const float DefaultPinkBrandSpeed = 10f;

		public const float DefaultRedBrandSpeed = 20f;

		internal static Func<float> pinkBrandRecovery;

		internal static Func<float> redBrandRecovery;

		public const float DefaultPinkBrandRecovery = 20f;

		public const float DefaultRedBrandRecovery = 40f;

		internal static Func<float> pinkBrandLifesteal;

		internal static Func<float> redBrandLifesteal;

		public const float DefaultPinkBrandLifesteal = 3.25f;

		public const float DefaultRedBrandLifesteal = 6.5f;

		public static bool Verbose
		{
			get
			{
				try
				{
					return verbose != null && verbose();
				}
				catch
				{
					return false;
				}
			}
		}

		public static float LungeFirstDamage => V(lungeFirstDamage, 250f, 0f, 10000f) / 100f;

		public static float LungeDamage => V(lungeDamage, 200f, 0f, 10000f) / 100f;

		public static float VortexDamage => V(vortexDamage, 400f, 0f, 10000f) / 100f;

		public static bool Classic202
		{
			get
			{
				try
				{
					return classic202 != null && classic202();
				}
				catch
				{
					return false;
				}
			}
		}

		public static float AcolyteArmor => V(armor, 20f, 0f, 1000f);

		public static float BladeSliceRecharge => V(bladeSlice, 5.5f, 0.5f, 60f);

		public static float BladeSlingCooldown => V(bladeSling, 5.5f, 0.5f, 60f);

		public static float JavelinCooldown => V(javelin, 5.5f, 0.5f, 60f);

		public static float SacrificeCoefficient => V(sacrificeDamage, 500f, 0f, 10000f) / 100f;

		public static float SacrificeCooldown => V(sacrificeCooldown, 7f, 0.5f, 60f);

		public static int SacrificeCharges
		{
			get
			{
				if (sacrificeCharges == null)
				{
					return 2;
				}
				try
				{
					return Math.Max(1, Math.Min(10, sacrificeCharges()));
				}
				catch
				{
					return 2;
				}
			}
		}

		public static double SacrificeLifesteal => (double)V(sacrificeLifesteal, 10f, 0f, 100f) / 100.0;

		public static float ClawCoefficient => V(clawDamage, 800f, 0f, 10000f) / 100f;

		public static float DashBurstCoefficient => V(dashBurst, 1200f, 0f, 10000f) / 100f;

		public static float DashSlashCoefficient => V(dashSlash, 40f, 0f, 10000f) / 100f;

		public static float DashFinalCoefficient => V(dashFinal, 440f, 0f, 10000f) / 100f;

		public static float HarvesterArmor => V(harvesterArmor, 60f, 0f, 1000f);

		public static float TorrentialCoefficient => V(torrential, 250f, 0f, 10000f) / 100f;

		public static float StormCoefficient => V(storm, 200f, 0f, 10000f) / 100f;

		public static float ReactivatedStormCoefficient => V(stormReactivated, 500f, 0f, 10000f) / 100f;

		public static float LitanyDuration => V(litany, 12f, 1f, 120f);

		public static float HarvesterRecovery => V(harvesterRecovery, 7.5f, 0f, 100f) / 100f;

		public static float PinkBrandDuration => V(pinkBrand, 24f, 1f, 600f);

		public static float RedBrandDuration => V(redBrand, 38f, 1f, 600f);

		public static float PinkBrandMoveSpeed => V(pinkBrandSpeed, 10f, 0f, 500f) / 100f;

		public static float RedBrandMoveSpeed => V(redBrandSpeed, 20f, 0f, 500f) / 100f;

		public static float PinkBrandRecovery => V(pinkBrandRecovery, 20f, 0f, 100f) / 100f;

		public static float RedBrandRecovery => V(redBrandRecovery, 40f, 0f, 100f) / 100f;

		public static float PinkBrandLifesteal => V(pinkBrandLifesteal, 3.25f, 0f, 100f) / 100f;

		public static float RedBrandLifesteal => V(redBrandLifesteal, 6.5f, 0f, 100f) / 100f;

		private static float V(Func<float> e, float d, float min, float max)
		{
			if (e == null)
			{
				return d;
			}
			float num;
			try
			{
				num = e();
			}
			catch
			{
				return d;
			}
			if (!float.IsNaN(num) && !float.IsInfinity(num))
			{
				return Math.Max(min, Math.Min(max, num));
			}
			return d;
		}
	}
	public static class SettingsConfig
	{
		private static ConfigFile hidden;

		public static ConfigFile Hidden
		{
			get
			{
				//IL_0033: 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_0044: Expected O, but got Unknown
				if (hidden == null)
				{
					hidden = new ConfigFile(Path.Combine(Paths.CachePath, "AcolyteRebalance.unused-" + Guid.NewGuid().ToString("N") + ".cfg"), false)
					{
						SaveOnConfigSet = false
					};
				}
				return hidden;
			}
		}

		private static Func<float> F(ConfigEntry<float> e)
		{
			return () => e.Value;
		}

		private static Func<int> FI(ConfigEntry<int> e)
		{
			return () => e.Value;
		}

		private static Func<bool> FB(ConfigEntry<bool> e)
		{
			return () => e.Value;
		}

		public static void Bind(ConfigFile c)
		{
			Settings.verbose = FB(c.Bind<bool>("Debug", "Detailed Logging", false, "Write detailed diagnostic lines to the log, for bug reports. Off by default."));
			Settings.classic202 = FB(c.Bind<bool>("Mode", "2.0.2 Mode", false, "true = play the 2.0.2 kit: no Lunge or Vortex, no No Grace, and the claw's Weaken and the dash's healing disabled on every hit again."));
			Settings.lungeFirstDamage = F(c.Bind<float>("Lunge and Vortex", "Lunge First Strike Damage", 250f, "Damage of Lunge's first strike (the stab), percent."));
			Settings.lungeDamage = F(c.Bind<float>("Lunge and Vortex", "Lunge Damage", 200f, "Damage of Lunge's second strike (the sweep), percent."));
			Settings.vortexDamage = F(c.Bind<float>("Lunge and Vortex", "Vortex Damage", 400f, "Damage of Vortex's hit (Jump Quickstrike, then Utility), percent."));
			Settings.armor = F(c.Bind<float>("Acolyte", "Base Armor", 20f, "Base armour, the same with either passive."));
			Settings.bladeSlice = F(c.Bind<float>("Acolyte", "Quickstrike Recharge", 5.5f, "Seconds for a Blade Slice (Quickstrike) charge to recharge."));
			Settings.bladeSling = F(c.Bind<float>("Acolyte", "Blade Sling Cooldown", 5.5f, "Seconds."));
			Settings.javelin = F(c.Bind<float>("Acolyte", "Javelin Cooldown", 5.5f, "Seconds."));
			Settings.sacrificeDamage = F(c.Bind<float>("Sacrifice", "Damage", 500f, "Normal Sacrifice damage, percent."));
			Settings.sacrificeCooldown = F(c.Bind<float>("Sacrifice", "Cooldown", 7f, "Seconds per charge (shared by Sacrifice, the claw and the dash)."));
			Settings.sacrificeCharges = FI(c.Bind<int>("Sacrifice", "Charges", 2, "Sacrifice charges."));
			Settings.sacrificeLifesteal = F(c.Bind<float>("Sacrifice", "Healing", 10f, "Percent of the damage Sacrifice's orbs deal that heals you."));
			Settings.clawDamage = F(c.Bind<float>("Sacrifice", "Claw Damage", 800f, "Claw (Sacrifice during a jump Quickstrike) damage, percent."));
			Settings.dashBurst = F(c.Bind<float>("Sacrifice", "Dash Burst Damage", 1200f, "Dash (Sacrifice during a sprint Quickstrike) burst damage on one enemy, percent. Reduced by a twelfth per extra enemy, never below half."));
			Settings.dashSlash = F(c.Bind<float>("Sacrifice", "Dash Slash Damage", 40f, "Damage of each of the dash's quick slashes, percent."));
			Settings.dashFinal = F(c.Bind<float>("Sacrifice", "Dash Final Slash Damage", 440f, "Damage of the dash's last, heavy slash, percent."));
			Settings.harvesterArmor = F(c.Bind<float>("Anima Harvester", "Armor", 60f, "Anima Harvester base armour."));
			Settings.torrential = F(c.Bind<float>("Anima Harvester", "Torrential Slash Damage", 250f, "Percent."));
			Settings.storm = F(c.Bind<float>("Anima Harvester", "Soul Storm Damage", 200f, "Percent."));
			Settings.stormReactivated = F(c.Bind<float>("Anima Harvester", "Reactivated Soul Storm Damage", 500f, "Percent."));
			Settings.litany = F(c.Bind<float>("Anima Harvester", "Litany Duration", 12f, "Seconds a full Litany (7 Convictions) lasts."));
			Settings.harvesterRecovery = F(c.Bind<float>("Anima Harvester", "Recoverable Health From Damage", 7.5f, "Percent of damage dealt in Anima Harvester returned as recoverable health (scaled by the Harvester's health ratio, as in vanilla)."));
			Settings.pinkBrand = F(c.Bind<float>("Harvester Brand", "Pink Brand Duration", 24f, "Seconds the pink Brand lasts after leaving Anima Harvester (earned by staying in the form for half a full Litany). Gives the claw's haunt and the dash's slash spread."));
			Settings.redBrand = F(c.Bind<float>("Harvester Brand", "Red Brand Duration", 38f, "Seconds the red Brand lasts after leaving Anima Harvester (earned by staying in the form for a full Litany). Gives the full N'kuhana's Opinion Sacrifice effects."));
			Settings.pinkBrandSpeed = F(c.Bind<float>("Harvester Brand", "Pink Brand Move Speed", 10f, "Movement speed bonus of the pink Brand, percent."));
			Settings.redBrandSpeed = F(c.Bind<float>("Harvester Brand", "Red Brand Move Speed", 20f, "Movement speed bonus of the red Brand, percent."));
			Settings.pinkBrandRecovery = F(c.Bind<float>("Harvester Brand", "Pink Brand Recoverable Health", 20f, "Extra percent of damage taken that becomes recoverable health with the pink Brand (added to the passive's own: N'kuhana's Grace 40%, N'kuhana's Favor 0%)."));
			Settings.redBrandRecovery = F(c.Bind<float>("Harvester Brand", "Red Brand Recoverable Health", 40f, "Extra percent of damage taken that becomes recoverable health with the red Brand (Grace 40% becomes 80%, Favor 0% becomes 40%)."));
			Settings.pinkBrandLifesteal = F(c.Bind<float>("Harvester Brand", "Pink Brand Lifesteal", 3.25f, "Extra percent of skill damage dealt healed from recoverable health with the pink Brand (added to the passive's own: N'kuhana's Grace 6.5%, N'kuhana's Favor 0%)."));
			Settings.redBrandLifesteal = F(c.Bind<float>("Harvester Brand", "Red Brand Lifesteal", 6.5f, "Extra percent of skill damage dealt healed from recoverable health with the red Brand (Grace 6.5% becomes 13%, Favor 0% becomes 6.5%)."));
		}

		public static void RemoveOldEntries(ConfigFile c, Action<string> log)
		{
			try
			{
				if (AccessTools.Property(typeof(ConfigFile), "OrphanedEntries")?.GetValue(c, null) is IDictionary { Count: not 0, Count: var count } dictionary)
				{
					dictionary.Clear();
					c.Save();
					log?.Invoke("Removed " + count + " old config entries.");
				}
			}
			catch (Exception ex)
			{
				log?.Invoke("Old config entries kept: " + ex.Message);
			}
		}
	}
	[HarmonyPatch(typeof(Language), "GetLocalizedStringByToken")]
	internal static class SkillTextPatch
	{
		internal const string SacrificeToken = "ACOLYTE_SPECIAL_DESCRIPTION";

		internal const string LitanyToken = "ACOLYTE_SPECIAL_TRANSFORM_DESCRIPTION";

		internal const string LitanyLine = "Stay transformed to <style=cIsDamage>empower Acolyte</style>.";

		internal const string ClawKeywordToken = "ACOLYTE_REBALANCE_KEYWORD_CLAW";

		internal const string DashKeywordToken = "ACOLYTE_REBALANCE_KEYWORD_DASH";

		internal const string NkuhanaKeywordToken = "ACOLYTE_REBALANCE_KEYWORD_NKUHANA";

		internal const string ReapFavorKeywordToken = "ACOLYTE_REBALANCE_KEYWORD_REAP_FAVOR";

		internal const string ReapGraceKeywordToken = "ACOLYTE_REBALANCE_KEYWORD_REAP_GRACE";

		internal const float GraceNativeRecovery = 40f;

		internal const string NoGraceColor = "#299E33";

		internal const string LungeKeywordToken = "ACOLYTE_REBALANCE_KEYWORD_LUNGE";

		internal const string VortexKeywordToken = "ACOLYTE_REBALANCE_KEYWORD_VORTEX";

		internal const string NoGraceKeywordToken = "ACOLYTE_REBALANCE_KEYWORD_NOGRACE";

		internal const string UtilityLine = "Activate utility while using <style=cIsDamage>quickstrike</style> to perform unique attacks.";

		internal const string ClawKeyword231 = "<style=cKeywordName>Claw</style><style=cSub>Use Sacrifice during a jump Quickstrike. Slash around you for <style=cIsDamage>800% damage</style>. Grants <style=cIsHealing>recoverable health</style> on hit.</style>";

		internal const string DashKeyword231 = "<style=cKeywordName>Dash</style><style=cSub>Use Sacrifice during a sprint Quickstrike. Dash through enemies, then burst them for <style=cIsDamage>1200% damage</style>, reduced per extra enemy. <style=cIsHealing>Heals</style> from your <style=cIsHealing>recoverable health</style>. Hit a <style=cIsUtility>single enemy</style> for bonus damage.</style>";

		internal static readonly HashSet<string> UtilityDescriptionTokens = new HashSet<string>();

		internal const string NkuhanaKeyword = "<style=cKeywordName><color=#FF3B30>N'kuhana's Opinion</color></style><style=cSub><color=#FF3B30>N'kuhana's Opinion empowers you.</color></style>";

		internal const string DefaultClawKeyword = "<style=cKeywordName>Claw</style><style=cSub>Use Sacrifice during a jump Quickstrike. Slash around you for <style=cIsDamage>800% damage</style> and <style=cIsDamage>Weaken</style> enemies. Grants <style=cIsHealing>recoverable health</style> on hit.</style>";

		internal const string DefaultDashKeyword = "<style=cKeywordName>Dash</style><style=cSub>Use Sacrifice during a sprint Quickstrike. Dash through enemies, then burst them for <style=cIsDamage>1200% damage</style>, reduced per extra enemy. Burst enemies <style=cIsHealth>can't heal</style> for 6s. <style=cIsHealing>Heals</style> from your <style=cIsHealing>recoverable health</style>. Hit a <style=cIsUtility>single enemy</style> for bonus damage.</style>";

		internal static string ClawKeyword = "<style=cKeywordName>Claw</style><style=cSub>Use Sacrifice during a jump Quickstrike. Slash around you for <style=cIsDamage>800% damage</style> and <style=cIsDamage>Weaken</style> enemies. Grants <style=cIsHealing>recoverable health</style> on hit.</style>";

		internal static string DashKeyword = "<style=cKeywordName>Dash</style><style=cSub>Use Sacrifice during a sprint Quickstrike. Dash through enemies, then burst them for <style=cIsDamage>1200% damage</style>, reduced per extra enemy. Burst enemies <style=cIsHealth>can't heal</style> for 6s. <style=cIsHealing>Heals</style> from your <style=cIsHealing>recoverable health</style>. Hit a <style=cIsUtility>single enemy</style> for bonus damage.</style>";

		internal const string DefaultSacrificeDescription = "<style=cIsUtility>Agile</style>. Deal <style=cIsDamage>500% damage</style>, and gain 2 <style=cIsDamage>Convictions</style>. Kills grant an extra Conviction. At <style=cIsDamage>7</style> Convictions, invoke your <style=cIsHealth>Litany</style>. Holds <style=cIsUtility>2 charges</style>.\nActivate Sacrifice while using <style=cIsDamage>quickstrike</style> to perform unique attacks.";

		internal static string SacrificeDescription = "<style=cIsUtility>Agile</style>. Deal <style=cIsDamage>500% damage</style>, and gain 2 <style=cIsDamage>Convictions</style>. Kills grant an extra Conviction. At <style=cIsDamage>7</style> Convictions, invoke your <style=cIsHealth>Litany</style>. Holds <style=cIsUtility>2 charges</style>.\nActivate Sacrifice while using <style=cIsDamage>quickstrike</style> to perform unique attacks.";

		private static readonly Regex FavorArmor = new Regex("\\s*Increases\\s*(<style=[^>]*>)?\\s*armou?r\\s*(</style>)?\\s*by\\s*(<style=[^>]*>)?\\s*\\+?\\d+\\s*(</style>)?\\.?", RegexOptions.IgnoreCase);

		internal static string NoGraceName => "<color=#299E33>No Grace</color>";

		internal static string NoGraceKeyword => "<style=cKeywordName><color=#299E33>No Grace</color></style><style=cSub>Mark that can be expunged with <style=cIsDamage>Sacrifice</style> for <style=cIsDamage>bonus damage</style>. Refreshes <style=cIsUtility>utility</style>. Applies debuffs.</style>";

		internal static string LungeKeyword(float totalPercent)
		{
			return "<style=cKeywordName>Lunge</style><style=cSub>Strikes twice for <style=cIsDamage>" + Num(totalPercent) + "% damage</style>. Refreshes <style=cIsUtility>Blade Slice</style>. Applies " + NoGraceName + ".</style>";
		}

		internal static string VortexKeyword(float percent)
		{
			return "<style=cKeywordName>Vortex</style><style=cSub>Slice around you for <style=cIsDamage>" + Num(percent) + "% damage</style>. Refreshes <style=cIsUtility>Blade Slice</style>. Applies " + NoGraceName + ".</style>";
		}

		private static string Num(float v)
		{
			return Math.Round(v, 1).ToString(CultureInfo.InvariantCulture);
		}

		internal static string ReapKeyword(float percent)
		{
			return "<style=cKeywordName><color=#FF3B30>Reap what you sow</color></style><style=cSub>" + (Settings.Classic202 ? "" : "If you spend all <style=cIsDamage>Convictions</style>, empowers") + (Settings.Classic202 ? "Empowers" : "") + " Sacrifice variants and " + (Settings.Classic202 ? "convert" : "converts") + " <style=cIsHealing>" + Math.Round(percent, 1).ToString(CultureInfo.InvariantCulture) + "% damage taken</style> into <style=cIsHealing>recoverable health</style>.</style>";
		}

		private static string Pct(float coefficient)
		{
			return Math.Round(coefficient * 100f, 1).ToString(CultureInfo.InvariantCulture) + "%";
		}

		private static void Postfix(Language __instance, string token, ref string __result)
		{
			switch (token)
			{
			case "ACOLYTE_REBALANCE_KEYWORD_NKUHANA":
				__result = "<style=cKeywordName><color=#FF3B30>N'kuhana's Opinion</color></style><style=cSub><color=#FF3B30>N'kuhana's Opinion empowers you.</color></style>";
				return;
			case "ACOLYTE_REBALANCE_KEYWORD_REAP_FAVOR":
				__result = ReapKeyword(Settings.RedBrandRecovery * 100f);
				return;
			case "ACOLYTE_REBALANCE_KEYWORD_REAP_GRACE":
				__result = ReapKeyword(40f + Settings.RedBrandRecovery * 100f);
				return;
			case "ACOLYTE_REBALANCE_KEYWORD_LUNGE":
				__result = LungeKeyword((Settings.LungeFirstDamage + Settings.LungeDamage) * 100f);
				return;
			case "ACOLYTE_REBALANCE_KEYWORD_VORTEX":
				__result = VortexKeyword(Settings.VortexDamage * 100f);
				return;
			case "ACOLYTE_REBALANCE_KEYWORD_NOGRACE":
				__result = NoGraceKeyword;
				return;
			case "ACOLYTE_REBALANCE_KEYWORD_CLAW":
			{
				string text = (Settings.Classic202 ? ClawKeyword : "<style=cKeywordName>Claw</style><style=cSub>Use Sacrifice during a jump Quickstrike. Slash around you for <style=cIsDamage>800% damage</style>. Grants <style=cIsHealing>recoverable health</style> on hit.</style>");
				if (!string.IsNullOrEmpty(text))
				{
					__result = text.Replace("800%", Pct(Settings.ClawCoefficient));
				}
				return;
			}
			case "ACOLYTE_REBALANCE_KEYWORD_DASH":
			{
				string text2 = (Settings.Classic202 ? DashKeyword : "<style=cKeywordName>Dash</style><style=cSub>Use Sacrifice during a sprint Quickstrike. Dash through enemies, then burst them for <style=cIsDamage>1200% damage</style>, reduced per extra enemy. <style=cIsHealing>Heals</style> from your <style=cIsHealing>recoverable health</style>. Hit a <style=cIsUtility>single enemy</style> for bonus damage.</style>");
				if (!string.IsNullOrEmpty(text2))
				{
					__result = text2.Replace("1200%", Pct(Settings.DashBurstCoefficient));
				}
				return;
			}
			}
			if (!Settings.Classic202 && token != null && UtilityDescriptionTokens.Contains(token) && __instance != null && __instance.name == "en" && __result != null && __result.IndexOf("Activate utility while using <style=cIsDamage>quickstrike</style> to perform unique attacks.", StringComparison.Ordinal) < 0)
			{
				__result += "\nActivate utility while using <style=cIsDamage>quickstrike</style> to perform unique attacks.";
			}
			else if (token == "ACOLYTE_SPECIAL_DESCRIPTION" && __instance != null && __instance.name == "en" && !string.IsNullOrEmpty(SacrificeDescription))
			{
				__result = SacrificeDescription.Replace("500%", Pct(Settings.SacrificeCoefficient)).Replace("2 charges", Settings.SacrificeCharges + " charge" + ((Settings.SacrificeCharges == 1) ? "" : "s"));
			}
			else if (token == "ACOLYTE_SPECIAL_TRANSFORM_DESCRIPTION" && __instance != null && __instance.name == "en" && __result != null && __result.IndexOf("Stay transformed to <style=cIsDamage>empower Acolyte</style>.", StringComparison.Ordinal) < 0)
			{
				__result += " Stay transformed to <style=cIsDamage>empower Acolyte</style>.";
			}
			else if (__result != null && __result.IndexOf("cannot heal", StringComparison.Ordinal) >= 0 && __result.IndexOf("armor", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				__result = FavorArmor.Replace(__result, "");
			}
		}
	}
	[HarmonyPatch(typeof(HealthComponent), "TakeDamageProcess")]
	internal static class AcolyteUtilityTravelProtectionPatch
	{
		private static void Prefix(HealthComponent __instance, DamageInfo damageInfo)
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active || damageInfo == null || !__instance.alive || !Plugin.IsAcolyteBody(__instance.body))
			{
				return;
			}
			CharacterBody body = __instance.body;
			EntityStateMachine val = EntityStateMachine.FindByCustomName(((Component)body).gameObject, "Body");
			if ((Object)(object)val == (Object)null || val.destroying || val.HasPendingState() || !IsUtilityDash(((object)val.state)?.GetType()))
			{
				return;
			}
			BladeDash val2 = (BladeDash)val.state;
			if (!string.IsNullOrEmpty(val2.targetProjectileFindableName))
			{
				GameObject val3 = ProjectileLocator.FindProjectileInstance(((Component)body).gameObject, val2.targetProjectileFindableName);
				int num;
				if ((Object)(object)val3 != (Object)null)
				{
					Vector3 val4 = val3.transform.position - ((Component)body).transform.position;
					num = ((((Vector3)(ref val4)).magnitude <= BladeDash.minDistance) ? 1 : 0);
				}
				else
				{
					num = 0;
				}
				bool atDestination = (byte)num != 0;
				if (GameplayRules.ProtectUtilityTravel(NetworkServer.active, __instance.alive, utilityDash: true, (Object)(object)val3 != (Object)null, val.HasPendingState(), atDestination))
				{
					damageInfo.rejected = true;
				}
			}
		}

		internal static bool IsUtilityDash(Type state)
		{
			if (!(state == typeof(BladeDash)))
			{
				return state == typeof(JavelinDash);
			}
			return true;
		}
	}
}
namespace AcolyteAnimationTest
{
	public sealed class AerialClawFinisher : BaseState
	{
		public float EntryAttackSpeed => base.attackSpeedStat;

		public override void OnEnter()
		{
			((BaseState)this).OnEnter();
			if (!((EntityState)this).isAuthority)
			{
				Plugin.ObserveEnter((EntityState)(object)this, dash: false, base.attackSpeedStat);
			}
			else if (!Plugin.BeginFinisher(this))
			{
				((EntityState)this).outer.SetNextStateToMain();
			}
		}

		public override void FixedUpdate()
		{
			((EntityState)this).FixedUpdate();
			Plugin.TickFinisher(this, ((EntityState)this).fixedAge);
			if (((EntityState)this).isAuthority && !((EntityState)this).outer.HasPendingState() && (!Plugin.CanContinue(this) || ((EntityState)this).fixedAge >= Plugin.FinisherDuration(this)))
			{
				((EntityState)this).outer.SetNextStateToMain();
			}
		}

		public override InterruptPriority GetMinimumInterruptPriority()
		{
			if (Plugin.ClawCancelable(this))
			{
				return (InterruptPriority)0;
			}
			return (InterruptPriority)2;
		}

		public override void OnExit()
		{
			if (((EntityState)this).isAuthority)
			{
				Plugin.EndFinisher(this);
			}
			else
			{
				Plugin.ObserveExit((EntityState)(object)this);
			}
			((EntityState)this).OnExit();
		}
	}
	public sealed class AerialMovement : IDisposable
	{
		public const float DefaultHopSpeed = 12f;

		public const float MinimumHopSpeed = 3f;

		public const float MaximumHopSpeed = 12f;

		public const float DefaultGravityMultiplier = 0.1f;

		private readonly CharacterMotor motor;

		private readonly float previousAirControl;

		private readonly float appliedAirControl;

		private readonly float previousGravity;

		private readonly float appliedGravity;

		private readonly float hopSpeed;

		private bool gravityHeld;

		private bool disposed;

		private bool hopped;

		public static float BoundGravity(float value)
		{
			if (!float.IsNaN(value) && !float.IsInfinity(value))
			{
				return Mathf.Clamp(value, 0.01f, 1f);
			}
			return 0.1f;
		}

		public static float BoundHopSpeed(float value)
		{
			if (!float.IsNaN(value) && !float.IsInfinity(value))
			{
				return Mathf.Clamp(value, 3f, 12f);
			}
			return 12f;
		}

		public AerialMovement(CharacterMotor motor, float gravityMultiplier, float hopSpeed, float airControl)
		{
			this.motor = motor;
			this.hopSpeed = BoundHopSpeed(hopSpeed);
			if (!Object.op_Implicit((Object)(object)motor) || !motor.hasEffectiveAuthority || GroundContact.OnTerrain(motor))
			{
				disposed = true;
				return;
			}
			GroundContact.ReleaseFromCharacter(motor);
			previousAirControl = motor.airControl;
			appliedAirControl = airControl;
			motor.airControl = appliedAirControl;
			previousGravity = motor.gravityMultiplier;
			appliedGravity = previousGravity * BoundGravity(gravityMultiplier);
			motor.gravityMultiplier = appliedGravity;
			gravityHeld = true;
			SetVertical(0f);
		}

		private void SetVertical(float y)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			Vector3 velocity = motor.velocity;
			velocity.y = y;
			motor.velocity = velocity;
		}

		public void Tick(float age, float swipeEnd)
		{
			if (!disposed)
			{
				if (!Object.op_Implicit((Object)(object)motor) || !motor.hasEffectiveAuthority || GroundContact.OnTerrain(motor))
				{
					Dispose();
				}
				else if (!float.IsNaN(age) && !float.IsInfinity(age) && !(age < swipeEnd) && !hopped)
				{
					hopped = true;
					GroundContact.ReleaseFromCharacter(motor);
					SetVertical(Mathf.Max(motor.velocity.y, hopSpeed));
					ReleaseGravity();
				}
			}
		}

		private void ReleaseGravity()
		{
			if (gravityHeld)
			{
				gravityHeld = false;
				if (Object.op_Implicit((Object)(object)motor) && motor.gravityMultiplier == appliedGravity)
				{
					motor.gravityMultiplier = previousGravity;
				}
			}
		}

		public void Dispose()
		{
			if (!disposed)
			{
				disposed = true;
				ReleaseGravity();
				if (Object.op_Implicit((Object)(object)motor) && motor.airControl == appliedAirControl)
				{
					motor.airControl = previousAirControl;
				}
			}
		}
	}
	public sealed class AerialOptions
	{
		private sealed class HopRange : AcceptableValueRange<float>
		{
			public HopRange()
				: base(3f, 12f)
			{
			}

			public override object Clamp(object value)
			{
				return AerialMovement.BoundHopSpeed((value is float num) ? num : 12f);
			}
		}

		private sealed class GravityRange : AcceptableValueRange<float>
		{
			public GravityRange()
				: base(0.01f, 1f)
			{
			}

			public override object Clamp(object value)
			{
				return AerialMovement.BoundGravity((value is float num) ? num : 0.1f);
			}
		}

		private sealed class RearExtensionRange : AcceptableValueRange<float>
		{
			public RearExtensionRange()
				: base(0f, 0.75f)
			{
			}

			public override object Clamp(object value)
			{
				return ClawGeometry.BoundRearExtension((value is float num) ? num : 0.35f);
			}
		}

		public readonly ConfigEntry<KeyboardShortcut> Toggle;

		public readonly ConfigEntry<float> ReachHorizontal081;

		public readonly ConfigEntry<float> ReachDown081;

		public readonly ConfigEntry<float> ReachUp081;

		public readonly ConfigEntry<float> Gravity;

		public readonly ConfigEntry<float> Hop;

		public readonly ConfigEntry<float> Control;

		public readonly ConfigEntry<float> Width;

		public readonly ConfigEntry<float> Rear;

		public readonly ConfigEntry<float> Front;

		public readonly ConfigEntry<float> Below;

		public readonly ConfigEntry<float> RearAbove;

		public readonly ConfigEntry<float> FrontAbove;

		public readonly ConfigEntry<float> SideOverlap;

		public readonly ConfigEntry<float> CentreWidth;

		public readonly ConfigEntry<float> DepthOverlap;

		public readonly ConfigEntry<float> RearExtension;

		private static ConfigEntry<float> Bind(ConfigFile c, string section, string key, float value, float min, float max, string description)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			return SettingsConfig.Hidden.Bind<float>(section, key, value, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<float>(min, max), Array.Empty<object>()));
		}

		public AerialOptions(ConfigFile c)
		{
			//IL_0094: 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_00d6: Expected O, but got Unknown
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Expected O, but got Unknown
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Expected O, but got Unknown
			ReachHorizontal081 = Bind(c, "ClawReach081", "HorizontalMultiplier", 2f, 1f, 2f, "Experimental X/Z reach multiplier about the shared collision origin. Default 2 doubles width, forward and rear reach; does not multiply every axis by 2. Three boxes and F7 share these exact values.");
			ReachDown081 = Bind(c, "ClawReach081", "DownwardMultiplier", 1.25f, 1f, 1.5f, "Experimental downward reach multiplier. Default 1.25 limits vertical inflation versus uniform 2x (8x volume). Set all three multipliers to 1 for v080 collision.");
			ReachUp081 = Bind(c, "ClawReach081", "UpwardMultiplier", 2f, 1f, 2f, "Experimental height above origin; 2 improves contact with targets remaining overhead. No enemy repositioning.");
			Toggle = SettingsConfig.Hidden.Bind<KeyboardShortcut>("Developer", "HitboxToggle", KeyboardShortcut.Empty, "Local-only outlines; always OFF on startup. Change if another mod uses F7. Does not cast a skill.");
			Gravity = SettingsConfig.Hidden.Bind<float>("ExperimentalMovement042", "StallGravityMultiplier", 0.1f, new ConfigDescription("Native gravity multiplier during the original startup hold. Default 0.1 derives ~0.454 m drop over the existing 0.55 s hold at -30 m/s² (~quarter Beetle height). Range .01–1; invalid => .1. Entry brakes Y once, then gravity integrates normally. Prior multiplier restored at original hop time or interruption. Native zero-G remains respected.", (AcceptableValueBase)(object)new GravityRange(), Array.Empty<object>()));
			Hop = SettingsConfig.Hidden.Bind<float>("ExperimentalMovement042", "LaunchVerticalSpeedMetresPerSecond", 12f, new ConfigDescription("v0.4.2 experimental candidate, NOT final balance. Minimum upward motor velocity once at original 0.55 s clip time. Default 12 m/s; range 3–12; invalid => 12. Set 6 to compare baseline strength with partial gravity. Old v0.4.1 hop key ignored. Normal gravity resumes at launch.", (AcceptableValueBase)(object)new HopRange(), Array.Empty<object>()));
			Control = Bind(c, "AerialMovement", "AirControl", 1f, 0.25f, 1f, "Native motor air-control multiplier during this finisher; 1 gives full steering. Restored on exit.");
			Width = Bind(c, "ClawReach071", "Width", 5.5f, 0.5f, 8f, "Metres across horizontal aim: 110% of the verified native 5 m SwingJump width.");
			Rear = Bind(c, "ClawGeometry", "RearReach", 2f, 0.25f, 6f, "Metres behind origin.");
			Front = Bind(c, "ClawReach071", "FrontReach", 9.75f, 0.25f, 12f, "Metres in front of the shared core + 0.5 m origin. Body-relative forward edge 10.25 m, about 110% of native SwingJump 9.318 m.");
			Below = Bind(c, "ClawReach071", "BelowOrigin", 8.65f, 0.25f, 12f, "Downward metres below body core. Default 8.65 m is about 110.3% of native SwingJump downward reach from the static native core (7.839 m). See collision report for reference-frame and swept-shape limits.");
			RearAbove = Bind(c, "ClawGeometry", "RearAboveOrigin", 0.5f, 0f, 4f, "Rear height above origin.");
			FrontAbove = Bind(c, "ClawGeometry", "FrontAboveOrigin", 2f, 0.25f, 6f, "Front height above origin; clamped at least .25 m taller than rear.");
			SideOverlap = Bind(c, "ClawGeometry042", "SideOverlapFraction", 0.005f, 0.001f, 0.4f, "Each side reaches this fraction of total width past centre. Default gives 1 cm beyond centre at 2 m width. Technical overlap seam, not a dimension inferred from the unavailable sketch.");
			CentreWidth = Bind(c, "ClawGeometry042", "CentreWidthFraction", 1f, 0.1f, 1f, "Default retains existing lower/rear box width. Split front into left/right without inventing new exterior dimensions. Exact sketch fit unverified.");
			DepthOverlap = Bind(c, "ClawGeometry042", "DepthOverlapMetres", 0.01f, 0.001f, 1f, "Technical 1 cm overlap at old front/rear seam. Side boxes begin behind origin; central box ends in front. Clamped within existing reaches.");
			RearExtension = SettingsConfig.Hidden.Bind<float>("ClawGeometry043", "RearExtensionMetres", 0.35f, new ConfigDescription("Additional reach along negative attack-local Z, from the central/lower rear face only. World metres. Default .35; safe range 0–.75; 0 restores v0.4.2 geometry. No change to the origin, front or side boxes.", (AcceptableValueBase)(object)new RearExtensionRange(), Array.Empty<object>()));
		}

		public ClawExpansion Expansion()
		{
			return new ClawExpansion(ReachHorizontal081.Value, ReachDown081.Value, ReachUp081.Value);
		}

		public ClawGeometry Geometry()
		{
			return new ClawGeometry(Width.Value, Rear.Value, Front.Value, Below.Value, RearAbove.Value, Mathf.Max(FrontAbove.Value, RearAbove.Value + 0.25f), SideOverlap.Value, CentreWidth.Value, DepthOverlap.Value, RearExtension.Value).Expanded(Expansion());
		}
	}
	public sealed class AudioCues
	{
		private bool cast;

		private bool swipe;

		private bool closed;

		public bool Cast()
		{
			if (closed || cast)
			{
				return false;
			}
			cast = true;
			return true;
		}

		public bool Swipe(float progress, float start, float end)
		{
			if (closed || swipe || progress < start)
			{
				return false;
			}
			swipe = true;
			return progress < end;
		}

		public void Close()
		{
			closed = true;
		}
	}
	public static class BlendTiming
	{
		public static float Bound(float v, float fallback)
		{
			if (!float.IsNaN(v) && !float.IsInfinity(v))
			{
				return Math.Max(0.02f, Math.Min(0.25f, v));
			}
			return fallback;
		}

		private static float Smooth(float x)
		{
			x = Math.Max(0f, Math.Min(1f, x));
			return x * x * (3f - 2f * x);
		}

		public static float Weight(float time, float duration, float enter, float exit)
		{
			return Math.Min(Smooth(time / enter), Smooth((duration - time) / exit));
		}

		public static float InterruptWeight(float startWeight, float time, float duration)
		{
			return startWeight * (1f - Smooth(time / duration));
		}
	}
	public static class Brand
	{
		public const float ExitTolerance = 0.5f;

		public static BuffDef PinkBuff;

		public static BuffDef RedBuff;

		public static readonly Color PinkColor = new Color(1f, 0.45f, 0.7f);

		public static readonly Color RedColor = new Color(1f, 0.12f, 0.08f);

		private static readonly Dictionary<CharacterBody, float> entered = new Dictionary<CharacterBody, float>();

		private static bool iconsSet;

		public static BuffDef[] Create()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			PinkBuff = Make("Reap what you sow (pink)", PinkColor);
			RedBuff = Make("Reap what you sow", RedColor);
			BrandMoveSpeedPatch.PinkBuff = PinkBuff;
			BrandMoveSpeedPatch.RedBuff = RedBuff;
			return (BuffDef[])(object)new BuffDef[2] { PinkBuff, RedBuff };
		}

		private static BuffDef Make(string name, Color color)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			BuffDef obj = ScriptableObject.CreateInstance<BuffDef>();
			((Object)obj).name = name;
			obj.buffColor = color;
			obj.canStack = false;
			obj.isDebuff = false;
			obj.isCooldown = false;
			obj.isHidden = false;
			return obj;
		}

		public static void EnsureIcons()
		{
			if (iconsSet)
			{
				return;
			}
			try
			{
				BuffDef soulBranded = Buffs.SoulBranded;
				if (Object.op_Implicit((Object)(object)soulBranded) && Object.op_Implicit((Object)(object)soulBranded.iconSprite))
				{
					if (Object.op_Implicit((Object)(object)PinkBuff) && !Object.op_Implicit((Object)(object)PinkBuff.iconSprite))
					{
						PinkBuff.iconSprite = soulBranded.iconSprite;
					}
					if (Object.op_Implicit((Object)(object)RedBuff) && !Object.op_Implicit((Object)(object)RedBuff.iconSprite))
					{
						RedBuff.iconSprite = soulBranded.iconSprite;
					}
					iconsSet = true;
				}
			}
			catch
			{
				iconsSet = true;
			}
		}

		public static bool Pink(CharacterBody b)
		{
			if (Object.op_Implicit((Object)(object)PinkBuff) && Object.op_Implicit((Object)(object)b))
			{
				return b.HasBuff(PinkBuff);
			}
			return false;
		}

		public static bool Red(CharacterBody b)
		{
			if (Object.op_Implicit((Object)(object)RedBuff) && Object.op_Implicit((Object)(object)b))
			{
				return b.HasBuff(RedBuff);
			}
			return false;
		}

		public static int StageFor(float seconds, float litany)
		{
			if (float.IsNaN(seconds) || litany <= 0f)
			{
				return 0;
			}
			if (seconds >= litany - 0.5f)
			{
				return 2;
			}
			if (seconds >= litany * 0.5f)
			{
				return 1;
			}
			return 0;
		}

		private static void Remove(CharacterBody b, BuffDef d)
		{
			if (!Object.op_Implicit((Object)(object)d))
			{
				return;
			}
			b.ClearTimedBuffs(d);
			for (int i = 0; i < 16; i++)
			{
				if (!b.HasBuff(d))
				{
					break;
				}
				b.RemoveBuff(d);
			}
		}

		private static void ClearAll(CharacterBody b)
		{
			Remove(b, PinkBuff);
			Remove(b, RedBuff);
		}

		private static void Show(CharacterBody b, int stage)
		{
			if (stage == 1 && !b.HasBuff(PinkBuff))
			{
				b.AddBuff(PinkBuff);
			}
			if (stage == 2 && !b.HasBuff(RedBuff))
			{
				Remove(b, PinkBuff);
				b.AddBuff(RedBuff);
			}
		}

		public static void ServerTick(Action<string> log)
		{
			if (!NetworkServer.active)
			{
				entered.Clear();
			}
			else
			{
				if (!Object.op_Implicit((Object)(object)PinkBuff) || !Object.op_Implicit((Object)(object)RedBuff))
				{
					return;
				}
				EnsureIcons();
				float litanyDuration = Settings.LitanyDuration;
				ReadOnlyCollection<CharacterBody> readOnlyInstancesList = CharacterBody.readOnlyInstancesList;
				for (int i = 0; i < readOnlyInstancesList.Count; i++)
				{
					CharacterBody val = readOnlyInstancesList[i];
					if (!Object.op_Implicit((Object)(object)val) || !AcolyteRebalance.Plugin.IsAcolyteBody(val))
					{
						continue;
					}
					float value2;
					if (HarvesterBalance.IsHarvester(val))
					{
						if (!entered.TryGetValue(val, out var value))
						{
							entered[val] = Time.fixedTime;
							ClearAll(val);
							log?.Invoke("BRAND reset: " + val.GetDisplayName() + " entered Anima Harvester");
						}
						else
						{
							Show(val, StageFor(Time.fixedTime - value, litanyDuration));
						}
					}
					else if (entered.TryGetValue(val, out value2))
					{
						entered.Remove(val);
						float seconds = Time.fixedTime - value2;
						int num = StageFor(seconds, litanyDuration);
						ClearAll(val);
						switch (num)
						{
						case 2:
							val.AddTimedBuff(RedBuff, Settings.RedBrandDuration);
							break;
						case 1:
							val.AddTimedBuff(PinkBuff, Settings.PinkBrandDuration);
							break;
						}
						log?.Invoke("BRAND left Anima Harvester after " + seconds.ToString("0.00") + "s stage=" + num);
					}
				}
				if (entered.Count <= 0)
				{
					return;
				}
				List<CharacterBody> list = null;
				foreach (CharacterBody key in entered.Keys)
				{
					if (!Object.op_Implicit((Object)(object)key))
					{
						(list ?? (list = new List<CharacterBody>())).Add(key);
					}
				}
				if (list == null)
				{
					return;
				}
				foreach (CharacterBody item in list)
				{
					entered.Remove(item);
				}
			}
		}

		public static void Clear()
		{
			entered.Clear();
		}
	}
	public static class BrandRecovery
	{
		public const float NativeGraceLifesteal = 0.065f;

		private static bool installed;

		private static readonly Dictionary<CharacterBody, bool> drainHeld = new Dictionary<CharacterBody, bool>();

		public static void Install()
		{
			if (!installed)
			{
				installed = true;
				GlobalEventManager.onServerDamageDealt += Dealt;
			}
		}

		public static void Uninstall()
		{
			if (installed)
			{
				installed = false;
				GlobalEventManager.onServerDamageDealt -= Dealt;
				drainHeld.Clear();
			}
		}

		public static float Fraction(CharacterBody b)
		{
			if (Brand.Red(b))
			{
				return Settings.RedBrandRecovery;
			}
			if (Brand.Pink(b))
			{
				return Settings.PinkBrandRecovery;
			}
			return 0f;
		}

		public static float Lifesteal(CharacterBody b)
		{
			if (Brand.Red(b))
			{
				return Settings.RedBrandLifesteal;
			}
			if (Brand.Pink(b))
			{
				return Settings.PinkBrandLifesteal;
			}
			return 0f;
		}

		private static bool InForm(CharacterBody b)
		{
			AcolyteFormController component = ((Component)b).GetComponent<AcolyteFormController>();
			if (Object.op_Implicit((Object)(object)component))
			{
				return component.inTransformation;
			}
			return false;
		}

		private static bool Favor(CharacterBody b)
		{
			if (Object.op_Implicit((Object)(object)b.inventory))
			{
				return b.inventory.GetItemCountEffective(Items.ConvertHealingToAttackSpeed) > 0;
			}
			return false;
		}

		private static void Dealt(DamageReport report)
		{
			if (!NetworkServer.active || report == null)
			{
				return;
			}
			try
			{
				Taken(report);
			}
			catch (Exception)
			{
			}
			try
			{
				Steal(report);
			}
			catch (Exception)
			{
			}
		}

		private static void Taken(DamageReport report)
		{
			CharacterBody victimBody = report.victimBody;
			if (Object.op_Implicit((Object)(object)victimBody) && AcolyteRebalance.Plugin.IsAcolyteBody(victimBody) && Object.op_Implicit((Object)(object)victimBody.healthComponent) && victimBody.healthComponent.alive && !InForm(victimBody))
			{
				float num = Fraction(victimBody);
				if (!(num <= 0f) && !(report.damageDealt <= 0f))
				{
					victimBody.healthComponent.GrantRegainableHealthServer(report.damageDealt * num);
				}
			}
		}

		private static void Steal(DamageReport report)
		{
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Expected O, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			CharacterBody attackerBody = report.attackerBody;
			if (!Object.op_Implicit((Object)(object)attackerBody) || !AcolyteRebalance.Plugin.IsAcolyteBody(attackerBody) || !Object.op_Implicit((Object)(object)attackerBody.healthComponent) || !attackerBody.healthComponent.alive || !Object.op_Implicit((Object)(object)attackerBody.mainHurtBox) || InForm(attackerBody) || report.damageInfo == null || !((DamageTypeCombo)(ref report.damageInfo.damageType)).IsDamageSourceSkillBased)
			{
				return;
			}
			float num = Lifesteal(attackerBody);
			if (num <= 0f || attackerBody.healthComponent.regainableHealth <= 0f)
			{
				return;
			}
			float num2 = report.damageDealt * num * report.damageInfo.procCoefficient;
			if (!(num2 <= 0f) && Object.op_Implicit((Object)(object)OrbManager.instance))
			{
				Vector3 position = report.damageInfo.position;
				if (Favor(attackerBody))
				{
					OrbManager.instance.AddOrb((Orb)(object)new FavorLifestealOrb
					{
						origin = position,
						target = attackerBody.mainHurtBox,
						regainHealthAmount = num2
					});
				}
				else
				{
					OrbManager.instance.AddOrb((Orb)new RegainableHealthHealOrb
					{
						origin = position,
						target = attackerBody.mainHurtBox,
						regainHealthAmount = num2
					});
				}
			}
		}

		public static void ServerTick()
		{
			if (!NetworkServer.active)
			{
				drainHeld.Clear();
				return;
			}
			ReadOnlyCollection<CharacterBody> readOnlyInstancesList = CharacterBody.readOnlyInstancesList;
			for (int i = 0; i < readOnlyInstancesList.Count; i++)
			{
				CharacterBody val = readOnlyInstancesList[i];
				if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.healthComponent) && AcolyteRebalance.Plugin.IsAcolyteBody(val))
				{
					bool flag = Brand.Pink(val) || Brand.Red(val);
					drainHeld.TryGetValue(val, out var value);
					if (flag && !value)
					{
						HealthComponent healthComponent = val.healthComponent;
						int regainableHealthDepleteDisabledCounter = healthComponent.regainableHealthDepleteDisabledCounter;
						healthComponent.regainableHealthDepleteDisabledCounter = regainableHealthDepleteDisabledCounter + 1;
						drainHeld[val] = true;
					}
					else if (!flag && value)
					{
						HealthComponent healthComponent2 = val.healthComponent;
						int regainableHealthDepleteDisabledCounter = healthComponent2.regainableHealthDepleteDisabledCounter;
						healthComponent2.regainableHealthDepleteDisabledCounter = regainableHealthDepleteDisabledCounter - 1;
						drainHeld.Remove(val);
					}
				}
			}
			if (drainHeld.Count <= 0)
			{
				return;
			}
			List<CharacterBody> list = null;
			foreach (CharacterBody key in drainHeld.Keys)
			{
				if (!Object.op_Implicit((Object)(object)key))
				{
					(list ?? (list = new List<CharacterBody>())).Add(key);
				}
			}
			if (list == null)
			{
				return;
			}
			foreach (CharacterBody item in list)
			{
				drainHeld.Remove(item);
			}
		}
	}
	public sealed class FavorLifestealOrb : Orb
	{
		public float regainHealthAmount;

		private const float speed = 100f;

		public override void Begin()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			((Orb)this).duration = Mathf.Max(((Orb)this).distanceToTarget / 100f, 0.01f);
			EffectData val = new EffectData
			{
				origin = base.origin,
				genericFloat = ((Orb)this).duration,
				scale = ((Object.op_Implicit((Object)(object)base.target) && Object.op_Implicit((Object)(object)base.target.healthComponent)) ? (regainHealthAmount / base.target.healthComponent.fullHealth) : 0f)
			};
			val.SetHurtBoxReference(base.target);
			EffectManager.SpawnEffect(OrbStorageUtility.Get("Prefabs/Effects/OrbEffects/HealthOrbEffect"), val, true);
		}

		public override void OnArrival()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)base.target) && Object.op_Implicit((Object)(object)base.target.healthComponent))
			{
				HealthComponent healthComponent = base.target.healthComponent;
				float num = Mathf.Min(new float[3] { regainHealthAmount, healthComponent.regainableHealth, healthComponent.missingHealth });
				if (!(num <= 0f))
				{
					healthComponent.SpendRegainableHealthServer(num);
					ProcChainMask val = default(ProcChainMask);
					((ProcChainMask)(ref val)).AddProc((ProcType)31);
					healthComponent.Heal(num, val, true);
				}
			}
		}
	}
	public sealed class ChargeLedger
	{
		private sealed class Charge
		{
			public float Seconds;

			public float Elapsed;
		}

		public const float Native = float.NaN;

		private readonly List<Charge> spent = new List<Charge>();

		private readonly Queue<float> pending = new Queue<float>();

		public int Count => spent.Count;

		public float ActiveSeconds
		{
			get
			{
				if (spent.Count <= 0)
				{
					return float.NaN;
				}
				return spent[spent.Count - 1].Seconds;
			}
		}

		public bool ActiveIsNative => float.IsNaN(ActiveSeconds);

		public void MarkContextual(float seconds)
		{
			if (!float.IsNaN(seconds) && !float.IsInfinity(seconds) && !(seconds <= 0f))
			{
				pending.Enqueue(seconds);
			}
		}

		public bool Reconcile(int missing, float stopwatch, out float restored)
		{
			restored = stopwatch;
			if (missing < 0)
			{
				missing = 0;
			}
			if (float.IsNaN(stopwatch) || float.IsInfinity(stopwatch) || stopwatch < 0f)
			{
				stopwatch = 0f;
			}
			bool result = false;
			if (missing > spent.Count)
			{
				if (spent.Count > 0)
				{
					spent[spent.Count - 1].Elapsed = stopwatch;
				}
				while (spent.Count < missing)
				{
					spent.Add(new Charge
					{
						Seconds = ((pending.Count > 0) ? pending.Dequeue() : float.NaN),
						Elapsed = 0f
					});
				}
				restored = 0f;
				result = true;
			}
			else if (missing < spent.Count)
			{
				while (spent.Count > missing)
				{
					spent.RemoveAt(spent.Count - 1);
				}
				restored = ((spent.Count > 0) ? spent[spent.Count - 1].Elapsed : 0f);
				result = true;
			}
			pending.Clear();
			return result;
		}

		public void Seed(int count)
		{
			while (spent.Count < count)
			{
				spent.Add(new Charge
				{
					Seconds = float.NaN,
					Elapsed = 0f
				});
			}
		}

		public void Clear()
		{
			spent.Clear();
			pending.Clear();
		}
	}
	public sealed class ClawClock
	{
		public readonly float Rate;

		public readonly float StartupRate;

		public readonly float TailFrom;

		public readonly float TailRate;

		public ClawClock(float attackSpeed, float startupRate = 1.3f, float tailFrom = float.PositiveInfinity, float tailRate = 1f)
		{
			Rate = ((float.IsNaN(attackSpeed) || float.IsInfinity(attackSpeed) || attackSpeed <= 0f) ? 1f : Math.Max(0.01f, attackSpeed));
			StartupRate = ((float.IsNaN(startupRate) || float.IsInfinity(startupRate)) ? 1.3f : Math.Max(1f, Math.Min(1.3f, startupRate)));
			TailFrom = ((float.IsNaN(tailFrom) || tailFrom < 0f) ? float.PositiveInfinity : tailFrom);
			TailRate = ((float.IsNaN(tailRate) || float.IsInfinity(tailRate) || tailRate <= 0f) ? 1f : Math.Max(0.05f, Math.Min(1f, tailRate)));
		}

		public float Source(float elapsed, float clipDuration)
		{
			float num = clipDuration * SwipeTiming.ExportedFrames.Start;
			float num2 = Math.Max(0f, elapsed) * Rate;
			float num3 = num / StartupRate;
			return Math.Min(DashTiming.Tail((num2 <= num3) ? (num2 * StartupRate) : (num + num2 - num3), TailFrom, TailRate), clipDuration);
		}

		public float ElapsedAtSource(float source, float clipDuration)
		{
			source = DashTiming.Untail(source, TailFrom, TailRate);
			float num = clipDuration * SwipeTiming.ExportedFrames.Start;
			return ((source <= num) ? (source / StartupRate) : (num / StartupRate + source - num)) / Rate;
		}

		public float Duration(float clipDuration)
		{
			return ElapsedAtSource(clipDuration, clipDuration);
		}

		public static bool CrossedSwipe(float previous, float current, float start, float end)
		{
			if (previous < end && current >= start)
			{
				return current >= previous;
			}
			return false;
		}
	}
	public sealed class ClawCombat : IDisposable
	{
		public const float DamageCoefficient = 8f;

		private readonly CharacterBody attacker;

		private readonly float damage;

		private readonly bool crit;

		private readonly Func<bool> active;

		private readonly Action<GameObject> impact;

		private readonly Action<string> log;

		private readonly Action<Vector3> feedback;

		private readonly float upwardImpulse;

		private readonly HashSet<HealthComponent> attempted = new HashSet<HealthComponent>();

		private bool disposed;

		private bool utilityGiven;

		public static Action<CharacterBody, Vector3> EchoImpact;

		private static readonly Dictionary<CharacterBody, float> lastEchoSound = new Dictionary<CharacterBody, float>();

		public int Accepted { get; private set; }

		public int Expunged { get; private set; }

		public ClawCombat(CharacterBody attacker, float coefficient, Func<bool> active, Action<GameObject> impact, Action<string> log, Action<Vector3> feedback = null, float upwardImpulse = 0f)
		{
			this.attacker = attacker;
			this.active = active;
			this.impact = impact;
			this.log = log;
			this.feedback = feedback;
			this.upwardImpulse = ClawVfx.Bound(upwardImpulse, 1350f, 0f, 1600f);
			damage = attacker.damage * ClawVfx.Bound(coefficient, 8f, 0f, 100f);
			crit = Util.CheckRoll(attacker.crit, attacker.master);
		}

		public void Hit(HurtBox hurt)
		{
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Invalid comparison between Unknown and I4
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			/