Decompiled source of ItemDropCycler v1.1.0

BepInEx/plugins/ItemDropCycler.dll

Decompiled 7 months ago
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.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using ItemDropCycler.Patches;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("ItemDropCycler")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A template for Lethal Company")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ItemDropCycler")]
[assembly: AssemblyTitle("ItemDropCycler")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace ItemDropCycler
{
	[BepInPlugin("LCMOD.ItemDropCycler", "ItemDropCycler", "1.1.0")]
	public class ItemDropCyclerBase : BaseUnityPlugin
	{
		public const string MODGUID = "LCMOD.ItemDropCycler";

		public const string MODNAME = "ItemDropCycler";

		public const string MODVERSION = "1.1.0";

		private readonly Harmony harmony = new Harmony("LCMOD.ItemDropCycler");

		public static ItemDropCyclerBase Instance;

		public static ManualLogSource logger;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			logger = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Mod LCMOD.ItemDropCycler is loaded!");
			harmony.PatchAll(typeof(ItemDropCyclerBase));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
		}
	}
}
namespace ItemDropCycler.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		[HarmonyPatch("DiscardHeldObject")]
		[HarmonyPostfix]
		private static void CycleSlotsOnDrop()
		{
			ItemDropCyclerBase.logger.LogInfo((object)"Item Dropped");
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			MethodInfo method = typeof(PlayerControllerB).GetMethod("NextItemSlot", BindingFlags.Instance | BindingFlags.NonPublic);
			MethodInfo method2 = typeof(PlayerControllerB).GetMethod("SwitchToItemSlot", BindingFlags.Instance | BindingFlags.NonPublic);
			MethodInfo method3 = typeof(PlayerControllerB).GetMethod("SwitchItemSlotsServerRpc", BindingFlags.Instance | BindingFlags.NonPublic);
			object[] parameters = new object[1] { true };
			object obj = method.Invoke(localPlayerController, parameters);
			object[] parameters2 = new object[2] { obj, null };
			ItemDropCyclerBase.logger.LogInfo((object)$"Got slot at {obj} \tOld: {localPlayerController.currentItemSlot}");
			method2.Invoke(localPlayerController, parameters2);
			method3.Invoke(localPlayerController, parameters);
			ItemDropCyclerBase.logger.LogInfo((object)$"Set slot at {obj}");
		}
	}
}