Decompiled source of BetterShop v1.0.0

plugins/FastBuy/FastBuy.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FishNet.Object.Synchronizing;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Samples.RebindUI;
using UnityEngine.Localization;
using UnityEngine.Localization.Components;
using UnityEngine.Localization.Settings;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FastBuy")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+303efadd365d9b55b5caee6910ee2016cdfc074e")]
[assembly: AssemblyProduct("FastBuy")]
[assembly: AssemblyTitle("FastBuy")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace FastBuy
{
	public class FastBuyRow : MonoBehaviour
	{
		public Transform Source;
	}
	public static class ControlsMenu
	{
		private const string TemplateAction = "ChangeBait";

		private static readonly FieldInfo ActionField = AccessTools.Field(typeof(RebindActionUI), "m_Action");

		private static readonly FieldInfo BindingIdField = AccessTools.Field(typeof(RebindActionUI), "m_BindingId");

		private static readonly HashSet<RebindActionUI> Pending = new HashSet<RebindActionUI>();

		private static readonly List<TextMeshProUGUI> Labels = new List<TextMeshProUGUI>();

		private static ModInput _input;

		public static void Init(ModInput input)
		{
			_input = input;
			Strings.LanguageChanged += OnLanguageChanged;
		}

		public static void Notice(RebindActionUI ui)
		{
			if (_input != null && ActionName(ui) == "ChangeBait")
			{
				Pending.Add(ui);
			}
		}

		public static void ProcessPending()
		{
			if (Pending.Count == 0)
			{
				return;
			}
			List<RebindActionUI> list = Pending.ToList();
			Pending.Clear();
			foreach (RebindActionUI item in list)
			{
				try
				{
					if ((Object)(object)item == (Object)null || ActionName(item) != "ChangeBait" || (Object)(object)((Component)item).GetComponentInParent<FastBuyRow>(true) != (Object)null)
					{
						continue;
					}
					Transform val = FindRow(((Component)item).transform);
					if (!((Object)(object)val.parent == (Object)null))
					{
						Transform column = FindTargetColumn(val);
						if (!AlreadyInjected(column, val))
						{
							Inject(val, column);
						}
					}
				}
				catch (Exception arg)
				{
					Plugin.Log.LogError((object)$"Could not add the FastBuy row to the Controls menu: {arg}");
				}
			}
		}

		private static Transform FindRow(Transform t)
		{
			Transform val = t;
			while ((Object)(object)val.parent != (Object)null && !((Component)val.parent).GetComponentsInChildren<RebindActionUI>(true).Any((RebindActionUI u) => ActionName(u) != "ChangeBait"))
			{
				val = val.parent;
			}
			return val;
		}

		private static Transform FindTargetColumn(Transform row)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			Transform parent = row.parent;
			if ((Object)(object)parent.parent == (Object)null)
			{
				return parent;
			}
			Transform result = parent;
			int num = RowCount(parent);
			foreach (Transform item in parent.parent)
			{
				Transform val = item;
				if (!((Object)(object)val == (Object)(object)parent) && !((Object)(object)((Component)val).GetComponent<LayoutGroup>() == (Object)null))
				{
					int num2 = RowCount(val);
					if (num2 > 0 && num2 < num)
					{
						result = val;
						num = num2;
					}
				}
			}
			return result;
		}

		private static int RowCount(Transform column)
		{
			return ((IEnumerable)column).Cast<Transform>().Count((Transform c) => (Object)(object)((Component)c).GetComponentInChildren<RebindActionUI>(true) != (Object)null);
		}

		private static bool AlreadyInjected(Transform column, Transform row)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			foreach (Transform item in column)
			{
				FastBuyRow component = ((Component)item).GetComponent<FastBuyRow>();
				if ((Object)(object)component != (Object)null && (Object)(object)component.Source == (Object)(object)row)
				{
					return true;
				}
			}
			return false;
		}

		private static void Inject(Transform row, Transform column)
		{
			Transform val = ((IEnumerable)column).Cast<Transform>().LastOrDefault((Func<Transform, bool>)((Transform c) => (Object)(object)((Component)c).GetComponentInChildren<RebindActionUI>(true) != (Object)null)) ?? row;
			int num = (((Object)(object)val.parent == (Object)(object)column) ? val.GetSiblingIndex() : (column.childCount - 1));
			GameObject val2 = Object.Instantiate<GameObject>(((Component)row).gameObject, column, false);
			((Object)val2).name = "FastBuy_" + _input.Bulk.name;
			val2.transform.SetSiblingIndex(num + 1);
			val2.AddComponent<FastBuyRow>().Source = row;
			Retarget(val2.transform);
			ChainNavigation(val, val2.transform);
			Plugin.Log.LogInfo((object)("Added the FastBuy row to the Controls menu under '" + ((Object)column).name + "'"));
		}

		private static void Retarget(Transform clone)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			HashSet<TextMeshProUGUI> excluded = new HashSet<TextMeshProUGUI>();
			List<Transform> overlays = new List<Transform>();
			TextMeshProUGUI val = null;
			RebindActionUI[] componentsInChildren = ((Component)clone).GetComponentsInChildren<RebindActionUI>(true);
			InputAction val3 = default(InputAction);
			int num = default(int);
			foreach (RebindActionUI val2 in componentsInChildren)
			{
				int num2;
				if (val2.ResolveActionAndBinding(ref val3, ref num))
				{
					InputBinding val4 = InputBinding.MaskByGroup("Controller");
					num2 = (((InputBinding)(ref val4)).Matches(val3.bindings[num]) ? 1 : 0);
				}
				else
				{
					num2 = 0;
				}
				bool flag = (byte)num2 != 0;
				ActionField.SetValue(val2, InputActionReference.Create(_input.Bulk));
				BindingIdField.SetValue(val2, (flag ? ModInput.BulkControllerId : ModInput.BulkKeyboardId).ToString());
				val2.UpdateBindingDisplay();
				TextMeshProUGUI[] array = (TextMeshProUGUI[])(object)new TextMeshProUGUI[3] { val2.bindingText, val2.rebindPrompt, val2.rebindInfo };
				foreach (TextMeshProUGUI val5 in array)
				{
					if ((Object)(object)val5 != (Object)null)
					{
						excluded.Add(val5);
					}
				}
				if ((Object)(object)val2.rebindOverlay != (Object)null)
				{
					overlays.Add(val2.rebindOverlay.transform);
				}
				if ((Object)(object)val == (Object)null && (Object)(object)val2.actionLabel != (Object)null && ((TMP_Text)val2.actionLabel).transform.IsChildOf(clone))
				{
					val = val2.actionLabel;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				val = ((IEnumerable<TextMeshProUGUI>)((Component)clone).GetComponentsInChildren<TextMeshProUGUI>(true)).FirstOrDefault((Func<TextMeshProUGUI, bool>)((TextMeshProUGUI t) => !excluded.Contains(t) && !overlays.Any((Transform o) => ((TMP_Text)t).transform.IsChildOf(o))));
			}
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"No label found in the cloned Controls row");
				return;
			}
			LocalizeStringEvent component = ((Component)val).GetComponent<LocalizeStringEvent>();
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = false;
			}
			((TMP_Text)val).text = Strings.Get("BulkRow");
			Labels.Add(val);
		}

		private static void ChainNavigation(Transform anchor, Transform clone)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Invalid comparison between Unknown and I4
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Invalid comparison between Unknown and I4
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			Selectable[] componentsInChildren = ((Component)anchor).GetComponentsInChildren<Selectable>(true);
			Selectable[] componentsInChildren2 = ((Component)clone).GetComponentsInChildren<Selectable>(true);
			if (componentsInChildren2.Length != componentsInChildren.Length)
			{
				return;
			}
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Selectable val = componentsInChildren[i];
				Navigation navigation = val.navigation;
				if ((int)((Navigation)(ref navigation)).mode != 4)
				{
					continue;
				}
				navigation = val.navigation;
				Selectable selectOnDown = ((Navigation)(ref navigation)).selectOnDown;
				Selectable val2 = componentsInChildren2[i];
				Navigation navigation2 = val2.navigation;
				((Navigation)(ref navigation2)).mode = (Mode)4;
				((Navigation)(ref navigation2)).selectOnUp = val;
				((Navigation)(ref navigation2)).selectOnDown = selectOnDown;
				navigation = val.navigation;
				((Navigation)(ref navigation2)).selectOnLeft = MapWithinRow(((Navigation)(ref navigation)).selectOnLeft, componentsInChildren, componentsInChildren2);
				navigation = val.navigation;
				((Navigation)(ref navigation2)).selectOnRight = MapWithinRow(((Navigation)(ref navigation)).selectOnRight, componentsInChildren, componentsInChildren2);
				val2.navigation = navigation2;
				Navigation navigation3 = val.navigation;
				((Navigation)(ref navigation3)).selectOnDown = val2;
				val.navigation = navigation3;
				if (!((Object)(object)selectOnDown != (Object)null))
				{
					continue;
				}
				navigation = selectOnDown.navigation;
				if ((int)((Navigation)(ref navigation)).mode == 4)
				{
					navigation = selectOnDown.navigation;
					if ((Object)(object)((Navigation)(ref navigation)).selectOnUp == (Object)(object)val)
					{
						Navigation navigation4 = selectOnDown.navigation;
						((Navigation)(ref navigation4)).selectOnUp = val2;
						selectOnDown.navigation = navigation4;
					}
				}
			}
		}

		private static Selectable MapWithinRow(Selectable target, Selectable[] original, Selectable[] clone)
		{
			int num = Array.IndexOf(original, target);
			if (num < 0)
			{
				return target;
			}
			return clone[num];
		}

		private static void OnLanguageChanged()
		{
			Labels.RemoveAll((TextMeshProUGUI l) => (Object)(object)l == (Object)null);
			foreach (TextMeshProUGUI label in Labels)
			{
				((TMP_Text)label).text = Strings.Get("BulkRow");
			}
		}

		private static string ActionName(RebindActionUI ui)
		{
			object? value = ActionField.GetValue(ui);
			InputActionReference val = (InputActionReference)((value is InputActionReference) ? value : null);
			if (!((Object)(object)val != (Object)null) || val.action == null)
			{
				return null;
			}
			return val.action.name;
		}
	}
	[HarmonyPatch(typeof(RebindActionUI), "OnEnable")]
	internal static class RebindActionUIOnEnablePatch
	{
		private static void Postfix(RebindActionUI __instance)
		{
			ControlsMenu.Notice(__instance);
		}
	}
	public sealed class FastBuyer : MonoBehaviour
	{
		internal ConfigEntry<bool> Enabled;

		internal ConfigEntry<int> BulkAmount;

		internal ConfigEntry<float> RepeatDelay;

		internal ConfigEntry<float> StartRate;

		internal ConfigEntry<float> MaxRate;

		internal ConfigEntry<float> RampTime;

		internal ConfigEntry<bool> LogSteps;

		internal ModInput Input;

		private static readonly FieldRef<PlayerHolding, Interactable> HoveredRef = AccessTools.FieldRefAccess<PlayerHolding, Interactable>("_interactable");

		private static readonly FieldRef<BaitPurchasable, BaitInfo> BaitRef = AccessTools.FieldRefAccess<BaitPurchasable, BaitInfo>("_bait");

		internal static readonly FieldRef<Purchasable, int> CostRef = AccessTools.FieldRefAccess<Purchasable, int>("_customCost");

		internal static readonly FieldRef<Purchasable, bool> FreeRef = AccessTools.FieldRefAccess<Purchasable, bool>("_isFree");

		private const float ConfirmTimeout = 1f;

		private BaitPurchasable _vendor;

		private Player _player;

		private bool _holding;

		private float _repeatStart;

		private float _nextStep;

		private int _waitForCount = -1;

		private float _waitUntil;

		public static FastBuyer Instance { get; private set; }

		public static bool Driving { get; private set; }

		public int Bought { get; private set; }

		public BaitPurchasable LastVendor => _vendor;

		private void Awake()
		{
			Instance = this;
		}

		public bool OnInteract(BaitPurchasable vendor, Player player)
		{
			if (Driving || !Enabled.Value || (Object)(object)vendor == (Object)null || (Object)(object)player == (Object)null || (Object)(object)player != (Object)(object)Player.LocalPlayer)
			{
				return false;
			}
			if (FreeRef.Invoke((Purchasable)(object)vendor) || CostRef.Invoke((Purchasable)(object)vendor) <= 0)
			{
				return false;
			}
			InputAction val = BuyAction();
			if (val == null || !val.WasPerformedThisFrame())
			{
				return false;
			}
			_vendor = vendor;
			_player = player;
			_holding = true;
			Bought = 0;
			_waitForCount = -1;
			_repeatStart = Time.unscaledTime + Mathf.Max(0f, RepeatDelay.Value);
			_nextStep = _repeatStart;
			Step();
			return true;
		}

		private void Update()
		{
			if (!_holding)
			{
				if (Bought > 0 && ((Object)(object)_player == (Object)null || (Object)(object)_player.Holding == (Object)null || (Object)(object)HoveredRef.Invoke(_player.Holding) != (Object)(object)_vendor))
				{
					Bought = 0;
				}
				return;
			}
			if (!StillBuying())
			{
				_holding = false;
				return;
			}
			float unscaledTime = Time.unscaledTime;
			if (_waitForCount >= 0)
			{
				if (OwnedCount() < _waitForCount && unscaledTime < _waitUntil)
				{
					return;
				}
				_waitForCount = -1;
			}
			if (!(unscaledTime < _nextStep))
			{
				if (!Step())
				{
					_holding = false;
					return;
				}
				float num = ((RampTime.Value > 0f) ? Mathf.Clamp01((unscaledTime - _repeatStart) / RampTime.Value) : 1f);
				float num2 = Mathf.Max(0.1f, Mathf.Lerp(StartRate.Value, MaxRate.Value, num));
				_nextStep = unscaledTime + 1f / num2;
			}
		}

		private bool StillBuying()
		{
			if ((Object)(object)_vendor == (Object)null || (Object)(object)_player == (Object)null || (Object)(object)_player != (Object)(object)Player.LocalPlayer || _player.BlockInputs)
			{
				return false;
			}
			InputAction val = BuyAction();
			if (val == null || !val.IsPressed())
			{
				return false;
			}
			return (Object)(object)HoveredRef.Invoke(_player.Holding) == (Object)(object)_vendor;
		}

		private bool Step()
		{
			int num = ((Input == null || !Input.Bulk.IsPressed()) ? 1 : Mathf.Max(1, BulkAmount.Value));
			int num2 = CostRef.Invoke((Purchasable)(object)_vendor);
			int val = ((num2 > 0) ? (MoneyManager.Money / num2) : num);
			int num3 = Math.Min(num, val);
			if (num3 <= 0)
			{
				Interact();
				return false;
			}
			int num4 = OwnedCount();
			for (int i = 0; i < num3; i++)
			{
				Interact();
			}
			Bought += num3;
			if (num4 >= 0)
			{
				_waitForCount = num4 + num3;
				_waitUntil = Time.unscaledTime + 1f;
			}
			if (LogSteps.Value)
			{
				Plugin.Log.LogInfo((object)$"Bought {num3} x {num2} (owned before {num4}, money before {MoneyManager.Money})");
			}
			return true;
		}

		private void Interact()
		{
			Driving = true;
			try
			{
				((Interactable)_vendor).Interact(_player);
			}
			finally
			{
				Driving = false;
			}
		}

		private int OwnedCount()
		{
			try
			{
				BaitInfo val = BaitRef.Invoke(_vendor);
				if ((Object)(object)val == (Object)null)
				{
					return -1;
				}
				int num = GameInfo.GetIndexOfBait(val) - 1;
				SyncList<int> ownedBaits = _player.Inventory._ownedBaits;
				return (num >= 0 && num < ownedBaits.Count) ? ownedBaits[num] : (-1);
			}
			catch (Exception)
			{
				return -1;
			}
		}

		private static InputAction BuyAction()
		{
			try
			{
				return ((Object)(object)GameInfo.Input != (Object)null) ? GameInfo.Input.actions.FindAction("PlayerPickUp", false) : null;
			}
			catch (Exception)
			{
				return null;
			}
		}

		public string HintFor(BaitPurchasable vendor)
		{
			if (!Enabled.Value || Input == null || FreeRef.Invoke((Purchasable)(object)vendor) || CostRef.Invoke((Purchasable)(object)vendor) <= 0)
			{
				return null;
			}
			string text = $"{ModInput.Display(Input.Bulk)} ×{Mathf.Max(1, BulkAmount.Value)}";
			if ((Object)(object)vendor == (Object)(object)_vendor && Bought > 1)
			{
				text += $"   +{Bought}";
			}
			return text;
		}
	}
	public sealed class ModInput
	{
		public const string KeyboardGroup = "Keyboard";

		public const string ControllerGroup = "Controller";

		public static readonly Guid BulkKeyboardId = new Guid("8c41d2a7-3f5e-4b19-a6d0-7e2f9b3c1a01");

		public static readonly Guid BulkControllerId = new Guid("8c41d2a7-3f5e-4b19-a6d0-7e2f9b3c1a02");

		private readonly InputActionAsset _asset;

		private readonly InputActionMap _map;

		private readonly ConfigEntry<string> _overrides;

		public InputAction Bulk { get; }

		public static ModInput Instance { get; private set; }

		public ModInput(ConfigEntry<string> overrides)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			Instance = this;
			_overrides = overrides;
			_asset = ScriptableObject.CreateInstance<InputActionAsset>();
			((Object)_asset).name = "FastBuyInput";
			Object.DontDestroyOnLoad((Object)(object)_asset);
			_map = new InputActionMap("FastBuy");
			InputActionSetupExtensions.AddActionMap(_asset, _map);
			Bulk = InputActionSetupExtensions.AddAction(_map, "BuyTimesTen", (InputActionType)1, (string)null, (string)null, (string)null, (string)null, (string)null);
			AddBinding(Bulk, BulkKeyboardId, "<Keyboard>/leftShift", "Keyboard");
			AddBinding(Bulk, BulkControllerId, "<Gamepad>/dpad/down", "Controller");
			Load();
			InputSystem.onActionChange += OnActionChange;
			_map.Enable();
		}

		private void AddBinding(InputAction action, Guid id, string path, string group)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			InputActionMap map = _map;
			InputBinding val = default(InputBinding);
			((InputBinding)(ref val)).id = id;
			((InputBinding)(ref val)).path = path;
			((InputBinding)(ref val)).groups = group;
			((InputBinding)(ref val)).action = action.name;
			InputActionSetupExtensions.AddBinding(map, val);
		}

		public static string Display(InputAction action)
		{
			try
			{
				return SpriteManager.InputToSpriteName(action, (InputSchemeSelection)0, -1) ?? "";
			}
			catch (Exception)
			{
				return InputActionRebindingExtensions.GetBindingDisplayString(action, (DisplayStringOptions)0, (string)null);
			}
		}

		private void Load()
		{
			if (string.IsNullOrEmpty(_overrides.Value))
			{
				return;
			}
			try
			{
				InputActionRebindingExtensions.LoadBindingOverridesFromJson((IInputActionCollection2)(object)_asset, _overrides.Value, true);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Ignoring invalid saved bindings: " + ex.Message));
			}
		}

		private void OnActionChange(object obj, InputActionChange change)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)change != 8)
			{
				return;
			}
			object obj2 = ((obj is InputAction) ? obj : null);
			if ((((obj2 != null) ? ((InputAction)obj2).actionMap : null) ?? ((obj is InputActionMap) ? obj : null)) == _map || obj == _asset)
			{
				string text = InputActionRebindingExtensions.SaveBindingOverridesAsJson((IInputActionCollection2)(object)_asset);
				if (text != _overrides.Value)
				{
					_overrides.Value = text;
				}
			}
		}
	}
	[HarmonyPatch(typeof(BaitPurchasable), "Interact")]
	internal static class BaitPurchasableInteractPatch
	{
		private static bool Prefix(BaitPurchasable __instance, Player player)
		{
			try
			{
				return (Object)(object)FastBuyer.Instance == (Object)null || !FastBuyer.Instance.OnInteract(__instance, player);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"FastBuy failed, buying normally: {arg}");
				return true;
			}
		}
	}
	[HarmonyPatch(typeof(Purchasable), "Hover")]
	internal static class PurchasableHoverPatch
	{
		private static readonly FieldRef<Purchasable, string> HoverStringRef = AccessTools.FieldRefAccess<Purchasable, string>("_hoverString");

		private static void Prefix(Purchasable __instance)
		{
			BaitPurchasable val = (BaitPurchasable)(object)((__instance is BaitPurchasable) ? __instance : null);
			if (val == null || (Object)(object)FastBuyer.Instance == (Object)null)
			{
				return;
			}
			try
			{
				string text = FastBuyer.Instance.HintFor(val);
				if (!string.IsNullOrEmpty(text))
				{
					ref string reference = ref HoverStringRef.Invoke(__instance);
					reference = reference + "\n" + text;
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not add the FastBuy hint: " + ex.Message));
			}
		}
	}
	[BepInPlugin("avidkaos.howtofish.fastbuy", "BetterShop", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "avidkaos.howtofish.fastbuy";

		public const string PluginName = "BetterShop";

		public const string PluginVersion = "1.0.0";

		internal static ManualLogSource Log;

		private ConfigEntry<string> _bindings;

		private FastBuyer _buyer;

		private ModInput _input;

		private void Awake()
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Expected O, but got Unknown
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Expected O, but got Unknown
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			_buyer = ((Component)this).gameObject.AddComponent<FastBuyer>();
			_buyer.Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Hold the buy button at a bait shop to keep buying; hold the x10 modifier to buy 10 per step.");
			_buyer.BulkAmount = ((BaseUnityPlugin)this).Config.Bind<int>("General", "BulkAmount", 10, new ConfigDescription("How many bait one press buys while the modifier is held.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(2, 100), Array.Empty<object>()));
			_buyer.RepeatDelay = ((BaseUnityPlugin)this).Config.Bind<float>("Speed", "RepeatDelay", 0.4f, new ConfigDescription("Seconds the buy button must be held before it starts repeating.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>()));
			_buyer.StartRate = ((BaseUnityPlugin)this).Config.Bind<float>("Speed", "StartRate", 3f, new ConfigDescription("Purchases (or x10 steps) per second when repeating starts.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 30f), Array.Empty<object>()));
			_buyer.MaxRate = ((BaseUnityPlugin)this).Config.Bind<float>("Speed", "MaxRate", 15f, new ConfigDescription("Purchases (or x10 steps) per second after holding for RampTime. Each step also waits for the host to confirm the previous one.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 30f), Array.Empty<object>()));
			_buyer.RampTime = ((BaseUnityPlugin)this).Config.Bind<float>("Speed", "RampTime", 2f, new ConfigDescription("Seconds of repeating to go from StartRate to MaxRate.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			_buyer.LogSteps = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "LogSteps", false, "Write every buying step to the log.");
			_bindings = ((BaseUnityPlugin)this).Config.Bind<string>("Controls", "BindingOverrides", "", "Keybinds changed in the game's Controls menu (Buy Bait x10 row). Managed by the game menu; clear to reset.");
			new Harmony("avidkaos.howtofish.fastbuy").PatchAll(typeof(Plugin).Assembly);
			Log.LogInfo((object)"BetterShop 1.0.0 loaded");
		}

		private void Start()
		{
			_input = new ModInput(_bindings);
			_buyer.Input = _input;
			ControlsMenu.Init(_input);
		}

		private void Update()
		{
			ControlsMenu.ProcessPending();
		}
	}
	public static class Strings
	{
		public const string BulkRow = "BulkRow";

		private static bool _subscribed;

		private static readonly Dictionary<string, Dictionary<string, string>> Table = new Dictionary<string, Dictionary<string, string>> { ["BulkRow"] = new Dictionary<string, string>
		{
			["en"] = "Buy Bait ×10",
			["zh-CN"] = "购买饵料 ×10",
			["zh-TW"] = "購買釣餌 ×10",
			["fr"] = "Acheter des appâts ×10",
			["de"] = "Köder kaufen ×10",
			["it"] = "Compra esca ×10",
			["ja"] = "エサ購入 ×10",
			["ko"] = "미끼 구매 ×10",
			["pl"] = "Kup przynętę ×10",
			["pt-BR"] = "Comprar isca ×10",
			["ru"] = "Купить приманку ×10",
			["es-MX"] = "Comprar cebo ×10",
			["es-ES"] = "Comprar cebo ×10",
			["sv"] = "Köp bete ×10",
			["tr"] = "Yem Satın Al ×10",
			["uk"] = "Купівля наживки ×10"
		} };

		public static event Action LanguageChanged;

		public static string Get(string key, params object[] args)
		{
			EnsureSubscribed();
			if (!Table.TryGetValue(key, out var value))
			{
				return key;
			}
			string value2 = null;
			string text = CurrentCode();
			if (text != null && !value.TryGetValue(text, out value2))
			{
				string value3 = text.Split('-')[0];
				foreach (KeyValuePair<string, string> item in value)
				{
					if (item.Key.Split('-')[0].Equals(value3, StringComparison.OrdinalIgnoreCase))
					{
						value2 = item.Value;
						break;
					}
				}
			}
			if (value2 == null)
			{
				value2 = value["en"];
			}
			if (args.Length == 0)
			{
				return value2;
			}
			return string.Format(value2, args);
		}

		private static string CurrentCode()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Locale selectedLocale = LocalizationSettings.SelectedLocale;
				object obj;
				if (selectedLocale == null)
				{
					obj = null;
				}
				else
				{
					LocaleIdentifier identifier = selectedLocale.Identifier;
					obj = ((LocaleIdentifier)(ref identifier)).Code;
				}
				string text = (string)obj;
				if (string.IsNullOrEmpty(text))
				{
					return null;
				}
				string[] array = text.Split('-');
				return (array.Length == 2) ? (array[0].ToLowerInvariant() + "-" + array[1].ToUpperInvariant()) : text.ToLowerInvariant();
			}
			catch (Exception)
			{
				return null;
			}
		}

		private static void EnsureSubscribed()
		{
			if (_subscribed)
			{
				return;
			}
			try
			{
				LocalizationSettings.SelectedLocaleChanged += delegate
				{
					Strings.LanguageChanged?.Invoke();
				};
				_subscribed = true;
			}
			catch (Exception)
			{
			}
		}
	}
	internal static class PluginInfo
	{
		public const string Version = "1.0.0";
	}
}