Decompiled source of Emberskald Talents v1.2.45

plugins/EmberskaldTalents.dll

Decompiled 5 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace EmberskaldTalents;

internal static class ArtisanCompat
{
	internal const string Guid = "Dreanegade.Artisan_Mastery";

	internal const string ModName = "Artisan Mastery";

	private const string DualPrefix = "PickaxeDualMiner";

	internal static bool Installed => Chainloader.PluginInfos.ContainsKey("Dreanegade.Artisan_Mastery");

	internal static bool IsDualPick(ItemData w)
	{
		if ((Object)(object)w?.m_dropPrefab != (Object)null)
		{
			return ((Object)w.m_dropPrefab).name.StartsWith("PickaxeDualMiner", StringComparison.Ordinal);
		}
		return false;
	}

	internal static bool IsPickaxe(ItemData w)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Invalid comparison between Unknown and I4
		if (w != null)
		{
			if ((int)w.m_shared.m_skillType != 12)
			{
				return IsDualPick(w);
			}
			return true;
		}
		return false;
	}
}
internal static class Backgrounds
{
	internal enum Style
	{
		AlignedSky,
		Illustration,
		Custom
	}

	internal const float ImgW = 2400f;

	internal const float ImgH = 1350f;

	internal const float MarginX = 240f;

	internal const float MarginY = 135f;

	private static readonly MethodInfo LoadImage = typeof(ImageConversion).GetMethod("LoadImage", new Type[3]
	{
		typeof(Texture2D),
		typeof(byte[]),
		typeof(bool)
	});

	private static readonly Dictionary<string, (Texture2D Texture, Style Style)> cache = new Dictionary<string, (Texture2D, Style)>();

	internal static string CustomFolder => Path.Combine(Paths.ConfigPath, "EmberskaldTalents", "Backgrounds");

	private static Texture2D FromBytes(byte[] data)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected O, but got Unknown
		Texture2D val = new Texture2D(2, 2, (TextureFormat)3, false)
		{
			wrapMode = (TextureWrapMode)1,
			hideFlags = (HideFlags)61
		};
		if ((bool)LoadImage.Invoke(null, new object[3] { val, data, true }))
		{
			return val;
		}
		Object.Destroy((Object)(object)val);
		return null;
	}

	private static Texture2D FromResource(string race, string extension)
	{
		using Stream stream = typeof(Backgrounds).Assembly.GetManifestResourceStream("EmberskaldTalents.Backgrounds." + race + extension);
		if (stream == null)
		{
			return null;
		}
		using MemoryStream memoryStream = new MemoryStream();
		stream.CopyTo(memoryStream);
		return FromBytes(memoryStream.ToArray());
	}

	internal static Texture2D Get(string race, out Style style)
	{
		style = Style.AlignedSky;
		if (race == null)
		{
			return null;
		}
		if (cache.TryGetValue(race, out (Texture2D, Style) value))
		{
			style = value.Item2;
			return value.Item1;
		}
		try
		{
			string[] array = new string[3] { ".png", ".jpg", ".jpeg" };
			foreach (string text in array)
			{
				string path = Path.Combine(CustomFolder, race + text);
				if (File.Exists(path))
				{
					Texture2D val = FromBytes(File.ReadAllBytes(path));
					if ((Object)(object)val != (Object)null)
					{
						style = Style.Custom;
						cache[race] = (val, style);
						return val;
					}
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Custom talent background for " + race + ": " + ex.Message));
		}
		Texture2D val2 = null;
		try
		{
			val2 = FromResource(race, ".art.jpg");
		}
		catch (Exception ex2)
		{
			Plugin.Log.LogWarning((object)("Illustrated talent background for " + race + ": " + ex2.Message));
		}
		if ((Object)(object)val2 != (Object)null)
		{
			style = Style.Illustration;
		}
		else
		{
			try
			{
				val2 = FromResource(race, ".jpg");
			}
			catch (Exception ex3)
			{
				Plugin.Log.LogWarning((object)("Talent background for " + race + ": " + ex3.Message));
			}
		}
		cache[race] = (val2, style);
		return val2;
	}

	internal static Vector2 IllustrationAnchor(string race)
	{
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		return (Vector2)(race switch
		{
			"frostborn" => new Vector2(0.5382775f, 0.40063763f), 
			"dwegir" => new Vector2(0.4958134f, 0.54835284f), 
			"wildwood" => new Vector2(0.4348086f, 0.4410202f), 
			"hearthfolk" => new Vector2(0.50119615f, 0.37407014f), 
			"runeblood" => new Vector2(0.5f, 0.38257173f), 
			"mirewalkers" => new Vector2(0.5f, 0.34750265f), 
			"ashkin" => new Vector2(0.5f, 0.35281616f), 
			_ => new Vector2(77f / 152f, 0.46971306f), 
		});
	}
}
internal static class ChestSize
{
	[HarmonyPatch(typeof(Container), "Awake")]
	private static class OnAwake
	{
		private static void Prefix(Container __instance)
		{
			FromZdo(__instance);
		}
	}

	[HarmonyPatch(typeof(Container), "Load")]
	private static class OnLoad
	{
		private static void Prefix(Container __instance)
		{
			FromZdo(__instance);
		}
	}

	[HarmonyPatch(typeof(Piece), "SetCreator")]
	private static class OnBuilt
	{
		private static void Postfix(Piece __instance, long uid)
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || uid != localPlayer.GetPlayerID())
			{
				return;
			}
			int num = Mathf.RoundToInt(Talents.V("chest.size"));
			if (num > 0)
			{
				Container component = ((Component)__instance).GetComponent<Container>();
				ZNetView component2 = ((Component)__instance).GetComponent<ZNetView>();
				if (!((Object)(object)component == (Object)null) && !((Object)(object)component2 == (Object)null) && component2.IsValid() && component2.IsOwner() && Bigger(Utils.GetPrefabName(((Component)__instance).gameObject), num, component.m_width, component.m_height, out var nw, out var nh))
				{
					component2.GetZDO().Set("EST_ChestW", nw);
					component2.GetZDO().Set("EST_ChestH", nh);
					Apply(component, nw, nh);
				}
			}
		}
	}

	private const string KeyW = "EST_ChestW";

	private const string KeyH = "EST_ChestH";

	private static bool Bigger(string prefab, int rank, int w, int h, out int nw, out int nh)
	{
		nw = w;
		nh = h;
		switch (prefab)
		{
		case "piece_chest_wood":
			if (rank >= 1)
			{
				nw = w + 1;
			}
			break;
		case "piece_chest":
			if (rank >= 2)
			{
				nh = h + 1;
			}
			break;
		case "piece_chest_warderobe":
			if (rank >= 3)
			{
				nw = w + 2;
			}
			break;
		}
		nw = Mathf.Min(nw, 8);
		if (nw == w)
		{
			return nh != h;
		}
		return true;
	}

	private static void Apply(Container c, int w, int h)
	{
		c.m_width = w;
		c.m_height = h;
		Inventory inventory = c.GetInventory();
		if (inventory != null && (inventory.GetWidth() != w || inventory.GetHeight() != h))
		{
			Traverse.Create((object)inventory).Field("m_width").SetValue((object)w);
			Traverse.Create((object)inventory).Field("m_height").SetValue((object)h);
		}
	}

	private static void FromZdo(Container c)
	{
		ZNetView component = ((Component)c).GetComponent<ZNetView>();
		ZDO val = (((Object)(object)component != (Object)null) ? component.GetZDO() : null);
		if (val != null)
		{
			int num = val.GetInt("EST_ChestW", 0);
			int num2 = val.GetInt("EST_ChestH", 0);
			if (num > 0 && num2 > 0)
			{
				Apply(c, Mathf.Max(num, c.m_width), Mathf.Max(num2, c.m_height));
			}
		}
	}
}
internal static class Durability
{
	internal sealed class Snap
	{
		public readonly List<KeyValuePair<ItemData, float>> Items = new List<KeyValuePair<ItemData, float>>();
	}

	[HarmonyPatch]
	private static class WeaponDrain
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			string[] array = new string[4] { "DoMeleeAttack", "DoAreaAttack", "DoNonAttack", "ProjectileAttackTriggered" };
			foreach (string text in array)
			{
				MethodInfo methodInfo = AccessTools.Method(typeof(Attack), text, (Type[])null, (Type[])null);
				if (methodInfo != null)
				{
					yield return methodInfo;
				}
			}
		}

		private static void Prefix(Attack __instance, out Snap __state)
		{
			__state = null;
			try
			{
				__state = Take((Character)(object)AttackOwner.Invoke(__instance), armor: false);
			}
			catch (Exception)
			{
			}
		}

		private static void Postfix(Snap __state)
		{
			Refund(__state, armor: false);
		}
	}

	[HarmonyPatch(typeof(Humanoid), "BlockAttack")]
	private static class BlockDrain
	{
		private static void Prefix(Humanoid __instance, out Snap __state)
		{
			__state = Take((Character)(object)__instance, armor: false);
		}

		private static void Postfix(Snap __state)
		{
			Refund(__state, armor: false);
		}
	}

	[HarmonyPatch(typeof(Player), "DamageArmorDurability")]
	private static class ArmorDrain
	{
		private static void Prefix(Player __instance, out Snap __state)
		{
			__state = Take((Character)(object)__instance, armor: true);
		}

		private static void Postfix(Snap __state)
		{
			Refund(__state, armor: true);
		}
	}

	private static readonly FieldRef<Attack, Humanoid> AttackOwner = AccessTools.FieldRefAccess<Attack, Humanoid>("m_character");

	internal static bool IsStaff(ItemData it)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Invalid comparison between Unknown and I4
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Invalid comparison between Unknown and I4
		if ((int)it.m_shared.m_skillType != 9)
		{
			return (int)it.m_shared.m_skillType == 10;
		}
		return true;
	}

	private static float Keep(ItemData it, bool armor)
	{
		return Mathf.Clamp01(armor ? Talents.V("dur.armor") : (Talents.V("dur.weapon") + (IsStaff(it) ? Talents.V("dur.staff") : 0f)));
	}

	private static bool IsArmor(ItemData it)
	{
		//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_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Invalid comparison between Unknown and I4
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Invalid comparison between Unknown and I4
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Invalid comparison between Unknown and I4
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Invalid comparison between Unknown and I4
		ItemType itemType = it.m_shared.m_itemType;
		if ((int)itemType != 6 && (int)itemType != 7 && (int)itemType != 11)
		{
			return (int)itemType == 17;
		}
		return true;
	}

	private static Snap Take(Character c, bool armor)
	{
		Player val = (Player)(object)((c is Player) ? c : null);
		if ((Object)(object)val == (Object)null || (Object)(object)val != (Object)(object)Player.m_localPlayer || !Progress.Loaded)
		{
			return null;
		}
		if (armor ? (Talents.V("dur.armor") <= 0f) : (Talents.V("dur.weapon") + Talents.V("dur.staff") <= 0f))
		{
			return null;
		}
		Snap snap = new Snap();
		foreach (ItemData allItem in ((Humanoid)val).GetInventory().GetAllItems())
		{
			if (allItem.m_equipped && allItem.m_shared.m_useDurability && IsArmor(allItem) == armor && Keep(allItem, armor) > 0f)
			{
				snap.Items.Add(new KeyValuePair<ItemData, float>(allItem, allItem.m_durability));
			}
		}
		if (snap.Items.Count <= 0)
		{
			return null;
		}
		return snap;
	}

	private static void Refund(Snap snap, bool armor)
	{
		if (snap == null)
		{
			return;
		}
		foreach (KeyValuePair<ItemData, float> item in snap.Items)
		{
			float num = item.Value - item.Key.m_durability;
			if (num > 0f)
			{
				ItemData key = item.Key;
				key.m_durability += num * Keep(item.Key, armor);
			}
		}
	}
}
internal static class Effects
{
	[HarmonyPatch(typeof(Character), "Damage")]
	private static class DealDamage
	{
		private unsafe static void Prefix(Character __instance, HitData hit)
		{
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Expected O, but got Unknown
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Invalid comparison between Unknown and I4
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Invalid comparison between Unknown and I4
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Invalid comparison between Unknown and I4
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Invalid comparison between Unknown and I4
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Invalid comparison between Unknown and I4
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Invalid comparison between Unknown and I4
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Invalid comparison between Unknown and I4
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Invalid comparison between Unknown and I4
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Invalid comparison between Unknown and I4
			//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0457: Unknown result type (might be due to invalid IL or missing references)
			//IL_0459: Invalid comparison between Unknown and I4
			//IL_0471: Unknown result type (might be due to invalid IL or missing references)
			//IL_0473: Invalid comparison between Unknown and I4
			//IL_05b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b9: Invalid comparison between Unknown and I4
			//IL_077f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0781: Invalid comparison between Unknown and I4
			//IL_083e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0840: Invalid comparison between Unknown and I4
			//IL_0a48: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a4b: Invalid comparison between Unknown and I4
			//IL_0aec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a2e: Unknown result type (might be due to invalid IL or missing references)
			//IL_09b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c08: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c0b: Invalid comparison between Unknown and I4
			//IL_0ba5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ba7: Invalid comparison between Unknown and I4
			//IL_0b54: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b56: Invalid comparison between Unknown and I4
			//IL_0abc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cdb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d37: Unknown result type (might be due to invalid IL or missing references)
			if (hit == null || !Progress.Loaded || splashing)
			{
				return;
			}
			Character attacker = hit.GetAttacker();
			if ((Object)(object)attacker != (Object)null && !attacker.IsPlayer() && attacker.IsTamed())
			{
				ZNetView component = ((Component)attacker).GetComponent<ZNetView>();
				if ((Object)(object)component != (Object)null && component.IsValid() && component.IsOwner() && BeastcallOn(component))
				{
					float num = V("beast.strength");
					if (num > 0f)
					{
						((DamageTypes)(ref hit.m_damage)).Modify(1f + num);
					}
				}
				if (FollowsLocalHunter(((Component)attacker).GetComponent<MonsterAI>()) && marked.TryGetValue(__instance, out var value) && Time.time < value)
				{
					((DamageTypes)(ref hit.m_damage)).Modify(1f + V("hunt.wounds"));
				}
				return;
			}
			if (!IsLocal(attacker) || (Object)(object)__instance == (Object)(object)attacker || __instance.IsDead())
			{
				return;
			}
			Player val = (Player)attacker;
			float time = Time.time;
			SkillType val2 = hit.m_skill;
			bool flag = !hit.m_ranged && ArtisanCompat.IsDualPick(((Humanoid)val).GetCurrentWeapon());
			if (flag)
			{
				val2 = (SkillType)12;
			}
			bool flag2 = IsSpell(val2);
			bool flag3 = !flag2 && (hit.m_ranged || (int)val2 == 8 || (int)val2 == 14);
			bool flag4 = !flag2 && !flag3;
			bool flag5 = Talents.RaceWeapon(flag ? null : ((Humanoid)val).GetCurrentWeapon(), val2);
			bool flag6 = (int)val2 == 8;
			bool flag7 = (int)__instance.m_faction == 3;
			bool flag8 = IsAnimal(__instance);
			float healthPercentage = __instance.GetHealthPercentage();
			ItemData currentWeapon = ((Humanoid)val).GetCurrentWeapon();
			float num2 = (flag2 ? V("dmg.spell") : (flag3 ? V("dmg.ranged") : V("dmg.melee")));
			if (flag5)
			{
				num2 += V("dmg.weapon");
			}
			num2 += V("dmg.skill." + ((object)(*(SkillType*)(&val2))/*cast due to .constrained prefix*/).ToString());
			num2 += V("dmg.all");
			if (runeMarks.TryGetValue(__instance, out var value2) && value2 > time)
			{
				num2 += V("runesight.mark");
			}
			if ((int)val2 == 2 || (int)val2 == 3 || (int)val2 == 5)
			{
				num2 += V("dmg.light");
			}
			if (hit.m_ranged && (int)val2 == 5)
			{
				num2 += V("dmg.throw");
			}
			if (Night)
			{
				num2 += V("dmg.night");
			}
			if (Talents.AtHome(val))
			{
				num2 += V("dmg.home");
			}
			if (flag6)
			{
				if (Night)
				{
					num2 += V("bow.night");
				}
				if (Talents.AtHome(val))
				{
					num2 += V("bow.home");
				}
			}
			if (RacesBridge.Raging)
			{
				num2 += V("dmg.rage");
			}
			if (nearBed40)
			{
				num2 += V("dmg.nearBed");
			}
			if (currentWeapon != null && currentWeapon.m_crafterID == val.GetPlayerID() && currentWeapon.m_crafterID != 0L)
			{
				num2 += V("dmg.crafted");
			}
			num2 += CookBonus(val);
			if ((int)val2 == 1 && Foods.Invoke(val).Count >= 3)
			{
				num2 += V("sword.threeMeals");
			}
			if (healthPercentage < 0.3f)
			{
				num2 += V("dmg.execute");
			}
			if (AshBurning(val))
			{
				num2 += V("cap.emberborn");
			}
			if (time < providerUntil)
			{
				num2 += V("cap.providerWrath");
			}
			if (FromStealth(val))
			{
				num2 += V("dmg.ambush");
			}
			if (time < packUntil)
			{
				num2 += V("cap.packLeader") * (float)packStacks;
			}
			if (flag2 && time < runeMarkerUntil && Vector3.Distance(((Component)val).transform.position, runeMarker) <= 20f)
			{
				num2 += V("cap.allSeeing");
			}
			if (marked.TryGetValue(__instance, out var value3) && time < value3)
			{
				num2 += V("cap.mark") + V("hunt.wounds");
			}
			if (sundered.TryGetValue(__instance, out var value4) && time < value4)
			{
				num2 += V("sunder");
			}
			if (flag7)
			{
				num2 += V("undead.pct");
			}
			if (flag7 && flag5 && (int)val2 == 2)
			{
				num2 += V("cap.cryptReaper");
			}
			bool flag9 = flag5 && flag4 && (int)val2 == 3;
			if (flag9 && __instance.IsStaggering())
			{
				num2 += V("cap.guardBreaker");
			}
			int num3;
			if (flag6 && Night && Has("cap.eternalHunt"))
			{
				if (!(time - lastStealth < 3f))
				{
					num3 = ((time - eternalHuntArmed < 30f) ? 1 : 0);
					if (num3 == 0)
					{
						goto IL_04f4;
					}
				}
				else
				{
					num3 = 1;
				}
				num2 += V("cap.eternalHunt");
				eternalHuntArmed = -99f;
				lastStealth = -99f;
			}
			else
			{
				num3 = 0;
			}
			goto IL_04f4;
			IL_04f4:
			float num4 = 1f + num2;
			if (Has("cap.momentum"))
			{
				if (time - momentumSwing > 0.15f)
				{
					momentumCount = ((!(time - momentumLast <= 4f)) ? 1 : (momentumCount + 1));
					momentumLast = time;
					momentumSwing = time;
					momentumProc = momentumCount % 3 == 0;
				}
				if (momentumProc)
				{
					num4 *= 1f + V("cap.momentum");
				}
			}
			if (flag5 && flag4 && Has("cap.slaughter") && ++slaughterCount % 6 == 0)
			{
				num4 *= 1f + V("cap.slaughter");
				RacesBridge.Adrenaline += 8f;
				TalentVfx.Play(__instance.GetCenterPoint(), TalentVfx.Effect.Rage, 0.85f);
			}
			if (Has("cap.veilStrike") && !veilStrikeUsed && RacesBridge.PowerActive(val, "Bogveil"))
			{
				veilStrikeUsed = true;
				num4 *= 2.5f;
				TalentVfx.Play(__instance.GetCenterPoint(), TalentVfx.Effect.Stealth, 0.85f);
				StatusEffect statusEffect = ((Character)val).GetSEMan().GetStatusEffect(StringExtensionMethods.GetStableHashCode("RotR_Bogveil"));
				if ((Object)(object)statusEffect != (Object)null)
				{
					SeTime.Invoke(statusEffect) = Mathf.Max(0f, SeTime.Invoke(statusEffect) - statusEffect.m_ttl * 0.2f);
				}
			}
			float num5 = CritChance + ((Night && flag6) ? V("bow.critNight") : 0f) + (Night ? V("crit.night") : 0f) + (flag2 ? V("crit.spell") : 0f) + ((flag7 && flag5 && (int)val2 == 2 && Has("cap.cryptReaper")) ? 0.15f : 0f) + Professions.CritVs(__instance);
			bool flag10 = (Has("element.followup") && !__instance.IsPlayer() && ((DamageTypes)(ref hit.m_damage)).GetTotalDamage() > 0f && __instance.GetSEMan().HaveStatusEffect(FrostSe)) || Random.value < num5;
			if (flag10)
			{
				num4 *= Plugin.CritMultiplier.Value;
			}
			if (num4 != 1f)
			{
				((DamageTypes)(ref hit.m_damage)).Modify(num4);
			}
			float num6 = V("dmg.blunt");
			if (num6 > 0f)
			{
				hit.m_damage.m_blunt *= 1f + num6;
			}
			if (flag4 && (int)val2 == 3 && Has("cap.forgefire") && !__instance.IsPlayer() && __instance.GetSEMan().HaveStatusEffect(Burning))
			{
				hit.m_damage.m_fire += hit.m_damage.m_blunt * V("cap.forgefire");
			}
			if (flag4)
			{
				hit.m_damage.m_fire += V("fire.add");
				hit.m_damage.m_frost += V("frost.add");
				hit.m_damage.m_lightning += V("lightning.add");
			}
			if (flag7)
			{
				hit.m_damage.m_blunt += V("undead.flat");
			}
			if (flag4 && (int)val2 == 3)
			{
				hit.m_damage.m_blunt += V("club.flat");
			}
			if (flag8)
			{
				hit.m_damage.m_pierce += V("animal.flat");
			}
			hit.m_damage.m_pierce += Professions.FlatDamage(__instance);
			float num7 = V("stagger") + (flag6 ? V("bow.stagger") : 0f) + (flag5 ? V("stagger.weapon") : 0f) + ((flag9 && Has("cap.guardBreaker")) ? 0.3f : 0f);
			if (num7 > 0f)
			{
				hit.m_staggerMultiplier *= 1f + num7;
			}
			float num8 = V("backstab") + (flag5 ? V("backstab.weapon") : 0f);
			if (num8 > 0f)
			{
				hit.m_backstabBonus *= 1f + num8;
			}
			float totalDamage = ((DamageTypes)(ref hit.m_damage)).GetTotalDamage();
			if (flag9 && Has("cap.spreadFlames") && !__instance.IsPlayer() && __instance.GetSEMan().HaveStatusEffect(Burning) && time - splashSwing > 0.15f)
			{
				splashSwing = time;
				if (Splash(val, __instance, 3f, totalDamage * V("cap.spreadFlames"), 0f, 0f) > 0)
				{
					TalentVfx.Play(__instance.GetCenterPoint(), TalentVfx.Effect.Hearthfire, 0.7f);
				}
			}
			if (flag2 && Has("rune.echo") && !__instance.IsPlayer() && time - echoSwing > 0.1f)
			{
				echoSwing = time;
				if (++echoCount % 5 == 0)
				{
					Splash(val, __instance, 3f, 0f, 0f, 0f, totalDamage * V("rune.echo"));
					TalentVfx.Play(__instance.GetCenterPoint(), TalentVfx.Effect.Ward, 1f);
				}
			}
			if (flag5 && flag4 && (int)val2 == 12 && Has("cap.earthshaker") && !__instance.IsPlayer() && time - shakeSwing > 0.15f)
			{
				shakeSwing = time;
				if (++shakeCount % (flag ? 8 : 4) == 0)
				{
					Splash(val, __instance, 4f, 0f, totalDamage * V("cap.earthshaker"), 4f);
					TalentVfx.Play(((Component)__instance).transform.position, TalentVfx.Effect.Forge, 1f);
				}
			}
			if (num3 != 0 || (flag6 && Night && flag10 && Has("cap.starlit")))
			{
				TalentVfx.ArrowImpact(__instance.GetCenterPoint());
			}
			if (flag10)
			{
				if (Has("cap.bloodletting"))
				{
					RacesBridge.Adrenaline += 3f;
					((Character)val).Heal(2f, true);
				}
				if (flag6 && Night && Has("cap.starlit"))
				{
					hit.m_damage.m_frost += 1f;
				}
				if (flag5 && (int)val2 == 3 && Has("cap.searing"))
				{
					hit.m_damage.m_fire += totalDamage * 0.25f;
				}
				if (flag2 && Has("cap.runicOverload"))
				{
					((Character)val).AddEitr(lastEitrCost * V("cap.runicOverload"));
				}
			}
			if (flag5 && (int)val2 == 2)
			{
				if (Random.value < V("poison.chance"))
				{
					hit.m_damage.m_poison += totalDamage * 0.5f;
				}
				BaseAI component2 = ((Component)__instance).GetComponent<BaseAI>();
				if (Has("cap.silentDeath") && (Object)(object)component2 != (Object)null && !component2.IsAlerted())
				{
					((Character)val).AddStamina(V("cap.silentDeath"));
				}
			}
			if ((int)val2 == 10)
			{
				float num9 = V("siphon");
				if (num9 > 0f)
				{
					((Character)val).Heal(totalDamage * num9, true);
				}
			}
			if (flag4)
			{
				float num10 = V("lifesteal.melee");
				if (num10 > 0f)
				{
					((Character)val).Heal(totalDamage * num10, true);
				}
			}
			bool flag11 = totalDamage > 0f && !__instance.IsPlayer() && !__instance.IsTamed() && BaseAI.IsEnemy((Character)(object)val, __instance);
			if (flag11 && (Has("hunt.wounds") || Has("hunt.packSpeed")))
			{
				huntTarget = __instance;
				huntTargetUntil = time + 10f;
			}
			if ((flag8 && Has("cap.mark")) || (flag11 && Has("hunt.wounds")))
			{
				if (!marked.TryGetValue(__instance, out var value5) || time >= value5)
				{
					TalentVfx.Play(__instance.GetCenterPoint(), TalentVfx.Effect.Hunt, 0.65f);
				}
				marked[__instance] = time + 10f;
			}
			if (V("sunder") > 0f)
			{
				sundered[__instance] = time + 8f;
			}
			if (((DamageTypes)(ref hit.m_damage)).GetTotalDamage() >= __instance.GetHealth())
			{
				OnKill(val, __instance, flag8, val2);
			}
		}
	}

	[HarmonyPatch(typeof(MonsterAI), "UpdateAI")]
	private static class HuntPack
	{
		private static readonly Action<MonsterAI, Character> SetHuntTarget = (Action<MonsterAI, Character>)Delegate.CreateDelegate(typeof(Action<MonsterAI, Character>), AccessTools.Method(typeof(MonsterAI), "SetTarget", new Type[1] { typeof(Character) }, (Type[])null));

		private static void Prefix(MonsterAI __instance)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)huntTarget == (Object)null) && !huntTarget.IsDead() && !huntTarget.IsTamed() && !(Time.time >= huntTargetUntil) && Has("hunt.packSpeed") && FollowsLocalHunter(__instance))
			{
				Vector3 val = ((Component)huntTarget).transform.position - ((Component)__instance).transform.position;
				if (!(((Vector3)(ref val)).sqrMagnitude > 900f) && (Object)(object)((BaseAI)__instance).GetTargetCreature() != (Object)(object)huntTarget)
				{
					SetHuntTarget(__instance, huntTarget);
				}
			}
		}

		private static float AttackInterval(float seconds, MonsterAI ai)
		{
			if (!Has("hunt.packSpeed") || !FollowsLocalHunter(ai))
			{
				return seconds;
			}
			return seconds / (1f + V("hunt.packSpeed"));
		}

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			FieldInfo weaponInterval = AccessTools.Field(typeof(SharedData), "m_aiAttackInterval");
			FieldInfo minimumInterval = AccessTools.Field(typeof(MonsterAI), "m_minAttackInterval");
			MethodInfo adjust = AccessTools.Method(typeof(HuntPack), "AttackInterval", (Type[])null, (Type[])null);
			foreach (CodeInstruction instruction in instructions)
			{
				yield return instruction;
				if (CodeInstructionExtensions.LoadsField(instruction, weaponInterval, false) || CodeInstructionExtensions.LoadsField(instruction, minimumInterval, false))
				{
					yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
					yield return new CodeInstruction(OpCodes.Call, (object)adjust);
				}
			}
		}
	}

	[HarmonyPatch(typeof(MineRock), "Damage")]
	private static class MineA
	{
		private static void Prefix(HitData hit)
		{
			Mining(hit, ore: true);
		}

		private static void Postfix()
		{
			miningContext = false;
		}
	}

	[HarmonyPatch(typeof(MineRock5), "Damage")]
	private static class MineB
	{
		private static void Prefix(HitData hit)
		{
			Mining(hit, ore: true);
		}

		private static void Postfix()
		{
			miningContext = false;
		}
	}

	[HarmonyPatch(typeof(Destructible), "Damage")]
	private static class MineC
	{
		private static void Prefix(HitData hit)
		{
			Mining(hit, ore: false);
		}

		private static void Postfix()
		{
			miningContext = false;
		}
	}

	[HarmonyPatch(typeof(DropTable), "GetDropList", new Type[] { })]
	private static class ExtraOre
	{
		private static void Postfix(DropTable __instance, List<GameObject> __result)
		{
			if (woodBonus > 0 && woodDropTable == __instance && __result != null)
			{
				GameObject val = ((IEnumerable<GameObject>)__result).FirstOrDefault((Func<GameObject, bool>)((GameObject item) => (Object)(object)item != (Object)null && (((Object)item).name == "Wood" || ((Object)item).name == "FineWood" || ((Object)item).name == "RoundLog" || ((Object)item).name == "YggdrasilWood")));
				if ((Object)(object)val != (Object)null)
				{
					for (int num = 0; num < woodBonus; num++)
					{
						__result.Add(val);
					}
				}
			}
			if (miningContext && __result != null && __result.Count != 0)
			{
				Player localPlayer = Player.m_localPlayer;
				float num2 = V("drop.ore") + (RacesBridge.PowerActive(localPlayer, "DeepDelve") ? V("delve.yield") : 0f);
				if (num2 > 0f && Random.value < num2)
				{
					__result.Add(__result[Random.Range(0, __result.Count)]);
				}
			}
		}
	}

	[HarmonyPatch(typeof(CharacterDrop), "GenerateDropList")]
	private static class AnimalDrops
	{
		private static void Postfix(CharacterDrop __instance, List<KeyValuePair<GameObject, int>> __result)
		{
			if (__result == null || __result.Count == 0)
			{
				return;
			}
			Character component = ((Component)__instance).GetComponent<Character>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			ZNetView component2 = ((Component)component).GetComponent<ZNetView>();
			if ((Object)(object)component2 != (Object)null && component2.IsValid() && component2.GetZDO().GetLong("RotR.BeastcallUntil", 0L) > 0 && Has("cap.lordWild"))
			{
				__result.AddRange(__result.ToList());
				return;
			}
			HitData val = LastHit.Invoke(component);
			if (val == null || !IsLocal(val.GetAttacker()))
			{
				return;
			}
			Professions.Drops(component, __result);
			if (IsAnimal(component) && Random.value < V("drop.animal"))
			{
				KeyValuePair<GameObject, int> keyValuePair = __result.FirstOrDefault((KeyValuePair<GameObject, int> kv) => Professions.IsTrophy(kv.Key));
				if ((Object)(object)keyValuePair.Key == (Object)null)
				{
					keyValuePair = __result[Random.Range(0, __result.Count)];
				}
				__result.Add(new KeyValuePair<GameObject, int>(keyValuePair.Key, 1));
			}
		}
	}

	[HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[] { typeof(int) })]
	private static class CookedFoodTooltip
	{
		private static void Postfix(ItemData __instance, ref string __result)
		{
			if (__result != null && __instance?.m_customData != null && __instance.m_customData.TryGetValue("EST.Cook", out var value) && float.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out var result) && !(result <= 0f))
			{
				__result = __result + "\n<color=#e8b04a>Hearthfolk cooking: +" + (result * 100f).ToString("0.#", CultureInfo.InvariantCulture) + "% damage while this food is active (for whoever eats it)</color>";
			}
		}
	}

	[HarmonyPatch]
	private static class PovStacksCookedFood
	{
		private static MethodInfo target;

		private static bool Prepare()
		{
			if (!PovCompat.Installed)
			{
				return false;
			}
			Type type = AccessTools.TypeByName("PassiveTree.StackRules");
			target = ((type != null) ? AccessTools.Method(type, "Bookkeeping", new Type[1] { typeof(string) }, (Type[])null) : null);
			if (target == null || target.ReturnType != typeof(bool))
			{
				Plugin.Log.LogWarning((object)"Path of Valheiman stacking rule not found: Hearthfolk food may not stack with other food.");
				return false;
			}
			return true;
		}

		private static MethodBase TargetMethod()
		{
			return target;
		}

		private static void Postfix(string __0, ref bool __result)
		{
			if (!__result && __0 == "EST.Cook")
			{
				__result = true;
			}
		}
	}

	[HarmonyPatch(typeof(InventoryGui), "DoCrafting")]
	private static class CookedFood
	{
		private static Dictionary<ItemData, int> before;

		private static Recipe recipe;

		private static int countBefore;

		private static readonly FieldRef<InventoryGui, Recipe> CraftRecipe = AccessTools.FieldRefAccess<InventoryGui, Recipe>("m_craftRecipe");

		private static void Prefix(InventoryGui __instance, Player player)
		{
			before = (((Object)(object)player != (Object)null) ? ((Humanoid)player).GetInventory().GetAllItems().ToDictionary((ItemData i) => i, (ItemData i) => i.m_stack) : null);
			recipe = (((Object)(object)__instance != (Object)null) ? CraftRecipe.Invoke(__instance) : null);
			countBefore = (((Object)(object)recipe?.m_item != (Object)null && (Object)(object)player != (Object)null) ? ((Humanoid)player).GetInventory().CountItems(recipe.m_item.m_itemData.m_shared.m_name, -1, true) : 0);
		}

		private static void Postfix(Player player)
		{
			if (before == null || !IsLocal((Character)(object)player))
			{
				before = null;
				return;
			}
			float num = V("cook.dmg");
			if (num > 0f)
			{
				foreach (ItemData allItem in ((Humanoid)player).GetInventory().GetAllItems())
				{
					if (!(allItem.m_shared.m_food <= 0f) && (!before.TryGetValue(allItem, out var value) || allItem.m_stack > value))
					{
						if (allItem.m_customData == null)
						{
							allItem.m_customData = new Dictionary<string, string>();
						}
						allItem.m_customData["EST.Cook"] = num.ToString(CultureInfo.InvariantCulture);
					}
				}
			}
			try
			{
				Bonus(player);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Bulk Cooking: " + ex.Message));
			}
			before = null;
			recipe = null;
		}

		private static void Bonus(Player player)
		{
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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_011b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)recipe?.m_item == (Object)null)
			{
				return;
			}
			Inventory inventory = ((Humanoid)player).GetInventory();
			string name = recipe.m_item.m_itemData.m_shared.m_name;
			int num = inventory.CountItems(name, -1, true) - countBefore;
			if (num <= 0)
			{
				return;
			}
			int num2 = 0;
			if (num >= 5 && Random.value < V("craft.bulk"))
			{
				num2++;
			}
			bool flag = ((Object)((Component)recipe.m_item).gameObject).name.StartsWith("Feast", StringComparison.Ordinal);
			if (flag && Random.value < V("craft.feast"))
			{
				num2 += num;
			}
			if (num2 <= 0)
			{
				return;
			}
			int value;
			ItemData val = ((IEnumerable<ItemData>)inventory.GetAllItems()).FirstOrDefault((Func<ItemData, bool>)((ItemData i) => i.m_shared.m_name == name && (!before.TryGetValue(i, out value) || i.m_stack > value)));
			if (val != null)
			{
				ItemData val2 = val.Clone();
				val2.m_stack = num2;
				if (!inventory.AddItem(val2))
				{
					ItemDrop.DropItem(val2, num2, ((Component)player).transform.position + ((Component)player).transform.forward + Vector3.up, Quaternion.identity);
				}
				((Character)player).Message((MessageType)1, (flag ? "Feast Master: +" : "Bulk Cooking: +") + num2 + " " + Localization.instance.Localize(name), 0, (Sprite)null, false);
			}
		}
	}

	[HarmonyPatch]
	private static class CinderSlam
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			yield return AccessTools.Method(typeof(Attack), "DoAreaAttack", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(Attack), "DoMeleeAttack", (Type[])null, (Type[])null);
		}

		private static void Postfix(Attack __instance)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Invalid comparison between Unknown and I4
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Invalid comparison between Unknown and I4
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: 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)
			Humanoid obj = AttackChar.Invoke(__instance);
			Player val = (Player)(object)((obj is Player) ? obj : null);
			if (val == null || !IsLocal((Character)(object)val) || !SecondaryAttack.Invoke((Humanoid)(object)val) || !RacesBridge.PowerActive(val, "CinderGlow"))
			{
				return;
			}
			ItemData val2 = AttackWeapon.Invoke(__instance);
			if (val2 == null || (int)val2.m_shared.m_skillType != 3 || (int)val2.m_shared.m_itemType != 14)
			{
				return;
			}
			float num = V("cinder.slam");
			if (!(num <= 0f))
			{
				Vector3 position = ((Component)val).transform.position;
				TalentVfx.Play(position, TalentVfx.Effect.Hearthfire, 4f);
				CinderSlamDamage(val, position, num);
				if (Has("cinder.scorch"))
				{
					TalentVfx.Play(position, TalentVfx.Effect.ScorchedGround, 4f);
					((MonoBehaviour)Plugin.I).StartCoroutine(ScorchedGround(val, position));
				}
			}
		}
	}

	[HarmonyPatch(typeof(SE_Shield), "Setup")]
	private static class FixedShieldDuration
	{
		private static void Postfix(SE_Shield __instance, Character __0)
		{
			if (IsLocal(__0) && __instance.m_ttlPerItemLevel <= 0 && ((StatusEffect)__instance).m_ttl > 0f)
			{
				((StatusEffect)__instance).m_ttl = ((StatusEffect)__instance).m_ttl + V("shield.duration");
			}
		}
	}

	[HarmonyPatch(typeof(SE_Shield), "SetLevel")]
	private static class ShieldBubblePotency
	{
		private static void Postfix(SE_Shield __instance, Character ___m_character, ref float ___m_totalAbsorbDamage)
		{
			if (IsLocal(___m_character))
			{
				___m_totalAbsorbDamage *= 1f + V("shield.potency");
				if (__instance.m_ttlPerItemLevel > 0 && ((StatusEffect)__instance).m_ttl > 0f)
				{
					((StatusEffect)__instance).m_ttl = ((StatusEffect)__instance).m_ttl + V("shield.duration");
				}
			}
		}
	}

	[HarmonyPatch(typeof(CraftingStation), "GetStationBuildRange")]
	private static class WorkshopReach
	{
		private static void Postfix(ref float __result)
		{
			if ((Object)(object)Player.m_localPlayer != (Object)null)
			{
				__result += V("station.buildRange");
			}
		}
	}

	[HarmonyPatch]
	private static class WoodcuttingDamage
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			yield return AccessTools.Method(typeof(TreeBase), "Damage", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(TreeLog), "Damage", (Type[])null, (Type[])null);
		}

		private static void Prefix(HitData hit)
		{
			if (hit != null && hit.m_damage.m_chop > 0f && IsLocal(hit.GetAttacker()))
			{
				hit.m_damage.m_chop += V("wood.damage");
			}
		}
	}

	[HarmonyPatch]
	private static class WoodcuttingDrops
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			yield return AccessTools.Method(typeof(TreeBase), "RPC_Damage", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(TreeLog), "Destroy", (Type[])null, (Type[])null);
		}

		private static void Prefix(object __instance, object[] __args, out (DropTable table, int count) __state)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			__state = (table: woodDropTable, count: woodBonus);
			HitData val = ((__instance is TreeBase) ? ((HitData)__args[1]) : ((HitData)__args[0]));
			TreeBase val2 = (TreeBase)((__instance is TreeBase) ? __instance : null);
			woodDropTable = ((val2 != null) ? val2.m_dropWhenDestroyed : ((TreeLog)__instance).m_dropWhenDestroyed);
			woodBonus = 0;
			if (val == null || val.m_damage.m_chop <= 0f)
			{
				return;
			}
			Character attacker = val.GetAttacker();
			Player val3 = (Player)(object)((attacker is Player) ? attacker : null);
			if (val3 == null)
			{
				return;
			}
			if (IsLocal((Character)(object)val3))
			{
				woodBonus = (int)V("wood.yield");
				return;
			}
			ZNetView component = ((Component)val3).GetComponent<ZNetView>();
			if ((Object)(object)component != (Object)null && component.IsValid())
			{
				woodBonus = Mathf.Clamp(component.GetZDO().GetInt("EST_WoodYield", 0), 0, 5);
			}
		}

		private static Exception Finalizer(Exception __exception, (DropTable table, int count) __state)
		{
			(woodDropTable, woodBonus) = __state;
			return __exception;
		}
	}

	[HarmonyPatch(typeof(Character), "RPC_Damage")]
	private static class TakeDamage
	{
		private static bool Prefix(Character __instance, HitData hit, ref float __state)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0646: Unknown result type (might be due to invalid IL or missing references)
			__state = -1f;
			if (hit == null || !Progress.Loaded)
			{
				return true;
			}
			if (!IsLocal(__instance))
			{
				BeastProtect(__instance, hit);
				__state = BeastHealth(__instance);
				return true;
			}
			Character attacker = hit.GetAttacker();
			if ((Object)(object)attacker != (Object)null && BaseAI.IsEnemy(__instance, attacker) && ((DamageTypes)(ref hit.m_damage)).GetTotalDamage() > 0f && RollEvasion((Player)__instance))
			{
				return false;
			}
			__state = __instance.GetHealth();
			Player val = (Player)__instance;
			float num = Professions.DamageTakenFactor(hit.GetAttacker());
			if (num < 1f)
			{
				((DamageTypes)(ref hit.m_damage)).Modify(num);
			}
			float time = Time.time;
			bool flag = Talents.AtHome(val);
			bool flag2 = RacesBridge.PowerActive(val, "GlacierSkin");
			bool flag3 = flag && Has("cap.mistborn");
			float num2 = V("resist.element");
			float num3 = V("resist.magic") + (flag3 ? V("cap.mistborn") : 0f);
			hit.m_damage.m_fire *= Keep(num2 + num3 + V("resist.fire"));
			hit.m_damage.m_frost *= Keep(num2 + num3 + V("resist.frost"));
			hit.m_damage.m_lightning *= Keep(num2 + num3 + V("resist.lightning"));
			hit.m_damage.m_spirit *= Keep(num2 + num3 + V("resist.spirit"));
			hit.m_damage.m_poison *= Keep(num2 + V("resist.poison"));
			float num4 = V("poison.bubble");
			if (num4 > 0f && hit.m_damage.m_poison > 0f)
			{
				if (bubbleLeft < 0f)
				{
					bubbleLeft = num4;
				}
				float num5 = Mathf.Min(bubbleLeft, hit.m_damage.m_poison);
				if (num5 > 0f)
				{
					hit.m_damage.m_poison -= num5;
					bubbleLeft -= num5;
					if (time - bubbleFxAt > 1f)
					{
						bubbleFxAt = time;
						TalentVfx.Play(((Character)val).GetCenterPoint(), TalentVfx.Effect.Ward, 1.2f);
					}
					if (bubbleLeft <= 0f)
					{
						((Character)val).Message((MessageType)1, "Bog Bubble popped", 0, (Sprite)null, false);
					}
				}
				lastPoisonAt = time;
			}
			float reduction = (flag2 ? V("resist.physGlacier") : 0f) + (((Character)val).InInterior() ? V("cap.stoneSkin") : 0f);
			hit.m_damage.m_blunt *= Keep(reduction);
			hit.m_damage.m_slash *= Keep(reduction);
			hit.m_damage.m_pierce *= Keep(reduction);
			if (hit.m_ranged && flag2)
			{
				((DamageTypes)(ref hit.m_damage)).Modify(Keep(V("cap.frostVeil")));
			}
			float num6 = 0f;
			if (RacesBridge.Adrenaline > 40f)
			{
				num6 += V("cap.ironblood");
			}
			if (RacesBridge.Raging)
			{
				num6 += V("dr.rage");
			}
			if (RacesBridge.PowerActive(val, "DeepDelve"))
			{
				num6 += V("dr.delve");
			}
			if (((Character)val).InAttack())
			{
				ItemData currentWeapon = ((Humanoid)val).GetCurrentWeapon();
				if (IsSpell((SkillType)((currentWeapon != null) ? ((int)currentWeapon.m_shared.m_skillType) : 0)))
				{
					num6 += V("dr.casting");
				}
			}
			if (time < cinderSkinUntil)
			{
				num6 += V("cap.cinderSkin");
			}
			if (nearBed50)
			{
				num6 += V("cap.homeAdvantage");
			}
			if (nearFire && ((Character)val).GetSEMan().HaveStatusEffect(Rested))
			{
				num6 += V("cap.unbreakable");
			}
			if (LivingShadowActive(val, flag))
			{
				num6 += V("cap.livingShadow");
			}
			if (Has("cap.wildResilience") && Foods.Invoke(val).Any((Food f) => RacesBridge.IsRawFood(f?.m_item)))
			{
				num6 += V("cap.wildResilience");
			}
			if (LivingVeinActive(val))
			{
				num6 += V("cap.livingVein");
			}
			if (time < bulwarkUntil)
			{
				num6 += V("cap.bulwark");
			}
			num6 += StoneWard(val) + ShieldWall(val);
			if (num6 > 0f)
			{
				((DamageTypes)(ref hit.m_damage)).Modify(Keep(num6));
			}
			if (RacesBridge.Raging && Has("cap.unstoppable"))
			{
				hit.m_staggerMultiplier = 0f;
				hit.m_pushForce = 0f;
			}
			if (hit.m_damage.m_fire > 0f && Has("cap.cinderSkin"))
			{
				cinderSkinUntil = time + 5f;
			}
			Character attacker2 = hit.GetAttacker();
			float num7 = V("glacier.frostAura");
			if (flag2 && num7 > 0f && (Object)(object)attacker2 != (Object)null && !attacker2.IsPlayer() && !attacker2.IsDead())
			{
				Hit(val, attacker2, 0f, num7, 0f);
			}
			float totalDamage = ((DamageTypes)(ref hit.m_damage)).GetTotalDamage();
			if (totalDamage > 0f && Has("cap.runeWard") && ((Character)val).GetEitrPercentage() > 0.5f && time >= wardReady)
			{
				wardReady = time + 10f;
				ShieldMax = ((Character)val).GetMaxEitr() * V("cap.runeWard") * (1f + V("shield.potency"));
				Shield = ShieldMax;
				TalentVfx.Play(((Character)val).GetCenterPoint(), TalentVfx.Effect.Ward, 1.15f);
			}
			if (Shield > 0f && totalDamage > 0f)
			{
				float num8 = Mathf.Min(totalDamage, Shield);
				Shield -= num8;
				((DamageTypes)(ref hit.m_damage)).Modify((totalDamage - num8) / totalDamage);
				if (Shield <= 0f && Has("rune.pulse"))
				{
					Splash(val, (Character)(object)val, 4f, 0f, 1f, 60f);
					TalentVfx.Play(((Character)val).GetCenterPoint(), TalentVfx.Effect.Ward, 2f);
				}
			}
			return true;
		}

		private static float Keep(float reduction)
		{
			return 1f - Mathf.Clamp(reduction, 0f, 0.75f);
		}

		private static void Postfix(Character __instance, float __state)
		{
			if (!(__state < 0f))
			{
				if (!IsLocal(__instance))
				{
					LoyalPack(__instance, __state);
				}
				else if (Has("cap.bulwark") && !__instance.IsDead() && __state - __instance.GetHealth() > __instance.GetMaxHealth() * 0.2f && Time.time >= bulwarkReady)
				{
					bulwarkUntil = Time.time + 5f;
					bulwarkReady = Time.time + 30f;
					__instance.Message((MessageType)1, "Bulwark", 0, (Sprite)null, false);
				}
			}
		}
	}

	[HarmonyPatch(typeof(Character), "AddStaggerDamage")]
	private static class NoStaggerInRage
	{
		private static bool Prefix(Character __instance, ref bool __result)
		{
			if (!IsLocal(__instance) || !RacesBridge.Raging || !Has("cap.unstoppable"))
			{
				return true;
			}
			__result = false;
			return false;
		}
	}

	[HarmonyPatch(typeof(Character), "CheckDeath")]
	private static class LastStand
	{
		private static bool Prefix(Character __instance)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			if (!IsLocal(__instance) || __instance.IsDead() || __instance.GetHealth() > 0f || !Has("cap.laststand") || RacesBridge.Raging)
			{
				return true;
			}
			Player val = (Player)__instance;
			double num = Now();
			if (val.m_customData.TryGetValue("EST.LastStandAt", out var value) && double.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out var result) && num >= result && num - result < 600.0)
			{
				return true;
			}
			val.m_customData["EST.LastStandAt"] = num.ToString(CultureInfo.InvariantCulture);
			((Character)val).SetHealth(((Character)val).GetMaxHealth() * V("cap.laststand"));
			((Character)val).Message((MessageType)2, "Last Stand", 0, (Sprite)null, false);
			return false;
		}
	}

	[HarmonyPatch(typeof(ItemData), "GetBlockPower", new Type[]
	{
		typeof(int),
		typeof(float)
	})]
	private static class BlockPower
	{
		private static void Postfix(ItemData __instance, ref float __result)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Invalid comparison between Unknown and I4
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Invalid comparison between Unknown and I4
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Invalid comparison between Unknown and I4
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || CurrentBlocker((Humanoid)(object)localPlayer) != __instance)
			{
				return;
			}
			float num = V("block.power") + (Talents.RaceWeapon(__instance, __instance.m_shared.m_skillType) ? V("block.weapon") : 0f) + (((int)__instance.m_shared.m_itemType == 5) ? V("block.shield") : 0f);
			if ((int)__instance.m_shared.m_itemType == 5 && __instance.m_shared.m_timedBlockBonus <= 1f)
			{
				ItemData currentWeapon = ((Humanoid)localPlayer).GetCurrentWeapon();
				if (currentWeapon != null && (int)currentWeapon.m_shared.m_skillType == 5)
				{
					num += V("block.tower");
				}
			}
			__result *= 1f + num;
		}
	}

	[HarmonyPatch(typeof(SEMan), "ModifySkillLevel")]
	private static class SkillBonus
	{
		private static readonly FieldRef<SEMan, Character> Owner = AccessTools.FieldRefAccess<SEMan, Character>("m_character");

		private static void Postfix(SEMan __instance, SkillType skill, ref float level)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			if ((int)skill == 101 && Progress.Loaded)
			{
				Character val = Owner.Invoke(__instance);
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val != (Object)(object)Player.m_localPlayer))
				{
					level += V("skill.sneak");
				}
			}
		}
	}

	[HarmonyPatch(typeof(Humanoid), "BlockAttack")]
	private static class TimedParry
	{
		internal struct State
		{
			public ItemData Item;

			public float Bonus;

			public bool Timer;

			public float TimerWas;

			public float Heal;

			public float AllyHeal;

			public float IncomingDamage;
		}

		private static readonly FieldRef<Humanoid, float> BlockTimer = AccessTools.FieldRefAccess<Humanoid, float>("m_blockTimer");

		private const float ParryWindow = 0.25f;

		private static void Prefix(Humanoid __instance, HitData hit, out State __state)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Invalid comparison between Unknown and I4
			__state = default(State);
			if (!IsLocal((Character)(object)__instance) || !Progress.Loaded)
			{
				return;
			}
			ItemData val = CurrentBlocker(__instance);
			if (val == null || (int)val.m_shared.m_itemType != 5)
			{
				return;
			}
			__state.Heal = V("shield.blockHeal");
			__state.AllyHeal = V("cap.hearthfire");
			if (__state.Heal > 0f || __state.AllyHeal > 0f)
			{
				__state.IncomingDamage = hit.GetTotalBlockableDamage();
			}
			if (val.m_shared.m_timedBlockBonus <= 1f)
			{
				return;
			}
			float num = V("parry.shield");
			float num2 = V("parry.add");
			float num3 = V("parry.window");
			if (num3 > 0f && (val.m_shared.m_name ?? "").IndexOf("buckler", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				float num4 = BlockTimer.Invoke(__instance);
				if (num4 >= 0.25f && num4 < 0.25f + num3)
				{
					__state.Timer = true;
					__state.TimerWas = num4;
					BlockTimer.Invoke(__instance) = 0.24f;
				}
			}
			if (num > 0f || num2 > 0f)
			{
				__state.Item = val;
				__state.Bonus = val.m_shared.m_timedBlockBonus;
				val.m_shared.m_timedBlockBonus = (val.m_shared.m_timedBlockBonus + num2) * (1f + num);
			}
		}

		private static void Restore(Humanoid h, State s)
		{
			if (s.Item != null)
			{
				s.Item.m_shared.m_timedBlockBonus = s.Bonus;
			}
			if (s.Timer && (Object)(object)h != (Object)null)
			{
				BlockTimer.Invoke(h) = s.TimerWas;
			}
		}

		private static void Postfix(Humanoid __instance, HitData hit, bool __result, State __state)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			Restore(__instance, __state);
			if (__result && !(hit.GetTotalBlockableDamage() >= __state.IncomingDamage))
			{
				if (__state.Heal > 0f)
				{
					((Character)__instance).Heal(__state.Heal, true);
				}
				if (__state.AllyHeal > 0f)
				{
					HearthfirePulse((Player)__instance, __state.AllyHeal);
				}
			}
		}

		private static Exception Finalizer(Exception __exception, Humanoid __instance, State __state)
		{
			Restore(__instance, __state);
			return __exception;
		}
	}

	[HarmonyPatch(typeof(Player), "GetBodyArmor")]
	private static class Armor
	{
		private static void Postfix(Player __instance, ref float __result)
		{
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Invalid comparison between Unknown and I4
			if (!IsLocal((Character)(object)__instance) || !Progress.Loaded)
			{
				return;
			}
			float num = 0f;
			float num2 = V("armor.crafted");
			if (num2 > 0f)
			{
				foreach (ItemData equippedItem in ((Humanoid)__instance).GetInventory().GetEquippedItems())
				{
					if (equippedItem.m_crafterID == __instance.GetPlayerID() && equippedItem.m_shared.m_armor > 0f)
					{
						num += equippedItem.GetArmor();
					}
				}
			}
			__result = __result * (1f + V("armor.pct")) + num * num2 + RacesBridge.MediumArmor(__instance) * V("armor.medium");
			if (Talents.AtHome(__instance))
			{
				__result += V("armor.home");
			}
			__result += V("armor.flat");
			if (((Character)__instance).InInterior())
			{
				__result += V("armor.underground");
			}
			if ((int)__instance.GetCurrentBiome() == 1 || nearTrader)
			{
				__result += V("armor.trade");
			}
			float num3 = V("armor.perAdr");
			if (num3 > 0f)
			{
				float adrenaline = RacesBridge.Adrenaline;
				adrenaline = Mathf.Max(adrenaline, V("adr.floor") * 0.5f);
				__result += adrenaline * num3;
			}
		}
	}

	[HarmonyPatch(typeof(Tameable), "DecreaseRemainingTime")]
	private static class WolfTaming
	{
		private static void Prefix(Tameable __instance, ref float __0)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			if (__0 <= 0f)
			{
				return;
			}
			bool flag = Utils.GetPrefabName(((Component)__instance).gameObject) == "Wolf";
			float num = 0f;
			List<Player> list = new List<Player>();
			Player.GetPlayersInRange(((Component)__instance).transform.position, 10f, list);
			foreach (Player item in list)
			{
				if (((Character)item).IsDead())
				{
					continue;
				}
				if (IsLocal((Character)(object)item))
				{
					if (flag)
					{
						num = Mathf.Max(num, Mathf.Min(V("wolf.tame"), 0.45f));
					}
					num = Mathf.Max(num, Mathf.Min(V("tame.speed"), 0.3f));
					continue;
				}
				ZNetView component = ((Component)item).GetComponent<ZNetView>();
				if (!((Object)(object)component == (Object)null) && component.IsValid())
				{
					if (flag)
					{
						num = Mathf.Max(num, Mathf.Min(component.GetZDO().GetFloat("EST_WolfTame", 0f), 0.45f));
					}
					num = Mathf.Max(num, Mathf.Min(component.GetZDO().GetFloat("EST_TameSpeed", 0f), 0.3f));
				}
			}
			if (num > 0f)
			{
				__0 *= 1f + num;
			}
		}
	}

	[HarmonyPatch(typeof(Player), "GetTotalFoodValue")]
	private static class FoodValue
	{
		[HarmonyPriority(200)]
		private static void Postfix(Player __instance, ref float hp, ref float stamina, ref float eitr)
		{
			if (!IsLocal((Character)(object)__instance) || !Progress.Loaded)
			{
				return;
			}
			float num = V("food.ice");
			if (num > 0f)
			{
				foreach (Food item in Foods.Invoke(__instance))
				{
					ItemData val = item?.m_item;
					if (val != null && IsIceFood(val))
					{
						hp += item.m_health * num;
						stamina += item.m_stamina * num;
						eitr += item.m_eitr * num;
					}
				}
			}
			float num2 = (Talents.AtHome(__instance) ? V("hpstam.home") : 0f);
			hp = (hp + V("hp.flat")) * (1f + V("hp.pct") + num2);
			stamina *= 1f + num2;
			eitr += V("eitr.flat");
		}
	}

	[HarmonyPatch(typeof(ItemData), "GetDrawStaminaDrain")]
	private static class BowDrawStamina
	{
		private static void Postfix(ItemData __instance, ref float __result)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			if ((int)__instance.m_shared.m_skillType == 8)
			{
				Player localPlayer = Player.m_localPlayer;
				if (((localPlayer != null) ? ((Humanoid)localPlayer).GetCurrentWeapon() : null) == __instance)
				{
					__result *= 1f - Mathf.Clamp01(V("stam.draw"));
				}
			}
		}
	}

	[HarmonyPatch(typeof(Attack), "GetAttackStamina")]
	private static class AttackStamina
	{
		private static void Postfix(Attack __instance, ref float __result)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Invalid comparison between Unknown and I4
			Humanoid obj = AttackChar.Invoke(__instance);
			Player val = (Player)(object)((obj is Player) ? obj : null);
			if (IsLocal((Character)(object)val))
			{
				ItemData val2 = AttackWeapon.Invoke(__instance);
				bool flag = ArtisanCompat.IsDualPick(val2);
				bool flag2 = val2 != null && Talents.RaceWeapon(val2, (SkillType)(flag ? 12 : ((int)val2.m_shared.m_skillType)));
				float num = V("stam.attack") + (flag2 ? V("stam.weapon") : 0f) + (flag ? V("twin.picks") : 0f) + ((flag2 && RacesBridge.Raging) ? V("stam.rageWeapon") : 0f) + ((flag2 && RacesBridge.Raging && Has("cap.unstoppable")) ? 0.15f : 0f) + ((val2 != null && (int)val2.m_shared.m_skillType == 2 && RacesBridge.PowerActive(val, "Bogveil")) ? V("stam.veiledKnife") : 0f) + ((ArtisanCompat.IsPickaxe(val2) && RacesBridge.PowerActive(val, "DeepDelve")) ? V("delve.stamina") : 0f);
				__result *= Mathf.Max(0.1f, 1f - num);
			}
		}
	}

	[HarmonyPatch(typeof(Attack), "GetAttackHealth")]
	private static class BloodPrice
	{
		private static void Postfix(Attack __instance, ref float __result)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			Humanoid val = AttackChar.Invoke(__instance);
			ItemData val2 = AttackWeapon.Invoke(__instance);
			if (IsLocal((Character)(object)val) && val2 != null && IsSpell(val2.m_shared.m_skillType))
			{
				__result += ((Character)val).GetHealth() * V("blood.price");
			}
		}
	}

	[HarmonyPatch(typeof(Character), "RPC_Damage")]
	private static class BurningFollowup
	{
		private static void Prefix(Character __instance, HitData hit, out SE_Burning __state)
		{
			__state = null;
			if (__instance.IsPlayer() || __instance.IsDead() || hit == null || ((DamageTypes)(ref hit.m_damage)).GetTotalDamage() <= 0f)
			{
				return;
			}
			Character attacker = hit.GetAttacker();
			Player val = (Player)(object)((attacker is Player) ? attacker : null);
			if (val == null)
			{
				return;
			}
			ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid() || !component.IsOwner())
			{
				return;
			}
			ZNetView component2 = ((Component)val).GetComponent<ZNetView>();
			bool num;
			if (!IsLocal((Character)(object)val))
			{
				if (!((Object)(object)component2 != (Object)null) || !component2.IsValid())
				{
					return;
				}
				num = component2.GetZDO().GetBool("EST_ElementFollowup", false);
			}
			else
			{
				num = Has("element.followup");
			}
			if (num)
			{
				StatusEffect statusEffect = __instance.GetSEMan().GetStatusEffect(Burning);
				__state = (SE_Burning)(object)((statusEffect is SE_Burning) ? statusEffect : null);
			}
		}

		private static void Postfix(Character __instance, SE_Burning __state, bool __runOriginal)
		{
			if (__runOriginal && !((Object)(object)__state == (Object)null) && !__instance.IsDead() && !((Object)(object)__instance.GetSEMan().GetStatusEffect(Burning) != (Object)(object)__state))
			{
				ExtendBurn(__state);
			}
		}
	}

	[HarmonyPatch(typeof(Attack), "GetAttackEitr", new Type[] { })]
	private static class EitrCost
	{
		private static void Postfix(Attack __instance, ref float __result)
		{
			if (IsLocal((Character)(object)AttackChar.Invoke(__instance)))
			{
				__result *= Mathf.Max(0.1f, 1f - V("eitr.cost"));
				lastEitrCost = __result;
			}
		}
	}

	[HarmonyPatch(typeof(Player), "UseEitr")]
	private static class ArcaneMastery
	{
		private static bool Prefix(Player __instance, float v)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if (!IsLocal((Character)(object)__instance) || v <= 0f || !Has("cap.arcane"))
			{
				return true;
			}
			ItemData currentWeapon = ((Humanoid)__instance).GetCurrentWeapon();
			if (currentWeapon == null || !IsSpell(currentWeapon.m_shared.m_skillType))
			{
				return true;
			}
			return Random.value >= V("cap.arcane");
		}
	}

	[HarmonyPatch(typeof(Humanoid), "GetAttackDrawPercentage")]
	private static class DrawSpeed
	{
		private static void Postfix(Humanoid __instance, ref float __result)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Invalid comparison between Unknown and I4
			if (__result > 0f && IsLocal((Character)(object)__instance))
			{
				ItemData currentWeapon = __instance.GetCurrentWeapon();
				if (currentWeapon != null && (int)currentWeapon.m_shared.m_skillType == 8)
				{
					__result = Mathf.Min(1f, __result * (1f + V("speed.draw") + V("speed.bow")));
				}
			}
		}
	}

	[HarmonyPatch(typeof(ItemData), "GetWeaponLoadingTime")]
	private static class ReloadSpeed
	{
		private static void Postfix(ItemData __instance, ref float __result)
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && ((Humanoid)localPlayer).GetCurrentWeapon() == __instance)
			{
				float num = V("speed.draw");
				if ((Object)(object)__instance.m_dropPrefab != (Object)null && ((Object)__instance.m_dropPrefab).name == "GrapplingHook")
				{
					num += V("grapple.reload");
				}
				__result /= 1f + num;
			}
		}
	}

	[HarmonyPatch(typeof(CharacterAnimEvent), "CustomFixedUpdate")]
	private static class AttackSpeed
	{
		[HarmonyPriority(800)]
		private static void Postfix(CharacterAnimEvent __instance)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)AnimChar.Invoke(__instance) != (Object)(object)localPlayer)
			{
				return;
			}
			Animator val = AnimField.Invoke(__instance);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			ItemData currentWeapon = ((Humanoid)localPlayer).GetCurrentWeapon();
			bool flag = ArtisanCompat.IsDualPick(currentWeapon);
			float num = (IsRangedWeapon(currentWeapon) ? 0f : V("speed.melee")) + ((currentWeapon != null && Talents.RaceWeapon(currentWeapon, (SkillType)(flag ? 12 : ((int)currentWeapon.m_shared.m_skillType)))) ? V("speed.weapon") : 0f) + (flag ? V("twin.picks") : 0f);
			if (num <= 0f || !((Character)localPlayer).InAttack())
			{
				speedOn = false;
				return;
			}
			float speed = val.speed;
			if (!(speed < 0.01f))
			{
				if (!speedOn || !Mathf.Approximately(speed, speedEnd))
				{
					speedBase = speed;
				}
				speedOn = true;
				val.speed = speedBase * (1f + num);
			}
		}
	}

	[HarmonyPatch(typeof(CharacterAnimEvent), "CustomFixedUpdate")]
	private static class AttackSpeedEnd
	{
		[HarmonyPriority(0)]
		private static void Postfix(CharacterAnimEvent __instance)
		{
			if (speedOn && !((Object)(object)Player.m_localPlayer == (Object)null) && !((Object)(object)AnimChar.Invoke(__instance) != (Object)(object)Player.m_localPlayer))
			{
				Animator val = AnimField.Invoke(__instance);
				if ((Object)(object)val != (Object)null && val.speed >= 0.01f)
				{
					speedEnd = val.speed;
				}
			}
		}
	}

	[HarmonyPatch(typeof(Character), "OnDeath")]
	private static class Kill
	{
		private static void Prefix(Character __instance)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!(__instance is Player) && !__instance.IsTamed() && ZRoutedRpc.instance != null)
				{
					string text = ((__instance.IsBoss() && Progress.IsKnownBoss(__instance.m_name)) ? __instance.m_name : "");
					float num = ((text.Length > 0) ? 0f : Progress.KillXp(__instance));
					if (text.Length != 0 || !(num <= 0f))
					{
						ZPackage val = new ZPackage();
						val.Write(((Component)__instance).transform.position);
						val.Write(num);
						val.Write(text);
						val.Write(Utils.GetPrefabName(((Component)__instance).gameObject));
						val.Write(__instance.m_name ?? "");
						ZRoutedRpc.instance.InvokeRoutedRPC(0L, "EST_Kill", new object[1] { val });
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)ex);
			}
		}
	}

	[HarmonyPatch(typeof(Player), "OnSkillLevelup")]
	private static class SkillUp
	{
		private unsafe static void Postfix(Player __instance, SkillType skill, float level)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected I4, but got Unknown
			if (!IsLocal((Character)(object)__instance))
			{
				return;
			}
			Progress.EnsureLoaded(__instance);
			Dictionary<string, int> dictionary = ParseMax(__instance);
			int num = Mathf.FloorToInt(level);
			string key = ((int)skill).ToString(CultureInfo.InvariantCulture);
			if (!dictionary.TryGetValue(key, out var value) || num > value)
			{
				dictionary[key] = num;
				__instance.m_customData["EST.SkillMax"] = string.Join(",", dictionary.Select((KeyValuePair<string, int> kv) => kv.Key + ":" + kv.Value));
				Progress.AddXp((float)num * Plugin.SkillXpFactor.Value, ((object)(*(SkillType*)(&skill))/*cast due to .constrained prefix*/).ToString() + " " + num);
			}
		}

		private static Dictionary<string, int> ParseMax(Player p)
		{
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			if (p.m_customData.TryGetValue("EST.SkillMax", out var value))
			{
				string[] array = value.Split(new char[1] { ',' });
				for (int i = 0; i < array.Length; i++)
				{
					string[] array2 = array[i].Split(new char[1] { ':' });
					if (array2.Length == 2 && int.TryParse(array2[1], out var result))
					{
						dictionary[array2[0]] = result;
					}
				}
			}
			return dictionary;
		}
	}

	[HarmonyPatch(typeof(ZNet), "Awake")]
	private static class Rpc
	{
		private static void Postfix()
		{
			try
			{
				if (ZRoutedRpc.instance != null)
				{
					RegisterRpc();
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)ex);
			}
		}
	}

	[HarmonyPatch(typeof(GameCamera), "UpdateMouseCapture")]
	private static class MouseCapture
	{
		private static bool Prefix()
		{
			if (!TalentMenu.Open)
			{
				return true;
			}
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
			return false;
		}
	}

	[HarmonyPatch(typeof(PlayerController), "TakeInput")]
	private static class ControllerInput
	{
		private static void Postfix(ref bool __result)
		{
			if (TalentMenu.Open)
			{
				__result = false;
			}
		}
	}

	[HarmonyPatch(typeof(Player), "TakeInput")]
	private static class PlayerInput
	{
		private static void Postfix(ref bool __result)
		{
			if (TalentMenu.Open)
			{
				__result = false;
			}
		}
	}

	[HarmonyPatch(typeof(Aoe), "Setup")]
	private static class EmberAftershock
	{
		private const string Blast = "bombdynamite_explosion";

		private static bool second;

		private static void Postfix(Aoe __instance, Character owner, Vector3 velocity, float hitNoise, HitData hitData, ItemData item, ItemData ammo)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			if (!IsLocal(owner) || Utils.GetPrefabName(((Component)__instance).gameObject) != "bombdynamite_explosion")
			{
				return;
			}
			float num = V("bomb.radius");
			if (!(num <= 0f))
			{
				__instance.m_radius *= 1f + num;
				Transform transform = ((Component)__instance).transform;
				transform.localScale *= 1f + num;
				if (!second)
				{
					((MonoBehaviour)Plugin.I).StartCoroutine(Again(((Component)__instance).transform.position, ((Component)__instance).transform.rotation, owner, velocity, hitNoise, (hitData != null) ? hitData.Clone() : null, item, ammo));
				}
			}
		}

		private static IEnumerator Again(Vector3 at, Quaternion rot, Character owner, Vector3 velocity, float hitNoise, HitData hitData, ItemData item, ItemData ammo)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			yield return (object)new WaitForSeconds(0.5f);
			if ((Object)(object)owner == (Object)null || (Object)(object)ZNetScene.instance == (Object)null)
			{
				yield break;
			}
			GameObject prefab = ZNetScene.instance.GetPrefab("bombdynamite_explosion");
			if ((Object)(object)prefab == (Object)null)
			{
				yield break;
			}
			Aoe componentInChildren = Object.Instantiate<GameObject>(prefab, at, rot).GetComponentInChildren<Aoe>();
			if ((Object)(object)componentInChildren == (Object)null)
			{
				yield break;
			}
			second = true;
			try
			{
				componentInChildren.Setup(owner, velocity, hitNoise, hitData, item, ammo);
			}
			finally
			{
				second = false;
			}
		}
	}

	private const string SeName = "EST_Talents";

	private const string KillRpc = "EST_Kill";

	private const string RevealRpc = "EST_Reveal";

	private const string KLastStand = "EST.LastStandAt";

	private const string KSkillMax = "EST.SkillMax";

	private const string CookKey = "EST.Cook";

	private const string BeastKey = "RotR.BeastcallUntil";

	private const string BoostKey = "RotR.BeastBoostUntil";

	private static SE_Stats template;

	private static int seHash;

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

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

	private static readonly int FrostSe = StringExtensionMethods.GetStableHashCode("Frost");

	private static readonly FieldRef<Attack, Humanoid> AttackChar = AccessTools.FieldRefAccess<Attack, Humanoid>("m_character");

	private static readonly FieldRef<Attack, ItemData> AttackWeapon = AccessTools.FieldRefAccess<Attack, ItemData>("m_weapon");

	private static readonly FieldRef<CharacterAnimEvent, Animator> AnimField = AccessTools.FieldRefAccess<CharacterAnimEvent, Animator>("m_animator");

	private static readonly FieldRef<CharacterAnimEvent, Character> AnimChar = AccessTools.FieldRefAccess<CharacterAnimEvent, Character>("m_character");

	private static readonly FieldRef<Player, List<Food>> Foods = AccessTools.FieldRefAccess<Player, List<Food>>("m_foods");

	private static readonly FieldRef<Minimap, float> ExploreRadius = AccessTools.FieldRefAccess<Minimap, float>("m_exploreRadius");

	private static readonly FieldRef<StatusEffect, float> SeTime = AccessTools.FieldRefAccess<StatusEffect, float>("m_time");

	private static readonly MethodInfo MinimapExplore = AccessTools.Method(typeof(Minimap), "Explore", new Type[2]
	{
		typeof(Vector3),
		typeof(float)
	}, (Type[])null);

	private static readonly MethodInfo SetAlerted = AccessTools.Method(typeof(BaseAI), "SetAlerted", (Type[])null, (Type[])null);

	private static readonly FieldInfo TargetCreature = AccessTools.Field(typeof(MonsterAI), "m_targetCreature");

	private static readonly MethodInfo BedOwner = AccessTools.Method(typeof(Bed), "GetOwner", (Type[])null, (Type[])null);

	private static readonly FieldRef<Character, HitData> LastHit = AccessTools.FieldRefAccess<Character, HitData>("m_lastHit");

	private static readonly Func<Humanoid, ItemData> CurrentBlocker = AccessTools.MethodDelegate<Func<Humanoid, ItemData>>(AccessTools.Method(typeof(Humanoid), "GetCurrentBlocker", (Type[])null, (Type[])null), (object)null, true);

	private static int momentumCount;

	private static int slaughterCount;

	private static int masterworkCount;

	private static int rageKillSeconds;

	private static float momentumLast = -99f;

	private static float momentumSwing = -99f;

	private static bool momentumProc;

	private static float bulwarkUntil;

	private static float bulwarkReady;

	private static float cinderSkinUntil;

	private static float providerUntil;

	private static float wardReady;

	private static float lastEitrCost;

	private static float eternalHuntArmed = -99f;

	private static float lastStealth = -99f;

	private static float lastSneak = -99f;

	private static int packStacks;

	private static float packUntil;

	private static bool splashing;

	private static int shakeCount;

	private static float splashSwing = -99f;

	private static float shakeSwing = -99f;

	private const string WardKey = "EST_StoneWard";

	private const string ShieldWallKey = "EST_ShieldWall";

	private static float masterworkSwing = -99f;

	private static bool masterworkProc;

	private static float talentSpeed;

	private static float bubbleLeft = -1f;

	private static float lastPoisonAt = -99f;

	private static float bubbleFxAt = -99f;

	private static Vector3 runeMarker;

	private static float runeMarkerUntil;

	private static bool veilStrikeUsed;

	private static bool wasRaging;

	internal static float Shield;

	internal static float ShieldMax;

	private static Character huntTarget;

	private static float huntTargetUntil;

	private static readonly Dictionary<Character, float> marked = new Dictionary<Character, float>();

	private static readonly Dictionary<Character, float> sundered = new Dictionary<Character, float>();

	private static float baseExploreRadius = -1f;

	private static StatusEffect lastRested;

	private static StatusEffect lastBurning;

	private static float burnLingerUntil = -99f;

	private static float lastMovedAt;

	private static float echoSwing;

	private static float markPulseAt;

	private static int echoCount;

	private static readonly Dictionary<Character, float> runeMarks = new Dictionary<Character, float>();

	private static readonly FieldRef<Character, bool> IceShoes = AccessTools.FieldRefAccess<Character, bool>("m_iceShoes");

	private static bool gripForced;

	private static readonly FieldRef<Player, bool> UnderRoof = AccessTools.FieldRefAccess<Player, bool>("m_underRoof");

	private static bool lastEmberFed;

	private static readonly FieldRef<Player, bool> RoofAsh = AccessTools.FieldRefAccess<Player, bool>("m_underRoof");

	private static bool nearBed40;

	private static bool nearBed50;

	private static bool nearBase30;

	private static bool nearTrader;

	private static bool nearOre;

	private static bool nearFire;

	private static float scanTimer;

	private static float auraTimer;

	private static readonly int HearthsongLook = StringExtensionMethods.GetStableHashCode("RotR_HearthsongLook");

	private static bool miningContext;

	private const float CinderSlamRadius = 4f;

	private static readonly FieldRef<Humanoid, bool> SecondaryAttack = AccessTools.FieldRefAccess<Humanoid, bool>("m_currentAttackIsSecondary");

	private const string WoodYieldKey = "EST_WoodYield";

	private static DropTable woodDropTable;

	private static int woodBonus;

	private const string WolfTameKey = "EST_WolfTame";

	private const string TameKey = "EST_TameSpeed";

	private const string ElementFollowupKey = "EST_ElementFollowup";

	private static readonly FieldRef<SE_Burning, float> RemainingFire = AccessTools.FieldRefAccess<SE_Burning, float>("m_fireDamageLeft");

	private static readonly FieldRef<SE_Burning, float> FirePerTick = AccessTools.FieldRefAccess<SE_Burning, float>("m_fireDamagePerHit");

	private static float speedBase = 1f;

	private static float speedEnd = -1f;

	private static bool speedOn;

	internal static float CritChance => Plugin.CritChance.Value / 100f;

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

	private static bool BeastcallOn(ZNetView nv)
	{
		if (nv.GetZDO().GetLong("RotR.BeastcallUntil", 0L) <= 0)
		{
			return nv.GetZDO().GetLong("RotR.BeastBoostUntil", 0L) > 0;
		}
		return true;
	}

	private static float V(string k)
	{
		return Talents.V(k);
	}

	private static bool Has(string k)
	{
		return Talents.V(k) > 0f;
	}

	private static bool IsLocal(Character c)
	{
		if ((Object)(object)c != (Object)null)
		{
			return (Object)(object)c == (Object)(object)Player.m_localPlayer;
		}
		return false;
	}

	private static bool IsSpell(SkillType s)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Invalid comparison between Unknown and I4
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Invalid comparison between Unknown and I4
		if ((int)s != 9)
		{
			return (int)s == 10;
		}
		return true;
	}

	private static bool IsRangedWeapon(ItemData w)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Invalid comparison between Unknown and I4
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Invalid comparison between Unknown and I4
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		if (w != null)
		{
			if ((int)w.m_shared.m_skillType != 8 && (int)w.m_shared.m_skillType != 14)
			{
				return IsSpell(w.m_shared.m_skillType);
			}
			return true;
		}
		return false;
	}

	private static bool InRain(Player p)
	{
		if ((Object)(object)EnvMan.instance != (Object)null && EnvMan.IsWet() && !UnderRoof.Invoke(p))
		{
			return !((Character)p).InInterior();
		}
		return false;
	}

	private static bool GearIceShoes(Player p)
	{
		foreach (ItemData equippedItem in ((Humanoid)p).GetInventory().GetEquippedItems())
		{
			if (equippedItem.m_shared.m_iceShoes)
			{
				return true;
			}
		}
		return false;
	}

	private static bool AshBurning(Player p)
	{
		if (!((Character)p).GetSEMan().HaveStatusEffect(Burning) && !(Time.time < burnLingerUntil))
		{
			return EmberFed(p);
		}
		return true;
	}

	private static bool EmberFed(Player p)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Invalid comparison between Unknown and I4
		if (Talents.ActiveTree(0)?.Race != "ashkin" || ((Character)p).InInterior() || UnderRoofAsh(p) || (int)p.GetCurrentBiome() != 32)
		{
			return false;
		}
		EnvSetup val = (((Object)(object)EnvMan.instance != (Object)null) ? EnvMan.instance.GetCurrentEnvironment() : null);
		string text = val?.m_name?.ToLowerInvariant() ?? "";
		bool flag = text.Contains("ash") && (text.Contains("rain") || text.Contains("storm"));
		if (flag != lastEmberFed)
		{
			lastEmberFed = flag;
			Plugin.Log.LogInfo((object)("Ember-fed " + (flag ? "on" : "off") + " (weather: " + val?.m_name + ")"));
		}
		return flag;
	}

	private static bool UnderRoofAsh(Player p)
	{
		return RoofAsh.Invoke(p);
	}

	internal static void Register()
	{
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Expected O, but got Unknown
		template = ScriptableObject.CreateInstance<SE_Stats>();
		((Object)template).name = "EST_Talents";
		((StatusEffect)template).m_name = "Talents";
		((StatusEffect)template).m_icon = null;
		((StatusEffect)template).m_ttl = 0f;
		seHash = StringExtensionMethods.GetStableHashCode(((Object)template).name);
		ItemManager.Instance.AddStatusEffect(new CustomStatusEffect((StatusEffect)(object)template, false));
		RacesBridge.PowerUsed += OnPowerUsed;
	}

	internal static void RegisterRpc()
	{
		TalentVfx.RegisterRpc();
		ZRoutedRpc.instance.Register<ZPackage>("EST_Kill", (Action<long, ZPackage>)delegate(long sender, ZPackage pkg)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Vector3 pos = pkg.ReadVector3();
				float xp = pkg.ReadSingle();
				string boss = pkg.ReadString();
				string prefab = pkg.ReadString();
				string displayName = pkg.ReadString();
				Progress.OnKill(pos, xp, boss, prefab, displayName);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)ex);
			}
		});
		ZRoutedRpc.instance.Register<Vector3, float>("EST_Reveal", (Action<long, Vector3, float>)delegate(long sender, Vector3 pos, float radius)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && !((Object)(object)Minimap.instance == (Object)null) && !(Vector3.Distance(((Component)localPlayer).transform.position, pos) > 30f))
			{
				MinimapExplore.Invoke(Minimap.instance, new object[2] { pos, radius });
				((Character)localPlayer).Message((MessageType)1, "Shared Vision: the land is revealed", 0, (Sprite)null, false);
			}
		});
	}

	private static void OnPowerUsed(string power, Vector3 at)
	{
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Expected O, but got Unknown
		//IL_011b: 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_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0347: Unknown result type (might be due to invalid IL or missing references)
		//IL_0348: Unknown result type (might be due to invalid IL or missing references)
		//IL_035d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0215: Invalid comparison between Unknown and I4
		//IL_021e: 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)
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null)
		{
			return;
		}
		try
		{
			switch (power)
			{
			case "CinderBurst":
			{
				float num3 = V("cinder.ignite");
				if (num3 > 0f)
				{
					StatusEffect obj = ((Character)localPlayer).GetSEMan().AddStatusEffect(Burning, true, 0, 0f, (short)(-1));
					SE_Burning val3 = (SE_Burning)(object)((obj is SE_Burning) ? obj : null);
					if (val3 != null)
					{
						val3.AddFireDamage(num3);
					}
				}
				break;
			}
			case "GlacierSkin":
				if (!Has("cap.avalanche"))
				{
					break;
				}
				TalentVfx.Play(at, TalentVfx.Effect.Frost, 6f);
				{
					foreach (Character item in Enemies(localPlayer, at, 6f))
					{
						HitData val = new HitData();
						val.m_damage.m_frost = 5f;
						val.m_staggerMultiplier = 10f;
						val.m_point = item.GetCenterPoint();
						Vector3 val2 = ((Component)item).transform.position - at;
						val.m_dir = ((Vector3)(ref val2)).normalized;
						val.SetAttacker((Character)(object)localPlayer);
						item.Damage(val);
					}
					break;
				}
			case "Bogveil":
				veilStrikeUsed = false;
				if (Has("cap.eternalMist"))
				{
					StatusEffect statusEffect = ((Character)localPlayer).GetSEMan().GetStatusEffect(StringExtensionMethods.GetStableHashCode("RotR_Bogveil"));
					if ((Object)(object)statusEffect != (Object)null)
					{
						statusEffect.m_ttl = 3600f;
					}
				}
				break;
			case "Beastcall":
				if (!Has("cap.lordWild"))
				{
					break;
				}
				{
					foreach (Character allCharacter in Character.GetAllCharacters())
					{
						if (!((Object)(object)allCharacter == (Object)null) && !allCharacter.IsPlayer() && !allCharacter.IsTamed() && !allCharacter.IsBoss() && (int)allCharacter.m_faction == 1 && !(Vector3.Distance(((Component)allCharacter).transform.position, at) > 30f))
						{
							MonsterAI component = ((Component)allCharacter).GetComponent<MonsterAI>();
							if ((Object)(object)component != (Object)null)
							{
								SetAlerted?.Invoke(component, new object[1] { false });
								TargetCreature?.SetValue(component, null);
							}
						}
					}
					break;
				}
			case "RuneSight":
			{
				if (V("runesight.mark") > 0f)
				{
					runeMarks.Clear();
				}
				if (V("runesight.mark") > 0f)
				{
					foreach (Character item2 in Enemies(localPlayer, at, 40f))
					{
						runeMarks[item2] = Time.time + 15f;
						TalentVfx.Play(item2.GetCenterPoint(), TalentVfx.Effect.Ward, 0.8f);
					}
				}
				float num = V("runesight.eitr");
				if (num > 0f)
				{
					((Character)localPlayer).AddEitr(num);
				}
				if (Has("cap.allSeeing"))
				{
					runeMarker = at;
					runeMarkerUntil = Time.time + 60f;
					TalentVfx.Play(at, TalentVfx.Effect.Ward, 20f);
				}
				float num2 = V("runesight.repair");
				if (!(num2 > 0f))
				{
					break;
				}
				{
					foreach (ItemData allItem in ((Humanoid)localPlayer).GetInventory().GetAllItems())
					{
						if (allItem.m_equipped && allItem.m_shared.m_useDurability && Durability.IsStaff(allItem))
						{
							allItem.m_durability = Mathf.Min(allItem.GetMaxDurability(), allItem.m_durability + allItem.GetMaxDurability() * num2);
						}
					}
					break;
				}
			}
			case "BerserkirRage":
				rageKillSeconds = 0;
				break;
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
		}
	}

	private static IEnumerable<Character> Enemies(Player p, Vector3 at, float r)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		foreach (Character item in Character.GetAllCharacters().ToList())
		{
			if ((Object)(object)item != (Object)null && !item.IsDead() && !item.IsPlayer() && !item.IsTamed() && Vector3.Distance(((Component)item).transform.position, at) <= r && BaseAI.IsEnemy((Character)(object)p, item))
			{
				yield return item;
			}
		}
	}

	internal static void Tick(Player p)
	{
		Progress.CheckGates();
		Refresh(p);
	}

	internal static void Refresh(Player p)
	{
		//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0425: Unknown result type (might be due to invalid IL or missing references)
		//IL_042b: Invalid comparison between Unknown and I4
		if ((Object)(object)p == (Object)null || (Object)(object)p != (Object)(object)Player.m_localPlayer || !Progress.Loaded || ((Character)p).IsDead())
		{
			return;
		}
		Scan(p);
		float num = V("poison.bubble");
		if (num <= 0f)
		{
			bubbleLeft = -1f;
		}
		else if (bubbleLeft < num && Time.time - lastPoisonAt > 30f)
		{
			bubbleLeft = num;
		}
		ZNetView component = ((Component)p).GetComponent<ZNetView>();
		if ((Object)(object)component != (Object)null && component.IsValid() && component.IsOwner())
		{
			float num2 = V("cap.stoneWard");
			if (!Mathf.Approximately(component.GetZDO().GetFloat("EST_StoneWard", 0f), num2))
			{
				component.GetZDO().Set("EST_StoneWard", num2);
			}
		}
		SEMan sEMan = ((Character)p).GetSEMan();
		StatusEffect statusEffect = sEMan.GetStatusEffect(seHash);
		SE_Stats val = (SE_Stats)(object)((statusEffect is SE_Stats) ? statusEffect : null);
		if ((Object)(object)val == (Object)null)
		{
			StatusEffect obj = sEMan.AddStatusEffect(seHash, false, 0, 0f, (short)0);
			val = (SE_Stats)(object)((obj is SE_Stats) ? obj : null);
		}
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		bool flag = Talents.AtHome(p);
		bool flag2 = AshBurning(p);
		bool flag3 = RacesBridge.Pieces(p, "heavy") > 0;
		val.m_healthRegenMultiplier = 1f + V("regen.hp") + (nearBase30 ? V("regen.nearBase") : 0f);
		bool flag4 = ArtisanCompat.IsPickaxe(((Humanoid)p).GetCurrentWeapon());
		val.m_staminaRegenMultiplier = 1f + V("regen.stam") + (InRain(p) ? V("rain.stam") : 0f) + (Night ? V("regen.stam.night") : 0f) + (nearBase30 ? V("regen.nearBase") : 0f) + (flag4 ? V("regen.stam.pick") : 0f) + (ForestEmbraceActive(p, flag) ? V("cap.forestEmbrace") : 0f);
		val.m_eitrRegenMultiplier = 1f + V("regen.eitr") + (flag ? V("mist.eitr") : 0f) + ((Time.time - lastMovedAt >= 2f) ? V("eitr.still") : 0f);
		talentSpeed = V("speed.move") + V("speed.lightPiece") * (float)RacesBridge.Pieces(p, "light") + (flag2 ? V("cap.emberborn") : 0f) + ((Has("cap.bogwalker") && ((Character)p).InWater() && !((Character)p).IsSwimming()) ? 0.3f : 0f);
		val.m_speedModifier = talentSpeed + (((Character)p).IsCrouching() ? V("speed.sneak") : 0f);
		val.m_sneakStaminaUseModifier = 0f - V("stam.sneak");
		val.m_blockStaminaUseModifier = 0f - (V("stam.block") + ((nearFire && sEMan.HaveStatusEffect(Rested)) ? V("hearth.block") : 0f));
		val.m_addMaxCarryWeight = V("carry");
		float num3 = (flag ? V("stam.runjump.home") : 0f) + (flag3 ? V("stam.heavy") : 0f);
		val.m_runStaminaDrainModifier = 0f - num3;
		val.m_jumpStaminaUseModifier = 0f - num3;
		val.m_dodgeStaminaUseModifier = 0f - (flag3 ? V("stam.heavy") : 0f);
		val.m_swimStaminaUseModifier = 0f - V("stam.swim");
		val.m_homeItemStaminaUseModifier = 0f - V("stam.tool");
		val.m_stealthModifier = 0f - V("sneak.stealth");
		val.m_fallDamageModifier = 0f - V("fall");
		val.m_jumpModifier = new Vector3(0f, V("jump"), 0f);
		if ((Object)(object)Minimap.instance != (Object)null)
		{
			if (baseExploreRadius < 0f)
			{
				baseExploreRadius = ExploreRadius.Invoke(Minimap.instance);
			}
			float num4 = V("map.explore") * (((int)p.GetCurrentBiome() == 8) ? 2f : 1f);
			ExploreRadius.Invoke(Minimap.instance) = baseExploreRadius * (1f + num4);
		}
	}

	private static void Scan(Player p)
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: 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_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		scanTimer -= 1f;
		if (scanTimer > 0f)
		{
			return;
		}
		scanTimer = 2f;
		Vector3 position = ((Component)p).transform.position;
		long playerID = p.GetPlayerID();
		nearBed40 = (nearBed50 = (nearBase30 = (nearTrader = (nearOre = false))));
		Bed[] array = Object.FindObjectsByType<Bed>((FindObjectsSortMode)0);
		foreach (Bed val in array)
		{
			float num = Vector3.Distance(((Component)val).transform.position, position);
			if (num <= 30f)
			{
				nearBase30 = true;
			}
			if (!(BedOwner == null) && BedOwner.Invoke(val, null) is long num2 && num2 == playerID)
			{
				if (num <= 40f)
				{
					nearBed40 = true;
				}
				if (num <= 50f)
				{
					nearBed50 = true;
				}
			}
		}
		nearFire = (Object)(object)EffectArea.IsPointInsideArea(position, (Type)1, 3f) != (Object)null || (Object)(object)EffectArea.IsPointInsideArea(position, (Type)2, 3f) != (Object)null;
		if ((Object)(object)EffectArea.IsPointInsideArea(position, (Type)1, 30f) != (Object)null)
		{
			nearBase30 = true;
		}
		Trader[] array2 = Object.FindObjectsByType<Trader>((FindObjectsSortMode)0);
		for (int i = 0; i < array2.Length; i++)
		{
			if (Vector3.Distance(((Component)array2[i]).transform.position, position) <= 20f)
			{
				nearTrader = true;
				break;
			}
		}
		if (!Has("cap.livingVein"))
		{
			return;
		}
		MineRock5[] array3 = Object.FindObjectsByType<MineRock5>((FindObjectsSortMode)0);
		for (int i = 0; i < array3.Length; i++)
		{
			if (Vector3.Distance(((Component)array3[i]).transform.position, position) <= 6f)
			{
				nearOre = true;
				break;
			}
		}
		if (nearOre)
		{
			return;
		}
		MineRock[] array4 = Object.FindObjectsByType<MineRock>((FindObjectsSortMode)0);
		for (int i = 0; i < array4.Length; i++)
		{
			if (Vector3.Distance(((Component)array4[i]).transform.position, position) <= 6f)
			{
				nearOre = true;
				break;
			}
		}
	}

	internal static void Update(Player p)
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e8: Invalid comparison between Unknown and I4
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f0: Unknown result type (might be due to invalid IL or missing references)
		if (!Progress.Loaded || ((Character)p).IsDead())
		{
			return;
		}
		float deltaTime = Time.deltaTime;
		SEMan sEMan = ((Character)p).GetSEMan();
		bool flag = RacesBridge.PowerActive(p, "GlacierSkin");
		bool raging = RacesBridge.Raging;
		if (wasRaging && !raging)
		{
			rageKillSeconds = 0;
		}
		wasRaging = raging;
		if (((Character)p).IsCrouching())
		{
			lastStealth = (lastSneak = Time.time);
		}
		Vector3 velocity = ((Character)p).GetVelocity();
		if (((Vector3)(ref velocity)).magnitude > 0.3f || ((Character)p).InAttack())
		{
			lastMovedAt = Time.time;
		}
		if (runeMarks.Count > 0 && Time.time >= markPulseAt)
		{
			markPulseAt = Time.time + 2.5f;
			foreach (KeyValuePair<Character, float> runeMark in runeMarks)
			{
				if ((Object)(object)runeMark.Key != (Object)null && !runeMark.Key.IsDead() && runeMark.Value > Time.time)
				{
					TalentVfx.Play(runeMark.Key.GetCenterPoint(), TalentVfx.Effect.Ward, 0.6f);
				}
			}
		}
		if (Has("ice.grip"))
		{
			IceShoes.Invoke((Character)(object)p) = true;
			gripForced = true;
		}
		else if (gripForced)
		{
			gripForced = false;
			IceShoes.Invoke((Character)(object)p) = GearIceShoes(p);
		}
		float num = V("speed.sneak");
		if (num > 0f)
		{
			StatusEffect statusEffect = sEMan.GetStatusEffect(seHash);
			SE_Stats val = (SE_Stats)(object)((statusEffect is SE_Stats) ? statusEffect : null);
			if (val != null)
			{
				val.m_speedModifier = talentSpeed + (((Character)p).IsCrouching() ? num : 0f);
			}
		}
		float num2 = 0f;
		if (Has("cap.shieldWall") && ((Character)p).IsBlocking())
		{
			ItemData val2 = CurrentBlocker((Humanoid)(object)p);
			if (val2 != null && (int)val2.m_shared.m_itemType == 5)
			{
				num2 = V("cap.shieldWall");
			}
		}
		ZNetView component = ((Component)p).GetComponent<ZNetView>();
		if ((Object)(object)component != (Object)null && component.IsValid() && component.IsOwner() && !Mathf.Approximately(component.GetZDO().GetFloat("EST_ShieldWall", 0f), num2))
		{
			component.GetZDO().Set("EST_ShieldWall", num2);
		}
		if ((Object)(object)component != (Object)null && component.IsValid() && component.IsOwner())
		{
			ZDO zDO = component.GetZDO();
			int num3 = (int)V("wood.yield");
			if (zDO.GetInt("EST_WoodYield", 0) != num3)
			{
				zDO.Set("EST_WoodYield", num3);
			}
			float num4 = V("wolf.tame");
			if (!Mathf.Approximately(zDO.GetFloat("EST_WolfTame", 0f), num4))
			{
				zDO.Set("EST_WolfTame", num4);
			}
			float num5 = V("tame.speed");
			if (!Mathf.Approximately(zDO.GetFloat("EST_TameSpeed", 0f), num5))
			{
				zDO.Set("EST_TameSpeed", num5);
			}
			bool flag2 = Has("element.followup");
			if (zDO.GetBool("EST_ElementFollowup", false) != flag2)
			{
				zDO.Set("EST_ElementFollowup", flag2);
			}
		}
		float num6 = V("regen.flat");
		if (flag && Has("cap.livingGlacier"))
		{
			num6 += 2f;
		}
		bool home = Talents.AtHome(p);
		if (ForestEmbraceActive(p, home))
		{
			num6 += 2f;
		}
		if (LivingShadowActive(p, home))
		{
			num6 += 1.5f;
		}
		if (LivingVeinActive(p))
		{
			num6 += 2f;
		}
		if (nearFire && sEMan.HaveStatusEffect(Rested))
		{
			num6 += V("hearth.regen");
		}
		if (AshBurning(p))
		{
			num6 += V("burn.heal");
		}
		if (InRain(p))
		{
			num6 += V("rain.hp");
		}
		if (num6 > 0f && ((Character)p).GetHealth() < ((Character)p).GetMaxHealth())
		{
			((Character)p).Heal(num6 * deltaTime, false);
		}
		if ((Object)(object)sEMan.GetStatusEffect(Burning) != (Object)null)
		{
			if (flag && Has("cap.livingGlacier"))
			{
				sEMan.RemoveStatusEffect(Burning, true);
				burnLingerUntil = -99f;
			}
			else
			{
				burnLingerUntil = Time.time + V("burn.linger");
			}
		}
		if (raging && Has("cap.unstoppable") && sEMan.HaveStatusEffect(FrostSe))
		{
			sEMan.RemoveStatusEffect(FrostSe, true);
		}
		StatusEffect statusEffect2 = sEMan.GetStatusEffect(Rested);
		if ((Object)(object)statusEffect2 != (Object)null && (Object)(object)statusEffect2 != (Object)(object)lastRested)
		{
			lastRested = statusEffect2;
			statusEffect2.m_tt