mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-21 15:27:43 +01:00
payload constructors for user-created payloads
This commit is contained in:
parent
5416c4bc7e
commit
2d5fdd3c4c
10 changed files with 119 additions and 26 deletions
|
|
@ -35,7 +35,7 @@ namespace Dalamud.Game.Chat.SeStringHandling
|
||||||
|
|
||||||
protected byte[] encodedData;
|
protected byte[] encodedData;
|
||||||
|
|
||||||
public Payload()
|
protected Payload()
|
||||||
{
|
{
|
||||||
// this is not a good way to do this, but I don't want to have to include a dalamud
|
// this is not a good way to do this, but I don't want to have to include a dalamud
|
||||||
// reference on multiple methods in every payload class
|
// reference on multiple methods in every payload class
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,16 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||||
private uint group;
|
private uint group;
|
||||||
private uint key;
|
private uint key;
|
||||||
|
|
||||||
|
internal AutoTranslatePayload() { }
|
||||||
|
|
||||||
|
public AutoTranslatePayload(uint group, uint key)
|
||||||
|
{
|
||||||
|
this.group = group;
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: friendlier ctor? not sure how to handle that given how weird the tables are
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{Type} - Group: {group}, Key: {key}";
|
return $"{Type} - Group: {group}, Key: {key}";
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,15 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||||
|
|
||||||
private uint itemId;
|
private uint itemId;
|
||||||
|
|
||||||
|
internal ItemPayload() { }
|
||||||
|
|
||||||
|
public ItemPayload(uint itemId, bool isHQ, string displayNameOverride = null)
|
||||||
|
{
|
||||||
|
this.itemId = itemId;
|
||||||
|
this.IsHQ = isHQ;
|
||||||
|
this.displayName = displayNameOverride;
|
||||||
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{Type} - ItemId: {itemId}, IsHQ: {IsHQ}";
|
return $"{Type} - ItemId: {itemId}, IsHQ: {IsHQ}";
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,18 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string CoordinateString
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// this truncates the values to one decimal without rounding, which is what the game does
|
||||||
|
var x = Math.Truncate(XCoord * 10.0f) / 10.0f;
|
||||||
|
var y = Math.Truncate(YCoord * 10.0f) / 10.0f;
|
||||||
|
|
||||||
|
return $"( {x.ToString("0.0")}, {y.ToString("0.0")} )";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private string placeNameRegion;
|
private string placeNameRegion;
|
||||||
public string PlaceNameRegion
|
public string PlaceNameRegion
|
||||||
{
|
{
|
||||||
|
|
@ -66,14 +78,32 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string DataString => $"m:{TerritoryType.RowId},{Map.RowId},{unchecked((int)rawX)},{unchecked((int)rawY)}";
|
public string DataString => $"m:{TerritoryType.RowId},{Map.RowId},{rawX},{rawY}";
|
||||||
|
|
||||||
private uint territoryTypeId;
|
private uint territoryTypeId;
|
||||||
private uint mapId;
|
private uint mapId;
|
||||||
private uint rawX;
|
private int rawX;
|
||||||
private uint rawY;
|
private int rawY;
|
||||||
// there is no Z; it's purely in the text payload where applicable
|
// there is no Z; it's purely in the text payload where applicable
|
||||||
|
|
||||||
|
internal MapLinkPayload() { }
|
||||||
|
|
||||||
|
public MapLinkPayload(uint territoryTypeId, uint mapId, float niceXCoord, float niceYCoord)
|
||||||
|
{
|
||||||
|
this.territoryTypeId = territoryTypeId;
|
||||||
|
this.mapId = mapId;
|
||||||
|
this.rawX = this.ConvertMapCoordinateToRawPosition(niceXCoord, Map.SizeFactor);
|
||||||
|
this.rawY = this.ConvertMapCoordinateToRawPosition(niceYCoord, Map.SizeFactor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MapLinkPayload(uint territoryTypeId, uint mapId, int rawX, int rawY)
|
||||||
|
{
|
||||||
|
this.territoryTypeId = territoryTypeId;
|
||||||
|
this.mapId = mapId;
|
||||||
|
this.rawX = rawX;
|
||||||
|
this.rawY = rawY;
|
||||||
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{Type} - TerritoryTypeId: {territoryTypeId}, MapId: {mapId}, RawX: {rawX}, RawY: {rawY}";
|
return $"{Type} - TerritoryTypeId: {territoryTypeId}, MapId: {mapId}, RawX: {rawX}, RawY: {rawY}";
|
||||||
|
|
@ -81,12 +111,9 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||||
|
|
||||||
protected override byte[] EncodeImpl()
|
protected override byte[] EncodeImpl()
|
||||||
{
|
{
|
||||||
// TODO: for now we just encode the raw/internal values
|
|
||||||
// eventually we should allow creation using 'nice' values that then encode properly
|
|
||||||
|
|
||||||
var packedTerritoryAndMapBytes = MakePackedInteger(this.territoryTypeId, this.mapId);
|
var packedTerritoryAndMapBytes = MakePackedInteger(this.territoryTypeId, this.mapId);
|
||||||
var xBytes = MakeInteger(this.rawX);
|
var xBytes = MakeInteger(unchecked((uint)this.rawX));
|
||||||
var yBytes = MakeInteger(this.rawY);
|
var yBytes = MakeInteger(unchecked((uint)this.rawY));
|
||||||
|
|
||||||
var chunkLen = 4 + packedTerritoryAndMapBytes.Length + xBytes.Length + yBytes.Length;
|
var chunkLen = 4 + packedTerritoryAndMapBytes.Length + xBytes.Length + yBytes.Length;
|
||||||
|
|
||||||
|
|
@ -116,8 +143,8 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
(this.territoryTypeId, this.mapId) = GetPackedIntegers(reader);
|
(this.territoryTypeId, this.mapId) = GetPackedIntegers(reader);
|
||||||
this.rawX = (uint)GetInteger(reader);
|
this.rawX = unchecked((int)GetInteger(reader));
|
||||||
this.rawY = (uint)GetInteger(reader);
|
this.rawY = unchecked((int)GetInteger(reader));
|
||||||
// the Z coordinate is never in this chunk, just the text (if applicable)
|
// the Z coordinate is never in this chunk, just the text (if applicable)
|
||||||
|
|
||||||
// seems to always be FF 01
|
// seems to always be FF 01
|
||||||
|
|
@ -134,16 +161,16 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||||
#region ugliness
|
#region ugliness
|
||||||
// from https://github.com/xivapi/ffxiv-datamining/blob/master/docs/MapCoordinates.md
|
// from https://github.com/xivapi/ffxiv-datamining/blob/master/docs/MapCoordinates.md
|
||||||
// extra 1/1000 because that is how the network ints are done
|
// extra 1/1000 because that is how the network ints are done
|
||||||
private float ConvertRawPositionToMapCoordinate(uint pos, float scale)
|
private float ConvertRawPositionToMapCoordinate(int pos, float scale)
|
||||||
{
|
{
|
||||||
var c = scale / 100.0f;
|
var c = scale / 100.0f;
|
||||||
var scaledPos = (int)pos * c / 1000.0f;
|
var scaledPos = pos * c / 1000.0f;
|
||||||
|
|
||||||
return ((41.0f / c) * ((scaledPos + 1024.0f) / 2048.0f)) + 1.0f;
|
return ((41.0f / c) * ((scaledPos + 1024.0f) / 2048.0f)) + 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Created as the inverse of ConvertRawPositionToMapCoordinate(), since no one seemed to have a version of that
|
// Created as the inverse of ConvertRawPositionToMapCoordinate(), since no one seemed to have a version of that
|
||||||
private float ConvertMapCoordinateToRawPosition(float pos, float scale)
|
private int ConvertMapCoordinateToRawPosition(float pos, float scale)
|
||||||
{
|
{
|
||||||
var c = scale / 100.0f;
|
var c = scale / 100.0f;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,14 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||||
|
|
||||||
private uint serverId;
|
private uint serverId;
|
||||||
|
|
||||||
|
internal PlayerPayload() { }
|
||||||
|
|
||||||
|
public PlayerPayload(string playerName, uint serverId)
|
||||||
|
{
|
||||||
|
this.playerName = playerName;
|
||||||
|
this.serverId = serverId;
|
||||||
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{Type} - PlayerName: {PlayerName}, ServerId: {serverId}";
|
return $"{Type} - PlayerName: {PlayerName}, ServerId: {serverId}";
|
||||||
|
|
@ -58,12 +66,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||||
|
|
||||||
// encoded names are followed by the name in plain text again
|
// encoded names are followed by the name in plain text again
|
||||||
// use the payload parsing for consistency, as this is technically a new chunk
|
// use the payload parsing for consistency, as this is technically a new chunk
|
||||||
bytes.AddRange(
|
bytes.AddRange(new TextPayload(playerName).Encode());
|
||||||
new TextPayload()
|
|
||||||
{
|
|
||||||
Text = playerName
|
|
||||||
}.Encode()
|
|
||||||
);
|
|
||||||
|
|
||||||
// unsure about this entire packet, but it seems to always follow a name
|
// unsure about this entire packet, but it seems to always follow a name
|
||||||
bytes.AddRange(new byte[]
|
bytes.AddRange(new byte[]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||||
{
|
{
|
||||||
|
|
@ -8,23 +9,38 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||||
{
|
{
|
||||||
public override PayloadType Type => PayloadType.Unknown;
|
public override PayloadType Type => PayloadType.Unknown;
|
||||||
|
|
||||||
public byte[] Data { get; private set; }
|
private byte[] data;
|
||||||
|
public byte[] Data
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// for now don't allow modifying the contents
|
||||||
|
// because we don't really have a way to track Dirty
|
||||||
|
return (byte[])data.Clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private byte chunkType;
|
private byte chunkType;
|
||||||
|
|
||||||
public RawPayload(byte chunkType)
|
internal RawPayload(byte chunkType)
|
||||||
{
|
{
|
||||||
this.chunkType = chunkType;
|
this.chunkType = chunkType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RawPayload(byte[] data)
|
||||||
|
{
|
||||||
|
this.chunkType = data[0];
|
||||||
|
this.data = data.Skip(1).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{Type} - Chunk type: {chunkType:X}, Data: {BitConverter.ToString(Data).Replace("-", " ")}";
|
return $"{Type} - Chunk type: {chunkType:X}, Data: {BitConverter.ToString(data).Replace("-", " ")}";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override byte[] EncodeImpl()
|
protected override byte[] EncodeImpl()
|
||||||
{
|
{
|
||||||
var chunkLen = Data.Length + 1;
|
var chunkLen = this.data.Length + 1;
|
||||||
|
|
||||||
var bytes = new List<byte>()
|
var bytes = new List<byte>()
|
||||||
{
|
{
|
||||||
|
|
@ -32,7 +48,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||||
this.chunkType,
|
this.chunkType,
|
||||||
(byte)chunkLen
|
(byte)chunkLen
|
||||||
};
|
};
|
||||||
bytes.AddRange(Data);
|
bytes.AddRange(this.data);
|
||||||
|
|
||||||
bytes.Add(END_BYTE);
|
bytes.Add(END_BYTE);
|
||||||
|
|
||||||
|
|
@ -41,7 +57,7 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||||
|
|
||||||
protected override void DecodeImpl(BinaryReader reader, long endOfStream)
|
protected override void DecodeImpl(BinaryReader reader, long endOfStream)
|
||||||
{
|
{
|
||||||
Data = reader.ReadBytes((int)(endOfStream - reader.BaseStream.Position + 1));
|
this.data = reader.ReadBytes((int)(endOfStream - reader.BaseStream.Position + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,13 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||||
|
|
||||||
private uint statusId;
|
private uint statusId;
|
||||||
|
|
||||||
|
internal StatusPayload() { }
|
||||||
|
|
||||||
|
public StatusPayload(uint statusId)
|
||||||
|
{
|
||||||
|
this.statusId = statusId;
|
||||||
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{Type} - StatusId: {statusId}";
|
return $"{Type} - StatusId: {statusId}";
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,13 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||||
return $"{Type} - Text: {Text}";
|
return $"{Type} - Text: {Text}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal TextPayload() { }
|
||||||
|
|
||||||
|
public TextPayload(string text)
|
||||||
|
{
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
protected override byte[] EncodeImpl()
|
protected override byte[] EncodeImpl()
|
||||||
{
|
{
|
||||||
return Encoding.UTF8.GetBytes(Text);
|
return Encoding.UTF8.GetBytes(Text);
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,13 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||||
|
|
||||||
private ushort colorKey;
|
private ushort colorKey;
|
||||||
|
|
||||||
|
internal UIForegroundPayload() { }
|
||||||
|
|
||||||
|
public UIForegroundPayload(ushort colorKey)
|
||||||
|
{
|
||||||
|
this.colorKey = colorKey;
|
||||||
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{Type} - UIColor: {colorKey}";
|
return $"{Type} - UIColor: {colorKey}";
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,13 @@ namespace Dalamud.Game.Chat.SeStringHandling.Payloads
|
||||||
|
|
||||||
private ushort colorKey;
|
private ushort colorKey;
|
||||||
|
|
||||||
|
internal UIGlowPayload() { }
|
||||||
|
|
||||||
|
public UIGlowPayload(ushort colorKey)
|
||||||
|
{
|
||||||
|
this.colorKey = colorKey;
|
||||||
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{Type} - UIColor: {colorKey}";
|
return $"{Type} - UIColor: {colorKey}";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue