Decompiled source of Mjolnir Senhor do Trovao v1.18.1

BepInEx/plugins/Yoroshiro_Mjolnir/Mjolnir.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using SoftReferenceableAssets;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Yoroshiro")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Mod de Valheim criado por Yoroshiro.")]
[assembly: AssemblyFileVersion("1.18.1.0")]
[assembly: AssemblyInformationalVersion("1.18.1")]
[assembly: AssemblyProduct("Mjolnir - Senhor do Trovao")]
[assembly: AssemblyTitle("Mjolnir")]
[assembly: InternalsVisibleTo("Mjolnir.PoseFix")]
[assembly: AssemblyVersion("1.18.1.0")]
namespace MyValheimMod;

internal static class MjolnirAttackTempo
{
	private static Animator tracked;

	private static readonly TempoFactor factor = new TempoFactor();

	internal static void Remove(Animator animator)
	{
		if (Object.op_Implicit((Object)(object)animator))
		{
			if (Object.op_Implicit((Object)(object)tracked) && (Object)(object)tracked != (Object)(object)animator)
			{
				Restore();
			}
			tracked = animator;
			animator.speed = factor.Remove(animator.speed);
		}
	}

	internal static void Restore()
	{
		if (Object.op_Implicit((Object)(object)tracked))
		{
			tracked.speed = factor.Remove(tracked.speed);
		}
		tracked = null;
	}

	internal static void Apply(Animator animator, Character owner, float freezeTimer)
	{
		MjolnirPlugin active = MjolnirPlugin.Active;
		if (Object.op_Implicit((Object)(object)animator) && Object.op_Implicit((Object)(object)active) && !((Object)(object)owner != (Object)(object)Player.m_localPlayer))
		{
			bool enabled = owner.InAttack() && freezeTimer <= 0f && active.HasAttackBuff(Player.m_localPlayer);
			animator.speed = factor.Apply(animator.speed, active.AttackBonus.Value, enabled);
		}
	}
}
[HarmonyPatch(typeof(CharacterAnimEvent), "CustomFixedUpdate")]
internal static class AttackTempoUpdate
{
	[HarmonyPriority(800)]
	private static void Prefix(Character ___m_character, Animator ___m_animator)
	{
		if ((Object)(object)___m_character == (Object)(object)Player.m_localPlayer)
		{
			MjolnirAttackTempo.Remove(___m_animator);
		}
	}

	[HarmonyPriority(0)]
	private static void Postfix(Character ___m_character, Animator ___m_animator, float ___m_pauseTimer)
	{
		MjolnirAttackTempo.Apply(___m_animator, ___m_character, ___m_pauseTimer);
	}
}
[HarmonyPatch(typeof(CharacterAnimEvent), "FreezeFrame")]
internal static class AttackTempoFreeze
{
	private static void Prefix(Character ___m_character, Animator ___m_animator)
	{
		if ((Object)(object)___m_character == (Object)(object)Player.m_localPlayer)
		{
			MjolnirAttackTempo.Remove(___m_animator);
		}
	}
}
public sealed class CatchCue
{
	public bool Fired { get; private set; }

	public bool TryFire(bool returning, float distance, float speed)
	{
		if (Fired || !returning || float.IsNaN(distance) || float.IsInfinity(distance) || float.IsNaN(speed) || float.IsInfinity(speed) || distance < 0f || speed <= 0f)
		{
			return false;
		}
		if (distance > Math.Max(1f, speed * 0.3f))
		{
			return false;
		}
		Fired = true;
		return true;
	}
}
public sealed class ChargedAura : MonoBehaviour
{
	private LineRenderer[] arcs;

	private float next;

	private bool visible;

	private readonly Random random = new Random();

	private float Noise()
	{
		return (float)random.NextDouble() * 2f - 1f;
	}

	private void LateUpdate()
	{
		//IL_016a: 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_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: Unknown result type (might be due to invalid IL or missing references)
		MjolnirPlugin active = MjolnirPlugin.Active;
		if (!Object.op_Implicit((Object)(object)active) || active.Storm == null || !active.Storm.AuraReady || !Object.op_Implicit((Object)(object)Player.m_localPlayer) || !((Object)(object)((Component)this).gameObject == (Object)(object)((Component)Player.m_localPlayer).gameObject))
		{
			SetVisible(show: false);
			visible = false;
			return;
		}
		if (arcs == null)
		{
			if (!Object.op_Implicit((Object)(object)MjolnirLightning.ArcMaterial()))
			{
				return;
			}
			arcs = (LineRenderer[])(object)new LineRenderer[8];
			for (int i = 0; i < arcs.Length; i++)
			{
				arcs[i] = MjolnirLightning.NewLine(((Component)this).transform, "Mjolnir_ChargedAura", 0.015f);
				arcs[i].useWorldSpace = false;
			}
		}
		if (!visible)
		{
			SetVisible(show: true);
			visible = true;
		}
		if (Time.time < next)
		{
			return;
		}
		next = Time.time + 0.045f;
		Vector3 val = default(Vector3);
		for (int j = 0; j < arcs.Length; j++)
		{
			((Renderer)arcs[j]).enabled = random.NextDouble() > 0.25;
			float num = (float)random.NextDouble() * MathF.PI * 2f;
			float num2 = 0.25f + (float)random.NextDouble() * 1.4f;
			((Vector3)(ref val))..ctor(Mathf.Cos(num) * 0.38f, num2, Mathf.Sin(num) * 0.32f);
			Vector3 val2 = val + new Vector3(Noise() * 0.22f, 0.15f + (float)random.NextDouble() * 0.35f, Noise() * 0.22f);
			for (int k = 0; k < 8; k++)
			{
				float num3 = (float)k / 7f;
				Vector3 val3 = new Vector3(Noise(), Noise(), Noise()) * 0.09f * Mathf.Sin(num3 * MathF.PI);
				arcs[j].SetPosition(k, Vector3.Lerp(val, val2, num3) + val3);
			}
		}
	}

	private void SetVisible(bool show)
	{
		if (arcs == null)
		{
			return;
		}
		LineRenderer[] array = arcs;
		foreach (LineRenderer val in array)
		{
			if (Object.op_Implicit((Object)(object)val))
			{
				((Renderer)val).enabled = show;
			}
		}
	}

	private void OnDestroy()
	{
		if (arcs == null)
		{
			return;
		}
		LineRenderer[] array = arcs;
		foreach (LineRenderer val in array)
		{
			if (Object.op_Implicit((Object)(object)val))
			{
				Object.Destroy((Object)(object)((Component)val).gameObject);
			}
		}
	}
}
[HarmonyPatch(typeof(Character), "Damage")]
internal static class ChargedJumpFallDamage
{
	private static bool Prefix(Character __instance, HitData __0)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Invalid comparison between Unknown and I4
		MjolnirPlugin active = MjolnirPlugin.Active;
		if (Object.op_Implicit((Object)(object)active) && active.Storm != null && (Object)(object)__instance == (Object)(object)Player.m_localPlayer && __0 != null && (int)__0.m_hitType == 3)
		{
			return !active.Storm.ProtectOwnJumpFall;
		}
		return true;
	}
}
public sealed class ChargeMeter
{
	private readonly HashSet<int> awarded = new HashSet<int>();

	private double percent;

	public int Kills => (int)Math.Floor(percent * (double)Goal / 100.0 + 1E-06);

	public float Percent => (float)percent;

	public bool HasCharge => percent > 1E-05;

	public int Goal { get; private set; } = 5;

	public bool Ready => percent >= 99.99999;

	public float Fraction => (float)(percent / 100.0);

	public void SetGoal(int goal)
	{
		Goal = Math.Max(2, Math.Min(12, goal));
	}

	public void Load(int kills)
	{
		LoadPercent((float)kills * 100f / (float)Goal);
	}

	public void LoadPercent(float value)
	{
		percent = ((float.IsNaN(value) || float.IsInfinity(value)) ? 0f : Math.Max(0f, Math.Min(100f, value)));
	}

	public bool AddKill()
	{
		if (Ready)
		{
			return false;
		}
		percent = Math.Min(100.0, percent + 100.0 / (double)Goal);
		return true;
	}

	public bool AwardKill(int creatureId)
	{
		if (awarded.Add(creatureId))
		{
			return AddKill();
		}
		return false;
	}

	public void BeginSession()
	{
		awarded.Clear();
		Clear();
	}

	public bool Drain(float dt, float rate)
	{
		if (!HasCharge || float.IsNaN(dt) || float.IsInfinity(dt) || dt <= 0f || float.IsNaN(rate) || float.IsInfinity(rate))
		{
			return false;
		}
		rate = Math.Max(0.5f, Math.Min(10f, rate));
		percent = Math.Max(0.0, percent - (double)dt * (double)rate);
		if (percent < 1E-05)
		{
			percent = 0.0;
		}
		return true;
	}

	public bool SpendPercent(float cost)
	{
		if (float.IsNaN(cost) || float.IsInfinity(cost) || cost <= 0f || cost > 100f || percent + 1E-05 < (double)cost)
		{
			return false;
		}
		percent = Math.Max(0.0, percent - (double)cost);
		return true;
	}

	public bool SpendOne()
	{
		if (!HasCharge)
		{
			return false;
		}
		percent = Math.Max(0.0, percent - 100.0 / (double)Goal);
		return true;
	}

	public bool Consume()
	{
		if (!Ready)
		{
			return false;
		}
		Clear();
		return true;
	}

	public void Clear()
	{
		percent = 0.0;
	}
}
[BepInPlugin("com.seunome.mjolnir", "Mjölnir - Yoroshiro", "1.18.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class MjolnirPlugin : BaseUnityPlugin
{
	internal static MjolnirPlugin Active;

	internal ConfigEntry<Vector3> GripPosition;

	internal ConfigEntry<Vector3> GripRotation;

	internal ConfigEntry<float> GripScale;

	private AssetBundle bundle;

	private GameObject model;

	private Sprite inventoryIcon;

	private Sprite overchargeIcon;

	internal MjolnirFlight Flight;

	internal ConfigEntry<float> ThrowRange;

	internal ConfigEntry<float> ThrowSpeed;

	internal ConfigEntry<float> ReturnSpeed;

	internal ConfigEntry<float> ThrowStamina;

	internal ConfigEntry<bool> LightningEnabled;

	internal ConfigEntry<bool> ProtectPlayerBuildings;

	internal ConfigEntry<float> SprintDrainMultiplier;

	internal ConfigEntry<float> ImpactShake;

	private Harmony harmony;

	internal ConfigEntry<bool> CatchAnimationEnabled;

	internal ConfigEntry<bool> ThunderImpactEnabled;

	internal ConfigEntry<float> ThunderVolume;

	private SoftReference<GameObject> thunderReference;

	private bool thunderHeld;

	private AudioClip thunderClip;

	private AudioMixerGroup thunderMixer;

	private float nextThrow;

	internal string ThrowAnimation;

	internal readonly ThrowRequest Request = new ThrowRequest();

	internal ConfigEntry<KeyCode> ThrowKey;

	internal Attack AnimatedThrowAttack;

	internal ConfigEntry<float> MovementBonus;

	internal ConfigEntry<float> AttackBonus;

	internal ConfigEntry<bool> BuffEnabled;

	internal ConfigEntry<int> ImpactBolts;

	private SE_Stats lordOfThunder;

	internal StormAbility Storm;

	internal TargetLightning Strike;

	internal ConfigEntry<float> StrikeCost;

	internal ConfigEntry<float> StrikeCooldown;

	internal ConfigEntry<float> StrikeDamage;

	internal ConfigEntry<float> StrikeRange;

	internal ConfigEntry<float> StrikeRadius;

	internal StormFlight Wings;

	internal StatusEffect Overcharge;

	internal ConfigEntry<bool> InfiniteOvercharge;

	internal ConfigEntry<bool> FlightEnabled;

	internal ConfigEntry<bool> FlightDestruction;

	internal ConfigEntry<bool> FlightTerrain;

	internal ConfigEntry<float> FlightSpeed;

	internal ConfigEntry<float> FlightFastSpeed;

	internal ConfigEntry<float> FlightSmashDamage;

	internal ConfigEntry<float> FlightChargeSeconds;

	internal ConfigEntry<float> FlightDrainPercent;

	internal ConfigEntry<float> ThrowDamageMultiplier;

	internal ConfigEntry<float> JumpDamage;

	internal ConfigEntry<float> JumpRadius;

	internal ConfigEntry<float> JumpVelocity;

	internal ConfigEntry<int> ChargeKills;

	internal ConfigEntry<float> SprintLeapSpeed;

	internal ConfigEntry<float> LandingStructureDamage;

	internal ConfigEntry<bool> LandingDamagesStructures;

	internal ConfigEntry<bool> NordicHud;

	internal ConfigEntry<float> HudScale;

	internal ConfigEntry<float> HudVerticalOffset;

	internal StormMenu MenuPanel;

	internal Sprite LightningIcon => overchargeIcon;

	internal GameObject WeaponModel => model;

	private void Awake()
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_072f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0739: Expected O, but got Unknown
		Active = this;
		GripRotation = ((BaseUnityPlugin)this).Config.Bind<Vector3>("Visual", "Rotation", new Vector3(90f, 0f, 0f), "Rotacao local em graus.");
		GripPosition = ((BaseUnityPlugin)this).Config.Bind<Vector3>("Visual", "Position", Vector3.zero, "Deslocamento local em metros.");
		GripScale = ((BaseUnityPlugin)this).Config.Bind<float>("Visual", "Scale", 1f, "Escala do modelo.");
		string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "mjolnirassets");
		if (!File.Exists(text))
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Falta o AssetBundle: " + text + ". Gere-o no Unity conforme LEIA-ME."));
			return;
		}
		bundle = AssetBundle.LoadFromFile(text);
		if (!Object.op_Implicit((Object)(object)bundle) || !Object.op_Implicit((Object)(object)(model = bundle.LoadAsset<GameObject>("MjolnirVisual"))))
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"Nao foi possivel carregar MjolnirVisual do AssetBundle.");
			return;
		}
		ThrowRange = ((BaseUnityPlugin)this).Config.Bind<float>("Throw", "Range", 22f, "Alcance em metros (3 a 60).");
		ThrowSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Throw", "Speed", 24f, "Velocidade de ida em metros por segundo.");
		ReturnSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Throw", "ReturnSpeed", 32f, "Velocidade de retorno.");
		ThrowStamina = ((BaseUnityPlugin)this).Config.Bind<float>("Throw", "Stamina", 15f, "Custo de vigor por arremesso.");
		LightningEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Effects", "Lightning", true, "Arcos eletricos visuais.");
		ThrowKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "ThrowKey", (KeyCode)103, "Tecla para arremessar com animacao.");
		BuffEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Buff", "Enabled", true, "Senhor do Trovao enquanto equipado.");
		MovementBonus = ((BaseUnityPlugin)this).Config.Bind<float>("Buff", "MovementPercent", 5f, "Bonus de movimento, limitado a 10%.");
		AttackBonus = ((BaseUnityPlugin)this).Config.Bind<float>("Buff", "AttackSpeedPercent", 8f, "Bonus dos ataques normais, limitado a 15%.");
		ImpactBolts = ((BaseUnityPlugin)this).Config.Bind<int>("Effects", "ImpactBolts", 5, "Quantidade de raios no impacto, de 1 a 8.");
		CatchAnimationEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Return", "CatchAnimation", true, "Gesto de receber o martelo.");
		ThunderImpactEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Effects", "ThunderImpact", true, "Impacto visual e sonoro de trovao.");
		ThunderVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Effects", "ThunderVolume", 0.65f, "Volume do trovao de 0 a 1.");
		ThrowDamageMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Throw", "DamageMultiplier", 1.4f, "Multiplicador do dano de arremesso.");
		JumpDamage = ((BaseUnityPlugin)this).Config.Bind<float>("StormJump", "ImpactDamage", 120f, "Dano eletrico central do salto.");
		JumpRadius = ((BaseUnityPlugin)this).Config.Bind<float>("StormJump", "ImpactRadius", 5.5f, "Raio do impacto do salto em metros.");
		JumpVelocity = ((BaseUnityPlugin)this).Config.Bind<float>("StormJump", "ChargedVerticalSpeed", 14f, "Impulso do salto cheio, de 9 a 16 m/s.");
		ChargeKills = ((BaseUnityPlugin)this).Config.Bind<int>("StormJump", "KillsRequired", 5, "Abates diretos para encher o medidor.");
		NordicHud = ((BaseUnityPlugin)this).Config.Bind<bool>("HUD", "Enabled", true, "Mostrar medidor nordico com o martelo equipado.");
		HudScale = ((BaseUnityPlugin)this).Config.Bind<float>("HUD", "CompactScale", 0.85f, "Tamanho do HUD compacto.");
		HudVerticalOffset = ((BaseUnityPlugin)this).Config.Bind<float>("HUD", "VerticalOffset", 0f, "Ajuste vertical abaixo do mapa, em pixels.");
		SprintLeapSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("StormJump", "SprintForwardSpeed", 16f, "Impulso frontal correndo com Shift.");
		LandingStructureDamage = ((BaseUnityPlugin)this).Config.Bind<float>("StormJump", "StructureDamage", 100f, "Dano contundente base nas estruturas da aterrissagem.");
		LandingDamagesStructures = ((BaseUnityPlugin)this).Config.Bind<bool>("StormJump", "DamageStructures", true, "Dano nas estruturas proximas ao aterrissar.");
		FlightEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Flight", "Enabled", true, "Voo com dois toques em Espaco.");
		FlightDestruction = ((BaseUnityPlugin)this).Config.Bind<bool>("Flight", "Destruction", true, "Colisoes rapidas danificam objetos e inimigos.");
		FlightTerrain = ((BaseUnityPlugin)this).Config.Bind<bool>("Flight", "DeformTerrain", false, "PERMANENTE: escava solo nas colisoes e mergulhos.");
		FlightSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Flight", "Speed", 12f, "Velocidade normal do voo.");
		FlightFastSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Flight", "FastSpeed", 32f, "Velocidade com Shift.");
		FlightSmashDamage = ((BaseUnityPlugin)this).Config.Bind<float>("Flight", "SmashDamage", 1500f, "Dano bruto de colisao destrutiva.");
		FlightChargeSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Flight", "SecondsPerCharge", 8f, "Segundos de voo por parte do medidor (3 a 30).");
		FlightDrainPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Flight", "PercentPerSecond", 100f / (float)Mathf.Clamp(ChargeKills.Value, 2, 12) / Mathf.Clamp(FlightChargeSeconds.Value, 3f, 30f), "Consumo percentual por segundo (0.5 a 10).");
		InfiniteOvercharge = ((BaseUnityPlugin)this).Config.Bind<bool>("Tests", "InfiniteOvercharge", false, "TESTES: manter carga cheia, sem consumo no voo/salto.");
		ProtectPlayerBuildings = ((BaseUnityPlugin)this).Config.Bind<bool>("Safety", "ProtectPlayerBuildings", true, "Protege construcoes feitas por jogadores contra os poderes do Mjolnir.");
		SprintDrainMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Flight", "SprintDrainMultiplier", 1.5f, "Multiplicador do consumo com Shift em movimento (1 a 3).");
		ImpactShake = ((BaseUnityPlugin)this).Config.Bind<float>("Effects", "ImpactShake", 0.15f, "Intensidade da camera nos impactos fortes (0 desliga, maximo 0.3).");
		StrikeCost = ((BaseUnityPlugin)this).Config.Bind<float>("LightningSkill", "EnergyCostPercent", 30f, "Custo percentual da habilidade Shift+G (10 a 100).");
		StrikeCooldown = ((BaseUnityPlugin)this).Config.Bind<float>("LightningSkill", "CooldownSeconds", 8f, "Recarga em segundos, inclusive em energia infinita (2 a 30).");
		StrikeDamage = ((BaseUnityPlugin)this).Config.Bind<float>("LightningSkill", "Damage", 90f, "Dano eletrico central (20 a 180).");
		StrikeRange = ((BaseUnityPlugin)this).Config.Bind<float>("LightningSkill", "Range", 40f, "Alcance da mira em metros (5 a 60).");
		StrikeRadius = ((BaseUnityPlugin)this).Config.Bind<float>("LightningSkill", "Radius", 2.5f, "Raio do impacto (0.5 a 4 metros).");
		Strike = new TargetLightning(this);
		Wings = new StormFlight(this);
		Storm = new StormAbility(this);
		MenuPanel = new StormMenu(this, ((BaseUnityPlugin)this).Config);
		harmony = new Harmony("com.seunome.mjolnir.throw");
		harmony.PatchAll(typeof(MjolnirPlugin).Assembly);
		LoadInventoryIcon();
		LoadOverchargeIcon();
		PrefabManager.OnVanillaPrefabsAvailable += RegisterMjolnir;
	}

	private void LoadInventoryIcon()
	{
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Expected O, but got Unknown
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "Mjolnir_icon.png");
		if (!File.Exists(text))
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Icone nao encontrado: " + text + ". Usando icone da arma base."));
			return;
		}
		Texture2D val = null;
		try
		{
			val = new Texture2D(2, 2, (TextureFormat)4, false);
			if (!ImageConversion.LoadImage(val, File.ReadAllBytes(text), false))
			{
				throw new InvalidDataException("PNG invalido.");
			}
			((Object)val).name = "Mjolnir_InventoryTexture";
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Texture)val).filterMode = (FilterMode)1;
			inventoryIcon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0);
			((Object)inventoryIcon).name = "Mjolnir_InventoryIcon";
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Icone do Mjolnir carregado.");
		}
		catch (Exception ex)
		{
			if (Object.op_Implicit((Object)(object)val))
			{
				Object.Destroy((Object)(object)val);
			}
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Falha no icone; mantendo o original: " + ex.Message));
		}
	}

	private void LoadOverchargeIcon()
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Expected O, but got Unknown
		//IL_007a: 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)
		try
		{
			string path = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "Sobrecarga_icon.png");
			if (!File.Exists(path))
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Falta Sobrecarga_icon.png; usando icone do martelo.");
				return;
			}
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			if (!ImageConversion.LoadImage(val, File.ReadAllBytes(path), false))
			{
				Object.Destroy((Object)(object)val);
				return;
			}
			((Texture)val).wrapMode = (TextureWrapMode)1;
			overchargeIcon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0);
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Icone Sobrecarga: " + ex.Message));
		}
	}

	private void RegisterMjolnir()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Expected O, but got Unknown
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Expected O, but got Unknown
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Expected O, but got Unknown
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Expected O, but got Unknown
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Expected O, but got Unknown
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Expected O, but got Unknown
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0381: Unknown result type (might be due to invalid IL or missing references)
		//IL_038b: Expected O, but got Unknown
		//IL_04a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ac: Expected O, but got Unknown
		PrefabManager.OnVanillaPrefabsAvailable -= RegisterMjolnir;
		try
		{
			ItemConfig val = new ItemConfig();
			val.Name = "Mjölnir";
			val.Description = "O martelo do deus do trovão.";
			val.CraftingStation = "forge";
			val.MinStationLevel = 2;
			val.Amount = 1;
			val.Requirements = (RequirementConfig[])(object)new RequirementConfig[4]
			{
				new RequirementConfig("Iron", 12, 0, true),
				new RequirementConfig("Wood", 4, 0, true),
				new RequirementConfig("BlackMetal", 6, 0, true),
				new RequirementConfig("AncientSeed", 1, 0, true)
			};
			ItemConfig val2 = val;
			StormBalance.TuneRecipe(val2);
			CustomItem val3 = new CustomItem("ThorMjolnir1H", "MaceIron", val2);
			Transform val4 = val3.ItemPrefab.transform.Find("attach");
			if (!Object.op_Implicit((Object)(object)val4))
			{
				throw new InvalidOperationException("MaceIron nao contem o ponto attach esperado.");
			}
			Renderer[] componentsInChildren = ((Component)val4).GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].enabled = false;
			}
			GameObject val5 = Object.Instantiate<GameObject>(model, val4, false);
			((Object)val5).name = "MjolnirVisual";
			ApplyGrip(val5.transform);
			val5.AddComponent<MjolnirGrip>();
			val5.AddComponent<MjolnirLightning>();
			SharedData shared = val3.ItemPrefab.GetComponent<ItemDrop>().m_itemData.m_shared;
			GameObject prefab = PrefabManager.Instance.GetPrefab("SpearFlint");
			ItemDrop val6 = (Object.op_Implicit((Object)(object)prefab) ? prefab.GetComponent<ItemDrop>() : null);
			Attack val7 = (Object.op_Implicit((Object)(object)val6) ? val6.m_itemData.m_shared.m_secondaryAttack : null);
			if (val7 == null || string.IsNullOrEmpty(val7.m_attackAnimation))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Animacao SpearFlint indisponivel. Mantendo o item, sem arremesso.");
			}
			else
			{
				Attack val8 = val7.Clone();
				ThrowAnimation = val8.m_attackAnimation;
				val8.m_attackType = (AttackType)0;
				val8.m_consumeItem = false;
				val8.m_attackStamina = 0f;
				val8.m_attackEitr = 0f;
				val8.m_attackAdrenaline = 0f;
				val8.m_attackUseAdrenaline = 0f;
				val8.m_attackHealth = 0f;
				val8.m_attackProjectile = null;
				val8.m_spawnOnTrigger = null;
				val8.m_spawnOnHit = null;
				val8.m_attackChainLevels = 0;
				val8.m_attackRandomAnimations = 0;
				AnimatedThrowAttack = val8;
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Arremesso G: animacao nativa=" + ThrowAnimation));
			}
			lordOfThunder = ScriptableObject.CreateInstance<SE_Stats>();
			((Object)lordOfThunder).name = "SE_Mjolnir_LordOfThunder";
			((StatusEffect)lordOfThunder).m_name = "Senhor do Trovão";
			((StatusEffect)lordOfThunder).m_icon = inventoryIcon;
			lordOfThunder.m_speedModifier = (BuffEnabled.Value ? (Mathf.Clamp(MovementBonus.Value, 0f, 10f) / 100f) : 0f);
			((StatusEffect)lordOfThunder).m_hidden = !BuffEnabled.Value;
			((StatusEffect)lordOfThunder).m_tooltip = "+" + Mathf.Clamp(MovementBonus.Value, 0f, 10f) + "% movimento\n+" + Mathf.Clamp(AttackBonus.Value, 0f, 15f) + "% velocidade de ataque\nAtivo enquanto o Mjölnir estiver equipado.";
			if (ItemManager.Instance.AddStatusEffect(new CustomStatusEffect((StatusEffect)(object)lordOfThunder, false)))
			{
				shared.m_equipStatusEffect = (StatusEffect)(object)lordOfThunder;
				shared.m_movementModifier = 0f;
			}
			else
			{
				lordOfThunder = null;
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Nao foi possivel registrar Senhor do Trovao.");
			}
			if (Object.op_Implicit((Object)(object)inventoryIcon))
			{
				shared.m_icons = (Sprite[])(object)new Sprite[1] { inventoryIcon };
			}
			shared.m_attackForce = 60f;
			shared.m_damages.m_blunt = 55f;
			shared.m_damages.m_lightning = 20f;
			ForgeProgression.Configure(shared);
			if (!ItemManager.Instance.AddItem(val3))
			{
				throw new InvalidOperationException("Jotunn rejeitou o registro do item.");
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Mjolnir registrado: ThorMjolnir1H | Criado por Yoroshiro");
			StatusEffect val9 = ScriptableObject.CreateInstance<StatusEffect>();
			((Object)val9).name = "SE_Mjolnir_Overcharge";
			val9.m_name = "Sobrecarga";
			val9.m_icon = (Object.op_Implicit((Object)(object)overchargeIcon) ? overchargeIcon : inventoryIcon);
			val9.m_ttl = 0f;
			val9.m_tooltip = "Energia do trovão armazenada. O voo consome carga. Com o medidor cheio, segure Espaço para o salto carregado.";
			if (ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(val9, false)))
			{
				Overcharge = val9;
			}
			PrepareThunder();
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Falha ao registrar Mjolnir: " + ex));
		}
	}

	private void PrepareThunder()
	{
		//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_003a: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			thunderReference = AssetManager.Instance.GetSoftReference<GameObject>("sfx_thunder");
			if (!thunderReference.IsValid)
			{
				throw new InvalidOperationException("sfx_thunder nao encontrado.");
			}
			thunderHeld = true;
			thunderReference.Load();
			GameObject asset = thunderReference.Asset;
			if (!Object.op_Implicit((Object)(object)asset))
			{
				throw new InvalidOperationException("sfx_thunder nao carregou.");
			}
			ZSFX componentInChildren = asset.GetComponentInChildren<ZSFX>(true);
			if ((Object)(object)componentInChildren != (Object)null && componentInChildren.m_audioClips != null)
			{
				AudioClip[] audioClips = componentInChildren.m_audioClips;
				foreach (AudioClip val in audioClips)
				{
					if (Object.op_Implicit((Object)(object)val))
					{
						thunderClip = val;
						break;
					}
				}
			}
			AudioSource componentInChildren2 = asset.GetComponentInChildren<AudioSource>(true);
			if (!Object.op_Implicit((Object)(object)thunderClip) && Object.op_Implicit((Object)(object)componentInChildren2))
			{
				thunderClip = componentInChildren2.clip;
			}
			if (Object.op_Implicit((Object)(object)componentInChildren2))
			{
				thunderMixer = componentInChildren2.outputAudioMixerGroup;
			}
			if (!Object.op_Implicit((Object)(object)thunderClip))
			{
				throw new InvalidOperationException("Clip de trovao indisponivel.");
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Som de impacto do trovao carregado: " + ((Object)thunderClip).name));
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Som de trovao indisponivel: " + ex.Message));
		}
	}

	internal void ThunderImpact(Vector3 point, float strength = 1f)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Expected O, but got Unknown
		try
		{
			if (ThunderImpactEnabled.Value)
			{
				MjolnirLightning.ThunderBurst(point, Mathf.Clamp(Mathf.RoundToInt((float)ImpactBolts.Value * strength), 1, 8), strength);
				if (Object.op_Implicit((Object)(object)thunderClip))
				{
					GameObject val = new GameObject("Mjolnir_ThunderSound");
					val.transform.position = point;
					AudioSource obj = val.AddComponent<AudioSource>();
					obj.clip = thunderClip;
					obj.outputAudioMixerGroup = thunderMixer;
					obj.spatialBlend = 1f;
					obj.rolloffMode = (AudioRolloffMode)1;
					obj.minDistance = 4f;
					obj.maxDistance = 70f;
					obj.volume = Mathf.Clamp01(ThunderVolume.Value) * Mathf.Clamp(strength, 0.2f, 1f);
					obj.Play();
					Object.Destroy((Object)val, Mathf.Min(thunderClip.length + 1f, 30f));
				}
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Efeito de impacto: " + ex.Message));
		}
	}

	internal bool ProtectedBuilding(Collider collider)
	{
		if (!ProtectPlayerBuildings.Value || !Object.op_Implicit((Object)(object)collider))
		{
			return false;
		}
		Piece componentInParent = ((Component)collider).GetComponentInParent<Piece>();
		if (Object.op_Implicit((Object)(object)componentInParent))
		{
			return componentInParent.IsPlacedByPlayer();
		}
		return false;
	}

	internal void FlightImpact(Vector3 point, Vector3 normal, float speed)
	{
		//IL_0025: 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_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		if (!ThunderImpactEnabled.Value)
		{
			return;
		}
		float num = FlightPolishRules.ImpactStrength(speed);
		if (speed < 8f)
		{
			MjolnirLightning.Impact(point);
			return;
		}
		ThunderImpact(point, num);
		if (speed >= 18f)
		{
			LandingDust.Spawn(point, normal);
		}
		if (Object.op_Implicit((Object)(object)GameCamera.instance) && ImpactShake.Value > 0f)
		{
			GameCamera.instance.AddShake(point, 15f, Mathf.Clamp(ImpactShake.Value, 0f, 0.3f) * num, false);
		}
	}

	internal void CatchGesture(Player owner)
	{
		if (!CatchAnimationEnabled.Value || !Object.op_Implicit((Object)(object)owner) || ((Character)owner).IsDead())
		{
			return;
		}
		try
		{
			if (Wings.Active)
			{
				((Component)owner).GetComponent<ThorFlightPose>()?.BeginCatch();
				return;
			}
			ZSyncAnimation zAnim = ((Character)owner).GetZAnim();
			if (Object.op_Implicit((Object)(object)zAnim))
			{
				zAnim.SetTrigger("interact");
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Gesto de retorno: " + ex.Message));
		}
	}

	internal void RefreshBuff()
	{
		float num = (BuffEnabled.Value ? (Mathf.Clamp(MovementBonus.Value, 0f, 10f) / 100f) : 0f);
		string tooltip = "+" + (num * 100f).ToString("0") + "% movimento\n+" + (BuffEnabled.Value ? Mathf.Clamp(AttackBonus.Value, 0f, 15f) : 0f).ToString("0") + "% velocidade de ataque";
		if (Object.op_Implicit((Object)(object)lordOfThunder))
		{
			lordOfThunder.m_speedModifier = num;
			((StatusEffect)lordOfThunder).m_hidden = !BuffEnabled.Value;
			((StatusEffect)lordOfThunder).m_tooltip = tooltip;
		}
		Player localPlayer = Player.m_localPlayer;
		if (!Object.op_Implicit((Object)(object)localPlayer))
		{
			return;
		}
		foreach (StatusEffect statusEffect in ((Character)localPlayer).GetSEMan().GetStatusEffects())
		{
			if (((Object)statusEffect).name == "SE_Mjolnir_LordOfThunder")
			{
				SE_Stats val = (SE_Stats)(object)((statusEffect is SE_Stats) ? statusEffect : null);
				if (val != null)
				{
					val.m_speedModifier = num;
					((StatusEffect)val).m_hidden = !BuffEnabled.Value;
					((StatusEffect)val).m_tooltip = tooltip;
				}
			}
		}
	}

	internal bool HasAttackBuff(Player owner)
	{
		if (Object.op_Implicit((Object)(object)owner) && Object.op_Implicit((Object)(object)lordOfThunder) && BuffEnabled.Value && !((Character)owner).IsDead() && IsMjolnir(((Humanoid)owner).GetCurrentWeapon()) && !Object.op_Implicit((Object)(object)Flight))
		{
			return !Request.Pending;
		}
		return false;
	}

	internal static bool IsMjolnir(ItemData weapon)
	{
		if (weapon != null && Object.op_Implicit((Object)(object)weapon.m_dropPrefab))
		{
			return ((Object)weapon.m_dropPrefab).name == "ThorMjolnir1H";
		}
		return false;
	}

	internal bool CanBeginThrow(Player owner, ItemData weapon)
	{
		if (Object.op_Implicit((Object)(object)owner) && IsMjolnir(weapon) && !Object.op_Implicit((Object)(object)Flight) && !Request.Pending && !string.IsNullOrEmpty(ThrowAnimation) && Time.time >= nextThrow && !((Character)owner).IsDead() && !((Character)owner).IsTeleporting() && !((Character)owner).InCutscene() && ((Character)owner).CanMove() && !((Character)owner).InAttack() && !((Character)owner).IsDodgeInvincible() && !Storm.Busy && !MenuPanel.Open && (!weapon.m_shared.m_useDurability || weapon.m_durability > 0f))
		{
			return ((Character)owner).HaveStamina(Mathf.Clamp(ThrowStamina.Value, 0f, 100f));
		}
		return false;
	}

	internal void ReleaseFromAnimation(Player owner, ItemData weapon)
	{
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Expected O, but got Unknown
		if (!Request.Consume(weapon, Time.time) || !Object.op_Implicit((Object)(object)owner) || Object.op_Implicit((Object)(object)Flight) || ((Character)owner).IsDead() || ((Character)owner).IsTeleporting() || ((Humanoid)owner).GetCurrentWeapon() != weapon || (weapon.m_shared.m_useDurability && weapon.m_durability <= 0f))
		{
			return;
		}
		float num = Mathf.Clamp(ThrowStamina.Value, 0f, 100f);
		if (!((Character)owner).HaveStamina(num))
		{
			return;
		}
		Transform val = FindEquippedVisual();
		if (!Object.op_Implicit((Object)(object)val))
		{
			return;
		}
		GameObject val2 = new GameObject("Mjolnir_ReturningHammer");
		try
		{
			MjolnirFlight mjolnirFlight = val2.AddComponent<MjolnirFlight>();
			mjolnirFlight.Initialize(this, owner, weapon, val);
			Flight = mjolnirFlight;
			((Character)owner).UseStamina(num);
			if (weapon.m_shared.m_useDurability)
			{
				weapon.m_durability = Mathf.Max(0f, weapon.m_durability - 1f);
			}
			nextThrow = Time.time + 0.8f;
		}
		catch (Exception ex)
		{
			Object.Destroy((Object)(object)val2);
			((BaseUnityPlugin)this).Logger.LogError((object)("Falha no arremesso: " + ex));
		}
	}

	private void UpdateThrowInput()
	{
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if (!Object.op_Implicit((Object)(object)localPlayer))
		{
			Request.Cancel();
			return;
		}
		if (Request.Pending && (((Character)localPlayer).IsDead() || ((Character)localPlayer).IsTeleporting() || ((Humanoid)localPlayer).GetCurrentWeapon() != Request.Weapon))
		{
			Request.Cancel();
		}
		if (Request.Expire(Time.time))
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"Arremesso cancelado: animacao nao emitiu o evento em 3 segundos.");
		}
		if (Strike.Busy || TargetLightning.ChordHeld || MenuPanel.Open || Storm.Busy || !Input.GetKeyDown(ThrowKey.Value) || InventoryGui.IsVisible() || Menu.IsVisible() || Console.IsVisible() || TextInput.IsVisible() || (Object.op_Implicit((Object)(object)Chat.instance) && Chat.instance.HasFocus()))
		{
			return;
		}
		ItemData currentWeapon = ((Humanoid)localPlayer).GetCurrentWeapon();
		if (!CanBeginThrow(localPlayer, currentWeapon))
		{
			return;
		}
		MjolnirHotkeyScope.Active = true;
		try
		{
			((Character)localPlayer).StartAttack((Character)null, true);
		}
		finally
		{
			MjolnirHotkeyScope.Active = false;
		}
	}

	internal void ApplyGrip(Transform target)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		target.localPosition = GripPosition.Value;
		target.localEulerAngles = GripRotation.Value;
		target.localScale = Vector3.one * GripScale.Value;
	}

	private Transform FindEquippedVisual()
	{
		if (!Object.op_Implicit((Object)(object)Player.m_localPlayer))
		{
			return null;
		}
		Transform[] componentsInChildren = ((Component)Player.m_localPlayer).GetComponentsInChildren<Transform>();
		foreach (Transform val in componentsInChildren)
		{
			if (((Object)val).name == "MjolnirVisual" && ((Component)val).gameObject.activeInHierarchy)
			{
				return val;
			}
		}
		return null;
	}

	internal void NudgeGrip(Vector3 worldDelta)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		Transform val = FindEquippedVisual();
		if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.parent))
		{
			ConfigEntry<Vector3> gripPosition = GripPosition;
			gripPosition.Value += val.parent.InverseTransformVector(worldDelta);
		}
	}

	private void Update()
	{
		if (Storm != null && MenuPanel != null)
		{
			if (Input.GetKeyDown((KeyCode)291) && !StormAbility.InterfaceOpen())
			{
				NordicHud.Value = !NordicHud.Value;
				((BaseUnityPlugin)this).Config.Save();
			}
			MenuPanel.Update();
			Wings.Update();
			Storm.Update();
			StormBalance.Update(this);
			Strike.Update();
			UpdateThrowInput();
		}
	}

	private void OnGUI()
	{
		Storm?.DrawHud();
		MenuPanel?.Draw();
	}

	private void OnDestroy()
	{
		PrefabManager.OnVanillaPrefabsAvailable -= RegisterMjolnir;
		MenuPanel?.Close();
		Wings?.Stop();
		Storm?.Dispose();
		Request.Cancel();
		if (Object.op_Implicit((Object)(object)Flight))
		{
			Object.DestroyImmediate((Object)(object)((Component)Flight).gameObject);
		}
		MjolnirAttackTempo.Restore();
		Harmony obj = harmony;
		if (obj != null)
		{
			obj.UnpatchSelf();
		}
		if (thunderHeld)
		{
			thunderReference.Release();
			thunderHeld = false;
		}
		LandingDust.Release();
		MjolnirLightning.ReleaseMaterial();
		if ((Object)(object)Active == (Object)(object)this)
		{
			Active = null;
		}
	}
}
public class MjolnirGrip : MonoBehaviour
{
	private void LateUpdate()
	{
		if (Object.op_Implicit((Object)(object)MjolnirPlugin.Active))
		{
			MjolnirPlugin.Active.ApplyGrip(((Component)this).transform);
		}
	}
}
public sealed class FlightChargeClock
{
	public float Elapsed { get; private set; }

	public int Advance(float dt, float secondsPerUnit, int available)
	{
		if (available <= 0)
		{
			Elapsed = 0f;
			return 0;
		}
		if (float.IsNaN(dt) || float.IsInfinity(dt) || dt < 0f)
		{
			return 0;
		}
		if (float.IsNaN(secondsPerUnit) || float.IsInfinity(secondsPerUnit))
		{
			secondsPerUnit = 8f;
		}
		secondsPerUnit = Math.Max(3f, Math.Min(30f, secondsPerUnit));
		Elapsed += dt;
		int num = Math.Min(available, (int)Math.Min(available, Math.Floor(Elapsed / secondsPerUnit)));
		Elapsed -= (float)num * secondsPerUnit;
		if (num == available)
		{
			Elapsed = 0f;
		}
		return num;
	}

	public void Reset()
	{
		Elapsed = 0f;
	}
}
[HarmonyPatch(typeof(ZSyncAnimation), "SetTrigger", new Type[] { typeof(string) })]
internal static class FlightJumpGuard
{
	private static bool Prefix(ZSyncAnimation __instance, string __0)
	{
		MjolnirPlugin active = MjolnirPlugin.Active;
		if (Object.op_Implicit((Object)(object)active) && active.Wings != null && active.Wings.Active && Object.op_Implicit((Object)(object)Player.m_localPlayer) && (Object)(object)((Character)Player.m_localPlayer).GetZAnim() == (Object)(object)__instance)
		{
			return !(__0 == "jump");
		}
		return true;
	}
}
public static class FlightPolishRules
{
	public static float DrainRate(float basic, float multiplier, bool sprint)
	{
		if (float.IsNaN(basic) || float.IsInfinity(basic))
		{
			basic = 2.5f;
		}
		if (float.IsNaN(multiplier) || float.IsInfinity(multiplier))
		{
			multiplier = 1.5f;
		}
		return Math.Min(10f, Math.Max(0.5f, Math.Min(10f, basic)) * (sprint ? Math.Max(1f, Math.Min(3f, multiplier)) : 1f));
	}

	public static float ImpactStrength(float speed)
	{
		if (float.IsNaN(speed) || float.IsInfinity(speed))
		{
			return 0.2f;
		}
		return 0.2f + 0.8f * Math.Max(0f, Math.Min(1f, (speed - 5f) / 27f));
	}
}
public static class FlightPoseAngles
{
	public static float AscentPitch(float pitch, float weight)
	{
		if (float.IsNaN(pitch) || float.IsInfinity(pitch) || float.IsNaN(weight) || float.IsInfinity(weight))
		{
			return 0f;
		}
		return pitch * (1f - Math.Max(0f, Math.Min(1f, weight)));
	}

	public static float Pitch(float horizontal, float vertical, float forward)
	{
		if (float.IsNaN(horizontal) || float.IsNaN(vertical) || float.IsNaN(forward) || float.IsInfinity(horizontal) || float.IsInfinity(vertical) || float.IsInfinity(forward))
		{
			return 0f;
		}
		float num = Math.Max(0f, Math.Min(1f, horizontal / 8f));
		float num2 = Math.Max(-1f, Math.Min(1f, forward));
		float num3 = 68f * num * Math.Max(0f, num2);
		if (vertical < -3f)
		{
			float num4 = Math.Max(0f, Math.Min(1f, (0f - vertical - 3f) / 18f));
			num3 += (110f - num3) * num4;
		}
		if (num2 < 0f)
		{
			num3 = -22f * num * (0f - num2);
		}
		return num3;
	}
}
public sealed class FlightTap
{
	private float previous = float.NegativeInfinity;

	public bool Tap(float now)
	{
		if (float.IsNaN(now) || float.IsInfinity(now))
		{
			Reset();
			return false;
		}
		float num = now - previous;
		previous = now;
		if (num >= 0.055f && num <= 0.32f)
		{
			Reset();
			return true;
		}
		return false;
	}

	public void Reset()
	{
		previous = float.NegativeInfinity;
	}
}
public static class HudPlacement
{
	public static (float X, float Y) Compute(float width, float height, float mapBottom, float hudWidth, float hudHeight, float offset)
	{
		if (float.IsNaN(mapBottom) || float.IsInfinity(mapBottom))
		{
			mapBottom = 220f;
		}
		if (float.IsNaN(offset) || float.IsInfinity(offset))
		{
			offset = 0f;
		}
		float item = Math.Max(10f, Math.Min(18f, width - hudWidth - 10f));
		float item2 = Math.Max(10f, Math.Min(mapBottom + 12f + offset, height - hudHeight - 10f));
		return (X: item, Y: item2);
	}
}
internal sealed class MjolnirDamageOrigin : IDisposable
{
	[ThreadStatic]
	internal static int Depth;

	private bool disposed;

	internal static MjolnirDamageOrigin Begin()
	{
		Depth++;
		return new MjolnirDamageOrigin();
	}

	public void Dispose()
	{
		if (!disposed)
		{
			Depth = Math.Max(0, Depth - 1);
			disposed = true;
		}
	}
}
[HarmonyPatch(typeof(Attack), "DoMeleeAttack")]
internal static class MjolnirMeleeSource
{
	private static void Prefix(Humanoid ___m_character, ItemData ___m_weapon, out MjolnirDamageOrigin __state)
	{
		__state = (((Object)(object)___m_character == (Object)(object)Player.m_localPlayer && MjolnirPlugin.IsMjolnir(___m_weapon)) ? MjolnirDamageOrigin.Begin() : null);
	}

	private static Exception Finalizer(Exception __exception, MjolnirDamageOrigin __state)
	{
		__state?.Dispose();
		return __exception;
	}
}
internal sealed class DamageStamp
{
	internal Player Owner;

	internal HitData Original;

	internal Vector3 Point;

	internal SkillType Skill;

	internal bool Ranged;

	internal float Time;
}
[HarmonyPatch(typeof(Character), "Damage")]
internal static class StampMjolnirDamage
{
	private static readonly ConditionalWeakTable<Character, List<DamageStamp>> Hits = new ConditionalWeakTable<Character, List<DamageStamp>>();

	private static void Prefix(Character __instance, HitData __0)
	{
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		if (__0 != null && MjolnirDamageOrigin.Depth > 0 && Object.op_Implicit((Object)(object)Player.m_localPlayer) && !((Object)(object)__0.GetAttacker() != (Object)(object)Player.m_localPlayer))
		{
			List<DamageStamp> value = Hits.GetValue(__instance, (Character _) => new List<DamageStamp>());
			value.RemoveAll((DamageStamp s) => Time.time - s.Time > 2f);
			if (value.Count >= 16)
			{
				value.RemoveAt(0);
			}
			value.Add(new DamageStamp
			{
				Owner = Player.m_localPlayer,
				Original = __0,
				Point = __0.m_point,
				Skill = __0.m_skill,
				Ranged = __0.m_ranged,
				Time = Time.time
			});
		}
	}

	internal static bool Consume(Character victim, HitData hit)
	{
		//IL_006e: 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_008a: 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 (hit == null || !Object.op_Implicit((Object)(object)Player.m_localPlayer) || (Object)(object)hit.GetAttacker() != (Object)(object)Player.m_localPlayer || !Hits.TryGetValue(victim, out var value))
		{
			return false;
		}
		value.RemoveAll((DamageStamp s) => Time.time - s.Time > 2f);
		for (int num = 0; num < value.Count; num++)
		{
			DamageStamp damageStamp = value[num];
			int num2;
			if (damageStamp.Original != hit)
			{
				if (damageStamp.Skill == hit.m_skill && damageStamp.Ranged == hit.m_ranged)
				{
					Vector3 val = damageStamp.Point - hit.m_point;
					num2 = ((((Vector3)(ref val)).sqrMagnitude < 0.0025f) ? 1 : 0);
				}
				else
				{
					num2 = 0;
				}
			}
			else
			{
				num2 = 1;
			}
			bool flag = (byte)num2 != 0;
			if ((Object)(object)damageStamp.Owner == (Object)(object)Player.m_localPlayer && flag)
			{
				value.RemoveAt(num);
				return true;
			}
		}
		return false;
	}
}
[HarmonyPatch(typeof(Character), "ApplyDamage")]
internal static class MjolnirKillCharge
{
	private static void Prefix(Character __instance, HitData __0, out bool __state)
	{
		__state = __0 != null && Object.op_Implicit((Object)(object)__instance) && !__instance.IsPlayer() && !__instance.IsTamed() && __instance.GetHealth() > 0f && StampMjolnirDamage.Consume(__instance, __0);
	}

	private static void Postfix(Character __instance, bool __state)
	{
		if (__state && Object.op_Implicit((Object)(object)__instance) && __instance.GetHealth() <= 0f)
		{
			MjolnirPlugin.Active?.Storm?.AddKill(__instance);
		}
	}
}
[HarmonyPatch(typeof(Character), "Jump")]
internal static class StormJumpInput
{
	private static bool Prefix(Character __instance)
	{
		MjolnirPlugin active = MjolnirPlugin.Active;
		if (Object.op_Implicit((Object)(object)active) && active.Storm != null)
		{
			return !active.Storm.InterceptJump(__instance);
		}
		return true;
	}
}
internal static class LandingDust
{
	private static Material material;

	private static Texture2D texture;

	internal static void Spawn(Vector3 point, Vector3 normal)
	{
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Expected O, but got Unknown
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: 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_01b8: 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_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: Unknown result type (might be due to invalid IL or missing references)
		//IL_021b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0236: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_024b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0255: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: Expected O, but got Unknown
		//IL_0266: Unknown result type (might be due to invalid IL or missing references)
		//IL_0270: Unknown result type (might be due to invalid IL or missing references)
		//IL_0275: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0286: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Expected O, but got Unknown
		//IL_0051: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)material))
		{
			Shader val = Shader.Find("Sprites/Default");
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			texture = new Texture2D(32, 32, (TextureFormat)4, false);
			Color[] array = (Color[])(object)new Color[1024];
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 32; j++)
				{
					float num = Vector2.Distance(new Vector2((float)j, (float)i), new Vector2(15.5f, 15.5f)) / 16f;
					array[i * 32 + j] = new Color(1f, 1f, 1f, Mathf.Pow(Mathf.Clamp01(1f - num), 1.6f));
				}
			}
			texture.SetPixels(array);
			texture.Apply();
			material = new Material(val)
			{
				mainTexture = (Texture)(object)texture
			};
		}
		GameObject val2 = new GameObject("Mjolnir_LandingDust");
		val2.transform.position = point + normal * 0.12f;
		val2.transform.rotation = Quaternion.FromToRotation(Vector3.forward, normal);
		ParticleSystem val3 = val2.AddComponent<ParticleSystem>();
		val3.Stop(true, (ParticleSystemStopBehavior)0);
		MainModule main = val3.main;
		((MainModule)(ref main)).loop = false;
		((MainModule)(ref main)).playOnAwake = false;
		((MainModule)(ref main)).duration = 0.15f;
		((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.35f, 0.85f);
		((MainModule)(ref main)).startSpeed = new MinMaxCurve(2f, 5f);
		((MainModule)(ref main)).startSize = new MinMaxCurve(0.35f, 0.8f);
		((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(0.42f, 0.35f, 0.24f, 0.45f));
		((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(0.65f);
		((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
		((MainModule)(ref main)).maxParticles = 64;
		ShapeModule shape = val3.shape;
		((ShapeModule)(ref shape)).enabled = true;
		((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)2;
		((ShapeModule)(ref shape)).radius = 0.7f;
		EmissionModule emission = val3.emission;
		((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(0f);
		((EmissionModule)(ref emission)).SetBursts((Burst[])(object)new Burst[1]
		{
			new Burst(0f, (short)40)
		});
		ColorOverLifetimeModule colorOverLifetime = val3.colorOverLifetime;
		((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
		Gradient val4 = new Gradient();
		val4.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
		{
			new GradientColorKey(Color.white, 0f),
			new GradientColorKey(Color.white, 1f)
		}, (GradientAlphaKey[])(object)new GradientAlphaKey[2]
		{
			new GradientAlphaKey(1f, 0f),
			new GradientAlphaKey(0f, 1f)
		});
		((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val4);
		((Renderer)val2.GetComponent<ParticleSystemRenderer>()).sharedMaterial = material;
		val3.Play();
		Object.Destroy((Object)(object)val2, 1.2f);
	}

	internal static void Release()
	{
		if (Object.op_Implicit((Object)(object)material))
		{
			Object.Destroy((Object)(object)material);
		}
		if (Object.op_Implicit((Object)(object)texture))
		{
			Object.Destroy((Object)(object)texture);
		}
		material = null;
		texture = null;
	}
}
[HarmonyPatch(typeof(Character), "Land")]
internal static class StormNativeLanding
{
	private static void Postfix(Character __instance)
	{
		MjolnirPlugin active = MjolnirPlugin.Active;
		if (Object.op_Implicit((Object)(object)active) && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
		{
			active.Storm?.NotifyLanding();
		}
	}
}
public sealed class LandingShockwave : MonoBehaviour
{
	private LineRenderer[] rings;

	private Vector3 point;

	private Vector3 normal;

	private Quaternion plane;

	private float age;

	private float radius;

	internal static void Spawn(Vector3 point, Vector3 normal, float radius)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		ImpactVfx.Spawn(point, normal, radius);
	}

	private void Update()
	{
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		if (rings == null)
		{
			return;
		}
		age += Time.deltaTime;
		float num = Mathf.Clamp01(age / 0.8f);
		for (int i = 0; i < rings.Length; i++)
		{
			LineRenderer val = rings[i];
			float num2 = radius * Mathf.Lerp(0.15f, 1f, num) * (1f - (float)i * 0.22f);
			val.startColor = new Color(0.3f, 0.85f, 1f, 1f - num);
			val.endColor = val.startColor;
			for (int j = 0; j < 48; j++)
			{
				float num3 = (float)j * MathF.PI * 2f / 48f;
				float num4 = 1f + 0.035f * Mathf.Sin((float)(j * 13) + Mathf.Floor(age * 20f));
				val.SetPosition(j, point + normal * 0.09f + plane * new Vector3(Mathf.Cos(num3) * num2 * num4, 0f, Mathf.Sin(num3) * num2 * num4));
			}
		}
	}
}
public static class LightningCastTiming
{
	public const float ReleaseDelay = 0.35f;

	public static float GestureWeight(float age)
	{
		if (float.IsNaN(age) || float.IsInfinity(age) || age < 0f || age >= 0.95f)
		{
			return 0f;
		}
		float num = ((age < 0.3f) ? Math.Max(0f, Math.Min(1f, age / 0.3f)) : ((age < 0.55f) ? 1f : Math.Max(0f, Math.Min(1f, (0.95f - age) / 0.4f))));
		return num * num * (3f - 2f * num);
	}
}
public sealed class LightningSkillClock
{
	private float readyAt;

	public float Duration { get; private set; }

	public float Remaining(float now)
	{
		if (!float.IsNaN(now) && !float.IsInfinity(now))
		{
			return Math.Max(0f, readyAt - now);
		}
		return Duration;
	}

	public bool Ready(float now)
	{
		if (!float.IsNaN(now) && !float.IsInfinity(now))
		{
			return Remaining(now) <= 0f;
		}
		return false;
	}

	public bool Begin(float now, float duration)
	{
		if (!Ready(now) || float.IsNaN(duration) || float.IsInfinity(duration) || duration <= 0f)
		{
			return false;
		}
		Duration = Math.Max(2f, Math.Min(30f, duration));
		readyAt = now + Duration;
		return true;
	}
}
public sealed class LivingLightning : MonoBehaviour
{
	private LineRenderer[] lines;

	private readonly List<Vector3[]> points = new List<Vector3[]>();

	private readonly Random random = new Random();

	private float born;

	private float next;

	private Light flash;

	private float brightness;

	private void Start()
	{
		born = Time.time;
		lines = ((Component)this).GetComponentsInChildren<LineRenderer>();
		LineRenderer[] array = lines;
		foreach (LineRenderer obj in array)
		{
			Vector3[] array2 = (Vector3[])(object)new Vector3[obj.positionCount];
			obj.GetPositions(array2);
			points.Add(array2);
		}
		flash = ((Component)this).GetComponent<Light>();
		if (Object.op_Implicit((Object)(object)flash))
		{
			brightness = flash.intensity;
		}
	}

	private float Noise()
	{
		return (float)random.NextDouble() * 2f - 1f;
	}

	private void Update()
	{
		//IL_00c0: 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_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Unknown result type (might be due to invalid IL or missing references)
		float num = Time.time - born;
		float num2 = Mathf.Clamp01(1f - num / 0.36f);
		if (Object.op_Implicit((Object)(object)flash))
		{
			flash.intensity = brightness * num2 * (0.5f + 0.5f * Mathf.Sin(num * 95f));
		}
		if (Time.time < next)
		{
			return;
		}
		next = Time.time + 0.035f;
		for (int i = 0; i < lines.Length; i++)
		{
			LineRenderer val = lines[i];
			if (Object.op_Implicit((Object)(object)val))
			{
				((Renderer)val).enabled = random.NextDouble() > 0.18;
				val.startColor = new Color(1.8f, 3f, 4f, num2);
				val.endColor = new Color(0.1f, 1f, 3f, num2 * 0.35f);
				for (int j = 0; j < points[i].Length; j++)
				{
					float num3 = (float)j / (float)(points[i].Length - 1);
					val.SetPosition(j, points[i][j] + new Vector3(Noise(), Noise(), Noise()) * (0.14f * Mathf.Sin(num3 * MathF.PI)));
				}
			}
		}
	}
}
internal static class MinimapHudAnchor
{
	private static readonly FieldInfo Map = AccessTools.Field(typeof(Minimap), "m_mapSmall");

	private static readonly FieldInfo Root = AccessTools.Field(typeof(Minimap), "m_smallRoot");

	private static readonly Vector3[] Corners = (Vector3[])(object)new Vector3[4];

	internal static float Bottom()
	{
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: 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)
		if (!Object.op_Implicit((Object)(object)Minimap.instance))
		{
			return 220f;
		}
		FieldInfo[] array = new FieldInfo[2] { Map, Root };
		for (int i = 0; i < array.Length; i++)
		{
			object? obj = array[i]?.GetValue(Minimap.instance);
			GameObject val = (GameObject)((obj is GameObject) ? obj : null);
			RectTransform val2 = (Object.op_Implicit((Object)(object)val) ? val.GetComponent<RectTransform>() : null);
			if (Object.op_Implicit((Object)(object)val2))
			{
				Canvas componentInParent = ((Component)val2).GetComponentInParent<Canvas>();
				Camera val3 = ((Object.op_Implicit((Object)(object)componentInParent) && (int)componentInParent.renderMode != 0) ? componentInParent.worldCamera : null);
				val2.GetWorldCorners(Corners);
				float num = Screen.height;
				float num2 = 0f;
				Vector3[] corners = Corners;
				foreach (Vector3 val4 in corners)
				{
					float y = RectTransformUtility.WorldToScreenPoint(val3, val4).y;
					num = Mathf.Min(num, y);
					num2 = Mathf.Max(num2, y);
				}
				float num3 = num2 - num;
				if (num3 >= 40f && num3 < (float)Screen.height * 0.65f)
				{
					return (float)Screen.height - num;
				}
			}
		}
		return 220f;
	}
}
internal static class NordicHud
{
	private static void Fill(Rect rect, Color color)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: 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)
		Color color2 = GUI.color;
		GUI.color = color;
		GUI.DrawTexture(rect, (Texture)(object)Texture2D.whiteTexture);
		GUI.color = color2;
	}

	internal static void Ability(Rect r, Sprite icon, Color tint, string title, string status, string info, float cooldown)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: 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_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: 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_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_023d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0245: Expected O, but got Unknown
		//IL_024b: Unknown result type (might be due to invalid IL or missing references)
		//IL_027d: Unknown result type (might be due to invalid IL or missing references)
		//IL_028f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0328: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		Fill(r, new Color(0.035f, 0.045f, 0.055f, 0.94f));
		Color val = default(Color);
		((Color)(ref val))..ctor(0.65f, 0.47f, 0.21f);
		Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).yMax - 2f, ((Rect)(ref r)).width, 2f), val);
		Rect val2 = default(Rect);
		((Rect)(ref val2))..ctor(((Rect)(ref r)).x + 8f, ((Rect)(ref r)).y + 3f, 38f, 38f);
		Fill(val2, new Color(0.08f, 0.13f, 0.18f));
		Color color = GUI.color;
		GUI.color = tint;
		if (Object.op_Implicit((Object)(object)icon))
		{
			Rect textureRect = icon.textureRect;
			((Rect)(ref textureRect)).x = ((Rect)(ref textureRect)).x / (float)((Texture)icon.texture).width;
			((Rect)(ref textureRect)).y = ((Rect)(ref textureRect)).y / (float)((Texture)icon.texture).height;
			((Rect)(ref textureRect)).width = ((Rect)(ref textureRect)).width / (float)((Texture)icon.texture).width;
			((Rect)(ref textureRect)).height = ((Rect)(ref textureRect)).height / (float)((Texture)icon.texture).height;
			GUI.DrawTextureWithTexCoords(val2, (Texture)(object)icon.texture, textureRect);
		}
		else
		{
			for (int i = 0; i < 5; i++)
			{
				Fill(new Rect(((Rect)(ref val2)).x + 21f - (float)(i * 3), ((Rect)(ref val2)).y + 3f + (float)(i * 3), 7f, 5f), tint);
			}
			for (int j = 0; j < 5; j++)
			{
				Fill(new Rect(((Rect)(ref val2)).x + 21f - (float)(j * 3), ((Rect)(ref val2)).y + 18f + (float)(j * 3), 7f, 5f), tint);
			}
		}
		GUI.color = color;
		if (cooldown > 0f)
		{
			Fill(new Rect(((Rect)(ref val2)).x, ((Rect)(ref val2)).y, ((Rect)(ref val2)).width, ((Rect)(ref val2)).height * cooldown), new Color(0f, 0f, 0f, 0.6f));
		}
		GUIStyle val3 = new GUIStyle(GUI.skin.label)
		{
			fontSize = 11,
			fontStyle = (FontStyle)1
		};
		val3.normal.textColor = val;
		GUI.Label(new Rect(((Rect)(ref r)).x + 53f, ((Rect)(ref r)).y + 1f, ((Rect)(ref r)).width - 56f, 16f), title, val3);
		val3.normal.textColor = tint;
		GUI.Label(new Rect(((Rect)(ref r)).x + 53f, ((Rect)(ref r)).y + 15f, ((Rect)(ref r)).width - 56f, 16f), status, val3);
		val3.fontSize = 10;
		val3.fontStyle = (FontStyle)0;
		val3.normal.textColor = new Color(0.8f, 0.85f, 0.9f);
		GUI.Label(new Rect(((Rect)(ref r)).x + 53f, ((Rect)(ref r)).y + 29f, ((Rect)(ref r)).width - 56f, 16f), info, val3);
	}

	internal static void Draw(Rect r, float fraction, string title, string detail, int segments = 5)
	{
		//IL_001b: 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_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Expected O, but got Unknown
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0242: Unknown result type (might be due to invalid IL or missing references)
		//IL_0256: Unknown result type (might be due to invalid IL or missing references)
		//IL_0290: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0325: 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_0354: Unknown result type (might be due to invalid IL or missing references)
		//IL_0359: Unknown result type (might be due to invalid IL or missing references)
		//IL_0383: Unknown result type (might be due to invalid IL or missing references)
		//IL_0388: Unknown result type (might be due to invalid IL or missing references)
		Color color = default(Color);
		((Color)(ref color))..ctor(0.65f, 0.47f, 0.21f, 1f);
		Fill(r, new Color(0.035f, 0.045f, 0.055f, 0.94f));
		Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, ((Rect)(ref r)).width, 2f), color);
		Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).yMax - 2f, ((Rect)(ref r)).width, 2f), color);
		float[] array = new float[2]
		{
			((Rect)(ref r)).x,
			((Rect)(ref r)).xMax - 3f
		};
		foreach (float num in array)
		{
			Fill(new Rect(num, ((Rect)(ref r)).y, 3f, 20f), color);
			Fill(new Rect(num, ((Rect)(ref r)).yMax - 20f, 3f, 20f), color);
		}
		GUIStyle val = new GUIStyle(GUI.skin.label)
		{
			alignment = (TextAnchor)4,
			fontSize = 13,
			fontStyle = (FontStyle)1
		};
		val.normal.textColor = new Color(0.91f, 0.78f, 0.48f);
		GUI.Label(new Rect(((Rect)(ref r)).x + 10f, ((Rect)(ref r)).y + 4f, ((Rect)(ref r)).width - 20f, 22f), title, val);
		float num2 = ((Rect)(ref r)).x + 24f;
		float num3 = ((Rect)(ref r)).y + 29f;
		float num4 = ((Rect)(ref r)).width - 48f;
		Fill(new Rect(num2 - 2f, num3 - 2f, num4 + 4f, 15f), color);
		Fill(new Rect(num2, num3, num4, 11f), new Color(0.06f, 0.1f, 0.13f));
		Fill(new Rect(num2, num3, num4 * Mathf.Clamp01(fraction), 11f), new Color(0.08f, 0.62f, 0.87f));
		for (int j = 1; j < segments; j++)
		{
			Fill(new Rect(num2 + num4 * (float)j / (float)segments, num3, 2f, 11f), new Color(0.03f, 0.07f, 0.09f));
		}
		val.fontSize = 11;
		val.fontStyle = (FontStyle)0;
		val.normal.textColor = new Color(0.8f, 0.9f, 0.94f);
		GUI.Label(new Rect(((Rect)(ref r)).x + 4f, ((Rect)(ref r)).y + 47f, ((Rect)(ref r)).width - 8f, 22f), detail, val);
		Fill(new Rect(((Rect)(ref r)).x - 5f, ((Rect)(ref r)).y + 8f, 13f, 3f), color);
		Fill(new Rect(((Rect)(ref r)).xMax - 8f, ((Rect)(ref r)).y + 8f, 13f, 3f), color);
		Fill(new Rect(((Rect)(ref r)).x + 8f, ((Rect)(ref r)).y + 11f, 3f, 8f), color);
		Fill(new Rect(((Rect)(ref r)).xMax - 11f, ((Rect)(ref r)).y + 11f, 3f, 8f), color);
	}
}
public static class SprintLeap
{
	public static (float X, float Z) Compute(float vx, float vz, float fx, float fz, bool shift, float requested)
	{
		float num = (float)Math.Sqrt(fx * fx + fz * fz);
		if (!shift || num < 0.001f || float.IsNaN(requested) || float.IsInfinity(requested))
		{
			return (X: vx, Z: vz);
		}
		fx /= num;
		fz /= num;
		float num2 = vx * fx + vz * fz;
		if (num2 < 2f)
		{
			return (X: vx, Z: vz);
		}
		float num3 = Math.Max(10f, Math.Min(18f, requested));
		float num4 = Math.Max(0f, num3 - num2);
		float num5 = vx + fx * num4;
		float num6 = vz + fz * num4;
		float num7 = (float)Math.Sqrt(num5 * num5 + num6 * num6);
		if (num7 > 18f)
		{
			num5 *= 18f / num7;
			num6 *= 18f / num7;
		}
		return (X: num5, Z: num6);
	}
}
public sealed class StormAbility
{
	private readonly MjolnirPlugin mod;

	internal readonly ChargeMeter Meter = new ChargeMeter();

	private Player owner;

	private bool holding;

	private bool airborne;

	private bool observedAir;

	private bool bypassJump;

	private float heldSince;

	private float flightSince;

	private float takeoffHeight;

	private ChargedAura aura;

	private const string SaveKey = "mjolnir.storm-charge.v1";

	internal bool AuraReady
	{
		get
		{
			if (Valid() && Meter.HasCharge)
			{
				return mod.LightningEnabled.Value;
			}
			return false;
		}
	}

	internal bool ProtectOwnJumpFall
	{
		get
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)owner))
			{
				return StormFallSafety.Protect(airborne, Time.time - flightSince, takeoffHeight, ((Component)owner).transform.position.y);
			}
			return false;
		}
	}

	internal bool Busy
	{
		get
		{
			if (!holding)
			{
				return airborne;
			}
			return true;
		}
	}

	internal bool BypassJump => bypassJump;

	internal StormAbility(MjolnirPlugin plugin)
	{
		mod = plugin;
	}

	private void BindPlayer()
	{
		if ((Object)(object)owner == (Object)(object)Player.m_localPlayer)
		{
			return;
		}
		RemoveOvercharge();
		Cancel();
		if (Object.op_Implicit((Object)(object)aura))
		{
			Object.Destroy((Object)(object)aura);
		}
		owner = Player.m_localPlayer;
		Meter.BeginSession();
		if (Object.op_Implicit((Object)(object)owner))
		{
			aura = ((Component)owner).gameObject.AddComponent<ChargedAura>();
		}
		Meter.SetGoal(mod.ChargeKills.Value);
		if (Object.op_Implicit((Object)(object)owner) && owner.m_customData.TryGetValue("mjolnir.storm-charge.v1", out var value))
		{
			int result2;
			if (value.StartsWith("pct:") && float.TryParse(value.Substring(4), NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
			{
				Meter.LoadPercent(result);
			}
			else if (int.TryParse(value, out result2))
			{
				Meter.Load(result2);
			}
		}
	}

	private void Save()
	{
		if (Object.op_Implicit((Object)(object)owner))
		{
			owner.m_customData["mjolnir.storm-charge.v1"] = "pct:" + Meter.Percent.ToString("R", CultureInfo.InvariantCulture);
		}
	}

	internal void DrainFlightCharge(float dt)
	{
		if (mod.InfiniteOvercharge.Value)
		{
			RefillTestCharge();
			return;
		}
		int num = Mathf.FloorToInt(Meter.Percent);
		if (Meter.Drain(dt, mod.Wings.DrainRate))
		{
			if (num != Mathf.FloorToInt(Meter.Percent) || !Meter.HasCharge)
			{
				Save();
			}
			SyncOvercharge();
		}
	}

	internal bool SpendSkillCharge(float cost)
	{
		BindPlayer();
		if (!Valid())
		{
			return false;
		}
		if (mod.InfiniteOvercharge.Value)
		{
			return true;
		}
		if (!Meter.SpendPercent(cost))
		{
			return false;
		}
		Save();
		SyncOvercharge();
		return true;
	}

	internal void RefillTestCharge()
	{
		BindPlayer();
		if (Object.op_Implicit((Object)(object)owner) && !((Character)owner).IsDead())
		{
			Meter.SetGoal(mod.ChargeKills.Value);
			if (!Meter.Ready)
			{
				Meter.Load(Meter.Goal);
				Save();
				SyncOvercharge();
			}
		}
	}

	internal void Persist()
	{
		Meter.SetGoal(mod.ChargeKills.Value);
		Save();
	}

	internal void AddKill(Character victim)
	{
	}

	private void RemoveOvercharge()
	{
		if (Object.op_Implicit((Object)(object)owner) && Object.op_Implicit((Object)(object)mod.Overcharge))
		{
			((Character)owner).GetSEMan().RemoveStatusEffect(mod.Overcharge.NameHash(), true);
		}
	}

	private void SyncOvercharge()
	{
		if (!Object.op_Implicit((Object)(object)owner) || !Object.op_Implicit((Object)(object)mod.Overcharge))
		{
			return;
		}
		bool flag = Valid() && (Meter.HasCharge || (mod.Wings.Active && Meter.HasCharge));
		SEMan sEMan = ((Character)owner).GetSEMan();
		int num = mod.Overcharge.NameHash();
		if (flag && !sEMan.HaveStatusEffect(num))
		{
			sEMan.AddStatusEffect(num, false, 0, 0f, (short)0);
		}
		else if (!flag && sEMan.HaveStatusEffect(num))
		{
			sEMan.RemoveStatusEffect(num, true);
		}
		if (!flag)
		{
			return;
		}
		foreach (StatusEffect statusEffect in sEMan.GetStatusEffects())
		{
			if (((Object)statusEffect).name == ((Object)mod.Overcharge).name)
			{
				statusEffect.m_tooltip = HelpText();
			}
		}
	}

	internal string HelpText()
	{
		return StormBalance.HelpText(this);
	}

	private bool Equipped()
	{
		if (Object.op_Implicit((Object)(object)owner))
		{
			return MjolnirPlugin.IsMjolnir(((Humanoid)owner).GetCurrentWeapon());
		}
		return false;
	}

	private bool Valid()
	{
		if (Equipped() && !((Character)owner).IsDead() && !((Character)owner).IsTeleporting() && !((Character)owner).InCutscene() && !((Character)owner).IsSwimming())
		{
			return !((Character)owner).IsAttached();
		}
		return false;
	}

	internal static bool InterfaceOpen()
	{
		if (!InventoryGui.IsVisible() && !Menu.IsVisible() && !Console.IsVisible() && !TextInput.IsVisible())
		{
			if (Object.op_Implicit((Object)(object)Chat.instance))
			{
				return Chat.instance.HasFocus();
			}
			return false;
		}
		return true;
	}

	internal bool InterceptJump(Character character)
	{
		return FlightOnly.InterceptJump(character);
	}

	internal void Update()
	{
		BindPlayer();
		if (!Object.op_Implicit((Object)(object)owner))
		{
			return;
		}
		Meter.SetGoal(mod.ChargeKills.Value);
		if (mod.InfiniteOvercharge.Value && !((Character)owner).IsDead())
		{
			RefillTestCharge();
		}
		SyncOvercharge();
		if (((Character)owner).IsDead())
		{
			Cancel();
			if (Meter.HasCharge)
			{
				Meter.Clear();
				Save();
			}
		}
		else
		{
			Cancel();
		}
	}

	internal void FlightLanding(bool destructive, float strength = 1f)
	{
		BindPlayer();
		if (Object.op_Implicit((Object)(object)owner) && !((Character)owner).IsDead())
		{
			Land(destructive, strength);
		}
	}

	internal void NotifyLanding()
	{
		if (airborne && Object.op_Implicit((Object)(object)owner) && !((Character)owner).IsDead() && !(Time.time - flightSince < 0.15f))
		{
			airborne = false;
			Land();
		}
	}

	private void Land(bool allowStructureDamage = true, float strength = 1f)
	{
		//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_0011: 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_0043: 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: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0317: Unknown result type (might be due to invalid IL or missing references)
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_0215: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_0228: Unknown result type (might be due to invalid IL or missing references)
		//IL_0232: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_024b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_0251: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: 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_025c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_026a: Unknown result type (might be due to invalid IL or missing references)
		//IL_026f: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0281: Unknown result type (might be due to invalid IL or missing references)
		//IL_0288: Unknown result type (might be due to invalid IL or missing references)
		//IL_0291: Expected O, but got Unknown
		Vector3 val = ((Component)owner).transform.position;
		Vector3 val2 = Vector3.up;
		int mask = LayerMask.GetMask(new string[4] { "terrain", "piece", "static_solid", "Default" });
		RaycastHit val3 = default(RaycastHit);
		if (Physics.Raycast(val + Vector3.up * 0.6f, Vector3.down, ref val3, 2.5f, mask, (QueryTriggerInteraction)1))
		{
			val = ((RaycastHit)(ref val3)).point;
			val2 = ((RaycastHit)(ref val3)).normal;
		}
		mod.ThunderImpact(val, strength);
		if (mod.ThunderImpactEnabled.Value)
		{
			LandingShockwave.Spawn(val, val2, Mathf.Clamp(mod.JumpRadius.Value, 2f, 7f));
			if (strength >= 0.6f)
			{
				ImpactVfx.SkipLegacyDust(val, val2);
			}
			if (Object.op_Implicit((Object)(object)GameCamera.instance) && mod.ImpactShake.Value > 0f)
			{
				GameCamera.instance.AddShake(val, 15f, Mathf.Clamp(mod.ImpactShake.Value, 0f, 0.3f) * strength, false);
			}
		}
		float num = Mathf.Clamp(mod.JumpRadius.Value, 2f, 7f);
		float num2 = Mathf.Clamp(mod.JumpDamage.Value, 20f, 180f);
		int mask2 = LayerMask.GetMask(new string[4] { "terrain", "piece", "static_solid", "Default" });
		foreach (Character item in new List<Character>(Character.GetAllCharacters()))
		{
			if (Object.op_Implicit((Object)(object)item) && !((Object)(object)item == (Object)(object)owner) && !item.IsDead() && !item.IsPlayer() && !item.IsTamed() && BaseAI.IsEnemy((Character)(object)owner, item))
			{
				Vector3 centerPoint = item.GetCenterPoint();
				float num3 = Vector3.Distance(val, centerPoint);
				if (!(num3 > num) && !Physics.Linecast(val + Vector3.up * 0.45f, centerPoint, mask2, (QueryTriggerInteraction)1))
				{
					HitData val4 = new HitData
					{
						m_point = centerPoint
					};
					Vector3 val5 = centerPoint - val;
					val4.m_dir = ((Vector3)(ref val5)).normalized;
					val4.m_pushForce = 35f;
					val4.m_dodgeable = true;
					val4.m_blockable = false;
					val4.m_ranged = true;
					HitData val6 = val4;
					float num4 = Mathf.Lerp(1f, 0.5f, num3 / num);
					val6.m_damage.m_lightning = num2 * num4;
					val6.m_damage.m_blunt = num2 * 0.25f * num4;
					val6.SetAttacker((Character)(object)owner);
					item.Damage(val6);
				}
			}
		}
		if (allowStructureDamage && mod.LandingDamagesStructures.Value)
		{
			DamageStructures(val, num);
		}
		StormBalance.Landing(this);
	}

	private void DamageStructures(Vector3 origin, float radius)
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//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_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Expected O, but got Unknown
		HashSet<IDestructible> hashSet = new HashSet<IDestructible>();
		int mask = LayerMask.GetMask(new string[5] { "piece", "Default", "Default_small", "static_solid", "vehicle" });
		Collider[] array = Physics.OverlapSphere(origin, radius, mask, (QueryTriggerInteraction)1);
		foreach (Collider val in array)
		{
			if (!Object.op_Implicit((Object)(object)val) || Object.op_Implicit((Object)(object)((Component)val).GetComponentInParent<Character>()) || mod.ProtectedBuilding(val) || !Object.op_Implicit((Object)(object)((Component)val).GetComponentInParent<Piece>()))
			{
				continue;
			}
			IDestructible componentInParent = ((Component)val).GetComponentInParent<IDestructible>();
			if (componentInParent != null && !hashSet.Contains(componentInParent))
			{
				Vector3 val2 = val.ClosestPoint(origin + Vector3.up * 0.2f);
				float num = Vector3.Distance(origin, val2);
				if (!(num > radius))
				{
					hashSet.Add(componentInParent);
					HitData val3 = new HitData
					{
						m_point = val2
					};
					Vector3 val4 = val2 - origin;
					val3.m_dir = ((Vector3)(ref val4)).normalized;
					val3.m_pushForce = 50f;
					val3.m_ranged = true;
					val3.m_hitCollider = val;
					HitData val5 = val3;
					val5.m_damage.m_blunt = Mathf.Clamp(mod.LandingStructureDamage.Value, 0f, 200f) * Mathf.Lerp(1f, 0.5f, num / radius);
					val5.SetAttacker((Character)(object)owner);
					componentInParent.Damage(val5);
				}
			}
		}
	}

	internal void Cancel()
	{
		holding = false;
		airborne = false;
		observedAir = false;
	}

	internal void Dispose()
	{
		Cancel();
		RemoveOvercharge();
		if (Object.op_Implicit((Object)(object)aura))
		{
			Object.Destroy((Object)(object)aura);
		}
		aura = null;
	}

	internal void DrawHud()
	{
		StormBalance.DrawHud(this);
	}
}
public static class StormFallSafety
{
	public static bool Protect(bool specialActive, float elapsed, float takeoffY, float landingY)
	{
		if (specialActive && !float.IsNaN(elapsed) && !float.IsNaN(takeoffY) && !float.IsNaN(landingY) && !float.IsInfinity(elapsed) && !float.IsInfinity(takeoffY) && !float.IsInfinity(landingY) && elapsed >= 0f && elapsed < 6f)
		{
			return landingY >= takeoffY - 1.5f;
		}
		return false;
	}
}
public sealed class StormFlight
{
	private readonly MjolnirPlugin mod;

	private readonly FlightTap taps = new FlightTap();

	private readonly Dictionary<int, float> hitTimes = new Dictionary<int, float>();

	private Player owner;

	private Rigidbody body;

	private ThorFlightPose pose;

	private bool gravity;

	private CollisionDetectionMode collisionMode;

	private float started;

	private float terrainTime;

	private float nextImpact;

	internal float DrainRate
	{
		get
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			float value = mod.FlightDrainPercent.Value;
			float value2 = mod.SprintDrainMultiplier.Value;
			int sprint;
			if (Active)
			{
				Vector3 velocity = Velocity;
				if (((Vector3)(ref velocity)).sqrMagnitude > 1f)
				{
					sprint = ((Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303)) ? 1 : 0);
					goto IL_0059;
				}
			}
			sprint = 0;
			goto IL_0059;
			IL_0059:
			return FlightPolishRules.DrainRate(value, value2, (byte)sprint != 0);
		}
	}

	internal Vector3 Velocity
	{
		get
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)body))
			{
				return Vector3.zero;
			}
			return body.linearVelocity;
		}
	}

	internal bool EmergencyLanding { get; private set; }

	internal bool Active { get; private set; }

	internal StormFlight(MjolnirPlugin plugin)
	{
		mod = plugin;
	}

	private bool Valid(Player p)
	{
		if (Object.op_Implicit((Object)(object)p) && !((Character)p).IsDead() && !((Character)p).IsTeleporting() && !((Character)p).InCutscene() && !((Character)p).IsAttached() && !((Character)p).IsSwimming())
		{
			return MjolnirPlugin.IsMjolnir(((Humanoid)p).GetCurrentWeapon());
		}
		return false;
	}

	internal void Update()
	{
		if (Active && (!mod.FlightEnabled.Value || (Object)(object)owner != (Object)(object)Player.m_localPlayer || !Valid(owner) || owner.InDebugFlyMode()))
		{
			Stop();
		}
		if (mod.InfiniteOvercharge.Value)
		{
			mod.Storm.RefillTestCharge();
			EmergencyLanding = false;
		}
		if (Active && !mod.InfiniteOvercharge.Value && !mod.MenuPanel.Open && !StormAbility.InterfaceOpen() && !EmergencyLanding)
		{
			mod.Storm.DrainFlightCharge(Time.deltaTime);
			if (!mod.Storm.Meter.HasCharge)
			{
				EmergencyLanding = true;
			}
		}
		Player localPlayer = Player.m_localPlayer;
		if (!mod.FlightEnabled.Value || !Valid(localPlayer) || mod.MenuPanel.Open || StormAbility.InterfaceOpen())
		{
			taps.Reset();
		}
		else
		{
			if (!Input.GetKeyDown((KeyCode)32) || !taps.Tap(Time.time))
			{
				return;
			}
			if (Active)
			{
				if (!EmergencyLanding)
				{
					Stop();
				}
			}
			else if (!Object.op_Implicit((Object)(object)mod.Flight) && !mod.Request.Pending && !((Character)localPlayer).InAttack() && !mod.Storm.Busy)
			{
				Start(localPlayer);
			}
		}
	}

	private void Start(Player p)
	{
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		if (p.InDebugFlyMode() || !mod.Storm.Meter.HasCharge)
		{
			return;
		}
		body = ((Component)p).GetComponent<Rigidbody>();
		if (Object.op_Implicit((Object)(object)body))
		{
			owner = p;
			gravity = body.useGravity;
			collisionMode = body.collisionDetectionMode;
			mod.Storm.Cancel();
			pose = ((Component)p).GetComponent<ThorFlightPose>();
			if (!Object.op_Implicit((Object)(object)pose))
			{
				pose = ((Component)p).gameObject.AddComponent<ThorFlightPose>();
			}
			Active = true;
			EmergencyLanding = false;
			started = Time.time;
			hitTimes.Clear();
			taps.Reset();
			body.collisionDetectionMode = (CollisionDetectionMode)2;
			body.useGravity = false;
			body.linearVelocity = Vector3.up * 2f;
		}
	}

	internal void Stop()
	{
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		if (Active)
		{
			Active = false;
			EmergencyLanding = false;
			taps.Reset();
			mod.Storm.Persist();
			if (Object.op_Implicit((Object)(object)pose))
			{
				pose.EndFlight();
			}
			if (Object.op_Implicit((Object)(object)body))
			{
				body.useGravity = gravity;
				body.collisionDetectionMode = collisionMode;
			}
			owner = null;
			body = null;
			hitTimes.Clear();
		}
	}

	internal Vector3 FixedTick(float dt, Rigidbody physicsBody)
	{
		//IL_0003: 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_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			return Move(dt, physicsBody);
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[Mjolnir] Voo interrompido: " + ex));
			Stop();
			return Vector3.zero;
		}
	}

	private Vector3 Move(float dt, Rigidbody physicsBody)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: 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_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: 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_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: 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_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0238: Unknown result type (might be due to invalid IL or missing references)
		//IL_023d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to in

BepInEx/plugins/Yoroshiro_Mjolnir/Mjolnir.PoseFix.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Jotunn.Configs;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Yoroshiro")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.18.1.0")]
[assembly: AssemblyInformationalVersion("1.18.1")]
[assembly: AssemblyProduct("Mjolnir.PoseFix")]
[assembly: AssemblyTitle("Mjolnir.PoseFix")]
[assembly: AssemblyVersion("1.18.1.0")]
namespace MyValheimMod;

public static class TorsoStability
{
	private sealed class Rig
	{
		internal Transform Hips;

		internal Transform Neck;

		internal Transform Left;

		internal Transform Right;

		internal float FlightBlend;

		internal Rig(Transform root)
		{
			Animator componentInChildren = ((Component)root).GetComponentInChildren<Animator>();
			if (!Object.op_Implicit((Object)(object)componentInChildren))
			{
				return;
			}
			Transform[] componentsInChildren = ((Component)componentInChildren).GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				string text = ((Object)val).name.ToLowerInvariant().Replace("_", "").Replace(":", "")
					.Replace(" ", "");
				if (text.EndsWith("hips") || text.EndsWith("pelvis"))
				{
					Hips = val;
				}
				if (text.EndsWith("neck"))
				{
					Neck = val;
				}
				if (text.EndsWith("leftarm") || text.EndsWith("leftupperarm"))
				{
					Left = val;
				}
				if (text.EndsWith("rightarm") || text.EndsWith("rightupperarm"))
				{
					Right = val;
				}
			}
			if (componentInChildren.isHuman)
			{
				Hips = componentInChildren.GetBoneTransform((HumanBodyBones)0) ?? Hips;
				Neck = componentInChildren.GetBoneTransform((HumanBodyBones)9) ?? Neck;
				Left = componentInChildren.GetBoneTransform((HumanBodyBones)13) ?? Left;
				Right = componentInChildren.GetBoneTransform((HumanBodyBones)14) ?? Right;
			}
		}
	}

	private static readonly ConditionalWeakTable<Transform, Rig> Rigs = new ConditionalWeakTable<Transform, Rig>();

	public static void Align(Transform player)
	{
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//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_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)player))
		{
			return;
		}
		Rig value = Rigs.GetValue(player, (Transform p) => new Rig(p));
		if (!Object.op_Implicit((Object)(object)value.Hips) || !Object.op_Implicit((Object)(object)value.Neck) || !value.Neck.IsChildOf(value.Hips))
		{
			return;
		}
		Vector3 val = value.Neck.position - value.Hips.position;
		if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
		{
			return;
		}
		value.Hips.rotation = Quaternion.FromToRotation(((Vector3)(ref val)).normalized, Vector3.up) * value.Hips.rotation;
		if (Object.op_Implicit((Object)(object)value.Left) && Object.op_Implicit((Object)(object)value.Right))
		{
			Vector3 val2 = Vector3.ProjectOnPlane(value.Right.position - value.Left.position, Vector3.up);
			Vector3 val3 = Vector3.ProjectOnPlane(player.right, Vector3.up);
			if (!(((Vector3)(ref val2)).sqrMagnitude < 0.01f) && !(((Vector3)(ref val3)).sqrMagnitude < 0.01f))
			{
				float num = Vector3.SignedAngle(val2, val3, Vector3.up);
				value.Hips.rotation = Quaternion.AngleAxis(num, Vector3.up) * value.Hips.rotation;
			}
		}
	}

	public static void Superman(Transform player, float flightWeight, float lightningSince)
	{
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: 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_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)player))
		{
			return;
		}
		Rig value = Rigs.GetValue(player, (Transform p) => new Rig(p));
		if (Object.op_Implicit((Object)(object)value.Hips) && Object.op_Implicit((Object)(object)value.Neck))
		{
			Rigidbody component = ((Component)player).GetComponent<Rigidbody>();
			float num = SupermanPoseRules.Target(Object.op_Implicit((Object)(object)component) ? Vector3.Dot(component.linearVelocity, player.forward) : 0f, ascending: Input.GetKey((KeyCode)32), casting: Time.time - lightningSince >= 0f && Time.time - lightningSince < 0.95f, forward: Input.GetKey((KeyCode)119));
			value.FlightBlend = Mathf.Lerp(value.FlightBlend, num, 1f - Mathf.Exp(-5f * Time.deltaTime));
			float num2 = 78f * value.FlightBlend * Mathf.Clamp01(flightWeight);
			if (!(num2 < 0.01f))
			{
				value.Hips.rotation = Quaternion.AngleAxis(num2, player.right) * value.Hips.rotation;
				value.Neck.rotation = Quaternion.AngleAxis((0f - num2) * 0.7f, player.right) * value.Neck.rotation;
			}
		}
	}
}
public static class SupermanPoseRules
{
	public static float Target(float forwardSpeed, bool forward, bool ascending, bool casting)
	{
		if (!forward || ascending || casting || float.IsNaN(forwardSpeed) || float.IsInfinity(forwardSpeed))
		{
			return 0f;
		}
		return Math.Max(0f, Math.Min(1f, (forwardSpeed - 1f) / 11f));
	}
}
public static class StormBalance
{
	private static MjolnirPlugin configured;

	private static Player player;

	private static ConfigEntry<float> regen;

	private static ConfigEntry<float> delay;

	private static ConfigEntry<float> auraRadius;

	private static ConfigEntry<float> auraDamage;

	private static ConfigEntry<float> auraCost;

	private static ConfigEntry<bool> damageAura;

	private static ConfigEntry<bool> quake;

	private static float lastEnergy;

	private static float lastSpend;

	private static float nextAura;

	private static ConfigEntry<float> Entry(MjolnirPlugin m, string name, float value, string description)
	{
		return ((BaseUnityPlugin)m).Config.Bind<float>("StormBalance", name, value, description);
	}

	private static void Init(MjolnirPlugin mod)
	{
		if (!((Object)(object)configured == (Object)(object)mod))
		{
			configured = mod;
			regen = Entry(mod, "RegenerationPercentPerSecond", 4f, "Regeneracao automatica em porcentagem por segundo.");
			delay = Entry(mod, "RegenerationDelay", 3f, "Espera apos gastar energia antes de regenerar.");
			auraRadius = Entry(mod, "DamageAuraRadius", 3f, "Raio da aura de dano em metros.");
			auraDamage = Entry(mod, "DamageAuraDamage", 12f, "Dano eletrico por pulso de um segundo, antes das resistencias.");
			auraCost = Entry(mod, "DamageAuraCostPercent", 2f, "Custo percentual por pulso com inimigos proximos.");
			damageAura = ((BaseUnityPlugin)mod).Config.Bind<bool>("StormBalance", "DamageAura", true, "Aura de dano contra inimigos; nao atinge construcoes ou jogadores.");
			quake = ((BaseUnityPlugin)mod).Config.Bind<bool>("StormBalance", "LandingQuake", true, "Mini terremoto de 3 pulsos na aterrissagem, sem deformar solo.");
			ConfigEntry<int> val = ((BaseUnityPlugin)mod).Config.Bind<int>("StormBalance", "BalanceRevision", 0, "Migracao dos valores padrao da versao 1.16.");
			if (val.Value < 1)
			{
				mod.FlightDrainPercent.Value = 5f;
				mod.SprintDrainMultiplier.Value = 1.5f;
				mod.StrikeCost.Value = 40f;
				val.Value = 1;
				((BaseUnityPlugin)mod).Config.Save();
			}
			mod.FlightTerrain.Value = false;
		}
	}

	public static void TuneRecipe(ItemConfig recipe)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Expected O, but got Unknown
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Expected O, but got Unknown
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Expected O, but got Unknown
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Expected O, but got Unknown
		recipe.CraftingStation = "blackforge";
		recipe.RepairStation = "blackforge";
		recipe.MinStationLevel = 2;
		recipe.Requirements = (RequirementConfig[])(object)new RequirementConfig[5]
		{
			new RequirementConfig("BlackMetal", 40, 8, true),
			new RequirementConfig("Silver", 20, 6, true),
			new RequirementConfig("FlametalNew", 10, 4, true),
			new RequirementConfig("Eitr", 10, 4, true),
			new RequirementConfig("Thunderstone", 3, 1, true)
		};
	}

	public static void Update(MjolnirPlugin mod)
	{
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		Init(mod);
		mod.FlightTerrain.Value = false;
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer != (Object)(object)player)
		{
			player = localPlayer;
			lastEnergy = mod.Storm.Meter.Percent;
			lastSpend = Time.time;
			nextAura = Time.time;
		}
		if (!Object.op_Implicit((Object)(object)player) || ((Character)player).IsDead() || ((Character)player).IsTeleporting())
		{
			return;
		}
		ChargeMeter meter = mod.Storm.Meter;
		float percent = meter.Percent;
		if (percent < lastEnergy - 0.0001f)
		{
			lastSpend = Time.time;
		}
		bool flag = MjolnirPlugin.IsMjolnir(((Humanoid)player).GetCurrentWeapon()) && !((Character)player).IsSwimming() && !((Character)player).IsAttached();
		if (damageAura.Value && flag && meter.HasCharge && Time.time >= nextAura && !mod.MenuPanel.Open && !StormAbility.InterfaceOpen())
		{
			nextAura = Time.time + 1f;
			List<Character> list = Targets(player, ((Character)player).GetCenterPoint(), Mathf.Clamp(auraRadius.Value, 1f, 5f));
			if (list.Count > 0)
			{
				float num = Mathf.Min(meter.Percent, Mathf.Clamp(auraCost.Value, 0.5f, 8f));
				if (mod.InfiniteOvercharge.Value || meter.SpendPercent(num))
				{
					if (!mod.InfiniteOvercharge.Value)
					{
						lastSpend = Time.time;
					}
					Damage(player, list, Mathf.Clamp(auraDamage.Value, 1f, 30f) * (mod.InfiniteOvercharge.Value ? 1f : (num / Mathf.Clamp(auraCost.Value, 0.5f, 8f))), blunt: false);
				}
			}
		}
		bool busy = mod.Wings.Active || mod.Strike.Busy || mod.Storm.Busy;
		if (!mod.InfiniteOvercharge.Value)
		{
			meter.LoadPercent(RegenerationRules.Step(meter.Percent, Time.deltaTime, Time.time, lastSpend, regen.Value, Mathf.Clamp(delay.Value, 0f, 10f), busy));
		}
		if (Mathf.FloorToInt(percent) != Mathf.FloorToInt(meter.Percent) || (percent > 0f && !meter.HasCharge))
		{
			mod.Storm.Persist();
		}
		lastEnergy = meter.Percent;
	}

	internal static List<Character> Targets(Player owner, Vector3 origin, float radius)
	{
		//IL_007f: 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_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		List<Character> list = new List<Character>();
		int mask = LayerMask.GetMask(new string[4] { "terrain", "piece", "static_solid", "Default" });
		foreach (Character item in new List<Character>(Character.GetAllCharacters()))
		{
			if (Object.op_Implicit((Object)(object)item) && !((Object)(object)item == (Object)(object)owner) && !item.IsDead() && !item.IsPlayer() && !item.IsTamed() && BaseAI.IsEnemy((Character)(object)owner, item))
			{
				Vector3 centerPoint = item.GetCenterPoint();
				if (!(Vector3.Distance(centerPoint, origin) > radius) && !Physics.Linecast(origin, centerPoint, mask, (QueryTriggerInteraction)1))
				{
					list.Add(item);
				}
			}
		}
		return list;
	}

	internal static void Damage(Player owner, List<Character> targets, float amount, bool blunt)
	{
		//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_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		//IL_0040: 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_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Expected O, but got Unknown
		foreach (Character target in targets)
		{
			if (Object.op_Implicit((Object)(object)target) && !target.IsDead())
			{
				HitData val = new HitData
				{
					m_point = target.GetCenterPoint(),
					m_dir = Vector3.down,
					m_ranged = true,
					m_blockable = false,
					m_dodgeable = true,
					m_pushForce = 0f
				};
				if (blunt)
				{
					val.m_damage.m_blunt = amount;
				}
				else
				{
					val.m_damage.m_lightning = amount;
				}
				val.SetAttacker((Character)(object)owner);
				target.Damage(val);
			}
		}
	}

	public static void Landing(StormAbility ability)
	{
		//IL_003d: 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_004e: Unknown result type (might be due to invalid IL or missing references)
		MjolnirPlugin active = MjolnirPlugin.Active;
		if (Object.op_Implicit((Object)(object)active))
		{
			Init(active);
			Player localPlayer = Player.m_localPlayer;
			if (quake.Value && Object.op_Implicit((Object)(object)localPlayer) && !((Character)localPlayer).IsDead())
			{
				GameObject val = new GameObject("Mjolnir_MiniEarthquake");
				val.transform.position = ((Component)localPlayer).transform.position;
				val.AddComponent<MiniEarthquake>().Begin(active, localPlayer);
			}
		}
	}

	public static bool TerrainToggle(bool value, string text, GUILayoutOption[] options)
	{
		GUILayout.Label("Terreno protegido: sem deformacao", options);
		return false;
	}

	public static string HelpText(StormAbility ability)
	{
		MjolnirPlugin active = MjolnirPlugin.Active;
		Init(active);
		return "<b>SOBRECARGA</b>\nRegenera " + regen.Value.ToString("0.#") + "%/s apos " + delay.Value.ToString("0.#") + " s sem gastar. Nao exige abates. Regenera tambem desequipado, enquanto vivo.\nVoo: -" + active.FlightDrainPercent.Value.ToString("0.#") + "%/s; com Shift: -" + (active.FlightDrainPercent.Value * active.SprintDrainMultiplier.Value).ToString("0.#") + "%/s (limite 10%/s). Nao regenera voando.\nAura de dano: " + auraDamage.Value.ToString("0") + " eletrico por segundo em " + auraRadius.Value.ToString("0.#") + " m, custa " + auraCost.Value.ToString("0.#") + "% por pulso com inimigos. Jogadores e construcoes protegidos.\nAura visual permanece enquanto houver energia; apaga ao zerar. Abates nao recarregam.\n\n<b>FORJA NEGRA</b>\nMelhore a arma ate qualidade 4 na aba Melhorar. Cada qualidade aumenta dano e durabilidade. Consulte os custos no guia F9.\n\n<b>COMANDOS</b>\nG: arremesso | Shift+G: relampago, " + active.Strike.Cost.ToString("0") + "%, recarga " + active.Strike.Cooldown.ToString("0.#") + " s.\n2 toques em Espaco: entrar/sair do voo. W/A/S/D: mover. Espaco: subir. Ctrl: descer. Shift: acelerar.\nUm toque em Espaco: salto normal. Dois toques: voo. Nao ha salto carregado ou impulso frontal.\nAterrissagem: impacto e mini terremoto, sem escavar terreno.\nF9: ajustes | F10: mostrar/ocultar HUD. Energia infinita nao remove recargas.";
	}

	public static void DrawHud(StormAbility ability)
	{
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: 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)
		MjolnirPlugin active = MjolnirPlugin.Active;
		if (Object.op_Implicit((Object)(object)active) && active.NordicHud.Value)
		{
			Init(active);
			Player localPlayer = Player.m_localPlayer;
			if (Object.op_Implicit((Object)(object)localPlayer) && !((Character)localPlayer).IsDead() && MjolnirPlugin.IsMjolnir(((Humanoid)localPlayer).GetCurrentWeapon()))
			{
				float num = Mathf.Clamp(active.HudScale.Value, 0.65f, 1.25f);
				(float, float) tuple = HudPlacement.Compute((float)Screen.width, (float)Screen.height, MinimapHudAnchor.Bottom(), 300f * num, 126f * num, active.HudVerticalOffset.Value);
				Matrix4x4 matrix = GUI.matrix;
				GUI.matrix = Matrix4x4.TRS(new Vector3(tuple.Item1, tuple.Item2, 0f), Quaternion.identity, new Vector3(num, num, 1f));
				string text = "CARGA " + ability.Meter.Percent.ToString("0.0", CultureInfo.InvariantCulture) + "% | ";
				text = (active.InfiniteOvercharge.Value ? (text + "INFINITA") : (active.Wings.Active ? (text + "-" + active.Wings.DrainRate.ToString("0.##") + "%/s") : ((!(Time.time - lastSpend < delay.Value)) ? (text + "REGEN +" + regen.Value.ToString("0.#") + "%/s") : (text + "REGEN EM " + Mathf.Max(0f, delay.Value - (Time.time - lastSpend)).ToString("0.0") + "s"))));
				NordicHud.Draw(new Rect(0f, 0f, 300f, 76f), ability.Meter.Fraction, ForgeProgression.HudTitle(), text, 10);
				active.Strike.DrawHud(new Rect(0f, 78f, 300f, 46f));
				GUI.matrix = matrix;
			}
		}
	}

	private static void Slider(string label, ConfigEntry<float> field, float min, float max)
	{
		GUILayout.Label(label + ": " + field.Value.ToString("0.0"), Array.Empty<GUILayoutOption>());
		field.Value = GUILayout.HorizontalSlider(Mathf.Clamp(field.Value, min, max), min, max, Array.Empty<GUILayoutOption>());
	}

	public static void DrawSettings()
	{
		Init(MjolnirPlugin.Active);
		ForgeProgression.DrawGuide();
		RunesPulse.DrawSettings();
		GUILayout.Space(12f);
		GUILayout.Label("REGENERACAO E AURA", Array.Empty<GUILayoutOption>());
		Slider("Regeneracao (%/s)", regen, 0.5f, 10f);
		Slider("Espera apos gasto (s)", delay, 0f, 10f);
		damageAura.Value = GUILayout.Toggle(damageAura.Value, "Aura de dano contra inimigos proximos", Array.Empty<GUILayoutOption>());
		Slider("Raio da aura (m)", auraRadius, 1f, 5f);
		Slider("Dano por segundo", auraDamage, 1f, 30f);
		Slider("Gasto por pulso (%)", auraCost, 0.5f, 8f);
		quake.Value = GUILayout.Toggle(quake.Value, "Mini terremoto ao aterrissar (sem deformar solo)", Array.Empty<GUILayoutOption>());
		GUILayout.Label("3 pulsos de 8 de dano contundente. Tremor visual usa o ajuste de vibracao da camera.", Array.Empty<GUILayoutOption>());
	}

	public static void RestoreDefaults()
	{
		MjolnirPlugin active = MjolnirPlugin.Active;
		Init(active);
		active.FlightEnabled.Value = true;
		active.FlightDestruction.Value = true;
		active.FlightTerrain.Value = false;
		active.InfiniteOvercharge.Value = false;
		active.FlightDrainPercent.Value = 5f;
		active.SprintDrainMultiplier.Value = 1.5f;
		active.FlightSpeed.Value = 12f;
		active.FlightFastSpeed.Value = 32f;
		active.FlightSmashDamage.Value = 1500f;
		active.StrikeCost.Value = 40f;
		active.StrikeCooldown.Value = 8f;
		active.StrikeDamage.Value = 90f;
		active.StrikeRange.Value = 40f;
		active.StrikeRadius.Value = 2.5f;
		active.ThrowDamageMultiplier.Value = 1.4f;
		active.ThrowRange.Value = 22f;
		active.ThrowStamina.Value = 15f;
		active.ThrowSpeed.Value = 24f;
		active.ReturnSpeed.Value = 32f;
		active.JumpDamage.Value = 120f;
		active.JumpRadius.Value = 5.5f;
		active.JumpVelocity.Value = 14f;
		active.SprintLeapSpeed.Value = 0f;
		active.LandingStructureDamage.Value = 100f;
		active.LandingDamagesStructures.Value = true;
		active.ProtectPlayerBuildings.Value = true;
		active.MovementBonus.Value = 5f;
		active.AttackBonus.Value = 8f;
		active.BuffEnabled.Value = true;
		active.ImpactBolts.Value = 5;
		active.ThunderVolume.Value = 0.65f;
		active.HudScale.Value = 0.85f;
		active.HudVerticalOffset.Value = 0f;
		active.NordicHud.Value = true;
		active.LightningEnabled.Value = true;
		active.ThunderImpactEnabled.Value = true;
		active.ImpactShake.Value = 0.15f;
		regen.Value = 4f;
		delay.Value = 3f;
		damageAura.Value = true;
		auraRadius.Value = 3f;
		auraDamage.Value = 12f;
		auraCost.Value = 2f;
		quake.Value = true;
	}
}
public sealed class MiniEarthquake : MonoBehaviour
{
	private MjolnirPlugin mod;

	private Player owner;

	private float next;

	private int pulses;

	internal void Begin(MjolnirPlugin plugin, Player player)
	{
		mod = plugin;
		owner = player;
		next = Time.time;
		Object.Destroy((Object)(object)((Component)this).gameObject, 1.5f);
	}

	private void Update()
	{
		//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_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)mod) || !Object.op_Implicit((Object)(object)owner) || ((Character)owner).IsDead())
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
		else
		{
			if (Time.time < next || pulses >= 3)
			{
				return;
			}
			next = Time.time + 0.4f;
			pulses++;
			Vector3 position = ((Component)this).transform.position;
			StormBalance.Damage(owner, StormBalance.Targets(owner, position + Vector3.up * 0.4f, Mathf.Clamp(mod.JumpRadius.Value, 2f, 7f)), 8f, blunt: true);
			if (mod.ThunderImpactEnabled.Value)
			{
				LandingShockwave.Spawn(position, Vector3.up, Mathf.Clamp(mod.JumpRadius.Value, 2f, 7f));
				if (Object.op_Implicit((Object)(object)GameCamera.instance) && mod.ImpactShake.Value > 0f)
				{
					GameCamera.instance.AddShake(position, 12f, Mathf.Clamp(mod.ImpactShake.Value, 0f, 0.3f) * 0.6f, false);
				}
			}
		}
	}
}
public static class RegenerationRules
{
	public static float Step(float percent, float dt, float now, float lastSpend, float rate, float delay, bool busy)
	{
		if (float.IsNaN(percent) || float.IsInfinity(percent))
		{
			percent = 0f;
		}
		percent = Math.Max(0f, Math.Min(100f, percent));
		if (busy || float.IsNaN(dt) || float.IsInfinity(dt) || dt <= 0f || now - lastSpend < delay)
		{
			return percent;
		}
		if (float.IsNaN(rate) || float.IsInfinity(rate))
		{
			rate = 4f;
		}
		return Math.Min(100f, percent + Math.Min(dt, 0.25f) * Math.Max(0.5f, Math.Min(10f, rate)));
	}
}
public static class FlightOnly
{
	public static bool InterceptJump(Character character)
	{
		MjolnirPlugin active = MjolnirPlugin.Active;
		if (Object.op_Implicit((Object)(object)active) && active.Wings != null && active.Wings.Active)
		{
			return (Object)(object)character == (Object)(object)Player.m_localPlayer;
		}
		return false;
	}
}
public sealed class ImpactVfx : MonoBehaviour
{
	private static float lastTime = -10f;

	private static Vector3 lastPoint;

	private readonly List<LineRenderer> arcs = new List<LineRenderer>();

	private readonly Random random = new Random();

	private Light flash;

	private float born;

	private float next;

	public static void SkipLegacyDust(Vector3 point, Vector3 normal)
	{
	}

	public static void Spawn(Vector3 point, Vector3 normal, float radius)
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		if (Time.time - lastTime < 0.12f)
		{
			Vector3 val = point - lastPoint;
			if (((Vector3)(ref val)).sqrMagnitude < 1f)
			{
				return;
			}
		}
		lastTime = Time.time;
		lastPoint = point;
		GameObject val2 = new GameObject("Mjolnir_GroundedThunderImpact");
		val2.transform.position = point;
		val2.AddComponent<ImpactVfx>().Build(normal, Mathf.Clamp(radius, 2f, 7f));
		Object.Destroy((Object)val2, 0.9f);
	}

	private float Noise()
	{
		return (float)random.NextDouble() * 2f - 1f;
	}

	private Vector3 Ground(Vector3 point, Vector3 normal)
	{
		//IL_002c: 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_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		int mask = LayerMask.GetMask(new string[4] { "terrain", "piece", "static_solid", "Default" });
		RaycastHit val = default(RaycastHit);
		if (Physics.Raycast(point + normal * 1.5f, -normal, ref val, 3f, mask, (QueryTriggerInteraction)1))
		{
			return ((RaycastHit)(ref val)).point + ((RaycastHit)(ref val)).normal * 0.05f;
		}
		return point + normal * 0.05f;
	}

	private void Build(Vector3 normal, float radius)
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: 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_004c: 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_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02db: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e1: Expected O, but got Unknown
		//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_030f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0314: Unknown result type (might be due to invalid IL or missing references)
		//IL_0315: Unknown result type (might be due to invalid IL or missing references)
		//IL_032f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0334: Unknown result type (might be due to invalid IL or missing references)
		//IL_035e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0374: Unknown result type (might be due to invalid IL or missing references)
		//IL_038a: Unknown result type (might be due to invalid IL or missing references)
		//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_03af: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_0405: Unknown result type (might be due to invalid IL or missing references)
		//IL_040a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0415: Unknown result type (might be due to invalid IL or missing references)
		//IL_041a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: 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_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0207: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0211: 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)
		//IL_021f: 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_022f: 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_0240: Unknown result type (might be due to invalid IL or missing references)
		//IL_0245: Unknown result type (might be due to invalid IL or missing references)
		//IL_024a: Unknown result type (might be due to invalid IL or missing references)
		//IL_024b: Unknown result type (might be due to invalid IL or missing references)
		born = Time.time;
		if (((Vector3)(ref normal)).sqrMagnitude < 0.5f)
		{
			normal = Vector3.up;
		}
		((Vector3)(ref normal)).Normalize();
		LandingDust.Spawn(((Component)this).transform.position, normal);
		Vector3 val = Vector3.Cross(normal, Vector3.forward);
		Vector3 val2 = ((Vector3)(ref val)).normalized;
		if (((Vector3)(ref val2)).sqrMagnitude < 0.5f)
		{
			val2 = Vector3.right;
		}
		val = Vector3.Cross(val2, normal);
		Vector3 normalized = ((Vector3)(ref val)).normalized;
		if (Object.op_Implicit((Object)(object)MjolnirLightning.ArcMaterial()))
		{
			for (int i = 0; i < 8; i++)
			{
				float num = (float)i * MathF.PI * 0.25f + Noise() * 0.25f;
				Vector3 val3 = val2 * Mathf.Cos(num) + normalized * Mathf.Sin(num);
				float num2 = Mathf.Min(radius, 3.4f) * (0.55f + (float)random.NextDouble() * 0.4f);
				LineRenderer val4 = MjolnirLightning.NewLine(((Component)this).transform, "GroundDischarge", 0.022f);
				arcs.Add(val4);
				val4.endWidth = 0.003f;
				for (int j = 0; j < 8; j++)
				{
					float num3 = (float)j / 7f;
					Vector3 point = ((Component)this).transform.position + val3 * (0.15f + num2 * num3) + Vector3.Cross(normal, val3) * Noise() * 0.23f * Mathf.Sin(num3 * MathF.PI);
					val4.SetPosition(j, Ground(point, normal));
				}
				if (i % 2 == 0)
				{
					LineRenderer val5 = MjolnirLightning.NewLine(((Component)this).transform, "DischargeFork", 0.012f);
					arcs.Add(val5);
					Vector3 position = val4.GetPosition(4);
					Vector3 val6 = position + val3 * 0.45f + Vector3.Cross(normal, val3) * (0.35f + Noise() * 0.2f);
					for (int k = 0; k < 8; k++)
					{
						val5.SetPosition(k, Ground(Vector3.Lerp(position, val6, (float)k / 7f) + val2 * Noise() * 0.08f, normal));
					}
				}
			}
		}
		flash = ((Component)this).gameObject.AddComponent<Light>();
		flash.type = (LightType)2;
		flash.color = new Color(0.6f, 0.8f, 1f);
		flash.range = 5f;
		flash.intensity = 2.5f;
		flash.shadows = (LightShadows)0;
		GameObject val7 = new GameObject("GroundSparks");
		val7.transform.SetParent(((Component)this).transform, false);
		val7.transform.localPosition = normal * 0.12f;
		val7.transform.rotation = Quaternion.FromToRotation(Vector3.forward, normal);
		ParticleSystem val8 = val7.AddComponent<ParticleSystem>();
		val8.Stop(true, (ParticleSystemStopBehavior)0);
		MainModule main = val8.main;
		((MainModule)(ref main)).loop = false;
		((MainModule)(ref main)).playOnAwake = false;
		((MainModule)(ref main)).duration = 0.1f;
		((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.15f, 0.45f);
		((MainModule)(ref main)).startSpeed = new MinMaxCurve(2f, 5f);
		((MainModule)(ref main)).startSize = new MinMaxCurve(0.02f, 0.05f);
		((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(0.55f, 0.8f, 1f, 0.9f));
		((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(1.2f);
		((MainModule)(ref main)).maxParticles = 32;
		((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
		EmissionModule emission = val8.emission;
		((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(0f);
		((EmissionModule)(ref emission)).SetBursts((Burst[])(object)new Burst[1]
		{
			new Burst(0f, (short)24)
		});
		ShapeModule shape = val8.shape;
		((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)2;
		((ShapeModule)(ref shape)).radius = 0.3f;
		((Renderer)val7.GetComponent<ParticleSystemRenderer>()).sharedMaterial = MjolnirLightning.ArcMaterial();
		val8.Play();
	}

	private void Update()
	{
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		float num = Time.time - born;
		if (Object.op_Implicit((Object)(object)flash))
		{
			flash.intensity = 2.5f * Mathf.Clamp01(1f - num / 0.18f);
		}
		if (Time.time < next)
		{
			return;
		}
		next = Time.time + 0.04f;
		float num2 = Mathf.Clamp01(1f - num / 0.38f);
		foreach (LineRenderer arc in arcs)
		{
			if (Object.op_Implicit((Object)(object)arc))
			{
				((Renderer)arc).enabled = num2 > 0f && random.NextDouble() > 0.18;
				arc.startColor = new Color(1.1f, 1.7f, 2.3f, num2 * 0.9f);
				arc.endColor = new Color(0.15f, 0.55f, 1f, num2 * 0.05f);
			}
		}
	}
}
public sealed class RunesPulse : MonoBehaviour
{
	private sealed class Layer
	{
		internal MeshRenderer Source;

		internal MeshRenderer Overlay;
	}

	private readonly List<Layer> layers = new List<Layer>();

	private Material glow;

	private static Texture2D mask;

	private static ConfigEntry<bool> enabledPulse;

	private static ConfigEntry<float> intensity;

	private static void Settings()
	{
		MjolnirPlugin active = MjolnirPlugin.Active;
		if (Object.op_Implicit((Object)(object)active))
		{
			if (enabledPulse == null)
			{
				enabledPulse = ((BaseUnityPlugin)active).Config.Bind<bool>("Effects", "LivingRunes", true, "Pulsacao luminosa nas runas.");
			}
			if (intensity == null)
			{
				intensity = ((BaseUnityPlugin)active).Config.Bind<float>("Effects", "RuneIntensity", 2f, "Brilho das runas (0.5 a 5).");
			}
		}
	}

	public static void Attach(GameObject model)
	{
		if (Object.op_Implicit((Object)(object)model) && !Object.op_Implicit((Object)(object)model.GetComponent<RunesPulse>()))
		{
			model.AddComponent<RunesPulse>();
		}
	}

	private static Texture2D Mask()
	{
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Expected O, but got Unknown
		//IL_007b: 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_0082: 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: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)mask))
		{
			return mask;
		}
		string path = Path.Combine(Path.GetDirectoryName(typeof(MjolnirPlugin).Assembly.Location), "Mjolnir_RunesEmission.png");
		if (!File.Exists(path))
		{
			Debug.LogWarning((object)"[Mjolnir] Mapa de runas ausente: importe o ZIP completo com Mjolnir_RunesEmission.png.");
			return null;
		}
		Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true);
		if (!ImageConversion.LoadImage(val, File.ReadAllBytes(path), false))
		{
			Object.Destroy((Object)(object)val);
			return null;
		}
		Color32[] pixels = val.GetPixels32();
		for (int i = 0; i < pixels.Length; i++)
		{
			Color32 val2 = pixels[i];
			int num = Mathf.Max((int)val2.r, Mathf.Max((int)val2.g, (int)val2.b));
			pixels[i] = ((num == 0) ? new Color32((byte)0, (byte)0, (byte)0, (byte)0) : new Color32((byte)(val2.r * 255 / num), (byte)(val2.g * 255 / num), (byte)(val2.b * 255 / num), (byte)Mathf.Min(255, num * 2)));
		}
		val.SetPixels32(pixels);
		((Texture)val).wrapMode = (TextureWrapMode)1;
		((Object)val).name = "Mjolnir_RuneGlowMask";
		val.Apply(true, true);
		mask = val;
		return mask;
	}

	private void Start()
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Expected O, but got Unknown
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		Settings();
		Texture2D val = Mask();
		Shader val2 = Shader.Find("Sprites/Default");
		if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2))
		{
			Debug.LogWarning((object)"[Mjolnir] Camada luminosa das runas indisponivel.");
			return;
		}
		glow = new Material(val2)
		{
			name = "Mjolnir_LivingRunes",
			mainTexture = (Texture)(object)val
		};
		glow.renderQueue = 3001;
		MeshRenderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<MeshRenderer>(true);
		foreach (MeshRenderer val3 in componentsInChildren)
		{
			MeshFilter component = ((Component)val3).GetComponent<MeshFilter>();
			if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.sharedMesh))
			{
				GameObject val4 = new GameObject("Mjolnir_RuneGlow")
				{
					layer = ((Component)val3).gameObject.layer
				};
				val4.transform.SetParent(((Component)val3).transform, false);
				val4.transform.localScale = Vector3.one * 1.0002f;
				val4.AddComponent<MeshFilter>().sharedMesh = component.sharedMesh;
				MeshRenderer val5 = val4.AddComponent<MeshRenderer>();
				Material[] array = (Material[])(object)new Material[Mathf.Max(1, component.sharedMesh.subMeshCount)];
				for (int j = 0; j < array.Length; j++)
				{
					array[j] = glow;
				}
				((Renderer)val5).sharedMaterials = array;
				((Renderer)val5).shadowCastingMode = (ShadowCastingMode)0;
				((Renderer)val5).receiveShadows = false;
				((Renderer)val5).lightProbeUsage = (LightProbeUsage)0;
				((Renderer)val5).reflectionProbeUsage = (ReflectionProbeUsage)0;
				((Renderer)val5).enabled = ((Renderer)val3).enabled;
				layers.Add(new Layer
				{
					Source = val3,
					Overlay = val5
				});
			}
		}
		Debug.Log((object)("[Mjolnir] Runas luminosas: " + layers.Count + " malhas; pulsacao=" + enabledPulse.Value + "; intensidade=" + intensity.Value));
	}

	private void LateUpdate()
	{
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		MjolnirPlugin active = MjolnirPlugin.Active;
		if (!Object.op_Implicit((Object)(object)active) || !Object.op_Implicit((Object)(object)glow))
		{
			return;
		}
		float charge = ((active.Storm != null) ? active.Storm.Meter.Fraction : 0f);
		bool active2 = Object.op_Implicit((Object)(object)active.Flight) || active.Wings.Active || active.Strike.Casting;
		Player localPlayer = Player.m_localPlayer;
		ItemData val = (Object.op_Implicit((Object)(object)localPlayer) ? ((Humanoid)localPlayer).GetCurrentWeapon() : null);
		int quality = ((val == null || !MjolnirPlugin.IsMjolnir(val)) ? 1 : val.m_quality);
		float num = RunePulseRules.Gain(Time.time, intensity.Value, charge, quality, active2);
		glow.SetColor("_Color", new Color(num, num, num, 1f));
		foreach (Layer layer in layers)
		{
			if (Object.op_Implicit((Object)(object)layer.Overlay))
			{
				((Renderer)layer.Overlay).enabled = enabledPulse.Value && Object.op_Implicit((Object)(object)layer.Source) && ((Renderer)layer.Source).enabled;
			}
		}
	}

	private void OnDisable()
	{
		foreach (Layer layer in layers)
		{
			if (Object.op_Implicit((Object)(object)layer.Overlay))
			{
				((Renderer)layer.Overlay).enabled = false;
			}
		}
	}

	private void OnDestroy()
	{
		foreach (Layer layer in layers)
		{
			if (Object.op_Implicit((Object)(object)layer.Overlay))
			{
				Object.Destroy((Object)(object)((Component)layer.Overlay).gameObject);
			}
		}
		if (Object.op_Implicit((Object)(object)glow))
		{
			Object.Destroy((Object)(object)glow);
		}
	}

	public static void DrawSettings()
	{
		Settings();
		if (enabledPulse != null)
		{
			GUILayout.Space(12f);
			GUILayout.Label("RUNAS VIVAS", Array.Empty<GUILayoutOption>());
			enabledPulse.Value = GUILayout.Toggle(enabledPulse.Value, "Ativar pulsacao luminosa das runas", Array.Empty<GUILayoutOption>());
			GUILayout.Label("Intensidade: " + intensity.Value.ToString("0.0"), Array.Empty<GUILayoutOption>());
			intensity.Value = GUILayout.HorizontalSlider(Mathf.Clamp(intensity.Value, 0.5f, 5f), 0.5f, 5f, Array.Empty<GUILayoutOption>());
			GUILayout.Label("A pulsacao alterna visivelmente entre fraco e forte; nao depende da iluminacao ambiente.", Array.Empty<GUILayoutOption>());
		}
	}
}
public static class RunePulseRules
{
	public static float Gain(float time, float intensity, float charge, int quality, bool active)
	{
		if (float.IsNaN(time) || float.IsInfinity(time))
		{
			time = 0f;
		}
		if (float.IsNaN(intensity) || float.IsInfinity(intensity))
		{
			intensity = 2f;
		}
		if (float.IsNaN(charge) || float.IsInfinity(charge))
		{
			charge = 0f;
		}
		float num = (float)(0.5 + 0.5 * Math.Sin((double)time * 4.5));
		return (0.12f + 2.88f * num * num) * Math.Max(0.5f, Math.Min(5f, intensity)) * (1f + Math.Max(0f, Math.Min(1f, charge)) * 0.2f) * (1f + 0.12f * (float)(Math.Max(1, Math.Min(4, quality)) - 1)) * (active ? 1.2f : 1f);
	}
}
public static class ForgeProgression
{
	public static int Quality(int q)
	{
		return ForgeRules.Quality(q);
	}

	public static void Configure(SharedData item)
	{
		//IL_002a: 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_0049: Unknown result type (might be due to invalid IL or missing references)
		item.m_maxQuality = 4;
		item.m_damages.m_blunt = 55f;
		item.m_damages.m_lightning = 20f;
		item.m_damagesPerLevel = new DamageTypes
		{
			m_blunt = 10f,
			m_lightning = 5f
		};
		item.m_maxDurability = 200f;
		item.m_durabilityPerLevel = 50f;
	}

	public static string HudTitle()
	{
		Player localPlayer = Player.m_localPlayer;
		ItemData val = (Object.op_Implicit((Object)(object)localPlayer) ? ((Humanoid)localPlayer).GetCurrentWeapon() : null);
		int num = ((val == null) ? 1 : Quality(val.m_quality));
		string text = (new string[4] { "I", "II", "III", "IV" })[num - 1];
		return "MJÖLNIR " + text + " | " + ForgeRules.Rank(num);
	}

	public static void DrawGuide()
	{
		GUILayout.Space(12f);
		GUILayout.Label("PROGRESSAO NA FORJA NEGRA", Array.Empty<GUILayoutOption>());
		Player localPlayer = Player.m_localPlayer;
		ItemData val = (Object.op_Implicit((Object)(object)localPlayer) ? ((Humanoid)localPlayer).GetCurrentWeapon() : null);
		if (val != null && MjolnirPlugin.IsMjolnir(val))
		{
			int num = Quality(val.m_quality);
			GUILayout.Label("Estagio atual: " + num + "/4 - " + ForgeRules.Rank(num), Array.Empty<GUILayoutOption>());
			GUILayout.Label("Dano base: " + ForgeRules.Blunt(num) + " contundente + " + ForgeRules.Lightning(num) + " eletrico | Durabilidade: " + ForgeRules.Durability(num), Array.Empty<GUILayoutOption>());
			if (num < 4)
			{
				int num2 = ForgeRules.UpgradeFactor(num + 1);
				GUILayout.Label("Proxima melhoria: forja negra nivel " + ForgeRules.Station(num + 1), Array.Empty<GUILayoutOption>());
				GUILayout.Label(8 * num2 + " Metal negro | " + 6 * num2 + " Prata | " + 4 * num2 + " Flametal | " + 4 * num2 + " Eitr refinado | " + num2 + " Pedra do trovao", Array.Empty<GUILayoutOption>());
			}
			else
			{
				GUILayout.Label("Qualidade maxima: Senhor do Trovao.", Array.Empty<GUILayoutOption>());
			}
		}
		GUILayout.Label("Use a aba Melhorar da forja negra, com a arma no inventario e os materiais descobertos. Cada qualidade: +10 contundente, +5 eletrico e +50 durabilidade. Os poderes continuam disponiveis.", Array.Empty<GUILayoutOption>());
	}
}
public static class ForgeRules
{
	public static int Quality(int q)
	{
		return Math.Max(1, Math.Min(4, q));
	}

	public static int Blunt(int q)
	{
		return 55 + 10 * (Quality(q) - 1);
	}

	public static int Lightning(int q)
	{
		return 20 + 5 * (Quality(q) - 1);
	}

	public static int Durability(int q)
	{
		return 200 + 50 * (Quality(q) - 1);
	}

	public static int Station(int q)
	{
		return Quality(q) + 1;
	}

	public static int UpgradeFactor(int target)
	{
		if (Quality(target) != 1)
		{
			if (Quality(target) != 4)
			{
				return Quality(target) - 1;
			}
			return 4;
		}
		return 0;
	}

	public static string Rank(int q)
	{
		return (new string[4] { "FORJADO", "DESPERTO", "TEMPESTADE", "SENHOR DO TROVAO" })[Quality(q) - 1];
	}
}