Decompiled source of Cosmetic Menu v1.0.0

Mods/CosmeticMenu.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using CosmeticMenu;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Bonelab;
using Il2CppSLZ.Marrow.Data;
using Il2CppSLZ.Marrow.Pool;
using Il2CppTMPro;
using LabFusion.Marrow;
using LabFusion.Marrow.Pool;
using LabFusion.Marrow.Proxies;
using LabFusion.Menu;
using MelonLoader;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(CosmeticMenuMod), "CosmeticMenu", "1.0.0", "CosmeticMenuAuthor", null)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace CosmeticMenu;

public static class CatalogPanel
{
	internal static GameObject CachedCatalogClone;

	internal static bool IsActive;

	internal static GameObject ProfilePanel;

	internal static MenuPage ProfilePage;

	internal static bool IsCatalogUiInitialized;

	internal static bool AreButtonsPopulated;

	private const float CloseButtonSize = 45f;

	private const float CloseButtonOffset = 35f;

	private const int ToolbarLeftPadding = 85;

	private const int ToolbarRightPadding = 30;

	private static GameObject _overlayRoot;

	private static bool _spawning;

	private static void SetCachedCatalog(GameObject catalog)
	{
		CachedCatalogClone = catalog;
		IsCatalogUiInitialized = false;
		AreButtonsPopulated = false;
		IsActive = false;
	}

	public static void Toggle(GameObject menuRoot)
	{
		if (IsActive)
		{
			Hide();
		}
		else
		{
			Show(menuRoot);
		}
	}

	private static void Show(GameObject menuRoot)
	{
		if ((Object)(object)CachedCatalogClone != (Object)null)
		{
			ShowCached(menuRoot);
			return;
		}
		BitMart val = Object.FindObjectOfType<BitMart>();
		if ((Object)(object)val != (Object)null && (Object)(object)val.BitMartElement != (Object)null)
		{
			Transform val2 = ((Component)val.BitMartElement).transform.Find("panel_BitCatalog");
			if ((Object)(object)val2 != (Object)null)
			{
				SetCachedCatalog(Object.Instantiate<GameObject>(((Component)val2).gameObject));
				CachedCatalogClone.SetActive(true);
				ShowCached(menuRoot);
				return;
			}
		}
		SpawnTemporaryBitMart(menuRoot);
	}

	private static void SpawnTemporaryBitMart(GameObject menuRoot)
	{
		//IL_003d: 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)
		if (_spawning)
		{
			return;
		}
		_spawning = true;
		MelonLogger.Msg("[CosmeticMenu] No BitMart in scene, spawning temporary one to get catalog...");
		ShowLoadingOverlay(menuRoot);
		try
		{
			Spawnable obj = LocalAssetSpawner.CreateSpawnable(FusionSpawnableReferences.BitMartReference);
			LocalAssetSpawner.Register(obj);
			LocalAssetSpawner.Spawn(obj, new Vector3(0f, -10000f, 0f), Quaternion.identity, (Action<Poolee>)OnTemporaryBitMartSpawned);
		}
		catch (Exception value)
		{
			MelonLogger.Error($"[CosmeticMenu] Failed to spawn temporary BitMart: {value}");
			_spawning = false;
			ClearOverlay();
		}
	}

	private static void OnTemporaryBitMartSpawned(Poolee poolee)
	{
		try
		{
			GameObject val = ((poolee != null) ? ((Component)poolee).gameObject : null);
			if ((Object)(object)val == (Object)null)
			{
				MelonLogger.Warning("[CosmeticMenu] Temporary BitMart spawn returned null.");
				_spawning = false;
				return;
			}
			BitMart component = val.GetComponent<BitMart>();
			if ((Object)(object)component == (Object)null || (Object)(object)component.BitMartElement == (Object)null)
			{
				MelonLogger.Warning("[CosmeticMenu] Temporary BitMart has no elements.");
				Object.Destroy((Object)(object)val);
				_spawning = false;
				return;
			}
			Transform val2 = ((Component)component.BitMartElement).transform.Find("panel_BitCatalog");
			if ((Object)(object)val2 == (Object)null)
			{
				MelonLogger.Warning("[CosmeticMenu] Temporary BitMart has no catalog panel.");
				Object.Destroy((Object)(object)val);
				_spawning = false;
				return;
			}
			SetCachedCatalog(Object.Instantiate<GameObject>(((Component)val2).gameObject));
			CachedCatalogClone.SetActive(true);
			Object.Destroy((Object)(object)val);
			MelonLogger.Msg("[CosmeticMenu] Catalog cloned from temporary BitMart.");
			GameObject menuGameObject = MenuCreator.MenuGameObject;
			if ((Object)(object)menuGameObject != (Object)null)
			{
				ClearOverlay();
				ShowCached(menuGameObject);
			}
			_spawning = false;
		}
		catch (Exception value)
		{
			MelonLogger.Error($"[CosmeticMenu] Error cloning catalog from temp BitMart: {value}");
			_spawning = false;
		}
	}

	private static void ShowCached(GameObject menuRoot)
	{
		if (!((Object)(object)CachedCatalogClone == (Object)null))
		{
			ClearOverlay();
			if ((Object)(object)CachedCatalogClone.transform.parent != (Object)(object)menuRoot.transform)
			{
				CachedCatalogClone.transform.SetParent(menuRoot.transform, false);
				UiHelpers.StretchFull(CachedCatalogClone.GetComponent<RectTransform>());
			}
			if (!AreButtonsPopulated)
			{
				UiHelpers.RemoveButtonHoverClicks(CachedCatalogClone);
				MenuButtonHelper.PopulateButtons(CachedCatalogClone);
				AreButtonsPopulated = true;
			}
			BitCatalogElement component = CachedCatalogClone.GetComponent<BitCatalogElement>();
			if ((Object)(object)component != (Object)null)
			{
				SetupCatalogUI(component);
			}
			MenuPage component2 = CachedCatalogClone.GetComponent<MenuPage>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.ShowPage();
			}
			if ((Object)(object)ProfilePanel != (Object)null)
			{
				ProfilePanel.SetActive(false);
			}
			IsActive = true;
			MelonLogger.Msg("[CosmeticMenu] Cosmetics catalog shown (Inventory tab).");
		}
	}

	private static void SetupCatalogUI(BitCatalogElement catalogElement)
	{
		if (!IsCatalogUiInitialized)
		{
			if ((Object)(object)catalogElement.ShopElement != (Object)null)
			{
				((Component)catalogElement.ShopElement).gameObject.SetActive(false);
			}
			MenuPage browserPage = catalogElement.BrowserPage;
			Transform obj = ((browserPage != null) ? ((Component)browserPage).transform.Find("group_Toolbars") : null);
			Transform val = ((obj != null) ? obj.Find("layout_Tabs") : null);
			HorizontalLayoutGroup layoutTabsHlg = ((val != null) ? ((Component)val).GetComponent<HorizontalLayoutGroup>() : null);
			if ((Object)(object)catalogElement.CatalogCloseElement != (Object)null && (Object)(object)val != (Object)null)
			{
				SetupCloseButton(catalogElement.CatalogCloseElement, val, layoutTabsHlg);
			}
			if ((Object)(object)catalogElement.InventoryElement != (Object)null)
			{
				SetupInventoryLabel(catalogElement.InventoryElement, val);
			}
			if ((Object)(object)val != (Object)null)
			{
				SetupToolbarButtons(catalogElement, val);
			}
			if ((Object)(object)catalogElement.CatalogBitCountText != (Object)null && (Object)(object)catalogElement.CatalogUnequipAllElement != (Object)null)
			{
				SetupBitCount(catalogElement);
			}
			IsCatalogUiInitialized = true;
		}
		FunctionElement inventoryElement = catalogElement.InventoryElement;
		if (inventoryElement != null)
		{
			inventoryElement.Press();
		}
	}

	private static void SetupCloseButton(FunctionElement closeElement, Transform layoutTabs, HorizontalLayoutGroup layoutTabsHlg)
	{
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Expected O, but got Unknown
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Expected O, but got Unknown
		((Component)closeElement).transform.SetParent(layoutTabs, false);
		((Component)closeElement).transform.SetAsFirstSibling();
		LayoutElement component = ((Component)closeElement).GetComponent<LayoutElement>();
		if ((Object)(object)component != (Object)null)
		{
			component.ignoreLayout = true;
			component.minWidth = 45f;
			component.preferredWidth = 45f;
			component.minHeight = 45f;
			component.preferredHeight = 45f;
			component.flexibleWidth = 0f;
			component.flexibleHeight = 0f;
		}
		RectTransform component2 = ((Component)closeElement).GetComponent<RectTransform>();
		if ((Object)(object)component2 != (Object)null)
		{
			component2.anchorMin = new Vector2(0f, 0.5f);
			component2.anchorMax = new Vector2(0f, 0.5f);
			component2.pivot = new Vector2(0f, 0.5f);
			component2.sizeDelta = new Vector2(45f, 45f);
			component2.anchoredPosition = new Vector2(35f, 0f);
		}
		Transform val = ((Component)closeElement).transform.Find("Collider");
		if ((Object)(object)val != (Object)null)
		{
			UiHelpers.StretchFull(((Component)val).GetComponent<RectTransform>());
		}
		if ((Object)(object)layoutTabsHlg != (Object)null)
		{
			((LayoutGroup)layoutTabsHlg).padding = new RectOffset(85, 30, 0, 0);
		}
		closeElement.OnPressed = null;
		closeElement.OnPressed = (Action)Delegate.Combine(closeElement.OnPressed, new Action(Hide));
		Button component3 = ((Component)closeElement).GetComponent<Button>();
		if ((Object)(object)component3 != (Object)null)
		{
			component3.onClick = new ButtonClickedEvent();
			((UnityEvent)component3.onClick).AddListener(UnityAction.op_Implicit((Action)Hide));
		}
		MelonLogger.Msg("[CosmeticMenu] Close button rewired: OnPressed=" + (closeElement.OnPressed != null));
	}

	private static void SetupInventoryLabel(FunctionElement invElement, Transform layoutTabs)
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Expected O, but got Unknown
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		((MenuElement)invElement).Title = "Inventory";
		if ((Object)(object)layoutTabs != (Object)null)
		{
			((Component)invElement).transform.SetParent(layoutTabs, false);
			((Component)invElement).transform.SetSiblingIndex(1);
		}
		Button component = ((Component)invElement).gameObject.GetComponent<Button>();
		if ((Object)(object)component != (Object)null)
		{
			component.onClick = new ButtonClickedEvent();
			((Selectable)component).interactable = false;
			((Behaviour)component).enabled = false;
		}
		Collider component2 = ((Component)invElement).gameObject.GetComponent<Collider>();
		if ((Object)(object)component2 != (Object)null)
		{
			component2.enabled = false;
		}
		TintBackground(((Component)invElement).transform, new Color(0.15f, 0.15f, 0.15f, 0.85f));
		UiHelpers.ConfigureToolbarButton(((Component)invElement).gameObject, 90f, 40f);
	}

	private static void SetupToolbarButtons(BitCatalogElement catalogElement, Transform layoutTabs)
	{
		if ((Object)(object)catalogElement.CatalogSortByElement != (Object)null)
		{
			((Component)catalogElement.CatalogSortByElement).transform.SetParent(layoutTabs, false);
			UiHelpers.ConfigureToolbarButton(((Component)catalogElement.CatalogSortByElement).gameObject, 85f, 40f);
		}
		if ((Object)(object)catalogElement.CatalogUnequipAllElement != (Object)null)
		{
			((Component)catalogElement.CatalogUnequipAllElement).transform.SetParent(layoutTabs, false);
			UiHelpers.ConfigureToolbarButton(((Component)catalogElement.CatalogUnequipAllElement).gameObject, 110f, 40f);
		}
		RectTransform component = ((Component)layoutTabs).GetComponent<RectTransform>();
		if ((Object)(object)component != (Object)null)
		{
			LayoutRebuilder.ForceRebuildLayoutImmediate(component);
		}
	}

	private static void SetupBitCount(BitCatalogElement catalogElement)
	{
		//IL_0048: 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_0072: 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_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Expected O, but got Unknown
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		GameObject gameObject = ((Component)catalogElement.CatalogBitCountText.transform.parent).gameObject;
		gameObject.transform.SetParent(((Component)catalogElement.CatalogUnequipAllElement).transform, false);
		RectTransform component = gameObject.GetComponent<RectTransform>();
		if ((Object)(object)component != (Object)null)
		{
			component.anchorMin = new Vector2(0f, 1f);
			component.anchorMax = new Vector2(1f, 1f);
			component.pivot = new Vector2(0.5f, 1f);
			component.sizeDelta = new Vector2(10f, 25f);
			component.anchoredPosition = new Vector2(0f, 27f);
		}
		LayoutElement component2 = gameObject.GetComponent<LayoutElement>();
		if ((Object)(object)component2 != (Object)null)
		{
			((Behaviour)component2).enabled = false;
		}
		HorizontalLayoutGroup component3 = gameObject.GetComponent<HorizontalLayoutGroup>();
		if ((Object)(object)component3 != (Object)null)
		{
			((HorizontalOrVerticalLayoutGroup)component3).childForceExpandWidth = false;
			((HorizontalOrVerticalLayoutGroup)component3).childForceExpandHeight = false;
			((HorizontalOrVerticalLayoutGroup)component3).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)component3).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)component3).spacing = 4f;
			((LayoutGroup)component3).padding = new RectOffset(4, 4, 2, 2);
			((LayoutGroup)component3).childAlignment = (TextAnchor)4;
		}
		Image val = gameObject.GetComponent<Image>();
		if ((Object)(object)val == (Object)null)
		{
			val = gameObject.AddComponent<Image>();
		}
		((Graphic)val).color = new Color(0.15f, 0.15f, 0.15f, 0.85f);
		if ((Object)(object)catalogElement.CatalogBitCountText != (Object)null)
		{
			catalogElement.CatalogBitCountText.alignment = (TextAlignmentOptions)514;
		}
		Transform val2 = gameObject.transform.Find("icon_Bit");
		if ((Object)(object)val2 != (Object)null)
		{
			RectTransform component4 = ((Component)val2).GetComponent<RectTransform>();
			if ((Object)(object)component4 != (Object)null)
			{
				component4.sizeDelta = new Vector2(20f, 20f);
			}
			LayoutElement component5 = ((Component)val2).GetComponent<LayoutElement>();
			if ((Object)(object)component5 != (Object)null)
			{
				component5.preferredWidth = 20f;
				component5.preferredHeight = 20f;
				component5.minWidth = 20f;
				component5.minHeight = 20f;
			}
		}
	}

	public static void Hide()
	{
		if (IsActive)
		{
			if ((Object)(object)CachedCatalogClone != (Object)null)
			{
				CachedCatalogClone.SetActive(false);
			}
			ClearOverlay();
			IsActive = false;
			if ((Object)(object)ProfilePanel != (Object)null)
			{
				ProfilePanel.SetActive(true);
			}
			MelonLogger.Msg("[CosmeticMenu] Cosmetics catalog hidden.");
		}
	}

	internal static void UpdateInventoryButton(FunctionElement invElement, bool isResults, BitCatalogElement catalog)
	{
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)invElement == (Object)null)
		{
			return;
		}
		BitCatalogElement obj = catalog;
		if ((Object)(object)((obj != null) ? obj.BrowserPage : null) == (Object)null)
		{
			return;
		}
		Button component = ((Component)invElement).gameObject.GetComponent<Button>();
		Collider component2 = ((Component)invElement).gameObject.GetComponent<Collider>();
		if (isResults)
		{
			((MenuElement)invElement).Title = "Back";
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = true;
				((Selectable)component).interactable = true;
				component.onClick = new ButtonClickedEvent();
				((UnityEvent)component.onClick).AddListener(UnityAction.op_Implicit((Action)delegate
				{
					catalog.BrowserPage.SelectSubPage(catalog.BitPalletsPage);
				}));
			}
			if ((Object)(object)component2 != (Object)null)
			{
				component2.enabled = true;
			}
		}
		else
		{
			((MenuElement)invElement).Title = "Inventory";
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = false;
				((Selectable)component).interactable = false;
			}
			if ((Object)(object)component2 != (Object)null)
			{
				component2.enabled = false;
			}
		}
		TintBackground(((Component)invElement).transform, new Color(0.15f, 0.15f, 0.15f, 0.85f));
	}

	private static void TintBackground(Transform elementTransform, Color color)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		Transform val = elementTransform.Find("background");
		if (!((Object)(object)val == (Object)null))
		{
			Image component = ((Component)val).GetComponent<Image>();
			if (!((Object)(object)component == (Object)null))
			{
				((Behaviour)component).enabled = true;
				((Graphic)component).color = color;
			}
		}
	}

	private static void ShowLoadingOverlay(GameObject menuRoot)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Expected O, but got Unknown
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: 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_007a: 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_008f: 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)
		_overlayRoot = new GameObject("CosmeticMenuOverlay");
		_overlayRoot.transform.SetParent(menuRoot.transform, false);
		UiHelpers.StretchFull(_overlayRoot.AddComponent<RectTransform>());
		GameObject val = new GameObject("LoadingText");
		val.transform.SetParent(_overlayRoot.transform, false);
		RectTransform obj = val.AddComponent<RectTransform>();
		obj.anchorMin = new Vector2(0.3f, 0.45f);
		obj.anchorMax = new Vector2(0.7f, 0.55f);
		obj.sizeDelta = Vector2.zero;
		obj.anchoredPosition = Vector2.zero;
		TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>();
		((TMP_Text)val2).text = "Loading cosmetics...";
		((TMP_Text)val2).fontSize = 24f;
		((TMP_Text)val2).alignment = (TextAlignmentOptions)514;
		((Graphic)val2).color = Color.white;
		TMP_FontAsset val3 = UiHelpers.FindFont();
		if ((Object)(object)val3 != (Object)null)
		{
			((TMP_Text)val2).font = val3;
		}
	}

	private static void ClearOverlay()
	{
		if (!((Object)(object)_overlayRoot == (Object)null))
		{
			Object.Destroy((Object)(object)_overlayRoot);
			_overlayRoot = null;
		}
	}
}
public class CosmeticMenuMod : MelonMod
{
	private static Harmony _harmony;

	public override void OnInitializeMelon()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Expected O, but got Unknown
		_harmony = new Harmony("com.cosmeticmenu.fusionaddon");
		_harmony.PatchAll();
		((MelonBase)this).LoggerInstance.Msg("CosmeticMenu initialized! Harmony patches applied.");
	}

	public override void OnDeinitializeMelon()
	{
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}
}
[HarmonyPatch(typeof(MenuPageHelper), "PopulatePages")]
public static class CosmeticsButtonPatch
{
	private const string WrapperName = "button_Cosmetics_Wrapper";

	private const string ButtonName = "button_Cosmetics";

	private static readonly Vector2 ButtonSize = new Vector2(220f, 55f);

	private static readonly Vector2 ButtonAnchoredPosition = new Vector2(-5f, -55f);

	[HarmonyPostfix]
	public static void PopulatePagesPostfix(GameObject root)
	{
		try
		{
			AddCosmeticsButton(root);
		}
		catch (Exception value)
		{
			MelonLogger.Error($"[CosmeticMenu] Failed to add cosmetics button: {value}");
		}
	}

	private static void AddCosmeticsButton(GameObject root)
	{
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Expected O, but got Unknown
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: 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)
		Transform val = root.transform.Find("page_Profile");
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		Transform val2 = val.Find("panel_Profile");
		if ((Object)(object)val2 == (Object)null)
		{
			return;
		}
		Transform val3 = val2.Find("panel_Main");
		if ((Object)(object)val3 == (Object)null)
		{
			return;
		}
		Transform val4 = val3.Find("grid_PlayerOptions");
		if ((Object)(object)val4 == (Object)null || (Object)(object)val3.Find("button_Cosmetics_Wrapper") != (Object)null)
		{
			return;
		}
		GameObject val5 = FindButtonTemplate(root);
		if ((Object)(object)val5 == (Object)null)
		{
			MelonLogger.Warning("[CosmeticMenu] Could not find button template to clone.");
			return;
		}
		GameObject obj = Object.Instantiate<GameObject>(val5, val4, false);
		((Object)obj).name = "button_Cosmetics";
		obj.SetActive(true);
		ConfigureButtonText(obj);
		ConfigureButtonLayout(obj);
		WireButtonClick(obj, root);
		GameObject val6 = new GameObject("button_Cosmetics_Wrapper");
		val6.transform.SetParent(val3, false);
		RectTransform obj2 = val6.AddComponent<RectTransform>();
		obj2.anchorMin = new Vector2(0.5f, 0.5f);
		obj2.anchorMax = new Vector2(0.5f, 0.5f);
		obj2.pivot = new Vector2(0.5f, 0.5f);
		obj2.sizeDelta = ButtonSize;
		obj2.anchoredPosition = ButtonAnchoredPosition;
		HorizontalLayoutGroup obj3 = val6.AddComponent<HorizontalLayoutGroup>();
		((LayoutGroup)obj3).childAlignment = (TextAnchor)4;
		((HorizontalOrVerticalLayoutGroup)obj3).childControlWidth = false;
		((HorizontalOrVerticalLayoutGroup)obj3).childControlHeight = false;
		((HorizontalOrVerticalLayoutGroup)obj3).childForceExpandWidth = false;
		((HorizontalOrVerticalLayoutGroup)obj3).childForceExpandHeight = false;
		obj.transform.SetParent(val6.transform, false);
		RectTransform component = obj.GetComponent<RectTransform>();
		if ((Object)(object)component != (Object)null)
		{
			component.anchorMin = new Vector2(0.5f, 0.5f);
			component.anchorMax = new Vector2(0.5f, 0.5f);
			component.pivot = new Vector2(0.5f, 0.5f);
			component.sizeDelta = ButtonSize;
			component.anchoredPosition = Vector2.zero;
		}
		CatalogPanel.ProfilePanel = ((Component)val3).gameObject;
		CatalogPanel.ProfilePage = ((Component)val).GetComponent<MenuPage>();
		MelonLogger.Msg("[CosmeticMenu] Cosmetics button added.");
	}

	private static void ConfigureButtonText(GameObject cosmeticsButton)
	{
		StringElement component = cosmeticsButton.GetComponent<StringElement>();
		if ((Object)(object)component != (Object)null)
		{
			component.Value = " ";
			((LabelElement)component).TextFormat = "{0}";
			((MenuElement)component).Title = "Cosmetics";
		}
		TMP_Text componentInChildren = cosmeticsButton.GetComponentInChildren<TMP_Text>();
		if (!((Object)(object)componentInChildren == (Object)null))
		{
			TMP_FontAsset val = UiHelpers.FindFont();
			if ((Object)(object)val != (Object)null)
			{
				componentInChildren.font = val;
			}
			componentInChildren.enableAutoSizing = true;
			componentInChildren.fontSizeMin = 10f;
			componentInChildren.fontSizeMax = 24f;
			componentInChildren.alignment = (TextAlignmentOptions)514;
		}
	}

	private static void ConfigureButtonLayout(GameObject cosmeticsButton)
	{
		LayoutElement component = cosmeticsButton.GetComponent<LayoutElement>();
		if ((Object)(object)component != (Object)null)
		{
			component.minHeight = 40f;
			component.preferredHeight = 40f;
		}
	}

	private static void WireButtonClick(GameObject cosmeticsButton, GameObject menuRoot)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Expected O, but got Unknown
		Button component = cosmeticsButton.GetComponent<Button>();
		if (!((Object)(object)component == (Object)null))
		{
			component.onClick = new ButtonClickedEvent();
			((UnityEvent)component.onClick).AddListener(UnityAction.op_Implicit((Action)delegate
			{
				CatalogPanel.Toggle(menuRoot);
			}));
		}
	}

	private static GameObject FindButtonTemplate(GameObject menuRoot)
	{
		Transform val = menuRoot.transform.Find("page_Profile/panel_Profile/panel_Main/grid_PlayerInfo/button_Nickname");
		if ((Object)(object)val != (Object)null)
		{
			return ((Component)val).gameObject;
		}
		Transform val2 = menuRoot.transform.Find("page_Profile/panel_Profile/panel_Main/grid_PlayerInfo/button_Description");
		if ((Object)(object)val2 != (Object)null)
		{
			return ((Component)val2).gameObject;
		}
		return null;
	}
}
[HarmonyPatch(typeof(MenuPage), "SelectSubPage", new Type[] { typeof(MenuPage) })]
public static class MenuPageSelectSubPagePatch
{
	[HarmonyPostfix]
	public static void SelectSubPagePostfix(MenuPage __instance, MenuPage page)
	{
		try
		{
			if (!((Object)(object)CatalogPanel.CachedCatalogClone == (Object)null))
			{
				BitCatalogElement component = CatalogPanel.CachedCatalogClone.GetComponent<BitCatalogElement>();
				if (!((Object)(object)component == (Object)null) && !((Object)(object)component.BrowserPage == (Object)null) && !((Object)(object)component.InventoryElement == (Object)null) && !((Object)(object)__instance != (Object)(object)component.BrowserPage))
				{
					bool isResults = (Object)(object)component.BitResultsPage != (Object)null && (Object)(object)page == (Object)(object)component.BitResultsPage;
					CatalogPanel.UpdateInventoryButton(component.InventoryElement, isResults, component);
				}
			}
		}
		catch (Exception ex)
		{
			MelonLogger.Warning("[CosmeticMenu] MenuPage.SelectSubPage postfix error: " + ex.Message);
		}
	}
}
[HarmonyPatch(typeof(MenuPage), "ShowPage")]
public static class MenuPageShowPagePatch
{
	[HarmonyPostfix]
	public static void ShowPagePostfix(MenuPage __instance)
	{
		try
		{
			if (CatalogPanel.IsActive && (!((Object)(object)CatalogPanel.CachedCatalogClone != (Object)null) || !((Component)__instance).transform.IsChildOf(CatalogPanel.CachedCatalogClone.transform)))
			{
				Transform parent = ((Component)__instance).transform.parent;
				if (!((Object)(object)parent == (Object)null) && !((Object)(object)((Component)parent).GetComponentInParent<Canvas>() == (Object)null) && (!((Object)(object)CatalogPanel.ProfilePage != (Object)null) || !((Object)(object)__instance == (Object)(object)CatalogPanel.ProfilePage)))
				{
					CatalogPanel.Hide();
				}
			}
		}
		catch (Exception ex)
		{
			MelonLogger.Warning("[CosmeticMenu] MenuPage.ShowPage postfix error: " + ex.Message);
		}
	}
}
public static class UiHelpers
{
	private static TMP_FontAsset _cachedFont;

	public static TMP_FontAsset FindFont()
	{
		if ((Object)(object)_cachedFont != (Object)null)
		{
			return _cachedFont;
		}
		Il2CppArrayBase<TMP_FontAsset> val = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
		foreach (TMP_FontAsset item in val)
		{
			if (((Object)item).name.ToLowerInvariant().Contains("arlon-medium"))
			{
				_cachedFont = item;
				return _cachedFont;
			}
		}
		_cachedFont = ((val.Length > 0) ? val[0] : null);
		return _cachedFont;
	}

	public static void StretchFull(RectTransform rect)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: 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)
		rect.anchorMin = Vector2.zero;
		rect.anchorMax = Vector2.one;
		rect.pivot = new Vector2(0.5f, 0.5f);
		rect.sizeDelta = Vector2.zero;
		rect.anchoredPosition = Vector2.zero;
	}

	public static void ConfigureToolbarButton(GameObject buttonGo, float width, float height)
	{
		LayoutElement component = buttonGo.GetComponent<LayoutElement>();
		if ((Object)(object)component != (Object)null)
		{
			component.ignoreLayout = false;
			component.minWidth = width;
			component.preferredWidth = width;
			component.minHeight = height;
			component.preferredHeight = height;
			component.flexibleWidth = 0f;
			component.flexibleHeight = 0f;
		}
		Transform val = buttonGo.transform.Find("Collider");
		if ((Object)(object)val != (Object)null)
		{
			RectTransform component2 = ((Component)val).GetComponent<RectTransform>();
			if ((Object)(object)component2 != (Object)null)
			{
				StretchFull(component2);
			}
		}
	}

	public static void RemoveButtonHoverClicks(GameObject root)
	{
		foreach (Button componentsInChild in root.GetComponentsInChildren<Button>(true))
		{
			foreach (ButtonHoverClick component in ((Component)componentsInChild).gameObject.GetComponents<ButtonHoverClick>())
			{
				if ((Object)(object)component != (Object)null)
				{
					Object.Destroy((Object)(object)component);
				}
			}
		}
	}
}