Decompiled source of CartPort v1.0.1

plugins\CartPort.dll

Decompiled 4 days ago
using System;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Fusion;
using Fusion.Sockets;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Attributes;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using SSSGame;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("CartPort")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f125dc1c5a1088217f0d0b2164bf26ae55376f12")]
[assembly: AssemblyProduct("CartPort")]
[assembly: AssemblyTitle("CartPort")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CartPort
{
	internal static class CartPortFusionSession
	{
		private static int _dedupeFrame = -1;

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

		private static readonly HashSet<IntPtr> _inboundFusionCallbacksRegistered = new HashSet<IntPtr>();

		private static bool _loggedInboundFusionCallbacksOnce;

		private static NetworkRunner _cachedRunningRunner;

		private static bool _loggedSummonDroppedNonAuthorityOnce;

		internal static bool IsAuthoritativeServerPeer(NetworkRunner runner)
		{
			//IL_0027: 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_0036: Invalid comparison between Unknown and I4
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Invalid comparison between Unknown and I4
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Invalid comparison between Unknown and I4
			if ((Object)(object)runner == (Object)null || !runner.IsRunning)
			{
				return false;
			}
			try
			{
				if (runner.IsServer)
				{
					return true;
				}
			}
			catch
			{
			}
			GameMode gameMode;
			try
			{
				gameMode = runner.GameMode;
			}
			catch
			{
				return false;
			}
			if ((int)gameMode == 3 || (int)gameMode == 4)
			{
				return true;
			}
			if ((int)gameMode != 2)
			{
				return false;
			}
			try
			{
				if (runner.IsSharedModeMasterClient)
				{
					return true;
				}
			}
			catch
			{
			}
			try
			{
				return LikelyDedicatedSharedRelayPeer(runner);
			}
			catch
			{
				return false;
			}
		}

		private static bool LikelyDedicatedSharedRelayPeer(NetworkRunner runner)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			try
			{
				if ((int)SystemInfo.graphicsDeviceType == 4)
				{
					return true;
				}
			}
			catch
			{
			}
			try
			{
				if (Application.isBatchMode)
				{
					return true;
				}
			}
			catch
			{
			}
			try
			{
				if (runner.IsClient)
				{
					return false;
				}
			}
			catch
			{
				return false;
			}
			return false;
		}

		internal static void TryLogSummonDroppedNonAuthority(NetworkRunner runner, string inboundLabel)
		{
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Expected O, but got Unknown
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			if (_loggedSummonDroppedNonAuthorityOnce)
			{
				return;
			}
			_loggedSummonDroppedNonAuthorityOnce = true;
			bool flag = default(bool);
			try
			{
				string value = "?";
				try
				{
					GameMode gameMode = runner.GameMode;
					value = ((object)(GameMode)(ref gameMode)).ToString();
				}
				catch
				{
				}
				string value2 = "?";
				string value3 = "?";
				string value4 = "?";
				try
				{
					flag = runner.IsServer;
					value2 = flag.ToString();
				}
				catch
				{
				}
				try
				{
					flag = runner.IsClient;
					value3 = flag.ToString();
				}
				catch
				{
				}
				try
				{
					flag = runner.IsSharedModeMasterClient;
					value4 = flag.ToString();
				}
				catch
				{
				}
				string value5 = "?";
				string value6 = "?";
				try
				{
					flag = Application.isBatchMode;
					value5 = flag.ToString();
				}
				catch
				{
				}
				try
				{
					GraphicsDeviceType graphicsDeviceType = SystemInfo.graphicsDeviceType;
					value6 = ((object)(GraphicsDeviceType)(ref graphicsDeviceType)).ToString();
				}
				catch
				{
				}
				CartPortPlugin.Log.LogWarning((object)($"CartPort: CPRT summon ReliableData ignored — this peer is not treated as summon authority ({inboundLabel}). GameMode={value} IsServer={value2} IsClient={value3} IsSharedModeMasterClient={value4} BatchMode={value5} GraphicsDeviceType={value6}. " + "If this is the dedicated server, widen IsAuthoritativeServerPeer or enable Simulation socket + diagnostics."));
			}
			catch (Exception ex)
			{
				ManualLogSource log = CartPortPlugin.Log;
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(46, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CartPort: summon non-authority diag failed (");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(").");
				}
				log.LogWarning(val);
			}
		}

		internal static bool TrySummonAuthoritative(Structure structure, Vector3 position, Quaternion rotation, out bool clientSentReliableAwaitingHost)
		{
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Expected O, but got Unknown
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Expected O, but got Unknown
			//IL_0118: 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_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_0133: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: 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_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			clientSentReliableAwaitingHost = false;
			if (!CartPortPlugin.ServerAuthoritativeSummon.Value)
			{
				return false;
			}
			NetworkRunner val = TryGetRunningRunner();
			if ((Object)(object)val == (Object)null || !val.IsRunning)
			{
				return false;
			}
			NetworkObject val2 = ((Component)structure).GetComponent<NetworkObject>() ?? ((Component)structure).GetComponentInParent<NetworkObject>();
			if (!((Object)(object)val2 == (Object)null))
			{
				NetworkId id = val2.Id;
				if (((NetworkId)(ref id)).IsValid)
				{
					bool flag2 = default(bool);
					try
					{
						if (val2.HasStateAuthority)
						{
							CartSummon.ApplySummonOnAuthorityImmediate(structure, position, rotation);
							ManualLogSource log = CartPortPlugin.Log;
							bool flag = default(bool);
							BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(83, 0, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("CartPort: Local peer has state authority — applied direct summon (no server relay).");
							}
							log.LogInfo(val3);
							return true;
						}
					}
					catch (Exception ex)
					{
						ManualLogSource log2 = CartPortPlugin.Log;
						BepInExWarningLogInterpolatedStringHandler val4 = new BepInExWarningLogInterpolatedStringHandler(74, 1, ref flag2);
						if (flag2)
						{
							((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("CartPort: HasStateAuthority check failed (");
							((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(ex.Message);
							((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("); continuing normal relay path.");
						}
						log2.LogWarning(val4);
					}
					if (IsAuthoritativeServerPeer(val))
					{
						CartSummon.ApplySummonOnAuthority(structure, position, rotation);
						return true;
					}
					PlayerRef val5 = default(PlayerRef);
					bool flag3 = false;
					try
					{
						val5 = val2.StateAuthority;
						flag3 = ((PlayerRef)(ref val5)).PlayerId >= 0;
					}
					catch
					{
					}
					PlayerRef val6 = default(PlayerRef);
					try
					{
						val6 = val.LocalPlayer;
					}
					catch
					{
					}
					try
					{
						byte[] array = CartPortSummonPayload.Serialize(val2.Id, position, rotation);
						Il2CppStructArray<byte> val7 = new Il2CppStructArray<byte>((long)array.Length);
						for (int i = 0; i < array.Length; i++)
						{
							((Il2CppArrayBase<byte>)(object)val7)[i] = array[i];
						}
						bool flag4 = false;
						if (flag3 && val5 != val6)
						{
							try
							{
								val.SendReliableDataToPlayer(val5, val7);
								flag4 = true;
								ManualLogSource log3 = CartPortPlugin.Log;
								BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(88, 1, ref flag2);
								if (flag2)
								{
									((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("CartPort: Sent summon request directly to state-authority player ");
									((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(((PlayerRef)(ref val5)).PlayerId);
									((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" (Fusion ReliableData).");
								}
								log3.LogInfo(val3);
							}
							catch (Exception ex2)
							{
								ManualLogSource log4 = CartPortPlugin.Log;
								BepInExWarningLogInterpolatedStringHandler val4 = new BepInExWarningLogInterpolatedStringHandler(89, 2, ref flag2);
								if (flag2)
								{
									((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("CartPort: SendReliableDataToPlayer(");
									((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(((PlayerRef)(ref val5)).PlayerId);
									((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(") failed (");
									((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(ex2.Message);
									((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("); falling back to SendReliableDataToServer.");
								}
								log4.LogWarning(val4);
							}
						}
						if (!flag4)
						{
							val.SendReliableDataToServer(val7);
							CartPortPlugin.Log.LogInfo((object)"CartPort: Sent summon request to server/master (Fusion ReliableData). Local prediction will run next.");
						}
						clientSentReliableAwaitingHost = true;
						return true;
					}
					catch (Exception ex3)
					{
						ManualLogSource log5 = CartPortPlugin.Log;
						BepInExWarningLogInterpolatedStringHandler val4 = new BepInExWarningLogInterpolatedStringHandler(74, 1, ref flag2);
						if (flag2)
						{
							((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("CartPort: Fusion ReliableData send failed (");
							((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(ex3.Message);
							((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("); using local summon fallback.");
						}
						log5.LogWarning(val4);
						return false;
					}
				}
			}
			return false;
		}

		internal static void HandleReliableSummonFromSimulation(NetworkRunner runner, PlayerRef player, Il2CppStructArray<byte> dataArray)
		{
			if (!CartPortPlugin.ServerAuthoritativeSummon.Value)
			{
				return;
			}
			if ((Object)(object)runner == (Object)null || !IsAuthoritativeServerPeer(runner))
			{
				if ((Object)(object)runner != (Object)null && dataArray != null && ((Il2CppArrayBase<byte>)(object)dataArray).Length >= CartPortSummonPayload.TotalByteCount && CartPortSummonPayload.HasCartPortMagicPrefix(dataArray))
				{
					TryLogSummonDroppedNonAuthority(runner, "simulation Il2CppStructArray");
				}
			}
			else if (dataArray != null && ((Il2CppArrayBase<byte>)(object)dataArray).Length >= CartPortSummonPayload.TotalByteCount)
			{
				int length = ((Il2CppArrayBase<byte>)(object)dataArray).Length;
				byte[] array = new byte[length];
				for (int i = 0; i < length; i++)
				{
					array[i] = ((Il2CppArrayBase<byte>)(object)dataArray)[i];
				}
				ApplySummonPayloadFromManagedBytes(runner, array, length, "simulation Il2CppStructArray");
			}
		}

		internal static void HandleReliableSummonFromSimulation(NetworkRunner runner, PlayerRef player, ArraySegment<byte> segment)
		{
			if (!CartPortPlugin.ServerAuthoritativeSummon.Value)
			{
				return;
			}
			if ((Object)(object)runner == (Object)null || !IsAuthoritativeServerPeer(runner))
			{
				if ((Object)(object)runner != (Object)null && segment.Count >= CartPortSummonPayload.TotalByteCount && CartPortSummonPayload.HasCartPortMagicPrefix(segment))
				{
					TryLogSummonDroppedNonAuthority(runner, "RunnerCallbacks Il2Cpp ArraySegment");
				}
			}
			else
			{
				if (segment.Count < CartPortSummonPayload.TotalByteCount)
				{
					return;
				}
				Il2CppArrayBase<byte> array = segment.Array;
				if (array != null)
				{
					byte[] array2 = new byte[segment.Count];
					int offset = segment.Offset;
					for (int i = 0; i < segment.Count; i++)
					{
						array2[i] = array[offset + i];
					}
					ApplySummonPayloadFromManagedBytes(runner, array2, segment.Count, "RunnerCallbacks Il2Cpp ArraySegment");
				}
			}
		}

		internal static void HandleReliableSummonFromSimulation(NetworkRunner runner, PlayerRef player, ArraySegment<byte> segment)
		{
			if (!CartPortPlugin.ServerAuthoritativeSummon.Value)
			{
				return;
			}
			if ((Object)(object)runner == (Object)null || !IsAuthoritativeServerPeer(runner))
			{
				if ((Object)(object)runner != (Object)null && segment.Count >= CartPortSummonPayload.TotalByteCount && CartPortSummonPayload.HasCartPortMagicPrefix(segment))
				{
					TryLogSummonDroppedNonAuthority(runner, "RunnerCallbacks System.ArraySegment");
				}
			}
			else if (segment.Count >= CartPortSummonPayload.TotalByteCount)
			{
				byte[] array = new byte[segment.Count];
				segment.AsSpan().CopyTo(array);
				ApplySummonPayloadFromManagedBytes(runner, array, segment.Count, "RunnerCallbacks System.ArraySegment");
			}
		}

		internal static void NotifyRunnerSeen(NetworkRunner runner)
		{
			try
			{
				if ((Object)(object)runner != (Object)null && runner.IsRunning)
				{
					_cachedRunningRunner = runner;
				}
			}
			catch
			{
			}
			TryRegisterInboundFusionCallbacks(runner);
		}

		internal static void TryRegisterInboundFusionCallbacks(NetworkRunner runner)
		{
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Expected O, but got Unknown
			if (!CartPortPlugin.RegisterFusionInboundRunnerCallbacks.Value || !CartPortPlugin.ServerAuthoritativeSummon.Value)
			{
				return;
			}
			CartPortPlugin.EnsureFusionInboundClassInjectorRegistered();
			if (!CartPortPlugin.FusionInboundCallbacksClassInjectorOk || (Object)(object)runner == (Object)null || !runner.IsRunning)
			{
				return;
			}
			IntPtr pointer;
			try
			{
				pointer = ((Il2CppObjectBase)runner).Pointer;
			}
			catch
			{
				return;
			}
			if (!_inboundFusionCallbacksRegistered.Add(pointer))
			{
				return;
			}
			try
			{
				if (CartPortPlugin.FusionInboundCallbacksUseInjectPath)
				{
					INetworkRunnerCallbacks val = ((Il2CppObjectBase)new CartPortInboundFusionCallbacksInjected()).TryCast<INetworkRunnerCallbacks>();
					if (val == null)
					{
						_inboundFusionCallbacksRegistered.Remove(pointer);
						CartPortPlugin.Log.LogWarning((object)"CartPort: TryCast to INetworkRunnerCallbacks failed — AddCallbacks skipped (inject path).");
						return;
					}
					runner.AddCallbacks((INetworkRunnerCallbacks[])(object)new INetworkRunnerCallbacks[1] { val });
				}
				else
				{
					runner.AddCallbacks((INetworkRunnerCallbacks[])(object)new INetworkRunnerCallbacks[1]
					{
						new CartPortInboundFusionCallbacksSubclass()
					});
				}
				if (!_loggedInboundFusionCallbacksOnce)
				{
					_loggedInboundFusionCallbacksOnce = true;
					CartPortPlugin.Log.LogInfo((object)"CartPort: Registered Fusion INetworkRunnerCallbacks (NetworkRunner.AddCallbacks) for summon ReliableData.");
				}
			}
			catch (Exception ex)
			{
				_inboundFusionCallbacksRegistered.Remove(pointer);
				ManualLogSource log = CartPortPlugin.Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(47, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("CartPort: NetworkRunner.AddCallbacks failed (");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(").");
				}
				log.LogWarning(val2);
			}
		}

		private static void ApplySummonPayloadFromManagedBytes(NetworkRunner runner, byte[] tmp, int count, string sourceLabel)
		{
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Expected O, but got Unknown
			//IL_0110: 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_0154: Expected O, but got Unknown
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)runner == (Object)null)
			{
				return;
			}
			int frameCount = Time.frameCount;
			if (frameCount != _dedupeFrame)
			{
				_dedupeFrame = frameCount;
				_dedupePayloadHashes.Clear();
			}
			HashCode hashCode = default(HashCode);
			for (int i = 0; i < count; i++)
			{
				hashCode.Add(tmp[i]);
			}
			int item = hashCode.ToHashCode();
			if (!_dedupePayloadHashes.Add(item) || !CartPortSummonPayload.TryDeserialize(new ArraySegment<byte>(tmp, 0, count), out var networkId, out var position, out var rotation))
			{
				return;
			}
			ManualLogSource log = CartPortPlugin.Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(70, 3, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CartPort: Server received summon ReliableData (");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(sourceLabel);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(") for NetworkId ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint>(networkId.Raw);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" → pos ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Vector3>(position);
			}
			log.LogInfo(val);
			if (!TryResolveNetworkObjectForSummon(runner, networkId, out var netObj) || (Object)(object)netObj == (Object)null)
			{
				ManualLogSource log2 = CartPortPlugin.Log;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(154, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("CartPort: Server could not resolve NetworkId ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<uint>(networkId.Raw);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" for summon (TryFindObject + AOI fallback exhausted). Object may be outside simulation interest on this peer.");
				}
				log2.LogWarning(val2);
				return;
			}
			Structure componentInChildren = ((Component)netObj).GetComponentInChildren<Structure>(true);
			if ((Object)(object)componentInChildren == (Object)null)
			{
				ManualLogSource log3 = CartPortPlugin.Log;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(55, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("CartPort: NetworkObject '");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)netObj).name);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' has no Structure for summon.");
				}
				log3.LogWarning(val2);
				return;
			}
			try
			{
				CartSummon.ApplySummonOnAuthority(componentInChildren, position, rotation);
			}
			catch (Exception ex)
			{
				ManualLogSource log4 = CartPortPlugin.Log;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(34, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("CartPort: Server summon failed (");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(").");
				}
				log4.LogWarning(val2);
			}
		}

		internal static bool TryResolveNetworkObjectForSummon(NetworkRunner runner, NetworkId netId, out NetworkObject netObj)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			netObj = null;
			try
			{
				if (runner.TryFindObject(netId, ref netObj) && (Object)(object)netObj != (Object)null)
				{
					return true;
				}
			}
			catch
			{
				netObj = null;
			}
			try
			{
				foreach (NetworkObject item in Resources.FindObjectsOfTypeAll<NetworkObject>())
				{
					if ((Object)(object)item == (Object)null)
					{
						continue;
					}
					NetworkId id = item.Id;
					if (!((NetworkId)(ref id)).IsValid || item.Id != netId)
					{
						continue;
					}
					try
					{
						if ((Object)(object)item.Runner == (Object)(object)runner)
						{
							netObj = item;
							return true;
						}
					}
					catch
					{
						netObj = item;
						return true;
					}
				}
			}
			catch
			{
			}
			netObj = null;
			return false;
		}

		internal static NetworkRunner TryGetRunningRunner()
		{
			//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)
			try
			{
				if ((Object)(object)_cachedRunningRunner != (Object)null && _cachedRunningRunner.IsRunning && IsAuthoritativeServerPeer(_cachedRunningRunner))
				{
					return _cachedRunningRunner;
				}
			}
			catch
			{
				_cachedRunningRunner = null;
			}
			NetworkRunner val = null;
			NetworkRunner val2 = null;
			NetworkRunner val3 = null;
			foreach (NetworkRunner item in Resources.FindObjectsOfTypeAll<NetworkRunner>())
			{
				if ((Object)(object)item == (Object)null || !item.IsRunning || (Object)(object)((Component)item).gameObject == (Object)null)
				{
					continue;
				}
				if (val3 == null)
				{
					val3 = item;
				}
				try
				{
					if (IsAuthoritativeServerPeer(item) && val == null)
					{
						val = item;
					}
					Scene scene = ((Component)item).gameObject.scene;
					if (((Scene)(ref scene)).IsValid() && val2 == null)
					{
						val2 = item;
					}
				}
				catch
				{
				}
			}
			NetworkRunner val4 = val ?? val2 ?? val3;
			try
			{
				if ((Object)(object)_cachedRunningRunner != (Object)null && _cachedRunningRunner.IsRunning && val4 == null)
				{
					val4 = _cachedRunningRunner;
				}
			}
			catch
			{
				_cachedRunningRunner = null;
			}
			if ((Object)(object)val4 != (Object)null)
			{
				NotifyRunnerSeen(val4);
			}
			return val4;
		}

		internal static NetworkRunner TryGetRunnerForSimulation(Simulation simulation)
		{
			if (simulation == null)
			{
				return null;
			}
			try
			{
				ICallbacks callbacks = simulation.Callbacks;
				if (callbacks != null)
				{
					NetworkRunner val = ((Il2CppObjectBase)callbacks).TryCast<NetworkRunner>();
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
			}
			catch
			{
			}
			foreach (NetworkRunner item in Resources.FindObjectsOfTypeAll<NetworkRunner>())
			{
				if ((Object)(object)item == (Object)null || !item.IsRunning)
				{
					continue;
				}
				try
				{
					if (item.Simulation == simulation)
					{
						return item;
					}
				}
				catch
				{
				}
			}
			return null;
		}
	}
	internal static class CartPortGameplayInputSuspend
	{
		private static Dictionary<InputActionMap, bool> _snapshot;

		internal static bool IsActive => _snapshot != null;

		internal static void Push()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			Pop();
			_snapshot = new Dictionary<InputActionMap, bool>();
			foreach (PlayerInput item in Resources.FindObjectsOfTypeAll<PlayerInput>())
			{
				if ((Object)(object)((item != null) ? item.actions : null) == (Object)null)
				{
					continue;
				}
				Scene scene = ((Component)item).gameObject.scene;
				if (!((Scene)(ref scene)).IsValid())
				{
					continue;
				}
				scene = ((Component)item).gameObject.scene;
				if (!((Scene)(ref scene)).isLoaded)
				{
					continue;
				}
				ReadOnlyArray<InputActionMap> actionMaps = item.actions.actionMaps;
				for (int i = 0; i < actionMaps.Count; i++)
				{
					InputActionMap val = actionMaps[i];
					if (val != null && !_snapshot.ContainsKey(val))
					{
						_snapshot[val] = val.enabled;
					}
				}
			}
			foreach (InputActionAsset item2 in Resources.FindObjectsOfTypeAll<InputActionAsset>())
			{
				if (((item2 != null) ? item2.actionMaps : null) == null)
				{
					continue;
				}
				ReadOnlyArray<InputActionMap> actionMaps2 = item2.actionMaps;
				for (int j = 0; j < actionMaps2.Count; j++)
				{
					InputActionMap val2 = actionMaps2[j];
					if (val2 != null && !_snapshot.ContainsKey(val2))
					{
						_snapshot[val2] = val2.enabled;
					}
				}
			}
			ApplySuspend();
			if (CartPortPlugin.VerboseLogging.Value && _snapshot.Count == 0)
			{
				CartPortPlugin.Log.LogInfo((object)"CartPort: No InputActionMaps found to suspend (camera may still move).");
			}
		}

		internal static void Pop()
		{
			if (_snapshot == null)
			{
				return;
			}
			foreach (KeyValuePair<InputActionMap, bool> item in _snapshot)
			{
				InputActionMap key = item.Key;
				if (key == null)
				{
					continue;
				}
				try
				{
					if (item.Value)
					{
						key.Enable();
					}
					else
					{
						key.Disable();
					}
				}
				catch
				{
				}
			}
			_snapshot = null;
		}

		internal static void ReassertGameplayDisabled()
		{
			if (_snapshot == null)
			{
				return;
			}
			foreach (InputActionMap key in _snapshot.Keys)
			{
				if (key != null && IsGameplayMap(key.name) && key.enabled)
				{
					key.Disable();
				}
			}
		}

		private static void ApplySuspend()
		{
			foreach (InputActionMap key in _snapshot.Keys)
			{
				if (key != null)
				{
					string n = key.name ?? string.Empty;
					if (IsGameplayMap(n))
					{
						key.Disable();
					}
					else if (IsUiLikeMap(n))
					{
						key.Enable();
					}
				}
			}
		}

		private static bool IsGameplayMap(string n)
		{
			if (string.IsNullOrEmpty(n))
			{
				return false;
			}
			if (!n.Contains("Player", StringComparison.OrdinalIgnoreCase) && !n.Contains("Gameplay", StringComparison.OrdinalIgnoreCase) && !n.Contains("Character", StringComparison.OrdinalIgnoreCase) && !n.Contains("Ground", StringComparison.OrdinalIgnoreCase) && !n.Contains("Look", StringComparison.OrdinalIgnoreCase) && !n.Contains("Camera", StringComparison.OrdinalIgnoreCase) && !n.Contains("Aim", StringComparison.OrdinalIgnoreCase))
			{
				return n.Contains("Move", StringComparison.OrdinalIgnoreCase);
			}
			return true;
		}

		private static bool IsUiLikeMap(string n)
		{
			if (string.IsNullOrEmpty(n))
			{
				return false;
			}
			if (!n.Contains("UI", StringComparison.OrdinalIgnoreCase) && !n.Contains("Menu", StringComparison.OrdinalIgnoreCase) && !n.Contains("Interface", StringComparison.OrdinalIgnoreCase) && !n.Contains("Build", StringComparison.OrdinalIgnoreCase))
			{
				return n.Contains("Construct", StringComparison.OrdinalIgnoreCase);
			}
			return true;
		}
	}
	internal static class CartPortGameReliablePatches
	{
		private static bool _attemptedLateDiscover;

		internal static bool DiscoveryComplete { get; private set; }

		internal static int PatchedCallbackMethodCount { get; private set; }

		internal static void TryDiscoverExtended(Harmony harmony)
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			if (harmony == null || PatchedCallbackMethodCount > 0)
			{
				return;
			}
			bool flag = default(bool);
			try
			{
				DiscoveryComplete = false;
				DiscoverInner(harmony);
				ManualLogSource log = CartPortPlugin.Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(83, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CartPort: Extended reliable callback discovery finished (total patched ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(PatchedCallbackMethodCount);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" method(s)).");
				}
				log.LogInfo(val);
				if (PatchedCallbackMethodCount == 0)
				{
					CartPortPlugin.Log.LogWarning((object)"CartPort: Extended discovery still found no OnReliableDataReceived patch targets — inbound summon may rely on Fusion simulation hooks only.");
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = CartPortPlugin.Log;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(58, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("CartPort: Extended reliable callback discovery aborted (");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(").");
				}
				log2.LogError(val2);
			}
		}

		internal static void TryDiscoverLate(Harmony harmony)
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			if (harmony == null || _attemptedLateDiscover || PatchedCallbackMethodCount > 0)
			{
				return;
			}
			_attemptedLateDiscover = true;
			DiscoveryComplete = false;
			bool flag = default(bool);
			try
			{
				DiscoverInner(harmony);
				ManualLogSource log = CartPortPlugin.Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(73, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CartPort: Late reliable callback discovery complete (patched ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(PatchedCallbackMethodCount);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" method(s)).");
				}
				log.LogInfo(val);
			}
			catch (Exception ex)
			{
				DiscoveryComplete = true;
				ManualLogSource log2 = CartPortPlugin.Log;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(54, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("CartPort: Late reliable callback discovery aborted (");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(").");
				}
				log2.LogError(val2);
			}
		}

		internal static void TryDiscover(Harmony harmony)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			if (DiscoveryComplete || harmony == null)
			{
				return;
			}
			try
			{
				DiscoverInner(harmony);
			}
			catch (Exception ex)
			{
				DiscoveryComplete = true;
				ManualLogSource log = CartPortPlugin.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(49, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CartPort: Reliable callback discovery aborted (");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(").");
				}
				log.LogError(val);
			}
		}

		private static void DiscoverInner(Harmony harmony)
		{
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_033f: Expected O, but got Unknown
			//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Expected O, but got Unknown
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Expected O, but got Unknown
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Expected O, but got Unknown
			MethodInfo methodInfo = AccessTools.Method(typeof(CartPortGameReliablePatches), "PostfixIl2CppArraySegment", (Type[])null, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(typeof(CartPortGameReliablePatches), "PostfixSystemArraySegment", (Type[])null, (Type[])null);
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			bool flag2 = default(bool);
			BepInExInfoLogInterpolatedStringHandler val;
			foreach (Assembly assembly in assemblies)
			{
				if (ShouldSkipAssemblyForReliableDiscovery(assembly.GetName().Name))
				{
					continue;
				}
				Type[] types;
				try
				{
					types = assembly.GetTypes();
				}
				catch (ReflectionTypeLoadException ex)
				{
					types = ex.Types;
				}
				Type[] array = types;
				foreach (Type type in array)
				{
					if (type == null || type.IsInterface || type.IsAbstract)
					{
						continue;
					}
					string text = type.Namespace ?? string.Empty;
					if (text.StartsWith("Fusion.", StringComparison.Ordinal) || text.StartsWith("Il2Cpp", StringComparison.Ordinal) || text.StartsWith("CartPort", StringComparison.Ordinal))
					{
						continue;
					}
					MethodInfo[] methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					foreach (MethodInfo methodInfo3 in methods)
					{
						if (methodInfo3.Name.IndexOf("OnReliableDataReceived", StringComparison.Ordinal) < 0)
						{
							continue;
						}
						ParameterInfo[] parameters = methodInfo3.GetParameters();
						if (parameters.Length != 3 || parameters[0].ParameterType.IsByRef || parameters[1].ParameterType.IsByRef || parameters[2].ParameterType.IsByRef || !typeof(NetworkRunner).IsAssignableFrom(parameters[0].ParameterType) || !typeof(PlayerRef).IsAssignableFrom(parameters[1].ParameterType))
						{
							continue;
						}
						Type parameterType = parameters[2].ParameterType;
						string? fullName = parameterType.FullName;
						MethodInfo methodInfo4;
						if (fullName != null && fullName.Contains("Il2CppSystem.ArraySegment", StringComparison.Ordinal))
						{
							methodInfo4 = methodInfo;
						}
						else
						{
							string? fullName2 = parameterType.FullName;
							if (fullName2 == null || !fullName2.Contains("System.ArraySegment", StringComparison.Ordinal))
							{
								continue;
							}
							string? fullName3 = parameterType.FullName;
							if (fullName3 != null && fullName3.Contains("Il2CppSystem", StringComparison.Ordinal))
							{
								continue;
							}
							methodInfo4 = methodInfo2;
						}
						bool flag = false;
						try
						{
							Patches patchInfo = Harmony.GetPatchInfo((MethodBase)methodInfo3);
							if (patchInfo?.Postfixes != null)
							{
								foreach (Patch postfix in patchInfo.Postfixes)
								{
									MethodInfo patchMethod = postfix.PatchMethod;
									if (patchMethod != null && postfix.owner == "com.cartport.aska" && patchMethod.Name == methodInfo4.Name)
									{
										flag = true;
										break;
									}
								}
							}
						}
						catch
						{
						}
						if (flag)
						{
							continue;
						}
						try
						{
							harmony.Patch((MethodBase)methodInfo3, (HarmonyMethod)null, new HarmonyMethod(methodInfo4), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
							PatchedCallbackMethodCount++;
							ManualLogSource log = CartPortPlugin.Log;
							val = new BepInExInfoLogInterpolatedStringHandler(63, 2, ref flag2);
							if (flag2)
							{
								((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CartPort: Harmony postfix on ");
								((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(type.FullName);
								((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
								((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(methodInfo3.Name);
								((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (ReliableData → summon handler).");
							}
							log.LogInfo(val);
						}
						catch (Exception ex2)
						{
							ManualLogSource log2 = CartPortPlugin.Log;
							BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(29, 3, ref flag2);
							if (flag2)
							{
								((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("CartPort: Failed to patch ");
								((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(type.FullName);
								((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(".");
								((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(methodInfo3.Name);
								((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": ");
								((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex2.Message);
							}
							log2.LogWarning(val2);
						}
					}
				}
			}
			DiscoveryComplete = true;
			if (PatchedCallbackMethodCount == 0)
			{
				CartPortPlugin.Log.LogWarning((object)"CartPort: No Assembly-CSharp OnReliableDataReceived methods were patched — dedicated server may still miss summon ReliableData unless Fusion simulation hook fires.");
				return;
			}
			ManualLogSource log3 = CartPortPlugin.Log;
			val = new BepInExInfoLogInterpolatedStringHandler(74, 1, ref flag2);
			if (flag2)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CartPort: Patched ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(PatchedCallbackMethodCount);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" game OnReliableDataReceived method(s) for summon relay.");
			}
			log3.LogInfo(val);
		}

		private static bool ShouldSkipAssemblyForReliableDiscovery(string an)
		{
			if (string.IsNullOrEmpty(an))
			{
				return true;
			}
			if (an.Equals("Assembly-CSharp", StringComparison.Ordinal) || an.IndexOf("Assembly-CSharp", StringComparison.Ordinal) >= 0)
			{
				return false;
			}
			string[] array = new string[17]
			{
				"System", "mscorlib", "netstandard", "UnityEngine", "Unity.", "Fusion.", "Mono.", "Il2CppInterop", "Il2Cppmscorlib", "Il2CppSystem",
				"Il2Cpp", "BepInEx", "HarmonyLib", "CartPort", "Newtonsoft", "Microsoft.", "NuGet"
			};
			foreach (string value in array)
			{
				if (an.StartsWith(value, StringComparison.Ordinal))
				{
					return true;
				}
			}
			return false;
		}

		private static void PostfixIl2CppArraySegment(object __instance, NetworkRunner runner, PlayerRef player, ArraySegment<byte> data)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			CartPortFusionSession.HandleReliableSummonFromSimulation(runner, player, data);
		}

		private static void PostfixSystemArraySegment(object __instance, NetworkRunner runner, PlayerRef player, ArraySegment<byte> data)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			CartPortFusionSession.HandleReliableSummonFromSimulation(runner, player, data);
		}
	}
	[Il2CppImplements(new Type[] { typeof(INetworkRunnerCallbacks) })]
	internal sealed class CartPortInboundFusionCallbacksInjected : Il2CppObjectBase
	{
		internal CartPortInboundFusionCallbacksInjected()
			: base(IL2CPP.il2cpp_object_new(Il2CppClassPointerStore<CartPortInboundFusionCallbacksInjected>.NativeClassPtr))
		{
		}

		internal CartPortInboundFusionCallbacksInjected(IntPtr ptr)
			: base(ptr)
		{
		}

		public void OnReliableDataReceived(NetworkRunner runner, PlayerRef player, ArraySegment<byte> data)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			CartPortFusionSession.HandleReliableSummonFromSimulation(runner, player, data);
		}

		public void OnPlayerJoined(NetworkRunner runner, PlayerRef player)
		{
		}

		public void OnPlayerLeft(NetworkRunner runner, PlayerRef player)
		{
		}

		public void OnInput(NetworkRunner runner, NetworkInput input)
		{
		}

		public void OnInputMissing(NetworkRunner runner, PlayerRef player, NetworkInput input)
		{
		}

		public void OnShutdown(NetworkRunner runner, ShutdownReason shutdownReason)
		{
		}

		public void OnConnectedToServer(NetworkRunner runner)
		{
		}

		public void OnDisconnectedFromServer(NetworkRunner runner)
		{
		}

		public void OnConnectRequest(NetworkRunner runner, ConnectRequest request, Il2CppStructArray<byte> token)
		{
		}

		public void OnConnectFailed(NetworkRunner runner, NetAddress remoteAddress, NetConnectFailedReason reason)
		{
		}

		public void OnUserSimulationMessage(NetworkRunner runner, SimulationMessagePtr message)
		{
		}

		public void OnSessionListUpdated(NetworkRunner runner, List<SessionInfo> sessionList)
		{
		}

		public void OnCustomAuthenticationResponse(NetworkRunner runner, Dictionary<string, Object> data)
		{
		}

		public void OnHostMigration(NetworkRunner runner, HostMigrationToken hostMigrationToken)
		{
		}

		public void OnSceneLoadDone(NetworkRunner runner)
		{
		}

		public void OnSceneLoadStart(NetworkRunner runner)
		{
		}
	}
	internal sealed class CartPortInboundFusionCallbacksSubclass : INetworkRunnerCallbacks
	{
		internal CartPortInboundFusionCallbacksSubclass()
			: base(IL2CPP.il2cpp_object_new(Il2CppClassPointerStore<CartPortInboundFusionCallbacksSubclass>.NativeClassPtr))
		{
		}

		internal CartPortInboundFusionCallbacksSubclass(IntPtr ptr)
			: base(ptr)
		{
		}

		public override void OnReliableDataReceived(NetworkRunner runner, PlayerRef player, ArraySegment<byte> data)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			CartPortFusionSession.HandleReliableSummonFromSimulation(runner, player, data);
		}

		public override void OnPlayerJoined(NetworkRunner runner, PlayerRef player)
		{
		}

		public override void OnPlayerLeft(NetworkRunner runner, PlayerRef player)
		{
		}

		public override void OnInput(NetworkRunner runner, NetworkInput input)
		{
		}

		public override void OnInputMissing(NetworkRunner runner, PlayerRef player, NetworkInput input)
		{
		}

		public override void OnShutdown(NetworkRunner runner, ShutdownReason shutdownReason)
		{
		}

		public override void OnConnectedToServer(NetworkRunner runner)
		{
		}

		public override void OnDisconnectedFromServer(NetworkRunner runner)
		{
		}

		public override void OnConnectRequest(NetworkRunner runner, ConnectRequest request, Il2CppStructArray<byte> token)
		{
		}

		public override void OnConnectFailed(NetworkRunner runner, NetAddress remoteAddress, NetConnectFailedReason reason)
		{
		}

		public override void OnUserSimulationMessage(NetworkRunner runner, SimulationMessagePtr message)
		{
		}

		public override void OnSessionListUpdated(NetworkRunner runner, List<SessionInfo> sessionList)
		{
		}

		public override void OnCustomAuthenticationResponse(NetworkRunner runner, Dictionary<string, Object> data)
		{
		}

		public override void OnHostMigration(NetworkRunner runner, HostMigrationToken hostMigrationToken)
		{
		}

		public override void OnSceneLoadDone(NetworkRunner runner)
		{
		}

		public override void OnSceneLoadStart(NetworkRunner runner)
		{
		}
	}
	internal static class CartPortInput
	{
		internal static Vector2 MouseGuiPosition()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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)
			Mouse current = Mouse.current;
			if (current != null)
			{
				Vector2 val = ((InputControl<Vector2>)(object)((Pointer)current).position).ReadValue();
				return new Vector2(val.x, (float)Screen.height - val.y);
			}
			Vector3 mousePosition = Input.mousePosition;
			return new Vector2(mousePosition.x, (float)Screen.height - mousePosition.y);
		}

		internal static bool WasLeftClickPressed()
		{
			Mouse current = Mouse.current;
			if (current != null && current.leftButton.wasPressedThisFrame)
			{
				return true;
			}
			return Input.GetMouseButtonDown(0);
		}

		internal static bool GetKeyDown(KeyCode code)
		{
			//IL_001e: 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)
			Keyboard current = Keyboard.current;
			if (current != null && TryGetKeyControl(current, code, out var ctrl) && ((ButtonControl)ctrl).wasPressedThisFrame)
			{
				return true;
			}
			return Input.GetKeyDown(code);
		}

		internal static bool WasDigitRowPressed(int digit1To9)
		{
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			if ((digit1To9 < 1 || digit1To9 > 9) ? true : false)
			{
				return false;
			}
			Keyboard current = Keyboard.current;
			if (current != null)
			{
				KeyControl val = (KeyControl)(digit1To9 switch
				{
					1 => current.digit1Key, 
					2 => current.digit2Key, 
					3 => current.digit3Key, 
					4 => current.digit4Key, 
					5 => current.digit5Key, 
					6 => current.digit6Key, 
					7 => current.digit7Key, 
					8 => current.digit8Key, 
					9 => current.digit9Key, 
					_ => null, 
				});
				if (val != null && ((ButtonControl)val).wasPressedThisFrame)
				{
					return true;
				}
			}
			KeyCode? val2 = DigitToAlphaKeyCode(digit1To9);
			if (val2.HasValue)
			{
				return Input.GetKeyDown(val2.Value);
			}
			return false;
		}

		private static KeyCode? DigitToAlphaKeyCode(int d)
		{
			return d switch
			{
				1 => (KeyCode)49, 
				2 => (KeyCode)50, 
				3 => (KeyCode)51, 
				4 => (KeyCode)52, 
				5 => (KeyCode)53, 
				6 => (KeyCode)54, 
				7 => (KeyCode)55, 
				8 => (KeyCode)56, 
				9 => (KeyCode)57, 
				_ => null, 
			};
		}

		private static bool TryGetKeyControl(Keyboard kb, KeyCode code, out KeyControl ctrl)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Invalid comparison between Unknown and I4
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_0065: 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_00da: Expected I4, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Invalid comparison between Unknown and I4
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Expected I4, but got Unknown
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected I4, but got Unknown
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			KeyControl val;
			if ((int)code <= 27)
			{
				if ((int)code != 9)
				{
					if ((int)code != 13)
					{
						if ((int)code != 27)
						{
							goto IL_03d1;
						}
						val = kb.escapeKey;
					}
					else
					{
						val = kb.enterKey;
					}
				}
				else
				{
					val = kb.tabKey;
				}
			}
			else if ((int)code <= 57)
			{
				if ((int)code != 32)
				{
					switch (code - 48)
					{
					case 0:
						break;
					case 1:
						goto IL_029f;
					case 2:
						goto IL_02ab;
					case 3:
						goto IL_02b7;
					case 4:
						goto IL_02c3;
					case 5:
						goto IL_02cf;
					case 6:
						goto IL_02db;
					case 7:
						goto IL_02e7;
					case 8:
						goto IL_02f3;
					case 9:
						goto IL_02ff;
					default:
						goto IL_03d1;
					}
					val = kb.digit0Key;
				}
				else
				{
					val = kb.spaceKey;
				}
			}
			else
			{
				switch (code - 96)
				{
				case 0:
					goto IL_014f;
				case 1:
					goto IL_015b;
				case 2:
					goto IL_0167;
				case 3:
					goto IL_0173;
				case 4:
					goto IL_017f;
				case 5:
					goto IL_018b;
				case 6:
					goto IL_0197;
				case 7:
					goto IL_01a3;
				case 8:
					goto IL_01af;
				case 9:
					goto IL_01bb;
				case 10:
					goto IL_01c7;
				case 11:
					goto IL_01d3;
				case 12:
					goto IL_01df;
				case 13:
					goto IL_01eb;
				case 14:
					goto IL_01f7;
				case 15:
					goto IL_0203;
				case 16:
					goto IL_020f;
				case 17:
					goto IL_021b;
				case 18:
					goto IL_0227;
				case 19:
					goto IL_0233;
				case 20:
					goto IL_023f;
				case 21:
					goto IL_024b;
				case 22:
					goto IL_0257;
				case 23:
					goto IL_0263;
				case 24:
					goto IL_026f;
				case 25:
					goto IL_027b;
				case 26:
					goto IL_0287;
				}
				switch (code - 282)
				{
				case 0:
					break;
				case 1:
					goto IL_0323;
				case 2:
					goto IL_032f;
				case 3:
					goto IL_033b;
				case 4:
					goto IL_0347;
				case 5:
					goto IL_0353;
				case 6:
					goto IL_035c;
				case 7:
					goto IL_0365;
				case 8:
					goto IL_036e;
				case 9:
					goto IL_0377;
				case 10:
					goto IL_0380;
				case 11:
					goto IL_0389;
				case 22:
					goto IL_03a4;
				case 21:
					goto IL_03ad;
				case 24:
					goto IL_03b6;
				case 23:
					goto IL_03bf;
				default:
					goto IL_03d1;
				}
				val = kb.f1Key;
			}
			goto IL_03d3;
			IL_01df:
			val = kb.lKey;
			goto IL_03d3;
			IL_01c7:
			val = kb.jKey;
			goto IL_03d3;
			IL_01af:
			val = kb.hKey;
			goto IL_03d3;
			IL_0197:
			val = kb.fKey;
			goto IL_03d3;
			IL_01a3:
			val = kb.gKey;
			goto IL_03d3;
			IL_01bb:
			val = kb.iKey;
			goto IL_03d3;
			IL_01d3:
			val = kb.kKey;
			goto IL_03d3;
			IL_018b:
			val = kb.eKey;
			goto IL_03d3;
			IL_0173:
			val = kb.cKey;
			goto IL_03d3;
			IL_02ff:
			val = kb.digit9Key;
			goto IL_03d3;
			IL_02f3:
			val = kb.digit8Key;
			goto IL_03d3;
			IL_02e7:
			val = kb.digit7Key;
			goto IL_03d3;
			IL_02db:
			val = kb.digit6Key;
			goto IL_03d3;
			IL_02cf:
			val = kb.digit5Key;
			goto IL_03d3;
			IL_02c3:
			val = kb.digit4Key;
			goto IL_03d3;
			IL_02b7:
			val = kb.digit3Key;
			goto IL_03d3;
			IL_02ab:
			val = kb.digit2Key;
			goto IL_03d3;
			IL_029f:
			val = kb.digit1Key;
			goto IL_03d3;
			IL_015b:
			val = kb.aKey;
			goto IL_03d3;
			IL_0167:
			val = kb.bKey;
			goto IL_03d3;
			IL_017f:
			val = kb.dKey;
			goto IL_03d3;
			IL_014f:
			val = kb.backquoteKey;
			goto IL_03d3;
			IL_03b6:
			val = kb.leftCtrlKey;
			goto IL_03d3;
			IL_03bf:
			val = kb.rightCtrlKey;
			goto IL_03d3;
			IL_03a4:
			val = kb.leftShiftKey;
			goto IL_03d3;
			IL_03ad:
			val = kb.rightShiftKey;
			goto IL_03d3;
			IL_03d1:
			val = null;
			goto IL_03d3;
			IL_0389:
			val = kb.f12Key;
			goto IL_03d3;
			IL_0380:
			val = kb.f11Key;
			goto IL_03d3;
			IL_0377:
			val = kb.f10Key;
			goto IL_03d3;
			IL_036e:
			val = kb.f9Key;
			goto IL_03d3;
			IL_0365:
			val = kb.f8Key;
			goto IL_03d3;
			IL_035c:
			val = kb.f7Key;
			goto IL_03d3;
			IL_0353:
			val = kb.f6Key;
			goto IL_03d3;
			IL_0347:
			val = kb.f5Key;
			goto IL_03d3;
			IL_033b:
			val = kb.f4Key;
			goto IL_03d3;
			IL_032f:
			val = kb.f3Key;
			goto IL_03d3;
			IL_0323:
			val = kb.f2Key;
			goto IL_03d3;
			IL_03d3:
			ctrl = val;
			return ctrl != null;
			IL_0287:
			val = kb.zKey;
			goto IL_03d3;
			IL_027b:
			val = kb.yKey;
			goto IL_03d3;
			IL_026f:
			val = kb.xKey;
			goto IL_03d3;
			IL_0263:
			val = kb.wKey;
			goto IL_03d3;
			IL_0257:
			val = kb.vKey;
			goto IL_03d3;
			IL_024b:
			val = kb.uKey;
			goto IL_03d3;
			IL_023f:
			val = kb.tKey;
			goto IL_03d3;
			IL_0233:
			val = kb.sKey;
			goto IL_03d3;
			IL_0227:
			val = kb.rKey;
			goto IL_03d3;
			IL_021b:
			val = kb.qKey;
			goto IL_03d3;
			IL_020f:
			val = kb.pKey;
			goto IL_03d3;
			IL_0203:
			val = kb.oKey;
			goto IL_03d3;
			IL_01f7:
			val = kb.nKey;
			goto IL_03d3;
			IL_01eb:
			val = kb.mKey;
			goto IL_03d3;
		}
	}
	[HarmonyPatch(typeof(NetworkRunner), "Fusion_Simulation_ICallbacks_OnReliableData")]
	internal static class NetworkRunner_OnReliableData_Patch
	{
		[HarmonyPrepare]
		private static bool Prepare()
		{
			try
			{
				return CartPortPlugin.EnableHarmonyFusionReliablePatches.Value;
			}
			catch
			{
				return false;
			}
		}

		private static bool Prefix(NetworkRunner __instance, PlayerRef player, Il2CppStructArray<byte> dataArray)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			CartPortFusionSession.NotifyRunnerSeen(__instance);
			if (dataArray != null && ((Il2CppArrayBase<byte>)(object)dataArray).Length >= CartPortSummonPayload.TotalByteCount && CartPortSummonPayload.HasCartPortMagicPrefix(dataArray))
			{
				CartPortFusionSession.HandleReliableSummonFromSimulation(__instance, player, dataArray);
				return false;
			}
			return true;
		}
	}
	internal static class CartPortPersistentSummonOverride
	{
		private sealed class OverrideEntry
		{
			internal Structure Structure;

			internal Vector3 TargetPos;

			internal Quaternion TargetRot;

			internal int ExpiryFrame;

			internal int ApplyCount;
		}

		private static readonly List<OverrideEntry> _active = new List<OverrideEntry>();

		private const float ArrivalThreshold = 3f;

		internal static bool IsActive(Structure structure)
		{
			foreach (OverrideEntry item in _active)
			{
				if ((Object)(object)item.Structure == (Object)(object)structure)
				{
					return true;
				}
			}
			return false;
		}

		internal static void AddOrRefresh(Structure structure, Vector3 pos, Quaternion rot, int durationFrames)
		{
			//IL_0027: 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_002e: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_00c6: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			bool flag = default(bool);
			foreach (OverrideEntry item in _active)
			{
				if (!((Object)(object)item.Structure != (Object)(object)structure))
				{
					item.TargetPos = pos;
					item.TargetRot = rot;
					item.ExpiryFrame = Time.frameCount + durationFrames;
					ManualLogSource log = CartPortPlugin.Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(57, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CartPort: Persistent override refreshed for '");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)((Component)structure).gameObject).name);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' (");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(durationFrames);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" frames).");
					}
					log.LogInfo(val);
					return;
				}
			}
			_active.Add(new OverrideEntry
			{
				Structure = structure,
				TargetPos = pos,
				TargetRot = rot,
				ExpiryFrame = Time.frameCount + durationFrames
			});
			CartPortPlugin.Log.LogInfo((object)($"CartPort: Persistent override started for '{((Object)((Component)structure).gameObject).name}' ({durationFrames} frames). " + "Will re-apply transform every frame to fight Fusion sync."));
		}

		internal static void Cancel(Structure structure)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			bool flag = default(bool);
			for (int num = _active.Count - 1; num >= 0; num--)
			{
				if (!((Object)(object)_active[num].Structure != (Object)(object)structure))
				{
					ManualLogSource log = CartPortPlugin.Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(47, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CartPort: Persistent override cancelled for '");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)((Component)structure).gameObject).name);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'.");
					}
					log.LogInfo(val);
					_active.RemoveAt(num);
				}
			}
		}

		internal static void CancelAll()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			if (_active.Count > 0)
			{
				ManualLogSource log = CartPortPlugin.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(48, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CartPort: All ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(_active.Count);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" persistent override(s) cancelled.");
				}
				log.LogInfo(val);
				_active.Clear();
			}
		}

		internal static void Tick()
		{
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_0183: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			if (_active.Count == 0)
			{
				return;
			}
			bool flag = default(bool);
			for (int num = _active.Count - 1; num >= 0; num--)
			{
				OverrideEntry overrideEntry = _active[num];
				if ((Object)(object)overrideEntry.Structure == (Object)null)
				{
					_active.RemoveAt(num);
				}
				else if (Time.frameCount > overrideEntry.ExpiryFrame)
				{
					ManualLogSource log = CartPortPlugin.Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(120, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CartPort: Persistent override expired for '");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)((Component)overrideEntry.Structure).gameObject).name);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' ");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("after ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(overrideEntry.ApplyCount);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" re-applications — cart may be held by an unreachable authority peer.");
					}
					log.LogInfo(val);
					_active.RemoveAt(num);
				}
				else if (Vector3.Distance(((Component)overrideEntry.Structure).transform.position, overrideEntry.TargetPos) < 3f)
				{
					ManualLogSource log2 = CartPortPlugin.Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(89, 3, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CartPort: Persistent override succeeded for '");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)((Component)overrideEntry.Structure).gameObject).name);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' ");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("(arrived within ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(3f);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("m after ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(overrideEntry.ApplyCount);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" re-applications).");
					}
					log2.LogInfo(val);
					_active.RemoveAt(num);
				}
				else
				{
					CartSummon.BruteForceApplyTransform(overrideEntry.Structure, overrideEntry.TargetPos, overrideEntry.TargetRot);
					overrideEntry.ApplyCount++;
				}
			}
		}
	}
	internal static class CartPortServerSummonQueue
	{
		private sealed class Entry
		{
			internal NetworkId NetId;

			internal Vector3 Pos;

			internal Quaternion Rot;

			internal int DeadlineFrame;

			internal int LastAuthorityRequestFrame = -99999;
		}

		private static readonly List<Entry> Pending = new List<Entry>();

		internal static void Enqueue(NetworkId netId, Vector3 pos, Quaternion rot)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			int deadlineFrame = Time.frameCount + Mathf.Max(30, CartPortPlugin.ServerSummonAuthorityWaitFrames.Value);
			bool flag = default(bool);
			for (int i = 0; i < Pending.Count; i++)
			{
				if (Pending[i].NetId == netId)
				{
					Pending[i].Pos = pos;
					Pending[i].Rot = rot;
					Pending[i].DeadlineFrame = deadlineFrame;
					ManualLogSource log = CartPortPlugin.Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(84, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CartPort: Updated queued server summon for NetworkId ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint>(netId.Raw);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (waiting for state authority).");
					}
					log.LogInfo(val);
					return;
				}
			}
			Pending.Add(new Entry
			{
				NetId = netId,
				Pos = pos,
				Rot = rot,
				DeadlineFrame = deadlineFrame
			});
		}

		internal static void Tick()
		{
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0351: Expected O, but got Unknown
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Expected O, but got Unknown
			//IL_0057: 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_007f: Expected O, but got Unknown
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Expected O, but got Unknown
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Expected O, but got Unknown
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Expected O, but got Unknown
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Expected O, but got Unknown
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			if (Pending.Count == 0)
			{
				return;
			}
			NetworkRunner val = CartPortFusionSession.TryGetRunningRunner();
			if ((Object)(object)val == (Object)null || !val.IsRunning || !CartPortFusionSession.IsAuthoritativeServerPeer(val))
			{
				Pending.Clear();
				return;
			}
			bool flag = default(bool);
			for (int num = Pending.Count - 1; num >= 0; num--)
			{
				Entry entry = Pending[num];
				if (!CartPortFusionSession.TryResolveNetworkObjectForSummon(val, entry.NetId, out var netObj) || (Object)(object)netObj == (Object)null)
				{
					ManualLogSource log = CartPortPlugin.Log;
					BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(62, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("CartPort: Queued summon dropped — NetworkId ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<uint>(entry.NetId.Raw);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" no longer exists.");
					}
					log.LogWarning(val2);
					Pending.RemoveAt(num);
				}
				else if (netObj.HasStateAuthority)
				{
					Structure componentInChildren = ((Component)netObj).GetComponentInChildren<Structure>(true);
					if ((Object)(object)componentInChildren == (Object)null)
					{
						ManualLogSource log2 = CartPortPlugin.Log;
						BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(61, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("CartPort: Queued summon dropped — no Structure on NetworkId ");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<uint>(entry.NetId.Raw);
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(".");
						}
						log2.LogWarning(val2);
						Pending.RemoveAt(num);
					}
					else
					{
						CartSummon.ApplySummonOnAuthorityImmediate(componentInChildren, entry.Pos, entry.Rot);
						ManualLogSource log3 = CartPortPlugin.Log;
						BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(84, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("CartPort: Applied queued server summon for NetworkId ");
							((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<uint>(entry.NetId.Raw);
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" after state authority arrived.");
						}
						log3.LogInfo(val3);
						Pending.RemoveAt(num);
					}
				}
				else if (Time.frameCount > entry.DeadlineFrame)
				{
					if (CartPortPlugin.ServerSummonUnityPhysicsFallbackAfterQueueTimeout.Value)
					{
						Structure componentInChildren2 = ((Component)netObj).GetComponentInChildren<Structure>(true);
						if ((Object)(object)componentInChildren2 != (Object)null)
						{
							ManualLogSource log4 = CartPortPlugin.Log;
							BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(141, 1, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("CartPort: Queued summon timed out for NetworkId ");
								((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<uint>(entry.NetId.Raw);
								((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" — applying Unity physics fallback (ocean / carts Fusion never hands authority to this peer).");
							}
							log4.LogWarning(val2);
							CartSummon.ApplySummonOnAuthorityImmediate(componentInChildren2, entry.Pos, entry.Rot);
							if (CartPortPlugin.ForceSummonServerQueueFallbackPersist.Value)
							{
								CartPortPersistentSummonOverride.AddOrRefresh(componentInChildren2, entry.Pos, entry.Rot, CartPortPlugin.ForceSummonPersistDurationFrames.Value);
							}
						}
						else
						{
							ManualLogSource log5 = CartPortPlugin.Log;
							BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(107, 1, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("CartPort: Queued summon timed out — never gained state authority for NetworkId ");
								((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<uint>(entry.NetId.Raw);
								((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(". No Structure for fallback.");
							}
							log5.LogWarning(val2);
						}
					}
					else
					{
						ManualLogSource log6 = CartPortPlugin.Log;
						BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(143, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("CartPort: Queued summon timed out — never gained state authority for NetworkId ");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<uint>(entry.NetId.Raw);
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(". Cart may stay stuck until Fusion releases authority elsewhere.");
						}
						log6.LogWarning(val2);
					}
					Pending.RemoveAt(num);
				}
				else
				{
					int num2 = Mathf.Max(5, CartPortPlugin.ServerSummonAuthorityRetryIntervalFrames.Value);
					if (Time.frameCount - entry.LastAuthorityRequestFrame >= num2)
					{
						if (CartPortPlugin.ServerAllowAuthorityOverrideOnSummon.Value)
						{
							try
							{
								netObj.AllowStateAuthorityOverride = true;
							}
							catch (Exception ex)
							{
								ManualLogSource log7 = CartPortPlugin.Log;
								BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(41, 1, ref flag);
								if (flag)
								{
									((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("CartPort: AllowStateAuthorityOverride (");
									((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
									((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(").");
								}
								log7.LogWarning(val2);
							}
						}
						try
						{
							netObj.RequestStateAuthority();
						}
						catch (Exception ex2)
						{
							ManualLogSource log8 = CartPortPlugin.Log;
							BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(42, 1, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("CartPort: RequestStateAuthority failed (");
								((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex2.Message);
								((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(").");
							}
							log8.LogWarning(val2);
						}
						entry.LastAuthorityRequestFrame = Time.frameCount;
					}
				}
			}
		}
	}
	internal static class CartPortSummonPayload
	{
		private static readonly byte[] MagicBytes = new byte[4] { 67, 80, 82, 84 };

		private const byte Version = 1;

		private const int InnerByteCount = 33;

		internal static int TotalByteCount => MagicBytes.Length + 33;

		internal static bool HasCartPortMagicPrefix(byte[] buf, int count)
		{
			return HasCartPortMagicPrefix(buf, 0, count);
		}

		internal static bool HasCartPortMagicPrefix(byte[] buf, int offset, int count)
		{
			if (buf == null || count < MagicBytes.Length || offset < 0 || offset + MagicBytes.Length > buf.Length)
			{
				return false;
			}
			for (int i = 0; i < MagicBytes.Length; i++)
			{
				if (buf[offset + i] != MagicBytes[i])
				{
					return false;
				}
			}
			return true;
		}

		internal static bool HasCartPortMagicPrefix(ArraySegment<byte> segment)
		{
			if (segment.Count < MagicBytes.Length)
			{
				return false;
			}
			Il2CppArrayBase<byte> array = segment.Array;
			if (array == null)
			{
				return false;
			}
			int offset = segment.Offset;
			for (int i = 0; i < MagicBytes.Length; i++)
			{
				if (array[offset + i] != MagicBytes[i])
				{
					return false;
				}
			}
			return true;
		}

		internal static bool HasCartPortMagicPrefix(ArraySegment<byte> segment)
		{
			if (segment.Count < MagicBytes.Length || segment.Array == null)
			{
				return false;
			}
			byte[] array = segment.Array;
			int offset = segment.Offset;
			for (int i = 0; i < MagicBytes.Length; i++)
			{
				if (array[offset + i] != MagicBytes[i])
				{
					return false;
				}
			}
			return true;
		}

		internal static bool HasCartPortMagicPrefix(Il2CppStructArray<byte> data)
		{
			if (data == null || ((Il2CppArrayBase<byte>)(object)data).Length < MagicBytes.Length)
			{
				return false;
			}
			for (int i = 0; i < MagicBytes.Length; i++)
			{
				if (((Il2CppArrayBase<byte>)(object)data)[i] != MagicBytes[i])
				{
					return false;
				}
			}
			return true;
		}

		internal static byte[] Serialize(NetworkId networkId, Vector3 position, Quaternion rotation)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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)
			byte[] array = new byte[TotalByteCount];
			MagicBytes.CopyTo(array.AsSpan());
			int num = MagicBytes.Length;
			array[num] = 1;
			BinaryPrimitives.WriteUInt32LittleEndian(array.AsSpan(num + 1), networkId.Raw);
			int num2 = num + 5;
			BinaryPrimitives.WriteSingleLittleEndian(array.AsSpan(num2), position.x);
			BinaryPrimitives.WriteSingleLittleEndian(array.AsSpan(num2 + 4), position.y);
			BinaryPrimitives.WriteSingleLittleEndian(array.AsSpan(num2 + 8), position.z);
			num2 += 12;
			BinaryPrimitives.WriteSingleLittleEndian(array.AsSpan(num2), rotation.x);
			BinaryPrimitives.WriteSingleLittleEndian(array.AsSpan(num2 + 4), rotation.y);
			BinaryPrimitives.WriteSingleLittleEndian(array.AsSpan(num2 + 8), rotation.z);
			BinaryPrimitives.WriteSingleLittleEndian(array.AsSpan(num2 + 12), rotation.w);
			return array;
		}

		internal static bool TryDeserialize(ArraySegment<byte> data, out NetworkId networkId, out Vector3 position, out Quaternion rotation)
		{
			//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_000f: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			networkId = default(NetworkId);
			position = default(Vector3);
			rotation = default(Quaternion);
			if (data.Count < TotalByteCount || data.Array == null)
			{
				return false;
			}
			byte[] array = data.Array;
			int offset = data.Offset;
			for (int i = 0; i < MagicBytes.Length; i++)
			{
				if (array[offset + i] != MagicBytes[i])
				{
					return false;
				}
			}
			offset += MagicBytes.Length;
			if (array[offset] != 1)
			{
				return false;
			}
			uint raw = BinaryPrimitives.ReadUInt32LittleEndian(array.AsSpan(offset + 1));
			networkId = new NetworkId
			{
				Raw = raw
			};
			int num = offset + 5;
			position = new Vector3(BinaryPrimitives.ReadSingleLittleEndian(array.AsSpan(num)), BinaryPrimitives.ReadSingleLittleEndian(array.AsSpan(num + 4)), BinaryPrimitives.ReadSingleLittleEndian(array.AsSpan(num + 8)));
			num += 12;
			rotation = new Quaternion(BinaryPrimitives.ReadSingleLittleEndian(array.AsSpan(num)), BinaryPrimitives.ReadSingleLittleEndian(array.AsSpan(num + 4)), BinaryPrimitives.ReadSingleLittleEndian(array.AsSpan(num + 8)), BinaryPrimitives.ReadSingleLittleEndian(array.AsSpan(num + 12)));
			return true;
		}
	}
	public class CartPortUiBehaviour : MonoBehaviour
	{
		private bool _menuVisible;

		private readonly List<Structure> _structures = new List<Structure>();

		private GUIStyle _wrappedLabelStyle;

		private CursorLockMode _savedCursorLockMode;

		private bool _savedCursorVisible;

		private bool _haveSavedCursor;

		private Rect _panelRect;

		private readonly List<(Rect rect, Structure structure)> _summonRects = new List<(Rect, Structure)>();

		private Rect _refreshRect;

		private Rect _forceModeRect;

		private Rect _closeRect;

		private bool _forceMode;

		private int _deferSummonDueFrame = -1;

		private Structure _deferSummonStructure;

		private Vector3 _deferSummonPos;

		private Quaternion _deferSummonRot;

		private bool _deferSummonClientPredictionAfterServerRelay;

		internal static CartPortUiBehaviour Instance { get; private set; }

		private GUIStyle WrappedLabelStyle
		{
			get
			{
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Expected O, but got Unknown
				//IL_0028: Expected O, but got Unknown
				GUIStyle obj = _wrappedLabelStyle;
				if (obj == null)
				{
					GUIStyle val = new GUIStyle(GUI.skin.label)
					{
						wordWrap = true
					};
					GUIStyle val2 = val;
					_wrappedLabelStyle = val;
					obj = val2;
				}
				return obj;
			}
		}

		private void Awake()
		{
			Instance = this;
			((Behaviour)this).enabled = true;
		}

		private void Start()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			CartPortPlugin.EnsureFusionInboundClassInjectorRegistered();
			try
			{
				if (CartPortPlugin.EnableHarmonyFusionReliablePatches.Value && CartPortPlugin.PatchAssemblyCSharpReliableCallbacks.Value)
				{
					CartPortGameReliablePatches.TryDiscover(CartPortPlugin.HarmonyInstance);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = CartPortPlugin.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(48, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CartPort: Reliable callback discovery failed (");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(").");
				}
				log.LogError(val);
			}
			((MonoBehaviour)this).Invoke("LateDiscoverGameReliableCallbacks", 5f);
			((MonoBehaviour)this).Invoke("ExtendedDiscoverGameReliableCallbacks", 25f);
		}

		private void LateDiscoverGameReliableCallbacks()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			try
			{
				if (CartPortPlugin.EnableHarmonyFusionReliablePatches.Value && CartPortPlugin.PatchAssemblyCSharpReliableCallbacks.Value)
				{
					CartPortGameReliablePatches.TryDiscoverLate(CartPortPlugin.HarmonyInstance);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = CartPortPlugin.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(53, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CartPort: Late reliable callback discovery failed (");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(").");
				}
				log.LogError(val);
			}
		}

		private void ExtendedDiscoverGameReliableCallbacks()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			try
			{
				if (CartPortPlugin.EnableHarmonyFusionReliablePatches.Value && CartPortPlugin.PatchAssemblyCSharpReliableCallbacks.Value)
				{
					CartPortGameReliablePatches.TryDiscoverExtended(CartPortPlugin.HarmonyInstance);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = CartPortPlugin.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(57, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CartPort: Extended reliable callback discovery failed (");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(").");
				}
				log.LogError(val);
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}

		private void Update()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			CartPortServerSummonQueue.Tick();
			CartPortPersistentSummonOverride.Tick();
			if (CartPortInput.GetKeyDown(CartPortPlugin.ToggleMenuKey.Value))
			{
				SetMenuVisible(!_menuVisible);
			}
			if (_menuVisible && CartPortInput.GetKeyDown((KeyCode)27))
			{
				SetMenuVisible(visible: false);
			}
			if (_menuVisible)
			{
				HandleSummonDigits();
				HandlePanelMouseClick();
			}
		}

		private void HandleSummonDigits()
		{
			for (int i = 0; i < _structures.Count && i < 9; i++)
			{
				if (CartPortInput.WasDigitRowPressed(i + 1))
				{
					Structure val = _structures[i];
					if ((Object)(object)val != (Object)null)
					{
						DoSummon(val);
					}
					break;
				}
			}
		}

		private void HandlePanelMouseClick()
		{
			//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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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_010d: 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_00bb: Expected O, but got Unknown
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			if (!CartPortInput.WasLeftClickPressed())
			{
				return;
			}
			Vector2 val = CartPortInput.MouseGuiPosition();
			if (!((Rect)(ref _panelRect)).Contains(val))
			{
				return;
			}
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(val.x - ((Rect)(ref _panelRect)).x, val.y - ((Rect)(ref _panelRect)).y);
			if (((Rect)(ref _refreshRect)).width > 0f && ((Rect)(ref _refreshRect)).Contains(val2))
			{
				RefreshList();
				return;
			}
			if (((Rect)(ref _forceModeRect)).width > 0f && ((Rect)(ref _forceModeRect)).Contains(val2))
			{
				_forceMode = !_forceMode;
				if (!_forceMode)
				{
					CartPortPersistentSummonOverride.CancelAll();
				}
				ManualLogSource log = CartPortPlugin.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(22, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("CartPort: Force Mode ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(_forceMode ? "ON" : "OFF");
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(".");
				}
				log.LogInfo(val3);
				return;
			}
			if (((Rect)(ref _closeRect)).width > 0f && ((Rect)(ref _closeRect)).Contains(val2))
			{
				SetMenuVisible(visible: false);
				return;
			}
			for (int i = 0; i < _summonRects.Count; i++)
			{
				var (val4, val5) = _summonRects[i];
				if (((Rect)(ref val4)).Contains(val2) && (Object)(object)val5 != (Object)null)
				{
					DoSummon(val5);
					break;
				}
			}
		}

		internal void ScheduleDeferredSummon(Structure structure, Vector3 pos, Quaternion rot, bool clientPredictionAfterServerSummonRelay = false)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			if (CartPortPlugin.RequestFusionAuthority.Value)
			{
				num = Mathf.Max(0, CartPortPlugin.FusionAuthorityWaitFrames.Value);
			}
			_deferSummonDueFrame = Time.frameCount + 1 + num;
			_deferSummonStructure = structure;
			_deferSummonPos = pos;
			_deferSummonRot = rot;
			_deferSummonClientPredictionAfterServerRelay = clientPredictionAfterServerSummonRelay;
		}

		private void LateUpdate()
		{
			ProcessDeferredSummon();
			if (_menuVisible)
			{
				if (CartPortPlugin.SuspendGameplayInputWhileMenuOpen.Value)
				{
					CartPortGameplayInputSuspend.ReassertGameplayDisabled();
				}
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
			}
		}

		private void ProcessDeferredSummon()
		{
			//IL_001e: 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)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			if (_deferSummonDueFrame >= 0 && Time.frameCount >= _deferSummonDueFrame)
			{
				Structure deferSummonStructure = _deferSummonStructure;
				Vector3 deferSummonPos = _deferSummonPos;
				Quaternion deferSummonRot = _deferSummonRot;
				bool deferSummonClientPredictionAfterServerRelay = _deferSummonClientPredictionAfterServerRelay;
				_deferSummonDueFrame = -1;
				_deferSummonStructure = null;
				_deferSummonClientPredictionAfterServerRelay = false;
				CartSummon.ApplyDeferredTeleport(deferSummonStructure, deferSummonPos, deferSummonRot, deferSummonClientPredictionAfterServerRelay);
			}
		}

		private void OnDisable()
		{
			if (_menuVisible)
			{
				SetMenuVisible(visible: false);
			}
		}

		private void SetMenuVisible(bool visible)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			if (_menuVisible == visible)
			{
				return;
			}
			bool menuVisible = _menuVisible;
			_menuVisible = visible;
			if (visible)
			{
				if (CartPortPlugin.SuspendGameplayInputWhileMenuOpen.Value)
				{
					CartPortGameplayInputSuspend.Push();
				}
				_savedCursorLockMode = Cursor.lockState;
				_savedCursorVisible = Cursor.visible;
				_haveSavedCursor = true;
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
			}
			else if (menuVisible)
			{
				if (CartPortPlugin.SuspendGameplayInputWhileMenuOpen.Value)
				{
					CartPortGameplayInputSuspend.Pop();
				}
				if (_haveSavedCursor)
				{
					Cursor.lockState = _savedCursorLockMode;
					Cursor.visible = _savedCursorVisible;
					_haveSavedCursor = false;
				}
			}
		}

		private void OnGUI()
		{
			//IL_007e: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Invalid comparison between Unknown and I4
			//IL_00c0: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: 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_0257: 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_027f: Invalid comparison between Unknown and I4
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			if (!_menuVisible)
			{
				return;
			}
			GUI.depth = 2147483583;
			float num = 480f;
			float num2 = 70f;
			float num3 = 92f + (float)Mathf.Max(1, _structures.Count) * num2 + 24f;
			num3 = Mathf.Clamp(num3, 220f, (float)Screen.height - 48f);
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((float)Screen.width - num) * 0.5f, ((float)Screen.height - num3) * 0.5f, num, num3);
			_panelRect = val;
			if ((int)Event.current.type == 7)
			{
				_summonRects.Clear();
				_refreshRect = default(Rect);
				_forceModeRect = default(Rect);
				_closeRect = default(Rect);
			}
			GUILayout.BeginArea(val, GUI.skin.box);
			GUILayout.Label("CartPort — click Summon or press 1–9 for rows 1–9. (Uses Unity Input System.)", WrappedLabelStyle, Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			DrawToolbarButton("Refresh list", 110f, ref _refreshRect);
			GUILayout.Space(6f);
			DrawToolbarButton(_forceMode ? "Force: ON [!]" : "Force: OFF", 110f, ref _forceModeRect);
			GUILayout.Space(6f);
			DrawToolbarButton("Close (Esc)", 100f, ref _closeRect);
			GUILayout.EndHorizontal();
			if (_forceMode)
			{
				GUILayout.Label("Force Mode: ignores authority — re-applies position every frame for ~10 s. Use for bugged/orphaned carts.", WrappedLabelStyle, Array.Empty<GUILayoutOption>());
			}
			GUILayout.Space(6f);
			for (int i = 0; i < _structures.Count; i++)
			{
				Structure val2 = _structures[i];
				if (!((Object)(object)val2 == (Object)null))
				{
					GUILayout.BeginHorizontal(GUI.skin.box, Array.Empty<GUILayoutOption>());
					GUILayout.Label(DescribeStructure(val2, i), WrappedLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(288f) });
					GUILayout.FlexibleSpace();
					string text = ((i < 9) ? $" [{i + 1}]" : string.Empty);
					Rect rect = GUILayoutUtility.GetRect(172f, 26f, (GUILayoutOption[])(object)new GUILayoutOption[2]
					{
						GUILayout.Width(172f),
						GUILayout.MinHeight(26f)
					});
					GUI.Label(rect, "Summon" + text, GUI.skin.button);
					if ((int)Event.current.type == 7)
					{
						_summonRects.Add((rect, val2));
					}
					GUILayout.EndHorizontal();
				}
			}
			if (_structures.Count == 0)
			{
				GUILayout.Label("No carts or sleds found. Place one in the world or click Refresh.", WrappedLabelStyle, Array.Empty<GUILayoutOption>());
			}
			GUILayout.EndArea();
		}

		private void DrawToolbarButton(string text, float w, ref Rect slot)
		{
			//IL_0022: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Invalid comparison between Unknown and I4
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			Rect rect = GUILayoutUtility.GetRect(w, 24f, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(w),
				GUILayout.MinHeight(24f)
			});
			GUI.Label(rect, text, GUI.skin.button);
			if ((int)Event.current.type == 7)
			{
				slot = rect;
			}
		}

		private void DoSummon(Structure st)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)st == (Object)null)
			{
				return;
			}
			if (_forceMode)
			{
				if (!CartSummon.TryGetSummonPlacement(st, out var position, out var yawDegrees))
				{
					CartPortPlugin.Log.LogWarning((object)"CartPort: Force summon — no placement (no gameplay camera or ray miss). Enable VerboseLogging for details.");
					return;
				}
				Quaternion rot = Quaternion.Euler(0f, yawDegrees, 0f);
				CartSummon.TrySummon(st);
				CartPortPersistentSummonOverride.AddOrRefresh(st, position, rot, CartPortPlugin.ForceSummonPersistDurationFrames.Value);
			}
			else if (!CartSummon.TrySummon(st))
			{
				CartPortPlugin.Log.LogWarning((object)"CartPort: Summon failed — no gameplay camera or placement ray miss. Enable Debug.VerboseLogging for details.");
			}
		}

		private void OnEnable()
		{
			RefreshList();
		}

		private static string DescribeStructure(Structure st, int index)
		{
			//IL_000d: 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_006b: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			GameObject gameObject = ((Component)st).gameObject;
			Vector3 position = gameObject.transform.position;
			string name = ((object)st).GetType().Name;
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(index + 1).Append(". ").Append(((Object)gameObject).name);
			stringBuilder.Append("\n").Append(name);
			stringBuilder.Append("\n").AppendFormat(CultureInfo.InvariantCulture, "Pos: {0:F1}, {1:F1}, {2:F1}", position.x, position.y, position.z);
			try
			{
				NetworkObject val = gameObject.GetComponent<NetworkObject>() ?? gameObject.GetComponentInParent<NetworkObject>();
				if ((Object)(object)val != (Object)null)
				{
					stringBuilder.Append(val.HasStateAuthority ? " [Auth]" : " [No Auth]");
				}
			}
			catch
			{
			}
			if (CartPortPersistentSummonOverride.IsActive(st))
			{
				stringBuilder.Append(" [Forcing...]");
			}
			return stringBuilder