Decompiled source of Emberskald Races v1.4.17

plugins/EmberskaldRaces.dll

Decompiled 3 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.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using TMPro;
using UnityEngine;
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 OriginalRaces;

internal enum ArmorCategory
{
	None,
	Light,
	Medium,
	Heavy
}
internal static class ArmorClasses
{
	[HarmonyPatch(typeof(Player), "GetEquipmentMovementModifier")]
	private static class MoveSpeed
	{
		[HarmonyPriority(200)]
		private static void Postfix(Player __instance, ref float __result)
		{
			RaceDef race = Effects.GetRace(__instance);
			if (race == null)
			{
				return;
			}
			if (race.Berserk)
			{
				foreach (ItemData item in Worn((Humanoid)(object)__instance))
				{
					if (Of(item) == ArmorCategory.Heavy && item.m_shared.m_movementModifier < 0f)
					{
						__result -= item.m_shared.m_movementModifier;
					}
				}
				return;
			}
			if (!race.ArmorStyle)
			{
				return;
			}
			foreach (ItemData item2 in Worn((Humanoid)(object)__instance))
			{
				if (Of(item2) == ArmorCategory.Light)
				{
					__result += Plugin.LightSpeedPerPiece.Value;
				}
			}
		}
	}

	[HarmonyPatch(typeof(Player), "GetBodyArmor")]
	private static class BodyArmor
	{
		[HarmonyPriority(200)]
		private static void Postfix(Player __instance, ref float __result)
		{
			if (!Effects.Is(__instance, (RaceDef r) => r.ArmorStyle))
			{
				return;
			}
			foreach (ItemData item in Worn((Humanoid)(object)__instance))
			{
				if (Of(item) == ArmorCategory.Medium)
				{
					__result += item.GetArmor() * Plugin.MediumArmorPerPiece.Value;
				}
			}
		}
	}

	internal static readonly Dictionary<string, ArmorCategory> ByPrefab = new Dictionary<string, ArmorCategory>(StringComparer.OrdinalIgnoreCase);

	private static readonly FieldRef<Humanoid, ItemData> Helmet = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_helmetItem");

	private static readonly FieldRef<Humanoid, ItemData> Chest = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_chestItem");

	private static readonly FieldRef<Humanoid, ItemData> Legs = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_legItem");

	private static readonly FieldRef<Humanoid, ItemData> Shoulder = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_shoulderItem");

	private static bool hooked;

	private static bool validated;

	internal static void Load()
	{
		ByPrefab.Clear();
		Fill(Plugin.LightArmor.Value, ArmorCategory.Light);
		Fill(Plugin.MediumArmor.Value, ArmorCategory.Medium);
		Fill(Plugin.HeavyArmor.Value, ArmorCategory.Heavy);
		Fill(Plugin.LightArmorMods.Value, ArmorCategory.Light);
		Fill(Plugin.MediumArmorMods.Value, ArmorCategory.Medium);
		Fill(Plugin.HeavyArmorMods.Value, ArmorCategory.Heavy);
		if (hooked)
		{
			return;
		}
		hooked = true;
		ConfigEntry<string>[] array = new ConfigEntry<string>[6]
		{
			Plugin.LightArmor,
			Plugin.MediumArmor,
			Plugin.HeavyArmor,
			Plugin.LightArmorMods,
			Plugin.MediumArmorMods,
			Plugin.HeavyArmorMods
		};
		for (int i = 0; i < array.Length; i++)
		{
			array[i].SettingChanged += delegate
			{
				Load();
				validated = false;
			};
		}
	}

	private static void Fill(string list, ArmorCategory cat)
	{
		string[] array = (list ?? "").Split(new char[1] { ',' });
		for (int i = 0; i < array.Length; i++)
		{
			string text = array[i].Trim();
			if (text.Length > 0)
			{
				ByPrefab[text] = cat;
			}
		}
	}

	internal static ArmorCategory Of(ItemData item)
	{
		if (item == null || (Object)(object)item.m_dropPrefab == (Object)null)
		{
			return ArmorCategory.None;
		}
		if (!ByPrefab.TryGetValue(((Object)item.m_dropPrefab).name, out var value))
		{
			return ArmorCategory.None;
		}
		return value;
	}

	internal static IEnumerable<ItemData> Worn(Humanoid h)
	{
		ItemData val = Helmet.Invoke(h);
		if (val != null)
		{
			yield return val;
		}
		ItemData val2 = Chest.Invoke(h);
		if (val2 != null)
		{
			yield return val2;
		}
		ItemData val3 = Legs.Invoke(h);
		if (val3 != null)
		{
			yield return val3;
		}
		ItemData val4 = Shoulder.Invoke(h);
		if (val4 != null)
		{
			yield return val4;
		}
	}

	internal static void Validate()
	{
		if (validated || (Object)(object)ObjectDB.instance == (Object)null || ObjectDB.instance.m_items.Count == 0)
		{
			return;
		}
		validated = true;
		HashSet<string> names = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
		foreach (GameObject item in ObjectDB.instance.m_items)
		{
			if ((Object)(object)item != (Object)null)
			{
				names.Add(((Object)item).name);
			}
		}
		List<string> list = new List<string>();
		string[] array = new string[3]
		{
			Plugin.LightArmor.Value,
			Plugin.MediumArmor.Value,
			Plugin.HeavyArmor.Value
		};
		for (int i = 0; i < array.Length; i++)
		{
			string[] array2 = (array[i] ?? "").Split(new char[1] { ',' });
			for (int j = 0; j < array2.Length; j++)
			{
				string text = array2[j].Trim();
				if (text.Length > 0)
				{
					list.Add(text);
				}
			}
		}
		List<string> list2 = list.FindAll((string n) => !names.Contains(n));
		int num = 0;
		foreach (string key in ByPrefab.Keys)
		{
			if (names.Contains(key))
			{
				num++;
			}
		}
		if (list2.Count > 0)
		{
			Plugin.Log.LogWarning((object)("Armor classes: no item named " + string.Join(", ", list2)));
		}
		Plugin.Log.LogInfo((object)("Armor classes: " + num + " of " + ByPrefab.Count + " listed armor pieces are in this game (mod pieces count only when that mod is installed)."));
	}
}
internal static class AuraFx
{
	private static GameObject holder;

	private static readonly MethodInfo Clone = AccessTools.Method(typeof(object), "MemberwiseClone", (Type[])null, (Type[])null);

	internal static EffectList Tinted(EffectList src, Color c, string tag)
	{
		//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_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Expected O, but got Unknown
		if (src?.m_effectPrefabs == null)
		{
			return null;
		}
		return new EffectList
		{
			m_effectPrefabs = ((IEnumerable<EffectData>)src.m_effectPrefabs).Select((Func<EffectData, EffectData>)delegate(EffectData e)
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Expected O, but got Unknown
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				if (e == null)
				{
					return (EffectData)null;
				}
				EffectData val = (EffectData)Clone.Invoke(e, null);
				if ((Object)(object)e.m_prefab != (Object)null && (Object)(object)e.m_prefab.GetComponent<ZNetView>() == (Object)null)
				{
					val.m_prefab = TintCopy(e.m_prefab, c, tag);
				}
				return val;
			}).ToArray()
		};
	}

	private static GameObject TintCopy(GameObject prefab, Color c, string tag)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Expected O, but got Unknown
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)holder == (Object)null)
		{
			holder = new GameObject("RotR_AuraFx");
			holder.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)holder);
		}
		GameObject val = Object.Instantiate<GameObject>(prefab, holder.transform, false);
		((Object)val).name = ((Object)prefab).name + "_" + tag;
		ParticleSystem[] componentsInChildren = val.GetComponentsInChildren<ParticleSystem>(true);
		foreach (ParticleSystem obj in componentsInChildren)
		{
			MainModule main = obj.main;
			((MainModule)(ref main)).startColor = Tint(((MainModule)(ref main)).startColor, c);
			ColorOverLifetimeModule colorOverLifetime = obj.colorOverLifetime;
			if (((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled)
			{
				((ColorOverLifetimeModule)(ref colorOverLifetime)).color = Tint(((ColorOverLifetimeModule)(ref colorOverLifetime)).color, c);
			}
		}
		Renderer[] componentsInChildren2 = val.GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val2 in componentsInChildren2)
		{
			Material[] sharedMaterials = val2.sharedMaterials;
			for (int j = 0; j < sharedMaterials.Length; j++)
			{
				if ((Object)(object)sharedMaterials[j] == (Object)null)
				{
					continue;
				}
				Material val3 = new Material(sharedMaterials[j]);
				string[] array = new string[3] { "_Color", "_TintColor", "_EmissionColor" };
				foreach (string text in array)
				{
					if (val3.HasProperty(text))
					{
						val3.SetColor(text, TintColor(val3.GetColor(text), c));
					}
				}
				sharedMaterials[j] = val3;
			}
			val2.sharedMaterials = sharedMaterials;
		}
		Light[] componentsInChildren3 = val.GetComponentsInChildren<Light>(true);
		for (int i = 0; i < componentsInChildren3.Length; i++)
		{
			componentsInChildren3[i].color = c;
		}
		return val;
	}

	private static Color TintColor(Color o, Color c)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Max(o.r, Mathf.Max(o.g, o.b));
		return new Color(c.r * num, c.g * num, c.b * num, o.a);
	}

	private static Gradient TintGradient(Gradient g, Color c)
	{
		//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_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Expected O, but got Unknown
		if (g == null)
		{
			return null;
		}
		Gradient val = new Gradient
		{
			mode = g.mode
		};
		val.SetKeys(((IEnumerable<GradientColorKey>)g.colorKeys).Select((Func<GradientColorKey, GradientColorKey>)((GradientColorKey k) => new GradientColorKey(TintColor(k.color, c), k.time))).ToArray(), g.alphaKeys);
		return val;
	}

	private static MinMaxGradient Tint(MinMaxGradient g, Color c)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected I4, but got Unknown
		//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_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//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)
		ParticleSystemGradientMode mode = ((MinMaxGradient)(ref g)).mode;
		return (MinMaxGradient)((int)mode switch
		{
			0 => new MinMaxGradient(TintColor(((MinMaxGradient)(ref g)).color, c)), 
			2 => new MinMaxGradient(TintColor(((MinMaxGradient)(ref g)).colorMin, c), TintColor(((MinMaxGradient)(ref g)).colorMax, c)), 
			1 => new MinMaxGradient(TintGradient(((MinMaxGradient)(ref g)).gradient, c)), 
			3 => new MinMaxGradient(TintGradient(((MinMaxGradient)(ref g)).gradientMin, c), TintGradient(((MinMaxGradient)(ref g)).gradientMax, c)), 
			_ => new MinMaxGradient(c), 
		});
	}
}
internal static class Berserkir
{
	[HarmonyPatch(typeof(Player), "AddAdrenaline")]
	private static class BlockNativeAdrenaline
	{
		private static bool Prefix(Player __instance)
		{
			return !IsBerserk(__instance);
		}
	}

	[HarmonyPatch(typeof(Player), "GetMaxAdrenaline")]
	private static class MaxAdrenalineBar
	{
		[HarmonyPriority(200)]
		private static void Postfix(Player __instance, ref float __result)
		{
			if (IsBerserk(__instance) && Plugin.ShowAdrenalineHud.Value)
			{
				__result = MaxAdrenaline;
			}
		}
	}

	[HarmonyPatch(typeof(Character), "Damage")]
	private static class HitDealt
	{
		[HarmonyPriority(200)]
		private static void Postfix(Character __instance, HitData hit)
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && !((Object)(object)__instance == (Object)(object)localPlayer) && hit != null && IsBerserk(localPlayer) && !((Object)(object)hit.GetAttacker() != (Object)(object)localPlayer) && !__instance.IsDead())
			{
				OnHitDealt(localPlayer);
			}
		}
	}

	[HarmonyPatch(typeof(Character), "ApplyDamage")]
	private static class HitTaken
	{
		[HarmonyPriority(200)]
		private static void Postfix(Character __instance, HitData hit)
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)__instance != (Object)(object)localPlayer || !IsBerserk(localPlayer))
			{
				return;
			}
			if (raging && ((Character)localPlayer).GetHealth() < 1f)
			{
				((Character)localPlayer).SetHealth(1f);
			}
			if (hit != null && !((Object)(object)hit.GetAttacker() == (Object)(object)localPlayer) && !(hit.GetTotalDamage() <= 0f))
			{
				lastCombat = Time.time;
				if (!raging)
				{
					Adrenaline = Mathf.Min(MaxAdrenaline, Adrenaline + Plugin.AdrenalinePerHitTaken.Value + TalentHooks.V("adr.taken"));
				}
			}
		}
	}

	[HarmonyPatch(typeof(Character), "CheckDeath")]
	private static class NoDeathInRage
	{
		private static bool Prefix(Character __instance)
		{
			if (!raging || (Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return true;
			}
			if (__instance.GetHealth() <= 0f)
			{
				__instance.SetHealth(1f);
			}
			return false;
		}
	}

	[HarmonyPatch(typeof(Attack), "GetAttackStamina")]
	private static class AxeStamina
	{
		[HarmonyPriority(200)]
		private static void Postfix(Attack __instance, ref float __result)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Invalid comparison between Unknown and I4
			Humanoid obj = AttackChar.Invoke(__instance);
			Player val = (Player)(object)((obj is Player) ? obj : null);
			ItemData val2 = AttackWeapon.Invoke(__instance);
			if (!((Object)(object)val == (Object)null) && val2 != null && (int)val2.m_shared.m_skillType == 7 && IsBerserk(val))
			{
				__result *= Mathf.Clamp01(1f - Plugin.AxeStaminaPercent.Value / 100f);
			}
		}
	}

	[HarmonyPatch(typeof(CharacterAnimEvent), "CustomFixedUpdate")]
	private static class FrenzySpeed
	{
		[HarmonyPriority(200)]
		private static void Postfix(CharacterAnimEvent __instance)
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)AnimCharField.Invoke(__instance) != (Object)(object)localPlayer)
			{
				return;
			}
			Animator val = AnimField.Invoke(__instance);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			if (stacks > 0 && ((Character)localPlayer).InAttack() && IsFrenzyWeapon(((Humanoid)localPlayer).GetCurrentWeapon()))
			{
				if (!(val.speed < 0.01f))
				{
					if (!Mathf.Approximately(val.speed, lastSet))
					{
						lastBase = val.speed;
					}
					lastSet = lastBase * (1f + (float)stacks * FrenzySpeedPerStack);
					val.speed = lastSet;
				}
			}
			else if (lastSet > 0f)
			{
				if (Mathf.Approximately(val.speed, lastSet))
				{
					val.speed = lastBase;
				}
				lastSet = 0f;
			}
		}
	}

	[HarmonyPatch(typeof(Humanoid), "EquipItem")]
	private static class NoTrinkets
	{
		private static bool Prefix(Humanoid __instance, ItemData item, ref bool __result)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			if (item == null || (int)item.m_shared.m_itemType != 24)
			{
				return true;
			}
			Player val = (Player)(object)((__instance is Player) ? __instance : null);
			if (!IsBerserk(val))
			{
				return true;
			}
			if ((Object)(object)val == (Object)(object)Player.m_localPlayer)
			{
				((Character)val).Message((MessageType)2, "Berserkir cannot wear trinkets", 0, (Sprite)null, false);
			}
			__result = false;
			return false;
		}
	}

	internal static float Adrenaline;

	private static float lastCombat = -999f;

	private static float decayTimer;

	private static bool raging;

	private static bool mirrored;

	private static float rageEnds;

	private static int streak;

	private static int stacks;

	private static float lastHit = -999f;

	private static SE_Stats rage;

	private static Vector2? hudOrigin;

	private static readonly FieldRef<Player, float> AdrenalineField = AccessTools.FieldRefAccess<Player, float>("m_adrenaline");

	private static readonly FieldRef<Humanoid, ItemData> TrinketField = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_trinketItem");

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

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

	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 float lastSet;

	private static float lastBase = 1f;

	internal static bool InRage => raging;

	internal static float RageSecondsLeft
	{
		get
		{
			if (!raging)
			{
				return 0f;
			}
			return Mathf.Max(0f, rageEnds - Time.time);
		}
	}

	internal static int FrenzyStacks => stacks;

	internal static float MaxAdrenaline => Mathf.Max(1f, Plugin.AdrenalineMax.Value + TalentHooks.V("adr.max"));

	private static int FrenzyStart => Mathf.Max(1, Plugin.FrenzyStartHit.Value - Mathf.RoundToInt(TalentHooks.V("frenzy.earlier")));

	private static int FrenzyMax => Plugin.FrenzyMaxStacks.Value + Mathf.RoundToInt(TalentHooks.V("frenzy.stacks"));

	internal static float FrenzySpeedPerStack => Plugin.FrenzySpeedPerStack.Value + TalentHooks.V("frenzy.speed");

	internal static float RageSeconds => Plugin.RageSeconds.Value + TalentHooks.V("power.duration");

	private static bool InCombat => Time.time - lastCombat < 8f;

	internal static void ExtendRage(float seconds)
	{
		if (raging && !(seconds <= 0f))
		{
			rageEnds += seconds;
			Player localPlayer = Player.m_localPlayer;
			StatusEffect val = (((Object)(object)localPlayer != (Object)null) ? ((Character)localPlayer).GetSEMan().GetStatusEffect(((StatusEffect)rage).NameHash()) : null);
			if ((Object)(object)val != (Object)null)
			{
				val.m_ttl += seconds;
			}
		}
	}

	private static bool IsBerserk(Player p)
	{
		if ((Object)(object)p != (Object)null)
		{
			return Effects.Is(p, (RaceDef r) => r.Berserk);
		}
		return false;
	}

	internal static StatusEffect BuildRage()
	{
		rage = ScriptableObject.CreateInstance<SE_Stats>();
		((Object)rage).name = "RotR_BerserkirRage";
		((StatusEffect)rage).m_name = "Berserkir Rage";
		((StatusEffect)rage).m_tooltip = "Nothing can kill you while the rage lasts. Every blow costs blood.";
		((StatusEffect)rage).m_icon = Portraits.PowerIcon(PowerKind.BerserkirRage) ?? Portraits.Icon("berserkir");
		return (StatusEffect)(object)rage;
	}

	private static bool IsFrenzyWeapon(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_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		if (w == null || (int)w.m_shared.m_skillType != 7)
		{
			return false;
		}
		if (Plugin.FrenzyAllAxes.Value)
		{
			return true;
		}
		if ((int)w.m_shared.m_itemType != 22)
		{
			if ((Object)(object)w.m_dropPrefab != (Object)null)
			{
				return ((Object)w.m_dropPrefab).name.ToLowerInvariant().Contains("berzerkr");
			}
			return false;
		}
		return true;
	}

	private static void PayHp(Player p, float percent)
	{
		float num = ((Character)p).GetMaxHealth() * percent / 100f;
		((Character)p).SetHealth(Mathf.Max(1f, ((Character)p).GetHealth() - num));
	}

	internal static void Update(Player p, float dt)
	{
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		if (!IsBerserk(p))
		{
			if (mirrored)
			{
				AdrenalineField.Invoke(p) = 0f;
				mirrored = false;
			}
			Adrenaline = 0f;
			stacks = 0;
			streak = 0;
			raging = false;
			return;
		}
		float time = Time.time;
		float maxAdrenaline = MaxAdrenaline;
		if ((stacks > 0 || streak > 0) && time - lastHit > Plugin.FrenzyDecaySeconds.Value)
		{
			stacks = 0;
			streak = 0;
		}
		if (!raging && Adrenaline >= maxAdrenaline && !((Character)p).IsDead())
		{
			raging = true;
			rageEnds = time + RageSeconds;
			((StatusEffect)rage).m_ttl = RageSeconds;
			rage.m_speedModifier = Plugin.RageSpeed.Value + TalentHooks.V("rage.speed");
			((Character)p).GetSEMan().AddStatusEffect((StatusEffect)(object)rage, true, 0, 0f, (short)(-1));
			PowerVfx.Play(p, PowerVfx.Kind.Rage, 1.5f);
			((Character)p).Message((MessageType)2, "BERSERKIR RAGE", 0, (Sprite)null, false);
			Plugin.Log.LogInfo((object)("Berserkir Rage started (" + RageSeconds + " s)."));
			TalentHooks.RaisePower("BerserkirRage", ((Component)p).transform.position);
		}
		if (raging && (time >= rageEnds || ((Character)p).IsDead()))
		{
			raging = false;
			Adrenaline = Mathf.Max(maxAdrenaline * Mathf.Clamp01(TalentHooks.V("rage.keep")), InCombat ? TalentHooks.V("adr.floor") : 0f);
			((Character)p).GetSEMan().RemoveStatusEffect(((StatusEffect)rage).NameHash(), true);
			float num = TalentHooks.V("rage.healEnd");
			if (num > 0f && !((Character)p).IsDead())
			{
				((Character)p).Heal(((Character)p).GetMaxHealth() * num, true);
			}
			Plugin.Log.LogInfo((object)("Berserkir Rage ended; adrenaline " + Adrenaline.ToString("0") + "."));
			TalentHooks.RaiseRageEnded();
		}
		if (!raging && Adrenaline > 0f && time - lastCombat > 5f)
		{
			decayTimer += dt;
			float num2 = Mathf.Max(0.1f, Plugin.AdrenalineDecaySeconds.Value) / Mathf.Max(0.05f, 1f - TalentHooks.V("adr.decaySlow"));
			float num3 = (InCombat ? TalentHooks.V("adr.floor") : 0f);
			while (decayTimer >= num2)
			{
				decayTimer -= num2;
				Adrenaline = Mathf.Max(Mathf.Min(num3, Adrenaline), Adrenaline - 1f);
			}
		}
		else
		{
			decayTimer = 0f;
		}
		if (Plugin.ShowAdrenalineHud.Value)
		{
			AdrenalineField.Invoke(p) = (raging ? (maxAdrenaline * Mathf.Clamp01((rageEnds - time) / Mathf.Max(1f, RageSeconds))) : Adrenaline);
			mirrored = true;
		}
		else if (mirrored)
		{
			AdrenalineField.Invoke(p) = 0f;
			mirrored = false;
		}
		ApplyHudOffset();
		ItemData val = TrinketField.Invoke((Humanoid)(object)p);
		if (val != null)
		{
			((Humanoid)p).UnequipItem(val, false);
			((Character)p).Message((MessageType)2, "Berserkir cannot wear trinkets", 0, (Sprite)null, false);
		}
	}

	private static void ApplyHudOffset()
	{
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		Hud instance = Hud.instance;
		if ((Object)(object)instance == (Object)null || (Object)(object)instance.m_adrenalineBarRoot == (Object)null)
		{
			hudOrigin = null;
			return;
		}
		RectTransform adrenalineBarRoot = instance.m_adrenalineBarRoot;
		if (!hudOrigin.HasValue)
		{
			hudOrigin = adrenalineBarRoot.anchoredPosition;
		}
		Vector2 val = hudOrigin.Value + new Vector2(Plugin.AdrenalineHudX.Value, Plugin.AdrenalineHudY.Value);
		if (adrenalineBarRoot.anchoredPosition != val)
		{
			adrenalineBarRoot.anchoredPosition = val;
		}
	}

	private static void OnHitDealt(Player p)
	{
		float num = (lastCombat = Time.time);
		if (!raging)
		{
			Adrenaline = Mathf.Min(MaxAdrenaline, Adrenaline + Plugin.AdrenalinePerHitDealt.Value + TalentHooks.V("adr.dealt"));
		}
		else
		{
			PayHp(p, Plugin.RageHitHpPercent.Value * Mathf.Clamp01(1f - TalentHooks.V("rage.hpCost")));
		}
		if (IsFrenzyWeapon(((Humanoid)p).GetCurrentWeapon()))
		{
			if (num - lastHit > Plugin.FrenzyDecaySeconds.Value)
			{
				streak = 0;
				stacks = 0;
			}
			streak++;
			if (streak >= FrenzyStart && stacks < FrenzyMax)
			{
				stacks++;
				PayHp(p, Plugin.FrenzyHpPercent.Value * Mathf.Clamp01(1f - TalentHooks.V("frenzy.hpCost")));
				Plugin.Log.LogDebug((object)("Axe frenzy stack " + stacks + " (+" + ((float)stacks * FrenzySpeedPerStack * 100f).ToString("0") + "% attack speed)"));
			}
		}
		lastHit = num;
	}
}
internal static class CreatureFx
{
	private static readonly Dictionary<string, List<EffectList>> cache = new Dictionary<string, List<EffectList>>();

	internal static void Play(string key, string creature, Func<ItemDrop, int> score, Vector3 at)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		if (!cache.TryGetValue(key, out var value))
		{
			value = (cache[key] = Find(key, creature, score));
		}
		foreach (EffectList item in value)
		{
			try
			{
				item.Create(at, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
			}
			catch (Exception)
			{
			}
		}
	}

	private static List<EffectList> Find(string key, string creature, Func<ItemDrop, int> score)
	{
		//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e2: Expected O, but got Unknown
		List<EffectList> list = new List<EffectList>();
		try
		{
			ZNetScene instance = ZNetScene.instance;
			GameObject val = ((instance != null) ? instance.GetPrefab(creature) : null);
			Humanoid val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Humanoid>() : null);
			if ((Object)(object)val2 == (Object)null)
			{
				Plugin.Log.LogInfo((object)(key + " look: no " + creature));
				return list;
			}
			List<GameObject> list2 = new List<GameObject>();
			if (val2.m_defaultItems != null)
			{
				list2.AddRange(val2.m_defaultItems);
			}
			if (val2.m_randomWeapon != null)
			{
				list2.AddRange(val2.m_randomWeapon);
			}
			if (val2.m_randomSets != null)
			{
				ItemSet[] randomSets = val2.m_randomSets;
				foreach (ItemSet val3 in randomSets)
				{
					if (val3?.m_items != null)
					{
						list2.AddRange(val3.m_items);
					}
				}
			}
			List<ItemDrop> source = (from val7 in list2
				where (Object)(object)val7 != (Object)null
				select val7.GetComponent<ItemDrop>() into d
				where (Object)(object)d != (Object)null
				select d).Distinct().ToList();
			Plugin.Log.LogInfo((object)(key + " look: " + creature + " has " + string.Join(", ", source.Select((ItemDrop d) => ((Object)d).name))));
			ItemDrop val4 = (from d in source
				select new
				{
					d = d,
					s = score(d)
				} into x
				where x.s > 0
				orderby x.s descending
				select x).FirstOrDefault()?.d;
			if ((Object)(object)val4 == (Object)null)
			{
				Plugin.Log.LogInfo((object)(key + " look: no matching ability"));
				return list;
			}
			SharedData shared = val4.m_itemData.m_shared;
			List<object> list3 = new List<object> { shared, shared.m_attack, shared.m_secondaryAttack };
			List<string> list4 = new List<string>();
			Attack[] array = (Attack[])(object)new Attack[2] { shared.m_attack, shared.m_secondaryAttack };
			foreach (Attack val5 in array)
			{
				Projectile val6 = (((Object)(object)val5?.m_attackProjectile != (Object)null) ? val5.m_attackProjectile.GetComponent<Projectile>() : null);
				if (val6?.m_hitEffects != null)
				{
					list3.Add(val6);
				}
			}
			foreach (object item in list3.Where((object o) => o != null))
			{
				foreach (FieldInfo item2 in from f in item.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public)
					where f.FieldType == typeof(EffectList)
					select f)
				{
					object? value = item2.GetValue(item);
					EffectData[] array2 = ((EffectList)(((value is EffectList) ? value : null)?)).m_effectPrefabs?.Where((EffectData e) => e != null && e.m_enabled && (Object)(object)e.m_prefab != (Object)null && Visual(e.m_prefab)).ToArray();
					if (array2 != null && array2.Length != 0)
					{
						list.Add(new EffectList
						{
							m_effectPrefabs = array2
						});
						list4.AddRange(array2.Select((EffectData e) => ((Object)e.m_prefab).name));
					}
				}
			}
			Plugin.Log.LogInfo((object)(key + " look: using " + ((Object)val4).name + " (" + string.Join(", ", list4.Distinct()) + ")"));
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)(key + " look: " + ex.Message));
		}
		return list;
	}

	private static bool Visual(GameObject g)
	{
		if ((Object)(object)g.GetComponentInChildren<ZNetView>(true) == (Object)null && (Object)(object)g.GetComponentInChildren<Aoe>(true) == (Object)null && (Object)(object)g.GetComponentInChildren<Projectile>(true) == (Object)null)
		{
			return (Object)(object)g.GetComponentInChildren<Character>(true) == (Object)null;
		}
		return false;
	}

	private static int Has(ItemDrop d, params string[] words)
	{
		string text = ((Object)d).name.ToLowerInvariant();
		for (int i = 0; i < words.Length; i++)
		{
			if (text.Contains(words[i]))
			{
				return words.Length - i;
			}
		}
		return 0;
	}

	internal static int ShamanHeal(ItemDrop d)
	{
		return Has(d, "heal");
	}

	internal static int FulingArea(ItemDrop d)
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Invalid comparison between Unknown and I4
		int num = Has(d, "fireball", "fire", "aoe", "nova");
		if (num > 0)
		{
			return 10 + num;
		}
		Attack attack = d.m_itemData.m_shared.m_attack;
		if (attack == null || (int)attack.m_attackType != 4)
		{
			return 0;
		}
		return 5;
	}
}
internal static class Dwegir
{
	[HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[] { typeof(int) })]
	private static class LightSlotTooltip
	{
		private static void Postfix(ItemData __instance, ref string __result)
		{
			try
			{
				Player localPlayer = Player.m_localPlayer;
				if (!((Object)(object)localPlayer == (Object)null) && __result != null && IsDwegir(localPlayer))
				{
					Inventory inventory = ((Humanoid)localPlayer).GetInventory();
					if (inventory.ContainsItem(__instance) && InLightSlot(__instance, inventory))
					{
						float weight = __instance.GetWeight(-1);
						float num = weight * Factor;
						__result = __result + "\n<color=#9fd08a>Light slot: weighs " + num.ToString("0.##") + " instead of " + weight.ToString("0.##") + " (-" + Mathf.RoundToInt((1f - Factor) * 100f) + "%)</color>";
					}
				}
			}
			catch (Exception)
			{
			}
		}
	}

	[HarmonyPatch(typeof(Inventory), "GetTotalWeight")]
	private static class LightSlotWeight
	{
		[HarmonyPriority(200)]
		private static void Postfix(Inventory __instance, ref float __result)
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && __instance == ((Humanoid)localPlayer).GetInventory() && IsDwegir(localPlayer))
			{
				__result = Mathf.Max(0f, __result - Saved(__instance));
			}
		}
	}

	[HarmonyPatch(typeof(InventoryGrid), "UpdateGui")]
	private static class FeatherSlots
	{
		[HarmonyPriority(200)]
		private static void Postfix(InventoryGrid __instance, Player player)
		{
			//IL_012f: 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_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				InventoryGui instance = InventoryGui.instance;
				if ((Object)(object)instance == (Object)null || (Object)(object)__instance != (Object)(object)instance.m_playerGrid || (Object)(object)player == (Object)null || GetElement == null)
				{
					return;
				}
				int width = ((Humanoid)player).GetInventory().GetWidth();
				bool flag = IsDwegir(player);
				int[] array = new int[3] { 1, 2, 3 };
				foreach (int num in array)
				{
					bool flag2 = flag && (num < 3 || ThirdSlot);
					if (num >= ((Humanoid)player).GetInventory().GetHeight())
					{
						continue;
					}
					object? obj = GetElement.Invoke(__instance, new object[3]
					{
						width - 1,
						num,
						width
					});
					Component val = (Component)((obj is Component) ? obj : null);
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					Transform val2 = val.transform.Find("RotR_Feather");
					if ((Object)(object)val2 == (Object)null)
					{
						if (!flag2)
						{
							continue;
						}
						Sprite val3 = Portraits.IconSprite("LightSlot");
						if ((Object)(object)val3 == (Object)null)
						{
							break;
						}
						GameObject val4 = new GameObject("RotR_Feather", new Type[1] { typeof(RectTransform) });
						val4.transform.SetParent(val.transform, false);
						Image obj2 = val4.AddComponent<Image>();
						obj2.sprite = val3;
						((Graphic)obj2).raycastTarget = false;
						obj2.preserveAspect = true;
						((Graphic)obj2).color = new Color(0.62f, 0.62f, 0.6f, 0.42f);
						RectTransform val5 = (RectTransform)val4.transform;
						val5.anchorMin = Vector2.zero;
						val5.anchorMax = Vector2.one;
						val5.offsetMin = new Vector2(5f, 5f);
						val5.offsetMax = new Vector2(-5f, -5f);
						val2 = val4.transform;
					}
					if (((Component)val2).gameObject.activeSelf != flag2)
					{
						((Component)val2).gameObject.SetActive(flag2);
					}
					if (val2.GetSiblingIndex() != 0)
					{
						val2.SetSiblingIndex(0);
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Dwegir light slot icons: " + ex.Message));
			}
		}
	}

	[HarmonyPatch(typeof(InventoryGui), "DoCrafting")]
	private static class Craft
	{
		private static void Prefix(Player player)
		{
			before = (((Object)(object)player != (Object)null) ? new HashSet<ItemData>(((Humanoid)player).GetInventory().GetAllItems()) : null);
		}

		[HarmonyPriority(200)]
		private static void Postfix(InventoryGui __instance, Player player)
		{
			if (before == null || !IsDwegir(player))
			{
				before = null;
				return;
			}
			List<ItemData> list = new List<ItemData>();
			foreach (ItemData allItem in ((Humanoid)player).GetInventory().GetAllItems())
			{
				if (!before.Contains(allItem) && allItem.m_crafterID == player.GetPlayerID())
				{
					list.Add(allItem);
				}
			}
			ItemData val = CraftUpgrade.Invoke(__instance);
			if (val != null && !list.Contains(val))
			{
				list.Add(val);
			}
			foreach (ItemData item in list)
			{
				if (item.m_shared.m_useDurability)
				{
					if (item.m_customData == null)
					{
						item.m_customData = new Dictionary<string, string>();
					}
					item.m_customData["RotR.Dwegir"] = "1";
					item.m_durability = item.GetMaxDurability();
					Plugin.Log.LogInfo((object)("Dwegir craft: " + item.m_shared.m_name + " max durability " + item.GetMaxDurability().ToString("0")));
				}
			}
			before = null;
		}
	}

	[HarmonyPatch(typeof(ItemData), "GetMaxDurability", new Type[] { typeof(int) })]
	private static class Durability
	{
		[HarmonyPriority(200)]
		private static void Postfix(ItemData __instance, ref float __result)
		{
			if (__instance.m_customData != null && __instance.m_customData.ContainsKey("RotR.Dwegir"))
			{
				__result *= 1f + Plugin.DwegirDurabilityPercent.Value / 100f;
			}
		}
	}

	[HarmonyPatch(typeof(Player), "GetItemUpgradeChance")]
	private static class UpgradeLuck
	{
		[HarmonyPriority(200)]
		private static void Postfix(Player __instance, ref float __result)
		{
			if (Effects.Is(__instance, (RaceDef r) => r.UpgradeLuck))
			{
				float num = __result;
				__result = Mathf.Max(0f, __result - Plugin.DwegirUpgradeBonus.Value / 100f - (TalentHooks.PowerActive(__instance, "DeepDelve") ? TalentHooks.V("delve.forge") : 0f) - TalentHooks.V("forge.bonus"));
				Plugin.Log.LogInfo((object)("Dwegir forge luck: upgrade roll " + num.ToString("0.00") + " -> " + __result.ToString("0.00") + " (lower is better)."));
			}
		}
	}

	private const string CraftedKey = "RotR.Dwegir";

	private const string PouchKey = "RotR.Pouch";

	private static readonly FieldRef<InventoryGui, ItemData> CraftUpgrade = AccessTools.FieldRefAccess<InventoryGui, ItemData>("m_craftUpgradeItem");

	private static readonly MethodInfo GetElement = AccessTools.Method(typeof(InventoryGrid), "GetElement", new Type[3]
	{
		typeof(int),
		typeof(int),
		typeof(int)
	}, (Type[])null);

	private static HashSet<ItemData> before;

	private static float Factor => Mathf.Clamp01(Plugin.PouchWeightFactor.Value - TalentHooks.V("pouch.factor"));

	private static bool ThirdSlot => TalentHooks.V("pouch.slots") > 0f;

	private static bool IsDwegir(Player p)
	{
		if ((Object)(object)p != (Object)null)
		{
			return Effects.Is(p, (RaceDef r) => r.Pouch);
		}
		return false;
	}

	private static bool IsLightSlot(int x, int y, int width)
	{
		if (x == width - 1)
		{
			switch (y)
			{
			case 3:
				return ThirdSlot;
			default:
				return false;
			case 1:
			case 2:
				return true;
			}
		}
		return false;
	}

	private static bool InLightSlot(ItemData it, Inventory inv)
	{
		if (it != null)
		{
			return IsLightSlot(it.m_gridPos.x, it.m_gridPos.y, inv.GetWidth());
		}
		return false;
	}

	private static float Saved(Inventory inv)
	{
		float num = 0f;
		foreach (ItemData allItem in inv.GetAllItems())
		{
			if (InLightSlot(allItem, inv))
			{
				num += allItem.GetWeight(-1) * (1f - Factor);
			}
		}
		return num;
	}

	internal static string LightSlotsText(Player p)
	{
		if (!((Object)(object)p == (Object)null))
		{
			return "light slots save " + Saved(((Humanoid)p).GetInventory()).ToString("0.#") + " weight";
		}
		return "";
	}

	private static void MigrateOldPouch(Player p)
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Expected O, but got Unknown
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		if (!p.m_customData.TryGetValue("RotR.Pouch", out var value))
		{
			return;
		}
		p.m_customData.Remove("RotR.Pouch");
		if (string.IsNullOrEmpty(value))
		{
			return;
		}
		try
		{
			Inventory val = new Inventory("Dwegir pouch", (Sprite)null, 2, 1);
			val.Load(new ZPackage(Convert.FromBase64String(value)));
			Inventory inventory = ((Humanoid)p).GetInventory();
			int num = 0;
			foreach (ItemData item in new List<ItemData>(val.GetAllItems()))
			{
				if (!inventory.AddItem(item))
				{
					ItemDrop.DropItem(item, item.m_stack, ((Component)p).transform.position + Vector3.up, Quaternion.identity);
				}
				num++;
			}
			if (num > 0)
			{
				((Character)p).Message((MessageType)2, "The Dwegir pouch is gone: its items are back in your inventory. Your 2 light slots (feather, under hotbar slot 8) weigh half.", 0, (Sprite)null, false);
			}
			Plugin.Log.LogInfo((object)("Old Dwegir pouch emptied into the inventory (" + num + " items)."));
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Could not read the old Dwegir pouch: " + ex.Message));
		}
	}

	internal static void Tick(Player p)
	{
		if ((Object)(object)p != (Object)null)
		{
			MigrateOldPouch(p);
		}
	}
}
internal static class Effects
{
	[HarmonyPatch(typeof(ZInput), "GetButtonDown", new Type[] { typeof(string) })]
	private static class PowerKeyNotHolster
	{
		private static bool Prefix(string name, ref bool __result)
		{
			//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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			if (name != "Hide" || (Object)(object)Player.m_localPlayer == (Object)null || GetRace(Player.m_localPlayer) == null)
			{
				return true;
			}
			KeyboardShortcut value = Plugin.PowerKey.Value;
			KeyCode mainKey = ((KeyboardShortcut)(ref value)).MainKey;
			if ((int)mainKey == 0 || !UnityInput.Current.GetKey(mainKey))
			{
				return true;
			}
			__result = false;
			return false;
		}
	}

	internal const string RaceKey = "RotR.Race";

	private const string ReadyKey = "RotR.PowerReadyAt";

	private const string BeastKey = "RotR.BeastcallUntil";

	private static readonly Dictionary<string, SE_Stats> passives = new Dictionary<string, SE_Stats>();

	private static SE_Stats glacier;

	private static SE_Stats bogveil;

	private static SE_Stats recharge;

	private static SE_Stats ready;

	private static SE_Stats hearthsong;

	private static SE_Stats deepDelve;

	private static SE_Stats cinderGlow;

	private static SE_Stats runeGlow;

	private static SE_Stats beastGlow;

	private static bool auraLooks;

	private static readonly FieldInfo SeTime = AccessTools.Field(typeof(StatusEffect), "m_time");

	private static bool hearthVfx;

	private static int lookTick;

	internal static RaceDef GetRace(Player p)
	{
		if ((Object)(object)p == (Object)null || p.m_customData == null)
		{
			return null;
		}
		if (!p.m_customData.TryGetValue("RotR.Race", out var value))
		{
			return null;
		}
		return Races.Get(value);
	}

	internal static bool Is(Player p, Func<RaceDef, bool> test)
	{
		RaceDef race = GetRace(p);
		if (race != null)
		{
			return test(race);
		}
		return false;
	}

	internal static void SetRace(Player p, RaceDef r)
	{
		if (r == null)
		{
			p.m_customData.Remove("RotR.Race");
		}
		else
		{
			p.m_customData["RotR.Race"] = r.Id;
		}
	}

	private static SE_Stats NewSE(string id, string name, string tooltip, string icon)
	{
		SE_Stats obj = ScriptableObject.CreateInstance<SE_Stats>();
		((Object)obj).name = "RotR_" + id;
		((StatusEffect)obj).m_name = name;
		((StatusEffect)obj).m_tooltip = tooltip;
		((StatusEffect)obj).m_icon = Portraits.Icon(icon);
		return obj;
	}

	private static void Add(StatusEffect se)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(se, false));
	}

	internal static void Register()
	{
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		foreach (RaceDef item in Races.All)
		{
			SE_Stats val = NewSE(item.Id, item.Name, "", item.Id);
			FillPassive(val, item);
			passives[item.Id] = val;
			Add((StatusEffect)(object)val);
		}
		glacier = NewSE("GlacierSkin", "Glacier Skin", "Ice hardens over your skin.", "frostborn");
		glacier.m_speedModifier = -0.05f;
		glacier.m_mods = new List<DamageModPair>
		{
			new DamageModPair
			{
				m_type = (DamageType)2,
				m_modifier = (DamageModifier)1
			},
			new DamageModPair
			{
				m_type = (DamageType)4,
				m_modifier = (DamageModifier)1
			},
			new DamageModPair
			{
				m_type = (DamageType)1,
				m_modifier = (DamageModifier)1
			}
		};
		((StatusEffect)glacier).m_icon = Portraits.PowerIcon(PowerKind.GlacierSkin);
		Add((StatusEffect)(object)glacier);
		bogveil = NewSE("Bogveil", "Bogveil", "Marsh-mist clings to you.", "mirewalkers");
		bogveil.m_noiseModifier = -0.8f;
		bogveil.m_stealthModifier = -0.7f;
		((StatusEffect)bogveil).m_icon = Portraits.PowerIcon(PowerKind.Bogveil);
		Add((StatusEffect)(object)bogveil);
		hearthsong = NewSE("Hearthsong", "Hearthsong", "A warm song mends your wounds.", "hearthfolk");
		((StatusEffect)hearthsong).m_ttl = 5f;
		hearthsong.m_healthOverTimeDuration = 5f;
		hearthsong.m_healthOverTimeInterval = 1f;
		((StatusEffect)hearthsong).m_icon = Portraits.PowerIcon(PowerKind.Hearthsong);
		Add((StatusEffect)(object)hearthsong);
		deepDelve = NewSE("DeepDelve", "Deep Delve", "The stone gives way to you.", "dwegir");
		deepDelve.m_modifyAttackSkill = (SkillType)12;
		((StatusEffect)deepDelve).m_icon = Portraits.PowerIcon(PowerKind.DeepDelve);
		Add((StatusEffect)(object)deepDelve);
		recharge = NewSE("Recharge", "Race power recharging", "Your race power can be used again when this runs out.", "frostborn");
		((StatusEffect)recharge).m_cooldownIcon = true;
		((StatusEffect)recharge).m_ttl = 60f;
		Add((StatusEffect)(object)recharge);
		cinderGlow = NewSE("CinderGlow", "Fire fists", "Embers cling to you: your unarmed hits deal fire damage.", "ashkin");
		((StatusEffect)cinderGlow).m_ttl = 30f;
		((StatusEffect)cinderGlow).m_icon = Portraits.PowerIcon(PowerKind.CinderBurst);
		Add((StatusEffect)(object)cinderGlow);
		runeGlow = NewSE("RuneGlow", "Rune-sight", "The runes still burn around you.", "runeblood");
		((StatusEffect)runeGlow).m_ttl = 10f;
		((StatusEffect)runeGlow).m_icon = Portraits.PowerIcon(PowerKind.RuneSight);
		Add((StatusEffect)(object)runeGlow);
		beastGlow = NewSE("BeastGlow", "Beastcall", "The wild answers you.", "wildwood");
		((StatusEffect)beastGlow).m_ttl = 60f;
		((StatusEffect)beastGlow).m_icon = Portraits.PowerIcon(PowerKind.Beastcall);
		Add((StatusEffect)(object)beastGlow);
		ready = NewSE("PowerReady", "Race power ready", "Your race power is ready.", "frostborn");
		((StatusEffect)ready).m_ttl = 0f;
		Add((StatusEffect)(object)ready);
		Add(Berserkir.BuildRage());
		Homeland.Register();
	}

	private static void FillPassive(SE_Stats se, RaceDef r)
	{
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: 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_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0225: Unknown result type (might be due to invalid IL or missing references)
		//IL_022a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0236: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0260: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		IEnumerable<string> values = from l in Plugin.BonusLines(r)
			where !l.EndsWith(" resistance") && !l.Contains(" regen") && !l.Contains("% jump") && ((int)r.Skill1 == 0 || l != "+" + Plugin.SkillBonus.Value + " " + Races.SkillName(r.Skill1)) && ((int)r.Skill2 == 0 || l != "+" + Plugin.SkillBonus.Value + " " + Races.SkillName(r.Skill2))
			select l;
		((StatusEffect)se).m_tooltip = r.Tagline + "\n" + ((r.Cooldown > 0f) ? ("Power (" + ((object)Plugin.PowerKey.Value/*cast due to .constrained prefix*/).ToString() + "): " + r.PowerName) : (r.PowerName + " comes with full adrenaline.")) + "\n" + string.Join("\n", values);
		((StatusEffect)se).m_ttl = 0f;
		se.m_mods = (r.Resist.HasValue ? new List<DamageModPair>
		{
			new DamageModPair
			{
				m_type = r.Resist.Value,
				m_modifier = (DamageModifier)1
			}
		} : new List<DamageModPair>());
		se.m_healthRegenMultiplier = ((r.HealthRegen > 1f) ? (1f + (float)Plugin.HealthRegenPercent.Value / 100f) : 1f);
		se.m_staminaRegenMultiplier = ((r.StaminaRegen > 1f) ? (1f + (float)Plugin.StaminaRegenPercent.Value / 100f) : 1f);
		se.m_jumpModifier = (Vector3)(r.Agile ? new Vector3(0f, Plugin.JumpPercent.Value / 100f, 0f) : Vector3.zero);
		se.m_fallDamageModifier = (r.Agile ? ((0f - Plugin.FallDamagePercent.Value) / 100f) : 0f);
		se.m_homeItemStaminaUseModifier = (r.ToolStamina ? ((float)(-Plugin.ToolStaminaPercent.Value) / 100f) : 0f);
		se.m_skillLevel = r.Skill1;
		se.m_skillLevelModifier = (((int)r.Skill1 != 0) ? ((float)Plugin.SkillBonus.Value) : 0f);
		se.m_skillLevel2 = r.Skill2;
		se.m_skillLevelModifier2 = (((int)r.Skill2 != 0) ? ((float)Plugin.SkillBonus.Value) : 0f);
	}

	internal static bool CinderFists(Player p)
	{
		if ((Object)(object)p != (Object)null && (Object)(object)cinderGlow != (Object)null)
		{
			return ((Character)p).GetSEMan().HaveStatusEffect(((StatusEffect)cinderGlow).NameHash());
		}
		return false;
	}

	private static void EnsureAuraLooks()
	{
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		if (auraLooks || (Object)(object)ObjectDB.instance == (Object)null)
		{
			return;
		}
		StatusEffect statusEffect = ObjectDB.instance.GetStatusEffect(StringExtensionMethods.GetStableHashCode("Frost"));
		if ((statusEffect?.m_startEffects?.m_effectPrefabs?.Length).GetValueOrDefault() != 0)
		{
			try
			{
				((StatusEffect)glacier).m_startEffects = statusEffect.m_startEffects;
				((StatusEffect)cinderGlow).m_startEffects = (EffectList)(((object)AuraFx.Tinted(statusEffect.m_startEffects, new Color(1f, 0.42f, 0.1f), "cinder")) ?? ((object)new EffectList()));
				((StatusEffect)runeGlow).m_startEffects = (EffectList)(((object)AuraFx.Tinted(statusEffect.m_startEffects, new Color(1f, 0.4f, 0.85f), "rune")) ?? ((object)new EffectList()));
				((StatusEffect)beastGlow).m_startEffects = (EffectList)(((object)AuraFx.Tinted(statusEffect.m_startEffects, new Color(0.55f, 0.36f, 0.16f), "earth")) ?? ((object)new EffectList()));
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Power looks: " + ex.Message));
			}
			auraLooks = true;
		}
	}

	internal static void Tick(Player p)
	{
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_021d: Unknown result type (might be due to invalid IL or missing references)
		EnsureAuraLooks();
		PendingRace.Tick(p);
		SEMan sEMan = ((Character)p).GetSEMan();
		RaceDef race = GetRace(p);
		foreach (KeyValuePair<string, SE_Stats> passife in passives)
		{
			bool flag = race != null && passife.Key == race.Id;
			bool flag2 = sEMan.HaveStatusEffect(((StatusEffect)passife.Value).NameHash());
			if (flag && !flag2 && !((Character)p).IsDead())
			{
				FillPassive(passife.Value, race);
				sEMan.AddStatusEffect((StatusEffect)(object)passife.Value, false, 0, 0f, (short)(-1));
				Plugin.Log.LogInfo((object)("Race effect active on " + p.GetPlayerName() + ": " + race.Name + " [" + string.Join(", ", Plugin.BonusLines(race)) + "]" + SkillReport(p, race)));
			}
			else if (!flag && flag2)
			{
				sEMan.RemoveStatusEffect(((StatusEffect)passife.Value).NameHash(), true);
			}
		}
		EnsureHearthVfx();
		Dwegir.Tick(p);
		try
		{
			ArmorClasses.Validate();
		}
		catch
		{
		}
		Homeland.Tick(p, race);
		ExpireBeasts();
		if (race == null)
		{
			return;
		}
		double num = ReadyAt(p, race) - Now();
		if (num > 1.0 && !sEMan.HaveStatusEffect(((StatusEffect)recharge).NameHash()))
		{
			ShowRecharge(p, race, (float)num);
		}
		ShowReady(p, race, race.Cooldown > 0f && num <= 1.0 && !sEMan.HaveStatusEffect(((StatusEffect)recharge).NameHash()));
		StatusEffect statusEffect = sEMan.GetStatusEffect(((StatusEffect)glacier).NameHash());
		if ((Object)(object)statusEffect != (Object)null && (sEMan.HaveStatusEffect(StringExtensionMethods.GetStableHashCode("Burning")) || (Object)(object)EffectArea.IsPointInsideArea(((Component)p).transform.position, (Type)1, 3f) != (Object)null || (Object)(object)EffectArea.IsPointInsideArea(((Component)p).transform.position, (Type)2, 3f) != (Object)null))
		{
			SeTime.SetValue(statusEffect, (float)SeTime.GetValue(statusEffect) + 2f);
		}
		if (++lookTick >= 5)
		{
			lookTick = 0;
			if (Looks.EnforceLook(p, race, null))
			{
				Plugin.Log.LogInfo((object)(race.Name + " look rule applied to " + p.GetPlayerName() + "."));
			}
		}
	}

	private static string SkillReport(Player p, RaceDef r)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Expected I4, but got Unknown
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected I4, but got Unknown
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected I4, but got Unknown
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected I4, but got Unknown
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		string text = "";
		SkillType[] array = (SkillType[])(object)new SkillType[4]
		{
			(SkillType)(int)r.Skill1,
			(SkillType)(int)r.Skill2,
			(SkillType)(int)r.Skill3,
			(SkillType)(int)r.Skill4
		};
		foreach (SkillType val in array)
		{
			if ((int)val != 0)
			{
				float skillLevel = ((Character)p).GetSkills().GetSkillLevel(val);
				float num = skillLevel;
				((Character)p).GetSEMan().ModifySkillLevel(val, ref num);
				text = text + " | " + Races.SkillName(val) + " " + skillLevel.ToString("0") + " -> " + num.ToString("0");
			}
		}
		return text;
	}

	private static void EnsureHearthVfx()
	{
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Expected O, but got Unknown
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Expected O, but got Unknown
		if (hearthVfx || (Object)(object)ZNetScene.instance == (Object)null)
		{
			return;
		}
		hearthVfx = true;
		string[] array = new string[3] { "vfx_Potion_health_medium", "vfx_Potion_health_minor", "vfx_HealthUpgrade" };
		foreach (string text in array)
		{
			GameObject prefab = ZNetScene.instance.GetPrefab(text);
			if (!((Object)(object)prefab == (Object)null))
			{
				SE_Stats obj = hearthsong;
				EffectList val = new EffectList();
				val.m_effectPrefabs = (EffectData[])(object)new EffectData[1]
				{
					new EffectData
					{
						m_prefab = prefab,
						m_enabled = true,
						m_attach = true
					}
				};
				((StatusEffect)obj).m_startEffects = val;
				Plugin.Log.LogInfo((object)("Hearthsong effect: " + text));
				break;
			}
		}
	}

	internal static bool CanTakeKey(Player p)
	{
		//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_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Invalid comparison between Unknown and I4
		if (((Character)p).IsDead() || ((Character)p).InIntro() || ((Character)p).IsTeleporting())
		{
			return false;
		}
		if ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus())
		{
			return false;
		}
		if (Console.IsVisible() || Menu.IsVisible() || InventoryGui.IsVisible() || Minimap.IsOpen() || TextInput.IsVisible())
		{
			return false;
		}
		if (StoreGui.IsVisible() || ((Object)(object)TextViewer.instance != (Object)null && TextViewer.instance.IsVisible()))
		{
			return false;
		}
		KeyboardShortcut value = Plugin.PowerKey.Value;
		if ((int)((KeyboardShortcut)(ref value)).MainKey == 103)
		{
			GameObject hoverObject = ((Humanoid)p).GetHoverObject();
			if ((Object)(object)hoverObject != (Object)null && (Object)(object)hoverObject.GetComponentInParent<Character>() != (Object)null)
			{
				return false;
			}
		}
		return true;
	}

	internal static double Now()
	{
		if (!((Object)(object)ZNet.instance != (Object)null))
		{
			return Time.time;
		}
		return ZNet.instance.GetTimeSeconds();
	}

	private static double ReadyAt(Player p, RaceDef r)
	{
		if (!p.m_customData.TryGetValue("RotR.PowerReadyAt", out var value) || !double.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
		{
			return 0.0;
		}
		if (result - Now() > (double)(Plugin.Cooldown(r) + 5f))
		{
			return 0.0;
		}
		return result;
	}

	internal static void ResetPower(Player p)
	{
		p.m_customData.Remove("RotR.PowerReadyAt");
		if ((Object)(object)recharge != (Object)null)
		{
			((Character)p).GetSEMan().RemoveStatusEffect(((StatusEffect)recharge).NameHash(), true);
		}
	}

	internal static double PowerSecondsLeft(Player p, RaceDef r)
	{
		return ReadyAt(p, r) - Now();
	}

	internal static void TryUsePower(Player p)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		RaceDef race = GetRace(p);
		if (race == null)
		{
			((Character)p).Message((MessageType)2, "You have no race yet. Press " + ((object)Plugin.MenuKey.Value/*cast due to .constrained prefix*/).ToString() + " to choose one.", 0, (Sprite)null, false);
			return;
		}
		if (race.Power == PowerKind.BerserkirRage)
		{
			((Character)p).Message((MessageType)2, "Berserkir Rage comes by itself when your adrenaline is full (" + Mathf.FloorToInt(Berserkir.Adrenaline) + "/" + Berserkir.MaxAdrenaline + ")", 0, (Sprite)null, false);
			return;
		}
		double num = ReadyAt(p, race) - Now();
		if (num > 0.0)
		{
			((Character)p).Message((MessageType)2, race.PowerName + " is ready in " + FormatTime(num), 0, (Sprite)null, false);
			return;
		}
		bool flag = (Object)(object)EnvMan.instance != (Object)null && EnvMan.IsNight();
		bool flag2;
		try
		{
			flag2 = DoPower(p, race);
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)(race.PowerName + " failed: " + ex));
			flag2 = false;
		}
		if (flag2)
		{
			float num2 = Plugin.Cooldown(race);
			if (race.Power == PowerKind.GlacierSkin && flag && TalentHooks.On("glacier.nightEternal"))
			{
				num2 *= 0.5f;
			}
			TalentHooks.RaisePower(race.Power.ToString(), ((Component)p).transform.position);
			p.m_customData["RotR.PowerReadyAt"] = (Now() + (double)num2).ToString(CultureInfo.InvariantCulture);
			if (num2 > 0f)
			{
				ShowRecharge(p, race, num2);
			}
			Plugin.Log.LogInfo((object)(p.GetPlayerName() + " used " + race.PowerName + " (cooldown " + FormatTime(num2) + ")."));
		}
	}

	private static void ShowReady(Player p, RaceDef race, bool show)
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		SEMan sEMan = ((Character)p).GetSEMan();
		bool flag = sEMan.HaveStatusEffect(((StatusEffect)ready).NameHash());
		if (!show)
		{
			if (flag)
			{
				sEMan.RemoveStatusEffect(((StatusEffect)ready).NameHash(), true);
			}
			return;
		}
		string text = race.PowerName + " ready (" + ((object)Plugin.PowerKey.Value/*cast due to .constrained prefix*/).ToString() + ")";
		if (!flag || !(((StatusEffect)ready).m_name == text))
		{
			if (flag)
			{
				sEMan.RemoveStatusEffect(((StatusEffect)ready).NameHash(), true);
			}
			((StatusEffect)ready).m_name = text;
			((StatusEffect)ready).m_tooltip = Plugin.PowerText(race) ?? "";
			((StatusEffect)ready).m_icon = Portraits.PowerIcon(race.Power) ?? Portraits.Icon(race.Id);
			sEMan.AddStatusEffect((StatusEffect)(object)ready, false, 0, 0f, (short)(-1));
		}
	}

	private static void ShowRecharge(Player p, RaceDef race, float seconds)
	{
		ShowReady(p, race, show: false);
		((StatusEffect)recharge).m_name = race.PowerName + " recharging";
		((StatusEffect)recharge).m_icon = Portraits.PowerIcon(race.Power) ?? Portraits.Icon(race.Id);
		StatusEffect val = ((Character)p).GetSEMan().AddStatusEffect((StatusEffect)(object)recharge, true, 0, 0f, (short)(-1));
		if ((Object)(object)val != (Object)null)
		{
			val.m_ttl = seconds;
			AccessTools.Field(typeof(StatusEffect), "m_time").SetValue(val, 0f);
		}
	}

	internal static string FormatTime(double s)
	{
		int num = Mathf.CeilToInt((float)s);
		if (num < 60)
		{
			return num + " s";
		}
		return num / 60 + ":" + (num % 60).ToString("00");
	}

	private static bool DoPower(Player p, RaceDef race)
	{
		//IL_090b: Unknown result type (might be due to invalid IL or missing references)
		//IL_089a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0979: Unknown result type (might be due to invalid IL or missing references)
		//IL_0434: Unknown result type (might be due to invalid IL or missing references)
		//IL_0439: Unknown result type (might be due to invalid IL or missing references)
		//IL_043c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dd: Invalid comparison between Unknown and I4
		//IL_0481: Unknown result type (might be due to invalid IL or missing references)
		//IL_031f: Unknown result type (might be due to invalid IL or missing references)
		//IL_032a: Unknown result type (might be due to invalid IL or missing references)
		//IL_063a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0640: Invalid comparison between Unknown and I4
		//IL_0647: 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_034e: Expected O, but got Unknown
		//IL_0662: Unknown result type (might be due to invalid IL or missing references)
		//IL_0668: Invalid comparison between Unknown and I4
		//IL_06b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_06c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03da: Unknown result type (might be due to invalid IL or missing references)
		//IL_03de: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
		SEMan sEMan = ((Character)p).GetSEMan();
		switch (race.Power)
		{
		case PowerKind.GlacierSkin:
			((StatusEffect)glacier).m_ttl = (float)Plugin.GlacierSkinSeconds.Value + TalentHooks.V("power.duration");
			if ((Object)(object)EnvMan.instance != (Object)null && EnvMan.IsNight() && TalentHooks.On("glacier.nightEternal"))
			{
				SE_Stats obj = glacier;
				((StatusEffect)obj).m_ttl = ((StatusEffect)obj).m_ttl * 2f;
			}
			glacier.m_addArmor = (float)Plugin.GlacierSkinArmor.Value + TalentHooks.V("glacier.armor");
			EnsureAuraLooks();
			sEMan.AddStatusEffect((StatusEffect)(object)glacier, true, 0, 0f, (short)(-1));
			PowerVfx.Play(p, PowerVfx.Kind.GlacierSkin, 2f);
			((Character)p).Message((MessageType)2, "Glacier Skin", 0, (Sprite)null, false);
			return true;
		case PowerKind.Bogveil:
			((StatusEffect)bogveil).m_ttl = (float)Plugin.BogveilSeconds.Value + TalentHooks.V("power.duration");
			bogveil.m_speedModifier = TalentHooks.V("bogveil.speed");
			bogveil.m_stealthModifier = Mathf.Max(-1f, -0.7f - TalentHooks.V("bogveil.stealth"));
			sEMan.AddStatusEffect((StatusEffect)(object)bogveil, true, 0, 0f, (short)(-1));
			PowerVfx.Play(p, PowerVfx.Kind.Bogveil, 2.5f);
			((Character)p).Message((MessageType)2, "Bogveil", 0, (Sprite)null, false);
			return true;
		case PowerKind.DeepDelve:
			((StatusEffect)deepDelve).m_ttl = (float)Plugin.DeepDelveMinutes.Value * 60f + TalentHooks.V("power.duration");
			deepDelve.m_damageModifier = 1f + Plugin.DeepDelveDamage.Value / 100f + TalentHooks.V("delve.damage");
			deepDelve.m_addMaxCarryWeight = Plugin.DeepDelveCarry.Value + TalentHooks.V("delve.carry");
			sEMan.AddStatusEffect((StatusEffect)(object)deepDelve, true, 0, 0f, (short)(-1));
			PowerVfx.Play(p, PowerVfx.Kind.DeepDelve, 1.5f);
			((Character)p).Message((MessageType)2, "Deep Delve", 0, (Sprite)null, false);
			return true;
		case PowerKind.CinderBurst:
		{
			float num3 = Plugin.CinderBurstRadius.Value + TalentHooks.V("power.radius");
			float num4 = Plugin.CinderBurstDamage.Value + TalentHooks.V("power.damage") + (1.5f + TalentHooks.V("cinder.clubScale")) * ((Character)p).GetSkills().GetSkillLevel((SkillType)3);
			float num5 = TalentHooks.V("cinder.burnChance");
			List<Vector3> list2 = new List<Vector3>();
			int num6 = 0;
			foreach (Character item in Character.GetAllCharacters().ToList())
			{
				if ((Object)(object)item == (Object)null || (Object)(object)item == (Object)(object)p || item.IsDead() || item.IsPlayer() || item.IsTamed() || (int)item.m_faction == 0 || (int)item.m_faction == 11)
				{
					continue;
				}
				ZNetView component = ((Component)item).GetComponent<ZNetView>();
				if ((!((Object)(object)component != (Object)null) || !component.IsValid() || component.GetZDO().GetLong("RotR.BeastcallUntil", 0L) <= 0) && !(Vector3.Distance(((Component)item).transform.position, ((Component)p).transform.position) > num3) && BaseAI.IsEnemy((Character)(object)p, item))
				{
					HitData val = new HitData();
					val.m_damage.m_fire = num4 * ((num5 > 0f && Random.value < num5) ? 2f : 1f);
					if (TalentHooks.On("cinder.chain") && item.GetHealth() <= val.m_damage.m_fire)
					{
						list2.Add(((Component)item).transform.position);
					}
					val.m_point = item.GetCenterPoint();
					Vector3 val2 = ((Component)item).transform.position - ((Component)p).transform.position;
					val.m_dir = ((Vector3)(ref val2)).normalized;
					val.m_pushForce = 30f;
					val.SetAttacker((Character)(object)p);
					item.Damage(val);
					num6++;
				}
			}
			foreach (Vector3 item2 in list2)
			{
				FireArea(p, item2, 3f, num4 * 0.3f, 1, 0f);
			}
			if (TalentHooks.On("cinder.inferno"))
			{
				FireArea(p, ((Component)p).transform.position, 6f, 8f, 6, 1f);
			}
			PowerVfx.Play(p, PowerVfx.Kind.CinderBurst, num3);
			EnsureAuraLooks();
			sEMan.AddStatusEffect((StatusEffect)(object)cinderGlow, true, 0, 0f, (short)(-1));
			((Character)p).Message((MessageType)2, "Cinder Burst (" + num6 + " hit)", 0, (Sprite)null, false);
			Plugin.Log.LogInfo((object)("Cinder Burst: " + num4.ToString("0") + " fire damage to " + num6 + " enemies."));
			return true;
		}
		case PowerKind.Beastcall:
		{
			float num7 = Plugin.BeastcallRadius.Value + TalentHooks.V("power.radius");
			double num8 = Now() + (double)Plugin.BeastcallSeconds.Value + (double)TalentHooks.V("power.duration");
			string[] source = (from x in (Plugin.BeastcallExcluded.Value ?? "").ToLowerInvariant().Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries)
				select x.Trim() into x
				where x.Length > 0
				select x).ToArray();
			int num9 = 0;
			foreach (Character item3 in Character.GetAllCharacters().ToList())
			{
				if ((Object)(object)item3 == (Object)null || item3.IsPlayer() || item3.IsDead() || item3.IsBoss() || item3.IsTamed() || (int)item3.m_faction == 8 || (int)item3.m_faction == 0 || ((Object)(object)((Component)item3).GetComponent<Tameable>() == (Object)null && (int)item3.m_faction != 1))
				{
					continue;
				}
				string cname = (Utils.GetPrefabName(((Component)item3).gameObject) + " " + item3.m_name).ToLowerInvariant();
				if (source.Any((string x) => cname.Contains(x)) || Vector3.Distance(((Component)item3).transform.position, ((Component)p).transform.position) > num7)
				{
					continue;
				}
				ZNetView component2 = ((Component)item3).GetComponent<ZNetView>();
				if (!((Object)(object)component2 == (Object)null) && component2.IsValid())
				{
					component2.ClaimOwnership();
					item3.SetTamed(true);
					component2.GetZDO().Set("RotR.BeastcallUntil", (long)(num8 * 1000.0));
					MonsterAI component3 = ((Component)item3).GetComponent<MonsterAI>();
					if ((Object)(object)component3 != (Object)null)
					{
						component3.SetFollowTarget(((Component)p).gameObject);
					}
					num9++;
				}
			}
			if (num9 > 0)
			{
				EnsureAuraLooks();
				((StatusEffect)beastGlow).m_ttl = (float)(num8 - Now());
				sEMan.AddStatusEffect((StatusEffect)(object)beastGlow, true, 0, 0f, (short)(-1));
			}
			if (num9 == 0)
			{
				((Character)p).Message((MessageType)2, "No beast answers your call.", 0, (Sprite)null, false);
				return false;
			}
			PowerVfx.Play(p, PowerVfx.Kind.Beastcall, num7);
			((Character)p).Message((MessageType)2, "Beastcall: " + num9 + " beast" + ((num9 == 1) ? "" : "s") + " at your side", 0, (Sprite)null, false);
			Plugin.Log.LogInfo((object)("Beastcall: " + num9 + " creatures follow for " + Plugin.BeastcallSeconds.Value + " s."));
			return true;
		}
		case PowerKind.RuneSight:
			if ((Object)(object)Minimap.instance == (Object)null)
			{
				return false;
			}
			AccessTools.Method(typeof(Minimap), "Explore", new Type[2]
			{
				typeof(Vector3),
				typeof(float)
			}, (Type[])null).Invoke(Minimap.instance, new object[2]
			{
				((Component)p).transform.position,
				Plugin.RuneSightRadius.Value + TalentHooks.V("power.radius")
			});
			PowerVfx.Play(p, PowerVfx.Kind.RuneSight, 3f);
			EnsureAuraLooks();
			sEMan.AddStatusEffect((StatusEffect)(object)runeGlow, true, 0, 0f, (short)(-1));
			((Character)p).Message((MessageType)2, "Rune-sight: the land around you is revealed", 0, (Sprite)null, false);
			return true;
		case PowerKind.Hearthsong:
		{
			List<Player> list = new List<Player>();
			Player.GetPlayersInRange(((Component)p).transform.position, Plugin.HearthsongRadius.Value + TalentHooks.V("power.radius"), list);
			if (!list.Contains(p))
			{
				list.Add(p);
			}
			float num = 5f + TalentHooks.V("hearth.hotDur");
			float num2 = Plugin.HearthsongHps.Value + TalentHooks.V("hearth.hot");
			if (TalentHooks.On("hearth.fireDouble") && (Object)(object)EffectArea.IsPointInsideArea(((Component)p).transform.position, (Type)1, 3f) != (Object)null)
			{
				num2 *= 2f;
			}
			((StatusEffect)hearthsong).m_ttl = num;
			hearthsong.m_healthOverTime = num2 * num;
			hearthsong.m_healthOverTimeDuration = num;
			if (TalentHooks.On("hearth.cleanse"))
			{
				string[] array = new string[3] { "Poison", "Burning", "Wet" };
				foreach (string text in array)
				{
					sEMan.RemoveStatusEffect(StringExtensionMethods.GetStableHashCode(text), true);
				}
			}
			foreach (Player item4 in list)
			{
				((Character)item4).Heal(((Character)item4).GetMaxHealth() * (Plugin.HearthsongHealPercent.Value / 100f + TalentHooks.V("hearth.heal")), true);
				if ((Object)(object)item4 == (Object)(object)p)
				{
					sEMan.AddStatusEffect((StatusEffect)(object)hearthsong, true, 0, 0f, (short)(-1));
				}
				else
				{
					((Character)item4).GetSEMan().AddStatusEffect(((StatusEffect)hearthsong).NameHash(), true, 0, 0f, (short)(-1));
				}
			}
			PowerVfx.Play(p, PowerVfx.Kind.Hearthsong, Plugin.HearthsongRadius.Value + TalentHooks.V("power.radius"));
			((Character)p).Message((MessageType)2, "Hearthsong (" + list.Count + " healed)", 0, (Sprite)null, false);
			return true;
		}
		default:
			return false;
		}
	}

	private static void FireArea(Player p, Vector3 at, float radius, float damage, int ticks, float interval)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		((MonoBehaviour)Plugin.I).StartCoroutine(FireAreaRoutine(p, at, radius, damage, ticks, interval));
	}

	private static IEnumerator FireAreaRoutine(Player p, Vector3 at, float radius, float damage, int ticks, float interval)
	{
		//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)
		for (int i = 0; i < ticks; i++)
		{
			if ((Object)(object)p == (Object)null)
			{
				break;
			}
			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) > radius) && BaseAI.IsEnemy((Character)(object)p, item))
				{
					HitData val = new HitData();
					val.m_damage.m_fire = damage;
					val.m_point = item.GetCenterPoint();
					val.SetAttacker((Character)(object)p);
					item.Damage(val);
				}
			}
			if (i == 0)
			{
				PowerVfx.Play(at, PowerVfx.Kind.Inferno, radius);
			}
			if (interval > 0f)
			{
				yield return (object)new WaitForSeconds(interval);
			}
		}
	}

	private static void ExpireBeasts()
	{
		double num = Now() * 1000.0;
		foreach (Character item in Character.GetAllCharacters().ToList())
		{
			if ((Object)(object)item == (Object)null || item.IsPlayer())
			{
				continue;
			}
			ZNetView component = ((Component)item).GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid() || !component.IsOwner())
			{
				continue;
			}
			long num2 = component.GetZDO().GetLong("RotR.BeastcallUntil", 0L);
			if (num2 <= 0 || num < (double)num2)
			{
				continue;
			}
			component.GetZDO().Set("RotR.BeastcallUntil", 0L);
			if (!item.IsDead())
			{
				item.SetTamed(false);
				MonsterAI component2 = ((Component)item).GetComponent<MonsterAI>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.SetFollowTarget((GameObject)null);
				}
				Plugin.Log.LogInfo((object)("Beastcall ended for " + item.m_name + "."));
			}
		}
	}

	internal static void RegisterRpc()
	{
		PowerVfx.RegisterRpc();
		Respec.RegisterRpc();
	}
}
internal static class Homeland
{
	internal struct Home
	{
		public Biome Biome;

		public bool Underground;

		public string Name;

		public string Text;
	}

	[HarmonyPatch(typeof(SEMan), "AddStatusEffect", new Type[]
	{
		typeof(int),
		typeof(bool),
		typeof(int),
		typeof(float),
		typeof(short)
	})]
	private static class AshkinWeather
	{
		[HarmonyPriority(200)]
		private static bool Prefix(SEMan __instance, int nameHash, bool resetTime, ref StatusEffect __result)
		{
			if (nameHash != SEMan.s_statusEffectFreezing)
			{
				return true;
			}
			Character obj = SemanChar.Invoke(__instance);
			Player val = (Player)(object)((obj is Player) ? obj : null);
			if ((Object)(object)val == (Object)null || (Object)(object)val != (Object)(object)Player.m_localPlayer)
			{
				return true;
			}
			RaceDef race = Effects.GetRace(val);
			if (race == null || race.Id != "ashkin")
			{
				return true;
			}
			float time = Time.time;
			if (time - lastFreezeTry > 5f)
			{
				freezeStart = time;
				if (Plugin.AshkinFreezeDelay.Value > 0f)
				{
					((Character)val).Message((MessageType)1, "Ashkin blood holds the frost back (" + Effects.FormatTime(Plugin.AshkinFreezeDelay.Value) + ")", 0, (Sprite)null, false);
				}
			}
			lastFreezeTry = time;
			if (time - freezeStart >= Plugin.AshkinFreezeDelay.Value)
			{
				return true;
			}
			__result = __instance.AddStatusEffect(SEMan.s_statusEffectCold, resetTime, 0, 0f, (short)0);
			return false;
		}
	}

	[HarmonyPatch(typeof(SEMan), "Update")]
	private static class AshkinWetCap
	{
		private static float templateTtl = -1f;

		private static void Prefix(SEMan __instance)
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)SemanChar.Invoke(__instance) != (Object)(object)localPlayer)
			{
				return;
			}
			StatusEffect statusEffect = __instance.GetStatusEffect(SEMan.s_statusEffectWet);
			if ((Object)(object)statusEffect == (Object)null || Effects.GetRace(localPlayer)?.Id != "ashkin")
			{
				return;
			}
			float num = Mathf.Clamp(Plugin.AshkinWetPercent.Value, 0f, 100f);
			if (num <= 0f)
			{
				return;
			}
			if (num >= 100f)
			{
				__instance.RemoveStatusEffect(SEMan.s_statusEffectWet, true);
				return;
			}
			if (templateTtl <= 0f && (Object)(object)ObjectDB.instance != (Object)null)
			{
				StatusEffect statusEffect2 = ObjectDB.instance.GetStatusEffect(SEMan.s_statusEffectWet);
				if ((Object)(object)statusEffect2 != (Object)null)
				{
					templateTtl = statusEffect2.m_ttl;
				}
			}
			if (!(templateTtl <= 0f))
			{
				float num2 = templateTtl * (1f - num / 100f);
				if (statusEffect.m_ttl > num2)
				{
					statusEffect.m_ttl = num2;
				}
			}
		}
	}

	[HarmonyPatch(typeof(SEMan), "RemoveStatusEffect", new Type[]
	{
		typeof(int),
		typeof(bool)
	})]
	private static class AshkinKeepCold
	{
		private static bool Prefix(SEMan __instance, int nameHash)
		{
			if (nameHash != SEMan.s_statusEffectCold || Time.time - lastFreezeTry > 1f)
			{
				return true;
			}
			if (Time.time - freezeStart >= Plugin.AshkinFreezeDelay.Value)
			{
				return true;
			}
			Character obj = SemanChar.Invoke(__instance);
			Player val = (Player)(object)((obj is Player) ? obj : null);
			if (!((Object)(object)val == (Object)null) && !((Object)(object)val != (Object)(object)Player.m_localPlayer))
			{
				return Effects.GetRace(val)?.Id != "ashkin";
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(SEMan), "AddStatusEffect", new Type[]
	{
		typeof(int),
		typeof(bool),
		typeof(int),
		typeof(float),
		typeof(short)
	})]
	private static class BlockEnvironment
	{
		private static bool Prefix(SEMan __instance, int nameHash, ref StatusEffect __result)
		{
			if (!Plugin.HomelandBonuses.Value)
			{
				return true;
			}
			Character obj = SemanChar.Invoke(__instance);
			Player p = (Player)(object)((obj is Player) ? obj : null);
			RaceDef race = Effects.GetRace(p);
			if (race == null)
			{
				return true;
			}
			if ((!(race.Id == "frostborn") || (nameHash != SEMan.s_statusEffectCold && (nameHash != SEMan.s_statusEffectFreezing || !AtHome(p, race)))) && (!(race.Id == "mirewalkers") || nameHash != SEMan.s_statusEffectWet))
			{
				return true;
			}
			__result = null;
			return false;
		}
	}

	private static readonly Dictionary<string, SE_Stats> homes = new Dictionary<string, SE_Stats>();

	private static SE_Stats starlit;

	private static GameObject demister;

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

	private static float freezeStart = -999f;

	private static float lastFreezeTry = -999f;

	internal static Home Of(RaceDef r)
	{
		//IL_0242: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0297: 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_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		return r.Id switch
		{
			"frostborn" => new Home
			{
				Biome = (Biome)4,
				Name = "Mountain",
				Text = "No Freezing. At night: never Cold, +" + Plugin.StarlitDamagePercent.Value + "% damage, +10% stamina regen (anywhere)."
			}, 
			"ashkin" => new Home
			{
				Biome = (Biome)32,
				Name = "Ashlands",
				Text = "+15% damage, +10% stamina regen."
			}, 
			"mirewalkers" => new Home
			{
				Biome = (Biome)2,
				Name = "Swamp",
				Text = "+10% movement speed."
			}, 
			"wildwood" => new Home
			{
				Biome = (Biome)8,
				Name = "Black Forest",
				Text = "Harder to spot, +10% stamina regen."
			}, 
			"runeblood" => new Home
			{
				Biome = (Biome)512,
				Name = "Mistlands",
				Text = "The mist clears " + Plugin.MistClearRadius.Value + " m around you, +25% eitr regen."
			}, 
			"hearthfolk" => new Home
			{
				Biome = (Biome)1,
				Name = "Meadows",
				Text = "+25% health regen, +10% stamina regen."
			}, 
			"dwegir" => new Home
			{
				Underground = true,
				Name = "Underground",
				Text = "In caves, crypts and mines: +15% damage, +10% stamina regen."
			}, 
			"berserkir" => new Home
			{
				Biome = (Biome)16,
				Name = "Plains",
				Text = "-" + Plugin.PlainsRunStaminaPercent.Value + "% stamina used while running."
			}, 
			_ => default(Home), 
		};
	}

	private static void Add(StatusEffect se)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(se, false));
	}

	internal static void Register()
	{
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0200: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		foreach (RaceDef item in Races.All)
		{
			Home home = Of(item);
			SE_Stats val = ScriptableObject.CreateInstance<SE_Stats>();
			((Object)val).name = "RotR_Home_" + item.Id;
			((StatusEffect)val).m_name = "Homeland: " + home.Name;
			((StatusEffect)val).m_tooltip = item.Name + " are at home here.\n" + home.Text;
			((StatusEffect)val).m_icon = Portraits.Icon(item.Id);
			((StatusEffect)val).m_ttl = 0f;
			switch (item.Id)
			{
			case "ashkin":
				val.m_modifyAttackSkill = (SkillType)999;
				val.m_damageModifier = 1.15f;
				val.m_staminaRegenMultiplier = 1.1f;
				break;
			case "mirewalkers":
				val.m_speedModifier = 0.1f;
				break;
			case "wildwood":
				val.m_stealthModifier = -0.3f;
				val.m_staminaRegenMultiplier = 1.1f;
				break;
			case "runeblood":
				val.m_eitrRegenMultiplier = 1.25f;
				break;
			case "hearthfolk":
				val.m_healthRegenMultiplier = 1.25f;
				val.m_staminaRegenMultiplier = 1.1f;
				break;
			case "dwegir":
				val.m_modifyAttackSkill = (SkillType)999;
				val.m_damageModifier = 1.15f;
				val.m_staminaRegenMultiplier = 1.1f;
				break;
			}
			homes[item.Id] = val;
			Add((StatusEffect)(object)val);
		}
		starlit = ScriptableObject.CreateInstance<SE_Stats>();
		((Object)starlit).name = "RotR_Starlit";
		((StatusEffect)starlit).m_name = "Starlit Hunt";
		((StatusEffect)starlit).m_tooltip = "The cold of night only sharpens a Frostborn.";
		((StatusEffect)starlit).m_icon = Portraits.Icon("frostborn");
		starlit.m_modifyAttackSkill = (SkillType)999;
		starlit.m_staminaRegenMultiplier = 1.1f;
		Add((StatusEffect)(object)starlit);
	}

	internal static bool AtHome(Player p, RaceDef r)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		Home home = Of(r);
		if (home.Underground)
		{
			return ((Character)p).InInterior();
		}
		if (!((Character)p).InInterior())
		{
			return p.GetCurrentBiome() == home.Biome;
		}
		return false;
	}

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

	internal static void Tick(Player p, RaceDef race)
	{
		SEMan sEMan = ((Character)p).GetSEMan();
		bool flag = Plugin.HomelandBonuses.Value && race != null && !((Character)p).IsDead();
		foreach (KeyValuePair<string, SE_Stats> home in homes)
		{
			bool flag2 = flag && home.Key == race.Id && AtHome(p, race);
			if (flag2 && home.Key == "berserkir")
			{
				home.Value.m_runStaminaDrainModifier = (0f - Plugin.PlainsRunStaminaPercent.Value) / 100f;
			}
			SetEffect(sEMan, (StatusEffect)(object)home.Value, flag2, (race != null && home.Key == race.Id) ? ("Homeland " + Of(race).Name) : null);
		}
		bool want = flag && race.Id == "frostborn" && IsNight();
		starlit.m_damageModifier = 1f + Plugin.StarlitDamagePercent.Value / 100f;
		SetEffect(sEMan, (StatusEffect)(object)starlit, want, "Starlit Hunt");
		if (race != null && race.Id == "frostborn")
		{
			sEMan.RemoveStatusEffect(SEMan.s_statusEffectCold, true);
		}
		if (race != null && race.Id == "mirewalkers")
		{
			sEMan.RemoveStatusEffect(SEMan.s_statusEffectWet, true);
		}
		UpdateDemister(p, flag && race.Id == "runeblood" && AtHome(p, race));
	}

	private static void SetEffect(SEMan seman, StatusEffect se, bool want, string logName)
	{
		bool flag = seman.HaveStatusEffect(se.NameHash());
		if (want && !flag)
		{
			seman.AddStatusEffect(se, false, 0, 0f, (short)(-1));
			if (logName != null)
			{
				Plugin.Log.LogInfo((object)(logName + " bonus on."));
			}
		}
		else if (!want && flag)
		{
			seman.RemoveStatusEffect(se.NameHash(), true);
			if (logName != null)
			{
				Plugin.Log.LogInfo((object)(logName + " bonus off."));
			}
		}
	}

	private static void UpdateDemister(Player p, bool want)
	{
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Expected O, but got Unknown
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: 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_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_013a: Unknown result type (might be due to invalid IL or missing references)
		if (!want)
		{
			if ((Object)(object)demister != (Object)null)
			{
				Object.Destroy((Object)(object)demister);
				demister = null;
			}
			return;
		}
		if ((Object)(object)demister != (Object)null && (Object)(object)demister.transform.parent == (Object)(object)((Component)p).transform)
		{
			ParticleSystemForceField component = demister.GetComponent<ParticleSystemForceField>();
			if ((Object)(object)component != (Object)null && !Mathf.Approximately(component.endRange, Plugin.MistClearRadius.Value))
			{
				component.endRange = Plugin.MistClearRadius.Value;
			}
			return;
		}
		if ((Object)(object)demister != (Object)null)
		{
			Object.Destroy((Object)(object)demister);
		}
		demister = new GameObject("RotR_RunebloodDemister");
		demister.SetActive(false);
		demister.transform.SetParent(((Component)p).transform, false);
		demister.transform.localPosition = Vector3.up;
		ParticleSystemForceField val = demister.AddComponent<ParticleSystemForceField>();
		val.shape = (ParticleSystemForceFieldShape)0;
		val.startRange = 0f;
		val.endRange = Plugin.MistClearRadius.Value;
		val.gravity = MinMaxCurve.op_Implicit(0f);
		MinMaxCurve val2 = (val.directionZ = MinMaxCurve.op_Implicit(0f));
		MinMaxCurve directionX = (val.directionY = val2);
		val.directionX = directionX;
		Demister obj = demister.AddComponent<Demister>();
		obj.m_forceField = val;
		obj.m_disableForcefieldDelay = 0f;
		demister.SetActive(true);
		Plugin.Log.LogInfo((object)("Runeblood mist sight on (" + Plugin.MistClearRadius.Value + " m)."));
	}
}
internal static class Looks
{
	private static Color skin0 = new Color(1f, 0.85f, 0.75f);

	private static Color skin1 = new Color(0.35f, 0.2f, 0.14f);

	private static Color hair0 = new Color(1f, 0.9f, 0.6f);

	private static Color hair1 = new Color(0.5f, 0.3f, 0.15f);

	private static float hairMin = 0.1f;

	private static float hairMax = 1f;

	private static bool colorsKnown;

	private static bool Skin1IsDarker => Lum(skin1) < Lum(skin0);

	private static PlayerCustomizaton Customizer()
	{
		return ((IEnumerable<PlayerCustomizaton>)Resources.FindObjectsOfTypeAll<PlayerCustomizaton>()).FirstOrDefault((Func<PlayerCustomizaton, bool>)((PlayerCustomizaton c) => (Object)(object)c != (Object)null && (Object)(object)c.m_skinHue != (Object)null));
	}

	private static void LearnColors(PlayerCustomizaton pc)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)pc == (Object)null))
		{
			skin0 = pc.m_skinColor0;
			skin1 = pc.m_skinColor1;
			hair0 = pc.m_hairColor0;
			hair1 = pc.m_hairColor1;
			hairMin = pc.m_hairMinLevel;
			hairMax = pc.m_hairMaxLevel;
			colorsKnown = true;
		}
	}

	private static float Lum(Color c)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		return 0.3f * c.r + 0.59f * c.g + 0.11f * c.b;
	}

	private static float SkinSlider(float darkness)
	{
		if (!Skin1IsDarker)
		{
			return 1f - darkness;
		}
		return darkness;
	}

	private static Vector3 V(Color c)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		return new Vector3(c.r, c.g, c.b);
	}

	private static float Darkness(Vector3 skin)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		float num = Lum(skin0);
		float num2 = Lum(skin1);
		float num3 = 0.3f * skin.x + 0.59f * skin.y + 0.11f * skin.z;
		float num4 = (Mathf.Approximately(num, num2) ? 0f : Mathf.InverseLerp(num, num2, num3));
		if (!Skin1IsDarker)
		{
			return 1f - num4;
		}
		return num4;
	}

	private static string PrefabFor(string key)
	{
		if ((Object)(object)ObjectDB.instance == (Object)null || key == null)
		{
			return null;
		}
		foreach (GameObject item in ObjectDB.instance.m_items)
		{
			ItemDrop val = (((Object)(object)item != (Object)null) ? item.GetComponent<ItemDrop>() : null);
			if ((Object)(object)val != (Object)null && val.m_itemData.m_shared.m_name == key)
			{
				return ((Object)item).name;
			}
		}
		return null;
	}

	private static string KeyFor(string prefab)
	{
		if ((Object)(object)ObjectDB.instance == (Object)null || string.IsNullOrEmpty(prefab))
		{
			return null;
		}
		GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(prefab);
		ItemDrop val = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null);
		if (!((Object)(object)val != (Object)null))
		{
			return null;
		}
		return val.m_itemData.m_shared.m_name;
	}

	private static string NoBeardName()
	{
		PlayerCustomizaton val = Customizer();
		if (!((Object)(object)val != (Object)null) || !((Object)(object)val.m_noBeard != (Object)null))
		{
			return "BeardNone";
		}
		return ((Object)val.m_noBeard).name;
	}

	private static void SetSkin(Player p, PlayerCustomizaton pc, float darkness)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		float num = SkinSlider(darkness);
		if ((Object)(object)pc != (Object)null && (Object)(object)pc.m_skinHue != (Object)null)
		{
			pc.m_skinHue.value = num;
		}
		p.SetSkinColor(V(Color.Lerp(skin0, skin1, num)));
	}

	internal static void ApplyPreset(Player p, RaceDef r, PlayerCustomizaton pc)
	{
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		pc = pc ?? Customizer();
		LearnColors(pc);
		SetSkin(p, pc, r.SkinDarkness);
		if ((Object)(object)pc != (Object)null && (Object)(object)pc.m_hairTone != (Object)null)
		{
			pc.m_hairTone.value = r.HairTone;
		}
		if ((Object)(object)pc != (Object)null && (Object)(object)pc.m_hairLevel != (Object)null)
		{
			pc.m_hairLevel.value = r.HairLevel;
		}
		p.SetHairColor(V(Color.Lerp(hair0, hair1, r.HairTone) * Mathf.Lerp(hairMin, hairMax, r.HairLevel)));
		string text = PrefabFor(r.PresetHair);
		if (text != null)
		{
			((Humanoid)p).SetHair(text);
		}
		string text2 = PrefabFor(r.PresetBeard);
		if (text2 != null && p.GetPlayerModel() == 0)
		{
			((Humanoid)p).SetBeard(text2);
		}
		EnforceLook(p, r, pc);
	}

	internal static bool EnforceLook(Player p, RaceDef r, PlayerCustomizaton pc)
	{
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		bool result = false;
		if (r.RequiredHair != null && !r.RequiredHair.Contains(KeyFor(((Humanoid)p).GetHair())))
		{
			string text = PrefabFor(r.PresetHair);
			if (text != null)
			{
				((Humanoid)p).SetHair(text);
				result = true;
			}
		}
		if (r.RequiredBeard != null && p.GetPlayerModel() == 0 && !r.RequiredBeard.Contains(KeyFor(((Humanoid)p).GetBeard())))
		{
			string text2 = PrefabFor(r.PresetBeard);
			if (text2 != null)
			{
				((Humanoid)p).SetBeard(text2);
				result = true;
			}
		}
		if (r.NoBeard && p.GetPlayerModel() == 0)
		{
			string text3 = NoBeardName();
			string beard = ((Humanoid)p).GetBeard();
			if (!string.IsNullOrEmpty(beard) && beard != text3)
			{
				((Humanoid)p).SetBeard(text3);
				result = true;
			}
		}
		if (r.RequireDarkSkin)
		{
			if ((Object)(object)pc == (Object)null && !colorsKnown)
			{
				LearnColors(Customizer());
			}
			if (Darkness((Vector3)AccessTools.Field(typeof(Player), "m_skinColor").GetValue(p)) < 0.8f)
			{
				SetSkin(p, pc, r.SkinDarkness);
				result = true;
			}
		}
		return result;
	}

	internal static void ApplyInWorld(Player p, RaceDef r)
	{
		EnforceLook(p, r, null);
	}
}
inte