Decompiled source of NetworkSync v0.1.21

NetworkSync.dll

Decompiled 31 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using NetworkSync.Authority;
using NetworkSync.Core;
using NetworkSync.Diag;
using NetworkSync.Net;
using NetworkSync.Patches;
using NetworkSync.Prediction;
using NetworkSync.Smoothing;
using NetworkSync.Sync;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("NetworkSync")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.21.0")]
[assembly: AssemblyInformationalVersion("0.1.21")]
[assembly: AssemblyProduct("NetworkSync")]
[assembly: AssemblyTitle("NetworkSync")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.21.0")]
[module: UnverifiableCode]
namespace NetworkSync
{
	[BepInPlugin("networksync.repo", "NetworkSync", "0.1.21")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "networksync.repo";

		public const string Name = "NetworkSync";

		public const string Version = "0.1.21";

		internal static ManualLogSource Log;

		internal static Harmony Harmony;

		private void Awake()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Cfg.Bind(((BaseUnityPlugin)this).Config);
			BindModuleConfigs();
			DropOldConfigEntries();
			Harmony = new Harmony("networksync.repo");
			ApplyPatches();
			Log.LogInfo((object)string.Format("{0} {1} loaded (protocol {2}). Waiting for Photon.", "NetworkSync", "0.1.21", 3));
			CheckEarlyPhoton();
		}

		private static void CheckEarlyPhoton()
		{
			try
			{
				Bootstrap.HandlerExistedAtLoad = (Object)(object)Object.FindFirstObjectByType<PhotonHandler>() != (Object)null;
				if (Bootstrap.HandlerExistedAtLoad)
				{
					Log.LogWarning((object)"Photon was already started by another mod while it loaded - NetworkSync will hook in on the first Photon frame instead.");
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Early Photon check failed (harmless): " + ex.Message));
			}
		}

		private void BindModuleConfigs()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			foreach (Type type in types)
			{
				if (type == typeof(Cfg) || !type.Name.EndsWith("Cfg", StringComparison.Ordinal))
				{
					continue;
				}
				MethodInfo method = type.GetMethod("Bind", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(ConfigFile) }, null);
				if (!(method == null))
				{
					try
					{
						method.Invoke(null, new object[1] { ((BaseUnityPlugin)this).Config });
					}
					catch (Exception ex)
					{
						Log.LogError((object)("Config " + type.Name + " failed: " + (ex.InnerException?.Message ?? ex.Message)));
					}
				}
			}
		}

		private void DropOldConfigEntries()
		{
			try
			{
				if (!(AccessTools.Property(typeof(ConfigFile), "OrphanedEntries")?.GetValue(((BaseUnityPlugin)this).Config) is IDictionary { Count: not 0 } dictionary))
				{
					return;
				}
				int num = 0;
				foreach (DictionaryEntry item in dictionary)
				{
					object key = item.Key;
					ConfigDefinition val = (ConfigDefinition)((key is ConfigDefinition) ? key : null);
					if (val == null || !(item.Value is string serializedValue))
					{
						continue;
					}
					ConfigDefinition val2 = MapOldSetting(val.Section, val.Key);
					if (!(val2 == (ConfigDefinition)null) && ((BaseUnityPlugin)this).Config.ContainsKey(val2))
					{
						try
						{
							((BaseUnityPlugin)this).Config[val2].SetSerializedValue(serializedValue);
							num++;
						}
						catch (Exception ex)
						{
							Log.LogWarning((object)("Old setting [" + val.Section + "] " + val.Key + " not carried over: " + ex.Message));
						}
					}
				}
				dictionary.Clear();
				((BaseUnityPlugin)this).Config.Save();
				if (num > 0)
				{
					Log.LogInfo((object)$"Config: carried {num} setting(s) over to the new layout.");
				}
			}
			catch (Exception ex2)
			{
				Log.LogWarning((object)("Could not clean old config entries: " + ex2.Message));
			}
		}

		private static ConfigDefinition MapOldSetting(string section, string key)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			switch (section)
			{
			case "1. Carts":
				if (!(key == "Cart Authority (Experimental)"))
				{
					return null;
				}
				return new ConfigDefinition("1. Experimental", key);
			case "2. Main":
				return null;
			case "1. Main":
				if (!(key == "Cart Authority"))
				{
					return new ConfigDefinition("2. Main", key);
				}
				return null;
			case "2. Network":
				return new ConfigDefinition("5. Network (Advanced)", key);
			case "3. Debug":
				return new ConfigDefinition("4. Debug", (key == "Overlay") ? "Show Overlay On Start" : key);
			case "4. Smoothing":
				return new ConfigDefinition("3. Smoothing", key);
			default:
				return null;
			}
		}

		private static void ApplyPatches()
		{
			int num = 0;
			int num2 = 0;
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			foreach (Type type in types)
			{
				if (type.GetCustomAttributes(typeof(HarmonyPatch), inherit: false).Length != 0)
				{
					try
					{
						Harmony.CreateClassProcessor(type).Patch();
						num++;
					}
					catch (Exception ex)
					{
						num2++;
						Log.LogError((object)("Patch " + type.Name + " failed (that feature is off): " + ex.Message));
					}
				}
			}
			Log.LogInfo((object)$"Patches applied: {num} ok, {num2} failed.");
		}
	}
	[HarmonyPatch(typeof(PhotonHandler), "Awake")]
	internal static class Bootstrap
	{
		public enum BootState
		{
			NotStarted,
			Hooked,
			HookedLate,
			Failed
		}

		internal static bool HandlerExistedAtLoad;

		private const int MaxAttempts = 4;

		private const float LateRetrySeconds = 2f;

		private static float nextLateTry;

		public static bool PhotonReady { get; private set; }

		public static BootState State { get; private set; } = BootState.NotStarted;

		public static float StateSince { get; private set; } = -1f;

		public static int Attempts { get; private set; }

		public static string LastError { get; private set; }

		public static string StatusText
		{
			get
			{
				string text = ((StateSince >= 0f) ? $" at {StateSince:0.0}s" : "");
				switch (State)
				{
				case BootState.Hooked:
					return "hooked" + text;
				case BootState.HookedLate:
					return "hooked late (Photon was started early by another mod)" + text;
				case BootState.Failed:
					return string.Format("FAILED after {0} tries: {1}", Attempts, LastError ?? "?");
				default:
					if (Attempts <= 0)
					{
						return "not started (waiting for Photon)";
					}
					return string.Format("not hooked yet ({0} tries, last error: {1})", Attempts, LastError ?? "?");
				}
			}
		}

		[HarmonyPostfix]
		private static void Postfix()
		{
			Run(late: false);
		}

		internal static void TryLate()
		{
			if (!PhotonReady && State != BootState.Failed)
			{
				float realtimeSinceStartup = Time.realtimeSinceStartup;
				if (!(realtimeSinceStartup < nextLateTry))
				{
					nextLateTry = realtimeSinceStartup + 2f;
					Run(late: true);
				}
			}
		}

		private static void Run(bool late)
		{
			if (PhotonReady || State == BootState.Failed)
			{
				return;
			}
			Attempts++;
			try
			{
				Conflicts.Check();
				Overlay.Init();
				Session.Init();
				Bus.Init();
				AuthorityCore.Init();
				CartGroups.Init();
				ImpactForward.Init();
				TumblePrediction.Init();
				PhotonReady = true;
				SetState((!late) ? BootState.Hooked : BootState.HookedLate);
				Runner.RaisePhotonReady();
				Plugin.Log.LogInfo((object)(late ? "Photon ready - NetworkSync networking hooked (late: Photon was already started by another mod while it loaded)." : "Photon ready - NetworkSync networking hooked."));
			}
			catch (Exception ex)
			{
				LastError = ex.GetType().Name + ": " + ex.Message;
				Safe.Report("bootstrap", ex);
				if (!PhotonReady && Attempts >= 4)
				{
					SetState(BootState.Failed);
					Plugin.Log.LogError((object)$"NetworkSync could not hook into Photon after {Attempts} tries - it stays inactive (vanilla game). Last error: {LastError}");
				}
			}
		}

		private static void SetState(BootState s)
		{
			State = s;
			StateSince = Time.realtimeSinceStartup;
		}
	}
	internal interface ISystem
	{
		string Area { get; }

		void Tick();

		void FixedTick();

		void LateTick();
	}
	[HarmonyPatch]
	internal static class Runner
	{
		private static readonly List<ISystem> Systems = new List<ISystem>();

		private static int lastFrame = -1;

		private static int lastLateFrame = -1;

		private static float lastFixed = -1f;

		public static event Action PhotonReady;

		internal static void RaisePhotonReady()
		{
			Runner.PhotonReady?.Invoke();
		}

		public static void Register(ISystem s)
		{
			if (s != null && !Systems.Contains(s))
			{
				Systems.Add(s);
			}
		}

		[HarmonyPatch(typeof(PhotonHandler), "FixedUpdate")]
		[HarmonyPostfix]
		private static void FixedPost()
		{
			if (!Bootstrap.PhotonReady)
			{
				Bootstrap.TryLate();
			}
			if (Time.fixedTime != lastFixed)
			{
				lastFixed = Time.fixedTime;
				for (int i = 0; i < Systems.Count; i++)
				{
					ISystem system = Systems[i];
					Safe.Run(system.Area, system.FixedTick);
				}
			}
		}

		[HarmonyPatch(typeof(PhotonHandler), "LateUpdate")]
		[HarmonyPrefix]
		private static void LatePre()
		{
			if (!Bootstrap.PhotonReady)
			{
				Bootstrap.TryLate();
			}
			if (Time.frameCount != lastFrame)
			{
				lastFrame = Time.frameCount;
				for (int i = 0; i < Systems.Count; i++)
				{
					ISystem system = Systems[i];
					Safe.Run(system.Area, system.Tick);
				}
			}
		}

		[HarmonyPatch(typeof(PhotonHandler), "LateUpdate")]
		[HarmonyPostfix]
		private static void LatePost()
		{
			if (Time.frameCount != lastLateFrame)
			{
				lastLateFrame = Time.frameCount;
				for (int i = 0; i < Systems.Count; i++)
				{
					ISystem system = Systems[i];
					Safe.Run(system.Area, system.LateTick);
				}
			}
		}
	}
}
namespace NetworkSync.Sync
{
	internal struct Snapshot
	{
		public double Time;

		public Vector3 Pos;

		public Quaternion Rot;

		public Vector3 Vel;

		public Vector3 AngVel;
	}
	internal sealed class SnapshotBuffer
	{
		private const int Capacity = 32;

		private const double MaxExtrapolation = 0.12;

		private readonly Snapshot[] ring = new Snapshot[32];

		private int count;

		private double lastArrival = -1.0;

		private double lastSendTime = -1.0;

		private double jitter;

		private double sendInterval = 1.0 / 30.0;

		private double transitFloor = double.NaN;

		public int Count => count;

		public double NewestTime
		{
			get
			{
				if (count <= 0)
				{
					return double.NegativeInfinity;
				}
				return ring[count - 1].Time;
			}
		}

		public double OldestTime
		{
			get
			{
				if (count <= 0)
				{
					return double.PositiveInfinity;
				}
				return ring[0].Time;
			}
		}

		public Snapshot Newest => ring[count - 1];

		public double TransitFloor
		{
			get
			{
				if (!double.IsNaN(transitFloor))
				{
					return transitFloor;
				}
				return 0.0;
			}
		}

		public void Clear()
		{
			count = 0;
			lastArrival = (lastSendTime = -1.0);
			jitter = 0.0;
			transitFloor = double.NaN;
		}

		public void Add(in Snapshot s, double arrivalTime)
		{
			double num = arrivalTime - s.Time;
			if (num > -1.0 && num < 1.0)
			{
				if (double.IsNaN(transitFloor) || num < transitFloor)
				{
					transitFloor = num;
				}
				else
				{
					transitFloor += (num - transitFloor) * 0.002;
				}
			}
			if (count > 0 && s.Time <= ring[count - 1].Time)
			{
				if (s.Time <= ring[0].Time)
				{
					return;
				}
				int num2 = count - 1;
				while (num2 > 0 && ring[num2 - 1].Time >= s.Time)
				{
					num2--;
				}
				if (ring[num2].Time == s.Time)
				{
					return;
				}
				if (count == 32)
				{
					Array.Copy(ring, 1, ring, 0, 31);
					count--;
					num2--;
					if (num2 < 0)
					{
						return;
					}
				}
				Array.Copy(ring, num2, ring, num2 + 1, count - num2);
				ring[num2] = s;
				count++;
				return;
			}
			if (lastArrival >= 0.0)
			{
				double num3 = s.Time - lastSendTime;
				double num4 = arrivalTime - lastArrival;
				if (num3 > 0.0 && num3 < 1.0)
				{
					sendInterval += (num3 - sendInterval) * 0.1;
					double num5 = Math.Abs(num4 - num3);
					jitter += (num5 - jitter) * 0.1;
				}
			}
			lastArrival = arrivalTime;
			lastSendTime = s.Time;
			if (count == 32)
			{
				Array.Copy(ring, 1, ring, 0, 31);
				count--;
			}
			ring[count++] = s;
		}

		public double RenderDelay(double min, double max)
		{
			double num = sendInterval * 1.5 + jitter * 2.5;
			num = ((num < min) ? min : ((num > max) ? max : num));
			return num + (double.IsNaN(transitFloor) ? 0.0 : transitFloor);
		}

		public double Cushion(double min, double max)
		{
			double num = sendInterval * 1.5 + jitter * 2.5;
			if (!(num < min))
			{
				if (!(num > max))
				{
					return num;
				}
				return max;
			}
			return min;
		}

		public bool Sample(double renderTime, out Vector3 pos, out Quaternion rot, out Vector3 vel)
		{
			Vector3 angVel;
			return Sample(renderTime, out pos, out rot, out vel, out angVel);
		}

		public bool Sample(double renderTime, out Vector3 pos, out Quaternion rot, out Vector3 vel, out Vector3 angVel)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_001c: 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_00b9: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: 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_0133: 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_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: 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_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			pos = default(Vector3);
			rot = Quaternion.identity;
			vel = default(Vector3);
			angVel = default(Vector3);
			if (count == 0)
			{
				return false;
			}
			if (renderTime <= ring[0].Time || count == 1)
			{
				Snapshot snapshot = ring[0];
				if (count == 1 && renderTime > snapshot.Time)
				{
					double num = Math.Min(renderTime - snapshot.Time, 0.12);
					pos = snapshot.Pos + snapshot.Vel * (float)num;
				}
				else
				{
					pos = snapshot.Pos;
				}
				rot = snapshot.Rot;
				vel = snapshot.Vel;
				angVel = snapshot.AngVel;
				return true;
			}
			Snapshot snapshot2 = ring[count - 1];
			if (renderTime >= snapshot2.Time)
			{
				double num2 = Math.Min(renderTime - snapshot2.Time, 0.12);
				pos = snapshot2.Pos + snapshot2.Vel * (float)num2;
				float num3 = ((Vector3)(ref snapshot2.AngVel)).magnitude * (float)num2 * 57.29578f;
				rot = ((num3 > 0.01f) ? (Quaternion.AngleAxis(num3, ((Vector3)(ref snapshot2.AngVel)).normalized) * snapshot2.Rot) : snapshot2.Rot);
				vel = snapshot2.Vel;
				angVel = snapshot2.AngVel;
				return true;
			}
			int i;
			for (i = 1; i < count && ring[i].Time < renderTime; i++)
			{
			}
			Snapshot snapshot3 = ring[i - 1];
			Snapshot snapshot4 = ring[i];
			double num4 = snapshot4.Time - snapshot3.Time;
			float num5 = ((num4 > 1E-06) ? ((float)((renderTime - snapshot3.Time) / num4)) : 1f);
			float num6 = (float)num4;
			float num7 = num5 * num5;
			float num8 = num7 * num5;
			float num9 = 2f * num8 - 3f * num7 + 1f;
			float num10 = num8 - 2f * num7 + num5;
			float num11 = -2f * num8 + 3f * num7;
			float num12 = num8 - num7;
			pos = num9 * snapshot3.Pos + num10 * num6 * snapshot3.Vel + num11 * snapshot4.Pos + num12 * num6 * snapshot4.Vel;
			Vector3 val = pos - Vector3.Lerp(snapshot3.Pos, snapshot4.Pos, num5);
			float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
			val = snapshot4.Pos - snapshot3.Pos;
			if (sqrMagnitude > ((Vector3)(ref val)).sqrMagnitude + 0.25f)
			{
				pos = Vector3.Lerp(snapshot3.Pos, snapshot4.Pos, num5);
			}
			rot = Quaternion.Slerp(snapshot3.Rot, snapshot4.Rot, num5);
			vel = Vector3.Lerp(snapshot3.Vel, snapshot4.Vel, num5);
			angVel = Vector3.Lerp(snapshot3.AngVel, snapshot4.AngVel, num5);
			return true;
		}

		public bool SampleHold(double renderTime, out Vector3 pos, out Quaternion rot, out Vector3 vel, out bool held)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: 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_00aa: 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_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: 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_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: 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_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: 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_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: 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_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: 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_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			pos = default(Vector3);
			rot = Quaternion.identity;
			vel = default(Vector3);
			held = false;
			if (count == 0)
			{
				return false;
			}
			if (renderTime <= ring[0].Time || count == 1)
			{
				Snapshot snapshot = ring[0];
				pos = snapshot.Pos;
				rot = snapshot.Rot;
				held = renderTime != snapshot.Time;
				return true;
			}
			Snapshot snapshot2 = ring[count - 1];
			if (renderTime >= snapshot2.Time)
			{
				pos = snapshot2.Pos;
				rot = snapshot2.Rot;
				held = renderTime > snapshot2.Time;
				return true;
			}
			int i;
			for (i = 1; i < count && ring[i].Time < renderTime; i++)
			{
			}
			Snapshot p = ring[i - 1];
			Snapshot q = ring[i];
			double num = q.Time - p.Time;
			if (num <= 1E-06)
			{
				pos = q.Pos;
				rot = q.Rot;
				return true;
			}
			float num2 = (float)((renderTime - p.Time) / num);
			float num3 = (float)num;
			Vector3 val = (q.Pos - p.Pos) / num3;
			Vector3 val2 = ((i >= 2) ? Slope(in ring[i - 2], in q, val) : val);
			Vector3 val3 = ((i + 1 < count) ? Slope(in p, in ring[i + 1], val) : val);
			float num4 = num2 * num2;
			float num5 = num4 * num2;
			float num6 = 2f * num5 - 3f * num4 + 1f;
			float num7 = num5 - 2f * num4 + num2;
			float num8 = -2f * num5 + 3f * num4;
			float num9 = num5 - num4;
			pos = num6 * p.Pos + num7 * num3 * val2 + num8 * q.Pos + num9 * num3 * val3;
			Vector3 val4 = Vector3.Lerp(p.Pos, q.Pos, num2);
			Vector3 val5 = pos - val4;
			float sqrMagnitude = ((Vector3)(ref val5)).sqrMagnitude;
			val5 = q.Pos - p.Pos;
			if (sqrMagnitude > ((Vector3)(ref val5)).sqrMagnitude * 0.0625f + 1E-08f)
			{
				pos = val4;
			}
			rot = Quaternion.Slerp(p.Rot, q.Rot, num2);
			vel = val;
			return true;
		}

		private static Vector3 Slope(in Snapshot p, in Snapshot q, Vector3 fallback)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			double num = q.Time - p.Time;
			if (!(num > 1E-06))
			{
				return fallback;
			}
			return (q.Pos - p.Pos) / (float)num;
		}
	}
}
namespace NetworkSync.Smoothing
{
	internal static class EnemySmoothing
	{
		private sealed class Body
		{
			public PhotonTransformView Ptv;

			public Rigidbody Rb;

			public readonly PoseBuffer Buf = new PoseBuffer(derivedVel: false, 5f);

			public int LastStamp;

			public bool HasStamp;
		}

		private sealed class Root
		{
			public Enemy Enemy;

			public readonly PoseBuffer Buf = new PoseBuffer(derivedVel: true, 5f);
		}

		[HarmonyPatch]
		private static class RootPatches
		{
			[HarmonyPatch(typeof(Enemy), "OnPhotonSerializeView")]
			[HarmonyPostfix]
			private static void EnemySerializePostfix(Enemy __instance, PhotonStream stream, PhotonMessageInfo info)
			{
				//IL_001b: 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_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)
				if (stream == null || stream.IsWriting || !Enabled)
				{
					return;
				}
				try
				{
					if (IsClient() && SemiFunc.MasterOnlyRPC(info))
					{
						int instanceID = ((Object)__instance).GetInstanceID();
						if (!Roots.TryGetValue(instanceID, out var value))
						{
							value = new Root
							{
								Enemy = __instance
							};
							Roots[instanceID] = value;
						}
						double sentServerTime = ((PhotonMessageInfo)(ref info)).SentServerTime;
						MasterClock.Observe(sentServerTime, SmoothTime.Now);
						value.Buf.Add(sentServerTime, __instance.PositionTarget, Quaternion.identity, Vector3.zero, Vector3.zero, MasterClock.Interval);
					}
				}
				catch (Exception e)
				{
					Safe.Report("smooth.enemies", e);
				}
			}

			[HarmonyPatch(typeof(Enemy), "Update")]
			[HarmonyPostfix]
			private static void EnemyUpdatePostfix(Enemy __instance)
			{
				//IL_0079: Unknown result type (might be due to invalid IL or missing references)
				if (Roots.Count == 0)
				{
					return;
				}
				if (!Enabled)
				{
					ResetAll();
					return;
				}
				try
				{
					if (!__instance.MasterClient && IsClient() && Roots.TryGetValue(((Object)__instance).GetInstanceID(), out var value) && value.Buf.Count != 0 && value.Buf.Sample(RenderTime(SmoothTime.Now), 0.12f, out var pos, out var _, out var _, out var _))
					{
						((Component)__instance).transform.position = pos;
					}
				}
				catch (Exception e)
				{
					Safe.Report("smooth.enemies", e);
				}
			}

			[HarmonyPatch(typeof(Enemy), "EnemyTeleportedRPC")]
			[HarmonyPostfix]
			private static void EnemyTeleportedPostfix(Enemy __instance, Vector3 teleportPosition, PhotonMessageInfo _info)
			{
				//IL_000e: 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_005c: Unknown result type (might be due to invalid IL or missing references)
				if (Roots.Count == 0)
				{
					return;
				}
				try
				{
					if (SemiFunc.MasterOnlyRPC(_info) && Roots.TryGetValue(((Object)__instance).GetInstanceID(), out var value))
					{
						double num = Math.Max(value.Buf.NewestTime, ((PhotonMessageInfo)(ref _info)).SentServerTime);
						if (double.IsInfinity(num))
						{
							num = ((PhotonMessageInfo)(ref _info)).SentServerTime;
						}
						value.Buf.Seed(num, teleportPosition, Quaternion.identity);
					}
				}
				catch (Exception e)
				{
					Safe.Report("smooth.enemies", e);
				}
			}
		}

		[HarmonyPatch]
		private static class BodyPatches
		{
			[HarmonyPatch(typeof(PhotonTransformView), "OnPhotonSerializeView")]
			[HarmonyPostfix]
			private static void PtvSerializePostfix(PhotonTransformView __instance, PhotonStream stream, PhotonMessageInfo info)
			{
				//IL_00a2: 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_00c2: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
				if (stream == null || stream.IsWriting || !Enabled)
				{
					return;
				}
				try
				{
					if (!IsClient() || !Refs())
					{
						return;
					}
					Body body = Lookup(__instance);
					if (body != null)
					{
						int sentServerTimestamp = ((PhotonMessageInfo)(ref info)).SentServerTimestamp;
						if (__instance.receivedServerTimestamp == sentServerTimestamp && (!body.HasStamp || body.LastStamp != sentServerTimestamp))
						{
							body.HasStamp = true;
							body.LastStamp = sentServerTimestamp;
							double sentServerTime = ((PhotonMessageInfo)(ref info)).SentServerTime;
							MasterClock.Observe(sentServerTime, SmoothTime.Now);
							bool flag = F_isSleeping.Invoke(__instance);
							body.Buf.Add(sentServerTime, F_netPos.Invoke(__instance), F_netRot.Invoke(__instance), flag ? Vector3.zero : __instance.receivedVelocity, flag ? Vector3.zero : __instance.receivedAngularVelocity, MasterClock.Interval);
						}
					}
				}
				catch (Exception e)
				{
					Safe.Report("smooth.enemies", e);
				}
			}

			[HarmonyPatch(typeof(PhotonTransformView), "Update")]
			[HarmonyPrefix]
			private static bool PtvUpdatePrefix(PhotonTransformView __instance)
			{
				if (Bodies.Count == 0 || !Enabled || !refsOk)
				{
					return true;
				}
				try
				{
					if (!IsClient())
					{
						return true;
					}
					Body body = Lookup(__instance);
					if (body == null || body.Buf.Count == 0)
					{
						return true;
					}
					Rigidbody val = (Object.op_Implicit((Object)(object)body.Rb) ? body.Rb : F_rb.Invoke(__instance));
					if (!Object.op_Implicit((Object)(object)val))
					{
						return true;
					}
					FrameTick(body, __instance, val);
					return false;
				}
				catch (Exception e)
				{
					Safe.Report("smooth.enemies", e);
					return true;
				}
			}

			[HarmonyPatch(typeof(EnemyRigidbody), "FixedUpdate")]
			[HarmonyPostfix]
			private static void BodyFixedPostfix(EnemyRigidbody __instance)
			{
				DriveBody(__instance);
			}
		}

		internal const string Area = "smooth.enemies";

		private const float MaxExtrap = 0.12f;

		private const float PosGain = 10f;

		private const float RotGain = 10f;

		private const float MaxCorrection = 20f;

		private const float SnapDistSq = 25f;

		private static readonly NetClock MasterClock = new NetClock();

		private static readonly Dictionary<int, Body> Bodies = new Dictionary<int, Body>();

		private static readonly HashSet<int> NotEnemy = new HashSet<int>();

		private static readonly Dictionary<int, Root> Roots = new Dictionary<int, Root>();

		private static readonly List<int> Scratch = new List<int>();

		private static bool refsTried;

		private static bool refsOk;

		private static FieldRef<PhotonTransformView, bool> F_teleport;

		private static FieldRef<PhotonTransformView, bool> F_isSleeping;

		private static FieldRef<PhotonTransformView, Vector3> F_netPos;

		private static FieldRef<PhotonTransformView, Vector3> F_smoothPos;

		private static FieldRef<PhotonTransformView, Quaternion> F_netRot;

		private static FieldRef<PhotonTransformView, Quaternion> F_smoothRot;

		private static FieldRef<PhotonTransformView, Rigidbody> F_rb;

		private static FieldRef<PhotonTransformView, float> F_throttleDisable;

		private static FieldRef<PhotonTransformView, float> F_overrideExtrap;

		private static FieldRef<PhotonTransformView, float> F_kinForced;

		private static int clientFrame = -1;

		private static bool clientCached;

		private static bool Enabled
		{
			get
			{
				if (SmoothCfg.Enemies != null && SmoothCfg.Enemies.Value)
				{
					return !SmoothCfg.EnemiesOff;
				}
				return false;
			}
		}

		private static bool IsClient()
		{
			int frameCount = Time.frameCount;
			if (frameCount != clientFrame)
			{
				clientFrame = frameCount;
				GameManager instance = GameManager.instance;
				clientCached = Object.op_Implicit((Object)(object)instance) && instance.gameMode == 1 && !PhotonNetwork.IsMasterClient;
			}
			return clientCached;
		}

		private static bool Refs()
		{
			if (refsTried)
			{
				return refsOk;
			}
			refsTried = true;
			try
			{
				F_teleport = AccessTools.FieldRefAccess<PhotonTransformView, bool>("teleport");
				F_isSleeping = AccessTools.FieldRefAccess<PhotonTransformView, bool>("isSleeping");
				F_netPos = AccessTools.FieldRefAccess<PhotonTransformView, Vector3>("m_NetworkPosition");
				F_smoothPos = AccessTools.FieldRefAccess<PhotonTransformView, Vector3>("smoothedPosition");
				F_netRot = AccessTools.FieldRefAccess<PhotonTransformView, Quaternion>("m_NetworkRotation");
				F_smoothRot = AccessTools.FieldRefAccess<PhotonTransformView, Quaternion>("smoothedRotation");
				F_rb = AccessTools.FieldRefAccess<PhotonTransformView, Rigidbody>("rb");
				F_throttleDisable = AccessTools.FieldRefAccess<PhotonTransformView, float>("throttleDisableTimer");
				F_overrideExtrap = AccessTools.FieldRefAccess<PhotonTransformView, float>("overrideExtrapolateTimer");
				F_kinForced = AccessTools.FieldRefAccess<PhotonTransformView, float>("kinematicClientForcedTimer");
				refsOk = true;
			}
			catch (Exception ex)
			{
				refsOk = false;
				Plugin.Log.LogWarning((object)("[smooth.enemies] PhotonTransformView fields not found (" + ex.Message + ") - enemy body smoothing off, root smoothing still on."));
			}
			return refsOk;
		}

		private static double RenderTime(double now)
		{
			return MasterClock.RenderTime(now, SmoothCfg.DMin, SmoothCfg.DMax);
		}

		private static Body Lookup(PhotonTransformView ptv)
		{
			int instanceID = ((Object)ptv).GetInstanceID();
			if (Bodies.TryGetValue(instanceID, out var value))
			{
				return value;
			}
			if (NotEnemy.Contains(instanceID))
			{
				return null;
			}
			if (!Object.op_Implicit((Object)(object)((Component)ptv).GetComponent<EnemyRigidbody>()))
			{
				if (NotEnemy.Count > 8192)
				{
					NotEnemy.Clear();
				}
				NotEnemy.Add(instanceID);
				return null;
			}
			value = new Body
			{
				Ptv = ptv,
				Rb = ((Component)ptv).GetComponent<Rigidbody>()
			};
			Bodies[instanceID] = value;
			return value;
		}

		private static void FrameTick(Body b, PhotonTransformView ptv, Rigidbody rb)
		{
			//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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Invalid comparison between Unknown and I4
			//IL_00c8: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_0136: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: 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)
			float deltaTime = Time.deltaTime;
			ref float reference = ref F_throttleDisable.Invoke(ptv);
			if (reference > 0f)
			{
				reference -= deltaTime;
			}
			ref bool reference2 = ref F_teleport.Invoke(ptv);
			Vector3 val = F_netPos.Invoke(ptv);
			Quaternion val2 = F_netRot.Invoke(ptv);
			if (F_isSleeping.Invoke(ptv))
			{
				if (!rb.isKinematic)
				{
					rb.isKinematic = true;
				}
				if (rb.position != val || rb.rotation != val2)
				{
					rb.position = val;
					rb.rotation = val2;
				}
				F_smoothPos.Invoke(ptv) = val;
				F_smoothRot.Invoke(ptv) = val2;
				reference2 = false;
				return;
			}
			if (reference2)
			{
				rb.position = val;
				rb.rotation = val2;
				F_smoothPos.Invoke(ptv) = val;
				F_smoothRot.Invoke(ptv) = val2;
				reference2 = false;
				double val3 = RenderTime(SmoothTime.Now);
				double num = Math.Max(b.Buf.NewestTime, val3);
				if (!double.IsInfinity(num) && !double.IsNaN(num))
				{
					b.Buf.Seed(num, val, val2);
				}
				else
				{
					b.Buf.Clear();
				}
				if (!rb.isKinematic)
				{
					rb.linearVelocity = ptv.receivedVelocity;
					rb.angularVelocity = ptv.receivedAngularVelocity;
				}
			}
			else
			{
				if ((int)rb.interpolation != 1)
				{
					rb.interpolation = (RigidbodyInterpolation)1;
				}
				F_smoothPos.Invoke(ptv) = rb.position;
				F_smoothRot.Invoke(ptv) = rb.rotation;
			}
			ref float reference3 = ref F_overrideExtrap.Invoke(ptv);
			if (reference3 > 0f)
			{
				reference3 -= deltaTime;
			}
			ref float reference4 = ref F_kinForced.Invoke(ptv);
			if (reference4 > 0f)
			{
				reference4 = Mathf.Max(0f, reference4 - deltaTime);
			}
		}

		private static void DriveBody(EnemyRigidbody __instance)
		{
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: 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_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: 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_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: 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_0136: 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_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: 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_0195: 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_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			if (Bodies.Count == 0 || !Enabled || !refsOk)
			{
				return;
			}
			try
			{
				if (!IsClient())
				{
					return;
				}
				PhysGrabObject physGrabObject = __instance.physGrabObject;
				if (!Object.op_Implicit((Object)(object)physGrabObject))
				{
					return;
				}
				PhotonTransformView photonTransformView = physGrabObject.photonTransformView;
				if (!Object.op_Implicit((Object)(object)photonTransformView) || !((Behaviour)photonTransformView).isActiveAndEnabled || !Bodies.TryGetValue(((Object)photonTransformView).GetInstanceID(), out var value) || value.Buf.Count == 0 || F_isSleeping.Invoke(photonTransformView) || F_teleport.Invoke(photonTransformView))
				{
					return;
				}
				Rigidbody rb = value.Rb;
				if (!Object.op_Implicit((Object)(object)rb))
				{
					return;
				}
				float fixedDeltaTime = Time.fixedDeltaTime;
				double rt = RenderTime(SmoothTime.Now + (double)fixedDeltaTime);
				if (!value.Buf.Sample(rt, 0.12f, out var pos, out var rot, out var vel, out var angVel))
				{
					return;
				}
				if (rb.isKinematic)
				{
					rb.MovePosition(pos);
					rb.MoveRotation(rot);
					return;
				}
				Vector3 val = pos - rb.position;
				if (((Vector3)(ref val)).sqrMagnitude > 25f)
				{
					rb.position = pos;
					rb.rotation = rot;
					rb.linearVelocity = vel;
					rb.angularVelocity = angVel;
					return;
				}
				Vector3 val2 = vel + Vector3.ClampMagnitude(val * 10f, 20f);
				if (rb.useGravity)
				{
					val2 -= Physics.gravity * fixedDeltaTime;
				}
				rb.linearVelocity = val2;
				Vector3 val3 = angVel;
				Quaternion val4 = rot * Quaternion.Inverse(rb.rotation);
				float num = default(float);
				Vector3 val5 = default(Vector3);
				((Quaternion)(ref val4)).ToAngleAxis(ref num, ref val5);
				if (num > 180f)
				{
					num -= 360f;
				}
				if (Mathf.Abs(num) > 0.01f && PoseBuffer.Finite(val5))
				{
					val3 += val5 * (num * ((float)Math.PI / 180f) * 10f);
				}
				rb.angularVelocity = Vector3.ClampMagnitude(val3, 50f);
			}
			catch (Exception e)
			{
				Safe.Report("smooth.enemies", e);
			}
		}

		internal static void Prune()
		{
			if (Bodies.Count > 0)
			{
				Scratch.Clear();
				foreach (KeyValuePair<int, Body> body in Bodies)
				{
					if (!Object.op_Implicit((Object)(object)body.Value.Ptv))
					{
						Scratch.Add(body.Key);
					}
				}
				for (int i = 0; i < Scratch.Count; i++)
				{
					Bodies.Remove(Scratch[i]);
				}
			}
			if (Roots.Count > 0)
			{
				Scratch.Clear();
				foreach (KeyValuePair<int, Root> root in Roots)
				{
					if (!Object.op_Implicit((Object)(object)root.Value.Enemy))
					{
						Scratch.Add(root.Key);
					}
				}
				for (int j = 0; j < Scratch.Count; j++)
				{
					Roots.Remove(Scratch[j]);
				}
			}
			Scratch.Clear();
		}

		internal static void ResetAll()
		{
			Bodies.Clear();
			Roots.Clear();
			NotEnemy.Clear();
			MasterClock.Reset();
		}
	}
	internal static class GrabPullerSmoothing
	{
		private sealed class Entry
		{
			public PhysGrabber Grabber;

			public readonly NetClock Clock = new NetClock();

			public readonly PoseBuffer Buf = new PoseBuffer(derivedVel: true, 5f);

			public bool Armed;
		}

		[HarmonyPatch]
		private static class Core
		{
			[HarmonyPatch(typeof(PhysGrabber), "OnPhotonSerializeView")]
			[HarmonyPostfix]
			private static void SerializePostfix(PhysGrabber __instance, PhotonStream stream, PhotonMessageInfo info)
			{
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_0085: Unknown result type (might be due to invalid IL or missing references)
				//IL_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_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)
				if (stream == null || stream.IsWriting || !Enabled)
				{
					return;
				}
				try
				{
					if (!__instance.isLocal && SemiFunc.IsMultiplayer() && SemiFunc.MasterAndOwnerOnlyRPC(info, info.photonView))
					{
						Entry orCreate = GetOrCreate(__instance);
						if (!orCreate.Armed && IsHolding(__instance))
						{
							orCreate.Buf.Clear();
							orCreate.Armed = true;
						}
						double sentServerTime = ((PhotonMessageInfo)(ref info)).SentServerTime;
						orCreate.Clock.Observe(sentServerTime, SmoothTime.Now);
						orCreate.Buf.Add(sentServerTime, __instance.physGrabPointPullerPosition, Quaternion.identity, Vector3.zero, Vector3.zero, orCreate.Clock.Interval);
						Drive(__instance, orCreate);
					}
				}
				catch (Exception e)
				{
					Safe.Report("smooth.pullers", e);
				}
			}

			[HarmonyPatch(typeof(PhysGrabber), "FixedUpdate")]
			[HarmonyPrefix]
			private static void FixedPrefix(PhysGrabber __instance)
			{
				Apply(__instance);
			}

			[HarmonyPatch(typeof(PhysGrabber), "Update")]
			[HarmonyPrefix]
			private static void UpdatePrefix(PhysGrabber __instance)
			{
				Apply(__instance);
			}
		}

		[HarmonyPatch]
		private static class GrabStart
		{
			[HarmonyPatch(typeof(PhysGrabObject), "GrabLinkRPC")]
			[HarmonyPrefix]
			private static void GrabLinkPrefix(int playerPhotonID, int _grabRevision, out PhysGrabber __state)
			{
				__state = null;
				if (!Enabled || _grabRevision <= 0)
				{
					return;
				}
				try
				{
					PhotonView val = PhotonView.Find(playerPhotonID);
					if (Object.op_Implicit((Object)(object)val))
					{
						PhysGrabber component = ((Component)val).GetComponent<PhysGrabber>();
						if (Object.op_Implicit((Object)(object)component) && !component.isLocal && component.grabRevision != _grabRevision)
						{
							__state = component;
						}
					}
				}
				catch (Exception e)
				{
					Safe.Report("smooth.pullers", e);
				}
			}

			[HarmonyPatch(typeof(PhysGrabObject), "GrabLinkRPC")]
			[HarmonyPostfix]
			private static void GrabLinkPostfix(Vector3 point, int _grabRevision, PhotonMessageInfo _info, PhysGrabber __state)
			{
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)__state == (Object)null)
				{
					return;
				}
				try
				{
					if (Object.op_Implicit((Object)(object)__state) && __state.grabRevision == _grabRevision)
					{
						Entry orCreate = GetOrCreate(__state);
						orCreate.Buf.Seed(((PhotonMessageInfo)(ref _info)).SentServerTime - 0.001, point, Quaternion.identity);
						orCreate.Armed = true;
					}
				}
				catch (Exception e)
				{
					Safe.Report("smooth.pullers", e);
				}
			}
		}

		[HarmonyPatch]
		private static class Lifecycle
		{
			[HarmonyPatch(typeof(PhysGrabber), "OnDestroy")]
			[HarmonyPrefix]
			private static void DestroyPrefix(PhysGrabber __instance)
			{
				if (Entries.Count == 0)
				{
					return;
				}
				try
				{
					Entries.Remove(((Object)__instance).GetInstanceID());
				}
				catch (Exception e)
				{
					Safe.Report("smooth.pullers", e);
				}
			}
		}

		internal const string Area = "smooth.pullers";

		private const double DelayMin = 0.04;

		private const double DelayMax = 0.08;

		private const float MaxExtrap = 0.05f;

		private static readonly Dictionary<int, Entry> Entries = new Dictionary<int, Entry>();

		private static readonly List<int> Scratch = new List<int>();

		private static bool Enabled
		{
			get
			{
				if (SmoothCfg.GrabPullers != null && SmoothCfg.GrabPullers.Value)
				{
					return !SmoothCfg.PullersOff;
				}
				return false;
			}
		}

		private static void Apply(PhysGrabber g)
		{
			if (Entries.Count == 0)
			{
				return;
			}
			if (!Enabled)
			{
				Entries.Clear();
				return;
			}
			try
			{
				if (!g.isLocal && Entries.TryGetValue(((Object)g).GetInstanceID(), out var value))
				{
					Drive(g, value);
				}
			}
			catch (Exception e)
			{
				Safe.Report("smooth.pullers", e);
			}
		}

		private static bool IsHolding(PhysGrabber g)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			if (g.grabbed)
			{
				return (int)g.grabState != 4;
			}
			return false;
		}

		private static void Drive(PhysGrabber g, Entry e)
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			if (!IsHolding(g))
			{
				e.Armed = false;
			}
			else if (!e.Armed)
			{
				e.Buf.Clear();
				e.Armed = true;
			}
			else
			{
				if (e.Buf.Count == 0)
				{
					return;
				}
				double rt = e.Clock.RenderTime(SmoothTime.Now, 0.04, 0.08);
				if (e.Buf.Sample(rt, 0.05f, out var pos, out var _, out var _, out var _))
				{
					g.physGrabPointPullerPosition = pos;
					Transform physGrabPointPuller = g.physGrabPointPuller;
					if (Object.op_Implicit((Object)(object)physGrabPointPuller))
					{
						physGrabPointPuller.position = pos;
					}
				}
			}
		}

		private static Entry GetOrCreate(PhysGrabber g)
		{
			int instanceID = ((Object)g).GetInstanceID();
			if (!Entries.TryGetValue(instanceID, out var value))
			{
				value = new Entry
				{
					Grabber = g
				};
				Entries[instanceID] = value;
			}
			return value;
		}

		internal static void Prune()
		{
			if (Entries.Count == 0)
			{
				return;
			}
			Scratch.Clear();
			foreach (KeyValuePair<int, Entry> entry in Entries)
			{
				if (!Object.op_Implicit((Object)(object)entry.Value.Grabber))
				{
					Scratch.Add(entry.Key);
				}
			}
			for (int i = 0; i < Scratch.Count; i++)
			{
				Entries.Remove(Scratch[i]);
			}
			Scratch.Clear();
		}

		internal static void ResetAll()
		{
			Entries.Clear();
		}
	}
	internal static class RemotePlayerSmoothing
	{
		private sealed class Entry
		{
			public PlayerAvatar Avatar;

			public readonly NetClock Clock = new NetClock();

			public readonly PoseBuffer Buf = new PoseBuffer(derivedVel: false, 5f);

			public bool Overriding;

			public Vector3 BlendFrom;

			public double BlendStart;
		}

		[HarmonyPatch]
		private static class Core
		{
			[HarmonyPatch(typeof(PlayerAvatar), "OnPhotonSerializeView")]
			[HarmonyPrefix]
			private static void SerializePrefix(PlayerAvatar __instance, PhotonStream stream, out long __state)
			{
				__state = long.MinValue;
				if (stream == null || stream.IsWriting || !Enabled)
				{
					return;
				}
				try
				{
					if (!__instance.isLocal && IsClient())
					{
						__state = __instance.clientPhysRidingID;
						__instance.clientPhysRidingID = -2147483571;
					}
				}
				catch (Exception e)
				{
					Safe.Report("smooth.players", e);
				}
			}

			[HarmonyPatch(typeof(PlayerAvatar), "OnPhotonSerializeView")]
			[HarmonyPostfix]
			private static void SerializePostfix(PlayerAvatar __instance, PhotonMessageInfo info, long __state)
			{
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0053: Unknown result type (might be due to invalid IL or missing references)
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				//IL_005e: 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)
				if (__state == long.MinValue)
				{
					return;
				}
				try
				{
					if (__instance.clientPhysRidingID == -2147483571)
					{
						__instance.clientPhysRidingID = (int)__state;
						return;
					}
					Entry orCreate = GetOrCreate(__instance);
					double sentServerTime = ((PhotonMessageInfo)(ref info)).SentServerTime;
					orCreate.Clock.Observe(sentServerTime, SmoothTime.Now);
					if (orCreate.Buf.Add(sentServerTime, __instance.clientPosition, __instance.clientRotation, __instance.rbVelocityRaw, Vector3.zero, orCreate.Clock.Interval) == AddResult.Teleported)
					{
						orCreate.BlendFrom = Vector3.zero;
					}
				}
				catch (Exception e)
				{
					Safe.Report("smooth.players", e);
				}
			}

			[HarmonyPatch(typeof(PlayerAvatar), "FixedUpdate")]
			[HarmonyPrefix]
			private static void FixedPrefix(PlayerAvatar __instance)
			{
				Apply(__instance);
			}

			[HarmonyPatch(typeof(PlayerAvatar), "Update")]
			[HarmonyPostfix]
			private static void UpdatePostfix(PlayerAvatar __instance)
			{
				Apply(__instance);
			}
		}

		[HarmonyPatch]
		private static class Lifecycle
		{
			[HarmonyPatch(typeof(PlayerAvatar), "SpawnRPC")]
			[HarmonyPostfix]
			private static void SpawnPostfix(PlayerAvatar __instance)
			{
				ResetEntry(__instance);
			}

			[HarmonyPatch(typeof(PlayerAvatar), "ReviveRPC")]
			[HarmonyPostfix]
			private static void RevivePostfix(PlayerAvatar __instance)
			{
				ResetEntry(__instance);
			}

			[HarmonyPatch(typeof(PlayerAvatar), "OnDestroy")]
			[HarmonyPrefix]
			private static void DestroyPrefix(PlayerAvatar __instance)
			{
				if (Entries.Count == 0)
				{
					return;
				}
				try
				{
					Entries.Remove(((Object)__instance).GetInstanceID());
				}
				catch (Exception e)
				{
					Safe.Report("smooth.players", e);
				}
			}
		}

		internal const string Area = "smooth.players";

		private const int Sentinel = -2147483571;

		private const float MaxExtrap = 0.1f;

		private const float BlendTau = 0.15f;

		private static readonly Dictionary<int, Entry> Entries = new Dictionary<int, Entry>();

		private static readonly List<int> Scratch = new List<int>();

		private static bool Enabled
		{
			get
			{
				if (SmoothCfg.RemotePlayers != null && SmoothCfg.RemotePlayers.Value)
				{
					return !SmoothCfg.PlayersOff;
				}
				return false;
			}
		}

		private static bool IsClient()
		{
			GameManager instance = GameManager.instance;
			if (Object.op_Implicit((Object)(object)instance) && instance.gameMode == 1)
			{
				return !PhotonNetwork.IsMasterClient;
			}
			return false;
		}

		private static void Apply(PlayerAvatar a)
		{
			//IL_00ec: 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_00aa: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: 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_00d8: 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_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: 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_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)
			if (Entries.Count == 0)
			{
				return;
			}
			if (!Enabled)
			{
				Entries.Clear();
				return;
			}
			try
			{
				if (a.isLocal || !Entries.TryGetValue(((Object)a).GetInstanceID(), out var value))
				{
					return;
				}
				if (!CanOverride(a) || value.Buf.Count == 0)
				{
					value.Overriding = false;
					return;
				}
				double now = SmoothTime.Now;
				double rt = value.Clock.RenderTime(now, SmoothCfg.DMin, SmoothCfg.DMax);
				if (!value.Buf.Sample(rt, 0.1f, out var pos, out var rot, out var _, out var _))
				{
					return;
				}
				if (!value.Overriding)
				{
					Vector3 val = a.clientPositionCurrent - pos;
					value.BlendFrom = ((PoseBuffer.Finite(val) && ((Vector3)(ref val)).sqrMagnitude < 9f) ? val : Vector3.zero);
					value.BlendStart = now;
					value.Overriding = true;
				}
				if (value.BlendFrom != Vector3.zero)
				{
					double num = now - value.BlendStart;
					if (num < 0.0)
					{
						num = 0.0;
					}
					float num2 = Mathf.Exp((float)((0.0 - num) / 0.15000000596046448));
					if (num2 < 0.01f)
					{
						value.BlendFrom = Vector3.zero;
					}
					else
					{
						pos += value.BlendFrom * num2;
					}
				}
				a.clientPositionCurrent = pos;
				a.clientRotationCurrent = rot;
			}
			catch (Exception e)
			{
				Safe.Report("smooth.players", e);
			}
		}

		private static bool CanOverride(PlayerAvatar a)
		{
			if (!IsClient())
			{
				return false;
			}
			LevelGenerator instance = LevelGenerator.Instance;
			if (!Object.op_Implicit((Object)(object)instance) || !instance.Generated)
			{
				return false;
			}
			if (a.isTumbling || a.clientPhysRiding || a.isDisabled || a.deadSet)
			{
				return false;
			}
			PhotonView photonView = a.photonView;
			if (Object.op_Implicit((Object)(object)photonView))
			{
				return !photonView.IsMine;
			}
			return false;
		}

		private static void ResetEntry(PlayerAvatar a)
		{
			if (Entries.Count == 0)
			{
				return;
			}
			try
			{
				if (Entries.TryGetValue(((Object)a).GetInstanceID(), out var value))
				{
					value.Buf.Clear();
					value.Overriding = false;
				}
			}
			catch (Exception e)
			{
				Safe.Report("smooth.players", e);
			}
		}

		private static Entry GetOrCreate(PlayerAvatar a)
		{
			int instanceID = ((Object)a).GetInstanceID();
			if (!Entries.TryGetValue(instanceID, out var value))
			{
				value = new Entry
				{
					Avatar = a
				};
				Entries[instanceID] = value;
			}
			return value;
		}

		internal static void Prune()
		{
			if (Entries.Count == 0)
			{
				return;
			}
			Scratch.Clear();
			foreach (KeyValuePair<int, Entry> entry in Entries)
			{
				if (!Object.op_Implicit((Object)(object)entry.Value.Avatar))
				{
					Scratch.Add(entry.Key);
				}
			}
			for (int i = 0; i < Scratch.Count; i++)
			{
				Entries.Remove(Scratch[i]);
			}
			Scratch.Clear();
		}

		internal static void ResetAll()
		{
			Entries.Clear();
		}
	}
	internal static class SmoothCfg
	{
		public static ConfigEntry<bool> RemotePlayers;

		public static ConfigEntry<bool> Enemies;

		public static ConfigEntry<bool> GrabPullers;

		public static ConfigEntry<float> DelayMin;

		public static ConfigEntry<float> DelayMax;

		internal static volatile bool PlayersOff;

		internal static volatile bool EnemiesOff;

		internal static volatile bool PullersOff;

		internal static float DMin
		{
			get
			{
				if (DelayMin == null)
				{
					return 0.06f;
				}
				return DelayMin.Value;
			}
		}

		internal static float DMax
		{
			get
			{
				if (DelayMax == null)
				{
					return 0.2f;
				}
				return Mathf.Max(DelayMax.Value, DMin);
			}
		}

		public static void Bind(ConfigFile f)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			RemotePlayers = f.Bind<bool>("3. Smoothing", "Remote Players", true, "Buffered interpolation of other players' movement (body and visuals) instead of snapping to each packet.");
			Enemies = f.Bind<bool>("3. Smoothing", "Enemies", true, "Clients only: enemies' root and physical body are interpolated on one shared, buffered timeline (no stop-and-go, no body/root drift).");
			GrabPullers = f.Bind<bool>("3. Smoothing", "Grab Pullers", true, "Other players' grab-beam target point is interpolated. On the host this makes objects held by clients move smoothly for everyone.");
			DelayMin = f.Bind<float>("3. Smoothing", "Delay Min", 0.06f, new ConfigDescription("Minimum buffering delay (seconds, on top of network latency) for players and enemies.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.02f, 0.3f), Array.Empty<object>()));
			DelayMax = f.Bind<float>("3. Smoothing", "Delay Max", 0.2f, new ConfigDescription("Maximum buffering delay (seconds) used on bad connections.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 0.5f), Array.Empty<object>()));
			Safe.Disabled += OnAreaDisabled;
			Runner.Register(SmoothingSystem.Instance);
		}

		private static void OnAreaDisabled(string area)
		{
			switch (area)
			{
			case "smooth.players":
				PlayersOff = true;
				break;
			case "smooth.enemies":
				EnemiesOff = true;
				break;
			case "smooth.pullers":
				PullersOff = true;
				break;
			}
		}
	}
	internal static class SmoothTime
	{
		public static double Now
		{
			get
			{
				if (!Time.inFixedTimeStep)
				{
					return Time.unscaledTimeAsDouble;
				}
				return Time.fixedUnscaledTimeAsDouble;
			}
		}
	}
	internal sealed class NetClock
	{
		private double offset;

		private bool hasOffset;

		private double lastSend = double.NegativeInfinity;

		private double interval = 1.0 / 30.0;

		private double jitter = 0.01;

		private double baseCur;

		private bool baseInit;

		private double lastNow;

		public double Interval => interval;

		public bool HasData => hasOffset;

		public void Reset()
		{
			hasOffset = false;
			baseInit = false;
			lastSend = double.NegativeInfinity;
			interval = 1.0 / 30.0;
			jitter = 0.01;
		}

		public void Observe(double send, double arrival)
		{
			if (double.IsNaN(send) || double.IsInfinity(send))
			{
				return;
			}
			if (send <= lastSend)
			{
				if (lastSend - send < 5.0)
				{
					return;
				}
				Reset();
			}
			double num = arrival - send;
			if (!hasOffset || Math.Abs(num - offset) > 1.0)
			{
				offset = num;
				hasOffset = true;
				jitter = 0.01;
				baseInit = false;
			}
			else
			{
				double num2 = num - offset;
				offset += ((num2 < 0.0) ? (num2 * 0.25) : (num2 * 0.02));
				double num3 = num - offset;
				if (num3 < 0.0)
				{
					num3 = 0.0;
				}
				jitter += (num3 - jitter) * ((num3 > jitter) ? 0.2 : 0.05);
			}
			if (!double.IsNegativeInfinity(lastSend))
			{
				double num4 = send - lastSend;
				if (num4 > 0.004 && num4 < 0.2)
				{
					interval += (num4 - interval) * 0.1;
				}
			}
			lastSend = send;
		}

		public double RenderTime(double now, double minDelay, double maxDelay)
		{
			if (!hasOffset)
			{
				return double.NegativeInfinity;
			}
			double num = interval + 2.0 * jitter;
			if (num < minDelay)
			{
				num = minDelay;
			}
			if (num > maxDelay)
			{
				num = maxDelay;
			}
			double num2 = offset + num;
			if (!baseInit || Math.Abs(num2 - baseCur) > 0.3)
			{
				baseCur = num2;
				baseInit = true;
			}
			else
			{
				double num3 = now - lastNow;
				if (num3 < 0.0)
				{
					num3 = 0.0;
				}
				else if (num3 > 0.1)
				{
					num3 = 0.1;
				}
				double num4 = num3 * 0.08;
				double num5 = num2 - baseCur;
				baseCur += ((num5 > num4) ? num4 : ((num5 < 0.0 - num4) ? (0.0 - num4) : num5));
			}
			lastNow = now;
			return now - baseCur;
		}
	}
	internal struct PoseSample
	{
		public double T;

		public Vector3 Pos;

		public Quaternion Rot;

		public Vector3 Vel;

		public Vector3 AngVel;
	}
	internal enum AddResult
	{
		Rejected,
		Added,
		Teleported
	}
	internal sealed class PoseBuffer
	{
		private const int Cap = 20;

		private readonly PoseSample[] s = new PoseSample[20];

		private int n;

		private readonly bool derivedVel;

		private readonly float teleportDistSq;

		public int Count => n;

		public double NewestTime
		{
			get
			{
				if (n <= 0)
				{
					return double.NegativeInfinity;
				}
				return s[n - 1].T;
			}
		}

		public PoseBuffer(bool derivedVel, float teleportDist)
		{
			this.derivedVel = derivedVel;
			teleportDistSq = teleportDist * teleportDist;
		}

		public void Clear()
		{
			n = 0;
		}

		public void Seed(double t, Vector3 pos, Quaternion rot)
		{
			//IL_0009: 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_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)
			n = 0;
			Push(t, pos, rot, Vector3.zero, Vector3.zero);
		}

		public AddResult Add(double t, Vector3 pos, Quaternion rot, Vector3 vel, Vector3 angVel, double interval)
		{
			//IL_0010: 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_0021: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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_0093: 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_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: 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_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			if (double.IsNaN(t) || double.IsInfinity(t) || !Finite(pos) || !Finite(vel) || !Finite(angVel))
			{
				return AddResult.Rejected;
			}
			if (!Finite(rot))
			{
				rot = Quaternion.identity;
			}
			AddResult result = AddResult.Added;
			if (n > 0)
			{
				PoseSample poseSample = s[n - 1];
				if (t <= poseSample.T)
				{
					if (poseSample.T - t < 5.0)
					{
						return AddResult.Rejected;
					}
					n = 0;
				}
				else
				{
					Vector3 val = pos - poseSample.Pos;
					if (((Vector3)(ref val)).sqrMagnitude > teleportDistSq)
					{
						n = 0;
						result = AddResult.Teleported;
					}
					else
					{
						double num = t - poseSample.T;
						double num2 = ((interval > 0.005 && interval < 0.2) ? interval : (1.0 / 30.0));
						if (num > Math.Max(0.25, num2 * 4.0) && (num > 1.0 || ((Vector3)(ref poseSample.Vel)).sqrMagnitude < 0.25f))
						{
							if (num > 1.0)
							{
								s[0] = poseSample;
								n = 1;
							}
							PoseSample x = poseSample;
							x.T = t - Math.Min(num2, num * 0.5);
							x.Vel = Vector3.zero;
							x.AngVel = Vector3.zero;
							PushSample(in x);
						}
					}
				}
			}
			if (derivedVel)
			{
				vel = Vector3.zero;
				if (n > 0)
				{
					PoseSample poseSample2 = s[n - 1];
					double num3 = t - poseSample2.T;
					if (num3 > 0.001)
					{
						vel = Vector3.ClampMagnitude((pos - poseSample2.Pos) / (float)num3, 60f);
					}
				}
				angVel = Vector3.zero;
			}
			Push(t, pos, rot, vel, angVel);
			return result;
		}

		private void Push(double t, Vector3 pos, Quaternion rot, Vector3 vel, Vector3 angVel)
		{
			//IL_000a: 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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			PoseSample x = default(PoseSample);
			x.T = t;
			x.Pos = pos;
			x.Rot = rot;
			x.Vel = vel;
			x.AngVel = angVel;
			PushSample(in x);
		}

		private void PushSample(in PoseSample x)
		{
			if (n == 20)
			{
				Array.Copy(s, 1, s, 0, 19);
				n--;
			}
			s[n++] = x;
		}

		public bool Sample(double rt, float maxExtrap, out Vector3 pos, out Quaternion rot, out Vector3 vel, out Vector3 angVel)
		{
			//IL_0009: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_0106: 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_0112: 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_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_00b9: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: 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_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04da: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0408: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0417: Unknown result type (might be due to invalid IL or missing references)
			//IL_0419: Unknown result type (might be due to invalid IL or missing references)
			//IL_041e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_042b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0430: Unknown result type (might be due to invalid IL or missing references)
			//IL_043a: Unknown result type (might be due to invalid IL or missing references)
			//IL_043c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0441: Unknown result type (might be due to invalid IL or missing references)
			//IL_0446: Unknown result type (might be due to invalid IL or missing references)
			//IL_0451: Unknown result type (might be due to invalid IL or missing references)
			//IL_0457: Unknown result type (might be due to invalid IL or missing references)
			//IL_045c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0461: Unknown result type (might be due to invalid IL or missing references)
			//IL_0474: Unknown result type (might be due to invalid IL or missing references)
			//IL_0479: Unknown result type (might be due to invalid IL or missing references)
			//IL_047b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0480: Unknown result type (might be due to invalid IL or missing references)
			//IL_049e: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0491: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			if (n == 0)
			{
				pos = default(Vector3);
				rot = Quaternion.identity;
				vel = default(Vector3);
				angVel = default(Vector3);
				return false;
			}
			if (rt <= s[0].T)
			{
				pos = s[0].Pos;
				rot = s[0].Rot;
				vel = ((n == 1) ? Vector3.zero : s[0].Vel);
				angVel = ((n == 1) ? Vector3.zero : s[0].AngVel);
				return true;
			}
			PoseSample poseSample = s[n - 1];
			if (rt >= poseSample.T)
			{
				double num = rt - poseSample.T;
				float num2 = (float)((num < (double)maxExtrap) ? num : ((double)maxExtrap));
				pos = poseSample.Pos + poseSample.Vel * num2;
				rot = poseSample.Rot;
				float num3 = ((Vector3)(ref poseSample.AngVel)).magnitude * num2 * 57.29578f;
				if (num3 > 0.01f && num3 < 360f)
				{
					if (num3 > 30f)
					{
						num3 = 30f;
					}
					rot = Quaternion.AngleAxis(num3, ((Vector3)(ref poseSample.AngVel)).normalized) * poseSample.Rot;
				}
				bool flag = num > (double)maxExtrap;
				vel = (flag ? Vector3.zero : poseSample.Vel);
				angVel = (flag ? Vector3.zero : poseSample.AngVel);
				return true;
			}
			int i;
			for (i = 1; i < n - 1 && s[i].T < rt; i++)
			{
			}
			PoseSample poseSample2 = s[i - 1];
			PoseSample poseSample3 = s[i];
			double num4 = poseSample3.T - poseSample2.T;
			float num5 = ((num4 > 1E-06) ? ((float)((rt - poseSample2.T) / num4)) : 1f);
			if (num5 < 0f)
			{
				num5 = 0f;
			}
			else if (num5 > 1f)
			{
				num5 = 1f;
			}
			Vector3 val = Vector3.LerpUnclamped(poseSample2.Pos, poseSample3.Pos, num5);
			Vector3 val2 = ((num4 > 1E-06) ? ((poseSample3.Pos - poseSample2.Pos) / (float)num4) : Vector3.zero);
			if (num4 > 0.3)
			{
				pos = val;
				vel = val2;
			}
			else
			{
				Vector3 val3;
				Vector3 val4;
				if (derivedVel)
				{
					val3 = val2;
					val4 = val2;
					if (i >= 2)
					{
						double num6 = poseSample3.T - s[i - 2].T;
						if (num6 > 0.0001 && num6 < 0.6)
						{
							val3 = (poseSample3.Pos - s[i - 2].Pos) / (float)num6;
						}
					}
					if (i + 1 < n)
					{
						double num7 = s[i + 1].T - poseSample2.T;
						if (num7 > 0.0001 && num7 < 0.6)
						{
							val4 = (s[i + 1].Pos - poseSample2.Pos) / (float)num7;
						}
					}
				}
				else
				{
					val3 = poseSample2.Vel;
					val4 = poseSample3.Vel;
				}
				float num8 = (float)num4;
				float num9 = num5 * num5;
				float num10 = num9 * num5;
				float num11 = 2f * num10 - 3f * num9 + 1f;
				float num12 = num10 - 2f * num9 + num5;
				float num13 = -2f * num10 + 3f * num9;
				float num14 = num10 - num9;
				pos = num11 * poseSample2.Pos + num12 * num8 * val3 + num13 * poseSample3.Pos + num14 * num8 * val4;
				Vector3 val5 = poseSample3.Pos - poseSample2.Pos;
				float num15 = 0.5f * ((Vector3)(ref val5)).magnitude + 0.05f;
				val5 = pos - val;
				if (((Vector3)(ref val5)).sqrMagnitude > num15 * num15 || !Finite(pos))
				{
					pos = val;
				}
				vel = Vector3.LerpUnclamped(val3, val4, num5);
			}
			rot = Quaternion.Slerp(poseSample2.Rot, poseSample3.Rot, num5);
			angVel = Vector3.LerpUnclamped(poseSample2.AngVel, poseSample3.AngVel, num5);
			return true;
		}

		internal static bool Finite(Vector3 v)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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)
			if (!float.IsNaN(v.x) && !float.IsNaN(v.y) && !float.IsNaN(v.z) && !float.IsInfinity(v.x) && !float.IsInfinity(v.y))
			{
				return !float.IsInfinity(v.z);
			}
			return false;
		}

		private static bool Finite(Quaternion q)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0051: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			if (float.IsNaN(q.x) || float.IsNaN(q.y) || float.IsNaN(q.z) || float.IsNaN(q.w))
			{
				return false;
			}
			float num = q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w;
			if (num > 0.5f)
			{
				return num < 1.5f;
			}
			return false;
		}
	}
	internal sealed class SmoothingSystem : ISystem
	{
		public static readonly SmoothingSystem Instance = new SmoothingSystem();

		private float nextPrune;

		private bool wasInRoom;

		private int lastMaster = int.MinValue;

		public string Area => "smooth.house";

		public void Tick()
		{
			bool inRoom = PhotonNetwork.InRoom;
			int num = ((inRoom && PhotonNetwork.MasterClient != null) ? PhotonNetwork.MasterClient.ActorNumber : (-1));
			if ((wasInRoom && !inRoom) || (lastMaster != int.MinValue && num != lastMaster))
			{
				RemotePlayerSmoothing.ResetAll();
				EnemySmoothing.ResetAll();
				GrabPullerSmoothing.ResetAll();
			}
			wasInRoom = inRoom;
			lastMaster = num;
			float unscaledTime = Time.unscaledTime;
			if (unscaledTime >= nextPrune)
			{
				nextPrune = unscaledTime + 2f;
				RemotePlayerSmoothing.Prune();
				EnemySmoothing.Prune();
				GrabPullerSmoothing.Prune();
			}
		}

		public void FixedTick()
		{
		}

		public void LateTick()
		{
		}
	}
}
namespace NetworkSync.Prediction
{
	internal static class TumblePrediction
	{
		private enum Phase
		{
			None,
			Starting,
			Confirmed,
			Blending,
			Exiting
		}

		private struct Hint
		{
			public Vector3 Pos;

			public Quaternion Rot;

			public float Time;

			public int Actor;
		}

		private sealed class Sys : ISystem
		{
			public string Area => "tumble";

			public void Tick()
			{
				TumblePrediction.Tick();
			}

			public void FixedTick()
			{
				TumblePrediction.FixedTick();
			}

			public void LateTick()
			{
			}
		}

		internal struct RbState
		{
			public bool Valid;

			public bool Kinematic;

			public Vector3 Vel;

			public Vector3 AngVel;
		}

		public const string Area = "tumble";

		private const float BlendSeconds = 0.3f;

		private const float BlendMaxSeconds = 1f;

		private const float StreamWaitSeconds = 1f;

		private const float FollowStrength = 10f;

		private const float SnapDistance = 4f;

		private const float HintMaxDistance = 3f;

		private const float HintMaxAge = 1.5f;

		private static bool inited;

		private static bool fieldsOk;

		private static Phase phase;

		private static PlayerTumble tumble;

		internal static PhotonTransformView HeldPtv;

		private static float phaseStart;

		private static float timeout;

		private static int phaseServerTs;

		private static int confirmTs;

		private static Vector3 launchImpulse;

		private static float launchAt;

		private static bool applyingLocal;

		public static int Starts;

		public static int StartConfirms;

		public static int StartRollbacks;

		public static int Exits;

		public static int ExitConfirms;

		public static int ExitRollbacks;

		public static int Overridden;

		public static int HintsUsed;

		public static int HintsRejected;

		public static string LastEvent = "-";

		private static FieldRef<PhotonTransformView, bool> fTeleport;

		private static FieldRef<PhotonTransformView, float> fThrottleDisable;

		private static FieldRef<PhotonTransformView, float> fExtrapolate;

		private static FieldRef<PhotonTransformView, float> fKinForced;

		private static bool najChecked;

		private static Func<PlayerTumble, float> najLaunch;

		private static Func<PlayerTumble, int> najUnlock;

		private static readonly Dictionary<int, Hint> Hints = new Dictionary<int, Hint>();

		private static float nextHintPurge;

		public static bool Enabled
		{
			get
			{
				if (fieldsOk && Cfg.InstantTumble != null && Cfg.InstantTumble.Value && Session.Active)
				{
					return !Safe.IsDisabled("tumble");
				}
				return false;
			}
		}

		private static bool HostEnabled
		{
			get
			{
				if (fieldsOk && Session.Active)
				{
					return !Safe.IsDisabled("tumble");
				}
				return false;
			}
		}

		internal static bool HasHints => Hints.Count > 0;

		internal static bool Busy => phase != Phase.None;

		public static string Status
		{
			get
			{
				if (!fieldsOk)
				{
					return "off (game changed)";
				}
				if (Cfg.InstantTumble == null || !Cfg.InstantTumble.Value)
				{
					return "off (config)";
				}
				if (Safe.IsDisabled("tumble"))
				{
					return "off (crashed)";
				}
				if (!Session.Active)
				{
					return "inactive (host has no NetworkSync)";
				}
				return $"{phase.ToString().ToLowerInvariant()} | starts {Starts} ok {StartConfirms} back {StartRollbacks} | getup {Exits} ok {ExitConfirms} back {ExitRollbacks} | overridden {Overridden} | hints used {HintsUsed} rej {HintsRejected} | last: {LastEvent}";
			}
		}

		public static void Init()
		{
			if (inited)
			{
				return;
			}
			inited = true;
			try
			{
				fTeleport = Ref<bool>("teleport");
				fThrottleDisable = Ref<float>("throttleDisableTimer");
				fExtrapolate = Ref<float>("overrideExtrapolateTimer");
				fKinForced = Ref<float>("kinematicClientForcedTimer");
				fieldsOk = TumblePatches.AllApplied(out var missing);
				if (!fieldsOk)
				{
					Plugin.Log.LogError((object)("[tumble] instant tumble off: patch missing (" + missing + ")."));
				}
			}
			catch (Exception ex)
			{
				fieldsOk = false;
				Plugin.Log.LogError((object)("[tumble] instant tumble off: PhotonTransformView layout changed (" + ex.Message + ")."));
			}
			Bus.On(158, OnHintMsg);
			Session.RoomLeft += delegate
			{
				Reset("left room");
			};
			Session.MasterSwitched += delegate
			{
				Reset("master switched");
			};
			Session.ActiveChanged += delegate(bool a)
			{
				if (!a)
				{
					Reset("session inactive");
				}
			};
			Safe.Disabled += delegate(string area)
			{
				if (area == "tumble")
				{
					Reset("area off");
				}
			};
			Runner.Register(new Sys());
			if (fieldsOk)
			{
				Plugin.Log.LogInfo((object)"[tumble] instant tumble ready.");
			}
		}

		private static FieldRef<PhotonTransformView, T> Ref<T>(string name)
		{
			if (AccessTools.Field(typeof(PhotonTransformView), name) == null)
			{
				throw new MissingFieldException("PhotonTransformView", name);
			}
			return AccessTools.FieldRefAccess<PhotonTransformView, T>(name);
		}

		internal static bool WillSend(PlayerTumble t, bool isTumbling, bool playerInput)
		{
			if (!playerInput || (Object)(object)t == (Object)null || PhotonNetwork.IsMasterClient || !Enabled)
			{
				return false;
			}
			if (SemiFunc.MenuLevel() || t.isTumbling == isTumbling)
			{
				return false;
			}
			if ((Object)(object)t.playerAvatar == (Object)null || !t.playerAvatar.isLocal)
			{
				return false;
			}
			if (t.tumbleRequestTimer > 0f && t.tumbleRequestIsTumbling == isTumbling && t.tumbleRequestPlayerInput == playerInput)
			{
				return false;
			}
			return true;
		}

		internal static void SendHint(PlayerTumble t)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			if (phase == Phase.None && CanPredict(t))
			{
				Transform transform = ((Component)t.playerAvatar).transform;
				Vector3 val = transform.position + Vector3.up * 0.3f;
				Quaternion rotation = transform.rotation;
				Bus.ToMaster(158, new object[2]
				{
					t.photonView.ViewID,
					new float[7] { val.x, val.y, val.z, rotation.x, rotation.y, rotation.z, rotation.w }
				});
			}
		}

		internal static void OnRequestSent(PlayerTumble t, bool isTumbling)
		{
			if (phase == Phase.None && CanPredict(t) && !(t.tumbleRequestTimer < 0.45f) && t.tumbleRequestIsTumbling == isTumbling)
			{
				if (isTumbling)
				{
					BeginStart(t);
				}
				else
				{
					BeginExit(t);
				}
			}
		}

		private static bool CanPredict(PlayerTumble t)
		{
			if ((Object)(object)t == (Object)null || !t.setup || (Object)(object)t.rb == (Object)null || (Object)(object)t.photonView == (Object)null || (Object)(object)t.physGrabObject == (Object)null)
			{
				return false;
			}
			if ((Object)(object)t.physGrabObject.photonTransformView == (Object)null || !t.physGrabObject.spawned)
			{
				return false;
			}
			PlayerAvatar playerAvatar = t.playerAvatar;
			if ((Object)(object)playerAvatar == (Object)null || !playerAvatar.isLocal || playerAvatar.isDisabled || (Object)(object)playerAvatar.playerHealth == (Object)null)
			{
				return false;
			}
			if ((Object)(object)PlayerController.instance == (Object)null || PhotonNetwork.MasterClient == null || !PhotonNetwork.InRoom || PhotonNetwork.IsMasterClient)
			{
				return false;
			}
			return !SemiFunc.MenuLevel();
		}

		private static void BeginStart(PlayerTumble t)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL o