Decompiled source of PortalGauntlet v1.1.4

PortalGauntlet.dll

Decompiled 9 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using ReservedItemSlotCore.Data;
using StaticNetcodeLib;
using Unity.Netcode;
using Unity.Netcode.Components;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PortalGauntlet")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.4.0")]
[assembly: AssemblyInformationalVersion("1.1.4")]
[assembly: AssemblyProduct("PortalGauntlet")]
[assembly: AssemblyTitle("PortalGauntlet")]
[assembly: AssemblyVersion("1.1.4.0")]
namespace PortalGauntlet;

public class GauntletItem : GrabbableObject
{
	public ScanNodeProperties ScanNode;

	public int charges = -1;

	private readonly WornGauntlet _worn = new WornGauntlet();

	private Renderer[] _ownRenderers;

	private bool _meshesWanted = true;

	private bool _wornFailed;

	private float ExpectedCharge => (float)charges / (float)Mathf.Max(1, Plugin.MaxCharges.Value);

	public override void Start()
	{
		((GrabbableObject)this).Start();
		if (!((Object)(object)((Component)this).gameObject == (Object)(object)PortalContent.GauntletTemplate))
		{
			if (charges < 0)
			{
				charges = Plugin.MaxCharges.Value;
			}
			base.useCooldown = 1.1f;
			SyncBattery();
			RefreshPresentation();
		}
	}

	public override int GetItemDataToSave()
	{
		return Mathf.Clamp(charges, 0, Plugin.MaxCharges.Value) + 1;
	}

	public override void LoadItemSaveData(int saveData)
	{
		if (saveData > 0)
		{
			charges = Mathf.Clamp(saveData - 1, 0, Plugin.MaxCharges.Value);
			SyncBattery();
			RefreshPresentation();
		}
	}

	public override void ItemActivate(bool used, bool buttonDown)
	{
		//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)
		if (!buttonDown || !((NetworkBehaviour)this).IsOwner || (Object)(object)base.playerHeldBy == (Object)null || (Object)(object)((Component)this).gameObject == (Object)(object)PortalContent.GauntletTemplate)
		{
			return;
		}
		if (RiftLink.Links.Count > 0)
		{
			PortalNet.RequestCloseServerRpc();
			return;
		}
		if (charges <= 0)
		{
			Fizzle();
			return;
		}
		StartOfRound instance = StartOfRound.Instance;
		if ((Object)(object)instance == (Object)null || !instance.shipHasLanded || instance.shipIsLeaving)
		{
			Tip("Portal Gauntlet", "The ship has to be landed before the rift will hold.");
			return;
		}
		if ((Object)(object)RiftFrame.Active == (Object)null)
		{
			Tip("Portal Gauntlet", "Place the Rift Frame on a ship wall first. It comes with the Portal Gauntlet upgrade.");
			return;
		}
		if (base.playerHeldBy.isInHangarShipRoom)
		{
			Tip("Portal Gauntlet", "Step outside the ship and paint the rift on a wall. It always comes home to the frame.");
			return;
		}
		if (!PortalAim.TryGetWall(base.playerHeldBy, out var point, out var normal, out var insideFactory))
		{
			Fizzle();
			return;
		}
		int playerSlot = Array.IndexOf(instance.allPlayerScripts, base.playerHeldBy);
		PortalNet.RequestOpenServerRpc(point, normal, insideFactory, playerSlot, ((NetworkBehaviour)this).NetworkObjectId);
	}

	public override void SetControlTipsForItem()
	{
		if ((Object)(object)base.itemProperties != (Object)null)
		{
			base.itemProperties.toolTips = new string[2]
			{
				(RiftLink.Links.Count > 0) ? "Close rift : [LMB]" : "Open rift : [LMB]",
				"Charges: " + charges + "/" + Plugin.MaxCharges.Value
			};
		}
		((GrabbableObject)this).SetControlTipsForItem();
	}

	public override void EnableItemMeshes(bool enable)
	{
		((GrabbableObject)this).EnableItemMeshes(enable);
		_meshesWanted = enable;
		SetOwnRenderers(enable && !_worn.Visible);
	}

	public override void LateUpdate()
	{
		((GrabbableObject)this).LateUpdate();
		if (!((Object)(object)((Component)this).gameObject == (Object)(object)PortalContent.GauntletTemplate))
		{
			CheckShipCharger();
			bool flag = !_wornFailed && (Object)(object)base.playerHeldBy != (Object)null && (base.isHeld || base.isPocketed) && !base.playerHeldBy.isPlayerDead;
			bool visible = _worn.Visible;
			try
			{
				_worn.Update(flag ? base.playerHeldBy : null, flag, (float)charges / (float)Mathf.Max(1, Plugin.MaxCharges.Value));
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Worn gauntlet failed, showing the normal item instead: " + ex));
				_wornFailed = true;
				_worn.Clear();
			}
			if (_worn.Visible)
			{
				SetOwnRenderers(enable: false);
			}
			else if (visible)
			{
				SetOwnRenderers(_meshesWanted);
			}
		}
	}

	public override void OnDestroy()
	{
		_worn.Clear();
		((GrabbableObject)this).OnDestroy();
	}

	private void SyncBattery()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		float num = Mathf.Clamp01(ExpectedCharge);
		if (base.insertedBattery == null)
		{
			base.insertedBattery = new Battery(false, num);
		}
		base.insertedBattery.charge = num;
		base.insertedBattery.empty = false;
	}

	private void CheckShipCharger()
	{
		if (charges >= 0)
		{
			if (base.insertedBattery == null)
			{
				SyncBattery();
			}
			else if (charges < Plugin.MaxCharges.Value && base.insertedBattery.charge > ExpectedCharge + 0.05f)
			{
				SetCharges(Plugin.MaxCharges.Value);
			}
			else if (base.insertedBattery.empty || Mathf.Abs(base.insertedBattery.charge - ExpectedCharge) > 0.001f)
			{
				SyncBattery();
			}
		}
	}

	private void SetOwnRenderers(bool enable)
	{
		if (_ownRenderers == null)
		{
			_ownRenderers = ((Component)this).GetComponentsInChildren<Renderer>(true);
		}
		for (int i = 0; i < _ownRenderers.Length; i++)
		{
			if ((Object)(object)_ownRenderers[i] != (Object)null && _ownRenderers[i].enabled != enable)
			{
				_ownRenderers[i].enabled = enable;
			}
		}
	}

	public void SetCharges(int value)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		int num = charges;
		charges = Mathf.Clamp(value, 0, Plugin.MaxCharges.Value);
		if (num >= 0 && charges > num)
		{
			PortalAudio.PlayAt(PortalAudio.Recharge, ((Component)this).transform.position, 0.7f, 14f);
		}
		SyncBattery();
		RefreshPresentation();
		RefreshHeldTips();
	}

	public static void RefreshHeldTips()
	{
		PlayerControllerB val = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.localPlayerController : null);
		if (!((Object)(object)val == (Object)null))
		{
			GauntletItem gauntletItem = val.currentlyHeldObjectServer as GauntletItem;
			if ((Object)(object)gauntletItem == (Object)null)
			{
				gauntletItem = val.currentlyHeldObject as GauntletItem;
			}
			if ((Object)(object)gauntletItem != (Object)null && (Object)(object)((GrabbableObject)gauntletItem).playerHeldBy == (Object)(object)val && ((GrabbableObject)gauntletItem).isHeld && !((GrabbableObject)gauntletItem).isPocketed)
			{
				((GrabbableObject)gauntletItem).SetControlTipsForItem();
			}
		}
	}

	private void RefreshPresentation()
	{
		int value = Plugin.MaxCharges.Value;
		int num = Mathf.Clamp(charges, 0, value);
		base.customGrabTooltip = "Grab Portal Gauntlet : [E]\nCharges: " + num + "/" + value;
		if ((Object)(object)ScanNode != (Object)null)
		{
			ScanNode.subText = "Charges: " + num + "/" + value;
		}
	}

	private void Fizzle()
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		Vector3 position = (((Object)(object)base.playerHeldBy != (Object)null) ? (((Component)base.playerHeldBy).transform.position + Vector3.up * 1.2f) : ((Component)this).transform.position);
		PortalAudio.PlayAt(PortalAudio.Fizzle, position, 0.55f, 10f);
	}

	public static void Tip(string header, string body, bool warning = false)
	{
		if ((Object)(object)HUDManager.Instance != (Object)null)
		{
			HUDManager.Instance.DisplayTip(header, body, warning, false, "PortalGauntlet." + header);
		}
	}
}
[BepInPlugin("com.zozin.portalgauntlet", "Portal Gauntlet", "1.1.4")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	public const string Guid = "com.zozin.portalgauntlet";

	public const string Name = "Portal Gauntlet";

	public const string Version = "1.1.4";

	public const string KitName = "Portal Gauntlet";

	public const string StabilizerName = "Rift Stabilizer";

	public const string CapacitorName = "Rift Capacitor";

	public const string AnchorName = "Rift Anchor";

	public static ConfigEntry<int> KitPrice;

	public static ConfigEntry<int> StabilizerPrice;

	public static ConfigEntry<int> CapacitorPrice;

	public static ConfigEntry<int> AnchorPrice;

	public static ConfigEntry<float> BaseSeconds;

	public static ConfigEntry<float> StabilizerSeconds;

	public static ConfigEntry<float> CapacitorSeconds;

	public static ConfigEntry<float> AnchorSeconds;

	public static ConfigEntry<int> MaxCharges;

	public static ConfigEntry<float> MaxRange;

	public static ConfigEntry<bool> FlipFrame;

	public static ConfigEntry<Vector3> WornPosition;

	public static ConfigEntry<Vector3> WornRotation;

	public static ConfigEntry<float> WornScale;

	public static Plugin Instance { get; private set; }

	public static ManualLogSource Log { get; private set; }

	private void Awake()
	{
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		KitPrice = ((BaseUnityPlugin)this).Config.Bind<int>("Shop", "KitPrice", 200, "Credits for the Portal Gauntlet upgrade. Unlocks the ship frame immediately and sends one gauntlet on the dropship.");
		StabilizerPrice = ((BaseUnityPlugin)this).Config.Bind<int>("Shop", "StabilizerPrice", 200, "Credits for Rift Stabilizer.");
		CapacitorPrice = ((BaseUnityPlugin)this).Config.Bind<int>("Shop", "CapacitorPrice", 350, "Credits for Rift Capacitor.");
		AnchorPrice = ((BaseUnityPlugin)this).Config.Bind<int>("Shop", "AnchorPrice", 500, "Credits for Rift Anchor.");
		BaseSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Rift", "BaseSeconds", 30f, "How long a rift stays open before any stabilizer upgrade.");
		StabilizerSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Rift", "StabilizerSeconds", 45f, "Open time once Rift Stabilizer is owned.");
		CapacitorSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Rift", "CapacitorSeconds", 60f, "Open time once Rift Capacitor is owned.");
		AnchorSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Rift", "AnchorSeconds", 90f, "Open time once Rift Anchor is owned. The highest owned tier wins.");
		MaxCharges = ((BaseUnityPlugin)this).Config.Bind<int>("Rift", "MaxCharges", 10, "Rifts the gauntlet can open before it must be recharged at the frame.");
		MaxRange = ((BaseUnityPlugin)this).Config.Bind<float>("Rift", "MaxRange", 9f, "How far the gauntlet can paint a rift onto a wall.");
		FlipFrame = ((BaseUnityPlugin)this).Config.Bind<bool>("Rift", "FlipFrame", false, "Turn this on if the ship-side door opens into the wall instead of into the room.");
		WornPosition = ((BaseUnityPlugin)this).Config.Bind<Vector3>("Worn", "HandPosition", new Vector3(0f, 0.045f, 0f), "Where the worn gauntlet sits on the right hand, in metres along the hand bone. Y runs from the wrist toward the fingers.");
		WornRotation = ((BaseUnityPlugin)this).Config.Bind<Vector3>("Worn", "HandRotation", new Vector3(0f, 180f, 0f), "Rotation of the worn gauntlet on the right hand, in degrees.");
		WornScale = ((BaseUnityPlugin)this).Config.Bind<float>("Worn", "HandScale", 1.3f, "Size of the worn gauntlet. Larger values hide the hand underneath better.");
		PortalContent.BuildAndRegister(((Component)this).transform);
		RegisterToolSlot();
		new Harmony("com.zozin.portalgauntlet").PatchAll(typeof(Plugin).Assembly);
		Log.LogInfo((object)"Portal Gauntlet ready.");
	}

	private static void RegisterToolSlot()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		ReservedItemSlotData obj = ReservedItemSlotData.CreateReservedItemSlotData("portal_gauntlet", 40, 0);
		ReservedItemData val = new ReservedItemData("Portal Gauntlet", (PlayerBone)14, Vector3.zero, Vector3.zero);
		obj.AddItemToReservedItemSlot(val);
	}

	public static int OwnedTier()
	{
		int num = 0;
		if ((Object)(object)StartOfRound.Instance == (Object)null || (Object)(object)StartOfRound.Instance.unlockablesList == (Object)null)
		{
			return num;
		}
		foreach (UnlockableItem unlockable in StartOfRound.Instance.unlockablesList.unlockables)
		{
			if (unlockable != null && unlockable.hasBeenUnlockedByPlayer)
			{
				if (unlockable.unlockableName == "Rift Stabilizer")
				{
					num = Mathf.Max(num, 1);
				}
				else if (unlockable.unlockableName == "Rift Capacitor")
				{
					num = Mathf.Max(num, 2);
				}
				else if (unlockable.unlockableName == "Rift Anchor")
				{
					num = Mathf.Max(num, 3);
				}
			}
		}
		return num;
	}

	public static float CurrentDuration()
	{
		float num = BaseSeconds.Value;
		if ((Object)(object)StartOfRound.Instance == (Object)null || (Object)(object)StartOfRound.Instance.unlockablesList == (Object)null)
		{
			return num;
		}
		foreach (UnlockableItem unlockable in StartOfRound.Instance.unlockablesList.unlockables)
		{
			if (unlockable != null && unlockable.hasBeenUnlockedByPlayer)
			{
				if (unlockable.unlockableName == "Rift Stabilizer")
				{
					num = Mathf.Max(num, StabilizerSeconds.Value);
				}
				else if (unlockable.unlockableName == "Rift Capacitor")
				{
					num = Mathf.Max(num, CapacitorSeconds.Value);
				}
				else if (unlockable.unlockableName == "Rift Anchor")
				{
					num = Mathf.Max(num, AnchorSeconds.Value);
				}
			}
		}
		return num;
	}
}
[HarmonyPatch(typeof(StartOfRound), "Update")]
public static class PortalDriver
{
	private static bool _wasLeaving;

	[HarmonyPostfix]
	public static void Postfix(StartOfRound __instance)
	{
		try
		{
			if (!__instance.shipIsLeaving)
			{
				PortalDelivery.ReplaceIfLost();
				PortalDelivery.TryDeliver();
			}
			if (__instance.shipIsLeaving && !_wasLeaving)
			{
				RiftLink.CloseAll();
			}
			_wasLeaving = __instance.shipIsLeaving;
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("Portal Gauntlet update failed: " + ex));
		}
	}
}
public static class PortalAudio
{
	private const int Rate = 44100;

	private const float Tau = MathF.PI * 2f;

	private static AudioClip _open;

	private static AudioClip _hum;

	private static AudioClip _close;

	private static AudioClip _strain;

	private static AudioClip _fizzle;

	private static AudioClip _recharge;

	private static readonly float[] ChordFreq = new float[6] { 55f, 110f, 165f, 220f, 58f, 113.5f };

	private static readonly float[] ChordAmp = new float[6] { 0.5f, 0.32f, 0.15f, 0.09f, 0.42f, 0.27f };

	public static AudioClip Open
	{
		get
		{
			if (!((Object)(object)_open != (Object)null))
			{
				return _open = BuildOpen();
			}
			return _open;
		}
	}

	public static AudioClip Hum
	{
		get
		{
			if (!((Object)(object)_hum != (Object)null))
			{
				return _hum = BuildHum();
			}
			return _hum;
		}
	}

	public static AudioClip Close
	{
		get
		{
			if (!((Object)(object)_close != (Object)null))
			{
				return _close = BuildClose();
			}
			return _close;
		}
	}

	public static AudioClip Strain
	{
		get
		{
			if (!((Object)(object)_strain != (Object)null))
			{
				return _strain = BuildStrain();
			}
			return _strain;
		}
	}

	public static AudioClip Fizzle
	{
		get
		{
			if (!((Object)(object)_fizzle != (Object)null))
			{
				return _fizzle = BuildFizzle();
			}
			return _fizzle;
		}
	}

	public static AudioClip Recharge
	{
		get
		{
			if (!((Object)(object)_recharge != (Object)null))
			{
				return _recharge = BuildRecharge();
			}
			return _recharge;
		}
	}

	public static AudioSource MakeSource(GameObject host, float maxDistance)
	{
		AudioSource obj = host.AddComponent<AudioSource>();
		obj.playOnAwake = false;
		obj.spatialBlend = 1f;
		obj.dopplerLevel = 0f;
		obj.rolloffMode = (AudioRolloffMode)1;
		obj.minDistance = 1.5f;
		obj.maxDistance = maxDistance;
		return obj;
	}

	public static void PlayAt(AudioClip clip, Vector3 position, float volume, float maxDistance = 22f)
	{
		//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_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected O, but got Unknown
		//IL_004b: Expected O, but got Unknown
		if (!((Object)(object)clip == (Object)null))
		{
			GameObject val = new GameObject("PortalSound");
			val.transform.position = position;
			AudioSource obj = MakeSource(val, maxDistance);
			obj.clip = clip;
			obj.volume = volume;
			obj.Play();
			Object.Destroy((Object)val, clip.length + 0.2f);
		}
	}

	private static AudioClip BuildOpen()
	{
		float[] array = new float[Mathf.CeilToInt(1.45f * 44100f)];
		float[] phase = new float[ChordFreq.Length];
		float num = 0f;
		float num2 = 0f;
		for (int i = 0; i < array.Length; i++)
		{
			float num3 = (float)i / 44100f;
			float num4 = Mathf.Clamp01(num3 / 0.4f);
			float pitch = Mathf.Lerp(0.5f, 1f, 1f - (1f - num4) * (1f - num4));
			float num5 = ((num3 < 0.4f) ? 1f : Mathf.Exp((0f - (num3 - 0.4f)) * 4f));
			float num6 = (float)Math.Tanh(Chord(phase, pitch, num5 * 0.7f) * 1.2f);
			num += MathF.PI * 2f * Mathf.Lerp(2f, 7f, num4) / 44100f;
			float num7 = 1f - 0.6f * num5 * (0.5f + 0.5f * Mathf.Sin(num));
			float num8 = Mathf.SmoothStep(0.2f, 1f, num4) * ((num3 < 0.9f) ? 1f : Mathf.Exp((0f - (num3 - 0.9f)) * 5f));
			float num9 = num3 - 0.4f;
			float num10 = ((num9 >= 0f) ? (Mathf.Sin(MathF.PI * 2f * (36f + 18f * Mathf.Exp((0f - num9) * 9f)) * num9) * Mathf.Clamp01(num9 / 0.03f) * Mathf.Exp((0f - num9) * 3.5f) * 0.7f) : 0f);
			num2 = LowPass(num2, num6 * num7 * num8, 1400f);
			array[i] = (num2 + num10) * Mathf.Clamp01(num3 / 0.06f);
		}
		return Finish("RiftOpen", array, 0.92f);
	}

	private static AudioClip BuildHum()
	{
		float[] array = new float[Mathf.RoundToInt(4f * 44100f)];
		for (int i = 0; i < array.Length; i++)
		{
			float num = (float)i / 44100f;
			array[i] = Mathf.Sin(MathF.PI * 110f * num) * 0.55f + Mathf.Sin(MathF.PI * 220f * num) * 0.32f + Mathf.Sin(MathF.PI * 330f * num) * 0.14f + Mathf.Sin(MathF.PI * 440f * num) * 0.09f + Mathf.Sin(MathF.PI * 443f * num) * 0.09f + Mathf.Sin(2766.1724f * num) * 0.035f;
		}
		return Finish("RiftHum", array, 0.8f);
	}

	private static AudioClip BuildStrain()
	{
		float[] array = new float[Mathf.RoundToInt(4f * 44100f)];
		for (int i = 0; i < array.Length; i++)
		{
			float num = (float)i / 44100f;
			float num2 = Mathf.Sin(MathF.PI * 110f * num) * 0.45f + Mathf.Sin(MathF.PI * 116f * num) * 0.4f + Mathf.Sin(MathF.PI * 220f * num) * 0.3f + Mathf.Sin(MathF.PI * 227f * num) * 0.26f + Mathf.Sin(1038.2964f * num) * 0.14f;
			float num3 = (Mathf.Sin(MathF.PI * 1760f * num) + Mathf.Sin(MathF.PI * 1768f * num)) * 0.05f;
			float num4 = (float)Math.Tanh(num2 * 2.2f) * 0.7f;
			array[i] = num4 + num3;
		}
		return Finish("RiftStrain", array, 0.85f);
	}

	private static AudioClip BuildClose()
	{
		float[] array = new float[Mathf.CeilToInt(1.35f * 44100f)];
		float[] phase = new float[ChordFreq.Length];
		float num = 0f;
		float num2 = 0f;
		for (int i = 0; i < array.Length; i++)
		{
			float num3 = (float)i / 44100f;
			float num4 = Mathf.Clamp01(num3 / 0.32f);
			float pitch = ((num3 < 0.32f) ? Mathf.Lerp(1.15f, 0.4f, num4 * num4) : (0.4f * Mathf.Exp((0f - (num3 - 0.32f)) * 0.9f)));
			float num5 = (float)Math.Tanh(Chord(phase, pitch, 1f) * 1.4f);
			num += MathF.PI * 2f * ((num3 < 0.32f) ? Mathf.Lerp(9f, 14f, num4) : Mathf.Lerp(14f, 3f, Mathf.Clamp01((num3 - 0.32f) / 0.6f))) / 44100f;
			float num6 = 1f - 0.6f * (0.5f + 0.5f * Mathf.Sin(num));
			float num7 = ((num3 < 0.32f) ? Mathf.Lerp(0.8f, 1f, num4) : (Mathf.Exp((0f - (num3 - 0.32f)) * 2.8f) * 0.75f));
			float num8 = num3 - 0.32f;
			float num9 = ((num8 >= 0f) ? (Mathf.Sin(MathF.PI * 2f * (32f + 22f * Mathf.Exp((0f - num8) * 10f)) * num8) * Mathf.Clamp01(num8 / 0.025f) * Mathf.Exp((0f - num8) * 3.8f) * 0.8f) : 0f);
			num2 = LowPass(num2, num5 * num6 * num7, 1200f);
			array[i] = (num2 + num9) * Mathf.Clamp01(num3 / 0.03f);
		}
		return Finish("RiftClose", array, 0.95f);
	}

	private static float Chord(float[] phase, float pitch, float detune)
	{
		float num = 0f;
		for (int i = 0; i < ChordFreq.Length; i++)
		{
			phase[i] += MathF.PI * 2f * ChordFreq[i] * pitch / 44100f;
			if (phase[i] > MathF.PI * 2f)
			{
				phase[i] -= MathF.PI * 2f;
			}
			num += Mathf.Sin(phase[i]) * ((i >= 4) ? (ChordAmp[i] * detune) : ChordAmp[i]);
		}
		return num;
	}

	private static AudioClip BuildFizzle()
	{
		float num = 0.42f;
		float[] array = new float[Mathf.CeilToInt(num * 44100f)];
		Random random = new Random(41);
		float num2 = 0f;
		for (int i = 0; i < array.Length; i++)
		{
			float num3 = (float)i / 44100f;
			num2 = LowPass(num2, Noise(random), 3000f);
			float num4 = Mathf.Sign(Mathf.Sin(MathF.PI * 2f * Mathf.Lerp(150f, 70f, num3 / num) * num3)) * 0.25f;
			float num5 = ((Mathf.PerlinNoise(num3 * 60f, 0.5f) > 0.4f) ? 1f : 0.25f);
			array[i] = (num2 * 1.3f + num4) * num5 * Mathf.Exp((0f - num3) * 7f) * Mathf.Clamp01(num3 / 0.01f);
		}
		return Finish("RiftFizzle", array, 0.6f);
	}

	private static AudioClip BuildRecharge()
	{
		float[] array = new float[Mathf.CeilToInt(1.1f * 44100f)];
		float num = 0f;
		for (int i = 0; i < array.Length; i++)
		{
			float num2 = (float)i / 44100f;
			float num3 = Mathf.Lerp(220f, 880f, Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(num2 / 0.7f)));
			num += MathF.PI * 2f * num3 / 44100f;
			float num4 = (Mathf.Sin(num) + 0.3f * Mathf.Sin(num * 2f)) * Mathf.Clamp01(num2 / 0.05f) * ((num2 < 0.7f) ? 0.5f : (0.5f * Mathf.Exp((0f - (num2 - 0.7f)) * 12f)));
			float num5 = Mathf.Max(0f, num2 - 0.68f);
			float num6 = ((num2 >= 0.68f) ? ((Mathf.Sin(MathF.PI * 2640f * num5) + 0.5f * Mathf.Sin(MathF.PI * 3960f * num5)) * Mathf.Exp((0f - num5) * 7f) * 0.45f) : 0f);
			array[i] = num4 + num6;
		}
		return Finish("RiftRecharge", array, 0.7f);
	}

	private static float Noise(Random random)
	{
		return (float)(random.NextDouble() * 2.0 - 1.0);
	}

	private static float LowPass(float previous, float input, float cutoff)
	{
		float num = 1f - Mathf.Exp(MathF.PI * -2f * cutoff / 44100f);
		return previous + num * (input - previous);
	}

	private static AudioClip Finish(string name, float[] data, float level)
	{
		float num = 0.0001f;
		for (int i = 0; i < data.Length; i++)
		{
			num = Mathf.Max(num, Mathf.Abs(data[i]));
		}
		float num2 = level / num;
		for (int j = 0; j < data.Length; j++)
		{
			data[j] *= num2;
		}
		int num3 = Mathf.Min(data.Length / 4, 441);
		if (name != "RiftHum" && name != "RiftStrain")
		{
			for (int k = 0; k < num3; k++)
			{
				data[data.Length - 1 - k] *= (float)k / (float)num3;
			}
		}
		AudioClip obj = AudioClip.Create(name, data.Length, 1, 44100, false);
		obj.SetData(data, 0);
		return obj;
	}
}
public static class PortalContent
{
	public static Item GauntletItemData;

	public static GameObject GauntletTemplate;

	public static GameObject FrameTemplate;

	public static readonly Dictionary<string, UnlockableItem> Registered = new Dictionary<string, UnlockableItem>();

	public static void BuildAndRegister(Transform persistentParent)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Expected O, but got Unknown
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		GauntletTemplate = BuildGauntlet();
		FrameTemplate = BuildFrame();
		GameObject val = new GameObject("PortalGauntletPrefabs");
		val.SetActive(false);
		val.transform.SetParent(persistentParent, false);
		GauntletTemplate.transform.SetParent(val.transform, false);
		FrameTemplate.transform.SetParent(val.transform, false);
		AttachGauntletNetwork(GauntletTemplate);
		AttachFrameNetwork(FrameTemplate);
		GauntletTemplate.SetActive(true);
		FrameTemplate.SetActive(true);
		GauntletItemData = ScriptableObject.CreateInstance<Item>();
		((Object)GauntletItemData).name = "PortalGauntletItem";
		GauntletItemData.itemName = "Portal Gauntlet";
		GauntletItemData.spawnPrefab = GauntletTemplate;
		GauntletItemData.twoHanded = false;
		GauntletItemData.twoHandedAnimation = false;
		GauntletItemData.canBeGrabbedBeforeGameStart = true;
		GauntletItemData.weight = 1.05f;
		GauntletItemData.itemSpawnsOnGround = true;
		GauntletItemData.isScrap = false;
		GauntletItemData.creditsWorth = 0;
		GauntletItemData.highestSalePercentage = 0;
		GauntletItemData.minValue = 0;
		GauntletItemData.maxValue = 0;
		GauntletItemData.requiresBattery = true;
		GauntletItemData.batteryUsage = 100000f;
		GauntletItemData.holdButtonUse = false;
		GauntletItemData.itemIcon = PortalVisuals.CreateIconSprite();
		GauntletItemData.grabAnim = "";
		GauntletItemData.positionOffset = new Vector3(0.03f, 0.04f, -0.02f);
		GauntletItemData.rotationOffset = new Vector3(-8f, 170f, -75f);
		GauntletItemData.restingRotation = new Vector3(0f, 0f, 80f);
		GauntletItemData.verticalOffset = 0.15f;
		GauntletItemData.allowDroppingAheadOfPlayer = true;
		GauntletItemData.saveItemVariable = true;
		GauntletItemData.toolTips = new string[2] { "Open rift : [LMB]", "Charges: 10/10" };
		((GrabbableObject)GauntletTemplate.GetComponent<GauntletItem>()).itemProperties = GauntletItemData;
		NetworkPrefabs.RegisterNetworkPrefab(GauntletTemplate);
		NetworkPrefabs.RegisterNetworkPrefab(FrameTemplate);
		Items.RegisterItem(GauntletItemData);
		RegisterUpgrade("Portal Gauntlet", Plugin.KitPrice.Value, FrameTemplate, spawnsPrefab: true, "Mount the Rift Frame on a ship wall in build mode.\nThe Portal Gauntlet is delivered by dropship.\n\nLook at a flat wall and fire. A door opens back to the frame for a short time. Fire again to close it early. Crew, scrap, and monsters can all walk through, and monsters chasing you will follow.\n\nThe gauntlet holds 10 charges. Recharge it by interacting with the frame.\n\n");
		RegisterUpgrade("Rift Stabilizer", Plugin.StabilizerPrice.Value, null, spawnsPrefab: false, "Holds an open rift for 45 seconds.\nThe highest rift upgrade you own is the one that applies.\n\n");
		RegisterUpgrade("Rift Capacitor", Plugin.CapacitorPrice.Value, null, spawnsPrefab: false, "Holds an open rift for 60 seconds.\nThe highest rift upgrade you own is the one that applies.\n\n");
		RegisterUpgrade("Rift Anchor", Plugin.AnchorPrice.Value, null, spawnsPrefab: false, "Holds an open rift for 90 seconds.\nThe highest rift upgrade you own is the one that applies.\n\n");
	}

	private static void RegisterUpgrade(string unlockName, int price, GameObject prefab, bool spawnsPrefab, string info)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: 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_0045: Expected O, but got Unknown
		UnlockableItem val = new UnlockableItem
		{
			unlockableName = unlockName,
			prefabObject = prefab,
			unlockableType = 1,
			alwaysInStock = true,
			IsPlaceable = spawnsPrefab,
			spawnPrefab = spawnsPrefab,
			maxNumber = 1,
			hasBeenUnlockedByPlayer = false,
			alreadyUnlocked = false
		};
		TerminalNode val2 = ScriptableObject.CreateInstance<TerminalNode>();
		((Object)val2).name = unlockName.Replace(" ", "") + "Info";
		val2.displayText = info;
		val2.clearPreviousText = true;
		val2.maxCharactersToType = 40;
		Unlockables.RegisterUnlockable(val, (StoreType)1, (TerminalNode)null, (TerminalNode)null, val2, price);
		Registered[unlockName] = val;
	}

	private static GameObject BuildGauntlet()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("PortalGauntletPrefab");
		val.SetActive(false);
		val.tag = SafeTag("PhysicsProp");
		val.layer = Layer("Props");
		Rigidbody val2 = val.AddComponent<Rigidbody>();
		val2.mass = 1.2f;
		val2.interpolation = (RigidbodyInterpolation)1;
		val2.collisionDetectionMode = (CollisionDetectionMode)1;
		BoxCollider val3 = val.AddComponent<BoxCollider>();
		val3.size = new Vector3(0.2f, 0.42f, 0.15f);
		val3.center = new Vector3(0f, -0.03f, 0.02f);
		val.AddComponent<AudioSource>();
		GauntletItem gauntletItem = val.AddComponent<GauntletItem>();
		Transform obj = NewChild(val.transform, "Model");
		PortalVisuals.BuildGauntletModel(obj);
		Renderer componentInChildren = ((Component)obj).GetComponentInChildren<Renderer>();
		((GrabbableObject)gauntletItem).mainObjectRenderer = (MeshRenderer)(object)((componentInChildren is MeshRenderer) ? componentInChildren : null);
		((GrabbableObject)gauntletItem).propBody = val2;
		((GrabbableObject)gauntletItem).propColliders = (Collider[])(object)new Collider[1] { (Collider)val3 };
		((GrabbableObject)gauntletItem).grabbable = true;
		((GrabbableObject)gauntletItem).grabbableToEnemies = false;
		GameObject gameObject = ((Component)NewChild(val.transform, "ScanNode")).gameObject;
		gameObject.layer = Layer("ScanNode");
		BoxCollider obj2 = gameObject.AddComponent<BoxCollider>();
		((Collider)obj2).isTrigger = true;
		obj2.size = new Vector3(0.1f, 0.25f, 0.08f);
		obj2.center = new Vector3(0f, -0.03f, 0.02f);
		ScanNodeProperties val4 = gameObject.AddComponent<ScanNodeProperties>();
		val4.maxRange = 13;
		val4.minRange = 1;
		val4.requiresLineOfSight = true;
		val4.headerText = "Portal Gauntlet";
		val4.subText = "Charges: 10/10";
		val4.nodeType = 2;
		val4.creatureScanID = -1;
		gauntletItem.ScanNode = val4;
		return val;
	}

	private static GameObject BuildFrame()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("RiftFramePrefab");
		val.SetActive(false);
		val.transform.position = new Vector3(0f, -800f, 0f);
		val.layer = Layer("Props");
		PortalVisuals.BuildFrameModel(val.transform, out var mainMesh, out var placeCollider);
		Transform val2 = NewChild(val.transform, "Anchor");
		val2.localPosition = new Vector3(0f, 0f, 0.15f);
		val2.localRotation = Quaternion.identity;
		((Component)placeCollider).gameObject.AddComponent<AudioSource>();
		PlaceableShipObject obj = ((Component)placeCollider).gameObject.AddComponent<PlaceableShipObject>();
		obj.mainMesh = mainMesh;
		obj.mainTransform = val.transform;
		obj.placeObjectCollider = placeCollider;
		obj.AllowPlacementOnWalls = true;
		obj.AllowPlacementOnCounters = false;
		obj.overrideWallOffset = true;
		obj.wallOffset = 0.08f;
		obj.yOffset = 1.8000001f;
		AutoParentToShip val3 = val.AddComponent<AutoParentToShip>();
		val3.overrideOffset = true;
		obj.parentObject = val3;
		val.AddComponent<RiftFrame>().Anchor = val2;
		InteractTrigger obj2 = val.AddComponent<InteractTrigger>();
		obj2.hoverTip = "Recharge gauntlet : [E]";
		obj2.interactable = true;
		obj2.oneHandedItemAllowed = true;
		obj2.twoHandedItemAllowed = true;
		obj2.holdInteraction = false;
		obj2.timeToHold = 0f;
		val.AddComponent<AudioSource>();
		return val;
	}

	private static void AttachGauntletNetwork(GameObject root)
	{
		NetworkObject obj = root.AddComponent<NetworkObject>();
		obj.DestroyWithScene = false;
		obj.AutoObjectParentSync = false;
		AssignPrefabHash(obj, 1346842673u);
	}

	private static void AttachFrameNetwork(GameObject root)
	{
		NetworkObject obj = root.AddComponent<NetworkObject>();
		obj.DestroyWithScene = false;
		AssignPrefabHash(obj, 1346842674u);
		root.AddComponent<NetworkTransform>();
	}

	public static void AssignPrefabHash(NetworkObject net, uint hash)
	{
		string[] array = new string[4] { "GlobalObjectIdHash", "m_GlobalObjectIdHash", "PrefabGlobalObjectIdHash", "m_PrefabGlobalObjectIdHash" };
		for (int i = 0; i < array.Length; i++)
		{
			FieldInfo field = typeof(NetworkObject).GetField(array[i], BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null && field.FieldType == typeof(uint))
			{
				field.SetValue(net, hash);
			}
		}
	}

	public static Transform NewChild(Transform parent, string name)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(name);
		val.transform.SetParent(parent, false);
		return val.transform;
	}

	public static int Layer(string name)
	{
		int num = LayerMask.NameToLayer(name);
		if (num >= 0)
		{
			return num;
		}
		return 0;
	}

	private static string SafeTag(string tag)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		try
		{
			Object.Destroy((Object)new GameObject("tagprobe")
			{
				tag = tag
			});
			return tag;
		}
		catch
		{
			return "Untagged";
		}
	}
}
public static class PortalDelivery
{
	private const string Key = "PortalGauntlet.PendingDeliveries";

	private static int _pending = int.MinValue;

	private static string _file = "";

	private static float _nextWaitLog;

	private static float _nextLostCheck;

	public static void QueueGauntlet()
	{
		if (!((Object)(object)StartOfRound.Instance == (Object)null) && ((NetworkBehaviour)StartOfRound.Instance).IsServer)
		{
			int value = Read() + 1;
			Write(value);
			Plugin.Log.LogInfo((object)("Portal Gauntlet queued on the dropship. Pending=" + value));
		}
	}

	public static void ReplaceIfLost()
	{
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		StartOfRound instance = StartOfRound.Instance;
		if ((Object)(object)instance == (Object)null || !((NetworkBehaviour)instance).IsServer || (Object)(object)PortalContent.GauntletTemplate == (Object)null || Time.time < _nextLostCheck)
		{
			return;
		}
		_nextLostCheck = Time.time + 3f;
		if (Time.timeSinceLevelLoad < 10f || instance.shipIsLeaving || !KitOwned(instance) || Read() > 0)
		{
			return;
		}
		List<GauntletItem> list = new List<GauntletItem>();
		GauntletItem[] array = Object.FindObjectsOfType<GauntletItem>(true);
		foreach (GauntletItem gauntletItem in array)
		{
			if (!((Object)(object)gauntletItem == (Object)null) && !((Object)(object)((Component)gauntletItem).gameObject == (Object)(object)PortalContent.GauntletTemplate))
			{
				if (Usable(gauntletItem, instance))
				{
					return;
				}
				list.Add(gauntletItem);
			}
		}
		foreach (GauntletItem item in list)
		{
			Plugin.Log.LogInfo((object)string.Format("Removing a lost Portal Gauntlet (held {0}, pocketed {1}, holder {2}, holder dead {3}, in ship {4}, deactivated {5}, active {6}, at {7})", ((GrabbableObject)item).isHeld, ((GrabbableObject)item).isPocketed, ((Object)(object)((GrabbableObject)item).playerHeldBy != (Object)null) ? ((GrabbableObject)item).playerHeldBy.playerUsername : "-", (Object)(object)((GrabbableObject)item).playerHeldBy != (Object)null && ((GrabbableObject)item).playerHeldBy.isPlayerDead, ((GrabbableObject)item).isInShipRoom || ((GrabbableObject)item).isInElevator, ((GrabbableObject)item).deactivated, ((Component)item).gameObject.activeInHierarchy, ((Component)item).transform.position));
			if ((Object)(object)((GrabbableObject)item).playerHeldBy != (Object)null)
			{
				PlayerControllerB playerHeldBy = ((GrabbableObject)item).playerHeldBy;
				int num = 0;
				while (playerHeldBy.ItemSlots != null && num < playerHeldBy.ItemSlots.Length)
				{
					if ((Object)(object)playerHeldBy.ItemSlots[num] == (Object)(object)item)
					{
						playerHeldBy.ItemSlots[num] = null;
					}
					num++;
				}
			}
			NetworkObject networkObject = ((NetworkBehaviour)item).NetworkObject;
			if ((Object)(object)networkObject != (Object)null && networkObject.IsSpawned)
			{
				networkObject.Despawn(true);
			}
			else
			{
				Object.Destroy((Object)(object)((Component)item).gameObject);
			}
		}
		Write(1);
		Plugin.Log.LogInfo((object)"No usable Portal Gauntlet left, sending a replacement to the ship.");
	}

	private static bool Usable(GauntletItem gauntlet, StartOfRound round)
	{
		if (((GrabbableObject)gauntlet).deactivated)
		{
			return false;
		}
		if (!round.inShipPhase)
		{
			return true;
		}
		PlayerControllerB playerHeldBy = ((GrabbableObject)gauntlet).playerHeldBy;
		if ((Object)(object)playerHeldBy != (Object)null && (((GrabbableObject)gauntlet).isHeld || ((GrabbableObject)gauntlet).isPocketed))
		{
			if (playerHeldBy.isPlayerDead || !playerHeldBy.isPlayerControlled)
			{
				return false;
			}
			if (playerHeldBy.ItemSlots != null)
			{
				return Array.IndexOf(playerHeldBy.ItemSlots, (GrabbableObject)(object)gauntlet) >= 0;
			}
			return false;
		}
		if (!((GrabbableObject)gauntlet).isInShipRoom)
		{
			return ((GrabbableObject)gauntlet).isInElevator;
		}
		return true;
	}

	private static bool KitOwned(StartOfRound round)
	{
		if ((Object)(object)round.unlockablesList == (Object)null)
		{
			return false;
		}
		foreach (UnlockableItem unlockable in round.unlockablesList.unlockables)
		{
			if (unlockable != null && unlockable.unlockableName == "Portal Gauntlet" && unlockable.hasBeenUnlockedByPlayer)
			{
				return true;
			}
		}
		return false;
	}

	public static void TryDeliver()
	{
		if ((Object)(object)StartOfRound.Instance == (Object)null || !((NetworkBehaviour)StartOfRound.Instance).IsServer || (Object)(object)PortalContent.GauntletTemplate == (Object)null || Read() <= 0)
		{
			return;
		}
		if (!CanDeliverNow())
		{
			if (Time.time >= _nextWaitLog)
			{
				_nextWaitLog = Time.time + 15f;
				Plugin.Log.LogInfo((object)("Portal Gauntlet waiting to deliver. Pending=" + Read() + " shipHasLanded=" + StartOfRound.Instance.shipHasLanded + " shipIsLeaving=" + StartOfRound.Instance.shipIsLeaving));
			}
		}
		else
		{
			int num = Read();
			Write(0);
			if (num > 1)
			{
				Plugin.Log.LogInfo((object)("Cleared " + (num - 1) + " extra queued gauntlets from earlier purchases."));
			}
			SpawnGauntlet();
		}
	}

	private unsafe static void SpawnGauntlet()
	{
		//IL_000c: 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_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_021e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: 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_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_0232: Unknown result type (might be due to invalid IL or missing references)
		//IL_0233: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
		Transform elevatorTransform = StartOfRound.Instance.elevatorTransform;
		Vector3 val = elevatorTransform.position + elevatorTransform.forward * 1.6f + Vector3.up * 0.35f;
		ItemDropship val2 = Object.FindObjectOfType<ItemDropship>();
		int num;
		if ((Object)(object)val2 != (Object)null)
		{
			num = (val2.shipLanded ? 1 : 0);
			if (num != 0)
			{
				val = ((Component)val2).transform.position + Vector3.up * 1.4f + ((Component)val2).transform.forward * 1.2f;
				goto IL_01da;
			}
		}
		else
		{
			num = 0;
		}
		RiftFrame active = RiftFrame.Active;
		if ((Object)(object)active != (Object)null && (Object)(object)active.Anchor != (Object)null)
		{
			Vector3 forward = active.Anchor.forward;
			forward.y = 0f;
			val = active.Anchor.position + ((((Vector3)(ref forward)).sqrMagnitude > 0.01f) ? ((Vector3)(ref forward)).normalized : Vector3.zero) * 0.6f;
		}
		StartOfRound instance = StartOfRound.Instance;
		Collider shipInnerRoomBounds = instance.shipInnerRoomBounds;
		Vector3 val5;
		if ((Object)(object)shipInnerRoomBounds != (Object)null)
		{
			Bounds bounds = shipInnerRoomBounds.bounds;
			float x = val.x;
			Bounds bounds2 = shipInnerRoomBounds.bounds;
			if (!((Bounds)(ref bounds)).Contains(new Vector3(x, ((Bounds)(ref bounds2)).center.y, val.z)))
			{
				Vector3 val3;
				if (!((Object)(object)instance.middleOfShipNode != (Object)null))
				{
					bounds = shipInnerRoomBounds.bounds;
					val3 = ((Bounds)(ref bounds)).center;
				}
				else
				{
					val3 = instance.middleOfShipNode.position;
				}
				Vector3 val4 = val3;
				ManualLogSource log = Plugin.Log;
				val5 = val;
				log.LogWarning((object)("Delivery spot " + ((object)(*(Vector3*)(&val5))/*cast due to .constrained prefix*/).ToString() + " is outside the ship room, using the middle of the ship"));
				((Vector3)(ref val))..ctor(val4.x, elevatorTransform.position.y + 1f, val4.z);
			}
		}
		goto IL_01da;
		IL_01da:
		RaycastHit val6 = default(RaycastHit);
		if (Physics.Raycast(val + Vector3.up * 0.5f, Vector3.down, ref val6, 8f, 2305, (QueryTriggerInteraction)1))
		{
			val = ((RaycastHit)(ref val6)).point + Vector3.up * 0.35f;
		}
		Transform val7 = ((num != 0) ? null : elevatorTransform);
		GameObject val8 = Object.Instantiate<GameObject>(PortalContent.GauntletTemplate, val, Quaternion.identity, val7);
		GauntletItem component = val8.GetComponent<GauntletItem>();
		if ((Object)(object)component != (Object)null && (Object)(object)val7 != (Object)null)
		{
			((GrabbableObject)component).isInElevator = true;
			((GrabbableObject)component).isInShipRoom = true;
		}
		val8.SetActive(true);
		NetworkObject val9 = val8.GetComponent<NetworkObject>();
		if ((Object)(object)val9 == (Object)null)
		{
			val9 = val8.AddComponent<NetworkObject>();
			PortalContent.AssignPrefabHash(val9, 1346842673u);
		}
		if (!val9.IsSpawned)
		{
			val9.Spawn(false);
		}
		string text = ((num != 0) ? "on the dropship" : "in the ship");
		ManualLogSource log2 = Plugin.Log;
		val5 = val;
		log2.LogInfo((object)("Portal Gauntlet delivered " + text + " at " + ((object)(*(Vector3*)(&val5))/*cast due to .constrained prefix*/).ToString()));
		PortalNet.AnnounceClientRpc((num != 0) ? "Dropship" : "Ship", "Portal Gauntlet delivered " + text + ".");
	}

	private static bool CanDeliverNow()
	{
		StartOfRound instance = StartOfRound.Instance;
		if ((Object)(object)instance == (Object)null || instance.shipIsLeaving)
		{
			return false;
		}
		ItemDropship val = Object.FindObjectOfType<ItemDropship>();
		if ((Object)(object)val != (Object)null && val.shipLanded)
		{
			return true;
		}
		if (!instance.shipHasLanded)
		{
			return instance.inShipPhase;
		}
		return true;
	}

	private static int Read()
	{
		string text = FileName();
		if (text != _file)
		{
			_file = text;
			_pending = int.MinValue;
		}
		if (_pending != int.MinValue)
		{
			return _pending;
		}
		if (string.IsNullOrEmpty(text) || !ES3.KeyExists("PortalGauntlet.PendingDeliveries", text))
		{
			_pending = 0;
			return 0;
		}
		_pending = ES3.Load<int>("PortalGauntlet.PendingDeliveries", text, 0);
		return _pending;
	}

	private static void Write(int value)
	{
		_pending = value;
		string text = (_file = FileName());
		if (!string.IsNullOrEmpty(text))
		{
			ES3.Save<int>("PortalGauntlet.PendingDeliveries", value, text);
		}
	}

	private static string FileName()
	{
		if (!((Object)(object)GameNetworkManager.Instance != (Object)null))
		{
			return "";
		}
		return GameNetworkManager.Instance.currentSaveFileName;
	}
}
[HarmonyPatch(typeof(StartOfRound), "BuyShipUnlockableServerRpc")]
public static class BuyKitPatch
{
	private static int _lastQueuedFrame = -1;

	private static int _lastQueuedId = int.MinValue;

	[HarmonyPostfix]
	public static void Postfix(int unlockableID)
	{
		if (Time.frameCount != _lastQueuedFrame || unlockableID != _lastQueuedId)
		{
			_lastQueuedFrame = Time.frameCount;
			_lastQueuedId = unlockableID;
			StartOfRound instance = StartOfRound.Instance;
			if (!((Object)(object)instance == (Object)null) && ((NetworkBehaviour)instance).IsServer && !((Object)(object)instance.unlockablesList == (Object)null) && unlockableID >= 0 && unlockableID < instance.unlockablesList.unlockables.Count && instance.unlockablesList.unlockables[unlockableID].unlockableName == "Portal Gauntlet")
			{
				PortalDelivery.QueueGauntlet();
			}
		}
	}
}
[HarmonyPatch(typeof(StartOfRound), "SpawnUnlockable")]
public static class SpawnFramePatch
{
	private const float WallClearance = 0.21000001f;

	[HarmonyPrefix]
	public static bool Prefix(StartOfRound __instance, int unlockableIndex)
	{
		if (!IsFrame(__instance, unlockableIndex) || (Object)(object)PortalContent.FrameTemplate == (Object)null)
		{
			return true;
		}
		try
		{
			SpawnFrame(__instance, unlockableIndex);
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("Rift frame spawn failed: " + ex));
		}
		return false;
	}

	private static void SpawnFrame(StartOfRound round, int unlockableIndex)
	{
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		if (round.SpawnedShipUnlockables.ContainsKey(unlockableIndex))
		{
			return;
		}
		if (!TryLoadSavedPose(round.unlockablesList.unlockables[unlockableIndex], out var position, out var euler) && !TryFramePose(round, out position, out euler))
		{
			position = round.elevatorTransform.position + Vector3.up * 1.2f;
			euler = round.elevatorTransform.eulerAngles;
		}
		GameObject val = Object.Instantiate<GameObject>(PortalContent.FrameTemplate, position, Quaternion.Euler(euler));
		((Object)val).name = "Rift Frame";
		NetworkObject val2 = val.GetComponent<NetworkObject>();
		if ((Object)(object)val2 == (Object)null)
		{
			val2 = val.AddComponent<NetworkObject>();
			Plugin.Log.LogWarning((object)"Rift frame clone had no NetworkObject. Added one before spawn.");
		}
		PortalContent.AssignPrefabHash(val2, 1346842674u);
		val2.DestroyWithScene = false;
		PlaceableShipObject componentInChildren = val.GetComponentInChildren<PlaceableShipObject>(true);
		AutoParentToShip component = val.GetComponent<AutoParentToShip>();
		if ((Object)(object)componentInChildren != (Object)null)
		{
			componentInChildren.unlockableID = unlockableIndex;
			if ((Object)(object)componentInChildren.placeObjectSFX == (Object)null)
			{
				PlaceableShipObject[] array = Object.FindObjectsOfType<PlaceableShipObject>();
				foreach (PlaceableShipObject val3 in array)
				{
					if ((Object)(object)val3 != (Object)(object)componentInChildren && (Object)(object)val3.placeObjectSFX != (Object)null)
					{
						componentInChildren.placeObjectSFX = val3.placeObjectSFX;
						break;
					}
				}
			}
		}
		if ((Object)(object)component != (Object)null)
		{
			component.unlockableID = unlockableIndex;
			component.overrideOffset = true;
			if ((Object)(object)componentInChildren != (Object)null)
			{
				componentInChildren.parentObject = component;
			}
		}
		val.SetActive(true);
		if ((Object)(object)componentInChildren != (Object)null && (Object)(object)component != (Object)null && (Object)(object)ShipBuildModeManager.Instance != (Object)null)
		{
			ShipBuildModeManager.Instance.PlaceShipObject(position, euler, componentInChildren, false);
			component.MoveToOffset();
		}
		else if ((Object)(object)component != (Object)null && (Object)(object)round.elevatorTransform != (Object)null)
		{
			component.positionOffset = round.elevatorTransform.InverseTransformPoint(position);
			Quaternion val4 = Quaternion.Inverse(round.elevatorTransform.rotation) * Quaternion.Euler(euler);
			component.rotationOffset = ((Quaternion)(ref val4)).eulerAngles;
		}
		if (!val2.IsSpawned)
		{
			val2.Spawn(false);
		}
		round.SpawnedShipUnlockables.Add(unlockableIndex, val);
		Plugin.Log.LogInfo((object)("Rift frame spawned left of the battery charger, toward the terminal, at " + ((object)val.transform.position/*cast due to .constrained prefix*/).ToString()));
	}

	private static bool TryLoadSavedPose(UnlockableItem unlock, out Vector3 position, out Vector3 euler)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		position = Vector3.zero;
		euler = Vector3.zero;
		GameNetworkManager instance = GameNetworkManager.Instance;
		if (unlock == null || (Object)(object)instance == (Object)null || string.IsNullOrEmpty(instance.currentSaveFileName))
		{
			return false;
		}
		string text = "ShipUnlockMoved_" + unlock.unlockableName;
		if (!ES3.KeyExists(text, instance.currentSaveFileName))
		{
			return false;
		}
		position = ES3.Load<Vector3>(text.Replace("ShipUnlockMoved_", "ShipUnlockPos_"), instance.currentSaveFileName, Vector3.zero);
		euler = ES3.Load<Vector3>(text.Replace("ShipUnlockMoved_", "ShipUnlockRot_"), instance.currentSaveFileName, Vector3.zero);
		return position != Vector3.zero;
	}

	private unsafe static bool TryFramePose(StartOfRound ship, out Vector3 position, out Vector3 euler)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: 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_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: 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)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: 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_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_0289: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0290: Unknown result type (might be due to invalid IL or missing references)
		//IL_0292: Unknown result type (might be due to invalid IL or missing references)
		//IL_0294: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0231: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_024b: Unknown result type (might be due to invalid IL or missing references)
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_0256: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_0266: Unknown result type (might be due to invalid IL or missing references)
		//IL_026a: Unknown result type (might be due to invalid IL or missing references)
		//IL_026f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0274: Unknown result type (might be due to invalid IL or missing references)
		//IL_027b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0280: Unknown result type (might be due to invalid IL or missing references)
		//IL_0285: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0200: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_0297: Unknown result type (might be due to invalid IL or missing references)
		//IL_0299: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0221: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0303: Unknown result type (might be due to invalid IL or missing references)
		//IL_0321: Unknown result type (might be due to invalid IL or missing references)
		//IL_0323: Unknown result type (might be due to invalid IL or missing references)
		//IL_0328: Unknown result type (might be due to invalid IL or missing references)
		//IL_032b: Unknown result type (might be due to invalid IL or missing references)
		//IL_032d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0334: Unknown result type (might be due to invalid IL or missing references)
		//IL_0339: Unknown result type (might be due to invalid IL or missing references)
		//IL_033e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0345: Unknown result type (might be due to invalid IL or missing references)
		//IL_034a: Unknown result type (might be due to invalid IL or missing references)
		//IL_034f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0398: Unknown result type (might be due to invalid IL or missing references)
		//IL_039d: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03de: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0404: Unknown result type (might be due to invalid IL or missing references)
		//IL_0428: Unknown result type (might be due to invalid IL or missing references)
		//IL_042a: Unknown result type (might be due to invalid IL or missing references)
		//IL_042f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0434: Unknown result type (might be due to invalid IL or missing references)
		//IL_0438: Unknown result type (might be due to invalid IL or missing references)
		//IL_043d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0443: Unknown result type (might be due to invalid IL or missing references)
		//IL_0448: Unknown result type (might be due to invalid IL or missing references)
		//IL_0464: Unknown result type (might be due to invalid IL or missing references)
		//IL_0469: Unknown result type (might be due to invalid IL or missing references)
		position = Vector3.zero;
		euler = Vector3.zero;
		if ((Object)(object)ship == (Object)null || (Object)(object)ship.elevatorTransform == (Object)null)
		{
			return false;
		}
		ItemCharger val = Object.FindObjectOfType<ItemCharger>();
		Terminal val2 = Object.FindObjectOfType<Terminal>();
		if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
		{
			return false;
		}
		Vector3 val3 = ((Component)val2).transform.position - ((Component)val).transform.position;
		val3.y = 0f;
		if (((Vector3)(ref val3)).sqrMagnitude < 0.25f)
		{
			return false;
		}
		float y = ship.elevatorTransform.position.y;
		Vector3 val4 = ((Component)val).transform.position + val3 * 0.5f;
		Vector3 val5 = (((Object)(object)ship.middleOfShipNode != (Object)null) ? ship.middleOfShipNode.position : ship.elevatorTransform.position);
		Collider shipInnerRoomBounds = ship.shipInnerRoomBounds;
		Vector3 val6 = Vector3.Cross(Vector3.up, ((Vector3)(ref val3)).normalized);
		Vector3 val7 = val5 - val4;
		val7.y = 0f;
		if (Vector3.Dot(val6, val7) > 0f)
		{
			val6 = -val6;
		}
		float[] array = new float[3] { 1.2f, 2f, 0.7f };
		bool flag = false;
		RaycastHit val8 = default(RaycastHit);
		for (int i = 0; i < array.Length; i++)
		{
			if (flag)
			{
				break;
			}
			if (FindWall(new Vector3(val4.x, y + array[i], val4.z) - val6 * 0.6f, val6, 3f, ((Component)val).transform, ((Component)val2).transform, out var wall))
			{
				val8 = wall;
				flag = true;
			}
		}
		if (!flag)
		{
			Vector3 val9 = default(Vector3);
			((Vector3)(ref val9))..ctor(val5.x, y + 1.2f, val5.z);
			Vector3 val10 = new Vector3(val4.x, val9.y, val4.z) - val9;
			if (((Vector3)(ref val10)).sqrMagnitude > 0.04f && FindWall(val9, ((Vector3)(ref val10)).normalized, 12f, ((Component)val).transform, ((Component)val2).transform, out var wall2))
			{
				val8 = wall2;
				flag = true;
			}
		}
		Vector3 val11;
		Vector3 val12;
		Vector3 val13;
		if (flag)
		{
			val11 = ((RaycastHit)(ref val8)).normal;
			val11.y = 0f;
			((Vector3)(ref val11)).Normalize();
			val12 = Vector3.Cross(Vector3.up, val11);
			Vector3 normalized = ((Vector3)(ref val12)).normalized;
			val13 = ((RaycastHit)(ref val8)).point + normalized * Vector3.Dot(val4 - ((RaycastHit)(ref val8)).point, normalized);
		}
		else
		{
			val11 = -val6;
			val13 = val4;
		}
		position = val13 + val11 * 0.21000001f;
		position.y = y + 1.8000001f;
		if ((Object)(object)shipInnerRoomBounds != (Object)null)
		{
			Bounds bounds = shipInnerRoomBounds.bounds;
			if (!((Bounds)(ref bounds)).Contains(new Vector3(position.x, y + 1f, position.z)))
			{
				ManualLogSource log = Plugin.Log;
				val12 = position;
				log.LogWarning((object)("Rift frame default: wall spot " + ((object)(*(Vector3*)(&val12))/*cast due to .constrained prefix*/).ToString() + " is outside the ship room, using the gap instead"));
				val11 = -val6;
				position = val4 - val6 * 0.05f + val11 * 0.21000001f;
				position.y = y + 1.8000001f;
				goto IL_0427;
			}
		}
		ManualLogSource log2 = Plugin.Log;
		string[] obj = new string[11]
		{
			"Rift frame default: ",
			flag ? "mounted on the wall" : "no wall found, using the gap",
			" at ",
			null,
			null,
			null,
			null,
			null,
			null,
			null,
			null
		};
		val12 = position;
		obj[3] = ((object)(*(Vector3*)(&val12))/*cast due to .constrained prefix*/).ToString();
		obj[4] = ", facing ";
		val12 = val11;
		obj[5] = ((object)(*(Vector3*)(&val12))/*cast due to .constrained prefix*/).ToString();
		obj[6] = " (charger ";
		val12 = ((Component)val).transform.position;
		obj[7] = ((object)(*(Vector3*)(&val12))/*cast due to .constrained prefix*/).ToString();
		obj[8] = ", terminal ";
		val12 = ((Component)val2).transform.position;
		obj[9] = ((object)(*(Vector3*)(&val12))/*cast due to .constrained prefix*/).ToString();
		obj[10] = ")";
		log2.LogInfo((object)string.Concat(obj));
		goto IL_0427;
		IL_0427:
		Quaternion val14 = Quaternion.LookRotation(val11, Vector3.up);
		euler = ((Quaternion)(ref val14)).eulerAngles;
		if (euler == Vector3.zero)
		{
			euler = new Vector3(0f, 0.01f, 0f);
		}
		return true;
	}

	private static bool FindWall(Vector3 from, Vector3 direction, float distance, Transform charger, Transform terminal, out RaycastHit wall)
	{
		//IL_0002: 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_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: 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_00ef: 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)
		wall = default(RaycastHit);
		RaycastHit[] array = Physics.RaycastAll(from, direction, distance, 2305, (QueryTriggerInteraction)1);
		Array.Sort(array, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance));
		for (int num = 0; num < array.Length; num++)
		{
			Transform val = (((Object)(object)((RaycastHit)(ref array[num])).collider != (Object)null) ? ((Component)((RaycastHit)(ref array[num])).collider).transform : null);
			if (!((Object)(object)val == (Object)null) && !val.IsChildOf(charger) && !val.IsChildOf(terminal) && !((Object)(object)((Component)val).GetComponentInParent<RiftFrame>() != (Object)null) && !((Object)(object)((Component)val).GetComponentInParent<GrabbableObject>() != (Object)null) && !((Object)(object)((Component)val).GetComponentInParent<PlayerControllerB>() != (Object)null) && !(Mathf.Abs(((RaycastHit)(ref array[num])).normal.y) > 0.3f) && !(Vector3.Dot(((RaycastHit)(ref array[num])).normal, direction) > -0.2f))
			{
				wall = array[num];
				return true;
			}
		}
		return false;
	}

	private static bool IsFrame(StartOfRound round, int unlockableID)
	{
		if ((Object)(object)round == (Object)null || (Object)(object)round.unlockablesList == (Object)null)
		{
			return false;
		}
		if (unlockableID < 0 || unlockableID >= round.unlockablesList.unlockables.Count)
		{
			return false;
		}
		UnlockableItem val = round.unlockablesList.unlockables[unlockableID];
		if (val != null)
		{
			return (Object)(object)val.prefabObject == (Object)(object)PortalContent.FrameTemplate;
		}
		return false;
	}
}
[HarmonyPatch(typeof(ShipBuildModeManager), "Update")]
public static class FrameGhostPatch
{
	private const int FloorMask = 2305;

	[HarmonyPostfix]
	public static void Postfix(ShipBuildModeManager __instance, PlaceableShipObject ___placingObject)
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		if (__instance.InBuildMode && !((Object)(object)___placingObject == (Object)null) && !((Object)(object)__instance.ghostObject == (Object)null) && !((Object)(object)((Component)___placingObject).GetComponentInParent<RiftFrame>() == (Object)null))
		{
			Transform ghostObject = __instance.ghostObject;
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(ghostObject.position + Vector3.up * 0.25f, Vector3.down, ref val, 8f, 2305, (QueryTriggerInteraction)1) && !(Vector3.Angle(((RaycastHit)(ref val)).normal, Vector3.up) > 45f))
			{
				Vector3 position = ghostObject.position;
				position.y = ((RaycastHit)(ref val)).point.y + 1.8000001f;
				ghostObject.position = position;
			}
		}
	}
}
[HarmonyPatch(typeof(ItemDropship), "LandShipOnServer")]
public static class DropshipPatch
{
	[HarmonyPostfix]
	public static void Postfix()
	{
		PortalDelivery.TryDeliver();
	}
}
[StaticNetcode]
public static class PortalNet
{
	[ServerRpc]
	public static void RequestOpenServerRpc(Vector3 point, Vector3 normal, bool insideFactory, int playerSlot, ulong gauntletId)
	{
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		StartOfRound instance = StartOfRound.Instance;
		if ((Object)(object)instance == (Object)null || !((NetworkBehaviour)instance).IsServer || playerSlot < 0 || playerSlot >= instance.allPlayerScripts.Length)
		{
			return;
		}
		PlayerControllerB val = instance.allPlayerScripts[playerSlot];
		RiftFrame active = RiftFrame.Active;
		if ((Object)(object)val == (Object)null || (Object)(object)active == (Object)null || (Object)(object)active.Anchor == (Object)null)
		{
			TipClientRpc(playerSlot, "Portal Gauntlet", "The Rift Frame is not mounted on the ship.");
			return;
		}
		if (!instance.shipHasLanded || instance.shipIsLeaving)
		{
			TipClientRpc(playerSlot, "Portal Gauntlet", "The ship has to be landed before the rift will hold.");
			return;
		}
		if (Vector3.Distance(((Component)val).transform.position, point) > Plugin.MaxRange.Value + 4f)
		{
			TipClientRpc(playerSlot, "Portal Gauntlet", "That wall is too far away.");
			return;
		}
		if (((Vector3)(ref normal)).sqrMagnitude < 0.1f)
		{
			normal = Vector3.forward;
		}
		((Vector3)(ref normal)).Normalize();
		Vector3 wallPos = PortalAim.PlacedCenter(point, normal);
		Quaternion val2 = Quaternion.LookRotation(normal, Vector3.up);
		Transform anchor = active.Anchor;
		Quaternion val3 = anchor.rotation;
		if (Plugin.FlipFrame.Value)
		{
			val3 *= Quaternion.Euler(0f, 180f, 0f);
		}
		OpenClientRpc(wallPos, ((Quaternion)(ref val2)).eulerAngles, anchor.position, ((Quaternion)(ref val3)).eulerAngles, Plugin.CurrentDuration(), insideFactory, gauntletId, playerSlot);
	}

	[ClientRpc]
	public static void OpenClientRpc(Vector3 wallPos, Vector3 wallEuler, Vector3 shipPos, Vector3 shipEuler, float duration, bool insideFactory, ulong gauntletId, int playerSlot)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: 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_0009: Unknown result type (might be due to invalid IL or missing references)
		RiftLink.Spawn(wallPos, Quaternion.Euler(wallEuler), shipPos, Quaternion.Euler(shipEuler), duration, insideFactory);
		if ((Object)(object)NetworkManager.Singleton != (Object)null && NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(gauntletId, out var value))
		{
			GauntletItem component = ((Component)value).GetComponent<GauntletItem>();
			if ((Object)(object)component != (Object)null)
			{
				component.SetCharges(component.charges - 1);
			}
		}
	}

	[ServerRpc]
	public static void RequestRechargeServerRpc(int playerSlot)
	{
		StartOfRound instance = StartOfRound.Instance;
		if ((Object)(object)instance == (Object)null || !((NetworkBehaviour)instance).IsServer || playerSlot < 0 || playerSlot >= instance.allPlayerScripts.Length)
		{
			return;
		}
		PlayerControllerB val = instance.allPlayerScripts[playerSlot];
		if ((Object)(object)val == (Object)null || val.ItemSlots == null)
		{
			return;
		}
		bool flag = false;
		for (int i = 0; i < val.ItemSlots.Length; i++)
		{
			GauntletItem gauntletItem = val.ItemSlots[i] as GauntletItem;
			if (!((Object)(object)gauntletItem == (Object)null))
			{
				flag = true;
				SetChargesClientRpc(((NetworkBehaviour)gauntletItem).NetworkObjectId, Plugin.MaxCharges.Value);
			}
		}
		if (!flag)
		{
			TipClientRpc(playerSlot, "Rift Frame", "Have the Portal Gauntlet on you, then use the frame to refill it.");
		}
	}

	[ClientRpc]
	public static void SetChargesClientRpc(ulong gauntletId, int charges)
	{
		if (!((Object)(object)NetworkManager.Singleton == (Object)null) && NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(gauntletId, out var value))
		{
			GauntletItem component = ((Component)value).GetComponent<GauntletItem>();
			if ((Object)(object)component != (Object)null)
			{
				component.SetCharges(charges);
			}
		}
	}

	[ClientRpc]
	public static void TipClientRpc(int playerSlot, string header, string body)
	{
		StartOfRound instance = StartOfRound.Instance;
		if (!((Object)(object)instance == (Object)null) && !((Object)(object)instance.localPlayerController == (Object)null) && Array.IndexOf(instance.allPlayerScripts, instance.localPlayerController) == playerSlot)
		{
			GauntletItem.Tip(header, body);
		}
	}

	[ServerRpc]
	public static void CrossedServerRpc(int playerSlot, bool inside, bool inShip)
	{
		CrossedClientRpc(playerSlot, inside, inShip);
	}

	[ClientRpc]
	public static void CrossedClientRpc(int playerSlot, bool inside, bool inShip)
	{
		StartOfRound instance = StartOfRound.Instance;
		if ((Object)(object)instance == (Object)null || playerSlot < 0 || playerSlot >= instance.allPlayerScripts.Length)
		{
			return;
		}
		PlayerControllerB val = instance.allPlayerScripts[playerSlot];
		if (!((Object)(object)val == (Object)null) && !((Object)(object)val == (Object)(object)instance.localPlayerController))
		{
			RiftPortal.ApplyLocation(val, inside, inShip);
			RiftLink riftLink = ((RiftLink.Links.Count > 0) ? RiftLink.Links[0] : null);
			if ((Object)(object)riftLink != (Object)null)
			{
				RiftPursuit.PlayerCrossed(val, inShip ? riftLink.Wall : riftLink.ShipSide);
			}
		}
	}

	[ServerRpc]
	public static void RequestCloseServerRpc()
	{
		StartOfRound instance = StartOfRound.Instance;
		if (!((Object)(object)instance == (Object)null) && ((NetworkBehaviour)instance).IsServer)
		{
			CloseClientRpc();
		}
	}

	[ClientRpc]
	public static void AnnounceClientRpc(string header, string body)
	{
		GauntletItem.Tip(header, body);
	}

	[ClientRpc]
	public static void CloseClientRpc()
	{
		RiftLink.CloseAll();
	}
}
public static class PortalAim
{
	public const float Width = 1.56f;

	public const float Height = 3.12f;

	private const int FloorMask = 2305;

	public static bool TryGetWall(PlayerControllerB player, out Vector3 point, out Vector3 normal, out bool insideFactory)
	{
		//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_003f: 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_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: 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: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		point = default(Vector3);
		normal = default(Vector3);
		insideFactory = false;
		if ((Object)(object)player == (Object)null || (Object)(object)player.gameplayCamera == (Object)null)
		{
			return false;
		}
		insideFactory = player.isInsideFactory;
		Transform transform = ((Component)player.gameplayCamera).transform;
		RaycastHit[] array = Physics.RaycastAll(new Ray(transform.position, transform.forward), Plugin.MaxRange.Value, -1, (QueryTriggerInteraction)1);
		Array.Sort(array, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance));
		for (int num = 0; num < array.Length; num++)
		{
			RaycastHit val = array[num];
			if ((Object)(object)((RaycastHit)(ref val)).collider == (Object)null || (Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<PlayerControllerB>() != (Object)null || (Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<GrabbableObject>() != (Object)null || (Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<RiftPortal>() != (Object)null || (Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<RiftFrame>() != (Object)null)
			{
				continue;
			}
			Transform val2 = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.elevatorTransform : null);
			if (!((Object)(object)val2 != (Object)null) || !((RaycastHit)(ref val)).transform.IsChildOf(val2))
			{
				if (Mathf.Abs(((RaycastHit)(ref val)).normal.y) > 0.38f)
				{
					return false;
				}
				if (!Fits(((RaycastHit)(ref val)).point, ((RaycastHit)(ref val)).normal))
				{
					return false;
				}
				point = ((RaycastHit)(ref val)).point;
				normal = ((RaycastHit)(ref val)).normal;
				return true;
			}
		}
		return false;
	}

	public static Vector3 PlacedCenter(Vector3 hit, Vector3 normal)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = hit + normal * 0.07f;
		RaycastHit val2 = default(RaycastHit);
		if (Physics.Raycast(val + normal * 0.35f + Vector3.up * 0.15f, Vector3.down, ref val2, 4f, 2305, (QueryTriggerInteraction)1) && ((RaycastHit)(ref val2)).normal.y > 0.55f)
		{
			val.y = ((RaycastHit)(ref val2)).point.y + 0.05f + 1.56f;
		}
		return val;
	}

	public static bool Fits(Vector3 hit, Vector3 normal)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: 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_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: 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_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: 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_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = PlacedCenter(hit, normal);
		Quaternion val2 = Quaternion.LookRotation(normal, Vector3.up);
		Vector3 val3 = val2 * Vector3.right;
		Vector3 val4 = val2 * Vector3.up;
		Vector3[] array = (Vector3[])(object)new Vector3[4]
		{
			val3 * 0.65519994f + val4 * 0.468f,
			-val3 * 0.65519994f + val4 * 0.468f,
			val3 * 0.65519994f - val4 * 1.248f,
			-val3 * 0.65519994f - val4 * 1.248f
		};
		int num = 0;
		RaycastHit val5 = default(RaycastHit);
		for (int i = 0; i < array.Length; i++)
		{
			if (Physics.Raycast(val + array[i] + normal * 0.5f, -normal, ref val5, 1f, -1, (QueryTriggerInteraction)1) && Vector3.Dot(((RaycastHit)(ref val5)).normal, normal) > 0.72f)
			{
				num++;
			}
		}
		return num >= 3;
	}
}
public class RiftLink : MonoBehaviour
{
	public static readonly List<RiftLink> Links = new List<RiftLink>();

	public RiftPortal Wall;

	public RiftPortal ShipSide;

	public float CloseAt;

	private bool _closed;

	public static void Spawn(Vector3 wallPos, Quaternion wallRot, Vector3 shipPos, Quaternion shipRot, float duration, bool insideFactory)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		CloseAll();
		RiftPortal riftPortal = RiftPortal.Create(wallPos, wallRot, shipSide: false, insideFactory);
		RiftPortal riftPortal2 = RiftPortal.Create(shipPos, shipRot, shipSide: true, facilityInside: true);
		RiftFrame active = RiftFrame.Active;
		if ((Object)(object)active != (Object)null && (Object)(object)active.Anchor != (Object)null)
		{
			((Component)riftPortal2).transform.SetParent(active.Anchor, true);
		}
		riftPortal.Other = riftPortal2;
		riftPortal2.Other = riftPortal;
		RiftLink riftLink = new GameObject("RiftLink").AddComponent<RiftLink>();
		riftLink.Wall = riftPortal;
		riftLink.ShipSide = riftPortal2;
		riftLink.CloseAt = Time.time + Mathf.Max(5f, duration);
		Links.Add(riftLink);
		RiftAudio.Ensure();
		RiftPursuitDriver.Ensure();
		RiftSky.Ensure();
		GauntletItem.RefreshHeldTips();
	}

	public static void CloseAll()
	{
		for (int num = Links.Count - 1; num >= 0; num--)
		{
			if ((Object)(object)Links[num] != (Object)null)
			{
				Links[num].ForceClose();
			}
		}
		Links.Clear();
	}

	private void Update()
	{
		float num = CloseAt - Time.time;
		bool warning = num <= 5f;
		if ((Object)(object)Wall != (Object)null)
		{
			Wall.SetWarning(warning, num);
		}
		if ((Object)(object)ShipSide != (Object)null)
		{
			ShipSide.SetWarning(warning, num);
		}
		if (num <= 0f)
		{
			ForceClose();
		}
	}

	public void ForceClose()
	{
		if (!_closed)
		{
			_closed = true;
			Links.Remove(this);
			GauntletItem.RefreshHeldTips();
			if ((Object)(object)Wall != (Object)null)
			{
				Wall.BeginClose();
			}
			if ((Object)(object)ShipSide != (Object)null)
			{
				ShipSide.BeginClose();
			}
			Object.Destroy((Object)(object)((Component)this).gameObject, 0.65f);
		}
	}
}
public static class PortalVisuals
{
	public enum Finish
	{
		Metal,
		Plate,
		Glow
	}

	private static Shader _shader;

	private static Texture2D _noise;

	private static Material _metal;

	private static Material _plate;

	private static Material _orange;

	private static Material _cyan;

	private static Material _screen;

	public const float DoorScale = 1.5f;

	public const float FrameHalfHeight = 1.8000001f;

	public const float ScreenWidth = 0.98f;

	public const float ScreenHeight = 1.98f;

	private static Mesh _screenMesh;

	private static bool _loggedScreen;

	private static Material _foglessTemplate;

	private static bool _searchedFogless;

	private static readonly string[] ColorMaps = new string[3] { "_UnlitColorMap", "_BaseColorMap", "_MainTex" };

	public static void BuildGauntletModel(Transform root, bool withFingers = true)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: 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_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0263: Unknown result type (might be due to invalid IL or missing references)
		//IL_0277: Unknown result type (might be due to invalid IL or missing references)
		//IL_029a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0323: Unknown result type (might be due to invalid IL or missing references)
		//IL_0337: Unknown result type (might be due to invalid IL or missing references)
		//IL_035a: Unknown result type (might be due to invalid IL or missing references)
		//IL_036e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0410: Unknown result type (might be due to invalid IL or missing references)
		//IL_0424: Unknown result type (might be due to invalid IL or missing references)
		//IL_044a: Unknown result type (might be due to invalid IL or missing references)
		//IL_045e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0472: Unknown result type (might be due to invalid IL or missing references)
		//IL_0494: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
		Warm();
		Material plate = _plate;
		Part(root, "Bracer", (PrimitiveType)2, new Vector3(0f, -0.165f, 0.02f), new Vector3(0.132f, 0.075f, 0.112f), _metal, keepCollider: false);
		Part(root, "BracerTaper", (PrimitiveType)2, new Vector3(0f, -0.086f, 0.02f), new Vector3(0.12f, 0.012f, 0.1f), _metal, keepCollider: false);
		Part(root, "BracerPlate", (PrimitiveType)3, new Vector3(0f, -0.165f, -0.036f), new Vector3(0.07f, 0.12f, 0.012f), plate, keepCollider: false);
		Part(root, "BracerLineL", (PrimitiveType)3, new Vector3(-0.024f, -0.165f, -0.0425f), new Vector3(0.007f, 0.1f, 0.003f), _orange, keepCollider: false);
		Part(root, "BracerLineR", (PrimitiveType)3, new Vector3(0.024f, -0.165f, -0.0425f), new Vector3(0.007f, 0.1f, 0.003f), _orange, keepCollider: