mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
improve payload parsing of item links
This commit is contained in:
parent
28e348d5f0
commit
766b777f74
1 changed files with 37 additions and 8 deletions
|
|
@ -14,29 +14,42 @@ namespace Dalamud.Game.Chat {
|
||||||
PlayerLink = 0x27
|
PlayerLink = 0x27
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// in all likelihood these are flags of some kind, but these are the only 2 values I've noticed
|
||||||
|
public enum ItemQuality {
|
||||||
|
NormalQuality = 0xF2,
|
||||||
|
HighQuality = 0xF6
|
||||||
|
}
|
||||||
|
|
||||||
private const int START_BYTE = 0x02;
|
private const int START_BYTE = 0x02;
|
||||||
private const int END_BYTE = 0x03;
|
private const int END_BYTE = 0x03;
|
||||||
|
|
||||||
public static (string Output, List<SeStringPayloadContainer> Payloads) Parse(string input) {
|
public static (string Output, List<SeStringPayloadContainer> Payloads) Parse(byte[] bytes)
|
||||||
|
{
|
||||||
var output = new List<byte>();
|
var output = new List<byte>();
|
||||||
var payloads = new List<SeStringPayloadContainer>();
|
var payloads = new List<SeStringPayloadContainer>();
|
||||||
|
|
||||||
var bytes = Encoding.UTF8.GetBytes(input);
|
|
||||||
using (var stream = new MemoryStream(bytes))
|
using (var stream = new MemoryStream(bytes))
|
||||||
using (var reader = new BinaryReader(stream)) {
|
using (var reader = new BinaryReader(stream))
|
||||||
while (stream.Position < bytes.Length) {
|
{
|
||||||
|
while (stream.Position < bytes.Length)
|
||||||
|
{
|
||||||
var b = stream.ReadByte();
|
var b = stream.ReadByte();
|
||||||
|
|
||||||
if (b == START_BYTE)
|
if (b == START_BYTE)
|
||||||
ProcessPacket(reader, output, payloads);
|
ProcessPacket(reader, output, payloads);
|
||||||
else
|
else
|
||||||
output.Add((byte) b);
|
output.Add((byte)b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (Encoding.UTF8.GetString(output.ToArray()), payloads);
|
return (Encoding.UTF8.GetString(output.ToArray()), payloads);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static (string Output, List<SeStringPayloadContainer> Payloads) Parse(string input) {
|
||||||
|
var bytes = Encoding.UTF8.GetBytes(input);
|
||||||
|
return Parse(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
private static void ProcessPacket(BinaryReader reader, List<byte> output,
|
private static void ProcessPacket(BinaryReader reader, List<byte> output,
|
||||||
List<SeStringPayloadContainer> payloads) {
|
List<SeStringPayloadContainer> payloads) {
|
||||||
var type = reader.ReadByte();
|
var type = reader.ReadByte();
|
||||||
|
|
@ -54,11 +67,27 @@ namespace Dalamud.Game.Chat {
|
||||||
|
|
||||||
switch ((SeStringPayloadType) type) {
|
switch ((SeStringPayloadType) type) {
|
||||||
case SeStringPayloadType.PlayerLink:
|
case SeStringPayloadType.PlayerLink:
|
||||||
if (payload[0] == (byte) PlayerLinkType.ItemLink)
|
if (payload[0] == (byte)PlayerLinkType.ItemLink)
|
||||||
payloads.Add(new SeStringPayloadContainer {
|
{
|
||||||
|
int itemId;
|
||||||
|
if ((ItemQuality)payload[1] == ItemQuality.HighQuality)
|
||||||
|
{
|
||||||
|
// hq items have an extra 0x0F byte before the ID, and the ID is 0x4240 above the actual item ID
|
||||||
|
// This _seems_ consistent but I really don't know
|
||||||
|
itemId = (payload[3] << 8 | payload[4]) - 0x4240;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
itemId = (payload[2] << 8 | payload[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
payloads.Add(new SeStringPayloadContainer
|
||||||
|
{
|
||||||
Type = SeStringPayloadType.PlayerLink,
|
Type = SeStringPayloadType.PlayerLink,
|
||||||
Param1 = BitConverter.ToInt16(payload, 4)
|
Param1 = itemId
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue