using 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.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using JetBrains.Annotations; using Jotunn; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("Testing2")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Testing2")] [assembly: AssemblyCopyright("Copyright © 2025")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("55CC6F29-0D48-4124-93BF-F657DE656B82")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace YourModName { public enum ItemRarity { Common, Uncommon, Rare, Epic, Legendary } public static class RarityData { public static readonly Dictionary Info = new Dictionary { { ItemRarity.Common, new RarityInfo { Name = "Common", Color = new Color(1f, 1f, 1f), StatBonus = 0f, SlotCount = 0, Weight = 50f } }, { ItemRarity.Uncommon, new RarityInfo { Name = "Uncommon", Color = new Color(0.3f, 0.85f, 0.3f), StatBonus = 0.05f, SlotCount = 1, Weight = 25f } }, { ItemRarity.Rare, new RarityInfo { Name = "Rare", Color = new Color(0.3f, 0.5f, 1f), StatBonus = 0.1f, SlotCount = 2, Weight = 15f } }, { ItemRarity.Epic, new RarityInfo { Name = "Epic", Color = new Color(0.7f, 0.3f, 1f), StatBonus = 0.15f, SlotCount = 3, Weight = 5f } }, { ItemRarity.Legendary, new RarityInfo { Name = "Legendary", Color = new Color(1f, 0.85f, 0.1f), StatBonus = 0.2f, SlotCount = 4, Weight = 0f } } }; public static ItemRarity RollRarity() { float num = 0f; foreach (KeyValuePair item in Info) { num += item.Value.Weight; } float num2 = Random.Range(0f, num); float num3 = 0f; foreach (KeyValuePair item2 in Info) { num3 += item2.Value.Weight; if (num2 < num3) { return item2.Key; } } return ItemRarity.Common; } } public class RarityInfo { public string Name; public Color Color; public float StatBonus; public int SlotCount; public float Weight; } public class RarityItemData { public ItemRarity Rarity; public int SlotCount; public List InsertedScrollIds; public float BasePierce; public float BaseBlunt; public float BaseSlash; public float BaseFire; public float BaseFrost; public float BaseLightning; public float BaseSpirit; public float BasePoison; public float BaseArmor; public float BaseBlockPower; private static readonly CultureInfo Inv = CultureInfo.InvariantCulture; public int FilledSlots => InsertedScrollIds.FindAll((string s) => !string.IsNullOrEmpty(s)).Count; public int EmptySlots => SlotCount - FilledSlots; public bool HasFreeSlot => EmptySlots > 0; public bool HasBaseDamages => BasePierce > 0f || BaseBlunt > 0f || BaseSlash > 0f || BaseFire > 0f || BaseFrost > 0f || BaseLightning > 0f || BaseSpirit > 0f || BasePoison > 0f; public RarityItemData() { } public RarityItemData(ItemRarity rarity) { Rarity = rarity; SlotCount = RarityData.Info[rarity].SlotCount; InsertedScrollIds = new List(); for (int i = 0; i < SlotCount; i++) { InsertedScrollIds.Add(string.Empty); } } public void SaveBaseDamages(ItemData item) { //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_000e: 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_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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_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) DamageTypes damages = item.m_shared.m_damages; BasePierce = damages.m_pierce; BaseBlunt = damages.m_blunt; BaseSlash = damages.m_slash; BaseFire = damages.m_fire; BaseFrost = damages.m_frost; BaseLightning = damages.m_lightning; BaseSpirit = damages.m_spirit; BasePoison = damages.m_poison; BaseArmor = item.m_shared.m_armor; BaseBlockPower = item.m_shared.m_blockPower; Logger.LogInfo((object)($"[SaveBase] {item.m_shared.m_name} q={item.m_quality} " + $"BaseArmor={BaseArmor:0.##} BaseBlockPower={BaseBlockPower:0.##}")); } public void RestoreBaseDamages(ItemData item) { //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_007b: 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) DamageTypes damages = item.m_shared.m_damages; damages.m_pierce = BasePierce; damages.m_blunt = BaseBlunt; damages.m_slash = BaseSlash; damages.m_fire = BaseFire; damages.m_frost = BaseFrost; damages.m_lightning = BaseLightning; damages.m_spirit = BaseSpirit; damages.m_poison = BasePoison; item.m_shared.m_damages = damages; } public bool InsertScroll(string scrollPerkId) { for (int i = 0; i < InsertedScrollIds.Count; i++) { if (string.IsNullOrEmpty(InsertedScrollIds[i])) { InsertedScrollIds[i] = scrollPerkId; return true; } } return false; } public string RemoveScroll(int slotIndex) { if (slotIndex < 0 || slotIndex >= InsertedScrollIds.Count) { return string.Empty; } string result = InsertedScrollIds[slotIndex]; InsertedScrollIds[slotIndex] = string.Empty; return result; } public string Serialize() { string text = string.Join(",", InsertedScrollIds); string text2 = string.Join(";", BasePierce.ToString("F4", Inv), BaseBlunt.ToString("F4", Inv), BaseSlash.ToString("F4", Inv), BaseFire.ToString("F4", Inv), BaseFrost.ToString("F4", Inv), BaseLightning.ToString("F4", Inv), BaseSpirit.ToString("F4", Inv), BasePoison.ToString("F4", Inv), BaseArmor.ToString("F4", Inv), BaseBlockPower.ToString("F4", Inv)); return $"{(int)Rarity}|{SlotCount}|{text}|{text2}"; } public static RarityItemData Deserialize(string raw) { if (string.IsNullOrEmpty(raw)) { return null; } string[] array = raw.Split(new char[1] { '|' }); if (array.Length < 1) { return null; } RarityItemData rarityItemData = new RarityItemData(); if (int.TryParse(array[0], out var result)) { rarityItemData.Rarity = (ItemRarity)result; } if (array.Length > 1 && int.TryParse(array[1], out var result2)) { rarityItemData.SlotCount = result2; } else { rarityItemData.SlotCount = RarityData.Info[rarityItemData.Rarity].SlotCount; } rarityItemData.InsertedScrollIds = new List(); if (array.Length > 2 && !string.IsNullOrEmpty(array[2])) { string[] array2 = array[2].Split(new char[1] { ',' }); foreach (string item in array2) { rarityItemData.InsertedScrollIds.Add(item); } } while (rarityItemData.InsertedScrollIds.Count < rarityItemData.SlotCount) { rarityItemData.InsertedScrollIds.Add(string.Empty); } string[] d; if (array.Length > 3 && !string.IsNullOrEmpty(array[3])) { d = array[3].Split(new char[1] { ';' }); rarityItemData.BasePierce = F(0); rarityItemData.BaseBlunt = F(1); rarityItemData.BaseSlash = F(2); rarityItemData.BaseFire = F(3); rarityItemData.BaseFrost = F(4); rarityItemData.BaseLightning = F(5); rarityItemData.BaseSpirit = F(6); rarityItemData.BasePoison = F(7); rarityItemData.BaseArmor = F(8); rarityItemData.BaseBlockPower = F(9); } return rarityItemData; float F(int i) { float result3; return (d.Length > i && float.TryParse(d[i], NumberStyles.Float, Inv, out result3)) ? result3 : 0f; } } } [HarmonyPatch(typeof(ZNetScene), "RemoveObjects")] public static class ZNetScene_RemoveObjects_NullSafePatch { [HarmonyPrefix] public static void Prefix(ZNetScene __instance) { List list = new List(); foreach (KeyValuePair instance in __instance.m_instances) { if ((Object)(object)instance.Value == (Object)null || (Object)(object)((Component)instance.Value).gameObject == (Object)null) { list.Add(instance.Key); } } foreach (ZDO item in list) { __instance.m_instances.Remove(item); } } } [HarmonyPatch(typeof(ZNetScene), "Shutdown")] public static class ZNetScene_Shutdown_NullSafePatch { [HarmonyPrefix] public static void Prefix(ZNetScene __instance) { List list = new List(); foreach (KeyValuePair instance in __instance.m_instances) { if ((Object)(object)instance.Value == (Object)null || (Object)(object)((Component)instance.Value).gameObject == (Object)null) { list.Add(instance.Key); } } foreach (ZDO item in list) { __instance.m_instances.Remove(item); } } } [HarmonyPatch] public static class RarityItemVFX { [CompilerGenerated] private sealed class d__2 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public ItemDrop drop; private float 5__1; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__2(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = null; <>1__state = 1; return true; case 1: <>1__state = -1; if ((Object)(object)drop == (Object)null || (Object)(object)((Component)drop).gameObject == (Object)null) { return false; } 5__1 = 5f; goto IL_00b4; case 2: <>1__state = -1; 5__1 -= 0.2f; goto IL_00b4; case 3: { <>1__state = -1; if ((Object)(object)drop == (Object)null || (Object)(object)((Component)drop).gameObject == (Object)null) { return false; } ApplyVFX(drop); return false; } IL_00b4: if (5__1 > 0f && ((Object)(object)Player.m_localPlayer == (Object)null || ((Character)Player.m_localPlayer).IsTeleporting())) { <>2__current = (object)new WaitForSeconds(0.2f); <>1__state = 2; return true; } <>2__current = null; <>1__state = 3; return true; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } private const string VFX_CHILD_NAME = "RarityVFX"; [HarmonyPatch(typeof(ItemDrop), "Start")] [HarmonyPostfix] public static void ItemDrop_Start_Postfix(ItemDrop __instance) { ((MonoBehaviour)__instance).StartCoroutine(ApplyVFXNextFrame(__instance)); } [IteratorStateMachine(typeof(d__2))] private static IEnumerator ApplyVFXNextFrame(ItemDrop drop) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__2(0) { drop = drop }; } public static void ApplyVFX(ItemDrop drop) { //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0133: 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_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0188: 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_02ea: Unknown result type (might be due to invalid IL or missing references) //IL_0305: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Expected O, but got Unknown //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: 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_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_0253: Expected O, but got Unknown //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Unknown result type (might be due to invalid IL or missing references) //IL_02b2: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)drop == (Object)null) { return; } ItemData itemData = drop.m_itemData; if (itemData == null) { return; } Color color; if (ScrollItem.IsEnchantScroll(itemData)) { ScrollItem.TryGetScrollTier(itemData, out var rarity); if (rarity == ItemRarity.Common) { return; } color = RarityData.Info[rarity].Color; } else { if (!RarityPatches.IsWeaponOrArmor(itemData)) { return; } RarityItemData rarityItemData = RarityTooltip.Get(itemData); if (rarityItemData == null || rarityItemData.Rarity == ItemRarity.Common) { return; } color = RarityData.Info[rarityItemData.Rarity].Color; } Transform val = FindDeep(((Component)drop).transform, "fx_ItemSparkles"); if ((Object)(object)val == (Object)null) { Logger.LogWarning((object)("[Rarity VFX] No se encontró fx_ItemSparkles en " + ((Object)drop).name)); return; } ParticleSystem[] componentsInChildren = ((Component)val).GetComponentsInChildren(true); foreach (ParticleSystem val2 in componentsInChildren) { MainModule main = val2.main; ((MainModule)(ref main)).startColor = new MinMaxGradient(new Color(color.r, color.g, color.b, 1f), new Color(color.r, color.g, color.b, 0.4f)); ((MainModule)(ref main)).maxParticles = 100; ((MainModule)(ref main)).simulationSpeed = 1f; EmissionModule emission = val2.emission; ((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(50f); ColorOverLifetimeModule colorOverLifetime = val2.colorOverLifetime; if (((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled) { Gradient val3 = new Gradient(); val3.SetKeys((GradientColorKey[])(object)new GradientColorKey[2] { new GradientColorKey(color, 0f), new GradientColorKey(color, 1f) }, (GradientAlphaKey[])(object)new GradientAlphaKey[2] { new GradientAlphaKey(1f, 0f), new GradientAlphaKey(0f, 1f) }); ((ColorOverLifetimeModule)(ref colorOverLifetime)).color = new MinMaxGradient(val3); } ParticleSystemRenderer component = ((Component)val2).GetComponent(); if ((Object)(object)component != (Object)null && (Object)(object)((Renderer)component).material != (Object)null) { Material val4 = new Material(((Renderer)component).material); if (val4.HasProperty("_Color")) { val4.SetColor("_Color", color); } if (val4.HasProperty("_TintColor")) { val4.SetColor("_TintColor", color); } if (val4.HasProperty("_EmissionColor")) { val4.SetColor("_EmissionColor", color * 2f); } ((Renderer)component).material = val4; } } val.localScale = new Vector3(1f, 4f, 1f); Logger.LogInfo((object)("[Rarity VFX] " + ((Object)drop).name + " recoloreado | color #" + ColorUtility.ToHtmlStringRGB(color))); } private static Transform FindDeep(Transform parent, string name) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown foreach (Transform item in parent) { Transform val = item; if (((Object)val).name == name) { return val; } Transform val2 = FindDeep(val, name); if ((Object)(object)val2 != (Object)null) { return val2; } } return null; } } [HarmonyPatch] public static class RarityPatches { private static bool _addItemProcessing; [HarmonyPatch(typeof(InventoryGui), "DoCrafting")] [HarmonyPostfix] public static void DoCrafting_Postfix(InventoryGui __instance, Player player) { Inventory inventory = ((Humanoid)player).GetInventory(); foreach (ItemData allItem in inventory.GetAllItems()) { if (!allItem.m_customData.ContainsKey("RarityData") && IsWeaponOrArmor(allItem) && allItem.m_quality <= 1) { RarityItemData orCreate = RarityTooltip.GetOrCreate(allItem); orCreate.SaveBaseDamages(allItem); ApplyStatBonusToDamages(allItem, orCreate); ApplyStatBonusToArmor(allItem, orCreate); ApplyStatBonusToBlockPower(allItem, orCreate); RarityTooltip.Save(allItem, orCreate); } } } [HarmonyPatch(typeof(Inventory), "AddItem", new Type[] { typeof(string), typeof(int), typeof(int), typeof(int), typeof(long), typeof(string), typeof(Vector2i), typeof(bool) })] [HarmonyPostfix] public static void AddItem_Postfix(ref ItemData __result) { //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_022a: 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_0212: Unknown result type (might be due to invalid IL or missing references) //IL_025e: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_0246: Unknown result type (might be due to invalid IL or missing references) //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_0273: Unknown result type (might be due to invalid IL or missing references) //IL_027a: Unknown result type (might be due to invalid IL or missing references) //IL_02c6: Unknown result type (might be due to invalid IL or missing references) //IL_02a7: Unknown result type (might be due to invalid IL or missing references) //IL_02ae: Unknown result type (might be due to invalid IL or missing references) //IL_02fa: Unknown result type (might be due to invalid IL or missing references) //IL_02db: 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_032e: Unknown result type (might be due to invalid IL or missing references) //IL_030f: Unknown result type (might be due to invalid IL or missing references) //IL_0316: Unknown result type (might be due to invalid IL or missing references) //IL_0362: Unknown result type (might be due to invalid IL or missing references) //IL_0343: Unknown result type (might be due to invalid IL or missing references) //IL_034a: Unknown result type (might be due to invalid IL or missing references) //IL_0377: Unknown result type (might be due to invalid IL or missing references) //IL_037e: Unknown result type (might be due to invalid IL or missing references) if (__result == null || !IsWeaponOrArmor(__result)) { return; } RarityItemData rarityItemData = RarityTooltip.Get(__result); if (rarityItemData == null || __result.m_quality <= 1 || _addItemProcessing) { return; } _addItemProcessing = true; try { ObjectDB instance = ObjectDB.instance; object obj; if (instance == null) { obj = null; } else { GameObject dropPrefab = __result.m_dropPrefab; obj = instance.GetItemPrefab(((dropPrefab != null) ? ((Object)dropPrefab).name : null) ?? ""); } GameObject val = (GameObject)obj; ItemData val2 = ((val == null) ? null : val.GetComponent()?.m_itemData); if (val2 == null && (Object)(object)ObjectDB.instance != (Object)null) { foreach (GameObject item in ObjectDB.instance.m_items) { ItemDrop val3 = ((item != null) ? item.GetComponent() : null); if (val3?.m_itemData?.m_shared?.m_name == __result.m_shared.m_name) { val2 = val3.m_itemData; break; } } } if (val2 != null) { float baseArmor = val2.m_shared.m_armor + val2.m_shared.m_armorPerLevel * (float)(__result.m_quality - 1); rarityItemData.BaseArmor = baseArmor; float num = val2.m_shared.m_blockPower + val2.m_shared.m_blockPowerPerLevel * (float)(__result.m_quality - 1); if (num > 0f) { rarityItemData.BaseBlockPower = num; } DamageTypes damages = val2.m_shared.m_damages; DamageTypes damagesPerLevel = val2.m_shared.m_damagesPerLevel; if (damages.m_pierce > 0f) { rarityItemData.BasePierce = damages.m_pierce + damagesPerLevel.m_pierce * (float)(__result.m_quality - 1); } if (damages.m_blunt > 0f) { rarityItemData.BaseBlunt = damages.m_blunt + damagesPerLevel.m_blunt * (float)(__result.m_quality - 1); } if (damages.m_slash > 0f) { rarityItemData.BaseSlash = damages.m_slash + damagesPerLevel.m_slash * (float)(__result.m_quality - 1); } if (damages.m_fire > 0f) { rarityItemData.BaseFire = damages.m_fire + damagesPerLevel.m_fire * (float)(__result.m_quality - 1); } if (damages.m_frost > 0f) { rarityItemData.BaseFrost = damages.m_frost + damagesPerLevel.m_frost * (float)(__result.m_quality - 1); } if (damages.m_lightning > 0f) { rarityItemData.BaseLightning = damages.m_lightning + damagesPerLevel.m_lightning * (float)(__result.m_quality - 1); } if (damages.m_spirit > 0f) { rarityItemData.BaseSpirit = damages.m_spirit + damagesPerLevel.m_spirit * (float)(__result.m_quality - 1); } if (damages.m_poison > 0f) { rarityItemData.BasePoison = damages.m_poison + damagesPerLevel.m_poison * (float)(__result.m_quality - 1); } } else { float num2 = 1f + RarityData.Info[rarityItemData.Rarity].StatBonus; float num3 = rarityItemData.BaseArmor * num2; bool flag = Mathf.Abs(__result.m_shared.m_armor - num3) < 0.2f; if (rarityItemData.BaseArmor > 0f && flag) { rarityItemData.BaseArmor = __result.m_shared.m_armor / num2; } else if (rarityItemData.BaseArmor <= 0f) { rarityItemData.SaveBaseDamages(__result); } float num4 = rarityItemData.BaseBlockPower * num2; bool flag2 = Mathf.Abs(__result.m_shared.m_blockPower - num4) < 0.2f; if (rarityItemData.BaseBlockPower > 0f && flag2) { rarityItemData.BaseBlockPower = __result.m_shared.m_blockPower / num2; } } ApplyStatBonusToDamages(__result, rarityItemData); ApplyStatBonusToArmor(__result, rarityItemData); ApplyStatBonusToBlockPower(__result, rarityItemData); EnchantBonusManager.RefreshSingleItem(__result); RarityTooltip.Save(__result, rarityItemData); } finally { _addItemProcessing = false; } } [HarmonyPatch(typeof(InventoryGrid), "UpdateGui")] [HarmonyPostfix] public static void UpdateGui_Postfix(InventoryGrid __instance) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: 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_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) Inventory inventory = __instance.m_inventory; if (inventory == null) { return; } foreach (Element element in __instance.m_elements) { if (!element.m_used) { ((Graphic)element.m_icon).color = Color.white; continue; } ItemData itemAt = inventory.GetItemAt(element.m_pos.x, element.m_pos.y); if (itemAt == null) { ((Graphic)element.m_icon).color = Color.white; continue; } if (ScrollItem.IsEnchantScroll(itemAt)) { ScrollItem.TryGetScrollTier(itemAt, out var rarity); Color color = RarityData.Info[rarity].Color; ((Graphic)element.m_icon).color = Color.Lerp(Color.white, color, 0.45f); string text = ColorUtility.ToHtmlStringRGB(color); element.m_tooltip.m_topic = "" + itemAt.m_shared.m_name + ""; continue; } RarityItemData rarityItemData = RarityTooltip.Get(itemAt); if (rarityItemData == null || rarityItemData.Rarity == ItemRarity.Common) { ((Graphic)element.m_icon).color = Color.white; element.m_tooltip.m_topic = itemAt.m_shared.m_name; continue; } Color color2 = RarityData.Info[rarityItemData.Rarity].Color; ((Graphic)element.m_icon).color = Color.Lerp(Color.white, color2, 0.35f); string text2 = ColorUtility.ToHtmlStringRGB(color2); element.m_tooltip.m_topic = "" + itemAt.m_shared.m_name + ""; } } public static bool IsWeaponOrArmor(ItemData item) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Invalid comparison between Unknown and I4 //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Invalid comparison between Unknown and I4 //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Invalid comparison between Unknown and I4 //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Invalid comparison between Unknown and I4 //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Invalid comparison between Unknown and I4 //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Invalid comparison between Unknown and I4 //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Invalid comparison between Unknown and I4 //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Invalid comparison between Unknown and I4 ItemType itemType = item.m_shared.m_itemType; return (int)itemType == 3 || (int)itemType == 14 || (int)itemType == 4 || (int)itemType == 5 || (int)itemType == 6 || (int)itemType == 7 || (int)itemType == 11 || (int)itemType == 17 || (int)itemType == 18; } public static void ApplyStatBonusToDamages(ItemData item, RarityItemData data) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0130: 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_0186: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: 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) if (data.Rarity != 0 && data.HasBaseDamages) { float num = 1f + RarityData.Info[data.Rarity].StatBonus; DamageTypes damages = item.m_shared.m_damages; DamageTypes damagesPerLevel = item.m_shared.m_damagesPerLevel; float num2 = item.m_quality - 1; if (data.BasePierce > 0f) { damages.m_pierce = data.BasePierce * num - damagesPerLevel.m_pierce * num2; } if (data.BaseBlunt > 0f) { damages.m_blunt = data.BaseBlunt * num - damagesPerLevel.m_blunt * num2; } if (data.BaseSlash > 0f) { damages.m_slash = data.BaseSlash * num - damagesPerLevel.m_slash * num2; } if (data.BaseFire > 0f) { damages.m_fire = data.BaseFire * num - damagesPerLevel.m_fire * num2; } if (data.BaseFrost > 0f) { damages.m_frost = data.BaseFrost * num - damagesPerLevel.m_frost * num2; } if (data.BaseLightning > 0f) { damages.m_lightning = data.BaseLightning * num - damagesPerLevel.m_lightning * num2; } if (data.BaseSpirit > 0f) { damages.m_spirit = data.BaseSpirit * num - damagesPerLevel.m_spirit * num2; } if (data.BasePoison > 0f) { damages.m_poison = data.BasePoison * num - damagesPerLevel.m_poison * num2; } item.m_shared.m_damages = damages; } } public static void ApplyStatBonusToArmor(ItemData item, RarityItemData data) { //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_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Invalid comparison between Unknown and I4 //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Invalid comparison between Unknown and I4 //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Invalid comparison between Unknown and I4 //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Invalid comparison between Unknown and I4 if (data.Rarity != 0 && !(data.BaseArmor <= 0f)) { ItemType itemType = item.m_shared.m_itemType; if ((int)itemType == 6 || (int)itemType == 7 || (int)itemType == 11 || (int)itemType == 17) { float num = 1f + RarityData.Info[data.Rarity].StatBonus; float num2 = item.m_shared.m_armorPerLevel * (float)(item.m_quality - 1); item.m_shared.m_armor = data.BaseArmor * num - num2; } } } public static void ApplyStatBonusToBlockPower(ItemData item, RarityItemData data) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Invalid comparison between Unknown and I4 if (data.Rarity != 0 && !(data.BaseBlockPower <= 0f) && (int)item.m_shared.m_itemType == 5) { float num = 1f + RarityData.Info[data.Rarity].StatBonus; float num2 = item.m_shared.m_blockPowerPerLevel * (float)(item.m_quality - 1); item.m_shared.m_blockPower = data.BaseBlockPower * num - num2; } } } [HarmonyPatch] public static class GetTooltip_Patch { private static MethodBase TargetMethod() { return typeof(ItemData).GetMethod("GetTooltip", BindingFlags.Static | BindingFlags.Public, null, new Type[5] { typeof(ItemData), typeof(int), typeof(bool), typeof(float), typeof(int) }, null); } [HarmonyPostfix] public static void Postfix(ItemData item, ref string __result) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) if (item == null) { return; } if (ScrollItem.IsEnchantScroll(item)) { ScrollItem.TryGetScrollTier(item, out var rarity); RarityInfo rarityInfo = RarityData.Info[rarity]; string text = ColorUtility.ToHtmlStringRGB(rarityInfo.Color); string text2 = ""; if (item.m_customData.TryGetValue("ScrollPerk", out var value) && !string.IsNullOrEmpty(value)) { string[] array = value.Split(new char[1] { ':' }); ScrollPerkDef byName = ScrollPerkRegistry.GetByName(array[0]); if (byName != null) { string text3 = ((array.Length == 2) ? (byName.GetDisplayText(rarity) + " vs " + array[1]) : byName.GetDisplayText(rarity)); text2 = "\n" + text3 + ""; } } __result = "Pergamino " + rarityInfo.Name + "" + text2 + "\n" + (ScrollItem.IsRevealed(item) ? "Click derecho para encantar" : "Click derecho para desbloquear") + ".\n\nRareza: " + rarityInfo.Name + ""; return; } RarityItemData rarityItemData = RarityTooltip.Get(item); if (rarityItemData == null || rarityItemData.Rarity == ItemRarity.Common) { return; } string value2 = "Tier: " + RarityData.Info[rarityItemData.Rarity].Name; if (__result == null || !__result.Contains(value2)) { __result = RarityTooltip.ColorizeHeader(__result, rarityItemData); __result = RarityTooltip.ReplaceDamageLines(__result, rarityItemData, item); __result = RarityTooltip.ReplaceArmorLine(__result, rarityItemData, item); __result = RarityTooltip.ReplaceBlockPowerLine(__result, rarityItemData, item); string text4 = RarityTooltip.BuildTooltipAddition(rarityItemData, item); if (!string.IsNullOrEmpty(text4)) { __result = __result + "\n" + text4; } } } } [BepInPlugin("com.tuusuario.valheim.rarity", "ItemRaritySystem", "0.2.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class RarityPlugin : BaseUnityPlugin { public const string ModGUID = "com.tuusuario.valheim.rarity"; public const string ModName = "ItemRaritySystem"; public const string ModVersion = "0.2.0"; private Harmony _harmony; private void Awake() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown Logger.LogInfo((object)"[ItemRaritySystem] Cargando sistema de rareza v0.2.0..."); _harmony = new Harmony("com.tuusuario.valheim.rarity"); _harmony.PatchAll(); ScrollItem.Register(); GUIManager.OnCustomGUIAvailable += CreateScrollUI; Logger.LogInfo((object)"[ItemRaritySystem] ¡Listo! Patches aplicados."); } private void CreateScrollUI() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown if (!((Object)(object)ScrollEnchantUI.Instance != (Object)null)) { GameObject val = new GameObject("ScrollEnchantUI"); Object.DontDestroyOnLoad((Object)(object)val); val.AddComponent(); } } private void OnDestroy() { GUIManager.OnCustomGUIAvailable -= CreateScrollUI; Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } public static class RarityTooltip { private const string CUSTOM_DATA_KEY = "RarityData"; private const string SMITH_LEVEL_KEY = "nazhi_blacksmith_lvl"; private const float SMITH_DAMAGE_ARMOR_MAX_100 = 1f; private static readonly Dictionary SlotFilledChar = new Dictionary { { ItemRarity.Common, "\ud83d\udc8e" }, { ItemRarity.Uncommon, "\ud83d\udc8e" }, { ItemRarity.Rare, "\ud83d\udc8e" }, { ItemRarity.Epic, "\ud83d\udc8e" }, { ItemRarity.Legendary, "\ud83d\udc8e" } }; private const string SLOT_EMPTY = "\ud83d\udd28"; private const string SEP = "━━━━━━━━━━━━━━━━"; private static readonly string[] ItemTypeKeys = new string[14] { "$item_onehanded", "$item_twohanded", "$item_bow", "$item_shield", "$item_helmet", "$item_chest", "$item_legs", "$item_shoulder", "$item_utility", "$item_tool", "$item_ammo", "$item_trophy", "$item_consumable", "$item_material" }; public static string ColorizeHeader(string tooltip, RarityItemData data) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) if (string.IsNullOrEmpty(tooltip) || data == null || data.Rarity == ItemRarity.Common) { return tooltip; } RarityInfo rarityInfo = RarityData.Info[data.Rarity]; string text = ColorUtility.ToHtmlStringRGB(rarityInfo.Color); string text2 = null; string[] itemTypeKeys = ItemTypeKeys; foreach (string text3 in itemTypeKeys) { if (tooltip.Contains(text3)) { text2 = text3; break; } } if (text2 == null) { return tooltip; } int num = tooltip.IndexOf(text2, StringComparison.OrdinalIgnoreCase); if (num < 0) { return tooltip; } string text4 = tooltip.Substring(0, num).TrimEnd('\n', '\r'); string text5 = tooltip.Substring(num); string[] array = text4.Split(new char[1] { '\n' }); StringBuilder stringBuilder = new StringBuilder(); string[] array2 = array; foreach (string text6 in array2) { string text7 = text6.TrimEnd(new char[1] { '\r' }); if (string.IsNullOrWhiteSpace(text7)) { stringBuilder.AppendLine(); continue; } stringBuilder.AppendLine("" + text7 + ""); } stringBuilder.AppendLine("Tier: " + rarityInfo.Name + ""); stringBuilder.AppendLine("━━━━━━━━━━━━━━━━"); return stringBuilder.ToString() + text5; } public static string ReplaceDamageLines(string tooltip, RarityItemData data, ItemData item) { //IL_0030: 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_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0088: 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_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) if (string.IsNullOrEmpty(tooltip) || item == null) { return tooltip; } RarityInfo rarityInfo = RarityData.Info[data.Rarity]; string arg = ColorUtility.ToHtmlStringRGB(rarityInfo.Color); float smithFactor = GetSmithFactor(GetSmithLevel(item)); DamageTypes damage = item.GetDamage(item.m_quality, (float)item.m_worldLevel); Dictionary dictionary = new Dictionary { { "pierce", (damage.m_pierce, data.BasePierce, "Perforante") }, { "blunt", (damage.m_blunt, data.BaseBlunt, "Contundente") }, { "slash", (damage.m_slash, data.BaseSlash, "Cortante") }, { "fire", (damage.m_fire, data.BaseFire, "Fuego") }, { "frost", (damage.m_frost, data.BaseFrost, "Escarcha") }, { "lightning", (damage.m_lightning, data.BaseLightning, "Rayo") }, { "spirit", (damage.m_spirit, data.BaseSpirit, "Espíritu") }, { "poison", (damage.m_poison, data.BasePoison, "Veneno") } }; foreach (KeyValuePair item2 in dictionary) { string pattern = "^\\$inventory_" + item2.Key + "\\s*:.*$"; var (num, num2, arg2) = item2.Value; if (num <= 0f) { tooltip = Regex.Replace(tooltip, pattern, string.Empty, RegexOptions.IgnoreCase | RegexOptions.Multiline); continue; } float num3 = num; float vanillaBase = num2 * smithFactor; string text = ((num2 > 0f) ? FormatStatDiff(num3, vanillaBase) : string.Empty); string replacement = $"{arg2}: {num3:0.#}" + ((text.Length > 0) ? (" " + text) : string.Empty) + ""; tooltip = Regex.Replace(tooltip, pattern, replacement, RegexOptions.IgnoreCase | RegexOptions.Multiline); } return tooltip; } public static string ReplaceBlockPowerLine(string tooltip, RarityItemData data, ItemData item) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Invalid comparison between Unknown and I4 //IL_004f: Unknown result type (might be due to invalid IL or missing references) if (string.IsNullOrEmpty(tooltip) || item == null) { return tooltip; } if ((int)item.m_shared.m_itemType != 5) { return tooltip; } RarityInfo rarityInfo = RarityData.Info[data.Rarity]; string arg = ColorUtility.ToHtmlStringRGB(rarityInfo.Color); float num = item.m_shared.m_blockPowerPerLevel * (float)(item.m_quality - 1); float num2 = item.m_shared.m_blockPower + num; string text = ((data.BaseBlockPower > 0f) ? FormatStatDiff(num2, data.BaseBlockPower) : string.Empty); string replacement = $"$item_blockarmor: {num2:0.#}" + ((text.Length > 0) ? (" " + text) : string.Empty) + ""; tooltip = Regex.Replace(tooltip, "^\\$item_blockarmor\\s*:.*$", replacement, RegexOptions.IgnoreCase | RegexOptions.Multiline); return tooltip; } public static string ReplaceArmorLine(string tooltip, RarityItemData data, ItemData item) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Invalid comparison between Unknown and I4 //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Invalid comparison between Unknown and I4 //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Invalid comparison between Unknown and I4 //IL_0080: 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_0056: Invalid comparison between Unknown and I4 if (string.IsNullOrEmpty(tooltip) || item == null) { return tooltip; } if ((int)item.m_shared.m_itemType != 6 && (int)item.m_shared.m_itemType != 7 && (int)item.m_shared.m_itemType != 11 && (int)item.m_shared.m_itemType != 17) { return tooltip; } RarityInfo rarityInfo = RarityData.Info[data.Rarity]; string arg = ColorUtility.ToHtmlStringRGB(rarityInfo.Color); float smithFactor = GetSmithFactor(GetSmithLevel(item)); float num = 0f; foreach (string insertedScrollId in data.InsertedScrollIds) { if (!string.IsNullOrEmpty(insertedScrollId)) { ScrollPerkDef byName = ScrollPerkRegistry.GetByName(insertedScrollId.Split(new char[1] { ':' })[0]); if (byName != null && byName.Type == ScrollPerkType.Armadura) { num += byName.GetValue(data.Rarity); } } } float num2 = data.BaseArmor * (1f + rarityInfo.StatBonus); float num3 = num2 * smithFactor; float num4 = num3 + num; string text = ((data.BaseArmor > 0f) ? FormatStatDiff(num4, data.BaseArmor) : string.Empty); Logger.LogInfo((object)($"[ArmorDebug] base={data.BaseArmor:0.##} " + $"afterRarity={num2:0.##} " + $"afterSmith={num3:0.##} " + $"perk={num:0.##} " + $"total={num4:0.##}")); string replacement = $"Armadura: {num4:0.#}" + ((text.Length > 0) ? (" " + text) : string.Empty) + ""; tooltip = Regex.Replace(tooltip, "^\\$item_armor\\s*:.*$", replacement, RegexOptions.IgnoreCase | RegexOptions.Multiline); return tooltip; } public static string BuildTooltipAddition(RarityItemData data, ItemData item = null) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) if (data == null || data.Rarity == ItemRarity.Common) { return string.Empty; } RarityInfo rarityInfo = RarityData.Info[data.Rarity]; string text = ColorUtility.ToHtmlStringRGB(rarityInfo.Color); string filledChar = SlotFilledChar[data.Rarity]; StringBuilder stringBuilder = new StringBuilder(); if (data.SlotCount > 0) { stringBuilder.AppendLine(); for (int i = 0; i < data.SlotCount; i++) { string text2 = ((i < data.InsertedScrollIds.Count) ? data.InsertedScrollIds[i] : string.Empty); if (string.IsNullOrEmpty(text2)) { stringBuilder.AppendLine("\ud83d\udd28 Slot vacío"); } else { stringBuilder.AppendLine(BuildPerkDescription(text2, data.Rarity, text, filledChar)); } } } stringBuilder.AppendLine(); stringBuilder.Append("━━━━━━━━━━━━━━━━"); return stringBuilder.ToString(); } public static RarityItemData GetOrCreate(ItemData itemData) { if (itemData.m_customData.TryGetValue("RarityData", out var value)) { RarityItemData rarityItemData = RarityItemData.Deserialize(value); if (rarityItemData != null) { return rarityItemData; } } ItemRarity rarity = RarityData.RollRarity(); RarityItemData rarityItemData2 = new RarityItemData(rarity); itemData.m_customData["RarityData"] = rarityItemData2.Serialize(); return rarityItemData2; } public static RarityItemData Get(ItemData itemData) { if (itemData.m_customData.TryGetValue("RarityData", out var value)) { return RarityItemData.Deserialize(value); } return null; } public static void Save(ItemData itemData, RarityItemData data) { itemData.m_customData["RarityData"] = data.Serialize(); } public static string GetRarityHex(RarityItemData data) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) if (data == null) { return "ffffff"; } return ColorUtility.ToHtmlStringRGB(RarityData.Info[data.Rarity].Color); } private static int GetSmithLevel(ItemData item) { if (item?.m_customData == null) { return 0; } if (!item.m_customData.TryGetValue("nazhi_blacksmith_lvl", out var value)) { return 0; } int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result); return result; } private static float GetSmithFactor(int smithLvl) { if (smithLvl <= 0) { return 1f; } return 1f + 1f * Mathf.Clamp01((float)smithLvl / 100f); } private static string FormatStatDiff(float current, float vanillaBase) { if (vanillaBase <= 0f) { return string.Empty; } float num = current - vanillaBase; float num2 = num / vanillaBase * 100f; if (Mathf.Abs(num) < 0.05f) { return string.Empty; } bool flag = num >= 0f; string text = (flag ? "↑" : "↓"); string text2 = (flag ? "00e676" : "ff5252"); string arg = (flag ? "+" : ""); string text3 = $"{arg}{num:0.#}"; string text4 = $"{arg}{num2:0.#}%"; return "" + text + " " + text3 + " (" + text4 + ")"; } private static string BuildPerkDescription(string scrollId, ItemRarity rarity, string hex, string filledChar) { string[] array = scrollId.Split(new char[1] { ':' }); string displayName = array[0]; string text = ((array.Length == 2) ? array[1] : null); ScrollPerkDef byName = ScrollPerkRegistry.GetByName(displayName); if (byName == null) { return filledChar + " " + scrollId + ""; } float value = byName.GetValue(rarity); string text2 = ((byName.Type == ScrollPerkType.Vida || byName.Type == ScrollPerkType.Armadura || byName.Type == ScrollPerkType.Durabilidad || byName.Type == ScrollPerkType.WeapSkill || byName.Type == ScrollPerkType.Weight) ? $"{value:0}" : $"{value:0.##}%"); if (byName.Type == ScrollPerkType.NoMovPen) { text2 = ""; } ScrollPerkType type = byName.Type; if (1 == 0) { } string text3 = type switch { ScrollPerkType.Pierce => "Perforante: Aumenta en +" + text2 + " el daño perforante", ScrollPerkType.Blunt => "Contundente: Aumenta en +" + text2 + " el daño contundente", ScrollPerkType.Slash => "Cortante: Aumenta en +" + text2 + " el daño cortante", ScrollPerkType.DmgMagico => "Dominio Elemental: Aumenta en +" + text2 + " el daño mágico", ScrollPerkType.VelocidadAtk => "Frenesí: Aumenta en +" + text2 + " la velocidad de ataque", ScrollPerkType.DmgFaccion => "Oportunista: Aumenta en +" + text2 + " el daño vs " + TranslateFaction(text ?? "enemigos"), ScrollPerkType.ReduccionDmg => "Piel de Hierro: Reduce en " + text2 + " el daño recibido", ScrollPerkType.Armadura => "Bastión: Aumenta en +" + text2 + " la armadura", ScrollPerkType.Vida => "Vitalidad: Aumenta en +" + text2 + " el HP máximo", ScrollPerkType.RegHP => "Vitalis: Aumenta en +" + text2 + " la regeneración de HP", ScrollPerkType.RegStamina => "Segundo Aliento: Aumenta en +" + text2 + " la regen. de Stamina", ScrollPerkType.RegEitr => "Eco de Eitr: Aumenta en +" + text2 + " la regeneración de Eitr", ScrollPerkType.Durabilidad => "Temple Reforjado: Aumenta en +" + text2 + " la durabilidad", ScrollPerkType.Healing => "Sagrado: Aumenta en +" + text2 + " el poder de curación", ScrollPerkType.ResistPierce => "Protección Perforante: Reduce en " + text2 + " el daño perforante recibido", ScrollPerkType.ResistBlunt => "Protección Contundente: Reduce en " + text2 + " el daño contundente recibido", ScrollPerkType.ResistSlash => "Protección Cortante: Reduce en " + text2 + " el daño cortante recibido", ScrollPerkType.Bloqueo => "Aegis: Aumenta en +" + text2 + " el poder de bloqueo del escudo", ScrollPerkType.Parry => "Contraataque: Aumenta en +" + text2 + " el multiplicador de parry", ScrollPerkType.NoMovPen => "Sin Límites: Elimina la penalización de movimiento de la armadura", ScrollPerkType.WeapSkill => "Destreza: Aumenta en +" + text2 + " la habilidad del arma equipada", ScrollPerkType.Weight => "Sobrecarga: Aumenta en +" + text2 + " el peso máximo que puedes cargar", _ => byName.DisplayName + ": +" + text2, }; if (1 == 0) { } string text4 = text3; return filledChar + " " + text4 + ""; } private static string TranslateFaction(string faction) { if (1 == 0) { } string result = faction switch { "AnimalsVeg" => "Animales", "ForestMonsters" => "Monstruos del Bosque", "Undead" => "No Muertos", "Demon" => "Demonios", "MountainMonsters" => "Monstruos de Montaña", "SeaMonsters" => "Monstruos del Mar", "PlainsMonsters" => "Monstruos de Llanos", "Boss" => "Jefes", "MistlandsMonsters" => "Monstruos de Niebla", "Dverger" => "Dverger", _ => faction, }; if (1 == 0) { } return result; } } [HarmonyPatch] public static class ScrollDropPatch { [HarmonyPatch(typeof(Humanoid), "UseItem")] [HarmonyPrefix] public static bool UseItem_Prefix(Humanoid __instance, Inventory inventory, ItemData item, bool fromInventoryGui) { if (item == null) { return true; } if (!ScrollItem.IsEnchantScroll(item)) { return true; } return false; } } public class ScrollEnchantUI : MonoBehaviour { private ItemData _scrollItem; private ItemData _targetItem; private bool _isOpen; private GameObject _titlePanel; private GameObject _leftPanel; private GameObject _rightPanel; private GameObject _bottomPanel; private Image _weaponIcon; private Text _weaponHint; private Text _weaponLabelText; private Image _scrollIcon; private Text _scrollPerkText; private Text _statusText; private Text _itemNameText; private Text _slotsAvailText; private Text _perksCurrentText; private Text _perksNewText; private Text _smithLevelText; private Button _acceptBtn; private Image _coinIcon; private Text _coinCostText; private const float LeftW = 300f; private const float RightW = 460f; private const float BodyH = 540f; private const float Gap = 10f; private const float TotalW = 770f; private const float BottomH = 80f; private const string COIN_PREFAB_NAME = "Coins"; private Text _titleText; public static ScrollEnchantUI Instance { get; private set; } private static int GetSmithLevelRequired(ItemRarity rarity) { if (1 == 0) { } int result = rarity switch { ItemRarity.Common => 0, ItemRarity.Uncommon => 10, ItemRarity.Rare => 25, ItemRarity.Epic => 50, ItemRarity.Legendary => 75, _ => 0, }; if (1 == 0) { } return result; } private static int GetCoinCost(ItemRarity rarity) { if (1 == 0) { } int result = rarity switch { ItemRarity.Common => 0, ItemRarity.Uncommon => 250, ItemRarity.Rare => 350, ItemRarity.Epic => 1000, ItemRarity.Legendary => 2500, _ => 0, }; if (1 == 0) { } return result; } private void Awake() { Instance = this; GUIManager.OnCustomGUIAvailable += OnGUIAvailable; } private void OnDestroy() { if ((Object)(object)Instance == (Object)(object)this) { Instance = null; } GUIManager.OnCustomGUIAvailable -= OnGUIAvailable; } private void OnGUIAvailable() { Object.Destroy((Object)(object)_titlePanel); _titlePanel = null; Object.Destroy((Object)(object)_leftPanel); _leftPanel = null; Object.Destroy((Object)(object)_rightPanel); _rightPanel = null; Object.Destroy((Object)(object)_bottomPanel); _bottomPanel = null; EnsurePanel(); } private void Update() { } public void Open(ItemData scrollItem) { if (scrollItem != null) { _scrollItem = scrollItem; _targetItem = null; EnsurePanel(); if (!((Object)(object)_titlePanel == (Object)null)) { RefreshUI(); _titlePanel.SetActive(true); _leftPanel.SetActive(true); _rightPanel.SetActive(true); _bottomPanel.SetActive(true); _isOpen = true; } } } public void Close() { ((MonoBehaviour)this).CancelInvoke("Close"); _isOpen = false; GameObject titlePanel = _titlePanel; if (titlePanel != null) { titlePanel.SetActive(false); } GameObject leftPanel = _leftPanel; if (leftPanel != null) { leftPanel.SetActive(false); } GameObject rightPanel = _rightPanel; if (rightPanel != null) { rightPanel.SetActive(false); } GameObject bottomPanel = _bottomPanel; if (bottomPanel != null) { bottomPanel.SetActive(false); } _scrollItem = null; _targetItem = null; } public void TrySetTarget(ItemData item) { if (_isOpen && item != null && RarityPatches.IsWeaponOrArmor(item)) { _targetItem = item; RefreshUI(); } } private void EnsurePanel() { //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009f: 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_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: 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_020b: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_026b: Unknown result type (might be due to invalid IL or missing references) //IL_02a7: Unknown result type (might be due to invalid IL or missing references) //IL_02e8: Unknown result type (might be due to invalid IL or missing references) //IL_0319: 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_0368: Unknown result type (might be due to invalid IL or missing references) //IL_03aa: Unknown result type (might be due to invalid IL or missing references) //IL_03ec: Unknown result type (might be due to invalid IL or missing references) //IL_03fb: 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_0433: Unknown result type (might be due to invalid IL or missing references) //IL_0452: Unknown result type (might be due to invalid IL or missing references) //IL_0485: Unknown result type (might be due to invalid IL or missing references) //IL_04a7: Unknown result type (might be due to invalid IL or missing references) //IL_04e4: Unknown result type (might be due to invalid IL or missing references) //IL_0505: Unknown result type (might be due to invalid IL or missing references) //IL_0527: Unknown result type (might be due to invalid IL or missing references) //IL_0566: Unknown result type (might be due to invalid IL or missing references) //IL_05a4: Unknown result type (might be due to invalid IL or missing references) //IL_05ca: Unknown result type (might be due to invalid IL or missing references) //IL_05f4: Unknown result type (might be due to invalid IL or missing references) //IL_0632: Unknown result type (might be due to invalid IL or missing references) //IL_0658: Unknown result type (might be due to invalid IL or missing references) //IL_0682: Unknown result type (might be due to invalid IL or missing references) //IL_06c4: Unknown result type (might be due to invalid IL or missing references) //IL_06d3: Unknown result type (might be due to invalid IL or missing references) //IL_06de: Unknown result type (might be due to invalid IL or missing references) //IL_070b: Unknown result type (might be due to invalid IL or missing references) //IL_0718: Unknown result type (might be due to invalid IL or missing references) //IL_071f: Expected O, but got Unknown //IL_0756: Unknown result type (might be due to invalid IL or missing references) //IL_075e: Unknown result type (might be due to invalid IL or missing references) //IL_0772: Unknown result type (might be due to invalid IL or missing references) //IL_0789: Unknown result type (might be due to invalid IL or missing references) //IL_07e7: Unknown result type (might be due to invalid IL or missing references) //IL_07f7: Unknown result type (might be due to invalid IL or missing references) //IL_07fe: Expected O, but got Unknown //IL_0828: Unknown result type (might be due to invalid IL or missing references) //IL_083f: Unknown result type (might be due to invalid IL or missing references) //IL_084e: Unknown result type (might be due to invalid IL or missing references) //IL_0853: Unknown result type (might be due to invalid IL or missing references) //IL_0854: Unknown result type (might be due to invalid IL or missing references) //IL_085c: Unknown result type (might be due to invalid IL or missing references) //IL_08a2: Unknown result type (might be due to invalid IL or missing references) //IL_08e9: Unknown result type (might be due to invalid IL or missing references) //IL_08f8: Unknown result type (might be due to invalid IL or missing references) //IL_0907: Unknown result type (might be due to invalid IL or missing references) //IL_093c: Unknown result type (might be due to invalid IL or missing references) //IL_0946: Expected O, but got Unknown //IL_0966: Unknown result type (might be due to invalid IL or missing references) //IL_0975: Unknown result type (might be due to invalid IL or missing references) //IL_0984: Unknown result type (might be due to invalid IL or missing references) //IL_09ad: Unknown result type (might be due to invalid IL or missing references) //IL_09b7: Expected O, but got Unknown if (!((Object)(object)_titlePanel != (Object)null) && GUIManager.Instance != null && !((Object)(object)GUIManager.CustomGUIFront == (Object)null)) { float num = -235f; float num2 = 155f; float num3 = 302f; float num4 = -316f; Color color = default(Color); ((Color)(ref color))..ctor(0.08f, 0.06f, 0.06f, 0.97f); _titlePanel = GUIManager.Instance.CreateWoodpanel(GUIManager.CustomGUIFront.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, num3), 770f, 58f, true); _titlePanel.SetActive(false); DarkenPanel(_titlePanel, color); GameObject val = GUIManager.Instance.CreateText("Encantamiento", _titlePanel.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, GUIManager.Instance.AveriaSerifBold, 27, GUIManager.Instance.ValheimOrange, true, Color.black, 750f, 35f, false); _titleText = val.GetComponent(); _titleText.alignment = (TextAnchor)4; _leftPanel = GUIManager.Instance.CreateWoodpanel(GUIManager.CustomGUIFront.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(num, 0f), 300f, 540f, false); _leftPanel.SetActive(false); DarkenPanel(_leftPanel, color); float num5 = 170f; float num6 = -60f; GameObject val2 = GUIManager.Instance.CreateText("Arma / Armadura", _leftPanel.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, num5 + 68f), GUIManager.Instance.AveriaSerifBold, 17, GUIManager.Instance.ValheimOrange, true, Color.black, 260f, 25f, false); _weaponLabelText = val2.GetComponent(); _weaponLabelText.alignment = (TextAnchor)4; GameObject val3 = CreateSlot(_leftPanel.transform, new Vector2(0f, num5)); _weaponIcon = ((Component)val3.transform.Find("Icon")).GetComponent(); _weaponHint = MakeText(_leftPanel.transform, new Vector2(0f, num5), 105f, 105f, 14); _weaponHint.text = "Click\nizquierdo"; ((Graphic)_weaponHint).color = new Color(0.5f, 0.5f, 0.5f); _weaponHint.alignment = (TextAnchor)4; MakeSep(_leftPanel.transform, new Vector2(0f, num5 - 78f)); MakeLabel(_leftPanel.transform, "Pergamino", new Vector2(0f, num6 + 68f), 260f, 17, orange: true); GameObject val4 = CreateSlot(_leftPanel.transform, new Vector2(0f, num6)); _scrollIcon = ((Component)val4.transform.Find("Icon")).GetComponent(); _scrollPerkText = MakeText(_leftPanel.transform, new Vector2(0f, num6 - 68f), 270f, 27f, 14); _scrollPerkText.alignment = (TextAnchor)4; _rightPanel = GUIManager.Instance.CreateWoodpanel(GUIManager.CustomGUIFront.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(num2, 0f), 460f, 540f, false); _rightPanel.SetActive(false); DarkenPanel(_rightPanel, color); _itemNameText = MakeText(_rightPanel.transform, new Vector2(0f, 228f), 420f, 30f, 25); _itemNameText.alignment = (TextAnchor)4; ((Graphic)_itemNameText).color = GUIManager.Instance.ValheimOrange; _slotsAvailText = MakeText(_rightPanel.transform, new Vector2(0f, 198f), 420f, 22f, 19); _slotsAvailText.alignment = (TextAnchor)4; ((Graphic)_slotsAvailText).color = new Color(0.75f, 0.75f, 0.75f); MakeSep(_rightPanel.transform, new Vector2(0f, 172f)); _statusText = MakeText(_rightPanel.transform, new Vector2(0f, 138f), 420f, 28f, 20); _statusText.alignment = (TextAnchor)4; _smithLevelText = MakeText(_rightPanel.transform, new Vector2(0f, 110f), 420f, 24f, 17); _smithLevelText.alignment = (TextAnchor)4; MakeSep(_rightPanel.transform, new Vector2(0f, 86f)); MakeLabel(_rightPanel.transform, "Perks actuales:", new Vector2(0f, 64f), 420f, 21); _perksCurrentText = MakeText(_rightPanel.transform, new Vector2(0f, -2f), 420f, 80f, 22); _perksCurrentText.alignment = (TextAnchor)1; MakeSep(_rightPanel.transform, new Vector2(0f, -50f)); MakeLabel(_rightPanel.transform, "Con este encanto:", new Vector2(0f, -72f), 420f, 21); _perksNewText = MakeText(_rightPanel.transform, new Vector2(0f, -138f), 420f, 80f, 22); _perksNewText.alignment = (TextAnchor)1; _bottomPanel = GUIManager.Instance.CreateWoodpanel(GUIManager.CustomGUIFront.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, num4), 770f, 80f, false); _bottomPanel.SetActive(false); DarkenPanel(_bottomPanel, color); GameObject val5 = new GameObject("CoinSlot"); val5.transform.SetParent(_bottomPanel.transform, false); RectTransform val6 = val5.AddComponent(); Vector2 val7 = default(Vector2); ((Vector2)(ref val7))..ctor(0.5f, 0.5f); val6.anchorMax = val7; val6.anchorMin = val7; val6.anchoredPosition = new Vector2(-345f, 0f); val6.sizeDelta = new Vector2(40f, 40f); Image val8 = val5.AddComponent(); Sprite sprite = GUIManager.Instance.GetSprite("item_background"); if ((Object)(object)sprite != (Object)null) { val8.sprite = sprite; val8.type = (Type)1; } ((Graphic)val8).color = new Color(0.1f, 0.1f, 0.1f, 0.6f); GameObject val9 = new GameObject("CoinIcon"); val9.transform.SetParent(val5.transform, false); RectTransform val10 = val9.AddComponent(); val10.anchorMin = new Vector2(0.1f, 0.1f); val10.anchorMax = new Vector2(0.9f, 0.9f); val7 = (val10.offsetMin = (val10.offsetMax = Vector2.zero)); _coinIcon = val9.AddComponent(); ((Behaviour)_coinIcon).enabled = false; ((Graphic)_coinIcon).raycastTarget = false; _coinCostText = MakeText(_bottomPanel.transform, new Vector2(-270f, 0f), 100f, 36f, 17); _coinCostText.alignment = (TextAnchor)3; GameObject val12 = GUIManager.Instance.CreateButton("ENCANTAR", _bottomPanel.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-110f, 0f), 180f, 50f); _acceptBtn = val12.GetComponent