Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Steelhammer CoinPouchExpansion v1.0.11
BepInEx/plugins/Steelhammer_CoinPouchExpansion/Steelhammer_CoinPouchExpansion.dll
Decompiled 3 days agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.UI; [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: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.0")] [module: UnverifiableCode] [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 SteelhammerEssentialsPouchPatch { [HarmonyPatch(typeof(GameCamera), "LateUpdate")] internal static class CameraLateUpdateBridge { private static void Postfix() { SmartHotbarModule.LateUpdate(); } } internal static class CraftFromStorageModule { [HarmonyPatch(typeof(Player), "HaveRequirementItems")] private static class HaveRequirementItemsPatch { private static bool Prefix(Player __instance, Recipe piece, bool discover, int qualityLevel, int amount, ref bool __result) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Expected O, but got Unknown if (Enabled == null || !Enabled.Value || discover || (Object)piece == (Object)null) { return true; } CraftingStation station = GetStation(__instance); Requirement[] resources = piece.m_resources; if (resources == null) { return true; } Requirement[] array = resources; foreach (Requirement val in array) { if (val == null || (Object)val.m_resItem == (Object)null || !RequirementMatchesStation(val, station)) { continue; } int num = val.GetAmount(qualityLevel) * amount; if (num <= 0) { continue; } string name = val.m_resItem.m_itemData.m_shared.m_name; int num2 = Mathf.Max(1, val.m_resItem.m_itemData.m_shared.m_maxQuality); int num3 = 0; for (int j = 1; j <= num2; j++) { int num4 = CountAvailable(__instance, name, j); if (num4 > num3) { num3 = num4; } } if (piece.m_requireOnlyOneIngredient) { if (num3 >= num) { __result = true; return false; } } else if (num3 < num) { __result = false; return false; } } __result = !piece.m_requireOnlyOneIngredient; return false; } } [HarmonyPatch(typeof(Player), "ConsumeResources")] private static class ConsumeResourcesPatch { private static bool Prefix(Player __instance, Requirement[] requirements, int qualityLevel, int itemQuality, int multiplier) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown if (Enabled == null || !Enabled.Value || requirements == null) { return true; } CraftingStation station = GetStation(__instance); List<Container> nearbyContainers = GetNearbyContainers(((Component)__instance).transform.position); foreach (Requirement val in requirements) { if (val == null || (Object)val.m_resItem == (Object)null || !RequirementMatchesStation(val, station)) { continue; } int num = val.GetAmount(qualityLevel) * multiplier; if (num <= 0) { continue; } string name = val.m_resItem.m_itemData.m_shared.m_name; Inventory inventory = ((Humanoid)__instance).GetInventory(); int val2 = inventory.CountItems(name, -1, true); int num2 = Math.Min(num, val2); if (num2 > 0) { inventory.RemoveItem(name, num2, itemQuality, true); num -= num2; } foreach (Container item in nearbyContainers) { if (num <= 0) { break; } Inventory inventory2 = item.GetInventory(); if (inventory2 != null) { int val3 = inventory2.CountItems(name, -1, true); int num3 = Math.Min(num, val3); if (num3 > 0) { inventory2.RemoveItem(name, num3, itemQuality, true); num -= num3; } } } } return false; } } [HarmonyPatch(typeof(Player), "HaveRequirements", new Type[] { typeof(Piece), typeof(RequirementMode) })] private static class HaveBuildRequirementsPatch { private static bool Prefix(Player __instance, Piece piece, RequirementMode mode, ref bool __result) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Invalid comparison between Unknown and I4 //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Invalid comparison between Unknown and I4 //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Expected O, but got Unknown //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Invalid comparison between Unknown and I4 //IL_00b1: 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_00c6: Expected O, but got Unknown //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Expected O, but got Unknown //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Invalid comparison between Unknown and I4 //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Invalid comparison between Unknown and I4 if (Enabled == null || !Enabled.Value || (Object)piece == (Object)null) { return true; } if ((int)mode == 1) { return true; } if ((Object)ZoneSystem.instance != (Object)null && ZoneSystem.instance.GetGlobalKey(piece.FreeBuildKey())) { __result = true; return false; } if ((Object)piece.m_craftingStation != (Object)null) { if ((int)mode == 2 && (!(KnownStationsField?.GetValue(__instance) is Dictionary<string, int> dictionary) || !dictionary.ContainsKey(piece.m_craftingStation.m_name))) { __result = false; return false; } if ((int)mode != 2 && (Object)CraftingStation.HaveBuildStationInRange(piece.m_craftingStation.m_name, ((Component)__instance).transform.position) == (Object)null) { __result = false; return false; } } if (!string.IsNullOrEmpty(piece.m_dlc) && (Object)DLCMan.instance != (Object)null && !DLCMan.instance.IsDLCInstalled(piece.m_dlc)) { __result = false; return false; } Requirement[] resources = piece.m_resources; if (resources == null) { __result = true; return false; } Requirement[] array = resources; foreach (Requirement val in array) { if (val != null && !((Object)val.m_resItem == (Object)null) && val.m_amount > 0) { string name = val.m_resItem.m_itemData.m_shared.m_name; int num = CountAvailable(__instance, name); if ((int)mode == 2 && num <= 0) { __result = false; return false; } if ((int)mode != 2 && num < val.m_amount) { __result = false; return false; } } } __result = true; return false; } } [HarmonyPatch(typeof(InventoryGui), "SetupRequirement")] private static class SetupRequirementPatch { private static void Postfix(Transform elementRoot, Requirement req, Player player, bool craft, int quality, int craftMultiplier, bool __result) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected O, but got Unknown //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Expected O, but got Unknown //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Expected O, but got Unknown //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Expected O, but got Unknown //IL_00e2: Unknown result type (might be due to invalid IL or missing references) if (Enabled == null || !Enabled.Value || ShowCombinedAmounts == null || !ShowCombinedAmounts.Value || !__result || (Object)elementRoot == (Object)null || req == null || (Object)req.m_resItem == (Object)null || (Object)player == (Object)null) { return; } int num = req.GetAmount(quality) * craftMultiplier; if (num <= 0) { return; } Transform val = elementRoot.Find("res_amount"); if ((Object)val == (Object)null) { return; } TMP_Text component = ((Component)val).GetComponent<TMP_Text>(); if (!((Object)component == (Object)null)) { string name = req.m_resItem.m_itemData.m_shared.m_name; int num2 = CountAvailable(player, name); component.text = num + "/" + num2; if (num2 >= num) { ((Graphic)component).color = Color.white; } } } } [HarmonyPatch(typeof(Smelter), "OnAddOre")] private static class AddOrePatch { private static void Prefix(Smelter __instance, Humanoid user, ItemData item) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown //IL_007a: 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) //IL_00c4: Expected O, but got Unknown //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Expected O, but got Unknown if (Enabled == null || !Enabled.Value || FeedProcessingStations == null || !FeedProcessingStations.Value || (Object)__instance == (Object)null || (Object)user == (Object)null || item != null || FindCookableItem == null || FindCookableItem.Invoke(__instance, new object[1] { user.GetInventory() }) is ItemData) { return; } foreach (Container nearbyContainer in GetNearbyContainers(((Component)user).transform.position)) { Inventory inventory = nearbyContainer.GetInventory(); if (inventory != null) { object obj = FindCookableItem.Invoke(__instance, new object[1] { inventory }); ItemData val = (ItemData)((obj is ItemData) ? obj : null); if (val != null && !((Object)val.m_dropPrefab == (Object)null)) { GameObject dropPrefab = val.m_dropPrefab; inventory.RemoveOneItem(val); user.GetInventory().AddItem(dropPrefab, 1); break; } } } } } [HarmonyPatch(typeof(Smelter), "OnAddFuel")] private static class AddFuelPatch { private static void Prefix(Smelter __instance, Humanoid user, ItemData item) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Expected O, but got Unknown //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Expected O, but got Unknown //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Expected O, but got Unknown if (Enabled == null || !Enabled.Value || FeedProcessingStations == null || !FeedProcessingStations.Value || (Object)__instance == (Object)null || (Object)user == (Object)null || item != null || SmelterFuelItem == null) { return; } object value = SmelterFuelItem.GetValue(__instance); ItemDrop val = (ItemDrop)((value is ItemDrop) ? value : null); if ((Object)val == (Object)null) { return; } string name = val.m_itemData.m_shared.m_name; if (user.GetInventory().HaveItem(name, true)) { return; } foreach (Container nearbyContainer in GetNearbyContainers(((Component)user).transform.position)) { Inventory inventory = nearbyContainer.GetInventory(); if (inventory != null) { ItemData item2 = inventory.GetItem(name, -1, false); if (item2 != null && !((Object)item2.m_dropPrefab == (Object)null)) { GameObject dropPrefab = item2.m_dropPrefab; inventory.RemoveOneItem(item2); user.GetInventory().AddItem(dropPrefab, 1); break; } } } } } internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<int> SearchRadius; internal static ConfigEntry<bool> ShowCombinedAmounts; internal static ConfigEntry<bool> FeedProcessingStations; private static readonly MethodInfo ContainerCheckAccess = AccessTools.Method(typeof(Container), "CheckAccess", new Type[1] { typeof(long) }, (Type[])null); private static readonly MethodInfo GetCurrentCraftingStation = AccessTools.Method(typeof(Player), "GetCurrentCraftingStation", (Type[])null, (Type[])null); private static readonly FieldInfo KnownStationsField = AccessTools.Field(typeof(Player), "m_knownStations"); private static readonly MethodInfo FindCookableItem = AccessTools.Method(typeof(Smelter), "FindCookableItem", new Type[1] { typeof(Inventory) }, (Type[])null); private static readonly FieldInfo SmelterFuelItem = AccessTools.Field(typeof(Smelter), "m_fuelItem"); internal static void Bind(ConfigFile config) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Expected O, but got Unknown //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected O, but got Unknown Enabled = config.Bind<bool>("03 - Craft From Storage", "Enabled", true, "Erlaubt Craften, Upgraden und Bauen mit Materialien aus nahen Kisten."); SearchRadius = config.Bind<int>("03 - Craft From Storage", "SearchRadiusMeters", 100, new ConfigDescription("Reichweite in Metern für Craften, Upgraden und Bauen aus Kisten. Einstellbar von 1 bis 500 Meter.", (AcceptableValueBase)new AcceptableValueRange<int>(1, 500), Array.Empty<object>())); ShowCombinedAmounts = config.Bind<bool>("03 - Craft From Storage", "ShowCombinedAmounts", true, "Zeigt Inventar + Kisten gemeinsam als verfügbare Materialmenge an."); FeedProcessingStations = config.Bind<bool>("03 - Craft From Storage", "FeedProcessingStations", false, "Erlaubt beim manuellen Befüllen von Öfen/Meilern Material aus Kisten. Bei serverseitigem AutoProcess besser AUS lassen."); } internal static List<Container> GetNearbyContainers(Vector3 position) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Expected O, but got Unknown //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Expected O, but got Unknown List<Container> list = new List<Container>(); if (Enabled == null || !Enabled.Value) { return list; } Collider[] array; try { array = Physics.OverlapSphere(position, (float)SearchRadius.Value); } catch { return list; } if (array == null) { return list; } Collider[] array2 = array; foreach (Collider val in array2) { if ((Object)val == (Object)null) { continue; } Container componentInParent = ((Component)val).GetComponentInParent<Container>(); if (!((Object)componentInParent == (Object)null) && !list.Contains(componentInParent)) { Inventory inventory; try { inventory = componentInParent.GetInventory(); } catch { continue; } if (inventory != null && CanAccess(componentInParent)) { list.Add(componentInParent); } } } return list; } private static bool CanAccess(Container container) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown Player localPlayer = Player.m_localPlayer; if ((Object)localPlayer == (Object)null || ContainerCheckAccess == null) { return true; } try { object obj = ContainerCheckAccess.Invoke(container, new object[1] { localPlayer.GetPlayerID() }); bool flag = false; int num; if (obj is bool) { flag = (bool)obj; num = 1; } else { num = 0; } return (byte)(num & (flag ? 1 : 0)) != 0; } catch { return false; } } internal static int CountAvailable(Player player, string itemName, int quality = -1) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_002d: Unknown result type (might be due to invalid IL or missing references) if ((Object)player == (Object)null || string.IsNullOrEmpty(itemName)) { return 0; } int num = ((Humanoid)player).GetInventory().CountItems(itemName, quality, true); foreach (Container nearbyContainer in GetNearbyContainers(((Component)player).transform.position)) { Inventory inventory = nearbyContainer.GetInventory(); if (inventory != null) { num += inventory.CountItems(itemName, quality, true); } } return num; } private static CraftingStation GetStation(Player player) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected O, but got Unknown if ((Object)player == (Object)null || GetCurrentCraftingStation == null) { return null; } try { object obj = GetCurrentCraftingStation.Invoke(player, null); return (CraftingStation)((obj is CraftingStation) ? obj : null); } catch { return null; } } private static bool RequirementMatchesStation(Requirement requirement, CraftingStation station) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown if (requirement == null) { return false; } if ((Object)station != (Object)null) { return station.m_upgrader == requirement.m_upgraderResource; } return !requirement.m_upgraderResource; } } internal static class EquipmentQuickSlotsModule { [HarmonyPatch(typeof(Player), "Update")] private static class PlayerUpdatePatch { private static void Prefix(Player __instance) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_000f: 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_0023: Expected O, but got Unknown //IL_0023: Expected O, but got Unknown //IL_005c: 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_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) if ((Object)__instance == (Object)null || (Object)__instance != (Object)Player.m_localPlayer) { return; } EnsurePlayer(__instance); if (Time.unscaledTime >= _nextNormalize) { _nextNormalize = Time.unscaledTime + 0.25f; NormalizeReservedSlots(__instance); } if (!CanTakeInput(__instance)) { return; } KeyboardShortcut value = QuickSlot1Key.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { UseQuickSlot(__instance, 0); ConsumeVanillaButtonState(); return; } value = QuickSlot2Key.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { UseQuickSlot(__instance, 1); ConsumeVanillaButtonState(); return; } value = QuickSlot3Key.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { UseQuickSlot(__instance, 2); ConsumeVanillaButtonState(); } } } [HarmonyPatch(typeof(Player), "SetInventorySize")] private static class SetInventorySizePatch { private static void Prefix(Player __instance, ref int rows) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown //IL_0021: 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) //IL_0035: Expected O, but got Unknown //IL_0035: Expected O, but got Unknown if (!((Object)__instance == (Object)null) && (!((Object)Player.m_localPlayer != (Object)null) || !((Object)__instance != (Object)Player.m_localPlayer))) { _baseRows = rows; if (_baseRows <= 7) { rows = Mathf.Min(9, _baseRows + 2); } } } private static void Postfix(Player __instance) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown //IL_0029: 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_003d: Expected O, but got Unknown //IL_003d: Expected O, but got Unknown if ((Object)__instance == (Object)null || _baseRows < 1 || ((Object)Player.m_localPlayer != (Object)null && (Object)__instance != (Object)Player.m_localPlayer) || !(AddUniqueKeyValueMethod != null)) { return; } try { AddUniqueKeyValueMethod.Invoke(__instance, new object[2] { "invrows", _baseRows.ToString() }); } catch { } } } [HarmonyPatch] private static class InventoryLoadPatch { private static IEnumerable<MethodBase> TargetMethods() { MethodInfo methodInfo = AccessTools.Method(typeof(Inventory), "Load", new Type[1] { typeof(ZPackage) }, (Type[])null); MethodInfo two = AccessTools.Method(typeof(Inventory), "Load", new Type[2] { typeof(ZPackage), typeof(bool) }, (Type[])null); if (methodInfo != null) { yield return methodInfo; } if (two != null) { yield return two; } } private static void Prefix(Inventory __instance, out int __state) { __state = -1; if (__instance != null && !(InventoryHeightField == null)) { __state = __instance.GetHeight(); InventoryHeightField.SetValue(__instance, __state + 16); } } private static void Postfix(Inventory __instance, int __state) { if (__instance != null && __state >= 0 && !(InventoryHeightField == null)) { int num = OccupiedRows(__instance); int num2 = Mathf.Max(__state, num); InventoryHeightField.SetValue(__instance, num2); } } } [HarmonyPatch(typeof(Humanoid), "DropInvalidItems")] private static class DropInvalidItemsPatch { private static void Prefix(Humanoid __instance) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown //IL_0021: 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) //IL_0035: Expected O, but got Unknown //IL_0035: Expected O, but got Unknown Player val = (Player)((__instance is Player) ? __instance : null); if (!((Object)val == (Object)null) && !((Object)val != (Object)Player.m_localPlayer)) { EnsurePlayer(val); Inventory inventory = ((Humanoid)val).GetInventory(); int num = Mathf.Max(TargetRows, OccupiedRows(inventory)); if (inventory.GetHeight() < num) { inventory.SetHeight(num); } } } } [HarmonyPatch(typeof(Inventory), "MoveInventoryToGrave")] private static class MoveInventoryToGravePatch { private static void Prefix(Inventory __instance, Inventory original) { if (__instance != null && original != null) { int num = Mathf.Max(original.GetHeight(), OccupiedRows(original)); if (__instance.GetHeight() < num) { __instance.SetHeight(num); } } } } [HarmonyPatch(typeof(Player), "UnequipDeathDropItems")] private static class DeathUnequipPatch { private static void Prefix(Player __instance) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Expected O, but got Unknown //IL_0015: Expected O, but got Unknown if ((Object)__instance == (Object)Player.m_localPlayer) { _deathUnequip = true; } } private static Exception Finalizer(Exception __exception) { _deathUnequip = false; return __exception; } } [HarmonyPatch(typeof(Inventory), "FindEmptySlot")] private static class FindEmptySlotPatch { private static bool Prefix(Inventory __instance, bool topFirst, ref Vector2i __result) { //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: 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_0079: Unknown result type (might be due to invalid IL or missing references) if (!IsPlayerInventory(__instance)) { return true; } EnsurePlayer(Player.m_localPlayer); int width = __instance.GetWidth(); if (topFirst) { for (int i = 0; i < _baseRows; i++) { for (int j = 0; j < width; j++) { if (__instance.GetItemAt(j, i) == null) { __result = new Vector2i(j, i); return false; } } } } if (!topFirst) { for (int num = _baseRows - 1; num >= 0; num--) { for (int k = 0; k < width; k++) { if (__instance.GetItemAt(k, num) == null) { __result = new Vector2i(k, num); return false; } } } } __result = new Vector2i(-1, -1); return false; } } [HarmonyPatch(typeof(Inventory), "GetEmptySlots")] private static class GetEmptySlotsPatch { private static bool Prefix(Inventory __instance, ref int __result) { if (!IsPlayerInventory(__instance)) { return true; } EnsurePlayer(Player.m_localPlayer); int num = 0; for (int i = 0; i < _baseRows; i++) { for (int j = 0; j < __instance.GetWidth(); j++) { if (__instance.GetItemAt(j, i) == null) { num++; } } } __result = num; return false; } } [HarmonyPatch(typeof(Inventory), "HaveEmptySlot")] private static class HaveEmptySlotPatch { private static bool Prefix(Inventory __instance, ref bool __result) { if (!IsPlayerInventory(__instance)) { return true; } EnsurePlayer(Player.m_localPlayer); __result = false; for (int i = 0; i < _baseRows; i++) { for (int j = 0; j < __instance.GetWidth(); j++) { if (__instance.GetItemAt(j, i) == null) { __result = true; return false; } } } return false; } } [HarmonyPatch(typeof(Inventory), "SlotsUsedPercentage")] private static class SlotsUsedPatch { private static bool Prefix(Inventory __instance, ref float __result) { if (!IsPlayerInventory(__instance)) { return true; } EnsurePlayer(Player.m_localPlayer); int num = __instance.GetWidth() * _baseRows; int num2 = 0; for (int i = 0; i < _baseRows; i++) { for (int j = 0; j < __instance.GetWidth(); j++) { if (__instance.GetItemAt(j, i) != null) { num2++; } } } __result = ((num > 0) ? ((float)num2 / (float)num) : 0f); return false; } } [HarmonyPatch(typeof(Humanoid), "EquipItem")] private static class EquipItemPatch { private static void Postfix(Humanoid __instance, ItemData item, bool __result) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown //IL_003c: Expected O, but got Unknown if (!__result || item == null) { return; } Player val = (Player)((__instance is Player) ? __instance : null); if (!((Object)val == (Object)null) && !((Object)val != (Object)Player.m_localPlayer)) { EnsurePlayer(val); if (EquipmentIndex(item) >= 0) { MoveEquippedItemToSlot(val, item); } } } } [HarmonyPatch(typeof(Humanoid), "UnequipItem")] private static class UnequipItemPatch { private static bool Prefix(Humanoid __instance, ItemData item) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown //IL_0021: 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) //IL_0035: Expected O, but got Unknown //IL_0035: Expected O, but got Unknown //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0065: 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_007e: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) Player val = (Player)((__instance is Player) ? __instance : null); if ((Object)val == (Object)null || (Object)val != (Object)Player.m_localPlayer || item == null || _deathUnequip || _uiDragUnequip || _normalizing) { return true; } EnsurePlayer(val); if (!IsEquipmentPosition(item.m_gridPos) || IsCoinPosition(item.m_gridPos)) { return true; } Vector2i val2 = FindNormalFreeSlot(((Humanoid)val).GetInventory()); if (val2.x < 0 || val2.y < 0) { ManualLogSource modLog = SteelhammerEssentialsPouchPatchPlugin.ModLog; if (modLog != null) { modLog.LogWarning((object)"Ausrüstung konnte nicht abgelegt werden: normales Inventar ist voll."); } return false; } item.m_gridPos = val2; NotifyChanged(((Humanoid)val).GetInventory()); return true; } } [HarmonyPatch(typeof(InventoryGui), "OnSelectedItem")] private static class SelectedItemPatch { private static bool Prefix(InventoryGui __instance, InventoryGrid grid, ItemData item, Vector2i pos) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown //IL_0053: 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_0082: Expected O, but got Unknown //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)localPlayer == (Object)null || (Object)grid == (Object)null) { return true; } EnsurePlayer(localPlayer); object obj = GridInventoryField?.GetValue(grid); if (((obj is Inventory) ? obj : null) != ((Humanoid)localPlayer).GetInventory()) { return true; } if (IsUnusedReservedPosition(pos)) { return false; } object obj2 = GuiDragItemField?.GetValue(__instance); ItemData val = (ItemData)((obj2 is ItemData) ? obj2 : null); if (IsEquipmentPosition(pos)) { if (val != null && !ItemFitsEquipmentPosition(val, pos)) { return false; } if (val == null && item == null) { return false; } } if (val != null && IsEquipmentPosition(val.m_gridPos) && !IsEquipmentPosition(pos) && !IsCoinPosition(val.m_gridPos)) { _uiDragUnequip = true; try { ((Humanoid)localPlayer).UnequipItem(val, true); } finally { _uiDragUnequip = false; } } return true; } private static void Postfix(InventoryGrid grid, Vector2i pos) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005a: 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_0070: 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) Player localPlayer = Player.m_localPlayer; if ((Object)localPlayer == (Object)null || (Object)grid == (Object)null) { return; } object obj = GridInventoryField?.GetValue(grid); Inventory val = (Inventory)((obj is Inventory) ? obj : null); if (val == ((Humanoid)localPlayer).GetInventory() && IsEquipmentPosition(pos)) { ItemData itemAt = val.GetItemAt(pos.x, pos.y); if (itemAt != null && ItemFitsEquipmentPosition(itemAt, pos) && !IsCoinPosition(pos) && !((Humanoid)localPlayer).IsItemEquiped(itemAt)) { ((Humanoid)localPlayer).EquipItem(itemAt, true); } } } } [HarmonyPatch(typeof(InventoryGrid), "UpdateGui")] private static class InventoryGridGuiPatch { private static void Postfix(InventoryGrid __instance) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Expected O, but got Unknown //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: 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_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Expected O, but got Unknown //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Expected O, but got Unknown //IL_00fb: 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_0122: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)localPlayer == (Object)null || (Object)__instance == (Object)null) { return; } EnsurePlayer(localPlayer); object obj = GridInventoryField?.GetValue(__instance); if (((obj is Inventory) ? obj : null) != ((Humanoid)localPlayer).GetInventory() || !(GridElementsField?.GetValue(__instance) is List<InventoryElement> list)) { return; } foreach (InventoryElement item in list) { if ((Object)item == (Object)null) { continue; } Vector2i val = (Vector2i)ElementPositionField.GetValue(item); if (val.y != EquipmentRow && val.y != QuickRow) { continue; } object obj2 = ElementButtonField?.GetValue(item); Button val2 = (Button)((obj2 is Button) ? obj2 : null); if (!((Object)val2 == (Object)null)) { bool flag = IsEquipmentPosition(val) || IsQuickPosition(val); ((Component)val2).gameObject.SetActive(flag); if (flag) { string slotLabel = GetSlotLabel(val); EnsureSlotLabel(item, val2, slotLabel); } } } } } private const int ExtraRows = 2; private const int EquipmentSlotCount = 8; private const int QuickSlotCount = 3; private const string SlotLabelName = "SteelhammerEssentialsPouchPatch_SlotLabel"; internal static ConfigEntry<KeyboardShortcut> QuickSlot1Key; internal static ConfigEntry<KeyboardShortcut> QuickSlot2Key; internal static ConfigEntry<KeyboardShortcut> QuickSlot3Key; internal static ConfigEntry<bool> ShowInventoryLabels; internal static ConfigEntry<bool> ShowQuickSlotHud; private static Player _trackedPlayer; private static int _baseRows = -1; private static float _nextNormalize; private static bool _deathUnequip; private static bool _uiDragUnequip; private static bool _normalizing; private static readonly FieldInfo InventoryHeightField = AccessTools.Field(typeof(Inventory), "m_height"); private static readonly FieldInfo GridInventoryField = AccessTools.Field(typeof(InventoryGrid), "m_inventory"); private static readonly FieldInfo GridElementsField = AccessTools.Field(typeof(InventoryGrid), "m_elements"); private static readonly FieldInfo ElementPositionField = AccessTools.Field(typeof(InventoryElement), "<Position>k__BackingField"); private static readonly FieldInfo ElementButtonField = AccessTools.Field(typeof(InventoryElement), "m_button"); private static readonly FieldInfo ElementAmountField = AccessTools.Field(typeof(InventoryElement), "m_amount"); private static readonly FieldInfo GuiDragItemField = AccessTools.Field(typeof(InventoryGui), "m_dragItem"); private static readonly MethodInfo InventoryChangedMethod = AccessTools.Method(typeof(Inventory), "Changed", new Type[2] { typeof(bool), typeof(bool) }, (Type[])null); private static readonly MethodInfo TakeInputMethod = AccessTools.Method(typeof(Player), "TakeInput", (Type[])null, (Type[])null); private static readonly MethodInfo ResetButtonStatusMethod = AccessTools.Method(typeof(ZInput), "ResetButtonStatus", (Type[])null, (Type[])null); private static readonly MethodInfo AddUniqueKeyValueMethod = AccessTools.Method(typeof(Player), "AddUniqueKeyValue", new Type[2] { typeof(string), typeof(string) }, (Type[])null); private static int EquipmentRow => _baseRows; private static int QuickRow => _baseRows + 1; private static int TargetRows { get { if (_baseRows < 1) { return 6; } return Mathf.Min(9, _baseRows + 2); } } internal static void Bind(ConfigFile config) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) QuickSlot1Key = config.Bind<KeyboardShortcut>("04 - Equipment & Quick Slots", "QuickSlot1", new KeyboardShortcut((KeyCode)122, Array.Empty<KeyCode>()), "Taste für Quickslot 1."); QuickSlot2Key = config.Bind<KeyboardShortcut>("04 - Equipment & Quick Slots", "QuickSlot2", new KeyboardShortcut((KeyCode)118, Array.Empty<KeyCode>()), "Taste für Quickslot 2."); QuickSlot3Key = config.Bind<KeyboardShortcut>("04 - Equipment & Quick Slots", "QuickSlot3", new KeyboardShortcut((KeyCode)98, Array.Empty<KeyCode>()), "Taste für Quickslot 3."); ShowInventoryLabels = config.Bind<bool>("04 - Equipment & Quick Slots", "ShowInventoryLabels", true, "Beschriftet die zusätzlichen Ausrüstungs- und Quickslots."); ShowQuickSlotHud = config.Bind<bool>("04 - Equipment & Quick Slots", "ShowQuickSlotHud", true, "Zeigt Z/V/B zusätzlich im HUD."); } internal static bool IsReservedSlot(Vector2i pos) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0026: 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) Player localPlayer = Player.m_localPlayer; if ((Object)localPlayer == (Object)null) { return false; } EnsurePlayer(localPlayer); if (_baseRows < 1) { return false; } if (pos.y != EquipmentRow) { return pos.y == QuickRow; } return true; } private static bool IsPlayerInventory(Inventory inventory) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown Player localPlayer = Player.m_localPlayer; if ((Object)localPlayer != (Object)null && inventory != null) { return inventory == ((Humanoid)localPlayer).GetInventory(); } return false; } private static void EnsurePlayer(Player player) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_001f: 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_002f: Expected O, but got Unknown //IL_002f: Expected O, but got Unknown if ((Object)player == (Object)null) { return; } Inventory inventory = ((Humanoid)player).GetInventory(); if (inventory == null) { return; } if ((Object)_trackedPlayer != (Object)player) { _trackedPlayer = player; _nextNormalize = 0f; } if (_baseRows < 1) { int height = inventory.GetHeight(); if (height >= 6) { _baseRows = height - 2; } if (height < 6) { _baseRows = Mathf.Max(4, height); } } if (_baseRows > 7) { ManualLogSource modLog = SteelhammerEssentialsPouchPatchPlugin.ModLog; if (modLog != null) { modLog.LogError((object)("Equipment/QuickSlots benötigen zwei freie Inventarreihen. Vanilla-Basis ist bereits " + _baseRows + " Reihen hoch.")); } } else { int targetRows = TargetRows; if (inventory.GetHeight() < targetRows) { inventory.SetHeight(targetRows); } } } private static int OccupiedRows(Inventory inventory) { int num = 0; if (inventory == null) { return num; } foreach (ItemData allItem in inventory.GetAllItems()) { if (allItem != null) { num = Mathf.Max(num, allItem.m_gridPos.y + 1); } } return num; } private static void NotifyChanged(Inventory inventory) { if (inventory == null || InventoryChangedMethod == null) { return; } try { InventoryChangedMethod.Invoke(inventory, new object[2] { true, false }); } catch { } } private static Vector2i FindNormalFreeSlot(Inventory inventory) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) if (inventory == null || _baseRows < 1) { return new Vector2i(-1, -1); } int width = inventory.GetWidth(); for (int i = 0; i < _baseRows; i++) { for (int j = 0; j < width; j++) { if (inventory.GetItemAt(j, i) == null) { return new Vector2i(j, i); } } } return new Vector2i(-1, -1); } private static bool IsNormalPosition(Vector2i pos) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) if (pos.y >= 0) { return pos.y < _baseRows; } return false; } private static bool IsCoin(ItemData item) { if (item == null || item.m_shared == null) { return false; } string name = item.m_shared.m_name; if (!(name == "$item_coins")) { return name == "Coins"; } return true; } private static bool IsCoinPosition(Vector2i pos) { //IL_0008: 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_001e: Unknown result type (might be due to invalid IL or missing references) if (_baseRows >= 1 && pos.y == EquipmentRow) { if (pos.x != 6) { return pos.x == 7; } return true; } return false; } private static int CoinIndex(ItemData item) { if (!IsCoin(item)) { return -1; } return 6; } private static int EquipmentIndex(ItemData item) { if (item == null || item.m_shared == null) { return -1; } return (((object)Unsafe.As<ItemType, ItemType>(ref item.m_shared.m_itemType)/*cast due to .constrained prefix*/).ToString() as string) switch { "Helmet" => 0, "Chest" => 1, "Legs" => 2, "Shoulder" => 3, "Utility" => 4, "Trinket" => 5, _ => -1, }; } private static bool IsEquipmentPosition(Vector2i pos) { //IL_0008: 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_001e: Unknown result type (might be due to invalid IL or missing references) if (_baseRows >= 1 && pos.y == EquipmentRow && pos.x >= 0) { return pos.x < 8; } return false; } private static bool IsQuickPosition(Vector2i pos) { //IL_0008: 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_001e: Unknown result type (might be due to invalid IL or missing references) if (_baseRows >= 1 && pos.y == QuickRow && pos.x >= 0) { return pos.x < 3; } return false; } private static bool IsUnusedReservedPosition(Vector2i pos) { //IL_000a: 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_0017: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) if (_baseRows < 1) { return false; } if (pos.y == EquipmentRow && pos.x >= 8) { return true; } if (pos.y == QuickRow && pos.x >= 3) { return true; } return false; } private static bool ItemFitsEquipmentPosition(ItemData item, Vector2i pos) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) if (item == null || pos.y != EquipmentRow) { return false; } if (IsCoinPosition(pos)) { return IsCoin(item); } int num = EquipmentIndex(item); if (num >= 0) { return pos.x == num; } return false; } private static bool MoveToNormalInventory(Inventory inventory, ItemData item) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: 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_001c: 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) Vector2i val = FindNormalFreeSlot(inventory); if (val.x < 0 || val.y < 0) { return false; } item.m_gridPos = val; return true; } private static bool MoveEquippedItemToSlot(Player player, ItemData item) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006b: 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_007d: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) if ((Object)player == (Object)null || item == null) { return false; } int num = EquipmentIndex(item); if (num < 0) { return false; } Inventory inventory = ((Humanoid)player).GetInventory(); Vector2i val = default(Vector2i); ((Vector2i)(ref val))..ctor(num, EquipmentRow); if (item.m_gridPos.x == val.x && item.m_gridPos.y == val.y) { return true; } ItemData itemAt = inventory.GetItemAt(val.x, val.y); Vector2i gridPos = item.m_gridPos; if (itemAt != null && itemAt != item) { if (IsNormalPosition(gridPos)) { itemAt.m_gridPos = gridPos; } if (!IsNormalPosition(gridPos)) { Vector2i val2 = FindNormalFreeSlot(inventory); if (val2.x < 0 || val2.y < 0) { return false; } itemAt.m_gridPos = val2; } if (((Humanoid)player).IsItemEquiped(itemAt)) { ((Humanoid)player).UnequipItem(itemAt, false); } } item.m_gridPos = val; NotifyChanged(inventory); return true; } private static void NormalizeReservedSlots(Player player) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: 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_006c: 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_007c: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_010c: 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_0183: 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_01a4: Unknown result type (might be due to invalid IL or missing references) if ((Object)player == (Object)null || _normalizing) { return; } _normalizing = true; try { EnsurePlayer(player); Inventory inventory = ((Humanoid)player).GetInventory(); if (inventory == null || _baseRows < 1 || _baseRows > 7) { return; } List<ItemData> list = new List<ItemData>(inventory.GetAllItems()); bool flag = false; foreach (ItemData item in list) { if (item != null) { Vector2i gridPos = item.m_gridPos; if (gridPos.y == EquipmentRow && !ItemFitsEquipmentPosition(item, gridPos) && MoveToNormalInventory(inventory, item)) { flag = true; } if (gridPos.y == QuickRow && gridPos.x >= 3 && MoveToNormalInventory(inventory, item)) { flag = true; } if (gridPos.y > QuickRow && MoveToNormalInventory(inventory, item)) { flag = true; } } } for (int i = 0; i < 8; i++) { ItemData itemAt = inventory.GetItemAt(i, EquipmentRow); if (i < 6 && itemAt != null && ItemFitsEquipmentPosition(itemAt, itemAt.m_gridPos) && !((Humanoid)player).IsItemEquiped(itemAt)) { ((Humanoid)player).EquipItem(itemAt, false); } } Vector2i val = default(Vector2i); foreach (ItemData item2 in new List<ItemData>(inventory.GetAllItems())) { if (item2 == null || !((Humanoid)player).IsItemEquiped(item2)) { continue; } int num = EquipmentIndex(item2); if (num >= 0) { val = new Vector2i(num, EquipmentRow); if ((item2.m_gridPos.x != val.x || item2.m_gridPos.y != val.y) && MoveEquippedItemToSlot(player, item2)) { flag = true; } } } if (flag) { NotifyChanged(inventory); } } finally { _normalizing = false; } } private static bool CanTakeInput(Player player) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown if ((Object)player == (Object)null) { return false; } if (TakeInputMethod == null) { return true; } try { object obj = TakeInputMethod.Invoke(player, null); bool flag = false; int num; if (obj is bool) { flag = (bool)obj; num = 0; } else { num = 1; } return (byte)(num | (flag ? 1 : 0)) != 0; } catch { return true; } } private static void ConsumeVanillaButtonState() { if (ResetButtonStatusMethod == null) { return; } try { ResetButtonStatusMethod.Invoke(null, null); } catch { } } private static void UseQuickSlot(Player player, int index) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown if (!((Object)player == (Object)null) && index >= 0 && index < 3) { EnsurePlayer(player); Inventory inventory = ((Humanoid)player).GetInventory(); ItemData itemAt = inventory.GetItemAt(index, QuickRow); if (itemAt != null) { ((Humanoid)player).UseItem(inventory, itemAt, false); } } } private static string GetSlotLabel(Vector2i pos) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_006c: 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_0079: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_0086: 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) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: 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_00b1: 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_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) if (pos.y == EquipmentRow) { switch (pos.x) { case 0: return "Head"; case 1: return "Chest"; case 2: return "Legs"; case 3: return "Cape"; case 4: return "Utility"; case 5: return "Trinket"; case 6: return "Coin Pouch 1"; case 7: return "Coin Pouch 2"; } } if (pos.y == QuickRow) { KeyboardShortcut value; if (pos.x == 0) { value = QuickSlot1Key.Value; return ((object)((KeyboardShortcut)(ref value)).MainKey).ToString(); } if (pos.x == 1) { value = QuickSlot2Key.Value; return ((object)((KeyboardShortcut)(ref value)).MainKey).ToString(); } if (pos.x == 2) { value = QuickSlot3Key.Value; return ((object)((KeyboardShortcut)(ref value)).MainKey).ToString(); } } return ""; } private static void EnsureSlotLabel(InventoryElement element, Button button, string text) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Expected O, but got Unknown //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0075: 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_0087: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Expected O, but got Unknown //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Expected O, but got Unknown Transform val = ((Component)button).transform.Find("SteelhammerEssentialsPouchPatch_SlotLabel"); TextMeshProUGUI val2 = null; if ((Object)val != (Object)null) { val2 = ((Component)val).GetComponent<TextMeshProUGUI>(); } if ((Object)val2 == (Object)null) { GameObject val3 = new GameObject("SteelhammerEssentialsPouchPatch_SlotLabel", new Type[2] { typeof(RectTransform), typeof(TextMeshProUGUI) }); val3.transform.SetParent(((Component)button).transform, false); RectTransform component = val3.GetComponent<RectTransform>(); component.anchorMin = Vector2.zero; component.anchorMax = Vector2.one; component.offsetMin = new Vector2(2f, 1f); component.offsetMax = new Vector2(-2f, -1f); val2 = val3.GetComponent<TextMeshProUGUI>(); object obj = ElementAmountField?.GetValue(element); TMP_Text val4 = (TMP_Text)((obj is TMP_Text) ? obj : null); if ((Object)val4 != (Object)null) { ((TMP_Text)val2).font = val4.font; ((TMP_Text)val2).fontSize = Mathf.Max(8f, val4.fontSize * 0.55f); } ((TMP_Text)val2).alignment = (TextAlignmentOptions)1026; ((Graphic)val2).raycastTarget = false; } ((Behaviour)val2).enabled = ShowInventoryLabels != null && ShowInventoryLabels.Value; ((TMP_Text)val2).text = text; } internal static void DrawHud() { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: 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_00f5: Expected O, but got Unknown //IL_0205: 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_020e: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Expected O, but got Unknown //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0232: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Expected O, but got Unknown //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) if (ShowQuickSlotHud == null || !ShowQuickSlotHud.Value) { return; } Player localPlayer = Player.m_localPlayer; if ((Object)localPlayer == (Object)null || (Object)Hud.instance == (Object)null) { return; } EnsurePlayer(localPlayer); Inventory inventory = ((Humanoid)localPlayer).GetInventory(); if (inventory == null || _baseRows < 1) { return; } float num = 50f; float num2 = 5f; float num3 = num * 3f + num2 * 2f; float num4 = ((float)Screen.width - num3) / 2f; float num5 = (float)Screen.height - 145f; Rect val = default(Rect); Rect val2 = default(Rect); for (int i = 0; i < 3; i++) { ((Rect)(ref val))..ctor(num4 + (float)i * (num + num2), num5, num, num); GUI.Box(val, ""); ItemData itemAt = inventory.GetItemAt(i, QuickRow); if (itemAt != null) { Sprite icon = itemAt.GetIcon(); if ((Object)icon != (Object)null && (Object)icon.texture != (Object)null) { Rect textureRect = icon.textureRect; Texture val3 = (Texture)icon.texture; ((Rect)(ref val2))..ctor(((Rect)(ref textureRect)).x / (float)val3.width, ((Rect)(ref textureRect)).y / (float)val3.height, ((Rect)(ref textureRect)).width / (float)val3.width, ((Rect)(ref textureRect)).height / (float)val3.height); GUI.DrawTextureWithTexCoords(new Rect(((Rect)(ref val)).x + 4f, ((Rect)(ref val)).y + 4f, ((Rect)(ref val)).width - 8f, ((Rect)(ref val)).height - 8f), val3, val2); } if (itemAt.m_stack > 1) { GUI.Label(new Rect(((Rect)(ref val)).x + 27f, ((Rect)(ref val)).y + 28f, 20f, 18f), itemAt.m_stack.ToString()); } } string text = ""; KeyboardShortcut value; if (i == 0) { value = QuickSlot1Key.Value; text = ((object)((KeyboardShortcut)(ref value)).MainKey).ToString(); } if (i == 1) { value = QuickSlot2Key.Value; text = ((object)((KeyboardShortcut)(ref value)).MainKey).ToString(); } if (i == 2) { value = QuickSlot3Key.Value; text = ((object)((KeyboardShortcut)(ref value)).MainKey).ToString(); } GUI.Label(new Rect(((Rect)(ref val)).x + 3f, ((Rect)(ref val)).y + 2f, 30f, 18f), text); } } } [HarmonyPatch(typeof(Player), "Update")] internal static class PlayerUpdateBridge { private static void Postfix(Player __instance) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Expected O, but got Unknown //IL_0015: Expected O, but got Unknown if ((Object)__instance == (Object)Player.m_localPlayer) { SmartHotbarModule.Update(); } } } internal static class SlotLockModule { [HarmonyPatch(typeof(InventoryGui), "OnSelectedItem")] private static class SelectedItemPatch { private static bool Prefix(InventoryGrid grid, ItemData item, Vector2i pos, object[] __args) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown //IL_006c: Unknown result type (might be due to invalid IL or missing references) if (Enabled == null || !Enabled.Value) { return true; } Player localPlayer = Player.m_localPlayer; if ((Object)localPlayer == (Object)null || (Object)grid == (Object)null) { return true; } object obj = GridInventoryField?.GetValue(grid); if (((obj is Inventory) ? obj : null) != ((Humanoid)localPlayer).GetInventory()) { return true; } if (!ModifierHeld(__args)) { return true; } ToggleSlot(pos); return false; } } [HarmonyPatch(typeof(InventoryGrid), "UpdateGui")] private static class UpdateGuiPatch { private static void Postfix(InventoryGrid __instance) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Expected O, but got Unknown //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Expected O, but got Unknown //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Expected O, but got Unknown //IL_00d8: Unknown result type (might be due to invalid IL or missing references) if (Enabled == null || !Enabled.Value || (Object)__instance == (Object)null) { return; } Player localPlayer = Player.m_localPlayer; if ((Object)localPlayer == (Object)null) { return; } object obj = GridInventoryField?.GetValue(__instance); if (((obj is Inventory) ? obj : null) != ((Humanoid)localPlayer).GetInventory()) { return; } EnsureCharacterLoaded(); if (!(GridElementsField?.GetValue(__instance) is List<InventoryElement> list)) { return; } foreach (InventoryElement item in list) { if ((Object)item == (Object)null) { continue; } Vector2i pos = (Vector2i)ElementPositionField.GetValue(item); GameObject orCreateFrame = GetOrCreateFrame(item); if (!((Object)orCreateFrame == (Object)null)) { bool flag = ShowOverlay.Value && IsSlotLocked(pos); orCreateFrame.SetActive(flag); if (flag) { orCreateFrame.transform.SetAsLastSibling(); } } } } } private sealed class StackState { internal Inventory Inventory; internal List<ItemData> HiddenItems; } [HarmonyPatch(typeof(Inventory), "StackAll")] private static class StackAllPatch { [HarmonyPriority(800)] private static void Prefix(Inventory fromInventory, ref StackState __state) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_009e: 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) __state = null; if (Enabled == null || !Enabled.Value || fromInventory == null) { return; } Player localPlayer = Player.m_localPlayer; if ((Object)localPlayer == (Object)null || fromInventory != ((Humanoid)localPlayer).GetInventory()) { return; } EnsureCharacterLoaded(); if (!(InventoryItemsField?.GetValue(fromInventory) is List<ItemData> { Count: not 0 } list)) { return; } List<ItemData> list2 = new List<ItemData>(); foreach (ItemData item in list) { if (item != null && !(ItemGridPosField == null)) { Vector2i pos = (Vector2i)ItemGridPosField.GetValue(item); if (IsSlotLocked(pos) || EquipmentQuickSlotsModule.IsReservedSlot(pos)) { list2.Add(item); } } } if (list2.Count == 0) { return; } foreach (ItemData item2 in list2) { list.Remove(item2); } __state = new StackState { Inventory = fromInventory, HiddenItems = list2 }; ManualLogSource modLog = SteelhammerEssentialsPouchPatchPlugin.ModLog; if (modLog != null) { modLog.LogInfo((object)("SlotLock schützt " + list2.Count + " Item(s) vor StackAll.")); } } [HarmonyPriority(800)] private static Exception Finalizer(StackState __state, Exception __exception) { if (__state == null || __state.Inventory == null || __state.HiddenItems == null) { return __exception; } try { if (InventoryItemsField?.GetValue(__state.Inventory) is List<ItemData> list) { foreach (ItemData hiddenItem in __state.HiddenItems) { if (!list.Contains(hiddenItem)) { list.Add(hiddenItem); } } } if (InventoryChangedMethod != null) { InventoryChangedMethod.Invoke(__state.Inventory, new object[2] { true, false }); } } catch (Exception ex) { ManualLogSource modLog = SteelhammerEssentialsPouchPatchPlugin.ModLog; if (modLog != null) { modLog.LogError((object)("SlotLock Wiederherstellung fehlgeschlagen: " + ex)); } } return __exception; } } private const string FrameName = "SteelhammerEssentialsPouchPatch_LockFrame"; internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<KeyCode> ToggleModifier; internal static ConfigEntry<bool> ShowOverlay; internal static ConfigEntry<bool> ProtectHotbarRow; private static readonly HashSet<string> LockedSlots = new HashSet<string>(); private static string _loadedCharacter; private static string _saveFile; private static readonly FieldInfo GridInventoryField = AccessTools.Field(typeof(InventoryGrid), "m_inventory"); private static readonly FieldInfo GridElementsField = AccessTools.Field(typeof(InventoryGrid), "m_elements"); private static readonly FieldInfo ElementPositionField = AccessTools.Field(typeof(InventoryElement), "<Position>k__BackingField"); private static readonly FieldInfo ElementButtonField = AccessTools.Field(typeof(InventoryElement), "m_button"); private static readonly FieldInfo InventoryItemsField = AccessTools.Field(typeof(Inventory), "m_inventory"); private static readonly FieldInfo ItemGridPosField = AccessTools.Field(typeof(ItemData), "m_gridPos"); private static readonly MethodInfo InventoryChangedMethod = AccessTools.Method(typeof(Inventory), "Changed", new Type[2] { typeof(bool), typeof(bool) }, (Type[])null); private static readonly MethodInfo GetPlayerNameMethod = AccessTools.Method(typeof(Player), "GetPlayerName", (Type[])null, (Type[])null); private static readonly MethodInfo GetPlayerIdMethod = AccessTools.Method(typeof(Player), "GetPlayerID", (Type[])null, (Type[])null); internal static void Bind(ConfigFile config) { Enabled = config.Bind<bool>("02 - Slot Lock", "Enabled", true, "Aktiviert den Schutz einzelner Inventarplätze."); ToggleModifier = config.Bind<KeyCode>("02 - Slot Lock", "ToggleModifier", (KeyCode)308, "Diese Taste halten und einen Inventarplatz anklicken."); ShowOverlay = config.Bind<bool>("02 - Slot Lock", "ShowOverlay", true, "Zeigt einen goldenen Rahmen um geschützte Slots."); ProtectHotbarRow = config.Bind<bool>("02 - Slot Lock", "ProtectHotbarRow", false, "Schützt auf Wunsch automatisch die komplette obere Hotbar-Reihe."); } private static void EnsureCharacterLoaded() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown Player localPlayer = Player.m_localPlayer; if ((Object)localPlayer == (Object)null) { return; } string text = "Player"; string value = "0"; try { if (GetPlayerNameMethod != null) { object obj = GetPlayerNameMethod.Invoke(localPlayer, null); if (obj != null) { text = obj.ToString(); } } if (GetPlayerIdMethod != null) { object obj2 = GetPlayerIdMethod.Invoke(localPlayer, null); if (obj2 != null) { value = obj2.ToString(); } } } catch { } string text2 = Sanitize(text) + "_" + Sanitize(value); if (_loadedCharacter == text2) { return; } _loadedCharacter = text2; LockedSlots.Clear(); string text3 = Path.Combine(Paths.ConfigPath, "SteelhammerEssentialsPouchPatch", "SlotLocks"); Directory.CreateDirectory(text3); _saveFile = Path.Combine(text3, text2 + ".txt"); if (File.Exists(_saveFile)) { string[] array = File.ReadAllLines(_saveFile); for (int i = 0; i < array.Length; i++) { string text4 = array[i].Trim(); if (!string.IsNullOrEmpty(text4)) { LockedSlots.Add(text4); } } } ManualLogSource modLog = SteelhammerEssentialsPouchPatchPlugin.ModLog; if (modLog != null) { modLog.LogInfo((object)("SlotLock geladen: " + LockedSlots.Count + " gesperrte Slots für " + text)); } } private static string Sanitize(string value) { if (string.IsNullOrWhiteSpace(value)) { return "Player"; } char[] invalidFileNameChars = Path.GetInvalidFileNameChars(); foreach (char oldChar in invalidFileNameChars) { value = value.Replace(oldChar, '_'); } return value; } private static void SaveLocks() { if (string.IsNullOrEmpty(_saveFile)) { return; } try { File.WriteAllLines(_saveFile, LockedSlots); ManualLogSource modLog = SteelhammerEssentialsPouchPatchPlugin.ModLog; if (modLog != null) { modLog.LogInfo((object)("SlotLock gespeichert: " + LockedSlots.Count + " Slots.")); } } catch (Exception ex) { ManualLogSource modLog2 = SteelhammerEssentialsPouchPatchPlugin.ModLog; if (modLog2 != null) { modLog2.LogWarning((object)("SlotLock konnte nicht gespeichert werden: " + ex.Message)); } } } private static string SlotKey(Vector2i pos) { return pos.x + "," + pos.y; } private static bool IsSlotLocked(Vector2i pos) { //IL_0027: 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) EnsureCharacterLoaded(); if (ProtectHotbarRow != null && ProtectHotbarRow.Value && pos.y == 0) { return true; } return LockedSlots.Contains(SlotKey(pos)); } private static bool ToggleSlot(Vector2i pos) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) EnsureCharacterLoaded(); string text = SlotKey(pos); bool flag; if (LockedSlots.Contains(text)) { LockedSlots.Remove(text); flag = false; } else { LockedSlots.Add(text); flag = true; } SaveLocks(); ManualLogSource modLog = SteelhammerEssentialsPouchPatchPlugin.ModLog; if (modLog != null) { modLog.LogInfo((object)("Slot " + text + (flag ? " gesperrt." : " entsperrt."))); } return flag; } private static bool ModifierHeld(object[] args) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Invalid comparison between Unknown and I4 //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Invalid comparison between Unknown and I4 KeyCode val = (KeyCode)((ToggleModifier == null) ? 308 : ((int)ToggleModifier.Value)); if (Input.GetKey(val)) { return true; } if ((int)val == 308 && Input.GetKey((KeyCode)307)) { return true; } if ((int)val == 307 && Input.GetKey((KeyCode)308)) { return true; } if (args != null && args.Length >= 4 && args[3] != null) { string text = args[3].ToString(); if (!string.IsNullOrEmpty(text) && text.IndexOf("Alt", StringComparison.OrdinalIgnoreCase) >= 0) { return true; } } return false; } private static GameObject GetOrCreateFrame(InventoryElement element) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Expected O, but got Unknown //IL_0073: 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_008a: 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_009c: 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_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00de: 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_00f0: 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_0102: 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_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0120: 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_012e: Expected O, but got Unknown object obj = ElementButtonField?.GetValue(element); Button val = (Button)((obj is Button) ? obj : null); if ((Object)val == (Object)null) { return null; } Transform val2 = ((Component)val).transform.Find("SteelhammerEssentialsPouchPatch_LockFrame"); if ((Object)val2 != (Object)null) { return ((Component)val2).gameObject; } GameObject val3 = new GameObject("SteelhammerEssentialsPouchPatch_LockFrame", new Type[1] { typeof(RectTransform) }); val3.transform.SetParent(((Component)val).transform, false); RectTransform component = val3.GetComponent<RectTransform>(); component.anchorMin = Vector2.zero; component.anchorMax = Vector2.one; component.offsetMin = Vector2.zero; component.offsetMax = Vector2.zero; Color color = default(Color); ((Color)(ref color))..ctor(1f, 0.72f, 0.05f, 1f); AddHorizontalEdge(val3.transform, "Top", top: true, color); AddHorizontalEdge(val3.transform, "Bottom", top: false, color); AddVerticalEdge(val3.transform, "Left", left: true, color); AddVerticalEdge(val3.transform, "Right", left: false, color); val3.SetActive(false); return val3; } private static void AddHorizontalEdge(Transform parent, string name, bool top, Color color) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: 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_0050: 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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name, new Type[2] { typeof(RectTransform), typeof(Image) }); val.transform.SetParent(parent, false); RectTransform component = val.GetComponent<RectTransform>(); float num = (top ? 1f : 0f); component.anchorMin = new Vector2(0f, num); component.anchorMax = new Vector2(1f, num); component.pivot = new Vector2(0.5f, num); component.sizeDelta = new Vector2(0f, 3f); component.anchoredPosition = Vector2.zero; Image component2 = val.GetComponent<Image>(); ((Graphic)component2).color = color; ((Graphic)component2).raycastTarget = false; } private static void AddVerticalEdge(Transform parent, string name, bool left, Color color) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: 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_0050: 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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name, new Type[2] { typeof(RectTransform), typeof(Image) }); val.transform.SetParent(parent, false); RectTransform component = val.GetComponent<RectTransform>(); float num = (left ? 0f : 1f); component.anchorMin = new Vector2(num, 0f); component.anchorMax = new Vector2(num, 1f); component.pivot = new Vector2(num, 0.5f); component.sizeDelta = new Vector2(3f, 0f); component.anchoredPosition = Vector2.zero; Image component2 = val.GetComponent<Image>(); ((Graphic)component2).color = color; ((Graphic)component2).raycastTarget = false; } } internal static class SmartHotbarModule { [HarmonyPatch(typeof(Player), "UseHotbarItem")] private static class UseHotbarItemPatch { private static void Prefix(Player __instance, int index) { RecordSlot(__instance, index); } } internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<bool> InvertScroll; internal static ConfigEntry<bool> WrapAround; internal static ConfigEntry<bool> SkipEmptySlots; internal static ConfigEntry<bool> DisableWhileBuilding; internal static ConfigEntry<KeyCode> ZoomModifier; internal static ConfigEntry<float> ScrollDelay; private static readonly MethodInfo InPlaceModeMethod = AccessTools.Method(typeof(Player), "InPlaceMode", (Type[])null, (Type[])null); private static readonly MethodInfo TakeInputMethod = AccessTools.Method(typeof(Player), "TakeInput", (Type[])null, (Type[])null); private static readonly FieldInfo CameraDistanceField = AccessTools.Field(typeof(GameCamera), "m_distance"); private static int _currentSlot = 1; private static float _nextScrollTime; private static bool _restoreCamera; private static float _cameraDistanceBeforeScroll; internal static void Bind(ConfigFile config) { Enabled = config.Bind<bool>("01 - Smart Hotbar", "Enabled", true, "Aktiviert Mausrad-Wechsel zwischen Hotbar 1-8."); InvertScroll = config.Bind<bool>("01 - Smart Hotbar", "InvertScrollDirection", false, "Kehrt die Scrollrichtung um."); WrapAround = config.Bind<bool>("01 - Smart Hotbar", "WrapAround", true, "Nach dem letzten belegten Slot wird wieder zum ersten gewechselt."); SkipEmptySlots = config.Bind<bool>("01 - Smart Hotbar", "SkipEmptySlots", true, "Überspringt leere Hotbar-Slots beim Scrollen."); DisableWhileBuilding = config.Bind<bool>("01 - Smart Hotbar", "DisableWhileBuilding", true, "Überlässt das Mausrad im Baumodus Valheim zum Drehen."); ZoomModifier = config.Bind<KeyCode>("01 - Smart Hotbar", "ZoomModifier", (KeyCode)306, "Beim Halten dieser Taste bleibt das Mausrad für Kamera-Zoom frei."); ScrollDelay = config.Bind<float>("01 - Smart Hotbar", "ScrollDelay", 0.1f, "Mindestzeit zwischen Hotbar-Wechseln."); } internal static void Update() { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown //IL_0049: Unknown result type (might be due to invalid IL or missing references) if (Enabled == null || !Enabled.Value) { return; } Player localPlayer = Player.m_localPlayer; if ((Object)localPlayer == (Object)null || !CanTakeInput(localPlayer) || (DisableWhileBuilding.Value && IsInBuildMode(localPlayer)) || Input.GetKey(ZoomModifier.Value)) { return; } float axis = Input.GetAxis("Mouse ScrollWheel"); if (!Mathf.Approximately(axis, 0f) && !(Time.unscaledTime < _nextScrollTime)) { int num = ((axis > 0f) ? 1 : (-1)); if (InvertScroll.Value) { num *= -1; } int num2 = ((!SkipEmptySlots.Value) ? FindNextSlot(_currentSlot, num) : FindNextOccupiedSlot(localPlayer, _currentSlot, num)); if (num2 < 1 || num2 > 8 || num2 == _currentSlot) { _nextScrollTime = Time.unscaledTime + Mathf.Max(0.02f, ScrollDelay.Value); return; } SaveCameraDistance(); _currentSlot = num2; localPlayer.UseHotbarItem(_currentSlot); _nextScrollTime = Time.unscaledTime + Mathf.Max(0.02f, ScrollDelay.Value); } } private static int FindNextOccupiedSlot(Player player, int current, int direction) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown if ((Object)player == (Object)null) { return current; } Inventory inventory = ((Humanoid)player).GetInventory(); if (inventory == null) { return current; } int num = current; for (int i = 0; i < 8; i++) { num = FindNextSlot(num, direction); if (num < 1 || num > 8) { return current; } if (inventory.GetItemAt(num - 1, 0) != null) { return num; } if (!WrapAround.Value && ((direction > 0 && num == 8) || (direction < 0 && num == 1))) { return current; } } return current; } private static int FindNextSlot(int current, int direction) { int num = current + direction; if (WrapAround.Value) { if (num > 8) { num = 1; } if (num < 1) { num = 8; } return num; } return Mathf.Clamp(num, 1, 8); } internal static void LateUpdate() { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown if (!_restoreCamera) { return; } _restoreCamera = false; if ((Object)GameCamera.instance == (Object)null || CameraDistanceField == null) { return; } try { CameraDistanceField.SetValue(GameCamera.instance, _cameraDistanceBeforeScroll); } catch { } } private static void SaveCameraDistance() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown if ((Object)GameCamera.instance == (Object)null || CameraDistanceField == null) { return; } try { if (CameraDistanceField.GetValue(GameCamera.instance) is float cameraDistanceBeforeScroll) { _cameraDistanceBeforeScroll = cameraDistanceBeforeScroll; _restoreCamera = true; } } catch { _restoreCamera = false; } } private static bool IsInBuildMode(Player player) { if (InPlaceModeMethod == null) { return false; } try { object obj = InPlaceModeMethod.Invoke(player, null); bool flag = false; int num; if (obj is bool) { flag = (bool)obj; num = 1; } else { num = 0; } return (byte)(num & (flag ? 1 : 0)) != 0; } catch { return false; } } private static bool CanTakeInput(Player player) { if (TakeInputMethod == null) { return true; } try { object obj = TakeInputMethod.Invoke(player, null); bool flag = false; int num; if (obj is bool) { flag = (bool)obj; num = 0; } else { num = 1; } return (byte)(num | (flag ? 1 : 0)) != 0; } catch { return true; } } internal static void RecordSlot(Player player, int index) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_000f: 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_0023: Expected O, but got Unknown //IL_0023: Expected O, but got Unknown if (!((Object)player == (Object)null) && !((Object)player != (Object)Player.m_localPlayer) && index >= 1 && index <= 8) { _currentSlot = index; } } } [BepInPlugin("dylan.steelhammeressentialspouchpatch", "Steelhammer Essentials Pouch Patch", "1.0.0")] public sealed class SteelhammerEssentialsPouchPatchPlugin : BaseUnityPlugin { public const string PluginGuid = "at.steelhammer.essentials"; public const string PluginName = "Steelhammer Essentials"; public const string PluginVersion = "1.0.0"; internal static SteelhammerEssentialsPouchPatchPlugin Instance; internal static ManualLogSource ModLog; private Harmony _harmony; private void Awake() { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown Instance = this; ModLog = ((BaseUnityPlugin)this).Logger; SmartHotbarModule.Bind(((BaseUnityPlugin)this).Config); SlotLockModule.Bind(((BaseUnityPlugin)this).Config); CraftFromStorageModule.Bind(((BaseUnityPlugin)this).Config); EquipmentQuickSlotsModule.Bind(((BaseUnityPlugin)this).Config); _harmony = new Harmony("at.steelhammer.essentials"); _harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Steelhammer Essentials 1.0.0 geladen."); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Module: SmartHotbar + SlotLock + CraftFromStorage + Equipment + QuickSlots"); } private void OnGUI() { EquipmentQuickSlotsModule.DrawHud(); } private void OnDestroy() { if (_harmony != null) { _harmony.UnpatchSelf(); } Instance = null; ModLog = null; } } }