From 6a0401646ff99ea845fb16e7f48a7e3e1c7314dd Mon Sep 17 00:00:00 2001
From: MidoriKami <9083275+MidoriKami@users.noreply.github.com>
Date: Thu, 7 Sep 2023 11:47:35 -0700
Subject: [PATCH] Add AddonOnRequestedUpdate
---
Dalamud/Game/AddonLifecycle/AddonEvent.cs | 10 ++++++
Dalamud/Game/AddonLifecycle/AddonLifecycle.cs | 31 +++++++++++++++++++
.../AddonLifecycleAddressResolver.cs | 6 ++++
3 files changed, 47 insertions(+)
diff --git a/Dalamud/Game/AddonLifecycle/AddonEvent.cs b/Dalamud/Game/AddonLifecycle/AddonEvent.cs
index 0125d1337..30121d162 100644
--- a/Dalamud/Game/AddonLifecycle/AddonEvent.cs
+++ b/Dalamud/Game/AddonLifecycle/AddonEvent.cs
@@ -39,4 +39,14 @@ public enum AddonEvent
/// Event that is fired before an addon is finalized.
///
PreFinalize,
+
+ ///
+ /// Event that is fired before an addon begins a requested update.
+ ///
+ PreRequestedUpdate,
+
+ ///
+ /// Event that is fired after an addon finishes a requested update.
+ ///
+ PostRequestedUpdate,
}
diff --git a/Dalamud/Game/AddonLifecycle/AddonLifecycle.cs b/Dalamud/Game/AddonLifecycle/AddonLifecycle.cs
index a3e9f4be8..9bc792f46 100644
--- a/Dalamud/Game/AddonLifecycle/AddonLifecycle.cs
+++ b/Dalamud/Game/AddonLifecycle/AddonLifecycle.cs
@@ -30,6 +30,7 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
private readonly Hook onAddonFinalizeHook;
private readonly CallHook onAddonDrawHook;
private readonly CallHook onAddonUpdateHook;
+ // private readonly CallHook onAddonRequestedUpdateHook; // See Note in Ctor
private readonly ConcurrentBag newEventListeners = new();
private readonly ConcurrentBag removeEventListeners = new();
@@ -47,6 +48,9 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
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);
+
+ // todo: reenable this. WARNING: This hook overwrites a system that SimpleTweaks uses, causing SimpleTweaks to report exceptions.
+ // this.onAddonRequestedUpdateHook = new CallHook(this.address.AddonOnRequestedUpdate, this.OnRequestedUpdate);
}
private delegate nint AddonSetupDelegate(AtkUnitBase* addon);
@@ -57,6 +61,8 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
private delegate void AddonUpdateDelegate(AtkUnitBase* addon, float delta);
+ private delegate void AddonOnRequestedUpdate(AtkUnitBase* addon, NumberArrayData** numberArrayData, StringArrayData** stringArrayData);
+
///
public void Dispose()
{
@@ -66,6 +72,7 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
this.onAddonFinalizeHook.Dispose();
this.onAddonDrawHook.Dispose();
this.onAddonUpdateHook.Dispose();
+ // this.onAddonRequestedUpdateHook.Dispose(); // See Note in Ctor
}
///
@@ -113,6 +120,7 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
this.onAddonFinalizeHook.Enable();
this.onAddonDrawHook.Enable();
this.onAddonUpdateHook.Enable();
+ // this.onAddonRequestedUpdateHook.Enable(); // See Note in Ctor
}
private void InvokeListeners(AddonEvent eventType, IAddonLifecycle.AddonArgs args)
@@ -217,6 +225,29 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
Log.Error(e, "Exception in OnAddonUpdate post-update invoke.");
}
}
+
+ private void OnRequestedUpdate(AtkUnitBase* addon, NumberArrayData** numberArrayData, StringArrayData** stringArrayData)
+ {
+ try
+ {
+ this.InvokeListeners(AddonEvent.PreRequestedUpdate, new IAddonLifecycle.AddonArgs { Addon = (nint)addon });
+ }
+ catch (Exception e)
+ {
+ Log.Error(e, "Exception in OnRequestedUpdate pre-requestedUpdate invoke.");
+ }
+
+ addon->OnUpdate(numberArrayData, stringArrayData);
+
+ try
+ {
+ this.InvokeListeners(AddonEvent.PostRequestedUpdate, new IAddonLifecycle.AddonArgs { Addon = (nint)addon });
+ }
+ catch (Exception e)
+ {
+ Log.Error(e, "Exception in OnRequestedUpdate post-requestedUpdate invoke.");
+ }
+ }
}
///
diff --git a/Dalamud/Game/AddonLifecycle/AddonLifecycleAddressResolver.cs b/Dalamud/Game/AddonLifecycle/AddonLifecycleAddressResolver.cs
index 688476d82..557cedc34 100644
--- a/Dalamud/Game/AddonLifecycle/AddonLifecycleAddressResolver.cs
+++ b/Dalamud/Game/AddonLifecycle/AddonLifecycleAddressResolver.cs
@@ -24,6 +24,11 @@ internal class AddonLifecycleAddressResolver : BaseAddressResolver
/// Gets the address of the addon update hook invoked by virtual function call.
///
public nint AddonUpdate { get; private set; }
+
+ ///
+ /// Gets the address of the addon onRequestedUpdate hook invoked by virtual function call.
+ ///
+ public nint AddonOnRequestedUpdate { get; private set; }
///
/// Scan for and setup any configured address pointers.
@@ -35,5 +40,6 @@ internal class AddonLifecycleAddressResolver : BaseAddressResolver
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");
+ this.AddonOnRequestedUpdate = sig.ScanText("FF 90 90 01 00 00 48 8B 5C 24 30 48 83 C4 20");
}
}