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 NjordWarehouseKeeper v1.3.3
NjordWarehouseKeeper.dll
Decompiled a day ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using Newtonsoft.Json; using NjordWarehouseKeeper.Client; using NjordWarehouseKeeper.Patches; using NjordWarehouseKeeper.Storage; using NjordWarehouseKeeper.UI; 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: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: IgnoresAccessChecksTo("assembly_googleanalytics")] [assembly: IgnoresAccessChecksTo("assembly_guiutils")] [assembly: IgnoresAccessChecksTo("assembly_lux")] [assembly: IgnoresAccessChecksTo("assembly_postprocessing")] [assembly: IgnoresAccessChecksTo("assembly_simplemeshcombine")] [assembly: IgnoresAccessChecksTo("assembly_sunshafts")] [assembly: IgnoresAccessChecksTo("assembly_utils")] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: IgnoresAccessChecksTo("gui_framework")] [assembly: IgnoresAccessChecksTo("SoftReferenceableAssets")] [assembly: IgnoresAccessChecksTo("Splatform")] [assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")] [assembly: AssemblyCompany("GitMCP")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("Njord, Warehouse Keeper. Lists and moves items across nearby chests.")] [assembly: AssemblyFileVersion("1.3.3.0")] [assembly: AssemblyInformationalVersion("1.3.3+fbf714d857d5f71eb7c7e5b6893550214cbafced")] [assembly: AssemblyProduct("NjordWarehouseKeeper")] [assembly: AssemblyTitle("NjordWarehouseKeeper")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.3.3.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] internal sealed class IsReadOnlyAttribute : Attribute { } [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 NjordWarehouseKeeper { internal static class Localizations { private sealed class Catalog { internal string Language { get; } internal Dictionary<string, string> Translations { get; } internal Catalog(string language, Dictionary<string, string> translations) { Language = language; Translations = translations; } } private const string ResourceMarker = ".Localization."; private const string ResourceExtension = ".json"; private static readonly Regex Placeholder = new Regex("\\{\\d+\\}", RegexOptions.Compiled); private static readonly HashSet<string> ValheimLanguages = new HashSet<string>(StringComparer.Ordinal) { "English", "Swedish", "French", "Italian", "German", "Spanish", "Russian", "Romanian", "Bulgarian", "Macedonian", "Finnish", "Danish", "Norwegian", "Icelandic", "Turkish", "Lithuanian", "Czech", "Hungarian", "Slovak", "Polish", "Dutch", "Portuguese_European", "Portuguese_Brazilian", "Chinese", "Chinese_Trad", "Japanese", "Korean", "Hindi", "Thai", "Abenaki", "Croatian", "Georgian", "Greek", "Serbian", "Ukrainian", "Latvian" }; internal static void Register() { try { List<Catalog> list = LoadCatalogs(typeof(Localizations).Assembly); Validate(list); CustomLocalization localization = LocalizationManager.Instance.GetLocalization(); foreach (Catalog item in list.OrderBy((Catalog c) => (!(c.Language == "English")) ? 1 : 0)) { string language = item.Language; localization.AddTranslation(ref language, item.Translations); } NjordWarehouseKeeperPlugin.Log.LogInfo((object)("Registered " + list.Count + " localization catalog(s): " + string.Join(", ", from c in list select c.Language into n orderby n select n))); } catch (Exception ex) { NjordWarehouseKeeperPlugin.Log.LogError((object)("Could not register Njord localization catalogs: " + ex)); } } private static List<Catalog> LoadCatalogs(Assembly assembly) { List<Catalog> list = new List<Catalog>(); string[] manifestResourceNames = assembly.GetManifestResourceNames(); foreach (string text in manifestResourceNames) { if (!text.EndsWith(".json", StringComparison.OrdinalIgnoreCase)) { continue; } int num = text.LastIndexOf(".Localization.", StringComparison.OrdinalIgnoreCase); if (num < 0) { continue; } int num2 = num + ".Localization.".Length; int num3 = text.Length - num2 - ".json".Length; if (num3 <= 0) { continue; } string text2 = text.Substring(num2, num3); if (text2.IndexOf('.') >= 0) { continue; } if (!ValheimLanguages.Contains(text2)) { NjordWarehouseKeeperPlugin.Log.LogWarning((object)("Localization catalog '" + text2 + "' is not a Valheim language id and will not be selected in-game.")); } using Stream stream = assembly.GetManifestResourceStream(text); if (stream == null) { throw new InvalidOperationException("Embedded localization resource is unavailable: " + text); } using StreamReader streamReader = new StreamReader(stream); Dictionary<string, string> dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(streamReader.ReadToEnd()); if (dictionary == null || dictionary.Count == 0) { throw new InvalidDataException("Localization catalog is empty: " + text); } list.Add(new Catalog(text2, dictionary)); } return list; } private static void Validate(IReadOnlyList<Catalog> catalogs) { Catalog catalog = catalogs.FirstOrDefault((Catalog c) => string.Equals(c.Language, "English", StringComparison.OrdinalIgnoreCase)); if (catalog == null) { throw new InvalidDataException("English localization catalog is required."); } string[] array = (from @group in catalogs.GroupBy<Catalog, string>((Catalog c) => c.Language, StringComparer.OrdinalIgnoreCase) where @group.Count() > 1 select @group.Key).ToArray(); if (array.Length != 0) { throw new InvalidDataException("Duplicate localization languages: " + string.Join(", ", array)); } HashSet<string> hashSet = new HashSet<string>(catalog.Translations.Keys, StringComparer.Ordinal); List<string> list = new List<string>(); foreach (Catalog catalog2 in catalogs) { HashSet<string> hashSet2 = new HashSet<string>(catalog2.Translations.Keys, StringComparer.Ordinal); string[] array2 = (from key in hashSet.Except(hashSet2) orderby key select key).ToArray(); string[] array3 = (from key in hashSet2.Except(hashSet) orderby key select key).ToArray(); if (array2.Length != 0) { list.Add(catalog2.Language + " is missing: " + string.Join(", ", array2)); } if (array3.Length != 0) { list.Add(catalog2.Language + " has unexpected keys: " + string.Join(", ", array3)); } foreach (string item in from key in hashSet.Intersect(hashSet2) orderby key select key) { string[] array4 = Placeholders(catalog.Translations[item]); string[] array5 = Placeholders(catalog2.Translations[item]); if (!array4.SequenceEqual(array5)) { list.Add(catalog2.Language + " changes placeholders for " + item + ": expected " + string.Join(", ", array4) + ", got " + string.Join(", ", array5)); } } } if (list.Count > 0) { throw new InvalidDataException(string.Join("; ", list)); } } private static string[] Placeholders(string value) { return (from Match match in Placeholder.Matches(value ?? string.Empty) select match.Value).OrderBy<string, string>((string item) => item, StringComparer.Ordinal).ToArray(); } } internal static class NjordLook { internal static void Attach(GameObject host) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected O, but got Unknown //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)host == (Object)null || (Object)(object)host.transform.Find("NjordBody") != (Object)null) { return; } GameObject val = PrefabManagerGetPlayer(); if ((Object)(object)val == (Object)null) { NjordWarehouseKeeperPlugin.Log.LogWarning((object)"Could not find the Player prefab to dress Njord."); return; } GameObject val2 = new GameObject("NjordHide"); val2.SetActive(false); GameObject val3 = Object.Instantiate<GameObject>(val, val2.transform); ((Object)val3).name = "NjordBody"; val3.transform.localPosition = Vector3.zero; val3.transform.localRotation = Quaternion.identity; val3.transform.localScale = Vector3.one; Strip(val3); WireView(val3, host); NjordLookHook njordLookHook = val3.GetComponent<NjordLookHook>(); if ((Object)(object)njordLookHook == (Object)null) { njordLookHook = val3.AddComponent<NjordLookHook>(); } val3.transform.SetParent(host.transform, false); Object.DestroyImmediate((Object)(object)val2); val3.SetActive(true); njordLookHook.Bind(host); } internal static void HideHostVisuals(GameObject host) { if ((Object)(object)host == (Object)null) { return; } Renderer[] componentsInChildren = host.GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if (!((Object)(object)val == (Object)null) && !IsBody(((Component)val).transform)) { val.enabled = false; } } Animator component = host.GetComponent<Animator>(); if ((Object)(object)component != (Object)null) { ((Behaviour)component).enabled = false; } } internal static void Dress(VisEquipment vis, Container hub = null) { if (!((Object)(object)vis == (Object)null)) { NjordOutfit.Apply(((Object)(object)hub != (Object)null) ? hub : (((Object)(object)vis.m_nview != (Object)null) ? ((Component)vis.m_nview).GetComponent<Container>() : (((Object)(object)vis.m_nViewOverride != (Object)null) ? ((Component)vis.m_nViewOverride).GetComponent<Container>() : null)), vis, ((Component)vis).GetComponent<Animator>()); } } private static void WireView(GameObject body, GameObject host) { VisEquipment component = body.GetComponent<VisEquipment>(); ZNetView val = (((Object)(object)host == (Object)null) ? null : host.GetComponent<ZNetView>()); if (!((Object)(object)component == (Object)null)) { component.m_nViewOverride = val; component.m_nview = val; component.m_playerComponent = null; component.m_isPlayer = true; component.m_isArmorStand = false; } } private static void Strip(GameObject body) { MonoBehaviour[] componentsInChildren = body.GetComponentsInChildren<MonoBehaviour>(true); foreach (MonoBehaviour val in componentsInChildren) { if (!((Object)(object)val == (Object)null) && !(val is VisEquipment) && !(val is NjordLookHook)) { Object.DestroyImmediate((Object)(object)val, true); } } ZNetView[] componentsInChildren2 = body.GetComponentsInChildren<ZNetView>(true); for (int j = 0; j < componentsInChildren2.Length; j++) { if ((Object)(object)componentsInChildren2[j] != (Object)null) { Object.DestroyImmediate((Object)(object)componentsInChildren2[j], true); } } ZSyncTransform[] componentsInChildren3 = body.GetComponentsInChildren<ZSyncTransform>(true); for (int k = 0; k < componentsInChildren3.Length; k++) { if ((Object)(object)componentsInChildren3[k] != (Object)null) { Object.DestroyImmediate((Object)(object)componentsInChildren3[k], true); } } Rigidbody[] componentsInChildren4 = body.GetComponentsInChildren<Rigidbody>(true); for (int l = 0; l < componentsInChildren4.Length; l++) { if ((Object)(object)componentsInChildren4[l] != (Object)null) { Object.DestroyImmediate((Object)(object)componentsInChildren4[l], true); } } Collider[] componentsInChildren5 = body.GetComponentsInChildren<Collider>(true); for (int m = 0; m < componentsInChildren5.Length; m++) { if ((Object)(object)componentsInChildren5[m] != (Object)null) { Object.DestroyImmediate((Object)(object)componentsInChildren5[m], true); } } Animator component = body.GetComponent<Animator>(); if ((Object)(object)component != (Object)null) { component.applyRootMotion = false; component.cullingMode = (AnimatorCullingMode)0; component.fireEvents = false; ((Behaviour)component).enabled = true; } } private static bool IsBody(Transform t) { while ((Object)(object)t != (Object)null) { if (((Object)t).name == "NjordBody") { return true; } t = t.parent; } return false; } private static GameObject PrefabManagerGetPlayer() { if (PrefabManager.Instance == null) { return null; } return PrefabManager.Instance.GetPrefab("Player"); } internal static string FindArmor(ItemType type, string prefab, params string[] needles) { //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) ObjectDB instance = ObjectDB.instance; if ((Object)(object)instance == (Object)null) { return prefab; } if ((Object)(object)instance.GetItemPrefab(prefab) != (Object)null) { return prefab; } if (instance.m_items == null) { return prefab; } for (int i = 0; i < instance.m_items.Count; i++) { GameObject val = instance.m_items[i]; ItemDrop val2 = (((Object)(object)val == (Object)null) ? null : val.GetComponent<ItemDrop>()); SharedData val3 = (((Object)(object)val2 == (Object)null) ? null : val2.m_itemData?.m_shared); if (val3 == null || val3.m_itemType != type) { continue; } string text = val3.m_name ?? ""; string text2 = ((Object)val).name ?? ""; foreach (string value in needles) { if (text.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0) { return ((Object)val).name; } } } return prefab; } } internal sealed class NjordLookHook : MonoBehaviour { private static readonly string[] IdleEmotes = new string[8] { "wave", "flex", "cheer", "challenge", "thumbsup", "nono", "point", "comehere" }; private const float IdleRange = 14f; private GameObject _host; private Animator _animator; private VisEquipment _vis; private float _nextEmote; private float _nextApply; internal void Bind(GameObject host) { _host = host; _animator = ((Component)this).GetComponent<Animator>(); _vis = ((Component)this).GetComponent<VisEquipment>(); WireAndDress(); _nextEmote = Time.time + Random.Range(16f, 28f); } internal void Wave() { PlayEmote("wave"); } private void Awake() { if ((Object)(object)_animator == (Object)null) { _animator = ((Component)this).GetComponent<Animator>(); } if ((Object)(object)_vis == (Object)null) { _vis = ((Component)this).GetComponent<VisEquipment>(); } } private void Start() { WireAndDress(); } private void Update() { TickPoseKey(); if (Time.time >= _nextApply) { _nextApply = Time.time + 0.25f; WireAndDress(); } else { HoldAnimator(); } IdleEmote(); } private void WireAndDress() { try { NjordOutfit.Apply(Hub(), _vis, _animator); } catch (Exception ex) { NjordWarehouseKeeperPlugin.Log.LogWarning((object)("Njord look failed: " + ex)); } } private void HoldAnimator() { NjordPose njordPose = CurrentPose(); bool num = njordPose == NjordPose.Drawn; ZDO val = Zdo(); int drawnRight = ((num && val != null) ? val.GetInt("njord.handR", 0) : 0); int drawnLeft = ((num && val != null) ? val.GetInt("njord.handL", 0) : 0); NjordOutfit.ApplyAnimator(_animator, njordPose, drawnRight, drawnLeft); if ((Object)(object)_vis != (Object)null && (Object)(object)_vis.m_nview != (Object)null) { try { _vis.UpdateVisuals(); } catch (Exception ex) { NjordWarehouseKeeperPlugin.Log.LogWarning((object)("Njord visuals failed: " + ex)); } } } private void TickPoseKey() { if (!CanTakePoseInput() || (!ZInput.GetKeyDown((KeyCode)114, false) && !Input.GetKeyDown((KeyCode)114))) { return; } Container val = Hub(); if (!((Object)(object)val == (Object)null)) { NjordPose pose = NjordOutfit.ReadPose(val); NjordOutfit.CyclePose(val); Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)2, Localization.instance.Localize(NjordOutfit.ActionToken(pose)), 0, (Sprite)null, false); } } } private bool CanTakePoseInput() { if (GUIManager.IsHeadless()) { return false; } try { if (Console.IsVisible() || Menu.IsVisible() || TextInput.IsVisible()) { return false; } } catch (Exception) { return false; } if ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus()) { return false; } if (NjordWarehouseKeeperPanel.SearchHasFocus()) { return false; } Container val = Hub(); if ((Object)(object)val == (Object)null) { return false; } if ((Object)(object)NjordWarehouseKeeperMarker.OpenHub != (Object)null) { return (Object)(object)NjordWarehouseKeeperMarker.OpenHub == (Object)(object)val; } Player localPlayer = Player.m_localPlayer; GameObject val2 = (((Object)(object)localPlayer == (Object)null) ? null : ((Humanoid)localPlayer).GetHoverObject()); if ((Object)(object)val2 == (Object)null) { return false; } NjordWarehouseKeeperMarker componentInParent = val2.GetComponentInParent<NjordWarehouseKeeperMarker>(); if ((Object)(object)componentInParent != (Object)null) { return (Object)(object)((Component)componentInParent).gameObject == (Object)(object)((Component)val).gameObject; } return false; } private void IdleEmote() { if (!(Time.time < _nextEmote)) { _nextEmote = Time.time + Random.Range(16f, 30f); if (PlayerNearby(14f)) { PlayEmote(IdleEmotes[Random.Range(0, IdleEmotes.Length)]); } } } private bool PlayerNearby(float range) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead()) { return false; } return Vector3.Distance(((Component)localPlayer).transform.position, ((Component)this).transform.position) <= range; } private void PlayEmote(string emote) { if (!((Object)(object)_animator == (Object)null) && !string.IsNullOrEmpty(emote)) { _animator.ResetTrigger("emote_stop"); _animator.SetTrigger("emote_" + emote); } } private NjordPose CurrentPose() { return NjordOutfit.ReadPose(Hub()); } private Container Hub() { if ((Object)(object)_host != (Object)null) { return _host.GetComponent<Container>(); } Transform parent = ((Component)this).transform.parent; if (!((Object)(object)parent == (Object)null)) { return ((Component)parent).GetComponent<Container>(); } return null; } private ZDO Zdo() { ZNetView val = NjordOutfit.ViewOf(Hub()); if (!((Object)(object)val == (Object)null) && val.IsValid()) { return val.GetZDO(); } return null; } } internal enum NjordPose { Sheathed, Drawn } internal enum NjordSlot { Chest, Legs, Helmet, Shoulder, Utility, Trinket, HandLeft, HandRight } internal static class NjordOutfit { internal const int PoseCount = 2; private const string PoseKey = "njord.pose"; private const string ChestKey = "njord.chest"; private const string LegsKey = "njord.legs"; private const string HelmetKey = "njord.helmet"; private const string ShoulderKey = "njord.shoulder"; private const string ShoulderVarKey = "njord.shoulder.var"; private const string ShoulderQualKey = "njord.shoulder.q"; private const string UtilityKey = "njord.utility"; private const string TrinketKey = "njord.trinket"; private const string HandLeftKey = "njord.handL"; private const string HandLeftVarKey = "njord.handL.var"; private const string HandLeftQualKey = "njord.handL.q"; private const string HandRightKey = "njord.handR"; private const string HandRightQualKey = "njord.handR.q"; internal static bool IsEquipable(ItemData item) { NjordSlot slot; return TrySlot(item, out slot); } internal static bool TrySlot(ItemData item, out NjordSlot slot) { //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_001d: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Expected I4, but got Unknown //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) slot = NjordSlot.Chest; SharedData val = item?.m_shared; if (val == null) { return false; } ItemType val2 = val.m_itemType; if ((int)val.m_attachOverride != 0) { val2 = val.m_attachOverride; } switch (val2 - 3) { case 4: slot = NjordSlot.Chest; return true; case 8: slot = NjordSlot.Legs; return true; case 3: slot = NjordSlot.Helmet; return true; case 14: slot = NjordSlot.Shoulder; return true; case 15: slot = NjordSlot.Utility; return true; case 21: slot = NjordSlot.Trinket; return true; case 1: case 2: case 19: slot = NjordSlot.HandLeft; return true; case 0: case 11: case 12: case 16: case 17: slot = NjordSlot.HandRight; return true; default: return false; } } internal static bool Toggle(Container hub, ItemData item) { if ((Object)(object)hub == (Object)null || !TrySlot(item, out var slot)) { return false; } int num = PrefabHash(item); if (num == 0) { return false; } bool flag = IsWearing(hub, item); WriteSlot(hub, slot, (!flag) ? num : 0, item, flag); if (!flag) { ClearConflicts(hub, item, slot); } Apply(hub); return true; } internal static bool IsWearing(Container hub, ItemData item) { if ((Object)(object)hub == (Object)null || !TrySlot(item, out var slot)) { return false; } ZDO val = Zdo(hub); if (val == null) { return false; } if (ReadHash(val, slot) == PrefabHash(item)) { return PrefabHash(item) != 0; } return false; } internal static NjordPose CyclePose(Container hub) { NjordPose njordPose = (NjordPose)((int)(ReadPose(hub) + 1) % 2); WritePose(hub, njordPose); Apply(hub); return njordPose; } internal static NjordPose ReadPose(Container hub) { ZDO val = Zdo(hub); if (val == null) { return NjordPose.Sheathed; } int num = val.GetInt("njord.pose", 0); if (num < 0 || num >= 2) { return NjordPose.Sheathed; } return (NjordPose)num; } internal static string ActionToken(NjordPose pose) { if (pose != NjordPose.Drawn) { return "$njord_pose_draw"; } return "$njord_pose_sheathe"; } internal static void Apply(Container hub) { if (!((Object)(object)hub == (Object)null)) { NjordLookHook componentInChildren = ((Component)hub).GetComponentInChildren<NjordLookHook>(true); VisEquipment vis = (((Object)(object)componentInChildren != (Object)null) ? ((Component)componentInChildren).GetComponent<VisEquipment>() : ((Component)hub).GetComponentInChildren<VisEquipment>(true)); Apply(hub, vis, ((Object)(object)componentInChildren != (Object)null) ? ((Component)componentInChildren).GetComponent<Animator>() : null); } } internal static void Apply(Container hub, VisEquipment vis, Animator animator) { if ((Object)(object)vis == (Object)null) { return; } ZNetView val = ViewOf(hub); if ((Object)(object)val == (Object)null) { val = (((Object)(object)vis.m_nViewOverride != (Object)null) ? vis.m_nViewOverride : vis.m_nview); } if ((Object)(object)val != (Object)null) { vis.m_nViewOverride = val; vis.m_nview = val; } vis.m_playerComponent = null; vis.m_isPlayer = true; vis.m_isArmorStand = false; if ((Object)(object)val != (Object)null && val.IsValid() && !val.IsOwner()) { val.ClaimOwnership(); } if ((Object)(object)vis.m_nview == (Object)null) { ApplyAnimator(animator, ReadPose(hub), 0, 0); return; } ZDO val2 = (((Object)(object)val != (Object)null && val.IsValid()) ? val.GetZDO() : null); bool flag = val2 != null && val.IsOwner(); int hash = ((val2 != null) ? val2.GetInt("njord.chest", 0) : 0); int hash2 = ((val2 != null) ? val2.GetInt("njord.legs", 0) : 0); int num = ((val2 != null) ? val2.GetInt("njord.helmet", 0) : 0); int num2 = ((val2 != null) ? val2.GetInt("njord.shoulder", 0) : 0); int num3 = ((val2 != null) ? val2.GetInt("njord.shoulder.var", 0) : 0); int num4 = ((val2 != null) ? val2.GetInt("njord.shoulder.q", 0) : 0); int num5 = ((val2 != null) ? val2.GetInt("njord.utility", 0) : 0); int num6 = ((val2 != null) ? val2.GetInt("njord.trinket", 0) : 0); int hash3 = ((val2 != null) ? val2.GetInt("njord.handL", 0) : 0); int num7 = ((val2 != null) ? val2.GetInt("njord.handL.var", 0) : 0); int num8 = ((val2 != null) ? val2.GetInt("njord.handL.q", 0) : 0); int hash4 = ((val2 != null) ? val2.GetInt("njord.handR", 0) : 0); int num9 = ((val2 != null) ? val2.GetInt("njord.handR.q", 0) : 0); NjordPose njordPose = ReadPose(hub); bool flag2 = njordPose == NjordPose.Drawn; hash = OrDefault(hash, NjordSlot.Chest); hash2 = OrDefault(hash2, NjordSlot.Legs); hash3 = OrDefault(hash3, NjordSlot.HandLeft); hash4 = OrDefault(hash4, NjordSlot.HandRight); try { WriteVisZdo(val2, flag2, hash, hash2, num, num2, num3, num4, num5, num6, hash3, num7, num8, hash4, num9); vis.SetHelmetItem(num); vis.SetShoulderItem(num2, num3, num4); vis.SetUtilityItem(num5); vis.SetTrinketItem((num6 == 0) ? "" : PrefabName(num6)); vis.SetChestItem(hash); vis.SetLegItem(hash2); if (flag2) { vis.SetLeftItem(hash3, num7, num8); vis.SetRightItem(hash4, num9); vis.SetLeftBackItem(0, 0, 0); vis.SetRightBackItem(0, 0); } else { vis.SetLeftItem(0, 0, 0); vis.SetRightItem(0, 0); vis.SetLeftBackItem(hash3, num7, num8); vis.SetRightBackItem(hash4, num9); } if (flag) { EnsureHair(vis, val2); } vis.UpdateVisuals(); } catch (Exception ex) { NjordWarehouseKeeperPlugin.Log.LogWarning((object)("Njord visuals failed: " + ex)); } ApplyAnimator(animator, njordPose, flag2 ? hash4 : 0, flag2 ? hash3 : 0); } internal static ZNetView ViewOf(Container hub) { if ((Object)(object)hub == (Object)null) { return null; } if ((Object)(object)hub.m_nview != (Object)null) { return hub.m_nview; } return ((Component)hub).GetComponent<ZNetView>(); } internal static void ApplyAnimator(Animator animator, NjordPose pose, int drawnRight, int drawnLeft) { //IL_00c7: 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_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Expected I4, but got Unknown //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)animator == (Object)null || !animator.isInitialized) { return; } try { animator.SetBool("encumbered", false); animator.SetBool("crouching", false); animator.SetBool("flying", false); animator.SetBool("inWater", false); animator.SetBool("wakeup", false); animator.SetBool("intro", false); animator.SetBool("dead", false); animator.SetBool("onGround", true); animator.SetFloat("forward_speed", 0f); animator.SetFloat("sideway_speed", 0f); animator.SetFloat("turn_speed", 0f); animator.ResetTrigger("emote_stop"); animator.SetBool("emote_sit", false); animator.SetBool("emote_flex", false); AnimationState val = (AnimationState)0; if (pose == NjordPose.Drawn) { val = DrawnState(drawnRight, drawnLeft); } animator.SetFloat("statef", (float)val); animator.SetInteger("statei", (int)val); } catch (Exception) { } } internal static int PrefabHash(ItemData item) { string text = PrefabName(item); if (!string.IsNullOrEmpty(text)) { return StringExtensionMethods.GetStableHashCode(text); } return 0; } internal static string PrefabName(ItemData item) { if ((Object)(object)item?.m_dropPrefab != (Object)null) { return Utils.GetPrefabName(item.m_dropPrefab); } GameObject val = FindPrefab(item?.m_shared?.m_name); if (!((Object)(object)val == (Object)null)) { return Utils.GetPrefabName(val); } return ""; } private static void WritePose(Container hub, NjordPose pose) { ZDO val = OwnZdo(hub); if (val != null) { val.Set("njord.pose", (int)pose); } } private static void WriteSlot(Container hub, NjordSlot slot, int hash, ItemData item, bool clear) { ZDO val = OwnZdo(hub); if (val != null) { int num = ((!clear && item != null) ? item.m_variant : 0); int num2 = ((!clear && item != null) ? item.m_quality : 0); switch (slot) { case NjordSlot.Chest: val.Set("njord.chest", hash); break; case NjordSlot.Legs: val.Set("njord.legs", hash); break; case NjordSlot.Helmet: val.Set("njord.helmet", hash); break; case NjordSlot.Shoulder: val.Set("njord.shoulder", hash); val.Set("njord.shoulder.var", num); val.Set("njord.shoulder.q", num2); break; case NjordSlot.Utility: val.Set("njord.utility", hash); break; case NjordSlot.Trinket: val.Set("njord.trinket", hash); break; case NjordSlot.HandLeft: val.Set("njord.handL", hash); val.Set("njord.handL.var", num); val.Set("njord.handL.q", num2); break; case NjordSlot.HandRight: val.Set("njord.handR", hash); val.Set("njord.handR.q", num2); break; } } } private static void ClearConflicts(Container hub, ItemData item, NjordSlot slot) { //IL_0025: 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_0038: 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_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Invalid comparison between Unknown and I4 //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Invalid comparison between Unknown and I4 //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Invalid comparison between Unknown and I4 //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Invalid comparison between Unknown and I4 //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Invalid comparison between Unknown and I4 //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010b: 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_0111: Invalid comparison between Unknown and I4 //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Invalid comparison between Unknown and I4 //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Invalid comparison between Unknown and I4 //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Invalid comparison between Unknown and I4 //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Invalid comparison between Unknown and I4 //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Invalid comparison between Unknown and I4 //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Invalid comparison between Unknown and I4 ItemType val = (item?.m_shared?.m_itemType).GetValueOrDefault(); ItemType valueOrDefault = (item?.m_shared?.m_attachOverride).GetValueOrDefault(); if ((int)valueOrDefault != 0) { val = valueOrDefault; } if ((int)val == 14 || (int)val == 22 || (int)val == 4 || (int)val == 20 || (int)val == 19) { NjordSlot slot2 = ((slot == NjordSlot.HandLeft) ? NjordSlot.HandRight : NjordSlot.HandLeft); WriteSlot(hub, slot2, 0, null, clear: true); } else { if (slot != NjordSlot.HandRight && slot != NjordSlot.HandLeft) { return; } NjordSlot njordSlot = ((slot == NjordSlot.HandLeft) ? NjordSlot.HandRight : NjordSlot.HandLeft); int num = ReadHash(Zdo(hub), njordSlot); if (num != 0) { ItemType valueOrDefault2 = (ItemOf(num)?.m_shared?.m_itemType).GetValueOrDefault(); bool num2 = (int)valueOrDefault2 == 14 || (int)valueOrDefault2 == 22 || (int)valueOrDefault2 == 4 || (int)valueOrDefault2 == 20 || (int)valueOrDefault2 == 19; bool flag = (int)valueOrDefault2 == 5 || (int)valueOrDefault2 == 15; if (num2 || (slot == NjordSlot.HandRight && !flag && njordSlot == NjordSlot.HandLeft)) { WriteSlot(hub, njordSlot, 0, null, clear: true); } } } } private static int ReadHash(ZDO zdo, NjordSlot slot) { if (zdo == null) { return 0; } return slot switch { NjordSlot.Chest => zdo.GetInt("njord.chest", 0), NjordSlot.Legs => zdo.GetInt("njord.legs", 0), NjordSlot.Helmet => zdo.GetInt("njord.helmet", 0), NjordSlot.Shoulder => zdo.GetInt("njord.shoulder", 0), NjordSlot.Utility => zdo.GetInt("njord.utility", 0), NjordSlot.Trinket => zdo.GetInt("njord.trinket", 0), NjordSlot.HandLeft => zdo.GetInt("njord.handL", 0), NjordSlot.HandRight => zdo.GetInt("njord.handR", 0), _ => 0, }; } private static void EnsureHair(VisEquipment vis, ZDO zdo) { if (!((Object)(object)vis == (Object)null) && zdo != null) { if (zdo.GetInt(ZDOVars.s_hairItem, 0) == 0) { vis.SetHairItem(StringExtensionMethods.GetStableHashCode("Hair4")); } if (zdo.GetInt(ZDOVars.s_beardItem, 0) == 0) { vis.SetBeardItem(StringExtensionMethods.GetStableHashCode("Beard5")); } } } private static AnimationState DrawnState(int rightHash, int leftHash) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Invalid comparison between Unknown and I4 //IL_004d: Unknown result type (might be due to invalid IL or missing references) ItemData val = ItemOf(rightHash); if (val?.m_shared != null) { return val.m_shared.m_animationState; } ItemData val2 = ItemOf(leftHash); if (val2?.m_shared != null) { if ((int)val2.m_shared.m_itemType == 15) { return (AnimationState)6; } return val2.m_shared.m_animationState; } return (AnimationState)0; } private static ItemData ItemOf(int hash) { if (hash == 0 || (Object)(object)ObjectDB.instance == (Object)null) { return null; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(hash); if (!((Object)(object)itemPrefab == (Object)null)) { return itemPrefab.GetComponent<ItemDrop>()?.m_itemData; } return null; } private static string PrefabName(int hash) { GameObject val = ((hash == 0 || (Object)(object)ObjectDB.instance == (Object)null) ? null : ObjectDB.instance.GetItemPrefab(hash)); if (!((Object)(object)val == (Object)null)) { return Utils.GetPrefabName(val); } return ""; } private static GameObject FindPrefab(string sharedName) { ObjectDB instance = ObjectDB.instance; if ((Object)(object)instance == (Object)null || instance.m_items == null || string.IsNullOrEmpty(sharedName)) { return null; } for (int i = 0; i < instance.m_items.Count; i++) { GameObject val = instance.m_items[i]; ItemDrop val2 = (((Object)(object)val == (Object)null) ? null : val.GetComponent<ItemDrop>()); if (val2?.m_itemData?.m_shared != null && val2.m_itemData.m_shared.m_name == sharedName) { return val; } } return null; } private static int OrDefault(int hash, NjordSlot slot) { if (hash == 0) { return DefaultOf(slot); } return hash; } private static int DefaultOf(NjordSlot slot) { switch (slot) { case NjordSlot.Chest: return ItemHash("ArmorRagsChest", (ItemType)7, "rag"); case NjordSlot.Legs: return ItemHash("ArmorRagsLegs", (ItemType)11, "rag"); case NjordSlot.HandLeft: return ItemHash("ShieldWood", (ItemType)5, "wood"); case NjordSlot.HandRight: { int num = ItemHash("SwordWood", (ItemType)3); if (num == 0) { return ItemHash("Club", (ItemType)3, "club"); } return num; } default: return 0; } } private static int ItemHash(string prefab, ItemType type, params string[] needles) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) ObjectDB instance = ObjectDB.instance; if ((Object)(object)instance != (Object)null && !string.IsNullOrEmpty(prefab) && (Object)(object)instance.GetItemPrefab(prefab) != (Object)null) { return StringExtensionMethods.GetStableHashCode(prefab); } if (needles == null || needles.Length == 0) { return 0; } string text = NjordLook.FindArmor(type, prefab, needles); if (!string.IsNullOrEmpty(text)) { return StringExtensionMethods.GetStableHashCode(text); } return 0; } private static void WriteVisZdo(ZDO zdo, bool drawn, int chest, int legs, int helmet, int shoulder, int shoulderVar, int shoulderQual, int utility, int trinket, int handL, int handLVar, int handLQual, int handR, int handRQual) { if (zdo != null) { zdo.Set(ZDOVars.s_chestItem, chest, false); zdo.Set(ZDOVars.s_legItem, legs, false); zdo.Set(ZDOVars.s_helmetItem, helmet, false); zdo.Set(ZDOVars.s_shoulderItem, shoulder, false); zdo.Set(ZDOVars.s_shoulderItemVariant, shoulderVar, false); zdo.Set(ZDOVars.s_shoulderItemQuality, shoulderQual, false); zdo.Set(ZDOVars.s_utilityItem, utility, false); zdo.Set(ZDOVars.s_trinketItem, trinket, false); if (drawn) { zdo.Set(ZDOVars.s_leftItem, handL, false); zdo.Set(ZDOVars.s_leftItemVariant, handLVar, false); zdo.Set(ZDOVars.s_leftItemQuality, handLQual, false); zdo.Set(ZDOVars.s_rightItem, handR, false); zdo.Set(ZDOVars.s_rightItemQuality, handRQual, false); zdo.Set(ZDOVars.s_leftBackItem, 0, false); zdo.Set(ZDOVars.s_leftBackItemVariant, 0, false); zdo.Set(ZDOVars.s_leftBackItemQuality, 0, false); zdo.Set(ZDOVars.s_rightBackItem, 0, false); zdo.Set(ZDOVars.s_rightBackItemQuality, 0, false); } else { zdo.Set(ZDOVars.s_leftItem, 0, false); zdo.Set(ZDOVars.s_leftItemVariant, 0, false); zdo.Set(ZDOVars.s_leftItemQuality, 0, false); zdo.Set(ZDOVars.s_rightItem, 0, false); zdo.Set(ZDOVars.s_rightItemQuality, 0, false); zdo.Set(ZDOVars.s_leftBackItem, handL, false); zdo.Set(ZDOVars.s_leftBackItemVariant, handLVar, false); zdo.Set(ZDOVars.s_leftBackItemQuality, handLQual, false); zdo.Set(ZDOVars.s_rightBackItem, handR, false); zdo.Set(ZDOVars.s_rightBackItemQuality, handRQual, false); } } } private static bool Own(Container hub) { ZNetView val = ViewOf(hub); if ((Object)(object)val == (Object)null || !val.IsValid()) { return false; } if (!val.IsOwner()) { val.ClaimOwnership(); } return val.IsOwner(); } private static ZDO OwnZdo(Container hub) { if (!Own(hub)) { return null; } return Zdo(hub); } private static ZDO Zdo(Container hub) { ZNetView val = ViewOf(hub); if (!((Object)(object)val == (Object)null) && val.IsValid()) { return val.GetZDO(); } return null; } } internal sealed class NjordReorganize : MonoBehaviour { private const float OwnerRetry = 3f; private ZNetView _view; private Container _hub; private float _next; private void Awake() { _view = ((Component)this).GetComponent<ZNetView>(); _hub = ((Component)this).GetComponent<Container>(); _next = Time.time + Random.Range(8f, 20f); } private void Update() { if (NjordWarehouseKeeperPlugin.Reorganize == null || !NjordWarehouseKeeperPlugin.Reorganize.Value || Time.time < _next) { return; } if ((Object)(object)_view == (Object)null || !_view.IsValid() || !_view.IsOwner() || (Object)(object)_hub == (Object)null) { _next = Time.time + 3f; return; } ScheduleNext(); if ((Object)(object)NjordWarehouseKeeperMarker.OpenHub == (Object)(object)_hub && NjordWarehouseKeeperPanel.IsDragging()) { _next = Time.time + 2f; } else if (StorageNetwork.Reorganize(_hub) > 0 && (Object)(object)NjordWarehouseKeeperMarker.OpenHub == (Object)(object)_hub) { NjordWarehouseKeeperPanel.RefreshAfterRemote(); } } private void ScheduleNext() { float num = ((NjordWarehouseKeeperPlugin.ReorganizeInterval != null) ? NjordWarehouseKeeperPlugin.ReorganizeInterval.Value : 60f); if (num < 15f) { num = 15f; } _next = Time.time + num + Random.Range(0f, 8f); } } internal sealed class NjordTalk : MonoBehaviour { private static readonly Vector3 Mouth = new Vector3(0f, 1.85f, 0f); private const float GreetRange = 8f; private const float TalkRange = 12f; private const float LeaveRange = 14f; private const float BubbleSeconds = 4.5f; private const float CullDistance = 24f; private static readonly string[] Greets = new string[3] { "$njord_talk_greet_1", "$njord_talk_greet_2", "$njord_talk_greet_3" }; private static readonly string[] Idle = new string[8] { "$njord_talk_idle_1", "$njord_talk_idle_2", "$njord_talk_idle_3", "$njord_talk_idle_4", "$njord_talk_idle_5", "$njord_talk_idle_6", "$njord_talk_idle_7", "$njord_talk_idle_8" }; private static readonly string[] Goodbyes = new string[3] { "$njord_talk_bye_1", "$njord_talk_bye_2", "$njord_talk_bye_3" }; private bool _near; private float _nextTalk; private NjordLookHook _look; private void Awake() { _look = ((Component)this).GetComponentInChildren<NjordLookHook>(true); } private void Update() { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) if (GUIManagerHeadless()) { return; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || (Object)(object)Chat.instance == (Object)null) { return; } float num = Vector3.Distance(((Component)localPlayer).transform.position, ((Component)this).transform.position); if (!_near) { if (num <= 8f) { _near = true; Say(Pick(Greets)); _look?.Wave(); _nextTalk = Time.time + Random.Range(10f, 16f); } } else if (num > 14f) { Say(Pick(Goodbyes)); _near = false; } else if (num <= 12f && Time.time >= _nextTalk) { Say(Pick(Idle)); _nextTalk = Time.time + Random.Range(14f, 24f); } } private void Say(string token) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) if (!string.IsNullOrEmpty(token) && !((Object)(object)Chat.instance == (Object)null)) { Chat.instance.SetNpcText(((Component)this).gameObject, Mouth, 24f, 4.5f, Localization.instance.Localize("$njord_npc"), Localization.instance.Localize(token), false); } } private static string Pick(string[] lines) { if (lines == null || lines.Length == 0) { return ""; } return lines[Random.Range(0, lines.Length)]; } private static bool GUIManagerHeadless() { return GUIManager.IsHeadless(); } } internal static class NjordWarehouseKeeperAssets { private const string IconResourceName = "NjordWarehouseKeeper.Assets.njord_warehouse_keeper_icon.png"; internal static Sprite Icon { get; private set; } internal static void Load() { Icon = LoadSprite("NjordWarehouseKeeper.Assets.njord_warehouse_keeper_icon.png"); HubSprites.Load(); } internal static Sprite LoadSprite(string resourceName) { return LoadEmbeddedSprite(Assembly.GetExecutingAssembly(), resourceName); } private static Sprite LoadEmbeddedSprite(Assembly assembly, string resourceName) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Expected O, but got Unknown //IL_0086: 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) using Stream stream = assembly.GetManifestResourceStream(resourceName); if (stream == null) { NjordWarehouseKeeperPlugin.Log.LogWarning((object)("Embedded sprite '" + resourceName + "' missing; the piece will use its clone source's icon.")); return null; } using MemoryStream memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); Texture2D val = new Texture2D(2, 2); if (!AssetUtils.LoadImage(val, memoryStream.ToArray())) { NjordWarehouseKeeperPlugin.Log.LogWarning((object)("Could not decode '" + resourceName + "'.")); return null; } return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)); } } internal static class NjordWarehouseKeeperPiece { internal const string PrefabName = "njord_warehouse_keeper"; internal const string NpcName = "Njord"; internal static readonly RequirementConfig[] Resources = (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("Coins", 200, 0, true) }; private static readonly string[] CloneSources = new string[3] { "piece_chest_wood", "piece_chest", "piece_chest_blackmetal" }; internal static void Register() { //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0125: 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_013b: 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_0151: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Expected O, but got Unknown //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Expected O, but got Unknown //IL_00ac: Unknown result type (might be due to invalid IL or missing references) GameObject val = null; string text = null; string[] cloneSources = CloneSources; foreach (string text2 in cloneSources) { val = PrefabManager.Instance.CreateClonedPrefab("njord_warehouse_keeper", text2); if ((Object)(object)val != (Object)null) { text = text2; break; } } if ((Object)(object)val == (Object)null) { NjordWarehouseKeeperPlugin.Log.LogError((object)"Could not clone a vanilla piece for Njord."); return; } val.AddComponent<NjordWarehouseKeeperMarker>(); if ((Object)(object)val.GetComponent<NjordTalk>() == (Object)null) { val.AddComponent<NjordTalk>(); } if ((Object)(object)val.GetComponent<NjordReorganize>() == (Object)null) { val.AddComponent<NjordReorganize>(); } Container component = val.GetComponent<Container>(); if ((Object)(object)component != (Object)null) { component.m_name = "$njord_npc"; component.m_privacy = (PrivacySetting)2; component.m_width = 1; component.m_height = 1; } Piece component2 = val.GetComponent<Piece>(); if ((Object)(object)component2 != (Object)null) { component2.m_name = "$njord_warehouse_keeper_name"; component2.m_description = "$njord_warehouse_keeper_description"; } try { NjordLook.Attach(val); } catch (Exception ex) { NjordWarehouseKeeperPlugin.Log.LogError((object)("Njord body failed to attach: " + ex)); } NjordLook.HideHostVisuals(val); FitCollider(val); PieceConfig val2 = new PieceConfig { Name = "$njord_warehouse_keeper_name", Description = "$njord_warehouse_keeper_description", PieceTable = PieceTables.Hammer, Category = PieceCategories.Furniture, CraftingStation = CraftingStations.None, Requirements = Resources }; if ((Object)(object)NjordWarehouseKeeperAssets.Icon != (Object)null) { val2.Icon = NjordWarehouseKeeperAssets.Icon; } CustomPiece val3 = new CustomPiece(val, false, val2); if (!PieceManager.Instance.AddPiece(val3)) { NjordWarehouseKeeperPlugin.Log.LogError((object)"Failed to register piece 'njord_warehouse_keeper'."); } else { NjordWarehouseKeeperPlugin.Log.LogInfo((object)("Njord cloned from '" + text + "'.")); } } internal static void FitCollider(GameObject prefab) { //IL_0051: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)prefab == (Object)null) { return; } Collider[] componentsInChildren = prefab.GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren.Length; i++) { if ((Object)(object)componentsInChildren[i] != (Object)null) { Object.DestroyImmediate((Object)(object)componentsInChildren[i], true); } } CapsuleCollider obj = prefab.AddComponent<CapsuleCollider>(); obj.direction = 1; obj.center = new Vector3(0f, 1f, 0f); obj.height = 2f; obj.radius = 0.4f; ((Collider)obj).isTrigger = false; ((Collider)obj).enabled = true; } } internal class NjordWarehouseKeeperMarker : MonoBehaviour { internal static Container OpenHub { get; set; } private void Awake() { NjordLook.HideHostVisuals(((Component)this).gameObject); if ((Object)(object)((Component)this).transform.Find("NjordBody") == (Object)null) { NjordLook.Attach(((Component)this).gameObject); } NjordWarehouseKeeperPiece.FitCollider(((Component)this).gameObject); WearNTear component = ((Component)this).GetComponent<WearNTear>(); if ((Object)(object)component != (Object)null) { component.SetupColliders(); } } internal static bool IsHub(Container container) { if ((Object)(object)container != (Object)null) { return (Object)(object)((Component)container).GetComponent<NjordWarehouseKeeperMarker>() != (Object)null; } return false; } } [BepInPlugin("com.gitmcp.njord", "Njord, Warehouse Keeper", "1.3.3")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class NjordWarehouseKeeperPlugin : BaseUnityPlugin { public const string PluginGuid = "com.gitmcp.njord"; public const string PluginName = "Njord, Warehouse Keeper"; public const string PluginVersion = "1.3.3"; internal static ManualLogSource Log; internal static ConfigEntry<float> Radius; internal static ConfigEntry<bool> RequireLineOfSight; internal static ConfigEntry<bool> DepositHotbar; internal static ConfigEntry<bool> Reorganize; internal static ConfigEntry<float> ReorganizeInterval; private Harmony _harmony; private void Awake() { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; Localizations.Register(); Localization.OnLanguageChange = (Action)Delegate.Combine(Localization.OnLanguageChange, new Action(OnLanguageChanged)); BindConfig(); ClientPreferences.Bind(((BaseUnityPlugin)this).Config); _harmony = new Harmony("com.gitmcp.njord"); _harmony.PatchAll(typeof(NjordWarehouseKeeperPlugin).Assembly); PrefabManager.OnVanillaPrefabsAvailable += RegisterContent; } private void Update() { if (!GUIManager.IsHeadless() && !NjordWarehouseKeeperPrefs.TickCapture()) { HubHotkey.Tick(); } } private void BindConfig() { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Expected O, but got Unknown //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Expected O, but got Unknown //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Expected O, but got Unknown //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Expected O, but got Unknown //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Expected O, but got Unknown //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Expected O, but got Unknown //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Expected O, but got Unknown Radius = ((BaseUnityPlugin)this).Config.Bind<float>("Njord", "Radius", 15f, new ConfigDescription("How far from Njord, in metres, a container is still part of the network.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(4f, 40f), new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); RequireLineOfSight = ((BaseUnityPlugin)this).Config.Bind<bool>("Njord", "RequireLineOfSight", false, new ConfigDescription("Only include chests Njord can see. Off by default so a chest in the next room still counts; turn it on if a busy hall is pulling in too much.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); DepositHotbar = ((BaseUnityPlugin)this).Config.Bind<bool>("Njord", "DepositHotbar", false, new ConfigDescription("When depositing everything, also send the hotbar (the first inventory row). Off by default so tools stay on the belt.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); Reorganize = ((BaseUnityPlugin)this).Config.Bind<bool>("Njord", "Reorganize", true, new ConfigDescription("From time to time Njord merges leftover piles of the same item so they use as few chest slots as possible. Chests someone has open are left alone.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); ReorganizeInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Njord", "ReorganizeInterval", 60f, new ConfigDescription("Seconds between each tidy pass. Only used when Reorganize is on.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(15f, 1800f), new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); } private void RegisterContent() { PrefabManager.OnVanillaPrefabsAvailable -= RegisterContent; NjordWarehouseKeeperAssets.Load(); NjordWarehouseKeeperPiece.Register(); int num = _harmony.GetPatchedMethods().Count(); Log.LogInfo((object)string.Format("{0} {1} registered its content, {2} method(s) patched.", "Njord, Warehouse Keeper", "1.3.3", num)); } private static void OnLanguageChanged() { NjordWarehouseKeeperPanel.OnLanguageChanged(); } private void OnDestroy() { Localization.OnLanguageChange = (Action)Delegate.Remove(Localization.OnLanguageChange, new Action(OnLanguageChanged)); Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } public static class MyPluginInfo { public const string PLUGIN_GUID = "NjordWarehouseKeeper"; public const string PLUGIN_NAME = "NjordWarehouseKeeper"; public const string PLUGIN_VERSION = "1.3.3"; } } namespace NjordWarehouseKeeper.UI { internal sealed class HubItemHover : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler { private const float ShowDelay = 0.5f; private const float MoveSlop = 4f; private const int OverlaySort = 12000; private static GameObject Shown; private static HubItemHover Owner; private static Transform Overlay; internal string Topic; internal string Body; private bool _over; private float _still; private Vector2 _origin; private Vector2 _rowOrigin; private RectTransform _rect; public void OnPointerEnter(PointerEventData eventData) { BeginHover(); } public void OnPointerExit(PointerEventData eventData) { _over = false; HideMine(); } private void Awake() { ref RectTransform rect = ref _rect; Transform transform = ((Component)this).transform; rect = (RectTransform)(object)((transform is RectTransform) ? transform : null); } private void OnDisable() { _over = false; HideMine(); } private void Update() { //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_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: 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_0071: 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_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) Vector2 val = Mouse(); if (!PointerOverSelf(val)) { if (_over) { _over = false; HideMine(); } return; } if (!_over) { BeginHover(); return; } Vector2 val2 = val - _origin; if (!(((Vector2)(ref val2)).sqrMagnitude > 16f)) { val2 = RowPos() - _rowOrigin; if (!(((Vector2)(ref val2)).sqrMagnitude > 16f)) { if (!string.IsNullOrEmpty(Topic) || !string.IsNullOrEmpty(Body)) { _still += Time.deltaTime; if (!(_still < 0.5f)) { Show(val); } } return; } } _origin = val; _rowOrigin = RowPos(); _still = 0f; HideMine(); } internal void Bind(ItemData item) { if (item?.m_shared == null) { BindText("", ""); } else { BindText(item.m_shared.m_name, item.GetTooltip(-1)); } } internal void BindText(string topic, string body) { Topic = topic ?? ""; Body = body ?? ""; if (string.IsNullOrEmpty(Topic) && string.IsNullOrEmpty(Body)) { HideMine(); } else if ((Object)(object)Owner == (Object)(object)this && (Object)(object)Shown != (Object)null) { ApplyText(Shown); } } internal static void Hide() { if ((Object)(object)Shown != (Object)null) { Object.Destroy((Object)(object)Shown); Shown = null; } Owner = null; } internal static void ForgetOverlay() { Hide(); Overlay = null; } private void BeginHover() { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) _over = true; _still = 0f; _origin = Mouse(); _rowOrigin = RowPos(); HideMine(); } private void HideMine() { if ((Object)(object)Owner == (Object)(object)this) { Hide(); } } private void Show(Vector2 mouse) { //IL_0024: 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_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Shown != (Object)null && (Object)(object)Owner == (Object)(object)this) { Shown.transform.position = Vector2.op_Implicit(mouse); Clamp(Shown); return; } GameObject val = Prefab(); Transform val2 = OverlayRoot(); if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null)) { Hide(); Shown = Object.Instantiate<GameObject>(val, val2); Owner = this; IgnoreRaycasts(Shown); ApplyText(Shown); Shown.transform.position = Vector2.op_Implicit(mouse); Clamp(Shown); val2.SetAsLastSibling(); } } private void ApplyText(GameObject tip) { TMP_Text val = FindTmp(tip.transform, "Text"); if ((Object)(object)val != (Object)null) { val.text = Localization.instance.Localize(Body ?? ""); } TMP_Text val2 = FindTmp(tip.transform, "Topic"); if ((Object)(object)val2 != (Object)null) { val2.text = Localization.instance.Localize(Topic ?? ""); } } private Vector2 RowPos() { //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_000e: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_rect != (Object)null)) { return Vector2.zero; } return Vector2.op_Implicit(((Transform)_rect).position); } private bool PointerOverSelf(Vector2 screen) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_rect == (Object)null) { return false; } Canvas componentInParent = ((Component)this).GetComponentInParent<Canvas>(); Camera val = null; if ((Object)(object)componentInParent != (Object)null && (int)componentInParent.renderMode != 0) { val = componentInParent.worldCamera; } return RectTransformUtility.RectangleContainsScreenPoint(_rect, screen, val); } private static Vector2 Mouse() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: 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) if (ZInput.instance == null) { return Vector2.op_Implicit(Input.mousePosition); } return Vector2.op_Implicit(ZInput.pointerPosition); } private static Transform OverlayRoot() { //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009b: 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_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Overlay != (Object)null) { return Overlay; } Transform val = null; if ((Object)(object)GUIManager.CustomGUIFront != (Object)null) { val = GUIManager.CustomGUIFront.transform; } else if ((Object)(object)InventoryGui.instance != (Object)null) { val = ((Component)InventoryGui.instance).transform; } if ((Object)(object)val == (Object)null) { return null; } GameObject val2 = new GameObject("NjordHoverOverlay", new Type[2] { typeof(RectTransform), typeof(Canvas) }); val2.transform.SetParent(val, false); val2.transform.SetAsLastSibling(); RectTransform component = val2.GetComponent<RectTransform>(); component.anchorMin = Vector2.zero; component.anchorMax = Vector2.one; component.offsetMin = Vector2.zero; component.offsetMax = Vector2.zero; Canvas component2 = val2.GetComponent<Canvas>(); Canvas val3 = ((Component)val).GetComponent<Canvas>() ?? ((Component)val).GetComponentInParent<Canvas>(); if ((Object)(object)val3 != (Object)null) { component2.renderMode = val3.renderMode; component2.worldCamera = val3.worldCamera; component2.sortingLayerID = val3.sortingLayerID; } component2.overrideSorting = true; component2.sortingOrder = 12000; Overlay = val2.transform; return Overlay; } private static void IgnoreRaycasts(GameObject root) { if ((Object)(object)root == (Object)null) { return; } Graphic[] componentsInChildren = root.GetComponentsInChildren<Graphic>(true); for (int i = 0; i < componentsInChildren.Length; i++) { if ((Object)(object)componentsInChildren[i] != (Object)null) { componentsInChildren[i].raycastTarget = false; } } } private static GameObject Prefab() { InventoryGui instance = InventoryGui.instance; InventoryGrid val = (((Object)(object)instance != (Object)null) ? instance.m_playerGrid : null); if ((Object)(object)val == (Object)null || (Object)(object)val.m_elementPrefab == (Object)null) { return null; } UITooltip val2 = val.m_elementPrefab.GetComponent<UITooltip>(); if ((Object)(object)val2 == (Object)null) { val2 = val.m_elementPrefab.GetComponentInChildren<UITooltip>(true); } if (!((Object)(object)val2 != (Object)null)) { return null; } return val2.m_tooltipPrefab; } private static TMP_Text FindTmp(Transform root, string name) { Transform val = Utils.FindChild(root, name, (IterativeSearchType)0); if (!((Object)(object)val != (Object)null)) { return null; } return ((Component)val).GetComponent<TMP_Text>(); } private static void Clamp(GameObject tip) { if (!((Object)(object)tip == (Object)null) && tip.transform.childCount != 0) { Transform child = tip.transform.GetChild(0); RectTransform val = (RectTransform)(object)((child is RectTransform) ? child : null); if ((Object)(object)val != (Object)null) { Utils.ClampUIToScreen(val); } } } } internal static class HubSprites { internal static Sprite StarEmpty { get; private set; } internal static Sprite StarFilled { get; private set; } internal static Sprite Cross { get; private set; } internal static Sprite Cog { get; private set; } internal static Sprite Dress { get; private set; } internal static Sprite Deposit { get; private set; } internal static Sprite Resupply { get; private set; } internal static Sprite QuickStack { get; private set; } internal static void Load() { if (!((Object)(object)StarFilled != (Object)null)) { StarFilled = MakeSprite(DrawStar(filled: true), "hub_star_filled"); StarEmpty = MakeSprite(DrawStar(filled: false), "hub_star_empty"); Cross = MakeSprite(DrawCross(), "hub_cross"); Cog = MakeSprite(DrawCog(), "hub_cog"); Dress = MakeSprite(DrawShirt(), "hub_dress"); Deposit = NjordWarehouseKeeperAssets.LoadSprite("NjordWarehouseKeeper.Assets.hub_deposit.png"); Resupply = NjordWarehouseKeeperAssets.LoadSprite("NjordWarehouseKeeper.Assets.hub_resupply.png"); QuickStack = NjordWarehouseKeeperAssets.LoadSprite("NjordWarehouseKeeper.Assets.hub_quickstack.png"); } } internal static Sprite DressIcon() { return Dress ?? (Dress = MakeSprite(DrawShirt(), "hub_dress")); } private static Sprite MakeSprite(Texture2D texture, string name) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) ((Object)texture).name = name; ((Texture)texture).filterMode = (FilterMode)1; ((Texture)texture).wrapMode = (TextureWrapMode)1; Sprite obj = Sprite.Create(texture, new Rect(0f, 0f, (float)((Texture)texture).width, (float)((Texture)texture).height), new Vector2(0.5f, 0.5f), 100f); ((Object)obj).name = name; return obj; } private static Texture2D DrawStar(bool filled) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0020: 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_004d: 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_0057: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(48, 48, (TextureFormat)5, false); Vector2[] poly = StarPoints(23.039999f, 9.6f, new Vector2(24f, 24f)); Vector2 p = default(Vector2); for (int i = 0; i < 48; i++) { for (int j = 0; j < 48; j++) { ((Vector2)(ref p))..ctor((float)j + 0.5f, (float)i + 0.5f); float num = ((!filled) ? EdgeAlpha(p, poly, 2.1f) : (InsidePolygon(p, poly) ? 1f : EdgeAlpha(p, poly, 1.6f))); val.SetPixel(j, i, new Color(1f, 1f, 1f, num)); } } val.Apply(false, true); return val; } private static Texture2D DrawCross() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0073: 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_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_007e: 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_00b2: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(32, 32, (TextureFormat)5, false); Vector2 a = default(Vector2); ((Vector2)(ref a))..ctor(7.04f, 7.04f); Vector2 b = default(Vector2); ((Vector2)(ref b))..ctor(24.96f, 24.96f); Vector2 a2 = default(Vector2); ((Vector2)(ref a2))..ctor(24.96f, 7.04f); Vector2 b2 = default(Vector2); ((Vector2)(ref b2))..ctor(7.04f, 24.96f); Vector2 p = default(Vector2); for (int i = 0; i < 32; i++) { for (int j = 0; j < 32; j++) { ((Vector2)(ref p))..ctor((float)j + 0.5f, (float)i + 0.5f); float num = Mathf.Min(DistanceToSegment(p, a, b), DistanceToSegment(p, a2, b2)); float num2 = Mathf.Clamp01(2.2f - num); val.SetPixel(j, i, new Color(1f, 1f, 1f, num2)); } } val.Apply(false, true); return val; } private static Texture2D DrawShirt() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(48, 48, (TextureFormat)5, false); Vector2[] poly = ShirtPoints(48); Vector2 p = default(Vector2); for (int i = 0; i < 48; i++) { for (int j = 0; j < 48; j++) { ((Vector2)(ref p))..ctor((float)j + 0.5f, (float)i + 0.5f); float num = (InsidePolygon(p, poly) ? 1f : EdgeAlpha(p, poly, 1.6f)); val.SetPixel(j, i, new Color(1f, 1f, 1f, num)); } } val.Apply(false, true); return val; } private static Vector2[] ShirtPoints(int size) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: 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_0074: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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_00e4: 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_0100: 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_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) return (Vector2[])(object)new Vector2[17] { new Vector2((float)size * 0.3f, (float)size * 0.1f), new Vector2((float)size * 0.7f, (float)size * 0.1f), new Vector2((float)size * 0.71f, (float)size * 0.46f), new Vector2((float)size * 0.92f, (float)size * 0.4f), new Vector2((float)size * 0.94f, (float)size * 0.62f), new Vector2((float)size * 0.84f, (float)size * 0.7f), new Vector2((float)size * 0.68f, (float)size * 0.68f), new Vector2((float)size * 0.62f, (float)size * 0.78f), new Vector2((float)size * 0.56f, (float)size * 0.64f), new Vector2((float)size * 0.5f, (float)size * 0.6f), new Vector2((float)size * 0.44f, (float)size * 0.64f), new Vector2((float)size * 0.38f, (float)size * 0.78f), new Vector2((float)size * 0.32f, (float)size * 0.68f), new Vector2((float)size * 0.16f, (float)size * 0.7f), new Vector2((float)size * 0.06f, (float)size * 0.62f), new Vector2((float)size * 0.08f, (float)size * 0.4f), new Vector2((float)size * 0.29f, (float)size * 0.46f) }; } private static Texture2D DrawCog() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //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) //IL_0049: 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_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(48, 48, (TextureFormat)5, false); Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(24f, 24f); float num = (float)Math.PI / 8f; for (int i = 0; i < 48; i++) { for (int j = 0; j < 48; j++) { Vector2 val3 = new Vector2((float)j + 0.5f, (float)i + 0.5f) - val2; float magnitude = ((Vector2)(ref val3)).magnitude; float num2 = Mathf.Atan2(val3.y, val3.x); if (num2 < 0f) { num2 += (float)Math.PI * 2f; } bool flag = num2 % (num * 2f) < num * 0.72f; float num3 = (flag ? 22.08f : 16.32f); float num4 = 6.7200003f; float num5 = 13.440001f; float num6 = 0f; if (magnitude >= num4 && magnitude <= num3 && (magnitude <= num5 || flag)) { num6 = 1f; if (magnitude > num3 - 1.2f) { num6 = Mathf.Clamp01(num3 - magnitude); } else if (magnitude < num4 + 1.2f) { num6 = Mathf.Clamp01(magnitude - num4); } } val.SetPixel(j, i, new Color(1f, 1f, 1f, num6)); } } val.Apply(false, true); return val; } private static Vector2[] StarPoints(float outer, float inner, Vector2 center) { //IL_002d: 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) Vector2[] array = (Vector2[])(object)new Vector2[10]; for (int i = 0; i < 10; i++) { float num = (((i & 1) == 0) ? outer : inner); float num2 = (-90f + (float)i * 36f) * ((float)Math.PI / 180f); array[i] = center + new Vector2(Mathf.Cos(num2) * num, Mathf.Sin(num2) * num); } return array; } private static bool InsidePolygon(Vector2 p, Vector2[] poly) { //IL_000e: 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_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_001d: 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_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0042: 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_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005e: 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_0073: Unknown result type (might be due to invalid IL or missing references) bool flag = false; int num = 0; int num2 = poly.Length - 1; while (num < poly.Length) { Vector2 val = poly[num]; Vector2 val2 = poly[num2]; if (val.y > p.y != val2.y > p.y && p.x < (val2.x - val.x) * (p.y - val.y) / (val2.y - val.y + 0.0001f) + val.x) { flag = !flag; } num2 = num++; } return flag; } private static float EdgeAlpha(Vector2 p, Vector2[] poly, float width) { //IL_000c: 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_001c: Unknown result type (might be due to invalid IL or missing references) float num = width + 1f; for (int i = 0; i < poly.Length; i++) { float num2 = DistanceToSegment(p, poly[i], poly[(i + 1) % poly.Length]); if (num2 < num) { num = num2; } } return Mathf.Clamp01(width - num); } private static float DistanceToSegment(Vector2 p, Vector2 a, Vector2 b) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0018: 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) Vector2 val = b - a; float sqrMagnitude = ((Vector2)(ref val)).sqrMagnitude; if (sqrMagnitude < 0.0001f) { return Vector2.Distance(p, a); } float num = Mathf.Clamp01(Vector2.Dot(p - a, val) / sqrMagnitude); return Vector2.Distance(p, a + val * num); } } internal static class InventoryFavouriteStars { private const string StarName = "NjordFavouriteStar"; private const float Size = 16f; internal static void Sync(InventoryGrid grid) { //IL_005e: 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) InventoryGui instance = InventoryGui.instance; if ((Object)(object)instance == (Object)null || (Object)(object)grid == (Object)null || (Object)(object)grid != (Object)(object)instance.m_playerGrid) { return; } HubSprites.Load(); Inventory inventory = grid.GetInventory(); List<InventoryElement> elements = grid.m_elements; if (elements == null) { return; } for (int i = 0; i < elements.Count; i++) { InventoryElement val = elements[i]; if (!((Object)(object)val == (Object)null)) { ItemData item = ((inventory != null) ? inventory.GetItemAt(val.Position.x, val.Position.y) : null); Bind(EnsureStar(val), item); } } } internal static bool PointerOverStar() { //IL_0014: 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_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_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_003d: Expected O, but got Unknown //IL_0055: 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_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)EventSystem.current == (Object)null) { return false; } PointerEventData val = new PointerEventData(EventSystem.current) { position = ((ZInput.instance != null) ? Vector2.op_Implicit(ZInput.pointerPosition) : Vector2.op_Implicit(Input.mousePosition)) }; List<RaycastResult> list = new List<RaycastResult>(); EventSystem.current.RaycastAll(val, list); for (int i = 0; i < list.Count; i++) { RaycastResult val2 = list[i]; if ((Object)(object)((RaycastResult)(ref val2)).gameObject != (Object)null) { val2 = list[i]; if ((Object)(object)((RaycastResult)(ref val2)).gameObject.GetComponent<PackFavouriteStar>() != (Object)null) { return true; } } } return false; } private static PackFavouriteStar EnsureStar(InventoryElement element) { //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Expected O, but got Unknown //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_0101: 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_012c: Expected O, but got Unknown PackFavouriteStar componentInChildren = ((Component)element).GetComponentInChildren<PackFavouriteStar>(true); if ((Object)(object)componentInChildren != (Object)null) { ((Component)componentInChildren).transform.SetAsLastSibling(); Transform transform = ((Component)componentInChildren).transform; PlaceStar((RectTransform)(object)((transform is RectTransform) ? transform : null)); return componentInChildren; } GameObject val = new GameObject("NjordFavouriteStar", new Type[5] { typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(Button), typeof(PackFavouriteStar) }); val.transform.SetParent(((Component)element).transform, false); PlaceStar(val.GetComponent<RectTransform>()); Image component = val.GetComponent<Image>(); component.preserveAspect = true; ((Graphic)component).raycastTarget = true; component.sprite = HubSprites.StarEmpty; ((Graphic)component).color = new Color(1f, 1f, 1f, 0.8f); Button component2 = val.GetComponent<Button>(); ((Selectable)component2).targetGraphic = (Graphic)(object)component; ((Selectable)component2).transition = (Transition)0; Navigation navigation = default(Navigation); ((Navigation)(ref navigation)).mode = (Mode)0; ((Selectable)component2).navigation = navigation; PackFavouriteStar component3 = val.GetComponent<PackFavouriteStar>(); component3.Image = component; ((UnityEvent)component2.onClick).AddListener(new UnityAction(component3.OnClicked)); return component3; } private static void PlaceStar(RectTransform rt) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: 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) if (!((Object)(object)rt == (Object)null)) { rt.anchorMin = new Vector2(0f, 1f); rt.anchorMax = new Vector2(0f, 1f); rt.pivot = new Vector2(0f, 1f); rt.sizeDelta = new Vector2(16f, 16f); rt.anchoredPosition = new Vector2(2f, -2f); } } private static void Bind(PackFavouriteStar star, ItemData item) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)star == (Object)null)) { star.Pos = (Vector2i)(((??)item?.m_gridPos) ?? new Vector2i(-1, -1)); bool flag = item?.m_shared != null; ((Component)star).gameObject.SetActive(flag); if (flag && !((Object)(object)star.Image == (Object)null)) { bool flag2 = ClientPreferences.IsFavourite(item); star.Image.sprite = (flag2 ? HubSprites.StarFilled : HubSprites.StarEmpty); ((Graphic)star.Image).color = (flag2 ? new Color(1f, 0.82f, 0.28f, 1f) : new Color(1f, 1f, 1f, 0.8f)); } } } } internal sealed class PackFavouriteStar : MonoBehaviour { internal Image Image; internal Vector2i Pos; internal void OnClicked() { //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) if (NjordWarehouseKeeperPanel.IsDragging()) { NjordWarehouseKeeperPanel.DepositDragged(); return; } InventoryGui instance = InventoryGui.instance; if ((Object)(object)instance != (Object)null && instance.m_dragItem != null) { return; } Inventory val = (((Object)(object)instance != (Object)null && (Object)(object)instance.m_playerGrid != (Object)null) ? instance.m_playerGrid.GetInventory() : (((Object)(object)Player.m_localPlayer != (Object)null) ? ((Humanoid)Player.m_localPlayer).GetInventory() : null)); ItemData val2 = ((val != null) ? val.GetItemAt(Pos.x, Pos.y) : null); if (val2?.m_shared != null) { ClientPreferences.ToggleFavourite(val2); ItemKey.Persist(val); bool flag = ClientPreferences.IsFavourite(val2); if ((Object)(object)Image != (Object)null) { Image.sprite = (flag ? HubSprites.StarFilled : HubSprites.StarEmpty); ((Graphic)Image).color = (flag ? new Color(1f, 0.82f, 0.28f, 1f) : new Color(1f, 1f, 1f, 0.8f)); } if ((Object)(object)instance != (Object)null) { InventoryFavouriteStars.Sync(instance.m_playerGrid); } NjordWarehouseKeeperPanel.RefreshAfterRemote(); } } } internal static class LocalizedUi { internal static void Capture(Text text, string token) { if (!((Object)(object)text == (Object)null) && !string.IsNullOrEmpty(token)) { text.text = token; if (Localization.instance != null) { Localization.instance.RemoveTextFromCache(text); Localization.instance.Localize(((Component)text).transform); } } } internal static void CapturePlaceholder(InputField field, string token) { if (!((Object)(object)field == (Object)null)) { Graphic placeholder = field.placeholder; Capture((Text)(object)((placeholder is Text) ? placeholder : null), token); } } internal static void CaptureRoot(Transform root) { if ((Object)(object)root != (Object)null && Localization.instance != null) { Localization.instance.Localize(root); } } internal static void RelocalizeRoot(Transform root) { if ((Object)(object)root != (Object)null && Localization.instance != null) { Localization.instance.ReLocalizeAll(root); } } } internal static class NjordWarehouseKeeperPanel { private enum SortMode { Name, Quantity, Category } private sealed class RowView { internal GameObject Go; internal Image Icon; internal Text Name; internal Text Qty; internal Image Star; internal Image Dress; internal GameObject DressGo; internal HubItemHover Hover; internal IndexedStack Stack; internal ColorBlock PlainColors; internal Color PlainName; } [CompilerGenerated] private static class <>O { public static Action <0>__BuildPending; public static UnityAction<string> <1>__OnSearch; public static Action <2>__OnSearchCleared; public static UnityAction <3>__OnQuickStack; public static UnityAction <4>__OnDeposit; public static UnityAction <5>__OnResupply; public static UnityAction <6>__OnFavouritesFilter; public static Comparison<IndexedStack> <7>__Compare; public static UnityAction<string> <8>__OnSearchEndEdit; } [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static UnityAction <>9__57_0; public static UnityAction<Vector2> <>9__57_1; internal void <EnsureBuilt>b__57_0() { if (IsDragging()) { DepositDragged(); } else { SetPrefsOpen(!_prefsOpen); } } internal void <EnsureBuilt>b__57_1(Vector2 _) { HubItemHover.Hide(); } } private const float PanelWidth = 520f; private const float PanelHeight = 830f; private const float RowHeight = 52f; private const float RowSpacing = 3f; private const float IconSize = 40f; private const float ActionY = 82f; private const float ActionHeight = 38f; private const float SearchY = 128f; private const float CatRow1Y = 166f; private const float CatRow2Y = 198f; private const float SortY = 232f; private const float ListTop = 268f; private const float ListBottom = 16f; private const float ListInset = 22f; internal const float ContentTop = 76f; private static GameObject _root; private static Text _title; private static Text _capacity; private static Text _empty; private static InputField _search; private static RectTransform _scrollRect; private static Transform _rowParent; private static GameObject _depositGo; private static GameObject _resupplyGo; private static GameObject _quickStackGo; private static Button _cogButton; private static Button _favFilterButton; private static readonly List<RowView> _rows = new List<RowView>(); private static readonly List<Button> _categoryButtons = new List<Button>(); private static readonly List<Button> _sortButtons = new List<Button>(); private static readonly List<GameObject> _itemTabUi = new List<GameObject>(); private static readonly List<GameObject> _chromeUi = new List<GameObject>(); private static ItemCategory _category = ItemCategory.All; private static SortMode _sort = SortMode.Name; private static string _query = ""; private static bool _favouritesOnly; private static bool _prefsOpen; private static float _nextRefresh; private static float _nextSnap; private static Container _pending; private static IndexedStack _splitGroup; private static bool _searchBlocked; private static readonly Vector3[] Corners = (Vector3[])(object)new Vector3[4]; internal static string SearchQuery => _query ?? ""; internal static void Open(Container hub) { if (GUIManager.IsHeadless() || (Object)(object)hub == (Object)null) { return; } NjordWarehouseKeeperMarker.OpenHub = hub; if (GUIManager.Instance == null || (Object)(object)GUIManager.CustomGUIFront == (Object)null) { _pending = hub; GUIManager.OnCustomGUIAvailable -= BuildPending; GUIManager.OnCustomGUIAvailable += BuildPending; return; } EnsureBuilt(); if (!((Object)(object)_root == (Object)null)) { RelocalizeChrome(); SetPrefsOpen(on: false); _nextSnap = 0f; SnapBetweenInventoryAndCrafting(); _root.SetActive(true); _nextRefresh = 0f; Refresh(); NjordWarehouseKeeperRecipes.Open(); } } internal static void Close() { NjordWarehouseKeeperMarker.OpenHub = null; _pending = null; _splitGroup = null; UnfocusSearch(); if (WantsResetFilters()) { ResetFilters(); NjordWarehouseKeeperRecipes.ResetFilters(); } HubItemHover.Hide(); SetPrefsOpen(on: false); NjordWarehouseKeeperRecipes.Close(); InventoryGuiPatch.HubClosed(); if ((Object)(object)_root != (Object)null) { _root.SetActive(false); } } internal static void Tick() { if ((Object)(object)NjordWarehouseKeeperMarker.OpenHub == (Object)null || (Object)(object)_root == (Object)null || !_root.activeSelf) { return; } if (!InventoryGui.IsVisible()) { Close(); return; } if (Time.time >= _nextSnap) { SnapBetweenInventoryAndCrafting(); } NjordWarehouseKeeperRecipes.Tick(); SyncSearchFocus(); if (!_prefsOpen && Time.time >= _nextRefresh) { Refresh(); } } internal static bool SearchHasFocus() { if ((Object)(object)_root == (Object)null || !_root.activeSelf) { return false; } if ((Object)(object)_search != (Object)null && _search.isFocused) { return true; } if (NjordWarehouseKeeperRecipes.SearchHasFocus()) { return true; } return NjordWarehouseKeeperPrefs.InputHasFocus(); } internal static bool HandleSplitOk() { if (_splitGroup == null) { return false; } InventoryGui instance = InventoryGui.instance; int amount = ((!((Object)(object)instance != (Object)null) || !((Object)(object)instance.m_splitDialog != (Object)null)) ? 1 : Mathf.Max(1, (int)instance.m_splitDialog.SliderValue)); IndexedStack splitGroup = _splitGroup; _splitGroup = null; if (instance != null) { instance.HideSplitDialog