using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using AutoSwitch.ASPatch;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
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("AutoSwitch")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AutoSwitch")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5c1c60c2-938d-464e-99d1-105c23f21e31")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AutoSwitch
{
[BepInPlugin("Slam.AutoSwitch", "Auto Switch", "0.1.0")]
public class AutoSwitchMain : BaseUnityPlugin
{
private const string modGUID = "Slam.AutoSwitch";
private const string modName = "Auto Switch";
private const string modVersion = "0.1.0";
private readonly Harmony harmony = new Harmony("Slam.AutoSwitch");
private static AutoSwitchMain instance;
internal ManualLogSource mls;
private void Awake()
{
if ((Object)(object)instance == (Object)null)
{
instance = this;
}
mls = Logger.CreateLogSource("Slam.AutoSwitch");
mls.LogInfo((object)"Auto Switch Mod has loaded!");
harmony.PatchAll(typeof(PlayerControllerBPatch));
harmony.PatchAll(typeof(AutoSwitchMain));
}
}
}
namespace AutoSwitch.ASPatch
{
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
[HarmonyPatch("DiscardHeldObject")]
[HarmonyPostfix]
private static void autoSwitchPatch(PlayerControllerB __instance, ref GrabbableObject[] ___ItemSlots, ref bool ___isHoldingObject)
{
MethodInfo method = typeof(PlayerControllerB).GetMethod("NextItemSlot", BindingFlags.Instance | BindingFlags.NonPublic);
MethodInfo method2 = typeof(PlayerControllerB).GetMethod("SwitchToItemSlot", BindingFlags.Instance | BindingFlags.NonPublic);
if (!(method != null) || !(method2 != null))
{
return;
}
int currentItemSlot = __instance.currentItemSlot;
for (int num = (int)method.Invoke(__instance, new object[1] { true }); num != currentItemSlot; num = (num + 1) % ___ItemSlots.Length)
{
if (___ItemSlots[num] != null)
{
method2.Invoke(__instance, new object[2] { num, null });
break;
}
}
}
}
}