using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using ItemScrollerContinued.Patches;
using Microsoft.CodeAnalysis;
using UnityEngine;
using Zorro.ControllerSupport;
using Zorro.Core;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("ItemScrollerContinued")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+820ccd2834552772e94063e7f47a29721cc3e04f")]
[assembly: AssemblyProduct("ItemScrollerContinued")]
[assembly: AssemblyTitle("ItemScrollerContinued")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace ItemScrollerContinued
{
[BepInPlugin("LeonYew.ItemScrollerContinued", "Item Scroller Continued", "1.0.0")]
[BepInIncompatibility("MasterAli2.ItemScroller")]
public sealed class Plugin : BaseUnityPlugin
{
public const string GUID = "LeonYew.ItemScrollerContinued";
public const string NAME = "Item Scroller Continued";
public const string VERSION = "1.0.0";
private Harmony? harmony;
internal static Plugin Instance { get; private set; }
internal ConfigEntry<float> ScrollThreshold { get; private set; }
internal ConfigEntry<float> MaxHoldTimeForScrollables { get; private set; }
private void Awake()
{
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Expected O, but got Unknown
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Expected O, but got Unknown
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Expected O, but got Unknown
Instance = this;
ScrollThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("Scrolling", "ScrollThreshold", 0.75f, new ConfigDescription("Minimum scroll input required to switch an item.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 10f), Array.Empty<object>()));
MaxHoldTimeForScrollables = ((BaseUnityPlugin)this).Config.Bind<float>("Scrolling", "MaxHoldTime", 0.75f, new ConfigDescription("Seconds after equipping a scrollable item before the wheel controls that item instead of switching slots.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5f), Array.Empty<object>()));
harmony = new Harmony("LeonYew.ItemScrollerContinued");
harmony.PatchAll(typeof(ScrollSwitching));
((BaseUnityPlugin)this).Logger.LogInfo((object)"Item Scroller Continued v1.0.0 loaded");
}
private void OnDestroy()
{
Harmony? obj = harmony;
if (obj != null)
{
obj.UnpatchSelf();
}
}
}
}
namespace ItemScrollerContinued.Patches
{
internal static class ScrollSwitching
{
[HarmonyPatch(typeof(CharacterItems), "DoSwitching")]
[HarmonyPrefix]
internal static void BeforeSwitching(CharacterItems __instance)
{
//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
Character character = __instance.character;
if ((Object)(object)character == (Object)null || !character.IsLocal || (Object)(object)character.input == (Object)null)
{
return;
}
float scrollInput = character.input.scrollInput;
if (float.IsNaN(scrollInput) || float.IsInfinity(scrollInput) || Mathf.Abs(scrollInput) < Plugin.Instance.ScrollThreshold.Value || (Object)(object)character.data == (Object)null || (Object)(object)character.player == (Object)null || character.player.itemSlots == null || !character.CanDoInput() || !character.data.fullyConscious || character.data.isClimbing || character.data.isRopeClimbing || (Object)(object)character.data.currentStickyItem != (Object)null || Time.time <= __instance.lastEquippedSlotTime + __instance.equippedSlotCooldown || character.input.selectSlotForwardWasPressed || character.input.selectSlotBackwardWasPressed || character.input.unselectSlotWasPressed)
{
return;
}
for (byte b = 0; b < 4; b++)
{
if (character.input.SelectSlotWasPressed((int)b))
{
return;
}
}
Item currentItem = character.data.currentItem;
if ((!((Object)(object)currentItem != (Object)null) || (!(currentItem.progress > 0f) && !(currentItem.lastFinishedCast + 0.1f > Time.time))) && (!HasScrollFunction(currentItem) || !(Time.time >= __instance.lastEquippedSlotTime + Plugin.Instance.MaxHoldTimeForScrollables.Value)))
{
byte current = (__instance.currentSelectedSlot.IsSome ? __instance.currentSelectedSlot.Value : (__instance.lastSelectedSlot.IsSome ? __instance.lastSelectedSlot.Value : byte.MaxValue));
byte? b2 = FindNextSlot(scrollInput < 0f, current, character.player);
if (b2.HasValue)
{
__instance.lastSwitched = Time.time;
__instance.timesSwitchedRecently++;
__instance.EquipSlot(Optionable<byte>.Some(b2.Value));
}
}
}
internal static bool HasScrollFunction(Item? item)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Invalid comparison between Unknown and I4
if ((Object)(object)item == (Object)null)
{
return false;
}
bool flag = (int)InputHandler.GetCurrentUsedInputScheme() == 0;
if (item.OnScrolled != null || (flag && item.OnScrolledMouseOnly != null))
{
return true;
}
if (item.itemComponents == null)
{
return false;
}
ItemComponent[] itemComponents = item.itemComponents;
for (int i = 0; i < itemComponents.Length; i++)
{
if (itemComponents[i] is RopeSpool)
{
return true;
}
}
return false;
}
internal static byte? FindNextSlot(bool forward, byte current, Player player)
{
int num = ((current < 4) ? current : (forward ? 3 : 0));
for (int i = 1; i <= 4; i++)
{
byte b = (byte)((num + (forward ? i : (-i)) + 4) % 4);
if (b != current && (b >= 3 || (player.itemSlots != null && b < player.itemSlots.Length)))
{
ItemSlot itemSlot = player.GetItemSlot(b);
if (itemSlot != null && !itemSlot.IsEmpty())
{
return b;
}
}
}
return null;
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}