Decompiled source of BoobeesSuits v0.3.2

plugins/BoobeesSuits/BoobeesSuits.dll

Decompiled an hour ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using Microsoft.CodeAnalysis;
using REPOLib.Modules;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BoobeesSuits")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.3.2.0")]
[assembly: AssemblyInformationalVersion("0.3.2")]
[assembly: AssemblyProduct("BoobeesSuits")]
[assembly: AssemblyTitle("BoobeesSuits")]
[assembly: AssemblyVersion("0.3.2.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace BoobeesSuits
{
	[DefaultExecutionOrder(1000)]
	internal sealed class BodiceMotion : MonoBehaviour
	{
		private const float MaximumOffset = 0.06f;

		private const float VisualMultiplier = 1.35f;

		private const float LobeScale = 0.68f;

		private static readonly Vector3 LeftPoint = new Vector3(-0.12f, 0.12f, 0.35f);

		private static readonly Vector3 RightPoint = new Vector3(0.12f, 0.12f, 0.35f);

		[SerializeField]
		private Transform left;

		[SerializeField]
		private Transform right;

		private Vector3 previousLeftPoint;

		private Vector3 previousRightPoint;

		private Vector3 previousLeftVelocity;

		private Vector3 previousRightVelocity;

		private Vector2 offset;

		private Vector2 previousOffset;

		private Vector2 speed;

		private float remainder;

		private int samples;

		internal void Configure(Transform leftCloth, Transform rightCloth)
		{
			left = leftCloth;
			right = rightCloth;
		}

		private void OnDisable()
		{
			//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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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)
			samples = 0;
			remainder = 0f;
			offset = (previousOffset = (speed = Vector2.zero));
			if ((Object)(object)left != (Object)null)
			{
				left.localPosition = Vector3.zero;
			}
			if ((Object)(object)right != (Object)null)
			{
				right.localPosition = Vector3.zero;
			}
		}

		private void LateUpdate()
		{
			//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_0017: 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)
			Tick(((Component)this).transform.TransformPoint(LeftPoint), ((Component)this).transform.TransformPoint(RightPoint), Time.deltaTime, Time.fixedDeltaTime);
		}

		internal void Tick(Vector3 leftPoint, Vector3 rightPoint, float seconds, float step)
		{
			//IL_0012: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_00f6: 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_00fd: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			if (seconds <= 0f || step <= 0f)
			{
				return;
			}
			Vector3 val = leftPoint - previousLeftPoint;
			Vector3 val2 = rightPoint - previousRightPoint;
			previousLeftPoint = leftPoint;
			previousRightPoint = rightPoint;
			if (samples == 0 || seconds > 0.12f || Mathf.Max(((Vector3)(ref val)).sqrMagnitude, ((Vector3)(ref val2)).sqrMagnitude) > 0.7225f)
			{
				ResetSpring();
				samples = 1;
				return;
			}
			Vector3 val3 = val / seconds;
			Vector3 val4 = val2 / seconds;
			if (samples == 2)
			{
				speed.x += MotionKick(((Component)this).transform.InverseTransformDirection(val3 - previousLeftVelocity), -0.6f, seconds);
				speed.y += MotionKick(((Component)this).transform.InverseTransformDirection(val4 - previousRightVelocity), 0.6f, seconds);
			}
			samples = 2;
			previousLeftVelocity = val3;
			previousRightVelocity = val4;
			remainder += seconds;
			while (remainder + 1E-06f >= step)
			{
				remainder = Mathf.Max(0f, remainder - step);
				previousOffset = offset;
				Advance(ref offset.x, ref speed.x, step);
				Advance(ref offset.y, ref speed.y, step);
			}
			Draw(Vector2.Lerp(previousOffset, offset, remainder / step));
		}

		private void ResetSpring()
		{
			//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_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			remainder = 0f;
			offset = (previousOffset = (speed = Vector2.zero));
			Draw(Vector2.zero);
		}

		private void Draw(Vector2 pose)
		{
			//IL_0000: 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_000b: 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_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)
			pose *= 0.91800004f;
			left.localPosition = Vector3.up * pose.x;
			right.localPosition = Vector3.up * pose.y;
		}

		private static float MotionKick(Vector3 change, float side, float elapsed)
		{
			//IL_0022: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			float magnitude = ((Vector3)(ref change)).magnitude;
			float num = 11f * elapsed;
			if (magnitude <= num || magnitude > 18f)
			{
				return 0f;
			}
			return (0f - change.y - 0.6f * change.z + side * change.x) * (1f - num / magnitude) * 0.45f;
		}

		internal static void Advance(ref float displacement, ref float velocity, float step)
		{
			velocity = Mathf.Clamp(velocity, -2f, 2f);
			velocity -= (250f * displacement + 15f * velocity) * step;
			displacement = Mathf.Clamp(displacement + velocity * step, -0.06f, 0.06f);
			if (Mathf.Abs(displacement) < 0.00018f && Mathf.Abs(velocity) < 0.003f)
			{
				displacement = (velocity = 0f);
			}
		}
	}
	[BepInPlugin("BooBees.BoobeesSuits", "Boobees Suits", "0.3.2")]
	[BepInDependency("REPOLib", "4.5.1")]
	public sealed class BoobeesSuitsPlugin : BaseUnityPlugin
	{
		private readonly List<CosmeticAsset> outfit = new List<CosmeticAsset>();

		private void Awake()
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			FieldInfo field = typeof(CosmeticAsset).GetField("icon", BindingFlags.Instance | BindingFlags.NonPublic);
			Shader val = Shader.Find("Standard");
			if (field?.FieldType != typeof(Sprite) || (Object)(object)val == (Object)null || !val.isSupported)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Boobees Suits needs the R.E.P.O. 0.5.3 cosmetic icon and Standard shader.");
				return;
			}
			GameObject val2 = new GameObject("Boobees Suits Templates");
			val2.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)val2);
			SuitModels models = new SuitModels(val);
			AddPiece("Antennae", (CosmeticType)0, val2.transform, delegate(Transform p)
			{
				models.Add(p, "Antennae");
			}, field);
			AddPiece("Hood", (CosmeticType)24, val2.transform, delegate(Transform p)
			{
				models.Add(p, "Hood");
			}, field);
			AddPiece("Hood Lower", (CosmeticType)25, val2.transform, delegate(Transform p)
			{
				models.Add(p, "Hood Lower");
			}, field, "Hood");
			AddPiece("Bodice", (CosmeticType)20, val2.transform, delegate(Transform p)
			{
				models.Add(p, "Bodice");
				models.Add(p, "Wings");
			}, field);
			AddPiece("Left Sleeve", (CosmeticType)2, val2.transform, delegate(Transform p)
			{
				models.Add(p, "Left Sleeve");
			}, field, "Sleeve");
			AddPiece("Right Sleeve", (CosmeticType)1, val2.transform, delegate(Transform p)
			{
				models.Add(p, "Right Sleeve");
			}, field, "Sleeve");
			AddPiece("Mantle", (CosmeticType)16, val2.transform, delegate(Transform p)
			{
				models.Add(p, "Hem");
			}, field);
			AddPiece("Left Sock", (CosmeticType)22, val2.transform, delegate(Transform p)
			{
				models.Add(p, "Left Sock");
			}, field, "Sock");
			AddPiece("Right Sock", (CosmeticType)19, val2.transform, delegate(Transform p)
			{
				models.Add(p, "Right Sock");
			}, field, "Sock");
		}

		private IEnumerator Start()
		{
			if (outfit.Count == 0)
			{
				yield break;
			}
			FieldInfo unlocksField = typeof(MetaManager).GetField("cosmeticUnlocks", BindingFlags.Instance | BindingFlags.NonPublic);
			if (unlocksField?.FieldType != typeof(List<int>))
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Could not find the cosmetic unlock list. The outfit is available through normal rewards.");
				yield break;
			}
			MetaManager instance;
			while (true)
			{
				instance = MetaManager.instance;
				if ((Object)(object)instance != (Object)null && outfit.TrueForAll(instance.cosmeticAssets.Contains))
				{
					break;
				}
				yield return null;
			}
			if (!(unlocksField.GetValue(instance) is List<int> list))
			{
				yield break;
			}
			int num = 0;
			foreach (CosmeticAsset item2 in outfit)
			{
				int item = instance.cosmeticAssets.IndexOf(item2);
				if (!list.Contains(item))
				{
					list.Add(item);
					num++;
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Boobees Suits available in Customize ({outfit.Count} pieces, {num} newly unlocked).");
		}

		private void AddPiece(string piece, CosmeticType slot, Transform inventory, Action<Transform> build, FieldInfo iconField, string? iconKey = null)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0033: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: 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)
			string text = "Boo-Bee " + piece;
			string text2 = "BoobeesSuits_" + text;
			GameObject val = new GameObject(text2);
			val.transform.SetParent(inventory, false);
			Cosmetic obj = val.AddComponent<Cosmetic>();
			obj.type = slot;
			Transform transform = new GameObject("Geometry").transform;
			transform.SetParent(val.transform, false);
			obj.meshParents = new List<Transform> { transform };
			build(transform);
			if ((int)slot == 0)
			{
				Transform transform2 = new GameObject("Crown Anchor").transform;
				transform2.SetParent(val.transform, false);
				transform2.localPosition = new Vector3(0f, 0.55f, 0.25f);
				val.AddComponent<CosmeticPlayerCrown>().targetMain = transform2;
			}
			CosmeticAsset val2 = ScriptableObject.CreateInstance<CosmeticAsset>();
			((Object)val2).name = text2;
			val2.assetName = text;
			val2.type = slot;
			val2.status = (Status)3;
			val2.rarity = (Rarity)0;
			val2.customTypeList = new List<Type>();
			val2.tintable = false;
			iconField.SetValue(val2, LoadIcon(iconKey ?? piece));
			val2.prefab = NetworkPrefabs.RegisterNetworkPrefab("Cosmetics/" + text2, val);
			if (val2.prefab == null || Cosmetics.RegisterCosmetic(val2) == null)
			{
				Object.Destroy((Object)(object)val);
				Object.Destroy((Object)(object)val2);
				((BaseUnityPlugin)this).Logger.LogError((object)("Failed to register " + text + "."));
			}
			else
			{
				outfit.Add(val2);
				((BaseUnityPlugin)this).Logger.LogInfo((object)$"Queued {text} for the {slot} slot.");
			}
		}

		private static Sprite LoadIcon(string piece)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_00ab: 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)
			using Stream stream = typeof(BoobeesSuitsPlugin).Assembly.GetManifestResourceStream("BoobeesSuits." + piece + ".png") ?? throw new InvalidDataException("Missing icon for " + piece + ".");
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			if (!ImageConversion.LoadImage(val, memoryStream.ToArray(), true))
			{
				Object.Destroy((Object)(object)val);
				throw new InvalidDataException("Invalid icon for " + piece + ".");
			}
			((Object)val).name = "Boo-Bee " + piece;
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		}
	}
	internal sealed class OutfitPose : MonoBehaviour
	{
		[SerializeField]
		private Mesh stand;

		[SerializeField]
		private Mesh crouch;

		private MeshFilter? filter;

		private SkinnedMeshRenderer? skinned;

		private PlayerAvatarVisuals? avatar;

		internal void Configure(Mesh standing, Mesh crouching)
		{
			stand = standing;
			crouch = crouching;
		}

		private void Start()
		{
			avatar = ((Component)this).GetComponentInParent<PlayerAvatarVisuals>();
			filter = ((Component)this).GetComponent<MeshFilter>();
			skinned = ((Component)this).GetComponent<SkinnedMeshRenderer>();
		}

		private void LateUpdate()
		{
			//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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Invalid comparison between Unknown and I4
			if (!((Object)(object)avatar == (Object)null))
			{
				Pose currentPose = avatar.currentPose;
				bool flag = currentPose - 1 <= 1;
				Mesh val = (flag ? crouch : stand);
				if ((Object)(object)filter != (Object)null && (Object)(object)filter.sharedMesh != (Object)(object)val)
				{
					filter.sharedMesh = val;
				}
				if ((Object)(object)skinned != (Object)null && (Object)(object)skinned.sharedMesh != (Object)(object)val)
				{
					skinned.sharedMesh = val;
				}
			}
		}
	}
	internal sealed class SuitModels
	{
		private readonly Dictionary<string, (Mesh Stand, Mesh Crouch)> meshes = new Dictionary<string, (Mesh, Mesh)>(StringComparer.Ordinal);

		private readonly Material patterned;

		private readonly Material sleeve;

		private readonly Material sock;

		internal SuitModels(Shader shader)
		{
			using GZipStream gZipStream = new GZipStream(Resource("Outfit.bin.gz"), CompressionMode.Decompress);
			using BinaryReader binaryReader = new BinaryReader(gZipStream);
			if (binaryReader.ReadUInt32() != 827540034 || binaryReader.ReadByte() != 10)
			{
				throw new InvalidDataException("Invalid Boobees outfit mesh pack.");
			}
			for (int i = 0; i < 10; i++)
			{
				string text = binaryReader.ReadString();
				bool usesAtlas = !text.EndsWith("Sleeve", StringComparison.Ordinal) && !text.EndsWith("Sock", StringComparison.Ordinal);
				bool springBodice = text == "Bodice";
				meshes.Add(text, (ReadMesh(binaryReader, text + " · Stand", usesAtlas, springBodice), ReadMesh(binaryReader, text + " · Crouch", usesAtlas, springBodice)));
			}
			if (gZipStream.ReadByte() != -1)
			{
				throw new InvalidDataException("Unexpected data after the outfit meshes.");
			}
			patterned = Fabric(shader, "Fabric.png");
			patterned.SetTexture("_BumpMap", (Texture)(object)LoadTexture("FabricNormal.png", linear: true));
			patterned.SetFloat("_BumpScale", 0.75f);
			patterned.EnableKeyword("_NORMALMAP");
			sleeve = Fabric(shader, "SleeveFabric.png");
			sock = Fabric(shader, "SockFabric.png");
		}

		internal void Add(Transform parent, string name)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			(Mesh, Mesh) tuple = meshes[name];
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.AddComponent<OutfitPose>().Configure(tuple.Item1, tuple.Item2);
			if (name == "Bodice")
			{
				AddSpringBodice(val, tuple.Item1, tuple.Item2);
				return;
			}
			val.AddComponent<MeshFilter>().sharedMesh = tuple.Item1;
			((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = (name.EndsWith("Sleeve", StringComparison.Ordinal) ? sleeve : (name.EndsWith("Sock", StringComparison.Ordinal) ? sock : patterned));
		}

		private void AddSpringBodice(GameObject piece, Mesh stand, Mesh crouch)
		{
			//IL_000c: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = piece.transform;
			Transform transform2 = new GameObject("Left Cloth Spring").transform;
			Transform transform3 = new GameObject("Right Cloth Spring").transform;
			transform2.SetParent(transform, false);
			transform3.SetParent(transform, false);
			SkinnedMeshRenderer val = piece.AddComponent<SkinnedMeshRenderer>();
			val.rootBone = transform;
			val.bones = (Transform[])(object)new Transform[3] { transform, transform2, transform3 };
			val.quality = (SkinQuality)4;
			val.sharedMesh = stand;
			((Renderer)val).sharedMaterial = patterned;
			Bounds bounds = stand.bounds;
			((Bounds)(ref bounds)).Encapsulate(crouch.bounds);
			((Renderer)val).localBounds = bounds;
			piece.AddComponent<BodiceMotion>().Configure(transform2, transform3);
		}

		private static Mesh ReadMesh(BinaryReader reader, string name, bool usesAtlas, bool springBodice)
		{
			//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_006e: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			int num = reader.ReadInt32();
			int num2 = reader.ReadInt32();
			if (num < 3 || num > 65535 || num2 < 3 || num2 > 240000 || num2 % 3 != 0)
			{
				throw new InvalidDataException("Invalid mesh dimensions for " + name + ".");
			}
			Vector3[] array = (Vector3[])(object)new Vector3[num];
			Vector3[] array2 = (Vector3[])(object)new Vector3[num];
			Vector2[] array3 = (Vector2[])(object)new Vector2[num];
			for (int i = 0; i < num; i++)
			{
				array[i] = ReadVector(reader);
				array2[i] = ReadVector(reader);
				array3[i] = new Vector2(reader.ReadSingle(), reader.ReadSingle());
			}
			int[] array4 = new int[num2];
			for (int j = 0; j < num2; j++)
			{
				array4[j] = reader.ReadUInt16();
				if (array4[j] >= num)
				{
					throw new InvalidDataException("Invalid triangle index in " + name + ".");
				}
			}
			Mesh val = new Mesh
			{
				name = name,
				vertices = array,
				normals = array2,
				uv = array3
			};
			val.SetTriangles(array4, 0);
			if (usesAtlas)
			{
				val.RecalculateTangents();
			}
			if (springBodice)
			{
				BindCloth(val, array);
			}
			val.UploadMeshData(true);
			return val;
		}

		private static void BindCloth(Mesh mesh, Vector3[] positions)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			Bounds bounds = mesh.bounds;
			BoneWeight[] array = (BoneWeight[])(object)new BoneWeight[positions.Length];
			for (int i = 0; i < positions.Length; i++)
			{
				Vector3 val = positions[i];
				float num = Mathf.InverseLerp(((Bounds)(ref bounds)).min.y, ((Bounds)(ref bounds)).max.y, val.y);
				float num2 = Ramp(0.11f, 0.3f, num) * (1f - Ramp(0.74f, 0.94f, num)) * Ramp(0.258f, 0.326f, val.z);
				float left = num2 * LobeWeight(val, num, -0.116f);
				float right = num2 * LobeWeight(val, num, 0.116f);
				array[i] = SkinWeight(left, right);
			}
			mesh.bindposes = (Matrix4x4[])(object)new Matrix4x4[3]
			{
				Matrix4x4.identity,
				Matrix4x4.identity,
				Matrix4x4.identity
			};
			mesh.boneWeights = array;
			((Bounds)(ref bounds)).Expand(0.12f);
			mesh.bounds = bounds;
		}

		private static float LobeWeight(Vector3 vertex, float height, float center)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor((vertex.x - center) / 0.175f, (height - 0.62f) / 0.59f, (vertex.z - 0.361f) / 0.14f);
			float num = Mathf.Max(0f, 1f - ((Vector3)(ref val)).sqrMagnitude);
			return num * num;
		}

		private static BoneWeight SkinWeight(float left, float right)
		{
			//IL_0048: 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)
			int num = 0;
			int num2 = 1;
			int num3 = 2;
			float num4 = 1f - left - right;
			float num5 = left;
			float num6 = right;
			if (num4 < num5)
			{
				float num7 = num5;
				float num8 = num4;
				int num9 = num2;
				num2 = num;
				num = num9;
				num5 = num8;
				num4 = num7;
			}
			if (num5 < num6)
			{
				float num10 = num6;
				float num11 = num5;
				int num12 = num3;
				num3 = num2;
				num2 = num12;
				num6 = num11;
				num5 = num10;
			}
			if (num4 < num5)
			{
				float num13 = num5;
				float num14 = num4;
				int num15 = num2;
				num2 = num;
				num = num15;
				num5 = num14;
				num4 = num13;
			}
			BoneWeight result = default(BoneWeight);
			((BoneWeight)(ref result)).boneIndex0 = num;
			((BoneWeight)(ref result)).boneIndex1 = num2;
			((BoneWeight)(ref result)).boneIndex2 = num3;
			((BoneWeight)(ref result)).weight0 = num4;
			((BoneWeight)(ref result)).weight1 = num5;
			((BoneWeight)(ref result)).weight2 = num6;
			return result;
		}

		private static float Ramp(float begin, float end, float value)
		{
			return Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(begin, end, value));
		}

		private static Vector3 ReadVector(BinaryReader reader)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
		}

		private static Material Fabric(Shader shader, string name)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			Material val = new Material(shader)
			{
				name = name,
				mainTexture = (Texture)(object)LoadTexture(name, linear: false)
			};
			val.SetFloat("_Glossiness", 0.13f);
			return val;
		}

		private static Texture2D LoadTexture(string name, bool linear)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_0059: Expected O, but got Unknown
			using Stream stream = Resource(name);
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true, linear)
			{
				name = name,
				wrapMode = (TextureWrapMode)1,
				anisoLevel = 4
			};
			if (!ImageConversion.LoadImage(val, memoryStream.ToArray(), true))
			{
				throw new InvalidDataException("Invalid outfit texture " + name + ".");
			}
			return val;
		}

		private static Stream Resource(string name)
		{
			return typeof(SuitModels).Assembly.GetManifestResourceStream("BoobeesSuits.Assets." + name) ?? throw new InvalidDataException("Missing outfit asset " + name + ".");
		}
	}
}