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.Managers;
using Jotunn.Utils;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[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.0.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_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Expected O, but got Unknown
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Expected O, but got Unknown
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Expected O, but got Unknown
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: 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("NOT YET SUPPORTED (Grab the delta of items needed for the grab pack)", (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__9_0;
public static ConsoleEvent <>9__10_0;
public static ConsoleEvent <>9__10_1;
public static ConsoleEvent <>9__10_2;
public static ConsoleEvent <>9__10_3;
public static ConsoleEvent <>9__10_4;
public static ConsoleEvent <>9__10_5;
public static ConsoleEvent <>9__10_6;
public static ConsoleEvent <>9__10_7;
public static ConsoleEvent <>9__10_8;
public static ConsoleEvent <>9__10_9;
public static ConsoleEvent <>9__10_10;
public static ConsoleEvent <>9__10_11;
public static ConsoleEvent <>9__10_12;
public static ConsoleEvent <>9__10_13;
public static ConsoleEvent <>9__10_14;
internal void <InitConfig>b__9_0(object sender, EventArgs e)
{
Debug.Log((object)("Grabpack renamed " + sender.ToString() + " " + e.ToString()));
}
internal void <InitCommands>b__10_0(ConsoleEventArgs args)
{
args.GrabItemsFromNearbyContainers();
}
internal void <InitCommands>b__10_1(ConsoleEventArgs args)
{
args.GrabItemsFromNearbyContainers();
}
internal void <InitCommands>b__10_2(ConsoleEventArgs args)
{
ConsoleCommands.GrabMaterialsForSelectedPiece();
}
internal void <InitCommands>b__10_3(ConsoleEventArgs args)
{
args.GrabMaterialsForPiece();
}
internal void <InitCommands>b__10_4(ConsoleEventArgs args)
{
ListKnownContainers();
}
internal void <InitCommands>b__10_5(ConsoleEventArgs args)
{
ListLocalContainers(args);
}
internal void <InitCommands>b__10_6(ConsoleEventArgs args)
{
ListLocalContainerContents(args);
}
internal void <InitCommands>b__10_7(ConsoleEventArgs args)
{
ListGrabPacks();
}
internal void <InitCommands>b__10_8(ConsoleEventArgs args)
{
ListLocalInventory(args);
}
internal void <InitCommands>b__10_9(ConsoleEventArgs args)
{
ListLocalInventory(args);
}
internal void <InitCommands>b__10_10(ConsoleEventArgs args)
{
FindContainersWithMatchingItems(args);
}
internal void <InitCommands>b__10_11(ConsoleEventArgs args)
{
FindContainersWithMatchingItems(args);
}
internal void <InitCommands>b__10_12(ConsoleEventArgs args)
{
StoreItemsInNearbyContainers();
}
internal void <InitCommands>b__10_13(ConsoleEventArgs args)
{
CountInventory(args);
}
internal void <InitCommands>b__10_14(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;
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_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Expected O, but got Unknown
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Expected O, but got Unknown
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
//IL_020e: Unknown result type (might be due to invalid IL or missing references)
//IL_0241: Unknown result type (might be due to invalid IL or missing references)
//IL_0294: Unknown result type (might be due to invalid IL or missing references)
ConfigDescription val = 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>()));
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_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: 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_0062: Expected O, but got Unknown
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Expected O, but got Unknown
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Expected O, but got Unknown
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Expected O, but got Unknown
//IL_014b: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Expected O, but got Unknown
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_017a: Expected O, but got Unknown
//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
//IL_01b2: Expected O, but got Unknown
//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
//IL_01df: Unknown result type (might be due to invalid IL or missing references)
//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
//IL_01ea: Expected O, but got Unknown
//IL_022b: Unknown result type (might be due to invalid IL or missing references)
//IL_0217: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_0222: Expected O, but got Unknown
//IL_0263: Unknown result type (might be due to invalid IL or missing references)
//IL_024f: Unknown result type (might be due to invalid IL or missing references)
//IL_0254: Unknown result type (might be due to invalid IL or missing references)
//IL_025a: Expected O, but got Unknown
//IL_029b: Unknown result type (might be due to invalid IL or missing references)
//IL_0287: Unknown result type (might be due to invalid IL or missing references)
//IL_028c: Unknown result type (might be due to invalid IL or missing references)
//IL_0292: Expected O, but got Unknown
//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
//IL_02ca: Expected O, but got Unknown
//IL_030b: Unknown result type (might be due to invalid IL or missing references)
//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0302: Expected O, but got Unknown
//IL_0343: Unknown result type (might be due to invalid IL or missing references)
//IL_032f: Unknown result type (might be due to invalid IL or missing references)
//IL_0334: Unknown result type (might be due to invalid IL or missing references)
//IL_033a: Expected O, but got Unknown
object obj = <>c.<>9__10_0;
if (obj == null)
{
ConsoleEvent val = delegate(ConsoleEventArgs args)
{
args.GrabItemsFromNearbyContainers();
};
<>c.<>9__10_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__10_1;
if (obj2 == null)
{
ConsoleEvent val2 = delegate(ConsoleEventArgs args)
{
args.GrabItemsFromNearbyContainers();
};
<>c.<>9__10_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__10_2;
if (obj3 == null)
{
ConsoleEvent val3 = delegate
{
ConsoleCommands.GrabMaterialsForSelectedPiece();
};
<>c.<>9__10_2 = val3;
obj3 = (object)val3;
}
new ConsoleCommand("grabselected", "", (ConsoleEvent)obj3, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
object obj4 = <>c.<>9__10_3;
if (obj4 == null)
{
ConsoleEvent val4 = delegate(ConsoleEventArgs args)
{
args.GrabMaterialsForPiece();
};
<>c.<>9__10_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__10_4;
if (obj5 == null)
{
ConsoleEvent val5 = delegate
{
ListKnownContainers();
};
<>c.<>9__10_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__10_5;
if (obj6 == null)
{
ConsoleEvent val6 = delegate(ConsoleEventArgs args)
{
ListLocalContainers(args);
};
<>c.<>9__10_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__10_6;
if (obj7 == null)
{
ConsoleEvent val7 = delegate(ConsoleEventArgs args)
{
ListLocalContainerContents(args);
};
<>c.<>9__10_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__10_7;
if (obj8 == null)
{
ConsoleEvent val8 = delegate
{
ListGrabPacks();
};
<>c.<>9__10_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__10_8;
if (obj9 == null)
{
ConsoleEvent val9 = delegate(ConsoleEventArgs args)
{
ListLocalInventory(args);
};
<>c.<>9__10_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__10_9;
if (obj10 == null)
{
ConsoleEvent val10 = delegate(ConsoleEventArgs args)
{
ListLocalInventory(args);
};
<>c.<>9__10_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__10_10;
if (obj11 == null)
{
ConsoleEvent val11 = delegate(ConsoleEventArgs args)
{
FindContainersWithMatchingItems(args);
};
<>c.<>9__10_10 = val11;
obj11 = (object)val11;
}
new ConsoleCommand("search", "[search-text] - search for items matching this string in nearby containers", (ConsoleEvent)obj11, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
object obj12 = <>c.<>9__10_11;
if (obj12 == null)
{
ConsoleEvent val12 = delegate(ConsoleEventArgs args)
{
FindContainersWithMatchingItems(args);
};
<>c.<>9__10_11 = val12;
obj12 = (object)val12;
}
new ConsoleCommand("s", "[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__10_12;
if (obj13 == null)
{
ConsoleEvent val13 = delegate
{
StoreItemsInNearbyContainers();
};
<>c.<>9__10_12 = val13;
obj13 = (object)val13;
}
new ConsoleCommand("store", "[items] - stores items randomly nearby containers", (ConsoleEvent)obj13, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
object obj14 = <>c.<>9__10_13;
if (obj14 == null)
{
ConsoleEvent val14 = delegate(ConsoleEventArgs args)
{
CountInventory(args);
};
<>c.<>9__10_13 = val14;
obj14 = (object)val14;
}
new ConsoleCommand("count", "[name of item to count] - omit to count everything", (ConsoleEvent)obj14, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
object obj15 = <>c.<>9__10_14;
if (obj15 == null)
{
ConsoleEvent val15 = delegate
{
ListAllPieces();
};
<>c.<>9__10_14 = val15;
obj15 = (object)val15;
}
new ConsoleCommand("listpieces", "", (ConsoleEvent)obj15, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
}
private void InitButtons()
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: 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_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: 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()
{
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()
{
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))
{
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)
{
Debug.Log((object)(((Object)prefab).name + " \"" + text + "\""));
continue;
}
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_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_020f: 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()}:");
Inventory inventory = item.GetInventory();
List<ItemData> allItems = inventory.GetAllItems();
foreach (ItemData item2 in allItems)
{
string text = "";
text = LocalizationManager.Instance.TryTranslate(item2.m_shared.m_name);
Debug.Log((object)$"{item2.Count()},{text},{item2.Name()},{item2.GetCategory()},{item2.m_shared.m_itemType},{item2.IsWeapon()},{item2.IsEquipable()},{item2.m_shared.m_isDrink},{item2.GetArmor()},{item2.m_shared.m_armorMaterial},{item2.m_shared.m_food},{item2.m_shared.m_foodStamina},{item2.m_shared.m_foodEitr},{item2.m_shared.m_ammoType},{item2.m_shared.m_questItem},{item2.m_shared.m_skillType}");
}
}
}
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");
Debug.Log((object)$"showing the inventory of {nearbyContainers.Count} nearby containers");
SortedDictionary<string, int> sortedDictionary = new SortedDictionary<string, int>();
foreach (Container item in nearbyContainers)
{
Inventory inventory = item.GetInventory();
List<ItemData> allItems = inventory.GetAllItems();
bool flag = false;
foreach (ItemData item2 in allItems)
{
string name = item2.m_shared.m_name;
string text2 = LocalizationManager.Instance.TryTranslate(name).ToLower();
Extensions.ItemCategory category = item2.GetCategory();
string text3 = category.ToString().ToLower();
Extensions.ItemCategory result = Extensions.ItemCategory.None;
bool flag2 = text != null && Enum.TryParse<Extensions.ItemCategory>(text, ignoreCase: true, out result);
string text4 = result.ToString().ToLower();
bool num2;
if (!flag2)
{
if (text == null || item2.Name().Contains(text) || name.Contains(text) || text2.Contains(text))
{
goto IL_0166;
}
num2 = text3.Contains(text);
}
else
{
num2 = category == result;
}
if (!num2)
{
continue;
}
goto IL_0166;
IL_0166:
if (sortedDictionary.ContainsKey(name))
{
sortedDictionary[name] += item2.Count();
}
else
{
sortedDictionary[name] = item2.Count();
}
if (!flag)
{
item.Highlight();
flag = true;
}
}
}
StringBuilder stringBuilder = new StringBuilder();
foreach (KeyValuePair<string, int> item3 in sortedDictionary)
{
string arg = LocalizationManager.Instance.TryTranslate(item3.Key);
Debug.Log((object)$"{item3.Value} {arg}");
stringBuilder.AppendLine($"{item3.Value} {arg}");
}
((Character)Player.m_localPlayer).Message((MessageType)2, stringBuilder.ToString(), 0, (Sprite)null);
}
private static void ListGrabPacks()
{
//IL_004d: 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();
List<ItemData> allItems = inventory.GetAllItems();
foreach (ItemData item2 in allItems)
{
if (item2.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;
Player localPlayer = Player.m_localPlayer;
Inventory inventory = ((Humanoid)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)
{
long playerID = Game.instance.GetPlayerProfile().GetPlayerID();
AddContainer(container);
}
}
internal static List<Container> GetNearbyContainers(float radius)
{
//IL_0029: 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)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
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);
continue;
}
if ((Object)(object)((Component)container).transform == (Object)null)
{
Debug.LogWarning((object)("Found container " + ((Object)container).name + " with null transform in list"));
ContainersToRemove.Add(container);
continue;
}
float num = Vector3.Distance(position, ((Component)container).transform.position);
if (num < radius)
{
list.Add(container);
}
}
UpdateContainers();
return list;
}
}
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>();
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);
}
public static void GrabMaterialsForPack(string packName, string itemsString)
{
Debug.Log((object)("GrabMaterialsForPack(" + packName + ", " + itemsString + ")"));
List<ItemToGrab> list = new List<ItemToGrab>();
string[] array = itemsString.Replace(" ", "").Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
string[] array2 = array;
foreach (string text in array2)
{
string[] array3 = text.Split(new char[1] { ':' }, StringSplitOptions.RemoveEmptyEntries);
if (array3.Length > 2)
{
Debug.LogError((object)("Invalid format for " + packName + " item list: was " + itemsString + ", expected 'item[:quantity],item[:quantity],...'"));
return;
}
string text2 = array3[0];
int result = 1;
if (array3.Length == 2 && !int.TryParse(array3[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} {text2}");
foreach (ItemToGrab item in GetItemsToGrab(text2, result))
{
list.Add(item);
}
}
GrabItemsFromNearbyContainers(list, 50f);
}
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)
{
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}");
GrabItemsFromNearbyContainers(val.m_resItem.m_itemData.m_shared.m_name, val.m_amount);
}
}
}
private static void GrabItemsFromNearbyContainers(List<ItemToGrab> itemsToGrab, float radius)
{
List<Container> nearbyContainers = Boxes.GetNearbyContainers(radius);
Player localPlayer = Player.m_localPlayer;
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < itemsToGrab.Count; i++)
{
ItemToGrab itemToGrab = itemsToGrab[i];
int count = itemToGrab.Count;
Debug.Log((object)$"grabbing {itemToGrab.Count} {itemToGrab.Name} from {nearbyContainers.Count} containers within {radius} meters");
for (int j = 0; j < nearbyContainers.Count; j++)
{
if (itemToGrab.Count <= 0)
{
break;
}
Container container = nearbyContainers[j];
int num = container.GrabItemFromContainer(itemToGrab.Name, itemToGrab.Count);
itemToGrab.Count -= num;
}
stringBuilder.AppendLine($"Grabbed {count - itemToGrab.Count} of {count} {itemToGrab.Name}");
}
((Character)localPlayer).Message((MessageType)2, stringBuilder.ToString(), 0, (Sprite)null);
}
public static void GrabMaterialsForSelectedPiece()
{
Player localPlayer = Player.m_localPlayer;
Piece selectedPiece = localPlayer.GetSelectedPiece();
if (!Object.op_Implicit((Object)(object)selectedPiece))
{
string text = "No build piece selected";
Debug.Log((object)text);
((Character)localPlayer).Message((MessageType)2, text, 0, (Sprite)null);
}
else
{
GrabMaterialsForPiece(selectedPiece);
}
}
private 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);
}
}
private static string GetPieceResourceList(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();
}
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))
{
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 val = pieceLookup[name.ToLowerInvariant()];
Debug.Log((object)("Found piece " + name + " in lookup table, grabbing materials for it"));
Requirement[] resources = val.m_resources;
if (resources != null)
{
Requirement[] array = resources;
foreach (Requirement val2 in array)
{
Debug.Log((object)$"{val2.m_amount} {val2.m_resItem.m_itemData.Name()}");
list.Add(new ItemToGrab(val2.m_resItem.m_itemData.Name(), val2.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);
GrabItemsFromNearbyContainers(itemsToGrab, radius);
}
}
public static class HudTranspilers
{
[HarmonyPatch(typeof(Hud), "Awake")]
public static class PieceTablePatch
{
private static void Postfix(Hud __instance)
{
Debug.Log((object)("Hud active " + ((Object)__instance).name));
}
}
}
[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_001e: 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 class ContainerFinder
{
public static List<Container> FindNearbyContainers(Vector3 position, float radius)
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: 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 val in array2)
{
Debug.Log((object)(((Object)val).name ?? ""));
Container component = ((Component)val).GetComponent<Container>();
ContainerFilterService component2 = ((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]);
}
}
}
}
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
}
[CompilerGenerated]
private sealed class <HighlightRoutine>d__23 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public WearNTear wearTear;
private float <duration>5__1;
private int <iterations>5__2;
private int <i>5__3;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <HighlightRoutine>d__23(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<duration>5__1 = global::GrabMaterialsMod.GrabMaterialsMod.Instance.HighlightDuration.Value;
<iterations>5__2 = Mathf.CeilToInt(<duration>5__1 / 0.1f);
<i>5__3 = 0;
break;
case 1:
<>1__state = -1;
<i>5__3++;
break;
}
if (<i>5__3 < <iterations>5__2)
{
wearTear.Highlight();
<>2__current = (object)new WaitForSeconds(0.1f);
<>1__state = 1;
return true;
}
return false;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
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>
{
"boar_meat", "wolfmeat", "loxmeat", "deermeat", "serpentmeat", "fishraw", "haremeat", "seekermeat", "chickenmeat", "asksvintail",
"bonemawmeat", "chickenegg", "entrails"
};
private static readonly HashSet<string> CookedMeatNames = new HashSet<string> { "cooked_boar_meat", "cookedwolfmeat", "cookedloxmeat", "cookeddeermeat", "serpentmeatcooked", "cookedfish", "cookedharemeat", "cookedseekermeat", "cookedchickenmeat", "cookedbonemawmeat" };
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)
{
return self.Name().isMatch(matchString) || self.m_shared.m_name.isMatch(matchString) || self.LocalizedName().isMatch(matchString);
}
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_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Invalid comparison between Unknown and I4
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Invalid comparison between Unknown and I4
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Invalid comparison between Unknown and I4
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Invalid comparison between Unknown and I4
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Invalid comparison between Unknown and I4
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Invalid comparison between Unknown and I4
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Invalid comparison between Unknown and I4
//IL_011e: Unknown result type (might be due to invalid IL or missing references)
//IL_0300: Unknown result type (might be due to invalid IL or missing references)
//IL_0306: 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 (PlantNames.Contains(text) || text.Contains("Seed"))
{
return ItemCategory.Plant;
}
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 (RawMeatNames.Contains(text))
{
return ItemCategory.RawMeat;
}
if (CookedMeatNames.Contains(text))
{
return ItemCategory.CookedMeat;
}
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 ((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));
}
}
[IteratorStateMachine(typeof(<HighlightRoutine>d__23))]
private static IEnumerator HighlightRoutine(WearNTear wearTear)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <HighlightRoutine>d__23(0)
{
wearTear = wearTear
};
}
public static int GrabItemFromContainer(this Container container, string name, int count)
{
Debug.Log((object)$"looking for {count} {name} in {container} {((Object)container).GetInstanceID()}");
Player localPlayer = Player.m_localPlayer;
Inventory inventory = ((Humanoid)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;
}
}
Debug.Log((object)$"grabbed a total of {num} {name} from {container} {((Object)container).GetInstanceID()}");
if (num > 0)
{
container.Highlight();
}
return num;
}
public static bool StoreItemInContainer(this Container container, ItemData item)
{
Player localPlayer = Player.m_localPlayer;
Inventory inventory = ((Humanoid)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;
Player localPlayer = Player.m_localPlayer;
Inventory inventory2 = ((Humanoid)localPlayer).GetInventory();
foreach (ItemData allItem in inventory2.GetAllItems())
{
num += allItem.Count();
}
return num;
}
public static int CountItems(this Inventory inventory, string name)
{
int num = 0;
Player localPlayer = Player.m_localPlayer;
Inventory inventory2 = ((Humanoid)localPlayer).GetInventory();
foreach (ItemData allItem in inventory2.GetAllItems())
{
if (allItem.Name() == name)
{
num += allItem.Count();
}
}
return num;
}
}
}