Decompiled source of BrockSkin v0.3.1

BrockSkin.dll

Decompiled 3 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using Microsoft.CodeAnalysis;
using ModMenu;
using ModelReplacement;
using ModelReplacement.AvatarBodyUpdater;
using SkinShared;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BrockSkin")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.3.1.0")]
[assembly: AssemblyInformationalVersion("0.3.1+7338f80c8a7274b1f103fdeee1603b653c323966")]
[assembly: AssemblyProduct("BrockSkin")]
[assembly: AssemblyTitle("BrockSkin")]
[assembly: AssemblyVersion("0.3.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SkinShared
{
	internal static class SuitTexture
	{
		internal static void Ensure(string dllPath, string suitName, string resource, ManualLogSource log)
		{
			string text = suitName + ".png";
			string text2 = Path.Combine(Path.GetDirectoryName(dllPath) ?? Paths.PluginPath, "moresuits");
			try
			{
				if (File.Exists(Path.Combine(text2, text)))
				{
					log.LogInfo((object)("Suit texture found: " + Path.Combine(text2, text)));
					return;
				}
				try
				{
					string[] directories = Directory.GetDirectories(Paths.PluginPath, "moresuits", SearchOption.AllDirectories);
					foreach (string path in directories)
					{
						if (File.Exists(Path.Combine(path, text)))
						{
							log.LogInfo((object)("Suit texture found: " + Path.Combine(path, text)));
							return;
						}
					}
				}
				catch (Exception ex)
				{
					log.LogWarning((object)("Could not scan plugins for moresuits folders (" + ex.Message + "); writing our own copy"));
				}
				using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource))
				{
					if (stream == null)
					{
						log.LogError((object)("Embedded suit texture " + resource + " is missing; the suit will not be on the rack"));
						return;
					}
					Directory.CreateDirectory(text2);
					string text3 = Path.Combine(text2, text + ".tmp");
					using (FileStream destination = File.Create(text3))
					{
						stream.CopyTo(destination);
					}
					File.Move(text3, Path.Combine(text2, text));
				}
				log.LogWarning((object)("No moresuits folder had \"" + text + "\" (the mod manager flattened it?); wrote it to " + text2 + " so More Suits puts the suit on the rack"));
			}
			catch (Exception ex2)
			{
				log.LogError((object)("Could not write the suit texture to " + text2 + ": " + ex2.Message + "; the suit will not be on the rack"));
			}
		}
	}
	internal static class SkinMenu
	{
		internal const string ModMenuGuid = "daniel.lethalcompany.modmenu";

		private const string Tab = "Skins";

		internal static bool MenuInstalled => Chainloader.PluginInfos.ContainsKey("daniel.lethalcompany.modmenu");

		private static PlayerControllerB Me
		{
			get
			{
				if (!((Object)(object)StartOfRound.Instance != (Object)null))
				{
					return null;
				}
				return StartOfRound.Instance.localPlayerController;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static void Register(string suitName, string who, ConfigEntry<bool> followEmotes = null)
		{
			MenuApi.Button("Skins", "Wear " + who, (Func<string>)(() => Wear(suitName, who)), false, false, (Func<string>)(() => Blocked(suitName)), "puts on the \"" + suitName + "\" suit from the rack; everyone sees it");
			if (followEmotes != null)
			{
				MenuApi.Toggle("Skins", who + " follows emotes", (Func<bool>)(() => followEmotes.Value), (Func<bool, string>)delegate(bool on)
				{
					followEmotes.Value = on;
					return (!on) ? (who + " stays upright during emotes") : (who + " turns and lies down with TooManyEmotes emotes");
				}, false, false, (Func<string>)null, "FollowEmotes, saved in the config; only on your game");
			}
		}

		private static string Key(string s)
		{
			return (s ?? "").Replace(" ", "").ToLowerInvariant();
		}

		private static UnlockableSuit Rack(string suitName)
		{
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.unlockablesList == (Object)null)
			{
				return null;
			}
			List<UnlockableItem> list = instance.unlockablesList.unlockables;
			string want = Key(suitName);
			return ((IEnumerable<UnlockableSuit>)Object.FindObjectsOfType<UnlockableSuit>()).FirstOrDefault((Func<UnlockableSuit, bool>)((UnlockableSuit s) => (Object)(object)s != (Object)null && s.suitID >= 0 && s.suitID < list.Count && Key(list[s.suitID].unlockableName) == want));
		}

		private static string Blocked(string suitName)
		{
			PlayerControllerB me = Me;
			if ((Object)(object)me == (Object)null)
			{
				return "not in a game";
			}
			if (me.isPlayerDead)
			{
				return "you're dead";
			}
			UnlockableSuit val = Rack(suitName);
			if ((Object)(object)val == (Object)null)
			{
				return "suit not on the rack (needs More Suits)";
			}
			if (me.currentSuitID != val.suitID)
			{
				return null;
			}
			return "wearing it";
		}

		private static string Wear(string suitName, string who)
		{
			UnlockableSuit val = Rack(suitName);
			if ((Object)(object)val == (Object)null || (Object)(object)Me == (Object)null)
			{
				return null;
			}
			val.SwitchSuitToThis(Me);
			return "put on the " + who + " suit";
		}
	}
}
namespace BrockSkin
{
	internal sealed class EmotePose
	{
		internal static ManualLogSource Log;

		internal static string Who = "Brock";

		private static bool resolved;

		private static Type controllerType;

		private static FieldInfo fPerforming;

		private static FieldInfo fEmote;

		private static FieldInfo fAnimator;

		private readonly GameObject player;

		private Component controller;

		private float nextSearch;

		public static bool Available
		{
			get
			{
				Resolve();
				return controllerType != null;
			}
		}

		public EmotePose(GameObject player)
		{
			this.player = player;
		}

		private static void Resolve()
		{
			if (resolved)
			{
				return;
			}
			resolved = true;
			try
			{
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				foreach (Assembly assembly in assemblies)
				{
					if (!(assembly.GetName().Name != "TooManyEmotes"))
					{
						controllerType = assembly.GetType("TooManyEmotes.EmoteControllerPlayer");
						break;
					}
				}
				if (controllerType == null)
				{
					return;
				}
				fPerforming = controllerType.GetField("isPerformingEmote", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
				fEmote = controllerType.GetField("performingEmote", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
				fAnimator = controllerType.GetField("animator", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
				if (fPerforming == null || fAnimator == null)
				{
					ManualLogSource log = Log;
					if (log != null)
					{
						log.LogWarning((object)("TooManyEmotes found but its EmoteController fields changed: " + Who + " stays upright while emoting"));
					}
					controllerType = null;
				}
				else
				{
					ManualLogSource log2 = Log;
					if (log2 != null)
					{
						log2.LogInfo((object)("TooManyEmotes found: " + Who + " follows emotes"));
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log3 = Log;
				if (log3 != null)
				{
					log3.LogWarning((object)("TooManyEmotes lookup failed (" + ex.Message + "): " + Who + " stays upright while emoting"));
				}
				controllerType = null;
			}
		}

		private Component Controller()
		{
			if ((Object)(object)controller != (Object)null)
			{
				return controller;
			}
			if (!Available || (Object)(object)player == (Object)null || Time.unscaledTime < nextSearch)
			{
				return null;
			}
			nextSearch = Time.unscaledTime + 1f;
			controller = player.GetComponentInChildren(controllerType, true);
			return controller;
		}

		public bool TryGet(out Vector3 hips, out Quaternion body, out Vector3 handL, out Vector3 handR)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0019: 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_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			hips = (handL = (handR = Vector3.zero));
			body = Quaternion.identity;
			Component val = Controller();
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			try
			{
				if (!(bool)fPerforming.GetValue(val))
				{
					return false;
				}
				if (fEmote != null && fEmote.GetValue(val) == null)
				{
					return false;
				}
				object? value = fAnimator.GetValue(val);
				Animator val2 = (Animator)((value is Animator) ? value : null);
				if ((Object)(object)val2 == (Object)null || !val2.isHuman || !((Behaviour)val2).isActiveAndEnabled)
				{
					return false;
				}
				Transform boneTransform = val2.GetBoneTransform((HumanBodyBones)0);
				Transform val3 = val2.GetBoneTransform((HumanBodyBones)9) ?? val2.GetBoneTransform((HumanBodyBones)54) ?? val2.GetBoneTransform((HumanBodyBones)8);
				Transform boneTransform2 = val2.GetBoneTransform((HumanBodyBones)1);
				Transform boneTransform3 = val2.GetBoneTransform((HumanBodyBones)2);
				Transform boneTransform4 = val2.GetBoneTransform((HumanBodyBones)13);
				Transform boneTransform5 = val2.GetBoneTransform((HumanBodyBones)14);
				if ((Object)(object)boneTransform == (Object)null || (Object)(object)val3 == (Object)null || (Object)(object)boneTransform2 == (Object)null || (Object)(object)boneTransform3 == (Object)null)
				{
					return false;
				}
				Vector3 val4 = val3.position - boneTransform.position;
				Vector3 val5 = boneTransform3.position - boneTransform2.position;
				if ((Object)(object)boneTransform4 != (Object)null && (Object)(object)boneTransform5 != (Object)null)
				{
					val5 += boneTransform5.position - boneTransform4.position;
				}
				if (((Vector3)(ref val4)).sqrMagnitude < 1E-06f || ((Vector3)(ref val5)).sqrMagnitude < 1E-06f)
				{
					return false;
				}
				((Vector3)(ref val4)).Normalize();
				Vector3 val6 = Vector3.Cross(val5, val4);
				if (((Vector3)(ref val6)).sqrMagnitude < 1E-06f)
				{
					return false;
				}
				body = Quaternion.LookRotation(val6, val4);
				hips = boneTransform.position;
				Transform boneTransform6 = val2.GetBoneTransform((HumanBodyBones)17);
				Transform boneTransform7 = val2.GetBoneTransform((HumanBodyBones)18);
				handL = (Object.op_Implicit((Object)(object)boneTransform6) ? boneTransform6.position : boneTransform.position);
				handR = (Object.op_Implicit((Object)(object)boneTransform7) ? boneTransform7.position : boneTransform.position);
				return true;
			}
			catch (Exception)
			{
				controller = null;
				return false;
			}
		}
	}
	public static class PluginInfo
	{
		public const string Guid = "daniel.lethalcompany.brockskin";

		public const string Name = "BrockSkin";

		public const string Version = "0.3.1";

		public const string SuitName = "Brock The Dodecahedron";
	}
	[BepInPlugin("daniel.lethalcompany.brockskin", "BrockSkin", "0.3.1")]
	[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 Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		internal static AssetBundle Bundle;

		internal static ConfigEntry<bool> FollowEmotes;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			EmotePose.Log = Log;
			SuitTexture.Ensure(((BaseUnityPlugin)this).Info.Location, "Brock The Dodecahedron", "BrockSkin.suit.png", Log);
			FollowEmotes = ((BaseUnityPlugin)this).Config.Bind<bool>("Brock", "FollowEmotes", true, "While a TooManyEmotes emote plays, Brock's body turns, flips and lies down with the emote, then floats upright again when it ends.");
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("BrockSkin.brocksuit"))
			{
				if (stream == null)
				{
					Log.LogError((object)"Embedded bundle BrockSkin.brocksuit is missing");
					return;
				}
				Bundle = AssetBundle.LoadFromStream(stream);
			}
			if ((Object)(object)Bundle == (Object)null)
			{
				Log.LogError((object)"Could not load the Brock bundle");
				return;
			}
			ModelReplacementAPI.RegisterSuitModelReplacement("Brock The Dodecahedron", typeof(BrockReplacement));
			Log.LogInfo((object)"BrockSkin 0.3.1 loaded: suit \"Brock The Dodecahedron\" -> Brock the Dodecahedron");
			if (SkinMenu.MenuInstalled)
			{
				SkinMenu.Register("Brock The Dodecahedron", "Brock", FollowEmotes);
			}
		}
	}
	public class BrockReplacement : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			return Plugin.Bundle.LoadAsset<GameObject>("brock");
		}

		protected override AvatarUpdater GetAvatarUpdater()
		{
			return (AvatarUpdater)(object)new BrockUpdater();
		}
	}
	public class BrockUpdater : AvatarUpdater
	{
		private const float BobHeight = 0.05f;

		private const float BobPeriod = 2f;

		private const float LeanPerMps = 2.6f;

		private const float MaxLean = 12f;

		private const float HandFollow = 0.7f;

		private const float CrouchShare = 0.6f;

		private const float HoverGap = 0.4f;

		private const float EmoteBlendIn = 8f;

		private const float EmoteBlendOut = 5f;

		private Transform hover;

		private Transform handL;

		private Transform handR;

		private Transform hiddenHandL;

		private Transform hiddenHandR;

		private Transform playerHandL;

		private Transform playerHandR;

		private Transform playerSpine;

		private Transform playerModel;

		private Vector3 handLRest;

		private Vector3 handRRest;

		private Vector3 playerHandLRest;

		private Vector3 playerHandRRest;

		private Vector3 assetHoverLocal;

		private Quaternion assetRootRot;

		private Quaternion assetHoverRot;

		private float playerSpineRestY;

		private Vector3 lastPos;

		private Vector3 velocity;

		private bool haveLast;

		private EmotePose emote;

		private float emoteW;

		private bool restHipsKnown;

		private Vector3 restHips;

		private Vector3 restHandL;

		private Vector3 restHandR;

		private Vector3 eHips;

		private Vector3 eHandL;

		private Vector3 eHandR;

		private Quaternion eBody = Quaternion.identity;

		private bool haveEmote;

		private float floorClear;

		public override void AssignModelReplacement(GameObject player, GameObject replacement)
		{
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			((AvatarUpdater)this).AssignModelReplacement(player, replacement);
			if ((Object)(object)replacement == (Object)null || (Object)(object)base.playerModelRenderer == (Object)null)
			{
				return;
			}
			ForceOnscreen();
			Transform[] all = replacement.GetComponentsInChildren<Transform>(true);
			hover = Find("Hover");
			handL = Find("Hand_L");
			handR = Find("Hand_R");
			if ((Object)(object)hover == (Object)null || (Object)(object)handL == (Object)null || (Object)(object)handR == (Object)null)
			{
				Plugin.Log.LogError((object)"Brock prefab is missing Hover/Hand_L/Hand_R: floating disabled");
				hover = null;
				return;
			}
			GameObject val = Plugin.Bundle.LoadAsset<GameObject>("brock");
			Transform val2 = (Object.op_Implicit((Object)(object)val) ? ((IEnumerable<Transform>)val.GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == "Hover")) : null);
			if ((Object)(object)val2 == (Object)null)
			{
				Plugin.Log.LogError((object)"Brock asset has no Hover: floating disabled");
				hover = null;
				return;
			}
			assetRootRot = val.transform.rotation;
			assetHoverRot = val2.rotation;
			assetHoverLocal = val.transform.InverseTransformPoint(val2.position);
			handLRest = handL.localPosition;
			handRRest = handR.localPosition;
			hiddenHandL = base.replacementAnimator.GetBoneTransform((HumanBodyBones)17);
			hiddenHandR = base.replacementAnimator.GetBoneTransform((HumanBodyBones)18);
			playerModel = ((Component)base.playerModelRenderer).transform;
			playerHandL = ((AvatarUpdater)this).GetPlayerTransformFromBoneName("hand.L");
			playerHandR = ((AvatarUpdater)this).GetPlayerTransformFromBoneName("hand.R");
			playerSpine = ((AvatarUpdater)this).GetPlayerTransformFromBoneName("spine");
			if (Object.op_Implicit((Object)(object)playerHandL))
			{
				playerHandLRest = playerModel.InverseTransformPoint(playerHandL.position);
			}
			if (Object.op_Implicit((Object)(object)playerHandR))
			{
				playerHandRRest = playerModel.InverseTransformPoint(playerHandR.position);
			}
			if (Object.op_Implicit((Object)(object)playerSpine))
			{
				playerSpineRestY = playerModel.InverseTransformPoint(playerSpine.position).y;
			}
			emote = new EmotePose(player);
			Vector3 val3 = replacement.transform.TransformVector(Vector3.up);
			float magnitude = ((Vector3)(ref val3)).magnitude;
			float y = (assetRootRot * (assetHoverLocal * magnitude)).y;
			floorClear = Mathf.Max(y - 0.4f * magnitude, 0.3f);
			Transform Find(string n)
			{
				return ((IEnumerable<Transform>)all).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == n));
			}
		}

		protected override void UpdateModel()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_0369: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_037d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_045a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0467: Unknown result type (might be due to invalid IL or missing references)
			//IL_048a: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0401: Unknown result type (might be due to invalid IL or missing references)
			//IL_0406: Unknown result type (might be due to invalid IL or missing references)
			//IL_0408: Unknown result type (might be due to invalid IL or missing references)
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_041c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0420: Unknown result type (might be due to invalid IL or missing references)
			//IL_0425: Unknown result type (might be due to invalid IL or missing references)
			//IL_0427: Unknown result type (might be due to invalid IL or missing references)
			//IL_0429: Unknown result type (might be due to invalid IL or missing references)
			//IL_042d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0432: Unknown result type (might be due to invalid IL or missing references)
			//IL_0436: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: Unknown result type (might be due to invalid IL or missing references)
			//IL_051a: Unknown result type (might be due to invalid IL or missing references)
			//IL_053d: Unknown result type (might be due to invalid IL or missing references)
			((AvatarUpdater)this).UpdateModel();
			if (!((Object)(object)hover == (Object)null))
			{
				Transform transform = base.replacement.transform;
				float num = Mathf.Max(Time.deltaTime, 0.0001f);
				Vector3 position = base.player.transform.position;
				Vector3 val = (haveLast ? ((position - lastPos) / num) : Vector3.zero);
				if (((Vector3)(ref val)).sqrMagnitude > 400f)
				{
					val = Vector3.zero;
				}
				lastPos = position;
				haveLast = true;
				velocity = Vector3.Lerp(velocity, val, 1f - Mathf.Exp(-5f * num));
				Vector3 val2 = Vector3.ProjectOnPlane(base.player.transform.forward, Vector3.up);
				if (((Vector3)(ref val2)).sqrMagnitude < 1E-06f)
				{
					val2 = Vector3.ProjectOnPlane(base.player.transform.up, Vector3.up);
				}
				Quaternion val3 = ((((Vector3)(ref val2)).sqrMagnitude > 1E-06f) ? Quaternion.LookRotation(val2, Vector3.up) : Quaternion.identity);
				Vector3 val4 = Quaternion.Inverse(val3) * velocity;
				float time = Time.time;
				Vector3 val5 = transform.TransformVector(Vector3.up);
				float magnitude = ((Vector3)(ref val5)).magnitude;
				float num2 = 0.05f * Mathf.Sin(MathF.PI * 2f * time / 2f) * magnitude;
				float num3 = 0f;
				if (Object.op_Implicit((Object)(object)playerSpine))
				{
					num3 = Mathf.Clamp(playerSpineRestY - playerModel.InverseTransformPoint(playerSpine.position).y, 0f, 2f) * 0.6f * playerModel.lossyScale.y;
				}
				Vector3 hips;
				Quaternion body;
				Vector3 hl;
				Vector3 hr;
				bool flag = Plugin.FollowEmotes.Value && emote != null && emote.TryGet(out hips, out body, out hl, out hr) && Remember(hips, body, hl, hr);
				float num4 = (flag ? 8f : 5f);
				emoteW = Mathf.Lerp(emoteW, flag ? 1f : 0f, 1f - Mathf.Exp((0f - num4) * num));
				if (!flag && emoteW < 0.002f)
				{
					emoteW = 0f;
					haveEmote = false;
				}
				if (!flag && !haveEmote)
				{
					TrackRest(position, val3);
				}
				float num5 = (haveEmote ? emoteW : 0f);
				float num6 = 1f - 0.7f * num5;
				float num7 = Mathf.Clamp(val4.z * 2.6f, -12f, 12f) * (1f - num5) + 1.5f * num6 * Mathf.Sin(time * MathF.PI / 2f + 0.6f);
				float num8 = Mathf.Clamp((0f - val4.x) * 2.6f, -12f, 12f) * (1f - num5) + 2.5f * num6 * Mathf.Sin(time * MathF.PI / 2f);
				float num9 = 3f * num6 * Mathf.Sin(time * MathF.PI / 2f + 1.9f);
				Quaternion val6 = Quaternion.Euler(num7, num9, num8);
				Vector3 val7 = val3 * (assetRootRot * (assetHoverLocal * magnitude));
				Vector3 val8 = position + val7 + Vector3.up * (num2 - num3);
				Quaternion val9 = val3 * val6 * assetHoverRot;
				if (num5 > 0f)
				{
					Vector3 val10 = Quaternion.Inverse(val3) * val7 - restHips;
					Vector3 val11 = eHips + eBody * val10 + Vector3.up * num2;
					Quaternion val12 = eBody * val6 * assetHoverRot;
					val8 = Vector3.Lerp(val8, val11, num5);
					val9 = Quaternion.Slerp(val9, val12, num5);
					val8.y = Mathf.Max(val8.y, position.y + floorClear);
				}
				hover.position = val8;
				hover.rotation = val9;
				float k = 1f - Mathf.Exp(-10f * num);
				float ratio = magnitude / Mathf.Max(playerModel.lossyScale.y, 0.0001f);
				FollowHand(handL, handLRest, playerHandL, playerHandLRest, ratio, k, num5, eHandL, restHandL);
				FollowHand(handR, handRRest, playerHandR, playerHandRRest, ratio, k, num5, eHandR, restHandR);
				if (Object.op_Implicit((Object)(object)hiddenHandL))
				{
					hiddenHandL.position = handL.position;
				}
				if (Object.op_Implicit((Object)(object)hiddenHandR))
				{
					hiddenHandR.position = handR.position;
				}
			}
		}

		private void ForceOnscreen()
		{
			SkinnedMeshRenderer[] componentsInChildren = base.replacement.GetComponentsInChildren<SkinnedMeshRenderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].updateWhenOffscreen = true;
			}
		}

		private bool Remember(Vector3 hips, Quaternion body, Vector3 hl, Vector3 hr)
		{
			//IL_000b: 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_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_0019: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if (!restHipsKnown)
			{
				return false;
			}
			eHips = hips;
			eBody = body;
			eHandL = hl;
			eHandR = hr;
			haveEmote = true;
			return true;
		}

		private void TrackRest(Vector3 feet, Quaternion facing)
		{
			//IL_000e: 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_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)
			//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)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_0070: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: 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_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)
			if (Object.op_Implicit((Object)(object)playerSpine))
			{
				Quaternion val = Quaternion.Inverse(facing);
				Vector3 val2 = val * (playerSpine.position - feet);
				Vector3 val3 = (Object.op_Implicit((Object)(object)playerHandL) ? (val * (playerHandL.position - playerSpine.position)) : Vector3.zero);
				Vector3 val4 = (Object.op_Implicit((Object)(object)playerHandR) ? (val * (playerHandR.position - playerSpine.position)) : Vector3.zero);
				if (!restHipsKnown)
				{
					restHips = val2;
					restHandL = val3;
					restHandR = val4;
					restHipsKnown = true;
				}
				else
				{
					float num = 1f - Mathf.Exp(-2f * Mathf.Max(Time.deltaTime, 0.0001f));
					restHips = Vector3.Lerp(restHips, val2, num);
					restHandL = Vector3.Lerp(restHandL, val3, num);
					restHandR = Vector3.Lerp(restHandR, val4, num);
				}
			}
		}

		private void FollowHand(Transform hand, Vector3 restLocal, Transform playerHand, Vector3 playerRest, float ratio, float k, float w, Vector3 emoteHand, Vector3 restFromHips)
		{
			//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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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_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_00cd: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = hover.TransformPoint(restLocal);
			Vector3 val2 = Vector3.zero;
			if (Object.op_Implicit((Object)(object)playerHand))
			{
				val2 = playerModel.TransformVector(playerModel.InverseTransformPoint(playerHand.position) - playerRest);
			}
			if (w > 0f)
			{
				Vector3 val3 = emoteHand - eHips - eBody * restFromHips;
				val2 = Vector3.Lerp(val2, val3, w);
			}
			val += val2 * 0.7f * Mathf.Clamp(ratio, 0.5f, 2f);
			float num = Mathf.Max(Time.deltaTime, 0.0001f);
			hand.position = Vector3.Lerp(hand.position, val, Mathf.Lerp(k, 1f - Mathf.Exp(-20f * num), w));
		}
	}
}