2018-11-14 03:14:23 +00:00
|
|
|
using System;
|
2019-07-06 01:04:36 +00:00
|
|
|
using System.Diagnostics;
|
2022-01-03 05:35:59 +00:00
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
2018-11-14 03:14:23 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
2022-08-27 06:43:36 +00:00
|
|
|
/// Pokédex structure used for Generation 6 games.
|
2022-06-18 18:04:24 +00:00
|
|
|
/// </summary>
|
2023-01-22 04:02:33 +00:00
|
|
|
public abstract class Zukan6 : Zukan<SAV6>
|
2018-11-01 22:38:09 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override int OFS_SEEN => OFS_CAUGHT + BitSeenSize;
|
|
|
|
protected override int OFS_CAUGHT => 0x8;
|
|
|
|
protected override int BitSeenSize => 0x60;
|
|
|
|
protected override int DexLangFlagByteCount => 631; // 721 * 7, rounded up
|
|
|
|
protected override int DexLangIDCount => 7;
|
|
|
|
protected int SpindaOffset { get; init; }
|
|
|
|
|
|
|
|
protected Zukan6(SAV6XY sav, int dex, int langflag) : base(sav, dex, langflag)
|
|
|
|
{
|
|
|
|
DexFormIndexFetcher = DexFormUtil.GetDexFormIndexXY;
|
|
|
|
}
|
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-01-22 04:02:33 +00:00
|
|
|
private Func<ushort, byte, int> DexFormIndexFetcher { 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
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected Zukan6(SAV6AO sav, int dex, int langflag) : base(sav, dex, langflag)
|
|
|
|
{
|
|
|
|
DexFormIndexFetcher = DexFormUtil.GetDexFormIndexORAS;
|
|
|
|
}
|
2018-11-14 03:14:23 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override int GetDexLangFlag(int lang)
|
|
|
|
{
|
|
|
|
lang--;
|
|
|
|
if (lang > 5)
|
|
|
|
lang--; // 0-6 language values
|
|
|
|
if ((uint)lang > 5)
|
|
|
|
return -1;
|
|
|
|
return lang;
|
|
|
|
}
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
protected override bool GetSaneFormsToIterate(ushort species, out int formStart, out int formEnd, int formIn)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
formStart = 0;
|
|
|
|
formEnd = 0;
|
|
|
|
return false;
|
|
|
|
}
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override void SetSpindaDexData(PKM pk, bool alreadySeen)
|
|
|
|
{
|
|
|
|
}
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override void SetAllDexFlagsLanguage(int bit, int lang, bool value = true)
|
|
|
|
{
|
|
|
|
lang = GetDexLangFlag(lang);
|
|
|
|
if (lang < 0)
|
|
|
|
return;
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
int lbit = (bit * DexLangIDCount) + lang;
|
|
|
|
if (lbit < DexLangFlagByteCount << 3) // Sanity check for max length of region
|
|
|
|
SetFlag(PokeDexLanguageFlags, lbit, value);
|
|
|
|
}
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
protected override void SetAllDexSeenFlags(int baseBit, byte form, int gender, bool isShiny, bool value = true)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
var shiny = isShiny ? 1 : 0;
|
|
|
|
SetDexFlags(baseBit, baseBit, gender, shiny);
|
2022-08-27 06:43:36 +00:00
|
|
|
SetFormFlags((ushort)(baseBit + 1), form, shiny, value);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override void SetDex(PKM pk)
|
|
|
|
{
|
|
|
|
if (pk.Species is 0 or > Legal.MaxSpeciesID_6)
|
|
|
|
return;
|
|
|
|
if (pk.IsEgg) // do not add
|
|
|
|
return;
|
|
|
|
|
|
|
|
int bit = pk.Species - 1;
|
|
|
|
SetCaughtFlag(bit, pk.Version);
|
|
|
|
|
|
|
|
// Set the [Species/Gender/Shiny] Seen Flag
|
|
|
|
SetAllDexSeenFlags(pk.Species - 1, pk.Form, pk.Gender, pk.IsShiny);
|
|
|
|
SetAllDexFlagsLanguage(bit, pk.Language);
|
|
|
|
SetFormFlags(pk);
|
|
|
|
}
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected abstract void SetCaughtFlag(int bit, int origin);
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private int FormLen => SAV is SAV6XY ? 0x18 : 0x26;
|
|
|
|
private int FormDex => 0x8 + (BitSeenSize * 9);
|
|
|
|
public bool GetFormFlag(int formIndex, int flagRegion) => GetFlag(FormDex + (FormLen * flagRegion), formIndex);
|
|
|
|
public void SetFormFlag(int formIndex, int flagRegion, bool value = true) => SetFlag(FormDex + (FormLen * flagRegion), formIndex, value);
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void SetFormFlags(PKM pk)
|
|
|
|
{
|
2022-08-27 06:43:36 +00:00
|
|
|
var species = pk.Species;
|
|
|
|
var form = pk.Form;
|
2022-06-18 18:04:24 +00:00
|
|
|
var shiny = pk.IsShiny ? 1 : 0;
|
|
|
|
SetFormFlags(species, form, shiny);
|
|
|
|
}
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
private void SetFormFlags(ushort species, byte form, int shiny, bool value = true)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
var fc = SAV.Personal[species].FormCount;
|
2022-06-18 18:04:24 +00:00
|
|
|
int f = DexFormIndexFetcher(species, fc);
|
|
|
|
if (f < 0)
|
|
|
|
return;
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var bit = f + form;
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Set Form Seen Flag
|
|
|
|
SetFormFlag(bit, shiny, value);
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Set Displayed Flag if necessary, check all flags
|
|
|
|
if (!value || !GetIsFormDisplayed(f, fc))
|
|
|
|
SetFormFlag(bit, 2 + shiny, value);
|
|
|
|
}
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
private bool GetIsFormDisplayed(int form, byte formCount)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
for (byte i = 0; i < formCount; i++)
|
2018-11-01 22:38:09 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
var index = form + i;
|
2022-06-18 18:04:24 +00:00
|
|
|
if (GetFormFlag(index, 2)) // Nonshiny
|
|
|
|
return true; // already set
|
|
|
|
if (GetFormFlag(index, 3)) // Shiny
|
|
|
|
return true; // already set
|
2018-11-01 22:38:09 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public uint SpindaPID
|
|
|
|
{
|
|
|
|
get => ReadUInt32LittleEndian(SAV.Data.AsSpan(PokeDex + SpindaOffset));
|
|
|
|
set => WriteUInt32LittleEndian(SAV.Data.AsSpan(PokeDex + SpindaOffset), value);
|
|
|
|
}
|
2019-07-06 04:39:47 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public bool[] GetLanguageBitflags(ushort species)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
var result = new bool[DexLangIDCount];
|
|
|
|
int bit = species - 1;
|
|
|
|
for (int i = 0; i < DexLangIDCount; i++)
|
2018-11-01 22:38:09 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
int lbit = (bit * DexLangIDCount) + i;
|
|
|
|
result[i] = GetFlag(PokeDexLanguageFlags, lbit);
|
2018-11-01 22:38:09 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
return result;
|
|
|
|
}
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public void SetLanguageBitflags(ushort species, ReadOnlySpan<bool> value)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
int bit = species - 1;
|
|
|
|
for (int i = 0; i < DexLangIDCount; i++)
|
2018-11-01 22:38:09 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
int lbit = (bit * DexLangIDCount) + i;
|
|
|
|
SetFlag(PokeDexLanguageFlags, lbit, value[i]);
|
2018-11-01 22:38:09 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void ToggleLanguageFlagsAll(bool value)
|
|
|
|
{
|
|
|
|
var arr = GetBlankLanguageBits(value);
|
2022-08-27 06:43:36 +00:00
|
|
|
for (ushort i = 1; i <= SAV.MaxSpeciesID; i++)
|
2022-06-18 18:04:24 +00:00
|
|
|
SetLanguageBitflags(i, arr);
|
|
|
|
}
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public void ToggleLanguageFlagsSingle(ushort species, bool value)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
var arr = GetBlankLanguageBits(value);
|
|
|
|
SetLanguageBitflags(species, arr);
|
|
|
|
}
|
2018-11-01 22:38:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private bool[] GetBlankLanguageBits(bool value)
|
|
|
|
{
|
|
|
|
var result = new bool[DexLangIDCount];
|
|
|
|
for (int i = 0; i < DexLangIDCount; i++)
|
|
|
|
result[i] = value;
|
|
|
|
return result;
|
2018-11-01 22:38:09 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-07-06 01:04:36 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
2022-08-27 06:43:36 +00:00
|
|
|
/// Pokédex structure used for <see cref="GameVersion.ORAS"/>.
|
2022-06-18 18:04:24 +00:00
|
|
|
/// </summary>
|
|
|
|
public sealed class Zukan6AO : Zukan6
|
|
|
|
{
|
|
|
|
public Zukan6AO(SAV6AO sav, int dex, int langflag) : base(sav, dex, langflag)
|
2019-07-06 01:04:36 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
SpindaOffset = 0x680;
|
|
|
|
}
|
2019-07-06 01:04:36 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override void SetCaughtFlag(int bit, int origin)
|
|
|
|
{
|
|
|
|
SetFlag(OFS_CAUGHT, bit);
|
|
|
|
if (GetEncounterCount(bit) == 0)
|
|
|
|
SetEncounterCount(bit, 1);
|
|
|
|
}
|
2019-07-06 01:04:36 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public ushort GetEncounterCount(int index)
|
|
|
|
{
|
|
|
|
var ofs = PokeDex + 0x686 + (index * 2);
|
|
|
|
return ReadUInt16LittleEndian(SAV.Data.AsSpan(ofs));
|
|
|
|
}
|
2019-07-06 01:04:36 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void SetEncounterCount(int index, ushort value)
|
|
|
|
{
|
|
|
|
var ofs = PokeDex + 0x686 + (index * 2);
|
|
|
|
WriteUInt16LittleEndian(SAV.Data.AsSpan(ofs), value);
|
2019-07-06 01:04:36 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-07-06 01:04:36 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
2022-08-27 06:43:36 +00:00
|
|
|
/// Pokédex structure used for <see cref="GameVersion.XY"/>.
|
2022-06-18 18:04:24 +00:00
|
|
|
/// </summary>
|
|
|
|
public sealed class Zukan6XY : Zukan6
|
|
|
|
{
|
|
|
|
public Zukan6XY(SAV6XY sav, int dex, int langflag) : base(sav, dex, langflag)
|
2019-07-06 01:04:36 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
SpindaOffset = 0x648;
|
|
|
|
}
|
2019-07-06 01:04:36 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override void SetCaughtFlag(int bit, int origin)
|
|
|
|
{
|
|
|
|
// Species: 1-649 for X/Y, and not for ORAS; Set the Foreign Owned Flag
|
|
|
|
if (origin < (int)GameVersion.X && bit < (int)Species.Genesect)
|
|
|
|
SetForeignFlag(bit);
|
|
|
|
else
|
|
|
|
SetFlag(OFS_CAUGHT, bit);
|
|
|
|
}
|
2019-07-06 01:04:36 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public bool GetForeignFlag(int bit)
|
|
|
|
{
|
|
|
|
Debug.Assert(bit < (int)Species.Genesect);
|
|
|
|
return GetFlag(0x64C, bit);
|
|
|
|
}
|
2019-07-06 01:04:36 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void SetForeignFlag(int bit, bool value = true)
|
|
|
|
{
|
|
|
|
Debug.Assert(bit < (int)Species.Genesect);
|
|
|
|
SetFlag(0x64C, bit, value);
|
2019-07-06 01:04:36 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|