Dash.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("Dash")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.5.3.0")]
[assembly: AssemblyInformationalVersion("0.5.3")]
[assembly: AssemblyProduct("Dash")]
[assembly: AssemblyTitle("Dash")]
[assembly: AssemblyVersion("0.5.3.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Dash
{
	internal static class DashConfig
	{
		public static ConfigEntry<KeyboardShortcut> DashKey;

		public static ConfigEntry<string> DashSound;

		public static ConfigEntry<bool> Motes;

		public static ConfigEntry<Color> MoteColour;

		public static ConfigEntry<string> LaunchEffect;

		public static ConfigEntry<bool> DustTrail;

		public static ConfigEntry<float> DustTrailDensity;

		public static ConfigEntry<float> Distance;

		public static ConfigEntry<float> Duration;

		public static ConfigEntry<float> Cooldown;

		public static ConfigEntry<float> StaminaCost;

		public static ConfigEntry<int> AirDashesPerAirtime;

		public static ConfigEntry<float> SlamAngle;

		public static ConfigEntry<float> SlamMinHeight;

		public static ConfigEntry<float> SlamDamage;

		public static ConfigEntry<float> SlamRadius;

		public static ConfigEntry<float> SlamPushForce;

		public static ConfigEntry<string> LargeCreatures;

		public static ConfigEntry<float> LargeCreatureSize;

		public static void Bind(ConfigFile config)
		{
			//IL_001b: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Expected O, but got Unknown
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Expected O, but got Unknown
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Expected O, but got Unknown
			DashKey = config.Bind<KeyboardShortcut>("Controls", "Dash key", new KeyboardShortcut((KeyCode)114, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 }), "Key combination that triggers the dash or slam. Local setting, not synced.");
			DashSound = config.Bind<string>("Effects", "Dash sound", "sfx_sword_swing", "Vanilla sound prefab played when any dash or slam starts (default: a sword swing whoosh). Leave empty for none. Local setting, not synced.");
			Motes = config.Bind<bool>("Effects", "Dash particles", true, "Shed small glowing particles from the character as a dash or slam begins. Local setting, not synced.");
			MoteColour = config.Bind<Color>("Effects", "Dash particle colour", new Color(0.3f, 1f, 0.35f, 1f), "Colour of the dash particles (default: green). Local setting, not synced.");
			LaunchEffect = config.Bind<string>("Effects", "Ground dash launch effect", "vfx_sledge_hit", "Vanilla effect prefab spawned where a ground dash starts (default: the wooden sledge's dust ring). Leave empty for none. Local setting, not synced.");
			DustTrail = config.Bind<bool>("Effects", "Ground dash dust trail", true, "Leave a trail of dust along a ground dash. Local setting, not synced.");
			DustTrailDensity = config.Bind<float>("Effects", "Ground dash dust trail density", 8f, new ConfigDescription("How much thicker than the game's normal slide dust the trail is. Local setting, not synced.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 30f), Array.Empty<object>()));
			Distance = Synced(config, "Dash", "Distance", 50f, 1f, 200f, "Metres travelled by one dash.");
			Duration = Synced(config, "Dash", "Duration", 0.5f, 0.1f, 3f, "Seconds one dash takes to cover its distance.");
			Cooldown = Synced(config, "Dash", "Cooldown", 5f, 0f, 120f, "Seconds before the dash can be used again.");
			StaminaCost = Synced(config, "Dash", "Stamina cost", 15f, 0f, 200f, "Stamina spent by one dash or slam.");
			AirDashesPerAirtime = Synced(config, "Dash", "Air dashes per airtime", 1, 0, 10, "How many dashes are allowed before touching the ground again.");
			SlamAngle = Synced(config, "Slam", "Angle", 40f, 5f, 89f, "Degrees below horizontal the camera must point for an airborne dash to become a slam.");
			SlamMinHeight = Synced(config, "Slam", "Minimum height", 1.5f, 0f, 20f, "Metres above the ground needed to slam; below this an airborne press is a dash.");
			SlamDamage = Synced(config, "Slam", "Damage", 60f, 0f, 1000f, "Blunt damage dealt to enemies at the impact point.");
			SlamRadius = Synced(config, "Slam", "Radius", 4f, 0.5f, 20f, "Metres around the impact point in which enemies are hit.");
			SlamPushForce = Synced(config, "Slam", "Push force", 80f, 0f, 500f, "Knockback applied to enemies hit by the slam.");
			LargeCreatureSize = Synced(config, "Creatures", "Large creature size", 3.8f, 0f, 10000f, "Creatures this big or bigger stop a dash where it reaches them instead of being pushed along. Size is the creature's collision volume in cubic metres, to one decimal, as shown in the log (Greydwarf brute 3.8, Fuling berserker 6.0, bear 14.4, troll 18.7). 0 = automatic: bigger than the smallest creature in the list below.");
			LargeCreatures = config.Bind<string>("Creatures", "Large creatures", "Troll, Bjorn, GoblinBrute", new ConfigDescription("Creature prefab names, comma separated, that always stop a dash whatever their size. Bosses always stop it. Server-enforced.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
		}

		private static ConfigEntry<float> Synced(ConfigFile config, string section, string key, float value, float min, float max, string description)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			return config.Bind<float>(section, key, value, new ConfigDescription(description + " Server-enforced.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(min, max), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
		}

		private static ConfigEntry<int> Synced(ConfigFile config, string section, string key, int value, int min, int max, string description)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			return config.Bind<int>(section, key, value, new ConfigDescription(description + " Server-enforced.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(min, max), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
		}
	}
	internal static class DashController
	{
		private const float ExitSpeed = 7f;

		private const float SlamMaxRange = 300f;

		private const float SlamNoise = 30f;

		private static readonly MethodInfo s_updateEyeRotation = AccessTools.Method(typeof(Character), "UpdateEyeRotation", (Type[])null, (Type[])null);

		private static readonly List<Character> s_targets = new List<Character>();

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

		private static Player? s_player;

		private static Rigidbody? s_body;

		private static bool s_active;

		private static bool s_finishing;

		private static bool s_blocked;

		private static string s_blockedBy = "";

		private static DashMove s_move;

		private static Vector3 s_dir;

		private static Vector3 s_startPos;

		private static float s_speed;

		private static float s_remaining;

		private static float s_dashReadyAt;

		private static float s_slamReadyAt;

		private static int s_airDashesUsed;

		public static bool Active => s_active;

		public static void FrameTick(Player player)
		{
			if (s_active && ((Object)(object)s_player != (Object)(object)player || (Object)(object)s_body == (Object)null))
			{
				s_active = false;
				s_finishing = false;
				DashEffects.OnEnd();
			}
			if (!s_active && ((Character)player).IsOnGround())
			{
				s_airDashesUsed = 0;
			}
		}

		public static void OnKeyPressed(Player player)
		{
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: 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_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: 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)
			if (s_active)
			{
				return;
			}
			string text = RefusalReason(player);
			if (text != null)
			{
				Say(player, text);
				return;
			}
			float pitchBelowHorizon;
			float heightAboveGround;
			DashMove move = DashMoves.Classify(player, out pitchBelowHorizon, out heightAboveGround);
			bool slam = move == DashMove.Slam;
			float num = (slam ? s_slamReadyAt : s_dashReadyAt) - Time.time;
			if (num > 0f)
			{
				Say(player, string.Format("{0} ready in {1:0.0}s", slam ? "Slam" : "Dash", num));
				return;
			}
			if (move == DashMove.AirDash && s_airDashesUsed >= DashConfig.AirDashesPerAirtime.Value)
			{
				Say(player, "No air dash left until you land");
				return;
			}
			float value = DashConfig.StaminaCost.Value;
			if (value > 0f && !((Character)player).HaveStamina(value))
			{
				if ((Object)(object)Hud.instance != (Object)null)
				{
					Hud.instance.StaminaBarEmptyFlash();
				}
				return;
			}
			Rigidbody component = ((Component)player).GetComponent<Rigidbody>();
			if (!((Object)(object)component == (Object)null))
			{
				((Character)player).UseStamina(value);
				float num2 = Mathf.Max(0.05f, DashConfig.Duration.Value);
				s_player = player;
				s_body = component;
				s_move = move;
				s_dir = DashMoves.Direction(player, move);
				s_startPos = component.position;
				s_speed = DashConfig.Distance.Value / num2;
				s_remaining = (slam ? 300f : DashConfig.Distance.Value);
				s_blocked = false;
				s_blockedBy = "";
				s_finishing = false;
				s_active = true;
				s_passed.Clear();
				float num3 = Time.time + DashConfig.Cooldown.Value;
				if (slam)
				{
					s_slamReadyAt = num3;
				}
				else
				{
					s_dashReadyAt = num3;
				}
				if (move == DashMove.AirDash)
				{
					s_airDashesUsed++;
				}
				Vector3 val = default(Vector3);
				((Vector3)(ref val))..ctor(s_dir.x, 0f, s_dir.z);
				if (((Vector3)(ref val)).sqrMagnitude > 0.0001f)
				{
					component.rotation = Quaternion.LookRotation(((Vector3)(ref val)).normalized);
				}
				Cosmetic(delegate
				{
					DashEffects.OnStart(player, move);
				});
				Cosmetic(delegate
				{
					DashCooldowns.Show(player, slam, DashConfig.Cooldown.Value);
				});
				DashPlugin.Log.LogInfo((object)($"Dash start: {move}, pitch {pitchBelowHorizon:0.0} deg below horizon, height {heightAboveGround:0.0} m, " + $"from {s_startPos}, direction {s_dir}, speed {s_speed:0.0} m/s"));
			}
		}

		public static bool Step(Player player, float dt, ref float lastGroundTouch, ref float maxAirAltitude)
		{
			//IL_00f5: 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_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: 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)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: 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_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: 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_01de: 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_01eb: 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_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: 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_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			Rigidbody val = s_body;
			if ((Object)(object)val == (Object)null || (Object)(object)s_player != (Object)(object)player)
			{
				s_active = false;
				s_finishing = false;
				DashEffects.OnEnd();
				return false;
			}
			if (s_finishing)
			{
				val.linearVelocity = (s_blocked ? Vector3.zero : (s_dir * Mathf.Min(7f, s_speed)));
				maxAirAltitude = val.position.y;
				if (s_move == DashMove.Slam && s_blocked)
				{
					SlamImpact(player, val.position);
				}
				End(val, s_blocked ? ("blocked by " + s_blockedBy) : "distance reached");
				return false;
			}
			val.useGravity = false;
			PhysicsMaterial material = ((Collider)((Character)player).GetCollider()).material;
			material.staticFriction = 0f;
			material.dynamicFriction = 0f;
			maxAirAltitude = val.position.y;
			s_updateEyeRotation.Invoke(player, null);
			float num = Mathf.Min(s_speed * dt, s_remaining);
			Vector3 position = val.position;
			Vector3 pos = position;
			DashPhysics.Capsule capsule = DashPhysics.CapsuleOf(player);
			bool grounded = false;
			string text = "";
			bool flag;
			RaycastHit blockHit;
			switch (s_move)
			{
			case DashMove.GroundDash:
			{
				flag = DashPhysics.GroundStep(ref pos, s_dir, num, capsule, out grounded, out blockHit);
				bool onGround = grounded;
				Cosmetic(delegate
				{
					DashEffects.OnGroundTick(player, onGround);
				});
				break;
			}
			case DashMove.Slam:
				flag = DashPhysics.SlideMove(ref pos, s_dir * num, capsule, stopOnAnyHit: true, out blockHit);
				break;
			default:
				flag = DashPhysics.SlideMove(ref pos, s_dir * num, capsule, stopOnAnyHit: false, out blockHit);
				break;
			}
			Vector3 val2 = pos - position;
			float magnitude = ((Vector3)(ref val2)).magnitude;
			if (magnitude > 0.001f)
			{
				Vector3 val3 = val2 / magnitude;
				if (DashPhysics.SweepCreatures(player, position, capsule, val3, magnitude + capsule.Margin, s_move == DashMove.Slam, s_passed, out float hitDistance, out Character stopper))
				{
					pos = position + val3 * Mathf.Clamp(hitDistance - capsule.Margin, 0f, magnitude);
					flag = true;
					text = (DashCreatures.IsLarge(stopper) ? "large creature " : "enemy ") + DashCreatures.Describe(stopper);
				}
			}
			val.linearVelocity = (pos - position) / dt;
			val.angularVelocity = Vector3.zero;
			if (grounded)
			{
				lastGroundTouch = 0f;
			}
			s_remaining -= num;
			if (flag || s_remaining <= 0.001f)
			{
				s_blocked = flag;
				s_blockedBy = ((text.Length > 0) ? text : DashPhysics.Describe(blockHit));
				s_finishing = true;
			}
			return true;
		}

		public static void CancelIfInterrupted(Player player)
		{
			//IL_0049: 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)
			if (s_active && (((Character)player).IsDead() || ((Character)player).IsSwimming() || ((Character)player).IsAttached() || ((Character)player).IsDebugFlying() || ((Character)player).IsTeleporting()))
			{
				Rigidbody val = s_body;
				if ((Object)(object)val != (Object)null)
				{
					val.useGravity = true;
					val.linearVelocity = Vector3.ClampMagnitude(val.linearVelocity, 7f);
					End(val, "interrupted");
				}
				s_active = false;
				s_finishing = false;
				DashEffects.OnEnd();
			}
		}

		private static void SlamImpact(Player player, Vector3 point)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_007b: 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_0086: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			//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_00fb: 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_0105: Unknown result type (might be due to invalid IL or missing references)
			float value = DashConfig.SlamRadius.Value;
			s_targets.Clear();
			Character.GetCharactersInRange(point, value, s_targets);
			int num = 0;
			foreach (Character s_target in s_targets)
			{
				if (!((Object)(object)s_target == (Object)(object)player) && !s_target.IsDead() && BaseAI.IsEnemy((Character)(object)player, s_target))
				{
					Vector3 dir = ((Component)s_target).transform.position - point;
					dir.y = 0f;
					dir = ((((Vector3)(ref dir)).sqrMagnitude > 0.0001f) ? ((Vector3)(ref dir)).normalized : ((Component)player).transform.forward);
					HitData val = new HitData();
					val.m_damage.m_blunt = DashConfig.SlamDamage.Value;
					val.m_pushForce = DashConfig.SlamPushForce.Value;
					val.m_point = s_target.GetCenterPoint();
					val.m_dir = dir;
					val.m_hitType = (HitType)2;
					val.SetAttacker((Character)(object)player);
					s_target.Damage(val);
					num++;
				}
			}
			s_targets.Clear();
			((Character)player).AddNoise(30f);
			Cosmetic(delegate
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				DashEffects.OnSlamImpact(point);
			});
			DashPlugin.Log.LogInfo((object)$"Slam impact at {point}: hit {num} enemies within {value:0.0} m");
		}

		private static void End(Rigidbody body, string reason)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			s_active = false;
			s_finishing = false;
			DashEffects.OnEnd();
			float num = Vector3.Distance(s_startPos, body.position);
			DashPlugin.Log.LogInfo((object)$"Dash end: {reason}, travelled {num:0.0} m, at {body.position}");
			if (s_passed.Count <= 0)
			{
				return;
			}
			List<string> list = new List<string>();
			foreach (Character item in s_passed)
			{
				if ((Object)(object)item != (Object)null)
				{
					list.Add(DashCreatures.Describe(item));
				}
			}
			s_passed.Clear();
			DashPlugin.Log.LogInfo((object)("Small creatures pushed along the way: " + string.Join(", ", list)));
		}

		private static string? RefusalReason(Player player)
		{
			if (((Character)player).IsSwimming())
			{
				return "Can't dash while swimming";
			}
			if (((Character)player).IsEncumbered())
			{
				return "Too encumbered to dash";
			}
			if (((Character)player).IsAttached() || ((Character)player).IsStaggering() || ((Character)player).InDodge() || ((Character)player).IsDebugFlying())
			{
				return "Can't dash right now";
			}
			return null;
		}

		private static void Say(Player player, string text)
		{
			((Character)player).Message((MessageType)2, text, 0, (Sprite)null, false);
		}

		private static void Cosmetic(Action action)
		{
			try
			{
				action();
			}
			catch (Exception arg)
			{
				DashPlugin.Log.LogError((object)$"Dash effect failed: {arg}");
			}
		}
	}
	internal static class DashCooldowns
	{
		private const int IconSize = 64;

		private static StatusEffect? s_dash;

		private static StatusEffect? s_slam;

		public static void Register()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			bool flag = (int)SystemInfo.graphicsDeviceType == 4;
			s_dash = Create("SE_DashCooldown", "Dash", "Dash is recharging.", flag ? null : ChevronIcon(pointDown: false));
			s_slam = Create("SE_SlamCooldown", "Slam", "Slam is recharging.", flag ? null : ChevronIcon(pointDown: true));
			ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(s_dash, false));
			ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(s_slam, false));
		}

		public static void Show(Player player, bool slam, float seconds)
		{
			StatusEffect val = (slam ? s_slam : s_dash);
			if (!((Object)(object)val == (Object)null) && !(seconds <= 0f))
			{
				SEMan sEMan = ((Character)player).GetSEMan();
				sEMan.RemoveStatusEffect(val.NameHash(), true);
				val.m_ttl = seconds;
				sEMan.AddStatusEffect(val, true, 0, 0f, (short)(-1));
			}
		}

		private static StatusEffect Create(string id, string displayName, string tooltip, Sprite? icon)
		{
			StatusEffect obj = ScriptableObject.CreateInstance<StatusEffect>();
			((Object)obj).name = id;
			obj.m_name = displayName;
			obj.m_tooltip = tooltip;
			obj.m_icon = icon;
			obj.m_cooldownIcon = true;
			return obj;
		}

		private static Sprite ChevronIcon(bool pointDown)
		{
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: 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_00fe: 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_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			Color32 val = default(Color32);
			((Color32)(ref val))..ctor(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
			Color32 val2 = default(Color32);
			((Color32)(ref val2))..ctor(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)0);
			Color32[] array = (Color32[])(object)new Color32[4096];
			float num = 31.5f;
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num2 = (pointDown ? (63 - i) : j);
					float num3 = Mathf.Abs((float)(pointDown ? j : i) - num);
					bool flag = false;
					for (float num4 = 32f; num4 <= 52f; num4 += 20f)
					{
						if (num3 <= 22f && Mathf.Abs(num4 - num2 - num3) <= 5f)
						{
							flag = true;
						}
					}
					array[i * 64 + j] = (flag ? val : val2);
				}
			}
			Texture2D val3 = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				wrapMode = (TextureWrapMode)1
			};
			val3.SetPixels32(array);
			val3.Apply();
			return Sprite.Create(val3, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 100f);
		}
	}
	internal static class DashCreatures
	{
		private static readonly HashSet<string> s_listed = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

		private static ZNetScene? s_scene;

		private static string s_listSource = "";

		private static float s_sizeSource = -1f;

		private static int s_thresholdTenths = int.MaxValue;

		public static bool IsLarge(Character creature)
		{
			if ((Object)(object)creature == (Object)null || creature.IsPlayer())
			{
				return false;
			}
			Refresh();
			if (creature.IsBoss() || s_listed.Contains(Utils.GetPrefabName(((Component)creature).gameObject)))
			{
				return true;
			}
			return Tenths(Size(creature)) >= s_thresholdTenths;
		}

		private static int Tenths(float size)
		{
			return Mathf.RoundToInt(size * 10f);
		}

		public static float Size(Character creature)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			CapsuleCollider val = creature.GetCollider();
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)creature).GetComponent<CapsuleCollider>();
			}
			if ((Object)(object)val == (Object)null)
			{
				return 0f;
			}
			float num = Mathf.Abs(((Component)val).transform.lossyScale.x);
			float num2 = val.radius * num;
			float num3 = Mathf.Max(val.height * num, num2 * 2f);
			return (float)Math.PI * num2 * num2 * (num3 - num2 * 2f) + 4.1887903f * num2 * num2 * num2;
		}

		public static string Describe(Character creature)
		{
			return $"{Utils.GetPrefabName(((Component)creature).gameObject)} ({Size(creature):0.0} m3)";
		}

		private static void Refresh()
		{
			ZNetScene instance = ZNetScene.instance;
			string value = DashConfig.LargeCreatures.Value;
			float value2 = DashConfig.LargeCreatureSize.Value;
			if ((Object)(object)instance == (Object)(object)s_scene && value == s_listSource && value2 == s_sizeSource)
			{
				return;
			}
			s_scene = instance;
			s_listSource = value;
			s_sizeSource = value2;
			s_listed.Clear();
			float num = float.PositiveInfinity;
			List<string> list = new List<string>();
			string[] array = value.Split(new char[1] { ',' });
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				if (text.Length == 0)
				{
					continue;
				}
				s_listed.Add(text);
				GameObject val = (((Object)(object)instance != (Object)null) ? instance.GetPrefab(text) : null);
				Character val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Character>() : null);
				if ((Object)(object)val2 == (Object)null)
				{
					list.Add(text + " (not found)");
					continue;
				}
				float num2 = Size(val2);
				if (num2 <= 0f)
				{
					list.Add(text + " (size unknown)");
					continue;
				}
				num = Mathf.Min(num, num2);
				list.Add($"{text} {num2:0.0} m3");
			}
			if (value2 > 0f)
			{
				s_thresholdTenths = Tenths(value2);
			}
			else if (float.IsPositiveInfinity(num))
			{
				s_thresholdTenths = int.MaxValue;
			}
			else
			{
				s_thresholdTenths = Tenths(num) + 1;
			}
			string text2 = ((list.Count > 0) ? string.Join(", ", list) : "none listed");
			string text3 = ((s_thresholdTenths == int.MaxValue) ? "No size threshold, so only listed creatures and bosses stop a dash." : string.Format("Anything of {0:0.0} m3 or more stops a dash ({1}).", (float)s_thresholdTenths / 10f, (value2 > 0f) ? "set in config" : "bigger than the smallest listed"));
			DashPlugin.Log.LogInfo((object)("Large creatures: " + text2 + ". " + text3));
		}
	}
	internal static class DashEffects
	{
		private const string SlamVfx = "vfx_sledge_iron_hit";

		private const string SlamSfx = "sfx_sledge_iron_hit";

		private const float FovKick = 12f;

		private const float FovInertia = 0.2f;

		private const float MaxFov = 110f;

		private const float RunAnimSpeed = 10f;

		private const int TrailMaxParticles = 600;

		private static readonly int s_forwardSpeed = ZSyncAnimation.GetHash("forward_speed");

		private static readonly int s_sidewaySpeed = ZSyncAnimation.GetHash("sideway_speed");

		private static readonly HashSet<string> s_missing = new HashSet<string>();

		private static bool s_fovKicked;

		private static GameObject[]? s_trail;

		private static Player? s_trailOwner;

		public static void OnStart(Player player, DashMove move)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_005a: 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)
			player.m_dodgeEffects.Create(((Component)player).transform.position, Quaternion.identity, ((Component)player).transform, 1f, -1, ((Character)player).GetZDOID());
			Spawn(DashConfig.DashSound.Value, ((Component)player).transform.position);
			if (DashConfig.Motes.Value)
			{
				DashParticles.Burst(player, DashConfig.MoteColour.Value);
			}
			if (move == DashMove.GroundDash)
			{
				ZSyncAnimation component = ((Component)player).GetComponent<ZSyncAnimation>();
				if ((Object)(object)component != (Object)null)
				{
					component.SetFloat(s_forwardSpeed, 10f);
					component.SetFloat(s_sidewaySpeed, 0f);
				}
				Spawn(DashConfig.LaunchEffect.Value, ((Component)player).transform.position);
				if (DashConfig.DustTrail.Value)
				{
					StartTrail(player);
				}
			}
			GameCamera instance = GameCamera.instance;
			if ((Object)(object)instance != (Object)null)
			{
				instance.SetTempFOV(Mathf.Min(instance.m_fov + 12f, 110f), 0.2f);
				s_fovKicked = true;
			}
		}

		public static void OnGroundTick(Player player, bool grounded)
		{
			//IL_001d: 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)
			if (s_trail != null)
			{
				if (!grounded)
				{
					StopTrail();
				}
				else
				{
					Character.SetupContinuousEffect(((Component)player).transform, ((Component)player).transform.position, true, ((Character)player).m_slideEffects, ref s_trail, ((Character)player).GetZDOID());
				}
			}
		}

		public static void OnEnd()
		{
			StopTrail();
			if (s_fovKicked)
			{
				s_fovKicked = false;
				if ((Object)(object)GameCamera.instance != (Object)null)
				{
					GameCamera.instance.ResetTempFOV();
				}
			}
		}

		public static void OnSlamImpact(Vector3 point)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			Spawn("vfx_sledge_iron_hit", point);
			Spawn("sfx_sledge_iron_hit", point);
			if ((Object)(object)GameCamera.instance != (Object)null)
			{
				GameCamera.instance.AddShake(point, 20f, 2f, false);
			}
		}

		private static void StartTrail(Player player)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			StopTrail();
			GameObject[] array = null;
			Character.SetupContinuousEffect(((Component)player).transform, ((Component)player).transform.position, true, ((Character)player).m_slideEffects, ref array, ((Character)player).GetZDOID());
			if (array == null)
			{
				return;
			}
			float value = DashConfig.DustTrailDensity.Value;
			GameObject[] array2 = array;
			foreach (GameObject val in array2)
			{
				if (!((Object)(object)val == (Object)null))
				{
					ParticleSystem[] componentsInChildren = val.GetComponentsInChildren<ParticleSystem>();
					foreach (ParticleSystem obj in componentsInChildren)
					{
						MainModule main = obj.main;
						((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
						((MainModule)(ref main)).maxParticles = Mathf.Max(((MainModule)(ref main)).maxParticles, 600);
						EmissionModule emission = obj.emission;
						((EmissionModule)(ref emission)).rateOverTimeMultiplier = ((EmissionModule)(ref emission)).rateOverTimeMultiplier * value;
						((EmissionModule)(ref emission)).rateOverDistanceMultiplier = ((EmissionModule)(ref emission)).rateOverDistanceMultiplier * value;
					}
				}
			}
			s_trail = array;
			s_trailOwner = player;
		}

		private static void StopTrail()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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)
			GameObject[] array = s_trail;
			Player val = s_trailOwner;
			s_trail = null;
			s_trailOwner = null;
			if (array == null)
			{
				return;
			}
			if ((Object)(object)val != (Object)null)
			{
				Character.SetupContinuousEffect(((Component)val).transform, ((Component)val).transform.position, false, ((Character)val).m_slideEffects, ref array, default(ZDOID));
				return;
			}
			GameObject[] array2 = array;
			foreach (GameObject val2 in array2)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					Object.Destroy((Object)(object)val2);
				}
			}
		}

		private static void Spawn(string prefabName, Vector3 position)
		{
			//IL_0058: 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)
			if (string.IsNullOrWhiteSpace(prefabName))
			{
				return;
			}
			ZNetScene instance = ZNetScene.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			GameObject prefab = instance.GetPrefab(prefabName.Trim());
			if ((Object)(object)prefab == (Object)null)
			{
				if (s_missing.Add(prefabName))
				{
					DashPlugin.Log.LogWarning((object)("Effect prefab '" + prefabName + "' not found; skipping it"));
				}
			}
			else
			{
				Object.Instantiate<GameObject>(prefab, position, Quaternion.identity);
			}
		}
	}
	internal enum DashMove
	{
		GroundDash,
		AirDash,
		Slam
	}
	internal static class DashMoves
	{
		public static DashMove Classify(Player player, out float pitchBelowHorizon, out float heightAboveGround)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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)
			Vector3 lookDir = ((Character)player).GetLookDir();
			pitchBelowHorizon = (0f - Mathf.Asin(Mathf.Clamp(lookDir.y, -1f, 1f))) * 57.29578f;
			heightAboveGround = 0f;
			if (((Character)player).IsOnGround())
			{
				return DashMove.GroundDash;
			}
			heightAboveGround = DashPhysics.HeightAboveGround(((Component)player).transform.position);
			bool num = pitchBelowHorizon >= DashConfig.SlamAngle.Value;
			bool flag = heightAboveGround >= DashConfig.SlamMinHeight.Value;
			if (!(num && flag))
			{
				return DashMove.AirDash;
			}
			return DashMove.Slam;
		}

		public static Vector3 Direction(Player player, DashMove move)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Character)player).GetLookDir();
			if (move != DashMove.GroundDash)
			{
				return ((Vector3)(ref val)).normalized;
			}
			val.y = 0f;
			if (((Vector3)(ref val)).sqrMagnitude < 0.0001f)
			{
				val = ((Component)player).transform.forward;
				val.y = 0f;
			}
			return ((Vector3)(ref val)).normalized;
		}
	}
	internal static class DashParticles
	{
		private const int TextureSize = 32;

		private const float EmitSeconds = 0.35f;

		private const float EmitPerSecond = 260f;

		private const int StartBurst = 24;

		private static readonly string[] s_shaderNames = new string[4] { "Sprites/Default", "Legacy Shaders/Particles/Additive", "Particles/Standard Unlit", "UI/Default" };

		private static Material? s_material;

		private static bool s_materialTried;

		public static void Burst(Player player, Color colour)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0042: 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_0061: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: 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_00d3: 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_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: 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_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Expected O, but got Unknown
			//IL_0178: 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_0187: 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_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: 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_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: 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_01f5: 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_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: 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)
			Material material = GetMaterial();
			if (!((Object)(object)material == (Object)null))
			{
				GameObject val = new GameObject("DashMotes");
				val.transform.SetParent(((Component)player).transform, false);
				val.transform.localPosition = new Vector3(0f, 1f, 0f);
				ParticleSystem val2 = val.AddComponent<ParticleSystem>();
				val2.Stop(true, (ParticleSystemStopBehavior)0);
				MainModule main = val2.main;
				((MainModule)(ref main)).playOnAwake = false;
				((MainModule)(ref main)).loop = false;
				((MainModule)(ref main)).duration = 0.35f;
				((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.5f, 1.1f);
				((MainModule)(ref main)).startSpeed = new MinMaxCurve(0.3f, 1.6f);
				((MainModule)(ref main)).startSize = new MinMaxCurve(0.05f, 0.14f);
				((MainModule)(ref main)).startColor = new MinMaxGradient(colour, Color.Lerp(colour, Color.white, 0.35f));
				((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
				((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(-0.05f);
				((MainModule)(ref main)).maxParticles = 400;
				EmissionModule emission = val2.emission;
				((EmissionModule)(ref emission)).enabled = true;
				((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(260f);
				((EmissionModule)(ref emission)).SetBursts((Burst[])(object)new Burst[1]
				{
					new Burst(0f, (short)24)
				});
				ShapeModule shape = val2.shape;
				((ShapeModule)(ref shape)).enabled = true;
				((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
				((ShapeModule)(ref shape)).radius = 0.45f;
				Gradient val3 = new Gradient();
				val3.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
				{
					new GradientColorKey(Color.white, 0f),
					new GradientColorKey(Color.white, 1f)
				}, (GradientAlphaKey[])(object)new GradientAlphaKey[3]
				{
					new GradientAlphaKey(0f, 0f),
					new GradientAlphaKey(1f, 0.15f),
					new GradientAlphaKey(0f, 1f)
				});
				ColorOverLifetimeModule colorOverLifetime = val2.colorOverLifetime;
				((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
				((ColorOverLifetimeModule)(ref colorOverLifetime)).color = new MinMaxGradient(val3);
				SizeOverLifetimeModule sizeOverLifetime = val2.sizeOverLifetime;
				((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
				((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, AnimationCurve.Linear(0f, 1f, 1f, 0.25f));
				ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
				((Renderer)component).sharedMaterial = material;
				component.renderMode = (ParticleSystemRenderMode)0;
				((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
				((Renderer)component).receiveShadows = false;
				val2.Play();
				Object.Destroy((Object)(object)val, 1.85f);
			}
		}

		private static Material? GetMaterial()
		{
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Expected O, but got Unknown
			if (s_materialTried)
			{
				return s_material;
			}
			s_materialTried = true;
			Shader val = null;
			string text = "";
			string[] array = s_shaderNames;
			foreach (string text2 in array)
			{
				val = Shader.Find(text2);
				if ((Object)(object)val != (Object)null)
				{
					text = text2;
					break;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				GameObject val2 = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("vfx_sledge_hit") : null);
				ParticleSystemRenderer val3 = (((Object)(object)val2 != (Object)null) ? val2.GetComponentInChildren<ParticleSystemRenderer>(true) : null);
				if ((Object)(object)val3 != (Object)null && (Object)(object)((Renderer)val3).sharedMaterial != (Object)null)
				{
					val = ((Renderer)val3).sharedMaterial.shader;
					text = "borrowed from vfx_sledge_hit: " + ((Object)val).name;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				DashPlugin.Log.LogWarning((object)"No usable particle shader found; the dash motes are disabled");
				return null;
			}
			s_material = new Material(val)
			{
				mainTexture = (Texture)(object)SoftDot()
			};
			DashPlugin.Log.LogInfo((object)("Dash motes use shader '" + text + "'"));
			return s_material;
		}

		private static Texture2D SoftDot()
		{
			//IL_0086: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			Color32[] array = (Color32[])(object)new Color32[1024];
			float num = 15.5f;
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 32; j++)
				{
					Vector2 val = new Vector2((float)j - num, (float)i - num);
					float num2 = ((Vector2)(ref val)).magnitude / num;
					float num3 = Mathf.Clamp01(1f - num2);
					array[i * 32 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(num3 * num3 * 255f));
				}
			}
			Texture2D val2 = new Texture2D(32, 32, (TextureFormat)4, false)
			{
				wrapMode = (TextureWrapMode)1
			};
			val2.SetPixels32(array);
			val2.Apply();
			return val2;
		}
	}
	internal static class DashPhysics
	{
		public struct Capsule
		{
			public Vector3 Bottom;

			public Vector3 Top;

			public float Radius;

			public float Margin;
		}

		public const float Skin = 0.05f;

		private const float StepHeight = 0.35f;

		private const float MinWalkableNormalY = 0.5f;

		private const float RadiusScale = 0.9f;

		private static readonly RaycastHit[] s_hits = (RaycastHit[])(object)new RaycastHit[32];

		private static int s_solidMask;

		private static int s_characterMask;

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

		public static Capsule CapsuleOf(Player player)
		{
			//IL_000e: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_0085: 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_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_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			CapsuleCollider collider = ((Character)player).GetCollider();
			Transform transform = ((Component)collider).transform;
			Vector3 lossyScale = transform.lossyScale;
			float num = collider.radius * Mathf.Max(Mathf.Abs(lossyScale.x), Mathf.Abs(lossyScale.z));
			float num2 = Mathf.Max(0f, collider.height * Mathf.Abs(lossyScale.y) * 0.5f - num);
			Vector3 val = transform.TransformPoint(collider.center) - ((Component)player).transform.position;
			return new Capsule
			{
				Bottom = val - Vector3.up * num2,
				Top = val + Vector3.up * num2,
				Radius = num * 0.9f,
				Margin = 0.05f + num * 0.100000024f
			};
		}

		public static float HeightAboveGround(Vector3 feet)
		{
			//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)
			//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_0015: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			if (!Physics.Raycast(feet + Vector3.up * 0.1f, Vector3.down, ref val, 1000f, SolidMask, (QueryTriggerInteraction)1))
			{
				return float.PositiveInfinity;
			}
			return Mathf.Max(0f, ((RaycastHit)(ref val)).distance - 0.1f);
		}

		public static bool SlideMove(ref Vector3 pos, Vector3 move, Capsule capsule, bool stopOnAnyHit, out RaycastHit blockHit)
		{
			//IL_0002: 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_0009: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00b5: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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_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)
			blockHit = default(RaycastHit);
			Vector3 val = move;
			for (int i = 0; i < 3; i++)
			{
				float magnitude = ((Vector3)(ref move)).magnitude;
				if (magnitude < 0.0001f)
				{
					return false;
				}
				Vector3 val2 = move / magnitude;
				if (!Cast(pos, capsule, val2, magnitude + capsule.Margin, out var hit))
				{
					pos += move;
					return false;
				}
				float num = Mathf.Clamp(((RaycastHit)(ref hit)).distance - capsule.Margin, 0f, magnitude);
				pos += val2 * num;
				if (stopOnAnyHit || ((RaycastHit)(ref hit)).normal.y < 0.5f)
				{
					blockHit = hit;
					return true;
				}
				Vector3 val3 = Vector3.ProjectOnPlane(val2, ((RaycastHit)(ref hit)).normal);
				if (((Vector3)(ref val3)).sqrMagnitude < 0.0001f || Vector3.Dot(val3, val) <= 0f)
				{
					blockHit = hit;
					return true;
				}
				move = ((Vector3)(ref val3)).normalized * (magnitude - num);
			}
			return false;
		}

		public static bool GroundStep(ref Vector3 pos, Vector3 dir, float distance, Capsule capsule, out bool grounded, out RaycastHit blockHit)
		{
			//IL_0007: 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)
			//IL_003f: 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_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_0054: 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_005c: 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_0075: 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_00e0: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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)
			//IL_00b0: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			float num = 0.35f;
			if (Cast(pos, capsule, Vector3.up, num + capsule.Margin, out var hit))
			{
				num = Mathf.Clamp(((RaycastHit)(ref hit)).distance - capsule.Margin, 0f, num);
			}
			pos += Vector3.up * num;
			bool result = SlideMove(ref pos, dir * distance, capsule, stopOnAnyHit: false, out blockHit);
			float num2 = num + distance;
			if (Cast(pos, capsule, Vector3.down, num2 + capsule.Margin, out var hit2))
			{
				pos += Vector3.down * Mathf.Clamp(((RaycastHit)(ref hit2)).distance - capsule.Margin, 0f, num2);
				grounded = ((RaycastHit)(ref hit2)).normal.y >= 0.5f;
				return result;
			}
			pos += Vector3.down * num;
			grounded = false;
			return result;
		}

		public static bool SweepCreatures(Player player, Vector3 pos, Capsule capsule, Vector3 dir, float distance, bool stopAtEnemies, HashSet<Character> passed, out float hitDistance, out Character? stopper)
		{
			//IL_003b: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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)
			if (s_characterMask == 0)
			{
				s_characterMask = LayerMask.GetMask(new string[3] { "character", "character_net", "character_noenv" });
			}
			hitDistance = float.MaxValue;
			stopper = null;
			Vector3 val = pos + (capsule.Bottom + capsule.Top) * 0.5f;
			int num = Physics.CapsuleCastNonAlloc(pos + capsule.Bottom, pos + capsule.Top, capsule.Radius, dir, s_hits, distance, s_characterMask, (QueryTriggerInteraction)1);
			for (int i = 0; i < num; i++)
			{
				Character componentInParent = ((Component)((RaycastHit)(ref s_hits[i])).collider).GetComponentInParent<Character>();
				if (!((Object)(object)componentInParent == (Object)null) && !((Object)(object)componentInParent == (Object)(object)player) && !componentInParent.IsDead() && (!(((RaycastHit)(ref s_hits[i])).distance <= 0f) || !(Vector3.Dot(componentInParent.GetCenterPoint() - val, dir) <= 0f)))
				{
					if (!DashCreatures.IsLarge(componentInParent) && (!stopAtEnemies || !BaseAI.IsEnemy((Character)(object)player, componentInParent)))
					{
						passed.Add(componentInParent);
					}
					else if (((RaycastHit)(ref s_hits[i])).distance < hitDistance)
					{
						hitDistance = ((RaycastHit)(ref s_hits[i])).distance;
						stopper = componentInParent;
					}
				}
			}
			return (Object)(object)stopper != (Object)null;
		}

		public static string Describe(RaycastHit hit)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			Collider collider = ((RaycastHit)(ref hit)).collider;
			if ((Object)(object)collider == (Object)null)
			{
				return "nothing";
			}
			return $"{((Object)collider).name} (layer {LayerMask.LayerToName(((Component)collider).gameObject.layer)}, surface normal y {((RaycastHit)(ref hit)).normal.y:0.00})";
		}

		private static bool Cast(Vector3 pos, Capsule capsule, Vector3 dir, float distance, out RaycastHit hit)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			return Physics.CapsuleCast(pos + capsule.Bottom, pos + capsule.Top, capsule.Radius, dir, ref hit, distance, SolidMask, (QueryTriggerInteraction)1);
		}
	}
	[BepInPlugin("com.skaket.valheim.dash", "Dash", "0.5.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class DashPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.skaket.valheim.dash";

		public const string PluginName = "Dash";

		public const string PluginVersion = "0.5.3";

		internal static ManualLogSource Log;

		private Harmony? _harmony;

		private void Awake()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			DashConfig.Bind(((BaseUnityPlugin)this).Config);
			_harmony = new Harmony("com.skaket.valheim.dash");
			_harmony.PatchAll(typeof(DashPlugin).Assembly);
			try
			{
				DashCooldowns.Register();
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Cooldown display unavailable: {arg}");
			}
			int num = _harmony.GetPatchedMethods().Count();
			Log.LogInfo((object)string.Format("{0} {1} loaded, {2} game methods patched", "Dash", "0.5.3", num));
		}

		private void OnDestroy()
		{
			Harmony? harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}
namespace Dash.Patches
{
	internal static class DashInput
	{
		private static readonly MethodInfo s_takeInput = AccessTools.Method(typeof(Player), "TakeInput", (Type[])null, (Type[])null);

		private static bool s_mainKeyWasDown;

		public static bool InPlayerUpdate;

		public static bool PollPressed()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut value = DashConfig.DashKey.Value;
			if ((int)((KeyboardShortcut)(ref value)).MainKey == 0)
			{
				return false;
			}
			bool key = ZInput.GetKey(((KeyboardShortcut)(ref value)).MainKey, false);
			bool num = key && !s_mainKeyWasDown;
			s_mainKeyWasDown = key;
			if (num)
			{
				return ModifiersHeld(value);
			}
			return false;
		}

		public static bool IsHeld()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut value = DashConfig.DashKey.Value;
			if ((int)((KeyboardShortcut)(ref value)).MainKey != 0 && ZInput.GetKey(((KeyboardShortcut)(ref value)).MainKey, false))
			{
				return ModifiersHeld(value);
			}
			return false;
		}

		public static bool PlayerTakesInput(Player player)
		{
			return (bool)s_takeInput.Invoke(player, null);
		}

		private static bool ModifiersHeld(KeyboardShortcut shortcut)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			foreach (KeyCode modifier in ((KeyboardShortcut)(ref shortcut)).Modifiers)
			{
				if (!ZInput.GetKey(modifier, false))
				{
					return false;
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Player), "Update")]
	internal static class Player_Update_Patch
	{
		private static void Prefix(Player __instance)
		{
			if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
			{
				DashInput.InPlayerUpdate = true;
				DashController.FrameTick(__instance);
				if (DashInput.PollPressed() && DashInput.PlayerTakesInput(__instance))
				{
					DashController.OnKeyPressed(__instance);
				}
			}
		}

		private static void Postfix()
		{
			DashInput.InPlayerUpdate = false;
		}
	}
	[HarmonyPatch(typeof(Humanoid), "HideHandItems")]
	internal static class Humanoid_HideHandItems_Patch
	{
		private static bool Prefix(Humanoid __instance, ref bool __result)
		{
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || !DashInput.InPlayerUpdate || !DashInput.IsHeld())
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	[HarmonyPatch(typeof(Humanoid), "ShowHandItems")]
	internal static class Humanoid_ShowHandItems_Patch
	{
		private static bool Prefix(Humanoid __instance)
		{
			if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && DashInput.InPlayerUpdate)
			{
				return !DashInput.IsHeld();
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Character), "UpdateMotion")]
	internal static class Character_UpdateMotion_Patch
	{
		private static void Prefix(Character __instance)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			if (DashController.Active && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
			{
				DashController.CancelIfInterrupted((Player)__instance);
			}
		}
	}
	[HarmonyPatch(typeof(Character), "UpdateWalking")]
	internal static class Character_UpdateWalking_Patch
	{
		private static bool Prefix(Character __instance, float dt, ref float ___m_lastGroundTouch, ref float ___m_maxAirAltitude)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			if (!DashController.Active || (Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return true;
			}
			return !DashController.Step((Player)__instance, dt, ref ___m_lastGroundTouch, ref ___m_maxAirAltitude);
		}
	}
}