From 8558ec64c898fcb7e324253b2d7b9db7996c7fbf Mon Sep 17 00:00:00 2001 From: arc_ Date: Thu, 16 Feb 2023 19:54:03 +0100 Subject: [PATCH] #120 Fix SJIS tunnel GetByteCount() not matching GetBytes() --- VNTextPatch.Shared/Util/SjisTunnelEncoding.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/VNTextPatch.Shared/Util/SjisTunnelEncoding.cs b/VNTextPatch.Shared/Util/SjisTunnelEncoding.cs index ab12324..27d8f6b 100644 --- a/VNTextPatch.Shared/Util/SjisTunnelEncoding.cs +++ b/VNTextPatch.Shared/Util/SjisTunnelEncoding.cs @@ -9,7 +9,7 @@ public class SjisTunnelEncoding : Encoding { private static readonly Encoding SjisEncoding = GetEncoding(932, EncoderFallback.ExceptionFallback, DecoderFallback.ExceptionFallback); - private readonly char[] _charArray = new char[1]; + private readonly byte[] _byteArray = new byte[2]; private readonly Dictionary _mappings = new Dictionary(); public SjisTunnelEncoding() @@ -30,15 +30,10 @@ public override int GetByteCount(string str) if (!tunneled) { - try - { - _charArray[0] = str[i]; - byteCount += SjisEncoding.GetByteCount(_charArray); - } - catch - { + if (TrySjisEncode(str, i, 1, _byteArray, 0, out int charByteCount)) + byteCount += charByteCount; + else tunneled = true; - } } if (tunneled)