Decompiled source of InstantTakeItems v1.8.1

InstantTakeItems.dll

Decompiled a day ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Instant Take Items")]
[assembly: AssemblyDescription("Pick up gatherable Items instantly without the hold timer")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("UrbanVibes")]
[assembly: AssemblyProduct("Instant Take Items")]
[assembly: AssemblyCopyright("Copyright ©  2021 - 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d3ae7b77-9644-4e91-9bca-24873b07dd67")]
[assembly: AssemblyFileVersion("1.8.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.8.0.0")]
namespace InstantTakeItems;

[BepInPlugin("com.outward.urbanvibes.instanttakeitems", "Instant Take Items", "1.8")]
public class InstantTakeItems : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Character), "OnInteractButtonDown")]
	private class Character_OnInteractButtonDown
	{
		[HarmonyPrefix]
		public static bool Prefix(Character __instance)
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)__instance.Interactable))
			{
				return false;
			}
			Item componentInParent = ((Component)__instance.Interactable).GetComponentInParent<Item>();
			if (!Object.op_Implicit((Object)(object)componentInParent))
			{
				return true;
			}
			if (((object)componentInParent).GetType() == typeof(Gatherable))
			{
				if (bGatherItemsInstantly)
				{
					__instance.Interactable.TryActivateHoldAction(__instance);
					return false;
				}
			}
			else if (((object)componentInParent).GetType() == typeof(CentralGatherable))
			{
				if (bGatherTreesInstantly)
				{
					__instance.Interactable.TryActivateHoldAction(__instance);
					return false;
				}
			}
			else if (((object)componentInParent).GetType() == typeof(TreasureChest))
			{
				InteractionTriggerBase val = (InteractionTriggerBase)fieldInteractionTrigger.GetValue(componentInParent);
				if (bOpenChestsInstantly && Object.op_Implicit((Object)(object)val) && val.HasHoldInteraction)
				{
					__instance.Interactable.TryActivateHoldAction(__instance);
					return false;
				}
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(InteractionDisplay), "SetInteractable")]
	private class InteractionDisplay_SetInteractable
	{
		[HarmonyPostfix]
		public static void Patching(InteractionDisplay __instance, InteractionTriggerBase _interactionTrigger)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			Item componentInParent = ((Component)_interactionTrigger).GetComponentInParent<Item>();
			if (!Object.op_Implicit((Object)(object)componentInParent))
			{
				return;
			}
			InputDisplay val = (InputDisplay)fieldInfoInteractionHold.GetValue(__instance);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			val.PrefixText = LocalizationManager.Instance.GetLoc("General_Hold");
			if (((object)componentInParent).GetType() == typeof(Gatherable))
			{
				if (bGatherItemsInstantly)
				{
					val.PrefixText = string.Empty;
				}
			}
			else if (((object)componentInParent).GetType() == typeof(CentralGatherable))
			{
				if (bGatherTreesInstantly)
				{
					val.PrefixText = string.Empty;
				}
			}
			else if (((object)componentInParent).GetType() == typeof(TreasureChest) && bOpenChestsInstantly && _interactionTrigger.HasHoldInteraction)
			{
				val.PrefixText = string.Empty;
			}
		}
	}

	[HarmonyPatch(typeof(WaterInteraction), "RefreshLocalization")]
	private class GatherWaterInteraction
	{
		[HarmonyPostfix]
		public static void Patching(WaterInteraction __instance, ref string ___m_defaultBaseText, ref string ___m_defaultHoldText)
		{
			if (bSwapWaterInteraction && ((object)__instance).GetType().ToString() == "GatherWaterInteraction")
			{
				___m_defaultBaseText = LocalizationManager.Instance.GetLoc("Interaction_Base_GatherWater");
				___m_defaultHoldText = LocalizationManager.Instance.GetLoc("Interaction_Base_GatherWater");
			}
		}
	}

	[HarmonyPatch(typeof(InteractionActivator), "InitDefaultInteractions")]
	private class InteractionActivator_InitDefaultInteractions
	{
		[HarmonyPostfix]
		public static void Patching(ref InteractionActivator __instance, ref Interaction ___m_defaultBasicInteraction, ref Interaction ___m_defaultHoldInteraction, ref Interaction ___m_sceneBasicInteraction, ref Interaction ___m_sceneHoldInteraction)
		{
			if (Object.op_Implicit((Object)(object)___m_defaultBasicInteraction) && Object.op_Implicit((Object)(object)___m_defaultHoldInteraction) && ((object)___m_defaultBasicInteraction).GetType().ToString() == "GatherWaterInteraction" && ((object)___m_defaultHoldInteraction).GetType().ToString() == "DrinkWaterInteraction")
			{
				if (!bSwapWaterInteraction)
				{
					return;
				}
				Interaction val = ___m_defaultHoldInteraction;
				___m_defaultHoldInteraction = ___m_defaultBasicInteraction;
				___m_defaultBasicInteraction = val;
			}
			if (Object.op_Implicit((Object)(object)___m_sceneBasicInteraction) && Object.op_Implicit((Object)(object)___m_sceneHoldInteraction) && ((object)___m_sceneBasicInteraction).GetType().ToString() == "GatherWaterInteraction" && ((object)___m_sceneHoldInteraction).GetType().ToString() == "DrinkWaterInteraction" && bSwapWaterInteraction)
			{
				Interaction val2 = ___m_sceneHoldInteraction;
				___m_sceneHoldInteraction = ___m_sceneBasicInteraction;
				___m_sceneBasicInteraction = val2;
			}
		}
	}

	[HarmonyPatch(typeof(GatherWaterInteractionTrigger), "StartInit")]
	private class GatherWaterInteractionTrigger_StartInit
	{
		[HarmonyPostfix]
		public static void Patching(ref GatherWaterInteractionTrigger __instance, ref EventActivator ___m_defaultTriggerManager, ref List<InteractionCondition> ___m_basicConditions, ref List<InteractionCondition> ___m_holdConditions)
		{
			if (bSwapWaterInteraction)
			{
				if (___m_basicConditions != null && ___m_holdConditions != null)
				{
					___m_holdConditions.AddRange(___m_basicConditions);
					___m_basicConditions.Clear();
				}
				OwnItemInteractionCondition component = ((Component)__instance).gameObject.GetComponent<OwnItemInteractionCondition>();
				if (Object.op_Implicit((Object)(object)component))
				{
					((InteractionCondition)component).IsForBasicAction = false;
				}
			}
		}
	}

	private const string ID = "com.outward.urbanvibes.instanttakeitems";

	private const string NAME = "Instant Take Items";

	private const string VERSION = "1.8";

	private static FieldInfo fieldInfoInteractionHold = null;

	private static FieldInfo fieldInteractionTrigger = null;

	private static bool bGatherItemsInstantly = true;

	private static bool bGatherTreesInstantly = true;

	private static bool bOpenChestsInstantly = true;

	private static bool bSwapWaterInteraction = true;

	private static ConfigEntry<bool> cfgGatherItemsInstantly = null;

	private static ConfigEntry<bool> cfgGatherTreesInstantly = null;

	private static ConfigEntry<bool> cfgOpenChestsInstantly = null;

	private static ConfigEntry<bool> cfgSwapWaterInteraction = null;

	private void Awake()
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		SetupConfiguration();
		fieldInfoInteractionHold = typeof(InteractionDisplay).GetField("m_interactionHold", AccessTools.all);
		fieldInteractionTrigger = typeof(Item).GetField("m_interactionTrigger", AccessTools.all);
		new Harmony("com.outward.urbanvibes.instanttakeitems").PatchAll(Assembly.GetExecutingAssembly());
	}

	private void SetupConfiguration()
	{
		cfgGatherItemsInstantly = ((BaseUnityPlugin)this).Config.Bind<bool>("", "Gather Items instantly?", true, "");
		cfgGatherTreesInstantly = ((BaseUnityPlugin)this).Config.Bind<bool>("", "Gather Wood from Trees instantly?", true, "");
		cfgOpenChestsInstantly = ((BaseUnityPlugin)this).Config.Bind<bool>("", "Open Chests instantly?", true, "");
		cfgSwapWaterInteraction = ((BaseUnityPlugin)this).Config.Bind<bool>("", "Swap Water Gather Interactions?", true, "");
		GetConfiguration();
		((BaseUnityPlugin)this).Config.SettingChanged -= OnSettingsChanged;
		((BaseUnityPlugin)this).Config.SettingChanged += OnSettingsChanged;
	}

	public void OnSettingsChanged(object sender, SettingChangedEventArgs e)
	{
		GetConfiguration();
	}

	private void GetConfiguration()
	{
		bGatherItemsInstantly = cfgGatherItemsInstantly.Value;
		bGatherTreesInstantly = cfgGatherTreesInstantly.Value;
		bOpenChestsInstantly = cfgOpenChestsInstantly.Value;
		bSwapWaterInteraction = cfgSwapWaterInteraction.Value;
	}
}