From 8cc324ba840419fbb903370b1017161ba9f3a584 Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 28 Sep 2023 20:53:50 -0400 Subject: [PATCH] refactor: update for api 9 --- client/Messages.cs | 24 ++++++++----------- client/MiniPenumbra/VfxReplacer.cs | 2 +- client/OrangeGuidanceTomestone.csproj | 4 ---- client/Pinger.cs | 7 +++--- client/Plugin.cs | 33 ++++++++++++++------------- client/PluginUi.cs | 4 ++-- client/Ui/MainWindow.cs | 4 ++-- client/Ui/MainWindowTabs/Write.cs | 4 ++-- client/Ui/Viewer.cs | 1 + client/Vfx.cs | 6 ++--- 10 files changed, 40 insertions(+), 49 deletions(-) diff --git a/client/Messages.cs b/client/Messages.cs index 3505308..b388212 100644 --- a/client/Messages.cs +++ b/client/Messages.cs @@ -1,9 +1,7 @@ using System.Diagnostics; using System.Numerics; -using Dalamud.Data; -using Dalamud.Game; using Dalamud.Game.ClientState.Conditions; -using Dalamud.Logging; +using Dalamud.Plugin.Services; using Lumina.Excel.GeneratedSheets; using Newtonsoft.Json; using OrangeGuidanceTomestone.Helpers; @@ -20,7 +18,7 @@ internal class Messages : IDisposable { "bg/ex2/02_est_e3/common/vfx/eff/b0941trp1f_o.avfx", }; - private static string GetPath(DataManager data, Message message) { + private static string GetPath(IDataManager data, Message message) { var glyph = message.Glyph; if (glyph < 0 || glyph >= VfxPaths.Length) { // not checking if this exists, but the check is really only for the @@ -105,7 +103,7 @@ internal class Messages : IDisposable { private readonly Stopwatch _timer = new(); - private void TerritoryChanged(object? sender, ushort e) { + private void TerritoryChanged(ushort territory) { this._territoryChanged = true; this.RemoveVfx(); } @@ -113,7 +111,7 @@ internal class Messages : IDisposable { private ushort _lastTerritory; private bool _territoryChanged; - private void DetermineIfSpawn(Framework framework) { + private void DetermineIfSpawn(IFramework framework) { var current = this.Plugin.ClientState.TerritoryType; var diffTerritory = current != this._lastTerritory; @@ -132,7 +130,7 @@ internal class Messages : IDisposable { this._lastTerritory = current; } - private void RemoveConditionally(Framework framework) { + private void RemoveConditionally(IFramework framework) { var nowCutscene = this.CutsceneActive; var cutsceneChanged = this._inCutscene != nowCutscene; if (this.Plugin.Config.DisableInCutscene && cutsceneChanged) { @@ -157,24 +155,20 @@ internal class Messages : IDisposable { this._inGpose = nowGpose; } - private unsafe void HandleSpawnQueue(Framework framework) { + private unsafe void HandleSpawnQueue(IFramework framework) { if (!this.SpawnQueue.TryDequeue(out var message)) { return; } - PluginLog.Debug($"spawning vfx for {message.Id}"); + Plugin.Log.Debug($"spawning vfx for {message.Id}"); var rotation = Quaternion.CreateFromYawPitchRoll(message.Yaw, 0, 0); var path = GetPath(this.Plugin.DataManager, message); if (this.Plugin.Vfx.SpawnStatic(message.Id, path, message.Position, rotation) == null) { - PluginLog.Debug("trying again"); + Plugin.Log.Debug("trying again"); this.SpawnQueue.Enqueue(message); } } - private void SpawnVfx(object? sender, EventArgs e) { - this.SpawnVfx(); - } - internal void SpawnVfx() { var territory = this.Plugin.ClientState.TerritoryType; if (territory == 0 || this.Plugin.Config.BannedTerritories.Contains(territory)) { @@ -212,7 +206,7 @@ internal class Messages : IDisposable { try { await this.DownloadMessages(world, territory, ward, plot); } catch (Exception ex) { - PluginLog.LogError(ex, $"Failed to get messages for territory {territory}"); + Plugin.Log.Error(ex, $"Failed to get messages for territory {territory}"); } }); } diff --git a/client/MiniPenumbra/VfxReplacer.cs b/client/MiniPenumbra/VfxReplacer.cs index 2face2f..318c7d7 100644 --- a/client/MiniPenumbra/VfxReplacer.cs +++ b/client/MiniPenumbra/VfxReplacer.cs @@ -16,7 +16,7 @@ internal unsafe class VfxReplacer : IDisposable { internal VfxReplacer(Plugin plugin) { this.Plugin = plugin; - SignatureHelper.Initialise(this); + this.Plugin.GameInteropProvider.InitializeFromAttributes(this); this._readSqPackHook!.Enable(); } diff --git a/client/OrangeGuidanceTomestone.csproj b/client/OrangeGuidanceTomestone.csproj index 26c0f33..59b7e00 100755 --- a/client/OrangeGuidanceTomestone.csproj +++ b/client/OrangeGuidanceTomestone.csproj @@ -39,10 +39,6 @@ $(DalamudLibPath)\ImGui.NET.dll false - - $(DalamudLibPath)\ImGuiScene.dll - false - $(DalamudLibPath)\Lumina.dll false diff --git a/client/Pinger.cs b/client/Pinger.cs index fa2759d..cc07cb9 100644 --- a/client/Pinger.cs +++ b/client/Pinger.cs @@ -1,6 +1,5 @@ using System.Diagnostics; -using Dalamud.Game; -using Dalamud.Logging; +using Dalamud.Plugin.Services; using OrangeGuidanceTomestone.Helpers; namespace OrangeGuidanceTomestone; @@ -22,7 +21,7 @@ internal class Pinger : IDisposable { this.Plugin.Framework.Update -= this.Ping; } - private void Ping(Framework framework) { + private void Ping(IFramework framework) { if (this.Stopwatch.Elapsed < TimeSpan.FromSeconds(this._waitSecs)) { return; } @@ -45,7 +44,7 @@ internal class Pinger : IDisposable { ); if (!resp.IsSuccessStatusCode) { - PluginLog.LogWarning($"Failed to ping, status {resp.StatusCode}"); + Plugin.Log.Warning($"Failed to ping, status {resp.StatusCode}"); } }); } diff --git a/client/Plugin.cs b/client/Plugin.cs index 71bac26..d1b7222 100644 --- a/client/Plugin.cs +++ b/client/Plugin.cs @@ -1,42 +1,43 @@ -using Dalamud.Data; -using Dalamud.Game; -using Dalamud.Game.ClientState; -using Dalamud.Game.ClientState.Conditions; -using Dalamud.Game.Command; -using Dalamud.Game.Gui; -using Dalamud.IoC; +using Dalamud.IoC; using Dalamud.Plugin; +using Dalamud.Plugin.Services; using OrangeGuidanceTomestone.MiniPenumbra; using XivCommon; namespace OrangeGuidanceTomestone; public class Plugin : IDalamudPlugin { - public string Name => "Orange Guidance Tomestone"; + internal static string Name => "Orange Guidance Tomestone"; + + [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 IGameInteropProvider GameInteropProvider { get; init; } internal Configuration Config { get; } internal XivCommonBase Common { get; } @@ -54,7 +55,7 @@ public class Plugin : IDalamudPlugin { this.Config = this.Interface!.GetPluginConfig() as Configuration ?? new Configuration(); this.Common = new XivCommonBase(); - this.Vfx = new Vfx(); + this.Vfx = new Vfx(this); this.Messages = new Messages(this); this.Ui = new PluginUi(this); this.VfxReplacer = new VfxReplacer(this); diff --git a/client/PluginUi.cs b/client/PluginUi.cs index 941fa52..b773ea3 100644 --- a/client/PluginUi.cs +++ b/client/PluginUi.cs @@ -41,13 +41,13 @@ public class PluginUi : IDisposable { private void DrawModals() { while (this.ToShow.TryDequeue(out var toShow)) { - ImGui.OpenPopup($"{this.Plugin.Name}##{toShow}"); + ImGui.OpenPopup($"{Plugin.Name}##{toShow}"); } var toRemove = -1; for (var i = 0; i < this.Modals.Count; i++) { var (id, text) = this.Modals[i]; - if (!ImGui.BeginPopupModal($"{this.Plugin.Name}##{id}")) { + if (!ImGui.BeginPopupModal($"{Plugin.Name}##{id}")) { continue; } diff --git a/client/Ui/MainWindow.cs b/client/Ui/MainWindow.cs index 4453de4..4545776 100644 --- a/client/Ui/MainWindow.cs +++ b/client/Ui/MainWindow.cs @@ -26,7 +26,7 @@ internal class MainWindow { } ImGui.SetNextWindowSize(new Vector2(475, 350), ImGuiCond.FirstUseEver); - if (!ImGui.Begin(this.Plugin.Name, ref this.Visible)) { + if (!ImGui.Begin(Plugin.Name, ref this.Visible)) { ImGui.End(); return; } @@ -65,7 +65,7 @@ internal class MainWindow { private void DrawApiKey() { ImGui.PushTextWrapPos(); - ImGui.TextUnformatted($"Somehow, {this.Plugin.Name} wasn't able to register you an account automatically."); + ImGui.TextUnformatted($"Somehow, {Plugin.Name} wasn't able to register you an account automatically."); ImGui.TextUnformatted("Click the button below to try again."); ImGui.PopTextWrapPos(); diff --git a/client/Ui/MainWindowTabs/Write.cs b/client/Ui/MainWindowTabs/Write.cs index 40b13d4..666b0ae 100644 --- a/client/Ui/MainWindowTabs/Write.cs +++ b/client/Ui/MainWindowTabs/Write.cs @@ -1,8 +1,8 @@ using System.Numerics; using System.Text; using Dalamud.Game.ClientState.Conditions; +using Dalamud.Interface.Internal; using ImGuiNET; -using ImGuiScene; using Newtonsoft.Json; using OrangeGuidanceTomestone.Helpers; @@ -21,7 +21,7 @@ internal class Write : ITab { private (int, int) _word2 = (-1, -1); private int _glyph; - private List GlyphImages { get; } = new(); + private List GlyphImages { get; } = new(); private void LoadSignImages() { for (var i = 0; i < Messages.VfxPaths.Length; i++) { diff --git a/client/Ui/Viewer.cs b/client/Ui/Viewer.cs index 4faa7fc..8f86843 100644 --- a/client/Ui/Viewer.cs +++ b/client/Ui/Viewer.cs @@ -1,5 +1,6 @@ using System.Numerics; using Dalamud.Interface; +using Dalamud.Interface.Utility; using ImGuiNET; using OrangeGuidanceTomestone.Helpers; diff --git a/client/Vfx.cs b/client/Vfx.cs index 53b8bf1..37f1791 100644 --- a/client/Vfx.cs +++ b/client/Vfx.cs @@ -6,7 +6,7 @@ using Dalamud.Utility.Signatures; namespace OrangeGuidanceTomestone; internal unsafe class Vfx : IDisposable { - private static readonly byte[] Pool = Encoding.UTF8.GetBytes("Client.System.Scheduler.Instance.VfxObject"); + private static readonly byte[] Pool = "Client.System.Scheduler.Instance.VfxObject"u8.ToArray(); [Signature("E8 ?? ?? ?? ?? F3 0F 10 35 ?? ?? ?? ?? 48 89 43 08")] private delegate* unmanaged _staticVfxCreate; @@ -19,8 +19,8 @@ internal unsafe class Vfx : IDisposable { private Dictionary Spawned { get; } = new(); - internal Vfx() { - SignatureHelper.Initialise(this); + internal Vfx(Plugin plugin) { + plugin.GameInteropProvider.InitializeFromAttributes(this); } public void Dispose() {