Decompiled source of ValkyrieFlyMount v1.0.10

ValkyrieFlyMount.dll

Decompiled 2 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 SoftReferenceableAssets;
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.10")]
public class ValkyrieFlyMount : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Menu), "OnSkip")]
	public static class Menu_OnSkip_IntroSkip
	{
		private static bool Prefix(Menu __instance)
		{
			if (!Object.op_Implicit((Object)(object)controlledValkyrie))
			{
				return true;
			}
			__instance.Hide();
			controlledValkyrie.DropPlayer(menuTeleportOnSkip.Value);
			return menuTeleportOnSkip.Value;
		}
	}

	[HarmonyPatch(typeof(Valkyrie), "Awake")]
	public static class Valkyrie_Awake_MountInitialization
	{
		private static bool Prefix(Valkyrie __instance)
		{
			//IL_00c8: 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_00fd: 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_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: 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_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: 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_021a: 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_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: 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_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: 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 (!isFlyingMountValkyrie)
			{
				return true;
			}
			Rigidbody val = default(Rigidbody);
			if (!((Component)__instance).gameObject.TryGetComponent<Rigidbody>(ref val))
			{
				((Component)__instance).gameObject.AddComponent<Rigidbody>().useGravity = false;
			}
			__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;
			Vector3 val2 = default(Vector3);
			Quaternion rotation = default(Quaternion);
			GameCamera.m_instance.GetCameraPosition(Time.unscaledDeltaTime, ref val2, ref rotation);
			((Component)__instance).transform.rotation = rotation;
			Player.m_localPlayer.m_intro = true;
			__instance.m_targetPoint = new Vector3(0f, ZoneSystem.instance.GetGroundHeight(Vector3.zero) + 150f, 0f);
			LocationInstance val3 = default(LocationInstance);
			if (ZoneSystem.instance.FindClosestLocation("StartTemple", Vector3.zero, ref val3))
			{
				__instance.m_targetPoint = val3.m_position;
			}
			float num = Random.value * (float)Math.PI * 2f;
			Vector3 val4 = default(Vector3);
			((Vector3)(ref val4))..ctor(Mathf.Sin(num), 0f, Mathf.Cos(num));
			Vector3 val5 = Vector3.Cross(val4, Vector3.up);
			__instance.m_descentStart = __instance.m_targetPoint + val4 * __instance.m_startDescentDistance + val5 * 200f;
			__instance.m_descentStart.y = __instance.m_descentAltitude;
			Vector3 val6 = __instance.m_targetPoint - __instance.m_descentStart;
			val6.y = 0f;
			((Vector3)(ref val6)).Normalize();
			__instance.m_flyAwayPoint = __instance.m_targetPoint + val6 * __instance.m_startDescentDistance;
			__instance.m_flyAwayPoint.y = __instance.m_startAltitude;
			__instance.SyncPlayer(true);
			val2 = ((Component)__instance).transform.position;
			string? text = ((object)(Vector3)(ref val2)).ToString();
			val2 = ZNet.instance.GetReferencePosition();
			LogInfo("Setting up valkyrie " + text + "   " + ((object)(Vector3)(ref val2)).ToString());
			return false;
		}
	}

	[HarmonyPatch(typeof(Valkyrie), "LateUpdate")]
	public static class Valkyrie_LateUpdate_DismountCommand
	{
		private static void Postfix(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_00c2: 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_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_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_0406: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_041c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0422: Unknown result type (might be due to invalid IL or missing references)
			//IL_0427: Unknown result type (might be due to invalid IL or missing references)
			//IL_042c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0456: Unknown result type (might be due to invalid IL or missing references)
			//IL_0475: Unknown result type (might be due to invalid IL or missing references)
			//IL_047a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0495: Unknown result type (might be due to invalid IL or missing references)
			//IL_049a: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0444: Unknown result type (might be due to invalid IL or missing references)
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0453: 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_01a9: 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_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: 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_01f9: 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_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			if (!modEnabled.Value)
			{
				return true;
			}
			if (TextViewer.IsShowingIntro())
			{
				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 (!ValkyrieFlyMount.isHovering && (DateTime.Now - ZInput.instance.GetLastInputTimer()).TotalSeconds > 60.0)
			{
				return true;
			}
			bool isHovering = ValkyrieFlyMount.isHovering;
			KeyboardShortcut value = hoverShortcut.Value;
			ValkyrieFlyMount.isHovering = isHovering ^ ((KeyboardShortcut)(ref value)).IsDown();
			Vector3 forward = ((Component)__instance).transform.forward;
			Vector3 val2 = (ValkyrieFlyMount.isHovering ? Vector3.zero : (forward / 4f));
			currentForce = Mathf.MoveTowards(currentForce, 0f, dt);
			if (CanOperateValkyrie())
			{
				bool flag = ZInput.GetButton("Forward") || ZInput.GetJoyLeftStickY(true) < 0f;
				bool flag2 = ZInput.GetButton("Backward") || ZInput.GetJoyLeftStickY(true) > 0f;
				if (flag && !flag2)
				{
					currentForce = Mathf.MoveTowards(currentForce, 1f, dt * 3f * forwardAccelerationMultiplier.Value);
				}
				else if (flag2 && !flag)
				{
					val2 -= forward / 4f;
				}
				if (ZInput.GetButton("Left") || ZInput.GetJoyLeftStickX(false) < 0f)
				{
					val2 -= ((Component)__instance).transform.right / (float)(flag ? 2 : (flag2 ? 10 : 5)) * horizontalAccelerationMultiplier.Value;
				}
				if (ZInput.GetButton("Right") || ZInput.GetJoyLeftStickX(false) > 0f)
				{
					val2 += ((Component)__instance).transform.right / (float)(flag ? 2 : (flag2 ? 10 : 5)) * horizontalAccelerationMultiplier.Value;
				}
				if (ZInput.GetButton("Jump") || ZInput.GetButton("JoyRTrigger"))
				{
					val2.y += (flag ? 0.8f : (flag2 ? 0.2f : 0.5f)) * verticalAccelerationMultiplier.Value;
				}
				if (ZInput.GetButton("Crouch") || ZInput.GetButton("JoyLTrigger"))
				{
					val2.y -= (flag ? 0.8f : (flag2 ? 0.2f : 0.5f)) * verticalAccelerationMultiplier.Value;
				}
				if (hoveringStoppedByMoving.Value && (flag || flag2))
				{
					ValkyrieFlyMount.isHovering = false;
				}
			}
			val2 += forward * currentForce;
			if (((Vector3)(ref val2)).magnitude > 1f)
			{
				((Vector3)(ref val2)).Normalize();
			}
			accelerationStaminaDepleted = accelerationStaminaDepleted || !((Character)Player.m_localPlayer).HaveStamina(0f);
			bool flag3 = ZInput.GetButton("Run") || ZInput.GetButton("JoyRun");
			if (flag3)
			{
				accelerationMultiplier = Mathf.MoveTowards(accelerationMultiplier, 1f, boostAccelerationMultiplier.Value * dt / 10f);
			}
			else
			{
				accelerationMultiplier = Mathf.MoveTowards(accelerationMultiplier, 0f, dt);
				accelerationStaminaDepleted = false;
			}
			float num = ((flag3 && !accelerationStaminaDepleted) ? (1.5f + accelerationMultiplier) : 1f);
			Vector3 val3 = 15f * val2 * num * forceMultiplier.Value - 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 * rotationMultiplier.Value);
			((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_0082: 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), maxAltitude.Value);
					((Component)__instance).transform.position = position;
				}
			}
		}
	}

	[HarmonyPatch(typeof(Valkyrie), "DropPlayer")]
	public static class Valkyrie_DropPlayer_Dismount
	{
		private static void Postfix(Valkyrie __instance)
		{
			//IL_00af: 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_00cc: 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_00d7: 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_00f2: 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)
			if (modEnabled.Value && !((Object)(object)__instance != (Object)(object)controlledValkyrie) && isFlyingMountValkyrie)
			{
				isFlyingMountValkyrie = false;
				playerDropped = true;
				if (!((Character)Player.m_localPlayer).GetSEMan().HaveStatusEffect(slowFallHash))
				{
					castSlowFall = true;
					((Character)Player.m_localPlayer).GetSEMan().AddStatusEffect(slowFallHash, 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), "TeleportTo")]
	public static class Player_TeleportTo_TeleportDrop
	{
		private static void Prefix()
		{
			if (Object.op_Implicit((Object)(object)controlledValkyrie))
			{
				controlledValkyrie.DropPlayer(true);
			}
		}
	}

	[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).GetSEMan().HaveStatusEffect(slowFallHash))
				{
					((Character)__instance).GetSEMan().RemoveStatusEffect(slowFallHash, 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")]
	public static class Hud_UpdateCrosshair_ShowBowCrosshair
	{
		[HarmonyPriority(0)]
		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)__instance.m_crosshair).enabled != flag)
				{
					((Behaviour)__instance.m_crosshair).enabled = flag;
				}
			}
		}
	}

	[HarmonyPatch(typeof(EnvMan), "GetEnvironmentOverride")]
	public static class EnvMan_GetEnvironmentOverride_EnableWeatherOnFlight
	{
		[HarmonyPriority(0)]
		private static void Prefix(ref Player __state)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Invalid comparison between Unknown and I4
			if (modEnabled.Value && (int)SystemInfo.graphicsDeviceType != 4 && isFlyingMountValkyrie)
			{
				__state = Player.m_localPlayer;
				Player.m_localPlayer = null;
			}
		}

		[HarmonyPriority(800)]
		private static void Postfix(Player __state)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Invalid comparison between Unknown and I4
			if (modEnabled.Value && (int)SystemInfo.graphicsDeviceType != 4 && isFlyingMountValkyrie)
			{
				Player.m_localPlayer = __state;
			}
		}
	}

	private const string pluginID = "shudnal.ValkyrieFlyMount";

	private const string pluginName = "Valkyrie Fly Mount";

	private const string pluginVersion = "1.0.10";

	private readonly Harmony harmony = new Harmony("shudnal.ValkyrieFlyMount");

	private static ConfigEntry<bool> modEnabled;

	private static ConfigEntry<bool> loggingEnabled;

	private static ConfigEntry<KeyboardShortcut> mountShortcut;

	private static ConfigEntry<KeyboardShortcut> dismountShortcut;

	private static ConfigEntry<bool> menuTeleportOnSkip;

	private static ConfigEntry<KeyboardShortcut> hoverShortcut;

	private static ConfigEntry<bool> hoveringStoppedByMoving;

	private static ConfigEntry<float> maxAltitude;

	private static ConfigEntry<float> forceMultiplier;

	private static ConfigEntry<float> rotationMultiplier;

	private static ConfigEntry<float> verticalAccelerationMultiplier;

	private static ConfigEntry<float> horizontalAccelerationMultiplier;

	private static ConfigEntry<float> boostAccelerationMultiplier;

	private static ConfigEntry<float> forwardAccelerationMultiplier;

	internal static ValkyrieFlyMount instance;

	internal static Valkyrie controlledValkyrie;

	private static bool isFlyingMountValkyrie = false;

	internal static bool playerDropped = false;

	internal static bool castSlowFall;

	internal static float accelerationMultiplier;

	internal static bool accelerationStaminaDepleted;

	internal static bool isHovering = false;

	internal static bool crosshairState;

	private static readonly int slowFallHash = StringExtensionMethods.GetStableHashCode("SlowFall");

	private static float currentForce = 0f;

	internal static SoftReference<GameObject> valkyriePrefab => Player.m_localPlayer.m_valkyrie;

	private void Awake()
	{
		harmony.PatchAll();
		instance = this;
		ConfigInit();
		Game.isModded = true;
	}

	private void OnDestroy()
	{
		((BaseUnityPlugin)this).Config.Save();
		instance = null;
		Harmony obj = harmony;
		if (obj != null)
		{
			obj.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)
		//IL_0100: 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", false, "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.");
		menuTeleportOnSkip = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Teleport to bed on menu skip", false, "Teleport to current spawn point when using Skip intro menu button.");
		hoverShortcut = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hovering", "Hovering shortcut", new KeyboardShortcut((KeyCode)116, Array.Empty<KeyCode>()), "Hovering shortcut. Press while on valkyrie to stop moving forward automatically.");
		hoveringStoppedByMoving = ((BaseUnityPlugin)this).Config.Bind<bool>("Hovering", "Hovering stopped by moving", true, "If true - moving valkyrie will resume flying forward.\nIf false - only pressing hovering shortcut again will start valkyrie flying forward automatically.");
		maxAltitude = ((BaseUnityPlugin)this).Config.Bind<float>("Misc", "Maximum altitude", 1500f, "Height limit.");
		forceMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Misc", "Force multiplier", 1f, "Multiplier of force applied to move Valkyrie. Basically indirect speed multiplier");
		rotationMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Misc", "Rotation multiplier", 1f, "Multiplier of rotation delta. Basically angular velocity");
		verticalAccelerationMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Misc", "Vertical Acceleration multiplier", 1f, "Multiplier of vertical change of speed on Up and Down movement");
		horizontalAccelerationMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Misc", "Horizontal Acceleration multiplier", 1f, "Multiplier of horizontal change of speed on Left or Right movement");
		boostAccelerationMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Misc", "Boost Acceleration multiplier", 1f, "Multiplier of speed of boost speed increase");
		forwardAccelerationMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Misc", "Forward acceleration multiplier", 1f, "Multiplier of speed of regular movement speed increase");
	}

	public void LateUpdate()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Invalid comparison between Unknown and I4
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		if (modEnabled.Value && (int)SystemInfo.graphicsDeviceType != 4 && !((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();
	}

	private void SpawnValkyrie(Player player)
	{
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: 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_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Expected O, but got Unknown
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		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;
			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;
			currentForce = 0f;
			isHovering = false;
			valkyriePrefab.Load();
			GameObject val = Object.Instantiate<GameObject>(valkyriePrefab.Asset);
			val.GetComponent<ZNetView>().HoldReferenceTo((IReferenceCounted)(object)valkyriePrefab);
			controlledValkyrie = val.GetComponent<Valkyrie>();
			valkyriePrefab.Release();
		}
	}
}