Add batrev party viewing/handling

ezpz

party 4 bytes at end:
pkm, 0 (b) party index (b), 0x8000 (be u16)

not sure if there's a better way to detect party count...
This commit is contained in:
Kurt 2018-05-19 14:42:21 -07:00
parent a7f9f69b02
commit 047272c2ba
2 changed files with 39 additions and 15 deletions

View file

@ -10,7 +10,7 @@ namespace PKHeX.Core
{ {
0x42, 0x43, 0x5E, 0x63, 0x64, 0x65, 0x66, 0x67, 0x87 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 SIZE_STORED => PKX.SIZE_4STORED;
public override int Format => 4; public override int Format => 4;
public override PersonalInfo PersonalInfo => PersonalTable.HGSS[Species]; public override PersonalInfo PersonalInfo => PersonalTable.HGSS[Species];
@ -29,13 +29,13 @@ namespace PKHeX.Core
RefreshChecksum(); RefreshChecksum();
if (Valid && Sanity == 0) if (Valid && Sanity == 0)
Sanity = 0x4000; Sanity = 0x4000;
if (Data.Length != SIZE_PARTY) SetStats(GetStats(PersonalInfo));
Array.Resize(ref Data, SIZE_PARTY);
} }
public BK4() public BK4()
{ {
Data = new byte[SIZE_PARTY]; Data = new byte[SIZE_PARTY];
Sanity = 0x4000; Sanity = 0x4000;
SetStats(GetStats(PersonalInfo));
} }
public override PKM Clone() => new BK4((byte[])Encrypt().Clone(), Identifier); public override PKM Clone() => new BK4((byte[])Encrypt().Clone(), Identifier);
@ -322,14 +322,15 @@ namespace PKHeX.Core
// Unused 0x87 // Unused 0x87
#endregion #endregion
public override int Stat_Level { get => Data[0x8C]; set => Data[0x8C] = (byte)value; } // Not stored
public override int Stat_HPCurrent { get => BigEndian.ToUInt16(Data, 0x8E); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x8E); } public override int Stat_Level { get => CurrentLevel; set {} }
public override int Stat_HPMax { get => BigEndian.ToUInt16(Data, 0x90); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x90); } public override int Stat_HPCurrent { get; set; }
public override int Stat_ATK { get => BigEndian.ToUInt16(Data, 0x92); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x92); } public override int Stat_HPMax { get; set; }
public override int Stat_DEF { get => BigEndian.ToUInt16(Data, 0x94); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x94); } public override int Stat_ATK { get; set; }
public override int Stat_SPE { get => BigEndian.ToUInt16(Data, 0x96); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x96); } public override int Stat_DEF { get; set; }
public override int Stat_SPA { get => BigEndian.ToUInt16(Data, 0x98); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x98); } public override int Stat_SPE { get; set; }
public override int Stat_SPD { get => BigEndian.ToUInt16(Data, 0x9A); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x9A); } public override int Stat_SPA { get; set; }
public override int Stat_SPD { get; set; }
// Methods // Methods
protected override ushort CalculateChecksum() protected override ushort CalculateChecksum()

View file

@ -75,11 +75,17 @@ namespace PKHeX.Core
{ {
get => _currentSlot; get => _currentSlot;
// 4 save slots, data reading depends on current slot // 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; 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 PKM BlankPKM => new BK4();
public override Type PKMType => typeof(BK4); public override Type PKMType => typeof(BK4);
@ -98,7 +104,19 @@ namespace PKHeX.Core
public override int MaxMoney => 999999; public override int MaxMoney => 999999;
public override int BoxCount => 18; 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 // Checksums
protected override void SetChecksums() protected override void SetChecksums()
@ -125,7 +143,7 @@ namespace PKHeX.Core
// Storage // Storage
public override int GetPartyOffset(int slot) // TODO public override int GetPartyOffset(int slot) // TODO
{ {
return -1; return Party + SIZE_PARTY * slot;
} }
public override int GetBoxOffset(int box) public override int GetBoxOffset(int box)
{ {
@ -157,6 +175,11 @@ namespace PKHeX.Core
pkm.RefreshChecksum(); pkm.RefreshChecksum();
} }
protected override void SetPartyValues(PKM pkm, bool isParty)
{
pkm.Sanity = (ushort)(isParty ? 0xC000 : 0x4000);
}
public static byte[] DecryptPBRSaveData(byte[] input) public static byte[] DecryptPBRSaveData(byte[] input)
{ {
byte[] output = new byte[input.Length]; byte[] output = new byte[input.Length];