Decompiled source of ZZZ Remielle v1.0.8

RemielleSuit.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 ModelReplacement;
using ModelReplacement.AvatarBodyUpdater;
using ModelReplacement.Scripts.Enemies;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyFileVersion("1.0.8")]
[assembly: AssemblyInformationalVersion("1.0.8")]
[assembly: AssemblyVersion("1.0.8.0")]
namespace RemielleSuit;

public static class MaskedAppearanceCompatibility
{
	private static readonly Type HostType = typeof(BodyReplacementBase).Assembly.GetType("ModelReplacement.Monobehaviors.Enemies.MaskedReplacementBase");

	private static readonly FieldInfo ModelField = ((HostType == null) ? null : AccessTools.Field(HostType, "replacementModel"));

	private static readonly FieldInfo ActiveField = ((HostType == null) ? null : AccessTools.Field(HostType, "IsActive"));

	private static readonly PropertyInfo AvatarProperty = ((HostType == null) ? null : AccessTools.Property(HostType, "avatar"));

	private static readonly MethodInfo Replace = ((HostType == null) ? null : AccessTools.Method(HostType, "SetReplacement", new Type[1] { typeof(PlayerControllerB) }, (Type[])null));

	private static readonly ManualLogSource Log = Logger.CreateLogSource("Remielle masked compatibility");

	public static void Install(Harmony harmony)
	{
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Expected O, but got Unknown
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Expected O, but got Unknown
		if (Replace == null || ModelField == null || AvatarProperty == null)
		{
			Log.LogWarning((object)"Masked API entry points unavailable; player replacements remain enabled.");
			return;
		}
		harmony.Patch((MethodBase)Replace, new HarmonyMethod(typeof(MaskedAppearanceCompatibility), "Assign", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		harmony.Patch((MethodBase)AccessTools.Method(typeof(MaskedPlayerEnemy), "Start", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(MaskedAppearanceCompatibility), "Spawned", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
	}

	private static bool Owns(PlayerControllerB player, out BodyReplacementBase body)
	{
		body = null;
		if (Object.op_Implicit((Object)(object)player) && ModelReplacementAPI.GetPlayerModelReplacement(player, ref body) && Object.op_Implicit((Object)(object)body))
		{
			return ((object)body).GetType().Assembly == typeof(Plugin).Assembly;
		}
		return false;
	}

	private static void Spawned(MaskedPlayerEnemy __instance)
	{
		if (Object.op_Implicit((Object)(object)__instance) && !Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<MaskedAppearanceRetry>()))
		{
			((Component)__instance).gameObject.AddComponent<MaskedAppearanceRetry>().Enemy = __instance;
		}
	}

	internal static void Retry(MaskedPlayerEnemy enemy)
	{
		if (!Object.op_Implicit((Object)(object)enemy) || !Object.op_Implicit((Object)(object)enemy.mimickingPlayer) || !Owns(enemy.mimickingPlayer, out var body) || !Object.op_Implicit((Object)(object)body.replacementModel) || (Object)(object)body.viewState == (Object)null)
		{
			return;
		}
		Component component = ((Component)enemy).GetComponent(HostType);
		if (!Object.op_Implicit((Object)(object)component))
		{
			((Component)enemy).gameObject.AddComponent(HostType);
			return;
		}
		object? value = ModelField.GetValue(component);
		if (!Object.op_Implicit((Object)((value is GameObject) ? value : null)))
		{
			Replace.Invoke(component, new object[1] { enemy.mimickingPlayer });
		}
	}

	private static bool Assign(object __instance, PlayerControllerB __0)
	{
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Expected O, but got Unknown
		if (!Owns(__0, out var body))
		{
			return true;
		}
		if (!Object.op_Implicit((Object)(object)body.replacementModel) || (Object)(object)body.viewState == (Object)null)
		{
			return false;
		}
		object obj = ((__instance is Component) ? __instance : null);
		MaskedPlayerEnemy val = ((obj != null) ? ((Component)obj).GetComponent<MaskedPlayerEnemy>() : null);
		if (!Object.op_Implicit((Object)(object)val))
		{
			return true;
		}
		GameObject val2 = null;
		object? value = ModelField.GetValue(__instance);
		GameObject val3 = (GameObject)((value is GameObject) ? value : null);
		try
		{
			MaskedModelFaceDriver maskedModelFaceDriver = (Object.op_Implicit((Object)(object)val3) ? val3.GetComponent<MaskedModelFaceDriver>() : null);
			if (Object.op_Implicit((Object)(object)maskedModelFaceDriver) && (Object)(object)maskedModelFaceDriver.SourcePlayer == (Object)(object)__0 && (Object)(object)maskedModelFaceDriver.SourceModel == (Object)(object)body.replacementModel)
			{
				return false;
			}
			val2 = Object.Instantiate<GameObject>(body.replacementModel);
			((Object)val2).name = ((Object)body.replacementModel).name + " (Masked)";
			val2.transform.localPosition = Vector3.zero;
			MaskedModelFaceDriver.DetachPlayerControllers(val2);
			Renderer[] componentsInChildren = val2.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer obj2 in componentsInChildren)
			{
				((Component)obj2).gameObject.layer = body.viewState.VisibleLayer;
				obj2.shadowCastingMode = (ShadowCastingMode)1;
				obj2.enabled = true;
			}
			Camera[] componentsInChildren2 = val2.GetComponentsInChildren<Camera>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				((Behaviour)componentsInChildren2[i]).enabled = false;
			}
			NaturalEyeSockets.Ensure(val2).Aim(Vector2.zero);
			val2.AddComponent<MaskedModelFaceDriver>().Initialize(val, __0, body.replacementModel);
			MaskedAvatarUpdater val4 = new MaskedAvatarUpdater();
			val4.AssignModelReplacement(((Component)val).gameObject, val2);
			AvatarProperty.SetValue(__instance, val4, null);
			ModelField.SetValue(__instance, val2);
			ActiveField?.SetValue(__instance, true);
			val2.SetActive(true);
			SkinnedMeshRenderer[] array = (SkinnedMeshRenderer[])(object)new SkinnedMeshRenderer[3] { val.rendererLOD0, val.rendererLOD1, val.rendererLOD2 };
			foreach (SkinnedMeshRenderer val5 in array)
			{
				if (Object.op_Implicit((Object)(object)val5))
				{
					((Renderer)val5).enabled = false;
					((Renderer)val5).shadowCastingMode = (ShadowCastingMode)0;
				}
			}
			if (Object.op_Implicit((Object)(object)val3) && (Object)(object)val3 != (Object)(object)val2)
			{
				Object.Destroy((Object)(object)val3);
			}
			return false;
		}
		catch (Exception ex)
		{
			if (Object.op_Implicit((Object)(object)val2))
			{
				Object.Destroy((Object)(object)val2);
			}
			Log.LogWarning((object)("Masked adapter could not initialize; retaining MRAPI fallback: " + ex));
			return true;
		}
	}
}
public sealed class MaskedAppearanceRetry : MonoBehaviour
{
	public MaskedPlayerEnemy Enemy;

	private float next;

	private void Update()
	{
		if (!(Time.unscaledTime < next))
		{
			next = Time.unscaledTime + 1f;
			if (!Object.op_Implicit((Object)(object)Enemy) || ((EnemyAI)Enemy).isEnemyDead)
			{
				((Behaviour)this).enabled = false;
			}
			else
			{
				MaskedAppearanceCompatibility.Retry(Enemy);
			}
		}
	}
}
[DefaultExecutionOrder(9000)]
public sealed class MaskedModelFaceDriver : MonoBehaviour
{
	private sealed class Face
	{
		public SkinnedMeshRenderer Renderer;

		public int Blink;

		public int Left;

		public int Right;

		public int Up;

		public int Down;
	}

	public PlayerControllerB SourcePlayer;

	public GameObject SourceModel;

	private MaskedPlayerEnemy enemy;

	private MaskedVanillaBadges.Binding vanillaBadges;

	private NaturalEyeSockets sockets;

	private Vector2 gaze;

	private bool morphGaze;

	private float nextBlink;

	private float blinkStart = -10f;

	private readonly List<Face> faces = new List<Face>();

	private static int Shape(Mesh mesh, string name)
	{
		for (int i = 0; i < mesh.blendShapeCount; i++)
		{
			string blendShapeName = mesh.GetBlendShapeName(i);
			if (blendShapeName == name || blendShapeName.EndsWith("." + name, StringComparison.Ordinal) || blendShapeName.EndsWith("_" + name, StringComparison.Ordinal))
			{
				return i;
			}
		}
		return -1;
	}

	private static void Set(Face face, int index, float value)
	{
		if (Object.op_Implicit((Object)(object)face.Renderer) && index >= 0)
		{
			face.Renderer.SetBlendShapeWeight(index, value);
		}
	}

	public static void DetachPlayerControllers(GameObject clone)
	{
		MaskedCloneIsolation.Detach(clone, typeof(MaskedModelFaceDriver).Namespace);
	}

	public void Initialize(MaskedPlayerEnemy masked, PlayerControllerB source, GameObject model)
	{
		RaidNightLod.Ensure(((Component)this).gameObject, null);
		enemy = masked;
		SourcePlayer = source;
		SourceModel = model;
		vanillaBadges = MaskedVanillaBadges.Bind(((Component)masked).gameObject, (Object)(object)this);
		sockets = NaturalEyeSockets.Ensure(((Component)this).gameObject);
		nextBlink = Time.time + (float)Random.Range(2, 5);
		SkinnedMeshRenderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<SkinnedMeshRenderer>(true);
		foreach (SkinnedMeshRenderer val in componentsInChildren)
		{
			if (Object.op_Implicit((Object)(object)val.sharedMesh) && ((Object)val).name.IndexOf("Ink", StringComparison.OrdinalIgnoreCase) < 0)
			{
				Mesh sharedMesh = val.sharedMesh;
				int num = Shape(sharedMesh, "blink");
				if (num < 0)
				{
					num = Shape(sharedMesh, "Fac_Eye_Close");
				}
				if (num >= 0)
				{
					Face face = new Face
					{
						Renderer = val,
						Blink = num,
						Left = Shape(sharedMesh, "eyes_look_left"),
						Right = Shape(sharedMesh, "eyes_look_right"),
						Up = Shape(sharedMesh, "eyes_look_up"),
						Down = Shape(sharedMesh, "eyes_look_down")
					};
					morphGaze |= face.Left >= 0 && face.Right >= 0;
					faces.Add(face);
				}
			}
		}
		RemielleAdaptiveLighting component = ((Component)this).GetComponent<RemielleAdaptiveLighting>();
		if (!Object.op_Implicit((Object)(object)component))
		{
			return;
		}
		component.Rebind();
		component.BindContext(delegate
		{
			//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_0065: Unknown result type (might be due to invalid IL or missing references)
			bool factory = Object.op_Implicit((Object)(object)enemy) && !((EnemyAI)enemy).isOutside;
			int ship;
			if (Object.op_Implicit((Object)(object)enemy) && Object.op_Implicit((Object)(object)StartOfRound.Instance) && Object.op_Implicit((Object)(object)StartOfRound.Instance.shipInnerRoomBounds))
			{
				Bounds bounds = StartOfRound.Instance.shipInnerRoomBounds.bounds;
				ship = (((Bounds)(ref bounds)).Contains(((Component)enemy).transform.position) ? 1 : 0);
			}
			else
			{
				ship = 0;
			}
			return new RemielleLightingContext(factory, (byte)ship != 0);
		});
	}

	private void OnDestroy()
	{
		MaskedVanillaBadges.Release(vanillaBadges, (Object)(object)this);
	}

	private void LateUpdate()
	{
		//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_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: 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)
		if (!Object.op_Implicit((Object)(object)enemy))
		{
			return;
		}
		vanillaBadges?.Hide();
		if (!Object.op_Implicit((Object)(object)sockets))
		{
			return;
		}
		Vector2 target = Vector2.zero;
		PlayerControllerB targetPlayer = ((EnemyAI)enemy).targetPlayer;
		if (!((EnemyAI)enemy).isEnemyDead && Plugin.EyeTracking.Value && Object.op_Implicit((Object)(object)targetPlayer) && !targetPlayer.isPlayerDead && Object.op_Implicit((Object)(object)sockets.Head))
		{
			target = NaturalEyeMath.Target((Object.op_Implicit((Object)(object)targetPlayer.playerEye) ? targetPlayer.playerEye.position : (((Component)targetPlayer).transform.position + Vector3.up * 1.5f)) - sockets.Head.position, sockets.Forward, sockets.Up);
		}
		gaze = NaturalEyeMath.Smooth(gaze, target, Time.deltaTime);
		sockets.Aim(morphGaze ? Vector2.zero : gaze);
		if (Time.time >= nextBlink)
		{
			blinkStart = Time.time;
			nextBlink = Time.time + Random.Range(2.5f, 6f);
		}
		float num = Time.time - blinkStart;
		float value = ((!((EnemyAI)enemy).isEnemyDead && Plugin.Blink.Value && num >= 0f && num < 0.18f) ? (Mathf.Sin(num / 0.18f * (float)Math.PI) * 100f) : 0f);
		foreach (Face face in faces)
		{
			Set(face, face.Blink, value);
			Set(face, face.Left, Mathf.Max(0f, (0f - gaze.x) / 12f) * 20f);
			Set(face, face.Right, Mathf.Max(0f, gaze.x / 12f) * 20f);
			Set(face, face.Up, Mathf.Max(0f, (0f - gaze.y) / 7f) * 15f);
			Set(face, face.Down, Mathf.Max(0f, gaze.y / 9f) * 15f);
		}
	}
}
public static class MaskedCloneIsolation
{
	private const BindingFlags Flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

	private static bool IsOwner(Type type)
	{
		Type type2 = type;
		while (type2 != null)
		{
			if (type2.Name == "PlayerControllerB" || type2.Name == "BodyReplacementBase")
			{
				return true;
			}
			type2 = type2.BaseType;
		}
		return false;
	}

	private static void Clear(Type type, MonoBehaviour component, string field, object value)
	{
		FieldInfo field2 = type.GetField(field, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if (field2 != null && !field2.IsInitOnly)
		{
			field2.SetValue(component, value);
		}
	}

	public static void Detach(GameObject clone, string ownNamespace)
	{
		MonoBehaviour[] componentsInChildren = clone.GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if (!Object.op_Implicit((Object)(object)val) || ((object)val).GetType().Namespace != ownNamespace)
			{
				continue;
			}
			Type type = ((object)val).GetType();
			bool flag = false;
			FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo in fields)
			{
				if (IsOwner(fieldInfo.FieldType))
				{
					if (!fieldInfo.IsInitOnly)
					{
						fieldInfo.SetValue(val, null);
					}
					flag = true;
				}
			}
			if (!(type.Name == "RaidNightLod"))
			{
				if (flag || type.Name.EndsWith("ReactionFace", StringComparison.Ordinal) || type.Name.Contains("HeadTracking") || type.Name.EndsWith("Face", StringComparison.Ordinal) || type.Name.Contains("FirstPerson") || type.Name.Contains("RenderDiagnostics") || type.Name.Contains("RuntimeMotionAudit"))
				{
					((Behaviour)val).enabled = false;
				}
				if (type.Name.EndsWith("OutfitState", StringComparison.Ordinal))
				{
					Clear(type, val, "HasPlayerBinding", false);
					Clear(type, val, "Corpse", false);
					Clear(type, val, "SourceState", null);
					Clear(type, val, "AutomaticEars", false);
					type.GetMethod("Rebind", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null)?.Invoke(val, null);
				}
			}
		}
	}
}
public static class MaskedVanillaBadges
{
	public sealed class Binding
	{
		internal GameObject Enemy;

		internal object[] State;

		public void Hide()
		{
			MeshRenderer[] array = (MeshRenderer[])State[1];
			foreach (MeshRenderer val in array)
			{
				if (Object.op_Implicit((Object)(object)val) && ((Renderer)val).enabled)
				{
					((Renderer)val).enabled = false;
				}
			}
		}
	}

	private const string Chest = "ScavengerModel/metarig/spine/spine.001/spine.002/spine.003/";

	private const string StateKey = "RaidNight.SuitMods.MaskedVanillaBadges.v1";

	private static Dictionary<GameObject, object[]> Active
	{
		get
		{
			Dictionary<GameObject, object[]> dictionary = AppDomain.CurrentDomain.GetData("RaidNight.SuitMods.MaskedVanillaBadges.v1") as Dictionary<GameObject, object[]>;
			if (dictionary == null)
			{
				dictionary = new Dictionary<GameObject, object[]>();
				AppDomain.CurrentDomain.SetData("RaidNight.SuitMods.MaskedVanillaBadges.v1", dictionary);
			}
			return dictionary;
		}
	}

	public static Binding Bind(GameObject enemy, Object owner)
	{
		if (!Object.op_Implicit((Object)(object)enemy) || !Object.op_Implicit(owner))
		{
			return null;
		}
		if (Active.TryGetValue(enemy, out var value))
		{
			value[0] = owner;
			Binding binding = new Binding();
			binding.Enemy = enemy;
			binding.State = value;
			binding.Hide();
			return binding;
		}
		List<MeshRenderer> list = new List<MeshRenderer>();
		string[] array = new string[2] { "LevelSticker", "BetaBadge" };
		foreach (string text in array)
		{
			Transform val = enemy.transform.Find("ScavengerModel/metarig/spine/spine.001/spine.002/spine.003/" + text);
			MeshRenderer val2 = (Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponent<MeshRenderer>() : null);
			if (Object.op_Implicit((Object)(object)val2))
			{
				list.Add(val2);
			}
		}
		bool[] array2 = new bool[list.Count];
		for (int j = 0; j < list.Count; j++)
		{
			array2[j] = ((Renderer)list[j]).enabled;
		}
		object[] array3 = new object[3]
		{
			owner,
			list.ToArray(),
			array2
		};
		Binding obj = new Binding
		{
			Enemy = enemy,
			State = array3
		};
		Active.Add(enemy, array3);
		obj.Hide();
		return obj;
	}

	public static void Release(Binding binding, Object owner)
	{
		if (binding == null || binding.State[0] != owner || !Active.TryGetValue(binding.Enemy, out var value) || value != binding.State)
		{
			return;
		}
		Active.Remove(binding.Enemy);
		MeshRenderer[] array = (MeshRenderer[])binding.State[1];
		bool[] array2 = (bool[])binding.State[2];
		for (int i = 0; i < array.Length; i++)
		{
			if (Object.op_Implicit((Object)(object)array[i]))
			{
				((Renderer)array[i]).enabled = array2[i];
			}
		}
	}
}
public static class NaturalEyeMath
{
	public const float YawLimit = 12f;

	public const float UpLimit = 7f;

	public const float DownLimit = 9f;

	public const float SocketLimit = 12f;

	public const float MorphHorizontal = 20f;

	public const float MorphVertical = 15f;

	private static bool Finite(float v)
	{
		if (!float.IsNaN(v))
		{
			return !float.IsInfinity(v);
		}
		return false;
	}

	public static Vector2 Clamp(Vector2 angles)
	{
		//IL_0000: 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_000d: 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_003c: 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_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		if (!Finite(angles.x) || !Finite(angles.y))
		{
			return Vector2.zero;
		}
		float num = ((angles.y < 0f) ? 7f : 9f);
		angles.x = Mathf.Clamp(angles.x, -12f, 12f);
		angles.y = Mathf.Clamp(angles.y, -7f, 9f);
		float num2 = Mathf.Sqrt(angles.x * angles.x / 144f + angles.y * angles.y / (num * num));
		if (!(num2 > 1f))
		{
			return angles;
		}
		return angles / num2;
	}

	public static Vector2 Target(Vector3 local)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: 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_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: 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_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
		if (!Finite(local.x) || !Finite(local.y) || !Finite(local.z) || ((Vector3)(ref local)).sqrMagnitude < 1E-10f || local.z <= 0f)
		{
			return Vector2.zero;
		}
		float num = Mathf.Atan2(local.x, local.z) * 57.29578f;
		float num2 = (0f - Mathf.Atan2(local.y, Mathf.Sqrt(local.x * local.x + local.z * local.z))) * 57.29578f;
		float num3 = Mathf.Max(Mathf.Abs(num), Mathf.Abs(num2));
		float num4 = 1f - Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(60f, 90f, num3));
		return Clamp(new Vector2(num, num2)) * num4;
	}

	public static Vector2 Smooth(Vector2 current, Vector2 target, float dt)
	{
		//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_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		current = Clamp(current);
		target = Clamp(target);
		if (!Finite(dt) || dt <= 0f)
		{
			return current;
		}
		return Clamp(Vector2.Lerp(current, target, 1f - Mathf.Exp((0f - Mathf.Min(dt, 0.1f)) * 12f)));
	}

	public static Vector2 Target(Vector3 direction, Vector3 forward, Vector3 up)
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: 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_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		if (!(((Vector3)(ref forward)).sqrMagnitude < 1E-08f) && !(((Vector3)(ref up)).sqrMagnitude < 1E-08f))
		{
			Vector3 val = Vector3.Cross(up, forward);
			if (!(((Vector3)(ref val)).sqrMagnitude < 1E-08f))
			{
				return Target(Quaternion.Inverse(Quaternion.LookRotation(forward, up)) * direction);
			}
		}
		return Vector2.zero;
	}

	public static void Apply(Transform eye, Quaternion neutral, Vector3 forward, Vector3 up, Vector2 angles)
	{
		//IL_0016: 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_001d: 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_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: 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_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: 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)
		if (Object.op_Implicit((Object)(object)eye) && Object.op_Implicit((Object)(object)eye.parent))
		{
			angles = Clamp(angles);
			Quaternion val = Quaternion.LookRotation(forward, up);
			Quaternion val2 = Quaternion.Inverse(eye.parent.rotation) * val;
			Quaternion val3 = val2 * Quaternion.Euler(angles.y, angles.x, 0f) * Quaternion.Inverse(val2) * neutral;
			eye.localRotation = Quaternion.RotateTowards(neutral, val3, 12f);
		}
	}
}
[DefaultExecutionOrder(10000)]
public sealed class NaturalEyeSockets : MonoBehaviour
{
	public Transform Left;

	public Transform Right;

	public Transform Head;

	public Quaternion LeftNeutral = Quaternion.identity;

	public Quaternion RightNeutral = Quaternion.identity;

	public Quaternion HeadToLook = Quaternion.identity;

	public bool Captured;

	public Vector3 Forward
	{
		get
		{
			//IL_001f: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)Head))
			{
				return ((Component)this).transform.forward;
			}
			return Head.rotation * HeadToLook * Vector3.forward;
		}
	}

	public Vector3 Up
	{
		get
		{
			//IL_001f: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)Head))
			{
				return ((Component)this).transform.up;
			}
			return Head.rotation * HeadToLook * Vector3.up;
		}
	}

	public static NaturalEyeSockets Ensure(GameObject model)
	{
		NaturalEyeSockets naturalEyeSockets = model.GetComponent<NaturalEyeSockets>();
		if (!Object.op_Implicit((Object)(object)naturalEyeSockets))
		{
			naturalEyeSockets = model.AddComponent<NaturalEyeSockets>();
		}
		naturalEyeSockets.Capture();
		return naturalEyeSockets;
	}

	private void Awake()
	{
		Capture();
	}

	public void Capture()
	{
		//IL_0104: 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_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		if (Captured)
		{
			return;
		}
		Animator componentInChildren = ((Component)this).GetComponentInChildren<Animator>(true);
		if (Object.op_Implicit((Object)(object)componentInChildren) && componentInChildren.isHuman)
		{
			Head = componentInChildren.GetBoneTransform((HumanBodyBones)10);
			Left = componentInChildren.GetBoneTransform((HumanBodyBones)21);
			Right = componentInChildren.GetBoneTransform((HumanBodyBones)22);
		}
		Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(true);
		foreach (Transform val in componentsInChildren)
		{
			if (((Object)val).name == "head.x" || (!Object.op_Implicit((Object)(object)Head) && (((Object)val).name == "DEF-spine.006" || ((Object)val).name == "spine.004")))
			{
				Head = val;
			}
			if (((Object)val).name == "Skn_L_Eye")
			{
				Left = val;
			}
			if (((Object)val).name == "Skn_R_Eye")
			{
				Right = val;
			}
		}
		if (Object.op_Implicit((Object)(object)Left))
		{
			LeftNeutral = Left.localRotation;
		}
		if (Object.op_Implicit((Object)(object)Right))
		{
			RightNeutral = Right.localRotation;
		}
		Transform val2 = null;
		componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(true);
		foreach (Transform val3 in componentsInChildren)
		{
			if (((Object)val3).name.EndsWith("GazeFrame", StringComparison.Ordinal))
			{
				val2 = val3;
				break;
			}
		}
		if (Object.op_Implicit((Object)(object)Head))
		{
			HeadToLook = Quaternion.Inverse(Head.rotation) * (Object.op_Implicit((Object)(object)val2) ? val2.rotation : ((Component)this).transform.rotation);
		}
		Captured = Object.op_Implicit((Object)(object)Head);
	}

	private static void Limit(Transform eye, Quaternion neutral)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)eye))
		{
			eye.localRotation = Quaternion.RotateTowards(neutral, eye.localRotation, 12f);
		}
	}

	private void LateUpdate()
	{
		//IL_000d: 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)
		Capture();
		Limit(Left, LeftNeutral);
		Limit(Right, RightNeutral);
	}

	public void Aim(Vector2 angles)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_002b: 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_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)
		Capture();
		NaturalEyeMath.Apply(Left, LeftNeutral, Forward, Up, angles);
		NaturalEyeMath.Apply(Right, RightNeutral, Forward, Up, angles);
	}
}
[Serializable]
public struct RemielleLightingContext
{
	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 RemielleLightingContext(bool factory, bool ship)
	{
		InsideFactory = factory;
		InsideShip = ship;
	}
}
public sealed class RemielleCorpseLightingContext
{
	private RemielleLightingContext context;

	private bool trackedItem;

	public RemielleCorpseLightingContext(RemielleLightingContext death)
	{
		context = death;
	}

	public RemielleLightingContext Observe(bool bodyInShip, bool hasHolder, RemielleLightingContext holder, bool hasItem, RemielleLightingContext item)
	{
		if (hasHolder)
		{
			context = holder;
			trackedItem = true;
		}
		else if (hasItem && trackedItem)
		{
			context = item;
		}
		if (!bodyInShip)
		{
			return context;
		}
		return new RemielleLightingContext(factory: false, ship: true);
	}
}
[DefaultExecutionOrder(1100)]
public sealed class RemielleAdaptiveLighting : 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<RemielleLightingContext> 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 RemielleLightingContext 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<RemielleLightingContext> reader)
	{
		contextReader = reader;
		Refresh();
	}

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

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

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

	public void Apply(RemielleLightingContext 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 RemielleLightingControl
{
	private sealed class Death
	{
		internal ulong Owner;

		internal RemielleLightingContext 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 RemielleLightingContext Native(PlayerControllerB player)
	{
		if (!Object.op_Implicit((Object)(object)player))
		{
			return default(RemielleLightingContext);
		}
		return new RemielleLightingContext(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(RemielleLightingControl), "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(RemielleLightingControl), "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(RemielleLightingControl), "Ragdoll", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		harmony.Patch((MethodBase)AccessTools.Method(typeof(PlayerControllerB), "KillPlayer", (Type[])null, (Type[])null), new HarmonyMethod(typeof(RemielleLightingControl), "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(RemielleLightingControl), "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(RemielleLightingControl), "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("Remielle_", 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<RemielleAdaptiveLighting>()))
		{
			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;
		}
		RemielleAdaptiveLighting remielleAdaptiveLighting = model.GetComponent<RemielleAdaptiveLighting>() ?? model.AddComponent<RemielleAdaptiveLighting>();
		remielleAdaptiveLighting.Rebind();
		ulong owner = ((NetworkBehaviour)player).OwnerClientId;
		if (!corpse)
		{
			remielleAdaptiveLighting.BindContext(() => (!Object.op_Implicit((Object)(object)player) || ((NetworkBehaviour)player).OwnerClientId != owner) ? default(RemielleLightingContext) : Native(player));
			return;
		}
		Death value;
		RemielleLightingContext death = ((deaths.TryGetValue(player, out value) && value.Owner == owner) ? value.Context : Native(player));
		RemielleCorpseLightingContext corpseContext = new RemielleCorpseLightingContext(death);
		DeadBodyInfo nativeBody = player.deadBody;
		remielleAdaptiveLighting.BindContext(delegate
		{
			if (!Object.op_Implicit((Object)(object)nativeBody))
			{
				return corpseContext.Observe(bodyInShip: false, hasHolder: false, default(RemielleLightingContext), hasItem: false, default(RemielleLightingContext));
			}
			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 RemielleLightingContext(grabBodyObject.isInFactory, grabBodyObject.isInShipRoom) : default(RemielleLightingContext));
		});
	}

	internal static void Clear()
	{
		deaths.Clear();
	}
}
public static class RemielleAdventScale
{
	public const float NominalHeightCm = 167f;

	public const float EmployeeGeometryHeight = 2.5812242f;

	public const float EstimatedEmployeeHeightCm = 158.92772f;

	public const float WorldUnitsPerCm = 0.016241498f;

	public static float TotalHeightCm(string outfit)
	{
		string[] array = new string[3] { "Remielle_FeatheredMurmurs", "Remielle_MoonlightWhispers", "Remielle_SeashadePasSeul" };
		foreach (string value in array)
		{
			if (outfit != null && outfit.StartsWith(value, StringComparison.Ordinal))
			{
				return 167f;
			}
		}
		throw new InvalidOperationException("Unknown Remielle outfit for height calibration");
	}

	public static bool CalibratedHeight(float height)
	{
		return Math.Abs(height - 167f) < 0.001f;
	}

	public static float UniformScale(float crownHeight, string outfit)
	{
		if (float.IsNaN(crownHeight) || float.IsInfinity(crownHeight) || crownHeight <= 1E-05f)
		{
			throw new InvalidOperationException("Invalid Remielle hair crown height");
		}
		return 0.016241498f * TotalHeightCm(outfit) / crownHeight;
	}

	public static void Prepare(GameObject model)
	{
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0299: 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_02b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_020e: Unknown result type (might be due to invalid IL or missing references)
		//IL_021a: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0236: 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_0247: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0251: Unknown result type (might be due to invalid IL or missing references)
		//IL_0254: 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)
		if (!Object.op_Implicit((Object)(object)model))
		{
			return;
		}
		RemielleMotionLayout component = model.GetComponent<RemielleMotionLayout>();
		if (!Object.op_Implicit((Object)(object)component))
		{
			throw new InvalidOperationException("Missing Remielle scale layout");
		}
		if (CalibratedHeight(component.HeightCm))
		{
			return;
		}
		float heightCm = TotalHeightCm(((Object)model).name);
		float num = float.PositiveInfinity;
		float num2 = float.NegativeInfinity;
		Matrix4x4 worldToLocalMatrix = model.transform.worldToLocalMatrix;
		SkinnedMeshRenderer[] componentsInChildren = model.GetComponentsInChildren<SkinnedMeshRenderer>(true);
		foreach (SkinnedMeshRenderer val in componentsInChildren)
		{
			Mesh sharedMesh = val.sharedMesh;
			if (!Object.op_Implicit((Object)(object)sharedMesh))
			{
				continue;
			}
			Vector3[] vertices = sharedMesh.vertices;
			BoneWeight[] boneWeights = sharedMesh.boneWeights;
			Matrix4x4[] bindposes = sharedMesh.bindposes;
			Transform[] bones = val.bones;
			if (boneWeights.Length != vertices.Length || bones.Length != bindposes.Length)
			{
				throw new InvalidOperationException("Invalid Remielle skin palette");
			}
			Matrix4x4[] array = (Matrix4x4[])(object)new Matrix4x4[bones.Length];
			for (int j = 0; j < bones.Length; j++)
			{
				array[j] = worldToLocalMatrix * bones[j].localToWorldMatrix * bindposes[j];
			}
			bool[] array2 = new bool[vertices.Length];
			Material[] sharedMaterials = ((Renderer)val).sharedMaterials;
			for (int k = 0; k < sharedMaterials.Length; k++)
			{
				Material val2 = sharedMaterials[k];
				if (Object.op_Implicit((Object)(object)val2) && val2.HasProperty("_ZZZHair") && val2.GetFloat("_ZZZHair") > 0.5f)
				{
					int[] triangles = sharedMesh.GetTriangles(k);
					foreach (int num3 in triangles)
					{
						array2[num3] = true;
					}
				}
			}
			for (int m = 0; m < vertices.Length; m++)
			{
				BoneWeight val3 = boneWeights[m];
				Vector3 val4 = ((Matrix4x4)(ref array[((BoneWeight)(ref val3)).boneIndex0])).MultiplyPoint3x4(vertices[m]) * ((BoneWeight)(ref val3)).weight0 + ((Matrix4x4)(ref array[((BoneWeight)(ref val3)).boneIndex1])).MultiplyPoint3x4(vertices[m]) * ((BoneWeight)(ref val3)).weight1 + ((Matrix4x4)(ref array[((BoneWeight)(ref val3)).boneIndex2])).MultiplyPoint3x4(vertices[m]) * ((BoneWeight)(ref val3)).weight2 + ((Matrix4x4)(ref array[((BoneWeight)(ref val3)).boneIndex3])).MultiplyPoint3x4(vertices[m]) * ((BoneWeight)(ref val3)).weight3;
				num = Mathf.Min(num, val4.y);
				if (array2[m])
				{
					num2 = Mathf.Max(num2, val4.y);
				}
			}
		}
		component.WorldLocalScale = Vector3.one * UniformScale(num2 - num, ((Object)model).name);
		component.HeightCm = heightCm;
	}
}
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 RemielleAttentionSelection
{
	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 RemielleAttention
{
	private readonly RemielleAttentionSelection selection = new RemielleAttentionSelection();

	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 (RemielleAttentionSelection.InView(origin, forward, val, range))
		{
			int mask = (Object.op_Implicit((Object)(object)StartOfRound.Instance) ? StartOfRound.Instance.collidersAndRoomMaskAndDefault : (-5));
			if (RemielleAttentionSelection.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 = RemielleVoiceActivity.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 RemielleVoiceActivity
{
	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 = RemielleFace.Read(player, "voicePlayerState") ?? RemielleFace.Read(RemielleFace.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 = RemielleFace.Read(StartOfRound.Instance, "voiceChatModule");
			if (comms != null)
			{
				commsType = comms.GetType();
				string text = (((NetworkBehaviour)player).IsOwner ? (RemielleFace.Read(comms, "LocalPlayerName") as string) : (RemielleFace.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 = RemielleFace.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 = RemielleFace.Read(obj, "IsConnected");
		if (obj3 is bool && !(bool)obj3)
		{
			return false;
		}
		if (!(RemielleFace.Read(obj, "Amplitude") is float amplitude))
		{
			return flag2;
		}
		return RemielleAttentionSelection.ActiveSpeech(flag2, amplitude);
	}
}
public sealed class RemielleBundleCache
{
	public const string PackedSHA256 = "7ed7f5ad4557b70f83f8a24a742d074f1392756ce324357fd47fb02c939a54bb";

	public const uint ContentCRC = 2421796570u;

	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, "7ed7f5ad4557b70f83f8a24a742d074f1392756ce324357fd47fb02c939a54bb.bundle");
			string text = Guid.NewGuid().ToString("N");
			packedPath = Path.Combine(directory, "7ed7f5ad4557b70f83f8a24a742d074f1392756ce324357fd47fb02c939a54bb." + text + ".packed");
			pendingPath = Path.Combine(directory, "7ed7f5ad4557b70f83f8a24a742d074f1392756ce324357fd47fb02c939a54bb." + 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() != "7ed7f5ad4557b70f83f8a24a742d074f1392756ce324357fd47fb02c939a54bb")
			{
				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, 2421796570u);
		}
		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, 2421796570u, (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, 2421796570u);
		}
		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(310)]
public class RemielleChainMotion : MonoBehaviour
{
	private class Joint
	{
		public Transform Bone;

		public Quaternion Rest;

		public Quaternion PreviousParent;

		public Vector3 Offset;

		public Vector3 Velocity;

		public float Limit;

		public float Frequency;

		public float Response;

		public float Damping;

		public float Travel;

		public bool Dress;

		public bool Wing;

		public bool Minor;

		public Quaternion WingRest;

		public Quaternion Applied;

		public Vector3 WingAnchor;

		public Vector3 WingDirection;

		public Vector3 LocalTip = Vector3.zero;

		public Vector3 TipPosition;

		public Vector3 TipVelocity;

		public Vector3 PreviousPivot;
	}

	private readonly List<Joint> joints = new List<Joint>();

	private RemielleWingRestPose wingRestPose;

	private RemielleOriginalWingPhysics originalWings;

	private RemielleLegacyWingMotion legacyWings;

	private RemielleLegacyWingLayout legacyLayout;

	private readonly List<Joint> wingJoints = new List<Joint>();

	private Transform pelvis;

	private Vector3 previousPelvis;

	private Quaternion previousPelvisRotation;

	private Vector3 previousPosition;

	private Vector3 filteredVelocity;

	private Quaternion previousRotation;

	private int lastFrame = -1;

	private bool initialized;

	private RaidNightPhysicsBudget physicsBudget;

	private float performanceStepDelta;

	public int WingJointCount
	{
		get
		{
			if (!Object.op_Implicit((Object)(object)legacyLayout))
			{
				return wingJoints.Count;
			}
			return legacyLayout.Bones.Length;
		}
	}

	public float MaxWingSwing { get; private set; }

	public float MaxRearPlaneViolation { get; private set; }

	public int DressJointCount => 0;

	public float MaxDressSwing { get; private set; }

	public float MaxDressTipSpeed { get; private set; }

	public float MaxRibbonTotalSwing { get; private set; }

	public float DrapeBodyTilt { get; private set; }

	public int PinnedBowJointCount { get; private set; }

	public int SwimsuitSkirtControlCount { get; private set; }

	public int HemMountedTailCount { get; private set; }

	public float MaxHemMountedTailSwing { get; private set; }

	private void Awake()
	{
		Initialize();
	}

	public void ResetReferencePose()
	{
		initialized = false;
		Initialize();
	}

	private void Initialize()
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0504: Unknown result type (might be due to invalid IL or missing references)
		//IL_0509: Unknown result type (might be due to invalid IL or missing references)
		//IL_0515: Unknown result type (might be due to invalid IL or missing references)
		//IL_051a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0550: Unknown result type (might be due to invalid IL or missing references)
		//IL_0555: Unknown result type (might be due to invalid IL or missing references)
		//IL_0561: Unknown result type (might be due to invalid IL or missing references)
		//IL_0566: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0239: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_024b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0373: Unknown result type (might be due to invalid IL or missing references)
		//IL_0378: Unknown result type (might be due to invalid IL or missing references)
		//IL_037f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0384: Unknown result type (might be due to invalid IL or missing references)
		//IL_0389: Unknown result type (might be due to invalid IL or missing references)
		//IL_0398: Unknown result type (might be due to invalid IL or missing references)
		//IL_039d: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c7: Expected O, but got Unknown
		//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0400: Unknown result type (might be due to invalid IL or missing references)
		//IL_0445: Unknown result type (might be due to invalid IL or missing references)
		//IL_044a: Unknown result type (might be due to invalid IL or missing references)
		//IL_044f: Unknown result type (might be due to invalid IL or missing references)
		//IL_045e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0463: Unknown result type (might be due to invalid IL or missing references)
		//IL_0468: Unknown result type (might be due to invalid IL or missing references)
		//IL_0434: Unknown result type (might be due to invalid IL or missing references)
		//IL_0439: Unknown result type (might be due to invalid IL or missing references)
		if (initialized)
		{
			return;
		}
		initialized = true;
		joints.Clear();
		wingJoints.Clear();
		pelvis = null;
		lastFrame = -1;
		filteredVelocity = Vector3.zero;
		PinnedBowJointCount = 0;
		SwimsuitSkirtControlCount = 0;
		HemMountedTailCount = 0;
		legacyLayout = ((Component)this).GetComponent<RemielleLegacyWingLayout>();
		wingRestPose = ((Component)this).GetComponent<RemielleWingRestPose>();
		wingRestPose?.RestorePositions();
		Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>();
		Dictionary<string, Transform> dictionary = new Dictionary<string, Transform>();
		Transform[] array = componentsInChildren;
		foreach (Transform val in array)
		{
			if (((Object)val).name.StartsWith("_cloth_tip_"))
			{
				dictionary[((Object)val).name.Substring(11)] = val;
			}
			if (((Object)val).name == "root.x")
			{
				pelvis = val;
			}
		}
		array = componentsInChildren;
		foreach (Transform val2 in array)
		{
			bool flag = ((Object)val2).name.StartsWith("Ctr_") && ((Object)val2).name.Contains("Hair");
			bool flag2 = ((Object)val2).name.StartsWith("Skn_") && (((Object)val2).name.Contains("Sleeve") || ((Object)val2).name.Contains("Cuff") || ((Object)val2).name.Contains("Lingzi"));
			bool dress = ((Object)val2).name.StartsWith("Skn_") && (((Object)val2).name.Contains("Skirt") || ((Object)val2).name.Contains("SwimTie"));
			bool flag3 = !Object.op_Implicit((Object)(object)legacyLayout) && ((Object)val2).name.StartsWith("Skn_") && ((Object)val2).name.Contains("WingA_");
			if (!Object.op_Implicit((Object)(object)val2.parent) || (!flag && !flag3))
			{
				continue;
			}
			bool flag4 = flag3 && ((Object)val2).name.Contains("Yu");
			Joint joint = new Joint
			{
				Bone = val2,
				Rest = val2.localRotation,
				PreviousParent = val2.parent.rotation,
				Applied = val2.localRotation,
				Dress = dress,
				Minor = (flag2 && ((Object)val2).name.Contains("Cuff")),
				Limit = ((!flag3) ? (flag ? 20f : (((Object)val2).name.EndsWith("01") ? 12f : 24f)) : (flag4 ? 7f : (((Object)val2).name.EndsWith("01") ? 10f : 18f))),
				Frequency = ((!flag3) ? (flag ? 10f : 7f) : (flag4 ? 7f : 6f)),
				Response = (flag4 ? 0.035f : 0.1f),
				Damping = (flag3 ? 0.85f : (flag ? 1.05f : 0.8f)),
				Travel = (flag4 ? 4f : (flag3 ? 10f : 14f))
			};
			if (flag3)
			{
				joint.Wing = true;
				joint.WingRest = Quaternion.Inverse(pelvis.rotation) * val2.rotation;
				joint.WingAnchor = pelvis.InverseTransformPoint(val2.position);
				Vector3 val3 = Vector3.zero;
				foreach (Transform item in val2)
				{
					Transform val4 = item;
					if (((Object)val4).name.StartsWith("Skn_") && ((Object)val4).name.Contains("WingA_"))
					{
						val3 = val4.position - val2.position;
						break;
					}
				}
				if (((Vector3)(ref val3)).sqrMagnitude < 1E-10f)
				{
					val3 = val2.up;
				}
				joint.WingDirection = pelvis.InverseTransformDirection(((Vector3)(ref val3)).normalized);
				joint.PreviousPivot = pelvis.TransformPoint(joint.WingAnchor);
				wingJoints.Add(joint);
			}
			if (flag2)
			{
				joint.Limit = 5f;
				joint.Frequency = 12f;
				joint.Damping = 1.25f;
				joint.Travel = 4f;
			}
			if (flag)
			{
				joint.Limit = 12f;
				joint.Damping = 1.5f;
			}
			joints.Add(joint);
		}
		if (!Object.op_Implicit((Object)(object)pelvis))
		{
			pelvis = ((Component)this).transform;
		}
		previousPelvis = pelvis.position;
		previousPelvisRotation = pelvis.rotation;
		wingJoints.Sort((Joint a, Joint b) => HierarchyDepth(a.Bone).CompareTo(HierarchyDepth(b.Bone)));
		previousPosition = ((Component)this).transform.position;
		previousRotation = ((Component)this).transform.rotation;
	}

	private void LateUpdate()
	{
		Step();
	}

	private IEnumerable<Transform> LodBones()
	{
		foreach (Joint joint in joints)
		{
			yield return joint.Bone;
		}
		if (Object.op_Implicit((Object)(object)legacyLayout))
		{
			Transform[] bones = legacyLayout.Bones;
			for (int i = 0; i < bones.Length; i++)
			{
				yield return bones[i];
			}
		}
	}

	private void ResetLodSimulation()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_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_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0068: 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_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		lastFrame = -1;
		filteredVelocity = Vector3.zero;
		previousPosition = ((Component)this).transform.position;
		previousRotation = ((Component)this).transform.rotation;
		ResetDressMotion();
		foreach (Joint joint in joints)
		{
			joint.Offset = (joint.Velocity = (joint.TipVelocity = Vector3.zero));
			joint.PreviousParent = joint.Bone.parent.rotation;
			joint.TipPosition = joint.Bone.TransformPoint(joint.LocalTip);
			joint.PreviousPivot = joint.Bone.position;
		}
		legacyWings?.ResetLodSimulation();
	}

	public void Step()
	{
		Initialize();
		if (physicsBudget == null)
		{
			physicsBudget = new RaidNightPhysicsBudget((Component)(object)this, LodBones(), ResetLodSimulation);
		}
		float elapsed = Time.deltaTime;
		if (!physicsBudget.Begin(ref elapsed))
		{
			return;
		}
		try
		{
			StepFull(elapsed);
		}
		finally
		{
			physicsBudget.Capture();
		}
	}

	public void StepFull(float performanceDelta)
	{
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: 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_0136: 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_014c: 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_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: 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_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_024b: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0254: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0260: Unknown result type (might be due to invalid IL or missing references)
		//IL_0262: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_0218: 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_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0282: Unknown result type (might be due to invalid IL or missing references)
		//IL_028a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0308: Unknown result type (might be due to invalid IL or missing references)
		//IL_030d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0314: Unknown result type (might be due to invalid IL or missing references)
		//IL_031c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0323: Unknown result type (might be due to invalid IL or missing references)
		//IL_032f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0334: Unknown result type (might be due to invalid IL or missing references)
		//IL_0340: Unknown result type (might be due to invalid IL or missing references)
		//IL_0345: Unknown result type (might be due to invalid IL or missing references)
		//IL_034c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0351: Unknown result type (might be due to invalid IL or missing references)
		//IL_0358: Unknown result type (might be due to invalid IL or missing references)
		//IL_035d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0362: Unknown result type (might be due to invalid IL or missing references)
		//IL_0367: Unknown result type (might be due to invalid IL or missing references)
		//IL_038f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0394: Unknown result type (might be due to invalid IL or missing references)
		//IL_0398: Unknown result type (might be due to invalid IL or missing references)
		//IL_039d: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0401: Unknown result type (might be due to invalid IL or missing references)
		//IL_0406: Unknown result type (might be due to invalid IL or missing references)
		//IL_041e: Unknown result type (might be due to invalid IL or missing references)
		//IL_042a: Unknown result type (might be due to invalid IL or missing references)
		//IL_042f: Unknown result type (might be due to invalid IL or missing references)
		//IL_043d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0444: Unknown result type (might be due to invalid IL or missing references)
		//IL_0449: Unknown result type (might be due to invalid IL or missing references)
		//IL_044e: Unknown result type (might be due to invalid IL or missing references)
		//IL_045a: Unknown result type (might be due to invalid IL or missing references)
		//IL_045c: Unknown result type (might be due to invalid IL or missing references)
		performanceStepDelta = performanceDelta;
		Initialize();
		if (lastFrame == Time.frameCount)
		{
			legacyWings?.Step();
			wingRestPose?.RestorePositions();
			{
				foreach (Joint joint in joints)
				{
					if (Object.op_Implicit((Object)(object)joint.Bone))
					{
						joint.Bone.localRotation = ((joint.Dress || joint.Wing) ? joint.Applied : (joint.Rest * Quaternion.Euler(joint.Offset)));
					}
				}
				return;
			}
		}
		bool flag = lastFrame < 0;
		lastFrame = Time.frameCount;
		float num = Mathf.Min(performanceDelta, 0.04f);
		if (num <= 0f)
		{
			return;
		}
		Vector3 val = ((Component)this).transform.position - previousPosition;
		bool flag2 = flag || ((Vector3)(ref val)).sqrMagnitude > 2.25f || Quaternion.Angle(previousRotation, ((Component)this).transform.rotation) > 80f;
		Vector3 val2 = (flag2 ? Vector3.zero : Vector3.ClampMagnitude(val / num, 4f));
		filteredVelocity = Vector3.Lerp(filteredVelocity, val2, 1f - Mathf.Exp((0f - num) * 12f));
		previousPosition = ((Component)this).transform.position;
		previousRotation = ((Component)this).transform.rotation;
		RaidNightLod component = ((Component)this).GetComponent<RaidNightLod>();
		bool flag3 = Object.op_Implicit((Object)(object)component) && component.Crowded;
		float num2 = default(float);
		Vector3 zero = default(Vector3);
		foreach (Joint joint2 in joints)
		{
			if (joint2.Dress || joint2.Wing)
			{
				continue;
			}
			if (joint2.Minor && flag3)
			{
				joint2.Offset = (joint2.Velocity = Vector3.zero);
				joint2.PreviousParent = joint2.Bone.parent.rotation;
				joint2.Bone.localRotation = joint2.Rest;
				continue;
			}
			Quaternion rotation = joint2.Bone.parent.rotation;
			Quaternion val3 = Quaternion.Inverse(joint2.PreviousParent) * rotation;
			if (val3.w < 0f)
			{
				((Quaternion)(ref val3))..ctor(0f - val3.x, 0f - val3.y, 0f - val3.z, 0f - val3.w);
			}
			((Quaternion)(ref val3)).ToAngleAxis(ref num2, ref zero);
			if (num2 > 180f)
			{
				num2 -= 360f;
			}
			if (float.IsNaN(zero.x) || float.IsInfinity(zero.x))
			{
				zero = Vector3.zero;
			}
			Vector3 val4 = joint2.Bone.parent.InverseTransformDirection(filteredVelocity);
			Vector3 val5 = Vector3.ClampMagnitude(-zero * (num2 / num) * joint2.Response + new Vector3(val4.z, 0f - val4.x, val4.x) * joint2.Travel, joint2.Limit);
			if (flag2)
			{
				joint2.Offset = Vector3.zero;
				joint2.Velocity = Vector3.zero;
				val5 = Vector3.zero;
			}
			int num3 = Mathf.Max(1, Mathf.CeilToInt(num / 0.008f));
			float num4 = num / (float)num3;
			for (int i = 0; i < num3; i++)
			{
				joint2.Velocity += ((val5 - joint2.Offset) * joint2.Frequency * joint2.Frequency - joint2.Velocity * (joint2.Damping * joint2.Frequency)) * num4;
				joint2.Offset += joint2.Velocity * num4;
			}
			joint2.Offset = Vector3.ClampMagnitude(joint2.Offset, joint2.Limit);
			joint2.Bone.localRotation = joint2.Rest * Quaternion.Euler(joint2.Offset);
			joint2.PreviousParent = rotation;
		}
		StepWings(flag, num);
	}

	private void StepWings(bool first, float dt)
	{
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)legacyLayout))
		{
			if (!Object.op_Implicit((Object)(object)legacyWings))
			{
				legacyWings = ((Component)this).GetComponent<RemielleLegacyWingMotion>();
				if (!Object.op_Implicit((Object)(object)legacyWings))
				{
					legacyWings = ((Component)this).gameObject.AddComponent<RemielleLegacyWingMotion>();
				}
			}
			legacyWings.Elapsed = performanceStepDelta;
			legacyWings.Step();
			MaxWingSwing = legacyWings.MaxS