Decompiled source of ValkyrieRunestones v1.1.0

plugins/ValkyrieRunestones.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_guiutils")]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("ValkyrieRunestones")]
[assembly: AssemblyConfiguration("release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ValkyrieRunestones")]
[assembly: AssemblyTitle("ValkyrieRunestones")]
[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 ValkyrieRunestones
{
	[BepInPlugin("com.custom.valkyrierunestones", "ValkyrieRunestones", "1.1.0")]
	public class ValkyrieRunestonesPlugin : BaseUnityPlugin
	{
		public struct RunestonePin
		{
			public Vector3 Pos;

			public string Name;
		}

		public const string ModGUID = "com.custom.valkyrierunestones";

		public const string ModName = "ValkyrieRunestones";

		public const string ModVersion = "1.1.0";

		private const string RpcRequestConfig = "ValkyrieRunestones_RequestConfig";

		private const string RpcSyncConfig = "ValkyrieRunestones_SyncConfig";

		public static ConfigEntry<KeyCode> TravelHotkey;

		public static ConfigEntry<bool> RequireStandingAtRunestone;

		public static ConfigEntry<float> DepartureRadius;

		public static ConfigEntry<float> TravelSpeed;

		public static ConfigEntry<float> TravelAltitude;

		public static ConfigEntry<bool> InvulnerableDuringFlight;

		public static ConfigEntry<bool> EnableItemToll;

		public static ConfigEntry<string> CostItemPrefab;

		public static ConfigEntry<int> CostItemAmount;

		public static ConfigEntry<float> AssumedOverlandSpeed;

		public static ConfigEntry<bool> StripRestedAndMeads;

		internal static ValkyrieRunestonesPlugin Instance;

		internal static string LoadedWorld = "";

		internal static readonly List<RunestonePin> Discovered = new List<RunestonePin>();

		internal static bool PinsDirty = true;

		internal static RunestonePin? PendingDest;

		internal static bool IsFlying;

		internal static Vector3 FlightStart;

		internal static Vector3 FlightDest;

		internal static string FlightDestName = "";

		internal static GameObject ValkyrieVisual;

		private readonly Harmony _harmony = new Harmony("com.custom.valkyrierunestones");

		private FileSystemWatcher _configWatcher;

		private volatile bool _pendingServerReload;

		private static Texture2D _bgTex;

		private static string SaveFilePath => Path.Combine(Paths.ConfigPath, "ValkyrieRunestones_Discovered.txt");

		private void Awake()
		{
			Instance = this;
			TravelHotkey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("1 - General", "TravelHotkey", (KeyCode)289, "Local client hotkey to summon the Valkyrie while hovering over an attuned Runestone pin on the large map.");
			RequireStandingAtRunestone = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "RequireStandingAtRunestone", true, "[Server Synced] If true, players must stand near an attuned Runestone to fly to another Runestone.");
			DepartureRadius = ((BaseUnityPlugin)this).Config.Bind<float>("1 - General", "DepartureRadius", 15f, "[Server Synced] Maximum distance in meters from an attuned Runestone to initiate a flight.");
			TravelSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("1 - General", "TravelSpeed", 20f, "[Server Synced] Valkyrie cruising speed in meters per second.");
			TravelAltitude = ((BaseUnityPlugin)this).Config.Bind<float>("1 - General", "TravelAltitude", 100f, "[Server Synced] Cruising altitude above terrain/water level in meters.");
			InvulnerableDuringFlight = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "InvulnerableDuringFlight", true, "[Server Synced] If true, players cannot take damage while carried by the Valkyrie.");
			EnableItemToll = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Item Cost", "EnableItemToll", true, "[Server Synced] Require and consume an item from the player's inventory for each Runestone flight.");
			CostItemPrefab = ((BaseUnityPlugin)this).Config.Bind<string>("2 - Item Cost", "CostItemPrefab", "SurtlingCore", "[Server Synced] Internal prefab name of the item consumed per flight (e.g., SurtlingCore, Coins, Eitr).");
			CostItemAmount = ((BaseUnityPlugin)this).Config.Bind<int>("2 - Item Cost", "CostItemAmount", 1, "[Server Synced] Number of items consumed per flight.");
			AssumedOverlandSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("3 - Exhaustion Penalty", "AssumedOverlandSpeed", 0.4f, "[Server Synced] Simulated walking speed in m/s used to drain food timers on arrival (0.4 = ~6x exhaustion; 0 = off).");
			StripRestedAndMeads = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Exhaustion Penalty", "StripRestedAndMeads", true, "[Server Synced] Remove Rested and active Mead/Potion buffs upon landing.");
			SetupConfigWatcher();
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"ValkyrieRunestones v1.1.0 loaded! Server config sync enabled.");
		}

		private void Update()
		{
			if (!_pendingServerReload)
			{
				return;
			}
			_pendingServerReload = false;
			if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer())
			{
				return;
			}
			try
			{
				((BaseUnityPlugin)this).Config.Reload();
				BroadcastConfigToAllPeers();
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Server config reloaded from disk and pushed to connected players.");
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Failed to reload server config: " + ex.Message));
			}
		}

		private void OnDestroy()
		{
			if (_configWatcher != null)
			{
				_configWatcher.EnableRaisingEvents = false;
				_configWatcher.Dispose();
				_configWatcher = null;
			}
			CleanupFlight(Player.m_localPlayer);
			_harmony.UnpatchSelf();
		}

		private void SetupConfigWatcher()
		{
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Config.ConfigFilePath);
			string fileName = Path.GetFileName(((BaseUnityPlugin)this).Config.ConfigFilePath);
			if (!string.IsNullOrEmpty(directoryName) && !string.IsNullOrEmpty(fileName))
			{
				_configWatcher = new FileSystemWatcher(directoryName, fileName)
				{
					NotifyFilter = (NotifyFilters.Size | NotifyFilters.LastWrite),
					IncludeSubdirectories = false,
					EnableRaisingEvents = true
				};
				_configWatcher.Changed += delegate
				{
					_pendingServerReload = true;
				};
			}
		}

		internal static void RegisterRPCs()
		{
			if (ZRoutedRpc.instance != null)
			{
				ZRoutedRpc.instance.Register("ValkyrieRunestones_RequestConfig", (Action<long>)RPC_OnConfigRequested);
				ZRoutedRpc.instance.Register<ZPackage>("ValkyrieRunestones_SyncConfig", (Action<long, ZPackage>)RPC_OnConfigReceived);
			}
		}

		internal static void RequestServerConfig()
		{
			if (ZRoutedRpc.instance != null && !((Object)(object)ZNet.instance == (Object)null) && !ZNet.instance.IsServer())
			{
				long serverPeerID = ZRoutedRpc.instance.GetServerPeerID();
				ZRoutedRpc.instance.InvokeRoutedRPC(serverPeerID, "ValkyrieRunestones_RequestConfig", Array.Empty<object>());
			}
		}

		internal static void BroadcastConfigToAllPeers()
		{
			if (ZRoutedRpc.instance != null && !((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer())
			{
				ZRoutedRpc.instance.InvokeRoutedRPC(0L, "ValkyrieRunestones_SyncConfig", new object[1] { BuildConfigPackage() });
			}
		}

		private static void RPC_OnConfigRequested(long senderPeerId)
		{
			if (ZRoutedRpc.instance != null && !((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer())
			{
				ZRoutedRpc.instance.InvokeRoutedRPC(senderPeerId, "ValkyrieRunestones_SyncConfig", new object[1] { BuildConfigPackage() });
			}
		}

		private static ZPackage BuildConfigPackage()
		{
			//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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			ZPackage val = new ZPackage();
			val.Write(RequireStandingAtRunestone.Value);
			val.Write(DepartureRadius.Value);
			val.Write(TravelSpeed.Value);
			val.Write(TravelAltitude.Value);
			val.Write(InvulnerableDuringFlight.Value);
			val.Write(EnableItemToll.Value);
			val.Write(CostItemPrefab.Value ?? "SurtlingCore");
			val.Write(CostItemAmount.Value);
			val.Write(AssumedOverlandSpeed.Value);
			val.Write(StripRestedAndMeads.Value);
			return val;
		}

		private static void RPC_OnConfigReceived(long senderPeerId, ZPackage pkg)
		{
			if (pkg == null || ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer()))
			{
				return;
			}
			try
			{
				RequireStandingAtRunestone.Value = pkg.ReadBool();
				DepartureRadius.Value = pkg.ReadSingle();
				TravelSpeed.Value = pkg.ReadSingle();
				TravelAltitude.Value = pkg.ReadSingle();
				InvulnerableDuringFlight.Value = pkg.ReadBool();
				EnableItemToll.Value = pkg.ReadBool();
				CostItemPrefab.Value = pkg.ReadString();
				CostItemAmount.Value = pkg.ReadInt();
				AssumedOverlandSpeed.Value = pkg.ReadSingle();
				StripRestedAndMeads.Value = pkg.ReadBool();
				if ((Object)(object)Instance != (Object)null)
				{
					((BaseUnityPlugin)Instance).Config.Save();
					((BaseUnityPlugin)Instance).Logger.LogInfo((object)"Synced ValkyrieRunestones configuration from server.");
				}
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[ValkyrieRunestones] Error reading server config package: " + ex.Message));
			}
		}

		private void OnGUI()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Invalid comparison between Unknown and I4
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Invalid comparison between Unknown and I4
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Expected O, but got Unknown
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Expected O, but got Unknown
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: 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)
			//IL_01bb: Expected O, but got Unknown
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			//IL_00b3: 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_0071: Invalid comparison between Unknown and I4
			//IL_020b: 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_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			if (!PendingDest.HasValue)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead() || (Object)(object)Minimap.instance == (Object)null || !Minimap.IsOpen() || (int)Minimap.instance.m_mode != 2)
			{
				PendingDest = null;
				return;
			}
			if (Event.current != null && (int)Event.current.type == 4 && (int)Event.current.keyCode == 27)
			{
				PendingDest = null;
				return;
			}
			if ((Object)(object)_bgTex == (Object)null)
			{
				_bgTex = new Texture2D(1, 1);
				_bgTex.SetPixel(0, 0, new Color(0.08f, 0.1f, 0.14f, 0.94f));
				_bgTex.Apply();
			}
			RunestonePin value = PendingDest.Value;
			float num = Vector3.Distance(((Component)localPlayer).transform.position, value.Pos);
			string displayName;
			int ownedCount;
			bool flag = HasRequiredToll(localPlayer, out displayName, out ownedCount);
			float num2 = 380f;
			float num3 = 215f;
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((float)Screen.width - num2) * 0.5f, ((float)Screen.height - num3) * 0.5f, num2, num3);
			GUIStyle val2 = new GUIStyle(GUI.skin.box);
			val2.normal.background = _bgTex;
			GUIStyle val3 = new GUIStyle(GUI.skin.label)
			{
				alignment = (TextAnchor)4,
				fontSize = 16,
				fontStyle = (FontStyle)1
			};
			val3.normal.textColor = new Color(0.96f, 0.82f, 0.44f);
			GUIStyle val4 = new GUIStyle(GUI.skin.label)
			{
				alignment = (TextAnchor)4,
				fontSize = 13,
				wordWrap = true
			};
			val4.normal.textColor = Color.white;
			GUIStyle val5 = new GUIStyle(val4)
			{
				fontStyle = (FontStyle)1
			};
			val5.normal.textColor = (flag ? new Color(0.45f, 0.92f, 0.55f) : new Color(1f, 0.4f, 0.4f));
			GUI.Box(val, GUIContent.none, val2);
			GUILayout.BeginArea(new Rect(((Rect)(ref val)).x + 16f, ((Rect)(ref val)).y + 14f, ((Rect)(ref val)).width - 32f, ((Rect)(ref val)).height - 28f));
			GUILayout.Label("VALKYRIE RUNESTONE FLIGHT", val3, Array.Empty<GUILayoutOption>());
			GUILayout.Space(8f);
			GUILayout.Label($"Destination: {value.Name}\nDistance: {num:F0} m", val4, Array.Empty<GUILayoutOption>());
			GUILayout.Space(6f);
			if (EnableItemToll.Value && CostItemAmount.Value > 0)
			{
				GUILayout.Label($"Cost: {CostItemAmount.Value}x {displayName} (You have: {ownedCount})", val5, Array.Empty<GUILayoutOption>());
			}
			else
			{
				GUILayout.Label("Cost: Free", val5, Array.Empty<GUILayoutOption>());
			}
			if (AssumedOverlandSpeed.Value > 0f)
			{
				float num4 = num / AssumedOverlandSpeed.Value / 60f;
				GUILayout.Label($"Exhaustion: -{num4:F0}m food timers" + (StripRestedAndMeads.Value ? " & clears Rested/Meads" : ""), val4, Array.Empty<GUILayoutOption>());
			}
			GUILayout.FlexibleSpace();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUI.enabled = flag;
			if (GUILayout.Button("Summon Valkyrie", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(34f) }) && TryConsumeToll(localPlayer))
			{
				PendingDest = null;
				StartValkyrieFlight(localPlayer, value);
			}
			GUI.enabled = true;
			GUILayout.Space(12f);
			if (GUILayout.Button("Cancel", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(34f) }))
			{
				PendingDest = null;
			}
			GUILayout.EndHorizontal();
			GUILayout.EndArea();
		}

		internal static string GetCurrentWorldKey()
		{
			if ((Object)(object)ZNet.instance != (Object)null)
			{
				string worldName = ZNet.instance.GetWorldName();
				if (!string.IsNullOrEmpty(worldName))
				{
					return worldName;
				}
			}
			return "default";
		}

		internal static void LoadWorldRunestones()
		{
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			string currentWorldKey = GetCurrentWorldKey();
			if (LoadedWorld == currentWorldKey)
			{
				return;
			}
			LoadedWorld = currentWorldKey;
			Discovered.Clear();
			PinsDirty = true;
			if (!File.Exists(SaveFilePath))
			{
				return;
			}
			string[] array = File.ReadAllLines(SaveFilePath);
			for (int i = 0; i < array.Length; i++)
			{
				string[] array2 = array[i].Split(new char[1] { '|' });
				if (array2.Length >= 5 && !(array2[0] != currentWorldKey) && float.TryParse(array2[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result) && float.TryParse(array2[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) && float.TryParse(array2[3], NumberStyles.Float, CultureInfo.InvariantCulture, out var result3))
				{
					Discovered.Add(new RunestonePin
					{
						Pos = new Vector3(result, result2, result3),
						Name = array2[4]
					});
				}
			}
		}

		internal static void SaveWorldRunestones()
		{
			//IL_00c5: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			string currentWorldKey = GetCurrentWorldKey();
			List<string> list = new List<string>();
			if (File.Exists(SaveFilePath))
			{
				string[] array = File.ReadAllLines(SaveFilePath);
				foreach (string text in array)
				{
					if (!text.StartsWith(currentWorldKey + "|", StringComparison.Ordinal))
					{
						list.Add(text);
					}
				}
			}
			foreach (RunestonePin item in Discovered)
			{
				string text2 = (item.Name ?? "Runestone").Replace("|", "-").Replace("\n", " ").Replace("\r", "");
				list.Add(string.Format(CultureInfo.InvariantCulture, "{0}|{1:F2}|{2:F2}|{3:F2}|{4}", currentWorldKey, item.Pos.x, item.Pos.y, item.Pos.z, text2));
			}
			File.WriteAllLines(SaveFilePath, list.ToArray());
		}

		internal static void SyncPinsToMinimap()
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Invalid comparison between Unknown and I4
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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_00b0: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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_00da: Expected O, but got Unknown
			if ((Object)(object)Minimap.instance == (Object)null || Minimap.instance.m_pins == null)
			{
				return;
			}
			Sprite sprite = Minimap.instance.GetSprite((PinType)3);
			foreach (RunestonePin item2 in Discovered)
			{
				bool flag = false;
				foreach (PinData pin in Minimap.instance.m_pins)
				{
					if ((int)pin.m_type == 3 && Vector3.Distance(pin.m_pos, item2.Pos) < 12f)
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					PinData item = new PinData
					{
						m_name = item2.Name,
						m_type = (PinType)3,
						m_pos = item2.Pos,
						m_save = false,
						m_checked = false,
						m_icon = sprite
					};
					Minimap.instance.m_pins.Add(item);
				}
			}
			PinsDirty = false;
		}

		internal static bool IsNearAnyDiscoveredRunestone(Vector3 playerPos, float radius)
		{
			//IL_0015: 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)
			foreach (RunestonePin item in Discovered)
			{
				if (Vector3.Distance(playerPos, item.Pos) <= radius)
				{
					return true;
				}
			}
			return false;
		}

		internal static bool HasRequiredToll(Player player, out string displayName, out int ownedCount)
		{
			displayName = CostItemPrefab.Value;
			ownedCount = 0;
			if (!EnableItemToll.Value || CostItemAmount.Value <= 0)
			{
				return true;
			}
			if ((Object)(object)player == (Object)null || (Object)(object)ObjectDB.instance == (Object)null)
			{
				return false;
			}
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(CostItemPrefab.Value);
			ItemDrop val = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null);
			if ((Object)(object)val == (Object)null)
			{
				return true;
			}
			string name = val.m_itemData.m_shared.m_name;
			displayName = ((Localization.instance != null) ? Localization.instance.Localize(name) : CostItemPrefab.Value);
			ownedCount = ((Humanoid)player).GetInventory().CountItems(name, -1, true);
			return ownedCount >= CostItemAmount.Value;
		}

		internal static bool TryConsumeToll(Player player)
		{
			if (!EnableItemToll.Value || CostItemAmount.Value <= 0)
			{
				return true;
			}
			GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(CostItemPrefab.Value) : null);
			ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null);
			if ((Object)(object)val2 == (Object)null)
			{
				Debug.LogWarning((object)("[ValkyrieRunestones] Unknown toll prefab '" + CostItemPrefab.Value + "', skipping toll check."));
				return true;
			}
			string name = val2.m_itemData.m_shared.m_name;
			string arg = ((Localization.instance != null) ? Localization.instance.Localize(name) : CostItemPrefab.Value);
			Inventory inventory = ((Humanoid)player).GetInventory();
			if (inventory.CountItems(name, -1, true) < CostItemAmount.Value)
			{
				((Character)player).Message((MessageType)2, $"Requires {CostItemAmount.Value}x {arg} to summon the Valkyrie!", 0, (Sprite)null, false);
				return false;
			}
			inventory.RemoveItem(name, CostItemAmount.Value, -1, true);
			((Character)player).Message((MessageType)1, $"Consumed {CostItemAmount.Value}x {arg} for Runestone flight.", 0, (Sprite)null, false);
			return true;
		}

		internal static void StartValkyrieFlight(Player player, RunestonePin dest)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ad: Unknown result type (might be due to invalid IL or missing references)
			IsFlying = true;
			FlightStart = ((Component)player).transform.position;
			FlightDest = dest.Pos;
			FlightDestName = dest.Name;
			if ((Object)(object)Minimap.instance != (Object)null)
			{
				Minimap.instance.SetMapMode((MapMode)1);
			}
			if ((Object)(object)((Character)player).m_body != (Object)null)
			{
				((Character)player).m_body.isKinematic = true;
			}
			GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("Valkyrie") : null);
			if ((Object)(object)val != (Object)null)
			{
				ValkyrieVisual = Object.Instantiate<GameObject>(val, ((Component)player).transform.position + Vector3.up * 2.4f, ((Component)player).transform.rotation);
				ZNetView component = ValkyrieVisual.GetComponent<ZNetView>();
				if ((Object)(object)component != (Object)null)
				{
					Object.Destroy((Object)(object)component);
				}
				Valkyrie component2 = ValkyrieVisual.GetComponent<Valkyrie>();
				if ((Object)(object)component2 != (Object)null)
				{
					Object.Destroy((Object)(object)component2);
				}
			}
			((Character)player).Message((MessageType)2, "A Valkyrie carries you toward " + FlightDestName + "...", 0, (Sprite)null, false);
		}

		internal static void ApplyExhaustionPenalty(Player player, float distance)
		{
			if (AssumedOverlandSpeed.Value > 0f && player.m_foods != null)
			{
				float num = distance / Mathf.Max(0.05f, AssumedOverlandSpeed.Value);
				for (int num2 = player.m_foods.Count - 1; num2 >= 0; num2--)
				{
					Food obj = player.m_foods[num2];
					obj.m_time -= num;
					if (player.m_foods[num2].m_time <= 0f)
					{
						player.m_foods.RemoveAt(num2);
					}
				}
			}
			if (!StripRestedAndMeads.Value)
			{
				return;
			}
			SEMan sEMan = ((Character)player).GetSEMan();
			if (sEMan == null)
			{
				return;
			}
			sEMan.RemoveStatusEffect(StringExtensionMethods.GetStableHashCode("Rested"), true);
			foreach (StatusEffect item in new List<StatusEffect>(sEMan.GetStatusEffects()))
			{
				if ((Object)(object)item != (Object)null && (((Object)item).name.StartsWith("Potion_", StringComparison.OrdinalIgnoreCase) || ((Object)item).name.IndexOf("Mead", StringComparison.OrdinalIgnoreCase) >= 0))
				{
					sEMan.RemoveStatusEffect(item, true);
				}
			}
		}

		internal static void CleanupFlight(Player player)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			IsFlying = false;
			PendingDest = null;
			if ((Object)(object)player != (Object)null && (Object)(object)((Character)player).m_body != (Object)null)
			{
				((Character)player).m_body.isKinematic = false;
				((Character)player).m_body.linearVelocity = Vector3.zero;
			}
			if ((Object)(object)ValkyrieVisual != (Object)null)
			{
				Object.Destroy((Object)(object)ValkyrieVisual);
				ValkyrieVisual = null;
			}
		}
	}
	[HarmonyPatch(typeof(ZNet), "Awake")]
	public static class Patch_ZNet_Awake
	{
		[HarmonyPostfix]
		public static void Postfix()
		{
			ValkyrieRunestonesPlugin.RegisterRPCs();
		}
	}
	[HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")]
	public static class Patch_ZNet_PeerInfo
	{
		[HarmonyPostfix]
		public static void Postfix(ZNet __instance)
		{
			if (__instance.IsServer())
			{
				ValkyrieRunestonesPlugin.BroadcastConfigToAllPeers();
			}
		}
	}
	[HarmonyPatch(typeof(RuneStone), "Interact")]
	public static class Patch_RuneStone_Interact
	{
		[HarmonyPostfix]
		public static void Postfix(RuneStone __instance, Humanoid character, bool hold)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			if (hold || (Object)(object)character == (Object)null || (Object)(object)character != (Object)(object)Player.m_localPlayer)
			{
				return;
			}
			ValkyrieRunestonesPlugin.LoadWorldRunestones();
			Vector3 position = ((Component)__instance).transform.position;
			foreach (ValkyrieRunestonesPlugin.RunestonePin item in ValkyrieRunestonesPlugin.Discovered)
			{
				if (Vector3.Distance(item.Pos, position) < 15f)
				{
					ValkyrieRunestonesPlugin.PinsDirty = true;
					ValkyrieRunestonesPlugin.SyncPinsToMinimap();
					((Character)Player.m_localPlayer).Message((MessageType)1, "Runestone attuned: " + item.Name, 0, (Sprite)null, false);
					return;
				}
			}
			string text = (string.IsNullOrEmpty(__instance.m_topic) ? "Runestone" : __instance.m_topic);
			string text2 = ((Localization.instance != null) ? Localization.instance.Localize(text) : "Runestone");
			if (string.IsNullOrWhiteSpace(text2))
			{
				text2 = "Runestone";
			}
			ValkyrieRunestonesPlugin.Discovered.Add(new ValkyrieRunestonesPlugin.RunestonePin
			{
				Pos = position,
				Name = text2
			});
			ValkyrieRunestonesPlugin.SaveWorldRunestones();
			ValkyrieRunestonesPlugin.PinsDirty = true;
			ValkyrieRunestonesPlugin.SyncPinsToMinimap();
			((Character)Player.m_localPlayer).Message((MessageType)2, $"Runestone attuned: {text2} ({ValkyrieRunestonesPlugin.Discovered.Count} discovered)", 0, (Sprite)null, false);
		}
	}
	[HarmonyPatch(typeof(Minimap), "Update")]
	public static class Patch_Minimap_Update
	{
		internal static string SyncedWorld = "";

		[HarmonyPostfix]
		public static void Postfix(Minimap __instance)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Invalid comparison between Unknown and I4
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: 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_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: 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_0175: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			ValkyrieRunestonesPlugin.LoadWorldRunestones();
			if (SyncedWorld != ValkyrieRunestonesPlugin.LoadedWorld)
			{
				SyncedWorld = ValkyrieRunestonesPlugin.LoadedWorld;
				ValkyrieRunestonesPlugin.RequestServerConfig();
			}
			if (ValkyrieRunestonesPlugin.PinsDirty || Minimap.IsOpen())
			{
				ValkyrieRunestonesPlugin.SyncPinsToMinimap();
			}
			if (!Minimap.IsOpen() || (int)__instance.m_mode != 2 || ValkyrieRunestonesPlugin.IsFlying || !ZInput.GetKeyDown(ValkyrieRunestonesPlugin.TravelHotkey.Value, true))
			{
				return;
			}
			if (ValkyrieRunestonesPlugin.RequireStandingAtRunestone.Value && !ValkyrieRunestonesPlugin.IsNearAnyDiscoveredRunestone(((Component)localPlayer).transform.position, ValkyrieRunestonesPlugin.DepartureRadius.Value))
			{
				((Character)localPlayer).Message((MessageType)2, $"Stand within {ValkyrieRunestonesPlugin.DepartureRadius.Value:F0}m of an attuned Runestone to summon the Valkyrie.", 0, (Sprite)null, false);
				return;
			}
			Vector3 val = __instance.ScreenToWorldPoint(Input.mousePosition);
			float num = Mathf.Max(150f, __instance.m_largeZoom * 450f);
			ValkyrieRunestonesPlugin.RunestonePin? runestonePin = null;
			float num2 = num;
			foreach (ValkyrieRunestonesPlugin.RunestonePin item in ValkyrieRunestonesPlugin.Discovered)
			{
				float num3 = Vector2.Distance(new Vector2(val.x, val.z), new Vector2(item.Pos.x, item.Pos.z));
				if (num3 < num2)
				{
					num2 = num3;
					runestonePin = item;
				}
			}
			if (!runestonePin.HasValue)
			{
				((Character)localPlayer).Message((MessageType)2, $"Hover over an attuned Runestone pin before pressing {ValkyrieRunestonesPlugin.TravelHotkey.Value}.", 0, (Sprite)null, false);
			}
			else if (Vector3.Distance(((Component)localPlayer).transform.position, runestonePin.Value.Pos) < 25f)
			{
				((Character)localPlayer).Message((MessageType)2, "You are already at this Runestone.", 0, (Sprite)null, false);
			}
			else
			{
				ValkyrieRunestonesPlugin.PendingDest = runestonePin.Value;
			}
		}
	}
	[HarmonyPatch(typeof(Player), "Update")]
	public static class Patch_Player_Update
	{
		[HarmonyPostfix]
		public static void Postfix(Player __instance)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: 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_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_020f: 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_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			if (!ValkyrieRunestonesPlugin.IsFlying || (Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return;
			}
			if (((Character)__instance).IsDead())
			{
				ValkyrieRunestonesPlugin.CleanupFlight(__instance);
				return;
			}
			float deltaTime = Time.deltaTime;
			Vector3 position = ((Component)__instance).transform.position;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(position.x, position.z);
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(ValkyrieRunestonesPlugin.FlightDest.x, ValkyrieRunestonesPlugin.FlightDest.z);
			float num = Vector2.Distance(val, val2);
			Vector2 val3;
			if (num <= 3.5f)
			{
				val3 = new Vector2(ValkyrieRunestonesPlugin.FlightStart.x, ValkyrieRunestonesPlugin.FlightStart.z) - val2;
				Vector2 val4 = ((Vector2)(ref val3)).normalized;
				if (((Vector2)(ref val4)).sqrMagnitude < 0.01f)
				{
					val4 = Vector2.up;
				}
				Vector3 val5 = default(Vector3);
				((Vector3)(ref val5))..ctor(ValkyrieRunestonesPlugin.FlightDest.x + val4.x * 2.2f, ValkyrieRunestonesPlugin.FlightDest.y, ValkyrieRunestonesPlugin.FlightDest.z + val4.y * 2.2f);
				float num2 = Mathf.Max(((Object)(object)ZoneSystem.instance != (Object)null) ? ZoneSystem.instance.GetGroundHeight(val5) : ValkyrieRunestonesPlugin.FlightDest.y, ValkyrieRunestonesPlugin.FlightDest.y) + 1f;
				Vector3 val6 = default(Vector3);
				((Vector3)(ref val6))..ctor(val5.x, num2, val5.z);
				((Component)__instance).transform.position = val6;
				((Character)__instance).m_maxAirAltitude = val6.y;
				float distance = Vector3.Distance(ValkyrieRunestonesPlugin.FlightStart, ValkyrieRunestonesPlugin.FlightDest);
				ValkyrieRunestonesPlugin.ApplyExhaustionPenalty(__instance, distance);
				ValkyrieRunestonesPlugin.CleanupFlight(__instance);
				((Character)__instance).Message((MessageType)2, "Arrived at " + ValkyrieRunestonesPlugin.FlightDestName + ".", 0, (Sprite)null, false);
				return;
			}
			val3 = val2 - val;
			Vector2 normalized = ((Vector2)(ref val3)).normalized;
			float num3 = Mathf.Max(5f, ValkyrieRunestonesPlugin.TravelSpeed.Value);
			float num4 = Mathf.Min(num3 * deltaTime, num);
			Vector2 val7 = val + normalized * num4;
			float num5 = Mathf.Max(((Object)(object)ZoneSystem.instance != (Object)null) ? ZoneSystem.instance.GetGroundHeight(new Vector3(val7.x, position.y, val7.y)) : ValkyrieRunestonesPlugin.FlightDest.y, 30f) + ValkyrieRunestonesPlugin.TravelAltitude.Value;
			float num6 = ((num < 85f) ? Mathf.Lerp(ValkyrieRunestonesPlugin.FlightDest.y + 2f, num5, num / 85f) : num5);
			float num7 = Mathf.MoveTowards(position.y, num6, num3 * 1.25f * deltaTime);
			Vector3 val8 = default(Vector3);
			((Vector3)(ref val8))..ctor(val7.x, num7, val7.y);
			((Component)__instance).transform.position = val8;
			((Component)__instance).transform.rotation = Quaternion.LookRotation(new Vector3(normalized.x, 0f, normalized.y));
			((Character)__instance).m_maxAirAltitude = val8.y;
			if ((Object)(object)ValkyrieRunestonesPlugin.ValkyrieVisual != (Object)null)
			{
				ValkyrieRunestonesPlugin.ValkyrieVisual.transform.position = val8 + Vector3.up * 2.4f;
				ValkyrieRunestonesPlugin.ValkyrieVisual.transform.rotation = ((Component)__instance).transform.rotation;
			}
		}
	}
	[HarmonyPatch(typeof(Player), "TakeInput")]
	public static class Patch_Player_TakeInput
	{
		[HarmonyPostfix]
		public static void Postfix(Player __instance, ref bool __result)
		{
			if (ValkyrieRunestonesPlugin.IsFlying && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				__result = false;
			}
		}
	}
	[HarmonyPatch(typeof(Character), "Damage")]
	public static class Patch_Character_Damage
	{
		[HarmonyPrefix]
		public static bool Prefix(Character __instance)
		{
			if (ValkyrieRunestonesPlugin.IsFlying && ValkyrieRunestonesPlugin.InvulnerableDuringFlight.Value && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Player), "OnDestroy")]
	public static class Patch_Player_OnDestroy
	{
		[HarmonyPrefix]
		public static void Prefix(Player __instance)
		{
			if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				ValkyrieRunestonesPlugin.CleanupFlight(__instance);
				ValkyrieRunestonesPlugin.LoadedWorld = "";
				ValkyrieRunestonesPlugin.PinsDirty = true;
				Patch_Minimap_Update.SyncedWorld = "";
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}