2019-06-09 02:56:11 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2021-02-21 23:01:28 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Pokédex structure used for Generation 5 games.
|
|
|
|
|
/// </summary>
|
2019-10-04 02:09:02 +00:00
|
|
|
|
public sealed class Zukan5 : Zukan
|
2019-06-09 02:56:11 +00:00
|
|
|
|
{
|
|
|
|
|
protected override int OFS_SEEN => OFS_CAUGHT + BitSeenSize;
|
|
|
|
|
protected override int OFS_CAUGHT => 0x8;
|
|
|
|
|
protected override int BitSeenSize => 0x54;
|
|
|
|
|
protected override int DexLangFlagByteCount => 7;
|
|
|
|
|
protected override int DexLangIDCount => 7;
|
|
|
|
|
|
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 Zukan5(SAV5B2W2 sav, int dex, int langflag) : base(sav, dex, langflag)
|
2019-06-09 02:56:11 +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
|
|
|
|
DexFormIndexFetcher = DexFormUtil.GetDexFormIndexB2W2;
|
2019-06-09 02:56:11 +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 Zukan5(SAV5BW sav, int dex, int langflag) : base(sav, dex, langflag)
|
|
|
|
|
{
|
|
|
|
|
DexFormIndexFetcher = DexFormUtil.GetDexFormIndexBW;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public readonly Func<int, int, int> DexFormIndexFetcher;
|
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
protected override int GetDexLangFlag(int lang)
|
|
|
|
|
{
|
|
|
|
|
lang--;
|
|
|
|
|
if (lang > 5)
|
|
|
|
|
lang--; // 0-6 language vals
|
|
|
|
|
if ((uint)lang > 5)
|
|
|
|
|
return -1;
|
|
|
|
|
return lang;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool GetSaneFormsToIterate(int species, out int formStart, out int formEnd, int formIn)
|
|
|
|
|
{
|
|
|
|
|
formStart = 0;
|
|
|
|
|
formEnd = 0;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void SetSpindaDexData(PKM pkm, bool alreadySeen)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void SetAllDexFlagsLanguage(int bit, int lang, bool value = true)
|
|
|
|
|
{
|
|
|
|
|
lang = GetDexLangFlag(lang);
|
|
|
|
|
if (lang < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Set the Language
|
|
|
|
|
int lbit = (bit * DexLangIDCount) + lang;
|
|
|
|
|
if (bit < 493) // shifted by 1, Gen5 species do not have international language bits
|
|
|
|
|
SetFlag(PokeDexLanguageFlags, lbit, value);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-11 04:42:30 +00:00
|
|
|
|
protected override void SetAllDexSeenFlags(int baseBit, int form, int gender, bool isShiny, bool value = true)
|
2019-06-09 02:56:11 +00:00
|
|
|
|
{
|
|
|
|
|
var shiny = isShiny ? 1 : 0;
|
2019-10-20 01:24:37 +00:00
|
|
|
|
SetDexFlags(baseBit, baseBit, gender, shiny);
|
2020-12-11 04:42:30 +00:00
|
|
|
|
SetFormFlags(baseBit + 1, form, shiny, value);
|
2019-06-09 02:56:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void SetDex(PKM pkm)
|
|
|
|
|
{
|
2021-06-05 00:26:06 +00:00
|
|
|
|
if (pkm.Species is 0 or > Legal.MaxSpeciesID_5)
|
2019-06-09 02:56:11 +00:00
|
|
|
|
return;
|
2021-06-05 00:26:06 +00:00
|
|
|
|
if (pkm.IsEgg) // do not add
|
2019-06-09 02:56:11 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int bit = pkm.Species - 1;
|
|
|
|
|
SetCaughtFlag(bit);
|
|
|
|
|
|
|
|
|
|
// Set the [Species/Gender/Shiny] Seen Flag
|
2020-12-11 04:42:30 +00:00
|
|
|
|
SetAllDexSeenFlags(bit, pkm.Form, pkm.Gender, pkm.IsShiny);
|
2019-06-09 02:56:11 +00:00
|
|
|
|
SetAllDexFlagsLanguage(bit, pkm.Language);
|
|
|
|
|
SetFormFlags(pkm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetCaughtFlag(int bit) => SetFlag(OFS_CAUGHT, bit);
|
|
|
|
|
|
2019-07-11 07:13:52 +00:00
|
|
|
|
protected override void SetDisplayedFlag(int baseBit, int formBit, bool value, int shift)
|
|
|
|
|
{
|
2019-10-20 01:24:37 +00:00
|
|
|
|
if (!value)
|
|
|
|
|
{
|
|
|
|
|
SetDisplayed(baseBit, shift, false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-11 07:13:52 +00:00
|
|
|
|
bool displayed = GetIsSpeciesAnyDisplayed(baseBit);
|
2019-10-20 01:24:37 +00:00
|
|
|
|
if (displayed)
|
|
|
|
|
return; // no need to set another bit
|
|
|
|
|
|
|
|
|
|
SetDisplayed(baseBit, shift, true);
|
2019-07-11 07:13:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool GetIsSpeciesAnyDisplayed(int baseBit)
|
|
|
|
|
{
|
|
|
|
|
// Check Displayed Status for base form
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
if (GetDisplayed(baseBit, i))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 22:06:45 +00:00
|
|
|
|
private int FormLen => SAV is SAV5B2W2 ? 0xB : 0x9;
|
2019-07-10 07:19:59 +00:00
|
|
|
|
private int FormDex => 0x8 + (BitSeenSize * 9);
|
2019-06-09 02:56:11 +00:00
|
|
|
|
|
|
|
|
|
private void SetFormFlags(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
int species = pkm.Species;
|
2020-12-11 04:42:30 +00:00
|
|
|
|
int form = pkm.Form;
|
2019-06-09 02:56:11 +00:00
|
|
|
|
var shiny = pkm.IsShiny ? 1 : 0;
|
|
|
|
|
SetFormFlags(species, form, shiny);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetFormFlags(int species, int form, int shiny, bool value = true)
|
|
|
|
|
{
|
2020-12-11 04:42:30 +00:00
|
|
|
|
int fc = SAV.Personal[species].FormCount;
|
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
|
|
|
|
int f = DexFormIndexFetcher(species, fc);
|
2019-06-09 02:56:11 +00:00
|
|
|
|
if (f < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var bit = f + form;
|
|
|
|
|
|
|
|
|
|
// Set Form Seen Flag
|
2019-07-05 23:21:53 +00:00
|
|
|
|
SetFormFlag(bit, shiny, value);
|
2019-06-09 02:56:11 +00:00
|
|
|
|
|
|
|
|
|
// Set Displayed Flag if necessary, check all flags
|
|
|
|
|
if (!value || !GetIsFormDisplayed(f, fc))
|
2019-07-05 23:21:53 +00:00
|
|
|
|
SetFormFlag(bit, 2 + shiny, value);
|
2019-06-09 02:56:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-05 23:21:53 +00:00
|
|
|
|
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);
|
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
private bool GetIsFormDisplayed(int f, int fc)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < fc; i++)
|
|
|
|
|
{
|
2019-07-05 23:21:53 +00:00
|
|
|
|
var index = f + i;
|
|
|
|
|
if (GetFormFlag(index, 2)) // Nonshiny
|
2019-06-09 02:56:11 +00:00
|
|
|
|
return true; // already set
|
2019-07-05 23:21:53 +00:00
|
|
|
|
if (GetFormFlag(index, 3)) // Shiny
|
2019-06-09 02:56:11 +00:00
|
|
|
|
return true; // already set
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool[] GetLanguageBitflags(int species)
|
|
|
|
|
{
|
|
|
|
|
var result = new bool[DexLangIDCount];
|
|
|
|
|
int bit = species - 1;
|
|
|
|
|
for (int i = 0; i < DexLangIDCount; i++)
|
|
|
|
|
{
|
|
|
|
|
int lbit = (bit * DexLangIDCount) + i;
|
|
|
|
|
result[i] = GetFlag(PokeDexLanguageFlags, lbit);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetLanguageBitflags(int species, bool[] value)
|
|
|
|
|
{
|
|
|
|
|
int bit = species - 1;
|
|
|
|
|
for (int i = 0; i < DexLangIDCount; i++)
|
|
|
|
|
{
|
|
|
|
|
int lbit = (bit * DexLangIDCount) + i;
|
|
|
|
|
SetFlag(PokeDexLanguageFlags, lbit, value[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ToggleLanguageFlagsAll(bool value)
|
|
|
|
|
{
|
|
|
|
|
var arr = GetBlankLanguageBits(value);
|
|
|
|
|
for (int i = 1; i <= SAV.MaxSpeciesID; i++)
|
|
|
|
|
SetLanguageBitflags(i, arr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ToggleLanguageFlagsSingle(int species, bool value)
|
|
|
|
|
{
|
|
|
|
|
var arr = GetBlankLanguageBits(value);
|
|
|
|
|
SetLanguageBitflags(species, arr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool[] GetBlankLanguageBits(bool value)
|
|
|
|
|
{
|
|
|
|
|
var result = new bool[DexLangIDCount];
|
|
|
|
|
for (int i = 0; i < DexLangIDCount; i++)
|
|
|
|
|
result[i] = value;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|