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 MoreCompanyCosmeticSorter v1.3.1
BepInEx/MoreCompanyCosmeticsSorter/CosmeticsAutoSort.dll
Decompiled 4 days agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using MoreCompany; using MoreCompany.Cosmetics; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("CosmeticsAutoSort")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("CosmeticsAutoSort")] [assembly: AssemblyTitle("CosmeticsAutoSort")] [assembly: AssemblyVersion("1.0.0.0")] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } } namespace CosmeticsAutoSort { [BepInPlugin("potatoh.morecompany.cosmeticsorter", "MoreCompany Cosmetic Sorter", "1.3.0")] public sealed class Plugin : BaseUnityPlugin { public const string ModGuid = "potatoh.morecompany.cosmeticsorter"; public const string ModName = "MoreCompany Cosmetic Sorter"; public const string ModVersion = "1.3.0"; internal static ManualLogSource Log; private void Awake() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; Harmony val = new Harmony("potatoh.morecompany.cosmeticsorter"); val.PatchAll(); Log.LogInfo((object)"MoreCompany Cosmetic Sorter loaded."); } } [HarmonyPatch(typeof(CosmeticRegistry), "PopulateCosmetics")] internal static class PopulateCosmeticsPatch { private enum CosmeticFilter { All, Head, Chest, Hip, Arms, Legs } private static readonly FieldInfo? CosmeticButtonField = AccessTools.Field(typeof(MainClass), "cosmeticButton"); private static readonly MethodInfo? WriteCosmeticsToFileMethod = AccessTools.Method(typeof(MainClass), "WriteCosmeticsToFile", (Type[])null, (Type[])null); private static readonly FieldInfo? CosmeticUiGlobalScaleField = AccessTools.Field(typeof(CosmeticRegistry), "cosmeticUIGlobalScale") ?? AccessTools.Field(typeof(CosmeticRegistry), "cosmeticGUIGlobalScale"); private static CosmeticFilter CurrentFilter = CosmeticFilter.All; private static bool Prefix() { try { RebuildCosmeticsList(); return false; } catch (Exception arg) { Plugin.Log.LogError((object)$"Failed to rebuild cosmetics list: {arg}"); return true; } } private static void RebuildCosmeticsList() { //IL_0220: Unknown result type (might be due to invalid IL or missing references) object? obj = CosmeticUiGlobalScaleField?.GetValue(null); Transform val = (Transform)((obj is Transform) ? obj : null); object obj2; if (val == null) { obj2 = null; } else { Transform obj3 = val.Find("CosmeticsScreen"); if (obj3 == null) { obj2 = null; } else { Transform obj4 = obj3.Find("CosmeticsHolder"); obj2 = ((obj4 != null) ? obj4.Find("Content") : null); } } Transform val2 = (Transform)obj2; if ((Object)(object)val2 == (Object)null) { throw new Exception("Could not find cosmetics content holder."); } object? obj5 = CosmeticButtonField?.GetValue(null); GameObject val3 = (GameObject)((obj5 is GameObject) ? obj5 : null); if ((Object)(object)val3 == (Object)null) { throw new Exception("Could not get MainClass.cosmeticButton."); } ClearChildren(val2); GridLayoutGroup component = ((Component)val2).GetComponent<GridLayoutGroup>(); int gridColumnCount = GetGridColumnCount(component); CreateControlButtons(val2); if (gridColumnCount > 0) { PadGridToNextRow(val2, gridColumnCount); } List<KeyValuePair<string, CosmeticInstance>> list = (from pair in CosmeticRegistry.cosmeticInstances where MatchesCurrentFilter(pair.Value.cosmeticType) orderby GetTypeOrder(pair.Value.cosmeticType) select pair).ThenBy<KeyValuePair<string, CosmeticInstance>, string>((KeyValuePair<string, CosmeticInstance> pair) => pair.Value.cosmeticId, StringComparer.OrdinalIgnoreCase).ToList(); if (list.Count == 0) { CreateEmptyState(val2, gridColumnCount); Plugin.Log.LogInfo((object)$"Rebuilt cosmetics list. Filter: {CurrentFilter}. Count: 0"); return; } if (CurrentFilter == CosmeticFilter.All) { Dictionary<int, int> dictionary = (from pair in list group pair by GetTypeOrder(pair.Value.cosmeticType)).ToDictionary((IGrouping<int, KeyValuePair<string, CosmeticInstance>> group) => group.Key, (IGrouping<int, KeyValuePair<string, CosmeticInstance>> group) => group.Count()); int num = -1; foreach (KeyValuePair<string, CosmeticInstance> item in list) { int typeOrder = GetTypeOrder(item.Value.cosmeticType); if (typeOrder != num) { string groupTitle = GetGroupTitle(typeOrder, dictionary[typeOrder]); CreateGroupHeader(val2, groupTitle, gridColumnCount); num = typeOrder; } CreateCosmeticButton(item.Key, item.Value, val2, val3); } } else { foreach (KeyValuePair<string, CosmeticInstance> item2 in list) { CreateCosmeticButton(item2.Key, item2.Value, val2, val3); } } Plugin.Log.LogInfo((object)$"Rebuilt cosmetics list. Filter: {CurrentFilter}. Count: {list.Count}"); } private static void ClearChildren(Transform parent) { List<Transform> list = new List<Transform>(); for (int i = 0; i < parent.childCount; i++) { list.Add(parent.GetChild(i)); } foreach (Transform item in list) { Object.Destroy((Object)(object)((Component)item).gameObject); } } private static void CreateCosmeticButton(string cosmeticId, CosmeticInstance cosmeticInstance, Transform parent, GameObject cosmeticButtonPrefab) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Expected O, but got Unknown string cosmeticId2 = cosmeticId; GameObject val = Object.Instantiate<GameObject>(cosmeticButtonPrefab, parent); ((Object)val).name = cosmeticId2; val.transform.localScale = Vector3.one; Transform val2 = val.transform.Find("Deselected"); Transform val3 = val.transform.Find("Selected"); Transform val4 = val.transform.Find("Icon"); if ((Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null) { throw new Exception("UI children missing on cosmetic button prefab for " + cosmeticId2 + "."); } GameObject disabledOverlay = ((Component)val2).gameObject; GameObject enabledOverlay = ((Component)val3).gameObject; disabledOverlay.SetActive(true); enabledOverlay.SetActive(true); SetOverlayState(enabledOverlay, disabledOverlay, CosmeticRegistry.IsEquipped(cosmeticId2)); RawImage component = ((Component)val4).GetComponent<RawImage>(); if ((Object)(object)component == (Object)null) { throw new Exception("RawImage missing on Icon for " + cosmeticId2 + "."); } component.texture = (Texture)(object)cosmeticInstance.icon; Button component2 = val.GetComponent<Button>(); if ((Object)(object)component2 == (Object)null) { throw new Exception("Button component missing for " + cosmeticId2 + "."); } ((UnityEventBase)component2.onClick).RemoveAllListeners(); ((UnityEvent)component2.onClick).AddListener((UnityAction)delegate { CosmeticRegistry.ToggleCosmetic(cosmeticId2); bool isEquipped = CosmeticRegistry.IsEquipped(cosmeticId2); SetOverlayState(enabledOverlay, disabledOverlay, isEquipped); WriteCosmeticsToFileMethod?.Invoke(null, null); CosmeticRegistry.UpdateCosmeticsOnDisplayGuy(true); }); } private static void CreateControlButtons(Transform parent) { CosmeticFilter[] array = new CosmeticFilter[6] { CosmeticFilter.All, CosmeticFilter.Head, CosmeticFilter.Chest, CosmeticFilter.Hip, CosmeticFilter.Arms, CosmeticFilter.Legs }; CosmeticFilter[] array2 = array; foreach (CosmeticFilter cosmeticFilter in array2) { CosmeticFilter filterCopy = cosmeticFilter; bool isActive = filterCopy == CurrentFilter; CreateFilterButton(parent, GetFilterTitle(filterCopy), isActive, delegate { CurrentFilter = filterCopy; RebuildCosmeticsList(); }); } CreateDangerButton(parent, "Clear All", delegate { ClearAllEquippedCosmetics(); RebuildCosmeticsList(); }); } private static void ClearAllEquippedCosmetics() { List<string> list = ((IEnumerable<string>)CosmeticRegistry.cosmeticInstances.Keys).Where((Func<string, bool>)CosmeticRegistry.IsEquipped).ToList(); foreach (string item in list) { CosmeticRegistry.ToggleCosmetic(item); } WriteCosmeticsToFileMethod?.Invoke(null, null); CosmeticRegistry.UpdateCosmeticsOnDisplayGuy(true); Plugin.Log.LogInfo((object)$"Clear All used. Removed cosmetics: {list.Count}"); } private static void CreateFilterButton(Transform parent, string title, bool isActive, Action onClick) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0070: 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_0088: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: 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_00ac: 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) Color normalColor = (isActive ? new Color(0.92f, 0.42f, 0.08f, 0.95f) : new Color(0f, 0f, 0f, 0.35f)); Color highlightedColor = (isActive ? new Color(1f, 0.5f, 0.12f, 1f) : new Color(0.15f, 0.15f, 0.15f, 0.45f)); Color pressedColor = (isActive ? new Color(0.78f, 0.32f, 0.05f, 1f) : new Color(0.08f, 0.08f, 0.08f, 0.55f)); CreateActionButton(parent, title, normalColor, highlightedColor, pressedColor, onClick); } private static void CreateDangerButton(Transform parent, string title, Action onClick) { //IL_0017: 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_0049: Unknown result type (might be due to invalid IL or missing references) CreateActionButton(parent, title, new Color(0.62f, 0.08f, 0.08f, 0.95f), new Color(0.78f, 0.12f, 0.12f, 1f), new Color(0.48f, 0.05f, 0.05f, 1f), onClick); } private static void CreateActionButton(Transform parent, string title, Color normalColor, Color highlightedColor, Color pressedColor, Action onClick) { //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown //IL_0063: 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_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: 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_0120: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Expected O, but got Unknown Action onClick2 = onClick; GameObject val = new GameObject("Action_" + title, new Type[3] { typeof(RectTransform), typeof(Image), typeof(Button) }); val.transform.SetParent(parent, false); Image component = val.GetComponent<Image>(); ((Graphic)component).color = normalColor; ((Graphic)component).raycastTarget = true; Button component2 = val.GetComponent<Button>(); ((Selectable)component2).targetGraphic = (Graphic)(object)component; ColorBlock colors = ((Selectable)component2).colors; ((ColorBlock)(ref colors)).normalColor = normalColor; ((ColorBlock)(ref colors)).highlightedColor = highlightedColor; ((ColorBlock)(ref colors)).pressedColor = pressedColor; ((ColorBlock)(ref colors)).selectedColor = highlightedColor; ((ColorBlock)(ref colors)).disabledColor = new Color(0.2f, 0.2f, 0.2f, 0.3f); ((Selectable)component2).colors = colors; CreateHeaderText(val.transform, title, 15, (FontStyle)1, (TextAnchor)4, new Vector2(6f, 4f), new Vector2(-6f, -4f)); ((UnityEventBase)component2.onClick).RemoveAllListeners(); ((UnityEvent)component2.onClick).AddListener((UnityAction)delegate { onClick2(); }); } private static void CreateEmptyState(Transform parent, int gridColumnCount) { if (gridColumnCount > 0) { PadGridToNextRow(parent, gridColumnCount); CreateGridHeaderCell(parent, "No cosmetics in this filter", isMainCell: true); for (int i = 1; i < gridColumnCount; i++) { CreateGridHeaderCell(parent, string.Empty, isMainCell: false); } } else { CreateVerticalHeader(parent, "No cosmetics in this filter"); } } private static int GetGridColumnCount(GridLayoutGroup? gridLayout) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Invalid comparison between Unknown and I4 if ((Object)(object)gridLayout == (Object)null) { return 0; } if ((int)gridLayout.constraint == 1 && gridLayout.constraintCount > 0) { return gridLayout.constraintCount; } return 0; } private static string GetFilterTitle(CosmeticFilter filter) { return filter switch { CosmeticFilter.All => "All", CosmeticFilter.Head => "Head", CosmeticFilter.Chest => "Chest", CosmeticFilter.Hip => "Hip", CosmeticFilter.Arms => "Arms", CosmeticFilter.Legs => "Legs", _ => "All", }; } private static bool MatchesCurrentFilter(CosmeticType type) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Invalid comparison between Unknown and I4 //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Invalid comparison between Unknown and I4 //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Invalid comparison between Unknown and I4 //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Invalid comparison between Unknown and I4 //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Invalid comparison between Unknown and I4 //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Invalid comparison between Unknown and I4 //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Invalid comparison between Unknown and I4 return CurrentFilter switch { CosmeticFilter.All => true, CosmeticFilter.Head => (int)type == 0, CosmeticFilter.Chest => (int)type == 2, CosmeticFilter.Hip => (int)type == 4, CosmeticFilter.Arms => (int)type == 3 || (int)type == 1, CosmeticFilter.Legs => (int)type == 5 || (int)type == 6, _ => true, }; } private static string GetGroupTitle(int group, int count) { return group switch { 0 => $"Head ({count})", 1 => $"Chest ({count})", 2 => $"Hip / Back ({count})", 3 => $"Arms / Wrist ({count})", 4 => $"Legs ({count})", _ => $"Other ({count})", }; } private static void CreateGroupHeader(Transform parent, string title, int gridColumnCount) { if (gridColumnCount > 0) { PadGridToNextRow(parent, gridColumnCount); CreateGridHeaderCell(parent, title, isMainCell: true); for (int i = 1; i < gridColumnCount; i++) { CreateGridHeaderCell(parent, string.Empty, isMainCell: false); } } else { CreateVerticalHeader(parent, title); } } private static void PadGridToNextRow(Transform parent, int gridColumnCount) { int num = parent.childCount % gridColumnCount; if (num != 0) { int num2 = gridColumnCount - num; for (int i = 0; i < num2; i++) { CreateInvisibleGridSpacer(parent); } } } private static void CreateInvisibleGridSpacer(Transform parent) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown GameObject val = new GameObject("Spacer", new Type[1] { typeof(RectTransform) }); val.transform.SetParent(parent, false); } private static void CreateGridHeaderCell(Transform parent, string title, bool isMainCell) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(isMainCell ? ("Header_" + title) : "HeaderFill", new Type[2] { typeof(RectTransform), typeof(Image) }); val.transform.SetParent(parent, false); Image component = val.GetComponent<Image>(); ((Graphic)component).color = (isMainCell ? new Color(0f, 0f, 0f, 0.42f) : new Color(0f, 0f, 0f, 0.22f)); ((Graphic)component).raycastTarget = false; if (!string.IsNullOrWhiteSpace(title)) { CreateHeaderText(val.transform, title, 18, (FontStyle)1, (TextAnchor)3, new Vector2(10f, 4f), new Vector2(-6f, -4f)); } } private static void CreateVerticalHeader(Transform parent, string title) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown //IL_0094: 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_00cb: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("Header_" + title, new Type[3] { typeof(RectTransform), typeof(LayoutElement), typeof(Image) }); val.transform.SetParent(parent, false); LayoutElement component = val.GetComponent<LayoutElement>(); component.preferredHeight = 34f; component.minHeight = 34f; component.flexibleWidth = 1f; Image component2 = val.GetComponent<Image>(); ((Graphic)component2).color = new Color(0f, 0f, 0f, 0.35f); ((Graphic)component2).raycastTarget = false; CreateHeaderText(val.transform, title, 18, (FontStyle)1, (TextAnchor)3, new Vector2(12f, 4f), new Vector2(-12f, -4f)); } private static void CreateHeaderText(Transform parent, string title, int fontSize, FontStyle fontStyle, TextAnchor anchor, Vector2 offsetMin, Vector2 offsetMax) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0094: 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_00b9: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("Text", new Type[2] { typeof(RectTransform), typeof(Text) }); val.transform.SetParent(parent, false); RectTransform component = val.GetComponent<RectTransform>(); component.anchorMin = Vector2.zero; component.anchorMax = Vector2.one; component.offsetMin = offsetMin; component.offsetMax = offsetMax; Text component2 = val.GetComponent<Text>(); component2.text = title; component2.font = Resources.GetBuiltinResource<Font>("Arial.ttf"); component2.fontSize = fontSize; component2.fontStyle = fontStyle; component2.alignment = anchor; ((Graphic)component2).color = new Color(0.95f, 0.95f, 0.95f, 1f); ((Graphic)component2).raycastTarget = false; component2.resizeTextForBestFit = true; component2.resizeTextMinSize = 10; component2.resizeTextMaxSize = fontSize; } private static void SetOverlayState(GameObject enabledOverlay, GameObject disabledOverlay, bool isEquipped) { enabledOverlay.SetActive(isEquipped); disabledOverlay.SetActive(!isEquipped); } private static int GetTypeOrder(CosmeticType type) { //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_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected I4, but got Unknown switch ((int)type) { case 0: return 0; case 2: return 1; case 4: return 2; case 1: case 3: return 3; case 5: case 6: return 4; default: return 999; } } } }