using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Common;
using HarmonyLib;
using TMPro;
using UnityEngine;
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("ComfyQuickSlots")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ComfyQuickSlots")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("08d30e30-98ba-4364-8410-f0d2534129ba")]
[assembly: AssemblyFileVersion("1.6.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.6.0.0")]
[module: UnverifiableCode]
namespace ValheimInventorySlots
{
[BepInPlugin("8F0F9F2B-E481-4BEC-B641-01228D7508F9", "MoreSlotsPatcherForComfyQuickslots", "1.1.0")]
public class FixGuiFrame : BaseUnityPlugin
{
public const string FixGuiGuid = "8F0F9F2B-E481-4BEC-B641-01228D7508F9";
public const string FixGuiName = "MoreSlotsPatcherForComfyQuickslots";
public const string FixVersion = "1.1.0";
private GameObject inventoryScreenObjectRoot;
private Transform inventoryScreenObject;
private Transform containerScreenObject;
private float bgYOffset = 0f;
private float containerYOffset = 0f;
private Coroutine screenSearch;
private void OnEnable()
{
screenSearch = ((MonoBehaviour)this).StartCoroutine(screenSearchCoroutine());
}
private void OnDisable()
{
((MonoBehaviour)this).StopCoroutine(screenSearch);
}
public IEnumerator screenSearchCoroutine()
{
while (((Behaviour)this).enabled)
{
if ((Object)(object)inventoryScreenObjectRoot == (Object)null || (Object)(object)inventoryScreenObject == (Object)null || (Object)(object)containerScreenObject == (Object)null)
{
bgYOffset = 0f;
containerYOffset = 0f;
inventoryScreenObjectRoot = (from obj in Resources.FindObjectsOfTypeAll<GameObject>()
where ((Object)obj).name == "Inventory_screen"
where obj.transform.position.x != 0f
select obj).SingleOrDefault();
if ((Object)(object)inventoryScreenObjectRoot != (Object)null)
{
yield return (object)new WaitForSecondsRealtime(1f);
inventoryScreenObject = inventoryScreenObjectRoot.transform.Find("root/Player/Bkg");
containerScreenObject = inventoryScreenObjectRoot.transform.Find("root/Container");
}
yield return (object)new WaitForSecondsRealtime(5f);
}
else if (bgYOffset == 0f)
{
containerYOffset = ((Component)inventoryScreenObject).transform.localPosition.y * 1.8125f;
((Component)containerScreenObject).transform.localPosition = new Vector3(((Component)containerScreenObject).transform.localPosition.x, ((Component)inventoryScreenObject).transform.localPosition.y - containerYOffset, ((Component)containerScreenObject).transform.localPosition.z);
float sleepSeconds = 30f;
yield return (object)new WaitForSecondsRealtime(sleepSeconds);
}
yield return 0;
}
}
}
}
namespace Common
{
public class ConfigPositionedElement : MonoBehaviour
{
public ConfigEntry<TextAnchor> AnchorConfig;
public ConfigEntry<Vector2> PositionConfig;
protected RectTransform _rt;
protected TextAnchor _currentAnchor;
public virtual void Awake()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
_rt = (RectTransform)((Component)this).transform;
EnsureCorrectPosition();
}
public virtual void Update()
{
EnsureCorrectPosition();
}
public virtual void EnsureCorrectPosition()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: 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_0066: 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_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Expected I4, but got Unknown
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: 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_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_017e: Unknown result type (might be due to invalid IL or missing references)
//IL_0186: Unknown result type (might be due to invalid IL or missing references)
//IL_0188: 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_0190: Unknown result type (might be due to invalid IL or missing references)
//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: 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)
//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
//IL_0200: Unknown result type (might be due to invalid IL or missing references)
//IL_0208: Unknown result type (might be due to invalid IL or missing references)
//IL_020a: Unknown result type (might be due to invalid IL or missing references)
//IL_020b: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: Unknown result type (might be due to invalid IL or missing references)
//IL_0241: Unknown result type (might be due to invalid IL or missing references)
//IL_0249: Unknown result type (might be due to invalid IL or missing references)
//IL_024b: Unknown result type (might be due to invalid IL or missing references)
//IL_024c: Unknown result type (might be due to invalid IL or missing references)
//IL_0253: Unknown result type (might be due to invalid IL or missing references)
//IL_027f: Unknown result type (might be due to invalid IL or missing references)
//IL_0287: 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_028a: Unknown result type (might be due to invalid IL or missing references)
//IL_0291: Unknown result type (might be due to invalid IL or missing references)
//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
if (AnchorConfig != null && PositionConfig != null && (_currentAnchor != AnchorConfig.Value || !(_rt.anchoredPosition == PositionConfig.Value)))
{
_currentAnchor = AnchorConfig.Value;
TextAnchor currentAnchor = _currentAnchor;
TextAnchor val = currentAnchor;
Vector2 val2 = default(Vector2);
switch ((int)val)
{
case 0:
{
RectTransform rt25 = _rt;
RectTransform rt26 = _rt;
RectTransform rt27 = _rt;
((Vector2)(ref val2))..ctor(0f, 1f);
rt27.anchorMax = val2;
Vector2 pivot = (rt26.anchorMin = val2);
rt25.pivot = pivot;
break;
}
case 1:
{
RectTransform rt22 = _rt;
RectTransform rt23 = _rt;
RectTransform rt24 = _rt;
((Vector2)(ref val2))..ctor(0.5f, 1f);
rt24.anchorMax = val2;
Vector2 pivot = (rt23.anchorMin = val2);
rt22.pivot = pivot;
break;
}
case 2:
{
RectTransform rt19 = _rt;
RectTransform rt20 = _rt;
RectTransform rt21 = _rt;
((Vector2)(ref val2))..ctor(1f, 1f);
rt21.anchorMax = val2;
Vector2 pivot = (rt20.anchorMin = val2);
rt19.pivot = pivot;
break;
}
case 3:
{
RectTransform rt16 = _rt;
RectTransform rt17 = _rt;
RectTransform rt18 = _rt;
((Vector2)(ref val2))..ctor(0f, 0.5f);
rt18.anchorMax = val2;
Vector2 pivot = (rt17.anchorMin = val2);
rt16.pivot = pivot;
break;
}
case 4:
{
RectTransform rt13 = _rt;
RectTransform rt14 = _rt;
RectTransform rt15 = _rt;
((Vector2)(ref val2))..ctor(0.5f, 0.5f);
rt15.anchorMax = val2;
Vector2 pivot = (rt14.anchorMin = val2);
rt13.pivot = pivot;
break;
}
case 5:
{
RectTransform rt10 = _rt;
RectTransform rt11 = _rt;
RectTransform rt12 = _rt;
((Vector2)(ref val2))..ctor(1f, 0.5f);
rt12.anchorMax = val2;
Vector2 pivot = (rt11.anchorMin = val2);
rt10.pivot = pivot;
break;
}
case 6:
{
RectTransform rt7 = _rt;
RectTransform rt8 = _rt;
RectTransform rt9 = _rt;
((Vector2)(ref val2))..ctor(0f, 0f);
rt9.anchorMax = val2;
Vector2 pivot = (rt8.anchorMin = val2);
rt7.pivot = pivot;
break;
}
case 7:
{
RectTransform rt4 = _rt;
RectTransform rt5 = _rt;
RectTransform rt6 = _rt;
((Vector2)(ref val2))..ctor(0.5f, 0f);
rt6.anchorMax = val2;
Vector2 pivot = (rt5.anchorMin = val2);
rt4.pivot = pivot;
break;
}
case 8:
{
RectTransform rt = _rt;
RectTransform rt2 = _rt;
RectTransform rt3 = _rt;
((Vector2)(ref val2))..ctor(1f, 0f);
rt3.anchorMax = val2;
Vector2 pivot = (rt2.anchorMin = val2);
rt.pivot = pivot;
break;
}
}
_rt.anchoredPosition = PositionConfig.Value;
}
}
}
}
namespace ComfyQuickSlots
{
[HarmonyPatch(typeof(TombStone))]
internal static class TombstonePatch
{
[HarmonyPrefix]
[HarmonyPatch("GiveBoost")]
private static bool GiveBoostPrefix(TombStone __instance)
{
if (__instance.m_nview.m_zdo.GetBool(ComfyQuickSlots.IsAdditionalTombstoneField, false))
{
return false;
}
return true;
}
}
public class PluginConfig
{
public static ConfigEntry<bool> IsModEnabled;
public static ConfigEntry<bool> EnableQuickslots;
public static ConfigEntry<KeyCode> QuickSlot1;
public static ConfigEntry<KeyCode> QuickSlot2;
public static ConfigEntry<KeyCode> QuickSlot3;
public static ConfigEntry<TextAnchor> QuickSlotsAnchor;
public static ConfigEntry<Vector2> QuickSlotsPosition;
public static ConfigEntry<string> LogFilesPath;
public static void BindConfig(ConfigFile config)
{
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
IsModEnabled = config.Bind<bool>("_Global", "isModEnabled", true, "Globally enable or disable this mod.");
QuickSlot1 = config.Bind<KeyCode>("QuickSlotBinding", "quickSlot1Use", (KeyCode)122, "Hot key for item use in quick slot 1");
QuickSlot2 = config.Bind<KeyCode>("QuickSlotBinding", "quickSlot2Use", (KeyCode)118, "Hot key for item use in quick slot 2");
QuickSlot3 = config.Bind<KeyCode>("QuickSlotBinding", "quickSlot3Use", (KeyCode)98, "Hot key for item use in quick slot 3");
EnableQuickslots = config.Bind<bool>("QuickSlotToggles", "quickSlotEnable", true, "Enables or disables quickslots.");
QuickSlotsAnchor = config.Bind<TextAnchor>("QuickSlotsAnchor", "quickSlotsAnchor", (TextAnchor)6, "The point on the HUD to anchor the Quick Slots bar. Changing this also changes the pivot of the Quick Slots to that corner.");
QuickSlotsPosition = config.Bind<Vector2>("QuickSlotsOffset", "quickSlotsOffset", new Vector2(216f, 150f), "The position offset from the Quick Slots Anchor at which to place the Quick Slots.");
LogFilesPath = config.Bind<string>("Logging", "logFilesPath", "ItemsOnDeath/", "Path to where logging of items on death are saved.");
}
}
public static class KeyCodeUtils
{
public static readonly Dictionary<KeyCode, string> KeyCodeToShortText = new Dictionary<KeyCode, string>
{
{
(KeyCode)97,
"A"
},
{
(KeyCode)98,
"B"
},
{
(KeyCode)99,
"C"
},
{
(KeyCode)100,
"D"
},
{
(KeyCode)101,
"E"
},
{
(KeyCode)102,
"F"
},
{
(KeyCode)103,
"G"
},
{
(KeyCode)104,
"H"
},
{
(KeyCode)105,
"I"
},
{
(KeyCode)106,
"J"
},
{
(KeyCode)107,
"K"
},
{
(KeyCode)108,
"L"
},
{
(KeyCode)109,
"M"
},
{
(KeyCode)110,
"N"
},
{
(KeyCode)111,
"O"
},
{
(KeyCode)112,
"P"
},
{
(KeyCode)113,
"Q"
},
{
(KeyCode)114,
"R"
},
{
(KeyCode)115,
"S"
},
{
(KeyCode)116,
"T"
},
{
(KeyCode)117,
"U"
},
{
(KeyCode)118,
"V"
},
{
(KeyCode)119,
"W"
},
{
(KeyCode)120,
"X"
},
{
(KeyCode)121,
"Y"
},
{
(KeyCode)122,
"Z"
},
{
(KeyCode)257,
"kp1"
},
{
(KeyCode)258,
"kp2"
},
{
(KeyCode)259,
"kp3"
},
{
(KeyCode)260,
"kp4"
},
{
(KeyCode)261,
"kp5"
},
{
(KeyCode)262,
"kp6"
},
{
(KeyCode)263,
"kp7"
},
{
(KeyCode)264,
"kp8"
},
{
(KeyCode)265,
"kp9"
},
{
(KeyCode)256,
"kp10"
},
{
(KeyCode)33,
"!"
},
{
(KeyCode)34,
"\""
},
{
(KeyCode)35,
"#"
},
{
(KeyCode)36,
"$"
},
{
(KeyCode)38,
"&"
},
{
(KeyCode)39,
"'"
},
{
(KeyCode)40,
"("
},
{
(KeyCode)41,
")"
},
{
(KeyCode)42,
"*"
},
{
(KeyCode)43,
"+"
},
{
(KeyCode)44,
","
},
{
(KeyCode)45,
"-"
},
{
(KeyCode)46,
"."
},
{
(KeyCode)47,
"/"
},
{
(KeyCode)58,
":"
},
{
(KeyCode)59,
";"
},
{
(KeyCode)60,
"<"
},
{
(KeyCode)61,
"="
},
{
(KeyCode)62,
">"
},
{
(KeyCode)63,
"?"
},
{
(KeyCode)64,
"@"
},
{
(KeyCode)91,
"["
},
{
(KeyCode)92,
"\\"
},
{
(KeyCode)93,
"]"
},
{
(KeyCode)94,
"^"
},
{
(KeyCode)95,
"_"
},
{
(KeyCode)96,
"`"
},
{
(KeyCode)49,
"1"
},
{
(KeyCode)50,
"2"
},
{
(KeyCode)51,
"3"
},
{
(KeyCode)52,
"4"
},
{
(KeyCode)53,
"5"
},
{
(KeyCode)54,
"6"
},
{
(KeyCode)55,
"7"
},
{
(KeyCode)56,
"8"
},
{
(KeyCode)57,
"9"
},
{
(KeyCode)48,
"0"
},
{
(KeyCode)266,
"kp ."
},
{
(KeyCode)267,
"kp //"
},
{
(KeyCode)268,
"kp *"
},
{
(KeyCode)269,
"kp -"
},
{
(KeyCode)270,
"kp +"
},
{
(KeyCode)272,
"kp ="
}
};
public static string ToShortString(this KeyCode keyCode)
{
//IL_0006: 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)
return KeyCodeToShortText.ContainsKey(keyCode) ? KeyCodeToShortText[keyCode] : ((object)(KeyCode)(ref keyCode)).ToString();
}
public static string ToShortString(this KeyboardShortcut keyboardShortcut)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
return string.Join(" + ", ((KeyboardShortcut)(ref keyboardShortcut)).Modifiers.Concat(Enumerable.Repeat<KeyCode>(((KeyboardShortcut)(ref keyboardShortcut)).MainKey, 1)).Select(ToShortString));
}
}
public static class InventoryExtensions
{
public static bool IsPlayerInventory(this Inventory inventory)
{
if (inventory.m_name.Equals(ComfyQuickSlots.PlayerInventoryName))
{
return true;
}
return false;
}
}
public class InventoryLogger
{
private static readonly string InventoryCsvHeaderRow = string.Join(",", "name", "crafterId", "crafterName", "gridpos.x", "gridpos.y", "quality", "stack", "variant");
public static void LogInventoryToFile(Inventory inventory, string filename)
{
ComfyQuickSlots.log($"Logging {inventory.m_inventory.Count} inventory items to file: {filename}");
using StreamWriter streamWriter = File.CreateText(filename);
streamWriter.AutoFlush = true;
streamWriter.WriteLine(InventoryCsvHeaderRow);
foreach (ItemData item in inventory.m_inventory)
{
streamWriter.WriteLine(ItemToCsvRow(item));
}
}
private static string ItemToCsvRow(ItemData item)
{
return string.Join(",", EscapeCsvField(item.m_shared.m_name), item.m_crafterID, EscapeCsvField(item.m_crafterName), item.m_gridPos.x, item.m_gridPos.y, item.m_quality, item.m_stack, item.m_variant);
}
private static string EscapeCsvField(string ValueToEscape)
{
if (ValueToEscape.Contains(","))
{
return "\"" + ValueToEscape + "\"";
}
return ValueToEscape;
}
}
[BepInPlugin("com.bruce.valheim.comfyquickslots", "ComfyQuickSlots", "1.6.0")]
public class ComfyQuickSlots : BaseUnityPlugin
{
public const string PluginGuid = "com.bruce.valheim.comfyquickslots";
public const string PluginName = "ComfyQuickSlots";
public const string PluginVersion = "1.6.0";
public const string playerDataKey = "ComfyQuickSlotsInventory";
private static ConfigFile configFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "ComfyQuickSlots.cfg"), true);
private static ManualLogSource _logger;
private Harmony _harmony;
public static readonly string PlayerInventoryName = "ComfyQuickSlotsInventory";
public static readonly int IsAdditionalTombstoneField = StringExtensionMethods.GetStableHashCode("cqs.tombstone");
private static bool _debug = false;
private static Assembly assem = typeof(ComfyQuickSlots).Assembly;
public static string fpath = assem.Location;
public static string path = fpath.Remove(fpath.Length - 13);
public static bool GKInstalled;
public const int quickSlotsCount = 3;
public const int rows = 5;
public const int columns = 8;
public static readonly List<ItemType> ArmorSlotTypes = new List<ItemType>
{
(ItemType)6,
(ItemType)7,
(ItemType)11,
(ItemType)17,
(ItemType)18
};
public static Vector2i helmetSlot = new Vector2i(0, 4);
public static Vector2i chestSlot = new Vector2i(1, 4);
public static Vector2i legsSlot = new Vector2i(2, 4);
public static Vector2i shoulderSlot = new Vector2i(3, 4);
public static Vector2i utilitySlot = new Vector2i(4, 4);
private static Vector2i _quickSlot1 = new Vector2i(5, 4);
private static Vector2i _quickSlot2 = new Vector2i(6, 4);
private static Vector2i _quickSlot3 = new Vector2i(7, 4);
public static List<Vector2i> armorSlots = new List<Vector2i> { helmetSlot, chestSlot, legsSlot, shoulderSlot, utilitySlot };
private static List<Vector2i> _quickSlots = new List<Vector2i> { _quickSlot1, _quickSlot2, _quickSlot3 };
public static bool firstLoad = false;
public static bool onMenuLoad = false;
public static List<ItemData> initialEquippedArmor = new List<ItemData>();
public void Awake()
{
_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.bruce.valheim.comfyquickslots");
_logger = ((BaseUnityPlugin)this).Logger;
PluginConfig.BindConfig(((BaseUnityPlugin)this).Config);
}
public void OnDestroy()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
public void Update()
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: 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)
Player localPlayer = Player.m_localPlayer;
if (!((Object)(object)localPlayer == (Object)null) && ((Character)localPlayer).TakeInput() && PluginConfig.EnableQuickslots.Value)
{
ItemData val = null;
if (Input.GetKeyDown(PluginConfig.QuickSlot3.Value))
{
val = ((Humanoid)Player.m_localPlayer).GetInventory().GetItemAt(7, 4);
}
if (Input.GetKeyDown(PluginConfig.QuickSlot2.Value))
{
val = ((Humanoid)Player.m_localPlayer).GetInventory().GetItemAt(6, 4);
}
if (Input.GetKeyDown(PluginConfig.QuickSlot1.Value))
{
val = ((Humanoid)Player.m_localPlayer).GetInventory().GetItemAt(5, 4);
}
if (val != null && !Player.m_localPlayer.IsEquipActionQueued(val))
{
((Humanoid)Player.m_localPlayer).UseItem((Inventory)null, val, false);
}
}
}
public static void log(string message)
{
if (_debug)
{
_logger.LogInfo((object)message);
}
}
public static bool HaveEmptyInventorySlot(Inventory inventory)
{
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 5; j++)
{
if (inventory.GetItemAt(i, j) == null && j != 4)
{
return true;
}
if (i > 4 && j == 4 && inventory.GetItemAt(i, j) == null)
{
return true;
}
}
}
return false;
}
public static Vector2i GetEmptyInventorySlot(Inventory inventory, bool topFirst)
{
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: 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)
//IL_00bb: 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_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: 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_0060: Unknown result type (might be due to invalid IL or missing references)
if (topFirst)
{
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 8; j++)
{
if (inventory.GetItemAt(j, i) == null && i != 4)
{
return new Vector2i(j, i);
}
if (j > 4 && i == 4 && inventory.GetItemAt(j, i) == null)
{
return new Vector2i(j, i);
}
}
}
}
else
{
for (int num = 4; num >= 0; num--)
{
for (int k = 0; k < 8; k++)
{
if (inventory.GetItemAt(k, num) == null && num != 4)
{
return new Vector2i(k, num);
}
if (k > 4 && num == 4 && inventory.GetItemAt(k, num) == null)
{
return new Vector2i(k, num);
}
}
}
}
return new Vector2i(-1, -1);
}
public static bool IsArmor(ItemData item)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Invalid comparison between Unknown and I4
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Invalid comparison between Unknown and I4
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Invalid comparison between Unknown and I4
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Invalid comparison between Unknown and I4
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Invalid comparison between Unknown and I4
if ((int)item.m_shared.m_itemType == 6 || (int)item.m_shared.m_itemType == 7 || (int)item.m_shared.m_itemType == 11 || (int)item.m_shared.m_itemType == 17 || (int)item.m_shared.m_itemType == 18)
{
return true;
}
return false;
}
public static bool IsArmorSlot(Vector2i loc)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
if (armorSlots.Contains(loc))
{
return true;
}
return false;
}
public static bool IsQuickSlot(Vector2i loc)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
if (_quickSlots.Contains(loc))
{
return true;
}
return false;
}
public static Vector2i GetArmorSlot(ItemData item)
{
//IL_000c: 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_0014: Unknown result type (might be due to invalid IL or missing references)
return armorSlots[GetArmorTypeIndex(item)];
}
public static int GetArmorSlotIndex(Vector2i loc)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
return armorSlots.IndexOf(loc);
}
public static int GetArmorTypeIndex(ItemData item)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
return ArmorSlotTypes.IndexOf(item.m_shared.m_itemType);
}
public static bool UnequipItem(Humanoid player, ItemData item)
{
if (player.m_helmetItem == item)
{
player.m_helmetItem = null;
item.m_equipped = false;
player.SetupEquipment();
player.TriggerEquipEffect(item);
return true;
}
if (player.m_chestItem == item)
{
player.m_chestItem = null;
item.m_equipped = false;
player.SetupEquipment();
player.TriggerEquipEffect(item);
return true;
}
if (player.m_legItem == item)
{
player.m_legItem = null;
item.m_equipped = false;
player.SetupEquipment();
player.TriggerEquipEffect(item);
return true;
}
if (player.m_shoulderItem == item)
{
player.m_shoulderItem = null;
item.m_equipped = false;
player.SetupEquipment();
player.TriggerEquipEffect(item);
return true;
}
if (player.m_utilityItem == item)
{
player.m_utilityItem = null;
item.m_equipped = false;
player.SetupEquipment();
player.TriggerEquipEffect(item);
return true;
}
return false;
}
public static void EquipItem(Humanoid humanoid, ItemData item)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Invalid comparison between Unknown and I4
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Invalid comparison between Unknown and I4
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Invalid comparison between Unknown and I4
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Invalid comparison between Unknown and I4
if ((int)item.m_shared.m_itemType == 6)
{
humanoid.m_helmetItem = item;
}
else if ((int)item.m_shared.m_itemType == 7)
{
humanoid.m_chestItem = item;
}
else if ((int)item.m_shared.m_itemType == 11)
{
humanoid.m_legItem = item;
}
else if ((int)item.m_shared.m_itemType == 17)
{
humanoid.m_shoulderItem = item;
}
else if ((int)item.m_shared.m_itemType == 18)
{
humanoid.m_utilityItem = item;
}
log("Equipped " + item.m_shared.m_name);
item.m_equipped = true;
humanoid.SetupEquipment();
humanoid.TriggerEquipEffect(item);
}
public static void EquipAndAddItem(Humanoid humanoid, ItemData item)
{
humanoid.m_inventory.AddItem(item);
EquipItem(humanoid, item);
}
public static bool IsArmorTypeEquipped(Humanoid humanoid, ItemData item)
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Invalid comparison between Unknown and I4
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Invalid comparison between Unknown and I4
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Invalid comparison between Unknown and I4
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Invalid comparison between Unknown and I4
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Invalid comparison between Unknown and I4
ItemData val = null;
if ((int)item.m_shared.m_itemType == 6)
{
val = humanoid.m_helmetItem;
}
else if ((int)item.m_shared.m_itemType == 7)
{
val = humanoid.m_chestItem;
}
else if ((int)item.m_shared.m_itemType == 11)
{
val = humanoid.m_legItem;
}
else if ((int)item.m_shared.m_itemType == 17)
{
val = humanoid.m_shoulderItem;
}
else if ((int)item.m_shared.m_itemType == 18)
{
val = humanoid.m_utilityItem;
}
if (val == null)
{
return false;
}
return true;
}
public static ItemData GetArmorItemToSwap(Humanoid humanoid, ItemData item)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Invalid comparison between Unknown and I4
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Invalid comparison between Unknown and I4
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Invalid comparison between Unknown and I4
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Invalid comparison between Unknown and I4
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Invalid comparison between Unknown and I4
if ((int)item.m_shared.m_itemType == 6)
{
return humanoid.m_helmetItem;
}
if ((int)item.m_shared.m_itemType == 7)
{
return humanoid.m_chestItem;
}
if ((int)item.m_shared.m_itemType == 11)
{
return humanoid.m_legItem;
}
if ((int)item.m_shared.m_itemType == 17)
{
return humanoid.m_shoulderItem;
}
if ((int)item.m_shared.m_itemType == 18)
{
return humanoid.m_utilityItem;
}
return null;
}
public static bool SwapArmorItems(Humanoid humanoid, ItemData itemToMove, ItemData itemInArmorSlot, int armorSlotX, int armorSlotY)
{
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//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_0078: 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)
log($"Swapping {itemToMove.m_shared.m_name} in {itemToMove.m_gridPos.x},{itemToMove.m_gridPos.y} with {itemInArmorSlot} in {armorSlotX},{armorSlotY}");
Vector2i gridPos = itemToMove.m_gridPos;
itemToMove.m_gridPos = new Vector2i(armorSlotX, armorSlotY);
itemInArmorSlot.m_gridPos = gridPos;
humanoid.GetInventory().Changed();
return false;
}
public static bool MoveArmorItemToSlot(Humanoid humanoid, ItemData item, int x, int y)
{
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
ItemData itemAt = humanoid.GetInventory().GetItemAt(x, y);
if (itemAt != null && !((object)itemAt).Equals((object?)item))
{
return SwapArmorItems(humanoid, item, itemAt, x, y);
}
item.m_gridPos = new Vector2i(x, y);
if (!humanoid.GetInventory().m_inventory.Contains(item))
{
humanoid.GetInventory().AddItem(item);
humanoid.GetInventory().Changed();
return true;
}
return false;
}
public static bool AddItemToSlot(Humanoid humanoid, ItemData item, int x, int y)
{
//IL_0016: 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)
humanoid.GetInventory().m_inventory.Add(item);
item.m_gridPos = new Vector2i(x, y);
return true;
}
public static bool AddItemToExistingStacks(Inventory inventory, ItemData item)
{
//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_0074: 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_008b: Unknown result type (might be due to invalid IL or missing references)
int i = 0;
if (item.m_shared.m_maxStackSize > 1)
{
for (; i < item.m_stack; i++)
{
ItemData val = inventory.FindFreeStackItem(item.m_shared.m_name, item.m_quality, (float)item.m_worldLevel);
if (val != null)
{
val.m_stack++;
continue;
}
item.m_stack -= i;
Vector2i emptyInventorySlot = GetEmptyInventorySlot(inventory, topFirst: true);
if (emptyInventorySlot.x >= 0)
{
item.m_gridPos = emptyInventorySlot;
inventory.m_inventory.Add(item);
return true;
}
return false;
}
}
return false;
}
public static bool EquipArmorInArmorSlots(Player player)
{
for (int i = 0; i < 5; i++)
{
if (((Humanoid)player).GetInventory().GetItemAt(i, 4) != null)
{
EquipItem((Humanoid)(object)player, ((Humanoid)player).GetInventory().GetItemAt(i, 4));
}
}
return true;
}
public static bool UnequipAllArmor(Player player)
{
for (int i = 0; i < 5; i++)
{
ItemData itemAt = ((Humanoid)player).GetInventory().GetItemAt(i, 4);
if (itemAt != null)
{
UnequipItem((Humanoid)(object)player, itemAt);
}
}
return true;
}
public static void GetAllArmorFirst(Player player)
{
if (((Humanoid)player).m_helmetItem != null)
{
initialEquippedArmor.Add(((Humanoid)player).m_helmetItem);
}
if (((Humanoid)player).m_chestItem != null)
{
initialEquippedArmor.Add(((Humanoid)player).m_chestItem);
}
if (((Humanoid)player).m_legItem != null)
{
initialEquippedArmor.Add(((Humanoid)player).m_legItem);
}
if (((Humanoid)player).m_shoulderItem != null)
{
initialEquippedArmor.Add(((Humanoid)player).m_shoulderItem);
}
if (((Humanoid)player).m_utilityItem != null)
{
initialEquippedArmor.Add(((Humanoid)player).m_utilityItem);
}
}
public static bool Save(Player player)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
log("Saving inventory data to ComfyQuickSlotsInventory");
ZPackage val = new ZPackage();
((Humanoid)player).GetInventory().Save(val);
if (player.m_knownTexts.ContainsKey("ComfyQuickSlotsInventory"))
{
player.m_knownTexts["ComfyQuickSlotsInventory"] = val.GetBase64();
}
else
{
player.m_knownTexts.Add("ComfyQuickSlotsInventory", val.GetBase64());
}
return true;
}
public static int ItemCountInInventory(ItemData item)
{
int num = 0;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 8; j++)
{
if (((Humanoid)Player.m_localPlayer).GetInventory().GetItemAt(j, i).m_shared.m_name == item.m_shared.m_name)
{
num++;
}
}
}
return num;
}
public static bool IsSimilarItemEquipped(ItemData item)
{
foreach (ItemData equippedItem in ((Humanoid)Player.m_localPlayer).GetInventory().GetEquippedItems())
{
if (item.m_shared.m_name.Equals(equippedItem.m_shared.m_name))
{
return true;
}
}
return false;
}
}
[HarmonyPatch(typeof(HotkeyBar))]
public static class HotkeyBarPatch
{
public static GameObject QuickSlotsHotkeyBar;
public static int SelectedHotkeyBarIndex = -1;
public static int[] hotkeysIndices = new int[3] { 37, 38, 39 };
public static string[] hotkeyTexts = new string[3]
{
PluginConfig.QuickSlot1.Value.ToShortString(),
PluginConfig.QuickSlot2.Value.ToShortString(),
PluginConfig.QuickSlot3.Value.ToShortString()
};
[HarmonyPrefix]
[HarmonyPatch("UpdateIcons")]
public static bool HotkeyBarPrefix(HotkeyBar __instance, Player player)
{
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_0158: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Expected O, but got Unknown
//IL_0196: Unknown result type (might be due to invalid IL or missing references)
//IL_0416: Unknown result type (might be due to invalid IL or missing references)
//IL_040f: Unknown result type (might be due to invalid IL or missing references)
if (((Object)__instance).name != "QuickSlotsHotkeyBar")
{
return true;
}
if (__instance.m_elements == null)
{
return false;
}
foreach (ElementData element in __instance.m_elements)
{
Object.Destroy((Object)(object)element.m_go);
}
__instance.m_elements.Clear();
if ((Object)(object)player == (Object)null || ((Character)player).IsDead() || !PluginConfig.EnableQuickslots.Value || __instance.m_items == null)
{
return false;
}
hotkeyTexts = new string[3]
{
PluginConfig.QuickSlot1.Value.ToShortString(),
PluginConfig.QuickSlot2.Value.ToShortString(),
PluginConfig.QuickSlot3.Value.ToShortString()
};
__instance.m_items = new List<ItemData>();
for (int i = 5; i < 8; i++)
{
if (((Humanoid)player).GetInventory().GetItemAt(i, 4) != null)
{
__instance.m_items.Add(((Humanoid)player).GetInventory().GetItemAt(i, 4));
}
}
for (int j = 0; j < 3; j++)
{
ElementData val = new ElementData
{
m_go = Object.Instantiate<GameObject>(__instance.m_elementPrefab, ((Component)__instance).transform)
};
val.m_go.transform.localPosition = new Vector3((float)j * __instance.m_elementSpace, 0f, 0f);
val.m_icon = ((Component)((Component)val.m_go.transform).transform.Find("icon")).GetComponent<Image>();
val.m_durability = ((Component)val.m_go.transform.Find("durability")).GetComponent<GuiBar>();
val.m_amount = ((Component)val.m_go.transform.Find("amount")).GetComponent<TMP_Text>();
val.m_equiped = ((Component)val.m_go.transform.Find("equiped")).gameObject;
val.m_queued = ((Component)val.m_go.transform.Find("queued")).gameObject;
val.m_selection = ((Component)val.m_go.transform.Find("selected")).gameObject;
TMP_Text component = ((Component)val.m_go.transform.Find("binding")).GetComponent<TMP_Text>();
((Behaviour)component).enabled = true;
component.text = hotkeyTexts[j];
__instance.m_elements.Add(val);
}
foreach (ElementData element2 in __instance.m_elements)
{
element2.m_used = false;
}
bool flag = ZInput.IsGamepadActive();
foreach (ItemData item in __instance.m_items)
{
ElementData val2 = __instance.m_elements[item.m_gridPos.x - 5];
val2.m_used = true;
((Component)val2.m_icon).gameObject.SetActive(true);
val2.m_icon.sprite = item.GetIcon();
((Component)val2.m_durability).gameObject.SetActive(item.m_shared.m_useDurability);
if (item.m_shared.m_useDurability)
{
if ((double)item.m_durability <= 0.0)
{
val2.m_durability.SetValue(1f);
val2.m_durability.SetColor((Color)(((double)Mathf.Sin(Time.time * 10f) > 0.0) ? Color.red : new Color(0f, 0f, 0f, 0f)));
}
else
{
val2.m_durability.SetValue(item.GetDurabilityPercentage());
val2.m_durability.ResetColor();
}
}
val2.m_equiped.SetActive(item.m_equipped);
val2.m_queued.SetActive(player.IsEquipActionQueued(item));
if (item.m_shared.m_maxStackSize > 1)
{
((Component)val2.m_amount).gameObject.SetActive(true);
val2.m_amount.text = item.m_stack + "/" + item.m_shared.m_maxStackSize;
}
else
{
((Component)val2.m_amount).gameObject.SetActive(false);
}
}
for (int k = 0; k < __instance.m_elements.Count; k++)
{
ElementData val3 = __instance.m_elements[k];
val3.m_selection.SetActive(flag && k == __instance.m_selected);
if (!val3.m_used)
{
((Component)val3.m_icon).gameObject.SetActive(false);
((Component)val3.m_durability).gameObject.SetActive(false);
val3.m_equiped.SetActive(false);
val3.m_queued.SetActive(false);
((Component)val3.m_amount).gameObject.SetActive(false);
}
}
return false;
}
}
[HarmonyPatch(typeof(Humanoid))]
public class HumanoidPatch
{
public static ItemData unequippedItem;
public static bool wasEquipped { get; set; }
[HarmonyPrefix]
[HarmonyPatch("EquipItem")]
public static bool EquipItemPrefix(Humanoid __instance, bool __result, ItemData item)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
if (ComfyQuickSlots.IsArmor(item))
{
Vector2i armorSlot = ComfyQuickSlots.GetArmorSlot(item);
if (ComfyQuickSlots.IsArmorTypeEquipped(__instance, item) && ComfyQuickSlots.IsArmorTypeEquipped(__instance, item))
{
ItemData armorItemToSwap = ComfyQuickSlots.GetArmorItemToSwap(__instance, item);
ComfyQuickSlots.UnequipItem(__instance, armorItemToSwap);
ComfyQuickSlots.log("Armor item already equipped. Swapping " + item.m_shared.m_name + " for " + armorItemToSwap.m_shared.m_name);
ComfyQuickSlots.EquipItem(__instance, item);
ComfyQuickSlots.MoveArmorItemToSlot(__instance, item, armorSlot.x, armorSlot.y);
__result = true;
return false;
}
ComfyQuickSlots.log("Equipping item " + item.m_shared.m_name);
ComfyQuickSlots.EquipItem(__instance, item);
if (item.m_gridPos.x != armorSlot.x || item.m_gridPos.y != armorSlot.y)
{
ComfyQuickSlots.MoveArmorItemToSlot(__instance, item, armorSlot.x, armorSlot.y);
ComfyQuickSlots.log($"Moving armor to item slot {armorSlot.x},{armorSlot.y}");
}
__result = true;
return false;
}
return true;
}
[HarmonyPostfix]
[HarmonyPatch("EquipItem")]
public static void EquipItemPostfix(Humanoid __instance, ItemData item)
{
if ((Object)(object)__instance != (Object)null && item != null)
{
ComfyQuickSlots.log($"Item equipped {item.m_equipped}");
__instance.GetInventory().Changed();
}
}
[HarmonyPrefix]
[HarmonyPatch("UnequipItem")]
public static bool UnequipItemPrefix(Humanoid __instance, ItemData item, bool triggerEquipEffects)
{
//IL_006f: 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_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
if (item != null && ComfyQuickSlots.IsArmor(item) && item.m_equipped)
{
if (!ComfyQuickSlots.HaveEmptyInventorySlot(__instance.GetInventory()))
{
ComfyQuickSlots.log("No empty slots found. Will not unequip item.");
((Character)__instance).Message((MessageType)2, "Inventory full. Item not unequipped.", 0, (Sprite)null);
return false;
}
ComfyQuickSlots.log("Unequipping item.");
ComfyQuickSlots.UnequipItem(__instance, item);
Vector2i emptyInventorySlot = ComfyQuickSlots.GetEmptyInventorySlot(__instance.GetInventory(), topFirst: true);
ComfyQuickSlots.MoveArmorItemToSlot(__instance, item, emptyInventorySlot.x, emptyInventorySlot.y);
return false;
}
return true;
}
[HarmonyPostfix]
[HarmonyPatch("UnequipItem")]
public static void UnequipItemPostfix(Humanoid __instance, ItemData item, bool triggerEquipEffects)
{
if ((Object)(object)__instance != (Object)null && item != null)
{
ComfyQuickSlots.log("Unequipping item complete.");
}
}
}
[HarmonyPatch(typeof(Inventory))]
public static class InventoryPatch
{
[HarmonyPrefix]
[HarmonyPatch(typeof(Inventory), "AddItem", new Type[]
{
typeof(ItemData),
typeof(int),
typeof(int),
typeof(int)
})]
public static bool AddItemPositionPrefix(Inventory __instance, ItemData item, int amount, int x, int y)
{
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
if (item != null && __instance.m_name == "ComfyQuickSlotsInventory")
{
Vector2i val = default(Vector2i);
((Vector2i)(ref val))..ctor(x, y);
ComfyQuickSlots.log($"Attempting to add item {item.m_shared.m_name} to {x},{y}. Is equipped? {item.m_equipped}. Local Player?{(Object)(object)Player.m_localPlayer != (Object)null}. On Menu Load? {ComfyQuickSlots.onMenuLoad}");
if (ComfyQuickSlots.firstLoad && ComfyQuickSlots.IsArmor(item) && item.m_equipped)
{
ComfyQuickSlots.log("Adding " + item.m_shared.m_name + " to initial armor list. Item not added to inventory");
if (!ComfyQuickSlots.initialEquippedArmor.Contains(item))
{
ComfyQuickSlots.initialEquippedArmor.Add(item);
}
return false;
}
if (item.m_equipped && ComfyQuickSlots.IsArmor(item) && (Object)(object)Player.m_localPlayer != (Object)null)
{
ComfyQuickSlots.UnequipItem((Humanoid)(object)Player.m_localPlayer, item);
Vector2i armorSlot = ComfyQuickSlots.GetArmorSlot(item);
if (x == armorSlot.x && y == armorSlot.y)
{
ComfyQuickSlots.log("Adding equipped item " + item.m_shared.m_name + " to armor slot.");
return true;
}
return false;
}
if ((Object)(object)Player.m_localPlayer == (Object)null)
{
ComfyQuickSlots.log("Adding item during menu loading phase.");
return true;
}
if (x < 5 && y == 4)
{
return false;
}
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Inventory), "MoveItemToThis", new Type[]
{
typeof(Inventory),
typeof(ItemData),
typeof(int),
typeof(int),
typeof(int)
})]
public static bool MoveItemToThisPrefix(Inventory __instance, ref bool __result, Inventory fromInventory, ItemData item, int amount, int x, int y)
{
if (__instance.m_name.Equals("ComfyQuickSlotsInventory") && x < 5 && y == 4)
{
return false;
}
ComfyQuickSlots.log($"Moving {item.m_shared.m_name} from {item.m_gridPos.x},{item.m_gridPos.y} in {fromInventory.m_name} to {x},{y} {__instance.m_name}");
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Inventory), "FindEmptySlot")]
public static bool FindEmptySlotPrefix(Inventory __instance, bool topFirst, ref Vector2i __result)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
if (__instance.m_name == "ComfyQuickSlotsInventory")
{
__result = ComfyQuickSlots.GetEmptyInventorySlot(__instance, topFirst);
ComfyQuickSlots.log($"Found empty slot in ${__instance.m_name} at {__result.x},{__result.y}");
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Inventory), "HaveEmptySlot")]
public static bool HaveEmptySlotPrefix(Inventory __instance, ref bool __result)
{
ComfyQuickSlots.log("Checking have empty slots");
if (__instance.m_name == "ComfyQuickSlotsInventory")
{
__result = ComfyQuickSlots.HaveEmptyInventorySlot(__instance);
return false;
}
return true;
}
}
[HarmonyPatch(typeof(Player))]
public static class PlayerPatch
{
[HarmonyPrefix]
[HarmonyPatch("Awake")]
public static void PlayerAwakePrefix(ref Player __instance)
{
((Humanoid)__instance).m_inventory.m_name = "ComfyQuickSlotsInventory";
((Humanoid)__instance).m_inventory.m_height = 5;
((Humanoid)__instance).m_inventory.m_width = 8;
}
[HarmonyPostfix]
[HarmonyPatch("Load")]
public static void PlayerLoadPostFix(Player __instance)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: 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_00be: Unknown result type (might be due to invalid IL or missing references)
if (__instance.m_knownTexts.ContainsKey("ComfyQuickSlotsInventory"))
{
ZPackage val = new ZPackage(__instance.m_knownTexts["ComfyQuickSlotsInventory"]);
((Humanoid)__instance).GetInventory().Load(val);
ComfyQuickSlots.EquipArmorInArmorSlots(__instance);
((Humanoid)__instance).GetInventory().Changed();
}
else
{
ComfyQuickSlots.firstLoad = true;
ZLog.Log((object)$"First load with {ComfyQuickSlots.initialEquippedArmor.Count}");
foreach (ItemData item in ComfyQuickSlots.initialEquippedArmor)
{
ComfyQuickSlots.UnequipItem((Humanoid)(object)__instance, item);
((Humanoid)__instance).GetInventory().AddItem(item);
((Humanoid)__instance).EquipItem(item, true);
Vector2i armorSlot = ComfyQuickSlots.GetArmorSlot(item);
ComfyQuickSlots.MoveArmorItemToSlot((Humanoid)(object)__instance, item, armorSlot.x, armorSlot.y);
((Humanoid)__instance).GetInventory().Changed();
}
ComfyQuickSlots.initialEquippedArmor = new List<ItemData>();
}
foreach (ItemData item2 in ((Humanoid)__instance).GetInventory().m_inventory)
{
if (item2.IsEquipable() && !ComfyQuickSlots.IsArmor(item2) && item2.m_equipped)
{
((Humanoid)__instance).EquipItem(item2, true);
}
}
}
[HarmonyPrefix]
[HarmonyPatch("Save")]
public static bool PlayerSavePrefix(Player __instance)
{
ComfyQuickSlots.firstLoad = false;
return ComfyQuickSlots.Save(__instance);
}
[HarmonyPrefix]
[HarmonyPatch("UseHotbarItem")]
public static bool UseHotBarItemPrefix(Player __instance, int index)
{
ItemData itemAt = ((Humanoid)__instance).m_inventory.GetItemAt(index - 1, 0);
if (__instance.IsEquipActionQueued(itemAt))
{
return false;
}
return true;
}
}
[HarmonyPatch(typeof(Player))]
internal static class TombstonePatcher
{
[HarmonyPrefix]
[HarmonyPatch("CreateTombStone")]
private static void CreateTombStonePrefix(Player __instance)
{
Directory.CreateDirectory(PluginConfig.LogFilesPath.Value);
string path = __instance.GetPlayerID() + ".csv";
InventoryLogger.LogInventoryToFile(((Humanoid)__instance).GetInventory(), Path.Combine(PluginConfig.LogFilesPath.Value, path));
ComfyQuickSlots.UnequipAllArmor(__instance);
GameObject val = CreateAdditionalTombstone(__instance);
SetupAdditionalTombstone(val.GetComponent<TombStone>());
Container component = val.GetComponent<Container>();
Inventory inventory = component.GetInventory();
((Humanoid)__instance).UnequipAllItems();
Inventory inventory2 = ((Humanoid)__instance).GetInventory();
List<ItemData> list = new List<ItemData>(inventory2.GetAllItems());
foreach (ItemData item in list)
{
if (item.m_gridPos.y >= 4 && !item.m_equipped)
{
inventory.AddItem(item);
inventory2.RemoveItem(item);
}
}
((Humanoid)__instance).GetInventory().m_height = 4;
((Humanoid)__instance).GetInventory().m_width = 8;
}
private static GameObject CreateAdditionalTombstone(Player player)
{
//IL_0008: 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_0017: 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_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
GameObject val = Object.Instantiate<GameObject>(player.m_tombstone, ((Character)player).GetCenterPoint() + Vector3.up * 1.25f, ((Component)player).transform.rotation);
Transform transform = val.transform;
transform.localScale -= new Vector3(0.5f, 0.5f, 0.5f);
return val;
}
private static void SetupAdditionalTombstone(TombStone tombstone)
{
PlayerProfile playerProfile = Game.instance.GetPlayerProfile();
tombstone.m_nview.m_zdo.Set(ZDOVars.s_owner, playerProfile.GetPlayerID());
tombstone.m_nview.m_zdo.Set(ZDOVars.s_ownerName, playerProfile.GetName());
tombstone.m_nview.m_zdo.Set(ComfyQuickSlots.IsAdditionalTombstoneField, true);
}
[HarmonyPostfix]
[HarmonyPatch("CreateTombStone")]
private static void CreateTombStonePostfix(Player __instance)
{
((Humanoid)__instance).GetInventory().m_height = 5;
((Humanoid)__instance).GetInventory().m_width = 8;
}
}
}
namespace ComfyQuickSlots.Patches
{
[HarmonyPatch(typeof(FejdStartup))]
public class FejdStartupPatcher
{
[HarmonyPrefix]
[HarmonyPatch("SetupCharacterPreview")]
public static void FejdStartupSetupCharacterPreviewPrefix(FejdStartup __instance)
{
ComfyQuickSlots.initialEquippedArmor = new List<ItemData>();
ComfyQuickSlots.firstLoad = false;
}
}
[HarmonyPatch(typeof(Hud))]
public static class Hud_Awake_Patch
{
private static HotkeyBar hotkeyBar;
[HarmonyPostfix]
[HarmonyPatch("Awake")]
public static void AwakePostfix(Hud __instance)
{
hotkeyBar = ((Component)__instance).GetComponentInChildren<HotkeyBar>();
if (PluginConfig.IsModEnabled.Value && !Object.op_Implicit((Object)(object)HotkeyBarPatch.QuickSlotsHotkeyBar) && PluginConfig.EnableQuickslots.Value)
{
HotkeyBarPatch.QuickSlotsHotkeyBar = Object.Instantiate<GameObject>(((Component)hotkeyBar).gameObject, __instance.m_rootObject.transform, true);
((Object)HotkeyBarPatch.QuickSlotsHotkeyBar).name = "QuickSlotsHotkeyBar";
HotkeyBarPatch.QuickSlotsHotkeyBar.GetComponent<HotkeyBar>().m_selected = -1;
ConfigPositionedElement configPositionedElement = HotkeyBarPatch.QuickSlotsHotkeyBar.AddComponent<ConfigPositionedElement>();
configPositionedElement.PositionConfig = PluginConfig.QuickSlotsPosition;
configPositionedElement.AnchorConfig = PluginConfig.QuickSlotsAnchor;
configPositionedElement.EnsureCorrectPosition();
}
}
[HarmonyPostfix]
[HarmonyPatch("Update")]
public static void UpdatePostfix(Hud __instance)
{
if (!PluginConfig.IsModEnabled.Value || Object.op_Implicit((Object)(object)HotkeyBarPatch.QuickSlotsHotkeyBar) || !PluginConfig.EnableQuickslots.Value)
{
return;
}
HotkeyBarPatch.QuickSlotsHotkeyBar = Object.Instantiate<GameObject>(((Component)hotkeyBar).gameObject, __instance.m_rootObject.transform, true);
((Object)HotkeyBarPatch.QuickSlotsHotkeyBar).name = "QuickSlotsHotkeyBar";
HotkeyBar component = HotkeyBarPatch.QuickSlotsHotkeyBar.GetComponent<HotkeyBar>();
component.m_selected = -1;
ConfigPositionedElement configPositionedElement = HotkeyBarPatch.QuickSlotsHotkeyBar.AddComponent<ConfigPositionedElement>();
configPositionedElement.PositionConfig = PluginConfig.QuickSlotsPosition;
configPositionedElement.AnchorConfig = PluginConfig.QuickSlotsAnchor;
configPositionedElement.EnsureCorrectPosition();
component.m_items.Clear();
foreach (ElementData element in component.m_elements)
{
Object.Destroy((Object)(object)element.m_go);
}
component.m_elements.Clear();
}
}
[HarmonyPatch(typeof(InventoryGrid))]
public static class InventoryGridPatch
{
[HarmonyPostfix]
[HarmonyPatch("UpdateGui")]
public static void UpdateGuiPostfix(ref InventoryGrid __instance, Player player, ItemData dragItem)
{
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0329: Unknown result type (might be due to invalid IL or missing references)
//IL_035b: Unknown result type (might be due to invalid IL or missing references)
//IL_038d: Unknown result type (might be due to invalid IL or missing references)
if (((Object)__instance).name == "PlayerGrid")
{
float num = 1f;
float num2 = -35f * num;
RectTransform orCreateBackground = GetOrCreateBackground(__instance, "ExtInvGrid");
orCreateBackground.anchoredPosition = new Vector2(0f, num2);
orCreateBackground.SetSizeWithCurrentAnchors((Axis)0, 590f);
orCreateBackground.SetSizeWithCurrentAnchors((Axis)1, 300f + 75f * num);
TMP_Text component = ((Component)__instance.m_elements[32].m_go.transform.Find("binding")).GetComponent<TMP_Text>();
component.text = "Head";
((Behaviour)component).enabled = true;
component.fontSize = 12f;
component.overflowMode = (TextOverflowModes)0;
component.textWrappingMode = (TextWrappingModes)0;
TMP_Text component2 = ((Component)__instance.m_elements[33].m_go.transform.Find("binding")).GetComponent<TMP_Text>();
component2.text = "Chest";
((Behaviour)component2).enabled = true;
component2.fontSize = 12f;
component2.alignment = (TextAlignmentOptions)257;
component2.overflowMode = (TextOverflowModes)0;
component2.textWrappingMode = (TextWrappingModes)0;
TMP_Text component3 = ((Component)__instance.m_elements[34].m_go.transform.Find("binding")).GetComponent<TMP_Text>();
component3.text = "Legs";
((Behaviour)component3).enabled = true;
component3.fontSize = 12f;
component3.alignment = (TextAlignmentOptions)257;
component3.overflowMode = (TextOverflowModes)0;
component3.textWrappingMode = (TextWrappingModes)0;
TMP_Text component4 = ((Component)__instance.m_elements[35].m_go.transform.Find("binding")).GetComponent<TMP_Text>();
component4.text = "Cape";
((Behaviour)component4).enabled = true;
component4.fontSize = 12f;
component4.alignment = (TextAlignmentOptions)257;
component4.overflowMode = (TextOverflowModes)0;
component4.textWrappingMode = (TextWrappingModes)0;
TMP_Text component5 = ((Component)__instance.m_elements[36].m_go.transform.Find("binding")).GetComponent<TMP_Text>();
component5.text = "Util";
((Behaviour)component5).enabled = true;
component5.fontSize = 12f;
component5.alignment = (TextAlignmentOptions)257;
component5.overflowMode = (TextOverflowModes)0;
component5.textWrappingMode = (TextWrappingModes)0;
TMP_Text component6 = ((Component)__instance.m_elements[37].m_go.transform.Find("binding")).GetComponent<TMP_Text>();
TMP_Text component7 = ((Component)__instance.m_elements[38].m_go.transform.Find("binding")).GetComponent<TMP_Text>();
TMP_Text component8 = ((Component)__instance.m_elements[39].m_go.transform.Find("binding")).GetComponent<TMP_Text>();
if (!PluginConfig.EnableQuickslots.Value)
{
((Behaviour)component6).enabled = false;
((Behaviour)component7).enabled = false;
((Behaviour)component8).enabled = false;
return;
}
component6.text = PluginConfig.QuickSlot1.Value.ToShortString();
((Behaviour)component6).enabled = true;
component6.overflowMode = (TextOverflowModes)0;
component6.textWrappingMode = (TextWrappingModes)0;
component7.text = PluginConfig.QuickSlot2.Value.ToShortString();
((Behaviour)component7).enabled = true;
component7.overflowMode = (TextOverflowModes)0;
component7.textWrappingMode = (TextWrappingModes)0;
component8.text = PluginConfig.QuickSlot3.Value.ToShortString();
((Behaviour)component8).enabled = true;
component8.overflowMode = (TextOverflowModes)0;
component8.textWrappingMode = (TextWrappingModes)0;
}
}
private static RectTransform GetOrCreateBackground(InventoryGrid __instance, string name)
{
Transform val = ((Component)__instance).transform.parent.Find(name);
if ((Object)(object)val == (Object)null)
{
GameObject gameObject = ((Component)((Component)__instance).transform.parent.Find("Bkg")).gameObject;
GameObject val2 = Object.Instantiate<GameObject>(gameObject, gameObject.transform.parent);
((Object)val2).name = name;
val2.transform.SetSiblingIndex(gameObject.transform.GetSiblingIndex() + 1);
val = val2.transform;
}
return (RectTransform)(object)((val is RectTransform) ? val : null);
}
}
[HarmonyPatch(typeof(InventoryGui))]
public class InventoryGuiPatch
{
[HarmonyPrefix]
[HarmonyPatch("OnSelectedItem")]
public static bool OnSelectedItemPrefix(InventoryGrid grid, ItemData item, Vector2i pos, Modifier mod)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
if (ComfyQuickSlots.IsArmorSlot(pos))
{
return false;
}
if (Player.m_localPlayer.IsEquipActionQueued(item))
{
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch("OnCraftPressed")]
public static bool OnCraftPressedPrefix(ref InventoryGui __instance)
{
if (__instance.m_selectedRecipe.Value != null && __instance.m_selectedRecipe.Value.m_equipped && !ComfyQuickSlots.HaveEmptyInventorySlot(((Humanoid)Player.m_localPlayer).GetInventory()) && ComfyQuickSlots.ItemCountInInventory(__instance.m_selectedRecipe.Value) == 1)
{
((Character)Player.m_localPlayer).Message((MessageType)2, "Inventory full. Make room to upgrade equipped item.", 0, (Sprite)null);
return false;
}
return true;
}
}
}