using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using HotbarPlus.Compatibility;
using HotbarPlus.Config;
using HotbarPlus.Input;
using HotbarPlus.Networking;
using HotbarPlus.Patches;
using LethalCompanyInputUtils.Api;
using ReservedItemSlotCore;
using ReservedItemSlotCore.Config;
using ReservedItemSlotCore.Data;
using TooManyEmotes;
using TooManyEmotes.Patches;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("HotbarPlus")]
[assembly: AssemblyDescription("Mod made by flipf17.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HotbarPlus")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("fab060f0-b006-42ea-ba6f-473f4850c587")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HotbarPlus
{
[HarmonyPatch]
internal static class SaveManager
{
[HarmonyPatch(typeof(StartOfRound), "ResetShip")]
[HarmonyPostfix]
private static void OnResetShip()
{
if (SyncManager.purchasedHotbarSlots > 0)
{
SyncManager.purchasedHotbarSlots = 0;
SyncManager.OnUpdateHotbarSize();
}
if (NetworkManager.Singleton.IsServer && SyncManager.purchasableHotbarSlots > 0)
{
ResetGameValues();
}
}
[HarmonyPatch(typeof(GameNetworkManager), "SaveGameValues")]
[HarmonyPostfix]
private static void OnSaveGameValues()
{
if (NetworkManager.Singleton.IsHost && StartOfRound.Instance.inShipPhase)
{
SaveGameValues();
}
}
internal static void SaveGameValues()
{
if (NetworkManager.Singleton.IsServer)
{
if (SyncManager.purchasableHotbarSlots > 0)
{
Plugin.LogWarning("Saving " + SyncManager.purchasedHotbarSlots + " purchased hotbar slots.");
}
ES3.Save<short>("HotbarPlus.PurchasedHotbarSlots", SyncManager.purchasedHotbarSlots, GameNetworkManager.Instance.currentSaveFileName);
}
}
internal static void LoadGameValues()
{
if (NetworkManager.Singleton.IsServer)
{
short num = ES3.Load<short>("HotbarPlus.PurchasedHotbarSlots", GameNetworkManager.Instance.currentSaveFileName, (short)0);
SyncManager.purchasedHotbarSlots = (short)Mathf.Clamp((int)num, 0, (int)(short)Mathf.Max((int)SyncManager.purchasableHotbarSlots, 0));
if (SyncManager.purchasableHotbarSlots > 0)
{
Plugin.LogWarning("Loaded " + SyncManager.purchasedHotbarSlots + " purchased hotbar slots.");
}
}
}
internal static void ResetGameValues()
{
if (NetworkManager.Singleton.IsServer)
{
if (SyncManager.purchasableHotbarSlots > 0)
{
Plugin.LogWarning("Resetting game values.");
}
ES3.DeleteKey("HotbarPlus.PurchasedHotbarSlots", GameNetworkManager.Instance.currentSaveFileName);
}
}
}
[BepInPlugin("FlipMods.HotbarPlus", "HotbarPlus", "1.8.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
public static Plugin instance;
private Harmony _harmony;
private static ManualLogSource logger;
internal static GameObject energyBarPrefab;
internal static GameObject lightningIndicatorPrefab;
private void Awake()
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Expected O, but got Unknown
instance = this;
CreateCustomLogger();
ConfigSettings.BindConfigSettings();
Keybinds.InitKeybinds();
LoadUIAssets();
_harmony = new Harmony("HotbarPlus");
PatchAll();
Log("HotbarPlus loaded");
}
private void LoadUIAssets()
{
try
{
string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)instance).Info.Location), "Assets/hotbarplus_assets");
AssetBundle val = AssetBundle.LoadFromFile(text);
energyBarPrefab = val.LoadAsset<GameObject>("energy_bar");
lightningIndicatorPrefab = val.LoadAsset<GameObject>("lightning_indicator");
}
catch
{
LogError("Failed to load UI assets from Asset Bundle.");
}
}
private void PatchAll()
{
IEnumerable<Type> enumerable;
try
{
enumerable = Assembly.GetExecutingAssembly().GetTypes();
}
catch (ReflectionTypeLoadException ex)
{
enumerable = ex.Types.Where((Type t) => t != null);
}
foreach (Type item in enumerable)
{
_harmony.PatchAll(item);
}
}
private void CreateCustomLogger()
{
try
{
logger = Logger.CreateLogSource(string.Format("{0}-{1}", "HotbarPlus", "1.8.0"));
}
catch
{
logger = ((BaseUnityPlugin)this).Logger;
}
}
public static void Log(string message)
{
logger.LogInfo((object)message);
}
public static void LogError(string message)
{
logger.LogError((object)message);
}
public static void LogWarning(string message)
{
logger.LogWarning((object)message);
}
public static bool IsModLoaded(string guid)
{
return Chainloader.PluginInfos.ContainsKey(guid);
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "FlipMods.HotbarPlus";
public const string PLUGIN_NAME = "HotbarPlus";
public const string PLUGIN_VERSION = "1.8.0";
}
}
namespace HotbarPlus.Networking
{
[HarmonyPatch]
public class SyncManager
{
public static short hotbarSize;
public static short purchasableHotbarSlots;
public static short purchasableHotbarSlotsPrice;
public static short purchasableHotbarSlotsPriceIncrease;
public static short purchasedHotbarSlots;
public static bool isSynced;
private static PlayerControllerB localPlayerController => StartOfRound.Instance?.localPlayerController;
public static short currentHotbarSize => (short)(hotbarSize + purchasedHotbarSlots);
[HarmonyPatch(typeof(StartOfRound), "Awake")]
[HarmonyPostfix]
private static void ResetValues()
{
isSynced = false;
hotbarSize = (short)(int)((ConfigEntryBase)ConfigSettings.hotbarSizeConfig).DefaultValue;
purchasableHotbarSlots = (short)(int)((ConfigEntryBase)ConfigSettings.purchasableHotbarSlotsConfig).DefaultValue;
purchasableHotbarSlotsPrice = (short)(int)((ConfigEntryBase)ConfigSettings.purchasableHotbarSlotsPriceConfig).DefaultValue;
purchasableHotbarSlotsPriceIncrease = (short)(int)((ConfigEntryBase)ConfigSettings.purchasableHotbarSlotsPriceIncreaseConfig).DefaultValue;
purchasedHotbarSlots = 0;
}
[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
[HarmonyPostfix]
private static void Init()
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Expected O, but got Unknown
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Expected O, but got Unknown
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Expected O, but got Unknown
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Expected O, but got Unknown
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Expected O, but got Unknown
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_0154: Expected O, but got Unknown
isSynced = false;
if (NetworkManager.Singleton.IsServer)
{
NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("HotbarPlus.OnRequestSyncServerRpc", new HandleNamedMessageDelegate(OnRequestSyncServerRpc));
NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("HotbarPlus.OnPurchaseHotbarSlotServerRpc", new HandleNamedMessageDelegate(OnPurchaseHotbarSlotServerRpc));
NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("HotbarPlus.RequestSyncHeldObjectsServerRpc", new HandleNamedMessageDelegate(RequestSyncHeldObjectsServerRpc));
hotbarSize = (short)Mathf.Max(ConfigSettings.hotbarSizeConfig.Value, 0);
purchasableHotbarSlots = (short)Mathf.Max(ConfigSettings.purchasableHotbarSlotsConfig.Value, 0);
purchasableHotbarSlotsPrice = (short)Mathf.Max(ConfigSettings.purchasableHotbarSlotsPriceConfig.Value, 1);
purchasableHotbarSlotsPriceIncrease = (short)Mathf.Max(ConfigSettings.purchasableHotbarSlotsPriceIncreaseConfig.Value, 0);
SaveManager.LoadGameValues();
OnSyncedWithServer();
}
else if (NetworkManager.Singleton.IsClient)
{
NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("HotbarPlus.OnRequestSyncClientRpc", new HandleNamedMessageDelegate(OnRequestSyncClientRpc));
NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("HotbarPlus.OnPurchaseHotbarSlotClientRpc", new HandleNamedMessageDelegate(OnPurchaseHotbarSlotClientRpc));
NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("HotbarPlus.RequestSyncHeldObjectsClientRpc", new HandleNamedMessageDelegate(RequestSyncHeldObjectsClientRpc));
RequestSyncWithServer();
}
}
private static void RequestSyncWithServer()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
Plugin.Log("Requesting sync with server.");
NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("HotbarPlus.OnRequestSyncServerRpc", 0uL, new FastBufferWriter(0, (Allocator)2, -1), (NetworkDelivery)3);
}
private static void OnRequestSyncServerRpc(ulong clientId, FastBufferReader reader)
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
if (NetworkManager.Singleton.IsServer)
{
Plugin.Log("Received request for sync from Client: " + clientId);
FastBufferWriter val = default(FastBufferWriter);
((FastBufferWriter)(ref val))..ctor(10, (Allocator)2, -1);
((FastBufferWriter)(ref val)).WriteValue<short>(ref hotbarSize, default(ForPrimitives));
((FastBufferWriter)(ref val)).WriteValue<short>(ref purchasableHotbarSlots, default(ForPrimitives));
((FastBufferWriter)(ref val)).WriteValue<short>(ref purchasableHotbarSlotsPrice, default(ForPrimitives));
((FastBufferWriter)(ref val)).WriteValue<short>(ref purchasableHotbarSlotsPriceIncrease, default(ForPrimitives));
((FastBufferWriter)(ref val)).WriteValue<short>(ref purchasedHotbarSlots, default(ForPrimitives));
NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("HotbarPlus.OnRequestSyncClientRpc", clientId, val, (NetworkDelivery)3);
}
}
private static void OnRequestSyncClientRpc(ulong clientId, FastBufferReader reader)
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
if (NetworkManager.Singleton.IsClient && !NetworkManager.Singleton.IsServer)
{
((FastBufferReader)(ref reader)).ReadValue<short>(ref hotbarSize, default(ForPrimitives));
((FastBufferReader)(ref reader)).ReadValue<short>(ref purchasableHotbarSlots, default(ForPrimitives));
((FastBufferReader)(ref reader)).ReadValue<short>(ref purchasableHotbarSlotsPrice, default(ForPrimitives));
((FastBufferReader)(ref reader)).ReadValue<short>(ref purchasableHotbarSlotsPriceIncrease, default(ForPrimitives));
((FastBufferReader)(ref reader)).ReadValue<short>(ref purchasedHotbarSlots, default(ForPrimitives));
Plugin.Log("Received sync from Server. Hotbar size: " + hotbarSize + " PurchasableHotbarSlots: " + purchasableHotbarSlots + " HotbarSlotsPrice: " + purchasableHotbarSlotsPrice + " HotbarSlotsPriceIncrease: " + purchasableHotbarSlotsPriceIncrease + " CurrentPurchasedHotbarSlots: " + purchasedHotbarSlots);
OnSyncedWithServer();
}
}
private static void OnSyncedWithServer()
{
isSynced = true;
PlayerPatcher.ResizeInventory();
HUDPatcher.ResizeHotbarSlotsHUD();
Keybinds.OnSetHotbarSize();
RequestSyncHeldObjects();
}
internal static void OnUpdateHotbarSize()
{
Plugin.Log("Finished receiving OnUpdatePurchasedHotbarSlots update. New purchased hotbar slots: " + purchasedHotbarSlots);
PlayerPatcher.ResizeInventory();
HUDPatcher.ResizeHotbarSlotsHUD();
Keybinds.OnSetHotbarSize();
}
private static void RequestSyncHeldObjects()
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
if (NetworkManager.Singleton.IsClient && !NetworkManager.Singleton.IsServer)
{
Plugin.Log("Requesting sync held objects from server.");
NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("HotbarPlus.RequestSyncHeldObjectsServerRpc", 0uL, new FastBufferWriter(0, (Allocator)2, -1), (NetworkDelivery)3);
}
}
private static void RequestSyncHeldObjectsServerRpc(ulong clientId, FastBufferReader reader)
{
//IL_023a: Unknown result type (might be due to invalid IL or missing references)
//IL_0240: Unknown result type (might be due to invalid IL or missing references)
//IL_027b: Unknown result type (might be due to invalid IL or missing references)
//IL_0281: Unknown result type (might be due to invalid IL or missing references)
//IL_028f: Unknown result type (might be due to invalid IL or missing references)
//IL_0295: Unknown result type (might be due to invalid IL or missing references)
//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
//IL_033e: Unknown result type (might be due to invalid IL or missing references)
//IL_02df: Unknown result type (might be due to invalid IL or missing references)
//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
if (!NetworkManager.Singleton.IsServer)
{
return;
}
List<ushort> list = new List<ushort>();
List<short> list2 = new List<short>();
Dictionary<ushort, List<short>> dictionary = new Dictionary<ushort, List<short>>();
Dictionary<ushort, List<ulong>> dictionary2 = new Dictionary<ushort, List<ulong>>();
int num = 2;
PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
foreach (PlayerControllerB val in allPlayerScripts)
{
ushort num2 = (ushort)val.actualClientId;
ushort num3 = (ushort)val.playerClientId;
if (num2 == clientId || (num2 == 0 && (Object)(object)val != (Object)(object)localPlayerController))
{
continue;
}
for (int j = 4; j < currentHotbarSize; j++)
{
GrabbableObject val2 = val.ItemSlots[j];
if ((Object)(object)val2 != (Object)null || j == val.currentItemSlot)
{
if (!dictionary.ContainsKey(num3))
{
dictionary.Add(num3, new List<short>());
dictionary2.Add(num3, new List<ulong>());
}
if ((Object)(object)val2 != (Object)null)
{
dictionary[num3].Add((short)j);
dictionary2[num3].Add(((NetworkBehaviour)val2).NetworkObjectId);
}
}
}
if (dictionary.ContainsKey(num3) && (dictionary[num3].Count > 0 || (val.currentItemSlot >= 4 && val.currentItemSlot < currentHotbarSize)))
{
num += 2;
num += 2;
num += 2;
num += 10 * dictionary[num3].Count;
list.Add(num3);
list2.Add((short)val.currentItemSlot);
}
}
Plugin.Log("Receiving sync held objects request from client with id: " + clientId + ". " + list.Count + " players are currently holding items in extra item slots.");
FastBufferWriter val3 = default(FastBufferWriter);
((FastBufferWriter)(ref val3))..ctor(num, (Allocator)2, -1);
short num4 = (short)list.Count;
((FastBufferWriter)(ref val3)).WriteValue<short>(ref num4, default(ForPrimitives));
for (int k = 0; k < list.Count; k++)
{
ushort key = list[k];
short num5 = list2[k];
short num6 = (short)dictionary[key].Count;
((FastBufferWriter)(ref val3)).WriteValue<ushort>(ref key, default(ForPrimitives));
((FastBufferWriter)(ref val3)).WriteValue<short>(ref num5, default(ForPrimitives));
((FastBufferWriter)(ref val3)).WriteValue<short>(ref num6, default(ForPrimitives));
for (int l = 0; l < num6; l++)
{
short num7 = dictionary[key][l];
ulong num8 = dictionary2[key][l];
((FastBufferWriter)(ref val3)).WriteValue<short>(ref num7, default(ForPrimitives));
((FastBufferWriter)(ref val3)).WriteValue<ulong>(ref num8, default(ForPrimitives));
}
}
NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("HotbarPlus.RequestSyncHeldObjectsClientRpc", clientId, val3, (NetworkDelivery)4);
}
private static void RequestSyncHeldObjectsClientRpc(ulong clientId, FastBufferReader reader)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
if (!NetworkManager.Singleton.IsClient || NetworkManager.Singleton.IsServer)
{
return;
}
short num = default(short);
((FastBufferReader)(ref reader)).ReadValue<short>(ref num, default(ForPrimitives));
Plugin.Log("Receiving sync held objects from server. Number of players already holding items in extra hotbar slots: " + num);
ushort num2 = default(ushort);
short num3 = default(short);
short num4 = default(short);
short num5 = default(short);
ulong networkObjectId = default(ulong);
for (int i = 0; i < num; i++)
{
((FastBufferReader)(ref reader)).ReadValue<ushort>(ref num2, default(ForPrimitives));
((FastBufferReader)(ref reader)).ReadValue<short>(ref num3, default(ForPrimitives));
((FastBufferReader)(ref reader)).ReadValue<short>(ref num4, default(ForPrimitives));
PlayerControllerB playerControllerByPlayerId = GetPlayerControllerByPlayerId(num2);
if (playerControllerByPlayerId.currentItemSlot >= 0 && playerControllerByPlayerId.currentItemSlot < playerControllerByPlayerId.ItemSlots.Length && playerControllerByPlayerId.currentItemSlot != num3 && num3 >= 4)
{
GrabbableObject val = playerControllerByPlayerId.ItemSlots[playerControllerByPlayerId.currentItemSlot];
if ((Object)(object)val != (Object)null)
{
val.PocketItem();
}
playerControllerByPlayerId.currentItemSlot = num3;
}
for (int j = 0; j < num4; j++)
{
((FastBufferReader)(ref reader)).ReadValue<short>(ref num5, default(ForPrimitives));
((FastBufferReader)(ref reader)).ReadValue<ulong>(ref networkObjectId, default(ForPrimitives));
GrabbableObject grabbableObjectByNetworkId = GetGrabbableObjectByNetworkId(networkObjectId);
if ((Object)(object)grabbableObjectByNetworkId != (Object)null && Object.op_Implicit((Object)(object)playerControllerByPlayerId) && num5 >= 0)
{
grabbableObjectByNetworkId.isHeld = true;
playerControllerByPlayerId.ItemSlots[num5] = grabbableObjectByNetworkId;
grabbableObjectByNetworkId.parentObject = playerControllerByPlayerId.serverItemHolder;
grabbableObjectByNetworkId.playerHeldBy = playerControllerByPlayerId;
bool flag = num3 == num5;
grabbableObjectByNetworkId.EnablePhysics(false);
if (flag)
{
grabbableObjectByNetworkId.EquipItem();
playerControllerByPlayerId.currentlyHeldObjectServer = grabbableObjectByNetworkId;
playerControllerByPlayerId.isHoldingObject = true;
playerControllerByPlayerId.twoHanded = grabbableObjectByNetworkId.itemProperties.twoHanded;
playerControllerByPlayerId.twoHandedAnimation = grabbableObjectByNetworkId.itemProperties.twoHandedAnimation;
playerControllerByPlayerId.currentItemSlot = num5;
}
else
{
grabbableObjectByNetworkId.PocketItem();
}
}
}
}
}
public static void SendPurchaseHotbarSlotToServer(int newAdditionalSlots)
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
FastBufferWriter val = default(FastBufferWriter);
((FastBufferWriter)(ref val))..ctor(2, (Allocator)2, -1);
Plugin.Log("Sending purchase hotbar slot update to server. New additional hotbar slots: " + newAdditionalSlots);
short num = (short)newAdditionalSlots;
((FastBufferWriter)(ref val)).WriteValue<short>(ref num, default(ForPrimitives));
NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("HotbarPlus.OnPurchaseHotbarSlotServerRpc", 0uL, val, (NetworkDelivery)3);
}
private static void OnPurchaseHotbarSlotServerRpc(ulong clientId, FastBufferReader reader)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
if (!NetworkManager.Singleton.IsServer)
{
return;
}
((FastBufferReader)(ref reader)).ReadValue<short>(ref purchasedHotbarSlots, default(ForPrimitives));
if (NetworkManager.Singleton.IsClient)
{
if (clientId != localPlayerController.actualClientId)
{
Plugin.Log("Receiving on purchase additional hotbar slot update from client: " + clientId + ". New hotbar slots purchased: " + purchasedHotbarSlots);
}
OnUpdateHotbarSize();
}
SendNewAdditionalHotbarSlotsToClients(purchasedHotbarSlots);
}
public static void SendNewAdditionalHotbarSlotsToClients(int newAdditionalSlots)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
if (NetworkManager.Singleton.IsServer)
{
FastBufferWriter val = default(FastBufferWriter);
((FastBufferWriter)(ref val))..ctor(2, (Allocator)2, -1);
short num = (short)newAdditionalSlots;
((FastBufferWriter)(ref val)).WriteValue<short>(ref num, default(ForPrimitives));
NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("HotbarPlus.OnPurchaseHotbarSlotClientRpc", val, (NetworkDelivery)3);
}
}
private static void OnPurchaseHotbarSlotClientRpc(ulong clientId, FastBufferReader reader)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
if (NetworkManager.Singleton.IsClient && !NetworkManager.Singleton.IsServer)
{
((FastBufferReader)(ref reader)).ReadValue<short>(ref purchasedHotbarSlots, default(ForPrimitives));
Plugin.Log("Receiving on purchase additional hotbar slot update from server. New hotbar slots purchased: " + purchasedHotbarSlots);
OnUpdateHotbarSize();
}
}
private static void SendHotbarSlotChange(int hotbarSlot)
{
if (NetworkManager.Singleton.IsClient && hotbarSlot != localPlayerController.currentItemSlot)
{
Plugin.Log("Sending hotbar swap slot: " + hotbarSlot);
int num = hotbarSlot - localPlayerController.currentItemSlot;
bool flag = num > 0;
for (int i = 0; i < Mathf.Abs(num); i++)
{
MethodInfo method = ((object)localPlayerController).GetType().GetMethod("SwitchItemSlotsServerRpc", BindingFlags.Instance | BindingFlags.NonPublic);
method.Invoke(localPlayerController, new object[1] { flag });
}
}
}
public static void SwapHotbarSlot(int hotbarIndex)
{
if (hotbarIndex < currentHotbarSize)
{
SendHotbarSlotChange(hotbarIndex);
CallSwitchToItemSlotMethod(localPlayerController, hotbarIndex);
}
}
public static void CallSwitchToItemSlotMethod(PlayerControllerB playerController, int hotbarIndex)
{
if (hotbarIndex >= 0 && hotbarIndex < currentHotbarSize && playerController.currentItemSlot != hotbarIndex)
{
if ((Object)(object)playerController == (Object)(object)localPlayerController)
{
ShipBuildModeManager.Instance.CancelBuildMode(true);
playerController.playerBodyAnimator.SetBool("GrabValidated", false);
}
MethodInfo method = ((object)playerController).GetType().GetMethod("SwitchToItemSlot", BindingFlags.Instance | BindingFlags.NonPublic);
method.Invoke(playerController, new object[2] { hotbarIndex, null });
PlayerPatcher.SetTimeSinceSwitchingSlots(playerController, 0f);
if ((Object)(object)playerController.currentlyHeldObjectServer != (Object)null)
{
((Component)playerController.currentlyHeldObjectServer).gameObject.GetComponent<AudioSource>().PlayOneShot(playerController.currentlyHeldObjectServer.itemProperties.grabSFX, 0.6f);
}
}
}
internal static PlayerControllerB GetPlayerControllerByClientId(ulong clientId)
{
for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++)
{
PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[i];
if (val.actualClientId == clientId)
{
return val;
}
}
return null;
}
internal static PlayerControllerB GetPlayerControllerByPlayerId(ulong playerId)
{
for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++)
{
PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[i];
if (val.playerClientId == playerId)
{
return val;
}
}
return null;
}
internal static GrabbableObject GetGrabbableObjectByNetworkId(ulong networkObjectId)
{
if (NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(networkObjectId, out var value))
{
return ((Component)value).GetComponentInChildren<GrabbableObject>();
}
return null;
}
}
}
namespace HotbarPlus.UI
{
internal static class LightningIndicatorManager
{
private static Color warningIconColorHidden = new Color(1f, 1f, 1f, 0f);
private static float iconScale = 0.85f;
private static GameObject currentMetalObject;
private static Image currentWarningIcon = null;
private static float timeSetWarning = 0f;
private static float updateTime = 0f;
[HarmonyPatch(typeof(StormyWeather), "OnDisable")]
[HarmonyPrefix]
private static void OnStopStorm()
{
if (Object.op_Implicit((Object)(object)currentWarningIcon))
{
ClearCurrentWarningIcon();
}
}
[HarmonyPatch(typeof(StormyWeather), "Update")]
[HarmonyPostfix]
private static void Update()
{
//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
//IL_0189: Unknown result type (might be due to invalid IL or missing references)
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)currentMetalObject) && !ConfigSettings.disableItemStaticWarningsConfig.Value)
{
if (Time.time - updateTime > 0.1f)
{
updateTime = Time.time;
Image val = null;
for (int i = 0; i < StartOfRound.Instance.localPlayerController.ItemSlots.Length; i++)
{
GrabbableObject obj = StartOfRound.Instance.localPlayerController.ItemSlots[i];
GameObject val2 = ((obj != null) ? ((Component)obj).gameObject : null);
if ((Object)(object)currentMetalObject == (Object)(object)val2)
{
Image val3 = HUDManager.Instance.itemSlotIconFrames[i];
Transform obj2 = ((Component)val3).transform.Find("LightningWarningIcon");
val = ((obj2 != null) ? ((Component)obj2).GetComponent<Image>() : null);
if (!Object.op_Implicit((Object)(object)val))
{
GameObject obj3 = Object.Instantiate<GameObject>(Plugin.lightningIndicatorPrefab);
val = ((obj3 != null) ? obj3.GetComponent<Image>() : null);
((Object)val).name = "LightningWarningIcon";
((Component)val).transform.SetParent(((Component)val3).transform);
((Graphic)val).rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
((Graphic)val).rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
((Graphic)val).rectTransform.pivot = new Vector2(0.5f, 0.5f);
float num = ((Graphic)val3).rectTransform.sizeDelta.x / HUDPatcher.defaultItemFrameSize.x * iconScale;
((Transform)((Graphic)val).rectTransform).localScale = Vector3.one / 36f * num;
((Graphic)val).rectTransform.anchoredPosition3D = new Vector3(0f, 0f, 0f);
((Component)val).transform.localEulerAngles = new Vector3(0f, 0f, 90f);
}
break;
}
}
if (Object.op_Implicit((Object)(object)val))
{
if ((Object)(object)currentWarningIcon != (Object)(object)val)
{
ClearCurrentWarningIcon();
SetCurrentWarningIcon(val);
}
}
else if (Object.op_Implicit((Object)(object)currentWarningIcon))
{
ClearCurrentWarningIcon();
}
}
}
else if (Object.op_Implicit((Object)(object)currentWarningIcon))
{
ClearCurrentWarningIcon();
}
if (Object.op_Implicit((Object)(object)currentWarningIcon))
{
((Graphic)currentWarningIcon).color = new Color(1f, 1f, 1f, (Mathf.Sin((float)Math.PI * 2f * (Time.time - timeSetWarning - 0.25f)) + 1f) / 2f);
}
}
[HarmonyPatch(typeof(StormyWeather), "SetStaticElectricityWarning")]
[HarmonyPrefix]
private static void OnSetStaticToObject(NetworkObject warningObject, float particleTime)
{
currentMetalObject = ((Component)warningObject).gameObject;
}
[HarmonyPatch(typeof(StormyWeather), "LightningStrike")]
[HarmonyPrefix]
private static void OnLightningStrike(Vector3 strikePosition, bool useTargetedObject)
{
if (useTargetedObject)
{
currentMetalObject = null;
}
}
[HarmonyPatch(typeof(PlayerControllerB), "SetObjectAsNoLongerHeld")]
[HarmonyPrefix]
private static void OnDiscardItem(bool droppedInElevator, bool droppedInShipRoom, Vector3 targetFloorPosition, GrabbableObject dropObject, PlayerControllerB __instance)
{
if (Object.op_Implicit((Object)(object)currentWarningIcon) && (Object)(object)dropObject == (Object)(object)currentMetalObject && (Object)(object)__instance == (Object)(object)StartOfRound.Instance.localPlayerController)
{
ClearCurrentWarningIcon();
}
}
private static void SetCurrentWarningIcon(Image warningIcon)
{
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)currentWarningIcon) && (Object)(object)currentWarningIcon != (Object)(object)warningIcon)
{
ClearCurrentWarningIcon();
}
if (Object.op_Implicit((Object)(object)warningIcon))
{
currentWarningIcon = warningIcon;
((Graphic)warningIcon).color = new Color(1f, 1f, 1f, 0f);
timeSetWarning = Time.time;
}
}
private static void ClearCurrentWarningIcon()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)currentWarningIcon))
{
((Graphic)currentWarningIcon).color = warningIconColorHidden;
currentWarningIcon = null;
}
}
}
internal class EnergyBarData
{
public GameObject gameObject;
public Slider slider;
public Image energyBarImage;
public Transform transform => gameObject.transform;
public RectTransform rectTransform
{
get
{
Transform obj = transform;
return (RectTransform)(object)((obj is RectTransform) ? obj : null);
}
}
public EnergyBarData(GameObject gameObject)
{
this.gameObject = gameObject;
slider = gameObject.GetComponentInChildren<Slider>();
Transform obj = transform.Find("FillMask/Fill");
energyBarImage = ((obj != null) ? ((Component)obj).GetComponent<Image>() : null);
if (!Object.op_Implicit((Object)(object)energyBarImage))
{
Plugin.LogWarning("Failed to find image for energy bar. This is okay.");
}
}
public void SetEnergyBarColor(Color color)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)energyBarImage))
{
((Graphic)energyBarImage).color = color;
}
}
}
[HarmonyPatch]
internal static class EnergyBarManager
{
internal static Dictionary<Image, EnergyBarData> energyBarSlidersDict = new Dictionary<Image, EnergyBarData>();
public static Color energyBarColor = new Color(200f, 200f, 0f, 0.75f);
private static PlayerControllerB localPlayerController => StartOfRound.Instance?.localPlayerController;
[HarmonyPatch(typeof(HUDManager), "Awake")]
[HarmonyPrefix]
private static void Init(HUDManager __instance)
{
energyBarSlidersDict?.Clear();
}
[HarmonyPatch(typeof(StartOfRound), "ResetShip")]
[HarmonyPrefix]
private static void OnResetShip()
{
ResetEnergyBars();
}
[HarmonyPatch(typeof(PlayerControllerB), "SpawnPlayerAnimation")]
[HarmonyPrefix]
private static void OnPlayerRespawn(PlayerControllerB __instance)
{
if (!((Object)(object)__instance != (Object)(object)localPlayerController))
{
ResetEnergyBars();
}
}
private static void ResetEnergyBars()
{
Plugin.Log("Resetting energy bars.");
foreach (EnergyBarData value in energyBarSlidersDict.Values)
{
Object.DestroyImmediate((Object)(object)value.gameObject);
}
energyBarSlidersDict?.Clear();
}
[HarmonyPatch(typeof(HUDManager), "Update")]
[HarmonyPostfix]
private static void UpdateEnergyBars(HUDManager __instance)
{
//IL_019c: Unknown result type (might be due to invalid IL or missing references)
//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
//IL_0210: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_0148: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)localPlayerController == (Object)null || __instance?.itemSlotIconFrames == null || localPlayerController.isPlayerDead)
{
return;
}
for (int i = 0; i < __instance.itemSlotIconFrames.Length; i++)
{
Image val = __instance.itemSlotIconFrames[i];
if (!Object.op_Implicit((Object)(object)val))
{
continue;
}
GrabbableObject val2 = null;
if (i >= 0 && i < localPlayerController.ItemSlots.Length)
{
val2 = localPlayerController.ItemSlots[i];
}
if (!energyBarSlidersDict.TryGetValue(val, out var value))
{
Transform obj = ((Component)val).transform.Find("EnergyBar");
GameObject val3 = ((obj != null) ? ((Component)obj).gameObject : null);
if (!Object.op_Implicit((Object)(object)val3))
{
val3 = Object.Instantiate<GameObject>(Plugin.energyBarPrefab);
}
((Object)val3).name = "EnergyBar";
val3.transform.SetParent(((Component)val).transform);
value = new EnergyBarData(val3);
value.rectTransform.anchorMin = new Vector2(1f, 0.5f);
value.rectTransform.anchorMax = new Vector2(1f, 0.5f);
value.rectTransform.pivot = new Vector2(0.5f, 0.5f);
value.SetEnergyBarColor(energyBarColor);
energyBarSlidersDict.Add(val, value);
}
if (!Object.op_Implicit((Object)(object)value.gameObject))
{
energyBarSlidersDict.Remove(val);
continue;
}
float num = ((Graphic)val).rectTransform.sizeDelta.x / HUDPatcher.defaultItemFrameSize.x;
((Transform)value.rectTransform).localScale = Vector3.one / 36f * num;
value.rectTransform.anchoredPosition3D = new Vector3(-4f * num, 0f, 0f);
value.transform.localEulerAngles = new Vector3(0f, 0f, 90f);
if (ConfigSettings.disableEnergyBarsConfig.Value || !Object.op_Implicit((Object)(object)val2) || !val2.itemProperties.requiresBattery || val2.insertedBattery == null || (ReservedItemSlots_Compat.Enabled && ((Object)val).name.ToLower().Contains("reserved") && ReservedItemSlots_Compat.ShouldDisableEnergyBarsReservedItemSlots()))
{
if (value.gameObject.activeSelf)
{
value.gameObject.SetActive(false);
}
}
else
{
value.gameObject.SetActive(true);
value.slider.value = Mathf.Clamp(val2.insertedBattery.charge, 0f, 1f);
}
}
}
}
}
namespace HotbarPlus.Patches
{
[HarmonyPatch]
internal static class TerminalPatcher
{
public static Terminal terminalInstance;
public static bool initializedTerminalNodes;
private static bool inHotbarPlusTerminalMenu;
private static bool purchasingHotbarSlot;
internal static int nextHotbarSlotPrice => SyncManager.purchasableHotbarSlotsPrice + SyncManager.purchasedHotbarSlots * SyncManager.purchasableHotbarSlotsPriceIncrease;
[HarmonyPatch(typeof(Terminal), "Awake")]
[HarmonyPrefix]
public static void InitializeTerminal(Terminal __instance)
{
terminalInstance = __instance;
initializedTerminalNodes = false;
EditExistingTerminalNodes();
}
[HarmonyPatch(typeof(Terminal), "BeginUsingTerminal")]
[HarmonyPrefix]
public static void OnBeginUsingTerminal(Terminal __instance)
{
if (!initializedTerminalNodes && SyncManager.isSynced)
{
EditExistingTerminalNodes();
}
}
public static void EditExistingTerminalNodes()
{
if (!SyncManager.isSynced)
{
return;
}
initializedTerminalNodes = true;
if (SyncManager.purchasedHotbarSlots >= SyncManager.purchasableHotbarSlots)
{
return;
}
foreach (TerminalNode specialNode in terminalInstance.terminalNodes.specialNodes)
{
if (((Object)specialNode).name == "Start" && !specialNode.displayText.Contains("[HotbarPlus]"))
{
string text = "Type \"Help\" for a list of commands.";
int num = specialNode.displayText.IndexOf(text);
if (num != -1)
{
num += text.Length;
string value = "\n\n[HotbarPlus]\nType \"HotbarPlus\" to buy additional hotbar slots.";
specialNode.displayText = specialNode.displayText.Insert(num, value);
}
else
{
Plugin.LogError("Failed to add HotbarPlus tips to terminal. Maybe an update broke it?");
}
}
else if (((Object)specialNode).name == "HelpCommands" && !specialNode.displayText.Contains(">HOTBARPLUS"))
{
string value2 = "[numberOfItemsOnRoute]";
int num2 = specialNode.displayText.IndexOf(value2);
if (num2 != -1)
{
string text2 = ">HOTBARPLUS\n";
text2 += "Purchase additional hotbar slots.\n\n";
specialNode.displayText = specialNode.displayText.Insert(num2, text2);
}
}
}
}
[HarmonyPatch(typeof(Terminal), "ParsePlayerSentence")]
[HarmonyPrefix]
public static bool ParsePlayerSentence(ref TerminalNode __result, Terminal __instance)
{
if (__instance.screenText.text.Length <= 0)
{
inHotbarPlusTerminalMenu = false;
purchasingHotbarSlot = false;
return true;
}
string text = __instance.screenText.text.Substring(__instance.screenText.text.Length - __instance.textAdded).ToLower();
string[] array = text.Split(new char[1] { ' ' });
if (!SyncManager.isSynced)
{
if (text.StartsWith("hotbarplus"))
{
__result = BuildTerminalNodeHostDoesNotHaveMod();
return false;
}
return true;
}
if (purchasingHotbarSlot)
{
inHotbarPlusTerminalMenu = false;
purchasingHotbarSlot = false;
if ("confirm".StartsWith(text))
{
if (SyncManager.purchasableHotbarSlots <= 0)
{
Plugin.LogWarning("Attempted to purchase additional hotbar slot while this is not enabled by the host.");
__result = BuildTerminalNodePurchasingSlotsNotEnabled();
}
else if (SyncManager.purchasedHotbarSlots >= SyncManager.purchasableHotbarSlots)
{
Plugin.LogWarning("Attempted to purchase additional hotbar slot while the maximum slots have already been purchased.");
__result = BuildTerminalNodeMaxHotbarSlotsPurchased();
}
else if (terminalInstance.groupCredits < nextHotbarSlotPrice)
{
Plugin.LogWarning("Attempted to purchase additional hotbar slot with insufficient credits. Current credits: " + terminalInstance.groupCredits + " Required credits: " + nextHotbarSlotPrice);
__result = BuildTerminalNodeInsufficientFunds();
}
else
{
Plugin.Log("Purchasing additional hotbar slot for " + nextHotbarSlotPrice + " credits. New num hotbar slots purchased: " + (SyncManager.purchasedHotbarSlots + 1));
Terminal obj = terminalInstance;
obj.groupCredits -= nextHotbarSlotPrice;
terminalInstance.BuyItemsServerRpc(new int[0], terminalInstance.groupCredits, terminalInstance.numberOfItemsInDropship);
if (terminalInstance.groupCredits < nextHotbarSlotPrice + SyncManager.purchasableHotbarSlotsPriceIncrease && SyncManager.purchasedHotbarSlots + 1 < SyncManager.purchasableHotbarSlots)
{
inHotbarPlusTerminalMenu = true;
}
__result = BuildTerminalNodeOnPurchased(terminalInstance.groupCredits);
SyncManager.SendPurchaseHotbarSlotToServer(SyncManager.purchasedHotbarSlots + 1);
}
}
else
{
Plugin.Log("Canceling order.");
__result = BuildCustomTerminalNode("Canceled order.\n\n");
}
return false;
}
purchasingHotbarSlot = false;
if (array.Length != 0 && (array[0] == "hotbarplus" || array[0] == "hotbar" || (inHotbarPlusTerminalMenu && ("buy".StartsWith(array[0]) || "purchase".StartsWith(array[0])))))
{
if (array[0] == "hotbarplus" || array[0] == "hotbar")
{
if (array.Length == 1)
{
__result = BuildTerminalNodeHome();
inHotbarPlusTerminalMenu = true;
return false;
}
if (!"buy".StartsWith(array[1]) && !"purchase".StartsWith(array[1]))
{
__result = BuildCustomTerminalNode("Invalid command. Type \"HotbarPlus\" to view the HotbarPlus terminal menu.\n\n");
return false;
}
}
if (SyncManager.purchasableHotbarSlots <= 0)
{
Plugin.LogWarning("Attempted to purchase additional hotbar slot, but the host does not have this setting enabled.");
__result = BuildTerminalNodePurchasingSlotsNotEnabled();
}
else if (SyncManager.purchasedHotbarSlots >= SyncManager.purchasableHotbarSlots)
{
Plugin.LogWarning("Attempted to purchase additional hotbar slot while the maximum slots have already been purchased.");
__result = BuildTerminalNodeMaxHotbarSlotsPurchased();
}
else if (terminalInstance.groupCredits < nextHotbarSlotPrice)
{
Plugin.LogWarning("Attempted to purchase additional hotbar slot with insufficient credits. Current credits: " + terminalInstance.groupCredits + " Required credits: " + nextHotbarSlotPrice);
__result = BuildTerminalNodeInsufficientFunds();
}
else
{
Plugin.Log("Starting purchase on additional hotbar slot for " + nextHotbarSlotPrice + " credits.");
__result = BuildTerminalNodeConfirmDenyPurchase();
purchasingHotbarSlot = true;
}
inHotbarPlusTerminalMenu = false;
return false;
}
inHotbarPlusTerminalMenu = false;
return true;
}
private static TerminalNode BuildTerminalNodeHome()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: 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_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Expected O, but got Unknown
TerminalNode val = new TerminalNode
{
displayText = "[HotbarPlus]\n\n",
clearPreviousText = true,
acceptAnything = false
};
if (SyncManager.purchasableHotbarSlots <= 0)
{
val.displayText += "Additional hotbar slots cannot be purchased.\n\nHost does not have this setting enabled.\n\n";
}
else if (SyncManager.purchasedHotbarSlots >= SyncManager.purchasableHotbarSlots)
{
val.displayText += "Additional hotbar slots cannot be purchased.\n\nMaximum purchasable slots has been reached.\n\n";
}
else
{
val.displayText = val.displayText + "Purchase additional hotbar slot: $" + nextHotbarSlotPrice + "\n> PURCHASE\n\n";
}
return val;
}
private static TerminalNode BuildTerminalNodeConfirmDenyPurchase()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Expected O, but got Unknown
TerminalNode val = new TerminalNode
{
displayText = "You have requested to purchase an additional hotbar slot for $" + nextHotbarSlotPrice + " credits.\n\n",
isConfirmationNode = true,
acceptAnything = false,
clearPreviousText = true
};
val.displayText = val.displayText + "Credit balance: $" + terminalInstance.groupCredits + "\n";
TerminalNode val2 = val;
val2.displayText = val2.displayText + "Current purchased hotbar slots: (" + SyncManager.purchasedHotbarSlots + "/" + SyncManager.purchasableHotbarSlots + ")\n\n";
val.displayText += "Please CONFIRM or DENY.\n\n";
return val;
}
private static TerminalNode BuildTerminalNodeOnPurchased(int newGroupCredits)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
TerminalNode val = new TerminalNode();
val.displayText = "You have successfully purchased an additional hotbar slot!\n\nNew main hotbar size: " + (SyncManager.currentHotbarSize + 1) + "\nNew credit balance: $" + newGroupCredits + "\n\n";
val.buyUnlockable = true;
val.clearPreviousText = true;
val.acceptAnything = false;
val.playSyncedClip = 0;
TerminalNode val2 = val;
if (terminalInstance.groupCredits < nextHotbarSlotPrice + SyncManager.purchasableHotbarSlotsPriceIncrease && SyncManager.purchasedHotbarSlots + 1 < SyncManager.purchasableHotbarSlots)
{
val2.displayText = val2.displayText + "Purchase additional hotbar slot: $" + (nextHotbarSlotPrice + 1) + "\n> PURCHASE\n\n";
}
return val2;
}
private static TerminalNode BuildTerminalNodePurchasingSlotsNotEnabled()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: 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_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Expected O, but got Unknown
return new TerminalNode
{
displayText = "Cannot purchase additional hotbar slots.\n\nHost does not have this setting enabled.\n\n",
clearPreviousText = false,
acceptAnything = false
};
}
private static TerminalNode BuildTerminalNodeMaxHotbarSlotsPurchased()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: 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_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Expected O, but got Unknown
return new TerminalNode
{
displayText = "Cannot purchase more hotbar slots.\n\nMaximum purchasable slots has been reached.\n\n",
clearPreviousText = false,
acceptAnything = false
};
}
private static TerminalNode BuildTerminalNodeInsufficientFunds()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
TerminalNode val = new TerminalNode();
val.displayText = "You cannot afford to purchase an additional hotbar slot.\n\nCredit balance is $" + terminalInstance.groupCredits + "\nAdditional hotbar slot price: " + nextHotbarSlotPrice + "\n\n";
val.clearPreviousText = true;
val.acceptAnything = false;
return val;
}
private static TerminalNode BuildTerminalNodeHostDoesNotHaveMod()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: 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_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Expected O, but got Unknown
return new TerminalNode
{
displayText = "You cannot use purchase additional hotbar slots until you have synced with the host.\n\nYou may also be seeing this because the host does not have this mod.\n\n",
clearPreviousText = true,
acceptAnything = false
};
}
private static TerminalNode BuildCustomTerminalNode(string displayText, bool clearPreviousText = false, bool acceptAnything = false, bool isConfirmationNode = false)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: 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_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
return new TerminalNode
{
displayText = displayText,
clearPreviousText = clearPreviousText,
acceptAnything = false,
isConfirmationNode = isConfirmationNode
};
}
}
[HarmonyPatch]
public class HUDPatcher
{
internal static List<Image> mainItemSlotFrames = new List<Image>();
internal static List<Image> mainItemSlotIcons = new List<Image>();
private static int mainHotbarSize = 4;
internal static float hotbarSlotSize = 40f;
internal static Vector2 defaultItemFrameSize;
internal static Vector2 defaultItemIconSize;
internal static float defaultItemSlotPosY;
internal static float currentOverrideHotbarSpacing;
internal static float currentOverrideHotbarHudScale;
[HarmonyPatch(typeof(HUDManager), "Awake")]
[HarmonyPostfix]
private static void Init(HUDManager __instance)
{
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
mainItemSlotFrames.Clear();
mainItemSlotIcons.Clear();
mainHotbarSize = __instance.itemSlotIconFrames.Length;
for (int i = 0; i < mainHotbarSize; i++)
{
mainItemSlotFrames.Add(__instance.itemSlotIconFrames[i]);
mainItemSlotIcons.Add(__instance.itemSlotIcons[i]);
}
defaultItemFrameSize = ((Graphic)__instance.itemSlotIconFrames[0]).rectTransform.sizeDelta;
defaultItemIconSize = ((Graphic)__instance.itemSlotIcons[0]).rectTransform.sizeDelta;
defaultItemSlotPosY = ((Graphic)__instance.itemSlotIconFrames[0]).rectTransform.anchoredPosition.y;
}
public static void ResizeHotbarSlotsHUD()
{
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_0267: Unknown result type (might be due to invalid IL or missing references)
//IL_026d: Unknown result type (might be due to invalid IL or missing references)
//IL_0285: Unknown result type (might be due to invalid IL or missing references)
//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
List<Image> list = new List<Image>(HUDManager.Instance.itemSlotIconFrames);
List<Image> list2 = new List<Image>(HUDManager.Instance.itemSlotIcons);
float num = (hotbarSlotSize + (float)ConfigSettings.overrideHotbarSpacingConfig.Value) * ConfigSettings.overrideHotbarHudSizeConfig.Value;
float num2 = defaultItemSlotPosY + 36f * ((ConfigSettings.overrideHotbarHudSizeConfig.Value - 1f) / 2f);
Vector3 eulerAngles = ((Transform)((Graphic)list[0]).rectTransform).eulerAngles;
Vector3 eulerAngles2 = ((Transform)((Graphic)list2[0]).rectTransform).eulerAngles;
mainItemSlotFrames.Clear();
mainItemSlotIcons.Clear();
for (int i = 0; i < Mathf.Max((int)SyncManager.currentHotbarSize, mainHotbarSize); i++)
{
if (i >= SyncManager.currentHotbarSize)
{
Object.Destroy((Object)(object)list[SyncManager.currentHotbarSize]);
Object.Destroy((Object)(object)list2[SyncManager.currentHotbarSize]);
list.RemoveAt(SyncManager.currentHotbarSize);
list2.RemoveAt(SyncManager.currentHotbarSize);
continue;
}
if (i >= mainHotbarSize)
{
Image item = Object.Instantiate<Image>(list[0], ((Component)list[0]).transform.parent);
list.Insert(i, item);
((Component)list[i]).transform.SetSiblingIndex(((Component)list[i - 1]).transform.GetSiblingIndex() + 1);
Image component = ((Component)((Component)list[i]).transform.GetChild(0)).GetComponent<Image>();
component.sprite = null;
((Behaviour)component).enabled = false;
list2.Insert(i, component);
list[i].fillMethod = list[0].fillMethod;
list[i].sprite = list[0].sprite;
((Graphic)list[i]).material = ((Graphic)list[0]).material;
if (Plugin.IsModLoaded("xuxiaolan.hotbarrd"))
{
list[i].overrideSprite = list[0].overrideSprite;
}
}
mainItemSlotFrames.Insert(i, list[i]);
mainItemSlotIcons.Insert(i, list2[i]);
((Object)list[i]).name = $"Slot{i}";
((Graphic)list[i]).rectTransform.anchoredPosition = Vector2.up * num2;
((Transform)((Graphic)list[i]).rectTransform).eulerAngles = eulerAngles;
((Object)list2[i]).name = "Icon";
((Transform)((Graphic)list2[i]).rectTransform).eulerAngles = eulerAngles2;
}
mainHotbarSize = SyncManager.currentHotbarSize;
HUDManager.Instance.itemSlotIconFrames = list.ToArray();
HUDManager.Instance.itemSlotIcons = list2.ToArray();
UpdateUI();
}
internal static void UpdateUI()
{
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
Image[] itemSlotIconFrames = HUDManager.Instance.itemSlotIconFrames;
Image[] itemSlotIcons = HUDManager.Instance.itemSlotIcons;
float num = (hotbarSlotSize + (float)ConfigSettings.overrideHotbarSpacingConfig.Value) * ConfigSettings.overrideHotbarHudSizeConfig.Value;
float num2 = defaultItemSlotPosY + 36f * ((ConfigSettings.overrideHotbarHudSizeConfig.Value - 1f) / 2f);
float num3 = num * (float)(mainHotbarSize - 1);
float num4 = num3 / 2f;
for (int i = 0; i < mainHotbarSize; i++)
{
float num5 = (float)i * num - num4;
((Graphic)itemSlotIconFrames[i]).rectTransform.anchoredPosition = new Vector2(num5, num2);
((Graphic)itemSlotIconFrames[i]).rectTransform.sizeDelta = defaultItemFrameSize * ConfigSettings.overrideHotbarHudSizeConfig.Value;
((Graphic)itemSlotIcons[i]).rectTransform.sizeDelta = defaultItemIconSize * ConfigSettings.overrideHotbarHudSizeConfig.Value;
}
currentOverrideHotbarSpacing = ConfigSettings.overrideHotbarSpacingConfig.Value;
currentOverrideHotbarHudScale = ConfigSettings.overrideHotbarHudSizeConfig.Value;
}
[HarmonyPatch(typeof(HUDManager), "PingHUDElement")]
[HarmonyPrefix]
public static void OnPingHUDElement(HUDElement element, ref float startAlpha, ref float endAlpha, HUDManager __instance)
{
if (element != __instance.Inventory || endAlpha != 0.13f)
{
return;
}
if (startAlpha == 0.13f && StartOfRound.Instance.localPlayerController.twoHanded)
{
endAlpha = 1f;
return;
}
endAlpha = Mathf.Clamp(ConfigSettings.overrideFadeHudAlphaConfig.Value, 0f, 1f);
if (startAlpha == 0.13f)
{
startAlpha = endAlpha;
}
}
[HarmonyPatch(typeof(QuickMenuManager), "CloseQuickMenu")]
[HarmonyPrefix]
public static void OnCloseQuickMenu()
{
if (ReservedItemSlots_Compat.Enabled || ConfigSettings.overrideHotbarHudSizeConfig.Value != currentOverrideHotbarHudScale || (float)ConfigSettings.overrideHotbarSpacingConfig.Value != currentOverrideHotbarSpacing)
{
ResizeHotbarSlotsHUD();
}
}
}
[HarmonyPatch]
public class PlayerPatcher
{
public static int vanillaHotbarSize = -1;
public static int mainHotbarSize = -1;
private static PlayerControllerB localPlayerController => StartOfRound.Instance?.localPlayerController;
[HarmonyPatch(typeof(StartOfRound), "Awake")]
[HarmonyPostfix]
private static void ResetValues(StartOfRound __instance)
{
vanillaHotbarSize = -1;
mainHotbarSize = vanillaHotbarSize;
}
[HarmonyPatch(typeof(PlayerControllerB), "Awake")]
[HarmonyPostfix]
public static void GetInitialHotbarSize(PlayerControllerB __instance)
{
if (vanillaHotbarSize == -1)
{
vanillaHotbarSize = __instance.ItemSlots.Length;
mainHotbarSize = vanillaHotbarSize;
}
}
[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
[HarmonyPostfix]
public static void InitializeLocalPlayer(PlayerControllerB __instance)
{
((Component)HUDManager.Instance.itemSlotIconFrames[Mathf.Max(__instance.currentItemSlot, 0)]).GetComponent<Animator>().SetBool("selectedSlot", true);
HUDManager.Instance.PingHUDElement(HUDManager.Instance.Inventory, 0.1f, 0.13f, 0.13f);
}
public static void ResizeInventory()
{
int num = SyncManager.currentHotbarSize - mainHotbarSize;
if (num == 0)
{
return;
}
Plugin.LogWarning("Resizing main hotbar to: " + SyncManager.currentHotbarSize + ". Previous: " + mainHotbarSize);
PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
foreach (PlayerControllerB val in allPlayerScripts)
{
List<GrabbableObject> list = new List<GrabbableObject>(val.ItemSlots);
if (num > 0)
{
for (int j = 0; j < Mathf.Abs(num); j++)
{
list.Insert(mainHotbarSize, null);
if (val.currentItemSlot >= mainHotbarSize)
{
val.currentItemSlot++;
}
}
}
else
{
for (int k = 0; k < Mathf.Abs(num); k++)
{
list.RemoveAt(SyncManager.currentHotbarSize);
if (val.currentItemSlot >= SyncManager.currentHotbarSize)
{
val.currentItemSlot--;
}
}
}
val.ItemSlots = list.ToArray();
}
mainHotbarSize = SyncManager.currentHotbarSize;
}
public static int CallGetNextItemSlot(PlayerControllerB __instance, bool forward, int index)
{
int currentItemSlot = __instance.currentItemSlot;
__instance.currentItemSlot = index;
MethodInfo method = ((object)__instance).GetType().GetMethod("NextItemSlot", BindingFlags.Instance | BindingFlags.NonPublic);
index = (int)method.Invoke(__instance, new object[1] { forward });
__instance.currentItemSlot = currentItemSlot;
return index;
}
public static void CallSwitchToItemSlot(PlayerControllerB __instance, int index, GrabbableObject fillSlotWithItem = null)
{
MethodInfo method = ((object)__instance).GetType().GetMethod("SwitchToItemSlot", BindingFlags.Instance | BindingFlags.NonPublic);
method.Invoke(__instance, new object[2] { index, fillSlotWithItem });
SetTimeSinceSwitchingSlots(__instance, 0f);
}
public static float GetTimeSinceSwitchingSlots(PlayerControllerB playerController)
{
return (float)Traverse.Create((object)playerController).Field("timeSinceSwitchingSlots").GetValue();
}
public static void SetTimeSinceSwitchingSlots(PlayerControllerB playerController, float value)
{
Traverse.Create((object)playerController).Field("timeSinceSwitchingSlots").SetValue((object)value);
}
[HarmonyPatch(typeof(PlayerControllerB), "ScrollMouse_performed")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> PatchSwitchItemInterval(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
if (!ConfigSettings.disableFasterHotbarSwappingConfig.Value && !GeneralImprovements_Compat.Enabled)
{
for (int i = 0; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Ldc_R4 && (float)list[i].operand == 0.3f)
{
list[i].operand = ConfigSettings.minSwapItemInterval;
break;
}
}
}
return list.AsEnumerable();
}
[HarmonyPatch(typeof(PlayerControllerB), "ActivateItem_performed")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> PatchActivateItemInterval(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
if (!ConfigSettings.disableFasterItemActivateConfig.Value && !GeneralImprovements_Compat.Enabled)
{
for (int i = 0; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Ldc_R4 && (float)list[i].operand == 0.075f)
{
list[i].operand = ConfigSettings.minActivateItemInterval;
break;
}
}
}
return list.AsEnumerable();
}
[HarmonyPatch(typeof(PlayerControllerB), "Discard_performed")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> PatchDiscardItemInterval(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
if (!ConfigSettings.disableFasterItemDroppingConfig.Value)
{
for (int i = 0; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Ldc_R4 && (float)list[i].operand == 0.2f)
{
list[i].operand = ConfigSettings.minDiscardItemInterval;
}
}
}
return list.AsEnumerable();
}
[HarmonyPatch(typeof(PlayerControllerB), "Interact_performed")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> PatchInteractInterval(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
if (!GeneralImprovements_Compat.Enabled)
{
for (int i = 0; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Ldc_R4 && (float)list[i].operand == 0.2f)
{
list[i].operand = ConfigSettings.minInteractInterval;
break;
}
}
}
return list.AsEnumerable();
}
[HarmonyPatch(typeof(PlayerControllerB), "PerformEmote")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> PatchPerformEmoteInterval(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 0; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Ldc_R4 && (float)list[i].operand == 0.5f)
{
list[i].operand = ConfigSettings.minUseEmoteInterval;
break;
}
}
return list.AsEnumerable();
}
[HarmonyPatch(typeof(PlayerControllerB), "ScrollMouse_performed")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> InvertHotbarScrollDirection(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
if (ConfigSettings.invertHotbarScrollDirectionConfig.Value)
{
for (int i = 1; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Ble_Un && list[i - 1].opcode == OpCodes.Ldc_R4 && (float)list[i - 1].operand == 0f)
{
list[i].opcode = OpCodes.Bge_Un;
break;
}
}
}
return list.AsEnumerable();
}
}
[HarmonyPatch]
public class QuickDrop
{
public static float timeDroppedItem;
public static bool droppingItem = false;
private static float timeLoggedPreventedItemSwap = 0f;
private static HashSet<int> checkedSlots = new HashSet<int>();
public static PlayerControllerB localPlayerController => StartOfRound.Instance?.localPlayerController;
[HarmonyPatch(typeof(PlayerControllerB), "DiscardHeldObject")]
[HarmonyPostfix]
private static void PerformQuickDiscard(PlayerControllerB __instance)
{
if (droppingItem || (Object)(object)__instance != (Object)(object)localPlayerController || !ConfigSettings.useItemQuickDropConfig.Value || !SyncManager.isSynced || (ReservedItemSlots_Compat.Enabled && ReservedItemSlots_Compat.IsItemSlotReserved(localPlayerController.currentItemSlot)))
{
return;
}
checkedSlots.Clear();
int num = PlayerPatcher.CallGetNextItemSlot(__instance, forward: true, __instance.currentItemSlot);
while (num != __instance.currentItemSlot && !checkedSlots.Contains(num))
{
checkedSlots.Add(num);
GrabbableObject val = __instance.ItemSlots[num];
if ((Object)(object)val != (Object)null)
{
break;
}
num = PlayerPatcher.CallGetNextItemSlot(__instance, forward: true, num);
}
if (num != __instance.currentItemSlot && num >= 0 && num < __instance.ItemSlots.Length)
{
Plugin.Log("On discard item. Auto swapping to held item at slot: " + num + ". Prev slot: " + __instance.currentItemSlot);
droppingItem = true;
localPlayerController.playerBodyAnimator.SetBool("cancelGrab", false);
PlayerPatcher.SetTimeSinceSwitchingSlots(__instance, 0f);
__instance.playerBodyAnimator.ResetTrigger("SwitchHoldAnimation");
((MonoBehaviour)__instance).StartCoroutine(SwitchToItemSlotAfterDelay(__instance, num));
}
}
private static IEnumerator SwitchToItemSlotAfterDelay(PlayerControllerB __instance, int slot)
{
int oldSlot = __instance.currentItemSlot;
yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)__instance.currentlyHeldObjectServer == (Object)null || __instance.currentItemSlot != oldSlot));
if (__instance.currentItemSlot == oldSlot)
{
SyncManager.SwapHotbarSlot(slot);
}
else
{
Plugin.LogWarning("Failed to perform item quick drop. Current selected item slot was updated before drop animation could complete. (this is okay)");
}
droppingItem = false;
}
[HarmonyPatch(typeof(PlayerControllerB), "ScrollMouse_performed")]
[HarmonyPrefix]
private static bool PreventItemSwappingDroppingItem(CallbackContext context, PlayerControllerB __instance)
{
if ((Object)(object)__instance == (Object)(object)localPlayerController && droppingItem)
{
float time = Time.time;
if (time - timeLoggedPreventedItemSwap > 1f)
{
timeLoggedPreventedItemSwap = time;
Plugin.LogWarning("[VERBOSE] Prevented item swap. Player is currently discarding an item? This should be fine, unless these logs are spamming.");
}
return false;
}
return true;
}
}
}
namespace HotbarPlus.Input
{
internal class InputUtilsCompat
{
internal static InputActionAsset Asset => IngameKeybinds.GetAsset();
internal static bool Enabled => Plugin.IsModLoaded("com.rune580.LethalCompanyInputUtils");
public static InputAction QuickHotbarSlotHotkey1 => IngameKeybinds.Instance.QuickHotbarSlotHotkey1;
public static InputAction QuickHotbarSlotHotkey2 => IngameKeybinds.Instance.QuickHotbarSlotHotkey2;
public static InputAction QuickHotbarSlotHotkey3 => IngameKeybinds.Instance.QuickHotbarSlotHotkey3;
public static InputAction QuickHotbarSlotHotkey4 => IngameKeybinds.Instance.QuickHotbarSlotHotkey4;
public static InputAction QuickHotbarSlotHotkey5 => IngameKeybinds.Instance.QuickHotbarSlotHotkey5;
public static InputAction QuickHotbarSlotHotkey6 => IngameKeybinds.Instance.QuickHotbarSlotHotkey6;
public static InputAction QuickHotbarSlotHotkey7 => IngameKeybinds.Instance.QuickHotbarSlotHotkey7;
public static InputAction QuickHotbarSlotHotkey8 => IngameKeybinds.Instance.QuickHotbarSlotHotkey8;
}
internal class IngameKeybinds : LcInputActions
{
internal static IngameKeybinds Instance = new IngameKeybinds();
[InputAction("<Keyboard>/1", Name = "[HB+] Quick Slot 1")]
public InputAction QuickHotbarSlotHotkey1 { get; set; }
[InputAction("<Keyboard>/2", Name = "[HB+] Quick Slot 2")]
public InputAction QuickHotbarSlotHotkey2 { get; set; }
[InputAction("<Keyboard>/3", Name = "[HB+] Quick Slot 3")]
public InputAction QuickHotbarSlotHotkey3 { get; set; }
[InputAction("<Keyboard>/4", Name = "[HB+] Quick Slot 4")]
public InputAction QuickHotbarSlotHotkey4 { get; set; }
[InputAction("<Keyboard>/5", Name = "[HB+] Quick Slot 5")]
public InputAction QuickHotbarSlotHotkey5 { get; set; }
[InputAction("<Keyboard>/6", Name = "[HB+] Quick Slot 6")]
public InputAction QuickHotbarSlotHotkey6 { get; set; }
[InputAction("<Keyboard>/7", Name = "[HB+] Quick Slot 7")]
public InputAction QuickHotbarSlotHotkey7 { get; set; }
[InputAction("<Keyboard>/8", Name = "[HB+] Quick Slot 8")]
public InputAction QuickHotbarSlotHotkey8 { get; set; }
internal static InputActionAsset GetAsset()
{
return ((LcInputActions)Instance).Asset;
}
}
[HarmonyPatch]
public class Keybinds
{
private static bool setHotbarSize;
public static InputActionAsset Asset;
public static InputActionMap ActionMap;
public static InputAction quickHotbarSlotHotkey1;
public static InputAction quickHotbarSlotHotkey2;
public static InputAction quickHotbarSlotHotkey3;
public static InputAction quickHotbarSlotHotkey4;
public static InputAction quickHotbarSlotHotkey5;
public static InputAction quickHotbarSlotHotkey6;
public static InputAction quickHotbarSlotHotkey7;
public static InputAction quickHotbarSlotHotkey8;
private static PlayerControllerB localPlayerController => StartOfRound.Instance?.localPlayerController;
public static void InitKeybinds()
{
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Expected O, but got Unknown
setHotbarSize = false;
if (ConfigSettings.useHotbarNumberHotkeysConfig.Value)
{
if (InputUtilsCompat.Enabled)
{
Asset = InputUtilsCompat.Asset;
quickHotbarSlotHotkey1 = InputUtilsCompat.QuickHotbarSlotHotkey1;
quickHotbarSlotHotkey2 = InputUtilsCompat.QuickHotbarSlotHotkey2;
quickHotbarSlotHotkey3 = InputUtilsCompat.QuickHotbarSlotHotkey3;
quickHotbarSlotHotkey4 = InputUtilsCompat.QuickHotbarSlotHotkey4;
quickHotbarSlotHotkey5 = InputUtilsCompat.QuickHotbarSlotHotkey5;
quickHotbarSlotHotkey6 = InputUtilsCompat.QuickHotbarSlotHotkey6;
quickHotbarSlotHotkey7 = InputUtilsCompat.QuickHotbarSlotHotkey7;
quickHotbarSlotHotkey8 = InputUtilsCompat.QuickHotbarSlotHotkey8;
}
else
{
Asset = ScriptableObject.CreateInstance<InputActionAsset>();
ActionMap = new InputActionMap("HotbarPlus");
InputActionSetupExtensions.AddActionMap(Asset, ActionMap);
quickHotbarSlotHotkey1 = InputActionSetupExtensions.AddAction(ActionMap, "[HB+] Quick Slot 1", (InputActionType)0, "<Keyboard>/1", "Press", (string)null, (string)null, (string)null);
quickHotbarSlotHotkey2 = InputActionSetupExtensions.AddAction(ActionMap, "[HB+] Quick Slot 2", (InputActionType)0, "<Keyboard>/2", "Press", (string)null, (string)null, (string)null);
quickHotbarSlotHotkey3 = InputActionSetupExtensions.AddAction(ActionMap, "[HB+] Quick Slot 3", (InputActionType)0, "<Keyboard>/3", "Press", (string)null, (string)null, (string)null);
quickHotbarSlotHotkey4 = InputActionSetupExtensions.AddAction(ActionMap, "[HB+] Quick Slot 4", (InputActionType)0, "<Keyboard>/4", "Press", (string)null, (string)null, (string)null);
quickHotbarSlotHotkey5 = InputActionSetupExtensions.AddAction(ActionMap, "[HB+] Quick Slot 5", (InputActionType)0, "<Keyboard>/5", "Press", (string)null, (string)null, (string)null);
quickHotbarSlotHotkey6 = InputActionSetupExtensions.AddAction(ActionMap, "[HB+] Quick Slot 6", (InputActionType)0, "<Keyboard>/6", "Press", (string)null, (string)null, (string)null);
quickHotbarSlotHotkey7 = InputActionSetupExtensions.AddAction(ActionMap, "[HB+] Quick Slot 7", (InputActionType)0, "<Keyboard>/7", "Press", (string)null, (string)null, (string)null);
quickHotbarSlotHotkey8 = InputActionSetupExtensions.AddAction(ActionMap, "[HB+] Quick Slot 8", (InputActionType)0, "<Keyboard>/8", "Press", (string)null, (string)null, (string)null);
}
}
}
public static void OnSetHotbarSize()
{
setHotbarSize = true;
}
[HarmonyPatch(typeof(StartOfRound), "OnEnable")]
[HarmonyPostfix]
public static void OnEnable()
{
if (ConfigSettings.useHotbarNumberHotkeysConfig.Value)
{
Asset.Enable();
quickHotbarSlotHotkey1.performed += OnPressItemSlotHotkeyAction1;
quickHotbarSlotHotkey2.performed += OnPressItemSlotHotkeyAction2;
quickHotbarSlotHotkey3.performed += OnPressItemSlotHotkeyAction3;
quickHotbarSlotHotkey4.performed += OnPressItemSlotHotkeyAction4;
quickHotbarSlotHotkey5.performed += OnPressItemSlotHotkeyAction5;
quickHotbarSlotHotkey6.performed += OnPressItemSlotHotkeyAction6;
quickHotbarSlotHotkey7.performed += OnPressItemSlotHotkeyAction7;
quickHotbarSlotHotkey8.performed += OnPressItemSlotHotkeyAction8;
}
}
[HarmonyPatch(typeof(StartOfRound), "OnDisable")]
[HarmonyPostfix]
public static void OnDisable()
{
if (ConfigSettings.useHotbarNumberHotkeysConfig.Value)
{
Asset.Disable();
quickHotbarSlotHotkey1.performed -= OnPressItemSlotHotkeyAction1;
quickHotbarSlotHotkey2.performed -= OnPressItemSlotHotkeyAction2;
quickHotbarSlotHotkey3.performed -= OnPressItemSlotHotkeyAction3;
quickHotbarSlotHotkey4.performed -= OnPressItemSlotHotkeyAction4;
quickHotbarSlotHotkey5.performed -= OnPressItemSlotHotkeyAction5;
quickHotbarSlotHotkey6.performed -= OnPressItemSlotHotkeyAction6;
quickHotbarSlotHotkey7.performed -= OnPressItemSlotHotkeyAction7;
quickHotbarSlotHotkey8.performed -= OnPressItemSlotHotkeyAction8;
}
}
private static void OnPressItemSlotHotkeyAction1(CallbackContext context)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
OnPressItemSlotHotkeyAction(context, 0);
}
private static void OnPressItemSlotHotkeyAction2(CallbackContext context)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
OnPressItemSlotHotkeyAction(context, 1);
}
private static void OnPressItemSlotHotkeyAction3(CallbackContext context)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
OnPressItemSlotHotkeyAction(context, 2);
}
private static void OnPressItemSlotHotkeyAction4(CallbackContext context)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
OnPressItemSlotHotkeyAction(context, 3);
}
private static void OnPressItemSlotHotkeyAction5(CallbackContext context)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
OnPressItemSlotHotkeyAction(context, 4);
}
private static void OnPressItemSlotHotkeyAction6(CallbackContext context)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
OnPressItemSlotHotkeyAction(context, 5);
}
private static void OnPressItemSlotHotkeyAction7(CallbackContext context)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
OnPressItemSlotHotkeyAction(context, 6);
}
private static void OnPressItemSlotHotkeyAction8(CallbackContext context)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
OnPressItemSlotHotkeyAction(context, 7);
}
private static void OnPressItemSlotHotkeyAction(CallbackContext context, int slot)
{
if (!((Object)(object)localPlayerController == (Object)null) && ((NetworkBehaviour)localPlayerController).IsOwner && localPlayerController.isPlayerControlled && SyncManager.isSynced && ((CallbackContext)(ref context)).performed && ConfigSettings.useHotbarNumberHotkeysConfig.Value && setHotbarSize && slot >= 0 && slot < SyncManager.currentHotbarSize && !(bool)Traverse.Create((object)localPlayerController).Field("throwingObject").GetValue() && !localPlayerController.isTypingChat && !localPlayerController.inTerminalMenu && !localPlayerController.quickMenuManager.isMenuOpen && !localPlayerController.isPlayerDead && !localPlayerController.isGrabbingObjectAnimation && !localPlayerController.activatingItem && !localPlayerController.inSpecialInteractAnimation && !localPlayerController.twoHanded && !localPlayerController.jetpackControls && !localPlayerController.disablingJetpackControls && !(PlayerPatcher.GetTimeSinceSwitchingSlots(localPlayerController) < ((!ConfigSettings.disableFasterHotbarSwappingConfig.Value) ? ConfigSettings.minSwapItemInterval : 0.3f)))
{
SyncManager.SwapHotbarSlot(slot);
}
}
}
}
namespace HotbarPlus.Config
{
public static class ConfigSettings
{
public static ConfigEntry<int> hotbarSizeConfig;
public static ConfigEntry<int> purchasableHotbarSlotsConfig;
public static ConfigEntry<int> purchasableHotbarSlotsPriceConfig;
public static ConfigEntry<int> purchasableHotbarSlotsPriceIncreaseConfig;
public static ConfigEntry<bool> useHotbarNumberHotkeysConfig;
public static ConfigEntry<bool> invertHotbarScrollDirectionConfig;
public static ConfigEntry<bool> useItemQuickDropConfig;
public static ConfigEntry<bool> disableFasterHotbarSwappingConfig;
public static ConfigEntry<bool> disableFasterItemDroppingConfig;
public static ConfigEntry<bool> disableFasterItemActivateConfig;
public static ConfigEntry<bool> applyFormattingToReservedItemSlotsConfig;
public static ConfigEntry<bool> disableEnergyBarsConfig;
public static ConfigEntry<bool> disableItemStaticWarningsConfig;
public static ConfigEntry<int> overrideHotbarSpacingConfig;
public static ConfigEntry<float> overrideFadeHudAlphaConfig;
public static ConfigEntry<float> overrideHotbarHudSizeConfig;
public static ConfigEntry<bool> verboseLogs;
public static Dictionary<string, ConfigEntryBase> currentConfigEntries = new Dictionary<string, ConfigEntryBase>();
public static float minSwapItemInterval = 0.05f;
public static float minActivateItemInterval = 0.05f;
public static float minDiscardItemInterval = 0.05f;
public static float minInteractInterval = 0.05f;
public static float minUseEmoteInterval = 0.25f;
public static List<ConfigEntryBase> configEntries = new List<ConfigEntryBase>();
public static void BindConfigSettings()
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Expected O, but got Unknown
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Expected O, but got Unknown
//IL_0249: Unknown result type (might be due to invalid IL or missing references)
//IL_0253: Expected O, but got Unknown
//IL_028f: Unknown result type (might be due to invalid IL or missing references)
//IL_0299: Expected O, but got Unknown
//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
//IL_02df: Expected O, but got Unknown
Plugin.Log("BindingConfigs");
hotbarSizeConfig = AddConfigEntry<int>(((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("Server-side", "NumHotbarSlots", 4, new ConfigDescription("[Host only] The amount of hotbar slots player will have. This will sync with other clients who have the mod.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 20), Array.Empty<object>())));
purchasableHotbarSlotsConfig = AddConfigEntry<int>(((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("Server-side", "PurchasableHotbarSlots", 0, new ConfigDescription("[Host only] The amount of hotbar slots that can be purchased", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>())));
purchasableHotbarSlotsPriceConfig = AddConfigEntry<int>(((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("Server-side", "PurchasableHotbarSlotsPrice", 200, "[Host only] The price of purchasing a hotbar slot."));
purchasableHotbarSlotsPriceIncreaseConfig = AddConfigEntry<int>(((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("Server-side", "PurchasableHotbarSlotsPriceIncrease", 100, "[Host only] The price increase on hotbar slots after each purchase."));
useHotbarNumberHotkeysConfig = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Client-side", "UseHotbarNumberHotkeys", true, "Use the quick item selection numerical hotkeys."));
invertHotbarScrollDirectionConfig = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Client-side", "InvertHotbarScrollDirection", true, "Inverts the direction in which you scroll on the hotbar. Will not affect the terminal scrolling direction."));
useItemQuickDropConfig = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Client-side", "UseItemQuickDropConfig", true, "If enabled, dropping an item will automatically swap to the next item for easier chain dropping. This may not work if the host does not have the mod. This is for stability reasons, and to help reduce de-sync."));
disableFasterHotbarSwappingConfig = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Client-side", "UseDefaultItemSwapInterval", false, "If true, the interval (delay) between swapping items will not be reduced by this mod."));
disableFasterItemDroppingConfig = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Client-side", "UseDefaultItemDropInterval", false, "If true, the interval (delay) between dropping items will not be reduced by this mod."));
disableFasterItemActivateConfig = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Client-side", "UseDefaultItemActivateInterval", false, "If true, the interval (delay) between activating items will not be reduced by this mod."));
disableEnergyBarsConfig = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("UI", "DisableEnergyBars", false, "Disables/hides the energy bars for items in the HUD."));
disableItemStaticWarningsConfig = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("UI", "DisableItemStaticWarnings", false, "Disables the lightning indicator that appears over item slots of held metal items that are about to be struck with lightning."));
overrideHotbarSpacingConfig = AddConfigEntry<int>(((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("UI", "OverrideHotbarHudSpacing", 10, new ConfigDescription("The spacing between each hotbar slot UI element.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())));
overrideHotbarHudSizeConfig = AddConfigEntry<float>(((BaseUnityPlugin)Plugin.instance).Config.Bind<float>("UI", "OverrideHotbarHudSize", 1f, new ConfigDescription("Scales the hotbar slot HUD elements by a multiplier. HUD spacing/position should be scaled automatically.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 10f), Array.Empty<object>())));
overrideFadeHudAlphaConfig = AddConfigEntry<float>(((BaseUnityPlugin)Plugin.instance).Config.Bind<float>("UI", "OverrideFadeHudAlpha", 0.13f, new ConfigDescription("Sets the alpha for when the hotbar hud fades. Default = 0.13 | Fade completely: 0 | Never fade: 1", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())));
verboseLogs = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Other", "VerboseLogs", true, "If enabled, extra logs will be created for debugging. This may be useful for tracking down various issues."));
hotbarSizeConfig.Value = Mathf.Max(hotbarSizeConfig.Value, 0);
purchasableHotbarSlotsConfig.Value = Mathf.Max(purchasableHotbarSlotsConfig.Value, 0);
purchasableHotbarSlotsPriceConfig.Value = Mathf.Max(purchasableHotbarSlotsPriceConfig.Value, 1);
purchasableHotbarSlotsPriceIncreaseConfig.Value = Mathf.Max(purchasableHotbarSlotsPriceIncreaseConfig.Value, 0);
TryRemoveOldConfigSettings();
}
public static ConfigEntry<T> AddConfigEntry<T>(ConfigEntry<T> configEntry)
{
currentConfigEntries.Add(((ConfigEntryBase)configEntry).Definition.Key, (ConfigEntryBase)(object)configEntry);
return configEntry;
}
public static void TryRemoveOldConfigSettings()
{
HashSet<string> hashSet = new HashSet<string>();
HashSet<string> hashSet2 = new HashSet<string>();
foreach (ConfigEntryBase value in currentConfigEntries.Values)
{
hashSet.Add(value.Definition.Section);
hashSet2.Add(value.Definition.Key);
}
try
{
ConfigFile config = ((BaseUnityPlugin)Plugin.instance).Config;
string configFilePath = config.ConfigFilePath;
if (!File.Exists(configFilePath))
{
return;
}
string text = File.ReadAllText(configFilePath);
string[] array = File.ReadAllLines(configFilePath);
string text2 = "";
for (int i = 0; i < array.Length; i++)
{
array[i] = array[i].Replace("\n", "");
if (array[i].Length <= 0)
{
continue;
}
if (array[i].StartsWith("["))
{
if (text2 != "" && !hashSet.Contains(text2))
{
text2 = "[" + text2 + "]";
int num = text.IndexOf(text2);
int num2 = text.IndexOf(array[i]);
text = text.Remove(num, num2 - num);
}
text2 = array[i].Replace("[", "").Replace("]", "").Trim();
}
else
{
if (!(text2 != ""))
{
continue;
}
if (i <= array.Length - 4 && array[i].StartsWith("##"))
{
int j;
for (j = 1; i + j < array.Length && array[i + j].Length > 3; j++)
{
}
if (hashSet.Contains(text2))
{
int num3 = array[i + j - 1].IndexOf("=");
string item = array[i + j - 1].Substring(0, num3 - 1);
if (!hashSet2.Contains(item))
{
int num4 = text.IndexOf(array[i]);
int num5 = text.IndexOf(array[i + j - 1]) + array[i + j - 1].Length;
text = text.Remove(num4, num5 - num4);
}
}
i += j - 1;
}
else if (array[i].Length > 3)
{
text = text.Replace(array[i], "");
}
}
}
if (!hashSet.Contains(text2))
{
text2 = "[" + text2 + "]";
int num6 = text.IndexOf(text2);
text = text.Remove(num6, text.Length - num6);
}
while (text.Contains("\n\n\n"))
{
text = text.Replace("\n\n\n", "\n\n");
}
File.WriteAllText(configFilePath, text);
config.Reload();
}
catch
{
}
}
}
}
namespace HotbarPlus.Compatibility
{
internal static class GeneralImprovements_Compat
{
public static bool Enabled => Plugin.IsModLoaded("ShaosilGaming.GeneralImprovements");
}
internal static class ReservedItemSlots_Compat
{
public static bool Enabled => Plugin.IsModLoaded("FlipMods.ReservedItemSlotCore");
public static bool IsToggledInReservedItemSlots()
{
if (!Enabled)
{
return false;
}
return ReservedHotbarManager.isToggledInReservedSlots;
}
public static bool IsItemSlotReserved(int index)
{
if (!Enabled)
{
return false;
}
return ReservedPlayerData.localPlayerData.IsReservedItemSlot(index);
}
public static bool ShouldDisableEnergyBarsReservedItemSlots()
{
if (!Enabled)
{
return false;
}
try
{
return ConfigSettings.disableHotbarPlusEnergyBars.Value;
}
catch
{
return false;
}
}
}
internal static class TooManyEmotes_Compat
{
public static bool Enabled => Plugin.IsModLoaded("FlipMods.TooManyEmotes");
public static bool IsLocalPlayerPerformingCustomEmote()
{
if ((Object)(object)EmoteControllerPlayer.emoteControllerLocal != (Object)null && ((EmoteController)EmoteControllerPlayer.emoteControllerLocal).IsPerformingCustomEmote())
{
return true;
}
return false;
}
public static bool CanMoveWhileEmoting()
{
return ThirdPersonEmoteController.allowMovingWhileEmoting;
}
}
}