Decompiled source of TumbleWingImpact v0.1.17

plugins/TumbleWingImpact.dll

Decompiled an hour ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

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

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

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

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TumbleWingImpact
{
	internal sealed class EffectSettings
	{
		internal ConfigEntry<bool> LaunchEnabled { get; }

		internal ConfigEntry<bool> ClimbEnabled { get; }

		internal ConfigEntry<bool> WingsEnabled { get; }

		internal ConfigEntry<double> LaunchDamage { get; }

		internal ConfigEntry<float> WallLaunchMultiplier { get; }

		internal ConfigEntry<float> StunPerLevel { get; }

		internal ConfigEntry<float> StunCooldown { get; }

		internal ConfigEntry<float> KnockbackPerLevel { get; }

		internal ConfigEntry<float> ZeroGravitySeconds { get; }

		internal ConfigEntry<float> ExtraJumpStrength { get; }

		internal ConfigEntry<float> AirTumbleSprintMultiplier { get; }

		internal ConfigEntry<int> RedirectsPerLevel { get; }

		internal ConfigEntry<float> WingRefill { get; }

		internal ConfigEntry<float> TurnSpeed { get; }

		internal ConfigEntry<float> MinimumFlightSpeed { get; }

		internal ConfigEntry<float> WallDuration { get; }

		internal ConfigEntry<float> WallDurationPerLevel { get; }

		internal ConfigEntry<float> WallStaminaRate { get; }

		internal ConfigEntry<float> WallSpeed { get; }

		internal ConfigEntry<int> WallEntryRefund { get; }

		internal ConfigEntry<int> WallPeriodicRefund { get; }

		internal ConfigEntry<float> WallRefundInterval { get; }

		internal ConfigEntry<float> WallJumpOutward { get; }

		internal ConfigEntry<float> WallJumpUpward { get; }

		internal EffectSettings(ConfigFile config)
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			LaunchEnabled = config.Bind<bool>("Tumble Launch", "Enable", true, "Enable the mod's Launch effects.");
			ClimbEnabled = config.Bind<bool>("Tumble Climb", "Enable", true, "Enable the mod's Climb effects.");
			WingsEnabled = config.Bind<bool>("Tumble Wings", "Enable", true, "Enable the mod's Wings effects.");
			LaunchDamage = config.Bind<double>("Tumble Launch", "DamageMultiplierPerLevel", 1.1, new ConfigDescription("Native enemy hit damage times this value times Launch level.", (AcceptableValueBase)(object)new AcceptableValueRange<double>(0.0, 100.0), new object[1] { "REPOConfigStep=0.1" }));
			WallLaunchMultiplier = Number("Tumble Launch", "WallLaunchImpulseMultiplier", 1f, 0f, 10f, "Multiplier on the native Launch impulse when launching off a wall.");
			StunPerLevel = Number("Tumble Wings", "StunSecondsPerLevel", 0.5f, 0f, 30f, "Extra stun duration per Wings level.");
			StunCooldown = Number("Tumble Wings", "StunCooldownSeconds", 5f, 0f, 120f, "Minimum time between tumble stuns on the same enemy. 0 disables the cooldown.");
			KnockbackPerLevel = Number("Tumble Wings", "KnockbackBonusPerLevel", 1f, 0f, 10f, "Extra knockback per Wings level. 1 equals +100%.");
			ZeroGravitySeconds = Number("Tumble Wings", "ZeroGravitySeconds", 1f, 0f, 30f, "Zero gravity duration after each successful tumble jump.");
			ExtraJumpStrength = Number("Tumble Wings", "AirJumpStrengthMultiplier", 0.5f, 0f, 10f, "Air jump impulse relative to a ground jump.");
			AirTumbleSprintMultiplier = Number("Tumble Wings", "AirTumbleSprintMultiplier", 1f, 0f, 10f, "Minimum re-tumble forward speed relative to sprint speed.");
			RedirectsPerLevel = Integer("Tumble Wings", "RedirectsPerLevel", 1, "Number of redirects per Wings level.");
			WingRefill = Number("Tumble Wings", "WingRefillFraction", 1f, 0f, 1f, "Minimum wing meter charge after a redirect. 1 is full.");
			TurnSpeed = Number("Tumble Wings", "FlightTurnDegreesPerSecond", 480f, 0f, 2000f, "Flight steering speed. 0 restores native steering.");
			MinimumFlightSpeed = Number("Tumble Wings", "MinimumFlightSpeed", 2.5f, 0f, 100f, "Minimum speed during the mod's wing steering.");
			WallDuration = Number("Tumble Climb", "WallRunSecondsAtLevelOne", 2.5f, 0f, 120f, "Wall run duration at Climb level 1.");
			WallDurationPerLevel = Number("Tumble Climb", "WallRunSecondsPerExtraLevel", 0.5f, 0f, 30f, "Extra duration per Climb level above level 1.");
			WallStaminaRate = Number("Tumble Climb", "WallRunStaminaMultiplier", 0.5f, 0f, 10f, "Wall run stamina cost relative to full sprint.");
			WallSpeed = Number("Tumble Climb", "WallRunSprintMultiplier", 1f, 0f, 10f, "Minimum wall run speed relative to sprint speed.");
			WallEntryRefund = Integer("Tumble Climb", "WallEntryRedirectRefund", 1, "Redirects restored when wall running starts.");
			WallPeriodicRefund = Integer("Tumble Climb", "WallPeriodicRedirectRefund", 1, "Redirects restored each interval while wall running.");
			WallRefundInterval = Number("Tumble Climb", "WallRefundIntervalSeconds", 1f, 0f, 30f, "Time between wall refunds. 0 disables periodic refunds.");
			WallJumpOutward = Number("Tumble Climb", "WallJumpOutwardSpeed", 4f, 0f, 100f, "Outward wall jump speed.");
			WallJumpUpward = Number("Tumble Climb", "WallJumpUpwardSpeed", 3f, 0f, 100f, "Upward wall jump speed.");
			ConfigEntry<int> Integer(string section, string key, int value, string help)
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Expected O, but got Unknown
				return config.Bind<int>(section, key, value, new ConfigDescription(help, (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			}
			ConfigEntry<float> Number(string section, string key, float value, float min, float max, string help)
			{
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Expected O, but got Unknown
				return config.Bind<float>(section, key, value, new ConfigDescription(help, (AcceptableValueBase)(object)new AcceptableValueRange<float>(min, max), new object[1] { "REPOConfigStep=0.1" }));
			}
		}
	}
	[BepInPlugin("ponyo.tumblewingimpact", "Tumble Wing Impact", "0.1.17")]
	public sealed class Plugin : BaseUnityPlugin
	{
		private const string Id = "ponyo.tumblewingimpact";

		private Harmony? _harmony;

		internal static EffectSettings Effects { get; private set; }

		private void Awake()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			ConfigEntry<bool> logHits = ((BaseUnityPlugin)this).Config.Bind<bool>("Diagnostics", "LogHits", false, "Log each Tumble Wing impact.");
			Effects = new EffectSettings(((BaseUnityPlugin)this).Config);
			Harmony val = new Harmony("ponyo.tumblewingimpact");
			try
			{
				ImpactPatch.Install(val, ((BaseUnityPlugin)this).Logger, () => logHits.Value);
				_harmony = val;
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Tumble Wing Impact installed.");
			}
			catch (Exception ex)
			{
				val.UnpatchSelf();
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Tumble Wing Impact unavailable: " + ex.Message));
			}
			if (_harmony != null)
			{
				try
				{
					TumbleJump.Install(val, ((BaseUnityPlugin)this).Logger, () => logHits.Value);
				}
				catch (Exception ex2)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Tumble jump unavailable: " + ex2.Message));
				}
				if (TumbleJump.Installed)
				{
					try
					{
						WingFlight.Install(val, ((BaseUnityPlugin)this).Logger, () => logHits.Value);
					}
					catch (Exception ex3)
					{
						((BaseUnityPlugin)this).Logger.LogWarning((object)("Tumble Wing steering unavailable: " + ex3.Message));
					}
					try
					{
						WallRun.Install(val, ((BaseUnityPlugin)this).Logger, () => logHits.Value);
					}
					catch (Exception ex4)
					{
						((BaseUnityPlugin)this).Logger.LogWarning((object)("Tumble Climb wall run unavailable: " + ex4.Message));
					}
				}
			}
			ConfigEntry<bool> val2 = ((BaseUnityPlugin)this).Config.Bind<bool>("Testing", "SpawnTestUpgrades", false, "Spawn three Tumble Launch, three Tumble Wings, two Extra Jump and four Tumble Climb upgrades in the first mission truck after each launch.");
			if (_harmony != null && val2.Value)
			{
				try
				{
					TestSupplies.Install(val, ((BaseUnityPlugin)this).Logger);
				}
				catch (Exception ex5)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Tumble Wing test supplies unavailable: " + ex5.Message));
				}
			}
		}

		private void OnDestroy()
		{
			Harmony? harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal static class ImpactPatch
	{
		private sealed class StunCooldown
		{
			internal float ReadyAt;
		}

		private sealed class Hit
		{
			internal int Level;

			internal Component Tumble;

			internal Rigidbody? PlayerBody;

			internal Rigidbody? TargetBody;

			internal Vector3 Velocity;

			internal float? NativeForce;

			internal int? NativeDamage;

			internal int LaunchLevel;

			internal int ScaledDamage;

			internal bool StunBlocked;

			internal bool RestoreNativeStun;

			internal float PreviousStunTime;
		}

		private static FieldInfo _owner = null;

		private static FieldInfo _avatarTumble = null;

		private static FieldInfo _tumbleCollider = null;

		private static FieldInfo _tumbling = null;

		private static FieldInfo _tumbleBody = null;

		private static FieldInfo _enemyPhysics = null;

		private static FieldInfo _enemyBody = null;

		private static FieldInfo _nativeForce = null;

		private static FieldInfo _stunState = null;

		private static FieldInfo _nativeStun = null;

		private static FieldInfo _nativeStunTime = null;

		private static FieldInfo _enemyType = null;

		private static FieldInfo _nativeStunType = null;

		private static FieldInfo _health = null;

		private static FieldInfo _healthCurrent = null;

		private static FieldInfo _stats = null;

		private static FieldInfo _wingLevels = null;

		private static FieldInfo _launchLevel = null;

		private static FieldInfo _nativeDamage = null;

		private static FieldInfo _stunTimer = null;

		private static MethodInfo _steamId = null;

		private static MethodInfo _resetMotion = null;

		private static MethodInfo _setStun = null;

		private static Func<bool> _hasAuthority = null;

		private static Func<bool> _logHits = null;

		private static ManualLogSource _log = null;

		private static readonly ConditionalWeakTable<Component, StunCooldown> Stuns = new ConditionalWeakTable<Component, StunCooldown>();

		internal static void Install(Harmony harmony, ManualLogSource log, Func<bool> logHits)
		{
			Type type = RequireType("HurtCollider");
			Type type2 = RequireType("PlayerAvatar");
			Type type3 = RequireType("PlayerTumble");
			Type type4 = RequireType("Enemy");
			Type type5 = RequireType("EnemyRigidbody");
			Type type6 = RequireType("EnemyHealth");
			Type type7 = RequireType("EnemyStateStunned");
			Type type8 = RequireType("StatsManager");
			Type owner = RequireType("SemiFunc");
			Type type9 = RequireType("EnemyType");
			_owner = Field(type, "playerCausingHurtOverride", type2);
			_avatarTumble = Field(type2, "tumble", type3);
			_tumbleCollider = Field(type3, "hurtCollider", type);
			_tumbling = Field(type3, "isTumbling", typeof(bool));
			_tumbleBody = Field(type3, "rb", typeof(Rigidbody));
			_launchLevel = Field(type3, "tumbleLaunch", typeof(int));
			_nativeDamage = Field(type, "enemyDamage", typeof(int));
			_enemyPhysics = Field(type4, "Rigidbody", type5);
			_enemyBody = Field(type5, "rb", typeof(Rigidbody));
			_nativeForce = Field(type, "enemyHitForce", typeof(float));
			_stunState = Field(type4, "StateStunned", type7);
			_stunTimer = Field(type7, "stunTimer", typeof(float));
			_nativeStun = Field(type, "enemyStun", typeof(bool));
			_nativeStunTime = Field(type, "enemyStunTime", typeof(float));
			_enemyType = Field(type4, "Type", type9);
			_nativeStunType = Field(type, "enemyStunType", type9);
			_health = Field(type4, "Health", type6);
			_healthCurrent = Field(type6, "healthCurrent", typeof(int));
			_stats = Field(type8, "instance", type8, isStatic: true);
			_wingLevels = Field(type8, "playerUpgradeTumbleWings", typeof(Dictionary<string, int>));
			_steamId = Method(owner, "PlayerGetSteamID", typeof(string), type2);
			_resetMotion = Method(type3, "TumbleMotionReset", typeof(void));
			_setStun = Method(type7, "Set", typeof(void), typeof(float));
			_hasAuthority = (Func<bool>)Method(owner, "IsMasterClientOrSingleplayer", typeof(bool)).CreateDelegate(typeof(Func<bool>));
			_log = log;
			_logHits = logHits;
			harmony.Patch((MethodBase)Method(type, "EnemyHurt", typeof(bool), type4), Hook("BeforeHit"), Hook("AfterHit"), (HarmonyMethod)null, Hook("RestoreNativeHitValues"), (HarmonyMethod)null);
		}

		private static void BeforeHit(Component __instance, Component __0, out Hit? __state)
		{
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			__state = null;
			if (!_hasAuthority() || (Object)(object)__0 == (Object)null)
			{
				return;
			}
			object? value = _owner.GetValue(__instance);
			Component val = (Component)((value is Component) ? value : null);
			if (val == null || (Object)(object)val == (Object)null)
			{
				return;
			}
			object? value2 = _avatarTumble.GetValue(val);
			Component val2 = (Component)((value2 is Component) ? value2 : null);
			if (val2 == null || (Object)(object)val2 == (Object)null)
			{
				return;
			}
			object value3 = _tumbling.GetValue(val2);
			if (!(value3 is bool) || !(bool)value3 || !object.Equals(_tumbleCollider.GetValue(val2), __instance))
			{
				return;
			}
			int num = WingLevel(val);
			int num2 = LaunchLevel(val2);
			if (num <= 0 && num2 <= 0)
			{
				return;
			}
			Hit hit = (__state = new Hit
			{
				Level = num,
				LaunchLevel = num2,
				Tumble = val2
			});
			if (num > 0)
			{
				object? value4 = _stunState.GetValue(__0);
				Component val3 = (Component)((value4 is Component) ? value4 : null);
				if (val3 != null && (Object)(object)val3 != (Object)null)
				{
					hit.PreviousStunTime = (float)_stunTimer.GetValue(val3);
					hit.StunBlocked = Plugin.Effects.StunCooldown.Value > 0f && Stuns.TryGetValue(__0, out StunCooldown value5) && Time.time < value5.ReadyAt;
					if (hit.StunBlocked)
					{
						value3 = _nativeStun.GetValue(__instance);
						if (value3 is bool && (bool)value3)
						{
							hit.RestoreNativeStun = true;
							_nativeStun.SetValue(__instance, false);
						}
					}
				}
			}
			int num3 = (int)_nativeDamage.GetValue(__instance);
			double value6 = Plugin.Effects.LaunchDamage.Value;
			if (num2 > 0 && num3 > 0 && value6 > 0.0 && !double.IsInfinity(value6))
			{
				hit.NativeDamage = num3;
				hit.ScaledDamage = (int)Math.Min(2147483647.0, Math.Floor((double)num3 * (value6 * (double)num2)));
				_nativeDamage.SetValue(__instance, hit.ScaledDamage);
			}
			if (num <= 0)
			{
				return;
			}
			object? value7 = _tumbleBody.GetValue(val2);
			Rigidbody val4 = (Rigidbody)((value7 is Rigidbody) ? value7 : null);
			if (val4 == null || (Object)(object)val4 == (Object)null || val4.isKinematic)
			{
				return;
			}
			object? value8 = _enemyPhysics.GetValue(__0);
			Component val5 = (Component)((value8 is Component) ? value8 : null);
			if (val5 == null || (Object)(object)val5 == (Object)null)
			{
				return;
			}
			object? value9 = _enemyBody.GetValue(val5);
			Rigidbody val6 = (Rigidbody)((value9 is Rigidbody) ? value9 : null);
			if (val6 != null && !((Object)(object)val6 == (Object)null) && !val6.isKinematic)
			{
				Vector3 linearVelocity = val4.linearVelocity;
				if (!(((Vector3)(ref linearVelocity)).sqrMagnitude < 0.0025f))
				{
					hit.PlayerBody = val4;
					hit.TargetBody = val6;
					hit.Velocity = val4.linearVelocity;
					hit.NativeForce = (float)_nativeForce.GetValue(__instance);
					_nativeForce.SetValue(__instance, 0f);
				}
			}
		}

		private static void AfterHit(Component __instance, Component __0, bool __result, Hit? __state)
		{
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			if (!__result || __state == null || (Object)(object)__0 == (Object)null)
			{
				return;
			}
			if (_logHits())
			{
				int? nativeDamage = __state.NativeDamage;
				if (nativeDamage.HasValue)
				{
					int valueOrDefault = nativeDamage.GetValueOrDefault();
					_log.LogInfo((object)$"Tumble Launch Lv{__state.LaunchLevel}: {valueOrDefault} -> {__state.ScaledDamage} enemy hit damage before resistance.");
				}
			}
			if (__state.Level <= 0)
			{
				return;
			}
			object? value = _health.GetValue(__0);
			Component val = (Component)((value is Component) ? value : null);
			bool num = val == null || (Object)(object)val == (Object)null || (_healthCurrent.GetValue(val) is int num2 && num2 > 0);
			float num3 = 0f;
			if (num && !__state.StunBlocked)
			{
				object? value2 = _stunState.GetValue(__0);
				Component val2 = (Component)((value2 is Component) ? value2 : null);
				if (val2 != null && (Object)(object)val2 != (Object)null)
				{
					object value3 = _nativeStun.GetValue(__instance);
					num3 = ((value3 is bool && (bool)value3 && Convert.ToInt32(_enemyType.GetValue(__0)) <= Convert.ToInt32(_nativeStunType.GetValue(__instance))) ? ((float)_nativeStunTime.GetValue(__instance)) : 0f) + Plugin.Effects.StunPerLevel.Value * (float)__state.Level;
					if (num3 > 0f)
					{
						_setStun.Invoke(val2, new object[1] { num3 });
					}
					if ((float)_stunTimer.GetValue(val2) > __state.PreviousStunTime)
					{
						Stuns.GetValue(__0, (Component _) => new StunCooldown()).ReadyAt = Time.time + Plugin.Effects.StunCooldown.Value;
					}
				}
			}
			Rigidbody playerBody = __state.PlayerBody;
			Rigidbody targetBody = __state.TargetBody;
			float num4 = 0f;
			if ((Object)(object)playerBody != (Object)null && !playerBody.isKinematic && (Object)(object)targetBody != (Object)null && !targetBody.isKinematic)
			{
				float num5 = Mathf.Sqrt(playerBody.mass / targetBody.mass);
				Vector3 val3 = __state.Velocity * (num5 * (1f + Plugin.Effects.KnockbackPerLevel.Value * (float)__state.Level));
				_resetMotion.Invoke(__state.Tumble, null);
				playerBody.linearVelocity = Vector3.zero;
				playerBody.angularVelocity = Vector3.zero;
				targetBody.AddForce(val3, (ForceMode)2);
				num4 = ((Vector3)(ref val3)).magnitude;
			}
			if (_logHits())
			{
				_log.LogInfo((object)$"Wing Lv{__state.Level}: {((Object)__0).name}, knockback +{num4:0.00} m/s, stun requested {num3:0.00} s.");
			}
		}

		private static void RestoreNativeHitValues(Component __instance, Hit? __state)
		{
			float? num = __state?.NativeForce;
			if (num.HasValue)
			{
				float valueOrDefault = num.GetValueOrDefault();
				_nativeForce.SetValue(__instance, valueOrDefault);
			}
			int? num2 = __state?.NativeDamage;
			if (num2.HasValue)
			{
				int valueOrDefault2 = num2.GetValueOrDefault();
				_nativeDamage.SetValue(__instance, valueOrDefault2);
			}
			if (__state != null && __state.RestoreNativeStun)
			{
				_nativeStun.SetValue(__instance, true);
			}
		}

		internal static int LaunchLevel(Component tumble)
		{
			if (!Plugin.Effects.LaunchEnabled.Value)
			{
				return 0;
			}
			return (int)_launchLevel.GetValue(tumble);
		}

		internal static int WingLevel(Component avatar)
		{
			if (!Plugin.Effects.WingsEnabled.Value)
			{
				return 0;
			}
			object value = _stats.GetValue(null);
			if (value == null || !(_wingLevels.GetValue(value) is Dictionary<string, int> dictionary) || !(_steamId.Invoke(null, new object[1] { avatar }) is string key) || !dictionary.TryGetValue(key, out var value2))
			{
				return 0;
			}
			return value2;
		}

		internal static Type RequireType(string name)
		{
			return AccessTools.TypeByName(name) ?? throw new TypeLoadException(name);
		}

		internal static FieldInfo Field(Type owner, string name, Type type, bool isStatic = false)
		{
			FieldInfo fieldInfo = AccessTools.Field(owner, name);
			if (!(fieldInfo?.FieldType == type) || fieldInfo.IsStatic != isStatic)
			{
				throw new MissingFieldException(owner.FullName, name);
			}
			return fieldInfo;
		}

		internal static MethodInfo Method(Type owner, string name, Type result, params Type[] arguments)
		{
			MethodInfo methodInfo = AccessTools.Method(owner, name, arguments, (Type[])null);
			if (!(methodInfo?.ReturnType == result))
			{
				throw new MissingMethodException(owner.FullName, name);
			}
			return methodInfo;
		}

		private static HarmonyMethod Hook(string name)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			return new HarmonyMethod(typeof(ImpactPatch), name, (Type[])null);
		}
	}
	internal static class TestSupplies
	{
		private static Func<bool> _inMission;

		private static Func<bool> _hasAuthority;

		private static FieldInfo _stats;

		private static FieldInfo _catalog;

		private static FieldInfo _pun;

		private static FieldInfo _itemPrefab;

		private static FieldInfo _spawnPrefab;

		private static FieldInfo _spawnPosition;

		private static FieldInfo _spawnRotation;

		private static Type _record;

		private static Type _launchUpgrade;

		private static Type _wingsUpgrade;

		private static Type _extraJumpUpgrade;

		private static Type _climbUpgrade;

		private static MethodInfo _getPrefab;

		private static MethodInfo _applySpawn;

		private static ManualLogSource _log;

		private static bool _attemptedSpawn;

		internal static void Install(Harmony harmony, ManualLogSource log)
		{
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Expected O, but got Unknown
			Type owner = ImpactPatch.RequireType("SemiFunc");
			Type type = ImpactPatch.RequireType("StatsManager");
			Type type2 = ImpactPatch.RequireType("Item");
			Type type3 = ImpactPatch.RequireType("PrefabRef");
			Type type4 = ImpactPatch.RequireType("PunManager");
			Type owner2 = ImpactPatch.RequireType("TruckSafetySpawnPoint");
			_record = AccessTools.Inner(type4, "ItemSpawn") ?? throw new TypeLoadException("PunManager.ItemSpawn");
			_launchUpgrade = ImpactPatch.RequireType("ItemUpgradePlayerTumbleLaunch");
			_wingsUpgrade = ImpactPatch.RequireType("ItemUpgradePlayerTumbleWings");
			_extraJumpUpgrade = ImpactPatch.RequireType("ItemUpgradePlayerExtraJump");
			_climbUpgrade = ImpactPatch.RequireType("ItemUpgradePlayerTumbleClimb");
			_stats = ImpactPatch.Field(type, "instance", type, isStatic: true);
			_catalog = ImpactPatch.Field(type, "itemDictionary", typeof(Dictionary<, >).MakeGenericType(typeof(string), type2));
			_pun = ImpactPatch.Field(type4, "instance", type4, isStatic: true);
			_itemPrefab = ImpactPatch.Field(type2, "prefab", type3);
			_spawnPrefab = ImpactPatch.Field(_record, "prefab", type3);
			_spawnPosition = ImpactPatch.Field(_record, "position", typeof(Vector3));
			_spawnRotation = ImpactPatch.Field(_record, "rotation", typeof(Quaternion));
			_getPrefab = ImpactPatch.Method(type3, "get_Prefab", typeof(GameObject));
			_applySpawn = ImpactPatch.Method(type4, "ItemSpawnApply", typeof(void), _record);
			_inMission = (Func<bool>)ImpactPatch.Method(owner, "RunIsLevel", typeof(bool)).CreateDelegate(typeof(Func<bool>));
			_hasAuthority = (Func<bool>)ImpactPatch.Method(owner, "IsMasterClientOrSingleplayer", typeof(bool)).CreateDelegate(typeof(Func<bool>));
			_log = log;
			harmony.Patch((MethodBase)ImpactPatch.Method(owner2, "Awake", typeof(void)), (HarmonyMethod)null, new HarmonyMethod(typeof(TestSupplies), "AfterTruckAwake", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private static void AfterTruckAwake(MonoBehaviour __instance)
		{
			if (!_attemptedSpawn)
			{
				__instance.StartCoroutine(PlaceInTruck(((Component)__instance).transform));
			}
		}

		private static IEnumerator PlaceInTruck(Transform anchor)
		{
			yield return null;
			if (_attemptedSpawn || (Object)(object)anchor == (Object)null || !_inMission() || !_hasAuthority())
			{
				yield break;
			}
			float deadline = Time.realtimeSinceStartup + 10f;
			while ((Object)(object)anchor != (Object)null && !_attemptedSpawn && _inMission() && _hasAuthority() && Time.realtimeSinceStartup < deadline)
			{
				object value = _stats.GetValue(null);
				if (value != null)
				{
					object? value2 = _pun.GetValue(null);
					Component val = (Component)((value2 is Component) ? value2 : null);
					if (val != null && (Object)(object)val != (Object)null && _catalog.GetValue(value) is IDictionary { Count: >0 } dictionary)
					{
						_attemptedSpawn = true;
						try
						{
							SpawnSupplies(anchor, val, dictionary);
							break;
						}
						catch (Exception ex)
						{
							_log.LogWarning((object)("Tumble Wing test supplies failed: " + ex.GetBaseException().Message));
							break;
						}
					}
				}
				yield return null;
			}
		}

		private static void SpawnSupplies(Transform anchor, Component pun, IDictionary catalog)
		{
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			object obj = null;
			object obj2 = null;
			object obj3 = null;
			object obj4 = null;
			foreach (DictionaryEntry item in catalog)
			{
				if (!(item.Key is string text) || (text.IndexOf("Tumble", StringComparison.OrdinalIgnoreCase) < 0 && text.IndexOf("Jump", StringComparison.OrdinalIgnoreCase) < 0) || item.Value == null)
				{
					continue;
				}
				object value = _itemPrefab.GetValue(item.Value);
				if (value == null)
				{
					continue;
				}
				object? obj5 = _getPrefab.Invoke(value, null);
				GameObject val = (GameObject)((obj5 is GameObject) ? obj5 : null);
				if (val != null && !((Object)(object)val == (Object)null))
				{
					if ((Object)(object)val.GetComponentInChildren(_launchUpgrade, true) != (Object)null)
					{
						obj = value;
					}
					if ((Object)(object)val.GetComponentInChildren(_wingsUpgrade, true) != (Object)null)
					{
						obj2 = value;
					}
					if ((Object)(object)val.GetComponentInChildren(_extraJumpUpgrade, true) != (Object)null)
					{
						obj3 = value;
					}
					if ((Object)(object)val.GetComponentInChildren(_climbUpgrade, true) != (Object)null)
					{
						obj4 = value;
					}
					if (obj != null && obj2 != null && obj3 != null && obj4 != null)
					{
						break;
					}
				}
			}
			Vector3 val2 = Vector3.ProjectOnPlane(anchor.right, Vector3.up);
			Vector3 right = ((Vector3)(ref val2)).normalized;
			Vector3 forward = Vector3.Cross(right, Vector3.up);
			Quaternion rotation = Quaternion.LookRotation(forward);
			int floorMask = LayerMask.GetMask(new string[1] { "Default" });
			SpawnRow("Tumble Launch", obj, 3, 0.4f);
			SpawnRow("Tumble Wings", obj2, 3, 0.76f);
			SpawnRow("Extra Jump", obj3, 2, 1.12f);
			SpawnRow("Tumble Climb", obj4, 4, 1.48f);
			void SpawnRow(string name, object? prefab, int count, float distance)
			{
				//IL_003a: 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_004d: 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_0059: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0064: Unknown result type (might be due to invalid IL or missing references)
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				//IL_006a: 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_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_007f: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c2: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: Unknown result type (might be due to invalid IL or missing references)
				if (prefab == null)
				{
					_log.LogWarning((object)("Could not find the " + name + " upgrade in the catalog."));
				}
				else
				{
					RaycastHit val4 = default(RaycastHit);
					for (int i = 0; i < count; i++)
					{
						float num = (float)i - (float)(count - 1) * 0.5f;
						Vector3 val3 = anchor.position + right * (num * 0.34f) + forward * distance;
						if (Physics.Raycast(val3 + Vector3.up * 0.5f, Vector3.down, ref val4, 2f, floorMask, (QueryTriggerInteraction)1))
						{
							val3.y = ((RaycastHit)(ref val4)).point.y;
						}
						val3 += Vector3.up * 0.3f;
						object obj6 = Activator.CreateInstance(_record);
						_spawnPrefab.SetValue(obj6, prefab);
						_spawnPosition.SetValue(obj6, val3);
						_spawnRotation.SetValue(obj6, rotation);
						_applySpawn.Invoke(pun, new object[1] { obj6 });
					}
					_log.LogInfo((object)$"Requested {count} {name} test upgrades in the truck.");
				}
			}
		}
	}
	internal static class TumbleJump
	{
		private sealed class JumpState
		{
			internal int Remaining;

			internal int RedirectsUsed;

			internal float ReadyAt;

			internal bool Extra;

			internal float ExitDeadline;

			internal float RetumbleDeadline;

			internal float GravityDeadline;

			internal Vector3 JumpVelocity;

			internal Vector3 StandingVelocity;
		}

		private const float JumpInterval = 0.18f;

		private static readonly ConditionalWeakTable<Component, JumpState> States = new ConditionalWeakTable<Component, JumpState>();

		private static FieldInfo _avatar = null;

		private static FieldInfo _avatarTumble = null;

		private static FieldInfo _isTumbling = null;

		private static FieldInfo _body = null;

		private static FieldInfo _colliders = null;

		private static FieldInfo _dead = null;

		private static FieldInfo _disabled = null;

		private static FieldInfo _jumpForce = null;

		private static FieldInfo _extraCapacity = null;

		private static FieldInfo _extraRemaining = null;

		private static FieldInfo _firstJump = null;

		private static FieldInfo _physGrabObject = null;

		private static FieldInfo _grabbers = null;

		private static FieldInfo _standingBody = null;

		private static FieldInfo _tumbleInputCooldown = null;

		private static FieldInfo _overrideTime = null;

		private static FieldInfo _stunTime = null;

		private static FieldInfo _override = null;

		private static FieldInfo _antiGravityTimer = null;

		private static FieldInfo _tumbleZeroGravityTimer = null;

		private static FieldInfo _sprintSpeed = null;

		private static FieldInfo _camera = null;

		private static FieldInfo _inputDisabled = null;

		private static FieldInfo _health = null;

		private static FieldInfo _hurtFreeze = null;

		private static FieldInfo _hurtFreezeTimer = null;

		private static MethodInfo _jumpInput = null;

		private static MethodInfo _tumbleForce = null;

		private static MethodInfo _jumpSound = null;

		private static MethodInfo _requestTumble = null;

		private static MethodInfo _antiGravity = null;

		private static MethodInfo _zeroGravity = null;

		private static MethodInfo _aimTransform = null;

		private static MethodInfo _resetMotion = null;

		private static Func<bool> _noTextInput = null;

		private static Func<bool> _logHits = null;

		private static Func<bool> _hasAuthority = null;

		private static object[] _jumpKey = null;

		private static object[] _tumbleKey = null;

		private static Component? _redirectedTumble;

		private static int _redirectFrame = -1;

		private static Component? _reservedJump;

		private static int _reservedJumpFrame = -1;

		private static int _groundMask;

		private static ManualLogSource _log = null;

		internal static bool Installed { get; private set; }

		internal static void Install(Harmony harmony, ManualLogSource log, Func<bool> logHits)
		{
			//IL_0554: Unknown result type (might be due to invalid IL or missing references)
			//IL_0569: Unknown result type (might be due to invalid IL or missing references)
			//IL_0576: Expected O, but got Unknown
			//IL_0576: Expected O, but got Unknown
			//IL_058d: Unknown result type (might be due to invalid IL or missing references)
			//IL_059b: Expected O, but got Unknown
			Type owner = ImpactPatch.RequireType("PlayerController");
			Type type = ImpactPatch.RequireType("PlayerAvatar");
			Type type2 = ImpactPatch.RequireType("PlayerTumble");
			Type owner2 = ImpactPatch.RequireType("SemiFunc");
			Type type3 = ImpactPatch.RequireType("InputKey");
			Type type4 = ImpactPatch.RequireType("PhysGrabObject");
			Type type5 = ImpactPatch.RequireType("PhysGrabber");
			Type type6 = ImpactPatch.RequireType("PlayerLocalCamera");
			Type type7 = ImpactPatch.RequireType("PlayerHealth");
			_avatar = ImpactPatch.Field(owner, "playerAvatarScript", type);
			_avatarTumble = ImpactPatch.Field(type, "tumble", type2);
			_isTumbling = ImpactPatch.Field(type2, "isTumbling", typeof(bool));
			_body = ImpactPatch.Field(type2, "rb", typeof(Rigidbody));
			_standingBody = ImpactPatch.Field(owner, "rb", typeof(Rigidbody));
			_sprintSpeed = ImpactPatch.Field(owner, "SprintSpeed", typeof(float));
			_camera = ImpactPatch.Field(type, "localCamera", type6);
			_antiGravityTimer = ImpactPatch.Field(owner, "antiGravityTimer", typeof(float));
			_tumbleInputCooldown = ImpactPatch.Field(owner, "tumbleInputDisableTimer", typeof(float));
			_inputDisabled = ImpactPatch.Field(owner, "InputDisableTimer", typeof(float));
			_overrideTime = ImpactPatch.Field(type2, "tumbleOverrideTimer", typeof(float));
			_stunTime = ImpactPatch.Field(type2, "tumbleStunTimer", typeof(float));
			_override = ImpactPatch.Field(type2, "tumbleOverride", typeof(bool));
			_colliders = ImpactPatch.Field(type2, "colliders", typeof(Collider[]));
			_dead = ImpactPatch.Field(type, "deadSet", typeof(bool));
			_disabled = ImpactPatch.Field(type, "isDisabled", typeof(bool));
			_health = ImpactPatch.Field(type, "playerHealth", type7);
			_hurtFreeze = ImpactPatch.Field(type7, "hurtFreeze", typeof(bool));
			_hurtFreezeTimer = ImpactPatch.Field(type7, "hurtFreezeTimer", typeof(float));
			_jumpForce = ImpactPatch.Field(owner, "JumpForce", typeof(float));
			_extraCapacity = ImpactPatch.Field(owner, "JumpExtra", typeof(int));
			_extraRemaining = ImpactPatch.Field(owner, "JumpExtraCurrent", typeof(int));
			_firstJump = ImpactPatch.Field(owner, "JumpFirst", typeof(bool));
			_physGrabObject = ImpactPatch.Field(type2, "physGrabObject", type4);
			_tumbleZeroGravityTimer = ImpactPatch.Field(type4, "timerZeroGravity", typeof(float));
			_grabbers = ImpactPatch.Field(type4, "playerGrabbing", typeof(List<>).MakeGenericType(type5));
			_jumpInput = ImpactPatch.Method(owner2, "InputDown", typeof(bool), type3);
			_noTextInput = (Func<bool>)ImpactPatch.Method(owner2, "NoTextInputsActive", typeof(bool)).CreateDelegate(typeof(Func<bool>));
			_hasAuthority = (Func<bool>)ImpactPatch.Method(owner2, "IsMasterClientOrSingleplayer", typeof(bool)).CreateDelegate(typeof(Func<bool>));
			_tumbleForce = ImpactPatch.Method(type2, "TumbleForce", typeof(void), typeof(Vector3));
			_requestTumble = ImpactPatch.Method(type2, "TumbleRequest", typeof(void), typeof(bool), typeof(bool));
			_resetMotion = ImpactPatch.Method(type2, "TumbleMotionReset", typeof(void));
			_jumpSound = ImpactPatch.Method(type, "Jump", typeof(void), typeof(bool));
			_antiGravity = ImpactPatch.Method(owner, "AntiGravity", typeof(void), typeof(float));
			_zeroGravity = ImpactPatch.Method(type4, "OverrideZeroGravity", typeof(void), typeof(float));
			_aimTransform = ImpactPatch.Method(type6, "GetOverrideTransform", typeof(Transform));
			_jumpKey = new object[1] { Enum.Parse(type3, "Jump") };
			_tumbleKey = new object[1] { Enum.Parse(type3, "Tumble") };
			_groundMask = LayerMask.GetMask(new string[2] { "Default", "PhysGrabObject" });
			_log = log;
			_logHits = logHits;
			harmony.Patch((MethodBase)ImpactPatch.Method(owner, "Update", typeof(void)), new HarmonyMethod(typeof(TumbleJump), "BeforeControllerUpdate", (Type[])null), new HarmonyMethod(typeof(TumbleJump), "AfterControllerUpdate", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)_requestTumble, new HarmonyMethod(typeof(TumbleJump), "KeepRedirectTumbling", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			Installed = true;
		}

		private static void BeforeControllerUpdate(Component __instance)
		{
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			if (Cursor.visible || !_noTextInput() || (float)_inputDisabled.GetValue(__instance) > 0f)
			{
				return;
			}
			object? value = _avatar.GetValue(__instance);
			Component val = (Component)((value is Component) ? value : null);
			if (val == null || (Object)(object)val == (Object)null)
			{
				return;
			}
			object value2 = _dead.GetValue(val);
			if (value2 is bool && (bool)value2)
			{
				return;
			}
			value2 = _disabled.GetValue(val);
			if (value2 is bool && (bool)value2)
			{
				return;
			}
			object? value3 = _avatarTumble.GetValue(val);
			Component val2 = (Component)((value3 is Component) ? value3 : null);
			if (val2 == null || (Object)(object)val2 == (Object)null)
			{
				return;
			}
			value2 = _isTumbling.GetValue(val2);
			if (!(value2 is bool) || !(bool)value2)
			{
				return;
			}
			object? value4 = _body.GetValue(val2);
			Rigidbody val3 = (Rigidbody)((value4 is Rigidbody) ? value4 : null);
			if (val3 == null || (Object)(object)val3 == (Object)null)
			{
				return;
			}
			value2 = _jumpInput.Invoke(null, _jumpKey);
			if (value2 is bool && (bool)value2)
			{
				if (WallRun.TryJumpOff(val2, val3))
				{
					KeepTumblingThisFrame(val2);
				}
				else if (ImpactPatch.WingLevel(val) > 0 && CanReserveJump(__instance, val2, val3))
				{
					_reservedJump = val2;
					_reservedJumpFrame = Time.frameCount;
				}
				return;
			}
			value2 = _jumpInput.Invoke(null, _tumbleKey);
			if (!(value2 is bool) || !(bool)value2)
			{
				return;
			}
			int num = ImpactPatch.WingLevel(val);
			if (num <= 0)
			{
				return;
			}
			object? value5 = _physGrabObject.GetValue(val2);
			Component val4 = (Component)((value5 is Component) ? value5 : null);
			if (val4 != null && (Object)(object)val4 != (Object)null && _grabbers.GetValue(val4) is IList { Count: >0 })
			{
				return;
			}
			bool flag = _hasAuthority();
			if (flag && val3.isKinematic)
			{
				return;
			}
			JumpState state = GetState(__instance);
			int num2 = RedirectLimit(num);
			if (state.RedirectsUsed >= num2 || state.ExitDeadline > Time.time)
			{
				return;
			}
			bool flag2 = WallRun.IsRunning(val2);
			Vector3 val5 = AimDirection(val);
			if (!flag2 && IsGrounded(val2, val3))
			{
				val5 = Vector3.ProjectOnPlane(val5, Vector3.up);
			}
			if (((Vector3)(ref val5)).sqrMagnitude < 0.01f)
			{
				val5 = val.transform.forward;
			}
			Vector3 linearVelocity = val3.linearVelocity;
			float num3 = Mathf.Max(((Vector3)(ref linearVelocity)).magnitude, (float)_sprintSpeed.GetValue(__instance));
			Vector3 val6 = ((Vector3)(ref val5)).normalized * num3;
			if (flag)
			{
				if (flag2)
				{
					WallRun.EndForRedirect(val2);
				}
				_resetMotion.Invoke(val2, null);
				_stunTime.SetValue(val2, 0f);
				object? value6 = _health.GetValue(val);
				Component val7 = (Component)((value6 is Component) ? value6 : null);
				if (val7 != null && (Object)(object)val7 != (Object)null)
				{
					value2 = _hurtFreeze.GetValue(val7);
					if (value2 is bool && (bool)value2)
					{
						_hurtFreezeTimer.SetValue(val7, 0f);
						_hurtFreeze.SetValue(val7, false);
					}
				}
				val3.linearVelocity = val6;
				if (flag2)
				{
					int num4 = ImpactPatch.LaunchLevel(val2);
					if (num4 > 0)
					{
						val3.AddForce(((Vector3)(ref val5)).normalized * (3f * (float)num4 * Plugin.Effects.WallLaunchMultiplier.Value), (ForceMode)1);
					}
				}
				WingFlight.Refill(val);
			}
			else
			{
				_tumbleForce.Invoke(val2, new object[1] { (val6 - linearVelocity) * val3.mass });
			}
			state.RedirectsUsed++;
			KeepTumblingThisFrame(val2);
			if (_logHits())
			{
				_log.LogInfo((object)string.Format("Tumble redirect{0}: {1:0.00} m/s, {2} redirects remaining.", flag2 ? " from wall run" : "", num3, num2 - state.RedirectsUsed));
			}
		}

		private static bool CanReserveJump(Component controller, Component tumble, Rigidbody body)
		{
			JumpState state = GetState(controller);
			if (!(state.ExitDeadline > Time.time) && (!(state.RetumbleDeadline <= 0f) || !(Time.time < state.ReadyAt)) && !((float)_overrideTime.GetValue(tumble) > 0f) && !((float)_stunTime.GetValue(tumble) > 0f))
			{
				object value = _override.GetValue(tumble);
				if (!(value is bool) || !(bool)value)
				{
					object? value2 = _physGrabObject.GetValue(tumble);
					Component val = (Component)((value2 is Component) ? value2 : null);
					if (val != null && (Object)(object)val != (Object)null && _grabbers.GetValue(val) is IList { Count: >0 })
					{
						return false;
					}
					if (!IsGrounded(tumble, body))
					{
						return state.Remaining > 0;
					}
					return true;
				}
			}
			return false;
		}

		private static void KeepTumblingThisFrame(Component tumble)
		{
			_redirectedTumble = tumble;
			_redirectFrame = Time.frameCount;
		}

		internal static bool TryRefundRedirect(Component controller, Component avatar, int count, out int remaining)
		{
			remaining = 0;
			int num = RedirectLimit(ImpactPatch.WingLevel(avatar));
			if (num <= 0 || count <= 0)
			{
				return false;
			}
			JumpState state = GetState(controller);
			if (state.RedirectsUsed <= 0)
			{
				return false;
			}
			state.RedirectsUsed = Math.Max(0, state.RedirectsUsed - count);
			remaining = Math.Max(0, num - state.RedirectsUsed);
			return true;
		}

		private static bool KeepRedirectTumbling(Component __instance, bool __0, bool __1)
		{
			if (!__0 && __1)
			{
				if (Time.frameCount != _redirectFrame || (Object)(object)__instance != (Object)(object)_redirectedTumble)
				{
					if (Time.frameCount == _reservedJumpFrame)
					{
						return (Object)(object)__instance != (Object)(object)_reservedJump;
					}
					return true;
				}
				return false;
			}
			return true;
		}

		private static int RedirectLimit(int level)
		{
			return (int)Math.Min(2147483647L, (long)Math.Max(0, level) * (long)Plugin.Effects.RedirectsPerLevel.Value);
		}

		private static void AfterControllerUpdate(Component __instance)
		{
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0361: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			object? value = _avatar.GetValue(__instance);
			Component val = (Component)((value is Component) ? value : null);
			if (val != null && !((Object)(object)val == (Object)null))
			{
				object? value2 = _avatarTumble.GetValue(val);
				Component val2 = (Component)((value2 is Component) ? value2 : null);
				if (val2 != null && !((Object)(object)val2 == (Object)null))
				{
					object value3 = _dead.GetValue(val);
					if (!(value3 is bool) || !(bool)value3)
					{
						value3 = _disabled.GetValue(val);
						if (!(value3 is bool) || !(bool)value3)
						{
							object? value4 = _body.GetValue(val2);
							Rigidbody val3 = (Rigidbody)((value4 is Rigidbody) ? value4 : null);
							if (val3 != null && !((Object)(object)val3 == (Object)null))
							{
								float time = Time.time;
								if (_redirectFrame == Time.frameCount && (Object)(object)val2 == (Object)(object)_redirectedTumble)
								{
									return;
								}
								value3 = _isTumbling.GetValue(val2);
								if (!(value3 is bool) || !(bool)value3)
								{
									if (States.TryGetValue(__instance, out JumpState value5))
									{
										UpdateStanding(__instance, val, value5, time);
									}
									return;
								}
								if (!Plugin.Effects.WingsEnabled.Value)
								{
									States.Remove(__instance);
									return;
								}
								if (!States.TryGetValue(__instance, out JumpState value6))
								{
									if (ImpactPatch.WingLevel(val) <= 0)
									{
										return;
									}
									value6 = GetState(__instance);
								}
								if (value6.RetumbleDeadline > 0f)
								{
									if (time <= value6.RetumbleDeadline)
									{
										Vector3 airTumbleVelocity = GetAirTumbleVelocity(__instance, val, value6.StandingVelocity);
										bool flag = _hasAuthority();
										if (flag && !val3.isKinematic)
										{
											val3.linearVelocity = airTumbleVelocity;
										}
										else if (!flag)
										{
											_tumbleForce.Invoke(val2, new object[1] { airTumbleVelocity * val3.mass });
										}
										_extraRemaining.SetValue(__instance, value6.Remaining);
										float num = value6.GravityDeadline - time;
										if (flag && num > 0f)
										{
											object? value7 = _physGrabObject.GetValue(val2);
											Component val4 = (Component)((value7 is Component) ? value7 : null);
											if (val4 != null && (Object)(object)val4 != (Object)null)
											{
												float num2 = Mathf.Max(num, (float)_tumbleZeroGravityTimer.GetValue(val4));
												_zeroGravity.Invoke(val4, new object[1] { num2 });
												if (num2 > 0f)
												{
													val3.useGravity = false;
												}
											}
										}
										value6.ReadyAt = time;
										if (flag)
										{
											WingFlight.Refill(val);
										}
										if (_logHits())
										{
											ManualLogSource log = _log;
											Vector3 val5 = Vector3.ProjectOnPlane(airTumbleVelocity, Vector3.up);
											log.LogInfo((object)$"Zero-gravity re-tumble: horizontal speed {((Vector3)(ref val5)).magnitude:0.00} m/s.");
										}
									}
									value6.RetumbleDeadline = 0f;
								}
								if (value6.ExitDeadline > time)
								{
									return;
								}
								value6.ExitDeadline = 0f;
								bool flag2 = time >= value6.ReadyAt && IsGrounded(val2, val3);
								if (flag2)
								{
									value6.Remaining = (int)_extraCapacity.GetValue(__instance);
								}
								if (Time.frameCount != _reservedJumpFrame || (Object)(object)val2 != (Object)(object)_reservedJump)
								{
									return;
								}
								_reservedJump = null;
								bool flag3 = !flag2;
								if ((!flag3 || value6.Remaining > 0) && ImpactPatch.WingLevel(val) > 0)
								{
									float num3 = (float)_jumpForce.GetValue(__instance) * (flag3 ? Plugin.Effects.ExtraJumpStrength.Value : 1f);
									Vector3 linearVelocity = val3.linearVelocity;
									linearVelocity.y = Mathf.Max(0f, linearVelocity.y) + num3 / val3.mass;
									value6.JumpVelocity = linearVelocity;
									value6.Extra = flag3;
									value6.ExitDeadline = time + 1f;
									_requestTumble.Invoke(val2, new object[2] { false, true });
									value3 = _isTumbling.GetValue(val2);
									if (!(value3 is bool) || !(bool)value3)
									{
										UpdateStanding(__instance, val, value6, time);
									}
								}
								return;
							}
						}
					}
				}
			}
			States.Remove(__instance);
		}

		private static Vector3 GetAirTumbleVelocity(Component controller, Component avatar, Vector3 velocity)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_005d: 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_0065: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Vector3 val = Vector3.ProjectOnPlane(AimDirection(avatar), Vector3.up);
			if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
			{
				val = Vector3.ProjectOnPlane(avatar.transform.forward, Vector3.up);
			}
			((Vector3)(ref val)).Normalize();
			float num = (float)_sprintSpeed.GetValue(controller) * Plugin.Effects.AirTumbleSprintMultiplier.Value;
			float num2 = Vector3.Dot(velocity, val);
			return velocity + val * Mathf.Max(0f, num - num2);
		}

		internal static Vector3 AimDirection(Component avatar)
		{
			//IL_0041: 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)
			object? value = _camera.GetValue(avatar);
			Component val = (Component)((value is Component) ? value : null);
			if (val != null && (Object)(object)val != (Object)null)
			{
				object? obj = _aimTransform.Invoke(val, null);
				Transform val2 = (Transform)((obj is Transform) ? obj : null);
				if (val2 != null && (Object)(object)val2 != (Object)null)
				{
					return val2.forward;
				}
			}
			return avatar.transform.forward;
		}

		private static JumpState GetState(Component controller)
		{
			return States.GetValue(controller, (Component key) => new JumpState
			{
				Remaining = (int)_extraRemaining.GetValue(key)
			});
		}

		private static void UpdateStanding(Component controller, Component avatar, JumpState state, float now)
		{
			//IL_003f: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			object? value = _standingBody.GetValue(controller);
			Rigidbody val = (Rigidbody)((value is Rigidbody) ? value : null);
			if (val == null || (Object)(object)val == (Object)null)
			{
				States.Remove(controller);
			}
			else if (state.ExitDeadline > now)
			{
				val.isKinematic = false;
				val.linearVelocity = state.JumpVelocity;
				state.StandingVelocity = state.JumpVelocity;
				state.ExitDeadline = 0f;
				float value2 = Plugin.Effects.ZeroGravitySeconds.Value;
				state.GravityDeadline = now + value2;
				state.RetumbleDeadline = now + Mathf.Max(1.25f, value2);
				state.ReadyAt = now + 0.18f;
				if (state.Extra)
				{
					state.Remaining--;
				}
				_extraRemaining.SetValue(controller, state.Remaining);
				_firstJump.SetValue(controller, false);
				_tumbleInputCooldown.SetValue(controller, 0f);
				if (value2 > 0f)
				{
					float num = Mathf.Max(value2, (float)_antiGravityTimer.GetValue(controller));
					_antiGravity.Invoke(controller, new object[1] { num });
				}
				_jumpSound.Invoke(avatar, new object[1] { state.Extra });
				if (_logHits())
				{
					_log.LogInfo((object)string.Format("Tumble jump released: {0}, {1} extra jumps remaining, {2:0.0} s zero gravity.", state.Extra ? "air" : "ground", state.Remaining, value2));
				}
			}
			else if (state.RetumbleDeadline > now)
			{
				state.StandingVelocity = val.linearVelocity;
				state.Remaining = Math.Min(state.Remaining, (int)_extraRemaining.GetValue(controller));
				if (now < state.ReadyAt)
				{
					_extraRemaining.SetValue(controller, state.Remaining);
					_firstJump.SetValue(controller, false);
				}
			}
			else
			{
				States.Remove(controller);
			}
		}

		internal static bool IsGrounded(Component tumble, Rigidbody body)
		{
			//IL_0001: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			if (body.linearVelocity.y > 0.6f || !(_colliders.GetValue(tumble) is Collider[] array))
			{
				return false;
			}
			Collider[] array2 = array;
			foreach (Collider val in array2)
			{
				if ((Object)(object)val == (Object)null || !val.enabled || val.isTrigger)
				{
					continue;
				}
				Bounds bounds = val.bounds;
				RaycastHit[] array3 = Physics.RaycastAll(((Bounds)(ref bounds)).center, Vector3.down, ((Bounds)(ref bounds)).extents.y + 0.08f, _groundMask, (QueryTriggerInteraction)1);
				for (int j = 0; j < array3.Length; j++)
				{
					RaycastHit val2 = array3[j];
					if (((RaycastHit)(ref val2)).normal.y >= 0.55f && (Object)(object)((RaycastHit)(ref val2)).rigidbody != (Object)(object)body && (Object)(object)((RaycastHit)(ref val2)).collider != (Object)(object)val)
					{
						return true;
					}
				}
			}
			return false;
		}
	}
	internal static class WallRun
	{
		private sealed class Contact
		{
			internal bool Running;

			internal bool MustLeaveWall;

			internal float Until;

			internal float NextRecharge;

			internal float ClearSince = -1f;

			internal Vector3 Normal;
		}

		private const float WallReach = 0.65f;

		private static readonly ConditionalWeakTable<Component, Contact> Contacts = new ConditionalWeakTable<Component, Contact>();

		private static FieldInfo _controller = null;

		private static FieldInfo _avatar = null;

		private static FieldInfo _local = null;

		private static FieldInfo _climb = null;

		private static FieldInfo _dead = null;

		private static FieldInfo _disabled = null;

		private static FieldInfo _tumbling = null;

		private static FieldInfo _body = null;

		private static FieldInfo _grabbable = null;

		private static FieldInfo _grabbers = null;

		private static FieldInfo _sprintSpeed = null;

		private static FieldInfo _energy = null;

		private static FieldInfo _sprintDrain = null;

		private static FieldInfo _sprintUpgrades = null;

		private static FieldInfo _rechargeTimer = null;

		private static FieldInfo _rechargeDelay = null;

		private static FieldInfo _debugEnergy = null;

		private static MethodInfo _gravity = null;

		private static Func<bool> _authority = null;

		private static Func<bool> _logHits = null;

		private static ManualLogSource _log = null;

		private static int _wallMask;

		internal static void Install(Harmony harmony, ManualLogSource log, Func<bool> logHits)
		{
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Expected O, but got Unknown
			Type type = ImpactPatch.RequireType("PlayerController");
			Type type2 = ImpactPatch.RequireType("PlayerAvatar");
			Type owner = ImpactPatch.RequireType("PlayerTumble");
			Type type3 = ImpactPatch.RequireType("PhysGrabObject");
			Type type4 = ImpactPatch.RequireType("PhysGrabber");
			Type owner2 = ImpactPatch.RequireType("SemiFunc");
			_controller = ImpactPatch.Field(type, "instance", type, isStatic: true);
			_avatar = ImpactPatch.Field(owner, "playerAvatar", type2);
			_local = ImpactPatch.Field(type2, "isLocal", typeof(bool));
			_climb = ImpactPatch.Field(type2, "upgradeTumbleClimb", typeof(float));
			_dead = ImpactPatch.Field(type2, "deadSet", typeof(bool));
			_disabled = ImpactPatch.Field(type2, "isDisabled", typeof(bool));
			_tumbling = ImpactPatch.Field(owner, "isTumbling", typeof(bool));
			_body = ImpactPatch.Field(owner, "rb", typeof(Rigidbody));
			_grabbable = ImpactPatch.Field(owner, "physGrabObject", type3);
			_grabbers = ImpactPatch.Field(type3, "playerGrabbing", typeof(List<>).MakeGenericType(type4));
			_sprintSpeed = ImpactPatch.Field(type, "SprintSpeed", typeof(float));
			_energy = ImpactPatch.Field(type, "EnergyCurrent", typeof(float));
			_sprintDrain = ImpactPatch.Field(type, "EnergySprintDrain", typeof(float));
			_sprintUpgrades = ImpactPatch.Field(type, "SprintSpeedUpgrades", typeof(float));
			_rechargeTimer = ImpactPatch.Field(type, "sprintRechargeTimer", typeof(float));
			_rechargeDelay = ImpactPatch.Field(type, "sprintRechargeTime", typeof(float));
			_debugEnergy = ImpactPatch.Field(type, "DebugEnergy", typeof(bool));
			_gravity = ImpactPatch.Method(owner, "GravityAccelerationGet", typeof(Vector3));
			_authority = (Func<bool>)ImpactPatch.Method(owner2, "IsMasterClientOrSingleplayer", typeof(bool)).CreateDelegate(typeof(Func<bool>));
			_log = log;
			_logHits = logHits;
			_wallMask = LayerMask.GetMask(new string[1] { "Default" });
			harmony.Patch((MethodBase)ImpactPatch.Method(owner, "FixedUpdate", typeof(void)), (HarmonyMethod)null, new HarmonyMethod(typeof(WallRun), "AfterTumblePhysics", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		internal static bool IsRunning(Component tumble)
		{
			if (Plugin.Effects.ClimbEnabled.Value && Contacts.TryGetValue(tumble, out Contact value))
			{
				return value.Running;
			}
			return false;
		}

		internal static bool TryJumpOff(Component tumble, Rigidbody body)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			if (!IsRunning(tumble) || !Contacts.TryGetValue(tumble, out Contact value))
			{
				return false;
			}
			Vector3 val = Vector3.ProjectOnPlane(body.linearVelocity, value.Normal);
			body.linearVelocity = val + value.Normal * Plugin.Effects.WallJumpOutward.Value + Vector3.up * Plugin.Effects.WallJumpUpward.Value;
			StopUntilClear(value);
			return true;
		}

		internal static void EndForRedirect(Component tumble)
		{
			if (Contacts.TryGetValue(tumble, out Contact value) && value.Running)
			{
				StopUntilClear(value);
			}
		}

		private static void StopUntilClear(Contact contact)
		{
			contact.Running = false;
			contact.MustLeaveWall = true;
		}

		private static void AfterTumblePhysics(Component __instance)
		{
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: 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_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_038a: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_041b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0420: Unknown result type (might be due to invalid IL or missing references)
			//IL_0422: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_0431: Unknown result type (might be due to invalid IL or missing references)
			//IL_0433: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.Effects.ClimbEnabled.Value && _authority())
			{
				object value = _tumbling.GetValue(__instance);
				if (value is bool && (bool)value)
				{
					object? value2 = _avatar.GetValue(__instance);
					Component val = (Component)((value2 is Component) ? value2 : null);
					if (val != null && !((Object)(object)val == (Object)null))
					{
						value = _local.GetValue(val);
						if (value is bool && (bool)value)
						{
							value = _dead.GetValue(val);
							if (!(value is bool) || !(bool)value)
							{
								value = _disabled.GetValue(val);
								if (!(value is bool) || !(bool)value)
								{
									object? value3 = _body.GetValue(__instance);
									Rigidbody val2 = (Rigidbody)((value3 is Rigidbody) ? value3 : null);
									if (val2 != null && !((Object)(object)val2 == (Object)null) && !val2.isKinematic)
									{
										object? value4 = _controller.GetValue(null);
										Component val3 = (Component)((value4 is Component) ? value4 : null);
										if (val3 != null && !((Object)(object)val3 == (Object)null) && _climb.GetValue(val) is float num && !(num < 1f))
										{
											Contact value5 = Contacts.GetValue(__instance, (Component _) => new Contact());
											float fixedTime = Time.fixedTime;
											object? value6 = _grabbable.GetValue(__instance);
											Component val4 = (Component)((value6 is Component) ? value6 : null);
											if ((val4 != null && (Object)(object)val4 != (Object)null && _grabbers.GetValue(val4) is IList { Count: >0 }) || TumbleJump.IsGrounded(__instance, val2))
											{
												Contacts.Remove(__instance);
												return;
											}
											Vector3 val5 = Vector3.ProjectOnPlane(TumbleJump.AimDirection(val), Vector3.up);
											Vector3 normalized = ((Vector3)(ref val5)).normalized;
											Vector3 val6 = Vector3.ProjectOnPlane(val2.linearVelocity, Vector3.up);
											if (!TryFindWall(val2, normalized, val6, value5, out var normal))
											{
												value5.Running = false;
												if (value5.ClearSince < 0f)
												{
													value5.ClearSince = fixedTime;
												}
												if (fixedTime - value5.ClearSince >= 0.15f)
												{
													value5.MustLeaveWall = false;
												}
												return;
											}
											value5.ClearSince = -1f;
											if (value5.MustLeaveWall || (!value5.Running && ((Vector3)(ref val6)).sqrMagnitude < 0.56f))
											{
												return;
											}
											float num2 = Plugin.Effects.WallDuration.Value + Plugin.Effects.WallDurationPerLevel.Value * (num - 1f);
											if (!value5.Running && num2 <= 0f)
											{
												return;
											}
											if ((value5.Running && fixedTime >= value5.Until) || !SpendSprintEnergy(val3))
											{
												StopUntilClear(value5);
												return;
											}
											float value7 = Plugin.Effects.WallRefundInterval.Value;
											if (!value5.Running)
											{
												value5.Running = true;
												value5.Until = fixedTime + num2;
												value5.NextRecharge = fixedTime + value7;
												Recharge(val3, val, Plugin.Effects.WallEntryRefund.Value, "entry");
											}
											else if (value7 > 0f && fixedTime >= value5.NextRecharge)
											{
												value5.NextRecharge = fixedTime + value7;
												Recharge(val3, val, Plugin.Effects.WallPeriodicRefund.Value, "interval");
											}
											value5.Normal = normal;
											Vector3 val7 = Vector3.ProjectOnPlane(normalized, normal);
											if (((Vector3)(ref val7)).sqrMagnitude < 0.04f)
											{
												val7 = Vector3.ProjectOnPlane(val6, normal);
											}
											if (((Vector3)(ref val7)).sqrMagnitude < 0.04f)
											{
												val7 = Vector3.Cross(Vector3.up, normal);
											}
											float num3 = Mathf.Max(((Vector3)(ref val6)).magnitude, (float)_sprintSpeed.GetValue(val3) * Plugin.Effects.WallSpeed.Value);
											val2.linearVelocity = ((Vector3)(ref val7)).normalized * num3 - normal * 0.45f;
											if (_gravity.Invoke(__instance, null) is Vector3 val8 && val8 != Vector3.zero)
											{
												val2.AddForce(-val8, (ForceMode)5);
											}
											return;
										}
									}
								}
							}
						}
					}
				}
			}
			Contacts.Remove(__instance);
		}

		private static bool SpendSprintEnergy(Component controller)
		{
			float value = Plugin.Effects.WallStaminaRate.Value;
			if (!(value <= 0f))
			{
				object value2 = _debugEnergy.GetValue(controller);
				if (!(value2 is bool) || !(bool)value2)
				{
					float num = (float)_energy.GetValue(controller);
					if (num <= 0f)
					{
						return false;
					}
					float num2 = (float)_sprintDrain.GetValue(controller) + (float)_sprintUpgrades.GetValue(controller);
					float num3 = Mathf.Max(0f, num - Mathf.Max(0f, num2) * value * Time.fixedDeltaTime);
					_energy.SetValue(controller, num3);
					_rechargeTimer.SetValue(controller, Mathf.Max((float)_rechargeTimer.GetValue(controller), (float)_rechargeDelay.GetValue(controller)));
					return num3 > 0f;
				}
			}
			return true;
		}

		private static bool TryFindWall(Rigidbody body, Vector3 aim, Vector3 travel, Contact contact, out Vector3 normal)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0042: 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_004a: 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_005b: 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_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_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Vector3.Cross(Vector3.up, aim);
			Vector3[] array = (Vector3[])(object)new Vector3[5]
			{
				-contact.Normal,
				((Vector3)(ref travel)).normalized,
				val,
				-val,
				aim
			};
			RaycastHit val3 = default(RaycastHit);
			for (int i = 0; i < array.Length; i++)
			{
				Vector3 val2 = array[i];
				if (!(((Vector3)(ref val2)).sqrMagnitude < 0.1f) && Physics.Raycast(body.worldCenterOfMass, val2, ref val3, 0.65f, _wallMask, (QueryTriggerInteraction)1) && !((Object)(object)((RaycastHit)(ref val3)).rigidbody == (Object)(object)body) && !(Mathf.Abs(((RaycastHit)(ref val3)).normal.y) > 0.2f))
				{
					Vector3 val4 = Vector3.ProjectOnPlane(((RaycastHit)(ref val3)).normal, Vector3.up);
					normal = ((Vector3)(ref val4)).normalized;
					return true;
				}
			}
			normal = default(Vector3);
			return false;
		}

		private static void Recharge(Component controller, Component avatar, int count, string reason)
		{
			if (TumbleJump.TryRefundRedirect(controller, avatar, count, out var remaining) && _logHits())
			{
				_log.LogInfo((object)$"Wall run recharge ({reason}): {remaining} redirects remaining.");
			}
		}
	}
	internal static class WingFlight
	{
		private sealed class RefillState
		{
			internal bool StartedInAir;
		}

		private static readonly ConditionalWeakTable<Component, RefillState> Refills = new ConditionalWeakTable<Component, RefillState>();

		private static FieldInfo _avatar = null;

		private static FieldInfo _tumble = null;

		private static FieldInfo _avatarWing = null;

		private static FieldInfo _timer = null;

		private static FieldInfo _grounded = null;

		private static FieldInfo _ready = null;

		private static FieldInfo _fetchComplete = null;

		private static FieldInfo _dead = null;

		private static FieldInfo _disabled = null;

		private static FieldInfo _tumbling = null;

		private static FieldInfo _body = null;

		private static FieldInfo _grabbable = null;

		private static FieldInfo _grabbers = null;

		private static MethodInfo _showWings = null;

		private static MethodInfo _wingsActive = null;

		private static MethodInfo _pinkWings = null;

		private static MethodInfo _gravity = null;

		private static Func<bool> _hasAuthority = null;

		private static Func<bool> _logHits = null;

		private static ManualLogSource _log = null;

		private static bool _installed;

		internal static void Install(Harmony harmony, ManualLogSource log, Func<bool> logHits)
		{
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Expected O, but got Unknown
			Type type = ImpactPatch.RequireType("ItemUpgradePlayerTumbleWingsLogic");
			Type type2 = ImpactPatch.RequireType("PlayerAvatar");
			Type type3 = ImpactPatch.RequireType("PlayerTumble");
			Type type4 = ImpactPatch.RequireType("PhysGrabObject");
			Type type5 = ImpactPatch.RequireType("PhysGrabber");
			Type owner = ImpactPatch.RequireType("SemiFunc");
			_avatar = ImpactPatch.Field(type, "playerAvatar", type2);
			_tumble = ImpactPatch.Field(type, "playerTumble", type3);
			_avatarWing = ImpactPatch.Field(type2, "upgradeTumbleWingsLogic", type);
			_timer = ImpactPatch.Field(type, "tumbleWingTimer", typeof(float));
			_grounded = ImpactPatch.Field(type, "hasBeenGrounded", typeof(bool));
			_ready = ImpactPatch.Field(type, "lateStartDone", typeof(bool));
			_fetchComplete = ImpactPatch.Field(type, "fetchComplete", typeof(bool));
			_dead = ImpactPatch.Field(type2, "deadSet", typeof(bool));
			_disabled = ImpactPatch.Field(type2, "isDisabled", typeof(bool));
			_tumbling = ImpactPatch.Field(type3, "isTumbling", typeof(bool));
			_body = ImpactPatch.Field(type3, "rb", typeof(Rigidbody));
			_grabbable = ImpactPatch.Field(type, "physGrabObject", type4);
			_grabbers = ImpactPatch.Field(type4, "playerGrabbing", typeof(List<>).MakeGenericType(type5));
			_showWings = ImpactPatch.Method(type2, "OverrideTumbleWings", typeof(void), typeof(bool), typeof(float));
			_wingsActive = ImpactPatch.Method(type2, "get_upgradeTumbleWingsVisualsActive", typeof(bool));
			_pinkWings = ImpactPatch.Method(type2, "get_upgradeTumbleWingsVisualsPink", typeof(bool));
			_gravity = ImpactPatch.Method(type3, "GravityAccelerationGet", typeof(Vector3));
			_hasAuthority = (Func<bool>)ImpactPatch.Method(owner, "IsMasterClientOrSingleplayer", typeof(bool)).CreateDelegate(typeof(Func<bool>));
			_log = log;
			_logHits = logHits;
			harmony.Patch((MethodBase)ImpactPatch.Method(type, "FixedUpdate", typeof(void)), (HarmonyMethod)null, new HarmonyMethod(typeof(WingFlight), "Steer", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			_installed = true;
		}

		internal static void Refill(Component avatar)
		{
			float value = Plugin.Effects.WingRefill.Value;
			if (!_installed || !Plugin.Effects.WingsEnabled.Value || value <= 0f)
			{
				return;
			}
			object? value2 = _avatarWing.GetValue(avatar);
			Behaviour val = (Behaviour)((value2 is Behaviour) ? value2 : null);
			if (val != null && !((Object)(object)val == (Object)null) && val.isActiveAndEnabled)
			{
				float num = Mathf.Max((float)_timer.GetValue(val), value);
				_timer.SetValue(val, num);
				Refills.Remove((Component)(object)val);
				Refills.Add((Component)(object)val, new RefillState());
				if (_logHits())
				{
					_log.LogInfo((object)$"Tumble Wings refilled to {num:P0}.");
				}
			}
		}

		private static void Steer(Component __instance)
		{
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.Effects.WingsEnabled.Value)
			{
				Refills.Remove(__instance);
			}
			else
			{
				if (!_hasAuthority())
				{
					return;
				}
				object value = _ready.GetValue(__instance);
				if (!(value is bool) || !(bool)value)
				{
					return;
				}
				value = _fetchComplete.GetValue(__instance);
				if (!(value is bool) || !(bool)value)
				{
					return;
				}
				object? value2 = _avatar.GetValue(__instance);
				Component val = (Component)((value2 is Component) ? value2 : null);
				if (val != null && !((Object)(object)val == (Object)null))
				{
					value = _dead.GetValue(val);
					if (!(value is bool) || !(bool)value)
					{
						value = _disabled.GetValue(val);
						if (!(value is bool) || !(bool)value)
						{
							object? value3 = _tumble.GetValue(__instance);
							Component val2 = (Component)((value3 is Component) ? value3 : null);
							if (val2 != null && !((Object)(object)val2 == (Object)null))
							{
								value = _tumbling.GetValue(val2);
								if (value is bool && (bool)value && !((float)_timer.GetValue(__instance) <= 0f))
								{
									if (WallRun.IsRunning(val2))
									{
										return;
									}
									value = _pinkWings.Invoke(val, null);
									if (value is bool && (bool)value)
									{
										return;
									}
									object? value4 = _body.GetValue(val2);
									Rigidbody val3 = (Rigidbody)((value4 is Rigidbody) ? value4 : null);
									if (val3 == null || (Object)(object)val3 == (Object)null || val3.isKinematic)
									{
										return;
									}
									object? value5 = _grabbable.GetValue(__instance);
									Component val4 = (Component)((value5 is Component) ? value5 : null);
									if (val4 != null && (Object)(object)val4 != (Object)null && _grabbers.GetValue(val4) is IList { Count: >0 })
									{
										return;
									}
									RefillState value6;
									bool flag = Refills.TryGetValue(__instance, out value6);
									if (!flag)
									{
										value = _wingsActive.Invoke(val, null);
										if (!(value is bool) || !(bool)value)
										{
											return;
										}
									}
									if (TumbleJump.IsGrounded(val2, val3))
									{
										if (flag && value6.StartedInAir)
										{
											Refills.Remove(__instance);
										}
										return;
									}
									if (flag)
									{
										value6.StartedInAir = true;
										_grounded.SetValue(__instance, false);
										_showWings.Invoke(val, new object[2] { false, 0.2f });
									}
									float value7 = Plugin.Effects.TurnSpeed.Value;
									if (!(value7 <= 0f))
									{
										Vector3 val5 = TumbleJump.AimDirection(val);
										Vector3 normalized = ((Vector3)(ref val5)).normalized;
										Vector3 linearVelocity = val3.linearVelocity;
										float num = Mathf.Max(((Vector3)(ref linearVelocity)).magnitude, Plugin.Effects.MinimumFlightSpeed.Value);
										Vector3 val6 = ((((Vector3)(ref linearVelocity)).sqrMagnitude < 0.01f) ? normalized : Vector3.RotateTowards(((Vector3)(ref linearVelocity)).normalized, normalized, value7 * (MathF.PI / 180f) * Time.fixedDeltaTime, 0f));
										val3.linearVelocity = val6 * num;
										if (_gravity.Invoke(val2, null) is Vector3 val7 && val7 != Vector3.zero)
										{
											val3.AddForce(-val7, (ForceMode)5);
										}
									}
									return;
								}
							}
						}
					}
				}
				Refills.Remove(__instance);
			}
		}
	}
}