Add AddonLifecycle to Self-Test

This commit is contained in:
MidoriKami 2023-09-09 20:21:26 -07:00
parent 1b4bee3d13
commit c9a5c7c4c5
3 changed files with 142 additions and 2 deletions

View file

@ -6,8 +6,14 @@ using Reloaded.Hooks.Definitions;
namespace Dalamud.Hooking.Internal;
/// <summary>
/// Hooking class for callsite hooking. This hook does not have capabilities of calling the original function.
/// The intended use is replacing virtual function calls where you are able to manually invoke the original call using the delegate arguments.
/// This class represents a callsite hook. Only the specific address's instructions are replaced with this hook.
/// This is a destructive operation, no other callsite hooks can coexist at the same address.
///
/// There's no .Original for this hook type.
/// This is only intended for be for functions where the parameters provided allow you to invoke the original call.
///
/// This class was specifically added for hooking virtual function callsites.
/// Only the specific callsite hooked is modified, if the game calls the virtual function from other locations this hook will not be triggered.
/// </summary>
/// <typeparam name="T">Delegate signature for this hook.</typeparam>
internal class CallHook<T> : IDisposable where T : Delegate

View file

@ -0,0 +1,133 @@
using System.Collections.Generic;
using Dalamud.Game.AddonLifecycle;
using Dalamud.Plugin.Services;
using ImGuiNET;
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps;
/// <summary>
/// Test setup AddonLifecycle Service.
/// </summary>
internal class AddonLifecycleAgingStep : IAgingStep
{
private readonly List<AddonLifecycleEventListener> listeners;
private AddonLifecycle? service;
private TestStep currentStep = TestStep.CharacterRefresh;
private bool listenersRegistered;
/// <summary>
/// Initializes a new instance of the <see cref="AddonLifecycleAgingStep"/> class.
/// </summary>
public AddonLifecycleAgingStep()
{
this.listeners = new List<AddonLifecycleEventListener>
{
new(AddonEvent.PostSetup, "Character", this.PostSetup),
new(AddonEvent.PostUpdate, "Character", this.PostUpdate),
new(AddonEvent.PostDraw, "Character", this.PostDraw),
new(AddonEvent.PostRefresh, "Character", this.PostRefresh),
new(AddonEvent.PostRequestedUpdate, "Character", this.PostRequestedUpdate),
new(AddonEvent.PreFinalize, "Character", this.PreFinalize),
};
}
private enum TestStep
{
CharacterRefresh,
CharacterSetup,
CharacterRequestedUpdate,
CharacterUpdate,
CharacterDraw,
CharacterFinalize,
Complete,
}
/// <inheritdoc/>
public string Name => "Test AddonLifecycle";
/// <inheritdoc/>
public SelfTestStepResult RunStep()
{
this.service ??= Service<AddonLifecycle>.Get();
if (this.service is null) return SelfTestStepResult.Fail;
if (!this.listenersRegistered)
{
foreach (var listener in this.listeners)
{
this.service.RegisterListener(listener);
}
this.listenersRegistered = true;
}
switch (this.currentStep)
{
case TestStep.CharacterRefresh:
ImGui.Text("Open Character Window.");
break;
case TestStep.CharacterSetup:
ImGui.Text("Open Character Window.");
break;
case TestStep.CharacterRequestedUpdate:
ImGui.Text("Change tabs, or un-equip/equip gear.");
break;
case TestStep.CharacterFinalize:
ImGui.Text("Close Character Window.");
break;
case TestStep.CharacterUpdate:
case TestStep.CharacterDraw:
case TestStep.Complete:
default:
// Nothing to report to tester.
break;
}
return this.currentStep is TestStep.Complete ? SelfTestStepResult.Pass : SelfTestStepResult.Waiting;
}
/// <inheritdoc/>
public void CleanUp()
{
foreach (var listener in this.listeners)
{
this.service?.UnregisterListener(listener);
}
}
private void PostSetup(AddonEvent eventType, IAddonLifecycle.AddonArgs addonInfo)
{
if (this.currentStep is TestStep.CharacterSetup) this.currentStep++;
}
private void PostUpdate(AddonEvent eventType, IAddonLifecycle.AddonArgs addonInfo)
{
if (this.currentStep is TestStep.CharacterUpdate) this.currentStep++;
}
private void PostDraw(AddonEvent eventType, IAddonLifecycle.AddonArgs addonInfo)
{
if (this.currentStep is TestStep.CharacterDraw) this.currentStep++;
}
private void PostRefresh(AddonEvent eventType, IAddonLifecycle.AddonArgs addonInfo)
{
if (this.currentStep is TestStep.CharacterRefresh) this.currentStep++;
}
private void PostRequestedUpdate(AddonEvent eventType, IAddonLifecycle.AddonArgs addonInfo)
{
if (this.currentStep is TestStep.CharacterRequestedUpdate) this.currentStep++;
}
private void PreFinalize(AddonEvent eventType, IAddonLifecycle.AddonArgs addonInfo)
{
if (this.currentStep is TestStep.CharacterFinalize) this.currentStep++;
}
}

View file

@ -39,6 +39,7 @@ internal class SelfTestWindow : Window
new ChatAgingStep(),
new HoverAgingStep(),
new LuminaAgingStep<TerritoryType>(),
new AddonLifecycleAgingStep(),
new PartyFinderAgingStep(),
new HandledExceptionAgingStep(),
new DutyStateAgingStep(),