Beispiel #1
0
        private void VerifyG1NicknameWithinBounds(LegalityAnalysis data, string str)
        {
            var pkm = data.pkm;

            if (StringConverter12.GetIsG1English(str))
            {
                if (str.Length > 10)
                {
                    data.AddLine(GetInvalid(LNickLengthLong));
                }
            }
            else if (StringConverter12.GetIsG1Japanese(str))
            {
                if (str.Length > 5)
                {
                    data.AddLine(GetInvalid(LNickLengthLong));
                }
            }
            else if (pkm.Korean && StringConverter2KOR.GetIsG2Korean(str))
            {
                if (str.Length > 5)
                {
                    data.AddLine(GetInvalid(LNickLengthLong));
                }
            }
            else
            {
                data.AddLine(GetInvalid(LG1CharNick));
            }
        }
 private void VerifyG1OTWithinBounds(LegalityAnalysis data, string str)
 {
     if (StringConverter12.GetIsG1English(str))
     {
         if (str.Length > 7 && !(data.EncounterOriginal is EncounterTrade)) // OT already verified; GER shuckle has 8 chars
         {
             data.AddLine(GetInvalid(LOTLong));
         }
     }
     else if (StringConverter12.GetIsG1Japanese(str))
     {
         if (str.Length > 5)
         {
             data.AddLine(GetInvalid(LOTLong));
         }
     }
     else if (data.pkm.Korean && StringConverter2KOR.GetIsG2Korean(str))
     {
         if (str.Length > 5)
         {
             data.AddLine(GetInvalid(LOTLong));
         }
     }
     else
     {
         data.AddLine(GetInvalid(LG1CharOT));
     }
 }
Beispiel #3
0
        protected override void SetBoxMetadata(int box)
        {
            var bdata = GetBoxOffset(box);

            // Set box count
            int count = 0;

            for (int s = 0; s < BoxSlotCount; s++)
            {
                var rel = bdata + (SIZE_STORED * s);
                if (Data[rel] != 0) // Species present
                {
                    count++;
                }
            }

            var boxOfs = bdata - ListHeaderSizeBox;

            if (Data[boxOfs] == 0)
            {
                Data[boxOfs]     = 1;
                Data[boxOfs + 1] = (byte)count;
                Data[boxOfs + 4] = StringConverter12.G1TerminatorCode;
                StringConverter12.SetString1("1234", 4, Japanese).CopyTo(Data, boxOfs + 0x10);
            }
            else
            {
                Data[boxOfs + 1] = (byte)count;
            }
        }
Beispiel #4
0
 private int SetString(ReadOnlySpan <char> value, Span <byte> destBuffer, int maxLength, StringConverterOption option = StringConverterOption.None)
 {
     if (Korean)
     {
         return(StringConverter2KOR.SetString(destBuffer, value, maxLength, option));
     }
     return(StringConverter12.SetString(destBuffer, value, maxLength, Japanese, option));
 }
Beispiel #5
0
 public override void SetMessage(string line1, string line2)
 {
     if (US)
     {
         StringConverter12.SetString1(line2, 0x10, false, 0x10, 0x50).CopyTo(Data, 0x11);
         StringConverter12.SetString1(line1, 0x10, false, 0x10, Data.Skip(0x11).Take(0x10).All(v => v == 0x50) ? (byte)0x50 : (byte)0x7F).CopyTo(Data, 0);
         Data[0x10] = 0x4E;
     }
 }
Beispiel #6
0
 public override void SetMessage(string line1, string line2)
 {
     if (US)
     {
         StringConverter12.SetString(Data.AsSpan(0x11, 0x10), line2.AsSpan(), 0x10, false, StringConverterOption.Clear50);
         bool hasLine2 = Data[0x11] != StringConverter12.G1TerminatorCode;
         var  padChar  = !hasLine2 ? StringConverterOption.Clear50 : StringConverterOption.Clear7F; // space
         StringConverter12.SetString(Data.AsSpan(0, 0x10), line1.AsSpan(), 0x10, false, padChar);
         Data[0x10] = 0x4E;
     }
 }
Beispiel #7
0
        /// <summary>
        /// Converts bytes to a string according to the input parameters.
        /// </summary>
        /// <param name="data">Encoded data</param>
        /// <param name="generation">Generation string format</param>
        /// <param name="jp">Encoding is Japanese</param>
        /// <param name="isBigEndian">Encoding is Big Endian</param>
        /// <param name="count">Length of data to read.</param>
        /// <param name="offset">Offset to read from</param>
        /// <returns>Decoded string.</returns>
        public static string GetString(byte[] data, int generation, bool jp, bool isBigEndian, int count, int offset = 0)
        {
            if (isBigEndian)
            {
                return(generation == 3 ? StringConverter3.GetBEString3(data, offset, count) : StringConverter4.GetBEString4(data, offset, count));
            }

            return(generation switch
            {
                1 or 2 => StringConverter12.GetString1(data, offset, count, jp),
                3 => StringConverter3.GetString3(data, offset, count, jp),
                4 => StringConverter4.GetString4(data, offset, count),
                5 => GetString5(data, offset, count),
                6 => GetString6(data, offset, count),
                _ => GetString7(data, offset, count),
            });
Beispiel #8
0
        /// <summary>
        /// Gets the bytes for a Generation specific string according to the input parameters.
        /// </summary>
        /// <param name="value">Decoded string.</param>
        /// <param name="generation">Generation string format</param>
        /// <param name="jp">Encoding is Japanese</param>
        /// <param name="bigendian">Encoding is BigEndian</param>
        /// <param name="maxLength"></param>
        /// <param name="language"></param>
        /// <param name="padTo">Pad to given length</param>
        /// <param name="padWith">Pad with value</param>
        /// <returns>Encoded data.</returns>
        public static byte[] SetString(string value, int generation, bool jp, bool bigendian, int maxLength, int language = 0, int padTo = 0, ushort padWith = 0)
        {
            if (bigendian)
            {
                return(generation == 3 ? StringConverter3.SetBEString3(value, maxLength, padTo, padWith) : StringConverter4.SetBEString4(value, maxLength, padTo, padWith));
            }

            switch (generation)
            {
            case 1:
            case 2: return(StringConverter12.SetString1(value, maxLength, jp, padTo, padWith));

            case 3: return(StringConverter3.SetString3(value, maxLength, jp, padTo, padWith));

            case 4: return(StringConverter4.SetString4(value, maxLength, padTo, padWith));

            case 5: return(SetString5(value, maxLength, padTo, padWith));

            case 6: return(SetString6(value, maxLength, padTo, padWith));

            default: return(SetString7(value, maxLength, language, padTo, padWith));
            }
        }
Beispiel #9
0
        /// <summary>
        /// Converts bytes to a string according to the input parameters.
        /// </summary>
        /// <param name="data">Encoded data</param>
        /// <param name="generation">Generation string format</param>
        /// <param name="jp">Encoding is Japanese</param>
        /// <param name="bigendian">Encoding is BigEndian</param>
        /// <param name="count">Length of data to read.</param>
        /// <param name="offset">Offset to read from</param>
        /// <returns>Decoded string.</returns>
        public static string GetString(byte[] data, int generation, bool jp, bool bigendian, int count, int offset = 0)
        {
            if (bigendian)
            {
                return(generation == 3 ? StringConverter3.GetBEString3(data, offset, count) : StringConverter4.GetBEString4(data, offset, count));
            }

            switch (generation)
            {
            case 1:
            case 2: return(StringConverter12.GetString1(data, offset, count, jp));

            case 3: return(StringConverter3.GetString3(data, offset, count, jp));

            case 4: return(StringConverter4.GetString4(data, offset, count));

            case 5: return(GetString5(data, offset, count));

            case 6: return(GetString6(data, offset, count));

            default: return(GetString7(data, offset, count));
            }
        }
Beispiel #10
0
 public override string GetMessage(bool isLastLine) => US?StringConverter12.GetString1(Data, isLastLine? 0x11 : 0, 0x10, false) : string.Empty;
Beispiel #11
0
 public sealed override int SetString(Span <byte> destBuffer, ReadOnlySpan <char> value, int maxLength, StringConverterOption option)
 {
     return(StringConverter12.SetString(destBuffer, value, maxLength, Japanese, option));
 }
Beispiel #12
0
 public sealed override string GetString(ReadOnlySpan <byte> data) => StringConverter12.GetString(data, Japanese);