diff --git a/Misc/SAV6.cs b/Misc/SAV6.cs index 1e298cb49..244e5350f 100644 --- a/Misc/SAV6.cs +++ b/Misc/SAV6.cs @@ -439,5 +439,29 @@ public void setParty() if (battlemem == 0) BattleBoxLocked = false; } + public void sortBoxes() + { + const int len = 31 * 30; // amount of pk6's in boxes + + // Fetch encrypted box data + byte[][] bdata = new byte[len][]; + for (int i = 0; i < len; i++) + bdata[i] = getData(Box + i * PK6.SIZE_STORED, PK6.SIZE_STORED); + + // Sorting Method: Data will sort empty slots to the end, then from the filled slots eggs will be last, then species will be sorted. + var query = from i in bdata + let p = new PK6(decryptArray(i)) + orderby + p.Species == 0 ascending, + p.IsEgg ascending, + p.Species ascending, + p.IsNicknamed ascending + select i; + byte[][] sorted = query.ToArray(); + + // Write data back + for (int i = 0; i < len; i++) + setData(sorted[i], Box + i * PK6.SIZE_STORED); + } } } diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index 17ffd7492..4694488c1 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -2812,31 +2812,6 @@ private void getBox(object sender, EventArgs e) { setPKXBoxes(); } - private void sortBoxes() - { - const int len = 31*30; // amount of pk6's in boxes - - // Fetch encrypted box data - byte[][] bdata = new byte[len][]; - for (int i = 0; i < len; i++) - bdata[i] = SAV.getData(SAV.Box + i * PK6.SIZE_STORED, PK6.SIZE_STORED); - - // Sorting Method: Data will sort empty slots to the end, then from the filled slots eggs will be last, then species will be sorted. - var query = from i in bdata - let p = new PK6(PKX.decryptArray(i)) orderby - p.Species == 0 ascending, - p.IsEgg ascending, - p.Species ascending, - p.IsNicknamed ascending - select i; - byte[][] sorted = query.ToArray(); - - // Write data back - for (int i = 0; i < len; i++) - SAV.setData(sorted[i], SAV.Box + i * PK6.SIZE_STORED); - - setPKXBoxes(); - } private int DaycareSlot; private void switchDaycare(object sender, EventArgs e)