2018-11-14 03:14:23 +00:00
|
|
|
using System;
|
2019-07-06 01:04:36 +00:00
|
|
|
using System.Diagnostics;
|
2018-11-14 03:14:23 +00:00
|
|
|
|
2018-11-01 22:38:09 +00:00
|
|
|
namespace PKHeX.Core
|
|
|
|
{
|
2019-07-06 01:04:36 +00:00
|
|
|
public abstract class Zukan6 : Zukan
|
2018-11-01 22:38:09 +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 => 7;
|
|
|
|
protected override int DexLangIDCount => 7;
|
|
|
|
|
2019-07-06 01:04:36 +00:00
|
|
|
protected Zukan6(SaveFile sav, int dex, int langflag) : base(sav, dex, langflag) { }
|
2018-11-14 03:14:23 +00:00
|
|
|
|
2018-11-01 22:38:09 +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;
|
|
|
|
|
|
|
|
int lbit = (bit * DexLangIDCount) + lang;
|
|
|
|
if (lbit < DexLangFlagByteCount << 3) // Sanity check for max length of region
|
|
|
|
SetFlag(PokeDexLanguageFlags, lbit, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void SetAllDexSeenFlags(int baseBit, int altform, int gender, bool isShiny, bool value = true)
|
|
|
|
{
|
|
|
|
var shiny = isShiny ? 1 : 0;
|
|
|
|
SetDexFlags(baseBit, 0, gender, shiny);
|
|
|
|
SetFormFlags(baseBit + 1, altform, shiny, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void SetDex(PKM pkm)
|
|
|
|
{
|
|
|
|
if (PokeDex < 0)
|
|
|
|
return;
|
|
|
|
if (pkm.Species == 0)
|
|
|
|
return;
|
|
|
|
if (pkm.Species > SAV.MaxSpeciesID)
|
|
|
|
return;
|
|
|
|
if (SAV.Version == GameVersion.Invalid)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int bit = pkm.Species - 1;
|
|
|
|
SetCaughtFlag(bit, pkm.Version);
|
|
|
|
|
|
|
|
// Set the [Species/Gender/Shiny] Seen Flag
|
|
|
|
SetAllDexSeenFlags(pkm.Species - 1, pkm.AltForm, pkm.Gender, pkm.IsShiny);
|
|
|
|
SetAllDexFlagsLanguage(bit, pkm.Language);
|
|
|
|
SetFormFlags(pkm);
|
|
|
|
}
|
|
|
|
|
2019-07-06 01:04:36 +00:00
|
|
|
protected abstract void SetCaughtFlag(int bit, int origin);
|
2018-11-01 22:38:09 +00:00
|
|
|
|
|
|
|
private int FormLen => SAV.ORAS ? 0x26 : 0x18;
|
2019-07-06 01:04:36 +00:00
|
|
|
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
|
|
|
|
|
|
|
private void SetFormFlags(PKM pkm)
|
|
|
|
{
|
|
|
|
int species = pkm.Species;
|
|
|
|
int form = pkm.AltForm;
|
|
|
|
var shiny = pkm.IsShiny ? 1 : 0;
|
|
|
|
SetFormFlags(species, form, shiny);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetFormFlags(int species, int form, int shiny, bool value = true)
|
|
|
|
{
|
|
|
|
int fc = SAV.Personal[species].FormeCount;
|
2018-11-14 03:14:23 +00:00
|
|
|
int f = DexFormIndexFetcher(species, fc, SAV.MaxSpeciesID - 1);
|
2018-11-01 22:38:09 +00:00
|
|
|
if (f < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var bit = f + form;
|
|
|
|
|
|
|
|
// Set Form Seen Flag
|
2019-07-06 01:04:36 +00:00
|
|
|
SetFormFlag(bit, shiny, value);
|
2018-11-01 22:38:09 +00:00
|
|
|
|
|
|
|
// Set Displayed Flag if necessary, check all flags
|
|
|
|
if (!value || !GetIsFormDisplayed(f, fc))
|
2019-07-06 01:04:36 +00:00
|
|
|
SetFormFlag(bit, 2 + shiny, value);
|
2018-11-01 22:38:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private bool GetIsFormDisplayed(int f, int fc)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < fc; i++)
|
|
|
|
{
|
2019-07-06 01:04:36 +00:00
|
|
|
var index = f + i;
|
|
|
|
if (GetFormFlag(index, 2)) // Nonshiny
|
2018-11-01 22:38:09 +00:00
|
|
|
return true; // already set
|
2019-07-06 01:04:36 +00:00
|
|
|
if (GetFormFlag(index, 3)) // Shiny
|
2018-11-01 22:38:09 +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;
|
|
|
|
}
|
|
|
|
}
|
2019-07-06 01:04:36 +00:00
|
|
|
|
|
|
|
public class Zukan6AO : Zukan6
|
|
|
|
{
|
|
|
|
public Zukan6AO(SaveFile sav, int dex, int langflag) : base(sav, dex, langflag)
|
|
|
|
{
|
|
|
|
DexFormIndexFetcher = (spec, form, _) => DexFormUtil.GetDexFormIndexORAS(spec, form);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void SetCaughtFlag(int bit, int origin)
|
|
|
|
{
|
|
|
|
SetFlag(OFS_CAUGHT, bit);
|
|
|
|
if (GetEncounterCount(bit) == 0)
|
|
|
|
SetEncounterCount(bit, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ushort GetEncounterCount(int index)
|
|
|
|
{
|
|
|
|
var ofs = PokeDex + 0x686 + (index * 2);
|
|
|
|
return BitConverter.ToUInt16(SAV.Data, ofs);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetEncounterCount(int index, ushort value)
|
|
|
|
{
|
|
|
|
var ofs = PokeDex + 0x686 + (index * 2);
|
|
|
|
var data = BitConverter.GetBytes(value);
|
|
|
|
SAV.SetData(data, ofs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class Zukan6XY : Zukan6
|
|
|
|
{
|
|
|
|
public Zukan6XY(SaveFile sav, int dex, int langflag) : base(sav, dex, langflag)
|
|
|
|
{
|
|
|
|
DexFormIndexFetcher = (spec, form, _) => DexFormUtil.GetDexFormIndexXY(spec, form);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 < 24 && bit < (int)Species.Genesect)
|
|
|
|
SetForeignFlag(bit);
|
|
|
|
else
|
|
|
|
SetFlag(OFS_CAUGHT, bit);
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool GetForeignFlag(int bit)
|
|
|
|
{
|
|
|
|
Debug.Assert(bit < (int)Species.Genesect);
|
|
|
|
return GetFlag(0x64C, bit);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetForeignFlag(int bit, bool value = true)
|
|
|
|
{
|
|
|
|
Debug.Assert(bit < (int)Species.Genesect);
|
|
|
|
SetFlag(0x64C, bit, value);
|
|
|
|
}
|
|
|
|
}
|
2018-11-01 22:38:09 +00:00
|
|
|
}
|