using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ScrollHotbar")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ScrollHotbar")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("627dabf2-9d96-4d59-ae3a-ec205c1bc5b0")]
[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 ScrollHotbar;
[BepInPlugin("com.kurophantom.scrollhotbar", "HotbarScroll", "1.2.4")]
public class Main : BaseUnityPlugin
{
private readonly Harmony HarmonyInstance = new Harmony("com.kurophantom.scrollhotbar");
private ManualLogSource logger;
private ConfigEntry<KeyCode> keybindPreview;
private ConfigEntry<bool> invertScroll;
private int currentIndex = 0;
private float savedZoom;
private float scrollTimer = 0f;
private float scrollDelay = 0.1f;
private bool pendingEquip = false;
private float lastScrollValue = 0f;
private bool scrollJustEnded = false;
public void Awake()
{
HarmonyInstance.PatchAll();
logger = ((BaseUnityPlugin)this).Logger;
logger.LogInfo((object)"HotbarScroll mod loaded!");
keybindPreview = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Hotbar Scroll Settings", "Preview Key", (KeyCode)306, "Key used to activate hotbar preview scrolling.");
invertScroll = ((BaseUnityPlugin)this).Config.Bind<bool>("Hotbar Scroll Settings", "Invert Scroll Direction", false, "If true, scrolling up selects lower hotbar slots and vice versa.");
}
public void Update()
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)GameCamera.instance == (Object)null)
{
return;
}
float axis = Input.GetAxis("Mouse ScrollWheel");
bool key = Input.GetKey(keybindPreview.Value);
int num = ((axis > 0f) ? 1 : ((axis < 0f) ? (-1) : 0));
if (invertScroll.Value)
{
num *= -1;
}
GameCamera instance = GameCamera.instance;
if (key)
{
savedZoom = GetCameraZoom(instance);
}
scrollJustEnded = lastScrollValue != 0f && Mathf.Approximately(axis, 0f);
lastScrollValue = axis;
if (!key && scrollJustEnded)
{
float cameraZoom = GetCameraZoom(instance);
if (Mathf.Abs(cameraZoom - savedZoom) > 0.0005f)
{
SetCameraZoom(instance, savedZoom);
}
}
if (!key && num != 0)
{
if (num > 0)
{
currentIndex = (currentIndex + 1) % 9;
}
else if (num < 0)
{
currentIndex = (currentIndex + 7) % 8;
}
scrollTimer = scrollDelay;
pendingEquip = true;
logger.LogInfo((object)$"Queued slot: {currentIndex + 1}");
}
if (pendingEquip)
{
scrollTimer -= Time.deltaTime;
if (scrollTimer <= 0f)
{
Player.m_localPlayer.UseHotbarItem(currentIndex);
logger.LogInfo((object)$"Equipped slot: {currentIndex + 1}");
pendingEquip = false;
}
}
}
private float GetCameraZoom(GameCamera cam)
{
return (float)typeof(GameCamera).GetField("m_distance", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(cam);
}
private void SetCameraZoom(GameCamera cam, float value)
{
typeof(GameCamera).GetField("m_distance", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(cam, value);
}
}