7d5496e959
81 namespace declarations and 100 using directives converted via sed, plus two FQN-aliases (ChatTwoPartyFinderPayload in PayloadHandler.cs and ModifierFlag in KeybindManager.cs) updated. Critical: Language.Designer.cs and HellionStrings.Designer.cs ResourceManager string arguments updated synchronously — these are runtime reflection lookups not caught by the C# compiler. Two intentional ChatTwo references remain: the legacy migration path 'ChatTwo.json' in Plugin.cs (still points to upstream Chat 2's config file by design) and the InternalsVisibleTo declaration in AssemblyInfo.cs (handled in the upcoming repo-folder rename task). The local alias names 'ChatTwoPartyFinderPayload' and 'ChatTwoConflictDetector' are preserved as local symbols; only their target namespaces and references changed.
67 lines
2.5 KiB
C#
67 lines
2.5 KiB
C#
namespace HellionChat.Util;
|
|
|
|
public class ColorPayload
|
|
{
|
|
private const byte StartByte = 2;
|
|
|
|
public bool Enabled;
|
|
public uint Color;
|
|
public uint UnshiftedColor;
|
|
|
|
public static ColorPayload? From(byte[] data)
|
|
{
|
|
using var stream = new MemoryStream(data);
|
|
if (stream.ReadByte() != StartByte || stream.ReadByte() != 0x13)
|
|
return null;
|
|
|
|
stream.ReadByte(); // skip the length byte;
|
|
|
|
var typeByte = stream.ReadByte();
|
|
var payload = new ColorPayload();
|
|
switch (typeByte)
|
|
{
|
|
case 0xEC:
|
|
payload.Enabled = false;
|
|
return payload;
|
|
case 0xE9:
|
|
var param = stream.ReadByte();
|
|
var globalValue = (uint) GlobalParametersCache.GetValue(param - 2);
|
|
payload.Enabled = true;
|
|
payload.UnshiftedColor = globalValue;
|
|
payload.Color = ColourUtil.ArgbToRgba(globalValue);
|
|
|
|
return payload;
|
|
case >= 0xF0 and <= 0xFE:
|
|
// From: https://github.com/NotAdam/Lumina/blob/master/src/Lumina/Text/Expressions/IntegerExpression.cs#L119-L128
|
|
uint ShiftAndThrowIfZero(int v, int shift)
|
|
{
|
|
return v switch
|
|
{
|
|
// ReSharper disable once LocalizableElement
|
|
-1 => throw new ArgumentException("Encountered premature end of input (unexpected EOF).", nameof(v)),
|
|
// ReSharper disable once LocalizableElement
|
|
0 => throw new ArgumentException("Encountered premature end of input (unexpected null character).", nameof(v)),
|
|
_ => (uint)v << shift
|
|
};
|
|
}
|
|
|
|
typeByte += 1;
|
|
var argbValue = 0u;
|
|
if ((typeByte & 8) != 0)
|
|
argbValue |= ShiftAndThrowIfZero(stream.ReadByte(), 24);
|
|
else
|
|
argbValue |= 0xff000000u;
|
|
|
|
if( (typeByte & 4) != 0 ) argbValue |= ShiftAndThrowIfZero( stream.ReadByte(), 16 );
|
|
if( (typeByte & 2) != 0 ) argbValue |= ShiftAndThrowIfZero( stream.ReadByte(), 8 );
|
|
if( (typeByte & 1) != 0 ) argbValue |= ShiftAndThrowIfZero( stream.ReadByte(), 0 );
|
|
|
|
payload.Enabled = true;
|
|
payload.Color = ColourUtil.ArgbToRgba(argbValue);
|
|
|
|
return payload;
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
} |