Remove reflection from InputPreview
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using ChatTwo.Code;
|
using ChatTwo.Code;
|
||||||
@@ -177,17 +176,13 @@ public partial class InputPreview : Window
|
|||||||
if (icon.Icon != BitmapFontIcon.AutoTranslateBegin)
|
if (icon.Icon != BitmapFontIcon.AutoTranslateBegin)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
NextChunkIsAutoTranslate = true;
|
NextChunkIsAutoTranslate = true;
|
||||||
var key = (uint)typeof(AutoTranslatePayload).GetField("key", BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(chunk.Link)!;
|
|
||||||
var group = (uint)typeof(AutoTranslatePayload).GetField("group", BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(chunk.Link)!;
|
// Skipping: StartByte, PayloadType, PayloadLength
|
||||||
CursorPosition += $"<at:{key},{group}>".Length;
|
using var reader = new BinaryReader(new MemoryStream(chunk.Link!.Encode().Skip(3).ToArray()));
|
||||||
}
|
var group = (uint) reader.ReadByte();
|
||||||
catch
|
var key = PayloadExt.GetInteger(reader);
|
||||||
{
|
CursorPosition += $"<at:{group},{key}>".Length;
|
||||||
// Ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,33 @@ using Dalamud.Game.Text.SeStringHandling;
|
|||||||
|
|
||||||
namespace ChatTwo.Util;
|
namespace ChatTwo.Util;
|
||||||
|
|
||||||
|
internal static class PayloadExt
|
||||||
|
{
|
||||||
|
// TODO: Remove after Key and Group in AutoTranslatePayload became public
|
||||||
|
// From: https://github.com/goatcorp/Dalamud/blob/master/Dalamud/Game/Text/SeStringHandling/Payload.cs#L366
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve the packed integer from SE's native data format.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">The BinaryReader instance.</param>
|
||||||
|
/// <returns>An integer.</returns>
|
||||||
|
internal static uint GetInteger(BinaryReader input)
|
||||||
|
{
|
||||||
|
uint marker = input.ReadByte();
|
||||||
|
if (marker < 0xD0)
|
||||||
|
return marker - 1;
|
||||||
|
|
||||||
|
marker = (marker + 1) & 0b1111;
|
||||||
|
|
||||||
|
var ret = new byte[4];
|
||||||
|
for (var i = 3; i >= 0; i--)
|
||||||
|
{
|
||||||
|
ret[i] = (marker & (1 << i)) == 0 ? (byte)0 : input.ReadByte();
|
||||||
|
}
|
||||||
|
|
||||||
|
return BitConverter.ToUInt32(ret, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal class PartyFinderPayload : Payload {
|
internal class PartyFinderPayload : Payload {
|
||||||
public override PayloadType Type => (PayloadType) 0x50;
|
public override PayloadType Type => (PayloadType) 0x50;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user