SpellBrigadeDash.dll

Decompiled 21 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Common;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppInterop.Runtime.Runtime;
using Il2CppInterop.Runtime.Runtime.VersionSpecific.MethodInfo;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using SpellBrigadeDash.Controls;
using SpellBrigadeDash.Core;
using SpellBrigadeDash.Discovery;
using SpellBrigadeDash.Fx;
using SpellBrigadeDash.Game;
using SpellBrigadeDash.Motion;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Audio;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Localization.Components;
using UnityEngine.Localization.Tables;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("SpellBrigadeDash")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.5.1.0")]
[assembly: AssemblyInformationalVersion("0.5.1+c92768cde891adc347795b6f00f69f4fcc0ca0da")]
[assembly: AssemblyProduct("SpellBrigadeDash")]
[assembly: AssemblyTitle("SpellBrigadeDash")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.5.1.0")]
[module: UnverifiableCode]
namespace SpellBrigadeDash
{
	public class DashRunner : MonoBehaviour
	{
		public DashRunner(IntPtr ptr)
			: base(ptr)
		{
		}

		public void Update()
		{
			DashSystem.Instance.Update();
		}

		public void LateUpdate()
		{
			DashSystem.Instance.LateUpdate();
		}

		public void OnApplicationQuit()
		{
			ModLog.Step("clean exit");
		}
	}
	internal sealed class DashSystem
	{
		private sealed class ActiveDash
		{
			public Vector3 Dir;

			public float Remaining;

			public float Speed;

			public float Elapsed;

			public float MaxTime;

			public float NextGhost;

			public float Travelled;

			public float NextFlameAt;

			public float FlameSpacing;

			public float NextSparkleAt;

			public float SparkleSpacing;

			public float FlameRadius;

			public float NextStreak;
		}

		private sealed class RemoteEmitter
		{
			public PlayerInfo Player { get; }

			public float Until { get; }

			public float Next { get; set; }

			public RemoteEmitter(PlayerInfo player, float until)
			{
				Player = player;
				Until = until;
			}
		}

		private const float FlameSpacingFactor = 0.22f;

		private const float GameFlameSpacingFactor = 0.42f;

		private const float SparkleSpacingFactor = 0.16f;

		private const float StreakInterval = 0.018f;

		private readonly DashInput _input = new DashInput();

		private readonly DashProgress _progress = new DashProgress();

		private readonly DashCharges _charges = new DashCharges(0, 2f);

		private readonly FxManager _fx = new FxManager();

		private readonly GameFireTrail _gameFire = new GameFireTrail();

		private readonly BlazeDamage _blaze = new BlazeDamage();

		private readonly DashBar _bar = new DashBar();

		private readonly RemoteDashDetector _remote = new RemoteDashDetector();

		private readonly List<RemoteEmitter> _remoteEmitters = new List<RemoteEmitter>();

		private readonly HashSet<long> _hookedRemotes = new HashSet<long>();

		private IReadOnlyList<DashCardDef> _cards = Array.Empty<DashCardDef>();

		private DashBaseStats _stats = new DashBaseStats();

		private Color _ghostStart;

		private Color _ghostEnd;

		private Color _dustColor;

		private Color _sparkleStart;

		private Color _sparkleEnd;

		private Color _streakColor;

		private bool _initialized;

		private ActiveDash? _active;

		private float _bufferedUntil = -1f;

		private float _discoveryAt = -1f;

		private float _hooksAt = -1f;

		private bool _hooksInstalled;

		private string? _runKey;

		private float _nextRunCheck;

		private int _remoteDashes;

		private int _localDashes;

		private readonly Random _rng = new Random();

		public static DashSystem Instance { get; } = new DashSystem();

		public PlayerLocator Locator { get; } = new PlayerLocator();

		public SoundPlayer Sound { get; } = new SoundPlayer();

		public void Update()
		{
			float time = Time.time;
			float deltaTime = Time.deltaTime;
			try
			{
				if (!_initialized)
				{
					Init();
				}
				Invulnerability.Now = time;
				ModLog.StepOnce("poll", "first frame: reading input");
				_input.Poll();
				if (ModConfig.DebugHotkeys.Value)
				{
					HandleHotkeys();
				}
				CheckRun(Time.unscaledTime);
				ModLog.StepOnce("locate", "first frame: looking for the wizard");
				Locator.Update(Time.unscaledTime);
				PlayerInfo playerInfo = Locator.Local;
				if (playerInfo != null && playerInfo.IsDestroyed)
				{
					playerInfo = null;
				}
				if (playerInfo != null)
				{
					TrackMovement(playerInfo, deltaTime);
				}
				if (playerInfo != null && !_hooksInstalled && _hooksAt > 0f && Time.unscaledTime >= _hooksAt)
				{
					InstallHooks(playerInfo);
				}
				SyncCharges();
				int num = _charges.Tick(deltaTime);
				if (num > 0)
				{
					_bar.OnRefilled(_charges, num, time);
				}
				if (playerInfo != null)
				{
					if (_input.DashPressed)
					{
						OnDashPressed(playerInfo, time);
					}
					else if (_active == null && _bufferedUntil >= time)
					{
						_bufferedUntil = -1f;
						OnDashPressed(playerInfo, time);
					}
				}
				UpdateRemotes(time);
				Invulnerability.Prune();
				CardBridge.Update(_cards, _progress, Time.unscaledTime);
				StatPanelRows.Update(_stats, _progress, Time.unscaledTime);
				DamageReference.Tick(Time.unscaledTime);
				if (_discoveryAt > 0f && Time.unscaledTime >= _discoveryAt)
				{
					_discoveryAt = -1f;
					ModLog.Step("discovery report: writing");
					DiscoveryReport.Write(this, "run started");
					ModLog.Step("discovery report: done");
				}
			}
			catch (Exception ex)
			{
				ModLog.ErrorThrottled("DashSystem.Update", ex, Time.unscaledTime);
			}
		}

		public void LateUpdate()
		{
			float time = Time.time;
			float deltaTime = Time.deltaTime;
			try
			{
				PlayerInfo playerInfo = Locator.Local;
				if (playerInfo != null && playerInfo.IsDestroyed)
				{
					playerInfo = null;
				}
				if (_active != null)
				{
					if (playerInfo == null)
					{
						_active = null;
					}
					else
					{
						StepDash(playerInfo, time, deltaTime);
					}
				}
				ModLog.StepOnce("fx", "first frame: effects + bar");
				_fx.Update(deltaTime);
				_gameFire.Update(time);
				_blaze.Update(time);
				bool allowed = playerInfo != null && Time.timeScale > 0f && !Locator.IsDead(playerInfo);
				_bar.Update(playerInfo, _charges, allowed, time, Time.unscaledDeltaTime);
				ModLog.StepOnce("frame-ok", "first frame completed");
			}
			catch (Exception ex)
			{
				ModLog.ErrorThrottled("DashSystem.LateUpdate", ex, Time.unscaledTime);
			}
		}

		private void Init()
		{
			//IL_004b: 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_0055: 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_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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			ModLog.Step("Init: start");
			_initialized = true;
			_stats = ModConfig.BaseStats();
			_cards = DashCards.Build(ModConfig.CardSettings());
			_ghostStart = FxAssets.ParseColor(ModConfig.AfterimageColor.Value, new Color(0.94f, 0.78f, 1f, 0.85f));
			_ghostEnd = FxAssets.ParseColor(ModConfig.AfterimageFadeColor.Value, new Color(0.42f, 0.17f, 1f, 0f));
			_dustColor = FxAssets.ParseColor(ModConfig.DustColor.Value, new Color(0.89f, 0.84f, 0.95f, 0.94f));
			_sparkleStart = FxAssets.ParseColor(ModConfig.SparkleColor.Value, new Color(1f, 0.88f, 1f, 1f));
			_sparkleEnd = FxAssets.ParseColor(ModConfig.SparkleFadeColor.Value, new Color(0.61f, 0.36f, 1f, 1f));
			_streakColor = FxAssets.ParseColor(ModConfig.StreakColor.Value, new Color(0.82f, 0.66f, 1f, 0.75f));
			Locator.LocalChanged += OnNewLocalPlayer;
			CardBridge.Picked = ApplyCard;
			ModLog.Step("Init: done");
		}

		private void InstallHooks(PlayerInfo p)
		{
			_hooksInstalled = true;
			if (ModConfig.SafeMode.Value)
			{
				ModLog.Info("SafeMode: skipping i-frame hooks and tracing.");
				return;
			}
			if (ModConfig.SoundEnabled.Value)
			{
				ModLog.Step("sound: preparing FMOD event");
				FmodSound.Prepare();
			}
			ModLog.Step("hooks: start");
			DamageHooks.HookConfigured();
			DamageHooks.HookFor(p);
			CardBridge.InstallPickHook();
			MethodTracer.Install();
			ModLog.Step("hooks: done");
		}

		private void OnNewLocalPlayer(PlayerInfo p)
		{
			_active = null;
			_bufferedUntil = -1f;
			_fx.Clear();
			_gameFire.Clear();
			_blaze.Clear();
			_remote.Clear();
			_remoteEmitters.Clear();
			SyncCharges();
			_charges.RefillAll();
			ModLog.Info($"Wizard spawned; dash cards this run: {_progress}.");
			DamageHooks.SetLocal(p);
			if (!_hooksInstalled)
			{
				_hooksAt = Time.unscaledTime + Math.Max(0f, ModConfig.HookDelaySeconds.Value);
			}
			else if (!ModConfig.SafeMode.Value)
			{
				DamageHooks.HookFor(p);
			}
			if (ModConfig.DiscoveryEnabled.Value)
			{
				_discoveryAt = Time.unscaledTime + Math.Max(0f, ModConfig.HookDelaySeconds.Value) + 3f;
			}
		}

		private void CheckRun(float now)
		{
			if (now < _nextRunCheck)
			{
				return;
			}
			_nextRunCheck = now + 0.5f;
			string text = GameRun.Key();
			if (text != null && !(text == _runKey))
			{
				_runKey = text;
				_stats = ModConfig.BaseStats();
				_active = null;
				_blaze.Clear();
				_progress.Reset();
				if (ModConfig.StartRunWithDash.Value)
				{
					_progress.Apply(DashCardId.Dash);
				}
				SyncCharges();
				_charges.RefillAll();
				ModLog.Info($"New run ({GameRun.Status}). Dash {(_progress.Unlocked ? "unlocked (Debug.StartRunWithDash)" : "locked until the Dash card is picked")}.");
			}
		}

		private void SyncCharges()
		{
			int num = DashTuning.MaxCharges(_stats, _progress);
			if (_charges.Max != num)
			{
				bool num2 = _charges.Max == 0 && num > 0;
				_charges.SetMax(num);
				if (num2)
				{
					_charges.RefillAll();
				}
			}
			_charges.RechargeSeconds = DashTuning.RechargeSeconds(_stats, _progress);
		}

		private void OnDashPressed(PlayerInfo p, float now)
		{
			if (Time.timeScale <= 0f || !_progress.Unlocked || Locator.IsDead(p))
			{
				return;
			}
			if (_active != null)
			{
				float num = _active.Remaining / Math.Max(0.01f, _active.Speed);
				if (num <= ModConfig.InputBuffer.Value)
				{
					_bufferedUntil = now + num + 0.05f;
				}
			}
			else if (!_charges.TryConsume())
			{
				_bar.OnEmptyPress(now);
			}
			else
			{
				StartDash(p, now);
			}
		}

		private void StartDash(PlayerInfo p, float now)
		{
			//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_003c: 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_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_0189: 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_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			ModLog.StepOnce("first-dash", "first dash");
			Vector3 val = ResolveDirection(p);
			float num = DashTuning.Distance(_stats, _progress);
			float num2 = DashTuning.Duration(_stats);
			_active = new ActiveDash
			{
				Dir = val,
				Remaining = num,
				Speed = num / num2,
				MaxTime = num2 * 2f + 0.05f,
				FlameSpacing = Math.Max(0.05f, p.VisualSize * (_gameFire.Usable ? 0.42f : 0.22f)),
				FlameRadius = (DashTuning.Blazing(_progress) ? _blaze.FlameRadius(p, now) : 0f),
				SparkleSpacing = Math.Max(0.05f, p.VisualSize * 0.16f)
			};
			_localDashes++;
			float num3 = DashTuning.InvulnerableSeconds(_stats);
			Invulnerability.Grant(p, num3);
			NetBridge.SendDash(num3);
			float num4 = HealthBridge.ApplyCost(p, DashTuning.HealthCostFraction(_stats, _progress));
			if (num4 > 0f)
			{
				ModLog.Debug($"Dash cost {num4:0.#} HP.");
			}
			_bar.OnDash(now);
			if (ModConfig.DustPuff.Value)
			{
				_fx.SpawnPuff(p, p.Feet, val, _dustColor, 1f);
			}
			if (ModConfig.Afterimages.Value)
			{
				_fx.SpawnAfterimage(p, _ghostStart, _ghostEnd, ModConfig.AfterimageLifetime.Value);
			}
			_active.NextGhost = ModConfig.AfterimageInterval.Value;
			Sound.Play(_fx.Root, p.Feet, now);
			if (DashTuning.Blazing(_progress) && ModConfig.SoundEnabled.Value)
			{
				FmodSound.PlayEvent(ModConfig.BlazingFmodEvent.Value, p.Feet);
			}
			GameFx.TeleportBurst(p);
			GameFx.SpeedLines(p, (Object)(object)_fx.Root, on: true);
		}

		private static Vector3 BodyCenter(PlayerInfo p)
		{
			//IL_0001: 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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			return p.Feet + (Vector3)(p.Is2D ? new Vector3(0f, p.VisualSize * 0.45f, 0f) : (Vector3.up * p.VisualSize * 0.45f));
		}

		private static Vector3 RandomInBody(PlayerInfo p, Random rng)
		{
			//IL_001c: 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_0029: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			float num = p.VisualSize * (0.1f + 0.8f * (float)rng.NextDouble());
			return p.Feet + (Vector3)(p.Is2D ? new Vector3(0f, num, 0f) : (Vector3.up * num));
		}

		private void StepDash(PlayerInfo p, float now, float dt)
		{
			//IL_0043: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: 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_010b: 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_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: 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_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: 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_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: 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_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: 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_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_01fe: 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_022c: Unknown result type (might be due to invalid IL or missing references)
			ActiveDash active = _active;
			if (dt <= 0f)
			{
				return;
			}
			active.Elapsed += dt;
			float num = Math.Min(active.Speed * dt, active.Remaining);
			float num2 = ((num > 0f) ? DashMotor.Move(p, active.Dir, num) : 0f);
			active.Remaining -= num;
			active.Travelled += num2;
			if (ModConfig.Afterimages.Value && active.Elapsed >= active.NextGhost)
			{
				_fx.SpawnAfterimage(p, _ghostStart, _ghostEnd, ModConfig.AfterimageLifetime.Value);
				active.NextGhost = active.Elapsed + Math.Max(0.01f, ModConfig.AfterimageInterval.Value);
			}
			if (ModConfig.SpeedStreaks.Value && active.Elapsed >= active.NextStreak)
			{
				Vector3 bodyCenter = BodyCenter(p);
				_fx.SpawnStreak(p, bodyCenter, active.Dir, _streakColor);
				_fx.SpawnStreak(p, bodyCenter, active.Dir, _streakColor);
				active.NextStreak = active.Elapsed + 0.018f;
			}
			if (ModConfig.Sparkles.Value)
			{
				while (active.Travelled >= active.NextSparkleAt)
				{
					float num3 = active.Travelled - active.NextSparkleAt;
					_fx.SpawnSparkle(p, RandomInBody(p, _rng) - active.Dir * num3, _sparkleStart, _sparkleEnd);
					active.NextSparkleAt += active.SparkleSpacing;
				}
			}
			if (DashTuning.Blazing(_progress))
			{
				Vector3 feet = p.Feet;
				float value = ModConfig.BlazingTrailSeconds.Value;
				while (active.Travelled >= active.NextFlameAt)
				{
					float num4 = active.Travelled - active.NextFlameAt;
					Vector3 val = feet - active.Dir * num4;
					if (!_gameFire.TrySpawn(p, val, _fx.Root.transform, value, now, _blaze.SizeMultiplier))
					{
						_fx.SpawnFlame(p, val, value);
					}
					_blaze.AddFlame(val, active.FlameRadius, now + value);
					active.NextFlameAt += active.FlameSpacing;
				}
			}
			bool flag = num > 0.0001f && num2 < num * 0.3f;
			if (active.Remaining <= 0.0001f || flag || active.Elapsed >= active.MaxTime)
			{
				EndDash(p);
			}
		}

		private void EndDash(PlayerInfo p)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_0069: 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)
			ActiveDash active = _active;
			_active = null;
			GameFx.SpeedLines(p, (Object)(object)_fx.Root, on: false);
			if (ModConfig.DustPuffOnLanding.Value)
			{
				_fx.SpawnPuff(p, p.Feet, active.Dir, _dustColor, 0.6f);
			}
			if (ModConfig.Sparkles.Value)
			{
				_fx.SpawnSparkleBurst(p, BodyCenter(p), _sparkleStart, _sparkleEnd, 8);
			}
		}

		private Vector3 ResolveDirection(PlayerInfo p)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: 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_0049: 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_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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: 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_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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: 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_00de: 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_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_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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_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_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			Vector2 move = _input.Move;
			if (((Vector2)(ref move)).sqrMagnitude > 0.04f)
			{
				((Vector2)(ref move)).Normalize();
				if (p.Is2D)
				{
					return new Vector3(move.x, move.y, 0f);
				}
				Vector3 val = Vector3.forward;
				Vector3 right = Vector3.right;
				Camera main = Camera.main;
				if ((Object)(object)main != (Object)null)
				{
					Transform transform = ((Component)main).transform;
					val = transform.forward;
					val.y = 0f;
					if (((Vector3)(ref val)).sqrMagnitude < 0.0001f)
					{
						val = transform.up;
						val.y = 0f;
					}
					((Vector3)(ref val)).Normalize();
					right = transform.right;
					right.y = 0f;
					((Vector3)(ref right)).Normalize();
				}
				Vector3 val2 = val * move.y + right * move.x;
				return ((Vector3)(ref val2)).normalized;
			}
			if (((Vector3)(ref p.LastMoveDir)).sqrMagnitude > 0.01f)
			{
				return p.LastMoveDir;
			}
			if (p.Is2D)
			{
				Renderer? mainRenderer = p.MainRenderer;
				SpriteRenderer val3 = ((mainRenderer != null) ? ((Il2CppObjectBase)mainRenderer).TryCast<SpriteRenderer>() : null);
				float num = (((Object)(object)val3 != (Object)null && val3.flipX) ? (-1f) : 1f);
				if (p.RootT.lossyScale.x < 0f)
				{
					num = 0f - num;
				}
				return new Vector3(num, 0f, 0f);
			}
			Vector3 forward = p.RootT.forward;
			forward.y = 0f;
			if (!(((Vector3)(ref forward)).sqrMagnitude > 0.0001f))
			{
				return Vector3.forward;
			}
			return ((Vector3)(ref forward)).normalized;
		}

		private void TrackMovement(PlayerInfo p, float dt)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: 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_002d: 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)
			//IL_0039: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = p.RootT.position;
			if (p.HasLastPos && dt > 0f && _active == null)
			{
				Vector3 val = position - p.LastPos;
				if (p.Is2D)
				{
					val.z = 0f;
				}
				else
				{
					val.y = 0f;
				}
				float num = ((Vector3)(ref val)).magnitude / dt;
				if (num > 0.3f)
				{
					p.LastMoveDir = ((Vector3)(ref val)).normalized;
					if (num < _stats.Distance / DashTuning.Duration(_stats) * 0.5f)
					{
						p.MaxWalkSpeed = Math.Max(p.MaxWalkSpeed, num);
					}
				}
			}
			p.LastPos = position;
			p.HasLastPos = true;
		}

		private void UpdateRemotes(float now)
		{
			//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_00d1: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			bool value = ModConfig.RemoteIFrames.Value;
			bool value2 = ModConfig.RemoteAfterimages.Value;
			if (!value && !value2)
			{
				return;
			}
			float num = _stats.Distance / DashTuning.Duration(_stats);
			_remote.SpeedThreshold = num * ModConfig.RemoteDashSpeedFactor.Value;
			_remote.MaxJump = _stats.Distance * 4f;
			foreach (PlayerInfo remote in Locator.Remotes)
			{
				if (remote.IsDestroyed)
				{
					continue;
				}
				if (_hooksInstalled && _hookedRemotes.Add(remote.Id))
				{
					DamageHooks.HookFor(remote);
				}
				Vector3 position = remote.RootT.position;
				if (_remote.Observe(remote.Id, new Vector3(position.x, position.y, position.z), now))
				{
					_remoteDashes++;
					if (value)
					{
						Invulnerability.Grant(remote, DashTuning.InvulnerableSeconds(_stats) + 0.1f);
					}
					if (value2)
					{
						_remoteEmitters.Add(new RemoteEmitter(remote, now + DashTuning.Duration(_stats)));
					}
				}
			}
			for (int num2 = _remoteEmitters.Count - 1; num2 >= 0; num2--)
			{
				RemoteEmitter remoteEmitter = _remoteEmitters[num2];
				if (remoteEmitter.Player.IsDestroyed || now > remoteEmitter.Until)
				{
					_remoteEmitters.RemoveAt(num2);
				}
				else if (!(now < remoteEmitter.Next))
				{
					_fx.SpawnAfterimage(remoteEmitter.Player, _ghostStart, _ghostEnd, ModConfig.AfterimageLifetime.Value);
					remoteEmitter.Next = now + Math.Max(0.02f, ModConfig.AfterimageInterval.Value);
				}
			}
			_remote.Prune(now);
		}

		private void HandleHotkeys()
		{
			if (_input.DebugPressed(DebugKey.Report))
			{
				ModLog.Step("discovery report (hotkey): writing");
				DiscoveryReport.Write(this, "hotkey");
				ModLog.Step("discovery report (hotkey): done");
			}
			if (_input.DebugPressed(DebugKey.ToggleDash))
			{
				if (_progress.Unlocked)
				{
					_progress.Lock();
				}
				else
				{
					_progress.Apply(DashCardId.Dash);
				}
				ModLog.Info("[debug] Dash " + (_progress.Unlocked ? "unlocked" : "locked") + ".");
			}
			if (_input.DebugPressed(DebugKey.ExtraCharge))
			{
				ApplyCard(DashCardId.ExtraCharge);
			}
			if (_input.DebugPressed(DebugKey.QuickRecovery))
			{
				ApplyCard(DashCardId.QuickRecovery);
			}
			if (_input.DebugPressed(DebugKey.LongStride))
			{
				ApplyCard(DashCardId.LongStride);
			}
			if (_input.DebugPressed(DebugKey.BlazingDash))
			{
				ApplyCard(DashCardId.BlazingDash);
			}
			if (_input.DebugPressed(DebugKey.EtherealStep))
			{
				ApplyCard(DashCardId.EtherealStep);
			}
		}

		public void ApplyCard(DashCardId id)
		{
			DashCardDef dashCardDef = _cards.FirstOrDefault((DashCardDef c) => c.Id == id);
			if (dashCardDef != null)
			{
				if (id != DashCardId.Dash && !_progress.Unlocked)
				{
					_progress.Apply(DashCardId.Dash);
				}
				if (!DashCards.IsAvailable(dashCardDef, _progress))
				{
					ModLog.Info($"[cards] {dashCardDef.Title} is at its limit ({_progress.Stacks(id)}/{dashCardDef.MaxStacks}).");
					return;
				}
				_progress.Apply(id);
				SyncCharges();
				ModLog.Info($"[cards] {dashCardDef.Title} ({dashCardDef.Rarity}) applied. Run upgrades: {_progress}. Charges {_charges.Max}, recharge {_charges.RechargeSeconds:0.00}s, distance {DashTuning.Distance(_stats, _progress):0.00}.");
			}
		}

		public void AppendStatus(StringBuilder sb)
		{
			StringBuilder stringBuilder = sb;
			StringBuilder stringBuilder2 = stringBuilder;
			StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder);
			handler.AppendLiteral("Input backend: ");
			handler.AppendFormatted(_input.BackendName);
			stringBuilder2.AppendLine(ref handler);
			stringBuilder = sb;
			StringBuilder stringBuilder3 = stringBuilder;
			handler = new StringBuilder.AppendInterpolatedStringHandler(27, 2, stringBuilder);
			handler.AppendLiteral("Run upgrades: ");
			handler.AppendFormatted(_progress);
			handler.AppendLiteral("   unlocked: ");
			handler.AppendFormatted(_progress.Unlocked);
			stringBuilder3.AppendLine(ref handler);
			stringBuilder = sb;
			StringBuilder stringBuilder4 = stringBuilder;
			handler = new StringBuilder.AppendInterpolatedStringHandler(33, 4, stringBuilder);
			handler.AppendLiteral("Charges: ");
			handler.AppendFormatted(_charges.Full);
			handler.AppendLiteral("/");
			handler.AppendFormatted(_charges.Max);
			handler.AppendLiteral("  progress ");
			handler.AppendFormatted(_charges.Progress, "0.00");
			handler.AppendLiteral("  recharge ");
			handler.AppendFormatted(_charges.RechargeSeconds, "0.00");
			handler.AppendLiteral("s");
			stringBuilder4.AppendLine(ref handler);
			stringBuilder = sb;
			StringBuilder stringBuilder5 = stringBuilder;
			handler = new StringBuilder.AppendInterpolatedStringHandler(39, 3, stringBuilder);
			handler.AppendLiteral("Dash: distance ");
			handler.AppendFormatted(DashTuning.Distance(_stats, _progress), "0.00");
			handler.AppendLiteral("  duration ");
			handler.AppendFormatted(DashTuning.Duration(_stats), "0.000");
			handler.AppendLiteral("s  i-frames ");
			handler.AppendFormatted(DashTuning.InvulnerableSeconds(_stats), "0.000");
			handler.AppendLiteral("s");
			stringBuilder5.AppendLine(ref handler);
			stringBuilder = sb;
			StringBuilder stringBuilder6 = stringBuilder;
			handler = new StringBuilder.AppendInterpolatedStringHandler(53, 2, stringBuilder);
			handler.AppendLiteral("Dashes this session: yours ");
			handler.AppendFormatted(_localDashes);
			handler.AppendLiteral(", other players' detected ");
			handler.AppendFormatted(_remoteDashes);
			stringBuilder6.AppendLine(ref handler);
			stringBuilder = sb;
			StringBuilder stringBuilder7 = stringBuilder;
			handler = new StringBuilder.AppendInterpolatedStringHandler(5, 1, stringBuilder);
			handler.AppendLiteral("Run: ");
			handler.AppendFormatted(GameRun.Status);
			stringBuilder7.AppendLine(ref handler);
			stringBuilder = sb;
			StringBuilder stringBuilder8 = stringBuilder;
			handler = new StringBuilder.AppendInterpolatedStringHandler(13, 1, stringBuilder);
			handler.AppendLiteral("Card bridge: ");
			handler.AppendFormatted(CardBridge.Status);
			stringBuilder8.AppendLine(ref handler);
			stringBuilder = sb;
			StringBuilder stringBuilder9 = stringBuilder;
			handler = new StringBuilder.AppendInterpolatedStringHandler(18, 1, stringBuilder);
			handler.AppendLiteral("Stats panel rows: ");
			handler.AppendFormatted(StatPanelRows.Status);
			stringBuilder9.AppendLine(ref handler);
			foreach (string item in CardBridge.Log)
			{
				sb.AppendLine("  " + item.Replace("\n", "\n  "));
			}
			sb.AppendLine("Card catalogue:");
			foreach (DashCardDef card in _cards)
			{
				stringBuilder = sb;
				StringBuilder stringBuilder10 = stringBuilder;
				handler = new StringBuilder.AppendInterpolatedStringHandler(33, 5, stringBuilder);
				handler.AppendLiteral("  ");
				handler.AppendFormatted<string>(card.Title, -16);
				handler.AppendLiteral(" ");
				handler.AppendFormatted<string>(card.Rarity, -10);
				handler.AppendLiteral(" max ");
				handler.AppendFormatted(card.MaxStacks);
				handler.AppendLiteral("  taken ");
				handler.AppendFormatted(_progress.Stacks(card.Id));
				handler.AppendLiteral("  offerable now: ");
				handler.AppendFormatted(DashCards.IsAvailable(card, _progress));
				stringBuilder10.AppendLine(ref handler);
			}
			stringBuilder = sb;
			StringBuilder stringBuilder11 = stringBuilder;
			handler = new StringBuilder.AppendInterpolatedStringHandler(12, 1, stringBuilder);
			handler.AppendLiteral("Dash sound: ");
			handler.AppendFormatted(Sound.Status);
			stringBuilder11.AppendLine(ref handler);
			stringBuilder = sb;
			StringBuilder stringBuilder12 = stringBuilder;
			handler = new StringBuilder.AppendInterpolatedStringHandler(14, 1, stringBuilder);
			handler.AppendLiteral("Game effects: ");
			handler.AppendFormatted(GameFx.Status);
			stringBuilder12.AppendLine(ref handler);
			stringBuilder = sb;
			StringBuilder stringBuilder13 = stringBuilder;
			handler = new StringBuilder.AppendInterpolatedStringHandler(20, 1, stringBuilder);
			handler.AppendLiteral("Blazing Dash trail: ");
			handler.AppendFormatted(_gameFire.Status);
			stringBuilder13.AppendLine(ref handler);
			stringBuilder = sb;
			StringBuilder stringBuilder14 = stringBuilder;
			handler = new StringBuilder.AppendInterpolatedStringHandler(21, 1, stringBuilder);
			handler.AppendLiteral("Blazing Dash damage: ");
			handler.AppendFormatted(_blaze.Status);
			stringBuilder14.AppendLine(ref handler);
			stringBuilder = sb;
			StringBuilder stringBuilder15 = stringBuilder;
			handler = new StringBuilder.AppendInterpolatedStringHandler(13, 1, stringBuilder);
			handler.AppendLiteral("Wall checks: ");
			handler.AppendFormatted(DashMotor.Describe());
			stringBuilder15.AppendLine(ref handler);
			stringBuilder = sb;
			StringBuilder stringBuilder16 = stringBuilder;
			handler = new StringBuilder.AppendInterpolatedStringHandler(35, 2, stringBuilder);
			handler.AppendLiteral("Dash HP cost: ");
			handler.AppendFormatted(DashTuning.HealthCostFraction(_stats, _progress) * 100f, "0.#");
			handler.AppendLiteral("% of max HP; health: ");
			handler.AppendFormatted(HealthBridge.Status);
			stringBuilder16.AppendLine(ref handler);
		}
	}
	internal static class ModConfig
	{
		public static ConfigEntry<float> Distance;

		public static ConfigEntry<float> Duration;

		public static ConfigEntry<int> Charges;

		public static ConfigEntry<float> RechargeSeconds;

		public static ConfigEntry<float> IFrameGrace;

		public static ConfigEntry<bool> PassThroughEnemies;

		public static ConfigEntry<string> EnemyLayerHints;

		public static ConfigEntry<float> InputBuffer;

		public static ConfigEntry<float> HealthCostPercent;

		public static ConfigEntry<string> BlockingLayers;

		public static ConfigEntry<bool> StayOnNavMesh;

		public static ConfigEntry<string> KeyboardBinding;

		public static ConfigEntry<string> GamepadBinding;

		public static ConfigEntry<string> LegacyKey;

		public static ConfigEntry<string> LegacyGamepadKey;

		public static ConfigEntry<bool> BarAutoHide;

		public static ConfigEntry<float> BarHideDelay;

		public static ConfigEntry<float> BarWidth;

		public static ConfigEntry<float> BarHeight;

		public static ConfigEntry<float> BarOffset;

		public static ConfigEntry<float> BarScale;

		public static ConfigEntry<string> BarFillColor;

		public static ConfigEntry<string> BarChargingColor;

		public static ConfigEntry<string> BarBackColor;

		public static ConfigEntry<string> BarFlashColor;

		public static ConfigEntry<string> BarEmptyColor;

		public static ConfigEntry<int> BarSortingOrder;

		public static ConfigEntry<bool> BarRounded;

		public static ConfigEntry<string> BarSpriteName;

		public static ConfigEntry<bool> Afterimages;

		public static ConfigEntry<float> AfterimageInterval;

		public static ConfigEntry<float> AfterimageLifetime;

		public static ConfigEntry<string> AfterimageColor;

		public static ConfigEntry<string> AfterimageFadeColor;

		public static ConfigEntry<bool> Sparkles;

		public static ConfigEntry<string> SparkleColor;

		public static ConfigEntry<string> SparkleFadeColor;

		public static ConfigEntry<bool> SpeedStreaks;

		public static ConfigEntry<string> StreakColor;

		public static ConfigEntry<bool> DustPuff;

		public static ConfigEntry<bool> DustPuffOnLanding;

		public static ConfigEntry<string> DustColor;

		public static ConfigEntry<bool> BarFeedback;

		public static ConfigEntry<bool> RemoteAfterimages;

		public static ConfigEntry<bool> GameTeleportBurst;

		public static ConfigEntry<bool> GameSpeedLines;

		public static ConfigEntry<bool> GameFireTrail;

		public static ConfigEntry<float> GameFireScale;

		public static ConfigEntry<string> GameFireTheme;

		public static ConfigEntry<bool> SoundEnabled;

		public static ConfigEntry<string> SoundClipName;

		public static ConfigEntry<string> SoundClipHints;

		public static ConfigEntry<float> SoundVolume;

		public static ConfigEntry<string> SoundFmodEvent;

		public static ConfigEntry<string> BlazingFmodEvent;

		public static ConfigEntry<string> UnlockRarity;

		public static ConfigEntry<float> UnlockWeight;

		public static ConfigEntry<string> ExtraChargeRarity;

		public static ConfigEntry<int> ExtraChargeMaxStacks;

		public static ConfigEntry<string> QuickRecoveryRarity;

		public static ConfigEntry<int> QuickRecoveryMaxStacks;

		public static ConfigEntry<float> QuickRecoveryPerStack;

		public static ConfigEntry<string> LongStrideRarity;

		public static ConfigEntry<int> LongStrideMaxStacks;

		public static ConfigEntry<float> LongStridePerStack;

		public static ConfigEntry<string> BlazingDashRarity;

		public static ConfigEntry<float> BlazingDashDamage;

		public static ConfigEntry<float> BlazingTrailSeconds;

		public static ConfigEntry<string> EtherealStepRarity;

		public static ConfigEntry<bool> ShopCards;

		public static ConfigEntry<bool> StatsPanelRows;

		public static ConfigEntry<bool> RemoteIFrames;

		public static ConfigEntry<float> RemoteDashSpeedFactor;

		public static ConfigEntry<string> PlayerComponent;

		public static ConfigEntry<string> LocalPlayerMembers;

		public static ConfigEntry<string> DeadMembers;

		public static ConfigEntry<string> DamageMethods;

		public static ConfigEntry<bool> AutoDamageHooks;

		public static ConfigEntry<string> HealthMembers;

		public static ConfigEntry<string> MaxHealthMembers;

		public static ConfigEntry<bool> DiscoveryEnabled;

		public static ConfigEntry<bool> TraceLevelUpMethods;

		public static ConfigEntry<int> TraceMaxMethods;

		public static ConfigEntry<bool> SafeMode;

		public static ConfigEntry<float> HookDelaySeconds;

		public static ConfigEntry<bool> StartRunWithDash;

		public static ConfigEntry<bool> ShopCardTestMode;

		public static ConfigEntry<bool> DebugHotkeys;

		public static ConfigEntry<string> HotkeyModifier;

		public static ConfigEntry<string> KeyReport;

		public static ConfigEntry<string> KeyToggleDash;

		public static ConfigEntry<string> KeyExtraCharge;

		public static ConfigEntry<string> KeyQuickRecovery;

		public static ConfigEntry<string> KeyLongStride;

		public static ConfigEntry<string> KeyBlazingDash;

		public static ConfigEntry<string> KeyEtherealStep;

		private const int CurrentConfigVersion = 10;

		public static ConfigEntry<int> ConfigVersion;

		public static void Init(ConfigFile cfg)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Expected O, but got Unknown
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Expected O, but got Unknown
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Expected O, but got Unknown
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Expected O, but got Unknown
			//IL_065b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0665: Expected O, but got Unknown
			//IL_070b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0715: Expected O, but got Unknown
			//IL_0978: Unknown result type (might be due to invalid IL or missing references)
			//IL_0982: Expected O, but got Unknown
			Distance = cfg.Bind<float>("Dash", "Distance", 3f, new ConfigDescription("How far one dash goes, in world units.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 20f), Array.Empty<object>()));
			Duration = cfg.Bind<float>("Dash", "Duration", 0.12f, new ConfigDescription("How long one dash takes, in seconds. Lower = snappier.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.03f, 1f), Array.Empty<object>()));
			Charges = cfg.Bind<int>("Dash", "Charges", 1, new ConfigDescription("Bar segments once the dash is unlocked (before +1 Charge cards).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 6), Array.Empty<object>()));
			RechargeSeconds = cfg.Bind<float>("Dash", "RechargeSeconds", 15f, new ConfigDescription("Seconds to refill ONE segment (Quick Recovery cards make it faster).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 60f), Array.Empty<object>()));
			IFrameGrace = cfg.Bind<float>("Dash", "IFrameGraceSeconds", 0.08f, new ConfigDescription("Extra invulnerability after the dash ends (the dash itself is always invulnerable).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			PassThroughEnemies = cfg.Bind<bool>("Dash", "PassThroughEnemies", false, "If true, enemies never stop a dash. If false, the dash collides with whatever your wizard collides with while walking.");
			EnemyLayerHints = cfg.Bind<string>("Dash", "EnemyLayerHints", "enemy,enemies,monster,mob", "Comma-separated words. Physics layers whose name contains one of them count as 'enemy' for PassThroughEnemies.");
			InputBuffer = cfg.Bind<float>("Dash", "InputBufferSeconds", 0.1f, new ConfigDescription("Pressing dash this long before the current dash ends queues the next one.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 0.5f), Array.Empty<object>()));
			BlockingLayers = cfg.Bind<string>("Dash", "BlockingLayers", "Obstacles,TargetableObstacles", "Comma-separated physics layer names that stop a dash (3D). The game's walls and rocks are on 'Obstacles'. Empty = use the collision matrix.");
			StayOnNavMesh = cfg.Bind<bool>("Dash", "StayOnNavMesh", true, "Stop the dash at the edge of the walkable area (the NavMesh), so you can't dash out of the arena.");
			HealthCostPercent = cfg.Bind<float>("Dash", "HealthCostPercent", 5f, new ConfigDescription("Percent of max HP each dash costs until you pick the Legendary 'Ethereal Step' card. Never takes your last HP. 0 = free.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 50f), Array.Empty<object>()));
			KeyboardBinding = cfg.Bind<string>("Controls", "KeyboardBinding", "<Keyboard>/space", "Input System control path for the keyboard dash key, e.g. <Keyboard>/space, <Keyboard>/leftAlt, <Mouse>/rightButton. (Not Shift: the game uses it for the stats panel.)");
			GamepadBinding = cfg.Bind<string>("Controls", "GamepadBinding", "<Gamepad>/leftShoulder", "Input System control path for the gamepad dash button, e.g. <Gamepad>/leftShoulder, <Gamepad>/leftTrigger, <Gamepad>/buttonEast. Empty = no gamepad dash.");
			LegacyKey = cfg.Bind<string>("Controls", "LegacyKey", "Space", "Only used if the game doesn't use Unity's new Input System: a UnityEngine.KeyCode name.");
			LegacyGamepadKey = cfg.Bind<string>("Controls", "LegacyGamepadKey", "JoystickButton4", "Only used if the game doesn't use Unity's new Input System: KeyCode for the gamepad button (JoystickButton4 = LB on Xbox pads).");
			BarAutoHide = cfg.Bind<bool>("Bar", "AutoHide", true, "Fade the bar out when all charges are full.");
			BarHideDelay = cfg.Bind<float>("Bar", "HideDelaySeconds", 1f, "How long the bar stays visible after it is full again.");
			BarWidth = cfg.Bind<float>("Bar", "Width", 56f, "Total bar width in pixels at 1080p.");
			BarHeight = cfg.Bind<float>("Bar", "Height", 8f, "Bar height in pixels at 1080p.");
			BarOffset = cfg.Bind<float>("Bar", "OffsetBelowFeet", 14f, "Pixels (at 1080p) between the wizard's feet and the bar.");
			BarScale = cfg.Bind<float>("Bar", "Scale", 1f, new ConfigDescription("Overall bar size multiplier.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.25f, 4f), Array.Empty<object>()));
			BarFillColor = cfg.Bind<string>("Bar", "FillColor", "#B57BFFFF", "Colour of full segments (#RRGGBB or #RRGGBBAA).");
			BarChargingColor = cfg.Bind<string>("Bar", "ChargingColor", "#6A45B8FF", "Colour of the segment that is refilling.");
			BarBackColor = cfg.Bind<string>("Bar", "BackgroundColor", "#150C26D0", "Background / frame colour.");
			BarFlashColor = cfg.Bind<string>("Bar", "FlashColor", "#FFFFFFFF", "Flash colour when a segment refills.");
			BarEmptyColor = cfg.Bind<string>("Bar", "EmptyPressColor", "#FF4A4AFF", "Flash colour when you press dash with no charges.");
			BarSortingOrder = cfg.Bind<int>("Bar", "SortingOrder", -50, "Canvas sorting order. Negative = drawn below the game's own UI (menus cover the bar). Raise it if the bar is hidden behind the HUD.");
			BarRounded = cfg.Bind<bool>("Bar", "Rounded", true, "Rounded (pill-shaped) frame and segments, like the game's own bars.");
			BarSpriteName = cfg.Bind<string>("Bar", "GameSpriteName", "", "Optional: name of one of the game's own UI sprites to draw the bar with (see section 15 of the discovery report). Empty = built-in rounded shape.");
			Afterimages = cfg.Bind<bool>("Effects", "Afterimages", true, "Leave fading copies of the wizard along the dash path.");
			AfterimageInterval = cfg.Bind<float>("Effects", "AfterimageInterval", 0.02f, "Seconds between afterimages during a dash.");
			AfterimageLifetime = cfg.Bind<float>("Effects", "AfterimageLifetime", 0.35f, "Seconds an afterimage takes to fade.");
			AfterimageColor = cfg.Bind<string>("Effects", "AfterimageColor", "#F0C8FFD8", "Afterimage colour when it appears (alpha = starting opacity). It glows from this...");
			AfterimageFadeColor = cfg.Bind<string>("Effects", "AfterimageFadeColor", "#6A2CFF00", "...to this colour as it fades out.");
			Sparkles = cfg.Bind<bool>("Effects", "Sparkles", true, "Arcane sparkles left along the dash path, plus a small burst on landing.");
			SparkleColor = cfg.Bind<string>("Effects", "SparkleColor", "#FFE0FFFF", "Sparkle colour when it appears.");
			SparkleFadeColor = cfg.Bind<string>("Effects", "SparkleFadeColor", "#9B5CFFFF", "Sparkle colour as it twinkles out.");
			SpeedStreaks = cfg.Bind<bool>("Effects", "SpeedStreaks", true, "Thin light streaks behind the wizard while dashing.");
			StreakColor = cfg.Bind<string>("Effects", "StreakColor", "#D2A8FFC0", "Speed streak colour.");
			DustPuff = cfg.Bind<bool>("Effects", "DustPuff", true, "Dust burst where the dash starts.");
			DustPuffOnLanding = cfg.Bind<bool>("Effects", "DustPuffOnLanding", true, "Smaller dust burst where the dash ends.");
			DustColor = cfg.Bind<string>("Effects", "DustColor", "#E2D6F2F0", "Dust colour.");
			BarFeedback = cfg.Bind<bool>("Effects", "BarFeedback", true, "Segments flash when refilled; the bar shakes red on an empty press.");
			RemoteAfterimages = cfg.Bind<bool>("Effects", "RemoteAfterimages", true, "Show afterimages when other (modded) players dash.");
			GameTeleportBurst = cfg.Bind<bool>("Effects", "GameTeleportBurst", true, "Also play the game's own teleport sparkle burst when you dash.");
			GameSpeedLines = cfg.Bind<bool>("Effects", "GameSpeedLines", true, "Also show the game's own fast-running speed lines during the dash.");
			GameFireTrail = cfg.Bind<bool>("Effects", "GameFireTrail", true, "Blazing Dash leaves the game's own fire (the burning effect wizards get) along the path. Off = the mod's own sprite flames.");
			GameFireScale = cfg.Bind<float>("Effects", "GameFireScale", 0.9f, new ConfigDescription("Size of each game fire in the Blazing Dash trail (1 = as big as on a burning wizard).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 3f), Array.Empty<object>()));
			GameFireTheme = cfg.Bind<string>("Effects", "GameFireTheme", "Fire", "Which of the game's fire looks the trail uses: Fire, or FireDouble (the game's stronger double-fire look).");
			SoundEnabled = cfg.Bind<bool>("Sound", "Enabled", true, "Play a sound on dash, reusing one of the game's own sounds.");
			SoundClipName = cfg.Bind<string>("Sound", "ClipName", "", "Exact AudioClip name to use (see the discovery report for the list). Empty = pick automatically using ClipNameHints.");
			SoundClipHints = cfg.Bind<string>("Sound", "ClipNameHints", "dash,dodge,blink,teleport,whoosh,woosh,swoosh,swish", "Comma-separated words, in priority order, used to pick a game sound automatically.");
			SoundVolume = cfg.Bind<float>("Sound", "Volume", 0.7f, new ConfigDescription("Dash sound volume (Unity audio only; FMOD events use the game's volume).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			SoundFmodEvent = cfg.Bind<string>("Sound", "FmodEvent", "auto", "The game plays sound through FMOD. 'auto' = pick an event whose path matches ClipNameHints. Or an exact path like event:/... (section 17 of the discovery report lists them all).");
			BlazingFmodEvent = cfg.Bind<string>("Sound", "BlazingFmodEvent", "event:/Elements/Fire/SFX_Element_Fire_Cast", "Extra FMOD event played when a Blazing Dash lights its trail (the game's fire-spell cast sound). Empty = none.");
			UnlockRarity = cfg.Bind<string>("Upgrades", "DashUnlockRarity", "Epic", "Rarity of the card that unlocks the dash (the game's rarity name).");
			UnlockWeight = cfg.Bind<float>("Upgrades", "DashUnlockWeight", 5f, "Copies of the Dash card in the level-up shop (1 = as likely as any one game card of its rarity). 5 by default: with 1, an Epic Dash card showed up about once in three runs. The upgrade cards have one copy each.");
			ExtraChargeRarity = cfg.Bind<string>("Upgrades", "ExtraChargeRarity", "Legendary", "Rarity of '+1 Dash Charge'.");
			ExtraChargeMaxStacks = cfg.Bind<int>("Upgrades", "ExtraChargeMaxStacks", 2, "How many times '+1 Dash Charge' can be taken per run.");
			QuickRecoveryRarity = cfg.Bind<string>("Upgrades", "QuickRecoveryRarity", "Epic", "Rarity of 'Quick Recovery'.");
			QuickRecoveryMaxStacks = cfg.Bind<int>("Upgrades", "QuickRecoveryMaxStacks", 3, "How many times 'Quick Recovery' can be taken per run.");
			QuickRecoveryPerStack = cfg.Bind<float>("Upgrades", "QuickRecoveryPerStack", 0.25f, "Refill-rate bonus per 'Quick Recovery' (0.25 = 25% faster).");
			LongStrideRarity = cfg.Bind<string>("Upgrades", "LongStrideRarity", "Epic", "Rarity of 'Long Stride'.");
			LongStrideMaxStacks = cfg.Bind<int>("Upgrades", "LongStrideMaxStacks", 2, "How many times 'Long Stride' can be taken per run.");
			LongStridePerStack = cfg.Bind<float>("Upgrades", "LongStridePerStack", 0.3f, "Distance bonus per 'Long Stride' (0.30 = 30% farther).");
			BlazingDashRarity = cfg.Bind<string>("Upgrades", "BlazingDashRarity", "Legendary", "Rarity of 'Blazing Dash'.");
			BlazingDashDamage = cfg.Bind<float>("Upgrades", "BlazingDashDamage", 0f, "Fire damage per tick (every 0.5 s) to enemies in the Blazing Dash trail, before your Damage % and crits. 0 = the same as the game's own Trail spell (recommended).");
			BlazingTrailSeconds = cfg.Bind<float>("Upgrades", "BlazingTrailSeconds", 1.5f, "How long the Blazing Dash trail stays on the ground.");
			EtherealStepRarity = cfg.Bind<string>("Upgrades", "EtherealStepRarity", "Legendary", "Rarity of 'Ethereal Step' (dashes stop costing HP).");
			ShopCards = cfg.Bind<bool>("Upgrades", "ShopCards", true, "Offer the dash cards in the game's own level-up shop (as character cards at the rarities above).");
			StatsPanelRows = cfg.Bind<bool>("Upgrades", "StatsPanelRows", true, "Show the dash's stats (charges, recharge, distance, HP cost, Blazing Dash) as rows in the game's stats list (Escape screen and the hold-to-show stats panel).");
			RemoteIFrames = cfg.Bind<bool>("Multiplayer", "RemoteIFrames", false, "Also protect OTHER players while they dash, detected from their movement. Off: The Spell Brigade applies damage on each player's own PC, so their own mod already protects them.");
			RemoteDashSpeedFactor = cfg.Bind<float>("Multiplayer", "RemoteDashSpeedFactor", 0.8f, new ConfigDescription("A remote wizard moving faster than this fraction of dash speed counts as dashing.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 1.5f), Array.Empty<object>()));
			PlayerComponent = cfg.Bind<string>("GameHooks", "PlayerComponent", "GameplayPlayer", "Class name of the component on the player wizard (e.g. PlayerController). 'auto' = guess by name. See the discovery report.");
			LocalPlayerMembers = cfg.Bind<string>("GameHooks", "LocalPlayerMembers", "isLocalPlayer,IsLocalPlayer,IsLocal,isLocal,IsOwner,isOwner,IsOwned,isOwned,IsMine,isMine,hasAuthority,HasAuthority,HasInputAuthority,IsLocallyControlled,isLocallyControlled", "Bool fields/properties checked (on any component of the wizard) to tell YOUR wizard apart from other players.");
			DeadMembers = cfg.Bind<string>("GameHooks", "DeadMembers", "isGhost,IsGhost,IsDead,isDead,Dead,dead,IsDowned,isDowned,Downed,downed,IsKnockedOut,!IsAlive,!isAlive", "Bool members that mean 'can't dash right now'. Prefix with ! to invert (e.g. !IsAlive).");
			DamageMethods = cfg.Bind<string>("GameHooks", "DamageMethods", "PlayerHealthContainer:TakeDamage;PlayerHealthContainer:RemoveHealthOnOwner", "Extra damage methods to block during i-frames, as Type:Method separated by ';' (e.g. PlayerHealth:TakeDamage). Always applied.");
			AutoDamageHooks = cfg.Bind<bool>("GameHooks", "AutoDamageHooks", false, "Automatically hook methods named like TakeDamage/OnHit on the wizard's components for i-frames.");
			HealthMembers = cfg.Bind<string>("GameHooks", "HealthMembers", "CurrentHealth,currentHealth,curHealth,health,Health,currentHp,CurrentHp,CurrentHP,hp,HP,Hp,_health,m_Health,_currentHealth,currentLife,CurrentLife", "Numeric fields/properties (on the wizard's components) that hold CURRENT HP, used for the dash's HP cost. First match wins.");
			MaxHealthMembers = cfg.Bind<string>("GameHooks", "MaxHealthMembers", "MaxHealth,maxHealth,maxHp,MaxHp,MaxHP,maxHP,_maxHealth,m_MaxHealth,maxLife,MaxLife,totalHealth,TotalHealth", "Numeric fields/properties that hold MAX HP.");
			DiscoveryEnabled = cfg.Bind<bool>("Discovery", "Enabled", false, "Diagnostics for the mod's author, OFF by default: write BepInEx/SpellBrigadeDash-discovery.txt (game classes, damage numbers, upgrade types...) when a run starts and on the report hotkey, and log extra detail to BepInEx/SpellBrigadeDash.log (shop contents, stats panel layout, enemy health, fire damage summaries).");
			TraceLevelUpMethods = cfg.Bind<bool>("Discovery", "TraceLevelUpMethods", false, "Developer tool, OFF: patches game methods to log when they run. It crashed the game at level-up in 0.3.0 (merged method bodies), so it now skips risky methods, but leave it off unless asked.");
			TraceMaxMethods = cfg.Bind<int>("Discovery", "TraceMaxMethods", 40, "Maximum number of game methods traced (level-up shop classes first).");
			SafeMode = cfg.Bind<bool>("Debug", "SafeMode", false, "If the game crashes with the mod: turn this on. No Harmony patches at all (no i-frames, no tracing), only dash + bar + effects. Tells us whether the crash comes from the patches. BepInEx/SpellBrigadeDash.log names the last step before a crash.");
			HookDelaySeconds = cfg.Bind<float>("Debug", "HookDelaySeconds", 3f, "Seconds after your wizard appears before the i-frame damage hooks are installed.");
			StartRunWithDash = cfg.Bind<bool>("Debug", "StartRunWithDash", false, "Test aid: give the dash at the start of every run instead of waiting for the Dash card in the level-up shop.");
			ShopCardTestMode = cfg.Bind<bool>("Debug", "ShopCardTestMode", false, "Test aid: the dash cards are Common and much more likely in the level-up shop, so they show up at the first level-up.");
			DebugHotkeys = cfg.Bind<bool>("Debug", "Hotkeys", false, "Test aid, OFF by default. Debug hotkeys (hold the modifier, then press the key). Defaults: Left Ctrl + 1 = discovery report, + 2 = toggle dash, + 3 = +1 Charge, + 4 = Quick Recovery, + 5 = Long Stride, + 6 = Blazing Dash, + 7 = Ethereal Step.");
			HotkeyModifier = cfg.Bind<string>("Debug", "HotkeyModifier", "<Keyboard>/leftCtrl", "Key that must be held for the debug hotkeys. Empty = no modifier. Input System control path, e.g. <Keyboard>/1, <Keyboard>/k, <Keyboard>/numpad1, <Keyboard>/f6.");
			KeyReport = cfg.Bind<string>("Debug", "KeyWriteReport", "<Keyboard>/1", "Write the discovery report now. Input System control path, e.g. <Keyboard>/1, <Keyboard>/k, <Keyboard>/numpad1, <Keyboard>/f6.");
			KeyToggleDash = cfg.Bind<string>("Debug", "KeyToggleDash", "<Keyboard>/2", "Lock / unlock the dash. Input System control path, e.g. <Keyboard>/1, <Keyboard>/k, <Keyboard>/numpad1, <Keyboard>/f6.");
			KeyExtraCharge = cfg.Bind<string>("Debug", "KeyExtraCharge", "<Keyboard>/3", "Apply the '+1 Dash Charge' card. Input System control path, e.g. <Keyboard>/1, <Keyboard>/k, <Keyboard>/numpad1, <Keyboard>/f6.");
			KeyQuickRecovery = cfg.Bind<string>("Debug", "KeyQuickRecovery", "<Keyboard>/4", "Apply the 'Quick Recovery' card. Input System control path, e.g. <Keyboard>/1, <Keyboard>/k, <Keyboard>/numpad1, <Keyboard>/f6.");
			KeyLongStride = cfg.Bind<string>("Debug", "KeyLongStride", "<Keyboard>/5", "Apply the 'Long Stride' card. Input System control path, e.g. <Keyboard>/1, <Keyboard>/k, <Keyboard>/numpad1, <Keyboard>/f6.");
			KeyBlazingDash = cfg.Bind<string>("Debug", "KeyBlazingDash", "<Keyboard>/6", "Apply the 'Blazing Dash' card. Input System control path, e.g. <Keyboard>/1, <Keyboard>/k, <Keyboard>/numpad1, <Keyboard>/f6.");
			KeyEtherealStep = cfg.Bind<string>("Debug", "KeyEtherealStep", "<Keyboard>/7", "Apply the 'Ethereal Step' card (dashes stop costing HP). Input System control path, e.g. <Keyboard>/1, <Keyboard>/k, <Keyboard>/numpad1, <Keyboard>/f6.");
			ConfigVersion = cfg.Bind<int>("Internal", "ConfigVersion", 0, "Used by the mod to update old settings. Don't edit.");
			Migrate(cfg);
		}

		private static void Migrate(ConfigFile cfg)
		{
			if (ConfigVersion.Value >= 10)
			{
				return;
			}
			List<ConfigEntryBase> list = new List<ConfigEntryBase>();
			if (ConfigVersion.Value < 2)
			{
				list.AddRange((IEnumerable<ConfigEntryBase>)(object)new ConfigEntryBase[12]
				{
					(ConfigEntryBase)KeyboardBinding,
					(ConfigEntryBase)LegacyKey,
					(ConfigEntryBase)Charges,
					(ConfigEntryBase)RechargeSeconds,
					(ConfigEntryBase)BarHeight,
					(ConfigEntryBase)BarFillColor,
					(ConfigEntryBase)BarChargingColor,
					(ConfigEntryBase)BarBackColor,
					(ConfigEntryBase)AfterimageInterval,
					(ConfigEntryBase)AfterimageLifetime,
					(ConfigEntryBase)AfterimageColor,
					(ConfigEntryBase)DustColor
				});
			}
			if (ConfigVersion.Value < 3)
			{
				list.AddRange((IEnumerable<ConfigEntryBase>)(object)new ConfigEntryBase[6]
				{
					(ConfigEntryBase)PlayerComponent,
					(ConfigEntryBase)DeadMembers,
					(ConfigEntryBase)RemoteIFrames,
					(ConfigEntryBase)RemoteDashSpeedFactor,
					(ConfigEntryBase)SoundClipHints,
					(ConfigEntryBase)TraceMaxMethods
				});
			}
			if (ConfigVersion.Value < 4)
			{
				list.Add((ConfigEntryBase)(object)TraceLevelUpMethods);
			}
			if (ConfigVersion.Value < 5)
			{
				list.AddRange((IEnumerable<ConfigEntryBase>)(object)new ConfigEntryBase[5]
				{
					(ConfigEntryBase)TraceLevelUpMethods,
					(ConfigEntryBase)DamageMethods,
					(ConfigEntryBase)AutoDamageHooks,
					(ConfigEntryBase)HealthMembers,
					(ConfigEntryBase)MaxHealthMembers
				});
			}
			if (ConfigVersion.Value < 6 && Math.Abs(RechargeSeconds.Value - 12f) < 0.001f)
			{
				list.Add((ConfigEntryBase)(object)RechargeSeconds);
			}
			if (ConfigVersion.Value < 7 && Math.Abs(BlazingDashDamage.Value - 15f) < 0.001f)
			{
				list.Add((ConfigEntryBase)(object)BlazingDashDamage);
			}
			if (ConfigVersion.Value < 8)
			{
				if (StartRunWithDash.Value)
				{
					list.Add((ConfigEntryBase)(object)StartRunWithDash);
				}
				if (ShopCardTestMode.Value)
				{
					list.Add((ConfigEntryBase)(object)ShopCardTestMode);
				}
			}
			if (ConfigVersion.Value < 9 && Math.Abs(UnlockWeight.Value - 1f) < 0.001f)
			{
				list.Add((ConfigEntryBase)(object)UnlockWeight);
			}
			if (ConfigVersion.Value < 10)
			{
				if (DiscoveryEnabled.Value)
				{
					list.Add((ConfigEntryBase)(object)DiscoveryEnabled);
				}
				if (DebugHotkeys.Value)
				{
					list.Add((ConfigEntryBase)(object)DebugHotkeys);
				}
			}
			foreach (ConfigEntryBase item in list)
			{
				item.BoxedValue = item.DefaultValue;
			}
			ConfigVersion.Value = 10;
			cfg.Save();
			ModLog.Info($"Config updated to version {10} ({list.Count} setting(s) reset to the new defaults).");
		}

		public static string DebugKeyPath(DebugKey key)
		{
			return key switch
			{
				DebugKey.Report => KeyReport.Value, 
				DebugKey.ToggleDash => KeyToggleDash.Value, 
				DebugKey.ExtraCharge => KeyExtraCharge.Value, 
				DebugKey.QuickRecovery => KeyQuickRecovery.Value, 
				DebugKey.LongStride => KeyLongStride.Value, 
				DebugKey.BlazingDash => KeyBlazingDash.Value, 
				_ => KeyEtherealStep.Value, 
			};
		}

		public static string PrettyKey(string path)
		{
			string text;
			string text2;
			if (!path.Contains('/'))
			{
				text = path;
			}
			else
			{
				text2 = path;
				int num = path.LastIndexOf('/') + 1;
				text = text2.Substring(num, text2.Length - num);
			}
			string text3 = text;
			if (text3.Length == 0)
			{
				return "(none)";
			}
			string text4 = Regex.Replace(text3, "(?<=[a-z])(?=[A-Z0-9])", " ");
			string text5 = char.ToUpperInvariant(text4[0]).ToString();
			text2 = text4;
			return text5 + text2.Substring(1, text2.Length - 1);
		}

		public static DashBaseStats BaseStats()
		{
			return new DashBaseStats
			{
				Distance = Distance.Value,
				Duration = Duration.Value,
				Charges = Charges.Value,
				RechargeSeconds = RechargeSeconds.Value,
				IFrameGraceSeconds = IFrameGrace.Value,
				QuickRecoveryPerStack = QuickRecoveryPerStack.Value,
				LongStridePerStack = LongStridePerStack.Value,
				HealthCostFraction = HealthCostPercent.Value / 100f
			};
		}

		public static DashCardSettings CardSettings()
		{
			return new DashCardSettings
			{
				UnlockRarity = UnlockRarity.Value,
				UnlockWeight = UnlockWeight.Value,
				ExtraChargeRarity = ExtraChargeRarity.Value,
				ExtraChargeMaxStacks = ExtraChargeMaxStacks.Value,
				QuickRecoveryRarity = QuickRecoveryRarity.Value,
				QuickRecoveryMaxStacks = QuickRecoveryMaxStacks.Value,
				QuickRecoveryPerStack = QuickRecoveryPerStack.Value,
				LongStrideRarity = LongStrideRarity.Value,
				LongStrideMaxStacks = LongStrideMaxStacks.Value,
				LongStridePerStack = LongStridePerStack.Value,
				BlazingDashRarity = BlazingDashRarity.Value,
				BlazingDashDamage = BlazingDashDamage.Value,
				EtherealStepRarity = EtherealStepRarity.Value,
				HealthCostFraction = HealthCostPercent.Value / 100f
			};
		}

		public static string[] SplitList(string value, char sep = ',')
		{
			return value.Split(sep, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
		}
	}
	internal static class ModLog
	{
		private static ManualLogSource? _log;

		private static StreamWriter? _file;

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

		private static readonly Dictionary<string, float> Throttle = new Dictionary<string, float>();

		public const string CleanExit = "clean exit";

		public static string FilePath => Path.Combine(Paths.BepInExRootPath, "SpellBrigadeDash.log");

		public static string PreviousFilePath => Path.Combine(Paths.BepInExRootPath, "SpellBrigadeDash.prev.log");

		public static string? PreviousCrashStep { get; private set; }

		public static void Init(ManualLogSource log)
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Expected O, but got Unknown
			_log = log;
			bool flag = default(bool);
			try
			{
				if (File.Exists(FilePath))
				{
					File.Copy(FilePath, PreviousFilePath, overwrite: true);
					string text = null;
					string[] array = File.ReadAllLines(FilePath);
					foreach (string text2 in array)
					{
						int num = text2.IndexOf(" STEP  ", StringComparison.Ordinal);
						if (num >= 0)
						{
							string text3 = text2;
							int num2 = num + 7;
							text = text3.Substring(num2, text3.Length - num2).Trim();
						}
					}
					if (text != null && text != "clean exit")
					{
						PreviousCrashStep = text;
					}
				}
			}
			catch (Exception ex)
			{
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(30, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Could not read the previous ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(FilePath);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				log.LogWarning(val);
			}
			try
			{
				_file = new StreamWriter(new FileStream(FilePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
				{
					AutoFlush = true
				};
				_file.WriteLine($"SpellBrigadeDash {"0.5.1"} log, started {DateTime.Now:yyyy-MM-dd HH:mm:ss}");
				if (PreviousCrashStep != null)
				{
					_file.WriteLine("Previous session did not exit cleanly; its last step was: " + PreviousCrashStep + " (log kept as SpellBrigadeDash.prev.log)");
				}
			}
			catch (Exception ex2)
			{
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(17, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Could not open ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(FilePath);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex2.Message);
				}
				log.LogWarning(val);
			}
		}

		public static void Info(string msg)
		{
			ManualLogSource? log = _log;
			if (log != null)
			{
				log.LogInfo((object)msg);
			}
			ToFile("INFO ", msg);
		}

		public static void Warn(string msg)
		{
			ManualLogSource? log = _log;
			if (log != null)
			{
				log.LogWarning((object)msg);
			}
			ToFile("WARN ", msg);
		}

		public static void Error(string msg)
		{
			ManualLogSource? log = _log;
			if (log != null)
			{
				log.LogError((object)msg);
			}
			ToFile("ERROR", msg);
		}

		public static void Debug(string msg)
		{
			ManualLogSource? log = _log;
			if (log != null)
			{
				log.LogDebug((object)msg);
			}
			if (ModConfig.DiscoveryEnabled == null || ModConfig.DiscoveryEnabled.Value)
			{
				ToFile("DEBUG", msg);
			}
		}

		public static void Step(string msg)
		{
			ToFile("STEP ", msg);
		}

		public static void StepOnce(string key, string msg)
		{
			if (Once.Add("step:" + key))
			{
				Step(msg);
			}
		}

		public static void InfoOnce(string key, string msg)
		{
			if (Once.Add(key))
			{
				Info(msg);
			}
		}

		public static void WarnOnce(string key, string msg)
		{
			if (Once.Add(key))
			{
				Warn(msg);
			}
		}

		public static void ErrorThrottled(string key, Exception ex, float now, float seconds = 10f)
		{
			if (!Throttle.TryGetValue(key, out var value) || !(now - value < seconds))
			{
				Throttle[key] = now;
				Error($"[{key}] {ex.GetType().Name}: {ex.Message}\n{ex.StackTrace}");
			}
		}

		private static void ToFile(string level, string msg)
		{
			if (_file == null)
			{
				return;
			}
			try
			{
				lock (_file)
				{
					_file.WriteLine($"{DateTime.Now:HH:mm:ss.fff} {level} {msg}");
				}
			}
			catch
			{
			}
		}
	}
	[BepInPlugin("com.stefanws0.spellbrigadedash", "SpellBrigadeDash", "0.5.1")]
	public class Plugin : BasePlugin
	{
		public const string Guid = "com.stefanws0.spellbrigadedash";

		public const string Name = "SpellBrigadeDash";

		public const string Version = "0.5.1";

		internal static Harmony Harmony { get; private set; }

		public override void Load()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			ModLog.Init(((BasePlugin)this).Log);
			ModLog.Step("Load: config");
			ModConfig.Init(((BasePlugin)this).Config);
			Harmony = new Harmony("com.stefanws0.spellbrigadedash");
			ModLog.Step("Load: registering DashRunner");
			((BasePlugin)this).AddComponent<DashRunner>();
			ModLog.Step("Load: done");
			if (ModConfig.SafeMode.Value)
			{
				ModLog.Warn("Debug.SafeMode is ON: no Harmony patches (no i-frames, no tracing).");
			}
			ModLog.Info($"{"SpellBrigadeDash"} {"0.5.1"} loaded. Discovery report: {(ModConfig.DiscoveryEnabled.Value ? "ON" : "off")}, debug hotkeys: {(ModConfig.DebugHotkeys.Value ? ("ON (hold " + ModConfig.PrettyKey(ModConfig.HotkeyModifier.Value) + ")") : "off")}.");
		}
	}
}
namespace SpellBrigadeDash.Motion
{
	internal static class DashMotor
	{
		private const float Skin = 0.05f;

		private const float CastHeight = 0.5f;

		private static bool _castBroken;

		private static int _castMode;

		private static bool _navBroken;

		public static float Move(PlayerInfo p, Vector3 dir, float distance)
		{
			//IL_0056: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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_00bd: 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_00c5: 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_0103: 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_010d: 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_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: 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_00e7: 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_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: 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_00a1: 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_0141: 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_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)
			if (distance <= 0f)
			{
				return 0f;
			}
			ModLog.StepOnce("move", $"motor: first dash move ({p.Mode})");
			Transform rootT = p.RootT;
			Vector3 position = rootT.position;
			switch (p.Mode)
			{
			case MoveMode.CharacterController:
				if ((Object)(object)p.Cc != (Object)null && ((Collider)p.Cc).enabled)
				{
					p.Cc.Move(dir * distance);
					break;
				}
				goto default;
			case MoveMode.Rigidbody2D:
			case MoveMode.Transform2D:
			{
				float num = Allowed2D(p, position, dir, distance);
				Vector3 val = position + dir * num;
				if ((Object)(object)p.Rb2D != (Object)null)
				{
					p.Rb2D.position = new Vector2(val.x, val.y);
				}
				rootT.position = val;
				break;
			}
			default:
			{
				float num2 = Allowed3D(p, position, dir, distance);
				Vector3 position2 = position + dir * num2;
				if ((Object)(object)p.Rb != (Object)null)
				{
					p.Rb.position = position2;
				}
				rootT.position = position2;
				break;
			}
			}
			return Math.Abs(Vector3.Dot(rootT.position - position, dir));
		}

		public static int BlockingMask(PlayerInfo p)
		{
			string[] array = ModConfig.SplitList(ModConfig.BlockingLayers.Value);
			if (!p.Is2D && array.Length != 0)
			{
				int num = 0;
				string[] array2 = array;
				foreach (string text in array2)
				{
					try
					{
						int num2 = LayerMask.NameToLayer(text);
						if (num2 >= 0)
						{
							num |= 1 << num2;
						}
					}
					catch
					{
					}
				}
				if (num != 0)
				{
					return num;
				}
				ModLog.WarnOnce("no-blocking-layers", "None of Dash.BlockingLayers (" + ModConfig.BlockingLayers.Value + ") exist; falling back to the collision matrix.");
			}
			int layer = p.Root.layer;
			int num3 = 0;
			try
			{
				if (p.Is2D)
				{
					num3 = Physics2D.GetLayerCollisionMask(layer);
				}
				else
				{
					for (int j = 0; j < 32; j++)
					{
						if (!Physics.GetIgnoreLayerCollision(layer, j))
						{
							num3 |= 1 << j;
						}
					}
					num3 &= ~(1 << layer);
				}
			}
			catch
			{
				num3 = ~(1 << layer);
			}
			if (ModConfig.PassThroughEnemies.Value)
			{
				string[] array3 = ModConfig.SplitList(ModConfig.EnemyLayerHints.Value.ToLowerInvariant());
				for (int k = 0; k < 32; k++)
				{
					string text2 = (LayerMask.LayerToName(k) ?? "").ToLowerInvariant();
					if (text2.Length == 0)
					{
						continue;
					}
					string[] array2 = array3;
					foreach (string value in array2)
					{
						if (text2.Contains(value))
						{
							num3 &= ~(1 << k);
							break;
						}
					}
				}
			}
			return num3;
		}

		private static float Allowed2D(PlayerInfo p, Vector3 from, Vector3 dir, float distance)
		{
			//IL_0031: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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_004e: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
			if (_castBroken)
			{
				return distance;
			}
			try
			{
				? val = (((Object)(object)p.Rb2D != (Object)null) ? p.Rb2D.position : new Vector2(from.x, from.y));
				float num = p.Radius * 0.9f;
				Vector2 val2 = new Vector2(dir.x, dir.y);
				float num2 = distance + 0.05f;
				int valueOrDefault = p.CachedMask.GetValueOrDefault();
				int num3;
				if (!p.CachedMask.HasValue)
				{
					valueOrDefault = BlockingMask(p);
					p.CachedMask = valueOrDefault;
					num3 = valueOrDefault;
				}
				else
				{
					num3 = valueOrDefault;
				}
				Il2CppStructArray<RaycastHit2D> obj = Physics2D.CircleCastAll((Vector2)val, num, val2, num2, num3);
				float num4 = distance;
				foreach (RaycastHit2D item in (Il2CppArrayBase<RaycastHit2D>)(object)obj)
				{
					RaycastHit2D current = item;
					Collider2D collider = ((RaycastHit2D)(ref current)).collider;
					if (!((Object)(object)collider == (Object)null) && !collider.isTrigger && !(((RaycastHit2D)(ref current)).distance <= 0.0001f) && !p.GameObjectPtrs.Contains(((Il2CppObjectBase)((Component)collider).gameObject).Pointer))
					{
						num4 = Math.Min(num4, Math.Max(0f, ((RaycastHit2D)(ref current)).distance - 0.05f));
					}
				}
				return num4;
			}
			catch (Exception ex)
			{
				_castBroken = true;
				ModLog.Warn("Physics2D.CircleCastAll unavailable (" + ex.Message + "); dashes will ignore walls.");
				return distance;
			}
		}

		private static float Allowed3D(PlayerInfo p, Vector3 from, Vector3 dir, float distance)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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)
			float num = distance;
			int valueOrDefault = p.CachedMask.GetValueOrDefault();
			int num2;
			if (!p.CachedMask.HasValue)
			{
				valueOrDefault = BlockingMask(p);
				p.CachedMask = valueOrDefault;
				num2 = valueOrDefault;
			}
			else
			{
				num2 = valueOrDefault;
			}
			int num3 = num2;
			if (num3 != 0)
			{
				num = Math.Min(num, ObstacleDistance(p, from, dir, distance, num3));
			}
			if (ModConfig.StayOnNavMesh.Value)
			{
				num = Math.Min(num, NavMeshDistance(from, dir, num));
			}
			return Math.Max(0f, num);
		}

		public static float ObstacleDistance(PlayerInfo p, Vector3 from, Vector3 dir, float distance, int mask)
		{
			//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)
			//IL_0034: 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_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_00a0: 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_00a9: 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_00c1: 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_00c9: 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_00d1: 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_00d9: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = from + Vector3.up * 0.5f;
			float num = Math.Max(0.1f, p.Radius * 0.9f);
			if (_castMode == 0)
			{
				try
				{
					RaycastHit val2 = default(RaycastHit);
					return Physics.SphereCast(val, num, dir, ref val2, distance + 0.05f, mask, (QueryTriggerInteraction)1) ? Math.Max(0f, ((RaycastHit)(ref val2)).distance - 0.05f) : distance;
				}
				catch (Exception ex)
				{
					_castMode = 1;
					ModLog.Warn("Physics.SphereCast unavailable (" + ex.Message + "); using raycasts for walls.");
				}
			}
			if (_castMode == 1)
			{
				try
				{
					Vector3 val3 = Vector3.Cross(Vector3.up, dir);
					Vector3 val4 = ((Vector3)(ref val3)).normalized * num;
					float num2 = distance;
					Vector3[] array = (Vector3[])(object)new Vector3[3]
					{
						val,
						val + val4,
						val - val4
					};
					RaycastHit val5 = default(RaycastHit);
					for (int i = 0; i < array.Length; i++)
					{
						if (Physics.Raycast(array[i], dir, ref val5, distance + num + 0.05f, mask, (QueryTriggerInteraction)1))
						{
							num2 = Math.Min(num2, Math.Max(0f, ((RaycastHit)(ref val5)).distance - num - 0.05f));
						}
					}
					return num2;
				}
				catch (Exception ex2)
				{
					_castMode = 2;
					ModLog.Warn("Physics.Raycast unavailable (" + ex2.Message + "); dashes only stop at the edge of the map.");
				}
			}
			return distance;
		}

		public static float NavMeshDistance(Vector3 from, Vector3 dir, float distance)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_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)
			if (_navBroken || distance <= 0f)
			{
				return distance;
			}
			try
			{
				NavMeshHit val = default(NavMeshHit);
				if (!NavMesh.SamplePosition(from, ref val, 2f, -1))
				{
					return distance;
				}
				Vector3 val2 = ((NavMeshHit)(ref val)).position + dir * distance;
				NavMeshHit val3 = default(NavMeshHit);
				if (!NavMesh.Raycast(((NavMeshHit)(ref val)).position, val2, ref val3, -1))
				{
					return distance;
				}
				Vector3 val4 = ((NavMeshHit)(ref val3)).position - ((NavMeshHit)(ref val)).position;
				val4.y = 0f;
				return Math.Max(0f, ((Vector3)(ref val4)).magnitude - 0.05f);
			}
			catch (Exception ex)
			{
				_navBroken = true;
				ModLog.Warn("NavMesh queries unavailable (" + ex.Message + "); dashes don't check the map edge.");
				return distance;
			}
		}

		public static string Describe()
		{
			return "obstacles: " + ((_castMode == 0) ? "SphereCast" : ((_castMode == 1) ? "Raycast x3" : "none")) + ", map edge: " + (_navBroken ? "none" : "NavMesh.Raycast");
		}
	}
}
namespace SpellBrigadeDash.Game
{
	internal sealed class BlazeDamage
	{
		private const float ScanSeconds = 0.1f;

		private const float StatsSeconds = 2f;

		private const float SummarySeconds = 10f;

		private const float FallbackBaseDamage = 15f;

		private const float FlameRadiusFactor = 0.35f;

		private const float MaxTargetRadius = 3f;

		private const int MaxErrors = 5;

		private const int DetailedHits = 10;

		private readonly BlazeTicks _ticks = new BlazeTicks(0.5f);

		private float _nextScan;

		private bool _off;

		private int _errors;

		private GameplayPlayerIdentity? _identity;

		private float? _trailBase;

		private string _baseSource = "";

		private float _nextStats;

		private float _damageMultiplier = 1f;

		private float _sizeMultiplier = 1f;

		private bool _statsLogged;

		private int _statsLogs;

		private SpellType _spell = (SpellType)8;

		private bool _spellChosen;

		private bool _spellSwitched;

		private bool _crits = true;

		private int _detailed;

		private int _hits;

		private float _dealt;

		private readonly HashSet<long> _hitTargets = new HashSet<long>();

		private float _nextSummary;

		public string Status { get; private set; } = "no Blazing Dash yet";

		public float SizeMultiplier => _sizeMultiplier;

		public float FlameRadius(PlayerInfo p, float now)
		{
			RefreshStats(now);
			return 0.35f * p.VisualSize * Math.Max(0.05f, ModConfig.GameFireScale.Value) * _sizeMultiplier;
		}

		public void AddFlame(Vector3 ground, float radius, float until)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (!_off)
			{
				_ticks.AddFlame(ground.x, ground.z, radius, until);
			}
		}

		public void Clear()
		{
			_ticks.Clear();
			_identity = null;
		}

		public void Update(float now)
		{
			if (_off || now < _nextScan)
			{
				return;
			}
			_nextScan = now + 0.1f;
			_ticks.Prune(now);
			if (_ticks.FlameCount > 0)
			{
				try
				{
					Scan(now);
				}
				catch (Exception ex)
				{
					Fail("scanning for enemies in the fire", ex);
				}
			}
			if (_hits > 0 && now >= _nextSummary)
			{
				if (ModConfig.DiscoveryEnabled.Value)
				{
					ModLog.Info($"Blazing Dash: {_hits} fire hit(s) on {_hitTargets.Count} enemy(ies) in the last {10f:0} s, {_dealt:0} damage " + "(with crits, before the burn that follows).");
				}
				_hits = 0;
				_dealt = 0f;
				_hitTargets.Clear();
			}
		}

		private void Scan(float now)
		{
			//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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			List<Enemy> allEnemies = Enemy.AllEnemies;
			if (allEnemies == null || allEnemies.Count == 0)
			{
				return;
			}
			for (int i = 0; i < allEnemies.Count; i++)
			{
				Enemy val = allEnemies[i];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Vector3 position = ((Component)val).transform.position;
				if (!_ticks.InFlame(position.x, position.z, 3f, now))
				{
					continue;
				}
				Hitbox hitbox = val.hitbox;
				if ((Object)(object)hitbox == (Object)null)
				{
					continue;
				}
				HealthContainer healthContainer = hitbox.HealthContainer;
				if (!((Object)(object)healthContainer == (Object)null) && !(healthContainer.CurrentHealth <= 0f))
				{
					Footprint(hitbox, position, out var x, out var z, out var r);
					if (_ticks.InFlame(x, z, r, now) && _ticks.TryHit(((Il2CppObjectBase)val).Pointer.ToInt64(), now) && !Hit(val, hitbox, healthContainer, now))
					{
						break;
					}
				}
			}
		}

		private static void Footprint(Hitbox hb, Vector3 pos, out float x, out float z, out float r)
		{
			//IL_0001: 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_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_0055: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			x = pos.x;
			z = pos.z;
			r = 0.3f;
			List<Collider> colliders = hb.colliders;
			if (colliders != null && colliders.Count != 0)
			{
				Collider val = colliders[0];
				if (!((Object)(object)val == (Object)null))
				{
					Bounds bounds = val.bounds;
					x = ((Bounds)(ref bounds)).center.x;
					z = ((Bounds)(ref bounds)).center.z;
					r = Math.Min(3f, Math.Max(((Bounds)(ref bounds)).size.x, ((Bounds)(ref bounds)).size.z) * 0.5f);
				}
			}
		}

		private bool Hit(Enemy e, Hitbox hb, HealthContainer health, float now)
		{
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			RefreshStats(now);
			GameplayPlayerIdentity? identity = _identity;
			PlayerStats val = ((identity != null) ? identity.stats : null);
			if ((Object)(object)_identity == (Object)null || (Object)(object)val == (Object)null)
			{
				Status = "waiting for your wizard's stats";
				return false;
			}
			float num = BlazeMath.PerTick(BaseDamage(), _damageMultiplier);
			float currentHealth = health.CurrentHealth;
			try
			{
				hb.Hit((DamageInfo)(object)MakeInfo(((NetworkBehaviour)_identity).OwnerClientId, val, num));
			}
			catch (Exception ex)
			{
				if (!_spellSwitched && SwitchSpell(val, ex))
				{
					return true;
				}
				Fail("hitting an enemy", ex);
				return !_off;
			}
			float currentHealth2 = health.CurrentHealth;
			float num2 = Math.Max(0f, currentHealth - currentHealth2);
			_hits++;
			_dealt += num2;
			_hitTargets.Add(((Il2CppObjectBase)e).Pointer.ToInt64());
			if (_hits == 1 && _nextSummary <= now)
			{
				_nextSummary = now + 10f;
			}
			Status = $"burning: {num:0.#} per tick ({_baseSource} x{_damageMultiplier:0.##}), fire, crits {(_crits ? "on" : "off")}, as {_spell}";
			if (_detailed < 10)
			{
				_detailed++;
				float num3 = ((num > 0f) ? (num2 / num) : 1f);
				ModLog.Info($"Blazing Dash hit '{Clean(((Object)((Component)e).gameObject).name)}': {num:0.#} fire damage sent, HP {currentHealth:0.#} -> {currentHealth2:0.#}" + ((Math.Abs(num3 - 1f) > 0.05f && currentHealth2 > 0f) ? $" (x{num3:0.##})" : "") + ".");
			}
			return true;
		}

		private PlayerSpellDamageInfo MakeInfo(ulong owner, PlayerStats stats, float damage)
		{
			//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_0051: Expected O, but got Unknown
			//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_0060: Expected O, but got Unknown
			//IL_000a: 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_001f: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			PlayerSpellDamageInfo val;
			if (_crits)
			{
				try
				{
					val = new PlayerSpellDamageInfo(owner, _spell, new IPlayerStats(((Il2CppObjectBase)stats).Pointer));
				}
				catch (Exception ex)
				{
					_crits = false;
					ModLog.Warn("Blazing Dash: the game's damage info with your stats failed (" + Message(ex) + "); hits go on without crits.");
					val = new PlayerSpellDamageInfo(owner, _spell);
				}
			}
			else
			{
				val = new PlayerSpellDamageInfo(owner, _spell);
			}
			((DamageInfo)val).Damage = damage;
			((DamageInfo)val).Element = (ElementType)1;
			return val;
		}

		private bool SwitchSpell(PlayerStats stats, Exception ex)
		{
			//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_002a: 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_0052: 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)
			_spellSwitched = true;
			try
			{
				List<SpellType> equippedSpells = stats.GetEquippedSpells();
				if (equippedSpells == null || equippedSpells.Count == 0)
				{
					return false;
				}
				SpellType spell = _spell;
				_spell = equippedSpells[0];
				_crits = true;
				ModLog.Warn($"Blazing Dash: a fire hit credited to {spell} failed ({Message(ex)}); crediting {_spell} from now on.");
				return true;
			}
			catch
			{
				return false;
			}
		}

		private float BaseDamage()
		{
			float value = ModConfig.BlazingDashDamage.Value;
			if (value > 0f)
			{
				_baseSource = $"BlazingDashDamage {value:0.#}";
				return value;
			}
			float valueOrDefault = _trailBase.GetValueOrDefault();
			if (!_trailBase.HasValue)
			{
				valueOrDefault = FindTrailBase();
				_trailBase = valueOrDefault;
			}
			return _trailBase.Value;
		}

		private float FindTrailBase()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Invalid comparison between Unknown and I4
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				foreach (SpellConfiguration item in Resources.FindObjectsOfTypeAll<SpellConfiguration>())
				{
					if ((Object)(object)item == (Object)null || (int)item.SpellType != 8)
					{
						continue;
					}
					List<BaseStat> stats = item.Stats;
					if (stats == null)
					{
						continue;
					}
					for (int i = 0; i < stats.Count; i++)
					{
						BaseStat val = stats[i];
						if (val != null && (int)val.Stat == 0 && !(val.Value <= 0f))
						{
							_baseSource = $"Trail base {val.Value:0.#}";
							ModLog.Info($"Blazing Dash: base damage per tick = the game's Trail spell ('{((Object)item).name}'): {val.Value:0.##}.");
							return val.Value;
						}
					}
				}
			}
			catch (Exception ex)
			{
				ModLog.Warn("Blazing Dash: reading the Trail spell's damage failed (" + Message(ex) + ").");
			}
			_baseSource = $"fallback {15f:0}";
			ModLog.Warn($"Blazing Dash: the game's Trail spell wasn't found; using {15f:0} damage per tick.");
			return 15f;
		}

		private void RefreshStats(float now)
		{
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			if (now < _nextStats && (Object)(object)_identity != (Object)null)
			{
				return;
			}
			_nextStats = now + 2f;
			try
			{
				if ((Object)(object)_identity == (Object)null || (Object)(object)_identity.stats == (Object)null)
				{
					_identity = FindLocalIdentity();
				}
				GameplayPlayerIdentity? identity = _identity;
				PlayerStats val = ((identity != null) ? identity.stats : null);
				if (!((Object)(object)val == (Object)null))
				{
					ChooseSpell(val);
					string detail;
					float num = StatMultiplier(val, (StatType)0, 0.2f, 50f, out detail);
					string detail2;
					float num2 = StatMultiplier(val, (StatType)6, 0.5f, 4f, out detail2);
					bool num3 = !_statsLogged || Math.Abs(num - _damageMultiplier) > 0.005f || Math.Abs(num2 - _sizeMultiplier) > 0.005f;
					_damageMultiplier = num;
					_sizeMultiplier = num2;
					if (num3 && _statsLogs < 12)
					{
						_statsLogged = true;
						_statsLogs++;
						ModLog.Info($"Blazing Dash scaling: Damage x{num:0.###} ({detail}), Spell Size x{num2:0.###} ({detail2}); {BlazeMath.PerTick(BaseDamage(), num):0.#} per tick, credited to {_spell}.");
					}
				}
			}
			catch (Exception ex)
			{
				ModLog.WarnOnce("blaze-stats", "Blazing Dash: reading your stats failed (" + Message(ex) + "); no Damage % / Spell Size bonus for now.");
			}
		}

		private static float StatMultiplier(PlayerStats stats, StatType type, float min, float max, out string detail)
		{
			//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)
			//IL_003a: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Invalid comparison between Unknown and I4
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			detail = "not in your stats";
			List<Stat> playerStats = stats.GetPlayerStats();
			if (playerStats == null)
			{
				return 1f;
			}
			for (int i = 0; i < playerStats.Count; i++)
			{
				Stat val = playerStats[i];
				if (val != null && val.StatType == type)
				{
					StatCalculationType statCalculationType = val.StatCalculationType;
					float baseValue = val.BaseValue;
					float value = val.GetValue();
					float sumOfModifiers = val.GetSumOfModifiers();
					float num = BlazeMath.StatMultiplier((int)statCalculationType == 1, baseValue, value, sumOfModifiers);
					float num2 = BlazeMath.Multiplier(1f, num, min, max);
					detail = $"{statCalculationType}, base {baseValue:0.##}, value {value:0.##}, modifiers {sumOfModifiers:0.##}" + ((Math.Abs(num2 - num) > 0.0001f) ? $", {num:0.##} ignored" : "");
					return num2;
				}
			}
			return 1f;
		}

		private void ChooseSpell(PlayerStats stats)
		{
			//IL_001e: 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_0027: 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_0041: 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_0066: 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_007c: Invalid comparison between Unknown and I4
			List<SpellType> equippedSpells = stats.GetEquippedSpells();
			if (equippedSpells != null && equippedSpells.Count != 0)
			{
				SpellType val = (SpellType)(equippedSpells.Contains((SpellType)8) ? 8 : ((int)equippedSpells[0]));
				if (val != _spell || !_spellChosen)
				{
					_spellChosen = true;
					_spell = val;
					_crits = true;
					ModLog.Info($"Blazing Dash: fire hits are credited to your {val} spell{(((int)