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 Runebound Storage v0.16.0
plugins/RuneboundStorage/RuneLectern.dll
Decompiled 8 hours 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.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security.Cryptography; using System.Text; using System.Threading; using BepInEx; using BepInEx.Bootstrap; using HarmonyLib; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using Splatform; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("RuneLectern")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+4c4da4f86bcab21115802b4458213194bf2c8c2a")] [assembly: AssemblyProduct("RuneLectern")] [assembly: AssemblyTitle("RuneLectern")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace RuneStorage { internal static class ArcaneMaterials { private static readonly Color InactiveCrystal = new Color(0.48f, 0.48f, 0.48f); private static readonly Material[][] Finishes = new Material[8][]; private static readonly Material[][] RelayFinishes = new Material[2][]; internal static Material[] RelayFinish(bool lit) { //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: Expected O, but got Unknown //IL_0053: 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_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) int num = (lit ? 1 : 0); if (RelayFinishes[num] != null) { return RelayFinishes[num]; } Material[] array = Finish(4, lit: false); Material val = new Material(array[2]) { name = "Relay crystal" }; Color val2 = default(Color); ((Color)(ref val2))..ctor(0.18f, 0.91f, 0.77f); val.color = (lit ? val2 : InactiveCrystal); val.SetColor("_EmissionColor", lit ? (val2 * 1.2f) : Color.black); return RelayFinishes[num] = (Material[])(object)new Material[4] { array[0], array[1], val, val }; } internal static Material[] Finish(int tier, bool lit) { int num = (tier - 1) * 2 + (lit ? 1 : 0); return Finishes[num] ?? (Finishes[num] = Create(tier, lit)); } private static Material[] Create(int tier, bool lit) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0089: 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) //IL_00b3: 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_012e: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: 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_0171: Unknown result type (might be due to invalid IL or missing references) //IL_015b: 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_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) Material template = ((Renderer)PrefabManager.Instance.GetPrefab("Bronze").GetComponentInChildren<MeshRenderer>(true)).sharedMaterial; Material val = Surface("Carved heartwood", new Color(0.34f, 0.17f, 0.075f), 0.03f); if (tier == 3) { val = Surface("Black metal shell", new Color(0.13f, 0.17f, 0.19f), 0.78f); } if (tier == 4) { val = Surface("Hewn grausten", new Color(0.56f, 0.53f, 0.56f), 0.04f); } Material val2 = ((tier >= 2) ? Surface("Forged iron", new Color(0.31f, 0.34f, 0.32f), 0.65f) : Surface("Resin binding", new Color(0.55f, 0.32f, 0.13f), 0.08f)); if (tier == 3) { val2 = Surface("Burnished black metal", new Color(0.28f, 0.35f, 0.43f), 0.72f); } if (tier == 4) { val2 = Surface("Chiseled stone edge", new Color(0.34f, 0.32f, 0.37f), 0.1f); } Color val3 = (Color)(tier switch { 2 => new Color(0.22f, 0.95f, 0.34f), 3 => new Color(0.12f, 0.43f, 1f), 4 => new Color(0.74f, 0.32f, 1f), _ => new Color(1f, 0.54f, 0.12f), }); Material val4 = Surface("Set shard", lit ? val3 : InactiveCrystal, 0.18f); val4.EnableKeyword("_EMISSION"); val4.SetColor("_EmissionColor", lit ? (val3 * 0.9f) : Color.black); return (Material[])(object)new Material[4] { val, val2, val4, val4 }; Material Surface(string name, Color color, float metal) { //IL_0006: 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_0012: 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_0019: 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_0031: Expected O, but got Unknown Material val5 = new Material(template) { name = name, color = color, mainTexture = (Texture)(object)Texture2D.whiteTexture }; val5.SetFloat("_Metallic", metal); return val5; } } } internal sealed class BackpackTransferOverlay { private sealed class Slot { private readonly Image icon; private readonly TMP_Text quantity; private readonly RectTransform root; internal Slot(InventoryElement cell) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Expected O, but got Unknown //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008c: 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_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("Runebound pending delivery", new Type[2] { typeof(RectTransform), typeof(CanvasGroup) }); root = (RectTransform)val.transform; ((Transform)root).SetParent(((Component)cell).transform, false); root.anchorMin = Vector2.zero; root.anchorMax = Vector2.one; root.offsetMin = (root.offsetMax = Vector2.zero); CanvasGroup component = val.GetComponent<CanvasGroup>(); component.interactable = false; component.blocksRaycasts = false; icon = new GameObject("Pending item", new Type[2] { typeof(RectTransform), typeof(Image) }).GetComponent<Image>(); ((Component)icon).transform.SetParent((Transform)(object)root, false); icon.preserveAspect = true; ((Graphic)icon).raycastTarget = false; ((Graphic)icon).color = new Color(1f, 1f, 1f, 0.5f); quantity = Object.Instantiate<TMP_Text>(cell.m_amount, (Transform)(object)root, false); ((Component)quantity).gameObject.SetActive(true); ((Behaviour)quantity).enabled = true; ((Graphic)quantity).raycastTarget = false; ((Graphic)quantity).color = new Color(1f, 0.84f, 0.49f); quantity.enableAutoSizing = true; quantity.fontSizeMin = 9f; quantity.fontSizeMax = cell.m_amount.fontSize; } internal void Draw(Sprite sprite, int amount, bool occupied) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_0095: 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_00be: 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) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) icon.sprite = sprite; RectTransform rectTransform = ((Graphic)icon).rectTransform; rectTransform.anchorMin = (occupied ? new Vector2(0.04f, 0.6f) : new Vector2(0.1f, 0.1f)); rectTransform.anchorMax = (occupied ? new Vector2(0.38f, 0.94f) : new Vector2(0.9f, 0.9f)); Vector2 offsetMin = (rectTransform.offsetMax = Vector2.zero); rectTransform.offsetMin = offsetMin; RectTransform rectTransform2 = quantity.rectTransform; rectTransform2.anchorMin = (occupied ? new Vector2(0.36f, 0.6f) : new Vector2(0.04f, 0.03f)); rectTransform2.anchorMax = (occupied ? new Vector2(0.96f, 0.96f) : new Vector2(0.96f, 0.4f)); offsetMin = (rectTransform2.offsetMax = Vector2.zero); rectTransform2.offsetMin = offsetMin; quantity.alignment = (TextAlignmentOptions)(occupied ? 4097 : 1028); quantity.text = "+" + amount; } internal void Remove() { if (Object.op_Implicit((Object)(object)root)) { ((Component)root).gameObject.SetActive(false); Object.Destroy((Object)(object)((Component)root).gameObject); } } } private static readonly FieldRef<InventoryGrid, List<InventoryElement>> Elements = AccessTools.FieldRefAccess<InventoryGrid, List<InventoryElement>>("m_elements"); private readonly InventoryGrid grid; private readonly Dictionary<InventoryElement, Slot> displayed = new Dictionary<InventoryElement, Slot>(); internal BackpackTransferOverlay(InventoryGrid grid) { this.grid = grid; } internal void Draw(IReadOnlyList<PendingMoveView> transfers) { //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) if (displayed.Count == 0 && transfers.Count == 0) { return; } ILookup<Vector2i, PendingMoveView> lookup = transfers.Where((PendingMoveView t) => t.Incoming > 0 && t.Item != null).ToLookup((PendingMoveView t) => t.Destination); List<InventoryElement> list = Elements.Invoke(grid); KeyValuePair<InventoryElement, Slot>[] array = displayed.ToArray(); for (int num = 0; num < array.Length; num++) { KeyValuePair<InventoryElement, Slot> keyValuePair = array[num]; if (!Object.op_Implicit((Object)(object)keyValuePair.Key) || !list.Contains(keyValuePair.Key) || !lookup.Contains(keyValuePair.Key.Position)) { keyValuePair.Value.Remove(); displayed.Remove(keyValuePair.Key); } } if (lookup.Count == 0) { return; } Inventory inventory = ((Humanoid)Player.m_localPlayer).GetInventory(); foreach (InventoryElement item in list) { Vector2i position = item.Position; if (lookup.Contains(position)) { IEnumerable<PendingMoveView> source = lookup[position]; PendingMoveView pendingMoveView = source.First(); if (!displayed.TryGetValue(item, out var value)) { value = (displayed[item] = new Slot(item)); } value.Draw(pendingMoveView.Item.GetIcon(), source.Sum((PendingMoveView t) => t.Incoming), inventory.GetItemAt(position.x, position.y) != null); } } } internal void Dispose() { foreach (Slot value in displayed.Values) { value.Remove(); } displayed.Clear(); } } [HarmonyPatch(typeof(ZNet), "OnNewConnection")] internal static class BrowseTransport { internal const int Protocol = 4; internal const string Request = "RuneLectern_Browse"; private const string Reply = "RuneLectern_BrowseReply"; internal const int MaxTracked = 64; private const int MaxBytes = 1048576; private static void Postfix(ZNet __instance, ZNetPeer peer) { if (__instance.IsServer()) { float nextRequest = 0f; peer.m_rpc.Register<ZPackage>("RuneLectern_Browse", (Action<ZRpc, ZPackage>)delegate(ZRpc rpc, ZPackage input) { if (!peer.IsReady() || __instance.GetPeer(peer.m_uid) != peer || rpc != peer.m_rpc || Time.unscaledTime < nextRequest || input.Size() > 3392) { return; } nextRequest = Time.unscaledTime + 0.1f; try { rpc.Invoke("RuneLectern_BrowseReply", new object[1] { Answer(peer.m_uid, input) }); } catch (EndOfStreamException) { } }); } else { if (!peer.m_server) { return; } peer.m_rpc.Register<ZPackage>("RuneLectern_BrowseReply", (Action<ZRpc, ZPackage>)delegate(ZRpc rpc, ZPackage result) { if (rpc == __instance.GetServerRPC() && result.Size() <= 1048576) { LecternPlugin.Instance.Browse?.Receive(result); } }); } } internal static ZPackage Answer(long sender, ZPackage input) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: 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_022e: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) int num = input.ReadInt(); int num2 = input.ReadInt(); ZDOID deskId = input.ReadZDOID(); ZDOID val = input.ReadZDOID(); bool flag = input.ReadBool(); int num3 = input.ReadInt(); Dictionary<ZDOID, List<string>> dictionary = new Dictionary<ZDOID, List<string>>(); ZPackage val2 = new ZPackage(); val2.Write(num2); if (num3 < 0 || num3 > 64) { val2.Write("Invalid transfer list."); return val2; } for (int i = 0; i < num3; i++) { ZDOID key = input.ReadZDOID(); string text = input.ReadString(); if (!Guid.TryParseExact(text, "N", out var _)) { val2.Write("Invalid transfer identifier."); return val2; } if (!dictionary.TryGetValue(key, out var value)) { value = (dictionary[key] = new List<string>()); } value.Add(text); } int tier; List<DedicatedChest> chests; if (num != 4) { val2.Write("Runebound Storage protocol mismatch. Install the server's build."); } else if (!DedicatedSnapshot.TryRead(sender, deskId, out tier, out chests, flag ? val : ZDOID.None)) { val2.Write("This Runekeeper is unavailable."); } else if (chests.Sum((DedicatedChest c) => (long)c.Items.Length + 64L) > 1048512 - 34 * num3) { val2.Write("This network exceeds the storage snapshot limit."); } else { val2.Write(""); val2.Write(tier); val2.Write(chests.Count); foreach (DedicatedChest item in chests) { val2.Write(item.Id); val2.Write(item.Width); val2.Write(item.Height); val2.Write(item.Items); List<string> value2; string[] array = (dictionary.TryGetValue(item.Id, out value2) ? MutationServer.Included(sender, ZDOMan.instance.GetZDO(item.Id), value2) : Array.Empty<string>()); val2.Write(array.Length); string[] array2 = array; foreach (string text2 in array2) { val2.Write(text2); } if (!flag && val != ZDOID.None && val == item.Id) { val2.Write(true); val2.Write(item.Position); val2.Write(item.Tier); } else { val2.Write(false); } } } return val2; } } internal sealed class BrowseSession { private readonly ZDOID desk; private static int sequence; private int waiting; private float sent; private float nextPoll; private ZDOID queuedChest; private readonly HashSet<ZDOID> changed = new HashSet<ZDOID>(); private ZDOID pendingPartial; private readonly Dictionary<ZDOID, HashSet<string>> included = new Dictionary<ZDOID, HashSet<string>>(); private string queuedPrefab; private Func<ItemData, bool> queuedFilter; private string findPrefab; private Func<ItemData, bool> findFilter; private readonly Dictionary<Inventory, ZDOID> sources = new Dictionary<Inventory, ZDOID>(); internal ZDOID DeskId => desk; internal int Revision { get; private set; } internal string Status { get; private set; } = "Reading storage..."; internal int Tier { get; private set; } internal Inventory[] Inventories { get; private set; } = Array.Empty<Inventory>(); internal bool IncludesOperation(ZDOID chest, string id) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) if (included.TryGetValue(chest, out var value)) { return value.Contains(id); } return false; } internal void TransferConfirmed(ZDOID console, ZDOID chest) { //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_000f: 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_002f: Unknown result type (might be due to invalid IL or missing references) if (!(desk != console)) { if (chest == desk) { nextPoll = 0f; } else { changed.Add(chest); } } } internal BrowseSession(ZDOID deskId) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) desk = deskId; } internal void Tick() { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: 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) if (waiting != 0 && Time.unscaledTime - sent > 4f) { Clear("Server did not respond."); waiting = 0; } if (queuedChest != ZDOID.None && waiting == 0 && Time.unscaledTime >= sent + 0.2f) { findPrefab = queuedPrefab; findFilter = queuedFilter; Request(queuedChest); queuedChest = ZDOID.None; } else if (waiting == 0 && changed.Count > 0 && Time.unscaledTime >= sent + 0.2f) { ZDOID val = changed.First(); changed.Remove(val); Request(val, partial: true); } else if (waiting == 0 && Time.unscaledTime >= sent + 0.2f && Time.unscaledTime >= nextPoll) { Request(ZDOID.None); } } private void Clear(string message) { Status = message; Inventories = Array.Empty<Inventory>(); sources.Clear(); included.Clear(); } internal bool TrySource(Inventory inventory, out ZDOID id) { return sources.TryGetValue(inventory, out id); } internal void Find(ItemData item, Func<ItemData, bool> filter) { //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) foreach (KeyValuePair<Inventory, ZDOID> source in sources) { if (source.Key.GetAllItems().Any((ItemData val) => (Object)(object)val.m_dropPrefab == (Object)(object)item.m_dropPrefab && filter(val))) { queuedPrefab = Utils.GetPrefabName(item.m_dropPrefab); queuedFilter = filter; queuedChest = source.Value; Tick(); break; } } } private void Request(ZDOID target, bool partial = false) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: 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_005e: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Expected O, but got Unknown //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014b: 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_017e: Expected O, but got Unknown //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Expected O, but got Unknown bool flag = ZNet.instance.IsServer(); ZRpc val = (flag ? null : ZNet.instance.GetServerRPC()); if (flag || val != null) { waiting = ++sequence; sent = Time.unscaledTime; pendingPartial = (partial ? target : ZDOID.None); if (!partial) { nextPoll = sent + 2f; } ZPackage val2 = new ZPackage(); val2.Write(4); val2.Write(waiting); val2.Write(desk); val2.Write(target); val2.Write(partial); MutationClient.SnapshotStarted(this); (ZDOID, string)[] array = (from op in MutationClient.SnapshotOperations(desk) where !partial || op.chest == target select op).Take(64).ToArray(); val2.Write(array.Length); (ZDOID, string)[] array2 = array; for (int num = 0; num < array2.Length; num++) { (ZDOID, string) tuple = array2[num]; val2.Write(tuple.Item1); val2.Write(tuple.Item2); } if (partial || target == ZDOID.None) { findPrefab = null; findFilter = null; } if (flag) { Receive(new ZPackage(BrowseTransport.Answer(ZNet.GetUID(), new ZPackage(val2.GetArray())).GetArray())); return; } val.Invoke("RuneLectern_Browse", new object[1] { val2 }); } } internal void Receive(ZPackage input) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: 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_00c5: 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_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Expected O, but got Unknown //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Expected O, but got Unknown //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) if (input.ReadInt() != waiting || waiting == 0) { return; } waiting = 0; string text = input.ReadString(); Revision++; if (text.Length != 0 || pendingPartial == ZDOID.None) { Clear(text); } else { Inventory key = sources.FirstOrDefault((KeyValuePair<Inventory, ZDOID> pair) => pair.Value == pendingPartial).Key; if (key != null) { sources.Remove(key); } included.Remove(pendingPartial); } if (text.Length != 0) { return; } Tier = input.ReadInt(); int num = input.ReadInt(); bool flag = false; for (int num2 = 0; num2 < num; num2++) { ZDOID val = input.ReadZDOID(); Inventory val2 = new Inventory("Rune snapshot", (Sprite)null, input.ReadInt(), input.ReadInt()); string text2 = input.ReadString(); if (text2.Length > 0) { val2.Load(new ZPackage(text2)); } sources.Add(val2, val); int num3 = input.ReadInt(); if (num3 > 0) { HashSet<string> hashSet = new HashSet<string>(); for (int num4 = 0; num4 < num3; num4++) { hashSet.Add(input.ReadString()); } included[val] = hashSet; } if (input.ReadBool()) { Vector3 position = input.ReadVector3(); int tier = input.ReadInt(); if (((IEnumerable<ItemData>)val2.GetAllItems()).FirstOrDefault((Func<ItemData, bool>)((ItemData x) => Object.op_Implicit((Object)(object)x.m_dropPrefab) && Utils.GetPrefabName(x.m_dropPrefab) == findPrefab && (findFilter?.Invoke(x) ?? false))) != null) { ChestMarker.Show(val, position, RuneNetwork.ChestName(tier) + " chest"); flag = true; } } } if (findPrefab != null && !flag) { Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)2, "That item is no longer available in this chest.", 0, (Sprite)null, false); } } Inventories = sources.Keys.ToArray(); MutationClient.SnapshotReceived(this, pendingPartial); Status = ""; } } internal static class ChestMarker { private static ZDOID chest; private static PinData pin; private static Minimap map; private static float expires; private static float highlightAt; internal static void Show(ZDOID id, Vector3 position, string label) { //IL_0005: 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_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) Clear(); chest = id; expires = Time.unscaledTime + 20f; highlightAt = 0f; map = Minimap.instance; if (Object.op_Implicit((Object)(object)map)) { pin = map.AddPin(position, (PinType)3, label, false, false, 0L, default(PlatformUserID)); } float num = Vector3.Distance(position, ((Component)Player.m_localPlayer).transform.position); ((Character)Player.m_localPlayer).Message((MessageType)2, $"{label} highlighted, {num:0} m away.", 0, (Sprite)null, false); } internal static void Tick() { //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_005e: Unknown result type (might be due to invalid IL or missing references) if (chest == ZDOID.None) { return; } if (!Object.op_Implicit((Object)(object)Player.m_localPlayer) || !Object.op_Implicit((Object)(object)ZNetScene.instance) || Time.unscaledTime >= expires) { Clear(); } else if (!(Time.unscaledTime < highlightAt)) { highlightAt = Time.unscaledTime + 0.15f; GameObject val = ZNetScene.instance.FindInstance(chest); WearNTear val2 = default(WearNTear); if (Object.op_Implicit((Object)(object)val) && val.TryGetComponent<WearNTear>(ref val2)) { val2.Highlight(); } } } private static void Clear() { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)map) && pin != null) { map.RemovePin(pin); } map = null; pin = null; chest = ZDOID.None; } } internal static class ChestPlacement { [HarmonyPatch(typeof(Player), "PieceRayTest")] private static class ReadHammerHit { private static void Postfix(bool __result, Piece piece, Vector3 point, Vector3 normal, GameObject ___m_placementGhost) { //IL_00b7: 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) mount = null; previewGhost = ___m_placementGhost; previewText = null; RuneConnector runeConnector = default(RuneConnector); if (Object.op_Implicit((Object)(object)previewGhost) && previewGhost.TryGetComponent<RuneConnector>(ref runeConnector)) { RuneEndpoint runeEndpoint = default(RuneEndpoint); if (!__result || !Object.op_Implicit((Object)(object)piece) || !((Component)piece).TryGetComponent<RuneEndpoint>(ref runeEndpoint)) { previewText = "Aim at a matching chest"; return; } if (runeConnector.Tier != runeEndpoint.RequiredTier) { previewText = "Use the " + RuneNetwork.CrystalName(runeEndpoint.RequiredTier); return; } if (!runeEndpoint.CanMount) { previewText = "Chest access denied"; return; } if (!runeEndpoint.PrepareMount()) { previewText = "Preparing chest mount..."; return; } if (RuneConnector.HasMount(runeEndpoint)) { previewText = "This chest already has a runestone"; return; } mount = runeEndpoint; runeEndpoint.GetMount(point, normal, out mountPosition, out mountRotation); } } } [HarmonyPatch(typeof(Player), "UpdatePlacementGhost")] private static class MountCrystalGhost { private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Expected O, but got Unknown //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Expected O, but got Unknown List<CodeInstruction> list = instructions.ToList(); FieldInfo support = AccessTools.Field(typeof(WearNTear), "m_supports"); FieldInfo fieldInfo = AccessTools.Field(typeof(Player), "m_placementGhost"); MethodInfo zone = AccessTools.Method(typeof(Location), "IsInsideNoBuildLocation", (Type[])null, (Type[])null); int num = list.FindIndex((CodeInstruction instruction) => CodeInstructionExtensions.Calls(instruction, zone)); if (num < 4 || !CodeInstructionExtensions.LoadsField(list[num - 3], fieldInfo, false)) { throw new InvalidOperationException("Valheim placement zone check has changed."); } int index = num - 4; list.InsertRange(index, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[3] { CodeInstructionExtensions.MoveLabelsFrom(new CodeInstruction(OpCodes.Ldarg_0, (object)null), list[index]), new CodeInstruction(OpCodes.Ldfld, (object)fieldInfo), CodeInstruction.Call(typeof(ChestPlacement), "ApplyMount", (Type[])null, (Type[])null) }); int num2 = list.FindIndex((CodeInstruction instruction) => CodeInstructionExtensions.LoadsField(instruction, support, false)); if (num2 < 0) { throw new InvalidOperationException("Valheim placement support check has changed."); } list[num2].opcode = OpCodes.Call; list[num2].operand = AccessTools.Method(typeof(ChestPlacement), "Supports", (Type[])null, (Type[])null); return list; } private static void Postfix(Player __instance, GameObject ___m_placementGhost, ref PlacementStatus ___m_placementStatus) { //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) RuneConnector runeConnector = default(RuneConnector); RuneRelay runeRelay = default(RuneRelay); if (!Object.op_Implicit((Object)(object)___m_placementGhost) || (Object)(object)previewGhost != (Object)(object)___m_placementGhost) { previewText = null; } else if (previewGhost.TryGetComponent<RuneConnector>(ref runeConnector)) { if (!Object.op_Implicit((Object)(object)mount) && (int)___m_placementStatus == 0) { ___m_placementStatus = (PlacementStatus)1; SetGhostValid(__instance, arg2: false); } if (Object.op_Implicit((Object)(object)mount) && (int)___m_placementStatus == 0) { previewText = RuneNetwork.DescribeCrystal(runeConnector.Tier, mountPosition); } } else if (previewGhost.TryGetComponent<RuneRelay>(ref runeRelay)) { Vector3? upstream = null; if ((int)___m_placementStatus == 0) { previewText = RuneNetwork.DescribeRelay(previewGhost.transform.position, out upstream); } previewGhost.GetComponent<RelayPlacementLine>().Show(upstream); } } } [HarmonyPatch(typeof(Player), "PlacePiece")] private static class CommitChestMount { private static bool Prefix(Piece piece, Vector3 pos, out RuneEndpoint __state) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) __state = committingMount; committingMount = null; RuneConnector runeConnector = default(RuneConnector); if (!((Component)piece).TryGetComponent<RuneConnector>(ref runeConnector)) { return true; } if (Object.op_Implicit((Object)(object)mount) && mount.CanMount && mount.PrepareMount()) { Vector3 val = pos - mountPosition; if (!(((Vector3)(ref val)).sqrMagnitude >= 0.0001f) && !RuneConnector.HasMount(mount)) { committingMount = mount; return true; } } return false; } private static void Finalizer(RuneEndpoint __state) { committingMount = __state; } } [HarmonyPatch(typeof(Hud), "UpdateCrosshair")] private static class ShowConnectionStatus { private static void Postfix(Player player, TextMeshProUGUI ___m_hoverName) { if (Object.op_Implicit((Object)(object)player) && ((Character)player).InPlaceMode() && Object.op_Implicit((Object)(object)previewGhost) && !string.IsNullOrEmpty(previewText)) { ((TMP_Text)___m_hoverName).text = previewText; } } } private static RuneEndpoint mount; private static RuneEndpoint committingMount; private static GameObject previewGhost; private static Vector3 mountPosition; private static Quaternion mountRotation; private static string previewText; private static readonly Action<Player, bool> SetGhostValid = AccessTools.MethodDelegate<Action<Player, bool>>(AccessTools.Method(typeof(Player), "SetPlacementGhostValid", (Type[])null, (Type[])null), (object)null, true); private static bool Supports(WearNTear surface) { if (!surface.m_supports) { if (Object.op_Implicit((Object)(object)mount)) { return (Object)(object)((Component)mount).gameObject == (Object)(object)((Component)surface).gameObject; } return false; } return true; } private static void ApplyMount(GameObject ghost) { //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) if (Object.op_Implicit((Object)(object)mount) && (Object)(object)ghost == (Object)(object)previewGhost) { ghost.transform.SetPositionAndRotation(mountPosition, mountRotation); } } internal static void BindPlacedCrystal(RuneConnector crystal) { if (Object.op_Implicit((Object)(object)committingMount)) { crystal.Bind(committingMount); } } } internal sealed class CrystalMountOnPlaced : MonoBehaviour, IPlaced { public void OnPlaced() { ChestPlacement.BindPlacedCrystal(((Component)this).GetComponent<RuneConnector>()); } } internal sealed class RelayPlacementLine : MonoBehaviour { private LineRenderer line; private Material material; internal void Show(Vector3? source) { //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: 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_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected O, but got Unknown //IL_0084: 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) if (!source.HasValue) { if (Object.op_Implicit((Object)(object)line)) { ((Renderer)line).enabled = false; } return; } if (!Object.op_Implicit((Object)(object)line)) { line = ((Component)this).gameObject.AddComponent<LineRenderer>(); material = new Material(Shader.Find("Sprites/Default")); ((Renderer)line).sharedMaterial = material; line.startColor = new Color(1f, 0.65f, 0.22f, 0.85f); line.endColor = new Color(1f, 0.85f, 0.42f, 0.65f); line.widthMultiplier = 0.035f; line.positionCount = 2; } ((Renderer)line).enabled = true; line.SetPosition(0, ((Component)this).transform.position + Vector3.up * 0.65f); line.SetPosition(1, source.Value + Vector3.up * 0.65f); } private void OnDestroy() { if (Object.op_Implicit((Object)(object)material)) { Object.Destroy((Object)(object)material); } } } internal static class ConsoleModel { internal static void Install(GameObject prefab) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Expected O, but got Unknown //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) int layer = ((Component)prefab.GetComponentInChildren<Collider>(true)).gameObject.layer; MeshRenderer[] componentsInChildren = prefab.GetComponentsInChildren<MeshRenderer>(true); for (int i = 0; i < componentsInChildren.Length; i++) { ((Renderer)componentsInChildren[i]).enabled = false; } GameObject val = new GameObject("Console model"); val.transform.SetParent(prefab.transform, false); foreach (var item in StorageModel.Load("RuneStorage.Console")) { GameObject val2 = new GameObject(item.Name) { layer = layer }; val2.transform.SetParent(val.transform, false); val2.AddComponent<MeshFilter>().sharedMesh = item.Mesh; MeshRenderer obj = val2.AddComponent<MeshRenderer>(); int num = int.Parse(item.Name.Substring(4)); bool flag = item.Name.StartsWith("Body"); ((Renderer)obj).sharedMaterials = ArcaneMaterials.Finish(num, flag || num == 1); if (flag) { float num2 = 0.47f + (float)num * 0.087f; float num3 = 2f * (0.102f + (float)num * 0.018f); BoxCollider obj2 = val2.AddComponent<BoxCollider>(); obj2.center = new Vector3(0f, 1.145f + num2 / 2f, -0.12f); obj2.size = new Vector3(num3, num2, num3 * 0.78f); val2.SetActive(num == 1); } } } internal static void ShowTier(Transform root, int tier) { for (int i = 1; i <= 4; i++) { ((Component)root.Find("Body" + i)).gameObject.SetActive(i == tier); ((Renderer)((Component)root.Find("Lamp" + i)).GetComponent<MeshRenderer>()).sharedMaterials = ArcaneMaterials.Finish(i, i <= tier); } } } internal sealed class DedicatedChest { internal ZDOID Id; internal Vector3 Position; internal int Tier; internal int Width; internal int Height; internal string Items; } internal static class DedicatedSnapshot { private static readonly int DeskHash = StringExtensionMethods.GetStableHashCode("RuneStorage_Lectern"); private static readonly int PlayerHash = StringExtensionMethods.GetStableHashCode("Player"); private static readonly int RelayHash = StringExtensionMethods.GetStableHashCode("RuneStorage_Relay"); private static readonly Dictionary<int, int> ChestTiers = new Dictionary<int, int> { { StringExtensionMethods.GetStableHashCode("piece_chest_wood"), 1 }, { StringExtensionMethods.GetStableHashCode("piece_chest"), 2 }, { StringExtensionMethods.GetStableHashCode("piece_chest_blackmetal"), 3 }, { StringExtensionMethods.GetStableHashCode("piece_chest_grausten"), 4 } }; private static readonly Dictionary<int, int> CrystalTiers = Enumerable.Range(1, 4).ToDictionary((int tier) => StringExtensionMethods.GetStableHashCode("RuneStorage_Crystal" + tier)); private static readonly Dictionary<int, float> WardRadii = new Dictionary<int, float>(); private static ZNetScene wardScene; private static float largestWard; internal static bool IsSupportedChest(int prefab) { return ChestTiers.ContainsKey(prefab); } internal static bool TryRead(long sender, ZDOID deskId, out int tier, out List<DedicatedChest> chests, ZDOID targetId = default(ZDOID), ZDOID leased = default(ZDOID), bool includeItems = true) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_0251: 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_0205: Unknown result type (might be due to invalid IL or missing references) //IL_025d: Unknown result type (might be due to invalid IL or missing references) //IL_025f: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_0278: Unknown result type (might be due to invalid IL or missing references) //IL_027a: Unknown result type (might be due to invalid IL or missing references) //IL_03ca: Unknown result type (might be due to invalid IL or missing references) //IL_032b: Unknown result type (might be due to invalid IL or missing references) //IL_03ef: Unknown result type (might be due to invalid IL or missing references) //IL_03fc: Unknown result type (might be due to invalid IL or missing references) //IL_0401: Unknown result type (might be due to invalid IL or missing references) //IL_0406: Unknown result type (might be due to invalid IL or missing references) //IL_0420: Unknown result type (might be due to invalid IL or missing references) //IL_0579: Unknown result type (might be due to invalid IL or missing references) //IL_057f: Invalid comparison between Unknown and I4 //IL_05c3: Unknown result type (might be due to invalid IL or missing references) //IL_05c8: Unknown result type (might be due to invalid IL or missing references) //IL_05d5: Unknown result type (might be due to invalid IL or missing references) //IL_05da: Unknown result type (might be due to invalid IL or missing references) tier = 0; chests = new List<DedicatedChest>(); ZNet net = ZNet.instance; ZNetScene scene = ZNetScene.instance; ZDOMan instance = ZDOMan.instance; if (!Object.op_Implicit((Object)(object)net) || !net.IsServer() || !Object.op_Implicit((Object)(object)scene) || instance == null || !Object.op_Implicit((Object)(object)ZoneSystem.instance)) { return false; } ZDO val; if (sender == ZNet.GetUID() && !net.IsDedicated() && Object.op_Implicit((Object)(object)Player.m_localPlayer)) { ZNetView component = ((Component)Player.m_localPlayer).GetComponent<ZNetView>(); val = ((component != null) ? component.GetZDO() : null); } else { ZNetPeer peer = net.GetPeer(sender); if (peer == null || !peer.IsReady()) { return false; } val = instance.GetZDO(peer.m_characterID); } if (val == null || val.GetPrefab() != PlayerHash || val.GetOwner() != sender || val.GetBool(ZDOVars.s_dead, false)) { return false; } long num = val.GetLong(ZDOVars.s_playerID, 0L); if (num == 0L) { return false; } ZDO zDO = instance.GetZDO(deskId); if (zDO == null || zDO.GetPrefab() != DeskHash || !(Vector3.Distance(val.GetPosition(), zDO.GetPosition()) <= 5f)) { return false; } CacheWardPrefabs(scene); Vector2s center = ZoneSystem.GetZone(val.GetPosition()); SimulationDistance syncedSimulationDistance = net.GetSyncedSimulationDistance(); int nearSimulationDistance = ((SimulationDistance)(ref syncedSimulationDistance)).NearSimulationDistance; int num2 = 1 + Mathf.CeilToInt(largestWard / ZoneSystem.instance.m_zoneSize); List<ZDO> list = new List<ZDO>(); instance.FindSectorObjects(center, new SimulationDistance(nearSimulationDistance + num2, 0, true), list, (List<ZDO>)null); List<(Vector3 position, float radius)> blocked = new List<(Vector3, float)>(); foreach (ZDO item in list) { if (WardRadii.TryGetValue(item.GetPrefab(), out var value) && item.GetBool(ZDOVars.s_enabled, false) && !WardPermits(item, num)) { blocked.Add((item.GetPosition(), value)); } } if (!Eligible(zDO)) { return false; } tier = Mathf.Clamp(zDO.GetInt("RuneLectern.Tier", 1), 1, 4); if (targetId == deskId) { return true; } ZDO val2 = ((targetId == ZDOID.None) ? null : instance.GetZDO(targetId)); if (targetId != ZDOID.None && (val2 == null || !ChestTiers.ContainsKey(val2.GetPrefab()) || !Eligible(val2))) { return true; } string text = ((val2 != null) ? val2.GetString("RuneStorage.ChestCrystalId", "") : null); if (val2 != null && string.IsNullOrEmpty(text)) { return true; } List<Vector3> list2 = new List<Vector3>(); List<ZDO> list3 = new List<ZDO>(); List<ZDO> list4 = new List<ZDO>(); if (val2 != null) { list4.Add(val2); } foreach (ZDO item2 in list) { int prefab = item2.GetPrefab(); int value2; if (prefab == RelayHash && Eligible(item2)) { list2.Add(item2.GetPosition()); } else if (CrystalTiers.TryGetValue(prefab, out value2) && value2 <= tier && (val2 == null || item2.GetString("RuneStorage.ChestCrystalId", "") == text) && Eligible(item2)) { list3.Add(item2); } else if (val2 == null && ChestTiers.ContainsKey(prefab) && Eligible(item2)) { list4.Add(item2); } } List<Vector3> sources = new List<Vector3> { zDO.GetPosition() }; for (int i = 0; i < sources.Count; i++) { for (int num3 = list2.Count - 1; num3 >= 0; num3--) { Vector3 val3 = list2[num3] - sources[i]; if (!(((Vector3)(ref val3)).sqrMagnitude > 144f)) { sources.Add(list2[num3]); list2.RemoveAt(num3); } } } ILookup<string, ZDO> lookup = list3.Where((ZDO obj) => sources.Any(delegate(Vector3 source) { //IL_0000: 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_000c: 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) Vector3 val6 = source - obj.GetPosition(); return ((Vector3)(ref val6)).sqrMagnitude <= 144f; })).ToLookup((ZDO obj) => obj.GetString("RuneStorage.ChestCrystalId", "")); foreach (ZDO chest in list4) { int chestTier = ChestTiers[chest.GetPrefab()]; string text2 = chest.GetString("RuneStorage.ChestCrystalId", ""); if (text2.Length != 0 && chest.GetInt(ZDOVars.s_inUse, 0) == 0 && lookup[text2].Any((ZDO crystal) => CrystalTiers[crystal.GetPrefab()] == chestTier && RuneNetwork.Mounted(crystal.GetPosition(), chest.GetPosition()))) { ZNetView val4 = scene.FindInstance(chest); Container val5 = (Object.op_Implicit((Object)(object)val4) ? ((Component)val4).GetComponent<Container>() : scene.GetPrefab(chest.GetPrefab()).GetComponent<Container>()); if (Object.op_Implicit((Object)(object)val5) && (int)val5.m_privacy == 2 && (!Object.op_Implicit((Object)(object)val4) || !val5.IsInUse())) { byte[] array = (includeItems ? chest.GetByteArray(ZDOVars.s_items, (byte[])null) : null); chests.Add(new DedicatedChest { Id = chest.m_uid, Position = chest.GetPosition(), Tier = chestTier, Width = val5.m_width, Height = val5.m_height, Items = ((array == null) ? "" : Convert.ToBase64String(array)) }); } } } return true; bool Eligible(ZDO obj) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) if (!obj.HasOwner() || !ZNetScene.InActiveArea(obj.GetPosition(), center)) { return false; } long owner = obj.GetOwner(); if (owner == ZNet.GetUID()) { if (!scene.HaveInstance(obj) && obj.m_uid != leased && !MutationServer.JournalHolds(obj.m_uid)) { return false; } } else { ZNetPeer peer2 = net.GetPeer(owner); if (peer2 == null || !peer2.IsReady() || !ZNetScene.InActiveArea(obj.GetPosition(), peer2.GetRefPos())) { return false; } } foreach (var item3 in blocked) { if (Utils.DistanceXZ(obj.GetPosition(), item3.position) < item3.radius) { return false; } } return true; } } private static bool WardPermits(ZDO ward, long characterId) { if (ward.GetLong(ZDOVars.s_creator, 0L) == characterId) { return true; } int num = ward.GetInt(ZDOVars.s_permitted, 0); for (int i = 0; i < num; i++) { if (ward.GetLong("pu_id" + i, 0L) == characterId) { return true; } } return false; } private static void CacheWardPrefabs(ZNetScene scene) { if ((Object)(object)wardScene == (Object)(object)scene) { return; } WardRadii.Clear(); largestWard = 0f; PrivateArea val = default(PrivateArea); foreach (string prefabName in scene.GetPrefabNames()) { GameObject prefab = scene.GetPrefab(prefabName); if (Object.op_Implicit((Object)(object)prefab) && prefab.TryGetComponent<PrivateArea>(ref val)) { WardRadii[StringExtensionMethods.GetStableHashCode(prefabName)] = val.m_radius; largestWard = Mathf.Max(largestWard, val.m_radius); } } wardScene = scene; } } internal static class EikthyrBuildGate { [HarmonyPatch(typeof(PieceTable), "UpdateAvailable")] private static class FilterHammer { private static void Postfix(HashSet<Piece> ___m_enabledPieces, HashSet<Piece> ___m_availablePieces, List<List<Piece>> ___m_availablePiecesByCategory) { if (Unlocked || !___m_enabledPieces.Overlaps(Pieces)) { return; } ___m_enabledPieces.ExceptWith(Pieces); ___m_availablePieces.ExceptWith(Pieces); foreach (List<Piece> item in ___m_availablePiecesByCategory) { item.RemoveAll(Pieces.Contains); } } } [HarmonyPatch(typeof(Player), "HaveRequirements", new Type[] { typeof(Piece), typeof(RequirementMode) })] private static class CheckRequirements { private static bool Prefix(Piece piece, ref bool __result) { if (!Pieces.Contains(piece) || Unlocked) { return true; } __result = false; return false; } } [HarmonyPatch] private static class Placement { private static IEnumerable<MethodBase> TargetMethods() { yield return AccessTools.Method(typeof(Player), "TryPlacePiece", (Type[])null, (Type[])null); yield return AccessTools.Method(typeof(Player), "PlacePiece", (Type[])null, (Type[])null); } private static bool Prefix(Player __instance, Piece piece) { if (!Pieces.Contains(piece) || Unlocked) { return true; } ((Character)__instance).Message((MessageType)2, "Defeat Eikthyr in this world to build Runebound Storage pieces.", 0, (Sprite)null, false); return false; } } internal const string WorldKey = "defeated_eikthyr"; private static readonly HashSet<Piece> Pieces = new HashSet<Piece>(); private static readonly Action<Player, Piece> TeachPiece = AccessTools.MethodDelegate<Action<Player, Piece>>(AccessTools.Method(typeof(Player), "AddKnownPiece", (Type[])null, (Type[])null), (object)null, true); private static readonly Action<Player> RefreshRecipes = AccessTools.MethodDelegate<Action<Player>>(AccessTools.Method(typeof(Player), "UpdateKnownRecipesList", (Type[])null, (Type[])null), (object)null, true); private static readonly Action<Player> RefreshHammer = AccessTools.MethodDelegate<Action<Player>>(AccessTools.Method(typeof(Player), "UpdateAvailablePiecesList", (Type[])null, (Type[])null), (object)null, true); private static Player lastPlayer; private static bool lastUnlocked; private static bool Unlocked { get { if (Object.op_Implicit((Object)(object)ZoneSystem.instance)) { return ZoneSystem.instance.GetGlobalKey("defeated_eikthyr"); } return false; } } internal static void Register(Piece piece) { Pieces.Add(piece); } internal static void Refresh() { Player localPlayer = Player.m_localPlayer; bool unlocked = Unlocked; if ((Object.op_Implicit((Object)(object)localPlayer) && (!Object.op_Implicit((Object)(object)Hud.instance) || !Object.op_Implicit((Object)(object)Hud.instance.m_buildUi) || !Object.op_Implicit((Object)(object)MessageHud.instance) || Pieces.Count == 0)) || ((Object)(object)localPlayer == (Object)(object)lastPlayer && unlocked == lastUnlocked)) { return; } lastPlayer = localPlayer; lastUnlocked = unlocked; if (!Object.op_Implicit((Object)(object)localPlayer)) { return; } if (unlocked) { foreach (Piece piece in Pieces) { TeachPiece(localPlayer, piece); } RefreshRecipes(localPlayer); } RefreshHammer(localPlayer); } } internal static class EpicLootRarity { private delegate bool RarityLookup(ItemData item, out int rarity); private static readonly Type EpicApi = (Chainloader.PluginInfos.TryGetValue("randyknapp.mods.epicloot", out var value) ? ((object)value.Instance).GetType().Assembly.GetType("EpicLoot.API", throwOnError: true) : null); private static readonly RarityLookup Lookup = Bind<RarityLookup>("TryGetRarity"); internal static readonly Func<int> RarityCount = Bind<Func<int>>("GetRarityCount"); internal static readonly Func<int, string> RarityName = Bind<Func<int, string>>("GetRarityDisplayNameByIndex"); private static T Bind<T>(string name) where T : Delegate { if (!(EpicApi == null)) { return AccessTools.MethodDelegate<T>(AccessTools.Method(EpicApi, name, (Type[])null, (Type[])null), (object)null, true); } return null; } internal static bool HasRarity(ItemData item, int rarity) { if (Lookup(item, out var rarity2)) { return rarity2 == rarity; } return false; } } [HarmonyPatch(typeof(ZNet), "OnNewConnection")] internal static class MutationServer { [HarmonyPatch(typeof(Container), "Interact")] private static class OpenPhysical { private static bool Prefix(Container __instance, Humanoid character, bool hold, bool alt, ref bool __result) { if (hold || !DeferPhysical(__instance, character, takeAll: false, alt)) { return true; } __result = true; return false; } } [HarmonyPatch(typeof(Container), "TakeAll")] private static class TakePhysical { private static bool Prefix(Container __instance, Humanoid character, ref bool __result) { if (!DeferPhysical(__instance, character, takeAll: true, alt: false)) { return true; } __result = true; return false; } } private sealed class Operation { internal string Id; internal string Digest; internal string Marker; internal string File; internal string Token; internal string Subject; internal string ObjectIdentity; internal long Sender; internal long OriginalOwner; internal long Character; internal ZNetPeer Peer; internal ZDOID Desk; internal ZDOID Target; internal int Kind; internal int Tier; internal int X; internal int Y; internal int Amount; internal byte[] Item; internal Action<ZPackage> Respond; internal float Deadline; internal float RetryLease; internal bool Prepared; internal bool Applied; } [HarmonyPatch(typeof(ZNet), "LoadWorld")] private static class LoadedCheckpoint { private static void Postfix(ZNet __instance, ref bool __result) { if (!__result || !__instance.IsServer()) { return; } loadedWorld = __instance; loadedSave = SaveSystem.GetSaveNumber(); if (!__instance.IsDedicated()) { return; } try { LoadJournal(__instance); } catch (Exception ex) { StopJournal("Cannot recover the transfer journal: " + ex); __result = false; } } } [HarmonyPatch(typeof(Container), "RPC_RequestOpen")] private static class OpeningChest { private static void Prefix(Container __instance) { ReloadMutatedChest(__instance); } } [HarmonyPatch(typeof(Container), "RPC_OpenResponse")] private static class ReceivingChest { private static void Prefix(Container __instance) { ReloadMutatedChest(__instance); } } [HarmonyPatch(typeof(ZDOMan), "PrepareSave")] private static class CaptureCheckpoint { private static void Postfix() { lock (saveLock) { checkpoint = (from o in Active.Values where o.Applied select o.Marker).ToList(); CaptureJournalCheckpoint(); } } } [HarmonyPatch(typeof(SaveSystem), "EndSave")] private static class ConfirmCheckpoint { private static void Postfix(bool writeOK) { if (!writingWorld) { return; } lock (saveLock) { EndJournalCheckpoint(writeOK); if (writeOK) { foreach (string item in checkpoint) { Saved.Add(item); } } checkpoint.Clear(); } } } [HarmonyPatch(typeof(ZNet), "Update")] private static class Service { private static void Postfix(ZNet __instance) { //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) ServiceJournal(); if ((Object)(object)__instance != (Object)(object)session || !__instance.IsServer()) { return; } for (int num = Released.Count - 1; num >= 0; num--) { Operation operation = Released[num]; RestoreOwner(operation); if (Time.unscaledTime > operation.Deadline) { Released.RemoveAt(num); } } if (Active.Count == 0) { return; } List<Operation>[] array = Waiting.Values.ToArray(); foreach (List<Operation> list in array) { Operation operation2 = list[0]; ZDO zDO = ZDOMan.instance.GetZDO(operation2.Target); if (zDO != null && zDO.GetOwner() == ZNet.GetUID() && (operation2.OriginalOwner == ZNet.GetUID() || zDO.GetString("Runebound.Lease", "") == operation2.Token)) { Thread obj = SaveThread.Invoke(__instance); if (obj == null || !obj.IsAlive) { Release(list); } } else if (Time.unscaledTime > operation2.Deadline) { Debug.LogWarning((object)$"Runebound lease timed out for {operation2.Target}. Expected {operation2.OriginalOwner}, observed {((zDO != null) ? new long?(zDO.GetOwner()) : ((long?)null))}, server {ZNet.GetUID()}."); Release(list, "The chest owner did not yield. Try again."); } else if (zDO != null && operation2.OriginalOwner != ZNet.GetUID() && zDO.GetOwner() == operation2.OriginalOwner && Time.unscaledTime >= operation2.RetryLease) { ZNetPeer peer = __instance.GetPeer(operation2.OriginalOwner); if (peer != null && peer.IsReady()) { RequestLease(operation2, peer); } } } Operation[] array2 = Active.Values.Where((Operation move) => move.Applied).ToArray(); foreach (Operation operation3 in array2) { bool flag; lock (saveLock) { flag = Saved.Contains(operation3.Marker); } if (!flag) { continue; } try { File.Move(operation3.File + ".pending", operation3.File + ".done"); Remember(operation3.Id, (player: operation3.Subject, target: operation3.ObjectIdentity)); lock (saveLock) { Saved.Remove(operation3.Marker); } Finish(operation3, 1, "Transfer completed."); } catch (Exception ex) { Debug.LogWarning((object)("Runebound receipt: " + ex.Message)); } } if (Time.unscaledTime < nextSave || !Active.Values.Any((Operation o) => o.Applied) || (Waiting.Count != 0 && Time.unscaledTime < firstAppliedAt + 0.75f)) { return; } Thread obj2 = SaveThread.Invoke(__instance); if (obj2 != null && obj2.IsAlive) { return; } nextSave = Time.unscaledTime + 2f; float num2 = AutoSaveTimer.Invoke(Game.instance); try { __instance.Save(false, false, false); } finally { AutoSaveTimer.Invoke(Game.instance) = num2; } } } private sealed class Anchor { internal string Binding; internal byte[] Items; } private sealed class Redo { internal string Id; internal string Digest; internal string File; internal string Binding; internal string Identity; internal int Prefab; internal Vector3 Position; internal long Revision; internal ZDOID Target; internal byte[] BeforeHash; internal byte[] After; internal byte[] Receipt; } [HarmonyPatch(typeof(ZDO), "Deserialize")] private static class ReplicatedChest { private static void Postfix(ZDO __instance) { //IL_0047: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)journalSession) && (Object)(object)journalSession == (Object)(object)ZNet.instance && DedicatedSnapshot.IsSupportedChest(__instance.GetPrefab()) && __instance.GetString("RuneStorage.ChestCrystalId", "").Length != 0) { candidates.Add(__instance.m_uid); } } } [HarmonyPatch(typeof(ZDO), "Set", new Type[] { typeof(int), typeof(string) })] private static class LocalBinding { private static readonly int bindingHash = StringExtensionMethods.GetStableHashCode("RuneStorage.ChestCrystalId"); private static void Postfix(ZDO __instance, int __0) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) if (__0 == bindingHash && Object.op_Implicit((Object)(object)journalSession) && (Object)(object)journalSession == (Object)(object)ZNet.instance && DedicatedSnapshot.IsSupportedChest(__instance.GetPrefab())) { candidates.Add(__instance.m_uid); } } } [HarmonyPatch(typeof(ZNet), "SaveWorldThread")] private static class WorldWriter { private static void Prefix() { writingWorld = true; } private static void Finalizer() { writingWorld = false; } } [HarmonyPatch(typeof(ZDOMan), "RPC_ZDOData")] private static class PinnedNetworkData { private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) { //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Expected O, but got Unknown //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Expected O, but got Unknown //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Expected O, but got Unknown List<CodeInstruction> list = instructions.ToList(); int num = list.FindIndex((CodeInstruction i) => i.operand is MethodInfo methodInfo && methodInfo.Name == "ReadPackage"); int num2 = list.FindLastIndex(num, (CodeInstruction i) => CodeInstructionExtensions.Calls(i, AccessTools.Method(typeof(ZPackage), "ReadZDOID", (Type[])null, (Type[])null))); if (num2 <= 0 || !CodeInstructionExtensions.IsStloc(list[num2 + 1], (LocalBuilder)null) || !CodeInstructionExtensions.IsLdarg(list[num2 - 1], (int?)2)) { throw new InvalidOperationException("Unsupported Valheim ZDO update framing."); } Label label = generator.DefineLabel(); list[num2 - 1].labels.Add(label); list.InsertRange(num + 1, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[3] { new CodeInstruction(OpCodes.Ldloc, list[num2 + 1].operand), new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(MutationServer), "JournalHolds", (Type[])null, (Type[])null)), new CodeInstruction(OpCodes.Brtrue, (object)label) }); return list; } } [HarmonyPatch(typeof(ZDO), "SetOwner")] private static class PinnedJournalOwner { private static bool Prefix(ZDO __instance, long __0) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) if (JournalHolds(__instance.m_uid)) { return __0 == ZNet.GetUID(); } return true; } } [HarmonyPatch] private static class NativeChestFence { private static IEnumerable<MethodBase> TargetMethods() { return ((IEnumerable<string>)new string[4] { "OnDestroyed", "Save", "RPC_RequestOpen", "RPC_RequestTakeAll" }).Select((Func<string, MethodBase>)((string n) => AccessTools.Method(typeof(Container), n, (Type[])null, (Type[])null))); } private static bool Prefix(Container __instance) { ZNetView component = ((Component)__instance).GetComponent<ZNetView>(); return NativeBarrier((component != null) ? component.GetZDO() : null); } } [HarmonyPatch(typeof(ZDOMan), "HandleDestroyedZDO")] private static class NativeDestroyFence { private static bool Prefix(ZDOMan __instance, ZDOID __0) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) if (JournalHolds(__0)) { return NativeBarrier(__instance.GetZDO(__0)); } return true; } } private const string NativeAccessRequest = "Runebound_PhysicalChest"; private const string NativeAccessReady = "Runebound_PhysicalChestReady"; private static int nativeRequest; private static int nativeReply; private static long nativeOwner; private static bool invokingNative; internal const string Request = "Runebound_Mutate"; internal const string Reply = "Runebound_Mutated"; private const string Lease = "Runebound_Yield"; private const string YieldResult = "Runebound_Yielded"; private const string LeaseKey = "Runebound.Lease"; private const string IdentityKey = "Runebound.StorageObject"; private const string ReceiptKey = "Runebound.LastMutation"; internal const int MaxItemBytes = 65536; internal const int MaxBatch = 32; internal const int MaxBatchBytes = 524288; private static readonly Dictionary<string, Operation> Active = new Dictionary<string, Operation>(); private static readonly Dictionary<ZDOID, List<Operation>> Waiting = new Dictionary<ZDOID, List<Operation>>(); private static readonly Dictionary<string, (string player, string target)> Completed = new Dictionary<string, (string, string)>(); private static readonly HashSet<string> Saved = new HashSet<string>(); private static readonly FieldRef<ZNet, Thread> SaveThread = AccessTools.FieldRefAccess<ZNet, Thread>("m_saveThread"); private static readonly FieldRef<Game, float> AutoSaveTimer = AccessTools.FieldRefAccess<Game, float>("m_saveTimer"); private static readonly Func<Container, bool> Reload = AccessTools.MethodDelegate<Func<Container, bool>>(AccessTools.Method(typeof(Container), "Load", (Type[])null, (Type[])null), (object)null, true); private static ZNet session; private static ZNet loadedWorld; private static long loadedSave; private static string directory; private static float nextSave; private static float firstAppliedAt; private static List<string> checkpoint = new List<string>(); private static readonly object saveLock = new object(); private static string serverId; private static ZRpc ledgerConnection; private static string remoteId; private static float nextIdentityQuery; private static readonly List<Operation> Released = new List<Operation>(); private const string IdentityRequest = "Runebound_ReceiptStore"; private const string IdentityReply = "Runebound_ReceiptStoreID"; private const string JournalRevision = "Runebound.JournalRevision"; private static readonly FieldRef<ZDOMan, Dictionary<ZDOID, ZDO>> AllObjects = AccessTools.FieldRefAccess<ZDOMan, Dictionary<ZDOID, ZDO>>("m_objectsByID"); private static readonly Dictionary<ZDOID, Anchor> anchors = new Dictionary<ZDOID, Anchor>(); private static readonly HashSet<string> duplicateAnchors = new HashSet<string>(); private static readonly HashSet<ZDOID> candidates = new HashSet<ZDOID>(); private static readonly Dictionary<string, Redo> journalEntries = new Dictionary<string, Redo>(); private static readonly Dictionary<ZDOID, Redo> dirtyChests = new Dictionary<ZDOID, Redo>(); private static readonly Dictionary<ZDOID, Operation> journalOwners = new Dictionary<ZDOID, Operation>(); private static Dictionary<ZDOID, Anchor> snapshotAnchors; private static string[] capturedEntries; private static readonly HashSet<string> persisted = new HashSet<string>(); private static Dictionary<ZDOID, Anchor> persistedAnchors; private static ZNet journalSession; private static float checkpointAt; private static float firstDirty; private static bool journalUnavailable; [ThreadStatic] private static bool writingWorld; private const uint MoveWriteThrough = 8u; internal static string LedgerId { get { ZNet instance = ZNet.instance; if (!Object.op_Implicit((Object)(object)instance)) { return ""; } if (instance.IsServer()) { if (instance.GetWorld() == null) { return ""; } Initialize(); return serverId; } ZRpc serverRPC = instance.GetServerRPC(); if (serverRPC != ledgerConnection) { ledgerConnection = serverRPC; remoteId = ""; nextIdentityQuery = 0f; } if (serverRPC != null && string.IsNullOrEmpty(remoteId) && Time.unscaledTime >= nextIdentityQuery) { nextIdentityQuery = Time.unscaledTime + 2f; serverRPC.Invoke("Runebound_ReceiptStore", Array.Empty<object>()); } return remoteId ?? ""; } } private static void RegisterNativeAccess(ZNet net, ZNetPeer peer) { if (net.IsServer()) { float next = 0f; peer.m_rpc.Register<ZPackage>("Runebound_PhysicalChest", (Action<ZRpc, ZPackage>)delegate(ZRpc rpc, ZPackage p) { //IL_0083: 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_00a5: 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_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Expected O, but got Unknown //IL_0153: Unknown result type (might be due to invalid IL or missing references) if (p.Size() == 16 && peer.IsReady() && rpc == peer.m_rpc && net.GetPeer(peer.m_uid) == peer && !(Time.unscaledTime < next)) { next = Time.unscaledTime + 0.1f; int num = p.ReadInt(); ZDOID val = p.ReadZDOID(); ZDO zDO = ZDOMan.instance.GetZDO(val); ZDO zDO2 = ZDOMan.instance.GetZDO(peer.m_characterID); if (zDO != null && zDO2 != null && zDO2.GetOwner() == peer.m_uid && !(Vector3.Distance(zDO2.GetPosition(), zDO.GetPosition()) > 8f) && DedicatedSnapshot.IsSupportedChest(zDO.GetPrefab()) && zDO.GetString("RuneStorage.ChestCrystalId", "").Length != 0 && !Waiting.ContainsKey(val) && NativeBarrier(zDO)) { ZPackage val2 = new ZPackage(); val2.Write(num); val2.Write(zDO.GetOwner()); ZDOMan.instance.ForceSendZDO(peer.m_uid, val); rpc.Invoke("Runebound_PhysicalChestReady", new object[1] { val2 }); } } }); } else { if (!peer.m_server) { return; } peer.m_rpc.Register<ZPackage>("Runebound_PhysicalChestReady", (Action<ZRpc, ZPackage>)delegate(ZRpc rpc, ZPackage p) { if (rpc == net.GetServerRPC() && p.Size() == 12) { nativeReply = p.ReadInt(); nativeOwner = p.ReadLong(); } }); } } private static bool DeferPhysical(Container chest, Humanoid actor, bool takeAll, bool alt) { ZNet instance = ZNet.instance; if (invokingNative || !Object.op_Implicit((Object)(object)instance) || instance.IsServer() || (Object)(object)actor != (Object)(object)Player.m_localPlayer) { return false; } ZNetView component = ((Component)chest).GetComponent<ZNetView>(); if (!Object.op_Implicit((Object)(object)component) || !component.IsValid() || component.GetZDO().GetString("RuneStorage.ChestCrystalId", "").Length == 0) { return false; } ((MonoBehaviour)chest).StartCoroutine(WaitForPhysical(chest, Player.m_localPlayer, component, instance.GetServerRPC(), ++nativeRequest, takeAll, alt)); return true; } private static IEnumerator WaitForPhysical(Container chest, Player player, ZNetView view, ZRpc rpc, int request, bool takeAll, bool alt) { ZPackage packet = new ZPackage(); packet.Write(request); packet.Write(view.GetZDO().m_uid); float deadline = Time.unscaledTime + 8f; float next = 0f; while (Object.op_Implicit((Object)(object)chest) && Object.op_Implicit((Object)(object)view) && view.IsValid() && Object.op_Implicit((Object)(object)player) && (Object)(object)player == (Object)(object)Player.m_localPlayer && !((Character)player).IsDead() && !((Character)player).IsTeleporting() && Object.op_Implicit((Object)(object)ZNet.instance) && rpc != null && rpc == ZNet.instance.GetServerRPC() && request == nativeRequest && Vector3.Distance(((Component)player).transform.position, ((Component)chest).transform.position) <= 6f) { if (nativeReply == request && view.GetZDO().GetOwner() == nativeOwner) { try { invokingNative = true; if (takeAll) { chest.TakeAll((Humanoid)(object)player); } else { chest.Interact((Humanoid)(object)player, false, alt); } break; } finally { invokingNative = false; } } if (Time.unscaledTime >= deadline) { ((Character)player).Message((MessageType)2, "Waiting for the chest to finish saving. Try again.", 0, (Sprite)null, false); break; } if (Time.unscaledTime >= next) { rpc.Invoke("Runebound_PhysicalChest", new object[1] { packet }); next = Time.unscaledTime + 0.25f; } yield return null; } } private static void Postfix(ZNet __instance, ZNetPeer peer) { //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Expected O, but got Unknown RegisterNativeAccess(__instance, peer); if (__instance.IsServer()) { peer.m_rpc.Register("Runebound_ReceiptStore", (Method)delegate(ZRpc rpc) { if (rpc == peer.m_rpc && peer.IsReady() && __instance.GetPeer(peer.m_uid) == peer) { Initialize(); rpc.Invoke("Runebound_ReceiptStoreID", new object[1] { serverId }); } }); float replenished = Time.unscaledTime; float credits = 8f; peer.m_rpc.Register<ZPackage>("Runebound_Mutate", (Action<ZRpc, ZPackage>)delegate(ZRpc rpc, ZPackage p) { if (peer.IsReady() && rpc == peer.m_rpc && __instance.GetPeer(peer.m_uid) == peer) { float unscaledTime = Time.unscaledTime; credits = Math.Min(8f, credits + 10f * (unscaledTime - replenished)); replenished = unscaledTime; if (!(credits < 1f)) { credits--; HandleBatch(peer.m_uid, peer, p, delegate(ZPackage answer) { rpc.Invoke("Runebound_Mutated", new object[1] { answer }); }); } } }); peer.m_rpc.Register<ZPackage>("Runebound_Yielded", (Action<ZRpc, ZPackage>)delegate(ZRpc rpc, ZPackage p) { //IL_0046: 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_0058: Unknown result type (might be due to invalid IL or missing references) if (p.Size() > 100 || !peer.IsReady() || rpc != peer.m_rpc || __instance.GetPeer(peer.m_uid) != peer) { return; } try { ZDOID key = p.ReadZDOID(); string text = p.ReadString(); if (Waiting.TryGetValue(key, out var value) && value[0].OriginalOwner == peer.m_uid && value[0].Token == text && !p.ReadBool()) { Release(value, "The chest or Runekeeper is busy. Try again."); } } catch (IOException) { } }); } else { if (!peer.m_server) { return; } peer.m_rpc.Register<string>("Runebound_ReceiptStoreID", (Action<ZRpc, string>)delegate(ZRpc rpc, string value) { if (rpc == __instance.GetServerRPC() && rpc == ledgerConnection && Guid.TryParseExact(value, "N", out var _)) { remoteId = value; } }); peer.m_rpc.Register<ZPackage>("Runebound_Yield", (Action<ZRpc, ZPackage>)delegate(ZRpc rpc, ZPackage p) { //IL_001a: 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_002c: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Invalid comparison between Unknown and I4 //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Expected O, but got Unknown //IL_010e: 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) if (rpc == __instance.GetServerRPC() && p.Size() <= 100) { ZDOID val = p.ReadZDOID(); string text = p.ReadString(); ZDO zDO = ZDOMan.instance.GetZDO(val); ZNetView val2 = ((zDO == null) ? null : ZNetScene.instance.FindInstance(zDO)); ZNetView val3 = (Object.op_Implicit((Object)(object)val2) ? ((Component)val2).GetComponent<ZNetView>() : null); Container val4 = (Object.op_Implicit((Object)(object)val2) ? ((Component)val2).GetComponent<Container>() : null); if (Object.op_Implicit((Object)(object)val3) && val3.IsValid() && val3.IsOwner()) { bool flag = (Object.op_Implicit((Object)(object)((Component)val2).GetComponent<RuneEndpoint>()) && Object.op_Implicit((Object)(object)val4) && (int)val4.m_privacy == 2 && !val4.IsInUse() && zDO.GetInt(ZDOVars.s_inUse, 0) == 0) || Object.op_Implicit((Object)(object)((Component)val2).GetComponent<RuneLectern>()); if (flag) { zDO.Set("Runebound.Lease", text); zDO.SetOwner(peer.m_uid); ZDOMan.instance.ForceSendZDO(peer.m_uid, val); } ZPackage val5 = new ZPackage(); val5.Write(val); val5.Write(text); val5.Write(flag); rpc.Invoke("Runebound_Yielded", new object[1] { val5 }); } } }); } } internal static void Local(ZPackage input, Action<ZPackage> reply) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown if (Object.op_Implicit((Object)(object)ZNet.instance) && ZNet.instance.IsServer() && !ZNet.instance.IsDedicated()) { HandleBatch(ZNet.GetUID(), null, new ZPackage(input.GetArray()), reply); } } internal static byte[] Encode(ItemData item) { //IL_0008: 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_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown Inventory val = new Inventory("", (Sprite)null, 1, 1); ItemData val2 = item.Clone(); val2.m_stack = 1; val2.m_gridPos = new Vector2i(0, 0); val2.m_equipped = false; val.GetAllItems().Add(val2); return Serialize(val); } private static byte[] Serialize(Inventory inventory) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown ZPackage val = new ZPackage(); inventory.Save(val); return val.GetArray(); } private static void HandleBatch(long sender, ZNetPeer peer, ZPackage packet, Action<ZPackage> respond) { //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Expected O, but got Unknown if (journalUnavailable || packet.Size() < 4 || packet.Size() > 524288) { return; } int num = packet.ReadInt(); if (num < 1 || num > 32) { return; } List<ZPackage> list = new List<ZPackage>(num); HashSet<string> hashSet = new HashSet<string>(); for (int i = 0; i < num; i++) { if (packet.Size() - packet.GetPos() < 4) { return; } int num2 = packet.ReadInt(); if (num2 <= 0 || num2 > 65696 || num2 > packet.Size() - packet.GetPos()) { return; } ZPackage val = new ZPackage(packet.ReadByteArray(num2)); try { string text = val.ReadString(); if (!Guid.TryParseExact(text, "N", out var _) || !hashSet.Add(text)) { return; } } catch (IOException) { return; } catch (FormatException) { return; } val.SetPos(0); list.Add(val); } if (packet.Size() != packet.GetPos()) { return; } foreach (ZPackage item in list) { Handle(sender, peer, item, Collect); } void Collect(ZPackage answer) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Expected O, but got Unknown ZPackage val2 = new ZPackage(); val2.Write(1); val2.Write(answer.ReadString()); val2.Write(answer.ReadInt()); val2.Write(answer.ReadString()); respond(new ZPackage(val2.GetArray())); } } private static string Subject(ZNetPeer peer, long characterId) { return ((peer == null) ? "host" : peer.m_socket.GetHostName()) + "/" + characterId.ToString(CultureInfo.InvariantCulture) + "/"; } private static void Handle(long sender, ZNetPeer peer, ZPackage p, Action<ZPackage> respond) { //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_02d2: Unknown result type (might be due to invalid IL or missing references) //IL_02d8: Unknown result type (might be due to invalid IL or missing references) //IL_0321: Unknown result type (might be due to invalid IL or missing references) //IL_035f: Unknown result type (might be due to invalid IL or missing references) //IL_0376: Unknown result type (might be due to invalid IL or missing references) if (p.Size() > 65696) { return; } Operation op = null; try { Initialize(); string text = p.ReadString(); if (!Guid.TryParseExact(text, "N", out var result) || result.ToString("N") != text) { return; } op = new Operation { Id = text, Sender = sender, Peer = peer, Respond = respond, Desk = p.ReadZDOID(), Target = p.ReadZDOID(), Kind = p.ReadInt(), Tier = p.ReadInt(), X = p.ReadInt(), Y = p.ReadInt(), Amount = p.ReadInt() }; int num = p.ReadInt(); if (num < 0 || num > 65536 || num != p.Size() - p.GetPos()) { Answer(op, 0, "Invalid item data."); return; } op.Item = p.ReadByteArray(num); long num2; if (peer != null) { ZDO zDO = ZDOMan.instance.GetZDO(peer.m_characterID); num2 = ((zDO != null) ? zDO.GetLong(ZDOVars.s_playerID, 0L) : 0); } else { num2 = Player.m_localPlayer.GetPlayerID(); } long num3 = num2; if (num3 == 0L) { Answer(op, 2, "Waiting for the player to load."); return; } op.Character = num3; op.Subject = Subject(peer, num3); using (SHA256 sHA = SHA256.Create()) { byte[] bytes = Encoding.UTF8.GetBytes(op.Subject); sHA.TransformBlock(bytes, 0, bytes.Length, bytes, 0); byte[] array = p.GetArray(); sHA.TransformFinalBlock(array, 0, array.Length); op.Digest = Convert.ToBase64String(sHA.Hash); } op.File = Path.Combine(directory, text); op.Marker = text + ":" + op.Digest; if (Active.TryGetValue(text, out var value)) { if (value.Marker != op.Marker) { Answer(op, 2, "Transfer identity conflict."); } else { value.Respond = respond; } } else { if (ResolveReceipt(op)) { return; } if (Active.Count >= 256 || Active.Values.Count((Operation x) => x.Subject == op.Subject) >= 64) { Answer(op, 2, "Waiting for the current transfers."); return; } if (!Authorized(op, default(ZDOID), out var _, out var _)) { Answer(op, 0, "The selected chest or Runekeeper is unavailable."); return; } Active.Add(op.Id, op); if (Waiting.TryGetValue(op.Target, out var value2)) { value2.Add(op); return; } value2 = new List<Operation> { op }; Waiting.Add(op.Target, value2); ZDO zDO2 = ZDOMan.instance.GetZDO(op.Target); op.OriginalOwner = zDO2.GetOwner(); op.Token = Guid.NewGuid().ToString("N"); op.Deadline = Time.unscaledTime + 6f; if (op.OriginalOwner != ZNet.GetUID()) { ZNetPeer peer2 = ZNet.instance.GetPeer(op.OriginalOwner); if (peer2 == null || !peer2.IsReady()) { Release(value2, "The chest owner has left."); } else { RequestLease(op, peer2); } } } } catch (Exception ex) { Debug.LogWarning((object)("Runebound transfer request: " + ex.Message)); if (op != null) { Answer(op, 2, "The transfer could not be verified."); } } } private static void RequestLease(Operation holder, ZNetPeer owner) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown //IL_0019: Unknown result type (might be due to invalid IL or missing references) holder.RetryLease = Time.unscaledTime + 0.25f; ZPackage val = new ZPackage(); val.Write(holder.Target); val.Write(holder.Token); owner.m_rpc.Invoke("Runebound_Yield", new object[1] { val }); } private static bool Authorized(Operation op, ZDOID lease, out int tier, out DedicatedChest chest) { //IL_0019: 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_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) chest = null; tier = 0; if (op.Target == ZDOID.None) { return false; } if (op.Peer != null) { if (ZNet.instance.GetPeer(op.Sender) == op.Peer) { ZDO zDO = ZDOMan.instance.GetZDO(op.Peer.m_characterID); if (((zDO != null) ? new long?(zDO.GetLong(ZDOVars.s_playerID, 0L)) : ((long?)null)) == op.Character) { goto IL_00bc; } } return false; } goto IL_00bc; IL_00bc: if (!DedicatedSnapshot.TryRead(op.Sender, op.Desk, out tier, out var chests, op.Target, lease, includeItems: false)) { return false; } if (op.Kind == 3) { if (op.Item.Length == 0 && op.Target == op.Desk && tier == op.Tier) { return tier < 4; } return false; } chest = chests.FirstOrDefault((DedicatedChest c) => c.Id == op.Target); if ((op.Kind == 1 || op.Kind == 2) && chest != null) { return op.Amount > 0; } return false; } private static void Apply(Operation op) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Expected O, but got Unknown //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Expected O, but got Unknown //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Expected O, but got Unknown //IL_0303: Unknown result type (might be due to invalid IL or missing references) ZDO zDO = ZDOMan.instance.GetZDO(op.Target); if (zDO == null || zDO.GetOwner() != ZNet.GetUID() || !Authorized(op, op.Target, out var tier, out var chest)) { Finish(op, 0, "Access or storage changed. Try again."); return; } byte[] array = null; if (op.Kind != 3) { Inventory val = new Inventory("", (Sprite)null, chest.Width, chest.Height); byte[] byteArray = zDO.GetByteArray(ZDOVars.s_items, (byte[])null); if (byteArray != null) { val.Load(new ZPackage(byteArray)); } if (!ChangeInventory(op, val)) { Finish(op, 0, "The stack changed or the chest has insufficient space."); return; } array = Serialize(val); } string text = zDO.GetString("Runebound.StorageObject", ""); if (text.Length == 0) { text = Guid.NewGuid().ToString("N"); } op.ObjectIdentity = text; ZPackage val2 = new ZPackage(); val2.Write(op.Digest); val2.Write(zDO.GetPosition()); val2.Write((long)SaveSystem.GetSaveNumber()); val2.Write(op.Subject); val2.Write(text); bool flag = array != null && CanJournal(zDO); if (flag) { CommitJournal(op, zDO, array, val2); } else { WriteRecord(op.File + ".pending", val2.GetArray()); } op.Prepared = true; if (op.Kind == 3) { zDO.Set("RuneLectern.Tier", tier + 1); } else { zDO.Set(ZDOVars.s_items, array); } if (flag) { zDO.Set("Runebound.JournalRevision", journalEntries[op.Id].Revision); } zDO.Set("Runebound.StorageObject", text); IEnumerable<string> values = (from other in Active.Values where other.Target == op.Target && other.Applied select other.Marker).Concat(new string[1] { op.Marker }); zDO.Set("Runebound.LastMutation", string.Join("\n", values)); if (!Active.Values.Any((Operation other) => other.Applied)) { firstAppliedAt = Time.unscaledTime; } op.Applied = true; ZNetView val3 = ZNetScene.instance.FindInstance(zDO); Container arg = default(Container); if (Object.op_Implicit((Object)(object)val3) && ((Component)val3).TryGetComponent<Container>(ref arg)) { Reload(arg); } ZDOMan.instance.ForceSendZDO(op.Target); if (flag) { Remember(op.Id, (player: op.Subject, target: text)); Finish(op, 1, "Transfer completed."); } } private static bool ChangeInventory(Operation op, Inventory inventory) { //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Expected O, but got Unknown //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Expected O, but got Unknown if (op.Item.Length < 8 || BitConverter.ToInt32(op.Item, 0) != 110 || BitConverter.ToUInt16(op.Item, 4) != 1) { return false; } if (op.Kind == 2) { ItemData itemAt = inventory.GetItemAt(op.X, op.Y); if (itemAt == null || itemAt.m_stack < op.Amount || !Encode(itemAt).SequenceEqual(op.Item)) { return false; } inventory.RemoveItem(itemAt, op.Amount); return true; } Inventory val = new Inventory("", (Sprite)null, 1, 1); val.Load(new ZPackage(op.Item)); ItemData val2 = val.GetAllItems().SingleOrDefault(); if (val2 == null || op.Amount > val2.m_shared.m_maxStackSize || !Encode(val2).SequenceEqual(op.Item)) { return false; } val2.m_stack = op.Amount; return StorageTransfer.Move(val, val2, (Inventory[])(object)new Inventory[1] { inventory }, op.Amount) == op.Amount; } private static void RestoreOwner(Operation op) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) if (JournalHolds(op.Target)) { return; } ZDO zDO = ZDOMan.instance.GetZDO(op.Target); if (zDO != null && zDO.GetOwner() == ZNet.GetUID() && !(zDO.GetString("Runebound.Lease", "") != op.Token)) { zDO.RemoveString(StringExtensionMethods.GetStableHashCode("Runebound.Lease")); ZNetPeer peer = ZNet.instance.GetPeer(op.OriginalOwner); if (peer != null && peer.IsReady()) { zDO.SetOwner(op.OriginalOwner); ZDOMan.instance.ForceSendZDO(op.OriginalOwner, op.Target); }