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 Andvaranaut Enchanting v1.0.0
BepInEx/plugins/OctoberJemini-Andvaranaut_Enchanting/AndvaranautEnchanting.dll
Decompiled an hour agousing System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using EpicLoot; using HarmonyLib; using Jotunn.Utils; using Newtonsoft.Json; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: AssemblyVersion("1.0.0.0")] namespace OctoberJemini.AndvaranautEnchanting; internal static class MarkerPolicy { internal static int[] MarkerIndices(IList<string> effects) { List<int> list = new List<int>(); for (int num = effects.Count - 1; num >= 0; num--) { if (effects[num] == "Andvaranaut") { list.Add(num); } } return list.ToArray(); } internal static bool EmptyOriginal(int effects, int sockets, int socketed, string legendary, string set, bool unidentified, string name) { if (effects == 0 && sockets == 0 && socketed == 0 && string.IsNullOrEmpty(legendary) && string.IsNullOrEmpty(set) && !unidentified) { return string.IsNullOrEmpty(name); } return false; } } [BepInDependency("com.jotunn.jotunn", "2.30.2")] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] [BepInPlugin("OctoberJemini.AndvaranautEnchanting", "Andvaranaut Enchanting", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { [HarmonyPatch(typeof(EpicLoot), "SetupAndvaranaut")] private static class Setup { private static void Postfix() { GameObject val = EpicAssets.AssetBundle.LoadAsset<GameObject>("Andvaranaut"); if (Object.op_Implicit((Object)(object)val)) { Normalize(val.GetComponent<ItemDrop>().m_itemData); } } } [HarmonyPatch] private static class MagicQueries { private static IEnumerable<MethodBase> TargetMethods() { return (from m in typeof(ItemDataExtensions).GetMethods(BindingFlags.Static | BindingFlags.Public) where (m.Name == "IsMagic" || m.Name == "CanBeDisenchanted" || m.Name == "CanBeAugmented" || m.Name == "CanBeRunified") && m.GetParameters().Length > 0 && m.GetParameters()[0].ParameterType == typeof(ItemData) select m).Cast<MethodBase>(); } private static void Prefix(ItemData __0) { Normalize(__0); } } [HarmonyPatch(typeof(EpicLoot), "IsNotRestrictedItem")] private static class Restriction { private static void Postfix(ItemData __0, ref bool __result) { if (IsRing(__0)) { __result = true; } } } [HarmonyPatch(typeof(EpicLoot), "IsAllowedMagicItemType")] private static class Category { private static void Postfix(ItemData __0, ref bool __result) { if (IsRing(__0)) { __result = true; } } } [HarmonyPatch] private static class Tooltip { private static MethodBase TargetMethod() { return typeof(ItemData).GetMethods(BindingFlags.Static | BindingFlags.Public).Single((MethodInfo m) => m.Name == "GetTooltip" && m.GetParameters()[0].ParameterType == typeof(ItemData)); } private static void Postfix(ItemData __0, ref string __result) { if (IsRing(__0)) { __result += "\n\n<color=#E5C36B>Unique ability: Treasure finder</color>\nPermanent. Enchanting and disenchanting do not remove it."; } } } public const string Guid = "OctoberJemini.AndvaranautEnchanting"; internal const string Backup = "oct_andvaranaut_original_magic_v1"; private Harmony harmony; private float next; [ThreadStatic] private static bool migrating; private static Plugin instance; private void Awake() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown instance = this; harmony = new Harmony("OctoberJemini.AndvaranautEnchanting"); harmony.PatchAll(); } private void OnDestroy() { if (harmony != null) { harmony.UnpatchSelf(); } } private void Update() { if (Time.unscaledTime < next) { return; } next = Time.unscaledTime + 1f; GameObject val = (Object.op_Implicit((Object)(object)ObjectDB.instance) ? ObjectDB.instance.GetItemPrefab("Andvaranaut") : null); if (Object.op_Implicit((Object)(object)val)) { Normalize(val.GetComponent<ItemDrop>().m_itemData); } Player localPlayer = Player.m_localPlayer; if (!Object.op_Implicit((Object)(object)localPlayer)) { return; } foreach (ItemData allItem in ((Humanoid)localPlayer).GetInventory().GetAllItems()) { Normalize(allItem); } } internal static bool IsRing(ItemData item) { if (item == null || item.m_shared == null) { return false; } if (Object.op_Implicit((Object)(object)item.m_dropPrefab)) { return ((Object)item.m_dropPrefab).name == "Andvaranaut"; } GameObject val = (Object.op_Implicit((Object)(object)ObjectDB.instance) ? ObjectDB.instance.GetItemPrefab("Andvaranaut") : null); if (Object.op_Implicit((Object)(object)val)) { return object.ReferenceEquals(item.m_shared, val.GetComponent<ItemDrop>().m_itemData.m_shared); } return false; } internal static void Normalize(ItemData item) { if (migrating || !IsRing(item)) { return; } StatusEffect equipStatusEffect = item.m_shared.m_equipStatusEffect; if (!Object.op_Implicit((Object)(object)equipStatusEffect) || ((Object)equipStatusEffect).name != "Andvaranaut") { return; } migrating = true; try { MagicItem magicItem = ItemDataExtensions.GetMagicItem(item); if (magicItem != null && magicItem.Effects != null && magicItem.Effects.Any((MagicItemEffect e) => e.EffectType == "Andvaranaut")) { string text = MagicItemData.RawOf(item); MagicItem val = JsonConvert.DeserializeObject<MagicItem>(JsonConvert.SerializeObject((object)magicItem)); if (val == null) { throw new InvalidOperationException("Cannot copy ring enchantments"); } int[] array = MarkerPolicy.MarkerIndices(val.Effects.Select((MagicItemEffect e) => e.EffectType).ToArray()); foreach (int num2 in array) { val.RemoveEffectAt(num2); } if (item.m_customData == null) { item.m_customData = new Dictionary<string, string>(); } if (!item.m_customData.ContainsKey("oct_andvaranaut_original_magic_v1")) { item.m_customData.Add("oct_andvaranaut_original_magic_v1", text ?? ""); } if (MarkerPolicy.EmptyOriginal(val.Effects.Count, val.SocketCount, (val.Sockets != null) ? val.Sockets.Count : 0, val.LegendaryID, val.SetID, val.IsUnidentified, val.DisplayName)) { ItemDataExtensions.RemoveMagicItem(item); } else { ItemDataExtensions.SaveMagicItem(item, val); } } } catch (Exception ex) { if (Object.op_Implicit((Object)(object)instance)) { ((BaseUnityPlugin)instance).Logger.LogError((object)("Andvaranaut migration stopped: " + ex)); } } finally { migrating = false; } } }