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 SelfSortingStoragePLUS v1.0.3
plugins/bobabulker.SelfSortingStoragePLUS.dll
Decompiled 2 weeks ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using LethalCompanyInputUtils.Api; using Microsoft.CodeAnalysis; using SelfSortingStorage.Cupboard; using SelfSortingStoragePLUS.StandIns; using TMPro; using Unity.Collections; using Unity.Netcode; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.Rendering; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("bobabulker.SelfSortingStoragePLUS")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.3.0")] [assembly: AssemblyInformationalVersion("1.0.3")] [assembly: AssemblyProduct("SelfSortingStoragePLUS")] [assembly: AssemblyTitle("bobabulker.SelfSortingStoragePLUS")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.3.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [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 SelfSortingStoragePLUS { [BepInPlugin("bobabulker.SelfSortingStoragePLUS", "SelfSortingStoragePLUS", "1.0.3")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class SelfSortingStoragePLUS : BaseUnityPlugin { internal static ConfigEntry<TeamWipeScrapMode> TeamWipeScrap { get; private set; } internal static ConfigEntry<bool> UseTextStandIns { get; private set; } public static SelfSortingStoragePLUS Instance { get; private set; } internal static ManualLogSource Logger { get; private set; } internal static Harmony? Harmony { get; private set; } internal static ConfigEntry<string> AutoStoreMoons { get; private set; } internal static ConfigEntry<bool> VerboseLogging { get; private set; } private void Awake() { Logger = ((BaseUnityPlugin)this).Logger; Instance = this; AutoStoreMoons = ((BaseUnityPlugin)this).Config.Bind<string>("Terminal Purchases", "AutoStoreMoons", "71 Gordion, Shutter", "Comma-separated list of moons where terminal purchases should be automatically stored in the SelfSortingStorage cupboard when possible (e.g. \"71 Gordion, Experimentation\"). A moon matches if its name contains any entry in this list, case-insensitive, so \"Gordion\" also matches \"71 Gordion\". Works from the moment the ship starts its descent. Leave blank to disable AutoStore on every moon."); UseTextStandIns = ((BaseUnityPlugin)this).Config.Bind<bool>("Stand-ins", "UseTextStandIns", false, "Client-side, applies immediately. When true, the Smart Cupboard shows each item's name as text (the game's font, white with a black outline) instead of a model of the item. Aiming at one outlines the text in blue."); TeamWipeScrap = ((BaseUnityPlugin)this).Config.Bind<TeamWipeScrapMode>("Team Wipe", "StoredScrap", TeamWipeScrapMode.ExposeInternalStorage, "What happens to scrap stored in the Smart Cupboard when the whole team dies (host setting). ExposeInternalStorage: every stored scrap unit goes through the wipe like scrap lying on the ship floor, so mods that only despawn part of the scrap thin out stacks too (6 stop signs with 50% despawn leaves about 3). The survivors stay in the cupboard with the counter updated, and a slot with none left is freed. ProtectAll: stored scrap is never exposed and always stays in the cupboard's memory, so no team wipe despawn can touch it. This replaces SelfSortingStorage's own 'Prevent memory reset on death' for team wipes; being fired is still handled by SelfSortingStorage."); VerboseLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("Verbose Logging", "Log Info", false, "Enable to get information logging on different stages of the patch."); StandInKeybinds.Initialize(); Patch(); Logger.LogInfo((object)"bobabulker.SelfSortingStoragePLUS v1.0.3 has loaded!"); } internal static void Patch() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown if (Harmony == null) { Harmony = new Harmony("bobabulker.SelfSortingStoragePLUS"); } Harmony.PatchAll(); StandInSystem.TryPatch(Harmony); Logger.LogDebug((object)"Finished patching!"); } internal static bool IsAutoStoreEnabledOnCurrentMoon() { string value = AutoStoreMoons.Value; if (string.IsNullOrWhiteSpace(value)) { return false; } StartOfRound instance = StartOfRound.Instance; if ((Object)(object)instance == (Object)null) { return false; } bool flag = !instance.inShipPhase && !instance.shipIsLeaving; if (!instance.shipHasLanded && !flag) { if (VerboseLogging.Value) { Logger.LogInfo((object)"[AutoStoreMoons] Ship is in orbit or leaving. Using normal dropship storage."); } return false; } string text = instance.currentLevel?.PlanetName; if (string.IsNullOrEmpty(text)) { if (VerboseLogging.Value) { Logger.LogInfo((object)"[AutoStoreMoons] Could not determine the current moon. Using normal dropship storage."); } return false; } string[] array = value.Split(','); foreach (string text2 in array) { string text3 = text2.Trim(); if (text3.Length != 0 && text.IndexOf(text3, StringComparison.OrdinalIgnoreCase) >= 0) { return true; } } if (VerboseLogging.Value) { Logger.LogInfo((object)("[AutoStoreMoons] AutoStore is not enabled for the current moon \"" + text + "\". Using normal dropship storage.")); } return false; } } public enum TeamWipeScrapMode { ExposeInternalStorage, ProtectAll } public static class MyPluginInfo { public const string PLUGIN_GUID = "bobabulker.SelfSortingStoragePLUS"; public const string PLUGIN_NAME = "SelfSortingStoragePLUS"; public const string PLUGIN_VERSION = "1.0.3"; } } namespace SelfSortingStoragePLUS.StandIns { internal sealed class BoxLines { private static readonly int[] PathOrder = new int[16] { 0, 1, 2, 3, 0, 4, 5, 1, 5, 6, 2, 6, 7, 3, 7, 4 }; private readonly Transform parent; private readonly Color color; private readonly string name; private readonly List<LineRenderer> lines = new List<LineRenderer>(); private readonly Vector3[] path = (Vector3[])(object)new Vector3[16]; private Material? material; private int used; internal BoxLines(Transform parent, Color color, string name) { //IL_0026: 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) this.parent = parent; this.color = color; this.name = name; } internal void Begin() { used = 0; } internal void Draw(Vector3[] corners) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) LineRenderer line = GetLine(used); used++; for (int i = 0; i < path.Length; i++) { path[i] = corners[PathOrder[i]]; } line.SetPositions(path); ((Renderer)line).enabled = true; } internal void End() { HideFrom(used); } internal void Clear() { used = 0; HideFrom(0); } private LineRenderer GetLine(int index) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006d: 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) while (lines.Count <= index) { GameObject val = new GameObject(name); val.transform.SetParent(parent, false); LineRenderer val2 = val.AddComponent<LineRenderer>(); val2.useWorldSpace = true; val2.loop = false; val2.positionCount = path.Length; val2.widthMultiplier = 0.01f; val2.numCornerVertices = 0; val2.numCapVertices = 0; val2.startColor = color; val2.endColor = color; ((Renderer)val2).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)val2).receiveShadows = false; ((Renderer)val2).sharedMaterial = material ?? (material = CreateMaterial(color)); ((Renderer)val2).enabled = false; lines.Add(val2); } return lines[index]; } private void HideFrom(int start) { for (int i = start; i < lines.Count; i++) { if ((Object)(object)lines[i] != (Object)null && ((Renderer)lines[i]).enabled) { ((Renderer)lines[i]).enabled = false; } } } internal static Material CreateMaterial(Color color) { //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Expected O, but got Unknown //IL_00b7: 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_004a: Expected O, but got Unknown //IL_0085: Unknown result type (might be due to invalid IL or missing references) string[] array = new string[4] { "HDRP/Unlit", "Sprites/Default", "Unlit/Color", "Hidden/Internal-Colored" }; foreach (string text in array) { Shader val = Shader.Find(text); if ((Object)(object)val == (Object)null) { continue; } Material val2 = new Material(val); string[] array2 = new string[3] { "_UnlitColor", "_BaseColor", "_Color" }; foreach (string text2 in array2) { if (val2.HasProperty(text2)) { val2.SetColor(text2, color); } } return val2; } Material val3 = new Material(Shader.Find("Standard")); val3.color = color; return val3; } } internal static class StandInSystem { private readonly struct FrontRegion { public readonly Vector3 Origin; public readonly Vector3 Across; public readonly Vector3 Up; public readonly Vector3 Normal; public readonly float AcrossMin; public readonly float AcrossMax; public readonly float UpMin; public readonly float UpMax; public readonly int FrontSign; public FrontRegion(Vector3 origin, Vector3 across, Vector3 up, Vector3 normal, float acrossMin, float acrossMax, float upMin, float upMax, int frontSign) { //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_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000f: 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_0016: 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) Origin = origin; Across = across; Up = up; Normal = normal; AcrossMin = acrossMin; AcrossMax = acrossMax; UpMin = upMin; UpMax = upMax; FrontSign = frontSign; } } private sealed class Cup { public float CreatedAt; public bool HelloSent; public bool PinnerAdded; public bool ReportedShowing; public BoxLines? Highlight; public readonly Dictionary<int, float> HandoverSince = new Dictionary<int, float>(); public readonly Dictionary<int, List<Renderer>> HiddenReal = new Dictionary<int, List<Renderer>>(); public readonly Dictionary<int, List<GameObject>> HiddenScanNodes = new Dictionary<int, List<GameObject>>(); public readonly Dictionary<int, float> CalibStart = new Dictionary<int, float>(); public readonly HashSet<string> CalibGaveUp = new HashSet<string>(); public bool AfterSweep; public bool SawShipPhase; public int[]? ReadingOrder; public int[]? OrderIndex; public int HoveredSlot = -1; public bool TipShown; public string TipText = string.Empty; public GrabbableObject? TipHeld; public bool DesiredDirty; public readonly Dictionary<int, SlotState> Desired = new Dictionary<int, SlotState>(); public readonly Dictionary<int, SlotState> Applied = new Dictionary<int, SlotState>(); public readonly Dictionary<int, StandIn> StandIns = new Dictionary<int, StandIn>(); public int LastAimSent = -1; public bool CrosshairLogged; public float LastSwapAt = -10f; public float LastAimSentAt; public float NextReconcile; public readonly Dictionary<int, SlotState> LastSent = new Dictionary<int, SlotState>(); public readonly Dictionary<ulong, AimInfo> Aims = new Dictionary<ulong, AimInfo>(); public readonly Dictionary<int, float> RetryAfter = new Dictionary<int, float>(); public readonly Dictionary<int, int> RetryCount = new Dictionary<int, int>(); public readonly Dictionary<int, float> RealSince = new Dictionary<int, float>(); } private sealed class ExposedUnit { public readonly GrabbableObject? Item; public readonly bool Spawned; public readonly int Value; public readonly int Save; public ExposedUnit(GrabbableObject? item, int value, int save) { Item = item; Spawned = (Object)(object)item != (Object)null; Value = value; Save = save; } } private sealed class ExposedStack { public readonly Data Data; public readonly int Row; public readonly int Column; public readonly int RowLength; public readonly List<ExposedUnit> Units = new List<ExposedUnit>(); public ExposedStack(Data data, int row, int column, int rowLength) { Data = data; Row = row; Column = column; RowLength = rowLength; } } private sealed class ColliderBackup { public Vector3 Center; public Vector3 Size; } [CompilerGenerated] private static class <>O { public static HandleNamedMessageDelegate <0>__OnStateMessage; public static HandleNamedMessageDelegate <1>__OnHelloMessage; public static HandleNamedMessageDelegate <2>__OnAimMessage; public static HandleNamedMessageDelegate <3>__OnPoseMessage; public static HandleNamedMessageDelegate <4>__OnSwapMessage; } private const float AimDistance = 5f; private const float AimHeartbeatSeconds = 1f; private const float HandoverTimeoutSeconds = 2.5f; private const float PendingTimeoutSeconds = 5f; private static readonly HashSet<Renderer> HiddenRenderers = new HashSet<Renderer>(); private const float ReleaseCheckSeconds = 0.2f; private static float NextReleaseCheck; private static readonly List<Transform> LentScratch = new List<Transform>(); private const float AimMargin = 0.03f; private static MethodInfo? ShowTipsMethod; private static MethodInfo? ClearTipsMethod; private static MethodInfo? ItemTipsMethod; private static bool ResolvedTips; private const float SwapCooldownSeconds = 0.5f; private static float NextSwapAllowed; private const float FrontMargin = 0.4f; private static FieldInfo? CursorIconField; private static bool CursorIconResolved; private static readonly Color HighlightColor = new Color(0f, 0f, 1f); private static readonly Vector3[] BoxCornerBuffer = (Vector3[])(object)new Vector3[8]; private const string StateMessage = "SSSPLUS.StandIn.State"; private const string HelloMessage = "SSSPLUS.StandIn.Hello"; private const string AimMessage = "SSSPLUS.StandIn.Aim"; private const string SwapMessage = "SSSPLUS.StandIn.Swap"; private const string PoseMessage = "SSSPLUS.StandIn.Pose"; private static CustomMessagingManager? RegisteredMessaging; private const char RecordSeparator = '\u001e'; private const char FieldSeparator = '\u001f'; private static readonly Dictionary<int, (Quaternion rot, Vector3 pos, Vector3 scale)> LastCalibrationSample = new Dictionary<int, (Quaternion, Vector3, Vector3)>(); private const float CalibrationGiveUpSeconds = 8f; private const float AimStaleSeconds = 3f; private const float ReconcileSeconds = 0.2f; private const float QuietSecondsAfterSpawn = 6f; private static bool Materializing; private static MethodInfo? SpawnItemMethod; private static MethodInfo? GetItemMethod; private static MethodInfo? ShouldRescaleMethod; private static MethodInfo? UpdateNetworkQuantityMethod; private static Type? EffectsClass; private static float NextCacheFill; private static object? SssConfigInstance; private static bool ResolvedSssConfig; private static readonly ConditionalWeakTable<SmartCupboard, Cup> Cups = new ConditionalWeakTable<SmartCupboard, Cup>(); private static readonly Dictionary<int, SlotState> PendingStates = new Dictionary<int, SlotState>(); private static readonly Dictionary<string, bool> NeedsRealCache = new Dictionary<string, bool>(); private static readonly Dictionary<string, PoseOverride> PoseOverrides = new Dictionary<string, PoseOverride>(); private static SmartCupboard? CurrentCupboard; private static Cup? CurrentCup; private static float LastErrorLog = -100f; private const float ParentRotationToleranceDegrees = 10f; private static readonly List<ExposedStack> ExposedStacks = new List<ExposedStack>(); private static SmartCupboard? ExposedCupboard; private const float LoadGraceSeconds = 3.5f; private static bool LoadGraceActive; private static bool LoadCleanupPending; private static bool patchOwnersLogged; private const float TextFontSize = 1.5f; private const float TextRectHeight = 0.6f; private const float TextAboveQuantity = 0.1f; private const float TextBoxDepth = 0.12f; private const float TextBoxPadding = 0.04f; private static readonly Color32 TextOutlineColor = new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue); private static readonly Color32 TextHoverOutlineColor = new Color32((byte)0, (byte)0, byte.MaxValue, byte.MaxValue); private static readonly ConditionalWeakTable<BoxCollider, ColliderBackup> ColliderBackups = new ConditionalWeakTable<BoxCollider, ColliderBackup>(); internal static bool Enabled { get; private set; } private static void ApplyDesired(SmartCupboard cupboard, Cup cup) { cup.DesiredDirty = false; foreach (KeyValuePair<int, SlotState> item in cup.Desired) { ApplySlot(cupboard, cup, item.Key, item.Value); } if (!cup.ReportedShowing && cup.StandIns.Count > 0) { cup.ReportedShowing = true; SelfSortingStoragePLUS.Logger.LogInfo((object)$"[StandIns] Showing {cup.StandIns.Count} stand-in(s) from the host's cupboard."); } } private static void ApplySlot(SmartCupboard cupboard, Cup cup, int slot, SlotState state) { //IL_0117: Unknown result type (might be due to invalid IL or missing references) cup.Applied.TryGetValue(slot, out var value); if (value.Equals(state)) { return; } cup.Applied[slot] = state; if (!state.Valid) { RestoreHiddenReal(cup, slot); DestroyStandIn(cup, slot); SetQuantityText(cupboard, slot, 0); return; } if (!cup.StandIns.TryGetValue(slot, out StandIn value2) || value2.Id != state.Id) { DestroyStandIn(cup, slot); value2 = StandInVisual.Build(cupboard, slot, state.Id); if (value2 != null) { cup.StandIns[slot] = value2; } } if (value2 != null && !state.Real) { value2.Root.SetActive(true); RestoreHiddenReal(cup, slot); cup.HandoverSince.Remove(slot); } SetQuantityText(cupboard, slot, state.Quantity); bool flag = !value.Valid || state.Quantity > value.Quantity; if (value2 != null && !state.Real && flag && Time.unscaledTime - cup.CreatedAt > 6f) { PlayDropSound(state.Id, value2.Root.transform.position); } } internal static void PinRealItems(SmartCupboard cupboard) { //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Unknown result type (might be due to invalid IL or missing references) if (!Enabled || !Cups.TryGetValue(cupboard, out Cup value)) { return; } ReleaseTakenItems(cupboard, value); foreach (KeyValuePair<int, StandIn> standIn in value.StandIns) { StandIn value2 = standIn.Value; int key = standIn.Key; if ((Object)(object)value2.Root == (Object)null || key < 0 || key >= cupboard.placePositions.Length) { continue; } Transform val = cupboard.placePositions[key]; if ((Object)(object)val == (Object)null) { continue; } bool flag = !NeedsCalibration(cupboard, key, value2.Id); if (value2.Pending && Time.unscaledTime - value2.CreatedAt > 5f) { value2.SetPending(pending: false); } SlotState value3; bool flag2 = value.Applied.TryGetValue(key, out value3) && value3.Real && value2.Root.activeSelf; Transform transform = value2.Root.transform; bool flag3 = false; for (int i = 0; i < val.childCount; i++) { Transform child = val.GetChild(i); if ((Object)(object)child == (Object)(object)transform) { continue; } GrabbableObject component = ((Component)child).GetComponent<GrabbableObject>(); if ((Object)(object)component == (Object)null) { continue; } if (component.isHeld || component.isHeldByEnemy) { RestoreHiddenReal(value, key); RestoreTextCollider(component); continue; } if (flag && value2.IsText) { flag3 = PinToTextBox(val, child, component, value2); } else if (flag) { RestoreTextCollider(component); child.localPosition = transform.localPosition; child.localRotation = transform.localRotation; if (component.originalScale != Vector3.zero) { child.localScale = transform.localScale; } component.startFallingPosition = transform.localPosition; component.targetFloorPosition = transform.localPosition; component.fallTime = 1f; component.reachedFloorTarget = true; component.hasHitGround = true; flag3 = component.originalScale != Vector3.zero; } if (flag2) { HideReal(value, key, component); } } if (!flag2) { value.HandoverSince.Remove(key); continue; } if (value2.IsText) { value.HandoverSince.Remove(key); continue; } if (value.LastAimSent != key) { value.HandoverSince.Remove(key); continue; } if (!value.HandoverSince.TryGetValue(key, out var value4)) { value4 = Time.unscaledTime; value.HandoverSince[key] = value4; } if (flag3 || Time.unscaledTime - value4 > 2.5f) { value2.Root.SetActive(false); RestoreHiddenReal(value, key); value.HandoverSince.Remove(key); } } } internal static bool IsHiddenByStandIns(Renderer renderer) { return HiddenRenderers.Contains(renderer); } private static void HideReal(Cup cup, int slot, GrabbableObject item) { if (!cup.HiddenReal.TryGetValue(slot, out List<Renderer> value)) { value = new List<Renderer>(); cup.HiddenReal[slot] = value; } Renderer[] componentsInChildren = ((Component)item).GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if ((Object)(object)val != (Object)null && val.enabled) { val.enabled = false; value.Add(val); HiddenRenderers.Add(val); } } if (!cup.HiddenScanNodes.TryGetValue(slot, out List<GameObject> value2)) { value2 = new List<GameObject>(); cup.HiddenScanNodes[slot] = value2; } ScanNodeProperties[] componentsInChildren2 = ((Component)item).GetComponentsInChildren<ScanNodeProperties>(true); foreach (ScanNodeProperties val2 in componentsInChildren2) { if ((Object)(object)val2 != (Object)null && ((Component)val2).gameObject.activeSelf) { ((Component)val2).gameObject.SetActive(false); value2.Add(((Component)val2).gameObject); } } } private static Transform? SlotTransformOf(SmartCupboard cupboard, int slot) { if (slot < 0 || slot >= cupboard.placePositions.Length) { return null; } return cupboard.placePositions[slot]; } private static void CollectLentItems(Transform? slotTransform) { LentScratch.Clear(); if ((Object)(object)slotTransform == (Object)null) { return; } for (int i = 0; i < slotTransform.childCount; i++) { Transform child = slotTransform.GetChild(i); GrabbableObject component = ((Component)child).GetComponent<GrabbableObject>(); if ((Object)(object)component != (Object)null && !component.isHeld && !component.isHeldByEnemy) { LentScratch.Add(child); } } } private static bool BelongsToLentItem(Transform part) { for (int i = 0; i < LentScratch.Count; i++) { if (part.IsChildOf(LentScratch[i])) { return true; } } return false; } private static void ReleaseTakenItems(SmartCupboard cupboard, Cup cup) { float unscaledTime = Time.unscaledTime; if (unscaledTime < NextReleaseCheck) { return; } NextReleaseCheck = unscaledTime + 0.2f; foreach (KeyValuePair<int, List<GameObject>> hiddenScanNode in cup.HiddenScanNodes) { if (hiddenScanNode.Value.Count == 0) { continue; } CollectLentItems(SlotTransformOf(cupboard, hiddenScanNode.Key)); hiddenScanNode.Value.RemoveAll(delegate(GameObject node) { if ((Object)(object)node == (Object)null) { return true; } if (BelongsToLentItem(node.transform)) { return false; } node.SetActive(true); return true; }); } foreach (KeyValuePair<int, List<Renderer>> item in cup.HiddenReal) { if (item.Value.Count == 0) { continue; } CollectLentItems(SlotTransformOf(cupboard, item.Key)); item.Value.RemoveAll(delegate(Renderer renderer) { if ((Object)(object)renderer != (Object)null && BelongsToLentItem(((Component)renderer).transform)) { return false; } HiddenRenderers.Remove(renderer); if ((Object)(object)renderer != (Object)null) { renderer.enabled = true; } return true; }); } LentScratch.Clear(); } private static void RestoreHiddenReal(Cup cup, int slot) { if (cup.HiddenScanNodes.TryGetValue(slot, out List<GameObject> value)) { foreach (GameObject item in value) { if ((Object)(object)item != (Object)null) { item.SetActive(true); } } value.Clear(); } if (!cup.HiddenReal.TryGetValue(slot, out List<Renderer> value2)) { return; } foreach (Renderer item2 in value2) { HiddenRenderers.Remove(item2); if ((Object)(object)item2 != (Object)null) { item2.enabled = true; } } value2.Clear(); } private static void RebuildStandIn(int slot, string id) { SmartCupboard currentCupboard = CurrentCupboard; Cup currentCup = CurrentCup; if (!((Object)(object)currentCupboard == (Object)null) && currentCup != null && currentCup.StandIns.TryGetValue(slot, out StandIn value) && !(value.Id != id)) { DestroyStandIn(currentCup, slot); StandIn standIn = StandInVisual.Build(currentCupboard, slot, id); if (standIn != null) { currentCup.StandIns[slot] = standIn; standIn.Root.SetActive(true); } } } private static void DestroyStandIn(Cup cup, int slot) { if (cup.StandIns.TryGetValue(slot, out StandIn value)) { value.Destroy(); cup.StandIns.Remove(slot); } } private static void SetQuantityText(SmartCupboard cupboard, int slot, int quantity) { try { if (slot >= 0 && slot < cupboard.quantitiesTexts.Length && !((Object)(object)cupboard.quantitiesTexts[slot] == (Object)null) && ReadSssBool("quantityDisplayActive", fallback: true)) { ShowQuantity(cupboard.quantitiesTexts[slot], quantity); } } catch { } } private static void PlayDropSound(string id, Vector3 position) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) try { Item val = ResolveItem(id); if ((Object)(object)val != (Object)null && (Object)(object)val.dropSFX != (Object)null) { AudioSource.PlayClipAtPoint(val.dropSFX, position, 0.7f); } } catch { } } private static void ClientHover(SmartCupboard cupboard, Cup cup, float now) { bool keepCurrent; int num = FindAimedSlot(cupboard, cup, out keepCurrent); if (!keepCurrent && (num != cup.LastAimSent || (num >= 0 && now - cup.LastAimSentAt >= 1f))) { cup.LastAimSent = num; cup.LastAimSentAt = now; SendAim(num); } } private static int FindAimedSlot(SmartCupboard cupboard, Cup cup, out bool keepCurrent) { //IL_0072: 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_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_016b: 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_018d: 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_0198: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) keepCurrent = false; PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null); if ((Object)(object)val == (Object)null || val.isPlayerDead || (Object)(object)val.gameplayCamera == (Object)null || cup.StandIns.Count == 0) { return -1; } if (val.isGrabbingObjectAnimation) { keepCurrent = true; return -1; } if (val.FirstEmptyItemSlot((GrabbableObject)null) == -1) { return -1; } Transform transform = ((Component)val.gameplayCamera).transform; if (Vector3.Distance(transform.position, ((Component)cupboard).transform.position) > 9f) { return -1; } Ray ray = default(Ray); ((Ray)(ref ray))..ctor(transform.position, transform.forward); float num = 0.03f; int lastAimSent = cup.LastAimSent; if (lastAimSent >= 0 && cup.StandIns.TryGetValue(lastAimSent, out StandIn value) && (Object)(object)value.Root != (Object)null && AimsAtSlot(value, ray, num * 2f, out var _)) { return lastAimSent; } int result = -1; float num2 = float.MaxValue; foreach (KeyValuePair<int, StandIn> standIn in cup.StandIns) { StandIn value2 = standIn.Value; int key = standIn.Key; if ((Object)(object)value2.Root == (Object)null || key < 0 || key >= cupboard.placePositions.Length) { continue; } Vector3 val2 = value2.Root.transform.position - ((Ray)(ref ray)).origin; float num3 = Vector3.Dot(val2, ((Ray)(ref ray)).direction); if (!(num3 < -0.5f) && !(num3 > 6f)) { Vector3 val3 = val2 - ((Ray)(ref ray)).direction * num3; if (!(((Vector3)(ref val3)).sqrMagnitude > 2.25f) && AimsAtSlot(value2, ray, num, out var distance2) && distance2 < num2) { result = key; num2 = distance2; } } } return result; } private static bool AimsAtSlot(StandIn standIn, Ray ray, float margin, out float distance) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) if (standIn.IsText) { return standIn.RaycastText(ray, 5f, margin, out distance); } if (standIn.HasBox) { return standIn.RaycastBox(ray, 5f, margin, out distance); } Bounds val = standIn.WorldBounds(); ((Bounds)(ref val)).Expand(0.05f + margin * 2f); if (((Bounds)(ref val)).IntersectRay(ray, ref distance)) { return distance <= 5f; } return false; } private static GrabbableObject? FindRealItem(Transform? slotTransform, Transform standInRoot) { if ((Object)(object)slotTransform == (Object)null) { return null; } for (int i = 0; i < slotTransform.childCount; i++) { Transform child = slotTransform.GetChild(i); if (!((Object)(object)child == (Object)(object)standInRoot)) { GrabbableObject component = ((Component)child).GetComponent<GrabbableObject>(); if ((Object)(object)component != (Object)null && !component.isHeld && !component.isHeldByEnemy) { return component; } } } return null; } private static bool EnsureReadingOrder(SmartCupboard cupboard, Cup cup) { //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: 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) if (cup.ReadingOrder != null) { return true; } List<List<Data>> itemList = cupboard.memory.ItemList; int count = itemList.Count; int rowLength = ((count > 0) ? itemList[0].Count : 0); int num = count * rowLength; TMP_Text[] quantitiesTexts = cupboard.quantitiesTexts; Transform[] places = cupboard.placePositions; if (rowLength <= 0 || quantitiesTexts == null || places == null || quantitiesTexts.Length < num || places.Length < num) { return false; } for (int i = 0; i < num; i++) { if ((Object)(object)quantitiesTexts[i] == (Object)null || (Object)(object)places[i] == (Object)null) { return false; } } Vector3 right = quantitiesTexts[0].transform.right; float[] rowHeight = new float[count]; float num2 = float.MaxValue; float num3 = float.MinValue; for (int j = 0; j < count; j++) { float num4 = 0f; for (int k = 0; k < rowLength; k++) { num4 += places[j * rowLength + k].position.y; } rowHeight[j] = num4 / (float)rowLength; num2 = Mathf.Min(num2, rowHeight[j]); num3 = Mathf.Max(num3, rowHeight[j]); } List<int> list = new List<int>(); for (int l = 0; l < count; l++) { list.Add(l); } if (num3 - num2 > 0.02f) { list.Sort((int a, int b) => rowHeight[b].CompareTo(rowHeight[a])); } List<int> list2 = new List<int>(); foreach (int item in list) { int row = item; List<int> list3 = new List<int>(); for (int num5 = 0; num5 < rowLength; num5++) { list3.Add(num5); } list3.Sort((int a, int b) => Vector3.Dot(places[row * rowLength + a].position, right).CompareTo(Vector3.Dot(places[row * rowLength + b].position, right))); foreach (int item2 in list3) { list2.Add(row * rowLength + item2); } } int[] array = list2.ToArray(); int[] array2 = new int[num]; for (int num6 = 0; num6 < array.Length; num6++) { array2[array[num6]] = num6; } cup.OrderIndex = array2; cup.ReadingOrder = array; return true; } private static void UpdateSwapControls(SmartCupboard cupboard, Cup cup) { try { int hoveredSlot = cup.HoveredSlot; PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null); if (hoveredSlot < 0 || (Object)(object)val == (Object)null || !EnsureReadingOrder(cupboard, cup)) { HideSwapTip(cup); return; } int[] readingOrder = cup.ReadingOrder; int num = cup.OrderIndex[hoveredSlot]; int count = cupboard.memory.ItemList[0].Count; bool flag = num > 0; bool flag2 = num < readingOrder.Length - 1; List<string> list = new List<string>(); Data val2 = cupboard.memory.ItemList[hoveredSlot / count][hoveredSlot % count]; if (val2.IsValid()) { list.Add("<b>" + (ResolveItem(val2.Id)?.itemName ?? NameFromId(val2.Id)) + "</b>"); } if (flag) { bool flag3 = readingOrder[num - 1] / count != hoveredSlot / count; list.Add((flag3 ? "Move to previous row" : "Move left") + " : " + StandInKeybinds.KeyName(right: false)); } if (flag2) { bool flag4 = readingOrder[num + 1] / count != hoveredSlot / count; list.Add((flag4 ? "Move to next row" : "Move right") + " : " + StandInKeybinds.KeyName(right: true)); } ShowSwapTip(cup, val, list); if (InputAllowed(val)) { if (flag2 && StandInKeybinds.WasPressed(right: true)) { RequestSwap(cupboard, cup, hoveredSlot, 1); } else if (flag && StandInKeybinds.WasPressed(right: false)) { RequestSwap(cupboard, cup, hoveredSlot, -1); } } } catch (Exception ex) { float unscaledTime = Time.unscaledTime; if (unscaledTime - LastErrorLog > 10f) { LastErrorLog = unscaledTime; SelfSortingStoragePLUS.Logger.LogWarning((object)("[StandIns] Reorder controls failed: " + ex.Message)); } } } private static bool InputAllowed(PlayerControllerB player) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Invalid comparison between Unknown and I4 if (player.isPlayerDead || (int)Cursor.lockState != 1) { return false; } if (!ReadBool(player, "isTypingChat")) { return !ReadBool(player, "inTerminalMenu"); } return false; } private static bool ReadBool(object target, string field) { try { object obj = AccessTools.Field(target.GetType(), field)?.GetValue(target); bool flag = default(bool); int num; if (obj is bool) { flag = (bool)obj; num = 1; } else { num = 0; } return (byte)((uint)num & (flag ? 1u : 0u)) != 0; } catch { return false; } } private static void RequestSwap(SmartCupboard cupboard, Cup cup, int slot, int direction) { float unscaledTime = Time.unscaledTime; if (!(unscaledTime < NextSwapAllowed)) { int num = cup.OrderIndex[slot] + direction; if (num >= 0 && num < cup.ReadingOrder.Length) { NextSwapAllowed = unscaledTime + 0.5f; SendSwap(slot, cup.ReadingOrder[num]); } } } private static void ResolveTipMethods() { if (ResolvedTips) { return; } ResolvedTips = true; try { ShowTipsMethod = AccessTools.Method(typeof(HUDManager), "ChangeControlTipMultiple", (Type[])null, (Type[])null); ClearTipsMethod = AccessTools.Method(typeof(HUDManager), "ClearControlTips", (Type[])null, (Type[])null); ItemTipsMethod = AccessTools.Method(typeof(GrabbableObject), "SetControlTipsForItem", (Type[])null, (Type[])null); } catch (Exception ex) { SelfSortingStoragePLUS.Logger.LogWarning((object)("[StandIns] Could not find the game's control tip methods: " + ex.Message)); } } private static GrabbableObject? HeldItem(PlayerControllerB player) { GrabbableObject[] itemSlots = player.ItemSlots; int currentItemSlot = player.currentItemSlot; if (itemSlots == null || currentItemSlot < 0 || currentItemSlot >= itemSlots.Length) { return null; } return itemSlots[currentItemSlot]; } private static void ShowSwapTip(Cup cup, PlayerControllerB player, List<string> lines) { ResolveTipMethods(); if (!(ShowTipsMethod == null) && !((Object)(object)HUDManager.Instance == (Object)null) && lines.Count != 0) { string text = string.Join("\n", lines); GrabbableObject val = HeldItem(player); if (!cup.TipShown || !(cup.TipText == text) || cup.TipHeld != val) { ShowTipsMethod.Invoke(HUDManager.Instance, new object[3] { lines.ToArray(), false, null }); cup.TipShown = true; cup.TipText = text; cup.TipHeld = val; } } } private static void HideSwapTip(Cup cup) { if (!cup.TipShown) { return; } cup.TipShown = false; cup.TipText = string.Empty; cup.TipHeld = null; try { ResolveTipMethods(); PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null); GrabbableObject val2 = (((Object)(object)val != (Object)null) ? HeldItem(val) : null); if ((Object)(object)val2 != (Object)null && ItemTipsMethod != null) { ItemTipsMethod.Invoke(val2, null); } else if ((Object)(object)HUDManager.Instance != (Object)null) { ClearTipsMethod?.Invoke(HUDManager.Instance, null); } } catch (Exception ex) { SelfSortingStoragePLUS.Logger.LogWarning((object)("[StandIns] Could not restore the control tips: " + ex.Message)); } } private static void HandleSwap(ulong clientId, int a, int b) { SmartCupboardGuard(out Cup cup, out SmartCupboard cupboard); if (cup == null || (Object)(object)cupboard == (Object)null || !EnsureReadingOrder(cupboard, cup)) { return; } float unscaledTime = Time.unscaledTime; if (unscaledTime - cup.LastSwapAt < 0.5f) { return; } int[] orderIndex = cup.OrderIndex; if (a < 0 || b < 0 || a >= orderIndex.Length || b >= orderIndex.Length || a == b || Mathf.Abs(orderIndex[a] - orderIndex[b]) != 1) { return; } List<List<Data>> itemList = cupboard.memory.ItemList; int count = itemList[0].Count; Data val = itemList[a / count][a % count]; Data val2 = itemList[b / count][b % count]; if (!val.IsValid() && !val2.IsValid()) { return; } int[] array = new int[2] { a, b }; foreach (int slot in array) { if (TryGetReal(cupboard, slot, out GrabbableObject item) && (Object)(object)item != (Object)null && (item.isHeld || item.isHeldByEnemy || item.heldByPlayerOnServer)) { return; } } cup.LastSwapAt = unscaledTime; int[] array2 = new int[2] { a, b }; foreach (int num in array2) { if (TryGetReal(cupboard, num, out GrabbableObject item2) && (Object)(object)item2 != (Object)null) { Dematerialize(cupboard, num, item2, hide: false); } cup.RetryAfter.Remove(num); cup.RetryCount.Remove(num); } itemList[a / count][a % count] = val2; itemList[b / count][b % count] = val; Reconcile(cupboard, cup); } private static void UpdateCrosshair(SmartCupboard cupboard, Cup cup) { bool show = false; try { show = ShouldShowCrosshair(cupboard, cup); } catch { } StandInCrosshair.Request(show); } private static bool ShouldShowCrosshair(SmartCupboard cupboard, Cup cup) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Invalid comparison between Unknown and I4 //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: 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_0081: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) if ((int)Cursor.lockState != 1) { return false; } PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null); if ((Object)(object)val == (Object)null || val.isPlayerDead || (Object)(object)val.gameplayCamera == (Object)null) { return false; } if (InteractIconVisible(val)) { return false; } if (!TryGetFrontRegion(cupboard, cup, out var region)) { return cup.LastAimSent >= 0; } Transform transform = ((Component)val.gameplayCamera).transform; Vector3 forward = transform.forward; float num = Vector3.Dot(region.Normal, forward); if (Mathf.Abs(num) < 0.05f) { return cup.LastAimSent >= 0; } float num2 = Vector3.Dot(region.Origin - transform.position, region.Normal) / num; if (num2 < 0f || num2 > 6f) { return cup.LastAimSent >= 0; } Vector3 val2 = transform.position + forward * num2 - region.Origin; float num3 = Vector3.Dot(val2, region.Across); float num4 = Vector3.Dot(val2, region.Up); if (num3 < region.AcrossMin || num3 > region.AcrossMax || num4 < region.UpMin || num4 > region.UpMax) { return cup.LastAimSent >= 0; } if (region.FrontSign != 0 && Vector3.Dot(transform.position - region.Origin, region.Normal) * (float)region.FrontSign <= 0f) { return cup.LastAimSent >= 0; } return true; } private static bool InteractIconVisible(PlayerControllerB player) { if (!CursorIconResolved) { CursorIconResolved = true; CursorIconField = AccessTools.Field(typeof(PlayerControllerB), "cursorIcon"); } if (CursorIconField != null) { object? value = CursorIconField.GetValue(player); Behaviour val = (Behaviour)((value is Behaviour) ? value : null); if (val != null && (Object)(object)val != (Object)null) { return val.isActiveAndEnabled; } } return false; } private static bool TryGetFrontRegion(SmartCupboard cupboard, Cup cup, out FrontRegion region) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: 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_005f: 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_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_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) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_009b: 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_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_014f: 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_0156: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: 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_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0187: 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_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_026b: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Unknown result type (might be due to invalid IL or missing references) //IL_0279: Unknown result type (might be due to invalid IL or missing references) //IL_027e: Unknown result type (might be due to invalid IL or missing references) //IL_02e5: Unknown result type (might be due to invalid IL or missing references) //IL_02ea: Unknown result type (might be due to invalid IL or missing references) //IL_02ee: Unknown result type (might be due to invalid IL or missing references) //IL_02f3: Unknown result type (might be due to invalid IL or missing references) //IL_02f5: Unknown result type (might be due to invalid IL or missing references) //IL_02fa: Unknown result type (might be due to invalid IL or missing references) //IL_03d3: Unknown result type (might be due to invalid IL or missing references) //IL_03d5: Unknown result type (might be due to invalid IL or missing references) //IL_03d7: Unknown result type (might be due to invalid IL or missing references) //IL_03d9: Unknown result type (might be due to invalid IL or missing references) region = default(FrontRegion); List<List<Data>> itemList = cupboard.memory.ItemList; int count = itemList.Count; int num = ((count > 0) ? itemList[0].Count : 0); Transform[] placePositions = cupboard.placePositions; if (count == 0 || num == 0 || placePositions.Length < count * num) { return false; } Vector3 val = Vector3.zero; for (int i = 0; i < count * num; i++) { if ((Object)(object)placePositions[i] == (Object)null) { return false; } val += placePositions[i].position; } val /= (float)(count * num); Vector3 val2 = Vector3.zero; if (num >= 2) { for (int j = 0; j < count; j++) { val2 += placePositions[j * num + num - 1].position - placePositions[j * num].position; } } Vector3 val3 = Vector3.zero; if (count >= 2) { for (int k = 0; k < num; k++) { val3 += placePositions[(count - 1) * num + k].position - placePositions[k].position; } } if (((Vector3)(ref val2)).sqrMagnitude < 0.0001f) { val2 = ((Component)cupboard).transform.right; } if (((Vector3)(ref val3)).sqrMagnitude < 0.0001f) { val3 = Vector3.up; } ((Vector3)(ref val2)).Normalize(); ((Vector3)(ref val3)).Normalize(); Vector3 val4 = Vector3.Cross(val2, val3); if (((Vector3)(ref val4)).sqrMagnitude < 0.01f) { val4 = ((Component)cupboard).transform.forward; } ((Vector3)(ref val4)).Normalize(); Vector3 val5 = Vector3.Cross(val4, val2); val3 = ((Vector3)(ref val5)).normalized; float num2 = float.MaxValue; float num3 = float.MinValue; float num4 = float.MaxValue; float num5 = float.MinValue; for (int l = 0; l < count * num; l++) { Vector3 val6 = placePositions[l].position - val; float num6 = Vector3.Dot(val6, val2); float num7 = Vector3.Dot(val6, val3); num2 = Mathf.Min(num2, num6); num3 = Mathf.Max(num3, num6); num4 = Mathf.Min(num4, num7); num5 = Mathf.Max(num5, num7); } num2 -= 0.4f; num3 += 0.4f; num4 -= 0.4f; num5 += 0.4f; int num8 = 0; float num9 = 0f; int num10 = 0; for (int m = 0; m < Mathf.Min(cupboard.quantitiesTexts.Length, count * num); m++) { if (!((Object)(object)cupboard.quantitiesTexts[m] == (Object)null)) { num9 += Vector3.Dot(cupboard.quantitiesTexts[m].transform.position - placePositions[m].position, val4); num10++; } } if (num10 > 0 && Mathf.Abs(num9 / (float)num10) >= 0.03f) { num8 = ((num9 > 0f) ? 1 : (-1)); } int num11 = 0; Collider val7 = FrontCollider(cupboard); if ((Object)(object)val7 != (Object)null) { Bounds bounds = val7.bounds; float num12 = Vector3.Dot(((Bounds)(ref bounds)).center - val, val4); if (Mathf.Abs(num12) >= 0.05f) { num11 = ((num12 > 0f) ? 1 : (-1)); } } int num13 = ((num8 != 0 && num8 == num11) ? num8 : 0); if (!cup.CrosshairLogged && SelfSortingStoragePLUS.VerboseLogging.Value) { cup.CrosshairLogged = true; SelfSortingStoragePLUS.Logger.LogInfo((object)(string.Format("[StandIns] Crosshair area: {0:F2} x {1:F2} m, normal {2}; ", num3 - num2, num5 - num4, ((Vector3)(ref val4)).ToString("F2")) + $"front side hints: labels {num8}, trigger {num11} " + "(" + ((num13 != 0) ? "the back side is left out" : "shown from both sides") + ").")); } region = new FrontRegion(val, val2, val3, val4, num2, num3, num4, num5, num13); return true; } private static Collider? FrontCollider(SmartCupboard cupboard) { InteractTrigger triggerScript = cupboard.triggerScript; if ((Object)(object)triggerScript == (Object)null) { return null; } Collider component = ((Component)triggerScript).GetComponent<Collider>(); if (!((Object)(object)component != (Object)null)) { return ((Component)triggerScript).GetComponentInChildren<Collider>(true); } return component; } internal static void DrawOverlays(SmartCupboard cupboard) { if (Enabled && Cups.TryGetValue(cupboard, out Cup value)) { SyncTextMode(value); DrawHoverHighlight(cupboard, value); UpdateTextStandIns(cupboard, value); UpdateCrosshair(cupboard, value); UpdateSwapControls(cupboard, value); } } private static void DrawHoverHighlight(SmartCupboard cupboard, Cup cup) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: 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 (cup.Highlight == null) { cup.Highlight = new BoxLines(((Component)cupboard).transform, HighlightColor, "SSSPLUS_HoverBox"); } BoxLines highlight = cup.Highlight; highlight.Begin(); cup.HoveredSlot = -1; try { int lastAimSent = cup.LastAimSent; if (lastAimSent < 0 || lastAimSent >= cupboard.placePositions.Length || !cup.StandIns.TryGetValue(lastAimSent, out StandIn value) || (Object)(object)value.Root == (Object)null) { return; } GrabbableObject val = FindRealItem(cupboard.placePositions[lastAimSent], value.Root.transform); if ((Object)(object)val == (Object)null) { return; } if (!value.IsText) { Collider[] components = ((Component)val).GetComponents<Collider>(); foreach (Collider val2 in components) { if (!((Object)(object)val2 == (Object)null) && val2.enabled) { BoxCollider val3 = (BoxCollider)(object)((val2 is BoxCollider) ? val2 : null); if (val3 != null) { FillBoxCorners(((Component)val3).transform, val3.center, val3.size); } else { FillBoundsCorners(val2.bounds); } highlight.Draw(BoxCornerBuffer); } } } cup.HoveredSlot = lastAimSent; } finally { highlight.End(); } } private static void FillBoxCorners(Transform transform, Vector3 center, Vector3 size) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: 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_0014: 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_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0052: 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_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: 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) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: 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) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) Vector3 val = size * 0.5f; BoxCornerBuffer[0] = transform.TransformPoint(center + new Vector3(0f - val.x, 0f - val.y, 0f - val.z)); BoxCornerBuffer[1] = transform.TransformPoint(center + new Vector3(val.x, 0f - val.y, 0f - val.z)); BoxCornerBuffer[2] = transform.TransformPoint(center + new Vector3(val.x, 0f - val.y, val.z)); BoxCornerBuffer[3] = transform.TransformPoint(center + new Vector3(0f - val.x, 0f - val.y, val.z)); BoxCornerBuffer[4] = transform.TransformPoint(center + new Vector3(0f - val.x, val.y, 0f - val.z)); BoxCornerBuffer[5] = transform.TransformPoint(center + new Vector3(val.x, val.y, 0f - val.z)); BoxCornerBuffer[6] = transform.TransformPoint(center + new Vector3(val.x, val.y, val.z)); BoxCornerBuffer[7] = transform.TransformPoint(center + new Vector3(0f - val.x, val.y, val.z)); } private static void FillBoundsCorners(Bounds bounds) { //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_000a: 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_0016: 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) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: 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_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_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_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: 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) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) Vector3 min = ((Bounds)(ref bounds)).min; Vector3 max = ((Bounds)(ref bounds)).max; BoxCornerBuffer[0] = new Vector3(min.x, min.y, min.z); BoxCornerBuffer[1] = new Vector3(max.x, min.y, min.z); BoxCornerBuffer[2] = new Vector3(max.x, min.y, max.z); BoxCornerBuffer[3] = new Vector3(min.x, min.y, max.z); BoxCornerBuffer[4] = new Vector3(min.x, max.y, min.z); BoxCornerBuffer[5] = new Vector3(max.x, max.y, min.z); BoxCornerBuffer[6] = new Vector3(max.x, max.y, max.z); BoxCornerBuffer[7] = new Vector3(min.x, max.y, max.z); } private static void EnsureNet() { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Expected O, but got Unknown //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Expected O, but got Unknown //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Expected O, but got Unknown //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Expected O, but got Unknown //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Expected O, but got Unknown NetworkManager singleton = NetworkManager.Singleton; CustomMessagingManager val = (((Object)(object)singleton != (Object)null) ? singleton.CustomMessagingManager : null); if (val == null || val == RegisteredMessaging) { return; } try { object obj = <>O.<0>__OnStateMessage; if (obj == null) { HandleNamedMessageDelegate val2 = OnStateMessage; <>O.<0>__OnStateMessage = val2; obj = (object)val2; } val.RegisterNamedMessageHandler("SSSPLUS.StandIn.State", (HandleNamedMessageDelegate)obj); object obj2 = <>O.<1>__OnHelloMessage; if (obj2 == null) { HandleNamedMessageDelegate val3 = OnHelloMessage; <>O.<1>__OnHelloMessage = val3; obj2 = (object)val3; } val.RegisterNamedMessageHandler("SSSPLUS.StandIn.Hello", (HandleNamedMessageDelegate)obj2); object obj3 = <>O.<2>__OnAimMessage; if (obj3 == null) { HandleNamedMessageDelegate val4 = OnAimMessage; <>O.<2>__OnAimMessage = val4; obj3 = (object)val4; } val.RegisterNamedMessageHandler("SSSPLUS.StandIn.Aim", (HandleNamedMessageDelegate)obj3); object obj4 = <>O.<3>__OnPoseMessage; if (obj4 == null) { HandleNamedMessageDelegate val5 = OnPoseMessage; <>O.<3>__OnPoseMessage = val5; obj4 = (object)val5; } val.RegisterNamedMessageHandler("SSSPLUS.StandIn.Pose", (HandleNamedMessageDelegate)obj4); object obj5 = <>O.<4>__OnSwapMessage; if (obj5 == null) { HandleNamedMessageDelegate val6 = OnSwapMessage; <>O.<4>__OnSwapMessage = val6; obj5 = (object)val6; } val.RegisterNamedMessageHandler("SSSPLUS.StandIn.Swap", (HandleNamedMessageDelegate)obj5); SelfSortingStoragePLUS.Logger.LogInfo((object)"[StandIns] Network handlers registered."); } catch (Exception ex) { SelfSortingStoragePLUS.Logger.LogError((object)("[StandIns] Could not register network handlers: " + ex)); } RegisteredMessaging = val; } private unsafe static bool SendString(string messageName, ulong clientId, string payload) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) NetworkManager singleton = NetworkManager.Singleton; CustomMessagingManager val = (((Object)(object)singleton != (Object)null) ? singleton.CustomMessagingManager : null); if (val == null) { return false; } try { FastBufferWriter val2 = default(FastBufferWriter); ((FastBufferWriter)(ref val2))..ctor(FastBufferWriter.GetWriteSize(payload, false), (Allocator)2, -1); try { ((FastBufferWriter)(ref val2)).WriteValueSafe(payload, false); val.SendNamedMessage(messageName, clientId, val2, (NetworkDelivery)4); return true; } finally { ((IDisposable)(*(FastBufferWriter*)(&val2))/*cast due to .constrained prefix*/).Dispose(); } } catch (Exception ex) { SelfSortingStoragePLUS.Logger.LogWarning((object)("[StandIns] Could not send '" + messageName + "': " + ex.Message)); return false; } } private static string EncodeState(int slot, SlotState state) { return $"{slot}|{(state.Valid ? 1 : 0)}|{(state.Real ? 1 : 0)}|{state.Quantity}|{state.Id}"; } private static bool TryDecodeState(string payload, out int slot, out SlotState state) { slot = -1; state = SlotState.Empty; string[] array = payload.Split(new char[1] { '|' }, 5); if (array.Length < 5 || !int.TryParse(array[0], out slot) || !int.TryParse(array[3], out var result)) { return false; } state = new SlotState(array[1] == "1", array[4], result, array[2] == "1"); return true; } private static void BroadcastState(int slot, SlotState state) { NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || !singleton.IsServer) { return; } string payload = EncodeState(slot, state); foreach (ulong connectedClientsId in singleton.ConnectedClientsIds) { if (connectedClientsId != 0L) { SendString("SSSPLUS.StandIn.State", connectedClientsId, payload); } } } private static void SendFullState(ulong clientId, Cup cup) { foreach (KeyValuePair<int, SlotState> item in cup.LastSent) { if (item.Value.Valid) { SendString("SSSPLUS.StandIn.State", clientId, EncodeState(item.Key, item.Value)); } } } private static void OnStateMessage(ulong senderClientId, FastBufferReader reader) { try { string payload = default(string); ((FastBufferReader)(ref reader)).ReadValueSafe(ref payload, false); if (TryDecodeState(payload, out var slot, out var state)) { Cup currentCup = CurrentCup; if (currentCup == null) { PendingStates[slot] = state; return; } currentCup.Desired[slot] = state; currentCup.DesiredDirty = true; } } catch (Exception ex) { SelfSortingStoragePLUS.Logger.LogWarning((object)("[StandIns] Bad state message: " + ex.Message)); } } private static string F(float value) { return value.ToString("R", CultureInfo.InvariantCulture); } private static string EncodeTransform(Vector3 position, Quaternion rotation, Vector3 scale) { //IL_000e: 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) //IL_002a: 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_0046: 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_0062: 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_007e: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) return string.Join(",", F(position.x), F(position.y), F(position.z), F(rotation.x), F(rotation.y), F(rotation.z), F(rotation.w), F(scale.x), F(scale.y), F(scale.z)); } private static bool TryParseTransform(string text, out Vector3 position, out Quaternion rotation, out Vector3 scale) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: 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_0018: 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_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) position = default(Vector3); rotation = Quaternion.identity; scale = Vector3.one; string[] array = text.Split(','); if (array.Length < 10) { return false; } float[] array2 = new float[10]; for (int i = 0; i < 10; i++) { if (!float.TryParse(array[i], NumberStyles.Float, CultureInfo.InvariantCulture, out array2[i])) { return false; } } position = new Vector3(array2[0], array2[1], array2[2]); rotation = new Quaternion(array2[3], array2[4], array2[5], array2[6]); scale = new Vector3(array2[7], array2[8], array2[9]); return true; } private static string EncodePose(string id, PoseOverride pose) { //IL_0017: 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_0049: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: 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_00f9: Unknown result type (might be due to invalid IL or missing references) StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(id).Append('\u001e'); stringBuilder.Append(EncodeTransform(pose.Position, pose.Rotation, pose.Scale)).Append('\u001e'); stringBuilder.Append(string.Join(",", F(pose.ParentRotation.x), F(pose.ParentRotation.y), F(pose.ParentRotation.z), F(pose.ParentRotation.w))); if (pose.Parts != null) { PartPose[] parts = pose.Parts; for (int i = 0; i < parts.Length; i++) { PartPose partPose = parts[i]; stringBuilder.Append('\u001e').Append(partPose.Path).Append('\u001f') .Append(partPose.Visible ? '1' : '0') .Append('\u001f') .Append(EncodeTransform(partPose.Position, partPose.Rotation, partPose.Scale)); } } return stringBuilder.ToString(); } private static bool TryDecodePose(string payload, out string id, out PoseOverride pose) { //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_010f: 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_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) id = string.Empty; pose = default(PoseOverride); string[] array = payload.Split('\u001e'); if (array.Length < 3) { return false; } if (!TryParseTransform(array[1], out var position, out var rotation, out var scale)) { return false; } string[] array2 = array[2].Split(','); if (array2.Length < 4 || !float.TryParse(array2[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var result) || !float.TryParse(array2[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) || !float.TryParse(array2[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result3) || !float.TryParse(array2[3], NumberStyles.Float, CultureInfo.InvariantCulture, out var result4)) { return false; } List<PartPose> list = new List<PartPose>(); for (int i = 3; i < array.Length; i++) { string[] array3 = array[i].Split('\u001f'); if (array3.Length >= 3 && TryParseTransform(array3[2], out var position2, out var rotation2, out var scale2)) { list.Add(new PartPose(array3[0], array3[1] == "1", position2, rotation2, scale2)); } } id = array[0]; pose = new PoseOverride(position, rotation, scale, new Quaternion(result, result2, result3, result4), list.ToArray()); return true; } private static void SetPoseOverride(string key, PoseOverride pose, bool broadcast) { PoseOverrides[key] = pose; if (TrySplitPoseKey(key, out int slot, out string id)) { RebuildStandIn(slot, id); } NetworkManager singleton = NetworkManager.Singleton; if (!broadcast || (Object)(object)singleton == (Object)null || !singleton.IsServer) { return; } string payload = EncodePose(key, pose); foreach (ulong connectedClientsId in singleton.ConnectedClientsIds) { if (connectedClientsId != 0L) { SendString("SSSPLUS.StandIn.Pose", connectedClientsId, payload); } } } private static void OnPoseMessage(ulong senderClientId, FastBufferReader reader) { try { string payload = default(string); ((FastBufferReader)(ref reader)).ReadValueSafe(ref payload, false); if (TryDecodePose(payload, out string id, out PoseOverride pose)) { SetPoseOverride(id, pose, broadcast: false); } } catch (Exception ex) { SelfSortingStoragePLUS.Logger.LogWarning((object)("[StandIns] Bad pose message: " + ex.Message)); } } private static bool SendHello() { NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || singleton.IsServer) { return true; } return SendString("SSSPLUS.StandIn.Hello", 0uL, "hello"); } private static void SendAim(int slot) { NetworkManager singleton = NetworkManager.Singleton; if (!((Object)(object)singleton == (Object)null)) { if (singleton.IsServer) { HandleAim(0uL, slot); } else { SendString("SSSPLUS.StandIn.Aim", 0uL, slot.ToString()); } } } private static void SendSwap(int from, int to) { NetworkManager singleton = NetworkManager.Singleton; if (!((Object)(object)singleton == (Object)null)) { if (singleton.IsServer) { HandleSwap(0uL, from, to); } else { SendString("SSSPLUS.StandIn.Swap", 0uL, $"{from}|{to}"); } } } private static void OnSwapMessage(ulong senderClientId, FastBufferReader reader) { try { string text = default(string); ((FastBufferReader)(ref reader)).ReadValueSafe(ref text, false); string[] array = text.Split('|'); if (array.Length == 2 && int.TryParse(array[0], out var result) && int.TryParse(array[1], out var result2)) { HandleSwap(senderClientId, result, result2); } } catch (Exception ex) { SelfSortingStoragePLUS.Logger.LogWarning((object)("[StandIns] Bad swap message: " + ex.Message)); } } private static void OnHelloMessage(ulong senderClientId, FastBufferReader reader) { try { SmartCupboardGuard(out Cup cup, out SmartCupboard cupboard); if (cup == null || (Object)(object)cupboard == (Object)null) { return; } Reconcile(cupboard, cup); SendFullState(senderClientId, cup); foreach (KeyValuePair<string, PoseOverride> poseOverride in PoseOverrides) { SendString("SSSPLUS.StandIn.Pose", senderClientId, EncodePose(poseOverride.Key, poseOverride.Value)); } } catch (Exception ex) { SelfSortingStoragePLUS.Logger.LogWarning((object)("[StandIns] Bad hello message: " + ex.Message)); } } private static void OnAimMessage(ulong senderClientId, FastBufferReader reader) { try { string s = default(string); ((FastBufferReader)(ref reader)).ReadValueSafe(ref s, false); if (int.TryParse(s, out var result)) { HandleAim(senderClientId, result); } } catch (Exception ex) { SelfSortingStoragePLUS.Logger.LogWarning((object)("[StandIns] Bad aim message: " + ex.Message)); } } private static void SmartCupboardGuard(out Cup? cup, out SmartCupboard? cupboard) { cup = null; cupboard = null; SmartCupboard currentCupboard = CurrentCupboard; if (!((Object)(object)currentCupboard == (Object)null) && ((NetworkBehaviour)currentCupboard).IsServer && CurrentCup != null) { cupboard = currentCupboard; cup = CurrentCup; } } private static void ServerTick(SmartCupboard cupboard, Cup cup, float now) { StartOfRound instance = StartOfRound.Instance; if ((Object)(object)instance == (Object)null) { return; } bool flag = now >= cup.NextReconcile; if (flag) { cup.NextReconcile = now + 0.2f; PruneStaleAims(cup, now); } List<List<Data>> itemList = cupboard.memory.ItemList; int num = ((itemList.Count > 0) ? itemList[0].Count : 0); if (num <= 0) { return; } if (LoadCleanupPending && !LoadGraceActive) { LoadCleanupPending = false; RemoveLooseLoadDuplicates(cupboard); } for (int i = 0; i < itemList.Count; i++) { for (int j = 0; j < itemList[i].Count; j++) { int num2 = i * num + j; Data val = itemList[i][j]; bool flag2 = val.IsValid() && val.Quantity >= 1; if (cupboard.placedItems.TryGetValue(num2, out var value) && (Object)(object)value == (Object)null) { cupboard.placedItems.Remove(num2); } GrabbableObject item; bool flag3 = TryGetReal(cupboard, num2, out item); bool flag4 = false; if (flag2) { bool loadGraceActive = LoadGraceActive; bool flag5 = IsAimedAt(cup, num2, now) || (!loadGraceActive && (NeedsRealItem(val.Id) || WantsCalibrationLend(cupboard, cup, num2, val.Id, now) || KeepRealForSave(cup))); if (flag5 && !flag3) { TryMaterialize(cupboard, cup, num2, val, now); cup.NextReconcile = now; } else if (!flag5 && flag3 && (Object)(object)item != (Object)null && !loadGraceActive) { Dematerialize(cupboard, num2, item, hide: false); cup.RetryAfter.Remove(num2); flag3 = TryGetReal(cupboard, num2, out GrabbableObject _); flag4 = true; } if (flag3 && !loadGraceActive) { RemoveDuplicateRealItems(cupboard, num2); } if (flag3) { cup.RetryCount.Remove(num2); cup.RetryAfter.Remove(num2); if (!cup.RealSince.TryGetValue(num2, out var value2)) { cup.RealSince[num2] = now; } else if (now - value2 > 1f && (Object)(object)item != (Object)null && NeedsCalibration(cupboard, num2, val.Id)) { TryCalibrate(cupboard, cup, num2, val.Id, item); } } else { cup.RealSince.Remove(num2); } } if (flag || flag4) { PublishIfChanged(cup, num2, val, flag2, flag3); } } } } private static void Reconcile(SmartCupboard cupboard, Cup cup) { List<List<Data>> itemList = cupboard.memory.ItemList; int num = ((itemList.Count > 0) ? itemList[0].Count : 0); if (num <= 0) { return; } for (int i = 0; i < itemList.Count; i++) { for (int j = 0; j < itemList[i].Count; j++) { int slot = i * num + j; Data val = itemList[i][j]; bool valid = val.IsValid() && val.Quantity >= 1; GrabbableObject item; bool real = TryGetReal(cupboard, slot, out item); PublishIfChanged(cup, slot, val, valid, real); } } } private static void PublishIfChanged(Cup cup, int slot, Data data, bool valid, bool real) { SlotState slotState = (valid ? new SlotState(valid: true, data.Id, data.Quantity, real) : SlotState.Empty); if (!cup.LastSent.TryGetValue(slot, out var value)) { value = SlotState.Empty; } if (!slotState.Equals(value)) { cup.LastSent[slot] = slotState; cup.Desired[slot] = slotState; cup.DesiredDirty = true; BroadcastState(slot, slotState); } } private static void TryCalibrate(SmartCupboard cupboard, Cup cup, int slot, string id, GrabbableObject real) { //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: 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_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_025d: Unknown result type (might be due to invalid IL or missing references) //IL_0213: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Unknown result type (might be due to invalid IL or missing references) if (real.isHeld || real.isHeldByEnemy || real.heldByPlayerOnServer) { return; } Item itemProperties = real.itemProperties; if ((Object)(object)itemProperties == (Object)null || (itemProperties.itemSpawnsOnGround && real.fallTime < 1f) || (Object)(object)((Component)real).transform.parent != (Object)(object)cupboard.placePositions[slot] || IsTextModified(real) || !cup.StandIns.TryGetValue(slot, out StandIn value) || (Object)(object)value.Root == (Object)null) { return; } Transform transform = ((Component)real).transform; Transform transform2 = value.Root.transform; if (LastCalibrationSample.TryGetValue(slot, out (Quaternion, Vector3, Vector3) value2) && !(Quaternion.Angle(value2.Item1, transform.localRotation) > 0.05f) && !(Vector3.Distance(value2.Item2, transform.localPosition) > 0.0005f)) { Vector3 val = value2.Item3 - transform.localScale; if (!(((Vector3)(ref val)).sqrMagnitude > 1E-08f)) { LastCalibrationSample.Remove(slot); float num = Quaternion.Angle(transform.localRotation, transform2.localRotation); float num2 = Vector3.Distance(transform.localPosition, transform2.localPosition); float num3 = Mathf.Max(new float[3] { Mathf.Abs(transform.localScale.x - transform2.localScale.x), Mathf.Abs(transform.localScale.y - transform2.localScale.y), Mathf.Abs(transform.localScale.z - transform2.localScale.z) }); PartPose[] array = StandInVisual.CapturePartPoses(real); if (SelfSortingStoragePLUS.VerboseLogging.Value) { SelfSortingStoragePLUS.Logger.LogInfo((object)($"[StandIns] Measured '{id}' from a real item ({array.Length} meshes). The stand-in was off by " + $"{num:F1} degrees, position {num2:F3}, scale {num3:F3}. " + $"Real local euler {transform.localEulerAngles}, stand-in was {transform2.localEulerAngles}.")); } SetPoseOverride(PoseKey(slot, id), new PoseOverride(transform.localPosition, transform.localRotation, transform.localScale, RelativeToShip(cupboard.placePositions[slot].rotation), array), broadcast: true); return; } } LastCalibrationSample[slot] = (transform.localRotation, transform.localPosition, transform.localScale); } private static bool WantsCalibrationLend(SmartCupboard cupboard, Cup cup, int slot, string id, float now) { string item = PoseKey(slot, id); if (cup.CalibGaveUp.Contains(item) || !NeedsCalibration(cupboard, slot, id)) { cup.CalibStart.Remove(slot); return false; } if (!cup.CalibStart.TryGetValue(slot, out var value)) { cup.CalibStart[slot] = now; return true; } if (now - value > 8f) { cup.CalibGaveUp.Add(item); cup.CalibStart.Remove(slot); SelfSortingStoragePLUS.Logger.LogWarning((object)$"[StandIns] Could not measure '{id}' in slot {slot}; its stand-in uses the calculated pose."); return false; } return true; } private static bool NeedsCalibration(SmartCupboard cupboard, int slot, string id) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) if (slot < 0 || slot >= cupboard.placePositions.Length || (Object)(object)cupboard.placePositions[slot] == (Object)null) { return false; } PoseOverride pose; return !TryGetPoseOverride(slot, id, cupboard.placePositions[slot].rotation, out pose); } private static void HandleAim(ulong clientId, int slot) { SmartCupboardGuard(out Cup cup, out SmartCupboard cupboard); if (cup != null && !((Object)(object)cupboard == (Object)null)) { if (slot < 0 || slot >= cupboard.placePositions.Length) { cup.Aims.Remove(clientId); } else { cup.Aims[clientId] = new AimInfo(slot, Time.unscaledTime); } } } private static bool IsAimedAt(Cup cup, int slot, float now) { foreach (AimInfo value in cup.Aims.Values) { if (value.Slot == slot && now - value.SeenAt <= 3f) { return true; } } return false; } private static void PruneStaleAims(Cup cup, float now) { List<ulong> list = null; foreach (KeyValuePair<ulong, AimInfo> aim in cup.Aims) { if (now - aim.Value.SeenAt > 3f) { (list ?? (list = new List<ulong>())).Add(aim.Key); } } if (list == null) { return; } foreach (ulong item in list) { cup.Aims.Remove(item); } } private static bool TryGetReal(SmartCupboard cupboard, int slot, out GrabbableObject? item) { item = null; if (!cupboard.placedItems.TryGetValue(slot, out var value) || (Object)(object)value == (Object)null) { return false; } NetworkObject networkObject = ((NetworkBehaviour)value).NetworkObject; if ((Object)(object)networkObject == (Object)null || !networkObject.IsSpawned) { return false; } item = value; return true; } private static void TryMaterialize(SmartCupboard cupboard, Cup cup, int slot, Data data, float now) { if (cup.RetryAfter.TryGetValue(slot, out var value) && now < value) { return; } GrabbableObject val = FindOrphan(cupboard, slot, data); if ((Object)(object)val != (Object)null) { cupboard.placedItems[slot] = val; cup.RetryAfter[slot] = now + 1f; return; } int value2; int num = (cup.RetryCount.TryGetValue(slot, out value2) ? value2 : 0); cup.RetryCount[slot] = num + 1; cup.RetryAfter[slot] = now + ((num < 3) ? 1.5f : 20f); if (data.Values.Count == 0 || data.Saves.Count == 0 || data.States.Count == 0) { SelfSortingStoragePLUS.Logger.LogWarning((object)$"[StandIns] Slot {slot} ({data.Id}) has no per-item data; cannot lend out a real item."); return; } Materializing = true; try { SpawnItemMethod.Invoke(cupboard, new object[3] { data, slot, true }); } catch (Exception ex) { SelfSortingStoragePLUS.Logger.LogError((object)($"[StandIns] Could not lend out the real item for slot {slot} ({data.Id}): " + $"{(ex as TargetInvocationException)?.InnerException ?? ex}")); } finally { Materializing = false; } } private static void RemoveLooseLoadDuplicates(SmartCupboard cupboard) { //IL_00a1: 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_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result typ