Decompiled source of QuickslotFallback v1.0.4

QuickslotFallback.dll

Decompiled 2 months 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 QuickslotFallback;

[BepInPlugin("Tchernobill.QuickslotFallback", "QuickslotFallback", "1.0.4")]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(QuickSlot), "Activate")]
	public class QuickSlot_Activate
	{
		private static Dictionary<string, int> mappingStatusTagName2PotionID = new Dictionary<string, int>
		{
			{ "Rage", 4300050 },
			{ "Discipline", 4300060 },
			{ "Warm", 4300070 },
			{ "Cool", 4300080 },
			{ "Mist", 4300090 },
			{ "Blessed", 4300100 },
			{ "Possessed", 4300120 }
		};

		private static Dictionary<int, int> mappingItemID2SkillPrerequisite = new Dictionary<int, int>
		{
			{ 8100210, 8205170 },
			{ 8100220, 8205170 },
			{ 8100230, 8205170 },
			{ 8100240, 8205170 }
		};

		private static void Prefix(ref QuickSlot __instance)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Invalid comparison between I4 and Unknown
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			Skill itemAsSkill = __instance.ItemAsSkill;
			if ((Object)(object)itemAsSkill != (Object)null)
			{
				for (int i = 0; i < itemAsSkill.m_additionalConditions.Length; i++)
				{
					EffectCondition condition = itemAsSkill.m_additionalConditions[i].Condition;
					if (!((Object)(object)condition != (Object)null) || condition.IsValid(((Item)itemAsSkill).m_ownerCharacter) || !(condition is HasStatusEffectEffectCondition))
					{
						continue;
					}
					StatusEffectSelector statusEffect = ((HasStatusEffectEffectCondition)condition).StatusEffect;
					if (2 == (int)statusEffect.Type && statusEffect.StatusType != null && mappingStatusTagName2PotionID.TryGetValue(statusEffect.StatusType.Tag.TagName, out var value))
					{
						Item effectSourceItem = getEffectSourceItem(__instance.m_owner, value);
						if ((Object)(object)effectSourceItem != (Object)null)
						{
							effectSourceItem.TryQuickSlotUse();
						}
					}
				}
				Skill itemAsSkill2 = __instance.ItemAsSkill;
				AttackSkill val = (AttackSkill)(object)((itemAsSkill2 is AttackSkill) ? itemAsSkill2 : null);
				if (val == null)
				{
					return;
				}
				if (__instance.ItemAsSkill is MeleeSkill)
				{
					if (__instance.ItemAsSkill is CounterSkill)
					{
						if (!(__instance.ItemAsSkill is CounterAbsorbSkill) && !(__instance.ItemAsSkill is CounterSelfSkill))
						{
						}
					}
					else if (!(__instance.ItemAsSkill is LevelAttackSkill))
					{
					}
				}
				else if (!(__instance.ItemAsSkill is PistolSkill) && !(__instance.ItemAsSkill is RangeAttackSkill))
				{
					_ = __instance.ItemAsSkill is ThrowSkill;
				}
				if (val.RequiredOffHandTypes != null && val.RequiredOffHandTypes.Count > 0 && ((Object)(object)((Item)val).m_ownerCharacter.LeftHandWeapon == (Object)null || !val.RequiredOffHandTypes.Contains(((Item)val).m_ownerCharacter.LeftHandWeapon.Type)))
				{
					foreach (WeaponType requiredOffHandType in val.RequiredOffHandTypes)
					{
						Item weaponOfType = GetWeaponOfType(((Item)val).m_ownerCharacter, requiredOffHandType);
						if (Object.op_Implicit((Object)(object)weaponOfType))
						{
							weaponOfType.TryQuickSlotUse();
							break;
						}
					}
				}
				if (val.RequiredTags == null || val.RequiredTags.Length == 0)
				{
					return;
				}
				bool flag = true;
				if (mappingItemID2SkillPrerequisite.TryGetValue(((Item)val).ItemID, out var value2) && ((CharacterKnowledge)((Item)val).m_ownerCharacter.Inventory.SkillKnowledge).IsItemLearned(value2))
				{
					flag = false;
				}
				else
				{
					for (int j = 0; j < val.RequiredTags.Length; j++)
					{
						Tag tag = val.RequiredTags[j].Tag;
						if (((Object)(object)((Item)val).m_ownerCharacter.CurrentWeapon != (Object)null && ((Item)((Item)val).m_ownerCharacter.CurrentWeapon).HasTag(tag)) || ((Object)(object)((Item)val).m_ownerCharacter.LeftHandWeapon != (Object)null && ((Item)((Item)val).m_ownerCharacter.LeftHandWeapon).HasTag(tag)) || ((Object)(object)((Item)val).m_ownerCharacter.LeftHandEquipment != (Object)null && ((Item)((Item)val).m_ownerCharacter.LeftHandEquipment).HasTag(tag)))
						{
							flag = false;
						}
					}
				}
				if (!flag)
				{
					return;
				}
				for (int k = 0; k < val.RequiredTags.Length; k++)
				{
					Item itemFromTag = GetItemFromTag(((Item)val).m_ownerCharacter, val.RequiredTags[k].Tag);
					if (Object.op_Implicit((Object)(object)itemFromTag))
					{
						itemFromTag.TryQuickSlotUse();
					}
				}
			}
			else
			{
				_ = __instance.ItemIsEquipment;
			}
		}

		private static Item getItemFromList(List<string> containedItemUIDs)
		{
			Item val = null;
			for (int i = 0; i < containedItemUIDs.Count; i++)
			{
				val = ItemManager.Instance.GetItem(containedItemUIDs[i]);
				if ((Object)(object)val != (Object)null)
				{
					break;
				}
			}
			return val;
		}

		private static Item getEffectSourceItem(Character m_owner, int itemID)
		{
			Item val = null;
			if ((Object)(object)val == (Object)null && usePouch.Value)
			{
				val = getItemFromList(m_owner.Inventory.Pouch.GetContainedItemUIDs(itemID));
			}
			if ((Object)(object)val == (Object)null && m_owner.Inventory.HasABag && useBackPack.Value)
			{
				val = getItemFromList(((ItemContainer)m_owner.Inventory.EquippedBag.Container).GetContainedItemUIDs(itemID));
			}
			return val;
		}

		private static Item GetItemFromTag(ItemContainer container, Tag tag)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			Item val = null;
			List<Item> itemsFromTag = container.GetItemsFromTag(tag);
			for (int i = 0; i < itemsFromTag.Count; i++)
			{
				val = itemsFromTag[i];
				if ((Object)(object)val != (Object)null)
				{
					break;
				}
			}
			return val;
		}

		private static Item GetItemFromTag(Character m_owner, Tag tag)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			Item val = null;
			if ((Object)(object)val == (Object)null && usePouch.Value)
			{
				val = GetItemFromTag(m_owner.Inventory.Pouch, tag);
			}
			if ((Object)(object)val == (Object)null && m_owner.Inventory.HasABag && useBackPack.Value)
			{
				val = GetItemFromTag((ItemContainer)(object)m_owner.Inventory.EquippedBag.Container, tag);
			}
			return val;
		}

		private static Item GetWeaponOfType(ItemContainer container, WeaponType type)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			List<Weapon> itemOfType = container.GetItemOfType<Weapon>();
			if (itemOfType == null)
			{
				return null;
			}
			for (int i = 0; i < itemOfType.Count; i++)
			{
				Weapon val = itemOfType[i];
				if (val.Type == type)
				{
					return (Item)(object)val;
				}
			}
			return null;
		}

		private static Item GetWeaponOfType(Character m_owner, WeaponType type)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			Item val = null;
			if ((Object)(object)val == (Object)null && usePouch.Value)
			{
				val = GetWeaponOfType(m_owner.Inventory.Pouch, type);
			}
			if ((Object)(object)val == (Object)null && m_owner.Inventory.HasABag && useBackPack.Value)
			{
				val = GetWeaponOfType((ItemContainer)(object)m_owner.Inventory.EquippedBag.Container, type);
			}
			return val;
		}
	}

	public const string GUID = "Tchernobill.QuickslotFallback";

	public const string NAME = "QuickslotFallback";

	public const string VERSION = "1.0.4";

	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>("QuickslotFallback", "Pick from backpack.", true, "pick fallback items from your worn backpack.");
		usePouch = ((BaseUnityPlugin)this).Config.Bind<bool>("QuickslotFallback", "Pick from pouch.", true, "pick fallback items from your pouch.");
		new Harmony("Tchernobill.QuickslotFallback").PatchAll();
	}

	internal void Update()
	{
	}
}