Decompiled source of BetterQuickSlots v0.1.0

BetterQuickSlots.dll

Decompiled 4 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BetterQuickSlots")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BetterQuickSlots")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("69c45483-8baf-46ea-a41c-1e3e262e7c9a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BetterQuickSlots;

[BepInPlugin("randyknapp.mods.betterquickslots", "Better Quick Slots", "0.1.0")]
public class BetterQuickSlots : BaseUnityPlugin
{
	public const string GUID = "randyknapp.mods.betterquickslots";

	public const string NAME = "Better Quick Slots";

	public const string VERSION = "0.1.0";

	public void Awake()
	{
		((BaseUnityPlugin)this).Logger.LogWarning((object)"Better Quick Slots Loaded");
		Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "randyknapp.mods.betterquickslots");
	}
}
[HarmonyPatch]
public static class UIInventoryStorageSlotPatch
{
	[HarmonyPatch(typeof(UIInventoryStorageSlot), "Init")]
	[HarmonyPostfix]
	public static void Init_Postfix(UIInventoryStorageSlot __instance, int index)
	{
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Expected O, but got Unknown
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		if (!(__instance is UIQuickSlot))
		{
			return;
		}
		Transform val = ((Component)__instance).transform.Find("slotDisplayText");
		if (!((Object)(object)val != (Object)null))
		{
			GameObject val2 = Object.Instantiate<GameObject>(((Component)((Component)__instance).transform.Find("tmpAmount")).gameObject, ((Component)__instance).transform);
			((Object)val2).name = "slotDisplayText";
			val2.SetActive(true);
			RectTransform val3 = (RectTransform)val2.transform;
			((Transform)val3).localPosition = new Vector3(0f, 0f);
			val3.anchoredPosition = new Vector2(0f, 0f);
			val3.anchorMin = Vector2.zero;
			val3.anchorMax = new Vector2(1f, 0f);
			val3.pivot = new Vector2(0.5f, 1f);
			val3.sizeDelta = new Vector2(0f, 30f);
			TextMeshProUGUI component = val2.GetComponent<TextMeshProUGUI>();
			((TMP_Text)component).alignment = (TextAlignmentOptions)514;
			switch (index)
			{
			default:
				((TMP_Text)component).text = $"[{index + 1}]";
				break;
			case 9:
				((TMP_Text)component).text = "[0]";
				break;
			case 10:
				((TMP_Text)component).text = "[-]";
				break;
			case 11:
				((TMP_Text)component).text = "[=]";
				break;
			}
		}
	}
}
[HarmonyPatch]
public static class UICombatPatch
{
	[HarmonyPatch(typeof(UICombat), "RefreshQuickSlot")]
	[HarmonyPrefix]
	public static bool RefreshQuickSlot_Prefix(UICombat __instance)
	{
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Expected O, but got Unknown
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		if (Global.code.Player.quickSlotStorage.MaxItemsAmount < 12)
		{
			Global.code.Player.quickSlotStorage.MaxItemsAmount = 12;
			RectTransform val = (RectTransform)((Component)__instance).transform.Find("Root/Combat GUI Group/Player Health Panel/Armor Panel");
			val.anchoredPosition = new Vector2(418f, 0f);
			Transform child = __instance.quickSlotIconGroup.GetChild(0);
			for (int i = 0; i < 4; i++)
			{
				GameObject val2 = Object.Instantiate<GameObject>(((Component)child).gameObject, __instance.quickSlotIconGroup);
				((Object)val2).name = $"QuickSlot_{9 + i}";
			}
		}
		return true;
	}

	private static void SelectNextItemOnQuickBar(int step)
	{
		Storage quickSlotStorage = Global.code.Player.quickSlotStorage;
		UICombat uiCombat = Global.code.uiCombat;
		int count = quickSlotStorage.Items.Count;
		int num = 0;
		if (!uiCombat.QuickSlotIndex.HasValue)
		{
			if (step > 0)
			{
				uiCombat.QuickSlotIndex = 0;
			}
			else if (step < 0)
			{
				uiCombat.QuickSlotIndex = count - 1;
			}
		}
		else
		{
			num = uiCombat.QuickSlotIndex.Value;
		}
		int num2 = (count + num + step) % count;
		for (int i = 0; i < count; i++)
		{
			if (!((Object)(object)quickSlotStorage.GetItemAtIndex(num2) == (Object)null))
			{
				break;
			}
			num2 = (count + num2 + step) % count;
		}
		uiCombat.QuickSlotIndex = num2;
	}

	[HarmonyPatch(typeof(UICombat), "CalculateQuickSlotIndex")]
	[HarmonyPostfix]
	public static void CalculateQuickSlotIndex_Postfix(UICombat __instance)
	{
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		if (Global.code.Player.IsBusy || (Object)(object)Global.code.Player.CurHelicopter != (Object)null || Global.code.uiCombat.IsFocusedInteraction || Global.code.Player.IsDead)
		{
			return;
		}
		Transform val = ((Component)__instance).transform.parent.Find("UIMain");
		Transform val2 = ((Component)__instance).transform.parent.Find("UIGameMenu");
		if (!((Component)val).gameObject.activeSelf && !((Component)val2).gameObject.activeSelf)
		{
			if (Input.mouseScrollDelta.y > 0f)
			{
				SelectNextItemOnQuickBar(-1);
			}
			else if (Input.mouseScrollDelta.y < 0f)
			{
				SelectNextItemOnQuickBar(1);
			}
		}
	}
}
[HarmonyPatch]
public static class PlayerCharacterPatch
{
	private static void OnQuickSlotPressed(PlayerCharacter __instance, int index)
	{
		__instance.UseItem(__instance.quickSlotStorage.GetItemAtIndex(index), true);
		Global.code.uiCombat.QuickSlotIndex = index;
	}

	[HarmonyPatch(typeof(PlayerCharacter), "UpdateKeys")]
	[HarmonyPrefix]
	public static bool UpdateKeys_Prefix(PlayerCharacter __instance)
	{
		if (Input.GetKeyDown((KeyCode)57))
		{
			OnQuickSlotPressed(__instance, 8);
			return false;
		}
		if (Input.GetKeyDown((KeyCode)48))
		{
			OnQuickSlotPressed(__instance, 9);
			return false;
		}
		if (Input.GetKeyDown((KeyCode)45))
		{
			OnQuickSlotPressed(__instance, 10);
			return false;
		}
		if (Input.GetKeyDown((KeyCode)61))
		{
			OnQuickSlotPressed(__instance, 11);
			return false;
		}
		if (Global.code.Player.IsBusy || (Object)(object)Global.code.Player.CurHelicopter != (Object)null || Global.code.uiCombat.IsFocusedInteraction || Global.code.Player.IsDead)
		{
			return true;
		}
		if (Global.code.uiCombat.QuickSlotIndex.HasValue && Input.GetMouseButtonDown(2))
		{
			Item selectedQuickSlotItem = Global.code.uiCombat.SelectedQuickSlotItem;
			if ((Object)(object)selectedQuickSlotItem != (Object)null)
			{
				__instance.UseItem(selectedQuickSlotItem, true);
				return false;
			}
		}
		return true;
	}
}