Decompiled source of SourceGolf v1.1.0

plugins/SourceGolf.dll

Decompiled 41 minutes ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Epic.OnlineServices;
using Epic.OnlineServices.Lobby;
using HarmonyLib;
using Mirror;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.LowLevel;
using UnityEngine.Localization.Components;
using UnityEngine.UI;

[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("SourceGolf")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+1215e4465b1a38a6135382b40652ea6413db62f3")]
[assembly: AssemblyProduct("SourceGolf")]
[assembly: AssemblyTitle("SourceGolf")]
[assembly: InternalsVisibleTo("SourceGolf.RangeProbe")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace SourceGolf;

internal static class AirAcceleration
{
	internal static void Assist(ref float side, ref float forward, int turn, bool allowForwardOnly)
	{
		if (!(forward <= 0.001f))
		{
			float num = MathF.Min(1f, MathF.Sqrt(side * side + forward * forward));
			int num2 = ((MathF.Abs(side) > 0.2f * num) ? Math.Sign(side) : (allowForwardOnly ? turn : 0));
			if (num2 != 0)
			{
				side = (float)num2 * num;
				forward = 0f;
			}
		}
	}

	internal static void Step(ref float vx, ref float vz, float inputX, float inputZ, float moveSpeed, float deltaTime, float acceleration = 10f, float directionalCap = 0.96f)
	{
		float num = MathF.Sqrt(inputX * inputX + inputZ * inputZ);
		if (!(num <= 1E-05f) && !(moveSpeed <= 0f) && !(deltaTime <= 0f))
		{
			float num2 = inputX / num;
			float num3 = inputZ / num;
			float num4 = moveSpeed * MathF.Min(num, 1f);
			float num5 = MathF.Min(num4, directionalCap) - (vx * num2 + vz * num3);
			if (!(num5 <= 0f))
			{
				float num6 = MathF.Min(num5, acceleration * num4 * deltaTime);
				vx += num2 * num6;
				vz += num3 * num6;
			}
		}
	}
}
[HarmonyPatch(typeof(SettingsMenu), "Start")]
internal static class AssistOption
{
	private static readonly FieldRef<DropdownOption, TextMeshProUGUI> Label = AccessTools.FieldRefAccess<DropdownOption, TextMeshProUGUI>("nameLabel");

	private static void Postfix(SettingsMenu __instance)
	{
		DropdownOption mouseInvertY = __instance.mouseInvertY;
		DropdownOption option = Object.Instantiate<DropdownOption>(mouseInvertY, ((Component)mouseInvertY).transform.parent, false);
		((Object)option).name = "Assisted Air Strafing";
		((Component)option).transform.SetSiblingIndex(((Component)mouseInvertY).transform.GetSiblingIndex() + 1);
		TextMeshProUGUI obj = Label.Invoke(option);
		LocalizeStringEvent component = ((Component)obj).GetComponent<LocalizeStringEvent>();
		if (Object.op_Implicit((Object)(object)component))
		{
			((Behaviour)component).enabled = false;
		}
		((TMP_Text)obj).text = ((Object)option).name;
		option.valueWithoutNotify = ((!Plugin.Assisted.Value) ? 1 : 0);
		option.Initialize((Action)delegate
		{
			Plugin.Assisted.Value = option.value == 0;
		}, -1);
	}
}
internal static class CrouchGeometry
{
	internal static float LowHeight(float standingHeight)
	{
		return standingHeight * 0.5f;
	}

	internal static float FootShift(float fromHeight, float toHeight, bool grounded)
	{
		if (!grounded)
		{
			return fromHeight - toHeight;
		}
		return 0f;
	}
}
internal enum Stance : byte
{
	Standing,
	Crouched,
	Sliding
}
[HarmonyPatch]
internal static class CrouchSlide
{
	private sealed class State
	{
		internal Stance Mode;

		internal float Elapsed;

		internal float Grace;

		internal bool Landed;

		internal float? AirHeadHeight;
	}

	private static readonly Dictionary<PlayerMovement, State> States = new Dictionary<PlayerMovement, State>();

	private static readonly Collider[] Overlaps = (Collider[])(object)new Collider[64];

	private static readonly FieldRef<PlayerMovement, CapsuleColliderSettings> Upright = AccessTools.FieldRefAccess<PlayerMovement, CapsuleColliderSettings>("uprightColliderDefaultSettings");

	private static readonly FieldRef<PlayerMovement, CapsuleColliderSettings> Hittable = AccessTools.FieldRefAccess<PlayerMovement, CapsuleColliderSettings>("hittableColliderDefaultSettings");

	private static readonly FieldRef<PlayerMovement, CapsuleColliderSettings> Giant = AccessTools.FieldRefAccess<PlayerMovement, CapsuleColliderSettings>("jumboBurgerGiantPlayerCollisionColliderDefaultSettings");

	private static readonly FieldRef<PlayerMovement, CapsuleCollider> GiantCollider = AccessTools.FieldRefAccess<PlayerMovement, CapsuleCollider>("jumboBurgerGiantPlayerCollisionCollider");

	private static readonly Action<PlayerMovement, DivingState> SetDiveState = AccessTools.MethodDelegate<Action<PlayerMovement, DivingState>>(AccessTools.Method(typeof(PlayerMovement), "SetDivingState", (Type[])null, (Type[])null), (object)null, true);

	internal static Stance Mode(PlayerMovement p)
	{
		if (!Object.op_Implicit((Object)(object)p) || !States.TryGetValue(p, out var value))
		{
			return Stance.Standing;
		}
		return value.Mode;
	}

	internal static float Height(PlayerMovement p)
	{
		return Upright.Invoke(p).height * p.GetEffectiveCharacterScale();
	}

	private static bool Eligible(PlayerMovement p)
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Invalid comparison between Unknown and I4
		if (p.IsVisible && !p.IsRespawningOrDrowning && !p.IsKnockedOutOrRecovering && !p.IsWadingInWater)
		{
			GolfCartSeat activeGolfCartSeat = p.PlayerInfo.ActiveGolfCartSeat;
			if (!((GolfCartSeat)(ref activeGolfCartSeat)).IsValid() && (int)p.PlayerInfo.AsHittable.FrozenState != 2 && !p.PlayerInfo.AsSpectator.IsSpectating)
			{
				return !p.PlayerInfo.AsGolfer.IsMatchResolved;
			}
		}
		return false;
	}

	private static void ApplyShape(PlayerMovement p, bool low)
	{
		//IL_0026: 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_0066: Unknown result type (might be due to invalid IL or missing references)
		float scale = p.GetEffectiveCharacterScale();
		Apply(p.UprightCollider, Upright.Invoke(p));
		Apply(p.HittableCollider, Hittable.Invoke(p));
		Apply(GiantCollider.Invoke(p), Giant.Invoke(p));
		void Apply(CapsuleCollider collider, CapsuleColliderSettings original)
		{
			//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_001f: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)collider))
			{
				CapsuleColliderSettings val = ((CapsuleColliderSettings)(ref original)).Scale(scale);
				if (low)
				{
					float num = CrouchGeometry.LowHeight(val.height);
					val.localCenter.y -= (val.height - num) * 0.5f;
					val.height = num;
					val.radius = Mathf.Min(val.radius, val.height * 0.5f);
				}
				((CapsuleColliderSettings)(ref val)).ApplyTo(collider);
			}
		}
	}

	private static void Set(PlayerMovement p, Stance mode, bool moveFeet = false)
	{
		//IL_0055: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00df: Unknown result type (might be due to invalid IL or missing references)
		Stance stance = Mode(p);
		if (stance == mode)
		{
			return;
		}
		float? airHeadHeight = null;
		if (stance == Stance.Standing && mode == Stance.Crouched && !p.IsGrounded && Object.op_Implicit((Object)(object)p.PlayerInfo.HeadBone))
		{
			float num = Height(p);
			float num2 = CrouchGeometry.FootShift(num, CrouchGeometry.LowHeight(num), grounded: false);
			airHeadHeight = p.PlayerInfo.HeadBone.position.y - ((Component)p).transform.position.y - num2;
		}
		if (stance == Stance.Standing != (mode == Stance.Standing))
		{
			if (moveFeet)
			{
				float num3 = Height(p);
				float num4 = CrouchGeometry.LowHeight(num3);
				float num5 = ((mode == Stance.Standing) ? CrouchGeometry.FootShift(num4, num3, grounded: false) : CrouchGeometry.FootShift(num3, num4, grounded: false));
				Rigidbody rigidbody = p.PlayerInfo.Rigidbody;
				rigidbody.position += Vector3.up * num5;
				((Component)p).transform.position = rigidbody.position;
			}
			ApplyShape(p, mode != Stance.Standing);
		}
		if (mode == Stance.Standing)
		{
			States.Remove(p);
			return;
		}
		if (!States.TryGetValue(p, out var value))
		{
			value = (States[p] = new State());
		}
		value.Mode = mode;
		value.AirHeadHeight = airHeadHeight;
	}

	internal static float AirPoseDrop(PlayerMovement p)
	{
		//IL_004a: 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)
		if (p.IsGrounded || !States.TryGetValue(p, out var value) || !value.AirHeadHeight.HasValue)
		{
			return 0f;
		}
		Transform headBone = p.PlayerInfo.HeadBone;
		if (!Object.op_Implicit((Object)(object)headBone))
		{
			return 0f;
		}
		return Mathf.Max(0f, headBone.position.y - ((Component)p).transform.position.y - value.AirHeadHeight.Value);
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(PlayerMovement), "UpdateIsGroundedAtAll")]
	private static void ReleaseAirPoseOnLanding(PlayerMovement __instance, bool ___isGroundedAtAll)
	{
		if (___isGroundedAtAll && States.TryGetValue(__instance, out var value))
		{
			value.AirHeadHeight = null;
		}
	}

	internal static void ApplyRemote(PlayerMovement p, Stance mode)
	{
		if (Object.op_Implicit((Object)(object)p) && !((NetworkBehaviour)p).isLocalPlayer)
		{
			Set(p, mode);
		}
	}

	internal static void Clear()
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		foreach (PlayerMovement item in new List<PlayerMovement>(States.Keys))
		{
			if (Object.op_Implicit((Object)(object)item))
			{
				Set(item, Stance.Standing, ((NetworkBehaviour)item).isLocalPlayer && !item.IsGrounded && Eligible(item) && (int)item.DivingState == 0 && !item.PlayerInfo.Rigidbody.isKinematic);
			}
		}
		States.Clear();
	}

	private static bool CanStand(PlayerMovement p)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: 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_0030: 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_0036: 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_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: 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)
		CapsuleCollider uprightCollider = p.UprightCollider;
		CapsuleColliderSettings val = ((CapsuleColliderSettings)(ref Upright.Invoke(p))).Scale(p.GetEffectiveCharacterScale());
		Vector3 val2 = ((Component)uprightCollider).transform.TransformPoint(val.localCenter);
		val2 += Vector3.up * CrouchGeometry.FootShift(CrouchGeometry.LowHeight(val.height), val.height, p.IsGrounded);
		Vector3 val3 = Vector3.up * Mathf.Max(0f, val.height * 0.5f - val.radius);
		float num = Mathf.Max(0.001f, val.radius - 0.005f);
		int layer = ((Component)uprightCollider).gameObject.layer;
		int num2 = Physics.OverlapCapsuleNonAlloc(val2 - val3, val2 + val3, num, Overlaps, ~LayerMask.op_Implicit(((Collider)uprightCollider).excludeLayers), (QueryTriggerInteraction)1);
		if (num2 == Overlaps.Length)
		{
			return false;
		}
		for (int i = 0; i < num2; i++)
		{
			Collider val4 = Overlaps[i];
			if (!((Object)(object)val4.attachedRigidbody == (Object)(object)p.PlayerInfo.Rigidbody) && !((Component)val4).transform.IsChildOf(((Component)p).transform) && !Physics.GetIgnoreLayerCollision(layer, ((Component)val4).gameObject.layer) && !Physics.GetIgnoreCollision((Collider)(object)uprightCollider, val4))
			{
				return false;
			}
		}
		return true;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(PlayerMovement), "FixedUpdate")]
	private static void BeforePhysics(PlayerMovement __instance)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		if (!Plugin.MovementEnabled || !((NetworkBehaviour)__instance).isLocalPlayer)
		{
			return;
		}
		if (!Eligible(__instance) || (int)__instance.DivingState != 0 || __instance.PlayerInfo.Rigidbody.isKinematic)
		{
			Set(__instance, Stance.Standing);
			return;
		}
		if (__instance.PlayerInfo.Input.IsHoldingWalk)
		{
			PlayerGolfer asGolfer = __instance.PlayerInfo.AsGolfer;
			PlayerInventory inventory = __instance.PlayerInfo.Inventory;
			if (!__instance.IsGrounded || Mode(__instance) == Stance.Standing || asGolfer.IsSwinging || asGolfer.IsAimingSwing || asGolfer.IsChargingSwing || inventory.IsUsingItemAtAll || inventory.IsAimingItem)
			{
				Set(__instance, Stance.Crouched, !__instance.IsGrounded);
			}
		}
		else if (Mode(__instance) != Stance.Standing)
		{
			if (CanStand(__instance))
			{
				Set(__instance, Stance.Standing, !__instance.IsGrounded);
			}
			else
			{
				Set(__instance, Stance.Crouched);
			}
		}
		if (States.TryGetValue(__instance, out var value))
		{
			value.Landed = !__instance.IsGrounded;
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(PlayerMovement), "ApplyCharacterScale")]
	private static void Rescale(PlayerMovement __instance)
	{
		if (Mode(__instance) != Stance.Standing)
		{
			ApplyShape(__instance, low: true);
		}
	}

	private static float ViewDrop(Transform subject)
	{
		if (States.Count == 0 || !Object.op_Implicit((Object)(object)subject))
		{
			return 0f;
		}
		PlayerMovement component = ((Component)subject).GetComponent<PlayerMovement>();
		if (Mode(component) != Stance.Standing)
		{
			return Height(component) * 0.5f;
		}
		return 0f;
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(OrbitCameraModule), "GetCurrentTargetTrackedPoint")]
	private static void OrbitEye(OrbitCameraModule __instance, ref Vector3 __result)
	{
		__result.y -= ViewDrop(__instance.Subject);
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(FirstPersonCameraModule), "UpdateModule")]
	private static void FirstPersonEye(FirstPersonCameraModule __instance)
	{
		((CameraModule)__instance).position.y -= ViewDrop(__instance.Viewer);
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(PlayerMovement), "TryDive")]
	private static bool CanDive(PlayerMovement __instance, ref bool __result)
	{
		if (Mode(__instance) != Stance.Sliding)
		{
			return true;
		}
		__result = false;
		return false;
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(PlayerMovement), "Unground")]
	private static void LeftGround(PlayerMovement __instance)
	{
		if (Mode(__instance) == Stance.Sliding)
		{
			Set(__instance, Stance.Crouched);
		}
	}

	private static bool Downhill(Vector3 normal, Vector3 travel)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		if (normal.y < 0.994522f)
		{
			return Vector3.Dot(travel, Vector3.down) > 0.001f;
		}
		return false;
	}

	private static Vector3 AlongGround(Vector3 velocity, Vector3 normal)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: 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_0022: 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)
		return new Vector3(velocity.x, (0f - (normal.x * velocity.x + normal.z * velocity.z)) / normal.y, velocity.z);
	}

	internal static bool IsSlideTakeoff(PlayerMovement p)
	{
		//IL_003f: 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_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		if (!p.IsGrounded || !States.TryGetValue(p, out var value))
		{
			return false;
		}
		if (value.Mode == Stance.Sliding)
		{
			return true;
		}
		if (!value.Landed || !p.PlayerInfo.Input.IsHoldingWalk || (int)p.DivingState != 0 || !Eligible(p) || !MovementPatch.CanApplyMovement(p))
		{
			return false;
		}
		PlayerGroundData groundData = p.GroundData;
		Vector3 normalized = ((Vector3)(ref groundData.normal)).normalized;
		Vector3 travel = AlongGround(p.Velocity, normalized);
		return Plugin.Tuning.CanStartSlide(((Vector3)(ref travel)).magnitude, Downhill(normalized, travel));
	}

	private static void BeginSlide(PlayerMovement p, bool landing)
	{
		Set(p, Stance.Sliding);
		State state = States[p];
		state.Elapsed = 0f;
		state.Grace = (landing ? 0.75f : 0.6f);
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(PlayerMovement), "SetDivingState")]
	private static void CaptureLanding(PlayerMovement __instance, DivingState state, out bool __state)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Invalid comparison between Unknown and I4
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Invalid comparison between Unknown and I4
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		__state = Plugin.MovementEnabled && ((NetworkBehaviour)__instance).isLocalPlayer && (int)state == 2 && (int)__instance.DivingState == 1 && (int)__instance.DiveType == 0 && Eligible(__instance) && __instance.PlayerInfo.Input.IsHoldingWalk;
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(PlayerMovement), "SetDivingState")]
	private static void FinishLanding(PlayerMovement __instance, bool __state)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: 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_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: 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_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: 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_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_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: 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_00a7: 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)
		if (__state)
		{
			PlayerGroundData groundData = __instance.GroundData;
			Vector3 val = __instance.PlayerInfo.Rigidbody.linearVelocity;
			if (groundData.hasRigidbody && Object.op_Implicit((Object)(object)groundData.rigidbody))
			{
				val -= groundData.rigidbody.GetPointVelocity(groundData.point);
			}
			Vector3 travel = Vector3.ProjectOnPlane(new Vector3(val.x, 0f, val.z), groundData.normal);
			if (!(groundData.normal.y <= 0f) && !(Vector3.Angle(Vector3.up, groundData.normal) > GameManager.PlayerMovementSettings.UngroundableGroundPitchThreshold) && Plugin.Tuning.CanStartSlide(((Vector3)(ref travel)).magnitude, Downhill(groundData.normal, travel)))
			{
				BeginSlide(__instance, landing: true);
				SetDiveState(__instance, (DivingState)0);
			}
		}
	}

	internal static bool TrySlide(PlayerMovement p, Vector3 input, out Vector3 result)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_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_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_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: 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_00c9: 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_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: 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_014b: 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)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		result = p.Velocity;
		if (!p.IsGrounded || !p.PlayerInfo.Input.IsHoldingWalk || !States.TryGetValue(p, out var value))
		{
			return false;
		}
		PlayerGroundData groundData = p.GroundData;
		Vector3 normalized = ((Vector3)(ref groundData.normal)).normalized;
		Vector3 val = AlongGround(result, normalized);
		float num = result.y - val.y;
		bool flag = Downhill(normalized, val);
		MovementTuning tuning = Plugin.Tuning;
		if (value.Mode != Stance.Sliding)
		{
			if (!tuning.CanStartSlide(((Vector3)(ref val)).magnitude, flag))
			{
				return false;
			}
			BeginSlide(p, value.Landed);
		}
		else if (!flag && ((Vector3)(ref val)).magnitude < tuning.SlideExit)
		{
			Set(p, Stance.Crouched);
			return false;
		}
		float fixedDeltaTime = Time.fixedDeltaTime;
		Vector3 val2 = Vector3.ProjectOnPlane(input, normalized);
		if (((Vector3)(ref val2)).sqrMagnitude > 0.0001f && ((Vector3)(ref val)).sqrMagnitude > 0.0001f)
		{
			float errorDegrees = Vector3.SignedAngle(val, val2, normalized);
			val = Quaternion.AngleAxis(tuning.SteerSlide(errorDegrees, Mathf.Clamp01(((Vector3)(ref input)).magnitude), fixedDeltaTime, out var retained), normalized) * val * retained;
		}
		val += Vector3.ProjectOnPlane(Physics.gravity * GameManager.PlayerMovementSettings.BaseGravityFactor, normalized) * fixedDeltaTime;
		if (Downhill(normalized, val))
		{
			value.Grace = 0.6f;
			value.Elapsed = 0f;
		}
		val *= tuning.SlideRetention(value.Elapsed, value.Grace, fixedDeltaTime);
		value.Elapsed += fixedDeltaTime;
		result = val + Vector3.up * num;
		return true;
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(PlayerMovement), "OnWillBeDestroyed")]
	private static void Removed(PlayerMovement __instance)
	{
		States.Remove(__instance);
	}
}
[HarmonyPatch]
internal static class DashJump
{
	internal const int Capacity = 2;

	private static readonly Action<PlayerMovement, DivingState> SetDiveState = AccessTools.MethodDelegate<Action<PlayerMovement, DivingState>>(AccessTools.Method(typeof(PlayerMovement), "SetDivingState", (Type[])null, (Type[])null), (object)null, true);

	private static double fullAt;

	private static PlayerMovement owner;

	private static PlayerMovement doubleJumpUsedBy;

	private static PlayerMovement itemEscapeUsedBy;

	private static Vector3 launchHeading;

	private static double dashStart;

	private static bool spent;

	internal static double Stamina => Plugin.Tuning.Charges(fullAt, Time.timeAsDouble, 2);

	internal static void ChangeRecharge(float seconds)
	{
		fullAt = Time.timeAsDouble + (2.0 - Stamina) * (double)seconds;
	}

	private static void SpendSegment()
	{
		fullAt = Math.Max(Time.timeAsDouble, fullAt) + (double)Plugin.Tuning.RechargeSeconds;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(PlayerMovement), "TryTriggerJump")]
	private static bool BeforeGroundJump(PlayerMovement __instance, out bool __state, ref bool __result)
	{
		__state = Plugin.MovementEnabled && ((NetworkBehaviour)__instance).isLocalPlayer && CrouchSlide.IsSlideTakeoff(__instance);
		if (!__state || Stamina >= 1.0)
		{
			return true;
		}
		__result = false;
		return false;
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(PlayerMovement), "TryTriggerJump")]
	private static void AfterGroundJump(bool __state, bool __result)
	{
		if (__state && __result)
		{
			SpendSegment();
		}
	}

	internal static void ResetDive()
	{
		owner = null;
		spent = false;
	}

	internal static void Refill()
	{
		ResetDive();
		doubleJumpUsedBy = null;
		itemEscapeUsedBy = null;
		fullAt = 0.0;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(PlayerInput), "Dive")]
	private static void BeforeDive(PlayerInfo ___playerInfo, out float? __state)
	{
		//IL_001c: 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_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		__state = null;
		if (Plugin.MovementEnabled && ((NetworkBehaviour)___playerInfo).isLocalPlayer && (int)___playerInfo.Movement.DivingState == 0)
		{
			Vector3 linearVelocity = ___playerInfo.Rigidbody.linearVelocity;
			Vector2 val = new Vector2(linearVelocity.x, linearVelocity.z);
			__state = ((Vector2)(ref val)).magnitude;
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(PlayerInput), "Dive")]
	private static void AfterDive(PlayerInfo ___playerInfo, CallbackContext context, float? __state)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Invalid comparison between Unknown and I4
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: 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_0052: 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_006f: 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_0066: Unknown result type (might be due to invalid IL or missing references)
		if (!__state.HasValue)
		{
			return;
		}
		PlayerMovement movement = ___playerInfo.Movement;
		if ((int)movement.DivingState == 1 && (int)movement.DiveType == 0)
		{
			Rigidbody rigidbody = ___playerInfo.Rigidbody;
			Vector3 linearVelocity = rigidbody.linearVelocity;
			Vector3 val = linearVelocity;
			Plugin.Tuning.CarryDashSpeed(__state.Value, ref val.x, ref val.z);
			if (val.x != linearVelocity.x || val.z != linearVelocity.z)
			{
				rigidbody.linearVelocity = val;
			}
			ArmDive(movement, ((CallbackContext)(ref context)).time);
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(PlayerMovement), "InformLocalPlayerExitedGolfCart")]
	private static void AfterCartExit(PlayerMovement __instance, GolfCartExitType exitType)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Invalid comparison between Unknown and I4
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Invalid comparison between Unknown and I4
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		if ((int)exitType == 1 && Plugin.MovementEnabled && ((NetworkBehaviour)__instance).isLocalPlayer && (int)__instance.DivingState == 1 && (int)__instance.DiveType == 0)
		{
			ArmDive(__instance, InputState.currentTime);
		}
	}

	private static void ArmDive(PlayerMovement player, double start)
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: 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_0044: 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_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)owner == (Object)(object)player) || !spent)
		{
			owner = player;
			spent = false;
			dashStart = start;
			Vector3 val = Vector3.ProjectOnPlane(player.PlayerInfo.Rigidbody.linearVelocity, Vector3.up);
			launchHeading = ((Vector3)(ref val)).normalized;
			if (((Vector3)(ref launchHeading)).sqrMagnitude < 0.5f)
			{
				launchHeading = Quaternion.Euler(0f, player.Yaw, 0f) * Vector3.forward;
			}
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(PlayerMovement), "TryDive")]
	private static bool AllowRegularDash(PlayerMovement __instance, ref bool __result)
	{
		if (!spent || (Object)(object)__instance != (Object)(object)owner || !Plugin.MovementEnabled)
		{
			return true;
		}
		__result = false;
		return false;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(PlayerMovement), "TryDiveInternal")]
	private static bool AllowDiveAfterItemEscape(PlayerMovement __instance, DiveType type, ref bool __result)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Invalid comparison between Unknown and I4
		if ((Object)(object)__instance != (Object)(object)itemEscapeUsedBy || !Plugin.MovementEnabled || ((int)type != 0 && (int)type != 3))
		{
			return true;
		}
		__result = false;
		return false;
	}

	internal static bool CanExitDive(PlayerMovement player, double pressTime)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Invalid comparison between Unknown and I4
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Invalid comparison between Unknown and I4
		//IL_002d: 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)
		if (!Object.op_Implicit((Object)(object)player) || !((NetworkBehaviour)player).isLocalPlayer || (int)player.DivingState != 1 || !CanSpendOnAirJump(player))
		{
			return false;
		}
		if ((int)player.DiveType == 3 || DiveTypeExtensions.IsElephantGunDive(player.DiveType))
		{
			return true;
		}
		if ((int)player.DiveType == 0 && (Object)(object)player == (Object)(object)owner && !spent)
		{
			return Plugin.Tuning.InJumpWindow(dashStart, pressTime);
		}
		return false;
	}

	private static bool CanSpendOnAirJump(PlayerMovement player)
	{
		//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_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Invalid comparison between Unknown and I4
		//IL_009b: 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)
		PlayerInfo playerInfo = player.PlayerInfo;
		if (Plugin.MovementEnabled && (Object)(object)player != (Object)(object)itemEscapeUsedBy && Stamina >= 1.0 && !player.IsGrounded && !player.IsRespawningOrDrowning && !player.IsKnockedOutOrRecovering && player.IsVisible && !playerInfo.Rigidbody.isKinematic)
		{
			GolfCartSeat activeGolfCartSeat = playerInfo.ActiveGolfCartSeat;
			if (!((GolfCartSeat)(ref activeGolfCartSeat)).IsValid() && !playerInfo.AsGolfer.IsMatchResolved && !playerInfo.AsSpectator.IsSpectating && (int)playerInfo.AsHittable.FrozenState != 2)
			{
				GameplayActions gameplay = PlayerInput.Controls.Gameplay;
				return ((GameplayActions)(ref gameplay)).Jump.enabled;
			}
		}
		return false;
	}

	private static bool CanDoubleJump(PlayerMovement player)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)player == (Object)(object)doubleJumpUsedBy || (int)player.DivingState != 0 || player.IsWadingInWater || !CanSpendOnAirJump(player) || !MovementPatch.CanMove(player))
		{
			return false;
		}
		PlayerInfo playerInfo = player.PlayerInfo;
		if (!playerInfo.AsGolfer.IsAimingSwing && !playerInfo.AsGolfer.IsChargingSwing && !playerInfo.AsGolfer.IsSwinging && !playerInfo.Inventory.IsAimingItem)
		{
			return !playerInfo.Inventory.IsUsingItemAtAll;
		}
		return false;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(ConditionalInputBuffer), "Activate")]
	private static bool OnPress(ConditionalInputBuffer __instance, CallbackContext context)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Invalid comparison between Unknown and I4
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		InputAction action = ((CallbackContext)(ref context)).action;
		GameplayActions gameplay = PlayerInput.Controls.Gameplay;
		if (action != ((GameplayActions)(ref gameplay)).Jump || !Plugin.MovementEnabled)
		{
			return true;
		}
		PlayerMovement localPlayerMovement = GameManager.LocalPlayerMovement;
		if (!Object.op_Implicit((Object)(object)localPlayerMovement))
		{
			return true;
		}
		bool flag = CanExitDive(localPlayerMovement, ((CallbackContext)(ref context)).time);
		if (!flag && !CanDoubleJump(localPlayerMovement))
		{
			return true;
		}
		PlayerInfo playerInfo = localPlayerMovement.PlayerInfo;
		Vector3 val = playerInfo.Rigidbody.linearVelocity;
		float num = (playerInfo.IsInJumboBurgerGiantForm ? GameManager.ItemSettings.JumboBurgerGiantFormJumpUpwardsSpeed : GameManager.PlayerMovementSettings.JumpUpwardsSpeed);
		__instance.Cancel();
		if (flag)
		{
			bool num2 = (int)localPlayerMovement.DiveType > 0;
			if (num2)
			{
				MovementTuning.ApplyItemEscape(retention: DiveTypeExtensions.IsElephantGunDive(localPlayerMovement.DiveType) ? Plugin.Tuning.RifleEscapeSpeedRetention : Plugin.Tuning.RocketEscapeSpeedRetention, x: ref val.x, y: ref val.y, z: ref val.z, jumpSpeed: num);
			}
			else
			{
				Vector3 val2 = Vector3.ProjectOnPlane(val, Vector3.up);
				Vector3 val3 = ((((Vector3)(ref val2)).sqrMagnitude > 0.0001f) ? ((Vector3)(ref val2)).normalized : launchHeading);
				val += val3 * Plugin.Tuning.JumpBoost;
				val.y = Mathf.Max(0f, val.y) + num;
			}
			playerInfo.Rigidbody.linearVelocity = val;
			PlayerMovement obj = doubleJumpUsedBy;
			SetDiveState(localPlayerMovement, (DivingState)0);
			localPlayerMovement.Unground(false);
			doubleJumpUsedBy = obj;
			if (num2)
			{
				localPlayerMovement.NetworkdiveType = (DiveType)0;
				itemEscapeUsedBy = localPlayerMovement;
			}
			else
			{
				spent = true;
				owner = localPlayerMovement;
			}
		}
		else
		{
			doubleJumpUsedBy = localPlayerMovement;
			val.y = Plugin.Tuning.DoubleJumpSpeed(val.y, num);
			playerInfo.Rigidbody.linearVelocity = val;
		}
		SpendSegment();
		playerInfo.AnimatorIo.BeginJump((JumpType)((flag || val.x * val.x + val.z * val.z > 0.04f) ? 1 : 0));
		if (!flag)
		{
			TravelAnimation.RequestFlip(localPlayerMovement);
			StanceNetwork.SendDoubleJumpFlip(localPlayerMovement);
		}
		playerInfo.PlayerAudio.PlayJumpForAllClients(playerInfo.IsInJumboBurgerGiantForm);
		return false;
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(PlayerMovement), "UpdateIsGroundedAtAll")]
	private static void OnGroundContact(PlayerMovement __instance, bool ___isGroundedAtAll)
	{
		if (___isGroundedAtAll)
		{
			RearmAirJumps(__instance);
		}
	}

	private static void RearmAirJumps(PlayerMovement player)
	{
		if ((Object)(object)player == (Object)(object)doubleJumpUsedBy)
		{
			doubleJumpUsedBy = null;
		}
		if ((Object)(object)player == (Object)(object)itemEscapeUsedBy)
		{
			itemEscapeUsedBy = null;
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(PlayerMovement), "SetDivingState")]
	private static void EndDive(PlayerMovement __instance, DivingState state)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Invalid comparison between Unknown and I4
		if ((Object)(object)__instance == (Object)(object)owner && !spent && (int)state != 1)
		{
			ResetDive();
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(PlayerMovement), "UpdateGroundingState")]
	private static void OnFooting(PlayerMovement __instance, bool suppressLandingAnimation)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		if (spent && (Object)(object)__instance == (Object)(object)owner && !suppressLandingAnimation && __instance.IsGrounded && (int)__instance.DivingState == 0)
		{
			ResetDive();
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(PlayerMovement), "Unground")]
	private static void OnImmediateTakeoff(PlayerMovement __instance)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		if (__instance.IsGrounded)
		{
			RearmAirJumps(__instance);
		}
		if (spent && (Object)(object)__instance == (Object)(object)owner && __instance.IsGrounded && (int)__instance.DivingState == 0)
		{
			ResetDive();
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	private static void OnRespawn(PlayerMovement __instance, RespawnState __0)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Invalid comparison between Unknown and I4
		if (((NetworkBehaviour)__instance).isLocalPlayer && (int)__0 == 1)
		{
			Refill();
		}
	}
}
[HarmonyPatch(typeof(PlayerMovement), "UpdateDivingState")]
internal static class DiveSteering
{
	internal static bool UsesLook(DiveType type)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Invalid comparison between Unknown and I4
		if ((int)type != 0)
		{
			return (int)type == 3;
		}
		return true;
	}

	private static void Postfix(PlayerMovement __instance)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Invalid comparison between Unknown and I4
		//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_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Invalid comparison between Unknown and I4
		//IL_0092: 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_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: 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_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0266: Unknown result type (might be due to invalid IL or missing references)
		if (!Plugin.MovementEnabled || !((NetworkBehaviour)__instance).isLocalPlayer || (int)__instance.DivingState != 1 || __instance.IsGrounded || __instance.IsRespawningOrDrowning || __instance.IsKnockedOutOrRecovering || !__instance.IsVisible || __instance.IsWadingInWater)
		{
			return;
		}
		PlayerInfo playerInfo = __instance.PlayerInfo;
		if (playerInfo.Rigidbody.isKinematic)
		{
			return;
		}
		GolfCartSeat activeGolfCartSeat = playerInfo.ActiveGolfCartSeat;
		if (((GolfCartSeat)(ref activeGolfCartSeat)).IsValid() || playerInfo.AsSpectator.IsSpectating || playerInfo.AsGolfer.IsMatchResolved || (int)playerInfo.AsHittable.FrozenState == 2)
		{
			return;
		}
		if (UsesLook(__instance.DiveType))
		{
			float num = DiveLook.Consume(__instance);
			if (MovementPatch.TryGetYaw(out var yaw, allowLockedOrbit: true))
			{
				FreeLook.GetHeading(__instance, yaw, out var independentLook);
				if (!independentLook && num != 0f)
				{
					playerInfo.Rigidbody.linearVelocity = Quaternion.AngleAxis(num, Vector3.up) * playerInfo.Rigidbody.linearVelocity;
				}
			}
		}
		else
		{
			if (!DiveTypeExtensions.IsElephantGunDive(__instance.DiveType))
			{
				return;
			}
			float rifleTurn = Plugin.Tuning.RifleTurn;
			GameplayActions gameplay = PlayerInput.Controls.Gameplay;
			InputAction move = ((GameplayActions)(ref gameplay)).Move;
			if (rifleTurn <= 0f || !move.enabled || !MovementPatch.TryGetYaw(out var yaw2, allowLockedOrbit: true))
			{
				return;
			}
			yaw2 = FreeLook.GetHeading(__instance, yaw2, out var _);
			Vector2 val = move.ReadValue<Vector2>();
			float num2 = Mathf.Clamp01(((Vector2)(ref val)).magnitude);
			if (!(num2 <= 0.001f))
			{
				Vector3 linearVelocity = playerInfo.Rigidbody.linearVelocity;
				Vector2 val2 = default(Vector2);
				((Vector2)(ref val2))..ctor(linearVelocity.x, linearVelocity.z);
				float num3 = ((Vector2)(ref val2)).magnitude;
				float num4 = yaw2 + Mathf.Atan2(val.x, val.y) * 57.29578f;
				float num5 = ((num3 > 0.001f) ? (Mathf.Atan2(linearVelocity.x, linearVelocity.z) * 57.29578f) : num4);
				float num6 = rifleTurn * num2 * Time.fixedDeltaTime;
				float num7 = Mathf.MoveTowardsAngle(num5, num4, num6);
				float defaultMoveSpeed = GameManager.PlayerMovementSettings.DefaultMoveSpeed;
				float num8 = Mathf.Clamp01(Mathf.Cos((num4 - num7) * ((float)Math.PI / 180f)));
				if (num3 < defaultMoveSpeed * num2)
				{
					num3 = Mathf.MoveTowards(num3, defaultMoveSpeed * num2, defaultMoveSpeed * num6 * ((float)Math.PI / 180f) * num8);
				}
				linearVelocity.x = Mathf.Sin(num7 * ((float)Math.PI / 180f)) * num3;
				linearVelocity.z = Mathf.Cos(num7 * ((float)Math.PI / 180f)) * num3;
				playerInfo.Rigidbody.linearVelocity = linearVelocity;
			}
		}
	}
}
[HarmonyPatch]
internal static class DiveLook
{
	private static PlayerMovement owner;

	private static CameraModule camera;

	private static DiveType type;

	private static double started;

	private static float pending;

	private static IEnumerable<MethodBase> TargetMethods()
	{
		yield return AccessTools.Method(typeof(OrbitCameraModule), "Rotate", (Type[])null, (Type[])null);
		yield return AccessTools.Method(typeof(FirstPersonCameraModule), "Rotate", (Type[])null, (Type[])null);
	}

	private static void Postfix(CameraModule __instance, Vector2 axis, float ___axisSensitivity)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Invalid comparison between Unknown and I4
		//IL_0034: 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_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Invalid comparison between Unknown and I4
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		if (!Plugin.MovementEnabled || CameraModuleController.IsTransitioning || (Object)(object)__instance != (Object)(object)CameraModuleController.CurrentModule)
		{
			return;
		}
		PlayerMovement localPlayerMovement = GameManager.LocalPlayerMovement;
		if (Object.op_Implicit((Object)(object)localPlayerMovement) && (int)localPlayerMovement.DivingState == 1 && DiveSteering.UsesLook(localPlayerMovement.DiveType))
		{
			bool isHeld = FreeLook.IsHeld;
			if (!Matches(localPlayerMovement) || isHeld)
			{
				pending = 0f;
			}
			owner = localPlayerMovement;
			camera = __instance;
			type = localPlayerMovement.DiveType;
			started = localPlayerMovement.DivingStateTimestamp;
			if (!isHeld)
			{
				bool num = (int)type == 3;
				float num2 = (num ? Plugin.Tuning.RocketTurn : Plugin.Tuning.DashTurn) * Time.deltaTime;
				float num3 = (num ? Plugin.Tuning.RocketLookPercent : Plugin.Tuning.DashLookPercent);
				float num4 = axis.x * ___axisSensitivity * (num3 / 100f);
				pending += Mathf.Clamp(num4, 0f - num2, num2);
			}
		}
	}

	private static bool Matches(PlayerMovement player)
	{
		//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)
		if ((Object)(object)owner == (Object)(object)player && (Object)(object)camera == (Object)(object)CameraModuleController.CurrentModule && type == player.DiveType)
		{
			return started == player.DivingStateTimestamp;
		}
		return false;
	}

	internal static float Consume(PlayerMovement player)
	{
		float result = (Matches(player) ? pending : 0f);
		pending = 0f;
		return result;
	}
}
internal static class FreeLook
{
	internal const string Name = "Free Look (Hold)";

	internal const string ActionId = "9a1cd130-25f6-4310-841c-a4e40f041299";

	internal const string BindingId = "b4aa93e6-b534-4392-aa88-78a34465902e";

	private static GameControls controls;

	private static InputAction action;

	private static PlayerMovement holder;

	private static CameraModule heldCamera;

	private static double lastTick;

	private static float heading;

	internal static bool IsHeld
	{
		get
		{
			if (controls != PlayerInput.Controls)
			{
				controls = PlayerInput.Controls;
				action = controls.asset.FindAction("Gameplay/Free Look (Hold)", false);
			}
			if (action != null)
			{
				return action.IsPressed();
			}
			return false;
		}
	}

	internal static float GetHeading(PlayerMovement player, float cameraYaw, out bool independentLook)
	{
		CameraModule currentModule = CameraModuleController.CurrentModule;
		double fixedTimeAsDouble = Time.fixedTimeAsDouble;
		if ((Object)(object)holder != (Object)(object)player || (Object)(object)heldCamera != (Object)(object)currentModule || fixedTimeAsDouble - lastTick > 1.5 * (double)Time.fixedDeltaTime)
		{
			holder = null;
		}
		lastTick = fixedTimeAsDouble;
		bool isHeld = IsHeld;
		independentLook = Object.op_Implicit((Object)(object)holder) || isHeld;
		if (isHeld)
		{
			if (!Object.op_Implicit((Object)(object)holder))
			{
				holder = player;
				heldCamera = currentModule;
				heading = player.Yaw;
			}
			return heading;
		}
		if (!Object.op_Implicit((Object)(object)holder))
		{
			return cameraYaw;
		}
		holder = null;
		OrbitCameraModule val = (OrbitCameraModule)(object)((currentModule is OrbitCameraModule) ? currentModule : null);
		if (val != null)
		{
			val.SetYaw(heading);
		}
		else
		{
			FirstPersonCameraModule val2 = (FirstPersonCameraModule)(object)((currentModule is FirstPersonCameraModule) ? currentModule : null);
			if (val2 != null)
			{
				val2.SetYaw(heading);
			}
		}
		return heading;
	}
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
internal static class FreeLookBinding
{
	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> source)
	{
		//IL_009b: 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_00ab: 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_00ca: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Expected O, but got Unknown
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: 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_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Expected O, but got Unknown
		List<CodeInstruction> list = new List<CodeInstruction>(source);
		MethodInfo fromJson = AccessTools.Method(typeof(InputActionAsset), "FromJson", new Type[1] { typeof(string) }, (Type[])null);
		int num = list.FindIndex((CodeInstruction i) => CodeInstructionExtensions.Calls(i, fromJson));
		if (num < 1 || list[num - 1].opcode != OpCodes.Ldstr)
		{
			throw new InvalidOperationException("Could not locate Golf's generated input asset.");
		}
		JObject val = JObject.Parse((string)list[num - 1].operand);
		JObject val2 = (JObject)((JToken)val).SelectToken("maps[?(@.name == 'Gameplay')]");
		((JArray)val2["actions"]).Add((JToken)new JObject
		{
			["name"] = JToken.op_Implicit("Free Look (Hold)"),
			["type"] = JToken.op_Implicit("Button"),
			["id"] = JToken.op_Implicit("9a1cd130-25f6-4310-841c-a4e40f041299"),
			["expectedControlType"] = JToken.op_Implicit("Button")
		});
		((JArray)val2["bindings"]).Add((JToken)new JObject
		{
			["name"] = JToken.op_Implicit(""),
			["id"] = JToken.op_Implicit("b4aa93e6-b534-4392-aa88-78a34465902e"),
			["path"] = JToken.op_Implicit("<Keyboard>/x"),
			["action"] = JToken.op_Implicit("Free Look (Hold)"),
			["groups"] = JToken.op_Implicit("Keyboard Mouse")
		});
		list[num - 1].operand = ((JToken)val).ToString((Formatting)0, Array.Empty<JsonConverter>());
		return list;
	}
}
[HarmonyPatch(typeof(ActionRebindOption), "Initialize")]
internal static class FreeLookRow
{
	private static void Postfix(InputAction action, LocalizeStringEvent ___localizedName)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		if (action.name != "Free Look (Hold)")
		{
			Guid id = action.id;
			GameplayActions gameplay = PlayerInput.Controls.Gameplay;
			if (id != ((GameplayActions)(ref gameplay)).Walk.id)
			{
				return;
			}
		}
		((Behaviour)___localizedName).enabled = false;
		((UnityEvent<string>)(object)___localizedName.OnUpdateString).Invoke((action.name == "Free Look (Hold)") ? "Free Look (Hold)" : "Crouch / Slide");
	}
}
[HarmonyPatch(typeof(ActionRebindOption), "GetLocalizedBindingName")]
internal static class FreeLookPrompt
{
	private static bool Prefix(InputAction action, ref string __result)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		if (action.name != "Free Look (Hold)")
		{
			Guid id = action.id;
			GameplayActions gameplay = PlayerInput.Controls.Gameplay;
			if (id != ((GameplayActions)(ref gameplay)).Walk.id)
			{
				return true;
			}
		}
		__result = ((action.name == "Free Look (Hold)") ? "Free Look (Hold)" : "Crouch / Slide");
		return false;
	}
}
internal static class GroundMovement
{
	internal static void Step(ref float x, ref float z, float wishX, float wishZ, float moveSpeed, float dt)
	{
		float num = MathF.Sqrt(x * x + z * z);
		if (num > 0f)
		{
			float num2 = MathF.Max(num, 2.4f) * 8f * dt;
			float num3 = MathF.Max(0f, num - num2) / num;
			x *= num3;
			z *= num3;
		}
		float num4 = MathF.Sqrt(wishX * wishX + wishZ * wishZ);
		if (!(num4 <= 1E-05f))
		{
			float num5 = wishX / num4;
			float num6 = wishZ / num4;
			float num7 = MathF.Min(num4, 1f) * moveSpeed;
			float x2 = num7 - (x * num5 + z * num6);
			float num8 = MathF.Max(0f, MathF.Min(x2, 10f * num7 * dt));
			x += num8 * num5;
			z += num8 * num6;
		}
	}
}
internal sealed class JoinGrace
{
	internal const int WarningSeconds = 20;

	private readonly double firstSeen;

	private double? warnedAt;

	internal JoinGrace(double now)
	{
		firstSeen = now;
	}

	internal bool NeedsWarning(double now)
	{
		if (!warnedAt.HasValue)
		{
			return now - firstSeen >= 5.0;
		}
		return false;
	}

	internal void MarkWarned(double now)
	{
		double valueOrDefault = warnedAt.GetValueOrDefault();
		if (!warnedAt.HasValue)
		{
			valueOrDefault = now;
			warnedAt = valueOrDefault;
		}
	}

	internal bool Expired(double now)
	{
		if (warnedAt.HasValue)
		{
			return now - warnedAt.Value >= 20.0;
		}
		return false;
	}
}
internal static class LegacyConfig
{
	internal static bool Import(string destination)
	{
		string text = Path.Combine(Path.GetDirectoryName(destination), "golfmods.air-strafe.cfg");
		if (File.Exists(destination) || !File.Exists(text))
		{
			return false;
		}
		string text2 = destination + "." + Guid.NewGuid().ToString("N") + ".tmp";
		try
		{
			File.Copy(text, text2);
			File.Move(text2, destination);
			return true;
		}
		catch (IOException) when (File.Exists(destination))
		{
			return false;
		}
		finally
		{
			if (File.Exists(text2))
			{
				File.Delete(text2);
			}
		}
	}
}
[HarmonyPatch(typeof(PlayerMovement), "FixedUpdate")]
internal static class MovementPatch
{
	internal static readonly Func<PlayerMovement, bool> CanMove = AccessTools.MethodDelegate<Func<PlayerMovement, bool>>(AccessTools.Method(typeof(PlayerMovement), "CanMove", (Type[])null, (Type[])null), (object)null, true);

	private static readonly Action<PlayerMovement> UpdateSpeed = AccessTools.MethodDelegate<Action<PlayerMovement>>(AccessTools.Method(typeof(PlayerMovement), "UpdateMovementSpeed", (Type[])null, (Type[])null), (object)null, true);

	private static readonly FieldRef<PlayerMovement, float> Speed = AccessTools.FieldRefAccess<PlayerMovement, float>("speed");

	private static readonly FieldRef<PlayerMovement, bool> HardReversal = AccessTools.FieldRefAccess<PlayerMovement, bool>("turningOnADime");

	private static readonly FieldRef<PlayerMovement, bool> Suppressed = AccessTools.FieldRefAccess<PlayerMovement, bool>("movementSuppressedUntilInputReleased");

	private static readonly FieldRef<PlayerMovement, float> TargetYaw = AccessTools.FieldRefAccess<PlayerMovement, float>("targetYaw");

	private static readonly FieldRef<OrbitCameraModule, bool> LockedYaw = AccessTools.FieldRefAccess<OrbitCameraModule, bool>("yawLockedToSubjectForward");

	private static readonly Action<PlayerMovement, Vector3> SetVelocity = AccessTools.MethodDelegate<Action<PlayerMovement, Vector3>>(AccessTools.PropertySetter(typeof(PlayerMovement), "Velocity"), (object)null, true);

	private static readonly FieldRef<PlayerMovement, bool> JumpPad = AccessTools.FieldRefAccess<PlayerMovement, bool>("lastUngroundedDueToJumpPad");

	private static readonly FieldRef<PlayerMovement, Vector3> StockInput = AccessTools.FieldRefAccess<PlayerMovement, Vector3>("worldMoveVector3d");

	private static readonly Action<PlayerMovement> StockMove = AccessTools.MethodDelegate<Action<PlayerMovement>>(AccessTools.Method(typeof(PlayerMovement), "ApplyMovement", (Type[])null, (Type[])null), (object)null, true);

	private static readonly Action<PlayerMovement> StockDrag = AccessTools.MethodDelegate<Action<PlayerMovement>>(AccessTools.Method(typeof(PlayerMovement), "ApplyHorizontalDrag", (Type[])null, (Type[])null), (object)null, true);

	private static PlayerMovement sampledPlayer;

	private static CameraModule sampledCamera;

	private static double lastSample;

	private static float sampledYaw;

	private static int sampledFrame;

	private static int turnSide;

	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> source, ILGenerator generator)
	{
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Expected O, but got Unknown
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Expected O, but got Unknown
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Expected O, but got Unknown
		List<CodeInstruction> list = new List<CodeInstruction>(source);
		MethodInfo methodInfo = AccessTools.Method(typeof(PlayerMovement), "ApplyMovement", (Type[])null, (Type[])null);
		MethodInfo methodInfo2 = AccessTools.Method(typeof(PlayerMovement), "ApplyHorizontalDrag", (Type[])null, (Type[])null);
		int num = -1;
		for (int i = 0; i + 4 < list.Count; i++)
		{
			if (!(list[i].opcode != OpCodes.Ldarg_0) && CodeInstructionExtensions.Calls(list[i + 1], methodInfo) && !(list[i + 2].opcode != OpCodes.Ldarg_0) && CodeInstructionExtensions.Calls(list[i + 3], methodInfo2))
			{
				if (num >= 0)
				{
					throw new InvalidOperationException("Multiple ordinary movement branches in this game build.");
				}
				num = i;
			}
		}
		if (num < 0)
		{
			throw new InvalidOperationException("Could not identify this game's ordinary movement branch.");
		}
		Label label = generator.DefineLabel();
		list[num + 4].labels.Add(label);
		CodeInstruction val = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
		val.labels.AddRange(list[num].labels);
		list[num].labels.Clear();
		list.InsertRange(num, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[3]
		{
			val,
			new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(MovementPatch), "TryMove", (Type[])null, (Type[])null)),
			new CodeInstruction(OpCodes.Brtrue, (object)label)
		});
		return list;
	}

	internal static bool CanApplyMovement(PlayerMovement player)
	{
		//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)
		if (!Plugin.MovementEnabled || player.IsInSpringBootsJump || (!player.IsGrounded && JumpPad.Invoke(player)) || player.IsRespawningOrDrowning || player.IsWadingInWater || !CanMove(player))
		{
			return false;
		}
		PlayerGolfer asGolfer = player.PlayerInfo.AsGolfer;
		PlayerInventory inventory = player.PlayerInfo.Inventory;
		if (asGolfer.IsAimingSwing || asGolfer.IsChargingSwing || asGolfer.IsSwinging || inventory.IsUsingItemAtAll || inventory.IsAimingItem)
		{
			return false;
		}
		if (!player.PlayerInfo.Rigidbody.isKinematic)
		{
			if (player.IsGrounded)
			{
				return player.GroundData.normal.y > 0.001f;
			}
			return true;
		}
		return false;
	}

	private static bool TryMove(PlayerMovement player)
	{
		//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: 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_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_006d: 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_0079: 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_00d6: 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_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: 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_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: 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_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0329: 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_033e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0345: Unknown result type (might be due to invalid IL or missing references)
		//IL_0377: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_024a: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0251: Unknown result type (might be due to invalid IL or missing references)
		//IL_0256: Unknown result type (might be due to invalid IL or missing references)
		//IL_025a: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: Unknown result type (might be due to invalid IL or missing references)
		//IL_0263: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_026a: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_0274: 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_027f: 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_028a: Unknown result type (might be due to invalid IL or missing references)
		//IL_028c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0291: Unknown result type (might be due to invalid IL or missing references)
		//IL_0293: Unknown result type (might be due to invalid IL or missing references)
		//IL_029a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fe: 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_030c: Unknown result type (might be due to invalid IL or missing references)
		//IL_030e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0310: Unknown result type (might be due to invalid IL or missing references)
		//IL_0317: Unknown result type (might be due to invalid IL or missing references)
		//IL_031c: 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_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		if (!CanApplyMovement(player))
		{
			return false;
		}
		Rigidbody rigidbody = player.PlayerInfo.Rigidbody;
		PlayerGolfer asGolfer = player.PlayerInfo.AsGolfer;
		if (!TryGetYaw(out var yaw))
		{
			if (!CrouchSlide.TrySlide(player, Vector3.zero, out var result))
			{
				return false;
			}
			SetVelocity(player, result);
			return true;
		}
		Vector2 val;
		if (!Suppressed.Invoke(player))
		{
			GameplayActions gameplay = PlayerInput.Controls.Gameplay;
			val = ((GameplayActions)(ref gameplay)).Move.ReadValue<Vector2>();
		}
		else
		{
			val = Vector2.zero;
		}
		Vector2 val2 = val;
		yaw = FreeLook.GetHeading(player, yaw, out var independentLook);
		int turn = SampleTurn(player, yaw, independentLook);
		if (!player.IsGrounded && Plugin.Assisted.Value && !independentLook)
		{
			AirAcceleration.Assist(ref val2.x, ref val2.y, turn, Plugin.Tuning.AllowForwardOnlyAssist);
		}
		Quaternion val3 = Quaternion.Euler(0f, yaw, 0f);
		Vector3 val4 = val3 * new Vector3(val2.x, 0f, val2.y);
		if (asGolfer.CanRotate())
		{
			TargetYaw.Invoke(player) = yaw;
			rigidbody.MoveRotation(val3);
			Vector3 angularVelocity = rigidbody.angularVelocity;
			angularVelocity.y = 0f;
			rigidbody.angularVelocity = angularVelocity;
		}
		if (CrouchSlide.TrySlide(player, val4, out var result2))
		{
			SetVelocity(player, result2);
			return true;
		}
		if (player.IsGrounded && CrouchSlide.Mode(player) == Stance.Crouched)
		{
			val4 *= GameManager.PlayerMovementSettings.WalkSpeedFactor;
		}
		if (player.IsGrounded && (int)player.GroundTerrainType != 0 && TerrainManager.Settings.LayerSettings.TryGetValue(player.GroundTerrainDominantGlobalLayer, out var value) && value.DoesOverridePlayerDrag)
		{
			Vector3 val5 = StockInput.Invoke(player);
			StockInput.Invoke(player) = val4;
			try
			{
				StockMove(player);
				StockDrag(player);
			}
			finally
			{
				StockInput.Invoke(player) = val5;
			}
			return true;
		}
		bool flag = HardReversal.Invoke(player);
		HardReversal.Invoke(player) = false;
		try
		{
			UpdateSpeed(player);
		}
		finally
		{
			HardReversal.Invoke(player) = flag;
		}
		if (player.IsGrounded)
		{
			PlayerGroundData groundData = player.GroundData;
			Vector3 normalized = ((Vector3)(ref groundData.normal)).normalized;
			Vector3 val6 = Vector3.Cross(normalized, Vector3.forward);
			Vector3 normalized2 = ((Vector3)(ref val6)).normalized;
			Vector3 val7 = Vector3.Cross(normalized2, normalized);
			Vector3 velocity = player.Velocity;
			float x = Vector3.Dot(velocity, normalized2);
			float z = Vector3.Dot(velocity, val7);
			Vector3 val8 = val4 - Vector3.up * (Vector3.Dot(val4, normalized) / normalized.y);
			val8 = ((Vector3)(ref val8)).normalized * ((Vector3)(ref val4)).magnitude;
			GroundMovement.Step(ref x, ref z, Vector3.Dot(val8, normalized2), Vector3.Dot(val8, val7), Speed.Invoke(player), Time.fixedDeltaTime);
			SetVelocity(player, normalized2 * x + val7 * z + normalized * Vector3.Dot(velocity, normalized));
		}
		else
		{
			Vector3 linearVelocity = rigidbody.linearVelocity;
			AirAcceleration.Step(ref linearVelocity.x, ref linearVelocity.z, val4.x, val4.z, Speed.Invoke(player), Time.fixedDeltaTime, Plugin.Tuning.Acceleration, Plugin.Tuning.DirectionalCap);
			rigidbody.linearVelocity = linearVelocity;
		}
		return true;
	}

	private static int SampleTurn(PlayerMovement player, float yaw, bool independentLook)
	{
		CameraModule currentModule = CameraModuleController.CurrentModule;
		double fixedTimeAsDouble = Time.fixedTimeAsDouble;
		if (independentLook || (Object)(object)sampledPlayer != (Object)(object)player || (Object)(object)currentModule != (Object)(object)sampledCamera || fixedTimeAsDouble - lastSample > 1.5 * (double)Time.fixedDeltaTime)
		{
			turnSide = 0;
		}
		else if (Time.frameCount != sampledFrame)
		{
			float num = Mathf.DeltaAngle(sampledYaw, yaw);
			turnSide = ((!(Mathf.Abs(num) < 0.015f)) ? ((num > 0f) ? 1 : (-1)) : 0);
		}
		sampledPlayer = (independentLook ? null : player);
		sampledCamera = currentModule;
		sampledFrame = Time.frameCount;
		sampledYaw = yaw;
		lastSample = fixedTimeAsDouble;
		return turnSide;
	}

	internal static bool TryGetYaw(out float yaw, bool allowLockedOrbit = false)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Invalid comparison between Unknown and I4
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Invalid comparison between Unknown and I4
		yaw = 0f;
		if (CameraModuleController.IsTransitioning)
		{
			return false;
		}
		OrbitCameraModule val = default(OrbitCameraModule);
		if ((int)CameraModuleController.CurrentModuleType == 1 && CameraModuleController.TryGetOrbitModule(ref val) && (allowLockedOrbit || !LockedYaw.Invoke(val)))
		{
			yaw = val.Yaw;
			return true;
		}
		FirstPersonCameraModule val2 = default(FirstPersonCameraModule);
		if ((int)CameraModuleController.CurrentModuleType == 2 && CameraModuleController.TryGetFirstPersonModule(ref val2))
		{
			yaw = val2.Yaw;
			return true;
		}
		return false;
	}
}
internal sealed class MovementTuning
{
	internal float Acceleration = 10f;

	internal float DirectionalCap = 0.96f;

	internal bool AllowForwardOnlyAssist = true;

	internal float RechargeSeconds = 5f;

	internal bool PreserveDashSpeed = true;

	internal float JumpBoost = 3.5f;

	internal int OpenMs;

	internal int CloseMs;

	internal float DoubleJumpLiftMultiplier = 1.15f;

	internal float DoubleJumpUpwardCarry = 0.5f;

	internal float RocketEscapeSpeedRetention = 0.85f;

	internal float RifleEscapeSpeedRetention = 0.85f;

	internal float DashTurn = 100f;

	internal float RifleTurn = 100f;

	internal float RocketTurn = 35f;

	internal float DashLookPercent = 35f;

	internal float RocketLookPercent = 20f;

	internal float SlideEntry = 7.8f;

	internal float SlideExit = 2.5f;

	internal float SlideEarlyDrag = 0.2f;

	internal float SlideLateDrag = 2f;

	internal float SlideTurn = 540f;

	internal float SteerSlide(float errorDegrees, float input, float dt, out float retained)
	{
		float num = Math.Abs(errorDegrees);
		float num2 = Math.Min(num, SlideTurn * dt * input);
		float num3 = num * ((float)Math.PI / 180f);
		float num4 = (num - num2) * ((float)Math.PI / 180f);
		float num5 = Math.Max(0f, num3 - num4 - (MathF.Sin(num3) - MathF.Sin(num4)));
		retained = MathF.Exp(-0.44f * num5);
		return (float)Math.Sign(errorDegrees) * num2;
	}

	internal bool CanStartSlide(float speed, bool downhill)
	{
		if (!(speed >= SlideEntry))
		{
			if (downhill)
			{
				return speed > 0.1f;
			}
			return false;
		}
		return true;
	}

	internal float SlideRetention(float elapsed, float grace, float dt)
	{
		float num = Math.Min(dt, Math.Max(0f, grace - elapsed));
		return MathF.Exp((0f - SlideEarlyDrag) * num - SlideLateDrag * (dt - num));
	}

	internal float DoubleJumpSpeed(float verticalSpeed, float jumpSpeed)
	{
		float num = Math.Min(Math.Max(0f, verticalSpeed) * DoubleJumpUpwardCarry, 0.5f * jumpSpeed);
		return Math.Max(verticalSpeed, jumpSpeed * DoubleJumpLiftMultiplier + num);
	}

	internal static void ApplyItemEscape(ref float x, ref float y, ref float z, float jumpSpeed, float retention)
	{
		x *= retention;
		z *= retention;
		y = Math.Max(y, jumpSpeed);
	}

	internal bool InJumpWindow(double start, double press)
	{
		if (press >= start + (double)OpenMs / 1000.0)
		{
			if (CloseMs != 0)
			{
				return press <= start + (double)CloseMs / 1000.0;
			}
			return true;
		}
		return false;
	}

	internal void CarryDashSpeed(float incoming, ref float x, ref float z)
	{
		float num = MathF.Sqrt(x * x + z * z);
		if (PreserveDashSpeed && !(num <= 0f) && !(incoming <= num))
		{
			float num2 = incoming / num;
			x *= num2;
			z *= num2;
		}
	}

	internal double Charges(double fullAt, double now, int capacity)
	{
		return Math.Max(0.0, (double)capacity - Math.Max(0.0, fullAt - now) / (double)RechargeSeconds);
	}

	internal string Encode()
	{
		return FormattableString.Invariant($"{Acceleration:R}|{DirectionalCap:R}|{AllowForwardOnlyAssist}|{RechargeSeconds:R}|{PreserveDashSpeed}|{JumpBoost:R}|{OpenMs}|{CloseMs}|{DoubleJumpLiftMultiplier:R}|{DoubleJumpUpwardCarry:R}|{RocketEscapeSpeedRetention:R}|{SlideEntry:R}|{SlideExit:R}|{SlideEarlyDrag:R}|{SlideLateDrag:R}|{SlideTurn:R}|{DashTurn:R}|{RifleTurn:R}|{RocketTurn:R}|{RifleEscapeSpeedRetention:R}|{DashLookPercent:R}|{RocketLookPercent:R}");
	}

	internal static bool TryDecode(string value, out MovementTuning tuning)
	{
		tuning = null;
		if (string.IsNullOrEmpty(value) || value.Length > 384)
		{
			return false;
		}
		string[] array = value.Split('|');
		MovementTuning movementTuning = new MovementTuning();
		if (array.Length != 22 || !ReadFloat(array[0], 0f, out movementTuning.Acceleration) || !ReadFloat(array[1], 0f, out movementTuning.DirectionalCap) || !bool.TryParse(array[2], out movementTuning.AllowForwardOnlyAssist) || !ReadFloat(array[3], 0.001f, out movementTuning.RechargeSeconds) || !bool.TryParse(array[4], out movementTuning.PreserveDashSpeed) || !ReadFloat(array[5], 0f, out movementTuning.JumpBoost) || !int.TryParse(array[6], NumberStyles.None, CultureInfo.InvariantCulture, out movementTuning.OpenMs) || !int.TryParse(array[7], NumberStyles.None, CultureInfo.InvariantCulture, out movementTuning.CloseMs) || (movementTuning.CloseMs != 0 && movementTuning.CloseMs < movementTuning.OpenMs) || !ReadFloat(array[8], 0f, out movementTuning.DoubleJumpLiftMultiplier) || !ReadFloat(array[9], 0f, out movementTuning.DoubleJumpUpwardCarry, 1f) || !ReadFloat(array[10], 0f, out movementTuning.RocketEscapeSpeedRetention, 1f) || !ReadFloat(array[11], 0.1f, out movementTuning.SlideEntry) || !ReadFloat(array[12], 0f, out movementTuning.SlideExit, movementTuning.SlideEntry) || !ReadFloat(array[13], 0f, out movementTuning.SlideEarlyDrag) || !ReadFloat(array[14], 0f, out movementTuning.SlideLateDrag) || !ReadFloat(array[15], 0f, out movementTuning.SlideTurn) || !ReadFloat(array[16], 0f, out movementTuning.DashTurn, 720f) || !ReadFloat(array[17], 0f, out movementTuning.RifleTurn, 720f) || !ReadFloat(array[18], 0f, out movementTuning.RocketTurn, 720f) || !ReadFloat(array[19], 0f, out movementTuning.RifleEscapeSpeedRetention, 1f) || !ReadFloat(array[20], 0f, out movementTuning.DashLookPercent, 100f) || !ReadFloat(array[21], 0f, out movementTuning.RocketLookPercent, 100f))
		{
			return false;
		}
		tuning = movementTuning;
		return true;
	}

	private static bool ReadFloat(string value, float min, out float result, float max = float.MaxValue)
	{
		if (float.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out result) && result >= min)
		{
			return result <= max;
		}
		return false;
	}
}
[BepInPlugin("golfmods.sourcegolf", "Source Golf", "1.1.0")]
[BepInIncompatibility("golfmods.air-strafe")]
public sealed class Plugin : BaseUnityPlugin
{
	internal const string Id = "golfmods.sourcegolf";

	internal const string Version = "1.1.0";

	private SessionRules sessions;

	private readonly PublicLobbyAdmission admission = new PublicLobbyAdmission();

	private readonly Speedometer hud = new Speedometer();

	private Harmony patches;

	private ConfigEntry<bool> rangeMovement;

	private bool operational;

	private float retryAt;

	private NetworkConnection sessionConnection;

	internal static ConfigEntry<bool> Assisted { get; private set; }

	internal static bool MovementEnabled { get; private set; }

	internal static MovementTuning Tuning { get; private set; }

	internal static BEosLobby PublicHostLobby { get; private set; }

	private void Awake()
	{
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Expected O, but got Unknown
		try
		{
			if (LegacyConfig.Import(((BaseUnityPlugin)this).Config.ConfigFilePath))
			{
				((BaseUnityPlugin)this).Config.Reload();
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Imported settings from Golf Air Strafe.");
			}
		}
		catch (IOException ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Could not import Golf Air Strafe settings: " + ex.Message));
			return;
		}
		bool upgradeSlideTurn = false;
		if (File.Exists(((BaseUnityPlugin)this).Config.ConfigFilePath))
		{
			using StreamReader streamReader = File.OpenText(((BaseUnityPlugin)this).Config.ConfigFilePath);
			upgradeSlideTurn = streamReader.ReadLine() == "## Settings file was created by plugin Golf Air Strafe v1.9.0";
		}
		Assisted = ((BaseUnityPlugin)this).Config.Bind<bool>("Controls", "AssistedAirStrafing", true, "While airborne, hold forward and turn to strafe. Forward plus a side selects that side. Disable for Classic controls.");
		rangeMovement = ((BaseUnityPlugin)this).Config.Bind<bool>("Practice", "SoloRangeAirStrafe", true, "Use modded air and ground movement in solo practice. Set false for stock movement with the same speedometer.");
		try
		{
			Tuning = TuningProfile.Load(((BaseUnityPlugin)this).Config, delegate(string msg)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)msg);
			}, upgradeSlideTurn);
			sessions = new SessionRules(Tuning);
			patches = new Harmony("golfmods.sourcegolf");
			patches.PatchAll(typeof(Plugin).Assembly);
			operational = true;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Movement patch ready.");
		}
		catch (Exception ex2)
		{
			Harmony obj = patches;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			((BaseUnityPlugin)this).Logger.LogError((object)ex2);
		}
	}

	private void Update()
	{
		if (!operational || Time.unscaledTime < retryAt)
		{
			return;
		}
		try
		{
			if ((object)sessionConnection != NetworkClient.connection)
			{
				sessionConnection = (NetworkConnection)(object)NetworkClient.connection;
				DashJump.Refill();
			}
			bool flag = sessions.Evaluate(rangeMovement.Value);
			PublicHostLobby = sessions.PublicHostLobby;
			if (flag && Tuning != sessions.ActiveTuning)
			{
				DashJump.ChangeRecharge(sessions.ActiveTuning.RechargeSeconds);
				Tuning = sessions.ActiveTuning;
			}
			SetMovement(flag);
			StanceNetwork.Tick();
			admission.Tick(PublicHostLobby);
		}
		catch (Exception ex)
		{
			PublicHostLobby = null;
			admission.Tick(null);
			SetMovement(enabled: false);
			retryAt = Time.unscaledTime + 5f;
			((BaseUnityPlugin)this).Logger.LogWarning((object)ex);
		}
	}

	private void SetMovement(bool enabled)
	{
		if (MovementEnabled != enabled)
		{
			MovementEnabled = enabled;
			if (!enabled)
			{
				DashJump.ResetDive();
				CrouchSlide.Clear();
				TravelAnimation.ClearControllers();
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Source movement " + (enabled ? "enabled." : "disabled.")));
		}
	}

	private void LateUpdate()
	{
		hud.Render();
	}

	private void OnDestroy()
	{
		PublicHostLobby = null;
		SetMovement(enabled: false);
		StanceNetwork.Stop();
		Harmony obj = patches;
		if (obj != null)
		{
			obj.UnpatchSelf();
		}
		hud.Destroy();
	}
}
internal sealed class PoseRelay
{
	private sealed class Peer
	{
		internal GolferStanceMessage Stance;

		internal uint LastFlip;
	}

	private readonly Dictionary<int, Peer> peers = new Dictionary<int, Peer>();

	internal void Update(int sender, GolferStanceMessage stance, Action<int, GolferStanceMessage> send)
	{
		bool flag = stance.Snapshot;
		if (!peers.TryGetValue(sender, out var value) || value.Stance.Player != stance.Player)
		{
			value = (peers[sender] = new Peer());
			flag = true;
		}
		stance.Snapshot = false;
		value.Stance = stance;
		foreach (KeyValuePair<int, Peer> peer2 in peers)
		{
			send(peer2.Key, stance);
			if (flag && peer2.Key != sender)
			{
				send(sender, peer2.Value.Stance);
			}
		}
	}

	internal void Flip(int sender, DoubleJumpFlipMessage flip, Action<int, DoubleJumpFlipMessage> send)
	{
		if (!peers.TryGetValue(sender, out var value) || value.Stance.Player != flip.Player || (int)(flip.Sequence - value.LastFlip) <= 0)
		{
			return;
		}
		value.LastFlip = flip.Sequence;
		foreach (int key in peers.Keys)
		{
			if (key != sender)
			{
				send(key, flip);
			}
		}
	}

	internal void Remove(int connection)
	{
		peers.Remove(connection);
	}

	internal void Clear()
	{
		peers.Clear();
	}
}
internal sealed class PublicLobbyAdmission
{
	private readonly Dictionary<NetworkConnectionToClient, JoinGrace> waiting = new Dictionary<NetworkConnectionToClient, JoinGrace>();

	private readonly List<NetworkConnectionToClient> peers = new List<NetworkConnectionToClient>();

	private readonly List<NetworkConnectionToClient> stale = new List<NetworkConnectionToClient>();

	private string lobbyId;

	private NetworkConnection hostConnection;

	private double nextCheck;

	private double nextNotice;

	internal void Tick(BEosLobby lobby)
	{
		if (lobbyId != ((lobby != null) ? lobby.Id : null) || (object)hostConnection != NetworkServer.localConnection)
		{
			waiting.Clear();
			lobbyId = ((lobby != null) ? lobby.Id : null);
			hostConnection = (NetworkConnection)(object)NetworkServer.localConnection;
			nextCheck = (nextNotice = 0.0);
		}
		double realtimeSinceStartupAsDouble = Time.realtimeSinceStartupAsDouble;
		if (lobby == null || realtimeSinceStartupAsDouble < nextCheck)
		{
			return;
		}
		nextCheck = realtimeSinceStartupAsDouble + 0.25;
		peers.Clear();
		peers.AddRange(NetworkServer.connections.Values);
		stale.Clear();
		foreach (NetworkConnectionToClient key in waiting.Keys)
		{
			if (!NetworkServer.connections.TryGetValue(key.connectionId, out var value) || value != key)
			{
				stale.Add(key);
			}
		}
		foreach (NetworkConnectionToClient item in stale)
		{
			waiting.Remove(item);
		}
		foreach (NetworkConnectionToClient peer in peers)
		{
			if ((object)peer == NetworkServer.localConnection)
			{
				continue;
			}
			if (!((NetworkConnection)peer).isReady || !SessionRules.TryGetPeerMember(lobby, peer, out var member) || SessionRules.Matches(member))
			{
				waiting.Remove(peer);
				continue;
			}
			if (!waiting.TryGetValue(peer, out var value2))
			{
				waiting.Add(peer, value2 = new JoinGrace(realtimeSinceStartupAsDouble));
			}
			if (value2.Expired(realtimeSinceStartupAsDouble))
			{
				waiting.Remove(peer);
				((NetworkConnection)peer).Disconnect();
			}
			else if (value2.NeedsWarning(realtimeSinceStartupAsDouble) && !(realtimeSinceStartupAsDouble < nextNotice) && CanHearLobbyChat(peer) && !GameSettings.All.General.MuteTextChat && !GameManager.LocalPlayerId.HasCommunicationSanction)
			{
				string text = BuildNotice(GameManager.RemotePlayerPerConnectionId[peer.connectionId].PlayerId.PlayerName, SingletonNetworkBehaviour<TextChatManager>.Instance.maxMessageLength);
				if (text != null)
				{
					TextChatManager.SendChatMessage(text);
					value2.MarkWarned(realtimeSinceStartupAsDouble);
					nextNotice = realtimeSinceStartupAsDouble + 2.0;
				}
			}
		}
	}

	internal static string BuildNotice(string name, int maxLength)
	{
		string text = string.Format(", this lobby requires SourceGolf {0}. You'll be disconnected in {1} seconds. Install it from Thunderstore or r2modman to rejoin! :)", "1.1.0", 20);
		int num = maxLength - text.Length;
		if (num < 2 || string.IsNullOrWhiteSpace(name))
		{
			return null;
		}
		name = name.Trim().Replace('\r', ' ').Replace('\n', ' ');
		if (name.Length > num)
		{
			TextElementEnumerator textElementEnumerator = StringInfo.GetTextElementEnumerator(name);
			int length = 0;
			while (textElementEnumerator.MoveNext() && textElementEnumerator.ElementIndex < num)
			{
				length = textElementEnumerator.ElementIndex;
			}
			name = name.Substring(0, length) + "…";
		}
		return name + text;
	}

	private static bool CanHearLobbyChat(NetworkConnectionToClient peer)
	{
		if (SingletonNetworkBehaviour<TextChatManager>.HasInstance)
		{
			return ((NetworkBehaviour)SingletonNetworkBehaviour<TextChatManager>.Instance).netIdentity.observers.ContainsKey(peer.connectionId);
		}
		return false;
	}
}
internal sealed class SessionRules
{
	internal const string MemberKey = "SOURCE_GOLF_VERSION";

	private const string RulesKey = "SOURCE_GOLF_RULES";

	private readonly MovementTuning local;

	private readonly string localPayload;

	private string lastPayload;

	private MovementTuning decoded;

	private string advertisedLobby;

	private float nextPublish;

	internal MovementTuning ActiveTuning { get; private set; }

	internal BEosLobby PublicHostLobby { get; private set; }

	internal SessionRules(MovementTuning profile)
	{
		ActiveTuning = (local = profile);
		localPayload = profile.Encode();
	}

	internal bool Evaluate(bool rangeEnabled)
	{
		//IL_006e: 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_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Expected O, but got Unknown
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c6: Expected O, but got Unknown
		PublicHostLobby = null;
		if (!Object.op_Implicit((Object)(object)GameManager.LocalPlayerInfo) || !NetworkClient.ready || BNetworkManager.IsChangingSceneOrShuttingDown)
		{
			return false;
		}
		bool hasInstance = SingletonBehaviour<DrivingRangeManager>.HasInstance;
		BEosLobby currentLobby = BEosLobbyManager.CurrentLobby;
		if (!currentLobby.IsValid())
		{
			advertisedLobby = null;
			ActiveTuning = local;
			if (hasInstance && rangeEnabled && BNetworkManager.CurrentlyPlayingOffline && NetworkServer.localConnection != null)
			{
				return NetworkServer.connections.Count == 1;
			}
			return false;
		}
		if ((int)currentLobby.ProcessStatus != 0 || !currentLobby.Attributes.TryGetValue("LOBBY_VISIBILITY", out var value) || (NetworkServer.active && value.LongValue != (long)(ulong)BNetworkManager.LobbyMode))
		{
			return false;
		}
		bool flag = value.LongValue == 0;
		if (!flag && !IsPrivate(value.LongValue))
		{
			return false;
		}
		PlayerId localPlayerId = GameManager.LocalPlayerId;
		ProductUserId val = ((localPlayerId != null) ? localPlayerId.EosProductUserId : null);
		if ((Handle)(object)val == (Handle)null || !currentLobby.Members.TryGetValue(val, out var value2))
		{
			return false;
		}
		bool flag2 = (Handle)(object)currentLobby.OwnerId != (Handle)null && (Handle)(object)currentLobby.OwnerId == (Handle)(object)val;
		BEosAttribute value3;
		bool flag3 = flag2 && (!value2.Attributes.TryGetValue("SOURCE_GOLF_RULES", out value3) || value3.StringValue != localPayload);
		if (!Matches(value2) || flag3)
		{
			if (advertisedLobby != currentLobby.Id || Time.unscaledTime >= nextPublish)
			{
				advertisedLobby = currentLobby.Id;
				nextPublish = Time.unscaledTime + 5f;
				if (!Matches(value2))
				{
					currentLobby.SetOwnMemberAttribute(new BEosAttribute("SOURCE_GOLF_VERSION", "1.1.0", (LobbyAttributeVisibility)0));
				}
				if (flag3)
				{
					currentLobby.SetOwnMemberAttribute(new BEosAttribute("SOURCE_GOLF_RULES", localPayload, (LobbyAttributeVisibility)0));
				}
			}
			return false;
		}
		if ((Handle)(object)currentLobby.OwnerId == (Handle)null || !currentLobby.Members.TryGetValue(currentLobby.OwnerId, out var value4) || !Matches(value4) || (NetworkServer.active && !flag2))
		{
			return false;
		}
		if (!flag && !PrivatePartyReady(currentLobby))
		{
			return false;
		}
		if (!value4.Attributes.TryGetValue("SOURCE_GOLF_RULES", out var value5))
		{
			return false;
		}
		if (lastPayload != value5.StringValue)
		{
			lastPayload = value5.StringValue;
			MovementTuning.TryDecode(lastPayload, out decoded);
		}
		if (decoded == null)
		{
			return false;
		}
		ActiveTuning = (flag2 ? local : decoded);
		if (flag && flag2 && NetworkServer.activeHost)
		{
			PublicHostLobby = currentLobby;
		}
		return flag || !hasInstance || currentLobby.MemberCount > 1 || rangeEnabled;
	}

	private static bool PrivatePartyReady(BEosLobby lobby)
	{
		if (lobby.Members.Count != lobby.MemberCount || lobby.Members.Count != 1 + GameManager.RemotePlayers.Count || (NetworkServer.active && NetworkServer.connections.Count != lobby.Members.Count))
		{
			return false;
		}
		PlayerInfo val = default(PlayerInfo);
		foreach (KeyValuePair<ProductUserId, BEosLobbyMember> member in lobby.Members)
		{
			if (!Matches(member.Value) || !GameManager.TryFindPlayerByEosProductUserId(member.Key, ref val) || !Object.op_Implicit((Object)(object)val))
			{
				return false;
			}
		}
		return true;
	}

	internal static bool TryGetPeerMember(BEosLobby lobby, NetworkConnectionToClient peer, out BEosLobbyMember member)
	{
		member = null;
		if (!GameManager.RemotePlayerPerConnectionId.TryGetValue(peer.connectionId, out var value) || !Object.op_Implicit((Object)(object)value) || ((NetworkBehaviour)value).connectionToClient != peer || !Object.op_Implicit((Object)(object)value.PlayerId))
		{
			return false;
		}
		ProductUserId eosProductUserId = value.PlayerId.EosProductUserId;
		if ((Handle)(object)eosProductUserId != (Handle)null)
		{
			return lobby.Members.TryGetValue(eosProductUserId, out member);
		}
		return false;
	}

	private static bool IsPrivate(long mode)
	{
		if (mode != 1)
		{
			return mode == 2;
		}
		return true;
	}

	internal static bool Matches(BEosLobbyMember member)
	{
		if (member.Attributes.TryGetValue("SOURCE_GOLF_VERSION", out var value))
		{
			return string.Equals(value.StringValue, "1.1.0", StringComparison.Ordinal);
		}
		return false;
	}
}
internal sealed class Speedometer
{
	private GameObject overlay;

	private TextMeshProUGUI label;

	private GameObject staminaBar;

	private RectTransform cartPromptDock;

	private static readonly FieldRef<PlayerInfo, ButtonPrompt> ExitPrompt = AccessTools.FieldRefAccess<PlayerInfo, ButtonPrompt>("exitButtonPrompt");

	private readonly Image[] fills = (Image[])(object)new Image[2];

	private static readonly Color TrackColor = Color32.op_Implicit(new Color32((byte)32, (byte)48, (byte)52, byte.MaxValue));

	private static readonly Color ChargingColor = Color32.op_Implicit(new Color32((byte)99, (byte)140, (byte)131, byte.MaxValue));

	private static readonly Color FullColor = Color32.op_Implicit(new Color32((byte)145, (byte)224, (byte)191, byte.MaxValue));

	private int lastTenths = int.MinValue;

	private static readonly Color DashRe