Decompiled source of QSS EAQS Bridge v1.1.0

QSS_EAQS_Bridge.dll

Decompiled 13 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;

[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("QSS_EAQS_Bridge")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("QSS_EAQS_Bridge")]
[assembly: AssemblyTitle("QSS_EAQS_Bridge")]
[assembly: AssemblyVersion("1.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 TheShack.QssEaqsBridge
{
	[BepInPlugin("theshack.qss_eaqs_bridge", "QSS EAQS Bridge", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "theshack.qss_eaqs_bridge";

		public const string PluginName = "QSS EAQS Bridge";

		public const string PluginVersion = "1.1.0";

		private const string QssGuid = "goldenrevolver.quick_stack_store";

		private const string EaqsGuid = "randyknapp.mods.equipmentandquickslots";

		private const int EaqsHiddenRows = 3;

		private static ManualLogSource log;

		private static MethodInfo isSlotCell;

		private static MethodInfo getVisibleRows;

		private static bool loggedInvokeError;

		private readonly Harmony harmony = new Harmony("theshack.qss_eaqs_bridge");

		private void Awake()
		{
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Expected O, but got Unknown
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Expected O, but got Unknown
			log = ((BaseUnityPlugin)this).Logger;
			Type type = AccessTools.TypeByName("EquipmentAndQuickSlots.API");
			if (type != null)
			{
				isSlotCell = AccessTools.Method(type, "IsSlotCell", new Type[3]
				{
					typeof(int),
					typeof(int),
					typeof(string).MakeByRefType()
				}, (Type[])null);
			}
			MethodInfo methodInfo = AccessTools.Method("QuickStackStore.CompatibilitySupport:InternalIsEquipOrQuickSlot", (Type[])null, (Type[])null);
			if (isSlotCell == null || methodInfo == null)
			{
				log.LogWarning((object)("Not patching: EAQS IsSlotCell " + ((isSlotCell == null) ? "missing" : "found") + ", QSS InternalIsEquipOrQuickSlot " + ((methodInfo == null) ? "missing" : "found") + "."));
				return;
			}
			harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "InternalIsEquipOrQuickSlotPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			log.LogInfo((object)"Quick Stack now leaves Equipment and Quick Slots' armor and quick slots alone.");
			Type type2 = AccessTools.TypeByName("EquipmentAndQuickSlots.Slots");
			getVisibleRows = ((type2 == null) ? null : AccessTools.PropertyGetter(type2, "VisibleRows"));
			MethodInfo methodInfo2 = AccessTools.Method("QuickStackStore.SortModule:GetAllowedSlots", (Type[])null, (Type[])null);
			if (methodInfo2 == null)
			{
				log.LogWarning((object)"Not patching sort: QSS SortModule.GetAllowedSlots missing.");
				return;
			}
			harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "GetAllowedSlotsPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			log.LogInfo((object)"Quick Stack's sort now fills the visible inventory before Equipment and Quick Slots' hidden rows.");
		}

		private static void GetAllowedSlotsPostfix(Inventory __0, List<Vector2i> __result)
		{
			if (__result == null || __0 == null)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if (__0 != ((localPlayer != null) ? ((Humanoid)localPlayer).GetInventory() : null))
			{
				return;
			}
			int visibleRows = __0.GetHeight() - 3;
			try
			{
				if (getVisibleRows != null)
				{
					visibleRows = (int)getVisibleRows.Invoke(null, null);
				}
			}
			catch (Exception)
			{
			}
			List<Vector2i> list = __result.FindAll((Vector2i pos) => pos.y >= visibleRows);
			if (list.Count != 0)
			{
				__result.RemoveAll((Vector2i pos) => pos.y >= visibleRows);
				__result.AddRange(list);
			}
		}

		private static void InternalIsEquipOrQuickSlotPostfix(int __0, int __1, Vector2i __2, bool __3, ref bool __result)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (__result)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			Inventory val = ((localPlayer != null) ? ((Humanoid)localPlayer).GetInventory() : null);
			if (val == null || val.GetHeight() != __0 || val.GetWidth() != __1)
			{
				return;
			}
			object[] array = new object[3] { __2.x, __2.y, null };
			try
			{
				if (!(bool)isSlotCell.Invoke(null, array))
				{
					return;
				}
			}
			catch (Exception ex)
			{
				if (!loggedInvokeError)
				{
					loggedInvokeError = true;
					log.LogError((object)$"EAQS IsSlotCell failed, bridge inactive for this call: {ex.InnerException ?? ex}");
				}
				return;
			}
			if (!((array[2] as string) ?? "").StartsWith("Quick", StringComparison.OrdinalIgnoreCase) || __3)
			{
				__result = true;
			}
		}
	}
}