Decompiled source of Silksong Keyboard Inventory Fix v0.1.1

inventory_key_fix.dll

Decompiled 2 weeks ago
using System;
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.Logging;
using HarmonyLib;
using HutongGames.PlayMaker;
using HutongGames.PlayMaker.Actions;
using InControl;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("inventory_key_fix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1+11e4e81d6a0acff03e100559728b327afa8c4c36")]
[assembly: AssemblyProduct("inventory_key_fix")]
[assembly: AssemblyTitle("inventory_key_fix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 inventory_key_fix
{
	[BepInPlugin("com.bigfootmech.silksong.inv_keyfix", "inventory_key_fix", "0.1.1")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(InventoryPaneInput), "GetInventoryInputPressed")]
		public class AtStart
		{
			[HarmonyPostfix]
			private static void Postfix(PaneTypes __result, HeroActions ia)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (ButtPressed(ia) && SanityCheck(__result) && (int)__result == 0 && (int)lastOpen != 0)
					{
						FsmSwitchToInv();
					}
				}
				catch (Exception)
				{
				}
			}

			private static bool SanityCheck(PaneTypes result)
			{
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)paneListPtr == (Object)null)
				{
					return false;
				}
				InventoryPane pane = paneListPtr.GetPane(result);
				if ((Object)(object)pane == (Object)null || !pane.IsAvailable)
				{
					return false;
				}
				return true;
			}

			private static bool ButtPressed(HeroActions ia)
			{
				if (!((OneAxisInputControl)ia.OpenInventory).WasPressed && !((OneAxisInputControl)ia.OpenInventoryMap).WasPressed && !((OneAxisInputControl)ia.OpenInventoryJournal).WasPressed && !((OneAxisInputControl)ia.OpenInventoryTools).WasPressed)
				{
					return ((OneAxisInputControl)ia.OpenInventoryQuests).WasPressed;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(InventoryPaneInput), "Update")]
		public class OnUpdateDo
		{
			[HarmonyPostfix]
			private static void Postfix(InventoryPaneInput __instance, ref PaneTypes ___paneControl, ref InventoryPaneList ___paneList)
			{
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				if ((int)___paneControl != -1)
				{
					if ((Object)(object)paneListPtr == (Object)null)
					{
						paneListPtr = ___paneList;
					}
					if ((Object)(object)inventoryObject == (Object)null)
					{
						inventoryObject = ((Component)___paneList).gameObject;
					}
					lastInst = __instance;
					lastOpen = ___paneControl;
				}
			}
		}

		[HarmonyPatch(typeof(SetCurrentInventoryPane), "OnEnter")]
		public class SetInvPane
		{
			[HarmonyPrefix]
			private static void Prefix(SetCurrentInventoryPane __instance)
			{
				if (((NamedVariable)__instance.PaneIndex).ToInt() == -1)
				{
					__instance.PaneIndex = FsmInt.op_Implicit(0);
				}
			}
		}

		private const string modGUID = "com.bigfootmech.silksong.inv_keyfix";

		internal static ManualLogSource Logger;

		private readonly Harmony harmony = new Harmony("com.bigfootmech.silksong.inv_keyfix");

		public const int INV_INDEX = 0;

		public static InventoryPaneList paneListPtr;

		public static InventoryPaneInput lastInst;

		public static GameObject inventoryObject;

		public static PaneTypes lastOpen = (PaneTypes)(-1);

		public static bool snapshot = false;

		public static FsmVariables savedVars = new FsmVariables();

		public static ListenForInventoryShortcut listenForInvShortInst;

		public static string saveState = "None";

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin inventory_key_fix is loaded!");
			harmony.PatchAll();
		}

		private static void FsmSwitchToInv()
		{
			if (!((Object)(object)inventoryObject == (Object)null))
			{
				PlayMakerFSM obj = PlayMakerFSM.FindFsmOnGameObject(inventoryObject, "Inventory Control");
				obj.FsmVariables.FindFsmInt("Target Pane Index").Value = 0;
				obj.SendEvent("MOVE PANE TO");
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "inventory_key_fix";

		public const string PLUGIN_NAME = "inventory_key_fix";

		public const string PLUGIN_VERSION = "0.1.1";
	}
}