2016-06-20 04:22:43 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
public sealed class SAV4 : 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 => (Footer.Length > 0 ? "DeSmuME DSV|*.dsv|" : "") + "SAV File|*.sav|All Files|*.*";
|
2016-06-20 05:11:53 +00:00
|
|
|
|
public override string Extension => ".sav";
|
2016-06-28 06:03:57 +00:00
|
|
|
|
public SAV4(byte[] data = null, GameVersion versionOverride = GameVersion.Any)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
Data = data == null ? new byte[SaveUtil.SIZE_G4RAW] : (byte[])data.Clone();
|
|
|
|
|
BAK = (byte[])Data.Clone();
|
|
|
|
|
Exportable = !Data.SequenceEqual(new byte[Data.Length]);
|
|
|
|
|
|
|
|
|
|
// Get Version
|
2016-06-30 00:21:59 +00:00
|
|
|
|
if (data == null)
|
|
|
|
|
Version = GameVersion.HGSS;
|
|
|
|
|
else if (versionOverride != GameVersion.Any)
|
|
|
|
|
Version = versionOverride;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
else Version = SaveUtil.GetIsG4SAV(Data);
|
2016-06-28 06:03:57 +00:00
|
|
|
|
if (Version == GameVersion.Invalid)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
GetActiveGeneralBlock();
|
|
|
|
|
GetActiveStorageBlock();
|
|
|
|
|
GetSAVOffsets();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2016-07-03 03:24:17 +00:00
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
2016-07-18 05:39:18 +00:00
|
|
|
|
case GameVersion.DP: Personal = PersonalTable.DP; break;
|
|
|
|
|
case GameVersion.Pt: Personal = PersonalTable.Pt; break;
|
|
|
|
|
case GameVersion.HGSS: Personal = PersonalTable.HGSS; break;
|
2016-07-03 03:24:17 +00:00
|
|
|
|
}
|
2016-06-28 06:03:57 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (!Exportable)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
ClearBoxes();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Configuration
|
2016-06-28 06:03:57 +00:00
|
|
|
|
public override SaveFile Clone() { return new SAV4(Data, Version); }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
public override int SIZE_STORED => PKX.SIZE_4STORED;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected override int SIZE_PARTY => PKX.SIZE_4PARTY;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public override PKM BlankPKM => new PK4();
|
2016-09-26 23:14:11 +00:00
|
|
|
|
public override Type PKMType => typeof(PK4);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
public override int BoxCount => 18;
|
|
|
|
|
public override int MaxEV => 255;
|
|
|
|
|
public override int Generation => 4;
|
2017-05-19 02:20:19 +00:00
|
|
|
|
protected override int EventFlagMax => EventFlag > 0 ? 0xB60 : int.MinValue;
|
2017-05-13 01:15:04 +00:00
|
|
|
|
protected override int EventConstMax => EventConst > 0 ? (EventFlag - EventConst) >> 1 : int.MinValue;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
protected override int GiftCountMax => 11;
|
2017-04-10 04:53:53 +00:00
|
|
|
|
public override int OTLength => 7;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public override int NickLength => 10;
|
2016-09-09 03:20:32 +00:00
|
|
|
|
public override int MaxMoney => 999999;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2017-01-27 03:18:20 +00:00
|
|
|
|
public override int MaxMoveID => Legal.MaxMoveID_4;
|
2016-10-24 04:59:27 +00:00
|
|
|
|
public override int MaxSpeciesID => Legal.MaxSpeciesID_4;
|
2017-01-27 03:18:20 +00:00
|
|
|
|
public override int MaxItemID => Version == GameVersion.HGSS ? Legal.MaxItemID_4_HGSS : Version == GameVersion.Pt ? Legal.MaxItemID_4_Pt : Legal.MaxItemID_4_DP;
|
|
|
|
|
public override int MaxAbilityID => Legal.MaxAbilityID_4;
|
|
|
|
|
public override int MaxBallID => Legal.MaxBallID_4;
|
2016-06-21 01:58:06 +00:00
|
|
|
|
public override int MaxGameID => 15; // Colo/XD
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
// Checksums
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static int[][] GetChecksumOffsets(GameVersion g)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-01-16 00:16:35 +00:00
|
|
|
|
// start, end, chkoffset
|
|
|
|
|
switch (g)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
case GameVersion.DP:
|
2017-01-16 00:16:35 +00:00
|
|
|
|
return new[] {new[] {0x0000, 0xC0EC, 0xC0FE}, new[] {0xc100, 0x1E2CC, 0x1E2DE}};
|
2016-06-20 04:22:43 +00:00
|
|
|
|
case GameVersion.Pt:
|
2017-01-16 00:16:35 +00:00
|
|
|
|
return new[] {new[] {0x0000, 0xCF18, 0xCF2A}, new[] {0xCF2C, 0x1F0FC, 0x1F10E}};
|
2016-06-20 04:22:43 +00:00
|
|
|
|
case GameVersion.HGSS:
|
2017-01-20 13:41:15 +00:00
|
|
|
|
return new[] {new[] {0x0000, 0xF618, 0xF626}, new[] {0xF700, 0x21A00, 0x21A0E}};
|
2017-01-16 00:16:35 +00:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected override void SetChecksums()
|
2017-01-16 00:16:35 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int[][] c = GetChecksumOffsets(Version);
|
2017-01-16 00:16:35 +00:00
|
|
|
|
if (c == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
BitConverter.GetBytes(SaveUtil.CRC16_CCITT(Data, c[0][0] + GBO, c[0][1] - c[0][0])).CopyTo(Data, c[0][2] + GBO);
|
|
|
|
|
BitConverter.GetBytes(SaveUtil.CRC16_CCITT(Data, c[1][0] + SBO, c[1][1] - c[1][0])).CopyTo(Data, c[1][2] + SBO);
|
2017-01-16 00:16:35 +00:00
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public override bool ChecksumsValid
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int[][] c = GetChecksumOffsets(Version);
|
2017-01-16 00:16:35 +00:00
|
|
|
|
if (c == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (SaveUtil.CRC16_CCITT(Data, c[0][0] + GBO, c[0][1] - c[0][0]) != BitConverter.ToUInt16(Data, c[0][2] + GBO))
|
2017-01-16 00:16:35 +00:00
|
|
|
|
return false; // Small Fail
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (SaveUtil.CRC16_CCITT(Data, c[1][0] + SBO, c[1][1] - c[1][0]) != BitConverter.ToUInt16(Data, c[1][2] + SBO))
|
2017-01-16 00:16:35 +00:00
|
|
|
|
return false; // Large Fail
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public override string ChecksumInfo
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int[][] c = GetChecksumOffsets(Version);
|
2017-01-16 00:16:35 +00:00
|
|
|
|
if (c == null)
|
|
|
|
|
return "Unable to check Save File.";
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
string r = "";
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (SaveUtil.CRC16_CCITT(Data, c[0][0] + GBO, c[0][1] - c[0][0]) != BitConverter.ToUInt16(Data, c[0][2] + GBO))
|
2017-01-16 00:16:35 +00:00
|
|
|
|
r += "Small block checksum is invalid" + Environment.NewLine;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (SaveUtil.CRC16_CCITT(Data, c[1][0] + SBO, c[1][1] - c[1][0]) != BitConverter.ToUInt16(Data, c[1][2] + SBO))
|
2017-01-16 00:16:35 +00:00
|
|
|
|
r += "Large block checksum is invalid" + Environment.NewLine;
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return r.Length == 0 ? "Checksums valid." : r.TrimEnd();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Blocks & Offsets
|
|
|
|
|
private int generalBlock = -1; // Small Block
|
|
|
|
|
private int storageBlock = -1; // Big Block
|
|
|
|
|
private int hofBlock = -1; // Hall of Fame Block
|
|
|
|
|
private int SBO => 0x40000 * storageBlock;
|
|
|
|
|
private int GBO => 0x40000 * generalBlock;
|
|
|
|
|
private int HBO => 0x40000 * hofBlock;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public int GetGBO => GBO;
|
|
|
|
|
private void GetActiveGeneralBlock()
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2016-06-28 06:03:57 +00:00
|
|
|
|
if (Version < 0)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return;
|
|
|
|
|
int ofs = 0;
|
|
|
|
|
|
2016-09-13 01:01:26 +00:00
|
|
|
|
// Check to see if the save is initialized completely
|
2016-09-13 01:10:42 +00:00
|
|
|
|
// if the block is not initialized, fall back to the other save.
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (GetData(0x00000, 10).SequenceEqual(Enumerable.Repeat((byte)0xFF, 10)))
|
2016-09-13 01:10:42 +00:00
|
|
|
|
{ generalBlock = 1; return; }
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (GetData(0x40000, 10).SequenceEqual(Enumerable.Repeat((byte)0xFF, 10)))
|
2016-09-28 05:42:13 +00:00
|
|
|
|
{ generalBlock = 0; return; }
|
2016-09-13 01:01:26 +00:00
|
|
|
|
|
2016-09-21 16:03:47 +00:00
|
|
|
|
// Check SaveCount for current save
|
2016-06-28 06:03:57 +00:00
|
|
|
|
if (Version == GameVersion.DP) ofs = 0xC0F0; // DP
|
|
|
|
|
else if (Version == GameVersion.Pt) ofs = 0xCF1C; // PT
|
2016-09-21 16:03:47 +00:00
|
|
|
|
else if (Version == GameVersion.HGSS) ofs = 0xF618; // HGSS
|
2016-06-20 04:22:43 +00:00
|
|
|
|
generalBlock = BitConverter.ToUInt16(Data, ofs) >= BitConverter.ToUInt16(Data, ofs + 0x40000) ? 0 : 1;
|
2016-09-13 01:10:42 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void GetActiveStorageBlock()
|
2016-09-13 01:10:42 +00:00
|
|
|
|
{
|
|
|
|
|
if (Version < 0)
|
|
|
|
|
return;
|
|
|
|
|
int ofs = 0;
|
|
|
|
|
|
2016-09-21 16:03:47 +00:00
|
|
|
|
// Check SaveCount for current save
|
2016-06-28 06:03:57 +00:00
|
|
|
|
if (Version == GameVersion.DP) ofs = 0x1E2D0; // DP
|
|
|
|
|
else if (Version == GameVersion.Pt) ofs = 0x1F100; // PT
|
|
|
|
|
else if (Version == GameVersion.HGSS) ofs = 0x21A00; // HGSS
|
2016-09-13 01:10:42 +00:00
|
|
|
|
|
|
|
|
|
// Check to see if the save is initialized completely
|
|
|
|
|
// if the block is not initialized, fall back to the other save.
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (GetData(ofs + 0x00000, 10).SequenceEqual(Enumerable.Repeat((byte)0xFF, 10)))
|
2016-09-13 01:10:42 +00:00
|
|
|
|
{ storageBlock = 1; return; }
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (GetData(ofs + 0x40000, 10).SequenceEqual(Enumerable.Repeat((byte)0xFF, 10)))
|
2016-09-13 01:10:42 +00:00
|
|
|
|
{ storageBlock = 0; return; }
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
storageBlock = BitConverter.ToUInt16(Data, ofs) >= BitConverter.ToUInt16(Data, ofs + 0x40000) ? 0 : 1;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void GetSAVOffsets()
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2016-06-28 06:03:57 +00:00
|
|
|
|
if (Version < 0)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
|
|
|
|
case GameVersion.DP:
|
|
|
|
|
AdventureInfo = 0 + GBO;
|
|
|
|
|
Trainer1 = 0x64 + GBO;
|
|
|
|
|
Party = 0x98 + GBO;
|
2016-07-04 20:06:01 +00:00
|
|
|
|
PokeDex = 0x12DC + GBO;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
WondercardFlags = 0xA6D0 + GBO;
|
|
|
|
|
WondercardData = 0xA7fC + GBO;
|
|
|
|
|
|
|
|
|
|
OFS_PouchHeldItem = 0x624 + GBO;
|
|
|
|
|
OFS_PouchKeyItem = 0x8B8 + GBO;
|
|
|
|
|
OFS_PouchTMHM = 0x980 + GBO;
|
2017-07-05 16:33:04 +00:00
|
|
|
|
OFS_MailItems = 0xB10 + GBO;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
OFS_PouchMedicine = 0xB40 + GBO;
|
|
|
|
|
OFS_PouchBerry = 0xBE0 + GBO;
|
|
|
|
|
OFS_PouchBalls = 0xCE0 + GBO;
|
|
|
|
|
OFS_BattleItems = 0xD1C + GBO;
|
|
|
|
|
LegalItems = Legal.Pouch_Items_DP;
|
|
|
|
|
LegalKeyItems = Legal.Pouch_Key_DP;
|
|
|
|
|
LegalTMHMs = Legal.Pouch_TMHM_DP;
|
|
|
|
|
LegalMedicine = Legal.Pouch_Medicine_DP;
|
|
|
|
|
LegalBerries = Legal.Pouch_Berries_DP;
|
|
|
|
|
LegalBalls = Legal.Pouch_Ball_DP;
|
|
|
|
|
LegalBattleItems = Legal.Pouch_Battle_DP;
|
|
|
|
|
LegalMailItems = Legal.Pouch_Mail_DP;
|
|
|
|
|
|
|
|
|
|
HeldItems = Legal.HeldItems_DP;
|
2017-05-19 02:20:19 +00:00
|
|
|
|
EventConst = 0xD9C + GBO;
|
|
|
|
|
EventFlag = 0xFDC + GBO;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
Daycare = 0x141C + GBO;
|
2017-06-10 13:12:51 +00:00
|
|
|
|
OFS_HONEY = 0x72E4 + GBO;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
Box = 0xC104 + SBO;
|
2017-07-07 00:32:26 +00:00
|
|
|
|
|
|
|
|
|
_currentPoketchApp = 0x114E;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
break;
|
|
|
|
|
case GameVersion.Pt:
|
|
|
|
|
AdventureInfo = 0 + GBO;
|
|
|
|
|
Trainer1 = 0x68 + GBO;
|
|
|
|
|
Party = 0xA0 + GBO;
|
2016-07-04 20:06:01 +00:00
|
|
|
|
PokeDex = 0x1328 + GBO;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
WondercardFlags = 0xB4C0 + GBO;
|
|
|
|
|
WondercardData = 0xB5C0 + GBO;
|
|
|
|
|
|
|
|
|
|
OFS_PouchHeldItem = 0x630 + GBO;
|
|
|
|
|
OFS_PouchKeyItem = 0x8C4 + GBO;
|
|
|
|
|
OFS_PouchTMHM = 0x98C + GBO;
|
|
|
|
|
OFS_MailItems = 0xB1C + GBO;
|
|
|
|
|
OFS_PouchMedicine = 0xB4C + GBO;
|
|
|
|
|
OFS_PouchBerry = 0xBEC + GBO;
|
|
|
|
|
OFS_PouchBalls = 0xCEC + GBO;
|
|
|
|
|
OFS_BattleItems = 0xD28 + GBO;
|
|
|
|
|
LegalItems = Legal.Pouch_Items_Pt;
|
|
|
|
|
LegalKeyItems = Legal.Pouch_Key_Pt;
|
|
|
|
|
LegalTMHMs = Legal.Pouch_TMHM_Pt;
|
|
|
|
|
LegalMedicine = Legal.Pouch_Medicine_Pt;
|
|
|
|
|
LegalBerries = Legal.Pouch_Berries_Pt;
|
|
|
|
|
LegalBalls = Legal.Pouch_Ball_Pt;
|
|
|
|
|
LegalBattleItems = Legal.Pouch_Battle_Pt;
|
|
|
|
|
LegalMailItems = Legal.Pouch_Mail_Pt;
|
|
|
|
|
|
|
|
|
|
HeldItems = Legal.HeldItems_Pt;
|
2017-06-10 13:12:51 +00:00
|
|
|
|
EventConst = 0xDAC + GBO;
|
|
|
|
|
EventFlag = 0xFEC + GBO;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
Daycare = 0x1654 + GBO;
|
2017-06-10 13:12:51 +00:00
|
|
|
|
OFS_HONEY = 0x7F38 + GBO;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
Box = 0xCF30 + SBO;
|
2017-07-07 00:32:26 +00:00
|
|
|
|
|
|
|
|
|
_currentPoketchApp = 0x1162;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
break;
|
|
|
|
|
case GameVersion.HGSS:
|
|
|
|
|
AdventureInfo = 0 + GBO;
|
|
|
|
|
Trainer1 = 0x64 + GBO;
|
|
|
|
|
Party = 0x98 + GBO;
|
2016-07-04 20:06:01 +00:00
|
|
|
|
PokeDex = 0x12B8 + GBO;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
WondercardFlags = 0x9D3C + GBO;
|
|
|
|
|
WondercardData = 0x9E3C + GBO;
|
|
|
|
|
|
|
|
|
|
OFS_PouchHeldItem = 0x644 + GBO; // 0x644-0x8D7 (0x8CB)
|
|
|
|
|
OFS_PouchKeyItem = 0x8D8 + GBO; // 0x8D8-0x99F (0x979)
|
|
|
|
|
OFS_PouchTMHM = 0x9A0 + GBO; // 0x9A0-0xB33 (0xB2F)
|
|
|
|
|
OFS_MailItems = 0xB34 + GBO; // 0xB34-0xB63 (0xB63)
|
|
|
|
|
OFS_PouchMedicine = 0xB64 + GBO; // 0xB64-0xC03 (0xBFB)
|
|
|
|
|
OFS_PouchBerry = 0xC04 + GBO; // 0xC04-0xD03
|
|
|
|
|
OFS_PouchBalls = 0xD04 + GBO; // 0xD04-0xD63
|
|
|
|
|
OFS_BattleItems = 0xD64 + GBO; // 0xD64-0xD97
|
|
|
|
|
LegalItems = Legal.Pouch_Items_HGSS;
|
|
|
|
|
LegalKeyItems = Legal.Pouch_Key_HGSS;
|
|
|
|
|
LegalTMHMs = Legal.Pouch_TMHM_HGSS;
|
|
|
|
|
LegalMedicine = Legal.Pouch_Medicine_HGSS;
|
|
|
|
|
LegalBerries = Legal.Pouch_Berries_HGSS;
|
|
|
|
|
LegalBalls = Legal.Pouch_Ball_HGSS;
|
|
|
|
|
LegalBattleItems = Legal.Pouch_Battle_HGSS;
|
|
|
|
|
LegalMailItems = Legal.Pouch_Mail_HGSS;
|
|
|
|
|
|
|
|
|
|
HeldItems = Legal.HeldItems_HGSS;
|
2017-05-19 02:20:19 +00:00
|
|
|
|
EventConst = 0xDE4 + GBO;
|
|
|
|
|
EventFlag = 0x10C4 + GBO;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
Daycare = 0x15FC + GBO;
|
|
|
|
|
Box = 0xF700 + SBO;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int WondercardFlags = int.MinValue;
|
|
|
|
|
private int AdventureInfo = int.MinValue;
|
|
|
|
|
|
|
|
|
|
// Inventory
|
|
|
|
|
private ushort[] LegalItems, LegalKeyItems, LegalTMHMs, LegalMedicine, LegalBerries, LegalBalls, LegalBattleItems, LegalMailItems;
|
|
|
|
|
public override InventoryPouch[] Inventory
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
InventoryPouch[] pouch =
|
|
|
|
|
{
|
2017-06-15 01:43:28 +00:00
|
|
|
|
new InventoryPouch(InventoryType.Items, LegalItems, 999, OFS_PouchHeldItem),
|
2016-06-20 04:22:43 +00:00
|
|
|
|
new InventoryPouch(InventoryType.KeyItems, LegalKeyItems, 1, OFS_PouchKeyItem),
|
2017-06-15 01:43:28 +00:00
|
|
|
|
new InventoryPouch(InventoryType.TMHMs, LegalTMHMs, 99, OFS_PouchTMHM),
|
|
|
|
|
new InventoryPouch(InventoryType.Medicine, LegalMedicine, 999, OFS_PouchMedicine),
|
|
|
|
|
new InventoryPouch(InventoryType.Berries, LegalBerries, 999, OFS_PouchBerry),
|
|
|
|
|
new InventoryPouch(InventoryType.Balls, LegalBalls, 999, OFS_PouchBalls),
|
|
|
|
|
new InventoryPouch(InventoryType.BattleItems, LegalBattleItems, 999, OFS_BattleItems),
|
|
|
|
|
new InventoryPouch(InventoryType.MailItems, LegalMailItems, 999, OFS_MailItems),
|
2016-06-20 04:22:43 +00:00
|
|
|
|
};
|
|
|
|
|
foreach (var p in pouch)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
p.GetPouch(ref Data);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return pouch;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
foreach (var p in value)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
p.SetPouch(ref Data);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Storage
|
|
|
|
|
public override int PartyCount
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[Party - 4];
|
|
|
|
|
protected set => Data[Party - 4] = (byte)value;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override int GetBoxOffset(int box)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2016-06-28 06:03:57 +00:00
|
|
|
|
return Box + SIZE_STORED*box*30 + (Version == GameVersion.HGSS ? box * 0x10 : 0);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override int GetPartyOffset(int slot)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
return Party + SIZE_PARTY*slot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Trainer Info
|
|
|
|
|
public override string OT
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
get => GetString(Trainer1, 16);
|
|
|
|
|
set => SetString(value, OTLength).CopyTo(Data, Trainer1);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
public override ushort TID
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt16(Data, Trainer1 + 0x10 + 0);
|
|
|
|
|
set => BitConverter.GetBytes(value).CopyTo(Data, Trainer1 + 0x10 + 0);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
public override ushort SID
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt16(Data, Trainer1 + 0x12);
|
|
|
|
|
set => BitConverter.GetBytes(value).CopyTo(Data, Trainer1 + 0x12);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2016-06-22 00:35:12 +00:00
|
|
|
|
public override uint Money
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt32(Data, Trainer1 + 0x14);
|
|
|
|
|
set => BitConverter.GetBytes(value).CopyTo(Data, Trainer1 + 0x14);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
public override int Gender
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[Trainer1 + 0x18];
|
|
|
|
|
set => Data[Trainer1 + 0x18] = (byte)value;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
public override int Language
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[Trainer1 + 0x19];
|
|
|
|
|
set => Data[Trainer1 + 0x19] = (byte)value;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
public int Badges
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[Trainer1 + 0x1A];
|
2016-06-20 04:22:43 +00:00
|
|
|
|
set { if (value < 0) return; Data[Trainer1 + 0x1A] = (byte)value; }
|
|
|
|
|
}
|
|
|
|
|
public int Sprite
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[Trainer1 + 0x1B];
|
2016-06-20 04:22:43 +00:00
|
|
|
|
set { if (value < 0) return; Data[Trainer1 + 0x1B] = (byte)value; }
|
|
|
|
|
}
|
|
|
|
|
public int Badges16
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Version != GameVersion.HGSS)
|
|
|
|
|
return -1;
|
|
|
|
|
return Data[Trainer1 + 0x1F];
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value < 0)
|
|
|
|
|
return;
|
|
|
|
|
if (Version != GameVersion.HGSS)
|
|
|
|
|
return;
|
|
|
|
|
Data[Trainer1 + 0x1F] = (byte)value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-22 00:35:12 +00:00
|
|
|
|
public override int PlayedHours
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt16(Data, Trainer1 + 0x22);
|
|
|
|
|
set => BitConverter.GetBytes((ushort)value).CopyTo(Data, Trainer1 + 0x22);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2016-06-22 00:35:12 +00:00
|
|
|
|
public override int PlayedMinutes
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[Trainer1 + 0x24];
|
|
|
|
|
set => Data[Trainer1 + 0x24] = (byte)value;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2016-06-22 00:35:12 +00:00
|
|
|
|
public override int PlayedSeconds
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[Trainer1 + 0x25];
|
|
|
|
|
set => Data[Trainer1 + 0x25] = (byte)value;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
public int M
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
int ofs = 0;
|
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
2016-12-31 23:45:04 +00:00
|
|
|
|
case GameVersion.DP: ofs = 0x1238; break;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
case GameVersion.HGSS: ofs = 0x1234; break;
|
|
|
|
|
case GameVersion.Pt: ofs = 0x1280; break;
|
|
|
|
|
}
|
2016-09-13 01:01:26 +00:00
|
|
|
|
ofs += GBO;
|
2016-07-09 20:54:49 +00:00
|
|
|
|
return BitConverter.ToUInt16(Data, ofs);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
int ofs = 0;
|
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
2016-12-31 23:45:04 +00:00
|
|
|
|
case GameVersion.DP: ofs = 0x1238; break;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
case GameVersion.HGSS: ofs = 0x1234; break;
|
|
|
|
|
case GameVersion.Pt: ofs = 0x1280; break;
|
|
|
|
|
}
|
2016-09-13 01:01:26 +00:00
|
|
|
|
ofs += GBO;
|
2016-07-09 20:54:49 +00:00
|
|
|
|
BitConverter.GetBytes((ushort)value).CopyTo(Data, ofs);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public int X
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
int ofs = 0;
|
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
|
|
|
|
case GameVersion.DP: ofs = 0x25FA; break;
|
|
|
|
|
case GameVersion.Pt: ofs = 0x287E; break;
|
|
|
|
|
case GameVersion.HGSS: ofs = 0x236E; break;
|
|
|
|
|
}
|
2016-09-13 01:01:26 +00:00
|
|
|
|
ofs += GBO;
|
2016-07-09 20:54:49 +00:00
|
|
|
|
return BitConverter.ToUInt16(Data, ofs);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-31 23:45:04 +00:00
|
|
|
|
int ofs = 0; int ofs2 = 0;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
2016-12-31 23:45:04 +00:00
|
|
|
|
case GameVersion.DP: ofs = 0x25FA; ofs2 = 0x1240; break;
|
|
|
|
|
case GameVersion.Pt: ofs = 0x287E; ofs2 = 0x1288; break;
|
|
|
|
|
case GameVersion.HGSS: ofs = 0x236E; ofs2 = 0x123C; break;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2016-12-31 23:45:04 +00:00
|
|
|
|
ofs += GBO; ofs2 += GBO;
|
2016-07-09 20:54:49 +00:00
|
|
|
|
BitConverter.GetBytes((ushort)value).CopyTo(Data, ofs);
|
2016-12-31 23:45:04 +00:00
|
|
|
|
BitConverter.GetBytes((ushort)value).CopyTo(Data, ofs2);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public int Z
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
int ofs = 0;
|
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
|
|
|
|
case GameVersion.DP: ofs = 0x2602; break;
|
|
|
|
|
case GameVersion.Pt: ofs = 0x2886; break;
|
|
|
|
|
case GameVersion.HGSS: ofs = 0x2376; break;
|
|
|
|
|
}
|
2016-09-13 01:01:26 +00:00
|
|
|
|
ofs += GBO;
|
2016-07-09 20:54:49 +00:00
|
|
|
|
return BitConverter.ToUInt16(Data, ofs);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
int ofs = 0;
|
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
|
|
|
|
case GameVersion.DP: ofs = 0x2602; break;
|
|
|
|
|
case GameVersion.Pt: ofs = 0x2886; break;
|
|
|
|
|
case GameVersion.HGSS: ofs = 0x2376; break;
|
|
|
|
|
}
|
2016-09-13 01:01:26 +00:00
|
|
|
|
ofs += GBO;
|
2016-07-09 20:54:49 +00:00
|
|
|
|
BitConverter.GetBytes((ushort)value).CopyTo(Data, ofs);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public int Y
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
int ofs = 0;
|
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
|
|
|
|
case GameVersion.DP: ofs = 0x25FE; break;
|
|
|
|
|
case GameVersion.Pt: ofs = 0x2882; break;
|
|
|
|
|
case GameVersion.HGSS: ofs = 0x2372; break;
|
|
|
|
|
}
|
2016-09-13 01:01:26 +00:00
|
|
|
|
ofs += GBO;
|
2016-07-09 20:54:49 +00:00
|
|
|
|
return BitConverter.ToUInt16(Data, ofs);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-31 23:45:04 +00:00
|
|
|
|
int ofs = 0; int ofs2 = 0;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
2016-12-31 23:45:04 +00:00
|
|
|
|
case GameVersion.DP: ofs = 0x25FE; ofs2 = 0x1244; break;
|
|
|
|
|
case GameVersion.Pt: ofs = 0x2882; ofs2 = 0x128C; break;
|
|
|
|
|
case GameVersion.HGSS: ofs = 0x2372; ofs2 = 0x1240; break;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2016-12-31 23:45:04 +00:00
|
|
|
|
ofs += GBO; ofs2 += GBO;
|
2016-07-09 20:54:49 +00:00
|
|
|
|
BitConverter.GetBytes((ushort)value).CopyTo(Data, ofs);
|
2016-12-31 23:45:04 +00:00
|
|
|
|
BitConverter.GetBytes((ushort)value).CopyTo(Data, ofs2);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int SecondsToStart { get => BitConverter.ToInt32(Data, AdventureInfo + 0x34); set => BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x34); }
|
|
|
|
|
public override int SecondsToFame { get => BitConverter.ToInt32(Data, AdventureInfo + 0x3C); set => BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x3C); }
|
2017-07-07 00:32:26 +00:00
|
|
|
|
public int CurrentPoketchApp { get => Data[_currentPoketchApp]; set => Data[_currentPoketchApp] = (byte)Math.Min(24, value); /* Alarm Clock */ }
|
|
|
|
|
private int _currentPoketchApp;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
// Storage
|
2016-06-24 04:55:14 +00:00
|
|
|
|
public override int CurrentBox
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
get => Data[Version == GameVersion.HGSS ? GetBoxOffset(BoxCount) : Box - 4];
|
|
|
|
|
set => Data[Version == GameVersion.HGSS ? GetBoxOffset(BoxCount) : Box - 4] = (byte)value;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2017-05-24 04:38:15 +00:00
|
|
|
|
private static int InvertHGSSBoxWallpaperAlias(int value)
|
|
|
|
|
{
|
|
|
|
|
// HG/SS Special Wallpapers 1-8 (Primo Phrases) are shifted by +0x10; swap 0x2_ and 0x1_ by xoring with 0x30
|
|
|
|
|
if (value >= 0x10)
|
|
|
|
|
return value ^ 0x30;
|
|
|
|
|
return value;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override int GetBoxWallpaper(int box)
|
2017-05-24 04:38:15 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int value = base.GetBoxWallpaper(box);
|
2017-05-24 04:38:15 +00:00
|
|
|
|
return Version == GameVersion.HGSS ? InvertHGSSBoxWallpaperAlias(value) : value;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override void SetBoxWallpaper(int box, int value)
|
2017-05-24 04:38:15 +00:00
|
|
|
|
{
|
|
|
|
|
if (Version == GameVersion.HGSS)
|
|
|
|
|
value = InvertHGSSBoxWallpaperAlias(value);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
base.SetBoxWallpaper(box, value);
|
2017-05-24 04:38:15 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected override int GetBoxWallpaperOffset(int box)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
// Box Wallpaper is directly after the Box Names
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int offset = GetBoxOffset(BoxCount);
|
2017-05-24 04:38:15 +00:00
|
|
|
|
if (Version == GameVersion.HGSS) offset += 0x8;
|
2016-07-26 05:40:05 +00:00
|
|
|
|
offset += BoxCount*0x28 + box;
|
2016-10-29 18:32:21 +00:00
|
|
|
|
return offset;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override string GetBoxName(int box)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int offset = GetBoxOffset(BoxCount);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (Version == GameVersion.HGSS) offset += 0x8;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetString(offset + box*0x28, 0x28);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override void SetBoxName(int box, string value)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (value.Length > 13)
|
|
|
|
|
value = value.Substring(0, 13); // Hard cap
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int offset = GetBoxOffset(BoxCount);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (Version == GameVersion.HGSS) offset += 0x8;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetData(SetString(value, 13), offset + box*0x28);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override PKM GetPKM(byte[] data)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
return new PK4(data);
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override byte[] DecryptPKM(byte[] data)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return PKX.DecryptArray45(data);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Daycare
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override int GetDaycareSlotOffset(int loc, int slot)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
return Daycare + slot * SIZE_PARTY;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override uint? GetDaycareEXP(int loc, int slot)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
int ofs = Daycare + (slot+1)*SIZE_PARTY - 4;
|
|
|
|
|
return BitConverter.ToUInt32(Data, ofs);
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override bool? IsDaycareOccupied(int loc, int slot)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override void SetDaycareEXP(int loc, int slot, uint EXP)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
int ofs = Daycare + (slot+1)*SIZE_PARTY - 4;
|
|
|
|
|
BitConverter.GetBytes(EXP).CopyTo(Data, ofs);
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override void SetDaycareOccupied(int loc, int slot, bool occupied)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mystery Gift
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private bool MysteryGiftActive { get => (Data[GBO + 72] & 1) == 1; set => Data[GBO + 72] = (byte)((Data[GBO + 72] & 0xFE) | (value ? 1 : 0)); }
|
|
|
|
|
private static bool IsMysteryGiftAvailable(MysteryGift[] value)
|
2017-01-16 00:52:10 +00:00
|
|
|
|
{
|
|
|
|
|
if (value == null)
|
|
|
|
|
return false;
|
|
|
|
|
for (int i = 0; i < 8; i++) // 8 PGT
|
|
|
|
|
if ((value[i] as PGT)?.CardType != 0)
|
|
|
|
|
return true;
|
|
|
|
|
for (int i = 8; i < 11; i++) // 3 PCD
|
|
|
|
|
if ((value[i] as PCD)?.Gift.CardType != 0)
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-01-20 07:49:46 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static int[] MatchMysteryGifts(MysteryGift[] value)
|
2017-01-20 07:49:46 +00:00
|
|
|
|
{
|
|
|
|
|
if (value == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
int[] cardMatch = new int[8];
|
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
|
{
|
|
|
|
|
var pgt = value[i] as PGT;
|
|
|
|
|
if (pgt == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
2017-01-21 03:35:56 +00:00
|
|
|
|
if (pgt.CardType == 0) // empty
|
|
|
|
|
{
|
|
|
|
|
cardMatch[i] = pgt.Slot = 0;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-20 16:43:41 +00:00
|
|
|
|
cardMatch[i] = pgt.Slot = 3;
|
2017-01-20 07:49:46 +00:00
|
|
|
|
for (byte j = 0; j < 3; j++)
|
|
|
|
|
{
|
|
|
|
|
var pcd = value[8 + j] as PCD;
|
|
|
|
|
if (pcd == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Check if data matches (except Slot @ 0x02)
|
2017-01-21 03:35:56 +00:00
|
|
|
|
if (!pcd.GiftEquals(pgt))
|
2017-01-20 07:49:46 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
cardMatch[i] = pgt.Slot = j;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return cardMatch;
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public override MysteryGiftAlbum GiftAlbum
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-01-16 00:52:10 +00:00
|
|
|
|
var album = new MysteryGiftAlbum
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
Flags = MysteryGiftReceivedFlags,
|
|
|
|
|
Gifts = MysteryGiftCards,
|
|
|
|
|
};
|
2017-01-16 00:52:10 +00:00
|
|
|
|
album.Flags[2047] = false;
|
|
|
|
|
return album;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
bool available = IsMysteryGiftAvailable(value.Gifts);
|
2017-01-16 00:52:10 +00:00
|
|
|
|
MysteryGiftActive |= available;
|
|
|
|
|
value.Flags[2047] = available;
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
MysteryGiftReceivedFlags = value.Flags;
|
|
|
|
|
MysteryGiftCards = value.Gifts;
|
2017-01-21 20:09:15 +00:00
|
|
|
|
|
|
|
|
|
if (Version != GameVersion.DP)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
bool[] activeGifts = value.Gifts.Select(gift => !gift.Empty).ToArray();
|
|
|
|
|
MysteryGiftDPSlotActiveFlags = activeGifts;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
protected override bool[] MysteryGiftReceivedFlags
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (WondercardData < 0 || WondercardFlags < 0)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
bool[] r = new bool[GiftFlagMax];
|
|
|
|
|
for (int i = 0; i < r.Length; i++)
|
|
|
|
|
r[i] = (Data[WondercardFlags + (i >> 3)] >> (i & 7) & 0x1) == 1;
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (WondercardData < 0 || WondercardFlags < 0)
|
|
|
|
|
return;
|
|
|
|
|
if (GiftFlagMax != value?.Length)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
byte[] data = new byte[value.Length / 8];
|
|
|
|
|
for (int i = 0; i < value.Length; i++)
|
|
|
|
|
if (value[i])
|
|
|
|
|
data[i >> 3] |= (byte)(1 << (i & 7));
|
|
|
|
|
|
|
|
|
|
data.CopyTo(Data, WondercardFlags);
|
|
|
|
|
Edited = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-21 20:09:15 +00:00
|
|
|
|
|
|
|
|
|
private const uint MysteryGiftDPSlotActive = 0xEDB88320;
|
|
|
|
|
private bool[] MysteryGiftDPSlotActiveFlags
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Version != GameVersion.DP)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
int ofs = WondercardFlags + 0x100; // skip over flags
|
|
|
|
|
bool[] active = new bool[GiftCountMax]; // 8 PGT, 3 PCD
|
|
|
|
|
for (int i = 0; i < active.Length; i++)
|
|
|
|
|
active[i] = BitConverter.ToUInt32(Data, ofs + 4*i) == MysteryGiftDPSlotActive;
|
|
|
|
|
|
|
|
|
|
return active;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (Version != GameVersion.DP)
|
|
|
|
|
return;
|
|
|
|
|
if (value == null || value.Length != GiftCountMax)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int ofs = WondercardFlags + 0x100; // skip over flags
|
2017-01-21 20:10:35 +00:00
|
|
|
|
for (int i = 0; i < value.Length; i++)
|
2017-01-21 20:09:15 +00:00
|
|
|
|
{
|
|
|
|
|
byte[] magic = BitConverter.GetBytes(value[i] ? MysteryGiftDPSlotActive : 0); // 4 bytes
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetData(magic, ofs + 4*i);
|
2017-01-21 20:09:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
protected override MysteryGift[] MysteryGiftCards
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
MysteryGift[] cards = new MysteryGift[8 + 3];
|
|
|
|
|
for (int i = 0; i < 8; i++) // 8 PGT
|
2017-06-18 01:37:19 +00:00
|
|
|
|
cards[i] = new PGT(GetData(WondercardData + i * PGT.Size, PGT.Size));
|
2016-06-20 04:22:43 +00:00
|
|
|
|
for (int i = 8; i < 11; i++) // 3 PCD
|
2017-06-18 01:37:19 +00:00
|
|
|
|
cards[i] = new PCD(GetData(WondercardData + 8 * PGT.Size + (i-8) * PCD.Size, PCD.Size));
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return cards;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == null)
|
|
|
|
|
return;
|
2017-01-20 07:49:46 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var Matches = MatchMysteryGifts(value); // automatically applied
|
2017-01-20 07:49:46 +00:00
|
|
|
|
if (Matches == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
for (int i = 0; i < 8; i++) // 8 PGT
|
2017-01-16 00:52:10 +00:00
|
|
|
|
if (value[i] is PGT)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetData(value[i].Data, WondercardData + i*PGT.Size);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
for (int i = 8; i < 11; i++) // 3 PCD
|
2017-01-16 00:52:10 +00:00
|
|
|
|
if (value[i] is PCD)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetData(value[i].Data, WondercardData + 8*PGT.Size + (i - 8)*PCD.Size);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-04 20:06:01 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected override void SetDex(PKM pkm)
|
2016-07-04 20:06:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (pkm.Species == 0)
|
|
|
|
|
return;
|
|
|
|
|
if (pkm.Species > MaxSpeciesID)
|
|
|
|
|
return;
|
|
|
|
|
if (Version == GameVersion.Unknown)
|
|
|
|
|
return;
|
|
|
|
|
if (PokeDex < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const int brSize = 0x40;
|
|
|
|
|
int bit = pkm.Species - 1;
|
2017-03-22 05:50:55 +00:00
|
|
|
|
byte mask = (byte)(1 << (bit & 7));
|
2017-03-07 06:43:46 +00:00
|
|
|
|
int ofs = PokeDex + (bit >> 3) + 0x4;
|
|
|
|
|
|
|
|
|
|
/* 4 BitRegions with 0x40*8 bits
|
|
|
|
|
* Region 0: Caught (Captured/Owned) flags
|
|
|
|
|
* Region 1: Seen flags
|
|
|
|
|
* Region 2/3: Toggle for gender display
|
|
|
|
|
* 4 possible states: 00, 01, 10, 11
|
|
|
|
|
* 00 - 1Seen: Male Only
|
|
|
|
|
* 01 - 2Seen: Male First, Female Second
|
|
|
|
|
* 10 - 2Seen: Female First, Male Second
|
|
|
|
|
* 11 - 1Seen: Female Only
|
|
|
|
|
* (bit1 ^ bit2) + 1 = forms in dex
|
|
|
|
|
* bit2 = male/female shown first toggle
|
|
|
|
|
*/
|
2016-07-04 20:06:01 +00:00
|
|
|
|
|
|
|
|
|
// Set the Species Owned Flag
|
2017-03-22 05:50:55 +00:00
|
|
|
|
Data[ofs + brSize * 0] |= mask;
|
2016-07-04 20:06:01 +00:00
|
|
|
|
|
2017-02-24 05:25:56 +00:00
|
|
|
|
// Check if already Seen
|
2017-03-22 05:50:55 +00:00
|
|
|
|
if ((Data[ofs + brSize * 1] & mask) == 0) // Not seen
|
2017-02-24 05:25:56 +00:00
|
|
|
|
{
|
2017-07-09 02:33:20 +00:00
|
|
|
|
Data[ofs + brSize * 1] |= mask; // Set seen
|
2017-03-07 06:43:46 +00:00
|
|
|
|
int gr = pkm.PersonalInfo.Gender;
|
|
|
|
|
switch (gr)
|
2017-02-24 05:25:56 +00:00
|
|
|
|
{
|
2017-03-07 06:43:46 +00:00
|
|
|
|
case 255: // Genderless
|
|
|
|
|
case 0: // Male Only
|
2017-03-22 05:50:55 +00:00
|
|
|
|
Data[ofs + brSize * 2] &= mask;
|
2017-07-09 02:33:20 +00:00
|
|
|
|
Data[ofs + brSize * 3] &= mask;
|
2017-03-07 06:43:46 +00:00
|
|
|
|
break;
|
|
|
|
|
case 254: // Female Only
|
2017-03-22 05:50:55 +00:00
|
|
|
|
Data[ofs + brSize * 2] |= mask;
|
2017-07-09 02:33:20 +00:00
|
|
|
|
Data[ofs + brSize * 3] |= mask;
|
2017-03-07 06:43:46 +00:00
|
|
|
|
break;
|
|
|
|
|
default: // Male or Female
|
2017-07-09 02:33:20 +00:00
|
|
|
|
bool m = (Data[ofs + brSize * 2] & mask) != 0;
|
|
|
|
|
bool f = (Data[ofs + brSize * 3] & mask) != 0;
|
|
|
|
|
if (m || f) // bit already set?
|
|
|
|
|
break;
|
|
|
|
|
int gender = pkm.Gender & 1;
|
|
|
|
|
Data[ofs + brSize * 2] &= (byte)~mask; // unset
|
|
|
|
|
Data[ofs + brSize * 3] &= (byte)~mask; // unset
|
|
|
|
|
gender ^= 1; // Set OTHER gender seen bit so it appears second
|
|
|
|
|
Data[ofs + brSize * (2 + gender)] |= mask;
|
2017-03-07 06:43:46 +00:00
|
|
|
|
break;
|
2017-02-24 05:25:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-04 20:06:01 +00:00
|
|
|
|
|
2017-03-22 05:50:55 +00:00
|
|
|
|
int FormOffset1 = PokeDex + 4 + brSize * 4 + 4;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var forms = GetForms(pkm.Species);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
if (forms != null)
|
2016-08-28 06:30:49 +00:00
|
|
|
|
{
|
2017-03-07 06:43:46 +00:00
|
|
|
|
if (pkm.Species == 201) // Unown
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 0x1C; i++)
|
|
|
|
|
{
|
|
|
|
|
byte val = Data[FormOffset1 + 4 + i];
|
|
|
|
|
if (val == pkm.AltForm)
|
|
|
|
|
break; // already set
|
|
|
|
|
if (val != 0xFF)
|
|
|
|
|
continue; // keep searching
|
|
|
|
|
|
|
|
|
|
Data[FormOffset1 + 4 + i] = (byte)pkm.AltForm;
|
|
|
|
|
break; // form now set
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2016-08-28 06:30:49 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
CheckInsertForm(ref forms, pkm.AltForm);
|
|
|
|
|
SetForms(pkm.Species, forms);
|
2016-08-28 06:30:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-07 04:47:28 +00:00
|
|
|
|
int[] DPLangSpecies = { 23, 25, 54, 77, 120, 129, 202, 214, 215, 216, 228, 278, 287, 315 };
|
2017-03-22 05:50:55 +00:00
|
|
|
|
int dpl = 1 + Array.IndexOf(DPLangSpecies, pkm.Species);
|
|
|
|
|
if (DP && dpl <= 0)
|
2016-08-28 06:30:49 +00:00
|
|
|
|
return;
|
2016-08-27 20:07:21 +00:00
|
|
|
|
|
2016-08-28 06:30:49 +00:00
|
|
|
|
// Set the Language
|
|
|
|
|
int lang = pkm.Language - 1;
|
|
|
|
|
if (lang > 5) lang = 0; // no KOR
|
|
|
|
|
if (lang < 0) lang = 1;
|
2017-03-07 06:43:46 +00:00
|
|
|
|
int PokeDexLanguageFlags = FormOffset1 + (HGSS ? 0x3C : 0x20);
|
2017-03-22 05:50:55 +00:00
|
|
|
|
Data[PokeDexLanguageFlags + (DP ? dpl : pkm.Species)] |= (byte)(1 << lang);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override bool GetCaught(int species)
|
2017-03-15 05:41:15 +00:00
|
|
|
|
{
|
|
|
|
|
int bit = species - 1;
|
|
|
|
|
int bd = bit >> 3; // div8
|
|
|
|
|
int bm = bit & 7; // mod8
|
|
|
|
|
int ofs = PokeDex // Raw Offset
|
|
|
|
|
+ 0x4; // Magic
|
|
|
|
|
return (1 << bm & Data[ofs + bd]) != 0;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override bool GetSeen(int species)
|
2017-03-15 05:41:15 +00:00
|
|
|
|
{
|
|
|
|
|
const int brSize = 0x40;
|
|
|
|
|
|
|
|
|
|
int bit = species - 1;
|
|
|
|
|
int bd = bit >> 3; // div8
|
|
|
|
|
int bm = bit & 7; // mod8
|
|
|
|
|
int ofs = PokeDex // Raw Offset
|
|
|
|
|
+ 0x4; // Magic
|
|
|
|
|
|
|
|
|
|
return (1 << bm & Data[ofs + bd + brSize*1]) != 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public int[] GetForms(int species)
|
2017-03-07 06:43:46 +00:00
|
|
|
|
{
|
|
|
|
|
const int brSize = 0x40;
|
|
|
|
|
if (species == 386)
|
|
|
|
|
{
|
|
|
|
|
uint val = (uint) (Data[PokeDex + 0x4 + 1*brSize - 1] | Data[PokeDex + 0x4 + 2*brSize - 1] << 8);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetDexFormValues(val, 4, 4);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int FormOffset1 = PokeDex + 4 + 4*brSize + 4;
|
|
|
|
|
switch (species)
|
|
|
|
|
{
|
|
|
|
|
case 422: // Shellos
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetDexFormValues(Data[FormOffset1 + 0], 1, 2);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
case 423: // Gastrodon
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetDexFormValues(Data[FormOffset1 + 1], 1, 2);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
case 412: // Burmy
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetDexFormValues(Data[FormOffset1 + 2], 2, 3);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
case 413: // Wormadam
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetDexFormValues(Data[FormOffset1 + 3], 2, 3);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
case 201: // Unown
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetData(FormOffset1 + 4, 0x1C).Select(i => (int)i).ToArray();
|
2017-03-07 06:43:46 +00:00
|
|
|
|
}
|
2017-03-22 05:50:55 +00:00
|
|
|
|
if (DP)
|
2017-03-07 06:43:46 +00:00
|
|
|
|
return null;
|
2016-08-28 06:30:49 +00:00
|
|
|
|
|
2017-03-07 06:43:46 +00:00
|
|
|
|
int PokeDexLanguageFlags = FormOffset1 + (HGSS ? 0x3C : 0x20);
|
|
|
|
|
int FormOffset2 = PokeDexLanguageFlags + 0x1F4;
|
|
|
|
|
switch (species)
|
2016-08-28 06:30:49 +00:00
|
|
|
|
{
|
2017-03-07 06:43:46 +00:00
|
|
|
|
case 479: // Rotom
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetDexFormValues(BitConverter.ToUInt32(Data, FormOffset2), 3, 6);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
case 492: // Shaymin
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetDexFormValues(Data[FormOffset2 + 4], 1, 2);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
case 487: // Giratina
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetDexFormValues(Data[FormOffset2 + 5], 1, 2);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
case 172:
|
|
|
|
|
if (!HGSS)
|
|
|
|
|
return null;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetDexFormValues(Data[FormOffset2 + 6], 2, 3);
|
2016-08-28 06:30:49 +00:00
|
|
|
|
}
|
2017-03-07 06:43:46 +00:00
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public void SetForms(int spec, int[] forms)
|
2017-03-07 06:43:46 +00:00
|
|
|
|
{
|
|
|
|
|
const int brSize = 0x40;
|
|
|
|
|
switch (spec)
|
2016-08-28 06:30:49 +00:00
|
|
|
|
{
|
2017-03-07 06:43:46 +00:00
|
|
|
|
case 386: // Deoxys
|
2017-06-18 01:37:19 +00:00
|
|
|
|
uint newval = SetDexFormValues(forms, 4, 4);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
Data[PokeDex + 0x4 + 1*brSize - 1] = (byte) (newval & 0xFF);
|
|
|
|
|
Data[PokeDex + 0x4 + 2*brSize - 1] = (byte) ((newval >> 8) & 0xFF);
|
|
|
|
|
break;
|
2016-08-28 06:30:49 +00:00
|
|
|
|
}
|
2017-03-07 06:43:46 +00:00
|
|
|
|
|
|
|
|
|
int FormOffset1 = PokeDex + 4 + 4*brSize + 4;
|
|
|
|
|
switch (spec)
|
2016-08-28 06:30:49 +00:00
|
|
|
|
{
|
2017-03-07 06:43:46 +00:00
|
|
|
|
case 422: // Shellos
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Data[FormOffset1 + 0] = (byte)SetDexFormValues(forms, 1, 2);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
return;
|
|
|
|
|
case 423: // Gastrodon
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Data[FormOffset1 + 1] = (byte)SetDexFormValues(forms, 1, 2);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
return;
|
|
|
|
|
case 412: // Burmy
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Data[FormOffset1 + 2] = (byte)SetDexFormValues(forms, 2, 3);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
return;
|
|
|
|
|
case 413: // Wormadam
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Data[FormOffset1 + 3] = (byte)SetDexFormValues(forms, 2, 3);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
return;
|
|
|
|
|
case 201: // Unown
|
|
|
|
|
int ofs = FormOffset1 + 4;
|
|
|
|
|
int len = forms.Length;
|
|
|
|
|
Array.Resize(ref forms, 0x1C);
|
|
|
|
|
for (int i = len; i < forms.Length; i++)
|
|
|
|
|
forms[i] = 0xFF;
|
|
|
|
|
Array.Copy(forms.Select(b => (byte)b).ToArray(), 0, Data, ofs, forms.Length);
|
|
|
|
|
return;
|
2016-08-28 06:30:49 +00:00
|
|
|
|
}
|
2017-03-07 06:43:46 +00:00
|
|
|
|
|
|
|
|
|
if (DP)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int PokeDexLanguageFlags = FormOffset1 + (HGSS ? 0x3C : 0x20);
|
|
|
|
|
int FormOffset2 = PokeDexLanguageFlags + 0x1F4;
|
|
|
|
|
switch (spec)
|
2016-08-28 06:30:49 +00:00
|
|
|
|
{
|
2017-03-07 06:43:46 +00:00
|
|
|
|
case 479: // Rotom
|
2017-06-18 01:37:19 +00:00
|
|
|
|
BitConverter.GetBytes(SetDexFormValues(forms, 3, 6)).CopyTo(Data, FormOffset2);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
return;
|
|
|
|
|
case 492: // Shaymin
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Data[FormOffset2 + 4] = (byte)SetDexFormValues(forms, 1, 2);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
return;
|
|
|
|
|
case 487: // Giratina
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Data[FormOffset2 + 5] = (byte)SetDexFormValues(forms, 1, 2);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
return;
|
|
|
|
|
case 172: // Pichu
|
|
|
|
|
if (!HGSS)
|
|
|
|
|
return;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Data[FormOffset2 + 6] = (byte)SetDexFormValues(forms, 2, 3);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
return;
|
2016-08-28 06:30:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-07 06:43:46 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static int[] GetDexFormValues(uint Value, int BitsPerForm, int readCt)
|
2016-08-28 06:30:49 +00:00
|
|
|
|
{
|
|
|
|
|
int[] Forms = new int[readCt];
|
|
|
|
|
int n1 = 0xFF >> (8 - BitsPerForm);
|
|
|
|
|
for (int i = 0; i < Forms.Length; i++)
|
|
|
|
|
{
|
2017-03-22 05:50:55 +00:00
|
|
|
|
int val = (int)(Value >> (i * BitsPerForm)) & n1;
|
|
|
|
|
if (n1 == val && BitsPerForm > 1)
|
2016-08-28 06:30:49 +00:00
|
|
|
|
Forms[i] = -1;
|
|
|
|
|
else
|
|
|
|
|
Forms[i] = val;
|
|
|
|
|
}
|
|
|
|
|
return Forms;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static uint SetDexFormValues(int[] Forms, int BitsPerForm, int readCt)
|
2016-08-28 06:30:49 +00:00
|
|
|
|
{
|
|
|
|
|
int n1 = 0xFF >> (8 - BitsPerForm);
|
|
|
|
|
uint Value = 0xFFFFFFFF << (Forms.Length*BitsPerForm);
|
|
|
|
|
for (int i = 0; i < Forms.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
int val = Forms[i];
|
|
|
|
|
if (val == -1)
|
|
|
|
|
val = n1;
|
|
|
|
|
|
|
|
|
|
Value |= (uint)(val << (BitsPerForm*i));
|
|
|
|
|
}
|
|
|
|
|
return Value;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static bool CheckInsertForm(ref int[] Forms, int FormNum)
|
2016-08-28 06:30:49 +00:00
|
|
|
|
{
|
|
|
|
|
if (Forms.Any(num => num == FormNum))
|
|
|
|
|
{
|
|
|
|
|
return false; // already in list
|
|
|
|
|
}
|
|
|
|
|
if (Forms.All(num => num == -1))
|
|
|
|
|
{
|
|
|
|
|
Forms[0] = FormNum;
|
|
|
|
|
return true; // none in list, insert at top
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// insert at first empty
|
|
|
|
|
int n1 = Array.IndexOf(Forms, -1);
|
|
|
|
|
if (n1 < 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
Forms[n1] = FormNum;
|
|
|
|
|
return true;
|
2016-07-04 20:06:01 +00:00
|
|
|
|
}
|
2017-03-22 05:50:55 +00:00
|
|
|
|
public int DexUpgraded
|
2017-03-21 03:14:37 +00:00
|
|
|
|
{
|
2017-03-22 05:50:55 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
|
|
|
|
case GameVersion.DP:
|
2017-06-10 13:12:51 +00:00
|
|
|
|
if (Data[0x1413 + GBO] != 0) return 4;
|
|
|
|
|
else if (Data[0x1415 + GBO] != 0) return 3;
|
|
|
|
|
else if (Data[0x1404 + GBO] != 0) return 2;
|
|
|
|
|
else if (Data[0x1414 + GBO] != 0) return 1;
|
2017-03-22 05:50:55 +00:00
|
|
|
|
else return 0;
|
|
|
|
|
case GameVersion.HGSS:
|
2017-06-10 13:12:51 +00:00
|
|
|
|
if (Data[0x15ED + GBO] != 0) return 3;
|
|
|
|
|
else if (Data[0x15EF + GBO] != 0) return 2;
|
|
|
|
|
else if (Data[0x15EE + GBO] != 0 && (Data[0x10D1 + GBO] & 8) != 0) return 1;
|
|
|
|
|
else return 0;
|
|
|
|
|
case GameVersion.Pt:
|
|
|
|
|
if (Data[0x1641 + GBO] != 0) return 4;
|
|
|
|
|
else if (Data[0x1643 + GBO] != 0) return 3;
|
|
|
|
|
else if (Data[0x1640 + GBO] != 0) return 2;
|
|
|
|
|
else if (Data[0x1642 + GBO] != 0) return 1;
|
2017-03-22 05:50:55 +00:00
|
|
|
|
else return 0;
|
|
|
|
|
default: return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
|
|
|
|
case GameVersion.DP:
|
2017-06-10 13:12:51 +00:00
|
|
|
|
Data[0x1413 + GBO] = (byte)(value == 4 ? 1 : 0);
|
|
|
|
|
Data[0x1415 + GBO] = (byte)(value >= 3 ? 1 : 0);
|
|
|
|
|
Data[0x1404 + GBO] = (byte)(value >= 2 ? 1 : 0);
|
|
|
|
|
Data[0x1414 + GBO] = (byte)(value >= 1 ? 1 : 0);
|
2017-03-22 05:50:55 +00:00
|
|
|
|
break;
|
|
|
|
|
case GameVersion.HGSS:
|
2017-06-10 13:12:51 +00:00
|
|
|
|
Data[0x15ED + GBO] = (byte)(value == 3 ? 1 : 0);
|
|
|
|
|
Data[0x15EF + GBO] = (byte)(value >= 2 ? 1 : 0);
|
|
|
|
|
Data[0x15EE + GBO] = (byte)(value >= 1 ? 1 : 0);
|
|
|
|
|
Data[0x10D1 + GBO] = (byte)(Data[0x10D1 + GBO] & ~8 | (value >= 1 ? 8 : 0));
|
|
|
|
|
break;
|
|
|
|
|
case GameVersion.Pt:
|
|
|
|
|
Data[0x1641 + GBO] = (byte)(value == 4 ? 1 : 0);
|
|
|
|
|
Data[0x1643 + GBO] = (byte)(value >= 3 ? 1 : 0);
|
|
|
|
|
Data[0x1640 + GBO] = (byte)(value >= 2 ? 1 : 0);
|
|
|
|
|
Data[0x1642 + GBO] = (byte)(value >= 1 ? 1 : 0);
|
2017-03-22 05:50:55 +00:00
|
|
|
|
break;
|
|
|
|
|
default: return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-21 03:14:37 +00:00
|
|
|
|
}
|
2017-04-07 04:47:28 +00:00
|
|
|
|
|
|
|
|
|
// Honey Trees
|
2017-06-10 13:12:51 +00:00
|
|
|
|
private int OFS_HONEY = int.MinValue;
|
2017-04-07 04:47:28 +00:00
|
|
|
|
private const int HONEY_SIZE = 8;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public HoneyTree GetHoneyTree(int index)
|
2017-04-07 04:47:28 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (OFS_HONEY <= 0 || index > 21)
|
|
|
|
|
return null;
|
|
|
|
|
return new HoneyTree(GetData(OFS_HONEY + HONEY_SIZE * index, HONEY_SIZE));
|
2017-04-07 04:47:28 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public void SetHoneyTree(HoneyTree tree, int index)
|
2017-04-07 04:47:28 +00:00
|
|
|
|
{
|
2017-06-10 13:12:51 +00:00
|
|
|
|
if (index <= 21 && OFS_HONEY > 0)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetData(tree.Data, OFS_HONEY + HONEY_SIZE * index);
|
2017-04-07 04:47:28 +00:00
|
|
|
|
}
|
|
|
|
|
public int[] MunchlaxTrees
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
int A = (TID >> 8) % 21;
|
|
|
|
|
int B = (TID & 0x00FF) % 21;
|
|
|
|
|
int C = (SID >> 8) % 21;
|
|
|
|
|
int D = (SID & 0x00FF) % 21;
|
|
|
|
|
|
|
|
|
|
if (A == B) B = (B + 1) % 21;
|
|
|
|
|
if (A == C) C = (C + 1) % 21;
|
|
|
|
|
if (B == C) C = (C + 1) % 21;
|
|
|
|
|
if (A == D) D = (D + 1) % 21;
|
|
|
|
|
if (B == D) D = (D + 1) % 21;
|
|
|
|
|
if (C == D) D = (D + 1) % 21;
|
|
|
|
|
|
|
|
|
|
return new[] { A, B, C, D };
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-09 21:07:56 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override string GetString(int Offset, int Count) => PKX.GetString4(Data, Offset, Count);
|
|
|
|
|
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-06-18 01:37:19 +00:00
|
|
|
|
return PKX.SetString4(value, maxLength, PadToSize, PadWith);
|
2017-04-09 21:06:50 +00:00
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|