Decompiled source of EasyBackpack v1.1.0

EasyBackpack.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("EasyBackpack")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EasyBackpack")]
[assembly: AssemblyTitle("EasyBackpack")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace EasyBackpack;

[BepInPlugin("nickklmao.easybackpack", "EasyBackpack", "1.1.0")]
internal sealed class Entry : BaseUnityPlugin
{
	private const string MOD_NAME = "EasyBackpack";

	private static readonly ManualLogSource logger = Logger.CreateLogSource("EasyBackpack");

	private static ConfigEntry<KeyCode> backpackKey;

	private static ConfigEntry<KeyCode> alternativeBackpackKey;

	private static bool isAccessingBackpack;

	private static bool isAccessingCarriedPlayersBackpack;

	private static void BackpackWheelILHook(ILContext il)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		ILCursor val = new ILCursor(il);
		val.Emit<Entry>(OpCodes.Ldsfld, "isAccessingBackpack");
		ILLabel val2 = val.DefineLabel();
		val.Emit(OpCodes.Brtrue_S, (object)val2);
		val.GotoNext(new Func<Instruction, bool>[1]
		{
			(Instruction instruction) => ILPatternMatchingExt.MatchLdflda<BackpackWheel>(instruction, "backpack")
		});
		int index = val.Index;
		val.Index = index - 1;
		val.MarkLabel(val2);
	}

	private void Awake()
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Expected O, but got Unknown
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Expected O, but got Unknown
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		logger.LogInfo((object)"Creating config entries");
		backpackKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keybinds", "Backpack Key", (KeyCode)98, new ConfigDescription("The key you want to use to access the backpack while it's on your back", (AcceptableValueBase)null, Array.Empty<object>()));
		alternativeBackpackKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keybinds", "Alternative Backpack Key", (KeyCode)0, new ConfigDescription("An optional alternative key for accessing the backpack while it's on your back", (AcceptableValueBase)null, Array.Empty<object>()));
		logger.LogInfo((object)"Hooking BackpackWheel.Update");
		new ILHook((MethodBase)AccessTools.Method(typeof(BackpackWheel), "Update", (Type[])null, (Type[])null), new Manipulator(BackpackWheelILHook));
	}

	private void Update()
	{
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		Character localCharacter = Character.localCharacter;
		if (!Application.isFocused || !Object.op_Implicit((Object)(object)localCharacter))
		{
			isAccessingBackpack = false;
			return;
		}
		if (isAccessingCarriedPlayersBackpack)
		{
			if (!Object.op_Implicit((Object)(object)localCharacter.data.carriedPlayer))
			{
				goto IL_0063;
			}
		}
		else if (localCharacter.data.passedOut || localCharacter.data.dead || localCharacter.data.currentItem is Backpack)
		{
			goto IL_0063;
		}
		if (Input.GetKeyUp(backpackKey.Value) || Input.GetKeyUp(alternativeBackpackKey.Value))
		{
			isAccessingCarriedPlayersBackpack = (isAccessingBackpack = false);
		}
		else
		{
			if (!Input.GetKeyDown(backpackKey.Value) && !Input.GetKeyDown(alternativeBackpackKey.Value))
			{
				return;
			}
			if (localCharacter.player.backpackSlot.hasBackpack)
			{
				GUIManager.instance.OpenBackpackWheel(BackpackReference.GetFromEquippedBackpack(localCharacter));
				isAccessingBackpack = true;
				return;
			}
			Character carriedPlayer = localCharacter.data.carriedPlayer;
			if (carriedPlayer == null)
			{
				return;
			}
			Player player = carriedPlayer.player;
			if (player != null)
			{
				BackpackSlot backpackSlot = player.backpackSlot;
				if (backpackSlot != null && backpackSlot.hasBackpack)
				{
					GUIManager.instance.OpenBackpackWheel(BackpackReference.GetFromEquippedBackpack(carriedPlayer));
					isAccessingCarriedPlayersBackpack = (isAccessingBackpack = true);
				}
			}
		}
		return;
		IL_0063:
		isAccessingBackpack = false;
	}
}