2016-06-20 04:22:43 +00:00
|
|
|
|
using System;
|
2017-09-30 05:58:25 +00:00
|
|
|
|
using System.Collections.Generic;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// <summary>
|
2019-09-03 02:30:58 +00:00
|
|
|
|
/// Generation 4 abstract <see cref="SaveFile"/> object.
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// </summary>
|
2019-09-14 18:39:48 +00:00
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Storage data is stored in one contiguous block, and the remaining data is stored in another block.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public abstract class SAV4 : SaveFile
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2018-07-30 04:51:45 +00:00
|
|
|
|
protected override string BAKText => $"{OT} ({Version}) - {PlayTimeString}";
|
2019-02-08 05:40:20 +00:00
|
|
|
|
public override string Filter => (Footer.Length > 0 ? "DeSmuME DSV|*.dsv|" : string.Empty) + "SAV File|*.sav|All Files|*.*";
|
2016-06-20 05:11:53 +00:00
|
|
|
|
public override string Extension => ".sav";
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
// Blocks & Offsets
|
|
|
|
|
private readonly int GeneralBlockPosition; // Small Block
|
|
|
|
|
private readonly int StorageBlockPosition; // Big Block
|
|
|
|
|
|
2019-09-14 18:39:48 +00:00
|
|
|
|
// SaveData is chunked into two pieces.
|
|
|
|
|
protected readonly byte[] Storage;
|
|
|
|
|
public readonly byte[] General;
|
2019-11-16 01:34:18 +00:00
|
|
|
|
protected override byte[] BoxBuffer => Storage;
|
|
|
|
|
protected override byte[] PartyBuffer => General;
|
2019-09-13 02:01:06 +00:00
|
|
|
|
|
2019-09-14 18:39:48 +00:00
|
|
|
|
protected abstract int StorageSize { get; }
|
|
|
|
|
protected abstract int GeneralSize { get; }
|
|
|
|
|
protected abstract int StorageStart { get; }
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override bool GetFlag(int offset, int bitIndex) => FlagUtil.GetFlag(General, offset, bitIndex);
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override void SetFlag(int offset, int bitIndex, bool value) => FlagUtil.SetFlag(General, offset, bitIndex, value);
|
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
protected SAV4()
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
Storage = new byte[StorageSize];
|
|
|
|
|
General = new byte[GeneralSize];
|
2019-06-09 02:56:11 +00:00
|
|
|
|
ClearBoxes();
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
protected SAV4(byte[] data) : base(data)
|
2019-06-09 02:56:11 +00:00
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
GeneralBlockPosition = GetActiveGeneralBlock();
|
|
|
|
|
StorageBlockPosition = GetActiveStorageBlock();
|
2016-06-28 06:03:57 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
var gbo = (GeneralBlockPosition == 0 ? 0 : 0x40000);
|
|
|
|
|
var sbo = (StorageBlockPosition == 0 ? 0 : 0x40000) + StorageStart;
|
|
|
|
|
General = GetData(gbo, GeneralSize);
|
|
|
|
|
Storage = GetData(sbo, StorageSize);
|
2019-06-09 02:56:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
// Configuration
|
|
|
|
|
public override SaveFile Clone()
|
2019-06-09 02:56:11 +00:00
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
var sav = CloneInternal();
|
|
|
|
|
SetData(sav.General, General, 0);
|
|
|
|
|
SetData(sav.Storage, Storage, 0);
|
|
|
|
|
sav.Footer = (byte[])Footer.Clone();
|
|
|
|
|
return sav;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
protected abstract SAV4 CloneInternal();
|
|
|
|
|
|
|
|
|
|
public override void CopyChangesFrom(SaveFile sav)
|
|
|
|
|
{
|
|
|
|
|
SetData(sav.Data, 0);
|
|
|
|
|
var s4 = (SAV4)sav;
|
|
|
|
|
SetData(General, s4.General, 0);
|
|
|
|
|
SetData(Storage, s4.Storage, 0);
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
public override int SIZE_STORED => PKX.SIZE_4STORED;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected override int SIZE_PARTY => PKX.SIZE_4PARTY;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public override PKM BlankPKM => new PK4();
|
2016-09-26 23:14:11 +00:00
|
|
|
|
public override Type PKMType => typeof(PK4);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
public override int BoxCount => 18;
|
|
|
|
|
public override int MaxEV => 255;
|
|
|
|
|
public override int Generation => 4;
|
2019-07-21 19:30:21 +00:00
|
|
|
|
protected override int EventFlagMax => 0xB60; // 2912
|
|
|
|
|
protected override int EventConstMax => (EventFlag - EventConst) >> 1;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
protected override int GiftCountMax => 11;
|
2017-04-10 04:53:53 +00:00
|
|
|
|
public override int OTLength => 7;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public override int NickLength => 10;
|
2016-09-09 03:20:32 +00:00
|
|
|
|
public override int MaxMoney => 999999;
|
2018-03-25 00:29:48 +00:00
|
|
|
|
public override int MaxCoins => 50_000;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2017-01-27 03:18:20 +00:00
|
|
|
|
public override int MaxMoveID => Legal.MaxMoveID_4;
|
2016-10-24 04:59:27 +00:00
|
|
|
|
public override int MaxSpeciesID => Legal.MaxSpeciesID_4;
|
2017-01-27 03:18:20 +00:00
|
|
|
|
public override int MaxItemID => Version == GameVersion.HGSS ? Legal.MaxItemID_4_HGSS : Version == GameVersion.Pt ? Legal.MaxItemID_4_Pt : Legal.MaxItemID_4_DP;
|
|
|
|
|
public override int MaxAbilityID => Legal.MaxAbilityID_4;
|
|
|
|
|
public override int MaxBallID => Legal.MaxBallID_4;
|
2017-12-28 00:36:24 +00:00
|
|
|
|
public override int MaxGameID => Legal.MaxGameID_4; // Colo/XD
|
2016-06-21 01:58:06 +00:00
|
|
|
|
|
2019-07-14 22:06:45 +00:00
|
|
|
|
public bool HGSS => Version == GameVersion.HGSS;
|
|
|
|
|
public bool DP => Version == GameVersion.DP;
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
// Checksums
|
2019-09-04 01:16:10 +00:00
|
|
|
|
protected abstract int FooterSize { get; }
|
|
|
|
|
private ushort CalcBlockChecksum(byte[] data) => Checksums.CRC16_CCITT(data, 0, data.Length - FooterSize);
|
2019-09-03 02:30:58 +00:00
|
|
|
|
private static ushort GetBlockChecksumSaved(byte[] data) => BitConverter.ToUInt16(data, data.Length - 2);
|
2019-09-04 01:16:10 +00:00
|
|
|
|
private bool GetBlockChecksumValid(byte[] data) => CalcBlockChecksum(data) == GetBlockChecksumSaved(data);
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected override void SetChecksums()
|
2017-01-16 00:16:35 +00:00
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
BitConverter.GetBytes(CalcBlockChecksum(General)).CopyTo(General, General.Length - 2);
|
|
|
|
|
BitConverter.GetBytes(CalcBlockChecksum(Storage)).CopyTo(Storage, Storage.Length - 2);
|
2017-01-16 00:16:35 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
// Write blocks back
|
|
|
|
|
General.CopyTo(Data, GeneralBlockPosition * 0x40000);
|
|
|
|
|
Storage.CopyTo(Data, (StorageBlockPosition * 0x40000) + StorageStart);
|
2017-01-16 00:16:35 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public override bool ChecksumsValid
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
if (!GetBlockChecksumValid(General))
|
|
|
|
|
return false;
|
|
|
|
|
if (!GetBlockChecksumValid(Storage))
|
2017-01-16 00:16:35 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public override string ChecksumInfo
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-09-30 05:58:25 +00:00
|
|
|
|
var list = new List<string>();
|
2019-09-03 02:30:58 +00:00
|
|
|
|
if (!GetBlockChecksumValid(General))
|
2017-09-30 05:58:25 +00:00
|
|
|
|
list.Add("Small block checksum is invalid");
|
2019-09-03 02:30:58 +00:00
|
|
|
|
if (!GetBlockChecksumValid(Storage))
|
2017-09-30 05:58:25 +00:00
|
|
|
|
list.Add("Large block checksum is invalid");
|
2017-01-16 00:16:35 +00:00
|
|
|
|
|
2017-12-05 04:16:54 +00:00
|
|
|
|
return list.Count != 0 ? string.Join(Environment.NewLine, list) : "Checksums are valid.";
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-25 23:00:52 +00:00
|
|
|
|
private int GetActiveGeneralBlock()
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2016-09-13 01:01:26 +00:00
|
|
|
|
// Check to see if the save is initialized completely
|
2016-09-13 01:10:42 +00:00
|
|
|
|
// if the block is not initialized, fall back to the other save.
|
2019-09-03 02:30:58 +00:00
|
|
|
|
int start = 0;
|
2019-10-25 01:10:23 +00:00
|
|
|
|
if (Data.IsRangeAll((byte)0, start, 10) || Data.IsRangeAll((byte)0xFF, start, 10))
|
2018-07-25 23:00:52 +00:00
|
|
|
|
return 1;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
start += 0x40000; // check other save
|
2019-10-25 01:10:23 +00:00
|
|
|
|
if (Data.IsRangeAll((byte)0, start, 10) || Data.IsRangeAll((byte)0xFF, start, 10))
|
2018-07-25 23:00:52 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
int ofs = GetGeneralBlockSaveCounterOffset();
|
2018-07-25 23:00:52 +00:00
|
|
|
|
bool first = BitConverter.ToUInt16(Data, ofs) >= BitConverter.ToUInt16(Data, ofs + 0x40000);
|
|
|
|
|
return first ? 0 : 1;
|
2016-09-13 01:10:42 +00:00
|
|
|
|
}
|
2018-07-25 23:00:52 +00:00
|
|
|
|
|
|
|
|
|
private int GetActiveStorageBlock()
|
2016-09-13 01:10:42 +00:00
|
|
|
|
{
|
|
|
|
|
// Check to see if the save is initialized completely
|
|
|
|
|
// if the block is not initialized, fall back to the other save.
|
2019-09-03 02:30:58 +00:00
|
|
|
|
int start = StorageStart;
|
2019-10-25 01:10:23 +00:00
|
|
|
|
if (Data.IsRangeAll((byte)0, start, 10) || Data.IsRangeAll((byte)0xFF, start, 10))
|
2018-07-25 23:00:52 +00:00
|
|
|
|
return 1;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
start += 0x40000; // check other save
|
2019-10-25 01:10:23 +00:00
|
|
|
|
if (Data.IsRangeAll((byte)0, start, 10) || Data.IsRangeAll((byte)0xFF, start, 10))
|
2018-07-25 23:00:52 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
int ofs = GetStorageBlockSaveCounterOffset();
|
|
|
|
|
bool first = BitConverter.ToUInt16(Data, ofs) >= BitConverter.ToUInt16(Data, ofs + 0x40000);
|
|
|
|
|
return first ? 0 : 1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
private int GetGeneralBlockSaveCounterOffset() => GeneralSize - 0x10;
|
|
|
|
|
private int GetStorageBlockSaveCounterOffset() => StorageStart + StorageSize - 0x10;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
protected int WondercardFlags = int.MinValue;
|
|
|
|
|
protected int AdventureInfo = int.MinValue;
|
|
|
|
|
protected int Seal = int.MinValue;
|
2019-11-28 22:00:55 +00:00
|
|
|
|
protected int Trainer1;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
public int GTS { get; protected set; } = int.MinValue;
|
2019-10-26 19:33:58 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
// Storage
|
|
|
|
|
public override int PartyCount
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
get => General[Party - 4];
|
|
|
|
|
protected set => General[Party - 4] = (byte)value;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
public override int GetPartyOffset(int slot) => Party + (SIZE_PARTY * slot);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
// Trainer Info
|
|
|
|
|
public override string OT
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
get => GetString(General, Trainer1, 16);
|
|
|
|
|
set => SetString(value, OTLength).CopyTo(General, Trainer1);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-04-28 18:06:58 +00:00
|
|
|
|
public override int TID
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
get => BitConverter.ToUInt16(General, Trainer1 + 0x10);
|
|
|
|
|
set => BitConverter.GetBytes((ushort)value).CopyTo(General, Trainer1 + 0x10);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-04-28 18:06:58 +00:00
|
|
|
|
public override int SID
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
get => BitConverter.ToUInt16(General, Trainer1 + 0x12);
|
|
|
|
|
set => BitConverter.GetBytes((ushort)value).CopyTo(General, Trainer1 + 0x12);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-06-22 00:35:12 +00:00
|
|
|
|
public override uint Money
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
get => BitConverter.ToUInt32(General, Trainer1 + 0x14);
|
|
|
|
|
set => BitConverter.GetBytes(value).CopyTo(General, Trainer1 + 0x14);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public override int Gender
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
get => General[Trainer1 + 0x18];
|
|
|
|
|
set => General[Trainer1 + 0x18] = (byte)value;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public override int Language
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
get => General[Trainer1 + 0x19];
|
|
|
|
|
set => General[Trainer1 + 0x19] = (byte)value;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public int Badges
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
get => General[Trainer1 + 0x1A];
|
|
|
|
|
set { if (value < 0) return; General[Trainer1 + 0x1A] = (byte)value; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public int Sprite
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
get => General[Trainer1 + 0x1B];
|
|
|
|
|
set { if (value < 0) return; General[Trainer1 + 0x1B] = (byte)value; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-07-21 19:30:21 +00:00
|
|
|
|
public uint Coin
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
get => BitConverter.ToUInt16(General, Trainer1 + 0x20);
|
|
|
|
|
set => BitConverter.GetBytes((ushort)value).CopyTo(General, Trainer1 + 0x20);
|
2019-07-21 19:30:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-22 00:35:12 +00:00
|
|
|
|
public override int PlayedHours
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
get => BitConverter.ToUInt16(General, Trainer1 + 0x22);
|
|
|
|
|
set => BitConverter.GetBytes((ushort)value).CopyTo(General, Trainer1 + 0x22);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-06-22 00:35:12 +00:00
|
|
|
|
public override int PlayedMinutes
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
get => General[Trainer1 + 0x24];
|
|
|
|
|
set => General[Trainer1 + 0x24] = (byte)value;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-06-22 00:35:12 +00:00
|
|
|
|
public override int PlayedSeconds
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
get => General[Trainer1 + 0x25];
|
|
|
|
|
set => General[Trainer1 + 0x25] = (byte)value;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public int M
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
int ofs = 0;
|
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
case GameVersion.DP: ofs = 0x1238; break;
|
|
|
|
|
case GameVersion.Pt: ofs = 0x1280; break;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
case GameVersion.HGSS: ofs = 0x1234; break;
|
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
return BitConverter.ToUInt16(General, ofs);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
int ofs = 0;
|
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
case GameVersion.DP: ofs = 0x1238; break;
|
|
|
|
|
case GameVersion.Pt: ofs = 0x1280; break;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
case GameVersion.HGSS: ofs = 0x1234; break;
|
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
BitConverter.GetBytes((ushort)value).CopyTo(General, ofs);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public int X
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
int ofs = 0;
|
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
case GameVersion.DP: ofs = 0x1240; break;
|
|
|
|
|
case GameVersion.Pt: ofs = 0x1288; break;
|
|
|
|
|
case GameVersion.HGSS: ofs = 0x123C; break;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
return BitConverter.ToUInt16(General, ofs);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
int ofs = 0;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
case GameVersion.DP: ofs = 0x1240; break;
|
|
|
|
|
case GameVersion.Pt: ofs = 0x1288; break;
|
|
|
|
|
case GameVersion.HGSS: ofs = 0x123C; break;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
BitConverter.GetBytes((ushort)(X2 = value)).CopyTo(General, ofs);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
public int Y
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
int ofs = 0;
|
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
case GameVersion.DP: ofs = 0x1244; break;
|
|
|
|
|
case GameVersion.Pt: ofs = 0x128C; break;
|
|
|
|
|
case GameVersion.HGSS: ofs = 0x1240; break;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
return BitConverter.ToUInt16(General, ofs);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
int ofs = 0;
|
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
case GameVersion.DP: ofs = 0x1244; break;
|
|
|
|
|
case GameVersion.Pt: ofs = 0x128C; break;
|
|
|
|
|
case GameVersion.HGSS: ofs = 0x1240; break;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
BitConverter.GetBytes((ushort)(Y2 = value)).CopyTo(General, ofs);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
public int X2
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
int ofs = 0;
|
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
case GameVersion.DP: ofs = 0x25FA; break;
|
|
|
|
|
case GameVersion.Pt: ofs = 0x287E; break;
|
|
|
|
|
case GameVersion.HGSS: ofs = 0x236E; break;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
return BitConverter.ToUInt16(General, ofs);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
int ofs = 0;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
case GameVersion.DP: ofs = 0x25FA; break;
|
|
|
|
|
case GameVersion.Pt: ofs = 0x287E; break;
|
|
|
|
|
case GameVersion.HGSS: ofs = 0x236E; break;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
BitConverter.GetBytes((ushort)value).CopyTo(General, ofs);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
public int Y2
|
2017-05-24 04:38:15 +00:00
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
int ofs = 0;
|
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
|
|
|
|
case GameVersion.DP: ofs = 0x25FE; break;
|
|
|
|
|
case GameVersion.Pt: ofs = 0x2882; break;
|
|
|
|
|
case GameVersion.HGSS: ofs = 0x2372; break;
|
|
|
|
|
}
|
|
|
|
|
return BitConverter.ToUInt16(General, ofs);
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
int ofs = 0;
|
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
|
|
|
|
case GameVersion.DP: ofs = 0x25FE; break;
|
|
|
|
|
case GameVersion.Pt: ofs = 0x2882; break;
|
|
|
|
|
case GameVersion.HGSS: ofs = 0x2372; break;
|
|
|
|
|
}
|
|
|
|
|
BitConverter.GetBytes((ushort)value).CopyTo(General, ofs);
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
public int Z
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
int ofs = 0;
|
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
|
|
|
|
case GameVersion.DP: ofs = 0x2602; break;
|
|
|
|
|
case GameVersion.Pt: ofs = 0x2886; break;
|
|
|
|
|
case GameVersion.HGSS: ofs = 0x2376; break;
|
|
|
|
|
}
|
|
|
|
|
return BitConverter.ToUInt16(General, ofs);
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
int ofs = 0;
|
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
|
|
|
|
case GameVersion.DP: ofs = 0x2602; break;
|
|
|
|
|
case GameVersion.Pt: ofs = 0x2886; break;
|
|
|
|
|
case GameVersion.HGSS: ofs = 0x2376; break;
|
|
|
|
|
}
|
|
|
|
|
BitConverter.GetBytes((ushort)value).CopyTo(General, ofs);
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
public override uint SecondsToStart { get => BitConverter.ToUInt32(General, AdventureInfo + 0x34); set => BitConverter.GetBytes(value).CopyTo(General, AdventureInfo + 0x34); }
|
|
|
|
|
public override uint SecondsToFame { get => BitConverter.ToUInt32(General, AdventureInfo + 0x3C); set => BitConverter.GetBytes(value).CopyTo(General, AdventureInfo + 0x3C); }
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
protected override PKM GetPKM(byte[] data) => new PK4(data);
|
|
|
|
|
protected override byte[] DecryptPKM(byte[] data) => PKX.DecryptArray45(data);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2018-03-22 04:10:23 +00:00
|
|
|
|
protected override void SetPKM(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
var pk4 = (PK4)pkm;
|
|
|
|
|
// Apply to this Save File
|
|
|
|
|
DateTime Date = DateTime.Now;
|
|
|
|
|
if (pk4.Trade(OT, TID, SID, Gender, Date.Day, Date.Month, Date.Year))
|
|
|
|
|
pkm.RefreshChecksum();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
// Daycare
|
2019-10-19 03:42:03 +00:00
|
|
|
|
public override int GetDaycareSlotOffset(int loc, int slot) => DaycareOffset + (slot * SIZE_PARTY);
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override uint? GetDaycareEXP(int loc, int slot)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-10-19 03:42:03 +00:00
|
|
|
|
int ofs = DaycareOffset + ((slot+1)*SIZE_PARTY) - 4;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
return BitConverter.ToUInt32(General, ofs);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-12-11 04:32:08 +00:00
|
|
|
|
public override bool? IsDaycareOccupied(int loc, int slot) => null; // todo
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override void SetDaycareEXP(int loc, int slot, uint EXP)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-10-19 03:42:03 +00:00
|
|
|
|
int ofs = DaycareOffset + ((slot+1)*SIZE_PARTY) - 4;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
BitConverter.GetBytes(EXP).CopyTo(General, ofs);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-02-02 18:19:41 +00:00
|
|
|
|
public override void SetDaycareOccupied(int loc, int slot, bool occupied)
|
|
|
|
|
{
|
|
|
|
|
// todo
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
// Mystery Gift
|
2019-09-03 02:30:58 +00:00
|
|
|
|
private bool MysteryGiftActive { get => (General[72] & 1) == 1; set => General[72] = (byte)((General[72] & 0xFE) | (value ? 1 : 0)); }
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
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
|
|
|
|
private static bool IsMysteryGiftAvailable(DataMysteryGift[] value)
|
2017-01-16 00:52:10 +00:00
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 8; i++) // 8 PGT
|
2018-09-15 05:37:47 +00:00
|
|
|
|
{
|
2017-12-11 18:13:08 +00:00
|
|
|
|
if (value[i] is PGT g && g.CardType != 0)
|
2017-01-16 00:52:10 +00:00
|
|
|
|
return true;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
}
|
2017-01-16 00:52:10 +00:00
|
|
|
|
for (int i = 8; i < 11; i++) // 3 PCD
|
2018-09-15 05:37:47 +00:00
|
|
|
|
{
|
2017-12-11 18:13:08 +00:00
|
|
|
|
if (value[i] is PCD d && d.Gift.CardType != 0)
|
2017-01-16 00:52:10 +00:00
|
|
|
|
return true;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
}
|
2017-01-16 00:52:10 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-01-20 07:49:46 +00:00
|
|
|
|
|
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
|
|
|
|
private int[] MatchMysteryGifts(DataMysteryGift[] value)
|
2017-01-20 07:49:46 +00:00
|
|
|
|
{
|
|
|
|
|
int[] cardMatch = new int[8];
|
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
|
{
|
2017-12-11 18:13:08 +00:00
|
|
|
|
if (!(value[i] is PGT pgt))
|
2017-01-20 07:49:46 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
2017-01-21 03:35:56 +00:00
|
|
|
|
if (pgt.CardType == 0) // empty
|
|
|
|
|
{
|
|
|
|
|
cardMatch[i] = pgt.Slot = 0;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-20 16:43:41 +00:00
|
|
|
|
cardMatch[i] = pgt.Slot = 3;
|
2017-01-20 07:49:46 +00:00
|
|
|
|
for (byte j = 0; j < 3; j++)
|
|
|
|
|
{
|
2017-12-11 18:13:08 +00:00
|
|
|
|
if (!(value[8 + j] is PCD pcd))
|
2017-01-20 07:49:46 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Check if data matches (except Slot @ 0x02)
|
2017-01-21 03:35:56 +00:00
|
|
|
|
if (!pcd.GiftEquals(pgt))
|
2017-01-20 07:49:46 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
if (this is SAV4HGSS)
|
2018-12-01 18:44:38 +00:00
|
|
|
|
j++; // hgss 0,1,2; dppt 1,2,3
|
2017-01-20 07:49:46 +00:00
|
|
|
|
cardMatch[i] = pgt.Slot = j;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return cardMatch;
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public override MysteryGiftAlbum GiftAlbum
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
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
|
|
|
|
var album = new MysteryGiftAlbum(MysteryGiftCards, MysteryGiftReceivedFlags);
|
2017-01-16 00:52:10 +00:00
|
|
|
|
album.Flags[2047] = false;
|
|
|
|
|
return album;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
bool available = IsMysteryGiftAvailable(value.Gifts);
|
2019-09-03 02:30:58 +00:00
|
|
|
|
if (available && !MysteryGiftActive)
|
|
|
|
|
MysteryGiftActive = true;
|
2017-01-16 00:52:10 +00:00
|
|
|
|
value.Flags[2047] = available;
|
|
|
|
|
|
2017-12-11 18:13:08 +00:00
|
|
|
|
// Check encryption for each gift (decrypted wc4 sneaking in)
|
|
|
|
|
foreach (var g in value.Gifts)
|
|
|
|
|
{
|
|
|
|
|
if (g is PGT pgt)
|
2018-09-15 05:37:47 +00:00
|
|
|
|
{
|
2017-12-11 18:13:08 +00:00
|
|
|
|
pgt.VerifyPKEncryption();
|
2018-09-15 05:37:47 +00:00
|
|
|
|
}
|
2017-12-11 18:13:08 +00:00
|
|
|
|
else if (g is PCD pcd)
|
|
|
|
|
{
|
2017-12-11 19:01:57 +00:00
|
|
|
|
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
|
|
|
|
MysteryGiftReceivedFlags = value.Flags;
|
|
|
|
|
MysteryGiftCards = value.Gifts;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
protected override bool[] MysteryGiftReceivedFlags
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2019-02-07 07:28:02 +00:00
|
|
|
|
bool[] result = new bool[GiftFlagMax];
|
|
|
|
|
for (int i = 0; i < result.Length; i++)
|
2019-09-03 02:30:58 +00:00
|
|
|
|
result[i] = (General[WondercardFlags + (i >> 3)] >> (i & 7) & 0x1) == 1;
|
2019-02-07 07:28:02 +00:00
|
|
|
|
return result;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (GiftFlagMax != value?.Length)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
byte[] data = new byte[value.Length / 8];
|
|
|
|
|
for (int i = 0; i < value.Length; i++)
|
2018-09-15 05:37:47 +00:00
|
|
|
|
{
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (value[i])
|
|
|
|
|
data[i >> 3] |= (byte)(1 << (i & 7));
|
2018-09-15 05:37:47 +00:00
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
SetData(General, data, WondercardFlags);
|
2017-01-21 20:09:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
protected override DataMysteryGift[] MysteryGiftCards
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
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
|
|
|
|
DataMysteryGift[] cards = new DataMysteryGift[8 + 3];
|
2016-06-20 04:22:43 +00:00
|
|
|
|
for (int i = 0; i < 8; i++) // 8 PGT
|
2019-09-03 02:30:58 +00:00
|
|
|
|
cards[i] = new PGT(General.Slice(WondercardData + (i * PGT.Size), PGT.Size));
|
2016-06-20 04:22:43 +00:00
|
|
|
|
for (int i = 8; i < 11; i++) // 3 PCD
|
2019-09-03 02:30:58 +00:00
|
|
|
|
cards[i] = new PCD(General.Slice(WondercardData + (8 * PGT.Size) + ((i-8) * PCD.Size), PCD.Size));
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return cards;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var Matches = MatchMysteryGifts(value); // automatically applied
|
2019-02-02 07:26:43 +00:00
|
|
|
|
if (Matches.Length == 0)
|
2017-01-20 07:49:46 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
for (int i = 0; i < 8; i++) // 8 PGT
|
2018-09-15 05:37:47 +00:00
|
|
|
|
{
|
2017-01-16 00:52:10 +00:00
|
|
|
|
if (value[i] is PGT)
|
2019-09-03 02:30:58 +00:00
|
|
|
|
SetData(General, value[i].Data, WondercardData + (i *PGT.Size));
|
2018-09-15 05:37:47 +00:00
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
for (int i = 8; i < 11; i++) // 3 PCD
|
2018-09-15 05:37:47 +00:00
|
|
|
|
{
|
2017-01-16 00:52:10 +00:00
|
|
|
|
if (value[i] is PCD)
|
2019-09-03 02:30:58 +00:00
|
|
|
|
SetData(General, value[i].Data, WondercardData + (8 *PGT.Size) + ((i - 8)*PCD.Size));
|
2018-09-15 05:37:47 +00:00
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-04 20:06:01 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected override void SetDex(PKM pkm)
|
2016-07-04 20:06:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (pkm.Species == 0)
|
|
|
|
|
return;
|
|
|
|
|
if (pkm.Species > MaxSpeciesID)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const int brSize = 0x40;
|
|
|
|
|
int bit = pkm.Species - 1;
|
2017-03-22 05:50:55 +00:00
|
|
|
|
byte mask = (byte)(1 << (bit & 7));
|
2017-03-07 06:43:46 +00:00
|
|
|
|
int ofs = PokeDex + (bit >> 3) + 0x4;
|
|
|
|
|
|
|
|
|
|
/* 4 BitRegions with 0x40*8 bits
|
|
|
|
|
* Region 0: Caught (Captured/Owned) flags
|
|
|
|
|
* Region 1: Seen flags
|
|
|
|
|
* Region 2/3: Toggle for gender display
|
|
|
|
|
* 4 possible states: 00, 01, 10, 11
|
|
|
|
|
* 00 - 1Seen: Male Only
|
|
|
|
|
* 01 - 2Seen: Male First, Female Second
|
|
|
|
|
* 10 - 2Seen: Female First, Male Second
|
|
|
|
|
* 11 - 1Seen: Female Only
|
|
|
|
|
* (bit1 ^ bit2) + 1 = forms in dex
|
|
|
|
|
* bit2 = male/female shown first toggle
|
|
|
|
|
*/
|
2016-07-04 20:06:01 +00:00
|
|
|
|
|
|
|
|
|
// Set the Species Owned Flag
|
2019-09-03 02:30:58 +00:00
|
|
|
|
General[ofs + (brSize * 0)] |= mask;
|
2016-07-04 20:06:01 +00:00
|
|
|
|
|
2017-02-24 05:25:56 +00:00
|
|
|
|
// Check if already Seen
|
2019-09-03 02:30:58 +00:00
|
|
|
|
if ((General[ofs + (brSize * 1)] & mask) == 0) // Not seen
|
2017-02-24 05:25:56 +00:00
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
General[ofs + (brSize * 1)] |= mask; // Set seen
|
2017-03-07 06:43:46 +00:00
|
|
|
|
int gr = pkm.PersonalInfo.Gender;
|
|
|
|
|
switch (gr)
|
2017-02-24 05:25:56 +00:00
|
|
|
|
{
|
2017-03-07 06:43:46 +00:00
|
|
|
|
case 255: // Genderless
|
|
|
|
|
case 0: // Male Only
|
2019-09-03 02:30:58 +00:00
|
|
|
|
General[ofs + (brSize * 2)] &= (byte)~mask; // unset
|
|
|
|
|
General[ofs + (brSize * 3)] &= (byte)~mask; // unset
|
2017-03-07 06:43:46 +00:00
|
|
|
|
break;
|
|
|
|
|
case 254: // Female Only
|
2019-09-03 02:30:58 +00:00
|
|
|
|
General[ofs + (brSize * 2)] |= mask;
|
|
|
|
|
General[ofs + (brSize * 3)] |= mask;
|
2017-03-07 06:43:46 +00:00
|
|
|
|
break;
|
|
|
|
|
default: // Male or Female
|
2019-09-03 02:30:58 +00:00
|
|
|
|
bool m = (General[ofs + (brSize * 2)] & mask) != 0;
|
|
|
|
|
bool f = (General[ofs + (brSize * 3)] & mask) != 0;
|
2017-07-09 02:33:20 +00:00
|
|
|
|
if (m || f) // bit already set?
|
|
|
|
|
break;
|
|
|
|
|
int gender = pkm.Gender & 1;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
General[ofs + (brSize * 2)] &= (byte)~mask; // unset
|
|
|
|
|
General[ofs + (brSize * 3)] &= (byte)~mask; // unset
|
2017-07-09 02:33:20 +00:00
|
|
|
|
gender ^= 1; // Set OTHER gender seen bit so it appears second
|
2019-09-03 02:30:58 +00:00
|
|
|
|
General[ofs + (brSize * (2 + gender))] |= mask;
|
2017-03-07 06:43:46 +00:00
|
|
|
|
break;
|
2017-02-24 05:25:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-04 20:06:01 +00:00
|
|
|
|
|
2018-09-15 05:37:47 +00:00
|
|
|
|
int FormOffset1 = PokeDex + 4 + (brSize * 4) + 4;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var forms = GetForms(pkm.Species);
|
2019-02-02 07:26:43 +00:00
|
|
|
|
if (forms.Length > 0)
|
2016-08-28 06:30:49 +00:00
|
|
|
|
{
|
2017-03-07 06:43:46 +00:00
|
|
|
|
if (pkm.Species == 201) // Unown
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 0x1C; i++)
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
byte val = General[FormOffset1 + 4 + i];
|
2017-03-07 06:43:46 +00:00
|
|
|
|
if (val == pkm.AltForm)
|
|
|
|
|
break; // already set
|
|
|
|
|
if (val != 0xFF)
|
|
|
|
|
continue; // keep searching
|
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
General[FormOffset1 + 4 + i] = (byte)pkm.AltForm;
|
2017-03-07 06:43:46 +00:00
|
|
|
|
break; // form now set
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-11 01:43:00 +00:00
|
|
|
|
else if (pkm.Species == 172 && HGSS) // Pichu (HGSS Only)
|
|
|
|
|
{
|
|
|
|
|
int form = pkm.AltForm == 1 ? 2 : pkm.Gender;
|
|
|
|
|
CheckInsertForm(ref forms, form);
|
|
|
|
|
SetForms(pkm.Species, forms);
|
|
|
|
|
}
|
2017-03-07 06:43:46 +00:00
|
|
|
|
else
|
2016-08-28 06:30:49 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
CheckInsertForm(ref forms, pkm.AltForm);
|
|
|
|
|
SetForms(pkm.Species, forms);
|
2016-08-28 06:30:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-22 05:50:55 +00:00
|
|
|
|
int dpl = 1 + Array.IndexOf(DPLangSpecies, pkm.Species);
|
|
|
|
|
if (DP && dpl <= 0)
|
2016-08-28 06:30:49 +00:00
|
|
|
|
return;
|
2016-08-27 20:07:21 +00:00
|
|
|
|
|
2016-08-28 06:30:49 +00:00
|
|
|
|
// Set the Language
|
2017-03-07 06:43:46 +00:00
|
|
|
|
int PokeDexLanguageFlags = FormOffset1 + (HGSS ? 0x3C : 0x20);
|
2017-08-20 01:43:36 +00:00
|
|
|
|
int lang = GetGen4LanguageBitIndex(pkm.Language);
|
2019-09-03 02:30:58 +00:00
|
|
|
|
General[PokeDexLanguageFlags + (DP ? dpl : pkm.Species)] |= (byte)(1 << lang);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
private static readonly int[] DPLangSpecies = { 23, 25, 54, 77, 120, 129, 202, 214, 215, 216, 228, 278, 287, 315 };
|
|
|
|
|
|
2017-08-20 01:43:36 +00:00
|
|
|
|
private static int GetGen4LanguageBitIndex(int lang)
|
|
|
|
|
{
|
2018-05-12 19:28:48 +00:00
|
|
|
|
lang--;
|
2017-08-20 01:43:36 +00:00
|
|
|
|
switch (lang) // invert ITA/GER
|
|
|
|
|
{
|
|
|
|
|
case 3: return 4;
|
|
|
|
|
case 4: return 3;
|
|
|
|
|
}
|
|
|
|
|
if (lang > 5)
|
|
|
|
|
return 0; // no KOR+
|
|
|
|
|
return lang < 0 ? 1 : lang; // default English
|
|
|
|
|
}
|
2017-03-07 06:43:46 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override bool GetCaught(int species)
|
2017-03-15 05:41:15 +00:00
|
|
|
|
{
|
|
|
|
|
int bit = species - 1;
|
|
|
|
|
int bd = bit >> 3; // div8
|
|
|
|
|
int bm = bit & 7; // mod8
|
|
|
|
|
int ofs = PokeDex // Raw Offset
|
|
|
|
|
+ 0x4; // Magic
|
2019-09-03 02:30:58 +00:00
|
|
|
|
return (1 << bm & General[ofs + bd]) != 0;
|
2017-03-15 05:41:15 +00:00
|
|
|
|
}
|
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 = 0x40;
|
|
|
|
|
|
|
|
|
|
int bit = species - 1;
|
|
|
|
|
int bd = bit >> 3; // div8
|
|
|
|
|
int bm = bit & 7; // mod8
|
|
|
|
|
int ofs = PokeDex // Raw Offset
|
|
|
|
|
+ 0x4; // Magic
|
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
return (1 << bm & General[ofs + bd + (brSize * 1)]) != 0;
|
2017-03-15 05:41:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public int[] GetForms(int species)
|
2017-03-07 06:43:46 +00:00
|
|
|
|
{
|
|
|
|
|
const int brSize = 0x40;
|
|
|
|
|
if (species == 386)
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
uint val = (uint) (General[PokeDex + 0x4 + (1 * brSize) - 1] | General[PokeDex + 0x4 + (2 * brSize) - 1] << 8);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetDexFormValues(val, 4, 4);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-15 05:37:47 +00:00
|
|
|
|
int FormOffset1 = PokeDex + 4 + (4 * brSize) + 4;
|
2017-03-07 06:43:46 +00:00
|
|
|
|
switch (species)
|
|
|
|
|
{
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case (int)Species.Shellos: // Shellos
|
2019-09-03 02:30:58 +00:00
|
|
|
|
return GetDexFormValues(General[FormOffset1 + 0], 1, 2);
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case (int)Species.Gastrodon: // Gastrodon
|
2019-09-03 02:30:58 +00:00
|
|
|
|
return GetDexFormValues(General[FormOffset1 + 1], 1, 2);
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case (int)Species.Burmy: // Burmy
|
2019-09-03 02:30:58 +00:00
|
|
|
|
return GetDexFormValues(General[FormOffset1 + 2], 2, 3);
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case (int)Species.Wormadam: // Wormadam
|
2019-09-03 02:30:58 +00:00
|
|
|
|
return GetDexFormValues(General[FormOffset1 + 3], 2, 3);
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case (int)Species.Unown: // Unown
|
2019-09-03 02:30:58 +00:00
|
|
|
|
return General.Slice(FormOffset1 + 4, 0x1C).Select(i => (int)i).ToArray();
|
2017-03-07 06:43:46 +00:00
|
|
|
|
}
|
2017-03-22 05:50:55 +00:00
|
|
|
|
if (DP)
|
2019-02-02 07:26:43 +00:00
|
|
|
|
return Array.Empty<int>();
|
2016-08-28 06:30:49 +00:00
|
|
|
|
|
2017-03-07 06:43:46 +00:00
|
|
|
|
int PokeDexLanguageFlags = FormOffset1 + (HGSS ? 0x3C : 0x20);
|
|
|
|
|
int FormOffset2 = PokeDexLanguageFlags + 0x1F4;
|
2019-10-08 01:40:09 +00:00
|
|
|
|
return species switch
|
|
|
|
|
{
|
|
|
|
|
(int)Species.Rotom => GetDexFormValues(BitConverter.ToUInt32(General, FormOffset2), 3, 6),
|
|
|
|
|
(int)Species.Shaymin => GetDexFormValues(General[FormOffset2 + 4], 1, 2),
|
|
|
|
|
(int)Species.Giratina => GetDexFormValues(General[FormOffset2 + 5], 1, 2),
|
|
|
|
|
(int)Species.Pichu when HGSS => GetDexFormValues(General[FormOffset2 + 6], 2, 3),
|
|
|
|
|
_ => Array.Empty<int>()
|
|
|
|
|
};
|
2017-03-07 06:43:46 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public void SetForms(int spec, int[] forms)
|
2017-03-07 06:43:46 +00:00
|
|
|
|
{
|
|
|
|
|
const int brSize = 0x40;
|
|
|
|
|
switch (spec)
|
2016-08-28 06:30:49 +00:00
|
|
|
|
{
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case (int)Species.Deoxys: // Deoxys
|
2017-06-18 01:37:19 +00:00
|
|
|
|
uint newval = SetDexFormValues(forms, 4, 4);
|
2019-09-03 02:30:58 +00:00
|
|
|
|
General[PokeDex + 0x4 + (1 * brSize) - 1] = (byte) (newval & 0xFF);
|
|
|
|
|
General[PokeDex + 0x4 + (2 * brSize) - 1] = (byte) ((newval >> 8) & 0xFF);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
break;
|
2016-08-28 06:30:49 +00:00
|
|
|
|
}
|
2017-03-07 06:43:46 +00:00
|
|
|
|
|
2018-09-15 05:37:47 +00:00
|
|
|
|
int FormOffset1 = PokeDex + 4 + (4 * brSize) + 4;
|
2017-03-07 06:43:46 +00:00
|
|
|
|
switch (spec)
|
2016-08-28 06:30:49 +00:00
|
|
|
|
{
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case (int)Species.Shellos: // Shellos
|
2019-09-03 02:30:58 +00:00
|
|
|
|
General[FormOffset1 + 0] = (byte)SetDexFormValues(forms, 1, 2);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
return;
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case (int)Species.Gastrodon: // Gastrodon
|
2019-09-03 02:30:58 +00:00
|
|
|
|
General[FormOffset1 + 1] = (byte)SetDexFormValues(forms, 1, 2);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
return;
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case (int)Species.Burmy: // Burmy
|
2019-09-03 02:30:58 +00:00
|
|
|
|
General[FormOffset1 + 2] = (byte)SetDexFormValues(forms, 2, 3);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
return;
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case (int)Species.Wormadam: // Wormadam
|
2019-09-03 02:30:58 +00:00
|
|
|
|
General[FormOffset1 + 3] = (byte)SetDexFormValues(forms, 2, 3);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
return;
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case (int)Species.Unown: // Unown
|
2017-03-07 06:43:46 +00:00
|
|
|
|
int ofs = FormOffset1 + 4;
|
|
|
|
|
int len = forms.Length;
|
|
|
|
|
Array.Resize(ref forms, 0x1C);
|
|
|
|
|
for (int i = len; i < forms.Length; i++)
|
|
|
|
|
forms[i] = 0xFF;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
Array.Copy(forms.Select(b => (byte)b).ToArray(), 0, General, ofs, forms.Length);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
return;
|
2016-08-28 06:30:49 +00:00
|
|
|
|
}
|
2017-03-07 06:43:46 +00:00
|
|
|
|
|
|
|
|
|
if (DP)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int PokeDexLanguageFlags = FormOffset1 + (HGSS ? 0x3C : 0x20);
|
|
|
|
|
int FormOffset2 = PokeDexLanguageFlags + 0x1F4;
|
|
|
|
|
switch (spec)
|
2016-08-28 06:30:49 +00:00
|
|
|
|
{
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case (int)Species.Rotom: // Rotom
|
2019-09-03 02:30:58 +00:00
|
|
|
|
BitConverter.GetBytes(SetDexFormValues(forms, 3, 6)).CopyTo(General, FormOffset2);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
return;
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case (int)Species.Shaymin: // Shaymin
|
2019-09-03 02:30:58 +00:00
|
|
|
|
General[FormOffset2 + 4] = (byte)SetDexFormValues(forms, 1, 2);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
return;
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case (int)Species.Giratina: // Giratina
|
2019-09-03 02:30:58 +00:00
|
|
|
|
General[FormOffset2 + 5] = (byte)SetDexFormValues(forms, 1, 2);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
return;
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case (int)Species.Pichu when HGSS: // Pichu
|
2019-09-03 02:30:58 +00:00
|
|
|
|
General[FormOffset2 + 6] = (byte)SetDexFormValues(forms, 2, 3);
|
2017-03-07 06:43:46 +00:00
|
|
|
|
return;
|
2016-08-28 06:30:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-07 06:43:46 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static int[] GetDexFormValues(uint Value, int BitsPerForm, int readCt)
|
2016-08-28 06:30:49 +00:00
|
|
|
|
{
|
|
|
|
|
int[] Forms = new int[readCt];
|
|
|
|
|
int n1 = 0xFF >> (8 - BitsPerForm);
|
|
|
|
|
for (int i = 0; i < Forms.Length; i++)
|
|
|
|
|
{
|
2017-03-22 05:50:55 +00:00
|
|
|
|
int val = (int)(Value >> (i * BitsPerForm)) & n1;
|
|
|
|
|
if (n1 == val && BitsPerForm > 1)
|
2016-08-28 06:30:49 +00:00
|
|
|
|
Forms[i] = -1;
|
|
|
|
|
else
|
|
|
|
|
Forms[i] = val;
|
|
|
|
|
}
|
2018-03-17 00:54:47 +00:00
|
|
|
|
|
|
|
|
|
// (BitsPerForm > 1) was already handled, handle (BitsPerForm == 1)
|
|
|
|
|
if (BitsPerForm == 1 && Forms[0] == Forms[1] && Forms[0] == 1)
|
|
|
|
|
Forms[0] = Forms[1] = -1;
|
|
|
|
|
|
2016-08-28 06:30:49 +00:00
|
|
|
|
return Forms;
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static uint SetDexFormValues(int[] Forms, int BitsPerForm, int readCt)
|
2016-08-28 06:30:49 +00:00
|
|
|
|
{
|
|
|
|
|
int n1 = 0xFF >> (8 - BitsPerForm);
|
2019-01-05 20:37:41 +00:00
|
|
|
|
uint Value = 0xFFFFFFFF << (readCt * BitsPerForm);
|
2016-08-28 06:30:49 +00:00
|
|
|
|
for (int i = 0; i < Forms.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
int val = Forms[i];
|
|
|
|
|
if (val == -1)
|
|
|
|
|
val = n1;
|
|
|
|
|
|
|
|
|
|
Value |= (uint)(val << (BitsPerForm*i));
|
2018-09-15 05:37:47 +00:00
|
|
|
|
if (i >= readCt)
|
|
|
|
|
throw new ArgumentException("Array count should be less than bitfield count", nameof(Forms));
|
2016-08-28 06:30:49 +00:00
|
|
|
|
}
|
|
|
|
|
return Value;
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static bool CheckInsertForm(ref int[] Forms, int FormNum)
|
2016-08-28 06:30:49 +00:00
|
|
|
|
{
|
|
|
|
|
if (Forms.Any(num => num == FormNum))
|
|
|
|
|
{
|
|
|
|
|
return false; // already in list
|
|
|
|
|
}
|
|
|
|
|
if (Forms.All(num => num == -1))
|
|
|
|
|
{
|
|
|
|
|
Forms[0] = FormNum;
|
|
|
|
|
return true; // none in list, insert at top
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// insert at first empty
|
|
|
|
|
int n1 = Array.IndexOf(Forms, -1);
|
|
|
|
|
if (n1 < 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
Forms[n1] = FormNum;
|
|
|
|
|
return true;
|
2016-07-04 20:06:01 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-03-22 05:50:55 +00:00
|
|
|
|
public int DexUpgraded
|
2017-03-21 03:14:37 +00:00
|
|
|
|
{
|
2017-03-22 05:50:55 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
|
|
|
|
case GameVersion.DP:
|
2019-09-03 02:30:58 +00:00
|
|
|
|
if (General[0x1413] != 0) return 4;
|
|
|
|
|
else if (General[0x1415] != 0) return 3;
|
|
|
|
|
else if (General[0x1404] != 0) return 2;
|
|
|
|
|
else if (General[0x1414] != 0) return 1;
|
2017-03-22 05:50:55 +00:00
|
|
|
|
else return 0;
|
|
|
|
|
case GameVersion.HGSS:
|
2019-09-03 02:30:58 +00:00
|
|
|
|
if (General[0x15ED] != 0) return 3;
|
|
|
|
|
else if (General[0x15EF] != 0) return 2;
|
|
|
|
|
else if (General[0x15EE] != 0 && (General[0x10D1] & 8) != 0) return 1;
|
2017-06-10 13:12:51 +00:00
|
|
|
|
else return 0;
|
|
|
|
|
case GameVersion.Pt:
|
2019-09-03 02:30:58 +00:00
|
|
|
|
if (General[0x1641] != 0) return 4;
|
|
|
|
|
else if (General[0x1643] != 0) return 3;
|
|
|
|
|
else if (General[0x1640] != 0) return 2;
|
|
|
|
|
else if (General[0x1642] != 0) return 1;
|
2017-03-22 05:50:55 +00:00
|
|
|
|
else return 0;
|
|
|
|
|
default: return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
|
|
|
|
case GameVersion.DP:
|
2019-09-03 02:30:58 +00:00
|
|
|
|
General[0x1413] = (byte)(value == 4 ? 1 : 0);
|
|
|
|
|
General[0x1415] = (byte)(value >= 3 ? 1 : 0);
|
|
|
|
|
General[0x1404] = (byte)(value >= 2 ? 1 : 0);
|
|
|
|
|
General[0x1414] = (byte)(value >= 1 ? 1 : 0);
|
2017-03-22 05:50:55 +00:00
|
|
|
|
break;
|
|
|
|
|
case GameVersion.HGSS:
|
2019-09-03 02:30:58 +00:00
|
|
|
|
General[0x15ED] = (byte)(value == 3 ? 1 : 0);
|
|
|
|
|
General[0x15EF] = (byte)(value >= 2 ? 1 : 0);
|
|
|
|
|
General[0x15EE] = (byte)(value >= 1 ? 1 : 0);
|
|
|
|
|
General[0x10D1] = (byte)((General[0x10D1] & ~8) | (value >= 1 ? 8 : 0));
|
2017-06-10 13:12:51 +00:00
|
|
|
|
break;
|
|
|
|
|
case GameVersion.Pt:
|
2019-09-03 02:30:58 +00:00
|
|
|
|
General[0x1641] = (byte)(value == 4 ? 1 : 0);
|
|
|
|
|
General[0x1643] = (byte)(value >= 3 ? 1 : 0);
|
|
|
|
|
General[0x1640] = (byte)(value >= 2 ? 1 : 0);
|
|
|
|
|
General[0x1642] = (byte)(value >= 1 ? 1 : 0);
|
2017-03-22 05:50:55 +00:00
|
|
|
|
break;
|
|
|
|
|
default: return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-21 03:14:37 +00:00
|
|
|
|
}
|
2017-04-07 04:47:28 +00:00
|
|
|
|
|
2019-03-21 04:50:44 +00:00
|
|
|
|
public override string GetString(byte[] data, int offset, int length) => StringConverter4.GetString4(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;
|
2019-03-21 04:50:44 +00:00
|
|
|
|
return StringConverter4.SetString4(value, maxLength, PadToSize, PadWith);
|
2017-04-09 21:06:50 +00:00
|
|
|
|
}
|
2018-09-04 22:12:35 +00:00
|
|
|
|
|
|
|
|
|
// Seals
|
2018-09-04 22:26:16 +00:00
|
|
|
|
private const byte SealMaxCount = 99;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
public byte[] SealCase { get => General.Slice(Seal, (int) Seal4.MAX); set => SetData(General, value, Seal); }
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
public void SetAllSeals(byte count, bool unreleased = false)
|
|
|
|
|
{
|
|
|
|
|
var sealIndexCount = (int)(unreleased ? Seal4.MAX : Seal4.MAXLEGAL);
|
|
|
|
|
var val = Math.Min(count, SealMaxCount);
|
|
|
|
|
for (int i = 0; i < sealIndexCount; i++)
|
2019-09-03 02:30:58 +00:00
|
|
|
|
General[Seal + i] = val;
|
2019-04-30 00:21:19 +00:00
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
|
public int GetMailOffset(int index)
|
|
|
|
|
{
|
|
|
|
|
int ofs = (index * Mail4.SIZE);
|
|
|
|
|
return Version switch
|
|
|
|
|
{
|
|
|
|
|
GameVersion.DP => (ofs + 0x4BEC),
|
|
|
|
|
GameVersion.Pt => (ofs + 0x4E80),
|
|
|
|
|
_ => (ofs + 0x3FA8)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public byte[] GetMailData(int ofs) => General.Slice(ofs, Mail4.SIZE);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|