Decompiled source of FixContactIcons v1.2.4

plugins/FixContactIcons/FixContactIcons.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text.Json;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.NET.Common;
using BepInExResoniteShim;
using BepisResoniteWrapper;
using Elements.Core;
using FrooxEngine;
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("NepuShiro")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.4.0")]
[assembly: AssemblyInformationalVersion("1.2.4+a24837278260af1c5ddc6f4a766068294c9e9d22")]
[assembly: AssemblyProduct("FixContactIcons")]
[assembly: AssemblyTitle("FixContactIcons")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/NepuShiro/FixContactIcons")]
[assembly: AssemblyVersion("1.2.4.0")]
[module: RefSafetyRules(11)]
namespace FixContactIcons;

[ResonitePlugin("NepuShiro.FixContactIcons", "FixContactIcons", "1.2.4", "NepuShiro", "https://github.com/NepuShiro/FixContactIcons")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
	[HarmonyPatch(typeof(NotificationPanel), "AddNotification")]
	[HarmonyPatch(new global::System.Type[]
	{
		typeof(string),
		typeof(string),
		typeof(Uri),
		typeof(colorX),
		typeof(NotificationType),
		typeof(string),
		typeof(Uri),
		typeof(IAssetProvider<AudioClip>)
	})]
	public class AddNotificationPatch
	{
		[HarmonyPrefix]
		private static void Prefix(string userId, ref Uri overrideProfile)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			Contact val = default(Contact);
			if (!string.IsNullOrEmpty(userId) && !(overrideProfile != (Uri)null) && ContactCache.TryGetValue(userId, ref val))
			{
				object obj;
				if (val == null)
				{
					obj = null;
				}
				else
				{
					UserProfile profile = val.Profile;
					obj = ((profile != null) ? profile.IconUrl : null);
				}
				if (!string.IsNullOrEmpty((string)obj))
				{
					overrideProfile = new Uri(val.Profile.IconUrl);
				}
			}
		}
	}

	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static Action <>9__3_0;

		public static Func<RadiantDashScreen, bool> <>9__5_0;

		internal void <Load>b__3_0()
		{
			((SkyFrostInterface)Engine.Current.Cloud).Contacts.ForeachContactData((Action<ContactData>)EnsureProfile);
			((SkyFrostInterface)Engine.Current.Cloud).Contacts.ContactRemoved += EnsureProfile;
			((SkyFrostInterface)Engine.Current.Cloud).Contacts.ContactAdded += EnsureProfile;
			((SkyFrostInterface)Engine.Current.Cloud).Contacts.ContactUpdated += EnsureProfile;
		}

		internal bool <EnsureProfile>b__5_0(RadiantDashScreen x)
		{
			if (!(x is LegacyRadiantScreenWrapper<ContactsDialog>) && !((SyncField<string>)(object)x.Label).Value.Contains("Contacts"))
			{
				return ((SyncField<string>)(object)((ContainerWorker<Component>)(object)((Component)x).Slot).GetComponent<LocaleStringDriver>((Predicate<LocaleStringDriver>)null, false)?.Key)?.Value == "Dash.Screens.Contacts";
			}
			return true;
		}
	}

	[CompilerGenerated]
	private sealed class <>c__DisplayClass5_0
	{
		public ContactData cd;

		internal bool <EnsureProfile>b__1(ContactItem x)
		{
			if (x.Contact != cd.Contact)
			{
				return x.Data == cd;
			}
			return true;
		}
	}

	[StructLayout(3)]
	[CompilerGenerated]
	private struct <EnsureProfile>d__5 : IAsyncStateMachine
	{
		public int <>1__state;

		public AsyncVoidMethodBuilder <>t__builder;

		public ContactData cd;

		private <>c__DisplayClass5_0 <>8__1;

		private TaskAwaiter<User?> <>u__1;

		private void MoveNext()
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: 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)
			int num = <>1__state;
			try
			{
				if (num != 0)
				{
					<>8__1 = new <>c__DisplayClass5_0();
					<>8__1.cd = cd;
				}
				try
				{
					TaskAwaiter<User> awaiter;
					if (num != 0)
					{
						awaiter = EnsureProfile(<>8__1.cd.Contact).GetAwaiter();
						if (!awaiter.IsCompleted)
						{
							num = (<>1__state = 0);
							<>u__1 = awaiter;
							((AsyncVoidMethodBuilder)(ref <>t__builder)).AwaitUnsafeOnCompleted<TaskAwaiter<User>, <EnsureProfile>d__5>(ref awaiter, ref this);
							return;
						}
					}
					else
					{
						awaiter = <>u__1;
						<>u__1 = default(TaskAwaiter<User>);
						num = (<>1__state = -1);
					}
					User result = awaiter.GetResult();
					if (result != null)
					{
						List<ContactItem> val = new List<ContactItem>();
						World userspaceWorld = Userspace.UserspaceWorld;
						if (userspaceWorld != null)
						{
							UserspaceRadiantDash radiantDash = UserspaceRadiantDashExtensions.GetRadiantDash(userspaceWorld);
							if (radiantDash != null)
							{
								RadiantDash dash = radiantDash.Dash;
								if (dash != null)
								{
									global::System.Collections.Generic.IEnumerable<RadiantDashScreen> screens = dash.Screens;
									if (screens != null)
									{
										RadiantDashScreen obj = Enumerable.FirstOrDefault<RadiantDashScreen>(screens, (Func<RadiantDashScreen, bool>)((RadiantDashScreen x) => x is LegacyRadiantScreenWrapper<ContactsDialog> || ((SyncField<string>)(object)x.Label).Value.Contains("Contacts") || ((SyncField<string>)(object)((ContainerWorker<Component>)(object)((Component)x).Slot).GetComponent<LocaleStringDriver>((Predicate<LocaleStringDriver>)null, false)?.Key)?.Value == "Dash.Screens.Contacts"));
										if (obj != null)
										{
											Slot slot = ((Component)obj).Slot;
											if (slot != null)
											{
												slot.GetComponentsInChildren<ContactItem>(val, (Predicate<ContactItem>)((ContactItem x) => x.Contact == <>8__1.cd.Contact || x.Data == <>8__1.cd), false, false, (Predicate<Slot>)null);
											}
										}
									}
								}
							}
						}
						if (val.Count > 0)
						{
							Enumerator<ContactItem> enumerator = val.GetEnumerator();
							try
							{
								while (enumerator.MoveNext())
								{
									enumerator.Current.Update(result);
								}
							}
							finally
							{
								if (num < 0)
								{
									((global::System.IDisposable)enumerator).Dispose();
								}
							}
						}
					}
				}
				catch (object obj2) when (((Func<bool>)delegate
				{
					// Could not convert BlockContainer to single expression
					object obj3 = ((obj2 is InvalidOperationException) ? obj2 : null);
					return obj3 != null && ((global::System.Exception)obj3).Message.Contains("Collection was modified");
				}).Invoke())
				{
				}
				catch (global::System.Exception ex)
				{
					Log.LogError((object)ex);
				}
			}
			catch (global::System.Exception exception)
			{
				<>1__state = -2;
				<>8__1 = null;
				((AsyncVoidMethodBuilder)(ref <>t__builder)).SetException(exception);
				return;
			}
			<>1__state = -2;
			<>8__1 = null;
			((AsyncVoidMethodBuilder)(ref <>t__builder)).SetResult();
		}

		[DebuggerHidden]
		private void SetStateMachine(IAsyncStateMachine stateMachine)
		{
			((AsyncVoidMethodBuilder)(ref <>t__builder)).SetStateMachine(stateMachine);
		}
	}

	[StructLayout(3)]
	[CompilerGenerated]
	private struct <EnsureProfile>d__6 : IAsyncStateMachine
	{
		public int <>1__state;

		public AsyncTaskMethodBuilder<User> <>t__builder;

		public Contact contact;

		private TaskAwaiter<User?> <>u__1;

		private void MoveNext()
		{
			//IL_0079: 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_0085: 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)
			//IL_004e: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			int num = <>1__state;
			User result;
			try
			{
				TaskAwaiter<User> awaiter;
				if (num == 0)
				{
					awaiter = <>u__1;
					<>u__1 = default(TaskAwaiter<User>);
					num = (<>1__state = -1);
					goto IL_0094;
				}
				ContactCache[contact.ContactUserId] = contact;
				if (contact.Profile == null)
				{
					awaiter = GetUser(contact.ContactUserId).GetAwaiter();
					if (!awaiter.IsCompleted)
					{
						num = (<>1__state = 0);
						<>u__1 = awaiter;
						<>t__builder.AwaitUnsafeOnCompleted<TaskAwaiter<User>, <EnsureProfile>d__6>(ref awaiter, ref this);
						return;
					}
					goto IL_0094;
				}
				result = null;
				goto end_IL_0007;
				IL_0094:
				User result2 = awaiter.GetResult();
				if (((result2 != null) ? result2.Profile : null) == null)
				{
					result = null;
				}
				else
				{
					contact.Profile = result2.Profile;
					result = result2;
				}
				end_IL_0007:;
			}
			catch (global::System.Exception exception)
			{
				<>1__state = -2;
				<>t__builder.SetException(exception);
				return;
			}
			<>1__state = -2;
			<>t__builder.SetResult(result);
		}

		[DebuggerHidden]
		private void SetStateMachine(IAsyncStateMachine stateMachine)
		{
			<>t__builder.SetStateMachine(stateMachine);
		}
	}

	[StructLayout(3)]
	[CompilerGenerated]
	private struct <GetUser>d__7 : IAsyncStateMachine
	{
		public int <>1__state;

		public AsyncTaskMethodBuilder<User> <>t__builder;

		public string userId;

		private ConfiguredTaskAwaiter<HttpResponseMessage> <>u__1;

		private TaskAwaiter<string> <>u__2;

		private void MoveNext()
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_00df: 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_00ec: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_00b2: 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_005e: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			int num = <>1__state;
			User result2;
			try
			{
				TaskAwaiter<string> awaiter;
				ConfiguredTaskAwaiter<HttpResponseMessage> awaiter2;
				if (num != 0)
				{
					if (num == 1)
					{
						awaiter = <>u__2;
						<>u__2 = default(TaskAwaiter<string>);
						num = (<>1__state = -1);
						goto IL_00fb;
					}
					awaiter2 = HttpClient.GetAsync(((SkyFrostInterface)Engine.Current.Cloud).ApiEndpoint + "/users/" + userId).ConfigureAwait(false).GetAwaiter();
					if (!awaiter2.IsCompleted)
					{
						num = (<>1__state = 0);
						<>u__1 = awaiter2;
						<>t__builder.AwaitUnsafeOnCompleted<ConfiguredTaskAwaiter<HttpResponseMessage>, <GetUser>d__7>(ref awaiter2, ref this);
						return;
					}
				}
				else
				{
					awaiter2 = <>u__1;
					<>u__1 = default(ConfiguredTaskAwaiter<HttpResponseMessage>);
					num = (<>1__state = -1);
				}
				HttpResponseMessage result = awaiter2.GetResult();
				if (result.IsSuccessStatusCode)
				{
					awaiter = result.Content.ReadAsStringAsync().GetAwaiter();
					if (!awaiter.IsCompleted)
					{
						num = (<>1__state = 1);
						<>u__2 = awaiter;
						<>t__builder.AwaitUnsafeOnCompleted<TaskAwaiter<string>, <GetUser>d__7>(ref awaiter, ref this);
						return;
					}
					goto IL_00fb;
				}
				User val = null;
				goto IL_010f;
				IL_00fb:
				val = JsonSerializer.Deserialize<User>(awaiter.GetResult(), (JsonSerializerOptions)null);
				goto IL_010f;
				IL_010f:
				result2 = val;
			}
			catch (global::System.Exception exception)
			{
				<>1__state = -2;
				<>t__builder.SetException(exception);
				return;
			}
			<>1__state = -2;
			<>t__builder.SetResult(result2);
		}

		[DebuggerHidden]
		private void SetStateMachine(IAsyncStateMachine stateMachine)
		{
			<>t__builder.SetStateMachine(stateMachine);
		}
	}

	internal static ManualLogSource Log = null;

	private static readonly HttpClient HttpClient = new HttpClient();

	private static readonly Dictionary<string, Contact?> ContactCache = new Dictionary<string, Contact>();

	public override void Load()
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Expected O, but got Unknown
		//IL_002a: 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_0035: Expected O, but got Unknown
		Log = ((BasePlugin)this).Log;
		((BasePlugin)this).HarmonyInstance.PatchAll();
		object obj = <>c.<>9__3_0;
		if (obj == null)
		{
			Action val = delegate
			{
				((SkyFrostInterface)Engine.Current.Cloud).Contacts.ForeachContactData((Action<ContactData>)EnsureProfile);
				((SkyFrostInterface)Engine.Current.Cloud).Contacts.ContactRemoved += EnsureProfile;
				((SkyFrostInterface)Engine.Current.Cloud).Contacts.ContactAdded += EnsureProfile;
				((SkyFrostInterface)Engine.Current.Cloud).Contacts.ContactUpdated += EnsureProfile;
			};
			<>c.<>9__3_0 = val;
			obj = (object)val;
		}
		ResoniteHooks.OnEngineReady += (Action)obj;
		ManualLogSource log = Log;
		bool flag = default(bool);
		BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
		if (flag)
		{
			((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Plugin ");
			((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("NepuShiro.FixContactIcons");
			((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" is loaded!");
		}
		log.LogInfo(val2);
	}

	[AsyncStateMachine(typeof(<EnsureProfile>d__5))]
	private static void EnsureProfile(ContactData cd)
	{
		//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)
		<EnsureProfile>d__5 <EnsureProfile>d__ = default(<EnsureProfile>d__5);
		<EnsureProfile>d__.<>t__builder = AsyncVoidMethodBuilder.Create();
		<EnsureProfile>d__.cd = cd;
		<EnsureProfile>d__.<>1__state = -1;
		((AsyncVoidMethodBuilder)(ref <EnsureProfile>d__.<>t__builder)).Start<<EnsureProfile>d__5>(ref <EnsureProfile>d__);
	}

	[AsyncStateMachine(typeof(<EnsureProfile>d__6))]
	private static async global::System.Threading.Tasks.Task<User?> EnsureProfile(Contact contact)
	{
		//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)
		ContactCache[contact.ContactUserId] = contact;
		if (contact.Profile != null)
		{
			return null;
		}
		User val = await GetUser(contact.ContactUserId);
		if (((val != null) ? val.Profile : null) == null)
		{
			return null;
		}
		contact.Profile = val.Profile;
		return val;
	}

	[AsyncStateMachine(typeof(<GetUser>d__7))]
	private static async global::System.Threading.Tasks.Task<User?> GetUser(string userId)
	{
		//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)
		HttpResponseMessage val = await HttpClient.GetAsync(((SkyFrostInterface)Engine.Current.Cloud).ApiEndpoint + "/users/" + userId).ConfigureAwait(false);
		return (!val.IsSuccessStatusCode) ? null : JsonSerializer.Deserialize<User>(await val.Content.ReadAsStringAsync(), (JsonSerializerOptions)null);
	}
}
public static class PluginMetadata
{
	public const string GUID = "NepuShiro.FixContactIcons";

	public const string NAME = "FixContactIcons";

	public const string VERSION = "1.2.4";

	public const string AUTHORS = "NepuShiro";

	public const string REPOSITORY_URL = "https://github.com/NepuShiro/FixContactIcons";
}