mirror of
https://github.com/Manu098vm/Switch-Gift-Data-Manager.git
synced 2026-07-18 16:31:19 -05:00
Properly handle TID/SID methods on both the WinForm and ConsoleApp projects
This commit is contained in:
parent
bf85d40baf
commit
cfd46b8077
|
|
@ -51,6 +51,30 @@ public static class Program
|
|||
}
|
||||
|
||||
bcat.Sort();
|
||||
|
||||
var methodSelectionInfo = $"{Environment.NewLine}The Pokémon Scarlet & Violet v2.0.1 Update, released on September 13 - 2023, introduced a new TID / SID handling method for Wondercards.{Environment.NewLine}" +
|
||||
$"This Pokémon Gift could be redeemed both before and after the v2.0.1 release, meaning it can be redeemed with either the old or new TID/SID handling method, depending on the redemption date.{Environment.NewLine}" +
|
||||
$"The redemption date can be changed with the homebrew 'switch-time'. If you're not going to use 'switch-time', please select 'After v2.0.1'.";
|
||||
|
||||
foreach (var (i, title) in bcat.GetListNames().Select((title, i) => (i, title)).Where(x => bcat.GetRequiresMethodSelection(x.i)))
|
||||
{
|
||||
var method = 0;
|
||||
while (method is not (1 or 2))
|
||||
{
|
||||
Log($"{Environment.NewLine}[{title}] This Pokémon Gift could be redeemed both before and after the v2.0.1 release. Please select the redemption method you want to use, depending on the Date/Time you'll redeem the gift." +
|
||||
$"{Environment.NewLine}1 - Before v2.0.1" +
|
||||
$"{Environment.NewLine}2 - After v2.0.1" +
|
||||
$"{Environment.NewLine}3 - Info");
|
||||
|
||||
method = int.Parse(Console.ReadLine()!);
|
||||
|
||||
if (method is (1 or 2))
|
||||
bcat.SetIsBefore201(i, method == 1);
|
||||
else
|
||||
Log(methodSelectionInfo);
|
||||
}
|
||||
}
|
||||
|
||||
Log($"{Environment.NewLine}Enter the source (full) path to your dumped BCAT:");
|
||||
var sourcepath = Console.ReadLine()!;
|
||||
if (!CheckValidBcatPath(sourcepath))
|
||||
|
|
|
|||
|
|
@ -130,14 +130,22 @@ public class BCATManager
|
|||
return false;
|
||||
}
|
||||
|
||||
public void SetTIDSID(int index, bool after200)
|
||||
public bool GetIsBefore201(int index)
|
||||
{
|
||||
if (WCList is not null && WCList.Count > 0 && WCList.Count >= index - 1 && index >= 0)
|
||||
if (WCList.ElementAt(index) is WC9 wc9)
|
||||
return wc9.IsBefore201;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SetIsBefore201(int index, bool before201)
|
||||
{
|
||||
if (WCList is not null && WCList.Count > 0 && WCList.Count >= index - 1 && index >= 0)
|
||||
if (WCList.ElementAt(index) is WC9 wc9 && wc9.RequiresMethodSelection)
|
||||
if (after200)
|
||||
wc9.UpdateNewToOldTIDSID();
|
||||
else
|
||||
if (before201)
|
||||
wc9.UpdateOldToNewTIDSID();
|
||||
else
|
||||
wc9.UpdateNewToOldTIDSID();
|
||||
}
|
||||
|
||||
public int GetIndex(ushort wcid)
|
||||
|
|
|
|||
|
|
@ -21,10 +21,12 @@ public class WC9 : Wondercard
|
|||
// Entities with set TID / SID prior to the v2.0.1 game update would've had their TID / SID modified based on the Wondercard ID.
|
||||
private readonly HashSet<ushort> OldGifts = new() { 0024, 0025, 0028, 0501, 0503, 0504, 0505, 0506, 1002, 1003, 1005 };
|
||||
|
||||
// These Gifts (Birthday Flabébé, Glaseado Cetitan) could be obtained both before and after the v2.0.1 game update.
|
||||
private readonly HashSet<ushort> MixedGifts = new() { 0001, 1524 };
|
||||
// These Gifts (Birthday Flabébé, Glaseado Cetitan, Home Gifts) could be obtained both before and after the v2.0.1 game update.
|
||||
private readonly HashSet<ushort> MixedGifts = new() { 0001, 1524, 9021, 9022, 9023 };
|
||||
public bool RequiresMethodSelection { get => MixedGifts.Contains(WCID); }
|
||||
|
||||
public bool IsBefore201 { get; set; } = false;
|
||||
|
||||
public WC9(ReadOnlySpan<byte> data) : base(data)
|
||||
{
|
||||
WCID = BinaryPrimitives.ReadUInt16LittleEndian(data[WondercardIDOffset..]);
|
||||
|
|
@ -129,14 +131,22 @@ public class WC9 : Wondercard
|
|||
|
||||
public void UpdateOldToNewTIDSID()
|
||||
{
|
||||
if (IsBefore201)
|
||||
return;
|
||||
|
||||
var FTID = BinaryPrimitives.ReadUInt32LittleEndian(Data.AsSpan(TIDOffset)) - (1000000u * WCID);
|
||||
BinaryPrimitives.WriteUInt32LittleEndian(Data.AsSpan(TIDOffset), FTID);
|
||||
IsBefore201 = true;
|
||||
}
|
||||
|
||||
public void UpdateNewToOldTIDSID()
|
||||
{
|
||||
if (!IsBefore201)
|
||||
return;
|
||||
|
||||
var FTID = BinaryPrimitives.ReadUInt32LittleEndian(Data.AsSpan(TIDOffset));
|
||||
BinaryPrimitives.WriteUInt32LittleEndian(Data.AsSpan(TIDOffset), FTID + (1000000u * WCID));
|
||||
IsBefore201 = false;
|
||||
}
|
||||
|
||||
public override void UpdateChecksum()
|
||||
|
|
|
|||
|
|
@ -204,6 +204,7 @@ public partial class MainWindow : Form
|
|||
var list = GetCurrentList();
|
||||
var wcid = UInt16.Parse(TxtWCID.Text);
|
||||
var repeatable = ChkRepeatable.Checked;
|
||||
var isBefore201 = cmbRedemptionMethod.SelectedIndex == 0;
|
||||
|
||||
if (wcid != list.GetWCID(ListBoxWC.SelectedIndex))
|
||||
{
|
||||
|
|
@ -228,6 +229,12 @@ public partial class MainWindow : Form
|
|||
list.SetIsRepeatable(ListBoxWC.SelectedIndex, repeatable);
|
||||
BtnApply.Enabled = false;
|
||||
}
|
||||
|
||||
if (list.GetRequiresMethodSelection(ListBoxWC.SelectedIndex))
|
||||
{
|
||||
list.SetIsBefore201(ListBoxWC.SelectedIndex, isBefore201);
|
||||
BtnApply.Enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnRemove_Click(object sender, EventArgs e)
|
||||
|
|
@ -305,19 +312,22 @@ public partial class MainWindow : Form
|
|||
|
||||
private void CmbRedemptionMethod_IndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
int newIndex = cmbRedemptionMethod.SelectedIndex;
|
||||
if (newIndex != cmbRedemptionMethod.Tag as int?)
|
||||
if (CurrentGame is Games.SCVI)
|
||||
{
|
||||
if (CurrentGame is Games.SCVI)
|
||||
var list = GetCurrentList();
|
||||
if (list.GetRequiresMethodSelection(ListBoxWC.SelectedIndex))
|
||||
{
|
||||
var list = GetCurrentList();
|
||||
list.SetTIDSID(ListBoxWC.SelectedIndex, newIndex == 1);
|
||||
var newValue = cmbRedemptionMethod.SelectedIndex == 0;
|
||||
var oldValue = list.GetIsBefore201(ListBoxWC.SelectedIndex);
|
||||
|
||||
if (newValue != oldValue)
|
||||
BtnApply.Enabled = true;
|
||||
else
|
||||
BtnApply.Enabled = false;
|
||||
}
|
||||
cmbRedemptionMethod.Tag = newIndex;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ToolTipWcid_Draw(object sender, DrawToolTipEventArgs e)
|
||||
{
|
||||
Point screenPosition = ListBox.MousePosition;
|
||||
|
|
@ -387,8 +397,13 @@ public partial class MainWindow : Form
|
|||
|
||||
TxtWCID.Text = content.ElementAt(0);
|
||||
ChkRepeatable.Checked = list.GetIsRepeatable(index);
|
||||
|
||||
cmbRedemptionMethod.Visible = cmbRedemptionMethod.Enabled = lblRedemptionMethod.Visible
|
||||
= lblRedemptionMethod.Enabled = list.GetRequiresMethodSelection(index);
|
||||
|
||||
if (cmbRedemptionMethod.Enabled)
|
||||
cmbRedemptionMethod.SelectedIndex = list.GetIsBefore201(index) ? 0 : 1;
|
||||
|
||||
EnableContent();
|
||||
}
|
||||
else
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user