using Dalamud.Plugin.Ipc; namespace ChatTwo.Ipc; internal sealed class ExtraChat : IDisposable { [Serializable] private struct OverrideInfo { public string? Channel; public ushort UiColour; public uint Rgba; } private Plugin Plugin { get; } private ICallGateSubscriber OverrideChannelGate { get; } private ICallGateSubscriber, Dictionary> ChannelCommandColoursGate { get; } private ICallGateSubscriber, Dictionary> ChannelNamesGate { get; } internal (string, uint)? ChannelOverride { get; set; } private Dictionary ChannelCommandColoursInternal { get; set; } = new(); internal IReadOnlyDictionary ChannelCommandColours => ChannelCommandColoursInternal; private Dictionary ChannelNamesInternal { get; set; } = new(); internal IReadOnlyDictionary ChannelNames => ChannelNamesInternal; internal ExtraChat(Plugin plugin) { Plugin = plugin; OverrideChannelGate = Plugin.Interface.GetIpcSubscriber("ExtraChat.OverrideChannelColour"); ChannelCommandColoursGate = Plugin.Interface.GetIpcSubscriber, Dictionary>("ExtraChat.ChannelCommandColours"); ChannelNamesGate = Plugin.Interface.GetIpcSubscriber, Dictionary>("ExtraChat.ChannelNames"); OverrideChannelGate.Subscribe(OnOverrideChannel); ChannelCommandColoursGate.Subscribe(OnChannelCommandColours); ChannelNamesGate.Subscribe(OnChannelNames); try { ChannelCommandColoursInternal = ChannelCommandColoursGate.InvokeFunc(null!); ChannelNamesInternal = ChannelNamesGate.InvokeFunc(null!); } catch (Exception) { // no-op } } public void Dispose() { OverrideChannelGate.Unsubscribe(OnOverrideChannel); } private void OnOverrideChannel(OverrideInfo info) { if (info.Channel == null) { ChannelOverride = null; return; } ChannelOverride = (info.Channel, info.Rgba); } private void OnChannelCommandColours(Dictionary obj) { ChannelCommandColoursInternal = obj; } private void OnChannelNames(Dictionary obj) { ChannelNamesInternal = obj; } }