mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
Update FindAgentModule
- use a signature the AgentModule instead of offsets - move FindAgentModule to the other UI related functions and make it public
This commit is contained in:
parent
67dd9fbf9c
commit
b724b10678
3 changed files with 55 additions and 25 deletions
|
|
@ -75,6 +75,9 @@ namespace Dalamud.Game.Internal.Gui {
|
|||
private delegate IntPtr GetUiModuleDelegate(IntPtr basePtr);
|
||||
private readonly GetUiModuleDelegate getUiModule;
|
||||
|
||||
private delegate IntPtr GetAgentModuleDelegate(IntPtr uiModule);
|
||||
private GetAgentModuleDelegate getAgentModule;
|
||||
|
||||
public bool GameUiHidden { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -117,6 +120,7 @@ namespace Dalamud.Game.Internal.Gui {
|
|||
Log.Verbose("HandleItemHover address {Address}", Address.HandleItemHover);
|
||||
Log.Verbose("HandleItemOut address {Address}", Address.HandleItemOut);
|
||||
Log.Verbose("GetUIObject address {Address}", Address.GetUIObject);
|
||||
Log.Verbose("GetAgentModule address {Address}", Address.GetAgentModule);
|
||||
|
||||
Chat = new ChatGui(Address.ChatManager, scanner, dalamud);
|
||||
PartyFinder = new PartyFinderGui(scanner, dalamud);
|
||||
|
|
@ -159,6 +163,7 @@ namespace Dalamud.Game.Internal.Gui {
|
|||
this.getUIObjectByName = Marshal.GetDelegateForFunctionPointer<GetUIObjectByNameDelegate>(Address.GetUIObjectByName);
|
||||
|
||||
this.getUiModule = Marshal.GetDelegateForFunctionPointer<GetUiModuleDelegate>(Address.GetUIModule);
|
||||
this.getAgentModule = Marshal.GetDelegateForFunctionPointer<GetAgentModuleDelegate>(Address.GetAgentModule);
|
||||
}
|
||||
|
||||
private IntPtr HandleSetGlobalBgmDetour(UInt16 bgmKey, byte a2, UInt32 a3, UInt32 a4, UInt32 a5, byte a6) {
|
||||
|
|
@ -454,6 +459,48 @@ namespace Dalamud.Game.Internal.Gui {
|
|||
return new Addon.Addon(addonMem, addonStruct);
|
||||
}
|
||||
|
||||
public IntPtr FindAgentInterface(string addonName)
|
||||
{
|
||||
var addon = this.dalamud.Framework.Gui.GetUiObjectByName(addonName, 1);
|
||||
return this.FindAgentInterface(addon);
|
||||
}
|
||||
|
||||
public IntPtr FindAgentInterface(IntPtr addon)
|
||||
{
|
||||
if (addon == IntPtr.Zero)
|
||||
return IntPtr.Zero;
|
||||
|
||||
var uiModule = this.dalamud.Framework.Gui.GetUIModule();
|
||||
if (uiModule == IntPtr.Zero)
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
var agentModule = this.getAgentModule(uiModule);
|
||||
if (agentModule == IntPtr.Zero)
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
var id = Marshal.ReadInt16(addon, 0x1CE);
|
||||
if (id == 0)
|
||||
id = Marshal.ReadInt16(addon, 0x1CC);
|
||||
|
||||
if (id == 0)
|
||||
return IntPtr.Zero;
|
||||
|
||||
for (var i = 0; i < 379; i++)
|
||||
{
|
||||
var agent = Marshal.ReadIntPtr(agentModule, 0x20 + (i * 8));
|
||||
if (agent == IntPtr.Zero)
|
||||
continue;
|
||||
if (Marshal.ReadInt32(agent, 0x20) == id)
|
||||
return agent;
|
||||
}
|
||||
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
public void SetBgm(ushort bgmKey) => this.setGlobalBgmHook.Original(bgmKey, 0, 0, 0, 0, 0);
|
||||
|
||||
public void Enable() {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ namespace Dalamud.Game.Internal.Gui {
|
|||
public IntPtr GetBaseUIObject { get; private set; }
|
||||
public IntPtr GetUIObjectByName { get; private set; }
|
||||
public IntPtr GetUIModule { get; private set; }
|
||||
public IntPtr GetAgentModule { get; private set; }
|
||||
|
||||
public GameGuiAddressResolver(IntPtr baseAddress) {
|
||||
BaseAddress = baseAddress;
|
||||
|
|
@ -47,6 +48,12 @@ namespace Dalamud.Game.Internal.Gui {
|
|||
GetBaseUIObject = sig.ScanText("E8 ?? ?? ?? ?? 41 B8 01 00 00 00 48 8D 15 ?? ?? ?? ?? 48 8B 48 20 E8 ?? ?? ?? ?? 48 8B CF");
|
||||
GetUIObjectByName = sig.ScanText("E8 ?? ?? ?? ?? 48 8B CF 48 89 87 ?? ?? 00 00 E8 ?? ?? ?? ?? 41 B8 01 00 00 00");
|
||||
GetUIModule = sig.ScanText("E8 ?? ?? ?? ?? 83 3B 01");
|
||||
|
||||
// TODO replace manual resolving the vtable when SigScanner supports resolving .rdata offsets
|
||||
var uiModuleVtableSig = sig.ScanText("48 8D 05 ?? ?? ?? ?? 4C 89 44 24 ?? 48 89 01");
|
||||
var offset = Marshal.ReadInt32(uiModuleVtableSig, 3);
|
||||
var vtable = uiModuleVtableSig + offset + 7;
|
||||
this.GetAgentModule = Marshal.ReadIntPtr(vtable, 34 * IntPtr.Size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -504,7 +504,7 @@ namespace Dalamud.Interface
|
|||
}
|
||||
|
||||
if (ImGui.Button("Find Agent"))
|
||||
this.findAgentInterfacePtr = this.FindAgentInterface(this.inputAddonName);
|
||||
this.findAgentInterfacePtr = this.dalamud.Framework.Gui.FindAgentInterface(this.inputAddonName);
|
||||
|
||||
if (this.resultAddon != null)
|
||||
{
|
||||
|
|
@ -577,30 +577,6 @@ namespace Dalamud.Interface
|
|||
}
|
||||
}
|
||||
|
||||
private unsafe IntPtr FindAgentInterface(string addonName)
|
||||
{
|
||||
var addon = this.dalamud.Framework.Gui.GetUiObjectByName(addonName, 1);
|
||||
if (addon == IntPtr.Zero) return IntPtr.Zero;
|
||||
SafeMemory.Read<short>(addon + 0x1CE, out var id);
|
||||
|
||||
if (id == 0)
|
||||
_ = SafeMemory.Read(addon + 0x1CC, out id);
|
||||
|
||||
var framework = this.dalamud.Framework.Address.BaseAddress;
|
||||
var uiModule = *(IntPtr*)(framework + 0x29F8);
|
||||
var agentModule = uiModule + 0xC3E78;
|
||||
for (var i = 0; i < 379; i++)
|
||||
{
|
||||
var agent = *(IntPtr*)(agentModule + 0x20 + (i * 8));
|
||||
if (agent == IntPtr.Zero)
|
||||
continue;
|
||||
if (*(short*)(agent + 0x20) == id)
|
||||
return agent;
|
||||
}
|
||||
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
private void PrintActor(Actor actor, string tag)
|
||||
{
|
||||
var actorString =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue