Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of VillageOfFoolsCostumes v0.3.1
plugins/VillageOfFools/VillageOfFools.dll
Decompiled 4 minutes agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.IO.Compression; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using HarmonyLib; using Microsoft.CodeAnalysis; using REPOLib.Modules; using UnityEngine; using UnityEngine.Rendering; [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("VillageOfFools")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.3.1.0")] [assembly: AssemblyInformationalVersion("0.3.1")] [assembly: AssemblyProduct("VillageOfFools")] [assembly: AssemblyTitle("VillageOfFools")] [assembly: AssemblyVersion("0.3.1.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 VillageOfFools { [BepInPlugin("VillageOfFools.Costumes", "Village of Fools Costumes", "0.3.1")] [BepInDependency("REPOLib", "4.5.1")] public sealed class PeasantWardrobe : BaseUnityPlugin { private readonly List<CosmeticAsset> outfit = new List<CosmeticAsset>(); private Harmony? harmony; private void Awake() { //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Expected O, but got Unknown //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Expected O, but got Unknown //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Unknown result type (might be due to invalid IL or missing references) FieldInfo icon = typeof(CosmeticAsset).GetField("icon", BindingFlags.Instance | BindingFlags.NonPublic); Shader val = Shader.Find("Standard"); if (icon?.FieldType != typeof(Sprite) || (Object)(object)val == (Object)null || !val.isSupported) { throw new NotSupportedException("Missing cosmetic icon field or Standard shader."); } WardrobeModels models = new WardrobeModels(val); GameObject templates = new GameObject("Village of Fools wardrobe"); templates.SetActive(false); Object.DontDestroyOnLoad((Object)(object)templates); harmony = new Harmony("VillageOfFools.Costumes"); harmony.CreateClassProcessor(typeof(GarmentMount)).Patch(); using (StreamReader streamReader = new StreamReader(WardrobeModels.Resource("costumes.tsv"))) { TextInfo textInfo = CultureInfo.InvariantCulture.TextInfo; while (true) { string text = streamReader.ReadLine(); if (text == null) { break; } string[] array = text.Split('\t'); if (array.Length != 4) { throw new InvalidDataException(text); } string text2 = array[1]; string text3 = ((array[0] == "peasant") ? text2 : text2.Substring(array[0].Length + 1)); string label = text3 switch { "headband" => "Kokoshnik", "braid" => "Braided Hair", "lip-upper" => "Upper Lip", "lip-lower" => "Lower Lip", _ => textInfo.ToTitleCase(text3.Replace('-', ' ')), }; Register(textInfo.ToTitleCase(array[0]), text2, label, Enum.Parse<CosmeticType>(array[2]), (array[3].Length == 0) ? ((CosmeticType?)null) : new CosmeticType?(Enum.Parse<CosmeticType>(array[3]))); } if (models.PieceCount != outfit.Count + 6) { throw new InvalidDataException("Catalog and fitted attachment count differ."); } ((BaseUnityPlugin)this).Logger.LogInfo((object)$"Registered {outfit.Count} cosmetics across five costumes."); } void Register(string set, string id, string text5, CosmeticType slot, CosmeticType? mount) { //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_003b: 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_0080: Expected O, but got Unknown //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Invalid comparison between Unknown and I4 //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Invalid comparison between Unknown and I4 //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Expected O, but got Unknown //IL_011c: 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_0121: Invalid comparison between Unknown and I4 //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Invalid comparison between Unknown and I4 //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_0220: Expected O, but got Unknown //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Expected O, but got Unknown //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Invalid comparison between Unknown and I4 //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_014f: 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_0154: Invalid comparison between Unknown and I4 //IL_0260: 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_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Expected O, but got Unknown //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Invalid comparison between Unknown and I4 //IL_0280: 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_02f1: Unknown result type (might be due to invalid IL or missing references) //IL_02f9: Unknown result type (might be due to invalid IL or missing references) //IL_0301: Unknown result type (might be due to invalid IL or missing references) //IL_0349: Unknown result type (might be due to invalid IL or missing references) //IL_0358: Unknown result type (might be due to invalid IL or missing references) //IL_0289: Unknown result type (might be due to invalid IL or missing references) //IL_02b4: Unknown result type (might be due to invalid IL or missing references) string text4 = "VillageOfFools_" + set + "_" + id; GameObject val2 = new GameObject(text4); val2.transform.SetParent(templates.transform, false); Cosmetic val3 = val2.AddComponent<Cosmetic>(); val3.type = slot; val3.meshParents = new List<Transform>(); bool flag = !mount.HasValue; bool flag2; if (flag) { flag2 = (((int)slot == 16 || (int)slot == 25) ? true : false); flag = flag2; } bool num = flag; GameObject val4 = new GameObject("Garment"); val4.transform.SetParent(val2.transform, false); if (!mount.HasValue) { val3.meshParents.Add(val4.transform); } bool flag3; if (!num) { flag = id == "braid"; if (!flag) { flag3 = ((slot - 3 <= 1 || (int)slot == 20) ? true : false); flag = flag3; } flag2 = flag; if (!flag2) { if (mount.HasValue) { CosmeticType valueOrDefault = mount.GetValueOrDefault(); if (valueOrDefault - 3 <= 1 || (int)valueOrDefault == 20) { flag3 = true; goto IL_0164; } } flag3 = false; goto IL_0164; } goto IL_0168; } models.Attach(val4, id, flat: false); GameObject val5 = new GameObject("Flat garment"); val5.transform.SetParent(val2.transform, false); models.Attach(val5, id, flat: true); val5.SetActive(false); val3.meshParents.Add(val5.transform); goto IL_0207; IL_0207: if (id == "fool-makeup") { GameObject val6 = new GameObject("Lower face paint"); val6.transform.SetParent(val2.transform, false); models.Attach(val6, "fool-chin", flat: false); val6.AddComponent<JawPaint>(); } if (mount.HasValue) { val2.AddComponent<GarmentMount>().target = mount.Value; } if ((Object)(object)val2.GetComponentInChildren<SkinnedMeshRenderer>(true) != (Object)null) { val2.AddComponent<WaistGarment>(); } if ((int)slot == 0) { Transform transform = new GameObject("Crown anchor").transform; transform.SetParent(val2.transform, false); transform.localPosition = new Vector3(0f, 0.385f, 0.254f); val2.AddComponent<CosmeticPlayerCrown>().targetMain = transform; } CosmeticAsset val7 = ScriptableObject.CreateInstance<CosmeticAsset>(); ((Object)val7).name = text4; val7.assetName = set + " " + text5; val7.type = slot; val7.rarity = (Rarity)0; val7.status = (Status)3; val7.customTypeList = new List<Type>(); Texture2D val8 = WardrobeModels.Texture(id + ".png"); icon.SetValue(val7, Sprite.Create(val8, new Rect(0f, 0f, (float)((Texture)val8).width, (float)((Texture)val8).height), new Vector2(0.5f, 0.5f))); val7.prefab = NetworkPrefabs.RegisterNetworkPrefab("Cosmetics/" + text4, val2); if (val7.prefab == null || Cosmetics.RegisterCosmetic(val7) == null) { throw new InvalidOperationException("Could not register " + text4); } outfit.Add(val7); return; IL_0164: flag2 = flag3; goto IL_0168; IL_0168: if (flag2) { GameObject val9 = new GameObject("Standing"); val9.transform.SetParent(val4.transform, false); models.Attach(val9, id, flat: false); if ((int)slot == 20) { models.AttachWaist(val9.transform, id); } GameObject val10 = new GameObject("Crouching"); val10.transform.SetParent(val4.transform, false); models.Attach(val10, id, flat: true); val10.SetActive(false); val4.AddComponent<GarmentPose>(); } else { models.Attach(val4, id, flat: false); } goto IL_0207; } } private IEnumerator Start() { if (outfit.Count == 0) { yield break; } MetaManager instance; while ((Object)(object)(instance = MetaManager.instance) == (Object)null || !outfit.TrueForAll(instance.cosmeticAssets.Contains)) { yield return null; } if (!(typeof(MetaManager).GetField("cosmeticUnlocks", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(instance) is List<int> list)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"Cosmetics registered, could not unlock immediately."); yield break; } foreach (CosmeticAsset item2 in outfit) { int item = instance.cosmeticAssets.IndexOf(item2); if (!list.Contains(item)) { list.Add(item); } } } private void OnDestroy() { Harmony? obj = harmony; if (obj != null) { obj.UnpatchSelf(); } } } [HarmonyPatch(typeof(PlayerCosmetics), "InstantiateCosmetic")] internal sealed class GarmentMount : MonoBehaviour { [SerializeField] internal CosmeticType target; [HarmonyPostfix] private static void Mount(PlayerCosmetics __instance, GameObject? __result) { if ((Object)(object)__result == (Object)null) { return; } GarmentMount marker = default(GarmentMount); if (__result.TryGetComponent<GarmentMount>(ref marker)) { CosmeticParent val = __instance.cosmeticParents.Find((CosmeticParent p) => p.cosmeticType == marker.target); if ((Object)(object)val?.parent != (Object)null) { __result.transform.SetParent(val.parent, false); } } WaistGarment component = __result.GetComponent<WaistGarment>(); if ((Object)(object)marker == (Object)null && (Object)(object)component == (Object)null) { return; } Transform val2 = (((Object)(object)component == (Object)null) ? null : __instance.cosmeticParents.Find((CosmeticParent p) => (int)p.cosmeticType == 21)?.parent); if ((Object)(object)val2 != (Object)null) { SkinnedMeshRenderer[] componentsInChildren = __result.GetComponentsInChildren<SkinnedMeshRenderer>(true); foreach (SkinnedMeshRenderer val3 in componentsInChildren) { if (val3.sharedMesh.bindposes.Length == 1) { val3.bones = (Transform[])(object)new Transform[1] { val2 }; val3.rootBone = val2; } else { val3.bones = (Transform[])(object)new Transform[2] { ((Component)val3).transform, val2 }; } } } JawPaint componentInChildren = __result.GetComponentInChildren<JawPaint>(true); if ((Object)(object)componentInChildren != (Object)null) { CosmeticParent val4 = __instance.cosmeticParents.Find((CosmeticParent p) => (int)p.cosmeticType == 25); if ((Object)(object)val4?.parent != (Object)null) { componentInChildren.Bind(val4.parent); } } } } internal sealed class WaistGarment : MonoBehaviour { } internal sealed class JawPaint : MonoBehaviour { private Transform? jaw; internal void Bind(Transform target) { jaw = target; LateUpdate(); } private void LateUpdate() { //IL_001a: 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) if ((Object)(object)jaw != (Object)null) { ((Component)this).transform.SetPositionAndRotation(jaw.position, jaw.rotation); } } } internal sealed class GarmentPose : MonoBehaviour { private PlayerAvatarVisuals? avatar; private void Start() { avatar = ((Component)this).GetComponentInParent<PlayerAvatarVisuals>(); } 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; bool flag2 = flag; GameObject gameObject = ((Component)((Component)this).transform.GetChild(0)).gameObject; if (gameObject.activeSelf == flag2) { gameObject.SetActive(!flag2); ((Component)((Component)this).transform.GetChild(1)).gameObject.SetActive(flag2); } } } } internal sealed class WardrobeModels { private readonly Dictionary<(string, bool), (Mesh, Material[])> pieces = new Dictionary<(string, bool), (Mesh, Material[])>(); private readonly Dictionary<string, Material> fabrics = new Dictionary<string, Material>(); private readonly Shader shader; internal int PieceCount => pieces.Count / 2; internal WardrobeModels(Shader shader) { this.shader = shader; using GZipStream gZipStream = new GZipStream(Resource("ensembles.bin.gz"), CompressionMode.Decompress); using BinaryReader binaryReader = new BinaryReader(gZipStream); if (binaryReader.ReadUInt32() != 826492502) { throw new InvalidDataException("Unknown garment format."); } int num = binaryReader.ReadByte(); if (num == 0 || num % 2 != 0) { throw new InvalidDataException("Expected two poses per garment."); } for (int i = 0; i < num; i++) { string text = binaryReader.ReadString(); bool item = binaryReader.ReadBoolean(); pieces.Add((text, item), ReadMesh(binaryReader, text)); } if (gZipStream.ReadByte() != -1) { throw new InvalidDataException("Extra garment data."); } foreach (var key in pieces.Keys) { if (!pieces.ContainsKey((key.Item1, !key.Item2))) { throw new InvalidDataException(key.Item1); } } } internal static Stream Resource(string name) { return typeof(WardrobeModels).Assembly.GetManifestResourceStream("VillageOfFools." + name) ?? throw new FileNotFoundException(name); } internal static Texture2D Texture(string file) { //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_002a: Expected O, but got Unknown //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown using Stream stream = Resource(file); using MemoryStream memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true); if (!ImageConversion.LoadImage(val, memoryStream.ToArray(), true)) { throw new InvalidDataException(file); } ((Object)val).name = file; return val; } private (Mesh, Material[]) ReadMesh(BinaryReader reader, string id) { //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_0216: 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_007a: 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_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Expected O, but got Unknown //IL_022f: Expected O, but got Unknown //IL_016c: 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_01a0: Unknown result type (might be due to invalid IL or missing references) Material[] array = (Material[])(object)new Material[reader.ReadByte()]; List<Vector3> list = new List<Vector3>(); List<Vector3> list2 = new List<Vector3>(); List<Vector2> list3 = new List<Vector2>(); List<int[]> list4 = new List<int[]>(); Color32 val = default(Color32); for (int i = 0; i < array.Length; i++) { string text = reader.ReadString(); ((Color32)(ref val))..ctor(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), byte.MaxValue); if (!fabrics.TryGetValue(text, out Material value)) { value = new Material(shader) { name = text, color = Color32.op_Implicit(val) }; if (text == "brocade" || text.StartsWith("meshy-", StringComparison.Ordinal)) { value.mainTexture = (Texture)(object)Texture(text + ".png"); } Material obj = value; float num; switch (text) { default: num = 0.16f; break; case "cream": case "sailcloth": num = 0.04f; break; case "beads": num = 0.5f; break; } obj.SetFloat("_Glossiness", num); fabrics.Add(text, value); } array[i] = value; int num2 = reader.ReadInt32(); int num3 = reader.ReadInt32(); if (num2 <= 0 || num2 > 65535 || num3 <= 0 || num3 % 3 != 0) { throw new InvalidDataException(id); } int count = list.Count; for (int j = 0; j < num2; j++) { list.Add(new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle())); list2.Add(new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle())); list3.Add(new Vector2(reader.ReadSingle(), reader.ReadSingle())); } int[] array2 = new int[num3]; for (int k = 0; k < array2.Length; k++) { int num4 = reader.ReadUInt16(); if (num4 >= num2) { throw new InvalidDataException(id); } array2[k] = count + num4; } list4.Add(array2); } Mesh val2 = new Mesh { name = id, indexFormat = (IndexFormat)(list.Count > 65535) }; val2.SetVertices(list); val2.SetNormals(list2); val2.SetUVs(0, list3); val2.subMeshCount = list4.Count; for (int l = 0; l < list4.Count; l++) { val2.SetTriangles(list4[l], l, false); } val2.RecalculateBounds(); return (val2, array); } internal void Attach(GameObject geometry, string id, bool flat) { //IL_0136: 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_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0266: Unknown result type (might be due to invalid IL or missing references) //IL_026b: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Unknown result type (might be due to invalid IL or missing references) //IL_0279: Unknown result type (might be due to invalid IL or missing references) //IL_027e: Unknown result type (might be due to invalid IL or missing references) //IL_0283: Unknown result type (might be due to invalid IL or missing references) //IL_02de: Unknown result type (might be due to invalid IL or missing references) //IL_02e3: Unknown result type (might be due to invalid IL or missing references) //IL_02f3: Unknown result type (might be due to invalid IL or missing references) //IL_0207: 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_0237: Unknown result type (might be due to invalid IL or missing references) (Mesh, Material[]) tuple = pieces[(id, flat)]; Mesh item = tuple.Item1; Material[] item2 = tuple.Item2; bool flag = !flat; if (flag) { bool flag2; switch (id) { case "fool-coat": case "fool-hips": case "bear-fur": case "bee-body": case "bodice": case "skirt": case "fool-scarf": case "sailor-shirt": case "sailor-collar": flag2 = true; break; default: flag2 = false; break; } flag = flag2; } if (flag) { Transform transform = new GameObject("Waist rest").transform; transform.SetParent(geometry.transform, false); transform.localPosition = Vector3.down * 0.2908f; Vector3[] vertices = item.vertices; BoneWeight[] array = (BoneWeight[])(object)new BoneWeight[vertices.Length]; for (int i = 0; i < item2.Length; i++) { bool flag3 = ((Object)item2[i]).name.StartsWith("lining-", StringComparison.Ordinal) || ((Object)item2[i]).name == "cream"; int[] triangles = item.GetTriangles(i); foreach (int num in triangles) { float num2 = (flag3 ? 0f : Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.18f, -0.16f, vertices[num].y))); BoneWeight val = default(BoneWeight); ((BoneWeight)(ref val)).boneIndex0 = 0; ((BoneWeight)(ref val)).weight0 = 1f - num2; ((BoneWeight)(ref val)).boneIndex1 = 1; ((BoneWeight)(ref val)).weight1 = num2; array[num] = val; } } item.bindposes = (Matrix4x4[])(object)new Matrix4x4[2] { Matrix4x4.identity, Matrix4x4.Translate(-transform.localPosition) }; item.boneWeights = array; SkinnedMeshRenderer val2 = geometry.AddComponent<SkinnedMeshRenderer>(); val2.sharedMesh = item; ((Renderer)val2).sharedMaterials = item2; val2.quality = (SkinQuality)2; val2.bones = (Transform[])(object)new Transform[2] { geometry.transform, transform }; val2.rootBone = geometry.transform; Bounds bounds = item.bounds; ((Bounds)(ref bounds)).Expand(0.58f); ((Renderer)val2).localBounds = bounds; } else { geometry.AddComponent<MeshFilter>().sharedMesh = item; ((Renderer)geometry.AddComponent<MeshRenderer>()).sharedMaterials = item2; } } internal void AttachWaist(Transform standing, string id) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Expected O, but got Unknown //IL_0047: 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_009b: 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_00e8: Unknown result type (might be due to invalid IL or missing references) (Mesh, Material[]) tuple = pieces[(id + "-lining", false)]; Mesh item = tuple.Item1; Material[] item2 = tuple.Item2; GameObject val = new GameObject("Waist lining"); val.transform.SetParent(standing, false); val.transform.localPosition = Vector3.down * 0.291f; BoneWeight[] array = (BoneWeight[])(object)new BoneWeight[item.vertexCount]; for (int i = 0; i < array.Length; i++) { ((BoneWeight)(ref array[i])).weight0 = 1f; } item.boneWeights = array; item.bindposes = (Matrix4x4[])(object)new Matrix4x4[1] { Matrix4x4.identity }; SkinnedMeshRenderer val2 = val.AddComponent<SkinnedMeshRenderer>(); val2.sharedMesh = item; ((Renderer)val2).sharedMaterials = item2; val2.bones = (Transform[])(object)new Transform[1] { val.transform }; val2.rootBone = val.transform; ((Renderer)val2).localBounds = item.bounds; } } }