Decompiled source of ValkyrieFlyMount v1.0.4

ValkyrieFlyMount.dll

Decompiled 6 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ValkyrieFlyMount")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ValkyrieFlyMount")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4c60a857-ac79-4677-abf0-ca105c4dbf4e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace ValkyrieFlyMount;

[BepInPlugin("shudnal.ValkyrieFlyMount", "Valkyrie Fly Mount", "1.0.4")]
public class ValkyrieFlyMount : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Menu), "OnSkip")]
	public static class Menu_OnSkip_IntroSkip
	{
		private static void Prefix()
		{
			if (Object.op_Implicit((Object)(object)controlledValkyrie))
			{
				controlledValkyrie.DropPlayer(true);
			}
		}
	}

	[HarmonyPatch(typeof(Valkyrie), "Awake")]
	public static class Valkyrie_Awake_MountInitialization
	{
		private static bool Prefix(Valkyrie __instance)
		{
			//IL_00ed: 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_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: 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_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: 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_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: 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_019a: 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)
			if (!modEnabled.Value)
			{
				return true;
			}
			__instance.m_nview = ((Component)__instance).GetComponent<ZNetView>();
			__instance.m_animator = ((Component)__instance).GetComponentInChildren<Animator>();
			if (!__instance.m_nview.IsOwner())
			{
				((Behaviour)__instance).enabled = false;
				return false;
			}
			if (Player.m_localPlayer.m_firstSpawn)
			{
				return true;
			}
			if (!isFlyingMountValkyrie)
			{
				return true;
			}
			Rigidbody val = default(Rigidbody);
			if (!((Component)__instance).gameObject.TryGetComponent<Rigidbody>(ref val))
			{
				((Component)__instance).gameObject.AddComponent<Rigidbody>().useGravity = false;
			}
			__instance.m_startPause = 0f;
			__instance.m_startAltitude = 10f;
			__instance.m_textDuration = 0f;
			__instance.m_descentAltitude = 100f;
			__instance.m_attachOffset = new Vector3(-0.1f, 1.5f, 0.1f);
			__instance.m_speed = 10f;
			__instance.m_turnRate = 5f;
			__instance.m_dropHeight = 10f;
			Vector3 position = ((Component)Player.m_localPlayer).transform.position;
			position.y += __instance.m_startAltitude;
			((Component)__instance).transform.position = position;
			Player.m_localPlayer.m_intro = true;
			__instance.m_targetPoint = new Vector3(0f, ZoneSystem.instance.GetGroundHeight(Vector3.zero) + 150f, 0f);
			LocationInstance val2 = default(LocationInstance);
			if (ZoneSystem.instance.FindClosestLocation("StartTemple", Vector3.zero, ref val2))
			{
				__instance.m_targetPoint = val2.m_position;
			}
			float num = Random.value * (float)Math.PI * 2f;
			Vector3 val3 = default(Vector3);
			((Vector3)(ref val3))..ctor(Mathf.Sin(num), 0f, Mathf.Cos(num));
			Vector3 val4 = Vector3.Cross(val3, Vector3.up);
			__instance.m_descentStart = __instance.m_targetPoint + val3 * __instance.m_startDescentDistance + val4 * 200f;
			__instance.m_descentStart.y = __instance.m_descentAltitude;
			Vector3 val5 = __instance.m_targetPoint - __instance.m_descentStart;
			val5.y = 0f;
			((Vector3)(ref val5)).Normalize();
			__instance.m_flyAwayPoint = __instance.m_targetPoint + val5 * __instance.m_startDescentDistance;
			__instance.m_flyAwayPoint.y = __instance.m_startAltitude;
			__instance.SyncPlayer(true);
			Vector3 val6 = ((Component)__instance).transform.position;
			string? text = ((object)(Vector3)(ref val6)).ToString();
			val6 = ZNet.instance.GetReferencePosition();
			LogInfo("Setting up valkyrie " + text + "   " + ((object)(Vector3)(ref val6)).ToString());
			return false;
		}
	}

	[HarmonyPatch(typeof(Valkyrie), "LateUpdate")]
	public static class Valkyrie_LateUpdate_DismountCommand
	{
		private static void Prefix(Valkyrie __instance)
		{
			//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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (!modEnabled.Value || (Object)(object)__instance != (Object)(object)controlledValkyrie || !isFlyingMountValkyrie)
			{
				return;
			}
			KeyboardShortcut value = mountShortcut.Value;
			if (!((KeyboardShortcut)(ref value)).IsDown())
			{
				value = dismountShortcut.Value;
				if (!((KeyboardShortcut)(ref value)).IsDown() && (!ZInput.GetButton("Use") || !ZInput.GetButton("AltPlace")) && (!ZInput.GetButton("JoyUse") || !ZInput.GetButton("JoyAltPlace")))
				{
					return;
				}
			}
			__instance.DropPlayer(false);
		}
	}

	[HarmonyPatch(typeof(Valkyrie), "UpdateValkyrie")]
	public static class Valkyrie_UpdateValkyrie_MountControl
	{
		private static bool Prefix(Valkyrie __instance, float dt)
		{
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: 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_010c: 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_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: 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_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: 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_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (!modEnabled.Value)
			{
				return true;
			}
			if ((Object)(object)__instance != (Object)(object)controlledValkyrie)
			{
				return true;
			}
			if (!isFlyingMountValkyrie)
			{
				return true;
			}
			Rigidbody val = default(Rigidbody);
			if (!((Component)__instance).TryGetComponent<Rigidbody>(ref val))
			{
				return true;
			}
			if ((DateTime.Now - ZInput.instance.GetLastInputTimer()).TotalSeconds > 60.0)
			{
				return true;
			}
			Vector3 val2 = Vector3.zero;
			Vector3 forward = ((Component)__instance).transform.forward;
			if (CanOperateValkyrie())
			{
				bool flag = ZInput.GetButton("Forward") || ZInput.GetJoyLeftStickY(true) < 0f;
				bool flag2 = ZInput.GetButton("Backward") || ZInput.GetJoyLeftStickY(true) > 0f;
				if (flag && !flag2)
				{
					val2 += forward;
				}
				else if (!flag)
				{
					val2 += forward / 5f;
				}
				if (flag2 && !flag)
				{
					val2 -= forward / 5f;
				}
				if (ZInput.GetButton("Left") || ZInput.GetJoyLeftStickX(false) < 0f)
				{
					val2 -= ((Component)__instance).transform.right / (float)(flag ? 2 : (flag2 ? 10 : 5));
				}
				if (ZInput.GetButton("Right") || ZInput.GetJoyLeftStickX(false) > 0f)
				{
					val2 += ((Component)__instance).transform.right / (float)(flag ? 2 : (flag2 ? 10 : 5));
				}
				if (ZInput.GetButton("Jump") || ZInput.GetButton("JoyRTrigger"))
				{
					val2.y += (flag ? 0.8f : (flag2 ? 0.2f : 0.5f));
				}
				if (ZInput.GetButton("Crouch") || ZInput.GetButton("JoyLTrigger"))
				{
					val2.y -= (flag ? 0.8f : (flag2 ? 0.2f : 0.5f));
				}
				if (((Vector3)(ref val2)).magnitude > 1f)
				{
					((Vector3)(ref val2)).Normalize();
				}
			}
			else
			{
				val2 += forward / 5f;
			}
			shiftStaminaDepleted = shiftStaminaDepleted || !((Character)Player.m_localPlayer).HaveStamina(0f);
			bool flag3 = ZInput.GetButton("Run") || ZInput.GetButton("JoyRun");
			if (flag3)
			{
				shiftDownTime += dt;
			}
			else
			{
				shiftDownTime = 0f;
				shiftStaminaDepleted = false;
			}
			float num = 15f * ((flag3 && !shiftStaminaDepleted) ? (1.5f + Mathf.Min(1f, shiftDownTime / 10f)) : 1f);
			Vector3 val3 = Vector3.Lerp(Vector3.zero, val2 * num, 1f) - val.velocity;
			if (((Vector3)(ref val3)).magnitude > 15f)
			{
				val3 = ((Vector3)(ref val3)).normalized * 15f;
			}
			val.AddForce(val3, (ForceMode)2);
			Vector3 val4 = default(Vector3);
			Quaternion val5 = default(Quaternion);
			GameCamera.m_instance.GetCameraPosition(dt, ref val4, ref val5);
			Quaternion rotation = Quaternion.RotateTowards(((Component)__instance).transform.rotation, val5, __instance.m_turnRate * 15f * dt);
			((Component)__instance).transform.rotation = rotation;
			return false;
		}

		private static void Postfix(Valkyrie __instance)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			if (modEnabled.Value && !((Object)(object)__instance != (Object)(object)controlledValkyrie))
			{
				Vector3 position = ((Component)__instance).transform.position;
				float num = default(float);
				if (ZoneSystem.instance.GetGroundHeight(position, ref num))
				{
					position.y = Mathf.Min(Mathf.Max(position.y, Mathf.Max(num, ZoneSystem.instance.m_waterLevel) + 5f), 1000f);
					((Component)__instance).transform.position = position;
				}
			}
		}
	}

	[HarmonyPatch(typeof(Valkyrie), "DropPlayer")]
	public static class Valkyrie_DropPlayer_Dismount
	{
		private static void Postfix(Valkyrie __instance)
		{
			//IL_00b4: 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_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_00dc: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			if (modEnabled.Value && !((Object)(object)__instance != (Object)(object)controlledValkyrie) && isFlyingMountValkyrie)
			{
				isFlyingMountValkyrie = false;
				playerDropped = true;
				if (!((Character)Player.m_localPlayer).m_seman.HaveStatusEffect("SlowFall"))
				{
					castSlowFall = true;
					((Character)Player.m_localPlayer).m_seman.AddStatusEffect(StringExtensionMethods.GetStableHashCode("SlowFall"), false, 0, 0f);
					LogInfo("Cast slow fall");
				}
				((Behaviour)Hud.instance.m_crosshair).enabled = crosshairState;
				Vector3 forward = ((Component)Player.m_localPlayer).transform.forward;
				forward.y = 0f;
				__instance.m_flyAwayPoint = ((Component)Player.m_localPlayer).transform.position + forward * 300f;
				__instance.m_flyAwayPoint.y = Mathf.Max(ZoneSystem.instance.GetGroundHeight(__instance.m_flyAwayPoint), ZoneSystem.instance.m_waterLevel) + Mathf.Max(((Component)Player.m_localPlayer).transform.position.y + 100f, 150f);
				__instance.m_speed = 15f;
				controlledValkyrie = null;
			}
		}
	}

	[HarmonyPatch(typeof(Player), "InCutscene")]
	public static class Player_InCutscene_Taxi
	{
		private static void Postfix(Player __instance, ref bool __result)
		{
			if (modEnabled.Value && !((Object)(object)Player.m_localPlayer != (Object)(object)__instance) && isFlyingMountValkyrie)
			{
				__result = false;
			}
		}
	}

	[HarmonyPatch(typeof(Player), "CheckRun")]
	public static class Player_CheckRun_Taxi
	{
		private static void Prefix(Player __instance, ref float __state)
		{
			if (modEnabled.Value && !((Object)(object)Player.m_localPlayer != (Object)(object)__instance) && isFlyingMountValkyrie)
			{
				__state = Game.m_moveStaminaRate;
				Game.m_moveStaminaRate *= 2f;
			}
		}

		private static void Postfix(Player __instance, ref float __state)
		{
			if (modEnabled.Value && !((Object)(object)Player.m_localPlayer != (Object)(object)__instance) && isFlyingMountValkyrie)
			{
				Game.m_moveStaminaRate = __state;
			}
		}
	}

	[HarmonyPatch(typeof(Character), "Jump")]
	public static class Character_Jump_Taxi
	{
		private static void Prefix(Character __instance, ref float __state)
		{
			if (modEnabled.Value && !((Object)(object)Player.m_localPlayer != (Object)(object)__instance) && isFlyingMountValkyrie)
			{
				__state = __instance.m_jumpStaminaUsage;
				__instance.m_jumpStaminaUsage = 0f;
			}
		}

		private static void Postfix(Character __instance, ref float __state)
		{
			if (modEnabled.Value && !((Object)(object)Player.m_localPlayer != (Object)(object)__instance) && isFlyingMountValkyrie)
			{
				__instance.m_jumpStaminaUsage = __state;
			}
		}
	}

	[HarmonyPatch(typeof(Player), "Update")]
	public static class Player_Update_Taxi
	{
		private static void Postfix(Player __instance)
		{
			if (modEnabled.Value && !((Object)(object)Player.m_localPlayer != (Object)(object)__instance) && !isFlyingMountValkyrie && playerDropped && castSlowFall && ((Character)__instance).IsOnGround())
			{
				castSlowFall = false;
				playerDropped = false;
				if (((Character)__instance).m_seman.HaveStatusEffect("SlowFall"))
				{
					((Character)__instance).m_seman.RemoveStatusEffect(StringExtensionMethods.GetStableHashCode("SlowFall"), true);
				}
				LogInfo("Remove slow fall");
			}
		}
	}

	[HarmonyPatch(typeof(Player), "UpdateBiome")]
	public static class Player_UpdateBiome_PreserveBiomeCalculation
	{
		private static void Prefix(ref Player __instance)
		{
			if (modEnabled.Value && !((Object)(object)Player.m_localPlayer != (Object)(object)__instance) && isFlyingMountValkyrie && ((Character)__instance).InIntro())
			{
				__instance.m_intro = false;
			}
		}

		private static void Postfix(ref Player __instance)
		{
			if (modEnabled.Value && !((Object)(object)Player.m_localPlayer != (Object)(object)__instance) && isFlyingMountValkyrie && !((Character)__instance).InIntro())
			{
				__instance.m_intro = true;
			}
		}
	}

	[HarmonyPatch(typeof(Player), "UpdateStats", new Type[] { typeof(float) })]
	public static class Player_UpdateStats_PreserveStatsCalculation
	{
		private static void Prefix(ref Player __instance)
		{
			if (modEnabled.Value && !((Object)(object)Player.m_localPlayer != (Object)(object)__instance) && isFlyingMountValkyrie && ((Character)__instance).InIntro())
			{
				__instance.m_intro = false;
			}
		}

		private static void Postfix(ref Player __instance)
		{
			if (modEnabled.Value && !((Object)(object)Player.m_localPlayer != (Object)(object)__instance) && isFlyingMountValkyrie && !((Character)__instance).InIntro())
			{
				__instance.m_intro = true;
			}
		}
	}

	[HarmonyPatch(typeof(Character), "Damage")]
	public static class Character_Damage_PlayerProtection
	{
		private static void Prefix(Character __instance, ref HitData hit, ZNetView ___m_nview)
		{
			if (modEnabled.Value && !((Object)(object)___m_nview == (Object)null) && isFlyingMountValkyrie && __instance.IsPlayer() && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && (!hit.HaveAttacker() || !hit.GetAttacker().IsBoss()))
			{
				((DamageTypes)(ref hit.m_damage)).Modify(Math.Max(0.1f, 0f));
			}
		}
	}

	[HarmonyPatch(typeof(Hud), "UpdateCrosshair")]
	[HarmonyPriority(0)]
	public static class Hud_UpdateCrosshair_ShowBowCrosshair
	{
		private static void Prefix(Hud __instance, Player player)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Invalid comparison between Unknown and I4
			if (modEnabled.Value && isFlyingMountValkyrie && crosshairState)
			{
				bool flag = ((Humanoid)player).GetLeftItem() != null && (int)((Humanoid)player).GetLeftItem().m_shared.m_itemType == 4;
				if (((Behaviour)Hud.instance.m_crosshair).enabled != flag)
				{
					((Behaviour)Hud.instance.m_crosshair).enabled = flag;
				}
			}
		}
	}

	[HarmonyPatch(typeof(EnvMan), "GetEnvironmentOverride")]
	public static class EnvMan_GetEnvironmentOverride_EnableWeatherOnFlight
	{
		[HarmonyPriority(0)]
		private static void Prefix(ref Player __state)
		{
			if (modEnabled.Value && isFlyingMountValkyrie)
			{
				__state = Player.m_localPlayer;
				Player.m_localPlayer = null;
			}
		}

		[HarmonyPriority(800)]
		private static void Postfix(Player __state)
		{
			if (modEnabled.Value && isFlyingMountValkyrie)
			{
				Player.m_localPlayer = __state;
			}
		}
	}

	private const string pluginID = "shudnal.ValkyrieFlyMount";

	private const string pluginName = "Valkyrie Fly Mount";

	private const string pluginVersion = "1.0.4";

	private Harmony _harmony;

	private static ConfigEntry<bool> modEnabled;

	private static ConfigEntry<bool> loggingEnabled;

	private static ConfigEntry<KeyboardShortcut> mountShortcut;

	private static ConfigEntry<KeyboardShortcut> dismountShortcut;

	internal static ValkyrieFlyMount instance;

	internal static Valkyrie controlledValkyrie;

	private static bool isFlyingMountValkyrie;

	internal static bool playerDropped;

	internal static bool castSlowFall;

	internal static float shiftDownTime;

	internal static bool shiftStaminaDepleted;

	internal static DateTime flightStarted;

	internal static bool crosshairState;

	private void Awake()
	{
		if (IsDedicated())
		{
			((BaseUnityPlugin)instance).Logger.LogWarning((object)"Dedicated server. Loading skipped.");
			return;
		}
		_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "shudnal.ValkyrieFlyMount");
		instance = this;
		ConfigInit();
	}

	private void OnDestroy()
	{
		((BaseUnityPlugin)this).Config.Save();
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}

	public static void LogInfo(object data)
	{
		if (loggingEnabled.Value)
		{
			((BaseUnityPlugin)instance).Logger.LogInfo(data);
		}
	}

	private void ConfigInit()
	{
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 2520, "Nexus mod ID for updates");
		modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable the mod.");
		loggingEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Logging enabled", true, "Enable logging.");
		mountShortcut = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "Mount shortcut", new KeyboardShortcut((KeyCode)116, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 }), "Mount shortcut.");
		dismountShortcut = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "Disount shortcut", new KeyboardShortcut((KeyCode)101, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 }), "Dismount shortcut.");
	}

	public void LateUpdate()
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		if (modEnabled.Value && !((Object)(object)Player.m_localPlayer == (Object)null))
		{
			KeyboardShortcut value = mountShortcut.Value;
			if (((KeyboardShortcut)(ref value)).IsDown() || (ZInput.GetButton("AltPlace") && ZInput.GetButton("Crouch") && ZInput.GetButton("Jump")) || (ZInput.GetButton("JoyAltPlace") && ZInput.GetButton("JoyCrouch") && ZInput.GetButton("JoyJump")))
			{
				SpawnValkyrie(Player.m_localPlayer);
			}
		}
	}

	public static bool CanOperateValkyrie()
	{
		Player localPlayer = Player.m_localPlayer;
		return !((Object)(object)localPlayer == (Object)null) && !((Character)localPlayer).IsDead() && !((Character)localPlayer).InCutscene() && !((Character)localPlayer).IsTeleporting() && ((Object)(object)Chat.instance == (Object)null || !Chat.instance.HasFocus()) && !Console.IsVisible() && !Menu.IsVisible() && (Object)(object)TextViewer.instance != (Object)null && !TextViewer.instance.IsVisible() && !TextInput.IsVisible() && !Minimap.IsOpen() && !GameCamera.InFreeFly() && !StoreGui.IsVisible() && !InventoryGui.IsVisible();
	}

	public static bool IsDedicated()
	{
		MethodInfo method = typeof(ZNet).GetMethod("IsDedicated", BindingFlags.Instance | BindingFlags.Public);
		Func<ZNet, bool> func = (Func<ZNet, bool>)Delegate.CreateDelegate(typeof(Func<ZNet, bool>), method);
		return func(null);
	}

	private void SpawnValkyrie(Player player)
	{
		if (isFlyingMountValkyrie)
		{
			return;
		}
		if ((Object)(object)controlledValkyrie != (Object)null)
		{
			((Character)player).Message((MessageType)2, Localization.instance.Localize("$hud_powernotready"), 0, (Sprite)null);
		}
		else if (CanOperateValkyrie() && !((Character)player).IsAttachedToShip() && !((Character)player).IsAttached() && !((Character)player).IsDead() && !((Character)player).IsRiding() && !player.IsSleeping() && !((Character)player).IsTeleporting() && !((Character)player).InPlaceMode() && !((Character)player).InBed() && !((Character)player).InCutscene() && !((Character)player).InInterior())
		{
			isFlyingMountValkyrie = true;
			flightStarted = DateTime.Now;
			if ((Object)(object)((Character)player).m_nview != (Object)null && ((Character)player).m_nview.IsValid())
			{
				((Character)player).Heal((((Character)player).GetMaxHealth() - ((Character)player).GetHealth()) * 0.3f, true);
				((Character)player).AddStamina(((Character)player).GetMaxStamina());
				((Character)player).SetCrouch(false);
			}
			crosshairState = ((Behaviour)Hud.instance.m_crosshair).enabled;
			((Behaviour)Hud.instance.m_crosshair).enabled = false;
			controlledValkyrie = Object.Instantiate<GameObject>(ZNetScene.instance.GetPrefab("Valkyrie")).GetComponent<Valkyrie>();
		}
	}
}