Decompiled source of MoistSlabSkin v0.1.0

MoistSlabSkin.dll

Decompiled 2 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.Configuration;
using BepInEx.Logging;
using BrockSkin;
using Microsoft.CodeAnalysis;
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("MoistSlabSkin")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+6c4eeabead00f28298402aff904e51047efaf841")]
[assembly: AssemblyProduct("MoistSlabSkin")]
[assembly: AssemblyTitle("MoistSlabSkin")]
[assembly: AssemblyVersion("0.1.0.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"));
			}
		}
	}
}
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;
			}
		}
	}
}
namespace MoistSlabSkin
{
	public static class PluginInfo
	{
		public const string Guid = "daniel.lethalcompany.moistslabskin";

		public const string Name = "MoistSlabSkin";

		public const string Version = "0.1.0";

		public const string SuitName = "Moist The Slab";
	}
	[BepInPlugin("daniel.lethalcompany.moistslabskin", "MoistSlabSkin", "0.1.0")]
	[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;
			EmotePose.Who = "Moist";
			SuitTexture.Ensure(((BaseUnityPlugin)this).Info.Location, "Moist The Slab", "MoistSlabSkin.suit.png", Log);
			FollowEmotes = ((BaseUnityPlugin)this).Config.Bind<bool>("Moist", "FollowEmotes", true, "While a TooManyEmotes emote plays, Moist tips, flops and turns over with the emote, then rights herself when it ends.");
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MoistSlabSkin.moistsuit"))
			{
				if (stream == null)
				{
					Log.LogError((object)"Embedded bundle MoistSlabSkin.moistsuit is missing");
					return;
				}
				Bundle = AssetBundle.LoadFromStream(stream);
			}
			if ((Object)(object)Bundle == (Object)null)
			{
				Log.LogError((object)"Could not load the Moist bundle");
				return;
			}
			ModelReplacementAPI.RegisterSuitModelReplacement("Moist The Slab", typeof(MoistReplacement));
			Log.LogInfo((object)"MoistSlabSkin 0.1.0 loaded: suit \"Moist The Slab\" -> Moist the Slab");
		}
	}
	public class MoistReplacement : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			return Plugin.Bundle.LoadAsset<GameObject>("moist");
		}

		protected override AvatarUpdater GetAvatarUpdater()
		{
			return (AvatarUpdater)(object)new MoistUpdater();
		}
	}
	public class MoistUpdater : AvatarUpdater
	{
		private const float HopHeight = 0.035f;

		private const float HopPerMetre = 1.6f;

		private const float LeanPerMps = 1.6f;

		private const float MaxLean = 9f;

		private const float CrouchSquash = 0.22f;

		private const float BreathAmount = 0.012f;

		private const float EmoteBlendIn = 8f;

		private const float EmoteBlendOut = 5f;

		private static readonly Vector3 LipL = new Vector3(0.32f, 0.48f, 0.72f);

		private static readonly Vector3 LipR = new Vector3(-0.32f, 0.48f, 0.72f);

		private Transform body;

		private Transform upper;

		private Transform hiddenHandL;

		private Transform hiddenHandR;

		private Transform playerSpine;

		private Transform playerModel;

		private Vector3 assetBodyLocal;

		private Vector3 upperRestScale;

		private Quaternion assetRootRot;

		private Quaternion assetBodyRot;

		private Quaternion upperRestRot;

		private float playerSpineRestY;

		private float hopPhase;

		private float halfDepth;

		private Vector3 lastPos;

		private Vector3 velocity;

		private bool haveLast;

		private SkinnedMeshRenderer face;

		private int blinkL = -1;

		private int blinkR = -1;

		private float nextBlink;

		private float blinkStart = -1f;

		private EmotePose emote;

		private float emoteW;

		private bool restHipsKnown;

		private bool haveEmote;

		private Vector3 restHips;

		private Vector3 eHips;

		private Quaternion eBody = Quaternion.identity;

		public override void AssignModelReplacement(GameObject player, GameObject replacement)
		{
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: 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;
			}
			SkinnedMeshRenderer[] componentsInChildren = replacement.GetComponentsInChildren<SkinnedMeshRenderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].updateWhenOffscreen = true;
			}
			Transform[] componentsInChildren2 = replacement.GetComponentsInChildren<Transform>(true);
			body = ((IEnumerable<Transform>)componentsInChildren2).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == "Body"));
			upper = ((IEnumerable<Transform>)componentsInChildren2).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == "Upper"));
			GameObject val = Plugin.Bundle.LoadAsset<GameObject>("moist");
			Transform val2 = (Object.op_Implicit((Object)(object)val) ? ((IEnumerable<Transform>)val.GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == "Body")) : null);
			if ((Object)(object)body == (Object)null || (Object)(object)upper == (Object)null || (Object)(object)val2 == (Object)null)
			{
				Plugin.Log.LogError((object)"Moist prefab is missing Body/Upper: her own motion is disabled");
				body = null;
				return;
			}
			assetRootRot = val.transform.rotation;
			assetBodyRot = val2.rotation;
			assetBodyLocal = val.transform.InverseTransformPoint(val2.position);
			upperRestRot = upper.localRotation;
			upperRestScale = upper.localScale;
			hiddenHandL = base.replacementAnimator.GetBoneTransform((HumanBodyBones)17);
			hiddenHandR = base.replacementAnimator.GetBoneTransform((HumanBodyBones)18);
			playerModel = ((Component)base.playerModelRenderer).transform;
			playerSpine = ((AvatarUpdater)this).GetPlayerTransformFromBoneName("spine");
			if (Object.op_Implicit((Object)(object)playerSpine))
			{
				playerSpineRestY = playerModel.InverseTransformPoint(playerSpine.position).y;
			}
			face = ((IEnumerable<SkinnedMeshRenderer>)replacement.GetComponentsInChildren<SkinnedMeshRenderer>(true)).FirstOrDefault((Func<SkinnedMeshRenderer, bool>)((SkinnedMeshRenderer r) => Object.op_Implicit((Object)(object)r.sharedMesh) && r.sharedMesh.blendShapeCount > 0));
			if (Object.op_Implicit((Object)(object)face))
			{
				blinkL = face.sharedMesh.GetBlendShapeIndex("Blink_L");
				blinkR = face.sharedMesh.GetBlendShapeIndex("Blink_R");
			}
			nextBlink = Time.time + Random.Range(1.5f, 4f);
			emote = new EmotePose(player);
			halfDepth = 0.625f;
		}

		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_00d9: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: 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_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: 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_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: 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_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: 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_037b: 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_03ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_040a: 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_041d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0491: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_0347: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0501: Unknown result type (might be due to invalid IL or missing references)
			//IL_0506: Unknown result type (might be due to invalid IL or missing references)
			//IL_0508: Unknown result type (might be due to invalid IL or missing references)
			//IL_050d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0512: Unknown result type (might be due to invalid IL or missing references)
			//IL_0535: Unknown result type (might be due to invalid IL or missing references)
			//IL_053a: Unknown result type (might be due to invalid IL or missing references)
			//IL_053c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0543: Unknown result type (might be due to invalid IL or missing references)
			//IL_0548: Unknown result type (might be due to invalid IL or missing references)
			//IL_054a: Unknown result type (might be due to invalid IL or missing references)
			//IL_054f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0554: Unknown result type (might be due to invalid IL or missing references)
			((AvatarUpdater)this).UpdateModel();
			if (!((Object)(object)body == (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(-6f * num));
				Vector3 val2 = Vector3.ProjectOnPlane(base.player.transform.forward, Vector3.up);
				Quaternion val3 = ((((Vector3)(ref val2)).sqrMagnitude > 1E-06f) ? Quaternion.LookRotation(val2, Vector3.up) : Quaternion.identity);
				Vector3 val4 = Quaternion.Inverse(val3) * velocity;
				Vector2 val5 = new Vector2(val4.x, val4.z);
				float magnitude = ((Vector2)(ref val5)).magnitude;
				Vector3 handL = transform.TransformVector(Vector3.up);
				float magnitude2 = ((Vector3)(ref handL)).magnitude;
				float time = Time.time;
				hopPhase += magnitude * 1.6f * num / Mathf.Max(magnitude2, 0.05f);
				float num2 = Mathf.Abs(Mathf.Sin(MathF.PI * hopPhase)) * 0.035f * magnitude2 * Mathf.Clamp01(magnitude / 3f);
				float num3 = 0f;
				if (Object.op_Implicit((Object)(object)playerSpine))
				{
					num3 = Mathf.Clamp01((playerSpineRestY - playerModel.InverseTransformPoint(playerSpine.position).y) / 0.6f);
				}
				Vector3 hips;
				Quaternion b;
				Vector3 handR;
				bool flag = Plugin.FollowEmotes.Value && emote != null && emote.TryGet(out hips, out b, out handL, out handR) && Remember(hips, b);
				emoteW = Mathf.Lerp(emoteW, flag ? 1f : 0f, 1f - Mathf.Exp((0f - (flag ? 8f : 5f)) * num));
				if (!flag && emoteW < 0.002f)
				{
					emoteW = 0f;
					haveEmote = false;
				}
				if (!flag && !haveEmote)
				{
					TrackRest(position, val3);
				}
				float num4 = (haveEmote ? emoteW : 0f);
				Vector3 val6 = val3 * (assetRootRot * (assetBodyLocal * magnitude2));
				Vector3 val7 = position + val6 + Vector3.up * num2;
				Quaternion val8 = val3 * assetBodyRot;
				if (num4 > 0f)
				{
					Vector3 val9 = Quaternion.Inverse(val3) * val6 - restHips;
					Vector3 val10 = eHips + eBody * val9;
					val7 = Vector3.Lerp(val7, val10, num4);
					val8 = Quaternion.Slerp(val8, eBody * assetBodyRot, num4);
					val7.y = Mathf.Max(val7.y, position.y + halfDepth * magnitude2);
				}
				body.position = val7;
				body.rotation = val8;
				float num5 = 1f - num4;
				float num6 = Mathf.Clamp(val4.z * 1.6f, -9f, 9f) * num5 + 1.2f * num5 * Mathf.Sin(time * 1.3f + 0.4f);
				float num7 = Mathf.Clamp((0f - val4.x) * 1.6f, -9f, 9f) * num5 + 1.6f * num5 * Mathf.Sin(time * 0.9f);
				upper.localRotation = upperRestRot * Quaternion.Euler(num6, 0f, num7);
				float num8 = 1f - 0.22f * num3 + 0.012f * Mathf.Sin(time * 2.1f);
				float num9 = 1f + 0.5f * (1f - num8);
				upper.localScale = new Vector3(upperRestScale.x * num9, upperRestScale.y * num8, upperRestScale.z * num9);
				Blink(time);
				Vector3 val11 = assetRootRot * (assetBodyLocal * magnitude2);
				Quaternion val12 = body.rotation * Quaternion.Inverse(assetBodyRot);
				if (Object.op_Implicit((Object)(object)hiddenHandL))
				{
					hiddenHandL.position = body.position + val12 * (LipL * magnitude2 - val11);
				}
				if (Object.op_Implicit((Object)(object)hiddenHandR))
				{
					hiddenHandR.position = body.position + val12 * (LipR * magnitude2 - val11);
				}
			}
		}

		private void Blink(float t)
		{
			if ((Object)(object)face == (Object)null || blinkL < 0 || blinkR < 0)
			{
				return;
			}
			if (blinkStart < 0f && t >= nextBlink)
			{
				blinkStart = t;
			}
			float num = 0f;
			if (blinkStart >= 0f)
			{
				float num2 = (t - blinkStart) / 0.16f;
				num = ((num2 < 0.5f) ? (num2 * 2f) : Mathf.Max(0f, 2f - num2 * 2f));
				if (num2 >= 1f)
				{
					blinkStart = -1f;
					num = 0f;
					nextBlink = t + Random.Range(2.5f, 6f);
				}
			}
			face.SetBlendShapeWeight(blinkL, num * 100f);
			face.SetBlendShapeWeight(blinkR, num * 100f);
		}

		private bool Remember(Vector3 hips, Quaternion b)
		{
			//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)
			if (!restHipsKnown)
			{
				return false;
			}
			eHips = hips;
			eBody = b;
			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_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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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)
			if (Object.op_Implicit((Object)(object)playerSpine))
			{
				Vector3 val = Quaternion.Inverse(facing) * (playerSpine.position - feet);
				if (!restHipsKnown)
				{
					restHips = val;
					restHipsKnown = true;
				}
				else
				{
					restHips = Vector3.Lerp(restHips, val, 1f - Mathf.Exp(-2f * Mathf.Max(Time.deltaTime, 0.0001f)));
				}
			}
		}
	}
}