Please disclose if your mod was created primarily 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 PickupBlacklist v1.0.2
PickupBlacklist.dll
Decompiled 3 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("PickupBlacklist")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("actuallytim")] [assembly: AssemblyProduct("PickupBlacklist")] [assembly: AssemblyCopyright("")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("bff5b111-9326-4950-b719-cabbdd23eb23")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace PickupBlacklist; [BepInPlugin("actuallytim.PickupBlacklist", "PickupBlacklist", "1.0.2")] public class PickupBlacklist : BaseUnityPlugin { public static class Reflector { public static FieldInfo PlayerAutoPickupMask; public static FieldInfo PlayerAutoPickupBool; static Reflector() { Type typeFromHandle = typeof(Player); PlayerAutoPickupMask = typeFromHandle.GetField("m_autoPickupMask", BindingFlags.Instance | BindingFlags.NonPublic); PlayerAutoPickupBool = typeFromHandle.GetField("m_enableAutoPickup", BindingFlags.Static | BindingFlags.NonPublic); } } [HarmonyPatch(typeof(Player), "AutoPickup")] public static class PickupPatch { private static bool Prefix(Player __instance, float dt) { //IL_0051: 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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Expected O, but got Unknown //IL_022b: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Unknown result type (might be due to invalid IL or missing references) //IL_0270: Unknown result type (might be due to invalid IL or missing references) //IL_0278: Unknown result type (might be due to invalid IL or missing references) //IL_027d: Unknown result type (might be due to invalid IL or missing references) //IL_0282: Unknown result type (might be due to invalid IL or missing references) //IL_0287: Unknown result type (might be due to invalid IL or missing references) //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Unknown result type (might be due to invalid IL or missing references) //IL_029f: Unknown result type (might be due to invalid IL or missing references) //IL_02a9: 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_02b0: Unknown result type (might be due to invalid IL or missing references) //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_02d8: Unknown result type (might be due to invalid IL or missing references) if (!(bool)Reflector.PlayerAutoPickupBool.GetValue(null)) { return false; } if (((Character)__instance).IsTeleporting()) { return false; } int num = (int)Reflector.PlayerAutoPickupMask.GetValue(__instance); Vector3 val = ((Component)__instance).transform.position + Vector3.up; Collider[] array = Physics.OverlapSphere(val, __instance.m_autoPickupRange, num); Collider[] array2 = array; foreach (Collider val2 in array2) { if ((Object)(object)val2.attachedRigidbody == (Object)null) { continue; } ItemDrop component = ((Component)val2.attachedRigidbody).GetComponent<ItemDrop>(); if ((Object)(object)component == (Object)null) { continue; } string item = ((Object)((Component)component).gameObject).name.Replace("(Clone)", ""); if (blacklist.Contains(item)) { continue; } FloatingTerrainDummy val3 = null; if ((Object)(object)component == (Object)null && (Object)(object)(val3 = ((Component)val2.attachedRigidbody).gameObject.GetComponent<FloatingTerrainDummy>()) != (Object)null) { component = ((Component)val3.m_parent).gameObject.GetComponent<ItemDrop>(); } if ((Object)(object)component == (Object)null || !component.m_autoPickup || component.IsPiece() || ((Humanoid)__instance).HaveUniqueKey(component.m_itemData.m_shared.m_name) || !((Component)component).GetComponent<ZNetView>().IsValid()) { continue; } if (!component.CanPickup(true)) { component.RequestOwn(); } else { if (component.InTar()) { continue; } component.Load(); Inventory val4 = (Inventory)AccessTools.Field(typeof(Humanoid), "m_inventory").GetValue(__instance); if (!val4.CanAddItem(component.m_itemData, -1) || component.m_itemData.GetWeight(-1) + val4.GetTotalWeight() > __instance.GetMaxCarryWeight()) { continue; } float num2 = Vector3.Distance(((Component)component).transform.position, val); if (num2 > __instance.m_autoPickupRange) { continue; } if (num2 < 0.3f) { ((Humanoid)__instance).Pickup(((Component)component).gameObject, true, true); continue; } Vector3 val5 = Vector3.Normalize(val - ((Component)component).transform.position); float num3 = 15f; Vector3 val6 = val5 * num3 * dt; Transform transform = ((Component)component).transform; transform.position += val6; if (Object.op_Implicit((Object)(object)val3)) { Transform transform2 = ((Component)val3).transform; transform2.position += val6; } } } return false; } } [HarmonyPatch(typeof(InventoryGui), "OnSelectedItem")] public static class ItemClickPatch { private static bool Prefix(ItemData item) { if (((KeyboardShortcut)(ref bindKey)).IsPressed()) { if (item == null) { return true; } string name = ((Object)item.m_dropPrefab).name; if (!blacklist.Contains(name)) { Blacklist(name); } else { Whitelist(name); } return false; } return true; } } [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static ConsoleEvent <>9__20_0; internal void <InitCommandWhitelist>b__20_0(ConsoleEventArgs args) { if (args.Args.Length == 2) { Whitelist(args.Args[1]); } else { Print("Must provide an item name to remove from Blacklist"); } } } private const string pluginGUID = "actuallytim.PickupBlacklist"; private const string pluginName = "PickupBlacklist"; private const string pluginVersion = "1.0.2"; private static ConfigEntry<string> blacklistConfig; private static ConfigEntry<KeyboardShortcut> bindKeyConfig; public static HashSet<string> blacklist = new HashSet<string>(); public static KeyboardShortcut bindKey; private bool settingKeybind = false; private bool setCommand = false; public static void Print(string message, bool showMessage = true, bool showInCenter = false) { Logger.CreateLogSource("PickupBlacklist").LogInfo((object)message); if (showMessage) { ShowMessage(message, showInCenter); } } private void Awake() { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown LoadConfig(); PopulateBlacklist(); InitCommandBlacklist(); InitCommandWhitelist(); InitCommandRemap(); Harmony val = new Harmony("actuallytim.PickupBlacklist"); val.PatchAll(); } private void Update() { //IL_0044: 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_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0058: 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_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) if (!settingKeybind) { return; } if (setCommand) { setCommand = false; return; } foreach (KeyCode value in Enum.GetValues(typeof(KeyCode))) { if (Input.GetKeyDown(value)) { bindKey = new KeyboardShortcut(value, Array.Empty<KeyCode>()); Print($"Blacklist Key set to: {(object)value}", showMessage: true, showInCenter: true); bindKeyConfig.Value = new KeyboardShortcut(value, Array.Empty<KeyCode>()); Print("Saved keybind configs", showMessage: false); settingKeybind = false; } } } private void LoadConfig() { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) blacklistConfig = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Blacklist", "", "List of item prefab names to exclude from auto-pickup separated by commas."); bindKeyConfig = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Controls", "BindKey", new KeyboardShortcut((KeyCode)308, Array.Empty<KeyCode>()), "Keybind to add/remove items from blacklist from clicking on the item in the inventory gui."); bindKey = bindKeyConfig.Value; } private void PopulateBlacklist() { Print("Populating blacklist from config", showMessage: false); Print(blacklistConfig.Value, showMessage: false); blacklist = new HashSet<string>(blacklistConfig.Value.Split(new char[1] { ',' })); if (blacklist.Contains("")) { blacklist.Remove(""); } SaveBlacklist(); } public static void SaveBlacklist() { Print("Saving current blacklist", showMessage: false); blacklistConfig.Value = string.Join(",", blacklist); } private void ClearBlacklist() { blacklist = new HashSet<string>(); SaveBlacklist(); } private void InitCommandRemap() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown //IL_0020: Unknown result type (might be due to invalid IL or missing references) new ConsoleCommand("setblacklistkey", "Set the key to add items to the blacklist from inventory guis", (ConsoleEvent)delegate(ConsoleEventArgs args) { setCommand = true; settingKeybind = true; args.Context.AddString("Waiting for new keybind"); }, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); } private void InitCommandBlacklist() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown //IL_0020: Unknown result type (might be due to invalid IL or missing references) new ConsoleCommand("blacklist", "Add an item to or view the blacklist", (ConsoleEvent)delegate(ConsoleEventArgs args) { if (args.Args.Length > 1) { if (args.Args[1].ToLower() == "clear") { ClearBlacklist(); args.Context.AddString("Cleared blacklist."); return; } Blacklist(args.Args[1]); } if (args.Args.Length == 1) { ShowBlacklist(args); } }, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); } public static void Blacklist(string itemName, bool showMessage = true) { itemName = char.ToUpper(itemName[0]) + itemName.Substring(1); Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null)) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(itemName); if ((Object)(object)itemPrefab == (Object)null) { Print("Item with name " + itemName + " not found, unable to add to Blacklist", showMessage); } else if (!blacklist.Contains(((Object)itemPrefab).name)) { blacklist.Add(((Object)itemPrefab).name); Print("Added " + itemName + " to Blacklist", showMessage, showInCenter: true); SaveBlacklist(); } } } private void ShowBlacklist(ConsoleEventArgs console) { console.Context.AddString("\nBlacklist:"); if (blacklist.Count == 0) { console.Context.AddString("-EMPTY-"); return; } foreach (string item in blacklist) { console.Context.AddString("- " + item); } } private void InitCommandWhitelist() { //IL_0033: 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_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown object obj = <>c.<>9__20_0; if (obj == null) { ConsoleEvent val = delegate(ConsoleEventArgs args) { if (args.Args.Length == 2) { Whitelist(args.Args[1]); } else { Print("Must provide an item name to remove from Blacklist"); } }; <>c.<>9__20_0 = val; obj = (object)val; } new ConsoleCommand("whitelist", "Remove an item from the blacklist", (ConsoleEvent)obj, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); } public static void Whitelist(string itemName, bool showMessage = true) { itemName = char.ToUpper(itemName[0]) + itemName.Substring(1); Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null) && blacklist.Contains(itemName)) { blacklist.Remove(itemName); Print("Removed " + itemName + " from Blacklist", showMessage, showInCenter: true); } } public static void ShowMessage(string message, bool showInCenter) { Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null)) { if (showInCenter) { ((Character)localPlayer).Message((MessageType)2, message, 0, (Sprite)null); } else { ((Character)localPlayer).Message((MessageType)1, message, 0, (Sprite)null); } } } }