Use generated AgentId

This commit is contained in:
MidoriKami 2026-01-10 08:30:15 -08:00
parent d689c4763a
commit 0c2ce097ed
5 changed files with 22 additions and 22 deletions

View file

@ -22,7 +22,7 @@ public unsafe class AgentArgs
/// <summary> /// <summary>
/// Gets the agent id. /// Gets the agent id.
/// </summary> /// </summary>
public uint AgentId { get; internal set; } public AgentId AgentId { get; internal set; }
/// <summary> /// <summary>
/// Gets the type of these args. /// Gets the type of these args.

View file

@ -57,7 +57,7 @@ internal unsafe class AgentLifecycle : IInternalDisposableService
/// Gets a list of all AgentLifecycle Event Listeners. /// Gets a list of all AgentLifecycle Event Listeners.
/// </summary> <br/> /// </summary> <br/>
/// Mapping is: EventType -> ListenerList /// Mapping is: EventType -> ListenerList
internal Dictionary<AgentEvent, Dictionary<uint, HashSet<AgentLifecycleEventListener>>> EventListeners { get; } = []; internal Dictionary<AgentEvent, Dictionary<AgentId, HashSet<AgentLifecycleEventListener>>> EventListeners { get; } = [];
/// <inheritdoc/> /// <inheritdoc/>
void IInternalDisposableService.DisposeService() void IInternalDisposableService.DisposeService()
@ -128,7 +128,7 @@ internal unsafe class AgentLifecycle : IInternalDisposableService
if (!this.EventListeners.TryGetValue(eventType, out var agentListeners)) return; if (!this.EventListeners.TryGetValue(eventType, out var agentListeners)) return;
// Handle listeners for this event type that don't care which agent is triggering it // Handle listeners for this event type that don't care which agent is triggering it
if (agentListeners.TryGetValue(uint.MaxValue, out var globalListeners)) if (agentListeners.TryGetValue((AgentId)uint.MaxValue, out var globalListeners))
{ {
foreach (var listener in globalListeners) foreach (var listener in globalListeners)
{ {
@ -154,7 +154,7 @@ internal unsafe class AgentLifecycle : IInternalDisposableService
} }
catch (Exception e) catch (Exception e)
{ {
Log.Error(e, $"Exception in {blame} during {eventType} invoke, for specific agent {(AgentId)args.AgentId}."); Log.Error(e, $"Exception in {blame} during {eventType} invoke, for specific agent {args.AgentId}.");
} }
} }
} }
@ -208,7 +208,7 @@ internal unsafe class AgentLifecycle : IInternalDisposableService
} }
// AgentVirtualTable class handles creating the virtual table, and overriding each of the tracked virtual functions // AgentVirtualTable class handles creating the virtual table, and overriding each of the tracked virtual functions
AllocatedTables.Add(new AgentVirtualTable(agentPointer->Value, index, this)); AllocatedTables.Add(new AgentVirtualTable(agentPointer->Value, (AgentId)index, this));
} }
catch (Exception e) catch (Exception e)
{ {
@ -243,7 +243,7 @@ internal class AgentLifecyclePluginScoped : IInternalDisposableService, IAgentLi
} }
/// <inheritdoc/> /// <inheritdoc/>
public void RegisterListener(AgentEvent eventType, IEnumerable<uint> agentIds, IAgentLifecycle.AgentEventDelegate handler) public void RegisterListener(AgentEvent eventType, IEnumerable<AgentId> agentIds, IAgentLifecycle.AgentEventDelegate handler)
{ {
foreach (var agentId in agentIds) foreach (var agentId in agentIds)
{ {
@ -252,7 +252,7 @@ internal class AgentLifecyclePluginScoped : IInternalDisposableService, IAgentLi
} }
/// <inheritdoc/> /// <inheritdoc/>
public void RegisterListener(AgentEvent eventType, uint agentId, IAgentLifecycle.AgentEventDelegate handler) public void RegisterListener(AgentEvent eventType, AgentId agentId, IAgentLifecycle.AgentEventDelegate handler)
{ {
var listener = new AgentLifecycleEventListener(eventType, agentId, handler); var listener = new AgentLifecycleEventListener(eventType, agentId, handler);
this.eventListeners.Add(listener); this.eventListeners.Add(listener);
@ -262,11 +262,11 @@ internal class AgentLifecyclePluginScoped : IInternalDisposableService, IAgentLi
/// <inheritdoc/> /// <inheritdoc/>
public void RegisterListener(AgentEvent eventType, IAgentLifecycle.AgentEventDelegate handler) public void RegisterListener(AgentEvent eventType, IAgentLifecycle.AgentEventDelegate handler)
{ {
this.RegisterListener(eventType, uint.MaxValue, handler); this.RegisterListener(eventType, (AgentId)uint.MaxValue, handler);
} }
/// <inheritdoc/> /// <inheritdoc/>
public void UnregisterListener(AgentEvent eventType, IEnumerable<uint> agentIds, IAgentLifecycle.AgentEventDelegate? handler = null) public void UnregisterListener(AgentEvent eventType, IEnumerable<AgentId> agentIds, IAgentLifecycle.AgentEventDelegate? handler = null)
{ {
foreach (var agentId in agentIds) foreach (var agentId in agentIds)
{ {
@ -275,7 +275,7 @@ internal class AgentLifecyclePluginScoped : IInternalDisposableService, IAgentLi
} }
/// <inheritdoc/> /// <inheritdoc/>
public void UnregisterListener(AgentEvent eventType, uint agentId, IAgentLifecycle.AgentEventDelegate? handler = null) public void UnregisterListener(AgentEvent eventType, AgentId agentId, IAgentLifecycle.AgentEventDelegate? handler = null)
{ {
this.eventListeners.RemoveAll(entry => this.eventListeners.RemoveAll(entry =>
{ {
@ -291,7 +291,7 @@ internal class AgentLifecyclePluginScoped : IInternalDisposableService, IAgentLi
/// <inheritdoc/> /// <inheritdoc/>
public void UnregisterListener(AgentEvent eventType, IAgentLifecycle.AgentEventDelegate? handler = null) public void UnregisterListener(AgentEvent eventType, IAgentLifecycle.AgentEventDelegate? handler = null)
{ {
this.UnregisterListener(eventType, uint.MaxValue, handler); this.UnregisterListener(eventType, (AgentId)uint.MaxValue, handler);
} }
/// <inheritdoc/> /// <inheritdoc/>

View file

@ -13,7 +13,7 @@ public class AgentLifecycleEventListener
/// <param name="eventType">Event type to listen for.</param> /// <param name="eventType">Event type to listen for.</param>
/// <param name="agentId">Agent id to listen for.</param> /// <param name="agentId">Agent id to listen for.</param>
/// <param name="functionDelegate">Delegate to invoke.</param> /// <param name="functionDelegate">Delegate to invoke.</param>
internal AgentLifecycleEventListener(AgentEvent eventType, uint agentId, IAgentLifecycle.AgentEventDelegate functionDelegate) internal AgentLifecycleEventListener(AgentEvent eventType, AgentId agentId, IAgentLifecycle.AgentEventDelegate functionDelegate)
{ {
this.EventType = eventType; this.EventType = eventType;
this.AgentId = agentId; this.AgentId = agentId;
@ -24,7 +24,7 @@ public class AgentLifecycleEventListener
/// Gets the agentId of the agent this listener is looking for. /// Gets the agentId of the agent this listener is looking for.
/// uint.MaxValue if it wants to be called for any agent. /// uint.MaxValue if it wants to be called for any agent.
/// </summary> /// </summary>
public uint AgentId { get; init; } public AgentId AgentId { get; init; }
/// <summary> /// <summary>
/// Gets the event type this listener is looking for. /// Gets the event type this listener is looking for.

View file

@ -27,7 +27,7 @@ internal unsafe class AgentVirtualTable : IDisposable
private readonly AgentLifecycle lifecycleService; private readonly AgentLifecycle lifecycleService;
private readonly uint agentId; private readonly AgentId agentId;
// Each agent gets its own set of args that are used to mutate the original call when used in pre-calls // Each agent gets its own set of args that are used to mutate the original call when used in pre-calls
private readonly AgentReceiveEventArgs receiveEventArgs = new(); private readonly AgentReceiveEventArgs receiveEventArgs = new();
@ -58,9 +58,9 @@ internal unsafe class AgentVirtualTable : IDisposable
/// <param name="agent">AgentInterface* for the agent to replace the table of.</param> /// <param name="agent">AgentInterface* for the agent to replace the table of.</param>
/// <param name="agentId">Agent ID.</param> /// <param name="agentId">Agent ID.</param>
/// <param name="lifecycleService">Reference to AgentLifecycle service to callback and invoke listeners.</param> /// <param name="lifecycleService">Reference to AgentLifecycle service to callback and invoke listeners.</param>
internal AgentVirtualTable(AgentInterface* agent, uint agentId, AgentLifecycle lifecycleService) internal AgentVirtualTable(AgentInterface* agent, AgentId agentId, AgentLifecycle lifecycleService)
{ {
Log.Debug($"Initializing AgentVirtualTable for {(AgentId)agentId}, Address: {(nint)agent:X}"); Log.Debug($"Initializing AgentVirtualTable for {agentId}, Address: {(nint)agent:X}");
this.agentInterface = agent; this.agentInterface = agent;
this.agentId = agentId; this.agentId = agentId;
@ -384,10 +384,10 @@ internal unsafe class AgentVirtualTable : IDisposable
if (loggingEnabled) if (loggingEnabled)
{ {
// Manually disable the really spammy log events, you can comment this out if you need to debug them. // Manually disable the really spammy log events, you can comment this out if you need to debug them.
if (caller is "OnAgentUpdate" || (AgentId)this.agentId is AgentId.PadMouseMode) if (caller is "OnAgentUpdate" || this.agentId is AgentId.PadMouseMode)
return; return;
Log.Debug($"[{caller}]: {(AgentId)this.agentId}"); Log.Debug($"[{caller}]: {this.agentId}");
} }
} }
} }

View file

@ -24,7 +24,7 @@ public interface IAgentLifecycle : IDalamudService
/// <param name="eventType">Event type to trigger on.</param> /// <param name="eventType">Event type to trigger on.</param>
/// <param name="agentIds">Agent IDs that will trigger the handler to be invoked.</param> /// <param name="agentIds">Agent IDs that will trigger the handler to be invoked.</param>
/// <param name="handler">The handler to invoke.</param> /// <param name="handler">The handler to invoke.</param>
void RegisterListener(AgentEvent eventType, IEnumerable<uint> agentIds, AgentEventDelegate handler); void RegisterListener(AgentEvent eventType, IEnumerable<AgentId> agentIds, AgentEventDelegate handler);
/// <summary> /// <summary>
/// Register a listener that will trigger on the specified event only for the specified agent. /// Register a listener that will trigger on the specified event only for the specified agent.
@ -32,7 +32,7 @@ public interface IAgentLifecycle : IDalamudService
/// <param name="eventType">Event type to trigger on.</param> /// <param name="eventType">Event type to trigger on.</param>
/// <param name="agentId">The agent ID that will trigger the handler to be invoked.</param> /// <param name="agentId">The agent ID that will trigger the handler to be invoked.</param>
/// <param name="handler">The handler to invoke.</param> /// <param name="handler">The handler to invoke.</param>
void RegisterListener(AgentEvent eventType, uint agentId, AgentEventDelegate handler); void RegisterListener(AgentEvent eventType, AgentId agentId, AgentEventDelegate handler);
/// <summary> /// <summary>
/// Register a listener that will trigger on the specified event for any agent. /// Register a listener that will trigger on the specified event for any agent.
@ -50,7 +50,7 @@ public interface IAgentLifecycle : IDalamudService
/// <param name="eventType">Event type to deregister.</param> /// <param name="eventType">Event type to deregister.</param>
/// <param name="agentIds">Agent IDs to deregister.</param> /// <param name="agentIds">Agent IDs to deregister.</param>
/// <param name="handler">Optional specific handler to remove.</param> /// <param name="handler">Optional specific handler to remove.</param>
void UnregisterListener(AgentEvent eventType, IEnumerable<uint> agentIds, [Optional] AgentEventDelegate handler); void UnregisterListener(AgentEvent eventType, IEnumerable<AgentId> agentIds, [Optional] AgentEventDelegate handler);
/// <summary> /// <summary>
/// Unregister all listeners for the specified event type and agent ID. /// Unregister all listeners for the specified event type and agent ID.
@ -61,7 +61,7 @@ public interface IAgentLifecycle : IDalamudService
/// <param name="eventType">Event type to deregister.</param> /// <param name="eventType">Event type to deregister.</param>
/// <param name="agentId">Agent id to deregister.</param> /// <param name="agentId">Agent id to deregister.</param>
/// <param name="handler">Optional specific handler to remove.</param> /// <param name="handler">Optional specific handler to remove.</param>
void UnregisterListener(AgentEvent eventType, uint agentId, [Optional] AgentEventDelegate handler); void UnregisterListener(AgentEvent eventType, AgentId agentId, [Optional] AgentEventDelegate handler);
/// <summary> /// <summary>
/// Unregister an event type handler.<br/>This will only remove a handler that is added via <see cref="RegisterListener(AgentEvent, AgentEventDelegate)"/>. /// Unregister an event type handler.<br/>This will only remove a handler that is added via <see cref="RegisterListener(AgentEvent, AgentEventDelegate)"/>.