Decompiled source of PackBeasts v1.7.6

plugins/PackBeasts.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using TMPro;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PackBeasts")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PackBeasts")]
[assembly: AssemblyTitle("PackBeasts")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PackBeasts;

internal static class Abilities
{
	internal enum Kind
	{
		Quick,
		Heavy,
		Friend,
		Other
	}

	private sealed class Cached
	{
		public float Until;

		public List<KeyValuePair<ItemData, Kind>> List;
	}

	internal const int Max = 10;

	private static readonly Dictionary<int, Cached> s_cache = new Dictionary<int, Cached>();

	internal static int GroupOf(ItemData i)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		if ((int)i.m_shared.m_aiTargetType != 0)
		{
			return 1;
		}
		if (!Riding.DoesHarm(i))
		{
			return 2;
		}
		return 0;
	}

	internal static List<KeyValuePair<T, Kind>> Order<T>(IEnumerable<T> items, Func<T, int> group, Func<T, float> interval, Func<T, float> strength, Func<T, string> name)
	{
		List<T> source = items.ToList();
		List<KeyValuePair<T, Kind>> list = new List<KeyValuePair<T, Kind>>();
		List<T> list2 = source.Where((T i) => group(i) == 0).ToList();
		if (list2.Count > 0)
		{
			Riding.Split(list2, interval, strength, name, out var quick, out var heavy);
			foreach (T item in quick)
			{
				list.Add(new KeyValuePair<T, Kind>(item, Kind.Quick));
			}
			foreach (T item2 in heavy)
			{
				if (!quick.Contains(item2))
				{
					list.Add(new KeyValuePair<T, Kind>(item2, Kind.Heavy));
				}
			}
		}
		foreach (T item3 in source.Where((T i) => group(i) == 1).OrderBy<T, string>(name, StringComparer.Ordinal))
		{
			list.Add(new KeyValuePair<T, Kind>(item3, Kind.Friend));
		}
		foreach (T item4 in source.Where((T i) => group(i) == 2).OrderBy(interval).ThenBy<T, string>(name, StringComparer.Ordinal))
		{
			list.Add(new KeyValuePair<T, Kind>(item4, Kind.Other));
		}
		return list;
	}

	internal static List<KeyValuePair<ItemData, Kind>> Of(Humanoid h)
	{
		if ((Object)(object)h == (Object)null || h.GetInventory() == null)
		{
			return new List<KeyValuePair<ItemData, Kind>>();
		}
		HashSet<string> seen = new HashSet<string>();
		return Order((from i in h.GetInventory().GetAllItems()
			where i != null && i.IsWeapon() && i.HavePrimaryAttack() && i.m_shared.m_attack != null && !string.IsNullOrEmpty(i.m_shared.m_attack.m_attackAnimation)
			where seen.Add(Riding.NameOf(i))
			select i).ToList(), GroupOf, (ItemData i) => i.m_shared.m_aiAttackInterval, Riding.Strength, Riding.NameOf).Take(10).ToList();
	}

	internal static List<KeyValuePair<ItemData, Kind>> For(Character c)
	{
		Humanoid val = (Humanoid)(object)((c is Humanoid) ? c : null);
		if (val == null)
		{
			return new List<KeyValuePair<ItemData, Kind>>();
		}
		int instanceID = ((Object)c).GetInstanceID();
		if (s_cache.TryGetValue(instanceID, out var value) && Time.time < value.Until)
		{
			return value.List;
		}
		if (s_cache.Count > 32)
		{
			s_cache.Clear();
		}
		value = (s_cache[instanceID] = new Cached
		{
			Until = Time.time + 1f,
			List = Of(val)
		});
		return value.List;
	}

	internal static KeyCode KeyFor(int index)
	{
		if (index == 9)
		{
			return (KeyCode)48;
		}
		return (KeyCode)(49 + index);
	}

	internal static string KeyName(int index)
	{
		if (index != 9)
		{
			return (index + 1).ToString();
		}
		return "0";
	}

	internal static string ShortName(string item, string creature)
	{
		if (string.IsNullOrEmpty(item))
		{
			return "?";
		}
		string text = item;
		if (!string.IsNullOrEmpty(creature) && text.Length > creature.Length + 1 && text.StartsWith(creature, StringComparison.OrdinalIgnoreCase) && text[creature.Length] == '_')
		{
			text = text.Substring(creature.Length + 1);
		}
		else
		{
			int num = text.IndexOf('_');
			if (num > 0 && num < text.Length - 1)
			{
				text = text.Substring(num + 1);
			}
		}
		StringBuilder stringBuilder = new StringBuilder();
		for (int i = 0; i < text.Length; i++)
		{
			char c = text[i];
			if (c == '_' || c == '-' || c == ' ' || c == '(' || c == ')')
			{
				if (stringBuilder.Length > 0 && stringBuilder[stringBuilder.Length - 1] != ' ')
				{
					stringBuilder.Append(' ');
				}
				continue;
			}
			if (i > 0 && char.IsUpper(c) && char.IsLower(text[i - 1]) && stringBuilder.Length > 0 && stringBuilder[stringBuilder.Length - 1] != ' ')
			{
				stringBuilder.Append(' ');
			}
			stringBuilder.Append(c);
		}
		string text2 = stringBuilder.ToString().Trim().ToLowerInvariant();
		if (text2.Length == 0)
		{
			return item;
		}
		return char.ToUpperInvariant(text2[0]) + text2.Substring(1);
	}

	internal static List<string> Names(IList<string> items, string creature)
	{
		List<string> bases = items.Select((string i) => ShortName(i, creature)).ToList();
		List<string> list = new List<string>();
		int k;
		for (k = 0; k < bases.Count; k++)
		{
			int num = bases.Take(k).Count((string n) => n == bases[k]);
			list.Add((num > 0) ? (bases[k] + " " + (num + 1)) : bases[k]);
		}
		return list;
	}

	internal static Character FriendTarget(Character caster)
	{
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if (!((Object)(object)localPlayer == (Object)null))
		{
			IDoodadController doodadController = localPlayer.GetDoodadController();
			Sadle val = (Sadle)(object)((doodadController is Sadle) ? doodadController : null);
			if (val != null && !((Object)(object)val == (Object)null) && !((Object)(object)val.GetCharacter() != (Object)(object)caster))
			{
				Character val2 = Riding.CrosshairCharacter(caster);
				if ((Object)(object)val2 != (Object)null && !val2.IsDead() && (Object)(object)val2 != (Object)(object)caster && !BaseAI.IsEnemy(caster, val2) && Vector3.Distance(((Component)val2).transform.position, ((Component)caster).transform.position) <= 40f)
				{
					return val2;
				}
				return (Character)(object)localPlayer;
			}
		}
		return null;
	}
}
internal static class AttackReport
{
	private sealed class Weapon
	{
		public string Name;

		public ItemData Data;
	}

	internal static void Write()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("Attacks a rider can use, per creature (PackBeasts 1.7.6). Written each time a game starts.");
		stringBuilder.AppendLine("Left click = the quick attacks, right click (or the middle mouse button) = the heavy ones, a different one each press. The number keys use each ability on its own.");
		stringBuilder.AppendLine("With Three attacks on the mouse on: a creature with three abilities or fewer has them on left, right and middle click (\"mouse\" below); one with exactly three attacks has those on the three buttons.");
		stringBuilder.AppendLine("A creature that gets one of several weapon sets (dvergr mages, for one) is listed once per set. Lines starting with ! are attacks the keys skip, or that may not work, and why.");
		stringBuilder.AppendLine();
		int num = 0;
		int num2 = 0;
		foreach (GameObject item in ZNetScene.instance.m_prefabs.Where((GameObject p) => (Object)(object)p != (Object)null).OrderBy<GameObject, string>((GameObject p) => ((Object)p).name, StringComparer.OrdinalIgnoreCase))
		{
			Humanoid component = item.GetComponent<Humanoid>();
			if ((Object)(object)component == (Object)null || (Object)(object)item.GetComponent<Player>() != (Object)null || (Object)(object)item.GetComponent<MonsterAI>() == (Object)null)
			{
				continue;
			}
			List<List<Weapon>> list = Sets(component);
			if (list.All((List<Weapon> s) => s.Count == 0))
			{
				continue;
			}
			num++;
			bool flag = (Object)(object)item.GetComponent<Tameable>() != (Object)null;
			bool flag2 = item.GetComponent<BaseAI>()?.m_randomFly ?? false;
			stringBuilder.AppendLine(((Object)item).name + (flag ? "" : " (not tameable by default)") + (flag2 ? " (flies)" : ""));
			for (int num3 = 0; num3 < list.Count; num3++)
			{
				List<Weapon> source = list[num3];
				string text = ((list.Count > 1) ? ("  set " + (num3 + 1) + ": ") : "  ");
				List<Weapon> list2 = source.Where((Weapon w) => w.Data.IsWeapon() && w.Data.HavePrimaryAttack()).ToList();
				List<Weapon> list3 = list2.Where((Weapon w) => Usable(w.Data)).ToList();
				if (list3.Count == 0)
				{
					list3 = list2.Where((Weapon w) => (int)w.Data.m_shared.m_aiTargetType == 0 && Riding.DoesHarm(w.Data)).ToList();
				}
				if (list3.Count == 0)
				{
					stringBuilder.AppendLine(text + "no attacks a rider can use");
					num2++;
				}
				else
				{
					Riding.Split(list3, (Weapon w) => w.Data.m_shared.m_aiAttackInterval, (Weapon w) => Riding.Strength(w.Data), (Weapon w) => w.Name, out var quick, out var heavy);
					stringBuilder.AppendLine(text + "left click: " + string.Join(", ", quick.Select(Describe)));
					stringBuilder.AppendLine(new string(' ', text.Length) + "right click: " + string.Join(", ", heavy.Select(Describe)));
					if (list3.Count == 3)
					{
						List<Weapon> list4 = (from w in list3
							orderby w.Data.m_shared.m_aiAttackInterval, Riding.Strength(w.Data)
							select w).ThenBy<Weapon, string>((Weapon w) => w.Name, StringComparer.Ordinal).ToList();
						stringBuilder.AppendLine(new string(' ', text.Length) + "three attacks: left " + list4[0].Name + ", right " + list4[1].Name + ", middle " + list4[2].Name);
					}
				}
				List<Weapon> list5 = list2.Where((Weapon w) => w.Data.m_shared.m_attack != null && !string.IsNullOrEmpty(w.Data.m_shared.m_attack.m_attackAnimation)).ToList();
				if (list5.Count > 0)
				{
					List<Weapon> list6 = (from p in Abilities.Order(list5, (Weapon w) => Abilities.GroupOf(w.Data), (Weapon w) => w.Data.m_shared.m_aiAttackInterval, (Weapon w) => Riding.Strength(w.Data), (Weapon w) => w.Name).Take(10)
						select p.Key).ToList();
					List<string> names = Abilities.Names(list6.Select((Weapon w) => w.Name).ToList(), ((Object)item).name);
					stringBuilder.AppendLine(new string(' ', text.Length) + "number keys: " + string.Join(", ", list6.Select((Weapon w, int k) => Abilities.KeyName(k) + " " + names[k])));
					if (list6.Count <= 3)
					{
						string[] buttons = new string[3] { "left", "right", "middle" };
						stringBuilder.AppendLine(new string(' ', text.Length) + "mouse: " + string.Join(", ", list6.Select((Weapon w, int k) => buttons[k] + " " + names[k])));
					}
				}
				foreach (Weapon item2 in list2)
				{
					string text2 = Problem(item2.Data, list3.Contains(item2));
					if (text2 != null)
					{
						string text3 = (list3.Contains(item2) ? item2.Name : (Describe(item2) + FriendSpell(item2.Data)));
						stringBuilder.AppendLine(new string(' ', text.Length) + "! " + text3 + ": " + text2);
						if (list3.Contains(item2))
						{
							num2++;
						}
					}
				}
			}
		}
		stringBuilder.AppendLine();
		stringBuilder.AppendLine(num + " creatures, " + num2 + " attacks (or sets) that may not work under a rider.");
		string text4 = Path.Combine(Paths.ConfigPath, "anwo.PackBeasts.attacks.txt");
		File.WriteAllText(text4, stringBuilder.ToString());
		FileLog.Info(PackBeastsPlugin.Log, "Wrote the attacks of " + num + " creatures to " + text4 + ((num2 > 0) ? (" (" + num2 + " may not work under a rider; see the lines starting with !)") : "") + ".");
	}

	private static string Describe(Weapon w)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Invalid comparison between Unknown and I4
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Invalid comparison between Unknown and I4
		Attack attack = w.Data.m_shared.m_attack;
		string text = ((attack == null) ? "?" : (((int)attack.m_attackType == 2) ? ("shot" + (((Object)(object)attack.m_attackProjectile != (Object)null) ? (" (" + ((Object)attack.m_attackProjectile).name + ")") : "")) : (((int)attack.m_attackType == 4) ? "area" : ((object)Unsafe.As<AttackType, AttackType>(ref attack.m_attackType)/*cast due to .constrained prefix*/).ToString().ToLowerInvariant())));
		return w.Name + " [" + text + ", every " + w.Data.m_shared.m_aiAttackInterval.ToString("0.#") + " s]";
	}

	internal static string FriendSpell(ItemData i)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			SharedData shared = i.m_shared;
			if ((int)shared.m_aiTargetType == 0 || shared.m_attack == null)
			{
				return "";
			}
			List<string> list = new List<string>();
			Attack attack = shared.m_attack;
			list.Add("range " + shared.m_aiAttackRange.ToString("0.#") + " m");
			if (attack.m_attackHealth != 0f)
			{
				list.Add("costs the caster " + attack.m_attackHealth.ToString("0.#") + " health");
			}
			GameObject val = attack.m_attackProjectile;
			Projectile val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Projectile>() : null);
			if ((Object)(object)val2 != (Object)null)
			{
				if (!string.IsNullOrEmpty(val2.m_statusEffect))
				{
					list.Add("the shot gives " + val2.m_statusEffect);
				}
				if ((Object)(object)val2.m_spawnOnHit != (Object)null)
				{
					val = val2.m_spawnOnHit;
					list.Add("lands as " + ((Object)val).name);
				}
			}
			if ((Object)(object)val == (Object)null && (Object)(object)attack.m_spawnOnTrigger != (Object)null)
			{
				val = attack.m_spawnOnTrigger;
				list.Add("makes " + ((Object)val).name);
			}
			Aoe val3 = (((Object)(object)val != (Object)null) ? val.GetComponentInChildren<Aoe>(true) : null);
			if ((Object)(object)val3 != (Object)null)
			{
				List<string> list2 = new List<string>();
				if (val3.m_hitOwner)
				{
					list2.Add("caster");
				}
				if (val3.m_hitFriendly)
				{
					list2.Add("friends");
				}
				if (val3.m_hitEnemy)
				{
					list2.Add("enemies");
				}
				if (val3.m_hitSame)
				{
					list2.Add("its own kind");
				}
				list.Add("area " + val3.m_radius.ToString("0.#") + " m on " + ((list2.Count > 0) ? string.Join("/", list2) : "nobody") + (string.IsNullOrEmpty(val3.m_statusEffect) ? "" : (", gives " + val3.m_statusEffect)) + (string.IsNullOrEmpty(val3.m_statusEffectIfPlayer) ? "" : (", players get " + val3.m_statusEffectIfPlayer)));
			}
			return " {" + string.Join("; ", list) + "}";
		}
		catch (Exception ex)
		{
			return " {" + ex.GetType().Name + "}";
		}
	}

	private static bool Usable(ItemData i)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		if ((int)i.m_shared.m_aiTargetType == 0 && Riding.DoesHarm(i))
		{
			if (!i.m_shared.m_aiWhenWalking)
			{
				return i.m_shared.m_aiWhenFlying;
			}
			return true;
		}
		return false;
	}

	private static string Problem(ItemData i, bool used)
	{
		//IL_0012: 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_0025: Invalid comparison between Unknown and I4
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Invalid comparison between Unknown and I4
		SharedData shared = i.m_shared;
		Attack attack = shared.m_attack;
		if (!used)
		{
			if ((int)shared.m_aiTargetType != 0)
			{
				return "skipped: meant for " + (((int)shared.m_aiTargetType == 1) ? "healing friends" : "friends") + ", not for fighting";
			}
			if (!Riding.DoesHarm(i))
			{
				return "skipped: does no harm";
			}
			return "skipped";
		}
		if (attack == null || string.IsNullOrEmpty(attack.m_attackAnimation))
		{
			return "has no animation";
		}
		if (attack.m_attackEitr > 0f)
		{
			return "needs eitr, which creatures don't have";
		}
		if (!string.IsNullOrEmpty(shared.m_ammoType))
		{
			return "needs ammo (" + shared.m_ammoType + ")";
		}
		if (attack.m_requiresReload)
		{
			return "needs reloading";
		}
		if (attack.m_cantUseInDungeon)
		{
			return "can't be used indoors";
		}
		if ((int)attack.m_attackType == 2 && (Object)(object)attack.m_attackProjectile == (Object)null)
		{
			return "shoots nothing (no projectile)";
		}
		if (!shared.m_aiWhenWalking)
		{
			return "only used in the air";
		}
		return null;
	}

	private static List<List<Weapon>> Sets(Humanoid h)
	{
		List<Weapon> list = new List<Weapon>();
		Add(list, h.m_defaultItems);
		Add(list, h.m_randomWeapon);
		if (h.m_randomItems != null)
		{
			Add(list, from r in h.m_randomItems
				where r != null
				select r.m_prefab);
		}
		List<List<Weapon>> list2 = new List<List<Weapon>>();
		if (h.m_randomSets != null)
		{
			ItemSet[] randomSets = h.m_randomSets;
			foreach (ItemSet val in randomSets)
			{
				if (val != null)
				{
					List<Weapon> list3 = new List<Weapon>(list);
					Add(list3, val.m_items);
					list2.Add(list3);
				}
			}
		}
		if (list2.Count == 0)
		{
			list2.Add(list);
		}
		return list2;
	}

	private static void Add(List<Weapon> list, IEnumerable<GameObject> items)
	{
		if (items == null)
		{
			return;
		}
		foreach (GameObject go in items)
		{
			ItemDrop val = (((Object)(object)go != (Object)null) ? go.GetComponent<ItemDrop>() : null);
			if (!((Object)(object)val == (Object)null) && val.m_itemData != null && val.m_itemData.m_shared != null && !list.Any((Weapon w) => w.Name == ((Object)go).name))
			{
				list.Add(new Weapon
				{
					Name = ((Object)go).name,
					Data = val.m_itemData
				});
			}
		}
	}
}
internal static class BackSeat
{
	internal static ConfigEntry<bool> Steady;

	internal const float NeckAlong = 0.5f;

	internal const float BakeWide = 0.2f;

	internal const float BakeMost = 3f;

	internal const float BakeShare = 0.8f;

	internal const float BakeAboveGuess = 0.5f;

	private static readonly HashSet<string> s_told = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

	private static int s_onLines;

	internal const int OnMost = 40;

	internal const float WatchMinute = 60f;

	internal const int WatchMost = 60;

	private static int s_watchSaid;

	private static object s_watchOn;

	private static float s_watchFrom;

	private static float s_watchDist;

	private static Vector3 s_watchLast;

	private static readonly HeadSeat.Range s_spot = new HeadSeat.Range();

	private static readonly HeadSeat.Range s_seat = new HeadSeat.Range();

	private static readonly HeadSeat.Range s_cam = new HeadSeat.Range();

	private static int s_cams;

	private static float s_gapMax;

	private static float s_camGapMax;

	internal static bool On
	{
		get
		{
			if (Steady != null)
			{
				return Steady.Value;
			}
			return false;
		}
	}

	internal static void Bind(ConfigFile cfg)
	{
		Steady = cfg.Bind<bool>("5 - Riding handle", "Steady seat on the back", true, "On a creature's back or shoulders with a riding handle, you move with its back exactly, every frame, so you never sink into it or float off it as it bobs with wing beats or steps, and the camera takes the bobbing out instead (see Steady camera on a head, which counts for back seats too). A back seat that would be on a creature's neck (the dragon's) goes on its back behind where the neck starts, between the wings, as high as the top of its back there (measured from its body when you get on, if the game lets it be read). Seat height still moves you up or down on top of that, live. Head seats (a troll's) go by Steady seat. The log names the bone your seat is on each time you get on, and once a minute while you ride says how much the spot under you, your seat and the camera bobbed (Seat watch lines). Changes when you next get on. Off: on a back or shoulders your seat follows the bone under it, smoothed side to side, as in PackBeasts 1.7.4.");
		Steady.SettingChanged += delegate
		{
			s_told.Clear();
			RidingHandle.RebuildAll();
		};
	}

	internal static bool Kind(char kind)
	{
		if (kind != 's')
		{
			return kind == 'u';
		}
		return true;
	}

	internal static Vector3 OnSpot(Vector3 spot, Quaternion facing, Vector3 off)
	{
		//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_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)
		return spot + facing * off;
	}

	internal static bool IsNeck(string name)
	{
		if (name != null)
		{
			return name.IndexOf("neck", StringComparison.OrdinalIgnoreCase) >= 0;
		}
		return false;
	}

	internal static bool PastNeckRoot(IList<string> names, out int root)
	{
		root = -1;
		if (names == null || names.Count < 2 || !IsNeck(names[0]) || !IsNeck(names[1]))
		{
			return false;
		}
		int i;
		for (i = 1; i + 1 < names.Count && IsNeck(names[i + 1]); i++)
		{
		}
		root = i;
		return i + 1 < names.Count;
	}

	internal static HandleSpots.Spot BehindNeck(Transform root, HandleSpots.Spot spot, out string note)
	{
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: 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_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_00b4: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: 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_00ff: 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_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: 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_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_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: 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_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: 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_01f8: 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_0206: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_022d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0232: 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_0241: Unknown result type (might be due to invalid IL or missing references)
		//IL_024a: 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_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0269: Unknown result type (might be due to invalid IL or missing references)
		//IL_026b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0270: Unknown result type (might be due to invalid IL or missing references)
		//IL_0275: Unknown result type (might be due to invalid IL or missing references)
		//IL_027f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0281: Unknown result type (might be due to invalid IL or missing references)
		//IL_0286: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: Unknown result type (might be due to invalid IL or missing references)
		note = null;
		if (!On || spot == null || spot.Kind != 's' || (Object)(object)spot.SeatBone == (Object)null || (Object)(object)root == (Object)null)
		{
			return null;
		}
		List<string> list = new List<string>();
		List<Transform> list2 = new List<Transform>();
		Transform val = spot.SeatBone;
		while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)root)
		{
			list.Add(((Object)val).name);
			list2.Add(val);
			val = val.parent;
		}
		if (!PastNeckRoot(list, out var root2))
		{
			return null;
		}
		Transform val2 = list2[root2];
		Transform val3 = list2[root2 + 1];
		Vector3 val4 = root.InverseTransformPoint(val3.position);
		Vector3 val5 = root.InverseTransformPoint(val2.position);
		Vector3 val6 = Vector3.Lerp(val4, val5, 0.5f);
		Vector3 val7 = val5 - val4;
		Vector3 val8;
		if (!(((Vector3)(ref val7)).sqrMagnitude > 1E-06f))
		{
			val8 = Vector3.up;
		}
		else
		{
			val7 = val5 - val4;
			val8 = ((Vector3)(ref val7)).normalized;
		}
		Vector3 val9 = val8;
		Vector3 val10 = Vector3.up - val9 * Vector3.Dot(Vector3.up, val9);
		if (((Vector3)(ref val10)).magnitude < 0.3f)
		{
			val10 = Vector3.back - val9 * Vector3.Dot(Vector3.back, val9);
		}
		val10 = ((((Vector3)(ref val10)).sqrMagnitude > 1E-06f) ? ((Vector3)(ref val10)).normalized : Vector3.up);
		string how;
		float num = Thickness(root, val6, val10, out how);
		Vector3 val11 = val6 + val10 * num;
		HandleSpots.Spot spot2 = new HandleSpots.Spot
		{
			Kind = spot.Kind,
			Pose = spot.Pose,
			HalfWidth = spot.HalfWidth,
			GripHeight = spot.GripHeight,
			Measured = spot.Measured,
			FromBones = spot.FromBones,
			Metric = spot.Metric,
			Report = spot.Report,
			SeatBone = val3,
			GripBone = val3,
			SeatRoot = val11
		};
		spot2.SeatLocal = val3.InverseTransformPoint(root.TransformPoint(val11));
		spot2.GripLocal = val3.InverseTransformPoint(root.TransformPoint(val11 + new Vector3(0f, 0f, 0.25f)));
		spot2.GripRot = Quaternion.Inverse(val3.rotation) * root.rotation;
		spot2.NeckBase = val3.InverseTransformPoint(root.TransformPoint(val6));
		spot2.NeckUp = val3.InverseTransformDirection(root.TransformDirection(val10));
		spot2.NeckOut = num;
		spot2.NeckHow = how;
		note = string.Format(CultureInfo.InvariantCulture, "moved from {0} (on its neck) onto {1}, where the neck starts: half way from {1} to {2}, {3:0.00} m out to the top of its back ({4})", ((Object)spot.SeatBone).name, ((Object)val3).name, ((Object)val2).name, num, how);
		return spot2;
	}

	private static float Thickness(Transform root, Vector3 point, Vector3 up, out string how)
	{
		//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_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: 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)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			List<Vector3> list = HandleSpots.SkinPoints(root);
			float num = float.NaN;
			foreach (Vector3 item in list)
			{
				Vector3 val = item - point;
				float num2 = Vector3.Dot(val, up);
				if (!(num2 <= 0f))
				{
					Vector3 val2 = val - up * num2;
					if (!(((Vector3)(ref val2)).sqrMagnitude > 0.040000003f) && (float.IsNaN(num) || num2 > num))
					{
						num = num2;
					}
				}
			}
			if (!float.IsNaN(num) && num < 3f)
			{
				how = "its skin";
				return num;
			}
		}
		catch (Exception ex)
		{
			PackBeastsPlugin.Log.LogDebug((object)("Seat: reading the body's shape failed: " + ex.Message));
		}
		CapsuleCollider component = ((Component)root).GetComponent<CapsuleCollider>();
		float result = (((Object)(object)component != (Object)null) ? Mathf.Clamp(component.radius * 0.5f, 0.15f, 1f) : 0.3f);
		how = (((Object)(object)component != (Object)null) ? "half its body capsule's radius, as its skin can't be read" : "a guess, as its skin can't be read");
		return result;
	}

	internal static float TopAlong(IList<Vector3> points, Vector3 point, Vector3 up, out int n)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: 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_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		n = 0;
		if (points == null || ((Vector3)(ref up)).sqrMagnitude < 1E-08f)
		{
			return float.NaN;
		}
		up = ((Vector3)(ref up)).normalized;
		List<float> list = new List<float>();
		foreach (Vector3 point2 in points)
		{
			Vector3 val = point2 - point;
			float num = Vector3.Dot(val, up);
			if (!(num <= 0f) && !(num > 3f))
			{
				Vector3 val2 = val - up * num;
				if (!(((Vector3)(ref val2)).sqrMagnitude > 0.040000003f))
				{
					list.Add(num);
				}
			}
		}
		n = list.Count;
		if (n == 0)
		{
			return float.NaN;
		}
		list.Sort();
		return list[(int)Math.Floor(0.8f * (float)(n - 1))];
	}

	internal static float Capped(float top, float guess, out bool capped)
	{
		capped = !float.IsNaN(top) && top > guess + 0.5f;
		if (!capped)
		{
			return top;
		}
		return guess + 0.5f;
	}

	internal static List<Vector3> Baked(Transform root, out string why)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected O, but got Unknown
		//IL_00d2: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		List<Vector3> list = new List<Vector3>();
		why = "";
		Mesh val = null;
		int num = 0;
		int num2 = 0;
		try
		{
			val = new Mesh();
			SkinnedMeshRenderer[] componentsInChildren = ((Component)root).GetComponentsInChildren<SkinnedMeshRenderer>(false);
			foreach (SkinnedMeshRenderer val2 in componentsInChildren)
			{
				if ((Object)(object)val2 == (Object)null || !((Renderer)val2).enabled || (Object)(object)val2.sharedMesh == (Object)null)
				{
					continue;
				}
				bool flag = false;
				Transform val3 = ((Component)val2).transform;
				while ((Object)(object)val3 != (Object)null && (Object)(object)val3 != (Object)(object)root)
				{
					if (((Object)val3).name.StartsWith("anwo_", StringComparison.Ordinal))
					{
						flag = true;
						break;
					}
					val3 = val3.parent;
				}
				if (flag)
				{
					continue;
				}
				num++;
				try
				{
					val2.BakeMesh(val, true);
					Vector3[] vertices = val.vertices;
					if (vertices == null || vertices.Length == 0)
					{
						num2++;
						continue;
					}
					Matrix4x4 val4 = Matrix4x4.TRS(((Component)val2).transform.position, ((Component)val2).transform.rotation, Vector3.one);
					for (int j = 0; j < vertices.Length; j++)
					{
						list.Add(((Matrix4x4)(ref val4)).MultiplyPoint3x4(vertices[j]));
					}
				}
				catch (Exception ex)
				{
					num2++;
					why = ex.GetType().Name + ": " + ex.Message;
				}
			}
		}
		catch (Exception ex2)
		{
			why = ex2.GetType().Name + ": " + ex2.Message;
		}
		finally
		{
			if ((Object)(object)val != (Object)null)
			{
				Object.Destroy((Object)(object)val);
			}
		}
		if (list.Count == 0 && why.Length == 0)
		{
			why = ((num == 0) ? "no skinned mesh" : (num2 + " of " + num + " mesh(es) baked empty"));
		}
		return list;
	}

	internal static void TellOn(string prefab, HandleSpot want, HandleSpots.Spot spot, float seatUp, string moved, bool steady, string height)
	{
		if (spot != null && s_onLines < 40)
		{
			s_onLines++;
			float num = ((HeadSeat.SteadyCamera != null) ? HeadSeat.SteadyCamera.Value : 0f);
			float num2 = ((RidingHandles.SeatUp != null) ? RidingHandles.SeatUp.Value : 0f);
			string text = ((spot.Kind == 'h') ? ("a head seat (Steady seat " + ((HeadSeat.Steady != null && HeadSeat.Steady.Value) ? "on" : "off") + ")") : (steady ? string.Format(CultureInfo.InvariantCulture, "Steady seat on the back on: you move with the spot on its bone exactly, every frame; the camera {0}; Seat height {1:0.00} m is added on top, live", (!HeadCamera.Ready) ? "follows you exactly (it couldn't be steadied: see the start of the log)" : ((num > 0f) ? ("follows a steadied copy of your seat (Steady camera on a head " + num.ToString("0.0#", CultureInfo.InvariantCulture) + " s)") : "follows you exactly (Steady camera on a head 0)"), num2) : "Steady seat on the back off: it follows the bone, smoothed side to side, as in 1.7.4"));
			if (!string.IsNullOrEmpty(height))
			{
				moved = (string.IsNullOrEmpty(moved) ? height : (moved + "; " + height));
			}
			FileLog.Info(PackBeastsPlugin.Log, string.Format(CultureInfo.InvariantCulture, "Seat: you got on the {0} ({1}): your seat is on its {2} bone, {3:0.00} m above its feet{4}; {5}.", prefab, HeadSeat.SpotWord(want), ((Object)(object)spot.SeatBone != (Object)null) ? ((Object)spot.SeatBone).name : "?", seatUp, string.IsNullOrEmpty(moved) ? "" : (" (" + moved + ")"), text));
		}
	}

	internal static void TellMoved(string prefab, string note)
	{
		if (!string.IsNullOrEmpty(note) && s_told.Count < 64 && s_told.Add(prefab))
		{
			PackBeastsPlugin.Log.LogInfo((object)("Seat: on the " + prefab + " a back seat stays behind where the neck starts (Steady seat on the back): " + note + "."));
		}
	}

	internal static void Watch(object h, Transform root, string prefab, HandleSpots.Spot spot, Vector3 bone, Vector3 seat, bool camOn, Vector3 cam)
	{
		//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_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: 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_0087: 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_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: 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_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: 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_0126: 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_0137: 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_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_024b: 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)
		if ((Object)(object)root == (Object)null || spot == null || s_watchSaid >= 60)
		{
			return;
		}
		float time = Time.time;
		if (h != s_watchOn)
		{
			s_watchOn = h;
			Restart(root, time);
			return;
		}
		float num = Vector3.Distance(root.position, s_watchLast);
		s_watchLast = root.position;
		if (num > 5f)
		{
			Restart(root, time);
			return;
		}
		s_watchDist += num;
		s_spot.Add(bone);
		s_seat.Add(seat);
		float num2 = s_gapMax;
		Vector3 val = seat - bone;
		s_gapMax = Mathf.Max(num2, ((Vector3)(ref val)).magnitude);
		if (camOn)
		{
			s_cam.Add(cam);
			s_cams++;
			float num3 = s_camGapMax;
			val = cam - seat;
			s_camGapMax = Mathf.Max(num3, ((Vector3)(ref val)).magnitude);
		}
		float num4 = time - s_watchFrom;
		if (!(num4 < 60f))
		{
			s_watchSaid++;
			Vector3 val2 = s_spot.Span * 100f;
			Vector3 val3 = s_seat.Span * 100f;
			Vector3 val4 = s_cam.Span * 100f;
			PackBeastsPlugin.Log.LogInfo((object)string.Format(CultureInfo.InvariantCulture, "Seat watch: riding the {0} on its {1} (your seat is on its {2} bone, Steady seat on the back on), the last {3:0} s at {4:0.0} m/s: the spot under you bobbed {5:0} cm up and down, {6:0} cm side to side and {7:0} cm forward and back; your seat moved {8:0}, {9:0} and {10:0} cm and was at most {11:0} cm from the spot; the camera {12}{13}.", prefab, HeadSeat.SpotWord(RidingHandles.SpotFor(prefab)), ((Object)(object)spot.SeatBone != (Object)null) ? ((Object)spot.SeatBone).name : "?", num4, s_watchDist / Mathf.Max(0.01f, num4), val2.y, val2.x, val2.z, val3.y, val3.x, val3.z, s_gapMax * 100f, (s_cams > 0) ? string.Format(CultureInfo.InvariantCulture, "(a steadied copy of your seat) moved {0:0}, {1:0} and {2:0} cm and was at most {3:0} cm from your seat{4}", val4.y, val4.x, val4.z, s_camGapMax * 100f, HeadCamera.FirstPersonNote()) : "followed you exactly (Steady camera on a head 0, or it couldn't be steadied)", (s_watchSaid >= 60) ? " (No more of these this session.)" : ""));
			Restart(root, time);
		}
	}

	private static void Restart(Transform root, float now)
	{
		//IL_0011: 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_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: 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_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: 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_006c: 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_006e: 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_0074: 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_0076: 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_007c: Unknown result type (might be due to invalid IL or missing references)
		s_watchFrom = now;
		s_watchDist = 0f;
		s_watchLast = root.position;
		s_spot.Min = (s_seat.Min = (s_cam.Min = Vector3.one * float.MaxValue));
		s_spot.Max = (s_seat.Max = (s_cam.Max = Vector3.one * float.MinValue));
		s_cams = 0;
		s_gapMax = (s_camGapMax = 0f);
		HeadCamera.ResetCounts();
	}
}
public class RidingHandle : MonoBehaviour
{
	private string m_backMoved;

	private bool m_wasMine;

	private bool m_baked;

	private static readonly HashSet<string> s_bakeTold = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

	private static bool s_backWatchFailed;

	private Vector3 m_cam;

	private Vector3 m_camVel;

	private bool m_camHave;

	private static bool s_camFailed;

	private static bool s_watchFailed;

	internal const string Name = "anwo_riding_handle";

	private const float Gap = 0.17f;

	private static readonly List<RidingHandle> All = new List<RidingHandle>();

	private Tameable m_tame;

	private Sadle m_sadle;

	private Transform m_root;

	private Transform m_attach;

	private GameObject m_grip;

	private GameObject m_touch;

	private BoxCollider m_box;

	private Quaternion m_gripLocal;

	private Quaternion m_gripSmooth;

	private bool m_gripSteady;

	private Vector3 m_offset;

	private Transform m_parts;

	private Transform m_bar;

	private Transform m_barGrip;

	private Transform m_capL;

	private Transform m_capR;

	private Transform m_strapL;

	private Transform m_strapR;

	private Vector3 m_barPos;

	private Vector3 m_barGripScale;

	private Vector3 m_capLPos;

	private Vector3 m_capRPos;

	private Vector3 m_strapLPos;

	private Vector3 m_strapRPos;

	private Vector3 m_strapScale;

	private Quaternion m_barRot;

	private Quaternion m_strapRot;

	private float m_strapRest;

	private bool m_held;

	private Player m_rider;

	private float m_riderAt;

	private string m_prefab;

	private bool m_dirty;

	private HandleSpots.Spot m_spot;

	private static int s_added;

	private static Sadle s_template;

	internal const float ReachAbove = 3f;

	private float m_baseReach = 6f;

	private static readonly HashSet<string> s_reachTold = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

	private static bool s_baseReachTold;

	private static readonly HashSet<string> s_told = new HashSet<string>();

	private const float SwaySide = 0.6f;

	private const float SwayUp = 0.12f;

	private const float SwayAlong = 0.08f;

	private const float WobbleTurn = 0.12f;

	private const float RealTurn = 0.03f;

	private const float RealTurnAngle = 15f;

	private Vector3 m_seatSmooth;

	private Quaternion m_turnSmooth;

	private bool m_seatHave;

	private int m_placedFrame = -1;

	private static readonly HashSet<RidingHandle> Riders = new HashSet<RidingHandle>();

	private static bool s_hooked;

	private static int s_heldFrame = -1;

	private const float MostSpan = 0.9f;

	private const float MostReach = 1f;

	internal HandleSpots.Spot Spot => m_spot;

	private bool SteadyBack()
	{
		if (BackSeat.On && m_spot != null)
		{
			return BackSeat.Kind(m_spot.Kind);
		}
		return false;
	}

	private void PlaceBack(Vector3 local, Quaternion body, Quaternion rot, Vector3 off, float dt)
	{
		//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_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: 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_0021: 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_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: 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_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: 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_006c: 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)
		m_seatSmooth = local;
		m_seatHave = true;
		Vector3 val = BackSeat.OnSpot(((Component)this).transform.position, rot, off);
		SteadyCamera(local, body, dt);
		if (RiddenByMe())
		{
			try
			{
				BackSeat.Watch(this, m_root, m_prefab, m_spot, local, Quaternion.Inverse(body) * (val - rot * off - m_root.position), m_camHave, m_cam);
			}
			catch (Exception ex)
			{
				if (!s_backWatchFailed)
				{
					s_backWatchFailed = true;
					PackBeastsPlugin.Log.LogDebug((object)("Seat watch (back) failed: " + ex.Message));
				}
			}
		}
		m_attach.SetPositionAndRotation(val, rot);
	}

	private string BakeHeight()
	{
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: 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_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: 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)
		if (m_baked || m_spot == null || (Object)(object)m_spot.SeatBone == (Object)null || string.IsNullOrEmpty(m_backMoved) || !SteadyBack())
		{
			return null;
		}
		m_baked = true;
		try
		{
			Transform seatBone = m_spot.SeatBone;
			Vector3 val = seatBone.TransformPoint(m_spot.NeckBase);
			Vector3 up = seatBone.TransformDirection(m_spot.NeckUp);
			string why;
			List<Vector3> list = BackSeat.Baked(m_root, out why);
			int n;
			float num = BackSeat.TopAlong(list, val, up, out n);
			string text;
			if (list.Count > 0 && !float.IsNaN(num))
			{
				bool capped;
				float num2 = BackSeat.Capped(num, m_spot.NeckOut, out capped);
				Vector3 position = ((Component)this).transform.position;
				Vector3 val2 = val + ((Vector3)(ref up)).normalized * num2;
				m_spot.SeatLocal = seatBone.InverseTransformPoint(val2);
				m_spot.SeatRoot = m_root.InverseTransformPoint(val2);
				((Component)this).transform.localPosition = m_spot.SeatLocal;
				MovedSeat(((Component)this).transform.position - position);
				text = string.Format(CultureInfo.InvariantCulture, "height from its baked mesh: the top of its back is {0:0.00} m out from the spine ({1:0}th percentile of {2} of its {3} points within {4:0.0} m of the line out from it){5}, not the guess {6:0.00} m ({7}); the grip moved with it", num2, 80f, n, list.Count, 0.2f, capped ? string.Format(CultureInfo.InvariantCulture, " (CAPPED: measured {0:0.00} m, more than {1:0.0} m above the guess)", num, 0.5f) : "", m_spot.NeckOut, m_spot.NeckHow);
			}
			else
			{
				text = string.Format(CultureInfo.InvariantCulture, "baked mesh unavailable ({0}), using the guess {1:0.00} m out from the spine ({2})", (list.Count == 0) ? why : ("no point of its " + list.Count + " within " + 0.2f.ToString("0.0", CultureInfo.InvariantCulture) + " m of the line out from the spine"), m_spot.NeckOut, m_spot.NeckHow);
			}
			if (s_bakeTold.Count < 64 && s_bakeTold.Add(m_prefab))
			{
				PackBeastsPlugin.Log.LogInfo((object)("Seat: on the " + m_prefab + ", " + text + "."));
			}
			return text;
		}
		catch (Exception ex)
		{
			PackBeastsPlugin.Log.LogDebug((object)("Seat: measuring the back from the baked mesh failed: " + ex.Message));
			return "baked mesh unavailable (" + ex.GetType().Name + "), using the guess";
		}
	}

	private void MovedSeat(Vector3 delta)
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: 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_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		Transform val = (((Object)(object)m_spot.GripBone != (Object)null) ? m_spot.GripBone : m_spot.SeatBone);
		if ((Object)(object)val != (Object)null)
		{
			m_spot.GripLocal = val.InverseTransformPoint(val.TransformPoint(m_spot.GripLocal) + delta);
		}
		if ((Object)(object)m_grip != (Object)null)
		{
			Transform transform = m_grip.transform;
			transform.position += delta;
		}
		float num = m_spot.SeatRoot.y + m_offset.y;
		m_sadle.m_detachOffset = new Vector3(0f - (m_spot.HalfWidth + 0.5f), (num < 1.5f) ? 0.2f : (1f - num), 0f);
		m_tame.m_dropSaddleOffset = new Vector3(0f, m_spot.SeatRoot.y + 0.3f, 0f);
		TouchBox(HeadSeat.TouchSpot(m_prefab, m_root, RidingHandles.SpotFor(m_prefab), m_spot));
		SetReach();
	}

	private void NoteRider()
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		bool flag = RiddenByMe();
		if (flag && !m_wasMine)
		{
			try
			{
				string height = BakeHeight();
				float seatUp = (((Object)(object)m_attach != (Object)null) ? (m_attach.position.y - m_root.position.y) : 0f);
				BackSeat.TellOn(m_prefab, RidingHandles.SpotFor(m_prefab), m_spot, seatUp, m_backMoved, SteadyBack(), height);
			}
			catch (Exception ex)
			{
				PackBeastsPlugin.Log.LogDebug((object)("Seat: the get-on line failed: " + ex.Message));
			}
		}
		m_wasMine = flag;
	}

	private bool SteadySeat()
	{
		if (HeadSeat.Steady != null && HeadSeat.Steady.Value && m_spot != null)
		{
			return HeadSeat.SteadyKind(m_spot.Kind);
		}
		return false;
	}

	private bool RiddenByMe()
	{
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer != (Object)null && (Object)(object)m_sadle != (Object)null)
		{
			return (object)localPlayer.GetDoodadController() == m_sadle;
		}
		return false;
	}

	private void SteadyCamera(Vector3 local, Quaternion body, float dt)
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: 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_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: 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_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: 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_0088: 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_008e: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (!RiddenByMe() || HeadSeat.SteadyCamera == null || !HeadCamera.Ready)
			{
				m_camHave = false;
				return;
			}
			float value = HeadSeat.SteadyCamera.Value;
			if (!m_camHave || value <= 0f)
			{
				m_cam = local;
				m_camVel = Vector3.zero;
				m_camHave = value > 0f;
			}
			else
			{
				m_cam = HeadSeat.CameraStep(m_cam, ref m_camVel, local, dt, value);
			}
			if (m_camHave)
			{
				HeadCamera.Set(body * (m_cam - local));
			}
		}
		catch (Exception ex)
		{
			m_camHave = false;
			if (!s_camFailed)
			{
				s_camFailed = true;
				PackBeastsPlugin.Log.LogWarning((object)("Steady camera on a head failed (reported once): " + ex.Message));
			}
		}
	}

	private void WatchSeat(bool steady, Vector3 bone, Vector3 seat)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (RiddenByMe())
			{
				HeadSeat.Drawing(this);
				HeadSeat.Watch(this, m_root, m_prefab, m_spot, steady, bone, seat, steady && m_camHave, m_cam);
			}
		}
		catch (Exception ex)
		{
			if (!s_watchFailed)
			{
				s_watchFailed = true;
				PackBeastsPlugin.Log.LogDebug((object)("Seat watch failed: " + ex.Message));
			}
		}
	}

	internal bool DrawnGap(out float gap)
	{
		//IL_002e: 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_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: 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)
		gap = 0f;
		Player localPlayer = Player.m_localPlayer;
		if (!RiddenByMe() || (Object)(object)m_attach == (Object)null || m_spot == null)
		{
			return false;
		}
		Vector3 val = m_offset + new Vector3(0f, RidingHandles.SeatUp.Value, RidingHandles.SeatForward.Value);
		gap = Vector3.Distance(((Component)localPlayer).transform.position, ((Component)this).transform.position + m_attach.rotation * val);
		return true;
	}

	internal static void Setup(Tameable tame)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Expected O, but got Unknown
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Expected O, but got Unknown
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_0210: Expected O, but got Unknown
		Sadle val = Template();
		GameObject val2 = new GameObject("anwo_riding_handle");
		val2.SetActive(false);
		int num = LayerMask.NameToLayer("piece_nonsolid");
		if (num >= 0)
		{
			val2.layer = num;
		}
		val2.transform.SetParent(((Component)tame).transform, false);
		RidingHandle ridingHandle = val2.AddComponent<RidingHandle>();
		ridingHandle.m_tame = tame;
		ridingHandle.m_root = ((Component)tame).transform;
		ridingHandle.m_prefab = Utils.GetPrefabName(((Component)tame).gameObject);
		GameObject val3 = new GameObject("anwo_riding_handle_seat");
		val3.transform.SetParent(((Component)tame).transform, false);
		ridingHandle.m_attach = val3.transform;
		Sadle val4 = (ridingHandle.m_sadle = val2.AddComponent<Sadle>());
		val4.m_hoverText = (((Object)(object)RidingHandles.ItemDrop != (Object)null) ? RidingHandles.ItemDrop.m_itemData.m_shared.m_name : "Riding handle");
		val4.m_attachPoint = val3.transform;
		val4.m_detachOffset = new Vector3(0f, 0.3f, 0f);
		val4.m_maxUseRange = (((Object)(object)val != (Object)null) ? val.m_maxUseRange : 6f);
		ridingHandle.m_baseReach = val4.m_maxUseRange;
		val4.m_maxStamina = (((Object)(object)val != (Object)null) ? val.m_maxStamina : 240f);
		val4.m_runStaminaDrain = (((Object)(object)val != (Object)null) ? val.m_runStaminaDrain : 1f);
		val4.m_swimStaminaDrain = (((Object)(object)val != (Object)null) ? val.m_swimStaminaDrain : 5f);
		val4.m_staminaRegen = (((Object)(object)val != (Object)null) ? val.m_staminaRegen : 0.2f);
		val4.m_staminaRegenHungry = (((Object)(object)val != (Object)null) ? val.m_staminaRegenHungry : 0.1f);
		val4.m_drownEffects = (EffectList)(((Object)(object)val != (Object)null && val.m_drownEffects != null) ? ((object)val.m_drownEffects) : ((object)new EffectList()));
		val4.m_mountIcon = (((Object)(object)val != (Object)null) ? val.m_mountIcon : null);
		val4.m_hoverOffset = 0f;
		GameObject val5 = new GameObject("anwo_riding_handle_touch");
		val5.SetActive(false);
		if (num >= 0)
		{
			val5.layer = num;
		}
		val5.transform.SetParent(((Component)tame).transform, false);
		ridingHandle.m_box = val5.AddComponent<BoxCollider>();
		((Collider)ridingHandle.m_box).isTrigger = true;
		val5.AddComponent<HandleTouch>().Saddle = val4;
		ridingHandle.m_touch = val5;
		tame.m_saddle = val4;
		tame.m_saddleItem = RidingHandles.ItemDrop;
		tame.m_dropSaddleOnDeath = true;
		if (tame.m_dropItemVel <= 0f)
		{
			tame.m_dropItemVel = 5f;
		}
		All.Add(ridingHandle);
		if (++s_added % 64 == 0)
		{
			All.RemoveAll((RidingHandle h) => (Object)(object)h == (Object)null);
		}
	}

	private static Sadle Template()
	{
		if ((Object)(object)s_template != (Object)null)
		{
			return s_template;
		}
		GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("Lox") : null);
		s_template = (((Object)(object)val != (Object)null) ? val.GetComponentInChildren<Sadle>(true) : null);
		return s_template;
	}

	internal static void RebuildAll()
	{
		All.RemoveAll((RidingHandle h) => (Object)(object)h == (Object)null);
		foreach (RidingHandle item in All.ToList())
		{
			try
			{
				if (!((Object)(object)item == (Object)null) && item.m_spot != null)
				{
					if ((Object)(object)item.m_sadle != (Object)null && item.m_sadle.HaveValidUser())
					{
						item.m_dirty = true;
					}
					else
					{
						item.Apply();
					}
				}
			}
			catch (Exception ex)
			{
				PackBeastsPlugin.Log.LogDebug((object)("Riding handle rebuild failed: " + ex.Message));
			}
		}
	}

	internal void Apply()
	{
		//IL_019e: 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_01be: 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)
		//IL_0210: Unknown result type (might be due to invalid IL or missing references)
		//IL_0215: Unknown result type (might be due to invalid IL or missing references)
		//IL_0222: 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_0232: 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_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0262: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
		m_dirty = false;
		if ((Object)(object)m_grip != (Object)null)
		{
			Object.DestroyImmediate((Object)(object)m_grip);
		}
		m_grip = null;
		HandleSpot handleSpot = RidingHandles.SpotFor(m_prefab);
		string how;
		HandleSpots.Spot spot = HandleSpots.Find(m_prefab, m_root, handleSpot, out how);
		if (spot == null)
		{
			return;
		}
		m_backMoved = null;
		m_baked = false;
		string note;
		HandleSpots.Spot spot2 = BackSeat.BehindNeck(m_root, spot, out note);
		if (spot2 != null)
		{
			BackSeat.TellMoved(m_prefab, note);
			spot = spot2;
			m_backMoved = note;
		}
		string item = m_prefab + "/" + handleSpot.ToString() + (spot.Metric ? "/whole" : "");
		if (s_told.Add(item))
		{
			PackBeastsPlugin.Log.LogInfo((object)($"Riding handle on {m_prefab}: {handleSpot}, {how}" + (string.IsNullOrEmpty(spot.Measured) ? "" : (" (from " + spot.Measured + ")")) + $", seat on {((Object)spot.SeatBone).name} {spot.SeatRoot.y:0.00} m up, back {spot.HalfWidth * 2f:0.00} m wide, {PoseName(spot)}."));
			if (!string.IsNullOrEmpty(spot.Report))
			{
				PackBeastsPlugin.Log.LogInfo((object)spot.Report);
			}
		}
		Transform seatBone = spot.SeatBone;
		((Component)this).transform.SetParent(seatBone, false);
		((Component)this).transform.localPosition = spot.SeatLocal;
		((Component)this).transform.localRotation = Quaternion.identity;
		((Component)this).transform.localScale = Vector3.one * (Scale(m_root) / Scale(seatBone));
		TouchBox(HeadSeat.TouchSpot(m_prefab, m_root, handleSpot, spot));
		string text = PoseName(spot);
		m_sadle.m_attachAnimation = text;
		Vector3 val = PoseBody(text);
		m_offset = new Vector3(0f, 0.17f - val.y, 0f - val.z);
		m_tame.m_dropSaddleOffset = new Vector3(0f, spot.SeatRoot.y + 0.3f, 0f);
		float num = spot.SeatRoot.y + m_offset.y;
		m_sadle.m_detachOffset = new Vector3(0f - (spot.HalfWidth + 0.5f), (num < 1.5f) ? 0.2f : (1f - num), 0f);
		m_spot = spot;
		if (((Component)this).gameObject.activeSelf)
		{
			ShowGrip();
		}
		Place();
		SetReach();
	}

	internal static float ReachFor(float baseReach, float seatUp)
	{
		return Math.Max(baseReach, seatUp + 3f);
	}

	private void SetReach()
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (!((Object)(object)m_sadle == (Object)null) && !((Object)(object)m_root == (Object)null) && !((Object)(object)m_attach == (Object)null))
			{
				float seatUp = Math.Max(m_attach.position.y, ((Component)this).transform.position.y) - m_root.position.y;
				float num = ReachFor(m_baseReach, seatUp);
				m_sadle.m_maxUseRange = num;
				if (!s_baseReachTold)
				{
					s_baseReachTold = true;
					PackBeastsPlugin.Log.LogInfo((object)("Riding handle: you can get on from up to " + m_baseReach.ToString("0.0", CultureInfo.InvariantCulture) + " m from the seat (" + (((Object)(object)Template() != (Object)null) ? "the lox saddle's reach" : "no lox saddle found") + "); a seat higher than " + (m_baseReach - 3f).ToString("0.0", CultureInfo.InvariantCulture) + " m above a creature's feet gets its height + " + 3f.ToString("0", CultureInfo.InvariantCulture) + " m, so it's always within reach."));
				}
				if (num > m_baseReach && s_reachTold.Count < 100 && s_reachTold.Add(m_prefab))
				{
					PackBeastsPlugin.Log.LogInfo((object)("Riding handle on " + m_prefab + ": its seat is " + seatUp.ToString("0.00", CultureInfo.InvariantCulture) + " m above its feet, so you can get on from up to " + num.ToString("0.00", CultureInfo.InvariantCulture) + " m from the seat (raised from " + m_baseReach.ToString("0.0", CultureInfo.InvariantCulture) + " m)."));
				}
			}
		}
		catch (Exception ex)
		{
			PackBeastsPlugin.Log.LogDebug((object)("Setting the riding handle's reach failed: " + ex.Message));
		}
	}

	private void TouchBox(HandleSpots.Spot spot)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: 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_00de: 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_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)m_box == (Object)null))
		{
			Vector3 seatRoot = spot.SeatRoot;
			float num = Mathf.Max(0.2f, spot.HalfWidth) + 0.2f;
			float num2 = 0.8f;
			float z = seatRoot.z;
			CapsuleCollider component = ((Component)m_root).GetComponent<CapsuleCollider>();
			if ((Object)(object)component != (Object)null && spot.Kind == 's')
			{
				float num3 = ((component.direction == 2) ? Mathf.Max(component.height, 2f * component.radius) : (2f * component.radius));
				num2 = Mathf.Max(0.8f, num3 * 0.75f);
				z = component.center.z;
			}
			float num4 = 0.45f;
			float num5 = Mathf.Clamp(seatRoot.y * 0.3f, 0.15f, 0.35f);
			m_box.center = new Vector3(0f, seatRoot.y + (num4 - num5) * 0.5f, z);
			m_box.size = new Vector3(2f * num, num4 + num5, num2);
			if ((Object)(object)m_touch != (Object)null && ((Component)this).gameObject.activeSelf)
			{
				m_touch.SetActive(true);
			}
		}
	}

	private void ShowGrip()
	{
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: 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_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		if (!RidingHandles.Show.Value || m_spot == null || (Object)(object)m_spot.GripBone == (Object)null)
		{
			if ((Object)(object)m_grip != (Object)null)
			{
				m_grip.SetActive(false);
			}
			return;
		}
		if ((Object)(object)m_grip == (Object)null)
		{
			Materials mats = Materials.For(LeatherBase(m_root));
			m_grip = HandleLook.Build(mats, RidingHandles.Size.Value, m_spot.GripHeight);
			((Object)m_grip).name = "anwo_riding_handle_grip";
			m_grip.transform.SetParent(m_spot.GripBone, false);
			m_grip.transform.localPosition = m_spot.GripLocal;
			m_grip.transform.localRotation = m_spot.GripRot;
			float num = (m_spot.Metric ? 1f : Scale(m_root));
			m_grip.transform.localScale = Vector3.one * (num / Scale(m_spot.GripBone));
			Transform seatBone = m_spot.SeatBone;
			if ((Object)(object)seatBone != (Object)null && (Object)(object)seatBone != (Object)(object)m_spot.GripBone && HandleSpots.IsHead(m_spot.GripBone))
			{
				m_grip.transform.SetParent(seatBone, true);
				m_grip.transform.localScale = Vector3.one * (num / Scale(seatBone));
			}
			m_gripLocal = m_grip.transform.localRotation;
			m_gripSmooth = Quaternion.Inverse(m_root.rotation) * m_grip.transform.rotation;
			m_gripSteady = true;
			FindParts();
		}
		m_grip.SetActive(true);
	}

	private static float Scale(Transform t)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Abs(t.lossyScale.x);
		if (!(num > 1E-06f))
		{
			return 1f;
		}
		return num;
	}

	private static Material LeatherBase(Transform root)
	{
		Renderer val = (Renderer)(object)((IEnumerable<SkinnedMeshRenderer>)((Component)root).GetComponentsInChildren<SkinnedMeshRenderer>(true)).FirstOrDefault((Func<SkinnedMeshRenderer, bool>)((SkinnedMeshRenderer x) => (Object)(object)((Renderer)x).sharedMaterial != (Object)null));
		if (!((Object)(object)val != (Object)null))
		{
			return null;
		}
		return val.sharedMaterial;
	}

	internal static string PoseName(HandleSpots.Spot spot)
	{
		return RidingHandles.Pose.Value switch
		{
			RiderPose.Lox => "attach_lox", 
			RiderPose.Moose => "attach_moose", 
			RiderPose.Asksvin => "attach_asksvin", 
			_ => spot.Pose, 
		};
	}

	internal static Vector3 PoseBody(string pose)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		return BodyFit.PoseBody(pose);
	}

	internal static float PoseFeet(string pose)
	{
		return BodyFit.PoseFeet(pose);
	}

	internal void PlaceThisFrame()
	{
		if (m_placedFrame != Time.frameCount)
		{
			Place();
		}
	}

	private void Place()
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: 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_00af: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: 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_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: 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_0139: 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_0148: 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_015b: 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_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: 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_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: 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_0256: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0271: Unknown result type (might be due to invalid IL or missing references)
		//IL_0273: Unknown result type (might be due to invalid IL or missing references)
		//IL_0278: Unknown result type (might be due to invalid IL or missing references)
		//IL_027d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0282: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0289: Unknown result type (might be due to invalid IL or missing references)
		//IL_028e: 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_01f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_022d: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)m_attach == (Object)null || (Object)(object)m_root == (Object)null)
		{
			return;
		}
		m_placedFrame = Time.frameCount;
		NoteRider();
		Quaternion rotation = m_root.rotation;
		float deltaTime = Time.deltaTime;
		if (!m_seatHave)
		{
			m_turnSmooth = rotation;
		}
		else if (deltaTime > 0f)
		{
			float num = Quaternion.Angle(m_turnSmooth, rotation);
			float num2 = Mathf.Lerp(0.12f, 0.03f, Mathf.Clamp01(num / 15f));
			m_turnSmooth = Quaternion.Slerp(m_turnSmooth, rotation, 1f - Mathf.Exp((0f - deltaTime) / num2));
		}
		Quaternion turnSmooth = m_turnSmooth;
		Vector3 val = m_offset + new Vector3(0f, RidingHandles.SeatUp.Value, RidingHandles.SeatForward.Value);
		Vector3 val2 = Quaternion.Inverse(rotation) * (((Component)this).transform.position - m_root.position);
		if (SteadySeat())
		{
			m_seatSmooth = val2;
			m_seatHave = true;
			HeadSeat.OnHead(((Component)this).transform.position, turnSmooth, val, out var at, out var facing);
			SteadyCamera(val2, rotation, deltaTime);
			WatchSeat(steady: true, val2, val2);
			m_attach.SetPositionAndRotation(at, facing);
			return;
		}
		if (SteadyBack())
		{
			PlaceBack(val2, rotation, turnSmooth, val, deltaTime);
			return;
		}
		m_camHave = false;
		if (m_seatHave)
		{
			Vector3 val3 = val2 - m_seatSmooth;
			if (!(((Vector3)(ref val3)).sqrMagnitude > 1f))
			{
				if (deltaTime > 0f)
				{
					m_seatSmooth.x = Mathf.Lerp(m_seatSmooth.x, val2.x, 1f - Mathf.Exp((0f - deltaTime) / 0.6f));
					m_seatSmooth.y = Mathf.Lerp(m_seatSmooth.y, val2.y, 1f - Mathf.Exp((0f - deltaTime) / 0.12f));
					m_seatSmooth.z = Mathf.Lerp(m_seatSmooth.z, val2.z, 1f - Mathf.Exp((0f - deltaTime) / 0.08f));
				}
				goto IL_0251;
			}
		}
		m_seatSmooth = val2;
		m_seatHave = true;
		goto IL_0251;
		IL_0251:
		WatchSeat(steady: false, val2, m_seatSmooth);
		m_attach.SetPositionAndRotation(m_root.position + rotation * m_seatSmooth + turnSmooth * val, turnSmooth);
	}

	private void LateUpdate()
	{
		if (m_spot == null || (m_dirty && (Object)(object)m_sadle != (Object)null && !m_sadle.HaveValidUser()))
		{
			try
			{
				Apply();
			}
			catch (Exception ex)
			{
				PackBeastsPlugin.Log.LogWarning((object)("Placing the riding handle on " + m_prefab + " failed: " + ex.Message));
				((Behaviour)this).enabled = false;
				return;
			}
		}
		PlaceThisFrame();
		Steady();
		HoldNow();
	}

	private void Steady()
	{
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: 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_0069: 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_0073: 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_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		if (m_gripSteady && !((Object)(object)m_grip == (Object)null) && m_grip.activeSelf && !((Object)(object)m_root == (Object)null))
		{
			Transform parent = m_grip.transform.parent;
			if (!((Object)(object)parent == (Object)null))
			{
				Quaternion val = Quaternion.Inverse(m_root.rotation) * (parent.rotation * m_gripLocal);
				m_gripSmooth = Quaternion.Slerp(m_gripSmooth, val, 1f - Mathf.Exp((0f - Time.deltaTime) / 0.45f));
				m_grip.transform.rotation = m_root.rotation * m_gripSmooth;
			}
		}
	}

	private void OnEnable()
	{
		if (m_spot != null)
		{
			if ((Object)(object)m_touch != (Object)null)
			{
				m_touch.SetActive(true);
			}
			Place();
			ShowGrip();
		}
	}

	private void OnDisable()
	{
		Riders.Remove(this);
		Rest();
		if ((Object)(object)m_grip != (Object)null)
		{
			m_grip.SetActive(false);
		}
		if ((Object)(object)m_touch != (Object)null)
		{
			m_touch.SetActive(false);
		}
	}

	private void OnDestroy()
	{
		All.Remove(this);
		Riders.Remove(this);
		if ((Object)(object)m_grip != (Object)null)
		{
			Object.Destroy((Object)(object)m_grip);
		}
		if ((Object)(object)m_attach != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)m_attach).gameObject);
		}
		if ((Object)(object)m_touch != (Object)null)
		{
			Object.Destroy((Object)(object)m_touch);
		}
	}

	private void FindParts()
	{
		//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_0180: 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_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		m_parts = m_grip.transform.Find("parts");
		m_bar = (((Object)(object)m_parts != (Object)null) ? m_parts.Find("bar") : null);
		m_barGrip = (((Object)(object)m_bar != (Object)null) ? m_bar.Find("grip") : null);
		m_capL = (((Object)(object)m_bar != (Object)null) ? m_bar.Find("capL") : null);
		m_capR = (((Object)(object)m_bar != (Object)null) ? m_bar.Find("capR") : null);
		m_strapL = (((Object)(object)m_parts != (Object)null) ? m_parts.Find("strapL") : null);
		m_strapR = (((Object)(object)m_parts != (Object)null) ? m_parts.Find("strapR") : null);
		m_held = false;
		if ((Object)(object)m_bar == (Object)null || (Object)(object)m_barGrip == (Object)null || (Object)(object)m_capL == (Object)null || (Object)(object)m_capR == (Object)null || (Object)(object)m_strapL == (Object)null || (Object)(object)m_strapR == (Object)null)
		{
			m_bar = null;
			return;
		}
		m_barPos = m_bar.localPosition;
		m_barRot = m_bar.localRotation;
		m_barGripScale = m_barGrip.localScale;
		m_capLPos = m_capL.localPosition;
		m_capRPos = m_capR.localPosition;
		m_strapLPos = m_strapL.localPosition;
		m_strapRPos = m_strapR.localPosition;
		m_strapRot = m_strapL.localRotation;
		m_strapScale = m_strapL.localScale;
		m_strapRest = HandleLook.StrapLength((m_spot != null) ? m_spot.GripHeight : 0.16f);
	}

	private void HoldNow()
	{
		if (RidingHandles.Hold == null || !RidingHandles.Hold.Value || !((Object)(object)m_bar != (Object)null) || !((Object)(object)m_grip != (Object)null) || !m_grip.activeInHierarchy || !((Object)(object)m_sadle != (Object)null) || !m_sadle.HaveValidUser())
		{
			if (Riders.Remove(this) || m_held)
			{
				Rest();
			}
			return;
		}
		Hook();
		Riders.Add(this);
		if (!HoldBy(Rider()))
		{
			Rest();
		}
	}

	private static void Hook()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Expected O, but got Unknown
		if (!s_hooked)
		{
			s_hooked = true;
			Camera.onPreCull = (CameraCallback)Delegate.Combine((Delegate?)(object)Camera.onPreCull, (Delegate?)new CameraCallback(BeforeDrawing));
		}
	}

	private static void BeforeDrawing(Camera cam)
	{
		if (Time.frameCount == s_heldFrame || Riders.Count == 0)
		{
			return;
		}
		s_heldFrame = Time.frameCount;
		foreach (RidingHandle item in Riders.ToList())
		{
			try
			{
				if ((Object)(object)item == (Object)null)
				{
					Riders.Remove(item);
				}
				else
				{
					item.HoldNow();
				}
			}
			catch (Exception ex)
			{
				PackBeastsPlugin.Log.LogDebug((object)("Holding the riding handle failed: " + ex.Message));
			}
		}
	}

	private Player Rider()
	{
		//IL_009c: 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)
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer != (Object)null && (object)localPlayer.GetDoodadController() == m_sadle)
		{
			return localPlayer;
		}
		if ((Object)(object)m_rider != (Object)null && Time.time < m_riderAt)
		{
			return m_rider;
		}
		m_riderAt = Time.time + 0.5f;
		m_rider = null;
		if ((Object)(object)m_attach == (Object)null)
		{
			return null;
		}
		float num = 1.2f;
		foreach (Player allPlayer in Player.GetAllPlayers())
		{
			if (!((Object)(object)allPlayer == (Object)null) && !((Object)(object)allPlayer == (Object)(object)localPlayer))
			{
				float num2 = Vector3.Distance(((Component)allPlayer).transform.position, m_attach.position);
				if (num2 < num)
				{
					num = num2;
					m_rider = allPlayer;
				}
			}
		}
		return m_rider;
	}

	private bool HoldBy(Player rider)
	{
		//IL_0061: 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_0081: 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_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: 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_00a0: 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_00c0: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: 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_00ff: 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_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: 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_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: 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_0147: 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_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: 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_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: 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_0193: 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_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_0241: Unknown result type (might be due to invalid IL or missing references)
		//IL_0288: Unknown result type (might be due to invalid IL or missing references)
		//IL_028d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		VisEquipment val = (((Object)(object)rider != (Object)null) ? ((Component)rider).GetComponent<VisEquipment>() : null);
		Transform val2 = (((Object)(object)val != (Object)null) ? val.m_leftHand : null);
		Transform val3 = (((Object)(object)val != (Object)null) ? val.m_rightHand : null);
		if ((Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null || (Object)(object)m_parts == (Object)null)
		{
			return false;
		}
		float num = Mathf.Abs(m_parts.lossyScale.x);
		if (num < 0.0001f)
		{
			return false;
		}
		Vector3 position = val2.position;
		Vector3 position2 = val3.position;
		Vector3 val4 = (position + position2) * 0.5f;
		float num2 = Vector3.Distance(position, position2);
		Vector3 val5 = m_parts.TransformPoint(new Vector3(0f, 0.012f, 0f));
		if (num2 > 0.9f || Vector3.Distance(val4, val5) > 1f)
		{
			return false;
		}
		Vector3 val6 = ((num2 > 0.02f) ? ((position2 - position) / num2) : m_parts.right);
		Vector3 val7 = val4 - val5;
		val7 = ((((Vector3)(ref val7)).sqrMagnitude > 0.0001f) ? ((Vector3)(ref val7)).normalized : m_parts.up);
		Vector3 val8 = Vector3.Cross(val6, val7);
		if (((Vector3)(ref val8)).sqrMagnitude < 0.0001f)
		{
			val8 = Vector3.Cross(val6, m_parts.up);
		}
		if (((Vector3)(ref val8)).sqrMagnitude < 0.0001f)
		{
			return false;
		}
		((Vector3)(ref val8)).Normalize();
		val7 = Vector3.Cross(val8, val6);
		m_bar.SetPositionAndRotation(val4, Quaternion.LookRotation(val8, val7));
		float num3 = Mathf.Clamp(num2 + 0.09f, 0.23f * num, 0.99f) / num;
		m_barGrip.localScale = new Vector3(m_barGripScale.x * num3 / 0.23f, m_barGripScale.y, m_barGripScale.z);
		m_capL.localPosition = new Vector3(0f - (num3 * 0.5f - 0.003f), 0f, 0f);
		m_capR.localPosition = new Vector3(num3 * 0.5f - 0.003f, 0f, 0f);
		float num4 = Mathf.Clamp(num2 / num * 0.5f - 0.06f, 0.04f, 0.085f);
		Strap(m_strapL, m_parts.TransformPoint(new Vector3(-0.085f, 0.012f, 0f)), m_bar.TransformPoint(new Vector3(0f - num4, 0f, 0f)), num);
		Strap(m_strapR, m_parts.TransformPoint(new Vector3(0.085f, 0.012f, 0f)), m_bar.TransformPoint(new Vector3(num4, 0f, 0f)), num);
		m_held = true;
		return true;
	}

	private void Strap(Transform strap, Vector3 from, Vector3 to, float s)
	{
		//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_0019: 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_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: 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_006c: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = to - from;
		float magnitude = ((Vector3)(ref val)).magnitude;
		if (!(magnitude < 0.005f))
		{
			Vector3 val2 = val / magnitude;
			Vector3 val3 = Vector3.ProjectOnPlane(m_parts.forward, val2);
			if (((Vector3)(ref val3)).sqrMagnitude < 0.0001f)
			{
				val3 = Vector3.ProjectOnPlane(m_parts.right, val2);
			}
			strap.SetPositionAndRotation((from + to) * 0.5f, Quaternion.LookRotation(((Vector3)(ref val3)).normalized, val2));
			strap.localScale = new Vector3(m_strapScale.x, m_strapScale.y * (magnitude / s) / m_strapRest, m_strapScale.z);
		}
	}

	private void Rest()
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: 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_005f: 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_0081: Unknown result