diff --git a/PKHeX.Core/PKM/CK3.cs b/PKHeX.Core/PKM/CK3.cs index a9bfad0e8..06dfee927 100644 --- a/PKHeX.Core/PKM/CK3.cs +++ b/PKHeX.Core/PKM/CK3.cs @@ -293,10 +293,10 @@ public override int SetString(Span destBuffer, ReadOnlySpan value, i if (current == expect) return StringConverter3GC.SetString(destBuffer, value, maxLength, option); // no remap needed - Span remap = stackalloc byte[destBuffer.Length]; - destBuffer.CopyTo(remap); - StringConverter3GC.RemapGlyphsBetweenRegions3GC(remap, expect, current, language); - return StringConverter3GC.SetString(remap, value, maxLength, option); + // ensure glyphs match the transfer route + var result = StringConverter3GC.SetString(destBuffer, value, maxLength, option); + StringConverter3GC.RemapGlyphsBetweenRegions3GC(destBuffer[..result], expect, current, language); + return result; } public override int GetStringTerminatorIndex(ReadOnlySpan data) diff --git a/PKHeX.Core/PKM/PK3.cs b/PKHeX.Core/PKM/PK3.cs index 5e0d599fb..fcb09b98e 100644 --- a/PKHeX.Core/PKM/PK3.cs +++ b/PKHeX.Core/PKM/PK3.cs @@ -374,7 +374,15 @@ public override string GetString(ReadOnlySpan data) public override int LoadString(ReadOnlySpan data, Span destBuffer) => StringConverter3.LoadString(data, destBuffer, Language); public override int SetString(Span destBuffer, ReadOnlySpan value, int maxLength, StringConverterOption option) - => StringConverter3.SetString(destBuffer, value, maxLength, Language, option); + { + int result = StringConverter3.SetString(destBuffer, value, maxLength, Language, option); + if (result == 0 && IsEgg) // Might be the user tried creating a non-JPN egg. Try using the international table (be nice). + result = StringConverter3.SetString(destBuffer, value, maxLength, (int)LanguageID.English, option); + // There are other cases like force-hatching an egg, which will have the wrong OT name encoding, or situations where one language has one but not all. + // Let the user figure it out. + return result; + } + public override int GetStringTerminatorIndex(ReadOnlySpan data) => TrashBytes8.GetTerminatorIndex(data); public override int GetStringLength(ReadOnlySpan data) diff --git a/PKHeX.Core/PKM/XK3.cs b/PKHeX.Core/PKM/XK3.cs index aab320188..8b1dcdd54 100644 --- a/PKHeX.Core/PKM/XK3.cs +++ b/PKHeX.Core/PKM/XK3.cs @@ -296,10 +296,10 @@ public override int SetString(Span destBuffer, ReadOnlySpan value, i if (current == expect) return StringConverter3GC.SetString(destBuffer, value, maxLength, option); // no remap needed - Span remap = stackalloc byte[destBuffer.Length]; - destBuffer.CopyTo(remap); - StringConverter3GC.RemapGlyphsBetweenRegions3GC(remap, expect, current, language); - return StringConverter3GC.SetString(remap, value, maxLength, option); + // ensure glyphs match the transfer route + var result = StringConverter3GC.SetString(destBuffer, value, maxLength, option); + StringConverter3GC.RemapGlyphsBetweenRegions3GC(destBuffer[..result], expect, current, language); + return result; } public override int GetStringTerminatorIndex(ReadOnlySpan data) diff --git a/PKHeX.WinForms/Controls/PKM Editor/EditPK3.cs b/PKHeX.WinForms/Controls/PKM Editor/EditPK3.cs index 7a814b763..20a76885d 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/EditPK3.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/EditPK3.cs @@ -1,4 +1,4 @@ -using System; +using System; using PKHeX.Core; namespace PKHeX.WinForms.Controls; @@ -10,9 +10,9 @@ private void PopulateFieldsPK3() if (Entity is not G3PKM pk3) throw new FormatException(nameof(Entity)); + LoadMisc3(pk3); LoadMisc1(pk3); LoadMisc2(pk3); - LoadMisc3(pk3); CB_Ability.SelectedIndex = pk3.AbilityBit && CB_Ability.Items.Count > 1 ? 1 : 0; if (pk3 is IShadowCapture s) @@ -27,9 +27,9 @@ private G3PKM PreparePK3() if (Entity is not G3PKM pk3) throw new FormatException(nameof(Entity)); + SaveMisc3(pk3); // save Language first so that Nickname/etc encode properly + SaveMisc2(pk3); // save IsEgg prior to setting ^ SaveMisc1(pk3); - SaveMisc2(pk3); - SaveMisc3(pk3); pk3.AbilityBit = CB_Ability.SelectedIndex != 0; if (Entity is IShadowCapture ck3)