Save Language first for gen3pkm

So that Nickname encoding can work as expected. Also fixes mainline int<->jpn changed edits

ty rainbowsunsetwaves on discord

Extend the fix to user-created eggs in Gen3 so that the OT name is converted.
This commit is contained in:
Kurt
2025-05-19 22:51:47 -05:00
parent 072dae8d14
commit 064e4293a0
4 changed files with 21 additions and 13 deletions

View File

@@ -293,10 +293,10 @@ public override int SetString(Span<byte> destBuffer, ReadOnlySpan<char> value, i
if (current == expect)
return StringConverter3GC.SetString(destBuffer, value, maxLength, option); // no remap needed
Span<byte> 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<byte> data)

View File

@@ -374,7 +374,15 @@ public override string GetString(ReadOnlySpan<byte> data)
public override int LoadString(ReadOnlySpan<byte> data, Span<char> destBuffer)
=> StringConverter3.LoadString(data, destBuffer, Language);
public override int SetString(Span<byte> destBuffer, ReadOnlySpan<char> 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<byte> data)
=> TrashBytes8.GetTerminatorIndex(data);
public override int GetStringLength(ReadOnlySpan<byte> data)

View File

@@ -296,10 +296,10 @@ public override int SetString(Span<byte> destBuffer, ReadOnlySpan<char> value, i
if (current == expect)
return StringConverter3GC.SetString(destBuffer, value, maxLength, option); // no remap needed
Span<byte> 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<byte> data)

View File

@@ -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)