mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-30 20:49:25 -05:00
SK2 coerce to load to a hint language
This format won't be supported cleanly, so let's just try to allow language detection to work as best as it can without storing metadata in the SK2 bytes.
This commit is contained in:
@@ -12,7 +12,8 @@ public sealed class SK2 : GBPKM, ICaughtData2
|
||||
|
||||
public override int SIZE_PARTY => PokeCrypto.SIZE_2STADIUM;
|
||||
public override int SIZE_STORED => PokeCrypto.SIZE_2STADIUM;
|
||||
public override bool Japanese { get; }
|
||||
private bool _jp { get; set; }
|
||||
public override bool Japanese => _jp;
|
||||
public override bool Korean => false;
|
||||
private const int StringLength = 12;
|
||||
|
||||
@@ -22,11 +23,11 @@ public sealed class SK2 : GBPKM, ICaughtData2
|
||||
|
||||
public SK2(bool jp = false) : base(PokeCrypto.SIZE_2STADIUM)
|
||||
{
|
||||
Japanese = jp;
|
||||
_jp = jp;
|
||||
}
|
||||
|
||||
public SK2(byte[] data) : this(data, IsJapanese(data)) { }
|
||||
public SK2(byte[] data, bool jp) : base(data) => Japanese = jp;
|
||||
public SK2(byte[] data, bool jp) : base(data) => _jp = jp;
|
||||
|
||||
public override PKM Clone() => new SK2((byte[])Data.Clone(), Japanese)
|
||||
{
|
||||
@@ -175,8 +176,25 @@ public PK2 ConvertToPK2()
|
||||
};
|
||||
}
|
||||
|
||||
private static bool IsJapanese(byte[] data) => StringConverter12.GetIsG1Japanese(data, 0x24, StringLength) && StringConverter12.GetIsG1Japanese(data, 0x30, StringLength);
|
||||
private static bool IsJapanese(byte[] data)
|
||||
{
|
||||
if (!StringConverter12.GetIsG1Japanese(data, 0x24, StringLength))
|
||||
return false;
|
||||
if (!StringConverter12.GetIsG1Japanese(data, 0x30, StringLength))
|
||||
return false;
|
||||
|
||||
for (int i = 6; i < 0xC; i++)
|
||||
{
|
||||
if (data[0x24 + i] != 0 && data[0x24 + i] != StringConverter12.G1TerminatorCode)
|
||||
return false;
|
||||
if (data[0x30 + i] != 0 && data[0x30 + i] != StringConverter12.G1TerminatorCode)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool IsEnglish(byte[] data) => StringConverter12.GetIsG1English(data, 0x24, StringLength) && StringConverter12.GetIsG1English(data, 0x30, StringLength);
|
||||
public bool IsPossible(bool japanese) => japanese ? IsJapanese(Data) : IsEnglish(Data);
|
||||
public void SwapLanguage() => _jp ^= true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ public static IEnumerable<PKM> GetCompatible(this SaveFile sav, IEnumerable<PKM>
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sav is ILangDeviantSave il && PKMConverter.IsIncompatibleGB(pk, il.Japanese, pk.Japanese))
|
||||
if (sav is ILangDeviantSave il && PKMConverter.IsIncompatibleGB(temp, il.Japanese, pk.Japanese))
|
||||
{
|
||||
c = PKMConverter.GetIncompatibleGBMessage(pk, il.Japanese);
|
||||
Debug.WriteLine(c);
|
||||
|
||||
@@ -10,6 +10,11 @@ private void PopulateFieldsPK2()
|
||||
if (!(Entity is GBPKM pk2) || !(Entity is ICaughtData2 c2))
|
||||
throw new FormatException(nameof(Entity));
|
||||
|
||||
if (Entity is SK2 sk2)
|
||||
{
|
||||
var sav = RequestSaveFile;
|
||||
CoerceStadium2Language(sk2, sav);
|
||||
}
|
||||
LoadMisc1(pk2);
|
||||
LoadMisc2(pk2);
|
||||
|
||||
@@ -25,6 +30,21 @@ private void PopulateFieldsPK2()
|
||||
UpdateStats();
|
||||
}
|
||||
|
||||
private static void CoerceStadium2Language(SK2 sk2, SaveFile sav)
|
||||
{
|
||||
if (sk2.Japanese == (sav.Language == 1))
|
||||
return;
|
||||
|
||||
var la = new LegalityAnalysis(sk2);
|
||||
if (la.Valid || !sk2.IsPossible(sav.Language == 1))
|
||||
return;
|
||||
|
||||
sk2.SwapLanguage();
|
||||
la = new LegalityAnalysis(sk2);
|
||||
if (!la.Valid) // fail
|
||||
sk2.SwapLanguage();
|
||||
}
|
||||
|
||||
private GBPKM PreparePK2()
|
||||
{
|
||||
if (!(Entity is GBPKM pk2) || !(Entity is ICaughtData2 c2))
|
||||
|
||||
@@ -286,7 +286,7 @@ private bool TryLoadFiles(IReadOnlyList<string> files, DragEventArgs e, bool bad
|
||||
if (badDest && (pk.Species == 0 || pk.IsEgg))
|
||||
return false;
|
||||
|
||||
if (sav is ILangDeviantSave il && PKMConverter.IsIncompatibleGB(pk, il.Japanese, pk.Japanese))
|
||||
if (sav is ILangDeviantSave il && PKMConverter.IsIncompatibleGB(temp, il.Japanese, pk.Japanese))
|
||||
{
|
||||
c = PKMConverter.GetIncompatibleGBMessage(pk, il.Japanese);
|
||||
WinFormsUtil.Error(c);
|
||||
|
||||
Reference in New Issue
Block a user