2022-06-18 18:04:24 +00:00
|
|
|
using System;
|
2017-09-30 05:58:25 +00:00
|
|
|
using System.Collections.Generic;
|
2023-08-17 07:07:54 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2022-01-03 05:35:59 +00:00
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Generation 4 abstract <see cref="SaveFile"/> object.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// Storage data is stored in one contiguous block, and the remaining data is stored in another block.
|
|
|
|
/// </remarks>
|
|
|
|
public abstract class SAV4 : SaveFile, IEventFlag37
|
2016-06-20 04:22:43 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
protected internal override string ShortSummary => $"{OT} ({Version}) - {PlayTimeString}";
|
|
|
|
public sealed override string Extension => ".sav";
|
2016-06-20 04:22:43 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Blocks & Offsets
|
|
|
|
private const int PartitionSize = 0x40000;
|
2020-03-12 04:09:36 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// SaveData is chunked into two pieces.
|
2023-03-26 22:16:12 +00:00
|
|
|
private readonly Memory<byte> StorageBuffer;
|
|
|
|
protected internal readonly Memory<byte> GeneralBuffer;
|
|
|
|
protected Span<byte> Storage => StorageBuffer.Span;
|
|
|
|
public Span<byte> General => GeneralBuffer.Span;
|
2023-03-26 06:14:50 +00:00
|
|
|
protected sealed override Span<byte> BoxBuffer => Storage;
|
|
|
|
protected sealed override Span<byte> PartyBuffer => General;
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2023-11-09 07:33:40 +00:00
|
|
|
private readonly Memory<byte> BackupStorageBuffer;
|
|
|
|
private readonly Memory<byte> BackupGeneralBuffer;
|
|
|
|
private Span<byte> BackupStorage => BackupStorageBuffer.Span;
|
|
|
|
private Span<byte> BackupGeneral => BackupGeneralBuffer.Span;
|
|
|
|
protected abstract IReadOnlyList<BlockInfo4> ExtraBlocks { get; }
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public abstract Zukan4 Dex { get; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected abstract int EventFlag { get; }
|
|
|
|
protected abstract int EventWork { get; }
|
|
|
|
public sealed override bool GetFlag(int offset, int bitIndex) => FlagUtil.GetFlag(General, offset, bitIndex);
|
|
|
|
public sealed override void SetFlag(int offset, int bitIndex, bool value) => FlagUtil.SetFlag(General, offset, bitIndex, value);
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2023-12-04 04:13:20 +00:00
|
|
|
protected SAV4([ConstantExpected] int gSize, [ConstantExpected] int sSize)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-03-26 22:16:12 +00:00
|
|
|
GeneralBuffer = new byte[gSize];
|
|
|
|
StorageBuffer = new byte[sSize];
|
2023-11-09 07:33:40 +00:00
|
|
|
BackupGeneralBuffer = new byte[gSize];
|
|
|
|
BackupStorageBuffer = new byte[sSize];
|
2022-06-18 18:04:24 +00:00
|
|
|
ClearBoxes();
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
2023-12-04 04:13:20 +00:00
|
|
|
protected SAV4(byte[] data, [ConstantExpected] int gSize, [ConstantExpected] int sSize, [ConstantExpected] int sStart) : base(data)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-03-26 22:16:12 +00:00
|
|
|
var GeneralBlockPosition = GetActiveBlock(data, 0, gSize);
|
|
|
|
var StorageBlockPosition = GetActiveBlock(data, sStart, sSize);
|
2017-01-16 00:16:35 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var gbo = (GeneralBlockPosition == 0 ? 0 : PartitionSize);
|
|
|
|
var sbo = (StorageBlockPosition == 0 ? 0 : PartitionSize) + sStart;
|
2023-03-26 22:16:12 +00:00
|
|
|
GeneralBuffer = Data.AsMemory(gbo, gSize);
|
|
|
|
StorageBuffer = Data.AsMemory(sbo, sSize);
|
2023-11-09 07:33:40 +00:00
|
|
|
|
|
|
|
var gboBackup = (GeneralBlockPosition != 0 ? 0 : PartitionSize);
|
|
|
|
var sboBackup = (StorageBlockPosition != 0 ? 0 : PartitionSize) + sStart;
|
|
|
|
BackupGeneralBuffer = Data.AsMemory(gboBackup, gSize);
|
|
|
|
BackupStorageBuffer = Data.AsMemory(sboBackup, sSize);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Configuration
|
2023-01-22 04:02:33 +00:00
|
|
|
protected sealed override SAV4 CloneInternal()
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
var sav = CloneInternal4();
|
2023-03-26 06:14:50 +00:00
|
|
|
SetData(sav.General, General);
|
|
|
|
SetData(sav.Storage, Storage);
|
2022-06-18 18:04:24 +00:00
|
|
|
return sav;
|
|
|
|
}
|
2017-01-16 00:16:35 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected abstract SAV4 CloneInternal4();
|
|
|
|
|
|
|
|
public sealed override void CopyChangesFrom(SaveFile sav)
|
|
|
|
{
|
|
|
|
SetData(sav.Data, 0);
|
|
|
|
var s4 = (SAV4)sav;
|
2023-03-26 06:14:50 +00:00
|
|
|
SetData(General, s4.General);
|
|
|
|
SetData(Storage, s4.Storage);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected sealed override int SIZE_STORED => PokeCrypto.SIZE_4STORED;
|
|
|
|
protected sealed override int SIZE_PARTY => PokeCrypto.SIZE_4PARTY;
|
2023-01-22 04:02:33 +00:00
|
|
|
public sealed override PK4 BlankPKM => new();
|
2022-06-18 18:04:24 +00:00
|
|
|
public sealed override Type PKMType => typeof(PK4);
|
|
|
|
|
|
|
|
public sealed override int BoxCount => 18;
|
2023-09-28 23:40:23 +00:00
|
|
|
public sealed override int MaxEV => EffortValues.Max255;
|
2022-06-18 18:04:24 +00:00
|
|
|
public sealed override int Generation => 4;
|
|
|
|
public override EntityContext Context => EntityContext.Gen4;
|
|
|
|
public int EventFlagCount => 0xB60; // 2912
|
|
|
|
public int EventWorkCount => (EventFlag - EventWork) >> 1;
|
|
|
|
protected sealed override int GiftCountMax => 11;
|
2022-11-25 01:42:17 +00:00
|
|
|
public sealed override int MaxStringLengthOT => 7;
|
|
|
|
public sealed override int MaxStringLengthNickname => 10;
|
2022-06-18 18:04:24 +00:00
|
|
|
public sealed override int MaxMoney => 999999;
|
|
|
|
public sealed override int MaxCoins => 50_000;
|
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public sealed override ushort MaxMoveID => Legal.MaxMoveID_4;
|
|
|
|
public sealed override ushort MaxSpeciesID => Legal.MaxSpeciesID_4;
|
2022-06-18 18:04:24 +00:00
|
|
|
// MaxItemID
|
|
|
|
public sealed override int MaxAbilityID => Legal.MaxAbilityID_4;
|
|
|
|
public sealed override int MaxBallID => Legal.MaxBallID_4;
|
|
|
|
public sealed override int MaxGameID => Legal.MaxGameID_4; // Colo/XD
|
|
|
|
|
|
|
|
// Checksums
|
|
|
|
protected abstract int FooterSize { get; }
|
|
|
|
private ushort CalcBlockChecksum(ReadOnlySpan<byte> data) => Checksums.CRC16_CCITT(data[..^FooterSize]);
|
|
|
|
private static ushort GetBlockChecksumSaved(ReadOnlySpan<byte> data) => ReadUInt16LittleEndian(data[^2..]);
|
|
|
|
private bool GetBlockChecksumValid(ReadOnlySpan<byte> data) => CalcBlockChecksum(data) == GetBlockChecksumSaved(data);
|
|
|
|
|
2023-11-09 07:33:40 +00:00
|
|
|
protected void SetMagics(uint magic)
|
|
|
|
{
|
|
|
|
WriteUInt32LittleEndian(General[^8..^4], magic);
|
|
|
|
WriteUInt32LittleEndian(Storage[^8..^4], magic);
|
|
|
|
if (ReadUInt32LittleEndian(BackupGeneral[^8..^4]) != 0xFFFFFFFF)
|
|
|
|
WriteUInt32LittleEndian(BackupGeneral[^8..^4], magic);
|
|
|
|
if (ReadUInt32LittleEndian(BackupStorage[^8..^4]) != 0xFFFFFFFF)
|
|
|
|
WriteUInt32LittleEndian(BackupStorage[^8..^4], magic);
|
|
|
|
ExtraBlocks.SetMagics(Data.AsSpan(), magic);
|
|
|
|
ExtraBlocks.SetMagics(Data.AsSpan(PartitionSize..), magic);
|
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected sealed override void SetChecksums()
|
|
|
|
{
|
2023-03-26 22:16:12 +00:00
|
|
|
WriteUInt16LittleEndian(General[^2..], CalcBlockChecksum(General));
|
|
|
|
WriteUInt16LittleEndian(Storage[^2..], CalcBlockChecksum(Storage));
|
2023-11-09 07:33:40 +00:00
|
|
|
if (ReadUInt32LittleEndian(BackupGeneral[^8..^4]) != 0xFFFFFFFF)
|
|
|
|
WriteUInt16LittleEndian(BackupGeneral[^2..], CalcBlockChecksum(BackupGeneral));
|
|
|
|
if (ReadUInt32LittleEndian(BackupStorage[^8..^4]) != 0xFFFFFFFF)
|
|
|
|
WriteUInt16LittleEndian(BackupStorage[^2..], CalcBlockChecksum(BackupStorage));
|
|
|
|
ExtraBlocks.SetChecksums(Data.AsSpan());
|
|
|
|
ExtraBlocks.SetChecksums(Data.AsSpan(PartitionSize..));
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public sealed override bool ChecksumsValid
|
|
|
|
{
|
|
|
|
get
|
2016-06-20 04:22:43 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!GetBlockChecksumValid(General))
|
|
|
|
return false;
|
|
|
|
if (!GetBlockChecksumValid(Storage))
|
|
|
|
return false;
|
2023-11-09 07:33:40 +00:00
|
|
|
if (!ExtraBlocks.GetChecksumsValid(Data.AsSpan()))
|
|
|
|
return false;
|
|
|
|
if (!ExtraBlocks.GetChecksumsValid(Data.AsSpan(PartitionSize..)))
|
|
|
|
return false;
|
2017-01-16 00:16:35 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
return true;
|
2016-06-20 04:22:43 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public sealed override string ChecksumInfo
|
|
|
|
{
|
|
|
|
get
|
2016-06-20 04:22:43 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var list = new List<string>();
|
|
|
|
if (!GetBlockChecksumValid(General))
|
|
|
|
list.Add("Small block checksum is invalid");
|
|
|
|
if (!GetBlockChecksumValid(Storage))
|
|
|
|
list.Add("Large block checksum is invalid");
|
2023-11-09 07:33:40 +00:00
|
|
|
if (!ExtraBlocks.GetChecksumsValid(Data.AsSpan()))
|
|
|
|
list.Add(ExtraBlocks.GetChecksumInfo(Data.AsSpan()));
|
|
|
|
if (!ExtraBlocks.GetChecksumsValid(Data.AsSpan(PartitionSize..)))
|
|
|
|
list.Add(ExtraBlocks.GetChecksumInfo(Data.AsSpan(PartitionSize..)));
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
return list.Count != 0 ? string.Join(Environment.NewLine, list) : "Checksums are valid.";
|
2016-09-13 01:10:42 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-07-25 23:00:52 +00:00
|
|
|
|
2023-12-04 04:13:20 +00:00
|
|
|
private static int GetActiveBlock(ReadOnlySpan<byte> data, [ConstantExpected] int begin, [ConstantExpected] int length)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
int offset = begin + length - 0x14;
|
|
|
|
return SAV4BlockDetection.CompareFooters(data, offset, offset + PartitionSize);
|
|
|
|
}
|
2019-10-26 19:33:58 +00:00
|
|
|
|
2023-11-09 07:33:40 +00:00
|
|
|
private int GetActiveExtraBlock(BlockInfo4 block)
|
|
|
|
{
|
|
|
|
int index = (int)block.ID;
|
|
|
|
|
|
|
|
// Hall of Fame
|
|
|
|
if (index == 0)
|
|
|
|
return SAV4BlockDetection.CompareExtra(Data, Data.AsSpan(PartitionSize), block);
|
|
|
|
|
|
|
|
// Battle Hall/Battle Videos
|
|
|
|
var KeyOffset = Extra;
|
2023-12-04 04:13:20 +00:00
|
|
|
var KeyBackupOffset = Extra + (0x4 * (ExtraBlocks.Count - 1));
|
|
|
|
var PreferOffset = Extra + (2 * 0x4 * (ExtraBlocks.Count - 1));
|
|
|
|
var key = ReadUInt32LittleEndian(General[(KeyOffset + (0x4 * (index - 1)))..]);
|
|
|
|
var keyBackup = ReadUInt32LittleEndian(General[(KeyBackupOffset + (0x4 * (index - 1)))..]);
|
|
|
|
var prefer = General[PreferOffset + (index - 1)];
|
2023-11-09 07:33:40 +00:00
|
|
|
return SAV4BlockDetection.CompareExtra(Data, Data.AsSpan(PartitionSize), block, key, keyBackup, prefer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Hall4? GetHall()
|
|
|
|
{
|
|
|
|
var block = ExtraBlocks[1];
|
|
|
|
var active = GetActiveExtraBlock(block);
|
|
|
|
return active == -1 ? null : new Hall4(Data, (active == 0 ? 0 : PartitionSize) + block.Offset);
|
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected int WondercardFlags = int.MinValue;
|
|
|
|
protected int AdventureInfo = int.MinValue;
|
|
|
|
protected int Seal = int.MinValue;
|
2023-12-18 00:39:15 +00:00
|
|
|
public int Chatter { get; protected set; } = int.MinValue;
|
|
|
|
public int Geonet { get; protected set; } = int.MinValue;
|
2023-11-09 07:33:40 +00:00
|
|
|
protected int Extra = int.MinValue;
|
2022-06-18 18:04:24 +00:00
|
|
|
protected int Trainer1;
|
|
|
|
public int GTS { get; protected set; } = int.MinValue;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Storage
|
|
|
|
public override int PartyCount
|
|
|
|
{
|
|
|
|
get => General[Party - 4];
|
|
|
|
protected set => General[Party - 4] = (byte)value;
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public sealed override int GetPartyOffset(int slot) => Party + (SIZE_PARTY * slot);
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Trainer Info
|
|
|
|
public override string OT
|
|
|
|
{
|
2023-03-26 22:16:12 +00:00
|
|
|
get => GetString(General.Slice(Trainer1, 16));
|
|
|
|
set => SetString(General.Slice(Trainer1, 16), value, MaxStringLengthOT, StringConverterOption.ClearZero);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public override uint ID32
|
|
|
|
{
|
2023-03-26 22:16:12 +00:00
|
|
|
get => ReadUInt32LittleEndian(General[(Trainer1 + 0x10)..]);
|
|
|
|
set => WriteUInt32LittleEndian(General[(Trainer1 + 0x10)..], value);
|
2023-01-22 04:02:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override ushort TID16
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-03-26 22:16:12 +00:00
|
|
|
get => ReadUInt16LittleEndian(General[(Trainer1 + 0x10)..]);
|
|
|
|
set => WriteUInt16LittleEndian(General[(Trainer1 + 0x10)..], value);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public override ushort SID16
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-03-26 22:16:12 +00:00
|
|
|
get => ReadUInt16LittleEndian(General[(Trainer1 + 0x12)..]);
|
|
|
|
set => WriteUInt16LittleEndian(General[(Trainer1 + 0x12)..], value);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override uint Money
|
|
|
|
{
|
2023-03-26 22:16:12 +00:00
|
|
|
get => ReadUInt32LittleEndian(General[(Trainer1 + 0x14)..]);
|
|
|
|
set => WriteUInt32LittleEndian(General[(Trainer1 + 0x14)..], value);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int Gender
|
|
|
|
{
|
|
|
|
get => General[Trainer1 + 0x18];
|
|
|
|
set => General[Trainer1 + 0x18] = (byte)value;
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int Language
|
|
|
|
{
|
|
|
|
get => General[Trainer1 + 0x19];
|
|
|
|
set => General[Trainer1 + 0x19] = (byte)value;
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public int Badges
|
|
|
|
{
|
|
|
|
get => General[Trainer1 + 0x1A];
|
|
|
|
set { if (value < 0) return; General[Trainer1 + 0x1A] = (byte)value; }
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public int Sprite
|
|
|
|
{
|
|
|
|
get => General[Trainer1 + 0x1B];
|
|
|
|
set { if (value < 0) return; General[Trainer1 + 0x1B] = (byte)value; }
|
|
|
|
}
|
2019-07-21 19:30:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public uint Coin
|
|
|
|
{
|
2023-03-26 22:16:12 +00:00
|
|
|
get => ReadUInt16LittleEndian(General[(Trainer1 + 0x20)..]);
|
|
|
|
set => WriteUInt16LittleEndian(General[(Trainer1 + 0x20)..], (ushort)value);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int PlayedHours
|
|
|
|
{
|
2023-03-26 22:16:12 +00:00
|
|
|
get => ReadUInt16LittleEndian(General[(Trainer1 + 0x22)..]);
|
|
|
|
set => WriteUInt16LittleEndian(General[(Trainer1 + 0x22)..], (ushort)value);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int PlayedMinutes
|
|
|
|
{
|
|
|
|
get => General[Trainer1 + 0x24];
|
|
|
|
set => General[Trainer1 + 0x24] = (byte)value;
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int PlayedSeconds
|
|
|
|
{
|
|
|
|
get => General[Trainer1 + 0x25];
|
|
|
|
set => General[Trainer1 + 0x25] = (byte)value;
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public abstract int M { get; set; }
|
|
|
|
public abstract int X { get; set; }
|
|
|
|
public abstract int Y { get; set; }
|
2022-01-03 05:35:59 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public string Rival
|
|
|
|
{
|
|
|
|
get => GetString(Rival_Trash);
|
2023-01-22 04:02:33 +00:00
|
|
|
set => SetString(Rival_Trash, value, MaxStringLengthOT, StringConverterOption.ClearZero);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2021-10-10 23:11:46 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public abstract Span<byte> Rival_Trash { get; set; }
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public abstract int X2 { get; set; }
|
|
|
|
public abstract int Y2 { get; set; }
|
|
|
|
public abstract int Z { get; set; }
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2023-03-26 22:16:12 +00:00
|
|
|
public override uint SecondsToStart { get => ReadUInt32LittleEndian(General[(AdventureInfo + 0x34)..]); set => WriteUInt32LittleEndian(General[(AdventureInfo + 0x34)..], value); }
|
|
|
|
public override uint SecondsToFame { get => ReadUInt32LittleEndian(General[(AdventureInfo + 0x3C)..]); set => WriteUInt32LittleEndian(General[(AdventureInfo + 0x3C)..], value); }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
2023-06-11 16:38:24 +00:00
|
|
|
public bool GeonetGlobalFlag { get => General[Geonet] != 0; set => General[Geonet] = (byte)(value ? 1 : 0); }
|
|
|
|
|
2023-02-27 00:33:53 +00:00
|
|
|
public int Country
|
|
|
|
{
|
2023-06-11 16:38:24 +00:00
|
|
|
get => General[Geonet + 1];
|
|
|
|
set { if (value < 0) return; General[Geonet + 1] = (byte)value; }
|
2023-02-27 00:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int Region
|
|
|
|
{
|
2023-06-11 16:38:24 +00:00
|
|
|
get => General[Geonet + 2];
|
|
|
|
set { if (value < 0) return; General[Geonet + 2] = (byte)value; }
|
2023-02-27 00:33:53 +00:00
|
|
|
}
|
|
|
|
|
2023-11-09 07:33:40 +00:00
|
|
|
public const uint MAGIC_JAPAN_INTL = 0x20060623;
|
|
|
|
public const uint MAGIC_KOREAN = 0x20070903;
|
|
|
|
public uint Magic { get => ReadUInt32LittleEndian(General[^8..^4]); set => SetMagics(value); }
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
protected sealed override PK4 GetPKM(byte[] data) => new(data);
|
2022-06-18 18:04:24 +00:00
|
|
|
protected sealed override byte[] DecryptPKM(byte[] data) => PokeCrypto.DecryptArray45(data);
|
|
|
|
|
|
|
|
protected sealed override void SetPKM(PKM pk, bool isParty = false)
|
|
|
|
{
|
|
|
|
var pk4 = (PK4)pk;
|
|
|
|
// Apply to this Save File
|
2023-09-11 04:17:47 +00:00
|
|
|
var now = EncounterDate.GetDateNDS();
|
|
|
|
if (pk4.Trade(OT, ID32, Gender, now.Day, now.Month, now.Year))
|
2022-06-18 18:04:24 +00:00
|
|
|
pk.RefreshChecksum();
|
|
|
|
}
|
2018-03-22 04:10:23 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Daycare
|
|
|
|
public override int GetDaycareSlotOffset(int loc, int slot) => DaycareOffset + (slot * SIZE_PARTY);
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override uint? GetDaycareEXP(int loc, int slot)
|
|
|
|
{
|
|
|
|
int ofs = DaycareOffset + ((slot+1)*SIZE_PARTY) - 4;
|
2023-03-26 22:16:12 +00:00
|
|
|
return ReadUInt32LittleEndian(General[ofs..]);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override bool? IsDaycareOccupied(int loc, int slot) => null; // todo
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override void SetDaycareEXP(int loc, int slot, uint EXP)
|
|
|
|
{
|
|
|
|
int ofs = DaycareOffset + ((slot+1)*SIZE_PARTY) - 4;
|
2023-03-26 22:16:12 +00:00
|
|
|
WriteUInt32LittleEndian(General[ofs..], EXP);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void SetDaycareOccupied(int loc, int slot, bool occupied)
|
|
|
|
{
|
|
|
|
// todo
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mystery Gift
|
|
|
|
private bool MysteryGiftActive { get => (General[72] & 1) == 1; set => General[72] = (byte)((General[72] & 0xFE) | (value ? 1 : 0)); }
|
|
|
|
|
|
|
|
private static bool IsMysteryGiftAvailable(DataMysteryGift[] value)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 8; i++) // 8 PGT
|
2016-06-20 04:22:43 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (value[i] is PGT {CardType: not 0})
|
|
|
|
return true;
|
2016-06-20 04:22:43 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
for (int i = 8; i < 11; i++) // 3 PCD
|
2019-02-02 18:19:41 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (value[i] is PCD {Gift.CardType: not 0 })
|
|
|
|
return true;
|
2019-02-02 18:19:41 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
2022-09-05 05:23:35 +00:00
|
|
|
private bool MatchMysteryGifts(DataMysteryGift[] value, Span<byte> indexes)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < 8; i++)
|
2017-01-16 00:52:10 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (value[i] is not PGT pgt)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (pgt.CardType == 0) // empty
|
2018-09-15 05:37:47 +00:00
|
|
|
{
|
2022-09-05 05:23:35 +00:00
|
|
|
indexes[i] = pgt.Slot = 0;
|
2022-06-18 18:04:24 +00:00
|
|
|
continue;
|
2018-09-15 05:37:47 +00:00
|
|
|
}
|
2017-01-20 07:49:46 +00:00
|
|
|
|
2022-09-05 05:23:35 +00:00
|
|
|
indexes[i] = pgt.Slot = 3;
|
2022-06-18 18:04:24 +00:00
|
|
|
for (byte j = 0; j < 3; j++)
|
2017-01-20 07:49:46 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (value[8 + j] is not PCD pcd)
|
2017-01-20 07:49:46 +00:00
|
|
|
continue;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Check if data matches (except Slot @ 0x02)
|
|
|
|
if (!pcd.GiftEquals(pgt))
|
2017-01-21 03:35:56 +00:00
|
|
|
continue;
|
|
|
|
|
2023-12-04 04:13:20 +00:00
|
|
|
if (this is not SAV4HGSS)
|
|
|
|
j++; // HG/SS 0,1,2; D/P/Pt 1,2,3
|
2022-09-05 05:23:35 +00:00
|
|
|
indexes[i] = pgt.Slot = j;
|
2022-06-18 18:04:24 +00:00
|
|
|
break;
|
2017-01-20 07:49:46 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-05 05:23:35 +00:00
|
|
|
return true;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override MysteryGiftAlbum GiftAlbum
|
|
|
|
{
|
|
|
|
get => new(MysteryGiftCards, MysteryGiftReceivedFlags) {Flags = {[2047] = false}};
|
|
|
|
set
|
2016-06-20 04:22:43 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
bool available = IsMysteryGiftAvailable(value.Gifts);
|
|
|
|
if (available && !MysteryGiftActive)
|
|
|
|
MysteryGiftActive = true;
|
|
|
|
value.Flags[2047] = available;
|
2017-01-16 00:52:10 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Check encryption for each gift (decrypted wc4 sneaking in)
|
|
|
|
foreach (var g in value.Gifts)
|
|
|
|
{
|
|
|
|
if (g is PGT pgt)
|
2017-12-11 18:13:08 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
pgt.VerifyPKEncryption();
|
|
|
|
}
|
|
|
|
else if (g is PCD pcd)
|
|
|
|
{
|
|
|
|
var dg = pcd.Gift;
|
|
|
|
if (dg.VerifyPKEncryption())
|
|
|
|
pcd.Gift = dg; // set encrypted gift back to PCD.
|
2017-12-11 18:13:08 +00:00
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
MysteryGiftReceivedFlags = value.Flags;
|
|
|
|
MysteryGiftCards = value.Gifts;
|
2016-06-20 04:22:43 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected sealed override bool[] MysteryGiftReceivedFlags
|
|
|
|
{
|
|
|
|
get
|
2016-06-20 04:22:43 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
bool[] result = new bool[GiftFlagMax];
|
|
|
|
for (int i = 0; i < result.Length; i++)
|
|
|
|
result[i] = ((General[WondercardFlags + (i >> 3)] >> (i & 7)) & 0x1) == 1;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (GiftFlagMax != value.Length)
|
|
|
|
return;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
2023-03-26 22:16:12 +00:00
|
|
|
Span<byte> data = General.Slice(WondercardFlags, value.Length / 8);
|
2022-06-18 18:04:24 +00:00
|
|
|
data.Clear();
|
|
|
|
for (int i = 0; i < value.Length; i++)
|
|
|
|
{
|
|
|
|
if (value[i])
|
|
|
|
data[i >> 3] |= (byte)(1 << (i & 7));
|
2017-01-21 20:09:15 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2017-01-21 20:09:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected sealed override DataMysteryGift[] MysteryGiftCards
|
|
|
|
{
|
|
|
|
get
|
2016-06-20 04:22:43 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
int pcd = this is SAV4HGSS ? 4 : 3;
|
|
|
|
DataMysteryGift[] cards = new DataMysteryGift[8 + pcd];
|
|
|
|
for (int i = 0; i < 8; i++) // 8 PGT
|
2023-03-26 22:16:12 +00:00
|
|
|
cards[i] = new PGT(General.Slice(WondercardData + (i * PGT.Size), PGT.Size).ToArray());
|
2022-06-18 18:04:24 +00:00
|
|
|
for (int i = 8; i < 11; i++) // 3 PCD
|
2023-03-26 22:16:12 +00:00
|
|
|
cards[i] = new PCD(General.Slice(WondercardData + (8 * PGT.Size) + ((i-8) * PCD.Size), PCD.Size).ToArray());
|
2022-06-18 18:04:24 +00:00
|
|
|
if (this is SAV4HGSS hgss)
|
|
|
|
cards[^1] = hgss.LockCapsuleSlot;
|
|
|
|
return cards;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2022-09-05 05:23:35 +00:00
|
|
|
Span<byte> indexes = stackalloc byte[8];
|
|
|
|
bool matchAny = MatchMysteryGifts(value, indexes); // automatically applied
|
|
|
|
if (!matchAny)
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (int i = 0; i < 8; i++) // 8 PGT
|
2016-06-20 04:22:43 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (value[i] is PGT)
|
2023-03-26 22:16:12 +00:00
|
|
|
{
|
|
|
|
var ofs = (WondercardData + (i * PGT.Size));
|
|
|
|
SetData(General[ofs..], value[i].Data);
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
for (int i = 8; i < 11; i++) // 3 PCD
|
2016-06-20 04:22:43 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (value[i] is PCD)
|
2023-03-26 22:16:12 +00:00
|
|
|
{
|
|
|
|
var ofs = (WondercardData + (8 * PGT.Size) + ((i - 8) * PCD.Size));
|
|
|
|
SetData(General[ofs..], value[i].Data);
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
if (this is SAV4HGSS hgss && value.Length >= 11 && value[^1] is PCD capsule)
|
|
|
|
hgss.LockCapsuleSlot = capsule;
|
2016-06-20 04:22:43 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2016-07-04 20:06:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected sealed override void SetDex(PKM pk) => Dex.SetDex(pk);
|
2022-08-27 06:43:36 +00:00
|
|
|
public sealed override bool GetCaught(ushort species) => Dex.GetCaught(species);
|
|
|
|
public sealed override bool GetSeen(ushort species) => Dex.GetSeen(species);
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public int DexUpgraded
|
|
|
|
{
|
|
|
|
get
|
2017-03-21 03:14:37 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
switch (Version)
|
2017-03-22 05:50:55 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
case GameVersion.DP:
|
|
|
|
if (General[0x1413] != 0) return 4;
|
|
|
|
if (General[0x1415] != 0) return 3;
|
|
|
|
if (General[0x1404] != 0) return 2;
|
|
|
|
if (General[0x1414] != 0) return 1;
|
|
|
|
return 0;
|
|
|
|
case GameVersion.HGSS:
|
|
|
|
if (General[0x15ED] != 0) return 3;
|
|
|
|
if (General[0x15EF] != 0) return 2;
|
|
|
|
if (General[0x15EE] != 0 && (General[0x10D1] & 8) != 0) return 1;
|
|
|
|
return 0;
|
|
|
|
case GameVersion.Pt:
|
|
|
|
if (General[0x1641] != 0) return 4;
|
|
|
|
if (General[0x1643] != 0) return 3;
|
|
|
|
if (General[0x1640] != 0) return 2;
|
|
|
|
if (General[0x1642] != 0) return 1;
|
|
|
|
return 0;
|
|
|
|
default: return 0;
|
2017-03-22 05:50:55 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
switch (Version)
|
2017-03-22 05:50:55 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
case GameVersion.DP:
|
|
|
|
General[0x1413] = value == 4 ? (byte)1 : (byte)0;
|
|
|
|
General[0x1415] = value >= 3 ? (byte)1 : (byte)0;
|
|
|
|
General[0x1404] = value >= 2 ? (byte)1 : (byte)0;
|
|
|
|
General[0x1414] = value >= 1 ? (byte)1 : (byte)0;
|
|
|
|
break;
|
|
|
|
case GameVersion.HGSS:
|
|
|
|
General[0x15ED] = value == 3 ? (byte)1 : (byte)0;
|
|
|
|
General[0x15EF] = value >= 2 ? (byte)1 : (byte)0;
|
|
|
|
General[0x15EE] = value >= 1 ? (byte)1 : (byte)0;
|
|
|
|
General[0x10D1] = (byte)((General[0x10D1] & ~8) | (value >= 1 ? 8 : 0));
|
|
|
|
break;
|
|
|
|
case GameVersion.Pt:
|
|
|
|
General[0x1641] = value == 4 ? (byte)1 : (byte)0;
|
|
|
|
General[0x1643] = value >= 3 ? (byte)1 : (byte)0;
|
|
|
|
General[0x1640] = value >= 2 ? (byte)1 : (byte)0;
|
|
|
|
General[0x1642] = value >= 1 ? (byte)1 : (byte)0;
|
|
|
|
break;
|
|
|
|
default: return;
|
2017-03-22 05:50:55 +00:00
|
|
|
}
|
2017-03-21 03:14:37 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2017-04-07 04:47:28 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public sealed override string GetString(ReadOnlySpan<byte> data) => StringConverter4.GetString(data);
|
2018-09-15 05:37:47 +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 StringConverter4.SetString(destBuffer, value, maxLength, option);
|
|
|
|
}
|
2018-09-04 22:12:35 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
#region Event Flag/Event Work
|
|
|
|
public bool GetEventFlag(int flagNumber)
|
|
|
|
{
|
|
|
|
if ((uint)flagNumber >= EventFlagCount)
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(flagNumber), $"Event Flag to get ({flagNumber}) is greater than max ({EventFlagCount}).");
|
|
|
|
return GetFlag(EventFlag + (flagNumber >> 3), flagNumber & 7);
|
|
|
|
}
|
2019-12-28 02:30:39 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void SetEventFlag(int flagNumber, bool value)
|
|
|
|
{
|
|
|
|
if ((uint)flagNumber >= EventFlagCount)
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(flagNumber), $"Event Flag to set ({flagNumber}) is greater than max ({EventFlagCount}).");
|
|
|
|
SetFlag(EventFlag + (flagNumber >> 3), flagNumber & 7, value);
|
|
|
|
}
|
2019-12-28 02:30:39 +00:00
|
|
|
|
2023-03-26 22:16:12 +00:00
|
|
|
public ushort GetWork(int index) => ReadUInt16LittleEndian(General[(EventWork + (index * 2))..]);
|
|
|
|
public void SetWork(int index, ushort value) => WriteUInt16LittleEndian(General[EventWork..][(index * 2)..], value);
|
2022-06-18 18:04:24 +00:00
|
|
|
#endregion
|
2022-04-10 01:12:57 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Seals
|
|
|
|
private const byte SealMaxCount = 99;
|
2020-11-12 05:01:41 +00:00
|
|
|
|
2023-03-26 22:16:12 +00:00
|
|
|
public Span<byte> GetSealCase() => General.Slice(Seal, (int)Seal4.MAX);
|
|
|
|
public void SetSealCase(ReadOnlySpan<byte> value) => SetData(General.Slice(Seal, (int)Seal4.MAX), value);
|
2020-11-12 05:01:41 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public byte GetSealCount(Seal4 id) => General[Seal + (int)id];
|
|
|
|
public byte SetSealCount(Seal4 id, byte count) => General[Seal + (int)id] = Math.Min(SealMaxCount, count);
|
2019-04-30 00:21:19 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void SetAllSeals(byte count, bool unreleased = false)
|
|
|
|
{
|
|
|
|
var sealIndexCount = (int)(unreleased ? Seal4.MAX : Seal4.MAXLEGAL);
|
|
|
|
var clamped = Math.Min(count, SealMaxCount);
|
|
|
|
for (int i = 0; i < sealIndexCount; i++)
|
|
|
|
General[Seal + i] = clamped;
|
|
|
|
}
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public int GetMailOffset(int index)
|
|
|
|
{
|
|
|
|
int ofs = (index * Mail4.SIZE);
|
|
|
|
return Version switch
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
GameVersion.DP => (ofs + 0x4BEC),
|
|
|
|
GameVersion.Pt => (ofs + 0x4E80),
|
|
|
|
_ => (ofs + 0x3FA8),
|
|
|
|
};
|
|
|
|
}
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
2023-03-26 22:16:12 +00:00
|
|
|
public byte[] GetMailData(int ofs) => General.Slice(ofs, Mail4.SIZE).ToArray();
|
2021-05-22 16:28:04 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public Mail4 GetMail(int mailIndex)
|
|
|
|
{
|
|
|
|
int ofs = GetMailOffset(mailIndex);
|
|
|
|
return new Mail4(GetMailData(ofs), ofs);
|
|
|
|
}
|
2021-08-21 02:52:31 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public abstract uint SwarmSeed { get; set; }
|
|
|
|
public abstract uint SwarmMaxCountModulo { get; }
|
2021-08-21 02:52:31 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public uint SwarmIndex
|
|
|
|
{
|
|
|
|
get => SwarmSeed % SwarmMaxCountModulo;
|
|
|
|
set
|
2021-08-21 02:52:31 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
value %= SwarmMaxCountModulo;
|
|
|
|
while (SwarmIndex != value)
|
|
|
|
++SwarmSeed;
|
2021-08-21 02:52:31 +00:00
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
}
|
|
|
|
}
|