mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-18 22:07:44 +01:00
feat: add plugins & settings option to main menu bar system context
This commit is contained in:
parent
c2f5941435
commit
7b2f939003
3 changed files with 53 additions and 20 deletions
|
|
@ -11,7 +11,6 @@ using Dalamud.Memory;
|
||||||
using FFXIVClientStructs.FFXIV.Client.UI;
|
using FFXIVClientStructs.FFXIV.Client.UI;
|
||||||
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
|
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
|
||||||
using FFXIVClientStructs.FFXIV.Component.GUI;
|
using FFXIVClientStructs.FFXIV.Component.GUI;
|
||||||
using Serilog;
|
|
||||||
|
|
||||||
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType;
|
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType;
|
||||||
|
|
||||||
|
|
@ -86,18 +85,6 @@ namespace Dalamud.Game.Gui.ContextMenus
|
||||||
|
|
||||||
private ContextMenuAddressResolver Address { get; set; }
|
private ContextMenuAddressResolver Address { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Enable this subsystem.
|
|
||||||
/// </summary>
|
|
||||||
public void Enable()
|
|
||||||
{
|
|
||||||
this.contextMenuOpeningHook.Enable();
|
|
||||||
this.contextMenuOpenedHook.Enable();
|
|
||||||
this.contextMenuItemSelectedHook.Enable();
|
|
||||||
this.subContextMenuOpeningHook.Enable();
|
|
||||||
this.subContextMenuOpenedHook.Enable();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
void IDisposable.Dispose()
|
void IDisposable.Dispose()
|
||||||
{
|
{
|
||||||
|
|
@ -108,6 +95,18 @@ namespace Dalamud.Game.Gui.ContextMenus
|
||||||
this.contextMenuOpeningHook.Disable();
|
this.contextMenuOpeningHook.Disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enable this subsystem.
|
||||||
|
/// </summary>
|
||||||
|
internal void Enable()
|
||||||
|
{
|
||||||
|
this.contextMenuOpeningHook.Enable();
|
||||||
|
this.contextMenuOpenedHook.Enable();
|
||||||
|
this.contextMenuItemSelectedHook.Enable();
|
||||||
|
this.subContextMenuOpeningHook.Enable();
|
||||||
|
this.subContextMenuOpenedHook.Enable();
|
||||||
|
}
|
||||||
|
|
||||||
private static unsafe bool IsInventoryContext(AgentContextInterface* agentContextInterface)
|
private static unsafe bool IsInventoryContext(AgentContextInterface* agentContextInterface)
|
||||||
{
|
{
|
||||||
return agentContextInterface == AgentInventoryContext.Instance();
|
return agentContextInterface == AgentInventoryContext.Instance();
|
||||||
|
|
@ -129,8 +128,6 @@ namespace Dalamud.Game.Gui.ContextMenus
|
||||||
|
|
||||||
private unsafe bool ContextMenuOpenedDetour(AddonContextMenu* addonContextMenu, int atkValueCount, AtkValue* atkValues)
|
private unsafe bool ContextMenuOpenedDetour(AddonContextMenu* addonContextMenu, int atkValueCount, AtkValue* atkValues)
|
||||||
{
|
{
|
||||||
Log.Information("Poop " + Marshal.PtrToStringUTF8(new IntPtr(((AtkUnitBase*)addonContextMenu)->Name)));
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.ContextMenuOpenedImplementation(addonContextMenu, ref atkValueCount, ref atkValues);
|
this.ContextMenuOpenedImplementation(addonContextMenu, ref atkValueCount, ref atkValues);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
using Dalamud.Game.Text.SeStringHandling;
|
using Dalamud.Game.Text;
|
||||||
|
using Dalamud.Game.Text.SeStringHandling;
|
||||||
|
using Dalamud.Game.Text.SeStringHandling.Payloads;
|
||||||
|
|
||||||
namespace Dalamud.Game.Gui.ContextMenus
|
namespace Dalamud.Game.Gui.ContextMenus
|
||||||
{
|
{
|
||||||
|
|
@ -13,7 +15,7 @@ namespace Dalamud.Game.Gui.ContextMenus
|
||||||
/// <param name="name">The name of the item.</param>
|
/// <param name="name">The name of the item.</param>
|
||||||
/// <param name="opened">The action that will be called when the item is selected.</param>
|
/// <param name="opened">The action that will be called when the item is selected.</param>
|
||||||
internal OpenSubContextMenuItem(SeString name, ContextMenuOpenedDelegate opened)
|
internal OpenSubContextMenuItem(SeString name, ContextMenuOpenedDelegate opened)
|
||||||
: base(name)
|
: base(new SeString().Append(new UIForegroundPayload(539)).Append($"{SeIconChar.BoxedLetterD.ToIconString()} ").Append(new UIForegroundPayload(0)).Append(name))
|
||||||
{
|
{
|
||||||
this.Opened = opened;
|
this.Opened = opened;
|
||||||
this.Indicator = ContextMenuItemIndicator.Next;
|
this.Indicator = ContextMenuItemIndicator.Next;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
using CheapLoc;
|
using CheapLoc;
|
||||||
using Dalamud.Configuration.Internal;
|
using Dalamud.Configuration.Internal;
|
||||||
|
using Dalamud.Data;
|
||||||
|
using Dalamud.Game.Gui.ContextMenus;
|
||||||
using Dalamud.Game.Text;
|
using Dalamud.Game.Text;
|
||||||
using Dalamud.Game.Text.SeStringHandling;
|
using Dalamud.Game.Text.SeStringHandling;
|
||||||
using Dalamud.Game.Text.SeStringHandling.Payloads;
|
using Dalamud.Game.Text.SeStringHandling.Payloads;
|
||||||
|
|
@ -11,6 +12,7 @@ using Dalamud.Hooking;
|
||||||
using Dalamud.Interface.Internal;
|
using Dalamud.Interface.Internal;
|
||||||
using Dalamud.Interface.Windowing;
|
using Dalamud.Interface.Windowing;
|
||||||
using FFXIVClientStructs.FFXIV.Component.GUI;
|
using FFXIVClientStructs.FFXIV.Component.GUI;
|
||||||
|
using Lumina.Excel.GeneratedSheets;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType;
|
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType;
|
||||||
|
|
@ -31,6 +33,9 @@ namespace Dalamud.Game.Internal
|
||||||
|
|
||||||
private readonly Hook<AtkUnitBaseReceiveGlobalEvent> hookAtkUnitBaseReceiveGlobalEvent;
|
private readonly Hook<AtkUnitBaseReceiveGlobalEvent> hookAtkUnitBaseReceiveGlobalEvent;
|
||||||
|
|
||||||
|
private readonly string locDalamudPlugins;
|
||||||
|
private readonly string locDalamudSettings;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="DalamudAtkTweaks"/> class.
|
/// Initializes a new instance of the <see cref="DalamudAtkTweaks"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -53,6 +58,12 @@ namespace Dalamud.Game.Internal
|
||||||
|
|
||||||
var atkUnitBaseReceiveGlobalEventAddress = sigScanner.ScanText("48 89 5C 24 ?? 48 89 7C 24 ?? 55 41 56 41 57 48 8B EC 48 83 EC 50 44 0F B7 F2 ");
|
var atkUnitBaseReceiveGlobalEventAddress = sigScanner.ScanText("48 89 5C 24 ?? 48 89 7C 24 ?? 55 41 56 41 57 48 8B EC 48 83 EC 50 44 0F B7 F2 ");
|
||||||
this.hookAtkUnitBaseReceiveGlobalEvent = new Hook<AtkUnitBaseReceiveGlobalEvent>(atkUnitBaseReceiveGlobalEventAddress, this.AtkUnitBaseReceiveGlobalEventDetour);
|
this.hookAtkUnitBaseReceiveGlobalEvent = new Hook<AtkUnitBaseReceiveGlobalEvent>(atkUnitBaseReceiveGlobalEventAddress, this.AtkUnitBaseReceiveGlobalEventDetour);
|
||||||
|
|
||||||
|
this.locDalamudPlugins = Loc.Localize("SystemMenuPlugins", "Dalamud Plugins");
|
||||||
|
this.locDalamudSettings = Loc.Localize("SystemMenuSettings", "Dalamud Settings");
|
||||||
|
|
||||||
|
var contextMenu = Service<ContextMenu>.Get();
|
||||||
|
contextMenu.ContextMenuOpened += this.ContextMenuOnContextMenuOpened;
|
||||||
}
|
}
|
||||||
|
|
||||||
private delegate void AgentHudOpenSystemMenuPrototype(void* thisPtr, AtkValue* atkValueArgs, uint menuSize);
|
private delegate void AgentHudOpenSystemMenuPrototype(void* thisPtr, AtkValue* atkValueArgs, uint menuSize);
|
||||||
|
|
@ -75,6 +86,27 @@ namespace Dalamud.Game.Internal
|
||||||
this.hookAtkUnitBaseReceiveGlobalEvent.Enable();
|
this.hookAtkUnitBaseReceiveGlobalEvent.Enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ContextMenuOnContextMenuOpened(ContextMenuOpenedArgs args)
|
||||||
|
{
|
||||||
|
var systemText = Service<DataManager>.Get().GetExcelSheet<Addon>()!.GetRow(1059)!.Text.RawString; // "System"
|
||||||
|
var configuration = Service<DalamudConfiguration>.Get();
|
||||||
|
|
||||||
|
if (args.Title == systemText && configuration.DoButtonsSystemMenu)
|
||||||
|
{
|
||||||
|
var dalamudInterface = Service<DalamudInterface>.Get();
|
||||||
|
|
||||||
|
args.Items.Insert(0, new CustomContextMenuItem(this.locDalamudSettings, selectedArgs =>
|
||||||
|
{
|
||||||
|
dalamudInterface.ToggleSettingsWindow();
|
||||||
|
}));
|
||||||
|
|
||||||
|
args.Items.Insert(0, new CustomContextMenuItem(this.locDalamudPlugins, selectedArgs =>
|
||||||
|
{
|
||||||
|
dalamudInterface.TogglePluginInstallerWindow();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private IntPtr AtkUnitBaseReceiveGlobalEventDetour(AtkUnitBase* thisPtr, ushort cmd, uint a3, IntPtr a4, uint* arg)
|
private IntPtr AtkUnitBaseReceiveGlobalEventDetour(AtkUnitBase* thisPtr, ushort cmd, uint a3, IntPtr a4, uint* arg)
|
||||||
{
|
{
|
||||||
// Log.Information("{0}: cmd#{1} a3#{2} - HasAnyFocus:{3}", Marshal.PtrToStringAnsi(new IntPtr(thisPtr->Name)), cmd, a3, WindowSystem.HasAnyWindowSystemFocus);
|
// Log.Information("{0}: cmd#{1} a3#{2} - HasAnyFocus:{3}", Marshal.PtrToStringAnsi(new IntPtr(thisPtr->Name)), cmd, a3, WindowSystem.HasAnyWindowSystemFocus);
|
||||||
|
|
@ -150,11 +182,11 @@ namespace Dalamud.Game.Internal
|
||||||
var strPlugins = new SeString().Append(new UIForegroundPayload(color))
|
var strPlugins = new SeString().Append(new UIForegroundPayload(color))
|
||||||
.Append($"{SeIconChar.BoxedLetterD.ToIconString()} ")
|
.Append($"{SeIconChar.BoxedLetterD.ToIconString()} ")
|
||||||
.Append(new UIForegroundPayload(0))
|
.Append(new UIForegroundPayload(0))
|
||||||
.Append(Loc.Localize("SystemMenuPlugins", "Dalamud Plugins")).Encode();
|
.Append(this.locDalamudPlugins).Encode();
|
||||||
var strSettings = new SeString().Append(new UIForegroundPayload(color))
|
var strSettings = new SeString().Append(new UIForegroundPayload(color))
|
||||||
.Append($"{SeIconChar.BoxedLetterD.ToIconString()} ")
|
.Append($"{SeIconChar.BoxedLetterD.ToIconString()} ")
|
||||||
.Append(new UIForegroundPayload(0))
|
.Append(new UIForegroundPayload(0))
|
||||||
.Append(Loc.Localize("SystemMenuSettings", "Dalamud Settings")).Encode();
|
.Append(this.locDalamudSettings).Encode();
|
||||||
|
|
||||||
// do this the most terrible way possible since im lazy
|
// do this the most terrible way possible since im lazy
|
||||||
var bytes = stackalloc byte[strPlugins.Length + 1];
|
var bytes = stackalloc byte[strPlugins.Length + 1];
|
||||||
|
|
@ -229,6 +261,8 @@ namespace Dalamud.Game.Internal
|
||||||
this.hookAgentHudOpenSystemMenu.Dispose();
|
this.hookAgentHudOpenSystemMenu.Dispose();
|
||||||
this.hookUiModuleRequestMainCommand.Dispose();
|
this.hookUiModuleRequestMainCommand.Dispose();
|
||||||
this.hookAtkUnitBaseReceiveGlobalEvent.Dispose();
|
this.hookAtkUnitBaseReceiveGlobalEvent.Dispose();
|
||||||
|
|
||||||
|
Service<ContextMenu>.Get().ContextMenuOpened -= this.ContextMenuOnContextMenuOpened;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.disposed = true;
|
this.disposed = true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue