2015-10-22 00:16:44 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2017-01-07 23:54:09 -08:00
|
|
|
|
namespace PKHeX.Core
|
2015-10-22 00:16:44 -07:00
|
|
|
|
{
|
2017-10-23 23:12:58 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generation 6 <see cref="SaveFile"/> object.
|
|
|
|
|
/// </summary>
|
2019-06-08 19:56:11 -07:00
|
|
|
|
public abstract class SAV6 : SAV_BEEF, ITrainerStatRecord
|
2015-10-22 00:16:44 -07:00
|
|
|
|
{
|
|
|
|
|
// Save Data Attributes
|
2019-06-08 19:56:11 -07:00
|
|
|
|
protected override string BAKText => $"{OT} ({Version}) - {Played.LastSavedTime}";
|
2016-06-19 22:11:53 -07:00
|
|
|
|
public override string Filter => "Main SAV|*.*";
|
2019-02-07 21:40:20 -08:00
|
|
|
|
public override string Extension => string.Empty;
|
2018-09-14 22:37:47 -07:00
|
|
|
|
|
2019-06-08 19:56:11 -07:00
|
|
|
|
protected SAV6(byte[] data, BlockInfo[] blocks, int biOffset) : base(data, blocks, biOffset) { }
|
|
|
|
|
protected SAV6(int size, BlockInfo[] blocks, int biOffset) : base(size, blocks, biOffset) => ClearBoxes();
|
2015-10-22 00:16:44 -07:00
|
|
|
|
|
2016-06-19 21:22:43 -07:00
|
|
|
|
// Configuration
|
|
|
|
|
public override int SIZE_STORED => PKX.SIZE_6STORED;
|
2017-06-17 18:37:19 -07:00
|
|
|
|
protected override int SIZE_PARTY => PKX.SIZE_6PARTY;
|
2016-06-19 21:22:43 -07:00
|
|
|
|
public override PKM BlankPKM => new PK6();
|
2016-09-26 16:14:11 -07:00
|
|
|
|
public override Type PKMType => typeof(PK6);
|
2016-06-19 21:22:43 -07:00
|
|
|
|
|
|
|
|
|
public override int BoxCount => 31;
|
|
|
|
|
public override int MaxEV => 252;
|
|
|
|
|
public override int Generation => 6;
|
|
|
|
|
protected override int GiftCountMax => 24;
|
|
|
|
|
protected override int GiftFlagMax => 0x100 * 8;
|
|
|
|
|
protected override int EventFlagMax => 8 * 0x180;
|
2019-06-08 19:56:11 -07:00
|
|
|
|
protected override int EventConstMax => (EventFlag - EventConst) / sizeof(ushort);
|
2016-06-19 21:22:43 -07:00
|
|
|
|
public override int OTLength => 12;
|
|
|
|
|
public override int NickLength => 12;
|
|
|
|
|
|
2016-10-23 21:59:27 -07:00
|
|
|
|
public override int MaxSpeciesID => Legal.MaxSpeciesID_6;
|
2017-01-26 19:18:20 -08:00
|
|
|
|
public override int MaxBallID => Legal.MaxBallID_6;
|
|
|
|
|
public override int MaxGameID => Legal.MaxGameID_6; // OR
|
2016-06-20 18:58:06 -07:00
|
|
|
|
|
2019-06-08 19:56:11 -07:00
|
|
|
|
protected override PKM GetPKM(byte[] data) => new PK6(data);
|
|
|
|
|
protected override byte[] DecryptPKM(byte[] data) => PKX.DecryptArray(data);
|
2019-01-01 00:57:51 -08:00
|
|
|
|
|
2019-06-08 19:56:11 -07:00
|
|
|
|
public MyItem Items { get; protected set; }
|
|
|
|
|
public ItemInfo6 ItemInfo { get; protected set; }
|
|
|
|
|
public GameTime6 GameTime { get; protected set; }
|
|
|
|
|
public Situation6 Situation { get; protected set; }
|
|
|
|
|
public PlayTime6 Played { get; protected set; }
|
|
|
|
|
public MyStatus6 Status { get; protected set; }
|
|
|
|
|
public Record6 Records { get; set; }
|
2016-06-19 21:22:43 -07:00
|
|
|
|
|
|
|
|
|
// Private Only
|
2019-06-08 19:56:11 -07:00
|
|
|
|
protected int Trainer2 { get; set; } = int.MinValue;
|
|
|
|
|
protected int WondercardFlags { get; set; } = int.MinValue;
|
|
|
|
|
protected int PlayTime { get; set; } = int.MinValue;
|
|
|
|
|
protected int Daycare2 { get; set; } = int.MinValue;
|
|
|
|
|
protected int LinkInfo { get; set; } = int.MinValue;
|
|
|
|
|
protected int JPEG { get; set; } = int.MinValue;
|
2016-06-19 21:22:43 -07:00
|
|
|
|
|
|
|
|
|
// Accessible as SAV6
|
2019-06-08 19:56:11 -07:00
|
|
|
|
public int MaisonStats { get; protected set; } = int.MinValue;
|
|
|
|
|
public int Accessories { get; protected set; } = int.MinValue;
|
|
|
|
|
public int PokeDexLanguageFlags { get; protected set; } = int.MinValue;
|
|
|
|
|
public int Spinda { get; protected set; } = int.MinValue;
|
|
|
|
|
public int EncounterCount { get; protected set; } = int.MinValue;
|
2016-06-19 21:22:43 -07:00
|
|
|
|
|
2019-06-08 19:56:11 -07:00
|
|
|
|
protected internal const int LongStringLength = 0x22; // bytes, not characters
|
|
|
|
|
protected internal const int ShortStringLength = 0x1A; // bytes, not characters
|
2018-05-12 08:13:39 -07:00
|
|
|
|
|
2015-10-22 00:16:44 -07:00
|
|
|
|
// Player Information
|
2019-06-08 19:56:11 -07:00
|
|
|
|
public override int TID { get => Status.TID; set => Status.TID = value; }
|
|
|
|
|
public override int SID { get => Status.SID; set => Status.SID = value; }
|
|
|
|
|
public override int Game { get => Status.Game; set => Status.Game = value; }
|
|
|
|
|
public override int Gender { get => Status.Gender; set => Status.Gender = value; }
|
|
|
|
|
public override int Language { get => Status.Language; set => Status.Language = value; }
|
|
|
|
|
public override string OT { get => Status.OT; set => Status.OT = value; }
|
2019-06-08 20:19:39 -07:00
|
|
|
|
public override int SubRegion { get => Status.SubRegion; set => Status.SubRegion = value; }
|
|
|
|
|
public override int Country { get => Status.Country; set => Status.Country = value; }
|
|
|
|
|
public override int ConsoleRegion { get => Status.ConsoleRegion; set => Status.ConsoleRegion = value; }
|
2018-09-14 22:37:47 -07:00
|
|
|
|
|
2016-06-21 17:35:12 -07:00
|
|
|
|
public override uint Money
|
2015-11-20 22:02:15 -08:00
|
|
|
|
{
|
2017-05-12 20:32:36 -07:00
|
|
|
|
get => BitConverter.ToUInt32(Data, Trainer2 + 0x8);
|
|
|
|
|
set => BitConverter.GetBytes(value).CopyTo(Data, Trainer2 + 0x8);
|
2015-11-20 22:02:15 -08:00
|
|
|
|
}
|
2018-09-14 22:37:47 -07:00
|
|
|
|
|
2015-11-20 22:02:15 -08:00
|
|
|
|
public int Badges
|
|
|
|
|
{
|
2017-05-12 20:32:36 -07:00
|
|
|
|
get => Data[Trainer2 + 0xC];
|
|
|
|
|
set => Data[Trainer2 + 0xC] = (byte)value;
|
2015-11-20 22:02:15 -08:00
|
|
|
|
}
|
2018-09-14 22:37:47 -07:00
|
|
|
|
|
2015-11-21 17:23:00 -08:00
|
|
|
|
public int BP
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
int offset = Trainer2 + 0x3C;
|
|
|
|
|
if (ORAS) offset -= 0xC; // 0x30
|
|
|
|
|
return BitConverter.ToUInt16(Data, offset);
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
int offset = Trainer2 + 0x3C;
|
|
|
|
|
if (ORAS) offset -= 0xC; // 0x30
|
|
|
|
|
BitConverter.GetBytes((ushort)value).CopyTo(Data, offset);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-14 22:37:47 -07:00
|
|
|
|
|
2015-11-20 22:02:15 -08:00
|
|
|
|
public int Vivillon
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
int offset = Trainer2 + 0x50;
|
|
|
|
|
if (ORAS) offset -= 0xC; // 0x44
|
|
|
|
|
return Data[offset];
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
int offset = Trainer2 + 0x50;
|
|
|
|
|
if (ORAS) offset -= 0xC; // 0x44
|
|
|
|
|
Data[offset] = (byte)value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-08 19:56:11 -07:00
|
|
|
|
public override int PlayedHours { get => Played.PlayedHours; set => Played.PlayedHours = value; }
|
|
|
|
|
public override int PlayedMinutes { get => Played.PlayedMinutes; set => Played.PlayedMinutes = value; }
|
|
|
|
|
public override int PlayedSeconds { get => Played.PlayedSeconds; set => Played.PlayedSeconds = value; }
|
2018-09-14 22:37:47 -07:00
|
|
|
|
|
2019-06-08 19:56:11 -07:00
|
|
|
|
public override uint SecondsToStart { get => GameTime.SecondsToStart; set => GameTime.SecondsToStart = value; }
|
|
|
|
|
public override uint SecondsToFame { get => GameTime.SecondsToFame; set => GameTime.SecondsToFame = value; }
|
|
|
|
|
public override InventoryPouch[] Inventory { get => Items.Inventory; set => Items.Inventory = value; }
|
2015-10-22 00:16:44 -07:00
|
|
|
|
|
2018-09-14 22:37:47 -07:00
|
|
|
|
public ushort GetMaisonStat(int index) { return BitConverter.ToUInt16(Data, MaisonStats + (2 * index)); }
|
|
|
|
|
public void SetMaisonStat(int index, ushort value) { BitConverter.GetBytes(value).CopyTo(Data, MaisonStats + (2 * index)); }
|
2018-05-12 08:13:39 -07:00
|
|
|
|
|
2016-06-19 21:22:43 -07:00
|
|
|
|
// Daycare
|
|
|
|
|
public override int DaycareSeedSize => 16;
|
2016-10-23 12:45:27 -07:00
|
|
|
|
public override bool HasTwoDaycares => ORAS;
|
2018-09-14 22:37:47 -07:00
|
|
|
|
|
2016-06-19 21:22:43 -07:00
|
|
|
|
// Storage
|
2018-09-14 22:37:47 -07:00
|
|
|
|
|
2019-06-08 19:56:11 -07:00
|
|
|
|
public override int GetPartyOffset(int slot) => Party + (SIZE_PARTY * slot);
|
2018-09-14 22:37:47 -07:00
|
|
|
|
|
2019-06-08 19:56:11 -07:00
|
|
|
|
public override int GetBoxOffset(int box) => Box + (SIZE_STORED * box * 30);
|
2018-09-14 22:37:47 -07:00
|
|
|
|
|
2019-01-01 20:05:36 -08:00
|
|
|
|
private int GetBoxNameOffset(int box) => PCLayout + (LongStringLength * box);
|
|
|
|
|
|
2017-06-17 18:37:19 -07:00
|
|
|
|
public override string GetBoxName(int box)
|
2015-10-22 00:16:44 -07:00
|
|
|
|
{
|
2016-06-19 21:22:43 -07:00
|
|
|
|
if (PCLayout < 0)
|
2019-06-08 19:56:11 -07:00
|
|
|
|
return $"B{box + 1}";
|
|
|
|
|
return GetString(Data, GetBoxNameOffset(box), LongStringLength / 2);
|
2015-10-22 00:16:44 -07:00
|
|
|
|
}
|
2018-09-14 22:37:47 -07:00
|
|
|
|
|
2018-05-12 08:13:39 -07:00
|
|
|
|
public override void SetBoxName(int box, string value)
|
2015-10-22 00:16:44 -07:00
|
|
|
|
{
|
2019-06-08 19:56:11 -07:00
|
|
|
|
var data = SetString(value, LongStringLength / 2, LongStringLength / 2);
|
|
|
|
|
SetData(data, PCLayout + (LongStringLength * box));
|
2016-01-24 10:19:30 -08:00
|
|
|
|
}
|
2018-09-14 22:37:47 -07:00
|
|
|
|
|
2017-06-17 18:37:19 -07:00
|
|
|
|
protected override void SetPKM(PKM pkm)
|
2015-10-24 11:29:03 -07:00
|
|
|
|
{
|
2017-12-11 16:01:24 -08:00
|
|
|
|
PK6 pk6 = (PK6)pkm;
|
2015-10-24 11:29:03 -07:00
|
|
|
|
// Apply to this Save File
|
2015-10-24 11:57:07 -07:00
|
|
|
|
int CT = pk6.CurrentHandler;
|
2015-10-24 11:29:03 -07:00
|
|
|
|
DateTime Date = DateTime.Now;
|
2019-03-30 22:05:28 -07:00
|
|
|
|
pk6.Trade(this, Date.Day, Date.Month, Date.Year);
|
2015-10-24 11:57:07 -07:00
|
|
|
|
if (CT != pk6.CurrentHandler) // Logic updated Friendship
|
|
|
|
|
{
|
2015-10-25 18:46:17 -07:00
|
|
|
|
// Copy over the Friendship Value only under certain circumstances
|
|
|
|
|
if (pk6.Moves.Contains(216)) // Return
|
|
|
|
|
pk6.CurrentFriendship = pk6.OppositeFriendship;
|
|
|
|
|
else if (pk6.Moves.Contains(218)) // Frustration
|
2016-06-19 21:22:43 -07:00
|
|
|
|
pkm.CurrentFriendship = pk6.OppositeFriendship;
|
2015-10-24 11:57:07 -07:00
|
|
|
|
}
|
2016-06-19 21:22:43 -07:00
|
|
|
|
pkm.RefreshChecksum();
|
2019-06-08 19:56:11 -07:00
|
|
|
|
AddCountAcquired(pkm);
|
2018-09-27 21:30:20 -07:00
|
|
|
|
}
|
2018-09-26 19:06:05 -07:00
|
|
|
|
|
2018-09-27 21:30:20 -07:00
|
|
|
|
private void AddCountAcquired(PKM pkm)
|
|
|
|
|
{
|
2019-06-08 19:56:11 -07:00
|
|
|
|
Records.AddRecord(pkm.WasEgg ? 009 : 007); // egg, capture
|
2018-09-26 19:06:05 -07:00
|
|
|
|
if (pkm.CurrentHandler == 1)
|
2019-06-08 19:56:11 -07:00
|
|
|
|
Records.AddRecord(012); // trade
|
2018-11-27 08:53:56 -08:00
|
|
|
|
if (!pkm.WasEgg)
|
2019-06-08 19:56:11 -07:00
|
|
|
|
Records.AddRecord(005); // wild encounters
|
2015-10-22 00:16:44 -07:00
|
|
|
|
}
|
2018-09-14 22:37:47 -07:00
|
|
|
|
|
2017-06-17 18:37:19 -07:00
|
|
|
|
protected override void SetPartyValues(PKM pkm, bool isParty)
|
2017-06-06 22:13:12 -07:00
|
|
|
|
{
|
2018-03-25 19:05:49 -07:00
|
|
|
|
base.SetPartyValues(pkm, isParty);
|
2018-07-20 20:25:28 -07:00
|
|
|
|
((PK6)pkm).FormDuration = GetFormDuration(pkm, isParty);
|
|
|
|
|
}
|
2018-09-14 22:37:47 -07:00
|
|
|
|
|
2018-07-20 20:25:28 -07: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-06 22:13:12 -07:00
|
|
|
|
}
|
2017-03-14 22:41:15 -07:00
|
|
|
|
|
2016-06-19 21:22:43 -07:00
|
|
|
|
public override int PartyCount
|
2015-11-15 21:58:34 -08:00
|
|
|
|
{
|
2018-09-14 22:37:47 -07:00
|
|
|
|
get => Data[Party + (6 * SIZE_PARTY)];
|
|
|
|
|
protected set => Data[Party + (6 * SIZE_PARTY)] = (byte)value;
|
2015-11-15 21:58:34 -08:00
|
|
|
|
}
|
2018-09-14 22:37:47 -07:00
|
|
|
|
|
2019-06-08 19:56:11 -07:00
|
|
|
|
private int LockedFlagOffset => BattleBox + (6 * SIZE_STORED);
|
2018-09-14 22:37:47 -07:00
|
|
|
|
|
2019-06-08 19:56:11 -07:00
|
|
|
|
public override bool BattleBoxLocked
|
2016-04-21 19:16:55 -07:00
|
|
|
|
{
|
2019-06-08 19:56:11 -07:00
|
|
|
|
get => BattleBoxLockedWiFiTournament || BattleBoxLockedLiveTournament;
|
|
|
|
|
set => BattleBoxLockedWiFiTournament = BattleBoxLockedLiveTournament = value;
|
2016-04-21 19:16:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-08 19:56:11 -07:00
|
|
|
|
public bool BattleBoxLockedWiFiTournament
|
2017-09-03 17:23:20 -07:00
|
|
|
|
{
|
2019-06-08 19:56:11 -07:00
|
|
|
|
get => (Data[LockedFlagOffset] & 1) != 0;
|
|
|
|
|
set => Data[LockedFlagOffset] = (byte)((Data[LockedFlagOffset] & ~1) | (value ? 1 : 0));
|
2017-09-03 17:23:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-08 19:56:11 -07:00
|
|
|
|
public bool BattleBoxLockedLiveTournament
|
2015-10-24 16:52:25 -07:00
|
|
|
|
{
|
2019-06-08 19:56:11 -07:00
|
|
|
|
get => (Data[LockedFlagOffset] & 2) != 0;
|
|
|
|
|
set => Data[LockedFlagOffset] = (byte)((Data[LockedFlagOffset] & ~2) | (value ? 2 : 0));
|
2015-10-24 16:52:25 -07:00
|
|
|
|
}
|
2018-09-14 22:37:47 -07:00
|
|
|
|
|
2018-12-04 22:00:57 -08:00
|
|
|
|
public override string GetString(byte[] data, int offset, int length) => StringConverter.GetString6(data, offset, length);
|
2018-09-14 22:37:47 -07:00
|
|
|
|
|
2017-06-17 18:37:19 -07:00
|
|
|
|
public override byte[] SetString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
|
2017-04-09 14:06:50 -07:00
|
|
|
|
{
|
|
|
|
|
if (PadToSize == 0)
|
|
|
|
|
PadToSize = maxLength + 1;
|
2017-07-31 23:03:51 -07:00
|
|
|
|
return StringConverter.SetString6(value, maxLength, PadToSize, PadWith);
|
2017-04-09 14:06:50 -07:00
|
|
|
|
}
|
2018-06-09 12:32:55 -07:00
|
|
|
|
|
2019-06-08 19:56:11 -07:00
|
|
|
|
public int GetRecord(int recordID) => Records.GetRecord(recordID);
|
|
|
|
|
public int GetRecordOffset(int recordID) => Records.GetRecordOffset(recordID);
|
|
|
|
|
public int GetRecordMax(int recordID) => Records.GetRecordMax(recordID);
|
|
|
|
|
public void SetRecord(int recordID, int value) => Records.SetRecord(recordID, value);
|
|
|
|
|
public int RecordCount => Record6.RecordCount;
|
2015-10-22 00:16:44 -07:00
|
|
|
|
}
|
2019-06-08 19:56:11 -07:00
|
|
|
|
}
|