using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Valheim Item Vacuum")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Valheim Item Vacuum")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a0ea8960-687f-4860-821c-01a3e40c5dd8")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MasterVacuumMod;
[BepInPlugin("com.peep.mastervacuum", "Item Vacuum", "1.1.3")]
public class MasterVacuumPlugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(ZNet), "Awake")]
private static class ZNet_Awake_Patch
{
private static void Postfix(ZNet __instance)
{
ZRoutedRpc.instance.Register<long, uint, ZPackage>("MasterVacuum_ConfirmRemoval", (Action<long, long, uint, ZPackage>)Instance.RPC_MasterVacuum_ConfirmRemoval);
}
}
[HarmonyPatch(typeof(Terminal), "InitTerminal")]
private static class ConsolePatch
{
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
public static readonly <>c <>9 = new <>c();
public static Func<string, bool> <>9__0_1;
public static ConsoleEvent <>9__0_0;
internal void <Postfix>b__0_0(ConsoleEventArgs args)
{
string text = ZoneSystem.instance.m_globalKeysValues.Keys.FirstOrDefault((string k) => k.StartsWith("mastervacuum_zdoid"));
if (!string.IsNullOrEmpty(text))
{
ZoneSystem.instance.RemoveGlobalKey(text);
args.Context.AddString("Master Vacuum key cleared.");
}
else
{
args.Context.AddString("No vacuum key found.");
}
}
internal bool <Postfix>b__0_1(string k)
{
return k.StartsWith("mastervacuum_zdoid");
}
}
private static void Postfix(Terminal __instance)
{
//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
object obj = <>c.<>9__0_0;
if (obj == null)
{
ConsoleEvent val = delegate(ConsoleEventArgs args)
{
string text = ZoneSystem.instance.m_globalKeysValues.Keys.FirstOrDefault((string k) => k.StartsWith("mastervacuum_zdoid"));
if (!string.IsNullOrEmpty(text))
{
ZoneSystem.instance.RemoveGlobalKey(text);
args.Context.AddString("Master Vacuum key cleared.");
}
else
{
args.Context.AddString("No vacuum key found.");
}
};
<>c.<>9__0_0 = val;
obj = (object)val;
}
new ConsoleCommand("resetvacuum", "Manual wipe of the vacuum global key.", (ConsoleEvent)obj, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
}
}
[HarmonyPatch(typeof(Container), "Awake")]
private static class Container_Track_Patch
{
private static void Postfix(Container __instance)
{
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
ZNetView nview = Traverse.Create((object)__instance).Field("m_nview").GetValue<ZNetView>();
if ((Object)(object)nview == (Object)null || !nview.IsValid())
{
return;
}
nview.Register("OnInventoryChanged", (Action<long>)delegate
{
});
nview.Register<long, uint, ZPackage>("MasterVacuum_RequestAdd", (Action<long, long, uint, ZPackage>)delegate(long sender, long vacUserId, uint vacId, ZPackage pkg)
{
//IL_002c: 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_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Expected O, but got Unknown
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_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_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Expected O, but got Unknown
if (nview.IsOwner())
{
Inventory inventory3 = __instance.GetInventory();
Inventory val2 = new Inventory("temp", (Sprite)null, inventory3.GetWidth(), inventory3.GetHeight());
val2.Load(pkg);
Inventory val3 = new Inventory("success", (Sprite)null, inventory3.GetWidth(), inventory3.GetHeight());
bool flag = false;
foreach (ItemData allItem in val2.GetAllItems())
{
if (inventory3.CanAddItem(allItem, -1))
{
inventory3.AddItem(allItem);
val3.AddItem(allItem.Clone());
flag = true;
}
else
{
ItemDrop.DropItem(allItem, allItem.m_stack, ((Component)__instance).transform.position + Vector3.up, Quaternion.identity);
}
}
if (flag)
{
nview.InvokeRPC(ZNetView.Everybody, "OnInventoryChanged", Array.Empty<object>());
if (vacUserId != 0L)
{
ZPackage val4 = new ZPackage();
val3.Save(val4);
ZRoutedRpc.instance.InvokeRoutedRPC(sender, "MasterVacuum_ConfirmRemoval", new object[3] { vacUserId, vacId, val4 });
}
}
}
});
nview.Register<ZPackage>("MasterVacuum_RequestRemove", (Action<long, ZPackage>)delegate(long uid, ZPackage pkg)
{
//IL_002c: 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)
if (!nview.IsOwner())
{
return;
}
Inventory inventory2 = __instance.GetInventory();
Inventory val = new Inventory("temp", (Sprite)null, inventory2.GetWidth(), inventory2.GetHeight());
val.Load(pkg);
foreach (ItemData allItem2 in val.GetAllItems())
{
inventory2.RemoveItem(allItem2.m_shared.m_name, allItem2.m_stack, -1, true);
}
});
if (!TrackedContainers.Contains(__instance))
{
TrackedContainers.Add(__instance);
}
Inventory inventory = __instance.GetInventory();
nview.GetZDO().Set(HashWidth, inventory.GetWidth(), false);
nview.GetZDO().Set(HashHeight, inventory.GetHeight(), false);
if (((Object)__instance).name.Contains("Item_Vacuum") && ZNet.instance.IsServer())
{
ZDOID uid2 = nview.GetZDO().m_uid;
ZoneSystem.instance.SetGlobalKey(string.Format("{0}={1}:{2}", "mastervacuum_zdoid", ((ZDOID)(ref uid2)).UserID, ((ZDOID)(ref uid2)).ID));
}
}
}
[HarmonyPatch(typeof(ZoneSystem), "Start")]
private static class ZoneSystem_Start_Persistent_Patch
{
private static void Postfix()
{
//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)
if (ZNet.instance.IsServer() && !ZoneSystem.instance.m_globalKeysValues.Keys.Any((string k) => k.StartsWith("mastervacuum_zdoid=")))
{
logger.LogInfo((object)"Server started: No Master Vacuum link found. Scanning world database...");
string text = "Item_Vacuum";
List<ZDO> list = new List<ZDO>();
int num = 0;
while (!ZDOMan.instance.GetAllZDOsWithPrefabIterative(text, list, ref num))
{
}
if (list.Count > 0)
{
ZDOID uid = list[0].m_uid;
string globalKey = $"mastervacuum_zdoid={((ZDOID)(ref uid)).UserID}:{((ZDOID)(ref uid)).ID}";
ZoneSystem.instance.SetGlobalKey(globalKey);
logger.LogInfo((object)$"Successfully restored Master Vacuum Link: {((ZDOID)(ref uid)).UserID}:{((ZDOID)(ref uid)).ID}");
}
else
{
logger.LogInfo((object)"No Master Vacuum objects found in the world.");
}
}
}
}
[HarmonyPatch(typeof(Container), "OnDestroyed")]
private static class Container_Cleanup_Patch
{
private static void Prefix(Container __instance)
{
TrackedContainers.RemoveAll((Container c) => (Object)(object)c == (Object)null);
if (((Object)__instance).name.Contains("Item_Vacuum") && ZNet.instance.IsServer())
{
string text = ZoneSystem.instance.m_globalKeysValues.Keys.FirstOrDefault((string k) => k.StartsWith("mastervacuum_zdoid"));
if (!string.IsNullOrEmpty(text))
{
ZoneSystem.instance.RemoveGlobalKey(text);
}
}
}
}
[HarmonyPatch(typeof(ItemDrop), "SlowUpdate")]
private static class ItemDrop_SlowUpdate_Patch
{
private static Dictionary<ZDOID, float> m_attemptTracker = new Dictionary<ZDOID, float>();
private static void Postfix(ItemDrop __instance, ZNetView ___m_nview)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: 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_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_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Expected O, but got Unknown
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)___m_nview == (Object)null || !___m_nview.IsValid() || !___m_nview.IsOwner())
{
return;
}
ZDOID uid = ___m_nview.GetZDO().m_uid;
float time = Time.time;
if ((!m_attemptTracker.TryGetValue(uid, out var value) || !(time - value < 10f)) && IsItemTypeAllowed(__instance.m_itemData.m_shared.m_itemType))
{
string text = ZoneSystem.instance.m_globalKeysValues.Keys.FirstOrDefault((string k) => k.StartsWith("mastervacuum_zdoid"));
if (!string.IsNullOrEmpty(text))
{
ZDOID val = ParseZDOID(text.Split(new char[1] { '=' })[1]);
m_attemptTracker[uid] = time;
Inventory val2 = new Inventory("temp", (Sprite)null, 1, 1);
val2.AddItem(__instance.m_itemData.Clone());
ZPackage val3 = new ZPackage();
val2.Save(val3);
ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "MasterVacuum_RequestIntake", new object[3] { val, val3, uid });
}
}
}
}
[HarmonyPatch(typeof(Player), "UpdatePlacement")]
private static class Placement_Blocker_Patch
{
private static bool Prefix(Player __instance)
{
//IL_008a: 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_0095: Unknown result type (might be due to invalid IL or missing references)
GameObject value = Traverse.Create((object)__instance).Field("m_placementGhost").GetValue<GameObject>();
if ((Object)(object)value == (Object)null || !((Object)value).name.Contains("Item_Vacuum"))
{
return true;
}
string text = ZoneSystem.instance.m_globalKeysValues.Keys.FirstOrDefault((string k) => k.StartsWith("mastervacuum_zdoid"));
if (!string.IsNullOrEmpty(text))
{
string[] array = text.Split(new char[1] { '=' });
if (array.Length >= 2)
{
ZDOID val = ParseZDOID(array[1]);
if (ZDOMan.instance.GetZDO(val) == null)
{
ZoneSystem.instance.RemoveGlobalKey(text);
return true;
}
}
SetPlacementGhostValidDelegate?.Invoke(__instance, arg2: false);
if (ZInput.GetButtonDown("Attack") || ZInput.GetButton("Attack"))
{
((Character)__instance).Message((MessageType)2, "A Master Vacuum already exists!", 0, (Sprite)null);
return false;
}
}
return true;
}
}
[HarmonyPatch(typeof(ZNetScene), "Awake")]
public static class ZNetSceneAwakePatch_Post
{
public static void Postfix(ZNetScene __instance, Dictionary<int, GameObject> ___m_namedPrefabs)
{
//IL_00d8: 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)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Expected O, but got Unknown
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Expected O, but got Unknown
ZRoutedRpc.instance.Register<ZDOID, ZPackage, ZDOID>("MasterVacuum_RequestIntake", (Action<long, ZDOID, ZPackage, ZDOID>)Instance.RPC_MasterVacuum_RequestIntake);
ZRoutedRpc.instance.Register<ZDOID>("MasterVacuum_ConfirmIntake", (Action<long, ZDOID>)Instance.RPC_MasterVacuum_ConfirmIntake);
if ((Object)(object)vacuumPrefab != (Object)null)
{
if (!__instance.m_prefabs.Contains(vacuumPrefab))
{
__instance.m_prefabs.Add(vacuumPrefab);
}
int stableHashCode = StringExtensionMethods.GetStableHashCode(((Object)vacuumPrefab).name);
if (!___m_namedPrefabs.ContainsKey(stableHashCode))
{
___m_namedPrefabs[stableHashCode] = vacuumPrefab;
}
Piece component = vacuumPrefab.GetComponent<Piece>();
GameObject prefab = __instance.GetPrefab("vfx_Place_chest");
GameObject prefab2 = __instance.GetPrefab("sfx_build_hammer_wood");
if ((Object)(object)component != (Object)null && (Object)(object)prefab != (Object)null)
{
component.m_placeEffect.m_effectPrefabs = (EffectData[])(object)new EffectData[2]
{
new EffectData
{
m_prefab = prefab,
m_enabled = true
},
new EffectData
{
m_prefab = prefab2,
m_enabled = true
}
};
}
}
}
}
[HarmonyPatch(typeof(ZNet), "OnNewConnection")]
private static class RegisterAndSyncRPC
{
private static void Postfix(ZNet __instance, ZNetPeer peer)
{
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Expected O, but got Unknown
peer.m_rpc.Register<ZPackage>("MasterVacuum_RPC_SyncConfig", (Action<ZRpc, ZPackage>)RPC_MasterVacuum_SyncConfig);
if (ZNet.instance.IsServer())
{
logger.LogInfo((object)("Sending config to peer: " + peer.m_playerName));
ZPackage val = new ZPackage();
val.Write(PickUpMaterials.Value);
val.Write(PickUpConsumables.Value);
val.Write(PickUpTrophies.Value);
val.Write(PickUpEquipment.Value);
val.Write(PickUpMisc.Value);
peer.m_rpc.Invoke("MasterVacuum_RPC_SyncConfig", new object[1] { val });
}
}
private static void RPC_MasterVacuum_SyncConfig(ZRpc rpc, ZPackage pkg)
{
if (!ZNet.instance.IsServer())
{
logger.LogInfo((object)"Received config from server. Applying settings...");
PickUpMaterials.Value = pkg.ReadBool();
PickUpConsumables.Value = pkg.ReadBool();
PickUpTrophies.Value = pkg.ReadBool();
PickUpEquipment.Value = pkg.ReadBool();
PickUpMisc.Value = pkg.ReadBool();
}
}
}
[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
public static class ObjectDB_Patch
{
public static void Postfix(ObjectDB __instance)
{
GameObject itemPrefab = __instance.GetItemPrefab("Hammer");
if ((Object)(object)itemPrefab != (Object)null)
{
PieceTable buildPieces = itemPrefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_buildPieces;
if ((Object)(object)vacuumPrefab != (Object)null && !buildPieces.m_pieces.Contains(vacuumPrefab))
{
buildPieces.m_pieces.Add(vacuumPrefab);
}
}
}
}
public static MasterVacuumPlugin Instance;
private const string ModGUID = "com.peep.mastervacuum";
private const string ModName = "Item Vacuum";
private const string ModVersion = "1.1.3";
public static ManualLogSource logger;
private readonly Harmony harmony = new Harmony("com.peep.mastervacuum");
private static GameObject vacuumPrefab;
private static MethodInfo _findObjectsMethod;
private static float m_distributeTimer = 0f;
private const string GlobalKeyName = "mastervacuum_zdoid";
public static readonly int HashWidth = StringExtensionMethods.GetStableHashCode("mastervac_width");
public static readonly int HashHeight = StringExtensionMethods.GetStableHashCode("mastervac_height");
public static readonly List<Container> TrackedContainers = new List<Container>();
private static Action<Player, bool> SetPlacementGhostValidDelegate;
public static ConfigEntry<bool> PickUpMaterials;
public static ConfigEntry<bool> PickUpConsumables;
public static ConfigEntry<bool> PickUpTrophies;
public static ConfigEntry<bool> PickUpEquipment;
public static ConfigEntry<bool> PickUpMisc;
public void Awake()
{
Instance = this;
logger = ((BaseUnityPlugin)this).Logger;
PickUpMaterials = ((BaseUnityPlugin)this).Config.Bind<bool>("Filters", "PickUpMaterials", true, "Pick up items like wood, stone, and ores.");
PickUpConsumables = ((BaseUnityPlugin)this).Config.Bind<bool>("Filters", "PickUpConsumables", true, "Pick up food and potions.");
PickUpTrophies = ((BaseUnityPlugin)this).Config.Bind<bool>("Filters", "PickUpTrophies", true, "Pick up monster trophies.");
PickUpEquipment = ((BaseUnityPlugin)this).Config.Bind<bool>("Filters", "PickUpEquipment", false, "Pick up weapons and armor.");
PickUpMisc = ((BaseUnityPlugin)this).Config.Bind<bool>("Filters", "PickUpMisc", false, "Pick up miscellaneous items.");
LoadAssets();
_findObjectsMethod = typeof(ZDOMan).GetMethod("FindObjects", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[2]
{
typeof(Vector2i),
typeof(List<ZDO>)
}, null);
SetPlacementGhostValidDelegate = AccessTools.MethodDelegate<Action<Player, bool>>(AccessTools.Method(typeof(Player), "SetPlacementGhostValid", (Type[])null, (Type[])null), (object)null, true);
harmony.PatchAll();
logger.LogInfo((object)"Master Vacuum: Two-Way Handshake System Initialized.");
}
private void Update()
{
if (!((Object)(object)ZNet.instance == (Object)null))
{
m_distributeTimer += Time.deltaTime;
if (m_distributeTimer >= 5f)
{
m_distributeTimer = 0f;
ProcessVacuumCycle();
}
}
}
private void LoadAssets()
{
Assembly executingAssembly = Assembly.GetExecutingAssembly();
string text = executingAssembly.GetManifestResourceNames().FirstOrDefault((string str) => str.EndsWith("item_vacuum"));
if (text != null)
{
using (Stream stream = executingAssembly.GetManifestResourceStream(text))
{
AssetBundle obj = AssetBundle.LoadFromStream(stream);
vacuumPrefab = obj.LoadAsset<GameObject>("Item_Vacuum");
obj.Unload(false);
}
}
}
private void ProcessVacuumCycle()
{
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: 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_00ce: Expected O, but got Unknown
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_0397: Unknown result type (might be due to invalid IL or missing references)
//IL_039e: Expected O, but got Unknown
//IL_0278: Unknown result type (might be due to invalid IL or missing references)
//IL_027f: Expected O, but got Unknown
//IL_050c: Unknown result type (might be due to invalid IL or missing references)
//IL_0513: Expected O, but got Unknown
//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
//IL_02fb: Expected O, but got Unknown
string text = ZoneSystem.instance.m_globalKeysValues.Keys.FirstOrDefault((string k) => k.StartsWith("mastervacuum_zdoid"));
if (string.IsNullOrEmpty(text))
{
return;
}
string[] array = text.Split(new char[1] { '=' });
ZDOID masterID = ParseZDOID(array[1]);
ZDO zDO = ZDOMan.instance.GetZDO(masterID);
if (zDO == null)
{
ZoneSystem.instance.RemoveGlobalKey(array[0]);
return;
}
int @int = zDO.GetInt(HashWidth, 8);
int int2 = zDO.GetInt(HashHeight, 5);
Inventory inventoryFromZDO = GetInventoryFromZDO(zDO, @int, int2);
if (inventoryFromZDO.GetAllItems().Count == 0)
{
return;
}
Inventory val = new Inventory("tracker", (Sprite)null, @int, int2);
Container val2 = TrackedContainers.Find(delegate(Container c)
{
//IL_001a: 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)
if ((Object)(object)c != (Object)null)
{
ZNetView component3 = ((Component)c).GetComponent<ZNetView>();
if (component3 == null)
{
return false;
}
return component3.GetZDO().m_uid == masterID;
}
return false;
});
List<ZDO> list = FindAllZDOsInRange(zDO.GetPosition(), 30f, masterID);
bool flag = false;
foreach (ZDO containerZDO in list)
{
if (containerZDO.m_uid == masterID)
{
continue;
}
Container val3 = TrackedContainers.Find(delegate(Container c)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: 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_004c: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)c != (Object)null)
{
ZNetView component2 = ((Component)c).GetComponent<ZNetView>();
ZDOID? val8 = ((component2 != null) ? new ZDOID?(component2.GetZDO().m_uid) : null);
ZDOID uid = containerZDO.m_uid;
if (!val8.HasValue)
{
return false;
}
return val8.GetValueOrDefault() == uid;
}
return false;
});
if ((Object)(object)val3 != (Object)null)
{
ZNetView component = ((Component)val3).GetComponent<ZNetView>();
Inventory inventory = val3.GetInventory();
if (component.IsOwner())
{
bool flag2 = false;
foreach (ItemData item in inventoryFromZDO.GetAllItems().ToList())
{
if (inventory.HaveItem(item.m_shared.m_name, true) && inventory.CanAddItem(item, -1))
{
inventory.AddItem(item);
inventoryFromZDO.RemoveItem(item);
if ((Object)(object)val2 != (Object)null && ((Component)val2).GetComponent<ZNetView>().IsOwner())
{
val2.GetInventory().RemoveItem(item.m_shared.m_name, item.m_stack, -1, true);
}
else if ((Object)(object)val2 != (Object)null)
{
val.AddItem(item);
}
flag = true;
flag2 = true;
}
}
if (flag2)
{
component.InvokeRPC(ZNetView.Everybody, "OnInventoryChanged", Array.Empty<object>());
}
}
else
{
Inventory val4 = new Inventory("temp", (Sprite)null, @int, int2);
foreach (ItemData item2 in inventoryFromZDO.GetAllItems().ToList())
{
if (inventory.HaveItem(item2.m_shared.m_name, true) && inventory.CanAddItem(item2, -1))
{
val4.AddItem(item2);
}
}
if (val4.GetAllItems().Count > 0)
{
ZPackage val5 = new ZPackage();
val4.Save(val5);
component.InvokeRPC(component.GetZDO().GetOwner(), "MasterVacuum_RequestAdd", new object[3]
{
((ZDOID)(ref masterID)).UserID,
((ZDOID)(ref masterID)).ID,
val5
});
}
}
}
else
{
int int3 = containerZDO.GetInt(HashWidth, 5);
int int4 = containerZDO.GetInt(HashHeight, 2);
Inventory inventoryFromZDO2 = GetInventoryFromZDO(containerZDO, int3, int4);
Inventory val6 = new Inventory("success", (Sprite)null, @int, int2);
bool flag3 = false;
foreach (ItemData item3 in inventoryFromZDO.GetAllItems().ToList())
{
if (inventoryFromZDO2.HaveItem(item3.m_shared.m_name, true) && inventoryFromZDO2.CanAddItem(item3, -1))
{
inventoryFromZDO2.AddItem(item3);
val6.AddItem(item3);
flag3 = true;
}
}
if (flag3)
{
SaveInventoryToZDO(inventoryFromZDO2, containerZDO);
foreach (ItemData allItem in val6.GetAllItems())
{
inventoryFromZDO.RemoveItem(allItem);
if ((Object)(object)val2 != (Object)null && ((Component)val2).GetComponent<ZNetView>().IsOwner())
{
val2.GetInventory().RemoveItem(allItem.m_shared.m_name, allItem.m_stack, -1, true);
}
else if ((Object)(object)val2 != (Object)null)
{
val.AddItem(allItem);
}
}
flag = true;
}
}
if (inventoryFromZDO.GetAllItems().Count == 0)
{
break;
}
}
if (flag)
{
if ((Object)(object)val2 != (Object)null && !((Component)val2).GetComponent<ZNetView>().IsOwner() && val.GetAllItems().Count > 0)
{
ZPackage val7 = new ZPackage();
val.Save(val7);
((Component)val2).GetComponent<ZNetView>().InvokeRPC(((Component)val2).GetComponent<ZNetView>().GetZDO().GetOwner(), "MasterVacuum_RequestRemove", new object[1] { val7 });
}
else if (zDO.IsOwner())
{
SaveInventoryToZDO(inventoryFromZDO, zDO);
}
}
}
public void RPC_MasterVacuum_ConfirmRemoval(long sender, long vacUserId, uint vacId, ZPackage pkg)
{
//IL_0009: 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_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Expected O, but got Unknown
ZDOID vacuumID = new ZDOID(vacUserId, vacId);
ZDO zDO = ZDOMan.instance.GetZDO(vacuumID);
if (zDO == null || !zDO.IsOwner())
{
return;
}
int @int = zDO.GetInt(HashWidth, 8);
int int2 = zDO.GetInt(HashHeight, 5);
Inventory val = new Inventory("temp", (Sprite)null, @int, int2);
val.Load(pkg);
Container val2 = TrackedContainers.Find(delegate(Container c)
{
//IL_001a: 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)
if ((Object)(object)c != (Object)null)
{
ZNetView component = ((Component)c).GetComponent<ZNetView>();
if (component == null)
{
return false;
}
return component.GetZDO().m_uid == vacuumID;
}
return false;
});
if (zDO.IsOwner())
{
Inventory inventoryFromZDO = GetInventoryFromZDO(zDO, @int, int2);
bool flag = false;
foreach (ItemData allItem in val.GetAllItems())
{
if (inventoryFromZDO.HaveItem(allItem.m_shared.m_name, true))
{
inventoryFromZDO.RemoveItem(allItem.m_shared.m_name, allItem.m_stack, -1, true);
flag = true;
}
if ((Object)(object)val2 != (Object)null && ((Component)val2).GetComponent<ZNetView>().IsOwner())
{
val2.GetInventory().RemoveItem(allItem.m_shared.m_name, allItem.m_stack, -1, true);
}
}
if (flag)
{
SaveInventoryToZDO(inventoryFromZDO, zDO);
}
}
else if ((Object)(object)val2 != (Object)null)
{
((Component)val2).GetComponent<ZNetView>().InvokeRPC(zDO.GetOwner(), "MasterVacuum_RequestRemove", new object[1] { pkg });
}
}
public Inventory GetInventoryFromZDO(ZDO zdo, int width, int height)
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Expected O, but got Unknown
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Expected O, but got Unknown
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Expected O, but got Unknown
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Expected O, but got Unknown
foreach (Container trackedContainer in TrackedContainers)
{
if (!((Object)(object)trackedContainer != (Object)null))
{
continue;
}
ZNetView val = (ZNetView)typeof(Container).GetField("m_nview", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(trackedContainer);
if (!((Object)(object)val != (Object)null) || !(val.GetZDO().m_uid == zdo.m_uid))
{
continue;
}
Inventory inventory = trackedContainer.GetInventory();
Inventory val2 = new Inventory(inventory.GetName(), inventory.GetBkg(), width, height);
foreach (ItemData allItem in inventory.GetAllItems())
{
val2.AddItem(allItem.Clone());
}
return val2;
}
Inventory val3 = new Inventory("OfflineInventory", (Sprite)null, width, height);
string @string = zdo.GetString(ZDOVars.s_items, "");
if (!string.IsNullOrEmpty(@string))
{
ZPackage val4 = new ZPackage(@string);
val3.Load(val4);
}
return val3;
}
public void SaveInventoryToZDO(Inventory inv, ZDO zdo)
{
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Expected O, but got Unknown
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
if (zdo == null || !zdo.IsValid())
{
return;
}
if (zdo.GetOwner() == 0L)
{
zdo.SetOwner(ZDOMan.GetSessionID());
}
if (!zdo.IsOwner())
{
return;
}
zdo.Set(HashWidth, inv.GetWidth(), false);
zdo.Set(HashHeight, inv.GetHeight(), false);
ZPackage val = new ZPackage();
inv.Save(val);
zdo.Set(ZDOVars.s_items, val.GetBase64());
uint dataRevision = zdo.DataRevision;
zdo.DataRevision = dataRevision + 1;
foreach (Container trackedContainer in TrackedContainers)
{
if (!((Object)(object)trackedContainer == (Object)null))
{
ZNetView value = Traverse.Create((object)trackedContainer).Field("m_nview").GetValue<ZNetView>();
if ((Object)(object)value != (Object)null && value.IsValid() && value.GetZDO().m_uid == zdo.m_uid)
{
value.InvokeRPC(ZNetView.Everybody, "OnInventoryChanged", Array.Empty<object>());
break;
}
}
}
}
private List<ZDO> FindAllZDOsInRange(Vector3 center, float radius, ZDOID ignore)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: 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_008d: 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_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
List<ZDO> list = new List<ZDO>();
float num = radius * radius;
Vector2i zone = ZoneSystem.GetZone(center);
Vector2i val = default(Vector2i);
for (int i = -1; i <= 1; i++)
{
for (int j = -1; j <= 1; j++)
{
((Vector2i)(ref val))..ctor(zone.x + i, zone.y + j);
List<ZDO> list2 = new List<ZDO>();
_findObjectsMethod?.Invoke(ZDOMan.instance, new object[2] { val, list2 });
if (list2 == null)
{
continue;
}
foreach (ZDO item in list2)
{
if (item != null && !(item.m_uid == ignore) && Vector3.SqrMagnitude(item.GetPosition() - center) <= num)
{
list.Add(item);
}
}
}
}
return list;
}
public static ZDOID ParseZDOID(string id)
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
string[] array = id.Split(new char[1] { ':' });
if (array.Length == 2)
{
return new ZDOID(long.Parse(array[0]), uint.Parse(array[1]));
}
return ZDOID.None;
}
private static bool IsItemTypeAllowed(ItemType type)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Expected I4, but got Unknown
switch (type - 1)
{
case 0:
return PickUpMaterials.Value;
case 1:
return PickUpConsumables.Value;
case 12:
return PickUpTrophies.Value;
case 2:
case 3:
case 4:
case 5:
case 6:
case 10:
case 13:
return PickUpEquipment.Value;
case 15:
return PickUpMisc.Value;
default:
return true;
}
}
public void RPC_MasterVacuum_RequestIntake(long sender, ZDOID vacuumID, ZPackage itemPkg, ZDOID originalItemID)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
if (!ZNet.instance.IsServer())
{
return;
}
ZDO zDO = ZDOMan.instance.GetZDO(vacuumID);
if (zDO != null)
{
if (zDO.GetOwner() != ZDOMan.GetSessionID())
{
zDO.SetOwner(ZDOMan.GetSessionID());
}
int @int = zDO.GetInt(HashWidth, 8);
int int2 = zDO.GetInt(HashHeight, 5);
Inventory inventoryFromZDO = GetInventoryFromZDO(zDO, @int, int2);
Inventory val = new Inventory("temp", (Sprite)null, 1, 1);
val.Load(itemPkg);
ItemData itemAt = val.GetItemAt(0, 0);
if (itemAt != null && inventoryFromZDO.CanAddItem(itemAt, -1))
{
inventoryFromZDO.AddItem(itemAt);
SaveInventoryToZDO(inventoryFromZDO, zDO);
ZRoutedRpc.instance.InvokeRoutedRPC(sender, "MasterVacuum_ConfirmIntake", new object[1] { originalItemID });
}
}
}
public void RPC_MasterVacuum_ConfirmIntake(long sender, ZDOID itemID)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
GameObject val = ZNetScene.instance.FindInstance(itemID);
if ((Object)(object)val != (Object)null)
{
ZNetView component = val.GetComponent<ZNetView>();
if ((Object)(object)component != (Object)null && component.IsValid() && component.IsOwner())
{
component.Destroy();
}
}
}
}