refactor(common): fix some code warnings

This commit is contained in:
Anna 2020-10-31 21:27:24 -04:00
parent fa97137517
commit 0ba0344b68
6 changed files with 219 additions and 258 deletions

View File

@ -1,9 +1,6 @@
using Sodium; using Sodium;
using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace XIVChatCommon { namespace XIVChatCommon {
@ -90,8 +87,8 @@ namespace XIVChatCommon {
} }
public class HandshakeInfo { public class HandshakeInfo {
public byte[] RemotePublicKey { get; private set; } public byte[] RemotePublicKey { get; }
public SessionKeys Keys { get; private set; } public SessionKeys Keys { get; }
internal HandshakeInfo(byte[] remote, SessionKeys keys) { internal HandshakeInfo(byte[] remote, SessionKeys keys) {
this.RemotePublicKey = remote; this.RemotePublicKey = remote;

View File

@ -9,17 +9,22 @@ namespace XIVChatCommon {
[MessagePackFormatter(typeof(MillisecondsDateTimeFormatter))] [MessagePackFormatter(typeof(MillisecondsDateTimeFormatter))]
[Key(0)] [Key(0)]
public DateTime Timestamp { get; set; } public DateTime Timestamp { get; set; }
[Key(1)] [Key(1)]
public ChatType Channel { get; set; } public ChatType Channel { get; set; }
[Key(2)] [Key(2)]
public byte[] Sender { get; set; } public byte[] Sender { get; set; }
[Key(3)] [Key(3)]
public byte[] Content { get; set; } public byte[] Content { get; set; }
[Key(4)] [Key(4)]
public List<Chunk> Chunks { get; set; } public List<Chunk> Chunks { get; set; }
[IgnoreMember] [IgnoreMember]
public string ContentText => XivString.GetText(this.Content); public string ContentText => XivString.GetText(this.Content);
[IgnoreMember] [IgnoreMember]
public string SenderText => XivString.GetText(this.Sender); public string SenderText => XivString.GetText(this.Sender);
@ -45,20 +50,23 @@ namespace XIVChatCommon {
public class TextChunk : Chunk { public class TextChunk : Chunk {
[Key(0)] [Key(0)]
public uint? FallbackColour { get; set; } public uint? FallbackColour { get; set; }
[Key(1)] [Key(1)]
public uint? Foreground { get; set; } public uint? Foreground { get; set; }
[Key(2)] [Key(2)]
public uint? Glow { get; set; } public uint? Glow { get; set; }
[Key(3)] [Key(3)]
public bool Italic { get; set; } public bool Italic { get; set; }
[Key(4)] [Key(4)]
public string Content { get; set; } public string Content { get; set; }
} }
[MessagePackObject] [MessagePackObject]
public class IconChunk : Chunk { public class IconChunk : Chunk {
[Key(0)] [Key(0)] public byte Index;
public byte Index;
} }
public class NameFormatting { public class NameFormatting {
@ -101,89 +109,62 @@ namespace XIVChatCommon {
this.code = code; this.code = code;
} }
public ChatType Parent() { public ChatType Parent() => this.Type switch {
switch (this.Type) { ChatType.Say => ChatType.Say,
case ChatType.Say: ChatType.GmSay => ChatType.Say,
case ChatType.GmSay: ChatType.Shout => ChatType.Shout,
return ChatType.Say; ChatType.GmShout => ChatType.Shout,
case ChatType.Shout: ChatType.TellOutgoing => ChatType.TellOutgoing,
case ChatType.GmShout: ChatType.TellIncoming => ChatType.TellOutgoing,
return ChatType.Shout; ChatType.GmTell => ChatType.TellOutgoing,
case ChatType.TellOutgoing: ChatType.Party => ChatType.Party,
case ChatType.TellIncoming: ChatType.CrossParty => ChatType.Party,
case ChatType.GmTell: ChatType.GmParty => ChatType.Party,
return ChatType.TellOutgoing; ChatType.Linkshell1 => ChatType.Linkshell1,
case ChatType.Party: ChatType.GmLinkshell1 => ChatType.Linkshell1,
case ChatType.CrossParty: ChatType.Linkshell2 => ChatType.Linkshell2,
case ChatType.GmParty: ChatType.GmLinkshell2 => ChatType.Linkshell2,
return ChatType.Party; ChatType.Linkshell3 => ChatType.Linkshell3,
case ChatType.Linkshell1: ChatType.GmLinkshell3 => ChatType.Linkshell3,
case ChatType.GmLinkshell1: ChatType.Linkshell4 => ChatType.Linkshell4,
return ChatType.Linkshell1; ChatType.GmLinkshell4 => ChatType.Linkshell4,
case ChatType.Linkshell2: ChatType.Linkshell5 => ChatType.Linkshell5,
case ChatType.GmLinkshell2: ChatType.GmLinkshell5 => ChatType.Linkshell5,
return ChatType.Linkshell2; ChatType.Linkshell6 => ChatType.Linkshell6,
case ChatType.Linkshell3: ChatType.GmLinkshell6 => ChatType.Linkshell6,
case ChatType.GmLinkshell3: ChatType.Linkshell7 => ChatType.Linkshell7,
return ChatType.Linkshell3; ChatType.GmLinkshell7 => ChatType.Linkshell7,
case ChatType.Linkshell4: ChatType.Linkshell8 => ChatType.Linkshell8,
case ChatType.GmLinkshell4: ChatType.GmLinkshell8 => ChatType.Linkshell8,
return ChatType.Linkshell4; ChatType.FreeCompany => ChatType.FreeCompany,
case ChatType.Linkshell5: ChatType.GmFreeCompany => ChatType.FreeCompany,
case ChatType.GmLinkshell5: ChatType.NoviceNetwork => ChatType.NoviceNetwork,
return ChatType.Linkshell5; ChatType.GmNoviceNetwork => ChatType.NoviceNetwork,
case ChatType.Linkshell6: ChatType.CustomEmote => ChatType.CustomEmote,
case ChatType.GmLinkshell6: ChatType.StandardEmote => ChatType.StandardEmote,
return ChatType.Linkshell6; ChatType.Yell => ChatType.Yell,
case ChatType.Linkshell7: ChatType.GmYell => ChatType.Yell,
case ChatType.GmLinkshell7: ChatType.GainBuff => ChatType.GainBuff,
return ChatType.Linkshell7; ChatType.LoseBuff => ChatType.GainBuff,
case ChatType.Linkshell8: ChatType.GainDebuff => ChatType.GainDebuff,
case ChatType.GmLinkshell8: ChatType.LoseDebuff => ChatType.GainDebuff,
return ChatType.Linkshell8; ChatType.System => ChatType.System,
case ChatType.FreeCompany: ChatType.Alarm => ChatType.System,
case ChatType.GmFreeCompany: ChatType.RetainerSale => ChatType.System,
return ChatType.FreeCompany; ChatType.PeriodicRecruitmentNotification => ChatType.System,
case ChatType.NoviceNetwork: ChatType.Sign => ChatType.System,
case ChatType.GmNoviceNetwork: ChatType.Orchestrion => ChatType.System,
return ChatType.NoviceNetwork; ChatType.MessageBook => ChatType.System,
case ChatType.CustomEmote: ChatType.NpcDialogue => ChatType.NpcDialogue,
return ChatType.CustomEmote; ChatType.NpcAnnouncement => ChatType.NpcDialogue,
case ChatType.StandardEmote: ChatType.LootRoll => ChatType.LootRoll,
return ChatType.StandardEmote; ChatType.RandomNumber => ChatType.LootRoll,
case ChatType.Yell: ChatType.FreeCompanyAnnouncement => ChatType.FreeCompanyAnnouncement,
case ChatType.GmYell: ChatType.FreeCompanyLoginLogout => ChatType.FreeCompanyAnnouncement,
return ChatType.Yell; ChatType.PvpTeamAnnouncement => ChatType.PvpTeamAnnouncement,
case ChatType.GainBuff: ChatType.PvpTeamLoginLogout => ChatType.PvpTeamAnnouncement,
case ChatType.LoseBuff: _ => this.Type,
return ChatType.GainBuff; };
case ChatType.GainDebuff:
case ChatType.LoseDebuff:
return ChatType.GainDebuff;
case ChatType.System:
case ChatType.Alarm:
case ChatType.RetainerSale:
case ChatType.PeriodicRecruitmentNotification:
case ChatType.Sign:
case ChatType.Orchestrion:
case ChatType.MessageBook:
return ChatType.System;
case ChatType.NpcDialogue:
case ChatType.NpcAnnouncement:
return ChatType.NpcDialogue;
case ChatType.LootRoll:
case ChatType.RandomNumber:
return ChatType.LootRoll;
case ChatType.FreeCompanyAnnouncement:
case ChatType.FreeCompanyLoginLogout:
return ChatType.FreeCompanyAnnouncement;
case ChatType.PvpTeamAnnouncement:
case ChatType.PvpTeamLoginLogout:
return ChatType.PvpTeamAnnouncement;
default:
return this.Type;
}
}
//public string ConfigKey() { //public string ConfigKey() {
// switch (this.Type) { // switch (this.Type) {
@ -317,97 +298,55 @@ namespace XIVChatCommon {
// } // }
//} //}
public NameFormatting NameFormat() { public NameFormatting NameFormat() => this.Type switch {
switch (this.Type) { ChatType.Say => NameFormatting.Of("", ": "),
case ChatType.Say: ChatType.Shout => NameFormatting.Of("", ": "),
case ChatType.Shout: ChatType.Yell => NameFormatting.Of("", ": "),
case ChatType.Yell: ChatType.NpcAnnouncement => NameFormatting.Of("", ": "),
case ChatType.NpcAnnouncement: ChatType.NpcDialogue => NameFormatting.Of("", ": "),
case ChatType.NpcDialogue: ChatType.TellOutgoing => NameFormatting.Of(">> ", ": "),
return NameFormatting.Of("", ": "); ChatType.TellIncoming => NameFormatting.Of("", " >> "),
case ChatType.TellOutgoing: ChatType.GmTell => NameFormatting.Of("[GM]", " >> "),
return NameFormatting.Of(">> ", ": "); ChatType.GmSay => NameFormatting.Of("[GM]", ": "),
case ChatType.TellIncoming: ChatType.GmShout => NameFormatting.Of("[GM]", ": "),
return NameFormatting.Of("", " >> "); ChatType.GmYell => NameFormatting.Of("[GM]", ": "),
case ChatType.GmTell: ChatType.GmParty => NameFormatting.Of("([GM]", ") "),
return NameFormatting.Of("[GM]", " >> "); ChatType.GmFreeCompany => NameFormatting.Of("[FC]<[GM]", "> "),
case ChatType.GmSay: ChatType.GmLinkshell1 => NameFormatting.Of("[1]<[GM]", "> "),
case ChatType.GmShout: ChatType.GmLinkshell2 => NameFormatting.Of("[2]<[GM]", "> "),
case ChatType.GmYell: ChatType.GmLinkshell3 => NameFormatting.Of("[3]<[GM]", "> "),
return NameFormatting.Of("[GM]", ": "); ChatType.GmLinkshell4 => NameFormatting.Of("[4]<[GM]", "> "),
case ChatType.GmParty: ChatType.GmLinkshell5 => NameFormatting.Of("[5]<[GM]", "> "),
return NameFormatting.Of("([GM]", ") "); ChatType.GmLinkshell6 => NameFormatting.Of("[6]<[GM]", "> "),
case ChatType.GmFreeCompany: ChatType.GmLinkshell7 => NameFormatting.Of("[7]<[GM]", "> "),
return NameFormatting.Of("[FC]<[GM]", "> "); ChatType.GmLinkshell8 => NameFormatting.Of("[8]<[GM]", "> "),
case ChatType.GmLinkshell1: ChatType.GmNoviceNetwork => NameFormatting.Of("[NOVICE][GM]", ": "),
return NameFormatting.Of("[1]<[GM]", "> "); ChatType.Party => NameFormatting.Of("(", ") "),
case ChatType.GmLinkshell2: ChatType.CrossParty => NameFormatting.Of("(", ") "),
return NameFormatting.Of("[2]<[GM]", "> "); ChatType.Alliance => NameFormatting.Of("((", ")) "),
case ChatType.GmLinkshell3: ChatType.PvpTeam => NameFormatting.Of("[PVP]<", "> "),
return NameFormatting.Of("[3]<[GM]", "> "); ChatType.FreeCompany => NameFormatting.Of("[FC]<", "> "),
case ChatType.GmLinkshell4: ChatType.Linkshell1 => NameFormatting.Of("[1]<", "> "),
return NameFormatting.Of("[4]<[GM]", "> "); ChatType.Linkshell2 => NameFormatting.Of("[2]<", "> "),
case ChatType.GmLinkshell5: ChatType.Linkshell3 => NameFormatting.Of("[3]<", "> "),
return NameFormatting.Of("[5]<[GM]", "> "); ChatType.Linkshell4 => NameFormatting.Of("[4]<", "> "),
case ChatType.GmLinkshell6: ChatType.Linkshell5 => NameFormatting.Of("[5]<", "> "),
return NameFormatting.Of("[6]<[GM]", "> "); ChatType.Linkshell6 => NameFormatting.Of("[6]<", "> "),
case ChatType.GmLinkshell7: ChatType.Linkshell7 => NameFormatting.Of("[7]<", "> "),
return NameFormatting.Of("[7]<[GM]", "> "); ChatType.Linkshell8 => NameFormatting.Of("[8]<", "> "),
case ChatType.GmLinkshell8: ChatType.StandardEmote => NameFormatting.Empty(),
return NameFormatting.Of("[8]<[GM]", "> "); ChatType.CustomEmote => NameFormatting.Of("", ""),
case ChatType.GmNoviceNetwork: ChatType.CrossLinkshell1 => NameFormatting.Of("[CWLS1]<", "> "),
return NameFormatting.Of("[NOVICE][GM]", ": "); ChatType.CrossLinkshell2 => NameFormatting.Of("[CWLS2]<", "> "),
case ChatType.Party: ChatType.CrossLinkshell3 => NameFormatting.Of("[CWLS3]<", "> "),
case ChatType.CrossParty: ChatType.CrossLinkshell4 => NameFormatting.Of("[CWLS4]<", "> "),
return NameFormatting.Of("(", ") "); ChatType.CrossLinkshell5 => NameFormatting.Of("[CWLS5]<", "> "),
case ChatType.Alliance: ChatType.CrossLinkshell6 => NameFormatting.Of("[CWLS6]<", "> "),
return NameFormatting.Of("((", ")) "); ChatType.CrossLinkshell7 => NameFormatting.Of("[CWLS7]<", "> "),
case ChatType.PvpTeam: ChatType.CrossLinkshell8 => NameFormatting.Of("[CWLS8]<", "> "),
return NameFormatting.Of("[PVP]<", "> "); ChatType.NoviceNetwork => NameFormatting.Of("[NOVICE]", ": "),
case ChatType.FreeCompany: _ => null
return NameFormatting.Of("[FC]<", "> "); };
case ChatType.Linkshell1:
return NameFormatting.Of("[1]<", "> ");
case ChatType.Linkshell2:
return NameFormatting.Of("[2]<", "> ");
case ChatType.Linkshell3:
return NameFormatting.Of("[3]<", "> ");
case ChatType.Linkshell4:
return NameFormatting.Of("[4]<", "> ");
case ChatType.Linkshell5:
return NameFormatting.Of("[5]<", "> ");
case ChatType.Linkshell6:
return NameFormatting.Of("[6]<", "> ");
case ChatType.Linkshell7:
return NameFormatting.Of("[7]<", "> ");
case ChatType.Linkshell8:
return NameFormatting.Of("[8]<", "> ");
case ChatType.StandardEmote:
return NameFormatting.Empty();
case ChatType.CustomEmote:
return NameFormatting.Of("", "");
case ChatType.CrossLinkshell1:
return NameFormatting.Of("[CWLS1]<", "> ");
case ChatType.CrossLinkshell2:
return NameFormatting.Of("[CWLS2]<", "> ");
case ChatType.CrossLinkshell3:
return NameFormatting.Of("[CWLS3]<", "> ");
case ChatType.CrossLinkshell4:
return NameFormatting.Of("[CWLS4]<", "> ");
case ChatType.CrossLinkshell5:
return NameFormatting.Of("[CWLS5]<", "> ");
case ChatType.CrossLinkshell6:
return NameFormatting.Of("[CWLS6]<", "> ");
case ChatType.CrossLinkshell7:
return NameFormatting.Of("[CWLS7]<", "> ");
case ChatType.CrossLinkshell8:
return NameFormatting.Of("[CWLS8]<", "> ");
case ChatType.NoviceNetwork:
return NameFormatting.Of("[NOVICE]", ": ");
default:
return null;
}
}
public bool IsBattle() { public bool IsBattle() {
switch (this.Type) { switch (this.Type) {
@ -532,9 +471,9 @@ namespace XIVChatCommon {
} }
private static uint Rgba(byte red, byte green, byte blue, byte alpha = 0xFF) => alpha private static uint Rgba(byte red, byte green, byte blue, byte alpha = 0xFF) => alpha
| (uint)(red << 24) | (uint)(red << 24)
| (uint)(green << 16) | (uint)(green << 16)
| (uint)(blue << 8); | (uint)(blue << 8);
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1028:Enum Storage should be Int32")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1028:Enum Storage should be Int32")]
@ -561,6 +500,7 @@ namespace XIVChatCommon {
CustomEmote = 28, CustomEmote = 28,
StandardEmote = 29, StandardEmote = 29,
Yell = 30, Yell = 30,
// 31 - also party? // 31 - also party?
CrossParty = 32, CrossParty = 32,
PvpTeam = 36, PvpTeam = 36,
@ -659,10 +599,12 @@ namespace XIVChatCommon {
/// Sent in response to a client ping. Has no payload. /// Sent in response to a client ping. Has no payload.
/// </summary> /// </summary>
Pong = 1, Pong = 1,
/// <summary> /// <summary>
/// A message was sent in game and is being relayed to the client. /// A message was sent in game and is being relayed to the client.
/// </summary> /// </summary>
Message = 2, Message = 2,
/// <summary> /// <summary>
/// The server is shutting down. Clients should send no response and close their sockets. Has no payload. /// The server is shutting down. Clients should send no response and close their sockets. Has no payload.
/// </summary> /// </summary>
@ -677,14 +619,10 @@ namespace XIVChatCommon {
[MessagePackObject] [MessagePackObject]
public class PlayerData : IEncodable { public class PlayerData : IEncodable {
[Key(0)] [Key(0)] public readonly string homeWorld;
public readonly string homeWorld; [Key(1)] public readonly string currentWorld;
[Key(1)] [Key(2)] public readonly string location;
public readonly string currentWorld; [Key(3)] public readonly string name;
[Key(2)]
public readonly string location;
[Key(3)]
public readonly string name;
public PlayerData(string homeWorld, string currentWorld, string location, string name) { public PlayerData(string homeWorld, string currentWorld, string location, string name) {
this.homeWorld = homeWorld; this.homeWorld = homeWorld;
@ -718,8 +656,7 @@ namespace XIVChatCommon {
[MessagePackObject] [MessagePackObject]
public class Availability : IEncodable { public class Availability : IEncodable {
[Key(0)] [Key(0)] public readonly bool available;
public readonly bool available;
public Availability(bool available) { public Availability(bool available) {
this.available = available; this.available = available;
@ -739,10 +676,8 @@ namespace XIVChatCommon {
[MessagePackObject] [MessagePackObject]
public class ServerChannel : IEncodable { public class ServerChannel : IEncodable {
[Key(0)] [Key(0)] public readonly byte channel;
public readonly byte channel; [Key(1)] public readonly string name;
[Key(1)]
public readonly string name;
[IgnoreMember] [IgnoreMember]
public InputChannel InputChannel => (InputChannel)this.channel; public InputChannel InputChannel => (InputChannel)this.channel;
@ -841,8 +776,7 @@ namespace XIVChatCommon {
[MessagePackObject] [MessagePackObject]
public class ServerBacklog : IEncodable { public class ServerBacklog : IEncodable {
[Key(0)] [Key(0)] public readonly ServerMessage[] messages;
public readonly ServerMessage[] messages;
protected override byte Code => (byte)ServerOperation.Backlog; protected override byte Code => (byte)ServerOperation.Backlog;
@ -938,32 +872,46 @@ namespace XIVChatCommon {
public class Player { public class Player {
[Key(0)] [Key(0)]
public string Name { get; set; } public string Name { get; set; }
[Key(1)] [Key(1)]
public string FreeCompany { get; set; } public string FreeCompany { get; set; }
[Key(2)] [Key(2)]
public ulong Status { get; set; } public ulong Status { get; set; }
[Key(3)] [Key(3)]
public ushort CurrentWorld { get; set; } public ushort CurrentWorld { get; set; }
[Key(4)] [Key(4)]
public string CurrentWorldName { get; set; } public string CurrentWorldName { get; set; }
[Key(5)] [Key(5)]
public ushort HomeWorld { get; set; } public ushort HomeWorld { get; set; }
[Key(6)] [Key(6)]
public string HomeWorldName { get; set; } public string HomeWorldName { get; set; }
[Key(7)] [Key(7)]
public ushort Territory { get; set; } public ushort Territory { get; set; }
[Key(8)] [Key(8)]
public string TerritoryName { get; set; } public string TerritoryName { get; set; }
[Key(9)] [Key(9)]
public byte Job { get; set; } public byte Job { get; set; }
[Key(10)] [Key(10)]
public string JobName { get; set; } public string JobName { get; set; }
[Key(11)] [Key(11)]
public byte GrandCompany { get; set; } public byte GrandCompany { get; set; }
[Key(12)] [Key(12)]
public string GrandCompanyName { get; set; } public string GrandCompanyName { get; set; }
[Key(13)] [Key(13)]
public byte Languages { get; set; } public byte Languages { get; set; }
[Key(14)] [Key(14)]
public byte MainLanguage { get; set; } public byte MainLanguage { get; set; }
} }
@ -976,7 +924,9 @@ namespace XIVChatCommon {
byte[] payload = this.PayloadEncode(); byte[] payload = this.PayloadEncode();
if (payload.Length == 0) { if (payload.Length == 0) {
return new byte[] { this.Code }; return new[] {
this.Code,
};
} }
byte[] bytes = new byte[1 + payload.Length]; byte[] bytes = new byte[1 + payload.Length];

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace XIVChatCommon { namespace XIVChatCommon {
public static class SecretMessage { public static class SecretMessage {
private const uint MAX_MESSAGE_LEN = 128_000; private const uint MaxMessageLen = 128_000;
public async static Task<byte[]> ReadSecretMessage(Stream s, byte[] key, CancellationToken token = default) { public async static Task<byte[]> ReadSecretMessage(Stream s, byte[] key, CancellationToken token = default) {
int read = 0; int read = 0;
@ -20,8 +20,8 @@ namespace XIVChatCommon {
uint length = BitConverter.ToUInt32(header, 0); uint length = BitConverter.ToUInt32(header, 0);
byte[] nonce = header.Skip(4).ToArray(); byte[] nonce = header.Skip(4).ToArray();
if (length > MAX_MESSAGE_LEN) { if (length > MaxMessageLen) {
throw new ArgumentOutOfRangeException($"Encrypted message specified a size of {length}, which is greater than the limit of {MAX_MESSAGE_LEN}"); throw new ArgumentOutOfRangeException($"Encrypted message specified a size of {length}, which is greater than the limit of {MaxMessageLen}");
} }
byte[] ciphertext = new byte[length]; byte[] ciphertext = new byte[length];
@ -38,8 +38,8 @@ namespace XIVChatCommon {
byte[] ciphertext = SecretBox.Create(message, nonce, key); byte[] ciphertext = SecretBox.Create(message, nonce, key);
byte[] len = BitConverter.GetBytes((uint)ciphertext.Length); byte[] len = BitConverter.GetBytes((uint)ciphertext.Length);
if (ciphertext.Length > MAX_MESSAGE_LEN) { if (ciphertext.Length > MaxMessageLen) {
throw new ArgumentOutOfRangeException($"Encrypted message would be {len} bytes long, which is larger than the limit of {MAX_MESSAGE_LEN}"); throw new ArgumentOutOfRangeException($"Encrypted message would be {len} bytes long, which is larger than the limit of {MaxMessageLen}");
} }
await s.WriteAsync(len, 0, len.Length, token); await s.WriteAsync(len, 0, len.Length, token);

View File

@ -33,35 +33,48 @@
<LangVersion>8.0</LangVersion> <LangVersion>8.0</LangVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="MessagePack, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b4a0369545f0a1be, processorArchitecture=MSIL"> <Reference Include="MessagePack, Version=2.2.0.0, Culture=neutral, PublicKeyToken=b4a0369545f0a1be">
<HintPath>..\packages\MessagePack.2.1.194\lib\netstandard2.0\MessagePack.dll</HintPath> <HintPath>..\packages\MessagePack.2.2.60\lib\netstandard2.0\MessagePack.dll</HintPath>
<Private>True</Private>
</Reference> </Reference>
<Reference Include="MessagePack.Annotations, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b4a0369545f0a1be, processorArchitecture=MSIL"> <Reference Include="MessagePack.Annotations, Version=2.2.0.0, Culture=neutral, PublicKeyToken=b4a0369545f0a1be">
<HintPath>..\packages\MessagePack.Annotations.2.1.194\lib\netstandard2.0\MessagePack.Annotations.dll</HintPath> <HintPath>..\packages\MessagePack.Annotations.2.2.60\lib\netstandard2.0\MessagePack.Annotations.dll</HintPath>
<Private>True</Private>
</Reference> </Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.1.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath> <HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.1.1.1\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
<Private>True</Private>
</Reference> </Reference>
<Reference Include="mscorlib" />
<Reference Include="Sodium.Core, Version=1.2.3.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Sodium.Core, Version=1.2.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Sodium.Core.1.2.3\lib\netstandard2.0\Sodium.Core.dll</HintPath> <HintPath>..\packages\Sodium.Core.1.2.3\lib\netstandard2.0\Sodium.Core.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
<HintPath>..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll</HintPath> <HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Collections.Immutable, Version=1.2.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>..\packages\System.Collections.Immutable.1.7.1\lib\net461\System.Collections.Immutable.dll</HintPath>
<Private>True</Private>
</Reference> </Reference>
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
<HintPath>..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll</HintPath> <HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
<Private>True</Private>
</Reference> </Reference>
<Reference Include="System.Numerics" /> <Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll</HintPath> <HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
<Private>True</Private>
</Reference> </Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath> <HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
<Private>True</Private>
</Reference> </Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.3\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath> <HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
<Private>True</Private>
</Reference> </Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath> <HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>

View File

@ -5,8 +5,8 @@ using System.Text;
namespace XIVChatCommon { namespace XIVChatCommon {
public static class XivString { public static class XivString {
private const byte START = 2; private const byte Start = 2;
private const byte END = 3; private const byte End = 3;
public static List<Chunk> ToChunks(byte[] bytes) { public static List<Chunk> ToChunks(byte[] bytes) {
var chunks = new List<Chunk>(); var chunks = new List<Chunk>();
@ -16,7 +16,7 @@ namespace XIVChatCommon {
uint? foreground = null; uint? foreground = null;
uint? glow = null; uint? glow = null;
Action<bool> appendCurrent = (bool clear) => { void AppendCurrent(bool clear) {
var text = Encoding.UTF8.GetString(stringBytes.ToArray()); var text = Encoding.UTF8.GetString(stringBytes.ToArray());
chunks.Add(new TextChunk { chunks.Add(new TextChunk {
Foreground = foreground, Foreground = foreground,
@ -27,17 +27,17 @@ namespace XIVChatCommon {
if (clear) { if (clear) {
stringBytes.Clear(); stringBytes.Clear();
} }
}; }
var reader = new BinaryReader(new MemoryStream(bytes)); var reader = new BinaryReader(new MemoryStream(bytes));
while (reader.BaseStream.Position < reader.BaseStream.Length) { while (reader.BaseStream.Position < reader.BaseStream.Length) {
var b = reader.ReadByte(); var b = reader.ReadByte();
if (b == START) { if (b == Start) {
var kind = reader.ReadByte(); // kind var kind = reader.ReadByte(); // kind
var len = GetInteger(reader); // data length var len = GetInteger(reader); // data length
var data = new BinaryReader(new MemoryStream(reader.ReadBytes((int)len))); // data var data = new BinaryReader(new MemoryStream(reader.ReadBytes((int)len))); // data
var end = reader.ReadByte(); // end var end = reader.ReadByte(); // end
if (end != END) { if (end != End) {
throw new ArgumentException("Input was not a valid XivString"); throw new ArgumentException("Input was not a valid XivString");
} }
@ -58,7 +58,7 @@ namespace XIVChatCommon {
break; break;
} }
appendCurrent(true); AppendCurrent(true);
italic = newStatus; italic = newStatus;
break; break;
@ -83,12 +83,12 @@ namespace XIVChatCommon {
var reader = new BinaryReader(new MemoryStream(bytes)); var reader = new BinaryReader(new MemoryStream(bytes));
while (reader.BaseStream.Position < reader.BaseStream.Length) { while (reader.BaseStream.Position < reader.BaseStream.Length) {
var b = reader.ReadByte(); var b = reader.ReadByte();
if (b == START) { if (b == Start) {
reader.ReadByte(); // kind reader.ReadByte(); // kind
var len = GetInteger(reader); // data length var len = GetInteger(reader); // data length
reader.ReadBytes((int)len); // data reader.ReadBytes((int)len); // data
var end = reader.ReadByte(); // end var end = reader.ReadByte(); // end
if (end != END) { if (end != End) {
throw new ArgumentException("Input was not a valid XivString"); throw new ArgumentException("Input was not a valid XivString");
} }
continue; continue;
@ -101,24 +101,24 @@ namespace XIVChatCommon {
// Thanks, Dalamud // Thanks, Dalamud
protected enum IntegerType { private enum IntegerType {
// used as an internal marker; sometimes single bytes are bare with no marker at all // used as an internal marker; sometimes single bytes are bare with no marker at all
None = 0, None = 0,
Byte = 0xF0, Byte = 0xF0,
ByteTimes256 = 0xF1, ByteTimes256 = 0xF1,
Int16 = 0xF2, Int16 = 0xF2,
ByteSHL16 = 0xF3, ByteShl16 = 0xF3,
Int16Packed = 0xF4, // seen in map links, seemingly 2 8-bit values packed into 2 bytes with only one marker Int16Packed = 0xF4, // seen in map links, seemingly 2 8-bit values packed into 2 bytes with only one marker
Int16SHL8 = 0xF5, Int16Shl8 = 0xF5,
Int24Special = 0xF6, // unsure how different form Int24 - used for hq items that add 1 million, also used for normal 24-bit values in map links Int24Special = 0xF6, // unsure how different form Int24 - used for hq items that add 1 million, also used for normal 24-bit values in map links
Int8SHL24 = 0xF7, Int8Shl24 = 0xF7,
Int8SHL8Int8 = 0xF8, Int8Shl8Int8 = 0xF8,
Int8SHL8Int8SHL8 = 0xF9, Int8Shl8Int8Shl8 = 0xF9,
Int24 = 0xFA, Int24 = 0xFA,
Int16SHL16 = 0xFB, Int16Shl16 = 0xFB,
Int24Packed = 0xFC, // used in map links- sometimes short+byte, sometimes... not?? Int24Packed = 0xFC, // used in map links- sometimes short+byte, sometimes... not??
Int16Int8SHL8 = 0xFD, Int16Int8Shl8 = 0xFD,
Int32 = 0xFE Int32 = 0xFE
} }
@ -129,10 +129,10 @@ namespace XIVChatCommon {
} }
private static uint GetInteger(BinaryReader input, IntegerType type) { private static uint GetInteger(BinaryReader input, IntegerType type) {
const byte ByteLengthCutoff = 0xF0; const byte byteLengthCutoff = 0xF0;
var t = (byte)type; var t = (byte)type;
if (t < ByteLengthCutoff) { if (t < byteLengthCutoff) {
return (uint)(t - 1); return (uint)(t - 1);
} }
@ -142,17 +142,17 @@ namespace XIVChatCommon {
case IntegerType.ByteTimes256: case IntegerType.ByteTimes256:
return input.ReadByte() * (uint)256; return input.ReadByte() * (uint)256;
case IntegerType.ByteSHL16: case IntegerType.ByteShl16:
return (uint)(input.ReadByte() << 16); return (uint)(input.ReadByte() << 16);
case IntegerType.Int8SHL24: case IntegerType.Int8Shl24:
return (uint)(input.ReadByte() << 24); return (uint)(input.ReadByte() << 24);
case IntegerType.Int8SHL8Int8: { case IntegerType.Int8Shl8Int8: {
var v = 0; var v = 0;
v |= input.ReadByte() << 24; v |= input.ReadByte() << 24;
v |= input.ReadByte(); v |= input.ReadByte();
return (uint)v; return (uint)v;
} }
case IntegerType.Int8SHL8Int8SHL8: { case IntegerType.Int8Shl8Int8Shl8: {
var v = 0; var v = 0;
v |= input.ReadByte() << 24; v |= input.ReadByte() << 24;
v |= input.ReadByte() << 8; v |= input.ReadByte() << 8;
@ -168,13 +168,13 @@ namespace XIVChatCommon {
v |= input.ReadByte(); v |= input.ReadByte();
return (uint)v; return (uint)v;
} }
case IntegerType.Int16SHL8: { case IntegerType.Int16Shl8: {
var v = 0; var v = 0;
v |= input.ReadByte() << 16; v |= input.ReadByte() << 16;
v |= input.ReadByte() << 8; v |= input.ReadByte() << 8;
return (uint)v; return (uint)v;
} }
case IntegerType.Int16SHL16: { case IntegerType.Int16Shl16: {
var v = 0; var v = 0;
v |= input.ReadByte() << 24; v |= input.ReadByte() << 24;
v |= input.ReadByte() << 16; v |= input.ReadByte() << 16;
@ -192,7 +192,7 @@ namespace XIVChatCommon {
v |= input.ReadByte(); v |= input.ReadByte();
return (uint)v; return (uint)v;
} }
case IntegerType.Int16Int8SHL8: { case IntegerType.Int16Int8Shl8: {
var v = 0; var v = 0;
v |= input.ReadByte() << 24; v |= input.ReadByte() << 24;
v |= input.ReadByte() << 16; v |= input.ReadByte() << 16;

View File

@ -1,17 +1,18 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="MessagePack" version="2.2.60" targetFramework="net48" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="1.1.1" targetFramework="net48" />
<package id="System.Memory" version="4.5.4" targetFramework="net48" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" />
<package id="System.Reflection.Emit" version="4.7.0" targetFramework="net48" />
<package id="System.Reflection.Emit.Lightweight" version="4.7.0" targetFramework="net48" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.7.1" targetFramework="net48" />
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net48" />
<package id="System.Collections.Immutable" version="1.7.1" targetFramework="net48" />
<package id="libsodium" version="1.0.18" targetFramework="net48" /> <package id="libsodium" version="1.0.18" targetFramework="net48" />
<package id="MessagePack" version="2.1.194" targetFramework="net48" /> <package id="MessagePack.Annotations" version="2.2.60" targetFramework="net48" />
<package id="MessagePack.Annotations" version="2.1.194" targetFramework="net48" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="1.0.0" targetFramework="net48" />
<package id="Microsoft.NETCore.Platforms" version="3.1.3" targetFramework="net48" /> <package id="Microsoft.NETCore.Platforms" version="3.1.3" targetFramework="net48" />
<package id="Sodium.Core" version="1.2.3" targetFramework="net48" /> <package id="Sodium.Core" version="1.2.3" targetFramework="net48" />
<package id="System.Buffers" version="4.4.0" targetFramework="net48" /> <package id="System.Buffers" version="4.5.1" targetFramework="net48" />
<package id="System.Memory" version="4.5.3" targetFramework="net48" />
<package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net48" />
<package id="System.Reflection.Emit" version="4.6.0" targetFramework="net48" />
<package id="System.Reflection.Emit.Lightweight" version="4.6.0" targetFramework="net48" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net48" />
<package id="System.Threading.Tasks.Extensions" version="4.5.3" targetFramework="net48" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net48" /> <package id="System.ValueTuple" version="4.5.0" targetFramework="net48" />
</packages> </packages>