2016-08-27 11:33:21 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-08-27 11:33:21 +00:00
|
|
|
|
{
|
|
|
|
|
public sealed class SAV1 : SaveFile
|
|
|
|
|
{
|
2016-09-04 22:54:16 +00:00
|
|
|
|
public override string BAKName => $"{FileName} [{OT} ({Version}) - {PlayTimeString}].bak";
|
2016-10-17 14:49:40 +00:00
|
|
|
|
public override string Filter => "SAV File|*.sav|All Files|*.*";
|
2016-08-27 11:33:21 +00:00
|
|
|
|
public override string Extension => ".sav";
|
2017-01-05 06:22:50 +00:00
|
|
|
|
public override string[] PKMExtensions => PKM.Extensions.Where(f =>
|
|
|
|
|
{
|
|
|
|
|
int gen = f.Last() - 0x30;
|
|
|
|
|
return 1 <= gen && gen <= 2;
|
|
|
|
|
}).ToArray();
|
2016-08-27 11:33:21 +00:00
|
|
|
|
|
2017-01-15 00:43:16 +00:00
|
|
|
|
public SAV1(byte[] data = null, GameVersion versionOverride = GameVersion.Any)
|
2016-08-27 11:33:21 +00:00
|
|
|
|
{
|
|
|
|
|
Data = data == null ? new byte[SaveUtil.SIZE_G1RAW] : (byte[])data.Clone();
|
|
|
|
|
BAK = (byte[])Data.Clone();
|
|
|
|
|
Exportable = !Data.SequenceEqual(new byte[Data.Length]);
|
|
|
|
|
|
2017-01-15 00:43:16 +00:00
|
|
|
|
if (data == null)
|
|
|
|
|
Version = GameVersion.RBY;
|
|
|
|
|
else if (versionOverride != GameVersion.Any)
|
|
|
|
|
Version = versionOverride;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
else Version = SaveUtil.GetIsG1SAV(Data);
|
2016-08-27 11:33:21 +00:00
|
|
|
|
if (Version == GameVersion.Invalid)
|
|
|
|
|
return;
|
2017-09-24 23:58:19 +00:00
|
|
|
|
if (Starter != 0)
|
2017-10-23 00:11:48 +00:00
|
|
|
|
Version = Yellow ? GameVersion.YW : GameVersion.RB;
|
2016-08-27 11:33:21 +00:00
|
|
|
|
|
2016-08-28 10:18:22 +00:00
|
|
|
|
Box = Data.Length;
|
|
|
|
|
Array.Resize(ref Data, Data.Length + SIZE_RESERVED);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Party = GetPartyOffset(0);
|
2016-08-27 11:33:21 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Japanese = SaveUtil.GetIsG1SAVJ(Data);
|
2017-02-13 06:31:31 +00:00
|
|
|
|
Personal = PersonalTable.Y;
|
2016-08-27 11:33:21 +00:00
|
|
|
|
|
2016-08-28 10:18:22 +00:00
|
|
|
|
// Stash boxes after the save file's end.
|
2016-08-29 20:27:17 +00:00
|
|
|
|
byte[] TempBox = new byte[SIZE_STOREDBOX];
|
2016-08-28 10:18:22 +00:00
|
|
|
|
for (int i = 0; i < BoxCount; i++)
|
|
|
|
|
{
|
|
|
|
|
if (i < BoxCount / 2)
|
|
|
|
|
Array.Copy(Data, 0x4000 + i * TempBox.Length, TempBox, 0, TempBox.Length);
|
|
|
|
|
else
|
|
|
|
|
Array.Copy(Data, 0x6000 + (i - BoxCount / 2) * TempBox.Length, TempBox, 0, TempBox.Length);
|
|
|
|
|
PokemonList1 PL1 = new PokemonList1(TempBox, Japanese ? PokemonList1.CapacityType.StoredJP : PokemonList1.CapacityType.Stored, Japanese);
|
|
|
|
|
for (int j = 0; j < PL1.Pokemon.Length; j++)
|
|
|
|
|
{
|
|
|
|
|
if (j < PL1.Count)
|
|
|
|
|
{
|
|
|
|
|
byte[] pkDat = new PokemonList1(PL1[j]).GetBytes();
|
|
|
|
|
pkDat.CopyTo(Data, Data.Length - SIZE_RESERVED + i * SIZE_BOX + j * SIZE_STORED);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
byte[] pkDat = new byte[PokemonList1.GetDataLength(PokemonList1.CapacityType.Single, Japanese)];
|
|
|
|
|
pkDat.CopyTo(Data, Data.Length - SIZE_RESERVED + i * SIZE_BOX + j * SIZE_STORED);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Array.Copy(Data, Japanese ? 0x302D : 0x30C0, TempBox, 0, TempBox.Length);
|
|
|
|
|
PokemonList1 curBoxPL = new PokemonList1(TempBox, Japanese ? PokemonList1.CapacityType.StoredJP : PokemonList1.CapacityType.Stored, Japanese);
|
|
|
|
|
for (int i = 0; i < curBoxPL.Pokemon.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (i < curBoxPL.Count)
|
|
|
|
|
{
|
|
|
|
|
byte[] pkDat = new PokemonList1(curBoxPL[i]).GetBytes();
|
|
|
|
|
pkDat.CopyTo(Data, Data.Length - SIZE_RESERVED + CurrentBox * SIZE_BOX + i * SIZE_STORED);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
byte[] pkDat = new byte[PokemonList1.GetDataLength(PokemonList1.CapacityType.Single, Japanese)];
|
|
|
|
|
pkDat.CopyTo(Data, Data.Length - SIZE_RESERVED + CurrentBox * SIZE_BOX + i * SIZE_STORED);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
byte[] TempParty = new byte[PokemonList1.GetDataLength(PokemonList1.CapacityType.Party, Japanese)];
|
|
|
|
|
Array.Copy(Data, Japanese ? 0x2ED5 : 0x2F2C, TempParty, 0, TempParty.Length);
|
|
|
|
|
PokemonList1 partyList = new PokemonList1(TempParty, PokemonList1.CapacityType.Party, Japanese);
|
|
|
|
|
for (int i = 0; i < partyList.Pokemon.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (i < partyList.Count)
|
|
|
|
|
{
|
|
|
|
|
byte[] pkDat = new PokemonList1(partyList[i]).GetBytes();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
pkDat.CopyTo(Data, GetPartyOffset(i));
|
2016-08-28 10:18:22 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
byte[] pkDat = new byte[PokemonList1.GetDataLength(PokemonList1.CapacityType.Single, Japanese)];
|
2017-06-18 01:37:19 +00:00
|
|
|
|
pkDat.CopyTo(Data, GetPartyOffset(i));
|
2016-08-28 10:18:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-29 20:27:17 +00:00
|
|
|
|
byte[] rawDC = new byte[0x38];
|
|
|
|
|
Array.Copy(Data, Japanese ? 0x2CA7 : 0x2CF4, rawDC, 0, rawDC.Length);
|
|
|
|
|
byte[] TempDaycare = new byte[PokemonList1.GetDataLength(PokemonList1.CapacityType.Single, Japanese)];
|
|
|
|
|
TempDaycare[0] = rawDC[0];
|
|
|
|
|
Array.Copy(rawDC, 1, TempDaycare, 2 + 1 + PKX.SIZE_1PARTY + StringLength, StringLength);
|
|
|
|
|
Array.Copy(rawDC, 1 + StringLength, TempDaycare, 2 + 1 + PKX.SIZE_1PARTY, StringLength);
|
|
|
|
|
Array.Copy(rawDC, 1 + 2 * StringLength, TempDaycare, 2 + 1, PKX.SIZE_1STORED);
|
|
|
|
|
PokemonList1 daycareList = new PokemonList1(TempDaycare, PokemonList1.CapacityType.Single, Japanese);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
daycareList.GetBytes().CopyTo(Data, GetPartyOffset(7));
|
2017-09-24 05:13:48 +00:00
|
|
|
|
Daycare = GetPartyOffset(7);
|
|
|
|
|
|
2017-09-24 23:36:51 +00:00
|
|
|
|
EventFlag = Japanese ? 0x29E9 : 0x29F3;
|
|
|
|
|
ObjectSpawnFlags = Japanese ? 0x2848 : 0x2852; // 2 bytes after Coin
|
2016-08-28 10:18:22 +00:00
|
|
|
|
|
2016-08-30 00:48:05 +00:00
|
|
|
|
// Enable Pokedex editing
|
|
|
|
|
PokeDex = 0;
|
|
|
|
|
|
2016-08-27 11:33:21 +00:00
|
|
|
|
if (!Exportable)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
ClearBoxes();
|
2016-08-27 11:33:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-24 05:13:48 +00:00
|
|
|
|
// Event Flags
|
|
|
|
|
protected override int EventFlagMax => EventFlag > 0 ? 0xA00 : int.MinValue; // 320 * 8
|
|
|
|
|
protected override int EventConstMax => 0;
|
2017-09-24 23:36:51 +00:00
|
|
|
|
private readonly int ObjectSpawnFlags;
|
2017-09-24 05:13:48 +00:00
|
|
|
|
|
2016-08-28 10:18:22 +00:00
|
|
|
|
private const int SIZE_RESERVED = 0x8000; // unpacked box data
|
2017-06-18 01:37:19 +00:00
|
|
|
|
|
|
|
|
|
protected override byte[] Write(bool DSV)
|
2016-08-27 11:33:21 +00:00
|
|
|
|
{
|
2016-08-29 20:27:17 +00:00
|
|
|
|
for (int i = 0; i < BoxCount; i++)
|
|
|
|
|
{
|
|
|
|
|
PokemonList1 boxPL = new PokemonList1(Japanese ? PokemonList1.CapacityType.StoredJP : PokemonList1.CapacityType.Stored, Japanese);
|
|
|
|
|
int slot = 0;
|
|
|
|
|
for (int j = 0; j < boxPL.Pokemon.Length; j++)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PK1 boxPK = (PK1) GetPKM(GetData(GetBoxOffset(i) + j*SIZE_STORED, SIZE_STORED));
|
2016-08-29 20:27:17 +00:00
|
|
|
|
if (boxPK.Species > 0)
|
|
|
|
|
boxPL[slot++] = boxPK;
|
|
|
|
|
}
|
|
|
|
|
if (i < BoxCount / 2)
|
|
|
|
|
boxPL.GetBytes().CopyTo(Data, 0x4000 + i * SIZE_STOREDBOX);
|
|
|
|
|
else
|
|
|
|
|
boxPL.GetBytes().CopyTo(Data, 0x6000 + (i - BoxCount / 2) * SIZE_STOREDBOX);
|
|
|
|
|
if (i == CurrentBox)
|
|
|
|
|
boxPL.GetBytes().CopyTo(Data, Japanese ? 0x302D : 0x30C0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PokemonList1 partyPL = new PokemonList1(PokemonList1.CapacityType.Party, Japanese);
|
|
|
|
|
int pSlot = 0;
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PK1 partyPK = (PK1)GetPKM(GetData(GetPartyOffset(i), SIZE_STORED));
|
2016-08-29 20:27:17 +00:00
|
|
|
|
if (partyPK.Species > 0)
|
|
|
|
|
partyPL[pSlot++] = partyPK;
|
|
|
|
|
}
|
|
|
|
|
partyPL.GetBytes().CopyTo(Data, Japanese ? 0x2ED5 : 0x2F2C);
|
|
|
|
|
|
|
|
|
|
// Daycare is read-only, but in case it ever becomes editable, copy it back in.
|
2017-06-18 01:37:19 +00:00
|
|
|
|
byte[] rawDC = GetData(GetDaycareSlotOffset(loc: 0, slot: 0), SIZE_STORED);
|
2016-08-29 20:27:17 +00:00
|
|
|
|
byte[] dc = new byte[1 + 2*StringLength + PKX.SIZE_1STORED];
|
|
|
|
|
dc[0] = rawDC[0];
|
|
|
|
|
Array.Copy(rawDC, 2 + 1 + PKX.SIZE_1PARTY + StringLength, dc, 1, StringLength);
|
|
|
|
|
Array.Copy(rawDC, 2 + 1 + PKX.SIZE_1PARTY, dc, 1 + StringLength, StringLength);
|
|
|
|
|
Array.Copy(rawDC, 2 + 1, dc, 1 + 2*StringLength, PKX.SIZE_1STORED);
|
|
|
|
|
dc.CopyTo(Data, Japanese ? 0x2CA7 : 0x2CF4);
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetChecksums();
|
2016-08-29 20:27:17 +00:00
|
|
|
|
byte[] outData = new byte[Data.Length - SIZE_RESERVED];
|
|
|
|
|
Array.Copy(Data, outData, outData.Length);
|
|
|
|
|
return outData;
|
2016-08-27 11:33:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Configuration
|
2016-09-11 21:54:20 +00:00
|
|
|
|
public override SaveFile Clone() { return new SAV1(Write(DSV: false)); }
|
2016-08-27 11:33:21 +00:00
|
|
|
|
|
2016-08-28 10:18:22 +00:00
|
|
|
|
public override int SIZE_STORED => Japanese ? PKX.SIZE_1JLIST : PKX.SIZE_1ULIST;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected override int SIZE_PARTY => Japanese ? PKX.SIZE_1JLIST : PKX.SIZE_1ULIST;
|
2017-01-05 06:22:50 +00:00
|
|
|
|
private int SIZE_BOX => BoxSlotCount*SIZE_STORED;
|
|
|
|
|
private int SIZE_STOREDBOX => PokemonList1.GetDataLength(Japanese ? PokemonList1.CapacityType.StoredJP : PokemonList1.CapacityType.Stored, Japanese);
|
2016-08-29 20:27:17 +00:00
|
|
|
|
|
2016-08-28 10:18:22 +00:00
|
|
|
|
public override PKM BlankPKM => new PK1(null, null, Japanese);
|
2016-09-26 23:14:11 +00:00
|
|
|
|
public override Type PKMType => typeof(PK1);
|
2016-08-27 11:33:21 +00:00
|
|
|
|
|
2017-01-27 03:18:20 +00:00
|
|
|
|
public override int MaxMoveID => Legal.MaxMoveID_1;
|
2016-10-24 04:59:27 +00:00
|
|
|
|
public override int MaxSpeciesID => Legal.MaxSpeciesID_1;
|
2017-01-27 03:18:20 +00:00
|
|
|
|
public override int MaxAbilityID => Legal.MaxAbilityID_1;
|
|
|
|
|
public override int MaxItemID => Legal.MaxItemID_1;
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int MaxBallID => 0; // unused
|
|
|
|
|
public override int MaxGameID => 99; // unused
|
2016-09-09 03:20:32 +00:00
|
|
|
|
public override int MaxMoney => 999999;
|
2017-02-04 20:13:54 +00:00
|
|
|
|
public override int MaxCoins => 9999;
|
2016-08-27 11:33:21 +00:00
|
|
|
|
|
|
|
|
|
public override int BoxCount => Japanese ? 8 : 12;
|
|
|
|
|
public override int MaxEV => 65535;
|
2016-08-28 10:18:22 +00:00
|
|
|
|
public override int MaxIV => 15;
|
2016-08-27 11:33:21 +00:00
|
|
|
|
public override int Generation => 1;
|
|
|
|
|
protected override int GiftCountMax => 0;
|
2016-09-04 22:44:54 +00:00
|
|
|
|
public override int OTLength => Japanese ? 5 : 7;
|
2016-08-27 11:33:21 +00:00
|
|
|
|
public override int NickLength => Japanese ? 5 : 10;
|
2016-08-31 05:58:39 +00:00
|
|
|
|
public override int BoxSlotCount => Japanese ? 30 : 20;
|
2016-08-27 11:33:21 +00:00
|
|
|
|
|
|
|
|
|
public override bool HasParty => true;
|
2016-08-31 05:58:39 +00:00
|
|
|
|
private int StringLength => Japanese ? PK1.STRLEN_J : PK1.STRLEN_U;
|
2016-08-27 11:33:21 +00:00
|
|
|
|
|
|
|
|
|
// Checksums
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected override void SetChecksums()
|
2016-08-27 11:33:21 +00:00
|
|
|
|
{
|
|
|
|
|
int CHECKSUM_OFS = Japanese ? 0x3594 : 0x3523;
|
|
|
|
|
Data[CHECKSUM_OFS] = 0;
|
|
|
|
|
uint chksum = 0;
|
|
|
|
|
for (int i = 0x2598; i < CHECKSUM_OFS; i++)
|
|
|
|
|
{
|
|
|
|
|
chksum += Data[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
chksum = ~chksum;
|
|
|
|
|
chksum &= 0xFF;
|
|
|
|
|
|
|
|
|
|
Data[CHECKSUM_OFS] = (byte)chksum;
|
|
|
|
|
}
|
|
|
|
|
public override bool ChecksumsValid
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
int CHECKSUM_OFS = Japanese ? 0x3594 : 0x3523;
|
2016-09-22 04:08:09 +00:00
|
|
|
|
byte temp = Data[CHECKSUM_OFS]; // cache current chk
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetChecksums(); // chksum is recalculated (after being set to 0 to perform check)
|
2016-09-22 04:08:09 +00:00
|
|
|
|
byte chk = Data[CHECKSUM_OFS]; // correct checksum
|
|
|
|
|
Data[CHECKSUM_OFS] = temp; // restore old chk
|
|
|
|
|
return temp == chk;
|
2016-08-27 11:33:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-31 05:58:39 +00:00
|
|
|
|
public override string ChecksumInfo => ChecksumsValid ? "Checksum valid." : "Checksum invalid";
|
2016-08-27 11:33:21 +00:00
|
|
|
|
|
|
|
|
|
// Trainer Info
|
|
|
|
|
public override GameVersion Version { get; protected set; }
|
|
|
|
|
|
|
|
|
|
public override string OT
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
get => GetString(0x2598, OTLength);
|
|
|
|
|
set => SetString(value, OTLength).CopyTo(Data, 0x2598);
|
2016-08-27 11:33:21 +00:00
|
|
|
|
}
|
|
|
|
|
public override int Gender
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => 0;
|
2016-08-27 11:33:21 +00:00
|
|
|
|
set { }
|
|
|
|
|
}
|
|
|
|
|
public override ushort TID
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BigEndian.ToUInt16(Data, Japanese ? 0x25FB : 0x2605);
|
|
|
|
|
set => BigEndian.GetBytes(value).CopyTo(Data, Japanese ? 0x25FB : 0x2605);
|
2016-08-27 11:33:21 +00:00
|
|
|
|
}
|
|
|
|
|
public override ushort SID
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => 0;
|
2016-08-27 11:33:21 +00:00
|
|
|
|
set { }
|
|
|
|
|
}
|
2017-01-05 09:14:19 +00:00
|
|
|
|
|
2017-09-24 23:58:19 +00:00
|
|
|
|
public bool Yellow => Starter == 0x54; // Pikachu
|
|
|
|
|
public int Starter => Data[Japanese ? 0x29B9 : 0x29C3];
|
2017-01-05 09:14:19 +00:00
|
|
|
|
public byte PikaFriendship
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[Japanese ? 0x2712 : 0x271C];
|
|
|
|
|
set => Data[Japanese ? 0x2712 : 0x271C] = value;
|
2017-01-05 09:14:19 +00:00
|
|
|
|
}
|
2016-08-27 11:33:21 +00:00
|
|
|
|
public override int PlayedHours
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt16(Data, Japanese ? 0x2CA0 : 0x2CED);
|
|
|
|
|
set => BitConverter.GetBytes((ushort)value).CopyTo(Data, Japanese ? 0x2CA0 : 0x2CED);
|
2016-08-27 11:33:21 +00:00
|
|
|
|
}
|
|
|
|
|
public override int PlayedMinutes
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[Japanese ? 0x2CA2 : 0x2CEF];
|
|
|
|
|
set => Data[Japanese ? 0x2CA2 : 0x2CEF] = (byte)value;
|
2016-08-27 11:33:21 +00:00
|
|
|
|
}
|
|
|
|
|
public override int PlayedSeconds
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[Japanese ? 0x2CA3 : 0x2CF0];
|
|
|
|
|
set => Data[Japanese ? 0x2CA3 : 0x2CF0] = (byte)value;
|
2016-08-27 11:33:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-30 00:48:05 +00:00
|
|
|
|
public int Badges
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[Japanese ? 0x25F8 : 0x2602];
|
2016-08-30 00:48:05 +00:00
|
|
|
|
set { if (value < 0) return; Data[Japanese ? 0x25F8 : 0x2602] = (byte)value; }
|
|
|
|
|
}
|
|
|
|
|
private byte Options
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[Japanese ? 0x25F7 : 0x2601];
|
|
|
|
|
set => Data[Japanese ? 0x25F7 : 0x2601] = value;
|
2016-08-30 00:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
public bool BattleEffects
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => (Options & 0x80) == 0;
|
|
|
|
|
set => Options = (byte)((Options & 0x7F) | (value ? 0 : 0x80));
|
2016-08-30 00:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
public bool BattleStyleSwitch
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => (Options & 0x40) == 0;
|
|
|
|
|
set => Options = (byte)((Options & 0xBF) | (value ? 0 : 0x40));
|
2016-08-30 00:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
public int Sound
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => (Options & 0x30) >> 4;
|
2016-08-30 00:48:05 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
var new_sound = value;
|
|
|
|
|
if (new_sound > 3)
|
|
|
|
|
new_sound = 3;
|
|
|
|
|
if (new_sound < 0)
|
|
|
|
|
new_sound = 0;
|
|
|
|
|
Options = (byte)((Options & 0xCF) | (new_sound << 4));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public int TextSpeed
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Options & 0x7;
|
2016-08-30 00:48:05 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
var new_speed = value;
|
|
|
|
|
if (new_speed > 7)
|
|
|
|
|
new_speed = 7;
|
|
|
|
|
if (new_speed < 0)
|
|
|
|
|
new_speed = 0;
|
|
|
|
|
Options = (byte)((Options & 0xF8) | new_speed);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-27 11:33:21 +00:00
|
|
|
|
public override uint Money
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => (uint)BigEndian.BCDToInt32(Data, Japanese ? 0x25EE : 0x25F3, 3);
|
2016-08-27 11:33:21 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-02-08 23:51:18 +00:00
|
|
|
|
value = (uint)Math.Min(value, MaxMoney);
|
|
|
|
|
BigEndian.Int32ToBCD((int)value, 3).CopyTo(Data, Japanese ? 0x25EE : 0x25F3);
|
2016-08-27 11:33:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public uint Coin
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => (uint)BigEndian.BCDToInt32(Data, Japanese ? 0x2846 : 0x2850, 2);
|
2016-08-27 11:33:21 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-02-08 23:51:18 +00:00
|
|
|
|
value = (ushort)Math.Min(value, MaxCoins);
|
|
|
|
|
BigEndian.Int32ToBCD((int)value, 2).CopyTo(Data, Japanese ? 0x2846 : 0x2850);
|
2016-08-27 11:33:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-04 21:00:52 +00:00
|
|
|
|
private readonly ushort[] LegalItems = Legal.Pouch_Items_RBY;
|
2016-08-27 11:33:21 +00:00
|
|
|
|
public override InventoryPouch[] Inventory
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
ushort[] legalItems = LegalItems;
|
|
|
|
|
InventoryPouch[] pouch =
|
|
|
|
|
{
|
2016-08-31 05:58:39 +00:00
|
|
|
|
new InventoryPouch(InventoryType.Items, legalItems, 99, Japanese ? 0x25C4 : 0x25C9, 20),
|
2016-10-28 02:59:19 +00:00
|
|
|
|
new InventoryPouch(InventoryType.PCItems, legalItems, 99, Japanese ? 0x27DC : 0x27E6, 50)
|
2016-08-27 11:33:21 +00:00
|
|
|
|
};
|
|
|
|
|
foreach (var p in pouch)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
p.GetPouchG1(ref Data);
|
2016-08-27 11:33:21 +00:00
|
|
|
|
}
|
|
|
|
|
return pouch;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
foreach (var p in value)
|
|
|
|
|
{
|
|
|
|
|
int ofs = 0;
|
|
|
|
|
for (int i = 0; i < p.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
while (p.Items[ofs].Count == 0)
|
|
|
|
|
ofs++;
|
|
|
|
|
p.Items[i] = p.Items[ofs++];
|
|
|
|
|
}
|
2016-08-28 10:18:22 +00:00
|
|
|
|
while (ofs < p.Items.Length)
|
2016-08-27 11:33:21 +00:00
|
|
|
|
p.Items[ofs++] = new InventoryItem { Count = 0, Index = 0 };
|
2017-06-18 01:37:19 +00:00
|
|
|
|
p.SetPouchG1(ref Data);
|
2016-08-27 11:33:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override int GetDaycareSlotOffset(int loc, int slot)
|
2016-08-27 11:33:21 +00:00
|
|
|
|
{
|
|
|
|
|
return Daycare;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override uint? GetDaycareEXP(int loc, int slot)
|
2016-08-27 11:33:21 +00:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override bool? IsDaycareOccupied(int loc, int slot)
|
2016-08-27 11:33:21 +00:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override void SetDaycareEXP(int loc, int slot, uint EXP)
|
2016-08-27 11:33:21 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override void SetDaycareOccupied(int loc, int slot, bool occupied)
|
2016-08-27 11:33:21 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Storage
|
|
|
|
|
public override int PartyCount
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[Japanese ? 0x2ED5 : 0x2F2C];
|
|
|
|
|
protected set => Data[Japanese ? 0x2ED5 : 0x2F2C] = (byte)value;
|
2016-08-27 11:33:21 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override int GetBoxOffset(int box)
|
2016-08-27 11:33:21 +00:00
|
|
|
|
{
|
2016-08-28 10:18:22 +00:00
|
|
|
|
return Data.Length - SIZE_RESERVED + box * SIZE_BOX;
|
2016-08-27 11:33:21 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override int GetPartyOffset(int slot)
|
2016-08-27 11:33:21 +00:00
|
|
|
|
{
|
2016-08-28 10:18:22 +00:00
|
|
|
|
return Data.Length - SIZE_RESERVED + BoxCount * SIZE_BOX + slot * SIZE_STORED;
|
2016-08-27 11:33:21 +00:00
|
|
|
|
}
|
|
|
|
|
public override int CurrentBox
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[Japanese ? 0x2842 : 0x284C] & 0x7F;
|
|
|
|
|
set => Data[Japanese ? 0x2842 : 0x284C] = (byte)((Data[Japanese ? 0x2842 : 0x284C] & 0x80) | (value & 0x7F));
|
2016-08-27 11:33:21 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override string GetBoxName(int box)
|
2016-08-27 11:33:21 +00:00
|
|
|
|
{
|
2016-08-31 05:58:39 +00:00
|
|
|
|
return $"BOX {box + 1}";
|
2016-08-27 11:33:21 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override void SetBoxName(int box, string value)
|
2016-08-27 11:33:21 +00:00
|
|
|
|
{
|
2016-08-28 10:18:22 +00:00
|
|
|
|
// Don't allow for custom box names
|
2016-08-27 11:33:21 +00:00
|
|
|
|
}
|
2016-08-28 10:18:22 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override PKM GetPKM(byte[] data)
|
2016-08-27 11:33:21 +00:00
|
|
|
|
{
|
2016-08-28 10:18:22 +00:00
|
|
|
|
if (data.Length == SIZE_STORED)
|
2016-08-27 11:33:21 +00:00
|
|
|
|
return new PokemonList1(data, PokemonList1.CapacityType.Single, Japanese)[0];
|
|
|
|
|
return new PK1(data);
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override byte[] DecryptPKM(byte[] data)
|
2016-08-27 11:33:21 +00:00
|
|
|
|
{
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-31 05:58:39 +00:00
|
|
|
|
// Pokédex
|
2017-03-15 05:41:15 +00:00
|
|
|
|
private int PokedexSeenOffset => Japanese ? 0x25B1 : 0x25B6;
|
|
|
|
|
private int PokedexCaughtOffset => Japanese ? 0x259E : 0x25A3;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected override void SetDex(PKM pkm)
|
2016-08-30 00:48:05 +00:00
|
|
|
|
{
|
2017-03-15 05:41:15 +00:00
|
|
|
|
int species = pkm.Species;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (!CanSetDex(species))
|
2017-03-15 05:41:15 +00:00
|
|
|
|
return;
|
2016-08-30 00:48:05 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetCaught(pkm.Species, true);
|
|
|
|
|
SetSeen(pkm.Species, true);
|
2016-08-30 00:48:05 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private bool CanSetDex(int species)
|
2016-08-30 00:48:05 +00:00
|
|
|
|
{
|
2017-03-15 05:41:15 +00:00
|
|
|
|
if (species <= 0)
|
2016-08-30 00:48:05 +00:00
|
|
|
|
return false;
|
2017-03-15 05:41:15 +00:00
|
|
|
|
if (species > MaxSpeciesID)
|
2016-08-30 00:48:05 +00:00
|
|
|
|
return false;
|
|
|
|
|
if (Version == GameVersion.Unknown)
|
|
|
|
|
return false;
|
2017-03-15 05:41:15 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override void SetSeen(int species, bool seen)
|
2017-03-15 05:41:15 +00:00
|
|
|
|
{
|
|
|
|
|
int bit = species - 1;
|
2016-08-30 00:48:05 +00:00
|
|
|
|
int ofs = bit >> 3;
|
2017-10-19 04:43:42 +00:00
|
|
|
|
SetFlag(PokedexSeenOffset + ofs, bit & 7, seen);
|
2016-08-30 00:48:05 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override void SetCaught(int species, bool caught)
|
2016-08-27 11:33:21 +00:00
|
|
|
|
{
|
2017-03-15 05:41:15 +00:00
|
|
|
|
int bit = species - 1;
|
|
|
|
|
int ofs = bit >> 3;
|
2017-10-19 04:43:42 +00:00
|
|
|
|
SetFlag(PokedexCaughtOffset + ofs, bit & 7, caught);
|
2017-03-15 05:41:15 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override bool GetSeen(int species)
|
2017-03-15 05:41:15 +00:00
|
|
|
|
{
|
|
|
|
|
int bit = species - 1;
|
2016-08-27 11:33:21 +00:00
|
|
|
|
int ofs = bit >> 3;
|
2017-10-19 04:43:42 +00:00
|
|
|
|
return GetFlag(PokedexSeenOffset + ofs, bit & 7);
|
2016-08-30 00:48:05 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override bool GetCaught(int species)
|
2016-08-30 00:48:05 +00:00
|
|
|
|
{
|
2017-03-15 05:41:15 +00:00
|
|
|
|
int bit = species - 1;
|
2016-08-30 00:48:05 +00:00
|
|
|
|
int ofs = bit >> 3;
|
2017-10-19 04:43:42 +00:00
|
|
|
|
return GetFlag(PokedexCaughtOffset + ofs, bit & 7);
|
2016-08-27 11:33:21 +00:00
|
|
|
|
}
|
2017-04-09 21:06:50 +00:00
|
|
|
|
|
2017-09-24 23:36:51 +00:00
|
|
|
|
private const int SpawnFlagCount = 0xF0;
|
|
|
|
|
public bool[] EventSpawnFlags
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
// RB uses 0xE4 (0xE8) flags, Yellow uses 0xF0 flags. Just grab 0xF0
|
|
|
|
|
bool[] data = new bool[SpawnFlagCount];
|
|
|
|
|
for (int i = 0; i < data.Length; i++)
|
|
|
|
|
data[i] = GetFlag(ObjectSpawnFlags + i >> 3, i & 7);
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value?.Length != SpawnFlagCount)
|
|
|
|
|
return;
|
|
|
|
|
for (int i = 0; i < value.Length; i++)
|
|
|
|
|
SetFlag(ObjectSpawnFlags + i >> 3, i & 7, value[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-01 06:03:51 +00:00
|
|
|
|
public override string GetString(int Offset, int Count) => StringConverter.GetString1(Data, Offset, Count, Japanese);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override byte[] SetString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
|
2017-04-09 21:06:50 +00:00
|
|
|
|
{
|
|
|
|
|
if (PadToSize == 0)
|
|
|
|
|
PadToSize = maxLength + 1;
|
2017-08-01 06:03:51 +00:00
|
|
|
|
return StringConverter.SetString1(value, maxLength, Japanese, PadToSize, PadWith);
|
2017-04-09 21:06:50 +00:00
|
|
|
|
}
|
2016-08-27 11:33:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|