2016-10-20 01:19:01 +00:00
|
|
|
|
using System;
|
2017-07-02 02:43:51 +00:00
|
|
|
|
using System.Diagnostics;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-10-20 01:19:01 +00:00
|
|
|
|
{
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generation 7 <see cref="SaveFile"/> object.
|
|
|
|
|
/// </summary>
|
2018-12-19 01:15:35 +00:00
|
|
|
|
public sealed class SAV7 : SaveFile, ITrainerStatRecord, ISecureValueStorage
|
2016-10-20 01:19:01 +00:00
|
|
|
|
{
|
|
|
|
|
// Save Data Attributes
|
2018-07-30 04:51:45 +00:00
|
|
|
|
protected override string BAKText => $"{OT} ({Version}) - {LastSavedTime}";
|
2016-10-20 01:19:01 +00:00
|
|
|
|
public override string Filter => "Main SAV|*.*";
|
2019-02-08 05:40:20 +00:00
|
|
|
|
public override string Extension => string.Empty;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-01-05 06:22:50 +00:00
|
|
|
|
public override string[] PKMExtensions => PKM.Extensions.Where(f =>
|
|
|
|
|
{
|
|
|
|
|
int gen = f.Last() - 0x30;
|
2019-02-10 04:33:37 +00:00
|
|
|
|
return gen <= 7 && f[1] != 'b'; // ignore PB7
|
2017-01-05 06:22:50 +00:00
|
|
|
|
}).ToArray();
|
|
|
|
|
|
2016-10-20 01:19:01 +00:00
|
|
|
|
public SAV7(byte[] data = null)
|
|
|
|
|
{
|
2017-12-27 05:38:19 +00:00
|
|
|
|
Data = data ?? new byte[SaveUtil.SIZE_G7SM];
|
2016-10-20 01:19:01 +00:00
|
|
|
|
BAK = (byte[])Data.Clone();
|
2018-03-18 23:22:21 +00:00
|
|
|
|
Exportable = !IsRangeEmpty(0, Data.Length);
|
2016-10-20 01:19:01 +00:00
|
|
|
|
|
|
|
|
|
// Load Info
|
2018-02-19 19:33:37 +00:00
|
|
|
|
Blocks = BlockInfo3DS.GetBlockInfoData(Data, out BlockInfoOffset, SaveUtil.CRC16);
|
|
|
|
|
if (Exportable)
|
|
|
|
|
CanReadChecksums();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
GetSAVOffsets();
|
2016-10-20 01:19:01 +00:00
|
|
|
|
|
2017-10-31 16:24:54 +00:00
|
|
|
|
HeldItems = USUM ? Legal.HeldItems_USUM : Legal.HeldItems_SM;
|
2017-09-19 05:36:06 +00:00
|
|
|
|
Personal = USUM ? PersonalTable.USUM : PersonalTable.SM;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
if (!Exportable)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
ClearBoxes();
|
2016-11-08 16:43:57 +00:00
|
|
|
|
|
2017-10-31 16:24:54 +00:00
|
|
|
|
var demo = !USUM && Data.Skip(PCLayout).Take(0x4C4).All(z => z == 0); // up to Battle Box values
|
2016-12-16 16:50:50 +00:00
|
|
|
|
if (demo || !Exportable)
|
2016-11-08 16:43:57 +00:00
|
|
|
|
{
|
|
|
|
|
PokeDex = -1; // Disabled
|
2018-08-02 01:30:51 +00:00
|
|
|
|
TeamSlots = Array.Empty<int>();
|
2016-11-08 16:43:57 +00:00
|
|
|
|
}
|
2016-12-16 16:50:50 +00:00
|
|
|
|
else // Valid slot locking info present
|
2016-12-16 07:17:17 +00:00
|
|
|
|
{
|
2018-12-05 06:59:28 +00:00
|
|
|
|
LoadBattleTeams();
|
2016-12-16 07:17:17 +00:00
|
|
|
|
}
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2016-10-20 01:19:01 +00:00
|
|
|
|
// Configuration
|
2019-02-19 05:59:57 +00:00
|
|
|
|
public override SaveFile Clone() => new SAV7((byte[])Data.Clone());
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2016-10-20 01:19:01 +00:00
|
|
|
|
public override int SIZE_STORED => PKX.SIZE_6STORED;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected override int SIZE_PARTY => PKX.SIZE_6PARTY;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
public override PKM BlankPKM => new PK7();
|
|
|
|
|
public override Type PKMType => typeof(PK7);
|
|
|
|
|
|
|
|
|
|
public override int BoxCount => 32;
|
|
|
|
|
public override int MaxEV => 252;
|
|
|
|
|
public override int Generation => 7;
|
2016-10-27 05:06:03 +00:00
|
|
|
|
protected override int GiftCountMax => 48;
|
|
|
|
|
protected override int GiftFlagMax => 0x100 * 8;
|
2017-11-12 02:58:57 +00:00
|
|
|
|
protected override int EventFlagMax => USUM ? 4928 : 3968;
|
2017-11-13 05:28:34 +00:00
|
|
|
|
protected override int EventConstMax => 1000;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
public override int OTLength => 12;
|
|
|
|
|
public override int NickLength => 12;
|
|
|
|
|
|
2017-10-06 05:37:45 +00:00
|
|
|
|
public override int MaxMoveID => SM ? Legal.MaxMoveID_7 : Legal.MaxMoveID_7_USUM;
|
2017-11-08 08:51:08 +00:00
|
|
|
|
public override int MaxSpeciesID => SM ? Legal.MaxSpeciesID_7 : Legal.MaxSpeciesID_7_USUM;
|
2017-10-11 02:30:55 +00:00
|
|
|
|
public override int MaxItemID => SM ? Legal.MaxItemID_7 : Legal.MaxItemID_7_USUM;
|
2017-11-08 08:51:08 +00:00
|
|
|
|
public override int MaxAbilityID => SM ? Legal.MaxAbilityID_7 : Legal.MaxAbilityID_7_USUM;
|
2017-01-27 03:18:20 +00:00
|
|
|
|
public override int MaxBallID => Legal.MaxBallID_7; // 26
|
|
|
|
|
public override int MaxGameID => Legal.MaxGameID_7;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
|
2016-11-12 22:57:54 +00:00
|
|
|
|
public int QRSaveData;
|
|
|
|
|
|
2016-10-20 01:19:01 +00:00
|
|
|
|
// Feature Overrides
|
|
|
|
|
|
|
|
|
|
// Blocks & Offsets
|
2018-02-19 19:33:37 +00:00
|
|
|
|
private readonly int BlockInfoOffset;
|
|
|
|
|
private readonly BlockInfo[] Blocks;
|
2017-11-14 03:34:50 +00:00
|
|
|
|
private bool IsMemeCryptoApplied = true;
|
2017-11-08 23:07:04 +00:00
|
|
|
|
private const int MemeCryptoBlock = 36;
|
2018-02-19 19:33:37 +00:00
|
|
|
|
public override bool ChecksumsValid => CanReadChecksums() && Blocks.GetChecksumsValid(Data);
|
|
|
|
|
public override string ChecksumInfo => CanReadChecksums() ? Blocks.GetChecksumInfo(Data) : string.Empty;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-11-04 22:04:21 +00:00
|
|
|
|
private bool CanReadChecksums()
|
|
|
|
|
{
|
2017-11-14 03:34:50 +00:00
|
|
|
|
if (Blocks.Length <= MemeCryptoBlock)
|
|
|
|
|
{ Debug.WriteLine($"Not enough blocks ({Blocks.Length}), aborting {nameof(CanReadChecksums)}"); return false; }
|
|
|
|
|
if (!IsMemeCryptoApplied)
|
|
|
|
|
return true;
|
|
|
|
|
// clear memecrypto sig
|
|
|
|
|
new byte[0x80].CopyTo(Data, Blocks[MemeCryptoBlock].Offset + 0x100);
|
|
|
|
|
IsMemeCryptoApplied = false;
|
2017-11-04 22:04:21 +00:00
|
|
|
|
return true;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected override void SetChecksums()
|
2016-10-20 01:19:01 +00:00
|
|
|
|
{
|
2017-11-04 22:04:21 +00:00
|
|
|
|
if (!CanReadChecksums())
|
2016-10-20 01:19:01 +00:00
|
|
|
|
return;
|
2018-02-19 19:33:37 +00:00
|
|
|
|
Blocks.SetChecksums(Data);
|
2018-12-05 06:59:28 +00:00
|
|
|
|
SaveBattleTeams();
|
2016-11-08 16:43:57 +00:00
|
|
|
|
Data = SaveUtil.Resign7(Data);
|
2017-11-14 03:34:50 +00:00
|
|
|
|
IsMemeCryptoApplied = true;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2017-11-04 22:04:21 +00:00
|
|
|
|
|
2018-12-19 01:15:35 +00:00
|
|
|
|
public ulong TimeStampCurrent
|
2016-10-27 05:06:03 +00:00
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt64(Data, BlockInfoOffset - 0x14);
|
2018-12-19 01:15:35 +00:00
|
|
|
|
set => BitConverter.GetBytes(value).CopyTo(Data, BlockInfoOffset - 0x14);
|
2016-10-27 05:06:03 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-12-19 01:15:35 +00:00
|
|
|
|
public ulong TimeStampPrevious
|
2016-10-27 05:06:03 +00:00
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt64(Data, BlockInfoOffset - 0xC);
|
2018-12-19 01:15:35 +00:00
|
|
|
|
set => BitConverter.GetBytes(value).CopyTo(Data, BlockInfoOffset - 0xC);
|
2016-10-27 05:06:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void GetSAVOffsets()
|
2016-10-20 01:19:01 +00:00
|
|
|
|
{
|
2017-11-08 08:34:32 +00:00
|
|
|
|
if (!Exportable) // Empty input
|
2016-10-20 01:19:01 +00:00
|
|
|
|
{
|
2017-11-10 03:26:31 +00:00
|
|
|
|
// Set bare minimum values for empty sav compatibility (based on S/M offsets)
|
|
|
|
|
Trainer1 = 0x00E00;
|
|
|
|
|
TrainerCard = 0x01200;
|
|
|
|
|
Party = 0x01400;
|
|
|
|
|
Box = 0x04E00;
|
|
|
|
|
PCLayout = 0x04800;
|
2017-11-08 08:34:32 +00:00
|
|
|
|
BattleBoxFlags = PCLayout + 0x4C4;
|
|
|
|
|
PCBackgrounds = PCLayout + 0x5C0;
|
|
|
|
|
LastViewedBox = PCLayout + 0x5E3;
|
|
|
|
|
PCFlags = PCLayout + 0x5E0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 00 */ Bag = Blocks[00].Offset; // 0x00000 // [DE0] MyItem
|
|
|
|
|
/* 01 */ Trainer1 = Blocks[01].Offset; // 0x00E00 // [07C] Situation
|
|
|
|
|
/* 02 */ // = Blocks[02].Offset; // 0x01000 // [014] RandomGroup
|
|
|
|
|
/* 03 */ TrainerCard = Blocks[03].Offset; // 0x01200 // [0C0] MyStatus
|
|
|
|
|
/* 04 */ Party = Blocks[04].Offset; // 0x01400 // [61C] PokePartySave
|
|
|
|
|
/* 05 */ EventConst = Blocks[05].Offset; // 0x01C00 // [E00] EventWork
|
|
|
|
|
/* 06 */ PokeDex = Blocks[06].Offset; // 0x02A00 // [F78] ZukanData
|
|
|
|
|
/* 07 */ GTS = Blocks[07].Offset; // 0x03A00 // [228] GtsData
|
2018-05-12 15:41:23 +00:00
|
|
|
|
/* 08 */ Fused = Blocks[08].Offset; // 0x03E00 // [104] UnionPokemon
|
2017-11-08 08:34:32 +00:00
|
|
|
|
/* 09 */ Misc = Blocks[09].Offset; // 0x04000 // [200] Misc
|
|
|
|
|
/* 10 */ Trainer2 = Blocks[10].Offset; // 0x04200 // [020] FieldMenu
|
|
|
|
|
/* 11 */ ConfigSave = Blocks[11].Offset; // 0x04400 // [004] ConfigSave
|
|
|
|
|
/* 12 */ AdventureInfo = Blocks[12].Offset; // 0x04600 // [058] GameTime
|
|
|
|
|
/* 13 */ PCLayout = Blocks[13].Offset; // 0x04800 // [5E6] BOX
|
|
|
|
|
/* 14 */ Box = Blocks[14].Offset; // 0x04E00 // [36600] BoxPokemon
|
|
|
|
|
/* 15 */ Resort = Blocks[15].Offset; // 0x3B400 // [572C] ResortSave
|
|
|
|
|
/* 16 */ PlayTime = Blocks[16].Offset; // 0x40C00 // [008] PlayTime
|
|
|
|
|
/* 17 */ Overworld = Blocks[17].Offset; // 0x40E00 // [1080] FieldMoveModelSave
|
|
|
|
|
/* 18 */ Fashion = Blocks[18].Offset; // 0x42000 // [1A08] Fashion
|
|
|
|
|
/* 19 */ // = Blocks[19].Offset; // 0x43C00 // [6408] JoinFestaPersonalSave
|
|
|
|
|
/* 20 */ // = Blocks[20].Offset; // 0x4A200 // [6408] JoinFestaPersonalSave
|
|
|
|
|
/* 21 */ JoinFestaData = Blocks[21].Offset; // 0x50800 // [3998] JoinFestaDataSave
|
|
|
|
|
/* 22 */ // = Blocks[22].Offset; // 0x54200 // [100] BerrySpot
|
|
|
|
|
/* 23 */ // = Blocks[23].Offset; // 0x54400 // [100] FishingSpot
|
|
|
|
|
/* 24 */ // = Blocks[24].Offset; // 0x54600 // [10528] LiveMatchData
|
|
|
|
|
/* 25 */ // = Blocks[25].Offset; // 0x64C00 // [204] BattleSpotData
|
|
|
|
|
/* 26 */ PokeFinderSave = Blocks[26].Offset; // 0x65000 // [B60] PokeFinderSave
|
|
|
|
|
/* 27 */ WondercardFlags= Blocks[27].Offset; // 0x65C00 // [3F50] MysteryGiftSave
|
|
|
|
|
/* 28 */ Record = Blocks[28].Offset; // 0x69C00 // [358] Record
|
|
|
|
|
/* 29 */ // = Blocks[29].Offset; // 0x6A000 // [728] ValidationSave
|
|
|
|
|
/* 30 */ // = Blocks[30].Offset; // 0x6A800 // [200] GameSyncSave
|
|
|
|
|
/* 31 */ // = Blocks[31].Offset; // 0x6AA00 // [718] PokeDiarySave
|
|
|
|
|
/* 32 */ BattleTree = Blocks[32].Offset; // 0x6B200 // [1FC] BattleInstSave
|
|
|
|
|
/* 33 */ Daycare = Blocks[33].Offset; // 0x6B400 // [200] Sodateya
|
|
|
|
|
/* 34 */ // = Blocks[34].Offset; // 0x6B600 // [120] WeatherSave
|
|
|
|
|
/* 35 */ QRSaveData = Blocks[35].Offset; // 0x6B800 // [1C8] QRReaderSaveData
|
|
|
|
|
/* 36 */ // = Blocks[36].Offset; // 0x6BA00 // [200] TurtleSalmonSave
|
|
|
|
|
|
2018-09-15 05:37:47 +00:00
|
|
|
|
EventFlag = EventConst + (EventConstMax * 2); // After Event Const (u16)*n
|
|
|
|
|
HoF = EventFlag + (EventFlagMax / 8); // After Event Flags (1b)*(1u8/8b)*n
|
2017-11-08 08:34:32 +00:00
|
|
|
|
|
|
|
|
|
OFS_PouchHeldItem = Bag + 0; // 430 (Case 0)
|
|
|
|
|
OFS_PouchKeyItem = Bag + 0x6B8; // 184 (Case 4)
|
|
|
|
|
OFS_PouchTMHM = Bag + 0x998; // 108 (Case 2)
|
|
|
|
|
OFS_PouchMedicine = Bag + 0xB48; // 64 (Case 1)
|
|
|
|
|
OFS_PouchBerry = Bag + 0xC48; // 72 (Case 3)
|
|
|
|
|
OFS_PouchZCrystals = Bag + 0xD68; // 30 (Case 5)
|
|
|
|
|
|
|
|
|
|
PokeDexLanguageFlags = PokeDex + 0x550;
|
|
|
|
|
WondercardData = WondercardFlags + 0x100;
|
|
|
|
|
|
|
|
|
|
BattleBoxFlags = PCLayout + 0x4C4;
|
|
|
|
|
PCBackgrounds = PCLayout + 0x5C0;
|
|
|
|
|
LastViewedBox = PCLayout + 0x5E3;
|
|
|
|
|
PCFlags = PCLayout + 0x5E0;
|
|
|
|
|
|
|
|
|
|
FashionLength = 0x1A08;
|
|
|
|
|
|
|
|
|
|
TeamCount = 6;
|
|
|
|
|
TeamSlots = new int[6*TeamCount];
|
|
|
|
|
if (USUM)
|
|
|
|
|
{
|
|
|
|
|
// slight differences
|
|
|
|
|
/* 37 */ // = Blocks[37].Offset; BattleFesSave
|
|
|
|
|
/* 38 */ // = Blocks[38].Offset; FinderStudioSave
|
|
|
|
|
|
|
|
|
|
OFS_PouchHeldItem = Bag + 0; // 427 (Case 0)
|
2018-09-15 05:37:47 +00:00
|
|
|
|
OFS_PouchKeyItem = OFS_PouchHeldItem + (4 * 427); // 198 (Case 4)
|
|
|
|
|
OFS_PouchTMHM = OFS_PouchKeyItem + (4 * 198); // 108 (Case 2)
|
|
|
|
|
OFS_PouchMedicine = OFS_PouchTMHM + (4 * 108); // 60 (Case 1)
|
|
|
|
|
OFS_PouchBerry = OFS_PouchMedicine + (4 * 60); // 67 (Case 3)
|
|
|
|
|
OFS_PouchZCrystals = OFS_PouchBerry + (4 * 67); // 35 (Case 5)
|
|
|
|
|
OFS_BattleItems = OFS_PouchZCrystals + (4 * 35); // 11 (Case 6)
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Private Only
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private int Bag { get; set; } = int.MinValue;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
private int AdventureInfo { get; set; } = int.MinValue;
|
|
|
|
|
private int Trainer2 { get; set; } = int.MinValue;
|
2019-01-26 03:58:00 +00:00
|
|
|
|
public int Misc { get; private set; } = int.MinValue;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
private int LastViewedBox { get; set; } = int.MinValue;
|
|
|
|
|
private int WondercardFlags { get; set; } = int.MinValue;
|
|
|
|
|
private int PlayTime { get; set; } = int.MinValue;
|
2016-11-17 04:57:15 +00:00
|
|
|
|
private int Overworld { get; set; } = int.MinValue;
|
2019-01-26 03:58:00 +00:00
|
|
|
|
public int JoinFestaData { get; private set; } = int.MinValue;
|
2016-11-29 07:02:25 +00:00
|
|
|
|
private int PokeFinderSave { get; set; } = int.MinValue;
|
2016-12-04 21:23:35 +00:00
|
|
|
|
private int BattleTree { get; set; } = int.MinValue;
|
2016-12-16 07:17:17 +00:00
|
|
|
|
private int BattleBoxFlags { get; set; } = int.MinValue;
|
2016-12-27 00:41:12 +00:00
|
|
|
|
private int TeamCount { get; set; } = int.MinValue;
|
2017-10-15 06:47:16 +00:00
|
|
|
|
private int ConfigSave { get; set; } = int.MinValue;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
|
2016-10-23 19:45:27 +00:00
|
|
|
|
// Accessible as SAV7
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private int TrainerCard { get; set; } = 0x14000;
|
|
|
|
|
private int Resort { get; set; }
|
|
|
|
|
private int PCFlags { get; set; } = int.MinValue;
|
|
|
|
|
private int PCBackgrounds { get; set; } = int.MinValue;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
public int PokeDexLanguageFlags { get; private set; } = int.MinValue;
|
2016-11-23 04:28:20 +00:00
|
|
|
|
public int Fashion { get; set; } = int.MinValue;
|
|
|
|
|
public int FashionLength { get; set; } = int.MinValue;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private int Record { get; set; } = int.MinValue;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
|
2018-01-30 04:15:51 +00:00
|
|
|
|
public const int ResortCount = 93;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
public int GetResortSlotOffset(int slot) => Resort + 0x16 + (slot * SIZE_STORED);
|
|
|
|
|
|
2016-10-23 19:45:27 +00:00
|
|
|
|
public PKM[] ResortPKM
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
PKM[] data = new PKM[ResortCount];
|
|
|
|
|
for (int i = 0; i < data.Length; i++)
|
|
|
|
|
{
|
2018-01-30 04:15:51 +00:00
|
|
|
|
data[i] = GetPKM(GetData(GetResortSlotOffset(i), SIZE_STORED));
|
2016-10-23 19:45:27 +00:00
|
|
|
|
data[i].Identifier = $"Resort Slot {i}";
|
|
|
|
|
}
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value?.Length != ResortCount)
|
2019-02-02 07:08:03 +00:00
|
|
|
|
throw new ArgumentException(nameof(ResortCount));
|
2016-10-23 19:45:27 +00:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < value.Length; i++)
|
2018-01-30 04:15:51 +00:00
|
|
|
|
SetStoredSlot(value[i], GetResortSlotOffset(i));
|
2016-10-23 19:45:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-20 01:19:01 +00:00
|
|
|
|
public override GameVersion Version
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
switch (Game)
|
|
|
|
|
{
|
|
|
|
|
case 30: return GameVersion.SN;
|
2016-10-23 03:09:22 +00:00
|
|
|
|
case 31: return GameVersion.MN;
|
2017-11-08 08:34:32 +00:00
|
|
|
|
case 32: return GameVersion.US;
|
|
|
|
|
case 33: return GameVersion.UM;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-03-12 01:07:48 +00:00
|
|
|
|
return GameVersion.Invalid;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2016-10-20 01:19:01 +00:00
|
|
|
|
// Player Information
|
2018-04-28 18:06:58 +00:00
|
|
|
|
public override int TID
|
2016-10-20 01:19:01 +00:00
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt16(Data, TrainerCard + 0);
|
2018-04-28 18:06:58 +00:00
|
|
|
|
set => BitConverter.GetBytes((ushort)value).CopyTo(Data, TrainerCard + 0);
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-04-28 18:06:58 +00:00
|
|
|
|
public override int SID
|
2016-10-20 01:19:01 +00:00
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt16(Data, TrainerCard + 2);
|
2018-04-28 18:06:58 +00:00
|
|
|
|
set => BitConverter.GetBytes((ushort)value).CopyTo(Data, TrainerCard + 2);
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-10-20 01:19:01 +00:00
|
|
|
|
public override int Game
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[TrainerCard + 4];
|
|
|
|
|
set => Data[TrainerCard + 4] = (byte)value;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-10-20 01:19:01 +00:00
|
|
|
|
public override int Gender
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[TrainerCard + 5];
|
|
|
|
|
set => Data[TrainerCard + 5] = (byte)value;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-12-13 06:29:50 +00:00
|
|
|
|
public override int GameSyncIDSize => 16; // 64 bits
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-12-10 20:27:37 +00:00
|
|
|
|
public override string GameSyncID
|
2016-10-20 01:19:01 +00:00
|
|
|
|
{
|
2016-12-10 20:27:37 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-13 06:29:50 +00:00
|
|
|
|
var data = Data.Skip(TrainerCard + 0x10).Take(GameSyncIDSize/2).Reverse().ToArray();
|
2019-02-08 05:40:20 +00:00
|
|
|
|
return BitConverter.ToString(data).Replace("-", string.Empty);
|
2016-12-10 20:27:37 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == null)
|
|
|
|
|
return;
|
|
|
|
|
if (value.Length > GameSyncIDSize)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-12-13 06:29:50 +00:00
|
|
|
|
Enumerable.Range(0, value.Length)
|
|
|
|
|
.Where(x => x % 2 == 0)
|
|
|
|
|
.Reverse()
|
|
|
|
|
.Select(x => Convert.ToByte(value.Substring(x, 2), 16))
|
|
|
|
|
.ToArray().CopyTo(Data, TrainerCard + 0x10);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private const int NexUniqueIDSize = 32; // 128 bits
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-12-13 06:29:50 +00:00
|
|
|
|
public string NexUniqueID
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var data = Data.Skip(TrainerCard + 0x18).Take(NexUniqueIDSize/2).Reverse().ToArray();
|
2019-02-08 05:40:20 +00:00
|
|
|
|
return BitConverter.ToString(data).Replace("-", string.Empty);
|
2016-12-13 06:29:50 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == null)
|
|
|
|
|
return;
|
|
|
|
|
if (value.Length > NexUniqueIDSize)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-12-10 20:27:37 +00:00
|
|
|
|
Enumerable.Range(0, value.Length)
|
|
|
|
|
.Where(x => x % 2 == 0)
|
|
|
|
|
.Reverse()
|
|
|
|
|
.Select(x => Convert.ToByte(value.Substring(x, 2), 16))
|
|
|
|
|
.ToArray().CopyTo(Data, TrainerCard + 0x18);
|
|
|
|
|
}
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-11-19 21:50:30 +00:00
|
|
|
|
public byte[] FestaID // 12byte
|
|
|
|
|
{
|
|
|
|
|
get => Data.Skip(TrainerCard + 0x28).Take(4).Concat(Data.Skip(TrainerCard + 0x18).Take(8)).ToArray();
|
|
|
|
|
set
|
|
|
|
|
{
|
2019-02-20 04:26:20 +00:00
|
|
|
|
if (value?.Length != 12)
|
|
|
|
|
return;
|
2017-11-19 21:50:30 +00:00
|
|
|
|
Array.Copy(value, 0, Data, TrainerCard + 0x28, 4);
|
|
|
|
|
Array.Copy(value, 4, Data, TrainerCard + 0x18, 8);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-10-20 01:19:01 +00:00
|
|
|
|
public override int SubRegion
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[TrainerCard + 0x2E];
|
|
|
|
|
set => Data[TrainerCard + 0x2E] = (byte)value;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-10-20 01:19:01 +00:00
|
|
|
|
public override int Country
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[TrainerCard + 0x2F];
|
|
|
|
|
set => Data[TrainerCard + 0x2F] = (byte)value;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-10-20 01:19:01 +00:00
|
|
|
|
public override int ConsoleRegion
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[TrainerCard + 0x34];
|
|
|
|
|
set => Data[TrainerCard + 0x34] = (byte)value;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-10-20 01:19:01 +00:00
|
|
|
|
public override int Language
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[TrainerCard + 0x35];
|
|
|
|
|
set => Data[TrainerCard + 0x35] = (byte)value;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-10-20 01:19:01 +00:00
|
|
|
|
public override string OT
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
get => GetString(TrainerCard + 0x38, 0x1A);
|
|
|
|
|
set => SetString(value, OTLength).CopyTo(Data, TrainerCard + 0x38);
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-12-30 06:15:25 +00:00
|
|
|
|
public int DressUpSkinColor
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => (Data[TrainerCard + 0x54] >> 2) & 7;
|
|
|
|
|
set => Data[TrainerCard + 0x54] = (byte)((Data[TrainerCard + 0x54] & ~(7 << 2)) | (value << 2));
|
2016-12-30 06:15:25 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-10-15 06:47:16 +00:00
|
|
|
|
public override int MultiplayerSpriteID
|
|
|
|
|
{
|
|
|
|
|
get => Data[TrainerCard + 0x58];
|
|
|
|
|
set => Data[TrainerCard + 0x58] = (byte)value;
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-11-27 21:32:02 +00:00
|
|
|
|
public int BallThrowType
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[TrainerCard + 0x7A];
|
|
|
|
|
set => Data[TrainerCard + 0x7A] = (byte)(value > 8 ? 0 : value);
|
2016-11-27 21:32:02 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-10-15 06:47:16 +00:00
|
|
|
|
public int M // "StartLocation"
|
2016-10-28 04:30:21 +00:00
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt16(Data, Trainer1 + 0x00);
|
|
|
|
|
set => BitConverter.GetBytes((ushort)value).CopyTo(Data, Trainer1 + 0x00);
|
2016-10-28 04:30:21 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-10-28 04:30:21 +00:00
|
|
|
|
public float X
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToSingle(Data, Trainer1 + 0x08);
|
2016-11-17 04:57:15 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
BitConverter.GetBytes(value).CopyTo(Data, Trainer1 + 0x08);
|
|
|
|
|
BitConverter.GetBytes(value).CopyTo(Data, Overworld + 0x08);
|
|
|
|
|
}
|
2016-10-28 04:30:21 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-10-28 04:30:21 +00:00
|
|
|
|
public float Z
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToSingle(Data, Trainer1 + 0x10);
|
2016-11-17 04:57:15 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
BitConverter.GetBytes(value).CopyTo(Data, Trainer1 + 0x10);
|
|
|
|
|
BitConverter.GetBytes(value).CopyTo(Data, Overworld + 0x10);
|
|
|
|
|
}
|
2016-10-28 04:30:21 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-10-28 04:30:21 +00:00
|
|
|
|
public float Y
|
2016-11-17 04:57:15 +00:00
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => (int)BitConverter.ToSingle(Data, Trainer1 + 0x18);
|
2016-11-17 04:57:15 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
BitConverter.GetBytes(value).CopyTo(Data, Trainer1 + 0x18);
|
|
|
|
|
BitConverter.GetBytes(value).CopyTo(Data, Overworld + 0x18);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-11-17 04:57:15 +00:00
|
|
|
|
public float R
|
2016-10-28 04:30:21 +00:00
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => (int)BitConverter.ToSingle(Data, Trainer1 + 0x20);
|
2016-11-17 04:57:15 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
BitConverter.GetBytes(value).CopyTo(Data, Trainer1 + 0x20);
|
|
|
|
|
BitConverter.GetBytes(value).CopyTo(Data, Overworld + 0x20);
|
|
|
|
|
}
|
2016-10-28 04:30:21 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-10-15 06:47:16 +00:00
|
|
|
|
public int SpecialLocation
|
|
|
|
|
{
|
|
|
|
|
get => Data[Trainer1 + 0x24];
|
|
|
|
|
set => Data[Trainer1 + 0x24] = (byte)value;
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-10-15 06:47:16 +00:00
|
|
|
|
public int WarpContinueRequest
|
|
|
|
|
{
|
|
|
|
|
get => Data[Trainer1 + 0x6E];
|
|
|
|
|
set => Data[Trainer1 + 0x6E] = (byte)value;
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-10-15 06:47:16 +00:00
|
|
|
|
public int StepCountEgg
|
|
|
|
|
{
|
|
|
|
|
get => BitConverter.ToInt32(Data, Trainer1 + 0x70);
|
|
|
|
|
set => BitConverter.GetBytes(value).CopyTo(Data, Trainer1 + 0x70);
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-10-15 06:47:16 +00:00
|
|
|
|
public int LastZoneID
|
|
|
|
|
{
|
|
|
|
|
get => BitConverter.ToUInt16(Data, Trainer1 + 0x74);
|
|
|
|
|
set => BitConverter.GetBytes((ushort)value).CopyTo(Data, Trainer1 + 0x74);
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-10-15 06:47:16 +00:00
|
|
|
|
public int StepCountFriendship
|
|
|
|
|
{
|
|
|
|
|
get => BitConverter.ToUInt16(Data, Trainer1 + 0x76);
|
|
|
|
|
set => BitConverter.GetBytes((ushort)value).CopyTo(Data, Trainer1 + 0x76);
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-10-15 06:47:16 +00:00
|
|
|
|
public int StepCountAffection // Kawaigari
|
|
|
|
|
{
|
|
|
|
|
get => BitConverter.ToUInt16(Data, Trainer1 + 0x78);
|
|
|
|
|
set => BitConverter.GetBytes((ushort)value).CopyTo(Data, Trainer1 + 0x78);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int ConfigValue
|
|
|
|
|
{
|
|
|
|
|
get => BitConverter.ToInt32(Data, ConfigSave);
|
|
|
|
|
set => BitConverter.GetBytes(value).CopyTo(Data, ConfigSave);
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-10-15 06:47:16 +00:00
|
|
|
|
public int TalkingSpeed
|
|
|
|
|
{
|
|
|
|
|
get => ConfigValue & 3;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
set => ConfigValue = (ConfigValue & ~3) | (value & 3);
|
2017-10-15 06:47:16 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-10-15 06:47:16 +00:00
|
|
|
|
public int BattleAnimation
|
|
|
|
|
{
|
|
|
|
|
// Effects OFF = 1, Effects ON = 0
|
|
|
|
|
get => (ConfigValue >> 2) & 1;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
set => ConfigValue = (ConfigValue & ~(1<<2)) | (value << 2);
|
2017-10-15 06:47:16 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-10-15 06:47:16 +00:00
|
|
|
|
public int BattleStyle
|
|
|
|
|
{
|
|
|
|
|
// SET = 1, SWITCH = 0
|
|
|
|
|
get => (ConfigValue >> 3) & 1;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
set => ConfigValue = (ConfigValue & ~(1 << 3)) | (value << 3);
|
2017-10-15 06:47:16 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-10-15 06:47:16 +00:00
|
|
|
|
public int ButtonMode
|
|
|
|
|
{
|
|
|
|
|
get => (ConfigValue >> 13) & 3;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
set => ConfigValue = (ConfigValue & ~(1 << 13)) | (value << 13);
|
2017-10-15 06:47:16 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-10-15 06:47:16 +00:00
|
|
|
|
public int BoxStatus
|
|
|
|
|
{
|
|
|
|
|
// MANUAL = 1, AUTOMATIC = 0
|
|
|
|
|
get => (ConfigValue >> 15) & 1;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
set => ConfigValue = (ConfigValue & ~(1 << 15)) | (value << 15);
|
2017-10-15 06:47:16 +00:00
|
|
|
|
}
|
2016-10-28 04:30:21 +00:00
|
|
|
|
|
2016-10-20 01:19:01 +00:00
|
|
|
|
public override uint Money
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt32(Data, Misc + 0x4);
|
2016-11-22 07:26:27 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value > 9999999) value = 9999999;
|
|
|
|
|
BitConverter.GetBytes(value).CopyTo(Data, Misc + 0x4);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-03-14 07:45:14 +00:00
|
|
|
|
public uint Stamps
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => (BitConverter.ToUInt32(Data, Misc + 0x08) << 13) >> 17; // 15 stamps; discard top13, lowest4
|
2017-03-14 07:45:14 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
uint flags = BitConverter.ToUInt32(Data, Misc + 0x08) & 0xFFF8000F;
|
|
|
|
|
flags |= (value & 0x7FFF) << 4;
|
|
|
|
|
BitConverter.GetBytes(flags).CopyTo(Data, Misc + 0x08);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-11-22 07:26:27 +00:00
|
|
|
|
public uint BP
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt32(Data, Misc + 0x11C);
|
2016-11-22 07:26:27 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value > 9999) value = 9999;
|
|
|
|
|
BitConverter.GetBytes(value).CopyTo(Data, Misc + 0x11C);
|
|
|
|
|
}
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-03-02 18:36:02 +00:00
|
|
|
|
public int Vivillon
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[Misc + 0x130] & 0x1F;
|
|
|
|
|
set => Data[Misc + 0x130] = (byte)((Data[Misc + 0x130] & ~0x1F) | (value & 0x1F));
|
2017-03-02 18:36:02 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-11-30 04:04:01 +00:00
|
|
|
|
public uint StarterEncryptionConstant
|
|
|
|
|
{
|
|
|
|
|
get => BitConverter.ToUInt32(Data, Misc + 0x148);
|
|
|
|
|
set => SetData(BitConverter.GetBytes(value), Misc + 0x148);
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-03-13 05:30:27 +00:00
|
|
|
|
public int DaysFromRefreshed
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[Misc + 0x123];
|
|
|
|
|
set => Data[Misc + 0x123] = (byte)value;
|
2017-03-13 05:30:27 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-12-08 01:40:54 +00:00
|
|
|
|
public uint UsedFestaCoins
|
2016-12-07 16:59:51 +00:00
|
|
|
|
{
|
2017-11-19 21:50:30 +00:00
|
|
|
|
get => BitConverter.ToUInt32(Data, Record + (38 << 2)); //Record[038]
|
2016-12-07 16:59:51 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value > 9999999) value = 9999999;
|
2017-11-19 21:50:30 +00:00
|
|
|
|
BitConverter.GetBytes(value).CopyTo(Data, Record + (38 << 2));
|
2016-12-07 16:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-11-22 07:26:27 +00:00
|
|
|
|
public uint FestaCoins
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt32(Data, JoinFestaData + 0x508);
|
2016-11-22 07:26:27 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value > 9999999) value = 9999999;
|
2016-12-08 01:40:54 +00:00
|
|
|
|
BitConverter.GetBytes(value).CopyTo(Data, JoinFestaData + 0x508);
|
2016-12-07 16:59:51 +00:00
|
|
|
|
|
2016-12-08 01:40:54 +00:00
|
|
|
|
TotalFestaCoins = UsedFestaCoins + value;
|
2016-11-22 07:26:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-11-22 07:35:29 +00:00
|
|
|
|
private uint TotalFestaCoins
|
2016-11-22 07:26:27 +00:00
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt32(Data, JoinFestaData + 0x50C);
|
2016-11-22 07:26:27 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value > 9999999) value = 9999999;
|
2016-12-08 01:40:54 +00:00
|
|
|
|
BitConverter.GetBytes(value).CopyTo(Data, JoinFestaData + 0x50C);
|
2016-11-22 07:26:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-02-15 03:09:10 +00:00
|
|
|
|
public string FestivalPlazaName
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Util.TrimFromZero(Encoding.Unicode.GetString(Data, JoinFestaData + 0x510, 0x2A));
|
2017-02-15 03:09:10 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
const int max = 20;
|
|
|
|
|
if (value.Length > max) value = value.Substring(0, max);
|
|
|
|
|
Encoding.Unicode.GetBytes(value.PadRight(value.Length + 1, '\0')).CopyTo(Data, JoinFestaData + 0x510);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-11-19 21:50:30 +00:00
|
|
|
|
public ushort FestaRank { get => BitConverter.ToUInt16(Data, JoinFestaData + 0x53A); set => BitConverter.GetBytes(value).CopyTo(Data, JoinFestaData + 0x53A); }
|
2018-09-15 05:37:47 +00:00
|
|
|
|
public ushort GetFestaMessage(int index) => BitConverter.ToUInt16(Data, JoinFestaData + (index * 2));
|
|
|
|
|
public void SetFestaMessage(int index, ushort value) => BitConverter.GetBytes(value).CopyTo(Data, JoinFestaData + (index * 2));
|
2017-11-20 00:16:44 +00:00
|
|
|
|
public bool GetFestaPhraseUnlocked(int index) => Data[JoinFestaData + 0x2A50 + index] != 0; //index: 0 to 105:commonPhrases, 106:Lv100!
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-11-20 00:16:44 +00:00
|
|
|
|
public void SetFestaPhraseUnlocked(int index, bool value)
|
2017-11-19 21:50:30 +00:00
|
|
|
|
{
|
2017-11-20 00:16:44 +00:00
|
|
|
|
if (GetFestaPhraseUnlocked(index) != value) Data[JoinFestaData + 0x2A50 + index] = (byte)(value ? 1 : 0);
|
2017-11-19 21:50:30 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-11-20 00:16:44 +00:00
|
|
|
|
public byte GetFestPrizeReceived(int index) => Data[JoinFestaData + 0x53C + index];
|
|
|
|
|
public void SetFestaPrizeReceived(int index, byte value) => Data[JoinFestaData + 0x53C + index] = value;
|
2017-11-19 21:50:30 +00:00
|
|
|
|
private int FestaYear { get => BitConverter.ToInt32(Data, JoinFestaData + 0x2F0); set => BitConverter.GetBytes(value).CopyTo(Data, JoinFestaData + 0x2F0); }
|
|
|
|
|
private int FestaMonth { get => BitConverter.ToInt32(Data, JoinFestaData + 0x2F4); set => BitConverter.GetBytes(value).CopyTo(Data, JoinFestaData + 0x2F4); }
|
|
|
|
|
private int FestaDay { get => BitConverter.ToInt32(Data, JoinFestaData + 0x2F8); set => BitConverter.GetBytes(value).CopyTo(Data, JoinFestaData + 0x2F8); }
|
|
|
|
|
private int FestaHour { get => BitConverter.ToInt32(Data, JoinFestaData + 0x300); set => BitConverter.GetBytes(value).CopyTo(Data, JoinFestaData + 0x300); }
|
|
|
|
|
private int FestaMinute { get => BitConverter.ToInt32(Data, JoinFestaData + 0x304); set => BitConverter.GetBytes(value).CopyTo(Data, JoinFestaData + 0x304); }
|
|
|
|
|
private int FestaSecond { get => BitConverter.ToInt32(Data, JoinFestaData + 0x308); set => BitConverter.GetBytes(value).CopyTo(Data, JoinFestaData + 0x308); }
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-11-19 21:50:30 +00:00
|
|
|
|
public DateTime? FestaDate
|
|
|
|
|
{
|
|
|
|
|
get => FestaYear >= 0 && FestaMonth > 0 && FestaDay > 0 && FestaHour >= 0 && FestaMinute >= 0 && FestaSecond >= 0 && Util.IsDateValid(FestaYear, FestaMonth, FestaDay)
|
|
|
|
|
? new DateTime(FestaYear, FestaMonth, FestaDay, FestaHour, FestaMinute, FestaSecond)
|
|
|
|
|
: (DateTime?)null;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value.HasValue)
|
|
|
|
|
{
|
|
|
|
|
DateTime dt = value.Value;
|
|
|
|
|
FestaYear = dt.Year;
|
|
|
|
|
FestaMonth = dt.Month;
|
|
|
|
|
FestaDay = dt.Day;
|
|
|
|
|
FestaHour = dt.Hour;
|
|
|
|
|
FestaMinute = dt.Minute;
|
|
|
|
|
FestaSecond = dt.Second;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public sealed class FashionItem
|
2017-03-14 07:45:14 +00:00
|
|
|
|
{
|
2019-02-02 07:08:03 +00:00
|
|
|
|
public bool IsOwned { get; set; }
|
|
|
|
|
public bool IsNew { get; set; }
|
2017-03-14 07:45:14 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-03-14 07:45:14 +00:00
|
|
|
|
public FashionItem[] Wardrobe
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var data = GetData(Fashion, 0x5A8);
|
2017-03-14 07:45:14 +00:00
|
|
|
|
return data.Select(b => new FashionItem {IsOwned = (b & 1) != 0, IsNew = (b & 2) != 0}).ToArray();
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value.Length != 0x5A8)
|
|
|
|
|
throw new ArgumentOutOfRangeException($"Unexpected size: 0x{value.Length:X}");
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetData(value.Select(t => (byte) ((t.IsOwned ? 1 : 0) | (t.IsNew ? 2 : 0))).ToArray(), Fashion);
|
2017-03-14 07:45:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-22 07:26:27 +00:00
|
|
|
|
|
2016-10-20 01:19:01 +00:00
|
|
|
|
public override int PlayedHours
|
2017-05-13 03:32:36 +00:00
|
|
|
|
{
|
|
|
|
|
get => BitConverter.ToUInt16(Data, PlayTime);
|
|
|
|
|
set => BitConverter.GetBytes((ushort)value).CopyTo(Data, PlayTime);
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-10-20 01:19:01 +00:00
|
|
|
|
public override int PlayedMinutes
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[PlayTime + 2];
|
|
|
|
|
set => Data[PlayTime + 2] = (byte)value;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-10-20 01:19:01 +00:00
|
|
|
|
public override int PlayedSeconds
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[PlayTime + 3];
|
|
|
|
|
set => Data[PlayTime + 3] = (byte)value;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
private uint LastSaved { get => BitConverter.ToUInt32(Data, PlayTime + 0x4); set => BitConverter.GetBytes(value).CopyTo(Data, PlayTime + 0x4); }
|
2018-09-15 05:37:47 +00:00
|
|
|
|
private int LastSavedYear { get => (int)(LastSaved & 0xFFF); set => LastSaved = (LastSaved & 0xFFFFF000) | (uint)value; }
|
|
|
|
|
private int LastSavedMonth { get => (int)(LastSaved >> 12 & 0xF); set => LastSaved = (LastSaved & 0xFFFF0FFF) | ((uint)value & 0xF) << 12; }
|
|
|
|
|
private int LastSavedDay { get => (int)(LastSaved >> 16 & 0x1F); set => LastSaved = (LastSaved & 0xFFE0FFFF) | ((uint)value & 0x1F) << 16; }
|
|
|
|
|
private int LastSavedHour { get => (int)(LastSaved >> 21 & 0x1F); set => LastSaved = (LastSaved & 0xFC1FFFFF) | ((uint)value & 0x1F) << 21; }
|
|
|
|
|
private int LastSavedMinute { get => (int)(LastSaved >> 26 & 0x3F); set => LastSaved = (LastSaved & 0x03FFFFFF) | ((uint)value & 0x3F) << 26; }
|
2016-12-21 21:57:38 +00:00
|
|
|
|
private string LastSavedTime => $"{LastSavedYear:0000}{LastSavedMonth:00}{LastSavedDay:00}{LastSavedHour:00}{LastSavedMinute:00}";
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-12-21 14:45:22 +00:00
|
|
|
|
public DateTime? LastSavedDate
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => !Util.IsDateValid(LastSavedYear, LastSavedMonth, LastSavedDay)
|
|
|
|
|
? (DateTime?)null
|
2016-12-21 21:57:38 +00:00
|
|
|
|
: new DateTime(LastSavedYear, LastSavedMonth, LastSavedDay, LastSavedHour, LastSavedMinute, 0);
|
2016-12-21 14:45:22 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-21 21:57:38 +00:00
|
|
|
|
// Only update the properties if a value is provided.
|
2016-12-21 14:45:22 +00:00
|
|
|
|
if (value.HasValue)
|
|
|
|
|
{
|
2016-12-21 21:57:38 +00:00
|
|
|
|
var dt = value.Value;
|
|
|
|
|
LastSavedYear = dt.Year;
|
|
|
|
|
LastSavedMonth = dt.Month;
|
|
|
|
|
LastSavedDay = dt.Day;
|
|
|
|
|
LastSavedHour = dt.Hour;
|
|
|
|
|
LastSavedMinute = dt.Minute;
|
2016-12-21 14:45:22 +00:00
|
|
|
|
}
|
2016-12-21 21:57:38 +00:00
|
|
|
|
else // Clear the date.
|
2016-12-21 14:45:22 +00:00
|
|
|
|
{
|
|
|
|
|
// If code tries to access MetDate again, null will be returned.
|
|
|
|
|
LastSavedYear = 0;
|
|
|
|
|
LastSavedMonth = 0;
|
|
|
|
|
LastSavedDay = 0;
|
|
|
|
|
LastSavedHour = 0;
|
|
|
|
|
LastSavedMinute = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-20 01:19:01 +00:00
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public int ResumeYear { get => BitConverter.ToInt32(Data, AdventureInfo + 0x4); set => BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x4); }
|
|
|
|
|
public int ResumeMonth { get => Data[AdventureInfo + 0x8]; set => Data[AdventureInfo + 0x8] = (byte)value; }
|
|
|
|
|
public int ResumeDay { get => Data[AdventureInfo + 0x9]; set => Data[AdventureInfo + 0x9] = (byte)value; }
|
|
|
|
|
public int ResumeHour { get => Data[AdventureInfo + 0xB]; set => Data[AdventureInfo + 0xB] = (byte)value; }
|
|
|
|
|
public int ResumeMinute { get => Data[AdventureInfo + 0xC]; set => Data[AdventureInfo + 0xC] = (byte)value; }
|
|
|
|
|
public int ResumeSeconds { get => Data[AdventureInfo + 0xD]; set => Data[AdventureInfo + 0xD] = (byte)value; }
|
|
|
|
|
public override int SecondsToStart { get => BitConverter.ToInt32(Data, AdventureInfo + 0x28); set => BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x28); }
|
|
|
|
|
public override int SecondsToFame { get => BitConverter.ToInt32(Data, AdventureInfo + 0x30); set => BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x30); }
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public ulong AlolaTime { get => BitConverter.ToUInt64(Data, AdventureInfo + 0x48); set => BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x48); }
|
2016-11-11 12:13:23 +00:00
|
|
|
|
|
2016-12-30 08:30:54 +00:00
|
|
|
|
// Stat Records
|
2018-07-07 22:38:11 +00:00
|
|
|
|
public int RecordCount => 200;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public int GetRecord(int recordID)
|
2016-12-30 08:30:54 +00:00
|
|
|
|
{
|
2018-08-05 19:39:06 +00:00
|
|
|
|
int ofs = Records.GetOffset(Record, recordID);
|
2016-12-30 08:30:54 +00:00
|
|
|
|
if (recordID < 100)
|
|
|
|
|
return BitConverter.ToInt32(Data, ofs);
|
|
|
|
|
if (recordID < 200)
|
|
|
|
|
return BitConverter.ToInt16(Data, ofs);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public void SetRecord(int recordID, int value)
|
2016-12-30 08:30:54 +00:00
|
|
|
|
{
|
2018-08-05 19:39:06 +00:00
|
|
|
|
int ofs = Records.GetOffset(Record, recordID);
|
|
|
|
|
var maxes = USUM ? Records.MaxType_USUM: Records.MaxType_SM;
|
|
|
|
|
int max = Records.GetMax(recordID, maxes);
|
2017-03-11 18:52:18 +00:00
|
|
|
|
if (value > max)
|
|
|
|
|
value = max;
|
2016-12-30 08:30:54 +00:00
|
|
|
|
if (recordID < 100)
|
|
|
|
|
BitConverter.GetBytes(value).CopyTo(Data, ofs);
|
|
|
|
|
if (recordID < 200)
|
2017-03-11 18:52:18 +00:00
|
|
|
|
BitConverter.GetBytes((ushort)value).CopyTo(Data, ofs);
|
2016-12-30 08:30:54 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-08-05 19:39:06 +00:00
|
|
|
|
public int GetRecordMax(int recordID) => Records.GetMax(recordID, USUM ? Records.MaxType_USUM : Records.MaxType_SM);
|
|
|
|
|
public int GetRecordOffset(int recordID) => Records.GetOffset(Record, recordID);
|
2018-09-27 02:00:52 +00:00
|
|
|
|
public void AddRecord(int recordID) => SetRecord(recordID, GetRecord(recordID) + 1);
|
2017-03-11 18:52:18 +00:00
|
|
|
|
|
2016-11-29 07:02:25 +00:00
|
|
|
|
public ushort PokeFinderCameraVersion
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt16(Data, PokeFinderSave + 0x00);
|
|
|
|
|
set => BitConverter.GetBytes(value).CopyTo(Data, PokeFinderSave + 0x00);
|
2016-11-29 07:02:25 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-11-29 07:02:25 +00:00
|
|
|
|
public bool PokeFinderGyroFlag
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt16(Data, PokeFinderSave + 0x02) == 1;
|
|
|
|
|
set => BitConverter.GetBytes((ushort)(value ? 1 : 0)).CopyTo(Data, PokeFinderSave + 0x02);
|
2016-11-29 07:02:25 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-11-29 07:02:25 +00:00
|
|
|
|
public uint PokeFinderSnapCount
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt32(Data, PokeFinderSave + 0x04);
|
2016-11-29 07:02:25 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value > 9999999) // Top bound is unchecked, check anyway
|
|
|
|
|
value = 9999999;
|
|
|
|
|
BitConverter.GetBytes(value).CopyTo(Data, PokeFinderSave + 0x04);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-11-29 07:02:25 +00:00
|
|
|
|
public uint PokeFinderThumbsTotalValue
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt32(Data, PokeFinderSave + 0x0C);
|
|
|
|
|
set => BitConverter.GetBytes(value).CopyTo(Data, PokeFinderSave + 0x0C);
|
2016-11-29 07:02:25 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-11-29 07:02:25 +00:00
|
|
|
|
public uint PokeFinderThumbsHighValue
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt32(Data, PokeFinderSave + 0x10);
|
2016-11-29 07:02:25 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2019-02-02 07:08:03 +00:00
|
|
|
|
if (value > 9_999_999)
|
|
|
|
|
value = 9_999_999;
|
2016-11-29 07:02:25 +00:00
|
|
|
|
BitConverter.GetBytes(value).CopyTo(Data, PokeFinderSave + 0x10);
|
|
|
|
|
|
|
|
|
|
if (value > PokeFinderThumbsTotalValue)
|
2016-11-30 16:49:30 +00:00
|
|
|
|
PokeFinderThumbsTotalValue = value;
|
2016-11-29 07:02:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-11-29 07:02:25 +00:00
|
|
|
|
public ushort PokeFinderTutorialFlags
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt16(Data, PokeFinderSave + 0x14);
|
|
|
|
|
set => BitConverter.GetBytes(value).CopyTo(Data, PokeFinderSave + 0x14);
|
2016-11-29 07:02:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-20 01:19:01 +00:00
|
|
|
|
// Inventory
|
|
|
|
|
public override InventoryPouch[] Inventory
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2018-12-11 04:32:08 +00:00
|
|
|
|
var bag = GetPouches();
|
|
|
|
|
foreach (var p in bag)
|
|
|
|
|
p.GetPouch(Data);
|
|
|
|
|
return bag;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
foreach (var p in value)
|
|
|
|
|
p.SetPouch(Data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private InventoryPouch[] GetPouches()
|
|
|
|
|
{
|
|
|
|
|
if (SM)
|
|
|
|
|
{
|
|
|
|
|
return new InventoryPouch[]
|
2017-11-08 08:34:32 +00:00
|
|
|
|
{
|
2018-07-29 20:55:07 +00:00
|
|
|
|
new InventoryPouch7(InventoryType.Medicine, Legal.Pouch_Medicine_SM, 999, OFS_PouchMedicine),
|
|
|
|
|
new InventoryPouch7(InventoryType.Items, Legal.Pouch_Items_SM, 999, OFS_PouchHeldItem),
|
|
|
|
|
new InventoryPouch7(InventoryType.TMHMs, Legal.Pouch_TMHM_SM, 1, OFS_PouchTMHM),
|
|
|
|
|
new InventoryPouch7(InventoryType.Berries, Legal.Pouch_Berries_SM, 999, OFS_PouchBerry),
|
|
|
|
|
new InventoryPouch7(InventoryType.KeyItems, Legal.Pouch_Key_SM, 1, OFS_PouchKeyItem),
|
|
|
|
|
new InventoryPouch7(InventoryType.ZCrystals, Legal.Pouch_ZCrystal_SM, 1, OFS_PouchZCrystals),
|
2017-11-08 08:34:32 +00:00
|
|
|
|
};
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-12-11 04:32:08 +00:00
|
|
|
|
return new InventoryPouch[] // USUM
|
2016-10-20 01:19:01 +00:00
|
|
|
|
{
|
2018-12-11 04:32:08 +00:00
|
|
|
|
new InventoryPouch7(InventoryType.Medicine, Legal.Pouch_Medicine_SM, 999, OFS_PouchMedicine),
|
|
|
|
|
new InventoryPouch7(InventoryType.Items, Legal.Pouch_Items_SM, 999, OFS_PouchHeldItem),
|
|
|
|
|
new InventoryPouch7(InventoryType.TMHMs, Legal.Pouch_TMHM_SM, 1, OFS_PouchTMHM),
|
|
|
|
|
new InventoryPouch7(InventoryType.Berries, Legal.Pouch_Berries_SM, 999, OFS_PouchBerry),
|
|
|
|
|
new InventoryPouch7(InventoryType.KeyItems, Legal.Pouch_Key_USUM, 1, OFS_PouchKeyItem),
|
|
|
|
|
new InventoryPouch7(InventoryType.ZCrystals, Legal.Pouch_ZCrystal_USUM, 1, OFS_PouchZCrystals),
|
|
|
|
|
new InventoryPouch7(InventoryType.BattleItems, Legal.Pouch_Roto_USUM, 999, OFS_BattleItems),
|
|
|
|
|
};
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-04 21:23:35 +00:00
|
|
|
|
// Battle Tree
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public int GetTreeStreak(int battletype, bool super, bool max)
|
2016-12-04 21:23:35 +00:00
|
|
|
|
{
|
|
|
|
|
if (battletype > 3)
|
2019-02-02 07:08:03 +00:00
|
|
|
|
throw new ArgumentException(nameof(battletype));
|
2016-12-04 21:23:35 +00:00
|
|
|
|
|
|
|
|
|
int offset = 8*battletype;
|
|
|
|
|
if (super)
|
|
|
|
|
offset += 2;
|
|
|
|
|
if (max)
|
|
|
|
|
offset += 4;
|
|
|
|
|
|
|
|
|
|
return BitConverter.ToUInt16(Data, BattleTree + offset);
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public void SetTreeStreak(int value, int battletype, bool super, bool max)
|
2016-12-04 21:23:35 +00:00
|
|
|
|
{
|
|
|
|
|
if (battletype > 3)
|
2019-02-02 07:08:03 +00:00
|
|
|
|
throw new ArgumentException(nameof(battletype));
|
2016-12-04 21:23:35 +00:00
|
|
|
|
|
|
|
|
|
if (value > ushort.MaxValue)
|
|
|
|
|
value = ushort.MaxValue;
|
|
|
|
|
|
|
|
|
|
int offset = 8 * battletype;
|
|
|
|
|
if (super)
|
|
|
|
|
offset += 2;
|
|
|
|
|
if (max)
|
|
|
|
|
offset += 4;
|
|
|
|
|
|
|
|
|
|
BitConverter.GetBytes((ushort)value).CopyTo(Data, BattleTree + offset);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-15 05:40:31 +00:00
|
|
|
|
// Resort Save
|
|
|
|
|
public int GetPokebeanCount(int bean_id)
|
|
|
|
|
{
|
|
|
|
|
if (bean_id < 0 || bean_id > 14)
|
|
|
|
|
throw new ArgumentException("Invalid bean id!");
|
|
|
|
|
return Data[Resort + 0x564C + bean_id];
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-11-15 05:40:31 +00:00
|
|
|
|
public void SetPokebeanCount(int bean_id, int count)
|
|
|
|
|
{
|
|
|
|
|
if (bean_id < 0 || bean_id > 14)
|
|
|
|
|
throw new ArgumentException("Invalid bean id!");
|
|
|
|
|
if (count < 0)
|
|
|
|
|
count = 0;
|
|
|
|
|
if (count > 255)
|
|
|
|
|
count = 255;
|
|
|
|
|
Data[Resort + 0x564C + bean_id] = (byte) count;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-20 01:19:01 +00:00
|
|
|
|
// Storage
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int CurrentBox { get => Data[LastViewedBox]; set => Data[LastViewedBox] = (byte)value; }
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override int GetPartyOffset(int slot)
|
2016-10-20 01:19:01 +00:00
|
|
|
|
{
|
2018-09-15 05:37:47 +00:00
|
|
|
|
return Party + (SIZE_PARTY * slot);
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override int GetBoxOffset(int box)
|
2016-10-20 01:19:01 +00:00
|
|
|
|
{
|
2018-09-15 05:37:47 +00:00
|
|
|
|
return Box + (SIZE_STORED *box*30);
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected override int GetBoxWallpaperOffset(int box)
|
2016-10-20 01:19:01 +00:00
|
|
|
|
{
|
2016-10-29 18:32:21 +00:00
|
|
|
|
int ofs = PCBackgrounds > 0 && PCBackgrounds < Data.Length ? PCBackgrounds : -1;
|
|
|
|
|
if (ofs > -1)
|
|
|
|
|
return ofs + box;
|
|
|
|
|
return ofs;
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override void SetBoxWallpaper(int box, int value)
|
2016-10-29 18:32:21 +00:00
|
|
|
|
{
|
|
|
|
|
if (PCBackgrounds < 0)
|
|
|
|
|
return;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
int ofs = PCBackgrounds > 0 && PCBackgrounds < Data.Length ? PCBackgrounds : 0;
|
2016-10-29 18:32:21 +00:00
|
|
|
|
Data[ofs + box] = (byte)value;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override string GetBoxName(int box)
|
2016-10-20 01:19:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (PCLayout < 0)
|
2017-09-30 05:58:25 +00:00
|
|
|
|
return $"B{box + 1}";
|
2018-09-15 05:37:47 +00:00
|
|
|
|
return Util.TrimFromZero(Encoding.Unicode.GetString(Data, PCLayout + (0x22 * box), 0x22));
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-05-12 15:13:39 +00:00
|
|
|
|
public override void SetBoxName(int box, string value)
|
2016-10-20 01:19:01 +00:00
|
|
|
|
{
|
2018-09-15 05:37:47 +00:00
|
|
|
|
Encoding.Unicode.GetBytes(value.PadRight(0x11, '\0')).CopyTo(Data, PCLayout + (0x22 * box));
|
2016-10-20 01:19:01 +00:00
|
|
|
|
Edited = true;
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override PKM GetPKM(byte[] data)
|
2016-10-20 01:19:01 +00:00
|
|
|
|
{
|
|
|
|
|
return new PK7(data);
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected override void SetPKM(PKM pkm)
|
2016-10-20 01:19:01 +00:00
|
|
|
|
{
|
2017-12-12 00:01:24 +00:00
|
|
|
|
PK7 pk7 = (PK7)pkm;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
// Apply to this Save File
|
|
|
|
|
int CT = pk7.CurrentHandler;
|
|
|
|
|
DateTime Date = DateTime.Now;
|
|
|
|
|
pk7.Trade(OT, TID, SID, Country, SubRegion, Gender, false, Date.Day, Date.Month, Date.Year);
|
|
|
|
|
if (CT != pk7.CurrentHandler) // Logic updated Friendship
|
|
|
|
|
{
|
|
|
|
|
// Copy over the Friendship Value only under certain circumstances
|
|
|
|
|
if (pk7.Moves.Contains(216)) // Return
|
|
|
|
|
pk7.CurrentFriendship = pk7.OppositeFriendship;
|
|
|
|
|
else if (pk7.Moves.Contains(218)) // Frustration
|
|
|
|
|
pkm.CurrentFriendship = pk7.OppositeFriendship;
|
|
|
|
|
}
|
|
|
|
|
pkm.RefreshChecksum();
|
2018-09-28 04:30:20 +00:00
|
|
|
|
if (Record > 0)
|
|
|
|
|
AddCountAcquired(pkm);
|
|
|
|
|
}
|
2018-09-27 02:06:05 +00:00
|
|
|
|
|
2018-09-28 04:30:20 +00:00
|
|
|
|
private void AddCountAcquired(PKM pkm)
|
|
|
|
|
{
|
2018-09-27 02:06:05 +00:00
|
|
|
|
AddRecord(pkm.WasEgg ? 008 : 006); // egg, capture
|
|
|
|
|
if (pkm.CurrentHandler == 1)
|
|
|
|
|
AddRecord(011); // trade
|
2018-11-27 16:53:56 +00:00
|
|
|
|
if (!pkm.WasEgg)
|
|
|
|
|
AddRecord(004); // wild encounters
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected override void SetDex(PKM pkm)
|
2016-10-20 01:19:01 +00:00
|
|
|
|
{
|
2018-03-12 01:07:48 +00:00
|
|
|
|
if (PokeDex < 0 || Version == GameVersion.Invalid) // sanity
|
2016-10-20 01:19:01 +00:00
|
|
|
|
return;
|
2016-11-08 16:43:57 +00:00
|
|
|
|
if (pkm.Species == 0 || pkm.Species > MaxSpeciesID) // out of range
|
2016-10-20 01:19:01 +00:00
|
|
|
|
return;
|
2016-11-08 16:43:57 +00:00
|
|
|
|
if (pkm.IsEgg) // do not add
|
2016-10-20 01:19:01 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int bit = pkm.Species - 1;
|
2016-10-23 03:09:22 +00:00
|
|
|
|
int bd = bit >> 3; // div8
|
|
|
|
|
int bm = bit & 7; // mod8
|
2016-10-20 01:19:01 +00:00
|
|
|
|
int gender = pkm.Gender % 2; // genderless -> male
|
|
|
|
|
int shiny = pkm.IsShiny ? 1 : 0;
|
2016-11-08 16:43:57 +00:00
|
|
|
|
if (pkm.Species == 351) // castform
|
|
|
|
|
shiny = 0;
|
|
|
|
|
int shift = gender | (shiny << 1);
|
2016-10-23 03:09:22 +00:00
|
|
|
|
if (pkm.Species == 327) // Spinda
|
|
|
|
|
{
|
|
|
|
|
if ((Data[PokeDex + 0x84] & (1 << (shift + 4))) != 0) // Already 2
|
|
|
|
|
{
|
2018-09-15 05:37:47 +00:00
|
|
|
|
BitConverter.GetBytes(pkm.EncryptionConstant).CopyTo(Data, PokeDex + 0x8E8 + (shift * 4));
|
2016-10-23 03:09:22 +00:00
|
|
|
|
// Data[PokeDex + 0x84] |= (byte)(1 << (shift + 4)); // 2 -- pointless
|
|
|
|
|
Data[PokeDex + 0x84] |= (byte)(1 << shift); // 1
|
|
|
|
|
}
|
|
|
|
|
else if ((Data[PokeDex + 0x84] & (1 << shift)) == 0) // Not yet 1
|
|
|
|
|
{
|
|
|
|
|
Data[PokeDex + 0x84] |= (byte)(1 << shift); // 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int ofs = PokeDex // Raw Offset
|
|
|
|
|
+ 0x08 // Magic + Flags
|
|
|
|
|
+ 0x80; // Misc Data (1024 bits)
|
|
|
|
|
// Set the Owned Flag
|
|
|
|
|
Data[ofs + bd] |= (byte)(1 << bm);
|
2016-10-20 01:19:01 +00:00
|
|
|
|
|
2016-11-08 16:43:57 +00:00
|
|
|
|
// Starting with Gen7, form bits are stored in the same region as the species flags.
|
2016-10-20 01:19:01 +00:00
|
|
|
|
|
2016-11-08 16:43:57 +00:00
|
|
|
|
int formstart = pkm.AltForm;
|
|
|
|
|
int formend = pkm.AltForm;
|
2017-11-15 03:13:58 +00:00
|
|
|
|
bool reset = SanitizeFormsToIterate(pkm.Species, out int fs, out int fe, formstart, USUM);
|
2016-11-08 16:43:57 +00:00
|
|
|
|
if (reset)
|
2016-10-23 03:09:22 +00:00
|
|
|
|
{
|
2016-11-08 16:43:57 +00:00
|
|
|
|
formstart = fs;
|
|
|
|
|
formend = fe;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int form = formstart; form <= formend; form++)
|
|
|
|
|
{
|
|
|
|
|
int bitIndex = bit;
|
|
|
|
|
if (form > 0) // Override the bit to overwrite
|
|
|
|
|
{
|
|
|
|
|
int fc = Personal[pkm.Species].FormeCount;
|
|
|
|
|
if (fc > 1) // actually has forms
|
|
|
|
|
{
|
2018-05-12 15:13:39 +00:00
|
|
|
|
int f = USUM
|
2017-11-11 01:08:43 +00:00
|
|
|
|
? SaveUtil.GetDexFormIndexUSUM(pkm.Species, fc, MaxSpeciesID - 1)
|
|
|
|
|
: SaveUtil.GetDexFormIndexSM(pkm.Species, fc, MaxSpeciesID - 1);
|
2016-11-08 16:43:57 +00:00
|
|
|
|
if (f >= 0) // bit index valid
|
|
|
|
|
bitIndex = f + form;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetDexFlags(bitIndex, gender, shiny, pkm.Species - 1);
|
2016-10-23 03:09:22 +00:00
|
|
|
|
}
|
2016-10-20 01:19:01 +00:00
|
|
|
|
|
|
|
|
|
// Set the Language
|
2016-10-23 03:09:22 +00:00
|
|
|
|
int lang = pkm.Language;
|
|
|
|
|
const int langCount = 9;
|
|
|
|
|
if (lang <= 10 && lang != 6 && lang != 0) // valid language
|
|
|
|
|
{
|
|
|
|
|
if (lang >= 7)
|
|
|
|
|
lang--;
|
|
|
|
|
lang--; // 0-8 languages
|
|
|
|
|
if (lang < 0) lang = 1;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
int lbit = (bit * langCount) + lang;
|
2016-10-23 03:09:22 +00:00
|
|
|
|
if (lbit >> 3 < 920) // Sanity check for max length of region
|
|
|
|
|
Data[PokeDexLanguageFlags + (lbit >> 3)] |= (byte)(1 << (lbit & 7));
|
|
|
|
|
}
|
2016-11-08 16:43:57 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected override void SetPartyValues(PKM pkm, bool isParty)
|
2017-06-07 05:13:12 +00:00
|
|
|
|
{
|
2018-03-26 02:05:49 +00:00
|
|
|
|
base.SetPartyValues(pkm, isParty);
|
2018-07-21 03:25:28 +00:00
|
|
|
|
((PK7)pkm).FormDuration = GetFormDuration(pkm, isParty);
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-07-21 03:25:28 +00:00
|
|
|
|
private static uint GetFormDuration(PKM pkm, bool isParty)
|
|
|
|
|
{
|
|
|
|
|
if (!isParty || pkm.AltForm == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
switch (pkm.Species)
|
|
|
|
|
{
|
|
|
|
|
case 676: return 5; // Furfrou
|
|
|
|
|
case 720: return 3; // Hoopa
|
|
|
|
|
default: return 0;
|
|
|
|
|
}
|
2017-06-07 05:13:12 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-11-15 03:13:58 +00:00
|
|
|
|
public static bool SanitizeFormsToIterate(int species, out int formStart, out int formEnd, int formIn, bool USUM)
|
2016-11-08 16:43:57 +00:00
|
|
|
|
{
|
|
|
|
|
// 004AA370 in Moon
|
|
|
|
|
// Simplified in terms of usage -- only overrides to give all the battle forms for a pkm
|
|
|
|
|
switch (species)
|
|
|
|
|
{
|
|
|
|
|
case 351: // Castform
|
|
|
|
|
formStart = 0;
|
|
|
|
|
formEnd = 3;
|
|
|
|
|
return true;
|
2017-11-11 01:08:43 +00:00
|
|
|
|
|
2019-02-02 07:08:03 +00:00
|
|
|
|
|
|
|
|
|
case 421: // Cherrim
|
|
|
|
|
case 555: // Darmanitan
|
|
|
|
|
case 648: // Meloetta
|
|
|
|
|
case 746: // Wishiwashi
|
|
|
|
|
case 778: // Mimikyu
|
|
|
|
|
// Alolans
|
2017-11-11 01:08:43 +00:00
|
|
|
|
case 020: // Raticate
|
2017-11-15 03:13:58 +00:00
|
|
|
|
case 105: // Marowak
|
2017-11-11 01:08:43 +00:00
|
|
|
|
formStart = 0;
|
2017-11-15 03:13:58 +00:00
|
|
|
|
formEnd = 1;
|
2017-11-11 01:08:43 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
2017-11-15 03:13:58 +00:00
|
|
|
|
case 735: // Gumshoos
|
|
|
|
|
case 758: // Salazzle
|
|
|
|
|
case 754: // Lurantis
|
|
|
|
|
case 738: // Vikavolt
|
|
|
|
|
case 784: // Kommo-o
|
|
|
|
|
case 752: // Araquanid
|
|
|
|
|
case 777: // Togedemaru
|
|
|
|
|
case 743: // Ribombee
|
|
|
|
|
case 744: // Rockruff
|
|
|
|
|
break;
|
|
|
|
|
|
2017-11-15 05:55:52 +00:00
|
|
|
|
case 774 when formIn <= 6: // Minior
|
|
|
|
|
break; // don't give meteor forms except the first
|
2016-10-23 03:09:22 +00:00
|
|
|
|
|
2017-11-15 03:13:58 +00:00
|
|
|
|
case 718 when formIn > 1:
|
|
|
|
|
break;
|
2016-11-08 16:43:57 +00:00
|
|
|
|
default:
|
2017-11-15 03:13:58 +00:00
|
|
|
|
int count = USUM ? SaveUtil.GetDexFormCountUSUM(species) : SaveUtil.GetDexFormCountSM(species);
|
|
|
|
|
formStart = formEnd = 0;
|
|
|
|
|
return count < formIn;
|
2016-11-08 16:43:57 +00:00
|
|
|
|
}
|
2017-11-15 03:13:58 +00:00
|
|
|
|
formStart = 0;
|
|
|
|
|
formEnd = 0;
|
|
|
|
|
return true;
|
2016-11-08 16:43:57 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void SetDexFlags(int index, int gender, int shiny, int baseSpecies)
|
2016-11-08 16:43:57 +00:00
|
|
|
|
{
|
|
|
|
|
const int brSize = 0x8C;
|
|
|
|
|
int shift = gender | (shiny << 1);
|
|
|
|
|
int ofs = PokeDex // Raw Offset
|
|
|
|
|
+ 0x08 // Magic + Flags
|
|
|
|
|
+ 0x80 // Misc Data (1024 bits)
|
|
|
|
|
+ 0x68; // Owned Flags
|
2016-10-20 01:19:01 +00:00
|
|
|
|
|
2016-11-08 16:43:57 +00:00
|
|
|
|
int bd = index >> 3; // div8
|
|
|
|
|
int bm = index & 7; // mod8
|
|
|
|
|
int bd1 = baseSpecies >> 3;
|
|
|
|
|
int bm1 = baseSpecies & 7;
|
|
|
|
|
// Set the [Species/Gender/Shiny] Seen Flag
|
|
|
|
|
int brSeen = shift * brSize;
|
|
|
|
|
Data[ofs + brSeen + bd] |= (byte)(1 << bm);
|
2016-10-20 01:19:01 +00:00
|
|
|
|
|
2016-11-08 16:43:57 +00:00
|
|
|
|
// Check Displayed Status for base form
|
|
|
|
|
bool Displayed = false;
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
int brDisplayed = (4 + i) * brSize;
|
|
|
|
|
Displayed |= (Data[ofs + brDisplayed + bd1] & (byte)(1 << bm1)) != 0;
|
|
|
|
|
}
|
2016-10-20 01:19:01 +00:00
|
|
|
|
|
2016-11-08 16:43:57 +00:00
|
|
|
|
// If form is not base form, check form too
|
|
|
|
|
if (!Displayed && baseSpecies != index)
|
2016-10-20 01:19:01 +00:00
|
|
|
|
{
|
2016-11-08 16:43:57 +00:00
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
int brDisplayed = (4 + i) * brSize;
|
|
|
|
|
Displayed |= (Data[ofs + brDisplayed + bd] & (byte)(1 << bm)) != 0;
|
|
|
|
|
}
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2016-11-08 16:43:57 +00:00
|
|
|
|
if (Displayed)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Set the Display flag if none are set
|
2018-09-15 05:37:47 +00:00
|
|
|
|
Data[ofs + ((4 + shift) * brSize) + bd] |= (byte)(1 << bm);
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-10-15 06:47:16 +00:00
|
|
|
|
public bool NationalDex
|
|
|
|
|
{
|
|
|
|
|
get => (Data[PokeDex + 4] & 1) == 1;
|
|
|
|
|
set => Data[PokeDex + 4] = (byte)((Data[PokeDex + 4] & 0xFE) | (value ? 1 : 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the last viewed dex entry in the Pokedex (by National Dex ID), internally called DefaultMons
|
|
|
|
|
/// </summary>
|
|
|
|
|
public uint CurrentViewedDex => BitConverter.ToUInt32(Data, PokeDex + 4) >> 9 & 0x3FF;
|
2017-03-15 05:41:15 +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
|
|
|
|
|
+ 0x08 // Magic + Flags
|
|
|
|
|
+ 0x80; // Misc Data (1024 bits)
|
|
|
|
|
return (1 << bm & Data[ofs + bd]) != 0;
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
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 = 0x8C;
|
|
|
|
|
|
|
|
|
|
int bit = species - 1;
|
|
|
|
|
int bd = bit >> 3; // div8
|
|
|
|
|
int bm = bit & 7; // mod8
|
|
|
|
|
byte mask = (byte)(1 << bm);
|
|
|
|
|
int ofs = PokeDex // Raw Offset
|
|
|
|
|
+ 0x08 // Magic + Flags
|
|
|
|
|
+ 0x80; // Misc Data (1024 bits)
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= 4; i++) // check all 4 seen flags (gender/shiny)
|
2019-01-26 03:58:00 +00:00
|
|
|
|
{
|
2018-09-15 05:37:47 +00:00
|
|
|
|
if ((Data[ofs + bd + (i * brSize)] & mask) != 0)
|
2017-03-15 05:41:15 +00:00
|
|
|
|
return true;
|
2019-01-26 03:58:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-15 05:41:15 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override byte[] DecryptPKM(byte[] data)
|
2016-10-20 01:19:01 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return PKX.DecryptArray(data);
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-10-20 01:19:01 +00:00
|
|
|
|
public override int PartyCount
|
|
|
|
|
{
|
2018-09-15 05:37:47 +00:00
|
|
|
|
get => Data[Party + (6 * SIZE_PARTY)];
|
|
|
|
|
protected set => Data[Party + (6 * SIZE_PARTY)] = (byte)value;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int BoxesUnlocked { get => Data[PCFlags + 1]; set => Data[PCFlags + 1] = (byte)value; }
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-12-05 06:59:28 +00:00
|
|
|
|
private void LoadBattleTeams()
|
2016-12-16 07:17:17 +00:00
|
|
|
|
{
|
2018-12-05 06:59:28 +00:00
|
|
|
|
for (int i = 0; i < TeamCount*6; i++)
|
|
|
|
|
{
|
|
|
|
|
short val = BitConverter.ToInt16(Data, BattleBoxFlags + (i * 2));
|
|
|
|
|
if (val < 0)
|
|
|
|
|
{
|
|
|
|
|
TeamSlots[i] = -1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2016-12-16 07:17:17 +00:00
|
|
|
|
|
2018-12-05 06:59:28 +00:00
|
|
|
|
int box = val >> 8;
|
|
|
|
|
int slot = val & 0xFF;
|
|
|
|
|
int index = (BoxSlotCount * box) + slot;
|
|
|
|
|
TeamSlots[i] = index & 0xFFFF;
|
|
|
|
|
}
|
2016-12-16 07:17:17 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-12-05 06:59:28 +00:00
|
|
|
|
private void SaveBattleTeams()
|
2016-12-27 00:41:12 +00:00
|
|
|
|
{
|
2018-12-05 06:59:28 +00:00
|
|
|
|
for (int i = 0; i < TeamCount * 6; i++)
|
|
|
|
|
{
|
|
|
|
|
int index = TeamSlots[i];
|
|
|
|
|
if (index < 0)
|
|
|
|
|
{
|
|
|
|
|
BitConverter.GetBytes((short)index).CopyTo(Data, BattleBoxFlags + (i * 2));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2016-12-27 00:41:12 +00:00
|
|
|
|
|
2018-12-05 06:59:28 +00:00
|
|
|
|
int box = index / BoxSlotCount;
|
|
|
|
|
int slot = index % BoxSlotCount;
|
|
|
|
|
int val = (box << 8) | slot;
|
|
|
|
|
BitConverter.GetBytes((short)val).CopyTo(Data, BattleBoxFlags + (i * 2));
|
|
|
|
|
}
|
2016-12-27 00:41:12 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-12-05 06:59:28 +00:00
|
|
|
|
private bool IsTeamLocked(int team) => Data[PCBackgrounds - TeamCount - team] == 1;
|
2017-10-31 16:24:54 +00:00
|
|
|
|
|
2018-12-05 06:59:28 +00:00
|
|
|
|
public override StorageSlotFlag GetSlotFlags(int index)
|
|
|
|
|
{
|
|
|
|
|
int team = Array.IndexOf(TeamSlots, index);
|
|
|
|
|
if (team < 0)
|
|
|
|
|
return StorageSlotFlag.None;
|
2017-10-31 16:24:54 +00:00
|
|
|
|
|
2018-12-05 06:59:28 +00:00
|
|
|
|
team /= 6;
|
|
|
|
|
var val = (StorageSlotFlag)((int)StorageSlotFlag.BattleTeam1 << team);
|
|
|
|
|
if (IsTeamLocked(team))
|
|
|
|
|
val |= StorageSlotFlag.Locked;
|
|
|
|
|
return val;
|
2017-10-31 16:24:54 +00:00
|
|
|
|
}
|
2016-10-29 18:32:21 +00:00
|
|
|
|
|
2017-11-13 05:28:34 +00:00
|
|
|
|
private int FusedCount => USUM ? 3 : 1;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-11-13 05:28:34 +00:00
|
|
|
|
public int GetFusedSlotOffset(int slot)
|
|
|
|
|
{
|
|
|
|
|
if (Fused < 0 || slot < 0 || slot >= FusedCount)
|
|
|
|
|
return -1;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
return Fused + (SIZE_PARTY * slot); // 0x104*slot
|
2017-11-13 05:28:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-15 05:35:28 +00:00
|
|
|
|
public int GetSurfScore(int recordID)
|
|
|
|
|
{
|
|
|
|
|
if (recordID < 0 || recordID > 4)
|
|
|
|
|
recordID = 0;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
return BitConverter.ToInt32(Data, Misc + 0x138 + (4 * recordID));
|
2017-11-15 05:35:28 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-11-15 05:35:28 +00:00
|
|
|
|
public void SetSurfScore(int recordID, int score)
|
|
|
|
|
{
|
|
|
|
|
if (recordID < 0 || recordID > 4)
|
|
|
|
|
recordID = 0;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
SetData(BitConverter.GetBytes(score), Misc + 0x138 + (4 * recordID));
|
2017-11-15 05:35:28 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-11-19 06:26:57 +00:00
|
|
|
|
public string RotomOT
|
|
|
|
|
{
|
|
|
|
|
get => GetString(Trainer2 + 0x30, 0x1A);
|
|
|
|
|
set => SetString(value, OTLength).CopyTo(Data, Trainer2 + 0x30);
|
|
|
|
|
}
|
2017-11-15 05:35:28 +00:00
|
|
|
|
|
2016-10-30 02:11:47 +00:00
|
|
|
|
public override int DaycareSeedSize => 32; // 128 bits
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override int GetDaycareSlotOffset(int loc, int slot)
|
2016-10-23 19:45:27 +00:00
|
|
|
|
{
|
|
|
|
|
if (loc != 0)
|
|
|
|
|
return -1;
|
|
|
|
|
if (Daycare < 0)
|
|
|
|
|
return -1;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
return Daycare + 1 + (slot * (SIZE_STORED + 1));
|
2016-10-23 19:45:27 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override bool? IsDaycareOccupied(int loc, int slot)
|
2016-10-23 19:45:27 +00:00
|
|
|
|
{
|
|
|
|
|
if (loc != 0)
|
|
|
|
|
return null;
|
|
|
|
|
if (Daycare < 0)
|
|
|
|
|
return null;
|
|
|
|
|
|
2018-09-15 05:37:47 +00:00
|
|
|
|
return Data[Daycare + ((SIZE_STORED + 1) * slot)] != 0;
|
2016-10-23 19:45:27 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override string GetDaycareRNGSeed(int loc)
|
2016-10-23 19:45:27 +00:00
|
|
|
|
{
|
|
|
|
|
if (loc != 0)
|
|
|
|
|
return null;
|
|
|
|
|
if (Daycare < 0)
|
|
|
|
|
return null;
|
|
|
|
|
|
2016-10-30 02:11:47 +00:00
|
|
|
|
var data = Data.Skip(Daycare + 0x1DC).Take(DaycareSeedSize / 2).Reverse().ToArray();
|
2019-02-08 05:40:20 +00:00
|
|
|
|
return BitConverter.ToString(data).Replace("-", string.Empty);
|
2016-10-23 19:45:27 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override bool? IsDaycareHasEgg(int loc)
|
2016-10-23 19:45:27 +00:00
|
|
|
|
{
|
|
|
|
|
if (loc != 0)
|
|
|
|
|
return null;
|
|
|
|
|
if (Daycare < 0)
|
|
|
|
|
return null;
|
|
|
|
|
|
2016-11-14 03:36:39 +00:00
|
|
|
|
return Data[Daycare + 0x1D8] == 1;
|
2016-10-23 19:45:27 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override void SetDaycareOccupied(int loc, int slot, bool occupied)
|
2016-10-23 19:45:27 +00:00
|
|
|
|
{
|
|
|
|
|
if (loc != 0)
|
|
|
|
|
return;
|
|
|
|
|
if (Daycare < 0)
|
|
|
|
|
return;
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2018-09-15 05:37:47 +00:00
|
|
|
|
Data[Daycare + ((SIZE_STORED + 1) * slot)] = (byte)(occupied ? 1 : 0);
|
2016-10-23 19:45:27 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override void SetDaycareRNGSeed(int loc, string seed)
|
2016-10-23 19:45:27 +00:00
|
|
|
|
{
|
|
|
|
|
if (loc != 0)
|
|
|
|
|
return;
|
|
|
|
|
if (Daycare < 0)
|
|
|
|
|
return;
|
2016-10-30 02:11:47 +00:00
|
|
|
|
if (seed == null)
|
|
|
|
|
return;
|
|
|
|
|
if (seed.Length > DaycareSeedSize)
|
|
|
|
|
return;
|
2016-10-23 19:45:27 +00:00
|
|
|
|
|
2016-10-30 02:11:47 +00:00
|
|
|
|
Enumerable.Range(0, seed.Length)
|
|
|
|
|
.Where(x => x % 2 == 0)
|
|
|
|
|
.Reverse()
|
|
|
|
|
.Select(x => Convert.ToByte(seed.Substring(x, 2), 16))
|
2016-12-01 16:18:13 +00:00
|
|
|
|
.ToArray().CopyTo(Data, Daycare + 0x1DC);
|
2016-10-23 19:45:27 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override void SetDaycareHasEgg(int loc, bool hasEgg)
|
2016-10-23 19:45:27 +00:00
|
|
|
|
{
|
|
|
|
|
if (loc != 0)
|
|
|
|
|
return;
|
|
|
|
|
if (Daycare < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-11-14 03:36:39 +00:00
|
|
|
|
Data[Daycare + 0x1D8] = (byte)(hasEgg ? 1 : 0);
|
2016-10-23 19:45:27 +00:00
|
|
|
|
}
|
2016-10-20 01:19:01 +00:00
|
|
|
|
|
|
|
|
|
// Mystery Gift
|
|
|
|
|
protected override bool[] MysteryGiftReceivedFlags
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (WondercardData < 0 || WondercardFlags < 0)
|
2019-02-02 07:26:43 +00:00
|
|
|
|
return Array.Empty<bool>();
|
2016-10-20 01:19:01 +00:00
|
|
|
|
|
2019-02-07 07:28:02 +00:00
|
|
|
|
bool[] result = new bool[(WondercardData-WondercardFlags)*8];
|
|
|
|
|
for (int i = 0; i < result.Length; i++)
|
|
|
|
|
result[i] = (Data[WondercardFlags + (i>>3)] >> (i&7) & 0x1) == 1;
|
|
|
|
|
return result;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (WondercardData < 0 || WondercardFlags < 0)
|
|
|
|
|
return;
|
2019-02-02 07:08:03 +00:00
|
|
|
|
if (value == null || (WondercardData - WondercardFlags)*8 != value.Length)
|
2016-10-20 01:19:01 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
byte[] data = new byte[value.Length/8];
|
|
|
|
|
for (int i = 0; i < value.Length; i++)
|
2018-12-11 04:32:08 +00:00
|
|
|
|
{
|
2016-10-20 01:19:01 +00:00
|
|
|
|
if (value[i])
|
|
|
|
|
data[i>>3] |= (byte)(1 << (i&7));
|
2018-12-11 04:32:08 +00:00
|
|
|
|
}
|
2016-10-20 01:19:01 +00:00
|
|
|
|
|
|
|
|
|
data.CopyTo(Data, WondercardFlags);
|
|
|
|
|
Edited = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-10-20 01:19:01 +00:00
|
|
|
|
protected override MysteryGift[] MysteryGiftCards
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (WondercardData < 0)
|
2019-02-02 07:26:43 +00:00
|
|
|
|
return Array.Empty<MysteryGift>();
|
2016-10-20 01:19:01 +00:00
|
|
|
|
MysteryGift[] cards = new MysteryGift[GiftCountMax];
|
|
|
|
|
for (int i = 0; i < cards.Length; i++)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
cards[i] = GetWC7(i);
|
2016-10-20 01:19:01 +00:00
|
|
|
|
|
|
|
|
|
return cards;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == null)
|
|
|
|
|
return;
|
2016-10-27 05:06:03 +00:00
|
|
|
|
if (value.Length > GiftCountMax)
|
|
|
|
|
Array.Resize(ref value, GiftCountMax);
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2016-10-20 01:19:01 +00:00
|
|
|
|
for (int i = 0; i < value.Length; i++)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetWC7(value[i], i);
|
2016-10-20 01:19:01 +00:00
|
|
|
|
for (int i = value.Length; i < GiftCountMax; i++)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetWC7(new WC7(), i);
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private WC7 GetWC7(int index)
|
2016-10-20 01:19:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (WondercardData < 0)
|
2019-02-02 07:26:43 +00:00
|
|
|
|
throw new ArgumentException(nameof(WondercardData));
|
2016-10-20 01:19:01 +00:00
|
|
|
|
if (index < 0 || index > GiftCountMax)
|
2019-02-02 07:26:43 +00:00
|
|
|
|
throw new ArgumentException(nameof(index));
|
2016-10-20 01:19:01 +00:00
|
|
|
|
|
2018-09-15 05:37:47 +00:00
|
|
|
|
return new WC7(GetData(WondercardData + (index * WC7.Size), WC7.Size));
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void SetWC7(MysteryGift wc7, int index)
|
2016-10-20 01:19:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (WondercardData < 0)
|
|
|
|
|
return;
|
|
|
|
|
if (index < 0 || index > GiftCountMax)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-09-15 05:37:47 +00:00
|
|
|
|
wc7.Data.CopyTo(Data, WondercardData + (index * WC7.Size));
|
2016-10-20 01:19:01 +00:00
|
|
|
|
|
|
|
|
|
Edited = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Writeback Validity
|
|
|
|
|
public override string MiscSaveChecks()
|
|
|
|
|
{
|
2019-02-07 07:28:02 +00:00
|
|
|
|
var sb = new StringBuilder();
|
2016-11-12 15:30:51 +00:00
|
|
|
|
|
|
|
|
|
// FFFF checks
|
2016-10-20 01:19:01 +00:00
|
|
|
|
for (int i = 0; i < Data.Length / 0x200; i++)
|
|
|
|
|
{
|
2018-02-19 19:33:37 +00:00
|
|
|
|
if (Data.Skip(i * 0x200).Take(0x200).Any(z => z != 0xFF))
|
|
|
|
|
continue;
|
2019-02-07 07:28:02 +00:00
|
|
|
|
sb.Append("0x200 chunk @ 0x").AppendFormat("{0:X5}", i * 0x200).AppendLine(" is FF'd.");
|
|
|
|
|
sb.AppendLine("Cyber will screw up (as of August 31st 2014).");
|
|
|
|
|
sb.AppendLine();
|
2016-10-20 01:19:01 +00:00
|
|
|
|
|
|
|
|
|
// Check to see if it is in the Pokedex
|
|
|
|
|
if (i * 0x200 > PokeDex && i * 0x200 < PokeDex + 0x900)
|
|
|
|
|
{
|
2019-02-07 07:28:02 +00:00
|
|
|
|
sb.Append("Problem lies in the Pokedex. ");
|
2016-10-20 01:19:01 +00:00
|
|
|
|
if (i * 0x200 == PokeDex + 0x400)
|
2019-02-07 07:28:02 +00:00
|
|
|
|
sb.Append("Remove a language flag for a species < 585, ie Petilil");
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-02-07 07:28:02 +00:00
|
|
|
|
return sb.ToString();
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-02-19 19:33:37 +00:00
|
|
|
|
public override string MiscSaveInfo() => string.Join(Environment.NewLine, Blocks.Select(b => b.Summary));
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-03-30 18:06:01 +00:00
|
|
|
|
public bool MegaUnlocked
|
|
|
|
|
{
|
2017-08-13 07:21:42 +00:00
|
|
|
|
get => (Data[TrainerCard + 0x78] & 0x01) != 0;
|
|
|
|
|
set => Data[TrainerCard + 0x78] = (byte)((Data[TrainerCard + 0x78] & 0xFE) | (value ? 1 : 0)); // in battle
|
2017-05-13 03:32:36 +00:00
|
|
|
|
// Data[0x1F22] = (byte)((Data[0x1F22] & 0xFE) | (value ? 1 : 0)); // event
|
2017-03-30 18:06:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-11-13 05:28:34 +00:00
|
|
|
|
public bool ZMoveUnlocked
|
|
|
|
|
{
|
|
|
|
|
get => (Data[TrainerCard + 0x78] & 2) != 0;
|
|
|
|
|
set => Data[TrainerCard + 0x78] = (byte)((Data[TrainerCard + 0x78] & ~2) | (value ? 2 : 0)); // in battle
|
|
|
|
|
}
|
2016-11-12 15:34:22 +00:00
|
|
|
|
|
2018-12-05 06:00:57 +00:00
|
|
|
|
public override string GetString(byte[] data, int offset, int length) => StringConverter.GetString7(data, offset, length);
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
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-10-04 01:15:15 +00:00
|
|
|
|
return StringConverter.SetString7(value, maxLength, Language, PadToSize, PadWith);
|
2017-04-09 21:06:50 +00:00
|
|
|
|
}
|
2016-10-20 01:19:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|