Decompiled source of HLVRAI Suits v1.0.4

HLVRAI Mod Compile.dll

Decompiled 8 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("HLVRAI Mod Compile")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HLVRAI Mod Compile")]
[assembly: AssemblyTitle("HLVRAI Mod Compile")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace ModelReplacement
{
	public class BubbyReplacement : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			string text = "nerd";
			return Assets.MainAssetBundle.LoadAsset<GameObject>(text);
		}
	}
	public class DrCoomerReplacement : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			string text = "Einstien";
			return Assets.MainAssetBundle.LoadAsset<GameObject>(text);
		}
	}
	public class BenreyReplacement : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			string text = "0000_BARNEY-X";
			return Assets.MainAssetBundle.LoadAsset<GameObject>(text);
		}
	}
	public class TommyReplacement : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			string text = "slick";
			return Assets.MainAssetBundle.LoadAsset<GameObject>(text);
		}
	}
	[BepInPlugin("com.ImNotZelda.AllHLVRAI", "Half Life VR AI Compiled Mod", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static ConfigFile config;

		public static ConfigEntry<bool> enableModelForAllSuits { get; private set; }

		public static ConfigEntry<bool> enableModelAsDefault { get; private set; }

		public static ConfigEntry<string> suitNamesToEnableModel { get; private set; }

		private static void InitConfig()
		{
			enableModelForAllSuits = config.Bind<bool>("Suits to Replace Settings", "Enable Model for all Suits", false, "Enable to model replace every suit. Set to false to specify suits");
			enableModelAsDefault = config.Bind<bool>("Suits to Replace Settings", "Enable Model as default", false, "Enable to model replace every suit that hasn't been otherwise registered.");
			suitNamesToEnableModel = config.Bind<string>("Suits to Replace Settings", "Suits to enable Model for", "Dr. Coomer,Bubby,Tommy,Benrey", "Enter a comma separated list of suit names.(Additionally, [Green suit,Pajama suit,Hazard suit])");
		}

		private void Awake()
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Expected O, but got Unknown
			config = ((BaseUnityPlugin)this).Config;
			InitConfig();
			Assets.PopulateAssets();
			string[] array = suitNamesToEnableModel.Value.Split(',');
			string[] array2 = array;
			foreach (string text in array2)
			{
				ModelReplacementAPI.RegisterSuitModelReplacement("Dr. Coomer", typeof(DrCoomerReplacement));
				ModelReplacementAPI.RegisterSuitModelReplacement("Bubby", typeof(BubbyReplacement));
				ModelReplacementAPI.RegisterSuitModelReplacement("Tommy", typeof(TommyReplacement));
				ModelReplacementAPI.RegisterSuitModelReplacement("Benrey", typeof(BenreyReplacement));
			}
			Harmony val = new Harmony("com.ImNotZelda.AllHLVRAI");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin com.ImNotZelda.AllHLVRAI is loaded!");
		}
	}
	public static class Assets
	{
		public static string mainAssetBundleName = "templatebundle";

		public static AssetBundle MainAssetBundle = null;

		private static string GetAssemblyName()
		{
			return Assembly.GetExecutingAssembly().GetName().Name.Replace(" ", "_");
		}

		public static void PopulateAssets()
		{
			if ((Object)(object)MainAssetBundle == (Object)null)
			{
				Console.WriteLine(GetAssemblyName() + "." + mainAssetBundleName);
				using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(GetAssemblyName() + "." + mainAssetBundleName);
				MainAssetBundle = AssetBundle.LoadFromStream(stream);
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}

ModelReplacementAPI.dll

Decompiled 8 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LCThirdPerson;
using Microsoft.CodeAnalysis;
using ModelReplacement;
using ModelReplacement.AvatarBodyUpdater;
using ModelReplacement.Modules;
using MoreCompany.Cosmetics;
using Steamworks.Data;
using TooManyEmotes;
using TooManyEmotes.Patches;
using UnityEngine;
using UnityEngine.LowLevel;
using UnityEngine.PlayerLoop;
using UnityEngine.Pool;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.Serialization;
using _3rdPerson.Helper;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ModelReplacementAPI")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("https://github.com/BunyaPineTree/LethalCompany_ModelReplacementAPI")]
[assembly: AssemblyProduct("meow.ModelReplacementAPI")]
[assembly: AssemblyCopyright("Copyright © meow 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("6390E70C-AB5E-42ED-BA29-F173942DC3A9")]
[assembly: AssemblyFileVersion("2.3.8")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.3.8.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
[HarmonyPatch(typeof(GrabbableObject))]
public class LocateHeldObjectsOnModelReplacementPatch
{
	[HarmonyPatch("LateUpdate")]
	[HarmonyPostfix]
	public static void LateUpdatePatch(ref GrabbableObject __instance)
	{
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)__instance.parentObject == (Object)null) && !((Object)(object)__instance.playerHeldBy == (Object)null))
		{
			BodyReplacementBase component = ((Component)__instance.playerHeldBy).gameObject.GetComponent<BodyReplacementBase>();
			if (Object.op_Implicit((Object)(object)component) && component.viewState.GetViewState() == ViewState.ThirdPerson)
			{
				Transform itemHolder = component.avatar.ItemHolder;
				itemHolder.localPosition = component.avatar.ItemHolderPositionOffset;
				Transform playerItemHolder = component.avatar.GetPlayerItemHolder();
				((Component)__instance).transform.rotation = playerItemHolder.rotation;
				((Component)__instance).transform.Rotate(__instance.itemProperties.rotationOffset);
				((Component)__instance).transform.position = itemHolder.position;
				Vector3 positionOffset = __instance.itemProperties.positionOffset;
				positionOffset = playerItemHolder.rotation * positionOffset;
				Transform transform = ((Component)__instance).transform;
				transform.position += positionOffset;
			}
		}
	}
}
[HarmonyPatch(typeof(StartOfRound))]
public class RepairBrokenBodyReplacementsPatch
{
	[HarmonyPatch("ReviveDeadPlayers")]
	[HarmonyPostfix]
	public static void ReviveDeadPlayersPatch(ref StartOfRound __instance)
	{
		PlayerControllerB[] allPlayerScripts = __instance.allPlayerScripts;
		foreach (PlayerControllerB val in allPlayerScripts)
		{
			if (val.isPlayerDead)
			{
				ModelReplacementAPI.ResetPlayerModelReplacement(val);
			}
		}
	}
}
namespace JigglePhysics
{
	public static class CachedSphereCollider
	{
		private class DestroyListener : MonoBehaviour
		{
			private void OnDestroy()
			{
				_hasSphere = false;
			}
		}

		private static bool _hasSphere;

		private static SphereCollider _sphereCollider;

		public static void StartPass()
		{
			if (TryGet(out var collider))
			{
				((Collider)collider).enabled = true;
			}
		}

		public static void FinishedPass()
		{
			if (TryGet(out var collider))
			{
				((Collider)collider).enabled = false;
			}
		}

		public static bool TryGet(out SphereCollider collider)
		{
			//IL_0040: 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_004f: Expected O, but got Unknown
			if (_hasSphere)
			{
				collider = _sphereCollider;
				return true;
			}
			try
			{
				GameObject val = new GameObject("JiggleBoneSphereCollider", new Type[2]
				{
					typeof(SphereCollider),
					typeof(DestroyListener)
				})
				{
					hideFlags = (HideFlags)61
				};
				if (Application.isPlaying)
				{
					Object.DontDestroyOnLoad((Object)(object)val);
				}
				_sphereCollider = val.GetComponent<SphereCollider>();
				collider = _sphereCollider;
				((Collider)collider).enabled = false;
				_hasSphere = true;
				return true;
			}
			catch
			{
				if ((Object)(object)_sphereCollider != (Object)null)
				{
					if (Application.isPlaying)
					{
						Object.Destroy((Object)(object)((Component)_sphereCollider).gameObject);
					}
					else
					{
						Object.DestroyImmediate((Object)(object)((Component)_sphereCollider).gameObject);
					}
				}
				_hasSphere = false;
				collider = null;
				throw;
			}
		}
	}
	public class JiggleBone
	{
		private readonly bool hasTransform;

		private readonly PositionSignal targetAnimatedBoneSignal;

		private Vector3 currentFixedAnimatedBonePosition;

		public readonly JiggleBone parent;

		private JiggleBone child;

		private Quaternion boneRotationChangeCheck;

		private Vector3 bonePositionChangeCheck;

		private Quaternion lastValidPoseBoneRotation;

		private float projectionAmount;

		private Vector3 lastValidPoseBoneLocalPosition;

		private float normalizedIndex;

		public readonly Transform transform;

		private readonly PositionSignal particleSignal;

		private Vector3 workingPosition;

		private Vector3? preTeleportPosition;

		private Vector3 extrapolatedPosition;

		private float GetLengthToParent()
		{
			//IL_0018: 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)
			if (parent == null)
			{
				return 0.1f;
			}
			return Vector3.Distance(currentFixedAnimatedBonePosition, parent.currentFixedAnimatedBonePosition);
		}

		public JiggleBone(Transform transform, JiggleBone parent, float projectionAmount = 1f)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			this.transform = transform;
			this.parent = parent;
			this.projectionAmount = projectionAmount;
			Vector3 startPosition;
			if ((Object)(object)transform != (Object)null)
			{
				lastValidPoseBoneRotation = transform.localRotation;
				lastValidPoseBoneLocalPosition = transform.localPosition;
				startPosition = transform.position;
			}
			else
			{
				startPosition = GetProjectedPosition();
			}
			targetAnimatedBoneSignal = new PositionSignal(startPosition, Time.timeAsDouble);
			particleSignal = new PositionSignal(startPosition, Time.timeAsDouble);
			hasTransform = (Object)(object)transform != (Object)null;
			if (parent != null)
			{
				this.parent.child = this;
			}
		}

		public void CalculateNormalizedIndex()
		{
			int num = 0;
			JiggleBone jiggleBone = this;
			while (jiggleBone.parent != null)
			{
				jiggleBone = jiggleBone.parent;
				num++;
			}
			int num2 = 0;
			jiggleBone = this;
			while (jiggleBone.child != null)
			{
				jiggleBone = jiggleBone.child;
				num2++;
			}
			int num3 = num + num2;
			float num4 = (float)num / (float)num3;
			normalizedIndex = num4;
		}

		public void VerletPass(JiggleSettingsData jiggleSettings, Vector3 wind, double time)
		{
			//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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			currentFixedAnimatedBonePosition = targetAnimatedBoneSignal.SamplePosition(time);
			if (parent == null)
			{
				workingPosition = currentFixedAnimatedBonePosition;
				particleSignal.SetPosition(workingPosition, time);
			}
			else
			{
				Vector3 localSpaceVelocity = particleSignal.GetCurrent() - particleSignal.GetPrevious() - (parent.particleSignal.GetCurrent() - parent.particleSignal.GetPrevious());
				workingPosition = NextPhysicsPosition(particleSignal.GetCurrent(), particleSignal.GetPrevious(), localSpaceVelocity, Time.fixedDeltaTime, jiggleSettings.gravityMultiplier, jiggleSettings.friction, jiggleSettings.airDrag);
				workingPosition += wind * (Time.fixedDeltaTime * jiggleSettings.airDrag);
			}
		}

		public void CollisionPreparePass(JiggleSettingsData jiggleSettings)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			workingPosition = ConstrainLengthBackwards(workingPosition, jiggleSettings.lengthElasticity * jiggleSettings.lengthElasticity * 0.5f);
		}

		public void ConstraintPass(JiggleSettingsData jiggleSettings)
		{
			//IL_0014: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			if (parent != null)
			{
				workingPosition = ConstrainAngle(workingPosition, jiggleSettings.angleElasticity * jiggleSettings.angleElasticity, jiggleSettings.elasticitySoften);
				workingPosition = ConstrainLength(workingPosition, jiggleSettings.lengthElasticity * jiggleSettings.lengthElasticity);
			}
		}

		public void CollisionPass(JiggleSettingsBase jiggleSettings, List<Collider> colliders)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			if (colliders.Count == 0 || !CachedSphereCollider.TryGet(out var collider))
			{
				return;
			}
			Vector3 val = default(Vector3);
			float num = default(float);
			foreach (Collider collider2 in colliders)
			{
				collider.radius = jiggleSettings.GetRadius(normalizedIndex);
				if (!(collider.radius <= 0f) && Physics.ComputePenetration((Collider)(object)collider, workingPosition, Quaternion.identity, collider2, ((Component)collider2).transform.position, ((Component)collider2).transform.rotation, ref val, ref num))
				{
					workingPosition += val * num;
				}
			}
		}

		public void SignalWritePosition(double time)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			particleSignal.SetPosition(workingPosition, time);
		}

		private Vector3 GetProjectedPosition()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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)
			Vector3 position = parent.transform.position;
			return parent.transform.TransformPoint(parent.GetParentTransform().InverseTransformPoint(position) * projectionAmount);
		}

		private Vector3 GetTransformPosition()
		{
			//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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			if (!hasTransform)
			{
				return GetProjectedPosition();
			}
			return transform.position;
		}

		private Transform GetParentTransform()
		{
			if (parent != null)
			{
				return parent.transform;
			}
			return transform.parent;
		}

		private void CacheAnimationPosition()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			if (!hasTransform)
			{
				targetAnimatedBoneSignal.SetPosition(GetProjectedPosition(), Time.timeAsDouble);
				return;
			}
			targetAnimatedBoneSignal.SetPosition(transform.position, Time.timeAsDouble);
			lastValidPoseBoneRotation = transform.localRotation;
			lastValidPoseBoneLocalPosition = transform.localPosition;
		}

		private Vector3 ConstrainLengthBackwards(Vector3 newPosition, float elasticity)
		{
			//IL_0013: 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_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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			if (child == null)
			{
				return newPosition;
			}
			Vector3 val = newPosition - child.workingPosition;
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			return Vector3.Lerp(newPosition, child.workingPosition + normalized * child.GetLengthToParent(), elasticity);
		}

		private Vector3 ConstrainLength(Vector3 newPosition, float elasticity)
		{
			//IL_0001: 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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = newPosition - parent.workingPosition;
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			return Vector3.Lerp(newPosition, parent.workingPosition + normalized * GetLengthToParent(), elasticity);
		}

		public void MatchAnimationInstantly()
		{
			//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_0015: 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)
			double timeAsDouble = Time.timeAsDouble;
			Vector3 transformPosition = GetTransformPosition();
			targetAnimatedBoneSignal.FlattenSignal(timeAsDouble, transformPosition);
			particleSignal.FlattenSignal(timeAsDouble, transformPosition);
		}

		public void PrepareTeleport()
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			preTeleportPosition = GetTransformPosition();
		}

		public void FinishTeleport()
		{
			//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_0024: 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_0041: 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_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)
			if (!preTeleportPosition.HasValue)
			{
				MatchAnimationInstantly();
				return;
			}
			Vector3 transformPosition = GetTransformPosition();
			Vector3 val = transformPosition - preTeleportPosition.Value;
			targetAnimatedBoneSignal.FlattenSignal(Time.timeAsDouble, transformPosition);
			particleSignal.OffsetSignal(val);
			workingPosition += val;
		}

		private Vector3 ConstrainAngleBackward(Vector3 newPosition, float elasticity, float elasticitySoften)
		{
			//IL_0034: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			if (child == null || child.child == null)
			{
				return newPosition;
			}
			Vector3 val = child.child.currentFixedAnimatedBonePosition - child.currentFixedAnimatedBonePosition;
			Vector3 val2 = child.child.workingPosition - child.workingPosition;
			Quaternion val3 = Quaternion.FromToRotation(val, val2);
			Vector3 val4 = newPosition - child.workingPosition;
			Vector3 val5 = val3 * val4;
			Debug.DrawLine(newPosition, child.workingPosition + val5, Color.cyan);
			float num = Vector3.Distance(newPosition, child.workingPosition + val5);
			num /= child.GetLengthToParent();
			num = Mathf.Clamp01(num);
			num = Mathf.Pow(num, elasticitySoften * 2f);
			return Vector3.Lerp(newPosition, child.workingPosition + val5, elasticity * num);
		}

		private Vector3 ConstrainAngle(Vector3 newPosition, float elasticity, float elasticitySoften)
		{
			//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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_0043: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			if (!hasTransform && projectionAmount == 0f)
			{
				return newPosition;
			}
			Vector3 val;
			Vector3 val2;
			if (parent.parent == null)
			{
				val = parent.currentFixedAnimatedBonePosition + (parent.currentFixedAnimatedBonePosition - currentFixedAnimatedBonePosition);
				val2 = val;
			}
			else
			{
				val2 = parent.parent.workingPosition;
				val = parent.parent.currentFixedAnimatedBonePosition;
			}
			Vector3 val3 = parent.currentFixedAnimatedBonePosition - val;
			Vector3 val4 = parent.workingPosition - val2;
			Quaternion val5 = Quaternion.FromToRotation(val3, val4);
			Vector3 val6 = currentFixedAnimatedBonePosition - val;
			Vector3 val7 = val5 * val6;
			float num = Vector3.Distance(newPosition, val2 + val7);
			num /= GetLengthToParent();
			num = Mathf.Clamp01(num);
			num = Mathf.Pow(num, elasticitySoften * 2f);
			return Vector3.Lerp(newPosition, val2 + val7, elasticity * num);
		}

		public static Vector3 NextPhysicsPosition(Vector3 newPosition, Vector3 previousPosition, Vector3 localSpaceVelocity, float deltaTime, float gravityMultiplier, float friction, float airFriction)
		{
			//IL_0005: 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_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0027: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			float num = deltaTime * deltaTime;
			Vector3 val = newPosition - previousPosition - localSpaceVelocity;
			return newPosition + val * (1f - airFriction) + localSpaceVelocity * (1f - friction) + Physics.gravity * (gravityMultiplier * num);
		}

		public void DebugDraw(Color simulateColor, Color targetColor, bool interpolated)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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)
			if (parent != null)
			{
				if (interpolated)
				{
					Debug.DrawLine(extrapolatedPosition, parent.extrapolatedPosition, simulateColor, 0f, false);
				}
				else
				{
					Debug.DrawLine(workingPosition, parent.workingPosition, simulateColor, 0f, false);
				}
				Debug.DrawLine(currentFixedAnimatedBonePosition, parent.currentFixedAnimatedBonePosition, targetColor, 0f, false);
			}
		}

		public Vector3 DeriveFinalSolvePosition(Vector3 offset)
		{
			//IL_0002: 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_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0026: Unknown result type (might be due to invalid IL or missing references)
			extrapolatedPosition = offset + particleSignal.SamplePosition(Time.timeAsDouble);
			return extrapolatedPosition;
		}

		public Vector3 GetCachedSolvePosition()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return extrapolatedPosition;
		}

		public void PrepareBone()
		{
			//IL_000d: 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_003b: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			if (hasTransform)
			{
				if (boneRotationChangeCheck == transform.localRotation)
				{
					transform.localRotation = lastValidPoseBoneRotation;
				}
				if (bonePositionChangeCheck == transform.localPosition)
				{
					transform.localPosition = lastValidPoseBoneLocalPosition;
				}
			}
			CacheAnimationPosition();
		}

		public void OnDrawGizmos(JiggleSettingsBase jiggleSettings)
		{
			//IL_0036: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)transform != (Object)null && child != null && (Object)(object)child.transform != (Object)null)
			{
				Gizmos.DrawLine(transform.position, child.transform.position);
			}
			if ((Object)(object)transform != (Object)null && child != null && (Object)(object)child.transform == (Object)null)
			{
				Gizmos.DrawLine(transform.position, child.GetProjectedPosition());
			}
			if ((Object)(object)transform != (Object)null && (Object)(object)jiggleSettings != (Object)null)
			{
				Gizmos.DrawWireSphere(transform.position, jiggleSettings.GetRadius(normalizedIndex));
			}
			if ((Object)(object)transform == (Object)null && (Object)(object)jiggleSettings != (Object)null)
			{
				Gizmos.DrawWireSphere(GetProjectedPosition(), jiggleSettings.GetRadius(normalizedIndex));
			}
		}

		public void PoseBone(float blend)
		{
			//IL_001d: 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_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			if (child != null)
			{
				Vector3 val = Vector3.Lerp(targetAnimatedBoneSignal.SamplePosition(Time.timeAsDouble), extrapolatedPosition, blend);
				Vector3 val2 = Vector3.Lerp(child.targetAnimatedBoneSignal.SamplePosition(Time.timeAsDouble), child.extrapolatedPosition, blend);
				if (parent != null)
				{
					transform.position = val;
				}
				Vector3 transformPosition = child.GetTransformPosition();
				Vector3 val3 = transformPosition - transform.position;
				Vector3 val4 = val2 - val;
				Quaternion val5 = Quaternion.FromToRotation(val3, val4);
				transform.rotation = val5 * transform.rotation;
			}
			if (hasTransform)
			{
				boneRotationChangeCheck = transform.localRotation;
				bonePositionChangeCheck = transform.localPosition;
			}
		}
	}
	[DefaultExecutionOrder(200)]
	public class JiggleRigBuilder : MonoBehaviour
	{
		[SerializeField]
		[Tooltip("The root bone from which an individual JiggleRig will be constructed. The JiggleRig encompasses all children of the specified root.")]
		[FormerlySerializedAs("target")]
		private Transform rootTransform;

		[Tooltip("The settings that the rig should update with, create them using the Create->JigglePhysics->Settings menu option.")]
		public JiggleSettingsBase jiggleSettings;

		[SerializeField]
		[Tooltip("The list of transforms to ignore during the jiggle. Each bone listed will also ignore all the children of the specified bone.")]
		private List<Transform> ignoredTransforms;

		public List<Collider> colliders;

		[Tooltip("An air force that is applied to the entire rig, this is useful to plug in some wind volumes from external sources.")]
		public Vector3 wind;

		[Tooltip("Level of detail manager. This system will control how the jiggle rig saves performance cost.")]
		public JiggleRigLOD levelOfDetail;

		[Tooltip("Draws some simple lines to show what the simulation is doing. Generally this should be disabled.")]
		[SerializeField]
		private bool debugDraw;

		private JiggleSettingsData data;

		private bool initialized;

		[HideInInspector]
		protected List<JiggleBone> simulatedPoints;

		private double accumulation;

		private bool dirtyFromEnable = false;

		private bool wasLODActive = true;

		public static float maxCatchupTime => Time.fixedDeltaTime * 4f;

		private bool NeedsCollisions => colliders.Count != 0;

		public Transform GetRootTransform()
		{
			return rootTransform;
		}

		public void PrepareBone(Vector3 position, JiggleRigLOD jiggleRigLOD)
		{
			//IL_0014: 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)
			if (!initialized)
			{
				throw new UnityException("JiggleRig was never initialized. Please call JiggleRig.Initialize() if you're going to manually timestep.");
			}
			foreach (JiggleBone simulatedPoint in simulatedPoints)
			{
				simulatedPoint.PrepareBone();
			}
			data = jiggleSettings.GetData();
			data = (((Object)(object)jiggleRigLOD != (Object)null) ? jiggleRigLOD.AdjustJiggleSettingsData(position, data) : data);
		}

		public void MatchAnimationInstantly()
		{
			foreach (JiggleBone simulatedPoint in simulatedPoints)
			{
				simulatedPoint.MatchAnimationInstantly();
			}
		}

		public void UpdateJiggle(Vector3 wind, double time)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			foreach (JiggleBone simulatedPoint in simulatedPoints)
			{
				simulatedPoint.VerletPass(data, wind, time);
			}
			if (NeedsCollisions)
			{
				for (int num = simulatedPoints.Count - 1; num >= 0; num--)
				{
					simulatedPoints[num].CollisionPreparePass(data);
				}
			}
			foreach (JiggleBone simulatedPoint2 in simulatedPoints)
			{
				simulatedPoint2.ConstraintPass(data);
			}
			if (NeedsCollisions)
			{
				foreach (JiggleBone simulatedPoint3 in simulatedPoints)
				{
					simulatedPoint3.CollisionPass(jiggleSettings, colliders);
				}
			}
			foreach (JiggleBone simulatedPoint4 in simulatedPoints)
			{
				simulatedPoint4.SignalWritePosition(time);
			}
		}

		public void DeriveFinalSolve()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_002e: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = simulatedPoints[0].DeriveFinalSolvePosition(Vector3.zero);
			Vector3 offset = simulatedPoints[0].transform.position - val;
			foreach (JiggleBone simulatedPoint in simulatedPoints)
			{
				simulatedPoint.DeriveFinalSolvePosition(offset);
			}
		}

		public void Pose(bool debugDraw)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			DeriveFinalSolve();
			foreach (JiggleBone simulatedPoint in simulatedPoints)
			{
				simulatedPoint.PoseBone(data.blend);
				if (debugDraw)
				{
					simulatedPoint.DebugDraw(Color.red, Color.blue, interpolated: true);
				}
			}
		}

		public void PrepareTeleport()
		{
			foreach (JiggleBone simulatedPoint in simulatedPoints)
			{
				simulatedPoint.PrepareTeleport();
			}
		}

		public void FinishTeleport()
		{
			foreach (JiggleBone simulatedPoint in simulatedPoints)
			{
				simulatedPoint.FinishTeleport();
			}
		}

		protected virtual void CreateSimulatedPoints(ICollection<JiggleBone> outputPoints, ICollection<Transform> ignoredTransforms, Transform currentTransform, JiggleBone parentJiggleBone)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			JiggleBone jiggleBone = new JiggleBone(currentTransform, parentJiggleBone);
			outputPoints.Add(jiggleBone);
			if (currentTransform.childCount == 0)
			{
				if (jiggleBone.parent == null)
				{
					if ((Object)(object)jiggleBone.transform.parent == (Object)null)
					{
						throw new UnityException("Can't have a singular jiggle bone with no parents. That doesn't even make sense!");
					}
					outputPoints.Add(new JiggleBone(null, jiggleBone));
				}
				else
				{
					outputPoints.Add(new JiggleBone(null, jiggleBone));
				}
				return;
			}
			for (int i = 0; i < currentTransform.childCount; i++)
			{
				if (!ignoredTransforms.Contains(currentTransform.GetChild(i)))
				{
					CreateSimulatedPoints(outputPoints, ignoredTransforms, currentTransform.GetChild(i), jiggleBone);
				}
			}
		}

		private void Awake()
		{
			Initialize();
		}

		private void OnEnable()
		{
			JiggleRigHandler.AddBuilder(this);
			dirtyFromEnable = true;
		}

		private void OnDisable()
		{
			JiggleRigHandler.RemoveBuilder(this);
			PrepareTeleport();
		}

		public void Initialize()
		{
			accumulation = 0.0;
			simulatedPoints = new List<JiggleBone>();
			if ((Object)(object)rootTransform == (Object)null)
			{
				return;
			}
			CreateSimulatedPoints(simulatedPoints, ignoredTransforms, rootTransform, null);
			foreach (JiggleBone simulatedPoint in simulatedPoints)
			{
				simulatedPoint.CalculateNormalizedIndex();
			}
			initialized = true;
		}

		public virtual void Advance(float deltaTime)
		{
			//IL_001b: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)levelOfDetail != (Object)null && !levelOfDetail.CheckActive(((Component)this).transform.position))
			{
				if (wasLODActive)
				{
					PrepareTeleport();
				}
				wasLODActive = false;
				return;
			}
			if (!wasLODActive)
			{
				FinishTeleport();
			}
			PrepareBone(((Component)this).transform.position, levelOfDetail);
			if (dirtyFromEnable)
			{
				FinishTeleport();
				dirtyFromEnable = false;
			}
			accumulation = Math.Min(accumulation + (double)deltaTime, maxCatchupTime);
			while (accumulation > (double)Time.fixedDeltaTime)
			{
				accumulation -= Time.fixedDeltaTime;
				double time = Time.timeAsDouble - accumulation;
				UpdateJiggle(wind, time);
			}
			Pose(debugDraw);
			wasLODActive = true;
		}

		private void OnDrawGizmos()
		{
			if (!initialized || simulatedPoints == null)
			{
				Initialize();
			}
			foreach (JiggleBone simulatedPoint in simulatedPoints)
			{
				simulatedPoint.OnDrawGizmos(jiggleSettings);
			}
		}

		private void OnValidate()
		{
			if ((Object)(object)rootTransform == (Object)null)
			{
				rootTransform = ((Component)this).transform;
			}
			if (!Application.isPlaying)
			{
				Initialize();
			}
		}
	}
	public static class JiggleRigHandler
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static UpdateFunction <0>__UpdateJiggleRigs;
		}

		private static bool initialized = false;

		private static HashSet<JiggleRigBuilder> builders = new HashSet<JiggleRigBuilder>();

		private static void Initialize()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			if (!initialized)
			{
				PlayerLoopSystem currentPlayerLoop = PlayerLoop.GetCurrentPlayerLoop();
				PlayerLoopSystem self = currentPlayerLoop;
				PlayerLoopSystem systemToInject = default(PlayerLoopSystem);
				object obj = <>O.<0>__UpdateJiggleRigs;
				if (obj == null)
				{
					UpdateFunction val = UpdateJiggleRigs;
					<>O.<0>__UpdateJiggleRigs = val;
					obj = (object)val;
				}
				systemToInject.updateDelegate = (UpdateFunction)obj;
				systemToInject.type = typeof(JiggleRigHandler);
				currentPlayerLoop = self.InjectAt<PostLateUpdate>(systemToInject);
				PlayerLoop.SetPlayerLoop(currentPlayerLoop);
				initialized = true;
			}
		}

		private static void UpdateJiggleRigs()
		{
			CachedSphereCollider.StartPass();
			foreach (JiggleRigBuilder builder in builders)
			{
				builder.Advance(Time.deltaTime);
			}
			CachedSphereCollider.FinishedPass();
		}

		public static void AddBuilder(JiggleRigBuilder builder)
		{
			builders.Add(builder);
			Initialize();
		}

		public static void RemoveBuilder(JiggleRigBuilder builder)
		{
			builders.Remove(builder);
		}

		private static PlayerLoopSystem InjectAt<T>(this PlayerLoopSystem self, PlayerLoopSystem systemToInject)
		{
			//IL_0001: 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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: 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_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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: Expected O, but got Unknown
			int num = FindIndexOfSubsystem<T>(self.subSystemList);
			if (num == -1)
			{
				throw new UnityException($"Failed to find PlayerLoopSystem with type{typeof(T)}");
			}
			List<PlayerLoopSystem> list = new List<PlayerLoopSystem>(self.subSystemList[num].subSystemList);
			foreach (PlayerLoopSystem item2 in list)
			{
				if (item2.type != typeof(JiggleRigBuilder))
				{
					continue;
				}
				Debug.LogWarning((object)$"Tried to inject a PlayerLoopSystem ({systemToInject.type}) more than once! Ignoring the second injection.");
				return self;
			}
			PlayerLoopSystem item = default(PlayerLoopSystem);
			object obj = <>O.<0>__UpdateJiggleRigs;
			if (obj == null)
			{
				UpdateFunction val = UpdateJiggleRigs;
				<>O.<0>__UpdateJiggleRigs = val;
				obj = (object)val;
			}
			item.updateDelegate = (UpdateFunction)obj;
			item.type = typeof(JiggleRigHandler);
			list.Insert(0, item);
			self.subSystemList[num].subSystemList = list.ToArray();
			return self;
		}

		private static int FindIndexOfSubsystem<T>(PlayerLoopSystem[] list, int index = -1)
		{
			if (list == null)
			{
				return -1;
			}
			for (int i = 0; i < list.Length; i++)
			{
				if (list[i].type == typeof(T))
				{
					return i;
				}
			}
			return -1;
		}
	}
	public abstract class JiggleRigLOD : ScriptableObject
	{
		public abstract bool CheckActive(Vector3 position);

		public abstract JiggleSettingsData AdjustJiggleSettingsData(Vector3 position, JiggleSettingsData data);
	}
	[CreateAssetMenu(fileName = "JiggleRigSimpleLOD", menuName = "JigglePhysics/JiggleRigSimpleLOD", order = 1)]
	public class JiggleRigSimpleLOD : JiggleRigLOD
	{
		[Tooltip("Distance to disable the jiggle rig")]
		[SerializeField]
		private float distance;

		[Tooltip("Level of detail manager. This system will control how the jiggle rig saves performance cost.")]
		[SerializeField]
		private float blend;

		[NonSerialized]
		private Camera currentCamera;

		[NonSerialized]
		private Transform cameraTransform;

		private bool TryGetCamera(out Camera camera)
		{
			if ((Object)(object)currentCamera == (Object)null || !((Component)currentCamera).CompareTag("MainCamera"))
			{
				currentCamera = Camera.main;
			}
			camera = currentCamera;
			return (Object)(object)currentCamera != (Object)null;
		}

		public override bool CheckActive(Vector3 position)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (!TryGetCamera(out var camera))
			{
				return false;
			}
			return Vector3.Distance(((Component)camera).transform.position, position) < distance;
		}

		public override JiggleSettingsData AdjustJiggleSettingsData(Vector3 position, JiggleSettingsData data)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (!TryGetCamera(out var camera))
			{
				return data;
			}
			float num = (Vector3.Distance(((Component)camera).transform.position, position) - distance + blend) / blend;
			num = Mathf.Clamp01(1f - num);
			data.blend = num;
			return data;
		}
	}
	public struct JiggleSettingsData
	{
		public float gravityMultiplier;

		public float friction;

		public float angleElasticity;

		public float blend;

		public float airDrag;

		public float lengthElasticity;

		public float elasticitySoften;

		public float radiusMultiplier;

		public static JiggleSettingsData Lerp(JiggleSettingsData a, JiggleSettingsData b, float t)
		{
			JiggleSettingsData result = default(JiggleSettingsData);
			result.gravityMultiplier = Mathf.Lerp(a.gravityMultiplier, b.gravityMultiplier, t);
			result.friction = Mathf.Lerp(a.friction, b.friction, t);
			result.angleElasticity = Mathf.Lerp(a.angleElasticity, b.angleElasticity, t);
			result.blend = Mathf.Lerp(a.blend, b.blend, t);
			result.airDrag = Mathf.Lerp(a.airDrag, b.airDrag, t);
			result.lengthElasticity = Mathf.Lerp(a.lengthElasticity, b.lengthElasticity, t);
			result.elasticitySoften = Mathf.Lerp(a.elasticitySoften, b.elasticitySoften, t);
			result.radiusMultiplier = Mathf.Lerp(a.radiusMultiplier, b.radiusMultiplier, t);
			return result;
		}
	}
	[CreateAssetMenu(fileName = "JiggleSettings", menuName = "JigglePhysics/Settings", order = 1)]
	public class JiggleSettings : JiggleSettingsBase
	{
		[SerializeField]
		[Range(0f, 2f)]
		[Tooltip("How much gravity to apply to the simulation, it is a multiplier of the Physics.gravity setting.")]
		private float gravityMultiplier = 1f;

		[SerializeField]
		[Range(0f, 1f)]
		[Tooltip("How much mechanical friction to apply, this is specifically how quickly oscillations come to rest.")]
		private float friction = 0.4f;

		[SerializeField]
		[Range(0f, 1f)]
		[Tooltip("How much angular force is applied to bring it to the target shape.")]
		private float angleElasticity = 0.4f;

		[SerializeField]
		[Range(0f, 1f)]
		[Tooltip("How much of the simulation should be expressed. A value of 0 would make the jiggle have zero effect. A value of 1 gives the full movement as intended. 0.5 would ")]
		private float blend = 1f;

		[FormerlySerializedAs("airFriction")]
		[HideInInspector]
		[SerializeField]
		[Range(0f, 1f)]
		[Tooltip("How much jiggled objects should get dragged behind by moving through the air. Or how \"thick\" the air is.")]
		private float airDrag = 0.1f;

		[HideInInspector]
		[SerializeField]
		[Range(0f, 1f)]
		[Tooltip("How rigidly the rig holds its length. Low values cause lots of squash and stretch!")]
		private float lengthElasticity = 0.8f;

		[HideInInspector]
		[SerializeField]
		[Range(0f, 1f)]
		[Tooltip("How much to allow free bone motion before engaging elasticity.")]
		private float elasticitySoften = 0f;

		[HideInInspector]
		[SerializeField]
		[Tooltip("How much radius points have, only used for collisions. Set to 0 to disable collisions")]
		private float radiusMultiplier = 0f;

		[HideInInspector]
		[SerializeField]
		[Tooltip("How the radius is expressed as a curve along the bone chain from root to child.")]
		private AnimationCurve radiusCurve = new AnimationCurve((Keyframe[])(object)new Keyframe[2]
		{
			new Keyframe(0f, 1f),
			new Keyframe(1f, 0f)
		});

		public override JiggleSettingsData GetData()
		{
			JiggleSettingsData result = default(JiggleSettingsData);
			result.gravityMultiplier = gravityMultiplier;
			result.friction = friction;
			result.airDrag = airDrag;
			result.blend = blend;
			result.angleElasticity = angleElasticity;
			result.elasticitySoften = elasticitySoften;
			result.lengthElasticity = lengthElasticity;
			result.radiusMultiplier = radiusMultiplier;
			return result;
		}

		public void SetData(JiggleSettingsData data)
		{
			gravityMultiplier = data.gravityMultiplier;
			friction = data.friction;
			angleElasticity = data.angleElasticity;
			blend = data.blend;
			airDrag = data.airDrag;
			lengthElasticity = data.lengthElasticity;
			elasticitySoften = data.elasticitySoften;
			radiusMultiplier = data.radiusMultiplier;
		}

		public override float GetRadius(float normalizedIndex)
		{
			return radiusMultiplier * radiusCurve.Evaluate(normalizedIndex);
		}

		public void SetRadiusCurve(AnimationCurve curve)
		{
			radiusCurve = curve;
		}
	}
	public class JiggleSettingsBase : ScriptableObject
	{
		public virtual JiggleSettingsData GetData()
		{
			return default(JiggleSettingsData);
		}

		public virtual float GetRadius(float normalizedIndex)
		{
			return 0f;
		}
	}
	[CreateAssetMenu(fileName = "JiggleSettingsBlend", menuName = "JigglePhysics/Blend Settings", order = 1)]
	public class JiggleSettingsBlend : JiggleSettingsBase
	{
		[Tooltip("The list of jiggle settings to blend between.")]
		public List<JiggleSettings> blendSettings;

		[Range(0f, 1f)]
		[Tooltip("A value from 0 to 1 that linearly blends between all of the blendSettings.")]
		public float normalizedBlend;

		public override JiggleSettingsData GetData()
		{
			int num = blendSettings.Count - 1;
			float num2 = Mathf.Clamp01(normalizedBlend);
			int num3 = Mathf.Clamp(Mathf.FloorToInt(num2 * (float)num), 0, num);
			int index = Mathf.Clamp(Mathf.FloorToInt(num2 * (float)num) + 1, 0, num);
			return JiggleSettingsData.Lerp(blendSettings[num3].GetData(), blendSettings[index].GetData(), Mathf.Clamp01(num2 * (float)num - (float)num3));
		}

		public override float GetRadius(float normalizedIndex)
		{
			float num = Mathf.Clamp01(normalizedBlend);
			int num2 = Mathf.FloorToInt(num * (float)blendSettings.Count);
			int num3 = Mathf.FloorToInt(num * (float)blendSettings.Count) + 1;
			return Mathf.Lerp(blendSettings[Mathf.Clamp(num2, 0, blendSettings.Count - 1)].GetRadius(normalizedIndex), blendSettings[Mathf.Clamp(num3, 0, blendSettings.Count - 1)].GetRadius(normalizedIndex), Mathf.Clamp01(num * (float)blendSettings.Count - (float)num2));
		}
	}
	public class PositionSignal
	{
		private struct Frame
		{
			public Vector3 position;

			public double time;
		}

		private Frame previousFrame;

		private Frame currentFrame;

		public PositionSignal(Vector3 startPosition, double time)
		{
			//IL_0014: 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)
			currentFrame = (previousFrame = new Frame
			{
				position = startPosition,
				time = time
			});
		}

		public void SetPosition(Vector3 position, double time)
		{
			//IL_0018: 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)
			previousFrame = currentFrame;
			currentFrame = new Frame
			{
				position = position,
				time = time
			};
		}

		public void OffsetSignal(Vector3 offset)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			previousFrame = new Frame
			{
				position = previousFrame.position + offset,
				time = previousFrame.time
			};
			currentFrame = new Frame
			{
				position = currentFrame.position + offset,
				time = previousFrame.time
			};
		}

		public void FlattenSignal(double time, Vector3 position)
		{
			//IL_000c: 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_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)
			previousFrame = new Frame
			{
				position = position,
				time = time - (double)(JiggleRigBuilder.maxCatchupTime * 2f)
			};
			currentFrame = new Frame
			{
				position = position,
				time = time - (double)JiggleRigBuilder.maxCatchupTime
			};
		}

		public Vector3 GetCurrent()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return currentFrame.position;
		}

		public Vector3 GetPrevious()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return previousFrame.position;
		}

		public Vector3 SamplePosition(double time)
		{
			//IL_0051: 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_0063: 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_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_006b: Unknown result type (might be due to invalid IL or missing references)
			double num = currentFrame.time - previousFrame.time;
			if (num == 0.0)
			{
				return previousFrame.position;
			}
			double num2 = (time - previousFrame.time) / num;
			return Vector3.Lerp(previousFrame.position, currentFrame.position, (float)num2);
		}
	}
}
namespace ModelReplacement
{
	public static class PluginInfo
	{
		public const string GUID = "meow.ModelReplacementAPI";

		public const string NAME = "ModelReplacementAPI";

		public const string VERSION = "2.3.8";

		public const string WEBSITE = "https://github.com/BunyaPineTree/LethalCompany_ModelReplacementAPI";
	}
	[BepInPlugin("meow.ModelReplacementAPI", "ModelReplacementAPI", "2.3.8")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class ModelReplacementAPI : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(PlayerControllerB))]
		public class PlayerControllerBPatch
		{
			[HarmonyPatch("Update")]
			[HarmonyPostfix]
			public static void ManageRegistryBodyReplacements(ref PlayerControllerB __instance)
			{
				try
				{
					ManageBodyReplacements(__instance);
				}
				catch (Exception arg)
				{
					Instance.Logger.LogError((object)$"Exception in ManageRegistryBodyReplacements: {arg}");
				}
			}

			private static void ManageBodyReplacements(PlayerControllerB player)
			{
				BodyReplacementBase component = ((Component)player.thisPlayerBody).gameObject.GetComponent<BodyReplacementBase>();
				if ((Object)(object)component != (Object)null && RegisteredModelReplacementExceptions.Contains(((object)component).GetType()))
				{
					return;
				}
				if (RegisteredModelReplacementOverride != null)
				{
					SetPlayerModelReplacement(player, RegisteredModelReplacementOverride);
					return;
				}
				int num = player.currentSuitID;
				List<UnlockableItem> unlockables = StartOfRound.Instance.unlockablesList.unlockables;
				if (num > unlockables.Count)
				{
					throw new Exception($"Suit ID {num} is out of range of the suit list, which has {unlockables.Count} elements.");
				}
				if (num >= unlockables.Count)
				{
					num = 0;
				}
				string key = unlockables[num].unlockableName.ToLower().Replace(" ", "");
				if (RegisteredModelReplacements.ContainsKey(key))
				{
					SetPlayerModelReplacement(player, RegisteredModelReplacements[key]);
				}
				else if (RegisteredModelReplacementDefault != null)
				{
					SetPlayerModelReplacement(player, RegisteredModelReplacementDefault);
				}
				else
				{
					RemovePlayerModelReplacement(player);
				}
			}
		}

		public static bool moreCompanyPresent;

		public static bool thirdPersonPresent;

		public static bool LCthirdPersonPresent;

		public static bool mirrorDecorPresent;

		public static bool tooManyEmotesPresent;

		public static bool recordingCameraPresent;

		public static ModelReplacementAPI Instance = null;

		public ManualLogSource Logger = new ManualLogSource("ModelReplacementAPI");

		private static List<Type> RegisteredModelReplacementExceptions = new List<Type>();

		private static Dictionary<string, Type> RegisteredModelReplacements = new Dictionary<string, Type>();

		private static Type RegisteredModelReplacementOverride = null;

		private static Type RegisteredModelReplacementDefault = null;

		private static HashSet<ulong> blackListedSteamIDs = new HashSet<ulong>();

		private static int steamLobbyID
		{
			get
			{
				//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_002c: Unknown result type (might be due to invalid IL or missing references)
				int result;
				if (!GameNetworkManager.Instance.currentLobby.HasValue)
				{
					result = -1;
				}
				else
				{
					Lobby value = GameNetworkManager.Instance.currentLobby.Value;
					result = (int)((Lobby)(ref value)).Id.Value;
				}
				return result;
			}
		}

		public static bool IsLan => steamLobbyID == -1;

		private void Awake()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			Instance = this;
			moreCompanyPresent = IsPluginPresent("me.swipez.melonloader.morecompany");
			thirdPersonPresent = IsPluginPresent("verity.3rdperson");
			LCthirdPersonPresent = IsPluginPresent("LCThirdPerson");
			mirrorDecorPresent = IsPluginPresent("quackandcheese.mirrordecor");
			tooManyEmotesPresent = IsPluginPresent("FlipMods.TooManyEmotes");
			recordingCameraPresent = IsPluginPresent("com.graze.gorillatag.placeablecamera");
			Harmony val = new Harmony("meow.ModelReplacementAPI");
			val.PatchAll();
			Logger.LogInfo((object)"Plugin meow.ModelReplacementAPI is loaded!");
		}

		private static bool IsPluginPresent(string pluginName)
		{
			return Chainloader.PluginInfos.ContainsKey(pluginName);
		}

		public static void RegisterModelReplacementDefault(Type type)
		{
			RegisterModelReplacement(type, ref RegisteredModelReplacementDefault, "default");
		}

		public static void RegisterModelReplacementOverride(Type type)
		{
			RegisterModelReplacement(type, ref RegisteredModelReplacementOverride, "override");
		}

		public static void RegisterModelReplacementException(Type type)
		{
			RegisterModelReplacement(type, RegisteredModelReplacementExceptions, "exception");
		}

		public static void RegisterSuitModelReplacement(string suitNameToReplace, Type type)
		{
			suitNameToReplace = suitNameToReplace.ToLower().Replace(" ", "");
			if (!type.IsSubclassOf(typeof(BodyReplacementBase)))
			{
				Instance.Logger.LogError((object)$"Cannot register body replacement type {type}, must inherit from BodyReplacementBase");
				return;
			}
			if (RegisteredModelReplacements.ContainsKey(suitNameToReplace))
			{
				Instance.Logger.LogError((object)$"Cannot register body replacement type {type}, suit name to replace {suitNameToReplace} is already registered.");
				return;
			}
			Instance.Logger.LogDebug((object)$"Registering body replacement type {type} to suit name {suitNameToReplace}.");
			RegisteredModelReplacements.Add(suitNameToReplace, type);
		}

		private static void RegisterModelReplacement(Type type, ref Type registeredType, string logType)
		{
			if (!type.IsSubclassOf(typeof(BodyReplacementBase)))
			{
				Instance.Logger.LogError((object)$"Cannot register body replacement {logType} type {type}, must inherit from BodyReplacementBase");
				return;
			}
			if (registeredType != null)
			{
				Instance.Logger.LogError((object)$"Cannot register body replacement {logType}, already registered to {registeredType}.");
				return;
			}
			Instance.Logger.LogDebug((object)$"Registering body replacement {logType} type {type}.");
			registeredType = type;
		}

		private static void RegisterModelReplacement(Type type, List<Type> registeredList, string logType)
		{
			if (!type.IsSubclassOf(typeof(BodyReplacementBase)))
			{
				Instance.Logger.LogError((object)$"Cannot register body replacement {logType} type {type}, must inherit from BodyReplacementBase");
				return;
			}
			Instance.Logger.LogInfo((object)$"Registering body replacement {logType} type {type}.");
			if (!registeredList.Contains(type))
			{
				registeredList.Add(type);
			}
		}

		public static void RegisterPlayerBlackList(ulong steamID, bool blackListed)
		{
			if (blackListed)
			{
				blackListedSteamIDs.Add(steamID);
			}
			else if (blackListedSteamIDs.Contains(steamID))
			{
				blackListedSteamIDs.Remove(steamID);
			}
		}

		public static void RegisterPlayerBlackList(PlayerControllerB player, bool blackListed)
		{
			RegisterPlayerBlackList(player.playerSteamId, blackListed);
			RemovePlayerModelReplacement(player);
		}

		public static void ResetPlayerModelReplacement(PlayerControllerB player)
		{
			BodyReplacementBase component = ((Component)player).gameObject.GetComponent<BodyReplacementBase>();
			if (!((Object)(object)component == (Object)null))
			{
				Instance.Logger.LogInfo((object)("Reinstantiating model replacement for " + player.playerUsername));
				Type type = ((object)component).GetType();
				component.IsActive = false;
				Object.Destroy((Object)(object)component);
				((Component)player).gameObject.AddComponent(type);
			}
		}

		public static void SetPlayerModelReplacement(PlayerControllerB player, Type type)
		{
			if (!type.IsSubclassOf(typeof(BodyReplacementBase)))
			{
				Instance.Logger.LogError((object)("Cannot set body replacement of type " + type.Name + ", must inherit from BodyReplacementBase"));
			}
			else
			{
				if ((!IsLan && player.playerSteamId == 0) || blackListedSteamIDs.Contains(player.playerSteamId))
				{
					return;
				}
				BodyReplacementBase bodyReplacementBase = default(BodyReplacementBase);
				bool flag = ((Component)player).gameObject.TryGetComponent<BodyReplacementBase>(ref bodyReplacementBase);
				int currentSuitID = player.currentSuitID;
				string unlockableName = StartOfRound.Instance.unlockablesList.unlockables[currentSuitID].unlockableName;
				if (flag)
				{
					if (((object)bodyReplacementBase).GetType() == type && bodyReplacementBase.suitName == unlockableName)
					{
						return;
					}
					Instance.Logger.LogInfo((object)$"Model Replacement Change detected {((object)bodyReplacementBase).GetType()} => {type}, changing model.");
					bodyReplacementBase.IsActive = false;
					Object.Destroy((Object)(object)bodyReplacementBase);
				}
				Instance.Logger.LogInfo((object)$"Suit Change detected {bodyReplacementBase?.suitName} => {unlockableName}, Replacing {type}.");
				BodyReplacementBase bodyReplacementBase2 = ((Component)player).gameObject.AddComponent(type) as BodyReplacementBase;
				bodyReplacementBase2.suitName = unlockableName;
			}
		}

		public static bool GetPlayerModelReplacement(PlayerControllerB player, out BodyReplacementBase modelReplacement)
		{
			try
			{
				modelReplacement = ((Component)player).gameObject.GetComponent<BodyReplacementBase>();
				return (Object)(object)modelReplacement == (Object)null;
			}
			catch (Exception arg)
			{
				Instance.Logger.LogError((object)$"Error in GetPlayerModelReplacement, returning false {arg}");
				modelReplacement = null;
				return false;
			}
		}

		public static bool GetPlayerModelReplacement(PlayerControllerB player)
		{
			try
			{
				return (Object)(object)((Component)player).gameObject.GetComponent<BodyReplacementBase>() == (Object)null;
			}
			catch (Exception arg)
			{
				Instance.Logger.LogError((object)$"Error in GetPlayerModelReplacement, returning false {arg}");
				return false;
			}
		}

		public static void RemovePlayerModelReplacement(PlayerControllerB player)
		{
			BodyReplacementBase component = ((Component)player).gameObject.GetComponent<BodyReplacementBase>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.IsActive = false;
				Object.Destroy((Object)(object)component);
			}
		}
	}
	public abstract class BodyReplacementBase : MonoBehaviour
	{
		public class RaycastTarget : MonoBehaviour
		{
			public PlayerControllerB controller = null;

			public BodyReplacementBase bodyReplacement = null;

			public GameObject modelObj = null;

			private void Update()
			{
				if ((Object)(object)bodyReplacement == (Object)null && !((Object)(object)modelObj != (Object)null))
				{
				}
			}
		}

		public ViewStateManager viewState = null;

		public MoreCompanyCosmeticManager cosmeticManager = null;

		public MaterialHelper materialHelper = null;

		public GameObject replacementModel;

		public GameObject replacementViewModel;

		public BoxCollider nameTagCollider = null;

		protected GameObject deadBody = null;

		protected GameObject replacementDeadBody = null;

		private int danceNumber = 0;

		private int previousDanceNumber = 0;

		public AvatarUpdater cosmeticAvatar = null;

		public bool IsActive = true;

		public bool UseNoPostProcessing = false;

		public bool DontConvertUnsupportedShaders = false;

		public bool DebugRenderPlayer = false;

		public bool DebugRenderModel = false;

		private bool emoteOngoing = false;

		public AvatarUpdater avatar { get; private set; }

		public PlayerControllerB controller { get; private set; }

		public AvatarUpdater ragdollAvatar { get; private set; }

		public string suitName { get; set; } = "";


		protected abstract GameObject LoadAssetsAndReturnModel();

		protected virtual GameObject LoadAssetsAndReturnViewModel()
		{
			return null;
		}

		protected virtual AvatarUpdater GetAvatarUpdater()
		{
			return new AvatarUpdater();
		}

		protected virtual void AddModelScripts()
		{
		}

		protected internal virtual void OnHitEnemy(bool dead)
		{
			Console.WriteLine("PLAYER HIT ENEMY " + controller.playerUsername);
		}

		protected internal virtual void OnHitAlly(PlayerControllerB ally, bool dead)
		{
			Console.WriteLine("PLAYER HIT ALLY " + controller.playerUsername);
		}

		protected internal virtual void OnDamageTaken(bool dead)
		{
			Console.WriteLine("PLAYER TAKE DAMAGE  " + controller.playerUsername);
		}

		protected internal virtual void OnDamageTakenByAlly(PlayerControllerB ally, bool dead)
		{
			Console.WriteLine("PLAYER TAKE DAMAGE BY ALLY " + controller.playerUsername);
		}

		protected internal virtual void OnDeath()
		{
			Console.WriteLine("PLAYER DEATH " + controller.playerUsername + " ");
		}

		protected internal virtual void OnEmoteStart(int emoteId)
		{
			Console.WriteLine($"PLAYER EMOTE START {controller.playerUsername} ID {emoteId}");
		}

		protected internal virtual void OnEmoteEnd()
		{
			Console.WriteLine("PLAYER EMOTE END " + controller.playerUsername);
		}

		protected virtual void Awake()
		{
			//IL_03a4: 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_0452: Unknown result type (might be due to invalid IL or missing references)
			//IL_046b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0472: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Expected O, but got Unknown
			//IL_0523: Unknown result type (might be due to invalid IL or missing references)
			//IL_052a: Expected O, but got Unknown
			controller = ((Component)this).GetComponent<PlayerControllerB>();
			viewState = ((Component)this).GetComponent<ViewStateManager>();
			ModelReplacementAPI.Instance.Logger.LogInfo((object)("Awake " + controller.playerUsername));
			replacementModel = LoadAssetsAndReturnModel();
			if ((Object)(object)replacementModel == (Object)null)
			{
				ModelReplacementAPI.Instance.Logger.LogFatal((object)"LoadAssetsAndReturnModel() returned null. Verify that your assetbundle works and your asset name is correct. ");
			}
			replacementViewModel = (viewState.localPlayer ? LoadAssetsAndReturnViewModel() : null);
			if ((Object)(object)replacementViewModel != (Object)null)
			{
				ModelReplacementAPI.Instance.Logger.LogFatal((object)("Loading custom viewmodel on " + Object.GetName((Object)(object)this)));
			}
			Material sharedMaterial = ((Renderer)((Component)controller.thisPlayerModel).GetComponent<SkinnedMeshRenderer>()).sharedMaterial;
			sharedMaterial = new Material(sharedMaterial);
			materialHelper = new MaterialHelper(this);
			Renderer[] componentsInChildren = replacementModel.GetComponentsInChildren<Renderer>();
			SkinnedMeshRenderer[] componentsInChildren2 = replacementModel.GetComponentsInChildren<SkinnedMeshRenderer>();
			Dictionary<Material, Material> dictionary = new Dictionary<Material, Material>();
			List<Material> list = CollectionPool<List<Material>, Material>.Get();
			Renderer[] array = componentsInChildren;
			foreach (Renderer val in array)
			{
				val.GetSharedMaterials(list);
				for (int j = 0; j < list.Count; j++)
				{
					Material val2 = list[j];
					if (!dictionary.TryGetValue(val2, out var value))
					{
						value = (dictionary[val2] = materialHelper.GetReplacementMaterial(sharedMaterial, val2));
					}
					list[j] = value;
				}
				val.SetMaterials(list);
			}
			CollectionPool<List<Material>, Material>.Release(list);
			SkinnedMeshRenderer[] array2 = componentsInChildren2;
			foreach (SkinnedMeshRenderer val3 in array2)
			{
				val3.updateWhenOffscreen = true;
			}
			if ((Object)(object)replacementViewModel != (Object)null)
			{
				Renderer[] componentsInChildren3 = replacementViewModel.GetComponentsInChildren<Renderer>();
				SkinnedMeshRenderer[] componentsInChildren4 = replacementViewModel.GetComponentsInChildren<SkinnedMeshRenderer>();
				Dictionary<Material, Material> dictionary2 = new Dictionary<Material, Material>();
				List<Material> list2 = CollectionPool<List<Material>, Material>.Get();
				Renderer[] array3 = componentsInChildren3;
				foreach (Renderer val4 in array3)
				{
					val4.GetSharedMaterials(list2);
					for (int m = 0; m < list2.Count; m++)
					{
						Material val5 = list2[m];
						if (!dictionary2.TryGetValue(val5, out var value2))
						{
							value2 = (dictionary2[val5] = materialHelper.GetReplacementMaterial(sharedMaterial, val5));
						}
						list2[m] = value2;
					}
					val4.SetMaterials(list2);
				}
				CollectionPool<List<Material>, Material>.Release(list2);
				SkinnedMeshRenderer[] array4 = componentsInChildren4;
				foreach (SkinnedMeshRenderer val6 in array4)
				{
					val6.updateWhenOffscreen = true;
				}
			}
			Animator componentInChildren = replacementModel.GetComponentInChildren<Animator>();
			OffsetBuilder component = ((Component)componentInChildren).gameObject.GetComponent<OffsetBuilder>();
			UseNoPostProcessing = component.UseNoPostProcessing;
			try
			{
				AddModelScripts();
			}
			catch (Exception ex)
			{
				ModelReplacementAPI.Instance.Logger.LogError((object)("Could not set all model scripts.\n Error: " + ex.Message));
			}
			replacementModel = Object.Instantiate<GameObject>(replacementModel);
			GameObject obj = replacementModel;
			((Object)obj).name = ((Object)obj).name + "(" + controller.playerUsername + ")";
			replacementModel.transform.localPosition = new Vector3(0f, 0f, 0f);
			replacementModel.SetActive(true);
			if ((Object)(object)replacementViewModel != (Object)null)
			{
				replacementViewModel = Object.Instantiate<GameObject>(replacementViewModel);
				GameObject obj2 = replacementViewModel;
				((Object)obj2).name = ((Object)obj2).name + "(" + controller.playerUsername + ")";
				replacementViewModel.transform.localPosition = new Vector3(0f, 0f, 0f);
				replacementViewModel.SetActive(true);
			}
			float num = 1.465f;
			Bounds bounds = GetBounds();
			float num2 = num / ((Bounds)(ref bounds)).extents.y;
			Transform transform = replacementModel.transform;
			transform.localScale *= num2;
			avatar = GetAvatarUpdater();
			cosmeticAvatar = avatar;
			ragdollAvatar = new AvatarUpdater();
			avatar.AssignModelReplacement(((Component)controller).gameObject, replacementModel);
			if ((Object)(object)replacementViewModel != (Object)null)
			{
				avatar.AssignViewModelReplacement(((Component)controller).gameObject, replacementViewModel);
			}
			if (ModelReplacementAPI.moreCompanyPresent)
			{
				cosmeticManager = new MoreCompanyCosmeticManager(this);
			}
			SetAvatarRenderers(enabled: true);
			viewState.ReportBodyReplacementAddition(this);
			GameObject val7 = new GameObject("MRAPINameCollider");
			val7.layer = 23;
			val7.transform.SetParent(replacementModel.transform);
			nameTagCollider = val7.AddComponent<BoxCollider>();
			((Collider)nameTagCollider).isTrigger = true;
			RaycastTarget raycastTarget = val7.AddComponent<RaycastTarget>();
			raycastTarget.controller = controller;
			raycastTarget.bodyReplacement = this;
			raycastTarget.modelObj = replacementModel;
			ModelReplacementAPI.Instance.Logger.LogInfo((object)("AwakeEnd " + controller.playerUsername));
		}

		protected virtual void Start()
		{
		}

		protected virtual void LateUpdate()
		{
			//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_0107: 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_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = null;
			try
			{
				val = ((Component)controller.deadBody).gameObject;
			}
			catch
			{
			}
			if (Object.op_Implicit((Object)(object)val) && (Object)(object)replacementDeadBody == (Object)null)
			{
				cosmeticAvatar = ragdollAvatar;
				CreateAndParentRagdoll(controller.deadBody);
				OnDeath();
			}
			if (Object.op_Implicit((Object)(object)replacementDeadBody) && (Object)(object)val == (Object)null)
			{
				cosmeticAvatar = avatar;
				Object.Destroy((Object)(object)replacementDeadBody);
				replacementDeadBody = null;
			}
			if (Object.op_Implicit((Object)(object)val) && !val.activeInHierarchy)
			{
				replacementDeadBody.SetActive(false);
			}
			avatar.Update();
			ragdollAvatar.Update();
			if (ModelReplacementAPI.moreCompanyPresent)
			{
				cosmeticManager.Update(useAvatarTransforms: true);
			}
			Bounds bounds = GetBounds();
			nameTagCollider.center = ((Bounds)(ref bounds)).center;
			nameTagCollider.size = ((Bounds)(ref bounds)).size;
			previousDanceNumber = danceNumber;
			AnimatorStateInfo currentAnimatorStateInfo = controller.playerBodyAnimator.GetCurrentAnimatorStateInfo(1);
			int fullPathHash = ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).fullPathHash;
			if (controller.performingEmote)
			{
				switch (fullPathHash)
				{
				case -462656950:
					danceNumber = 1;
					break;
				case 2103786480:
					danceNumber = 2;
					break;
				default:
					danceNumber = 3;
					break;
				}
			}
			else
			{
				danceNumber = 0;
			}
			if (ModelReplacementAPI.tooManyEmotesPresent)
			{
				danceNumber = SafeGetEmoteID(danceNumber);
			}
			if (danceNumber != previousDanceNumber)
			{
				if (previousDanceNumber == 0)
				{
					((MonoBehaviour)this).StartCoroutine(WaitForDanceNumberChange());
				}
				else if (danceNumber == 0)
				{
					OnEmoteEnd();
				}
				else if (!emoteOngoing)
				{
					OnEmoteStart(danceNumber);
				}
			}
		}

		protected virtual void OnDestroy()
		{
			ModelReplacementAPI.Instance.Logger.LogInfo((object)("Destroy body component for " + controller.playerUsername));
			Object.Destroy((Object)(object)replacementModel);
			Object.Destroy((Object)(object)replacementViewModel);
			Object.Destroy((Object)(object)replacementDeadBody);
			if (ModelReplacementAPI.moreCompanyPresent)
			{
				cosmeticManager.Update(useAvatarTransforms: false);
			}
		}

		private void CreateAndParentRagdoll(DeadBodyInfo bodyinfo)
		{
			deadBody = ((Component)bodyinfo).gameObject;
			SkinnedMeshRenderer componentInChildren = deadBody.GetComponentInChildren<SkinnedMeshRenderer>();
			replacementDeadBody = Object.Instantiate<GameObject>(replacementModel);
			GameObject obj = replacementDeadBody;
			((Object)obj).name = ((Object)obj).name + "(Ragdoll)";
			ragdollAvatar.AssignModelReplacement(deadBody, replacementDeadBody);
			Renderer[] componentsInChildren = replacementDeadBody.GetComponentsInChildren<Renderer>();
			foreach (Renderer val in componentsInChildren)
			{
				val.enabled = true;
				val.shadowCastingMode = (ShadowCastingMode)1;
				((Component)val).gameObject.layer = viewState.VisibleLayer;
			}
			((Renderer)componentInChildren).enabled = false;
			GameObject[] bodyBloodDecals = bodyinfo.bodyBloodDecals;
			foreach (GameObject val2 in bodyBloodDecals)
			{
				Transform parent = val2.transform.parent;
				Transform avatarTransformFromBoneName = ragdollAvatar.GetAvatarTransformFromBoneName(((Object)parent).name);
				if (Object.op_Implicit((Object)(object)avatarTransformFromBoneName))
				{
					Object.Instantiate<GameObject>(val2, avatarTransformFromBoneName);
				}
			}
		}

		public void SetAvatarRenderers(bool enabled)
		{
			Renderer[] componentsInChildren = replacementModel.GetComponentsInChildren<Renderer>();
			foreach (Renderer val in componentsInChildren)
			{
				val.enabled = enabled;
			}
			if ((Object)(object)replacementViewModel != (Object)null)
			{
				Renderer[] componentsInChildren2 = replacementViewModel.GetComponentsInChildren<Renderer>();
				foreach (Renderer val2 in componentsInChildren2)
				{
					val2.enabled = enabled;
				}
			}
		}

		private Bounds GetBounds()
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: 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_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: 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_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: 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)
			Bounds result = default(Bounds);
			IEnumerable<Bounds> source = from r in replacementModel.GetComponentsInChildren<SkinnedMeshRenderer>()
				select ((Renderer)r).bounds;
			Bounds val = source.OrderByDescending((Bounds x) => ((Bounds)(ref x)).max.x).First();
			float x2 = ((Bounds)(ref val)).max.x;
			val = source.OrderByDescending((Bounds x) => ((Bounds)(ref x)).max.y).First();
			float y = ((Bounds)(ref val)).max.y;
			val = source.OrderByDescending((Bounds x) => ((Bounds)(ref x)).max.z).First();
			float z = ((Bounds)(ref val)).max.z;
			val = source.OrderBy((Bounds x) => ((Bounds)(ref x)).min.x).First();
			float x3 = ((Bounds)(ref val)).min.x;
			val = source.OrderBy((Bounds x) => ((Bounds)(ref x)).min.y).First();
			float y2 = ((Bounds)(ref val)).min.y;
			val = source.OrderBy((Bounds x) => ((Bounds)(ref x)).min.z).First();
			float z2 = ((Bounds)(ref val)).min.z;
			((Bounds)(ref result)).SetMinMax(new Vector3(x3, y2, z2), new Vector3(x2, y, z));
			return result;
		}

		private IEnumerator WaitForDanceNumberChange()
		{
			if (emoteOngoing)
			{
				yield break;
			}
			emoteOngoing = true;
			for (int frame = 0; frame < 20; frame++)
			{
				if (danceNumber == 0)
				{
					emoteOngoing = false;
					yield break;
				}
				yield return (object)new WaitForEndOfFrame();
			}
			if (danceNumber != 0)
			{
				emoteOngoing = false;
				OnEmoteStart(danceNumber);
			}
		}

		private int SafeGetEmoteID(int currentID)
		{
			return DangerousGetEmoteID(currentID);
		}

		private int DangerousGetEmoteID(int currentID)
		{
			UnlockableEmote currentlyPlayingEmote = PlayerPatcher.GetCurrentlyPlayingEmote(controller);
			if (currentlyPlayingEmote == null)
			{
				return currentID;
			}
			if (currentlyPlayingEmote.emoteId == 1)
			{
				return -1;
			}
			if (currentlyPlayingEmote.emoteId == 2)
			{
				return -2;
			}
			if (currentlyPlayingEmote.emoteId == 3)
			{
				return -3;
			}
			return currentlyPlayingEmote.emoteId;
		}
	}
	public enum ViewState
	{
		None,
		ThirdPerson,
		FirstPerson,
		Debug
	}
	public class ViewStateManager : MonoBehaviour
	{
		private static int CullingMaskThirdPerson = 700127231;

		public static int CullingMaskFirstPerson = 1765349375;

		private static int CullingNoPostExcluded = 2013134847;

		public static int modelLayer = 23;

		public static int armsLayer = 30;

		public static int visibleLayer = 0;

		public static int NoPostModelLayer = 17;

		public static int NoPostVisibleLayer = 27;

		private static int invisibleLayer = 31;

		private bool bodyReplacementExists = false;

		private BodyReplacementBase bodyReplacement;

		private PlayerControllerB controller;

		private GameObject replacementModel;

		private GameObject replacementViewModel;

		private MeshRenderer nameTagObj = null;

		private MeshRenderer nameTagObj2 = null;

		private bool UseNoPostProcessing => bodyReplacementExists && bodyReplacement.UseNoPostProcessing;

		private bool DebugRenderPlayer => bodyReplacementExists && bodyReplacement.DebugRenderPlayer;

		private bool DebugRenderModel => bodyReplacementExists && bodyReplacement.DebugRenderModel;

		public bool localPlayer => (Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)(object)controller;

		public int ModelLayer => UseNoPostProcessing ? NoPostModelLayer : modelLayer;

		public int ArmsLayer => armsLayer;

		public int VisibleLayer => UseNoPostProcessing ? NoPostVisibleLayer : visibleLayer;

		public int InvisibleLayer => invisibleLayer;

		public void Awake()
		{
			controller = ((Component)this).GetComponent<PlayerControllerB>();
			MeshRenderer[] componentsInChildren = ((Component)controller).gameObject.GetComponentsInChildren<MeshRenderer>();
			nameTagObj = componentsInChildren.Where((MeshRenderer x) => ((Object)((Component)x).gameObject).name == "LevelSticker").First();
			nameTagObj2 = componentsInChildren.Where((MeshRenderer x) => ((Object)((Component)x).gameObject).name == "BetaBadge").First();
		}

		public void Start()
		{
			RendererPatches();
		}

		public void Update()
		{
			if (bodyReplacementExists && (Object)(object)bodyReplacement == (Object)null)
			{
				ReportBodyReplacementRemoval();
			}
			if (bodyReplacementExists)
			{
				UpdateModelReplacement();
			}
			else
			{
				UpdatePlayer();
			}
		}

		public void ReportBodyReplacementAddition(BodyReplacementBase replacement)
		{
			bodyReplacement = replacement;
			replacementModel = replacement.replacementModel;
			replacementViewModel = replacement.replacementViewModel;
			bodyReplacementExists = true;
			PatchViewState();
		}

		public void ReportBodyReplacementRemoval()
		{
			bodyReplacement = null;
			replacementModel = null;
			replacementViewModel = null;
			bodyReplacementExists = false;
		}

		public static void PatchViewState()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			CustomPass val = GameObject.Find("Systems/Rendering/CustomPass").GetComponent<CustomPassVolume>().customPasses.First();
			((DrawRenderersCustomPass)((val is DrawRenderersCustomPass) ? val : null)).layerMask = LayerMask.op_Implicit(CullingNoPostExcluded);
			Camera[] array = Object.FindObjectsOfType<Camera>();
			int num = 1 << modelLayer;
			int num2 = 1 << visibleLayer;
			int num3 = 1 << NoPostModelLayer;
			int num4 = 1 << NoPostVisibleLayer;
			int num5 = 8;
			Camera[] array2 = array;
			foreach (Camera val2 in array2)
			{
				int cullingMask = val2.cullingMask;
				if ((cullingMask & num) != 0 && (cullingMask & num3) == 0)
				{
					val2.cullingMask += num3;
				}
				if ((cullingMask & num2) != 0 && (cullingMask & num4) == 0)
				{
					val2.cullingMask += num4;
				}
			}
			Camera component = GameObject.Find("Environment/HangarShip/Cameras/FrontDoorSecurityCam/SecurityCamera").GetComponent<Camera>();
			if ((component.cullingMask & (1 << modelLayer)) == 0)
			{
				component.cullingMask += 1 << modelLayer;
			}
			Camera component2 = GameObject.Find("Environment/HangarShip/Cameras/ShipCamera").GetComponent<Camera>();
			if ((component2.cullingMask & (1 << modelLayer)) == 0)
			{
				component2.cullingMask += 1 << modelLayer;
			}
			Console.WriteLine(GameObject.Find("Environment/HangarShip/Cameras/ShipCamera").GetComponent<Camera>().cullingMask);
		}

		public void UpdatePlayer()
		{
			ViewState viewState = GetViewState();
			SetPlayerRenderers(enabled: true);
			controller.gameplayCamera.cullingMask = CullingMaskFirstPerson;
			switch (viewState)
			{
			case ViewState.None:
				SetArmLayers(InvisibleLayer);
				SetPlayerLayers(invisibleLayer);
				break;
			case ViewState.FirstPerson:
				SetArmLayers(ArmsLayer);
				SetPlayerLayers(modelLayer);
				break;
			case ViewState.ThirdPerson:
				SetArmLayers(InvisibleLayer);
				SetPlayerLayers(visibleLayer);
				if (ModelReplacementAPI.LCthirdPersonPresent)
				{
					controller.gameplayCamera.cullingMask = CullingMaskThirdPerson;
				}
				break;
			}
		}

		public void UpdateModelReplacement()
		{
			ViewState viewState = GetViewState();
			SetPlayerRenderers(enabled: false);
			SetPlayerLayers(modelLayer);
			controller.gameplayCamera.cullingMask = CullingMaskFirstPerson;
			switch (viewState)
			{
			case ViewState.None:
				SetArmLayers(InvisibleLayer);
				SetAvatarLayers(InvisibleLayer, (ShadowCastingMode)0);
				break;
			case ViewState.FirstPerson:
				SetArmLayers(ArmsLayer);
				SetAvatarLayers(ModelLayer, (ShadowCastingMode)1);
				break;
			case ViewState.ThirdPerson:
				SetArmLayers(InvisibleLayer);
				SetAvatarLayers(VisibleLayer, (ShadowCastingMode)1);
				if (ModelReplacementAPI.LCthirdPersonPresent)
				{
					controller.gameplayCamera.cullingMask = CullingMaskThirdPerson;
				}
				break;
			case ViewState.Debug:
				if (DebugRenderModel)
				{
					SetAvatarLayers(VisibleLayer, (ShadowCastingMode)1);
				}
				else
				{
					SetAvatarLayers(InvisibleLayer, (ShadowCastingMode)0);
				}
				if (DebugRenderPlayer)
				{