From d3c44080b5198f311879acc6896ab871c20cd298 Mon Sep 17 00:00:00 2001 From: shakdar Date: Sat, 11 Feb 2023 04:39:32 -0700 Subject: [PATCH] implemented everything --- Dalamud/Game/Text/SeStringHandling/Payload.cs | 16 ++ .../Game/Text/SeStringHandling/PayloadType.cs | 5 + .../Payloads/PartyFinderPayload.cs | 146 ++++++++++++++++++ .../Game/Text/SeStringHandling/SeString.cs | 45 ++++++ 4 files changed, 212 insertions(+) create mode 100644 Dalamud/Game/Text/SeStringHandling/Payloads/PartyFinderPayload.cs diff --git a/Dalamud/Game/Text/SeStringHandling/Payload.cs b/Dalamud/Game/Text/SeStringHandling/Payload.cs index dc4b7cba0..dbd70a58e 100644 --- a/Dalamud/Game/Text/SeStringHandling/Payload.cs +++ b/Dalamud/Game/Text/SeStringHandling/Payload.cs @@ -168,6 +168,12 @@ public abstract partial class Payload payload = new DalamudLinkPayload(); break; + case EmbeddedInfoType.PartyFinderNotificationLink: + // this is handled by PartyFinderPayload, so let this fall through + case EmbeddedInfoType.PartyFinderLink: + payload = new PartyFinderPayload(); + break; + case EmbeddedInfoType.LinkTerminator: // this has no custom handling and so needs to fallthrough to ensure it is captured default: @@ -267,11 +273,21 @@ public abstract partial class Payload /// QuestLink = 0x05, + /// + /// The link to the party finder search conditions. + /// + PartyFinderNotificationLink = 0x08, + /// /// A status effect. /// Status = 0x09, + /// + /// The link to a party finder listing. + /// + PartyFinderLink = 0x0A, + /// /// A custom Dalamud link. /// diff --git a/Dalamud/Game/Text/SeStringHandling/PayloadType.cs b/Dalamud/Game/Text/SeStringHandling/PayloadType.cs index c58f2954d..820cf6bbe 100644 --- a/Dalamud/Game/Text/SeStringHandling/PayloadType.cs +++ b/Dalamud/Game/Text/SeStringHandling/PayloadType.cs @@ -79,4 +79,9 @@ public enum PayloadType /// An SeString payload representing a doublewide SE hypen. /// SeHyphen, + + /// + /// An SeString payload representing a party finder link. + /// + PartyFinder, } diff --git a/Dalamud/Game/Text/SeStringHandling/Payloads/PartyFinderPayload.cs b/Dalamud/Game/Text/SeStringHandling/Payloads/PartyFinderPayload.cs new file mode 100644 index 000000000..8a9124504 --- /dev/null +++ b/Dalamud/Game/Text/SeStringHandling/Payloads/PartyFinderPayload.cs @@ -0,0 +1,146 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.IO; + +using Lumina.Extensions; +using Newtonsoft.Json; + +namespace Dalamud.Game.Text.SeStringHandling.Payloads +{ + /// + /// An SeString Payload representing an interactable party finder link. + /// + public class PartyFinderPayload : Payload + { + /// + /// Delimiting byte for party finder payload flags. + /// + // at least that's what i think it is... in any case, this works. + [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "This is preferred.")] + protected const byte FLAG_DELIMITER = 0x01; + + /// + /// Initializes a new instance of the class. + /// Creates a payload representing an interactable party finder link for the specified party finder listing. + /// + /// The listing ID of the party finder listing. + /// The party finder link type that should be encoded with this link. + public PartyFinderPayload(uint listingId, PartyFinderLinkType type) + { + this.ListingId = listingId; + this.LinkType = type; + } + + /// + /// Initializes a new instance of the class. + /// Creates a payload representing an interactable party finder notification link. + /// + public PartyFinderPayload() + { + } + + /// + /// Represents the flags in a party finder link. + /// + public enum PartyFinderLinkType + { + /// + /// Indicates that the party finder link is for a party that is limited to the host's home world. + /// + LimitedToHomeWorld = 0xF3, + + /// + /// Indicates that the party finder link is for the "Display advanced search results in log." option. + /// + PartyFinderNotification = 0xFF, + + /// + /// Indicates that the party finder link type was unspecified. Only for internal use. Not used by SE and omitted from encoding. + /// + NotSpecified = 0x00, + } + + /// + /// Gets the party finder listing ID. + /// + [JsonProperty] + public uint ListingId { get; private set; } + + /// + /// Gets the link type. + /// + [JsonProperty] + public PartyFinderLinkType LinkType { get; private set; } = PartyFinderLinkType.PartyFinderNotification; + + /// + public override PayloadType Type => PayloadType.PartyFinder; + + /// + protected override void DecodeImpl(BinaryReader reader, long endOfStream) + { + // 0x01 here indicates a party finder notification, which needs to be handled uniquely + if (reader.PeekByte() == 0x01) + { + this.LinkType = PartyFinderLinkType.PartyFinderNotification; + return; + } + + this.ListingId = GetInteger(reader); + + // throw away always 0x01 + reader.ReadByte(); + + // if the next byte is 0xF3 then this listing is limited to home world + byte nextByte = reader.ReadByte(); + switch (nextByte) + { + case (byte)PartyFinderLinkType.LimitedToHomeWorld: + this.LinkType = PartyFinderLinkType.LimitedToHomeWorld; + break; + + // if this byte is just the flag delimiter, then nothing was specified. + case FLAG_DELIMITER: + this.LinkType = PartyFinderLinkType.NotSpecified; + break; + + default: + Serilog.Log.Information($"Unrecognized PartyFinderLinkType code {nextByte} (Hex - {nextByte:X2})"); + break; + } + } + + /// + protected override byte[] EncodeImpl() + { + // if the link type is notification, just use premade payload data since it's always the same. + // i have no idea why it is formatted like this, but it is how it is. + // note it is identical to the link terminator payload except the embedded info type is 0x08 + if (this.LinkType == PartyFinderLinkType.PartyFinderNotification) return new byte[] { 0x02, 0x27, 0x07, 0x08, 0x01, 0x01, 0x01, 0xFF, 0x01, 0x03, }; + + // back to our regularly scheduled programming... + var listingIDBytes = MakeInteger(this.ListingId); + bool isFlagSpecified = this.LinkType != PartyFinderLinkType.NotSpecified; + + var chunkLen = listingIDBytes.Length + 4; + // 1 more byte for the type flag if it is specified + if (isFlagSpecified) chunkLen++; + + var bytes = new List() + { + START_BYTE, (byte)SeStringChunkType.Interactable, (byte)chunkLen, (byte)EmbeddedInfoType.PartyFinderLink, + }; + + bytes.AddRange(listingIDBytes); + + bytes.Add(FLAG_DELIMITER); + + if (isFlagSpecified) bytes.Add((byte)this.LinkType); + + bytes.Add(FLAG_DELIMITER); + + bytes.Add(END_BYTE); + + return bytes.ToArray(); + } + } +} diff --git a/Dalamud/Game/Text/SeStringHandling/SeString.cs b/Dalamud/Game/Text/SeStringHandling/SeString.cs index 8413bf610..6d0c8b0fb 100644 --- a/Dalamud/Game/Text/SeStringHandling/SeString.cs +++ b/Dalamud/Game/Text/SeStringHandling/SeString.cs @@ -314,6 +314,51 @@ public class SeString return null; } + /// + /// Creates an SeString representing an entire payload chain that can be used to link party finder listings in the chat log. + /// + /// The listing ID of the party finder entry. + /// The name of the recruiter. + /// Whether the listing is limited to the current world or not. + /// An SeString containing all the payloads necessary to display a party finder link in the chat log. + public static SeString CreatePartyFinderLink(uint listingId, string recruiterName, bool isCrossWorld = false) + { + var payloads = new List() + { + new PartyFinderPayload(listingId, isCrossWorld ? PartyFinderPayload.PartyFinderLinkType.NotSpecified : PartyFinderPayload.PartyFinderLinkType.LimitedToHomeWorld), + // -> + new TextPayload($"Looking for Party ({recruiterName})"), + }; + + payloads.InsertRange(1, TextArrowPayloads); + + if (isCrossWorld) + payloads.Add(new IconPayload(BitmapFontIcon.CrossWorld)); + + payloads.Add(RawPayload.LinkTerminator); + + return new SeString(payloads); + } + + /// + /// Creates an SeString representing an entire payload chain that can be used to link the party finder search conditions. + /// + /// The text that should be displayed for the link. + /// An SeString containing all the payloads necessary to display a link to the party finder search conditions. + public static SeString CreatePartyFinderSearchConditionsLink(string message) + { + var payloads = new List() + { + new PartyFinderPayload(), + // -> + new TextPayload(message), + }; + payloads.InsertRange(1, TextArrowPayloads); + payloads.Add(RawPayload.LinkTerminator); + + return new SeString(payloads); + } + /// /// Creates a SeString from a json. (For testing - not recommended for production use.) ///