using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[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("CWMouseWheel")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Allows to switch inventory slots using mouse wheel")]
[assembly: AssemblyFileVersion("1.0.21.0")]
[assembly: AssemblyInformationalVersion("1.0.21+4061617987c3d9e9f64c76ab32f079493a2c4360")]
[assembly: AssemblyProduct("CWMouseWheel")]
[assembly: AssemblyTitle("CWMouseWheel")]
[assembly: AssemblyVersion("1.0.21.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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]
[Microsoft.CodeAnalysis.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;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 CWMouseWheel
{
[ContentWarningPlugin("CWMouseWheel", "1.0.21", true)]
[BepInPlugin("CWMouseWheel", "CWMouseWheel", "1.0.21")]
public class Plugin : BaseUnityPlugin
{
public static PluginConfig? Config;
private void Awake()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Expected O, but got Unknown
Harmony harmony = new Harmony("CWMouseWheel");
Config = new PluginConfig(((BaseUnityPlugin)this).Config);
PluginConfig? config = Config;
config.OnPluginToggled = (Action<bool>)Delegate.Combine(config.OnPluginToggled, (Action<bool>)delegate(bool enabled)
{
if (enabled)
{
harmony.PatchAll();
}
else
{
harmony.UnpatchSelf();
}
});
Config.Init();
}
}
public class PluginConfig
{
private static readonly KeyboardShortcut _defaultZoomKey = new KeyboardShortcut((KeyCode)122, Array.Empty<KeyCode>());
private const string SECTION = "Input";
private readonly ConfigEntry<KeyboardShortcut> _zoomKey = Bind<KeyboardShortcut>(config, "Camera zoom key", _defaultZoomKey);
private readonly ConfigEntry<bool> _enabled = Bind(config, "Enabled", _default: true);
private readonly ConfigEntry<bool> _invertScroll = Bind(config, "Invert scroll", _default: true);
private readonly ConfigEntry<bool> _skipEmptySlots = Bind(config, "Skip empty slots", _default: true);
private readonly ConfigEntry<bool> _skipArtifactSlot = Bind(config, "Skip artifact slot", _default: false);
public Action<bool> OnPluginToggled = delegate
{
};
public bool IsZoomKeyPressed
{
get
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
KeyboardShortcut value = _zoomKey.Value;
return ((KeyboardShortcut)(ref value)).IsPressed();
}
}
public bool InvertScroll => _invertScroll.Value;
public bool SkipEmptySlots => _skipEmptySlots.Value;
public bool SkipArtifactSlot => _skipArtifactSlot.Value;
public string? ZoomKeyName
{
get
{
//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)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
ConfigEntry<KeyboardShortcut> zoomKey = _zoomKey;
if (zoomKey == null)
{
return null;
}
KeyboardShortcut value = zoomKey.Value;
KeyCode mainKey = ((KeyboardShortcut)(ref value)).MainKey;
return ((object)(KeyCode)(ref mainKey)).ToString();
}
}
public PluginConfig(ConfigFile config)
{
}//IL_0007: Unknown result type (might be due to invalid IL or missing references)
public void Init()
{
_enabled.SettingChanged += delegate
{
OnPluginToggled(_enabled.Value);
};
OnPluginToggled(_enabled.Value);
}
private static ConfigEntry<T> Bind<T>(ConfigFile config, string name, T _default)
{
return config.Bind<T>("Input", name, _default, (ConfigDescription)null);
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "CWMouseWheel";
public const string PLUGIN_NAME = "CWMouseWheel";
public const string PLUGIN_VERSION = "1.0.21";
}
}
namespace CWMouseWheel.Patches
{
[HarmonyPatch(typeof(PlayerItems), "Update")]
public class ChangeSlot
{
[HarmonyPrefix]
public static void Prefix(Player ___player)
{
PlayerInventory val = default(PlayerInventory);
if (!___player.data.isLocal || !___player.data.physicsAreReady || ___player.HasLockedInput() || !___player.TryGetInventory(ref val))
{
return;
}
PluginConfig config = Plugin.Config;
if (config.IsZoomKeyPressed)
{
return;
}
int num = ___player.data.selectedItemSlot;
int num2 = Math.Sign(Input.GetAxis("Mouse ScrollWheel")) * ((!config.InvertScroll) ? 1 : (-1));
InventorySlot[] slots = val.slots;
if (num2 != 0 && (!config.SkipEmptySlots || !slots.All((InventorySlot slot) => (Object)(object)slot.ItemInSlot.item == (Object)null)))
{
int num3 = slots.Length;
if (config.SkipArtifactSlot)
{
num3--;
}
ItemDescriptor val2 = default(ItemDescriptor);
do
{
num = (num + num2 + num3) % num3;
}
while (config.SkipEmptySlots && !val.TryGetItemInSlot(num, ref val2));
___player.data.selectedItemSlot = num;
}
}
}
[HarmonyPatch(typeof(ItemKeyTooltip), "GetString")]
public class ZoomKeyInfo
{
private const string SCROLL_PREFIX = "[Scroll]";
private static string ZoomPrefix => "[" + Plugin.Config.ZoomKeyName + " + Scroll]";
private static void Postfix(ref string __result, ref string ___m_key)
{
if (__result.StartsWith("[Scroll]"))
{
string zoomPrefix = ZoomPrefix;
string text = ___m_key;
int length = "[Scroll]".Length;
__result = zoomPrefix + text.Substring(length, text.Length - length);
}
}
}
}