fix user-created RawPayload to take entire chunk, testing helper for full item link string

This commit is contained in:
meli 2020-04-22 11:17:11 -07:00
parent 9f884f63f8
commit fb40a69785
7 changed files with 86 additions and 35 deletions

View file

@ -558,23 +558,11 @@ namespace Dalamud {
private void OnItemLinkCommand(string command, string arguments) {
this.itemSearchCommandWindow = new ItemSearchWindow(this.Data, new UiBuilder(this.InterfaceManager, "ItemSearcher"), false);
this.itemSearchCommandWindow.OnItemChosen += (sender, item) => {
var hexData = new byte[] {
0x02, 0x13, 0x06, 0xFE, 0xFF, 0xF3, 0xF3, 0xF3, 0x03, 0x02, 0x27, 0x07, 0x03, 0xF2, 0x3A, 0x2F,
0x02, 0x01, 0x03, 0x02, 0x13, 0x06, 0xFE, 0xFF, 0xFF, 0x7B, 0x1A, 0x03, 0xEE, 0x82, 0xBB, 0x02,
0x13, 0x02, 0xEC, 0x03
};
var endTag = new byte[] {
0x02, 0x27, 0x07, 0xCF, 0x01, 0x01, 0x01, 0xFF, 0x01, 0x03, 0x02, 0x13, 0x02, 0xEC, 0x03
};
BitConverter.GetBytes((short) item.RowId).Reverse().ToArray().CopyTo(hexData, 14);
hexData = hexData.Concat(Encoding.UTF8.GetBytes(item.Name)).Concat(endTag).ToArray();
this.Framework.Gui.Chat.PrintChat(new XivChatEntry {
MessageBytes = hexData
this.itemSearchCommandWindow.OnItemChosen += (sender, item) =>
{
this.Framework.Gui.Chat.PrintChat(new XivChatEntry
{
MessageBytes = SeStringUtils.CreateItemLink((uint)item.RowId, false).Encode()
});
};
this.isImguiDrawItemSearchWindow = true;

View file

@ -29,8 +29,10 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
public RawPayload(byte[] data)
{
this.chunkType = data[0];
this.data = data.Skip(1).ToArray();
// this payload is 'special' in that we require the entire chunk to be passed in
// and not just the data after the header
this.chunkType = data[1];
this.data = data.Skip(3).Take(data.Length-4).ToArray();
}
public override string ToString()

View file

@ -35,7 +35,14 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
protected override byte[] EncodeImpl()
{
return Encoding.UTF8.GetBytes(Text);
// special case to allow for empty text payloads, so users don't have to check
// this may change or go away
if (string.IsNullOrEmpty(this.text))
{
return new byte[] { };
}
return Encoding.UTF8.GetBytes(this.text);
}
protected override void DecodeImpl(BinaryReader reader, long endOfStream)

View file

@ -9,6 +9,8 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
{
public override PayloadType Type => PayloadType.UIForeground;
public bool IsEnabled => ColorKey != 0;
private UIColor color;
public UIColor UIColor
{

View file

@ -9,6 +9,8 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
{
public override PayloadType Type => PayloadType.UIGlow;
public bool IsEnabled => ColorKey != 0;
private UIColor color;
public UIColor UIColor
{

View file

@ -12,15 +12,10 @@ namespace Dalamud.Game.Chat.SeStringHandling
public class SeString
{
// TODO: probably change how this is done/where it comes from
public static Dalamud Dalamud { get; internal set; }
internal static Dalamud Dalamud { get; set; }
public List<Payload> Payloads { get; }
public SeString(List<Payload> payloads)
{
Payloads = payloads;
}
/// <summary>
/// Helper function to get all raw text from a message as a single joined string
/// </summary>
@ -39,10 +34,10 @@ namespace Dalamud.Game.Chat.SeStringHandling
}
/// <summary>
/// Parse an array of bytes to a SeString.
/// Parse a binary game message into an SeString.
/// </summary>
/// <param name="bytes"></param>
/// <returns></returns>
/// <param name="bytes">Binary message payload data in SE's internal format.</param>
/// <returns>An SeString containing parsed Payload objects for each payload in the data.</returns>
public static SeString Parse(byte[] bytes)
{
var payloads = new List<Payload>();
@ -61,12 +56,30 @@ namespace Dalamud.Game.Chat.SeStringHandling
return new SeString(payloads);
}
/// <summary>
/// Encode a parsed/created SeString to an array of bytes, to be used for injection.
/// </summary>
/// <param name="payloads"></param>
/// <returns>The bytes of the message.</returns>
public byte[] Encode()
public SeString(List<Payload> payloads)
{
Payloads = payloads;
}
public SeString Append(SeString other)
{
Payloads.AddRange(other.Payloads);
return this;
}
public SeString Append(List<Payload> payloads)
{
Payloads.AddRange(payloads);
return this;
}
public SeString Append(Payload payload)
{
Payloads.Add(payload);
return this;
}
internal byte[] Encode()
{
var messageBytes = new List<byte>();
foreach (var p in Payloads)

View file

@ -0,0 +1,37 @@
using Dalamud.Data.TransientSheet;
using Dalamud.Game.Chat.SeStringHandling.Payloads;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Dalamud.Game.Chat.SeStringHandling
{
public class SeStringUtils
{
public static SeString CreateItemLink(uint itemId, bool isHQ, string displayNameOverride = null)
{
string displayName = displayNameOverride ?? SeString.Dalamud.Data.GetExcelSheet<Item>().GetRow((int)itemId).Name;
if (isHQ)
{
displayName += " \uE03C";
}
var payloads = new List<Payload>(new Payload[]
{
new UIForegroundPayload(0x0225),
new UIGlowPayload(0x0226),
new ItemPayload(itemId, isHQ),
new UIForegroundPayload(0x01F4),
new UIGlowPayload(0x01F5),
new TextPayload("\uE0BB"),
new UIGlowPayload(0),
new UIForegroundPayload(0),
new TextPayload(displayName),
new RawPayload(new byte[] { 0x02, 0x27, 0x07, 0xCF, 0x01, 0x01, 0x01, 0xFF, 0x01, 0x03 })
});
return new SeString(payloads);
}
}
}