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 PickupFilter v1.0.0
plugins/PickupFilter.dll
Decompiled a day agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("PickupFilter")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("PickupFilter")] [assembly: AssemblyTitle("PickupFilter")] [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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace PickupFilter { [HarmonyPatch(typeof(Player), "AutoPickup")] internal static class AutoPickupPatch { private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { FieldInfo autoPickupField = AccessTools.Field(typeof(ItemDrop), "m_autoPickup"); MethodInfo filter = AccessTools.Method(typeof(Filter), "ShouldAutoPickup", (Type[])null, (Type[])null); int replaced = 0; foreach (CodeInstruction instruction in instructions) { if (CodeInstructionExtensions.LoadsField(instruction, autoPickupField, false)) { replaced++; yield return CodeInstructionExtensions.MoveBlocksFrom(CodeInstructionExtensions.MoveLabelsFrom(new CodeInstruction(OpCodes.Call, (object)filter), instruction), instruction); } else { yield return instruction; } } if (replaced != 1) { Plugin.Log.LogWarning((object)($"Expected 1 auto pickup check in Player.AutoPickup, patched {replaced}. " + "A game update may have changed it; the filter may not work.")); } } } internal sealed class ConfigurationManagerAttributes { public int? Order; public bool? HideDefaultButton; public Action<ConfigEntryBase> CustomDrawer; } internal static class Filter { private static readonly HashSet<string> s_blocked = new HashSet<string>(StringComparer.OrdinalIgnoreCase); public static void Load(string csv) { s_blocked.Clear(); if (string.IsNullOrEmpty(csv)) { return; } string[] array = csv.Split(new char[2] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < array.Length; i++) { string text = array[i].Trim(); if (text.Length > 0) { s_blocked.Add(text); } } } public static bool IsBlocked(ItemDrop drop) { return s_blocked.Contains(PrefabName(drop)); } public static bool Toggle(ItemDrop drop) { string item = PrefabName(drop); bool num = !s_blocked.Remove(item); if (num) { s_blocked.Add(item); } Plugin.BlockedItems.Value = string.Join(", ", s_blocked.OrderBy<string, string>((string n) => n, StringComparer.OrdinalIgnoreCase)); return num; } public static bool ShouldAutoPickup(ItemDrop drop) { if (drop.m_autoPickup) { if (Plugin.Enabled.Value) { return !IsBlocked(drop); } return true; } return false; } private static string PrefabName(ItemDrop drop) { return Utils.GetPrefabName(((Component)drop).gameObject); } } internal class HotkeyListener : MonoBehaviour { private static readonly Func<Player, bool> TakeInput = AccessTools.MethodDelegate<Func<Player, bool>>(AccessTools.Method(typeof(Player), "TakeInput", (Type[])null, (Type[])null), (object)null, true); private void Update() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.Enabled.Value) { return; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || !ZInput.GetKeyDown(Plugin.ToggleKey.Value, false) || !TakeInput(localPlayer)) { return; } GameObject hoverObject = ((Humanoid)localPlayer).GetHoverObject(); ItemDrop val = (((Object)(object)hoverObject != (Object)null) ? hoverObject.GetComponentInParent<ItemDrop>() : null); if (!((Object)(object)val == (Object)null) && !val.IsPiece()) { bool flag = Filter.Toggle(val); string text = Localization.instance.Localize(val.m_itemData.m_shared.m_name); MessageHud instance = MessageHud.instance; if (instance != null) { instance.ShowMessage((MessageType)1, text + ": " + (flag ? Texts.MessageOff : Texts.MessageOn), 0, (Sprite)null, false, true); } } } } [HarmonyPatch(typeof(ItemDrop), "GetHoverText")] internal static class HoverHint { private static void Postfix(ItemDrop __instance, ref string __result) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) if (Plugin.Enabled.Value && Plugin.ShowHoverHint.Value && !__instance.IsPiece()) { string text = $"[<color=yellow><b>{Plugin.ToggleKey.Value}</b></color>]"; __result += (Filter.IsBlocked(__instance) ? ("\n<color=#ff8c8c>" + Texts.HoverOff + "</color> " + text + " " + Texts.TurnOn) : ("\n" + text + " " + Texts.TurnOff)); } } } [BepInPlugin("batera.PickupFilter", "PickupFilter", "1.0.0")] public class Plugin : BaseUnityPlugin { public const string PluginGuid = "batera.PickupFilter"; public const string PluginName = "PickupFilter"; public const string PluginVersion = "1.0.0"; internal static ManualLogSource Log; internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<KeyCode> ToggleKey; internal static ConfigEntry<bool> ShowHoverHint; internal static ConfigEntry<string> BlockedItems; private Harmony _harmony; private void Awake() { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected O, but got Unknown //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; BindConfig(); Filter.Load(BlockedItems.Value); BlockedItems.SettingChanged += delegate { Filter.Load(BlockedItems.Value); }; GameObject val = new GameObject("PickupFilter"); Object.DontDestroyOnLoad((Object)val); val.AddComponent<HotkeyListener>(); _harmony = new Harmony("batera.PickupFilter"); _harmony.PatchAll(typeof(Plugin).Assembly); ((BaseUnityPlugin)this).Logger.LogInfo((object)"PickupFilter 1.0.0 loaded"); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } private void BindConfig() { Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "Enabled", true, Desc("Turn the filter on/off. When off, auto pickup (V) works exactly like the vanilla game.", 3)); ToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("1 - General", "ToggleKey", (KeyCode)108, Desc("Aim at an item on the ground and press this key to stop (or resume) auto picking up that item.", 2)); ShowHoverHint = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "ShowHoverHint", true, Desc("Show the auto pickup state and the key hint when aiming at items on the ground.", 1)); BlockedItems = ((BaseUnityPlugin)this).Config.Bind<string>("2 - Items", "BlockedItems", "", Desc("Items never auto picked up, as prefab names separated by commas (e.g. Stone, Wood). The easiest way to fill this is aiming at an item on the ground and pressing ToggleKey. Reset clears the list.", 1)); } private static ConfigDescription Desc(string text, int order) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown return new ConfigDescription(text, (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Order = order } }); } } internal static class Texts { public static string HoverOff { get { if (!Pt) { return "Auto pickup off"; } return "Coleta automática desligada"; } } public static string TurnOn { get { if (!Pt) { return "Auto pick up"; } return "Coletar automaticamente"; } } public static string TurnOff { get { if (!Pt) { return "Don't auto pick up"; } return "Não coletar automaticamente"; } } public static string MessageOff { get { if (!Pt) { return "auto pickup off"; } return "coleta automática desligada"; } } public static string MessageOn { get { if (!Pt) { return "auto pickup on"; } return "coleta automática ligada"; } } private static bool Pt { get { if (Localization.instance != null) { return Localization.instance.GetSelectedLanguage().StartsWith("Portuguese", StringComparison.OrdinalIgnoreCase); } return false; } } } }