chore: make sure that ctx menu code is 100% accurate to 6.0 version

This commit is contained in:
goaaats 2022-04-14 21:39:32 +02:00
parent 08ad57aa6c
commit ab8eb2dba2
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
4 changed files with 44 additions and 14 deletions

View file

@ -183,6 +183,9 @@ namespace Dalamud.Game.Gui.ContextMenus
// TODO: For inventory sub context menus, we take only the last item -- the return item.
// This is because we're doing a hack to spawn a Second Tier sub context menu and then appropriating it.
var contextMenuItems = contextMenuReaderWriter.Read();
if (contextMenuItems == null)
return;
if (IsInventoryContext(this.currentAgentContextInterface) && this.selectedOpenSubContextMenuItem != null)
{
contextMenuItems = contextMenuItems.TakeLast(1).ToArray();
@ -400,6 +403,9 @@ namespace Dalamud.Game.Gui.ContextMenus
// Read the selected item directly from the game
ContextMenuReaderWriter contextMenuReaderWriter = new ContextMenuReaderWriter(this.currentAgentContextInterface, addonContextMenu->AtkValuesCount, addonContextMenu->AtkValues);
var gameContextMenuItems = contextMenuReaderWriter.Read();
if (gameContextMenuItems == null)
return;
var gameSelectedItem = gameContextMenuItems.ElementAtOrDefault(selectedIndex);
// This should be impossible

View file

@ -277,7 +277,7 @@ namespace Dalamud.Game.Gui.ContextMenus
/// Read the context menu from the agent.
/// </summary>
/// <returns>Read menu items.</returns>
public GameContextMenuItem[] Read()
public GameContextMenuItem[]? Read()
{
var gameContextMenuItems = new List<GameContextMenuItem>();
for (var contextMenuItemIndex = 0; contextMenuItemIndex < this.ContextMenuItemCount; contextMenuItemIndex++)
@ -306,19 +306,24 @@ namespace Dalamud.Game.Gui.ContextMenus
byte action;
if (this.IsInventoryContext)
{
var actions = &((AgentInventoryContext*)this.agentContextInterface)->EventIdArray;
action = *actions[contextMenuItemAtkValueBaseIndex];
var actions = &((OldAgentInventoryContext*)this.agentContextInterface)->Actions;
action = *(actions + contextMenuItemAtkValueBaseIndex);
}
else if (this.StructLayout is SubContextMenuStructLayout.Alternate)
{
var redButtonActions = &((OldAgentContext*)this.agentContextInterface)->Items->RedButtonActions;
action = (byte)*(redButtonActions + contextMenuItemIndex);
}
else
else if (((OldAgentContext*)this.agentContextInterface)->Items != null)
{
var actions = &((OldAgentContext*)this.agentContextInterface)->Items->Actions;
action = *(actions + contextMenuItemAtkValueBaseIndex);
}
else
{
PluginLog.Warning("Context Menu action failed, Items pointer was unexpectedly null.");
return null;
}
// Get the has previous indicator flag
var hasPreviousIndicatorFlagsAtkValue = &this.atkValues[this.HasPreviousIndicatorFlagsIndex];
@ -438,8 +443,8 @@ namespace Dalamud.Game.Gui.ContextMenus
if (this.IsInventoryContext)
{
var actions = &((AgentInventoryContext*)this.agentContextInterface)->EventIdArray;
*actions[this.FirstContextMenuItemIndex + contextMenuItemIndex] = action;
var actions = &((OldAgentInventoryContext*)this.agentContextInterface)->Actions;
*(actions + this.FirstContextMenuItemIndex + contextMenuItemIndex) = action;
}
else if (this.StructLayout is SubContextMenuStructLayout.Alternate && this.FirstUnhandledAction != null)
{

View file

@ -0,0 +1,25 @@
using System.Runtime.InteropServices;
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
using FFXIVClientStructs.FFXIV.Component.GUI;
namespace Dalamud.Game.Gui.ContextMenus.OldStructs;
[StructLayout(LayoutKind.Explicit)]
public unsafe struct OldAgentInventoryContext
{
public static OldAgentInventoryContext* Instance() => (OldAgentInventoryContext*) FFXIVClientStructs.FFXIV.Client.System.Framework.Framework.Instance()->GetUiModule()->GetAgentModule()->GetAgentByInternalId(AgentId.InventoryContext);
[FieldOffset(0x0)] public AgentInterface AgentInterface;
[FieldOffset(0x0)] public OldAgentContextInterface AgentContextInterface;
[FieldOffset(0x2C)] public uint FirstContextMenuItemAtkValueIndex;
[FieldOffset(0x30)] public uint ContextMenuItemCount;
[FieldOffset(0x38)] public AtkValue AtkValues;
[FieldOffset(0x558)] public unsafe byte Actions;
[FieldOffset(0x5A8)] public uint UnkFlags;
[FieldOffset(0x5B0)] public uint PositionX;
[FieldOffset(0x5B4)] public uint PositionY;
[FieldOffset(0x5F8)] public uint InventoryItemId;
[FieldOffset(0x5FC)] public uint InventoryItemCount;
[FieldOffset(0x604)] public bool InventoryItemIsHighQuality;
}

View file

@ -19,7 +19,7 @@ namespace Dalamud.Interface.Internal.Windows
/// <summary>
/// Whether the latest update warrants a changelog window.
/// </summary>
public const string WarrantsChangelogForMajorMinor = "6.3.";
public const string WarrantsChangelogForMajorMinor = "6.4.";
private const string ChangeLog =
@"• Added a new menu to the title screen which allows you to access the plugin installer and various other plugins before logging in.
@ -39,11 +39,7 @@ Thanks and have fun!";
@"• All of your plugins were disabled automatically, due to this update. This is normal.
Open the plugin installer, then click 'update plugins'. Updated plugins should update and then re-enable themselves.
=> Please keep in mind that not all of your plugins may already be updated for the new version.
=> If some plugins are displayed with a red cross in the 'Installed Plugins' tab, they may not yet be available.
While we tested the released plugins considerably with a smaller set of people and believe that they are stable, we cannot guarantee to you that you will not run into crashes.
Considering current queue times, this is why we recommend that for now, you only use a set of plugins that are most essential to you, so you can go on playing the game instead of waiting endlessly.";
=> If some plugins are displayed with a red cross in the 'Installed Plugins' tab, they may not yet be available.";
private readonly string assemblyVersion = Util.AssemblyVersion;
@ -82,13 +78,11 @@ Considering current queue times, this is why we recommend that for now, you only
ImGui.TextWrapped(ChangeLog);
/*
ImGuiHelpers.ScaledDummy(5);
ImGui.TextColored(ImGuiColors.DalamudRed, " !!! ATTENTION !!!");
ImGui.TextWrapped(UpdatePluginsInfo);
*/
ImGuiHelpers.ScaledDummy(10);