Decompiled source of QuickslotPistols v1.0.1

QuickslotPistols.dll

Decompiled 2 weeks ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("OutwardModTemplate")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OutwardModTemplate")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c5450fe0-edcf-483f-b9ea-4b1ef9d36da7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace QuickslotPistols;

[BepInPlugin("Tchernobill.QuickslotPistols", "QuickslotPistols", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(WeaponLoadoutItem), "Load")]
	public class WeaponLoadoutItem_Load
	{
		private static void Postfix(ref WeaponLoadoutItem __instance)
		{
			WeaponLoadout __instance2 = (WeaponLoadout)(object)__instance;
			WeaponLoadout_Load.Postfix(ref __instance2);
		}
	}

	[HarmonyPatch(typeof(WeaponLoadout), "Load")]
	public class WeaponLoadout_Load
	{
		private static bool inhibitInstantLoading;

		public static void Postfix(ref WeaponLoadout __instance)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Invalid comparison between Unknown and I4
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Invalid comparison between Unknown and I4
			if (inhibitInstantLoading || !((Object)(object)__instance != (Object)null) || __instance.m_pendingLoading)
			{
				return;
			}
			ProjectileWeapon projectileWeapon = __instance.m_projectileWeapon;
			if (!((Object)(object)projectileWeapon != (Object)null) || (int)((Weapon)projectileWeapon).Type != 45)
			{
				return;
			}
			Character ownerCharacter = ((EffectSynchronizer)projectileWeapon).OwnerCharacter;
			if (!((Object)(object)ownerCharacter != (Object)null) || ownerCharacter.InCombat)
			{
				return;
			}
			List<ProjectileWeapon> itemOfType = ownerCharacter.Inventory.Pouch.GetItemOfType<ProjectileWeapon>();
			itemOfType.AddRange(((ItemContainer)ownerCharacter.Inventory.EquippedBag.Container).GetItemOfType<ProjectileWeapon>());
			for (int i = 0; i < itemOfType.Count; i++)
			{
				ProjectileWeapon val = itemOfType[i];
				if ((int)((Weapon)val).Type == 45 && !val.IsFullyLoaded)
				{
					inhibitInstantLoading = true;
					((Weapon)val).InstantLoadWeapon();
					inhibitInstantLoading = false;
				}
			}
			_ = itemOfType.Count;
			_ = 0;
		}
	}

	[HarmonyPatch(typeof(QuickSlot), "Activate")]
	public class QuickSlot_Activate
	{
		private static void Prefix(ref QuickSlot __instance)
		{
			Skill itemAsSkill = __instance.ItemAsSkill;
			PistolSkill val = (PistolSkill)(object)((itemAsSkill is PistolSkill) ? itemAsSkill : null);
			if (!((Object)(object)val != (Object)null) || !((Object)(object)((EffectSynchronizer)val).OwnerCharacter != (Object)null))
			{
				return;
			}
			Weapon leftHandWeapon = ((EffectSynchronizer)val).OwnerCharacter.LeftHandWeapon;
			ProjectileWeapon val2 = (ProjectileWeapon)(object)((leftHandWeapon is ProjectileWeapon) ? leftHandWeapon : null);
			if (Object.op_Implicit((Object)(object)val2))
			{
				if (((Weapon)val2).IsEmpty)
				{
					ProjectileWeapon pistolItem = getPistolItem(__instance.m_owner);
					if ((Object)(object)pistolItem != (Object)null && pistolItem.IsFullyLoaded)
					{
						((Item)pistolItem).TryQuickSlotUse();
					}
				}
			}
			else
			{
				ProjectileWeapon pistolItem2 = getPistolItem(__instance.m_owner);
				if ((Object)(object)pistolItem2 != (Object)null)
				{
					((Item)pistolItem2).TryQuickSlotUse();
				}
			}
		}

		private static ProjectileWeapon getPistolItem(Character m_owner)
		{
			ProjectileWeapon loadedPistol = null;
			ProjectileWeapon unloadedPistol = null;
			if ((Object)(object)loadedPistol == (Object)null && (Object)(object)m_owner.Inventory.Pouch != (Object)null && usePouch.Value)
			{
				getPistolsFromList(m_owner.Inventory.Pouch.GetItemOfType<ProjectileWeapon>(), ref loadedPistol, ref unloadedPistol);
			}
			if ((Object)(object)loadedPistol == (Object)null && m_owner.Inventory.HasABag && useBackPack.Value)
			{
				getPistolsFromList(((ItemContainer)m_owner.Inventory.EquippedBag.Container).GetItemOfType<ProjectileWeapon>(), ref loadedPistol, ref unloadedPistol);
			}
			if ((Object)(object)loadedPistol != (Object)null)
			{
				return loadedPistol;
			}
			return unloadedPistol;
		}

		private static void getPistolsFromList(List<ProjectileWeapon> containedPistols, ref ProjectileWeapon loadedPistol, ref ProjectileWeapon unloadedPistol)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Invalid comparison between Unknown and I4
			for (int i = 0; i < containedPistols.Count; i++)
			{
				ProjectileWeapon val = containedPistols[i];
				if (!Object.op_Implicit((Object)(object)val) || (int)((Weapon)val).Type != 45)
				{
					continue;
				}
				if ((Object)(object)loadedPistol == (Object)null && val.IsFullyLoaded)
				{
					loadedPistol = val;
					if ((Object)(object)unloadedPistol != (Object)null)
					{
						break;
					}
				}
				else if ((Object)(object)unloadedPistol == (Object)null)
				{
					unloadedPistol = val;
					if ((Object)(object)loadedPistol != (Object)null)
					{
						break;
					}
				}
			}
		}
	}

	public const string GUID = "Tchernobill.QuickslotPistols";

	public const string NAME = "QuickslotPistols";

	public const string VERSION = "1.0.1";

	internal static ManualLogSource Log;

	public static ConfigEntry<bool> useBackPack;

	public static ConfigEntry<bool> usePouch;

	internal void Awake()
	{
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		useBackPack = ((BaseUnityPlugin)this).Config.Bind<bool>("QuickslotPistols", "Pick from backpack.", true, "use and reload pistols from your worn backpack.");
		usePouch = ((BaseUnityPlugin)this).Config.Bind<bool>("QuickslotPistols", "Pick from pouch.", true, "use and reload pistols from your pouch.");
		new Harmony("Tchernobill.QuickslotPistols").PatchAll();
	}
}