From c9cd28589b7e71926db1dbb4b718486bfc09bb97 Mon Sep 17 00:00:00 2001 From: Anna Date: Tue, 3 Oct 2023 02:59:51 -0400 Subject: [PATCH] refactor: update for api 9 --- ChatTwo/ChatTwo.csproj | 4 --- ChatTwo/Code/InputChannelExt.cs | 4 +-- ChatTwo/GameFunctions/Chat.cs | 18 +++++----- ChatTwo/GameFunctions/Context.cs | 2 +- ChatTwo/GameFunctions/GameFunctions.cs | 4 +-- ChatTwo/GameFunctions/Party.cs | 2 +- ChatTwo/PayloadHandler.cs | 10 +++--- ChatTwo/Plugin.cs | 49 ++++++++++++++------------ ChatTwo/Store.cs | 10 +++--- ChatTwo/TextureCache.cs | 34 +++++++++--------- ChatTwo/Ui/ChatLog.cs | 13 +++---- ChatTwo/Ui/CommandHelp.cs | 2 +- ChatTwo/Ui/Settings.cs | 6 ++-- ChatTwo/Util/AutoTranslate.cs | 8 ++--- ChatTwo/Util/ImGuiUtil.cs | 1 + 15 files changed, 85 insertions(+), 82 deletions(-) diff --git a/ChatTwo/ChatTwo.csproj b/ChatTwo/ChatTwo.csproj index 450702d..3e3de1c 100755 --- a/ChatTwo/ChatTwo.csproj +++ b/ChatTwo/ChatTwo.csproj @@ -39,10 +39,6 @@ $(DalamudLibPath)\ImGui.NET.dll false - - $(DalamudLibPath)\ImGuiScene.dll - false - $(DalamudLibPath)\Lumina.dll false diff --git a/ChatTwo/Code/InputChannelExt.cs b/ChatTwo/Code/InputChannelExt.cs index 2730455..215e2bf 100755 --- a/ChatTwo/Code/InputChannelExt.cs +++ b/ChatTwo/Code/InputChannelExt.cs @@ -1,4 +1,4 @@ -using Dalamud.Data; +using Dalamud.Plugin.Services; using Lumina.Excel.GeneratedSheets; namespace ChatTwo.Code; @@ -82,7 +82,7 @@ internal static class InputChannelExt { _ => "", }; - public static IEnumerable? TextCommands(this InputChannel channel, DataManager data) { + public static IEnumerable? TextCommands(this InputChannel channel, IDataManager data) { var ids = channel switch { InputChannel.Tell => new uint[] { 104, 118 }, InputChannel.Say => new uint[] { 102 }, diff --git a/ChatTwo/GameFunctions/Chat.cs b/ChatTwo/GameFunctions/Chat.cs index 13f6a9f..59c4e81 100755 --- a/ChatTwo/GameFunctions/Chat.cs +++ b/ChatTwo/GameFunctions/Chat.cs @@ -3,10 +3,12 @@ using ChatTwo.Code; using ChatTwo.GameFunctions.Types; using ChatTwo.Util; using Dalamud.Game.ClientState.Keys; +using Dalamud.Game.Config; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Hooking; using Dalamud.Logging; using Dalamud.Memory; +using Dalamud.Plugin.Services; using Dalamud.Utility.Signatures; using FFXIVClientStructs.FFXIV.Client.System.Framework; using FFXIVClientStructs.FFXIV.Client.System.Memory; @@ -142,7 +144,7 @@ internal sealed unsafe class Chat : IDisposable { internal Chat(Plugin plugin) { this.Plugin = plugin; - SignatureHelper.Initialise(this); + this.Plugin.GameInteropProvider.InitializeFromAttributes(this); this.ChatLogRefreshHook?.Enable(); this.ChangeChannelNameHook?.Enable(); @@ -151,7 +153,7 @@ internal sealed unsafe class Chat : IDisposable { this.Plugin.Framework.Update += this.InterceptKeybinds; this.Plugin.ClientState.Login += this.Login; - this.Login(null, null); + this.Login(); } public void Dispose() { @@ -368,7 +370,7 @@ internal sealed unsafe class Chat : IDisposable { } } - private void InterceptKeybinds(Dalamud.Game.Framework framework) { + private void InterceptKeybinds(IFramework framework1) { this.CheckFocus(); this.UpdateKeybinds(); @@ -435,7 +437,7 @@ internal sealed unsafe class Chat : IDisposable { } } - private void Login(object? sender, EventArgs? e) { + private void Login() { if (this.ChangeChannelNameHook == null) { return; } @@ -454,10 +456,8 @@ internal sealed unsafe class Chat : IDisposable { } string? input = null; - var option = Framework.Instance()->GetUiModule()->GetConfigModule()->GetValue(ConfigOption.DirectChat); - if (option != null) { - var directChat = option->Int > 0; - if (directChat && this._currentCharacter != null) { + if (this.Plugin.GameConfig.TryGet(UiControlOption.DirectChat, out bool option) && option) { + if (this._currentCharacter != null) { // FIXME: this whole system sucks var c = *this._currentCharacter; if (c != '\0' && !char.IsControl(c)) { @@ -592,7 +592,7 @@ internal sealed unsafe class Chat : IDisposable { idx = 0; } - this._changeChatChannel(RaptureShellModule.Instance, (int) channel, idx, target, 1); + this._changeChatChannel(RaptureShellModule.Instance(), (int) channel, idx, target, 1); target->Dtor(); IMemorySpace.Free(target); } diff --git a/ChatTwo/GameFunctions/Context.cs b/ChatTwo/GameFunctions/Context.cs index 68d7992..da4b3e1 100755 --- a/ChatTwo/GameFunctions/Context.cs +++ b/ChatTwo/GameFunctions/Context.cs @@ -40,7 +40,7 @@ internal sealed unsafe class Context { internal Context(Plugin plugin) { this.Plugin = plugin; - SignatureHelper.Initialise(this); + this.Plugin.GameInteropProvider.InitializeFromAttributes(this); } internal void InviteToNoviceNetwork(string name, ushort world) { diff --git a/ChatTwo/GameFunctions/GameFunctions.cs b/ChatTwo/GameFunctions/GameFunctions.cs index 075b1fe..df99fff 100755 --- a/ChatTwo/GameFunctions/GameFunctions.cs +++ b/ChatTwo/GameFunctions/GameFunctions.cs @@ -71,7 +71,7 @@ internal unsafe class GameFunctions : IDisposable { this.Chat = new Chat(this.Plugin); this.Context = new Context(this.Plugin); - SignatureHelper.Initialise(this); + this.Plugin.GameInteropProvider.InitializeFromAttributes(this); this.ResolveTextCommandPlaceholderHook?.Enable(); } @@ -207,7 +207,7 @@ internal unsafe class GameFunctions : IDisposable { // hide addon first to prevent the "addon close" sound var addon = AtkStage.GetSingleton()->RaptureAtkUnitManager->GetAddonByName("ItemDetail"); if (addon != null) { - addon->Hide(true); + addon->Hide(true, false, 0); } var agent = Framework.Instance()->GetUiModule()->GetAgentModule()->GetAgentByInternalId(AgentId.ItemDetail); diff --git a/ChatTwo/GameFunctions/Party.cs b/ChatTwo/GameFunctions/Party.cs index 6b356dd..568af78 100755 --- a/ChatTwo/GameFunctions/Party.cs +++ b/ChatTwo/GameFunctions/Party.cs @@ -26,7 +26,7 @@ internal sealed unsafe class Party { internal Party(Plugin plugin) { this.Plugin = plugin; - SignatureHelper.Initialise(this); + this.Plugin.GameInteropProvider.InitializeFromAttributes(this); } internal void InviteSameWorld(string name, ushort world, ulong contentId) { diff --git a/ChatTwo/PayloadHandler.cs b/ChatTwo/PayloadHandler.cs index cb3db53..bd1485f 100755 --- a/ChatTwo/PayloadHandler.cs +++ b/ChatTwo/PayloadHandler.cs @@ -7,11 +7,11 @@ using ChatTwo.Util; using Dalamud.Game.ClientState.Objects.SubKinds; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling.Payloads; -using Dalamud.Interface; +using Dalamud.Interface.Internal; +using Dalamud.Interface.Utility; using Dalamud.Logging; using Dalamud.Utility; using ImGuiNET; -using ImGuiScene; using Lumina.Excel.GeneratedSheets; using Action = System.Action; using DalamudPartyFinderPayload = Dalamud.Game.Text.SeStringHandling.Payloads.PartyFinderPayload; @@ -120,7 +120,7 @@ internal sealed class PayloadHandler { ImGui.Separator(); } - if (!ImGui.BeginMenu(this.Ui.Plugin.Name)) { + if (!ImGui.BeginMenu(Plugin.Name)) { return; } @@ -216,7 +216,7 @@ internal sealed class PayloadHandler { } } - private static void InlineIcon(TextureWrap icon) { + private static void InlineIcon(IDalamudTextureWrap icon) { var lineHeight = ImGui.CalcTextSize("A").Y; var cursor = ImGui.GetCursorPos(); @@ -531,7 +531,7 @@ internal sealed class PayloadHandler { } if (ImGui.Selectable(Language.Context_Target) && this.FindCharacterForPayload(player) is { } obj) { - this.Ui.Plugin.TargetManager.SetTarget(obj); + this.Ui.Plugin.TargetManager.Target = obj; } // View Party Finder 0x2E diff --git a/ChatTwo/Plugin.cs b/ChatTwo/Plugin.cs index 8725110..56cb3f4 100755 --- a/ChatTwo/Plugin.cs +++ b/ChatTwo/Plugin.cs @@ -3,17 +3,10 @@ using System.Globalization; using ChatTwo.Ipc; using ChatTwo.Resources; using ChatTwo.Util; -using Dalamud.Data; -using Dalamud.Game; -using Dalamud.Game.ClientState; -using Dalamud.Game.ClientState.Conditions; -using Dalamud.Game.ClientState.Keys; using Dalamud.Game.ClientState.Objects; -using Dalamud.Game.ClientState.Party; -using Dalamud.Game.Command; -using Dalamud.Game.Gui; using Dalamud.IoC; using Dalamud.Plugin; +using Dalamud.Plugin.Services; using XivCommon; namespace ChatTwo; @@ -22,43 +15,55 @@ namespace ChatTwo; public sealed class Plugin : IDalamudPlugin { internal const string PluginName = "Chat 2"; - public string Name => PluginName; + internal static string Name => PluginName; + + [PluginService] + internal static IPluginLog Log { get; private set; } [PluginService] internal DalamudPluginInterface Interface { get; init; } [PluginService] - internal ChatGui ChatGui { get; init; } + internal IChatGui ChatGui { get; init; } [PluginService] - internal ClientState ClientState { get; init; } + internal IClientState ClientState { get; init; } [PluginService] - internal CommandManager CommandManager { get; init; } + internal ICommandManager CommandManager { get; init; } [PluginService] - internal Condition Condition { get; init; } + internal ICondition Condition { get; init; } [PluginService] - internal DataManager DataManager { get; init; } + internal IDataManager DataManager { get; init; } [PluginService] - internal Framework Framework { get; init; } + internal IFramework Framework { get; init; } [PluginService] - internal GameGui GameGui { get; init; } + internal IGameGui GameGui { get; init; } [PluginService] - internal KeyState KeyState { get; init; } + internal IKeyState KeyState { get; init; } [PluginService] - internal ObjectTable ObjectTable { get; init; } + internal IObjectTable ObjectTable { get; init; } [PluginService] - internal PartyList PartyList { get; init; } + internal IPartyList PartyList { get; init; } [PluginService] - internal TargetManager TargetManager { get; init; } + internal ITargetManager TargetManager { get; init; } + + [PluginService] + internal ITextureProvider TextureProvider { get; init; } + + [PluginService] + internal IGameInteropProvider GameInteropProvider { get; init; } + + [PluginService] + internal IGameConfig GameConfig { get; init; } internal Configuration Config { get; } internal Commands Commands { get; } @@ -89,7 +94,7 @@ public sealed class Plugin : IDalamudPlugin { this.Commands = new Commands(this); this.Common = new XivCommonBase(); - this.TextureCache = new TextureCache(this.DataManager!); + this.TextureCache = new TextureCache(this.TextureProvider!); this.Functions = new GameFunctions.GameFunctions(this); this.Store = new Store(this); this.Ipc = new IpcManager(this.Interface); @@ -143,7 +148,7 @@ public sealed class Plugin : IDalamudPlugin { "ChatLogPanel_3", }; - private void FrameworkUpdate(Framework framework) { + private void FrameworkUpdate(IFramework framework) { if (this.DeferredSaveFrames >= 0 && this.DeferredSaveFrames-- == 0) { this.SaveConfig(); } diff --git a/ChatTwo/Store.cs b/ChatTwo/Store.cs index e118554..6239015 100755 --- a/ChatTwo/Store.cs +++ b/ChatTwo/Store.cs @@ -4,10 +4,10 @@ using System.Numerics; using ChatTwo.Code; using ChatTwo.Resources; using ChatTwo.Util; -using Dalamud.Game; using Dalamud.Game.Text; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Logging; +using Dalamud.Plugin.Services; using ImGuiNET; using LiteDB; using Lumina.Excel.GeneratedSheets; @@ -177,18 +177,18 @@ internal class Store : IDisposable { this.Database = this.Connect(); } - private void Logout(object? sender, EventArgs eventArgs) { + private void Logout() { this.LastContentId = 0; } - private void UpdateReceiver(Framework framework) { + private void UpdateReceiver(IFramework framework) { var contentId = this.Plugin.ClientState.LocalContentId; if (contentId != 0) { this.LastContentId = contentId; } } - private void GetMessageInfo(Framework framework) { + private void GetMessageInfo(IFramework framework) { if (this.CheckpointTimer.Elapsed > TimeSpan.FromMinutes(5)) { this.CheckpointTimer.Restart(); new Thread(() => this.Database.Checkpoint()).Start(); @@ -210,7 +210,7 @@ internal class Store : IDisposable { private void MigrateDraw() { ImGui.SetNextWindowSizeConstraints(new Vector2(450, 0), new Vector2(450, float.MaxValue)); - if (!ImGui.Begin($"{this.Plugin.Name}##migration-window", ImGuiWindowFlags.AlwaysAutoResize)) { + if (!ImGui.Begin($"{Plugin.Name}##migration-window", ImGuiWindowFlags.AlwaysAutoResize)) { ImGui.End(); return; } diff --git a/ChatTwo/TextureCache.cs b/ChatTwo/TextureCache.cs index f9dc007..6c0caad 100755 --- a/ChatTwo/TextureCache.cs +++ b/ChatTwo/TextureCache.cs @@ -1,22 +1,22 @@ -using Dalamud.Data; -using ImGuiScene; +using Dalamud.Interface.Internal; +using Dalamud.Plugin.Services; using Lumina.Excel.GeneratedSheets; namespace ChatTwo; internal class TextureCache : IDisposable { - private DataManager Data { get; } + private ITextureProvider TextureProvider { get; } - private readonly Dictionary<(uint, bool), TextureWrap> _itemIcons = new(); - private readonly Dictionary<(uint, bool), TextureWrap> _statusIcons = new(); - private readonly Dictionary<(uint, bool), TextureWrap> _eventItemIcons = new(); + private readonly Dictionary<(uint, bool), IDalamudTextureWrap> _itemIcons = new(); + private readonly Dictionary<(uint, bool), IDalamudTextureWrap> _statusIcons = new(); + private readonly Dictionary<(uint, bool), IDalamudTextureWrap> _eventItemIcons = new(); - internal IReadOnlyDictionary<(uint, bool), TextureWrap> ItemIcons => this._itemIcons; - internal IReadOnlyDictionary<(uint, bool), TextureWrap> StatusIcons => this._statusIcons; - internal IReadOnlyDictionary<(uint, bool), TextureWrap> EventItemIcons => this._eventItemIcons; + internal IReadOnlyDictionary<(uint, bool), IDalamudTextureWrap> ItemIcons => this._itemIcons; + internal IReadOnlyDictionary<(uint, bool), IDalamudTextureWrap> StatusIcons => this._statusIcons; + internal IReadOnlyDictionary<(uint, bool), IDalamudTextureWrap> EventItemIcons => this._eventItemIcons; - internal TextureCache(DataManager data) { - this.Data = data; + internal TextureCache(ITextureProvider textureProvider) { + this.TextureProvider = textureProvider; } public void Dispose() { @@ -28,14 +28,14 @@ internal class TextureCache : IDisposable { } } - private void AddIcon(IDictionary<(uint, bool), TextureWrap> dict, uint icon, bool hq = false) { + private void AddIcon(IDictionary<(uint, bool), IDalamudTextureWrap> dict, uint icon, bool hq = false) { if (dict.ContainsKey((icon, hq))) { return; } var tex = hq - ? this.Data.GetImGuiTextureHqIcon(icon) - : this.Data.GetImGuiTextureIcon(icon); + ? this.TextureProvider.GetIcon(icon, ITextureProvider.IconFlags.ItemHighQuality) + : this.TextureProvider.GetIcon(icon); if (tex != null) { dict[(icon, hq)] = tex; } @@ -53,19 +53,19 @@ internal class TextureCache : IDisposable { this.AddIcon(this._eventItemIcons, item.Icon); } - internal TextureWrap? GetItem(Item item, bool hq = false) { + internal IDalamudTextureWrap? GetItem(Item item, bool hq = false) { this.AddItem(item, hq); this.ItemIcons.TryGetValue((item.Icon, hq), out var icon); return icon; } - internal TextureWrap? GetStatus(Status status) { + internal IDalamudTextureWrap? GetStatus(Status status) { this.AddStatus(status); this.StatusIcons.TryGetValue((status.Icon, false), out var icon); return icon; } - internal TextureWrap? GetEventItem(EventItem item) { + internal IDalamudTextureWrap? GetEventItem(EventItem item) { this.AddEventItem(item); this.EventItemIcons.TryGetValue((item.Icon, false), out var icon); return icon; diff --git a/ChatTwo/Ui/ChatLog.cs b/ChatTwo/Ui/ChatLog.cs index 54a3425..83c2afa 100755 --- a/ChatTwo/Ui/ChatLog.cs +++ b/ChatTwo/Ui/ChatLog.cs @@ -11,10 +11,11 @@ using Dalamud.Game.ClientState.Keys; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Interface; +using Dalamud.Interface.Internal; +using Dalamud.Interface.Utility; using Dalamud.Logging; using Dalamud.Memory; using ImGuiNET; -using ImGuiScene; using Lumina.Excel.GeneratedSheets; namespace ChatTwo.Ui; @@ -28,7 +29,7 @@ internal sealed class ChatLog : IUiComponent { internal bool Activate; private int _activatePos = -1; internal string Chat = string.Empty; - private readonly TextureWrap? _fontIcon; + private readonly IDalamudTextureWrap? _fontIcon; private readonly List _inputBacklog = new(); private int _inputBacklogIdx = -1; internal int LastTab { get; private set; } @@ -62,7 +63,7 @@ internal sealed class ChatLog : IUiComponent { this.Ui.Plugin.Commands.Register("/clearlog2", "Clear the Chat 2 chat log").Execute += this.ClearLog; this.Ui.Plugin.Commands.Register("/chat2").Execute += this.ToggleChat; - this._fontIcon = this.Ui.Plugin.DataManager.GetImGuiTexture("common/font/fonticon_ps5.tex"); + this._fontIcon = this.Ui.Plugin.TextureProvider.GetTextureFromGame("common/font/fonticon_ps5.tex"); this.Ui.Plugin.Functions.Chat.Activated += this.Activated; this.Ui.Plugin.ClientState.Login += this.Login; @@ -78,13 +79,13 @@ internal sealed class ChatLog : IUiComponent { this.Ui.Plugin.Commands.Register("/clearlog2").Execute -= this.ClearLog; } - private void Logout(object? sender, EventArgs e) { + private void Logout() { foreach (var tab in this.Ui.Plugin.Config.Tabs) { tab.Clear(); } } - private void Login(object? sender, EventArgs e) { + private void Login() { this.Ui.Plugin.Store.FilterAllTabs(false); } @@ -415,7 +416,7 @@ internal sealed class ChatLog : IUiComponent { ImGui.SetNextWindowSize(new Vector2(500, 250) * ImGuiHelpers.GlobalScale, ImGuiCond.FirstUseEver); - if (!ImGui.Begin($"{this.Ui.Plugin.Name}###chat2", flags)) { + if (!ImGui.Begin($"{Plugin.Name}###chat2", flags)) { this._lastViewport = ImGui.GetWindowViewport().NativePtr; this._wasDocked = ImGui.IsWindowDocked(); ImGui.End(); diff --git a/ChatTwo/Ui/CommandHelp.cs b/ChatTwo/Ui/CommandHelp.cs index d3b2627..644a398 100755 --- a/ChatTwo/Ui/CommandHelp.cs +++ b/ChatTwo/Ui/CommandHelp.cs @@ -1,6 +1,6 @@ using System.Numerics; using ChatTwo.Util; -using Dalamud.Interface; +using Dalamud.Interface.Utility; using Dalamud.Utility; using ImGuiNET; using Lumina.Excel.GeneratedSheets; diff --git a/ChatTwo/Ui/Settings.cs b/ChatTwo/Ui/Settings.cs index c67fe3c..408096c 100755 --- a/ChatTwo/Ui/Settings.cs +++ b/ChatTwo/Ui/Settings.cs @@ -3,7 +3,7 @@ using System.Numerics; using ChatTwo.Resources; using ChatTwo.Ui.SettingsTabs; using ChatTwo.Util; -using Dalamud.Interface; +using Dalamud.Interface.Utility; using ImGuiNET; namespace ChatTwo.Ui; @@ -61,7 +61,7 @@ internal sealed class Settings : IUiComponent { ImGui.SetNextWindowSize(new Vector2(475, 600) * ImGuiHelpers.GlobalScale, ImGuiCond.FirstUseEver); - var name = string.Format(Language.Settings_Title, this.Ui.Plugin.Name); + var name = string.Format(Language.Settings_Title, Plugin.Name); if (!ImGui.Begin($"{name}###chat2-settings", ref this.Ui.SettingsVisible, ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse)) { ImGui.End(); return; @@ -117,7 +117,7 @@ internal sealed class Settings : IUiComponent { this.Ui.SettingsVisible = false; } - var buttonLabel = string.Format(Language.Settings_Kofi, this.Ui.Plugin.Name); + var buttonLabel = string.Format(Language.Settings_Kofi, Plugin.Name); ImGui.PushStyleColor(ImGuiCol.Button, ColourUtil.RgbaToAbgr(0xFF5E5BFF)); ImGui.PushStyleColor(ImGuiCol.ButtonHovered, ColourUtil.RgbaToAbgr(0xFF7775FF)); diff --git a/ChatTwo/Util/AutoTranslate.cs b/ChatTwo/Util/AutoTranslate.cs index 6bb61c9..7c85e26 100644 --- a/ChatTwo/Util/AutoTranslate.cs +++ b/ChatTwo/Util/AutoTranslate.cs @@ -1,9 +1,9 @@ using System.Runtime.InteropServices; using System.Text; using Dalamud; -using Dalamud.Data; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling.Payloads; +using Dalamud.Plugin.Services; using Dalamud.Utility; using Lumina.Excel; using Lumina.Excel.GeneratedSheets; @@ -89,7 +89,7 @@ internal static class AutoTranslate { return string.Join("", payloads); } - private static List AllEntries(DataManager data) { + private static List AllEntries(IDataManager data) { if (Entries.TryGetValue(data.Language, out var entries)) { return entries; } @@ -197,7 +197,7 @@ internal static class AutoTranslate { return list; } - internal static List Matching(DataManager data, string prefix, bool sort) { + internal static List Matching(IDataManager data, string prefix, bool sort) { var wholeMatches = new List(); var prefixMatches = new List(); var otherMatches = new List(); @@ -227,7 +227,7 @@ internal static class AutoTranslate { [DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)] private static extern int memcmp(byte[] b1, byte[] b2, UIntPtr count); - internal static void ReplaceWithPayload(DataManager data, ref byte[] bytes) { + internal static void ReplaceWithPayload(IDataManager data, ref byte[] bytes) { var search = Encoding.UTF8.GetBytes("