using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using ProjectM.UI;
using TMPro;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("ChatPrefixesClient")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ChatPrefixesClient")]
[assembly: AssemblyTitle("ChatPrefixesClient")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ChatPrefixesClient;
internal static class Hooks
{
private static bool HasTags(string value)
{
if (string.IsNullOrEmpty(value))
{
return false;
}
if (value.IndexOf("<color=", StringComparison.Ordinal) < 0)
{
return value.IndexOf("<#", StringComparison.Ordinal) >= 0;
}
return true;
}
internal static void Queue(TMP_Text __instance, string value)
{
if (!((Object)(object)__instance == (Object)null) && HasTags(value) && !__instance.richText)
{
TextQueue.Enqueue(__instance);
}
}
}
[HarmonyPatch(typeof(TMP_Text), "set_text")]
internal static class SetTextPatch
{
[HarmonyPrefix]
internal static void Prefix(TMP_Text __instance, string value)
{
Hooks.Queue(__instance, value);
}
}
[HarmonyPatch(typeof(ClientChatSystem), "OnUpdate")]
internal static class PumpPatch
{
[HarmonyPostfix]
internal static void Postfix()
{
TextQueue.Process();
}
}
[BepInPlugin("agenthere.chatprefixes.client", "Chat Prefixes Client", "1.1.0")]
public class Plugin : BasePlugin
{
public const string PluginGuid = "agenthere.chatprefixes.client";
public const string PluginName = "Chat Prefixes Client";
public const string PluginVersion = "1.1.0";
internal static ManualLogSource Logger;
internal static ConfigEntry<bool> Enabled;
public override void Load()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Expected O, but got Unknown
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Expected O, but got Unknown
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
//IL_014c: Expected O, but got Unknown
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
Logger = ((BasePlugin)this).Log;
ManualLogSource logger = Logger;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(34, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ChatPrefixesClient] ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Chat Prefixes Client");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" v");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.1.0");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loading...");
}
logger.LogInfo(val);
try
{
Enabled = new ConfigFile(Path.Combine(Paths.ConfigPath, "ChatPrefixesClient.cfg"), true).Bind<bool>("General", "Enabled", true, "Включить клиентскую отрисовку цветных префиксов (rich-text в никах).");
}
catch (Exception ex)
{
ManualLogSource logger2 = Logger;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(29, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[ChatPrefixesClient] config: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
}
logger2.LogWarning(val2);
}
if (Enabled != null && !Enabled.Value)
{
Logger.LogInfo((object)"[ChatPrefixesClient] disabled by config.");
return;
}
try
{
new Harmony("agenthere.chatprefixes.client").PatchAll(Assembly.GetExecutingAssembly());
Logger.LogInfo((object)"[ChatPrefixesClient] hooks installed.");
}
catch (Exception ex2)
{
ManualLogSource logger3 = Logger;
BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(35, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[ChatPrefixesClient] patch failed: ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<Exception>(ex2);
}
logger3.LogError(val3);
}
ManualLogSource logger4 = Logger;
val = new BepInExInfoLogInterpolatedStringHandler(31, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ChatPrefixesClient] ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Chat Prefixes Client");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" v");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.1.0");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded.");
}
logger4.LogInfo(val);
}
}
internal static class TextQueue
{
private static readonly List<TMP_Text> Pending = new List<TMP_Text>();
internal static void Enqueue(TMP_Text text)
{
if ((Object)(object)text == (Object)null)
{
return;
}
lock (Pending)
{
if (Pending.Count > 200)
{
Pending.Clear();
}
if (!Pending.Contains(text))
{
Pending.Add(text);
}
}
}
internal static void Process()
{
TMP_Text[] array;
lock (Pending)
{
if (Pending.Count == 0)
{
return;
}
array = Pending.ToArray();
Pending.Clear();
}
TMP_Text[] array2 = array;
foreach (TMP_Text val in array2)
{
try
{
if (!((Object)(object)val == (Object)null) && !val.richText)
{
val.richText = true;
}
}
catch
{
}
}
}
}