using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UIElements;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("Joive")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Configurable player inventory slots for Burglin Gnomes.")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0")]
[assembly: AssemblyProduct("BG Inventory QoL")]
[assembly: AssemblyTitle("BG-InventoryQoL-Joive")]
[assembly: AssemblyVersion("1.3.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace Joive.BurglinGnomes.Inventory
{
[BepInPlugin("joive.bg.inventoryqol", "BG Inventory QoL", "1.3.0")]
public sealed class InventoryQoLPlugin : BaseUnityPlugin
{
private const string PluginGuid = "joive.bg.inventoryqol";
private const string PluginName = "BG Inventory QoL";
private const string PluginVersion = "1.3.0";
private const int VanillaEquipmentSlotCount = 2;
private const int EquipmentSlotCountWithBackpack = 3;
private const int EquipmentSlotCountWithExtra = 4;
private const int HatSlot = 0;
private const int BootsSlot = 1;
private const int BackpackSlot = 2;
private const int ExtraEquipmentSlot = 3;
private const int MaxTotalSlots = 40;
private const int MaxHotkeySlots = 10;
private const string DefaultExtraEquipmentKeywords = "glider,planer,plane,wing,wings,fairy,планер";
private static readonly Dictionary<EquipmentController, List<EquipmentUsageData<WearedEquipment>>> extraWearableHandlers = new Dictionary<EquipmentController, List<EquipmentUsageData<WearedEquipment>>>();
private static InventoryQoLPlugin instance;
private static ConfigEntry<string> configVersion;
private static ConfigEntry<bool> enableMod;
private static ConfigEntry<bool> useVanillaSlots;
private static ConfigEntry<int> baseExtraSlots;
private static ConfigEntry<int> backpackBonusSlots;
private static ConfigEntry<int> overrideBaseSlots;
private static ConfigEntry<int> overrideBackpackSlots;
private static ConfigEntry<bool> enableThreeEquipmentSlots;
private static ConfigEntry<bool> enableExtraEquipmentSlot;
private static ConfigEntry<bool> extraSlotAcceptsAnyWearable;
private static ConfigEntry<string> extraEquipmentKeywords;
private static ConfigEntry<bool> enableExtendedHotkeys;
private static ConfigEntry<bool> enableMouseWheelSelection;
private static ConfigEntry<bool> pauseGameInMenu;
private static ConfigEntry<KeyCode> menuKey;
private static ConfigEntry<bool> debugLogs;
private Harmony harmony;
private bool menuOpen;
private bool pauseApplied;
private float previousTimeScale = 1f;
private float nextPassiveApplyTime;
private string statusMessage = "Ready.";
private Rect windowRect = new Rect(90f, 70f, 760f, 560f);
private Vector2 menuScroll;
private GUIStyle windowStyle;
private GUIStyle headerStyle;
private GUIStyle labelStyle;
private GUIStyle smallLabelStyle;
private GUIStyle sectionStyle;
private GUIStyle sectionHeaderStyle;
private GUIStyle buttonStyle;
private GUIStyle activeButtonStyle;
internal static bool Enabled
{
get
{
if (enableMod != null)
{
return enableMod.Value;
}
return false;
}
}
internal static bool CustomSlotsEnabled
{
get
{
if (Enabled && useVanillaSlots != null)
{
return !useVanillaSlots.Value;
}
return false;
}
}
internal static bool ManagedInventoryEnabled
{
get
{
if (Enabled)
{
if (!CustomSlotsEnabled && !ThreeEquipmentSlotsEnabled)
{
return ExtraEquipmentSlotEnabled;
}
return true;
}
return false;
}
}
internal static bool ThreeEquipmentSlotsEnabled
{
get
{
if (Enabled && enableThreeEquipmentSlots != null)
{
return enableThreeEquipmentSlots.Value;
}
return false;
}
}
internal static bool ExtraEquipmentSlotEnabled
{
get
{
if (ThreeEquipmentSlotsEnabled && enableExtraEquipmentSlot != null)
{
return enableExtraEquipmentSlot.Value;
}
return false;
}
}
internal static bool ExtendedHotkeysEnabled
{
get
{
if (ManagedInventoryEnabled && enableExtendedHotkeys != null)
{
return enableExtendedHotkeys.Value;
}
return false;
}
}
internal static bool MouseWheelSelectionEnabled
{
get
{
if (ManagedInventoryEnabled && enableMouseWheelSelection != null)
{
return enableMouseWheelSelection.Value;
}
return false;
}
}
internal static int EquipmentSlotCount
{
get
{
if (!ExtraEquipmentSlotEnabled)
{
if (!ThreeEquipmentSlotsEnabled)
{
return 2;
}
return 3;
}
return 4;
}
}
private void Awake()
{
//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
//IL_02c0: Expected O, but got Unknown
instance = this;
configVersion = ((BaseUnityPlugin)this).Config.Bind<string>("General", "ConfigVersion", "", "Internal config version.");
enableMod = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableMod", true, "Enable inventory quality-of-life changes.");
useVanillaSlots = ((BaseUnityPlugin)this).Config.Bind<bool>("Inventory", "UseVanillaSlots", true, "Keep vanilla inventory sizes. Turn this off to use the options below.");
baseExtraSlots = ((BaseUnityPlugin)this).Config.Bind<int>("Inventory", "BaseExtraSlots", 0, "Extra slots added to the normal inventory.");
backpackBonusSlots = ((BaseUnityPlugin)this).Config.Bind<int>("Inventory", "BackpackBonusSlots", 0, "Extra slots added on top of the backpack's normal bonus.");
overrideBaseSlots = ((BaseUnityPlugin)this).Config.Bind<int>("Inventory", "OverrideBaseSlots", 0, "Exact total slots without backpack. 0 means automatic.");
overrideBackpackSlots = ((BaseUnityPlugin)this).Config.Bind<int>("Inventory", "OverrideBackpackSlots", 0, "Exact total slots with backpack. 0 means automatic.");
enableThreeEquipmentSlots = ((BaseUnityPlugin)this).Config.Bind<bool>("Equipment", "EnableThreeEquipmentSlots", true, "Use separate Hat, Boots, and Backpack equipment slots.");
enableExtraEquipmentSlot = ((BaseUnityPlugin)this).Config.Bind<bool>("Equipment", "EnableExtraEquipmentSlot", true, "Add a fourth equipment slot for glider-style wearable items.");
extraSlotAcceptsAnyWearable = ((BaseUnityPlugin)this).Config.Bind<bool>("Equipment", "ExtraSlotAcceptsAnyWearable", false, "Let the fourth equipment slot accept any wearable item that is not Hat, Boots, or Backpack.");
extraEquipmentKeywords = ((BaseUnityPlugin)this).Config.Bind<string>("Equipment", "ExtraEquipmentKeywords", "glider,planer,plane,wing,wings,fairy,планер", "Comma-separated item name parts that go into the fourth equipment slot.");
enableExtendedHotkeys = ((BaseUnityPlugin)this).Config.Bind<bool>("Controls", "EnableExtendedHotkeys", true, "Allow number keys 1-0 to select up to 10 hand slots.");
enableMouseWheelSelection = ((BaseUnityPlugin)this).Config.Bind<bool>("Controls", "EnableMouseWheelSelection", true, "Use the mouse wheel to cycle hand/item slots.");
pauseGameInMenu = ((BaseUnityPlugin)this).Config.Bind<bool>("Controls", "PauseGameInMenu", true, "Pause the local game while the Inventory QoL menu is open.");
menuKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "MenuKey", (KeyCode)290, "Open the BG Inventory QoL menu.");
debugLogs = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "DebugLogs", false, "Write inventory resize messages to BepInEx LogOutput.log.");
if (string.IsNullOrEmpty(configVersion.Value))
{
ResetToVanillaDefaults();
configVersion.Value = "1.3.0";
((BaseUnityPlugin)this).Config.Save();
}
else if (!string.Equals(configVersion.Value, "1.3.0", StringComparison.Ordinal))
{
enableThreeEquipmentSlots.Value = true;
enableExtraEquipmentSlot.Value = true;
if (string.IsNullOrWhiteSpace(extraEquipmentKeywords.Value))
{
extraEquipmentKeywords.Value = "glider,planer,plane,wing,wings,fairy,планер";
}
configVersion.Value = "1.3.0";
((BaseUnityPlugin)this).Config.Save();
}
ClampConfigValues();
harmony = new Harmony("joive.bg.inventoryqol");
harmony.PatchAll(typeof(InventoryQoLPlugin).Assembly);
((BaseUnityPlugin)this).Logger.LogInfo((object)"BG Inventory QoL 1.3.0 loaded.");
}
private void Update()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
if (Input.GetKeyDown(menuKey.Value))
{
SetMenuOpen(!menuOpen);
}
if (ManagedInventoryEnabled && Time.unscaledTime >= nextPassiveApplyTime)
{
nextPassiveApplyTime = Time.unscaledTime + 2f;
ApplyToAllPlayers();
}
HandleMouseWheelSelection();
}
private void OnGUI()
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
if (menuOpen)
{
EnsureStyles();
windowRect = GUI.Window(4724993, windowRect, new WindowFunction(DrawWindow), string.Empty, windowStyle);
}
}
private void OnDestroy()
{
RestorePause();
Harmony obj = harmony;
if (obj != null)
{
obj.UnpatchSelf();
}
if ((Object)(object)instance == (Object)(object)this)
{
instance = null;
}
}
private void SetMenuOpen(bool open)
{
menuOpen = open;
Cursor.visible = menuOpen;
Cursor.lockState = (CursorLockMode)(!menuOpen);
if (menuOpen && pauseGameInMenu.Value)
{
if (!pauseApplied)
{
previousTimeScale = Time.timeScale;
Time.timeScale = 0f;
pauseApplied = true;
}
}
else
{
RestorePause();
}
}
private void RestorePause()
{
if (pauseApplied)
{
Time.timeScale = ((previousTimeScale <= 0f) ? 1f : previousTimeScale);
pauseApplied = false;
}
}
private void DrawWindow(int id)
{
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: 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_0535: Unknown result type (might be due to invalid IL or missing references)
GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
GUILayout.Label("Inventory QoL", headerStyle, Array.Empty<GUILayoutOption>());
GUILayout.FlexibleSpace();
GUILayout.Label("Joive build", smallLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f) });
GUILayout.EndHorizontal();
GUILayout.Label("Small inventory changes that still feel like Burglin' Gnomes.", smallLabelStyle, Array.Empty<GUILayoutOption>());
GUILayout.Space(8f);
menuScroll = GUILayout.BeginScrollView(menuScroll, false, true, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(Mathf.Max(300f, ((Rect)(ref windowRect)).height - 118f)) });
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
if (GUILayout.Button("Vanilla", useVanillaSlots.Value ? activeButtonStyle : buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) }))
{
useVanillaSlots.Value = true;
SaveAndApply();
}
if (GUILayout.Button("Custom", (!useVanillaSlots.Value) ? activeButtonStyle : buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) }))
{
useVanillaSlots.Value = false;
SaveAndApply();
}
GUILayout.EndHorizontal();
GUILayout.Space(8f);
GUILayout.BeginVertical(sectionStyle, Array.Empty<GUILayoutOption>());
GUILayout.Label("Quick add", sectionHeaderStyle, Array.Empty<GUILayoutOption>());
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
if (GUILayout.Button("+1 slot now", activeButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(42f) }))
{
AddLocalSlot(1);
}
if (GUILayout.Button("-1", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Width(72f),
GUILayout.Height(42f)
}))
{
AddLocalSlot(-1);
}
if (GUILayout.Button("Apply", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Width(110f),
GUILayout.Height(42f)
}))
{
SaveAndApply();
statusMessage = "Applied.";
}
GUILayout.EndHorizontal();
GUILayout.Label(GetLiveInventoryText(), smallLabelStyle, Array.Empty<GUILayoutOption>());
GUILayout.Label(statusMessage, smallLabelStyle, Array.Empty<GUILayoutOption>());
GUILayout.EndVertical();
GUILayout.Space(8f);
GUILayout.BeginVertical(sectionStyle, Array.Empty<GUILayoutOption>());
DrawToggle("Mod enabled", enableMod);
DrawToggle("Hotbar keys 1-0", enableExtendedHotkeys);
DrawToggle("Mouse wheel hotbar", enableMouseWheelSelection);
DrawToggle("Pause while open", pauseGameInMenu);
GUILayout.EndVertical();
GUILayout.Space(8f);
GUILayout.BeginVertical(sectionStyle, Array.Empty<GUILayoutOption>());
GUILayout.Label("Equipment slots", sectionHeaderStyle, Array.Empty<GUILayoutOption>());
DrawToggle("Hat / Boots / Backpack", enableThreeEquipmentSlots);
DrawToggle("Extra glider slot", enableExtraEquipmentSlot);
DrawToggle("Extra accepts any wearable", extraSlotAcceptsAnyWearable);
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
GUILayout.Label("Extra item names", labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(250f) });
string text = GUILayout.TextField(extraEquipmentKeywords.Value ?? string.Empty, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) });
if (!string.Equals(text, extraEquipmentKeywords.Value, StringComparison.Ordinal))
{
extraEquipmentKeywords.Value = text;
}
GUILayout.EndHorizontal();
GUILayout.Label(GetEquipmentSummaryText(), smallLabelStyle, Array.Empty<GUILayoutOption>());
GUILayout.EndVertical();
GUILayout.Space(8f);
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
if (GUILayout.Button("Apply now", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
{
SaveAndApply();
}
if (GUILayout.Button("Vanilla", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
{
useVanillaSlots.Value = true;
baseExtraSlots.Value = 0;
backpackBonusSlots.Value = 0;
overrideBaseSlots.Value = 0;
overrideBackpackSlots.Value = 0;
enableThreeEquipmentSlots.Value = true;
enableExtraEquipmentSlot.Value = true;
extraSlotAcceptsAnyWearable.Value = false;
extraEquipmentKeywords.Value = "glider,planer,plane,wing,wings,fairy,планер";
SaveAndApply();
statusMessage = "Vanilla inventory settings restored.";
}
if (GUILayout.Button("Close", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
{
SetMenuOpen(open: false);
}
GUILayout.EndHorizontal();
GUILayout.Space(8f);
GUILayout.Label(GetSummaryText(), smallLabelStyle, Array.Empty<GUILayoutOption>());
GUILayout.Label("F9 opens this menu. Mouse wheel cycles item slots; 1-0 still works for the first 10.", smallLabelStyle, Array.Empty<GUILayoutOption>());
GUILayout.Label("Support: https://ko-fi.com/joive", smallLabelStyle, Array.Empty<GUILayoutOption>());
GUILayout.EndScrollView();
GUILayout.EndVertical();
GUI.DragWindow(new Rect(0f, 0f, 10000f, 42f));
}
private void DrawToggle(string text, ConfigEntry<bool> entry)
{
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
GUILayout.Label(text, labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(250f) });
if (GUILayout.Button(entry.Value ? "ON" : "OFF", entry.Value ? activeButtonStyle : buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Width(90f),
GUILayout.Height(26f)
}))
{
entry.Value = !entry.Value;
SaveAndApply();
}
GUILayout.EndHorizontal();
}
private void SaveAndApply()
{
ClampConfigValues();
configVersion.Value = "1.3.0";
((BaseUnityPlugin)this).Config.Save();
if (!pauseGameInMenu.Value)
{
RestorePause();
}
ApplyToAllPlayers();
}
private void AddLocalSlot(int delta)
{
PlayerInventory val = FindLocalInventory();
if ((Object)(object)val == (Object)null)
{
statusMessage = "Local inventory was not found yet. Join a round first.";
return;
}
if (!((NetworkBehaviour)val).IsServer)
{
statusMessage = "Only the host can change inventory size.";
return;
}
useVanillaSlots.Value = false;
bool flag = HasBackpackEquipped(val);
int slotCount = ((InventoryBase)val).SlotCount;
int num = ClampTotalSlots(slotCount + delta);
if (num == slotCount)
{
statusMessage = "Slot count is already at the limit.";
return;
}
if (flag)
{
overrideBackpackSlots.Value = num;
}
else
{
overrideBaseSlots.Value = num;
}
((InventoryBase)val).ResizeInventory(num);
((BaseUnityPlugin)this).Config.Save();
RefreshLocalEquipment(val);
statusMessage = "Inventory slots: " + slotCount + " -> " + num + ".";
Log(statusMessage);
}
private void HandleMouseWheelSelection()
{
//IL_000f: 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_0033: Invalid comparison between Unknown and I4
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
if (!MouseWheelSelectionEnabled || menuOpen || Mathf.Abs(Input.mouseScrollDelta.y) < 0.01f || (Cursor.visible && (int)Cursor.lockState != 1))
{
return;
}
PlayerInventory val = FindLocalInventory();
if ((Object)(object)val == (Object)null)
{
return;
}
EquipmentController component = ((Component)val).GetComponent<EquipmentController>();
if ((Object)(object)component == (Object)null)
{
return;
}
int num = Mathf.Max(0, ((InventoryBase)val).SlotCount - EquipmentSlotCount);
if (num > 0)
{
int num2 = ((!(Input.mouseScrollDelta.y > 0f)) ? 1 : (-1));
int activeSelectedItemSlot = component.ActiveSelectedItemSlot;
int num3 = (((activeSelectedItemSlot >= 0) ? activeSelectedItemSlot : ((num2 > 0) ? (-1) : 0)) + num2) % num;
if (num3 < 0)
{
num3 += num;
}
component.SetActiveHandSlot(num3);
}
}
private string GetLiveInventoryText()
{
PlayerInventory val = FindLocalInventory();
if ((Object)(object)val == (Object)null)
{
return "Current inventory: not found yet.";
}
string text = (((NetworkBehaviour)val).IsServer ? "host" : "client");
string text2 = (HasBackpackEquipped(val) ? "backpack on" : "no backpack");
return "Current slots: " + ((InventoryBase)val).SlotCount + " | " + text2 + " | " + text + ".";
}
private string GetSummaryText()
{
string obj = (useVanillaSlots.Value ? "Vanilla mode: custom values are saved but inactive." : "Custom mode: active.");
string text = (ExtraEquipmentSlotEnabled ? "Hat, boots, backpack, and extra equipment slots are active." : (ThreeEquipmentSlotsEnabled ? "Hat, boots, and backpack slots are active." : "Equipment slots stay vanilla."));
return obj + " " + text;
}
private string GetEquipmentSummaryText()
{
if (!ThreeEquipmentSlotsEnabled)
{
return "Vanilla: two wearable slots.";
}
if (!ExtraEquipmentSlotEnabled)
{
return "Active: Hat, Boots, Backpack. Normal item slots start after those.";
}
string text = (extraSlotAcceptsAnyWearable.Value ? "The extra slot accepts any other wearable." : "The extra slot uses the item name list above.");
return "Active: Hat, Boots, Backpack, Extra. " + text;
}
private void EnsureStyles()
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Expected O, but got Unknown
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: 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_0079: 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_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Expected O, but got Unknown
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Expected O, but got Unknown
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Expected O, but got Unknown
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_0146: Expected O, but got Unknown
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
//IL_014b: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Expected O, but got Unknown
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Expected O, but got Unknown
//IL_018e: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
//IL_01c6: Expected O, but got Unknown
//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
//IL_01de: Unknown result type (might be due to invalid IL or missing references)
//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0217: Unknown result type (might be due to invalid IL or missing references)
//IL_0226: Unknown result type (might be due to invalid IL or missing references)
//IL_022c: Unknown result type (might be due to invalid IL or missing references)
//IL_0236: Unknown result type (might be due to invalid IL or missing references)
//IL_0250: Unknown result type (might be due to invalid IL or missing references)
//IL_025f: Unknown result type (might be due to invalid IL or missing references)
//IL_0265: Unknown result type (might be due to invalid IL or missing references)
//IL_026f: Unknown result type (might be due to invalid IL or missing references)
//IL_0289: Unknown result type (might be due to invalid IL or missing references)
//IL_029d: Expected O, but got Unknown
//IL_02a4: 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_02af: Unknown result type (might be due to invalid IL or missing references)
//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
//IL_02e7: Expected O, but got Unknown
if (windowStyle == null)
{
GUIStyle val = new GUIStyle(GUI.skin.window)
{
padding = new RectOffset(22, 22, 18, 18)
};
val.normal.background = MakeTex(new Color(0.045f, 0.028f, 0.016f, 0.94f));
windowStyle = val;
GUIStyle val2 = new GUIStyle(GUI.skin.label)
{
fontSize = 24,
fontStyle = (FontStyle)1,
alignment = (TextAnchor)3
};
val2.normal.textColor = new Color(1f, 0.7f, 0.22f);
headerStyle = val2;
GUIStyle val3 = new GUIStyle(GUI.skin.label)
{
fontSize = 13
};
val3.normal.textColor = new Color(1f, 0.88f, 0.62f);
labelStyle = val3;
GUIStyle val4 = new GUIStyle(GUI.skin.label)
{
fontSize = 11,
wordWrap = true
};
val4.normal.textColor = new Color(0.8f, 0.61f, 0.36f);
smallLabelStyle = val4;
GUIStyle val5 = new GUIStyle(GUI.skin.box)
{
padding = new RectOffset(12, 12, 10, 10),
margin = new RectOffset(0, 0, 2, 2)
};
val5.normal.background = MakeTex(new Color(0.13f, 0.065f, 0.032f, 0.88f));
sectionStyle = val5;
GUIStyle val6 = new GUIStyle(GUI.skin.label)
{
fontSize = 13,
fontStyle = (FontStyle)1
};
val6.normal.textColor = new Color(1f, 0.27f, 0.08f);
sectionHeaderStyle = val6;
GUIStyle val7 = new GUIStyle(GUI.skin.button)
{
fontSize = 12
};
val7.normal.textColor = new Color(0.97f, 0.82f, 0.55f);
val7.normal.background = MakeTex(new Color(0.22f, 0.1f, 0.045f, 1f));
val7.hover.textColor = Color.white;
val7.hover.background = MakeTex(new Color(0.43f, 0.18f, 0.055f, 1f));
val7.active.textColor = Color.white;
val7.active.background = MakeTex(new Color(0.58f, 0.22f, 0.045f, 1f));
buttonStyle = val7;
GUIStyle val8 = new GUIStyle(buttonStyle);
val8.normal.textColor = Color.white;
val8.normal.background = MakeTex(new Color(0.78f, 0.3f, 0.055f, 1f));
activeButtonStyle = val8;
}
}
private static Texture2D MakeTex(Color color)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
Texture2D val = new Texture2D(1, 1);
val.SetPixel(0, 0, color);
val.Apply();
return val;
}
internal static int WantedUiSlots(PlayerInventory inventory)
{
if (!ManagedInventoryEnabled)
{
return 0;
}
return GetTargetSlotCount(inventory);
}
internal static int GetTargetSlotCount(PlayerInventory inventory)
{
return GetTargetSlotCount(inventory, HasBackpackEquipped(inventory));
}
internal static int GetTargetSlotCount(PlayerInventory inventory, bool hasBackpack)
{
if ((Object)(object)inventory == (Object)null)
{
return 0;
}
int num = EquipmentSlotCount - 2;
int num2 = Mathf.Max(2, ((InventoryBase)inventory).InitialSlotCount) + num;
int num3 = Mathf.Max(num2, GetVanillaBackpackSlots(inventory) + num);
int num4 = Mathf.Max(0, num3 - num2);
int value = ((overrideBaseSlots.Value > 0) ? overrideBaseSlots.Value : (num2 + (CustomSlotsEnabled ? baseExtraSlots.Value : 0)));
value = ClampTotalSlots(value);
if (!hasBackpack)
{
return Mathf.Max(value, EquipmentSlotCount + 1);
}
return Mathf.Max(ClampTotalSlots((overrideBackpackSlots.Value > 0) ? overrideBackpackSlots.Value : (value + num4 + (CustomSlotsEnabled ? backpackBonusSlots.Value : 0))), EquipmentSlotCount + 1);
}
internal static int GetVanillaBackpackSlots(PlayerInventory inventory)
{
try
{
return (int)(AccessTools.Field(typeof(PlayerInventory), "inventorySizeWithBackpack")?.GetValue(inventory) ?? ((object)((InventoryBase)inventory).InitialSlotCount));
}
catch
{
return ((Object)(object)inventory != (Object)null) ? ((InventoryBase)inventory).InitialSlotCount : 0;
}
}
internal static int ClampTotalSlots(int value)
{
return Mathf.Clamp(value, EquipmentSlotCount, 40);
}
internal static void ClampConfigValues()
{
baseExtraSlots.Value = Mathf.Clamp(baseExtraSlots.Value, -10, 30);
backpackBonusSlots.Value = Mathf.Clamp(backpackBonusSlots.Value, -10, 30);
overrideBaseSlots.Value = Mathf.Clamp(overrideBaseSlots.Value, 0, 40);
overrideBackpackSlots.Value = Mathf.Clamp(overrideBackpackSlots.Value, 0, 40);
if (string.IsNullOrWhiteSpace(extraEquipmentKeywords.Value))
{
extraEquipmentKeywords.Value = "glider,planer,plane,wing,wings,fairy,планер";
}
}
internal static void ResetToVanillaDefaults()
{
useVanillaSlots.Value = true;
baseExtraSlots.Value = 0;
backpackBonusSlots.Value = 0;
overrideBaseSlots.Value = 0;
overrideBackpackSlots.Value = 0;
enableThreeEquipmentSlots.Value = true;
enableExtraEquipmentSlot.Value = true;
extraSlotAcceptsAnyWearable.Value = false;
extraEquipmentKeywords.Value = "glider,planer,plane,wing,wings,fairy,планер";
enableExtendedHotkeys.Value = true;
enableMouseWheelSelection.Value = true;
}
internal static void ApplyToAllPlayers()
{
PlayerInventory[] array = Object.FindObjectsByType<PlayerInventory>((FindObjectsSortMode)0);
foreach (PlayerInventory obj in array)
{
ApplyCurrentSize(obj);
EquipmentController component = ((Component)obj).GetComponent<EquipmentController>();
if ((Object)(object)component != (Object)null)
{
component.UpdateEquipmentState();
}
}
}
internal static void ApplyCurrentSize(PlayerInventory inventory)
{
if (ManagedInventoryEnabled && !((Object)(object)inventory == (Object)null) && ((NetworkBehaviour)inventory).IsServer)
{
int targetSlotCount = GetTargetSlotCount(inventory);
if (targetSlotCount > 0 && ((InventoryBase)inventory).SlotCount != targetSlotCount)
{
((InventoryBase)inventory).ResizeInventory(targetSlotCount);
Log("Player inventory resized to " + targetSlotCount + " slot(s).");
}
}
}
internal static PlayerInventory FindLocalInventory()
{
try
{
PlayerNetworking localPlayer = ServerManager.GetLocalPlayer();
if ((Object)(object)localPlayer != (Object)null && (Object)(object)localPlayer.Inventory != (Object)null)
{
return localPlayer.Inventory;
}
}
catch
{
}
PlayerInventory[] array = Object.FindObjectsByType<PlayerInventory>((FindObjectsSortMode)0);
foreach (PlayerInventory val in array)
{
if ((Object)(object)val != (Object)null && ((NetworkBehaviour)val).IsLocalPlayer)
{
return val;
}
}
return null;
}
internal static void RefreshLocalEquipment(PlayerInventory inventory)
{
if (!((Object)(object)inventory == (Object)null))
{
EquipmentController component = ((Component)inventory).GetComponent<EquipmentController>();
if ((Object)(object)component != (Object)null)
{
component.UpdateEquipmentState();
}
}
}
internal static bool TryHandleBackpackEquipChange(PlayerInventory inventory, string itemName, bool equipped)
{
if (!ManagedInventoryEnabled || (Object)(object)inventory == (Object)null || !((NetworkBehaviour)inventory).IsServer)
{
return false;
}
ItemData backpackItem = GetBackpackItem(inventory);
if ((Object)(object)backpackItem == (Object)null || !string.Equals(itemName, ((Object)backpackItem).name, StringComparison.Ordinal))
{
return false;
}
int targetSlotCount = GetTargetSlotCount(inventory, equipped);
if (((InventoryBase)inventory).SlotCount != targetSlotCount)
{
((InventoryBase)inventory).ResizeInventory(targetSlotCount);
}
return true;
}
internal static bool HasBackpackEquipped(PlayerInventory inventory)
{
ItemData backpackItem = GetBackpackItem(inventory);
if ((Object)(object)backpackItem != (Object)null)
{
return ((InventoryBase)inventory).GetItemCount(((CraftableItemBase)backpackItem).Name) > 0;
}
return false;
}
internal static ItemData GetBackpackItem(PlayerInventory inventory)
{
try
{
object? obj = AccessTools.Field(typeof(PlayerInventory), "backpack")?.GetValue(inventory);
return (ItemData)((obj is ItemData) ? obj : null);
}
catch
{
return null;
}
}
internal static bool IsWearableSlot(int slotIndex)
{
if (slotIndex >= 0)
{
return slotIndex < EquipmentSlotCount;
}
return false;
}
internal static int ExtraWearableStart(PlayerInventory inventory)
{
return 2;
}
internal static bool IsReservedWearableSlot(PlayerInventory inventory, int slotIndex)
{
if (slotIndex < 0 || (Object)(object)inventory == (Object)null)
{
return false;
}
return slotIndex < EquipmentSlotCount;
}
internal static bool AllowedPlayerSlot(PlayerInventory inventory, ItemData itemData, int slotIndex)
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Invalid comparison between Unknown and I4
if (!ManagedInventoryEnabled || (Object)(object)inventory == (Object)null || (Object)(object)itemData == (Object)null)
{
return true;
}
if (slotIndex == -1)
{
return true;
}
if (slotIndex < 0 || slotIndex >= ((InventoryBase)inventory).SlotCount)
{
return false;
}
if ((int)itemData.equipmentType != 2)
{
return slotIndex >= EquipmentSlotCount;
}
if (!ThreeEquipmentSlotsEnabled)
{
if (slotIndex != 0)
{
return slotIndex == 1;
}
return true;
}
int requiredEquipmentSlot = GetRequiredEquipmentSlot(inventory, itemData);
if (requiredEquipmentSlot >= 0)
{
return slotIndex == requiredEquipmentSlot;
}
if (slotIndex != 0)
{
return slotIndex == 1;
}
return true;
}
internal static bool CanFitPlayerItem(PlayerInventory inventory, ItemData itemData)
{
if (!ManagedInventoryEnabled || (Object)(object)inventory == (Object)null || (Object)(object)itemData == (Object)null)
{
return true;
}
for (int i = 0; i < ((InventoryBase)inventory).SlotCount; i++)
{
if (AllowedPlayerSlot(inventory, itemData, i) && ((InventoryBase)inventory).IsSlotFree(i))
{
return true;
}
}
return false;
}
internal static bool TryCanContainPlayerItem(PlayerInventory inventory, ItemData itemData, int slotIndex, ref ItemContainmentResult result)
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Invalid comparison between Unknown and I4
if (!ManagedInventoryEnabled || (Object)(object)inventory == (Object)null || (Object)(object)itemData == (Object)null)
{
return true;
}
if (slotIndex != -1 && (slotIndex < 0 || slotIndex >= ((InventoryBase)inventory).SlotCount))
{
result = (ItemContainmentResult)4;
return false;
}
if ((int)itemData.equipmentType != 2)
{
return true;
}
if (((InventoryBase)inventory).GetItemCount(((CraftableItemBase)itemData).Name) > 0)
{
result = (ItemContainmentResult)2;
return false;
}
if ((Object)(object)FindBlockingEquipment(inventory, itemData) != (Object)null)
{
result = (ItemContainmentResult)3;
return false;
}
if (slotIndex == -1)
{
result = (ItemContainmentResult)(!CanFitPlayerItem(inventory, itemData));
return false;
}
result = (ItemContainmentResult)((!AllowedPlayerSlot(inventory, itemData, slotIndex)) ? 4 : 0);
return false;
}
internal static ItemData FindBlockingEquipment(PlayerInventory inventory, ItemData itemData)
{
if (itemData.dontAllowEquipTogetherWith == null)
{
return null;
}
ItemData[] dontAllowEquipTogetherWith = itemData.dontAllowEquipTogetherWith;
foreach (ItemData val in dontAllowEquipTogetherWith)
{
if (!((Object)(object)val == (Object)null) && ((InventoryBase)inventory).GetItemCount(((CraftableItemBase)val).Name) > 0 && (!ThreeEquipmentSlotsEnabled || !IsManagedEquipmentItem(inventory, itemData) || !IsManagedEquipmentItem(inventory, val)))
{
return val;
}
}
return null;
}
internal static bool IsManagedEquipmentItem(PlayerInventory inventory, ItemData itemData)
{
return GetRequiredEquipmentSlot(inventory, itemData) >= 0;
}
internal static int GetRequiredEquipmentSlot(PlayerInventory inventory, ItemData itemData)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Invalid comparison between Unknown and I4
if ((Object)(object)inventory == (Object)null || (Object)(object)itemData == (Object)null || (int)itemData.equipmentType != 2)
{
return -1;
}
if (IsBackpackItem(inventory, itemData))
{
return 2;
}
NormalMovement component = ((Component)inventory).GetComponent<NormalMovement>();
ItemData movementItem = GetMovementItem(component, "springShoesItemData");
if (SameItem(itemData, movementItem) || NameContains(itemData, "boot", "shoe", "spring"))
{
return 1;
}
ItemData movementItem2 = GetMovementItem(component, "helmetItemData");
if (SameItem(itemData, movementItem2) || NameContains(itemData, "hat", "helmet", "cap"))
{
return 0;
}
if (IsExtraEquipmentItem(inventory, itemData))
{
return 3;
}
return -1;
}
internal static bool IsExtraEquipmentItem(PlayerInventory inventory, ItemData itemData)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Invalid comparison between Unknown and I4
if (!ExtraEquipmentSlotEnabled || (Object)(object)inventory == (Object)null || (Object)(object)itemData == (Object)null || (int)itemData.equipmentType != 2)
{
return false;
}
if (extraSlotAcceptsAnyWearable != null && extraSlotAcceptsAnyWearable.Value)
{
return true;
}
string text = ((((CraftableItemBase)itemData).Name ?? ((Object)itemData).name) ?? string.Empty).ToLowerInvariant();
string[] array = (extraEquipmentKeywords?.Value ?? "glider,planer,plane,wing,wings,fairy,планер").Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < array.Length; i++)
{
string text2 = array[i].Trim().ToLowerInvariant();
if (text2.Length > 0 && text.Contains(text2))
{
return true;
}
}
return false;
}
internal static bool IsBackpackItem(PlayerInventory inventory, ItemData itemData)
{
ItemData backpackItem = GetBackpackItem(inventory);
if (!SameItem(itemData, backpackItem))
{
return NameContains(itemData, "backpack");
}
return true;
}
private static ItemData GetMovementItem(NormalMovement movement, string fieldName)
{
if ((Object)(object)movement == (Object)null)
{
return null;
}
try
{
object? obj = AccessTools.Field(typeof(NormalMovement), fieldName)?.GetValue(movement);
return (ItemData)((obj is ItemData) ? obj : null);
}
catch
{
return null;
}
}
private static bool SameItem(ItemData a, ItemData b)
{
if ((Object)(object)a != (Object)null && (Object)(object)b != (Object)null)
{
if (a != b && !string.Equals(((CraftableItemBase)a).Name, ((CraftableItemBase)b).Name, StringComparison.OrdinalIgnoreCase))
{
return string.Equals(((Object)a).name, ((Object)b).name, StringComparison.OrdinalIgnoreCase);
}
return true;
}
return false;
}
private static bool NameContains(ItemData itemData, params string[] parts)
{
object obj = ((CraftableItemBase)itemData).Name ?? ((Object)itemData).name;
if (obj == null)
{
obj = string.Empty;
}
string text = ((string)obj).ToLowerInvariant();
foreach (string value in parts)
{
if (text.Contains(value))
{
return true;
}
}
return false;
}
internal static void EnsureUiHasSlots(InventoryPanelControl panel, int requiredSlots)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected O, but got Unknown
if (!ManagedInventoryEnabled || panel == null || panel.slots == null)
{
return;
}
if (requiredSlots > panel.slots.Count)
{
VisualElement val = (VisualElement)(((object)FindSlotParent(panel)) ?? ((object)panel));
while (panel.slots.Count < requiredSlots)
{
InventorySlotView val2 = new InventorySlotView();
val.Add((VisualElement)(object)val2);
((InventoryItemElement)val2).Init(panel);
panel.slots.Add(val2);
TryActivateDrag(val2, panel);
}
ExpandSlotContainer(val);
Log("Inventory UI expanded to " + panel.slots.Count + " slot(s).");
}
DecorateEquipmentSlots(panel);
}
internal static void ApplyUiSlotVisibility(InventoryPanelControl panel, int visibleSlots)
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
if (ManagedInventoryEnabled && panel != null && panel.slots != null)
{
EnsureUiHasSlots(panel, visibleSlots);
ExpandSlotContainer((VisualElement)(((object)FindSlotParent(panel)) ?? ((object)panel)));
for (int i = 0; i < panel.slots.Count; i++)
{
((VisualElement)panel.slots[i]).style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)((i >= visibleSlots) ? 1 : 0));
}
DecorateEquipmentSlots(panel);
}
}
internal static void DecorateEquipmentSlots(InventoryPanelControl panel)
{
if (!ThreeEquipmentSlotsEnabled || panel == null)
{
return;
}
InventoryBase inventory = panel.Inventory;
PlayerInventory val = (PlayerInventory)(object)((inventory is PlayerInventory) ? inventory : null);
if (val != null && panel.slots != null)
{
SetSlotLabel(panel, val, 0, "Hat");
SetSlotLabel(panel, val, 1, "Boots");
SetSlotLabel(panel, val, 2, "Backpack");
if (ExtraEquipmentSlotEnabled)
{
SetSlotLabel(panel, val, 3, "Glider");
}
}
}
private static void SetSlotLabel(InventoryPanelControl panel, PlayerInventory inventory, int slotIndex, string text)
{
//IL_010c: 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_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Expected O, but got Unknown
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: 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)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
if (slotIndex >= 0 && slotIndex < panel.slots.Count)
{
InventorySlotView val = panel.slots[slotIndex];
Label val2 = UQueryExtensions.Q<Label>((VisualElement)(object)val, "joive-equipment-slot-label", (string)null);
if (val2 == null)
{
val2 = new Label();
((VisualElement)val2).name = "joive-equipment-slot-label";
((VisualElement)val2).pickingMode = (PickingMode)1;
((VisualElement)val2).style.position = StyleEnum<Position>.op_Implicit((Position)1);
((VisualElement)val2).style.left = StyleLength.op_Implicit(0f);
((VisualElement)val2).style.right = StyleLength.op_Implicit(0f);
((VisualElement)val2).style.bottom = StyleLength.op_Implicit(2f);
((VisualElement)val2).style.unityTextAlign = StyleEnum<TextAnchor>.op_Implicit((TextAnchor)7);
((VisualElement)val2).style.fontSize = StyleLength.op_Implicit(9f);
((VisualElement)val2).style.color = StyleColor.op_Implicit(new Color(1f, 0.82f, 0.48f, 0.9f));
((VisualElement)val2).style.unityFontStyleAndWeight = StyleEnum<FontStyle>.op_Implicit((FontStyle)1);
((VisualElement)val).Add((VisualElement)(object)val2);
}
((TextElement)val2).text = text;
Label obj = val2;
InventoryItem itemInSlot = ((InventoryBase)inventory).GetItemInSlot(slotIndex);
((VisualElement)obj).visible = !((InventoryItem)(ref itemInSlot)).IsValidItem;
}
}
private static void ExpandSlotContainer(VisualElement parent)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: 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_0042: Unknown result type (might be due to invalid IL or missing references)
if (parent != null)
{
parent.style.flexWrap = StyleEnum<Wrap>.op_Implicit((Wrap)1);
parent.style.overflow = StyleEnum<Overflow>.op_Implicit((Overflow)0);
parent.style.flexShrink = StyleFloat.op_Implicit(0f);
parent.style.width = StyleLength.op_Implicit((StyleKeyword)2);
}
}
internal static bool TryHandleExtendedHotkeys(NormalMovement movement)
{
if (!ExtendedHotkeysEnabled || (Object)(object)movement == (Object)null || IsAnyMenuOpen())
{
return false;
}
object? obj = AccessTools.Field(typeof(NormalMovement), "player")?.GetValue(movement);
PlayerNetworking val = (PlayerNetworking)((obj is PlayerNetworking) ? obj : null);
object? obj2 = AccessTools.Field(typeof(NormalMovement), "equipmentController")?.GetValue(movement);
EquipmentController val2 = (EquipmentController)((obj2 is EquipmentController) ? obj2 : null);
object? obj3 = AccessTools.Field(typeof(NormalMovement), "handController")?.GetValue(movement);
PlayerHandController val3 = (PlayerHandController)((obj3 is PlayerHandController) ? obj3 : null);
if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null || (Object)(object)val.Dismemberment == (Object)null || val.Dismemberment.IsMissingHand)
{
return false;
}
int num = ReadHotkeySlot();
if (num < 0)
{
return false;
}
if (num >= Mathf.Min(10, Mathf.Max(0, ((InventoryBase)val.Inventory).SlotCount - EquipmentSlotCount)))
{
return false;
}
val3.ResetHandPositions();
val2.SetActiveHandSlot(num);
return true;
}
internal static int ReadHotkeySlot()
{
if (Input.GetKeyDown((KeyCode)49))
{
return 0;
}
if (Input.GetKeyDown((KeyCode)50))
{
return 1;
}
if (Input.GetKeyDown((KeyCode)51))
{
return 2;
}
if (Input.GetKeyDown((KeyCode)52))
{
return 3;
}
if (Input.GetKeyDown((KeyCode)53))
{
return 4;
}
if (Input.GetKeyDown((KeyCode)54))
{
return 5;
}
if (Input.GetKeyDown((KeyCode)55))
{
return 6;
}
if (Input.GetKeyDown((KeyCode)56))
{
return 7;
}
if (Input.GetKeyDown((KeyCode)57))
{
return 8;
}
if (Input.GetKeyDown((KeyCode)48))
{
return 9;
}
return -1;
}
internal static bool IsAnyMenuOpen()
{
if ((Object)(object)instance != (Object)null)
{
return instance.menuOpen;
}
return false;
}
internal static int GetHandInventoryIndex(EquipmentController controller)
{
if (controller.ActiveSelectedItemSlot != -1)
{
return controller.ActiveSelectedItemSlot + EquipmentSlotCount;
}
return -1;
}
internal static bool UpdateEquipmentState(EquipmentController controller)
{
if (!ManagedInventoryEnabled || (Object)(object)controller == (Object)null)
{
return true;
}
PlayerNetworking component = ((Component)controller).GetComponent<PlayerNetworking>();
EquipmentHandler handler = controller.Handler;
if ((Object)(object)component == (Object)null || (Object)(object)handler == (Object)null)
{
return true;
}
if (!ThreeEquipmentSlotsEnabled)
{
UpdateHandlerState(component, GetHandInventoryIndex(controller), (Action<string>)handler.SetHandEquipment);
UpdateHandlerState(component, 0, (Action<string>)handler.SetWearedEquipment);
UpdateHandlerState(component, 1, (Action<string>)handler.SetOtherWearedEquipment);
return false;
}
UpdateHandlerState(component, GetHandInventoryIndex(controller), (Action<string>)handler.SetHandEquipment);
UpdateHandlerState(component, 0, (Action<string>)handler.SetWearedEquipment);
UpdateHandlerState(component, 1, (Action<string>)handler.SetOtherWearedEquipment);
List<EquipmentUsageData<WearedEquipment>> list = GetExtraWearableHandlers(controller);
if (list.Count > 0)
{
UpdateHandlerState(component, 2, (Action<string>)list[0].PerformActivation);
}
if (ExtraEquipmentSlotEnabled && list.Count > 1)
{
UpdateHandlerState(component, 3, (Action<string>)list[1].PerformActivation);
}
for (int i = ((!ExtraEquipmentSlotEnabled) ? 1 : 2); i < list.Count; i++)
{
list[i].PerformActivation((string)null);
}
return false;
}
internal static List<EquipmentUsageData<WearedEquipment>> GetExtraWearableHandlers(EquipmentController controller)
{
if (!extraWearableHandlers.TryGetValue(controller, out var value))
{
value = new List<EquipmentUsageData<WearedEquipment>>();
extraWearableHandlers[controller] = value;
}
EquipmentHandler handler = controller.Handler;
int num = (ExtraEquipmentSlotEnabled ? 2 : (ThreeEquipmentSlotsEnabled ? 1 : 0));
while (value.Count < num)
{
value.Add(new EquipmentUsageData<WearedEquipment>
{
nameToVisualEquipmentMap = handler.wearedEquipment.nameToVisualEquipmentMap,
visualElementParent = handler.wearedEquipment.visualElementParent
});
}
return value;
}
internal static bool TryUseExtraWearable(EquipmentHandler handler, int inventorySlot)
{
if (!ThreeEquipmentSlotsEnabled || (Object)(object)handler == (Object)null)
{
return false;
}
int num = -1;
if (inventorySlot == 2)
{
num = 0;
}
else if (ExtraEquipmentSlotEnabled && inventorySlot == 3)
{
num = 1;
}
if (num < 0)
{
return false;
}
EquipmentController[] array = Object.FindObjectsByType<EquipmentController>((FindObjectsSortMode)0);
foreach (EquipmentController val in array)
{
if (!((Object)(object)val == (Object)null) && !((Object)(object)val.Handler != (Object)(object)handler))
{
PlayerNetworking component = ((Component)val).GetComponent<PlayerNetworking>();
if ((Object)(object)component == (Object)null || (Object)(object)component.Inventory == (Object)null)
{
return false;
}
List<EquipmentUsageData<WearedEquipment>> list = GetExtraWearableHandlers(val);
if (list.Count > num && (Object)(object)list[num].activeEquipment != (Object)null)
{
((EquipmentBase)list[num].activeEquipment).OnUsageStart();
}
return true;
}
}
return false;
}
internal static void SetExtraWearableCameraState(EquipmentController controller, bool firstPerson)
{
if (!ManagedInventoryEnabled || (Object)(object)controller == (Object)null || !extraWearableHandlers.TryGetValue(controller, out var value))
{
return;
}
foreach (EquipmentUsageData<WearedEquipment> item in value)
{
if ((Object)(object)item.activeEquipment != (Object)null)
{
item.activeEquipment.SetCameraState(firstPerson);
}
}
}
private static void UpdateHandlerState(PlayerNetworking player, int inventorySlotIndex, Action<string> activationFunction)
{
//IL_0013: 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)
if (inventorySlotIndex == -1)
{
activationFunction(null);
return;
}
InventoryItem itemInSlot = ((InventoryBase)player.Inventory).GetItemInSlot(inventorySlotIndex);
activationFunction(((InventoryItem)(ref itemInSlot)).IsValidItem ? ((CraftableItemBase)((InventoryBase)player.Inventory).GetItemData((int)((InventoryItem)(ref itemInSlot)).ItemIndex)).Name : null);
}
private static VisualElement FindSlotParent(InventoryPanelControl panel)
{
for (int num = panel.slots.Count - 1; num >= 0; num--)
{
InventorySlotView obj = panel.slots[num];
VisualElement val = ((obj != null) ? ((VisualElement)obj).parent : null);
if (val != null)
{
return val;
}
}
return null;
}
private static void TryActivateDrag(InventorySlotView slot, InventoryPanelControl panel)
{
try
{
if (((VisualElement)slot).panel != null)
{
((InventoryItemElement)slot).ActivateDragManipulator((InventoryPanelControl[])(object)new InventoryPanelControl[1] { panel });
return;
}
((CallbackEventHandler)slot).RegisterCallback<AttachToPanelEvent>((EventCallback<AttachToPanelEvent>)delegate
{
((InventoryItemElement)slot).ActivateDragManipulator((InventoryPanelControl[])(object)new InventoryPanelControl[1] { panel });
}, (TrickleDown)0);
}
catch (Exception ex)
{
Log("Could not attach drag handler to extra inventory slot: " + ex.Message);
}
}
internal static void Log(string message)
{
if (debugLogs != null && debugLogs.Value)
{
InventoryQoLPlugin inventoryQoLPlugin = instance;
if (inventoryQoLPlugin != null)
{
((BaseUnityPlugin)inventoryQoLPlugin).Logger.LogInfo((object)message);
}
}
}
}
[HarmonyPatch(typeof(PlayerInventory), "OnNetworkSpawn")]
internal static class PlayerInventoryOnNetworkSpawnPatch
{
private static void Postfix(PlayerInventory __instance)
{
InventoryQoLPlugin.ApplyCurrentSize(__instance);
}
}
[HarmonyPatch(typeof(PlayerInventory), "OnEquipped")]
internal static class PlayerInventoryOnEquippedPatch
{
private static bool Prefix(PlayerInventory __instance, string item)
{
return !InventoryQoLPlugin.TryHandleBackpackEquipChange(__instance, item, equipped: true);
}
}
[HarmonyPatch(typeof(PlayerInventory), "OnUnequipped")]
internal static class PlayerInventoryOnUnequippedPatch
{
private static bool Prefix(PlayerInventory __instance, string item)
{
return !InventoryQoLPlugin.TryHandleBackpackEquipChange(__instance, item, equipped: false);
}
}
[HarmonyPatch(typeof(PlayerInventory), "AllowedSlot")]
internal static class PlayerInventoryAllowedSlotPatch
{
private static bool Prefix(PlayerInventory __instance, ItemData itemData, int slotIndex, ref bool __result)
{
if (!InventoryQoLPlugin.ManagedInventoryEnabled)
{
return true;
}
__result = InventoryQoLPlugin.AllowedPlayerSlot(__instance, itemData, slotIndex);
return false;
}
}
[HarmonyPatch(typeof(PlayerInventory), "CanFitItem")]
internal static class PlayerInventoryCanFitItemPatch
{
private static bool Prefix(PlayerInventory __instance, ItemData itemData, ref bool __result)
{
if (!InventoryQoLPlugin.ManagedInventoryEnabled)
{
return true;
}
__result = InventoryQoLPlugin.CanFitPlayerItem(__instance, itemData);
return false;
}
}
[HarmonyPatch(typeof(PlayerInventory), "CanContainItem")]
internal static class PlayerInventoryCanContainItemPatch
{
private static bool Prefix(PlayerInventory __instance, ItemData itemData, int slotIndex, ref ItemContainmentResult __result)
{
return InventoryQoLPlugin.TryCanContainPlayerItem(__instance, itemData, slotIndex, ref __result);
}
}
[HarmonyPatch(typeof(PlayerInventory), "OnInventoryContentsChanged", new Type[] { })]
internal static class PlayerInventoryOnInventoryContentsChangedPatch
{
private static void Postfix(PlayerInventory __instance)
{
InventoryQoLPlugin.ApplyCurrentSize(__instance);
}
}
[HarmonyPatch(typeof(InventoryPanelControl), "Bind")]
internal static class InventoryPanelControlBindPatch
{
private static void Postfix(InventoryPanelControl __instance, InventoryBase inventory)
{
PlayerInventory val = (PlayerInventory)(object)((inventory is PlayerInventory) ? inventory : null);
if (val != null)
{
InventoryQoLPlugin.EnsureUiHasSlots(__instance, InventoryQoLPlugin.WantedUiSlots(val));
InventoryQoLPlugin.ApplyUiSlotVisibility(__instance, inventory.SlotCount);
}
}
}
[HarmonyPatch(typeof(InventoryPanelControl), "OnInventoryResized")]
internal static class InventoryPanelControlOnInventoryResizedPatch
{
private static void Prefix(InventoryPanelControl __instance, int newSize)
{
InventoryQoLPlugin.EnsureUiHasSlots(__instance, newSize);
}
}
[HarmonyPatch(typeof(InventoryPanelControl), "OnInventoryUpdated")]
internal static class InventoryPanelControlOnInventoryUpdatedPatch
{
private static void Prefix(InventoryPanelControl __instance)
{
InventoryBase inventory = __instance.Inventory;
PlayerInventory val = (PlayerInventory)(object)((inventory is PlayerInventory) ? inventory : null);
if (val != null)
{
InventoryQoLPlugin.EnsureUiHasSlots(__instance, ((InventoryBase)val).SlotCount);
}
}
private static void Postfix(InventoryPanelControl __instance)
{
InventoryQoLPlugin.DecorateEquipmentSlots(__instance);
}
}
[HarmonyPatch(typeof(NormalMovement), "HandleEquipping")]
internal static class NormalMovementHandleEquippingPatch
{
private static bool Prefix(NormalMovement __instance)
{
return !InventoryQoLPlugin.TryHandleExtendedHotkeys(__instance);
}
}
[HarmonyPatch(typeof(EquipmentController), "get_ActiveItemInventoryIndex")]
internal static class EquipmentControllerActiveItemInventoryIndexPatch
{
private static void Postfix(EquipmentController __instance, ref int __result)
{
if (InventoryQoLPlugin.ManagedInventoryEnabled && __instance.ActiveSelectedItemSlot != -1)
{
__result = InventoryQoLPlugin.GetHandInventoryIndex(__instance);
}
}
}
[HarmonyPatch(typeof(EquipmentController), "get_HandEquipmentCapacity")]
internal static class EquipmentControllerHandEquipmentCapacityPatch
{
private static void Postfix(EquipmentController __instance, ref int __result)
{
if (InventoryQoLPlugin.ManagedInventoryEnabled)
{
PlayerNetworking component = ((Component)__instance).GetComponent<PlayerNetworking>();
__result = (((Object)(object)component != (Object)null) ? Mathf.Max(0, ((InventoryBase)component.Inventory).SlotCount - InventoryQoLPlugin.EquipmentSlotCount) : __result);
}
}
}
[HarmonyPatch(typeof(EquipmentController), "DropHeldItem")]
internal static class EquipmentControllerDropHeldItemPatch
{
private static bool Prefix(EquipmentController __instance, Vector3 pos, Vector3 velocity)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
if (!InventoryQoLPlugin.ManagedInventoryEnabled)
{
return true;
}
int handInventoryIndex = InventoryQoLPlugin.GetHandInventoryIndex(__instance);
if (handInventoryIndex >= 0)
{
((InventoryBase)((Component)__instance).GetComponent<PlayerNetworking>().Inventory).DropItemRpc((byte)handInventoryIndex, pos, velocity, default(RpcParams));
}
return false;
}
}
[HarmonyPatch(typeof(EquipmentController), "UpdateEquipmentState")]
internal static class EquipmentControllerUpdateEquipmentStatePatch
{
private static bool Prefix(EquipmentController __instance)
{
return InventoryQoLPlugin.UpdateEquipmentState(__instance);
}
}
[HarmonyPatch(typeof(EquipmentController), "SetHandStateRpc")]
internal static class EquipmentControllerSetHandStateRpcPatch
{
private static void Postfix(EquipmentController __instance, bool firstPerson)
{
InventoryQoLPlugin.SetExtraWearableCameraState(__instance, firstPerson);
}
}
[HarmonyPatch(typeof(EquipmentHandler), "OnWearedEquipmentUsed")]
internal static class EquipmentHandlerOnWearedEquipmentUsedPatch
{
private static bool Prefix(EquipmentHandler __instance, int wearedEquipmentInventorySlot)
{
return !InventoryQoLPlugin.TryUseExtraWearable(__instance, wearedEquipmentInventorySlot);
}
}
}