diff --git a/NamePlateDebuffs/AddonNamePlateHooks.cs b/NamePlateDebuffs/AddonNamePlateHooks.cs index 4b261fc..0432bf2 100644 --- a/NamePlateDebuffs/AddonNamePlateHooks.cs +++ b/NamePlateDebuffs/AddonNamePlateHooks.cs @@ -3,7 +3,6 @@ using FFXIVClientStructs.FFXIV.Client.Game.Character; using FFXIVClientStructs.FFXIV.Client.System.Framework; using FFXIVClientStructs.FFXIV.Client.UI; -using FFXIVClientStructs.FFXIV.Component.GUI; using System; using System.Diagnostics; @@ -34,8 +33,8 @@ public AddonNamePlateHooks(NamePlateDebuffsPlugin p) public void Initialize() { - _hookAddonNamePlateFinalize = new Hook(_plugin.Address.AddonNamePlateFinalizeAddress, AddonNamePlateFinalizeDetour); - _hookAddonNamePlateDraw = new Hook(_plugin.Address.AddonNamePlateDrawAddress, AddonNamePlateDrawDetour); + _hookAddonNamePlateFinalize = NamePlateDebuffsPlugin.Hook.HookFromAddress(_plugin.Address.AddonNamePlateFinalizeAddress, AddonNamePlateFinalizeDetour); + _hookAddonNamePlateDraw = NamePlateDebuffsPlugin.Hook.HookFromAddress(_plugin.Address.AddonNamePlateDrawAddress, AddonNamePlateDrawDetour); _hookAddonNamePlateFinalize.Enable(); _hookAddonNamePlateDraw.Enable(); @@ -80,7 +79,7 @@ public void AddonNamePlateDrawDetour(AddonNamePlate* thisPtr) return; } - var framework = FFXIVClientStructs.FFXIV.Client.System.Framework.Framework.Instance(); + var framework = Framework.Instance(); var ui3DModule = framework->GetUiModule()->GetUI3DModule(); for (int i = 0; i < ui3DModule->NamePlateObjectInfoCount; i++) @@ -114,7 +113,7 @@ public void AddonNamePlateDrawDetour(AddonNamePlate* thisPtr) _plugin.StatusNodeManager.HideUnusedStatus(npIndex, 0); continue; } - StatusManager targetStatus = ((BattleChara*)objectInfo->GameObject)->StatusManager; + StatusManager targetStatus = ((BattleChara*)objectInfo->GameObject)->GetStatusManager[0]; var statusArray = (Status*)targetStatus.Status; diff --git a/NamePlateDebuffs/NamePlateDebuffs.csproj b/NamePlateDebuffs/NamePlateDebuffs.csproj index 464892c..26548cb 100644 --- a/NamePlateDebuffs/NamePlateDebuffs.csproj +++ b/NamePlateDebuffs/NamePlateDebuffs.csproj @@ -3,7 +3,7 @@ NamePlateDebuffs - 1.0.1.1 + 1.0.1.2 aers, JHerig, squidmade https://github.com/jherig/NamePlateDebuffs @@ -25,9 +25,8 @@ - + - $(DalamudLibPath)Dalamud.dll diff --git a/NamePlateDebuffs/NamePlateDebuffsPlugin.cs b/NamePlateDebuffs/NamePlateDebuffsPlugin.cs index ec0d0d6..2287997 100644 --- a/NamePlateDebuffs/NamePlateDebuffsPlugin.cs +++ b/NamePlateDebuffs/NamePlateDebuffsPlugin.cs @@ -1,13 +1,10 @@ using Dalamud.Game.Command; +using Dalamud.IoC; using Dalamud.Plugin; -using Lumina.Excel.GeneratedSheets; +using Dalamud.Plugin.Services; using NamePlateDebuffs.StatusNode; -using System.Collections.Generic; -using Dalamud.Data; using Dalamud.Game; -using Dalamud.Game.ClientState; -using Dalamud.IoC; -using Dalamud.Logging; + namespace NamePlateDebuffs { @@ -21,14 +18,17 @@ public class NamePlateDebuffsPlugin : IDalamudPlugin [PluginService] [RequiredVersion("1.0")] - public ClientState ClientState { get; private set; } = null!; + public IClientState ClientState { get; private set; } = null!; [PluginService] [RequiredVersion("1.0")] - public static CommandManager CommandManager { get; private set; } = null!; + public static ICommandManager CommandManager { get; private set; } = null!; - public DataManager DataManager { get; private set; } = null!; - public Framework Framework { get; private set; } = null!; + [PluginService] public static IDataManager DataManager { get; private set; } = null!; + [PluginService] public static IFramework Framework { get; private set; } = null!; + [PluginService] public static IPluginLog Log { get; private set; } = null!; + [PluginService] public static ISigScanner SigScanner { get; private set; } = null!; + [PluginService] public static IGameInteropProvider Hook { get; private set; } = null!; public PluginAddressResolver Address { get; private set; } = null!; public StatusNodeManager StatusNodeManager { get; private set; } = null!; public static AddonNamePlateHooks Hooks { get; private set; } = null!; @@ -37,25 +37,15 @@ public class NamePlateDebuffsPlugin : IDalamudPlugin internal bool InPvp; - public NamePlateDebuffsPlugin( - ClientState clientState, - CommandManager commandManager, - DalamudPluginInterface pluginInterface, - DataManager dataManager, - Framework framework - ) + public NamePlateDebuffsPlugin() { - ClientState = clientState; - CommandManager = commandManager; - DataManager = dataManager; - Interface = pluginInterface; - Framework = framework; + // load or create config + Config = Interface.GetPluginConfig() as NamePlateDebuffsPluginConfig ?? new NamePlateDebuffsPluginConfig(); + Config.Initialize(Interface); - Config = pluginInterface.GetPluginConfig() as NamePlateDebuffsPluginConfig ?? new NamePlateDebuffsPluginConfig(); - Config.Initialize(pluginInterface); Address = new PluginAddressResolver(); - Address.Setup(); + Address.Setup(SigScanner); StatusNodeManager = new StatusNodeManager(this); @@ -64,7 +54,7 @@ Framework framework UI = new NamePlateDebuffsPluginUI(this); - ClientState.TerritoryChanged += OnTerritoryChange; + //ClientState.TerritoryChanged += OnTerritoryChange; CommandManager.AddHandler("/npdebuffs", new CommandInfo(this.ToggleConfig) { @@ -73,7 +63,7 @@ Framework framework } public void Dispose() { - ClientState.TerritoryChanged -= OnTerritoryChange; + //ClientState?.TerritoryChanged -= OnTerritoryChange; CommandManager.RemoveHandler("/npdebuffs"); UI.Dispose(); @@ -81,18 +71,18 @@ public void Dispose() StatusNodeManager.Dispose(); } - private void OnTerritoryChange(object sender, ushort e) - { - try - { - TerritoryType territory = DataManager.GetExcelSheet()?.GetRow(e); - if (territory != null) InPvp = territory.IsPvpZone; - } - catch (KeyNotFoundException) - { - PluginLog.Warning("Could not get territory for current zone"); - } - } + //private void OnTerritoryChange(object sender, ushort e) + //{ + // try + // { + // TerritoryType? territory = DataManager.GetExcelSheet()?.GetRow(e); + // if (territory != null) InPvp = territory.IsPvpZone; + // } + // catch (KeyNotFoundException) + // { + // Log.Warning("Could not get territory for current zone"); + // } + //} private void ToggleConfig(string command, string args) { diff --git a/NamePlateDebuffs/NamePlateDebuffsPluginConfig.cs b/NamePlateDebuffs/NamePlateDebuffsPluginConfig.cs index 03436c5..e46a45a 100644 --- a/NamePlateDebuffs/NamePlateDebuffsPluginConfig.cs +++ b/NamePlateDebuffs/NamePlateDebuffsPluginConfig.cs @@ -1,11 +1,7 @@ using Dalamud.Configuration; using Dalamud.Plugin; using System; -using System.Collections.Generic; -using System.Linq; using System.Numerics; -using System.Text; -using System.Threading.Tasks; namespace NamePlateDebuffs { @@ -35,8 +31,8 @@ public class NamePlateDebuffsPluginConfig : IPluginConfiguration public int DurationY = 23; public int FontSize = 14; public int DurationPadding = 2; - public Vector4 DurationTextColor = new Vector4(1, 1, 1, 1); - public Vector4 DurationEdgeColor = new Vector4(0, 0, 0, 1); + public Vector4 DurationTextColor = new(1, 1, 1, 1); + public Vector4 DurationEdgeColor = new(0, 0, 0, 1); public void SetDefaults() { @@ -70,7 +66,7 @@ public void SetDefaults() DurationEdgeColor.W = 1; } - [NonSerialized] private DalamudPluginInterface _pluginInterface; + [NonSerialized] private DalamudPluginInterface? _pluginInterface; public void Initialize(DalamudPluginInterface pluginInterface) { @@ -79,7 +75,7 @@ public void Initialize(DalamudPluginInterface pluginInterface) public void Save() { - _pluginInterface.SavePluginConfig(this); + _pluginInterface!.SavePluginConfig(this); } } } diff --git a/NamePlateDebuffs/NamePlateDebuffsPluginUI.cs b/NamePlateDebuffs/NamePlateDebuffsPluginUI.cs index af21cf2..bb2d417 100644 --- a/NamePlateDebuffs/NamePlateDebuffsPluginUI.cs +++ b/NamePlateDebuffs/NamePlateDebuffsPluginUI.cs @@ -1,11 +1,7 @@ using ImGuiNET; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Numerics; -using Dalamud.Interface.Components; + namespace NamePlateDebuffs { diff --git a/NamePlateDebuffs/PluginAddressResolver.cs b/NamePlateDebuffs/PluginAddressResolver.cs index fe14171..49e27ef 100644 --- a/NamePlateDebuffs/PluginAddressResolver.cs +++ b/NamePlateDebuffs/PluginAddressResolver.cs @@ -1,12 +1,5 @@ using Dalamud.Game; -using Dalamud.Game.Internal; -using Dalamud.Plugin; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Dalamud.Logging; namespace NamePlateDebuffs { @@ -20,14 +13,14 @@ public class PluginAddressResolver : BaseAddressResolver private const string AddonNamePlateDrawSignature = "0F B7 81 ?? ?? ?? ?? 4C 8B C1 66 C1 E0 06"; - protected override void Setup64Bit(SigScanner scanner) + protected override void Setup64Bit(ISigScanner scanner) { AddonNamePlateFinalizeAddress = scanner.ScanText(AddonNamePlateFinalizeSignature); AddonNamePlateDrawAddress = scanner.ScanText(AddonNamePlateDrawSignature); - PluginLog.Verbose("===== NamePlate Debuffs ====="); - PluginLog.Verbose($"{nameof(AddonNamePlateFinalizeAddress)} {AddonNamePlateFinalizeAddress.ToInt64():X}"); - PluginLog.Verbose($"{nameof(AddonNamePlateDrawAddress)} {AddonNamePlateDrawAddress.ToInt64():X}"); + NamePlateDebuffsPlugin.Log.Verbose("===== NamePlate Debuffs ====="); + NamePlateDebuffsPlugin.Log.Verbose($"{nameof(AddonNamePlateFinalizeAddress)} {AddonNamePlateFinalizeAddress.ToInt64():X}"); + NamePlateDebuffsPlugin.Log.Verbose($"{nameof(AddonNamePlateDrawAddress)} {AddonNamePlateDrawAddress.ToInt64():X}"); } } } diff --git a/NamePlateDebuffs/StatusNode/StatusNode.cs b/NamePlateDebuffs/StatusNode/StatusNode.cs index a11f06a..1cccf0c 100644 --- a/NamePlateDebuffs/StatusNode/StatusNode.cs +++ b/NamePlateDebuffs/StatusNode/StatusNode.cs @@ -1,6 +1,4 @@ -using Dalamud.Logging; -using Dalamud.Plugin; -using FFXIVClientStructs.FFXIV.Client.System.Memory; +using FFXIVClientStructs.FFXIV.Client.System.Memory; using FFXIVClientStructs.FFXIV.Component.GUI; namespace NamePlateDebuffs.StatusNode @@ -150,14 +148,14 @@ public void DestroyNodes() var newResNode = (AtkResNode*)IMemorySpace.GetUISpace()->Malloc((ulong)sizeof(AtkResNode), 8); if (newResNode == null) { - PluginLog.Debug("Failed to allocate memory for res node"); + NamePlateDebuffsPlugin.Log.Debug("Failed to allocate memory for res node"); return null; } IMemorySpace.Memset(newResNode, 0, (ulong)sizeof(AtkResNode)); newResNode->Ctor(); newResNode->Type = NodeType.Res; - newResNode->Flags = (short)(NodeFlags.AnchorLeft | NodeFlags.AnchorTop); + newResNode->NodeFlags = (NodeFlags.AnchorLeft | NodeFlags.AnchorTop); newResNode->DrawFlags = 0; return newResNode; @@ -168,14 +166,14 @@ public void DestroyNodes() var newImageNode = (AtkImageNode*)IMemorySpace.GetUISpace()->Malloc((ulong)sizeof(AtkImageNode), 8); if (newImageNode == null) { - PluginLog.Debug("Failed to allocate memory for image node"); + NamePlateDebuffsPlugin.Log.Debug("Failed to allocate memory for image node"); return null; } IMemorySpace.Memset(newImageNode, 0, (ulong)sizeof(AtkImageNode)); newImageNode->Ctor(); newImageNode->AtkResNode.Type = NodeType.Image; - newImageNode->AtkResNode.Flags = (short)(NodeFlags.AnchorLeft | NodeFlags.AnchorTop | NodeFlags.UseDepthBasedPriority); + newImageNode->AtkResNode.NodeFlags = (NodeFlags.AnchorLeft | NodeFlags.AnchorTop | NodeFlags.UseDepthBasedPriority); newImageNode->AtkResNode.DrawFlags = 0; newImageNode->WrapMode = 1; @@ -184,7 +182,7 @@ public void DestroyNodes() var partsList = (AtkUldPartsList*)IMemorySpace.GetUISpace()->Malloc((ulong)sizeof(AtkUldPartsList), 8); if (partsList == null) { - PluginLog.Debug("Failed to allocate memory for parts list"); + NamePlateDebuffsPlugin.Log.Debug("Failed to allocate memory for parts list"); newImageNode->AtkResNode.Destroy(true); return null; } @@ -195,7 +193,7 @@ public void DestroyNodes() var part = (AtkUldPart*)IMemorySpace.GetUISpace()->Malloc((ulong)sizeof(AtkUldPart), 8); if (part == null) { - PluginLog.Debug("Failed to allocate memory for part"); + NamePlateDebuffsPlugin.Log.Debug("Failed to allocate memory for part"); IMemorySpace.Free(partsList, (ulong)sizeof(AtkUldPartsList)); newImageNode->AtkResNode.Destroy(true); } @@ -210,7 +208,7 @@ public void DestroyNodes() var asset = (AtkUldAsset*)IMemorySpace.GetUISpace()->Malloc((ulong)sizeof(AtkUldAsset), 8); if (asset == null) { - PluginLog.Log("Failed to allocate memory for asset"); + NamePlateDebuffsPlugin.Log.Debug("Failed to allocate memory for asset"); IMemorySpace.Free(part, (ulong)sizeof(AtkUldPart)); IMemorySpace.Free(partsList, (ulong)sizeof(AtkUldPartsList)); newImageNode->AtkResNode.Destroy(true); @@ -233,14 +231,14 @@ public void DestroyNodes() var newTextNode = (AtkTextNode*)IMemorySpace.GetUISpace()->Malloc((ulong)sizeof(AtkTextNode), 8); if (newTextNode == null) { - PluginLog.Debug("Failed to allocate memory for text node"); + NamePlateDebuffsPlugin.Log.Debug("Failed to allocate memory for text node"); return null; } IMemorySpace.Memset(newTextNode, 0, (ulong)sizeof(AtkTextNode)); newTextNode->Ctor(); newTextNode->AtkResNode.Type = NodeType.Text; - newTextNode->AtkResNode.Flags = (short)(NodeFlags.AnchorLeft | NodeFlags.AnchorTop | NodeFlags.UseDepthBasedPriority); + newTextNode->AtkResNode.NodeFlags = (NodeFlags.AnchorLeft | NodeFlags.AnchorTop | NodeFlags.UseDepthBasedPriority); newTextNode->AtkResNode.DrawFlags = 12; newTextNode->AtkResNode.SetWidth(24); newTextNode->AtkResNode.SetHeight(17); diff --git a/NamePlateDebuffs/StatusNode/StatusNodeGroup.cs b/NamePlateDebuffs/StatusNode/StatusNodeGroup.cs index e91cf5c..e3a288b 100644 --- a/NamePlateDebuffs/StatusNode/StatusNodeGroup.cs +++ b/NamePlateDebuffs/StatusNode/StatusNodeGroup.cs @@ -1,8 +1,7 @@ -using Dalamud.Plugin; -using FFXIVClientStructs.FFXIV.Client.System.Memory; +using FFXIVClientStructs.FFXIV.Client.System.Memory; using FFXIVClientStructs.FFXIV.Component.GUI; using System; -using Dalamud.Logging; + namespace NamePlateDebuffs.StatusNode { @@ -154,14 +153,14 @@ public void SetupVisibility() var newResNode = (AtkResNode*)IMemorySpace.GetUISpace()->Malloc((ulong)sizeof(AtkResNode), 8); if (newResNode == null) { - PluginLog.Debug("Failed to allocate memory for res node"); + NamePlateDebuffsPlugin.Log.Debug("Failed to allocate memory for res node"); return null; } IMemorySpace.Memset(newResNode, 0, (ulong)sizeof(AtkResNode)); newResNode->Ctor(); newResNode->Type = NodeType.Res; - newResNode->Flags = (short)(NodeFlags.AnchorLeft | NodeFlags.AnchorTop); + newResNode->NodeFlags = (NodeFlags.AnchorLeft | NodeFlags.AnchorTop); newResNode->DrawFlags = 0; return newResNode; diff --git a/NamePlateDebuffs/StatusNode/StatusNodeManager.cs b/NamePlateDebuffs/StatusNode/StatusNodeManager.cs index e9f1d89..efbc34e 100644 --- a/NamePlateDebuffs/StatusNode/StatusNodeManager.cs +++ b/NamePlateDebuffs/StatusNode/StatusNodeManager.cs @@ -1,7 +1,4 @@ -using Dalamud.Hooking; -using Dalamud.Plugin; -using FFXIVClientStructs.FFXIV.Client.System.Memory; -using FFXIVClientStructs.FFXIV.Client.UI; +using FFXIVClientStructs.FFXIV.Client.UI; using FFXIVClientStructs.FFXIV.Component.GUI; using Lumina.Excel; using Lumina.Excel.GeneratedSheets; @@ -30,7 +27,7 @@ internal StatusNodeManager(NamePlateDebuffsPlugin p) NodeGroups = new StatusNodeGroup[NamePlateCount]; - StatusSheet = _plugin.DataManager.GetExcelSheet(); + StatusSheet = NamePlateDebuffsPlugin.DataManager.GetExcelSheet(); } public void Dispose() @@ -72,7 +69,7 @@ public void SetStatus(int groupIndex, int statusIndex, int id, int timer) StatusNodeGroup group = NodeGroups[groupIndex]; - group?.SetStatus(statusIndex, row.Icon, timer); + group?.SetStatus(statusIndex, (int)row.Icon, timer); } public void HideUnusedStatus(int groupIndex, int statusCount) @@ -113,7 +110,7 @@ public bool BuildNodes(bool rebuild = false) for(byte i = 0; i < NamePlateCount; i++) { - StatusNodeGroup nodeGroup = new StatusNodeGroup(_plugin); + StatusNodeGroup nodeGroup = new(_plugin); var npObj = &namePlateAddon->NamePlateObjectArray[i]; if (!nodeGroup.BuildNodes(StartingNodeId)) { diff --git a/NamePlateDebuffs/packages.lock.json b/NamePlateDebuffs/packages.lock.json index 2426061..6cf1c73 100644 --- a/NamePlateDebuffs/packages.lock.json +++ b/NamePlateDebuffs/packages.lock.json @@ -4,9 +4,9 @@ "net7.0-windows7.0": { "DalamudPackager": { "type": "Direct", - "requested": "[2.1.10, )", - "resolved": "2.1.10", - "contentHash": "S6NrvvOnLgT4GDdgwuKVJjbFo+8ZEj+JsEYk9ojjOR/MMfv1dIFpT8aRJQfI24rtDcw1uF+GnSSMN4WW1yt7fw==" + "requested": "[2.1.12, )", + "resolved": "2.1.12", + "contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg==" } } }