anna-is-cute / plugin-issues

A repository of confirmed issues for my plugins.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Chat 2] Custom Payloads not working when clicked

Diyagi opened this issue · comments

Hello, hope you are doing well.

Right now theres is an issue with chat 2 where custom payloads made using DalamudLinkPayloads are now working when clicked,
they do work in normal game chat.

I took sometime to look at Chat 2 code and found an reflection that wont work anymore because of dalamud changes to services.
https://git.anna.lgbt/anna/ChatTwo/src/branch/dev/ChatTwo/PayloadHandler.cs#L340

I cloned the repo and fixed the reflection locally and now the payloads are working again.

Heres how I fixed it if it helps in any way (with a little guide from goaats)

        var chatGuiScoped = this.Ui.Plugin.ChatGui;
        var chatGuiService = chatGuiScoped.GetType()
            .GetField("chatGuiService", BindingFlags.Instance | BindingFlags.NonPublic)!
            .GetValue(chatGuiScoped);
        
        var field = chatGuiService!.GetType().GetField("dalamudLinkHandlers", BindingFlags.Instance | BindingFlags.NonPublic);
        if (field == null || field.GetValue(chatGuiService) is not Dictionary<(string PluginName, uint CommandId), Action<uint, SeString>> dict || !dict.TryGetValue((link.Plugin, link.CommandId), out var action)) {
            return;
        }

Thanks for looking up the changed reflection for me! I would've responded sooner, but GitHub emails are being put in my spam folder 🙃

It seems the issue might be because of the PluginScoping of the ChatGui, since the reference you are given via IChatGui doesn't contain the dalamudLinkHandlers.

We might be able to add a IReadOnlyDictionary of the link handlers to the IChatGui interface, it doesn't seem unreasonable to do. Will have to check with the Dalamud Maintainers.

Fixed on the repository, but I have yet to test it yet.