Decompiled source of PickupShareApi v1.0.0

PickupShareApi.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using RoR2;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("PickupShareApi")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PickupShareApi")]
[assembly: AssemblyTitle("PickupShareApi")]
[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 PickupShare
{
	public interface IPickupStateProvider
	{
		string Name { get; }

		bool HasOrbState(int instanceId);

		bool HasPickerState(int instanceId);

		bool TransferOrbState(int oldInstanceId, int newInstanceId);

		bool TransferPickerState(int oldInstanceId, int newInstanceId);

		void ForgetOrb(int instanceId);

		void ForgetPicker(int instanceId);
	}
	public static class PickupClassifier
	{
		public static bool IsCommandCube(PickupPickerController picker)
		{
			if ((Object)(object)picker == (Object)null || picker.isDelusionChoice || picker.isRebirthChoice)
			{
				return false;
			}
			if (!HasCreatePickupListener((UnityEventBase)(object)picker.onPickupSelected))
			{
				return HasCreatePickupListener((UnityEventBase)(object)picker.onUniquePickupSelected);
			}
			return true;
		}

		public static bool IsRuntimeSpawned(Component component)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)component == (Object)null)
			{
				return false;
			}
			NetworkIdentity component2 = component.GetComponent<NetworkIdentity>();
			if ((Object)(object)component2 != (Object)null)
			{
				NetworkSceneId sceneId = component2.sceneId;
				return ((NetworkSceneId)(ref sceneId)).IsEmpty();
			}
			return false;
		}

		private static bool HasCreatePickupListener(UnityEventBase choiceEvent)
		{
			if (choiceEvent == null)
			{
				return false;
			}
			int persistentEventCount = choiceEvent.GetPersistentEventCount();
			for (int i = 0; i < persistentEventCount; i++)
			{
				if (choiceEvent.GetPersistentMethodName(i) == "CreatePickup")
				{
					return true;
				}
			}
			return false;
		}
	}
	public static class PickupShareApi
	{
		public const int ApiVersion = 1;

		private static IPickupStateProvider _provider;

		public static bool HasProvider => _provider != null;

		public static string ProviderName => _provider?.Name;

		public static IPickupStateProvider Provider => _provider;

		public static event Action<IPickupStateProvider> onProviderChanged;

		public static void RegisterProvider(IPickupStateProvider provider)
		{
			if (provider == null)
			{
				throw new ArgumentNullException("provider");
			}
			if (_provider != null && _provider != provider)
			{
				ManualLogSource log = PickupSharePlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("'" + provider.Name + "' is replacing '" + _provider.Name + "' as the pickup state provider. Only one mod can track drop collection state; expect the replaced one to misbehave."));
				}
			}
			_provider = provider;
			ManualLogSource log2 = PickupSharePlugin.Log;
			if (log2 != null)
			{
				log2.LogInfo((object)("Pickup state provider registered: " + provider.Name));
			}
			PickupShareApi.onProviderChanged?.Invoke(_provider);
		}

		public static void UnregisterProvider(IPickupStateProvider provider)
		{
			if (provider != null && _provider == provider)
			{
				_provider = null;
				ManualLogSource log = PickupSharePlugin.Log;
				if (log != null)
				{
					log.LogInfo((object)("Pickup state provider unregistered: " + provider.Name));
				}
				PickupShareApi.onProviderChanged?.Invoke(null);
			}
		}

		public static bool HasOrbState(int instanceId)
		{
			if (_provider != null)
			{
				return _provider.HasOrbState(instanceId);
			}
			return false;
		}

		public static bool HasPickerState(int instanceId)
		{
			if (_provider != null)
			{
				return _provider.HasPickerState(instanceId);
			}
			return false;
		}

		public static bool TransferOrbState(int oldInstanceId, int newInstanceId)
		{
			if (_provider != null)
			{
				return _provider.TransferOrbState(oldInstanceId, newInstanceId);
			}
			return false;
		}

		public static bool TransferPickerState(int oldInstanceId, int newInstanceId)
		{
			if (_provider != null)
			{
				return _provider.TransferPickerState(oldInstanceId, newInstanceId);
			}
			return false;
		}

		public static void ForgetOrb(int instanceId)
		{
			_provider?.ForgetOrb(instanceId);
		}

		public static void ForgetPicker(int instanceId)
		{
			_provider?.ForgetPicker(instanceId);
		}
	}
	[BepInPlugin("com.majai.pickupshareapi", "PickupShareApi", "1.0.0")]
	public class PickupSharePlugin : BaseUnityPlugin
	{
		public const string Guid = "com.majai.pickupshareapi";

		public const string Name = "PickupShareApi";

		public const string Version = "1.0.0";

		internal static ManualLogSource Log;

		public void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)(string.Format("{0} {1} loaded, contract version {2}. ", "PickupShareApi", "1.0.0", 1) + "This is a library; it does nothing by itself."));
		}
	}
}