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 Skas Jewelry v1.0.0
Jewelry.dll
Decompiled 2 weeks agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using Jotunn.Configs; 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("Jewelry")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("Jewelry")] [assembly: AssemblyTitle("Jewelry")] [assembly: AssemblyVersion("1.0.0.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 Jewelry { internal sealed class BodyFit : MonoBehaviour { public const string First = "model"; public const string Second = "model_F"; public const string Slim = "model_FF"; private const string FeminineFigureGuid = "com.skaket.valheim.femininefigure"; private const float CheckSeconds = 1f; private static bool? _feminineFigure; private VisEquipment? _equipment; private float _nextCheck; public string Shown { get; private set; } = "model"; internal static bool FeminineFigureInstalled { get { if (!_feminineFigure.HasValue) { _feminineFigure = Chainloader.PluginInfos.ContainsKey("com.skaket.valheim.femininefigure"); } return _feminineFigure.Value; } } public static string Pick(Transform holder, int bodyShape) { if (bodyShape != 1) { return "model"; } if (FeminineFigureInstalled && Object.op_Implicit((Object)(object)holder.Find("model_FF"))) { return "model_FF"; } if (!Object.op_Implicit((Object)(object)holder.Find("model_F"))) { return "model"; } return "model_F"; } private void OnEnable() { Apply(); } private void Update() { if (Time.unscaledTime >= _nextCheck) { Apply(); } } private void Apply() { //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Expected O, but got Unknown _nextCheck = Time.unscaledTime + 1f; if (!Object.op_Implicit((Object)(object)_equipment)) { _equipment = ((Component)this).GetComponentInParent<VisEquipment>(); } Shown = Pick(((Component)this).transform, Object.op_Implicit((Object)(object)_equipment) ? _equipment.GetModelIndex() : 0); foreach (Transform item in ((Component)this).transform) { Transform val = item; bool flag = ((Object)val).name == Shown; if (((Component)val).gameObject.activeSelf != flag) { ((Component)val).gameObject.SetActive(flag); } } } } internal enum JewelryKind { Ring, Necklace, Earrings } internal enum JewelrySlot { Utility, Trinket } internal sealed class JewelryDef { public string Id { get; set; } = ""; public JewelryKind Kind { get; set; } public string Name { get; set; } = ""; public string Description { get; set; } = ""; public string Joint { get; set; } = ""; public string CraftingStation { get; set; } = CraftingStations.Forge; public List<(string Item, int Amount)> Recipe { get; set; } = new List<(string, int)>(); public string NameToken => "item_" + Id.ToLowerInvariant(); public string DescriptionToken => NameToken + "_description"; public string JointName { get { if (!(Joint != "")) { return DefaultJoint(Kind); } return Joint; } } public static string DefaultJoint(JewelryKind kind) { return kind switch { JewelryKind.Ring => "LeftHandRing1", JewelryKind.Necklace => "Spine2", _ => "Head", }; } } internal static class JewelryDefs { public static readonly JewelryDef[] All = new JewelryDef[18] { Piece("SkaDiamondRing", JewelryKind.Ring, "Diamond Ring", "A gold ring set with a sparkling diamond.", ("Coins", 100), ("Crystal", 2)), Piece("SkaEmeraldRing", JewelryKind.Ring, "Emerald Ring", "A gold ring set with a green emerald.", ("Coins", 100), ("GemstoneGreen", 1)), Piece("SkaRubyRing", JewelryKind.Ring, "Ruby Ring", "A gold ring set with a red ruby.", ("Coins", 100), ("Ruby", 2)), Piece("SkaSpinelRing", JewelryKind.Ring, "Spinel Ring", "A gold ring set with a pink spinel.", ("Coins", 100), ("Ruby", 1), ("Crystal", 1)), Piece("SkaSapphireRing", JewelryKind.Ring, "Sapphire Ring", "A gold ring set with a blue sapphire.", ("Coins", 100), ("GemstoneBlue", 1)), Piece("SkaAquamarineRing", JewelryKind.Ring, "Aquamarine Ring", "A gold ring set with a cyan aquamarine.", ("Coins", 100), ("Crystal", 1), ("GemstoneBlue", 1)), Piece("SkaGoldHoops", JewelryKind.Earrings, "Gold Hoops", "A pair of gold hoops.", ("Coins", 100)), Piece("SkaSilverHoops", JewelryKind.Earrings, "Silver Hoops", "A pair of silver hoops.", ("Silver", 1)), Piece("SkaDiamondStuds", JewelryKind.Earrings, "Diamond Studs", "A diamond for each ear, set in silver.", ("Silver", 1), ("Crystal", 2)), Piece("SkaPinkJewelDrops", JewelryKind.Earrings, "Pink Jewel Drop", "A small pink stone for each ear with a pink drop hanging from it.", ("Coins", 100), ("Ruby", 2)), Piece("SkaPearlEarrings", JewelryKind.Earrings, "Pearl Earrings", "A pearl for each ear.", ("Coins", 50), ("AmberPearl", 2)), Piece("SkaEmeraldDangles", JewelryKind.Earrings, "Emerald Dangle", "A square-cut emerald in a gold frame, hanging from a smaller one.", ("Coins", 100), ("GemstoneGreen", 2)), Piece("SkaPinkJewelNecklace", JewelryKind.Necklace, "Pink Jewel Necklace", "A gold chain with a pink jewel at its centre.", ("Coins", 200), ("Ruby", 1)), Piece("SkaHeartNecklace", JewelryKind.Necklace, "Heart Necklace", "A silver chain with a red heart.", ("Silver", 2), ("Ruby", 1)), Piece("SkaEmeraldNecklace", JewelryKind.Necklace, "Emerald Necklace", "A gold necklace with green emeralds along its whole length.", ("Coins", 300), ("GemstoneGreen", 5)), On("Neck", Piece("SkaWovenCollar", JewelryKind.Necklace, "Woven Silver Collar", "A woven silver band worn close round the neck.", ("Silver", 4))), Piece("SkaThreeGemNecklace", JewelryKind.Necklace, "Three Gem Necklace", "A silver chain with three small gems and a fourth hanging below.", ("Silver", 2), ("Crystal", 4)), On("Neck", Piece("SkaBlackChoker", JewelryKind.Necklace, "Black Choker", "A plain black band for the neck.", ("DeerHide", 1), ("Coal", 1))) }; private static JewelryDef Piece(string id, JewelryKind kind, string name, string description, params (string Item, int Amount)[] recipe) { JewelryDef jewelryDef = new JewelryDef(); jewelryDef.Id = id; jewelryDef.Kind = kind; jewelryDef.Name = name; jewelryDef.Description = description; jewelryDef.Recipe.AddRange(recipe); return jewelryDef; } private static JewelryDef On(string joint, JewelryDef def) { def.Joint = joint; return def; } } internal sealed class JewelryDiagnostics : MonoBehaviour { private const float SettleSeconds = 3f; private const float CheckSeconds = 0.5f; private const float WornReportDelay = 1f; private static readonly FieldInfo? UtilityInstancesField = PrivateField("m_utilityItemInstances"); private static readonly FieldInfo? TrinketInstancesField = PrivateField("m_trinketItemInstances"); private Player? _player; private float _readyAt; private float _nextCheck; private bool _introDone; private string _inventoryState = ""; private string _wornKey = ""; private float _wornReportAt = float.MaxValue; public bool LogState { get; set; } public bool GiveItems { get; set; } private static FieldInfo? PrivateField(string name) { return typeof(VisEquipment).GetField(name, BindingFlags.Instance | BindingFlags.NonPublic); } private void Update() { if (!LogState && !GiveItems) { return; } float unscaledTime = Time.unscaledTime; if (unscaledTime < _nextCheck) { return; } _nextCheck = unscaledTime + 0.5f; Player localPlayer = Player.m_localPlayer; if (!Object.op_Implicit((Object)(object)localPlayer)) { _player = null; return; } if ((Object)(object)localPlayer != (Object)(object)_player) { _player = localPlayer; _readyAt = unscaledTime + 3f; _introDone = false; _inventoryState = (_wornKey = ""); _wornReportAt = float.MaxValue; } if (unscaledTime < _readyAt || !Object.op_Implicit((Object)(object)ObjectDB.instance)) { return; } try { if (!_introDone) { _introDone = true; if (LogState) { ReportRegistration(localPlayer); } if (GiveItems) { Give(localPlayer); } } if (LogState) { ReportInventory(localPlayer); ReportWorn(localPlayer, unscaledTime); } } catch (Exception arg) { JewelryPlugin.Log.LogWarning((object)$"Diagnostics stopped after an error: {arg}"); LogState = false; GiveItems = false; } } private static void ReportRegistration(Player player) { JewelryDef[] all = JewelryDefs.All; foreach (JewelryDef def in all) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(def.Id); Recipe val = ((IEnumerable<Recipe>)ObjectDB.instance.m_recipes).FirstOrDefault((Func<Recipe, bool>)((Recipe r) => Object.op_Implicit((Object)(object)r) && Object.op_Implicit((Object)(object)r.m_item) && ((Object)((Component)r.m_item).gameObject).name == def.Id)); string text = "no recipe"; if ((Object)(object)val != (Object)null) { string text2 = string.Join(", ", val.m_resources.Select((Requirement r) => string.Format("{0} {1}", r.m_amount, Object.op_Implicit((Object)(object)r.m_resItem) ? ((Object)r.m_resItem).name : "?"))); string text3 = (Object.op_Implicit((Object)(object)val.m_craftingStation) ? Localization.instance.Localize(val.m_craftingStation.m_name) : "no crafting station"); text = "recipe at " + text3 + " for " + text2; } BuiltPiece builtPiece = JewelryPlugin.Pieces.FirstOrDefault((BuiltPiece p) => p.Def.Id == def.Id); string text4 = (Object.op_Implicit((Object)(object)itemPrefab) ? ((object)Unsafe.As<ItemType, ItemType>(ref itemPrefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_itemType)/*cast due to .constrained prefix*/).ToString() : "?"); string text5 = (Object.op_Implicit((Object)(object)itemPrefab) ? string.Join(", ", from Transform child in (IEnumerable)itemPrefab.transform select ((Object)child).name) : ""); Say(def.Id + ": " + (Object.op_Implicit((Object)(object)itemPrefab) ? "in the item database" : "NOT in the item database") + ", type " + text4 + ", parts [" + text5 + "], " + ((builtPiece != null && builtPiece.Placed) ? "set against its bone" : "NOT set against its bone") + ", " + text); } } private static void Give(Player player) { Inventory inventory = ((Humanoid)player).GetInventory(); List<string> list = new List<string>(); List<string> list2 = new List<string>(); JewelryDef[] all = JewelryDefs.All; foreach (JewelryDef jewelryDef in all) { if (Owned(inventory, jewelryDef.Id).Any()) { continue; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(jewelryDef.Id); if (Object.op_Implicit((Object)(object)itemPrefab)) { if (!inventory.CanAddItem(itemPrefab, 1)) { Say("GiveItemsOnSpawn: no room in the inventory for " + jewelryDef.Id); list2.Add(jewelryDef.Name); } else { inventory.AddItem(itemPrefab, 1); Say("GiveItemsOnSpawn: added " + jewelryDef.Id + " to the inventory"); list.Add(jewelryDef.Name); } } } List<string> list3 = new List<string>(); if (list.Count > 0) { list3.Add("Test items added to your inventory: " + string.Join(", ", list)); } if (list2.Count > 0) { list3.Add("No room in the inventory for: " + string.Join(", ", list2)); } if (list3.Count > 0) { ((Character)player).Message((MessageType)2, string.Join("\n", list3), 0, (Sprite)null, false); } } private void ReportInventory(Player player) { Inventory inventory = ((Humanoid)player).GetInventory(); List<string> list = new List<string>(); JewelryDef[] all = JewelryDefs.All; foreach (JewelryDef jewelryDef in all) { foreach (ItemData item in Owned(inventory, jewelryDef.Id)) { list.Add(string.Format("{0} in slot ({1}, {2}){3}", jewelryDef.Id, item.m_gridPos.x, item.m_gridPos.y, item.m_equipped ? ", equipped" : "")); } } string text = ((list.Count == 0) ? "none of this mod's items" : string.Join("; ", list)); if (!(text == _inventoryState)) { _inventoryState = text; Say("Inventory: " + text); } } private void ReportWorn(Player player, float now) { //IL_0268: Unknown result type (might be due to invalid IL or missing references) //IL_02ee: Unknown result type (might be due to invalid IL or missing references) //IL_02f3: Unknown result type (might be due to invalid IL or missing references) //IL_0309: 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_0333: Unknown result type (might be due to invalid IL or missing references) //IL_038a: Unknown result type (might be due to invalid IL or missing references) //IL_039f: Unknown result type (might be due to invalid IL or missing references) //IL_03c5: Unknown result type (might be due to invalid IL or missing references) //IL_03cc: Unknown result type (might be due to invalid IL or missing references) VisEquipment equipment = ((Component)player).GetComponent<VisEquipment>(); if (!Object.op_Implicit((Object)(object)equipment)) { return; } (string, ItemType, FieldInfo)[] array = new(string, ItemType, FieldInfo)[2] { ("Utility", (ItemType)18, UtilityInstancesField), ("Trinket", (ItemType)24, TrinketInstancesField) }; List<ItemData> equipped = ((Humanoid)player).GetInventory().GetEquippedItems(); string text = string.Join("|", array.Select(delegate((string Name, ItemType Type, FieldInfo Field) tuple) { ItemData val3 = ((IEnumerable<ItemData>)equipped).FirstOrDefault((Func<ItemData, bool>)((ItemData i) => i.m_shared.m_itemType == tuple.Type)); List<GameObject> list2 = tuple.Field?.GetValue(equipment) as List<GameObject>; return string.Format("{0}/{1}", (val3 == null) ? "" : PrefabName(val3), list2?.Count ?? 0); })); if (text != _wornKey) { _wornKey = text; _wornReportAt = now + 1f; } if (now < _wornReportAt) { return; } _wornReportAt = float.MaxValue; (string, ItemType, FieldInfo)[] array2 = array; for (int num = 0; num < array2.Length; num++) { (string Name, ItemType Type, FieldInfo Field) slot = array2[num]; ItemData item = ((IEnumerable<ItemData>)equipped).FirstOrDefault((Func<ItemData, bool>)((ItemData i) => i.m_shared.m_itemType == slot.Type)); if (item == null) { Say(slot.Name + " slot: empty"); continue; } StringBuilder stringBuilder = new StringBuilder(slot.Name + " slot: " + PrefabName(item) + ". "); if (slot.Field?.GetValue(equipment) is List<GameObject> { Count: not 0 } list) { BuiltPiece builtPiece = JewelryPlugin.Pieces.FirstOrDefault((BuiltPiece p) => p.Def.Id == PrefabName(item)); foreach (GameObject item2 in list.Where((GameObject i) => Object.op_Implicit((Object)(object)i))) { Transform transform = item2.transform; Transform parent = transform.parent; stringBuilder.Append("Hung '" + ((Object)item2).name + "' on '" + (Object.op_Implicit((Object)(object)parent) ? ((Object)parent).name : "nothing") + "', " + $"active {item2.activeInHierarchy}, world scale {Vec(transform.lossyScale)}."); BodyFit componentInChildren = item2.GetComponentInChildren<BodyFit>(); string text2 = (Object.op_Implicit((Object)(object)componentInChildren) ? componentInChildren.Shown : "model"); stringBuilder.Append($" Body shape {equipment.GetModelIndex()}, model '{text2}' shown."); Renderer[] componentsInChildren = item2.GetComponentsInChildren<Renderer>(false); if (componentsInChildren.Length == 0) { stringBuilder.Append(" It has no renderers."); continue; } Bounds bounds = componentsInChildren[0].bounds; Renderer[] array3 = componentsInChildren; foreach (Renderer val in array3) { ((Bounds)(ref bounds)).Encapsulate(val.bounds); } Vector3 v = ((Component)player).transform.InverseTransformPoint(((Bounds)(ref bounds)).center); stringBuilder.Append($" {componentsInChildren.Length} renderer(s), {componentsInChildren.Count((Renderer r) => r.isVisible)} on screen; " + "size " + Vec(((Bounds)(ref bounds)).size) + " m; its middle is at " + Vec(v) + " from the character's feet (x to its right, y up, z forward, in the pose of the moment)"); if (Object.op_Implicit((Object)(object)parent)) { float num3 = Vector3.Distance(((Bounds)(ref bounds)).center, parent.position); stringBuilder.Append($" and {num3 * 1000f:0} mm from the bone"); if (builtPiece != null && builtPiece.Placed) { stringBuilder.Append($" (built for {builtPiece.CentreFromJoint(text2) * 1000f:0} mm; these should agree to within a few mm)"); } } stringBuilder.Append('.'); array3 = componentsInChildren; foreach (Renderer val2 in array3) { Material sharedMaterial = val2.sharedMaterial; stringBuilder.AppendLine(); stringBuilder.Append($" renderer '{((Object)val2).name}': enabled {val2.enabled}, layer {LayerMask.LayerToName(((Component)val2).gameObject.layer)}, " + (Object.op_Implicit((Object)(object)sharedMaterial) ? $"material '{((Object)sharedMaterial).name}', shader '{((Object)sharedMaterial.shader).name}' (supported {sharedMaterial.shader.isSupported})" : "no material")); } } Say(stringBuilder.ToString()); } else { stringBuilder.Append("The game has hung nothing on the character for it."); Say(stringBuilder.ToString()); } } } private static IEnumerable<ItemData> Owned(Inventory inventory, string id) { return from item in inventory.GetAllItems() where PrefabName(item) == id select item; } private static string PrefabName(ItemData item) { if (!Object.op_Implicit((Object)(object)item.m_dropPrefab)) { return item.m_shared.m_name; } return ((Object)item.m_dropPrefab).name; } private static string Num(float value) { return value.ToString("0.000", CultureInfo.InvariantCulture); } private static string Vec(Vector3 v) { //IL_0010: 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_003c: Unknown result type (might be due to invalid IL or missing references) return "(" + Num(v.x) + ", " + Num(v.y) + ", " + Num(v.z) + ")"; } private static void Say(string message) { JewelryPlugin.Log.LogInfo((object)("[test] " + message)); } } internal sealed class BuiltPiece { public JewelryDef Def; public SharedData Shared; public Transform WornVisual; public readonly Dictionary<string, Vector3> ModelCentres = new Dictionary<string, Vector3>(); public bool Placed; public Vector3 JointPosition; public float CentreFromJoint(string model) { //IL_0022: 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_0024: Unknown result type (might be due to invalid IL or missing references) Vector3 value; return Vector3.Distance(ModelCentres.TryGetValue(model, out value) ? value : ModelCentres["model"], JointPosition); } } internal static class JewelryFactory { private const string BasePrefab = "HelmetRootCrown"; private const string ModelSuffix = "_model"; private const float GroundSize = 0.18f; private static readonly Quaternion IconRotation = Quaternion.Euler(20f, 0f, 0f) * Quaternion.Euler(0f, 25f, 0f); private static readonly (string Suffix, string Name)[] OtherFits = new(string, string)[2] { ("_F", "model_F"), ("_FF", "model_FF") }; public static BuiltPiece Add(AssetBundle bundle, JewelryDef def, JewelrySlot slot, bool useGameShader) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Expected O, but got Unknown //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Expected O, but got Unknown //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Expected O, but got Unknown //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Expected O, but got Unknown //IL_02d1: Unknown result type (might be due to invalid IL or missing references) //IL_02d6: Unknown result type (might be due to invalid IL or missing references) //IL_02dd: Unknown result type (might be due to invalid IL or missing references) //IL_02e2: Unknown result type (might be due to invalid IL or missing references) //IL_02f1: Expected O, but got Unknown //IL_0323: 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_0341: Unknown result type (might be due to invalid IL or missing references) //IL_0374: Unknown result type (might be due to invalid IL or missing references) //IL_0385: Unknown result type (might be due to invalid IL or missing references) //IL_038c: Unknown result type (might be due to invalid IL or missing references) //IL_039f: Unknown result type (might be due to invalid IL or missing references) //IL_03a4: Unknown result type (might be due to invalid IL or missing references) //IL_03ab: Unknown result type (might be due to invalid IL or missing references) //IL_03bf: Unknown result type (might be due to invalid IL or missing references) //IL_03cb: Unknown result type (might be due to invalid IL or missing references) //IL_03d0: Unknown result type (might be due to invalid IL or missing references) //IL_03dd: Unknown result type (might be due to invalid IL or missing references) //IL_03e2: Unknown result type (might be due to invalid IL or missing references) //IL_0409: Unknown result type (might be due to invalid IL or missing references) //IL_040e: Unknown result type (might be due to invalid IL or missing references) //IL_058c: Unknown result type (might be due to invalid IL or missing references) //IL_059d: Unknown result type (might be due to invalid IL or missing references) //IL_05ae: Unknown result type (might be due to invalid IL or missing references) //IL_0644: Unknown result type (might be due to invalid IL or missing references) //IL_0649: Unknown result type (might be due to invalid IL or missing references) //IL_064d: Unknown result type (might be due to invalid IL or missing references) string text = def.Id + "_model"; GameObject val = bundle.LoadAsset<GameObject>(text); if (!Object.op_Implicit((Object)(object)val)) { throw new InvalidOperationException("The bundle has no prefab named " + text + "."); } ItemConfig val2 = new ItemConfig { Name = "$" + def.NameToken, Description = "$" + def.DescriptionToken, CraftingStation = def.CraftingStation }; foreach (var (text2, num) in def.Recipe) { val2.AddRequirement(text2, num, 0); } CustomItem val3 = new CustomItem(def.Id, "HelmetRootCrown", val2); GameObject itemPrefab = val3.ItemPrefab; if (!Object.op_Implicit((Object)(object)itemPrefab)) { throw new InvalidOperationException("Could not clone HelmetRootCrown."); } Transform val4 = itemPrefab.transform.Find("attach"); if (!Object.op_Implicit((Object)(object)val4)) { throw new InvalidOperationException("HelmetRootCrown has no 'attach' child."); } Renderer componentInChildren = ((Component)val4).GetComponentInChildren<Renderer>(true); Shader val5 = ((Object.op_Implicit((Object)(object)componentInChildren) && Object.op_Implicit((Object)(object)componentInChildren.sharedMaterial)) ? componentInChildren.sharedMaterial.shader : null); for (int num2 = val4.childCount - 1; num2 >= 0; num2--) { Object.DestroyImmediate((Object)(object)((Component)val4.GetChild(num2)).gameObject); } val4.localPosition = Vector3.zero; val4.localRotation = Quaternion.identity; val4.localScale = Vector3.one; GameObject val6 = new GameObject("attach_" + def.JointName) { layer = itemPrefab.layer }; val6.transform.SetParent(itemPrefab.transform, false); GameObject val7 = new GameObject("visual"); val7.transform.SetParent(val6.transform, false); GameObject val8 = Object.Instantiate<GameObject>(val, val7.transform, false); ((Object)val8).name = "model"; List<GameObject> list = new List<GameObject> { val8 }; (string, string)[] otherFits = OtherFits; for (int i = 0; i < otherFits.Length; i++) { (string, string) tuple2 = otherFits[i]; string item = tuple2.Item1; string item2 = tuple2.Item2; GameObject val9 = bundle.LoadAsset<GameObject>(def.Id + item + "_model"); if (Object.op_Implicit((Object)(object)val9)) { GameObject val10 = Object.Instantiate<GameObject>(val9, val7.transform, false); ((Object)val10).name = item2; val10.SetActive(false); list.Add(val10); } } if (list.Count > 1) { val7.AddComponent<BodyFit>(); } SetLayer(val7, itemPrefab.layer); int num3 = PrepareMaterials(val7, useGameShader ? val5 : null); Bounds val11 = ModelBounds(val7.transform, val8); GameObject val12 = new GameObject("visual") { layer = itemPrefab.layer }; val12.transform.SetParent(val4, false); ((Object)Object.Instantiate<GameObject>(val8, val12.transform, false)).name = "model"; float num4 = Mathf.Max(new float[3] { ((Bounds)(ref val11)).size.x, ((Bounds)(ref val11)).size.y, ((Bounds)(ref val11)).size.z }); float num5 = ((num4 < 0.18f) ? (0.18f / num4) : 1f); val12.transform.localRotation = Quaternion.identity; val12.transform.localScale = Vector3.one * num5; val12.transform.localPosition = -((Bounds)(ref val11)).center * num5; BoxCollider obj = val12.AddComponent<BoxCollider>(); obj.center = ((Bounds)(ref val11)).center; obj.size = Vector3.Max(((Bounds)(ref val11)).size, Vector3.one * (0.03f / num5)); val6.SetActive(false); SharedData shared = val3.ItemDrop.m_itemData.m_shared; shared.m_itemType = ItemType(slot); shared.m_armor = 0f; shared.m_armorPerLevel = 0f; shared.m_maxQuality = 1; shared.m_weight = 0.1f; shared.m_useDurability = false; Sprite val13 = RenderIcon(val4, def.Id); if (Object.op_Implicit((Object)(object)val13)) { shared.m_icons = (Sprite[])(object)new Sprite[1] { val13 }; } else { JewelryPlugin.Log.LogWarning((object)(def.Id + ": the icon could not be rendered; it keeps the HelmetRootCrown icon.")); } if (!ItemManager.Instance.AddItem(val3)) { throw new InvalidOperationException("Jotunn refused to add " + def.Id + "."); } JewelryPlugin.Log.LogInfo((object)($"Added {def.Id}: a {def.Kind} in the {slot} slot, worn on {def.JointName}, " + string.Format("fitted to {0} body shape(s) [{1}], {2} material(s) ", list.Count, string.Join(", ", list.Select((GameObject fit) => ((Object)fit).name)), num3) + "(" + ((useGameShader && Object.op_Implicit((Object)(object)val5)) ? ("game shader " + ((Object)val5).name) : "bundle shader") + "), " + $"model size {((Bounds)(ref val11)).size.x:0.###} x {((Bounds)(ref val11)).size.y:0.###} x {((Bounds)(ref val11)).size.z:0.###} m, " + string.Format("shown {0:0.#} times larger on the ground, icon {1}", num5, Object.op_Implicit((Object)(object)val13) ? "rendered" : "vanilla"))); BuiltPiece builtPiece = new BuiltPiece { Def = def, Shared = shared, WornVisual = val7.transform }; foreach (GameObject item3 in list) { Dictionary<string, Vector3> modelCentres = builtPiece.ModelCentres; string name = ((Object)item3).name; Bounds val14 = ModelBounds(val7.transform, item3); modelCentres[name] = ((Bounds)(ref val14)).center; } return builtPiece; } public static bool Place(BuiltPiece piece, out string problem) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0026: 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_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_0039: 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_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_009f: 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_00b5: Unknown result type (might be due to invalid IL or missing references) if (!Skeleton.TryGetRestPose(piece.Def.JointName, out var position, out var rotation, out problem)) { return false; } Quaternion val = Quaternion.Inverse(rotation); piece.WornVisual.localRotation = val; piece.WornVisual.localPosition = val * -position; piece.WornVisual.localScale = Vector3.one; piece.JointPosition = position; piece.Placed = true; JewelryPlugin.Log.LogInfo((object)(piece.Def.Id + ": set against " + piece.Def.JointName + ", which rests at " + $"({position.x:0.000}, {position.y:0.000}, {position.z:0.000}) in the character's space; " + string.Format("the model's middle is {0:0} mm from it", piece.CentreFromJoint("model") * 1000f))); return true; } public static ItemType ItemType(JewelrySlot slot) { if (slot == JewelrySlot.Trinket) { return (ItemType)24; } return (ItemType)18; } private static void SetLayer(GameObject root, int layer) { Transform[] componentsInChildren = root.GetComponentsInChildren<Transform>(true); for (int i = 0; i < componentsInChildren.Length; i++) { ((Component)componentsInChildren[i]).gameObject.layer = layer; } } private static int PrepareMaterials(GameObject visual, Shader? gameShader) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown int num = 0; Renderer[] componentsInChildren = visual.GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { Material[] sharedMaterials = val.sharedMaterials; for (int j = 0; j < sharedMaterials.Length; j++) { if (!Object.op_Implicit((Object)(object)sharedMaterials[j])) { continue; } Material val2 = new Material(sharedMaterials[j]); if (Object.op_Implicit((Object)(object)gameShader)) { if (((Object)gameShader).name == ((Object)val2.shader).name) { val2.shader = gameShader; } else { JewelryPlugin.Log.LogWarning((object)("Material " + ((Object)val2).name + " uses shader '" + ((Object)val2.shader).name + "', not '" + ((Object)gameShader).name + "'; left on the bundle's shader.")); } } sharedMaterials[j] = val2; num++; } val.sharedMaterials = sharedMaterials; } return num; } private static Bounds ModelBounds(Transform holder, GameObject model) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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_0089: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: 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_00e4: Unknown result type (might be due to invalid IL or missing references) bool flag = false; Bounds result = default(Bounds); MeshFilter[] componentsInChildren = model.GetComponentsInChildren<MeshFilter>(true); Vector3 val3 = default(Vector3); foreach (MeshFilter val in componentsInChildren) { if (!Object.op_Implicit((Object)(object)val.sharedMesh)) { continue; } Matrix4x4 val2 = holder.worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix; Bounds bounds = val.sharedMesh.bounds; for (int j = 0; j < 8; j++) { ((Vector3)(ref val3))..ctor(((j & 1) == 0) ? (0f - ((Bounds)(ref bounds)).extents.x) : ((Bounds)(ref bounds)).extents.x, ((j & 2) == 0) ? (0f - ((Bounds)(ref bounds)).extents.y) : ((Bounds)(ref bounds)).extents.y, ((j & 4) == 0) ? (0f - ((Bounds)(ref bounds)).extents.z) : ((Bounds)(ref bounds)).extents.z); Vector3 val4 = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(((Bounds)(ref bounds)).center + val3); if (flag) { ((Bounds)(ref result)).Encapsulate(val4); } else { ((Bounds)(ref result))..ctor(val4, Vector3.zero); } flag = true; } } if (!flag) { throw new InvalidOperationException("The model has no mesh."); } return result; } private static Sprite? RenderIcon(Transform attach, string name) { //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_001a: 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_0030: Expected O, but got Unknown GameObject val = Object.Instantiate<GameObject>(((Component)attach).gameObject); try { ((Object)val).name = name; RenderRequest val2 = new RenderRequest(val) { Rotation = IconRotation, DistanceMultiplier = 0.8f }; return RenderManager.Instance.Render(val2); } catch (Exception ex) { JewelryPlugin.Log.LogWarning((object)("Icon render for " + name + " failed: " + ex.Message)); return null; } finally { Object.DestroyImmediate((Object)(object)val); } } } [BepInPlugin("com.skaket.valheim.jewelry", "Ska's Jewelry", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class JewelryPlugin : BaseUnityPlugin { public const string PluginGuid = "com.skaket.valheim.jewelry"; public const string PluginName = "Ska's Jewelry"; public const string PluginVersion = "1.0.0"; private const string BundleName = "jewelry"; internal static ManualLogSource Log = null; internal static readonly List<BuiltPiece> Pieces = new List<BuiltPiece>(); private AssetBundle? _bundle; private readonly Dictionary<JewelryKind, ConfigEntry<JewelrySlot>> _slots = new Dictionary<JewelryKind, ConfigEntry<JewelrySlot>>(); private ConfigEntry<bool> _useGameShader; private ConfigEntry<bool> _diagnostics; private ConfigEntry<bool> _giveItems; private void Awake() { Log = ((BaseUnityPlugin)this).Logger; BindSlot(JewelryKind.Ring, "Rings", JewelrySlot.Utility); BindSlot(JewelryKind.Necklace, "Necklaces", JewelrySlot.Trinket); BindSlot(JewelryKind.Earrings, "Earrings", JewelrySlot.Trinket); _useGameShader = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "UseGameShader", true, "Render the models with the game's own copy of their shader. Turn off to use the shader compiled into the mod's asset bundle instead. Only for comparing the two while testing. Takes effect on the next launch."); _diagnostics = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Diagnostics", false, "Write test lines to the log: whether the items and recipes exist, which the character holds, and what the game hung on the character for a worn piece and where. Takes effect on the next launch."); _giveItems = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "GiveItemsOnSpawn", false, "On entering a world, put one of each item this mod adds into the inventory if the character has none. For testing how a piece looks without crafting it. Takes effect on the next launch."); JewelryDiagnostics jewelryDiagnostics = ((Component)this).gameObject.AddComponent<JewelryDiagnostics>(); jewelryDiagnostics.LogState = _diagnostics.Value; jewelryDiagnostics.GiveItems = _giveItems.Value; _bundle = AssetUtils.LoadAssetBundleFromResources("jewelry"); if (!Object.op_Implicit((Object)(object)_bundle)) { Log.LogError((object)"The asset bundle could not be loaded, so no items were added. If the log just above mentions the Unity version, the bundle was built with an editor the game cannot read."); return; } Log.LogInfo((object)$"Asset bundle loaded: {_bundle.GetAllAssetNames().Length} assets"); AddTranslations(); PrefabManager.OnVanillaPrefabsAvailable += AddItems; ItemManager.OnItemsRegistered += PlacePending; SynchronizationManager.OnConfigurationSynchronized += delegate { ApplySlots(); }; } private void BindSlot(JewelryKind kind, string key, JewelrySlot standard) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Expected O, but got Unknown ConfigEntry<JewelrySlot> val = ((BaseUnityPlugin)this).Config.Bind<JewelrySlot>("Slots", key, standard, new ConfigDescription("The equipment slot " + key.ToLowerInvariant() + " are worn in: Utility (where Megingjord and the Wishbone go) or Trinket. The game has one of each, so two kinds set to the same slot cannot be worn together. On a server, the server's choice is used by everyone.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); val.SettingChanged += delegate { ApplySlots(); }; _slots[kind] = val; } private static void AddTranslations() { Dictionary<string, string> dictionary = new Dictionary<string, string>(); JewelryDef[] all = JewelryDefs.All; foreach (JewelryDef jewelryDef in all) { dictionary[jewelryDef.NameToken] = jewelryDef.Name; dictionary[jewelryDef.DescriptionToken] = jewelryDef.Description; } CustomLocalization localization = LocalizationManager.Instance.GetLocalization(); string text = "English"; localization.AddTranslation(ref text, dictionary); } private void AddItems() { PrefabManager.OnVanillaPrefabsAvailable -= AddItems; JewelryDef[] all = JewelryDefs.All; foreach (JewelryDef jewelryDef in all) { try { Pieces.Add(JewelryFactory.Add(_bundle, jewelryDef, _slots[jewelryDef.Kind].Value, _useGameShader.Value)); } catch (Exception arg) { Log.LogError((object)$"{jewelryDef.Id} was not added: {arg}"); } } PlacePending(); } private void PlacePending() { foreach (BuiltPiece item in Pieces.Where((BuiltPiece piece) => !piece.Placed)) { try { if (!JewelryFactory.Place(item, out string problem)) { if (Object.op_Implicit((Object)(object)ZNetScene.instance)) { Log.LogError((object)(item.Def.Id + " could not be set against " + item.Def.JointName + ": " + problem + ". It will not show in the right place when worn.")); } else { Log.LogInfo((object)(item.Def.Id + ": not set against " + item.Def.JointName + " yet (" + problem + "); trying again when a world loads.")); } } } catch (Exception arg) { Log.LogError((object)$"{item.Def.Id} could not be set against {item.Def.JointName}: {arg}"); } } } private void ApplySlots() { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004d: 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) foreach (BuiltPiece piece in Pieces) { ItemType val = JewelryFactory.ItemType(_slots[piece.Def.Kind].Value); if (piece.Shared.m_itemType != val) { piece.Shared.m_itemType = val; Log.LogInfo((object)$"{piece.Def.Id} now goes in the {_slots[piece.Def.Kind].Value} slot."); } } } } internal static class Skeleton { private static GameObject? _player; public static bool TryGetRestPose(string joint, out Vector3 position, out Quaternion rotation, out string problem) { //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_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_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) position = Vector3.zero; rotation = Quaternion.identity; problem = ""; GameObject val = FindPlayerPrefab(); if (!Object.op_Implicit((Object)(object)val)) { problem = "the player prefab is not loaded yet"; return false; } Transform transform = val.transform; Transform val2 = transform.Find("Visual"); if (!Object.op_Implicit((Object)(object)val2)) { val2 = transform; } Transform val3 = Utils.FindChild(val2, joint, (IterativeSearchType)0); if (!Object.op_Implicit((Object)(object)val3)) { problem = "the player has no bone named '" + joint + "'"; return false; } position = transform.InverseTransformPoint(val3.position); rotation = Quaternion.Inverse(transform.rotation) * val3.rotation; return true; } private static GameObject? FindPlayerPrefab() { if (Object.op_Implicit((Object)(object)_player)) { return _player; } GameObject val = null; try { val = PrefabManager.Instance.GetPrefab("Player"); } catch { } if (!IsPlayer(val) && Object.op_Implicit((Object)(object)ZNetScene.instance)) { val = ZNetScene.instance.GetPrefab("Player"); } if (!IsPlayer(val) && Object.op_Implicit((Object)(object)Game.instance)) { val = Game.instance.m_playerPrefab; } if (!IsPlayer(val) && Object.op_Implicit((Object)(object)FejdStartup.instance)) { val = FejdStartup.instance.m_playerPrefab; } if (!IsPlayer(val)) { val = (from player in Resources.FindObjectsOfTypeAll<Player>() where ((Object)player).name == "Player" select ((Component)player).gameObject).FirstOrDefault(); } if (IsPlayer(val)) { _player = val; } return _player; } private static bool IsPlayer(GameObject? candidate) { if (Object.op_Implicit((Object)(object)candidate)) { return Object.op_Implicit((Object)(object)candidate.GetComponent<VisEquipment>()); } return false; } } }