Decompiled source of GFL2 Florence v1.1.2

FlorenceSuit.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using JigglePhysics;
using ModelReplacement;
using ModelReplacement.AvatarBodyUpdater;
using ModelReplacement.Scripts.Enemies;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyFileVersion("1.1.2")]
[assembly: AssemblyInformationalVersion("1.1.2")]
[assembly: AssemblyVersion("1.1.2.0")]
namespace FlorenceSuit;

[Serializable]
public struct FlorenceLightingContext
{
	public bool InsideFactory;

	public bool InsideShip;

	public bool Indoors
	{
		get
		{
			if (!InsideFactory)
			{
				return InsideShip;
			}
			return true;
		}
	}

	public float Floor
	{
		get
		{
			if (!Indoors)
			{
				return 0.075f;
			}
			return 0f;
		}
	}

	public FlorenceLightingContext(bool factory, bool ship)
	{
		InsideFactory = factory;
		InsideShip = ship;
	}
}
public sealed class FlorenceCorpseLightingContext
{
	private FlorenceLightingContext context;

	private bool trackedItem;

	public FlorenceCorpseLightingContext(FlorenceLightingContext death)
	{
		context = death;
	}

	public FlorenceLightingContext Observe(bool bodyInShip, bool hasHolder, FlorenceLightingContext holder, bool hasItem, FlorenceLightingContext item)
	{
		if (hasHolder)
		{
			context = holder;
			trackedItem = true;
		}
		else if (hasItem && trackedItem)
		{
			context = item;
		}
		if (!bodyInShip)
		{
			return context;
		}
		return new FlorenceLightingContext(factory: false, ship: true);
	}
}
[DefaultExecutionOrder(1100)]
public sealed class FlorenceAdaptiveLighting : MonoBehaviour
{
	private struct Draw
	{
		public Renderer Renderer;

		public int Slot;

		public bool Floor;

		public bool Ink;

		public bool ZZZFloor;

		public Color InkColor;
	}

	public Renderer[] receivers;

	private readonly List<Draw> draws = new List<Draw>();

	private MaterialPropertyBlock block;

	private MaterialPropertyBlock globalBlock;

	private Func<FlorenceLightingContext> contextReader;

	private bool initialized;

	private static readonly int FloorId = Shader.PropertyToID("_GflAmbientFloor");

	private static readonly int InkId = Shader.PropertyToID("_InkColor");

	private static readonly string[] FrameVectors = new string[5] { "_GflFaceForward", "_ZZZFaceCenter", "_ZZZFaceRight", "_ZZZFaceUp", "_ZZZFaceForward" };

	private static readonly string[] FrameFloats = new string[2] { "_ZZZFaceHalfWidth", "_ZZZFaceFrameValid" };

	public FlorenceLightingContext Context { get; private set; }

	public float CurrentFloor => Context.Floor;

	public int FloorSlots { get; private set; }

	public int InkSlots { get; private set; }

	private void Awake()
	{
		Rebind();
		Refresh();
	}

	private void OnEnable()
	{
		if (initialized)
		{
			Refresh();
		}
	}

	public void Rebind()
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Expected O, but got Unknown
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Expected O, but got Unknown
		//IL_0111: 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_0116: Unknown result type (might be due to invalid IL or missing references)
		if (block == null)
		{
			block = new MaterialPropertyBlock();
		}
		if (globalBlock == null)
		{
			globalBlock = new MaterialPropertyBlock();
		}
		draws.Clear();
		int floorSlots = (InkSlots = 0);
		FloorSlots = floorSlots;
		receivers = ((Component)this).GetComponentsInChildren<Renderer>(true);
		Renderer[] array = receivers;
		foreach (Renderer val in array)
		{
			Material[] sharedMaterials = val.sharedMaterials;
			for (int i = 0; i < sharedMaterials.Length; i++)
			{
				Material val2 = sharedMaterials[i];
				if (!Object.op_Implicit((Object)(object)val2))
				{
					continue;
				}
				bool flag = val2.HasProperty(FloorId) || val2.HasProperty("_ZZZOutdoorAmbientFloor");
				bool flag2 = val2.HasProperty(InkId);
				if (flag || flag2)
				{
					draws.Add(new Draw
					{
						Renderer = val,
						Slot = i,
						Floor = flag,
						ZZZFloor = val2.HasProperty("_ZZZOutdoorAmbientFloor"),
						Ink = flag2,
						InkColor = (flag2 ? val2.GetColor(InkId) : Color.black)
					});
					if (flag)
					{
						FloorSlots++;
					}
					if (flag2)
					{
						InkSlots++;
					}
				}
			}
		}
		initialized = true;
		Apply(Context);
	}

	public void BindContext(Func<FlorenceLightingContext> reader)
	{
		contextReader = reader;
		Refresh();
	}

	public FlorenceLightingContext ReadContext()
	{
		if (contextReader == null)
		{
			return Context;
		}
		return contextReader();
	}

	public void InheritContext(FlorenceAdaptiveLighting source)
	{
		if (Object.op_Implicit((Object)(object)source))
		{
			BindContext(source.ReadContext);
		}
	}

	public void Refresh()
	{
		Apply(ReadContext());
	}

	public void Apply(FlorenceLightingContext context)
	{
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		if (!initialized)
		{
			Rebind();
		}
		Context = context;
		foreach (Draw draw in draws)
		{
			if (!Object.op_Implicit((Object)(object)draw.Renderer))
			{
				continue;
			}
			block.Clear();
			draw.Renderer.GetPropertyBlock(block, draw.Slot);
			draw.Renderer.GetPropertyBlock(globalBlock);
			string[] frameVectors = FrameVectors;
			foreach (string text in frameVectors)
			{
				if (globalBlock.HasVector(text))
				{
					block.SetVector(text, globalBlock.GetVector(text));
				}
			}
			frameVectors = FrameFloats;
			foreach (string text2 in frameVectors)
			{
				if (globalBlock.HasFloat(text2))
				{
					block.SetFloat(text2, globalBlock.GetFloat(text2));
				}
			}
			if (draw.Floor)
			{
				block.SetFloat(draw.ZZZFloor ? Shader.PropertyToID("_ZZZOutdoorAmbientFloor") : FloorId, context.Floor);
			}
			if (draw.Ink)
			{
				Color inkColor = draw.InkColor;
				if (context.Indoors)
				{
					((Color)(ref inkColor))..ctor(0f, 0f, 0f, inkColor.a);
				}
				block.SetColor(InkId, inkColor);
			}
			draw.Renderer.SetPropertyBlock(block, draw.Slot);
		}
	}

	private void LateUpdate()
	{
		Refresh();
	}
}
internal static class FlorenceLightingControl
{
	private sealed class Death
	{
		internal ulong Owner;

		internal FlorenceLightingContext Context;
	}

	private static readonly Dictionary<PlayerControllerB, Death> deaths = new Dictionary<PlayerControllerB, Death>();

	private static readonly FieldInfo sourceField = AccessTools.Field(typeof(BodyReplacementBase), "replacementModel");

	private static readonly FieldInfo shadowField = AccessTools.Field(typeof(BodyReplacementBase), "replacementModelShadow");

	private static readonly FieldInfo viewField = AccessTools.Field(typeof(BodyReplacementBase), "replacementViewModel");

	private static FlorenceLightingContext Native(PlayerControllerB player)
	{
		if (!Object.op_Implicit((Object)(object)player))
		{
			return default(FlorenceLightingContext);
		}
		return new FlorenceLightingContext(player.isInsideFactory, player.isInHangarShipRoom);
	}

	internal static void Install(Harmony harmony)
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Expected O, but got Unknown
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Expected O, but got Unknown
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Expected O, but got Unknown
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Expected O, but got Unknown
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Expected O, but got Unknown
		harmony.Patch((MethodBase)AccessTools.Method(typeof(BodyReplacementBase), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(FlorenceLightingControl), "Created", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		MethodInfo methodInfo = AccessTools.Method(typeof(BodyReplacementBase).Assembly.GetType("ModelReplacement.Scripts.Player.ViewModelUpdater"), "AssignViewModelReplacement", new Type[2]
		{
			typeof(GameObject),
			typeof(GameObject)
		}, (Type[])null);
		if (methodInfo != null)
		{
			harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(FlorenceLightingControl), "ViewAssigned", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		MethodInfo methodInfo2 = AccessTools.Method(typeof(BodyReplacementBase), "LoadRagdollReplacement", (Type[])null, (Type[])null);
		if (methodInfo2 != null)
		{
			harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(FlorenceLightingControl), "Ragdoll", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		harmony.Patch((MethodBase)AccessTools.Method(typeof(PlayerControllerB), "KillPlayer", (Type[])null, (Type[])null), new HarmonyMethod(typeof(FlorenceLightingControl), "CaptureDeath", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		harmony.Patch((MethodBase)AccessTools.Method(typeof(PlayerControllerB), "SpawnDeadBody", (Type[])null, (Type[])null), new HarmonyMethod(typeof(FlorenceLightingControl), "CaptureRemoteDeath", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		harmony.Patch((MethodBase)AccessTools.Method(typeof(StartOfRound), "ReviveDeadPlayers", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(FlorenceLightingControl), "Clear", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
	}

	private static void ViewAssigned(GameObject __0, GameObject __1)
	{
		if (Object.op_Implicit((Object)(object)__0) && Object.op_Implicit((Object)(object)__1) && ((Object)__1).name.StartsWith("Florence_", StringComparison.Ordinal))
		{
			Bind(__1, __0.GetComponent<PlayerControllerB>());
		}
	}

	private static void CaptureDeath(PlayerControllerB __instance)
	{
		if (Object.op_Implicit((Object)(object)__instance) && !__instance.isPlayerDead)
		{
			deaths[__instance] = new Death
			{
				Owner = ((NetworkBehaviour)__instance).OwnerClientId,
				Context = Native(__instance)
			};
		}
	}

	private static void CaptureRemoteDeath(PlayerControllerB deadPlayerController)
	{
		if (Object.op_Implicit((Object)(object)deadPlayerController) && !((NetworkBehaviour)deadPlayerController).IsOwner)
		{
			deaths[deadPlayerController] = new Death
			{
				Owner = ((NetworkBehaviour)deadPlayerController).OwnerClientId,
				Context = Native(deadPlayerController)
			};
		}
	}

	private static void Created(BodyReplacementBase __instance)
	{
		if (!(((object)__instance).GetType().Assembly != typeof(Plugin).Assembly) && Object.op_Implicit((Object)(object)__instance.controller))
		{
			FieldInfo[] array = new FieldInfo[3] { sourceField, shadowField, viewField };
			for (int i = 0; i < array.Length; i++)
			{
				object? obj = array[i]?.GetValue(__instance);
				Bind((GameObject)((obj is GameObject) ? obj : null), __instance.controller);
			}
		}
	}

	internal static void AttachView(GameObject playerObject, GameObject view)
	{
		if (Object.op_Implicit((Object)(object)playerObject) && Object.op_Implicit((Object)(object)view) && Object.op_Implicit((Object)(object)view.GetComponent<FlorenceAdaptiveLighting>()))
		{
			Bind(view, playerObject.GetComponent<PlayerControllerB>());
		}
	}

	private static void Ragdoll(BodyReplacementBase __instance, GameObject __result)
	{
		if (((object)__instance).GetType().Assembly == typeof(Plugin).Assembly && Object.op_Implicit((Object)(object)__instance.controller))
		{
			Bind(__result, __instance.controller, corpse: true);
		}
	}

	private static void Bind(GameObject model, PlayerControllerB player, bool corpse = false)
	{
		if (!Object.op_Implicit((Object)(object)model) || !Object.op_Implicit((Object)(object)player))
		{
			return;
		}
		FlorenceAdaptiveLighting florenceAdaptiveLighting = model.GetComponent<FlorenceAdaptiveLighting>() ?? model.AddComponent<FlorenceAdaptiveLighting>();
		florenceAdaptiveLighting.Rebind();
		ulong owner = ((NetworkBehaviour)player).OwnerClientId;
		if (!corpse)
		{
			florenceAdaptiveLighting.BindContext(() => (!Object.op_Implicit((Object)(object)player) || ((NetworkBehaviour)player).OwnerClientId != owner) ? default(FlorenceLightingContext) : Native(player));
			return;
		}
		Death value;
		FlorenceLightingContext death = ((deaths.TryGetValue(player, out value) && value.Owner == owner) ? value.Context : Native(player));
		FlorenceCorpseLightingContext corpseContext = new FlorenceCorpseLightingContext(death);
		DeadBodyInfo nativeBody = player.deadBody;
		florenceAdaptiveLighting.BindContext(delegate
		{
			if (!Object.op_Implicit((Object)(object)nativeBody))
			{
				return corpseContext.Observe(bodyInShip: false, hasHolder: false, default(FlorenceLightingContext), hasItem: false, default(FlorenceLightingContext));
			}
			GrabbableObject grabBodyObject = nativeBody.grabBodyObject;
			PlayerControllerB val = ((Object.op_Implicit((Object)(object)grabBodyObject) && grabBodyObject.isHeld) ? grabBodyObject.playerHeldBy : null);
			return corpseContext.Observe(nativeBody.isInShip || nativeBody.parentedToShip, Object.op_Implicit((Object)(object)val), Native(val), Object.op_Implicit((Object)(object)grabBodyObject), Object.op_Implicit((Object)(object)grabBodyObject) ? new FlorenceLightingContext(grabBodyObject.isInFactory, grabBodyObject.isInShipRoom) : default(FlorenceLightingContext));
		});
	}

	internal static void Clear()
	{
		deaths.Clear();
	}
}
public static class FlorenceAssets
{
	public const string ResourceName = "FlorenceSuit.florencesuits";

	private static AssetBundle bundle;

	private static Stream resourceStream;

	internal static void SetLoadedBundle(AssetBundle loaded, Stream stream)
	{
		resourceStream = stream;
		bundle = loaded;
	}

	public static AssetBundle Load()
	{
		if (Object.op_Implicit((Object)(object)bundle))
		{
			return bundle;
		}
		Stream manifestResourceStream = typeof(FlorenceAssets).Assembly.GetManifestResourceStream("FlorenceSuit.florencesuits");
		if (manifestResourceStream == null)
		{
			throw new InvalidOperationException("The Florence model resource is missing from FlorenceSuit.dll.");
		}
		try
		{
			if (!manifestResourceStream.CanRead || !manifestResourceStream.CanSeek)
			{
				throw new InvalidOperationException("The Florence model resource must be readable and seekable.");
			}
			AssetBundle obj = AssetBundle.LoadFromStream(manifestResourceStream);
			if (!Object.op_Implicit((Object)(object)obj))
			{
				throw new InvalidOperationException("The embedded Florence model bundle could not be loaded.");
			}
			resourceStream = manifestResourceStream;
			bundle = obj;
			return bundle;
		}
		catch
		{
			manifestResourceStream.Dispose();
			throw;
		}
	}
}
public enum AttentionKind
{
	Player,
	Enemy,
	Item
}
public struct AttentionCandidate
{
	public int Key;

	public AttentionKind Kind;

	public float Distance;

	public bool Speaking;

	public bool Eligible;

	public AttentionCandidate(int key, AttentionKind kind, float distance, bool speaking = true, bool eligible = true)
	{
		Key = key;
		Kind = kind;
		Distance = distance;
		Speaking = speaking;
		Eligible = eligible;
	}
}
public sealed class FlorenceAttentionSelection
{
	private float lastSpeech;

	private float selectedAt;

	public int CurrentKey { get; private set; }

	public bool HasTarget { get; private set; }

	public AttentionKind CurrentKind { get; private set; }

	public void Reset()
	{
		HasTarget = false;
		CurrentKey = 0;
		lastSpeech = (selectedAt = 0f);
	}

	public int Choose(IList<AttentionCandidate> candidates, float now, float pauseHold = 1.2f)
	{
		AttentionCandidate attentionCandidate = default(AttentionCandidate);
		AttentionCandidate c = default(AttentionCandidate);
		AttentionCandidate c2 = default(AttentionCandidate);
		bool flag = false;
		bool flag2 = false;
		bool flag3 = false;
		foreach (AttentionCandidate candidate in candidates)
		{
			if (!candidate.Eligible || float.IsNaN(candidate.Distance) || float.IsInfinity(candidate.Distance) || candidate.Distance < 0f)
			{
				continue;
			}
			if (HasTarget && candidate.Key == CurrentKey && candidate.Kind == CurrentKind)
			{
				attentionCandidate = candidate;
				flag = true;
			}
			if (candidate.Kind == AttentionKind.Player)
			{
				if (candidate.Speaking && (!flag2 || candidate.Distance < c.Distance))
				{
					c = candidate;
					flag2 = true;
				}
			}
			else if (!flag3 || candidate.Kind < c2.Kind || (candidate.Kind == c2.Kind && candidate.Distance < c2.Distance))
			{
				c2 = candidate;
				flag3 = true;
			}
		}
		if (flag && attentionCandidate.Kind == AttentionKind.Player && attentionCandidate.Speaking)
		{
			lastSpeech = now;
		}
		if (flag2)
		{
			if (flag && attentionCandidate.Kind == AttentionKind.Player && attentionCandidate.Speaking && (now - selectedAt < 0.65f || c.Distance >= attentionCandidate.Distance * 0.7f))
			{
				return CurrentKey;
			}
			return Select(c, now);
		}
		if (flag && attentionCandidate.Kind == AttentionKind.Player && now - lastSpeech <= Mathf.Clamp(pauseHold, 0f, 5f))
		{
			return CurrentKey;
		}
		if (flag3)
		{
			if (flag && attentionCandidate.Kind == c2.Kind && attentionCandidate.Kind != AttentionKind.Player && (now - selectedAt < 1.5f || c2.Distance >= attentionCandidate.Distance * 0.7f))
			{
				return CurrentKey;
			}
			return Select(c2, now);
		}
		Reset();
		return 0;
	}

	private int Select(AttentionCandidate c, float now)
	{
		if (!HasTarget || c.Key != CurrentKey || c.Kind != CurrentKind)
		{
			selectedAt = now;
		}
		HasTarget = true;
		CurrentKey = c.Key;
		CurrentKind = c.Kind;
		if (c.Kind == AttentionKind.Player && c.Speaking)
		{
			lastSpeech = now;
		}
		return CurrentKey;
	}

	public static bool InView(Vector3 origin, Vector3 forward, Vector3 point, float radius)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: 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_002a: 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_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = point - origin;
		float magnitude = ((Vector3)(ref val)).magnitude;
		if (magnitude < 0.15f || magnitude > radius)
		{
			return false;
		}
		Vector3 val2 = Vector3.ProjectOnPlane(val, Vector3.up);
		Vector3 val3 = Vector3.ProjectOnPlane(forward, Vector3.up);
		if (Vector3.Angle(val2, val3) <= 65f)
		{
			return Mathf.Abs(Mathf.Atan2(val.y, ((Vector3)(ref val2)).magnitude) * 57.29578f) <= 60f;
		}
		return false;
	}

	public static bool ActiveSpeech(bool speaking, float amplitude)
	{
		if (speaking && !float.IsNaN(amplitude) && !float.IsInfinity(amplitude))
		{
			return amplitude >= 0.002f;
		}
		return false;
	}

	public static bool Visible(Vector3 origin, Vector3 point, int mask, Transform observer, Transform model, Transform target, RaycastHit[] hits)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = point - origin;
		float magnitude = ((Vector3)(ref val)).magnitude;
		if (magnitude < 0.05f)
		{
			return true;
		}
		int num = Physics.RaycastNonAlloc(origin, val / magnitude, hits, magnitude, mask, (QueryTriggerInteraction)1);
		if (num == hits.Length)
		{
			return false;
		}
		for (int i = 0; i < num; i++)
		{
			Transform transform = ((RaycastHit)(ref hits[i])).transform;
			if (Object.op_Implicit((Object)(object)transform) && (!Object.op_Implicit((Object)(object)observer) || !transform.IsChildOf(observer)) && (!Object.op_Implicit((Object)(object)model) || !transform.IsChildOf(model)) && (!Object.op_Implicit((Object)(object)target) || !transform.IsChildOf(target)))
			{
				return false;
			}
		}
		return true;
	}
}
public sealed class FlorenceAttention
{
	private readonly FlorenceAttentionSelection selection = new FlorenceAttentionSelection();

	private readonly List<AttentionCandidate> candidates = new List<AttentionCandidate>(64);

	private readonly Dictionary<int, Object> objects = new Dictionary<int, Object>();

	private readonly RaycastHit[] hits = (RaycastHit[])(object)new RaycastHit[24];

	private EnemyAI[] enemies = (EnemyAI[])(object)new EnemyAI[0];

	private GrabbableObject[] items = (GrabbableObject[])(object)new GrabbableObject[0];

	private Object target;

	private float nextScan;

	private float nextSceneScan;

	public void Reset()
	{
		selection.Reset();
		target = null;
		nextScan = (nextSceneScan = 0f);
	}

	private static Vector3 Point(Object value)
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: 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_0076: 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_0065: 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_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_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		PlayerControllerB val = (PlayerControllerB)(object)((value is PlayerControllerB) ? value : null);
		if (val != null)
		{
			if (!Object.op_Implicit((Object)(object)val.playerEye))
			{
				return ((Component)val).transform.position + Vector3.up * 1.6f;
			}
			return val.playerEye.position;
		}
		EnemyAI val2 = (EnemyAI)(object)((value is EnemyAI) ? value : null);
		if (val2 != null)
		{
			if (!Object.op_Implicit((Object)(object)val2.eye))
			{
				return ((Component)val2).transform.position + Vector3.up;
			}
			return val2.eye.position;
		}
		GrabbableObject val3 = (GrabbableObject)(object)((value is GrabbableObject) ? value : null);
		if (val3 != null)
		{
			Renderer componentInChildren = ((Component)val3).GetComponentInChildren<Renderer>();
			if (!Object.op_Implicit((Object)(object)componentInChildren))
			{
				return ((Component)val3).transform.position;
			}
			Bounds bounds = componentInChildren.bounds;
			return ((Bounds)(ref bounds)).center;
		}
		return Vector3.zero;
	}

	private void Add(Component value, AttentionKind kind, Vector3 origin, Vector3 forward, float range, bool speaking, PlayerControllerB owner, Transform model)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = Point((Object)(object)value);
		if (FlorenceAttentionSelection.InView(origin, forward, val, range))
		{
			int mask = (Object.op_Implicit((Object)(object)StartOfRound.Instance) ? StartOfRound.Instance.collidersAndRoomMaskAndDefault : (-5));
			if (FlorenceAttentionSelection.Visible(origin, val, mask, ((Component)owner).transform, model, value.transform, hits))
			{
				int instanceID = ((Object)value).GetInstanceID();
				objects[instanceID] = (Object)(object)value;
				candidates.Add(new AttentionCandidate(instanceID, kind, Vector3.Distance(origin, val), speaking));
			}
		}
	}

	public bool Resolve(PlayerControllerB owner, Transform model, Vector3 origin, Vector3 forward, float now, out Vector3 direction)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: 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_01ac: Unknown result type (might be due to invalid IL or missing references)
		direction = forward;
		if (!Object.op_Implicit((Object)(object)owner) || owner.isPlayerDead || !owner.isPlayerControlled || !Object.op_Implicit((Object)(object)StartOfRound.Instance))
		{
			Reset();
			return false;
		}
		if (now >= nextScan)
		{
			nextScan = now + 0.1f;
			candidates.Clear();
			objects.Clear();
			if (now >= nextSceneScan)
			{
				nextSceneScan = now + 1f;
				enemies = Object.FindObjectsOfType<EnemyAI>();
				items = Object.FindObjectsOfType<GrabbableObject>();
			}
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (Object.op_Implicit((Object)(object)val) && !((Object)(object)val == (Object)(object)owner) && val.isPlayerControlled && !val.isPlayerDead && ((Component)val).gameObject.activeInHierarchy)
				{
					bool speaking = FlorenceVoiceActivity.IsSpeaking(val);
					Add((Component)(object)val, AttentionKind.Player, origin, forward, Plugin.TalkingPlayersRange.Value, speaking, owner, model);
				}
			}
			EnemyAI[] array = enemies;
			foreach (EnemyAI val2 in array)
			{
				if (Object.op_Implicit((Object)(object)val2) && !val2.isEnemyDead && ((Behaviour)val2).isActiveAndEnabled)
				{
					Add((Component)(object)val2, AttentionKind.Enemy, origin, forward, Plugin.EnemiesRange.Value, speaking: false, owner, model);
				}
			}
			GrabbableObject[] array2 = items;
			foreach (GrabbableObject val3 in array2)
			{
				if (Object.op_Implicit((Object)(object)val3) && !val3.isHeld && !val3.isPocketed && !val3.isHeldByEnemy && ((Behaviour)val3).isActiveAndEnabled)
				{
					Add((Component)(object)val3, AttentionKind.Item, origin, forward, Plugin.ItemsRange.Value, speaking: false, owner, model);
				}
			}
			int key = selection.Choose(candidates, now, Plugin.SpeechPauseHold.Value);
			target = ((selection.HasTarget && objects.TryGetValue(key, out var value)) ? value : null);
		}
		if (!Object.op_Implicit(target))
		{
			return false;
		}
		Object obj = target;
		PlayerControllerB val4 = (PlayerControllerB)(object)((obj is PlayerControllerB) ? obj : null);
		if (val4 == null || (val4.isPlayerControlled && !val4.isPlayerDead))
		{
			Object obj2 = target;
			EnemyAI val5 = (EnemyAI)(object)((obj2 is EnemyAI) ? obj2 : null);
			if (val5 == null || !val5.isEnemyDead)
			{
				Object obj3 = target;
				GrabbableObject val6 = (GrabbableObject)(object)((obj3 is GrabbableObject) ? obj3 : null);
				if (val6 == null || (!val6.isHeld && !val6.isPocketed && !val6.isHeldByEnemy))
				{
					direction = Point(target) - origin;
					return ((Vector3)(ref direction)).sqrMagnitude > 1E-06f;
				}
			}
		}
		target = null;
		selection.Reset();
		nextScan = 0f;
		return false;
	}
}
internal static class FlorenceVoiceActivity
{
	private static Type commsType;

	private static object comms;

	private static readonly Dictionary<int, float> retry = new Dictionary<int, float>();

	private static readonly Dictionary<int, object> states = new Dictionary<int, object>();

	internal static bool IsSpeaking(PlayerControllerB player)
	{
		object obj = FlorenceFace.Read(player, "voicePlayerState") ?? FlorenceFace.Read(FlorenceFace.Read(player, "currentVoiceChatIngameSettings"), "_playerState");
		int instanceID = ((Object)player).GetInstanceID();
		if (obj == null && states.TryGetValue(instanceID, out var value))
		{
			obj = value;
		}
		if (obj == null && (!retry.TryGetValue(instanceID, out var value2) || Time.unscaledTime >= value2))
		{
			retry[instanceID] = Time.unscaledTime + 1f;
			comms = FlorenceFace.Read(StartOfRound.Instance, "voiceChatModule");
			if (comms != null)
			{
				commsType = comms.GetType();
				string text = (((NetworkBehaviour)player).IsOwner ? (FlorenceFace.Read(comms, "LocalPlayerName") as string) : (FlorenceFace.Read(player, "voicePlayerName") as string));
				if (!string.IsNullOrEmpty(text))
				{
					try
					{
						obj = commsType.GetMethod("FindPlayer", new Type[1] { typeof(string) })?.Invoke(comms, new object[1] { text });
						if (obj != null)
						{
							states[instanceID] = obj;
						}
					}
					catch
					{
					}
				}
			}
		}
		object obj3 = FlorenceFace.Read(obj, "IsSpeaking");
		bool flag = default(bool);
		int num;
		if (obj3 is bool)
		{
			flag = (bool)obj3;
			num = 1;
		}
		else
		{
			num = 0;
		}
		bool flag2 = (byte)((uint)num & (flag ? 1u : 0u)) != 0;
		obj3 = FlorenceFace.Read(obj, "IsConnected");
		if (obj3 is bool && !(bool)obj3)
		{
			return false;
		}
		if (!(FlorenceFace.Read(obj, "Amplitude") is float amplitude))
		{
			return flag2;
		}
		return FlorenceAttentionSelection.ActiveSpeech(flag2, amplitude);
	}
}
public sealed class FlorenceBundleCache
{
	public const string PackedSHA256 = "ec8e10c068064e28714108549467c117cdb25d4819ec2f4209dae2fc53b27349";

	public const uint ContentCRC = 3526463548u;

	private string packedPath;

	private string pendingPath;

	private FileStream output;

	private SHA256 digest;

	public AssetBundle Bundle { get; private set; }

	public bool CacheHit { get; private set; }

	public bool Rebuilt { get; private set; }

	public bool UsedFallback { get; private set; }

	public string Warning { get; private set; }

	public string CachePath { get; private set; }

	private bool Prepare(string directory)
	{
		try
		{
			Directory.CreateDirectory(directory);
			CachePath = Path.Combine(directory, "ec8e10c068064e28714108549467c117cdb25d4819ec2f4209dae2fc53b27349.bundle");
			string text = Guid.NewGuid().ToString("N");
			packedPath = Path.Combine(directory, "ec8e10c068064e28714108549467c117cdb25d4819ec2f4209dae2fc53b27349." + text + ".packed");
			pendingPath = Path.Combine(directory, "ec8e10c068064e28714108549467c117cdb25d4819ec2f4209dae2fc53b27349." + text + ".pending");
			return true;
		}
		catch (Exception ex)
		{
			Warning = "Model cache unavailable: " + ex.Message;
			return false;
		}
	}

	private bool OpenOutput(Stream source)
	{
		try
		{
			source.Position = 0L;
			output = new FileStream(packedPath, FileMode.CreateNew, FileAccess.Write, FileShare.None);
			digest = SHA256.Create();
			return true;
		}
		catch (Exception ex)
		{
			Warning = "Model cache staging failed: " + ex.Message;
			CloseOutput();
			return false;
		}
	}

	private int Copy(Stream source, byte[] buffer)
	{
		try
		{
			int num = source.Read(buffer, 0, buffer.Length);
			if (num > 0)
			{
				output.Write(buffer, 0, num);
				digest.TransformBlock(buffer, 0, num, buffer, 0);
			}
			return num;
		}
		catch (Exception ex)
		{
			Warning = "Model cache write failed: " + ex.Message;
			return -1;
		}
	}

	private bool FinishOutput()
	{
		try
		{
			digest.TransformFinalBlock(Array.Empty<byte>(), 0, 0);
			if (BitConverter.ToString(digest.Hash).Replace("-", "").ToLowerInvariant() != "ec8e10c068064e28714108549467c117cdb25d4819ec2f4209dae2fc53b27349")
			{
				Warning = "Embedded model checksum differs; loading directly.";
				return false;
			}
			return true;
		}
		catch (Exception ex)
		{
			Warning = "Model checksum verification failed: " + ex.Message;
			return false;
		}
		finally
		{
			CloseOutput();
		}
	}

	private void CloseOutput()
	{
		output?.Dispose();
		output = null;
		digest?.Dispose();
		digest = null;
	}

	private void RemoveOwnedTemporaryFiles()
	{
		CloseOutput();
		string[] array = new string[2] { packedPath, pendingPath };
		foreach (string text in array)
		{
			if (string.IsNullOrEmpty(text))
			{
				continue;
			}
			try
			{
				if (File.Exists(text))
				{
					File.Delete(text);
				}
			}
			catch (Exception)
			{
			}
		}
	}

	private bool Commit()
	{
		try
		{
			if (File.Exists(CachePath))
			{
				File.Delete(CachePath);
			}
			File.Move(pendingPath, CachePath);
			return true;
		}
		catch (Exception ex)
		{
			Warning = "Model cache commit failed: " + ex.Message;
			return false;
		}
	}

	private AssetBundleCreateRequest LoadFile()
	{
		try
		{
			return AssetBundle.LoadFromFileAsync(CachePath, 3526463548u);
		}
		catch (Exception ex)
		{
			Warning = "Model cache load failed: " + ex.Message;
			return null;
		}
	}

	private AssetBundleRecompressOperation Recompress()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			return AssetBundle.RecompressAssetBundleAsync(packedPath, pendingPath, BuildCompression.LZ4Runtime, 3526463548u, (ThreadPriority)0);
		}
		catch (Exception ex)
		{
			Warning = "Model cache conversion failed: " + ex.Message;
			return null;
		}
	}

	private AssetBundleCreateRequest LoadDirect(Stream source)
	{
		try
		{
			source.Position = 0L;
			return AssetBundle.LoadFromStreamAsync(source, 3526463548u);
		}
		catch (Exception ex)
		{
			Warning = "Direct model load failed: " + ex.Message;
			return null;
		}
	}

	public IEnumerator Load(Stream source, string directory)
	{
		if (source == null)
		{
			Warning = "Missing embedded models.";
			yield break;
		}
		try
		{
			if (Prepare(directory))
			{
				if (File.Exists(CachePath))
				{
					AssetBundleCreateRequest warm = LoadFile();
					if (warm != null)
					{
						yield return warm;
						if (Object.op_Implicit((Object)(object)warm.assetBundle))
						{
							Bundle = warm.assetBundle;
							CacheHit = true;
							yield break;
						}
					}
				}
				bool staged = OpenOutput(source);
				if (staged)
				{
					byte[] buffer = new byte[2097152];
					while (true)
					{
						int num = Copy(source, buffer);
						if (num < 0)
						{
							staged = false;
							break;
						}
						if (num == 0)
						{
							break;
						}
						yield return null;
					}
					if (staged)
					{
						staged = FinishOutput();
					}
					else
					{
						CloseOutput();
					}
				}
				if (staged)
				{
					AssetBundleRecompressOperation convert = Recompress();
					if (convert != null)
					{
						yield return convert;
						if (convert.success && Commit())
						{
							AssetBundleCreateRequest warm = LoadFile();
							if (warm != null)
							{
								yield return warm;
								if (Object.op_Implicit((Object)(object)warm.assetBundle))
								{
									Bundle = warm.assetBundle;
									Rebuilt = true;
									yield break;
								}
							}
						}
						else
						{
							Warning = "Model cache conversion did not complete: " + convert.humanReadableResult;
						}
					}
				}
			}
			UsedFallback = true;
			AssetBundleCreateRequest direct = LoadDirect(source);
			if (direct != null)
			{
				yield return direct;
				Bundle = direct.assetBundle;
			}
		}
		finally
		{
			RemoveOwnedTemporaryFiles();
		}
	}
}
[DefaultExecutionOrder(325)]
public class FlorenceChestCorrectives : MonoBehaviour
{
	private Transform[] breast;

	private Vector3[] rest;

	private Vector3[] travel;

	private SkinnedMeshRenderer[] cloth;

	private int[][] indices;

	private float[][] previous;

	private bool ready;

	public static string ShapeName(int side, int axis, int sign)
	{
		return "FlorenceChest_" + ((side == 0) ? "L" : "R") + "_" + "XYZ"[axis] + ((sign == 0) ? "_Pos" : "_Neg");
	}

	private void Awake()
	{
		Initialize();
	}

	public bool Initialize()
	{
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: 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_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_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		if (ready)
		{
			return true;
		}
		breast = (Transform[])(object)new Transform[2];
		rest = (Vector3[])(object)new Vector3[2];
		Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(true);
		foreach (Transform val in componentsInChildren)
		{
			if (((Object)val).name == "DEF-breast.L")
			{
				breast[0] = val;
			}
			else if (((Object)val).name == "DEF-breast.R")
			{
				breast[1] = val;
			}
		}
		if (!Object.op_Implicit((Object)(object)breast[0]) || !Object.op_Implicit((Object)(object)breast[1]))
		{
			return false;
		}
		Mesh val2 = null;
		MeshFilter[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<MeshFilter>(true);
		foreach (MeshFilter val3 in componentsInChildren2)
		{
			if (((Object)val3).name == "FlorenceChestCalibration")
			{
				val2 = val3.sharedMesh;
				break;
			}
		}
		if (!Object.op_Implicit((Object)(object)val2) || val2.vertexCount != 4)
		{
			return false;
		}
		Vector3[] vertices = val2.vertices;
		travel = (Vector3[])(object)new Vector3[2]
		{
			vertices[2],
			vertices[3]
		};
		rest[0] = vertices[0];
		rest[1] = vertices[1];
		List<SkinnedMeshRenderer> list = new List<SkinnedMeshRenderer>();
		List<int[]> list2 = new List<int[]>();
		SkinnedMeshRenderer[] componentsInChildren3 = ((Component)this).GetComponentsInChildren<SkinnedMeshRenderer>(true);
		foreach (SkinnedMeshRenderer val4 in componentsInChildren3)
		{
			if (!Object.op_Implicit((Object)(object)val4.sharedMesh) || val4.sharedMesh.GetBlendShapeIndex(ShapeName(0, 0, 0)) < 0)
			{
				continue;
			}
			int[] array = new int[12];
			for (int j = 0; j < 2; j++)
			{
				for (int k = 0; k < 3; k++)
				{
					for (int l = 0; l < 2; l++)
					{
						int num = j * 6 + k * 2 + l;
						array[num] = val4.sharedMesh.GetBlendShapeIndex(ShapeName(j, k, l));
						if (array[num] < 0)
						{
							return false;
						}
					}
				}
			}
			list.Add(val4);
			list2.Add(array);
		}
		cloth = list.ToArray();
		indices = list2.ToArray();
		previous = new float[cloth.Length][];
		for (int m = 0; m < cloth.Length; m++)
		{
			previous[m] = new float[12];
			for (int n = 0; n < 12; n++)
			{
				previous[m][n] = -1f;
			}
		}
		ready = cloth.Length != 0;
		return ready;
	}

	public void Apply()
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		if (!ready && !Initialize())
		{
			return;
		}
		for (int i = 0; i < 2; i++)
		{
			if (!Object.op_Implicit((Object)(object)breast[i]))
			{
				continue;
			}
			Vector3 val = breast[i].localPosition - rest[i];
			for (int j = 0; j < 3; j++)
			{
				for (int k = 0; k < 2; k++)
				{
					int num = i * 6 + j * 2 + k;
					float num2 = Mathf.Clamp(((Vector3)(ref val))[j] * (float)((k == 0) ? 1 : (-1)) / ((Vector3)(ref travel[i]))[j] * 100f, 0f, 100f);
					if (num2 < 0.001f)
					{
						num2 = 0f;
					}
					for (int l = 0; l < cloth.Length; l++)
					{
						if (Object.op_Implicit((Object)(object)cloth[l]) && Mathf.Abs(previous[l][num] - num2) > 0.0001f)
						{
							cloth[l].SetBlendShapeWeight(indices[l][num], num2);
							previous[l][num] = num2;
						}
					}
				}
			}
		}
	}

	private void LateUpdate()
	{
		Apply();
	}

	private void OnDisable()
	{
		if (!ready)
		{
			return;
		}
		for (int i = 0; i < cloth.Length; i++)
		{
			if (Object.op_Implicit((Object)(object)cloth[i]))
			{
				for (int j = 0; j < 12; j++)
				{
					cloth[i].SetBlendShapeWeight(indices[i][j], 0f);
					previous[i][j] = -1f;
				}
			}
		}
	}
}
public class FlorenceFootAlignment : MonoBehaviour
{
	private Transform hip;

	private Transform leftSole;

	private Transform rightSole;

	private Transform playerLeft;

	private Transform playerRight;

	private Vector3 leftReference;

	private Vector3 rightReference;

	private SkinnedMeshRenderer source;

	private bool ready;

	public float LastCorrection { get; private set; }

	public void Align(SkinnedMeshRenderer player)
	{
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_025a: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_026a: Unknown result type (might be due to invalid IL or missing references)
		//IL_026f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)player))
		{
			return;
		}
		if (!ready || (Object)(object)source != (Object)(object)player)
		{
			source = player;
			Animator component = ((Component)this).GetComponent<Animator>();
			if (!Object.op_Implicit((Object)(object)component) || !component.isHuman)
			{
				return;
			}
			hip = component.GetBoneTransform((HumanBodyBones)0);
			Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(true);
			leftSole = ((IEnumerable<Transform>)componentsInChildren).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == "FlorenceSole.L"));
			rightSole = ((IEnumerable<Transform>)componentsInChildren).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == "FlorenceSole.R"));
			Transform val = ((IEnumerable<Transform>)componentsInChildren).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == "EmployeeSoleReference.L"));
			Transform val2 = ((IEnumerable<Transform>)componentsInChildren).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == "EmployeeSoleReference.R"));
			playerLeft = ((IEnumerable<Transform>)player.bones).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == "foot.L"));
			playerRight = ((IEnumerable<Transform>)player.bones).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == "foot.R"));
			ready = Object.op_Implicit((Object)(object)hip) && Object.op_Implicit((Object)(object)leftSole) && Object.op_Implicit((Object)(object)rightSole) && Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)playerLeft) && Object.op_Implicit((Object)(object)playerRight);
			if (!ready)
			{
				return;
			}
			leftReference = val.localPosition;
			rightReference = val2.localPosition;
		}
		float num = Mathf.Min(playerLeft.TransformPoint(leftReference).y, playerRight.TransformPoint(rightReference).y);
		float num2 = Mathf.Min(leftSole.position.y, rightSole.position.y);
		LastCorrection = num - num2;
		if (!float.IsNaN(LastCorrection) && !float.IsInfinity(LastCorrection))
		{
			Transform obj = hip;
			obj.position += Vector3.up * LastCorrection;
		}
	}
}
public static class FlorenceFootAlignmentPatch
{
	public static void Install(Harmony h)
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		h.Patch((MethodBase)AccessTools.Method(typeof(AvatarUpdater), "UpdateModel", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(FlorenceFootAlignmentPatch), "AfterPose", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
	}

	private static void AfterPose(GameObject ___replacement, SkinnedMeshRenderer ___playerModelRenderer)
	{
		if (Object.op_Implicit((Object)(object)___replacement) && ((Object)___replacement).name.StartsWith("Florence_", StringComparison.Ordinal))
		{
			FlorenceFootAlignment florenceFootAlignment = ___replacement.GetComponent<FlorenceFootAlignment>();
			if (!Object.op_Implicit((Object)(object)florenceFootAlignment))
			{
				florenceFootAlignment = ___replacement.AddComponent<FlorenceFootAlignment>();
			}
			florenceFootAlignment.Align(___playerModelRenderer);
			FlorenceHeadTracking component = ___replacement.GetComponent<FlorenceHeadTracking>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.Step();
			}
			FlorenceNativeMotion component2 = ___replacement.GetComponent<FlorenceNativeMotion>();
			if (Object.op_Implicit((Object)(object)component2) && ((Behaviour)component2).enabled)
			{
				component2.StepFrame();
			}
			FlorenceGarmentMotion component3 = ___replacement.GetComponent<FlorenceGarmentMotion>();
			if (Object.op_Implicit((Object)(object)component3))
			{
				component3.StepFrame();
			}
		}
	}
}
[DefaultExecutionOrder(400)]
public class FlorenceGarmentMotion : MonoBehaviour
{
	private int boneCount;

	private int particleCount;

	private Transform[,] bones;

	private Vector3[,] local;

	private Vector3[,] points;

	private Vector3[,] previous;

	private Vector3[,] targets;

	private Quaternion[,] rest;

	private float[,] vertical;

	private float[,] lateral;

	private Vector3[] tailLocal;

	private float scale;

	private int lastFrame = -1;

	private Transform[] contactTransforms;

	private int[,] contactBoneIds;

	private Matrix4x4[] contactMatrices;

	private Dictionary<Transform, int> contactLookup;

	private Vector3[,] contactLocal;

	private float[,] contactWeights;

	private int[] contactPanels;

	private int[] contactSlots;

	private SphereCollider[] thighSpheres;

	private Vector3[] sphereCenters;

	private float[] sphereRadii;

	private bool poseDriverChecked;

	private bool externalPoseDriver;

	private RaidNightPhysicsBudget physicsBudget;

	public int CollisionCorrections { get; private set; }

	public int ContactSampleCount
	{
		get
		{
			if (contactPanels != null)
			{
				return contactPanels.Length;
			}
			return 0;
		}
	}

	public float CurrentMaxThighPenetration { get; private set; }

	public float PeakDisplacement { get; private set; }

	public float MaximumStrain { get; private set; }

	private static Vector3[] SkinPoints(SkinnedMeshRenderer skin)
	{
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0087: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		Mesh sharedMesh = skin.sharedMesh;
		Vector3[] vertices = sharedMesh.vertices;
		BoneWeight[] boneWeights = sharedMesh.boneWeights;
		Matrix4x4[] bindposes = sharedMesh.bindposes;
		Matrix4x4[] array = skin.bones.Select((Transform b, int i) => b.localToWorldMatrix * bindposes[i]).ToArray();
		Vector3[] array2 = (Vector3[])(object)new Vector3[vertices.Length];
		for (int num = 0; num < vertices.Length; num++)
		{
			BoneWeight val = boneWeights[num];
			array2[num] = ((Matrix4x4)(ref array[((BoneWeight)(ref val)).boneIndex0])).MultiplyPoint3x4(vertices[num]) * ((BoneWeight)(ref val)).weight0 + ((Matrix4x4)(ref array[((BoneWeight)(ref val)).boneIndex1])).MultiplyPoint3x4(vertices[num]) * ((BoneWeight)(ref val)).weight1 + ((Matrix4x4)(ref array[((BoneWeight)(ref val)).boneIndex2])).MultiplyPoint3x4(vertices[num]) * ((BoneWeight)(ref val)).weight2 + ((Matrix4x4)(ref array[((BoneWeight)(ref val)).boneIndex3])).MultiplyPoint3x4(vertices[num]) * ((BoneWeight)(ref val)).weight3;
		}
		return array2;
	}

	public unsafe static SphereCollider[] CreateThighSpheres(GameObject model)
	{
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: 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_00c3: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_029b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fe: Expected O, but got Unknown
		//IL_031e: Unknown result type (might be due to invalid IL or missing references)
		//IL_034f: Unknown result type (might be due to invalid IL or missing references)
		SphereCollider[] array = (from c in model.GetComponentsInChildren<SphereCollider>()
			where ((Object)c).name.StartsWith("ShirtCollision_Thigh_")
			select c).ToArray();
		if (array.Length == 2)
		{
			return array;
		}
		Animator component = model.GetComponent<Animator>();
		SphereCollider[] array2 = (SphereCollider[])(object)new SphereCollider[2];
		Vector3[] source = SkinPoints(model.GetComponentsInChildren<SkinnedMeshRenderer>().Single((SkinnedMeshRenderer r) => ((Object)r).name == "YamPastry_Body_00"));
		for (int num = 0; num < 2; num++)
		{
			Transform boneTransform = component.GetBoneTransform((HumanBodyBones)((num == 0) ? 1 : 2));
			Transform boneTransform2 = component.GetBoneTransform((HumanBodyBones)((num == 0) ? 3 : 4));
			Vector3 val = boneTransform2.position - boneTransform.position;
			Vector3 axis = ((Vector3)(ref val)).normalized;
			float length = Vector3.Distance(boneTransform.position, boneTransform2.position);
			Vector3 center = Vector3.Lerp(boneTransform.position, boneTransform2.position, 0.2f);
			val = Vector3.ProjectOnPlane(model.transform.right, axis);
			Vector3 x = ((Vector3)(ref val)).normalized;
			val = Vector3.Cross(axis, x);
			Vector3 z = ((Vector3)(ref val)).normalized;
			Vector3[] array3 = source.Where((Vector3 v) => Mathf.Abs(Vector3.Dot(v - center, axis)) < length * 0.055f && Mathf.Abs(Vector3.Dot(v - center, x)) < length * 0.38f && Mathf.Abs(Vector3.Dot(v - center, z)) < length * 0.38f).ToArray();
			if (array3.Length < 12)
			{
				string[] obj = new string[12]
				{
					"Cannot fit shirt thigh sphere to skin: ",
					((Object)boneTransform).name,
					" samples=",
					array3.Length.ToString(),
					" center=",
					null,
					null,
					null,
					null,
					null,
					null,
					null
				};
				val = center;
				obj[5] = ((object)(*(Vector3*)(&val))/*cast due to .constrained prefix*/).ToString();
				obj[6] = " length=";
				obj[7] = length.ToString();
				obj[8] = " skinMin=";
				val = ((IEnumerable<Vector3>)source).Aggregate((Func<Vector3, Vector3, Vector3>)Vector3.Min);
				obj[9] = ((object)(*(Vector3*)(&val))/*cast due to .constrained prefix*/).ToString();
				obj[10] = " skinMax=";
				val = ((IEnumerable<Vector3>)source).Aggregate((Func<Vector3, Vector3, Vector3>)Vector3.Max);
				obj[11] = ((object)(*(Vector3*)(&val))/*cast due to .constrained prefix*/).ToString();
				throw new Exception(string.Concat(obj));
			}
			float num2 = array3.Min((Vector3 v) => Vector3.Dot(v - center, x));
			float num3 = array3.Max((Vector3 v) => Vector3.Dot(v - center, x));
			float num4 = array3.Min((Vector3 v) => Vector3.Dot(v - center, z));
			float num5 = array3.Max((Vector3 v) => Vector3.Dot(v - center, z));
			center += x * ((num2 + num3) * 0.5f) + z * ((num4 + num5) * 0.5f);
			GameObject val2 = new GameObject("ShirtCollision_Thigh_" + ((num == 0) ? "L" : "R"));
			val2.layer = 2;
			val2.transform.SetParent(boneTransform, false);
			val2.transform.position = center;
			SphereCollider val3 = val2.AddComponent<SphereCollider>();
			val3.radius = Mathf.Max(num3 - num2, num5 - num4) * 0.48f / Mathf.Abs(val2.transform.lossyScale.x);
			((Collider)val3).isTrigger = true;
			((Collider)val3).enabled = false;
			array2[num] = val3;
		}
		return array2;
	}

	public static FlorenceGarmentMotion Attach(GameObject model)
	{
		FlorenceGarmentMotion florenceGarmentMotion = model.GetComponent<FlorenceGarmentMotion>();
		if (!Object.op_Implicit((Object)(object)florenceGarmentMotion) && model.GetComponentsInChildren<Transform>().Any((Transform t) => ((Object)t).name == "DEF-florence.cloth.00.00"))
		{
			florenceGarmentMotion = model.AddComponent<FlorenceGarmentMotion>();
		}
		if (Object.op_Implicit((Object)(object)florenceGarmentMotion))
		{
			florenceGarmentMotion.Initialize();
		}
		return florenceGarmentMotion;
	}

	private void Start()
	{
		Initialize();
	}

	public bool Initialize()
	{
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0207: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_026a: Unknown result type (might be due to invalid IL or missing references)
		//IL_026f: Unknown result type (might be due to invalid IL or missing references)
		//IL_032c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0346: Unknown result type (might be due to invalid IL or missing references)
		//IL_034b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0350: Unknown result type (might be due to invalid IL or missing references)
		//IL_0354: Unknown result type (might be due to invalid IL or missing references)
		//IL_0359: Unknown result type (might be due to invalid IL or missing references)
		//IL_0370: Unknown result type (might be due to invalid IL or missing references)
		//IL_038a: Unknown result type (might be due to invalid IL or missing references)
		//IL_043e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0442: Unknown result type (might be due to invalid IL or missing references)
		//IL_0447: Unknown result type (might be due to invalid IL or missing references)
		//IL_044c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0487: Unknown result type (might be due to invalid IL or missing references)
		//IL_048c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0490: Unknown result type (might be due to invalid IL or missing references)
		//IL_0495: Unknown result type (might be due to invalid IL or missing references)
		//IL_049a: Unknown result type (might be due to invalid IL or missing references)
		//IL_049f: Unknown result type (might be due to invalid IL or missing references)
		//IL_03da: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_04da: Unknown result type (might be due to invalid IL or missing references)
		//IL_04df: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e7: 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_04ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_052f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0540: Unknown result type (might be due to invalid IL or missing references)
		//IL_0588: Unknown result type (might be due to invalid IL or missing references)
		//IL_059b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0926: Unknown result type (might be due to invalid IL or missing references)
		//IL_092b: Unknown result type (might be due to invalid IL or missing references)
		//IL_09c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_09ce: 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)
		if (bones != null)
		{
			return true;
		}
		Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>();
		if (!componentsInChildren.Any((Transform t) => ((Object)t).name == "DEF-florence.cloth.00.00"))
		{
			return false;
		}
		boneCount = (componentsInChildren.Any((Transform t) => ((Object)t).name == "DEF-florence.waist.00") ? 4 : 3);
		particleCount = boneCount + 1;
		bones = new Transform[8, boneCount];
		local = new Vector3[8, particleCount];
		rest = new Quaternion[8, boneCount];
		points = new Vector3[8, particleCount];
		previous = new Vector3[8, particleCount];
		targets = new Vector3[8, particleCount];
		vertical = new float[8, boneCount];
		lateral = new float[8, particleCount];
		scale = Mathf.Abs(((Component)this).transform.lossyScale.x);
		tailLocal = (Vector3[])(object)new Vector3[8];
		thighSpheres = CreateThighSpheres(((Component)this).gameObject);
		sphereCenters = (Vector3[])(object)new Vector3[2];
		sphereRadii = new float[2];
		for (int i = 0; i < 8; i++)
		{
			int j;
			for (j = 0; j < boneCount; j++)
			{
				bones[i, j] = componentsInChildren.Single((Transform t) => ((Object)t).name == ((boneCount == 4 && j == 0) ? ("DEF-florence.waist." + i.ToString("00")) : ("DEF-florence.cloth." + i.ToString("00") + "." + (j - ((boneCount == 4) ? 1 : 0)).ToString("00"))));
				rest[i, j] = bones[i, j].localRotation;
				local[i, j] = bones[i, 0].parent.InverseTransformPoint(bones[i, j].position);
			}
		}
		SkinnedMeshRenderer val = ((Component)this).GetComponentsInChildren<SkinnedMeshRenderer>().Single((SkinnedMeshRenderer r) => ((Object)r).name == "YamPastry_Clothes_05");
		Vector3[] hemPoints = SkinPoints(val);
		BoneWeight[] hemWeights = val.sharedMesh.boneWeights;
		Transform[] hemBones = val.bones;
		for (int num = 0; num < 8; num++)
		{
			Vector3 val2 = bones[num, boneCount - 1].position - bones[num, boneCount - 2].position;
			Vector3 normalized = ((Vector3)(ref val2)).normalized;
			float num2 = Vector3.Distance(bones[num, boneCount - 1].position, bones[num, boneCount - 2].position);
			for (int num3 = 0; num3 < hemPoints.Length; num3++)
			{
				if ((Object)(object)hemBones[((BoneWeight)(ref hemWeights[num3])).boneIndex0] == (Object)(object)bones[num, boneCount - 1])
				{
					num2 = Mathf.Max(num2, Vector3.Dot(hemPoints[num3] - bones[num, boneCount - 1].position, normalized));
				}
			}
			tailLocal[num] = bones[num, boneCount - 1].InverseTransformVector(normalized * num2);
			local[num, boneCount] = bones[num, 0].parent.InverseTransformPoint(bones[num, boneCount - 1].position + normalized * num2);
			for (int num4 = 0; num4 < particleCount; num4++)
			{
				val2 = (points[num, num4] = (previous[num, num4] = bones[num, 0].parent.TransformPoint(local[num, num4])));
			}
		}
		for (int num5 = 0; num5 < 8; num5++)
		{
			for (int num6 = 0; num6 < boneCount; num6++)
			{
				vertical[num5, num6] = Vector3.Distance(points[num5, num6], points[num5, num6 + 1]);
			}
		}
		for (int num7 = 0; num7 < 8; num7++)
		{
			for (int num8 = 0; num8 < particleCount; num8++)
			{
				lateral[num7, num8] = Vector3.Distance(points[num7, num8], points[(num7 + 1) % 8, num8]);
			}
		}
		Mesh sharedMesh = val.sharedMesh;
		Vector3[] vertices = sharedMesh.vertices;
		Matrix4x4[] bindposes = sharedMesh.bindposes;
		List<int[]> list = new List<int[]>();
		bool[] array = new bool[vertices.Length];
		for (int num9 = 0; num9 < vertices.Length; num9++)
		{
			array[num9] = ((Object)hemBones[((BoneWeight)(ref hemWeights[num9])).boneIndex0]).name.StartsWith("DEF-florence.cloth.") || ((Object)hemBones[((BoneWeight)(ref hemWeights[num9])).boneIndex0]).name.StartsWith("DEF-florence.waist.");
			if (array[num9])
			{
				list.Add(new int[1] { num9 });
			}
		}
		HashSet<long> hashSet = new HashSet<long>();
		int[] triangles = sharedMesh.triangles;
		for (int num10 = 0; num10 < triangles.Length; num10 += 3)
		{
			int num11 = triangles[num10];
			int num12 = triangles[num10 + 1];
			int num13 = triangles[num10 + 2];
			if (!array[num11] || !array[num12] || !array[num13])
			{
				continue;
			}
			list.Add(new int[3] { num11, num12, num13 });
			int[] array2 = new int[3] { num11, num12, num13 };
			for (int num14 = 0; num14 < 3; num14++)
			{
				int num15 = array2[num14];
				int num16 = array2[(num14 + 1) % 3];
				long item = ((long)Mathf.Min(num15, num16) << 32) | (uint)Mathf.Max(num15, num16);
				if (hashSet.Add(item))
				{
					list.Add(new int[2] { num15, num16 });
				}
			}
		}
		HashSet<string> cells = new HashSet<string>();
		list = list.Where(delegate(int[] sample)
		{
			//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_005e: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			int num23 = sample.OrderByDescending((int index) => ((BoneWeight)(ref hemWeights[index])).weight0).First();
			string name = ((Object)hemBones[((BoneWeight)(ref hemWeights[num23])).boneIndex0]).name;
			Vector3 val4 = Vector3.zero;
			foreach (int num25 in sample)
			{
				val4 += hemPoints[num25] / (float)sample.Length;
			}
			val4 = (val4 - ((Component)this).transform.position) / (((sample.Length == 1) ? 0.001f : 0.024f) * scale);
			return cells.Add(name + ":" + sample.Length + ":" + Mathf.FloorToInt(val4.x) + ":" + Mathf.FloorToInt(val4.y) + ":" + Mathf.FloorToInt(val4.z));
		}).ToList();
		contactTransforms = hemBones;
		contactMatrices = (Matrix4x4[])(object)new Matrix4x4[contactTransforms.Length];
		contactLookup = contactTransforms.Select((Transform b, int i2) => new
		{
			b = b,
			i = i2
		}).ToDictionary(pair => pair.b, pair => pair.i);
		contactBoneIds = new int[list.Count, 12];
		contactLocal = new Vector3[list.Count, 12];
		contactWeights = new float[list.Count, 12];
		contactPanels = new int[list.Count];
		contactSlots = new int[list.Count];
		for (int num17 = 0; num17 < list.Count; num17++)
		{
			contactSlots[num17] = list[num17].Length * 4;
			int num18 = list[num17].OrderByDescending((int index) => ((BoneWeight)(ref hemWeights[index])).weight0).First();
			contactPanels[num17] = int.Parse(((Object)hemBones[((BoneWeight)(ref hemWeights[num18])).boneIndex0]).name.Split('.')[2]);
			for (int num19 = 0; num19 < list[num17].Length; num19++)
			{
				int num20 = list[num17][num19];
				BoneWeight val3 = hemWeights[num20];
				int[] array3 = new int[4]
				{
					((BoneWeight)(ref val3)).boneIndex0,
					((BoneWeight)(ref val3)).boneIndex1,
					((BoneWeight)(ref val3)).boneIndex2,
					((BoneWeight)(ref val3)).boneIndex3
				};
				float[] array4 = new float[4]
				{
					((BoneWeight)(ref val3)).weight0,
					((BoneWeight)(ref val3)).weight1,
					((BoneWeight)(ref val3)).weight2,
					((BoneWeight)(ref val3)).weight3
				};
				for (int num21 = 0; num21 < 4; num21++)
				{
					int num22 = num19 * 4 + num21;
					contactBoneIds[num17, num22] = array3[num21];
					contactLocal[num17, num22] = ((Matrix4x4)(ref bindposes[array3[num21]])).MultiplyPoint3x4(vertices[num20]);
					contactWeights[num17, num22] = array4[num21] / (float)list[num17].Length;
				}
			}
		}
		return true;
	}

	private void LateUpdate()
	{
		if (!poseDriverChecked)
		{
			externalPoseDriver = Object.op_Implicit((Object)(object)((Component)this).GetComponent<OffsetBuilder>());
			poseDriverChecked = true;
		}
		if (!externalPoseDriver)
		{
			StepFrame();
		}
	}

	public void StepFrame()
	{
		if (lastFrame != Time.frameCount)
		{
			lastFrame = Time.frameCount;
			Step(Time.deltaTime);
		}
	}

	private static void Distance(ref Vector3 a, ref Vector3 b, float length, bool pinned)
	{
		//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_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_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: 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_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: 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)
		Vector3 val = b - a;
		float magnitude = ((Vector3)(ref val)).magnitude;
		if (!(magnitude < 1E-07f))
		{
			Vector3 val2 = val * (1f - length / magnitude);
			if (pinned)
			{
				b -= val2;
				return;
			}
			a += val2 * 0.5f;
			b -= val2 * 0.5f;
		}
	}

	private void Collide(ref Vector3 point, ref Vector3 history)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: 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_0051: 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_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < 2; i++)
		{
			Vector3 val = point - sphereCenters[i];
			float magnitude = ((Vector3)(ref val)).magnitude;
			if (!(magnitude >= sphereRadii[i]))
			{
				Vector3 val2 = ((magnitude > 1E-07f) ? (val / magnitude) : ((Component)this).transform.forward);
				Vector3 val3 = val2 * (sphereRadii[i] - magnitude);
				point += val3;
				history += val3;
				float num = Vector3.Dot(point - history, val2);
				if (num < 0f)
				{
					history += val2 * num;
				}
				CollisionCorrections++;
			}
		}
	}

	private Vector3 ContactVertex(int v)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: 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_0060: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = Vector3.zero;
		for (int i = 0; i < contactSlots[v]; i++)
		{
			if (contactWeights[v, i] > 0f)
			{
				val += ((Matrix4x4)(ref contactMatrices[contactBoneIds[v, i]])).MultiplyPoint3x4(contactLocal[v, i]) * contactWeights[v, i];
			}
		}
		return val;
	}

	private void ResolveFabricContacts()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: 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_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_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_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_028f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0303: Unknown result type (might be due to invalid IL or missing references)
		//IL_0308: Unknown result type (might be due to invalid IL or missing references)
		//IL_0317: Unknown result type (might be due to invalid IL or missing references)
		//IL_0319: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: 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_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_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: 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_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < contactTransforms.Length; i++)
		{
			contactMatrices[i] = contactTransforms[i].localToWorldMatrix;
		}
		for (int j = 0; j < 8; j++)
		{
			bool flag = false;
			for (int k = 0; k < contactPanels.Length; k++)
			{
				Vector3 val = ContactVertex(k);
				for (int l = 0; l < 2; l++)
				{
					float num = sphereRadii[l];
					Vector3 val2 = val - sphereCenters[l];
					if (((Vector3)(ref val2)).sqrMagnitude >= (num - 0.0001f * scale) * (num - 0.0001f * scale))
					{
						continue;
					}
					Transform val3 = bones[contactPanels[k], 0];
					Vector3 val4 = sphereCenters[l] - val3.position;
					float magnitude = ((Vector3)(ref val4)).magnitude;
					Vector3 val5 = val - val3.position;
					float magnitude2 = ((Vector3)(ref val5)).magnitude;
					if (!(magnitude <= num) && !(magnitude2 < 1E-06f))
					{
						Vector3 val6 = val4 / magnitude;
						val2 = Vector3.ProjectOnPlane(val5, val6);
						Vector3 normalized = ((Vector3)(ref val2)).normalized;
						if (((Vector3)(ref normalized)).sqrMagnitude < 0.5f)
						{
							val2 = Vector3.ProjectOnPlane(((Component)this).transform.forward, val6);
							normalized = ((Vector3)(ref val2)).normalized;
						}
						float num2 = Mathf.Clamp((magnitude2 * magnitude2 + magnitude * magnitude - num * num) / (2f * magnitude2 * magnitude), -1f, 1f);
						Vector3 val7 = val6 * num2 + normalized * Mathf.Sqrt(Mathf.Max(0f, 1f - num2 * num2));
						val3.rotation = Quaternion.FromToRotation(val5, val7) * val3.rotation;
						for (int m = 0; m < boneCount; m++)
						{
							Transform val8 = bones[contactPanels[k], m];
							contactMatrices[contactLookup[val8]] = val8.localToWorldMatrix;
						}
						CollisionCorrections++;
						flag = true;
						if (l == 0)
						{
							val = ContactVertex(k);
						}
					}
				}
			}
			if (!flag)
			{
				break;
			}
		}
		for (int n = 0; n < 8; n++)
		{
			for (int num3 = 0; num3 < particleCount; num3++)
			{
				Vector3 val9 = ((num3 < boneCount) ? bones[n, num3].position : (bones[n, boneCount - 1].position + bones[n, boneCount - 1].TransformVector(tailLocal[n])));
				ref Vector3 reference = ref previous[n, num3];
				reference += val9 - points[n, num3];
				points[n, num3] = val9;
			}
		}
	}

	private void ResetLodSimulation()
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < 8; i++)
		{
			for (int j = 0; j < particleCount; j++)
			{
				points[i, j] = (previous[i, j] = bones[i, 0].parent.TransformPoint(local[i, j]));
			}
		}
		lastFrame = -1;
	}

	public void Step(float elapsed)
	{
		if (!Initialize())
		{
			return;
		}
		if (physicsBudget == null)
		{
			physicsBudget = new RaidNightPhysicsBudget((Component)(object)this, bones.Cast<Transform>(), ResetLodSimulation);
		}
		if (!physicsBudget.Begin(ref elapsed))
		{
			return;
		}
		try
		{
			StepFull(elapsed);
		}
		finally
		{
			physicsBudget.Capture();
		}
	}

	public void StepFull(float elapsed)
	{
		//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_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: 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_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: 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_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0216: Unknown result type (might be due to invalid IL or missing references)
		//IL_021b: Unknown result type (might be due to invalid IL or missing references)
		//IL_021d: Unknown result type (might be due to invalid IL or missing references)
		//IL_048c: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0240: Unknown result type (might be due to invalid IL or missing references)
		//IL_0245: Unknown result type (might be due to invalid IL or missing references)
		//IL_025a: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_0269: Unknown result type (might be due to invalid IL or missing references)
		//IL_0278: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_04fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0500: Unknown result type (might be due to invalid IL or missing references)
		//IL_0507: 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_0529: Unknown result type (might be due to invalid IL or missing references)
		//IL_053a: Unknown result type (might be due to invalid IL or missing references)
		//IL_053f: 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_0599: Unknown result type (might be due to invalid IL or missing references)
		//IL_05aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0607: Unknown result type (might be due to invalid IL or missing references)
		//IL_060c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0630: Unknown result type (might be due to invalid IL or missing references)
		//IL_063a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0383: Unknown result type (might be due to invalid IL or missing references)
		//IL_0392: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cc: 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_03d6: Unknown result type (might be due to invalid IL or missing references)
		if (!Initialize() || elapsed <= 0f)
		{
			return;
		}
		float num = Mathf.Min(elapsed, 0.05f);
		int num2 = Mathf.CeilToInt(num / 0.008f);
		float num3 = num / (float)num2;
		for (int i = 0; i < 2; i++)
		{
			sphereCenters[i] = ((Component)thighSpheres[i]).transform.TransformPoint(thighSpheres[i].center);
			sphereRadii[i] = thighSpheres[i].radius * Mathf.Abs(((Component)thighSpheres[i]).transform.lossyScale.x) + 0.012f * scale;
		}
		for (int j = 0; j < 8; j++)
		{
			for (int k = 0; k < particleCount; k++)
			{
				targets[j, k] = bones[j, 0].parent.TransformPoint(local[j, k]);
			}
		}
		Vector3 val;
		if (Vector3.Distance(points[0, 0], targets[0, 0]) > 1.5f)
		{
			for (int l = 0; l < 8; l++)
			{
				for (int m = 0; m < particleCount; m++)
				{
					val = (points[l, m] = (previous[l, m] = targets[l, m]));
				}
			}
		}
		for (int n = 0; n < num2; n++)
		{
			for (int num4 = 0; num4 < 8; num4++)
			{
				val = (points[num4, 0] = (previous[num4, 0] = targets[num4, 0]));
				for (int num5 = 1; num5 < particleCount; num5++)
				{
					Vector3 val2 = points[num4, num5];
					Vector3 val3 = (val2 - previous[num4, num5]) * Mathf.Exp(-10.5f * num3);
					ref Vector3 reference = ref points[num4, num5];
					reference += val3 + (targets[num4, num5] - val2) * ((float)((boneCount == 4 && num5 == 1) ? 115 : 48) * num3 * num3) + Vector3.down * (0.16f * scale * num3 * num3);
					previous[num4, num5] = val2;
				}
			}
			for (int num6 = 0; num6 < 24; num6++)
			{
				for (int num7 = 0; num7 < 8; num7++)
				{
					for (int num8 = 0; num8 < boneCount; num8++)
					{
						Distance(ref points[num7, num8], ref points[num7, num8 + 1], vertical[num7, num8], num8 == 0);
					}
				}
				for (int num9 = 0; num9 < 8; num9++)
				{
					for (int num10 = 1; num10 < particleCount; num10++)
					{
						Distance(ref points[num9, num10], ref points[(num9 + 1) % 8, num10], lateral[num9, num10], pinned: false);
					}
				}
				for (int num11 = 0; num11 < 8; num11++)
				{
					for (int num12 = 1; num12 < particleCount; num12++)
					{
						points[num11, num12] = targets[num11, num12] + Vector3.ClampMagnitude(points[num11, num12] - targets[num11, num12], ((boneCount == 4 && num12 == 1) ? 0.025f : 0.1f) * scale);
					}
				}
				for (int num13 = 0; num13 < 8; num13++)
				{
					for (int num14 = 1; num14 < particleCount; num14++)
					{
						Collide(ref points[num13, num14], ref previous[num13, num14]);
					}
				}
			}
		}
		for (int num15 = 0; num15 < 8; num15++)
		{
			for (int num16 = 0; num16 < boneCount; num16++)
			{
				Transform val4 = bones[num15, num16];
				val4.localRotation = rest[num15, num16];
				Vector3 val5 = ((num16 < boneCount - 1) ? val4.TransformVector(bones[num15, num16 + 1].localPosition) : val4.TransformVector(tailLocal[num15]));
				val4.rotation = Quaternion.FromToRotation(val5, points[num15, num16 + 1] - points[num15, num16]) * val4.rotation;
				float peakDisplacement = PeakDisplacement;
				val = points[num15, num16 + 1] - targets[num15, num16 + 1];
				PeakDisplacement = Mathf.Max(peakDisplacement, ((Vector3)(ref val)).magnitude);
			}
		}
		ResolveFabricContacts();
		for (int num17 = 0; num17 < 8; num17++)
		{
			for (int num18 = 0; num18 < boneCount; num18++)
			{
				MaximumStrain = Mathf.Max(MaximumStrain, Mathf.Abs(Vector3.Distance(points[num17, num18], points[num17, num18 + 1]) / vertical[num17, num18] - 1f));
			}
		}
		CurrentMaxThighPenetration = 0f;
		for (int num19 = 0; num19 < contactPanels.Length; num19++)
		{
			Vector3 val6 = ContactVertex(num19);
			for (int num20 = 0; num20 < 2; num20++)
			{
				CurrentMaxThighPenetration = Mathf.Max(CurrentMaxThighPenetration, sphereRadii[num20] - 0.012f * scale - Vector3.Distance(val6, sphereCenters[num20]));
			}
		}
	}

	private void OnDisable()
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		if (bones == null)
		{
			return;
		}
		for (int i = 0; i < 8; i++)
		{
			if (Object.op_Implicit((Object)(object)bones[i, 0]))
			{
				bones[i, 0].position = bones[i, 0].parent.TransformPoint(local[i, 0]);
			}
			for (int j = 0; j < boneCount; j++)
			{
				if (Object.op_Implicit((Object)(object)bones[i, j]))
				{
					bones[i, j].localRotation = rest[i, j];
				}
			}
		}
	}
}
[DefaultExecutionOrder(200)]
public class FlorenceHeadTracking : MonoBehaviour
{
	public PlayerControllerB Player;

	private readonly FlorenceAttention attention = new FlorenceAttention();

	public Quaternion? WorldAimFrame;

	public bool TrackingEnabled = true;

	private Transform neck;

	private Transform head;

	private Quaternion headToLook;

	private Quaternion neckBase;

	private Quaternion headBase;

	private Quaternion neckApplied;

	private Quaternion headApplied;

	private Quaternion neutralNeck;

	private Quaternion neutralHead;

	private bool ready;

	private bool applied;

	private int previousFrame = int.MinValue;

	private float yaw;

	private float pitch;

	private float aimWeight;

	public const float MaximumYaw = 50f;

	public const float MaximumUpPitch = 35f;

	public const float MaximumDownPitch = 45f;

	public const float MaximumCorrection = 55f;

	public const float NeckShare = 0.3f;

	private bool initializationAttempted;

	private RaidNightLod performanceLod;

	private bool performanceResolved;

	public bool HasAttentionTarget { get; private set; }

	public Vector3 AttentionDirection { get; private set; }

	public float CurrentYaw => yaw;

	public float CurrentPitch => pitch;

	public float LastCorrectionAngle { get; private set; }

	public bool Ready => ready;

	public Vector3 LookForward
	{
		get
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_002f: 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)
			if (!ready)
			{
				return ((Component)this).transform.forward;
			}
			return head.rotation * headToLook * Vector3.forward;
		}
	}

	public Vector3 LookUp
	{
		get
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_002f: 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)
			if (!ready)
			{
				return ((Component)this).transform.up;
			}
			return head.rotation * headToLook * Vector3.up;
		}
	}

	private void Awake()
	{
		Initialize();
	}

	private void Initialize()
	{
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_014a: 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_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: 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_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		if (ready || initializationAttempted)
		{
			return;
		}
		initializationAttempted = true;
		Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(true);
		Animator componentInChildren = ((Component)this).GetComponentInChildren<