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 Inventory Finders v1.0.0
plugins/InventoryFinders/InventoryFinders.dll
Decompiled 2 weeks agousing System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyVersion("0.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [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 OctoberJemini.InventoryFinders { [BepInPlugin("OctoberJemini.InventoryFinders", "Inventory Finders", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { private sealed class FinderState { public readonly string Prefab; public Player Owner; public StatusEffect Added; public int Hash; public bool Failed; public FinderState(string prefab) { Prefab = prefab; } } public const string Guid = "OctoberJemini.InventoryFinders"; private ConfigEntry<bool> findersEnabled; private float nextCheck; private readonly FinderState[] finders = new FinderState[2] { new FinderState("Wishbone"), new FinderState("Andvaranaut") }; private void Awake() { findersEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Activate native Wishbone and Andvaranaut finders only while their items are carried in your inventory. No equipment slots required; original ranges."); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Inventory Finders loaded. Carry a Wishbone or Andvaranaut to activate its finder."); } private void Update() { if (Time.unscaledTime < nextCheck) { return; } nextCheck = Time.unscaledTime + 0.5f; FinderState[] array = finders; foreach (FinderState finderState in array) { if (!finderState.Failed) { try { Refresh(finderState); } catch (Exception ex) { finderState.Failed = true; Release(finderState); ((BaseUnityPlugin)this).Logger.LogError((object)(finderState.Prefab + " finder stopped after an error: " + ex)); } } } } private void Refresh(FinderState finder) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)finder.Owner != (Object)(object)localPlayer) { Release(finder); } if (!findersEnabled.Value || !Object.op_Implicit((Object)(object)localPlayer) || ((Character)localPlayer).IsDead()) { Release(finder); return; } if (!Object.op_Implicit((Object)(object)ObjectDB.instance)) { Release(finder); return; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(finder.Prefab); ItemDrop val = (Object.op_Implicit((Object)(object)itemPrefab) ? itemPrefab.GetComponent<ItemDrop>() : null); StatusEffect val2 = (((Object)(object)val != (Object)null && val.m_itemData != null && val.m_itemData.m_shared != null) ? val.m_itemData.m_shared.m_equipStatusEffect : null); if (!Object.op_Implicit((Object)(object)val2)) { Release(finder); return; } bool flag = false; Inventory inventory = ((Humanoid)localPlayer).GetInventory(); if (inventory != null) { foreach (ItemData allItem in inventory.GetAllItems()) { if (allItem != null && allItem.m_shared != null && allItem.m_shared.m_name == val.m_itemData.m_shared.m_name) { flag = true; break; } } } if (!flag) { Release(finder); return; } SEMan sEMan = ((Character)localPlayer).GetSEMan(); if (sEMan == null) { return; } finder.Hash = val2.NameHash(); StatusEffect statusEffect = sEMan.GetStatusEffect(finder.Hash); if (Object.op_Implicit((Object)(object)statusEffect)) { ShowIcon(statusEffect, val.m_itemData); if (Object.op_Implicit((Object)(object)finder.Added) && statusEffect != finder.Added) { finder.Added = null; } return; } finder.Owner = localPlayer; finder.Added = sEMan.AddStatusEffect(val2, false, 0, 0f, (short)(-1)); if (Object.op_Implicit((Object)(object)finder.Added)) { ShowIcon(finder.Added, val.m_itemData); } if (Object.op_Implicit((Object)(object)finder.Added)) { ((BaseUnityPlugin)this).Logger.LogInfo((object)(finder.Prefab + " inventory finder active; native range and pulses preserved.")); } } private static void ShowIcon(StatusEffect effect, ItemData item) { if (!Object.op_Implicit((Object)(object)effect.m_icon)) { effect.m_icon = item.GetIcon(); } effect.m_hidden = false; } private static bool Equipped(Player player, int hash) { Inventory inventory = ((Humanoid)player).GetInventory(); if (inventory == null) { return false; } foreach (ItemData equippedItem in inventory.GetEquippedItems()) { StatusEffect equipStatusEffect = equippedItem.m_shared.m_equipStatusEffect; if (Object.op_Implicit((Object)(object)equipStatusEffect) && equipStatusEffect.NameHash() == hash) { return true; } } return false; } private void Release(FinderState finder) { try { if (Object.op_Implicit((Object)(object)finder.Owner) && Object.op_Implicit((Object)(object)finder.Added) && !Equipped(finder.Owner, finder.Hash)) { SEMan sEMan = ((Character)finder.Owner).GetSEMan(); if (sEMan != null && sEMan.GetStatusEffect(finder.Hash) == finder.Added) { sEMan.RemoveStatusEffect(finder.Added, true); } } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)(finder.Prefab + " cleanup: " + ex.Message)); } finally { finder.Owner = null; finder.Added = null; } } private void OnDisable() { FinderState[] array = finders; foreach (FinderState finder in array) { Release(finder); } } private void OnDestroy() { FinderState[] array = finders; foreach (FinderState finder in array) { Release(finder); } } } }