diff --git a/PKHeX.Core/PKM/BK4.cs b/PKHeX.Core/PKM/BK4.cs index a87397e46..aca2a8fd5 100644 --- a/PKHeX.Core/PKM/BK4.cs +++ b/PKHeX.Core/PKM/BK4.cs @@ -10,7 +10,7 @@ public sealed class BK4 : _K4 { 0x42, 0x43, 0x5E, 0x63, 0x64, 0x65, 0x66, 0x67, 0x87 }; - public override int SIZE_PARTY => PKX.SIZE_4PARTY; + public override int SIZE_PARTY => PKX.SIZE_4STORED; public override int SIZE_STORED => PKX.SIZE_4STORED; public override int Format => 4; public override PersonalInfo PersonalInfo => PersonalTable.HGSS[Species]; @@ -29,13 +29,13 @@ public BK4(byte[] decryptedData = null, string ident = null) RefreshChecksum(); if (Valid && Sanity == 0) Sanity = 0x4000; - if (Data.Length != SIZE_PARTY) - Array.Resize(ref Data, SIZE_PARTY); + SetStats(GetStats(PersonalInfo)); } public BK4() { Data = new byte[SIZE_PARTY]; Sanity = 0x4000; + SetStats(GetStats(PersonalInfo)); } public override PKM Clone() => new BK4((byte[])Encrypt().Clone(), Identifier); @@ -322,14 +322,15 @@ public override int Ball // Unused 0x87 #endregion - public override int Stat_Level { get => Data[0x8C]; set => Data[0x8C] = (byte)value; } - public override int Stat_HPCurrent { get => BigEndian.ToUInt16(Data, 0x8E); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x8E); } - public override int Stat_HPMax { get => BigEndian.ToUInt16(Data, 0x90); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x90); } - public override int Stat_ATK { get => BigEndian.ToUInt16(Data, 0x92); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x92); } - public override int Stat_DEF { get => BigEndian.ToUInt16(Data, 0x94); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x94); } - public override int Stat_SPE { get => BigEndian.ToUInt16(Data, 0x96); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x96); } - public override int Stat_SPA { get => BigEndian.ToUInt16(Data, 0x98); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x98); } - public override int Stat_SPD { get => BigEndian.ToUInt16(Data, 0x9A); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x9A); } + // Not stored + public override int Stat_Level { get => CurrentLevel; set {} } + public override int Stat_HPCurrent { get; set; } + public override int Stat_HPMax { get; set; } + public override int Stat_ATK { get; set; } + public override int Stat_DEF { get; set; } + public override int Stat_SPE { get; set; } + public override int Stat_SPA { get; set; } + public override int Stat_SPD { get; set; } // Methods protected override ushort CalculateChecksum() diff --git a/PKHeX.Core/Saves/SAV4BR.cs b/PKHeX.Core/Saves/SAV4BR.cs index 2094b8c8d..4efe462b8 100644 --- a/PKHeX.Core/Saves/SAV4BR.cs +++ b/PKHeX.Core/Saves/SAV4BR.cs @@ -75,11 +75,17 @@ public int CurrentSlot { get => _currentSlot; // 4 save slots, data reading depends on current slot - set => Box = 0x978 + 0x6FF00 * (_currentSlot = value); + set + { + _currentSlot = value; + var ofs = 0x6FF00 * _currentSlot; + Box = ofs + 0x978; + Party = ofs + 0x65F48; // near the end of the slot chunk + } } public override int SIZE_STORED => PKX.SIZE_4STORED; - protected override int SIZE_PARTY => PKX.SIZE_4PARTY - 0x10; // PBR has a party + protected override int SIZE_PARTY => PKX.SIZE_4STORED + 4; public override PKM BlankPKM => new BK4(); public override Type PKMType => typeof(BK4); @@ -98,7 +104,19 @@ public int CurrentSlot public override int MaxMoney => 999999; public override int BoxCount => 18; - public override bool HasParty => false; + + public override int PartyCount + { + get + { + int ctr = 0; + for (int i = 0; i < 6; i++) + if (Data[GetPartyOffset(i) + 4] != 0) // sanity + ctr += 1; + return ctr; + } + protected set { } + } // Checksums protected override void SetChecksums() @@ -125,7 +143,7 @@ public static bool IsChecksumsValid(byte[] sav) // Storage public override int GetPartyOffset(int slot) // TODO { - return -1; + return Party + SIZE_PARTY * slot; } public override int GetBoxOffset(int box) { @@ -157,6 +175,11 @@ protected override void SetPKM(PKM pkm) pkm.RefreshChecksum(); } + protected override void SetPartyValues(PKM pkm, bool isParty) + { + pkm.Sanity = (ushort)(isParty ? 0xC000 : 0x4000); + } + public static byte[] DecryptPBRSaveData(byte[] input) { byte[] output = new byte[input.Length];