Decompiled source of LobbyPatches v1.0.0

LobbyPatches.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using LobbyPatches.Core;
using LobbyPatches.Features;
using LobbyPatches.Features.HearPlayers;
using LobbyPatches.Features.LoadingPlayerList;
using LobbyPatches.Features.Menus;
using LobbyPatches.Features.Menus.Logic;
using LobbyPatches.Features.Security;
using LobbyPatches.Features.Security.Logic;
using LobbyPatches.Features.Spectators;
using LobbyPatches.Features.Spectators.Logic;
using LobbyPatches.Features.ZeroPingPhysics;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.PostProcessing;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LobbyPatches")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Usability patches for everyone in a R.E.P.O. lobby.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+21c8010926a10a371d0e58dd7a31e8fb23fd665c")]
[assembly: AssemblyProduct("LobbyPatches")]
[assembly: AssemblyTitle("LobbyPatches")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LobbyPatches
{
	[BepInPlugin("LobbyPatches", "LobbyPatches", "1.0.0")]
	[BepInProcess("REPO.exe")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private static readonly List<Feature> FeatureList = new List<Feature>();

		public static ConfigEntry<bool> ModEnabled { get; private set; }

		public static bool IsEnabled
		{
			get
			{
				if (ModEnabled != null)
				{
					return ModEnabled.Value;
				}
				return false;
			}
		}

		public static IReadOnlyList<Feature> Features => FeatureList;

		public static event Action<bool> EnabledChanged;

		private void Awake()
		{
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			ModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Master switch for LobbyPatches. Disabling it turns off every feature below without restarting the game.");
			ModEnabled.SettingChanged += delegate
			{
				foreach (Feature feature in FeatureList)
				{
					feature.ResetErrors();
				}
				RefreshFeatures();
				try
				{
					Plugin.EnabledChanged?.Invoke(IsEnabled);
				}
				catch (Exception exception)
				{
					ErrorLog.Report("EnabledChanged", exception);
				}
			};
			FeatureList.Add(new ZeroPingPhysicsFeature());
			FeatureList.Add(new SpectatorsFeature());
			FeatureList.Add(new SecurityFeature());
			FeatureList.Add(new HearPlayersFeature());
			FeatureList.Add(new LoadingPlayerListFeature());
			try
			{
				new Harmony("LobbyPatches").CreateClassProcessor(typeof(RunnerHeartbeat)).Patch();
			}
			catch (Exception arg)
			{
				Logger.LogError((object)$"Could not install the runner heartbeat: {arg}");
			}
			try
			{
				new Harmony("LobbyPatches.VoiceMute").CreateClassProcessor(typeof(VoiceMute)).Patch();
			}
			catch (Exception arg2)
			{
				Logger.LogError((object)$"Could not patch voice muting; muting players won't work: {arg2}");
			}
			foreach (Feature feature2 in FeatureList)
			{
				feature2.Bind(((BaseUnityPlugin)this).Config);
				feature2.ApplyPatches();
			}
			Runner.EnsureExists();
			RefreshFeatures();
			Logger.LogInfo((object)"Plugin LobbyPatches is loaded!");
		}

		internal static void RefreshFeatures()
		{
			Runner.EnsureExists();
			foreach (Feature feature in FeatureList)
			{
				feature.SetActive(IsEnabled && feature.Enabled.Value);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "LobbyPatches";

		public const string PLUGIN_NAME = "LobbyPatches";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace LobbyPatches.Features
{
	internal sealed class PublishedProperty
	{
		private const int NotPublished = int.MinValue;

		private readonly string _key;

		private int _published = int.MinValue;

		private Room _room;

		internal PublishedProperty(string key)
		{
			_key = key;
		}

		internal void Publish(int value)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			if (!PhotonNetwork.InRoom)
			{
				Forget();
				return;
			}
			if (PhotonNetwork.CurrentRoom != _room)
			{
				_published = int.MinValue;
				_room = PhotonNetwork.CurrentRoom;
			}
			if (value != _published && PhotonNetwork.LocalPlayer.SetCustomProperties(new Hashtable { [(object)_key] = value }, (Hashtable)null, (WebFlags)null))
			{
				_published = value;
			}
		}

		internal void Withdraw()
		{
			//IL_0026: 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_0041: Expected O, but got Unknown
			if (PhotonNetwork.InRoom && _published != int.MinValue && PhotonNetwork.CurrentRoom == _room)
			{
				PhotonNetwork.LocalPlayer.SetCustomProperties(new Hashtable { [(object)_key] = null }, (Hashtable)null, (WebFlags)null);
			}
			Forget();
		}

		internal object Read(Player player)
		{
			object value = null;
			if (player != null)
			{
				((Dictionary<object, object>)(object)player.CustomProperties).TryGetValue((object)_key, out value);
			}
			return value;
		}

		private void Forget()
		{
			_published = int.MinValue;
			_room = null;
		}
	}
	[HarmonyPatch]
	internal static class VoiceMute
	{
		internal sealed class Source
		{
			internal Feature Feature;

			internal Func<string, bool> Mutes;

			internal Action<Player, string> TurnedUp;
		}

		private static readonly List<Source> Sources = new List<Source>();

		private static readonly Dictionary<PlayerVoiceChat, float> Muted = new Dictionary<PlayerVoiceChat, float>();

		private static readonly HashSet<MenuSliderPlayerMicGain> ZeroedSliders = new HashSet<MenuSliderPlayerMicGain>();

		private static readonly List<PlayerVoiceChat> Stale = new List<PlayerVoiceChat>();

		private static int _prunedFrame;

		internal static void Register(Source source)
		{
			if (!Sources.Contains(source))
			{
				Sources.Add(source);
			}
		}

		internal static bool IsMuted(string steamId)
		{
			foreach (Source source in Sources)
			{
				if (Mutes(source, steamId))
				{
					return true;
				}
			}
			return false;
		}

		internal static bool IsMuted(PlayerAvatar player)
		{
			if (Object.op_Implicit((Object)(object)player) && !player.isLocal)
			{
				return IsMuted(SteamIdOf(player));
			}
			return false;
		}

		private static bool Mutes(Source source, string steamId)
		{
			try
			{
				return source.Mutes(steamId);
			}
			catch (Exception e)
			{
				Report(source, "VoiceMute", e);
				return false;
			}
		}

		internal static string SteamIdOf(PlayerAvatar player)
		{
			if (!string.IsNullOrEmpty(player.steamID))
			{
				return player.steamID;
			}
			if (!((Object)(object)player.photonView != (Object)null))
			{
				return null;
			}
			Player owner = player.photonView.Owner;
			if (owner == null)
			{
				return null;
			}
			return owner.UserId;
		}

		private static float GainFor(string steamId, float fallback = 0.5f)
		{
			if (!string.IsNullOrEmpty(steamId) && Object.op_Implicit((Object)(object)GameManager.instance))
			{
				return GameManager.instance.PlayerMicrophoneSettingGet(steamId);
			}
			return fallback;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerVoiceChat), "Update")]
		private static void PlayerVoiceChat_Update(PlayerVoiceChat __instance)
		{
			try
			{
				PruneStale();
				PhotonView photonView = __instance.photonView;
				if (Sources.Count == 0 || (Object.op_Implicit((Object)(object)photonView) && photonView.IsMine))
				{
					return;
				}
				PlayerAvatar playerAvatar = __instance.playerAvatar;
				object obj;
				if (!Object.op_Implicit((Object)(object)playerAvatar))
				{
					if (!Object.op_Implicit((Object)(object)photonView))
					{
						obj = null;
					}
					else
					{
						Player owner = photonView.Owner;
						obj = ((owner != null) ? owner.UserId : null);
					}
				}
				else
				{
					obj = SteamIdOf(playerAvatar);
				}
				string steamId = (string)obj;
				bool num;
				if (!Object.op_Implicit((Object)(object)playerAvatar))
				{
					num = IsMuted(steamId);
				}
				else
				{
					if (playerAvatar.isLocal)
					{
						goto IL_00f2;
					}
					num = IsMuted(steamId);
				}
				if (num)
				{
					if (!Muted.ContainsKey(__instance))
					{
						Muted[__instance] = GainFor(steamId, __instance.voiceGain);
					}
					__instance.voiceGain = 0f;
					if (Object.op_Implicit((Object)(object)__instance.lowPassLogic))
					{
						__instance.lowPassLogic.Volume = 0f;
					}
					if (Object.op_Implicit((Object)(object)__instance.lowPassLogicTTS))
					{
						__instance.lowPassLogicTTS.Volume = 0f;
					}
					return;
				}
				goto IL_00f2;
				IL_00f2:
				if (Muted.TryGetValue(__instance, out var value))
				{
					__instance.voiceGain = GainFor(steamId, value);
					Muted.Remove(__instance);
				}
			}
			catch (Exception exception)
			{
				ErrorLog.Report("VoiceMute.Voice", exception);
			}
		}

		private static void PruneStale()
		{
			if (_prunedFrame == Time.frameCount)
			{
				return;
			}
			_prunedFrame = Time.frameCount;
			ZeroedSliders.RemoveWhere((MenuSliderPlayerMicGain slider) => !Object.op_Implicit((Object)(object)slider));
			if (Muted.Count == 0)
			{
				return;
			}
			Stale.Clear();
			foreach (PlayerVoiceChat key in Muted.Keys)
			{
				if (!Object.op_Implicit((Object)(object)key))
				{
					Stale.Add(key);
				}
			}
			foreach (PlayerVoiceChat item in Stale)
			{
				Muted.Remove(item);
			}
		}

		private static string SliderSteamId(MenuSliderPlayerMicGain slider)
		{
			if (!Object.op_Implicit((Object)(object)slider.playerAvatar))
			{
				Player playerPhoton = slider.playerPhoton;
				if (playerPhoton == null)
				{
					return null;
				}
				return playerPhoton.UserId;
			}
			return slider.playerAvatar.steamID;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MenuSliderPlayerMicGain), "Update")]
		private static void MicGainSlider_Update(MenuSliderPlayerMicGain __instance)
		{
			try
			{
				if (Sources.Count == 0 || !__instance.fetched || !Object.op_Implicit((Object)(object)__instance.menuSlider) || __instance.playerPhoton == null || __instance.playerPhoton.IsLocal)
				{
					return;
				}
				PlayerVoiceChat val = (Object.op_Implicit((Object)(object)__instance.playerAvatar) ? __instance.playerAvatar.voiceChat : SemiFunc.PlayerVoiceChatGetFromPhotonPlayer(__instance.playerPhoton));
				if (!Object.op_Implicit((Object)(object)val))
				{
					ZeroedSliders.Remove(__instance);
					return;
				}
				string steamId = SliderSteamId(__instance);
				bool flag = IsMuted(steamId);
				if (flag && ZeroedSliders.Remove(__instance) && __instance.menuSlider.currentValue > 0)
				{
					TurnedUp(__instance.playerPhoton, steamId);
					flag = IsMuted(steamId);
				}
				if (flag)
				{
					if (__instance.menuSlider.currentValue != 0 || !ZeroedSliders.Contains(__instance))
					{
						__instance.SetSlider(0f);
						ZeroedSliders.Add(__instance);
					}
				}
				else if (ZeroedSliders.Remove(__instance))
				{
					__instance.SetSlider(GainFor(steamId, val.voiceGain));
				}
			}
			catch (Exception exception)
			{
				ErrorLog.Report("VoiceMute.Slider", exception);
			}
		}

		private static void TurnedUp(Player player, string steamId)
		{
			foreach (Source source in Sources)
			{
				if (source.TurnedUp == null && Mutes(source, steamId))
				{
					return;
				}
			}
			foreach (Source source2 in Sources)
			{
				if (source2.TurnedUp != null && Mutes(source2, steamId))
				{
					try
					{
						source2.TurnedUp(player, steamId);
					}
					catch (Exception e)
					{
						Report(source2, "VoiceMute.TurnedUp", e);
					}
				}
			}
		}

		private static void Report(Source source, string site, Exception e)
		{
			if (source.Feature != null)
			{
				source.Feature.ReportError(site, e);
			}
			else
			{
				ErrorLog.Report(site, e);
			}
		}
	}
}
namespace LobbyPatches.Features.ZeroPingPhysics
{
	internal sealed class CartCargo
	{
		internal const float EnterMargin = 0.02f;

		internal const float ExitMargin = 0.15f;

		private readonly PredictedBody _cart;

		private readonly List<CargoRide> _rides = new List<CargoRide>();

		private BoxCollider _box;

		private float _weight;

		private int _weightSteps;

		private readonly CartFooting _footing;

		private float _ownMass;

		private float _appliedMass;

		private float _ridersOnMass;

		private float _riders;

		private string _load = "";

		private float _springLift;

		private float _springLiftTime = float.MinValue;

		private bool _inSpring;

		private Vector3 _inertiaOwn;

		private readonly List<(Vector3 Force, Vector3 Position, ForceMode Mode)> _pulls = new List<(Vector3, Vector3, ForceMode)>();

		private const float SpringFresh = 0.03f;

		private static readonly Collider[] OverlapBuffer = (Collider[])(object)new Collider[16];

		internal bool OffTheGround
		{
			get
			{
				if (Object.op_Implicit((Object)(object)_footing))
				{
					return !_footing.Standing;
				}
				return true;
			}
		}

		internal bool PressedOnFloor => _ridersOnMass <= 0f;

		internal PredictedBody Cart => _cart;

		internal BoxCollider Box
		{
			get
			{
				PhysGrabCart val = (Object.op_Implicit((Object)(object)_cart.Object) ? _cart.Object.physGrabCart : null);
				if (!Object.op_Implicit((Object)(object)_box) && Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.inCart))
				{
					_box = ((Component)val.inCart).GetComponent<BoxCollider>();
				}
				return _box;
			}
		}

		internal float SpringLift
		{
			get
			{
				if (!(Time.fixedTime - _springLiftTime <= 0.03f))
				{
					return 0f;
				}
				return _springLift;
			}
		}

		internal float Weight => (_ownMass + _riders) * (0f - Physics.gravity.y);

		internal CartCargo(PredictedBody cart)
		{
			_cart = cart;
			_footing = ((Component)cart.Rb).GetComponent<CartFooting>();
			if (!Object.op_Implicit((Object)(object)_footing))
			{
				_footing = ((Component)cart.Rb).gameObject.AddComponent<CartFooting>();
			}
		}

		internal void Add(CargoRide ride)
		{
			_rides.Add(ride);
		}

		internal void Remove(CargoRide ride)
		{
			_rides.Remove(ride);
		}

		internal void Board()
		{
			if (_cart.Ended || !Object.op_Implicit((Object)(object)_cart.Object))
			{
				return;
			}
			PhysGrabCart physGrabCart = _cart.Object.physGrabCart;
			if (!Object.op_Implicit((Object)(object)physGrabCart))
			{
				return;
			}
			_weightSteps++;
			Load();
			foreach (PhysGrabObject item in physGrabCart.itemsInCart)
			{
				if (Object.op_Implicit((Object)(object)item) && !((Object)(object)item == (Object)(object)_cart.Object) && MayRide(item) && Prediction.Get(item) == null && Object.op_Implicit((Object)(object)item.photonTransformView) && Object.op_Implicit((Object)(object)item.rb) && HostHas(item.photonTransformView, item.rb, 0.02f))
				{
					Prediction.Begin(item, _cart.Depth + 1, 0.75f, toRide: true);
				}
			}
		}

		private void Load()
		{
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			Rigidbody rb = _cart.Rb;
			if (!Mathf.Approximately(rb.mass, _appliedMass))
			{
				_ownMass = rb.mass;
			}
			float num = 0f;
			if (_cart.IsLocal && !rb.isKinematic)
			{
				foreach (CargoRide ride in _rides)
				{
					if (!ride.Item.Ended && ride.Item.Alive)
					{
						num += ride.Item.Rb.mass;
					}
				}
			}
			_riders = num;
			float springLift = SpringLift;
			bool flag = Object.op_Implicit((Object)(object)_footing) && _footing.Standing;
			_ridersOnMass = (RiderLoad.OnCartMass(num, _ownMass, flag, springLift, 0f - Physics.gravity.y) ? num : 0f);
			_load = ((num <= 0f) ? "" : ((_ridersOnMass <= 0f) ? "riders press on its floor" : (flag ? "riders on its mass (the beam lifts it all)" : "riders on its mass (in the air)")));
			SetMass(_ownMass + _ridersOnMass);
		}

		private void SetMass(float mass)
		{
			_appliedMass = mass;
			Rigidbody rb = _cart.Rb;
			if (Object.op_Implicit((Object)(object)rb) && !Mathf.Approximately(rb.mass, mass))
			{
				rb.mass = mass;
			}
		}

		internal void HandBack()
		{
			_ridersOnMass = 0f;
			if (Object.op_Implicit((Object)(object)_cart.Rb) && Mathf.Approximately(_cart.Rb.mass, _appliedMass))
			{
				SetMass(_ownMass);
			}
		}

		internal void SpringEnter()
		{
			//IL_005a: 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)
			_inSpring = true;
			_pulls.Clear();
			if (_springLiftTime != Time.fixedTime)
			{
				_springLift = 0f;
			}
			if (!(_ridersOnMass <= 0f))
			{
				_cart.Rb.mass = _ownMass;
				_inertiaOwn = _cart.Rb.inertiaTensor;
			}
		}

		internal bool TakeSpring(Vector3 force, Vector3 position, ForceMode mode)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			if (!_inSpring)
			{
				return false;
			}
			if ((int)mode == 0)
			{
				_springLift += force.y;
				_springLiftTime = Time.fixedTime;
			}
			if (_ridersOnMass <= 0f)
			{
				return false;
			}
			_pulls.Add((force, position, mode));
			return true;
		}

		internal void SpringExit()
		{
			//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_0089: 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_0091: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: 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_00ae: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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)
			_inSpring = false;
			if (_ridersOnMass <= 0f || !Object.op_Implicit((Object)(object)_cart.Rb))
			{
				return;
			}
			Rigidbody rb = _cart.Rb;
			rb.mass = _appliedMass;
			Vector3 inertiaTensor = rb.inertiaTensor;
			float num = ((((Vector3)(ref _inertiaOwn)).sqrMagnitude > 0f) ? (((Vector3)(ref inertiaTensor)).magnitude / ((Vector3)(ref _inertiaOwn)).magnitude) : 1f);
			foreach (var (val, val2, val3) in _pulls)
			{
				rb.AddForce(RiderLoad.SpringForce(val, _ownMass, _ridersOnMass), val3);
				rb.AddTorque(Vector3.Cross(val2 - rb.worldCenterOfMass, val) * num, val3);
			}
			_pulls.Clear();
		}

		internal static bool MayRide(PhysGrabObject o)
		{
			if (!o.isCart && o.playerGrabbing.Count == 0)
			{
				if (o.isPlayer)
				{
					return Prediction.CanPredictPlayer(o);
				}
				return true;
			}
			return false;
		}

		internal static PredictedBody FindCartFor(PredictedBody item, PredictedBody current)
		{
			if (!MayRide(item.Object))
			{
				return null;
			}
			foreach (PredictedBody item2 in Prediction.All)
			{
				if (item2 != item && item2.Cargo != null && !item2.Ended && item2.Alive && item2.Cargo.HostHas(item.View, item.Rb, CargoGeometry.Margin(item2 == current)))
				{
					return item2;
				}
			}
			return null;
		}

		internal string Describe()
		{
			int num = 0;
			float num2 = 0f;
			float num3 = 0f;
			string text = null;
			foreach (CargoRide ride in _rides)
			{
				if (!ride.Item.Ended && ride.Item.Alive)
				{
					num++;
					num2 += ride.Item.Rb.mass;
					num3 = Mathf.Max(num3, ride.OffHostSpot);
					PlayerAvatar player = ride.Player;
					if (Object.op_Implicit((Object)(object)player))
					{
						text = ((text == null) ? "" : (text + ", ")) + player.playerName;
					}
				}
			}
			string text2 = $"cargo {num} items {num2:F1} kg";
			if (text != null)
			{
				text2 = text2 + " (tumbling players: " + text + ")";
			}
			if (num > 0)
			{
				text2 += $", riders up to {num3:F2} m from their host spots, {_load}, pressing with {((_weightSteps > 0) ? (_weight / (float)_weightSteps) : 0f):F0} N";
			}
			_weight = 0f;
			_weightSteps = 0;
			return text2;
		}

		internal void OnWeight(float newtons)
		{
			_weight += newtons;
		}

		private bool HostHas(PhotonTransformView view, Rigidbody rb, float margin)
		{
			return HostInCart(view, rb, Box, _cart.View, _cart.Rb, margin);
		}

		private static bool HostInCart(PhotonTransformView view, Rigidbody rb, BoxCollider box, PhotonTransformView cartView, Rigidbody cartRb, float margin)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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)
			if (!Object.op_Implicit((Object)(object)box) || !Object.op_Implicit((Object)(object)cartView) || !Object.op_Implicit((Object)(object)cartRb) || !view.receivedAny || !cartView.receivedAny)
			{
				return false;
			}
			Vector3 val = CargoGeometry.OnOurCart(view.receivedPosition + view.receivedRotation * rb.centerOfMass, cartView.receivedPosition, cartView.receivedRotation, cartRb.position, cartRb.rotation);
			Vector3 val2 = ((Collider)box).ClosestPoint(val) - val;
			return ((Vector3)(ref val2)).sqrMagnitude <= margin * margin;
		}

		internal static PhysGrabCart CartAt(Vector3 point)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			int num = Physics.OverlapSphereNonAlloc(point, 0.01f, OverlapBuffer, -1, (QueryTriggerInteraction)2);
			for (int i = 0; i < num; i++)
			{
				Collider val = OverlapBuffer[i];
				PhysGrabCart val2 = (Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponentInParent<PhysGrabCart>() : null);
				if (Object.op_Implicit((Object)(object)val2) && (Object)(object)val2.inCart == (Object)(object)((Component)val).transform)
				{
					return val2;
				}
			}
			return null;
		}

		internal static bool Disagrees(PredictedBody item)
		{
			//IL_001e: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			if (item.Object.isCart)
			{
				return false;
			}
			PhotonTransformView view = item.View;
			Rigidbody rb = item.Rb;
			PhysGrabCart val = CartAt(rb.worldCenterOfMass);
			if (Object.op_Implicit((Object)(object)val) && !HostInCart(view, rb, val, 0.15f))
			{
				return true;
			}
			PhysGrabCart val2 = CartAt(view.receivedPosition + view.receivedRotation * rb.centerOfMass);
			if (!Object.op_Implicit((Object)(object)val2) || (Object)(object)val2 == (Object)(object)val || Prediction.Get(val2.physGrabObject) != null)
			{
				return false;
			}
			BoxCollider val3 = (Object.op_Implicit((Object)(object)val2.inCart) ? ((Component)val2.inCart).GetComponent<BoxCollider>() : null);
			Vector3 worldCenterOfMass = rb.worldCenterOfMass;
			if (Object.op_Implicit((Object)(object)val3))
			{
				Vector3 val4 = ((Collider)val3).ClosestPoint(worldCenterOfMass) - worldCenterOfMass;
				return ((Vector3)(ref val4)).sqrMagnitude > 0.0225f;
			}
			return false;
		}

		private static bool HostInCart(PhotonTransformView view, Rigidbody rb, PhysGrabCart cart, float margin)
		{
			PhysGrabObject physGrabObject = cart.physGrabObject;
			BoxCollider box = (Object.op_Implicit((Object)(object)cart.inCart) ? ((Component)cart.inCart).GetComponent<BoxCollider>() : null);
			if (Object.op_Implicit((Object)(object)physGrabObject))
			{
				return HostInCart(view, rb, box, physGrabObject.photonTransformView, physGrabObject.rb, margin);
			}
			return false;
		}
	}
	internal sealed class CargoRide
	{
		internal readonly PredictedBody Item;

		internal readonly PredictedBody Cart;

		private readonly CartCargo _cargo;

		private readonly CargoRiding _riding;

		private readonly IgnoredPairs<Collider> _pairs;

		private readonly PlayerTumble _tumble;

		internal Vector3 CartVelocity
		{
			get
			{
				//IL_001f: 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)
				if (!Cart.Alive || Cart.Rb.isKinematic)
				{
					return Vector3.zero;
				}
				return Cart.Rb.linearVelocity;
			}
		}

		internal PlayerAvatar Player
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)_tumble))
				{
					return null;
				}
				return _tumble.playerAvatar;
			}
		}

		internal float OffHostSpot => _riding.OffHostSpot;

		internal CargoRide(PredictedBody item, PredictedBody cart, IgnoredPairs<Collider> pairs)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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)
			Item = item;
			Cart = cart;
			_cargo = cart.Cargo;
			_pairs = pairs;
			_tumble = (item.Object.isPlayer ? ((Component)item.Object).GetComponent<PlayerTumble>() : null);
			_riding = new CargoRiding(item.Rb.position, item.Rb.rotation, cart.Rb.position, cart.Rb.rotation);
			item.Rb.isKinematic = true;
			Collider[] componentsInChildren = ((Component)item.Object).GetComponentsInChildren<Collider>(true);
			foreach (Collider val in componentsInChildren)
			{
				if (!Object.op_Implicit((Object)(object)val) || val.isTrigger)
				{
					continue;
				}
				Collider[] componentsInChildren2 = ((Component)cart.Object).GetComponentsInChildren<Collider>(true);
				foreach (Collider val2 in componentsInChildren2)
				{
					if (Object.op_Implicit((Object)(object)val2) && !val2.isTrigger)
					{
						_pairs.Claim(this, val, val2);
					}
				}
			}
			_cargo.Add(this);
		}

		internal void Detach()
		{
			int num = _pairs.Release(this);
			_cargo.Remove(this);
			if (num > 0 && ZeroPingPhysicsFeature.DebugLog.Value && Object.op_Implicit((Object)(object)Item.Object) && Object.op_Implicit((Object)(object)Cart.Object))
			{
				DebugFile.Write($"[ZeroPingPhysics] {((Object)Item.Object).name}: {num} collider pairs still inside {((Object)Cart.Object).name}; they collide again once apart");
			}
		}

		internal void Step(float dt)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
			if (!Item.Rb.isKinematic)
			{
				Item.Rb.isKinematic = true;
			}
			PhotonTransformView view = Item.View;
			PhotonTransformView view2 = Cart.View;
			_riding.OnHostPoses(view.receivedPosition, view.receivedRotation, view.receivedServerTimestamp, view2.receivedPosition, view2.receivedRotation, view2.receivedServerTimestamp);
			Rigidbody rb = Cart.Rb;
			_riding.Place(rb.position, rb.rotation, rb.linearVelocity, rb.angularVelocity, !rb.isKinematic, dt, out var position, out var rotation);
			Item.Rb.MovePosition(position);
			Item.Rb.MoveRotation(rotation);
			AddWeight();
		}

		private void AddWeight()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			Rigidbody rb = Cart.Rb;
			if (!rb.isKinematic && Item.Rb.useGravity && _cargo.PressedOnFloor)
			{
				Vector3 val = Item.Rb.worldCenterOfMass;
				BoxCollider box = _cargo.Box;
				if (Object.op_Implicit((Object)(object)box))
				{
					val = ((Collider)box).ClosestPoint(val);
				}
				Vector3 val2 = Physics.gravity * Item.Rb.mass;
				if (Object.op_Implicit((Object)(object)_tumble) && Item.Object.playerGrabbing.Count <= 0 && _tumble.customGravityOverrideTimer <= 0f)
				{
					val2 -= Vector3.up * _tumble.customGravity;
				}
				rb.AddForceAtPosition(val2, val, (ForceMode)0);
				_cargo.OnWeight(((Vector3)(ref val2)).magnitude);
			}
		}
	}
	internal sealed class CartFooting : MonoBehaviour
	{
		private const float MinUp = 0.5f;

		private float _lastStanding = float.MinValue;

		internal bool Standing => Time.fixedTime - _lastStanding <= Time.fixedDeltaTime * 1.5f;

		private void OnCollisionEnter(Collision collision)
		{
			Record(collision);
		}

		private void OnCollisionStay(Collision collision)
		{
			Record(collision);
		}

		private void Record(Collision collision)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < collision.contactCount; i++)
			{
				ContactPoint contact = collision.GetContact(i);
				if (((ContactPoint)(ref contact)).normal.y > 0.5f)
				{
					_lastStanding = Time.fixedTime;
					break;
				}
			}
		}
	}
	internal static class CartLiftDebug
	{
		private const int PullHistory = 50;

		private static readonly Queue<(double Time, Vector3 Puller)> Pulls = new Queue<(double, Vector3)>();

		private static PhysGrabObject _held;

		private static int _loggedStamp;

		internal static float Capacity(PhysGrabObject o, PhysGrabber grabber, float strength)
		{
			return Mathf.Min(grabber.forceMax * grabber.springConstant, grabber.forceMax) * 2f * o.GrabStrengthGet(strength, 30f) * grabber.forceConstant;
		}

		internal static string Describe(PhysGrabObject o, Rigidbody cartRb, PhysGrabber grabber, Vector3 hostPosition, Quaternion hostRotation, float lifting, float weight)
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)o) || !Object.op_Implicit((Object)(object)grabber) || !Object.op_Implicit((Object)(object)grabber.playerAvatar))
			{
				return "";
			}
			float grab;
			float throwStrength;
			float num = (HostStrength.TryGet(grabber, out grab, out throwStrength) ? grab : grabber.grabStrength);
			string text = $", lift: can pull {Capacity(o, grabber, num):F0} N (strength {num:F2}, " + $"{o.GrabStrengthGet(num, 30f):F2} as the force code takes it), has to lift {weight:F0} N";
			if (!float.IsNaN(lifting))
			{
				text += $", pulled up with {lifting:F0} N";
			}
			string text2 = Blocks(o, cartRb, grabber.playerAvatar, cartRb.position, cartRb.rotation, standingKnown: true);
			string text3 = Blocks(o, cartRb, grabber.playerAvatar, hostPosition, hostRotation, standingKnown: false);
			return text + ", lift taken away here: " + (text2 ?? "no") + ", on the host: " + (text3 ?? "no");
		}

		private static string Blocks(PhysGrabObject o, Rigidbody cartRb, PlayerAvatar avatar, Vector3 cartPosition, Quaternion cartRotation, bool standingKnown)
		{
			//IL_0048: 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_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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			string text = null;
			PhysGrabCart physGrabCart = o.physGrabCart;
			BoxCollider val = ((Object.op_Implicit((Object)(object)physGrabCart) && Object.op_Implicit((Object)(object)physGrabCart.inCart)) ? ((Component)physGrabCart.inCart).GetComponent<BoxCollider>() : null);
			Vector3 val2 = OnOurCart((avatar.isTumbling && Object.op_Implicit((Object)(object)avatar.tumble)) ? avatar.tumble.physGrabObject.centerPoint : (((Component)avatar).transform.position + Vector3.up * 0.25f), cartPosition, cartRotation, cartRb);
			if (Object.op_Implicit((Object)(object)val) && Vector3.Distance(((Collider)val).ClosestPoint(val2), val2) < 0.01f)
			{
				text = "we're inside it";
			}
			PlayerPhysObjectStander physObjectStander = avatar.physObjectStander;
			if (!Object.op_Implicit((Object)(object)physObjectStander))
			{
				return text;
			}
			bool flag;
			if (standingKnown)
			{
				flag = physObjectStander.physGrabObjects.Contains(o);
			}
			else
			{
				SphereCollider component = ((Component)physObjectStander).GetComponent<SphereCollider>();
				flag = Object.op_Implicit((Object)(object)component) && Touches(o, OnOurCart(((Component)physObjectStander).transform.position, cartPosition, cartRotation, cartRb), component.radius, physObjectStander.layerMask);
			}
			if (flag)
			{
				text = ((text == null) ? "we stand on it" : (text + ", we stand on it"));
			}
			return text;
		}

		private static Vector3 OnOurCart(Vector3 point, Vector3 cartPosition, Quaternion cartRotation, Rigidbody cartRb)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			return CargoGeometry.OnOurCart(point, cartPosition, cartRotation, cartRb.position, cartRb.rotation);
		}

		private static bool Touches(PhysGrabObject o, Vector3 center, float radius, LayerMask layers)
		{
			//IL_004c: 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)
			Collider[] componentsInChildren = ((Component)o).GetComponentsInChildren<Collider>();
			foreach (Collider val in componentsInChildren)
			{
				if (!Object.op_Implicit((Object)(object)val) || !val.enabled || (((LayerMask)(ref layers)).value & (1 << ((Component)val).gameObject.layer)) == 0)
				{
					continue;
				}
				MeshCollider val2 = (MeshCollider)(object)((val is MeshCollider) ? val : null);
				if (val2 == null || val2.convex)
				{
					Vector3 val3 = val.ClosestPoint(center) - center;
					if (((Vector3)(ref val3)).sqrMagnitude <= radius * radius)
					{
						return true;
					}
				}
			}
			return false;
		}

		internal static void Sample(float dt)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			PhysGrabber instance = PhysGrabber.instance;
			PhysGrabObject val = ((Object.op_Implicit((Object)(object)instance) && instance.grabbed) ? instance.grabbedPhysGrabObject : null);
			if (!Object.op_Implicit((Object)(object)val) || !val.isCart || Prediction.Get(val) != null || instance.physGrabForcesDisabledTimer > 0f)
			{
				Pulls.Clear();
				_held = null;
				return;
			}
			if ((Object)(object)val != (Object)(object)_held)
			{
				Pulls.Clear();
			}
			_held = val;
			Pulls.Enqueue((Prediction.Timeline.StepTime - (double)dt, instance.physGrabPointPullerPosition));
			while (Pulls.Count > 50)
			{
				Pulls.Dequeue();
			}
		}

		internal static void OnUnpredictedHostState(PhotonTransformView view, double sentServerTime)
		{
			//IL_00ca: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: 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_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			PhysGrabObject held = _held;
			if (!Object.op_Implicit((Object)(object)held) || (Object)(object)held.photonTransformView != (Object)(object)view || view.receivedServerTimestamp == _loggedStamp || Pulls.Count == 0)
			{
				return;
			}
			_loggedStamp = view.receivedServerTimestamp;
			PhysGrabber instance = PhysGrabber.instance;
			HostTimeline timeline = Prediction.Timeline;
			timeline.Observe(PhotonNetwork.Time, sentServerTime);
			double num = timeline.ToLocal(sentServerTime) - timeline.Delay;
			(double, Vector3) tuple = default((double, Vector3));
			double num2 = double.MaxValue;
			foreach (var pull in Pulls)
			{
				double num3 = Math.Abs(pull.Time - num);
				if (num3 < num2)
				{
					num2 = num3;
					tuple = pull;
				}
			}
			Vector3 val = view.receivedPosition + view.receivedRotation * instance.localGrabPosition;
			Vector3 val2 = tuple.Item2 - val;
			Vector3 receivedVelocity = view.receivedVelocity;
			float num4 = 0f;
			int num5 = 0;
			if (Object.op_Implicit((Object)(object)held.physGrabCart))
			{
				foreach (PhysGrabObject item in held.physGrabCart.itemsInCart)
				{
					if (Object.op_Implicit((Object)(object)item) && !((Object)(object)item == (Object)(object)held) && Object.op_Implicit((Object)(object)item.rb))
					{
						num5++;
						num4 += item.rb.mass;
					}
				}
			}
			float weight = (held.rb.mass + num4) * (0f - Physics.gravity.y);
			string[] array = new string[6];
			string name = ((Object)held).name;
			Vector2 val3 = new Vector2(receivedVelocity.x, receivedVelocity.z);
			array[0] = $"[ZeroPingPhysics] {name}: not predicted, held by our beam: host velocity {((Vector2)(ref val3)).magnitude:F2} m/s horizontal ";
			array[1] = $"{receivedVelocity.y:+0.00;-0.00} vertical, the host's spring stretched {((Vector3)(ref val2)).magnitude:F2} m ";
			val3 = new Vector2(val2.x, val2.z);
			array[2] = $"({((Vector2)(ref val3)).magnitude:F2} horizontal {val2.y:+0.00;-0.00} vertical) for our pull ";
			array[3] = string.Format("{0}, cart mass {1:F1}, ", (num2 < 0.05) ? $"{timeline.Delay * 1000.0:F0} ms before" : "(none from then)", held.rb.mass);
			array[4] = $"in it {num5} items {num4:F1} kg";
			array[5] = Describe(held, held.rb, instance, view.receivedPosition, view.receivedRotation, float.NaN, weight);
			DebugFile.Write(string.Concat(array));
		}
	}
	internal sealed class CartRole
	{
		private readonly PhysGrabObject _object;

		private readonly PhysGrabCart _cart;

		private readonly CartTurret _turret;

		private readonly CartMode _mode;

		private CartModeKind _modeNow;

		private bool _claimed;

		internal readonly CartCargo Cargo;

		internal readonly CartSteerDebug Debug;

		private CartModeKind HostMode => (CartModeKind)_cart.currentState;

		private PhysGrabObjectGrabArea Handle
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)_cart))
				{
					return _turret?.Handle;
				}
				return _cart.physGrabObjectGrabArea;
			}
		}

		private CartRole(PredictedBody body, CartTurret turret)
		{
			_object = body.Object;
			_cart = body.Object.physGrabCart;
			_turret = turret;
			Cargo = (Object.op_Implicit((Object)(object)_cart) ? new CartCargo(body) : null);
			if (Object.op_Implicit((Object)(object)_cart))
			{
				_modeNow = HostMode;
				_mode = new CartMode(_modeNow);
				if (ZeroPingPhysicsFeature.DebugLog.Value)
				{
					Debug = new CartSteerDebug(_cart, body.Rb, Cargo);
				}
			}
		}

		internal static CartRole For(PredictedBody body, CartTurret turret)
		{
			if (!Object.op_Implicit((Object)(object)body.Object.physGrabCart) && turret == null)
			{
				return null;
			}
			return new CartRole(body, turret);
		}

		internal void OnGrabStarted()
		{
			if (Object.op_Implicit((Object)(object)_cart) && _object.playerGrabbing.Count == 1)
			{
				_cart.cartActive = false;
			}
		}

		internal void Step(float dt, bool heldLocally, PhysGrabber localGrabber, float confirmWithin)
		{
			if (heldLocally && HostCopies.ClaimHandle(Handle, localGrabber))
			{
				_claimed = true;
			}
			if (Object.op_Implicit((Object)(object)_cart))
			{
				if (!heldLocally)
				{
					_cart.AutoTurnOff();
				}
				_modeNow = _mode.Step(dt, _cart.cartActive, _object.playerGrabbing.Count > 0, HostMode, confirmWithin);
				PutOnMaterials(_modeNow);
				Debug?.Step(dt, heldLocally ? localGrabber : null, _modeNow, HostMode);
			}
		}

		internal void HandBack()
		{
			if (Object.op_Implicit((Object)(object)_cart))
			{
				Cargo?.HandBack();
				_modeNow = HostMode;
				PutOnMaterials(_modeNow);
				Debug?.Detach();
			}
		}

		private void PutOnMaterials(CartModeKind mode)
		{
			PhysicsMaterial val;
			PhysicsMaterial val2;
			switch (mode)
			{
			case CartModeKind.Handled:
				val = _cart.physMaterialSlippery;
				val2 = SemiFunc.PhysicMaterialPhysGrabObject();
				break;
			case CartModeKind.Dragged:
				val = (val2 = _cart.physMaterialALilSlippery);
				break;
			default:
				val = (val2 = _cart.physMaterialNormal);
				break;
			}
			foreach (Collider capsuleCollider in _cart.capsuleColliders)
			{
				if (Object.op_Implicit((Object)(object)capsuleCollider) && (Object)(object)capsuleCollider.sharedMaterial != (Object)(object)val)
				{
					capsuleCollider.sharedMaterial = val;
				}
			}
			foreach (Collider item in _cart.cartInside)
			{
				if (Object.op_Implicit((Object)(object)item) && (Object)(object)item.sharedMaterial != (Object)(object)val2)
				{
					item.sharedMaterial = val2;
				}
			}
		}

		internal void Release(PhysGrabber grabber, bool evenIfHostAdded)
		{
			if (_claimed || evenIfHostAdded)
			{
				_claimed = false;
				PhysGrabObjectGrabArea handle = Handle;
				if (Object.op_Implicit((Object)(object)handle))
				{
					handle.listOfAllGrabbers.Remove(grabber);
				}
			}
		}

		internal string Describe(Rigidbody rb, PhysGrabber holder, in BodyState host, double hostTime, double hostDelay)
		{
			//IL_0114: 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)
			if (!Object.op_Implicit((Object)(object)_cart) || Cargo == null)
			{
				return "";
			}
			PhysGrabObjectGrabArea handle = Handle;
			return $", cart: mass {rb.mass:F1}, {Cargo.Describe()}, active {_cart.cartActive}, pulled {_cart.cartBeingPulled}, " + $"handle grabbers {(Object.op_Implicit((Object)(object)handle) ? handle.listOfAllGrabbers.Count : (-1))}, beam suppressed for " + $"{(Object.op_Implicit((Object)(object)holder) ? holder.physGrabForcesDisabledTimer : (-1f)):F2} s" + Debug?.Describe(handle, _modeNow, in host, hostTime, hostDelay) + ((Object.op_Implicit((Object)(object)holder) && holder.physGrabForcesDisabledTimer <= 0f) ? CartLiftDebug.Describe(_object, rb, holder, host.Position, host.Rotation, Cargo.SpringLift, Cargo.Weight) : "");
		}
	}
	internal sealed class CartSteerDebug
	{
		private readonly struct BeamSample
		{
			internal readonly double Time;

			internal readonly Vector3 Puller;

			internal readonly Vector3 LocalGrabPoint;

			internal readonly float Stretch;

			internal BeamSample(double time, Vector3 puller, Vector3 localGrabPoint, float stretch)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				Time = time;
				Puller = puller;
				LocalGrabPoint = localGrabPoint;
				Stretch = stretch;
			}
		}

		internal sealed class ContactProbe : MonoBehaviour
		{
			internal CartSteerDebug Owner;

			private Rigidbody _rb;

			private void Awake()
			{
				_rb = ((Component)this).GetComponent<Rigidbody>();
			}

			private void OnCollisionEnter(Collision collision)
			{
				Record(collision);
			}

			private void OnCollisionStay(Collision collision)
			{
				Record(collision);
			}

			private void Record(Collision collision)
			{
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				if (Owner != null && Object.op_Implicit((Object)(object)_rb) && !(_rb.mass <= 0f))
				{
					Vector3 val = Flat(collision.impulse);
					float num = ((Vector3)(ref val)).magnitude / _rb.mass;
					if (num >= 0.01f)
					{
						Owner.OnPushed(collision.collider, num);
					}
				}
			}
		}

		private readonly PhysGrabCart _cart;

		private readonly Rigidbody _rb;

		private readonly CartCargo _cargo;

		private readonly ContactProbe _probe;

		private int _steps;

		private float _leftAt;

		private float _foundAt;

		private float _lost;

		private float _corrected;

		private bool _hasLeft;

		private Vector3 _left;

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

		private readonly Dictionary<Collider, (string Label, PhysGrabObject Object, PlayerAvatar Avatar)> _labels = new Dictionary<Collider, (string, PhysGrabObject, PlayerAvatar)>();

		private const int PullerHistory = 40;

		private readonly Queue<(float Time, Vector3 Position, Vector3 Forward)> _puller = new Queue<(float, Vector3, Vector3)>();

		private const int BeamHistory = 50;

		private readonly Queue<BeamSample> _beam = new Queue<BeamSample>();

		private bool _wasOff;

		private int _groundSteps;

		private int _offSteps;

		private int _groundSwitches;

		private bool _modesLogged;

		private CartModeKind _oursLogged;

		private CartModeKind _hostLogged;

		private bool OffTheGround => _cargo.OffTheGround;

		internal CartSteerDebug(PhysGrabCart cart, Rigidbody rb, CartCargo cargo)
		{
			_cart = cart;
			_rb = rb;
			_cargo = cargo;
			_probe = ((Component)rb).GetComponent<ContactProbe>();
			if (!Object.op_Implicit((Object)(object)_probe))
			{
				_probe = ((Component)rb).gameObject.AddComponent<ContactProbe>();
			}
			_probe.Owner = this;
		}

		internal void Detach()
		{
			if (Object.op_Implicit((Object)(object)_probe) && _probe.Owner == this)
			{
				_probe.Owner = null;
			}
		}

		private static Vector3 Flat(Vector3 v)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(v.x, 0f, v.z);
		}

		internal void Step(float dt, PhysGrabber grabber, CartModeKind ours, CartModeKind host)
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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)
			bool offTheGround = OffTheGround;
			if (_groundSteps > 0 && offTheGround != _wasOff)
			{
				_groundSwitches++;
			}
			_wasOff = offTheGround;
			_groundSteps++;
			if (offTheGround)
			{
				_offSteps++;
			}
			LogModes(ours, host);
			if (Object.op_Implicit((Object)(object)grabber) && Object.op_Implicit((Object)(object)grabber.physGrabPoint) && grabber.physGrabForcesDisabledTimer <= 0f)
			{
				Vector3 position = grabber.physGrabPoint.position;
				Vector3 physGrabPointPullerPosition = grabber.physGrabPointPullerPosition;
				Queue<BeamSample> beam = _beam;
				double time = Prediction.Timeline.StepTime - (double)dt;
				Vector3 localGrabPoint = Quaternion.Inverse(_rb.rotation) * (position - _rb.position);
				Vector3 val = physGrabPointPullerPosition - position;
				beam.Enqueue(new BeamSample(time, physGrabPointPullerPosition, localGrabPoint, ((Vector3)(ref val)).magnitude));
				while (_beam.Count > 50)
				{
					_beam.Dequeue();
				}
			}
			else
			{
				_beam.Clear();
			}
		}

		private void LogModes(CartModeKind ours, CartModeKind host)
		{
			if (!_modesLogged || ours != _oursLogged || host != _hostLogged)
			{
				if (_modesLogged)
				{
					DebugFile.Write($"[ZeroPingPhysics] {((Object)_cart).name}: wheels {ours} (host's mode {host}" + ((ours != host) ? ", ours not confirmed yet" : "") + ")");
				}
				_modesLogged = true;
				_oursLogged = ours;
				_hostLogged = host;
			}
		}

		internal void BeforeSteer()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Flat(_rb.linearVelocity);
			if (_hasLeft)
			{
				_foundAt += ((Vector3)(ref val)).magnitude;
				_lost += ((Vector3)(ref _left)).magnitude - ((Vector3)(ref val)).magnitude;
			}
		}

		internal void AfterSteer()
		{
			//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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			_left = Flat(_rb.linearVelocity);
			_hasLeft = true;
			_leftAt += ((Vector3)(ref _left)).magnitude;
			_steps++;
			PhysGrabObjectGrabArea physGrabObjectGrabArea = _cart.physGrabObjectGrabArea;
			PhysGrabber val = ((Object.op_Implicit((Object)(object)physGrabObjectGrabArea) && physGrabObjectGrabArea.listOfAllGrabbers.Count > 0) ? physGrabObjectGrabArea.listOfAllGrabbers[0] : null);
			if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.playerAvatar))
			{
				_puller.Enqueue((Time.fixedTime, ((Component)val.playerAvatar).transform.position, ((Component)val).transform.forward));
				while (_puller.Count > 40)
				{
					_puller.Dequeue();
				}
			}
		}

		internal void OnCorrected(Vector3 step)
		{
			//IL_0021: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			if (_hasLeft && ((Vector3)(ref _left)).sqrMagnitude > 0.0001f)
			{
				_corrected += Vector3.Dot(Flat(step), ((Vector3)(ref _left)).normalized);
			}
		}

		private void OnPushed(Collider other, float speed)
		{
			string key = Label(other);
			_pushes[key] = (_pushes.TryGetValue(key, out var value) ? (value + speed) : speed);
		}

		private string Label(Collider other)
		{
			if (!_labels.TryGetValue(other, out (string, PhysGrabObject, PlayerAvatar) value))
			{
				Rigidbody attachedRigidbody = other.attachedRigidbody;
				PlayerController instance = PlayerController.instance;
				PlayerTumble componentInParent = ((Component)other).GetComponentInParent<PlayerTumble>();
				PlayerAvatar val = (Object.op_Implicit((Object)(object)componentInParent) ? null : ((Component)other).GetComponentInParent<PlayerAvatar>());
				string text = ((Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)attachedRigidbody) && (Object)(object)attachedRigidbody == (Object)(object)instance.rb) ? "our body" : (Object.op_Implicit((Object)(object)componentInParent) ? ((Object.op_Implicit((Object)(object)componentInParent.playerAvatar) ? componentInParent.playerAvatar.playerName : "?") + "'s tumbling body") : ((!Object.op_Implicit((Object)(object)val)) ? (Object.op_Implicit((Object)(object)attachedRigidbody) ? ((Object)attachedRigidbody).name : ((Object)other).name).Replace("(Clone)", "") : (val.playerName + "'s avatar (" + ((Object)other).name + ")"))));
				value = (text + " [" + LayerMask.LayerToName(((Component)other).gameObject.layer) + "]", ((Component)other).GetComponentInParent<PhysGrabObject>(), val);
				_labels[other] = value;
			}
			if (Prediction.StateOf(value.Item2) == PredictionState.Riding)
			{
				return value.Item1 + " (riding)";
			}
			if (!StandsOnThis(value.Item3))
			{
				return value.Item1;
			}
			return value.Item1 + " (standing on this cart)";
		}

		private bool StandsOnThis(PlayerAvatar avatar)
		{
			if (Object.op_Implicit((Object)(object)avatar) && !avatar.isLocal && !avatar.isTumbling && avatar.clientPhysRiding)
			{
				return (Object)(object)avatar.clientPhysRidingObject == (Object)(object)_cart.physGrabObject;
			}
			return false;
		}

		private string StandingPlayers()
		{
			List<PlayerAvatar> list = (Object.op_Implicit((Object)(object)GameDirector.instance) ? GameDirector.instance.PlayerList : null);
			if (list == null)
			{
				return "";
			}
			string text = null;
			foreach (PlayerAvatar item in list)
			{
				if (StandsOnThis(item))
				{
					text = ((text == null) ? "" : (text + ", ")) + item.playerName;
				}
			}
			if (text != null)
			{
				return ", players standing on it: " + text;
			}
			return "";
		}

		internal string Describe(PhysGrabObjectGrabArea handle, CartModeKind predicted, in BodyState host, double hostTime, double hostDelay)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected I4, but got Unknown
			//IL_00f1: 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_012b: Unknown result type (might be due to invalid IL or missing references)
			string text = string.Format(", {0} the ground (off {1} of {2} steps, {3} switches)", OffTheGround ? "off" : "on", _offSteps, _groundSteps, _groundSwitches) + $", mode {(CartModeKind)_cart.currentState} (ours {predicted}), wheels " + ((_cart.capsuleColliders.Count > 0 && Object.op_Implicit((Object)(object)_cart.capsuleColliders[0]) && Object.op_Implicit((Object)(object)_cart.capsuleColliders[0].sharedMaterial)) ? ((Object)_cart.capsuleColliders[0].sharedMaterial).name : "?");
			text += StandingPlayers();
			text += Velocities(host.Velocity);
			text += Beam(in host, hostTime, hostDelay);
			text += Steer(handle);
			text += HostFollows(handle, host.Position, host.Velocity);
			if (_steps > 0)
			{
				text = text + $", steered {_steps} steps: left at {_leftAt / (float)_steps:F2} m/s, found at {_foundAt / (float)Math.Max(1, _steps - 1):F2} m/s next step " + $"(lost {_lost / (float)Math.Max(1, _steps - 1):F2} m/s a step, our corrections added {_corrected:F2} m/s in all)";
			}
			if (_pushes.Count > 0)
			{
				text = text + ", pushed by " + string.Join(", ", from p in _pushes.OrderByDescending((KeyValuePair<string, float> p) => p.Value).Take(4)
					select $"{p.Key} {p.Value:F2} m/s");
			}
			_steps = 0;
			_leftAt = (_foundAt = (_lost = (_corrected = 0f)));
			_hasLeft = false;
			_pushes.Clear();
			_groundSteps = (_offSteps = (_groundSwitches = 0));
			return text;
		}

		private string Velocities(Vector3 host)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_0024: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			Vector3 linearVelocity = _rb.linearVelocity;
			Vector3 val = Flat(host);
			string text = $", velocity host {((Vector3)(ref val)).magnitude:F2} m/s horizontal {host.y:+0.00;-0.00} vertical, ";
			val = Flat(linearVelocity);
			return text + $"ours now {((Vector3)(ref val)).magnitude:F2} horizontal {linearVelocity.y:+0.00;-0.00} vertical";
		}

		private string Beam(in BodyState host, double hostTime, double hostDelay)
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			if (_beam.Count == 0)
			{
				return "";
			}
			double num = hostTime - hostDelay;
			BeamSample beamSample = default(BeamSample);
			BeamSample beamSample2 = default(BeamSample);
			double num2 = double.MaxValue;
			foreach (BeamSample item in _beam)
			{
				beamSample2 = item;
				double num3 = Math.Abs(item.Time - num);
				if (num3 < num2)
				{
					num2 = num3;
					beamSample = item;
				}
			}
			if (num2 > 0.05)
			{
				return $", beam: stretched {beamSample2.Stretch:F2} m now (no pull of ours from when the host simulated this)";
			}
			Vector3 val = beamSample.Puller - (host.Position + host.Rotation * beamSample.LocalGrabPoint);
			string text = $", beam: stretched {beamSample.Stretch:F2} m here then, the host's {((Vector3)(ref val)).magnitude:F2} m ";
			Vector3 val2 = Flat(val);
			return text + $"({((Vector3)(ref val2)).magnitude:F2} horizontal {val.y:+0.00;-0.00} vertical), {beamSample2.Stretch:F2} m here now";
		}

		private string Steer(PhysGrabObjectGrabArea handle)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: 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)
			if (!Object.op_Implicit((Object)(object)handle) || handle.listOfAllGrabbers.Count == 0 || !Object.op_Implicit((Object)(object)handle.listOfAllGrabbers[0]))
			{
				return "";
			}
			PhysGrabber val = handle.listOfAllGrabbers[0];
			PlayerAvatar playerAvatar = val.playerAvatar;
			if (!Object.op_Implicit((Object)(object)playerAvatar))
			{
				return "";
			}
			bool flag = Vector3.Dot((val.isLocal && Object.op_Implicit((Object)(object)PlayerController.instance)) ? PlayerController.instance.rb.linearVelocity : playerAvatar.rbVelocityRaw, _rb.rotation * Vector3.forward) > 0f;
			float num = (_cart.isSmallCart ? 1.5f : 2f);
			float num2 = (_cart.isSmallCart ? 2f : 2.5f);
			float num3 = (playerAvatar.isSprinting ? 7f : 5f);
			if (playerAvatar.isSprinting && flag)
			{
				num = 3f;
				num2 = 4f;
			}
			float num4 = Mathf.Clamp(Vector3.Dot(_rb.linearVelocity, ((Component)val).transform.forward) / num3, 0f, 1f);
			float num5 = Mathf.Lerp(num, num2, num4);
			string text = $", steer: sprinting {playerAvatar.isSprinting}, forward {flag}, follow distance {num5:F2} m, ";
			Vector3 val2 = Flat(_rb.position - ((Component)playerAvatar).transform.position);
			return text + $"cart {((Vector3)(ref val2)).magnitude:F2} m from the puller";
		}

		private string HostFollows(PhysGrabObjectGrabArea handle, Vector3 hostPosition, Vector3 hostVelocity)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: 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_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: 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_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			if (_puller.Count == 0 || !Object.op_Implicit((Object)(object)handle) || handle.listOfAllGrabbers.Count == 0 || !Object.op_Implicit((Object)(object)handle.listOfAllGrabbers[0]) || !Object.op_Implicit((Object)(object)handle.listOfAllGrabbers[0].playerAvatar))
			{
				return "";
			}
			bool isSprinting = handle.listOfAllGrabbers[0].playerAvatar.isSprinting;
			float fixedTime = Time.fixedTime;
			float item = _puller.Peek().Time;
			float num = fixedTime;
			float num2 = float.MaxValue;
			Vector3 val = default(Vector3);
			Vector3 val3;
			foreach (var item5 in _puller)
			{
				float item2 = item5.Time;
				Vector3 item3 = item5.Position;
				Vector3 item4 = item5.Forward;
				Vector3 val2 = item3 + item4 * FollowDistance(hostVelocity, item4, isSprinting);
				val3 = Flat(hostPosition - val2);
				float magnitude = ((Vector3)(ref val3)).magnitude;
				if (magnitude < num2)
				{
					num2 = magnitude;
					num = item2;
				}
				val = item3 + item4 * FollowDistance(_rb.linearVelocity, item4, isSprinting);
			}
			string arg = ((_puller.Count >= 40 && num <= item) ? "0.8 s or more" : $"{(fixedTime - num) * 1000f:F0} ms");
			string text = $", host's cart steers by where we were {arg} ago ({num2:F2} m from that point; ";
			val3 = Flat(_rb.position - val);
			object arg2 = ((Vector3)(ref val3)).magnitude;
			val3 = Flat(hostVelocity);
			return text + $"ours {arg2:F2} m from its point now, host speed {((Vector3)(ref val3)).magnitude:F2} m/s)";
		}

		private float FollowDistance(Vector3 velocity, Vector3 forward, bool sprinting)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			float num = (_cart.isSmallCart ? 1.5f : 2f);
			float num2 = (_cart.isSmallCart ? 2f : 2.5f);
			if (sprinting)
			{
				num = 3f;
				num2 = 4f;
			}
			return Mathf.Lerp(num, num2, Mathf.Clamp01(Vector3.Dot(velocity, forward) / (sprinting ? 7f : 5f)));
		}
	}
	[HarmonyPatch]
	internal static class CartSteerDebugPatches
	{
		private static CartSteerDebug For(PhysGrabCart cart)
		{
			if (!Object.op_Implicit((Object)(object)cart) || !Prediction.IsPredicting(cart.physGrabObject))
			{
				return null;
			}
			return Prediction.Get(cart.physGrabObject)?.CartDebug;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PhysGrabCart), "CartSteer")]
		private static void CartSteer_Prefix(PhysGrabCart __instance)
		{
			try
			{
				For(__instance)?.BeforeSteer();
			}
			catch (Exception exception)
			{
				ZeroPingPhysicsFeature.Instance?.ReportError("CartSteerDebug.Before", exception);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PhysGrabCart), "CartSteer")]
		private static void CartSteer_Postfix(PhysGrabCart __instance)
		{
			try
			{
				For(__instance)?.AfterSteer();
			}
			catch (Exception exception)
			{
				ZeroPingPhysicsFeature.Instance?.ReportError("CartSteerDebug.After", exception);
			}
		}
	}
	internal sealed class CartTurret
	{
		private readonly ItemCartCannonMain _main;

		private readonly PhysGrabObject _object;

		private readonly Rigidbody _rb;

		private readonly PhysGrabObjectGrabArea _area;

		private PhysGrabCart _cart;

		private BoxCollider _cartBox;

		private Quaternion _correctorLocal;

		internal PhysGrabObjectGrabArea Handle => _area;

		private bool Switched => (int)_main.stateCurrent > 0;

		private Quaternion CartRotation
		{
			get
			{
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)_cart.rb))
				{
					return ((Component)_cart).transform.rotation;
				}
				return _cart.rb.rotation;
			}
		}

		private CartTurret(ItemCartCannonMain main, PhysGrabObject o)
		{
			_main = main;
			_object = o;
			_rb = o.rb;
			_area = ((Component)main).GetComponent<PhysGrabObjectGrabArea>();
		}

		internal static CartTurret For(PhysGrabObject o)
		{
			ItemCartCannonMain component = ((Component)o).GetComponent<ItemCartCannonMain>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				return null;
			}
			return new CartTurret(component, o);
		}

		internal void Step()
		{
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: 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_011f: 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_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: 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_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: 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_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			if (!Switched || !Object.op_Implicit((Object)(object)_area) || !FindCart())
			{
				return;
			}
			List<PhysGrabber> playerGrabbing = _object.playerGrabbing;
			bool flag = false;
			foreach (PhysGrabber item in playerGrabbing)
			{
				if (Object.op_Implicit((Object)(object)item) && item.isRotating)
				{
					flag = true;
					break;
				}
			}
			bool flag2 = playerGrabbing.Count > 0 && Object.op_Implicit((Object)(object)playerGrabbing[0]) && _area.listOfAllGrabbers.Count > 0;
			Quaternion cartRotation = CartRotation;
			Vector3 zero = Vector3.zero;
			if (flag2)
			{
				PlayerAvatar playerAvatar = playerGrabbing[0].playerAvatar;
				Transform val = ((Object.op_Implicit((Object)(object)playerAvatar) && Object.op_Implicit((Object)(object)playerAvatar.localCamera)) ? playerAvatar.localCamera.GetOverrideTransform() : null);
				if (!Object.op_Implicit((Object)(object)val))
				{
					return;
				}
				Quaternion rotation = val.rotation;
				Quaternion val2 = Quaternion.Euler(0f, ((Quaternion)(ref rotation)).eulerAngles.y, 0f);
				_correctorLocal = Quaternion.Inverse(cartRotation) * val2;
				Vector3 val3 = val.position + val.rotation * Vector3.forward * 0.5f;
				((Vector3)(ref zero))..ctor(val3.x, _rb.position.y, val3.z);
				if (!flag)
				{
					_object.OverrideTorqueStrength(0f, 0.1f);
				}
				_object.OverrideGrabStrength(0f, 0.1f);
				_object.OverrideMass(2f, 0.1f);
				_rb.AddForce(Vector3.down * 2f, (ForceMode)0);
			}
			if (!flag)
			{
				Quaternion val4 = cartRotation * _correctorLocal;
				float num = (flag2 ? 0.8f : 0.5f) * Quaternion.Angle(val4, _rb.rotation);
				_object.OverrideAngularDrag(5f, 0.1f);
				num = Mathf.Min(num, 12f);
				_rb.AddTorque(FollowRotation(val4, num * 0.1f), (ForceMode)1);
			}
			if (flag2)
			{
				_rb.AddForce(SemiFunc.PhysFollowPosition(_rb.position, zero, _rb.linearVelocity, 5f) * 0.1f, (ForceMode)1);
			}
		}

		private bool FindCart()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//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_00b6: Unknown result type (might be due to invalid IL or missing references)
			Vector3 worldCenterOfMass = _rb.worldCenterOfMass;
			if (Object.op_Implicit((Object)(object)_cart) && Object.op_Implicit((Object)(object)_cartBox))
			{
				Vector3 val = ((Collider)_cartBox).ClosestPoint(worldCenterOfMass) - worldCenterOfMass;
				if (((Vector3)(ref val)).sqrMagnitude <= 0.0225f)
				{
					return true;
				}
			}
			PhysGrabCart val2 = CartCargo.CartAt(worldCenterOfMass);
			BoxCollider val3 = ((Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val2.inCart)) ? ((Component)val2.inCart).GetComponent<BoxCollider>() : null);
			if (!Object.op_Implicit((Object)(object)val3))
			{
				_cart = null;
				return false;
			}
			if ((Object)(object)val2 != (Object)(object)_cart)
			{
				_cart = val2;
				_correctorLocal = Quaternion.Inverse(CartRotation) * _rb.rotation;
			}
			_cartBox = val3;
			return true;
		}

		internal string Describe(Quaternion hostRotation)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0068: 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_00ac: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			if (!Switched)
			{
				return $", turret: {_main.stateCurrent} (not steered)";
			}
			if (!Object.op_Implicit((Object)(object)_cart))
			{
				return $", turret: {_main.stateCurrent}, no cart found here (not steered)";
			}
			Quaternion val = CartRotation * _correctorLocal;
			return $", turret: {_main.stateCurrent} in {((Object)_cart).name}, handle grabbers {(Object.op_Implicit((Object)(object)_area) ? _area.listOfAllGrabbers.Count : (-1))}, " + $"aim {Quaternion.Angle(val, _rb.rotation):F0} deg from ours, {Quaternion.Angle(val, hostRotation):F0} deg from the host's";
		}

		private Vector3 FollowRotation(Quaternion target, float maxSpeed)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_007e: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a6: Unknown result type (might be due to invalid IL or missing references)
			Quaternion rotation = _rb.rotation;
			Quaternion val = target * Quaternion.Inverse(rotation);
			float num = default(float);
			Vector3 val2 = default(Vector3);
			((Quaternion)(ref val)).ToAngleAxis(ref num, ref val2);
			((Vector3)(ref val2)).Normalize();
			Vector3 val3 = val2 * num * (MathF.PI / 180f) / Time.fixedDeltaTime - _rb.angularVelocity;
			Vector3 val4 = _rb.inertiaTensorRotation * (Quaternion.Inverse(rotation) * val3);
			((Vector3)(ref val4)).Scale(_rb.inertiaTensor);
			return Vector3.ClampMagnitude(rotation * (Quaternion.Inverse(_rb.inertiaTensorRotation) * val4), maxSpeed);
		}
	}
	[HarmonyPatch]
	internal static class EffectPatches
	{
		private static bool Active => Prediction.Active;

		private static void Report(string site, Exception e)
		{
			ZeroPingPhysicsFeature.Instance?.ReportError(site, e);
		}

		private static bool Predicted(PhysGrabObject o, PhysGrabObject source)
		{
			if (Object.op_Implicit((Object)(object)o) && (Object)(object)o != (Object)(object)source)
			{
				return Prediction.IsPredicting(o);
			}
			return false;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ItemOrbZeroGravity), "Update")]
		private static void OrbZeroGravity(ItemOrbZeroGravity __instance)
		{
			if (!Active)
			{
				return;
			}
			try
			{
				ItemOrb itemOrb = __instance.itemOrb;
				if (!Object.op_Implicit((Object)(object)itemOrb) || !itemOrb.itemActive)
				{
					return;
				}
				foreach (PhysGrabObject item in itemOrb.objectAffected)
				{
					if (Predicted(item, __instance.physGrabObject))
					{
						item.OverrideDrag(0.5f, 0.1f);
						item.OverrideAngularDrag(0.5f, 0.1f);
						item.OverrideZeroGravity(0.1f);
					}
				}
			}
			catch (Exception e)
			{
				Report("OrbZeroGravity", e);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ItemOrbFeather), "Update")]
		private static void OrbFeather(ItemOrbFeather __instance)
		{
			if (!Active)
			{
				return;
			}
			try
			{
				ItemOrb itemOrb = __instance.itemOrb;
				if (!Object.op_Implicit((Object)(object)itemOrb) || !itemOrb.itemActive)
				{
					return;
				}
				foreach (PhysGrabObject item in itemOrb.objectAffected)
				{
					if (Predicted(item, __instance.physGrabObject))
					{
						ApplyFeather(item, 0.05f);
					}
				}
			}
			catch (Exception e)
			{
				Report("OrbFeather", e);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ItemOrbMagnet), "FixedUpdate")]
		private static void OrbMagnet(ItemOrbMagnet __instance)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			if (!Active)
			{
				return;
			}
			try
			{
				ItemOrb itemOrb = __instance.itemOrb;
				PhysGrabObject physGrabObject = __instance.physGrabObject;
				if (!Object.op_Implicit((Object)(object)itemOrb) || !itemOrb.itemActive || !Object.op_Implicit((Object)(object)physGrabObject))
				{
					return;
				}
				foreach (PhysGrabObject item in itemOrb.objectAffected)
				{
					if (Predicted(item, physGrabObject))
					{
						Vector3 val = ((Component)physGrabObject).transform.position - ((Component)item).transform.position;
						if (((Vector3)(ref val)).magnitude > 0.45f)
						{
							item.rb.AddForce(((Vector3)(ref val)).normalized * Mathf.Clamp(item.rb.mass * 10f, 0.2f, 5f));
						}
						item.rb.linearVelocity = physGrabObject.rb.linearVelocity;
						item.OverrideZeroGravity(0.1f);
					}
				}
			}
			catch (Exception e)
			{
				Report("OrbMagnet", e);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ItemDrone), "Update")]
		private static void DroneSelf(ItemDrone __instance)
		{
			if (!Active)
			{
				return;
			}
			try
			{
				PhysGrabObject physGrabObject = __instance.physGrabObject;
				if (__instance.itemActivated && (!Object.op_Implicit((Object)(object)__instance.itemEquippable) || !__instance.itemEquippable.isEquipped) && Predicted(physGrabObject, null))
				{
					physGrabObject.OverrideZeroGravity(0.1f);
					physGrabObject.OverrideDrag(1f, 0.1f);
					physGrabObject.OverrideAngularDrag(10f, 0.1f);
				}
			}
			catch (Exception e)
			{
				Report("DroneSelf", e);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ItemDroneZeroGravity), "Update")]
		private static void DroneZeroGravity(ItemDroneZeroGravity __instance)
		{
			if (!Active)
			{
				return;
			}
			try
			{
				PhysGrabObject val = MagnetTarget(__instance.itemDrone, __instance.itemEquippable);
				if (Predicted(val, __instance.myPhysGrabObject))
				{
					val.OverrideDrag(0.1f, 0.1f);
					val.OverrideAngularDrag(0.1f, 0.1f);
					val.OverrideZeroGravity(0.1f);
				}
			}
			catch (Exception e)
			{
				Report("DroneZeroGravity", e);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ItemDroneFeather), "FixedUpdate")]
		private static void DroneFeather(ItemDroneFeather __instance)
		{
			if (!Active)
			{
				return;
			}
			try
			{
				PhysGrabObject o = MagnetTarget(__instance.itemDrone, __instance.itemEquippable);
				if (Predicted(o, __instance.myPhysGrabObject))
				{
					ApplyFeather(o, 0.5f);
				}
			}
			catch (Exception e)
			{
				Report("DroneFeather", e);
			}
		}

		private static PhysGrabObject MagnetTarget(ItemDrone drone, ItemEquippable equippable)
		{
			if (!Object.op_Implicit((Object)(object)drone) || !drone.itemActivated || !drone.magnetActive || (Object.op_Implicit((Object)(object)equippable) && equippable.isEquipped))
			{
				return null;
			}
			return drone.magnetTargetPhysGrabObject;
		}

		private static void ApplyFeather(PhysGrabObject o, float playerMass)
		{
			PlayerTumble val = (o.isPlayer ? ((Component)o).GetComponent<PlayerTumble>() : null);
			if (Object.op_Implicit((Object)(object)val))
			{
				val.DisableCustomGravity(0.1f);
				o.OverrideMass(playerMass, 0.1f);
			}
			else
			{
				o.OverrideMass(1f, 0.1f);
				o.OverrideDrag(1f, 0.1f);
				o.OverrideAngularDrag(5f, 0.1f);
			}
		}
	}
	internal sealed class GunRole
	{
		internal readonly ItemGun Gun;

		private readonly ItemGunRevolver _revolver;

		private readonly GunTrigger _trigger = new GunTrigger();

		private GunRole(ItemGun gun)
		{
			Gun = gun;
			_revolver = gun.itemGunRevolver;
		}

		internal static GunRole For(PhysGrabObject o)
		{
			ItemGun component = ((Component)o).GetComponent<ItemGun>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				return null;
			}
			return new GunRole(component);
		}

		internal bool Click(PhysGrabObject o, double now)
		{
			//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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			ItemBattery itemBattery = Gun.itemBattery;
			if (!Object.op_Implicit((Object)(object)itemBattery) || !Object.op_Implicit((Object)(object)o.rb) || !Object.op_Implicit((Object)(object)Gun.gunMuzzle))
			{
				return false;
			}
			if (!_trigger.Click(now, State(o, itemBattery.batteryLifeInt)))
			{
				return false;
			}
			o.rb.AddForceAtPosition(-Gun.gunMuzzle.forward * Gun.gunRecoilForce, Gun.gunMuzzle.position, (ForceMode)1);
			return true;
		}

		internal void OnHostAnswer()
		{
			_trigger.OnHostAnswer();
		}

		private GunState State(PhysGrabObject o, int rounds)
		{
			//IL_004d: 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_0031: Invalid comparison between Unknown and I4
			//IL_00b3: Expected I4, but got Unknown
			bool isKinematic = o.rb.isKinematic;
			if (!Object.op_Implicit((Object)(object)_revolver))
			{
				return GunState.Gun(isKinematic, Gun.hasOneShot, (int)Gun.stateCurrent == 0, rounds);
			}
			ItemEquippable itemEquippable = _revolver.itemEquippable;
			return GunState.Revolving(isKinematic, new RevolverTrigger((RevolverPhase)_revolver.currentState, _revolver.chamberAngle, _revolver.chamberSpeed, _revolver.loadedChambers, _revolver.alignmentTolerance, _revolver.settlingSpeed, rounds, _revolver.shootCooldownTimer, (Object.op_Implicit((Object)(object)itemEquippable) && itemEquippable.isEquipped) || o.dead));
		}

		internal string Describe(PhysGrabObject o, Rigidbody rb, PhotonTransformView view, PhysGrabber holder)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: 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_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (!Object.op_Implicit((Object)(object)Gun.gunMuzzle))
			{
				return "";
			}
			ItemBattery itemBattery = Gun.itemBattery;
			string text = $", gun: state {Gun.stateCurrent}, charge {(Object.op_Implicit((Object)(object)itemBattery) ? itemBattery.batteryLifeInt : (-1))}, torque override " + $"{o.overrideTorqueStrength:F2} for {o.overrideTorqueStrengthTimer:F2} s";
			if (Object.op_Implicit((Object)(object)_revolver))
			{
				text += $", revolver {_revolver.currentState}, rounds {CountBits(_revolver.loadedChambers)}";
			}
			if (!Object.op_Implicit((Object)(object)holder) || !Object.op_Implicit((Object)(object)holder.playerAvatar) || !Object.op_Implicit((Object)(object)holder.playerAvatar.localCamera))
			{
				return text;
			}
			Transform overrideTransform = holder.playerAvatar.localCamera.GetOverrideTransform();
			Vector3 val = holder.physGrabPointPullerPosition - overrideTransform.position;
			if (((Vector3)(ref val)).sqrMagnitude < 0.0001f)
			{
				val = overrideTransform.forward;
			}
			Vector3 val2 = Quaternion.Inverse(((Component)o).transform.rotation) * Gun.gunMuzzle.forward;
			return text + $", muzzle {Vector3.Angle(rb.rotation * val2, val):F0} deg off our aim here, " + string.Format("{0:F0} deg on the host{1}", Vector3.Angle(view.receivedRotation * val2, val), holder.isRotating ? " (rotating it by hand)" : "");
		}

		private static int CountBits(int bits)
		{
			int num = 0;
			while (bits != 0)
			{
				num++;
				bits &= bits - 1;
			}
			return num;
		}
	}
	[HarmonyPatch]
	internal static class GunShots
	{
		private sealed class Shot
		{
			internal ItemToggle Toggle;

			internal bool State;

			internal int Player;

			internal ItemGun Gun;

			internal double Hold;

			internal AimTrack Track;

			internal double ClickServerTime;

			internal Vector3 MuzzleOffset;

			internal Vector3 MuzzleForwardLocal;

			internal Vector3 MuzzlePosition;

			internal Vector3 MuzzleForward;

			internal Vector3 ForwardWithoutHold;

			internal bool HasForwardWithoutHold;

			internal float SentAt;

			internal bool Measured;
		}

		private const float ShotMatchAngle = 2f;

		private static readonly ShotTimer<Shot> Timer = new ShotTimer<Shot>();

		private static Shot _lastSent;

		internal static AimLagMeter Lag => Timer.Lag;

		private static bool Enabled
		{
			get
			{
				if (ZeroPingPhysicsFeature.ShouldPredict)
				{
					return ZeroPingPhysicsFeature.TimeGunShots.Value;
				}
				return false;
			}
		}

		private static void Report(string site, Exception e)
		{
			ZeroPingPhysicsFeature.Instance?.ReportError(site, e);
		}

		internal static void