using 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.Configuration;
using BepInEx.Logging;
using BepInEx.NET.Common;
using BepInExResoniteShim;
using BepisLocaleLoader;
using FrooxEngine;
using FrooxEngine.UIX;
using HarmonyLib;
using SkyFrost.Base;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0")]
[assembly: AssemblyCompany("LeCloutPanda")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+c1fcb76e6a2bf8553526508566d875c3be9773c6")]
[assembly: AssemblyProduct("ContactSorter")]
[assembly: AssemblyTitle("ContactSorter")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/lecloutpanda/ContactSorter")]
[assembly: AssemblyVersion("1.1.0.0")]
[module: RefSafetyRules(11)]
namespace ContactSorter;
[ResonitePlugin("dev.lecloutpanda.contactsorter", "ContactSorter", "1.1.0", "LeCloutPanda", "https://github.com/lecloutpanda/ContactSorter")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
[HarmonyPatch(typeof(ContactsDialog))]
private static class ContactsDialogPatches
{
[HarmonyPatch("OnCommonUpdate")]
[HarmonyPrefix]
private static void Prefix(ContactsDialog __instance, SyncRef<TextField> ____searchBar, ref bool ___sortList, out bool __state)
{
__state = ___sortList;
if (ENABLED.Value && Utility.IsNullOrWhiteSpace(____searchBar.Target.TargetString))
{
___sortList = false;
}
}
[HarmonyPatch("OnCommonUpdate")]
[HarmonyPostfix]
private static void Postfix(ContactsDialog __instance, SyncRef<Slot> ____listRoot, SyncRef<TextField> ____searchBar, ref bool ___sortList, bool __state)
{
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Expected O, but got Unknown
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
SyncRef<Slot> ____listRoot2 = ____listRoot;
if (!ENABLED.Value || !__state || !WorldExtensions.IsUserspace(((Worker)__instance).World) || !Utility.IsNullOrWhiteSpace(____searchBar.Target.TargetString))
{
return;
}
try
{
((Component)__instance).Slot.RunInUpdates(3, (Action)delegate
{
//IL_0049: 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_0052: Unknown result type (might be due to invalid IL or missing references)
List<ContactItem> val = SortContacts(((SyncElement)____listRoot2).Slot.GetComponentsInChildren<ContactItem>((Predicate<ContactItem>)null, false, false, (Predicate<Slot>)null));
for (int i = 0; i < val.Count; i++)
{
ContactItem val2 = val[i];
((Component)val2).Slot.OrderOffset = (long)i * 100L;
if (val2.Data.CurrentStatus.OnlineStatus == (OnlineStatus?)0)
{
((Component)val2).Slot[0].ActiveSelf = SHOW_OFFLINE_CONTACTS.Value;
((ComponentBase<Component>)(object)((ContainerWorker<Component>)(object)((Component)val2).Slot).GetComponent<LayoutElement>((Predicate<LayoutElement>)null, false)).Enabled = SHOW_OFFLINE_CONTACTS.Value;
}
}
});
}
catch
{
___sortList = true;
}
}
}
internal static ManualLogSource? Log;
private static ConfigEntry<bool> ENABLED;
private static ConfigEntry<bool> ALPHABETICAL_SORT;
private static ConfigEntry<bool> SHOW_OFFLINE_CONTACTS;
private static ConfigEntry<int> MESSAGED_PRIORITY;
private static ConfigEntry<int> PINNED_PRIORITY;
private static ConfigEntry<int> RESONITE_PRIORITY;
private static ConfigEntry<int> SELF_PRIORITY;
private static ConfigEntry<int> SOCIABLE_PRIORITY;
private static ConfigEntry<int> ONLINE_PRIORITY;
private static ConfigEntry<int> BUSY_PRIORITY;
private static ConfigEntry<int> AWAY_PRIORITY;
private static ConfigEntry<int> OFFLINE_PRIORITY;
private static ConfigEntry<int> HEADLESS_PRIORITY;
private static ConfigEntry<int> CONTACT_REQUEST_ORDER;
private static ConfigEntry<string> PINNED_CONTACTS;
public override void Load()
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Expected O, but got Unknown
//IL_0082: 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_0097: Expected O, but got Unknown
//IL_00c5: 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_00da: Expected O, but got Unknown
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Expected O, but got Unknown
//IL_0153: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
//IL_0168: Expected O, but got Unknown
//IL_019a: Unknown result type (might be due to invalid IL or missing references)
//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
//IL_01af: Expected O, but got Unknown
//IL_01de: Unknown result type (might be due to invalid IL or missing references)
//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
//IL_01f3: Expected O, but got Unknown
//IL_0222: Unknown result type (might be due to invalid IL or missing references)
//IL_022d: Unknown result type (might be due to invalid IL or missing references)
//IL_0237: Expected O, but got Unknown
//IL_0266: Unknown result type (might be due to invalid IL or missing references)
//IL_0271: Unknown result type (might be due to invalid IL or missing references)
//IL_027b: Expected O, but got Unknown
//IL_02aa: 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_02bf: Expected O, but got Unknown
//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
//IL_0303: Expected O, but got Unknown
//IL_0332: Unknown result type (might be due to invalid IL or missing references)
//IL_033d: Unknown result type (might be due to invalid IL or missing references)
//IL_0347: Expected O, but got Unknown
//IL_0376: Unknown result type (might be due to invalid IL or missing references)
//IL_0381: Unknown result type (might be due to invalid IL or missing references)
//IL_038b: Expected O, but got Unknown
//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
//IL_03ce: Expected O, but got Unknown
//IL_0400: Unknown result type (might be due to invalid IL or missing references)
//IL_040b: Unknown result type (might be due to invalid IL or missing references)
//IL_0415: Expected O, but got Unknown
Log = ((BasePlugin)this).Log;
((BasePlugin)this).HarmonyInstance.PatchAll();
ENABLED = ((BasePlugin)this).Config.Bind<bool>("Toggles", "enabled", true, new ConfigDescription("Enable the mod.", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.contactsorter.enabled.Key", "Settings.dev.lecloutpanda.contactsorter.enabled.Description") }));
ALPHABETICAL_SORT = ((BasePlugin)this).Config.Bind<bool>("Toggles", "alphabeticalSort", true, new ConfigDescription("Alphabetically sort users between groupings.", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.contactsorter.alphabeticalSort.Key", "Settings.dev.lecloutpanda.contactsorter.alphabeticalSort.Description") }));
SHOW_OFFLINE_CONTACTS = ((BasePlugin)this).Config.Bind<bool>("Toggles", "showOfflineContacts", true, new ConfigDescription("Whether or not to show offline contacts in contact list.", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.contactsorter.showOfflineContacts.Key", "Settings.dev.lecloutpanda.contactsorter.showOfflineContacts.Description") }));
MESSAGED_PRIORITY = ((BasePlugin)this).Config.Bind<int>("Orders", "messagedPriority", 1337, new ConfigDescription("Contact with a message priority (Default is 1337)", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.contactsorter.messagedPriority.Key", "Settings.dev.lecloutpanda.contactsorter.messagedPriority.Description") }));
PINNED_PRIORITY = ((BasePlugin)this).Config.Bind<int>("Orders", "pinnedPriority", 720, new ConfigDescription("Pinned contact priority (Default is 720)\nDisabled at -1", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.contactsorter.pinnedPriority.Key", "Settings.dev.lecloutpanda.contactsorter.pinnedPriority.Description") }));
RESONITE_PRIORITY = ((BasePlugin)this).Config.Bind<int>("Orders", "resonitePriority", 420, new ConfigDescription("Resonite Account priority (Default is 420)\nDisabled at -1", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.contactsorter.resonitePriority.Key", "Settings.dev.lecloutpanda.contactsorter.resonitePriority.Description") }));
SELF_PRIORITY = ((BasePlugin)this).Config.Bind<int>("Orders", "selfPriority", 69, new ConfigDescription("Self priority (Default is 69)\nDisabled at -1", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.contactsorter.selfPriority.Key", "Settings.dev.lecloutpanda.contactsorter.selfPriority.Description") }));
SOCIABLE_PRIORITY = ((BasePlugin)this).Config.Bind<int>("Orders", "sociable", 60, new ConfigDescription("Sociable priority (Default is 60)", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.contactsorter.sociable.Key", "Settings.dev.lecloutpanda.contactsorter.sociable.Description") }));
ONLINE_PRIORITY = ((BasePlugin)this).Config.Bind<int>("Orders", "onlinePriority", 50, new ConfigDescription("Online priority (Default is 50)", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.contactsorter.onlinePriority.Key", "Settings.dev.lecloutpanda.contactsorter.onlinePriority.Description") }));
BUSY_PRIORITY = ((BasePlugin)this).Config.Bind<int>("Orders", "busyPriority", 40, new ConfigDescription("Busy priority (Default is 40)", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.contactsorter.busyPriority.Key", "Settings.dev.lecloutpanda.contactsorter.busyPriority.Description") }));
AWAY_PRIORITY = ((BasePlugin)this).Config.Bind<int>("Orders", "awayPriority", 30, new ConfigDescription("Away priority (Default is 30)", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.contactsorter.awayPriority.Key", "Settings.dev.lecloutpanda.contactsorter.awayPriority.Description") }));
HEADLESS_PRIORITY = ((BasePlugin)this).Config.Bind<int>("Orders", "headlessPriority", 20, new ConfigDescription("Headless priority (Default is 20)", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.contactsorter.headlessPriority.Key", "Settings.dev.lecloutpanda.contactsorter.headlessPriority.Description") }));
CONTACT_REQUEST_ORDER = ((BasePlugin)this).Config.Bind<int>("Orders", "contactRequestPriority", 10, new ConfigDescription("Contact request priority (Default is 10)\nDisabled at -1", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.contactsorter.contactRequestPriority.Key", "Settings.dev.lecloutpanda.contactsorter.contactRequestPriority.Description") }));
OFFLINE_PRIORITY = ((BasePlugin)this).Config.Bind<int>("Orders", "offlinePriority", 0, new ConfigDescription("Offline priority (Default is 0)", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.contactsorter.offlinePriority.Key", "Settings.dev.lecloutpanda.contactsorter.offlinePriority.Description") }));
PINNED_CONTACTS = ((BasePlugin)this).Config.Bind<string>("Misc", "pinnedContacts", "", new ConfigDescription("", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.contactsorter.pinnedContacts.Key", "Settings.dev.lecloutpanda.contactsorter.pinnedContacts.Description") }));
}
public static List<ContactItem> SortContacts(List<ContactItem> contacts)
{
if (ALPHABETICAL_SORT.Value)
{
return Enumerable.ToList<ContactItem>((global::System.Collections.Generic.IEnumerable<ContactItem>)Enumerable.ThenBy<ContactItem, string>(Enumerable.OrderByDescending<ContactItem, int>((global::System.Collections.Generic.IEnumerable<ContactItem>)contacts, (Func<ContactItem, int>)((ContactItem c) => GetPriority(c))), (Func<ContactItem, string>)((ContactItem c) => c.Username)));
}
return Enumerable.ToList<ContactItem>((global::System.Collections.Generic.IEnumerable<ContactItem>)Enumerable.OrderByDescending<ContactItem, int>((global::System.Collections.Generic.IEnumerable<ContactItem>)contacts, (Func<ContactItem, int>)((ContactItem c) => GetPriority(c))));
}
private static int GetPriority(ContactItem c)
{
//IL_001c: 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_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Invalid comparison between Unknown and I4
//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_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_0146: Expected I4, but got Unknown
OnlineStatus? onlineStatus = c.Data.CurrentStatus.OnlineStatus;
UserSessionType sessionType = c.Data.CurrentStatus.SessionType;
if (c.HasMessages)
{
return MESSAGED_PRIORITY.Value;
}
if (PINNED_PRIORITY.Value != -1 && (PINNED_CONTACTS.Value.Contains(c.Data.UserId) || PINNED_CONTACTS.Value.Contains(c.Username)))
{
return PINNED_PRIORITY.Value;
}
if ((int)sessionType == 3)
{
return HEADLESS_PRIORITY.Value;
}
if (RESONITE_PRIORITY.Value != -1 && c.Data.Contact.ContactUserId == "U-Resonite")
{
return RESONITE_PRIORITY.Value;
}
if (SELF_PRIORITY.Value != -1 && c.Data.Contact.IsSelfContact)
{
return SELF_PRIORITY.Value;
}
if (CONTACT_REQUEST_ORDER.Value != -1 && c.Data.Contact.IsContactRequest)
{
return CONTACT_REQUEST_ORDER.Value;
}
return onlineStatus switch
{
5L => SOCIABLE_PRIORITY.Value,
4L => ONLINE_PRIORITY.Value,
3L => BUSY_PRIORITY.Value,
2L => AWAY_PRIORITY.Value,
1L => OFFLINE_PRIORITY.Value,
0L => OFFLINE_PRIORITY.Value,
_ => 0,
};
}
}
public static class PluginMetadata
{
public const string GUID = "dev.lecloutpanda.contactsorter";
public const string NAME = "ContactSorter";
public const string VERSION = "1.1.0";
public const string AUTHORS = "LeCloutPanda";
public const string REPOSITORY_URL = "https://github.com/lecloutpanda/ContactSorter";
}