Decompiled source of FasterPickupText v1.1.1

FasterPickupText.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using On.RoR2;
using RoR2;
using RoR2.UI;
using UnityEngine;
using UnityEngine.AddressableAssets;

[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("FasterPickupText")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Mod for Risk of Rain 2")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+c377511eef640225fa747f372b4f977f8e0ef46d")]
[assembly: AssemblyProduct("FasterPickupText")]
[assembly: AssemblyTitle("FasterPickupText")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace System.Diagnostics.CodeAnalysis
{
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class MemberNotNullAttribute : Attribute
	{
		public string[] Members { get; }

		public MemberNotNullAttribute(string member)
		{
			Members = new string[1] { member };
		}

		public MemberNotNullAttribute(params string[] members)
		{
			Members = members;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class MemberNotNullWhenAttribute : Attribute
	{
		public bool ReturnValue { get; }

		public string[] Members { get; }

		public MemberNotNullWhenAttribute(bool returnValue, string member)
		{
			ReturnValue = returnValue;
			Members = new string[1] { member };
		}

		public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
		{
			ReturnValue = returnValue;
			Members = members;
		}
	}
}
namespace FasterPickupText
{
	[BepInPlugin("com.DestroyedClone.FasterPickupText", "Faster Pickup Text", "1.1.1")]
	public class FasterPickupTextPlugin : BaseUnityPlugin
	{
		public static ConfigEntry<float> cfgNewItemOverride;

		public static ConfigEntry<float> cfgFirstStackDuration;

		public static ConfigEntry<float> cfgSubsequentStackDuration;

		public static ConfigEntry<float> cfgNewEquipmentOverride;

		public static ConfigEntry<float> cfgEquipmentDuration;

		public static ConfigEntry<float> cfgFirstStackTransformationDuration;

		public static ConfigEntry<float> cfgSubsequentStackTransformationDuration;

		public static GameObject NotificationPrefab;

		public static List<ItemDef> queuedItemDefs = new List<ItemDef>();

		public static List<EquipmentDef> queuedEquipmentDefs = new List<EquipmentDef>();

		public static List<ArtifactDef> queuedArtifactDefs = new List<ArtifactDef>();

		public static List<MiscPickupDef> queuedMiscPickupDefs = new List<MiscPickupDef>();

		public static ConfigEntry<bool> RemoveFlash { get; set; }

		public static ConfigEntry<float> FadeDurationDefault { get; set; }

		public static ConfigEntry<bool> ClearTopNotification { get; set; }

		public void Start()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Expected O, but got Unknown
			NotificationPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/UI/NotificationPanel2.prefab").WaitForCompletion();
			RemoveFlash = ((BaseUnityPlugin)this).Config.Bind<bool>("Notifications", "Remove Flash", true, "If true, then the notification popup will not have an initial flash.");
			if (RemoveFlash.Value)
			{
				((Component)NotificationPrefab.transform.Find("CanvasGroup/Flash")).GetComponent<AnimateUIAlpha>().timeMax = 0f;
			}
			FadeDurationDefault = ((BaseUnityPlugin)this).Config.Bind<float>("Notifications", "Fade Out Duration", 0.5f, "The duration of time, in seconds, of the fade-out time of notifications.");
			NotificationPrefab.GetComponent<GenericNotification>().fadeOutT = FadeDurationDefault.Value;
			cfgNewItemOverride = ((BaseUnityPlugin)this).Config.Bind<float>("Item Notification", "NEW Item Duration", 6f, "Overrides first stack/subsequent stack durations.\nThe duration of time, in seconds, of how long to show the pickup notification of an item that hasn't been picked up before for the profile.");
			cfgFirstStackDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Item Notification", "First Stack Duration", 4f, "The duration of time, in seconds, of how long to show the item pickup notification for the first stack of item.");
			cfgSubsequentStackDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Item Notification", "Subsequent Stack Duration", 2f, "The duration of time, in seconds, of how long to show the item pickup notification for the subsequent stack of an item.");
			cfgNewEquipmentOverride = ((BaseUnityPlugin)this).Config.Bind<float>("Equipment Notification", "NEW Equipment Duration", 6f, "Overrides equipment pickup duration.\nThe duration of time, in seconds, of how long to show the pickup notification of an item that hasn't been picked up before for the profile.");
			cfgEquipmentDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Equipment Notification", "Equipment Pickup Duration", 4f, "The duration of time, in seconds, of how long to show the equipment pickup notification.");
			cfgFirstStackTransformationDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Transformation Notification", "First Stack Duration", 6f, "The duration of time, in seconds, of how long to show the transformation notification for the first stack of an item.");
			cfgSubsequentStackTransformationDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Transformation Notification", "Subsequent Stack Duration", 3f, "The duration of time, in seconds, of how long to show the initial transformation notification duration for the subsequent stack of an item.");
			ClearTopNotification = ((BaseUnityPlugin)this).Config.Bind<bool>("Notifications", "Immediately replaces the topmost pickup notification when picking up", false, (ConfigDescription)null);
			CharacterMasterNotificationQueue.PushNotification += new hook_PushNotification(CharacterMasterNotificationQueue_PushNotification);
			Run.onRunStartGlobal += ClearDiscoveredPickups;
			LocalUserManager.onUserSignIn += SubscribeToProfile;
			LocalUserManager.onUserSignOut += ClearProfileSubscription;
		}

		public void SubscribeToProfile(LocalUser localUser)
		{
			UserProfile userProfile = localUser.userProfile;
			userProfile.onPickupDiscovered = (Action<PickupIndex>)Delegate.Combine(userProfile.onPickupDiscovered, new Action<PickupIndex>(QueueDiscoveredPickup));
		}

		public void ClearProfileSubscription(LocalUser localUser)
		{
			UserProfile userProfile = localUser.userProfile;
			userProfile.onPickupDiscovered = (Action<PickupIndex>)Delegate.Remove(userProfile.onPickupDiscovered, new Action<PickupIndex>(QueueDiscoveredPickup));
		}

		public void ClearDiscoveredPickups(Run run)
		{
			queuedItemDefs.Clear();
			queuedEquipmentDefs.Clear();
			queuedArtifactDefs.Clear();
			queuedMiscPickupDefs.Clear();
		}

		private void QueueDiscoveredPickup(PickupIndex pickupIndex)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Invalid comparison between Unknown and I4
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Invalid comparison between Unknown and I4
			//IL_0019: 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_004f: Invalid comparison between Unknown and I4
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIndex);
			if (pickupDef != null)
			{
				if ((int)pickupDef.itemIndex != -1)
				{
					queuedItemDefs.Add(ItemCatalog.GetItemDef(pickupDef.itemIndex));
				}
				else if ((int)pickupDef.equipmentIndex != -1)
				{
					queuedEquipmentDefs.Add(EquipmentCatalog.GetEquipmentDef(pickupDef.equipmentIndex));
				}
				else if ((int)pickupDef.artifactIndex != -1)
				{
					queuedArtifactDefs.Add(ArtifactCatalog.GetArtifactDef(pickupDef.artifactIndex));
				}
			}
		}

		private void CharacterMasterNotificationQueue_PushNotification(orig_PushNotification orig, CharacterMasterNotificationQueue self, NotificationInfo notificationInfo, float duration)
		{
			float num = duration;
			bool flag = notificationInfo.transformation != (TransformationInfo)null;
			object data = notificationInfo.data;
			ItemDef val = (ItemDef)((data is ItemDef) ? data : null);
			if (val != null)
			{
				if (queuedItemDefs.Contains(val))
				{
					queuedItemDefs.Remove(val);
					num = cfgNewItemOverride.Value;
				}
				else
				{
					int itemCount = self.master.inventory.GetItemCount(val);
					num = ((!flag) ? ((itemCount <= 1) ? cfgFirstStackDuration.Value : cfgSubsequentStackDuration.Value) : ((itemCount <= 1) ? cfgFirstStackTransformationDuration.Value : cfgSubsequentStackTransformationDuration.Value));
				}
			}
			else
			{
				object data2 = notificationInfo.data;
				EquipmentDef val2 = (EquipmentDef)((data2 is EquipmentDef) ? data2 : null);
				if (val2 != null)
				{
					if (queuedEquipmentDefs.Contains(val2))
					{
						queuedEquipmentDefs.Remove(val2);
						num = cfgNewEquipmentOverride.Value;
					}
					else
					{
						num = cfgEquipmentDuration.Value;
					}
				}
				else
				{
					_ = notificationInfo.data is ArtifactDef;
				}
			}
			if (ClearTopNotification.Value && self.notifications.Count > 0)
			{
				self.notifications[0].duration = 0f;
			}
			duration = num;
			orig.Invoke(self, notificationInfo, duration);
		}
	}
}