Decompiled source of BuminCamera v1.4.1

plugins/BuminCamera.dll

Decompiled 5 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.PostProcessing;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace BuminCamera;

internal static class AimPitch
{
	private sealed class Rig
	{
		public Animator Animator;

		public CharacterAnimEvent AnimEvent;

		public Transform[] Bones;

		public float[] Shares;

		public bool HasBowAim;

		public bool HasDrawPercent;

		public float Weight;

		public float LookFade;

		public Quaternion[] Base;

		public Quaternion[] Bent;

		public bool HasBent;
	}

	private const string BowAim = "bow_aim";

	private const string DrawPercent = "drawpercent";

	private const float BlendTime = 0.18f;

	private static readonly Dictionary<Player, Rig> Rigs = new Dictionary<Player, Rig>();

	private static readonly List<Player> Gone = new List<Player>();

	private static FieldInfo _headLookDir;

	private static FieldInfo _visEquipment;

	private static FieldInfo _leftItem;

	private static int _bowAimHash;

	private static int _drawPercentHash;

	private static float _nextCleanup;

	private static bool _logged;

	internal static void Apply(Harmony harmony)
	{
		_headLookDir = AccessTools.Field(typeof(CharacterAnimEvent), "m_headLookDir");
		_visEquipment = AccessTools.Field(typeof(Humanoid), "m_visEquipment");
		_leftItem = AccessTools.Field(typeof(VisEquipment), "m_leftItemInstance");
		_bowAimHash = Animator.StringToHash("bow_aim");
		_drawPercentHash = Animator.StringToHash("drawpercent");
		Plugin.PatchMethod(harmony, typeof(GameCamera), "LateUpdate", typeof(AimPitch), null, "Bend", 200);
		Plugin.PatchMethod(harmony, typeof(CharacterAnimEvent), "UpdateLookat", typeof(AimPitch), null, "SoftenLook", 400);
	}

	internal static GameObject LeftItem(Player player)
	{
		if (_visEquipment == null || _leftItem == null)
		{
			return null;
		}
		object? value = _visEquipment.GetValue(player);
		VisEquipment val = (VisEquipment)((value is VisEquipment) ? value : null);
		if (!((Object)(object)val != (Object)null))
		{
			return null;
		}
		object? value2 = _leftItem.GetValue(val);
		return (GameObject)((value2 is GameObject) ? value2 : null);
	}

	private static void Bend()
	{
		float deltaTime = Time.deltaTime;
		if (Time.unscaledTime >= _nextCleanup)
		{
			_nextCleanup = Time.unscaledTime + 10f;
			Cleanup();
			BowString.Cleanup();
		}
		bool value = Plugin.Enabled.Value;
		bool flag = value && Plugin.AimBodyPitch.Value;
		bool flag2 = value && Plugin.BowStringPull.Value;
		foreach (Player allPlayer in Player.GetAllPlayers())
		{
			if ((Object)(object)allPlayer == (Object)null)
			{
				continue;
			}
			Rig rig = GetRig(allPlayer);
			if (rig == null)
			{
				continue;
			}
			Undo(rig);
			float draw = Draw(allPlayer, rig);
			float num = ((flag && IsAimingNow(allPlayer, rig)) ? 1f : 0f);
			rig.Weight = Mathf.MoveTowards(rig.Weight, num, deltaTime / 0.18f);
			rig.LookFade = 0f;
			if (rig.Weight > 0.001f)
			{
				float weight = rig.Weight * rig.Weight * (3f - 2f * rig.Weight);
				SaveBase(rig);
				if (flag)
				{
					Pitch(allPlayer, rig, weight);
					rig.LookFade = rig.Weight;
				}
				SaveBent(rig);
			}
			if (flag2)
			{
				BowString.Update(allPlayer, rig.Animator, draw, deltaTime);
			}
			else
			{
				BowString.Release(allPlayer);
			}
		}
	}

	private static float Draw(Player player, Rig rig)
	{
		if (rig.HasDrawPercent)
		{
			return Mathf.Clamp01(rig.Animator.GetFloat(_drawPercentHash));
		}
		if (!((Object)(object)player == (Object)(object)Player.m_localPlayer))
		{
			return 0f;
		}
		return Mathf.Clamp01(((Humanoid)player).GetAttackDrawPercentage());
	}

	private static void Pitch(Player player, Rig rig, float weight)
	{
		//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_0024: 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_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_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = LookDir(player, rig);
		if (!(((Vector3)(ref val)).sqrMagnitude < 0.01f))
		{
			float value = Plugin.AimPitchLimit.Value;
			float num = Mathf.Clamp(Mathf.Asin(Mathf.Clamp(((Vector3)(ref val)).normalized.y, -1f, 1f)) * 57.29578f, 0f - value, value) * Plugin.AimPitchStrength.Value * weight;
			Vector3 right = ((Component)player).transform.right;
			for (int i = 0; i < rig.Bones.Length; i++)
			{
				Transform val2 = rig.Bones[i];
				val2.rotation = Quaternion.AngleAxis((0f - num) * rig.Shares[i], right) * val2.rotation;
			}
		}
	}

	private static void SaveBase(Rig rig)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < rig.Bones.Length; i++)
		{
			ref Quaternion reference = ref rig.Base[i];
			reference = rig.Bones[i].localRotation;
		}
	}

	private static void SaveBent(Rig rig)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < rig.Bones.Length; i++)
		{
			ref Quaternion reference = ref rig.Bent[i];
			reference = rig.Bones[i].localRotation;
		}
		rig.HasBent = true;
	}

	private static void Undo(Rig rig)
	{
		//IL_0027: 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_0051: Unknown result type (might be due to invalid IL or missing references)
		if (!rig.HasBent)
		{
			return;
		}
		rig.HasBent = false;
		for (int i = 0; i < rig.Bones.Length; i++)
		{
			Transform val = rig.Bones[i];
			if ((Object)(object)val != (Object)null && val.localRotation == rig.Bent[i])
			{
				val.localRotation = rig.Base[i];
			}
		}
	}

	private static bool IsAimingNow(Player player, Rig rig)
	{
		bool flag = rig.HasBowAim && rig.Animator.GetBool(_bowAimHash);
		if ((Object)(object)player != (Object)(object)Player.m_localPlayer)
		{
			return flag;
		}
		ItemData currentWeapon = ((Humanoid)player).GetCurrentWeapon();
		if (!Aiming.IsAimWeapon(currentWeapon))
		{
			return false;
		}
		if (!Aiming.IsAiming && !flag && !((Character)player).IsDrawingBow())
		{
			if (((Character)player).InAttack())
			{
				return rig.Weight > 0f;
			}
			return false;
		}
		return true;
	}

	private static Vector3 LookDir(Player player, Rig rig)
	{
		//IL_0062: 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_005c: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)player == (Object)(object)Player.m_localPlayer && (Object)(object)((Character)player).m_eye != (Object)null)
		{
			return ((Character)player).m_eye.forward;
		}
		if (_headLookDir != null && (Object)(object)rig.AnimEvent != (Object)null)
		{
			object value = _headLookDir.GetValue(rig.AnimEvent);
			if (value is Vector3)
			{
				return (Vector3)value;
			}
		}
		return Vector3.zero;
	}

	private static Rig GetRig(Player player)
	{
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Invalid comparison between Unknown and I4
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Invalid comparison between Unknown and I4
		//IL_034d: Unknown result type (might be due to invalid IL or missing references)
		if (Rigs.TryGetValue(player, out var value))
		{
			if ((Object)(object)value.Animator != (Object)null && AllBones(value) && ((Component)value.Bones[0]).gameObject.activeInHierarchy)
			{
				return value;
			}
			Rigs.Remove(player);
		}
		CharacterAnimEvent componentInChildren = ((Component)player).GetComponentInChildren<CharacterAnimEvent>();
		Animator val = (((Object)(object)componentInChildren != (Object)null) ? ((Component)componentInChildren).GetComponent<Animator>() : ((Component)player).GetComponentInChildren<Animator>());
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		List<Transform> list = new List<Transform>();
		List<float> list2 = new List<float>();
		if (val.isHuman)
		{
			Add(list, list2, val.GetBoneTransform((HumanBodyBones)7), 0.25f);
			Add(list, list2, val.GetBoneTransform((HumanBodyBones)8), 0.35f);
			Add(list, list2, val.GetBoneTransform((HumanBodyBones)54), 0.4f);
		}
		if (list.Count == 0)
		{
			Add(list, list2, Find(((Component)val).transform, "Spine"), 0.25f);
			Add(list, list2, Find(((Component)val).transform, "Spine1"), 0.35f);
			Add(list, list2, Find(((Component)val).transform, "Spine2"), 0.4f);
		}
		if (list.Count == 0)
		{
			if (!_logged)
			{
				_logged = true;
				Plugin.Log.LogWarning((object)"Aim body pitch: no spine bones found on the player model; the bow will not follow the crosshair.");
			}
			return null;
		}
		float num = 0f;
		foreach (float item in list2)
		{
			float num2 = item;
			num += num2;
		}
		for (int i = 0; i < list2.Count; i++)
		{
			list2[i] /= num;
		}
		bool flag = false;
		bool flag2 = false;
		AnimatorControllerParameter[] parameters = val.parameters;
		foreach (AnimatorControllerParameter val2 in parameters)
		{
			if (val2.nameHash == _bowAimHash && (int)val2.type == 4)
			{
				flag = true;
			}
			else if (val2.nameHash == _drawPercentHash && (int)val2.type == 1)
			{
				flag2 = true;
			}
		}
		Rig rig = new Rig();
		rig.Animator = val;
		rig.AnimEvent = componentInChildren;
		rig.Bones = list.ToArray();
		rig.Shares = list2.ToArray();
		rig.HasBowAim = flag;
		rig.HasDrawPercent = flag2;
		rig.Base = (Quaternion[])(object)new Quaternion[list.Count];
		rig.Bent = (Quaternion[])(object)new Quaternion[list.Count];
		value = rig;
		Rigs[player] = value;
		if (!_logged)
		{
			_logged = true;
			List<string> list3 = new List<string>();
			Transform[] bones = value.Bones;
			foreach (Transform val3 in bones)
			{
				list3.Add(((Object)val3).name);
			}
			Plugin.Log.LogInfo((object)string.Concat("Aim body pitch: bends ", string.Join(", ", list3.ToArray()), " (humanoid ", val.isHuman, ", bow_aim ", flag, ", drawpercent ", flag2, ", update mode ", val.updateMode, ")."));
		}
		return value;
	}

	private static bool AllBones(Rig rig)
	{
		Transform[] bones = rig.Bones;
		foreach (Transform val in bones)
		{
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
		}
		return rig.Bones.Length > 0;
	}

	private static void Add(List<Transform> bones, List<float> shares, Transform bone, float share)
	{
		if ((Object)(object)bone != (Object)null && !bones.Contains(bone))
		{
			bones.Add(bone);
			shares.Add(share);
		}
	}

	internal static Transform Find(Transform root, string name)
	{
		if (((Object)root).name == name)
		{
			return root;
		}
		for (int i = 0; i < root.childCount; i++)
		{
			Transform val = Find(root.GetChild(i), name);
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
		}
		return null;
	}

	private static void Cleanup()
	{
		Gone.Clear();
		foreach (KeyValuePair<Player, Rig> rig in Rigs)
		{
			if ((Object)(object)rig.Key == (Object)null)
			{
				Gone.Add(rig.Key);
			}
		}
		foreach (Player item in Gone)
		{
			Rigs.Remove(item);
		}
	}

	private static void SoftenLook(Character ___m_character, Animator ___m_animator, Transform ___m_head, bool ___m_headRotation, float ___m_lookAtWeight, float ___m_bodyLookWeight, float ___m_headLookWeight, float ___m_eyeLookWeight, float ___m_lookClamp)
	{
		Player val = (Player)(object)((___m_character is Player) ? ___m_character : null);
		if (___m_headRotation && !((Object)(object)___m_head == (Object)null) && !((Object)(object)___m_animator == (Object)null) && !((Object)(object)val == (Object)null) && Rigs.TryGetValue(val, out var value) && !(value.LookFade <= 0.001f))
		{
			float num = 1f - value.LookFade;
			float num2 = (((Character)val).IsAttached() ? 0f : ___m_bodyLookWeight);
			___m_animator.SetLookAtWeight(___m_lookAtWeight * num, num2 * num, ___m_headLookWeight * num, ___m_eyeLookWeight, ___m_lookClamp);
		}
	}
}
internal static class Aiming
{
	private sealed class Spread
	{
		public Attack Attack;

		public float Accuracy;

		public float AccuracyMin;

		public Attack Ammo;

		public float AmmoAccuracy;

		public float AmmoAccuracyMin;
	}

	private const float AimRange = 300f;

	private const float MinAimDot = 0.5f;

	internal static bool IsAiming;

	private static bool _toggled;

	private static bool _poseOwned;

	private static string _poseState;

	private static ItemData _poseWeapon;

	private static int _aimMask;

	private static FieldInfo _zanim;

	private static FieldInfo _animator;

	private static FieldInfo _ammoItem;

	private static FieldInfo _drawPercent;

	private static FieldInfo _accuracy;

	private static FieldInfo _accuracyMin;

	private static FieldInfo _velocity;

	private static FieldInfo _velocityMin;

	private static FieldInfo _drawCurve;

	private static FieldInfo _randomVelocity;

	private static FieldInfo _launchAngle;

	private static FieldInfo _bowDraw;

	private static FieldInfo _projectile;

	private static readonly Dictionary<string, bool> KnownBools = new Dictionary<string, bool>();

	internal static void Apply(Harmony harmony)
	{
		_zanim = AccessTools.Field(typeof(Character), "m_zanim");
		_animator = AccessTools.Field(typeof(Character), "m_animator");
		_ammoItem = AccessTools.Field(typeof(Attack), "m_ammoItem");
		_drawPercent = AccessTools.Field(typeof(Attack), "m_attackDrawPercentage");
		_accuracy = AccessTools.Field(typeof(Attack), "m_projectileAccuracy");
		_accuracyMin = AccessTools.Field(typeof(Attack), "m_projectileAccuracyMin");
		_velocity = AccessTools.Field(typeof(Attack), "m_projectileVel");
		_velocityMin = AccessTools.Field(typeof(Attack), "m_projectileVelMin");
		_drawCurve = AccessTools.Field(typeof(Attack), "m_drawVelocityCurve");
		_randomVelocity = AccessTools.Field(typeof(Attack), "m_randomVelocity");
		_launchAngle = AccessTools.Field(typeof(Attack), "m_launchAngle");
		_bowDraw = AccessTools.Field(typeof(Attack), "m_bowDraw");
		_projectile = AccessTools.Field(typeof(Attack), "m_attackProjectile");
		PatchSpread(harmony);
		_aimMask = LayerMask.GetMask(new string[12]
		{
			"Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "terrain", "vehicle", "character", "character_net", "character_ghost",
			"hitbox", "character_noenv"
		});
		Plugin.PatchMethod(harmony, typeof(Player), "SetControls", typeof(Aiming), "ReadControls", null, 200);
		Plugin.PatchMethod(harmony, typeof(Humanoid), "GetAttackSpeedFactorMovement", typeof(Aiming), null, "SlowWhileAiming", 0);
		Plugin.PatchMethod(harmony, typeof(Player), "AlwaysRotateCamera", typeof(Aiming), null, "FaceWhileAiming", 0);
		Plugin.PatchMethod(harmony, typeof(Player), "SetMouseLook", typeof(Aiming), "ScaleLook", null, 400);
		Plugin.PatchMethod(harmony, typeof(Attack), "FireProjectileBurst", typeof(Aiming), null, "KickOnShot", 400);
		Plugin.PatchMethod(harmony, typeof(Attack), "GetProjectileSpawnPoint", typeof(Aiming), null, "AimAtCrosshair", 0);
	}

	internal static bool IsAimWeapon(ItemData item)
	{
		//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_0025: Invalid comparison between Unknown and I4
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Invalid comparison between Unknown and I4
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Invalid comparison between Unknown and I4
		if (item == null || item.m_shared == null)
		{
			return false;
		}
		SharedData shared = item.m_shared;
		if ((int)shared.m_skillType == 8 || (int)shared.m_skillType == 14 || (int)shared.m_itemType == 4)
		{
			return true;
		}
		if (Plugin.AimWithStaffs.Value && (int)shared.m_skillType == 9 && shared.m_attack != null)
		{
			return (int)shared.m_attack.m_attackType == 2;
		}
		return false;
	}

	internal static float AimTarget(Player player)
	{
		if (IsAiming)
		{
			return 1f;
		}
		if (((Character)player).IsDrawingBow())
		{
			return Plugin.DrawZoom.Value;
		}
		return 0f;
	}

	private static bool CanAim(Player player, ItemData weapon)
	{
		if (Plugin.Enabled.Value && Plugin.RightClickAims.Value && IsAimWeapon(weapon) && !((Character)player).InPlaceMode() && !((Character)player).IsAttached() && !((Character)player).IsDead())
		{
			return !((Character)player).InIntro();
		}
		return false;
	}

	private static void ReadControls(Player __instance, Vector3 movedir, ref bool block, ref bool blockHold, ref bool run, ref bool jump)
	{
		if ((Object)(object)__instance == (Object)null || (Object)(object)__instance != (Object)(object)Player.m_localPlayer)
		{
			return;
		}
		if (!CanAim(__instance, ((Humanoid)__instance).GetCurrentWeapon()))
		{
			IsAiming = false;
			_toggled = false;
			return;
		}
		bool flag;
		if (Plugin.AimButton.Value == AimButtonMode.Toggle)
		{
			if (block)
			{
				_toggled = !_toggled;
			}
			flag = _toggled;
		}
		else
		{
			flag = blockHold;
		}
		if (flag && run && ((Vector3)(ref movedir)).sqrMagnitude > 0.01f)
		{
			if (Plugin.SprintWhileAiming.Value == SprintRule.EndsAim)
			{
				flag = false;
				_toggled = false;
			}
			else
			{
				run = false;
			}
		}
		block = false;
		blockHold = false;
		if (flag && jump && Plugin.JumpDodges.Value)
		{
			blockHold = true;
		}
		IsAiming = flag;
	}

	private static void SlowWhileAiming(Humanoid __instance, ref float __result)
	{
		if (IsAiming && !((Object)(object)__instance == (Object)null) && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && !((Character)__instance).InDodge())
		{
			float value = Plugin.AimMoveSpeed.Value;
			if (__result > value)
			{
				__result = value;
			}
		}
	}

	private static void FaceWhileAiming(Player __instance, ref bool __result)
	{
		if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && (FpsCamera.Active || (IsAiming && Plugin.FaceCrosshair.Value) || CrossbowStrafe(__instance)))
		{
			__result = true;
		}
	}

	private static bool CrossbowStrafe(Player player)
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Invalid comparison between Unknown and I4
		if (!Plugin.CrossbowStrafing.Value || !Plugin.Enabled.Value)
		{
			return false;
		}
		ItemData currentWeapon = ((Humanoid)player).GetCurrentWeapon();
		if (currentWeapon == null || currentWeapon.m_shared == null || (int)currentWeapon.m_shared.m_skillType != 14)
		{
			return false;
		}
		if (!((Character)player).IsSwimming() && !((Character)player).IsRiding() && !((Character)player).IsAttached() && !((Character)player).InPlaceMode())
		{
			return !((Character)player).IsDead();
		}
		return false;
	}

	private static void ScaleLook(Player __instance, ref Vector2 mouseLook)
	{
		//IL_003a: 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_0054: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && !(TpsCamera.AimBlend < 0.01f))
		{
			float num = (FpsCamera.Active ? Plugin.FpAimSensitivity.Value : Plugin.AimSensitivity.Value);
			mouseLook *= Mathf.Lerp(1f, num, TpsCamera.AimBlend);
		}
	}

	private static void KickOnShot(Humanoid ___m_character, ItemData ___m_weapon)
	{
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Invalid comparison between Unknown and I4
		if ((Object)(object)___m_character == (Object)null || (Object)(object)___m_character != (Object)(object)Player.m_localPlayer || !TpsCamera.Active || !IsAimWeapon(___m_weapon))
		{
			return;
		}
		Crosshair.Kick();
		Viewmodel.OnShot(___m_weapon);
		float num = Plugin.ShotKick.Value * (FpsCamera.Active ? Plugin.FpShake.Value : 1f);
		if (num <= 0f)
		{
			return;
		}
		if ((int)___m_weapon.m_shared.m_skillType == 14)
		{
			if (!Plugin.CrossbowShotKick.Value)
			{
				return;
			}
			num *= 1.6f;
		}
		TpsCamera.AddKick(num);
	}

	internal static void UpdatePose(Player player)
	{
		if (_zanim == null)
		{
			return;
		}
		ItemData val = null;
		string text = null;
		if ((Object)(object)player != (Object)null)
		{
			val = ((Humanoid)player).GetCurrentWeapon();
			if (val != null && val.m_shared != null && val.m_shared.m_attack != null)
			{
				text = val.m_shared.m_attack.m_drawAnimationState;
			}
		}
		bool flag = (Object)(object)player != (Object)null && IsAiming && Plugin.AimPose.Value && !string.IsNullOrEmpty(text) && val.m_shared.m_attack.m_bowDraw && !((Character)player).InAttack() && !((Character)player).IsDrawingBow() && !((Character)player).InDodge() && !((Character)player).IsDead() && !((Character)player).InMinorAction();
		if (_poseOwned && (!flag || val != _poseWeapon))
		{
			if ((Object)(object)player != (Object)null && (val != _poseWeapon || !((Character)player).IsDrawingBow()))
			{
				object? value = _zanim.GetValue(player);
				ZSyncAnimation val2 = (ZSyncAnimation)((value is ZSyncAnimation) ? value : null);
				if ((Object)(object)val2 != (Object)null)
				{
					val2.SetBool(_poseState, false);
				}
			}
			_poseOwned = false;
		}
		if (!flag)
		{
			if ((Object)(object)player == (Object)null)
			{
				_poseOwned = false;
			}
			return;
		}
		object? value2 = _zanim.GetValue(player);
		ZSyncAnimation val3 = (ZSyncAnimation)((value2 is ZSyncAnimation) ? value2 : null);
		Animator val4 = (Animator)((_animator == null) ? null : /*isinst with value type is only supported in some contexts*/);
		if (!((Object)(object)val3 == (Object)null) && !((Object)(object)val4 == (Object)null) && HasBool(val4, text))
		{
			if (!val4.GetBool(text))
			{
				val3.SetBool(text, true);
				val3.SetFloat("drawpercent", 0f);
			}
			_poseOwned = true;
			_poseState = text;
			_poseWeapon = val;
		}
	}

	private static bool HasBool(Animator animator, string name)
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Invalid comparison between Unknown and I4
		if (KnownBools.TryGetValue(name, out var value))
		{
			return value;
		}
		value = false;
		AnimatorControllerParameter[] parameters = animator.parameters;
		foreach (AnimatorControllerParameter val in parameters)
		{
			if (val.name == name && (int)val.type == 4)
			{
				value = true;
				break;
			}
		}
		KnownBools[name] = value;
		Plugin.Log.LogInfo((object)("Aim pose: draw state \"" + name + "\" " + (value ? "found" : "not in the player's animator, no pose for it") + "."));
		return value;
	}

	private static void AimAtCrosshair(Attack __instance, Humanoid ___m_character, bool ___m_useCharacterFacing, ref Vector3 __0, ref Vector3 __1)
	{
		//IL_013b: 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_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: 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_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_006b: 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_0076: 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_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: 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_00b3: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		if (!TpsCamera.Active || !Plugin.ShotsToCrosshair.Value || ___m_useCharacterFacing)
		{
			return;
		}
		Player val = (Player)(object)((___m_character is Player) ? ___m_character : null);
		GameCamera instance = GameCamera.instance;
		if ((Object)(object)val == (Object)null || (Object)(object)val != (Object)(object)Player.m_localPlayer || (Object)(object)instance == (Object)null || (Object)(object)((Character)val).m_eye == (Object)null)
		{
			return;
		}
		Vector3 position = ((Component)instance).transform.position;
		Vector3 forward = ((Component)instance).transform.forward;
		bool found;
		Vector3 val2 = CrosshairPoint(val, position, forward, out found);
		Vector3 val3 = val2 - __0;
		if (((Vector3)(ref val3)).sqrMagnitude < 0.01f)
		{
			return;
		}
		((Vector3)(ref val3)).Normalize();
		if (Vector3.Dot(val3, __1) < 0.5f)
		{
			return;
		}
		__1 = val3;
		if (found && Plugin.DropCompensation.Value)
		{
			try
			{
				if (Solve(__instance, __0, val2, out var aim) && Vector3.Dot(aim, val3) > Mathf.Cos((float)Math.PI / 6f))
				{
					__1 = aim;
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Aim: drop compensation failed and is skipped for this shot: " + ex.Message));
			}
		}
		float num = Get(_launchAngle, __instance, 0f);
		if (Mathf.Abs(num) > 0.001f)
		{
			Vector3 val4 = Vector3.Cross(Vector3.up, __1);
			if (((Vector3)(ref val4)).sqrMagnitude > 1E-06f)
			{
				__1 = Quaternion.AngleAxis(0f - num, val4) * __1;
			}
		}
	}

	private static T Get<T>(FieldInfo field, object owner, T fallback)
	{
		if (field == null || owner == null)
		{
			return fallback;
		}
		object value = field.GetValue(owner);
		if (!(value is T))
		{
			return fallback;
		}
		return (T)value;
	}

	private static bool Solve(Attack attack, Vector3 spawn, Vector3 target, out Vector3 aim)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: 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_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: 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_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: 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_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0211: Unknown result type (might be due to invalid IL or missing references)
		//IL_0216: Unknown result type (might be due to invalid IL or missing references)
		//IL_021b: Unknown result type (might be due to invalid IL or missing references)
		//IL_021d: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0221: Unknown result type (might be due to invalid IL or missing references)
		//IL_0226: Unknown result type (might be due to invalid IL or missing references)
		//IL_024b: Unknown result type (might be due to invalid IL or missing references)
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_024e: 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_0257: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: Unknown result type (might be due to invalid IL or missing references)
		aim = Vector3.zero;
		GameObject val = Get<GameObject>(_projectile, attack, null);
		float num = Get(_velocity, attack, 0f);
		float num2 = Get(_velocityMin, attack, 0f);
		AnimationCurve val2 = Get<AnimationCurve>(_drawCurve, attack, null);
		ItemData val3 = Get<ItemData>(_ammoItem, attack, null);
		if (val3 != null && val3.m_shared != null && val3.m_shared.m_attack != null)
		{
			Attack attack2 = val3.m_shared.m_attack;
			GameObject val4 = Get<GameObject>(_projectile, attack2, null);
			if ((Object)(object)val4 != (Object)null)
			{
				val = val4;
				num += Get(_velocity, attack2, 0f);
				num2 += Get(_velocityMin, attack2, 0f);
				val2 = Get<AnimationCurve>(_drawCurve, attack2, null);
			}
		}
		if (Get(_bowDraw, attack, fallback: false))
		{
			float num3 = Get(_drawPercent, attack, 1f);
			float num4 = ((val2 != null && val2.length > 0) ? val2.Evaluate(num3) : num3);
			num = Mathf.Lerp(num2, num, num4);
		}
		else if (Get(_randomVelocity, attack, fallback: false))
		{
			return false;
		}
		if ((Object)(object)val == (Object)null || num < 1f)
		{
			return false;
		}
		Projectile component = val.GetComponent<Projectile>();
		if ((Object)(object)component == (Object)null)
		{
			return false;
		}
		float gravity = component.m_gravity;
		float drag = component.m_drag;
		Vector3 val5 = target - spawn;
		float magnitude = ((Vector3)(ref val5)).magnitude;
		if (magnitude < 2f || magnitude > 250f || (gravity <= 0f && drag <= 0f))
		{
			return false;
		}
		Vector3 val6 = val5 / magnitude;
		float step = ((Time.fixedDeltaTime > 0f) ? Time.fixedDeltaTime : 0.02f);
		Vector3 val7 = target;
		bool flag = false;
		for (int i = 0; i < 6; i++)
		{
			Vector3 val8 = val7 - spawn;
			Vector3 normalized = ((Vector3)(ref val8)).normalized;
			if (!Fly(spawn, normalized * num, gravity, drag, step, val6, magnitude, out var cross))
			{
				break;
			}
			Vector3 val9 = target - cross;
			val9 -= Vector3.Dot(val9, val6) * val6;
			val7 += val9;
			flag = true;
			if (((Vector3)(ref val9)).sqrMagnitude < 0.0004f)
			{
				break;
			}
		}
		if (!flag)
		{
			return false;
		}
		Vector3 val10 = val7 - spawn;
		aim = ((Vector3)(ref val10)).normalized;
		return true;
	}

	private static bool Fly(Vector3 start, Vector3 velocity, float gravity, float drag, float step, Vector3 along, float distance, out Vector3 cross)
	{
		//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)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: 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_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: 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_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_006e: 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_0071: 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_003d: 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_0045: 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_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		cross = start;
		Vector3 val = start;
		float num = 0f;
		for (int i = 0; i < 2500; i++)
		{
			velocity += Vector3.down * (gravity * step);
			float magnitude = ((Vector3)(ref velocity)).magnitude;
			if (magnitude > 0.0001f)
			{
				velocity += -velocity / magnitude * (magnitude * magnitude * drag * step);
			}
			Vector3 val2 = val + velocity * step;
			float num2 = Vector3.Dot(val2 - start, along);
			if (num2 >= distance)
			{
				float num3 = (distance - num) / Mathf.Max(0.0001f, num2 - num);
				cross = Vector3.Lerp(val, val2, Mathf.Clamp01(num3));
				return true;
			}
			if (i > 10 && num2 <= num)
			{
				return false;
			}
			num = num2;
			val = val2;
		}
		return false;
	}

	private static Vector3 CrosshairPoint(Player player, Vector3 origin, Vector3 forward, out bool found)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: 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_003d: 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_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)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Max(0f, Vector3.Dot(((Character)player).m_eye.position - origin, forward));
		float num2 = 300f;
		Vector3 result = origin + forward * 300f;
		found = false;
		RaycastHit[] array = Physics.RaycastAll(origin, forward, 300f, _aimMask, (QueryTriggerInteraction)1);
		for (int i = 0; i < array.Length; i++)
		{
			RaycastHit val = array[i];
			if (!(((RaycastHit)(ref val)).distance <= num) && !(((RaycastHit)(ref val)).distance >= num2) && !((Object)(object)((RaycastHit)(ref val)).collider == (Object)null) && !((Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Player>() == (Object)(object)player))
			{
				num2 = ((RaycastHit)(ref val)).distance;
				result = ((RaycastHit)(ref val)).point;
				found = true;
			}
		}
		return result;
	}

	private static void PatchSpread(Harmony harmony)
	{
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Expected O, but got Unknown
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Expected O, but got Unknown
		try
		{
			MethodInfo methodInfo = AccessTools.Method(typeof(Attack), "FireProjectileBurst", (Type[])null, (Type[])null);
			if (!(methodInfo == null) && !(_accuracy == null) && !(_accuracyMin == null))
			{
				HarmonyMethod val = new HarmonyMethod(typeof(Aiming).GetMethod("TightenSpread", BindingFlags.Static | BindingFlags.NonPublic));
				val.priority = 800;
				HarmonyMethod val2 = val;
				HarmonyMethod val3 = new HarmonyMethod(typeof(Aiming).GetMethod("RestoreSpread", BindingFlags.Static | BindingFlags.NonPublic));
				val3.priority = 0;
				HarmonyMethod val4 = val3;
				harmony.Patch((MethodBase)methodInfo, val2, (HarmonyMethod)null, (HarmonyMethod)null, val4, (HarmonyMethod)null);
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("Could not patch Attack.FireProjectileBurst for the aimed spread: " + ex));
		}
	}

	private static void TightenSpread(Attack __instance, Humanoid ___m_character, out Spread __state)
	{
		__state = null;
		if (__instance == null || !Plugin.Enabled.Value || (Object)(object)___m_character == (Object)null || (Object)(object)___m_character != (Object)(object)Player.m_localPlayer || !TpsCamera.Active)
		{
			return;
		}
		ItemData currentWeapon = ___m_character.GetCurrentWeapon();
		bool flag = Viewmodel.IsCrossbow(currentWeapon) && (IsAiming || TpsCamera.AimBlend >= 0.5f);
		float num = (flag ? Plugin.CrossbowAimedSpread.Value : Plugin.AimedSpread.Value);
		if (!(num >= 0.999f) && (flag || !(TpsCamera.AimBlend < 0.5f)))
		{
			num = (IsAiming ? Mathf.Max(0f, num) : Mathf.Lerp(1f, Mathf.Max(0f, num), TpsCamera.AimBlend));
			Spread spread = new Spread();
			spread.Attack = __instance;
			spread.Accuracy = Get(_accuracy, __instance, 0f);
			spread.AccuracyMin = Get(_accuracyMin, __instance, 0f);
			_accuracy.SetValue(__instance, spread.Accuracy * num);
			_accuracyMin.SetValue(__instance, spread.AccuracyMin * num);
			ItemData val = Get<ItemData>(_ammoItem, __instance, null);
			if (val != null && val.m_shared != null && val.m_shared.m_attack != null && val.m_shared.m_attack != __instance)
			{
				spread.Ammo = val.m_shared.m_attack;
				spread.AmmoAccuracy = Get(_accuracy, spread.Ammo, 0f);
				spread.AmmoAccuracyMin = Get(_accuracyMin, spread.Ammo, 0f);
				_accuracy.SetValue(spread.Ammo, spread.AmmoAccuracy * num);
				_accuracyMin.SetValue(spread.Ammo, spread.AmmoAccuracyMin * num);
			}
			__state = spread;
		}
	}

	private static void RestoreSpread(Spread __state)
	{
		if (__state != null)
		{
			_accuracy.SetValue(__state.Attack, __state.Accuracy);
			_accuracyMin.SetValue(__state.Attack, __state.AccuracyMin);
			if (__state.Ammo != null)
			{
				_accuracy.SetValue(__state.Ammo, __state.AmmoAccuracy);
				_accuracyMin.SetValue(__state.Ammo, __state.AmmoAccuracyMin);
			}
		}
	}
}
internal static class ArmsRig
{
	private sealed class Arm
	{
		public Transform Upper;

		public Transform Lower;

		public Transform Hand;

		public Transform[] Fingers;

		public bool Show;

		public Vector3 Target;

		public Quaternion TargetRot;

		public Vector3 Hint;
	}

	private const float RightCurl = 30f;

	private const float LeftCurl = 25f;

	private const float Squash = 0.01f;

	internal static Vector3 Offset;

	internal static Vector3 RightShift;

	internal static Vector3 LeftShift;

	internal static float CurlShare = 1f;

	internal static float LeftReload;

	internal static Vector3 LeftReloadGrip;

	internal static Vector3 LeftReloadFingers = Vector3.forward;

	internal static Vector3 LeftReloadPalm = Vector3.up;

	private static GameObject _rig;

	private static int _signature;

	private static bool _failed;

	private static int _failSignature;

	private static Transform _srcRoot;

	private static Transform[] _src;

	private static Transform[] _dst;

	private static Transform _sChest;

	private static Transform _sNeck;

	private static Transform _sLeftUpper;

	private static Transform _sRightUpper;

	private static Transform _sRightHand;

	private static Transform _sRightMiddle;

	private static Transform _head;

	private static Transform _hips;

	private static readonly Arm Left = new Arm();

	private static readonly Arm Right = new Arm();

	private static readonly Vector3 ChestSpot = new Vector3(0f, -0.34f, -0.15f);

	private static readonly Vector3 RightHint = new Vector3(0.75f, -1f, -0.25f);

	private static readonly Vector3 LeftHint = new Vector3(-0.4f, -1f, 0.05f);

	internal static void DestroyRig()
	{
		if ((Object)(object)_rig != (Object)null)
		{
			Object.Destroy((Object)(object)_rig);
		}
		_rig = null;
		_src = null;
		_dst = null;
	}

	private static void Hide()
	{
		if ((Object)(object)_rig != (Object)null && _rig.activeSelf)
		{
			_rig.SetActive(false);
		}
	}

	private static int Signature(VisEquipment vis)
	{
		int num = 23;
		SkinnedMeshRenderer bodyModel = vis.m_bodyModel;
		num = num * 31 + ((!((Object)(object)bodyModel.sharedMesh == (Object)null)) ? ((Object)bodyModel.sharedMesh).GetInstanceID() : 0);
		List<GameObject> list = Viewmodel.ChestInstances(vis);
		if (list != null)
		{
			foreach (GameObject item in list)
			{
				num = num * 31 + ((!((Object)(object)item == (Object)null)) ? ((Object)item).GetInstanceID() : 0);
			}
		}
		return num;
	}

	internal static void Update(Player player, Transform vm, Held main)
	{
		if (!Plugin.VmArms.Value || main == null || main.Shape == null || ((Character)player).InDodge())
		{
			Hide();
			return;
		}
		VisEquipment visEquipment = ((Humanoid)player).GetVisEquipment();
		if ((Object)(object)visEquipment == (Object)null || (Object)(object)visEquipment.m_bodyModel == (Object)null)
		{
			Hide();
			return;
		}
		int num = Signature(visEquipment);
		if ((Object)(object)_rig == (Object)null || num != _signature)
		{
			if (_failed && num == _failSignature)
			{
				Hide();
				return;
			}
			if (!Build(visEquipment, num))
			{
				_failed = true;
				_failSignature = num;
				DestroyRig();
				return;
			}
			_failed = false;
		}
		try
		{
			if ((Object)(object)_rig.transform.parent != (Object)(object)vm)
			{
				_rig.transform.SetParent(vm, false);
			}
			if (!_rig.activeSelf)
			{
				_rig.SetActive(true);
			}
			Pose(vm, main);
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Arms: turned off for this armor after an error: " + ex));
			_failed = true;
			_failSignature = num;
			DestroyRig();
		}
	}

	private static bool Build(VisEquipment vis, int signature)
	{
		//IL_0436: Unknown result type (might be due to invalid IL or missing references)
		//IL_0453: Unknown result type (might be due to invalid IL or missing references)
		DestroyRig();
		_signature = signature;
		GameObject val = null;
		try
		{
			SkinnedMeshRenderer bodyModel = vis.m_bodyModel;
			_srcRoot = ((Component)bodyModel).transform.parent;
			if ((Object)(object)_srcRoot == (Object)null)
			{
				return false;
			}
			Animator val2 = ((Component)_srcRoot).GetComponent<Animator>();
			if ((Object)(object)val2 == (Object)null)
			{
				val2 = ((Component)_srcRoot).GetComponentInChildren<Animator>();
			}
			if ((Object)(object)val2 == (Object)null || !val2.isHuman)
			{
				Plugin.Log.LogWarning((object)"Arms: the character has no humanoid animator, so first person arms are off.");
				return false;
			}
			val = Object.Instantiate<GameObject>(((Component)_srcRoot).gameObject, Viewmodel.Holder, false);
			((Object)val).name = "BuminCamera Arms";
			Transform[] componentsInChildren = ((Component)_srcRoot).GetComponentsInChildren<Transform>(true);
			Transform[] componentsInChildren2 = val.GetComponentsInChildren<Transform>(true);
			if (componentsInChildren.Length != componentsInChildren2.Length)
			{
				Object.Destroy((Object)(object)val);
				return false;
			}
			Dictionary<Transform, Transform> dictionary = new Dictionary<Transform, Transform>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				dictionary[componentsInChildren[i]] = componentsInChildren2[i];
			}
			HashSet<Transform> hashSet = new HashSet<Transform>();
			Transform rootBone = bodyModel.rootBone;
			List<Transform> list = new List<Transform>(bodyModel.bones);
			if ((Object)(object)rootBone != (Object)null)
			{
				list.Add(rootBone);
			}
			foreach (Transform item in list)
			{
				Transform val3 = item;
				while ((Object)(object)val3 != (Object)null && (Object)(object)val3 != (Object)(object)_srcRoot && hashSet.Add(val3))
				{
					val3 = val3.parent;
				}
			}
			List<Transform> list2 = new List<Transform>();
			List<Transform> list3 = new List<Transform>();
			foreach (Transform item2 in hashSet)
			{
				if (dictionary.TryGetValue(item2, out var value))
				{
					list2.Add(item2);
					list3.Add(value);
				}
			}
			_src = list2.ToArray();
			_dst = list3.ToArray();
			HashSet<Renderer> hashSet2 = new HashSet<Renderer>();
			int num = 0;
			if (dictionary.TryGetValue(((Component)bodyModel).transform, out var value2))
			{
				Renderer component = ((Component)value2).GetComponent<Renderer>();
				if ((Object)(object)component != (Object)null)
				{
					hashSet2.Add(component);
				}
			}
			List<GameObject> list4 = Viewmodel.ChestInstances(vis);
			if (list4 != null)
			{
				foreach (GameObject item3 in list4)
				{
					if ((Object)(object)item3 == (Object)null)
					{
						continue;
					}
					Renderer[] componentsInChildren3 = item3.GetComponentsInChildren<Renderer>(true);
					foreach (Renderer val4 in componentsInChildren3)
					{
						if ((val4 is SkinnedMeshRenderer || val4 is MeshRenderer) && dictionary.TryGetValue(((Component)val4).transform, out var value3))
						{
							Renderer component2 = ((Component)value3).GetComponent<Renderer>();
							if ((Object)(object)component2 != (Object)null && hashSet2.Add(component2))
							{
								num++;
							}
						}
					}
				}
			}
			if (hashSet2.Count == 0)
			{
				Object.Destroy((Object)(object)val);
				return false;
			}
			Viewmodel.Strip(val, null, keepParticles: false, hashSet2);
			Viewmodel.SetupRenderers(val);
			Renderer[] componentsInChildren4 = val.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val5 in componentsInChildren4)
			{
				val5.enabled = true;
			}
			_sChest = Bone(val2, (HumanBodyBones)54, (HumanBodyBones)8, (HumanBodyBones)7);
			_sNeck = Bone(val2, (HumanBodyBones)9, (HumanBodyBones)10, (HumanBodyBones)9);
			_sLeftUpper = val2.GetBoneTransform((HumanBodyBones)13);
			_sRightUpper = val2.GetBoneTransform((HumanBodyBones)14);
			Transform boneTransform = val2.GetBoneTransform((HumanBodyBones)17);
			Transform boneTransform2 = val2.GetBoneTransform((HumanBodyBones)18);
			if ((Object)(object)_sChest == (Object)null || (Object)(object)_sNeck == (Object)null || (Object)(object)_sLeftUpper == (Object)null || (Object)(object)_sRightUpper == (Object)null || (Object)(object)boneTransform == (Object)null || (Object)(object)boneTransform2 == (Object)null)
			{
				Plugin.Log.LogWarning((object)"Arms: the character's chest, neck or arm bones are missing, so first person arms are off.");
				Object.Destroy((Object)(object)val);
				return false;
			}
			_sRightHand = boneTransform2;
			_sRightMiddle = val2.GetBoneTransform((HumanBodyBones)45);
			_head = Copy(dictionary, val2.GetBoneTransform((HumanBodyBones)10));
			_hips = Copy(dictionary, val2.GetBoneTransform((HumanBodyBones)0));
			Fill(Left, dictionary, val2, (HumanBodyBones)13, (HumanBodyBones)15, boneTransform, CrossbowFit.LeftFingers, LeftHint);
			Fill(Right, dictionary, val2, (HumanBodyBones)14, (HumanBodyBones)16, boneTransform2, CrossbowFit.RightFingers, RightHint);
			if ((Object)(object)Left.Upper == (Object)null || (Object)(object)Left.Lower == (Object)null || (Object)(object)Left.Hand == (Object)null || (Object)(object)Right.Upper == (Object)null || (Object)(object)Right.Lower == (Object)null || (Object)(object)Right.Hand == (Object)null)
			{
				Object.Destroy((Object)(object)val);
				return false;
			}
			if ((Object)(object)_hips != (Object)null && (!Below(Left.Upper, _hips) || !Below(Right.Upper, _hips)))
			{
				_hips = null;
			}
			if ((Object)(object)_hips == (Object)null)
			{
				Plugin.Log.LogInfo((object)"Arms: the hips bone was not found above the arms, so the chest stays visible.");
			}
			_rig = val;
			Plugin.Log.LogInfo((object)("Arms: first person arms made from the body and " + num + " chest armor parts."));
			return true;
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Arms: could not copy the body: " + ex));
			if ((Object)(object)val != (Object)null)
			{
				Object.Destroy((Object)(object)val);
			}
			return false;
		}
	}

	private static Transform Bone(Animator animator, HumanBodyBones first, HumanBodyBones second, HumanBodyBones third)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		Transform boneTransform = animator.GetBoneTransform(first);
		if ((Object)(object)boneTransform == (Object)null)
		{
			boneTransform = animator.GetBoneTransform(second);
		}
		if ((Object)(object)boneTransform == (Object)null)
		{
			boneTransform = animator.GetBoneTransform(third);
		}
		return boneTransform;
	}

	private static bool Below(Transform child, Transform ancestor)
	{
		Transform parent = child.parent;
		while ((Object)(object)parent != (Object)null)
		{
			if ((Object)(object)parent == (Object)(object)ancestor)
			{
				return true;
			}
			parent = parent.parent;
		}
		return false;
	}

	private static Transform Copy(Dictionary<Transform, Transform> map, Transform source)
	{
		if (!((Object)(object)source != (Object)null) || !map.TryGetValue(source, out var value))
		{
			return null;
		}
		return value;
	}

	private static void Fill(Arm arm, Dictionary<Transform, Transform> map, Animator animator, HumanBodyBones upper, HumanBodyBones lower, Transform hand, HumanBodyBones[] fingers, Vector3 hint)
	{
		//IL_0003: 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_0036: 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_004f: 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)
		arm.Upper = Copy(map, animator.GetBoneTransform(upper));
		arm.Lower = Copy(map, animator.GetBoneTransform(lower));
		arm.Hand = Copy(map, hand);
		arm.Hint = hint;
		List<Transform> list = new List<Transform>();
		foreach (HumanBodyBones val in fingers)
		{
			Transform val2 = Copy(map, animator.GetBoneTransform(val));
			if ((Object)(object)val2 != (Object)null)
			{
				list.Add(val2);
			}
		}
		arm.Fingers = list.ToArray();
	}

	private static Vector3 P(Transform vm, Transform t)
	{
		//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)
		return vm.InverseTransformPoint(t.position);
	}

	private static Quaternion R(Transform vm, Transform t)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		return Quaternion.Inverse(vm.rotation) * t.rotation;
	}

	private static void SetR(Transform vm, Transform t, Quaternion q)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		t.rotation = vm.rotation * q;
	}

	private static Quaternion ChestFrame(Vector3 chest, Vector3 neck, Vector3 left, Vector3 right)
	{
		//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_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_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_0028: 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_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)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = neck - chest;
		Vector3 normalized = ((Vector3)(ref val)).normalized;
		Vector3 val2 = right - left;
		Vector3 normalized2 = ((Vector3)(ref val2)).normalized;
		Vector3 val3 = Vector3.Cross(normalized2, normalized);
		if (((Vector3)(ref val3)).sqrMagnitude < 1E-06f || ((Vector3)(ref normalized)).sqrMagnitude < 1E-06f)
		{
			return Quaternion.identity;
		}
		return Quaternion.LookRotation(((Vector3)(ref val3)).normalized, normalized);
	}

	private static void Pose(Transform vm, Held held)
	{
		//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_0071: 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_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: 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_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_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: 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_00ff: 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_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: 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_0040: 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_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: 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_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: 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_020b: 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_02ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d8: 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_0245: 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_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: 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_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_0274: Unknown result type (might be due to invalid IL or missing references)
		//IL_0276: 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_02fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0303: Unknown result type (might be due to invalid IL or missing references)
		//IL_0305: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < _src.Length; i++)
		{
			Transform val = _src[i];
			Transform val2 = _dst[i];
			if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null))
			{
				val2.localPosition = val.localPosition;
				val2.localRotation = val.localRotation;
				val2.localScale = val.localScale;
			}
		}
		Quaternion val3 = ChestFrame(_sChest.position, _sNeck.position, _sLeftUpper.position, _sRightUpper.position);
		Quaternion val4 = Quaternion.Inverse(val3);
		Transform transform = _rig.transform;
		Vector3 lossyScale = _srcRoot.lossyScale;
		float num = Mathf.Max(0.0001f, (Mathf.Abs(lossyScale.x) + Mathf.Abs(lossyScale.y) + Mathf.Abs(lossyScale.z)) / 3f);
		transform.localScale = Vector3.one * num;
		transform.localRotation = val4 * _srcRoot.rotation;
		transform.localPosition = ChestSpot + Offset + val4 * (_srcRoot.position - _sChest.position);
		if ((Object)(object)_head != (Object)null)
		{
			_head.localScale = Vector3.one * 0.0001f;
		}
		float num2;
		if (!((Object)(object)_sRightMiddle != (Object)null))
		{
			num2 = 0.045f * num;
		}
		else
		{
			Vector3 val5 = _sRightMiddle.position - _sRightHand.position;
			num2 = 0.55f * ((Vector3)(ref val5)).magnitude;
		}
		float num3 = num2;
		float num4 = 0.018f * num;
		CrossbowFit.Hands(held.Shape, held.LocalScale, num3, num4, RightShift, LeftShift, out var right, out var left);
		if (LeftReload > 0.001f)
		{
			Vector3 normalized = ((Vector3)(ref LeftReloadFingers)).normalized;
			Vector3 val6 = LeftReloadPalm - Vector3.Dot(LeftReloadPalm, normalized) * normalized;
			if (((Vector3)(ref val6)).sqrMagnitude > 1E-06f)
			{
				((Vector3)(ref val6)).Normalize();
				float num5 = Mathf.Clamp01(LeftReload);
				left.Pos = Vector3.Lerp(left.Pos, LeftReloadGrip - normalized * num3 - val6 * num4, num5);
				left.Rot = Quaternion.Slerp(left.Rot, Quaternion.LookRotation(val6, normalized), num5);
			}
		}
		Aim(Right, held, right);
		Aim(Left, held, left);
		Vector3 shift = Vector3.zero;
		int count = 0;
		Reach(vm, Left, ref shift, ref count);
		Reach(vm, Right, ref shift, ref count);
		if (count > 0)
		{
			shift /= (float)count;
			if (((Vector3)(ref shift)).magnitude > 0.3f)
			{
				shift = ((Vector3)(ref shift)).normalized * 0.3f;
			}
			transform.localPosition += shift;
		}
		Solve(vm, Left);
		Solve(vm, Right);
		CrossbowFit.Curl(Right.Hand, Right.Fingers, 30f * CurlShare);
		CrossbowFit.Curl(Left.Hand, Left.Fingers, 25f * CurlShare);
		Collapse();
	}

	private static void Aim(Arm arm, Held held, HandPose pose)
	{
		//IL_0015: 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_0022: 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_0033: 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_003f: 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)
		arm.Show = true;
		arm.Target = CrossbowFit.ToCamera(held.Shape, held.LocalScale, held.Pos, held.Rot, pose.Pos);
		arm.TargetRot = held.Rot * pose.Rot;
	}

	private static void Collapse()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: 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_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_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_0058: 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_0071: 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)
		//IL_0073: 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_009b: 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_00c3: 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_00e1: 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_0101: 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)
		if (!((Object)(object)_hips == (Object)null))
		{
			Vector3 position = Left.Upper.position;
			Vector3 position2 = Right.Upper.position;
			Quaternion rotation = Left.Upper.rotation;
			Quaternion rotation2 = Right.Upper.rotation;
			_hips.localScale *= 0.01f;
			_hips.position = (position + position2) * 0.5f;
			Left.Upper.localScale = Left.Upper.localScale / 0.01f;
			Right.Upper.localScale = Right.Upper.localScale / 0.01f;
			Left.Upper.position = position;
			Right.Upper.position = position2;
			Left.Upper.rotation = rotation;
			Right.Upper.rotation = rotation2;
		}
	}

	private static void Reach(Transform vm, Arm arm, ref Vector3 shift, ref int count)
	{
		//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_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: 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_006e: 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_007b: 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_0085: Unknown result type (might be due to invalid IL or missing references)
		if (arm.Show)
		{
			Vector3 val = P(vm, arm.Upper);
			float num = Vector3.Distance(val, P(vm, arm.Lower)) + Vector3.Distance(P(vm, arm.Lower), P(vm, arm.Hand));
			Vector3 val2 = arm.Target - val;
			float num2 = ((Vector3)(ref val2)).magnitude - 0.97f * num;
			if (num2 > 0f)
			{
				shift += ((Vector3)(ref val2)).normalized * num2;
				count++;
			}
		}
	}

	private static void Solve(Transform vm, Arm arm)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//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_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: 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_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: 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_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_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: 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_00a3: 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_0101: 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)
		//IL_0113: 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_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: 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_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: 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_0185: 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_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: 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_01f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: 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_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0231: Unknown result type (might be due to invalid IL or missing references)
		//IL_0236: Unknown result type (might be due to invalid IL or missing references)
		if (!arm.Show)
		{
			arm.Upper.localScale = Vector3.one * 0.0001f;
			return;
		}
		Vector3 val = P(vm, arm.Upper);
		Vector3 val2 = P(vm, arm.Lower);
		Vector3 val3 = P(vm, arm.Hand);
		Vector3 val4 = val2 - val;
		float magnitude = ((Vector3)(ref val4)).magnitude;
		Vector3 val5 = val3 - val2;
		float magnitude2 = ((Vector3)(ref val5)).magnitude;
		Vector3 val6 = arm.Target - val;
		float magnitude3 = ((Vector3)(ref val6)).magnitude;
		if (!(magnitude < 0.0001f) && !(magnitude2 < 0.0001f) && !(magnitude3 < 0.0001f))
		{
			Vector3 val7 = val6 / magnitude3;
			magnitude3 = Mathf.Clamp(magnitude3, Mathf.Abs(magnitude - magnitude2) + 0.001f, (magnitude + magnitude2) * 0.999f);
			float num = (magnitude * magnitude - magnitude2 * magnitude2 + magnitude3 * magnitude3) / (2f * magnitude3);
			float num2 = Mathf.Sqrt(Mathf.Max(0f, magnitude * magnitude - num * num));
			Vector3 val8 = arm.Hint - Vector3.Dot(arm.Hint, val7) * val7;
			if (((Vector3)(ref val8)).sqrMagnitude < 1E-06f)
			{
				val8 = Vector3.Cross(val7, Vector3.forward);
			}
			((Vector3)(ref val8)).Normalize();
			Vector3 val9 = val + val7 * num + val8 * num2;
			Vector3 val10 = val + val7 * magnitude3;
			SetR(vm, arm.Upper, Quaternion.FromToRotation(val2 - val, val9 - val) * R(vm, arm.Upper));
			val2 = P(vm, arm.Lower);
			val3 = P(vm, arm.Hand);
			SetR(vm, arm.Lower, Quaternion.FromToRotation(val3 - val2, val10 - val2) * R(vm, arm.Lower));
			SetR(vm, arm.Hand, arm.TargetRot);
			Vector3 val11 = arm.Target - P(vm, arm.Hand);
			if (((Vector3)(ref val11)).sqrMagnitude < 0.0016f)
			{
				arm.Hand.position = vm.TransformPoint(arm.Target);
			}
		}
	}
}
internal static class BowString
{
	private sealed class Target
	{
		public MeshFilter Filter;

		public SkinnedMeshRenderer Skin;

		public int SkinBone;

		public Mesh Original;

		public Mesh Mesh;

		public Vector3[] Base;

		public Vector3[] Work;

		public int[] Index;

		public float[] T;

		public Vector3 A;

		public Vector3 Axis;

		public float Length;

		public Vector3 Belly;

		public Bounds Bounds;

		public bool Moved;
	}

	private sealed class Bow
	{
		public GameObject Instance;

		public readonly List<Target> Targets = new List<Target>();

		public Transform[] Fingers;

		public float Gate;
	}

	private const float TipBand = 0.015f;

	private const float StringRadius = 0.015f;

	private const float SearchRadius = 0.04f;

	private const float MaxPull = 0.6f;

	private const float DrawnAt = 0.02f;

	private const float GateTime = 0.06f;

	private static readonly Dictionary<Player, Bow> Bows = new Dictionary<Player, Bow>();

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

	private static readonly List<Player> Gone = new List<Player>();

	internal static void Update(Player player, Animator animator, float draw, float dt)
	{
		//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_00c6: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = AimPitch.LeftItem(player);
		Bows.TryGetValue(player, out var value);
		if (value != null && (Object)(object)value.Instance != (Object)(object)val)
		{
			Restore(value);
			Bows.Remove(player);
			value = null;
		}
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		if (value == null)
		{
			if (draw <= 0.02f || !IsBow(player))
			{
				return;
			}
			value = Build(val, animator);
			Bows[player] = value;
		}
		if (value.Targets.Count == 0)
		{
			return;
		}
		value.Gate = ((draw > 0.02f) ? Mathf.MoveTowards(value.Gate, 1f, dt / 0.06f) : 0f);
		Vector3 handWorld = HandPoint(value, animator);
		foreach (Target target in value.Targets)
		{
			Apply(target, handWorld, value.Gate);
		}
	}

	internal static void Release(Player player)
	{
		if (Bows.TryGetValue(player, out var value))
		{
			Restore(value);
			Bows.Remove(player);
		}
	}

	internal static void Cleanup()
	{
		Gone.Clear();
		foreach (KeyValuePair<Player, Bow> bow in Bows)
		{
			if ((Object)(object)bow.Key == (Object)null || (Object)(object)bow.Value.Instance == (Object)null)
			{
				Gone.Add(bow.Key);
			}
		}
		foreach (Player item in Gone)
		{
			Restore(Bows[item]);
			Bows.Remove(item);
		}
	}

	private static bool IsBow(Player player)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Invalid comparison between Unknown and I4
		if ((Object)(object)player != (Object)(object)Player.m_localPlayer)
		{
			return true;
		}
		ItemData currentWeapon = ((Humanoid)player).GetCurrentWeapon();
		if (currentWeapon != null && currentWeapon.m_shared != null)
		{
			return (int)currentWeapon.m_shared.m_skillType == 8;
		}
		return false;
	}

	private static Vector3 HandPoint(Bow bow, Animator animator)
	{
		//IL_004b: 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_0028: 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_0037: 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_0062: Unknown result type (might be due to invalid IL or missing references)
		Transform[] fingers = bow.Fingers;
		if ((Object)(object)fingers[0] != (Object)null && (Object)(object)fingers[1] != (Object)null)
		{
			return (fingers[0].position + fingers[1].position) * 0.5f;
		}
		if ((Object)(object)fingers[0] != (Object)null)
		{
			return fingers[0].position;
		}
		if (!((Object)(object)fingers[2] != (Object)null))
		{
			return ((Component)animator).transform.position;
		}
		return fingers[2].position;
	}

	private static Bow Build(GameObject instance, Animator animator)
	{
		Bow bow = new Bow();
		bow.Instance = instance;
		bow.Fingers = (Transform[])(object)new Transform[3];
		Bow bow2 = bow;
		if (animator.isHuman)
		{
			bow2.Fingers[0] = animator.GetBoneTransform((HumanBodyBones)45) ?? animator.GetBoneTransform((HumanBodyBones)42);
			bow2.Fingers[1] = animator.GetBoneTransform((HumanBodyBones)46) ?? animator.GetBoneTransform((HumanBodyBones)43);
			bow2.Fingers[2] = animator.GetBoneTransform((HumanBodyBones)18);
		}
		if ((Object)(object)bow2.Fingers[2] == (Object)null)
		{
			bow2.Fingers[2] = AimPitch.Find(((Component)animator).transform, "RightHand");
		}
		List<string> list = new List<string>();
		MeshFilter[] componentsInChildren = instance.GetComponentsInChildren<MeshFilter>(true);
		foreach (MeshFilter val in componentsInChildren)
		{
			MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>();
			if (!((Object)(object)component == (Object)null) && !((Object)(object)val.sharedMesh == (Object)null))
			{
				Target target = Detect(val.sharedMesh, list);
				if (target != null)
				{
					target.Filter = val;
					val.sharedMesh = target.Mesh;
					bow2.Targets.Add(target);
				}
			}
		}
		SkinnedMeshRenderer[] componentsInChildren2 = instance.GetComponentsInChildren<SkinnedMeshRenderer>(true);
		foreach (SkinnedMeshRenderer val2 in componentsInChildren2)
		{
			if (!((Object)(object)val2.sharedMesh == (Object)null))
			{
				Target target2 = Detect(val2.sharedMesh, list);
				if (target2 != null)
				{
					target2.Skin = val2;
					target2.SkinBone = SkinBone(val2, target2);
					val2.sharedMesh = target2.Mesh;
					bow2.Targets.Add(target2);
				}
			}
		}
		string text = ((Object)instance).name.Replace("(Clone)", "").Trim();
		if (Logged.Add(text))
		{
			Plugin.Log.LogInfo((object)("Bow string " + text + ": " + ((list.Count > 0) ? string.Join("; ", list.ToArray()) : "no meshes") + "."));
		}
		return bow2;
	}

	private static Target Detect(Mesh mesh, List<string> found)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_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_0046: 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_0064: 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_0072: 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_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: 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_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: 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_00ad: 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_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: 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_00fc: 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_010d: 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_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: 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_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: 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_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: 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_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_02a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_033f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0341: Unknown result type (might be due to invalid IL or missing references)
		//IL_0348: Unknown result type (might be due to invalid IL or missing references)
		//IL_034a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0366: Unknown result type (might be due to invalid IL or missing references)
		//IL_036b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0370: Unknown result type (might be due to invalid IL or missing references)
		//IL_0374: Unknown result type (might be due to invalid IL or missing references)
		//IL_035f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0379: Unknown result type (might be due to invalid IL or missing references)
		//IL_0380: Unknown result type (might be due to invalid IL or missing references)
		//IL_0382: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_022d: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		if (!mesh.isReadable)
		{
			found.Add(((Object)mesh).name + " cannot be read, the string stays straight");
			return null;
		}
		Vector3[] vertices = mesh.vertices;
		if (vertices.Length < 8)
		{
			return null;
		}
		Bounds bounds = mesh.bounds;
		Vector3 center = ((Bounds)(ref bounds)).center;
		Vector3 val = Farthest(vertices, center);
		Vector3 val2 = Farthest(vertices, val);
		float num = Vector3.Distance(val, val2);
		if (num <= 0.0001f)
		{
			return null;
		}
		val = Around(vertices, val, num * 0.015f);
		val2 = Around(vertices, val2, num * 0.015f);
		float radius = num * 0.04f;
		if (!Mean(vertices, val, val2 - val, radius, 0.28f, 0.44f, out var mean) || !Mean(vertices, val, val2 - val, radius, 0.56f, 0.72f, out var mean2))
		{
			found.Add(((Object)mesh).name + " has no straight string between its tips");
			return null;
		}
		Vector3 val3 = mean2 - mean;
		Vector3 normalized = ((Vector3)(ref val3)).normalized;
		Vector3 val4 = mean + normalized * Vector3.Dot(val - mean, normalized);
		Vector3 val5 = mean + normalized * Vector3.Dot(val2 - mean, normalized);
		Vector3 val6 = val5 - val4;
		num = ((Vector3)(ref val6)).magnitude;
		float num2 = num * 0.015f;
		List<int> list = new List<int>();
		List<float> list2 = new List<float>();
		int num3 = 0;
		Vector3 val7 = Vector3.zero;
		int num4 = 0;
		for (int i = 0; i < vertices.Length; i++)
		{
			float num5 = Vector3.Dot(vertices[i] - val4, val6) / (num * num);
			Vector3 val8 = vertices[i] - (val4 + val6 * num5);
			float magnitude = ((Vector3)(ref val8)).magnitude;
			if (num5 >= -0.01f && num5 <= 1.01f && magnitude < num2)
			{
				list.Add(i);
				list2.Add(Mathf.Clamp01(num5));
				if (num5 > 0.2f && num5 < 0.8f)
				{
					num3++;
				}
			}
			else if (num5 > 0.35f && num5 < 0.65f && magnitude > num2 * 4f)
			{
				val7 += val8;
				num4++;
			}
		}
		if (num3 < 2)
		{
			found.Add(((Object)mesh).name + " has no string vertices between its tips");
			return null;
		}
		Mesh val9 = Object.Instantiate<Mesh>(mesh);
		((Object)val9).name = ((Object)mesh).name + " (string)";
		Bounds bounds2 = mesh.bounds;
		((Bounds)(ref bounds2)).Expand(num * 0.6f * 2f);
		val9.bounds = bounds2;
		found.Add(((Object)mesh).name + " " + list.Count + " string vertices");
		Target target = new Target();
		target.Original = mesh;
		target.Mesh = val9;
		target.Base = vertices;
		target.Work = (Vector3[])vertices.Clone();
		target.Index = list.ToArray();
		target.T = list2.ToArray();
		target.A = val4;
		target.Axis = val6;
		target.Length = num;
		Vector3 belly;
		if (num4 <= 0)
		{
			belly = Vector3.zero;
		}
		else
		{
			Vector3 val10 = val7 / (float)num4;
			belly = ((Vector3)(ref val10)).normalized;
		}
		target.Belly = belly;
		target.Bounds = bounds2;
		return target;
	}

	private static int SkinBone(SkinnedMeshRenderer skin, Target target)
	{
		Transform[] bones = skin.bones;
		if (bones == null || bones.Length == 0)
		{
			return -1;
		}
		BoneWeight[] boneWeights = target.Original.boneWeights;
		int num = ((boneWeights.Length > target.Index[target.Index.Length / 2]) ? ((BoneWeight)(ref boneWeights[target.Index[target.Index.Length / 2]])).boneIndex0 : 0);
		if (num < 0 || num >= bones.Length || num >= target.Original.bindposes.Length)
		{
			return -1;
		}
		return num;
	}

	private static void Apply(Target target, Vector3 handWorld, float gate)
	{
		//IL_0056: 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_005c: 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_006e: 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_0071: 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_007c: 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_00a6: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: 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_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: 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_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: 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_010e: 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_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		if ((Object)(object)target.Mesh == (Object)null)
		{
			return;
		}
		if (gate <= 0f)
		{
			if (target.Moved)
			{
				target.Mesh.vertices = target.Base;
				target.Mesh.bounds = target.Bounds;
				target.Moved = false;
			}
		}
		else
		{
			if (!ToMesh(target, out var toMesh))
			{
				return;
			}
			Vector3 val = ((Matrix4x4)(ref toMesh)).MultiplyPoint3x4(handWorld);
			Vector3 val2 = target.Axis / target.Length;
			float num = Mathf.Clamp(Vector3.Dot(val - target.A, target.Axis) / (target.Length * target.Length), 0.25f, 0.75f);
			Vector3 val3 = val - (target.A + target.Axis * num);
			val3 -= val2 * Vector3.Dot(val3, val2);
			if (target.Belly != Vector3.zero)
			{
				float num2 = Vector3.Dot(val3, target.Belly);
				if (num2 > 0f)
				{
					val3 -= target.Belly * num2;
				}
			}
			float num3 = target.Length * 0.6f;
			if (((Vector3)(ref val3)).magnitude > num3)
			{
				val3 = ((Vector3)(ref val3)).normalized * num3;
			}
			val3 *= gate;
			for (int i = 0; i < target.Index.Length; i++)
			{
				int num4 = target.Index[i];
				float num5 = target.T[i];
				float num6 = ((num5 < num) ? (num5 / num) : ((1f - num5) / (1f - num)));
				ref Vector3 reference = ref target.Work[num4];
				reference = target.Base[num4] + val3 * num6;
			}
			target.Mesh.vertices = target.Work;
			target.Mesh.bounds = target.Bounds;
			target.Moved = true;
		}
	}

	private static bool ToMesh(Target target, out Matrix4x4 toMesh)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or miss