mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-10-02 19:06:48 -05:00
Set box metadata on write
Fix group export for 1U to exclude the right set of teams 0J now shows the correct amount of boxes & teams (halved)
This commit is contained in:
@@ -83,6 +83,7 @@ private void SetBoxChecksums()
|
||||
{
|
||||
for (int i = 0; i < BoxCount; i++)
|
||||
{
|
||||
SetBoxMetadata(i);
|
||||
var boxOfs = GetBoxOffset(i) - ListHeaderSize;
|
||||
var size = BoxSize - 2;
|
||||
var chk = Checksums.CheckSum16(Data, boxOfs, size);
|
||||
@@ -90,6 +91,23 @@ private void SetBoxChecksums()
|
||||
}
|
||||
}
|
||||
|
||||
private void SetBoxMetadata(int i)
|
||||
{
|
||||
var bdata = GetBoxOffset(i);
|
||||
|
||||
// Set box count
|
||||
int count = 0;
|
||||
for (int s = 0; s < BoxSlotCount; s++)
|
||||
{
|
||||
var rel = bdata + (SIZE_STORED * s);
|
||||
if (Data[rel] != 0) // Species present
|
||||
count++;
|
||||
}
|
||||
|
||||
// Last byte of header
|
||||
Data[bdata - 1] = (byte)count;
|
||||
}
|
||||
|
||||
public override Type PKMType => typeof(PK1);
|
||||
|
||||
protected override PKM GetPKM(byte[] data)
|
||||
@@ -229,9 +247,10 @@ public SlotGroup[] GetRegisteredTeams()
|
||||
if (Japanese)
|
||||
return result;
|
||||
|
||||
var noUnused = new SlotGroup[result.Length - 2];
|
||||
noUnused[0] = result[0];
|
||||
Array.Copy(result, 3, noUnused, 1, result.Length - 3);
|
||||
// Trim out the teams that aren't accessible
|
||||
var noUnused = new SlotGroup[result.Length - (2 * TeamCountU)];
|
||||
Array.Copy(result, 0, noUnused, 0, TeamCountU);
|
||||
Array.Copy(result, 2 * TeamCountU, noUnused, TeamCountU, result.Length - TeamCountU);
|
||||
return noUnused;
|
||||
}
|
||||
|
||||
@@ -252,6 +271,7 @@ public SlotGroup GetTeam(int team)
|
||||
}
|
||||
|
||||
private int BoxSize => Japanese ? BoxSizeJ : BoxSizeU;
|
||||
private int ListHeaderSizeBox => Japanese ? 0x0C : 0x10;
|
||||
private const int BoxSizeJ = 0x0C + (SIZE_PK1J * 30) + ListFooterSize; // 0x558
|
||||
private const int BoxSizeU = 0x10 + (SIZE_PK1U * 20) + 6 + ListFooterSize; // 0x468 (6 bytes alignment)
|
||||
public override int GetBoxOffset(int box) => Box + ListHeaderSize + (box * BoxSize);
|
||||
|
||||
@@ -40,7 +40,7 @@ public override byte[] SetString(string value, int maxLength, int PadToSize = 0,
|
||||
private const int StringLength = 6; // Japanese Only
|
||||
public override int OTLength => StringLength;
|
||||
public override int NickLength => StringLength;
|
||||
public override int BoxCount => 8;
|
||||
public override int BoxCount => 4; // 8 boxes stored sequentially; latter 4 are backups
|
||||
public override int BoxSlotCount => 30;
|
||||
|
||||
public override int MaxMoveID => Legal.MaxMoveID_1;
|
||||
@@ -130,7 +130,7 @@ public SAV1StadiumJ() : base(SaveUtil.SIZE_G1STAD)
|
||||
private const int ListHeaderSize = 0x14;
|
||||
private const int ListFooterSize = 6; // POKE + 2byte checksum
|
||||
|
||||
private const int TeamCount = 32; // todo
|
||||
private const int TeamCount = 16; // 32 teams stored sequentially; latter 16 are backups
|
||||
private const int TeamSizeJ = 0x14 + (SIZE_PK1J * 6) + ListFooterSize; // 0x128
|
||||
public static int GetTeamOffset(int team) => 0 + ListHeaderSize + (team * TeamSizeJ);
|
||||
public static string GetTeamName(int team) => $"Team {team + 1}";
|
||||
|
||||
@@ -81,6 +81,7 @@ private void SetBoxChecksums()
|
||||
{
|
||||
for (int i = 0; i < BoxCount; i++)
|
||||
{
|
||||
SetBoxMetadata(i);
|
||||
var boxOfs = GetBoxOffset(i) - ListHeaderSizeBox;
|
||||
var size = BoxSize - 2;
|
||||
var chk = Checksums.CheckSum16(Data, boxOfs, size);
|
||||
@@ -88,6 +89,33 @@ private void SetBoxChecksums()
|
||||
}
|
||||
}
|
||||
|
||||
private void SetBoxMetadata(int i)
|
||||
{
|
||||
var bdata = GetBoxOffset(i);
|
||||
|
||||
// Set box count
|
||||
int count = 0;
|
||||
for (int s = 0; s < BoxSlotCount; s++)
|
||||
{
|
||||
var rel = bdata + (SIZE_STORED * s);
|
||||
if (Data[rel] != 0) // Species present
|
||||
count++;
|
||||
}
|
||||
|
||||
var boxOfs = bdata - ListHeaderSizeBox;
|
||||
if (Data[boxOfs] == 0)
|
||||
{
|
||||
Data[boxOfs] = 1;
|
||||
Data[boxOfs + 1] = (byte) count;
|
||||
Data[boxOfs + 4] = StringConverter12.G1TerminatorCode;
|
||||
StringConverter12.SetString1("1234", 4, Japanese).CopyTo(Data, boxOfs + 0x10);
|
||||
}
|
||||
else
|
||||
{
|
||||
Data[boxOfs + 1] = (byte) count;
|
||||
}
|
||||
}
|
||||
|
||||
public override Type PKMType => typeof(SK2);
|
||||
protected override PKM GetPKM(byte[] data) => new SK2(data, Japanese);
|
||||
protected override byte[] DecryptPKM(byte[] data) => data;
|
||||
|
||||
Reference in New Issue
Block a user