Decompiled source of LootFilter v1.0.1

wonkotron.LootFilter.dll

Decompiled 6 months ago
using System;
using System.Diagnostics;
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 BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using JetBrains.Annotations;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("lootfilter")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("lootfilter")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d53493cc-38fc-46c6-9e06-45195b0efbd7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace lootfilter;

[BepInPlugin("wonkotron.LootFilter", "LootFilter", "1.0.1")]
public class LootFilter : BaseUnityPlugin
{
	internal const string ModName = "LootFilter";

	internal const string ModVersion = "1.0.1";

	internal const string Author = "wonkotron";

	private const string ModGUID = "wonkotron.LootFilter";

	private Harmony _harmony;

	public static ConfigEntry<bool> filterEnabled;

	private static ConfigEntry<string> blacklistString;

	private static LootFilter _instance;

	public static string[] blacklist { get; private set; }

	[UsedImplicitly]
	private void Awake()
	{
		_instance = this;
		_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "wonkotron.LootFilter");
		filterEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Filter", "Filter Enabled", true, "Enable Loot Filter");
		blacklistString = ((BaseUnityPlugin)this).Config.Bind<string>("Filter", "Item Blacklist", "", "Comma separated list (NO SPACES) of PrefabID strings (e.g. Resin,LeatherScraps)");
		blacklist = blacklistString.Value.Split(new char[1] { ',' });
		((BaseUnityPlugin)this).Config.SettingChanged += Config_SettingChanged;
	}

	private void Config_SettingChanged(object sender, EventArgs e)
	{
		((BaseUnityPlugin)this).Config.SettingChanged -= Config_SettingChanged;
		blacklist = blacklistString.Value.Split(new char[1] { ',' });
		((BaseUnityPlugin)this).Config.SettingChanged += Config_SettingChanged;
	}

	[UsedImplicitly]
	private void OnDestroy()
	{
		((BaseUnityPlugin)this).Config.SettingChanged -= Config_SettingChanged;
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}
}
[HarmonyPatch(typeof(Inventory), "CanAddItem", new Type[]
{
	typeof(ItemData),
	typeof(int)
})]
public static class Inventory_CanAddItem_Patch
{
	public static void Postfix(ItemData item, int stack, ref bool __result)
	{
		if (__result && LootFilter.filterEnabled.Value && LootFilter.blacklist.Contains(((Object)item.m_dropPrefab).name))
		{
			__result = false;
		}
	}
}