Decompiled source of Birdheim v1.0.2

Birdheim.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using MagicaCloth2;
using Microsoft.CodeAnalysis;
using Splatform;
using TMPro;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.EventSystems;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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 Birdheim
{
	internal static class ArrowGuard
	{
		[HarmonyPatch(typeof(Projectile), "Awake")]
		private static class Projectile_Awake
		{
			private static void Postfix(Projectile __instance)
			{
				s_shots.Add(__instance);
				s_made++;
			}
		}

		[HarmonyPatch(typeof(Character), "RPC_Damage")]
		private static class Character_RPC_Damage
		{
			private static bool Prefix(Character __instance, HitData hit)
			{
				return !Spends(__instance, hit);
			}
		}

		private const float DashSpeed = 70f;

		private const float Aimed = 1.3f;

		private const float Before = 0.35f;

		private const float BeforeRemote = 0.7f;

		private const float After = 0.6f;

		private static bool s_plannedRemote;

		private const float MinDash = 0.15f;

		private const float LastMoment = 0.04f;

		private const float GuardToward = 3f;

		private const float GuardAfter = 1.5f;

		private static readonly List<Projectile> s_shots = new List<Projectile>();

		private static readonly Dictionary<Projectile, Vector3> s_lastAt = new Dictionary<Projectile, Vector3>();

		private static readonly Dictionary<Projectile, Vector3> s_velocity = new Dictionary<Projectile, Vector3>();

		private static readonly HashSet<Projectile> s_ignored = new HashSet<Projectile>();

		private static readonly HashSet<Projectile> s_unreached = new HashSet<Projectile>();

		private static readonly HashSet<Projectile> s_described = new HashSet<Projectile>();

		private static Projectile s_planned;

		private static Vector3 s_meetPoint;

		private static float s_meetAt = -99f;

		private static float s_damage;

		private static float s_readyAt;

		private static Character s_archer;

		private static float s_guardUntil;

		private static Vector3 s_centre;

		private static bool s_haveCentre;

		private static string s_trace = "";

		private static int s_catches;

		private static int s_dives;

		private static int s_made;

		private static int s_aimed;

		public static bool FreezeOnDive;

		public static float Watch(float level)
		{
			return Gear.ParamAt(level, Settings.GuardWatch0.Value, Settings.GuardWatch100.Value);
		}

		public static float Reach(float level)
		{
			return Gear.ParamAt(level, Settings.GuardReach0.Value, Settings.GuardReach100.Value);
		}

		public static float Every(float level)
		{
			return Gear.ParamAt(level, Settings.GuardEvery0.Value, Settings.GuardEvery100.Value);
		}

		public static float Cost(Player player, float level)
		{
			return Gear.ParamAt(level, Settings.GuardCost0.Value, Settings.GuardCost100.Value) * Bond.MaxTime(player) * Mathf.Max(0f, 1f - Settings.GuardCostLessPerLevel.Value * (float)(Gear.Quality - 1));
		}

		private static bool Ready(Player player, Companion bird)
		{
			if ((Object)(object)player == (Object)null || (Object)(object)bird == (Object)null || Gear.Active != GearKind.Shield)
			{
				return false;
			}
			if (bird.IsControlled || bird.GoingHome || bird.Eating || ((Character)player).InInterior() || ((Character)player).IsDead())
			{
				return false;
			}
			if (Time.time < s_readyAt)
			{
				return false;
			}
			return Bond.Strength >= 2f;
		}

		public static void Update(float dt)
		{
			s_shots.RemoveAll((Projectile shot) => (Object)(object)shot == (Object)null);
			Player localPlayer = Player.m_localPlayer;
			Companion local = Companion.Local;
			Track(dt);
			if (!Ready(localPlayer, local))
			{
				if (Gear.Active == GearKind.Shield && (Object)(object)local != (Object)null)
				{
					s_trace = ((Time.time < s_readyAt) ? $"resting from a catch, {s_readyAt - Time.time:0.0} s" : "not ready");
				}
				s_archer = null;
				return;
			}
			float level = Gear.Level;
			if (!(s_meetAt > 0f) || !(Time.time < s_meetAt + 0.6f))
			{
				s_planned = null;
				Guard(localPlayer, local, level);
				Catch(localPlayer, local, level);
			}
		}

		private static void Track(float dt)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			foreach (Projectile s_shot in s_shots)
			{
				Vector3 position = ((Component)s_shot).transform.position;
				Vector3 value;
				if ((Object)(object)s_shot.m_nview != (Object)null && s_shot.m_nview.IsValid() && s_shot.m_nview.IsOwner())
				{
					s_velocity[s_shot] = s_shot.m_vel;
				}
				else if (s_lastAt.TryGetValue(s_shot, out value) && dt > 0f)
				{
					Vector3 val = (position - value) / dt;
					s_velocity[s_shot] = ((s_velocity.TryGetValue(s_shot, out var value2) && value2 != Vector3.zero) ? Vector3.Lerp(value2, val, 0.5f) : val);
				}
				s_lastAt[s_shot] = position;
			}
			if (s_lastAt.Count <= s_shots.Count * 2 + 16)
			{
				return;
			}
			List<Projectile> list = new List<Projectile>();
			foreach (Projectile key in s_lastAt.Keys)
			{
				if ((Object)(object)key == (Object)null)
				{
					list.Add(key);
				}
			}
			foreach (Projectile item in list)
			{
				s_lastAt.Remove(item);
				s_velocity.Remove(item);
				s_ignored.Remove(item);
				s_unreached.Remove(item);
				s_described.Remove(item);
			}
		}

		private static bool Catch(Player player, Companion bird, float level)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: 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_010f: 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_0187: 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_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: 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_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: 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_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			Vector3 centerPoint = ((Character)player).GetCenterPoint();
			Vector3 body = bird.Body;
			float num = Reach(level);
			foreach (Projectile s_shot in s_shots)
			{
				if (s_ignored.Contains(s_shot) || !s_velocity.TryGetValue(s_shot, out var value) || s_shot.m_didHit)
				{
					continue;
				}
				if ((Object)(object)s_shot.m_owner != (Object)null && s_shot.m_owner.IsPlayer())
				{
					s_ignored.Add(s_shot);
					continue;
				}
				float magnitude = ((Vector3)(ref value)).magnitude;
				if (magnitude < 3f)
				{
					continue;
				}
				Vector3 position = ((Component)s_shot).transform.position;
				float num2 = (((Object)(object)s_shot.m_nview != (Object)null && s_shot.m_nview.IsValid() && s_shot.m_nview.IsOwner()) ? s_shot.m_gravity : 0f);
				float num3 = 0f;
				float num4 = float.MaxValue;
				for (float num5 = 0f; num5 <= 3f; num5 += 0.02f)
				{
					float num6 = Vector3.Distance(At(position, value, num2, num5), centerPoint);
					if (num6 < num4)
					{
						num4 = num6;
						num3 = num5;
					}
				}
				if (s_described.Add(s_shot))
				{
					BirdheimPlugin.Log.LogInfo((object)$"guard: a shot seen: {((Object)s_shot).name} ({magnitude:0} m/s, gravity {num2:0.0}, blast {s_shot.m_aoe:0.0} m), {Vector3.Distance(position, centerPoint):0.0} m off, passes {num4:0.0} m from the chest in {num3:0.00} s");
				}
				if (num3 <= 0.02f || num3 > 3f || num4 > 1.3f + Mathf.Max(0f, s_shot.m_aoe))
				{
					continue;
				}
				if (!s_unreached.Contains(s_shot) && (Object)(object)s_shot != (Object)(object)s_planned)
				{
					s_aimed++;
				}
				float num7 = num3 - 0.7f / magnitude;
				float num8 = -1f;
				float num9 = float.MaxValue;
				Vector3 meet = Vector3.zero;
				for (int i = 0; i <= 32; i++)
				{
					float num10 = num7 * (float)i / 32f;
					if (!(num10 <= 0.06f))
					{
						Vector3 val = At(position, value, num2, num10);
						float num11 = Vector3.Distance(body, val);
						if (!(num11 > num) && !(num11 >= num9) && !(num11 / 70f + 0.04f > num10) && !Physics.Linecast(body, val, Perches.SolidMask, (QueryTriggerInteraction)1))
						{
							num8 = num10;
							num9 = num11;
							meet = val;
						}
					}
				}
				if (num8 < 0f)
				{
					if (s_unreached.Add(s_shot))
					{
						float num12 = float.MaxValue;
						for (int j = 0; j <= 16; j++)
						{
							num12 = Mathf.Min(num12, Vector3.Distance(body, At(position, value, num2, num7 * (float)j / 16f)));
						}
						BirdheimPlugin.Log.LogInfo((object)$"guard: a shot at the player ({magnitude:0} m/s, {Vector3.Distance(position, centerPoint):0.0} m off, {num3:0.00} s) out of reach: its way passes {num12:0.0} m from the bird ({bird.State}, {bird.CurrentGoal}), reach {num:0.0} m");
					}
					continue;
				}
				float num13 = Mathf.Max(num9 / 70f, 0.15f);
				if (num8 > num13 + 0.04f)
				{
					s_trace = $"waits {num8 - num13:0.00} s to dive {num9:0.0} m";
					return true;
				}
				Dive(player, bird, s_shot, meet, num8, value);
				return true;
			}
			return false;
		}

		private static Vector3 At(Vector3 p, Vector3 v, float gravity, float t)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			return p + v * t + Vector3.down * (0.5f * gravity * t * t);
		}

		private static void Dive(Player player, Companion bird, Projectile shot, Vector3 meet, float t, Vector3 v)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			s_planned = shot;
			s_plannedRemote = (Object)(object)shot.m_nview == (Object)null || !shot.m_nview.IsValid() || !shot.m_nview.IsOwner();
			s_meetPoint = meet;
			s_meetAt = Time.time + t;
			s_damage = ((DamageTypes)(ref shot.m_damage)).GetTotalDamage();
			s_ignored.Add(shot);
			s_dives++;
			float num = Vector3.Distance(bird.Body, meet);
			bird.Dash(meet, t, v);
			if (FreezeOnDive)
			{
				FreezeOnDive = false;
				Console instance = Console.instance;
				if (instance != null)
				{
					((Terminal)instance).TryRunCommand("hb_pause 1", false, false);
				}
			}
			s_trace = $"dives {num:0.0} m to meet a shot in {t:0.00} s";
			BirdheimPlugin.Log.LogInfo((object)$"guard: {Bond.Name(player)} dives {num:0.0} m ({num / t:0} m/s) to meet a shot ({((Vector3)(ref v)).magnitude:0} m/s, {s_damage:0} damage) in {t:0.00} s");
		}

		private static void Guard(Player player, Companion bird, float level)
		{
			//IL_00ab: 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_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: 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_014d: 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_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: 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_01a0: 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_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: 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)
			if ((Object)(object)s_archer != (Object)null && !s_archer.IsDead() && IsDrawing(s_archer, player, Watch(level)))
			{
				s_guardUntil = Time.time + 1.5f;
			}
			else
			{
				Character val = Drawing(player, Watch(level));
				if ((Object)(object)val != (Object)null && ((Object)(object)s_archer == (Object)null || Time.time > s_guardUntil - 1.5f + 0.3f))
				{
					if ((Object)(object)val != (Object)(object)s_archer)
					{
						BirdheimPlugin.Log.LogInfo((object)$"guard: {Bond.Name(player)} guards against a drawing {val.m_name} {Vector3.Distance(((Component)val).transform.position, ((Component)player).transform.position):0} m off");
					}
					s_archer = val;
					s_guardUntil = Time.time + 1.5f;
				}
			}
			if ((Object)(object)s_archer == (Object)null || s_archer.IsDead() || Time.time > s_guardUntil)
			{
				s_archer = null;
				s_haveCentre = false;
				return;
			}
			Vector3 val2 = VectorMath.Flat(((Component)s_archer).transform.position - ((Component)player).transform.position);
			float magnitude = ((Vector3)(ref val2)).magnitude;
			if (!(magnitude < 2f))
			{
				val2 /= magnitude;
				Vector3 val3 = ((Component)player).transform.position + Vector3.up * Settings.GuardHeight.Value + val2 * Mathf.Min(3f, magnitude * 0.4f);
				s_centre = (s_haveCentre ? Vector3.MoveTowards(s_centre, val3, 6f * Time.deltaTime) : val3);
				s_haveCentre = true;
				bird.Guard(s_centre);
				s_trace = $"guards against a {s_archer.m_name} {magnitude:0} m off, {Vector3.Distance(bird.Body, s_centre):0.0} m from its circle's centre ({bird.Body.y - s_centre.y:+0.0;-0.0} m)";
			}
		}

		private static Character Drawing(Player player, float within)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			Character result = null;
			float within2 = within;
			foreach (Character allCharacter in Character.GetAllCharacters())
			{
				if (IsDrawing(allCharacter, player, within2))
				{
					within2 = Vector3.Distance(((Component)allCharacter).transform.position, ((Component)player).transform.position);
					result = allCharacter;
				}
			}
			return result;
		}

		private static bool IsDrawing(Character c, Player player, float within)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Invalid comparison between Unknown and I4
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Invalid comparison between Unknown and I4
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			Humanoid val = (Humanoid)(object)((c is Humanoid) ? c : null);
			if (val == null || !Companion.IsThreat(c))
			{
				return false;
			}
			Attack currentAttack = val.m_currentAttack;
			bool flag = currentAttack == null;
			if (!flag)
			{
				AttackType attackType = currentAttack.m_attackType;
				bool flag2 = (((int)attackType == 2 || (int)attackType == 5) ? true : false);
				flag = !flag2;
			}
			if (flag)
			{
				return false;
			}
			BaseAI baseAI = c.GetBaseAI();
			MonsterAI val2 = (MonsterAI)(object)((baseAI is MonsterAI) ? baseAI : null);
			if (val2 == null || (Object)(object)((BaseAI)val2).GetTargetCreature() != (Object)(object)player)
			{
				return false;
			}
			float num = Vector3.Distance(((Component)c).transform.position, ((Component)player).transform.position);
			if (num < within)
			{
				return num >= 3f;
			}
			return false;
		}

		public static void FixedUpdate()
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			Projectile val = s_planned;
			Companion local = Companion.Local;
			if (!((Object)(object)val == (Object)null) && !((Object)(object)local == (Object)null) && !((Object)(object)val.m_nview == (Object)null) && val.m_nview.IsValid() && val.m_nview.IsOwner() && !(Time.time < s_meetAt - 0.35f) && !(Time.time > s_meetAt + 0.6f))
			{
				Vector3 position = ((Component)val).transform.position;
				float num = 1.1f + ((Vector3)(ref val.m_vel)).magnitude * Time.fixedDeltaTime;
				if (Vector3.Distance(position, local.Body) <= num || (Time.time >= s_meetAt - 0.02f && Vector3.Distance(position, s_meetPoint) <= num))
				{
					ZNetScene.instance.Destroy(((Component)val).gameObject);
					Caught(position, s_damage);
				}
			}
		}

		public static bool Spends(Character target, HitData hit)
		{
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)target != (Object)(object)Player.m_localPlayer || hit == null || !hit.m_ranged)
			{
				return false;
			}
			if (s_meetAt < 0f || Time.time < s_meetAt - (s_plannedRemote ? 0.7f : 0.35f) || Time.time > s_meetAt + 0.6f)
			{
				if (Gear.Active == GearKind.Shield)
				{
					BirdheimPlugin.Log.LogInfo((object)string.Format("guard: a shot hit the player ({0:0} damage){1}", hit.GetTotalDamage(), (s_meetAt > 0f) ? $", {Time.time - s_meetAt:+0.00;-0.00} s from a planned meeting" : ", no dive for it"));
				}
				return false;
			}
			Caught(hit.m_point, hit.GetTotalDamage());
			return true;
		}

		private static void Caught(Vector3 at, float damage)
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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_0099: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			Companion local = Companion.Local;
			float level = Gear.Level;
			s_meetAt = -99f;
			s_planned = null;
			s_readyAt = Time.time + Every(level);
			float num = Cost(localPlayer, level);
			Bond.Spend(num);
			s_catches++;
			ObjectDB instance = ObjectDB.instance;
			object obj;
			if (instance == null)
			{
				obj = null;
			}
			else
			{
				GameObject itemPrefab = instance.GetItemPrefab("Birdheim_GearShield");
				obj = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null);
			}
			if (obj != null)
			{
				((ItemDrop)obj).m_itemData.m_shared.m_blockEffect.Create(at, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
			}
			if (local != null)
			{
				Destructible component = ((Component)local).GetComponent<Destructible>();
				if (component != null)
				{
					component.m_hitEffect.Create(local.Body, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
				}
			}
			BirdheimPlugin.Log.LogInfo((object)$"guard: {Bond.Name(localPlayer)} catches a shot ({damage:0} damage), costs {num:0.0} s of strength");
		}

		public static string Describe()
		{
			float level = Gear.Level;
			return $"buckler level {level:0.0}: watch {Watch(level):0} m, reach {Reach(level):0.0} m, every {Every(level):0} s, {Cost(Player.m_localPlayer, level):0.0} s of strength a catch; " + $"shots known {s_shots.Count} (made {s_made}, aimed {s_aimed}), dives {s_dives}, catches {s_catches}; ready in {Mathf.Max(0f, s_readyAt - Time.time):0.0} s; {s_trace}";
		}

		public static void Unload()
		{
			s_shots.Clear();
			s_lastAt.Clear();
			s_velocity.Clear();
			s_ignored.Clear();
			s_unreached.Clear();
			s_described.Clear();
			s_planned = null;
			s_archer = null;
			s_meetAt = -99f;
		}

		public static void ReadyNow()
		{
			s_readyAt = 0f;
		}
	}
	internal static class BandItem
	{
		[HarmonyPatch(typeof(ObjectDB), "Awake")]
		private static class ObjectDB_Awake
		{
			private static void Postfix()
			{
				Ensure();
			}
		}

		[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
		private static class ObjectDB_CopyOtherDB
		{
			private static void Postfix()
			{
				Ensure();
			}
		}

		[HarmonyPatch(typeof(ZNetScene), "Awake")]
		private static class ZNetScene_Awake
		{
			private static void Postfix()
			{
				Ensure();
			}
		}

		[HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[]
		{
			typeof(ItemData),
			typeof(int),
			typeof(bool),
			typeof(float),
			typeof(int),
			typeof(bool)
		})]
		private static class ItemData_GetTooltip
		{
			private static void Postfix(ItemData item, bool appending, ref string __result)
			{
				if (appending || !Is(item) || __result == null)
				{
					return;
				}
				int num = __result.IndexOf('\n');
				if (num < 0)
				{
					return;
				}
				Player localPlayer = Player.m_localPlayer;
				StringBuilder stringBuilder = new StringBuilder();
				Species[] all = Species.All;
				foreach (Species species in all)
				{
					if (species != Species.AshCrow || (!((Object)(object)localPlayer == (Object)null) && localPlayer.m_knownBiome.Contains(BiomeSector.GetBiomeName((Biome)32))))
					{
						stringBuilder.Append('\n').Append("<color=orange>" + Loc.L(species.Label) + "</color>: " + Loc.L(species.DietWords));
					}
				}
				__result = __result.Insert(num + 1, stringBuilder.ToString().Substring(1) + "\n");
			}
		}

		[HarmonyPatch(typeof(Humanoid), "UseItem")]
		private static class Humanoid_UseItem
		{
			private static bool Prefix(Humanoid __instance, ItemData item, bool fromInventoryGui)
			{
				if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || !Is(item))
				{
					return true;
				}
				GameObject hoverObject = __instance.GetHoverObject();
				if (!fromInventoryGui && (Object)(object)hoverObject != (Object)null && (Object)(object)hoverObject.GetComponentInParent<TameTouch>() != (Object)null)
				{
					return true;
				}
				Taming.Scatter(Player.m_localPlayer);
				return false;
			}
		}

		public const string Prefab = "Birdheim_Band";

		private const string Source = "LeatherScraps";

		private const string HolderName = "Birdheim_Items";

		private const string Station = "piece_workbench";

		private const string IconPrefix = "Birdheim.band.";

		private static GameObject s_template;

		private static Recipe s_recipe;

		private static string s_costFrom;

		private static Sprite s_icon;

		public static GameObject Template => s_template;

		public static bool Is(ItemData item)
		{
			if ((Object)(object)item?.m_dropPrefab != (Object)null)
			{
				return ((Object)item.m_dropPrefab).name == "Birdheim_Band";
			}
			return false;
		}

		public static ItemData In(Player player)
		{
			if ((Object)(object)player == (Object)null)
			{
				return null;
			}
			foreach (ItemData allItem in ((Humanoid)player).GetInventory().GetAllItems())
			{
				if (Is(allItem))
				{
					return allItem;
				}
			}
			return null;
		}

		public static void DropAt(Vector3 at)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)s_template == (Object)null))
			{
				ItemDrop.DropItem(s_template.GetComponent<ItemDrop>().m_itemData, 1, at + Vector3.up * 0.4f, Quaternion.identity);
			}
		}

		public static void Ensure()
		{
			ObjectDB instance = ObjectDB.instance;
			if ((Object)(object)instance == (Object)null || instance.m_items.Count == 0)
			{
				return;
			}
			if ((Object)(object)s_template == (Object)null)
			{
				GameObject value = instance.m_items.Find((GameObject item) => (Object)(object)item != (Object)null && ((Object)item).name == "Birdheim_Band");
				if ((Object)(object)value == (Object)null && (Object)(object)ZNetScene.instance != (Object)null)
				{
					ZNetScene.instance.m_namedPrefabs.TryGetValue(StringExtensionMethods.GetStableHashCode("Birdheim_Band"), out value);
				}
				s_template = (((Object)(object)value != (Object)null) ? value : Make(instance));
			}
			if (!((Object)(object)s_template == (Object)null))
			{
				Dress();
				Register(instance);
				AddRecipe(instance);
			}
		}

		private static GameObject Make(ObjectDB db)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			GameObject itemPrefab = db.GetItemPrefab("LeatherScraps");
			if ((Object)(object)itemPrefab == (Object)null)
			{
				BirdheimPlugin.Log.LogWarning((object)"band: no LeatherScraps to make it from");
				return null;
			}
			GameObject val = GameObject.Find("Birdheim_Items");
			if ((Object)(object)val == (Object)null)
			{
				val = new GameObject("Birdheim_Items");
				val.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)val);
			}
			GameObject obj = Object.Instantiate<GameObject>(itemPrefab, val.transform, false);
			((Object)obj).name = "Birdheim_Band";
			BirdheimPlugin.Log.LogInfo((object)"band: made from LeatherScraps");
			return obj;
		}

		private static void Dress()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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)
			ItemDrop component = s_template.GetComponent<ItemDrop>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			SharedData shared = component.m_itemData.m_shared;
			shared.m_name = Loc.Word("birdheim_band", "banditem.bird_band");
			shared.m_description = Loc.Word("birdheim_band_description", "banditem.use_it_to_lay_a_ring");
			shared.m_itemType = (ItemType)16;
			shared.m_maxStackSize = 10;
			shared.m_maxQuality = 1;
			shared.m_weight = 0.1f;
			shared.m_teleportable = true;
			shared.m_value = 0;
			component.m_itemData.m_dropPrefab = s_template;
			if ((Object)(object)s_icon == (Object)null)
			{
				Texture2D val = Sparrow.LoadTexture("icon.rgba", linear: false, "Birdheim.band.");
				if ((Object)(object)val != (Object)null)
				{
					((Texture)val).filterMode = (FilterMode)1;
					s_icon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
					((Object)s_icon).name = "Birdheim_Icon_Band";
				}
			}
			if ((Object)(object)s_icon != (Object)null)
			{
				shared.m_icons = (Sprite[])(object)new Sprite[1] { s_icon };
			}
		}

		private static void Register(ObjectDB db)
		{
			int stableHashCode = StringExtensionMethods.GetStableHashCode("Birdheim_Band");
			db.m_items.RemoveAll((GameObject item) => (Object)(object)item != (Object)null && (Object)(object)item != (Object)(object)s_template && ((Object)item).name == "Birdheim_Band");
			if (!db.m_items.Contains(s_template))
			{
				db.m_items.Add(s_template);
			}
			db.m_itemByHash[stableHashCode] = s_template;
			ZNetScene instance = ZNetScene.instance;
			if (!((Object)(object)instance == (Object)null))
			{
				if (instance.m_namedPrefabs.TryGetValue(stableHashCode, out var value) && (Object)(object)value != (Object)(object)s_template && (Object)(object)value != (Object)null)
				{
					instance.m_prefabs.Remove(value);
				}
				if (!instance.m_prefabs.Contains(s_template))
				{
					instance.m_prefabs.Add(s_template);
				}
				instance.m_namedPrefabs[stableHashCode] = s_template;
			}
		}

		private static void AddRecipe(ObjectDB db)
		{
			//IL_0161: 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_016e: 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_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Expected O, but got Unknown
			if ((Object)(object)s_recipe == (Object)null)
			{
				s_recipe = ScriptableObject.CreateInstance<Recipe>();
				((Object)s_recipe).name = "Recipe_Birdheim_Band";
				s_costFrom = null;
			}
			s_recipe.m_item = s_template.GetComponent<ItemDrop>();
			s_recipe.m_amount = 1;
			s_recipe.m_enabled = Settings.Taming.Value;
			GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("piece_workbench") : null);
			if ((Object)(object)val != (Object)null)
			{
				s_recipe.m_craftingStation = val.GetComponent<CraftingStation>();
			}
			s_recipe.m_minStationLevel = 1;
			if (s_costFrom != Settings.BandCost.Value)
			{
				List<Requirement> list = new List<Requirement>();
				string[] array = Settings.BandCost.Value.Split(new char[1] { ',' });
				for (int i = 0; i < array.Length; i++)
				{
					string[] array2 = array[i].Split(new char[1] { ':' });
					if (array2.Length == 2 && int.TryParse(array2[1].Trim(), out var result) && result > 0)
					{
						GameObject itemPrefab = db.GetItemPrefab(array2[0].Trim());
						ItemDrop val2 = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null);
						if ((Object)(object)val2 == (Object)null)
						{
							BirdheimPlugin.Log.LogWarning((object)("band cost: no item " + array2[0].Trim()));
							continue;
						}
						list.Add(new Requirement
						{
							m_resItem = val2,
							m_amount = result,
							m_amountPerLevel = 0,
							m_recover = true
						});
					}
				}
				s_recipe.m_resources = list.ToArray();
				s_costFrom = Settings.BandCost.Value;
			}
			db.m_recipes.RemoveAll((Recipe other) => (Object)(object)other != (Object)null && (Object)(object)other != (Object)(object)s_recipe && ((Object)other).name == "Recipe_Birdheim_Band");
			if (!db.m_recipes.Contains(s_recipe))
			{
				db.m_recipes.Add(s_recipe);
			}
		}

		public static void Uninstall()
		{
			if ((Object)(object)s_recipe != (Object)null)
			{
				ObjectDB.instance?.m_recipes.Remove(s_recipe);
				Object.Destroy((Object)(object)s_recipe);
			}
			s_recipe = null;
			s_template = null;
			s_icon = null;
			s_costFrom = null;
		}
	}
	internal static class BirdFlight
	{
		public enum End
		{
			Voluntary,
			Range,
			Time,
			Crash,
			Water,
			Hurt,
			Lost,
			Unloaded,
			Unknown
		}

		public static float AimYaw;

		public static float AimPitch;

		private static float s_blend;

		private static bool s_leaving;

		private static Vector3 s_camTarget;

		private static Vector3 s_camVelocity;

		private static float s_camDistance;

		private static bool s_nearClipChanged;

		private static float s_lookYaw;

		private static float s_lookPitch;

		private static float s_camPull;

		private static float s_camCrown;

		private static float s_camSpeedOut;

		private static float s_camRaise;

		private static bool s_camHemmed;

		private static float s_camFree;

		private static float s_camLowFree;

		private static float s_camLowFull;

		private static float s_fovBoost;

		private static float s_camRoll;

		private static float s_camRollVelocity;

		private static float s_zoom = 4.3f;

		private const float NearestZoom = 1.8f;

		private const float FarthestZoom = 14f;

		private static bool s_birdsEye;

		private static float s_eyeBlend;

		private const float EyeTime = 0.3f;

		private const float EyesAhead = 0.3f;

		private static Quaternion s_eyeView = Quaternion.identity;

		private const float EyeTurnTime = 0.12f;

		private const float EyeAimReach = 50f;

		private static bool s_entering;

		private static float s_glideTime = 1f;

		private const float FadeFrom = 80f;

		private static bool s_fading;

		private static float s_exploreTimer;

		private static float s_xpTimer;

		private static bool s_warnedRange;

		private static bool s_warnedTime;

		private static Vector3 s_lastPerch;

		private static bool s_handsHidden;

		private const float CallHold = 0.45f;

		private const float DoubleTap = 0.3f;

		private static float s_keyHeld = -1f;

		private static float s_tapWaiting = -1f;

		private static float s_calledAt = -99f;

		private static bool s_diveRefused;

		private const float MaxPitch = 50f;

		private const float ClimbFrom = 15f;

		private static bool s_looping;

		private static float s_pulledAt;

		private static float s_viewRoll;

		private static float s_viewRollVelocity;

		private const float LookAhead = 8f;

		public static bool Active { get; private set; }

		public static float Elapsed { get; private set; }

		public static Vector3 Origin { get; private set; }

		public static float Range { get; private set; }

		public static float UnknownReach { get; private set; }

		public static float IntoUnknown { get; private set; }

		public static float Strain { get; private set; }

		public static End LastEnd { get; private set; }

		public static bool FreeLook { get; private set; }

		public static bool EyesFollow
		{
			get
			{
				if (s_birdsEye && s_eyeBlend > 0.5f)
				{
					return Settings.EyesFollowBird.Value;
				}
				return false;
			}
		}

		public static bool Fading
		{
			get
			{
				if (s_fading && s_blend > 0f)
				{
					return s_blend < 1f;
				}
				return false;
			}
		}

		public static float Blend => s_blend;

		public static bool CameraOnBird
		{
			get
			{
				if (!Active)
				{
					return s_blend > 0f;
				}
				return true;
			}
		}

		public static float Effort { get; private set; }

		public static bool Looping => s_looping;

		private static float ViewPitch => Mathf.Clamp(AimPitch + s_lookPitch, Mathf.Min(-80f, AimPitch), Mathf.Max(70f, AimPitch));

		private static float GlideTime(float distance)
		{
			return Mathf.Clamp(0.8f + distance / 22f, 0.9f, 2.2f);
		}

		public static string CannotStart(Player player)
		{
			//IL_00c5: 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_01ae: 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_01d6: Unknown result type (might be due to invalid IL or missing references)
			Companion local = Companion.Local;
			string text = Bond.Name(player);
			if ((Object)(object)player == (Object)null || ((Character)player).IsDead() || ((Character)player).IsTeleporting() || ((Character)player).InCutscene() || player.IsSleeping())
			{
				return "";
			}
			if (!Settings.Flying.Value)
			{
				return Loc.L("birdflight.flying_is_off");
			}
			if (!Bond.HasBird(player))
			{
				string text2 = Flock.NoneAlong(player);
				if (text2 == null)
				{
					if (!Settings.Taming.Value)
					{
						return Loc.L("birdflight.you_have_no_bird");
					}
					text2 = Loc.L("birdflight.you_have_no_bird_make_a");
				}
				return text2;
			}
			if ((Object)(object)local == (Object)null)
			{
				if (!Bond.StayingAt(player, out var _))
				{
					return Loc.L("common.is_not_here_yet", text);
				}
				return Loc.L("birdflight.stays_where_you_left_it_hold", text, Settings.FlyKey.Value);
			}
			if (local.GoingHome)
			{
				return Loc.L("common.is_on_its_way_into_the", text);
			}
			if (((Character)player).InInterior())
			{
				return Loc.L("common.waits_for_you_outside", text);
			}
			if (Bond.Tired(player))
			{
				return Loc.L("birdflight.is_too_tired_to_fly_s", text, Mathf.CeilToInt(Bond.TimeToFly(player)));
			}
			if ((Object)(object)player.GetControlledShip() != (Object)null)
			{
				return Loc.L("birdflight.not_while_steering");
			}
			if (((Character)player).IsRiding())
			{
				return Loc.L("birdflight.not_while_riding");
			}
			if (((Character)player).IsSwimming() || (((Character)player).InWater() && !((Character)player).IsOnGround()))
			{
				return Loc.L("birdflight.not_while_swimming");
			}
			if (((Character)player).InPlaceMode())
			{
				return "";
			}
			if (Vector3.Distance(((Component)local).transform.position, ((Component)player).transform.position) > StartReach(player))
			{
				return Loc.L("birdflight.is_too_far_away_hold_to", text, Settings.FlyKey.Value);
			}
			if (KnownLand.Beyond(local.Body, Bond.UnknownReach(player) + 20f) > Bond.UnknownReach(player))
			{
				return Loc.L("birdflight.unknown_land");
			}
			return null;
		}

		public static float StartReach(Player player)
		{
			return Bond.Range(player) * 0.5f;
		}

		internal static void FlyKey(Player player)
		{
			Start(player);
		}

		internal static void CallKey(Player player)
		{
			if (!Bond.HasBird(player))
			{
				string text = Flock.NoneAlong(player);
				if (text != null)
				{
					Bond.Tell(player, text);
				}
			}
			else if (((Character)player).InInterior())
			{
				Bond.Tell(player, Loc.L("common.waits_for_you_outside", Bond.Name(player)));
			}
			else
			{
				Bond.Recall(player);
			}
		}

		private static void UpdateFlyKey(Player player, float dt)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (UiOpen())
			{
				s_keyHeld = (s_tapWaiting = -1f);
			}
			else if (Pressed(Settings.LeaveKey.Value))
			{
				if (Active)
				{
					LeaveHere(player);
					s_keyHeld = (s_tapWaiting = -1f);
				}
			}
			else if (FlyKeyDown())
			{
				if (Active)
				{
					Stop(End.Voluntary);
					s_keyHeld = (s_tapWaiting = -1f);
				}
				else if (s_tapWaiting >= 0f)
				{
					s_keyHeld = (s_tapWaiting = -1f);
					ShoulderKey(player);
				}
				else
				{
					s_keyHeld = 0f;
				}
			}
			else if (s_tapWaiting >= 0f)
			{
				s_tapWaiting += dt;
				if (!(s_tapWaiting < 0.3f))
				{
					s_tapWaiting = -1f;
					if (!s_leaving || s_blend < 0.5f)
					{
						FlyKey(player);
					}
				}
			}
			else
			{
				if (s_keyHeld < 0f)
				{
					return;
				}
				s_keyHeld += dt;
				if (!FlyKeyHeld() || !(s_keyHeld < 0.45f))
				{
					if (s_keyHeld >= 0.45f)
					{
						s_keyHeld = -1f;
						CallKey(player);
					}
					else
					{
						s_keyHeld = -1f;
						s_tapWaiting = 0f;
					}
				}
			}
		}

		internal static void LeaveHere(Player player)
		{
			if (Active)
			{
				Bond.StayHere(player);
				Stop(End.Voluntary);
			}
		}

		internal static void ShoulderKey(Player player)
		{
			Bond.ToggleShoulder(player);
		}

		public static bool Start(Player player)
		{
			//IL_00e3: 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_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: 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_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			string text = CannotStart(player);
			if (text != null)
			{
				if (text.Length > 0)
				{
					Bond.Tell(player, text);
				}
				return false;
			}
			foreach (Vagon instance in Vagon.m_instances)
			{
				if (!((Object)(object)instance == (Object)null) && instance.IsAttached((Character)(object)player))
				{
					instance.Detach();
					Bond.Tell(player, Loc.L("birdflight.you_let_go_of_the_cart"));
				}
			}
			Companion local = Companion.Local;
			if (local.State == Companion.Mode.Perched && local.Target.Valid)
			{
				local.State = Companion.Mode.ControlledPerched;
			}
			else
			{
				Companion.Mode state = local.State;
				if ((state == Companion.Mode.Perched || state == Companion.Mode.Shoulder) ? true : false)
				{
					local.TakeOff(Companion.Goal.Perch);
				}
				local.State = Companion.Mode.Controlled;
			}
			Active = true;
			s_leaving = false;
			Elapsed = 0f;
			Origin = ((Component)player).transform.position;
			Range = Bond.Range(player);
			UnknownReach = Bond.UnknownReach(player);
			IntoUnknown = 0f;
			s_warnedRange = (s_warnedTime = false);
			s_exploreTimer = 0f;
			s_xpTimer = 0f;
			s_lastPerch = ((Component)local).transform.position;
			Transform obj = (((Object)(object)GameCamera.instance != (Object)null) ? ((Component)GameCamera.instance).transform : ((Character)player).m_eye);
			Vector3 forward = obj.forward;
			AimYaw = Mathf.Atan2(forward.x, forward.z) * 57.29578f;
			AimPitch = Mathf.Clamp(Mathf.Asin(Mathf.Clamp(forward.y, -1f, 1f)) * 57.29578f, -30f, 30f);
			s_camTarget = local.Body;
			s_camVelocity = Vector3.zero;
			s_camDistance = 0f;
			s_lookYaw = (s_lookPitch = 0f);
			FreeLook = false;
			s_diveRefused = false;
			s_camPull = 0f;
			s_camCrown = 0f;
			s_camSpeedOut = 0f;
			s_camRaise = 0f;
			s_camHemmed = false;
			s_eyeBlend = (s_birdsEye ? 1f : 0f);
			s_fovBoost = 0f;
			s_camRoll = (s_camRollVelocity = 0f);
			s_looping = false;
			s_viewRoll = (s_viewRollVelocity = 0f);
			s_pulledAt = 0f;
			s_entering = true;
			float num = Vector3.Distance(obj.position, local.Body);
			s_fading = num >= 80f;
			s_glideTime = (s_fading ? 0.9f : GlideTime(num));
			if (!((Character)player).IsAttached())
			{
				((Character)player).StopEmote();
				((Character)player).SetCrouch(false);
			}
			s_handsHidden = ((Humanoid)player).HideHandItems(false, false);
			local.Caw();
			FlightHud.Pulse(0.8f);
			return true;
		}

		public static void Stop(End why)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			if (Active)
			{
				BirdheimPlugin.Log.LogInfo((object)$"flight ended: {why} after {Elapsed:F1} s");
			}
			if (!Active)
			{
				return;
			}
			Active = false;
			LastEnd = why;
			s_leaving = true;
			s_entering = false;
			FlightHud.Pulse((why == End.Voluntary) ? 0.3f : 0.6f);
			Player localPlayer = Player.m_localPlayer;
			Companion local = Companion.Local;
			if ((Object)(object)local != (Object)null && (Object)(object)localPlayer != (Object)null)
			{
				float num = Vector3.Distance(local.Body, ((Character)localPlayer).m_eye.position);
				s_fading = num >= 80f;
				s_glideTime = (s_fading ? 0.9f : GlideTime(num));
			}
			string text = Bond.Name(localPlayer);
			if ((Object)(object)local != (Object)null)
			{
				local.Flight.LiftScale = 1f;
				Companion.Goal goal = ((!local.Staying) ? (local.WantsShoulder ? Companion.Goal.Shoulder : Companion.Goal.Return) : Companion.Goal.Perch);
				if (local.State == Companion.Mode.ControlledPerched)
				{
					local.State = Companion.Mode.Perched;
					if (!local.Staying)
					{
						local.TakeOff(goal);
					}
				}
				else
				{
					local.State = Companion.Mode.Flying;
					local.CurrentGoal = goal;
					if (!local.Staying || !local.Target.Valid)
					{
						local.Target = default(Perch);
					}
					if (why == End.Crash)
					{
						local.Flight.Velocity = Vector3.up * 2f + Random.insideUnitSphere * 2f;
					}
				}
			}
			if ((Object)(object)localPlayer != (Object)null)
			{
				if (s_handsHidden && !((Character)localPlayer).IsDead())
				{
					((Humanoid)localPlayer).ShowHandItems(false, true);
				}
				s_handsHidden = false;
				if (why == End.Crash)
				{
					Bond.SetStrength(0f);
				}
				string text2;
				switch (why)
				{
				case End.Range:
				case End.Unloaded:
					text2 = Loc.L("birdflight.the_bond_breaks_too_far");
					break;
				case End.Unknown:
					text2 = Loc.L("birdflight.the_bond_breaks_unknown_land");
					break;
				case End.Time:
					text2 = Loc.L("birdflight.is_spent", text);
					break;
				case End.Crash:
					text2 = Loc.L("birdflight.tumbles_out_of_the_air_spent", text);
					break;
				case End.Water:
					text2 = Loc.L("birdflight.splashes_into_the_water", text);
					break;
				case End.Hurt:
					text2 = Loc.L("birdflight.you_are_torn_back_into_your");
					break;
				case End.Lost:
					text2 = Loc.L("birdflight.you_lose_sight_of", text);
					break;
				default:
					text2 = "";
					break;
				}
				string text3 = text2;
				if (text3.Length > 0)
				{
					Bond.Tell(localPlayer, text3);
				}
			}
		}

		public static void Update(float dt)
		{
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: 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_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: 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_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: 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_0492: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				Active = false;
				s_blend = 0f;
				return;
			}
			if (s_leaving)
			{
				s_blend = Mathf.Max(0f, s_blend - dt / s_glideTime);
				if (s_blend <= 0f)
				{
					s_leaving = false;
				}
			}
			if (s_blend > 0f && s_blend < 1f && (s_fading || s_leaving) && (Object)(object)EnvMan.instance != (Object)null)
			{
				EnvMan.instance.ForceInstantEnvironmentSwitch();
			}
			UpdateFlyKey(localPlayer, dt);
			if (!Active || dt <= 0f)
			{
				return;
			}
			if (!Settings.Flying.Value)
			{
				Stop(End.Voluntary);
				return;
			}
			s_blend = Mathf.Min(1f, s_blend + dt / s_glideTime);
			Companion local = Companion.Local;
			if ((Object)(object)local == (Object)null || !local.NView.IsValid())
			{
				Stop(End.Lost);
				return;
			}
			if (((Character)localPlayer).IsDead() || ((Character)localPlayer).IsTeleporting())
			{
				Stop(End.Hurt);
				return;
			}
			Elapsed += dt;
			FlightControls controls = ReadControls(dt, local);
			Vector3 body = local.Body;
			float num = Companion.HeightAboveGround(body);
			float num2 = (local.Kind ?? Species.Crow).Ceiling * Settings.HeightCeilingScale.Value;
			local.Flight.LiftScale = Mathf.Lerp(0.25f, 1f, Mathf.Clamp01((num2 - num) / 12f));
			if (local.State == Companion.Mode.ControlledPerched)
			{
				Effort = 0f;
				UpdatePerched(dt, local, controls);
			}
			else
			{
				local.StepPhysics(dt, controls, Companion.Wind(body));
				bool flag = !controls.Dive && (local.Flight.Stalled || local.Flight.Speed < 5f);
				bool flapping = !controls.Dive && (controls.Flap || controls.Burst || local.Flight.StrongBeat || local.Flight.Pushing || flag);
				local.SetFlapping(flapping);
				Effort = EffortOf(local.Flight, controls, flapping);
				Bond.Spend(dt * Effort);
				local.SetFold(controls.Dive);
				Vector3 body2 = local.Body;
				if (body2.y < Floating.GetLiquidLevel(body2, 1f, (LiquidType)10) + 0.05f || (local.LastContact.Hit && local.LastContact.Point.y < Floating.GetLiquidLevel(local.LastContact.Point, 1f, (LiquidType)10) + 0.1f))
				{
					local.Sounds.Water();
					Stop(End.Water);
					return;
				}
				if (HandleContact(localPlayer, local))
				{
					return;
				}
			}
			body = local.Body;
			Origin = ((Component)localPlayer).transform.position;
			float num3 = Vector3.Distance(body, Origin);
			if (num3 > Range)
			{
				Stop(End.Range);
				return;
			}
			IntoUnknown = KnownLand.Beyond(body, UnknownReach + 20f);
			if (IntoUnknown > UnknownReach)
			{
				Stop(End.Unknown);
				return;
			}
			if (Bond.Strength <= 0f)
			{
				Stop(End.Time);
				return;
			}
			if ((Object)(object)ZoneSystem.instance != (Object)null && !ZoneSystem.instance.IsZoneLoaded(body))
			{
				Stop(End.Unloaded);
				return;
			}
			float num4 = Mathf.Min(0.85f * UnknownReach, UnknownReach - 15f);
			float num5 = Mathf.Min(0.65f * UnknownReach, UnknownReach - 25f);
			Strain = Mathf.Max(Mathf.Max(Mathf.InverseLerp(0.65f, 1f, num3 / Range), Mathf.InverseLerp(num5, UnknownReach, IntoUnknown)), Mathf.InverseLerp(6f, 0f, Bond.Strength));
			if (s_warnedRange && num3 < Range * 0.7f && IntoUnknown < num4 * 0.7f)
			{
				s_warnedRange = false;
			}
			if (!s_warnedRange && (num3 > Range * 0.85f || IntoUnknown > num4))
			{
				s_warnedRange = true;
				Bond.Tell(localPlayer, Loc.L("birdflight.the_bond_thins"));
			}
			if (!s_warnedTime && Bond.Strength < 5f && local.State != Companion.Mode.ControlledPerched)
			{
				s_warnedTime = true;
				Bond.Tell(localPlayer, Loc.L("birdflight.is_tiring", Bond.Name(localPlayer)));
			}
			if (Bond.Strength > 8f)
			{
				s_warnedTime = false;
			}
			Explore(dt, body);
			if (local.State != Companion.Mode.ControlledPerched)
			{
				s_xpTimer += dt;
			}
			if (s_xpTimer >= 1f)
			{
				s_xpTimer -= 1f;
				Birdsight.Raise(localPlayer, 0.25f);
			}
		}

		private static void UpdatePerched(float dt, Companion bird, FlightControls controls)
		{
			bird.SetFlapping(flap: false);
			if (controls.Flap && controls.Dive && !controls.Burst)
			{
				bird.HopForward(AimYaw);
			}
			else if (controls.Flap || controls.Burst)
			{
				bird.State = Companion.Mode.Perched;
				bird.TakeOff(Companion.Goal.Perch);
				bird.State = Companion.Mode.Controlled;
			}
			else
			{
				bird.LookAround(AimYaw);
			}
		}

		private static bool HandleContact(Player player, Companion bird)
		{
			//IL_00b5: 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_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: 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_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: 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)
			Companion.Contact lastContact = bird.LastContact;
			if (!lastContact.Hit)
			{
				return false;
			}
			if (lastContact.Into > 7.5f)
			{
				ManualLogSource log = BirdheimPlugin.Log;
				object[] array = new object[5];
				Collider collider = lastContact.Collider;
				array[0] = ((collider != null) ? ((Object)collider).name : null);
				array[1] = (((Object)(object)lastContact.Collider != (Object)null) ? LayerMask.LayerToName(((Component)lastContact.Collider).gameObject.layer) : "-");
				array[2] = lastContact.Into;
				array[3] = lastContact.Normal;
				array[4] = bird.Flight.Speed;
				log.LogInfo((object)string.Format("crash into {0} (layer {1}) at {2:F1} m/s, normal {3}, speed {4:F1}", array));
				Stop(End.Crash);
				return true;
			}
			bool num = lastContact.Normal.y > 0.7f;
			Ship val = Perches.ShipOf(lastContact.Collider);
			if (num && lastContact.Speed < 6f && (Object)(object)lastContact.Collider != (Object)null && ((Object)(object)lastContact.Collider.attachedRigidbody == (Object)null || (Object)(object)val != (Object)null))
			{
				Perch perch = new Perch
				{
					Point = lastContact.Point,
					Normal = lastContact.Normal,
					On = lastContact.Collider,
					Kind = "landed",
					Valid = true
				};
				perch.Board(val);
				bird.Sit(perch, bird.Flight.Velocity);
				if (Vector3.Distance(lastContact.Point, s_lastPerch) > 6f)
				{
					s_lastPerch = lastContact.Point;
					Birdsight.Raise(player, 1.5f);
				}
			}
			return false;
		}

		private static bool FlyKeyDown()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return Pressed(Settings.FlyKey.Value);
		}

		private static float EffortOf(FlightModel flight, FlightControls controls, bool flapping)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			if (!flapping)
			{
				return Settings.EffortGlide.Value;
			}
			Vector3 velocity = flight.Velocity;
			float num = ((((Vector3)(ref velocity)).magnitude > 2f) ? Mathf.Max(0f, velocity.y / ((Vector3)(ref velocity)).magnitude) : 0.5f);
			float num2 = Settings.EffortFlap.Value + Settings.EffortClimb.Value * num;
			if (flight.Pushing)
			{
				num2 += Settings.EffortFlap.Value * (controls.Burst ? 1f : Mathf.Max(controls.Climb, 0.3f));
			}
			return num2 * Mathf.Max(1f, flight.Load);
		}

		internal static bool Pressed(KeyboardShortcut shortcut)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if ((int)((KeyboardShortcut)(ref shortcut)).MainKey == 0 || !ZInput.GetKeyDown(((KeyboardShortcut)(ref shortcut)).MainKey, true))
			{
				return false;
			}
			foreach (KeyCode modifier in ((KeyboardShortcut)(ref shortcut)).Modifiers)
			{
				if (!ZInput.GetKey(modifier, true))
				{
					return false;
				}
			}
			return true;
		}

		private static bool FlyKeyHeld()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut value = Settings.FlyKey.Value;
			if ((int)((KeyboardShortcut)(ref value)).MainKey != 0)
			{
				return ZInput.GetKey(((KeyboardShortcut)(ref value)).MainKey, true);
			}
			return false;
		}

		public static bool UiOpen()
		{
			if (!Console.IsVisible() && (!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus()) && !Menu.IsVisible() && !InventoryGui.IsVisible() && !Minimap.IsOpen() && !TextInput.IsVisible() && !StoreGui.IsVisible())
			{
				if ((Object)(object)TextViewer.instance != (Object)null)
				{
					return TextViewer.instance.IsVisible();
				}
				return false;
			}
			return true;
		}

		public static void Zoom(float by)
		{
			if (by == 0f)
			{
				return;
			}
			if (s_birdsEye)
			{
				if (by > 0f)
				{
					s_birdsEye = false;
				}
			}
			else if (by < 0f && s_zoom <= 1.801f)
			{
				s_birdsEye = true;
			}
			else
			{
				s_zoom = Mathf.Clamp(s_zoom + by, 1.8f, 14f);
			}
		}

		private static FlightControls ReadControls(float dt, Companion bird)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00cb: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_047f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0484: Unknown result type (might be due to invalid IL or missing references)
			//IL_0489: Unknown result type (might be due to invalid IL or missing references)
			//IL_048e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04db: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			FlightControls result = default(FlightControls);
			float num = 0f;
			if (!UiOpen())
			{
				Vector2 val = Vector2.zero;
				if (ZInput.IsMouseActive())
				{
					float num2 = (ZInput.IsGamepadMouseActive() ? PlayerController.m_switchMouseSens : PlayerController.m_mouseSens) * Settings.MouseSensitivity.Value;
					val = ZInput.GetMouseDelta() * num2;
					if (PlayerController.m_invertMouse)
					{
						val.y = 0f - val.y;
					}
				}
				else if (ZInput.IsGamepadActive())
				{
					val = new Vector2(ZInput.GetJoyRightStickX(), 0f - ZInput.GetJoyRightStickY()) * (110f * dt * PlayerController.m_gamepadSens);
					if (PlayerController.m_invertCameraY)
					{
						val.y = 0f - val.y;
					}
				}
				val.y *= Settings.PitchSensitivity.Value;
				if (Settings.InvertMouseY.Value)
				{
					val.y = 0f - val.y;
				}
				FreeLook = ZInput.GetButton("Block") || ZInput.GetButton("JoyBlock");
				float num3 = (ZInput.GetButton("Right") ? 1f : 0f) - (ZInput.GetButton("Left") ? 1f : 0f) + ZInput.GetJoyLeftStickX();
				if (Looping)
				{
					val.x *= Mathf.Clamp((ViewRotation() * Vector3.up).y * 4f, -1f, 1f);
				}
				float num4 = Mathf.Clamp(num3, -1f, 1f) * 75f * dt;
				AimYaw += num4;
				if (FreeLook)
				{
					s_lookYaw = Mathf.DeltaAngle(0f, s_lookYaw + val.x - num4);
					s_lookPitch = Mathf.Clamp(s_lookPitch + val.y, -70f, 60f);
				}
				else
				{
					AimYaw += val.x;
					num = val.y;
				}
				GameCamera instance = GameCamera.instance;
				if ((Object)(object)instance != (Object)null)
				{
					float num5 = FirstPersonMods.ZoomSens(instance);
					float num6 = (0f - Mathf.Clamp(ZInput.GetMouseScrollWheel(), -0.05f, 0.05f)) * num5;
					if (ZInput.GetButton("JoyAltKeys"))
					{
						if (ZInput.GetButton("JoyCamZoomIn"))
						{
							num6 -= num5 * dt;
						}
						else if (ZInput.GetButton("JoyCamZoomOut"))
						{
							num6 += num5 * dt;
						}
					}
					Zoom(num6);
				}
				float joyLeftStickY = ZInput.GetJoyLeftStickY();
				result.Flap = ZInput.GetButton("Forward") || joyLeftStickY > 0.5f;
				result.Flare = ZInput.GetButton("Backward") || joyLeftStickY < -0.5f;
				result.Dive = ZInput.GetButton("Run") || ZInput.GetButton("JoyRun");
				if (ZInput.GetButtonDown("Attack") || ZInput.GetButtonDown("JoyAttack"))
				{
					CallOut(bird);
				}
				if (Pressed(Settings.PingKey.Value) && (Object)(object)GameCamera.instance != (Object)null)
				{
					FlightPing.Ping(GameCamera.instance.m_camera);
				}
				if ((ZInput.GetButtonDown("Use") || ZInput.GetButtonDown("JoyUse")) && !Hud.InRadial())
				{
					Cargo.UseKey(bird);
				}
			}
			if (Looping && Settings.GroundAssist.Value && GroundAhead(bird))
			{
				num = Mathf.Max(num, 180f * dt);
			}
			if (num > 0.01f)
			{
				s_pulledAt = Time.time;
			}
			_ = AimPitch;
			AimPitch = LoopAim.Pitch(AimPitch, num, bird.Flight.Course, AimYaw, ref s_looping);
			AimYaw = Mathf.Repeat(AimYaw, 360f);
			Vector3 val2 = s_eyeView * Vector3.forward;
			if (EyesFollow && !Looping && !FreeLook && Mathf.Abs(val2.y) < 0.85f)
			{
				float num7 = Mathf.Atan2(val2.x, val2.z) * 57.29578f;
				float num8 = Mathf.DeltaAngle(num7, AimYaw);
				if (Mathf.Abs(num8) > 50f)
				{
					AimYaw = Mathf.Repeat(num7 + Mathf.Sign(num8) * 50f, 360f);
				}
			}
			RightTheView(bird, dt);
			if (!FreeLook)
			{
				s_lookYaw = Mathf.MoveTowards(s_lookYaw, 0f, dt * 240f);
				s_lookPitch = Mathf.MoveTowards(s_lookPitch, 0f, dt * 240f);
			}
			result.Aim = AimRotation() * Vector3.forward;
			if (Looping)
			{
				result.LoopAxis = LoopAim.Axis(AimYaw);
			}
			if (result.Flap)
			{
				result.Climb = ClimbFor(AimPitch);
			}
			if (Settings.GroundAssist.Value && !Looping)
			{
				result.Aim = KeepOffTheGround(bird, result.Aim, result.Flare);
			}
			if (!result.Dive)
			{
				s_diveRefused = false;
			}
			else if (Settings.GroundAssist.Value && (s_diveRefused || GroundAhead(bird)))
			{
				if (!s_diveRefused)
				{
					Bond.Tell(Player.m_localPlayer, Loc.L("birdflight.opens_its_wings_the_ground", Bond.Name(Player.m_localPlayer)));
				}
				s_diveRefused = true;
				result.Dive = false;
			}
			return result;
		}

		private static Quaternion EyeView(Companion bird, float step)
		{
			//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_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: 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)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: 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_010e: 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_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: 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_015c: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = AimRotation() * Vector3.forward;
			Vector3 course = bird.Flight.Course;
			float magnitude = ((Vector3)(ref course)).magnitude;
			Vector3 val2 = ((magnitude > 0.1f) ? Vector3.Slerp(val, course / magnitude, Mathf.InverseLerp(2f, 6f, magnitude)) : val);
			if (((Vector3)(ref val2)).sqrMagnitude < 0.0001f)
			{
				val2 = val;
			}
			((Vector3)(ref val2)).Normalize();
			Vector3 val3 = Vector3.ProjectOnPlane(bird.Flight.Up, val2);
			Vector3 val4 = Vector3.ProjectOnPlane(Vector3.up, val2);
			float num = Mathf.Lerp(0.5f + 0.5f * Settings.CameraMotion.Value, 1f, Mathf.InverseLerp(0.75f, 0.95f, Mathf.Abs(val2.y)));
			Vector3 val5 = ((((Vector3)(ref val3)).sqrMagnitude < 0.0001f) ? val4 : ((!(((Vector3)(ref val4)).sqrMagnitude < 0.0001f)) ? Vector3.Slerp(((Vector3)(ref val4)).normalized, ((Vector3)(ref val3)).normalized, num) : val3));
			Quaternion val6 = Quaternion.LookRotation(val2, (((Vector3)(ref val5)).sqrMagnitude > 0.0001f) ? val5 : Vector3.up);
			s_eyeView = Quaternion.Slerp(s_eyeView, val6, 1f - Mathf.Exp((0f - step) / 0.12f));
			return s_eyeView * Quaternion.Euler(0f - s_lookPitch, s_lookYaw, 0f);
		}

		internal static void CallOut(Companion bird)
		{
			if (!(Time.time - s_calledAt < 0.8f))
			{
				s_calledAt = Time.time;
				bird.Caw();
			}
		}

		private static void RightTheView(Companion bird, float dt)
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			Vector3 towards;
			if (s_looping && Mathf.Abs(AimPitch) >= 140f && !FreeLook && Time.time - s_pulledAt > 0.6f)
			{
				AimPitch = Mathf.Repeat(180f - AimPitch + 180f, 360f) - 180f;
				AimYaw = Mathf.Repeat(AimYaw + 180f, 360f);
				Vector3 course = bird.Flight.Course;
				towards = ((((Vector3)(ref course)).sqrMagnitude > 0.01f) ? Vector3.Cross(((Vector3)(ref course)).normalized, bird.Flight.Up) : Vector3.zero);
				s_viewRoll = ((Towards(180f) >= Towards(-180f)) ? 180f : (-180f));
				s_viewRollVelocity = 0f;
			}
			s_viewRoll = Mathf.SmoothDamp(s_viewRoll, 0f, ref s_viewRollVelocity, 0.22f, float.PositiveInfinity, Mathf.Max(dt, 0.0001f));
			float Towards(float roll)
			{
				//IL_0012: 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_0022: Unknown result type (might be due to invalid IL or missing references)
				return Vector3.Dot(Quaternion.Euler(0f - AimPitch, AimYaw, roll * 0.9f) * Vector3.up, towards);
			}
		}

		public static float ClimbFor(float pitch)
		{
			return Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(15f, 50f, pitch));
		}

		public static Quaternion AimRotation()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			return Quaternion.Euler(0f - AimPitch, AimYaw, 0f);
		}

		public static Quaternion ViewRotation()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			return Quaternion.Euler(0f - ViewPitch, AimYaw + s_lookYaw, s_viewRoll);
		}

		private static float ViewUpWeight()
		{
			float viewPitch = ViewPitch;
			float num = Mathf.Max(Mathf.InverseLerp(50f, 80f, viewPitch), Mathf.InverseLerp(-60f, -85f, viewPitch));
			return Mathf.Max(Mathf.SmoothStep(0f, 1f, num), Mathf.Clamp01(Mathf.Abs(s_viewRoll) / 30f));
		}

		private static bool GroundAhead(Companion bird)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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)
			Vector3 velocity = bird.Flight.Velocity;
			float magnitude = ((Vector3)(ref velocity)).magnitude;
			if (magnitude < 8f || velocity.y > 0f)
			{
				return false;
			}
			float num = PullOutRoom(magnitude);
			Vector3 body = bird.Body;
			Vector3 val = body + velocity / magnitude * num;
			if (Floating.GetLiquidLevel(val, 1f, (LiquidType)10) > val.y)
			{
				return true;
			}
			RaycastHit val2 = default(RaycastHit);
			if (Physics.SphereCast(body, 0.3f, velocity / magnitude, ref val2, num, Perches.SolidMask, (QueryTriggerInteraction)1))
			{
				return ((RaycastHit)(ref val2)).normal.y > 0.5f;
			}
			return false;
		}

		private static Vector3 KeepOffTheGround(Companion bird, Vector3 aim, bool braking)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_006e: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: 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_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: 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_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: 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_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: 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_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			Vector3 velocity = bird.Flight.Velocity;
			float magnitude = ((Vector3)(ref velocity)).magnitude;
			if (braking || magnitude < 7f || aim.y > 0.05f)
			{
				return aim;
			}
			Vector3 val = velocity / magnitude;
			Vector3 val2 = ((val.y < aim.y) ? val : aim);
			float num = Mathf.Max(magnitude * 1.2f, PullOutRoom(magnitude) * 1.4f);
			RaycastHit val3 = default(RaycastHit);
			if (!Physics.SphereCast(bird.Body, 0.3f, val2, ref val3, num, Perches.SolidMask, (QueryTriggerInteraction)1) || ((RaycastHit)(ref val3)).normal.y < 0.5f)
			{
				return aim;
			}
			float num2 = 0f - Vector3.Dot(val2, ((RaycastHit)(ref val3)).normal);
			if (num2 < 0.02f)
			{
				return aim;
			}
			float num3 = ((RaycastHit)(ref val3)).distance * num2;
			float num4 = Mathf.Clamp01(0f - Vector3.Dot(val, ((RaycastHit)(ref val3)).normal));
			float num5 = magnitude * magnitude / 25f * (1f - Mathf.Sqrt(1f - num4 * num4)) + magnitude * 0.08f + 0.7f;
			float num6 = Mathf.Clamp01((2f * num5 + 3f - num3) / (num5 + 3f));
			if (num6 <= 0f)
			{
				return aim;
			}
			Vector3 val4 = Vector3.ProjectOnPlane(val2, ((RaycastHit)(ref val3)).normal);
			Vector3 normalized = ((Vector3)(ref val4)).normalized;
			val4 = normalized + ((RaycastHit)(ref val3)).normal * 0.15f;
			val4 = Vector3.Slerp(aim, ((Vector3)(ref val4)).normalized, num6);
			Vector3 normalized2 = ((Vector3)(ref val4)).normalized;
			if (!(normalized2.y < aim.y))
			{
				return normalized2;
			}
			return aim;
		}

		private static float PullOutRoom(float speed)
		{
			return speed * speed / 25f + speed * 0.3f + 4f;
		}

		private static void Explore(float dt, Vector3 at)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			s_exploreTimer -= dt;
			if (s_exploreTimer > 0f || (Object)(object)Minimap.instance == (Object)null)
			{
				return;
			}
			s_exploreTimer = 0.5f;
			Minimap instance = Minimap.instance;
			int num = (int)Mathf.Ceil(instance.m_exploreRadius / instance.m_pixelSize);
			int num2 = default(int);
			int num3 = default(int);
			instance.WorldToPixel(at, ref num2, ref num3);
			int num4 = 0;
			for (int i = num3 - num; i <= num3 + num; i++)
			{
				if (i < 0 || i >= instance.m_textureSize)
				{
					continue;
				}
				for (int j = num2 - num; j <= num2 + num; j++)
				{
					if (j >= 0 && j < instance.m_textureSize && (j - num2) * (j - num2) + (i - num3) * (i - num3) <= num * num && instance.Explore(j, i))
					{
						num4++;
						KnownLand.Flown(i * instance.m_textureSize + j);
					}
				}
			}
			if (num4 > 0)
			{
				instance.m_fogTexture.Apply();
				float num5 = (float)num4 * instance.m_pixelSize * instance.m_pixelSize / 10000f;
				Birdsight.Raise(Player.m_localPlayer, num5 * 0.25f);
			}
		}

		private static float FreeDistance(Vector3 from, Vector3 to, float size)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = to - from;
			RaycastHit val2 = default(RaycastHit);
			if (!Physics.SphereCast(from, 0.2f * size, ((Vector3)(ref val)).normalized, ref val2, ((Vector3)(ref val)).magnitude, Perches.SolidMask, (QueryTriggerInteraction)1))
			{
				return ((Vector3)(ref val)).magnitude;
			}
			return Mathf.Max(0f, ((RaycastHit)(ref val2)).distance - 0.05f);
		}

		public static string DescribeCamera()
		{
			return $"raise={s_camRaise:F3} hemmed={s_camHemmed} pull={s_camPull:F3} free={s_camFree:F3} low line {s_camLowFree:F3} clear of {s_camLowFull:F3} " + $"distance={s_camDistance:F3} crown={s_camCrown:F2} zoom={s_zoom:F2} eyes={s_birdsEye} eyeBlend={s_eyeBlend:F2} blend={s_blend:F2}";
		}

		public static void ApplyCamera(GameCamera gameCamera, float dt)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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_00b1: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: 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_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_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: 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_01c3: 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_01ca: 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_01d9: 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_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: 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_01fa: 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_0216: 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_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: 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_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: 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_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: 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_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0435: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: 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_0458: Unknown result type (might be due to invalid IL or missing references)
			//IL_045d: Unknown result type (might be due to invalid IL or missing references)
			//IL_045f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0461: Unknown result type (might be due to invalid IL or missing references)
			//IL_0465: Unknown result type (might be due to invalid IL or missing references)
			//IL_046a: Unknown result type (might be due to invalid IL or missing references)
			//IL_046c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0471: 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_047c: Unknown result type (might be due to invalid IL or missing references)
			//IL_047e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0485: Unknown result type (might be due to invalid IL or missing references)
			//IL_048a: Unknown result type (might be due to invalid IL or missing references)
			//IL_049c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_04af: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0572: Unknown result type (might be due to invalid IL or missing references)
			//IL_059d: Unknown result type (might be due to invalid IL or missing references)
			//IL_05aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_05af: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0600: Unknown result type (might be due to invalid IL or missing references)
			//IL_0602: Unknown result type (might be due to invalid IL or missing references)
			//IL_0609: Unknown result type (might be due to invalid IL or missing references)
			//IL_060d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0614: Unknown result type (might be due to invalid IL or missing references)
			//IL_0619: Unknown result type (might be due to invalid IL or missing references)
			//IL_0653: Unknown result type (might be due to invalid IL or missing references)
			//IL_0658: Unknown result type (might be due to invalid IL or missing references)
			//IL_0659: Unknown result type (might be due to invalid IL or missing references)
			//IL_0689: Unknown result type (might be due to invalid IL or missing references)
			//IL_068d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0692: Unknown result type (might be due to invalid IL or missing references)
			//IL_0699: Unknown result type (might be due to invalid IL or missing references)
			//IL_069e: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06db: Unknown result type (might be due to invalid IL or missing references)
			//IL_06dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_06de: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0703: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0708: Unknown result type (might be due to invalid IL or missing references)
			//IL_0716: Unknown result type (might be due to invalid IL or missing references)
			//IL_0711: Unknown result type (might be due to invalid IL or missing references)
			//IL_072a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0723: Unknown result type (might be due to invalid IL or missing references)
			//IL_072c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0743: Unknown result type (might be due to invalid IL or missing references)
			//IL_075c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0761: Unknown result type (might be due to invalid IL or missing references)
			//IL_0780: Unknown result type (might be due to invalid IL or missing references)
			//IL_0785: Unknown result type (might be due to invalid IL or missing references)
			//IL_0788: Unknown result type (might be due to invalid IL or missing references)
			//IL_079d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0799: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0844: Unknown result type (might be due to invalid IL or missing references)
			//IL_0849: Unknown result type (might be due to invalid IL or missing references)
			//IL_0885: Unknown result type (might be due to invalid IL or missing references)
			//IL_089b: Unknown result type (might be due to invalid IL or missing references)
			Companion local = Companion.Local;
			if ((Object)(object)gameCamera == (Object)null)
			{
				return;
			}
			if (s_blend <= 0f || (Object)(object)local == (Object)null)
			{
				if (s_nearClipChanged)
				{
					gameCamera.m_camera.nearClipPlane = gameCamera.m_nearClipPlaneMax;
				}
				s_nearClipChanged = false;
				FirstPersonMods.ViewAway(Player.m_localPlayer, away: false);
				if ((Object)(object)local != (Object)null)
				{
					local.SetSeenFromInside(inside: false);
				}
				return;
			}
			Transform transform = ((Component)gameCamera).transform;
			Vector3 body = local.Body;
			float num = Mathf.Max(dt, 0.0001f);
			Vector3 val = ((Component)local).transform.position + Vector3.up * local.Kind.ModelOffset.y;
			Vector3 val2 = val - s_camTarget;
			if (((Vector3)(ref val2)).sqrMagnitude > 100f)
			{
				s_camTarget = val;
				s_camVelocity = Vector3.zero;
			}
			float value = Settings.CameraMotion.Value;
			s_camTarget = Vector3.SmoothDamp(s_camTarget, val, ref s_camVelocity, Mathf.Lerp(0.08f, 0.28f, value), float.PositiveInfinity, num);
			float speed = local.Flight.Speed;
			s_camCrown = Mathf.MoveTowards(s_camCrown, local.InCrown ? 1f : 0f, num