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.Configuration;
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.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0+9d48a49fb4ac4861f2189412a021f61dd3ae9794")]
[assembly: AssemblyProduct("FixContactIcons")]
[assembly: AssemblyTitle("FixContactIcons")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/NepuShiro/FixContactIcons")]
[assembly: AssemblyVersion("1.3.0.0")]
[module: RefSafetyRules(11)]
namespace FixContactIcons;
[ResonitePlugin("NepuShiro.FixContactIcons", "FixContactIcons", "1.3.0", "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)
{
Contact val = default(Contact);
if (!(overrideProfile != (Uri)null) && !string.IsNullOrEmpty(userId) && ContactCache.TryGetValue(userId, ref val))
{
object obj;
if (val == null)
{
obj = null;
}
else
{
UserProfile profile = val.Profile;
obj = ((profile != null) ? profile.IconUrl : null);
}
Uri val2 = default(Uri);
if (!string.IsNullOrEmpty((string)obj) && Uri.TryCreate(val.Profile.IconUrl, (UriKind)1, ref val2))
{
overrideProfile = val2;
}
}
}
}
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
public static readonly <>c <>9 = new <>c();
public static Action <>9__4_0;
public static Func<RadiantDashScreen, bool> <>9__6_0;
internal void <Load>b__4_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__6_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__DisplayClass6_0
{
public ContactData cd;
internal bool <EnsureProfile>b__1(ContactItem x)
{
return x.Contact.ContactUserId == cd.Contact.ContactUserId;
}
}
[CompilerGenerated]
private sealed class <>c__DisplayClass6_1
{
public ContactItem theContact;
public <>c__DisplayClass6_0 CS$<>8__locals1;
internal void <EnsureProfile>b__2()
{
theContact.Update(CS$<>8__locals1.cd.Contact, CS$<>8__locals1.cd);
}
}
[StructLayout(3)]
[CompilerGenerated]
private struct <EnsureProfile>d__6 : IAsyncStateMachine
{
public int <>1__state;
public AsyncVoidMethodBuilder <>t__builder;
public ContactData cd;
private <>c__DisplayClass6_1 <>8__1;
private TaskAwaiter<bool> <>u__1;
private void MoveNext()
{
//IL_0084: 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_0090: 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_0056: 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_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_017e: Expected O, but got Unknown
int num = <>1__state;
try
{
<>c__DisplayClass6_0 cS$<>8__locals = default(<>c__DisplayClass6_0);
if (num != 0)
{
cS$<>8__locals = new <>c__DisplayClass6_0
{
cd = cd
};
}
try
{
TaskAwaiter<bool> awaiter;
if (num != 0)
{
<>8__1 = new <>c__DisplayClass6_1();
<>8__1.CS$<>8__locals1 = cS$<>8__locals;
awaiter = EnsureProfile(<>8__1.CS$<>8__locals1.cd.Contact).GetAwaiter();
if (!awaiter.IsCompleted)
{
num = (<>1__state = 0);
<>u__1 = awaiter;
((AsyncVoidMethodBuilder)(ref <>t__builder)).AwaitUnsafeOnCompleted<TaskAwaiter<bool>, <EnsureProfile>d__6>(ref awaiter, ref this);
return;
}
}
else
{
awaiter = <>u__1;
<>u__1 = default(TaskAwaiter<bool>);
num = (<>1__state = -1);
}
if (awaiter.GetResult() && UpdateContactAfterEnsure.Value)
{
World userspaceWorld = Userspace.UserspaceWorld;
object obj;
if (userspaceWorld == null)
{
obj = null;
}
else
{
UserspaceRadiantDash radiantDash = UserspaceRadiantDashExtensions.GetRadiantDash(userspaceWorld);
if (radiantDash == null)
{
obj = null;
}
else
{
RadiantDash dash = radiantDash.Dash;
if (dash == null)
{
obj = null;
}
else
{
global::System.Collections.Generic.IEnumerable<RadiantDashScreen> screens = dash.Screens;
obj = ((screens != null) ? 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")) : null);
}
}
}
RadiantDashScreen val = (RadiantDashScreen)obj;
<>c__DisplayClass6_1 <>c__DisplayClass6_ = <>8__1;
object theContact;
if (val == null)
{
theContact = null;
}
else
{
Slot slot = ((Component)val).Slot;
theContact = ((slot != null) ? slot.GetComponentInChildren<ContactItem>((Predicate<ContactItem>)((ContactItem x) => x.Contact.ContactUserId == <>8__1.CS$<>8__locals1.cd.Contact.ContactUserId), false, false) : null);
}
<>c__DisplayClass6_.theContact = (ContactItem)theContact;
ContactItem theContact2 = <>8__1.theContact;
if (theContact2 != null)
{
World world = ((Worker)theContact2).World;
if (world != null)
{
world.RunSynchronously((Action)delegate
{
<>8__1.theContact.Update(<>8__1.CS$<>8__locals1.cd.Contact, <>8__1.CS$<>8__locals1.cd);
}, false, (IUpdatable)null, false);
}
}
<>8__1 = null;
}
}
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;
((AsyncVoidMethodBuilder)(ref <>t__builder)).SetException(exception);
return;
}
<>1__state = -2;
((AsyncVoidMethodBuilder)(ref <>t__builder)).SetResult();
}
[DebuggerHidden]
private void SetStateMachine(IAsyncStateMachine stateMachine)
{
((AsyncVoidMethodBuilder)(ref <>t__builder)).SetStateMachine(stateMachine);
}
}
[StructLayout(3)]
[CompilerGenerated]
private struct <EnsureProfile>d__7 : IAsyncStateMachine
{
public int <>1__state;
public AsyncTaskMethodBuilder<bool> <>t__builder;
public Contact contact;
private TaskAwaiter<User?> <>u__1;
private void MoveNext()
{
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: 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_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)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Expected O, but got Unknown
int num = <>1__state;
bool result;
try
{
TaskAwaiter<User> awaiter;
if (num == 0)
{
awaiter = <>u__1;
<>u__1 = default(TaskAwaiter<User>);
num = (<>1__state = -1);
goto IL_0097;
}
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__7>(ref awaiter, ref this);
return;
}
goto IL_0097;
}
result = false;
goto end_IL_0007;
IL_0097:
User result2 = awaiter.GetResult();
if (((result2 != null) ? result2.Profile : null) == null)
{
result = false;
}
else
{
contact.Profile = result2.Profile;
ManualLogSource log = Log;
bool flag = default(bool);
BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(20, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Ensured Profile for ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(contact.ContactUserId);
}
log.LogDebug(val);
result = true;
}
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__8 : 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__8>(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__8>(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;
internal static ConfigEntry<bool> UpdateContactAfterEnsure = null;
private static readonly HttpClient HttpClient = new HttpClient();
private static readonly Dictionary<string, Contact?> ContactCache = new Dictionary<string, Contact>();
public override void Load()
{
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Expected O, but got Unknown
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Expected O, but got Unknown
Log = ((BasePlugin)this).Log;
UpdateContactAfterEnsure = ((BasePlugin)this).Config.Bind<bool>("General", "Update contact after ensure", true, "Update the Contact after ensuring that they have a Profile");
((BasePlugin)this).HarmonyInstance.PatchAll();
object obj = <>c.<>9__4_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__4_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__6))]
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__6 <EnsureProfile>d__ = default(<EnsureProfile>d__6);
<EnsureProfile>d__.<>t__builder = AsyncVoidMethodBuilder.Create();
<EnsureProfile>d__.cd = cd;
<EnsureProfile>d__.<>1__state = -1;
((AsyncVoidMethodBuilder)(ref <EnsureProfile>d__.<>t__builder)).Start<<EnsureProfile>d__6>(ref <EnsureProfile>d__);
}
[AsyncStateMachine(typeof(<EnsureProfile>d__7))]
private static async global::System.Threading.Tasks.Task<bool> 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 false;
}
User val = await GetUser(contact.ContactUserId);
if (((val != null) ? val.Profile : null) == null)
{
return false;
}
contact.Profile = val.Profile;
ManualLogSource log = Log;
bool flag = default(bool);
BepInExDebugLogInterpolatedStringHandler val2 = new BepInExDebugLogInterpolatedStringHandler(20, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Ensured Profile for ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(contact.ContactUserId);
}
log.LogDebug(val2);
return true;
}
[AsyncStateMachine(typeof(<GetUser>d__8))]
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.3.0";
public const string AUTHORS = "NepuShiro";
public const string REPOSITORY_URL = "https://github.com/NepuShiro/FixContactIcons";
}