2022-06-26 06:08:28 +00:00
|
|
|
using System;
|
2020-12-05 14:09:33 +00:00
|
|
|
using System.Collections.Generic;
|
2023-12-07 08:07:55 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2015-10-22 07:16:44 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Generation 6 <see cref="SaveFile"/> object.
|
|
|
|
/// </summary>
|
2024-03-04 05:13:16 +00:00
|
|
|
public abstract class SAV6 : SAV_BEEF, ITrainerStatRecord, ISaveBlock6Core, IRegionOrigin, IGameSync, IEventFlagProvider37
|
2015-10-22 07:16:44 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
// Save Data Attributes
|
|
|
|
protected internal override string ShortSummary => $"{OT} ({Version}) - {Played.LastSavedTime}";
|
|
|
|
public override string Extension => string.Empty;
|
|
|
|
|
2023-12-07 08:07:55 +00:00
|
|
|
protected SAV6(byte[] data, [ConstantExpected] int biOffset) : base(data, biOffset) { }
|
|
|
|
protected SAV6([ConstantExpected] int size, [ConstantExpected] int biOffset) : base(size, biOffset) { }
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
// Configuration
|
2024-03-04 05:13:16 +00:00
|
|
|
protected sealed override int SIZE_STORED => PokeCrypto.SIZE_6STORED;
|
|
|
|
protected sealed override int SIZE_PARTY => PokeCrypto.SIZE_6PARTY;
|
|
|
|
public sealed override PK6 BlankPKM => new();
|
|
|
|
public sealed override Type PKMType => typeof(PK6);
|
|
|
|
|
|
|
|
public sealed override int BoxCount => 31;
|
|
|
|
public sealed override int MaxEV => EffortValues.Max252;
|
|
|
|
public sealed override byte Generation => 6;
|
|
|
|
public sealed override EntityContext Context => EntityContext.Gen6;
|
2022-11-25 01:42:17 +00:00
|
|
|
public override int MaxStringLengthOT => 12;
|
|
|
|
public override int MaxStringLengthNickname => 12;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public override ushort MaxSpeciesID => Legal.MaxSpeciesID_6;
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int MaxBallID => Legal.MaxBallID_6;
|
2024-02-23 03:20:54 +00:00
|
|
|
public override GameVersion MaxGameID => Legal.MaxGameID_6; // OR
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
protected override PK6 GetPKM(byte[] data) => new(data);
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override byte[] DecryptPKM(byte[] data) => PokeCrypto.DecryptArray6(data);
|
|
|
|
|
|
|
|
protected int JPEG { get; set; } = int.MinValue;
|
|
|
|
public int PSS { get; protected set; } = int.MinValue;
|
|
|
|
public int HoF { get; protected set; } = int.MinValue;
|
|
|
|
|
|
|
|
public virtual string JPEGTitle => string.Empty;
|
2023-12-04 04:13:20 +00:00
|
|
|
public virtual byte[] GetJPEGData() => [];
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
protected internal const int LongStringLength = 0x22; // bytes, not characters
|
|
|
|
protected internal const int ShortStringLength = 0x1A; // bytes, not characters
|
|
|
|
|
|
|
|
// Player Information
|
2023-01-22 04:02:33 +00:00
|
|
|
public override uint ID32 { get => Status.ID32; set => Status.ID32 = value; }
|
|
|
|
public override ushort TID16 { get => Status.TID16; set => Status.TID16 = value; }
|
|
|
|
public override ushort SID16 { get => Status.SID16; set => Status.SID16 = value; }
|
2024-02-23 03:20:54 +00:00
|
|
|
public override GameVersion Version { get => (GameVersion)Status.Game; set => Status.Game = (byte)value; }
|
|
|
|
public override byte Gender { get => Status.Gender; set => Status.Gender = value; }
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int Language { get => Status.Language; set => Status.Language = value; }
|
|
|
|
public override string OT { get => Status.OT; set => Status.OT = value; }
|
|
|
|
public byte Region { get => Status.Region; set => Status.Region = value; }
|
|
|
|
public byte Country { get => Status.Country; set => Status.Country = value; }
|
|
|
|
public byte ConsoleRegion { get => Status.ConsoleRegion; set => Status.ConsoleRegion = value; }
|
|
|
|
public int GameSyncIDSize => MyStatus6.GameSyncIDSize; // 64 bits
|
|
|
|
public string GameSyncID { get => Status.GameSyncID; set => Status.GameSyncID = value; }
|
|
|
|
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; }
|
|
|
|
|
|
|
|
public abstract int Badges { get; set; }
|
|
|
|
public abstract int Vivillon { get; set; }
|
|
|
|
public abstract int BP { get; set; }
|
|
|
|
// Money
|
|
|
|
|
|
|
|
public override uint SecondsToStart { get => GameTime.SecondsToStart; set => GameTime.SecondsToStart = value; }
|
|
|
|
public override uint SecondsToFame { get => GameTime.SecondsToFame; set => GameTime.SecondsToFame = value; }
|
|
|
|
public override IReadOnlyList<InventoryPouch> Inventory { get => Items.Inventory; set => Items.Inventory = value; }
|
|
|
|
|
|
|
|
// Storage
|
|
|
|
public override int GetPartyOffset(int slot) => Party + (SIZE_PARTY * slot);
|
|
|
|
|
|
|
|
public override int GetBoxOffset(int box) => Box + (SIZE_STORED * box * 30);
|
|
|
|
|
|
|
|
protected override void SetPKM(PKM pk, bool isParty = false)
|
|
|
|
{
|
|
|
|
PK6 pk6 = (PK6)pk;
|
|
|
|
// Apply to this Save File
|
2024-02-23 23:01:36 +00:00
|
|
|
pk6.UpdateHandler(this);
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
pk6.FormArgumentElapsed = pk6.FormArgumentMaximum = 0;
|
|
|
|
pk6.FormArgumentRemain = (byte)GetFormArgument(pk, isParty);
|
|
|
|
if (!isParty && pk.Form != 0)
|
2015-10-24 18:29:03 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
switch (pk.Species)
|
2015-10-24 18:57:07 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
case (int) Species.Furfrou:
|
|
|
|
pk.Form = 0;
|
|
|
|
break;
|
|
|
|
case (int) Species.Hoopa:
|
2021-02-09 04:26:53 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
pk.Form = 0;
|
2022-06-26 06:08:28 +00:00
|
|
|
var hsf = pk.GetMoveIndex((int) Move.HyperspaceFury);
|
2022-06-18 18:04:24 +00:00
|
|
|
if (hsf != -1)
|
|
|
|
pk.SetMove(hsf, (int) Move.HyperspaceHole);
|
|
|
|
break;
|
2021-02-09 04:26:53 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-28 04:30:20 +00:00
|
|
|
}
|
2018-09-27 02:06:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
pk.RefreshChecksum();
|
2024-02-23 19:20:59 +00:00
|
|
|
if (SetUpdateRecords != PKMImportSetting.Skip)
|
|
|
|
AddCountAcquired(pk);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void AddCountAcquired(PKM pk)
|
|
|
|
{
|
|
|
|
Records.AddRecord(pk.WasEgg ? 009 : 007); // egg, capture
|
|
|
|
if (pk.CurrentHandler == 1)
|
|
|
|
Records.AddRecord(012); // trade
|
|
|
|
if (!pk.WasEgg)
|
2018-07-21 03:25:28 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
Records.AddRecord(004); // total battles
|
|
|
|
Records.AddRecord(005); // wild encounters
|
2017-06-07 05:13:12 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2017-03-15 05:41:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static uint GetFormArgument(PKM pk, bool isParty)
|
|
|
|
{
|
|
|
|
if (!isParty || pk.Form == 0)
|
|
|
|
return 0;
|
|
|
|
return pk.Species switch
|
2015-11-16 05:58:34 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
(int)Species.Furfrou => 5u, // Furfrou
|
|
|
|
(int)Species.Hoopa => 3u, // Hoopa
|
|
|
|
_ => 0u,
|
|
|
|
};
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int PartyCount
|
|
|
|
{
|
|
|
|
get => Data[Party + (6 * SIZE_PARTY)];
|
|
|
|
protected set => Data[Party + (6 * SIZE_PARTY)] = (byte)value;
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public sealed override string GetString(ReadOnlySpan<byte> data) => StringConverter6.GetString(data);
|
2018-06-09 19:32:55 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public sealed override int SetString(Span<byte> destBuffer, ReadOnlySpan<char> value, int maxLength, StringConverterOption option)
|
|
|
|
{
|
|
|
|
return StringConverter6.SetString(destBuffer, value, maxLength, option);
|
|
|
|
}
|
2022-04-10 01:12:57 +00:00
|
|
|
|
2022-06-18 18:04:24 +00: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 => RecordBlock6.RecordCount;
|
|
|
|
public abstract MyItem Items { get; }
|
|
|
|
public abstract ItemInfo6 ItemInfo { get; }
|
|
|
|
public abstract GameTime6 GameTime { get; }
|
|
|
|
public abstract Situation6 Situation { get; }
|
|
|
|
public abstract PlayTime6 Played { get; }
|
|
|
|
public abstract MyStatus6 Status { get; }
|
|
|
|
public abstract RecordBlock6 Records { get; }
|
2024-03-04 05:13:16 +00:00
|
|
|
public abstract EventWork6 EventWork { get; }
|
|
|
|
IEventFlag37 IEventFlagProvider37.EventWork => EventWork;
|
2021-03-20 19:47:21 +00:00
|
|
|
}
|