From eafc28422ef890feabec528c77212a5f53abe98d Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 16 Sep 2017 09:58:03 -0700 Subject: [PATCH] Misc gen4 handling updates Cross-game trading for egg locations (duh) Volt Tackle AND Fakeout pikachu from yellow forest Nidoran fullwidth handling in gen4 Thanks Britty! https://projectpokemon.org/home/forums/topic/41407-pkhex-legality-errors-on-gen-6-updated/?do=findComment&comment=220094 Replicate gen4's string setter for the bigendian variant --- .../Legality/Encounters/Data/Encounters4.cs | 2 +- .../Legality/Encounters/EncounterVerifier.cs | 2 +- PKHeX.Core/PKM/StringConverter.cs | 27 ++++++++----------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/PKHeX.Core/Legality/Encounters/Data/Encounters4.cs b/PKHeX.Core/Legality/Encounters/Data/Encounters4.cs index 1714043d4..1f15d1828 100644 --- a/PKHeX.Core/Legality/Encounters/Data/Encounters4.cs +++ b/PKHeX.Core/Legality/Encounters/Data/Encounters4.cs @@ -627,7 +627,7 @@ private static void MarkHGSSEncounterTypeSlots(ref EncounterArea[] Areas) new EncounterStatic{ Species = 095, Gender = 1, Level = 05, Moves = new[]{088}, }, // Onix: Rock Throw new EncounterStatic{ Species = 025, Gender = 0, Level = 15, Moves = new[]{019}, }, // Pikachu: Fly new EncounterStatic{ Species = 025, Gender = 1, Level = 14, Moves = new[]{057}, }, // Pikachu: Surf - new EncounterStatic{ Species = 025, Gender = 1, Level = 12, Moves = new[]{344}, }, // Pikachu: Volt Tackle + new EncounterStatic{ Species = 025, Gender = 1, Level = 12, Moves = new[]{344, 252}, }, // Pikachu: Volt Tackle, Fake Out new EncounterStatic{ Species = 025, Gender = 0, Level = 13, Moves = new[]{175}, }, // Pikachu: Flail new EncounterStatic{ Species = 025, Gender = 0, Level = 10, }, // Pikachu new EncounterStatic{ Species = 025, Gender = 1, Level = 10, }, // Pikachu diff --git a/PKHeX.Core/Legality/Encounters/EncounterVerifier.cs b/PKHeX.Core/Legality/Encounters/EncounterVerifier.cs index 06fbb00cc..745ce60fa 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterVerifier.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterVerifier.cs @@ -189,7 +189,7 @@ private static CheckResult VerifyEncounterEgg3Transfer(PKM pkm) private static CheckResult VerifyEncounterEgg4(PKM pkm) { if (pkm.Format == 4) - return VerifyEncounterEggLevelLoc(pkm, 0, pkm.HGSS ? Legal.ValidMet_HGSS : pkm.Pt ? Legal.ValidMet_Pt : Legal.ValidMet_DP); + return VerifyEncounterEggLevelLoc(pkm, 0, Legal.Met_HGSS_0); if (pkm.IsEgg) return new CheckResult(Severity.Invalid, V57, CheckIdentifier.Encounter); // transferred diff --git a/PKHeX.Core/PKM/StringConverter.cs b/PKHeX.Core/PKM/StringConverter.cs index 61ce9a901..08c6ed535 100644 --- a/PKHeX.Core/PKM/StringConverter.cs +++ b/PKHeX.Core/PKM/StringConverter.cs @@ -310,7 +310,7 @@ public static string GetBEString4(byte[] strdata, int offset, int count) if (chr == 0xFFFF) break; s += (char)chr; } - return s; + return SanitizeString(s); } /// @@ -325,23 +325,18 @@ public static byte[] SetBEString4(string value, int maxLength, int padTo = 0, us { if (value.Length > maxLength) value = value.Substring(0, maxLength); // Hard cap - byte[] strdata = new byte[value.Length * 2 + 2]; // +2 for 0xFFFF - for (int i = 0; i < value.Length; i++) + + string temp = UnSanitizeString(value, 4) // Replace Special Characters and add Terminator + .PadRight(value.Length + 1, (char)0xFFFF) // Null Terminator + .PadRight(padTo, (char)padWith); // Padding + + byte[] strdata = new byte[temp.Length * 2]; + for (int i = 0; i < temp.Length; i++) { - ushort chr = value[i]; + ushort chr = temp[i]; ushort val = ConvertChar2ValueG4(chr); - if (val == 0xFFFF || chr == 0xFFFF) - { Array.Resize(ref strdata, i * 2 + 2); break; } BigEndian.GetBytes(val).CopyTo(strdata, i * 2); } - BitConverter.GetBytes((ushort)0xFFFF).CopyTo(strdata, strdata.Length - 2); - if (padTo > strdata.Length) - { - int start = strdata.Length; - Array.Resize(ref strdata, padTo); - for (int i = start; i < padTo; i += 2) - BitConverter.GetBytes(padWith).CopyTo(strdata, i); - } return strdata; } @@ -361,7 +356,7 @@ public static string GetString4(byte[] data, int offset, int count) if (chr == 0xFFFF) break; s.Append((char)chr); } - return s.ToString(); + return SanitizeString(s.ToString()); } /// Gets the bytes for a 4th Generation String @@ -1937,7 +1932,7 @@ private static string UnSanitizeString(string str, int generation, int species = { var s = str.Replace("\u0027", "\u2019"); // farfetch'd - if (generation == 5) + if (generation == 5 || generation == 4) { s = s.Replace("\u2640", "\u246E"); // ♀ s = s.Replace("\u2642", "\u246D"); // ♂