mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-17 22:24:16 +01:00
fix user-created RawPayload to take entire chunk, testing helper for full item link string
This commit is contained in:
parent
9f884f63f8
commit
fb40a69785
7 changed files with 86 additions and 35 deletions
|
|
@ -558,23 +558,11 @@ namespace Dalamud {
|
||||||
|
|
||||||
private void OnItemLinkCommand(string command, string arguments) {
|
private void OnItemLinkCommand(string command, string arguments) {
|
||||||
this.itemSearchCommandWindow = new ItemSearchWindow(this.Data, new UiBuilder(this.InterfaceManager, "ItemSearcher"), false);
|
this.itemSearchCommandWindow = new ItemSearchWindow(this.Data, new UiBuilder(this.InterfaceManager, "ItemSearcher"), false);
|
||||||
this.itemSearchCommandWindow.OnItemChosen += (sender, item) => {
|
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,
|
this.Framework.Gui.Chat.PrintChat(new XivChatEntry
|
||||||
0x02, 0x01, 0x03, 0x02, 0x13, 0x06, 0xFE, 0xFF, 0xFF, 0x7B, 0x1A, 0x03, 0xEE, 0x82, 0xBB, 0x02,
|
{
|
||||||
0x13, 0x02, 0xEC, 0x03
|
MessageBytes = SeStringUtils.CreateItemLink((uint)item.RowId, false).Encode()
|
||||||
};
|
|
||||||
|
|
||||||
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.isImguiDrawItemSearchWindow = true;
|
this.isImguiDrawItemSearchWindow = true;
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,10 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||||
|
|
||||||
public RawPayload(byte[] data)
|
public RawPayload(byte[] data)
|
||||||
{
|
{
|
||||||
this.chunkType = data[0];
|
// this payload is 'special' in that we require the entire chunk to be passed in
|
||||||
this.data = data.Skip(1).ToArray();
|
// 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()
|
public override string ToString()
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,14 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||||
|
|
||||||
protected override byte[] EncodeImpl()
|
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)
|
protected override void DecodeImpl(BinaryReader reader, long endOfStream)
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||||
{
|
{
|
||||||
public override PayloadType Type => PayloadType.UIForeground;
|
public override PayloadType Type => PayloadType.UIForeground;
|
||||||
|
|
||||||
|
public bool IsEnabled => ColorKey != 0;
|
||||||
|
|
||||||
private UIColor color;
|
private UIColor color;
|
||||||
public UIColor UIColor
|
public UIColor UIColor
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||||
{
|
{
|
||||||
public override PayloadType Type => PayloadType.UIGlow;
|
public override PayloadType Type => PayloadType.UIGlow;
|
||||||
|
|
||||||
|
public bool IsEnabled => ColorKey != 0;
|
||||||
|
|
||||||
private UIColor color;
|
private UIColor color;
|
||||||
public UIColor UIColor
|
public UIColor UIColor
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -12,15 +12,10 @@ namespace Dalamud.Game.Chat.SeStringHandling
|
||||||
public class SeString
|
public class SeString
|
||||||
{
|
{
|
||||||
// TODO: probably change how this is done/where it comes from
|
// 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 List<Payload> Payloads { get; }
|
||||||
|
|
||||||
public SeString(List<Payload> payloads)
|
|
||||||
{
|
|
||||||
Payloads = payloads;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Helper function to get all raw text from a message as a single joined string
|
/// Helper function to get all raw text from a message as a single joined string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -39,10 +34,10 @@ namespace Dalamud.Game.Chat.SeStringHandling
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parse an array of bytes to a SeString.
|
/// Parse a binary game message into an SeString.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="bytes"></param>
|
/// <param name="bytes">Binary message payload data in SE's internal format.</param>
|
||||||
/// <returns></returns>
|
/// <returns>An SeString containing parsed Payload objects for each payload in the data.</returns>
|
||||||
public static SeString Parse(byte[] bytes)
|
public static SeString Parse(byte[] bytes)
|
||||||
{
|
{
|
||||||
var payloads = new List<Payload>();
|
var payloads = new List<Payload>();
|
||||||
|
|
@ -61,12 +56,30 @@ namespace Dalamud.Game.Chat.SeStringHandling
|
||||||
return new SeString(payloads);
|
return new SeString(payloads);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public SeString(List<Payload> payloads)
|
||||||
/// Encode a parsed/created SeString to an array of bytes, to be used for injection.
|
{
|
||||||
/// </summary>
|
Payloads = payloads;
|
||||||
/// <param name="payloads"></param>
|
}
|
||||||
/// <returns>The bytes of the message.</returns>
|
|
||||||
public byte[] Encode()
|
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>();
|
var messageBytes = new List<byte>();
|
||||||
foreach (var p in Payloads)
|
foreach (var p in Payloads)
|
||||||
|
|
|
||||||
37
Dalamud/Game/Chat/SeStringHandling/SeStringUtils.cs
Normal file
37
Dalamud/Game/Chat/SeStringHandling/SeStringUtils.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue