Decompiled source of WindstridesBowAnimations v1.1.1

BepInEx/plugins/WindstridesBowAnimations.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using MagicaCloth2;
using Microsoft.CodeAnalysis;
using QuickMod.Audio;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace QuickMod.Audio
{
	internal static class ModSfx
	{
		private static ModSfxVoices bank;

		internal static AudioClip LoadOwned(string name)
		{
			AudioClip val = null;
			try
			{
				using Stream stream = typeof(ModSfx).Assembly.GetManifestResourceStream("QuickMod.Sfx." + name + ".pcm");
				if (stream == null || stream.Length < 2 || stream.Length % 2 != 0)
				{
					return null;
				}
				float[] array = new float[checked((int)stream.Length) / 2];
				using (BinaryReader binaryReader = new BinaryReader(stream))
				{
					for (int i = 0; i < array.Length; i++)
					{
						array[i] = (float)binaryReader.ReadInt16() / 32768f;
					}
				}
				val = AudioClip.Create(name, array.Length, 1, 44100, false);
				object obj = typeof(AudioClip).GetMethod("SetData", new Type[2]
				{
					typeof(float[]),
					typeof(int)
				}).Invoke(val, new object[2] { array, 0 });
				if (obj is bool && !(bool)obj)
				{
					throw new InvalidOperationException("Audio upload failed");
				}
				return val;
			}
			catch (Exception ex)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					Object.Destroy((Object)(object)val);
				}
				Debug.LogWarning((object)("QuickMod SFX " + name + ": " + ex.Message));
				return null;
			}
		}

		internal static bool Play(string name, Vector3 position, float gain = 0.4f, float pitch = 1f, float range = 25f, Transform parent = null)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)Camera.main) || AudioMan.GetSFXVolume() <= 0f || gain <= 0f)
			{
				return true;
			}
			Vector3 val = ((Component)Camera.main).transform.position - position;
			if (((Vector3)(ref val)).sqrMagnitude > range * range)
			{
				return true;
			}
			if (!Object.op_Implicit((Object)(object)bank))
			{
				bank = new GameObject("QuickMod SFX " + typeof(ModSfx).Assembly.GetName().Name).AddComponent<ModSfxVoices>();
			}
			return bank.Play(name, position, gain, pitch, range, parent);
		}

		internal static void Clear()
		{
			if (Object.op_Implicit((Object)(object)bank))
			{
				Object.Destroy((Object)(object)((Component)bank).gameObject);
			}
			bank = null;
		}
	}
	internal sealed class ModSfxVoices : MonoBehaviour
	{
		private const int Limit = 16;

		private readonly Dictionary<string, AudioClip> clips = new Dictionary<string, AudioClip>();

		private readonly AudioSource[] voices = (AudioSource[])(object)new AudioSource[16];

		private readonly Transform[] follow = (Transform[])(object)new Transform[16];

		private readonly Vector3[] offsets = (Vector3[])(object)new Vector3[16];

		private readonly float[] gains = new float[16];

		private readonly float[] started = new float[16];

		internal bool Play(string name, Vector3 position, float gain, float pitch, float range, Transform parent)
		{
			//IL_017c: 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_013a: Expected O, but got Unknown
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: 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)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0243: Unknown result type (might be due to invalid IL or missing references)
			if (!clips.TryGetValue(name, out var value))
			{
				AudioClip val = (clips[name] = ModSfx.LoadOwned(name));
				value = val;
			}
			if (!Object.op_Implicit((Object)(object)value))
			{
				return false;
			}
			int num = -1;
			for (int i = 0; i < 16; i++)
			{
				AudioSource val3 = voices[i];
				if (Object.op_Implicit((Object)(object)val3) && val3.isPlaying && (Object)(object)val3.clip == (Object)(object)value && Time.unscaledTime - started[i] < 0.045f)
				{
					Vector3 val4 = ((Component)val3).transform.position - position;
					if (((Vector3)(ref val4)).sqrMagnitude < 0.09f)
					{
						return true;
					}
				}
				if ((!Object.op_Implicit((Object)(object)val3) || !val3.isPlaying) && num < 0)
				{
					num = i;
				}
			}
			if (num < 0)
			{
				return true;
			}
			if (!Object.op_Implicit((Object)(object)voices[num]))
			{
				GameObject val5 = new GameObject("SFX voice");
				val5.transform.SetParent(((Component)this).transform, false);
				voices[num] = val5.AddComponent<AudioSource>();
				voices[num].playOnAwake = false;
			}
			AudioSource val6 = voices[num];
			((Component)val6).transform.position = position;
			val6.clip = value;
			val6.loop = false;
			val6.spatialBlend = 1f;
			val6.dopplerLevel = 0f;
			val6.rolloffMode = (AudioRolloffMode)1;
			val6.minDistance = Mathf.Min(1.5f, range * 0.1f);
			val6.maxDistance = Mathf.Max(2f, range);
			val6.pitch = Mathf.Clamp(pitch, 0.5f, 2f);
			gains[num] = Mathf.Clamp01(gain);
			val6.volume = gains[num] * AudioMan.GetSFXVolume();
			follow[num] = parent;
			offsets[num] = (Object.op_Implicit((Object)(object)parent) ? parent.InverseTransformPoint(position) : Vector3.zero);
			started[num] = Time.unscaledTime;
			val6.Play();
			return true;
		}

		private void Update()
		{
			//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)
			float sFXVolume = AudioMan.GetSFXVolume();
			for (int i = 0; i < 16; i++)
			{
				if (!Object.op_Implicit((Object)(object)voices[i]) || !voices[i].isPlaying)
				{
					follow[i] = null;
					continue;
				}
				voices[i].volume = gains[i] * sFXVolume;
				if (Object.op_Implicit((Object)(object)follow[i]))
				{
					((Component)voices[i]).transform.position = follow[i].TransformPoint(offsets[i]);
				}
			}
		}

		private void OnDestroy()
		{
			foreach (AudioClip value in clips.Values)
			{
				if (Object.op_Implicit((Object)(object)value))
				{
					Object.Destroy((Object)(object)value);
				}
			}
			clips.Clear();
		}
	}
}
namespace QuickMod.BowString
{
	internal static class BetterArcheryCompatibility
	{
		private static MethodInfo teardown;

		private static MethodInfo clearArrow;

		private static FieldInfo installedPlayer;

		private static FieldInfo spineTimer;

		private static bool Handles(Player player)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Invalid comparison between Unknown and I4
			if (!Object.op_Implicit((Object)(object)player))
			{
				return false;
			}
			BowDrawDriver component = ((Component)player).GetComponent<BowDrawDriver>();
			int result;
			if (Object.op_Implicit((Object)(object)component) && ((Behaviour)component).enabled)
			{
				if (!component.OwnsShoulderPose)
				{
					ItemData currentWeapon = ((Humanoid)player).GetCurrentWeapon();
					result = ((currentWeapon != null && (int)currentWeapon.m_shared.m_itemType == 4) ? 1 : 0);
				}
				else
				{
					result = 1;
				}
			}
			else
			{
				result = 0;
			}
			return (byte)result != 0;
		}

		internal static void Install(Harmony harmony)
		{
			if (Chainloader.PluginInfos.TryGetValue("ishid4.mods.betterarchery", out var value))
			{
				Assembly assembly = ((object)value.Instance).GetType().Assembly;
				Type type = assembly.GetType("BetterArchery.Player_LateUpdate_Patch");
				Type type2 = assembly.GetType("BetterArchery.CrouchBowDrawOverlay");
				Type type3 = assembly.GetType("BetterArchery.NockedArrow");
				Type type4 = assembly.GetType("BetterArchery.Player_UpdateCrouch_Patch");
				teardown = AccessTools.Method(type2, "Teardown", (Type[])null, (Type[])null);
				installedPlayer = AccessTools.Field(type2, "_installedPlayer");
				clearArrow = AccessTools.Method(type3, "Clear", (Type[])null, (Type[])null);
				spineTimer = AccessTools.Field(type, "spineTimer");
				Patch(harmony, AccessTools.Method(type, "Postfix", (Type[])null, (Type[])null), "BeforeSpine");
				Patch(harmony, AccessTools.Method(type4, "Postfix", (Type[])null, (Type[])null), "BeforeCrouch");
				if (teardown != null && installedPlayer != null)
				{
					Patch(harmony, AccessTools.Method(type2, "Update", (Type[])null, (Type[])null), "BeforeOverlay");
				}
				Patch(harmony, AccessTools.Method(type2, "OnFireTrigger", (Type[])null, (Type[])null), "BeforeFire");
				if (clearArrow != null)
				{
					Patch(harmony, AccessTools.Method(type3, "Update", (Type[])null, (Type[])null), "BeforeArrow");
					Patch(harmony, AccessTools.Method(type3, "LateUpdate", (Type[])null, (Type[])null), "BeforeArrow");
				}
				Plugin.Log.LogInfo((object)"Better Archery compatibility installed: Windstride controls bow poses and held-arrow visuals; vanilla stand-to-shoot crouch behavior restored.");
			}
		}

		private static void Patch(Harmony harmony, MethodInfo target, string prefix)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			if (target == null)
			{
				Plugin.Log.LogWarning((object)("Better Archery compatibility method missing: " + prefix));
			}
			else
			{
				harmony.Patch((MethodBase)target, new HarmonyMethod(typeof(BetterArcheryCompatibility), prefix, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		private static bool BeforeSpine(Player __0)
		{
			if (!Handles(__0))
			{
				return true;
			}
			spineTimer?.SetValue(null, 0f);
			clearArrow?.Invoke(null, null);
			return false;
		}

		private static bool BeforeCrouch(Player __0)
		{
			return !Handles(__0);
		}

		private static bool BeforeOverlay(Player __0)
		{
			if (!Handles(__0))
			{
				return true;
			}
			if (installedPlayer.GetValue(null) != null)
			{
				teardown.Invoke(null, null);
			}
			return false;
		}

		private static bool BeforeArrow(Player __0)
		{
			if (!Handles(__0))
			{
				return true;
			}
			clearArrow.Invoke(null, null);
			return false;
		}

		private static bool BeforeFire(ZSyncAnimation __0, ref bool __result)
		{
			if (!Object.op_Implicit((Object)(object)__0) || !Handles(((Component)__0).GetComponentInParent<Player>()))
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	internal static class BowAimSpace
	{
		internal static readonly Quaternion ReferenceHips = new Quaternion(-0.0036906302f, 0.6900783f, -0.013638094f, 0.72359675f);

		internal static readonly Vector3 ReferenceSpine = new Vector3(-0.03182505f, 0.91944337f, -0.049251705f);

		internal static Vector3 Direction(float yaw, float pitch)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return Quaternion.Euler(0f - pitch, yaw, 0f) * Vector3.forward;
		}

		internal static Quaternion RootRotation(float yaw, Quaternion sampledSpine)
		{
			//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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			return Quaternion.Euler(0f, yaw, 0f) * ReferenceHips * sampledSpine;
		}

		internal static Vector3 RootPosition(Vector3 characterPosition, Vector3 scale, float yaw)
		{
			//IL_0000: 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)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			return characterPosition + Quaternion.Euler(0f, yaw, 0f) * Vector3.Scale(ReferenceSpine, scale);
		}
	}
	internal sealed class BowDiagnostics : MonoBehaviour
	{
		private IEnumerator Start()
		{
			yield return (object)new WaitForSeconds(3f);
			string folder = Environment.GetEnvironmentVariable("BOWDRAW_SELFTEST");
			try
			{
				Tuple<Type, string>[] array = new Tuple<Type, string>[5]
				{
					Tuple.Create(typeof(VisEquipment), "AttachItem"),
					Tuple.Create(typeof(Humanoid), "StartAttack"),
					Tuple.Create(typeof(Projectile), "Setup"),
					Tuple.Create(typeof(Projectile), "Awake"),
					Tuple.Create(typeof(ClothManager), "ClothUpdate")
				};
				foreach (Tuple<Type, string> spec in array)
				{
					Patches info = Harmony.GetPatchInfo((MethodBase)AccessTools.Method(spec.Item1, spec.Item2, (Type[])null, (Type[])null));
					if (info == null || !info.Owners.Contains("quickmod.bowstring"))
					{
						throw new Exception("Missing patch " + spec.Item2);
					}
				}
				AssetBundle bundle = null;
				foreach (AssetBundle candidate in AssetBundle.GetAllLoadedAssetBundles())
				{
					if (candidate.Contains("Assets/Characters/Player/Player.prefab"))
					{
						bundle = candidate;
						break;
					}
				}
				if (!Object.op_Implicit((Object)(object)bundle))
				{
					bundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "SoftRef/Bundles/c4210710"));
				}
				GameObject prefab = bundle.LoadAsset<GameObject>("Assets/Characters/Player/Player.prefab");
				Animator source = prefab.GetComponentInChildren<Animator>(true);
				Dictionary<Transform, Transform> map = new Dictionary<Transform, Transform>();
				Transform copy = Copy(prefab.transform, null, map);
				copy.position = Vector3.zero;
				copy.rotation = Quaternion.identity;
				Animator anim = ((Component)map[((Component)source).transform]).gameObject.AddComponent<Animator>();
				anim.avatar = source.avatar;
				anim.runtimeAnimatorController = source.runtimeAnimatorController;
				anim.cullingMode = (AnimatorCullingMode)0;
				anim.applyRootMotion = false;
				anim.Rebind();
				anim.Update(0f);
				anim.SetBool("bow_aim", true);
				anim.SetFloat("drawpercent", 1f);
				anim.Play("Base Layer.bow aim", 0, 0f);
				anim.Update(1E-05f);
				((Behaviour)anim).enabled = false;
				Dictionary<string, Transform> nodes = new Dictionary<string, Transform>();
				foreach (Transform t in map.Values)
				{
					nodes[((Object)t).name] = t;
				}
				StringBuilder sb = new StringBuilder();
				Transform hips = nodes["Hips"];
				for (int pose = 0; pose < 5; pose++)
				{
					for (int j = 0; j < BowDrawDriver.BoneNames.Length; j++)
					{
						nodes[BowDrawDriver.BoneNames[j]].localRotation = BowDrawDriver.Sample(j, -90 + 45 * pose, 1f);
					}
					string[] boneNames = BowDrawDriver.BoneNames;
					foreach (string name in boneNames)
					{
						Vector3 p = Quaternion.Inverse(hips.rotation) * (nodes[name].position - hips.position) * 100f;
						sb.Append(pose * 10).Append(' ').Append(name)
							.Append(' ')
							.Append(F(p.x))
							.Append(' ')
							.Append(F(p.y))
							.Append(' ')
							.Append(F(0f - p.z))
							.Append('\n');
					}
				}
				File.WriteAllText(Path.Combine(folder, "runtime_pose_positions.txt"), sb.ToString());
				for (int l = -90; l <= 90; l += 5)
				{
					for (int d = 0; d <= 100; d++)
					{
						for (int m = 0; m < BowDrawDriver.BoneNames.Length; m++)
						{
							Quaternion q = BowDrawDriver.Sample(m, l, (float)d / 100f);
							if (float.IsNaN(q.x) || (double)Mathf.Abs(1f - (q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w)) > 0.001)
							{
								throw new Exception("Invalid pose quaternion");
							}
						}
					}
				}
				File.WriteAllText(Path.Combine(folder, "selftest_result.txt"), "PASS: patches installed; authored layers loaded; 48,581 blended bone samples finite and normalized; runtime pose positions exported.");
				Plugin.Log.LogInfo((object)"SELFTEST PASS");
				Object.Destroy((Object)(object)((Component)copy).gameObject);
			}
			catch (Exception ex)
			{
				Exception e = ex;
				File.WriteAllText(Path.Combine(folder, "selftest_result.txt"), "FAIL: " + e);
				Plugin.Log.LogError((object)e);
			}
			finally
			{
				Application.Quit();
			}
		}

		private static string F(float f)
		{
			return f.ToString("R", CultureInfo.InvariantCulture);
		}

		private static Transform Copy(Transform src, Transform parent, Dictionary<Transform, Transform> map)
		{
			//IL_0007: 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_002a: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			Transform transform = new GameObject(((Object)src).name).transform;
			transform.SetParent(parent, false);
			transform.localPosition = src.localPosition;
			transform.localRotation = src.localRotation;
			transform.localScale = src.localScale;
			map[src] = transform;
			foreach (Transform item in src)
			{
				Transform src2 = item;
				Copy(src2, transform, map);
			}
			return transform;
		}
	}
	[DefaultExecutionOrder(900)]
	internal sealed class BowDrawDriver : MonoBehaviour
	{
		private static readonly HashSet<BowDrawDriver> ActiveDrivers = new HashSet<BowDrawDriver>();

		private int lastPoseFrame = -1;

		private Humanoid owner;

		private Animator animator;

		private CharacterAnimEvent characterAnimEvent;

		private VisEquipment visualEquipment;

		private Transform hand;

		private GameObject equipped;

		private int drawState;

		private bool pending;

		private bool fired;

		private bool lastDrawFlag;

		private float charge;

		private float pendingUntil;

		private Transform[] bones;

		private Quaternion[] before;

		private Quaternion[] applied;

		private bool wrotePose;

		private GameObject arrow;

		private GameObject arrowPrefab;

		private Vector3 arrowBack;

		private BowStringVisual primaryString;

		private ZNetView netView;

		private int bowHash;

		private int remoteAmmo;

		private int cycle;

		private int shotCycle = -1;

		private int suppressedCycle = -1;

		private float aimPitch;

		private float aimYaw;

		private float nextNetworkSend;

		private float poseWeight;

		private float poseBlendProgress;

		private Vector3 beforeSpinePosition;

		private Vector3 appliedSpinePosition;

		private Quaternion lastAimCorrection = Quaternion.identity;

		private Quaternion lastArmCorrection = Quaternion.identity;

		private float breathPhase;

		private float breathWeight;

		private Quaternion movementRotation = Quaternion.identity;

		private Vector3 movementPosition;

		private float movingWeight;

		private Transform hips;

		private float stanceYaw;

		private float stanceOffsetTime;

		private float stanceYawVelocity;

		private bool stanceTurning;

		private float stanceTurnAnim;

		private float stanceTurnDirection;

		private float lastHipYaw;

		private readonly Transform[] turnBones = (Transform[])(object)new Transform[6];

		private readonly Quaternion[] turnBefore = (Quaternion[])(object)new Quaternion[6];

		private readonly Quaternion[] turnApplied = (Quaternion[])(object)new Quaternion[6];

		private bool wroteTurnOverlay;

		private bool turnClipActive;

		private bool turnCueArmed;

		private float turnClipTime;

		private Quaternion beforeHips;

		private Quaternion appliedHips;

		private bool wroteHips;

		private float handSwayPhase;

		private bool wroteHandSway;

		private bool headFollowCaptured;

		private Quaternion headRelativeToAim;

		private readonly Vector3[] beforeArmPosition = (Vector3[])(object)new Vector3[2];

		private readonly Vector3[] appliedArmPosition = (Vector3[])(object)new Vector3[2];

		private string lastNetworkValue;

		internal const string NetworkKey = "quickmod_bowdraw_state_v1";

		internal const string ShooterKey = "quickmod_bowdraw_shooter";

		internal const string ShotKey = "quickmod_bowdraw_cycle";

		private static readonly string[] Names = new string[13]
		{
			"Spine", "Spine1", "Spine2", "LeftShoulder", "LeftArm", "LeftForeArm", "LeftHand", "RightShoulder", "RightArm", "RightForeArm",
			"RightHand", "Neck", "Head"
		};

		private static Quaternion[,] aimPoses;

		private static Quaternion[,] drawPoses;

		private static Quaternion[,] levelDrawPoses;

		private static Quaternion[,] turnDeltas;

		private const float ArrowWorldLift = 0.065f;

		internal bool OwnsShoulderPose => wrotePose && poseWeight > 0f;

		private bool IsRemote => Object.op_Implicit((Object)(object)netView) && netView.IsValid() && !netView.IsOwner();

		internal bool Drawing { get; private set; }

		internal Vector3 NockWorld => hand.position + hand.rotation * new Vector3(-0.0166914f, 0.133146f, 0.0339927f);

		internal static string[] BoneNames => Names;

		private void OnEnable()
		{
			ActiveDrivers.Add(this);
		}

		internal static void BeforeClothSimulation()
		{
			foreach (BowDrawDriver activeDriver in ActiveDrivers)
			{
				if (Object.op_Implicit((Object)(object)activeDriver) && ((Behaviour)activeDriver).isActiveAndEnabled)
				{
					activeDriver.ApplyPose();
				}
			}
		}

		internal void RegisterString(BowStringVisual source)
		{
			if (!Object.op_Implicit((Object)(object)primaryString))
			{
				primaryString = source;
			}
		}

		internal void Bind(Humanoid human, Animator anim, SkinnedMeshRenderer body, Transform rightHand, GameObject instance, int state, int itemHash)
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			ClearArrow();
			Restore();
			owner = human;
			animator = anim;
			hand = rightHand;
			equipped = instance;
			characterAnimEvent = ((Component)anim).GetComponent<CharacterAnimEvent>();
			visualEquipment = ((Component)human).GetComponentInChildren<VisEquipment>();
			drawState = state;
			pending = (fired = (lastDrawFlag = false));
			Drawing = false;
			primaryString = null;
			netView = ((Component)human).GetComponent<ZNetView>();
			bowHash = itemHash;
			remoteAmmo = 0;
			aimYaw = ((Component)human).transform.eulerAngles.y;
			poseWeight = (poseBlendProgress = 0f);
			breathWeight = 0f;
			stanceYaw = aimYaw;
			stanceOffsetTime = 0f;
			stanceYawVelocity = 0f;
			stanceTurning = false;
			stanceTurnAnim = 1f;
			stanceTurnDirection = 0f;
			turnClipActive = false;
			turnClipTime = 0f;
			wroteTurnOverlay = false;
			turnCueArmed = true;
			headFollowCaptured = false;
			headRelativeToAim = Quaternion.identity;
			hips = (Object.op_Implicit((Object)(object)animator) ? animator.GetBoneTransform((HumanBodyBones)0) : null);
			HumanBodyBones[] array = new HumanBodyBones[6];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			HumanBodyBones[] array2 = (HumanBodyBones[])(object)array;
			for (int i = 0; i < turnBones.Length; i++)
			{
				turnBones[i] = (Object.op_Implicit((Object)(object)animator) ? animator.GetBoneTransform(array2[i]) : null);
			}
			if (!Object.op_Implicit((Object)(object)hips) && Object.op_Implicit((Object)(object)body))
			{
				Transform[] array3 = body.bones;
				foreach (Transform val in array3)
				{
					if (Object.op_Implicit((Object)(object)val) && string.Equals(((Object)val).name, "Hips", StringComparison.OrdinalIgnoreCase))
					{
						hips = val;
						break;
					}
				}
			}
			if (!Object.op_Implicit((Object)(object)hips) && Object.op_Implicit((Object)(object)animator))
			{
				Transform[] componentsInChildren = ((Component)animator).GetComponentsInChildren<Transform>(true);
				foreach (Transform val2 in componentsInChildren)
				{
					if (Object.op_Implicit((Object)(object)val2) && string.Equals(((Object)val2).name, "Hips", StringComparison.OrdinalIgnoreCase))
					{
						hips = val2;
						break;
					}
				}
			}
			if (Object.op_Implicit((Object)(object)body))
			{
				Transform[] array4 = body.bones;
				foreach (Transform val3 in array4)
				{
					if (Object.op_Implicit((Object)(object)val3))
					{
						BindTurnBone(val3);
					}
				}
			}
			if (Object.op_Implicit((Object)(object)animator))
			{
				Transform[] componentsInChildren2 = ((Component)animator).GetComponentsInChildren<Transform>(true);
				foreach (Transform val4 in componentsInChildren2)
				{
					if (Object.op_Implicit((Object)(object)val4))
					{
						BindTurnBone(val4);
					}
				}
			}
			movementRotation = Quaternion.identity;
			movementPosition = Vector3.zero;
			movingWeight = 0f;
			breathPhase = Mathf.Repeat((float)((Object)human).GetInstanceID() * 0.618034f, 1f);
			if (Object.op_Implicit((Object)(object)netView) && netView.IsValid() && BowNetworkState.TryDecode(netView.GetZDO().GetString("quickmod_bowdraw_state_v1", ""), out var state2))
			{
				cycle = Math.Max(cycle, state2.Cycle);
				shotCycle = state2.ShotCycle;
			}
			bones = (Transform[])(object)new Transform[Names.Length];
			before = (Quaternion[])(object)new Quaternion[Names.Length];
			applied = (Quaternion[])(object)new Quaternion[Names.Length];
			Transform[] array5 = (Object.op_Implicit((Object)(object)body) ? body.bones : Array.Empty<Transform>());
			foreach (Transform val5 in array5)
			{
				if (Object.op_Implicit((Object)(object)val5))
				{
					int num = Array.IndexOf(Names, ((Object)val5).name);
					if (num >= 0)
					{
						bones[num] = val5;
					}
				}
			}
			if (Object.op_Implicit((Object)(object)animator))
			{
				HumanBodyBones[] array6 = new HumanBodyBones[13];
				RuntimeHelpers.InitializeArray(array6, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
				HumanBodyBones[] array7 = (HumanBodyBones[])(object)array6;
				for (int num2 = 0; num2 < bones.Length; num2++)
				{
					if (!Object.op_Implicit((Object)(object)bones[num2]))
					{
						bones[num2] = animator.GetBoneTransform(array7[num2]);
					}
				}
			}
			int num3 = 0;
			Transform[] array8 = bones;
			foreach (Transform val6 in array8)
			{
				if (Object.op_Implicit((Object)(object)val6))
				{
					num3++;
				}
			}
			if (num3 < Names.Length)
			{
				((Behaviour)this).enabled = false;
				Plugin.Log.LogError((object)("Bow animation binding failed: " + num3 + "/" + Names.Length + " rendered body bones found."));
				return;
			}
			hand = bones[10];
			((Behaviour)this).enabled = true;
			Plugin.Log.LogInfo((object)("Bow animation bound to " + num3 + " rendered body bones; nock hand=" + ((Object)hand).name + "; additive turn legs=" + CountTurnBones() + "/6; bow=" + ((Object)instance).name));
			if (aimPoses == null)
			{
				LoadPoses();
			}
			if (turnDeltas == null)
			{
				LoadTurnDeltas();
			}
		}

		private void BindTurnBone(Transform t)
		{
			if (Object.op_Implicit((Object)(object)t))
			{
				string name = ((Object)t).name;
				if (!Object.op_Implicit((Object)(object)turnBones[0]) && string.Equals(name, "LeftUpLeg", StringComparison.OrdinalIgnoreCase))
				{
					turnBones[0] = t;
				}
				else if (!Object.op_Implicit((Object)(object)turnBones[1]) && string.Equals(name, "LeftLeg", StringComparison.OrdinalIgnoreCase))
				{
					turnBones[1] = t;
				}
				else if (!Object.op_Implicit((Object)(object)turnBones[2]) && string.Equals(name, "LeftFoot", StringComparison.OrdinalIgnoreCase))
				{
					turnBones[2] = t;
				}
				else if (!Object.op_Implicit((Object)(object)turnBones[3]) && string.Equals(name, "RightUpLeg", StringComparison.OrdinalIgnoreCase))
				{
					turnBones[3] = t;
				}
				else if (!Object.op_Implicit((Object)(object)turnBones[4]) && string.Equals(name, "RightLeg", StringComparison.OrdinalIgnoreCase))
				{
					turnBones[4] = t;
				}
				else if (!Object.op_Implicit((Object)(object)turnBones[5]) && string.Equals(name, "RightFoot", StringComparison.OrdinalIgnoreCase))
				{
					turnBones[5] = t;
				}
			}
		}

		private int CountTurnBones()
		{
			int num = 0;
			Transform[] array = turnBones;
			foreach (Transform val in array)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					num++;
				}
			}
			return num;
		}

		private static void LoadPoses()
		{
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: 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_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			Quaternion[,] array = new Quaternion[5, Names.Length];
			Quaternion[,] array2 = new Quaternion[11, Names.Length];
			Quaternion[,] array3 = new Quaternion[11, Names.Length];
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			Quaternion val;
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("BowDraw.drawposes.txt"))
			{
				using StreamReader streamReader = new StreamReader(stream);
				string text;
				while ((text = streamReader.ReadLine()) != null)
				{
					string[] array4 = text.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
					if (array4.Length == 7)
					{
						int num4 = int.Parse(array4[1], CultureInfo.InvariantCulture);
						int num5 = Array.IndexOf(Names, array4[2]);
						val = new Quaternion(F(array4[3]), F(array4[4]), F(array4[5]), F(array4[6]));
						Quaternion normalized = ((Quaternion)(ref val)).normalized;
						if (array4[0] == "A")
						{
							array[num4 / 10, num5] = normalized;
							num++;
						}
						else if (array4[0] == "D")
						{
							array2[num4 / 3, num5] = normalized;
							num2++;
						}
					}
				}
			}
			using (Stream stream2 = Assembly.GetExecutingAssembly().GetManifestResourceStream("BowDraw.leveldrawposes.txt"))
			{
				using StreamReader streamReader2 = new StreamReader(stream2);
				string text2;
				while ((text2 = streamReader2.ReadLine()) != null)
				{
					string[] array5 = text2.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
					if (array5.Length == 7 && !(array5[0] != "D"))
					{
						int num6 = int.Parse(array5[1], CultureInfo.InvariantCulture);
						int num7 = Array.IndexOf(Names, array5[2]);
						int num8 = num6 / 3;
						val = new Quaternion(F(array5[3]), F(array5[4]), F(array5[5]), F(array5[6]));
						array3[num8, num7] = ((Quaternion)(ref val)).normalized;
						num3++;
					}
				}
			}
			if (num != 5 * Names.Length || num2 != 11 * Names.Length || num3 != 11 * Names.Length)
			{
				throw new InvalidDataException("Incomplete aim/draw layers");
			}
			aimPoses = array;
			drawPoses = array2;
			levelDrawPoses = array3;
		}

		private static float F(string s)
		{
			return float.Parse(s, CultureInfo.InvariantCulture);
		}

		private static void LoadTurnDeltas()
		{
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			Quaternion[,] array = new Quaternion[14, 6];
			bool[,] array2 = new bool[14, 6];
			string[] array3 = new string[6] { "LeftUpLeg", "LeftLeg", "LeftFoot", "RightUpLeg", "RightLeg", "RightFoot" };
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("BowDraw.turnposes.txt"))
			{
				using StreamReader streamReader = new StreamReader(stream);
				string text;
				while ((text = streamReader.ReadLine()) != null)
				{
					string[] array4 = text.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
					if (array4.Length >= 6)
					{
						int num = int.Parse(array4[0], CultureInfo.InvariantCulture);
						int num2 = Array.IndexOf(array3, array4[1]);
						if (num >= 0 && num < 14 && num2 >= 0)
						{
							Quaternion val = new Quaternion(F(array4[2]), F(array4[3]), F(array4[4]), F(array4[5]));
							array[num, num2] = ((Quaternion)(ref val)).normalized;
							array2[num, num2] = true;
						}
					}
				}
			}
			for (int i = 0; i < 14; i++)
			{
				for (int j = 0; j < 6; j++)
				{
					if (!array2[i, j])
					{
						throw new InvalidDataException("Incomplete additive turn clip");
					}
				}
			}
			turnDeltas = new Quaternion[14, 6];
			for (int k = 0; k < 14; k++)
			{
				for (int l = 0; l < 6; l++)
				{
					turnDeltas[k, l] = array[k, l] * Quaternion.Inverse(array[0, l]);
				}
			}
		}

		internal static Quaternion Sample(int bone, float pitch, float charge)
		{
			//IL_0059: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: 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_00e0: 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_00ef: 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_0103: 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_010a: 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_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_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_0123: Unknown result type (might be due to invalid IL or missing references)
			if (aimPoses == null)
			{
				LoadPoses();
			}
			float num = Mathf.Clamp01(charge) * 10f;
			int num2 = Mathf.Min((int)num, 9);
			float num3 = (Mathf.Clamp(pitch, -90f, 90f) + 90f) / 45f;
			int num4 = Mathf.Min((int)num3, 3);
			Quaternion val = Quaternion.Slerp(aimPoses[num4, bone], aimPoses[num4 + 1, bone], num3 - (float)num4);
			Quaternion val2 = Quaternion.Slerp(drawPoses[num2, bone], drawPoses[num2 + 1, bone], num - (float)num2);
			Quaternion val3 = Quaternion.Slerp(levelDrawPoses[num2, bone], levelDrawPoses[num2 + 1, bone], num - (float)num2);
			float num5 = Mathf.Clamp01(1f - Mathf.Abs(num3 - 2f));
			Quaternion val4 = Quaternion.Slerp(val2, val3, num5);
			Quaternion val5 = Quaternion.Slerp(drawPoses[10, bone], levelDrawPoses[10, bone], num5);
			return val * Quaternion.Inverse(val5) * val4;
		}

		internal void PendingShot()
		{
			pending = true;
			pendingUntil = Time.time + 2f;
		}

		internal void ProjectileSpawned(Projectile projectile = null)
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			pending = false;
			fired = true;
			Drawing = false;
			shotCycle = cycle;
			if (Object.op_Implicit((Object)(object)arrow))
			{
				arrow.SetActive(false);
			}
			if (!IsRemote)
			{
				Publish(immediate: true);
				ZNetView val = (Object.op_Implicit((Object)(object)projectile) ? ((Component)projectile).GetComponent<ZNetView>() : null);
				if (Object.op_Implicit((Object)(object)val) && val.IsValid() && val.IsOwner())
				{
					val.GetZDO().Set("quickmod_bowdraw_shooter", ((Character)owner).GetZDOID());
					val.GetZDO().Set("quickmod_bowdraw_cycle", cycle);
				}
			}
		}

		internal void RemoteProjectileSpawned(int shot)
		{
			if (!IsRemote || shot < 0)
			{
				return;
			}
			suppressedCycle = Math.Max(suppressedCycle, shot);
			if (cycle <= shot)
			{
				Drawing = false;
				if (Object.op_Implicit((Object)(object)arrow))
				{
					arrow.SetActive(false);
				}
			}
		}

		private void Publish(bool immediate = false)
		{
			if (Object.op_Implicit((Object)(object)netView) && netView.IsValid() && netView.IsOwner() && (immediate || !(Time.unscaledTime < nextNetworkSend)))
			{
				ItemData ammoItem = owner.GetAmmoItem();
				BowNetworkState bowNetworkState = new BowNetworkState
				{
					Bow = bowHash,
					Ammo = (Object.op_Implicit((Object)(object)ammoItem?.m_dropPrefab) ? StringExtensionMethods.GetStableHashCode(((Object)ammoItem.m_dropPrefab).name) : 0),
					Pitch = Mathf.RoundToInt(Mathf.Clamp(aimPitch, -90f, 90f) * 10f),
					Charge = Mathf.RoundToInt(Mathf.Clamp01(charge) * 1000f),
					Flags = (Drawing ? 1 : 0),
					Cycle = cycle,
					ShotCycle = shotCycle,
					Yaw = Mathf.RoundToInt(Mathf.DeltaAngle(0f, aimYaw) * 10f)
				};
				string text = bowNetworkState.Encode();
				if (text != lastNetworkValue)
				{
					netView.GetZDO().Set("quickmod_bowdraw_state_v1", text);
					lastNetworkValue = text;
				}
				nextNetworkSend = Time.unscaledTime + 0.05f;
			}
		}

		private void ReadRemote()
		{
			//IL_00b3: 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_0149: Unknown result type (might be due to invalid IL or missing references)
			ZDO zDO = netView.GetZDO();
			if (BowNetworkState.TryDecode(zDO.GetString("quickmod_bowdraw_state_v1", ""), out var state) && state.Bow == bowHash)
			{
				cycle = state.Cycle;
				Drawing = state.ShouldDraw(suppressedCycle);
				charge = (float)state.Charge / 1000f;
				aimPitch = (float)state.Pitch / 10f;
				remoteAmmo = state.Ammo;
				if (state.HasYaw)
				{
					aimYaw = (float)state.Yaw / 10f;
				}
				else
				{
					SetYaw(NativeRemoteDirection(zDO));
				}
			}
			else
			{
				Drawing = drawState != 0 && zDO.GetInt(438569 + drawState, 0) != 0;
				charge = Mathf.Clamp01(zDO.GetFloat(438569 + Animator.StringToHash("drawpercent"), 0f));
				Vector3 yaw = NativeRemoteDirection(zDO);
				aimPitch = Mathf.Asin(Mathf.Clamp(((Vector3)(ref yaw)).normalized.y, -1f, 1f)) * 57.29578f;
				SetYaw(yaw);
				remoteAmmo = 0;
			}
		}

		private Vector3 NativeRemoteDirection(ZDO zdo)
		{
			//IL_0007: 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)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_001f: 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_0042: 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)
			Vector3 vec = zdo.GetVec3(ZDOVars.s_lookTarget, Vector3.zero);
			return (vec == Vector3.zero) ? ((Component)owner).transform.forward : (vec - ((Character)owner).GetEyePoint());
		}

		private void SetYaw(Vector3 direction)
		{
			//IL_0001: 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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if (direction.x * direction.x + direction.z * direction.z > 1E-08f)
			{
				aimYaw = Mathf.Atan2(direction.x, direction.z) * 57.29578f;
			}
		}

		private void Update()
		{
			Restore();
		}

		private static bool SameRotation(Quaternion a, Quaternion b)
		{
			//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_001c: 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_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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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)
			float num = ((Quaternion.Dot(a, b) < 0f) ? (-1f) : 1f);
			float num2 = a.x - num * b.x;
			float num3 = a.y - num * b.y;
			float num4 = a.z - num * b.z;
			float num5 = a.w - num * b.w;
			return num2 * num2 + num3 * num3 + num4 * num4 + num5 * num5 < 1E-10f;
		}

		private void Restore()
		{
			//IL_0039: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: 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_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			if (!wrotePose || bones == null)
			{
				return;
			}
			for (int i = 0; i < bones.Length; i++)
			{
				if (Object.op_Implicit((Object)(object)bones[i]) && SameRotation(bones[i].localRotation, applied[i]))
				{
					bones[i].localRotation = before[i];
				}
			}
			Vector3 val;
			if (Object.op_Implicit((Object)(object)bones[0]))
			{
				val = bones[0].localPosition - appliedSpinePosition;
				if (((Vector3)(ref val)).sqrMagnitude < 1E-10f)
				{
					bones[0].localPosition = beforeSpinePosition;
				}
			}
			if (wroteHips && Object.op_Implicit((Object)(object)hips) && SameRotation(hips.rotation, appliedHips))
			{
				hips.rotation = beforeHips;
			}
			if (wroteTurnOverlay)
			{
				for (int j = 0; j < turnBones.Length; j++)
				{
					if (Object.op_Implicit((Object)(object)turnBones[j]) && SameRotation(turnBones[j].localRotation, turnApplied[j]))
					{
						turnBones[j].localRotation = turnBefore[j];
					}
				}
			}
			if (wroteHandSway)
			{
				for (int k = 0; k < 2; k++)
				{
					Transform val2 = bones[(k == 0) ? 4 : 8];
					if (Object.op_Implicit((Object)(object)val2))
					{
						val = val2.localPosition - appliedArmPosition[k];
						if (((Vector3)(ref val)).sqrMagnitude < 1E-10f)
						{
							val2.localPosition = beforeArmPosition[k];
						}
					}
				}
			}
			wroteHandSway = false;
			wroteHips = false;
			wroteTurnOverlay = false;
			wrotePose = false;
		}

		private void LateUpdate()
		{
			//IL_0023: 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_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_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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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)
			ApplyPose();
			if (wroteHips && Object.op_Implicit((Object)(object)hips) && Quaternion.Angle(hips.rotation, appliedHips) > 0.01f)
			{
				beforeHips = hips.rotation;
				hips.rotation = Quaternion.AngleAxis(lastHipYaw, Vector3.up) * beforeHips;
				appliedHips = hips.rotation;
			}
			ApplyTurnOverlayAfterAnimator();
		}

		private void ApplyTurnOverlayAfterAnimator()
		{
			//IL_00b0: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: 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_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_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			if (!turnClipActive || !Drawing || movingWeight > 0.05f || !wrotePose)
			{
				return;
			}
			float num = Mathf.Clamp01(turnClipTime / (13f / 30f)) * 13f;
			int num2 = Mathf.Min((int)num, 12);
			int num3 = num2 + 1;
			float num4 = num - (float)num2;
			bool flag = stanceTurnDirection < 0f;
			for (int i = 0; i < turnBones.Length; i++)
			{
				if (Object.op_Implicit((Object)(object)turnBones[i]))
				{
					int num5 = ((!flag) ? i : ((i < 3) ? (i + 3) : (i - 3)));
					Quaternion val = Quaternion.Slerp(turnDeltas[num2, num5], turnDeltas[num3, num5], num4);
					if (flag)
					{
						Quaternion val2 = new Quaternion(0f - val.x, val.y, val.z, val.w);
						val = ((Quaternion)(ref val2)).normalized;
					}
					val = Quaternion.Slerp(Quaternion.identity, val, Plugin.TurnAnimationStrength.Value);
					turnBefore[i] = turnBones[i].localRotation;
					turnApplied[i] = val * turnBefore[i];
					turnBones[i].localRotation = turnApplied[i];
				}
			}
			wroteTurnOverlay = true;
			turnClipTime += Time.deltaTime;
			if (turnClipTime >= 13f / 30f)
			{
				turnClipActive = false;
			}
		}

		private void ApplyPose()
		{
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Invalid comparison between Unknown and I4
			//IL_01c2: 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_0248: 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_0252: 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_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04db: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0503: Unknown result type (might be due to invalid IL or missing references)
			//IL_0508: Unknown result type (might be due to invalid IL or missing references)
			//IL_050a: Unknown result type (might be due to invalid IL or missing references)
			//IL_050c: Unknown result type (might be due to invalid IL or missing references)
			//IL_051e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0523: Unknown result type (might be due to invalid IL or missing references)
			//IL_0528: Unknown result type (might be due to invalid IL or missing references)
			//IL_052d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0532: Unknown result type (might be due to invalid IL or missing references)
			//IL_0537: Unknown result type (might be due to invalid IL or missing references)
			//IL_0544: Unknown result type (might be due to invalid IL or missing references)
			//IL_0549: Unknown result type (might be due to invalid IL or missing references)
			//IL_054b: Unknown result type (might be due to invalid IL or missing references)
			//IL_055b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0560: Unknown result type (might be due to invalid IL or missing references)
			//IL_0565: Unknown result type (might be due to invalid IL or missing references)
			//IL_056a: Unknown result type (might be due to invalid IL or missing references)
			//IL_056f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0577: Unknown result type (might be due to invalid IL or missing references)
			//IL_057c: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_08f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_08f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0903: Unknown result type (might be due to invalid IL or missing references)
			//IL_0919: Unknown result type (might be due to invalid IL or missing references)
			//IL_091e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0920: Unknown result type (might be due to invalid IL or missing references)
			//IL_0922: Unknown result type (might be due to invalid IL or missing references)
			//IL_0927: Unknown result type (might be due to invalid IL or missing references)
			//IL_0928: Unknown result type (might be due to invalid IL or missing references)
			//IL_092a: Unknown result type (might be due to invalid IL or missing references)
			//IL_092f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0936: Unknown result type (might be due to invalid IL or missing references)
			//IL_094c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0951: Unknown result type (might be due to invalid IL or missing references)
			//IL_097a: Unknown result type (might be due to invalid IL or missing references)
			//IL_097f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0983: Unknown result type (might be due to invalid IL or missing references)
			//IL_0988: Unknown result type (might be due to invalid IL or missing references)
			//IL_098f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0994: Unknown result type (might be due to invalid IL or missing references)
			//IL_0998: Unknown result type (might be due to invalid IL or missing references)
			//IL_099d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0456: Unknown result type (might be due to invalid IL or missing references)
			//IL_045b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0468: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aaa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aaf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0abf: Unknown result type (might be due to invalid IL or missing references)
			//IL_09d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_09d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a00: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a0b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a10: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ae5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ae7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0af3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0af8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b06: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b22: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b32: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b42: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b4d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b52: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b54: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b5a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b6d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b72: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b74: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b79: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b7b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b7d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b7f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b84: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b86: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b8b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ba3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ba8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bb2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bbf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bcf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bda: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bdf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0be1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0be3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0be6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0beb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bf0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bf5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bf7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c09: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c1d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c23: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c33: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c38: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c3d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c42: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c47: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c51: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c52: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c5a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c5f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c60: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c68: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c82: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c87: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c95: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c9a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c9f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ca2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ca7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cb3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cb8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cd3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ced: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cfa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d19: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d1e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d2b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d30: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d44: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d51: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d56: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d70: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d75: Unknown result type (might be due to invalid IL or missing references)
			//IL_0acf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ad4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ada: Unknown result type (might be due to invalid IL or missing references)
			//IL_0adf: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0809: Unknown result type (might be due to invalid IL or missing references)
			//IL_084b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0850: Unknown result type (might be due to invalid IL or missing references)
			//IL_0856: Unknown result type (might be due to invalid IL or missing references)
			//IL_085b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0878: Unknown result type (might be due to invalid IL or missing references)
			//IL_087d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a7a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a36: Unknown result type (might be due to invalid IL or missing references)
			//IL_0da2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0db3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dcc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dd1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0de7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a55: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a5a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a5f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a64: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e41: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e47: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e52: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e5f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e64: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e7e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e83: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e89: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e8f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e9a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e0e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e13: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f26: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f2d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f66: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f6e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f7e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f83: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f88: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f8d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0fa9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0fae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0fb0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0fc5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0fca: Unknown result type (might be due to invalid IL or missing references)
			if (lastPoseFrame == Time.frameCount)
			{
				return;
			}
			lastPoseFrame = Time.frameCount;
			breathPhase = Mathf.Repeat(breathPhase + Time.deltaTime / Plugin.BreathingPeriod.Value, 1f);
			if (Object.op_Implicit((Object)(object)owner) && Object.op_Implicit((Object)(object)animator) && Object.op_Implicit((Object)(object)hand) && Object.op_Implicit((Object)(object)equipped) && equipped.activeInHierarchy && !((Character)owner).IsDead())
			{
				if (!IsRemote)
				{
					ItemData currentWeapon = owner.GetCurrentWeapon();
					if (currentWeapon == null || (int)currentWeapon.m_shared.m_itemType != 4)
					{
						goto IL_00cf;
					}
				}
				bool drawing = Drawing;
				if (IsRemote)
				{
					ReadRemote();
				}
				else
				{
					bool flag = drawing;
					float attackDrawPercentage = owner.GetAttackDrawPercentage();
					bool flag2 = (drawState != 0 && animator.GetBool(drawState)) || attackDrawPercentage > 0.001f;
					if (flag2 && !lastDrawFlag)
					{
						fired = false;
						cycle++;
						headFollowCaptured = false;
						headRelativeToAim = Quaternion.identity;
					}
					lastDrawFlag = flag2;
					if (pending && Time.time > pendingUntil)
					{
						pending = false;
					}
					Drawing = !fired && (flag2 || pending);
					if (flag2 && !pending)
					{
						charge = attackDrawPercentage;
					}
					Vector3 aimDir = owner.GetAimDir(((Component)owner).transform.position);
					aimPitch = Mathf.Clamp(Mathf.Asin(Mathf.Clamp(((Vector3)(ref aimDir)).normalized.y, -1f, 1f)) * 57.29578f, -90f, 90f);
					SetYaw(aimDir);
					Publish(flag != Drawing);
				}
				if (Drawing && !drawing)
				{
					headFollowCaptured = false;
					headRelativeToAim = Quaternion.identity;
				}
				if (!Drawing && Object.op_Implicit((Object)(object)arrow))
				{
					arrow.SetActive(false);
				}
				if (!Drawing)
				{
					headFollowCaptured = false;
				}
				poseBlendProgress = BowPoseBlend.Advance(poseBlendProgress, Drawing, Time.deltaTime, Plugin.DrawPoseBlendTime.Value);
				poseWeight = BowPoseBlend.Weight(poseBlendProgress);
				breathWeight = Mathf.MoveTowards(breathWeight, Drawing ? 1f : 0f, Time.deltaTime / (Drawing ? 0.35f : 0.12f));
				if (poseWeight <= 0f)
				{
					return;
				}
				if (Object.op_Implicit((Object)(object)characterAnimEvent) && characterAnimEvent.m_femaleHack && Object.op_Implicit((Object)(object)visualEquipment))
				{
					float num = ((visualEquipment.GetModelIndex() == 1) ? characterAnimEvent.m_femaleOffset : characterAnimEvent.m_maleOffset);
					Transform leftShoulder = characterAnimEvent.m_leftShoulder;
					Transform rightShoulder = characterAnimEvent.m_rightShoulder;
					if (Object.op_Implicit((Object)(object)leftShoulder))
					{
						Vector3 localPosition = leftShoulder.localPosition;
						localPosition.x = 0f - num;
						leftShoulder.localPosition = localPosition;
					}
					if (Object.op_Implicit((Object)(object)rightShoulder))
					{
						Vector3 localPosition2 = rightShoulder.localPosition;
						localPosition2.x = num;
						rightShoulder.localPosition = localPosition2;
					}
				}
				float num2 = Mathf.Sin(breathPhase * (float)Math.PI * 2f) * breathWeight * Plugin.BreathingStrength.Value * Mathf.Lerp(1f, 0.65f, charge);
				beforeSpinePosition = bones[0].localPosition;
				Vector3 position = bones[0].position;
				Quaternion rotation = bones[0].rotation;
				Quaternion rotation2 = ((Component)owner).transform.rotation;
				Quaternion val = Quaternion.Euler(0f, aimYaw, 0f);
				Quaternion val2 = Quaternion.Inverse(rotation2) * bones[0].parent.rotation * Quaternion.Inverse(BowAimSpace.ReferenceHips);
				Vector3 val3 = ((Component)owner).transform.position + rotation2 * Vector3.Scale(BowAimSpace.ReferenceSpine, ((Component)owner).transform.lossyScale);
				Vector3 velocity = ((Character)owner).GetVelocity();
				velocity.y = 0f;
				movingWeight = Mathf.MoveTowards(movingWeight, Mathf.Clamp01(((Vector3)(ref velocity)).magnitude / 0.8f), Time.deltaTime * 5f);
				if (movingWeight > 0.05f || !Drawing)
				{
					stanceYaw = ((Component)owner).transform.eulerAngles.y;
					stanceOffsetTime = 0f;
					stanceYawVelocity = 0f;
					stanceTurning = false;
					stanceTurnAnim = 1f;
					turnClipActive = false;
					turnCueArmed = true;
				}
				else
				{
					float num3 = Mathf.DeltaAngle(stanceYaw, aimYaw);
					if (Mathf.Abs(num3) >= 10f && Mathf.Abs(num3) <= 55f)
					{
						stanceOffsetTime += Time.deltaTime;
					}
					else if (Mathf.Abs(num3) < 10f)
					{
						stanceOffsetTime = 0f;
						turnCueArmed = true;
					}
					if (Mathf.Abs(num3) > 55f)
					{
						stanceOffsetTime = 3f;
					}
					if (stanceOffsetTime >= 3f)
					{
						if (!stanceTurning)
						{
							stanceTurning = true;
							stanceTurnAnim = 0f;
							stanceTurnDirection = Mathf.Sign(num3);
						}
						if (turnCueArmed)
						{
							stanceTurnDirection = Mathf.Sign(num3);
							turnClipTime = 0f;
							turnClipActive = CountTurnBones() == 6;
							turnCueArmed = false;
						}
						stanceYaw = Mathf.SmoothDampAngle(stanceYaw, aimYaw, ref stanceYawVelocity, 0.18f, 720f, Time.deltaTime);
						stanceTurnAnim = Mathf.Min(1f, stanceTurnAnim + Time.deltaTime / 0.65f);
						if (Mathf.Abs(Mathf.DeltaAngle(stanceYaw, aimYaw)) < 0.5f && stanceTurnAnim >= 1f)
						{
							stanceTurning = false;
						}
					}
					if (Object.op_Implicit((Object)(object)hips))
					{
						beforeHips = hips.rotation;
						float num4 = Mathf.DeltaAngle(((Component)owner).transform.eulerAngles.y, stanceYaw);
						float num5 = Mathf.Sin(stanceTurnAnim * (float)Math.PI) * stanceTurnDirection * 1.5f;
						hips.rotation = Quaternion.AngleAxis(num4 + num5, Vector3.up) * beforeHips;
						lastHipYaw = num4 + num5;
						appliedHips = hips.rotation;
						wroteHips = true;
					}
				}
				float value = Plugin.MovingDrawIntensity.Value;
				float num6 = Mathf.Clamp01((value - 1f) / 2f) * movingWeight;
				float num7 = Mathf.Clamp01(Plugin.MovementInfluence.Value * Plugin.MovementSwayGain.Value) * Mathf.Lerp(1f, value, movingWeight);
				Quaternion val4 = Quaternion.RotateTowards(Quaternion.identity, val2, 45f);
				Quaternion val5 = Quaternion.RotateTowards(Quaternion.identity, Quaternion.SlerpUnclamped(Quaternion.identity, val4, num7), Mathf.Lerp(8f, 18f, num6));
				Vector3 val6 = Vector3.ClampMagnitude(Quaternion.Inverse(rotation2) * (position - val3) * num7, Mathf.Lerp(0.04f, 0.08f, num6));
				float num8 = 1f - Mathf.Exp((0f - Mathf.Lerp(20f, 35f, num6)) * Time.deltaTime);
				movementRotation = Quaternion.Slerp(movementRotation, val5, num8);
				movementPosition = Vector3.Lerp(movementPosition, val6, num8);
				for (int i = 0; i < bones.Length; i++)
				{
					if (Object.op_Implicit((Object)(object)bones[i]))
					{
						before[i] = bones[i].localRotation;
						applied[i] = Quaternion.Slerp(before[i], Sample(i, aimPitch, charge), poseWeight);
						if (i == 1 || i == 2)
						{
							ref Quaternion reference = ref applied[i];
							reference *= Quaternion.AngleAxis(num2 * poseWeight * ((i == 1) ? 0.1f : 0.06f), Vector3.right);
						}
						bones[i].localRotation = applied[i];
					}
				}
				Quaternion rotation3 = bones[11].rotation;
				Quaternion rotation4 = bones[12].rotation;
				if (Drawing)
				{
					lastAimCorrection = Quaternion.identity;
					lastArmCorrection = Quaternion.identity;
				}
				Vector3 val7 = Quaternion.Inverse(val) * ((Vector3)(ref velocity)).normalized;
				float num9 = 2f * Mathf.Abs(val7.x * val7.z) * movingWeight;
				Quaternion val8 = Quaternion.Euler(2f * val7.z * num9, 2f * val7.x * num9, -3f * val7.x * num9);
				Quaternion val9 = Quaternion.SlerpUnclamped(Quaternion.identity, movementRotation, 1f + 0.2f * num6) * val8;
				Quaternion val10 = val * val9 * Quaternion.Inverse(val) * BowAimSpace.RootRotation(aimYaw, Sample(0, aimPitch, charge));
				Vector3 val11 = BowAimSpace.RootPosition(((Component)owner).transform.position, ((Component)owner).transform.lossyScale, aimYaw);
				val11 += val * movementPosition;
				val11 += Quaternion.Euler(0f, aimYaw, 0f) * Vector3.Scale(new Vector3(0f, 0.00075f, 0.0003f) * num2, ((Component)owner).transform.lossyScale);
				bones[0].SetPositionAndRotation(Vector3.Lerp(position, val11, poseWeight), Quaternion.Slerp(rotation, val10, poseWeight));
				applied[0] = bones[0].localRotation;
				appliedSpinePosition = bones[0].localPosition;
				Quaternion val12 = val * movementRotation * Quaternion.Inverse(val);
				float value2 = Plugin.MovingSpineBend.Value;
				bones[1].rotation = Quaternion.Slerp(Quaternion.identity, val12, (0.45f + 0.3f * value2) * num6 * poseWeight) * bones[1].rotation;
				applied[1] = bones[1].localRotation;
				bones[2].rotation = Quaternion.Slerp(Quaternion.identity, val12, 0.35f * value2 * num6 * poseWeight) * bones[2].rotation;
				applied[2] = bones[2].localRotation;
				if (Drawing && movingWeight > 0.001f)
				{
					bones[11].rotation = rotation3;
					bones[12].rotation = rotation4;
					applied[11] = bones[11].localRotation;
					applied[12] = bones[12].localRotation;
				}
				for (int j = 0; j < 2; j++)
				{
					beforeArmPosition[j] = bones[(j == 0) ? 4 : 8].localPosition;
				}
				if (!Drawing)
				{
					bones[2].rotation = Quaternion.Slerp(Quaternion.identity, lastAimCorrection, poseWeight) * bones[2].rotation;
					applied[2] = bones[2].localRotation;
					RotateArms(Quaternion.Slerp(Quaternion.identity, lastArmCorrection, poseWeight));
				}
				wrotePose = true;
				if (Object.op_Implicit((Object)(object)primaryString))
				{
					AlignBow(primaryString);
				}
				handSwayPhase = Mathf.Repeat(handSwayPhase + Time.deltaTime * Mathf.Lerp(0.65f, 1.5f, Mathf.Clamp01(((Vector3)(ref velocity)).magnitude / 4f)), 1f);
				BowHandSway.Sample(handSwayPhase, movingWeight * poseWeight, Plugin.HandSwayStrength.Value, val7.x, val7.z, out var x, out var y, out var z);
				x *= 1f + 0.25f * num9;
				y *= 1f - 0.15f * num9;
				Vector3 val13 = val * Vector3.Scale(new Vector3(x, y, z), ((Component)owner).transform.lossyScale);
				for (int k = 0; k < 2; k++)
				{
					Transform val14 = bones[(k == 0) ? 4 : 8];
					val14.position += val13;
					appliedArmPosition[k] = val14.localPosition;
				}
				wroteHandSway = true;
				return;
			}
			goto IL_00cf;
			IL_00cf:
			bool drawing2 = Drawing;
			Drawing = false;
			pending = false;
			poseWeight = (poseBlendProgress = 0f);
			breathWeight = 0f;
			headFollowCaptured = false;
			if (Object.op_Implicit((Object)(object)owner))
			{
				Publish(drawing2);
			}
			ClearArrow();
		}

		internal void AlignBow(BowStringVisual source)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: 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_0124: 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_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: 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_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: 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_018d: Unknown result type (might be due to invalid IL or missing references)
			if (!Drawing || !wrotePose || source.cut == null)
			{
				return;
			}
			if (!Object.op_Implicit((Object)(object)primaryString))
			{
				primaryString = source;
			}
			if ((Object)(object)source != (Object)(object)primaryString)
			{
				return;
			}
			Vector3 val = ((Component)source).transform.TransformPoint(source.cut.Grip) - NockWorld;
			if (!(((Vector3)(ref val)).sqrMagnitude < 1E-08f))
			{
				Quaternion val2 = Quaternion.FromToRotation(val, BowAimSpace.Direction(aimYaw, aimPitch));
				val2 = Quaternion.Slerp(Quaternion.identity, val2, poseWeight);
				Quaternion val3 = Quaternion.Slerp(Quaternion.identity, val2, 1f - movingWeight);
				bones[2].rotation = val3 * bones[2].rotation;
				Quaternion val4 = val2 * Quaternion.Inverse(val3);
				RotateArms(val4);
				Quaternion val5 = Quaternion.Euler(0f - aimPitch, aimYaw, 0f);
				if (!headFollowCaptured && poseWeight >= 0.98f)
				{
					headRelativeToAim = Quaternion.Inverse(val5) * bones[12].rotation;
					headFollowCaptured = true;
				}
				if (headFollowCaptured)
				{
					bones[12].rotation = val5 * headRelativeToAim;
				}
				lastAimCorrection = val3 * lastAimCorrection;
				lastArmCorrection = val4 * lastArmCorrection;
				applied[2] = bones[2].localRotation;
				applied[12] = bones[12].localRotation;
			}
		}

		private void RotateArms(Quaternion rotation)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = (bones[4].position + bones[8].position) * 0.5f;
			for (int i = 4; i <= 8; i += 4)
			{
				Transform val2 = bones[i];
				val2.SetPositionAndRotation(val + rotation * (val2.position - val), rotation * val2.rotation);
				applied[i] = val2.localRotation;
			}
		}

		internal void UpdateArrow(BowStringVisual source, Vector3 nock, bool drawing)
		{
			//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_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)primaryString))
			{
				primaryString = source;
			}
			if ((Object)(object)source != (Object)(object)primaryString)
			{
				return;
			}
			ItemData val = owner.GetAmmoItem();
			if (IsRemote)
			{
				GameObject val2 = ((remoteAmmo != 0 && Object.op_Implicit((Object)(object)ObjectDB.instance)) ? ObjectDB.instance.GetItemPrefab(remoteAmmo) : null);
				val = ((!Object.op_Implicit((Object)(object)val2)) ? null : val2.GetComponent<ItemDrop>()?.m_itemData);
			}
			GameObject val3 = val?.m_shared.m_attack?.m_attackProjectile;
			if (!drawing || !Object.op_Implicit((Object)(object)val3))
			{
				if (Object.op_Implicit((Object)(object)arrow))
				{
					arrow.SetActive(false);
				}
				return;
			}
			if ((Object)(object)val3 != (Object)(object)arrowPrefab)
			{
				ClearArrow();
				BuildArrow(val3, ((Component)source).gameObject.layer);
			}
			if (Object.op_Implicit((Object)(object)arrow))
			{
				BowStringVisual.Cut cut = source.cut;
				Vector3 val4 = ((Component)source).transform.TransformPoint(cut.Grip) + Vector3.up * 0.065f;
				Vector3 val5 = val4 - nock;
				if (!(((Vector3)(ref val5)).sqrMagnitude < 1E-06f))
				{
					Quaternion val6 = Quaternion.LookRotation(val5, ((Component)source).transform.TransformDirection(cut.Axis));
					arrow.transform.SetPositionAndRotation(nock - val6 * arrowBack, val6);
					arrow.SetActive(true);
				}
			}
		}

		private void BuildArrow(GameObject prefab, int layer)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0404: Unknown result type (might be due to invalid IL or missing references)
			//IL_0409: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			arrowPrefab = prefab;
			arrow = new GameObject("BowDraw_Nocked_" + ((Object)prefab).name);
			arrow.SetActive(false);
			List<Vector3> list = new List<Vector3>();
			GameObject val = Object.Instantiate<GameObject>(prefab, arrow.transform, false);
			val.transform.localPosition = Vector3.zero;
			val.transform.localRotation = Quaternion.identity;
			val.transform.localScale = Vector3.one;
			Component[] componentsInChildren = val.GetComponentsInChildren<Component>(true);
			foreach (Component val2 in componentsInChildren)
			{
				if (Object.op_Implicit((Object)(object)val2) && !(val2 is Transform) && !(val2 is MeshFilter) && !(val2 is MeshRenderer) && !(val2 is SkinnedMeshRenderer) && !(val2 is ParticleSystem) && !(val2 is ParticleSystemRenderer) && !(val2 is Light) && !(val2 is LightFlicker) && !(val2 is LODGroup))
				{
					Object.DestroyImmediate((Object)(object)val2);
				}
			}
			Transform[] componentsInChildren2 = val.GetComponentsInChildren<Transform>(true);
			foreach (Transform val3 in componentsInChildren2)
			{
				((Component)val3).gameObject.layer = layer;
			}
			Light[] componentsInChildren3 = val.GetComponentsInChildren<Light>(true);
			foreach (Light val4 in componentsInChildren3)
			{
				LightFlicker component = ((Component)val4).GetComponent<LightFlicker>();
				if (val4.intensity <= 0f)
				{
					Transform val5 = prefab.transform.Find(((Object)(object)val.transform == (Object)(object)((Component)val4).transform) ? "" : GetVisualPath(((Component)val4).transform, val.transform));
					LightFlicker val6 = (Object.op_Implicit((Object)(object)val5) ? ((Component)val5).GetComponent<LightFlicker>() : null);
					FieldInfo field = typeof(LightFlicker).GetField("m_baseIntensity", BindingFlags.Instance | BindingFlags.NonPublic);
					val4.intensity = ((Object.op_Implicit((Object)(object)val6) && field != null) ? ((float)field.GetValue(val6)) : 1.5f);
				}
				val4.renderMode = (LightRenderMode)1;
				if (Object.op_Implicit((Object)(object)component))
				{
					component.m_ttl = 0f;
				}
			}
			ParticleSystem[] componentsInChildren4 = val.GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem val7 in componentsInChildren4)
			{
				if (((Object)val7).name.IndexOf("trail", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					((Component)val7).gameObject.SetActive(false);
					continue;
				}
				MainModule main = val7.main;
				((MainModule)(ref main)).playOnAwake = true;
				((MainModule)(ref main)).stopAction = (ParticleSystemStopAction)0;
			}
			MeshFilter[] componentsInChildren5 = val.GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val8 in componentsInChildren5)
			{
				if (Object.op_Implicit((Object)(object)val8.sharedMesh))
				{
					Bounds bounds = val8.sharedMesh.bounds;
					Matrix4x4 val9 = arrow.transform.worldToLocalMatrix * ((Component)val8).transform.localToWorldMatrix;
					for (int n = 0; n < 8; n++)
					{
						list.Add(((Matrix4x4)(ref val9)).MultiplyPoint3x4(((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((n & 1) != 0) ? 1 : (-1)), (float)(((n & 2) != 0) ? 1 : (-1)), (float)(((n & 4) != 0) ? 1 : (-1))))));
					}
				}
			}
			val.SetActive(true);
			if (list.Count == 0)
			{
				ClearArrow();
				return;
			}
			float num = float.PositiveInfinity;
			foreach (Vector3 item in list)
			{
				num = Mathf.Min(num, item.z);
			}
			arrowBack = new Vector3(0f, 0f, num);
		}

		private static string GetVisualPath(Transform node, Transform root)
		{
			string text = ((Object)node).name;
			while (Object.op_Implicit((Object)(object)node.parent) && (Object)(object)node.parent != (Object)(object)root)
			{
				node = node.parent;
				text = ((Object)node).name + "/" + text;
			}
			return text;
		}

		private static void CopyVisual(Transform src, Transform dst, Transform root, int layer, List<Vector3> bounds)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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_00aa: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			//IL_0134: 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_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			((Component)dst).gameObject.layer = layer;
			MeshFilter component = ((Component)src).GetComponent<MeshFilter>();
			MeshRenderer component2 = ((Component)src).GetComponent<MeshRenderer>();
			if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component2) && Object.op_Implicit((Object)(object)component.sharedMesh))
			{
				((Component)dst).gameObject.AddComponent<MeshFilter>().sharedMesh = component.sharedMesh;
				MeshRenderer val = ((Component)dst).gameObject.AddComponent<MeshRenderer>();
				((Renderer)val).sharedMaterials = ((Renderer)component2).sharedMaterials;
				((Renderer)val).shadowCastingMode = ((Renderer)component2).shadowCastingMode;
				((Renderer)val).receiveShadows = ((Renderer)component2).receiveShadows;
				Bounds bounds2 = component.sharedMesh.bounds;
				Matrix4x4 val2 = root.worldToLocalMatrix * src.localToWorldMatrix;
				for (int i = 0; i < 8; i++)
				{
					bounds.Add(((Matrix4x4)(ref val2)).MultiplyPoint3x4(((Bounds)(ref bounds2)).center + Vector3.Scale(((Bounds)(ref bounds2)).extents, new Vector3((float)(((i & 1) != 0) ? 1 : (-1)), (float)(((i & 2) != 0) ? 1 : (-1)), (float)(((i & 4) != 0) ? 1 : (-1))))));
				}
			}
			foreach (Transform item in src)
			{
				Transform val3 = item;
				Transform transform = new GameObject(((Object)val3).name).transform;
				transform.SetParent(dst, false);
				transform.localPosition = val3.localPosition;
				transform.localRotation = val3.localRotation;
				transform.localScale = val3.localScale;
				CopyVisual(val3, transform, root, layer, bounds);
				((Component)transform).gameObject.SetActive(((Component)val3).gameObject.activeSelf);
			}
		}

		private void ClearArrow()
		{
			if (Object.op_Implicit((Object)(object)arrow))
			{
				Object.Destroy((Object)(object)arrow);
			}
			arrow = null;
			arrowPrefab = null;
		}

		private void OnDisable()
		{
			ActiveDrivers.Remove(this);
			Drawing = false;
			if (Object.op_Implicit((Object)(object)owner))
			{
				Publish(immediate: true);
			}
			Restore();
			ClearArrow();
		}

		private void O