using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BaseSlots;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using NumberItemSlots.Patches;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("NumberItemSlots")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NumberItemSlots")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ace62bef-435c-4188-9167-ad3f5a80c618")]
[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 BaseSlots
{
public class Keybinds : LcInputActions
{
[InputAction(/*Could not decode attribute arguments.*/)]
public InputAction SlotOneKey { get; set; }
[InputAction(/*Could not decode attribute arguments.*/)]
public InputAction SlotTwoKey { get; set; }
[InputAction(/*Could not decode attribute arguments.*/)]
public InputAction SlotThreeKey { get; set; }
[InputAction(/*Could not decode attribute arguments.*/)]
public InputAction SlotFourKey { get; set; }
}
[BepInPlugin("phatisfat.NumberItemSlots", "NumberItemSlots", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class ItemSlotBase : BaseUnityPlugin
{
private const string modGUID = "phatisfat.NumberItemSlots";
private const string modName = "NumberItemSlots";
private const string modVersion = "1.0.0";
internal static Keybinds InputActionsInstance = new Keybinds();
private readonly Harmony harmony = new Harmony("phatisfat.NumberItemSlots");
private static ItemSlotBase Instance;
internal static ManualLogSource Log;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
Log = Logger.CreateLogSource("phatisfat.NumberItemSlots");
Log.LogInfo((object)"NumberItemSlots has loaded. VERSION: 1.0.0");
harmony.PatchAll(typeof(ItemSlotBase));
harmony.PatchAll(typeof(PlayerControllerBPatch));
}
}
}
namespace NumberItemSlots.Patches
{
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
private GrabbableObject currentlyGrabbingObject;
private static PlayerControllerB play;
private static GrabbableObject fillSlotWithItem;
internal static ManualLogSource mls;
[HarmonyPatch("Update")]
[HarmonyPrefix]
private static void onSlotChangePress(PlayerControllerB __instance)
{
play = __instance;
if (ItemSlotBase.InputActionsInstance.SlotOneKey.triggered && !__instance.isPlayerDead && !__instance.isTypingChat && !__instance.inTerminalMenu && (Object)(object)__instance == (Object)(object)GameNetworkManager.Instance.localPlayerController)
{
((Component)HUDManager.Instance.itemSlotIconFrames[0]).GetComponent<Animator>().SetBool("selectedSlot", true);
__instance.currentItemSlot = 0;
ItemSlotBase.Log.LogInfo((object)"Changing to slot ONE");
if (((NetworkBehaviour)play).IsOwner)
{
for (int i = 0; i < HUDManager.Instance.itemSlotIconFrames.Length; i++)
{
((Component)HUDManager.Instance.itemSlotIconFrames[i]).GetComponent<Animator>().SetBool("selectedSlot", false);
}
((Component)HUDManager.Instance.itemSlotIconFrames[0]).GetComponent<Animator>().SetBool("selectedSlot", true);
}
if ((Object)(object)fillSlotWithItem != (Object)null)
{
play.ItemSlots[0] = fillSlotWithItem;
if (((NetworkBehaviour)play).IsOwner)
{
HUDManager.Instance.itemSlotIcons[0].sprite = fillSlotWithItem.itemProperties.itemIcon;
((Behaviour)HUDManager.Instance.itemSlotIcons[play.currentItemSlot]).enabled = true;
}
}
if ((Object)(object)play.currentlyHeldObjectServer != (Object)null)
{
play.currentlyHeldObjectServer.playerHeldBy = play;
if (((NetworkBehaviour)play).IsOwner)
{
SetSpecialGrabAnimationBool(setTrue: false, play.currentlyHeldObjectServer);
}
play.currentlyHeldObjectServer.PocketItem();
if ((Object)(object)play.ItemSlots[0] != (Object)null && !string.IsNullOrEmpty(play.ItemSlots[0].itemProperties.pocketAnim))
{
play.playerBodyAnimator.SetTrigger(play.ItemSlots[0].itemProperties.pocketAnim);
}
}
if ((Object)(object)play.ItemSlots[0] != (Object)null)
{
play.ItemSlots[0].playerHeldBy = play;
play.ItemSlots[0].EquipItem();
if (((NetworkBehaviour)play).IsOwner)
{
SetSpecialGrabAnimationBool(setTrue: true, play.ItemSlots[0]);
}
if ((Object)(object)play.currentlyHeldObjectServer != (Object)null)
{
if (play.ItemSlots[0].itemProperties.twoHandedAnimation || play.currentlyHeldObjectServer.itemProperties.twoHandedAnimation)
{
play.playerBodyAnimator.ResetTrigger("SwitchHoldAnimationTwoHanded");
play.playerBodyAnimator.SetTrigger("SwitchHoldAnimationTwoHanded");
}
play.playerBodyAnimator.ResetTrigger("SwitchHoldAnimation");
play.playerBodyAnimator.SetTrigger("SwitchHoldAnimation");
}
play.twoHandedAnimation = play.ItemSlots[0].itemProperties.twoHandedAnimation;
play.twoHanded = play.ItemSlots[0].itemProperties.twoHanded;
play.playerBodyAnimator.SetBool("GrabValidated", true);
play.playerBodyAnimator.SetBool("cancelHolding", false);
play.isHoldingObject = true;
play.currentlyHeldObjectServer = play.ItemSlots[0];
}
else
{
if (!((NetworkBehaviour)play).IsOwner && (Object)(object)play.heldObjectServerCopy != (Object)null)
{
play.heldObjectServerCopy.SetActive(false);
}
if (((NetworkBehaviour)play).IsOwner)
{
HUDManager.Instance.ClearControlTips();
}
play.currentlyHeldObjectServer = null;
play.currentlyHeldObject = null;
play.isHoldingObject = false;
play.twoHanded = false;
play.playerBodyAnimator.SetBool("cancelHolding", true);
}
if (!((NetworkBehaviour)play).IsOwner)
{
return;
}
if (play.twoHanded)
{
HUDManager.Instance.PingHUDElement(HUDManager.Instance.Inventory, 0.1f, 0.13f, 0.13f);
((Behaviour)HUDManager.Instance.holdingTwoHandedItem).enabled = true;
}
else
{
HUDManager.Instance.PingHUDElement(HUDManager.Instance.Inventory, 1.5f, 1f, 0.13f);
((Behaviour)HUDManager.Instance.holdingTwoHandedItem).enabled = false;
}
}
if (ItemSlotBase.InputActionsInstance.SlotTwoKey.triggered && !__instance.isPlayerDead && !__instance.isTypingChat && !__instance.inTerminalMenu && (Object)(object)__instance == (Object)(object)GameNetworkManager.Instance.localPlayerController)
{
((Component)HUDManager.Instance.itemSlotIconFrames[1]).GetComponent<Animator>().SetBool("selectedSlot", true);
__instance.currentItemSlot = 1;
ItemSlotBase.Log.LogInfo((object)"Changing to slot TWO");
if (((NetworkBehaviour)play).IsOwner)
{
for (int j = 0; j < HUDManager.Instance.itemSlotIconFrames.Length; j++)
{
((Component)HUDManager.Instance.itemSlotIconFrames[j]).GetComponent<Animator>().SetBool("selectedSlot", false);
}
((Component)HUDManager.Instance.itemSlotIconFrames[1]).GetComponent<Animator>().SetBool("selectedSlot", true);
}
if ((Object)(object)fillSlotWithItem != (Object)null)
{
play.ItemSlots[1] = fillSlotWithItem;
if (((NetworkBehaviour)play).IsOwner)
{
HUDManager.Instance.itemSlotIcons[1].sprite = fillSlotWithItem.itemProperties.itemIcon;
((Behaviour)HUDManager.Instance.itemSlotIcons[play.currentItemSlot]).enabled = true;
}
}
if ((Object)(object)play.currentlyHeldObjectServer != (Object)null)
{
play.currentlyHeldObjectServer.playerHeldBy = play;
if (((NetworkBehaviour)play).IsOwner)
{
SetSpecialGrabAnimationBool(setTrue: false, play.currentlyHeldObjectServer);
}
play.currentlyHeldObjectServer.PocketItem();
if ((Object)(object)play.ItemSlots[1] != (Object)null && !string.IsNullOrEmpty(play.ItemSlots[1].itemProperties.pocketAnim))
{
play.playerBodyAnimator.SetTrigger(play.ItemSlots[1].itemProperties.pocketAnim);
}
}
if ((Object)(object)play.ItemSlots[1] != (Object)null)
{
play.ItemSlots[1].playerHeldBy = play;
play.ItemSlots[1].EquipItem();
if (((NetworkBehaviour)play).IsOwner)
{
SetSpecialGrabAnimationBool(setTrue: true, play.ItemSlots[1]);
}
if ((Object)(object)play.currentlyHeldObjectServer != (Object)null)
{
if (play.ItemSlots[1].itemProperties.twoHandedAnimation || play.currentlyHeldObjectServer.itemProperties.twoHandedAnimation)
{
play.playerBodyAnimator.ResetTrigger("SwitchHoldAnimationTwoHanded");
play.playerBodyAnimator.SetTrigger("SwitchHoldAnimationTwoHanded");
}
play.playerBodyAnimator.ResetTrigger("SwitchHoldAnimation");
play.playerBodyAnimator.SetTrigger("SwitchHoldAnimation");
}
play.twoHandedAnimation = play.ItemSlots[1].itemProperties.twoHandedAnimation;
play.twoHanded = play.ItemSlots[1].itemProperties.twoHanded;
play.playerBodyAnimator.SetBool("GrabValidated", true);
play.playerBodyAnimator.SetBool("cancelHolding", false);
play.isHoldingObject = true;
play.currentlyHeldObjectServer = play.ItemSlots[1];
}
else
{
if (!((NetworkBehaviour)play).IsOwner && (Object)(object)play.heldObjectServerCopy != (Object)null)
{
play.heldObjectServerCopy.SetActive(false);
}
if (((NetworkBehaviour)play).IsOwner)
{
HUDManager.Instance.ClearControlTips();
}
play.currentlyHeldObjectServer = null;
play.currentlyHeldObject = null;
play.isHoldingObject = false;
play.twoHanded = false;
play.playerBodyAnimator.SetBool("cancelHolding", true);
}
if (!((NetworkBehaviour)play).IsOwner)
{
return;
}
if (play.twoHanded)
{
HUDManager.Instance.PingHUDElement(HUDManager.Instance.Inventory, 0.1f, 0.13f, 0.13f);
((Behaviour)HUDManager.Instance.holdingTwoHandedItem).enabled = true;
}
else
{
HUDManager.Instance.PingHUDElement(HUDManager.Instance.Inventory, 1.5f, 1f, 0.13f);
((Behaviour)HUDManager.Instance.holdingTwoHandedItem).enabled = false;
}
}
if (ItemSlotBase.InputActionsInstance.SlotThreeKey.triggered && !__instance.isPlayerDead && !__instance.isTypingChat && !__instance.inTerminalMenu && (Object)(object)__instance == (Object)(object)GameNetworkManager.Instance.localPlayerController)
{
((Component)HUDManager.Instance.itemSlotIconFrames[2]).GetComponent<Animator>().SetBool("selectedSlot", true);
__instance.currentItemSlot = 2;
ItemSlotBase.Log.LogInfo((object)"Changing to slot THREE");
if (((NetworkBehaviour)play).IsOwner)
{
for (int k = 0; k < HUDManager.Instance.itemSlotIconFrames.Length; k++)
{
((Component)HUDManager.Instance.itemSlotIconFrames[k]).GetComponent<Animator>().SetBool("selectedSlot", false);
}
((Component)HUDManager.Instance.itemSlotIconFrames[2]).GetComponent<Animator>().SetBool("selectedSlot", true);
}
if ((Object)(object)fillSlotWithItem != (Object)null)
{
play.ItemSlots[2] = fillSlotWithItem;
if (((NetworkBehaviour)play).IsOwner)
{
HUDManager.Instance.itemSlotIcons[2].sprite = fillSlotWithItem.itemProperties.itemIcon;
((Behaviour)HUDManager.Instance.itemSlotIcons[play.currentItemSlot]).enabled = true;
}
}
if ((Object)(object)play.currentlyHeldObjectServer != (Object)null)
{
play.currentlyHeldObjectServer.playerHeldBy = play;
if (((NetworkBehaviour)play).IsOwner)
{
SetSpecialGrabAnimationBool(setTrue: false, play.currentlyHeldObjectServer);
}
play.currentlyHeldObjectServer.PocketItem();
if ((Object)(object)play.ItemSlots[2] != (Object)null && !string.IsNullOrEmpty(play.ItemSlots[2].itemProperties.pocketAnim))
{
play.playerBodyAnimator.SetTrigger(play.ItemSlots[2].itemProperties.pocketAnim);
}
}
if ((Object)(object)play.ItemSlots[2] != (Object)null)
{
play.ItemSlots[2].playerHeldBy = play;
play.ItemSlots[2].EquipItem();
if (((NetworkBehaviour)play).IsOwner)
{
SetSpecialGrabAnimationBool(setTrue: true, play.ItemSlots[2]);
}
if ((Object)(object)play.currentlyHeldObjectServer != (Object)null)
{
if (play.ItemSlots[2].itemProperties.twoHandedAnimation || play.currentlyHeldObjectServer.itemProperties.twoHandedAnimation)
{
play.playerBodyAnimator.ResetTrigger("SwitchHoldAnimationTwoHanded");
play.playerBodyAnimator.SetTrigger("SwitchHoldAnimationTwoHanded");
}
play.playerBodyAnimator.ResetTrigger("SwitchHoldAnimation");
play.playerBodyAnimator.SetTrigger("SwitchHoldAnimation");
}
play.twoHandedAnimation = play.ItemSlots[2].itemProperties.twoHandedAnimation;
play.twoHanded = play.ItemSlots[2].itemProperties.twoHanded;
play.playerBodyAnimator.SetBool("GrabValidated", true);
play.playerBodyAnimator.SetBool("cancelHolding", false);
play.isHoldingObject = true;
play.currentlyHeldObjectServer = play.ItemSlots[2];
}
else
{
if (!((NetworkBehaviour)play).IsOwner && (Object)(object)play.heldObjectServerCopy != (Object)null)
{
play.heldObjectServerCopy.SetActive(false);
}
if (((NetworkBehaviour)play).IsOwner)
{
HUDManager.Instance.ClearControlTips();
}
play.currentlyHeldObjectServer = null;
play.currentlyHeldObject = null;
play.isHoldingObject = false;
play.twoHanded = false;
play.playerBodyAnimator.SetBool("cancelHolding", true);
}
if (!((NetworkBehaviour)play).IsOwner)
{
return;
}
if (play.twoHanded)
{
HUDManager.Instance.PingHUDElement(HUDManager.Instance.Inventory, 0.1f, 0.13f, 0.13f);
((Behaviour)HUDManager.Instance.holdingTwoHandedItem).enabled = true;
}
else
{
HUDManager.Instance.PingHUDElement(HUDManager.Instance.Inventory, 1.5f, 1f, 0.13f);
((Behaviour)HUDManager.Instance.holdingTwoHandedItem).enabled = false;
}
}
if (!ItemSlotBase.InputActionsInstance.SlotFourKey.triggered || __instance.isPlayerDead || __instance.isTypingChat || __instance.inTerminalMenu || !((Object)(object)__instance == (Object)(object)GameNetworkManager.Instance.localPlayerController))
{
return;
}
((Component)HUDManager.Instance.itemSlotIconFrames[3]).GetComponent<Animator>().SetBool("selectedSlot", true);
__instance.currentItemSlot = 3;
ItemSlotBase.Log.LogInfo((object)"Changing to slot FOUR");
if (((NetworkBehaviour)play).IsOwner)
{
for (int l = 0; l < HUDManager.Instance.itemSlotIconFrames.Length; l++)
{
((Component)HUDManager.Instance.itemSlotIconFrames[l]).GetComponent<Animator>().SetBool("selectedSlot", false);
}
((Component)HUDManager.Instance.itemSlotIconFrames[3]).GetComponent<Animator>().SetBool("selectedSlot", true);
}
if ((Object)(object)fillSlotWithItem != (Object)null)
{
play.ItemSlots[3] = fillSlotWithItem;
if (((NetworkBehaviour)play).IsOwner)
{
HUDManager.Instance.itemSlotIcons[3].sprite = fillSlotWithItem.itemProperties.itemIcon;
((Behaviour)HUDManager.Instance.itemSlotIcons[play.currentItemSlot]).enabled = true;
}
}
if ((Object)(object)play.currentlyHeldObjectServer != (Object)null)
{
play.currentlyHeldObjectServer.playerHeldBy = play;
if (((NetworkBehaviour)play).IsOwner)
{
SetSpecialGrabAnimationBool(setTrue: false, play.currentlyHeldObjectServer);
}
play.currentlyHeldObjectServer.PocketItem();
if ((Object)(object)play.ItemSlots[3] != (Object)null && !string.IsNullOrEmpty(play.ItemSlots[3].itemProperties.pocketAnim))
{
play.playerBodyAnimator.SetTrigger(play.ItemSlots[3].itemProperties.pocketAnim);
}
}
if ((Object)(object)play.ItemSlots[3] != (Object)null)
{
play.ItemSlots[3].playerHeldBy = play;
play.ItemSlots[3].EquipItem();
if (((NetworkBehaviour)play).IsOwner)
{
SetSpecialGrabAnimationBool(setTrue: true, play.ItemSlots[3]);
}
if ((Object)(object)play.currentlyHeldObjectServer != (Object)null)
{
if (play.ItemSlots[3].itemProperties.twoHandedAnimation || play.currentlyHeldObjectServer.itemProperties.twoHandedAnimation)
{
play.playerBodyAnimator.ResetTrigger("SwitchHoldAnimationTwoHanded");
play.playerBodyAnimator.SetTrigger("SwitchHoldAnimationTwoHanded");
}
play.playerBodyAnimator.ResetTrigger("SwitchHoldAnimation");
play.playerBodyAnimator.SetTrigger("SwitchHoldAnimation");
}
play.twoHandedAnimation = play.ItemSlots[3].itemProperties.twoHandedAnimation;
play.twoHanded = play.ItemSlots[3].itemProperties.twoHanded;
play.playerBodyAnimator.SetBool("GrabValidated", true);
play.playerBodyAnimator.SetBool("cancelHolding", false);
play.isHoldingObject = true;
play.currentlyHeldObjectServer = play.ItemSlots[3];
}
else
{
if (!((NetworkBehaviour)play).IsOwner && (Object)(object)play.heldObjectServerCopy != (Object)null)
{
play.heldObjectServerCopy.SetActive(false);
}
if (((NetworkBehaviour)play).IsOwner)
{
HUDManager.Instance.ClearControlTips();
}
play.currentlyHeldObjectServer = null;
play.currentlyHeldObject = null;
play.isHoldingObject = false;
play.twoHanded = false;
play.playerBodyAnimator.SetBool("cancelHolding", true);
}
if (((NetworkBehaviour)play).IsOwner)
{
if (play.twoHanded)
{
HUDManager.Instance.PingHUDElement(HUDManager.Instance.Inventory, 0.1f, 0.13f, 0.13f);
((Behaviour)HUDManager.Instance.holdingTwoHandedItem).enabled = true;
}
else
{
HUDManager.Instance.PingHUDElement(HUDManager.Instance.Inventory, 1.5f, 1f, 0.13f);
((Behaviour)HUDManager.Instance.holdingTwoHandedItem).enabled = false;
}
}
}
private static void SetSpecialGrabAnimationBool(bool setTrue, GrabbableObject currentItem = null)
{
if ((Object)(object)currentItem == (Object)null)
{
currentItem = currentItem;
}
if (!((NetworkBehaviour)play).IsOwner)
{
return;
}
play.playerBodyAnimator.SetBool("Grab", setTrue);
if (string.IsNullOrEmpty(currentItem.itemProperties.grabAnim))
{
return;
}
try
{
play.playerBodyAnimator.SetBool(currentItem.itemProperties.grabAnim, setTrue);
}
catch (Exception)
{
Debug.LogError((object)("An item tried to set an animator bool which does not exist: " + currentItem.itemProperties.grabAnim));
}
}
}
}