From ab8eb2dba28516095635f4d25aeb6bd41e256167 Mon Sep 17 00:00:00 2001 From: goaaats Date: Thu, 14 Apr 2022 21:39:32 +0200 Subject: [PATCH] chore: make sure that ctx menu code is 100% accurate to 6.0 version --- Dalamud/Game/Gui/ContextMenus/ContextMenu.cs | 6 +++++ .../ContextMenus/ContextMenuReaderWriter.cs | 17 ++++++++----- .../OldStructs/OldAgentInventoryContext.cs | 25 +++++++++++++++++++ .../Internal/Windows/ChangelogWindow.cs | 10 ++------ 4 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 Dalamud/Game/Gui/ContextMenus/OldStructs/OldAgentInventoryContext.cs diff --git a/Dalamud/Game/Gui/ContextMenus/ContextMenu.cs b/Dalamud/Game/Gui/ContextMenus/ContextMenu.cs index 3d02634ab..2d469a3eb 100644 --- a/Dalamud/Game/Gui/ContextMenus/ContextMenu.cs +++ b/Dalamud/Game/Gui/ContextMenus/ContextMenu.cs @@ -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 diff --git a/Dalamud/Game/Gui/ContextMenus/ContextMenuReaderWriter.cs b/Dalamud/Game/Gui/ContextMenus/ContextMenuReaderWriter.cs index 9d378c26c..e1f54a09e 100644 --- a/Dalamud/Game/Gui/ContextMenus/ContextMenuReaderWriter.cs +++ b/Dalamud/Game/Gui/ContextMenus/ContextMenuReaderWriter.cs @@ -277,7 +277,7 @@ namespace Dalamud.Game.Gui.ContextMenus /// Read the context menu from the agent. /// /// Read menu items. - public GameContextMenuItem[] Read() + public GameContextMenuItem[]? Read() { var gameContextMenuItems = new List(); 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) { diff --git a/Dalamud/Game/Gui/ContextMenus/OldStructs/OldAgentInventoryContext.cs b/Dalamud/Game/Gui/ContextMenus/OldStructs/OldAgentInventoryContext.cs new file mode 100644 index 000000000..56fbbac97 --- /dev/null +++ b/Dalamud/Game/Gui/ContextMenus/OldStructs/OldAgentInventoryContext.cs @@ -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; +} diff --git a/Dalamud/Interface/Internal/Windows/ChangelogWindow.cs b/Dalamud/Interface/Internal/Windows/ChangelogWindow.cs index e6f32b551..47763e315 100644 --- a/Dalamud/Interface/Internal/Windows/ChangelogWindow.cs +++ b/Dalamud/Interface/Internal/Windows/ChangelogWindow.cs @@ -19,7 +19,7 @@ namespace Dalamud.Interface.Internal.Windows /// /// Whether the latest update warrants a changelog window. /// - 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);