From ad34b072aad09f92076e38f4f07e81bad23213c6 Mon Sep 17 00:00:00 2001 From: Stoia Date: Wed, 4 Oct 2023 16:45:37 +0200 Subject: [PATCH] API9 and 6.5 Compat --- CustomizePlus/Api/CustomizePlusIpc.cs | 5 ++-- CustomizePlus/CustomizePlus.csproj | 6 ++--- CustomizePlus/Data/Armature/Armature.cs | 1 + .../Data/Armature/ArmatureManager.cs | 1 + .../Configuration/ConfigurationManager.cs | 1 + CustomizePlus/Data/Files.cs | 8 +++--- .../Data/Profile/ProfileReaderWriter.cs | 1 + .../Extensions/CommandManagerExtensions.cs | 4 ++- .../Extensions/ObjectTableExtensions.cs | 6 +++-- CustomizePlus/Helpers/ChatHelper.cs | 1 + CustomizePlus/Helpers/GameDataHelper.cs | 1 + CustomizePlus/Plugin.cs | 9 +++---- .../{ => Services}/DalamudServices.cs | 26 ++++++++++++------- CustomizePlus/Services/GPoseService.cs | 7 ++--- .../Services/PosingModeDetectService.cs | 1 + .../UI/Windows/Debug/IPCTestWindow.cs | 1 + CustomizePlus/UI/Windows/SettingsWindow.cs | 1 + CustomizePlus/customizePlus.json | 23 ++++++++-------- 18 files changed, 64 insertions(+), 39 deletions(-) rename CustomizePlus/{ => Services}/DalamudServices.cs (57%) diff --git a/CustomizePlus/Api/CustomizePlusIpc.cs b/CustomizePlus/Api/CustomizePlusIpc.cs index e8b70b3..c874956 100644 --- a/CustomizePlus/Api/CustomizePlusIpc.cs +++ b/CustomizePlus/Api/CustomizePlusIpc.cs @@ -7,6 +7,7 @@ using System.Text; using CustomizePlus.Data; using CustomizePlus.Data.Profile; +using Dalamud.Plugin.Services; using Dalamud.Game.ClientState.Objects; using Dalamud.Game.ClientState.Objects.Types; using Dalamud.Logging; @@ -24,7 +25,7 @@ public class CustomizePlusIpc : IDisposable public const string RevertCharacterLabel = $"CustomizePlus.{nameof(RevertCharacter)}"; public const string OnProfileUpdateLabel = $"CustomizePlus.{nameof(OnProfileUpdate)}"; public static readonly (int, int) ApiVersion = (3, 0); - private readonly ObjectTable _objectTable; + private readonly IObjectTable _objectTable; private readonly DalamudPluginInterface _pluginInterface; @@ -36,7 +37,7 @@ public class CustomizePlusIpc : IDisposable internal ICallGateProvider? ProviderGetProfileFromCharacter; internal ICallGateProvider<(int, int)>? ProviderGetApiVersion; - public CustomizePlusIpc(ObjectTable objectTable, DalamudPluginInterface pluginInterface) + public CustomizePlusIpc(IObjectTable objectTable, DalamudPluginInterface pluginInterface) { _objectTable = objectTable; _pluginInterface = pluginInterface; diff --git a/CustomizePlus/CustomizePlus.csproj b/CustomizePlus/CustomizePlus.csproj index b6129d2..9da7b75 100644 --- a/CustomizePlus/CustomizePlus.csproj +++ b/CustomizePlus/CustomizePlus.csproj @@ -4,7 +4,7 @@ - 1.2.5.6 + 1.2.5.7 CustomizePlus https://github.com/XIV-Tools/CustomizePlus @@ -41,8 +41,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/CustomizePlus/Data/Armature/Armature.cs b/CustomizePlus/Data/Armature/Armature.cs index 168f7d5..fb3d00d 100644 --- a/CustomizePlus/Data/Armature/Armature.cs +++ b/CustomizePlus/Data/Armature/Armature.cs @@ -14,6 +14,7 @@ using Dalamud.Game.ClientState.Objects.Types; using FFXIVClientStructs.Havok; using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolTip; +using CustomizePlus.Services; namespace CustomizePlus.Data.Armature { diff --git a/CustomizePlus/Data/Armature/ArmatureManager.cs b/CustomizePlus/Data/Armature/ArmatureManager.cs index c3475dc..f83760b 100644 --- a/CustomizePlus/Data/Armature/ArmatureManager.cs +++ b/CustomizePlus/Data/Armature/ArmatureManager.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using CustomizePlus.Data.Profile; +using CustomizePlus.Services; using Dalamud.Game.ClientState.Objects.Types; using Dalamud.Logging; diff --git a/CustomizePlus/Data/Configuration/ConfigurationManager.cs b/CustomizePlus/Data/Configuration/ConfigurationManager.cs index a2887f6..5df8902 100644 --- a/CustomizePlus/Data/Configuration/ConfigurationManager.cs +++ b/CustomizePlus/Data/Configuration/ConfigurationManager.cs @@ -6,6 +6,7 @@ using CustomizePlus.Data.Configuration.Version0; using CustomizePlus.Data.Configuration.Version2; using CustomizePlus.Helpers; +using CustomizePlus.Services; using Dalamud.Logging; using Newtonsoft.Json; diff --git a/CustomizePlus/Data/Files.cs b/CustomizePlus/Data/Files.cs index 892d421..26b1c59 100644 --- a/CustomizePlus/Data/Files.cs +++ b/CustomizePlus/Data/Files.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using System.IO; using System.Reflection; +using CustomizePlus.Services; +using Dalamud.Interface.Internal; using ImGuiScene; namespace CustomizePlus.Data @@ -12,9 +14,9 @@ namespace CustomizePlus.Data public static class Files { private static readonly List LoadedResources = new(); - private static readonly Dictionary TextureCache = new(); + private static readonly Dictionary TextureCache = new(); - public static TextureWrap Icon => LoadImage("icon.png"); + public static IDalamudTextureWrap Icon => LoadImage("icon.png"); public static void Dispose() { @@ -26,7 +28,7 @@ public static void Dispose() LoadedResources.Clear(); } - private static TextureWrap LoadImage(string file) + private static IDalamudTextureWrap LoadImage(string file) { if (TextureCache.TryGetValue(file, out var image)) return image; diff --git a/CustomizePlus/Data/Profile/ProfileReaderWriter.cs b/CustomizePlus/Data/Profile/ProfileReaderWriter.cs index f17aa22..2802f8c 100644 --- a/CustomizePlus/Data/Profile/ProfileReaderWriter.cs +++ b/CustomizePlus/Data/Profile/ProfileReaderWriter.cs @@ -8,6 +8,7 @@ using CustomizePlus.Helpers; using Dalamud.Logging; using Newtonsoft.Json; +using CustomizePlus.Services; namespace CustomizePlus.Data.Profile { diff --git a/CustomizePlus/Extensions/CommandManagerExtensions.cs b/CustomizePlus/Extensions/CommandManagerExtensions.cs index 12ce68e..f85cf9f 100644 --- a/CustomizePlus/Extensions/CommandManagerExtensions.cs +++ b/CustomizePlus/Extensions/CommandManagerExtensions.cs @@ -2,7 +2,9 @@ // Licensed under the MIT license. using System.Collections.Generic; +using CustomizePlus.Services; using Dalamud.Game.Command; +using Dalamud.Plugin.Services; namespace CustomizePlus.Extensions { @@ -10,7 +12,7 @@ public static class CommandManagerExtensions { private static readonly List BoundCommands = new(); - public static void AddCommand(this CommandManager self, CommandInfo.HandlerDelegate handler, string command, + public static void AddCommand(this ICommandManager self, CommandInfo.HandlerDelegate handler, string command, string help) { var info = new CommandInfo(handler) diff --git a/CustomizePlus/Extensions/ObjectTableExtensions.cs b/CustomizePlus/Extensions/ObjectTableExtensions.cs index 55463d7..d620647 100644 --- a/CustomizePlus/Extensions/ObjectTableExtensions.cs +++ b/CustomizePlus/Extensions/ObjectTableExtensions.cs @@ -5,6 +5,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using Dalamud.Plugin.Services; +using CustomizePlus.Services; namespace CustomizePlus.Extensions { @@ -19,7 +21,7 @@ public static class ObjectTableExtensions /// /// Whether or not to include the local player. /// An of s. - public static IEnumerable GetPlayerCharacters(this ObjectTable objectTable, bool includeSelf = true) => objectTable + public static IEnumerable GetPlayerCharacters(this IObjectTable objectTable, bool includeSelf = true) => objectTable .Where(x => x is PlayerCharacter).Cast() .Where(x => includeSelf || x.ObjectId != DalamudServices.ClientState.LocalPlayer?.ObjectId) .Where(x => x.ObjectId > 240); @@ -29,7 +31,7 @@ public static IEnumerable GetPlayerCharacters(this ObjectTable /// /// /// - public static IEnumerable GetPlayerOwnedCharacters(this ObjectTable objectTable) => objectTable + public static IEnumerable GetPlayerOwnedCharacters(this IObjectTable objectTable) => objectTable .Where(x => x is PlayerCharacter).Cast() .Where(x => x.ObjectId == DalamudServices.ClientState.LocalPlayer?.ObjectId || x.ObjectId == 200 || x.ObjectId == 201 || x.OwnerId == DalamudServices.ClientState.LocalPlayer?.ObjectId) .Where(x => x.ObjectId > 240); diff --git a/CustomizePlus/Helpers/ChatHelper.cs b/CustomizePlus/Helpers/ChatHelper.cs index 5f1fc0c..9cd919e 100644 --- a/CustomizePlus/Helpers/ChatHelper.cs +++ b/CustomizePlus/Helpers/ChatHelper.cs @@ -1,6 +1,7 @@ // © Customize+. // Licensed under the MIT license. +using CustomizePlus.Services; using Dalamud.Game.Text.SeStringHandling; namespace CustomizePlus.Helpers diff --git a/CustomizePlus/Helpers/GameDataHelper.cs b/CustomizePlus/Helpers/GameDataHelper.cs index 5867464..9dc799a 100644 --- a/CustomizePlus/Helpers/GameDataHelper.cs +++ b/CustomizePlus/Helpers/GameDataHelper.cs @@ -7,6 +7,7 @@ using System.Xml.Linq; using CustomizePlus.Data.Profile; +using CustomizePlus.Services; using Dalamud.Game.ClientState.Objects.Enums; using Dalamud.Logging; using FFXIVClientStructs.FFXIV.Client.Graphics.Scene; diff --git a/CustomizePlus/Plugin.cs b/CustomizePlus/Plugin.cs index f72706c..7e9b813 100644 --- a/CustomizePlus/Plugin.cs +++ b/CustomizePlus/Plugin.cs @@ -23,6 +23,7 @@ using Dalamud.Hooking; using Dalamud.Logging; using Dalamud.Plugin; +using Dalamud.Plugin.Services; using Newtonsoft.Json; namespace CustomizePlus @@ -47,7 +48,6 @@ public sealed class Plugin : IDalamudPlugin [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void GameObjectMovementDelegate(IntPtr gameObject); - public Plugin(DalamudPluginInterface pluginInterface) { try @@ -127,15 +127,14 @@ public static void ReloadHooks() if (_renderManagerHook == null) { var renderAddress = DalamudServices.SigScanner.ScanText(Constants.RenderHookAddress); - _renderManagerHook = Hook.FromAddress(renderAddress, OnRender); + _renderManagerHook = DalamudServices.Hooker.HookFromAddress(renderAddress, OnRender); PluginLog.Debug("Render hook established"); } if (_gameObjectMovementHook == null) { var movementAddress = DalamudServices.SigScanner.ScanText(Constants.MovementHookAddress); - _gameObjectMovementHook = - Hook.FromAddress(movementAddress, OnGameObjectMove); + _gameObjectMovementHook = DalamudServices.Hooker.HookFromAddress(movementAddress, OnGameObjectMove); PluginLog.Debug("Movement hook established"); } @@ -164,7 +163,7 @@ public static void ReloadHooks() } } - private static void Framework_Update(Framework framework) + private static void Framework_Update(IFramework framework) { ServiceManager.Tick(); } diff --git a/CustomizePlus/DalamudServices.cs b/CustomizePlus/Services/DalamudServices.cs similarity index 57% rename from CustomizePlus/DalamudServices.cs rename to CustomizePlus/Services/DalamudServices.cs index e1004aa..44896c0 100644 --- a/CustomizePlus/DalamudServices.cs +++ b/CustomizePlus/Services/DalamudServices.cs @@ -8,40 +8,48 @@ using Dalamud.Game.Gui; using Dalamud.IoC; using Dalamud.Plugin; +using Dalamud.Plugin.Services; -namespace CustomizePlus +namespace CustomizePlus.Services { public class DalamudServices { - [PluginService] public static Framework Framework { get; private set; } = null!; + [PluginService] [RequiredVersion("1.0")] - public static ObjectTable ObjectTable { get; private set; } = null!; + public static DalamudPluginInterface PluginInterface { get; private set; } = null!; [PluginService] [RequiredVersion("1.0")] - public static DalamudPluginInterface PluginInterface { get; private set; } = null!; + public static ISigScanner SigScanner { get; private set; } = null!; + + [PluginService] + public static IFramework Framework { get; private set; } = null!; + + [PluginService] + [RequiredVersion("1.0")] + public static IObjectTable ObjectTable { get; private set; } = null!; [PluginService] [RequiredVersion("1.0")] - public static CommandManager CommandManager { get; private set; } = null!; + public static ICommandManager CommandManager { get; private set; } = null!; [PluginService] [RequiredVersion("1.0")] - public static ChatGui ChatGui { get; private set; } = null!; + public static IChatGui ChatGui { get; private set; } = null!; [PluginService] [RequiredVersion("1.0")] - public static ClientState ClientState { get; private set; } = null!; + public static IClientState ClientState { get; private set; } = null!; [PluginService] [RequiredVersion("1.0")] - public static SigScanner SigScanner { get; private set; } = null!; + public static IGameGui GameGui { get; private set; } = null!; [PluginService] [RequiredVersion("1.0")] - public static GameGui GameGui { get; private set; } = null!; + internal static IGameInteropProvider Hooker { get; private set; } = null!; public static void Initialize(DalamudPluginInterface pluginInterface) { diff --git a/CustomizePlus/Services/GPoseService.cs b/CustomizePlus/Services/GPoseService.cs index 4e23d44..0d472e5 100644 --- a/CustomizePlus/Services/GPoseService.cs +++ b/CustomizePlus/Services/GPoseService.cs @@ -5,6 +5,7 @@ using CustomizePlus.Core; using CustomizePlus.Helpers; using Dalamud.Hooking; +using Dalamud.Plugin.Services; using FFXIVClientStructs.FFXIV.Client.System.Framework; namespace CustomizePlus.Services @@ -48,16 +49,16 @@ public bool FakeGPose public override unsafe void Start() { - GPoseState = DalamudServices.PluginInterface.UiBuilder.GposeActive ? GPoseState.Inside : GPoseState.Outside; + GPoseState = DalamudServices.ClientState.IsGPosing ? GPoseState.Inside : GPoseState.Outside; var uiModule = Framework.Instance()->GetUiModule(); var enterGPoseAddress = (nint)uiModule->VTable->EnterGPose; var exitGPoseAddress = (nint)uiModule->VTable->ExitGPose; - _enterGPoseHook = Hook.FromAddress(enterGPoseAddress, EnteringGPoseDetour); + _enterGPoseHook = DalamudServices.Hooker.HookFromAddress(enterGPoseAddress, EnteringGPoseDetour); _enterGPoseHook.Enable(); - _exitGPoseHook = Hook.FromAddress(exitGPoseAddress, ExitingGPoseDetour); + _exitGPoseHook = DalamudServices.Hooker.HookFromAddress(exitGPoseAddress, ExitingGPoseDetour); _exitGPoseHook.Enable(); base.Start(); diff --git a/CustomizePlus/Services/PosingModeDetectService.cs b/CustomizePlus/Services/PosingModeDetectService.cs index 5cfc003..ac46c51 100644 --- a/CustomizePlus/Services/PosingModeDetectService.cs +++ b/CustomizePlus/Services/PosingModeDetectService.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using CustomizePlus.Core; +using Dalamud.Plugin.Services; namespace CustomizePlus.Services { diff --git a/CustomizePlus/UI/Windows/Debug/IPCTestWindow.cs b/CustomizePlus/UI/Windows/Debug/IPCTestWindow.cs index 4d34f49..c970d0b 100644 --- a/CustomizePlus/UI/Windows/Debug/IPCTestWindow.cs +++ b/CustomizePlus/UI/Windows/Debug/IPCTestWindow.cs @@ -6,6 +6,7 @@ using System.Numerics; using CustomizePlus.Data; using CustomizePlus.Data.Profile; +using CustomizePlus.Services; using Dalamud.Interface; using Dalamud.Interface.Components; using Dalamud.Logging; diff --git a/CustomizePlus/UI/Windows/SettingsWindow.cs b/CustomizePlus/UI/Windows/SettingsWindow.cs index 6eed042..1eb3625 100644 --- a/CustomizePlus/UI/Windows/SettingsWindow.cs +++ b/CustomizePlus/UI/Windows/SettingsWindow.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using CustomizePlus.Helpers; +using CustomizePlus.Services; using CustomizePlus.UI.Windows.Debug; using Dalamud.Interface; using Dalamud.Logging; diff --git a/CustomizePlus/customizePlus.json b/CustomizePlus/customizePlus.json index 3ab9a8b..5cb3ffc 100644 --- a/CustomizePlus/customizePlus.json +++ b/CustomizePlus/customizePlus.json @@ -1,13 +1,14 @@ { - "Author": "XIV Tools", - "Name": "Customize+", - "Punchline": "Customize your character beyond FFXIV's limitations.", - "Description": "A plugin that allows you to create and apply Anamnesis-style body scaling full time.", - "InternalName": "CustomizePlus", - "ApplicableVersion": "any", - "Tags": [ - "anamnesis", - "customize", - "XIV Tools" - ] + "Author": "XIV Tools", + "Name": "Customize+", + "Punchline": "Customize your character beyond FFXIV's limitations.", + "Description": "A plugin that allows you to create and apply Anamnesis-style body scaling full time.", + "InternalName": "CustomizePlus", + "ApplicableVersion": "any", + "DalamudApiLevel": 9, + "Tags": [ + "anamnesis", + "customize", + "XIV Tools" + ] }