Decompiled source of UmamusumeSemibots v2.0.2

JigglePhysicsPlugin.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.LowLevel;
using UnityEngine.PlayerLoop;
using UnityEngine.Serialization;

[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: AssemblyCompany("JigglePhysicsPlugin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("JigglePhysicsPlugin")]
[assembly: AssemblyTitle("JigglePhysicsPlugin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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;
		}
	}
}
namespace JigglePhysicsPlugin
{
	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));
		}
	}
	[BepInPlugin("1.Waga.JigglePhysicsPlugin", "JigglePhysicsPlugin", "1.1.2")]
	public class Plugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		private static Plugin instance;

		private void Awake()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			instance = this;
			_harmony = new Harmony("JigglePhysicsPlugin");
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"JigglePhysicsPlugin loaded!");
		}

		public static void Log(string message)
		{
			((BaseUnityPlugin)instance).Logger.LogInfo((object)message);
		}
	}
	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_0050: 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_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_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_006a: 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);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "JigglePhysicsPlugin";

		public const string PLUGIN_NAME = "JigglePhysicsPlugin";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}

UmamusumeSemiBots.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using JigglePhysicsPlugin;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UmamusumeSemiBots;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.Rendering.PostProcessing;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("UmamusumeSemiBots")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UmamusumeSemiBots")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4c8636a0-95bd-4967-9e4e-37630d6c4ea6")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
public class SmolSpectateAnimator : MonoBehaviour
{
	public Animator animator;

	public PlayerDeathHead deathHead;

	private static readonly int ParamIdle = Animator.StringToHash("Idle");

	private static readonly int ParamCharge = Animator.StringToHash("Charging");

	private static readonly int ParamJump = Animator.StringToHash("Jump");

	private static readonly int ParamChargePct = Animator.StringToHash("ChargeAmount");

	private Traverse<bool> _spectatedField;

	private Traverse<bool> _chargingField;

	private Traverse<float> _chargeAmtField;

	private Traverse<float> _chargeMaxField;

	private bool _wasCharging;

	private bool _ragdollActivated;

	private bool _spectateActivated;

	private bool _idleActivated;

	private float _fallbackTimer = -1f;

	private const float FallbackDelay = 0.1f;

	private Coroutine _freezeCoroutine;

	private Vector3 _originalLocalPosition;

	public bool IsIdling => _idleActivated && !_spectateActivated && !_ragdollActivated;

	public bool IsRagdolling => _ragdollActivated && !_spectateActivated;

	public void Init()
	{
		//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)
		Traverse val = Traverse.Create((object)deathHead);
		_spectatedField = val.Field<bool>("spectated");
		_chargingField = val.Field<bool>("spectatedJumpCharging");
		_chargeAmtField = val.Field<float>("spectatedJumpChargeAmount");
		_chargeMaxField = val.Field<float>("spectatedJumpChargeAmountMax");
		_originalLocalPosition = ((Component)this).gameObject.transform.localPosition;
		((Behaviour)this).enabled = true;
	}

	private void Update()
	{
		if ((Object)(object)deathHead == (Object)null)
		{
			return;
		}
		if (_fallbackTimer > 0f)
		{
			_fallbackTimer -= Time.deltaTime;
			if (_fallbackTimer <= 0f)
			{
				_fallbackTimer = -1f;
				if (!_spectateActivated && !_ragdollActivated && !_idleActivated)
				{
					if (CustomModelSwapMod.DisableDeathRagdoll.Value)
					{
						EnableIdleMode();
					}
					else
					{
						EnableRagdollMode();
					}
				}
			}
		}
		if (_spectateActivated && !_ragdollActivated && !((Object)(object)animator == (Object)null))
		{
			bool value = _chargingField.Value;
			float value2 = _chargeAmtField.Value;
			float value3 = _chargeMaxField.Value;
			animator.SetFloat(ParamChargePct, (value3 > 0f) ? (value2 / value3) : 0f);
			if (value)
			{
				animator.SetBool(ParamCharge, true);
				animator.SetBool(ParamIdle, false);
				_wasCharging = true;
			}
			else if (_wasCharging)
			{
				animator.SetBool(ParamCharge, false);
				animator.SetTrigger(ParamJump);
				_wasCharging = false;
			}
			else
			{
				animator.SetBool(ParamIdle, true);
				animator.SetBool(ParamCharge, false);
			}
		}
	}

	public void EnableSpectateMode()
	{
		//IL_0091: 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)
		_spectateActivated = true;
		_ragdollActivated = false;
		_idleActivated = false;
		_wasCharging = false;
		_fallbackTimer = -1f;
		CancelFreezeCoroutine();
		TearDownRagdoll();
		if ((Object)(object)animator != (Object)null)
		{
			animator.speed = 1f;
			animator.runtimeAnimatorController = CustomModelSwapMod.SmolSpectateController;
			((Behaviour)animator).enabled = true;
		}
		((Component)this).gameObject.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
		((Component)this).gameObject.transform.localPosition = _originalLocalPosition;
	}

	public void EnableIdleMode()
	{
		//IL_00d1: 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_00fc: 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)
		_idleActivated = true;
		_ragdollActivated = false;
		_spectateActivated = false;
		_wasCharging = false;
		_fallbackTimer = -1f;
		CancelFreezeCoroutine();
		TearDownRagdoll();
		if (!((Object)(object)animator == (Object)null))
		{
			animator.speed = 1f;
			animator.runtimeAnimatorController = CustomModelSwapMod.SmolSpectateController;
			((Behaviour)animator).enabled = true;
			try
			{
				animator.Rebind();
				animator.Update(0f);
				animator.Play("SpecialIdle", 0, 0f);
			}
			catch
			{
			}
			((Component)this).gameObject.transform.localRotation = Quaternion.Euler(-90f, 0f, 0f);
			((Component)this).gameObject.transform.localPosition = _originalLocalPosition + new Vector3(0f, 0.01f, 0.3f);
			_freezeCoroutine = ((MonoBehaviour)this).StartCoroutine(FreezeAfterSpecialIdle());
		}
	}

	private IEnumerator FreezeAfterSpecialIdle()
	{
		yield return null;
		yield return null;
		if ((Object)(object)animator == (Object)null)
		{
			yield break;
		}
		float timeout = 3f;
		float elapsed = 0f;
		while (elapsed < timeout)
		{
			AnimatorStateInfo info = animator.GetCurrentAnimatorStateInfo(0);
			if (((AnimatorStateInfo)(ref info)).IsName("SpecialIdle") || ((AnimatorStateInfo)(ref info)).IsName("Base Layer.SpecialIdle"))
			{
				break;
			}
			elapsed += Time.deltaTime;
			yield return null;
			info = default(AnimatorStateInfo);
		}
		if (!((Object)(object)animator == (Object)null))
		{
			AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
			float remaining = ((AnimatorStateInfo)(ref stateInfo)).length * (1f - ((AnimatorStateInfo)(ref stateInfo)).normalizedTime);
			yield return (object)new WaitForSeconds(Mathf.Max(0f, remaining));
			if ((Object)(object)animator != (Object)null)
			{
				animator.speed = 0f;
			}
			_freezeCoroutine = null;
		}
	}

	private void TearDownRagdoll()
	{
		CharacterJoint[] componentsInChildren = ((Component)this).gameObject.GetComponentsInChildren<CharacterJoint>(true);
		foreach (CharacterJoint val in componentsInChildren)
		{
			Object.Destroy((Object)(object)val);
		}
		ConfigurableJoint[] componentsInChildren2 = ((Component)this).gameObject.GetComponentsInChildren<ConfigurableJoint>(true);
		foreach (ConfigurableJoint val2 in componentsInChildren2)
		{
			Object.Destroy((Object)(object)val2);
		}
		Rigidbody[] componentsInChildren3 = ((Component)this).gameObject.GetComponentsInChildren<Rigidbody>(true);
		foreach (Rigidbody val3 in componentsInChildren3)
		{
			Object.Destroy((Object)(object)val3);
		}
		CapsuleCollider[] componentsInChildren4 = ((Component)this).gameObject.GetComponentsInChildren<CapsuleCollider>(true);
		foreach (CapsuleCollider val4 in componentsInChildren4)
		{
			Object.Destroy((Object)(object)val4);
		}
	}

	private void CancelFreezeCoroutine()
	{
		if (_freezeCoroutine != null)
		{
			((MonoBehaviour)this).StopCoroutine(_freezeCoroutine);
			_freezeCoroutine = null;
		}
	}

	public void EnableRagdollMode()
	{
		if (!_ragdollActivated)
		{
			_ragdollActivated = true;
			_spectateActivated = false;
			_idleActivated = false;
			CancelFreezeCoroutine();
			if ((Object)(object)animator != (Object)null)
			{
				animator.speed = 1f;
				((Behaviour)animator).enabled = false;
				animator.runtimeAnimatorController = null;
			}
			ActivateRagdoll();
		}
	}

	private void ActivateRagdoll()
	{
		//IL_0096: 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_05cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ea: 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_00f5: 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_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_030a: Unknown result type (might be due to invalid IL or missing references)
		//IL_030d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0310: Invalid comparison between Unknown and I4
		//IL_0323: Unknown result type (might be due to invalid IL or missing references)
		//IL_0341: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0519: Unknown result type (might be due to invalid IL or missing references)
		//IL_0523: Unknown result type (might be due to invalid IL or missing references)
		//IL_052d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0532: Unknown result type (might be due to invalid IL or missing references)
		//IL_0536: Unknown result type (might be due to invalid IL or missing references)
		//IL_0541: Unknown result type (might be due to invalid IL or missing references)
		//IL_054b: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d2: 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_03e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ef: 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_0403: Unknown result type (might be due to invalid IL or missing references)
		//IL_040d: Unknown result type (might be due to invalid IL or missing references)
		Animator smolAnim = ((Component)this).gameObject.GetComponent<Animator>() ?? ((Component)this).gameObject.GetComponentInChildren<Animator>(true);
		if ((Object)(object)smolAnim != (Object)null)
		{
			((Behaviour)smolAnim).enabled = false;
		}
		if ((Object)(object)smolAnim != (Object)null && smolAnim.isHuman)
		{
			HumanBodyBones[] array = new HumanBodyBones[12];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			HumanBodyBones[] array2 = (HumanBodyBones[])(object)array;
			int layer = LayerMask.NameToLayer("Default");
			HumanBodyBones[] array3 = array2;
			foreach (HumanBodyBones val in array3)
			{
				Transform boneTransform = smolAnim.GetBoneTransform(val);
				if ((Object)(object)boneTransform != (Object)null)
				{
					((Component)boneTransform).gameObject.layer = layer;
				}
			}
			Dictionary<HumanBodyBones, Rigidbody> dictionary = new Dictionary<HumanBodyBones, Rigidbody>();
			HumanBodyBones[] array4 = array2;
			foreach (HumanBodyBones val2 in array4)
			{
				Transform boneTransform2 = smolAnim.GetBoneTransform(val2);
				if (!((Object)(object)boneTransform2 == (Object)null))
				{
					Rigidbody val3 = ((Component)boneTransform2).gameObject.AddComponent<Rigidbody>();
					val3.mass = (((int)val2 == 0) ? 0.05f : 0.01f);
					val3.drag = 2f;
					val3.angularDrag = 3f;
					val3.interpolation = (RigidbodyInterpolation)1;
					val3.collisionDetectionMode = (CollisionDetectionMode)0;
					val3.maxAngularVelocity = 7f;
					CapsuleCollider val4 = ((Component)boneTransform2).gameObject.AddComponent<CapsuleCollider>();
					val4.radius = 0.04f;
					val4.height = 0.1f;
					dictionary[val2] = val3;
				}
			}
			List<CapsuleCollider> list = (from b in dictionary.Keys
				select smolAnim.GetBoneTransform(b) into t
				where (Object)(object)t != (Object)null
				select ((Component)t).GetComponent<CapsuleCollider>() into c
				where (Object)(object)c != (Object)null
				select c).ToList();
			for (int num = 0; num < list.Count; num++)
			{
				for (int num2 = num + 1; num2 < list.Count; num2++)
				{
					Physics.IgnoreCollision((Collider)(object)list[num], (Collider)(object)list[num2]);
				}
			}
			Collider[] componentsInChildren = ((Component)this).gameObject.GetComponentsInChildren<Collider>();
			foreach (CapsuleCollider item in list)
			{
				Collider[] array5 = componentsInChildren;
				foreach (Collider val5 in array5)
				{
					Physics.IgnoreCollision((Collider)(object)item, val5);
				}
			}
			HumanBodyBones[] array6 = array2;
			foreach (HumanBodyBones val6 in array6)
			{
				if ((int)val6 == 0)
				{
					continue;
				}
				Transform boneTransform3 = smolAnim.GetBoneTransform(val6);
				if (!((Object)(object)boneTransform3 == (Object)null) && dictionary.TryGetValue(val6, out var _))
				{
					CharacterJoint val7 = ((Component)boneTransform3).gameObject.AddComponent<CharacterJoint>();
					Rigidbody val8 = null;
					Transform parent = boneTransform3.parent;
					while ((Object)(object)parent != (Object)null && (Object)(object)val8 == (Object)null)
					{
						val8 = ((Component)parent).GetComponent<Rigidbody>();
						parent = parent.parent;
					}
					if ((Object)(object)val8 != (Object)null)
					{
						((Joint)val7).connectedBody = val8;
					}
					SoftJointLimit val9 = default(SoftJointLimit);
					((SoftJointLimit)(ref val9)).limit = 30f;
					SoftJointLimit val10 = val9;
					val9 = default(SoftJointLimit);
					((SoftJointLimit)(ref val9)).limit = -30f;
					SoftJointLimit lowTwistLimit = val9;
					val7.highTwistLimit = val10;
					val7.lowTwistLimit = lowTwistLimit;
					val7.swing1Limit = val10;
					val7.swing2Limit = val10;
					val7.enableProjection = true;
					val7.projectionDistance = 0.01f;
					val7.projectionAngle = 5f;
				}
			}
			if (dictionary.TryGetValue((HumanBodyBones)0, out var value2))
			{
				Rigidbody val11 = ((Component)deathHead).GetComponent<Rigidbody>() ?? ((Component)deathHead).GetComponentInChildren<Rigidbody>();
				if ((Object)(object)val11 != (Object)null)
				{
					ConfigurableJoint val12 = ((Component)value2).gameObject.AddComponent<ConfigurableJoint>();
					((Joint)val12).autoConfigureConnectedAnchor = false;
					((Joint)val12).axis = Vector3.right;
					val12.secondaryAxis = Vector3.up;
					((Joint)val12).anchor = Vector3.zero;
					((Joint)val12).connectedAnchor = Vector3.zero;
					((Joint)val12).connectedBody = val11;
					val12.xMotion = (ConfigurableJointMotion)0;
					val12.yMotion = (ConfigurableJointMotion)0;
					val12.zMotion = (ConfigurableJointMotion)0;
					val12.angularXMotion = (ConfigurableJointMotion)2;
					val12.angularYMotion = (ConfigurableJointMotion)2;
					val12.angularZMotion = (ConfigurableJointMotion)2;
					Vector3 val13 = Vector3.ClampMagnitude(val11.velocity * 0.3f, 3f);
					value2.AddForce(val13, (ForceMode)2);
					value2.AddTorque(Random.insideUnitSphere * 0.5f, (ForceMode)2);
				}
			}
		}
		else
		{
			Rigidbody val14 = ((Component)this).gameObject.AddComponent<Rigidbody>();
			val14.mass = 0.5f;
			val14.drag = 2f;
			val14.angularDrag = 4f;
			Rigidbody val15 = Traverse.Create((object)deathHead).Field("physGrabObject").GetValue<PhysGrabObject>()?.rb;
			if ((Object)(object)val15 != (Object)null)
			{
				Vector3 val16 = Vector3.ClampMagnitude(val15.velocity * 0.3f, 3f);
				val14.AddForce(val16, (ForceMode)2);
			}
		}
	}

	public void Reset()
	{
		_ragdollActivated = false;
		_spectateActivated = false;
		_idleActivated = false;
		_wasCharging = false;
		_fallbackTimer = -1f;
		CancelFreezeCoroutine();
		if ((Object)(object)animator != (Object)null)
		{
			animator.speed = 1f;
			animator.runtimeAnimatorController = null;
			((Behaviour)animator).enabled = false;
		}
	}

	public void StartFallbackTimer()
	{
		_fallbackTimer = 0.1f;
	}
}
namespace UmamusumeSemiBots;

public class DynEmissionStepper : MonoBehaviour
{
	private const string TargetMaterialName = "UmaEmission";

	private const float StepInterval = 3f;

	private static readonly float[] OffsetSteps = new float[4] { 0f, 0.07f, 0.14f, 0.21f };

	private Material _mat;

	private int _stepIndex = 0;

	private void Start()
	{
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		SkinnedMeshRenderer component = ((Component)this).GetComponent<SkinnedMeshRenderer>();
		if ((Object)(object)component == (Object)null)
		{
			((Behaviour)this).enabled = false;
			return;
		}
		Material[] materials = ((Renderer)component).materials;
		for (int i = 0; i < materials.Length; i++)
		{
			if ((Object)(object)materials[i] != (Object)null && ((Object)materials[i]).name.StartsWith("UmaEmission"))
			{
				_mat = materials[i];
				break;
			}
		}
		if ((Object)(object)_mat == (Object)null)
		{
			((Behaviour)this).enabled = false;
			return;
		}
		_mat.SetVector("_DynEmissionScrollDir", Vector4.zero);
		_mat.SetFloat("_DynEmissionScrollSpeed", 0f);
		ApplyCurrentStep();
		((MonoBehaviour)this).StartCoroutine(StepCoroutine());
	}

	private IEnumerator StepCoroutine()
	{
		while (true)
		{
			yield return (object)new WaitForSeconds(3f);
			_stepIndex = (_stepIndex + 1) % OffsetSteps.Length;
			ApplyCurrentStep();
		}
	}

	private void ApplyCurrentStep()
	{
		//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_002e: 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)
		Vector2 textureScale = _mat.GetTextureScale("_DynEmissionTex");
		_mat.SetTextureOffset("_DynEmissionTex", new Vector2(OffsetSteps[_stepIndex], 0f));
		_mat.SetTextureScale("_DynEmissionTex", textureScale);
	}

	private void OnDestroy()
	{
		if ((Object)(object)_mat != (Object)null)
		{
			Object.Destroy((Object)(object)_mat);
		}
	}
}
internal static class UmasTabState
{
	internal static bool IsUmasTabActive;

	internal static GameObject UmasSectionRoot;

	internal static GameObject UmasTabButton;

	internal static MenuPageCosmetics LastBuiltFor;

	internal static GameObject CachedCosmeticButtonTemplate;
}
[HarmonyPatch(typeof(MenuPageCosmetics))]
internal class MenuPageCosmeticsPatch
{
	internal static bool IsBuildingUmasGrid;

	[HarmonyPatch("AnimateSubCategories")]
	[HarmonyPostfix]
	public static void Start_Postfix(MenuPageCosmetics __instance)
	{
		if ((Object)(object)UmasTabState.CachedCosmeticButtonTemplate == (Object)null)
		{
			((MonoBehaviour)__instance).StartCoroutine(CacheButtonTemplateNextFrame(__instance));
		}
		InjectUmasTabButton(__instance);
		((MonoBehaviour)__instance).StartCoroutine(AutoOpenUmasTabNextFrame(__instance));
	}

	private static IEnumerator AutoOpenUmasTabNextFrame(MenuPageCosmetics page)
	{
		yield return null;
		yield return null;
		yield return null;
		yield return null;
		yield return null;
		yield return null;
		yield return null;
		if (UmasTabState.IsUmasTabActive)
		{
			yield break;
		}
		OnUmasTabClicked(page);
		yield return null;
		yield return null;
		MenuPage menuPage = ((Component)page).GetComponent<MenuPage>();
		if ((Object)(object)UmasTabState.UmasSectionRoot != (Object)null)
		{
			MenuButton[] componentsInChildren = UmasTabState.UmasSectionRoot.GetComponentsInChildren<MenuButton>(true);
			foreach (MenuButton mb in componentsInChildren)
			{
				Traverse.Create((object)mb).Field("parentPage").SetValue((object)menuPage);
			}
		}
	}

	[HarmonyPatch("RefreshScrollContent")]
	[HarmonyPrefix]
	public static bool RefreshScrollContent_Prefix(MenuPageCosmetics __instance)
	{
		if (UmasTabState.IsUmasTabActive && (Object)(object)UmasTabState.LastBuiltFor == (Object)(object)__instance)
		{
			return false;
		}
		CosmeticCategoryAsset value = Traverse.Create((object)__instance).Field<CosmeticCategoryAsset>("selectedCategory").Value;
		if ((Object)(object)value == (Object)null)
		{
			return false;
		}
		return true;
	}

	[HarmonyPatch("RefreshScrollContent")]
	[HarmonyPostfix]
	public static void RefreshScrollContent_Postfix(MenuPageCosmetics __instance)
	{
		UpdateUmasTabButtonAppearance(__instance);
		if (UmasTabState.IsUmasTabActive && !((Object)(object)UmasTabState.LastBuiltFor != (Object)(object)__instance))
		{
			((MonoBehaviour)__instance).StartCoroutine(BuildUmasGridNextFrame(__instance));
		}
	}

	private static IEnumerator CacheButtonTemplateNextFrame(MenuPageCosmetics page)
	{
		yield return null;
		if ((Object)(object)UmasTabState.CachedCosmeticButtonTemplate != (Object)null)
		{
			yield break;
		}
		Transform scrollerTf = (Transform)(object)page.menuScrollBox?.scroller;
		if ((Object)(object)scrollerTf == (Object)null)
		{
			yield break;
		}
		int sectionCount = 0;
		foreach (Transform item in scrollerTf)
		{
			Transform child = item;
			if (!((Object)child).name.StartsWith("Menu Element Cosmetic Section"))
			{
				continue;
			}
			sectionCount++;
			if (sectionCount != 3)
			{
				continue;
			}
			Transform obj = child.Find("Cosmetic List/Menu Element Cosmetic Button");
			GameObject found = ((obj != null) ? ((Component)obj).gameObject : null);
			if (!((Object)(object)found == (Object)null))
			{
				UmasTabState.CachedCosmeticButtonTemplate = Object.Instantiate<GameObject>(found);
				((Object)UmasTabState.CachedCosmeticButtonTemplate).name = "UmasCachedNoneTemplate";
				Object.DontDestroyOnLoad((Object)(object)UmasTabState.CachedCosmeticButtonTemplate);
				UmasTabState.CachedCosmeticButtonTemplate.SetActive(false);
			}
			break;
		}
	}

	private static void CreateNoneButton(MenuPageCosmetics page, Transform parent, GameObject _template)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected O, but got Unknown
		//IL_0039: 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_0065: 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_00b9: 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_00df: Expected O, but got Unknown
		//IL_00fe: 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_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Expected O, but got Unknown
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: 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_0226: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_0256: Unknown result type (might be due to invalid IL or missing references)
		//IL_0263: 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_02a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b3: Expected O, but got Unknown
		//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0339: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("UmaBtn_None");
		val.transform.SetParent(parent, false);
		RectTransform val2 = val.AddComponent<RectTransform>();
		val2.pivot = new Vector2(0f, 0f);
		val2.anchorMin = new Vector2(0f, 0f);
		val2.anchorMax = new Vector2(0f, 0f);
		Image val3 = val.AddComponent<Image>();
		((Graphic)val3).color = new Color(0.1f, 0.1f, 0.1f, 1f);
		((Graphic)val3).raycastTarget = true;
		Image val4 = CreateBorder(val, 2f, new Color(0.0157f, 0.2863f, 0.7451f, 1f));
		((Component)val4).gameObject.SetActive(false);
		GameObject val5 = new GameObject("_tmp");
		val5.transform.SetParent(val.transform, false);
		RectTransform val6 = val5.AddComponent<RectTransform>();
		val6.anchorMin = Vector2.zero;
		val6.anchorMax = Vector2.one;
		Vector2 offsetMin = (val6.offsetMax = Vector2.zero);
		val6.offsetMin = offsetMin;
		TextMeshProUGUI val7 = val5.AddComponent<TextMeshProUGUI>();
		((TMP_Text)val7).text = " ";
		((Graphic)val7).color = Color.clear;
		((Graphic)val7).raycastTarget = false;
		((TMP_Text)val7).enableAutoSizing = false;
		((TMP_Text)val7).fontSize = 1f;
		GameObject val8 = new GameObject("NoneLabel");
		val8.transform.SetParent(val.transform, false);
		RectTransform val9 = val8.AddComponent<RectTransform>();
		val9.anchorMin = Vector2.zero;
		val9.anchorMax = Vector2.one;
		offsetMin = (val9.offsetMax = Vector2.zero);
		val9.offsetMin = offsetMin;
		TextMeshProUGUI val10 = val8.AddComponent<TextMeshProUGUI>();
		((TMP_Text)val10).text = "None";
		((TMP_Text)val10).fontSize = 12f;
		((Graphic)val10).color = Color.white;
		((TMP_Text)val10).alignment = (TextAlignmentOptions)514;
		((Graphic)val10).raycastTarget = false;
		Button val11 = val.AddComponent<Button>();
		((Selectable)val11).targetGraphic = (Graphic)(object)val3;
		ColorBlock defaultColorBlock = ColorBlock.defaultColorBlock;
		((ColorBlock)(ref defaultColorBlock)).normalColor = Color.white;
		((ColorBlock)(ref defaultColorBlock)).highlightedColor = Color.white;
		((ColorBlock)(ref defaultColorBlock)).pressedColor = Color.white;
		((ColorBlock)(ref defaultColorBlock)).selectedColor = Color.white;
		((ColorBlock)(ref defaultColorBlock)).disabledColor = Color.white;
		((ColorBlock)(ref defaultColorBlock)).colorMultiplier = 1f;
		((ColorBlock)(ref defaultColorBlock)).fadeDuration = 0f;
		((Selectable)val11).colors = defaultColorBlock;
		((Selectable)val11).transition = (Transition)0;
		((UnityEvent)val11.onClick).AddListener((UnityAction)delegate
		{
			OnNoneButtonClicked(page);
		});
		MenuSelectableElement val12 = val.AddComponent<MenuSelectableElement>();
		MenuButton val13 = val.AddComponent<MenuButton>();
		val13.customColors = true;
		val13.colorNormal = Color.white;
		val13.colorHover = new Color(0.2f, 0.8f, 1f, 1f);
		val13.colorClick = Color.yellow;
		val13.doButtonEffect = true;
		val13.doHoverEffect = true;
		val13.resizeButton = false;
		val13.rectTransformSelection = val2;
		((Graphic)val3).color = new Color(0.1f, 0.1f, 0.1f, 1f);
		UmaNoneButton umaNoneButton = val.AddComponent<UmaNoneButton>();
		umaNoneButton.borderImage = val4;
	}

	private static void OnNoneButtonClicked(MenuPageCosmetics page)
	{
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Expected O, but got Unknown
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Expected O, but got Unknown
		ModdedModelPlayerAvatar.LocalModelID = -1;
		PlayerAvatar instance = PlayerAvatar.instance;
		ModdedModelPlayerAvatar moddedModelPlayerAvatar = ((instance != null) ? ((Component)instance).GetComponent<ModdedModelPlayerAvatar>() : null);
		if ((Object)(object)moddedModelPlayerAvatar != (Object)null)
		{
			moddedModelPlayerAvatar.currentModelID = -1;
			if (!GameManager.Multiplayer())
			{
				moddedModelPlayerAvatar.ModdedSetModelRPC(-1);
			}
			else
			{
				PlayerAvatar.instance.photonView.RPC("ModdedSetModelRPC", (RpcTarget)0, new object[1] { -1 });
			}
			moddedModelPlayerAvatar.ClearMenuModel();
			try
			{
				ES3Settings val = new ES3Settings("ModSettingsData.es3", (ES3Settings)null);
				ES3.Save<int>("PlayerModelID", -1, val);
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[ModelSwap] Failed to save None model ID: " + ex.Message));
			}
		}
		if ((Object)(object)UmasTabState.UmasSectionRoot != (Object)null)
		{
			UmaThumbnailButton[] componentsInChildren = UmasTabState.UmasSectionRoot.GetComponentsInChildren<UmaThumbnailButton>(true);
			foreach (UmaThumbnailButton umaThumbnailButton in componentsInChildren)
			{
				umaThumbnailButton.RefreshBorder();
				umaThumbnailButton.RefreshThumbnail();
			}
			UmaNoneButton[] componentsInChildren2 = UmasTabState.UmasSectionRoot.GetComponentsInChildren<UmaNoneButton>(true);
			foreach (UmaNoneButton umaNoneButton in componentsInChildren2)
			{
				umaNoneButton.RefreshBorder();
			}
		}
		Transform val2 = ((Component)page).transform.Find("UmasNamePanel");
		if ((Object)(object)val2 != (Object)null)
		{
			TextMeshProUGUI componentInChildren = ((Component)val2).GetComponentInChildren<TextMeshProUGUI>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				((TMP_Text)componentInChildren).text = "";
			}
		}
		Transform val3 = ((Component)page).transform.Find("UmasGrowthPanel");
		if ((Object)(object)val3 != (Object)null)
		{
			foreach (Transform item in val3)
			{
				Transform val4 = item;
				Object.Destroy((Object)(object)((Component)val4).gameObject);
			}
		}
		Transform obj = ((Component)page).transform.Find("UmaOutfitArrow_Left");
		if (obj != null)
		{
			((Component)obj).gameObject.SetActive(false);
		}
		Transform obj2 = ((Component)page).transform.Find("UmaOutfitArrow_Right");
		if (obj2 != null)
		{
			((Component)obj2).gameObject.SetActive(false);
		}
		RefreshLocalPlayerHead();
	}

	internal static void PopulateInfoPanelGrowthRates(MenuPageCosmetics page, Transform parent, int modelID)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Expected O, but got Unknown
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Expected O, but got Unknown
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Expected O, but got Unknown
		//IL_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0282: Unknown result type (might be due to invalid IL or missing references)
		foreach (Transform item in parent)
		{
			Transform val = item;
			Object.Destroy((Object)(object)((Component)val).gameObject);
		}
		if (!CustomModelSwapMod.GrowthRatesEnabled.Value)
		{
			return;
		}
		int num = ((modelID >= 0) ? CustomModelSwapMod.SlotToFlatIndex(modelID) : (-1));
		if (num < 0 || num >= CustomModelSwapMod.ModelNames.Count)
		{
			return;
		}
		string key = CustomModelSwapMod.ModelNames[num] ?? "";
		if (!UmaGrowthRateData.UmaGrowthRateTable.TryGetValue(key, out var value))
		{
			return;
		}
		string[] array = new string[5] { "icon_speed", "icon_stamina", "icon_power", "icon_guts", "icon_wits" };
		int[] array2 = new int[5] { value.Speed, value.Stamina, value.Power, value.Guts, value.Wit };
		for (int i = 0; i < array.Length; i++)
		{
			GameObject val2 = new GameObject($"GR_Icon_{i}");
			val2.transform.SetParent(parent, false);
			val2.AddComponent<RectTransform>().sizeDelta = new Vector2(14f, 14f);
			Image val3 = val2.AddComponent<Image>();
			((Graphic)val3).color = new Color(0.8f, 0.8f, 0.8f, 1f);
			if (CustomModelSwapMod.StatIcons.TryGetValue(array[i], out var value2))
			{
				val3.sprite = value2;
			}
			LayoutElement val4 = val2.AddComponent<LayoutElement>();
			float minWidth = (val4.preferredWidth = 14f);
			val4.minWidth = minWidth;
			minWidth = (val4.preferredHeight = 14f);
			val4.minHeight = minWidth;
			GameObject val5 = new GameObject($"GR_Label_{i}");
			val5.transform.SetParent(parent, false);
			val5.AddComponent<RectTransform>().sizeDelta = new Vector2(30f, 14f);
			TextMeshProUGUI val6 = val5.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val6).text = $"+{array2[i]}%";
			((TMP_Text)val6).fontSize = 11f;
			((Graphic)val6).color = new Color(0.8f, 0.8f, 0.8f, 1f);
			((TMP_Text)val6).alignment = (TextAlignmentOptions)514;
			TryAssignFont(page, val6);
			LayoutElement val7 = val5.AddComponent<LayoutElement>();
			minWidth = (val7.preferredWidth = 18f);
			val7.minWidth = minWidth;
		}
	}

	private static void InjectUmasTabButton(MenuPageCosmetics page)
	{
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Expected O, but got Unknown
		if ((Object)(object)page?.categoriesTransform == (Object)null || ((Object)(object)UmasTabState.UmasTabButton != (Object)null && UmasTabState.UmasTabButton.transform.IsChildOf(page.categoriesTransform)))
		{
			return;
		}
		MenuElementButtonCosmeticCategory componentInChildren = ((Component)page.categoriesTransform).GetComponentInChildren<MenuElementButtonCosmeticCategory>(true);
		if (!((Object)(object)componentInChildren == (Object)null))
		{
			GameObject val = Object.Instantiate<GameObject>(((Component)componentInChildren).gameObject, page.categoriesTransform);
			((Object)val).name = "Umas Tab Button";
			val.transform.SetAsFirstSibling();
			MenuElementButtonCosmeticCategory component = val.GetComponent<MenuElementButtonCosmeticCategory>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component);
			}
			MenuElementCosmeticHighlight componentInChildren2 = val.GetComponentInChildren<MenuElementCosmeticHighlight>(true);
			if ((Object)(object)componentInChildren2 != (Object)null)
			{
				((Component)componentInChildren2).gameObject.SetActive(false);
			}
			TextMeshProUGUI[] componentsInChildren = val.GetComponentsInChildren<TextMeshProUGUI>(true);
			foreach (TextMeshProUGUI val2 in componentsInChildren)
			{
				((TMP_Text)val2).text = "UMAS";
				((TMP_Text)val2).fontSize = 20f;
			}
			Button val3 = val.GetComponent<Button>();
			if ((Object)(object)val3 == (Object)null)
			{
				val3 = val.AddComponent<Button>();
			}
			((UnityEventBase)val3.onClick).RemoveAllListeners();
			((UnityEvent)val3.onClick).AddListener((UnityAction)delegate
			{
				OnUmasTabClicked(page);
			});
			UmasTabState.UmasTabButton = val;
			UmasTabState.LastBuiltFor = page;
			page.categoriesHolder.UpdateButtons();
			((MonoBehaviour)page).StartCoroutine(ForceUmasTabText());
		}
	}

	private static IEnumerator ForceUmasTabText()
	{
		yield return null;
		if (!((Object)(object)UmasTabState.UmasTabButton == (Object)null))
		{
			TextMeshProUGUI[] componentsInChildren = UmasTabState.UmasTabButton.GetComponentsInChildren<TextMeshProUGUI>(true);
			foreach (TextMeshProUGUI tmp in componentsInChildren)
			{
				((TMP_Text)tmp).text = "UMAS";
				((TMP_Text)tmp).fontSize = 20f;
			}
		}
	}

	private static void RefreshInfoPanel(MenuPageCosmetics page)
	{
		Transform val = ((Component)page).transform.Find("UmasNamePanel");
		if ((Object)(object)val != (Object)null)
		{
			TextMeshProUGUI componentInChildren = ((Component)val).GetComponentInChildren<TextMeshProUGUI>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				((TMP_Text)componentInChildren).text = GetModelDisplayName(ModdedModelPlayerAvatar.LocalModelID);
			}
		}
		Transform val2 = ((Component)page).transform.Find("UmasGrowthPanel");
		if ((Object)(object)val2 != (Object)null)
		{
			PopulateInfoPanelGrowthRates(page, ((Component)val2).transform, ModdedModelPlayerAvatar.LocalModelID);
		}
	}

	internal static void OnUmasTabClicked(MenuPageCosmetics page)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		if (UmasTabState.IsUmasTabActive)
		{
			return;
		}
		UmasTabState.IsUmasTabActive = true;
		UmasTabState.LastBuiltFor = page;
		page.selectedTab = (CosmeticPageTab)1;
		Transform val = (Transform)(object)page.menuScrollBox?.scroller;
		if ((Object)(object)val != (Object)null)
		{
			foreach (Transform item in ((IEnumerable)val).Cast<Transform>().ToList())
			{
				Object.Destroy((Object)(object)((Component)item).gameObject);
			}
		}
		UpdateUmasTabButtonAppearance(page);
		RefreshUmasHeaderDisplay(page);
		((MonoBehaviour)page).StartCoroutine(BuildUmasGridNextFrame(page));
		RefreshInfoPanel(page);
	}

	public static void SafeDestroyUmasSectionRoot()
	{
		if ((Object)(object)UmasTabState.UmasSectionRoot == (Object)null)
		{
			return;
		}
		if ((Object)(object)MenuManager.instance != (Object)null)
		{
			List<MenuButton> value = Traverse.Create((object)MenuManager.instance).Field<List<MenuButton>>("allMenuButtons").Value;
			if (value != null)
			{
				HashSet<MenuButton> umasButtons = new HashSet<MenuButton>(UmasTabState.UmasSectionRoot.GetComponentsInChildren<MenuButton>(true));
				value.RemoveAll(delegate(MenuButton mb)
				{
					if ((Object)(object)mb == (Object)null)
					{
						return true;
					}
					return (Object)(object)mb == (Object)null || umasButtons.Contains(mb);
				});
			}
		}
		if ((Object)(object)UmasTabState.LastBuiltFor != (Object)null)
		{
			DestroyChild(((Component)UmasTabState.LastBuiltFor).transform, "UmasSelectBanner");
		}
		Object.DestroyImmediate((Object)(object)UmasTabState.UmasSectionRoot);
		UmasTabState.UmasSectionRoot = null;
	}

	private static IEnumerator BuildUmasGridNextFrame(MenuPageCosmetics page)
	{
		IsBuildingUmasGrid = true;
		yield return null;
		yield return null;
		if (!UmasTabState.IsUmasTabActive || (Object)(object)page == (Object)null)
		{
			yield break;
		}
		SafeDestroyUmasSectionRoot();
		yield return null;
		try
		{
			MenuManager menuMgr = MenuManager.instance;
			if ((Object)(object)menuMgr != (Object)null)
			{
				Traverse obj = Traverse.Create((object)menuMgr).Field("currentHoverButton");
				if (obj != null)
				{
					obj.SetValue((object)null);
				}
				Traverse obj2 = Traverse.Create((object)menuMgr).Field("currentSelectedButton");
				if (obj2 != null)
				{
					obj2.SetValue((object)null);
				}
			}
		}
		catch
		{
		}
		GameObject sectionGO = Object.Instantiate<GameObject>(page.sectionPrefab, page.sectionRootTransform);
		MenuElementCosmeticSection sectionComp = sectionGO.GetComponent<MenuElementCosmeticSection>();
		if ((Object)(object)sectionComp != (Object)null)
		{
			Traverse.Create((object)sectionComp).Field("menuPageCosmetics").SetValue((object)page);
		}
		sectionGO.transform.localPosition = new Vector3(sectionGO.transform.localPosition.x, 0f, sectionGO.transform.localPosition.z);
		UmasTabState.UmasSectionRoot = sectionGO;
		MenuElementCosmeticSection section = sectionGO.GetComponent<MenuElementCosmeticSection>();
		CanvasGroup headerCG = Traverse.Create((object)section).Field<CanvasGroup>("headerCanvasGroup").Value;
		if ((Object)(object)headerCG != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)headerCG).gameObject);
		}
		else
		{
			TextMeshProUGUI headerText = section.headerText;
			Transform headerParent = ((headerText != null) ? ((TMP_Text)headerText).transform.parent : null);
			if ((Object)(object)headerParent != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)headerParent).gameObject);
			}
		}
		GameObject gridGO = new GameObject("UmasGrid");
		gridGO.transform.SetParent(section.cosmeticListTransform, false);
		RectTransform gridRT = gridGO.AddComponent<RectTransform>();
		gridRT.anchorMin = new Vector2(0f, 1f);
		gridRT.anchorMax = new Vector2(1f, 1f);
		gridRT.pivot = new Vector2(0f, 1f);
		gridRT.anchoredPosition = Vector2.zero;
		GridLayoutGroup grid = gridGO.AddComponent<GridLayoutGroup>();
		grid.startCorner = (Corner)0;
		grid.startAxis = (Axis)0;
		((LayoutGroup)grid).childAlignment = (TextAnchor)0;
		grid.cellSize = new Vector2(70f, 70f);
		grid.spacing = new Vector2(4f, 4f);
		grid.constraintCount = 6;
		grid.constraint = (Constraint)1;
		((LayoutGroup)grid).padding = new RectOffset(8, 8, 8, 8);
		ContentSizeFitter gridFitter = gridGO.AddComponent<ContentSizeFitter>();
		gridFitter.horizontalFit = (FitMode)0;
		gridFitter.verticalFit = (FitMode)2;
		for (int s = 0; s < CustomModelSwapMod.ModelOutfitGroups.Count; s++)
		{
			CreateUmaThumbnailButton(page, gridGO.transform, s);
		}
		yield return null;
		MenuPage pageComp = ((Component)page).GetComponent<MenuPage>();
		MenuButton[] componentsInChildren = sectionGO.GetComponentsInChildren<MenuButton>(true);
		foreach (MenuButton mb in componentsInChildren)
		{
			Traverse.Create((object)mb).Field("parentPage").SetValue((object)pageComp);
		}
		LayoutRebuilder.ForceRebuildLayoutImmediate(gridRT);
		Rect rect = gridRT.rect;
		float totalH = ((Rect)(ref rect)).height + 16f;
		Transform cosmeticListTransform = section.cosmeticListTransform;
		RectTransform listRT = ((cosmeticListTransform != null) ? ((Component)cosmeticListTransform).GetComponent<RectTransform>() : null);
		RectTransform sectionRT = sectionGO.GetComponent<RectTransform>();
		if ((Object)(object)listRT != (Object)null)
		{
			listRT.sizeDelta = new Vector2(listRT.sizeDelta.x, totalH);
			LayoutRebuilder.ForceRebuildLayoutImmediate(listRT);
		}
		if ((Object)(object)sectionRT != (Object)null)
		{
			sectionRT.sizeDelta = new Vector2(sectionRT.sizeDelta.x, totalH);
			LayoutRebuilder.ForceRebuildLayoutImmediate(sectionRT);
		}
		Traverse.Create((object)page).Field("subCategoriesReady").SetValue((object)false);
		yield return ((MonoBehaviour)page).StartCoroutine((IEnumerator)typeof(MenuPageCosmetics).GetMethod("RecalculateScrollHeightAfterFrame", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(page, null));
		UmaThumbnailButton[] componentsInChildren2 = sectionGO.GetComponentsInChildren<UmaThumbnailButton>(true);
		foreach (UmaThumbnailButton h in componentsInChildren2)
		{
			h.RefreshBorder();
		}
		UmaNoneButton[] componentsInChildren3 = sectionGO.GetComponentsInChildren<UmaNoneButton>(true);
		foreach (UmaNoneButton h2 in componentsInChildren3)
		{
			h2.RefreshBorder();
		}
		DestroyChild(((Component)page).transform, "UmasSelectBanner");
		TextMeshProUGUI fontSource = ((Component)page).GetComponentInChildren<TextMeshProUGUI>(true);
		GameObject banner = new GameObject("UmasSelectBanner");
		banner.transform.SetParent(((Component)page).transform, false);
		RectTransform bannerRT = banner.AddComponent<RectTransform>();
		bannerRT.anchorMin = new Vector2(0.5f, 1f);
		bannerRT.anchorMax = new Vector2(0.6f, 1f);
		bannerRT.pivot = new Vector2(0.5f, 1f);
		bannerRT.sizeDelta = new Vector2(400f, 40f);
		bannerRT.anchoredPosition = new Vector2(15f, -65f);
		TextMeshProUGUI bannerTMP = banner.AddComponent<TextMeshProUGUI>();
		((TMP_Text)bannerTMP).text = "SELECT UMAMUSUME";
		((TMP_Text)bannerTMP).fontSize = 42f;
		((TMP_Text)bannerTMP).fontStyle = (FontStyles)1;
		((Graphic)bannerTMP).color = new Color(1f, 0.4492f, 0f, 1f);
		((TMP_Text)bannerTMP).alignment = (TextAlignmentOptions)514;
		if ((Object)(object)fontSource != (Object)null)
		{
			((TMP_Text)bannerTMP).font = ((TMP_Text)fontSource).font;
		}
		RebuildOutfitArrows(page);
		MenuPage pageComp2 = ((Component)page).GetComponent<MenuPage>();
		string[] array = new string[2] { "UmaOutfitArrow_Left", "UmaOutfitArrow_Right" };
		foreach (string arrowName in array)
		{
			Transform arrowT = ((Component)page).transform.Find(arrowName);
			if (!((Object)(object)arrowT == (Object)null))
			{
				MenuButton[] componentsInChildren4 = ((Component)arrowT).GetComponentsInChildren<MenuButton>(true);
				foreach (MenuButton mb2 in componentsInChildren4)
				{
					Traverse.Create((object)mb2).Field("parentPage").SetValue((object)pageComp2);
				}
			}
		}
		UISafe.ForceRefreshMenuVisual();
		IsBuildingUmasGrid = false;
	}

	private static void CreateUmaThumbnailButton(MenuPageCosmetics page, Transform parent, int slotIdx)
	{
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Expected O, but got Unknown
		//IL_007c: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Expected O, but got Unknown
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: 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_0231: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_0242: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: 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_0290: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c0: Expected O, but got Unknown
		//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0304: 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)
		int value;
		int num = (CustomModelSwapMod.ColorToModel.TryGetValue(slotIdx, out value) ? value : slotIdx);
		if (num >= 0 && num < CustomModelSwapMod.Thumbnails.Count)
		{
			GameObject val = new GameObject($"UmaBtn_{slotIdx}");
			val.transform.SetParent(parent, false);
			RectTransform val2 = val.AddComponent<RectTransform>();
			val2.pivot = new Vector2(0f, 0f);
			val2.anchorMin = new Vector2(0f, 0f);
			val2.anchorMax = new Vector2(0f, 0f);
			Image val3 = val.AddComponent<Image>();
			Texture2D val4 = CustomModelSwapMod.Thumbnails[num];
			((Texture)val4).filterMode = (FilterMode)1;
			val3.sprite = Sprite.Create(val4, new Rect(0f, 0f, (float)((Texture)val4).width, (float)((Texture)val4).height), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0);
			((Graphic)val3).color = Color.white;
			val3.preserveAspect = false;
			val3.type = (Type)0;
			((Graphic)val3).raycastTarget = true;
			Image val5 = CreateBorder(val, 2f, new Color(0.0157f, 0.2863f, 0.7451f, 1f));
			((Component)val5).gameObject.SetActive(false);
			MenuSelectableElement val6 = val.AddComponent<MenuSelectableElement>();
			GameObject val7 = new GameObject("_tmp");
			val7.transform.SetParent(val.transform, false);
			RectTransform val8 = val7.AddComponent<RectTransform>();
			val8.anchorMin = Vector2.zero;
			val8.anchorMax = Vector2.one;
			Vector2 offsetMin = (val8.offsetMax = Vector2.zero);
			val8.offsetMin = offsetMin;
			TextMeshProUGUI val9 = val7.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val9).text = " ";
			((Graphic)val9).color = Color.clear;
			((Graphic)val9).raycastTarget = false;
			((TMP_Text)val9).enableAutoSizing = false;
			((TMP_Text)val9).fontSize = 1f;
			Button val10 = val.AddComponent<Button>();
			((Selectable)val10).targetGraphic = (Graphic)(object)val3;
			ColorBlock defaultColorBlock = ColorBlock.defaultColorBlock;
			((ColorBlock)(ref defaultColorBlock)).normalColor = Color.white;
			((ColorBlock)(ref defaultColorBlock)).highlightedColor = Color.white;
			((ColorBlock)(ref defaultColorBlock)).pressedColor = Color.white;
			((ColorBlock)(ref defaultColorBlock)).selectedColor = Color.white;
			((ColorBlock)(ref defaultColorBlock)).disabledColor = Color.white;
			((ColorBlock)(ref defaultColorBlock)).colorMultiplier = 1f;
			((ColorBlock)(ref defaultColorBlock)).fadeDuration = 0f;
			((Selectable)val10).colors = defaultColorBlock;
			((Selectable)val10).transition = (Transition)0;
			int captured = slotIdx;
			((UnityEvent)val10.onClick).AddListener((UnityAction)delegate
			{
				OnUmaThumbnailClicked(page, captured);
			});
			MenuButton val11 = val.AddComponent<MenuButton>();
			val11.customColors = true;
			val11.colorNormal = Color.white;
			val11.colorHover = new Color(0.2f, 0.8f, 1f, 1f);
			val11.colorClick = Color.yellow;
			val11.doButtonEffect = true;
			val11.doHoverEffect = true;
			val11.resizeButton = false;
			val11.rectTransformSelection = val2;
			((Graphic)val3).color = Color.white;
			UmaThumbnailButton umaThumbnailButton = val.AddComponent<UmaThumbnailButton>();
			umaThumbnailButton.slotIndex = slotIdx;
			umaThumbnailButton.borderImage = val5;
			umaThumbnailButton.pageRef = page;
		}
	}

	private static Image CreateBorder(GameObject parent, float thickness, Color color)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: 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_0067: 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_0093: 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_00ad: 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_00c8: 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_00e4: 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_0102: 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_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: 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_0147: 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_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("SelectionBorder");
		val.transform.SetParent(parent.transform, false);
		RectTransform val2 = val.AddComponent<RectTransform>();
		val2.pivot = new Vector2(0f, 0f);
		val2.anchorMin = Vector2.zero;
		val2.anchorMax = Vector2.one;
		val2.offsetMin = new Vector2(0f - thickness, 0f - thickness);
		val2.offsetMax = new Vector2(thickness, thickness);
		Image val3 = val.AddComponent<Image>();
		((Graphic)val3).color = Color.clear;
		((Graphic)val3).raycastTarget = false;
		CreateBorderLine(val.transform, color, new Vector2(0f, 1f), new Vector2(1f, 1f), new Vector2(0f, 0f - thickness), new Vector2(0f, 0f));
		CreateBorderLine(val.transform, color, new Vector2(0f, 0f), new Vector2(1f, 0f), new Vector2(0f, 0f), new Vector2(0f, thickness));
		CreateBorderLine(val.transform, color, new Vector2(0f, 0f), new Vector2(0f, 1f), new Vector2(0f, 0f), new Vector2(thickness, 0f));
		CreateBorderLine(val.transform, color, new Vector2(1f, 0f), new Vector2(1f, 1f), new Vector2(0f - thickness, 0f), new Vector2(0f, 0f));
		return val3;
	}

	private static void CreateBorderLine(Transform parent, Color color, Vector2 anchorMin, Vector2 anchorMax, Vector2 offsetMin, Vector2 offsetMax)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_0022: 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_0032: 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_004b: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("BorderLine");
		val.transform.SetParent(parent, false);
		RectTransform val2 = val.AddComponent<RectTransform>();
		val2.anchorMin = anchorMin;
		val2.anchorMax = anchorMax;
		val2.offsetMin = offsetMin;
		val2.offsetMax = offsetMax;
		Image val3 = val.AddComponent<Image>();
		((Graphic)val3).color = color;
		((Graphic)val3).raycastTarget = false;
	}

	private static void RebuildOutfitArrows(MenuPageCosmetics page)
	{
		//IL_00b9: 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_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)
		DestroyChild(((Component)page).transform, "UmaOutfitArrow_Left");
		DestroyChild(((Component)page).transform, "UmaOutfitArrow_Right");
		TMP_FontAsset pageFont = GetPageFont(page);
		Transform val = ((Component)page).transform.Find("UmasNamePanel");
		Vector2 anchoredPosition = default(Vector2);
		((Vector2)(ref anchoredPosition))..ctor(-265f, 52f);
		if ((Object)(object)val != (Object)null)
		{
			RectTransform component = ((Component)val).GetComponent<RectTransform>();
			if ((Object)(object)component != (Object)null)
			{
				anchoredPosition = component.anchoredPosition;
			}
		}
		CreateArrow(((Component)page).transform, "UmaOutfitArrow_Left", "◀", new Vector2(-342f, 207f), delegate
		{
			CycleOutfit(page, ModdedModelPlayerAvatar.LocalModelID, -1);
		}, pageFont);
		CreateArrow(((Component)page).transform, "UmaOutfitArrow_Right", "▶", new Vector2(-187f, 207f), delegate
		{
			CycleOutfit(page, ModdedModelPlayerAvatar.LocalModelID, 1);
		}, pageFont);
		int slotIndex = ((ModdedModelPlayerAvatar.LocalModelID >= 0) ? ModdedModelPlayerAvatar.LocalModelID : 0);
		UpdateArrowVisibility(page, slotIndex);
	}

	private static void CreateArrow(Transform parent, string goName, string label, Vector2 anchoredPos, Action onClick, TMP_FontAsset fontAsset)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Expected O, but got Unknown
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: 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_0106: 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_010f: 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_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Expected O, but got Unknown
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: 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_01ed: 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_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_0286: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_030e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0318: Expected O, but got Unknown
		//IL_0347: Unknown result type (might be due to invalid IL or missing references)
		//IL_034c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0367: Unknown result type (might be due to invalid IL or missing references)
		//IL_036c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0387: 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)
		GameObject val = new GameObject(goName);
		val.transform.SetParent(parent, false);
		RectTransform val2 = val.AddComponent<RectTransform>();
		val2.anchorMin = new Vector2(0.5f, 0f);
		val2.anchorMax = new Vector2(0.5f, 0f);
		val2.pivot = new Vector2(0.5f, 0.5f);
		val2.sizeDelta = new Vector2(60f, 60f);
		val2.anchoredPosition = anchoredPos;
		Image val3 = val.AddComponent<Image>();
		((Graphic)val3).color = new Color(0f, 0f, 0f, 0f);
		((Graphic)val3).raycastTarget = true;
		GameObject val4 = new GameObject("Label");
		val4.transform.SetParent(val.transform, false);
		RectTransform val5 = val4.AddComponent<RectTransform>();
		val5.anchorMin = Vector2.zero;
		val5.anchorMax = Vector2.one;
		Vector2 offsetMin = (val5.offsetMax = Vector2.zero);
		val5.offsetMin = offsetMin;
		TextMeshProUGUI val6 = val4.AddComponent<TextMeshProUGUI>();
		((TMP_Text)val6).text = label;
		((TMP_Text)val6).fontSize = 22f;
		((TMP_Text)val6).fontStyle = (FontStyles)1;
		((Graphic)val6).color = Color.white;
		((TMP_Text)val6).alignment = (TextAlignmentOptions)514;
		((Graphic)val6).raycastTarget = false;
		if ((Object)(object)fontAsset != (Object)null)
		{
			((TMP_Text)val6).font = fontAsset;
		}
		val5.anchoredPosition = new Vector2(val5.anchoredPosition.x, -15f);
		GameObject val7 = new GameObject("_tmp");
		val7.transform.SetParent(val.transform, false);
		RectTransform val8 = val7.AddComponent<RectTransform>();
		val8.anchorMin = Vector2.zero;
		val8.anchorMax = Vector2.one;
		offsetMin = (val8.offsetMax = Vector2.zero);
		val8.offsetMin = offsetMin;
		TextMeshProUGUI val9 = val7.AddComponent<TextMeshProUGUI>();
		((TMP_Text)val9).text = " ";
		((Graphic)val9).color = Color.clear;
		((Graphic)val9).raycastTarget = false;
		((TMP_Text)val9).enableAutoSizing = false;
		((TMP_Text)val9).fontSize = 1f;
		Button val10 = val.AddComponent<Button>();
		((Selectable)val10).targetGraphic = (Graphic)(object)val3;
		ColorBlock defaultColorBlock = ColorBlock.defaultColorBlock;
		((ColorBlock)(ref defaultColorBlock)).normalColor = new Color(0.5f, 0.5f, 0.5f, 1f);
		((ColorBlock)(ref defaultColorBlock)).highlightedColor = new Color(0.8f, 0.8f, 0.8f, 1f);
		((ColorBlock)(ref defaultColorBlock)).pressedColor = new Color(1f, 0.4492f, 0f, 1f);
		((ColorBlock)(ref defaultColorBlock)).selectedColor = new Color(0.8f, 0.8f, 0.8f, 1f);
		((ColorBlock)(ref defaultColorBlock)).colorMultiplier = 1f;
		((ColorBlock)(ref defaultColorBlock)).fadeDuration = 0.05f;
		((Selectable)val10).colors = defaultColorBlock;
		((Selectable)val10).transition = (Transition)1;
		((UnityEvent)val10.onClick).AddListener((UnityAction)delegate
		{
			onClick();
		});
		MenuSelectableElement val11 = val.AddComponent<MenuSelectableElement>();
		MenuButton val12 = val.AddComponent<MenuButton>();
		val12.customColors = true;
		val12.colorNormal = new Color(0.5f, 0.5f, 0.5f, 1f);
		val12.colorHover = new Color(0.8f, 0.8f, 0.8f, 1f);
		val12.colorClick = new Color(1f, 0.4492f, 0f, 1f);
		val12.doButtonEffect = true;
		val12.doHoverEffect = true;
		val12.resizeButton = false;
		val12.rectTransformSelection = val2;
	}

	private static void OnUmaThumbnailClicked(MenuPageCosmetics page, int slotIdx)
	{
		if (slotIdx < 0 || slotIdx >= CustomModelSwapMod.ModelOutfitGroups.Count)
		{
			return;
		}
		int value;
		int num = (CustomModelSwapMod.SlotOutfitSelection.TryGetValue(slotIdx, out value) ? value : 0);
		List<int> list = CustomModelSwapMod.ModelOutfitGroups[slotIdx];
		int num2 = ((num < list.Count) ? list[num] : list[0]);
		CustomModelSwapMod.SelectedSlotIndex = slotIdx;
		ModdedModelPlayerAvatar.LocalModelID = slotIdx;
		ModdedModelPlayerAvatar.LocalPlayerAvatarSetModel();
		if ((Object)(object)UmasTabState.UmasSectionRoot != (Object)null)
		{
			UmaThumbnailButton[] componentsInChildren = UmasTabState.UmasSectionRoot.GetComponentsInChildren<UmaThumbnailButton>(true);
			foreach (UmaThumbnailButton umaThumbnailButton in componentsInChildren)
			{
				umaThumbnailButton.RefreshBorder();
			}
			UmaNoneButton[] componentsInChildren2 = UmasTabState.UmasSectionRoot.GetComponentsInChildren<UmaNoneButton>(true);
			foreach (UmaNoneButton umaNoneButton in componentsInChildren2)
			{
				umaNoneButton.RefreshBorder();
			}
		}
		UpdateArrowVisibility(page, slotIdx);
		RefreshUmasHeaderDisplay(page);
		RefreshLocalPlayerHead();
		UISafe.ForceRefreshMenuVisual();
	}

	internal static void CycleOutfit(MenuPageCosmetics page, int slotIndex, int direction)
	{
		if (slotIndex < 0 || slotIndex >= CustomModelSwapMod.ModelOutfitGroups.Count)
		{
			return;
		}
		List<int> list = CustomModelSwapMod.ModelOutfitGroups[slotIndex];
		if (list.Count <= 1)
		{
			return;
		}
		int value;
		int num = (CustomModelSwapMod.SlotOutfitSelection.TryGetValue(slotIndex, out value) ? value : 0);
		int num2 = (num + direction + list.Count) % list.Count;
		CustomModelSwapMod.SlotOutfitSelection[slotIndex] = num2;
		CustomModelSwapMod.ColorToModel[slotIndex] = list[num2];
		ModdedModelPlayerAvatar.LocalModelID = slotIndex;
		ModdedModelPlayerAvatar.LocalPlayerAvatarSetModel();
		if ((Object)(object)UmasTabState.UmasSectionRoot != (Object)null)
		{
			UmaThumbnailButton[] componentsInChildren = UmasTabState.UmasSectionRoot.GetComponentsInChildren<UmaThumbnailButton>(true);
			foreach (UmaThumbnailButton umaThumbnailButton in componentsInChildren)
			{
				if (umaThumbnailButton.slotIndex == slotIndex)
				{
					umaThumbnailButton.RefreshThumbnail();
				}
				umaThumbnailButton.RefreshBorder();
			}
			UmaNoneButton[] componentsInChildren2 = UmasTabState.UmasSectionRoot.GetComponentsInChildren<UmaNoneButton>(true);
			foreach (UmaNoneButton umaNoneButton in componentsInChildren2)
			{
				umaNoneButton.RefreshBorder();
			}
		}
		UpdateArrowVisibility(page, slotIndex);
		RefreshUmasHeaderDisplay(page);
		RefreshLocalPlayerHead();
		RefreshInfoPanel(page);
	}

	private static void RefreshUmasHeaderDisplay(MenuPageCosmetics page)
	{
		Transform val = ((Component)page).transform.Find("UmasNamePanel");
		if ((Object)(object)val != (Object)null)
		{
			TextMeshProUGUI componentInChildren = ((Component)val).GetComponentInChildren<TextMeshProUGUI>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				((TMP_Text)componentInChildren).text = GetModelDisplayName(ModdedModelPlayerAvatar.LocalModelID);
			}
		}
		Transform val2 = ((Component)page).transform.Find("UmasGrowthPanel");
		if ((Object)(object)val2 != (Object)null)
		{
			PopulateInfoPanelGrowthRates(page, ((Component)val2).transform, ModdedModelPlayerAvatar.LocalModelID);
		}
	}

	private static void UpdateArrowVisibility(MenuPageCosmetics page, int slotIndex)
	{
		bool isUmasTabActive = UmasTabState.IsUmasTabActive;
		bool flag = slotIndex >= 0 && slotIndex < CustomModelSwapMod.ModelOutfitGroups.Count;
		bool flag2 = flag && CustomModelSwapMod.ModelOutfitGroups[slotIndex].Count > 1;
		bool active = isUmasTabActive && flag && flag2;
		Transform obj = ((Component)page).transform.Find("UmaOutfitArrow_Left");
		if (obj != null)
		{
			((Component)obj).gameObject.SetActive(active);
		}
		Transform obj2 = ((Component)page).transform.Find("UmaOutfitArrow_Right");
		if (obj2 != null)
		{
			((Component)obj2).gameObject.SetActive(active);
		}
	}

	private static void UpdateUmasTabButtonAppearance(MenuPageCosmetics page)
	{
		//IL_004e: 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_00fa: 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_00c1: 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_00a7: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)UmasTabState.UmasTabButton == (Object)null)
		{
			return;
		}
		Image component = UmasTabState.UmasTabButton.GetComponent<Image>();
		if ((Object)(object)component != (Object)null)
		{
			((Graphic)component).color = (Color)(UmasTabState.IsUmasTabActive ? Color.white : new Color(0.016f, 0.286f, 0.745f, 1f));
		}
		MenuButton component2 = UmasTabState.UmasTabButton.GetComponent<MenuButton>();
		if ((Object)(object)component2 != (Object)null)
		{
			TextMeshProUGUI value = Traverse.Create((object)component2).Field<TextMeshProUGUI>("buttonText").Value;
			if ((Object)(object)value != (Object)null)
			{
				((Graphic)value).color = (UmasTabState.IsUmasTabActive ? Color.black : Color.white);
			}
			component2.colorNormal = (UmasTabState.IsUmasTabActive ? Color.black : Color.white);
		}
		else
		{
			TextMeshProUGUI componentInChildren = UmasTabState.UmasTabButton.GetComponentInChildren<TextMeshProUGUI>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				((Graphic)componentInChildren).color = (UmasTabState.IsUmasTabActive ? Color.black : Color.white);
			}
		}
	}

	internal static void RefreshLocalPlayerHead()
	{
		foreach (MenuPlayerHead trackedHead in CustomModelSwapMod.MenuPlayerHeadPatch._trackedHeads)
		{
			CustomModelSwapMod.MenuPlayerHeadPatch.TrySpawnSmol(trackedHead);
		}
	}

	private static int GetSlotForPrefab(int prefabIndex)
	{
		for (int i = 0; i < CustomModelSwapMod.ModelOutfitGroups.Count; i++)
		{
			if (CustomModelSwapMod.ModelOutfitGroups[i].Contains(prefabIndex))
			{
				return i;
			}
		}
		return 0;
	}

	internal static string GetModelDisplayName(int slotID)
	{
		int num = ((slotID >= 0) ? CustomModelSwapMod.SlotToFlatIndex(slotID) : (-1));
		if (num < 0 || num >= CustomModelSwapMod.ModelNames.Count)
		{
			return "";
		}
		string input = CustomModelSwapMod.ModelNames[num];
		input = Regex.Replace(input, "Outfit\\d+$", "").TrimEnd(Array.Empty<char>());
		return AddSpacesBeforeCapitals(input);
	}

	private static string AddSpacesBeforeCapitals(string s)
	{
		if (string.IsNullOrEmpty(s))
		{
			return s;
		}
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.Append(s[0]);
		for (int i = 1; i < s.Length; i++)
		{
			if (char.IsUpper(s[i]) && !char.IsUpper(s[i - 1]))
			{
				stringBuilder.Append(' ');
			}
			stringBuilder.Append(s[i]);
		}
		return stringBuilder.ToString();
	}

	private static void TryAssignFont(MenuPageCosmetics page, TextMeshProUGUI t)
	{
		TextMeshProUGUI componentInChildren = ((Component)page).GetComponentInChildren<TextMeshProUGUI>(true);
		if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren != (Object)(object)t)
		{
			((TMP_Text)t).font = ((TMP_Text)componentInChildren).font;
		}
	}

	private static TMP_FontAsset GetPageFont(MenuPageCosmetics page)
	{
		TextMeshProUGUI componentInChildren = ((Component)page).GetComponentInChildren<TextMeshProUGUI>(true);
		return (componentInChildren != null) ? ((TMP_Text)componentInChildren).font : null;
	}

	private static void DestroyChild(Transform parent, string name)
	{
		Transform val = parent.Find(name);
		if ((Object)(object)val != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)val).gameObject);
		}
	}
}
[HarmonyPatch(typeof(MenuButton), "ButtonNormal")]
internal class MenuButtonNormalPatch
{
	[HarmonyPrefix]
	public static bool Prefix(MenuButton __instance)
	{
		TextMeshProUGUI value = Traverse.Create((object)__instance).Field<TextMeshProUGUI>("buttonText").Value;
		if ((Object)(object)value == (Object)null || (Object)(object)((TMP_Text)value).transform == (Object)null)
		{
			return false;
		}
		return true;
	}
}
[HarmonyPatch(typeof(MenuButton), "ButtonNormal")]
internal class MenuButtonNormalHoverClearPatch
{
	[HarmonyPostfix]
	public static void Postfix(MenuButton __instance)
	{
		UmaThumbnailButton umaThumbnailButton = ((__instance != null) ? ((Component)__instance).GetComponent<UmaThumbnailButton>() : null);
		if ((Object)(object)umaThumbnailButton != (Object)null)
		{
			umaThumbnailButton.SetHovered(hovered: false);
		}
	}
}
[HarmonyPatch(typeof(MenuButton), "OnHovering")]
internal class MenuButtonOnHoveringPatch
{
	[HarmonyPrefix]
	public static bool Prefix(MenuButton __instance)
	{
		if ((Object)(object)__instance == (Object)null)
		{
			return false;
		}
		UmaThumbnailButton component = ((Component)__instance).GetComponent<UmaThumbnailButton>();
		if ((Object)(object)component != (Object)null)
		{
			component.SetHovered(hovered: true);
			return false;
		}
		if ((Object)(object)((Component)__instance).GetComponent<UmaNoneButton>() != (Object)null)
		{
			return false;
		}
		return true;
	}
}
[HarmonyPatch(typeof(MenuElementCosmeticSection), "UpdateColorButton")]
internal class MenuElementCosmeticSectionColorButtonPatch
{
	[HarmonyPrefix]
	public static bool Prefix(MenuElementCosmeticSection __instance)
	{
		return false;
	}
}
[HarmonyPatch(typeof(MenuElementCosmeticSection), "Start")]
internal class MenuElementCosmeticSectionStartPatch
{
	[HarmonyPrefix]
	public static bool Prefix(MenuElementCosmeticSection __instance)
	{
		MenuPageCosmetics value = Traverse.Create((object)__instance).Field("menuPageCosmetics").GetValue<MenuPageCosmetics>();
		return (Object)(object)value != (Object)null;
	}
}
[HarmonyPatch(typeof(PlayerCrown), "Update")]
internal class PlayerCrownPatch
{
	[HarmonyPostfix]
	public static void Postfix(PlayerCrown __instance)
	{
		((Renderer)((Component)__instance.crownMesh).GetComponent<MeshRenderer>()).enabled = false;
	}
}
[HarmonyPatch(typeof(SemiFunc), "MenuSelectionBoxTargetSet")]
internal class MenuSelectionBoxTargetSetPatch
{
	[HarmonyPrefix]
	public static bool Prefix(MenuPage parentPage, RectTransform rectTransform, Vector2 customOffset, Vector2 customScale)
	{
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: 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_0217: Unknown result type (might be due to invalid IL or missing references)
		//IL_0218: Unknown result type (might be due to invalid IL or missing references)
		//IL_021d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0222: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0255: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if ((Object)(object)parentPage == (Object)null)
			{
				return false;
			}
			if ((Object)(object)rectTransform == (Object)null)
			{
				return false;
			}
			if ((Object)(object)((Component)rectTransform).gameObject == (Object)null)
			{
				return false;
			}
			MenuSelectableElement component = ((Component)rectTransform).GetComponent<MenuSelectableElement>();
			if ((Object)(object)component == (Object)null)
			{
				return false;
			}
			MenuSelectionBox value = Traverse.Create((object)parentPage).Field("selectionBox").GetValue<MenuSelectionBox>();
			bool flag = false;
			if (Traverse.Create((object)component).Field("isInScrollBox").GetValue<bool>())
			{
				MenuScrollBox value2 = Traverse.Create((object)component).Field("menuScrollBox").GetValue<MenuScrollBox>();
				if ((Object)(object)value2 == (Object)null)
				{
					return false;
				}
				value = Traverse.Create((object)value2).Field("menuSelectionBox").GetValue<MenuSelectionBox>();
				flag = true;
			}
			if ((Object)(object)value == (Object)null)
			{
				return false;
			}
			RectTransform value3 = Traverse.Create((object)value).Field("rectTransform").GetValue<RectTransform>();
			if ((Object)(object)value3 == (Object)null)
			{
				return false;
			}
			Transform parent = ((Transform)value3).parent;
			if ((Object)(object)parent == (Object)null)
			{
				return false;
			}
			RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			rectTransform.GetWorldCorners(array);
			for (int i = 0; i < 4; i++)
			{
				array[i] = ((Transform)val).InverseTransformPoint(array[i]);
			}
			float x = array[0].x;
			float x2 = array[2].x;
			float y = array[0].y;
			float y2 = array[2].y;
			Vector3 val2 = default(Vector3);
			((Vector3)(ref val2))..ctor((x + x2) * 0.5f, (y + y2) * 0.5f, 0f);
			Vector3 val3 = default(Vector3);
			((Vector3)(ref val3))..ctor(x2 - x, y2 - y, 0f);
			val2 += Vector2.op_Implicit(customOffset);
			MenuPage value4 = Traverse.Create((object)component).Field("parentPage").GetValue<MenuPage>();
			MenuScrollBox value5 = Traverse.Create((object)component).Field("menuScrollBox").GetValue<MenuScrollBox>();
			value.MenuSelectionBoxSetTarget(val2, val3, value4, flag, value5, customScale);
			return false;
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[UmaSemiBots] Safe MenuSelectionBoxTargetSet failed:\n" + ex));
			return false;
		}
	}
}
[HarmonyPatch(typeof(MenuElementButtonCosmeticCategory), "ClickCategory")]
internal class CosmeticCategoryClickPatch
{
	[HarmonyPrefix]
	public static bool Prefix(MenuElementButtonCosmeticCategory __instance)
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		if (((Object)((Component)__instance).gameObject).name == "Umas Tab Button")
		{
			MenuPageCosmetics componentInParent = ((Component)__instance).GetComponentInParent<MenuPageCosmetics>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				MenuPageCosmeticsPatch.OnUmasTabClicked(componentInParent);
			}
			return false;
		}
		if (!UmasTabState.IsUmasTabActive)
		{
			return true;
		}
		UmasTabState.IsUmasTabActive = false;
		MenuPageCosmetics componentInParent2 = ((Component)__instance).GetComponentInParent<MenuPageCosmetics>();
		if ((Object)(object)componentInParent2 != (Object)null)
		{
			componentInParent2.selectedTab = (CosmeticPageTab)0;
			CosmeticCategoryAsset value = ((IEnumerable<CosmeticCategoryAsset>)MetaManager.instance.CosmeticCategoryAssets).FirstOrDefault((Func<CosmeticCategoryAsset, bool>)((CosmeticCategoryAsset c) => (Object)(object)c != (Object)null));
			typeof(MenuPageCosmetics).GetField("selectedCategory", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.SetValue(componentInParent2, value);
			Transform obj = ((Component)componentInParent2).transform.Find("UmaOutfitArrow_Left");
			if (obj != null)
			{
				((Component)obj).gameObject.SetActive(false);
			}
			Transform obj2 = ((Component)componentInParent2).transform.Find("UmaOutfitArrow_Right");
			if (obj2 != null)
			{
				((Component)obj2).gameObject.SetActive(false);
			}
		}
		SafeDestroyUmasSectionRoot();
		return true;
	}

	private static void SafeDestroyUmasSectionRoot()
	{
		if ((Object)(object)UmasTabState.UmasSectionRoot == (Object)null)
		{
			return;
		}
		if ((Object)(object)MenuManager.instance != (Object)null)
		{
			MenuManager instance = MenuManager.instance;
			Traverse.Create((object)instance).Field("currentHoverButton").SetValue((object)null);
			Traverse.Create((object)instance).Field("currentSelectedButton").SetValue((object)null);
			List<MenuButton> value = Traverse.Create((object)instance).Field<List<MenuButton>>("allMenuButtons").Value;
			if (value != null)
			{
				HashSet<MenuButton> umasButtons = new HashSet<MenuButton>(UmasTabState.UmasSectionRoot.GetComponentsInChildren<MenuButton>(true));
				value.RemoveAll((MenuButton mb) => (Object)(object)mb == (Object)null || umasButtons.Contains(mb));
			}
		}
		if ((Object)(object)UmasTabState.LastBuiltFor != (Object)null)
		{
			Transform val = ((Component)UmasTabState.LastBuiltFor).transform.Find("UmasSelectBanner");
			if ((Object)(object)val != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)val).gameObject);
			}
		}
		Object.Destroy((Object)(object)UmasTabState.UmasSectionRoot);
		UmasTabState.UmasSectionRoot = null;
	}
}
[HarmonyPatch(typeof(MenuPageCosmetics), "ConfirmButton")]
internal class MenuPageCosmeticsConfirmPatch
{
	[HarmonyPrefix]
	public static void Prefix()
	{
		UmasTabState.IsUmasTabActive = false;
		UmasTabState.UmasSectionRoot = null;
		UmasTabState.UmasTabButton = null;
		UmasTabState.LastBuiltFor = null;
	}
}
internal class UmaThumbnailButton : MonoBehaviour
{
	internal int slotIndex;

	internal Image borderImage;

	internal MenuPageCosmetics pageRef;

	private Image _img;

	private bool _hovered = false;

	private static readonly Color HoverBorderColor = new Color(0.3f, 0.6f, 1f, 0.6f);

	private static readonly Color SelectedBorderColor = new Color(0.0157f, 0.2863f, 0.7451f, 1f);

	private void Awake()
	{
		_img = ((Component)this).GetComponent<Image>();
	}

	private void OnDisable()
	{
		_hovered = false;
	}

	internal void SetHovered(bool hovered)
	{
		_hovered = hovered;
		RefreshBorder();
	}

	internal void RefreshThumbnail()
	{
		//IL_00a4: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
		int value;
		int num = (CustomModelSwapMod.ColorToModel.TryGetValue(slotIndex, out value) ? value : slotIndex);
		if (num >= 0 && num < CustomModelSwapMod.Thumbnails.Count)
		{
			if ((Object)(object)_img == (Object)null)
			{
				_img = ((Component)this).GetComponent<Image>();
			}
			if (!((Object)(object)_img == (Object)null))
			{
				Texture2D val = CustomModelSwapMod.Thumbnails[num];
				((Texture)val).filterMode = (FilterMode)1;
				_img.sprite = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0);
				((Graphic)_img).color = Color.white;
			}
		}
	}

	internal void RefreshBorder()
	{
		//IL_0034: 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 (!((Object)(object)borderImage == (Object)null))
		{
			int localModelID = ModdedModelPlayerAvatar.LocalModelID;
			if (localModelID >= 0 && slotIndex == localModelID)
			{
				SetBorderLines(SelectedBorderColor);
				((Component)borderImage).gameObject.SetActive(true);
			}
			else if (_hovered)
			{
				SetBorderLines(HoverBorderColor);
				((Component)borderImage).gameObject.SetActive(true);
			}
			else
			{
				((Component)borderImage).gameObject.SetActive(false);
			}
		}
	}

	private void SetBorderLines(Color color)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		Image[] componentsInChildren = ((Component)borderImage).GetComponentsInChildren<Image>(true);
		foreach (Image val in componentsInChildren)
		{
			if (!((Object)(object)val == (Object)(object)borderImage))
			{
				((Graphic)val).color = color;
			}
		}
	}

	private static int GetSlotForPrefab(int prefabIndex)
	{
		for (int i = 0; i < CustomModelSwapMod.ModelOutfitGroups.Count; i++)
		{
			if (CustomModelSwapMod.ModelOutfitGroups[i].Contains(prefabIndex))
			{
				return i;
			}
		}
		return 0;
	}
}
internal class UmaNoneButton : MonoBehaviour
{
	internal Image borderImage;

	internal void RefreshBorder()
	{
		if (!((Object)(object)borderImage == (Object)null))
		{
			((Component)borderImage).gameObject.SetActive(ModdedModelPlayerAvatar.LocalModelID < 0);
		}
	}
}
internal class UmasTabClickForwarder : MonoBehaviour, IPointerClickHandler, IEventSystemHandler
{
	internal MenuPageCosmetics page;

	public void OnPointerClick(PointerEventData e)
	{
		if ((Object)(object)page != (Object)null)
		{
			MenuPageCosmeticsPatch.OnUmasTabClicked(page);
		}
	}
}
[HarmonyPatch(typeof(MenuPageEsc))]
internal class MenuPageEscPatch
{
	[HarmonyPatch("Start")]
	[HarmonyPostfix]
	public static void Start_Postfix(MenuPageEsc __instance)
	{
		((MonoBehaviour)__instance).StartCoroutine(ApplyModelNameNextFrame(__instance));
	}

	[HarmonyPatch("Update")]
	[HarmonyPostfix]
	public static void Update_Postfix(MenuPageEsc __instance)
	{
		//IL_0040: 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)
		((TMP_Text)((Component)((Component)__instance).transform.Find("Menu Button - Customize/ButtonText")).GetComponent<TextMeshProUGUI>()).text = "Change Umamusume";
		((Component)((Component)__instance).transform.Find("Menu Button - Customize")).GetComponent<RectTransform>().sizeDelta = new Vector2(165.38f, 35.83f);
		((Component)((Component)__instance).transform.Find("Menu Button - Customize/Menu Element Cosmetic Highlight")).gameObject.SetActive(false);
		((Graphic)((Component)((Component)__instance).transform.Find("Menu Button - Customize/ButtonText")).GetComponent<TextMeshProUGUI>()).color = new Color(0.5f, 0.5f, 0.5f, 1f);
	}

	private static IEnumerator ApplyModelNameNextFrame(MenuPageEsc __instance)
	{
		yield return null;
		Transform originalHeader = ((Component)__instance).transform.Find("Header");
		if ((Object)(object)originalHeader == (Object)null)
		{
			yield break;
		}
		Transform existing = ((Component)__instance).transform.Find("ModelNameHeader");
		if ((Object)(object)existing != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)existing).gameObject);
		}
		GameObject nameHeader = Object.Instantiate<GameObject>(((Component)originalHeader).gameObject, ((Component)__instance).transform);
		((Object)nameHeader).name = "ModelNameHeader";
		nameHeader.transform.localPosition = new Vector3(506f, 79f, 0f);
		LocalizationChangedEvent[] componentsInChildren = nameHeader.GetComponentsInChildren<LocalizationChangedEvent>(true);
		foreach (LocalizationChangedEvent loc in componentsInChildren)
		{
			Object.DestroyImmediate((Object)(object)loc);
		}
		LocalizeChangedUI[] componentsInChildren2 = nameHeader.GetComponentsInChildren<LocalizeChangedUI>(true);
		foreach (LocalizeChangedUI loc2 in componentsInChildren2)
		{
			Object.DestroyImmediate((Object)(object)loc2);
		}
		TextMeshProUGUI tmp = nameHeader.GetComponentInChildren<TextMeshProUGUI>();
		if ((Object)(object)tmp != (Object)null)
		{
			((TMP_Text)tmp).fontSizeMax = 36f;
			((TMP_Text)tmp).enableAutoSizing = true;
			((TMP_Text)tmp).text = MenuPageCosmeticsPatch.GetModelDisplayName(ModdedModelPlayerAvatar.LocalModelID);
		}
		if (!CustomModelSwapMod.GrowthRatesEnabled.Value)
		{
			yield break;
		}
		int slotID = ModdedModelPlayerAvatar.LocalModelID;
		int modelID = ((slotID >= 0) ? CustomModelSwapMod.SlotToFlatIndex(slotID) : (-1));
		if (modelID < 0 || modelID >= CustomModelSwapMod.ModelNames.Count)
		{
			yield break;
		}
		string modelKey = CustomModelSwapMod.ModelNames[modelID] ?? "";
		if (!UmaGrowthRateData.UmaGrowthRateTable.TryGetValue(modelKey, out var rates))
		{
			yield break;
		}
		GameObject growthGO = new GameObject("EscGrowthRates");
		growthGO.transform.SetParent(nameHeader.transform, false);
		RectTransform growthRT = growthGO.AddComponent<RectTransform>();
		growthRT.sizeDelta = new Vector2(300f, 20f);
		HorizontalLayoutGroup hLayout = growthGO.AddComponent<HorizontalLayoutGroup>();
		((HorizontalOrVerticalLayoutGroup)hLayout).spacing = 2f;
		((LayoutGroup)hLayout).childAlignment = (TextAnchor)4;
		((HorizontalOrVerticalLayoutGroup)hLayout).childForceExpandWidth = false;
		((HorizontalOrVerticalLayoutGroup)hLayout).childForceExpandHeight = false;
		TextMeshProUGUI fontSource = ((Component)__instance).GetComponentInChildren<TextMeshProUGUI>(true);
		string[] iconNames = new string[5] { "icon_speed", "icon_stamina", "icon_power", "icon_guts", "icon_wits" };
		int[] values = new int[5] { rates.Speed, rates.Stamina, rates.Power, rates.Guts, rates.Wit };
		for (int k = 0; k < iconNames.Length; k++)
		{
			GameObject iconObj = new GameObject($"GR_Icon_{k}");
			iconObj.transform.SetParent(growthGO.transform, false);
			iconObj.AddComponent<RectTransform>().sizeDelta = new Vector2(18f, 18f);
			Image iconImg = iconObj.AddComponent<Image>();
			((Graphic)iconImg).color = new Color(0.8f, 0.8f, 0.8f, 1f);
			if (CustomModelSwapMod.StatIcons.TryGetValue(iconNames[k], out var spr))
			{
				iconImg.sprite = spr;
			}
			LayoutElement iconLE = iconObj.AddComponent<LayoutElement>();
			float minWidth = (iconLE.preferredWidth = 18f);
			iconLE.minWidth = minWidth;
			minWidth = (iconLE.preferredHeight = 18f);
			iconLE.minHeight = minWidth;
			GameObject labelObj = new GameObject($"GR_Label_{k}");
			labelObj.transform.SetParent(growthGO.transform, false);
			labelObj.AddComponent<RectTransform>().sizeDelta = new Vector2(36f, 18f);
			TextMeshProUGUI label = labelObj.AddComponent<TextMeshProUGUI>();
			((TMP_Text)label).text = $"+{values[k]}%";
			((TMP_Text)label).fontSize = 15f;
			((Graphic)label).color = new Color(0.8f, 0.8f, 0.8f, 1f);
			((TMP_Text)label).alignment = (TextAlignmentOptions)4097;
			if ((Object)(object)fontSource != (Object)null)
			{
				((TMP_Text)label).font = ((TMP_Text)fontSource).font;
			}
			LayoutElement labelLE = labelObj.AddComponent<LayoutElement>();
			minWidth = (labelLE.preferredWidth = 30f);
			labelLE.minWidth = minWidth;
			spr = null;
		}
		yield return null;
		growthGO.transform.localPosition = new Vector3(0f, -30f, 0f);
	}
}
internal static class UISafe
{
	public static void Text(Transform root, string path, string text)
	{
		try
		{
			Transform val = root.Find(path);
			if (!((Object)(object)val == (Object)null))
			{
				TextMeshProUGUI componentInChildren = ((Component)val).GetComponentInChildren<TextMeshProUGUI>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					((TMP_Text)componentInChildren).text = text;
				}
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[UmaSemiBots] Text(" + path + "): " + ex.Message));
		}
	}

	public static void Size(Transform root, string path, float fontSize)
	{
		try
		{
			Transform val = root.Find(path);
			if (!((Object)(object)val == (Object)null))
			{
				TextMeshProUGUI componentInChildren = ((Component)val).GetComponentInChildren<TextMeshProUGUI>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					((TMP_Text)componentInChildren).fontSize = fontSize;
				}
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[UmaSemiBots] Size(" + path + "): " + ex.Message));
		}
	}

	public static void Delta(Transform root, string path, Vector2 delta)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Transform val = root.Find(path);
			if (!((Object)(object)val == (Object)null))
			{
				RectTransform component = ((Component)val).GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null)
				{
					component.sizeDelta = delta;
				}
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[UmaSemiBots] Delta(" + path + "): " + ex.Message));
		}
	}

	public static void Anchor(Transform root, string path, Vector2 pos)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Transform val = root.Find(path);
			if (!((Object)(object)val == (Object)null))
			{
				RectTransform component = ((Component)val).GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null)
				{
					component.anchoredPosition = pos;
				}
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[UmaSemiBots] Anchor(" + path + "): " + ex.Message));
		}
	}

	public static void ForceRefreshMenuVisual()
	{
		//IL_0090: 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)
		PlayerAvatar instance = PlayerAvatar.instance;
		ModdedModelPlayerAvatar moddedModelPlayerAvatar = ((instance != null) ? ((Component)instance).GetComponent<ModdedModelPlayerAvatar>() : null);
		if ((Object)(object)moddedModelPlayerAvatar == (Object)null || moddedModelPlayerAvatar.currentModelID < 0)
		{
			return;
		}
		PlayerAvatarVisuals[] array = Object.FindObjectsOfType<PlayerAvatarVisuals>();
		foreach (PlayerAvatarVisuals val in array)
		{
			if (!val.isMenuAvatar)
			{
				continue;
			}
			moddedModelPlayerAvatar.ApplyModelToVisual(val);
			if (!((Object)(object)moddedModelPlayerAvatar._cachedMenuModelTransform != (Object)null))
			{
				continue;
			}
			moddedModelPlayerAvatar._cachedMenuModelTransform.parent.localPosition = new Vector3(0.1f, -0.686f, 0.2f);
			Animator component = ((Component)moddedModelPlayerAvatar._cachedMenuModelTransform).GetComponent<Animator>();
			if ((Object)(object)component != (Object)null)
			{
				AnimatorStateInfo currentAnimatorStateInfo = component.GetCurrentAnimatorStateInfo(0);
				if (!((AnimatorStateInfo)(ref currentAnimatorStateInfo)).IsName("SpecialIdle"))
				{
					component.Play("SpecialIdle", 0, 0f);
				}
			}
		}
	}
}
[Serializable]
public class BlendShapeExpression
{
	public class SmolFaceData
	{
		public Vector2 eyeOffset = Vector2.zero;

		public Vector2 eyebrowOffset = Vector2.zero;

		public Vector2 mouthOffset = Vector2.zero;

		public Vector2 talkingMouthOffset = Vector2.zero;

		public Vector2 blinkOffset = Vector2.zero;
	}

	public string name;

	public Dictionary<string, float> shapes;

	public SmolFaceData smolFace = new SmolFaceData();

	public string talkingBlendShape;

	public float talkingMaxValue;

	public string blinkBlendShapeLeft;

	public string blinkBlendShapeRight;

	public float blinkClosedValue;

	public BlendShapeExpression(string name, Dictionary<string, float> shapes, string talkingBlendShape = "", float talkingMaxValue = 100f, string blinkBlendShapeLeft = "", string blinkBlendShapeRight = "", float blinkClosedValue = 100f)
	{
		this.name = name;
		this.shapes = shapes;
		this.talkingBlendShape = talkingBlendShape;
		this.talkingMaxValue = talkingMaxValue;
		this.blinkBlendShapeLeft = blinkBlendShapeLeft;
		this.blinkBlendShapeRight = blinkBlendShapeRight;
		this.blinkClosedValue = blinkClosedValue;
	}
}
public class ModdedModelExpression : MonoBehaviour
{
	private struct BakedExpression
	{
		public int[] indices;

		public float[] values;
	}

	public bool isLocalPlayer;

	public PlayerAvatar avatar;

	public PlayerAvatar avatarForVoice;

	public BlendShapeExpression[] expressions = new BlendShapeExpression[6];

	public string defaultTalkingBlendShape = "";

	public float defaultTalkingMaxValue = 100f;

	public string defaultBlinkBlendShapeLeft = "";

	public string defaultBlinkBlendShapeRight = "";

	public float defaultBlinkClosedValue = 100f;

	private int _activeIndex = -1;

	private SkinnedMeshRenderer _bodyMesh;

	private Dictionary<string, int> _blendShapeMap = new Dictionary<string, int>();

	private Dictionary<int, float> _currentWeights = new Dictionary<int, float>();

	private float[] _targetWeights;

	private int[] _allIndices;

	private HashSet<int> _reservedIndices = new HashSet<int>();

	private int _talkingBsIndex = -1;

	private float _talkingMaxValue = 100f;

	private float _talkingCurrentWeight = 0f;

	private const float TALK_SPEED = 25f;

	private int _blinkBsIndexLeft = -1;

	private int _blinkBsIndexRight = -1;

	private float _blinkClosedValue = 100f;

	private float _blinkCurrentWeight = 0f;

	private float _blinkTimer = 0f;

	private bool _isBlinking = false;

	private const float BLINK_SPEED = 25f;

	private const float EXPR_SPEED = 20f;

	private static FieldInfo _voiceChatFetchedField;

	private static FieldInfo _voiceChatField;

	private static FieldInfo _clipLoudnessField;

	private static FieldInfo _overrideNoTalkField;

	private PlayerVoiceChat _cachedVoiceChat = null;

	private bool _voiceCacheResolved = false;

	private Coroutine _applyCoroutine;

	private BakedExpression[] _bakedExpressions;

	public int ActiveIndex => _activeIndex;

	public float BlinkCurrentWeight => _blinkCurrentWeight;

	public float DefaultBlinkClosedValue => _blinkClosedValue;

	public void ReserveBlendShapeIndices(params int[] indices)
	{
		foreach (int num in indices)
		{
			if (num >= 0)
			{
				_reservedIndices.Add(num);
			}
		}
	}

	private void OnEnable()
	{
		if (!((Object)(object)_bodyMesh != (Object)null) || _applyCoroutine != null)
		{
			return;
		}
		if (_allIndices != null)
		{
			for (int i = 0; i < _allIndices.Length; i++)
			{
				int num = _allIndices[i];
				_currentWeights[num] = _bodyMesh.GetBlendShapeWeight(num);
			}
		}
		_applyCoroutine = ((MonoBehaviour)this).StartCoroutine(ApplyLoop());
	}

	private void BakeExpressions()
	{
		_bakedExpressions = new BakedExpression[expressions.Length];
		for (int i = 0; i < expressions.Length; i++)
		{
			if (expressions[i] == null || expressions[i].shapes == null)
			{
				_bakedExpressions[i] = new BakedExpression
				{
					indices = new int[0],
					values = new float[0]
				};
				continue;
			}
			List<int> list = new List<int>();
			List<float> list2 = new List<float>();
			foreach (KeyValuePair<string, float> shape in expressions[i].shapes)
			{
				if (_blendShapeMap.TryGetValue(shape.Key, out var value))
				{
					list.Add(value);
					list2.Add(shape.Value);
					continue;
				}
				foreach (KeyValuePair<string, int> item in _blendShapeMap)
				{
					if (item.Key.Contains(shape.Key))
					{
						list.Add(item.Value);
						list2.Add(shape.Value);
						break;
					}
				}
			}
			_bakedExpressions[i] = new BakedExpression
			{
				indices = list.ToArray(),
				values = list2.ToArray()
			};
		}
	}

	private void OnDisable()
	{
		if (_applyCoroutine != null)
		{
			((MonoBehaviour)this).StopCoroutine(_applyCoroutine);
			_applyCoroutine = null;
		}
		_blinkTimer = 0f;
		_isBlinking = false;
	}

	private void OnDestroy()
	{
		if (_applyCoroutine != null)
		{
			((MonoBehaviour)this).StopCoroutine(_applyCoroutine);
			_applyCoroutine = null;
		}
		if ((Object)(object)_bodyMesh != (Object)null)
		{
			foreach (KeyValuePair<int, float> currentWeight in _currentWeights)
			{
				if (!_reservedIndices.Contains(currentWeight.Key))
				{
					_bodyMesh.SetBlendShapeWeight(currentWeight.Key, 0f);
				}
			}
			if (_blinkBsIndexLeft >= 0)
			{
				_bodyMesh.SetBlendShapeWeight(_blinkBsIndexLeft, 0f);
			}
			if (_blinkBsIndexRight >= 0)
			{
				_bodyMesh.SetBlendShapeWeight(_blinkBsIndexRight, 0f);
			}
		}
		_blinkTimer = 0f;
		_isBlinking = false;
		_blinkCurrentWeight = 0f;
	}

	public void Initialize(SkinnedMeshRenderer bodyMesh)
	{
		_bodyMesh = bodyMesh;
		if (!((Object)(object)_bodyMesh == (Object)null))
		{
			if (_voiceChatFetchedField == null)
			{
				_voiceChatFetchedField = typeof(PlayerAvatar).GetField("voiceChatFetched", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			if (_voiceChatField == null)
			{
				_voiceChatField = typeof(PlayerAvatar).GetField("voiceChat", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			if (_clipLoudnessField == null)
			{
				_clipLoudnessField = typeof(PlayerVoiceChat).GetField("clipLoudness", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			if (_overrideNoTalkField == null)
			{
				_overrideNoTalkField = typeof(PlayerVoiceChat).GetField("overrideNoTalkAnimationTimer", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			Mesh sharedMesh = _bodyMesh.sharedMesh;
			int blendShapeCount = sharedMesh.blendShapeCount;
			_t