From b939825923313410f411b8e0aa1aaef5ff3df9e0 Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 28 Sep 2023 02:05:06 -0400 Subject: [PATCH] refactor: update for api 9 --- Tourist/GameFunctions.cs | 5 ++--- Tourist/Markers.cs | 9 ++++----- Tourist/Plugin.cs | 28 ++++++++++++++++------------ Tourist/PluginUi.cs | 2 +- Tourist/Util.cs | 4 ++-- 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/Tourist/GameFunctions.cs b/Tourist/GameFunctions.cs index af40561..c96f51f 100644 --- a/Tourist/GameFunctions.cs +++ b/Tourist/GameFunctions.cs @@ -2,7 +2,6 @@ using System.Numerics; using System.Runtime.InteropServices; using Dalamud.Hooking; -using Dalamud.Logging; namespace Tourist { public class GameFunctions : IDisposable { @@ -26,7 +25,7 @@ namespace Tourist { this.Plugin = plugin; var vistaUnlockedPtr = this.Plugin.SigScanner.ScanText("E8 ?? ?? ?? ?? E9 ?? ?? ?? ?? 8B CE E8 ?? ?? ?? ?? E9 ?? ?? ?? ?? 44 8B 7C 24"); - this.VistaUnlockedHook = Hook.FromAddress(vistaUnlockedPtr, this.OnVistaUnlock); + this.VistaUnlockedHook = this.Plugin.GameInteropProvider.HookFromAddress(vistaUnlockedPtr, this.OnVistaUnlock); this.VistaUnlockedHook.Enable(); var maskPtr = this.Plugin.SigScanner.GetStaticAddressFromSig("8B F2 48 8D 0D ?? ?? ?? ?? 8B D3"); @@ -50,7 +49,7 @@ namespace Tourist { try { this.Plugin.Markers.RemoveVfx(index); } catch (Exception ex) { - PluginLog.LogError(ex, "Exception in vista unlock"); + Plugin.Log.Error(ex, "Exception in vista unlock"); } return this.VistaUnlockedHook.Original(index, a2, a3); diff --git a/Tourist/Markers.cs b/Tourist/Markers.cs index b9e1836..2dd36ee 100644 --- a/Tourist/Markers.cs +++ b/Tourist/Markers.cs @@ -2,8 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Numerics; -using Dalamud.Game; -using Dalamud.Logging; +using Dalamud.Plugin.Services; using Lumina.Excel.GeneratedSheets; namespace Tourist { @@ -77,7 +76,7 @@ namespace Tourist { } } - private void OnTerritoryChange(object? sender, ushort territory) { + private void OnTerritoryChange(ushort territory) { if (!this.Plugin.Config.ShowArrVistas) { return; } @@ -86,11 +85,11 @@ namespace Tourist { this.RemoveAllVfx(); this.SpawnVfxForCurrentZone(territory); } catch (Exception ex) { - PluginLog.LogError(ex, "Exception in territory change"); + Plugin.Log.Error(ex, "Exception in territory change"); } } - private void OnFrameworkUpdate(Framework framework) { + private void OnFrameworkUpdate(IFramework framework1) { foreach (var vfx in this.Queue.ToArray()) { if (this.Plugin.Functions.PlayVfx(vfx)) { this.Queue.Remove(vfx); diff --git a/Tourist/Plugin.cs b/Tourist/Plugin.cs index 7ac5ece..84246b4 100644 --- a/Tourist/Plugin.cs +++ b/Tourist/Plugin.cs @@ -1,36 +1,40 @@ -using Dalamud.Data; -using Dalamud.Game; -using Dalamud.Game.ClientState; -using Dalamud.Game.Command; -using Dalamud.Game.Gui; +using Dalamud.Game; using Dalamud.IoC; using Dalamud.Plugin; +using Dalamud.Plugin.Services; using FFXIVWeather.Lumina; namespace Tourist { // ReSharper disable once ClassNeverInstantiated.Global public class Plugin : IDalamudPlugin { - public string Name => "Tourist"; + public static string Name => "Tourist"; + [PluginService] + internal static IPluginLog Log { get; private set; } = null!; + + [PluginService] internal DalamudPluginInterface Interface { get; } [PluginService] - internal ClientState ClientState { get; init; } = null!; + internal IClientState ClientState { get; init; } = null!; [PluginService] - internal CommandManager CommandManager { get; init; } = null!; + internal ICommandManager CommandManager { get; init; } = null!; [PluginService] - internal DataManager DataManager { get; init; } = null!; + internal IDataManager DataManager { get; init; } = null!; [PluginService] - internal Framework Framework { get; init; } = null!; + internal IFramework Framework { get; init; } = null!; [PluginService] - internal GameGui GameGui { get; init; } = null!; + internal IGameGui GameGui { get; init; } = null!; [PluginService] - internal SigScanner SigScanner { get; init; } = null!; + internal ISigScanner SigScanner { get; init; } = null!; + + [PluginService] + internal IGameInteropProvider GameInteropProvider { get; init; } = null!; internal Configuration Config { get; } internal PluginUi Ui { get; } diff --git a/Tourist/PluginUi.cs b/Tourist/PluginUi.cs index 9ca681c..61b2334 100644 --- a/Tourist/PluginUi.cs +++ b/Tourist/PluginUi.cs @@ -39,7 +39,7 @@ namespace Tourist { return; } - if (!ImGui.Begin(this.Plugin.Name, ref this._show, ImGuiWindowFlags.MenuBar)) { + if (!ImGui.Begin(Plugin.Name, ref this._show, ImGuiWindowFlags.MenuBar)) { ImGui.End(); return; } diff --git a/Tourist/Util.cs b/Tourist/Util.cs index b2354e5..152b6b8 100644 --- a/Tourist/Util.cs +++ b/Tourist/Util.cs @@ -2,8 +2,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using Dalamud.Game.Gui; using Dalamud.Game.Text.SeStringHandling.Payloads; +using Dalamud.Plugin.Services; using FFXIVWeather.Lumina; using Lumina.Excel.GeneratedSheets; @@ -11,7 +11,7 @@ namespace Tourist { public static class Util { private static Dictionary Availability { get; } = new(); - public static void OpenMapLocation(this GameGui gameGui, Adventure adventure) { + public static void OpenMapLocation(this IGameGui gameGui, Adventure adventure) { var loc = adventure.Level?.Value; var map = loc?.Map?.Value; var terr = map?.TerritoryType?.Value;