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 BetterBuildMenu v0.2.0
BetterBuildMenu.dll
Decompiled 2 days 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.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using GUIFramework; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("assembly_guiutils")] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("BetterBuildMenu")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.2.0.0")] [assembly: AssemblyInformationalVersion("0.2.0+f2e6f785a2c3681624be2817abd53d960b7e19e8")] [assembly: AssemblyProduct("BetterBuildMenu")] [assembly: AssemblyTitle("BetterBuildMenu")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.2.0.0")] [module: UnverifiableCode] [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 BetterBuildMenu { internal static class Buildable { public const int TagId = -100; private const string ObjectName = "BetterBuildMenu_Buildable"; private const string Label = "Buildable"; private const float CheckInterval = 0.5f; private static BuildUiTagButton _button; private static int? _lastState; private static float _nextCheck; public static bool Selected(BuildUi ui) { if ((Object)(object)_button != (Object)null) { return ui.m_currentTagId == -100; } return false; } public static void Ensure(BuildUi ui) { if ((Object)(object)ui == (Object)null) { return; } if (!Plugin.BuildableCategory.Value) { if (!((Object)(object)_button == (Object)null)) { bool num = Selected(ui); Destroy(); if (num && ((Behaviour)ui).isActiveAndEnabled) { ui.OnSelectTag(-1); } } } else if (!((Object)(object)_button != (Object)null)) { BuildUiTagButton showAllTagsButton = ui.m_showAllTagsButton; GameObject obj = Object.Instantiate<GameObject>(((Component)showAllTagsButton).gameObject, ((Component)showAllTagsButton).transform.parent, false); ((Object)obj).name = "BetterBuildMenu_Buildable"; obj.transform.SetSiblingIndex(((Component)showAllTagsButton).transform.GetSiblingIndex()); _button = obj.GetComponent<BuildUiTagButton>(); _button.Setup("Buildable", -100, false); _button.SetToggled(ui.m_currentTagId == -100); _button.Hover += ui.OnHoverTag; _button.Selected += ui.OnSelectTag; _button.NavigatedTo += ui.OnNavigatedToTag; if (((Behaviour)ui).isActiveAndEnabled) { ui.ConfigureButtonNavigation(); } } } public static void Destroy() { if ((Object)(object)_button != (Object)null) { Object.Destroy((Object)(object)((Component)_button).gameObject); } _button = null; _lastState = null; } public static bool TryGetButton(int tagId, out BuildUiTagButton button) { button = ((tagId == -100) ? _button : null); return (Object)(object)button != (Object)null; } public static void Filter(IList<Piece> pieces) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { return; } for (int num = pieces.Count - 1; num >= 0; num--) { Piece val = pieces[num]; if (!val.m_repairPiece && !val.m_removePiece && !HasMaterials(localPlayer, val)) { pieces.RemoveAt(num); } } } public static void Update(BuildUi ui) { if (!Selected(ui) || (Object)(object)ui.m_currentBuildTool == (Object)null) { _lastState = null; } else { if (Time.unscaledTime < _nextCheck) { return; } _nextCheck = Time.unscaledTime + 0.5f; Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { return; } int num = 17; foreach (Piece availablePiece in ui.m_currentBuildTool.m_availablePieces) { num = num * 31 + (HasMaterials(localPlayer, availablePiece) ? 1 : 0); } bool num2 = _lastState.HasValue && _lastState.Value != num; _lastState = num; if (num2) { ui.UpdatePieceButtons(); } } } private static bool HasMaterials(Player player, Piece piece) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) if (player.NoCostCheat() || ZoneSystem.instance.GetGlobalKey(piece.FreeBuildKey())) { return true; } Inventory inventory = ((Humanoid)player).GetInventory(); Requirement[] resources = piece.m_resources; foreach (Requirement val in resources) { if (!((Object)(object)val.m_resItem == (Object)null) && val.m_amount > 0 && inventory.CountItems(val.m_resItem.m_itemData.m_shared.m_name, -1, true) < val.m_amount) { return false; } } return true; } } [HarmonyPatch(typeof(BuildUi), "TryGetTagButtonById")] internal static class BuildUiTryGetTagButtonByIdPatch { private static bool Prefix(int tagId, ref BuildUiTagButton button, ref bool __result) { if (!Buildable.TryGetButton(tagId, out var button2)) { return true; } button = button2; __result = true; return false; } } [HarmonyPatch] internal static class PieceListGetAvailablePiecesWithTagPatch { private static IEnumerable<MethodBase> TargetMethods() { yield return AccessTools.Method(typeof(ByUsagePieceList), "GetAvailablePiecesWithTag", (Type[])null, (Type[])null); yield return AccessTools.Method(typeof(ByMaterialPieceList), "GetAvailablePiecesWithTag", (Type[])null, (Type[])null); yield return AccessTools.Method(typeof(FavoritePieceList), "GetAvailablePiecesWithTag", (Type[])null, (Type[])null); } private static void Prefix(ref int tagId, out bool __state) { __state = tagId == -100; if (__state) { tagId = -1; } } private static void Postfix(IList<Piece> resultOut, bool __state) { if (__state) { Buildable.Filter(resultOut); } } } [HarmonyPatch(typeof(BuildUi), "PlaceSeparator")] internal static class BuildUiPlaceSeparatorPatch { private static void Postfix(BuildUi __instance) { RectTransform materialSeparator = __instance.m_materialSeparator; if (((Component)materialSeparator).gameObject.activeSelf && Buildable.TryGetButton(-100, out var button) && ((Component)button).gameObject.activeSelf && !((Object)(object)((Component)button).transform.parent != (Object)(object)((Transform)materialSeparator).parent)) { ((Transform)materialSeparator).SetSiblingIndex(((Transform)materialSeparator).GetSiblingIndex() + 1); } } } internal static class ClickOutside { private static UIInputHandler _backdrop; private static bool _warned; public static void Ensure(BuildUi ui) { if ((Object)(object)_backdrop != (Object)null) { return; } Transform obj = ((Component)ui).transform.Find("CloseButton"); _backdrop = ((obj != null) ? ((Component)obj).GetComponent<UIInputHandler>() : null); if ((Object)(object)_backdrop == (Object)null) { if (!_warned) { Plugin.Log.LogWarning((object)"Click outside to close: couldn't find the build menu's backdrop"); } _warned = true; } else { UIInputHandler backdrop = _backdrop; backdrop.m_onLeftClick = (Action<UIInputHandler>)Delegate.Combine(backdrop.m_onLeftClick, new Action<UIInputHandler>(OnClick)); } } public static void Destroy() { if ((Object)(object)_backdrop != (Object)null) { UIInputHandler backdrop = _backdrop; backdrop.m_onLeftClick = (Action<UIInputHandler>)Delegate.Remove(backdrop.m_onLeftClick, new Action<UIInputHandler>(OnClick)); } _backdrop = null; } private static void OnClick(UIInputHandler _) { PlayerController.SetTakeInputDelay(0.2f); Hud.HidePieceSelection(); } } internal static class CloseIcon { private const int TextureSize = 64; private static Sprite _sprite; public static readonly Color HoverColor = new Color(1f, 0.4f, 0.35f); public static Sprite Sprite { get { if (!((Object)(object)_sprite != (Object)null)) { return _sprite = Draw(); } return _sprite; } } private static Sprite Draw() { //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_0016: 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_0025: Expected O, but got Unknown //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_007b: 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_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_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_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_009d: 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_0101: 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) Texture2D val = new Texture2D(64, 64, (TextureFormat)4, true) { name = "BetterBuildMenu_Close", wrapMode = (TextureWrapMode)1, filterMode = (FilterMode)2 }; Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(14f, 14f); Vector2 val3 = default(Vector2); ((Vector2)(ref val3))..ctor(50f, 50f); Color32[] array = (Color32[])(object)new Color32[4096]; Vector2 p = default(Vector2); for (int i = 0; i < 64; i++) { for (int j = 0; j < 64; j++) { ((Vector2)(ref p))..ctor((float)j + 0.5f, (float)i + 0.5f); float num = Mathf.Min(Segment(p, val2, val3), Segment(p, new Vector2(val2.x, val3.y), new Vector2(val3.x, val2.y))) - 5f; float num2 = Mathf.Clamp01(0.5f - num); float num3 = Mathf.Clamp01(0.5f - (num - 4f)); byte b = (byte)(255f * num2); array[i * 64 + j] = new Color32(b, b, b, (byte)(255f * num3)); } } val.SetPixels32(array); val.Apply(true, true); return Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f)); } private static float Segment(Vector2 p, Vector2 a, Vector2 b) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_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_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_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_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) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) Vector2 val = b - a; float num = Mathf.Clamp01(Vector2.Dot(p - a, val) / ((Vector2)(ref val)).sqrMagnitude); Vector2 val2 = p - (a + num * val); return ((Vector2)(ref val2)).magnitude; } } internal class ContainerPreview : MonoBehaviour { private const float RefreshInterval = 0.25f; private const float Margin = 8f; private static readonly Color Background = new Color(0f, 0f, 0f, 0.6f); private static ContainerPreview _instance; private static bool _on; private readonly List<InventoryElement> _elements = new List<InventoryElement>(); private RectTransform _panel; private RectTransform _grid; private TMP_Text _title; private InventoryGrid _vanillaGrid; private Canvas _canvas; private Container _shown; private int _width; private int _height; private float _nextRefresh; public static bool On { get { if (_on) { return Plugin.PreviewEnabled.Value; } return false; } } public static void Ensure() { //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_0099: 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_00b6: 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_00c2: 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_00cd: 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_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: 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) if ((Object)(object)_instance != (Object)null || !Plugin.PreviewEnabled.Value) { return; } Hud instance = Hud.instance; InventoryGui instance2 = InventoryGui.instance; InventoryGrid val = ((instance2 != null) ? instance2.ContainerGrid : null); if (!((Object)(object)instance == (Object)null) && !((Object)(object)val == (Object)null) && !((Object)(object)val.m_elementPrefab == (Object)null)) { Canvas componentInParent = instance.m_rootObject.GetComponentInParent<Canvas>(); Canvas val2 = ((componentInParent != null) ? componentInParent.rootCanvas : null); if (!((Object)(object)val2 == (Object)null)) { GameObject val3 = new GameObject("BetterBuildMenu_ContainerPreview", new Type[1] { typeof(RectTransform) }); val3.SetActive(false); val3.transform.SetParent(((Component)val2).transform, false); val3.transform.SetAsLastSibling(); RectTransform val4 = (RectTransform)val3.transform; val4.anchorMin = Vector2.zero; val4.anchorMax = Vector2.one; Vector2 offsetMin = (val4.offsetMax = Vector2.zero); val4.offsetMin = offsetMin; CanvasGroup obj = val3.AddComponent<CanvasGroup>(); obj.blocksRaycasts = false; obj.interactable = false; _instance = val3.AddComponent<ContainerPreview>(); _instance._vanillaGrid = val; _instance._canvas = val2; val3.SetActive(true); } } } public static void Destroy() { if ((Object)(object)_instance != (Object)null) { Object.Destroy((Object)(object)((Component)_instance).gameObject); } _instance = null; } public static void HandleInput(Player player) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) if (Plugin.PreviewEnabled.Value && !ZInput.IsGamepadActive() && ZInput.GetKeyDown(Plugin.PreviewKey.Value, false) && ((Character)player).TakeInput() && !Hud.InRadial() && !Hud.IsPieceSelectionVisible() && !((Object)(object)Hovered(player) == (Object)null)) { _on = !_on; ZInput.ResetButtonStatus("GP"); } } public static Container Hovered(Player player) { GameObject hoverObject = ((Humanoid)player).GetHoverObject(); if ((Object)(object)hoverObject == (Object)null) { return null; } Hoverable componentInParent = hoverObject.GetComponentInParent<Hoverable>(); Component val = (Component)(object)((componentInParent is Component) ? componentInParent : null); Container val2 = (Container)(((object)((val is Container) ? val : null)) ?? ((object)(((Object)(object)val != (Object)null) ? val.GetComponent<Container>() : null))); if (!CanPreview(val2)) { return null; } return val2; } public static bool CanPreview(Container container) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)container == (Object)null || container.GetInventory() == null || !container.m_nview.IsValid()) { return false; } if (container.m_checkGuardStone && !PrivateArea.CheckAccess(((Component)container).transform.position, 0f, false, false)) { return false; } return container.CheckAccess(Game.instance.GetPlayerProfile().GetPlayerID()); } private void Awake() { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Expected O, but got Unknown //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0064: 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_008a: 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_00b0: Expected O, but got Unknown //IL_00e3: 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_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Expected O, but got Unknown //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Expected O, but got Unknown GameObject val = new GameObject("Panel", new Type[1] { typeof(RectTransform) }); val.transform.SetParent(((Component)this).transform, false); _panel = (RectTransform)val.transform; RectTransform panel = _panel; RectTransform panel2 = _panel; Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(0.5f, 0.5f); panel2.anchorMax = val2; panel.anchorMin = val2; _panel.pivot = new Vector2(0f, 0f); ((Graphic)val.AddComponent<Image>()).color = Background; VerticalLayoutGroup obj = val.AddComponent<VerticalLayoutGroup>(); ((LayoutGroup)obj).childAlignment = (TextAnchor)1; ((LayoutGroup)obj).padding = new RectOffset(8, 8, 4, 8); ((HorizontalOrVerticalLayoutGroup)obj).spacing = 4f; bool childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true); ((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = childControlWidth; childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false); ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = childControlWidth; ContentSizeFitter obj2 = val.AddComponent<ContentSizeFitter>(); FitMode horizontalFit = (FitMode)2; obj2.verticalFit = (FitMode)2; obj2.horizontalFit = horizontalFit; _title = AddTitle(val.transform); GameObject val3 = new GameObject("Grid", new Type[1] { typeof(RectTransform) }); val3.transform.SetParent(val.transform, false); val3.AddComponent<LayoutElement>(); _grid = (RectTransform)val3.transform; val.SetActive(false); } private TMP_Text AddTitle(Transform parent) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown GameObject val = new GameObject("Name", new Type[1] { typeof(RectTransform) }); val.SetActive(false); val.transform.SetParent(parent, false); TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>(); TMP_Text val3 = _vanillaGrid.m_elementPrefab.GetComponent<InventoryElement>()?.m_amount; if ((Object)(object)val3 != (Object)null) { ((TMP_Text)val2).font = val3.font; ((TMP_Text)val2).fontSharedMaterial = val3.fontSharedMaterial; } ((TMP_Text)val2).fontSize = 22f; ((TMP_Text)val2).alignment = (TextAlignmentOptions)513; ((TMP_Text)val2).textWrappingMode = (TextWrappingModes)0; ((Graphic)val2).raycastTarget = false; val.SetActive(true); return (TMP_Text)(object)val2; } private void Update() { //IL_00be: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.PreviewEnabled.Value) { _on = false; Destroy(); return; } Container val = (Visible() ? Hovered(Player.m_localPlayer) : null); if (((Component)_panel).gameObject.activeSelf != ((Object)(object)val != (Object)null)) { ((Component)_panel).gameObject.SetActive((Object)(object)val != (Object)null); } if ((Object)(object)val == (Object)null) { _shown = null; return; } if ((Object)(object)val != (Object)(object)_shown || Time.unscaledTime >= _nextRefresh) { _shown = val; Refresh(val); } float num = Mathf.Clamp(Plugin.PreviewScale.Value, 0.2f, 3f); ((Transform)_panel).localScale = new Vector3(num, num, 1f); Place(); } private static bool Visible() { Player localPlayer = Player.m_localPlayer; Hud instance = Hud.instance; if (On && (Object)(object)localPlayer != (Object)null && !((Character)localPlayer).IsDead() && (Object)(object)instance != (Object)null && instance.m_rootObject.activeInHierarchy && !InventoryGui.IsVisible() && !Hud.IsPieceSelectionVisible() && !Menu.IsVisible() && !Minimap.IsOpen()) { if (Object.op_Implicit((Object)(object)TextViewer.instance)) { return !TextViewer.instance.IsVisible(); } return true; } return false; } private void Place() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0051: 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_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_006a: 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_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_0089: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Expected O, but got Unknown //IL_00a4: 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) RectTransform val = (RectTransform)((Component)this).transform; TextMeshProUGUI hoverName = Hud.instance.m_hoverName; Bounds textBounds = ((TMP_Text)hoverName).textBounds; Vector3 val2 = ((((Bounds)(ref textBounds)).size.y > 0f) ? ((Transform)((TMP_Text)hoverName).rectTransform).TransformPoint(new Vector3(((Bounds)(ref textBounds)).min.x, ((Bounds)(ref textBounds)).max.y, 0f)) : ((Transform)((TMP_Text)hoverName).rectTransform).position); Canvas canvas = ((Graphic)hoverName).canvas; Vector2 val3 = RectTransformUtility.WorldToScreenPoint(EventCamera((canvas != null) ? canvas.rootCanvas : null), val2); Vector2 val4 = default(Vector2); if (RectTransformUtility.ScreenPointToLocalPointInRectangle(val, val3, EventCamera(_canvas), ref val4)) { _panel.anchoredPosition = val4 + new Vector2(0f, 8f); } } private static Camera EventCamera(Canvas canvas) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)canvas == (Object)null) && (int)canvas.renderMode != 0) { return canvas.worldCamera; } return null; } private void Refresh(Container container) { //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: 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_00e3: 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_00fe: 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) _nextRefresh = Time.unscaledTime + 0.25f; Inventory inventory = container.GetInventory(); int width = inventory.GetWidth(); int height = inventory.GetHeight(); if (width != _width || height != _height) { Rebuild(width, height); } string arg = Localization.instance.Localize(container.GetHoverName()); _title.text = $"{arg} <color=#B0B0B0>{inventory.NrOfItems()}/{width * height}</color>"; foreach (InventoryElement element in _elements) { Clear(element); } foreach (ItemData allItem in inventory.GetAllItems()) { Vector2i gridPos = allItem.m_gridPos; if (gridPos.x >= 0 && gridPos.x < width && gridPos.y >= 0 && gridPos.y < height) { Show(_elements[gridPos.y * width + gridPos.x], allItem); } } } private void Rebuild(int width, int height) { //IL_00d6: 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_00dc: 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_00f5: 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_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) _width = width; _height = height; foreach (InventoryElement element in _elements) { Object.Destroy((Object)(object)((Component)element).gameObject); } _elements.Clear(); float elementSpace = _vanillaGrid.m_elementSpace; LayoutElement component = ((Component)_grid).GetComponent<LayoutElement>(); float minWidth = (component.preferredWidth = (float)width * elementSpace); component.minWidth = minWidth; minWidth = (component.preferredHeight = (float)height * elementSpace); component.minHeight = minWidth; Vector2 val2 = default(Vector2); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { GameObject obj = Object.Instantiate<GameObject>(_vanillaGrid.m_elementPrefab, (Transform)(object)_grid, false); ((Object)obj).name = $"Slot {j},{i}"; RectTransform val = (RectTransform)obj.transform; ((Vector2)(ref val2))..ctor(0f, 1f); val.anchorMax = val2; val.anchorMin = val2; val.pivot = new Vector2(0.5f, 0.5f); val.anchoredPosition = new Vector2(((float)j + 0.5f) * elementSpace, (0f - ((float)i + 0.5f)) * elementSpace); Transform obj2 = obj.transform.Find("binding"); TMP_Text val3 = ((obj2 != null) ? ((Component)obj2).GetComponent<TMP_Text>() : null); if ((Object)(object)val3 != (Object)null) { ((Behaviour)val3).enabled = false; } InventoryElement component2 = obj.GetComponent<InventoryElement>(); component2.Initialize(j, i); component2.m_selected.SetActive(false); _elements.Add(component2); } } } private static void Clear(InventoryElement element) { ((Behaviour)element.m_icon).enabled = false; ((Behaviour)element.m_amount).enabled = false; ((Behaviour)element.m_quality).enabled = false; ((Component)element.m_durability).gameObject.SetActive(false); ((Behaviour)element.m_equiped).enabled = false; ((Behaviour)element.m_queued).enabled = false; ((Behaviour)element.m_noteleport).enabled = false; ((Behaviour)element.m_food).enabled = false; } private void Show(InventoryElement element, ItemData item) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Invalid comparison between Unknown and I4 //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_019e: 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_0191: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) SharedData shared = item.m_shared; ((Behaviour)element.m_icon).enabled = true; element.m_icon.sprite = item.GetIcon(); ((Graphic)element.m_icon).color = Color.white; bool flag = shared.m_useDurability && item.m_durability < item.GetMaxDurability(); ((Component)element.m_durability).gameObject.SetActive(flag); if (flag) { element.m_durability.SetValue((item.m_durability <= 0f) ? 1f : item.GetDurabilityPercentage()); if (item.m_durability <= 0f) { element.m_durability.SetColor(Color.red); } else { element.m_durability.ResetColor(); } } ((Behaviour)element.m_noteleport).enabled = !shared.m_teleportable && (!Object.op_Implicit((Object)(object)ZoneSystem.instance) || !ZoneSystem.instance.GetGlobalKey((GlobalKeys)35)); bool flag2 = (int)shared.m_itemType == 2 && (shared.m_food > 0f || shared.m_foodStamina > 0f || shared.m_foodEitr > 0f); ((Behaviour)element.m_food).enabled = flag2; if (flag2) { ((Graphic)element.m_food).color = ((shared.m_food < shared.m_foodEitr / 2f && shared.m_foodStamina < shared.m_foodEitr / 2f) ? _vanillaGrid.m_foodEitrColor : ((shared.m_foodStamina < shared.m_food / 2f) ? _vanillaGrid.m_foodHealthColor : ((shared.m_food < shared.m_foodStamina / 2f) ? _vanillaGrid.m_foodStaminaColor : Color.white))); } ((Behaviour)element.m_quality).enabled = shared.m_maxQuality > 1; if (shared.m_maxQuality > 1) { element.m_quality.text = item.m_quality.ToString(); } ((Behaviour)element.m_amount).enabled = shared.m_maxStackSize > 1; if (shared.m_maxStackSize > 1) { element.m_amount.text = $"{item.m_stack}/{shared.m_maxStackSize}"; } } } [HarmonyPatch(typeof(Player), "Update")] internal static class PlayerUpdatePreviewPatch { private static void Prefix(Player __instance) { if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer) { ContainerPreview.HandleInput(__instance); } } } [HarmonyPatch(typeof(Container), "GetHoverText")] internal static class ContainerGetHoverTextPatch { private static void Postfix(Container __instance, ref string __result) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) if (Plugin.PreviewEnabled.Value && !ZInput.IsGamepadActive() && ContainerPreview.CanPreview(__instance)) { string arg = (ContainerPreview.On ? "Hide contents" : "Preview contents"); __result += $"\n[<color=yellow><b>{Plugin.PreviewKey.Value}</b></color>] {arg}"; } } } internal static class CraftSections { private sealed class Section { public readonly string Title; public readonly Color Color; public readonly CraftTab Tab; public int Order; public Section(string title, Color color, CraftTab tab = CraftTab.Misc) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) Title = title; Color = color; Tab = tab; } } private const string HeadingName = "BetterBuildMenu_CraftSection"; private const float Tie = 0.5f; private const string FavouritesKey = "BetterBuildMenu.FoodFavourites"; private static readonly Color Plain; private static readonly Section Favourites; private static readonly Section Health; private static readonly Section Stamina; private static readonly Section Eitr; private static readonly Section Balanced; private static readonly Section NotFood; private static readonly Section Swords; private static readonly Section Axes; private static readonly Section Clubs; private static readonly Section Knives; private static readonly Section Spears; private static readonly Section Polearms; private static readonly Section Fists; private static readonly Section Bows; private static readonly Section Crossbows; private static readonly Section ElementalMagic; private static readonly Section BloodMagic; private static readonly Section Throwables; private static readonly Section Arrows; private static readonly Section Bolts; private static readonly Section Ammo; private static readonly Section Shields; private static readonly Section Helmets; private static readonly Section Chest; private static readonly Section Legs; private static readonly Section Capes; private static readonly Section Utility; private static readonly Section Trinkets; private static readonly Section Tools; private static readonly Section Torches; private static readonly Section Consumables; private static readonly Section Materials; private static readonly Section Misc; private static readonly Section Other; static CraftSections() { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0051: 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_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: 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_00e7: 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_0111: 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_013b: 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_0165: 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_018f: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: 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_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_0261: Unknown result type (might be due to invalid IL or missing references) //IL_0276: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_02a0: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) //IL_02ca: Unknown result type (might be due to invalid IL or missing references) //IL_02df: Unknown result type (might be due to invalid IL or missing references) //IL_02f4: Unknown result type (might be due to invalid IL or missing references) //IL_0309: Unknown result type (might be due to invalid IL or missing references) //IL_031e: Unknown result type (might be due to invalid IL or missing references) Plain = new Color(0.9f, 0.9f, 0.9f); Favourites = new Section("Favourites", new Color(1f, 0.75f, 0.2f)); Health = new Section("$item_food_health", new Color(1f, 0.5f, 0.5f)); Stamina = new Section("$item_food_stamina", new Color(1f, 1f, 0.5f)); Eitr = new Section("$item_food_eitr", new Color(0.56f, 0.56f, 1f)); Balanced = new Section("Balanced", Color.white); NotFood = new Section("Other", new Color(0.8f, 0.8f, 0.8f)); Swords = new Section("Swords", Plain, CraftTab.Weapons); Axes = new Section("Axes", Plain, CraftTab.Weapons); Clubs = new Section("Clubs", Plain, CraftTab.Weapons); Knives = new Section("Knives", Plain, CraftTab.Weapons); Spears = new Section("Spears", Plain, CraftTab.Weapons); Polearms = new Section("Polearms", Plain, CraftTab.Weapons); Fists = new Section("Fists", Plain, CraftTab.Weapons); Bows = new Section("Bows", Plain, CraftTab.Weapons); Crossbows = new Section("Crossbows", Plain, CraftTab.Weapons); ElementalMagic = new Section("Elemental magic", Plain, CraftTab.Weapons); BloodMagic = new Section("Blood magic", Plain, CraftTab.Weapons); Throwables = new Section("Throwables", Plain, CraftTab.Weapons); Arrows = new Section("Arrows", Plain, CraftTab.Weapons); Bolts = new Section("Bolts", Plain, CraftTab.Weapons); Ammo = new Section("Ammo", Plain, CraftTab.Weapons); Shields = new Section("Shields", Plain, CraftTab.Armour); Helmets = new Section("Helmets", Plain, CraftTab.Armour); Chest = new Section("Chest armor", Plain, CraftTab.Armour); Legs = new Section("Leg armor", Plain, CraftTab.Armour); Capes = new Section("Capes", Plain, CraftTab.Armour); Utility = new Section("Utility", Plain, CraftTab.Armour); Trinkets = new Section("Trinkets", Plain, CraftTab.Armour); Tools = new Section("Tools", Plain); Torches = new Section("Torches", Plain); Consumables = new Section("Consumables", Plain); Materials = new Section("Materials", Plain); Misc = new Section("Misc", Plain); Other = new Section("Other", Plain); Section[] array = new Section[34] { Favourites, Health, Stamina, Eitr, Balanced, NotFood, Swords, Axes, Clubs, Knives, Spears, Polearms, Fists, Bows, Crossbows, ElementalMagic, BloodMagic, Throwables, Arrows, Bolts, Ammo, Shields, Helmets, Chest, Legs, Capes, Utility, Trinkets, Tools, Torches, Consumables, Materials, Misc, Other }; for (int i = 0; i < array.Length; i++) { array[i].Order = i; } } public static void Apply(InventoryGui gui, List<Recipe> available) { //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Expected O, but got Unknown //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Unknown result type (might be due to invalid IL or missing references) //IL_0291: Unknown result type (might be due to invalid IL or missing references) //IL_0301: Unknown result type (might be due to invalid IL or missing references) //IL_0322: Unknown result type (might be due to invalid IL or missing references) //IL_0327: Unknown result type (might be due to invalid IL or missing references) //IL_032a: Unknown result type (might be due to invalid IL or missing references) //IL_0351: Unknown result type (might be due to invalid IL or missing references) //IL_0356: Unknown result type (might be due to invalid IL or missing references) //IL_0357: Unknown result type (might be due to invalid IL or missing references) //IL_036d: Unknown result type (might be due to invalid IL or missing references) List<RecipeDataPair> availableRecipes = gui.m_availableRecipes; RectTransform recipeListRoot = gui.m_recipeListRoot; List<Recipe> source = available.Where((Recipe recipe) => !recipe.m_noCraftOnlyUpgrade).ToList(); bool food = Plugin.FoodSections.Value && source.Any((Recipe recipe) => FoodSection(recipe).section != NotFood); HashSet<CraftTab> present = ((!food && ((Component)gui.m_tabCraft).gameObject.activeSelf) ? source.Select(Tab).ToHashSet() : new HashSet<CraftTab>()); CraftTab? craftTab = CraftTabs.Update(gui, present); if (craftTab.HasValue) { Keep(gui, craftTab.Value); } if (!gui.InCraftTab() || availableRecipes.Count <= 0 || (!food && !Plugin.ItemSections.Value)) { Hide((Transform)(object)recipeListRoot); return; } List<string> favourites = FavouriteNames(Player.m_localPlayer); List<(Section, List<RecipeDataPair>)> list = (from x in availableRecipes.Select(delegate(RecipeDataPair pair, int index) { //IL_0071: Unknown result type (might be due to invalid IL or missing references) int num4 = favourites.IndexOf(((Object)((Component)((RecipeDataPair)(ref pair)).Recipe.m_item).gameObject).name); (Section, float) item = ((num4 >= 0) ? (Favourites, -num4) : (food ? FoodSection(((RecipeDataPair)(ref pair)).Recipe) : (ItemSection(((RecipeDataPair)(ref pair)).Recipe.m_item.m_itemData.m_shared), 0f))); return ((RecipeDataPair pair, int index, (Section section, float value) stat))(pair: pair, index: index, stat: item); }) group x by x.stat.section into g orderby g.Key.Order select (section: g.Key, pairs: (from x in g orderby x.stat.value descending, x.index select x.pair).ToList())).ToList(); if (!food && list.Count < 2) { Hide((Transform)(object)recipeListRoot); { foreach (RecipeDataPair item2 in availableRecipes) { RecipeDataPair current = item2; AddRightClick(gui, ((RecipeDataPair)(ref current)).InterfaceElement, ((RecipeDataPair)(ref current)).Recipe); } return; } } RecipeDataPair val = availableRecipes[0]; RectTransform val2 = (RectTransform)((RecipeDataPair)(ref val)).InterfaceElement.transform; float recipeListSpace = gui.m_recipeListSpace; List<Transform> list2 = (from Transform t in (IEnumerable)recipeListRoot where ((Object)t).name == "BetterBuildMenu_CraftSection" select t).ToList(); int num = 0; int num2 = 0; availableRecipes.Clear(); foreach (var item3 in list) { Transform obj; if (num >= list2.Count) { Rect rect = val2.rect; obj = Heading.Create("BetterBuildMenu_CraftSection", (Transform)(object)recipeListRoot, ((Rect)(ref rect)).height, ((Component)((Transform)val2).Find("name")).GetComponent<TMP_Text>(), 18f); } else { obj = list2[num]; } num++; Place(obj, val2, num2++, recipeListSpace); ((Component)obj).gameObject.SetActive(true); Heading.Set(obj, Localization.instance.Localize(item3.Item1.Title), null, item3.Item1.Color); foreach (RecipeDataPair item4 in item3.Item2) { RecipeDataPair current3 = item4; availableRecipes.Add(current3); AddRightClick(gui, ((RecipeDataPair)(ref current3)).InterfaceElement, ((RecipeDataPair)(ref current3)).Recipe); RectTransform val3 = (RectTransform)((RecipeDataPair)(ref current3)).InterfaceElement.transform; val3.anchoredPosition = new Vector2(val3.anchoredPosition.x, (float)(-(num2++)) * recipeListSpace); } } for (int num3 = num; num3 < list2.Count; num3++) { ((Component)list2[num3]).gameObject.SetActive(false); } recipeListRoot.SetSizeWithCurrentAnchors((Axis)1, Mathf.Max(gui.m_recipeListBaseSize, (float)num2 * recipeListSpace)); } public static void Destroy() { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown RectTransform val = InventoryGui.instance?.m_recipeListRoot; if ((Object)(object)val == (Object)null) { return; } foreach (Transform item in (Transform)val) { Transform val2 = item; if (((Object)val2).name == "BetterBuildMenu_CraftSection") { Object.Destroy((Object)(object)((Component)val2).gameObject); } } } public static string ItemSectionTitle(SharedData shared) { return ItemSection(shared).Title; } private static CraftTab Tab(Recipe recipe) { return ItemSection(recipe.m_item.m_itemData.m_shared).Tab; } private static void Keep(InventoryGui gui, CraftTab tab) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_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_0073: 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) List<RecipeDataPair> availableRecipes = gui.m_availableRecipes; RecipeDataPair val; for (int num = availableRecipes.Count - 1; num >= 0; num--) { val = availableRecipes[num]; if (Tab(((RecipeDataPair)(ref val)).Recipe) != tab) { val = availableRecipes[num]; Object.Destroy((Object)(object)((RecipeDataPair)(ref val)).InterfaceElement); availableRecipes.RemoveAt(num); } } float recipeListSpace = gui.m_recipeListSpace; for (int i = 0; i < availableRecipes.Count; i++) { val = availableRecipes[i]; RectTransform val2 = (RectTransform)((RecipeDataPair)(ref val)).InterfaceElement.transform; val2.anchoredPosition = new Vector2(val2.anchoredPosition.x, (float)(-i) * recipeListSpace); } gui.m_recipeListRoot.SetSizeWithCurrentAnchors((Axis)1, Mathf.Max(gui.m_recipeListBaseSize, (float)availableRecipes.Count * recipeListSpace)); } private static void AddRightClick(InventoryGui gui, GameObject element, Recipe recipe) { if (!((Object)(object)element.GetComponent<UIInputHandler>() != (Object)null)) { UIInputHandler obj = element.AddComponent<UIInputHandler>(); obj.m_onLeftClick = delegate { }; obj.m_onRightClick = delegate { ToggleFavourite(gui, recipe); }; } } private static List<string> FavouriteNames(Player player) { if (!((Object)(object)player != (Object)null) || !player.m_customData.TryGetValue("BetterBuildMenu.FoodFavourites", out var value)) { return new List<string>(); } return (from name in value.Split(new char[1] { ',' }) where name.Length > 0 select name).ToList(); } private static void ToggleFavourite(InventoryGui gui, Recipe recipe) { Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null) && !((Object)(object)recipe?.m_item == (Object)null)) { List<string> list = FavouriteNames(localPlayer); string name = ((Object)((Component)recipe.m_item).gameObject).name; bool flag = !list.Remove(name); if (flag) { list.Add(name); } if (list.Count == 0) { localPlayer.m_customData.Remove("BetterBuildMenu.FoodFavourites"); } else { localPlayer.m_customData["BetterBuildMenu.FoodFavourites"] = string.Join(",", list); } ItemData itemData = recipe.m_item.m_itemData; string text = Localization.instance.Localize(itemData.m_shared.m_name); ((Character)localPlayer).Message((MessageType)1, flag ? ("Favourited " + text) : ("Unfavourited " + text), 0, itemData.GetIcon(), false); gui.UpdateCraftingPanel(false); } } private static void Hide(Transform root) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Expected O, but got Unknown foreach (Transform item in root) { Transform val = item; if (((Object)val).name == "BetterBuildMenu_CraftSection") { ((Component)val).gameObject.SetActive(false); } } } private static void Place(Transform heading, RectTransform template, int row, float space) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0020: 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_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) RectTransform val = (RectTransform)heading; val.anchorMin = template.anchorMin; val.anchorMax = template.anchorMax; val.pivot = template.pivot; val.sizeDelta = template.sizeDelta; val.anchoredPosition = new Vector2(template.anchoredPosition.x, (float)(-row) * space); } private static Section ItemSection(SharedData shared) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected I4, but got Unknown ItemType itemType = shared.m_itemType; switch (itemType - 1) { case 2: case 3: case 13: case 21: return WeaponSection(shared); case 8: case 22: if (!(shared.m_ammoType == "$ammo_arrows")) { if (!(shared.m_ammoType == "$ammo_bolts")) { return Ammo; } return Bolts; } return Arrows; case 4: return Shields; case 5: return Helmets; case 6: return Chest; case 10: return Legs; case 16: return Capes; case 17: return Utility; case 23: return Trinkets; case 18: return Tools; case 14: return Torches; case 1: return Consumables; case 0: return Materials; case 15: return Misc; default: return Other; } } private static Section WeaponSection(SharedData shared) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected I4, but got Unknown //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Invalid comparison between Unknown and I4 //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Invalid comparison between Unknown and I4 //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Invalid comparison between Unknown and I4 //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Invalid comparison between Unknown and I4 SkillType skillType = shared.m_skillType; switch ((int)skillType) { default: if ((int)skillType != 106) { break; } goto case 12; case 1: if ((int)shared.m_animationState != 1 && (int)shared.m_animationState != 13) { return Misc; } return Swords; case 7: return Axes; case 3: return Clubs; case 2: return Knives; case 5: return Spears; case 4: return Polearms; case 11: return Fists; case 8: return Bows; case 14: return Crossbows; case 9: return ElementalMagic; case 10: return BloodMagic; case 12: case 13: return Tools; case 0: if ((int)shared.m_itemType != 4) { return Throwables; } return Tools; case 6: break; } return Other; } private static (Section section, float value) FoodSection(Recipe recipe) { SharedData val = FoodStats(recipe.m_item.m_itemData.m_shared); if (val == null) { return (section: NotFood, value: 0f); } float[] array = new float[3] { val.m_food, val.m_foodStamina, val.m_foodEitr }; float top = array.Max(); if (top <= 0f) { return (section: NotFood, value: 0f); } if (array.Count((float stat) => stat > top - 0.5f) > 1) { return (section: Balanced, value: top); } return (section: (new Section[3] { Health, Stamina, Eitr })[Array.FindIndex(array, (float stat) => stat > top - 0.5f)], value: top); } private static SharedData FoodStats(SharedData shared) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Invalid comparison between Unknown and I4 SharedData val = shared.m_appendToolTip?.m_itemData.m_shared; if (val != null && HasFood(val)) { return val; } if ((int)shared.m_itemType != 2 || !HasFood(shared)) { return null; } return shared; } private static bool HasFood(SharedData shared) { if (!(shared.m_food > 0f) && !(shared.m_foodStamina > 0f)) { return shared.m_foodEitr > 0f; } return true; } } internal enum CraftTab { Weapons, Armour, Misc } internal static class CraftTabs { private const string ObjectName = "BetterBuildMenu_CraftTab"; private const float Width = 92f; private const float Gap = 7f; private static readonly CraftTab?[] Entries = new CraftTab?[4] { null, CraftTab.Weapons, CraftTab.Armour, CraftTab.Misc }; private static readonly string[] Labels = new string[4] { "All", "Weapons", "Armour", "Misc" }; private static Button[] _buttons; private static CraftTab? _selected; private static readonly List<CraftTab?> Shown = new List<CraftTab?>(); private static InventoryGui _moved; private static Vector3 _craftScale; private static Vector3 _upgradePosition; private static Vector2 _upgradeSize; public static CraftTab? Update(InventoryGui gui, ICollection<CraftTab> present) { Shown.Clear(); if (Plugin.ItemTabs.Value && present.Count >= 2) { Shown.AddRange(Entries.Where((CraftTab? entry) => !entry.HasValue || present.Contains(entry.Value))); } if (Shown.Count == 0) { Hide(); return null; } Ensure(gui); bool flag = gui.InCraftTab(); CraftTab? craftTab = (Shown.Contains(_selected) ? _selected : ((CraftTab?)null)); Layout(gui, flag, craftTab); if (!flag) { return null; } return craftTab; } public static void Hide() { //IL_005b: 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_0079: 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_0084: Unknown result type (might be due to invalid IL or missing references) Shown.Clear(); if (_buttons != null) { Button[] buttons = _buttons; foreach (Button val in buttons) { if ((Object)(object)val != (Object)null) { ((Component)val).gameObject.SetActive(false); } } } if (!((Object)(object)_moved == (Object)null)) { ((Component)_moved.m_tabCraft).transform.localScale = _craftScale; RectTransform val2 = (RectTransform)((Component)_moved.m_tabUpgrade).transform; ((Transform)val2).localPosition = _upgradePosition; val2.sizeDelta = _upgradeSize; _moved = null; } } public static void Cycle(InventoryGui gui, int step) { if (Shown.Count >= 2 && gui.InCraftTab()) { int num = Shown.IndexOf(_selected); if (num < 0) { num = 0; } Select(gui, Shown[(num + step + Shown.Count) % Shown.Count]); } } public static void Destroy() { Hide(); if (_buttons != null) { Button[] buttons = _buttons; foreach (Button val in buttons) { if ((Object)(object)val != (Object)null) { Object.Destroy((Object)(object)((Component)val).gameObject); } } } _buttons = null; } private static void Select(InventoryGui gui, CraftTab? tab) { _selected = tab; gui.SetActiveGroup(gui.m_uiGroups[3], true); ((Selectable)gui.m_tabCraft).interactable = false; ((Selectable)gui.m_tabUpgrade).interactable = true; gui.UpdateCraftingPanel(true); } private static void Ensure(InventoryGui gui) { //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Expected O, but got Unknown //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Expected O, but got Unknown if (_buttons != null && _buttons.All((Button button) => (Object)(object)button != (Object)null)) { return; } Destroy(); Button tabCraft = gui.m_tabCraft; ButtonTextColor component = ((Component)tabCraft).GetComponent<ButtonTextColor>(); _buttons = (Button[])(object)new Button[Entries.Length]; for (int num = 0; num < Entries.Length; num++) { CraftTab? tab = Entries[num]; GameObject obj = Object.Instantiate<GameObject>(((Component)tabCraft).gameObject, ((Component)tabCraft).transform.parent, false); ((Object)obj).name = "BetterBuildMenu_CraftTab_" + Labels[num]; obj.transform.localScale = Vector3.one; Object.DestroyImmediate((Object)(object)obj.GetComponent<UIGamePad>()); Transform val = obj.transform.Find("gamepad_hint"); if ((Object)(object)val != (Object)null) { Object.DestroyImmediate((Object)(object)((Component)val).gameObject); } ButtonTextColor component2 = obj.GetComponent<ButtonTextColor>(); if ((Object)(object)component != (Object)null && (Object)(object)component2 != (Object)null) { Traverse val2 = Traverse.Create((object)component); Traverse obj2 = Traverse.Create((object)component2); obj2.Field("m_defaultColor").SetValue(val2.Field("m_defaultColor").GetValue()); obj2.Field("m_defaultMeshColor").SetValue(val2.Field("m_defaultMeshColor").GetValue()); } ((Component)obj.transform.Find("Text")).GetComponent<TMP_Text>().text = Labels[num]; Button component3 = obj.GetComponent<Button>(); component3.onClick = new ButtonClickedEvent(); ((UnityEvent)component3.onClick).AddListener((UnityAction)delegate { Select(gui, tab); }); _buttons[num] = component3; } } private static void Layout(InventoryGui gui, bool crafting, CraftTab? current) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: 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_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0041: 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_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0176: 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_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: 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_00fc: Unknown result type (might be due to invalid IL or missing references) RectTransform val = (RectTransform)((Component)gui.m_tabCraft).transform; RectTransform val2 = (RectTransform)((Component)gui.m_tabUpgrade).transform; if ((Object)(object)_moved == (Object)null) { _moved = gui; _craftScale = ((Transform)val).localScale; _upgradePosition = ((Transform)val2).localPosition; _upgradeSize = val2.sizeDelta; } Vector2 sizeDelta = default(Vector2); ((Vector2)(ref sizeDelta))..ctor(92f, val.sizeDelta.y); Vector3 localPosition = ((Transform)val).localPosition; float num = localPosition.x - val.sizeDelta.x / 2f + 46f; ((Transform)val).localScale = Vector3.zero; for (int i = 0; i < Entries.Length; i++) { Button val3 = _buttons[i]; bool flag = Shown.Contains(Entries[i]); ((Component)val3).gameObject.SetActive(flag); if (flag) { RectTransform val4 = (RectTransform)((Component)val3).transform; val4.sizeDelta = sizeDelta; ((Transform)val4).localPosition = new Vector3(num, localPosition.y, localPosition.z); num += 99f; ((Selectable)val3).interactable = !crafting || Entries[i] != current; } } val2.sizeDelta = new Vector2(92f, _upgradeSize.y); ((Transform)val2).localPosition = new Vector3(num, _upgradePosition.y, _upgradePosition.z); } } [HarmonyPatch(typeof(InventoryGui), "UpdateRecipeGamepadInput")] internal static class InventoryGuiUpdateRecipeGamepadInputPatch { private static void Postfix(InventoryGui __instance) { if (ZInput.GetButtonDown("JoyDPadLeft")) { CraftTabs.Cycle(__instance, -1); } if (ZInput.GetButtonDown("JoyDPadRight")) { CraftTabs.Cycle(__instance, 1); } } } internal static class Heading { public static Transform Create(string name, Transform parent, float height, TMP_Text style, float fontSize) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown //IL_004d: 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_005d: 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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Expected O, but got Unknown //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0132: 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_0148: Unknown result type (might be due to invalid IL or missing references) //IL_0182: 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_018e: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: 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_01b1: 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) //IL_0248: 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_025f: Unknown result type (might be due to invalid IL or missing references) //IL_0265: 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_027e: 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) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name, new Type[2] { typeof(RectTransform), typeof(LayoutElement) }); val.SetActive(false); val.GetComponent<LayoutElement>().ignoreLayout = true; val.transform.SetParent(parent, false); RectTransform val2 = (RectTransform)val.transform; val2.anchorMin = new Vector2(0f, 1f); val2.anchorMax = new Vector2(1f, 1f); val2.pivot = new Vector2(0f, 1f); HorizontalLayoutGroup obj = val.AddComponent<HorizontalLayoutGroup>(); ((LayoutGroup)obj).childAlignment = (TextAnchor)3; ((HorizontalOrVerticalLayoutGroup)obj).spacing = 6f; ((LayoutGroup)obj).padding = new RectOffset(2, 0, 0, 0); ((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true; ((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = false; bool childForceExpandWidth = (((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false); ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = childForceExpandWidth; float num = height - 2f; GameObject val3 = new GameObject("Icon", new Type[3] { typeof(RectTransform), typeof(Image), typeof(LayoutElement) }); val3.transform.SetParent(val.transform, false); ((RectTransform)val3.transform).sizeDelta = new Vector2(num, num); val3.GetComponent<Image>().preserveAspect = true; ((Graphic)val3.GetComponent<Image>()).raycastTarget = false; LayoutElement component = val3.GetComponent<LayoutElement>(); float preferredWidth = (component.minWidth = num); component.preferredWidth = preferredWidth; GameObject val4 = new GameObject("Name", new Type[1] { typeof(RectTransform) }); val4.SetActive(false); val4.transform.SetParent(val.transform, false); ((RectTransform)val4.transform).sizeDelta = new Vector2(0f, height); TextMeshProUGUI val5 = val4.AddComponent<TextMeshProUGUI>(); if ((Object)(object)style != (Object)null) { ((TMP_Text)val5).font = style.font; ((TMP_Text)val5).fontSharedMaterial = style.fontSharedMaterial; ((Graphic)val5).color = ((Graphic)style).color; } ((TMP_Text)val5).fontSize = fontSize; ((TMP_Text)val5).alignment = (TextAlignmentOptions)4097; ((TMP_Text)val5).textWrappingMode = (TextWrappingModes)0; ((Graphic)val5).raycastTarget = false; val4.SetActive(true); GameObject val6 = new GameObject("Line", new Type[3] { typeof(RectTransform), typeof(Image), typeof(LayoutElement) }); val6.transform.SetParent(val.transform, false); ((RectTransform)val6.transform).sizeDelta = new Vector2(0f, 2f); Image component2 = val6.GetComponent<Image>(); ((Graphic)component2).color = new Color(1f, 1f, 1f, 0.15f); ((Graphic)component2).raycastTarget = false; val6.GetComponent<LayoutElement>().flexibleWidth = 1f; return val.transform; } public static void Set(Transform heading, string text, Sprite icon, Color? color = null) { //IL_0059: Unknown result type (might be due to invalid IL or missing references) Image component = ((Component)heading.Find("Icon")).GetComponent<Image>(); component.sprite = icon; ((Behaviour)component).enabled = (Object)(object)icon != (Object)null; ((Component)component).gameObject.SetActive((Object)(object)icon != (Object)null); TMP_Text component2 = ((Component)heading.Find("Name")).GetComponent<TMP_Text>(); component2.text = text; if (color.HasValue) { ((Graphic)component2).color = color.Value; } } } internal static class Highlight { private const float Thickness = 3f; private const float Padding = 2f; private static GameObject _frame; public static BuildUiPieceButton Current { get; private set; } public static Piece CurrentPiece { get; private set; } public static void Show(BuildUiPieceButton button) { if ((Object)(object)button == (Object)null) { Hide(); return; } if ((Object)(object)_frame == (Object)null) { _frame = Create(); } Current = button; CurrentPiece = button.Piece; _frame.transform.SetParent(((Component)button).transform, false); _frame.transform.SetAsLastSibling(); _frame.SetActive(true); } public static void Hide() { Current = null; if ((Object)(object)_frame != (Object)null) { _frame.SetActive(false); } } public static void Destroy() { Current = null; if ((Object)(object)_frame != (Object)null) { Object.Destroy((Object)(object)_frame); } _frame = null; } private static GameObject Create() { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0036: 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_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0057: 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_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008a: 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_009b: 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_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Expected O, but got Unknown //IL_00c4: 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_00e3: 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_00fd: Expected O, but got Unknown //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Expected O, but got Unknown //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0155: 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_016f: Expected O, but got Unknown //IL_0170: Expected O, but got Unknown GameObject val = new GameObject("BetterBuildMenu_Highlight", new Type[2] { typeof(RectTransform), typeof(LayoutElement) }); val.GetComponent<LayoutElement>().ignoreLayout = true; RectTransform val2 = (RectTransform)val.transform; val2.anchorMin = Vector2.zero; val2.anchorMax = Vector2.one; val2.offsetMin = new Vector2(-2f, -2f); val2.offsetMax = new Vector2(2f, 2f); Color value = Plugin.HighlightColor.Value; Side(val, "Top", new Vector2(0f, 1f), new Vector2(1f, 1f), new Vector2(0f, 3f), value); Side(val, "Bottom", new Vector2(0f, 0f), new Vector2(1f, 0f), new Vector2(0f, 3f), value); Side(val, "Left", new Vector2(0f, 0f), new Vector2(0f, 1f), new Vector2(3f, 0f), value); Side(val, "Right", new Vector2(1f, 0f), new Vector2(1f, 1f), new Vector2(3f, 0f), value); return val; } private static void Side(GameObject frame, string name, Vector2 anchorMin, Vector2 anchorMax, Vector2 size, Color color) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: 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_004c: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0053: 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_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_007d: 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_008d: 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_0095: 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) GameObject val = new GameObject(name, new Type[2] { typeof(RectTransform), typeof(Image) }); RectTransform val2 = (RectTransform)val.transform; ((Transform)val2).SetParent(frame.transform, false); val2.anchorMin = anchorMin; val2.anchorMax = anchorMax; val2.pivot = new Vector2((anchorMin.x == anchorMax.x) ? anchorMin.x : 0.5f, (anchorMin.y == anchorMax.y) ? anchorMin.y : 0.5f); val2.sizeDelta = size; val2.anchoredPosition = Vector2.zero; Image component = val.GetComponent<Image>(); ((Graphic)component).color = color; ((Graphic)component).raycastTarget = false; } } internal static class MenuDetails { public const float Gap = 10f; private const string HomeName = "BetterBuildMenu_DetailsHome"; private static bool _warned; public static float Room(BuildUi ui) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.DetailsInMenu.Value) { return 0f; } RectTransform val = Home(Hud.instance, ui); RectTransform val2 = Panel(Hud.instance, ui); if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null)) { return val.sizeDelta.y * ((Transform)val2).localScale.y + 10f; } return 0f; } public static void Sync() { //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0098: 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_0086: 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_00ae: 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_00df: 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_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0127: 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_0146: 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) Hud instance = Hud.instance; if ((Object)(object)instance == (Object)null) { return; } BuildUi buildUi = instance.m_buildUi; RectTransform val = Panel(instance, buildUi); RectTransform val2 = Home(instance, buildUi); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null) { return; } if (Plugin.DetailsInMenu.Value && Hud.IsPieceSelectionVisible()) { if ((Object)(object)((Transform)val).parent != (Object)(object)buildUi.m_pieceView) { ((Transform)val).SetParent((Transform)(object)buildUi.m_pieceView, false); } if (val.anchorMin != Vector2.zero || val.anchorMax != Vector2.right) { val.anchorMin = Vector2.zero; val.anchorMax = Vector2.right; } if (val.pivot != new Vector2(0.5f, 1f)) { val.pivot = new Vector2(0.5f, 1f); } if (val.anchoredPosition != new Vector2(0f, -10f)) { val.anchoredPosition = new Vector2(0f, -10f); } float x = ((Transform)val).localScale.x; Rect rect = buildUi.m_pieceView.rect; float width = ((Rect)(ref rect)).width; val.sizeDelta = new Vector2(width / x - width, val2.sizeDelta.y); } else { Return(val, val2); } } public static void Destroy() { Hud instance = Hud.instance; if (!((Object)(object)instance == (Object)null)) { RectTransform val = Panel(instance, instance.m_buildUi); Transform obj = instance.m_buildHud.transform.Find("BetterBuildMenu_DetailsHome"); RectTransform val2 = (RectTransform)(object)((obj is RectTransform) ? obj : null); if ((Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null) { Return(val, val2); } } } private static void Return(RectTransform panel, RectTransform home) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)((Transform)panel).parent == (Object)(object)((Transform)home).parent)) { ((Transform)panel).SetParent(((Transform)home).parent, false); panel.anchorMin = home.anchorMin; panel.anchorMax = home.anchorMax; panel.pivot = home.pivot; panel.sizeDelta = home.sizeDelta; panel.anchoredPosition = home.anchoredPosition; ((Transform)panel).SetSiblingIndex(((Transform)home).GetSiblingIndex()); } } private static RectTransform Panel(Hud hud, BuildUi ui) { if ((Object)(object)hud == (Object)null || (Object)(object)ui == (Object)null || (Object)(object)hud.m_buildSelection == (Object)null) { return null; } Transform val = hud.m_buildSelection.transform; while ((Object)(object)val.parent != (Object)null && (Object)(object)val.parent != (Object)(object)hud.m_buildHud.transform && (Object)(object)val.parent != (Object)(object)ui.m_pieceView) { val = val.parent; } if (!((Object)(object)val.parent == (Object)null)) { return (RectTransform)(object)((val is RectTransform) ? val : null); } return null; } private static RectTransform Home(Hud hud, BuildUi ui) { //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Expected O, but got Unknown //IL_00a3: 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_00bb: 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) if ((Object)(object)hud == (Object)null) { return null; } Transform transform = hud.m_buildHud.transform; Transform obj = transform.Find("BetterBuildMenu_DetailsHome"); RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null); if (val != null) { return val; } RectTransform val2 = Panel(hud, ui); if ((Object)(object)val2 == (Object)null || (Object)(object)((Transform)val2).parent != (Object)(object)transform) { if (!_warned) { Plugin.Log.LogWarning((object)"Details in menu: couldn't find the build HUD's details panel"); } _warned = true; return null; } GameObject val3 = new GameObject("BetterBuildMenu_DetailsHome", new Type[1] { typeof(RectTransform) }); val3.SetActive(false); val = (RectTransform)val3.transform; ((Transform)val).SetParent(transform, false); val.anchorMin = val2.anchorMin; val.anchorMax = val2.anchorMax; val.pivot = val2.pivot; val.sizeDelta = val2.sizeDelta; val.anchoredPosition = val2.anchoredPosition; ((Transform)val).SetSiblingIndex(((Transform)val2).GetSiblingIndex() + 1); return val; } } internal static class MenuSize { private const float TopMargin = 40f; private const float SideMargin = 20f; private const float BottomMargin = 20f; private const float HudGap = 10f; private const string OriginalName = "BetterBuildMenu_OriginalSize"; private const string OriginalGridName = "BetterBuildMenu_OriginalGrid"; public static void Apply(BuildUi ui) { //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_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00da: 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_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Expected O, but got Unknown //IL_0099: 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_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0162: 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_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_021f: 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_023d: 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_025c: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Unknown result type (might be due to invalid IL or missing references) //IL_0281: Unknown result type (might be due to invalid IL or missing references) //IL_033e: Unknown result type (might be due to invalid IL or missing references) //IL_0349: Unknown result type (might be due to invalid IL or missing references) //IL_0362: Unknown result type (might be due to invalid IL or missing references) //IL_037a: Unknown result type (might be due to invalid IL or missing references) //IL_0389: Unknown result type (might be due to invalid IL or missing references) //IL_039f: Unknown result type (might be due to invalid IL or missing references) //IL_03ae: Unknown result type (might be due to invalid IL or missing references) //IL_03b9: Unknown result type (might be due to invalid IL or missing references) //IL_03c5: Unknown result type (might be due to invalid IL or missing references) //IL_03ca: Unknown result type (might be due to invalid IL or missing references) //IL_03cf: Unknown result type (might be due to invalid IL or missing references) //IL_03d6: Unknown result type (might be due to invalid IL or missing references) //IL_03f1: Unknown result type (might be due to invalid IL or missing references) //IL_03f4: Unknown result type (might be due to invalid IL or missing references) //IL_0424: Unknown result type (might be due to invalid IL or missing references) //IL_0433: Unknown result type (might be due to invalid IL or missing references) //IL_0442: Unknown result type (might be due to invalid IL or missing references) //IL_0400: Unknown result type (might be due to invalid IL or missing references) //IL_0403: Unknown result type (might be due to invalid IL or missing references) //IL_04b3: Unknown result type (might be due to invalid IL or missing references) //IL_04bb: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)ui == (Object)null) { return; } Transform obj = ((Component)ui).transform.Find("bar"); RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null); Canvas componentInParent = ((Component)ui).GetComponentInParent<Canvas>(); Canvas val2 = ((componentInParent != null) ? componentInParent.rootCanvas : null); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null) { return; } Transform obj2 = ((Transform)val).Find("BetterBuildMenu_OriginalSize"); RectTransform val3 = (RectTransform)(object)((obj2 is RectTransform) ? obj2 : null); if ((Object)(object)val3 == (Object)null) { GameObject val4 = new GameObject("BetterBuildMenu_OriginalSize", new Type[1] { typeof(RectTransform) }); val4.SetActive(false); val3 = (RectTransform)val4.transform; ((Transform)val3).SetParent((Transform)(object)val, false); val3.sizeDelta = val.sizeDelta; val3.anchoredPosition = val.anchoredPosition; } AnchorSearchToTop(ui, val, val3); Rect rect = ((RectTransform)((Component)val2).transform).rect; Vector2 val5 = ((Rect)(ref rect)).size / 2f; float num = 0f - val5.x + 20f; float num2 = val5.x - 20f; float? num3 = PinPanel.Left(val); if (num3.HasValue) { float valueOrDefault = num3.GetValueOrDefault(); num2 = Mathf.Min(num2, valueOrDefault - 10f); } float num4 = (Plugin.ColumnEnabled.Value ? (Plugin.ColumnWidth.Value + 10f) : 0f); float num5 = Mathf.Clamp(num4, 0f, Mathf.Max(2f * val5.x - 40f - val3.sizeDelta.x, 0f)); num5 = ((!(num5 < 130f)) ? Mathf.Max(Mathf.Min(num5, num2 - num - val3.sizeDelta.x), 130f) : 0f); float num6 = val3.sizeDelta.x + num5; float num7 = num + num6 / 2f; float num8 = Mathf.Clamp(val3.anchoredPosition.x, num7, Mathf.Max(num2 - num6 / 2f, num7)); float num9 = MenuDetails.Room(ui); float num10 = val3.anchoredPosition.y + val3.sizeDelta.y / 2f; float num11 = val3.anchoredPosition.y - val3.sizeDelta.y / 2f; float num12 = val5.y - 40f; float num13 = 0f - val5.y + 20f; foreach (var item in HudRects(val, val3.anchoredPosition.y)) { var (val6, _) = item; if (item.above) { num12 = Mathf.Min(num12, ((Rect)(ref val6)).yMin - 10f); } else if (((Rect)(ref val6)).xMax > num8 - num6 / 2f && ((Rect)(ref val6)).xMin < num8 + num6 / 2f) { num13 = Mathf.Max(num13, ((Rect)(ref val6)).yMax + 10f); } } float num14 = Mathf.Clamp(Plugin.MenuExtraHeight.Value, 0f, Mathf.Max(num12 - num10, 0f)); float num15 = Mathf.Clamp(num9, 0f, Mathf.Max(num11 - num13, 0f)); float num16 = num5 - (val.sizeDelta.x - val3.sizeDelta.x); float y = OriginalGrid(ui.m_pieceView).offsetMin.y; ui.m_pieceView.offsetMax = new Vector2(ui.m_pieceView.offsetMax.x, 0f); ui.m_pieceView.offsetMin = new Vector2(ui.m_pieceView.offsetMin.x, y + num9); Vector2 val7 = val3.sizeDelta + new Vector2(num5, num14 + num15); Vector2 val8 = default(Vector2); ((Vector2)(ref val8))..ctor(num8, val3.anchoredPosition.y + (num14 - num15) / 2f); if (val7 != val.sizeDelta || val8 != val.anchoredPosition) { Plugin.Log.LogInfo((object)($"Build menu window {val7.x:0} x {val7.y:0} at {val8.x:0}: column {num5:0} of " + $"{num4:0}, {num14:0} taller of {Plugin.MenuExtraHeight.Value:0}, {num15:0} lower of {num9:0}")); } val.sizeDelta = val7; val.anchoredPosition = val8; if (num16 != 0f) { MakeRoomForColumn(ui, num16); } SearchColumn.Apply(ui, (num5 > 0f) ? (num5 - 10f) : 0f); } private static RectTransform OriginalGrid(RectTransform grid) { //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_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) Transform obj = ((Transform)grid).Find("BetterBuildMenu_OriginalGrid"); RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null); if (val != null) { return val; } GameObject val2 = new GameObject("BetterBuildMenu_OriginalGrid", new Type[1] { typeof(RectTransform) }); val2.SetActive(false); val = (RectTransform)val2.transform; ((Transform)val).SetParent((Transform)(object)grid, false); val.anchorMin = grid.anchorMin; val.anchorMax = grid.anchorMax; val.pivot = grid.pivot; val.anchoredPosition = grid.anchoredPosition; val.sizeDelta = grid.sizeDelta; return val; } private static List<(Rect rect, bool above)> HudRects(RectTransform window, float middle) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown //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_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_009e: 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_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: 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_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_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: 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) //IL_01c0: 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_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01f2: 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_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0201: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_0218: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Unknown result type (might be due to invalid IL or missing references) RectTransform parent = (RectTransform)((Transform)window).parent; List<(Rect, bool)> rects = new List<(Rect, bool)>(); HotkeyBar[] array = Object.FindObjectsByType<HotkeyBar>((FindObjectsSortMode)0); foreach (HotkeyBar val in array) { if (!((Object)(object)val.m_elementPrefab == (Object)null) && ((Behaviour)val).isActiveAndEnabled && val.m_elements.Count != 0) { RectTransform val2 = (RectTransform)val.m_elementPrefab.transform; Rect rect = val2.rect; Vector2 val3 = Vector2.op_Implicit(((Transform)val2).localScale); Add(((Component)val).transform, Vector2.Scale(((Rect)(ref rect)).min, val3), Vector2.Scale(((Rect)(ref rect)).max, val3) + new Vector2((float)(val.m_elements.Count - 1) * val.m_elementSpace, 0f)); } } Hud instance = Hud.instance; RectTransform val4 = instance?.m_statusEffectListRoot; RectTransform val5 = instance?.m_statusEffectTemplate; int num = Mathf.Max(instance?.m_statusEffects.Count ?? 0, 1); if ((Object)(object)val4 != (Object)null && (Object)(object)val5 != (Object)null && ((Component)val4).gameObject.activeInHierarchy) { int num2 = Mathf.Max(instance.m_effectsPerRow, 1); int num3 = (num + num2 - 1) / num2; int num4 = Mathf.Min(num, num2); float statusEffectSpacing = instance.m_statusEffectSpacing; Rect rect2 = val4.rect; Vector2 min = ((Rect)(ref rect2)).min; rec