diff --git a/XivCommon/GameFunctions.cs b/XivCommon/GameFunctions.cs index 6fa4b41..1925298 100755 --- a/XivCommon/GameFunctions.cs +++ b/XivCommon/GameFunctions.cs @@ -1,5 +1,5 @@ using System; -using Dalamud.Game; +using Dalamud.Plugin; using Dalamud.Plugin.Services; using FFXIVClientStructs.FFXIV.Client.UI.Agent; using FFXIVClientStructs.FFXIV.Component.GUI; @@ -82,16 +82,21 @@ public class GameFunctions : IDisposable { /// public Housing Housing { get; } - internal GameFunctions(Hooks hooks) { - Logger.Log = Util.GetService(); + internal GameFunctions(DalamudPluginInterface @interface, Hooks hooks) { + var services = @interface.Create(); + if (services == null) { + throw new Exception("could not create services"); + } - this.Framework = Util.GetService(); - this.GameGui = Util.GetService(); + Logger.Log = services.Log; - var interop = Util.GetService(); - var objectTable = Util.GetService(); - var partyFinderGui = Util.GetService(); - var scanner = Util.GetService(); + this.Framework = services.Framework; + this.GameGui = services.GameGui; + + var interop = services.GameInteropProvider; + var objectTable = services.ObjectTable; + var partyFinderGui = services.PartyFinderGui; + var scanner = services.SigScanner; this.UiAlloc = new UiAlloc(scanner); this.Chat = new Chat(scanner); diff --git a/XivCommon/Services.cs b/XivCommon/Services.cs new file mode 100644 index 0000000..b89f6a0 --- /dev/null +++ b/XivCommon/Services.cs @@ -0,0 +1,28 @@ +using Dalamud.Game; +using Dalamud.IoC; +using Dalamud.Plugin.Services; + +namespace XivCommon; + +internal class Services { + [PluginService] + internal IPluginLog Log { get; private set; } + + [PluginService] + internal IFramework Framework { get; private set; } + + [PluginService] + internal IGameGui GameGui { get; private set; } + + [PluginService] + internal IGameInteropProvider GameInteropProvider { get; private set; } + + [PluginService] + internal IObjectTable ObjectTable { get; private set; } + + [PluginService] + internal IPartyFinderGui PartyFinderGui { get; private set; } + + [PluginService] + internal ISigScanner SigScanner { get; private set; } +} diff --git a/XivCommon/Util.cs b/XivCommon/Util.cs index 63c3697..af641b5 100755 --- a/XivCommon/Util.cs +++ b/XivCommon/Util.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.Reflection; using Dalamud.Game.Text.SeStringHandling; -using Dalamud.Plugin; namespace XivCommon; @@ -40,12 +38,6 @@ internal static class Util { Logger.Log.Warning($"Could not find signature for {name}. This functionality will be disabled."); } - internal static T GetService() { - var service = typeof(IDalamudPlugin).Assembly.GetType("Dalamud.Service`1")!.MakeGenericType(typeof(T)); - var get = service.GetMethod("Get", BindingFlags.Public | BindingFlags.Static)!; - return (T) get.Invoke(null, null)!; - } - internal static unsafe IntPtr FollowPointerChain(IntPtr start, IEnumerable offsets) { if (start == IntPtr.Zero) { return IntPtr.Zero; diff --git a/XivCommon/XivCommon.csproj b/XivCommon/XivCommon.csproj index 7402018..28cba85 100755 --- a/XivCommon/XivCommon.csproj +++ b/XivCommon/XivCommon.csproj @@ -5,7 +5,7 @@ latest true enable - 8.0.0 + 9.0.0 full diff --git a/XivCommon/XivCommonBase.cs b/XivCommon/XivCommonBase.cs index db6df8f..992d54b 100755 --- a/XivCommon/XivCommonBase.cs +++ b/XivCommon/XivCommonBase.cs @@ -1,4 +1,5 @@ using System; +using Dalamud.Plugin; namespace XivCommon; @@ -20,8 +21,8 @@ public class XivCommonBase : IDisposable { /// /// /// Flags indicating which hooks to enable - public XivCommonBase(Hooks hooks = HooksExt.DefaultHooks) { - this.Functions = new GameFunctions(hooks); + public XivCommonBase(DalamudPluginInterface @interface, Hooks hooks = HooksExt.DefaultHooks) { + this.Functions = new GameFunctions(@interface, hooks); } ///