4d54eabdac
General code-quality and robustness pass across the plugin: thread- safety on IPC state, resource-disposal cleanups, input validation, defensive null-checks and a few small UX glitches. Compliance docs (THIRD_PARTY_NOTICES, PRIVACY, COPYRIGHT) refreshed to v1.0.3. Highlights - ExtraChat IPC state synchronised across threads - ChatLogWindow autocomplete no longer leaks the unmanaged ImGuiListClipper allocation - ChatLogWindow + Popout style stack stays balanced when config toggles mid-frame - Retention sweep and privacy cleanup wait for the actual filter pass instead of the fire-and-forget Task that started it - Configuration.LatestVersion bumped to 13 to match the active migration path - GameFunctions placeholder buffer guarded against oversized replacement names - TellTarget.IsSet, ResolveTempInputChannel, InputPreview, IconUtil, Lender, Payloads, ExtraPayload all hardened against null / empty / EOF / cycle inputs - FontManager Lodestone download stays in scope for a follow-up (timeout + lazy init pending) - AutoTranslate replaced the msvcrt.dll memcmp P/Invoke with a managed Span comparison - Privacy cleanup worker thread marked IsBackground = true - Database cleanup now removes both legacy files in one click - Tell-target name redacted in the verbose debug log Compliance - THIRD_PARTY_NOTICES: last-reviewed bumped to v1.0.3, Pidgin 3.5.1, SQLitePCLRaw.lib.e_sqlite3 3.50.3 listed as direct dependency with CVE-2025-6965 / CVE-2025-7709 rationale - PRIVACY: last-reviewed bumped to v1.0.3, BetterTTV trigger wording clarified (list fetch at startup vs. on-demand image fetch) - COPYRIGHT: upstream attribution range widened Build: 0 warnings, 0 errors. No behavioural changes that would alter existing user configuration or stored chat history.
69 lines
2.6 KiB
C#
69 lines
2.6 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();
|
|
if (param == -1)
|
|
throw new ArgumentException("Encountered premature end of input (unexpected EOF).", nameof(stream));
|
|
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;
|
|
}
|
|
}
|
|
} |