Add events based on AgentUpdateFlag

This commit is contained in:
Haselnussbomber 2025-10-01 15:30:29 +02:00
parent 116e8aadbc
commit 0b6f3b8bcf
No known key found for this signature in database
GPG key ID: BB905BB49E7295D1
3 changed files with 103 additions and 18 deletions

View file

@ -2,16 +2,14 @@ using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Dalamud.Game.Gui;
using Dalamud.Game.Inventory.InventoryEventArgTypes;
using Dalamud.Hooking;
using Dalamud.IoC;
using Dalamud.IoC.Internal;
using Dalamud.Logging.Internal;
using Dalamud.Plugin.Internal;
using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.UI;
namespace Dalamud.Game.Inventory;
/// <summary>
@ -33,7 +31,8 @@ internal class GameInventory : IInternalDisposableService
[ServiceManager.ServiceDependency]
private readonly Framework framework = Service<Framework>.Get();
private readonly Hook<RaptureAtkModuleUpdateDelegate> raptureAtkModuleUpdateHook;
[ServiceManager.ServiceDependency]
private readonly GameGui gameGui = Service<GameGui>.Get();
private readonly GameInventoryType[] inventoryTypes;
private readonly GameInventoryItem[]?[] inventoryItems;
@ -47,18 +46,9 @@ internal class GameInventory : IInternalDisposableService
this.inventoryTypes = Enum.GetValues<GameInventoryType>();
this.inventoryItems = new GameInventoryItem[this.inventoryTypes.Length][];
unsafe
{
this.raptureAtkModuleUpdateHook = Hook<RaptureAtkModuleUpdateDelegate>.FromFunctionPointerVariable(
new(&RaptureAtkModule.StaticVirtualTablePointer->Update),
this.RaptureAtkModuleUpdateDetour);
}
this.raptureAtkModuleUpdateHook.Enable();
this.gameGui.InventoryUpdate += this.OnInventoryUpdate;
}
private unsafe delegate void RaptureAtkModuleUpdateDelegate(RaptureAtkModule* ram, float f1);
/// <inheritdoc/>
void IInternalDisposableService.DisposeService()
{
@ -68,7 +58,7 @@ internal class GameInventory : IInternalDisposableService
this.subscribersPendingChange.Clear();
this.subscribersChanged = false;
this.framework.Update -= this.OnFrameworkUpdate;
this.raptureAtkModuleUpdateHook.Dispose();
this.gameGui.InventoryUpdate -= this.OnInventoryUpdate;
}
}
@ -319,10 +309,9 @@ internal class GameInventory : IInternalDisposableService
return items;
}
private unsafe void RaptureAtkModuleUpdateDetour(RaptureAtkModule* ram, float f1)
private void OnInventoryUpdate()
{
this.inventoriesMightBeChanged |= ram->AgentUpdateFlag != 0;
this.raptureAtkModuleUpdateHook.Original(ram, f1);
this.inventoriesMightBeChanged |= true;
}
/// <summary>