mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-31 21:03:43 +01:00
Revert "refactor(Dalamud): switch to file-scoped namespaces"
This reverts commit b5f34c3199.
This commit is contained in:
parent
d473826247
commit
1561fbac00
325 changed files with 45549 additions and 45209 deletions
|
|
@ -5,115 +5,116 @@ using System.Linq;
|
|||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Dalamud.Game.Text.SeStringHandling.Payloads;
|
||||
|
||||
/// <summary>
|
||||
/// An SeString Payload representing unhandled raw payload data.
|
||||
/// Mainly useful for constructing unhandled hardcoded payloads, or forwarding any unknown
|
||||
/// payloads without modification.
|
||||
/// </summary>
|
||||
public class RawPayload : Payload
|
||||
namespace Dalamud.Game.Text.SeStringHandling.Payloads
|
||||
{
|
||||
[JsonProperty]
|
||||
private byte chunkType;
|
||||
|
||||
[JsonProperty]
|
||||
private byte[] data;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RawPayload"/> class.
|
||||
/// An SeString Payload representing unhandled raw payload data.
|
||||
/// Mainly useful for constructing unhandled hardcoded payloads, or forwarding any unknown
|
||||
/// payloads without modification.
|
||||
/// </summary>
|
||||
/// <param name="data">The payload data.</param>
|
||||
public RawPayload(byte[] data)
|
||||
public class RawPayload : Payload
|
||||
{
|
||||
// this payload is 'special' in that we require the entire chunk to be passed in
|
||||
// and not just the data after the header
|
||||
// This sets data to hold the chunk data fter the header, excluding the END_BYTE
|
||||
this.chunkType = data[1];
|
||||
this.data = data.Skip(3).Take(data.Length - 4).ToArray();
|
||||
}
|
||||
[JsonProperty]
|
||||
private byte chunkType;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RawPayload"/> class.
|
||||
/// </summary>
|
||||
/// <param name="chunkType">The chunk type.</param>
|
||||
[JsonConstructor]
|
||||
internal RawPayload(byte chunkType)
|
||||
{
|
||||
this.chunkType = chunkType;
|
||||
}
|
||||
[JsonProperty]
|
||||
private byte[] data;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a fixed Payload representing a common link-termination sequence, found in many payload chains.
|
||||
/// </summary>
|
||||
public static RawPayload LinkTerminator => new(new byte[] { 0x02, 0x27, 0x07, 0xCF, 0x01, 0x01, 0x01, 0xFF, 0x01, 0x03 });
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override PayloadType Type => PayloadType.Unknown;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the entire payload byte sequence for this payload.
|
||||
/// The returned data is a clone and modifications will not be persisted.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public byte[] Data
|
||||
{
|
||||
// this is a bit different from the underlying data
|
||||
// We need to store just the chunk data for decode to behave nicely, but when reading data out
|
||||
// it makes more sense to get the entire payload
|
||||
get
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RawPayload"/> class.
|
||||
/// </summary>
|
||||
/// <param name="data">The payload data.</param>
|
||||
public RawPayload(byte[] data)
|
||||
{
|
||||
// for now don't allow modifying the contents
|
||||
// because we don't really have a way to track Dirty
|
||||
return (byte[])this.Encode().Clone();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is RawPayload rp)
|
||||
{
|
||||
if (rp.Data.Length != this.Data.Length) return false;
|
||||
return !this.Data.Where((t, i) => rp.Data[i] != t).Any();
|
||||
// this payload is 'special' in that we require the entire chunk to be passed in
|
||||
// and not just the data after the header
|
||||
// This sets data to hold the chunk data fter the header, excluding the END_BYTE
|
||||
this.chunkType = data[1];
|
||||
this.data = data.Skip(3).Take(data.Length - 4).ToArray();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RawPayload"/> class.
|
||||
/// </summary>
|
||||
/// <param name="chunkType">The chunk type.</param>
|
||||
[JsonConstructor]
|
||||
internal RawPayload(byte chunkType)
|
||||
{
|
||||
this.chunkType = chunkType;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(this.Type, this.chunkType, this.data);
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets a fixed Payload representing a common link-termination sequence, found in many payload chains.
|
||||
/// </summary>
|
||||
public static RawPayload LinkTerminator => new(new byte[] { 0x02, 0x27, 0x07, 0xCF, 0x01, 0x01, 0x01, 0xFF, 0x01, 0x03 });
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{this.Type} - Data: {BitConverter.ToString(this.Data).Replace("-", " ")}";
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
public override PayloadType Type => PayloadType.Unknown;
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override byte[] EncodeImpl()
|
||||
{
|
||||
var chunkLen = this.data.Length + 1;
|
||||
/// <summary>
|
||||
/// Gets the entire payload byte sequence for this payload.
|
||||
/// The returned data is a clone and modifications will not be persisted.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public byte[] Data
|
||||
{
|
||||
// this is a bit different from the underlying data
|
||||
// We need to store just the chunk data for decode to behave nicely, but when reading data out
|
||||
// it makes more sense to get the entire payload
|
||||
get
|
||||
{
|
||||
// for now don't allow modifying the contents
|
||||
// because we don't really have a way to track Dirty
|
||||
return (byte[])this.Encode().Clone();
|
||||
}
|
||||
}
|
||||
|
||||
var bytes = new List<byte>()
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is RawPayload rp)
|
||||
{
|
||||
if (rp.Data.Length != this.Data.Length) return false;
|
||||
return !this.Data.Where((t, i) => rp.Data[i] != t).Any();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(this.Type, this.chunkType, this.data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{this.Type} - Data: {BitConverter.ToString(this.Data).Replace("-", " ")}";
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override byte[] EncodeImpl()
|
||||
{
|
||||
var chunkLen = this.data.Length + 1;
|
||||
|
||||
var bytes = new List<byte>()
|
||||
{
|
||||
START_BYTE,
|
||||
this.chunkType,
|
||||
(byte)chunkLen,
|
||||
};
|
||||
bytes.AddRange(this.data);
|
||||
bytes.AddRange(this.data);
|
||||
|
||||
bytes.Add(END_BYTE);
|
||||
bytes.Add(END_BYTE);
|
||||
|
||||
return bytes.ToArray();
|
||||
}
|
||||
return bytes.ToArray();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void DecodeImpl(BinaryReader reader, long endOfStream)
|
||||
{
|
||||
this.data = reader.ReadBytes((int)(endOfStream - reader.BaseStream.Position + 1));
|
||||
/// <inheritdoc/>
|
||||
protected override void DecodeImpl(BinaryReader reader, long endOfStream)
|
||||
{
|
||||
this.data = reader.ReadBytes((int)(endOfStream - reader.BaseStream.Position + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue