diff --git a/Dalamud/Game/Chat/LogMessage.cs b/Dalamud/Game/Chat/LogMessage.cs index 93b928d48..c772783a1 100644 --- a/Dalamud/Game/Chat/LogMessage.cs +++ b/Dalamud/Game/Chat/LogMessage.cs @@ -1,3 +1,5 @@ +using System.Diagnostics.CodeAnalysis; + using Dalamud.Data; using Dalamud.Utility; @@ -10,8 +12,6 @@ using FFXIVClientStructs.Interop; using Lumina.Excel; using Lumina.Text.ReadOnly; -using System.Diagnostics.CodeAnalysis; - namespace Dalamud.Game.Chat; /// @@ -88,30 +88,41 @@ internal unsafe readonly struct LogMessage(LogMessageQueueItem* ptr) : ILogMessa /// public RowRef GameData => LuminaUtils.CreateRef(ptr->LogMessageId); - public LogMessageEntity SourceEntity => new LogMessageEntity(ptr, true); /// ILogMessageEntity? ILogMessage.SourceEntity => ptr->SourceKind == EntityRelationKind.None ? null : this.SourceEntity; - public LogMessageEntity TargetEntity => new LogMessageEntity(ptr, false); - /// ILogMessageEntity? ILogMessage.TargetEntity => ptr->TargetKind == EntityRelationKind.None ? null : this.TargetEntity; /// public int ParameterCount => ptr->Parameters.Count; - public bool TryGetParameter(int index, out TextParameter value) - { - if (index < 0 || index >= ptr->Parameters.Count) - { - value = default; - return false; - } + private LogMessageEntity SourceEntity => new(ptr, true); - value = ptr->Parameters[index]; - return true; + private LogMessageEntity TargetEntity => new(ptr, false); + + public static bool operator ==(LogMessage x, LogMessage y) => x.Equals(y); + + public static bool operator !=(LogMessage x, LogMessage y) => !(x == y); + + /// + public bool Equals(ILogMessage? other) + { + return other is LogMessage logMessage && this.Equals(logMessage); } + /// + public override bool Equals([NotNullWhen(true)] object? obj) + { + return obj is LogMessage logMessage && this.Equals(logMessage); + } + + /// + public override int GetHashCode() + { + return HashCode.Combine(this.LogMessageId, this.SourceEntity, this.TargetEntity); + } + /// public bool TryGetIntParameter(int index, out int value) { @@ -132,6 +143,7 @@ internal unsafe readonly struct LogMessage(LogMessageQueueItem* ptr) : ILogMessa value = new(parameter.StringValue.AsSpan()); return true; } + if (parameter.Type == TextParameterType.ReferencedUtf8String) { value = new(parameter.ReferencedUtf8StringValue->Utf8String.AsSpan()); @@ -157,7 +169,7 @@ internal unsafe readonly struct LogMessage(LogMessageQueueItem* ptr) : ILogMessa return new ReadOnlySeString(utf8.AsSpan()); - void SetName(RaptureLogModule* self, LogMessageEntity item) + static void SetName(RaptureLogModule* self, LogMessageEntity item) { var name = item.NameSpan.GetPointer(0); @@ -190,31 +202,20 @@ internal unsafe readonly struct LogMessage(LogMessageQueueItem* ptr) : ILogMessa } } + private bool TryGetParameter(int index, out TextParameter value) + { + if (index < 0 || index >= ptr->Parameters.Count) + { + value = default; + return false; + } - public static bool operator ==(LogMessage x, LogMessage y) => x.Equals(y); + value = ptr->Parameters[index]; + return true; + } - public static bool operator !=(LogMessage x, LogMessage y) => !(x == y); - - public bool Equals(LogMessage other) + private bool Equals(LogMessage other) { return this.LogMessageId == other.LogMessageId && this.SourceEntity == other.SourceEntity && this.TargetEntity == other.TargetEntity; } - - /// - public bool Equals(ILogMessage? other) - { - return other is LogMessage logMessage && this.Equals(logMessage); - } - - /// - public override bool Equals([NotNullWhen(true)] object? obj) - { - return obj is LogMessage logMessage && this.Equals(logMessage); - } - - /// - public override int GetHashCode() - { - return HashCode.Combine(this.LogMessageId, this.SourceEntity, this.TargetEntity); - } } diff --git a/Dalamud/Game/Chat/LogMessageEntity.cs b/Dalamud/Game/Chat/LogMessageEntity.cs index 4294e4898..91e905928 100644 --- a/Dalamud/Game/Chat/LogMessageEntity.cs +++ b/Dalamud/Game/Chat/LogMessageEntity.cs @@ -37,46 +37,57 @@ public interface ILogMessageEntity : IEquatable uint ObjStrId { get; } /// - /// Gets a boolean indicating if this entity is a player. + /// Gets a value indicating whether this entity is a player. /// bool IsPlayer { get; } } - /// /// This struct represents an entity related to a log message. /// /// A pointer to the log message item. -/// If represents the source entity of the log message, otherwise represents the target entity +/// If represents the source entity of the log message, otherwise represents the target entity. internal unsafe readonly struct LogMessageEntity(LogMessageQueueItem* ptr, bool source) : ILogMessageEntity { - public Span NameSpan => source ? ptr->SourceName : ptr->TargetName; - - public ReadOnlySeString Name => new ReadOnlySeString(this.NameSpan[..this.NameSpan.IndexOf((byte)0)]); + /// + public ReadOnlySeString Name => new(this.NameSpan[..this.NameSpan.IndexOf((byte)0)]); + /// public ushort HomeWorldId => source ? ptr->SourceHomeWorld : ptr->TargetHomeWorld; + /// public RowRef HomeWorld => LuminaUtils.CreateRef(this.HomeWorldId); + /// public uint ObjStrId => source ? ptr->SourceObjStrId : ptr->TargetObjStrId; - public byte Kind => source ? (byte)ptr->SourceKind : (byte)ptr->TargetKind; - - public byte Sex => source ? ptr->SourceSex : ptr->TargetSex; - + /// public bool IsPlayer => source ? ptr->SourceIsPlayer : ptr->TargetIsPlayer; - public bool IsSourceEntity => source; + /// + /// Gets the Span containing the raw name of this entity. + /// + internal Span NameSpan => source ? ptr->SourceName : ptr->TargetName; + + /// + /// Gets the kind of the entity. + /// + internal byte Kind => source ? (byte)ptr->SourceKind : (byte)ptr->TargetKind; + + /// + /// Gets the Sex of this entity. + /// + internal byte Sex => source ? ptr->SourceSex : ptr->TargetSex; + + /// + /// Gets a value indicating whether this entity is the source entity of a log message. + /// + internal bool IsSourceEntity => source; public static bool operator ==(LogMessageEntity x, LogMessageEntity y) => x.Equals(y); public static bool operator !=(LogMessageEntity x, LogMessageEntity y) => !(x == y); - public bool Equals(LogMessageEntity other) - { - return this.Name == other.Name && this.HomeWorldId == other.HomeWorldId && this.ObjStrId == other.ObjStrId && this.Kind == other.Kind && this.Sex == other.Sex && this.IsPlayer == other.IsPlayer; - } - /// public bool Equals(ILogMessageEntity other) { @@ -94,4 +105,9 @@ internal unsafe readonly struct LogMessageEntity(LogMessageQueueItem* ptr, bool { return HashCode.Combine(this.Name, this.HomeWorldId, this.ObjStrId, this.Sex, this.IsPlayer); } + + private bool Equals(LogMessageEntity other) + { + return this.Name == other.Name && this.HomeWorldId == other.HomeWorldId && this.ObjStrId == other.ObjStrId && this.Kind == other.Kind && this.Sex == other.Sex && this.IsPlayer == other.IsPlayer; + } } diff --git a/Dalamud/Interface/Internal/Windows/SelfTest/Steps/ChatSelfTestStep.cs b/Dalamud/Interface/Internal/Windows/SelfTest/Steps/ChatSelfTestStep.cs index d4311176e..851957b4b 100644 --- a/Dalamud/Interface/Internal/Windows/SelfTest/Steps/ChatSelfTestStep.cs +++ b/Dalamud/Interface/Internal/Windows/SelfTest/Steps/ChatSelfTestStep.cs @@ -17,8 +17,8 @@ internal class ChatSelfTestStep : ISelfTestStep private bool subscribedLogMessage = false; private bool hasSeenEchoMessage = false; private bool hasSeenActionMessage = false; - private string actionName = ""; - private string actionUser = ""; + private string actionName = string.Empty; + private string actionUser = string.Empty; /// public string Name => "Test Chat"; diff --git a/Dalamud/Plugin/Services/IChatGui.cs b/Dalamud/Plugin/Services/IChatGui.cs index eec25cb5a..2bb7b6913 100644 --- a/Dalamud/Plugin/Services/IChatGui.cs +++ b/Dalamud/Plugin/Services/IChatGui.cs @@ -51,7 +51,6 @@ public interface IChatGui : IDalamudService /// The message sent. public delegate void OnMessageUnhandledDelegate(XivChatType type, int timestamp, SeString sender, SeString message); - /// /// A delegate type used with the event. ///