Decompiled source of Bifrost v0.2.0

Bifrost.dll

Decompiled 16 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.Json;
using AskaShared.Game;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Cinemachine;
using Fusion;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using SSSGame;
using SSSGame.Controllers;
using SSSGame.Network;
using SSSGame.Render;
using SSSGame.UI;
using SandSailorStudio.Inventory;
using SandSailorStudio.Localization;
using SandSailorStudio.Storage;
using SandSailorStudio.UI;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEngine.VFX;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace AskaTeleportation
{
	internal static class ArchConfirmDialog
	{
		private const string Title = "Open Portal";

		private const string ConfirmCaptionKey = "common.confirm";

		private const string CancelCaptionKey = "common.cancel";

		private const string Prefix = "[Portals][attune]";

		private const float VanishGraceSeconds = 5f;

		private static Action<ConfirmActionMenu> _confirmHandler;

		private static Action<ConfirmActionMenu> _cancelHandler;

		private static Structure _arch;

		private static Menu _menu;

		private static bool _tracking;

		private static float _lastAliveAt;

		internal static bool IsOpen
		{
			get
			{
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Expected O, but got Unknown
				try
				{
					return (Object)(object)_menu != (Object)null && _menu.IsActive;
				}
				catch (Exception ex)
				{
					ManualLogSource log = Plugin.Log;
					bool flag = default(bool);
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(35, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" reading the dialog's state threw: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					log.LogWarning(val);
					return false;
				}
			}
		}

		internal static bool TryOpen(Structure arch)
		{
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Expected O, but got Unknown
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Expected O, but got Unknown
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Expected O, but got Unknown
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Expected O, but got Unknown
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Expected O, but got Unknown
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Expected O, but got Unknown
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Expected O, but got Unknown
			//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Expected O, but got Unknown
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0386: Expected O, but got Unknown
			//IL_0441: Unknown result type (might be due to invalid IL or missing references)
			//IL_0448: Expected O, but got Unknown
			if ((Object)(object)arch == (Object)null)
			{
				return false;
			}
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val;
			if (_tracking)
			{
				if (!HasVanished())
				{
					ManualLogSource log = Plugin.Log;
					val = new BepInExInfoLogInterpolatedStringHandler(44, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" a confirm dialog is already open - ignoring");
					}
					log.LogInfo(val);
					return false;
				}
				ManualLogSource log2 = Plugin.Log;
				val = new BepInExInfoLogInterpolatedStringHandler(68, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" the previous confirm dialog vanished without a callback - reopening");
				}
				log2.LogInfo(val);
				Forget();
			}
			ItemCost portalCost = Plugin.PortalCost;
			if (portalCost == null || (!portalCost.IsFree && !portalCost.IsResolved))
			{
				Toast("The portal cost is not configured.", (NotificationType)1);
				ManualLogSource log3 = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(25, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" refused: cost unresolved");
				}
				log3.LogWarning(val2);
				return false;
			}
			MenuManager instance;
			try
			{
				instance = MenuManager.Instance;
			}
			catch (Exception ex)
			{
				ManualLogSource log4 = Plugin.Log;
				BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(37, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" reading MenuManager.Instance threw: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<Exception>(ex);
				}
				log4.LogError(val3);
				return false;
			}
			bool flag2 = default(bool);
			if ((Object)(object)instance == (Object)null)
			{
				ManualLogSource log5 = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(63, 1, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" there is no MenuManager - the confirm dialog cannot be opened.");
				}
				log5.LogWarning(val2);
				return false;
			}
			ConfirmActionMenu val4 = ResolvePrefab(instance, arch);
			if ((Object)(object)val4 == (Object)null)
			{
				ManualLogSource log6 = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(85, 1, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" no ConfirmActionMenu prefab could be resolved - the confirm dialog cannot be opened.");
				}
				log6.LogWarning(val2);
				return false;
			}
			string text = "Open this portal for " + portalCost.Describe() + "?";
			ConfirmActionMenuParameters val5;
			try
			{
				val5 = new ConfirmActionMenuParameters
				{
					Title = "Open Portal",
					Message = text,
					ConfirmMessage = "common.confirm",
					CancelMessage = "common.cancel",
					CloseOnConfirm = true,
					HideCancelButton = false,
					DontCloseOnEscape = false
				};
			}
			catch (Exception ex2)
			{
				ManualLogSource log7 = Plugin.Log;
				BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(40, 2, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" building the confirm parameters threw: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<Exception>(ex2);
				}
				log7.LogError(val3);
				return false;
			}
			_arch = arch;
			_confirmHandler = HandleConfirm;
			_cancelHandler = HandleCancel;
			try
			{
				val5.OnConfirm = DelegateSupport.ConvertDelegate<Action<ConfirmActionMenu>>((Delegate)_confirmHandler);
				val5.OnCancel = DelegateSupport.ConvertDelegate<Action<ConfirmActionMenu>>((Delegate)_cancelHandler);
			}
			catch (Exception ex3)
			{
				ManualLogSource log8 = Plugin.Log;
				BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(48, 2, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" converting the confirm/cancel callbacks threw: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<Exception>(ex3);
				}
				log8.LogError(val3);
				Forget();
				return false;
			}
			Menu val6;
			try
			{
				val6 = instance.OpenMenuPrefab((Menu)(object)val4, (MenuParameters)(object)val5);
			}
			catch (Exception ex4)
			{
				ManualLogSource log9 = Plugin.Log;
				BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(35, 2, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" opening the confirm dialog threw: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<Exception>(ex4);
				}
				log9.LogError(val3);
				Forget();
				return false;
			}
			if ((Object)(object)val6 == (Object)null)
			{
				ManualLogSource log10 = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(67, 1, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" OpenMenuPrefab returned nothing - the confirm dialog did not open.");
				}
				log10.LogWarning(val2);
				Forget();
				return false;
			}
			_menu = val6;
			_tracking = true;
			_lastAliveAt = SafeNow();
			ManualLogSource log11 = Plugin.Log;
			val = new BepInExInfoLogInterpolatedStringHandler(35, 3, ref flag2);
			if (flag2)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" dialog opened for the arch at ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ArchInteraction.PositionText(arch));
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": '");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'");
			}
			log11.LogInfo(val);
			if (!RawTextRenders("Open Portal"))
			{
				ManualLogSource log12 = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(152, 1, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" the localizer does not pass unknown keys through, so the dialog's title and message may not read as written - repeating the question as a notification.");
				}
				log12.LogWarning(val2);
				Toast(text);
			}
			return true;
		}

		private static void HandleConfirm(ConfirmActionMenu menu)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			Structure arch = _arch;
			Forget();
			try
			{
				Attune(arch);
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(34, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" handling the confirmation threw: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log.LogError(val);
			}
		}

		private static void HandleCancel(ConfirmActionMenu menu)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			Forget();
			ManualLogSource log = Plugin.Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(10, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" cancelled");
			}
			log.LogInfo(val);
		}

		private static void Attune(Structure arch)
		{
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Expected O, but got Unknown
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Expected O, but got Unknown
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Expected O, but got Unknown
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Expected O, but got Unknown
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Expected O, but got Unknown
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Expected O, but got Unknown
			if ((Object)(object)arch == (Object)null)
			{
				return;
			}
			PortalRegistry current = PortalRegistry.Current;
			if (current == null)
			{
				Toast("Portals are not ready yet.", (NotificationType)1);
				return;
			}
			bool flag = default(bool);
			if (!ArchTargeting.TrySnapshot(arch, out var snapshot))
			{
				Toast("That portal cannot be opened any more.", (NotificationType)1);
				ManualLogSource log = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(75, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" confirm refused: the arch is gone, dismantled or not built - nothing taken");
				}
				log.LogWarning(val);
				return;
			}
			if (current.TryFindByArch(arch, out var record))
			{
				Toast(record.Name + " is already open.");
				return;
			}
			ItemCost portalCost = Plugin.PortalCost;
			if (portalCost == null || (!portalCost.IsFree && !portalCost.IsResolved))
			{
				Toast("The portal cost is not configured.", (NotificationType)1);
				ManualLogSource log2 = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(33, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" confirm refused: cost unresolved");
				}
				log2.LogWarning(val);
				return;
			}
			int num = 0;
			BepInExInfoLogInterpolatedStringHandler val3;
			if (!portalCost.IsFree)
			{
				ItemCollection val2 = PlayerInventory();
				if (val2 == null)
				{
					Toast("Portals are not ready yet.", (NotificationType)1);
					ManualLogSource log3 = Plugin.Log;
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(37, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" confirm refused: no player inventory");
					}
					log3.LogWarning(val);
					return;
				}
				int itemQuantity;
				try
				{
					itemQuantity = val2.GetItemQuantity(portalCost.Info);
				}
				catch (Exception ex)
				{
					Toast("Portals are not ready yet.", (NotificationType)1);
					ManualLogSource log4 = Plugin.Log;
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(41, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" confirm refused: inventory read failed: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					log4.LogWarning(val);
					return;
				}
				if (itemQuantity < portalCost.Count)
				{
					Toast("Opening needs " + portalCost.Describe() + ".", (NotificationType)1);
					ManualLogSource log5 = Plugin.Log;
					val3 = new BepInExInfoLogInterpolatedStringHandler(31, 4, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>("[Portals][attune]");
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" confirm refused: have ");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(itemQuantity);
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(", need ");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(portalCost.Count);
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" ");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(portalCost.ItemName);
					}
					log5.LogInfo(val3);
					return;
				}
				try
				{
					num = val2.RemoveItems(portalCost.Info, portalCost.Count);
				}
				catch (Exception ex2)
				{
					ManualLogSource log6 = Plugin.Log;
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(39, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" confirm aborted: cost removal failed: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex2.Message);
					}
					log6.LogWarning(val);
					return;
				}
				if (num < portalCost.Count)
				{
					ManualLogSource log7 = Plugin.Log;
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(31, 4, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" confirm aborted: removed ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" of ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(portalCost.Count);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(portalCost.ItemName);
					}
					log7.LogWarning(val);
					Refund(val2, portalCost, num);
					Toast("Opening needs " + portalCost.Describe() + ".", (NotificationType)1);
					return;
				}
			}
			PortalRecord portalRecord = current.Attune(snapshot);
			try
			{
				PortalVisuals.Apply(portalRecord, arch);
			}
			catch (Exception ex3)
			{
				ManualLogSource log8 = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(36, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" the rune could not be applied to ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(portalRecord.Name);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex3.Message);
				}
				log8.LogWarning(val);
			}
			PortalNaming.ApplyPortalName(arch, portalRecord);
			Toast(portalRecord.Name + " opened.");
			ManualLogSource log9 = Plugin.Log;
			val3 = new BepInExInfoLogInterpolatedStringHandler(32, 4, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>("[Portals][attune]");
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" confirmed: consumed ");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(num);
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" ");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(portalCost.IsFree ? "(free)" : portalCost.ItemName);
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(", attuned ");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(portalRecord.Name);
			}
			log9.LogInfo(val3);
			if (current.Portals.Count >= 2)
			{
				PortalTool.RequestDestinationDialog(portalRecord);
			}
		}

		private static void Refund(ItemCollection inventory, ItemCost cost, int consumed)
		{
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			if (inventory == null || cost == null || consumed <= 0)
			{
				return;
			}
			bool flag = default(bool);
			try
			{
				int num = inventory.AddItems(cost.Info, consumed);
				if (num < consumed)
				{
					ManualLogSource log = Plugin.Log;
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(42, 5, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" refund incomplete: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" of ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(consumed);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(cost.ItemName);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" returned - ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(consumed - num);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" lost");
					}
					log.LogError(val);
				}
				else
				{
					ManualLogSource log2 = Plugin.Log;
					BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(11, 3, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("[Portals][attune]");
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" refunded ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(consumed);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(cost.ItemName);
					}
					log2.LogInfo(val2);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log3 = Plugin.Log;
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(24, 4, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" refund failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(consumed);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(cost.ItemName);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" lost: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log3.LogError(val);
			}
		}

		private static ItemCollection PlayerInventory()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			try
			{
				Character localCharacter = PortalTool.LocalCharacter;
				if ((Object)(object)localCharacter == (Object)null)
				{
					return null;
				}
				InventoryComponent inventory = localCharacter.Inventory;
				return ((Object)(object)inventory != (Object)null) ? inventory.GetItemCollection() : null;
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(33, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" player inventory lookup failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				log.LogWarning(val);
				return null;
			}
		}

		private static bool HasVanished()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			if (!_tracking)
			{
				return true;
			}
			float num = SafeNow();
			bool flag;
			try
			{
				flag = (Object)(object)_menu != (Object)null && _menu.IsActive;
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				bool flag2 = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(35, 2, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" reading the dialog's state threw: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log.LogError(val);
				flag = false;
			}
			if (flag)
			{
				_lastAliveAt = num;
				return false;
			}
			return num - _lastAliveAt > 5f;
		}

		private static void Forget()
		{
			_tracking = false;
			_menu = null;
			_arch = null;
		}

		internal static void Reset()
		{
			Forget();
			_lastAliveAt = 0f;
		}

		private static ConfirmActionMenu ResolvePrefab(MenuManager manager, Structure prefabSource)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				ConfirmActionMenu prefab = manager.GetPrefab<ConfirmActionMenu>();
				if ((Object)(object)prefab != (Object)null)
				{
					return prefab;
				}
				ManualLogSource log = Plugin.Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(106, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" MenuManager has no registered ConfirmActionMenu prefab - falling back to the arch's own dismantle dialog.");
				}
				log.LogInfo(val);
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(104, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" MenuManager.GetPrefab<ConfirmActionMenu>() failed (");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(") - falling back to the arch's own dismantle dialog.");
				}
				log2.LogWarning(val2);
			}
			try
			{
				if ((Object)(object)prefabSource != (Object)null)
				{
					ConfirmActionMenu confirmDismantleMenu = prefabSource._confirmDismantleMenu;
					if ((Object)(object)confirmDismantleMenu != (Object)null)
					{
						return confirmDismantleMenu;
					}
				}
			}
			catch (Exception ex2)
			{
				ManualLogSource log3 = Plugin.Log;
				BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(51, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" reading the arch's dismantle dialog prefab threw: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<Exception>(ex2);
				}
				log3.LogError(val3);
			}
			return null;
		}

		private static bool RawTextRenders(string sample)
		{
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			if (string.IsNullOrEmpty(sample))
			{
				return true;
			}
			bool flag3 = default(bool);
			try
			{
				LocalizationManager instance = LocalizationManager.Instance;
				BepInExInfoLogInterpolatedStringHandler val;
				if ((Object)(object)instance == (Object)null)
				{
					ManualLogSource log = Plugin.Log;
					bool flag = default(bool);
					val = new BepInExInfoLogInterpolatedStringHandler(108, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" there is no LocalizationManager to check raw-text rendering against - assuming the text renders as written.");
					}
					log.LogInfo(val);
					return true;
				}
				string text = instance.Loc(sample, false);
				bool flag2 = string.Equals(text, sample, StringComparison.Ordinal);
				ManualLogSource log2 = Plugin.Log;
				val = new BepInExInfoLogInterpolatedStringHandler(54, 4, ref flag3);
				if (flag3)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" raw-text check: Loc(\"");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(sample);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\") -> \"");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\" (renders as written: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(flag2 ? "yes" : "NO");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(").");
				}
				log2.LogInfo(val);
				return flag2;
			}
			catch (Exception ex)
			{
				ManualLogSource log3 = Plugin.Log;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(27, 2, ref flag3);
				if (flag3)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" the raw-text check threw: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
				}
				log3.LogError(val2);
				return true;
			}
		}

		private static float SafeNow()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			try
			{
				return Time.unscaledTime;
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(26, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" reading the clock threw: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log.LogError(val);
				return 0f;
			}
		}

		private static void Toast(string message)
		{
			Toast(message, (NotificationType)0);
		}

		private static void Toast(string message, NotificationType type)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			bool flag = default(bool);
			if ((int)type == 1)
			{
				try
				{
					string text = message;
					int hashCode = message.GetHashCode();
					float num = 1f;
					Color val = default(Color);
					((Color)(ref val))..ctor(0.85f, 0.2f, 0.18f, 1f);
					NotificationMenu.DisplayStacking((NotificationType)1, (StackingType)0, ref text, ref hashCode, ref num, (Sprite)null, val, val);
					return;
				}
				catch (Exception ex)
				{
					ManualLogSource log = Plugin.Log;
					BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(41, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("[Portals][attune]");
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" red notification failed, using default: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
					}
					log.LogWarning(val2);
				}
			}
			try
			{
				string text2 = message;
				NotificationMenu.Display(type, ref text2, false);
			}
			catch (Exception ex2)
			{
				ManualLogSource log2 = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(22, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" notification failed: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex2.Message);
				}
				log2.LogWarning(val2);
			}
		}
	}
	internal static class ArchInteraction
	{
		internal const string HolderName = "PortalDeposit";

		private const string AreaChildName = "ActivityInteractionArea";

		private const string EyeOfOdinPathFragment = "InteractionAreaComplete/StorageInteraction";

		internal static readonly List<Structure> Pending = new List<Structure>();

		private static readonly HashSet<string> _loggedFailures = new HashSet<string>();

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

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

		internal static bool WidgetRefreshUnsafe(Structure arch)
		{
			try
			{
				return (Object)(object)arch != (Object)null && _refileFailed.Contains(((Object)arch).GetInstanceID());
			}
			catch (Exception)
			{
				return true;
			}
		}

		private static void L(string message)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			ManualLogSource log = Plugin.Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Portals][attune] ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(message);
			}
			log.LogInfo(val);
		}

		private static void LogOnce(string key, string message)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			if (_loggedFailures.Add(key))
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(18, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Portals][attune] ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(message);
				}
				log.LogWarning(val);
			}
		}

		internal static bool IsInjected(Structure arch)
		{
			return (Object)(object)FindHolder(arch) != (Object)null;
		}

		internal static Interaction InjectedInteractionFor(Structure arch)
		{
			try
			{
				Transform val = FindHolder(arch);
				if ((Object)(object)val == (Object)null)
				{
					return null;
				}
				StorageInteraction val2 = FindStorage(val, (StorageInteractionType)4);
				return ((Object)(object)val2 != (Object)null) ? ((Il2CppObjectBase)val2).TryCast<Interaction>() : null;
			}
			catch (Exception ex)
			{
				LogOnce("injected-interaction-for", "InjectedInteractionFor failed: " + ex.Message);
				return null;
			}
		}

		internal static bool TryGetArch(InteractionSession session, out Structure arch)
		{
			arch = null;
			try
			{
				if (session == null)
				{
					return false;
				}
				return TryGetArch(session.Interaction, out arch);
			}
			catch (Exception ex)
			{
				LogOnce("try-get-arch", "TryGetArch failed: " + ex.Message);
				arch = null;
				return false;
			}
		}

		internal static bool TryGetArch(Interaction interaction, out Structure arch)
		{
			arch = null;
			try
			{
				if ((Object)(object)interaction == (Object)null)
				{
					return false;
				}
				if (!_injected.Contains(((Il2CppObjectBase)interaction).Pointer))
				{
					return false;
				}
				Transform val = ((Component)interaction).transform;
				while ((Object)(object)val != (Object)null && ((Object)val).name != "PortalDeposit")
				{
					val = val.parent;
				}
				if ((Object)(object)val == (Object)null)
				{
					return false;
				}
				Structure componentInParent = ((Component)val).GetComponentInParent<Structure>();
				if ((Object)(object)componentInParent == (Object)null || !ArchTargeting.IsArch(componentInParent))
				{
					return false;
				}
				arch = componentInParent;
				return true;
			}
			catch (Exception ex)
			{
				LogOnce("try-get-arch-interaction", "TryGetArch(Interaction) failed: " + ex.Message);
				arch = null;
				return false;
			}
		}

		internal static bool TryInject(Structure arch, out string reason)
		{
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Expected O, but got Unknown
			GameObject val = null;
			try
			{
				if ((Object)(object)arch == (Object)null)
				{
					reason = "no-arch";
					return false;
				}
				if (!ArchTargeting.IsArch(arch))
				{
					reason = "not-an-arch";
					return false;
				}
				bool dismantled;
				bool isActive;
				try
				{
					dismantled = arch.Dismantled;
					isActive = arch.IsActive;
				}
				catch (Exception ex)
				{
					LogOnce("arch-state", "arch state unreadable: " + ex.Message);
					reason = "arch-state-unreadable";
					return false;
				}
				if (dismantled)
				{
					reason = "dismantled";
					return false;
				}
				if (!isActive)
				{
					reason = "not-built";
					return false;
				}
				if (ArchTargeting.IsUnderConstruction(arch))
				{
					reason = "not-built";
					return false;
				}
				StructureInteractionArea val2 = FindArea(arch);
				if ((Object)(object)val2 == (Object)null)
				{
					reason = "no-interaction-area";
					return false;
				}
				if ((Object)(object)((Component)val2).transform.Find("PortalDeposit") != (Object)null)
				{
					reason = "already-injected";
					return false;
				}
				INetworkInteractable val3 = ResolveArchNi(val2);
				if (val3 == null)
				{
					reason = "no-network-interactable";
					return false;
				}
				Pickable areaPickable = ResolveAreaPickable(val2);
				if (!FindEyeOfOdinSource(out var sourceActivation, out var sourceContainer) || (Object)(object)sourceActivation == (Object)null || (Object)(object)sourceContainer == (Object)null)
				{
					reason = "source-missing";
					return false;
				}
				val = new GameObject("PortalDeposit");
				val.SetActive(false);
				val.transform.SetParent(((Component)val2).transform, false);
				GameObject val4 = Object.Instantiate<GameObject>(sourceActivation, val.transform, false);
				((Object)val4).name = "ActivationInteraction";
				GameObject obj = Object.Instantiate<GameObject>(sourceContainer, val.transform, false);
				((Object)obj).name = "Container";
				ItemContainerComponent component = obj.GetComponent<ItemContainerComponent>();
				if ((Object)(object)component == (Object)null)
				{
					LogOnce("clone-container", "cloned Container has no ItemContainerComponent");
					Cleanup(val);
					reason = "container-missing";
					return false;
				}
				InitializeContainer(component);
				DestroyAll<NetworkActivationState>(val4);
				DestroyAll<AnimatorEventPlaySounds>(val4);
				DestroyAll<ActivationInteraction>(val4);
				StorageInteraction val5 = KeepMenuStorageOnly(val4);
				if ((Object)(object)val5 == (Object)null)
				{
					LogOnce("clone-incomplete", "clone yielded no InventoryMenu StorageInteraction");
					Cleanup(val);
					reason = "clone-incomplete";
					return false;
				}
				RePointStorage(val5, component, ((Component)arch).gameObject);
				List<Interaction> list = new List<Interaction> { (Interaction)(object)val5 };
				BindAreas(val2, list);
				val.SetActive(true);
				for (int i = 0; i < list.Count; i++)
				{
					try
					{
						list[i].InitializeInteractable();
					}
					catch (Exception ex2)
					{
						LogOnce("init-interactable", "InitializeInteractable failed: " + ex2.Message);
					}
				}
				for (int j = 0; j < list.Count; j++)
				{
					Interaction it = list[j];
					MoveToArchInteractable(val3, it);
					RegisterWithInteractable(val3, it);
					EnsurePickable(it, areaPickable);
				}
				val.SetActive(false);
				val.SetActive(true);
				RegisterWithArea(val2, list);
				ResyncContainer(val5, component);
				UnfileFromEyeCollection(component, val, arch);
				NoteInjected(list);
				L("injected arch at " + PositionText(arch));
				reason = null;
				return true;
			}
			catch (Exception ex3)
			{
				LogOnce("inject", "injection failed: " + ex3.Message);
				Cleanup(val);
				reason = "exception";
				return false;
			}
		}

		private static StorageInteraction KeepMenuStorageOnly(GameObject cloneActivation)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Invalid comparison between Unknown and I4
			StorageInteraction val = null;
			Il2CppArrayBase<StorageInteraction> components = cloneActivation.GetComponents<StorageInteraction>();
			int num = components?.Length ?? 0;
			for (int i = 0; i < num; i++)
			{
				StorageInteraction val2 = components[i];
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				if ((int)ReadStorageType(val2) == 4 && (Object)(object)val == (Object)null)
				{
					val = val2;
					continue;
				}
				try
				{
					Object.DestroyImmediate((Object)(object)val2);
				}
				catch (Exception ex)
				{
					LogOnce("destroy-storage", "destroying a cloned StorageInteraction failed: " + ex.Message);
				}
			}
			return val;
		}

		private static void RePointStorage(StorageInteraction storage, ItemContainerComponent container, GameObject archRoot)
		{
			if ((Object)(object)storage == (Object)null)
			{
				return;
			}
			try
			{
				storage.storageContainer = container;
			}
			catch (Exception ex)
			{
				LogOnce("storage-container", "storageContainer failed: " + ex.Message);
			}
			try
			{
				storage.Container = container.container;
			}
			catch (Exception ex2)
			{
				LogOnce("container", "Container failed: " + ex2.Message);
			}
			try
			{
				((Interaction)storage).host = archRoot;
			}
			catch (Exception ex3)
			{
				LogOnce("host", "host failed: " + ex3.Message);
			}
			try
			{
				((Interaction)storage).order = (InteractionOrder)0;
			}
			catch (Exception ex4)
			{
				LogOnce("order", "order failed: " + ex4.Message);
			}
			try
			{
				storage.openStructureOrder = (InteractionOrder)8;
			}
			catch (Exception ex5)
			{
				LogOnce("open-structure-order", "openStructureOrder failed: " + ex5.Message);
			}
			try
			{
				storage.openMilitiaOrder = (InteractionOrder)8;
			}
			catch (Exception ex6)
			{
				LogOnce("open-militia-order", "openMilitiaOrder failed: " + ex6.Message);
			}
			try
			{
				storage.villagerOrder = (InteractionOrder)8;
			}
			catch (Exception ex7)
			{
				LogOnce("villager-order", "villagerOrder failed: " + ex7.Message);
			}
			try
			{
				storage.villagerAbortOrder = (InteractionOrder)8;
			}
			catch (Exception ex8)
			{
				LogOnce("villager-abort-order", "villagerAbortOrder failed: " + ex8.Message);
			}
		}

		private static void InitializeContainer(ItemContainerComponent component)
		{
			bool flag = false;
			try
			{
				flag = component._initialized;
			}
			catch (Exception ex)
			{
				LogOnce("initialized-read", "_initialized read failed: " + ex.Message);
			}
			if (!flag)
			{
				try
				{
					component.Initialize();
				}
				catch (Exception ex2)
				{
					LogOnce("container-init", "ItemContainerComponent.Initialize failed: " + ex2.Message);
				}
			}
		}

		private static void UnfileFromEyeCollection(ItemContainerComponent containerComponent, GameObject holder, Structure arch)
		{
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)containerComponent == (Object)null)
			{
				return;
			}
			ItemContainer val = null;
			try
			{
				val = containerComponent.container;
			}
			catch (Exception ex)
			{
				LogOnce("unfile-container-read", "container read failed: " + ex.Message);
			}
			InventoryComponent val2 = null;
			try
			{
				val2 = containerComponent.inventoryComponent;
			}
			catch (Exception ex2)
			{
				LogOnce("unfile-inventory-read", "inventoryComponent read failed: " + ex2.Message);
			}
			if (val == null || (Object)(object)val2 == (Object)null)
			{
				LogOnce("unfile-missing", "cannot unfile container: container or inventoryComponent is null");
				return;
			}
			string text = "?";
			try
			{
				text = PathOf(((Component)val2).transform);
			}
			catch (Exception ex3)
			{
				text = "EX: " + ex3.Message;
			}
			ItemCollection val3 = null;
			try
			{
				val3 = val2.GetItemCollection();
			}
			catch (Exception ex4)
			{
				LogOnce("unfile-collection-read", "GetItemCollection failed: " + ex4.Message);
			}
			if (val3 == null)
			{
				LogOnce("unfile-collection-null", "Eye of Odin inventory has no ItemCollection");
				return;
			}
			try
			{
				val3.RemoveContainer(val);
			}
			catch (Exception ex5)
			{
				LogOnce("unfile-remove", "RemoveContainer failed: " + ex5.Message);
				return;
			}
			bool flag = false;
			try
			{
				GameObject val4 = (((Object)(object)holder != (Object)null) ? holder : ((Component)arch).gameObject);
				ItemCollection val5 = new ItemCollection();
				val5.Setup(val4, "PortalDeposit");
				val5.AddContainer(val);
				flag = val.Inventory != null;
			}
			catch (Exception ex6)
			{
				LogOnce("refile", "re-filing the container into a private collection failed: " + ex6.Message);
			}
			if (!flag)
			{
				try
				{
					_refileFailed.Add(((Object)arch).GetInstanceID());
				}
				catch (Exception ex7)
				{
					LogOnce("refile-mark", "marking the arch failed: " + ex7.Message);
				}
				L("container unfiled from " + text + " collection but NOT re-filed - the widget refresh is skipped for this arch");
			}
			else
			{
				L("container unfiled from " + text + " collection and re-filed into a private one");
			}
		}

		private static void BindAreas(StructureInteractionArea area, List<Interaction> injected)
		{
			IInteractionArea val = null;
			try
			{
				val = ((Il2CppObjectBase)area).TryCast<IInteractionArea>();
			}
			catch (Exception ex)
			{
				LogOnce("area-cast", "area TryCast<IInteractionArea> failed: " + ex.Message);
			}
			if (val == null)
			{
				LogOnce("area-cast-null", "StructureInteractionArea does not cast to IInteractionArea");
				return;
			}
			for (int i = 0; i < injected.Count; i++)
			{
				Interaction val2 = injected[i];
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				try
				{
					val2._interactionArea = val;
				}
				catch (Exception ex2)
				{
					LogOnce("bind-area", "binding Interaction._interactionArea failed: " + ex2.Message);
				}
				StorageInteraction val3 = null;
				try
				{
					val3 = ((Il2CppObjectBase)val2).TryCast<StorageInteraction>();
				}
				catch (Exception ex3)
				{
					LogOnce("bind-cast", "TryCast<StorageInteraction> failed: " + ex3.Message);
				}
				if (!((Object)(object)val3 == (Object)null))
				{
					try
					{
						val3._interactionArea = val;
					}
					catch (Exception ex4)
					{
						LogOnce("bind-shadow", "binding StorageInteraction._interactionArea failed: " + ex4.Message);
					}
				}
			}
		}

		private static void MoveToArchInteractable(INetworkInteractable archNi, Interaction it)
		{
			if ((Object)(object)it == (Object)null)
			{
				return;
			}
			INetworkInteractable val = null;
			try
			{
				val = it.interactable;
			}
			catch (Exception ex)
			{
				LogOnce("interactable-read", "interaction.interactable read failed: " + ex.Message);
			}
			if (val != null && SamePtr((Il2CppObjectBase)(object)val, (Il2CppObjectBase)(object)archNi))
			{
				return;
			}
			if (val != null)
			{
				try
				{
					val.UnregisterInteraction(it);
				}
				catch (Exception ex2)
				{
					LogOnce("old-unregister", "unregistering from the source interactable failed: " + ex2.Message);
				}
			}
			bool flag = false;
			try
			{
				archNi.MoveInteractionToThis(it);
				flag = true;
			}
			catch (Exception ex3)
			{
				LogOnce("move-interaction", "MoveInteractionToThis failed: " + ex3.Message);
			}
			if (flag)
			{
				return;
			}
			try
			{
				it.interactable = archNi;
			}
			catch (Exception ex4)
			{
				LogOnce("interactable-write", "interaction.interactable write failed: " + ex4.Message);
			}
		}

		private static void RegisterWithInteractable(INetworkInteractable archNi, Interaction it)
		{
			if ((Object)(object)it == (Object)null)
			{
				return;
			}
			bool flag = false;
			try
			{
				flag = archNi.TryRegisterInteraction(it);
			}
			catch (Exception ex)
			{
				LogOnce("register-interactable", "TryRegisterInteraction failed: " + ex.Message);
			}
			if (flag)
			{
				return;
			}
			try
			{
				archNi.MoveInteractionToThis(it);
			}
			catch (Exception ex2)
			{
				LogOnce("register-move", "MoveInteractionToThis retry failed: " + ex2.Message);
			}
			try
			{
				archNi.TryRegisterInteraction(it);
			}
			catch (Exception ex3)
			{
				LogOnce("register-retry", "TryRegisterInteraction retry failed: " + ex3.Message);
			}
		}

		private static void EnsurePickable(Interaction it, Pickable areaPickable)
		{
			if ((Object)(object)it == (Object)null || (Object)(object)areaPickable == (Object)null)
			{
				return;
			}
			Pickable val = null;
			try
			{
				val = it.GetPickable();
			}
			catch (Exception ex)
			{
				LogOnce("pickable-read", "GetPickable failed: " + ex.Message);
			}
			if ((Object)(object)val != (Object)null)
			{
				return;
			}
			try
			{
				it._cachedPickable = areaPickable;
			}
			catch (Exception ex2)
			{
				LogOnce("pickable-write", "_cachedPickable write failed: " + ex2.Message);
			}
		}

		private static void RegisterWithArea(StructureInteractionArea area, List<Interaction> injected)
		{
			List<Interaction> val = null;
			try
			{
				val = ((StandaloneInteractionArea)area).interactions;
			}
			catch (Exception ex)
			{
				LogOnce("area-list-read", "area.interactions read failed: " + ex.Message);
			}
			if (val == null)
			{
				try
				{
					val = (((StandaloneInteractionArea)area).interactions = new List<Interaction>());
				}
				catch (Exception ex2)
				{
					LogOnce("area-list-create", "area.interactions create failed: " + ex2.Message);
					return;
				}
			}
			for (int i = 0; i < injected.Count; i++)
			{
				Interaction val3 = injected[i];
				if (!((Object)(object)val3 == (Object)null))
				{
					try
					{
						val.Add(val3);
					}
					catch (Exception ex3)
					{
						LogOnce("area-list-add", "area.interactions add failed: " + ex3.Message);
					}
				}
			}
			try
			{
				((StandaloneInteractionArea)area).SetAreaDirty();
			}
			catch (Exception ex4)
			{
				LogOnce("set-area-dirty", "SetAreaDirty failed: " + ex4.Message);
			}
		}

		private static void ResyncContainer(StorageInteraction menuStorage, ItemContainerComponent component)
		{
			ItemContainer val = null;
			try
			{
				val = component.container;
			}
			catch (Exception ex)
			{
				LogOnce("resync-read", "container re-read failed: " + ex.Message);
			}
			if (val == null || (Object)(object)menuStorage == (Object)null)
			{
				return;
			}
			try
			{
				menuStorage.storageContainer = component;
			}
			catch (Exception ex2)
			{
				LogOnce("resync-component", "storageContainer resync failed: " + ex2.Message);
			}
			try
			{
				menuStorage.Container = val;
			}
			catch (Exception ex3)
			{
				LogOnce("resync-container", "Container resync failed: " + ex3.Message);
			}
		}

		private static bool FindEyeOfOdinSource(out GameObject sourceActivation, out GameObject sourceContainer)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Invalid comparison between Unknown and I4
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			sourceActivation = null;
			sourceContainer = null;
			try
			{
				Il2CppArrayBase<StorageInteraction> val = Resources.FindObjectsOfTypeAll<StorageInteraction>();
				int num = val?.Length ?? 0;
				for (int i = 0; i < num; i++)
				{
					StorageInteraction val2 = val[i];
					if ((Object)(object)val2 == (Object)null || (int)ReadStorageType(val2) != 1)
					{
						continue;
					}
					string text;
					try
					{
						text = PathOf(((Component)val2).transform);
					}
					catch
					{
						continue;
					}
					if (text.IndexOf("InteractionAreaComplete/StorageInteraction", StringComparison.Ordinal) < 0)
					{
						continue;
					}
					GameObject gameObject = ((Component)val2).gameObject;
					Transform parent = ((Component)val2).transform.parent;
					Transform val3 = (((Object)(object)parent != (Object)null) ? parent.Find("Container") : null);
					if (!((Object)(object)val3 == (Object)null))
					{
						bool flag;
						try
						{
							Scene scene = gameObject.scene;
							flag = ((Scene)(ref scene)).IsValid();
						}
						catch
						{
							flag = false;
						}
						if (flag || (Object)(object)sourceActivation == (Object)null)
						{
							sourceActivation = gameObject;
							sourceContainer = ((Component)val3).gameObject;
						}
						if (flag)
						{
							break;
						}
					}
				}
				return true;
			}
			catch (Exception ex)
			{
				LogOnce("source-search", "Eye of Odin source search failed: " + ex.Message);
				return false;
			}
		}

		private static StorageInteractionType ReadStorageType(StorageInteraction si)
		{
			//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_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				return si.storageType;
			}
			catch
			{
				return (StorageInteractionType)4;
			}
		}

		private static StructureInteractionArea FindArea(Structure arch)
		{
			try
			{
				Transform val = ((Component)arch).transform.Find("ActivityInteractionArea");
				if ((Object)(object)val != (Object)null)
				{
					StructureInteractionArea component = ((Component)val).GetComponent<StructureInteractionArea>();
					if ((Object)(object)component != (Object)null)
					{
						return component;
					}
				}
			}
			catch (Exception ex)
			{
				LogOnce("area-find", "interaction-area lookup failed: " + ex.Message);
			}
			try
			{
				return ((Component)arch).GetComponentInChildren<StructureInteractionArea>(true);
			}
			catch (Exception ex2)
			{
				LogOnce("area-search", "interaction-area search failed: " + ex2.Message);
				return null;
			}
		}

		private static Transform FindHolder(Structure arch)
		{
			try
			{
				if ((Object)(object)arch == (Object)null)
				{
					return null;
				}
				StructureInteractionArea val = FindArea(arch);
				return ((Object)(object)val != (Object)null) ? ((Component)val).transform.Find("PortalDeposit") : null;
			}
			catch (Exception ex)
			{
				LogOnce("holder-find", "holder lookup failed: " + ex.Message);
				return null;
			}
		}

		private static StorageInteraction FindStorage(Transform holder, StorageInteractionType want)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			Il2CppArrayBase<StorageInteraction> componentsInChildren = ((Component)holder).GetComponentsInChildren<StorageInteraction>(true);
			int num = componentsInChildren?.Length ?? 0;
			for (int i = 0; i < num; i++)
			{
				StorageInteraction val = componentsInChildren[i];
				if ((Object)(object)val != (Object)null && ReadStorageType(val) == want)
				{
					return val;
				}
			}
			return null;
		}

		private static INetworkInteractable ResolveArchNi(StructureInteractionArea area)
		{
			NetworkObjectInteractable val = null;
			try
			{
				val = ((Component)area).gameObject.GetComponent<NetworkObjectInteractable>();
			}
			catch (Exception ex)
			{
				LogOnce("ni-get", "NetworkObjectInteractable lookup failed: " + ex.Message);
			}
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			try
			{
				return ((Il2CppObjectBase)val).TryCast<INetworkInteractable>();
			}
			catch (Exception ex2)
			{
				LogOnce("ni-cast", "NetworkObjectInteractable cast failed: " + ex2.Message);
				return null;
			}
		}

		private static Pickable ResolveAreaPickable(StructureInteractionArea area)
		{
			try
			{
				return ((Component)area).gameObject.GetComponent<Pickable>();
			}
			catch (Exception ex)
			{
				LogOnce("pickable-get", "area Pickable lookup failed: " + ex.Message);
				return null;
			}
		}

		private static void DestroyAll<T>(GameObject go) where T : Component
		{
			try
			{
				Il2CppArrayBase<T> components = go.GetComponents<T>();
				int num = components?.Length ?? 0;
				for (int i = 0; i < num; i++)
				{
					T val = components[i];
					if (!((Object)(object)val == (Object)null))
					{
						try
						{
							Object.DestroyImmediate((Object)(object)val);
						}
						catch (Exception ex)
						{
							LogOnce("destroy-" + typeof(T).Name, "destroying " + typeof(T).Name + " failed: " + ex.Message);
						}
					}
				}
			}
			catch (Exception ex2)
			{
				LogOnce("destroy-all-" + typeof(T).Name, "sweeping " + typeof(T).Name + " failed: " + ex2.Message);
			}
		}

		private static void NoteInjected(List<Interaction> injected)
		{
			for (int i = 0; i < injected.Count; i++)
			{
				try
				{
					Interaction val = injected[i];
					if ((Object)(object)val != (Object)null)
					{
						_injected.Add(((Il2CppObjectBase)val).Pointer);
					}
				}
				catch (Exception ex)
				{
					LogOnce("note-injected", "recording an injected interaction pointer failed: " + ex.Message);
				}
			}
		}

		private static void Cleanup(GameObject holder)
		{
			if ((Object)(object)holder == (Object)null)
			{
				return;
			}
			try
			{
				Il2CppArrayBase<Interaction> componentsInChildren = holder.GetComponentsInChildren<Interaction>(true);
				int num = componentsInChildren?.Length ?? 0;
				for (int i = 0; i < num; i++)
				{
					Interaction val = componentsInChildren[i];
					if ((Object)(object)val != (Object)null)
					{
						_injected.Remove(((Il2CppObjectBase)val).Pointer);
					}
				}
			}
			catch (Exception ex)
			{
				LogOnce("cleanup-injected", "forgetting a half-built holder's interaction pointers failed: " + ex.Message);
			}
			try
			{
				holder.SetActive(false);
				((Object)holder).name = "PortalDeposit(failed)";
				Object.Destroy((Object)(object)holder);
			}
			catch (Exception ex2)
			{
				LogOnce("cleanup", "tearing down a half-built holder failed: " + ex2.Message);
			}
		}

		internal static string PositionText(Structure arch)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Vector3 position = ((Component)arch).transform.position;
				return "(" + position.x.ToString("F1") + ", " + position.y.ToString("F1") + ", " + position.z.ToString("F1") + ")";
			}
			catch
			{
				return "(unknown)";
			}
		}

		private static string PathOf(Transform t)
		{
			string text = string.Empty;
			while ((Object)(object)t != (Object)null)
			{
				text = "/" + ((Object)t).name + text;
				t = t.parent;
			}
			return text;
		}

		private static bool SamePtr(Il2CppObjectBase a, Il2CppObjectBase b)
		{
			try
			{
				return a != null && b != null && a.Pointer == b.Pointer;
			}
			catch
			{
				return false;
			}
		}
	}
	internal static class ArchPromptConfig
	{
		private sealed class Entry
		{
			public PlayerStorageInteractionConfig Original;

			public PlayerStorageInteractionConfig Clone;

			public string CloneName;

			public string Label;
		}

		private sealed class ClonePair
		{
			public Entry Open;

			public Entry Destination;
		}

		[HarmonyPatch(typeof(PlayerStorageInteractionConfig), "CreateSession")]
		internal static class CreateSessionPostfixPatch
		{
			[HarmonyPostfix]
			public static void Postfix(PlayerStorageInteractionConfig __instance, Interaction interaction, InteractionSession __result)
			{
				try
				{
					if (!((Object)(object)__instance == (Object)null) && __result != null && ArchInteraction.TryGetArch(interaction, out var arch) && !((Object)(object)arch == (Object)null))
					{
						PortalRecord record;
						bool attuned = PortalRegistry.Current?.TryFindByArch(arch, out record) ?? false;
						PlayerStorageInteractionConfig val = CloneFor(__instance, attuned);
						if ((Object)(object)val != (Object)null)
						{
							__result.Config = (InteractionConfiguration)(object)val;
						}
					}
				}
				catch (Exception ex)
				{
					WarnOnce("create-session", "prompt label not applied: " + ex.Message);
				}
			}
		}

		[HarmonyPatch(typeof(LocalizationManager))]
		internal static class LanguagePatch
		{
			[HarmonyPostfix]
			[HarmonyPatch("Awake")]
			public static void AwakePostfix(LocalizationManager __instance)
			{
				ReapplyAll(__instance, "Awake");
			}

			[HarmonyPostfix]
			[HarmonyPatch("SetLanguage")]
			public static void SetLanguagePostfix(LocalizationManager __instance)
			{
				ReapplyAll(__instance, "SetLanguage");
			}
		}

		[HarmonyPatch(typeof(LocalizationManager), "Loc", new Type[]
		{
			typeof(string),
			typeof(bool)
		})]
		internal static class LocPatch
		{
			[HarmonyPostfix]
			public static void Postfix(string key, ref string __result)
			{
				Substitute(key, ref __result);
			}
		}

		[HarmonyPatch(typeof(LocalizationManager))]
		internal static class LocOverloadPatch
		{
			[HarmonyPostfix]
			[HarmonyPatch("Loc", new Type[]
			{
				typeof(string),
				typeof(Il2CppReferenceArray<Object>)
			})]
			public static void LocPostfix(string key, ref string __result)
			{
				Substitute(key, ref __result);
			}

			[HarmonyPostfix]
			[HarmonyPatch("LocFallback")]
			public static void LocFallbackPostfix(string key, ref string __result)
			{
				Substitute(key, ref __result);
			}
		}

		private const string OpenLabel = "Open Portal";

		private const string OpenCloneName = "PortalOpenInteractionConfig";

		private const string DestinationLabel = "Change Destination";

		private const string DestinationCloneName = "PortalDestinationInteractionConfig";

		private const string MenuToken = "menu";

		private const string Prefix = "[Portals][attune]";

		private static readonly Dictionary<IntPtr, ClonePair> _clones = new Dictionary<IntPtr, ClonePair>();

		private static readonly Dictionary<string, string> _entries = new Dictionary<string, string>();

		private static readonly HashSet<string> _logged = new HashSet<string>();

		internal static void Register()
		{
			Patch(typeof(CreateSessionPostfixPatch), "PlayerStorageInteractionConfig.CreateSession");
			Patch(typeof(LanguagePatch), "LocalizationManager.Awake/SetLanguage");
			Patch(typeof(LocPatch), "LocalizationManager.Loc(string, bool)");
			Patch(typeof(LocOverloadPatch), "LocalizationManager.Loc(string, array)/LocFallback");
		}

		private static void Patch(Type patchClass, string what)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			try
			{
				Harmony.CreateAndPatchAll(patchClass, (string)null);
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(15, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(what);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" not patched: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				log.LogWarning(val);
			}
		}

		private static void LogOnce(string key, string message)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			if (_logged.Add(key))
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(1, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(message);
				}
				log.LogInfo(val);
			}
		}

		private static void WarnOnce(string key, string message)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			if (_logged.Add(key))
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(1, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(message);
				}
				log.LogWarning(val);
			}
		}

		private static void Substitute(string key, ref string result)
		{
			if (key != null && _entries.Count != 0 && (string.IsNullOrEmpty(result) || !(result != key)) && _entries.TryGetValue(key, out var value))
			{
				result = value;
			}
		}

		private static bool StillTheSameAsset(Entry entry, PlayerStorageInteractionConfig original)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			if (entry == null)
			{
				return true;
			}
			try
			{
				return (Object)(object)entry.Original != (Object)null && ((Il2CppObjectBase)entry.Original).Pointer == ((Il2CppObjectBase)original).Pointer;
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(43, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" re-checking a cached prompt config threw: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				log.LogWarning(val);
				return false;
			}
		}

		private static PlayerStorageInteractionConfig CloneFor(PlayerStorageInteractionConfig original, bool attuned)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			IntPtr pointer = ((Il2CppObjectBase)original).Pointer;
			if (_clones.TryGetValue(pointer, out var value) && (!StillTheSameAsset(value.Open, original) || !StillTheSameAsset(value.Destination, original)))
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(76, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" the cached prompt-config clones no longer belong to this asset - rebuilding");
				}
				log.LogWarning(val);
				_clones.Remove(pointer);
				value = null;
			}
			if (value == null)
			{
				value = new ClonePair();
				_clones[pointer] = value;
			}
			Entry entry = (attuned ? value.Destination : value.Open);
			if (entry != null && (Object)(object)entry.Clone != (Object)null)
			{
				return entry.Clone;
			}
			if (!((InteractionConfiguration)original).Localized)
			{
				LogOnce("label-pending", "prompt label left (loc key) - the config is not localized yet");
				return null;
			}
			string text = (attuned ? "PortalDestinationInteractionConfig" : "PortalOpenInteractionConfig");
			string text2 = (attuned ? "Change Destination" : "Open Portal");
			Object val2 = (Object)(object)Object.Instantiate<PlayerStorageInteractionConfig>(original);
			PlayerStorageInteractionConfig val3 = ((val2 != (Object)null) ? ((Il2CppObjectBase)val2).TryCast<PlayerStorageInteractionConfig>() : null);
			if ((Object)(object)val3 == (Object)null)
			{
				WarnOnce("label-clone-" + text, "prompt label not applied: the storage config could not be cloned for " + text2);
				return null;
			}
			((Object)val3).hideFlags = (HideFlags)61;
			((Object)val3).name = text;
			entry = new Entry
			{
				Original = original,
				Clone = val3,
				CloneName = text,
				Label = text2
			};
			if (attuned)
			{
				value.Destination = entry;
			}
			else
			{
				value.Open = entry;
			}
			LocalizationManager instance = LocalizationManager.Instance;
			int value2 = Apply(entry, instance);
			string key = ((InteractionConfiguration)val3).GetKey("menu");
			string text3 = (((Object)(object)instance != (Object)null) ? Lookup(instance, key) : null);
			LogOnce("label-set-" + text, $"prompt label set: '{text2}', {value2} keys registered; '{key}' -> '{text3 ?? "(missing)"}' in the live table");
			return val3;
		}

		private static void ReapplyAll(LocalizationManager lm, string source)
		{
			try
			{
				if ((Object)(object)lm == (Object)null || _clones.Count == 0)
				{
					return;
				}
				int num = 0;
				foreach (ClonePair value in _clones.Values)
				{
					num += Reapply(value.Open, lm);
					num += Reapply(value.Destination, lm);
				}
				if (num > 0)
				{
					LogOnce("reapply-" + source, $"prompt labels re-applied after {source}: {num} keys");
				}
			}
			catch (Exception ex)
			{
				WarnOnce("reapply-" + source, "prompt label re-apply after " + source + " failed: " + ex.Message);
			}
		}

		private static int Reapply(Entry entry, LocalizationManager lm)
		{
			if (entry == null || (Object)(object)entry.Clone == (Object)null || (Object)(object)entry.Original == (Object)null)
			{
				return 0;
			}
			return Apply(entry, lm);
		}

		private static int Apply(Entry entry, LocalizationManager lm)
		{
			int result = 0;
			if ((Object)(object)lm != (Object)null)
			{
				result = RegisterKeys(entry, lm);
				ClearCache(lm);
			}
			entry.Clone.storageMenuMessage = entry.Label;
			return result;
		}

		private static int RegisterKeys(Entry entry, LocalizationManager lm)
		{
			int num = 0;
			try
			{
				string key = ((InteractionConfiguration)entry.Original).GetKey(string.Empty);
				Dictionary<string, string> localizationStrings = ((InteractionConfiguration)entry.Original).GetLocalizationStrings();
				if (localizationStrings != null && !string.IsNullOrEmpty(key))
				{
					Enumerator<string, string> enumerator = localizationStrings.GetEnumerator();
					while (enumerator.MoveNext())
					{
						string key2 = enumerator.Current.Key;
						if (key2 == null || !key2.StartsWith(key, StringComparison.Ordinal))
						{
							continue;
						}
						string text = key2.Substring(key.Length);
						if (text.Length != 0 && !(text == "menu"))
						{
							string value = Lookup(lm, key2) ?? enumerator.Current.Value;
							if (!string.IsNullOrEmpty(value) && Write(lm, ((InteractionConfiguration)entry.Clone).GetKey(text), value))
							{
								num++;
							}
						}
					}
				}
				else
				{
					WarnOnce("register-strings", "prompt keys: the original config listed no localization strings; only the menu key is registered");
				}
			}
			catch (Exception ex)
			{
				WarnOnce("register-keys", "prompt keys not all registered: " + ex.Message);
			}
			if (Write(lm, ((InteractionConfiguration)entry.Clone).GetKey("menu"), entry.Label))
			{
				num++;
			}
			return num;
		}

		private static string Lookup(LocalizationManager lm, string key)
		{
			try
			{
				Dictionary<string, string> localizedStrings = lm.LocalizedStrings;
				if (localizedStrings != null && localizedStrings.ContainsKey(key))
				{
					return localizedStrings[key];
				}
			}
			catch (Exception ex)
			{
				WarnOnce("lookup", "live-table read failed, using the field text: " + ex.Message);
			}
			return null;
		}

		private static bool Write(LocalizationManager lm, string key, string value)
		{
			if (string.IsNullOrEmpty(key) || value == null)
			{
				return false;
			}
			bool flag = false;
			flag |= Put(lm._localizedStrings, key, value, "_localizedStrings");
			flag |= Put(lm.LocalizedStrings, key, value, "LocalizedStrings");
			flag |= Put(lm._localizedFallbackStrings, key, value, "_localizedFallbackStrings");
			flag |= Put(lm.FallbackLocalizedStrings, key, value, "FallbackLocalizedStrings");
			try
			{
				LocalizationManager._allKeys?.Add(key);
			}
			catch (Exception ex)
			{
				WarnOnce("all-keys", "key set not updated: " + ex.Message);
			}
			_entries[key] = value;
			return flag;
		}

		private static bool Put(Dictionary<string, string> table, string key, string value, string which)
		{
			if (table == null)
			{
				return false;
			}
			try
			{
				table[key] = value;
				return true;
			}
			catch (Exception ex)
			{
				WarnOnce("put-" + which, "write into " + which + " failed: " + ex.Message);
				return false;
			}
		}

		private static void ClearCache(LocalizationManager lm)
		{
			try
			{
				lm._cache?.Clear();
			}
			catch (Exception ex)
			{
				WarnOnce("cache-clear", "localization cache not cleared: " + ex.Message);
			}
		}
	}
	[HarmonyPatch(typeof(Structure))]
	public static class ArchSpawnPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("AfterSpawned")]
		public static void AfterSpawned(Structure __instance)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			try
			{
				if (!ArchTargeting.IsArch(__instance))
				{
					return;
				}
				ArchTargeting.NoteLoaded(__instance);
				if (ArchInteraction.TryInject(__instance, out var reason) || (reason != "source-missing" && reason != "not-built"))
				{
					return;
				}
				for (int i = 0; i < ArchInteraction.Pending.Count; i++)
				{
					if ((Object)(object)ArchInteraction.Pending[i] == (Object)(object)__instance)
					{
						return;
					}
				}
				ArchInteraction.Pending.Add(__instance);
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(42, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Portals][attune] arch spawn hook failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				log.LogWarning(val);
			}
		}
	}
	internal readonly struct ArchSnapshot
	{
		internal Vector3 Position { get; }

		internal Vector3 OpeningAxis { get; }

		internal string Name { get; }

		internal int UniqueId { get; }

		internal ArchSnapshot(Vector3 position, Vector3 openingAxis, string name, int uniqueId)
		{
			//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_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)
			Position = position;
			OpeningAxis = openingAxis;
			Name = name;
			UniqueId = uniqueId;
		}
	}
	internal static class ArchTargeting
	{
		internal const string ArchTemplateName = "Item_Decoration_IvyArch";

		private static PickingManager _pickingManager;

		internal static readonly List<Structure> Loaded = new List<Structure>();

		private static readonly List<Structure> _announced = new List<Structure>();

		internal static void NoteLoaded(Structure arch)
		{
			if ((Object)(object)arch == (Object)null || !IsArch(arch))
			{
				return;
			}
			for (int i = 0; i < Loaded.Count; i++)
			{
				if ((Object)(object)Loaded[i] == (Object)(object)arch)
				{
					return;
				}
			}
			Loaded.Add(arch);
		}

		internal static void AnnounceOnce(Structure arch, int id)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			for (int num = _announced.Count - 1; num >= 0; num--)
			{
				if ((Object)(object)_announced[num] == (Object)null)
				{
					_announced.RemoveAt(num);
				}
				else if ((Object)(object)_announced[num] == (Object)(object)arch)
				{
					return;
				}
			}
			_announced.Add(arch);
			ManualLogSource log = Plugin.Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(28, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Portals][sync] arch id=");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(id);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" at ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ArchInteraction.PositionText(arch));
			}
			log.LogInfo(val);
		}

		internal static int UniqueIdOf(Structure arch)
		{
			try
			{
				return ((Object)(object)arch != (Object)null) ? arch._uniqueId : 0;
			}
			catch
			{
				return 0;
			}
		}

		internal static string NameOf(Structure arch)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			if ((Object)(object)arch == (Object)null)
			{
				return "";
			}
			bool flag = default(bool);
			try
			{
				string customName = arch.GetCustomName();
				if (!string.IsNullOrWhiteSpace(customName))
				{
					return customName.Trim();
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(32, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Portals] GetCustomName failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				log.LogWarning(val);
			}
			try
			{
				string name = arch.GetName();
				if (!string.IsNullOrWhiteSpace(name))
				{
					return name.Trim();
				}
			}
			catch (Exception ex2)
			{
				ManualLogSource log2 = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(26, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Portals] GetName failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex2.Message);
				}
				log2.LogWarning(val);
			}
			return "";
		}

		internal static bool IsUnderConstruction(Structure arch)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			try
			{
				return (Object)(object)arch != (Object)null && (Object)(object)arch.buildSite != (Object)null;
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(33, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Portals] buildSite read failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				log.LogWarning(val);
				return false;
			}
		}

		internal static bool TrySnapshot(Structure arch, out ArchSnapshot snapshot)
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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)
			snapshot = default(ArchSnapshot);
			if ((Object)(object)arch == (Object)null)
			{
				return false;
			}
			try
			{
				if (arch.Dismantled || !arch.IsActive)
				{
					return false;
				}
				if (IsUnderConstruction(arch))
				{
					return false;
				}
				Vector3 position = ((Component)arch).transform.position;
				snapshot = new ArchSnapshot(position, OpeningAxis(arch), NameOf(arch), UniqueIdOf(arch));
				return true;
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(32, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Portals] arch snapshot failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				log.LogWarning(val);
				snapshot = default(ArchSnapshot);
				return false;
			}
		}

		internal static bool IsArch(Structure s)
		{
			try
			{
				return (Object)(object)s != (Object)null && (Object)(object)s.Template != (Object)null && ((Object)s.Template).name == "Item_Decoration_IvyArch";
			}
			catch
			{
				return false;
			}
		}

		internal static bool TryGetAimedStructure(out Structure s)
		{
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected O, but got Unknown
			s = null;
			try
			{
				PickingManager pickingManager = GetPickingManager();
				if ((Object)(object)pickingManager == (Object)null)
				{
					return false;
				}
				Pickable selectedPickable = pickingManager.SelectedPickable;
				if ((Object)(object)selectedPickable == (Object)null)
				{
					return false;
				}
				GameObject gameObject = ((Component)selectedPickable).gameObject;
				if ((Object)(object)gameObject == (Object)null)
				{
					return false;
				}
				StructureInteraction val = gameObject.GetComponentInParent<StructureInteraction>();
				if ((Object)(object)val == (Object)null)
				{
					val = gameObject.GetComponentInChildren<StructureInteraction>(true);
				}
				if ((Object)(object)val != (Object)null)
				{
					s = val.GetStructure();
				}
				if ((Object)(object)s == (Object)null)
				{
					s = gameObject.GetComponentInParent<Structure>();
				}
				return (Object)(object)s != (Object)null;
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(39, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[Portals] TryGetAimedStructure failed: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
				}
				log.LogWarning(val2);
				s = null;
				return false;
			}
		}

		internal static List<Structure> FindArches()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			List<Structure> list = new List<Structure>();
			try
			{
				Il2CppArrayBase<Structure> val = Object.FindObjectsOfType<Structure>();
				if (val == null)
				{
					return list;
				}
				foreach (Structure item in val)
				{
					if (IsArch(item))
					{
						list.Add(item);
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(29, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[Portals] FindArches failed: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
				}
				log.LogWarning(val2);
			}
			return list;
		}

		internal static Vector3 OpeningAxis(Structure arch)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			//IL_002f: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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)
			try
			{
				Vector3 forward = ((Component)arch).transform.forward;
				forward.y = 0f;
				return (((Vector3)(ref forward)).sqrMagnitude > 0.0001f) ? ((Vector3)(ref forward)).normalized : Vector3.forward;
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(30, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Portals] OpeningAxis failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				log.LogWarning(val);
				return Vector3.forward;
			}
		}

		private static PickingManager GetPickingManager()
		{
			if ((Object)(object)_pickingManager == (Object)null)
			{
				_pickingManager = Object.FindObjectOfType<PickingManager>();
			}
			return _pickingManager;
		}
	}
	internal static class ArchUsePatch
	{
		[HarmonyPatch(typeof(Interaction), "Use")]
		internal static class UsePrefixPatch
		{
			[HarmonyPrefix]
			public static bool Prefix(Interaction __instance, ref bool __result)
			{
				try
				{
					if (!ArchInteraction.TryGetArch(__instance, out var arch) || (Object)(object)arch == (Object)null)
					{
						return true;
					}
					__result = false;
					OnInteract(arch);
					return false;
				}
				catch (Exception ex)
				{
					WarnOnce("use-prefix", "Use prefix failed, deferring to the game: " + ex.Message);
					return true;
				}
			}
		}

		private const string Prefix = "[Portals][attune]";

		private static readonly HashSet<string> _logged = new HashSet<string>();

		internal static void Register()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			try
			{
				Harmony.CreateAndPatchAll(typeof(UsePrefixPatch), (string)null);
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(30, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" Interaction.Use not patched: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				log.LogWarning(val);
			}
		}

		private static void WarnOnce(string key, string message)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			if (_logged.Add(key))
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(1, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(message);
				}
				log.LogWarning(val);
			}
		}

		internal static void OnInteract(Structure arch)
		{
			if (!((Object)(object)arch == (Object)null))
			{
				PortalRegistry current = PortalRegistry.Current;
				PortalRecord record;
				if (current == null)
				{
					Toast("Portals are not ready yet.", (NotificationType)1);
				}
				else if (!current.TryFindByArch(arch, out record))
				{
					ArchConfirmDialog.TryOpen(arch);
				}
				else if (current.Portals.Count < 2)
				{
					Toast("You need at least two Portals to travel the Bifrost", (NotificationType)1);
					Plugin.Log.LogInfo((object)"[Portals][destination] refused: only one portal");
				}
				else
				{
					PortalTool.RequestDestinationDialog(record);
				}
			}
		}

		private static void Toast(string message)
		{
			Toast(message, (NotificationType)0);
		}

		internal static void Toast(string message, NotificationType type)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_0037: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			if ((int)type == 1)
			{
				try
				{
					string text = message;
					int hashCode = message.GetHashCode();
					float num = 1f;
					Color val = default(Color);
					((Color)(ref val))..ctor(0.85f, 0.2f, 0.18f, 1f);
					NotificationMenu.DisplayStacking((NotificationType)1, (StackingType)0, ref text, ref hashCode, ref num, (Sprite)null, val, val);
					return;
				}
				catch (Exception ex)
				{
					WarnOnce("toast-red", "red notification failed, using default: " + ex.Message);
				}
			}
			try
			{
				string text2 = message;
				NotificationMenu.Display(type, ref text2, false);
			}
			catch (Exception ex2)
			{
				WarnOnce("toast", "notification failed: " + ex2.Message);
			}
		}
	}
	internal static class ArchWidgetPatch
	{
		[HarmonyPatch(typeof(PlayerStorageInteractionSession), "RefreshWidgetData")]
		internal static class RefreshWidgetDataPrefixPatch
		{
			[HarmonyPrefix]
			public static bool Prefix(PlayerStorageInteractionSession __instance)
			{
				try
				{
					Structure arch;
					return !ArchInteraction.TryGetArch((InteractionSession)(object)__instance, out arch) || !ArchInteraction.WidgetRefreshUnsafe(arch);
				}
				catch (Exception)
				{
					return true;
				}
			}
		}

		private const string Prefix = "[Portals][attune]";

		internal static void Register()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			try
			{
				Harmony.CreateAndPatchAll(typeof(RefreshWidgetDataPrefixPatch), (string)null);
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(64, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][attune]");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" PlayerStorageInteractionSession.RefreshWidgetData not patched: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				log.LogWarning(val);
			}
		}
	}
	[HarmonyPatch(typeof(Character))]
	public static class CharacterSpawnPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Spawned")]
		public static void Spawned(Character __instance)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			Type[] components = new Type[2]
			{
				typeof(TeleportEngine),
				typeof(PortalTool)
			};
			LocalPlayerTool.AttachOnSpawn(__instance, Plugin.Log, "Teleportation_Tool", Vector3.zero, components);
		}
	}
	internal static class ConfigRename
	{
		private const string Prefix = "[Portals][rename]";

		private const string OldGuid = "mugsy33.teleportation";

		private const string OldRegistryFolder = "Teleportation";

		internal static void Run(ConfigFile config, ManualLogSource log)
		{
			MoveSettings(config, log);
			MoveDevSettings(log);
			MoveRegistry(log);
		}

		private static void MoveSettings(ConfigFile config, ManualLogSource log)
		{
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Expected O, but got Unknown
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Expected O, but got Unknown
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Expected O, but got Unknown
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Expected O, but got Unknown
			bool flag = false;
			string text = null;
			bool flag2 = default(bool);
			try
			{
				text = config.ConfigFilePath;
				string text2 = Path.Combine(Paths.ConfigPath, "mugsy33.teleportation.cfg");
				string text3 = text2 + ".migrated";
				if (File.Exists(text))
				{
					if (File.Exists(text3))
					{
						File.Delete(text3);
						BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(39, 2, ref flag2);
						if (flag2)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][rename]");
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" deleted the migrated legacy settings: ");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text3);
						}
						log.LogInfo(val);
					}
					else if (File.Exists(text2))
					{
						File.Move(text2, text3, overwrite: true);
						BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(29, 2, ref flag2);
						if (flag2)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][rename]");
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" legacy settings archived to ");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text3);
						}
						log.LogInfo(val);
					}
				}
				else if (File.Exists(text2))
				{
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(24, 2, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][rename]");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" legacy settings found: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text2);
					}
					log.LogInfo(val);
					string text4 = text + ".tmp";
					File.Copy(text2, text4, overwrite: true);
					File.Move(text4, text, overwrite: true);
					flag = true;
					val = new BepInExInfoLogInterpolatedStringHandler(19, 2, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][rename]");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" settings moved to ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
					}
					log.LogInfo(val);
					config.Reload();
					File.Move(text2, text3, overwrite: true);
					val = new BepInExInfoLogInterpolatedStringHandler(29, 2, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("[Portals][rename]");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" legacy settings archived to ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text3);
					}
					log.LogInfo(val);
				}
			}
			catch (Exception ex)
			{
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(61, 2, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("[Portals][rename]");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" the settings could not be moved; the old file is untouched. ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
				}
				log.LogWarning(val2);
				if (!flag || text == null)
				{
					return;
				}
				try
				{
					File.Delete(text);
				}
				catch (Exception ex2)
				{
					val2 = new BepInExWarningLogInterpolatedStringHandler(54, 2, ref flag2);
					if (flag2)
					{