Handle WCID editing for GiftType9.Pokemon

This commit is contained in:
Manu 2023-06-05 23:56:51 +02:00
parent 32480c8c9b
commit eab6cb1f71
2 changed files with 30 additions and 26 deletions

View File

@ -126,8 +126,28 @@ namespace SwitchGiftDataManager.Core
public override void SetID(ushort wcid)
{
var pkEdited = false;
//Wondercard ID in Gen 9 also influence the TID and SID of Pokémon Entities
if (Type is GiftType9 t9 && t9 is GiftType9.Pokemon)
{
//Old FullTID
var ftid = BinaryPrimitives.ReadUInt32LittleEndian(Data.AsSpan(TIDOffset)) - (0xF4240 * (uint)WCID);
//Recalculate the TID and SID (FullTID) to account for the new Wondercard ID
BinaryPrimitives.WriteUInt32LittleEndian(Data.AsSpan(TIDOffset), ftid + (1000000u * (uint)wcid));
pkEdited = true;
}
//Write the new Wondercard ID
BinaryPrimitives.WriteUInt16LittleEndian(Data.AsSpan(WondercardIDOffset), wcid);
WCID = wcid;
//Reload Pokémon content
if (pkEdited)
Content = GetPokemon();
//Refresh card checksum
UpdateChecksum();
}

View File

@ -199,35 +199,19 @@ namespace SwitchGiftDataManager.WinForm
if (wcid != list.GetWCID(ListBoxWC.SelectedIndex))
{
var proceed = true;
if (CurrentGame is Games.SCVI)
var index = list.GetIndex(wcid);
if (index == -1)
{
var warning = "WARNING\n\n" +
"WCID editings in SV wondercards might impact the entity's TID and SID, resulting in an illegal Pokémon.\n" +
"Do not share Pokémon obtained with the use of edited wondercards.\n" +
"\nDo you want to coninue?";
var disclaimer = MessageBox.Show(warning, "Disclaimer", MessageBoxButtons.YesNo);
if (disclaimer == DialogResult.No)
proceed = false;
list.SetWCID(ListBoxWC.SelectedIndex, wcid);
list.Sort();
UpdateWCList();
ListBoxWC.SelectedIndex = list.GetIndex(wcid);
BtnApply.Enabled = false;
}
if (proceed)
else
{
var index = list.GetIndex(wcid);
if (index == -1)
{
list.SetWCID(ListBoxWC.SelectedIndex, wcid);
list.Sort();
UpdateWCList();
ListBoxWC.SelectedIndex = list.GetIndex(wcid);
BtnApply.Enabled = false;
}
else
{
MessageBox.Show($"WCID {wcid} already exists.");
return;
}
MessageBox.Show($"WCID {wcid} already exists.");
return;
}
}