Decompiled source of ValkyrieFlightPaths v0.2.0

ValkyrieFlightPaths.dll

Decompiled 10 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;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Extensions;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using Splatform;
using UnityEngine;
using UnityEngine.UI;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ValkyrieFlightPaths
{
	internal static class FlightPathAdminMode
	{
		internal static bool Enabled { get; private set; }

		internal static void Update()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)Player.m_localPlayer == (Object)null) && IsDown(ModConfig.ToggleAdminMapModeShortcut.Value))
			{
				if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.LocalPlayerIsAdminOrHost())
				{
					Enabled = false;
					((Character)Player.m_localPlayer).Message((MessageType)2, "$vfp_admin_required", 0, (Sprite)null);
				}
				else
				{
					Enabled = !Enabled;
					((Character)Player.m_localPlayer).Message((MessageType)2, Enabled ? "$vfp_admin_map_enabled" : "$vfp_admin_map_disabled", 0, (Sprite)null);
				}
			}
		}

		private static bool IsDown(KeyboardShortcut shortcut)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			if ((int)((KeyboardShortcut)(ref shortcut)).MainKey != 0)
			{
				return ((KeyboardShortcut)(ref shortcut)).IsDown();
			}
			return false;
		}
	}
	internal static class FlightPathClearance
	{
		private static readonly int ObstacleMask = LayerMask.GetMask(new string[9] { "Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "terrain", "blocker", "pathblocker", "viewblock" });

		internal static bool HasOpenSky(Vector3 position, Transform ignoredRoot, out Collider obstruction)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			float value = ModConfig.ClearanceRadius.Value;
			float num = Mathf.Max(ModConfig.ClearanceHeight.Value, value * 2f);
			Vector3 val = position + Vector3.up * (value + 0.5f);
			Vector3 val2 = position + Vector3.up * (num - value);
			Collider[] array = Physics.OverlapCapsule(val, val2, value, ObstacleMask, (QueryTriggerInteraction)1);
			foreach (Collider val3 in array)
			{
				if (!((Object)(object)val3 == (Object)null))
				{
					Transform transform = ((Component)val3).transform;
					if (!((Object)(object)ignoredRoot != (Object)null) || (!((Object)(object)transform == (Object)(object)ignoredRoot) && !transform.IsChildOf(ignoredRoot)))
					{
						obstruction = val3;
						return false;
					}
				}
			}
			obstruction = null;
			return true;
		}
	}
	internal sealed class FlightPathDestination
	{
		internal ZDOID Id;

		internal string Name;

		internal Vector3 Position;

		internal bool IsOrigin;

		internal bool AdminOnly;
	}
	internal static class FlightPathMapSelection
	{
		private static readonly List<PinData> Pins = new List<PinData>();

		private static readonly Dictionary<PinData, FlightPathDestination> Destinations = new Dictionary<PinData, FlightPathDestination>();

		private static readonly Dictionary<Selectable, bool> DisabledControls = new Dictionary<Selectable, bool>();

		private static readonly Dictionary<Graphic, bool> HiddenGraphics = new Dictionary<Graphic, bool>();

		private static bool _active;

		private static int _requestId;

		private static int _suppressInputThroughFrame = -1;

		private static ZDOID _originId;

		private static Vector3 _playerPositionWhenOpened;

		internal static bool IsActive => _active;

		internal static bool ShouldSuppressMapInput
		{
			get
			{
				if (!_active)
				{
					return Time.frameCount <= _suppressInputThroughFrame;
				}
				return true;
			}
		}

		internal static void Open(int requestId, ZDOID originId, List<FlightPathDestination> destinations)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Invalid comparison between Unknown and I4
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			Clear();
			if ((Object)(object)Minimap.instance == (Object)null || (Object)(object)Player.m_localPlayer == (Object)null)
			{
				return;
			}
			_active = true;
			_requestId = requestId;
			_originId = originId;
			_playerPositionWhenOpened = ((Component)Player.m_localPlayer).transform.position;
			Minimap.instance.SetMapMode((MapMode)2);
			if ((int)Minimap.instance.m_mode != 2)
			{
				Clear();
				((Character)Player.m_localPlayer).Message((MessageType)2, "$vfp_map_unavailable", 0, (Sprite)null);
				return;
			}
			HideLargeMapControls();
			foreach (FlightPathDestination destination in destinations)
			{
				string text = (destination.IsOrigin ? (destination.Name + " (" + Localization.instance.Localize("$vfp_current") + ")") : destination.Name);
				PinData val = Minimap.instance.AddPin(destination.Position, (PinType)(destination.IsOrigin ? 6 : (destination.AdminOnly ? 2 : 3)), text, false, destination.IsOrigin, 0L, default(PlatformUserID));
				Pins.Add(val);
				Destinations.Add(val, destination);
			}
			((Character)Player.m_localPlayer).Message((MessageType)2, (destinations.Count > 1) ? "$vfp_select_destination" : "$vfp_no_destinations", 0, (Sprite)null);
		}

		internal static bool TrySelect(Vector3 worldPosition)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			if (!_active || (Object)(object)Minimap.instance == (Object)null)
			{
				return false;
			}
			float num = Minimap.instance.m_removeRadius * (Minimap.instance.m_largeZoom * 2f);
			PinData val = null;
			float num2 = num;
			foreach (PinData pin in Pins)
			{
				float num3 = Utils.DistanceXZ(pin.m_pos, worldPosition);
				if (num3 < num2)
				{
					val = pin;
					num2 = num3;
				}
			}
			if (val == null || !Destinations.TryGetValue(val, out var value))
			{
				Player localPlayer = Player.m_localPlayer;
				if (localPlayer != null)
				{
					((Character)localPlayer).Message((MessageType)2, "$vfp_click_destination_pin", 0, (Sprite)null);
				}
				return false;
			}
			if (value.IsOrigin)
			{
				Player localPlayer2 = Player.m_localPlayer;
				if (localPlayer2 != null)
				{
					((Character)localPlayer2).Message((MessageType)2, "$vfp_same_destination", 0, (Sprite)null);
				}
				return false;
			}
			int requestId = _requestId;
			ZDOID originId = _originId;
			_suppressInputThroughFrame = Time.frameCount + 1;
			Clear();
			Minimap.instance.SetMapMode((MapMode)1);
			FlightPathRpc.SelectDestination(requestId, originId, value.Id, FlightPathAdminMode.Enabled);
			return true;
		}

		internal static void CancelForMovement()
		{
			if (_active && !((Object)(object)Minimap.instance == (Object)null))
			{
				_suppressInputThroughFrame = Time.frameCount + 1;
				Minimap.instance.SetMapMode((MapMode)1);
			}
		}

		internal static void MonitorPlayerMovement()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if (_active && !((Object)(object)Player.m_localPlayer == (Object)null))
			{
				Vector3 val = ((Component)Player.m_localPlayer).transform.position - _playerPositionWhenOpened;
				if (((Vector3)(ref val)).sqrMagnitude > 0.040000003f)
				{
					CancelForMovement();
				}
			}
		}

		internal static void Clear()
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Minimap.instance != (Object)null)
			{
				foreach (PinData pin in Pins)
				{
					Minimap.instance.RemovePin(pin);
				}
			}
			Pins.Clear();
			Destinations.Clear();
			RestoreLargeMapControls();
			if ((Object)(object)Minimap.instance != (Object)null)
			{
				Minimap.instance.m_pinUpdateRequired = true;
			}
			_active = false;
			_requestId = 0;
			_originId = ZDOID.None;
			_playerPositionWhenOpened = Vector3.zero;
		}

		internal static bool IsFlightPathPin(PinData pin)
		{
			if (pin != null)
			{
				return Destinations.ContainsKey(pin);
			}
			return false;
		}

		internal static List<PinData> GetPinsForRendering()
		{
			return new List<PinData>(Pins);
		}

		private static void HideLargeMapControls()
		{
			DisabledControls.Clear();
			HiddenGraphics.Clear();
			if ((Object)(object)Minimap.instance?.m_largeRoot == (Object)null)
			{
				return;
			}
			Selectable[] componentsInChildren = Minimap.instance.m_largeRoot.GetComponentsInChildren<Selectable>(true);
			foreach (Selectable val in componentsInChildren)
			{
				if (!DisabledControls.ContainsKey(val))
				{
					DisabledControls.Add(val, val.interactable);
					val.interactable = false;
				}
			}
			Graphic[] componentsInChildren2 = Minimap.instance.m_largeRoot.GetComponentsInChildren<Graphic>(true);
			foreach (Graphic val2 in componentsInChildren2)
			{
				if (!((Object)(object)val2 == (Object)(object)Minimap.instance.m_mapImageLarge) && !HiddenGraphics.ContainsKey(val2))
				{
					HiddenGraphics.Add(val2, ((Behaviour)val2).enabled);
					((Behaviour)val2).enabled = false;
				}
			}
		}

		private static void RestoreLargeMapControls()
		{
			foreach (KeyValuePair<Selectable, bool> disabledControl in DisabledControls)
			{
				if ((Object)(object)disabledControl.Key != (Object)null)
				{
					disabledControl.Key.interactable = disabledControl.Value;
				}
			}
			foreach (KeyValuePair<Graphic, bool> hiddenGraphic in HiddenGraphics)
			{
				if ((Object)(object)hiddenGraphic.Key != (Object)null)
				{
					((Behaviour)hiddenGraphic.Key).enabled = hiddenGraphic.Value;
				}
			}
			DisabledControls.Clear();
			HiddenGraphics.Clear();
		}
	}
	public sealed class FlightPathNode : MonoBehaviour, Hoverable, Interactable, TextReceiver, IPlaced
	{
		private ZNetView _networkView;

		private Piece _piece;

		private void Awake()
		{
			_networkView = ((Component)this).GetComponent<ZNetView>();
			_piece = ((Component)this).GetComponent<Piece>();
			if ((Object)(object)_networkView == (Object)null || !_networkView.IsValid())
			{
				((Behaviour)this).enabled = false;
			}
		}

		public string GetHoverName()
		{
			return Localization.instance.Localize("$vfp_piece_name");
		}

		public string GetHoverText()
		{
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_networkView == (Object)null || !_networkView.IsValid() || (Object)(object)Player.m_localPlayer == (Object)null)
			{
				return string.Empty;
			}
			Player localPlayer = Player.m_localPlayer;
			bool flag = IsCreator(localPlayer.GetPlayerID());
			bool flag2 = IsGlobal();
			bool flag3 = FlightPathAdminMode.Enabled && (Object)(object)ZNet.instance != (Object)null && ZNet.instance.LocalPlayerIsAdminOrHost();
			bool num = flag2 || flag || IsPermitted(localPlayer.GetPlayerID()) || flag3;
			bool flag4 = IsRegistrationOpen();
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("$vfp_piece_name");
			if (num)
			{
				stringBuilder.Append("\n[<color=yellow><b>$KEY_Use</b></color>]");
				AppendOptionalShortcut(stringBuilder, ModConfig.UseFlightPathShortcut.Value);
				stringBuilder.Append(" $vfp_open_map");
				int requiredGoldCost = FlightPayment.GetRequiredGoldCost(localPlayer);
				if (requiredGoldCost > 0)
				{
					stringBuilder.Append(" (").Append(requiredGoldCost).Append(" $item_coins)");
				}
				else
				{
					stringBuilder.Append(" ($vfp_flight_free)");
				}
			}
			else
			{
				stringBuilder.Append("\n$vfp_no_access");
			}
			if (flag || flag3)
			{
				AppendShortcutLine(stringBuilder, ModConfig.RenameFlightPathShortcut.Value, "$vfp_rename");
				if (!flag2)
				{
					AppendShortcutLine(stringBuilder, ModConfig.ManageAccessShortcut.Value, flag4 ? "$vfp_close_registration" : "$vfp_open_registration");
				}
			}
			else if (!flag2 && flag4)
			{
				AppendShortcutLine(stringBuilder, ModConfig.ManageAccessShortcut.Value, IsPermitted(localPlayer.GetPlayerID()) ? "$vfp_unregister" : "$vfp_register");
			}
			if ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.LocalPlayerIsAdminOrHost())
			{
				AppendShortcutLine(stringBuilder, ModConfig.ToggleGlobalShortcut.Value, flag2 ? "$vfp_make_private" : "$vfp_make_global");
			}
			AppendAccessSummary(stringBuilder, flag2);
			return Localization.instance.Localize(stringBuilder.ToString());
		}

		public void OnPlaced()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_networkView == (Object)null) && _networkView.IsValid() && _networkView.IsOwner() && !((Object)(object)Player.m_localPlayer == (Object)null))
			{
				ZDO zDO = _networkView.GetZDO();
				zDO.Set(ZDOVars.s_creatorName, Player.m_localPlayer.GetPlayerName());
				ZDOMan.instance.ForceSendZDO(zDO.m_uid);
			}
		}

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			if (!hold)
			{
				Player val = (Player)(object)((user is Player) ? user : null);
				if (val != null && !((Object)(object)_networkView == (Object)null) && _networkView.IsValid())
				{
					UseFlightPath(val);
					return true;
				}
			}
			return false;
		}

		internal void UseFlightPath(Player player)
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			long playerID = player.GetPlayerID();
			bool flag = FlightPathAdminMode.Enabled && (Object)(object)ZNet.instance != (Object)null && ZNet.instance.LocalPlayerIsAdminOrHost();
			Collider obstruction;
			if (!IsGlobal() && !IsCreator(playerID) && !IsPermitted(playerID) && !flag)
			{
				((Character)player).Message((MessageType)2, "$vfp_no_access", 0, (Sprite)null);
			}
			else if (FlightPathWorldRegistry.ExceedsRegistrationLimit(_networkView.GetZDO()))
			{
				((Character)player).Message((MessageType)2, "$vfp_departure_registration_over_limit", 0, (Sprite)null);
			}
			else if (!FlightPathClearance.HasOpenSky(((Component)this).transform.position, ((Component)this).transform, out obstruction))
			{
				Plugin.Instance.Log.LogDebug((object)$"Flight path blocked by '{((Object)obstruction).name}' at {((Component)obstruction).transform.position}");
				((Character)player).Message((MessageType)2, "$vfp_departure_blocked", 0, (Sprite)null);
			}
			else
			{
				FlightPathRpc.RequestDestinations(_networkView.GetZDO().m_uid);
			}
		}

		internal void ManageAccess(Player player)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			if (IsGlobal())
			{
				((Character)player).Message((MessageType)2, "$vfp_global_registration_unavailable", 0, (Sprite)null);
				return;
			}
			long playerID = player.GetPlayerID();
			if (IsCreator(playerID) || HasAdminManagementAccess())
			{
				FlightPathRpc.ToggleRegistration(_networkView.GetZDO().m_uid);
			}
			else if (IsRegistrationOpen())
			{
				FlightPathRpc.TogglePermitted(_networkView.GetZDO().m_uid, player.GetPlayerName());
			}
			else
			{
				((Character)player).Message((MessageType)2, "$vfp_registration_closed", 0, (Sprite)null);
			}
		}

		public bool UseItem(Humanoid user, ItemData item)
		{
			return false;
		}

		public string GetText()
		{
			ZNetView networkView = _networkView;
			object obj;
			if (networkView == null)
			{
				obj = null;
			}
			else
			{
				ZDO zDO = networkView.GetZDO();
				obj = ((zDO != null) ? zDO.GetString("vfp_name", string.Empty) : null);
			}
			if (obj == null)
			{
				obj = string.Empty;
			}
			return (string)obj;
		}

		public void SetText(string text)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_networkView != (Object)null && _networkView.IsValid())
			{
				FlightPathRpc.RenameFlightPath(_networkView.GetZDO().m_uid, text);
			}
		}

		internal void BeginRename(Player player)
		{
			if (!IsCreator(player.GetPlayerID()) && !HasAdminManagementAccess())
			{
				((Character)player).Message((MessageType)2, "$vfp_rename_owner_only", 0, (Sprite)null);
			}
			else
			{
				TextInput.instance.RequestText((TextReceiver)(object)this, "$vfp_rename", 50);
			}
		}

		private static bool HasAdminManagementAccess()
		{
			if (FlightPathAdminMode.Enabled && (Object)(object)ZNet.instance != (Object)null)
			{
				return ZNet.instance.LocalPlayerIsAdminOrHost();
			}
			return false;
		}

		internal void ToggleGlobal(Player player)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.LocalPlayerIsAdminOrHost())
			{
				((Character)player).Message((MessageType)2, "$vfp_admin_required", 0, (Sprite)null);
			}
			else
			{
				FlightPathRpc.ToggleGlobal(_networkView.GetZDO().m_uid);
			}
		}

		internal bool IsGlobal()
		{
			if ((Object)(object)_networkView != (Object)null && _networkView.IsValid())
			{
				return _networkView.GetZDO().GetBool("vfp_global", false);
			}
			return false;
		}

		private bool IsCreator(long playerId)
		{
			if ((Object)(object)_piece != (Object)null)
			{
				return _piece.GetCreator() == playerId;
			}
			return false;
		}

		private static void AppendOptionalShortcut(StringBuilder text, KeyboardShortcut shortcut)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			if ((int)((KeyboardShortcut)(ref shortcut)).MainKey != 0)
			{
				text.Append(" / <color=yellow><b>");
				text.Append(shortcut);
				text.Append("</b></color>");
			}
		}

		private static void AppendShortcutLine(StringBuilder text, KeyboardShortcut shortcut, string action)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			if ((int)((KeyboardShortcut)(ref shortcut)).MainKey != 0)
			{
				text.Append("\n[<color=yellow><b>");
				text.Append(shortcut);
				text.Append("</b></color>] ");
				text.Append(action);
			}
		}

		private void AppendAccessSummary(StringBuilder text, bool global)
		{
			text.Append("\n\n");
			if (global)
			{
				text.Append("<color=orange>$vfp_global_access</color>");
				return;
			}
			ZDO zDO = _networkView.GetZDO();
			long playerId = (((Object)(object)_piece != (Object)null) ? _piece.GetCreator() : 0);
			string name = zDO.GetString(ZDOVars.s_creatorName, string.Empty);
			name = FilterCharacterName(name, playerId);
			text.Append("$vfp_owner: ");
			text.Append(string.IsNullOrWhiteSpace(name) ? "$vfp_unknown" : name);
			text.Append("\n$vfp_registered:");
			List<KeyValuePair<long, string>> permittedPlayers = GetPermittedPlayers();
			if (permittedPlayers.Count == 0)
			{
				text.Append(" $vfp_none");
				return;
			}
			foreach (KeyValuePair<long, string> item in permittedPlayers)
			{
				string text2 = FilterCharacterName(item.Value, item.Key);
				text.Append("\n- ");
				text.Append(string.IsNullOrWhiteSpace(text2) ? "$vfp_unknown" : text2);
			}
		}

		private static string FilterCharacterName(string name, long playerId)
		{
			return CensorShittyWords.FilterUGC(name ?? string.Empty, (UGCType)2, playerId);
		}

		private bool IsRegistrationOpen()
		{
			return _networkView.GetZDO().GetBool("vfp_registration_open", false);
		}

		private bool IsPermitted(long playerId)
		{
			foreach (KeyValuePair<long, string> permittedPlayer in GetPermittedPlayers())
			{
				if (permittedPlayer.Key == playerId)
				{
					return true;
				}
			}
			return false;
		}

		private List<KeyValuePair<long, string>> GetPermittedPlayers()
		{
			ZDO zDO = _networkView.GetZDO();
			int num = zDO.GetInt("vfp_permitted_count", 0);
			List<KeyValuePair<long, string>> list = new List<KeyValuePair<long, string>>(num);
			for (int i = 0; i < num; i++)
			{
				long num2 = zDO.GetLong("vfp_permitted_id_" + i, 0L);
				if (num2 != 0L)
				{
					list.Add(new KeyValuePair<long, string>(num2, zDO.GetString("vfp_permitted_name_" + i, string.Empty)));
				}
			}
			return list;
		}
	}
	internal static class FlightPathPlacementAuthorization
	{
		private static int _nextRequestId;

		private static int _pendingRequestId;

		private static Vector3 _pendingPosition;

		private static bool _approved;

		private static Vector3 _approvedPosition;

		private static float _approvalExpiresAt;

		private static float _nextRequestAt;

		internal static void UpdateCandidate(Vector3 position)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)ZNet.instance == (Object)null) && !ZNet.instance.IsServer() && ZRoutedRpc.instance != null && (_pendingRequestId == 0 || !(Vector3.Distance(position, _pendingPosition) <= 0.25f)) && !IsApproved(position) && !(Time.time < _nextRequestAt))
			{
				_pendingRequestId = ++_nextRequestId;
				_pendingPosition = position;
				_approved = false;
				_nextRequestAt = Time.time + 0.2f;
				FlightPathRpc.RequestPlacement(_pendingRequestId, position);
			}
		}

		internal static bool IsApproved(Vector3 position)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (_approved && Time.time <= _approvalExpiresAt)
			{
				return Vector3.Distance(position, _approvedPosition) <= 0.25f;
			}
			return false;
		}

		internal static void Complete(int requestId, bool approved, string message)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (requestId == _pendingRequestId)
			{
				_pendingRequestId = 0;
				if (!approved)
				{
					_approved = false;
					return;
				}
				_approved = true;
				_approvedPosition = _pendingPosition;
				_approvalExpiresAt = Time.time + 1f;
			}
		}
	}
	internal static class FlightPathRpc
	{
		private sealed class ActiveFlight
		{
			internal int Id;

			internal float ExpiresAt;
		}

		private const string RequestDestinationsRpc = "VFP_RequestDestinations_v1";

		private const string ReplyDestinationsRpc = "VFP_ReplyDestinations_v1";

		private const string SelectDestinationRpc = "VFP_SelectDestination_v1";

		private const string SelectionResultRpc = "VFP_SelectionResult_v1";

		private const string RequestPlacementRpc = "VFP_RequestPlacement_v1";

		private const string PlacementResultRpc = "VFP_PlacementResult_v1";

		private const string CompleteFlightRpc = "VFP_CompleteFlight_v1";

		private const string ToggleGlobalRpc = "VFP_ToggleGlobal_v1";

		private const string RenameFlightPathRpc = "VFP_RenameFlightPath_v2";

		private const string ManagementResultRpc = "VFP_ManagementResult_v1";

		private const string ToggleRegistrationRpc = "VFP_ToggleRegistration_v3";

		private const string TogglePermittedRpc = "VFP_TogglePermitted_v2";

		private static int _nextRequestId;

		private static int _pendingRequestId;

		private static int _nextFlightId;

		private static readonly Dictionary<long, ActiveFlight> ActiveFlights = new Dictionary<long, ActiveFlight>();

		internal static void Register()
		{
			ZRoutedRpc instance = ZRoutedRpc.instance;
			if (instance != null && !instance.m_functions.ContainsKey(StringExtensionMethods.GetStableHashCode("VFP_RequestDestinations_v1")))
			{
				instance.Register<ZPackage>("VFP_RequestDestinations_v1", (Action<long, ZPackage>)OnRequestDestinations);
				instance.Register<ZPackage>("VFP_ReplyDestinations_v1", (Action<long, ZPackage>)OnReplyDestinations);
				instance.Register<ZPackage>("VFP_SelectDestination_v1", (Action<long, ZPackage>)OnSelectDestination);
				instance.Register<ZPackage>("VFP_SelectionResult_v1", (Action<long, ZPackage>)OnSelectionResult);
				instance.Register<ZPackage>("VFP_RequestPlacement_v1", (Action<long, ZPackage>)OnRequestPlacement);
				instance.Register<ZPackage>("VFP_PlacementResult_v1", (Action<long, ZPackage>)OnPlacementResult);
				instance.Register<ZPackage>("VFP_CompleteFlight_v1", (Action<long, ZPackage>)OnCompleteFlight);
				instance.Register<ZPackage>("VFP_ToggleGlobal_v1", (Action<long, ZPackage>)OnToggleGlobal);
				instance.Register<ZPackage>("VFP_RenameFlightPath_v2", (Action<long, ZPackage>)OnRenameFlightPath);
				instance.Register<ZPackage>("VFP_ManagementResult_v1", (Action<long, ZPackage>)OnManagementResult);
				instance.Register<ZPackage>("VFP_ToggleRegistration_v3", (Action<long, ZPackage>)OnToggleRegistration);
				instance.Register<ZPackage>("VFP_TogglePermitted_v2", (Action<long, ZPackage>)OnTogglePermitted);
			}
		}

		internal static void RequestDestinations(ZDOID originId)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			if (ZRoutedRpc.instance != null && !((Object)(object)Player.m_localPlayer == (Object)null))
			{
				int num = (_pendingRequestId = ++_nextRequestId);
				ZPackage val = new ZPackage();
				val.Write(num);
				val.Write(originId);
				val.Write(FlightPathAdminMode.Enabled);
				ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "VFP_RequestDestinations_v1", new object[1] { val });
			}
		}

		internal static void ToggleGlobal(ZDOID nodeId)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			ZPackage val = new ZPackage();
			val.Write(nodeId);
			ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "VFP_ToggleGlobal_v1", new object[1] { val });
		}

		internal static void ToggleRegistration(ZDOID nodeId)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			ZPackage val = new ZPackage();
			val.Write(nodeId);
			val.Write(FlightPathAdminMode.Enabled);
			ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "VFP_ToggleRegistration_v3", new object[1] { val });
		}

		internal static void TogglePermitted(ZDOID nodeId, string playerName)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			ZPackage val = new ZPackage();
			val.Write(nodeId);
			val.Write(playerName ?? string.Empty);
			ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "VFP_TogglePermitted_v2", new object[1] { val });
		}

		internal static void RenameFlightPath(ZDOID nodeId, string name)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			ZPackage val = new ZPackage();
			val.Write(nodeId);
			val.Write(name ?? string.Empty);
			val.Write(FlightPathAdminMode.Enabled);
			ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "VFP_RenameFlightPath_v2", new object[1] { val });
		}

		internal static void SelectDestination(int requestId, ZDOID originId, ZDOID destinationId, bool requestAdminOverride)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			ZPackage val = new ZPackage();
			val.Write(requestId);
			val.Write(originId);
			val.Write(destinationId);
			val.Write(requestAdminOverride);
			ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "VFP_SelectDestination_v1", new object[1] { val });
		}

		internal static void RequestPlacement(int requestId, Vector3 position)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			ZPackage val = new ZPackage();
			val.Write(requestId);
			val.Write(position);
			ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "VFP_RequestPlacement_v1", new object[1] { val });
		}

		internal static void CompleteFlight(int flightId)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			if (ZRoutedRpc.instance != null)
			{
				ZPackage val = new ZPackage();
				val.Write(flightId);
				ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "VFP_CompleteFlight_v1", new object[1] { val });
			}
		}

		private static void OnRequestDestinations(long sender, ZPackage package)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer())
			{
				return;
			}
			int num = package.ReadInt();
			ZDOID val = package.ReadZDOID();
			bool num2 = package.ReadBool();
			ZPackage val2 = new ZPackage();
			val2.Write(num);
			val2.Write(val);
			bool flag = num2 && IsSenderAdmin(sender);
			if (!TryResolveSender(sender, out var playerId, out var character) || !FlightPathWorldRegistry.TryGetNode(val, out var node) || (!FlightPathWorldRegistry.HasAccess(node, playerId) && !flag) || Vector3.Distance(character.GetPosition(), node.GetPosition()) > 8f)
			{
				val2.Write("$vfp_invalid_origin");
				val2.Write(0);
				Send(sender, "VFP_ReplyDestinations_v1", val2);
				return;
			}
			if (FlightPathWorldRegistry.ExceedsRegistrationLimit(node))
			{
				val2.Write("$vfp_departure_registration_over_limit");
				val2.Write(0);
				Send(sender, "VFP_ReplyDestinations_v1", val2);
				return;
			}
			bool includeAll = flag;
			List<FlightPathDestination> accessibleNodes = FlightPathWorldRegistry.GetAccessibleNodes(playerId, val, includeAll);
			val2.Write(string.Empty);
			val2.Write(accessibleNodes.Count);
			foreach (FlightPathDestination item in accessibleNodes)
			{
				val2.Write(item.Id);
				val2.Write(item.Name ?? string.Empty);
				val2.Write(item.Position);
				val2.Write(item.IsOrigin);
				val2.Write(item.AdminOnly);
			}
			Send(sender, "VFP_ReplyDestinations_v1", val2);
		}

		private static void OnReplyDestinations(long sender, ZPackage package)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			int num = package.ReadInt();
			ZDOID originId = package.ReadZDOID();
			string text = package.ReadString();
			int num2 = package.ReadInt();
			if (num != _pendingRequestId || (Object)(object)Player.m_localPlayer == (Object)null)
			{
				return;
			}
			if (!string.IsNullOrEmpty(text))
			{
				((Character)Player.m_localPlayer).Message((MessageType)2, text, 0, (Sprite)null);
				return;
			}
			List<FlightPathDestination> list = new List<FlightPathDestination>(num2);
			for (int i = 0; i < num2; i++)
			{
				list.Add(new FlightPathDestination
				{
					Id = package.ReadZDOID(),
					Name = package.ReadString(),
					Position = package.ReadVector3(),
					IsOrigin = package.ReadBool(),
					AdminOnly = package.ReadBool()
				});
			}
			FlightPathMapSelection.Open(num, originId, list);
		}

		private static void OnSelectDestination(long sender, ZPackage package)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer())
			{
				int num = package.ReadInt();
				ZDOID val = package.ReadZDOID();
				ZDOID val2 = package.ReadZDOID();
				bool num2 = package.ReadBool();
				bool flag = false;
				int num3 = 0;
				Vector3 val3 = Vector3.zero;
				Vector3 val4 = Vector3.zero;
				bool flag2 = num2 && IsSenderAdmin(sender);
				string text;
				long playerId;
				ZDO character;
				ZDO node;
				ZDO node2;
				if (ActiveFlights.TryGetValue(sender, out var value) && Time.time <= value.ExpiresAt)
				{
					text = "$vfp_flight_already_active";
				}
				else if (!TryResolveSender(sender, out playerId, out character) || !FlightPathWorldRegistry.TryGetNode(val, out node) || !FlightPathWorldRegistry.TryGetNode(val2, out node2) || (!FlightPathWorldRegistry.HasAccess(node, playerId) && !flag2) || (!FlightPathWorldRegistry.HasAccess(node2, playerId) && !flag2))
				{
					text = "$vfp_invalid_destination";
				}
				else if (val == val2)
				{
					text = "$vfp_same_destination";
				}
				else if (FlightPathWorldRegistry.ExceedsRegistrationLimit(node))
				{
					text = "$vfp_departure_registration_over_limit";
				}
				else if (Vector3.Distance(character.GetPosition(), node.GetPosition()) > 8f)
				{
					text = "$vfp_too_far_from_origin";
				}
				else if (!HasServerSideDepartureClearance(val, node.GetPosition()))
				{
					text = "$vfp_departure_blocked";
				}
				else
				{
					string text2 = $"Flight Path ({node2.GetPosition().x:0}, {node2.GetPosition().z:0})";
					string text3 = node2.GetString("vfp_name", text2);
					text = "$vfp_destination_confirmed " + text3;
					flag = true;
					num3 = ++_nextFlightId;
					val3 = node.GetPosition();
					val4 = node2.GetPosition();
					ActiveFlights[sender] = new ActiveFlight
					{
						Id = num3,
						ExpiresAt = Time.time + 600f
					};
				}
				ZPackage val5 = new ZPackage();
				val5.Write(num);
				val5.Write(flag);
				val5.Write(text);
				if (flag)
				{
					val5.Write(num3);
					val5.Write(val);
					val5.Write(val3);
					val5.Write(val2);
					val5.Write(val4);
				}
				Send(sender, "VFP_SelectionResult_v1", val5);
			}
		}

		private static void OnSelectionResult(long sender, ZPackage package)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			int num = package.ReadInt();
			bool flag = package.ReadBool();
			string text = package.ReadString();
			if (num != _pendingRequestId)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if (localPlayer != null)
			{
				((Character)localPlayer).Message((MessageType)2, text, 0, (Sprite)null);
			}
			if (!flag)
			{
				return;
			}
			int flightId = package.ReadInt();
			ZDOID originId = package.ReadZDOID();
			Vector3 origin = package.ReadVector3();
			ZDOID destinationId = package.ReadZDOID();
			Vector3 destination = package.ReadVector3();
			if (!FlightPayment.TryCharge(Player.m_localPlayer, out var error, out var _))
			{
				Player localPlayer2 = Player.m_localPlayer;
				if (localPlayer2 != null)
				{
					((Character)localPlayer2).Message((MessageType)2, error, 0, (Sprite)null);
				}
				CompleteFlight(flightId);
			}
			else
			{
				Game instance = Game.instance;
				if (instance != null)
				{
					instance.SavePlayerProfile(true);
				}
				ValkyrieTaxiSpawner.Spawn(flightId, originId, origin, destinationId, destination);
			}
		}

		private static void OnCompleteFlight(long sender, ZPackage package)
		{
			if (!((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer())
			{
				int num = package.ReadInt();
				if (ActiveFlights.TryGetValue(sender, out var value) && value.Id == num)
				{
					ActiveFlights.Remove(sender);
				}
			}
		}

		internal static void HandlePeerDisconnected(long peerId)
		{
			ActiveFlights.Remove(peerId);
		}

		private static void OnToggleGlobal(long sender, ZPackage package)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer())
			{
				return;
			}
			ZDOID val = package.ReadZDOID();
			if (!IsSenderAdmin(sender) || !FlightPathWorldRegistry.TryGetNode(val, out var node))
			{
				SendManagementResult(sender, "$vfp_admin_required");
				return;
			}
			bool flag = !FlightPathWorldRegistry.IsGlobal(node);
			node.SetOwner(ZDOMan.GetSessionID());
			node.Set("vfp_global", flag);
			if (flag)
			{
				node.Set("vfp_registration_open", false);
			}
			ZDOMan.instance.ForceSendZDO(val);
			SendManagementResult(sender, flag ? "$vfp_global_enabled" : "$vfp_global_disabled");
		}

		private static void OnRenameFlightPath(long sender, ZPackage package)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer())
			{
				return;
			}
			ZDOID val = package.ReadZDOID();
			string text = package.ReadString().Trim();
			bool flag = package.ReadBool();
			if (!TryResolveSender(sender, out var playerId, out var _) || !FlightPathWorldRegistry.TryGetNode(val, out var node) || (node.GetLong(ZDOVars.s_creator, 0L) != playerId && (!flag || !IsSenderAdmin(sender))))
			{
				SendManagementResult(sender, "$vfp_rename_owner_only");
				return;
			}
			if (text.Length > 50)
			{
				text = text.Substring(0, 50);
			}
			node.Set("vfp_name", text);
			ZDOMan.instance.ForceSendZDO(val);
			SendManagementResult(sender, "$vfp_name_updated");
		}

		private static void OnManagementResult(long sender, ZPackage package)
		{
			Player localPlayer = Player.m_localPlayer;
			if (localPlayer != null)
			{
				((Character)localPlayer).Message((MessageType)2, package.ReadString(), 0, (Sprite)null);
			}
		}

		internal static void SendManagementResult(long peer, string message)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			ZPackage val = new ZPackage();
			val.Write(message);
			Send(peer, "VFP_ManagementResult_v1", val);
		}

		private static void OnToggleRegistration(long sender, ZPackage package)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer())
			{
				ZDOID val = package.ReadZDOID();
				bool flag = package.ReadBool();
				if (TryResolveSender(sender, out var playerId, out var character) && FlightPathWorldRegistry.TryGetNode(val, out var node) && !FlightPathWorldRegistry.IsGlobal(node) && (node.GetLong(ZDOVars.s_creator, 0L) == playerId || (flag && IsSenderAdmin(sender))) && !(Vector3.Distance(character.GetPosition(), node.GetPosition()) > 8f))
				{
					node.SetOwner(ZDOMan.GetSessionID());
					bool flag2 = !node.GetBool("vfp_registration_open", false);
					node.Set("vfp_registration_open", flag2);
					ZDOMan.instance.ForceSendZDO(val);
				}
			}
		}

		private static void OnTogglePermitted(long sender, ZPackage package)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer())
			{
				return;
			}
			ZDOID val = package.ReadZDOID();
			string value = package.ReadString();
			if (!TryResolveSender(sender, out var playerId, out var character) || !FlightPathWorldRegistry.TryGetNode(val, out var node) || !node.GetBool("vfp_registration_open", false) || Vector3.Distance(character.GetPosition(), node.GetPosition()) > 8f)
			{
				return;
			}
			int num = node.GetInt("vfp_permitted_count", 0);
			List<KeyValuePair<long, string>> list = new List<KeyValuePair<long, string>>(num + 1);
			bool flag = false;
			for (int i = 0; i < num; i++)
			{
				long num2 = node.GetLong("vfp_permitted_id_" + i, 0L);
				if (num2 == playerId)
				{
					flag = true;
				}
				else if (num2 != 0L)
				{
					list.Add(new KeyValuePair<long, string>(num2, node.GetString("vfp_permitted_name_" + i, string.Empty)));
				}
			}
			if (!flag)
			{
				int value2 = ModConfig.MaximumRegistrationsPerFlightPath.Value;
				if (value2 <= 0 || list.Count >= value2)
				{
					SendManagementResult(sender, "$vfp_registration_limit_reached");
					return;
				}
				list.Add(new KeyValuePair<long, string>(playerId, value));
			}
			node.SetOwner(ZDOMan.GetSessionID());
			node.Set("vfp_permitted_count", list.Count);
			for (int j = 0; j < list.Count; j++)
			{
				node.Set("vfp_permitted_id_" + j, list[j].Key);
				node.Set("vfp_permitted_name_" + j, list[j].Value);
			}
			ZDOMan.instance.ForceSendZDO(val);
		}

		internal static bool IsSenderAdmin(long sender)
		{
			if (sender == ZRoutedRpc.instance.GetServerPeerID())
			{
				return true;
			}
			ZNetPeer peer = ZRoutedRpc.instance.GetPeer(sender);
			if (peer != null && peer.m_socket != null)
			{
				return ZNet.instance.IsAdmin(peer.m_socket.GetHostName());
			}
			return false;
		}

		private static void OnRequestPlacement(long sender, ZPackage package)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer())
			{
				int num = package.ReadInt();
				Vector3 val = package.ReadVector3();
				long playerId;
				ZDO character;
				Collider obstruction;
				bool flag = TryResolveSender(sender, out playerId, out character) && Vector3.Distance(character.GetPosition(), val) <= 12f && !FlightPathWorldRegistry.HasNodeWithin(val, ModConfig.MinimumFlightPathDistance.Value, ZDOID.None) && FlightPathClearance.HasOpenSky(val, null, out obstruction);
				ZPackage val2 = new ZPackage();
				val2.Write(num);
				val2.Write(flag);
				val2.Write(flag ? string.Empty : "$vfp_placement_rejected");
				Send(sender, "VFP_PlacementResult_v1", val2);
			}
		}

		private static void OnPlacementResult(long sender, ZPackage package)
		{
			FlightPathPlacementAuthorization.Complete(package.ReadInt(), package.ReadBool(), package.ReadString());
		}

		private static bool TryResolveSender(long sender, out long playerId, out ZDO character)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			playerId = 0L;
			character = null;
			ZDOID val;
			if (sender == ZRoutedRpc.instance.GetServerPeerID())
			{
				val = ZNet.instance.LocalPlayerCharacterID;
			}
			else
			{
				ZNetPeer peer = ZRoutedRpc.instance.GetPeer(sender);
				if (peer == null || !peer.IsReady())
				{
					return false;
				}
				val = peer.m_characterID;
			}
			character = ZDOMan.instance.GetZDO(val);
			if (character == null)
			{
				return false;
			}
			playerId = character.GetLong(ZDOVars.s_playerID, 0L);
			return playerId != 0;
		}

		private static bool HasServerSideDepartureClearance(ZDOID originId, Vector3 position)
		{
			//IL_000c: 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)
			ZNetScene instance = ZNetScene.instance;
			GameObject val = ((instance != null) ? instance.FindInstance(originId) : null);
			Transform ignoredRoot = (((Object)(object)val != (Object)null) ? val.transform : null);
			Collider obstruction;
			return FlightPathClearance.HasOpenSky(position, ignoredRoot, out obstruction);
		}

		private static void Send(long peer, string method, ZPackage package)
		{
			ZRoutedRpc.instance.InvokeRoutedRPC(peer, method, new object[1] { package });
		}
	}
	internal static class FlightPathWorldRegistry
	{
		internal static bool TryGetNode(ZDOID id, out ZDO node)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			ZDOMan instance = ZDOMan.instance;
			node = ((instance != null) ? instance.GetZDO(id) : null);
			return IsFlightPath(node);
		}

		internal static List<FlightPathDestination> GetAccessibleNodes(long playerId, ZDOID originId, bool includeAll = false)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			List<FlightPathDestination> list = new List<FlightPathDestination>();
			if (ZDOMan.instance == null)
			{
				return list;
			}
			foreach (ZDO value in ZDOMan.instance.m_objectsByID.Values)
			{
				bool flag = HasAccess(value, playerId);
				if (IsFlightPath(value) && (flag || includeAll))
				{
					Vector3 position = value.GetPosition();
					string text = $"({position.x:0}, {position.z:0})";
					string text2 = value.GetString("vfp_name", string.Empty);
					string name = (string.IsNullOrWhiteSpace(text2) ? ("Flight Path " + text) : (text2 + " " + text));
					list.Add(new FlightPathDestination
					{
						Id = value.m_uid,
						Name = name,
						Position = position,
						IsOrigin = (value.m_uid == originId),
						AdminOnly = !flag
					});
				}
			}
			list.Sort((FlightPathDestination left, FlightPathDestination right) => string.CompareOrdinal(left.Name, right.Name));
			return list;
		}

		internal static bool HasAccess(ZDO node, long playerId)
		{
			if (!IsFlightPath(node))
			{
				return false;
			}
			if (node.GetBool("vfp_global", false))
			{
				return true;
			}
			if (node.GetLong(ZDOVars.s_creator, 0L) == playerId)
			{
				return true;
			}
			int num = node.GetInt("vfp_permitted_count", 0);
			for (int i = 0; i < num; i++)
			{
				if (node.GetLong("vfp_permitted_id_" + i, 0L) == playerId)
				{
					return true;
				}
			}
			return false;
		}

		internal static bool IsGlobal(ZDO node)
		{
			if (IsFlightPath(node))
			{
				return node.GetBool("vfp_global", false);
			}
			return false;
		}

		internal static bool ExceedsRegistrationLimit(ZDO node)
		{
			if (!IsFlightPath(node) || IsGlobal(node))
			{
				return false;
			}
			return node.GetInt("vfp_permitted_count", 0) > ModConfig.MaximumRegistrationsPerFlightPath.Value;
		}

		internal static bool HasNodeWithin(Vector3 position, float minimumDistance, ZDOID ignoredId)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			if (ZDOMan.instance == null || minimumDistance <= 0f)
			{
				return false;
			}
			float num = minimumDistance * minimumDistance;
			foreach (ZDO value in ZDOMan.instance.m_objectsByID.Values)
			{
				if (IsFlightPath(value) && !(value.m_uid == ignoredId))
				{
					Vector3 val = value.GetPosition() - position;
					val.y = 0f;
					if (((Vector3)(ref val)).sqrMagnitude < num)
					{
						return true;
					}
				}
			}
			return false;
		}

		private static bool IsFlightPath(ZDO zdo)
		{
			if (zdo != null && zdo.IsValid())
			{
				return zdo.GetPrefab() == StringExtensionMethods.GetStableHashCode("VFP_ValkyrieFlightPath");
			}
			return false;
		}
	}
	internal static class FlightPathZdoKeys
	{
		internal const string Name = "vfp_name";

		internal const string Global = "vfp_global";

		internal const string RegistrationOpen = "vfp_registration_open";

		internal const string PermittedCount = "vfp_permitted_count";

		internal const string PermittedIdPrefix = "vfp_permitted_id_";

		internal const string PermittedNamePrefix = "vfp_permitted_name_";
	}
	internal static class FlightPayment
	{
		internal static int GetRequiredGoldCost(Player player)
		{
			if ((Object)(object)player == (Object)null || ((Humanoid)player).GetInventory() == null)
			{
				return 0;
			}
			int value = ModConfig.RestrictedCargoGoldPerItem.Value;
			int value2 = ModConfig.RestrictedCargoMaximumGold.Value;
			Inventory inventory = ((Humanoid)player).GetInventory();
			if (value <= 0 || value2 <= 0 || inventory.IsTeleportable())
			{
				return 0;
			}
			long num = 0L;
			foreach (ItemData allItem in inventory.GetAllItems())
			{
				if (allItem != null && allItem.m_shared != null && !allItem.m_shared.m_teleportable)
				{
					num += Mathf.Max(0, allItem.m_stack);
				}
			}
			long num2 = num * value;
			if (num2 < value2)
			{
				return (int)num2;
			}
			return value2;
		}

		internal static bool TryCharge(Player player, out string error, out int chargedAmount)
		{
			error = string.Empty;
			chargedAmount = 0;
			if ((Object)(object)player == (Object)null || ((Humanoid)player).GetInventory() == null)
			{
				error = "$vfp_payment_failed";
				return false;
			}
			Inventory inventory = ((Humanoid)player).GetInventory();
			int requiredGoldCost = GetRequiredGoldCost(player);
			if (requiredGoldCost <= 0)
			{
				return true;
			}
			ObjectDB instance = ObjectDB.instance;
			GameObject obj = ((instance != null) ? instance.GetItemPrefab("Coins") : null);
			string text = ((obj != null) ? obj.GetComponent<ItemDrop>() : null)?.m_itemData?.m_shared?.m_name;
			if (string.IsNullOrEmpty(text))
			{
				error = "$vfp_payment_failed";
				return false;
			}
			if (inventory.CountItems(text, -1, false) < requiredGoldCost)
			{
				error = "$vfp_not_enough_gold " + requiredGoldCost;
				return false;
			}
			inventory.RemoveItem(text, requiredGoldCost, -1, false);
			chargedAmount = requiredGoldCost;
			((Character)player).Message((MessageType)1, "$vfp_gold_paid " + requiredGoldCost, 0, (Sprite)null);
			return true;
		}
	}
	internal enum PortalPolicy
	{
		FullyFunctional,
		BuildableButDisabled,
		DisabledAndHidden
	}
	internal enum ValkyrieStatuePose
	{
		Embrace,
		Wingspan,
		Soaring,
		Perched
	}
	internal static class ModConfig
	{
		internal static ConfigEntry<float> ClearanceHeight { get; private set; }

		internal static ConfigEntry<float> ClearanceRadius { get; private set; }

		internal static ConfigEntry<KeyboardShortcut> UseFlightPathShortcut { get; private set; }

		internal static ConfigEntry<KeyboardShortcut> ManageAccessShortcut { get; private set; }

		internal static ConfigEntry<KeyboardShortcut> RenameFlightPathShortcut { get; private set; }

		internal static ConfigEntry<KeyboardShortcut> ToggleGlobalShortcut { get; private set; }

		internal static ConfigEntry<KeyboardShortcut> ToggleAdminMapModeShortcut { get; private set; }

		internal static ConfigEntry<float> MinimumFlightPathDistance { get; private set; }

		internal static ConfigEntry<int> MaximumRegistrationsPerFlightPath { get; private set; }

		internal static ConfigEntry<int> RestrictedCargoGoldPerItem { get; private set; }

		internal static ConfigEntry<int> RestrictedCargoMaximumGold { get; private set; }

		internal static ConfigEntry<PortalPolicy> PortalMode { get; private set; }

		internal static ConfigEntry<ValkyrieStatuePose> StatuePose { get; private set; }

		internal static void Bind(ConfigFile config)
		{
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			AcceptableValueBase val = (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 100f);
			ClearanceHeight = ConfigFileExtensions.BindConfig<float>(config, "Flight Paths", "Clearance Height", 30f, "Required open-air height above a flight path.", true, (int?)null, val, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null);
			val = (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f);
			ClearanceRadius = ConfigFileExtensions.BindConfig<float>(config, "Flight Paths", "Clearance Radius", 2.5f, "Radius of the open-air corridor above a flight path.", true, (int?)null, val, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null);
			val = (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2000f);
			MinimumFlightPathDistance = ConfigFileExtensions.BindConfig<float>(config, "Flight Paths", "Minimum Flight Path Distance", 100f, "Minimum horizontal distance between any two flight paths.", true, (int?)null, val, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null);
			val = (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000);
			MaximumRegistrationsPerFlightPath = ConfigFileExtensions.BindConfig<int>(config, "Flight Paths", "Maximum Registrations Per Flight Path", 10, "Maximum number of players that may register at one private flight path. Set to 0 to disable new registrations.", true, (int?)null, val, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null);
			val = (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10000);
			RestrictedCargoGoldPerItem = ConfigFileExtensions.BindConfig<int>(config, "Flight Costs", "Restricted Cargo Gold Per Item", 1, "Gold charged for each individual non-teleportable item carried by the player. Set to 0 to make restricted cargo free.", true, (int?)null, val, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null);
			val = (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000000);
			RestrictedCargoMaximumGold = ConfigFileExtensions.BindConfig<int>(config, "Flight Costs", "Restricted Cargo Maximum Gold", 100, "Maximum total gold charged for restricted cargo on one flight. Set to 0 to make restricted cargo free.", true, (int?)null, val, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null);
			PortalMode = ConfigFileExtensions.BindConfig<PortalPolicy>(config, "Portals", "Portal Policy", PortalPolicy.FullyFunctional, "FullyFunctional keeps portals unchanged. BuildableButDisabled allows building and tagging portals but blocks travel. DisabledAndHidden also removes portal pieces from build menus.", true, (int?)null, (AcceptableValueBase)null, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null);
			StatuePose = ConfigFileExtensions.BindConfig<ValkyrieStatuePose>(config, "Visuals", "Statue Pose", ValkyrieStatuePose.Embrace, "Static Valkyrie pose used for flight paths. Embrace folds the wings around the approaching player; Wingspan opens them broadly toward the player; Soaring uses the smooth original backward pose; Perched uses the partially folded pose from before custom wing posing. Requires a game restart after changing.", false, (int?)null, (AcceptableValueBase)null, (Action<ConfigEntryBase>)null, (ConfigurationManagerAttributes)null);
			UseFlightPathShortcut = config.Bind<KeyboardShortcut>("Controls", "Use Flight Path Shortcut", new KeyboardShortcut((KeyCode)0, Array.Empty<KeyCode>()), "Optional shortcut for using the flight path currently under the crosshair. Valheim's configurable Use binding always remains available.");
			ManageAccessShortcut = config.Bind<KeyboardShortcut>("Controls", "Manage Access Shortcut", new KeyboardShortcut((KeyCode)118, Array.Empty<KeyCode>()), "Opens or closes registration for the owner, or registers/unregisters another player.");
			RenameFlightPathShortcut = config.Bind<KeyboardShortcut>("Controls", "Rename Flight Path Shortcut", new KeyboardShortcut((KeyCode)110, Array.Empty<KeyCode>()), "Renames the flight path under the crosshair when you own it.");
			ToggleGlobalShortcut = config.Bind<KeyboardShortcut>("Controls", "Toggle Global Flight Path Shortcut", new KeyboardShortcut((KeyCode)103, Array.Empty<KeyCode>()), "Lets a server admin toggle global access for the flight path under the crosshair.");
			ToggleAdminMapModeShortcut = config.Bind<KeyboardShortcut>("Controls", "Toggle Admin Map Mode Shortcut", new KeyboardShortcut((KeyCode)289, Array.Empty<KeyCode>()), "Lets a server admin show all flight paths during destination selection.");
		}
	}
	[BepInPlugin("icecub.ValkyrieFlightPaths", "Valkyrie Flight Paths", "0.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	[SynchronizationMode(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		private struct LocalBonePose
		{
			internal Transform Bone;

			internal Vector3 Position;

			internal Quaternion Rotation;

			internal Vector3 Scale;
		}

		public const string PluginGuid = "icecub.ValkyrieFlightPaths";

		public const string PluginName = "Valkyrie Flight Paths";

		public const string PluginVersion = "0.2.0";

		internal const string FlightPathPrefabName = "VFP_ValkyrieFlightPath";

		private const string FlightPathIconResourceName = "ValkyrieFlightPaths.Assets.valkyrie_flight_path_icon.png";

		private Harmony _harmony;

		internal static Plugin Instance { get; private set; }

		internal ManualLogSource Log => ((BaseUnityPlugin)this).Logger;

		private void Awake()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			Instance = this;
			ModConfig.Bind(((BaseUnityPlugin)this).Config);
			PrefabManager.OnVanillaPrefabsAvailable += RegisterValkyrieFlightPathPiece;
			_harmony = new Harmony("icecub.ValkyrieFlightPaths");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Valkyrie Flight Paths 0.2.0 loaded");
		}

		private void OnDestroy()
		{
			PrefabManager.OnVanillaPrefabsAvailable -= RegisterValkyrieFlightPathPiece;
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Instance = null;
		}

		private void Update()
		{
			FlightPathMapSelection.MonitorPlayerMovement();
			FlightPathAdminMode.Update();
		}

		private static PieceConfig CreatePieceConfig()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			PieceConfig val = new PieceConfig
			{
				Name = "$vfp_piece_name",
				Description = "$vfp_piece_description",
				PieceTable = PieceTables.Hammer,
				CraftingStation = CraftingStations.Workbench,
				Category = PieceCategories.Misc
			};
			val.AddRequirement("GreydwarfEye", 10, true);
			val.AddRequirement("FineWood", 20, true);
			val.AddRequirement("SurtlingCore", 2, true);
			return val;
		}

		private void RegisterValkyrieFlightPathPiece()
		{
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			PrefabManager.OnVanillaPrefabsAvailable -= RegisterValkyrieFlightPathPiece;
			GameObject prefab = PrefabManager.Instance.GetPrefab("Valkyrie");
			if ((Object)(object)prefab == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Vanilla prefab 'Valkyrie' was not found; the flight-path build piece cannot be registered");
				return;
			}
			GameObject val = PrefabManager.Instance.CreateClonedPrefab("VFP_ValkyrieFlightPath", "wood_floor");
			if ((Object)(object)val == (Object)null)
			{
				throw new InvalidOperationException("Vanilla prefab 'wood_floor' could not be cloned for the flight path");
			}
			RemoveBasePieceGeometry(val);
			AddStaticValkyrieVisual(val.transform, prefab);
			ConfigurePhysicalStatue(val);
			Piece component = val.GetComponent<Piece>();
			if ((Object)(object)component == (Object)null)
			{
				throw new InvalidOperationException("The flight-path donor prefab does not contain a Piece component");
			}
			component.m_icon = LoadFlightPathIcon();
			if ((Object)(object)val.GetComponent<FlightPathNode>() == (Object)null)
			{
				val.AddComponent<FlightPathNode>();
			}
			PieceManager.Instance.AddPiece(new CustomPiece(val, false, CreatePieceConfig()));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Registered the static vanilla 'Valkyrie' prefab as the flight-path model");
		}

		private static Sprite LoadFlightPathIcon()
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ValkyrieFlightPaths.Assets.valkyrie_flight_path_icon.png");
			if (stream == null)
			{
				throw new InvalidDataException("Embedded flight-path icon 'ValkyrieFlightPaths.Assets.valkyrie_flight_path_icon.png' was not found");
			}
			byte[] array = new byte[stream.Length];
			int num;
			for (int i = 0; i < array.Length; i += num)
			{
				num = stream.Read(array, i, array.Length - i);
				if (num == 0)
				{
					break;
				}
			}
			Texture2D val = AssetUtils.LoadImage(array);
			if ((Object)(object)val == (Object)null)
			{
				throw new InvalidDataException("The embedded flight-path icon is not a valid PNG image");
			}
			((Object)val).name = "VFP_ValkyrieFlightPathIcon";
			((Texture)val).filterMode = (FilterMode)1;
			((Texture)val).wrapMode = (TextureWrapMode)1;
			Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
			((Object)obj).name = "VFP_ValkyrieFlightPathIcon";
			return obj;
		}

		private static void RemoveBasePieceGeometry(GameObject prefab)
		{
			Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
			}
			MeshFilter[] componentsInChildren2 = prefab.GetComponentsInChildren<MeshFilter>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren2[i]);
			}
			Collider[] componentsInChildren3 = prefab.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren3.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren3[i]);
			}
			Rigidbody[] componentsInChildren4 = prefab.GetComponentsInChildren<Rigidbody>(true);
			for (int i = 0; i < componentsInChildren4.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren4[i]);
			}
		}

		private static void AddStaticValkyrieVisual(Transform parent, GameObject vanillaValkyrie)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(vanillaValkyrie);
			((Object)val).name = "StaticValkyrieVisual";
			val.transform.SetParent(parent, false);
			val.transform.localPosition = Vector3.zero;
			val.transform.localRotation = Quaternion.identity;
			val.transform.localScale = Vector3.one * 0.35f;
			FreezeValkyrieFlightPose(val);
			val.transform.localRotation = Quaternion.Euler(-90f, 0f, 0f);
			AlignVisualToGround(val);
			Transform transform = val.transform;
			transform.localPosition += Vector3.down * 0.52f;
			CenterVisualOverBuildPoint(parent, val);
			MirrorSmoothWingPoseForward(val);
			MonoBehaviour[] componentsInChildren = val.GetComponentsInChildren<MonoBehaviour>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
			}
			AudioSource[] componentsInChildren2 = val.GetComponentsInChildren<AudioSource>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren2[i]);
			}
			ParticleSystem[] componentsInChildren3 = val.GetComponentsInChildren<ParticleSystem>(true);
			for (int i = 0; i < componentsInChildren3.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren3[i]);
			}
			Animator[] componentsInChildren4 = val.GetComponentsInChildren<Animator>(true);
			for (int i = 0; i < componentsInChildren4.Length; i++)
			{
				((Behaviour)componentsInChildren4[i]).enabled = false;
			}
			Rigidbody[] componentsInChildren5 = val.GetComponentsInChildren<Rigidbody>(true);
			for (int i = 0; i < componentsInChildren5.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren5[i]);
			}
			Collider[] componentsInChildren6 = val.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren6.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren6[i]);
			}
			val.SetActive(true);
		}

		private static void FreezeValkyrieFlightPose(GameObject visual)
		{
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			Animator componentInChildren = visual.GetComponentInChildren<Animator>(true);
			if ((Object)(object)componentInChildren == (Object)null || (Object)(object)componentInChildren.runtimeAnimatorController == (Object)null)
			{
				Instance.Log.LogWarning((object)"The Valkyrie prototype has no animation controller; using its bind pose");
				return;
			}
			AnimationClip val = null;
			AnimationClip[] animationClips = componentInChildren.runtimeAnimatorController.animationClips;
			AnimationClip[] array = animationClips;
			foreach (AnimationClip val2 in array)
			{
				if ((Object)(object)val2 != (Object)null && ((Object)val2).name.IndexOf("fly", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					val = val2;
					break;
				}
			}
			if ((Object)(object)val == (Object)null && animationClips.Length != 0)
			{
				val = animationClips[0];
			}
			if ((Object)(object)val == (Object)null)
			{
				Instance.Log.LogWarning((object)"The Valkyrie animation controller contains no clips; using its bind pose");
				return;
			}
			List<LocalBonePose> poses = CaptureGroundedLegPose(componentInChildren);
			List<LocalBonePose> poses2 = CaptureHeadPose(componentInChildren);
			float[] array2 = new float[121];
			float[] array3 = new float[121];
			float[] array4 = new float[121];
			float num = float.MaxValue;
			float num2 = float.MinValue;
			for (int j = 0; j < 121; j++)
			{
				float num3 = (float)j / 120f;
				val.SampleAnimation(((Component)componentInChildren).gameObject, val.length * num3);
				Bounds val3 = MeasureSkeletonBounds(visual);
				array2[j] = ((Bounds)(ref val3)).size.x;
				array3[j] = MeasureWingElbowAngle(visual);
				array4[j] = MeasureWingDropAfterUprightRotation(visual);
				num = Mathf.Min(num, array2[j]);
				num2 = Mathf.Max(num2, array2[j]);
			}
			float num4 = Mathf.Lerp(num, num2, 0.4f);
			int num5 = 0;
			float num6 = float.MaxValue;
			float num7 = Mathf.Max(0.01f, num2 - num);
			bool flag = ModConfig.StatuePose.Value == ValkyrieStatuePose.Perched;
			for (int k = 0; k < 121; k++)
			{
				float num8 = Mathf.Abs(array2[k] - num4) / num7;
				if (flag)
				{
					if (!(num8 >= num6))
					{
						num6 = num8;
						num5 = k;
					}
				}
				else if (!(num8 > 0.15f) && !(array3[k] < 0f))
				{
					float num9 = array3[k] + num8 * 10f;
					if (num9 < num6)
					{
						num6 = num9;
						num5 = k;
					}
				}
			}
			float num10 = (float)num5 / 120f;
			val.SampleAnimation(((Component)componentInChildren).gameObject, val.length * num10);
			RestoreBonePoses(poses);
			RestoreBonePoses(poses2);
			((Behaviour)componentInChildren).enabled = false;
			Instance.Log.LogInfo((object)($"Frozen Valkyrie statue on smooth frame {num10:P1} " + $"(joint angle {array3[num5]:0.0} degrees, " + $"span range {num:0.00}-{num2:0.00}m)"));
		}

		private static float MeasureWingDropAfterUprightRotation(GameObject visual)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			Quaternion val = Quaternion.Euler(-90f, 0f, 0f);
			float num = 0f;
			int num2 = 0;
			string[] array = new string[2] { "l", "r" };
			foreach (string text in array)
			{
				Transform val2 = FindRigTransform(visual.transform, text + "_arm0");
				Transform val3 = FindRigTransform(visual.transform, text + "_arm2");
				if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val3 == (Object)null))
				{
					Vector3 val4 = visual.transform.InverseTransformPoint(val2.position);
					Vector3 val5 = visual.transform.InverseTransformPoint(val3.position);
					num += (val * val5).y - (val * val4).y;
					num2++;
				}
			}
			if (num2 <= 0)
			{
				return float.MaxValue;
			}
			return num / (float)num2;
		}

		private static float MeasureWingElbowAngle(GameObject visual)
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f;
			int num2 = 0;
			string[] array = new string[2] { "l", "r" };
			foreach (string text in array)
			{
				Transform val = FindRigTransform(visual.transform, text + "_arm0");
				Transform val2 = FindRigTransform(visual.transform, text + "_arm1");
				Transform val3 = FindRigTransform(visual.transform, text + "_arm2");
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null) && !((Object)(object)val3 == (Object)null))
				{
					Vector3 val4 = val2.position - val.position;
					Vector3 val5 = val3.position - val2.position;
					if (!(((Vector3)(ref val4)).sqrMagnitude < 0.0001f) && !(((Vector3)(ref val5)).sqrMagnitude < 0.0001f))
					{
						num += Vector3.Angle(val4, val5);
						num2++;
					}
				}
			}
			if (num2 <= 0)
			{
				return -1f;
			}
			return num / (float)num2;
		}

		private static Transform FindRigTransform(Transform root, string exactName)
		{
			Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if (((Object)val).name.Equals(exactName, StringComparison.OrdinalIgnoreCase))
				{
					return val;
				}
			}
			return null;
		}

		private static void MirrorSmoothWingPoseForward(GameObject visual)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			ValkyrieStatuePose value = ModConfig.StatuePose.Value;
			if (value == ValkyrieStatuePose.Soaring || value == ValkyrieStatuePose.Perched)
			{
				return;
			}
			Transform parent = visual.transform.parent;
			Vector3 val;
			Vector3 val2;
			if (!((Object)(object)parent != (Object)null))
			{
				val = Vector3.forward;
			}
			else
			{
				val2 = parent.forward;
				val = ((Vector3)(ref val2)).normalized;
			}
			Vector3 val3 = val;
			string[] array = new string[2] { "l", "r" };
			foreach (string text in array)
			{
				Transform val4 = FindRigTransform(visual.transform, text + "_arm0");
				Transform val5 = FindRigTransform(visual.transform, text + "_arm1");
				Transform val6 = FindRigTransform(visual.transform, text + "_arm2");
				if ((Object)(object)val4 == (Object)null || (Object)(object)val5 == (Object)null || (Object)(object)val6 == (Object)null)
				{
					continue;
				}
				val2 = val5.position - val4.position;
				Vector3 normalized = ((Vector3)(ref val2)).normalized;
				Vector3 val7 = normalized - 2f * Vector3.Dot(normalized, val3) * val3;
				if (value == ValkyrieStatuePose.Wingspan)
				{
					val4.rotation = Quaternion.FromToRotation(normalized, ((Vector3)(ref val7)).normalized) * val4.rotation;
					continue;
				}
				float num = Mathf.Sign(Vector3.Dot(val7, val3));
				if (Mathf.Approximately(num, 0f))
				{
					num = 1f;
				}
				Vector3 val8 = val3 * num;
				val2 = Vector3.Slerp(((Vector3)(ref val7)).normalized, val8, 0.35f) + Vector3.down * 0.12f;
				Vector3 normalized2 = ((Vector3)(ref val2)).normalized;
				val4.rotation = Quaternion.FromToRotation(normalized, normalized2) * val4.rotation;
				val2 = val6.position - val5.position;
				Vector3 normalized3 = ((Vector3)(ref val2)).normalized;
				val2 = (((Object)(object)parent != (Object)null) ? parent.position : visual.transform.position) + val8 * 1f - val5.position;
				Vector3 normalized4 = ((Vector3)(ref val2)).normalized;
				val2 = Vector3.Slerp(normalized3, normalized4, 0.75f) + Vector3.down * 0.05f;
				Vector3 normalized5 = ((Vector3)(ref val2)).normalized;
				val5.rotation = Quaternion.FromToRotation(normalized3, normalized5) * val5.rotation;
			}
		}

		private static List<LocalBonePose> CaptureGroundedLegPose(Animator animator)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			List<LocalBonePose> list = new List<LocalBonePose>();
			HashSet<Transform> hashSet = new HashSet<Transform>();
			if (animator.isHuman)
			{
				HumanBodyBones[] array = new HumanBodyBones[8];
				RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
				HumanBodyBones[] array2 = (HumanBodyBones[])(object)array;
				foreach (HumanBodyBones val in array2)
				{
					Transform boneTransform = animator.GetBoneTransform(val);
					if ((Object)(object)boneTransform != (Object)null)
					{
						hashSet.Add(boneTransform);
					}
				}
			}
			string[] array3 = new string[10] { "leg", "foot", "toe", "thigh", "calf", "shin", "knee", "ankle", "talon", "claw" };
			Transform[] componentsInChildren = ((Component)animator).GetComponentsInChildren<Transform>(true);
			foreach (Transform val2 in componentsInChildren)
			{
				string text = ((Object)val2).name.ToLowerInvariant();
				string[] array4 = array3;
				foreach (string value in array4)
				{
					if (text.Contains(value))
					{
						hashSet.Add(val2);
						break;
					}
				}
			}
			foreach (Transform item in hashSet)
			{
				list.Add(new LocalBonePose
				{
					Bone = item,
					Position = item.localPosition,
					Rotation = item.localRotation,
					Scale = item.localScale
				});
			}
			Instance.Log.LogInfo((object)($"Captured the original Valkyrie leg pose for {list.Count} rig transforms: " + string.Join(", ", list.ConvertAll((LocalBonePose pose) => ((Object)pose.Bone).name).ToArray())));
			return list;
		}

		private static List<LocalBonePose> CaptureHeadPose(Animator animator)
		{
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			HashSet<Transform> hashSet = new HashSet<Transform>();
			if (animator.isHuman)
			{
				Transform boneTransform = animator.GetBoneTransform((HumanBodyBones)9);
				Transform boneTransform2 = animator.GetBoneTransform((HumanBodyBones)10);
				if ((Object)(object)boneTransform != (Object)null)
				{
					hashSet.Add(boneTransform);
				}
				if ((Object)(object)boneTransform2 != (Object)null)
				{
					hashSet.Add(boneTransform2);
				}
			}
			Transform[] componentsInChildren = ((Component)animator).GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				string text = ((Object)val).name.ToLowerInvariant();
				if (text.Contains("neck") || text.Contains("head"))
				{
					hashSet.Add(val);
				}
			}
			List<LocalBonePose> list = new List<LocalBonePose>();
			foreach (Transform item in hashSet)
			{
				list.Add(new LocalBonePose
				{
					Bone = item,
					Position = item.localPosition,
					Rotation = item.localRotation,
					Scale = item.localScale
				});
			}
			Instance.Log.LogInfo((object)($"Captured the original Valkyrie head pose for {list.Count} rig transforms: " + string.Join(", ", list.ConvertAll((LocalBonePose pose) => ((Object)pose.Bone).name).ToArray())));
			return list;
		}

		private static void RestoreBonePoses(List<LocalBonePose> poses)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			foreach (LocalBonePose pose in poses)
			{
				if (!((Object)(object)pose.Bone == (Object)null))
				{
					pose.Bone.localPosition = pose.Position;
					pose.Bone.localRotation = pose.Rotation;
					pose.Bone.localScale = pose.Scale;
				}
			}
		}

		private static void AlignVisualToGround(GameObject visual)
		{
			//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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			Bounds val = MeasureSkeletonBounds(visual);
			Vector3 localPosition = visual.transform.localPosition;
			localPosition.y += 0.15f - ((Bounds)(ref val)).min.y;
			visual.transform.localPosition = localPosition;
		}

		private static void CenterVisualOverBuildPoint(Transform prefabRoot, GameObject visual)
		{
			//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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = FindTorsoPosition(prefabRoot);
			Vector3 localPosition = visual.transform.localPosition;
			localPosition.x -= val.x;
			localPosition.z -= val.z;
			visual.transform.localPosition = localPosition;
			Instance.Log.LogInfo((object)$"Recentered the Valkyrie statue by local XZ ({0f - val.x:0.00}, {0f - val.z:0.00})");
		}

		private static Bounds MeasureSkeletonBounds(GameObject visual)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			Transform parent = visual.transform.parent;
			Bounds result = default(Bounds);
			bool flag = false;
			SkinnedMeshRenderer[] componentsInChildren = visual.GetComponentsInChildren<SkinnedMeshRenderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Transform[] bones = componentsInChildren[i].bones;
				foreach (Transform val in bones)
				{
					if (!((Object)(object)val == (Object)null))
					{
						Vector3 val2 = (((Object)(object)parent != (Object)null) ? parent.InverseTransformPoint(val.position) : val.position);
						if (!flag)
						{
							((Bounds)(ref result))..ctor(val2, Vector3.zero);
							flag = true;
						}
						else
						{
							((Bounds)(ref result)).Encapsulate(val2);
						}
					}
				}
			}
			return result;
		}

		private static void ConfigurePhysicalStatue(GameObject prefab)
		{
			//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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: