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 Long Hairstyles v1.1.1
LongHairstyles.dll
Decompiled 13 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("LongHairstyles")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.1.1.0")] [assembly: AssemblyInformationalVersion("1.1.1")] [assembly: AssemblyProduct("LongHairstyles")] [assembly: AssemblyTitle("LongHairstyles")] [assembly: AssemblyVersion("1.1.1.0")] [module: RefSafetyRules(11)] 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; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace LongHairstyles { internal sealed class HairDef { public readonly string Id; public readonly string Name; public readonly string BasePrefab; public HairDef(string id, string name, string basePrefab = "Hair6") { Id = id; Name = name; BasePrefab = basePrefab; } } internal static class HairDefs { public static readonly HairDef[] All = new HairDef[20] { new HairDef("HairSkaSleekStraight", "Sleek Straight"), new HairDef("HairSkaCenterPartFlowing", "Center Part Flowing"), new HairDef("HairSkaSidePartWaves", "Side Part Cascading Waves"), new HairDef("HairSkaBohemianWaves", "Loose Bohemian Waves"), new HairDef("HairSkaHighPonytail", "Long High Ponytail"), new HairDef("HairSkaLowPonytail", "Low Ponytail"), new HairDef("HairSkaBubblePonytail", "Bubble Ponytail"), new HairDef("HairSkaRibbonTied", "Ribbon-Tied Long Hair"), new HairDef("HairSkaSingleBraid", "Single Long Braid"), new HairDef("HairSkaTwinBraids", "Long Twin Braids"), new HairDef("HairSkaFishtailBraid", "Fishtail Braid"), new HairDef("HairSkaRopeBraid", "Rope Braid"), new HairDef("HairSkaHalfUpTwist", "Half-Up Twist"), new HairDef("HairSkaBraidedCrown", "Half-Up Braided Crown"), new HairDef("HairSkaCrownBraidWaves", "Crown Braid & Waves"), new HairDef("HairSkaWaterfallBraid", "Waterfall Braid"), new HairDef("HairSkaTwistedHalfCrown", "Twisted Half Crown"), new HairDef("HairSkaBraidedSideSweep", "Braided Side Sweep"), new HairDef("HairSkaMultiBraidAccent", "Multi-Braid Accent"), new HairDef("HairSkaOrnamentedBraids", "Ornamented Braids") }; } internal static class HairFactory { private static readonly Assembly Self = typeof(HairFactory).Assembly; private static readonly Color Gold = new Color(1f, 0.78f, 0.25f, 1f); private static readonly Color RibbonRed = new Color(0.6f, 0.06f, 0.08f, 1f); private static Material? _accessoryMaterial; private static Material? _ribbonMaterial; public static void Add(HairDef def, VisEquipment player, bool diagnostics) { //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Expected O, but got Unknown //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_046e: Unknown result type (might be due to invalid IL or missing references) //IL_0473: Unknown result type (might be due to invalid IL or missing references) //IL_0492: Unknown result type (might be due to invalid IL or missing references) //IL_04a6: Unknown result type (might be due to invalid IL or missing references) //IL_04ba: Unknown result type (might be due to invalid IL or missing references) //IL_04ce: Unknown result type (might be due to invalid IL or missing references) //IL_04e2: Unknown result type (might be due to invalid IL or missing references) //IL_04f6: Unknown result type (might be due to invalid IL or missing references) SkinnedMeshRenderer bodyModel = player.m_bodyModel; Matrix4x4[] bindposes = BindPoses(player); HairMesh.Data[] array = new HairMesh.Data[2]; Mesh[] array2 = (Mesh[])(object)new Mesh[2]; for (int i = 0; i < 2; i++) { array[i] = HairMesh.Parse(def.Id, ReadText($"{def.Id}.{i}.hair")); array2[i] = HairMesh.Build(array[i], ((Component)player).transform, bodyModel.bones, bindposes); ((Object)array2[i]).name = $"{def.Id}_{i}"; } if (array[0].Positions.Length != array[1].Positions.Length || array2[0].subMeshCount != array2[1].subMeshCount) { throw new InvalidOperationException("The two fits of " + def.Id + " differ in size; run tools\\art\\Hair.cs again."); } CustomItem val = new CustomItem(def.Id, def.BasePrefab); if (!Object.op_Implicit((Object)(object)val.ItemPrefab)) { throw new InvalidOperationException("Could not clone " + def.BasePrefab + "."); } Transform obj = val.ItemPrefab.transform.Find("attach_skin"); if (!Object.op_Implicit((Object)(object)obj)) { throw new InvalidOperationException(def.BasePrefab + " has no 'attach_skin' child."); } SkinnedMeshRenderer[] componentsInChildren = ((Component)obj).GetComponentsInChildren<SkinnedMeshRenderer>(true); if (componentsInChildren.Length != 1) { throw new InvalidOperationException($"{def.BasePrefab} has {componentsInChildren.Length} skinned meshes; one was expected."); } SkinnedMeshRenderer val2 = componentsInChildren[0]; MonoBehaviour[] componentsInChildren2 = ((Component)obj).GetComponentsInChildren<MonoBehaviour>(true); if (componentsInChildren2.Length != 0) { throw new InvalidOperationException(def.BasePrefab + " carries " + string.Join(", ", componentsInChildren2.Select((MonoBehaviour script) => (!Object.op_Implicit((Object)(object)script)) ? "a missing script" : ((object)script).GetType().Name)) + "; use a base style without cloth."); } Material hairMaterial = ((Renderer)val2).sharedMaterial; val2.sharedMesh = array2[0]; ((Renderer)val2).localBounds = HairMesh.BoundsFor(rootBone: Object.op_Implicit((Object)(object)bodyModel.rootBone) ? bodyModel.rootBone : bodyModel.bones[0], data: array[0], root: ((Component)player).transform); ((Renderer)val2).sharedMaterials = (from m in Enumerable.Range(0, array2[0].subMeshCount) select (Material)(m switch { 1 => AccessoryMaterial(), 0 => hairMaterial, _ => RibbonMaterial(), })).ToArray(); HairFit hairFit = ((Component)obj).gameObject.AddComponent<HairFit>(); hairFit.Style = def.Id; hairFit.Renderer = val2; hairFit.Meshes = array2; hairFit.Shown = 0; SharedData shared = val.ItemDrop.m_itemData.m_shared; shared.m_name = def.Name; if (!ItemManager.Instance.AddItem(val)) { throw new InvalidOperationException("Jotunn refused to add " + def.Id + "."); } HairFit.Register(def.Id, array[0].Rig); string text = ((shared.m_helmetHairSettings == null || shared.m_helmetHairSettings.Count == 0) ? "none" : string.Join(", ", shared.m_helmetHairSettings.Select((HelmetHairSettings setting) => string.Format("{0} shows {1}", setting.m_setting, Object.op_Implicit((Object)(object)setting.m_hairPrefab) ? ((Object)setting.m_hairPrefab).name : "nothing")))); LongHairstylesPlugin.Log.LogInfo((object)($"Added {def.Id} (\"{def.Name}\"): copied from {def.BasePrefab}, {array[0].Positions.Length} vertices, {array[0].TriangleCount} triangles, " + "hair material " + (Object.op_Implicit((Object)(object)hairMaterial) ? (((Object)hairMaterial).name + " (" + ((Object)hairMaterial.shader).name + ")") : "missing") + ((array2[0].subMeshCount > 1) ? (", accessory material on " + ((Object)AccessoryMaterial().shader).name) : "") + $", {array[0].Rig.Names.Length} sway bones in {array[0].Rig.Chains.Length} chains, tool tier {shared.m_toolTier}, under a helmet: {text}")); if (diagnostics) { Bounds localBounds = ((Renderer)val2).localBounds; LongHairstylesPlugin.Log.LogInfo((object)($"[test] {def.Id}: bounds in the root bone's space centre ({((Bounds)(ref localBounds)).center.x:0.###}, {((Bounds)(ref localBounds)).center.y:0.###}, {((Bounds)(ref localBounds)).center.z:0.###}) size ({((Bounds)(ref localBounds)).size.x:0.###}, {((Bounds)(ref localBounds)).size.y:0.###}, {((Bounds)(ref localBounds)).size.z:0.###}); " + "bones used: " + string.Join(", ", array[0].Bones))); } } private static Matrix4x4[] BindPoses(VisEquipment player) { //IL_009e: 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) SkinnedMeshRenderer bodyModel = player.m_bodyModel; Mesh val = ((player.m_models != null && player.m_models.Length != 0 && Object.op_Implicit((Object)(object)player.m_models[0].m_mesh)) ? player.m_models[0].m_mesh : bodyModel.sharedMesh); try { if (Object.op_Implicit((Object)(object)val) && val.isReadable) { Matrix4x4[] bindposes = val.bindposes; if (bindposes.Length == bodyModel.bones.Length) { return bindposes; } } } catch (Exception ex) { LongHairstylesPlugin.Log.LogWarning((object)("The body mesh's bind poses could not be read (" + ex.Message + "); they are worked out from the skeleton.")); } Matrix4x4 meshToWorld = ((Component)bodyModel).transform.localToWorldMatrix; return bodyModel.bones.Select((Transform bone) => bone.worldToLocalMatrix * meshToWorld).ToArray(); } private static Material AccessoryMaterial() { //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_010e: 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_0119: 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_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Expected O, but got Unknown //IL_0140: Expected O, but got Unknown if (Object.op_Implicit((Object)(object)_accessoryMaterial)) { return _accessoryMaterial; } Shader val = null; GameObject prefab = PrefabManager.Instance.GetPrefab("HelmetRootCrown"); if (Object.op_Implicit((Object)(object)prefab)) { val = (from material in prefab.GetComponentsInChildren<Renderer>(true).SelectMany((Renderer renderer) => renderer.sharedMaterials) where Object.op_Implicit((Object)(object)material) && Object.op_Implicit((Object)(object)material.shader) && ((Object)material.shader).name == "Standard" select material.shader).FirstOrDefault(); } if (!Object.op_Implicit((Object)(object)val)) { val = ((IEnumerable<Shader>)Resources.FindObjectsOfTypeAll<Shader>()).FirstOrDefault((Func<Shader, bool>)((Shader candidate) => Object.op_Implicit((Object)(object)candidate) && ((Object)candidate).name == "Standard")); } if (!Object.op_Implicit((Object)(object)val)) { val = Shader.Find("Standard"); } if (!Object.op_Implicit((Object)(object)val)) { throw new InvalidOperationException("The game's Standard shader was not found."); } Material val2 = new Material(val) { name = "SkaHairAccessory", color = Gold }; val2.SetFloat("_Metallic", 1f); val2.SetFloat("_Glossiness", 0.72f); _accessoryMaterial = val2; return val2; } private static Material RibbonMaterial() { //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) //IL_0027: 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_0032: 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_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Expected O, but got Unknown //IL_0059: Expected O, but got Unknown if (Object.op_Implicit((Object)(object)_ribbonMaterial)) { return _ribbonMaterial; } Material val = new Material(AccessoryMaterial()) { name = "SkaHairRibbon", color = RibbonRed }; val.SetFloat("_Metallic", 0f); val.SetFloat("_Glossiness", 0.25f); _ribbonMaterial = val; return val; } private static string ReadText(string file) { string text = Self.GetManifestResourceNames().FirstOrDefault((string name) => name.EndsWith("." + file, StringComparison.OrdinalIgnoreCase)); if (text == null) { throw new FileNotFoundException(file + " is not embedded in the plugin. Run tools\\art\\Hair.cs, then build again."); } using Stream stream = Self.GetManifestResourceStream(text); using StreamReader streamReader = new StreamReader(stream); return streamReader.ReadToEnd(); } } public class HairFit : MonoBehaviour { [HarmonyPatch(typeof(VisEquipment), "UpdateEquipmentVisuals")] private static class AfterEquipmentUpdate { private static void Postfix(VisEquipment __instance, GameObject ___m_hairItemInstance, int ___m_currentHairItemHash, int ___m_currentModelIndex, Vector3 ___m_hairColor) { //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_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_0209: 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) if (___m_currentHairItemHash == 0 || !Hashes.Contains(___m_currentHairItemHash) || !Object.op_Implicit((Object)(object)___m_hairItemInstance)) { return; } HairFit component = ___m_hairItemInstance.GetComponent<HairFit>(); if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)component.Renderer) || component.Meshes.Length == 0) { return; } if (!component._rigged) { component._rigged = true; component.Rig(); } int num = Mathf.Clamp(___m_currentModelIndex, 0, component.Meshes.Length - 1); if (component.Shown != num || (Object)(object)component.Renderer.sharedMesh != (Object)(object)component.Meshes[num]) { component.Renderer.sharedMesh = component.Meshes[num]; component.Shown = num; component.Reported = false; } if (Diagnostics && !component.Reported) { component.Reported = true; string text = string.Join(", ", ((Renderer)component.Renderer).sharedMaterials.Select((Material material) => (!Object.op_Implicit((Object)(object)material)) ? "missing" : (((Object)material).name + " (" + ((Object)material.shader).name + ")"))); HairSwayDriver component2 = ((Component)component).GetComponent<HairSwayDriver>(); LongHairstylesPlugin.Log.LogInfo((object)($"[test] {((Object)((Component)__instance).gameObject).name} wears {component.Style}: body shape {___m_currentModelIndex}, fit {num} shown ({((Object)component.Renderer.sharedMesh).name}), " + $"{component.Renderer.bones.Length} bones for {component.Renderer.sharedMesh.bindposes.Length} bind poses, " + "sway " + (Object.op_Implicit((Object)(object)component2) ? $"on with {component2.BoneCount} bones, amount {HairSwaySim.Amount:0.##}, wind {HairSwaySim.WindAmount:0.##}" : "off") + ", " + $"materials: {text}, hair colour ({___m_hairColor.x:0.##}, {___m_hairColor.y:0.##}, {___m_hairColor.z:0.##})")); } } } public string Style = ""; public SkinnedMeshRenderer Renderer; public Mesh[] Meshes = (Mesh[])(object)new Mesh[0]; public int Shown; public bool Reported; private bool _rigged; private static readonly HashSet<int> Hashes = new HashSet<int>(); private static readonly Dictionary<string, HairMesh.Rig> Rigs = new Dictionary<string, HairMesh.Rig>(); public static bool Diagnostics; public static void Register(string prefabName, HairMesh.Rig rig) { Hashes.Add(StringExtensionMethods.GetStableHashCode(prefabName)); Rigs[prefabName] = rig; } private void Rig() { if (!Rigs.TryGetValue(Style, out HairMesh.Rig value) || value.Names.Length == 0) { return; } try { Transform[] bones = Renderer.bones; HairSwaySim hairSwaySim = new HairSwaySim(value, bones); Renderer.bones = bones.Concat(hairSwaySim.Bones).ToArray(); ((Component)this).gameObject.AddComponent<HairSwayDriver>().Sim = hairSwaySim; } catch (Exception arg) { LongHairstylesPlugin.Log.LogError((object)$"{Style} could not be given its sway bones, so it will be drawn wrongly: {arg}"); } } } public class HairSwayDriver : MonoBehaviour { public HairSwaySim? Sim; private Player? _wearer; private Vector3 _wind; public int BoneCount { get { if (Sim == null) { return 0; } return Sim.Bones.Length; } } private void Start() { _wearer = ((Component)this).GetComponentInParent<Player>(); } private void LateUpdate() { //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_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) //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_0073: 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_003a: 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_004e: Unknown result type (might be due to invalid IL or missing references) if (Sim != null) { Vector3 val = Vector3.zero; if (Object.op_Implicit((Object)(object)EnvMan.instance) && (!Object.op_Implicit((Object)(object)_wearer) || !_wearer.InShelter())) { val = EnvMan.instance.GetWindDir() * EnvMan.instance.GetWindIntensity(); } _wind = Vector3.MoveTowards(_wind, val, 1.5f * Time.deltaTime); Sim.Wind = _wind; Sim.Step(Time.deltaTime); } } private void OnDestroy() { Sim?.Destroy(); } } public static class HairMesh { public sealed class Data { public string Name; public string[] Bones; public Vector3[] Positions; public Vector2[] Uvs; public int[][] VertexBones; public float[][] VertexWeights; public List<int>[] Triangles; public List<Chain> Chains = new List<Chain>(); public Rig Rig; public int TriangleCount { get { int num = 0; List<int>[] triangles = Triangles; foreach (List<int> list in triangles) { num += list.Count / 3; } return num; } } } public sealed class Chain { public string Id; public string Anchor; public Vector3 Root; public Vector3 Inward; public float Free = 1f; public List<int> Bones = new List<int>(); public List<Vector3> Points = new List<Vector3>(); } public sealed class Rig { public string[] Names = new string[0]; public string[] Anchors = new string[0]; public Vector3[] RestLocal = (Vector3[])(object)new Vector3[0]; public RigChain[] Chains = new RigChain[0]; } public sealed class RigChain { public string Anchor; public Vector3 RootLocal; public Vector3 InwardLocal; public float Free = 1f; public int[] Bones; } public static Data Parse(string name, string text) { //IL_01b8: 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_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01f2: 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_0331: Unknown result type (might be due to invalid IL or missing references) //IL_02d0: Unknown result type (might be due to invalid IL or missing references) List<Vector3> list = new List<Vector3>(); List<Vector2> list2 = new List<Vector2>(); List<int[]> list3 = new List<int[]>(); List<float[]> list4 = new List<float[]>(); string[] array = null; List<int>[] array2 = null; List<Chain> list5 = new List<Chain>(); int num = 0; string[] array3 = text.Split(new char[1] { '\n' }); foreach (string obj in array3) { num++; string text2 = obj.Trim(); if (text2.Length == 0 || text2[0] == '#') { continue; } string[] parts = text2.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries); try { switch (parts[0]) { case "bones": array = new string[parts.Length - 1]; Array.Copy(parts, 1, array, 0, array.Length); break; case "materials": { array2 = new List<int>[int.Parse(parts[1], CultureInfo.InvariantCulture)]; for (int l = 0; l < array2.Length; l++) { array2[l] = new List<int>(); } break; } case "chain": list5.Add(new Chain { Id = parts[1], Anchor = parts[2], Root = new Vector3(Number(parts[3]), Number(parts[4]), Number(parts[5])), Inward = new Vector3(Number(parts[6]), Number(parts[7]), Number(parts[8])), Free = ((parts.Length > 9) ? Number(parts[9]) : 1f) }); break; case "sway": { Chain? obj3 = list5.Find((Chain candidate) => candidate.Id == parts[2]) ?? throw new FormatException("no chain '" + parts[2] + "' before this line"); int num4 = Array.IndexOf(array, parts[1]); if (num4 < 0) { throw new FormatException("'" + parts[1] + "' is not in the bones line"); } obj3.Bones.Add(num4); obj3.Points.Add(new Vector3(Number(parts[3]), Number(parts[4]), Number(parts[5]))); break; } case "v": { list.Add(new Vector3(Number(parts[1]), Number(parts[2]), Number(parts[3]))); list2.Add(new Vector2(Number(parts[4]), Number(parts[5]))); int num2 = Mathf.Min(4, parts.Length - 6); if (num2 < 1) { throw new FormatException("a vertex needs at least one bone"); } int[] array4 = new int[num2]; float[] array5 = new float[num2]; float num3 = 0f; for (int j = 0; j < num2; j++) { string[] array6 = parts[6 + j].Split(new char[1] { ':' }); array4[j] = int.Parse(array6[0], CultureInfo.InvariantCulture); array5[j] = Number(array6[1]); num3 += array5[j]; } for (int k = 0; k < num2; k++) { array5[k] /= num3; } list3.Add(array4); list4.Add(array5); break; } case "f": { List<int> obj2 = array2[int.Parse(parts[4], CultureInfo.InvariantCulture)]; obj2.Add(int.Parse(parts[1], CultureInfo.InvariantCulture)); obj2.Add(int.Parse(parts[2], CultureInfo.InvariantCulture)); obj2.Add(int.Parse(parts[3], CultureInfo.InvariantCulture)); break; } default: throw new FormatException("unknown line type '" + parts[0] + "'"); } } catch (Exception ex) { throw new FormatException(name + ".hair, line " + num + ": " + ex.Message); } } if (array == null || array2 == null || list.Count == 0) { throw new FormatException(name + ".hair has no bones, materials or vertices."); } return new Data { Name = name, Bones = array, Positions = list.ToArray(), Uvs = list2.ToArray(), VertexBones = list3.ToArray(), VertexWeights = list4.ToArray(), Triangles = array2, Chains = list5 }; } private static float Number(string text) { return float.Parse(text, CultureInfo.InvariantCulture); } public static Mesh Build(Data data, Transform root, Transform[] bones, Matrix4x4[] bindposes) { //IL_00fb: 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_0102: 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_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_0211: 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_021b: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_0224: Unknown result type (might be due to invalid IL or missing references) //IL_023d: 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_0247: Unknown result type (might be due to invalid IL or missing references) //IL_0251: 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_025b: Unknown result type (might be due to invalid IL or missing references) //IL_025f: Unknown result type (might be due to invalid IL or missing references) //IL_0264: Unknown result type (might be due to invalid IL or missing references) //IL_02b8: Unknown result type (might be due to invalid IL or missing references) //IL_02bd: Unknown result type (might be due to invalid IL or missing references) //IL_02c2: 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_02f3: Unknown result type (might be due to invalid IL or missing references) //IL_0311: Unknown result type (might be due to invalid IL or missing references) //IL_0313: Unknown result type (might be due to invalid IL or missing references) //IL_0320: Unknown result type (might be due to invalid IL or missing references) //IL_0322: Unknown result type (might be due to invalid IL or missing references) //IL_0324: Unknown result type (might be due to invalid IL or missing references) //IL_0329: Unknown result type (might be due to invalid IL or missing references) //IL_032e: Unknown result type (might be due to invalid IL or missing references) //IL_0332: Unknown result type (might be due to invalid IL or missing references) //IL_0337: Unknown result type (might be due to invalid IL or missing references) //IL_0339: Unknown result type (might be due to invalid IL or missing references) //IL_033e: Unknown result type (might be due to invalid IL or missing references) //IL_03c4: Unknown result type (might be due to invalid IL or missing references) //IL_04e2: Unknown result type (might be due to invalid IL or missing references) //IL_04e7: Unknown result type (might be due to invalid IL or missing references) //IL_04f5: Expected O, but got Unknown //IL_03d5: Unknown result type (might be due to invalid IL or missing references) //IL_03da: Unknown result type (might be due to invalid IL or missing references) //IL_042b: Unknown result type (might be due to invalid IL or missing references) //IL_0430: Unknown result type (might be due to invalid IL or missing references) //IL_043c: Unknown result type (might be due to invalid IL or missing references) //IL_0441: Unknown result type (might be due to invalid IL or missing references) //IL_0446: Unknown result type (might be due to invalid IL or missing references) //IL_044d: 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_04ce: Unknown result type (might be due to invalid IL or missing references) if (bones.Length != bindposes.Length) { throw new InvalidOperationException("The body has " + bones.Length + " bones but " + bindposes.Length + " bind poses."); } int[] array = new int[data.Bones.Length]; for (int i = 0; i < array.Length; i++) { array[i] = -1; } int num = 0; foreach (Chain chain2 in data.Chains) { foreach (int bone in chain2.Bones) { array[bone] = num++; } } int[] array2 = new int[data.Bones.Length]; Matrix4x4[] array3 = (Matrix4x4[])(object)new Matrix4x4[data.Bones.Length]; Matrix4x4 worldToLocalMatrix = root.worldToLocalMatrix; Matrix4x4 val = Matrix4x4.identity; bool flag = false; for (int j = 0; j < data.Bones.Length; j++) { if (array[j] < 0) { array2[j] = Find(bones, data.Bones[j]); array3[j] = worldToLocalMatrix * bones[array2[j]].localToWorldMatrix * bindposes[array2[j]]; if (!flag) { val = array3[j]; flag = true; } } } if (!flag) { throw new InvalidOperationException(data.Name + " is weighted to no bone of the body."); } Matrix4x4[] array4 = (Matrix4x4[])(object)new Matrix4x4[bindposes.Length + num]; Array.Copy(bindposes, array4, bindposes.Length); Rig rig = new Rig { Names = new string[num], Anchors = new string[num], RestLocal = (Vector3[])(object)new Vector3[num], Chains = new RigChain[data.Chains.Count] }; Matrix4x4 val5; for (int k = 0; k < data.Chains.Count; k++) { Chain chain = data.Chains[k]; Matrix4x4 val2 = worldToLocalMatrix * bones[Find(bones, chain.Anchor)].localToWorldMatrix; Matrix4x4 inverse = ((Matrix4x4)(ref val2)).inverse; RigChain obj = new RigChain { Anchor = chain.Anchor, RootLocal = ((Matrix4x4)(ref inverse)).MultiplyPoint3x4(chain.Root) }; Vector3 val3 = ((Matrix4x4)(ref inverse)).MultiplyVector(chain.Inward); obj.InwardLocal = ((Vector3)(ref val3)).normalized; obj.Free = chain.Free; obj.Bones = new int[chain.Bones.Count]; RigChain rigChain = obj; for (int l = 0; l < chain.Bones.Count; l++) { int num2 = chain.Bones[l]; int num3 = array[num2]; Vector3 val4 = ((Matrix4x4)(ref inverse)).MultiplyPoint3x4(chain.Points[l]); rig.Names[num3] = data.Bones[num2]; rig.Anchors[num3] = chain.Anchor; rig.RestLocal[num3] = val4; rigChain.Bones[l] = num3; array2[num2] = bindposes.Length + num3; array3[num2] = val; int num4 = bindposes.Length + num3; val5 = val2 * Matrix4x4.Translate(val4); array4[num4] = ((Matrix4x4)(ref val5)).inverse * val; } rig.Chains[k] = rigChain; } data.Rig = rig; int num5 = data.Positions.Length; Vector3[] array5 = (Vector3[])(object)new Vector3[num5]; BoneWeight[] array6 = (BoneWeight[])(object)new BoneWeight[num5]; for (int m = 0; m < num5; m++) { int[] array7 = data.VertexBones[m]; float[] array8 = data.VertexWeights[m]; Matrix4x4 val6 = default(Matrix4x4); for (int n = 0; n < array7.Length; n++) { Matrix4x4 val7 = array3[array7[n]]; for (int num6 = 0; num6 < 16; num6++) { int num7 = num6; ((Matrix4x4)(ref val6))[num7] = ((Matrix4x4)(ref val6))[num7] + ((Matrix4x4)(ref val7))[num6] * array8[n]; } } int num8 = m; val5 = ((Matrix4x4)(ref val6)).inverse; array5[num8] = ((Matrix4x4)(ref val5)).MultiplyPoint3x4(data.Positions[m]); BoneWeight val8 = default(BoneWeight); ((BoneWeight)(ref val8)).boneIndex0 = array2[array7[0]]; ((BoneWeight)(ref val8)).weight0 = array8[0]; if (array7.Length > 1) { ((BoneWeight)(ref val8)).boneIndex1 = array2[array7[1]]; ((BoneWeight)(ref val8)).weight1 = array8[1]; } if (array7.Length > 2) { ((BoneWeight)(ref val8)).boneIndex2 = array2[array7[2]]; ((BoneWeight)(ref val8)).weight2 = array8[2]; } if (array7.Length > 3) { ((BoneWeight)(ref val8)).boneIndex3 = array2[array7[3]]; ((BoneWeight)(ref val8)).weight3 = array8[3]; } array6[m] = val8; } Mesh val9 = new Mesh { name = data.Name }; val9.vertices = array5; val9.uv = data.Uvs; val9.boneWeights = array6; val9.bindposes = array4; val9.subMeshCount = data.Triangles.Length; for (int num9 = 0; num9 < data.Triangles.Length; num9++) { val9.SetTriangles(data.Triangles[num9], num9); } val9.RecalculateNormals(); val9.RecalculateTangents(); val9.RecalculateBounds(); return val9; } private static int Find(Transform[] bones, string name) { for (int i = 0; i < bones.Length; i++) { if ((Object)(object)bones[i] != (Object)null && ((Object)bones[i]).name == name) { return i; } } throw new InvalidOperationException("The body has no bone named " + name + "."); } public static Bounds BoundsFor(Data data, Transform root, Transform rootBone) { //IL_0001: 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_0011: 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_003e: 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_0049: 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_0063: 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_0077: Unknown result type (might be due to invalid IL or missing references) Matrix4x4 val = rootBone.worldToLocalMatrix * root.localToWorldMatrix; Bounds result = default(Bounds); ((Bounds)(ref result))..ctor(((Matrix4x4)(ref val)).MultiplyPoint3x4(data.Positions[0]), Vector3.zero); Vector3[] positions = data.Positions; foreach (Vector3 val2 in positions) { ((Bounds)(ref result)).Encapsulate(((Matrix4x4)(ref val)).MultiplyPoint3x4(val2)); } ((Bounds)(ref result)).Expand(((Bounds)(ref result)).size * 0.3f); return result; } } public sealed class HairSwaySim { public static float Amount = 1f; private static readonly float[] Spring = new float[4] { 16f, 13f, 11f, 10f }; private static readonly float[] Reach = new float[4] { 0.04f, 0.08f, 0.12f, 0.15f }; private const float Damping = 0.25f; private const float Press = 0.01f; private const float WindReach = 1.8f; private const float WindLean = 0.4f; private const float WindSwell = 0.8f; private const float WindFlutter = 0.4f; private const float WindAcross = 0.9f; private const float WindGrip = 3f; public static float WindAmount = 1f; public Vector3 Wind; private float _clock; private readonly HairMesh.Rig _rig; private readonly Transform[] _bones; private readonly Transform[] _anchors; private readonly Vector3[] _position; private readonly Vector3[] _velocity; private bool _started; public Transform[] Bones => _bones; public HairSwaySim(HairMesh.Rig rig, Transform[] bodyBones) { //IL_0061: 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_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) _rig = rig; _bones = (Transform[])(object)new Transform[rig.Names.Length]; _position = (Vector3[])(object)new Vector3[rig.Names.Length]; _velocity = (Vector3[])(object)new Vector3[rig.Names.Length]; for (int i = 0; i < _bones.Length; i++) { Transform val = Find(bodyBones, rig.Anchors[i]); Transform transform = new GameObject(rig.Names[i]).transform; transform.SetParent(val, false); transform.localPosition = rig.RestLocal[i]; transform.localRotation = Quaternion.identity; transform.localScale = Vector3.one; _bones[i] = transform; } _anchors = (Transform[])(object)new Transform[rig.Chains.Length]; for (int j = 0; j < _anchors.Length; j++) { _anchors[j] = Find(bodyBones, rig.Chains[j].Anchor); } } private static Transform Find(Transform[] bones, string name) { foreach (Transform val in bones) { if ((Object)(object)val != (Object)null && ((Object)val).name == name) { return val; } } throw new InvalidOperationException("The body has no bone named " + name + "."); } public void Reset() { //IL_002f: Unknown result type (might be due to invalid IL or missing references) _started = false; for (int i = 0; i < _bones.Length; i++) { if ((Object)(object)_bones[i] != (Object)null) { _bones[i].localPosition = _rig.RestLocal[i]; } } } public void Step(float deltaTime) { //IL_0086: 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_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0097: 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_0090: 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_00d9: 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_00e5: 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_00ed: 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_00f7: 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_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_018b: 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_019a: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_016c: 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_0173: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: 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) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_0206: Unknown result type (might be due to invalid IL or missing references) //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Unknown result type (might be due to invalid IL or missing references) //IL_0324: Unknown result type (might be due to invalid IL or missing references) //IL_0329: Unknown result type (might be due to invalid IL or missing references) //IL_032c: Unknown result type (might be due to invalid IL or missing references) //IL_0331: Unknown result type (might be due to invalid IL or missing references) //IL_0336: Unknown result type (might be due to invalid IL or missing references) //IL_0338: Unknown result type (might be due to invalid IL or missing references) //IL_033a: Unknown result type (might be due to invalid IL or missing references) //IL_033d: Unknown result type (might be due to invalid IL or missing references) //IL_0342: Unknown result type (might be due to invalid IL or missing references) //IL_0347: Unknown result type (might be due to invalid IL or missing references) //IL_0349: Unknown result type (might be due to invalid IL or missing references) //IL_034b: Unknown result type (might be due to invalid IL or missing references) //IL_034d: Unknown result type (might be due to invalid IL or missing references) //IL_0352: Unknown result type (might be due to invalid IL or missing references) //IL_035d: Unknown result type (might be due to invalid IL or missing references) //IL_035f: Unknown result type (might be due to invalid IL or missing references) //IL_0361: Unknown result type (might be due to invalid IL or missing references) //IL_0366: Unknown result type (might be due to invalid IL or missing references) //IL_02ce: Unknown result type (might be due to invalid IL or missing references) //IL_02e7: Unknown result type (might be due to invalid IL or missing references) //IL_02ec: Unknown result type (might be due to invalid IL or missing references) //IL_02f6: Unknown result type (might be due to invalid IL or missing references) //IL_02fb: Unknown result type (might be due to invalid IL or missing references) //IL_0300: Unknown result type (might be due to invalid IL or missing references) //IL_0302: 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_0310: Unknown result type (might be due to invalid IL or missing references) //IL_0315: Unknown result type (might be due to invalid IL or missing references) //IL_031a: Unknown result type (might be due to invalid IL or missing references) //IL_038d: Unknown result type (might be due to invalid IL or missing references) //IL_038f: Unknown result type (might be due to invalid IL or missing references) //IL_0391: Unknown result type (might be due to invalid IL or missing references) //IL_0396: Unknown result type (might be due to invalid IL or missing references) //IL_0398: Unknown result type (might be due to invalid IL or missing references) //IL_039a: Unknown result type (might be due to invalid IL or missing references) //IL_0376: Unknown result type (might be due to invalid IL or missing references) //IL_037a: Unknown result type (might be due to invalid IL or missing references) //IL_0381: Unknown result type (might be due to invalid IL or missing references) //IL_0386: Unknown result type (might be due to invalid IL or missing references) //IL_038b: Unknown result type (might be due to invalid IL or missing references) //IL_03c4: Unknown result type (might be due to invalid IL or missing references) //IL_03c6: Unknown result type (might be due to invalid IL or missing references) //IL_03c8: Unknown result type (might be due to invalid IL or missing references) //IL_03cd: Unknown result type (might be due to invalid IL or missing references) //IL_03ac: Unknown result type (might be due to invalid IL or missing references) //IL_03ae: Unknown result type (might be due to invalid IL or missing references) //IL_03b8: 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_03c2: Unknown result type (might be due to invalid IL or missing references) //IL_03fc: Unknown result type (might be due to invalid IL or missing references) //IL_03fe: Unknown result type (might be due to invalid IL or missing references) //IL_0400: Unknown result type (might be due to invalid IL or missing references) //IL_0406: Unknown result type (might be due to invalid IL or missing references) //IL_040b: Unknown result type (might be due to invalid IL or missing references) //IL_0418: Unknown result type (might be due to invalid IL or missing references) //IL_041a: Unknown result type (might be due to invalid IL or missing references) //IL_0428: Unknown result type (might be due to invalid IL or missing references) //IL_042f: Unknown result type (might be due to invalid IL or missing references) //IL_0431: Unknown result type (might be due to invalid IL or missing references) //IL_0433: Unknown result type (might be due to invalid IL or missing references) //IL_0435: Unknown result type (might be due to invalid IL or missing references) //IL_03dd: Unknown result type (might be due to invalid IL or missing references) //IL_03e1: Unknown result type (might be due to invalid IL or missing references) //IL_03e8: Unknown result type (might be due to invalid IL or missing references) //IL_03ed: Unknown result type (might be due to invalid IL or missing references) //IL_03f2: Unknown result type (might be due to invalid IL or missing references) if (Amount <= 0f) { if (_started) { Reset(); } } else { if (deltaTime <= 0f) { return; } float num = Mathf.Min(deltaTime, 1f / 30f); _clock += num; float num2 = ((Vector3)(ref Wind)).magnitude * WindAmount; bool flag = num2 > 0.001f; float num3 = (flag ? (1f - Mathf.Exp(-3f * num2)) : 0f); Vector3 val = (flag ? ((Vector3)(ref Wind)).normalized : Vector3.zero); Vector3 val2 = (flag ? Vector3.Cross(Vector3.up, val) : Vector3.zero); for (int i = 0; i < _rig.Chains.Length; i++) { HairMesh.RigChain rigChain = _rig.Chains[i]; Transform val3 = _anchors[i]; if ((Object)(object)val3 == (Object)null) { continue; } Vector3 val4 = val3.TransformPoint(rigChain.RootLocal); Vector3 val5 = val4; Vector3 val6 = val3.TransformDirection(rigChain.InwardLocal); Vector3 normalized = ((Vector3)(ref val6)).normalized; for (int j = 0; j < rigChain.Bones.Length; j++) { int num4 = rigChain.Bones[j]; if ((Object)(object)_bones[num4] == (Object)null) { continue; } Vector3 val7 = val3.TransformPoint(_rig.RestLocal[num4]); int num5 = Mathf.Min(j, Spring.Length - 1); if (_started) { val6 = _position[num4] - val7; if (!(((Vector3)(ref val6)).sqrMagnitude > 2.25f)) { goto IL_01a4; } } _position[num4] = val7; _velocity[num4] = Vector3.zero; goto IL_01a4; IL_01a4: Vector3 val8 = _position[num4]; float num6 = Mathf.Max(0.25f, Amount * rigChain.Free); float num7 = Spring[num5] / Mathf.Sqrt(num6); Vector3 val9 = (val7 - val8) * (num7 * num7) - _velocity[num4] * (0.5f * num7); float num8 = Reach[num5] * Amount * rigChain.Free * (1f + 1.8f * num3 * WindAmount); if (flag) { float num9 = Mathf.PerlinNoise(_clock * 0.8f + (float)i * 7.3f, (float)j * 1.7f); float num10 = Mathf.PerlinNoise(_clock * 2.6f + (float)i * 3.1f, 5f + (float)j * 2.3f) - 0.5f; float num11 = Mathf.PerlinNoise(_clock * 1.1f + (float)i * 5.7f, 11f + (float)j * 1.3f) - 0.5f; Vector3 val10 = val * (0.4f + 0.8f * num9 + 0.4f * num10) + val2 * (0.9f * num11); val9 += val10 * (num8 * num3 * num7 * num7); } Vector3 val11 = _velocity[num4] + val9 * num; Vector3 val12 = val8 + val11 * num; val6 = val7 - val5; float magnitude = ((Vector3)(ref val6)).magnitude; Vector3 val13 = val12 - val4; if (((Vector3)(ref val13)).sqrMagnitude > 1E-10f) { val12 = val4 + ((Vector3)(ref val13)).normalized * magnitude; } Vector3 val14 = val12 - val7; float num12 = Vector3.Dot(val14, normalized); if (num12 > 0.01f) { val12 -= normalized * (num12 - 0.01f); } val14 = val12 - val7; if (((Vector3)(ref val14)).sqrMagnitude > num8 * num8) { val12 = val7 + ((Vector3)(ref val14)).normalized * num8; } _velocity[num4] = (val12 - val8) / num; _position[num4] = val12; _bones[num4].position = val12; val4 = val12; val5 = val7; } } _started = true; } } public void Destroy() { Transform[] bones = _bones; foreach (Transform val in bones) { if (!((Object)(object)val == (Object)null)) { if (Application.isPlaying) { Object.Destroy((Object)(object)((Component)val).gameObject); } else { Object.DestroyImmediate((Object)(object)((Component)val).gameObject); } } } } } [BepInPlugin("com.skaket.valheim.longhairstyles", "Long Hairstyles", "1.1.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class LongHairstylesPlugin : BaseUnityPlugin { public const string PluginGuid = "com.skaket.valheim.longhairstyles"; public const string PluginName = "Long Hairstyles"; public const string PluginVersion = "1.1.1"; internal static ManualLogSource Log; private ConfigEntry<bool> _diagnostics; private ConfigEntry<float> _sway; private ConfigEntry<float> _wind; private readonly List<string> _added = new List<string>(); private void Awake() { //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Expected O, but got Unknown //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Expected O, but got Unknown //IL_010b: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; _diagnostics = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Diagnostics", false, "Write test lines to the log: whether the game's hair list holds the new styles, what the hair screens allow, and what a character wearing one of the styles is drawn with. Takes effect on the next launch."); HairFit.Diagnostics = _diagnostics.Value; _sway = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Sway", 1f, new ConfigDescription("How much the hair below the shoulders swings when the character moves. 0 holds it still, 1 is the normal swing, 2 is the loosest. Swinging hair can pass through arms, capes and armour. Can be changed while the game runs.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>())); HairSwaySim.Amount = _sway.Value; _sway.SettingChanged += delegate { HairSwaySim.Amount = _sway.Value; }; _wind = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Wind", 1f, new ConfigDescription("How much the wind moves the hair below the shoulders. 0 leaves it out of the wind, 1 is the normal movement, 3 is the strongest. Hair is out of the wind under shelter, and Sway at 0 stills it too. Can be changed while the game runs.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>())); HairSwaySim.WindAmount = _wind.Value; _wind.SettingChanged += delegate { HairSwaySim.WindAmount = _wind.Value; }; new Harmony("com.skaket.valheim.longhairstyles").PatchAll(typeof(LongHairstylesPlugin).Assembly); PrefabManager.OnVanillaPrefabsAvailable += AddStyles; if (_diagnostics.Value) { ItemManager.OnItemsRegisteredFejd += delegate { ReportList("main menu"); }; ItemManager.OnItemsRegistered += delegate { ReportList("game"); }; } } private void AddStyles() { PrefabManager.OnVanillaPrefabsAvailable -= AddStyles; VisEquipment val = FindPlayer(); if (!Object.op_Implicit((Object)(object)val)) { Log.LogError((object)"The Player prefab was not found, so no hairstyles were added."); return; } HairDef[] all = HairDefs.All; foreach (HairDef hairDef in all) { try { HairFactory.Add(hairDef, val, _diagnostics.Value); _added.Add(hairDef.Id); } catch (Exception arg) { Log.LogError((object)$"{hairDef.Id} was not added: {arg}"); } } } private static VisEquipment? FindPlayer() { GameObject prefab = PrefabManager.Instance.GetPrefab("Player"); VisEquipment val = (Object.op_Implicit((Object)(object)prefab) ? prefab.GetComponent<VisEquipment>() : null); if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.m_bodyModel)) { val = ((IEnumerable<VisEquipment>)Resources.FindObjectsOfTypeAll<VisEquipment>()).FirstOrDefault((Func<VisEquipment, bool>)((VisEquipment candidate) => Object.op_Implicit((Object)(object)candidate) && ((Object)((Component)candidate).gameObject).name == "Player" && Object.op_Implicit((Object)(object)candidate.m_bodyModel) && candidate.m_bodyModel.bones.Length != 0)); } if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.m_bodyModel)) { return null; } return val; } private void ReportList(string where) { //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) try { if (!Object.op_Implicit((Object)(object)ObjectDB.instance)) { return; } List<ItemDrop> allItems = ObjectDB.instance.GetAllItems((ItemType)10, "Hair"); allItems.RemoveAll((ItemDrop hair) => ((Object)hair).name.Contains("_")); List<string> list = (from hair in allItems where _added.Contains(((Object)hair).name) select $"{((Object)hair).name} \"{hair.m_itemData.m_shared.m_name}\" tier {hair.m_itemData.m_shared.m_toolTier}").ToList(); string text = string.Join(", ", from hair in allItems group hair by hair.m_itemData.m_shared.m_toolTier into @group orderby @group.Key select $"tier {@group.Key}: {@group.Count()}"); Log.LogInfo((object)string.Format("[test] Hair list in the {0}: {1} styles ({2}); ours in it: {3}", where, allItems.Count, text, (list.Count == 0) ? "NONE" : string.Join("; ", list))); PlayerCustomizaton[] array = Resources.FindObjectsOfTypeAll<PlayerCustomizaton>(); foreach (PlayerCustomizaton val in array) { if (Object.op_Implicit((Object)(object)val)) { Log.LogInfo((object)($"[test] Hair screen '{((Object)((Component)val).gameObject).name}' in the {where}: shows styles up to tool tier {val.m_hairToolTier}; " + $"hair colour from {Describe(val.m_hairColor0)} to {Describe(val.m_hairColor1)}, brightness {val.m_hairMinLevel:0.##} to {val.m_hairMaxLevel:0.##}")); } } } catch (Exception ex) { Log.LogWarning((object)("[test] The hair list could not be read in the " + where + ": " + ex.Message)); } } private static string Describe(Color colour) { //IL_0005: 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_001b: Unknown result type (might be due to invalid IL or missing references) return $"({colour.r:0.##}, {colour.g:0.##}, {colour.b:0.##})"; } } }