From 076d113a4d8a8f445457c9635701e6f5cdd1de1e Mon Sep 17 00:00:00 2001 From: "DESKTOP-SN9KF5O\\Strawberry" Date: Fri, 30 Jan 2026 01:45:34 +0000 Subject: [PATCH] Injector: Just use Convert.ToHexString for Decoder now that we don't target .NET framework --- NHSE.Injection/SysBot/Decoder.cs | 36 ++------------------------------ 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/NHSE.Injection/SysBot/Decoder.cs b/NHSE.Injection/SysBot/Decoder.cs index 59f45ba..da6e1c3 100644 --- a/NHSE.Injection/SysBot/Decoder.cs +++ b/NHSE.Injection/SysBot/Decoder.cs @@ -4,38 +4,6 @@ namespace NHSE.Injection; public static class Decoder { - private static bool IsNum(char c) => (uint)(c - '0') <= 9; - private static bool IsHexUpper(char c) => (uint)(c - 'A') <= 5; - - public static byte[] ConvertHexByteStringToBytes(ReadOnlySpan bytes) - { - var dest = new byte[bytes.Length / 2]; - LoadHexBytesTo(bytes, dest, 2); - return dest; - } - - public static void LoadHexBytesTo(ReadOnlySpan str, Span dest, int tupleSize) - { - // The input string is 2-char hex values optionally separated. - // The destination array should always be larger or equal than the bytes written. Let the runtime bounds check us. - // Iterate through the string without allocating. - for (int i = 0, j = 0; i < str.Length; i += tupleSize) - dest[j++] = DecodeTuple((char)str[i + 0], (char)str[i + 1]); - } - - private static byte DecodeTuple(char _0, char _1) - { - return (byte)(DecodeChar(_0) << 4 | DecodeChar(_1)); - - static int DecodeChar(char x) - { - if (char.IsAsciiDigit(x)) - return (byte)(x - '0'); - if (char.IsAsciiHexDigitUpper(x)) - return (byte)(x - 'A' + 10); - if (char.IsAsciiHexDigitLower(x)) - return (byte)(x - 'a' + 10); - throw new ArgumentOutOfRangeException(nameof(_0)); - } - } + public static byte[] ConvertHexByteStringToBytes(byte[] bytes) + => Convert.FromHexString(bytes.AsSpan(0, bytes.Length - 1)); } \ No newline at end of file