mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
Switch PlayerPayload Encode/Decode to using Lumina (#2107)
* Switch PlayerPayload Encode/Decode to using Lumina - This also fixes a bug that PlayerPayload would encode worldIds as byte (they are ushort) * Remove comment
This commit is contained in:
parent
d538ce6350
commit
2f50276738
1 changed files with 22 additions and 37 deletions
|
|
@ -6,6 +6,9 @@ using Dalamud.Data;
|
||||||
|
|
||||||
using Lumina.Excel;
|
using Lumina.Excel;
|
||||||
using Lumina.Excel.Sheets;
|
using Lumina.Excel.Sheets;
|
||||||
|
using Lumina.Text.Payloads;
|
||||||
|
using Lumina.Text.ReadOnly;
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Dalamud.Game.Text.SeStringHandling.Payloads;
|
namespace Dalamud.Game.Text.SeStringHandling.Payloads;
|
||||||
|
|
@ -84,50 +87,32 @@ public class PlayerPayload : Payload
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
protected override byte[] EncodeImpl()
|
protected override byte[] EncodeImpl()
|
||||||
{
|
{
|
||||||
var chunkLen = this.playerName.Length + 7;
|
var ssb = Lumina.Text.SeStringBuilder.SharedPool.Get();
|
||||||
var bytes = new List<byte>()
|
var res = ssb
|
||||||
{
|
.PushLinkCharacter(this.playerName, this.serverId)
|
||||||
START_BYTE,
|
.Append(this.playerName)
|
||||||
(byte)SeStringChunkType.Interactable, (byte)chunkLen, (byte)EmbeddedInfoType.PlayerName,
|
.PopLink()
|
||||||
/* unk */ 0x01,
|
.ToArray();
|
||||||
(byte)(this.serverId + 1), // I didn't want to deal with single-byte values in MakeInteger, so we have to do the +1 manually
|
Lumina.Text.SeStringBuilder.SharedPool.Return(ssb);
|
||||||
/* unk */ 0x01,
|
return res;
|
||||||
/* unk */ 0xFF, // these sometimes vary but are frequently this
|
|
||||||
(byte)(this.playerName.Length + 1),
|
|
||||||
};
|
|
||||||
|
|
||||||
bytes.AddRange(Encoding.UTF8.GetBytes(this.playerName));
|
|
||||||
bytes.Add(END_BYTE);
|
|
||||||
|
|
||||||
// TODO: should these really be here? additional payloads should come in separately already...
|
|
||||||
|
|
||||||
// encoded names are followed by the name in plain text again
|
|
||||||
// use the payload parsing for consistency, as this is technically a new chunk
|
|
||||||
bytes.AddRange(new TextPayload(this.playerName).Encode());
|
|
||||||
|
|
||||||
// unsure about this entire packet, but it seems to always follow a name
|
|
||||||
bytes.AddRange(new byte[]
|
|
||||||
{
|
|
||||||
START_BYTE, (byte)SeStringChunkType.Interactable, 0x07, (byte)EmbeddedInfoType.LinkTerminator,
|
|
||||||
0x01, 0x01, 0x01, 0xFF, 0x01,
|
|
||||||
END_BYTE,
|
|
||||||
});
|
|
||||||
|
|
||||||
return bytes.ToArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
protected override void DecodeImpl(BinaryReader reader, long endOfStream)
|
protected override void DecodeImpl(BinaryReader reader, long endOfStream)
|
||||||
{
|
{
|
||||||
// unk
|
var body = reader.ReadBytes((int)(endOfStream - reader.BaseStream.Position));
|
||||||
reader.ReadByte();
|
var rosps = new ReadOnlySePayloadSpan(ReadOnlySePayloadType.Macro, MacroCode.Link, body.AsSpan());
|
||||||
|
|
||||||
this.serverId = GetInteger(reader);
|
if (!rosps.TryGetExpression(out _, out var worldIdExpression, out _, out var characterNameExpression))
|
||||||
|
return;
|
||||||
|
|
||||||
// unk
|
if (!worldIdExpression.TryGetUInt(out var worldId))
|
||||||
reader.ReadBytes(2);
|
return;
|
||||||
|
|
||||||
var nameLen = (int)GetInteger(reader);
|
if (!characterNameExpression.TryGetString(out var characterName))
|
||||||
this.playerName = Encoding.UTF8.GetString(reader.ReadBytes(nameLen));
|
return;
|
||||||
|
|
||||||
|
this.serverId = worldId;
|
||||||
|
this.playerName = characterName.ExtractText();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue