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("InstantTakeItems")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("InstantTakeItems")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d3ae7b77-9644-4e91-9bca-24873b07dd67")]
[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 InstantTakeItems;
[BepInPlugin("com.outward.urbanvibes.instanttakeitems", "InstantTakeItems", "1.6")]
public class InstantTakeItems : BaseUnityPlugin
{
[HarmonyPatch(typeof(Character), "OnInteractButtonDown")]
private class Character_OnInteractButtonDown
{
[HarmonyPrefix]
public static bool Prefix(Character __instance)
{
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Expected O, but got Unknown
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 && val.HasHoldInteraction)
{
__instance.Interactable.TryActivateHoldAction(__instance);
return false;
}
}
return true;
}
}
[HarmonyPatch(typeof(InteractionDisplay), "SetInteractable")]
private class InteractionDisplay_OnRefreshLanguage
{
[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;
}
}
}
private const string ID = "com.outward.urbanvibes.instanttakeitems";
private const string NAME = "InstantTakeItems";
private const string VERSION = "1.6";
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 ConfigEntry<bool> cfgGatherItemsInstantly = null;
private static ConfigEntry<bool> cfgGatherTreesInstantly = null;
private static ConfigEntry<bool> cfgOpenChestsInstantly = null;
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, "");
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;
}
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());
}
}