Decompiled source of ArcherQuiverSlot v0.1.0

plugins/ArcherQuiverSlot/ArcherQuiverSlot.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.Bootstrap;
using ExtraSlots;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("ArcherQuiverSlot")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("ArcherQuiverSlot")]
[assembly: AssemblyTitle("ArcherQuiverSlot")]
[assembly: AssemblyVersion("0.1.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 Vercadi.ArcherQuiverSlot
{
	[BepInPlugin("vercadi.ArcherQuiverSlot", "Archer Quiver Slot", "0.1.0")]
	[BepInDependency("radamanto.Vikings_Archer", "1.2.1")]
	[BepInDependency("shudnal.ExtraSlots", "1.2.12")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInIncompatibility("Azumatt.AzuExtendedPlayerInventory")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "vercadi.ArcherQuiverSlot";

		private const string ArcherGuid = "radamanto.Vikings_Archer";

		private const string ExtraSlotsGuid = "shudnal.ExtraSlots";

		private const string SlotId = "VercadiArcherQuiver";

		private const string DiscoveryItems = "RDA_quiver_01,RDA_quiver_02,RDA_quiver_03";

		private Func<ItemData, bool> isQuiver;

		private Func<bool> isEnabled;

		private void Awake()
		{
			if (!HasVersion("radamanto.Vikings_Archer", "1.2.1") || !HasVersion("shudnal.ExtraSlots", "1.2.12"))
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Quiver slot not registered: this build was checked against Vikings Archer 1.2.1 and ExtraSlots 1.2.12. Review the bridge after updating either dependency.");
				return;
			}
			try
			{
				Type type = ((object)Chainloader.PluginInfos["radamanto.Vikings_Archer"].Instance).GetType().Assembly.GetType("Vikings_Archer.QuiverCustomSlotManager", throwOnError: true);
				MethodInfo method = type.GetMethod("IsQuiverItem", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(ItemData) }, null);
				MethodInfo method2 = type.GetMethod("IsSlotSystemEnabled", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null);
				if (method == null || method2 == null || method.ReturnType != typeof(bool) || method2.ReturnType != typeof(bool))
				{
					throw new InvalidOperationException("Vikings Archer quiver API signature changed.");
				}
				isQuiver = (Func<ItemData, bool>)Delegate.CreateDelegate(typeof(Func<ItemData, bool>), method);
				isEnabled = (Func<bool>)Delegate.CreateDelegate(typeof(Func<bool>), method2);
				if (API.FindSlot("VercadiArcherQuiver") != null)
				{
					throw new InvalidOperationException("The quiver slot ID is already registered.");
				}
				if (!API.AddSlot("VercadiArcherQuiver", (Func<string>)(() => "Quiver"), (Func<ItemData, bool>)Fits, (Func<bool>)IsAvailable))
				{
					throw new InvalidOperationException("ExtraSlots has no free custom equipment slot.");
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Registered one discovery-gated quiver slot. Vikings Archer retains equipment, effects, visuals and ammunition handling. No tome slot added.");
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Quiver slot registration failed: " + ex.Message));
			}
		}

		private static bool HasVersion(string guid, string expected)
		{
			if (Chainloader.PluginInfos.TryGetValue(guid, out var value))
			{
				return value.Metadata.Version.ToString() == expected;
			}
			return false;
		}

		private bool Fits(ItemData item)
		{
			if (item?.m_shared == null || (Object)(object)item.m_dropPrefab == (Object)null)
			{
				return false;
			}
			switch (((Object)item.m_dropPrefab).name)
			{
			case "RDA_quiver_01":
			case "RDA_quiver_02":
			case "RDA_quiver_03":
				return isQuiver(item);
			default:
				return false;
			}
		}

		private bool IsAvailable()
		{
			if (isEnabled())
			{
				return API.IsAnyMaterialDiscovered("RDA_quiver_01,RDA_quiver_02,RDA_quiver_03");
			}
			return false;
		}
	}
}