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 DwarvenStorage v1.2.1
plugins/DwarvenStorage.dll
Decompiled a day agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.Events; 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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("DwarvenStorage")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.1.0")] [assembly: AssemblyInformationalVersion("1.0.1+e46afcdf80e7850677051bb102a6cf060af7bc08")] [assembly: AssemblyProduct("My first plugin")] [assembly: AssemblyTitle("DwarvenStorage")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.1.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 DwarvenStorage { public static class AssetHolder { private static AssetBundle _bundle; private static readonly Dictionary<string, GameObject> Prefabs = new Dictionary<string, GameObject>(); private static readonly Dictionary<string, Sprite> Sprites = new Dictionary<string, Sprite>(); private static readonly Dictionary<string, string> PrefabNames = new Dictionary<string, string> { { "Interface", "assets/dwarvenstorage/prefabs/dwarven_interface.prefab" }, { "Extension_Bronze", "assets/dwarvenstorage/prefabs/extension_bronze.prefab" }, { "Extension_Iron", "assets/dwarvenstorage/prefabs/extension_iron.prefab" }, { "Extension_Black_Metal", "assets/dwarvenstorage/prefabs/extension_black_metal.prefab" }, { "Extension_Flametal", "assets/dwarvenstorage/prefabs/extension_flametal.prefab" } }; private static readonly Dictionary<string, string> SpriteNames = new Dictionary<string, string> { { "Interface", "assets/dwarvenstorage/models/icons/interface_icon.png" }, { "Workbench_1", "assets/dwarvenstorage/models/icons/items/workbench_upgrade_1.png" }, { "Workbench_2", "assets/dwarvenstorage/models/icons/items/workbench_upgrade_2.png" }, { "Workbench_3", "assets/dwarvenstorage/models/icons/items/workbench_upgrade_3.png" }, { "Workbench_4", "assets/dwarvenstorage/models/icons/items/workbench_upgrade_4.png" }, { "Workbench_5", "assets/dwarvenstorage/models/icons/items/workbench_upgrade_5.png" }, { "Forge_1", "assets/dwarvenstorage/models/icons/items/forge_upgrade_1.png" }, { "Forge_2", "assets/dwarvenstorage/models/icons/items/forge_upgrade_2.png" }, { "Forge_3", "assets/dwarvenstorage/models/icons/items/forge_upgrade_3.png" }, { "Forge_4", "assets/dwarvenstorage/models/icons/items/forge_upgrade_4.png" }, { "Forge_5", "assets/dwarvenstorage/models/icons/items/forge_upgrade_5.png" }, { "Forge_6", "assets/dwarvenstorage/models/icons/items/forge_upgrade_6.png" }, { "Forge_7", "assets/dwarvenstorage/models/icons/items/forge_upgrade_7.png" }, { "Cauldron_1", "assets/dwarvenstorage/models/icons/items/cauldron_upgrade_1.png" }, { "Cauldron_2", "assets/dwarvenstorage/models/icons/items/cauldron_upgrade_2.png" }, { "Cauldron_3", "assets/dwarvenstorage/models/icons/items/cauldron_upgrade_3.png" }, { "Cauldron_4", "assets/dwarvenstorage/models/icons/items/cauldron_upgrade_4.png" }, { "Cauldron_5", "assets/dwarvenstorage/models/icons/items/cauldron_upgrade_5.png" }, { "Cauldron_6", "assets/dwarvenstorage/models/icons/items/cauldron_upgrade_6.png" }, { "Black_forge_1", "assets/dwarvenstorage/models/icons/items/black_forge_upgrade_1.png" }, { "Black_forge_2", "assets/dwarvenstorage/models/icons/items/black_forge_upgrade_2.png" }, { "Black_forge_3", "assets/dwarvenstorage/models/icons/items/black_forge_upgrade_3.png" }, { "Black_forge_4", "assets/dwarvenstorage/models/icons/items/black_forge_upgrade_4.png" }, { "Black_forge_5", "assets/dwarvenstorage/models/icons/items/black_forge_upgrade_5.png" }, { "Artisan_1", "assets/dwarvenstorage/models/icons/items/artisan_upgrade_1.png" }, { "Artisan_2", "assets/dwarvenstorage/models/icons/items/artisan_upgrade_2.png" }, { "Stonecutter_1", "assets/dwarvenstorage/models/icons/items/stonecutter_upgrade_1.png" }, { "Prep_table_1", "assets/dwarvenstorage/models/icons/items/prep_table_upgrade_1.png" }, { "Mage_table_1", "assets/dwarvenstorage/models/icons/items/mage_table_upgrade_1.png" }, { "Mage_table_2", "assets/dwarvenstorage/models/icons/items/mage_table_upgrade_2.png" }, { "Mage_table_3", "assets/dwarvenstorage/models/icons/items/mage_table_upgrade_3.png" }, { "Mage_table_4", "assets/dwarvenstorage/models/icons/items/mage_table_upgrade_4.png" } }; private static bool _loaded; public static AssetBundle Bundle => _bundle; public static GameObject GetPrefab(string key) { if (!_loaded) { return null; } GameObject value; return Prefabs.TryGetValue(key, out value) ? value : null; } public static Sprite GetSprite(string key) { if (!_loaded) { return null; } Sprite value; return Sprites.TryGetValue(key, out value) ? value : null; } public static void LoadAssetBundle() { if (_loaded) { return; } _bundle = AssetUtils.LoadAssetBundleFromResources("DwarvenStorage.Assets.Bundles.dwarvenstorage"); if ((Object)(object)_bundle == (Object)null) { Plugin.Logger.LogError((object)"Failed to load asset bundle"); return; } foreach (KeyValuePair<string, string> spriteName in SpriteNames) { string key = spriteName.Key; string value = spriteName.Value; Sprite val = _bundle.LoadAsset<Sprite>(value); if ((Object)(object)val == (Object)null) { Plugin.Logger.LogError((object)("Failed to load sprite: key=" + key + ", path=" + value)); continue; } Plugin.Logger.LogInfo((object)("Loaded sprite: " + key + " - " + value)); Sprites[key] = val; } foreach (KeyValuePair<string, string> prefabName in PrefabNames) { string key2 = prefabName.Key; string value2 = prefabName.Value; GameObject val2 = _bundle.LoadAsset<GameObject>(value2); if ((Object)(object)val2 == (Object)null) { Plugin.Logger.LogError((object)("Failed to load prefab: key=" + key2 + ", path=" + value2)); } else { Prefabs[key2] = val2; } } Plugin.Logger.LogInfo((object)$"Loaded prefabs: {Prefabs.Count}"); Plugin.Logger.LogInfo((object)$"Loaded sprites: {Sprites.Count}"); _loaded = true; } } [HarmonyPatch] public static class CraftingPatches { private static readonly MethodInfo ContainerSaveMethod = AccessTools.Method(typeof(Container), "Save", (Type[])null, (Type[])null); [HarmonyPrefix] [HarmonyPatch(typeof(CraftingStation), "CheckUsable")] private static bool CheckUsablePrefix(CraftingStation __instance, Player player, bool showMessage, ref bool __result) { StorageInterface instance = StorageInterface.Instance; if ((Object)(object)instance == (Object)null) { return true; } if ((Object)(object)instance.CraftingStation == (Object)null) { return true; } if ((Object)(object)__instance != (Object)(object)instance.CraftingStation) { return true; } __result = true; return false; } [HarmonyPostfix] [HarmonyPatch(typeof(CraftingStation), "GetLevel")] private static void GetLevelPostfix(CraftingStation __instance, bool checkExtensions, ref int __result) { StorageInterface instance = StorageInterface.Instance; if (!((Object)(object)instance == (Object)null) && !((Object)(object)__instance != (Object)(object)instance.CraftingStation)) { __result = Mathf.Max(1, instance.CurrentStationLevel); } } [HarmonyPostfix] [HarmonyPatch(typeof(Player), "HaveRequirementItems", new Type[] { typeof(Recipe), typeof(bool), typeof(int), typeof(int) })] private static void HaveRequirementItemsPostfix(Player __instance, ref bool __result, Recipe piece, bool discover, int qualityLevel, HashSet<string> ___m_knownMaterial, int amount) { if (__result || discover) { return; } StorageInterface instance = StorageInterface.Instance; if ((Object)(object)instance == (Object)null) { return; } Container container = instance.Container; if ((Object)(object)container == (Object)null) { return; } Inventory inventory = ((Humanoid)__instance).GetInventory(); Inventory inventory2 = container.GetInventory(); if (inventory == null || inventory2 == null || (Object)(object)piece == (Object)null || piece.m_resources == null) { return; } Requirement[] resources = piece.m_resources; foreach (Requirement val in resources) { if ((Object)(object)val.m_resItem == (Object)null) { continue; } int num = val.GetAmount(qualityLevel) * amount; if (num > 0) { string name = val.m_resItem.m_itemData.m_shared.m_name; int num2 = inventory.CountItems(name, -1, true) + inventory2.CountItems(name, -1, true); if (num2 < num) { return; } } } __result = true; } [HarmonyPrefix] [HarmonyPatch(typeof(Player), "ConsumeResources")] private static bool ConsumeResourcesPrefix(Player __instance, Requirement[] requirements, int qualityLevel, int multiplier) { StorageInterface instance = StorageInterface.Instance; if ((Object)(object)instance == (Object)null) { return true; } Container container = instance.Container; if ((Object)(object)container == (Object)null) { return true; } Inventory inventory = ((Humanoid)__instance).GetInventory(); Inventory inventory2 = container.GetInventory(); if (inventory == null || inventory2 == null) { return true; } foreach (Requirement val in requirements) { if ((Object)(object)val.m_resItem == (Object)null) { continue; } int num = val.GetAmount(qualityLevel) * multiplier; if (num > 0) { string name = val.m_resItem.m_itemData.m_shared.m_name; int num2 = inventory.CountItems(name, -1, true); int num3 = inventory2.CountItems(name, -1, true); int num4 = num2 + num3; if (num4 < num) { Plugin.Logger.LogWarning((object)$"Not enough {name}. Required={num}, Available={num4}"); return true; } int num5 = Mathf.Min(num2, num); if (num5 > 0) { inventory.RemoveItem(name, num5, -1, true); } int num6 = num - num5; if (num6 > 0) { inventory2.RemoveItem(name, num6, -1, true); } } } MarkInventoryChanged(inventory); MarkInventoryChanged(inventory2); SaveContainer(container); return false; } [HarmonyPostfix] [HarmonyPatch(typeof(InventoryGui), "SetupRequirement")] private static void SetupRequirementPostfix(InventoryGui __instance, Transform elementRoot, Requirement req, Player player, bool craft, int quality, int craftMultiplier) { //IL_0126: Unknown result type (might be due to invalid IL or missing references) StorageInterface instance = StorageInterface.Instance; if ((Object)(object)instance == (Object)null) { return; } Container container = instance.Container; if ((Object)(object)container == (Object)null || (Object)(object)req.m_resItem == (Object)null) { return; } Inventory inventory = ((Humanoid)player).GetInventory(); Inventory inventory2 = container.GetInventory(); if (inventory == null || inventory2 == null) { return; } int num = req.GetAmount(quality) * craftMultiplier; if (num <= 0) { return; } string name = req.m_resItem.m_itemData.m_shared.m_name; int num2 = inventory.CountItems(name, -1, true); int num3 = inventory2.CountItems(name, -1, true); int num4 = num2 + num3; Transform obj = elementRoot.Find("res_amount"); TMP_Text val = ((obj != null) ? ((Component)obj).GetComponent<TMP_Text>() : null); if (!((Object)(object)val == (Object)null)) { val.text = $"{num4}/{num}"; if (num2 < num && num4 >= num) { ((Graphic)val).color = Color.yellow; } } } private static void SaveContainer(Container container) { if ((Object)(object)container == (Object)null) { return; } try { ContainerSaveMethod?.Invoke(container, Array.Empty<object>()); } catch (Exception ex) { Plugin.Logger.LogWarning((object)("Failed to save storage container: " + ex.Message)); } } private static void MarkInventoryChanged(Inventory inventory) { if (inventory == null) { return; } try { InventoryAccess.NotifyChanged(inventory); } catch (Exception ex) { Plugin.Logger.LogWarning((object)("Failed to mark inventory changed: " + ex.Message)); } } } internal static class InventoryAccess { private static readonly FieldInfo WidthField = AccessTools.Field(typeof(Inventory), "m_width") ?? throw new MissingFieldException(typeof(Inventory).FullName, "m_width"); private static readonly MethodInfo ChangedMethod = AccessTools.Method(typeof(Inventory), "Changed", new Type[2] { typeof(bool), typeof(bool) }, (Type[])null) ?? throw new MissingMethodException(typeof(Inventory).FullName, "Changed(bool, bool)"); internal static void SetSize(Inventory inventory, int columns, int rows) { WidthField.SetValue(inventory, columns); inventory.SetHeight(rows); } internal static void NotifyChanged(Inventory inventory) { ChangedMethod.Invoke(inventory, new object[2] { false, false }); } } internal static class InventoryGuiAccess { private static readonly MethodInfo SetupCraftingMethod = AccessTools.Method(typeof(InventoryGui), "SetupCrafting", Type.EmptyTypes, (Type[])null) ?? throw new MissingMethodException(typeof(InventoryGui).FullName, "SetupCrafting"); private static readonly MethodInfo SetupDragItemMethod = AccessTools.Method(typeof(InventoryGui), "SetupDragItem", new Type[3] { typeof(ItemData), typeof(Inventory), typeof(int) }, (Type[])null) ?? throw new MissingMethodException(typeof(InventoryGui).FullName, "SetupDragItem"); private static readonly FieldInfo DragItemField = AccessTools.Field(typeof(InventoryGui), "m_dragItem") ?? throw new MissingFieldException(typeof(InventoryGui).FullName, "m_dragItem"); private static readonly FieldInfo DragInventoryField = AccessTools.Field(typeof(InventoryGui), "m_dragInventory") ?? throw new MissingFieldException(typeof(InventoryGui).FullName, "m_dragInventory"); internal static void RefreshCrafting(InventoryGui gui) { if (Object.op_Implicit((Object)(object)gui)) { SetupCraftingMethod.Invoke(gui, Array.Empty<object>()); } } internal static ItemData GetDragItem(InventoryGui gui) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) return (!Object.op_Implicit((Object)(object)gui)) ? ((ItemData)null) : ((ItemData)DragItemField.GetValue(gui)); } internal static Inventory GetDragInventory(InventoryGui gui) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) return (!Object.op_Implicit((Object)(object)gui)) ? ((Inventory)null) : ((Inventory)DragInventoryField.GetValue(gui)); } internal static void ClearDragItem(InventoryGui gui) { if (Object.op_Implicit((Object)(object)gui)) { SetupDragItemMethod.Invoke(gui, new object[3] { null, null, 1 }); } } } [BepInPlugin("jawlessjman.DwarvenStorage", "DwarvenStorage", "1.0.1")] public class Plugin : BaseUnityPlugin { internal static ManualLogSource Logger; public const string ModGuid = "jawlessjman.DwarvenStorage"; public const string ModName = "DwarvenStorage"; public const string ModVersion = "1.0.1"; public static readonly Dictionary<string, string> UpgradeStationsByPrefabName = new Dictionary<string, string>(); public static readonly Dictionary<string, int> UpgradeAmountsByPrefabName = new Dictionary<string, int>(); private static readonly List<StorageExtensionData> StorageExtensions = new List<StorageExtensionData>(4) { new StorageExtensionData { Name = "$extension_tier_1", PrefabName = "extension_bronze", Description = "$extension_tier_1_desc", Rows = 1, CraftingStation = CraftingStations.Forge, ItemRequirements = new List<ItemRequirements>(3) { new ItemRequirements { Name = "Wood", Amount = 10, UpgradeAmount = 0 }, new ItemRequirements { Name = "Bronze", Amount = 4, UpgradeAmount = 0 }, new ItemRequirements { Name = "SurtlingCore", Amount = 2, UpgradeAmount = 0 } } }, new StorageExtensionData { Name = "$extension_tier_2", PrefabName = "extension_iron", Description = "$extension_tier_2_desc", CraftingStation = CraftingStations.Forge, Rows = 3, ItemRequirements = new List<ItemRequirements>(4) { new ItemRequirements { Name = "FineWood", Amount = 10, UpgradeAmount = 0 }, new ItemRequirements { Name = "Iron", Amount = 8, UpgradeAmount = 0 }, new ItemRequirements { Name = "Chain", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "SurtlingCore", Amount = 2, UpgradeAmount = 0 } } }, new StorageExtensionData { Name = "$extension_tier_3", Description = "$extension_tier_3_desc", PrefabName = "extension_black_metal", Rows = 5, CraftingStation = CraftingStations.BlackForge, ItemRequirements = new List<ItemRequirements>(4) { new ItemRequirements { Name = "YggdrasilWood", Amount = 10, UpgradeAmount = 0 }, new ItemRequirements { Name = "Eitr", Amount = 4, UpgradeAmount = 0 }, new ItemRequirements { Name = "BlackMarble", Amount = 10, UpgradeAmount = 0 }, new ItemRequirements { Name = "BlackMetal", Amount = 6, UpgradeAmount = 0 } } }, new StorageExtensionData { Name = "$extension_tier_4", PrefabName = "extension_flametal", Description = "$extension_tier_4_desc", Rows = 7, CraftingStation = CraftingStations.BlackForge, ItemRequirements = new List<ItemRequirements>(4) { new ItemRequirements { Name = "Blackwood", Amount = 10, UpgradeAmount = 0 }, new ItemRequirements { Name = "CharredBone", Amount = 16, UpgradeAmount = 0 }, new ItemRequirements { Name = "MoltenCore", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "FlametalNew", Amount = 4, UpgradeAmount = 0 } } } }; private static readonly List<StorageUpgrade> StorageUpgrades = new List<StorageUpgrade>(31) { new StorageUpgrade { Name = "$workbench_upgrade_1", CraftingStation = CraftingStations.Workbench, ItemRequirements = new List<ItemRequirements>(1) { new ItemRequirements { Name = "Wood", Amount = 5, UpgradeAmount = 0 } }, SpriteName = "Workbench_1", Description = "$workbench_upgrade_1_desc", StationKey = "workbench", MinQualityLevel = 1 }, new StorageUpgrade { Name = "$workbench_upgrade_2", CraftingStation = CraftingStations.Workbench, ItemRequirements = new List<ItemRequirements>(3) { new ItemRequirements { Name = "$workbench_upgrade_1", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "Wood", Amount = 5, UpgradeAmount = 0 }, new ItemRequirements { Name = "Flint", Amount = 5, UpgradeAmount = 0 } }, SpriteName = "Workbench_2", Description = "$workbench_upgrade_2_desc", StationKey = "workbench", MinQualityLevel = 2 }, new StorageUpgrade { Name = "$workbench_upgrade_3", CraftingStation = CraftingStations.Workbench, ItemRequirements = new List<ItemRequirements>(5) { new ItemRequirements { Name = "$workbench_upgrade_2", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "Wood", Amount = 5, UpgradeAmount = 0 }, new ItemRequirements { Name = "Flint", Amount = 7, UpgradeAmount = 0 }, new ItemRequirements { Name = "LeatherScraps", Amount = 10, UpgradeAmount = 0 }, new ItemRequirements { Name = "DeerHide", Amount = 2, UpgradeAmount = 0 } }, SpriteName = "Workbench_3", Description = "$workbench_upgrade_3_desc", StationKey = "workbench", MinQualityLevel = 3 }, new StorageUpgrade { Name = "$workbench_upgrade_4", CraftingStation = CraftingStations.Workbench, ItemRequirements = new List<ItemRequirements>(3) { new ItemRequirements { Name = "$workbench_upgrade_3", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "FineWood", Amount = 5, UpgradeAmount = 0 }, new ItemRequirements { Name = "Bronze", Amount = 1, UpgradeAmount = 0 } }, SpriteName = "Workbench_4", Description = "$workbench_upgrade_4_desc", StationKey = "workbench", MinQualityLevel = 4 }, new StorageUpgrade { Name = "$workbench_upgrade_5", CraftingStation = CraftingStations.Workbench, ItemRequirements = new List<ItemRequirements>(4) { new ItemRequirements { Name = "$workbench_upgrade_4", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "FineWood", Amount = 5, UpgradeAmount = 0 }, new ItemRequirements { Name = "Iron", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "Obsidian", Amount = 2, UpgradeAmount = 0 } }, SpriteName = "Workbench_5", Description = "$workbench_upgrade_5_desc", StationKey = "workbench", MinQualityLevel = 5 }, new StorageUpgrade { Name = "$forge_upgrade_1", CraftingStation = CraftingStations.Forge, ItemRequirements = new List<ItemRequirements>(4) { new ItemRequirements { Name = "Wood", Amount = 5, UpgradeAmount = 0 }, new ItemRequirements { Name = "Stone", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "Coal", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "Copper", Amount = 3, UpgradeAmount = 0 } }, SpriteName = "Forge_1", Description = "$forge_upgrade_1_desc", StationKey = "forge", MinQualityLevel = 1 }, new StorageUpgrade { Name = "$forge_upgrade_2", CraftingStation = CraftingStations.Forge, ItemRequirements = new List<ItemRequirements>(3) { new ItemRequirements { Name = "$forge_upgrade_1", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "FineWood", Amount = 12, UpgradeAmount = 0 }, new ItemRequirements { Name = "Copper", Amount = 5, UpgradeAmount = 0 } }, SpriteName = "Forge_2", Description = "$forge_upgrade_2_desc", StationKey = "forge", MinQualityLevel = 2 }, new StorageUpgrade { Name = "$forge_upgrade_3", CraftingStation = CraftingStations.Forge, ItemRequirements = new List<ItemRequirements>(3) { new ItemRequirements { Name = "$forge_upgrade_2", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "Wood", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "Bronze", Amount = 1, UpgradeAmount = 0 } }, SpriteName = "Forge_3", Description = "$forge_upgrade_3_desc", StationKey = "forge", MinQualityLevel = 3 }, new StorageUpgrade { Name = "$forge_upgrade_4", CraftingStation = CraftingStations.Forge, ItemRequirements = new List<ItemRequirements>(3) { new ItemRequirements { Name = "$forge_upgrade_3", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "Wood", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "Iron", Amount = 10, UpgradeAmount = 0 } }, SpriteName = "Forge_4", Description = "$forge_upgrade_4_desc", StationKey = "forge", MinQualityLevel = 4 }, new StorageUpgrade { Name = "$forge_upgrade_5", CraftingStation = CraftingStations.Forge, ItemRequirements = new List<ItemRequirements>(3) { new ItemRequirements { Name = "$forge_upgrade_4", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "Wood", Amount = 5, UpgradeAmount = 0 }, new ItemRequirements { Name = "Iron", Amount = 7, UpgradeAmount = 0 } }, SpriteName = "Forge_5", Description = "$forge_upgrade_5_desc", StationKey = "forge", MinQualityLevel = 5 }, new StorageUpgrade { Name = "$forge_upgrade_6", CraftingStation = CraftingStations.Forge, ItemRequirements = new List<ItemRequirements>(4) { new ItemRequirements { Name = "$forge_upgrade_5", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "Wood", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "DeerHide", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "Chain", Amount = 2, UpgradeAmount = 0 } }, SpriteName = "Forge_6", Description = "$forge_upgrade_6_desc", StationKey = "forge", MinQualityLevel = 6 }, new StorageUpgrade { Name = "$forge_upgrade_7", CraftingStation = CraftingStations.Forge, ItemRequirements = new List<ItemRequirements>(3) { new ItemRequirements { Name = "$forge_upgrade_6", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "Wood", Amount = 12, UpgradeAmount = 0 }, new ItemRequirements { Name = "SharpeningStone", Amount = 1, UpgradeAmount = 0 } }, SpriteName = "Forge_7", Description = "$forge_upgrade_7_desc", StationKey = "forge", MinQualityLevel = 7 }, new StorageUpgrade { Name = "$cauldron_upgrade_1", CraftingStation = CraftingStations.Cauldron, ItemRequirements = new List<ItemRequirements>(1) { new ItemRequirements { Name = "Tin", Amount = 5, UpgradeAmount = 0 } }, SpriteName = "Cauldron_1", Description = "$cauldron_upgrade_1_desc", StationKey = "cauldron", MinQualityLevel = 1 }, new StorageUpgrade { Name = "$cauldron_upgrade_2", CraftingStation = CraftingStations.Cauldron, ItemRequirements = new List<ItemRequirements>(6) { new ItemRequirements { Name = "$cauldron_upgrade_1", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "Dandelion", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "Carrot", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "Mushroom", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "Thistle", Amount = 3, UpgradeAmount = 0 }, new ItemRequirements { Name = "Turnip", Amount = 1, UpgradeAmount = 0 } }, SpriteName = "Cauldron_2", Description = "$cauldron_upgrade_2_desc", StationKey = "cauldron", MinQualityLevel = 2 }, new StorageUpgrade { Name = "$cauldron_upgrade_3", CraftingStation = CraftingStations.Cauldron, ItemRequirements = new List<ItemRequirements>(5) { new ItemRequirements { Name = "$cauldron_upgrade_2", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "FineWood", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "RoundLog", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "ElderBark", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "Silver", Amount = 1, UpgradeAmount = 0 } }, SpriteName = "Cauldron_3", Description = "$cauldron_upgrade_3_desc", StationKey = "cauldron", MinQualityLevel = 3 }, new StorageUpgrade { Name = "$cauldron_upgrade_4", CraftingStation = CraftingStations.Cauldron, ItemRequirements = new List<ItemRequirements>(5) { new ItemRequirements { Name = "$cauldron_upgrade_3", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "Iron", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "Copper", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "BlackMetal", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "FineWood", Amount = 5, UpgradeAmount = 0 } }, SpriteName = "Cauldron_4", Description = "$cauldron_upgrade_4_desc", StationKey = "cauldron", MinQualityLevel = 4 }, new StorageUpgrade { Name = "$cauldron_upgrade_5", CraftingStation = CraftingStations.Cauldron, ItemRequirements = new List<ItemRequirements>(4) { new ItemRequirements { Name = "$cauldron_upgrade_4", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "BlackMarble", Amount = 4, UpgradeAmount = 0 }, new ItemRequirements { Name = "RoundLog", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "FineWood", Amount = 3, UpgradeAmount = 0 } }, SpriteName = "Cauldron_5", Description = "$cauldron_upgrade_5_desc", StationKey = "cauldron", MinQualityLevel = 5 }, new StorageUpgrade { Name = "$cauldron_upgrade_6", CraftingStation = CraftingStations.Cauldron, ItemRequirements = new List<ItemRequirements>(4) { new ItemRequirements { Name = "$cauldron_upgrade_5", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "Blackwood", Amount = 4, UpgradeAmount = 0 }, new ItemRequirements { Name = "FlametalNew", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "FineWood", Amount = 3, UpgradeAmount = 0 } }, SpriteName = "Cauldron_6", Description = "$cauldron_upgrade_6_desc", StationKey = "cauldron", MinQualityLevel = 6 }, new StorageUpgrade { Name = "$stonecutter_upgrade", CraftingStation = CraftingStations.Stonecutter, ItemRequirements = new List<ItemRequirements>(3) { new ItemRequirements { Name = "Wood", Amount = 5, UpgradeAmount = 0 }, new ItemRequirements { Name = "Iron", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "Stone", Amount = 2, UpgradeAmount = 0 } }, SpriteName = "Stonecutter_1", Description = "$stonecutter_upgrade_desc", StationKey = "stonecutter", MinQualityLevel = 1 }, new StorageUpgrade { Name = "$artisan_table_upgrade_1", CraftingStation = CraftingStations.ArtisanTable, ItemRequirements = new List<ItemRequirements>(2) { new ItemRequirements { Name = "Wood", Amount = 5, UpgradeAmount = 0 }, new ItemRequirements { Name = "DragonTear", Amount = 1, UpgradeAmount = 0 } }, SpriteName = "Artisan_1", Description = "$artisan_table_upgrade_1_desc", StationKey = "artisan", MinQualityLevel = 1 }, new StorageUpgrade { Name = "$artisan_table_upgrade_2", CraftingStation = CraftingStations.ArtisanTable, ItemRequirements = new List<ItemRequirements>(4) { new ItemRequirements { Name = "$artisan_table_upgrade_1", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "BlackMarble", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "Bronze", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "QueenDrop", Amount = 1, UpgradeAmount = 0 } }, SpriteName = "Artisan_2", Description = "$artisan_table_upgrade_2_desc", StationKey = "artisan", MinQualityLevel = 2 }, new StorageUpgrade { Name = "$prep_table_upgrade", CraftingStation = CraftingStations.FoodPreparationTable, ItemRequirements = new List<ItemRequirements>(3) { new ItemRequirements { Name = "FineWood", Amount = 10, UpgradeAmount = 0 }, new ItemRequirements { Name = "Iron", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "LeatherScraps", Amount = 7, UpgradeAmount = 0 } }, SpriteName = "Prep_table_1", Description = "$prep_table_upgrade_desc", StationKey = "preptable", MinQualityLevel = 1 }, new StorageUpgrade { Name = "$blackforge_upgrade_1", CraftingStation = CraftingStations.BlackForge, ItemRequirements = new List<ItemRequirements>(3) { new ItemRequirements { Name = "BlackMarble", Amount = 5, UpgradeAmount = 0 }, new ItemRequirements { Name = "YggdrasilWood", Amount = 5, UpgradeAmount = 0 }, new ItemRequirements { Name = "BlackCore", Amount = 2, UpgradeAmount = 0 } }, SpriteName = "Black_forge_1", Description = "$blackforge_upgrade_1_desc", StationKey = "blackforge", MinQualityLevel = 1 }, new StorageUpgrade { Name = "$blackforge_upgrade_2", CraftingStation = CraftingStations.BlackForge, ItemRequirements = new List<ItemRequirements>(4) { new ItemRequirements { Name = "$blackforge_upgrade_1", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "Iron", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "Copper", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "BlackMarble", Amount = 2, UpgradeAmount = 0 } }, SpriteName = "Black_forge_2", Description = "$blackforge_upgrade_2_desc", StationKey = "blackforge", MinQualityLevel = 2 }, new StorageUpgrade { Name = "$blackforge_upgrade_3", CraftingStation = CraftingStations.BlackForge, ItemRequirements = new List<ItemRequirements>(4) { new ItemRequirements { Name = "$blackforge_upgrade_2", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "Iron", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "Copper", Amount = 4, UpgradeAmount = 0 }, new ItemRequirements { Name = "MechanicalSpring", Amount = 1, UpgradeAmount = 0 } }, SpriteName = "Black_forge_3", Description = "$blackforge_upgrade_3_desc", StationKey = "blackforge", MinQualityLevel = 3 }, new StorageUpgrade { Name = "$blackforge_upgrade_4", CraftingStation = CraftingStations.BlackForge, ItemRequirements = new List<ItemRequirements>(5) { new ItemRequirements { Name = "$blackforge_upgrade_3", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "BlackMarble", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "FlametalNew", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "Blackwood", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "CharredBone", Amount = 2, UpgradeAmount = 0 } }, SpriteName = "Black_forge_4", Description = "$blackforge_upgrade_4_desc", StationKey = "blackforge", MinQualityLevel = 4 }, new StorageUpgrade { Name = "$blackforge_upgrade_5", CraftingStation = CraftingStations.BlackForge, ItemRequirements = new List<ItemRequirements>(5) { new ItemRequirements { Name = "$blackforge_upgrade_4", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "GemstoneRed", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "FlametalNew", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "Blackwood", Amount = 4, UpgradeAmount = 0 }, new ItemRequirements { Name = "MorgenSinew", Amount = 1, UpgradeAmount = 0 } }, SpriteName = "Black_forge_5", Description = "$blackforge_upgrade_5_desc", StationKey = "blackforge", MinQualityLevel = 5 }, new StorageUpgrade { Name = "$galdr_table_upgrade_1", CraftingStation = CraftingStations.GaldrTable, ItemRequirements = new List<ItemRequirements>(4) { new ItemRequirements { Name = "BlackMetal", Amount = 5, UpgradeAmount = 0 }, new ItemRequirements { Name = "YggdrasilWood", Amount = 10, UpgradeAmount = 0 }, new ItemRequirements { Name = "BlackCore", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "Eitr", Amount = 2, UpgradeAmount = 0 } }, SpriteName = "Mage_table_1", Description = "$galdr_table_upgrade_1_desc", StationKey = "galdr", MinQualityLevel = 1 }, new StorageUpgrade { Name = "$galdr_table_upgrade_2", CraftingStation = CraftingStations.GaldrTable, ItemRequirements = new List<ItemRequirements>(4) { new ItemRequirements { Name = "$galdr_table_upgrade_1", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "YggdrasilWood", Amount = 2, UpgradeAmount = 0 }, new ItemRequirements { Name = "BlackMarble", Amount = 5, UpgradeAmount = 0 }, new ItemRequirements { Name = "Eitr", Amount = 5, UpgradeAmount = 0 } }, SpriteName = "Mage_table_2", Description = "$galdr_table_upgrade_2_desc", StationKey = "galdr", MinQualityLevel = 2 }, new StorageUpgrade { Name = "$galdr_table_upgrade_3", CraftingStation = CraftingStations.GaldrTable, ItemRequirements = new List<ItemRequirements>(5) { new ItemRequirements { Name = "$galdr_table_upgrade_2", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "Resin", Amount = 7, UpgradeAmount = 0 }, new ItemRequirements { Name = "BlackMarble", Amount = 5, UpgradeAmount = 0 }, new ItemRequirements { Name = "Eitr", Amount = 5, UpgradeAmount = 0 }, new ItemRequirements { Name = "TrophySkeleton", Amount = 1, UpgradeAmount = 0 } }, SpriteName = "Mage_table_3", Description = "$galdr_table_upgrade_3_desc", StationKey = "galdr", MinQualityLevel = 3 }, new StorageUpgrade { Name = "$galdr_table_upgrade_4", CraftingStation = CraftingStations.GaldrTable, ItemRequirements = new List<ItemRequirements>(5) { new ItemRequirements { Name = "$galdr_table_upgrade_3", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "Blackwood", Amount = 1, UpgradeAmount = 0 }, new ItemRequirements { Name = "CelestialFeather", Amount = 4, UpgradeAmount = 0 }, new ItemRequirements { Name = "Eitr", Amount = 5, UpgradeAmount = 0 }, new ItemRequirements { Name = "TrophyAsksvin", Amount = 1, UpgradeAmount = 0 } }, SpriteName = "Mage_table_4", Description = "$galdr_table_upgrade_4_desc", StationKey = "galdr", MinQualityLevel = 4 } }; private Harmony _harmony; private void Awake() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown Logger = ((BaseUnityPlugin)this).Logger; _harmony = new Harmony("jawlessjman.DwarvenStorage"); _harmony.PatchAll(); AssetHolder.LoadAssetBundle(); string text = AssetUtils.LoadTextFromResources("DwarvenStorage.Assets.Translations.English.DwarvenStorage.json"); if (string.IsNullOrEmpty(text)) { Logger.LogError((object)"Failed to load English translation file: DwarvenStorage.Assets.Translations.English.DwarvenStorage.json"); } else { LocalizationManager.Instance.GetLocalization().AddJsonFile("English", text); } LoadTranslations(); PrefabManager.OnVanillaPrefabsAvailable += CreateInterface; PrefabManager.OnVanillaPrefabsAvailable += CreateStorageExtensions; PrefabManager.OnVanillaPrefabsAvailable += CreateUpgradeItems; Logger.LogInfo((object)"Plugin DwarvenStorage-1.0.1 is loaded!"); } private void LoadTranslations() { string path = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "Translations"); if (Directory.Exists(path)) { string[] files = Directory.GetFiles(path, "*.json", SearchOption.AllDirectories); foreach (string text in files) { Logger.LogInfo((object)("Loading translation file: " + text)); LocalizationManager.Instance.GetLocalization().AddFileByPath(text, true); } } } private static CustomPiece CreatePiece(string name, string description, string craftingStation, string category, List<ItemRequirements> itemRequirements, string prefabName) { //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_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Expected O, but got Unknown //IL_016d: Unknown result type (might be due to invalid IL or missing references) PieceConfig val = new PieceConfig { Name = name, Description = description, PieceTable = PieceTables.Hammer, CraftingStation = craftingStation, Category = category }; foreach (ItemRequirements itemRequirement in itemRequirements) { val.AddRequirement(itemRequirement.Name, itemRequirement.Amount, true); } CustomPiece val2 = new CustomPiece(AssetHolder.Bundle, prefabName, true, val); GameObject piecePrefab = val2.PiecePrefab; Piece component = piecePrefab.GetComponent<Piece>(); WearNTear component2 = piecePrefab.GetComponent<WearNTear>(); GameObject prefab = PrefabManager.Instance.GetPrefab("wood_wall_quarter"); Piece val3 = null; WearNTear val4 = null; if ((Object)(object)prefab != (Object)null) { val3 = prefab.GetComponent<Piece>(); val4 = prefab.GetComponent<WearNTear>(); } if ((Object)(object)component != (Object)null) { component.m_clipEverything = false; if ((Object)(object)val3 != (Object)null) { component.m_placeEffect = val3.m_placeEffect; } } if ((Object)(object)component2 != (Object)null && (Object)(object)val4 != (Object)null) { component2.m_destroyedEffect = val4.m_destroyedEffect; component2.m_hitEffect = val4.m_hitEffect; } ZNetView component3 = piecePrefab.GetComponent<ZNetView>(); if ((Object)(object)component3 == (Object)null) { return val2; } component3.m_persistent = true; component3.m_type = (ObjectType)2; component3.m_syncInitialScale = true; return val2; } private static void CreateInterface() { CustomPiece val = CreatePiece("$piece_dwarven_interface", "$piece_dwarven_interface_desc", CraftingStations.Workbench, PieceCategories.Misc, new List<ItemRequirements>(3) { new ItemRequirements { Name = "Wood", Amount = 10 }, new ItemRequirements { Name = "Stone", Amount = 4 }, new ItemRequirements { Name = "SurtlingCore", Amount = 2 } }, "dwarven_interface"); val.PiecePrefab.AddComponent<StorageInterface>(); val.PiecePrefab.AddComponent<StorageUpgradeSlots>(); PieceManager.Instance.AddPiece(val); PrefabManager.OnVanillaPrefabsAvailable -= CreateInterface; } private static void CreateStorageExtensions() { foreach (StorageExtensionData storageExtension in StorageExtensions) { CustomPiece val = CreatePiece(storageExtension.Name, storageExtension.Description, storageExtension.CraftingStation, PieceCategories.Misc, storageExtension.ItemRequirements, storageExtension.PrefabName); StorageInterfaceExtension storageInterfaceExtension = val.PiecePrefab.AddComponent<StorageInterfaceExtension>(); storageInterfaceExtension.addedRows = storageExtension.Rows; storageInterfaceExtension.addedColumns = 0; storageInterfaceExtension.hoverText = storageExtension.Name; storageInterfaceExtension.hoverName = storageExtension.Name; PieceManager.Instance.AddPiece(val); } PrefabManager.OnVanillaPrefabsAvailable -= CreateStorageExtensions; } private static void CreateUpgradeItems() { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_003a: 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_004e: 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_0067: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Expected O, but got Unknown //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Expected O, but got Unknown foreach (StorageUpgrade storageUpgrade in StorageUpgrades) { ItemConfig val = new ItemConfig { Name = storageUpgrade.Name, Description = storageUpgrade.Description, CraftingStation = storageUpgrade.CraftingStation, StackSize = 1, Weight = 2f, MinStationLevel = storageUpgrade.MinQualityLevel, Icon = AssetHolder.GetSprite(storageUpgrade.SpriteName) }; foreach (ItemRequirements itemRequirement in storageUpgrade.ItemRequirements) { val.AddRequirement(itemRequirement.Name, itemRequirement.Amount, itemRequirement.UpgradeAmount); } CustomItem val2 = new CustomItem(storageUpgrade.Name, "AskHide", val); val2.ItemDrop.m_itemData.m_quality = storageUpgrade.MinQualityLevel; val2.ItemDrop.m_itemData.m_customData["DwarvenUpgrade"] = storageUpgrade.StationKey; UpgradeStationsByPrefabName[storageUpgrade.Name] = storageUpgrade.StationKey; UpgradeAmountsByPrefabName[storageUpgrade.Name] = storageUpgrade.MinQualityLevel; ItemManager.Instance.AddItem(val2); } PrefabManager.OnVanillaPrefabsAvailable -= CreateUpgradeItems; } } public class StorageExtensionData { public int Rows; public int Columns; public string CraftingStation; public string PrefabName; public string Name; public string Description; public List<ItemRequirements> ItemRequirements; } public class StorageInterface : MonoBehaviour, Interactable { private class UpgradeSlotUI { public Image Icon; public Text StationLabel; public Text LevelLabel; } private const int DefaultRows = 5; private const int DefaultColumns = 8; private const int MaxRows = 75; private const int MaxColumns = 8; private const int UpgradeSlotCount = 8; private const float ExtensionScanInterval = 2f; private bool _hasBeenOpened; private bool _suppressDropdownCallback; private ZNetView _zNetView; private float _extensionScanTimer; private static readonly string[] StationNames = new string[8] { "workbench", "forge", "blackforge", "cauldron", "stonecutter", "artisan", "galdr", "preptable" }; private readonly Dictionary<string, int> _stationLevels = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase) { ["workbench"] = 0, ["forge"] = 0, ["blackforge"] = 0, ["cauldron"] = 0, ["stonecutter"] = 0, ["artisan"] = 0, ["galdr"] = 0, ["preptable"] = 0 }; private readonly List<UpgradeSlotUI> _upgradeSlotUis = new List<UpgradeSlotUI>(); private readonly List<string> _currentDropdownOptions = new List<string>(); private string _currentStationName = "None"; private GameObject _panel; private GameObject _stationDropdown; private Container _container; private CraftingStation _craftingStation; private StorageUpgradeSlots _upgradeSlots; private bool _hasDroppedUpgradeItems; private WearNTear _wearNTearComponent; private GameObject _extensionSummaryObject; private Text _extensionSummaryText; public static StorageInterface Instance { get; private set; } public string CurrentStationName => _currentStationName; public int CurrentStationLevel => GetStationLevel(_currentStationName); public CraftingStation CraftingStation => _craftingStation; public Container Container => _container; private Dropdown StationDropdownObject => ((Object)(object)_stationDropdown != (Object)null) ? _stationDropdown.GetComponent<Dropdown>() : null; private void Awake() { _container = ((Component)this).gameObject.AddComponent<Container>(); _container.m_name = "$piece_dwarven_interface"; ((Object)_container).name = "$piece_dwarven_interface"; _container.m_width = 8; _container.m_height = 75; if (_container.GetInventory() != null) { InventoryAccess.SetSize(_container.GetInventory(), 8, 75); } _zNetView = ((Component)this).GetComponent<ZNetView>(); _craftingStation = ((Component)this).gameObject.AddComponent<CraftingStation>(); _craftingStation.m_name = "$piece_workbench"; _craftingStation.m_rangeBuild = 0f; _craftingStation.m_discoverRange = 30f; _craftingStation.m_useDistance = 30f; _craftingStation.m_craftRequireRoof = false; _craftingStation.m_icon = AssetHolder.GetSprite("Interface"); GameObject prefab = PrefabManager.Instance.GetPrefab("piece_workbench"); CraftingStation val = ((prefab != null) ? prefab.GetComponent<CraftingStation>() : null); if ((Object)(object)val != (Object)null) { _craftingStation.m_craftItemDoneEffects = val.m_craftItemDoneEffects; _craftingStation.m_craftItemEffects = val.m_craftItemEffects; _craftingStation.m_repairItemDoneEffects = val.m_repairItemDoneEffects; } _upgradeSlots = ((Component)this).GetComponent<StorageUpgradeSlots>(); _wearNTearComponent = ((Component)this).gameObject.GetComponent<WearNTear>(); if ((Object)(object)_wearNTearComponent != (Object)null) { WearNTear wearNTearComponent = _wearNTearComponent; wearNTearComponent.m_onDestroyed = (Action)Delegate.Combine(wearNTearComponent.m_onDestroyed, new Action(OnDestruction)); } if ((Object)(object)_upgradeSlots != (Object)null) { _upgradeSlots.OnUpgradesChanged += OnUpgradesChanged; RebuildStationUpgrades(); EnsureValidCurrentStation(); } else { Plugin.Logger.LogWarning((object)"StorageInterface is missing StorageUpgradeSlots."); } } private void OnDestruction() { //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_0102: 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_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011b: 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_012b: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) if (_hasDroppedUpgradeItems) { return; } _hasDroppedUpgradeItems = true; if ((Object)(object)_upgradeSlots == (Object)null) { return; } Inventory inventory = _upgradeSlots.GetInventory(); if (inventory == null || ((Object)(object)_zNetView != (Object)null && _zNetView.IsValid() && !_zNetView.IsOwner())) { return; } List<ItemData> list = (from item in inventory.GetAllItems() where item != null select item).ToList(); foreach (ItemData item in list) { ItemData val = item.Clone(); val.m_stack = item.m_stack; inventory.RemoveItem(item); Vector3 val2 = ((Component)this).transform.position + ((Component)this).transform.forward * 1.2f + Vector3.up * 0.75f; ItemDrop.DropItem(val, val.m_stack, val2, Quaternion.identity); Plugin.Logger.LogInfo((object)$"Dropped upgrade item: {val.m_shared.m_name} x{val.m_stack}"); } _upgradeSlots.Save(); _upgradeSlots.InvokeChanged(); } private void OnDestroy() { if ((Object)(object)_upgradeSlots != (Object)null) { _upgradeSlots.OnUpgradesChanged -= OnUpgradesChanged; } if ((Object)(object)_wearNTearComponent != (Object)null) { WearNTear wearNTearComponent = _wearNTearComponent; wearNTearComponent.m_onDestroyed = (Action)Delegate.Remove(wearNTearComponent.m_onDestroyed, new Action(OnDestruction)); } StorageInterfaceExtension[] array = Object.FindObjectsByType<StorageInterfaceExtension>((FindObjectsSortMode)0); foreach (StorageInterfaceExtension storageInterfaceExtension in array) { storageInterfaceExtension.ReleaseOwner(this); } if ((Object)(object)Instance == (Object)(object)this) { Instance = null; } } public bool Interact(Humanoid user, bool hold, bool alt) { if (hold) { return false; } if ((Object)(object)Instance == (Object)(object)this && (Object)(object)_panel != (Object)null && _panel.activeSelf) { CloseInterface(); } else { OpenInterface(); } return true; } public bool UseItem(Humanoid user, ItemData item) { return false; } private void Update() { if (_hasBeenOpened && Object.op_Implicit((Object)(object)_panel) && _panel.activeSelf) { _extensionScanTimer += Time.deltaTime; if (!(_extensionScanTimer < 2f)) { _extensionScanTimer = 0f; RebuildStorageSizeFromExtensions(); } } } private void FixedUpdate() { if (Object.op_Implicit((Object)(object)_panel) && _panel.activeSelf && (!Object.op_Implicit((Object)(object)InventoryGui.instance) || !InventoryGui.instance.IsContainerOpen())) { CloseInterface(); } } private void OpenInterface() { if (GUIManager.Instance != null && !((Object)(object)InventoryGui.instance == (Object)null)) { _hasBeenOpened = true; Instance = this; bool flag = (Object)(object)_panel == (Object)null; if (flag) { CreatePanel(); _panel.SetActive(false); } RebuildStationUpgrades(); EnsureValidCurrentStation(); RebuildStorageSizeFromExtensions(); RefreshStationDropdown(); RefreshUpgradeSlots(); InventoryGui.instance.Show(_container, 1); _panel.SetActive(true); if (flag) { CenterPanel(); } ApplyCurrentCraftingStation(); } } private void CloseInterface() { if (Object.op_Implicit((Object)(object)_panel)) { _panel.SetActive(false); } if (Object.op_Implicit((Object)(object)InventoryGui.instance)) { InventoryGui.instance.Hide(); } ResetPlayerCrafting(); } private void RebuildStorageSizeFromExtensions() { int num = 5; int num2 = 8; int num3 = 0; int num4 = 0; StorageInterfaceExtension[] array = Object.FindObjectsByType<StorageInterfaceExtension>((FindObjectsSortMode)0); StorageInterfaceExtension[] array2 = array; foreach (StorageInterfaceExtension storageInterfaceExtension in array2) { if (Object.op_Implicit((Object)(object)storageInterfaceExtension)) { storageInterfaceExtension.RefreshOwner(force: true); if (storageInterfaceExtension.IsOwnedBy(this)) { num3++; num4 += storageInterfaceExtension.addedRows; num += storageInterfaceExtension.addedRows; num2 += storageInterfaceExtension.addedColumns; } } } num = Mathf.Clamp(num, 5, 75); num2 = Mathf.Clamp(num2, 8, 8); UpdateExtensionSummaryText(num3, num4, num, num2); ResizeStorage(num, num2); } private void UpdateExtensionSummaryText(int extensionCount, int addedRows, int totalRows, int totalColumns) { if (Object.op_Implicit((Object)(object)_extensionSummaryText)) { _extensionSummaryText.text = $"Extensions: {extensionCount} Added Rows: +{addedRows} Storage: {totalColumns}x{totalRows}"; } } private void ResizeStorage(int rows, int columns) { if (!Object.op_Implicit((Object)(object)_container) || _container.GetInventory() == null) { return; } Inventory inventory = _container.GetInventory(); if (inventory.GetWidth() != columns || inventory.GetHeight() != rows || _container.m_width != columns || _container.m_height != rows) { if ((inventory.GetWidth() > columns || inventory.GetHeight() > rows) && (!Object.op_Implicit((Object)(object)_zNetView) || !_zNetView.IsValid() || _zNetView.IsOwner())) { DropItemsOutsideBounds(columns, rows); } _container.m_width = columns; _container.m_height = rows; InventoryAccess.SetSize(inventory, columns, rows); MarkStorageChanged(); if (Object.op_Implicit((Object)(object)InventoryGui.instance) && InventoryGui.instance.IsContainerOpen()) { InventoryGuiAccess.RefreshCrafting(InventoryGui.instance); } Plugin.Logger.LogInfo((object)$"Storage resized to {columns}x{rows}"); } } private void DropItemsOutsideBounds(int columns, int rows) { //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: 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_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) Inventory inventory = _container.GetInventory(); if (inventory == null) { return; } List<ItemData> list = new List<ItemData>(); foreach (ItemData allItem in inventory.GetAllItems()) { if (allItem != null) { int x = allItem.m_gridPos.x; int y = allItem.m_gridPos.y; if (x >= columns || y >= rows) { list.Add(allItem); } } } foreach (ItemData item in list) { Vector3 val = ((Component)this).transform.position + ((Component)this).transform.forward * 1.5f + Vector3.up * 0.75f; ItemData val2 = item.Clone(); val2.m_stack = item.m_stack; inventory.RemoveItem(item); ItemDrop.DropItem(val2, val2.m_stack, val, Quaternion.identity); Plugin.Logger.LogInfo((object)("Dropped item " + item.m_shared.m_name + " outside bounds")); } } private void MarkStorageChanged() { if (!Object.op_Implicit((Object)(object)_container)) { return; } try { Inventory inventory = _container.GetInventory(); if (inventory != null) { InventoryAccess.NotifyChanged(inventory); } } catch (Exception ex) { Plugin.Logger.LogWarning((object)("Failed to mark storage changed: " + ex.Message)); } } private void OnUpgradesChanged() { RebuildStationUpgrades(); EnsureValidCurrentStation(); RefreshStationDropdown(); RefreshUpgradeSlots(); if ((Object)(object)Instance == (Object)(object)this) { ApplyCurrentCraftingStation(); } } private void RebuildStationUpgrades() { string[] stationNames = StationNames; foreach (string key in stationNames) { _stationLevels[key] = 0; } if ((Object)(object)_upgradeSlots == (Object)null) { return; } Inventory inventory = _upgradeSlots.GetInventory(); if (inventory == null) { return; } foreach (ItemData allItem in inventory.GetAllItems()) { if (TryGetUpgradeInfo(allItem, out var stationName, out var stationLevel) && _stationLevels.ContainsKey(stationName)) { _stationLevels[stationName] = Mathf.Max(_stationLevels[stationName], stationLevel); } } } private void EnsureValidCurrentStation() { if (!HasStationUpgrade(_currentStationName)) { _currentStationName = GetUnlockedStations().FirstOrDefault() ?? "None"; } } private IEnumerable<string> GetUnlockedStations() { return StationNames.Where(HasStationUpgrade); } private bool HasStationUpgrade(string stationName) { int value; return !string.IsNullOrEmpty(stationName) && _stationLevels.TryGetValue(stationName, out value) && value > 0; } private int GetStationLevel(string stationName) { int value; return (!string.IsNullOrEmpty(stationName) && _stationLevels.TryGetValue(stationName, out value)) ? value : 0; } private static bool TryGetUpgradeInfo(ItemData item, out string stationName, out int stationLevel) { stationName = null; stationLevel = 0; if (item == null) { return false; } if (item.m_customData.TryGetValue("DwarvenUpgrade", out var value)) { stationName = value; } if (item.m_customData.TryGetValue("DwarvenUpgradeLevel", out var value2) && int.TryParse(value2, out var result)) { stationLevel = result; } if (!string.IsNullOrEmpty(stationName) && stationLevel > 0) { return true; } if ((Object)(object)item.m_dropPrefab == (Object)null) { return false; } string key = ((Object)item.m_dropPrefab).name.Replace("(Clone)", ""); if (string.IsNullOrEmpty(stationName) && !Plugin.UpgradeStationsByPrefabName.TryGetValue(key, out stationName)) { return false; } if (stationLevel <= 0 && !Plugin.UpgradeAmountsByPrefabName.TryGetValue(key, out stationLevel)) { stationLevel = 1; } return !string.IsNullOrEmpty(stationName) && stationLevel > 0; } private static string GetStationDisplayName(string stationName) { if (1 == 0) { } string text = stationName switch { "workbench" => "$piece_workbench", "forge" => "$piece_forge", "blackforge" => "$piece_blackforge", "cauldron" => "$piece_cauldron", "stonecutter" => "$piece_stonecutter", "artisan" => "$piece_artisanstation", "galdr" => "$piece_magetable", "preptable" => "$piece_preptable", _ => stationName, }; if (1 == 0) { } string text2 = text; return LocalizationManager.Instance.TryTranslate(text2); } private void CreatePanel() { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) Transform transform = ((Component)InventoryGui.instance.m_container).transform; _panel = GUIManager.Instance.CreateWoodpanel(transform.parent, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, 700f, 900f, true); _panel.transform.SetSiblingIndex(Mathf.Max(0, transform.GetSiblingIndex() - 1)); CreateTitle(); CreateExtensionSummaryText(); CreateUpgradeSlots(); CreateStationDropdown(); CreateCloseButton(); } private void CenterPanel() { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_008c: 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_0095: 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_009f: Unknown result type (might be due to invalid IL or missing references) Canvas.ForceUpdateCanvases(); RectTransform component = _panel.GetComponent<RectTransform>(); Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(0.5f, 0.5f); component.anchorMax = val; component.anchorMin = val; component.pivot = new Vector2(0.5f, 0.5f); component.anchoredPosition = Vector2.zero; Canvas componentInParent = _panel.GetComponentInParent<Canvas>(); if (Object.op_Implicit((Object)(object)componentInParent)) { Transform transform = ((Component)componentInParent.rootCanvas).transform; RectTransform val2 = (RectTransform)(object)((transform is RectTransform) ? transform : null); if (val2 != null) { Rect rect = val2.rect; ((Transform)component).position = ((Transform)val2).TransformPoint(Vector2.op_Implicit(((Rect)(ref rect)).center)); } } } private void CreateExtensionSummaryText() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003f: 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_0056: Unknown result type (might be due to invalid IL or missing references) _extensionSummaryObject = GUIManager.Instance.CreateText("Extensions: 0 | Added Rows: 0", _panel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -85f), GUIManager.Instance.AveriaSerif, 20, Color.white, true, Color.black, 500f, 35f, false); _extensionSummaryText = _extensionSummaryObject.GetComponent<Text>(); if ((Object)(object)_extensionSummaryText != (Object)null) { _extensionSummaryText.alignment = (TextAnchor)4; } } private void CreateTitle() { //IL_0020: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) GUIManager.Instance.CreateText("Storage Interface", _panel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(90f, -45f), GUIManager.Instance.AveriaSerifBold, 32, Color.white, true, Color.black, 400f, 50f, false); } private void CreateUpgradeSlots() { //IL_004b: 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_0065: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Expected O, but got Unknown //IL_00f6: 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_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_0185: 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_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Expected O, but got Unknown //IL_01ff: 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_0219: Unknown result type (might be due to invalid IL or missing references) //IL_022a: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < 8; i++) { int index = i; float num = 320f - (float)i * 76f; GameObject val = GUIManager.Instance.CreateButton("", _panel.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-240f, num), 64f, 64f); Button component = val.GetComponent<Button>(); if ((Object)(object)component != (Object)null) { ((UnityEvent)component.onClick).AddListener((UnityAction)delegate { OnUpgradeSlotClicked(index); }); } GameObject val2 = new GameObject("Icon", new Type[2] { typeof(RectTransform), typeof(Image) }); val2.transform.SetParent(val.transform, false); RectTransform component2 = val2.GetComponent<RectTransform>(); component2.anchorMin = Vector2.zero; component2.anchorMax = Vector2.one; component2.offsetMin = new Vector2(7f, 7f); component2.offsetMax = new Vector2(-7f, -7f); Image component3 = val2.GetComponent<Image>(); ((Behaviour)component3).enabled = false; ((Graphic)component3).raycastTarget = false; GameObject val3 = GUIManager.Instance.CreateText("Empty", _panel.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-110f, num), GUIManager.Instance.AveriaSerif, 18, Color.grey, true, Color.black, 170f, 45f, false); Text component4 = val3.GetComponent<Text>(); if ((Object)(object)component4 != (Object)null) { component4.alignment = (TextAnchor)3; } GameObject val4 = GUIManager.Instance.CreateText("", _panel.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(15f, num), GUIManager.Instance.AveriaSerif, 18, Color.white, true, Color.black, 100f, 45f, false); Text component5 = val4.GetComponent<Text>(); if ((Object)(object)component5 != (Object)null) { component5.alignment = (TextAnchor)3; } _upgradeSlotUis.Add(new UpgradeSlotUI { Icon = component3, StationLabel = component4, LevelLabel = component5 }); } } private void OnUpgradeSlotClicked(int index) { //IL_00d1: 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_02ee: Unknown result type (might be due to invalid IL or missing references) //IL_02f9: Unknown result type (might be due to invalid IL or missing references) //IL_0303: Unknown result type (might be due to invalid IL or missing references) //IL_0308: Unknown result type (might be due to invalid IL or missing references) //IL_030d: Unknown result type (might be due to invalid IL or missing references) //IL_0317: Unknown result type (might be due to invalid IL or missing references) //IL_031c: Unknown result type (might be due to invalid IL or missing references) //IL_0321: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_upgradeSlots == (Object)null) { return; } Inventory inventory = _upgradeSlots.GetInventory(); if (inventory == null) { return; } InventoryGui instance = InventoryGui.instance; ItemData dragItem = InventoryGuiAccess.GetDragItem(instance); Inventory dragInventory = InventoryGuiAccess.GetDragInventory(instance); if (dragItem != null) { if (!TryGetUpgradeInfo(dragItem, out var stationName, out var stationLevel)) { Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)2, "Invalid upgrade item", 0, (Sprite)null, false); } return; } ItemData itemAt = inventory.GetItemAt(0, index); if (itemAt != null) { Player localPlayer2 = Player.m_localPlayer; if (localPlayer2 != null) { ((Character)localPlayer2).Message((MessageType)2, "Upgrade slot is occupied", 0, (Sprite)null, false); } return; } ItemData val = dragItem.Clone(); val.m_stack = 1; val.m_gridPos = new Vector2i(0, index); val.m_customData["DwarvenUpgrade"] = stationName; val.m_customData["DwarvenUpgradeLevel"] = stationLevel.ToString(); if (!inventory.AddItem(val)) { Player localPlayer3 = Player.m_localPlayer; if (localPlayer3 != null) { ((Character)localPlayer3).Message((MessageType)2, "Could not add upgrade item", 0, (Sprite)null, false); } return; } bool flag = false; if (dragInventory != null) { flag = dragInventory.RemoveItem(dragItem, 1); if (flag) { Container container = _container; if (dragInventory == ((container != null) ? container.GetInventory() : null)) { MarkStorageChanged(); } } } if (!flag) { flag = (Object)(object)Player.m_localPlayer != (Object)null && ((Humanoid)Player.m_localPlayer).GetInventory().RemoveItem(dragItem, 1); } if (!flag) { Container container2 = _container; if (((container2 != null) ? container2.GetInventory() : null) != null) { flag = _container.GetInventory().RemoveItem(dragItem, 1); MarkStorageChanged(); } } if (!flag) { inventory.RemoveItem(val); Player localPlayer4 = Player.m_localPlayer; if (localPlayer4 != null) { ((Character)localPlayer4).Message((MessageType)2, "Could not move upgrade item", 0, (Sprite)null, false); } } else { InventoryGuiAccess.ClearDragItem(instance); _upgradeSlots.Save(); _upgradeSlots.InvokeChanged(); RefreshUpgradeSlots(); } return; } ItemData itemAt2 = inventory.GetItemAt(0, index); if (itemAt2 == null) { return; } inventory.RemoveItem(itemAt2); if (!((Object)(object)Player.m_localPlayer != (Object)null) || !((Humanoid)Player.m_localPlayer).GetInventory().AddItem(itemAt2)) { Container container3 = _container; if (((container3 != null) ? container3.GetInventory() : null) != null && _container.GetInventory().AddItem(itemAt2)) { MarkStorageChanged(); } else { ItemDrop.DropItem(itemAt2, itemAt2.m_stack, ((Component)this).transform.position + ((Component)this).transform.forward * 1.2f + Vector3.up * 0.75f, Quaternion.identity); } } _upgradeSlots.Save(); _upgradeSlots.InvokeChanged(); RefreshUpgradeSlots(); } private void RefreshUpgradeSlots() { //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_0261: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_upgradeSlots == (Object)null) { return; } Inventory inventory = _upgradeSlots.GetInventory(); if (inventory == null) { return; } for (int i = 0; i < _upgradeSlotUis.Count; i++) { ItemData itemAt = inventory.GetItemAt(0, i); UpgradeSlotUI upgradeSlotUI = _upgradeSlotUis[i]; if (itemAt == null) { upgradeSlotUI.Icon.sprite = null; ((Behaviour)upgradeSlotUI.Icon).enabled = false; if ((Object)(object)upgradeSlotUI.StationLabel != (Object)null) { upgradeSlotUI.StationLabel.text = "Empty"; ((Graphic)upgradeSlotUI.StationLabel).color = Color.grey; } if ((Object)(object)upgradeSlotUI.LevelLabel != (Object)null) { upgradeSlotUI.LevelLabel.text = ""; ((Graphic)upgradeSlotUI.LevelLabel).color = Color.grey; } continue; } Sprite[] icons = itemAt.m_shared.m_icons; if (icons != null && icons.Length > 0) { upgradeSlotUI.Icon.sprite = itemAt.m_shared.m_icons[0]; ((Behaviour)upgradeSlotUI.Icon).enabled = true; } else { upgradeSlotUI.Icon.sprite = null; ((Behaviour)upgradeSlotUI.Icon).enabled = false; } if (TryGetUpgradeInfo(itemAt, out var stationName, out var stationLevel)) { if ((Object)(object)upgradeSlotUI.StationLabel != (Object)null) { upgradeSlotUI.StationLabel.text = GetStationDisplayName(stationName); ((Graphic)upgradeSlotUI.StationLabel).color = Color.white; } if (!((Object)(object)upgradeSlotUI.LevelLabel == (Object)null)) { upgradeSlotUI.LevelLabel.text = $"Level {stationLevel}"; ((Graphic)upgradeSlotUI.LevelLabel).color = Color.white; } } else { if ((Object)(object)upgradeSlotUI.StationLabel != (Object)null) { upgradeSlotUI.StationLabel.text = "Unknown"; ((Graphic)upgradeSlotUI.StationLabel).color = Color.red; } if (!((Object)(object)upgradeSlotUI.LevelLabel == (Object)null)) { upgradeSlotUI.LevelLabel.text = ""; ((Graphic)upgradeSlotUI.LevelLabel).color = Color.red; } } } } private void CreateStationDropdown() { //IL_001c: 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_003a: Unknown result type (might be due to invalid IL or missing references) _stationDropdown = GUIManager.Instance.CreateDropDown(_panel.transform, new Vector2(1f, 1f), new Vector2(1f, 1f), new Vector2(-115f, -120f), 16, 180f, 35f); Dropdown stationDropdownObject = StationDropdownObject; if (!((Object)(object)stationDropdownObject == (Object)null)) { RefreshStationDropdown(); ((UnityEvent<int>)(object)stationDropdownObject.onValueChanged).AddListener((UnityAction<int>)OnDropdownValueChanged); } } private void RefreshStationDropdown() { Dropdown stationDropdownObject = StationDropdownObject; if (!((Object)(object)stationDropdownObject == (Object)null)) { _currentDropdownOptions.Clear(); _currentDropdownOptions.AddRange(GetUnlockedStations()); if (_currentDropdownOptions.Count == 0) { _currentDropdownOptions.Add("None"); } if (!_currentDropdownOptions.Contains(_currentStationName)) { _currentStationName = _currentDropdownOptions[0]; } _suppressDropdownCallback = true; stationDropdownObject.ClearOptions(); stationDropdownObject.AddOptions(_currentDropdownOptions); stationDropdownObject.value = Mathf.Max(0, _currentDropdownOptions.IndexOf(_currentStationName)); stationDropdownObject.RefreshShownValue(); _suppressDropdownCallback = false; } } private void CreateCloseButton() { //IL_0020: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Expected O, but got Unknown GameObject val = GUIManager.Instance.CreateButton("Close", _panel.transform, new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), new Vector2(0f, 55f), 180f, 50f); Button component = val.GetComponent<Button>(); if ((Object)(object)component != (Object)null) { ((UnityEvent)component.onClick).AddListener(new UnityAction(CloseInterface)); } } private void OnDropdownValueChanged(int index) { if (!_suppressDropdownCallback && index >= 0 && index < _currentDropdownOptions.Count) { SetCraftingStation(_currentDropdownOptions[index]); } } private void ApplyCurrentCraftingStation() { if (_currentStationName == "None") { ClearPlayerCraftingStation(); } else { SetCraftingStation(_currentStationName); } } private void SetCraftingStation(string stationName) { if (string.IsNullOrEmpty(stationName) || stationName == "None") { _currentStationName = "None"; ClearPlayerCraftingStation(); return; } if (!HasStationUpgrade(stationName)) { Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)2, "Missing station upgrade", 0, (Sprite)null, false); } EnsureValidCurrentStation(); RefreshStationDropdown(); ApplyCurrentCraftingStation(); return; } CraftingStation craftingStation = _craftingStation; if (1 == 0) { } string name = stationName switch { "forge" => "$piece_forge", "blackforge" => "$piece_blackforge", "cauldron" => "$piece_cauldron", "stonecutter" => "$piece_stonecutter", "artisan" => "$piece_artisanstation", "galdr" => "$piece_magetable", "preptable" => "$piece_preptable", _ => "$piece_workbench", }; if (1 == 0) { } craftingStation.m_name = name; _currentStationName = stationName; Player localPlayer2 = Player.m_localPlayer; if (localPlayer2 != null) { localPlayer2.SetCraftingStation(_craftingStation); } InventoryGuiAccess.RefreshCrafting(InventoryGui.instance); } private static void ClearPlayerCraftingStation() { Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { localPlayer.SetCraftingStation((CraftingStation)null); } InventoryGuiAccess.RefreshCrafting(InventoryGui.instance); } private static void ResetPlayerCrafting() { Instance = null; ClearPlayerCraftingStation(); } } public class StorageInterfaceExtension : MonoBehaviour, Hoverable { public string extensionId; public int addedRows; public int addedColumns; public float range = 10f; public string hoverText; public string hoverName; private const float OwnerRefreshInterval = 1f; private StorageInterface _owningInterface; private float _nextOwnerRefreshTime; private string _cachedHoverText; private string _cachedHoverName; private bool IsOwned => (Object)(object)_owningInterface != (Object)null; private void Awake() { _cachedHoverText = LocalizationManager.Instance.TryTranslate(hoverText); _cachedHoverName = LocalizationManager.Instance.TryTranslate(hoverName); } public bool IsOwnedBy(StorageInterface storageInterface) { return Object.op_Implicit((Object)(object)storageInterface) && (Object)(object)_owningInterface == (Object)(object)storageInterface; } public void RefreshOwner(bool force = false) { if (!force && Time.time < _nextOwnerRefreshTime) { return; } _nextOwnerRefreshTime = Time.time + 1f; if (!Object.op_Implicit((Object)(object)_owningInterface) || !IsInRangeOf(_owningInterface)) { _owningInterface = null; StorageInterface[] source = Object.FindObjectsByType<StorageInterface>((FindObjectsSortMode)0); _owningInterface = (from storageInterface in source.Where((StorageInterface storageInterface) => Object.op_Implicit((Object)(object)storageInterface)).Where(IsInRangeOf) orderby Vector3.Distance(((Component)this).transform.position, ((Component)storageInterface).transform.position) select storageInterface).FirstOrDefault(); } } private bool IsInRangeOf(StorageInterface storageInterface) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)storageInterface)) { return false; } return Vector3.Distance(((Component)this).transform.position, ((Component)storageInterface).transform.position) <= range; } public void ReleaseOwner(StorageInterface storageInterface) { if ((Object)(object)_owningInterface == (Object)(object)storageInterface) { _owningInterface = null; } } public string GetHoverText() { RefreshOwner(); string text = (IsOwned ? " <color=yellow>(in use)</color>" : " <color=grey>(not in use)</color>"); return _cachedHoverText + text; } public string GetHoverName() { RefreshOwner(); string text = (IsOwned ? " <color=yellow>(in use)</color>" : " <color=grey>(not in use)</color>"); return _cachedHoverName + text; } public float GetHoverOffset() { return 0.1f; } } public class StorageUpgrade { public string Name; public string Description; public string CraftingStation; public string StationKey; public List<ItemRequirements> ItemRequirements; public int MinQualityLevel; public string SpriteName; } public class ItemRequirements { public string Name; public int Amount; public int UpgradeAmount; } public class StorageUpgradeSlots : MonoBehaviour { private const string ZdoKey = "dwarven_upgrade_inventory"; private const int Width = 1; private const int Height = 8; private ZNetView _nview; private Inventory _inventory; public event Action OnUpgradesChanged; private void Awake() { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown _nview = ((Component)this).GetComponent<ZNetView>(); _inventory = new Inventory("Dwarven Upgrades", (Sprite)null, 1, 8); Load(); } public Inventory GetInventory() { return _inventory; } private static bool CanAcceptItem(ItemData item) { if (item == null) { return false; } Plugin.Logger.LogInfo((object)("item: " + item.m_shared.m_name)); foreach (KeyValuePair<string, string> customDatum in item.m_customData) { Plugin.Logger.LogInfo((object)("data: " + customDatum.Key + " - " + customDatum.Value)); } if (item.m_customData.ContainsKey("DwarvenUpgrade")) { return true; } if ((Object)(object)item.m_dropPrefab == (Object)null) { return false; } string text = ((Object)item.m_dropPrefab).name.Replace("(Clone)", ""); Plugin.Logger.LogInfo((object)("prefabName: " + text)); return Plugin.UpgradeStationsByPrefabName.ContainsKey(text); } public void InvokeChanged() { this.OnUpgradesChanged?.Invoke(); } public bool AddItem(ItemData item) { if (!CanAcceptItem(item)) { return false; } if (!_inventory.AddItem(item.Clone())) { return false; } Save(); InvokeChanged(); return true; } public bool RemoveItem(ItemData item) { if (item == null) { return false; } if (!_inventory.RemoveItem(item)) { return false; } Save(); InvokeChanged(); return true; } public void Save() { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown if (!((Object)(object)_nview == (Object)null) && _nview.IsValid()) { ZPackage val = new ZPackage(); _inventory.Save(val); _nview.GetZDO().Set("dwarven_upgrade_inventory", val.GetBase64()); } } private void Load() { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Expected O, but got Unknown if (!((Object)(object)_nview == (Object)null) && _nview.IsValid()) { string text = _nview.GetZDO().GetString("dwarven_upgrade_inventory", ""); if (!string.IsNullOrEmpty(text)) { ZPackage val = new ZPackage(text); _inventory.Load(val); } } } } public static class MyPluginInfo { public const string PLUGIN_GUID = "DwarvenStorage"; public const string PLUGIN_NAME = "My first plugin"; public const string PLUGIN_VERSION = "1.0.1"; } }