Decompiled source of MysteryPickups v1.1.0

MysteryPickups.dll

Decompiled 12 hours ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using On.RoR2;
using RoR2;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace MysteryPickups;

[BepInPlugin("com.mysterypickups", "MysteryPickups", "1.1.0")]
public class MysteryPickups : BaseUnityPlugin
{
	public static ConfigEntry<bool> Enabled;

	public static ConfigEntry<bool> HideShopItems;

	public static ConfigEntry<bool> HideWhite;

	public static ConfigEntry<bool> HideGreen;

	public static ConfigEntry<bool> HideRed;

	public static ConfigEntry<bool> HideBoss;

	public static ConfigEntry<bool> HideLunar;

	public static ConfigEntry<bool> HideVoid;

	public static ConfigEntry<bool> HideFood;

	public static ConfigEntry<bool> HideCursedHexPage;

	public static ConfigEntry<bool> HideEquipment;

	public static ConfigEntry<bool> HideLunarEquipment;

	private static readonly FieldInfo HiddenField = typeof(PickupDisplay).GetField("hidden", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	public void Awake()
	{
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Expected O, but got Unknown
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: Expected O, but got Unknown
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: Expected O, but got Unknown
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Expected O, but got Unknown
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Expected O, but got Unknown
		Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Show items lying on the ground as a ? until someone picks them up.");
		HideShopItems = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "HideShopItems", false, "Also hide the items shown on multishop terminals, printers and other displays.");
		HideWhite = ((BaseUnityPlugin)this).Config.Bind<bool>("Hide by rarity", "HideWhite", true, "Hide common (white) items.");
		HideGreen = ((BaseUnityPlugin)this).Config.Bind<bool>("Hide by rarity", "HideGreen", true, "Hide uncommon (green) items.");
		HideRed = ((BaseUnityPlugin)this).Config.Bind<bool>("Hide by rarity", "HideRed", true, "Hide legendary (red) items.");
		HideBoss = ((BaseUnityPlugin)this).Config.Bind<bool>("Hide by rarity", "HideBoss", true, "Hide boss (yellow) items.");
		HideLunar = ((BaseUnityPlugin)this).Config.Bind<bool>("Hide by rarity", "HideLunar", true, "Hide lunar (blue) items.");
		HideVoid = ((BaseUnityPlugin)this).Config.Bind<bool>("Hide by rarity", "HideVoid", false, "Hide void (purple, corrupted) items. Off by default so you can see which void item it is before it corrupts your stuff.");
		HideFood = ((BaseUnityPlugin)this).Config.Bind<bool>("Hide by rarity", "HideFood", true, "Hide food items from Alloyed Collective.");
		HideCursedHexPage = ((BaseUnityPlugin)this).Config.Bind<bool>("Hide by rarity", "HideCursedHexPage", true, "Hide the cursed, hex and page items from Hallowed Concepts.");
		HideEquipment = ((BaseUnityPlugin)this).Config.Bind<bool>("Hide by rarity", "HideEquipment", true, "Hide normal (orange) equipment.");
		HideLunarEquipment = ((BaseUnityPlugin)this).Config.Bind<bool>("Hide by rarity", "HideLunarEquipment", true, "Hide lunar (blue) equipment.");
		PickupDisplay.SetPickup += new hook_SetPickup(PickupDisplay_SetPickup);
		PickupDisplay.RebuildModel += new hook_RebuildModel(PickupDisplay_RebuildModel);
		GenericPickupController.GetDisplayName += new hook_GetDisplayName(GenericPickupController_GetDisplayName);
		GenericPickupController.GetContextString += new hook_GetContextString(GenericPickupController_GetContextString);
		GenericPickupController.CanBeInspected += new hook_CanBeInspected(GenericPickupController_CanBeInspected);
	}

	public static bool HideRarity(PickupIndex pickupIndex)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Invalid comparison between Unknown and I4
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Invalid comparison between Unknown and I4
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Expected I4, but got Unknown
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		if (!Enabled.Value)
		{
			return false;
		}
		PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIndex);
		if (pickupDef == null)
		{
			return false;
		}
		if ((int)pickupDef.itemIndex != -1)
		{
			ItemTier itemTier = pickupDef.itemTier;
			switch ((int)itemTier)
			{
			case 0:
				return HideWhite.Value;
			case 1:
				return HideGreen.Value;
			case 2:
				return HideRed.Value;
			case 4:
				return HideBoss.Value;
			case 3:
				return HideLunar.Value;
			case 6:
			case 7:
			case 8:
			case 9:
				return HideVoid.Value;
			case 10:
				return HideFood.Value;
			case 11:
			case 12:
			case 13:
				return HideCursedHexPage.Value;
			default:
				return false;
			}
		}
		if ((int)pickupDef.equipmentIndex != -1)
		{
			EquipmentDef equipmentDef = EquipmentCatalog.GetEquipmentDef(pickupDef.equipmentIndex);
			if (!Object.op_Implicit((Object)(object)equipmentDef) || !equipmentDef.isLunar)
			{
				return HideEquipment.Value;
			}
			return HideLunarEquipment.Value;
		}
		return false;
	}

	private static bool ShouldHide(Component display, PickupIndex pickupIndex)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		if (!HideRarity(pickupIndex))
		{
			return false;
		}
		if (HideShopItems.Value)
		{
			return true;
		}
		return (Object)(object)display.GetComponentInParent<GenericPickupController>() != (Object)null;
	}

	private static void PickupDisplay_SetPickup(orig_SetPickup orig, PickupDisplay self, ref UniquePickup newPickup, bool newHidden)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		orig.Invoke(self, ref newPickup, newHidden || ShouldHide((Component)(object)self, newPickup.pickupIndex));
	}

	private static void PickupDisplay_RebuildModel(orig_RebuildModel orig, PickupDisplay self, GameObject modelObjectOverride)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (HiddenField != null && ShouldHide((Component)(object)self, self.GetPickupIndex()))
			{
				HiddenField.SetValue(self, true);
			}
		}
		catch
		{
		}
		orig.Invoke(self, modelObjectOverride);
	}

	private static string GenericPickupController_GetDisplayName(orig_GetDisplayName orig, GenericPickupController self)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		if (!HideRarity(self.pickup.pickupIndex))
		{
			return orig.Invoke(self);
		}
		return "?";
	}

	private static string GenericPickupController_GetContextString(orig_GetContextString orig, GenericPickupController self, Interactor activator)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		if (!HideRarity(self.pickup.pickupIndex))
		{
			return orig.Invoke(self, activator);
		}
		return "Pick up ?";
	}

	private static bool GenericPickupController_CanBeInspected(orig_CanBeInspected orig, GenericPickupController self)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		if (!HideRarity(self.pickup.pickupIndex))
		{
			return orig.Invoke(self);
		}
		return false;
	}
}