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 GrabMaterials v1.1.0
BepInEx/plugins/GrabMaterials.dll
Decompiled 3 days ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Configuration; using GrabMaterials; using GrabMaterialsMod; using HarmonyLib; using Jotunn; using Jotunn.Configs; using Jotunn.Extensions; using Jotunn.Managers; using Jotunn.Utils; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("GrabMaterials")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("GrabMaterials")] [assembly: AssemblyCopyright("Copyright © 2025")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("f3f4f7f9-7343-4b53-9531-aa1e3d80ea19")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace GrabMaterialsMod { [BepInPlugin("DeathMonger.GrabMaterialsMod", "Grab Materials", "1.1.0")] [BepInProcess("valheim.exe")] public class GrabMaterialsMod : BaseUnityPlugin { public class GrabPackConfig { public ConfigEntry<string> Name; public ConfigEntry<KeyboardShortcut> Key; public ConfigEntry<string> Items; public ConfigEntry<bool> GrabDelta; public ButtonConfig Button; public GrabPackConfig(ConfigFile config, string section, string name, KeyboardShortcut keyboardShortcut, string items) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown //IL_003d: 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_0054: Expected O, but got Unknown //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Expected O, but got Unknown //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: 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_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Expected O, but got Unknown Name = config.Bind<string>(section, section + " Name", name, new ConfigDescription("Name of the grab pack", (AcceptableValueBase)null, Array.Empty<object>())); Key = config.Bind<KeyboardShortcut>(section, section + " Key", keyboardShortcut, new ConfigDescription("Key to grab materials for the grab pack", (AcceptableValueBase)null, Array.Empty<object>())); Items = config.Bind<string>(section, section + " Items", items, new ConfigDescription("Items to grab for the grab pack", (AcceptableValueBase)null, Array.Empty<object>())); GrabDelta = config.Bind<bool>(section, section + " Grab Delta", false, new ConfigDescription("If true, only grab the shortfall between what you already have and what's needed (e.g. if the pack needs 10 wood and you have 7, only 3 will be grabbed).", (AcceptableValueBase)null, Array.Empty<object>())); Button = new ButtonConfig { Name = Name.Value, ShortcutConfig = Key }; } } [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static EventHandler <>9__21_0; public static ConsoleEvent <>9__22_0; public static ConsoleEvent <>9__22_1; public static ConsoleEvent <>9__22_2; public static ConsoleEvent <>9__22_3; public static ConsoleEvent <>9__22_4; public static ConsoleEvent <>9__22_5; public static ConsoleEvent <>9__22_6; public static ConsoleEvent <>9__22_7; public static ConsoleEvent <>9__22_8; public static ConsoleEvent <>9__22_9; public static ConsoleEvent <>9__22_10; public static ConsoleEvent <>9__22_11; public static ConsoleEvent <>9__22_12; public static ConsoleEvent <>9__22_13; public static ConsoleEvent <>9__22_14; public static ConsoleEvent <>9__22_15; internal void <InitConfig>b__21_0(object sender, EventArgs e) { Debug.Log((object)("Grabpack renamed " + sender.ToString() + " " + e.ToString())); } internal void <InitCommands>b__22_0(ConsoleEventArgs args) { args.GrabItemsFromNearbyContainers(); } internal void <InitCommands>b__22_1(ConsoleEventArgs args) { args.GrabItemsFromNearbyContainers(); } internal void <InitCommands>b__22_2(ConsoleEventArgs args) { ConsoleCommands.GrabMaterialsForSelectedPiece(); } internal void <InitCommands>b__22_3(ConsoleEventArgs args) { args.GrabMaterialsForPiece(); } internal void <InitCommands>b__22_4(ConsoleEventArgs args) { ListKnownContainers(); } internal void <InitCommands>b__22_5(ConsoleEventArgs args) { ListLocalContainers(args); } internal void <InitCommands>b__22_6(ConsoleEventArgs args) { ListLocalContainerContents(args); } internal void <InitCommands>b__22_7(ConsoleEventArgs args) { ListGrabPacks(); } internal void <InitCommands>b__22_8(ConsoleEventArgs args) { ListLocalInventory(args); } internal void <InitCommands>b__22_9(ConsoleEventArgs args) { ListLocalInventory(args); } internal void <InitCommands>b__22_10(ConsoleEventArgs args) { SetInventoryStyle(args); } internal void <InitCommands>b__22_11(ConsoleEventArgs args) { FindContainersWithMatchingItems(args); } internal void <InitCommands>b__22_12(ConsoleEventArgs args) { FindContainersWithMatchingItems(args); } internal void <InitCommands>b__22_13(ConsoleEventArgs args) { StoreItemsInNearbyContainers(); } internal void <InitCommands>b__22_14(ConsoleEventArgs args) { CountInventory(args); } internal void <InitCommands>b__22_15(ConsoleEventArgs args) { ListAllPieces(); } } private const string ModGuid = "DeathMonger.GrabMaterialsMod"; private readonly Harmony harmony = new Harmony("DeathMonger.GrabMaterialsMod"); public static GrabMaterialsMod Instance; public ConfigEntry<float> HighlightDuration; public ConfigEntry<float> PanelIdleTimeout; public ConfigEntry<float> PanelFadeDuration; public ConfigEntry<bool> PanelDismissOnMovement; public ConfigEntry<bool> PanelCategoryUnderlines; public ConfigEntry<bool> PanelShowItemIcons; public ConfigEntry<float> PanelIconSize; public ConfigEntry<MaterialsPanel.InventoryShape> InventoryShape; public ConfigEntry<MaterialsPanel.InventoryStyle> InventoryStyle; public ConfigEntry<bool> ShowDistanceHud; public ConfigEntry<bool> ShowDistanceCoords; public ConfigEntry<float> DistanceHudOffsetX; public ConfigEntry<float> DistanceHudOffsetY; private ButtonConfig GrabSelectedPieceMatsButton; private ConfigEntry<KeyCode> GrabSelectedPieceMatsKeyboardConfig; public GrabPackConfig[] GrabPacks; private void Awake() { if ((Object)(object)Instance == (Object)null) { Debug.Log((object)"GrabMaterialsMod instance created and Awake called for the first time"); Instance = this; } else if ((Object)(object)Instance == (Object)(object)this) { Debug.LogWarning((object)"GrabMaterialsMod Awake called an additional time"); } else { Debug.LogError((object)"GrabMaterialsMod instance already exists, additional one created, should it be destroyed?"); Instance = this; } harmony.PatchAll(); InitConfig(); InitCommands(); InitButtons(); } private void InitConfig() { //IL_000b: 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_0039: Expected O, but got Unknown //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Expected O, but got Unknown //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Expected O, but got Unknown //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Expected O, but got Unknown //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Expected O, but got Unknown //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Expected O, but got Unknown //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Expected O, but got Unknown //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Expected O, but got Unknown //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Expected O, but got Unknown //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Expected O, but got Unknown //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Expected O, but got Unknown //IL_0261: Unknown result type (might be due to invalid IL or missing references) //IL_026b: Expected O, but got Unknown //IL_0291: Unknown result type (might be due to invalid IL or missing references) //IL_029b: Expected O, but got Unknown //IL_02c1: Unknown result type (might be due to invalid IL or missing references) //IL_02f3: Unknown result type (might be due to invalid IL or missing references) //IL_0325: Unknown result type (might be due to invalid IL or missing references) //IL_0357: Unknown result type (might be due to invalid IL or missing references) //IL_0380: Unknown result type (might be due to invalid IL or missing references) //IL_03b2: Unknown result type (might be due to invalid IL or missing references) //IL_03e4: Unknown result type (might be due to invalid IL or missing references) //IL_0416: Unknown result type (might be due to invalid IL or missing references) //IL_043f: Unknown result type (might be due to invalid IL or missing references) //IL_0472: Unknown result type (might be due to invalid IL or missing references) //IL_04c4: Unknown result type (might be due to invalid IL or missing references) new ConfigDescription("Key to grab portal materials", (AcceptableValueBase)null, Array.Empty<object>()); GrabSelectedPieceMatsKeyboardConfig = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Grab Selected Piece", "GrabSelectedPieceMatsKey", (KeyCode)106, new ConfigDescription("Key to grab materials for the currently selectede build piece", (AcceptableValueBase)null, Array.Empty<object>())); HighlightDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Client config", "Highlight Duration", 2f, new ConfigDescription("Duration in seconds to highlight containers when grabbing materials", (AcceptableValueBase)null, Array.Empty<object>())); PanelIdleTimeout = ((BaseUnityPlugin)this).Config.Bind<float>("Panel UI", "Idle Timeout (seconds)", 15f, new ConfigDescription("Seconds the grab-results panel stays fully visible before fading out automatically.", (AcceptableValueBase)null, Array.Empty<object>())); PanelFadeDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Panel UI", "Fade Duration (seconds)", 3f, new ConfigDescription("Seconds the grab-results panel takes to fade out.", (AcceptableValueBase)null, Array.Empty<object>())); PanelDismissOnMovement = ((BaseUnityPlugin)this).Config.Bind<bool>("Panel UI", "Dismiss On Movement", true, new ConfigDescription("Start fading the panel when the player begins moving, attacking, blocking, or jumping. If false, only the idle timeout dismisses the panel.", (AcceptableValueBase)null, Array.Empty<object>())); InventoryStyle = ((BaseUnityPlugin)this).Config.Bind<MaterialsPanel.InventoryStyle>("Panel UI", "Inventory Style", MaterialsPanel.InventoryStyle.List, new ConfigDescription("Display style for the /inventory panel. List = grouped by category, count + name per row (counts right-aligned). Table = flat 3-column table with Category / Item / Count headers.", (AcceptableValueBase)null, Array.Empty<object>())); PanelCategoryUnderlines = ((BaseUnityPlugin)this).Config.Bind<bool>("Panel UI", "Category Underlines", true, new ConfigDescription("In List mode, draw a thin orange line under each category name. Has no effect in Table mode.", (AcceptableValueBase)null, Array.Empty<object>())); InventoryShape = ((BaseUnityPlugin)this).Config.Bind<MaterialsPanel.InventoryShape>("Panel UI", "Inventory Shape", MaterialsPanel.InventoryShape.SlightlyWide, new ConfigDescription("Target shape for the inventory panel in List mode. The panel auto-picks the column count that produces the closest match. MaxHeight = always 1 column. MaxWidth = fan out as many columns as fit on the screen.", (AcceptableValueBase)null, Array.Empty<object>())); PanelShowItemIcons = ((BaseUnityPlugin)this).Config.Bind<bool>("Panel UI", "Show Item Icons", true, new ConfigDescription("Show each item's icon next to its name in the inventory panel.", (AcceptableValueBase)null, Array.Empty<object>())); PanelIconSize = ((BaseUnityPlugin)this).Config.Bind<float>("Panel UI", "Icon Size", 24f, new ConfigDescription("Width of the item-icon column in pixels. Icons are square and sized to fit. Beyond ~26 the row stays the same height so icons get visually capped by the row.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(12f, 40f), Array.Empty<object>())); ShowDistanceHud = ((BaseUnityPlugin)this).Config.Bind<bool>("Distance HUD", "Enabled", true, new ConfigDescription("Show a small always-on widget displaying the player's horizontal distance from the world center.", (AcceptableValueBase)null, Array.Empty<object>())); ShowDistanceCoords = ((BaseUnityPlugin)this).Config.Bind<bool>("Distance HUD", "Show Coordinates", false, new ConfigDescription("Also include the player's (X, Z) coordinates in the distance widget.", (AcceptableValueBase)null, Array.Empty<object>())); DistanceHudOffsetX = ((BaseUnityPlugin)this).Config.Bind<float>("Distance HUD", "Offset X (px)", 10f, new ConfigDescription("Horizontal offset from the upper-left corner of the screen.", (AcceptableValueBase)null, Array.Empty<object>())); DistanceHudOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("Distance HUD", "Offset Y (px)", 10f, new ConfigDescription("Vertical offset from the top of the screen.", (AcceptableValueBase)null, Array.Empty<object>())); GrabPacks = new GrabPackConfig[10] { new GrabPackConfig(((BaseUnityPlugin)this).Config, "Grab Pack 1", "Explore", new KeyboardShortcut((KeyCode)103, Array.Empty<KeyCode>()), "Workbench,Chest,Portal"), new GrabPackConfig(((BaseUnityPlugin)this).Config, "Grab Pack 2", "Karve Explore", new KeyboardShortcut((KeyCode)103, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 }), "Workbench,Chest,Portal,Karve"), new GrabPackConfig(((BaseUnityPlugin)this).Config, "Grab Pack 3", "Longship Explore", new KeyboardShortcut((KeyCode)103, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), "Workbench,Chest,Portal,Longship"), new GrabPackConfig(((BaseUnityPlugin)this).Config, "Grab Pack 4", "Swamp Explore", new KeyboardShortcut((KeyCode)103, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), "Workbench,Chest,Portal,Campfire"), new GrabPackConfig(((BaseUnityPlugin)this).Config, "Grab Pack 5", "Ashlands Explore", new KeyboardShortcut((KeyCode)121, Array.Empty<KeyCode>()), "Workbench,Portal,Campfire:10"), new GrabPackConfig(((BaseUnityPlugin)this).Config, "Grab Pack 6", "Ashlands Flametal", new KeyboardShortcut((KeyCode)121, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 }), "Workbench,Stone Cutter,Stone Portal,Shield Generator,Bones:10"), new GrabPackConfig(((BaseUnityPlugin)this).Config, "Grab Pack 7", "Grab Pack 7", new KeyboardShortcut((KeyCode)121, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), ""), new GrabPackConfig(((BaseUnityPlugin)this).Config, "Grab Pack 8", "Grab Pack 8", new KeyboardShortcut((KeyCode)121, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), ""), new GrabPackConfig(((BaseUnityPlugin)this).Config, "Grab Pack 9", "Grab Pack 9", new KeyboardShortcut((KeyCode)117, Array.Empty<KeyCode>()), ""), new GrabPackConfig(((BaseUnityPlugin)this).Config, "Grab Pack 10", "Grab Pack 10", new KeyboardShortcut((KeyCode)117, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 }), "") }; GrabPacks[8].Name.SettingChanged += delegate(object sender, EventArgs e) { Debug.Log((object)("Grabpack renamed " + sender.ToString() + " " + e.ToString())); }; new ConfigFileWatcher(((BaseUnityPlugin)this).Config, 1000L); } private static void InitCommands() { //IL_0032: 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) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown //IL_00a2: 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_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Expected O, but got Unknown //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Expected O, but got Unknown //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: 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_0109: Expected O, but got Unknown //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Expected O, but got Unknown //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Expected O, but got Unknown //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Expected O, but got Unknown //IL_01f2: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Expected O, but got Unknown //IL_022a: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Expected O, but got Unknown //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_0253: Unknown result type (might be due to invalid IL or missing references) //IL_0259: Expected O, but got Unknown //IL_029a: Unknown result type (might be due to invalid IL or missing references) //IL_0286: 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_0291: Expected O, but got Unknown //IL_02d2: Unknown result type (might be due to invalid IL or missing references) //IL_02be: Unknown result type (might be due to invalid IL or missing references) //IL_02c3: Unknown result type (might be due to invalid IL or missing references) //IL_02c9: Expected O, but got Unknown //IL_030a: Unknown result type (might be due to invalid IL or missing references) //IL_02f6: Unknown result type (might be due to invalid IL or missing references) //IL_02fb: Unknown result type (might be due to invalid IL or missing references) //IL_0301: Expected O, but got Unknown //IL_0342: Unknown result type (might be due to invalid IL or missing references) //IL_032e: Unknown result type (might be due to invalid IL or missing references) //IL_0333: Unknown result type (might be due to invalid IL or missing references) //IL_0339: Expected O, but got Unknown //IL_037a: Unknown result type (might be due to invalid IL or missing references) //IL_0366: Unknown result type (might be due to invalid IL or missing references) //IL_036b: Unknown result type (might be due to invalid IL or missing references) //IL_0371: Expected O, but got Unknown object obj = <>c.<>9__22_0; if (obj == null) { ConsoleEvent val = delegate(ConsoleEventArgs args) { args.GrabItemsFromNearbyContainers(); }; <>c.<>9__22_0 = val; obj = (object)val; } new ConsoleCommand("grab", "[items] - grab items from nearby containers", (ConsoleEvent)obj, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj2 = <>c.<>9__22_1; if (obj2 == null) { ConsoleEvent val2 = delegate(ConsoleEventArgs args) { args.GrabItemsFromNearbyContainers(); }; <>c.<>9__22_1 = val2; obj2 = (object)val2; } new ConsoleCommand("g", "[items] - grab items from nearby containers", (ConsoleEvent)obj2, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj3 = <>c.<>9__22_2; if (obj3 == null) { ConsoleEvent val3 = delegate { ConsoleCommands.GrabMaterialsForSelectedPiece(); }; <>c.<>9__22_2 = val3; obj3 = (object)val3; } new ConsoleCommand("grabselected", "", (ConsoleEvent)obj3, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj4 = <>c.<>9__22_3; if (obj4 == null) { ConsoleEvent val4 = delegate(ConsoleEventArgs args) { args.GrabMaterialsForPiece(); }; <>c.<>9__22_3 = val4; obj4 = (object)val4; } new ConsoleCommand("grabpiece", "grab materials for named build piece, e.g. workbench or portal", (ConsoleEvent)obj4, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj5 = <>c.<>9__22_4; if (obj5 == null) { ConsoleEvent val5 = delegate { ListKnownContainers(); }; <>c.<>9__22_4 = val5; obj5 = (object)val5; } new ConsoleCommand("listcontainers", "list all known containers", (ConsoleEvent)obj5, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj6 = <>c.<>9__22_5; if (obj6 == null) { ConsoleEvent val6 = delegate(ConsoleEventArgs args) { ListLocalContainers(args); }; <>c.<>9__22_5 = val6; obj6 = (object)val6; } new ConsoleCommand("listlocalcontainers", "[radius] - Finds containers within the radius.", (ConsoleEvent)obj6, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj7 = <>c.<>9__22_6; if (obj7 == null) { ConsoleEvent val7 = delegate(ConsoleEventArgs args) { ListLocalContainerContents(args); }; <>c.<>9__22_6 = val7; obj7 = (object)val7; } new ConsoleCommand("listcontents", "[radius] - Finds containers within the radius and lists their contents.", (ConsoleEvent)obj7, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj8 = <>c.<>9__22_7; if (obj8 == null) { ConsoleEvent val8 = delegate { ListGrabPacks(); }; <>c.<>9__22_7 = val8; obj8 = (object)val8; } new ConsoleCommand("listpacks", "Lists your configured grab packs.", (ConsoleEvent)obj8, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj9 = <>c.<>9__22_8; if (obj9 == null) { ConsoleEvent val9 = delegate(ConsoleEventArgs args) { ListLocalInventory(args); }; <>c.<>9__22_8 = val9; obj9 = (object)val9; } new ConsoleCommand("inventory", "Displays counts of materials in containers in range.", (ConsoleEvent)obj9, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj10 = <>c.<>9__22_9; if (obj10 == null) { ConsoleEvent val10 = delegate(ConsoleEventArgs args) { ListLocalInventory(args); }; <>c.<>9__22_9 = val10; obj10 = (object)val10; } new ConsoleCommand("i", "Displays counts of materials in containers in range.", (ConsoleEvent)obj10, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj11 = <>c.<>9__22_10; if (obj11 == null) { ConsoleEvent val11 = delegate(ConsoleEventArgs args) { SetInventoryStyle(args); }; <>c.<>9__22_10 = val11; obj11 = (object)val11; } new ConsoleCommand("istyle", "[1-2] - cycle inventory display style (1=List, 2=Table)", (ConsoleEvent)obj11, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj12 = <>c.<>9__22_11; if (obj12 == null) { ConsoleEvent val12 = delegate(ConsoleEventArgs args) { FindContainersWithMatchingItems(args); }; <>c.<>9__22_11 = val12; obj12 = (object)val12; } new ConsoleCommand("search", "[search-text] - search for items matching this string in nearby containers", (ConsoleEvent)obj12, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj13 = <>c.<>9__22_12; if (obj13 == null) { ConsoleEvent val13 = delegate(ConsoleEventArgs args) { FindContainersWithMatchingItems(args); }; <>c.<>9__22_12 = val13; obj13 = (object)val13; } new ConsoleCommand("s", "[search-text] - search for items matching this string in nearby containers", (ConsoleEvent)obj13, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj14 = <>c.<>9__22_13; if (obj14 == null) { ConsoleEvent val14 = delegate { StoreItemsInNearbyContainers(); }; <>c.<>9__22_13 = val14; obj14 = (object)val14; } new ConsoleCommand("store", "[items] - stores items randomly nearby containers", (ConsoleEvent)obj14, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj15 = <>c.<>9__22_14; if (obj15 == null) { ConsoleEvent val15 = delegate(ConsoleEventArgs args) { CountInventory(args); }; <>c.<>9__22_14 = val15; obj15 = (object)val15; } new ConsoleCommand("count", "[name of item to count] - omit to count everything", (ConsoleEvent)obj15, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj16 = <>c.<>9__22_15; if (obj16 == null) { ConsoleEvent val16 = delegate { ListAllPieces(); }; <>c.<>9__22_15 = val16; obj16 = (object)val16; } new ConsoleCommand("listpieces", "", (ConsoleEvent)obj16, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); } private void InitButtons() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown GrabSelectedPieceMatsButton = new ButtonConfig { Name = "GrabSelectedPieceMaterials", Config = GrabSelectedPieceMatsKeyboardConfig }; InputManager.Instance.AddButton("DeathMonger.GrabMaterialsMod", GrabSelectedPieceMatsButton); GrabPackConfig[] grabPacks = GrabPacks; foreach (GrabPackConfig grabPackConfig in grabPacks) { InputManager.Instance.AddButton("DeathMonger.GrabMaterialsMod", grabPackConfig.Button); } } private void InitButton(string name, KeyCode key) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000c: 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_0026: Expected O, but got Unknown ButtonConfig val = new ButtonConfig { Name = name, Config = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("", name, key, (ConfigDescription)null) }; InputManager.Instance.AddButton("DeathMonger.GrabMaterialsMod", val); } private void Update() { MaterialsPanel.Tick(); DistanceHud.Tick(); if (!Object.op_Implicit((Object)(object)Player.m_localPlayer) || !Object.op_Implicit((Object)(object)Chat.instance) || Chat.instance.IsChatDialogWindowVisible()) { return; } if (ZInput.GetButtonDown(GrabSelectedPieceMatsButton.Name)) { ConsoleCommands.GrabMaterialsForSelectedPiece(); } GrabPackConfig[] grabPacks = GrabPacks; foreach (GrabPackConfig grabPackConfig in grabPacks) { if (ZInput.GetButtonDown(grabPackConfig.Button.Name)) { ConsoleCommands.GrabMaterialsForPack(grabPackConfig); } } } private void OnDestroy() { harmony.UnpatchSelf(); } private static void ListAllPieces() { //IL_0194: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)ZNetScene.instance)) { Debug.LogWarning((object)"Cannot index: ZNetScene.instance is null"); return; } Debug.LogWarning((object)"listing build pieces (prefabs with an associated component)"); Piece val = default(Piece); foreach (GameObject prefab in ZNetScene.instance.m_prefabs) { if (!prefab.TryGetComponent<Piece>(ref val)) { continue; } string text = ""; try { text = ((!val.m_name.StartsWith("$")) ? (val.m_name ?? "") : LocalizationManager.Instance.TryTranslate(val.m_name)); } catch (Exception ex) { Debug.LogError((object)("Error translating piece name " + val.m_name + ": " + ex.Message)); text = "translation failed"; } if (((Object)prefab).name == ((Object)val).name) { bool flag = false; foreach (Recipe recipe in ObjectDB.instance.m_recipes) { if ((Object)(object)recipe.m_item == (Object)(object)val && recipe.m_enabled) { flag = true; break; } } Debug.Log((object)$"{((Object)prefab).name} \"{text}\" {val.GetResourceList()} {flag} {prefab.activeInHierarchy} {((Behaviour)val).enabled} {val.m_enabled} {((Behaviour)val).isActiveAndEnabled} {val.IsPlacedByPlayer()} {val.m_category} {val.m_craftingStation}"); } else { Debug.LogError((object)("DIFFERENT NAMES Piece: " + ((Object)prefab).name + " " + ((Object)val).name + " " + text)); } } } private static void ListKnownContainers() { int num = 0; Debug.Log((object)$"listing {Boxes.Containers.Count} known containers"); foreach (Container container in Boxes.Containers) { Debug.Log((object)$"{++num}. {((Object)container).name} {container.m_name} ({((object)container).GetType()} {((Object)container).GetInstanceID()})"); } } private static void ListLocalContainers(ConsoleEventArgs args) { int num = 0; float result = 10f; if (args.Length > 1) { float.TryParse(args[1], NumberStyles.Float, CultureInfo.InvariantCulture, out result); } List<Container> nearbyContainers = Boxes.GetNearbyContainers(result); Debug.Log((object)$"listing {nearbyContainers.Count} containers within {result} meters out of {Boxes.Containers.Count} known containers"); foreach (Container item in nearbyContainers) { Debug.Log((object)$"{++num}. {((Object)item).name} {item.m_name} ({((object)item).GetType()} {((Object)item).GetInstanceID()})"); } } private static void ListLocalContainerContents(ConsoleEventArgs args) { //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_01f7: Unknown result type (might be due to invalid IL or missing references) float result = 50f; if (args.Length > 1) { float.TryParse(args[1], NumberStyles.Float, CultureInfo.InvariantCulture, out result); } List<Container> nearbyContainers = Boxes.GetNearbyContainers(result); Debug.Log((object)$"listing {nearbyContainers.Count} containers within {result} meters out of {Boxes.Containers.Count} known containers"); Debug.Log((object)$"showing the contents of {nearbyContainers.Count} nearby containers"); foreach (Container item in nearbyContainers) { Debug.Log((object)$"contents of {((Object)item).name} {((Object)item).GetInstanceID()}:"); foreach (ItemData allItem in item.GetInventory().GetAllItems()) { string text = ""; text = LocalizationManager.Instance.TryTranslate(allItem.m_shared.m_name); Debug.Log((object)$"{allItem.Count()},{text},{allItem.Name()},{allItem.GetCategory()},{allItem.m_shared.m_itemType},{allItem.IsWeapon()},{allItem.IsEquipable()},{allItem.m_shared.m_isDrink},{allItem.GetArmor()},{allItem.m_shared.m_armorMaterial},{allItem.m_shared.m_food},{allItem.m_shared.m_foodStamina},{allItem.m_shared.m_foodEitr},{allItem.m_shared.m_ammoType},{allItem.m_shared.m_questItem},{allItem.m_shared.m_skillType}"); } } } private static void SetInventoryStyle(ConsoleEventArgs args) { MaterialsPanel.InventoryStyle[] array = (MaterialsPanel.InventoryStyle[])Enum.GetValues(typeof(MaterialsPanel.InventoryStyle)); MaterialsPanel.InventoryStyle inventoryStyle; if (args.Length > 1 && int.TryParse(args[1], out var result) && result >= 1 && result <= array.Length) { inventoryStyle = array[result - 1]; } else { MaterialsPanel.InventoryStyle value = Instance.InventoryStyle.Value; int num = Array.IndexOf(array, value); inventoryStyle = array[(num + 1) % array.Length]; } Instance.InventoryStyle.Value = inventoryStyle; Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)2, $"Inventory style: {inventoryStyle}", 0, (Sprite)null); } } private static string FormatCategoryName(Extensions.ItemCategory cat) { string text = cat.ToString(); StringBuilder stringBuilder = new StringBuilder(text.Length + 4); for (int i = 0; i < text.Length; i++) { if (i > 0 && char.IsUpper(text[i])) { stringBuilder.Append(' '); } stringBuilder.Append(text[i]); } return stringBuilder.ToString(); } private static void ListLocalInventory(ConsoleEventArgs args) { float num = 50f; string text = ((args.Length > 1) ? args.ArgsAll.ToLower() : null); List<Container> nearbyContainers = Boxes.GetNearbyContainers(num); Debug.Log((object)$"searching {nearbyContainers.Count} containers within {num} meters out of {Boxes.Containers.Count} known containers"); Dictionary<Extensions.ItemCategory, SortedDictionary<string, int>> dictionary = new Dictionary<Extensions.ItemCategory, SortedDictionary<string, int>>(); Dictionary<string, Sprite> dictionary2 = new Dictionary<string, Sprite>(); foreach (Container item in nearbyContainers) { Inventory inventory = item.GetInventory(); if (inventory == null) { continue; } bool flag = false; foreach (ItemData allItem in inventory.GetAllItems()) { string name = allItem.m_shared.m_name; string text2 = LocalizationManager.Instance.TryTranslate(name).ToLower(); Extensions.ItemCategory category = allItem.GetCategory(); string text3 = category.ToString().ToLower(); Extensions.ItemCategory result = Extensions.ItemCategory.None; bool num2; if (text == null || !Enum.TryParse<Extensions.ItemCategory>(text, ignoreCase: true, out result)) { if (text == null || allItem.Name().Contains(text) || name.Contains(text) || text2.Contains(text)) { goto IL_0136; } num2 = text3.Contains(text); } else { num2 = category == result; } if (!num2) { continue; } goto IL_0136; IL_0136: if (!dictionary.TryGetValue(category, out var value)) { value = (dictionary[category] = new SortedDictionary<string, int>()); } if (value.ContainsKey(name)) { value[name] += allItem.Count(); } else { value[name] = allItem.Count(); } if (!dictionary2.ContainsKey(name) && allItem.m_shared.m_icons != null && allItem.m_shared.m_icons.Length != 0) { dictionary2[name] = allItem.m_shared.m_icons[0]; } if (!flag) { item.Highlight(); flag = true; } } } if (dictionary.Count == 0) { string text4 = (string.IsNullOrEmpty(text) ? "No items in nearby containers" : ("No items match '" + text + "'")); ((Character)Player.m_localPlayer).Message((MessageType)2, text4, 0, (Sprite)null); return; } List<MaterialsPanel.InventoryGroup> list = new List<MaterialsPanel.InventoryGroup>(); foreach (Extensions.ItemCategory value4 in Enum.GetValues(typeof(Extensions.ItemCategory))) { if (value4 == Extensions.ItemCategory.None || !dictionary.TryGetValue(value4, out var value2)) { continue; } List<MaterialsPanel.InventoryItem> list2 = new List<MaterialsPanel.InventoryItem>(value2.Count); foreach (KeyValuePair<string, int> item2 in value2) { string text5 = LocalizationManager.Instance.TryTranslate(item2.Key); Debug.Log((object)$"{item2.Value} {text5} [{value4}]"); dictionary2.TryGetValue(item2.Key, out var value3); list2.Add(new MaterialsPanel.InventoryItem { Name = text5, Count = item2.Value, Icon = value3, SharedName = item2.Key }); } list.Add(new MaterialsPanel.InventoryGroup { CategoryName = FormatCategoryName(value4), Items = list2 }); } MaterialsPanel.ShowCategorizedInventory(string.IsNullOrEmpty(text) ? "Inventory" : ("Inventory: " + text), list, Instance.InventoryStyle.Value); } private static void ListGrabPacks() { //IL_0049: Unknown result type (might be due to invalid IL or missing references) Debug.Log((object)$"listing {Instance.GrabPacks.Length} configured grab packs"); GrabPackConfig[] grabPacks = Instance.GrabPacks; foreach (GrabPackConfig grabPackConfig in grabPacks) { Debug.Log((object)$"{grabPackConfig.Name.Value} ({grabPackConfig.Key.Value}): {grabPackConfig.Items.Value}"); } } private static void FindContainersWithMatchingItems(ConsoleEventArgs args) { if (args.Length <= 1) { string text = "Please specify the text you want to search for in nearby containers"; ((Component)Chat.instance).SendMessage(text); Debug.Log((object)text); return; } float num = 50f; string text2 = args[1]; List<Container> nearbyContainers = Boxes.GetNearbyContainers(num); Debug.Log((object)$"searching for {text2} in {nearbyContainers.Count} containers within {num} meters"); foreach (Container item in nearbyContainers) { Inventory inventory = item.GetInventory(); foreach (ItemData allItem in inventory.GetAllItems()) { if (allItem.Name().Contains(text2)) { Debug.Log((object)("it contains " + text2 + "!")); item.Highlight(); } } if (inventory.ContainsItemByName(text2)) { Debug.Log((object)("it contains " + text2 + "!")); item.Highlight(); } } } private static void StoreItemsInNearbyContainers() { float num = 50f; List<Container> nearbyContainers = Boxes.GetNearbyContainers(num); Player localPlayer = Player.m_localPlayer; Inventory inventory = ((Humanoid)localPlayer).GetInventory(); List<ItemData> list = new List<ItemData>(); ((Character)localPlayer).Message((MessageType)2, $"Storing items in {nearbyContainers.Count} containers within {num} meters", 0, (Sprite)null); for (int i = 1; i < inventory.GetHeight(); i++) { for (int j = 0; j < inventory.GetWidth(); j++) { ItemData itemAt = inventory.GetItemAt(j, i); if (itemAt != null) { list.Add(itemAt); } } } Debug.Log((object)$"storing {list.Count()} items in {nearbyContainers.Count} containers within {num} meters"); int num2 = 0; while (list.Count > 0) { nearbyContainers[num2].StoreItemInContainer(list[0]); num2++; if (num2 == nearbyContainers.Count) { num2 = 0; } list.RemoveAt(0); } } private static void CountInventory(ConsoleEventArgs args) { string text = ""; int num = 0; Inventory inventory = ((Humanoid)Player.m_localPlayer).GetInventory(); if (args.Length > 1) { text = args[1]; num = inventory.CountItems(text, -1, true); Debug.Log((object)$"{num} {text} in inventory"); } else { num = inventory.CountItems(); Debug.Log((object)$"{num} items in inventory"); } } } } namespace GrabMaterials { internal class Boxes { internal static readonly List<Container> Containers = new List<Container>(); private static readonly List<Container> ContainersToAdd = new List<Container>(); private static readonly List<Container> ContainersToRemove = new List<Container>(); internal static void AddContainer(Container container) { if (!Containers.Contains(container)) { ContainersToAdd.Add(container); Logger.LogDebug((object)$"Added container {((Object)container).name} ({((object)container).GetType()} {((Object)container).GetInstanceID()}) to list"); } UpdateContainers(); } internal static void RemoveContainer(Container container) { if (Containers.Contains(container)) { ContainersToRemove.Add(container); Logger.LogDebug((object)$"Removed container {((Object)container).name} ({((object)container).GetType()} {((Object)container).GetInstanceID()}) from list"); } UpdateContainers(); } internal static void UpdateContainers() { foreach (Container item in ContainersToAdd) { Containers.Add(item); } ContainersToAdd.Clear(); foreach (Container item2 in ContainersToRemove) { Containers.Remove(item2); } ContainersToRemove.Clear(); } internal static void ConditionallyAddContainer(Container container, string trigger) { if (container.GetInventory() != null) { Game.instance.GetPlayerProfile().GetPlayerID(); AddContainer(container); } } internal static List<Container> GetNearbyContainers(float radius) { //IL_001e: 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_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) List<Container> list = new List<Container>(); if (!Object.op_Implicit((Object)(object)Player.m_localPlayer)) { return list; } Vector3 position = ((Component)Player.m_localPlayer).transform.position; Debug.Log((object)$"checking distance of {Containers.Count} containers"); foreach (Container container in Containers) { if ((Object)(object)container == (Object)null) { Debug.LogWarning((object)"Found null container in list"); ContainersToRemove.Add(container); } else if ((Object)(object)((Component)container).transform == (Object)null) { Debug.LogWarning((object)("Found container " + ((Object)container).name + " with null transform in list")); ContainersToRemove.Add(container); } else if (Vector3.Distance(position, ((Component)container).transform.position) < radius) { list.Add(container); } } UpdateContainers(); return list; } } [HarmonyPatch(typeof(Chat), "SendText")] public class HookChatInputText { private const float SearchRadius = 50f; private static void SearchNearbyContainersFor(string query) { foreach (Piece nearbyMatchingPiece in GetNearbyMatchingPieces(query)) { HighlightPiece(nearbyMatchingPiece); } } private static IEnumerable<Piece> GetNearbyMatchingPieces(string query) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) List<Piece> list = new List<Piece>(); Piece.GetAllPiecesInRadius(((Component)Player.m_localPlayer).transform.position, 50f, list); return from p in list where Object.op_Implicit((Object)(object)((Component)p).GetComponent<Container>()) where ContainerContainsMatchingItem(p, query) select p; } private static bool ContainerContainsMatchingItem(Piece container, string query) { return (from i in ((Component)container).GetComponent<Container>().GetInventory().GetAllItems() where NormalizedItemName(i).Contains(query) select i).Any(); } private static string NormalizedItemName(ItemData itemData) { return itemData.m_shared.m_name.ToLower(); } private static void HighlightPiece(Piece p) { WearNTear component = ((Component)p).GetComponent<WearNTear>(); if (Object.op_Implicit((Object)(object)component)) { component.Highlight(); } } } internal static class ConsoleCommands { private struct ItemToGrab { public string Name; public int Count; public string FullName => "$item_" + Name; public ItemToGrab(string name, int count) { Name = name.Replace("$item_", ""); Count = count; } } private static Dictionary<string, Piece> pieceLookup = new Dictionary<string, Piece>(); private static Dictionary<string, GameObject> itemLookup = new Dictionary<string, GameObject>(); private static FieldRef<Hud, List<PieceIconData>> _pieceIconsAccessor; public static void GrabMaterialsForPiece(this ConsoleEventArgs args) { Debug.Log((object)("GrabMaterialsForPiece(" + args.FullLine + ")")); if (args.Length <= 1) { string text = "usage: /grabpiece <name>, e.g. /grab workbench"; ((Component)Chat.instance).SendMessage(text); Debug.Log((object)text); } else { string text2 = args[1]; Debug.Log((object)("name of piece to grab materials for: " + text2)); GrabMaterialsForPiece(text2); } } public static void GrabMaterialsForPack(global::GrabMaterialsMod.GrabMaterialsMod.GrabPackConfig grabPack) { GrabMaterialsForPack(grabPack.Name.Value, grabPack.Items.Value, grabPack.GrabDelta.Value); } public static void GrabMaterialsForPack(string packName, string itemsString, bool grabDelta = false) { Debug.Log((object)("GrabMaterialsForPack(" + packName + ", " + itemsString + ")")); List<ItemToGrab> list = new List<ItemToGrab>(); string[] array = itemsString.Replace(" ", "").Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < array.Length; i++) { string[] array2 = array[i].Split(new char[1] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (array2.Length > 2) { Debug.LogError((object)("Invalid format for " + packName + " item list: was " + itemsString + ", expected 'item[:quantity],item[:quantity],...'")); return; } string text = array2[0]; int result = 1; if (array2.Length == 2 && !int.TryParse(array2[1], out result)) { Debug.LogError((object)("Invalid format for " + packName + " item list: was " + itemsString + ", expected 'item[:quantity],item[:quantity],...'")); return; } Debug.Log((object)$"grabbing {result} {text}"); foreach (ItemToGrab item in GetItemsToGrab(text, result)) { list.Add(item); } } GrabItemsFromNearbyContainers(list, 50f, packName, grabDelta); } public static void GrabItemsFromNearbyContainers(this ConsoleEventArgs args) { Debug.Log((object)$"GrabItemsFromNearbyContainers('{args.FullLine})' args.Length={args.Length}"); if (args.Length > 1) { if (args[1] == "pack") { int num = int.Parse(args[2]) - 1; GrabMaterialsForPack(global::GrabMaterialsMod.GrabMaterialsMod.Instance.GrabPacks[num]); return; } global::GrabMaterialsMod.GrabMaterialsMod.GrabPackConfig[] grabPacks = global::GrabMaterialsMod.GrabMaterialsMod.Instance.GrabPacks; foreach (global::GrabMaterialsMod.GrabMaterialsMod.GrabPackConfig grabPackConfig in grabPacks) { string argsAll = args.ArgsAll; Debug.Log((object)("Checking pack " + grabPackConfig.Name.Value + " against args.ArgsAll='" + argsAll + "'")); if (grabPackConfig.Name.Value == args.ArgsAll) { GrabMaterialsForPack(grabPackConfig); return; } } int num2 = args.Length - 1; int result = 0; int num3 = ((!int.TryParse(args[1], out result)) ? 1 : 2); int num4 = num2; if (result == 0) { num4 = (int.TryParse(args[num2], out result) ? (num2 - 1) : num2); if (result == 0) { result = 1; } } Debug.Log((object)$"count={result}, n={num2}, nameStartingArg={num3}, nameEndingArg={num4}"); StringBuilder stringBuilder = new StringBuilder(); for (int j = num3; j <= num4; j++) { if (stringBuilder.Length > 0) { stringBuilder.Append(" "); } stringBuilder.Append(args[j]); } string text = stringBuilder.ToString(); if (text != "") { Debug.Log((object)$"grabbing {result} '{text}'"); GrabItemsFromNearbyContainers(text, result); return; } } string text2 = "usage: /grab <all | name> [count], e.g. /grab 10 wood"; ((Component)Chat.instance).SendMessage(text2); Debug.Log((object)text2); } public static Requirement[] GetPieceRequirements(string pieceName) { Debug.Log((object)("GetPieceRequirements(" + pieceName + ")")); if (!Object.op_Implicit((Object)(object)ZNetScene.instance)) { Debug.LogWarning((object)"Cannot look for prefab: ZNetScene.instance is null"); return null; } Debug.Log((object)"looking for prefab..."); Debug.Log((object)$"ZNetScene.instance has {ZNetScene.instance.m_prefabs.Count} prefabs"); GameObject val = ZNetScene.instance.m_prefabs.Find((GameObject _prefab) => ((Object)_prefab).name == pieceName); if ((Object)(object)val == (Object)null) { Debug.LogError((object)("No prefab found for " + pieceName)); return null; } Debug.Log((object)("Prefab found: " + ((Object)val).name + " " + ((Object)val.gameObject).name + " " + val.gameObject.tag + " " + val.gameObject.GetComponent<Piece>().m_name)); return val.gameObject.GetComponent<Piece>().m_resources; } private static void GrabMaterialsForPiece(string pieceName) { Requirement[] pieceRequirements = GetPieceRequirements(pieceName); if (pieceRequirements != null) { List<ItemToGrab> list = new List<ItemToGrab>(); Requirement[] array = pieceRequirements; foreach (Requirement val in array) { Debug.Log((object)$"Grabbing for {pieceName}: {val.m_amount} {val.m_resItem.m_itemData.m_shared.m_name}"); list.Add(new ItemToGrab(val.m_resItem.m_itemData.m_shared.m_name, val.m_amount)); } GrabItemsFromNearbyContainers(list, 50f, pieceName); } } private static void GrabItemsFromNearbyContainers(List<ItemToGrab> itemsToGrab, float radius, string requestLabel = null, bool grabDelta = false) { List<Container> nearbyContainers = Boxes.GetNearbyContainers(radius); Player localPlayer = Player.m_localPlayer; List<ItemToGrab> list = new List<ItemToGrab>(); foreach (ItemToGrab item in itemsToGrab) { int num = list.FindIndex((ItemToGrab a) => string.Equals(a.Name, item.Name, StringComparison.OrdinalIgnoreCase)); if (num >= 0) { ItemToGrab value = list[num]; value.Count += item.Count; list[num] = value; } else { list.Add(item); } } int[] array = new int[list.Count]; int[] array2 = new int[list.Count]; for (int i = 0; i < list.Count; i++) { if (grabDelta && (Object)(object)localPlayer != (Object)null) { Inventory inventory = ((Humanoid)localPlayer).GetInventory(); if (inventory != null) { foreach (ItemData allItem in inventory.GetAllItems()) { if (allItem.isMatch(list[i].Name)) { array[i] += allItem.Count(); } } } } array2[i] = Math.Max(0, list[i].Count - array[i]); } bool flag = true; for (int j = 0; j < list.Count; j++) { if (array2[j] > 0) { flag = false; break; } } int[] array3 = new int[list.Count]; foreach (Container item3 in nearbyContainers) { Inventory inventory2 = item3.GetInventory(); if (inventory2 == null) { continue; } foreach (ItemData allItem2 in inventory2.GetAllItems()) { for (int k = 0; k < list.Count; k++) { if (array2[k] != 0 && allItem2.isMatch(list[k].Name)) { array3[k] += allItem2.Count(); break; } } } } bool flag2 = false; for (int l = 0; l < list.Count; l++) { if (array2[l] > 0 && array3[l] < array2[l]) { flag2 = true; break; } } if (flag2) { List<MaterialsPanel.ItemStatus> list2 = new List<MaterialsPanel.ItemStatus>(list.Count); List<string> list3 = new List<string>(); for (int m = 0; m < list.Count; m++) { list2.Add(new MaterialsPanel.ItemStatus { Name = LocalizeItemName(list[m]), Needed = list[m].Count, Had = array[m], Available = array3[m] }); if (array2[m] > array3[m]) { list3.Add($"{array2[m] - array3[m]} of {list[m].Count} {list[m].Name}"); } } Debug.Log((object)("Cannot grab" + (string.IsNullOrEmpty(requestLabel) ? "" : (" for " + requestLabel)) + " - missing: " + string.Join(", ", list3))); MaterialsPanel.Show(string.IsNullOrEmpty(requestLabel) ? "Missing materials" : ("Missing materials for " + requestLabel), list2); return; } List<MaterialsPanel.ItemStatus> list4 = new List<MaterialsPanel.ItemStatus>(list.Count); for (int n = 0; n < list.Count; n++) { ItemToGrab item2 = list[n]; int num2 = array2[n]; if (num2 > 0) { Debug.Log((object)$"grabbing {num2} {item2.Name} from {nearbyContainers.Count} containers within {radius} meters"); for (int num3 = 0; num3 < nearbyContainers.Count; num3++) { if (num2 <= 0) { break; } int num4 = nearbyContainers[num3].GrabItemFromContainer(item2.Name, num2); num2 -= num4; } } list4.Add(new MaterialsPanel.ItemStatus { Name = LocalizeItemName(item2), Needed = item2.Count, Had = array[n], Available = array2[n] - num2 }); } string text; if (flag) { text = (string.IsNullOrEmpty(requestLabel) ? "Already have everything" : ("Already have everything for " + requestLabel)); Debug.Log((object)text); } else { text = (string.IsNullOrEmpty(requestLabel) ? "Grabbed materials" : ("Grabbed materials for " + requestLabel)); } MaterialsPanel.Show(text, list4); } private static string LocalizeItemName(ItemToGrab item) { string text = LocalizationManager.Instance.TryTranslate(item.FullName); if (!string.IsNullOrEmpty(text) && !(text == item.FullName)) { return text; } return item.Name; } private static string LocalizePieceName(Piece piece) { if ((Object)(object)piece == (Object)null) { return null; } if (!piece.m_name.StartsWith("$")) { return piece.m_name; } try { string text = LocalizationManager.Instance.TryTranslate(piece.m_name); return (string.IsNullOrEmpty(text) || text == piece.m_name) ? piece.m_name : text; } catch { return piece.m_name; } } public static void GrabMaterialsForSelectedPiece() { Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null)) { Piece val = GetHoveredBuildPiece() ?? localPlayer.GetSelectedPiece(); if (!Object.op_Implicit((Object)(object)val)) { string text = "No build piece selected or hovered"; Debug.Log((object)text); ((Character)localPlayer).Message((MessageType)2, text, 0, (Sprite)null); } else { GrabMaterialsForPiece(val); } } } public static void HighlightContainersHolding(string sharedName) { if (string.IsNullOrEmpty(sharedName)) { return; } foreach (Container nearbyContainer in Boxes.GetNearbyContainers(50f)) { Inventory inventory = nearbyContainer.GetInventory(); if (inventory == null) { continue; } foreach (ItemData allItem in inventory.GetAllItems()) { if (allItem.m_shared.m_name == sharedName) { nearbyContainer.Highlight(); break; } } } } public static void HighlightContainersHoldingAny(ICollection<string> sharedNames) { if (sharedNames == null || sharedNames.Count == 0) { return; } HashSet<string> hashSet = (sharedNames as HashSet<string>) ?? new HashSet<string>(sharedNames); foreach (Container nearbyContainer in Boxes.GetNearbyContainers(50f)) { Inventory inventory = nearbyContainer.GetInventory(); if (inventory == null) { continue; } foreach (ItemData allItem in inventory.GetAllItems()) { if (hashSet.Contains(allItem.m_shared.m_name)) { nearbyContainer.Highlight(); break; } } } } public static Piece GetHoveredBuildPiece() { //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) Hud instance = Hud.instance; Player localPlayer = Player.m_localPlayer; if ((Object)(object)instance == (Object)null || (Object)(object)localPlayer == (Object)null) { return null; } if (_pieceIconsAccessor == null) { try { _pieceIconsAccessor = AccessTools.FieldRefAccess<Hud, List<PieceIconData>>("m_pieceIcons"); } catch (Exception ex) { Debug.LogWarning((object)("GrabMaterials: cannot reflect Hud.m_pieceIcons - " + ex.Message)); return null; } } List<PieceIconData> list = _pieceIconsAccessor.Invoke(instance); if (list == null) { return null; } foreach (PieceIconData item in list) { if (item == null) { continue; } Image icon = item.m_icon; if ((Object)(object)icon == (Object)null || !((Component)icon).gameObject.activeInHierarchy || !RectTransformUtility.RectangleContainsScreenPoint(((Graphic)icon).rectTransform, Vector2.op_Implicit(Input.mousePosition))) { continue; } Sprite sprite = icon.sprite; if ((Object)(object)sprite == (Object)null) { return null; } List<Piece> buildPieces = localPlayer.GetBuildPieces(); if (buildPieces == null) { return null; } foreach (Piece item2 in buildPieces) { if ((Object)(object)item2 != (Object)null && (Object)(object)item2.m_icon == (Object)(object)sprite) { return item2; } } return null; } return null; } public static void GrabMaterialsForPiece(Piece piece) { Requirement[] resources = piece.m_resources; Debug.Log((object)$"grabbing materials for selected piece {((Object)piece).name} - requires {resources.Count()} resources"); if (resources != null) { List<ItemToGrab> list = new List<ItemToGrab>(); Requirement[] array = resources; foreach (Requirement val in array) { Debug.Log((object)$"{val.m_amount} {val.m_resItem.m_itemData.Name()}"); list.Add(new ItemToGrab(val.m_resItem.m_itemData.Name(), val.m_amount)); } GrabItemsFromNearbyContainers(list, 10f, LocalizePieceName(piece)); } } private static void BuildPieceLookUp() { if ((Object)(object)ObjectDB.instance == (Object)null) { return; } if (!Object.op_Implicit((Object)(object)ZNetScene.instance)) { Debug.LogWarning((object)"Cannot index: ZNetScene.instance is null"); return; } Debug.Log((object)"building lookup table for all build pieces"); Piece val = default(Piece); foreach (GameObject prefab in ZNetScene.instance.m_prefabs) { if (prefab.TryGetComponent<Piece>(ref val) && !StringExtensions.ContainsAny(((Object)prefab).name, new string[2] { "loot_chest", "TreasureChest" })) { string text = ""; try { text = ((!val.m_name.StartsWith("$")) ? val.m_name : LocalizationManager.Instance.TryTranslate(val.m_name)); } catch (Exception ex) { Debug.LogError((object)("Error translating piece name " + val.m_name + ": " + ex.Message)); text = val.m_name; } pieceLookup[text.ToLowerInvariant()] = val; } } } private static void BuildItemLookUp() { if ((Object)(object)ObjectDB.instance == (Object)null) { return; } Logger.LogInfo((object)"Building item lookup..."); foreach (GameObject item in ObjectDB.instance.m_items) { if (!((Object)(object)item == (Object)null)) { string name = ((Object)item).name; itemLookup[name] = item; } } Logger.LogInfo((object)$"Built a lookup table with {itemLookup.Count} items."); } private static List<ItemToGrab> GetItemsToGrab(string name, int count = 1) { List<ItemToGrab> list = new List<ItemToGrab>(); if (pieceLookup.Count == 0) { BuildPieceLookUp(); } if (itemLookup.Count == 0) { BuildItemLookUp(); } if (pieceLookup.ContainsKey(name.ToLowerInvariant())) { Piece obj = pieceLookup[name.ToLowerInvariant()]; Debug.Log((object)("Found piece " + name + " in lookup table, grabbing materials for it")); Requirement[] resources = obj.m_resources; if (resources != null) { Requirement[] array = resources; foreach (Requirement val in array) { Debug.Log((object)$"{val.m_amount} {val.m_resItem.m_itemData.Name()}"); list.Add(new ItemToGrab(val.m_resItem.m_itemData.Name(), val.m_amount * count)); } } } else { Debug.Log((object)("No piece found for " + name + ", looking for material by this name instead")); list.Add(new ItemToGrab(name, count)); } return list; } public static void GrabItemsFromNearbyContainers(string name, int count = 1) { float radius = 50f; List<ItemToGrab> itemsToGrab = GetItemsToGrab(name, count); string requestLabel = (pieceLookup.ContainsKey(name.ToLowerInvariant()) ? name : null); GrabItemsFromNearbyContainers(itemsToGrab, radius, requestLabel); } } internal class ContainerFinder { public static List<Container> FindNearbyContainers(Vector3 position, float radius) { //IL_0015: 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) Debug.Log((object)$"FindNearbyContainers with {radius} meters"); Debug.Log((object)position); List<Container> list = new List<Container>(); Collider[] array = Physics.OverlapSphere(position, radius); Debug.Log((object)$"{array.Count()} colliders"); Collider[] array2 = array; foreach (Collider obj in array2) { Debug.Log((object)(((Object)obj).name ?? "")); Container component = ((Component)obj).GetComponent<Container>(); ((Component)component).GetComponent<ContainerFilterService>(); if ((Object)(object)component != (Object)null) { list.Add(component); } } return list; } } [HarmonyPatch(typeof(Container), "Load")] internal class ContainerLoadPatch { private static void Postfix(Container __instance) { Boxes.ConditionallyAddContainer(__instance, "Load"); } } [HarmonyPatch(typeof(Container), "Awake")] internal static class ContainerAwakePatch { private static void Postfix(Container __instance) { Boxes.ConditionallyAddContainer(__instance, "Awake"); } } [HarmonyPatch(typeof(Container), "OnDestroyed")] internal static class ContainerOnDestroyedPatch { private static void Postfix(Container __instance) { Boxes.RemoveContainer(__instance); } } [HarmonyPatch(typeof(Player), "UpdateTeleport")] public static class PlayerUpdateTeleportPatchCleanupContainers { public static void Prefix(float dt) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsTeleporting()) { return; } foreach (Container item in from container in Boxes.Containers.ToList() where !((Object)container != (Object)null) || !((Object)((Component)container).transform != (Object)null) || container.GetInventory() == null where (Object)container != (Object)null select container) { Boxes.RemoveContainer(item); } } } [HarmonyPatch(typeof(WearNTear), "OnDestroy")] internal static class WearNTearOnDestroyPatch { private static void Prefix(WearNTear __instance) { Container[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Container>(); Container[] componentsInParent = ((Component)__instance).GetComponentsInParent<Container>(); if (componentsInChildren.Length != 0) { Container[] array = componentsInChildren; for (int i = 0; i < array.Length; i++) { Boxes.RemoveContainer(array[i]); } } if (componentsInParent.Length != 0) { Container[] array2 = componentsInParent; for (int j = 0; j < array2.Length; j++) { Boxes.RemoveContainer(array2[j]); } } } } public static class DistanceHud { private const float UpdateInterval = 0.2f; private const float Width = 320f; private const float Height = 30f; private static GameObject _go; private static Text _text; private static RectTransform _rect; private static float _lastUpdate; private static bool Enabled => global::GrabMaterialsMod.GrabMaterialsMod.Instance?.ShowDistanceHud?.Value ?? true; private static bool ShowCoords => (global::GrabMaterialsMod.GrabMaterialsMod.Instance?.ShowDistanceCoords?.Value).GetValueOrDefault(); private static float OffsetX => global::GrabMaterialsMod.GrabMaterialsMod.Instance?.DistanceHudOffsetX?.Value ?? 10f; private static float OffsetY => global::GrabMaterialsMod.GrabMaterialsMod.Instance?.DistanceHudOffsetY?.Value ?? 10f; public static void Tick() { //IL_0057: 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_0087: 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_008e: 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_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) EnsureCreated(); if ((Object)(object)_text == (Object)null) { return; } Player localPlayer = Player.m_localPlayer; bool flag = Enabled && (Object)(object)localPlayer != (Object)null; if (_go.activeSelf != flag) { _go.SetActive(flag); } if (flag) { _rect.anchoredPosition = new Vector2(OffsetX, 0f - OffsetY); float time = Time.time; if (!(time - _lastUpdate < 0.2f)) { _lastUpdate = time; Vector3 position = ((Component)localPlayer).transform.position; float num = Mathf.Sqrt(position.x * position.x + position.z * position.z); _text.text = (ShowCoords ? $"World Center: {num:F0}m ({position.x:F0}, {position.z:F0})" : $"World Center: {num:F0}m"); } } } private static void EnsureCreated() { //IL_0041: 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_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_go != (Object)null) && GUIManager.Instance != null && !((Object)(object)GUIManager.CustomGUIFront == (Object)null)) { _go = GUIManager.Instance.CreateText(string.Empty, GUIManager.CustomGUIFront.transform, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(OffsetX, 0f - OffsetY), GUIManager.Instance.AveriaSerifBold, 16, GUIManager.Instance.ValheimOrange, true, Color.black, 320f, 30f, false); ((Object)_go).name = "GrabMaterials_DistanceHud"; _rect = _go.GetComponent<RectTransform>(); _rect.pivot = new Vector2(0f, 1f); _rect.anchoredPosition = new Vector2(OffsetX, 0f - OffsetY); _text = _go.GetComponent<Text>(); _text.alignment = (TextAnchor)0; ((Graphic)_text).raycastTarget = false; } } } internal static class Extensions { public enum ItemCategory { None, Weapon, Armor, Tool, Shield, Arrow, Bolt, Trophy, Utility, Mead, BalancedFood, HealthFood, StaminaFood, EitrFood, RawMeat, CookedMeat, Summoning, Metal, Wood, Stone, Treasure, Skin, Plant, FoodIngredient, FishingBait, Seed, Weed, Material, Misc } private static readonly HashSet<string> BossSummoningNames = new HashSet<string> { "trophydeer", "ancientseed", "witheredbone", "dragonegg", "goblintotem", "seekerbrood", "trophyfader", "bellfragment", "sealbreaker", "sealbreakerfragment" }; private static readonly HashSet<string> RawMeatNames = new HashSet<string> { "rawmeat", "wolfmeat", "loxmeat", "deermeat", "serpentmeat", "fishraw", "haremeat", "seekermeat", "chickenmeat", "asksvintail", "bonemawmeat", "chickenegg", "entrails", "necktail" }; private static readonly HashSet<string> CookedMeatNames = new HashSet<string> { "cooked_boar_meat", "cookedwolfmeat", "cookedloxmeat", "cookeddeermeat", "serpentmeatcooked", "cookedfish", "cookedharemeat", "cookedseekermeat", "cookedchickenmeat", "cookedbonemawmeat", "NeckTailGrilled" }; private static readonly HashSet<string> FoodIngredientNames = new HashSet<string> { "barleyflour", "bloodclot", "royaljelly" }; private static readonly HashSet<string> FishingBaitNames = new HashSet<string> { "fishingbait", "fishingbaitashlands", "fishingbaitcave", "fishingbaitdeepnorth", "fishingbaitforest", "fishingbaitmistlands", "fishingbaitocean", "fishingbaitplains", "fishingbaitswamp" }; private static readonly HashSet<string> AmmoNames = new HashSet<string> { "payload_grausten", "payload_explosive" }; private static readonly HashSet<string> SkinNames = new HashSet<string> { "leatherscraps", "deerhide", "trollhide", "wolfpelt", "loxpelt", "feathers", "chitin", "scalehide", "harepelt", "carapace", "askbladder", "askhide", "bonemawtooth", "celestialfeather", "fenrisclaw", "fenrishair", "mandible", "queendrop", "morgenheart", "morgensinew", "needle", "root", "ooze", "wolf_fang" }; private static readonly HashSet<string> TreasureNames = new HashSet<string> { "coins", "ruby", "amber", "amberpearl", "silvernecklace" }; private static readonly HashSet<string> WoodNames = new HashSet<string> { "wood", "finewood", "roundlog", "yggdrasilwood", "elderbark", "blackwood" }; private static readonly HashSet<string> StoneNames = new HashSet<string> { "stone", "flint", "obsidian", "marble", "blackmarble", "coal", "crystal", "grausten" }; private static readonly HashSet<string> MetalNames = new HashSet<string> { "iron", "copper", "tin", "silver", "bronze", "blackmetal", "flametal", "ironore", "copperore", "tinore", "silverore", "ironscrap", "blackmetalscrap", "copperscrap", "frometal", "frometalore", "bronzenails", "ironnails", "hildir_ironpit" }; private static readonly HashSet<string> SeedNames = new HashSet<string> { "carrotseeds", "turnipseeds", "onionseeds", "fircone", "pinecone", "beechseeds", "birchseeds" }; private static readonly HashSet<string> WeedNames = new HashSet<string> { "dandelion", "thistle", "vine", "guck" }; private static readonly HashSet<string> PlantNames = new HashSet<string> { "mushroom", "carrot", "turnip", "onion", "raspberry", "blueberries", "cloudberry", "jotunpuffs", "magecap", "sap", "barley", "flax", "fiddlehead", "smokepuff" }; private static readonly HashSet<ItemType> ArmorTypes = new HashSet<ItemType> { (ItemType)6, (ItemType)7, (ItemType)11, (ItemType)17 }; public static string Name(this ItemData self) { return self.m_shared.m_name.Substring(6); } public static string LocalizedName(this ItemData self) { return LocalizationManager.Instance.TryTranslate(self.m_shared.m_name); } public static bool isMatch(this ItemData self, string matchString) { if (!self.Name().isMatch(matchString) && !self.m_shared.m_name.isMatch(matchString)) { return self.LocalizedName().isMatch(matchString); } return true; } public static bool isMatch(this string self, string s) { return string.Equals(self, s, StringComparison.CurrentCultureIgnoreCase); } public static int Count(this ItemData self) { return self.m_stack; } public static ItemCategory GetCategory(this ItemData self) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Invalid comparison between Unknown and I4 //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Invalid comparison between Unknown and I4 //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Invalid comparison between Unknown and I4 //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Invalid comparison between Unknown and I4 //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Invalid comparison between Unknown and I4 //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Invalid comparison between Unknown and I4 //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Invalid comparison between Unknown and I4 //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_01f0: Invalid comparison between Unknown and I4 SharedData shared = self.m_shared; string text = ((Object)self.m_dropPrefab).name.ToLowerInvariant(); if ((int)shared.m_itemType == 13) { return ItemCategory.Trophy; } if ((int)shared.m_itemType == 19) { return ItemCategory.Tool; } if ((int)shared.m_itemType == 9 && shared.m_ammoType == "$ammo_arrows") { return ItemCategory.Arrow; } if ((int)shared.m_itemType == 9 && shared.m_ammoType == "$ammo_bolts") { return ItemCategory.Bolt; } if ((int)shared.m_itemType == 9 && shared.m_ammoType == "$item_fishingbait") { return ItemCategory.FishingBait; } if ((int)shared.m_itemType == 5) { return ItemCategory.Shield; } if ((int)shared.m_itemType == 18) { return ItemCategory.Utility; } if (shared.m_isDrink) { return ItemCategory.Mead; } if (self.IsWeapon()) { return ItemCategory.Weapon; } if (ArmorTypes.Contains(shared.m_itemType)) { return ItemCategory.Armor; } if (BossSummoningNames.Contains(text)) { return ItemCategory.Summoning; } if (MetalNames.Contains(text)) { return ItemCategory.Metal; } if (WoodNames.Contains(text)) { return ItemCategory.Wood; } if (StoneNames.Contains(text)) { return ItemCategory.Stone; } if (TreasureNames.Contains(text)) { return ItemCategory.Treasure; } if (SkinNames.Contains(text)) { return ItemCategory.Skin; } if (RawMeatNames.Contains(text)) { return ItemCategory.RawMeat; } if (FoodIngredientNames.Contains(text)) { return ItemCategory.FoodIngredient; } if (FishingBaitNames.Contains(text)) { return ItemCategory.FishingBait; } if (SeedNames.Contains(text)) { return ItemCategory.Seed; } if (WeedNames.Contains(text)) { return ItemCategory.Weed; } if (AmmoNames.Contains(text)) { return ItemCategory.Arrow; } if (shared.m_food > 0f) { if (shared.m_foodEitr > 0f) { return ItemCategory.EitrFood; } if (shared.m_food > shared.m_foodStamina) { return ItemCategory.HealthFood; } if (shared.m_foodStamina > shared.m_food) { return ItemCategory.StaminaFood; } return ItemCategory.BalancedFood; } if (PlantNames.Contains(text) || text.Contains("Seed")) { return ItemCategory.Plant; } if ((int)shared.m_itemType == 1) { return ItemCategory.Material; } return ItemCategory.Misc; } public static void Highlight(this Container container) { WearNTear component = ((Component)container).GetComponent<WearNTear>(); if (Object.op_Implicit((Object)(object)component)) { ((MonoBehaviour)component).StartCoroutine(HighlightRoutine(component)); } } private static IEnumerator HighlightRoutine(WearNTear wearTear) { float value = global::GrabMaterialsMod.GrabMaterialsMod.Instance.HighlightDuration.Value; int iterations = Mathf.CeilToInt(value / 0.1f); for (int i = 0; i < iterations; i++) { wearTear.Highlight(); yield return (object)new WaitForSeconds(0.1f); } } public static int GrabItemFromContainer(this Container container, string name, int count) { Inventory inventory = ((Humanoid)Player.m_localPlayer).GetInventory(); Inventory inventory2 = container.GetInventory(); int num = 0; ItemData[] array = inventory2.GetAllItems().ToArray(); for (int i = 0; i < array.Count(); i++) { if (count <= 0) { break; } ItemData val = array[i]; if (val.isMatch(name)) { int num2 = ((count > val.Count()) ? val.Count() : count); Debug.Log((object)$"grabbing {num2} of {val.Count()} {name} from {container} {((Object)container).GetInstanceID()}"); ItemData val2 = val.Clone(); val2.m_stack = num2; inventory2.RemoveItem(val, num2); inventory.AddItem(val2); num += num2; count -= num2; } } if (num > 0) { container.Highlight(); } return num; } public static bool StoreItemInContainer(this Container container, ItemData item) { Inventory inventory = ((Humanoid)Player.m_localPlayer).GetInventory(); Inventory inventory2 = container.GetInventory(); if (!inventory2.CanAddItem(item, -1)) { Debug.LogWarning((object)"Container's inventory full."); return false; } Debug.Log((object)$"moving {item.Name()} {item.Count()}"); inventory2.MoveItemToThis(inventory, item); Debug.Log((object)$"moved {item.Name()} {item.Count()}"); container.Highlight(); return true; } public static int CountItems(this Inventory inventory) { int num = 0; foreach (ItemData allItem in ((Humanoid)Player.m_localPlayer).GetInventory().GetAllItems()) { num += allItem.Count(); } return num; } public static int CountItems(this Inventory inventory, string name) { int num = 0; foreach (ItemData allItem in ((Humanoid)Player.m_localPlayer).GetInventory().GetAllItems()) { if (allItem.Name() == name) { num += allItem.Count(); } } return num; } public static string GetResourceList(this Piece piece) { Requirement[] resources = piece.m_resources; StringBuilder stringBuilder = new StringBuilder(); if (resources != null) { Requirement[] array = resources; foreach (Requirement val in array) { stringBuilder.Append(string.Format("{0}:{1},", val.m_resItem.m_itemData.m_shared.m_name.Replace("$item_", ""), val.m_amount)); } } return stringBuilder.ToString(); } } public static class MaterialsPanel { public struct ItemStatus { public string Name; public int Needed; public int Available; public int Had; } public struct InventoryItem { public string Name; public int Count; public Sprite Icon; public string SharedName; } public struct InventoryGroup { public string CategoryName; public List<InventoryItem> Items; } public enum InventoryStyle { List, Table } public enum InventoryShape { MaxHeight, VeryTall, Tall, SlightlyTall, Square, SlightlyWide, Wide, VeryWide, MaxWidth } internal class RowHoverTint : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler { public Image target; public Color normal; public Color hover; public Color pressed; private bool _hovered; private bool _pressed; public void OnPointerEnter(PointerEventData eventData) { if (!_hovered) { _hovered = true; _rowsHovered++; } Apply(); } public void OnPointerExit(PointerEventData eventData) { if (_hovered) { _hovered = false; _rowsHovered = Mathf.Max(0, _rowsHovered - 1); } _pressed = false; Apply(); } public void OnPointerDown(PointerEventData eventData) { _pressed = true; Apply(); } public void OnPointerUp(PointerEventData eventData) { _pressed = false; Apply(); } private void OnDisable() { if (_hovered) { _hovered = false; _rowsHovered = Mathf.Max(0, _rowsHovered - 1); } _pressed = false; } private void Apply() { //IL_001e: 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_0038: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)target == (Object)null)) { if (_pressed) { ((Graphic)target).color = pressed; } else if (_hovered) { ((Graphic)target).color = hover; } else { ((Graphic)target).color = normal; } } } } internal class PanelHoverTracker : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler { public void OnPointerEnter(PointerEventData eventData) { _panelHovered = true; } public void OnPointerExit(PointerEventData eventData) { _panelHovered = false; } private void OnDisable() { _panelHovered = false; } } private const float DefaultPanelWidth = 480f; private const float MinPanelWidth = 280f; private const float PanelSidePadding = 20f; private const float TitleHeight = 50f; private const float LineHeight = 26f; private const float HeaderUnderlineHeight = 2f; private const float CategorySpacing = 8f; private const float ColumnSpacing = 20f; private const float BottomPadding = 20f; private const float TopMargin = 20f; private const float ArmDelaySeconds = 0.3f; private const int MaxColumns = 20; private const float CountColumnWidth = 60f; private const float CategoryColumnWidth = 130f; private const float ColumnGap = 8f; private const float ListRowPadding = 0f; private const float TableRowPadding = 14f; private const int FontSize = 18; private static readonly Color CategoryColor = new Color(1f, 0.847f, 0.42f); private static readonly Color UnderlineColor = new Color(1f, 0.847f, 0.42f, 0.55f); private static GameObject _panel; private static RectTransform _panelRect; private static Text _titleText; private static Text _contentText; private static RectTransform _contentRect; private static GameObject _rowsContainer; private static RectTransform _rowsContainerRect; private static Transform _currentBuildParent; private static CanvasGroup _canvasGroup; private static float _shownAt; private static float _fadeStart = -1f; private static bool _dismissArmed; internal static int _rowsHovered; internal static bool _panelHovered; private static readonly Color RowNormalColor = new Color(1f, 1f, 1f, 0f); private static readonly Color RowHoverColor = new Color(1f, 0.92f, 0.45f, 0.22f); private static readonly Color RowPressedColor = new Color(1f, 0.92f, 0.45f, 0.4f); private static float MaxPanelWidth => Mathf.Max(800f, (float)Screen.width - 40f); private static float MaxPanelHeight => Mathf.Max(400f, (float)Screen.height - 100f); private static float IdleTimeoutSeconds => global::GrabMaterialsMod.GrabMaterialsMod.Instance?.PanelIdleTimeout?.Value ?? 15f; private static float FadeDurationSeconds => global::GrabMaterialsMod.GrabMaterialsMod.Instance?.PanelFadeDuration?.Value ?? 3f; private static bool DismissOnMovement => global::GrabMaterialsMod.GrabMaterialsMod.Instance?.PanelDismissOnMovement?.Value ?? true; private static bool ShowCategoryUnderlines => global::GrabMaterialsMod.GrabMaterialsMod.Instance?.PanelCategoryUnderlines?.Value ?? true; private static bool ShowItemIcons => global::GrabMaterialsMod.GrabMaterialsMod.Instance?.PanelShowItemIcons?.Value ?? true; private static float IconSize => global::GrabMaterialsMod.GrabMaterialsMod.Instance?.PanelIconSize?.Value ?? 24f; private static float TargetAspectRatio => AspectRatioFor(global::GrabMaterialsMod.GrabMaterialsMod.Instance?.InventoryShape?.Value ?? InventoryShape.SlightlyWide); private static bool IsPanelHovered { get { if (_rowsHovered <= 0) { return _panelHovered; } return true; } } private static float AspectRatioFor(InventoryShape s) { return s switch { InventoryShape.MaxHeight => 0.1f, InventoryShape.VeryTall => 0.6f, InventoryShape.Tall => 0.85f, InventoryShape.SlightlyTall => 1.05f, InventoryShape.Square => 1.25f, InventoryShape.SlightlyWide => 1.55f, InventoryShape.Wide => 2f, InventoryShape.VeryWide => 3f, InventoryShape.MaxWidth => 10f, _ => 1.55f, }; } public static void Show(string title, List<ItemStatus> items) { List<string> list = new List<string>(items.Count); foreach (ItemStatus item in items) { list.Add(FormatItemStatus(item)); } ShowLines(title, list); } public static void ShowInventory(string title, List<InventoryItem> items) { int width = MaxCountWidth(items); List<string> list = new List<string>(items.Count); foreach (InventoryItem item in items) { list.Add(RightAlignCount(item.Count, width) + " " + item.Name); } ShowLines(title, list); } public static void ShowCategorizedInventory(string title, List<InventoryGroup> groups, InventoryStyle style = InventoryStyle.List) { if (style == InventoryStyle.Table) { ShowTable(title, groups); } else { ShowList(title, groups); } } private static void ShowList(string title, List<InventoryGroup> groups) { EnsureCreated(); if ((Object)(object)_panel == (Object)null) { return; } float num = ComputeListCountColumnWidth(groups); bool showCategoryUnderlines = ShowCategoryUnderlines; List<float> list = new List<float>(groups.Count); float num2 = 0f; foreach (InventoryGroup group in groups) { float num3 = 26f + (showCategoryUnderlines ? 2f : 0f) + (float)group.Items.Count * 26f; list.Add(num3); num2 += num3; } if (groups.Count > 1) { num2 += (float)(groups.Count - 1) * 8f; } float num4 = 0f; float num5 = 0f; foreach (InventoryGroup group2 in groups) { num5 = Mathf.Max(num5, EstimateTextWidth(group2.CategoryName)); foreach (InventoryItem item in group2.Items) { num4 = Mathf.Max(num4, EstimateTextWidth(item.Name)); } } float num6 = (ShowItemIcons ? (IconSize + 8f) : 0f); float num7 = 0f + num + 8f + num6 + num4; float num8 = 0f + num5; float num9 = Mathf.Max(num7, num8); int num10 = ComputeColumnCount(num9, num2); List<List<int>> list2 = DistributeIntoColumns(list, num10); float panelWidth = Mathf.Clamp((float)num10 * num9 + (float)(num10 - 1) * 20f + 40f, 280f, MaxPanelWidth); SwitchToRowsMode(title, panelWidth); float num11 = 0f; for (int i = 0; i < num10; i++) { _currentBuildParent = CreateColumn(num9).transform; List<int> list3 = list2[i]; float num12 = 0f; for (int j = 0; j < list3.Count; j++) { if (j > 0) { AddSpacer(8f); num12 += 8f; } int index = list3[j]; InventoryGroup inventoryGroup = groups[index]; BuildHeaderRow(inventoryGroup.CategoryName, inventoryGroup.Items, showCategoryUnderlines, 0f); num12 += 26f + (showCategoryUnderlines ? 2f : 0f); foreach (InventoryItem item2 in inventoryGroup.Items) { int count = item2.Count; BuildDataRow(count.ToString(), item2.Icon, item2.Name, item2.SharedName, 0f, num); num12 += 26f; } } num11 = Mathf.Max(num11, num12); } FinalizeRowsLayout(panelWidth, num11); } private static int ComputeColumnCount(float perColumnContentWidth, float totalContentHeight) { float targetAspectRatio = TargetAspectRatio; float maxPanelHeight = MaxPanelHeight; int num = -1; float num2 = float.MaxValue; for (int i = 1; i <= 20; i++) { float num3 = Mathf.Clamp((float)i * perColumnContentWidth + (float)(i - 1) * 20f + 40f, 280f, MaxPanelWidth); float num4 = totalContentHeight / (float)i; float num5 = 50f + num4 + 20f; if (!(num5 > maxPanelHeight)) { float num6 = Mathf.Abs(num3 / Mathf.Max(num5, 1f) - targetAspectRatio); if (num6 < num2) { num2 = num6; num = i; } } } if (num < 0) { num = 20; } return num; } private static List<List<int>> DistributeIntoColumns(List<float> groupHeights, int numColumns) { if (numColumns <= 1) { List<int> list = new List<int>(groupHeights.Count); for (int i = 0; i < groupHeights.Count; i++) { list.Add(i); } return new List<List<int>> { list }; } float num = 0f; float num2 = 0f; foreach (float groupHeight in groupHeights) { if (groupHeight > num) { num = groupHeight; } num2 += groupHeight + 8f; } for (int j = 0; j < 40; j++) { if (!(num2 - num > 0.5f)) { break; } float num3 = (num + num2) * 0.5f; if (FitsInColumns(groupHeights, numColumns, num3)) { num2 = num3; } else { num = num3; } } return PackGreedy(groupHeights, numColumns, num2); } private static bool FitsInColumns(List<float> heights, int numColumns, float maxH) { int num = 1; float num2 = 0f; foreach (float height in heights) { float num3 = ((num2 > 0f) ? 8f : 0f) + height; if (num2 + num3 > maxH && num2 > 0f) { num++; if (num > numColumns) { return false; } num2 = height; } else { num2 += num3; } } return true; } private static List<List<int>> PackGreedy(List<float> heights, int numColumns, float maxH) { List<List<int>> list = new List<List<int>>(); list.Add(new List<int>()); float num = 0f; for (int i = 0; i < heights.Count; i++) { float num2 = ((num > 0f) ? 8f : 0f) + heights[i]; if (num + num2 > maxH && num > 0f) { list.Add(new List<int>()); num = heights[i]; } else { num += num2; } list[list.Count - 1].Add(i); } while (list.Count < numColumns) { list.Add(new List<int>()); } return list; } private static GameObject CreateColumn(float width) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0046: 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_0064: 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_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Expected O, but got Unknown GameObject val = new GameObject("Column"); val.transform.SetParent(_rowsContainer.transform, false); RectTransform obj = val.AddComponent<RectTransform>(); obj.anchorMin = new Vector2(0f, 1f); obj.anchorMax = new Vector2(0f, 1f); obj.pivot = new Vector2(0f, 1f); VerticalLayoutGroup obj2 = val.AddComponent<VerticalLayoutGroup>(); ((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = true; ((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true; ((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = true; ((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false; ((LayoutGroup)obj2).childAlignment = (TextAnchor)0; ((HorizontalOrVerticalLayoutGroup)obj2).spacing = 0f; ContentSizeFitter obj3 = val.AddComponent<ContentSizeFitter>(); obj3.verticalFit = (FitMode)2; obj3.horizontalFit = (FitMode)0; LayoutElement obj4 = val.AddComponent<LayoutElement>(); obj4.preferredWidth = width; obj4.flexibleWidth = 0f; return val; } private static float ComputeListCountColumnWidth(List<InventoryGroup> groups) { float num = EstimateTextWidth("9"); foreach (InventoryGroup group in groups) { foreach (InventoryItem item in group.Items) { float num2 = num; int count = item.Count; num = Mathf.Max(num2, EstimateTextWidth(count.ToString())); } } return num + 2f; } private static void ShowTable(string title, List<InventoryGroup> groups) { EnsureCreated(); if ((Object)(object)_panel == (Object)null) { return; } float num = ComputeTablePanelWidth(groups); SwitchToRowsMode(title, num); _currentBuildParent = CreateColumn(num - 40f).transform; BuildColumnHeadersRow(); float num2 = 28f; foreach (InventoryGroup group in groups) { foreach (InventoryItem item in group.Items) { string categoryName = group.CategoryName; Sprite icon = item.Icon; string name = item.Name; int count = item.Count; BuildFlatDataRow(categoryName, icon, name, count.ToString(), item.SharedName); num2 += 26f; } } FinalizeRowsLayout(num, num2); } private static void SwitchToRowsMode(string title, float panelWidth) { if ((Object)(object)_contentText != (Object)null) { ((Component)_contentText).gameObject.SetActive(false); } _rowsContainer.SetActive(true); _titleText.text = title; ApplyPanelWidth(panelWidth); ClearRows(); } private static void FinalizeRowsLayout(float panelWidth, float totalHeight) { //IL_000f: 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) float num = panelWidth - 40f; _rowsContainerRect.sizeDelta = new Vector2(num, totalHeight); float num2 = 50f + totalHeight + 20f; _panelRect.sizeDelta = new Vector2(panelWidth, num2); _panel.SetActive(true); _canvasGroup.alpha = 1f; _shownAt = Time.time; _fadeStart = -1f; _dismissArmed = false; } private static void ApplyPanelWidth(float panelWidth) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) float num = panelWidth - 40f; _panelRect.sizeDelta = new Vector2(panelWidth, _panelRect.sizeDelta.y); ((Component)_titleText).GetComponent<RectTransform>().sizeDelta = new Vector2(panelWidth - 60f, 30f); _contentRect.sizeDelta = new Vector2(num, _contentRect.sizeDelta.y); _rowsContainerRect.sizeDelta = new Vector2(num, _rowsContainerRect.sizeDelta.y); } private static float ComputeListPanelWidth(List<InventoryGroup> groups, float countCol) { float num = 0f; float num2 = 0f; foreach (InventoryGroup group in groups) { num2 = Mathf.Max(num2, EstimateTextWidth(group.CategoryName)); foreach (InventoryItem item in group.Items) { num = Mathf.Max(num, EstimateTextWidth(item.Name)); } } float num3 = 0f + countCol + 8f + num; float num4 = 0f + num2; return Mathf.Clamp(Mathf.Max(num3, num4) + 40f, 280f, MaxPanelWidth); } private static float ComputeTablePanelWidth(List<InventoryGroup> groups) { float num = EstimateTextWidth("Item"); float num2 = EstimateTextWidth("Count"); float num3 = EstimateTextWidth("Category"); foreach (InventoryGroup group in groups) { num3 = Mathf.Max(num3, EstimateTextWidth(group.CategoryName)); foreach (InventoryItem item in group.Items) { num = Mathf.Max(num, EstimateTextWidth(item.Name)); float num4 = num2; int count = item.Count; num2 = Mathf.Max(num4, EstimateTextWidth(count.ToString())); } } float num5 = Mathf.Max(130f, num3); float num6 = Mathf.Max(60f, num2); float num7 = (ShowItemIcons ? (IconSize + 8f) : 0f); return Mathf.Clamp(28f + num5 + 8f + num7 + num + 8f + num6 + 40f, 280f, MaxPanelWidth); } private static float EstimateTextWidth(string s) { if (string.IsNullOrEmpty(s)) { return 0f; } return (float)(s.Length * 18) * 0.55f; } public static void Hide() { if ((Object)(object)_panel != (Object)null) { _panel.SetActive(false); } if ((Object)(object)_canvasGroup != (Object)null) { _canvasGroup.alpha = 1f; } _fadeStart = -1f; _dismissArmed = false; _rowsHovered = 0; _panelHovered = false; } public static void KeepAlive() { if (!((Object)(object)_panel == (Object)null) && _panel.activeSelf) { _shownAt = Time.time; _fadeStart = -1f; _dismissArmed = false; if ((Object)(object)_canvasGroup != (Object)null) { _canvasGroup.alpha = 1f; } } } public static void Tick() { if ((Object)(object)_panel == (Object)null || !_panel.activeSelf) { return; } float time = Time.time; if (IsPanelHovered) { _shownAt = time; _fadeStart = -1f; _dismissArmed = false; if ((Object)(object)_canvasGroup != (Object)null && _canvasGroup.alpha < 1f) { _canvasGroup.alpha = 1f; } } else if (_fadeStart >= 0f) { float num = (time - _fadeStart) / FadeDurationSeconds; if (num >= 1f) { Hide(); } else { _canvasGroup.alpha = 1f - num; } } else if (time - _shownAt >= IdleTimeoutSeconds) { _fadeStart = time; } else { if (!_dismissArmed && time - _shownAt >= 0.3f) { _dismissArmed = true; } if (_dismissArmed && DismissOnMovement && HasGameplayInput()) { _fadeStart = time; } } } private static void ClearRows() { if (!((Object)(object)_rowsContainer == (Object)null)) { for (int num = _rowsContainer.transform.childCount - 1; num >= 0; num--) { Object.DestroyImmediate((Object)(object)((Component)_rowsContainer.transform.GetChild(num)).gameObject); } } } private static void BuildHeaderRow(string categoryName, List<InventoryItem> items, bool drawUnderline, float sidePadding) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: 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 r