mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Use CallHook for AddonSetup
This commit is contained in:
parent
0636a03e41
commit
bd81d23097
3 changed files with 28 additions and 10 deletions
|
|
@ -10,4 +10,14 @@ public class AddonSetupArgs : IAddonArgs
|
|||
|
||||
/// <inheritdoc/>
|
||||
public AddonArgsType Type => AddonArgsType.Setup;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of AtkValues.
|
||||
/// </summary>
|
||||
public uint AtkValueCount { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the address of the AtkValue array.
|
||||
/// </summary>
|
||||
public nint AtkValues { get; init; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
|
|||
private readonly Framework framework = Service<Framework>.Get();
|
||||
|
||||
private readonly AddonLifecycleAddressResolver address;
|
||||
private readonly Hook<AddonSetupDelegate> onAddonSetupHook;
|
||||
private readonly CallHook<AddonSetupDelegate> onAddonSetupHook;
|
||||
private readonly Hook<AddonFinalizeDelegate> onAddonFinalizeHook;
|
||||
private readonly CallHook<AddonDrawDelegate> onAddonDrawHook;
|
||||
private readonly CallHook<AddonUpdateDelegate> onAddonUpdateHook;
|
||||
|
|
@ -46,7 +46,7 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
|
|||
|
||||
this.framework.Update += this.OnFrameworkUpdate;
|
||||
|
||||
this.onAddonSetupHook = Hook<AddonSetupDelegate>.FromAddress(this.address.AddonSetup, this.OnAddonSetup);
|
||||
this.onAddonSetupHook = new CallHook<AddonSetupDelegate>(this.address.AddonSetup, this.OnAddonSetup);
|
||||
this.onAddonFinalizeHook = Hook<AddonFinalizeDelegate>.FromAddress(this.address.AddonFinalize, this.OnAddonFinalize);
|
||||
this.onAddonDrawHook = new CallHook<AddonDrawDelegate>(this.address.AddonDraw, this.OnAddonDraw);
|
||||
this.onAddonUpdateHook = new CallHook<AddonUpdateDelegate>(this.address.AddonUpdate, this.OnAddonUpdate);
|
||||
|
|
@ -54,7 +54,7 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
|
|||
this.onAddonRequestedUpdateHook = new CallHook<AddonOnRequestedUpdateDelegate>(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)
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ internal class AddonLifecycleAddressResolver : BaseAddressResolver
|
|||
/// <param name="sig">The signature scanner to facilitate setup.</param>
|
||||
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");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue