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 ValeriusItemStandMenu v1.0.0
plugins/ValeriusItemStandMenu.dll
Decompiled 3 hours agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using HarmonyLib; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("ValeriusItemStandMenu")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+8bb51c4960bad29f18df612d3092cc1c88c1a0cf")] [assembly: AssemblyProduct("ValeriusItemStandMenu")] [assembly: AssemblyTitle("ValeriusItemStandMenu")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ItemStandMenu { internal static class SmoothBrainSailing { [ThreadStatic] internal static bool CreatingProxy; internal static void TryInstall(Harmony harmony) { //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Expected O, but got Unknown Type type = AccessTools.TypeByName("Sailing.Sailing+IncreaseHealth"); if (type == null) { return; } MethodInfo methodInfo = AccessTools.Method(type, "Prefix", new Type[1] { typeof(WearNTear) }, (Type[])null); MethodInfo methodInfo2 = AccessTools.Method(typeof(SmoothBrainSailing), "BeforeSailingPrefix", (Type[])null, (Type[])null); if (methodInfo == null || methodInfo2 == null) { Debug.LogWarning((object)"[Valerius Item Stand Menu] Sailing compatibility unavailable: IncreaseHealth signature changed."); return; } try { harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2) { priority = 800 }, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } catch (Exception ex) { Debug.LogWarning((object)("[Valerius Item Stand Menu] Sailing compatibility patch failed: " + ex)); } } private static bool BeforeSailingPrefix(WearNTear __0) { if (CreatingProxy) { return false; } if (Object.op_Implicit((Object)(object)__0)) { return !Object.op_Implicit((Object)(object)((Component)__0).GetComponent<ShortcutPiece>()); } return true; } } [HarmonyPatch(typeof(BuildUiPieceButton), "Setup")] internal static class OrientationBadge { private static readonly FieldInfo IconField = AccessTools.Field(typeof(BuildUiPieceButton), "m_icon"); private static readonly FieldInfo LanguageChangeField = AccessTools.Field(AccessTools.TypeByName("Localization"), "OnLanguageChange"); private static bool warnedOrientationLabels; private static void Prefix(BuildUiPieceButton __instance) { if (Object.op_Implicit((Object)(object)__instance) && !(LanguageChangeField == null) && LanguageChangeField.GetValue(null) is Action source) { LanguageChangeField.SetValue(null, (Action)Delegate.Remove(source, new Action(__instance.RefreshSearchTerm))); } } private static string GetOrientation(string name) { if (name == null) { return null; } if (name.EndsWith(" (Horizontal)", StringComparison.Ordinal)) { return "H"; } if (name.EndsWith(" (Vertical)", StringComparison.Ordinal)) { return "V"; } return null; } internal static void WarnOrientationLabels() { if (!warnedOrientationLabels) { warnedOrientationLabels = true; Debug.LogWarning((object)"[Valerius Item Stand Menu] Could not display orientation labels on Hammer menu icons."); } } internal static void Apply(BuildUiPieceButton button, Piece piece) { Postfix(button, piece); } private static void Postfix(BuildUiPieceButton __instance, Piece pieceInfo) { if (!Object.op_Implicit((Object)(object)__instance)) { return; } OrientationBadgeView orientationBadgeView = ((Component)__instance).GetComponent<OrientationBadgeView>(); if (!Object.op_Implicit((Object)(object)pieceInfo) || !Object.op_Implicit((Object)(object)((Component)pieceInfo).GetComponent<MenuChoice>())) { if (Object.op_Implicit((Object)(object)orientationBadgeView)) { orientationBadgeView.SetOrientation(null); } return; } string orientation = GetOrientation(pieceInfo.m_name); if (orientation == null) { if (Object.op_Implicit((Object)(object)orientationBadgeView)) { orientationBadgeView.SetOrientation(null); } return; } if (!Object.op_Implicit((Object)(object)orientationBadgeView)) { object? obj = IconField?.GetValue(__instance); Image val = (Image)((obj is Image) ? obj : null); if (!Object.op_Implicit((Object)(object)val)) { WarnOrientationLabels(); return; } orientationBadgeView = ((Component)__instance).gameObject.AddComponent<OrientationBadgeView>(); orientationBadgeView.Initialize(((Graphic)val).rectTransform); } orientationBadgeView.SetOrientation(orientation); } } internal sealed class OrientationBadgeView : MonoBehaviour { private static TMP_FontAsset cachedFont; private static Material outlinedMaterial; private TextMeshProUGUI label; internal void Initialize(RectTransform icon) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Expected O, but got Unknown //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_008e: 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_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Expected O, but got Unknown //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: 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_0105: 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_0110: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0144: 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_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Expected O, but got Unknown //IL_0219: Unknown result type (might be due to invalid IL or missing references) TMP_FontAsset val = FindGameFont(icon); if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)((TMP_Asset)val).material)) { OrientationBadge.WarnOrientationLabels(); return; } GameObject val2 = new GameObject("ItemStand_OrientationBadge", new Type[1] { typeof(RectTransform) }); val2.SetActive(false); RectTransform val3 = (RectTransform)val2.transform; ((Transform)val3).SetParent((Transform)(object)icon, false); val3.anchorMin = new Vector2(1f, 0f); val3.anchorMax = new Vector2(1f, 0f); val3.pivot = new Vector2(1f, 0f); val3.anchoredPosition = new Vector2(-2f, 2f); val3.sizeDelta = new Vector2(27f, 27f); ((Transform)val3).localScale = Vector3.one; ((Transform)val3).SetAsLastSibling(); GameObject val4 = new GameObject("Letter", new Type[1] { typeof(RectTransform) }); RectTransform val5 = (RectTransform)val4.transform; ((Transform)val5).SetParent((Transform)(object)val3, false); val5.anchorMin = Vector2.zero; val5.anchorMax = Vector2.one; val5.offsetMin = new Vector2(0.5f, 0f); val5.offsetMax = new Vector2(-0.5f, 0f); ((Transform)val5).localScale = Vector3.one; label = val4.AddComponent<TextMeshProUGUI>(); ((TMP_Text)label).font = val; ((Graphic)label).raycastTarget = false; ((TMP_Text)label).alignment = (TextAlignmentOptions)514; ((TMP_Text)label).fontSize = 25f; ((TMP_Text)label).fontStyle = (FontStyles)1; ((TMP_Text)label).enableWordWrapping = false; ((Graphic)label).color = Color32.op_Implicit(new Color32(byte.MaxValue, (byte)202, (byte)96, byte.MaxValue)); if (!Object.op_Implicit((Object)(object)outlinedMaterial)) { outlinedMaterial = new Material(((TMP_Asset)val).material); ((Object)outlinedMaterial).name = "ItemStand_BadgeOutline"; if (outlinedMaterial.HasProperty(ShaderUtilities.ID_OutlineColor)) { outlinedMaterial.SetColor(ShaderUtilities.ID_OutlineColor, Color.black); } if (outlinedMaterial.HasProperty(ShaderUtilities.ID_OutlineWidth)) { outlinedMaterial.SetFloat(ShaderUtilities.ID_OutlineWidth, 0.2f); } if (outlinedMaterial.HasProperty(ShaderUtilities.ID_FaceDilate)) { outlinedMaterial.SetFloat(ShaderUtilities.ID_FaceDilate, 0.12f); } } ((TMP_Text)label).fontSharedMaterial = outlinedMaterial; } private static TMP_FontAsset FindGameFont(RectTransform icon) { if (Object.op_Implicit((Object)(object)cachedFont) && Object.op_Implicit((Object)(object)((TMP_Asset)cachedFont).material)) { return cachedFont; } BuildUi componentInParent = ((Component)icon).GetComponentInParent<BuildUi>(); TextMeshProUGUI[] componentsInChildren; if (Object.op_Implicit((Object)(object)componentInParent)) { componentsInChildren = ((Component)componentInParent).GetComponentsInChildren<TextMeshProUGUI>(true); foreach (TextMeshProUGUI val in componentsInChildren) { if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)((TMP_Text)val).font) && Object.op_Implicit((Object)(object)((TMP_Asset)((TMP_Text)val).font).material)) { return cachedFont = ((TMP_Text)val).font; } } } componentsInChildren = Resources.FindObjectsOfTypeAll<TextMeshProUGUI>(); foreach (TextMeshProUGUI val2 in componentsInChildren) { if (Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)((TMP_Text)val2).font) && Object.op_Implicit((Object)(object)((TMP_Asset)((TMP_Text)val2).font).material)) { return cachedFont = ((TMP_Text)val2).font; } } TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>(); foreach (TMP_FontAsset val3 in array) { if (Object.op_Implicit((Object)(object)val3) && Object.op_Implicit((Object)(object)((TMP_Asset)val3).material)) { return cachedFont = val3; } } return null; } internal void SetOrientation(string orientation) { if (Object.op_Implicit((Object)(object)label)) { ((TMP_Text)label).text = orientation ?? string.Empty; ((Component)((TMP_Text)label).transform.parent).gameObject.SetActive(orientation != null); } } } internal static class ProgressiveBuildMenu { private static readonly List<BuildUiPieceButton> cachedAllButtons = new List<BuildUiPieceButton>(); private static PieceTable cachedAllTool; private static int cachedAllFingerprint; private static bool hasCachedAll; private static int lastRenderedList = -1; private static int lastRenderedTag = int.MinValue; private static PieceTable lastRenderedTool; private static string lastRenderedSearch = ""; private static readonly FieldInfo ScrollField = AccessTools.Field(typeof(BuildUi), "m_pieceScrollRect"); private static readonly FieldInfo SearchField = AccessTools.Field(typeof(BuildUi), "m_searchField"); private static readonly FieldInfo TagField = AccessTools.Field(typeof(BuildUi), "m_currentTagId"); private static readonly FieldInfo TabField = AccessTools.Field(typeof(BuildUi), "m_currentPieceList"); private static readonly FieldInfo ButtonsField = AccessTools.Field(typeof(BuildUi), "m_pieceButtons"); private static readonly FieldInfo ContainerField = AccessTools.Field(typeof(BuildUi), "m_pieceButtonsContainer"); private static readonly FieldInfo ButtonPrefabField = AccessTools.Field(typeof(BuildUi), "m_pieceButtonPrefab"); private static readonly PropertyInfo ButtonPiece = AccessTools.Property(typeof(BuildUiPieceButton), "Piece"); private static readonly FieldInfo ButtonIcon = AccessTools.Field(typeof(BuildUiPieceButton), "m_icon"); private static readonly FieldInfo ButtonUpgrade = AccessTools.Field(typeof(BuildUiPieceButton), "m_upgradeArrow"); private static readonly FieldInfo ButtonFavorite = AccessTools.Field(typeof(BuildUiPieceButton), "m_favoriteStar"); private static readonly FieldInfo ButtonOwner = AccessTools.Field(typeof(BuildUiPieceButton), "m_buildUi"); private static readonly MethodInfo RefreshMethod = AccessTools.Method(typeof(BuildUi), "UpdatePieceButtons", (Type[])null, (Type[])null); private static readonly MethodInfo ConfigureNavigationMethod = AccessTools.Method(typeof(BuildUi), "ConfigureButtonNavigation", (Type[])null, (Type[])null); private static readonly FieldInfo ToolField = AccessTools.Field(typeof(BuildUi), "m_currentBuildTool"); private static readonly FieldInfo NativePoolField = AccessTools.Field(typeof(BuildUi), "m_pieceButtonPool"); private static BuildUi ui; private static ScrollRect scroll; private static RectTransform content; private static GridLayoutGroup grid; private static ContentSizeFitter fitter; private static bool originalGridEnabled; private static bool originalFitterEnabled; private static Vector2 originalContentSize; private static readonly List<BuildUiPieceButton> buttons = new List<BuildUiPieceButton>(); private static readonly List<int> boundIndex = new List<int>(); private static bool virtualMode; private static bool rebuilding; private static bool binding; private static int columns = 1; private static int capacity; private static int cachedRows; private static int cachedColumns; private static float rowStep; private static float colStep; private static float totalHeight; private static string lastSearch = ""; private static string savedStandSearch = ""; private static float savedStandScroll = 1f; private static bool restoringStandScroll; private static int Fingerprint(PieceTable table) { if (!Object.op_Implicit((Object)(object)table)) { return 0; } int num = 17; foreach (Piece availablePiece in table.m_availablePieces) { num = num * 31 + (Object.op_Implicit((Object)(object)availablePiece) ? ((Object)availablePiece).GetInstanceID() : 0); } return num; } private static void ReleaseShowAllCache() { if (!hasCachedAll) { return; } Stack<BuildUiPieceButton> stack = ((Object.op_Implicit((Object)(object)ui) && NativePoolField != null) ? (NativePoolField.GetValue(ui) as Stack<BuildUiPieceButton>) : null); foreach (BuildUiPieceButton cachedAllButton in cachedAllButtons) { if (Object.op_Implicit((Object)(object)cachedAllButton)) { ((Component)cachedAllButton).gameObject.SetActive(false); stack?.Push(cachedAllButton); } } cachedAllButtons.Clear(); cachedAllTool = null; hasCachedAll = false; } private static void SaveShowAllBeforeEnteringStands(BuildUi buildUi) { if (hasCachedAll || lastRenderedList != 0 || lastRenderedTag != -1 || lastRenderedSearch.Length != 0 || !string.IsNullOrEmpty(Search(buildUi))) { return; } PieceTable val = Tool(buildUi); List<BuildUiPieceButton> list = ButtonsField?.GetValue(buildUi) as List<BuildUiPieceButton>; if (!Object.op_Implicit((Object)(object)val) || (Object)(object)val != (Object)(object)lastRenderedTool || list == null || list.Count == 0) { return; } cachedAllTool = val; cachedAllFingerprint = Fingerprint(val); cachedAllButtons.AddRange(list); list.Clear(); foreach (BuildUiPieceButton cachedAllButton in cachedAllButtons) { if (Object.op_Implicit((Object)(object)cachedAllButton)) { ((Component)cachedAllButton).gameObject.SetActive(false); } } hasCachedAll = true; } private static bool RestoreShowAllWithoutRebuild(BuildUi buildUi) { if (!hasCachedAll || !ShowAllTag(buildUi) || Search(buildUi).Length != 0 || (Object)(object)Tool(buildUi) != (Object)(object)cachedAllTool || Fingerprint(cachedAllTool) != cachedAllFingerprint) { return false; } List<BuildUiPieceButton> list = ButtonsField?.GetValue(buildUi) as List<BuildUiPieceButton>; Stack<BuildUiPieceButton> stack = NativePoolField?.GetValue(buildUi) as Stack<BuildUiPieceButton>; if (list == null || stack == null) { return false; } foreach (BuildUiPieceButton item in list) { if (Object.op_Implicit((Object)(object)item)) { ((Component)item).gameObject.SetActive(false); stack.Push(item); } } list.Clear(); list.AddRange(cachedAllButtons); cachedAllButtons.Clear(); cachedAllTool = null; hasCachedAll = false; foreach (BuildUiPieceButton item2 in list) { if (Object.op_Implicit((Object)(object)item2)) { ((Component)item2).gameObject.SetActive(true); } } ConfigureNavigationMethod?.Invoke(buildUi, null); return true; } private static int Tag(BuildUi buildUi) { if (!((Object)(object)buildUi != (Object)null) || !(TagField != null)) { return -1; } return (int)TagField.GetValue(buildUi); } private static bool StandTag(BuildUi buildUi) { if (Object.op_Implicit((Object)(object)buildUi) && TabField != null && (int)TabField.GetValue(buildUi) == 0) { return ItemStandUsageTab.IsStandTagForAny(Tag(buildUi)); } return false; } private static bool ShowAllTag(BuildUi buildUi) { if (Object.op_Implicit((Object)(object)buildUi) && TabField != null && (int)TabField.GetValue(buildUi) == 0) { return Tag(buildUi) == -1; } return false; } private static PieceTable Tool(BuildUi buildUi) { if (!Object.op_Implicit((Object)(object)buildUi) || !(ToolField != null)) { return null; } object? value = ToolField.GetValue(buildUi); return (PieceTable)((value is PieceTable) ? value : null); } private static string Search(BuildUi buildUi) { object obj = ((Object.op_Implicit((Object)(object)buildUi) && SearchField != null) ? SearchField.GetValue(buildUi) : null); if (obj != null) { return ((obj.GetType().GetProperty("text")?.GetValue(obj, null) as string) ?? "").Trim(); } return ""; } internal static void Attach(BuildUi buildUi) { if (!Object.op_Implicit((Object)(object)buildUi) || ScrollField == null) { return; } object? value = ScrollField.GetValue(buildUi); ScrollRect val = (ScrollRect)((value is ScrollRect) ? value : null); if (Object.op_Implicit((Object)(object)val) && (!((Object)(object)ui == (Object)(object)buildUi) || !((Object)(object)scroll == (Object)(object)val))) { if (Object.op_Implicit((Object)(object)scroll)) { ((UnityEvent<Vector2>)(object)scroll.onValueChanged).RemoveListener((UnityAction<Vector2>)OnScroll); } Restore(); ReleaseShowAllCache(); lastRenderedList = -1; lastRenderedTag = int.MinValue; lastRenderedTool = null; ui = buildUi; scroll = val; ((UnityEvent<Vector2>)(object)scroll.onValueChanged).AddListener((UnityAction<Vector2>)OnScroll); } } internal static bool BeforeNativeRebuild(BuildUi buildUi) { rebuilding = true; if ((Object)(object)buildUi != (Object)(object)ui) { Attach(buildUi); } bool num = StandTag(buildUi); if (num) { SaveShowAllBeforeEnteringStands(buildUi); } if (virtualMode) { Restore(); } if (!num) { if (RestoreShowAllWithoutRebuild(buildUi)) { return false; } ReleaseShowAllCache(); return true; } lastSearch = Search(buildUi); if (!string.Equals(lastSearch, savedStandSearch, StringComparison.OrdinalIgnoreCase)) { savedStandSearch = lastSearch; savedStandScroll = 1f; } Plugin.Instance?.SetSearch(lastSearch); return true; } internal static void AfterNativeRebuild(BuildUi buildUi) { rebuilding = false; if (StandTag(buildUi)) { Activate(); } else if (Object.op_Implicit((Object)(object)buildUi) && !(TabField == null)) { lastRenderedList = (int)TabField.GetValue(buildUi); lastRenderedTag = Tag(buildUi); lastRenderedTool = Tool(buildUi); lastRenderedSearch = Search(buildUi); } } private static void Activate() { //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_022a: Unknown result type (might be due to invalid IL or missing references) //IL_0323: Unknown result type (might be due to invalid IL or missing references) //IL_0328: Unknown result type (might be due to invalid IL or missing references) if (virtualMode || !Object.op_Implicit((Object)(object)ui) || !Object.op_Implicit((Object)(object)scroll) || (Object)(object)Plugin.Instance == (Object)null || ContainerField == null || ButtonsField == null || ButtonPrefabField == null) { return; } object? value = ContainerField.GetValue(ui); content = (RectTransform)((value is RectTransform) ? value : null); grid = (Object.op_Implicit((Object)(object)content) ? ((Component)content).GetComponent<GridLayoutGroup>() : null); List<BuildUiPieceButton> list = ButtonsField.GetValue(ui) as List<BuildUiPieceButton>; object? value2 = ButtonPrefabField.GetValue(ui); GameObject val = (GameObject)((value2 is GameObject) ? value2 : null); if (!Object.op_Implicit((Object)(object)content) || !Object.op_Implicit((Object)(object)grid) || list == null || !Object.op_Implicit((Object)(object)val) || ButtonPiece == null || ButtonIcon == null || ButtonOwner == null) { return; } Rect rect; float width; if (!Object.op_Implicit((Object)(object)scroll.viewport)) { rect = content.rect; width = ((Rect)(ref rect)).width; } else { rect = scroll.viewport.rect; width = ((Rect)(ref rect)).width; } float num = width; float height; if (!Object.op_Implicit((Object)(object)scroll.viewport)) { rect = content.rect; height = ((Rect)(ref rect)).height; } else { rect = scroll.viewport.rect; height = ((Rect)(ref rect)).height; } float num2 = height; colStep = Mathf.Max(1f, grid.cellSize.x + grid.spacing.x); rowStep = Mathf.Max(1f, grid.cellSize.y + grid.spacing.y); columns = Mathf.Max(1, Mathf.FloorToInt((num - (float)((LayoutGroup)grid).padding.left - (float)((LayoutGroup)grid).padding.right + grid.spacing.x) / colStep)); int num3 = Mathf.Max(1, Mathf.CeilToInt(Mathf.Max(num2, grid.cellSize.y) / rowStep)); capacity = (num3 + 2) * columns; cachedRows = num3; cachedColumns = columns; if (capacity <= 0 || capacity > 512) { return; } Plugin.Instance.EnsureMenuPool(capacity); while (list.Count < capacity) { BuildUiPieceButton component = Object.Instantiate<GameObject>(val, (Transform)(object)content).GetComponent<BuildUiPieceButton>(); if (!Object.op_Implicit((Object)(object)component)) { return; } list.Add(component); ((Component)component).gameObject.SetActive(false); } buttons.Clear(); boundIndex.Clear(); for (int i = 0; i < capacity; i++) { buttons.Add(list[i]); boundIndex.Add(-1); } originalGridEnabled = ((Behaviour)grid).enabled; originalContentSize = content.sizeDelta; fitter = ((Component)content).GetComponent<ContentSizeFitter>(); originalFitterEnabled = Object.op_Implicit((Object)(object)fitter) && ((Behaviour)fitter).enabled; if (Object.op_Implicit((Object)(object)fitter)) { ((Behaviour)fitter).enabled = false; } ((Behaviour)grid).enabled = false; virtualMode = true; restoringStandScroll = true; try { UpdateHeight(); scroll.verticalNormalizedPosition = savedStandScroll; } finally { restoringStandScroll = false; } Bind(CurrentScrollRow()); } private static void UpdateHeight() { //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)content) && Object.op_Implicit((Object)(object)grid) && Object.op_Implicit((Object)(object)scroll) && !((Object)(object)Plugin.Instance == (Object)null)) { int num = Mathf.CeilToInt((float)Plugin.Instance.MatchCount / (float)columns); totalHeight = (float)(((LayoutGroup)grid).padding.top + ((LayoutGroup)grid).padding.bottom) + ((num > 0) ? ((float)num * rowStep - grid.spacing.y) : 0f); RectTransform obj = content; float num2 = totalHeight; float num3; if (!Object.op_Implicit((Object)(object)scroll.viewport)) { num3 = grid.cellSize.y; } else { Rect rect = scroll.viewport.rect; num3 = ((Rect)(ref rect)).height; } obj.SetSizeWithCurrentAnchors((Axis)1, Mathf.Max(num2, num3)); } } private static void Bind(int scrollRow) { //IL_011d: 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) //IL_01b9: 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_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Unknown result type (might be due to invalid IL or missing references) if (!virtualMode || binding || (Object)(object)Plugin.Instance == (Object)null) { return; } int num = Mathf.Max(0, scrollRow - 1) * columns; binding = true; try { for (int i = num; i < num + capacity; i++) { int num2 = i % capacity; BuildUiPieceButton val = buttons[num2]; if (!Object.op_Implicit((Object)(object)val)) { continue; } if (i >= Plugin.Instance.MatchCount) { if (((Component)val).gameObject.activeSelf) { ((Component)val).gameObject.SetActive(false); } boundIndex[num2] = -1; continue; } if (boundIndex[num2] != i) { Piece val2 = Plugin.Instance.BindVisibleSlot(num2, i); if (!Object.op_Implicit((Object)(object)val2)) { ((Component)val).gameObject.SetActive(false); boundIndex[num2] = -1; continue; } ButtonPiece.SetValue(val, val2, null); ButtonOwner.SetValue(val, ui); object? value = ButtonIcon.GetValue(val); Image val3 = (Image)((value is Image) ? value : null); if (Object.op_Implicit((Object)(object)val3)) { val3.sprite = val2.m_icon; ((Graphic)val3).color = Color.white; } object? obj = ButtonUpgrade?.GetValue(val); Image val4 = (Image)((obj is Image) ? obj : null); if (Object.op_Implicit((Object)(object)val4)) { ((Component)val4).gameObject.SetActive(false); } object? obj2 = ButtonFavorite?.GetValue(val); Image val5 = (Image)((obj2 is Image) ? obj2 : null); if (Object.op_Implicit((Object)(object)val5)) { ((Component)val5).gameObject.SetActive(false); } OrientationBadge.Apply(val, val2); Transform transform = ((Component)val).transform; RectTransform val6 = (RectTransform)(object)((transform is RectTransform) ? transform : null); if (Object.op_Implicit((Object)(object)val6)) { Vector2 anchorMin = (val6.anchorMax = new Vector2(0f, 1f)); val6.anchorMin = anchorMin; val6.pivot = new Vector2(0f, 1f); val6.sizeDelta = grid.cellSize; val6.anchoredPosition = new Vector2((float)((LayoutGroup)grid).padding.left + (float)(i % columns) * colStep, (float)(-((LayoutGroup)grid).padding.top) - (float)(i / columns) * rowStep); } boundIndex[num2] = i; } if (!((Component)val).gameObject.activeSelf) { ((Component)val).gameObject.SetActive(true); } } } finally { binding = false; } } private static int CurrentScrollRow() { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) float num; Rect rect; if (!Object.op_Implicit((Object)(object)scroll.viewport)) { num = 0f; } else { rect = scroll.viewport.rect; num = ((Rect)(ref rect)).height; } float num2 = num; rect = content.rect; return Mathf.FloorToInt(Mathf.Max(0f, (((Rect)(ref rect)).height - num2) * (1f - scroll.verticalNormalizedPosition)) / rowStep); } private static void OnScroll(Vector2 _) { if (virtualMode && !rebuilding && !binding && !restoringStandScroll && Object.op_Implicit((Object)(object)ui) && Object.op_Implicit((Object)(object)scroll) && StandTag(ui)) { savedStandScroll = Mathf.Clamp01(scroll.verticalNormalizedPosition); Bind(CurrentScrollRow()); } } private static void Restore() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) if (virtualMode) { virtualMode = false; if (Object.op_Implicit((Object)(object)content)) { content.sizeDelta = originalContentSize; } if (Object.op_Implicit((Object)(object)grid)) { ((Behaviour)grid).enabled = originalGridEnabled; } if (Object.op_Implicit((Object)(object)fitter)) { ((Behaviour)fitter).enabled = originalFitterEnabled; } buttons.Clear(); boundIndex.Clear(); } } internal static void Tick() { //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_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_009e: 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_00ee: 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) if (virtualMode && Object.op_Implicit((Object)(object)ui) && !StandTag(ui)) { Restore(); } if (virtualMode && Object.op_Implicit((Object)(object)ui) && Object.op_Implicit((Object)(object)scroll) && !rebuilding) { Rect rect; float width; if (!Object.op_Implicit((Object)(object)scroll.viewport)) { rect = content.rect; width = ((Rect)(ref rect)).width; } else { rect = scroll.viewport.rect; width = ((Rect)(ref rect)).width; } float num = width; float height; if (!Object.op_Implicit((Object)(object)scroll.viewport)) { rect = content.rect; height = ((Rect)(ref rect)).height; } else { rect = scroll.viewport.rect; height = ((Rect)(ref rect)).height; } float num2 = height; int num3 = Mathf.Max(1, Mathf.FloorToInt((num - (float)((LayoutGroup)grid).padding.left - (float)((LayoutGroup)grid).padding.right + grid.spacing.x) / colStep)); int num4 = Mathf.Max(1, Mathf.CeilToInt(Mathf.Max(num2, grid.cellSize.y) / rowStep)); if (num3 != cachedColumns || num4 != cachedRows) { RefreshMethod?.Invoke(ui, null); } } } internal static bool SearchChanged(BuildUi buildUi, string term) { if (!Object.op_Implicit((Object)(object)buildUi) || binding || !StandTag(buildUi)) { return true; } if (rebuilding) { return false; } term = (term ?? "").Trim(); if (string.Equals(term, lastSearch, StringComparison.OrdinalIgnoreCase)) { return false; } lastSearch = term; savedStandSearch = term; savedStandScroll = 1f; Plugin.Instance?.SetSearch(term); if (virtualMode) { restoringStandScroll = true; try { UpdateHeight(); for (int i = 0; i < boundIndex.Count; i++) { boundIndex[i] = -1; } scroll.verticalNormalizedPosition = 1f; } finally { restoringStandScroll = false; } Bind(0); } else { RefreshMethod?.Invoke(buildUi, null); } return false; } internal static void Filter(ByUsagePieceList usage, PieceTable table, int tagId, IList<Piece> results) { if (results == null) { return; } for (int num = results.Count - 1; num >= 0; num--) { Piece val = results[num]; if (Object.op_Implicit((Object)(object)val) && ((Object)((Component)val).gameObject).name.StartsWith("ItemStandMenu_Proxy", StringComparison.Ordinal)) { results.RemoveAt(num); } } Plugin.Instance?.AppendChoices(table, tagId, usage, results); } } [BepInPlugin("valerius.itemstandmenu", "ValeriusItemStandMenu", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { internal sealed class Entry { internal string ItemName; internal string Label; internal Sprite Icon; internal bool Horizontal; internal SearchIndex.Record SearchKey; internal string Description; internal Requirement[] DisplayRequirements; } internal const string PiecePrefix = "ItemStandMenu_Proxy"; internal const int BatchSize = 1; private Harmony harmony; private PieceTable table; private Piece horizontal; private Piece vertical; private readonly List<Entry> catalogue = new List<Entry>(); private readonly List<Entry> matches = new List<Entry>(); private readonly List<Piece> menuPool = new List<Piece>(); private string search = string.Empty; private int shown; private int windowStart; private bool building; private int lastDatabaseCount = -1; private Piece selectedDisplayPiece; private Piece selectedPlacementProxy; public const string PluginGuid = "valerius.itemstandmenu"; public const string PluginName = "ValeriusItemStandMenu"; public const string PluginVersion = "1.0.0"; internal static Plugin Instance { get; private set; } internal int MatchCount => matches.Count; internal int LoadedCount => shown; internal int WindowStart => windowStart; internal bool HasCatalogue { get { if (Object.op_Implicit((Object)(object)table) && Object.op_Implicit((Object)(object)horizontal) && Object.op_Implicit((Object)(object)vertical)) { return catalogue.Count > 0; } return false; } } private void Register() { //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_014d: 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) if (!Object.op_Implicit((Object)(object)ObjectDB.instance) || building || (HasCatalogue && lastDatabaseCount == ObjectDB.instance.m_items.Count)) { return; } PieceTable pieceTable = PieceManager.Instance.GetPieceTable("Hammer"); GameObject prefab = PrefabManager.Instance.GetPrefab("itemstandh"); GameObject prefab2 = PrefabManager.Instance.GetPrefab("itemstand"); if (!Object.op_Implicit((Object)(object)pieceTable) || !Object.op_Implicit((Object)(object)prefab) || !Object.op_Implicit((Object)(object)prefab2)) { return; } building = true; try { if (Object.op_Implicit((Object)(object)table) && (Object)(object)table != (Object)(object)pieceTable) { if (Object.op_Implicit((Object)(object)horizontal)) { table.m_pieces.Remove(((Component)horizontal).gameObject); Object.Destroy((Object)(object)((Component)horizontal).gameObject); } if (Object.op_Implicit((Object)(object)vertical)) { table.m_pieces.Remove(((Component)vertical).gameObject); Object.Destroy((Object)(object)((Component)vertical).gameObject); } horizontal = null; vertical = null; } table = pieceTable; PieceCategory category = PieceManager.Instance.AddPieceCategory("Item Stands"); if (!Object.op_Implicit((Object)(object)horizontal)) { horizontal = CreateProxy(prefab, isHorizontal: true, category); } if (!Object.op_Implicit((Object)(object)vertical)) { vertical = CreateProxy(prefab2, isHorizontal: false, category); } if (!Object.op_Implicit((Object)(object)horizontal) || !Object.op_Implicit((Object)(object)vertical)) { return; } if (!table.m_pieces.Contains(((Component)horizontal).gameObject)) { table.m_pieces.Add(((Component)horizontal).gameObject); } if (!table.m_pieces.Contains(((Component)vertical).gameObject)) { table.m_pieces.Add(((Component)vertical).gameObject); } Dictionary<string, GameObject> dictionary = new Dictionary<string, GameObject>(StringComparer.Ordinal); foreach (GameObject item in ObjectDB.instance.m_items) { if (Object.op_Implicit((Object)(object)item) && Object.op_Implicit((Object)(object)item.GetComponent<ItemDrop>()) && !((Object)item).name.EndsWith("(Clone)", StringComparison.Ordinal)) { dictionary[((Object)item).name] = item; } } ItemDrop[] array = Resources.FindObjectsOfTypeAll<ItemDrop>(); foreach (ItemDrop val in array) { if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)((Component)val).gameObject) || ((Object)((Component)val).gameObject).name.EndsWith("(Clone)", StringComparison.Ordinal)) { continue; } string name = ((Object)((Component)val).gameObject).name; if (!dictionary.ContainsKey(name)) { GameObject prefab3 = PrefabManager.Instance.GetPrefab(name); if (Object.op_Implicit((Object)(object)prefab3) && Object.op_Implicit((Object)(object)prefab3.GetComponent<ItemDrop>())) { dictionary[name] = prefab3; } } } Dictionary<string, string> modOrigins = SearchIndex.GetModOrigins(); List<string> list = new List<string>(dictionary.Keys); list.Sort(StringComparer.OrdinalIgnoreCase); catalogue.Clear(); foreach (string item2 in list) { ItemDrop component = dictionary[item2].GetComponent<ItemDrop>(); if (!Object.op_Implicit((Object)(object)component) || component.m_itemData == null || !Attachment.HasModel(dictionary[item2])) { continue; } Sprite icon = component.m_itemData.GetIcon(); if (Object.op_Implicit((Object)(object)icon)) { string text = component.m_itemData.m_shared?.m_name; string text2 = (string.IsNullOrEmpty(text) ? item2 : LocalizationManager.Instance.TryTranslate(text)); if (string.IsNullOrEmpty(text2)) { text2 = item2; } string description = component.m_itemData.m_shared?.m_description ?? string.Empty; modOrigins.TryGetValue(item2, out var value); AddEntry(item2, text2, icon, description, component, horizontalSide: true, SearchIndex.Build(text2, item2, value, component, horizontal: true)); AddEntry(item2, text2, icon, description, component, horizontalSide: false, SearchIndex.Build(text2, item2, value, component, horizontal: false)); } } RebuildMatches(); SetLoadedCount(1); lastDatabaseCount = ObjectDB.instance.m_items.Count; } finally { building = false; } } private void AddEntry(string name, string label, Sprite icon, string description, ItemDrop attachment, bool horizontalSide, SearchIndex.Record searchable) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0044: 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_0053: Expected O, but got Unknown Requirement[] array = StandPieceFor(horizontalSide)?.m_resources ?? Array.Empty<Requirement>(); Requirement[] array2 = (Requirement[])(object)new Requirement[array.Length + 1]; Array.Copy(array, array2, array.Length); array2[array.Length] = new Requirement { m_resItem = attachment, m_amount = 1, m_recover = false }; catalogue.Add(new Entry { ItemName = name, Label = label, Icon = icon, Horizontal = horizontalSide, Description = description, DisplayRequirements = array2, SearchKey = searchable }); } private void RebuildMatches() { matches.Clear(); string[] array = SearchIndex.Terms(search); if (array.Length == 0) { matches.AddRange(catalogue); return; } List<KeyValuePair<Entry, int>> list = new List<KeyValuePair<Entry, int>>(); foreach (Entry item in catalogue) { int num = SearchIndex.Score(item.SearchKey, array); if (num >= 0) { list.Add(new KeyValuePair<Entry, int>(item, num)); } } foreach (KeyValuePair<Entry, int> item2 in list.OrderByDescending((KeyValuePair<Entry, int> pair) => pair.Value)) { matches.Add(item2.Key); } } internal bool SetSearch(string value) { value = (value ?? string.Empty).Trim(); if (string.Equals(search, value, StringComparison.OrdinalIgnoreCase)) { return false; } search = value; RebuildMatches(); SetLoadedCount(1); return true; } internal void EnsureMenuPool(int count) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown //IL_0019: Unknown result type (might be due to invalid IL or missing references) while (menuPool.Count < count) { GameObject val = new GameObject("ItemStand_MenuIcon"); val.SetActive(false); Object.DontDestroyOnLoad((Object)val); Piece item = val.AddComponent<Piece>(); val.AddComponent<MenuChoice>(); menuPool.Add(item); } } internal Piece BindVisibleSlot(int slot, int absolute) { //IL_0089: Unknown result type (might be due to invalid IL or missing references) if (slot < 0 || absolute < 0 || absolute >= matches.Count) { return null; } EnsureMenuPool(slot + 1); Entry entry = matches[absolute]; Piece obj = menuPool[slot]; obj.m_name = entry.Label + (entry.Horizontal ? " (Horizontal)" : " (Vertical)"); obj.m_description = entry.Description; obj.m_icon = entry.Icon; obj.m_resources = entry.DisplayRequirements; obj.m_usage = (UsageTagFlags)512; obj.m_craftingStation = StandPieceFor(entry.Horizontal)?.m_craftingStation; MenuChoice component = ((Component)obj).GetComponent<MenuChoice>(); component.ItemName = entry.ItemName; component.Horizontal = entry.Horizontal; return obj; } private void SetLoadedCount(int requested) { EnsureMenuPool(1); shown = Mathf.Min(1, matches.Count); windowStart = 0; if (shown != 0) { BindVisibleSlot(0, 0); } } internal void AppendChoices(PieceTable source, int tagId, ByUsagePieceList usageList, IList<Piece> pieces) { if (!((Object)(object)source != (Object)(object)table) && Object.op_Implicit((Object)(object)horizontal) && Object.op_Implicit((Object)(object)vertical) && ItemStandUsageTab.IsStandTag(usageList, tagId) && (source.m_availablePieces.Contains(horizontal) || source.m_availablePieces.Contains(vertical))) { for (int i = 0; i < shown; i++) { pieces.Add(menuPool[i]); } } } internal bool TryGetSelectedDisplayPiece(Piece requested, out Piece display) { display = null; if (!Object.op_Implicit((Object)(object)requested) || (Object)(object)requested != (Object)(object)selectedPlacementProxy || !Object.op_Implicit((Object)(object)selectedDisplayPiece)) { return false; } display = selectedDisplayPiece; return true; } private void Update() { ProgressiveBuildMenu.Tick(); } internal Piece StandPieceFor(bool h) { if (!h) { Piece obj = vertical; if (obj == null) { return null; } return ((Component)obj).GetComponent<ShortcutPiece>()?.StandPiece; } Piece obj2 = horizontal; if (obj2 == null) { return null; } return ((Component)obj2).GetComponent<ShortcutPiece>()?.StandPiece; } internal Piece VisiblePiece(int index) { if (index < 0 || index >= shown) { return null; } return menuPool[index]; } internal bool IsCatalogueTable(PieceTable candidate) { if (HasCatalogue) { return (Object)(object)candidate == (Object)(object)table; } return false; } private void Awake() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown Instance = this; ModQuery.Enable(); harmony = new Harmony("valerius.itemstandmenu"); harmony.PatchAll(typeof(Plugin).Assembly); SmoothBrainSailing.TryInstall(harmony); PieceManager.OnPiecesRegistered += Register; ItemManager.OnItemsRegisteredFejd += Register; } private void OnDestroy() { PieceManager.OnPiecesRegistered -= Register; ItemManager.OnItemsRegisteredFejd -= Register; Harmony obj = harmony; if (obj != null) { obj.UnpatchSelf(); } if (Object.op_Implicit((Object)(object)table)) { if (Object.op_Implicit((Object)(object)horizontal)) { table.m_pieces.Remove(((Component)horizontal).gameObject); } if (Object.op_Implicit((Object)(object)vertical)) { table.m_pieces.Remove(((Component)vertical).gameObject); } } if (Object.op_Implicit((Object)(object)selectedDisplayPiece)) { Object.Destroy((Object)(object)((Component)selectedDisplayPiece).gameObject); } selectedDisplayPiece = null; selectedPlacementProxy = null; foreach (Piece item in menuPool) { if (Object.op_Implicit((Object)(object)item)) { Object.Destroy((Object)(object)((Component)item).gameObject); } } if (Object.op_Implicit((Object)(object)horizontal)) { Object.Destroy((Object)(object)((Component)horizontal).gameObject); } if (Object.op_Implicit((Object)(object)vertical)) { Object.Destroy((Object)(object)((Component)vertical).gameObject); } Instance = null; } private static Piece CreateProxy(GameObject original, bool isHorizontal, PieceCategory category) { //IL_0066: 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_00b6: 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) bool forceDisableInit = ZNetView.m_forceDisableInit; GameObject val; try { SmoothBrainSailing.CreatingProxy = true; ZNetView.m_forceDisableInit = true; val = Object.Instantiate<GameObject>(original); } finally { ZNetView.m_forceDisableInit = forceDisableInit; SmoothBrainSailing.CreatingProxy = false; } if (!Object.op_Implicit((Object)(object)val)) { return null; } ((Object)val).name = "ItemStandMenu_Proxy" + (isHorizontal ? "Horizontal" : "Vertical"); val.transform.position = new Vector3(0f, -10000f, 0f); val.SetActive(false); Object.DontDestroyOnLoad((Object)(object)val); Piece component = val.GetComponent<Piece>(); if (!Object.op_Implicit((Object)(object)component)) { Object.Destroy((Object)(object)val); return null; } component.m_name = (isHorizontal ? "Item Stand (Horizontal)" : "Item Stand (Vertical)"); component.m_description = "Place a normal item stand with the selected item attached."; component.m_category = category; component.m_usage = (UsageTagFlags)512; ShortcutPiece shortcutPiece = val.AddComponent<ShortcutPiece>(); shortcutPiece.StandPrefabName = ((Object)original).name; shortcutPiece.StandPiece = original.GetComponent<Piece>(); if (isHorizontal) { PlacementGhost.AddDirectionArrow(val); } return component; } internal bool SelectChoice(Player player, MenuChoice choice) { //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Expected O, but got Unknown if (!Object.op_Implicit((Object)(object)player) || !Object.op_Implicit((Object)(object)choice)) { return false; } Piece val = (choice.Horizontal ? horizontal : vertical); if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)table) || !table.IsPieceAvailable(val)) { return false; } Piece selectedPiece = player.GetSelectedPiece(); ((Component)val).GetComponent<ShortcutPiece>().ItemPrefabName = choice.ItemName; if (!player.SetSelectedPiece(val)) { return false; } selectedPlacementProxy = val; if (!Object.op_Implicit((Object)(object)selectedDisplayPiece)) { GameObject val2 = new GameObject("ItemStand_SelectedDisplay"); val2.SetActive(false); Object.DontDestroyOnLoad((Object)(object)val2); selectedDisplayPiece = val2.AddComponent<Piece>(); } Piece component = ((Component)choice).GetComponent<Piece>(); selectedDisplayPiece.m_name = component.m_name; selectedDisplayPiece.m_description = component.m_description; selectedDisplayPiece.m_icon = component.m_icon; selectedDisplayPiece.m_resources = component.m_resources; selectedDisplayPiece.m_usage = component.m_usage; selectedDisplayPiece.m_craftingStation = component.m_craftingStation; if ((Object)(object)selectedPiece == (Object)(object)val) { AccessTools.Method(typeof(Player), "SetupPlacementGhost", (Type[])null, (Type[])null)?.Invoke(player, null); } return true; } } [HarmonyPatch(typeof(ByUsagePieceList), "UpdateAvailableTags")] [HarmonyPriority(0)] internal static class StandTabAvailability { private static void Postfix(ByUsagePieceList __instance, PieceTable pieceTable) { ItemStandUsageTab.Updated(__instance, pieceTable); } } [HarmonyPatch(typeof(ByUsagePieceList), "GetAvailablePiecesWithTag")] [HarmonyPriority(0)] internal static class BuildMenuFilter { private static void Postfix(ByUsagePieceList __instance, int tagId, PieceTable pieceTable, IList<Piece> resultOut) { ProgressiveBuildMenu.Filter(__instance, pieceTable, tagId, resultOut); } } [HarmonyPatch(typeof(BuildUi), "OpenBuildMenu")] internal static class BuildMenuScrollSetup { private static void Postfix(BuildUi __instance) { ProgressiveBuildMenu.Attach(__instance); } } [HarmonyPatch(typeof(BuildUi), "UpdateSearch")] internal static class BuildMenuSearchRefresh { private static bool Prefix(BuildUi __instance, string term) { return ProgressiveBuildMenu.SearchChanged(__instance, term); } } [HarmonyPatch(typeof(BuildUi), "UpdatePieceButtons")] internal static class BuildButtonVirtualization { private static bool Prefix(BuildUi __instance) { return ProgressiveBuildMenu.BeforeNativeRebuild(__instance); } private static void Postfix(BuildUi __instance) { ProgressiveBuildMenu.AfterNativeRebuild(__instance); } } [HarmonyPatch(typeof(ByMaterialPieceList), "GetAvailablePiecesWithTag")] internal static class MaterialsFilter { private static void Postfix(IList<Piece> resultOut) { for (int num = resultOut.Count - 1; num >= 0; num--) { if (Object.op_Implicit((Object)(object)resultOut[num]) && ((Object)((Component)resultOut[num]).gameObject).name.StartsWith("ItemStandMenu_Proxy", StringComparison.Ordinal)) { resultOut.RemoveAt(num); } } } } [HarmonyPatch(typeof(BuildUi), "OnSelectPiece")] internal static class ChoiceSelection { private static bool Prefix(Piece piece) { MenuChoice menuChoice = (Object.op_Implicit((Object)(object)piece) ? ((Component)piece).GetComponent<MenuChoice>() : null); if (!Object.op_Implicit((Object)(object)menuChoice)) { return true; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)Plugin.Instance == (Object)null || !Plugin.Instance.SelectChoice(localPlayer, menuChoice)) { Debug.LogWarning((object)("[Valerius Item Stand Menu] Could not select " + menuChoice.ItemName + " from the Hammer menu.")); return false; } if (!ZInput.IsTouchActive() || ZInput.HasDoubleTapped()) { localPlayer.PlayButtonSound(); Hud.CloseBuildUi(); } return false; } } [HarmonyPatch(typeof(Player), "IsPieceAvailable")] internal static class CatalogueHoverAvailability { private static void Postfix(Piece piece, ref bool __result) { if (!__result && Object.op_Implicit((Object)(object)piece) && Object.op_Implicit((Object)(object)((Component)piece).GetComponent<MenuChoice>()) && (Object)(object)Plugin.Instance != (Object)null) { __result = true; } } } [HarmonyPatch(typeof(Hud), "SetupPieceInfo")] internal static class CatalogueDetailPanel { private static void Prefix(ref Piece piece) { if ((Object)(object)Plugin.Instance != (Object)null && Plugin.Instance.TryGetSelectedDisplayPiece(piece, out var display)) { piece = display; } } } internal static class ItemStandUsageTab { private const string CategoryToken = "$jotunn_cat_item_stands"; private static readonly Dictionary<ByUsagePieceList, int> TagIds = new Dictionary<ByUsagePieceList, int>(); internal static void Updated(ByUsagePieceList usage, PieceTable table) { if (usage == null) { return; } TagIds.Remove(usage); if ((Object)(object)Plugin.Instance == (Object)null || !Plugin.Instance.IsCatalogueTable(table)) { return; } for (int i = 0; i < usage.TagCount; i++) { if (!(usage.GetTagDisplayName(i) != "$jotunn_cat_item_stands")) { TagIds[usage] = usage.GetTagIdByIndex(i); break; } } } internal static bool IsStandTagForAny(int tagId) { foreach (KeyValuePair<ByUsagePieceList, int> tagId2 in TagIds) { if (tagId2.Key != null && tagId2.Value == tagId) { return true; } } return false; } internal static bool IsStandTag(ByUsagePieceList usage, int tagId) { if (usage != null && TagIds.TryGetValue(usage, out var value)) { return value == tagId; } return false; } } internal static class SearchIndex { internal sealed class Record { internal string Name; internal string Prefab; internal string Mod; internal string Category; internal string Orientation; } internal static Dictionary<string, string> GetModOrigins() { Dictionary<string, string> dictionary = new Dictionary<string, string>(StringComparer.Ordinal); foreach (IModPrefab prefab in ModQuery.GetPrefabs()) { if (!((Object)(object)((prefab != null) ? prefab.Prefab : null) == (Object)null) && prefab.SourceMod != null) { string name = ((Object)prefab.Prefab).name; string name2 = prefab.SourceMod.Name; if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(name2)) { dictionary[name] = name2; } } } return dictionary; } internal static Record Build(string label, string prefab, string mod, ItemDrop item, bool horizontal) { List<string> list = new List<string>(); SharedData val = item.m_itemData?.m_shared; if (val != null) { string text = ((object)Unsafe.As<ItemType, ItemType>(ref val.m_itemType)/*cast due to .constrained prefix*/).ToString(); list.Add(text); if (text.Contains("Weapon") || text == "Bow" || text == "Attach_Atgeir") { list.Add("weapon weapons"); string text2 = ((object)Unsafe.As<SkillType, SkillType>(ref val.m_skillType)/*cast due to .constrained prefix*/).ToString(); if (text2 != "None") { list.Add(text2); } } switch (text) { case "Helmet": case "Chest": case "Legs": case "Hands": case "Shoulder": list.Add("armor armour equipment"); break; } if (text == "Material") { list.Add("material materials"); } if (text == "Consumable") { list.Add("consumable consumables food"); } } return new Record { Name = Normalize(label), Prefab = Normalize(prefab), Mod = Normalize(mod), Category = Normalize(string.Join(" ", list.ToArray())), Orientation = (horizontal ? "horizontal" : "vertical") }; } internal static string[] Terms(string query) { return (query ?? string.Empty).ToLowerInvariant().Split(new char[4] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); } internal static int Score(Record record, string[] terms) { if (record == null) { return -1; } if (terms.Length == 0) { return 0; } int num = 0; for (int i = 0; i < terms.Length; i++) { string text = Normalize(terms[i]); if (text.Length != 0) { int num2 = -1; if (record.Name == text) { num2 = 100; } else if (record.Name.StartsWith(text, StringComparison.Ordinal)) { num2 = 75; } else if (record.Name.Contains(text)) { num2 = 60; } if (record.Prefab == text) { num2 = Math.Max(num2, 55); } else if (record.Prefab.Contains(text)) { num2 = Math.Max(num2, 40); } if (record.Category.Contains(text)) { num2 = Math.Max(num2, 30); } if (record.Mod.Contains(text)) { num2 = Math.Max(num2, 25); } if (record.Orientation.Contains(text)) { num2 = Math.Max(num2, 10); } if (num2 < 0) { return -1; } num += num2; } } return num; } private static string Normalize(string text) { return (text ?? string.Empty).ToLowerInvariant().Replace("_", "").Replace("-", "") .Replace(" ", ""); } } internal static class Attachment { private static bool providerWarningLogged; private static bool modelWarningLogged; private static readonly MethodInfo ExternalGetAttach = AccessTools.Method(AccessTools.TypeByName("ItemStandAllItems.Attacher"), "GetAttach", new Type[1] { typeof(GameObject) }, (Type[])null); internal static GameObject GetPrefab(GameObject item) { if (!Object.op_Implicit((Object)(object)item)) { return null; } GameObject attachPrefab = ItemStand.GetAttachPrefab(item); if (Object.op_Implicit((Object)(object)attachPrefab) || ExternalGetAttach == null) { return attachPrefab; } try { object? obj = ExternalGetAttach.Invoke(null, new object[1] { item }); return (GameObject)((obj is GameObject) ? obj : null); } catch (Exception ex) { if (!providerWarningLogged) { providerWarningLogged = true; Debug.LogWarning((object)("[Valerius Item Stand Menu] Attachment provider failed: " + ex.GetBaseException().Message)); } return null; } } internal static bool HasModel(GameObject item) { try { GameObject prefab = GetPrefab(item); if (!Object.op_Implicit((Object)(object)prefab)) { return false; } GameObject attachGameObject = ItemStand.GetAttachGameObject(prefab); return Object.op_Implicit((Object)(object)attachGameObject) && (Object)(object)attachGameObject.GetComponentInChildren<Renderer>(true) != (Object)null; } catch (Exception ex) { if (!modelWarningLogged) { modelWarningLogged = true; Debug.LogWarning((object)("[Valerius Item Stand Menu] Attachment model inspection failed: " + ex.GetBaseException().Message)); } return false; } } } [HarmonyPatch(typeof(Player), "PlacePiece")] internal static class ShortcutPlaceStand { private static void Prefix(Player __instance, ref Piece piece, out ShortcutPlacement.Pending __state) { __state = null; if (ShortcutPlacement.IsShortcut(piece, out var shortcut)) { __state = new ShortcutPlacement.Pending { ItemName = shortcut.ItemPrefabName, StandName = shortcut.StandPrefabName, FreeBuild = ShortcutPlacement.IsFreeBuild(__instance, piece) }; ShortcutPlacement.Current = __state; piece = shortcut.StandPiece; } } private static void Postfix(Player __instance, ShortcutPlacement.Pending __state) { if (__state != null) { ShortcutPlacement.Current = null; if (Object.op_Implicit((Object)(object)__state.Spawned)) { ((MonoBehaviour)__instance).StartCoroutine(AttachAfterMaterials(__instance, __state)); } else { AttachmentError(__state.ItemName); } } } private static void AttachmentError(string item) { Debug.LogError((object)("[Valerius Item Stand Menu] Could not attach " + item + " to the item stand.")); } private static IEnumerator AttachAfterMaterials(Player player, ShortcutPlacement.Pending state) { yield return null; if (!Object.op_Implicit((Object)(object)player) || !Object.op_Implicit((Object)(object)state.Spawned) || !Object.op_Implicit((Object)(object)ObjectDB.instance)) { yield break; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(state.ItemName); ItemDrop val = (Object.op_Implicit((Object)(object)itemPrefab) ? itemPrefab.GetComponent<ItemDrop>() : null); if (!Object.op_Implicit((Object)(object)val)) { yield break; } if (state.FreeBuild) { ZNetView component = ((Component)state.Spawned).GetComponent<ZNetView>(); if (!Object.op_Implicit((Object)(object)component) || !component.IsValid() || !component.IsOwner()) { AttachmentError(state.ItemName); yield break; } ItemData val2 = val.m_itemData.Clone(); val2.m_stack = 1; val2.m_dropPrefab = itemPrefab; int stableHashCode = StringExtensionMethods.GetStableHashCode(((Object)itemPrefab).name); ZDO zDO = component.GetZDO(); zDO.Set(ZDOVars.s_item, stableHashCode, false); ItemDrop.SaveToZDO(val2, zDO, -1); component.InvokeRPC(ZNetView.Everybody, "SetVisualItem", new object[4] { stableHashCode, val2.m_variant, val2.m_quality, 0 }); } else { ItemData val3 = ShortcutPlacement.FindInventoryItem(player, state.ItemName); if (val3 != null) { state.Spawned.UseItem((Humanoid)(object)player, val3); } } } } [HarmonyPatch(typeof(Player), "SetupPlacementGhost")] internal static class PlacementGhost { private static readonly FieldInfo GhostField = AccessTools.Field(typeof(Player), "m_placementGhost"); private static readonly HashSet<string> Warnings = new HashSet<string>(); private static Material directionMaterial; private const float ArrowThickness = 0.02f; private static readonly Vector3[] ArrowFootprint = (Vector3[])(object)new Vector3[7] { new Vector3(-0.014f, 0f, -0.09f), new Vector3(0.014f, 0f, -0.09f), new Vector3(-0.014f, 0f, 0.03f), new Vector3(0.014f, 0f, 0.03f), new Vector3(-0.058f, 0f, 0.03f), new Vector3(0.058f, 0f, 0.03f), new Vector3(0f, 0f, 0.09f) }; private static readonly int[] ArrowTopFaces = new int[15] { 0, 1, 2, 1, 3, 2, 4, 2, 6, 2, 3, 6, 3, 5, 6 }; private static readonly int[] ArrowPerimeter = new int[7] { 0, 1, 3, 5, 6, 4, 2 }; private static void Prefix(Player __instance, out GameObject __state) { __state = null; Piece selectedPiece = __instance.GetSelectedPiece(); if (Object.op_Implicit((Object)(object)selectedPiece) && Object.op_Implicit((Object)(object)((Component)selectedPiece).GetComponent<ShortcutPiece>())) { GameObject gameObject = ((Component)selectedPiece).gameObject; if (!gameObject.activeSelf) { __state = gameObject; gameObject.SetActive(true); } } } private static void Postfix(Player __instance, GameObject __state) { //IL_01c4: 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_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_0246: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Unknown result type (might be due to invalid IL or missing references) //IL_0264: 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_0270: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_028d: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)__state)) { __state.SetActive(false); } if (GhostField == null) { return; } object? value = GhostField.GetValue(__instance); GameObject val = (GameObject)((value is GameObject) ? value : null); if (!Object.op_Implicit((Object)(object)val)) { return; } Piece selectedPiece = __instance.GetSelectedPiece(); ShortcutPiece shortcutPiece = (Object.op_Implicit((Object)(object)selectedPiece) ? ((Component)selectedPiece).GetComponent<ShortcutPiece>() : null); if (!Object.op_Implicit((Object)(object)shortcutPiece) || string.IsNullOrEmpty(shortcutPiece.ItemPrefabName) || Object.op_Implicit((Object)(object)val.transform.Find("ItemStand_ItemPreview")) || Object.op_Implicit((Object)(object)val.GetComponentInChildren<PlacementPreviewMarker>(true))) { return; } ItemStand component = val.GetComponent<ItemStand>(); if (!Object.op_Implicit((Object)(object)component)) { return; } GameObject val2 = (Object.op_Implicit((Object)(object)ObjectDB.instance) ? ObjectDB.instance.GetItemPrefab(shortcutPiece.ItemPrefabName) : null); ItemDrop val3 = (Object.op_Implicit((Object)(object)val2) ? val2.GetComponent<ItemDrop>() : null); if (!Object.op_Implicit((Object)(object)val3) || val3.m_itemData == null) { WarnOnce(shortcutPiece.ItemPrefabName, "model", "Could not find 3D model for " + shortcutPiece.ItemPrefabName + "."); return; } try { GameObject prefab = Attachment.GetPrefab(val2); if (!Object.op_Implicit((Object)(object)prefab)) { WarnOnce(shortcutPiece.ItemPrefabName, "model", "Could not find 3D model for " + shortcutPiece.ItemPrefabName + "."); return; } GameObject attachGameObject = ItemStand.GetAttachGameObject(prefab); Transform attach = component.GetAttach(val3.m_itemData); if (!Object.op_Implicit((Object)(object)attachGameObject) || !Object.op_Implicit((Object)(object)attach)) { WarnOnce(shortcutPiece.ItemPrefabName, "preview", "Could not preview " + shortcutPiece.ItemPrefabName + " on the item stand."); return; } GameObject val4 = Object.Instantiate<GameObject>(attachGameObject, attach, false); ((Object)val4).name = "ItemStand_ItemPreview"; val4.transform.localPosition = prefab.transform.localPosition; val4.transform.localRotation = prefab.transform.localRotation; val4.transform.localScale = Vector3.Scale(prefab.transform.localScale, val3.m_itemData.GetScale(1f)); List<OrientationSettings> list = new List<OrientationSettings>(); component.GetOrientationSettings(val3.m_itemData, ref list); if (list.Count > 0) { OrientationSettings val5 = list[0]; Transform transform = val4.transform; transform.localPosition += val5.m_position; Transform transform2 = val4.transform; transform2.localRotation *= Quaternion.Euler(val5.m_rotation); val4.transform.localScale = Vector3.Scale(val4.transform.localScale, val5.m_scale); } MonoBehaviour[] componentsInChildren = val4.GetComponentsInChildren<MonoBehaviour>(true); for (int i = 0; i < componentsInChildren.Length; i++) { ((Behaviour)componentsInChildren[i]).enabled = false; } Collider[] componentsInChildren2 = val4.GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { componentsInChildren2[i].enabled = false; } Rigidbody[] componentsInChildren3 = val4.GetComponentsInChildren<Rigidbody>(true); for (int i = 0; i < componentsInChildren3.Length; i++) { componentsInChildren3[i].isKinematic = true; } val4.SetActive(true); bool flag = false; Renderer[] componentsInChildren4 = val4.GetComponentsInChildren<Renderer>(true); foreach (Renderer val6 in componentsInChildren4) { if (Object.op_Implicit((Object)(object)val6) && val6.enabled && ((Component)val6).gameObject.activeInHierarchy) { flag = true; break; } } if (!flag) { Object.Destroy((Object)(object)val4); WarnOnce(shortcutPiece.ItemPrefabName, "preview", "Could not preview " + shortcutPiece.ItemPrefabName + " on the item stand."); } else { val4.AddComponent<PlacementPreviewMarker>(); } } catch (Exception exception) { WarnOnce(shortcutPiece.ItemPrefabName, "preview", "Could not preview " + shortcutPiece.ItemPrefabName + " on the item stand.", exception); } } internal static void AddDirectionArrow(GameObject proxy) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown //IL_0052: 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_007f: 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_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_00aa: 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_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Expected O, but got Unknown //IL_0241: Unknown result type (might be due to invalid IL or missing references) //IL_0246: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_0266: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Expected O, but got Unknown if (!Object.op_Implicit((Object)(object)proxy) || Object.op_Implicit((Object)(object)proxy.transform.Find("ItemStand_DirectionPreview"))) { return; } GameObject val = new GameObject("ItemStand_DirectionPreview"); val.transform.SetParent(proxy.transform, false); val.transform.localPosition = new Vector3(0f, 0.035f, 0f); Vector3[] array = (Vector3[])(object)new Vector3[ArrowFootprint.Length * 2]; for (int i = 0; i < ArrowFootprint.Length; i++) { array[i] = ArrowFootprint[i] + Vector3.up * 0.02f; array[i + ArrowFootprint.Length] = ArrowFootprint[i]; } List<int> list = new List<int>(ArrowTopFaces.Length * 2 + ArrowPerimeter.Length * 6); list.AddRange(ArrowTopFaces); for (int j = 0; j < ArrowTopFaces.Length; j += 3) { list.Add(ArrowTopFaces[j] + ArrowFootprint.Length); list.Add(ArrowTopFaces[j + 2] + ArrowFootprint.Length); list.Add(ArrowTopFaces[j + 1] + ArrowFootprint.Length); } for (int k = 0; k < ArrowPerimeter.Length; k++) { int num = ArrowPerimeter[k]; int num2 = ArrowPerimeter[(k + 1) % ArrowPerimeter.Length]; list.Add(num); list.Add(num + ArrowFootprint.Length); list.Add(num2); list.Add(num2); list.Add(num + ArrowFootprint.Length); list.Add(num2 + ArrowFootprint.Length); } Mesh val2 = new Mesh { name = "ItemStand_DirectionArrow" }; val2.vertices = array; val2.triangles = list.ToArray(); val2.RecalculateNormals(); val.AddComponent<MeshFilter>().sharedMesh = val2; MeshRenderer val3 = val.AddComponent<MeshRenderer>(); if (!Object.op_Implicit((Object)(object)directionMaterial)) { Shader val4 = Shader.Find("Sprites/Default") ?? Shader.Find("Unlit/Transparent"); if (!Object.op_Implicit((Object)(object)val4)) { Object.Destroy((Object)(object)val); Debug.LogWarning((object)"[Valerius Item Stand Menu] Transparent arrow shader unavailable."); return; } directionMaterial = new Material(val4) { name = "ItemStand_ArrowMaterial", color = new Color(0.16f, 0.65f, 1f, 0.26f) }; } ((Renderer)val3).sharedMaterial = directionMaterial; } private static void WarnOnce(string item, string category, string message, Exception exception = null) { if (Warnings.Add(item + ":" + category)) { Debug.LogWarning((object)("[Valerius Item Stand Menu] " + message)); if (exception != null) { Debug.LogException(exception); } } } } internal sealed class PlacementPreviewMarker : MonoBehaviour { } [HarmonyPatch(typeof(WearNTear), "Awake")] internal static class ShortcutGhostWear { private static bool Prefix(WearNTear __instance) { return !Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<ShortcutPiece>()); } } [HarmonyPatch(typeof(ItemStand), "Awake")] internal static class ShortcutCaptureStand { private static bool Prefix(ItemStand __instance) { return !Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<ShortcutPiece>()); } private static void Postfix(ItemStand __instance) { ShortcutPlacement.Pending current = ShortcutPlacement.Current; if (current != null && !Object.op_Implicit((Object)(object)current.Spawned) && Object.op_Implicit((Object)(object)__instance) && ((Object)((Component)__instance).gameObject).name == current.StandName + "(Clone)") { current.Spawned = __instance; } } } internal sealed class ShortcutPiece : MonoBehaviour { internal string ItemPrefabName; internal string StandPrefabName; internal Piece StandPiece; } internal static class ShortcutPlacement { internal sealed class Pending { internal string ItemName; internal string StandName; internal ItemStand Spawned; internal bool FreeBuild; } internal static Pending Current; internal static bool IsFreeBuild(Player player, Piece piece) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)player)) { if (!player.PlacementCostDisabled) { if (Object.op_Implicit((Object)(object)ZoneSystem.instance)) { return ZoneSystem.instance.GetGlobalKey(piece.FreeBuildKey()); } return false; } return true; } return false; } internal static bool IsShortcut(Piece piece, out ShortcutPiece shortcut) { shortcut = (Object.op_Implicit((Object)(object)piece) ? ((Component)piece).GetComponent<ShortcutPiece>() : null); return Object.op_Implicit((Object)(object)shortcut); } internal static ItemData FindInventoryItem(Player player, string prefabName) { foreach (ItemData allItem in ((Humanoid)player).GetInventory().GetAllItems()) { if (allItem != null && Object.op_Implicit((Object)(object)allItem.m_dropPrefab) && ((Object)allItem.m_dropPrefab).name == prefabName && allItem.m_stack > 0) { return allItem; } } return null; } internal static bool HasItemPlusMaterials(Player player, Piece piece, ShortcutPiece shortcut) { return HasItemPlusMaterials(player, shortcut.ItemPrefabName, shortcut.StandPiece); } internal static bool HasItemPlusMaterials(Player player, string itemPrefabName, Piece standPiece) { if (!Object.op_Implicit((Object)(object)player) || !Object.op_Implicit((Object)(object)standPiece) || string.IsNullOrEmpty(itemPrefabName)) { return false; } GameObject val = (Object.op_Implicit((Object)(object)ObjectDB.instance) ? ObjectDB.instance.GetItemPrefab(itemPrefabName) : null); ItemDrop val2 = (Object.op_Implicit((Object)(object)val) ? val.GetComponent<ItemDrop>() : null); if (!Object.op_Implicit((Object)(object)val2) || val2.m_itemData?.m_shared == null) { return false; } string name = val2.m_itemData.m_shared.m_name; int num = 1; Requirement[] resources = standPiece.m_resources; foreach (Requirement val3 in resources) { if (Object.op_Implicit((Object)(object)val3.m_resItem) && val3.m_resItem.m_itemData.m_shared.m_name == name) { num += val3.GetAmount(0); } } if (FindInventoryItem(player, itemPrefabName) != null) { return ((Humanoid)player).GetInventory().CountItems(name, -1, true) >= num; } return false; } } [HarmonyPatch(typeof(PieceTable), "UpdateAvailable")] internal static class ShortcutRecipeVisibility { private static void Prefix(PieceTable __instance, HashSet<string> knownRecipies, out List<string> __state) { __state = new List<string>(); foreach (GameObject piece in __instance.m_pieces) { ShortcutPiece shortcutPiece = (Object.op_Implicit((Object)(object)piece) ? piece.GetComponent<ShortcutPiece>() : null); if (Object.op_Implicit((Object)(object)shortcutPiece) && Object.op_Implicit((Object)(object)shortcutPiece.StandPiece)) { Piece component = piece.GetComponent<Piece>(); if (knownRecipies.Contains(shortcutPiece.StandPiece.m_name) && knownRecipies.Add(component.m_name)) { __state.Add(component.m_name); } } } } private static void Postfix(HashSet<string> knownRecipies, List<string> __state) { if (__state == null) { return; } foreach (string item in __state) { knownRecipies.Remove(item); } } } [HarmonyPatch(typeof(Player), "HaveRequirements", new Type[] { typeof(Piece), typeof(RequirementMode) })] internal static class ShortcutRequirements { private static void Postfix(Player __instance, Piece piece, RequirementMode mode, ref bool __result) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Invalid comparison between Unknown and I4 MenuChoice menuChoice = (Object.op_Implicit((Object)(object)piece) ? ((Component)piece).GetComponent<MenuChoice>() : null); ShortcutPiece shortcut; bool flag = ShortcutPlacement.IsShortcut(piece, out shortcut); if (!flag && !Object.op_Implicit((Object)(object)menuChoice)) { return; } if ((int)mode == 0 && ShortcutPlacement.IsFreeBuild(__instance, piece)) { __result = true; } else if (__result && ((int)mode == 0 || (int)mode == 2)) { if (flag) { __result = ShortcutPlacement.HasItemPlusMaterials(__instance, piece, shortcut); } else { __result = ShortcutPlacement.HasItemPlusMaterials(__instance, menuChoice.ItemName, Plugin.Instance?.StandPieceFor(menuChoice.Horizontal)); } } } } [HarmonyPatch(typeof(Player), "ConsumeResources")] internal static class ShortcutResourceConsumption { private static void Prefix(Player __instance, ref Requirement[] requirements) { Piece selectedPiece = __instance.GetSelectedPiece(); if (ShortcutPlacement.IsShortcut(selectedPiece, out var shortcut) && requirements == selectedPiece.m_resources) { requirements = (ShortcutPlacement.IsFreeBuild(__instance, selectedPiece) ? Array.Empty<Requirement>() : shortcut.StandPiece.m_resources); } } } internal sealed class MenuChoice : MonoBehaviour { internal string ItemName; internal bool Horizontal; } }