From bd81d230972402d992ced89888aaa5d959ebf700 Mon Sep 17 00:00:00 2001
From: MidoriKami <9083275+MidoriKami@users.noreply.github.com>
Date: Thu, 21 Sep 2023 17:05:27 -0700
Subject: [PATCH] Use CallHook for AddonSetup
---
.../AddonArgTypes/AddonSetupArgs.cs | 10 +++++++
Dalamud/Game/AddonLifecycle/AddonLifecycle.cs | 26 ++++++++++++-------
.../AddonLifecycleAddressResolver.cs | 2 +-
3 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonSetupArgs.cs b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonSetupArgs.cs
index a73d11ae2..4b467deb8 100644
--- a/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonSetupArgs.cs
+++ b/Dalamud/Game/AddonLifecycle/AddonArgTypes/AddonSetupArgs.cs
@@ -10,4 +10,14 @@ public class AddonSetupArgs : IAddonArgs
///
public AddonArgsType Type => AddonArgsType.Setup;
+
+ ///
+ /// Gets the number of AtkValues.
+ ///
+ public uint AtkValueCount { get; init; }
+
+ ///
+ /// Gets the address of the AtkValue array.
+ ///
+ public nint AtkValues { get; init; }
}
diff --git a/Dalamud/Game/AddonLifecycle/AddonLifecycle.cs b/Dalamud/Game/AddonLifecycle/AddonLifecycle.cs
index 7f4a4de95..75b5b3753 100644
--- a/Dalamud/Game/AddonLifecycle/AddonLifecycle.cs
+++ b/Dalamud/Game/AddonLifecycle/AddonLifecycle.cs
@@ -27,7 +27,7 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
private readonly Framework framework = Service.Get();
private readonly AddonLifecycleAddressResolver address;
- private readonly Hook onAddonSetupHook;
+ private readonly CallHook onAddonSetupHook;
private readonly Hook onAddonFinalizeHook;
private readonly CallHook onAddonDrawHook;
private readonly CallHook onAddonUpdateHook;
@@ -46,7 +46,7 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
this.framework.Update += this.OnFrameworkUpdate;
- this.onAddonSetupHook = Hook.FromAddress(this.address.AddonSetup, this.OnAddonSetup);
+ this.onAddonSetupHook = new CallHook(this.address.AddonSetup, this.OnAddonSetup);
this.onAddonFinalizeHook = Hook.FromAddress(this.address.AddonFinalize, this.OnAddonFinalize);
this.onAddonDrawHook = new CallHook(this.address.AddonDraw, this.OnAddonDraw);
this.onAddonUpdateHook = new CallHook(this.address.AddonUpdate, this.OnAddonUpdate);
@@ -54,7 +54,7 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
this.onAddonRequestedUpdateHook = new CallHook(this.address.AddonOnRequestedUpdate, this.OnRequestedUpdate);
}
- private delegate nint AddonSetupDelegate(AtkUnitBase* addon);
+ private delegate void AddonSetupDelegate(AtkUnitBase* addon, uint valueCount, AtkValue* values);
private delegate void AddonFinalizeDelegate(AtkUnitManager* unitManager, AtkUnitBase** atkUnitBase);
@@ -137,29 +137,37 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
}
}
- private nint OnAddonSetup(AtkUnitBase* addon)
+ private void OnAddonSetup(AtkUnitBase* addon, uint valueCount, AtkValue* values)
{
try
{
- this.InvokeListeners(AddonEvent.PreSetup, new AddonSetupArgs { Addon = (nint)addon });
+ this.InvokeListeners(AddonEvent.PreSetup, new AddonSetupArgs()
+ {
+ Addon = (nint)addon,
+ AtkValueCount = valueCount,
+ AtkValues = (nint)values,
+ });
}
catch (Exception e)
{
Log.Error(e, "Exception in OnAddonSetup pre-setup invoke.");
}
- var result = this.onAddonSetupHook.Original(addon);
+ addon->OnSetup(valueCount, values);
try
{
- this.InvokeListeners(AddonEvent.PostSetup, new AddonSetupArgs { Addon = (nint)addon });
+ this.InvokeListeners(AddonEvent.PostSetup, new AddonSetupArgs()
+ {
+ Addon = (nint)addon,
+ AtkValueCount = valueCount,
+ AtkValues = (nint)values,
+ });
}
catch (Exception e)
{
Log.Error(e, "Exception in OnAddonSetup post-setup invoke.");
}
-
- return result;
}
private void OnAddonFinalize(AtkUnitManager* unitManager, AtkUnitBase** atkUnitBase)
diff --git a/Dalamud/Game/AddonLifecycle/AddonLifecycleAddressResolver.cs b/Dalamud/Game/AddonLifecycle/AddonLifecycleAddressResolver.cs
index d68fee9ed..16fd54832 100644
--- a/Dalamud/Game/AddonLifecycle/AddonLifecycleAddressResolver.cs
+++ b/Dalamud/Game/AddonLifecycle/AddonLifecycleAddressResolver.cs
@@ -41,7 +41,7 @@ internal class AddonLifecycleAddressResolver : BaseAddressResolver
/// The signature scanner to facilitate setup.
protected override void Setup64Bit(SigScanner sig)
{
- this.AddonSetup = sig.ScanText("E8 ?? ?? ?? ?? 8B 83 ?? ?? ?? ?? C1 E8 14");
+ this.AddonSetup = sig.ScanText("FF 90 ?? ?? ?? ?? 48 8B 93 ?? ?? ?? ?? 80 8B");
this.AddonFinalize = sig.ScanText("E8 ?? ?? ?? ?? 48 8B 7C 24 ?? 41 8B C6");
this.AddonDraw = sig.ScanText("FF 90 ?? ?? ?? ?? 83 EB 01 79 C1");
this.AddonUpdate = sig.ScanText("FF 90 ?? ?? ?? ?? 40 88 AF");