Refactoring

mostly renaming things, includes a little bit of added sugar and
splitting methods to simplify the codebase.

all methods are now PascalCase
This commit is contained in:
Kurt 2017-06-17 18:37:19 -07:00
parent 84d3247b75
commit 3f38b123a3
210 changed files with 6696 additions and 6730 deletions

View file

@ -1,6 +1,6 @@
namespace PKHeX.Core
{
public class ComboItem
public struct ComboItem
{
public string Text { get; set; }
public int Value { get; set; }

View file

@ -16,19 +16,19 @@ namespace PKHeX.Core
// Lazy fetch implementation
private static int DefaultLanguageIndex => Array.IndexOf(lang_val, DefaultLanguage);
private static int getLanguageIndex(string lang)
private static int GetLanguageIndex(string lang)
{
int l = Array.IndexOf(lang_val, lang);
return l < 0 ? DefaultLanguageIndex : l;
}
public static GameStrings getStrings(string lang)
public static GameStrings GetStrings(string lang)
{
int index = getLanguageIndex(lang);
int index = GetLanguageIndex(lang);
return Languages[index] ?? (Languages[index] = new GameStrings(lang_val[index]));
}
private static string getTransporterName(string lang)
private static string GetTransporterName(string lang)
{
int index = getLanguageIndex(lang);
int index = GetLanguageIndex(lang);
if (index >= ptransp.Length)
index = DefaultLanguageIndex;
return ptransp[index];
@ -53,35 +53,35 @@ namespace PKHeX.Core
// Misc
public readonly string[] wallpapernames, puffs;
public readonly string eggname;
private readonly string Language;
private readonly string lang;
public GameStrings(string l)
{
Language = l;
lang = l;
// Past Generation strings
g3items = get("ItemsG3");
g3items = Get("ItemsG3");
// XD and Colosseum
{
g3coloitems = (string[])g3items.Clone();
string[] tmp = get("ItemsG3Colosseum");
string[] tmp = Get("ItemsG3Colosseum");
Array.Resize(ref g3coloitems, 500 + tmp.Length);
for (int i = g3items.Length; i < g3coloitems.Length; i++)
g3coloitems[i] = $"UNUSED {i}";
Array.Copy(tmp, 0, g3coloitems, g3coloitems.Length - tmp.Length, tmp.Length);
g3xditems = (string[])g3items.Clone();
string[] tmp2 = get("ItemsG3XD");
string[] tmp2 = Get("ItemsG3XD");
Array.Resize(ref g3xditems, 500 + tmp2.Length);
for (int i = g3items.Length; i < g3xditems.Length; i++)
g3xditems[i] = $"UNUSED {i}";
Array.Copy(tmp2, 0, g3xditems, g3xditems.Length - tmp2.Length, tmp2.Length);
}
g2items = get("ItemsG2");
g1items = get("ItemsG1");
metRSEFRLG_00000 = get("rsefrlg_00000");
metGSC_00000 = get("gsc_00000");
g2items = Get("ItemsG2");
g1items = Get("ItemsG1");
metRSEFRLG_00000 = Get("rsefrlg_00000");
metGSC_00000 = Get("gsc_00000");
metCXD_00000 = get("cxd_00000");
metCXD_00000 = Get("cxd_00000");
// Sanitize a little
var metSanitize = (string[])metCXD_00000.Clone();
for (int i = 0; i < metSanitize.Length; i++)
@ -90,51 +90,51 @@ namespace PKHeX.Core
metCXD_00000 = metSanitize;
// Current Generation strings
natures = Util.getNaturesList(l);
types = get("types");
abilitylist = get("abilities");
natures = Util.GetNaturesList(l);
types = Get("types");
abilitylist = Get("abilities");
movelist = get("moves");
movelist = Get("moves");
string[] ps = {"P", "S"}; // Distinguish Physical/Special
for (int i = 622; i < 658; i++)
movelist[i] += $" ({ps[i%2]})";
itemlist = get("items");
characteristics = get("character");
specieslist = get("species");
wallpapernames = get("wallpaper");
encountertypelist = get("encountertype");
gamelist = get("games");
gamelanguages = Util.getNulledStringArray(Util.getStringList("languages"));
itemlist = Get("items");
characteristics = Get("character");
specieslist = Get("species");
wallpapernames = Get("wallpaper");
encountertypelist = Get("encountertype");
gamelist = Get("games");
gamelanguages = Util.GetNulledStringArray(Util.GetStringList("languages"));
balllist = new string[Legal.Items_Ball.Length];
for (int i = 0; i < balllist.Length; i++)
balllist[i] = itemlist[Legal.Items_Ball[i]];
pokeblocks = get("pokeblock");
forms = get("forms");
memories = get("memories");
genloc = get("genloc");
trainingbags = get("trainingbag");
trainingstage = get("supertraining");
puffs = get("puff");
pokeblocks = Get("pokeblock");
forms = Get("forms");
memories = Get("memories");
genloc = Get("genloc");
trainingbags = Get("trainingbag");
trainingstage = Get("supertraining");
puffs = Get("puff");
eggname = specieslist[0];
metHGSS_00000 = get("hgss_00000");
metHGSS_02000 = get("hgss_02000");
metHGSS_03000 = get("hgss_03000");
metBW2_00000 = get("bw2_00000");
metBW2_30000 = get("bw2_30000");
metBW2_40000 = get("bw2_40000");
metBW2_60000 = get("bw2_60000");
metXY_00000 = get("xy_00000");
metXY_30000 = get("xy_30000");
metXY_40000 = get("xy_40000");
metXY_60000 = get("xy_60000");
metSM_00000 = get("sm_00000");
metSM_30000 = get("sm_30000");
metSM_40000 = get("sm_40000");
metSM_60000 = get("sm_60000");
metHGSS_00000 = Get("hgss_00000");
metHGSS_02000 = Get("hgss_02000");
metHGSS_03000 = Get("hgss_03000");
metBW2_00000 = Get("bw2_00000");
metBW2_30000 = Get("bw2_30000");
metBW2_40000 = Get("bw2_40000");
metBW2_60000 = Get("bw2_60000");
metXY_00000 = Get("xy_00000");
metXY_30000 = Get("xy_30000");
metXY_40000 = Get("xy_40000");
metXY_60000 = Get("xy_60000");
metSM_00000 = Get("sm_00000");
metSM_30000 = Get("sm_30000");
metSM_40000 = Get("sm_40000");
metSM_60000 = Get("sm_60000");
Sanitize();
}
@ -194,7 +194,7 @@ namespace PKHeX.Core
metBW2_00000[2] += " (2)";
// Localize the Poketransfer to the language (30001)
metBW2_30000[1 - 1] = getTransporterName(Language); // Default to English
metBW2_30000[1 - 1] = GetTransporterName(lang); // Default to English
metBW2_30000[2 - 1] += " (NPC)"; // Anything from an NPC
metBW2_30000[3 - 1] += $" ({eggname})"; // Link Trade (Egg)
@ -234,16 +234,16 @@ namespace PKHeX.Core
// Fix (None) tags
abilitylist[0] = itemlist[0] = movelist[0] = metXY_00000[0] = metBW2_00000[0] = metHGSS_00000[0] = "(" + itemlist[0] + ")";
}
private string[] get(string ident)
private string[] Get(string ident)
{
string[] data = Util.getStringList(ident, Language);
string[] data = Util.GetStringList(ident, lang);
if (data == null || data.Length == 0)
data = Util.getStringList(ident, DefaultLanguage);
data = Util.GetStringList(ident, DefaultLanguage);
return data;
}
public string[] getItemStrings(int generation, GameVersion game)
public string[] GetItemStrings(int generation, GameVersion game)
{
switch (generation)
{
@ -276,157 +276,171 @@ namespace PKHeX.Core
public static GameStrings Strings;
// DataSource providing
public static List<ComboItem> ItemDataSource, SpeciesDataSource, BallDataSource, NatureDataSource, AbilityDataSource, VersionDataSource;
public static List<ComboItem> LegalMoveDataSource, HaXMoveDataSource, MoveDataSource;
private static List<ComboItem> metGen2, metGen3, metGen3CXD, metGen4, metGen5, metGen6, metGen7;
public static List<ComboItem> ItemDataSource { get; private set; }
public static List<ComboItem> SpeciesDataSource { get; private set; }
public static List<ComboItem> BallDataSource { get; private set; }
public static List<ComboItem> NatureDataSource { get; private set; }
public static List<ComboItem> AbilityDataSource { get; private set; }
public static List<ComboItem> VersionDataSource { get; private set; }
public static List<ComboItem> LegalMoveDataSource { get; private set; }
public static List<ComboItem> HaXMoveDataSource { get; private set; }
public static List<ComboItem> MoveDataSource { get; set; }
private static List<ComboItem> MetGen2 { get; set; }
private static List<ComboItem> MetGen3 { get; set; }
private static List<ComboItem> MetGen3CXD { get; set; }
private static List<ComboItem> MetGen4 { get; set; }
private static List<ComboItem> MetGen5 { get; set; }
private static List<ComboItem> MetGen6 { get; set; }
private static List<ComboItem> MetGen7 { get; set; }
public static void InitializeDataSources(GameStrings s)
{
int[] ball_nums = { 007, 576, 013, 492, 497, 014, 495, 493, 496, 494, 011, 498, 008, 006, 012, 015, 009, 005, 499, 010, 001, 016, 851 };
int[] ball_vals = { 007, 025, 013, 017, 022, 014, 020, 018, 021, 019, 011, 023, 008, 006, 012, 015, 009, 005, 024, 010, 001, 016, 026 };
BallDataSource = Util.getVariedCBList(s.itemlist, ball_nums, ball_vals);
SpeciesDataSource = Util.getCBList(s.specieslist, null);
NatureDataSource = Util.getCBList(s.natures, null);
AbilityDataSource = Util.getCBList(s.abilitylist, null);
VersionDataSource = Util.getCBList(s.gamelist, Legal.Games_7sm, Legal.Games_6oras, Legal.Games_6xy, Legal.Games_5, Legal.Games_4, Legal.Games_4e, Legal.Games_4r, Legal.Games_3, Legal.Games_3e, Legal.Games_3r, Legal.Games_3s);
VersionDataSource.AddRange(Util.getCBList(s.gamelist, Legal.Games_7vc1).OrderBy(g => g.Value)); // stuff to end unsorted
VersionDataSource.AddRange(Util.getCBList(s.gamelist, Legal.Games_7go).OrderBy(g => g.Value)); // stuff to end unsorted
BallDataSource = Util.GetVariedCBList(s.itemlist, ball_nums, ball_vals);
SpeciesDataSource = Util.GetCBList(s.specieslist, null);
NatureDataSource = Util.GetCBList(s.natures, null);
AbilityDataSource = Util.GetCBList(s.abilitylist, null);
VersionDataSource = Util.GetCBList(s.gamelist, Legal.Games_7sm, Legal.Games_6oras, Legal.Games_6xy, Legal.Games_5, Legal.Games_4, Legal.Games_4e, Legal.Games_4r, Legal.Games_3, Legal.Games_3e, Legal.Games_3r, Legal.Games_3s);
VersionDataSource.AddRange(Util.GetCBList(s.gamelist, Legal.Games_7vc1).OrderBy(g => g.Value)); // stuff to end unsorted
VersionDataSource.AddRange(Util.GetCBList(s.gamelist, Legal.Games_7go).OrderBy(g => g.Value)); // stuff to end unsorted
HaXMoveDataSource = Util.getCBList(s.movelist, null);
HaXMoveDataSource = Util.GetCBList(s.movelist, null);
MoveDataSource = LegalMoveDataSource = HaXMoveDataSource.Where(m => !Legal.Z_Moves.Contains(m.Value)).ToList();
#region Met Locations
// Gen 2
{
var met_list = Util.getCBList(s.metGSC_00000, Enumerable.Range(0, 0x5F).ToArray());
met_list = Util.getOffsetCBList(met_list, s.metGSC_00000, 00000, new[] { 0x7E, 0x7F });
metGen2 = met_list;
var met_list = Util.GetCBList(s.metGSC_00000, Enumerable.Range(0, 0x5F).ToArray());
met_list = Util.GetOffsetCBList(met_list, s.metGSC_00000, 00000, new[] { 0x7E, 0x7F });
MetGen2 = met_list;
}
// Gen 3
{
var met_list = Util.getCBList(s.metRSEFRLG_00000, Enumerable.Range(0, 213).ToArray());
met_list = Util.getOffsetCBList(met_list, s.metRSEFRLG_00000, 00000, new[] { 253, 254, 255 });
metGen3 = met_list;
var met_list = Util.GetCBList(s.metRSEFRLG_00000, Enumerable.Range(0, 213).ToArray());
met_list = Util.GetOffsetCBList(met_list, s.metRSEFRLG_00000, 00000, new[] { 253, 254, 255 });
MetGen3 = met_list;
var cxd_list = Util.getCBList(s.metCXD_00000, Enumerable.Range(0, s.metCXD_00000.Length).ToArray()).Where(c => c.Text.Length > 0).ToList();
metGen3CXD = cxd_list;
var cxd_list = Util.GetCBList(s.metCXD_00000, Enumerable.Range(0, s.metCXD_00000.Length).ToArray()).Where(c => c.Text.Length > 0).ToList();
MetGen3CXD = cxd_list;
}
// Gen 4
{
var met_list = Util.getCBList(s.metHGSS_00000, new[] { 0 });
met_list = Util.getOffsetCBList(met_list, s.metHGSS_02000, 2000, new[] { 2000 });
met_list = Util.getOffsetCBList(met_list, s.metHGSS_02000, 2000, new[] { 2002 });
met_list = Util.getOffsetCBList(met_list, s.metHGSS_03000, 3000, new[] { 3001 });
met_list = Util.getOffsetCBList(met_list, s.metHGSS_00000, 0000, Legal.Met_HGSS_0);
met_list = Util.getOffsetCBList(met_list, s.metHGSS_02000, 2000, Legal.Met_HGSS_2);
met_list = Util.getOffsetCBList(met_list, s.metHGSS_03000, 3000, Legal.Met_HGSS_3);
metGen4 = met_list;
var met_list = Util.GetCBList(s.metHGSS_00000, new[] { 0 });
met_list = Util.GetOffsetCBList(met_list, s.metHGSS_02000, 2000, new[] { 2000 });
met_list = Util.GetOffsetCBList(met_list, s.metHGSS_02000, 2000, new[] { 2002 });
met_list = Util.GetOffsetCBList(met_list, s.metHGSS_03000, 3000, new[] { 3001 });
met_list = Util.GetOffsetCBList(met_list, s.metHGSS_00000, 0000, Legal.Met_HGSS_0);
met_list = Util.GetOffsetCBList(met_list, s.metHGSS_02000, 2000, Legal.Met_HGSS_2);
met_list = Util.GetOffsetCBList(met_list, s.metHGSS_03000, 3000, Legal.Met_HGSS_3);
MetGen4 = met_list;
}
// Gen 5
{
var met_list = Util.getCBList(s.metBW2_00000, new[] { 0 });
met_list = Util.getOffsetCBList(met_list, s.metBW2_60000, 60001, new[] { 60002 });
met_list = Util.getOffsetCBList(met_list, s.metBW2_30000, 30001, new[] { 30003 });
met_list = Util.getOffsetCBList(met_list, s.metBW2_00000, 00000, Legal.Met_BW2_0);
met_list = Util.getOffsetCBList(met_list, s.metBW2_30000, 30001, Legal.Met_BW2_3);
met_list = Util.getOffsetCBList(met_list, s.metBW2_40000, 40001, Legal.Met_BW2_4);
met_list = Util.getOffsetCBList(met_list, s.metBW2_60000, 60001, Legal.Met_BW2_6);
metGen5 = met_list;
var met_list = Util.GetCBList(s.metBW2_00000, new[] { 0 });
met_list = Util.GetOffsetCBList(met_list, s.metBW2_60000, 60001, new[] { 60002 });
met_list = Util.GetOffsetCBList(met_list, s.metBW2_30000, 30001, new[] { 30003 });
met_list = Util.GetOffsetCBList(met_list, s.metBW2_00000, 00000, Legal.Met_BW2_0);
met_list = Util.GetOffsetCBList(met_list, s.metBW2_30000, 30001, Legal.Met_BW2_3);
met_list = Util.GetOffsetCBList(met_list, s.metBW2_40000, 40001, Legal.Met_BW2_4);
met_list = Util.GetOffsetCBList(met_list, s.metBW2_60000, 60001, Legal.Met_BW2_6);
MetGen5 = met_list;
}
// Gen 6
{
var met_list = Util.getCBList(s.metXY_00000, new[] { 0 });
met_list = Util.getOffsetCBList(met_list, s.metXY_60000, 60001, new[] { 60002 });
met_list = Util.getOffsetCBList(met_list, s.metXY_30000, 30001, new[] { 30002 });
met_list = Util.getOffsetCBList(met_list, s.metXY_00000, 00000, Legal.Met_XY_0);
met_list = Util.getOffsetCBList(met_list, s.metXY_30000, 30001, Legal.Met_XY_3);
met_list = Util.getOffsetCBList(met_list, s.metXY_40000, 40001, Legal.Met_XY_4);
met_list = Util.getOffsetCBList(met_list, s.metXY_60000, 60001, Legal.Met_XY_6);
metGen6 = met_list;
var met_list = Util.GetCBList(s.metXY_00000, new[] { 0 });
met_list = Util.GetOffsetCBList(met_list, s.metXY_60000, 60001, new[] { 60002 });
met_list = Util.GetOffsetCBList(met_list, s.metXY_30000, 30001, new[] { 30002 });
met_list = Util.GetOffsetCBList(met_list, s.metXY_00000, 00000, Legal.Met_XY_0);
met_list = Util.GetOffsetCBList(met_list, s.metXY_30000, 30001, Legal.Met_XY_3);
met_list = Util.GetOffsetCBList(met_list, s.metXY_40000, 40001, Legal.Met_XY_4);
met_list = Util.GetOffsetCBList(met_list, s.metXY_60000, 60001, Legal.Met_XY_6);
MetGen6 = met_list;
}
// Gen 7
{
var met_list = Util.getCBList(s.metSM_00000, new[] { 0 });
met_list = Util.getOffsetCBList(met_list, s.metSM_60000, 60001, new[] { 60002 });
met_list = Util.getOffsetCBList(met_list, s.metSM_30000, 30001, new[] { 30002 });
met_list = Util.getOffsetCBList(met_list, s.metSM_00000, 00000, Legal.Met_SM_0);
met_list = Util.getOffsetCBList(met_list, s.metSM_30000, 30001, Legal.Met_SM_3);
met_list = Util.getOffsetCBList(met_list, s.metSM_40000, 40001, Legal.Met_SM_4);
met_list = Util.getOffsetCBList(met_list, s.metSM_60000, 60001, Legal.Met_SM_6);
metGen7 = met_list;
var met_list = Util.GetCBList(s.metSM_00000, new[] { 0 });
met_list = Util.GetOffsetCBList(met_list, s.metSM_60000, 60001, new[] { 60002 });
met_list = Util.GetOffsetCBList(met_list, s.metSM_30000, 30001, new[] { 30002 });
met_list = Util.GetOffsetCBList(met_list, s.metSM_00000, 00000, Legal.Met_SM_0);
met_list = Util.GetOffsetCBList(met_list, s.metSM_30000, 30001, Legal.Met_SM_3);
met_list = Util.GetOffsetCBList(met_list, s.metSM_40000, 40001, Legal.Met_SM_4);
met_list = Util.GetOffsetCBList(met_list, s.metSM_60000, 60001, Legal.Met_SM_6);
MetGen7 = met_list;
}
#endregion
}
public static void setItemDataSource(bool HaX, int MaxItemID, IEnumerable<ushort> allowed, int generation, GameVersion game, GameStrings s)
public static void SetItemDataSource(bool HaX, int MaxItemID, IEnumerable<ushort> allowed, int generation, GameVersion game, GameStrings s)
{
string[] items = s.getItemStrings(generation, game);
ItemDataSource = Util.getCBList(items, (allowed == null || HaX ? Enumerable.Range(0, MaxItemID) : allowed.Select(i => (int) i)).ToArray());
string[] items = s.GetItemStrings(generation, game);
ItemDataSource = Util.GetCBList(items, (allowed == null || HaX ? Enumerable.Range(0, MaxItemID) : allowed.Select(i => (int) i)).ToArray());
}
public static List<ComboItem> getLocationList(GameVersion Version, int SaveFormat, bool egg)
public static List<ComboItem> GetLocationList(GameVersion Version, int SaveFormat, bool egg)
{
if (SaveFormat == 2)
return metGen2;
return MetGen2;
if (egg)
{
if (Version < GameVersion.W && SaveFormat >= 5)
return metGen4;
return MetGen4;
}
switch (Version)
{
case GameVersion.CXD:
if (SaveFormat == 3)
return metGen3CXD;
return MetGen3CXD;
break;
case GameVersion.R:
case GameVersion.S:
if (SaveFormat == 3)
return metGen3.OrderByDescending(loc => loc.Value <= 87).ToList(); // Ferry
return MetGen3.OrderByDescending(loc => loc.Value <= 87).ToList(); // Ferry
break;
case GameVersion.E:
if (SaveFormat == 3)
return metGen3.OrderByDescending(loc => loc.Value <= 87 || (loc.Value >= 196 && loc.Value <= 212)).ToList(); // Trainer Hill
return MetGen3.OrderByDescending(loc => loc.Value <= 87 || (loc.Value >= 196 && loc.Value <= 212)).ToList(); // Trainer Hill
break;
case GameVersion.FR:
case GameVersion.LG:
if (SaveFormat == 3)
return metGen3.OrderByDescending(loc => loc.Value > 87 && loc.Value < 197).ToList(); // Celadon Dept.
return MetGen3.OrderByDescending(loc => loc.Value > 87 && loc.Value < 197).ToList(); // Celadon Dept.
break;
case GameVersion.D:
case GameVersion.P:
if (SaveFormat == 4 || (SaveFormat >= 5 && egg))
return metGen4.Take(4).Concat(metGen4.Skip(4).OrderByDescending(loc => loc.Value <= 111)).ToList(); // Battle Park
return MetGen4.Take(4).Concat(MetGen4.Skip(4).OrderByDescending(loc => loc.Value <= 111)).ToList(); // Battle Park
break;
case GameVersion.Pt:
if (SaveFormat == 4 || (SaveFormat >= 5 && egg))
return metGen4.Take(4).Concat(metGen4.Skip(4).OrderByDescending(loc => loc.Value <= 125)).ToList(); // Rock Peak Ruins
return MetGen4.Take(4).Concat(MetGen4.Skip(4).OrderByDescending(loc => loc.Value <= 125)).ToList(); // Rock Peak Ruins
break;
case GameVersion.HG:
case GameVersion.SS:
if (SaveFormat == 4 || (SaveFormat >= 5 && egg))
return metGen4.Take(4).Concat(metGen4.Skip(4).OrderByDescending(loc => loc.Value > 125 && loc.Value < 234)).ToList(); // Celadon Dept.
return MetGen4.Take(4).Concat(MetGen4.Skip(4).OrderByDescending(loc => loc.Value > 125 && loc.Value < 234)).ToList(); // Celadon Dept.
break;
case GameVersion.B:
case GameVersion.W:
return metGen5;
return MetGen5;
case GameVersion.B2:
case GameVersion.W2:
return metGen5.Take(3).Concat(metGen5.Skip(3).OrderByDescending(loc => loc.Value <= 116)).ToList(); // Abyssal Ruins
return MetGen5.Take(3).Concat(MetGen5.Skip(3).OrderByDescending(loc => loc.Value <= 116)).ToList(); // Abyssal Ruins
case GameVersion.X:
case GameVersion.Y:
return metGen6.Take(3).Concat(metGen6.Skip(3).OrderByDescending(loc => loc.Value <= 168)).ToList(); // Unknown Dungeon
return MetGen6.Take(3).Concat(MetGen6.Skip(3).OrderByDescending(loc => loc.Value <= 168)).ToList(); // Unknown Dungeon
case GameVersion.OR:
case GameVersion.AS:
return metGen6.Take(3).Concat(metGen6.Skip(3).OrderByDescending(loc => loc.Value > 168 && loc.Value <= 354)).ToList(); // Secret Base
return MetGen6.Take(3).Concat(MetGen6.Skip(3).OrderByDescending(loc => loc.Value > 168 && loc.Value <= 354)).ToList(); // Secret Base
case GameVersion.SN:
case GameVersion.MN:
@ -436,21 +450,21 @@ namespace PKHeX.Core
case GameVersion.BU:
case GameVersion.GN:
case GameVersion.YW:
return metGen7.Take(3).Concat(metGen7.Skip(3).OrderByDescending(loc => loc.Value < 200)).ToList(); // Secret Base
return MetGen7.Take(3).Concat(MetGen7.Skip(3).OrderByDescending(loc => loc.Value < 200)).ToList(); // Secret Base
}
// Currently on a future game, return corresponding list for generation
if (Version <= GameVersion.CXD && SaveFormat == 4)
return metGen4.Where(loc => loc.Value == 0x37) // Pal Park to front
.Concat(metGen4.Take(4))
.Concat(metGen4.Skip(4).Where(loc => loc.Value != 0x37)).ToList();
return MetGen4.Where(loc => loc.Value == 0x37) // Pal Park to front
.Concat(MetGen4.Take(4))
.Concat(MetGen4.Skip(4).Where(loc => loc.Value != 0x37)).ToList();
if (Version < GameVersion.X && SaveFormat >= 5) // PokéTransfer to front
return metGen5.Where(loc => loc.Value == 30001)
.Concat(metGen5.Take(3))
.Concat(metGen5.Skip(3).Where(loc => loc.Value != 30001)).ToList();
return MetGen5.Where(loc => loc.Value == 30001)
.Concat(MetGen5.Take(3))
.Concat(MetGen5.Skip(3).Where(loc => loc.Value != 30001)).ToList();
return metGen6;
return MetGen6;
}
/// <summary>
@ -460,12 +474,12 @@ namespace PKHeX.Core
/// <param name="region">Region ID</param>
/// <param name="language">Language ID</param>
/// <returns></returns>
public static Tuple<string, string> getCountryRegionText(int country, int region, string language)
public static Tuple<string, string> GetCountryRegionText(int country, int region, string language)
{
// Get Language we're fetching for
int lang = Array.IndexOf(new[] { "ja", "en", "fr", "de", "it", "es", "zh", "ko" }, language);
string c = getCountryString(country, lang);
string r = getRegionString(country, region, lang);
string c = GetCountryString(country, lang);
string r = GetRegionString(country, region, lang);
return new Tuple<string, string>(c, r); // country, region
}
@ -475,13 +489,13 @@ namespace PKHeX.Core
/// <param name="country">Country ID</param>
/// <param name="language">Language ID</param>
/// <returns>Country ID string</returns>
private static string getCountryString(int country, int language)
private static string GetCountryString(int country, int language)
{
string c;
// Get Country Text
try
{
string[] inputCSV = Util.getStringList("countries");
string[] inputCSV = Util.GetStringList("countries");
// Set up our Temporary Storage
string[] unsortedList = new string[inputCSV.Length - 1];
int[] indexes = new int[inputCSV.Length - 1];
@ -510,12 +524,12 @@ namespace PKHeX.Core
/// <param name="region">Region ID</param>
/// <param name="language">Language ID</param>
/// <returns>Region ID string</returns>
private static string getRegionString(int country, int region, int language)
private static string GetRegionString(int country, int region, int language)
{
// Get Region Text
try
{
string[] inputCSV = Util.getStringList("sr_" + country.ToString("000"));
string[] inputCSV = Util.GetStringList("sr_" + country.ToString("000"));
// Set up our Temporary Storage
string[] unsortedList = new string[inputCSV.Length - 1];
int[] indexes = new int[inputCSV.Length - 1];
@ -541,7 +555,7 @@ namespace PKHeX.Core
/// <param name="gen">Generation to get location names for.</param>
/// <param name="bankID">BankID used to choose the text bank.</param>
/// <returns>List of location names.</returns>
public static string[] getLocationNames(int gen, int bankID)
public static string[] GetLocationNames(int gen, int bankID)
{
switch (gen)
{

View file

@ -5,7 +5,7 @@
/// <summary>Determines the Version Grouping of an input Version ID</summary>
/// <param name="Version">Version of which to determine the group</param>
/// <returns>Version Group Identifier or Invalid if type cannot be determined.</returns>
public static GameVersion getMetLocationVersionGroup(GameVersion Version)
public static GameVersion GetMetLocationVersionGroup(GameVersion Version)
{
switch (Version)
{
@ -80,7 +80,7 @@
/// </summary>
/// <param name="generation">Generation ID</param>
/// <returns>Version ID from requested generation. If none, return Unknown.</returns>
public static GameVersion getVersion(int generation)
public static GameVersion GetVersion(int generation)
{
switch (generation)
{

View file

@ -49,7 +49,7 @@
VCEvents
}
public static class Extension
public static partial class Extensions
{
public static bool Contains(this GameVersion g1, GameVersion g2)
{

View file

@ -15,7 +15,7 @@ namespace PKHeX.Core
private IEncounterable EncounterMatch => info.EncounterMatch;
private Type Type; // Parent class when applicable (EncounterStatic / MysteryGift)
private Type MatchedType; // Child class if applicable (WC6, PGF, etc)
private string EncounterName => Legal.getEncounterTypeName(EncounterOriginalGB ?? EncounterMatch) + $" ({specieslist[EncounterMatch.Species]})";
private string EncounterName => Legal.GetEncounterTypeName(EncounterOriginalGB ?? EncounterMatch) + $" ({SpeciesStrings[EncounterMatch.Species]})";
private CheckResult Encounter, History;
// private bool SecondaryChecked;
@ -25,7 +25,7 @@ namespace PKHeX.Core
public LegalInfo info;
public bool ParsedValid => Parsed && Valid;
public bool ParsedInvalid => Parsed && !Valid;
public string Report(bool verbose = false) => verbose ? getVerboseLegalityReport() : getLegalityReport();
public string Report(bool verbose = false) => verbose ? GetVerboseLegalityReport() : GetLegalityReport();
private IEnumerable<int> AllSuggestedMoves
{
get
@ -34,7 +34,7 @@ namespace PKHeX.Core
return _allSuggestedMoves;
if (Error || pkm == null || !pkm.IsOriginValid)
return new int[4];
return _allSuggestedMoves = getSuggestedMoves(true, true, true);
return _allSuggestedMoves = GetSuggestedMoves(true, true, true);
}
}
private IEnumerable<int> AllSuggestedRelearnMoves
@ -47,7 +47,7 @@ namespace PKHeX.Core
return new int[4];
var gender = pkm.PersonalInfo.Gender;
var inheritLvlMoves = gender > 0 && gender < 255 || Legal.MixedGenderBreeding.Contains(info.EncounterMatch.Species);
return _allSuggestedRelearnMoves = Legal.getValidRelearn(pkm, info.EncounterMatch.Species, inheritLvlMoves).ToArray();
return _allSuggestedRelearnMoves = Legal.GetValidRelearn(pkm, info.EncounterMatch.Species, inheritLvlMoves).ToArray();
}
}
private int[] _allSuggestedMoves, _allSuggestedRelearnMoves;
@ -59,34 +59,34 @@ namespace PKHeX.Core
{
switch (pk.Format) // prior to storing GameVersion
{
case 1: parsePK1(pk); break;
case 2: parsePK1(pk); break;
case 1: ParsePK1(pk); break;
case 2: ParsePK1(pk); break;
}
if (!Parse.Any())
switch (pk.GenNumber)
{
case 3: parsePK3(pk); break;
case 4: parsePK4(pk); break;
case 5: parsePK5(pk); break;
case 6: parsePK6(pk); break;
case 3: ParsePK3(pk); break;
case 4: ParsePK4(pk); break;
case 5: ParsePK5(pk); break;
case 6: ParsePK6(pk); break;
case 1: parsePK7(pk); break;
case 7: parsePK7(pk); break;
case 1: ParsePK7(pk); break;
case 7: ParsePK7(pk); break;
}
if (Parse.Count > 0)
{
if (Parse.Any(chk => !chk.Valid))
Valid = false;
else if (info.vMoves.Any(m => m.Valid != true))
else if (info.Moves.Any(m => m.Valid != true))
Valid = false;
else if (info.vRelearn.Any(m => m.Valid != true))
else if (info.Relearn.Any(m => m.Valid != true))
Valid = false;
else
Valid = true;
if (pkm.FatefulEncounter && info.vRelearn.Any(chk => !chk.Valid) && EncounterMatch == null)
if (pkm.FatefulEncounter && info.Relearn.Any(chk => !chk.Valid) && EncounterMatch == null)
AddLine(Severity.Indeterminate, V188, CheckIdentifier.Fateful);
}
}
@ -110,95 +110,95 @@ namespace PKHeX.Core
Parse.Add(chk);
}
private void parsePK1(PKM pk)
private void ParsePK1(PKM pk)
{
pkm = pk;
if (!pkm.IsOriginValid)
{ AddLine(Severity.Invalid, V187, CheckIdentifier.None); return; }
updateTradebackG12();
UpdateTradebackG12();
updateInfo();
updateTypeInfo();
UpdateInfo();
UpdateTypeInfo();
if (pk.Format > 2) // transferred
{
EncounterOriginalGB = EncounterMatch;
foreach (var z in verifyVCEncounter(pkm, EncounterMatch.Species, EncounterMatch as GBEncounterData))
foreach (var z in VerifyVCEncounter(pkm, EncounterMatch.Species, EncounterMatch as GBEncounterData))
AddLine(z);
}
verifyNickname();
verifyDVs();
verifyG1OT();
verifyMiscG1();
VerifyNickname();
VerifyDVs();
VerifyG1OT();
VerifyMiscG1();
}
private void parsePK3(PKM pk)
private void ParsePK3(PKM pk)
{
pkm = pk;
if (!pkm.IsOriginValid)
{ AddLine(Severity.Invalid, V187, CheckIdentifier.None); return; }
updateInfo();
updateTypeInfo();
updateChecks();
UpdateInfo();
UpdateTypeInfo();
UpdateChecks();
if (pkm.Format > 3)
verifyTransferLegalityG3();
VerifyTransferLegalityG3();
if (pkm.Version == 15)
verifyCXD();
VerifyCXD();
if (info.EncounterMatch is WC3 z && z.NotDistributed)
AddLine(Severity.Invalid, V413, CheckIdentifier.Encounter);
}
private void parsePK4(PKM pk)
private void ParsePK4(PKM pk)
{
pkm = pk;
if (!pkm.IsOriginValid)
{ AddLine(Severity.Invalid, V187, CheckIdentifier.None); return; }
updateInfo();
updateTypeInfo();
updateChecks();
UpdateInfo();
UpdateTypeInfo();
UpdateChecks();
if (pkm.Format > 4)
verifyTransferLegalityG4();
VerifyTransferLegalityG4();
}
private void parsePK5(PKM pk)
private void ParsePK5(PKM pk)
{
pkm = pk;
if (!pkm.IsOriginValid)
{ AddLine(Severity.Invalid, V187, CheckIdentifier.None); return; }
updateInfo();
updateTypeInfo();
updateChecks();
UpdateInfo();
UpdateTypeInfo();
UpdateChecks();
}
private void parsePK6(PKM pk)
private void ParsePK6(PKM pk)
{
pkm = pk;
if (!pkm.IsOriginValid)
{ AddLine(Severity.Invalid, V187, CheckIdentifier.None); return; }
updateInfo();
updateTypeInfo();
updateChecks();
UpdateInfo();
UpdateTypeInfo();
UpdateChecks();
}
private void parsePK7(PKM pk)
private void ParsePK7(PKM pk)
{
pkm = pk;
if (!pkm.IsOriginValid)
{ AddLine(Severity.Invalid, V187, CheckIdentifier.None); return; }
updateInfo();
updateTypeInfo();
updateChecks();
UpdateInfo();
UpdateTypeInfo();
UpdateChecks();
}
private void updateInfo()
private void UpdateInfo()
{
info = EncounterFinder.verifyEncounter(pkm);
info = EncounterFinder.FindVerifiedEncounter(pkm);
Encounter = info.Parse[0];
Parse.AddRange(info.Parse);
}
private void updateTradebackG12()
private void UpdateTradebackG12()
{
if (pkm.Format == 1)
{
@ -213,7 +213,7 @@ namespace PKHeX.Core
var catch_rate = ((PK1)pkm).Catch_Rate;
// For species catch rate, discard any species that has no valid encounters and a different catch rate than their pre-evolutions
var Lineage = Legal.getLineage(pkm).Where(s => !Legal.Species_NotAvailable_CatchRate.Contains(s)).ToList();
var Lineage = Legal.GetLineage(pkm).Where(s => !Legal.Species_NotAvailable_CatchRate.Contains(s)).ToList();
// Dragonite's Catch Rate is different than Dragonair's in Yellow, but there is no Dragonite encounter.
var RGBCatchRate = Lineage.Any(s => catch_rate == PersonalTable.RB[s].CatchRate);
var YCatchRate = Lineage.Any(s => s != 149 && catch_rate == PersonalTable.Y[s].CatchRate);
@ -254,14 +254,14 @@ namespace PKHeX.Core
pkm.TradebackStatus = TradebackType.Any;
}
}
private void updateTypeInfo()
private void UpdateTypeInfo()
{
if (pkm.Format >= 7)
{
if (pkm.VC1)
info.EncounterMatch = EncounterGenerator.getRBYStaticTransfer(pkm.Species);
info.EncounterMatch = EncounterGenerator.GetRBYStaticTransfer(pkm.Species);
else if (pkm.VC2)
info.EncounterMatch = EncounterGenerator.getGSStaticTransfer(pkm.Species);
info.EncounterMatch = EncounterGenerator.GetGSStaticTransfer(pkm.Species);
}
if (pkm.GenNumber <= 2 && pkm.TradebackStatus == TradebackType.Any && (EncounterMatch as GBEncounterData)?.Generation != pkm.GenNumber)
@ -273,67 +273,67 @@ namespace PKHeX.Core
if (bt != null && !(bt == typeof(Array) || bt == typeof(object) || bt.GetTypeInfo().IsPrimitive)) // a parent exists
Type = bt; // use base type
}
private void updateChecks()
private void UpdateChecks()
{
verifyECPID();
verifyNickname();
verifyOT();
verifyIVs();
verifyEVs();
verifyLevel();
verifyRibbons();
verifyAbility();
verifyBall();
verifyForm();
verifyMisc();
verifyGender();
verifyItem();
VerifyECPID();
VerifyNickname();
VerifyOT();
VerifyIVs();
VerifyEVs();
VerifyLevel();
VerifyRibbons();
VerifyAbility();
VerifyBall();
VerifyForm();
VerifyMisc();
VerifyGender();
VerifyItem();
if (pkm.Format >= 4)
verifyEncounterType();
VerifyEncounterType();
if (pkm.Format >= 6)
{
History = verifyHistory();
History = VerifyHistory();
AddLine(History);
verifyOTMemory();
verifyHTMemory();
verifyHyperTraining();
verifyMedals();
verifyRegion();
verifyVersionEvolution();
VerifyOTMemory();
VerifyHTMemory();
VerifyHyperTraining();
VerifyMedals();
VerifyRegion();
VerifyVersionEvolution();
}
// SecondaryChecked = true;
}
private string getLegalityReport()
private string GetLegalityReport()
{
if (!Parsed || pkm == null)
return V189;
var lines = new List<string>();
var vMoves = info.vMoves;
var vRelearn = info.vRelearn;
var vMoves = info.Moves;
var vRelearn = info.Relearn;
for (int i = 0; i < 4; i++)
if (!vMoves[i].Valid)
lines.Add(string.Format(V191, getString(vMoves[i].Judgement), i + 1, vMoves[i].Comment));
lines.Add(string.Format(V191, vMoves[i].Judgement.Description(), i + 1, vMoves[i].Comment));
if (pkm.Format >= 6)
for (int i = 0; i < 4; i++)
if (!vRelearn[i].Valid)
lines.Add(string.Format(V192, getString(vRelearn[i].Judgement), i + 1, vRelearn[i].Comment));
lines.Add(string.Format(V192, vRelearn[i].Judgement.Description(), i + 1, vRelearn[i].Comment));
if (lines.Count == 0 && Parse.All(chk => chk.Valid) && Valid)
return V193;
// Build result string...
var outputLines = Parse.Where(chk => !chk.Valid); // Only invalid
lines.AddRange(outputLines.Select(chk => string.Format(V196, getString(chk.Judgement), chk.Comment)));
lines.AddRange(outputLines.Select(chk => string.Format(V196, chk.Judgement.Description(), chk.Comment)));
if (lines.Count == 0)
return V190;
return string.Join(Environment.NewLine, lines);
}
private string getVerboseLegalityReport()
private string GetVerboseLegalityReport()
{
if (!Parsed)
return V189;
@ -344,22 +344,22 @@ namespace PKHeX.Core
lines.AddRange(br);
int rl = lines.Count;
var vMoves = info.vMoves;
var vRelearn = info.vRelearn;
var vMoves = info.Moves;
var vRelearn = info.Relearn;
for (int i = 0; i < 4; i++)
if (vMoves[i].Valid)
lines.Add(string.Format(V191, getString(vMoves[i].Judgement), i + 1, vMoves[i].Comment));
lines.Add(string.Format(V191, vMoves[i].Judgement.Description(), i + 1, vMoves[i].Comment));
if (pkm.Format >= 6)
for (int i = 0; i < 4; i++)
if (vRelearn[i].Valid)
lines.Add(string.Format(V192, getString(vRelearn[i].Judgement), i + 1, vRelearn[i].Comment));
lines.Add(string.Format(V192, vRelearn[i].Judgement.Description(), i + 1, vRelearn[i].Comment));
if (rl != lines.Count) // move info added, break for next section
lines.Add(br[1]);
var outputLines = Parse.Where(chk => chk != null && chk.Valid && chk.Comment != V).OrderBy(chk => chk.Judgement); // Fishy sorted to top
lines.AddRange(outputLines.Select(chk => string.Format(V196, getString(chk.Judgement), chk.Comment)));
lines.AddRange(outputLines.Select(chk => string.Format(V196, chk.Judgement.Description(), chk.Comment)));
lines.AddRange(br);
lines.Add(string.Format(V195, EncounterName));
@ -371,10 +371,10 @@ namespace PKHeX.Core
lines.Add(string.Format(V249, pidiv.Type));
}
return getLegalityReport() + string.Join(Environment.NewLine, lines);
return GetLegalityReport() + string.Join(Environment.NewLine, lines);
}
public int[] getSuggestedRelearn()
public int[] GetSuggestedRelearn()
{
if (info.RelearnBase == null || pkm.GenNumber < 6 || !pkm.IsOriginValid)
return new int[4];
@ -383,28 +383,28 @@ namespace PKHeX.Core
return info.RelearnBase;
List<int> window = new List<int>(info.RelearnBase);
var vMoves = info.vMoves;
var vMoves = info.Moves;
window.AddRange(pkm.Moves.Where((v, i) => !vMoves[i].Valid || vMoves[i].Flag));
window = window.Distinct().ToList();
if (window.Count < 4)
window.AddRange(new int[4 - window.Count]);
return window.Skip(window.Count - 4).ToArray();
}
public int[] getSuggestedMoves(bool tm, bool tutor, bool reminder)
public int[] GetSuggestedMoves(bool tm, bool tutor, bool reminder)
{
if (pkm == null || !pkm.IsOriginValid)
return null;
if (!Parsed)
return new int[4];
return Legal.getValidMoves(pkm, info.EvoChainsAllGens, Tutor: tutor, Machine: tm, MoveReminder: reminder).Skip(1).ToArray(); // skip move 0
return Legal.GetValidMoves(pkm, info.EvoChainsAllGens, Tutor: tutor, Machine: tm, MoveReminder: reminder).Skip(1).ToArray(); // skip move 0
}
public EncounterStatic getSuggestedMetInfo()
public EncounterStatic GetSuggestedMetInfo()
{
if (pkm == null)
return null;
int loc = getSuggestedTransferLocation(pkm);
int loc = GetSuggestedTransferLocation(pkm);
if (pkm.WasEgg)
{
int lvl = 1; // gen5+
@ -414,13 +414,13 @@ namespace PKHeX.Core
lvl = 0;
return new EncounterStatic
{
Species = Legal.getBaseSpecies(pkm),
Location = loc != -1 ? loc : getSuggestedEggMetLocation(pkm),
Species = Legal.GetBaseSpecies(pkm),
Location = loc != -1 ? loc : GetSuggestedEggMetLocation(pkm),
Level = lvl,
};
}
var area = EncounterGenerator.getCaptureLocation(pkm);
var area = EncounterGenerator.GetCaptureLocation(pkm);
if (area != null)
{
var slots = area.Slots.OrderBy(s => s.LevelMin);
@ -432,12 +432,12 @@ namespace PKHeX.Core
};
}
var encounter = EncounterGenerator.getStaticLocation(pkm);
var encounter = EncounterGenerator.GetStaticLocation(pkm);
if (loc != -1 && encounter != null)
encounter.Location = loc;
return encounter;
}
private static int getSuggestedEggMetLocation(PKM pkm)
private static int GetSuggestedEggMetLocation(PKM pkm)
{
// Return one of legal hatch locations for game
switch ((GameVersion)pkm.Version)
@ -482,7 +482,7 @@ namespace PKHeX.Core
}
return -1;
}
private static int getSuggestedTransferLocation(PKM pkm)
private static int GetSuggestedTransferLocation(PKM pkm)
{
// Return one of legal hatch locations for game
if (pkm.HasOriginalMetLocation)

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -4,7 +4,7 @@ namespace PKHeX.Core
{
public static class Data
{
public static byte[][] unpackMini(byte[] fileData, string identifier)
public static byte[][] UnpackMini(byte[] fileData, string identifier)
{
if (fileData == null || fileData.Length < 4)
return null;

View file

@ -6,61 +6,63 @@ namespace PKHeX.Core
{
public static class EncounterFinder
{
public static LegalInfo verifyEncounter(PKM pkm)
public static LegalInfo FindVerifiedEncounter(PKM pkm)
{
LegalInfo info = new LegalInfo(pkm);
var encounters = EncounterGenerator.getEncounters(pkm, info);
var encounters = EncounterGenerator.GetEncounters(pkm, info);
using (var encounter = new PeekEnumerator<IEncounterable>(encounters.GetEnumerator()))
{
if (!encounter.PeekIsNext())
return verifyWithoutEncounter(pkm, info);
{ return VerifyWithoutEncounter(pkm, info);}
var EncounterValidator = getEncounterVerifier(pkm);
var EncounterValidator = GetEncounterVerifierMethod(pkm);
while (encounter.MoveNext())
{
var EncounterMatch = info.EncounterMatch = encounter.Current;
bool PIDMatch = info.PIDIVMatches;
var EncounterMatch = info.EncounterMatch = encounter.Current;
var e = EncounterValidator(pkm, EncounterMatch);
if (!e.Valid && encounter.PeekIsNext())
continue;
info.Parse.Add(e);
if (pkm.Format >= 6)
{
info.vRelearn = VerifyRelearnMoves.verifyRelearn(pkm, info);
if (info.vRelearn.Any(z => !z.Valid) && encounter.PeekIsNext())
continue;
}
else
for (int i = 0; i < 4; i++)
info.vRelearn[i] = new CheckResult(CheckIdentifier.RelearnMove);
info.vMoves = VerifyCurrentMoves.verifyMoves(pkm, info);
if (info.vMoves.Any(z => !z.Valid) && encounter.PeekIsNext())
continue;
var evo = VerifyEvolution.verifyEvolution(pkm, info);
if (!evo.Valid && encounter.PeekIsNext())
continue;
info.Parse.Add(evo);
if (!PIDMatch)
{
if (encounter.PeekIsNext())
continue;
info.Parse.Add(new CheckResult(Severity.Invalid, V411, CheckIdentifier.PID));
}
// Encounter Passes
break;
if (VerifySecondaryChecks(pkm, info, PIDMatch, encounter))
break; // passes
}
return info;
}
}
private static LegalInfo verifyWithoutEncounter(PKM pkm, LegalInfo info)
private static bool VerifySecondaryChecks(PKM pkm, LegalInfo info, bool PIDMatch, PeekEnumerator<IEncounterable> iterator)
{
if (pkm.Format >= 6)
{
info.Relearn = VerifyRelearnMoves.VerifyRelearn(pkm, info);
if (info.Relearn.Any(z => !z.Valid) && iterator.PeekIsNext())
return false;
}
else
for (int i = 0; i < 4; i++)
info.Relearn[i] = new CheckResult(CheckIdentifier.RelearnMove);
info.Moves = VerifyCurrentMoves.VerifyMoves(pkm, info);
if (info.Moves.Any(z => !z.Valid) && iterator.PeekIsNext())
return false;
var evo = EvolutionVerifier.VerifyEvolution(pkm, info);
if (!evo.Valid && iterator.PeekIsNext())
return false;
info.Parse.Add(evo);
if (!PIDMatch)
{
if (iterator.PeekIsNext())
return false; // continue to next
info.Parse.Add(new CheckResult(Severity.Invalid, V411, CheckIdentifier.PID));
}
return true;
}
private static LegalInfo VerifyWithoutEncounter(PKM pkm, LegalInfo info)
{
info.EncounterMatch = new EncounterInvalid(pkm);
@ -75,20 +77,19 @@ namespace PKHeX.Core
hint = V80;
info.Parse.Add(new CheckResult(Severity.Invalid, hint, CheckIdentifier.Encounter));
info.vRelearn = VerifyRelearnMoves.verifyRelearn(pkm, info);
info.vMoves = VerifyCurrentMoves.verifyMoves(pkm, info);
info.Relearn = VerifyRelearnMoves.VerifyRelearn(pkm, info);
info.Moves = VerifyCurrentMoves.VerifyMoves(pkm, info);
return info;
}
private static Func<PKM, IEncounterable, CheckResult> getEncounterVerifier(PKM pkm)
private static Func<PKM, IEncounterable, CheckResult> GetEncounterVerifierMethod(PKM pkm)
{
switch (pkm.GenNumber)
{
case 1:
case 2:
return VerifyEncounter.verifyEncounterG12;
return EncounterVerifier.VerifyEncounterG12;
default:
return VerifyEncounter.verifyEncounter;
return EncounterVerifier.VerifyEncounter;
}
}
}

View file

@ -7,23 +7,23 @@ namespace PKHeX.Core
{
public static class EncounterGenerator
{
public static IEnumerable<IEncounterable> getEncounters(PKM pkm, LegalInfo info)
public static IEnumerable<IEncounterable> GetEncounters(PKM pkm, LegalInfo info)
{
switch (info.Generation)
{
case 1:
case 2:
foreach (var enc in getEncounters12(pkm, info))
foreach (var enc in GetEncounters12(pkm, info))
yield return enc;
yield break;
case 3:
// info.PIDIV = MethodFinder.Analyze(pkm);
foreach (var enc in getEncounters3(pkm, info))
foreach (var enc in GetEncounters3(pkm, info))
yield return enc;
yield break;
case 4:
// info.PIDIV = MethodFinder.Analyze(pkm);
foreach (var enc in getEncounters4(pkm, info))
foreach (var enc in GetEncounters4(pkm, info))
yield return enc;
yield break;
default:
@ -33,9 +33,9 @@ namespace PKHeX.Core
}
}
private static IEnumerable<IEncounterable> getEncounters12(PKM pkm, LegalInfo info)
private static IEnumerable<IEncounterable> GetEncounters12(PKM pkm, LegalInfo info)
{
int baseSpecies = getBaseSpecies(pkm);
int baseSpecies = GetBaseSpecies(pkm);
bool g1 = pkm.VC1 || pkm.Format == 1;
if (g1 && baseSpecies > MaxSpeciesID_1 || baseSpecies > MaxSpeciesID_2)
@ -48,14 +48,14 @@ namespace PKHeX.Core
yield return z.Encounter;
}
}
private static IEnumerable<IEncounterable> getEncounters3(PKM pkm, LegalInfo info)
private static IEnumerable<IEncounterable> GetEncounters3(PKM pkm, LegalInfo info)
{
info.PIDIV = MethodFinder.Analyze(pkm);
var deferred = new List<IEncounterable>();
foreach (var z in GenerateRawEncounters3(pkm))
{
if (z is EncounterSlot w && pkm.Version == 15)
info.PIDIV = MethodFinder.getPokeSpotSeeds(pkm, w.SlotNumber).FirstOrDefault() ?? info.PIDIV;
info.PIDIV = MethodFinder.GetPokeSpotSeeds(pkm, w.SlotNumber).FirstOrDefault() ?? info.PIDIV;
if (info.PIDIV.Type.IsCompatible3(z, pkm))
yield return z;
else
@ -65,7 +65,7 @@ namespace PKHeX.Core
foreach (var z in deferred)
yield return z;
}
private static IEnumerable<IEncounterable> getEncounters4(PKM pkm, LegalInfo info)
private static IEnumerable<IEncounterable> GetEncounters4(PKM pkm, LegalInfo info)
{
info.PIDIV = MethodFinder.Analyze(pkm);
var deferred = new List<IEncounterable>();
@ -88,15 +88,15 @@ namespace PKHeX.Core
// Calculate all 3 at the same time and pick the best result (by species).
// Favor special event move gifts as Static Encounters when applicable
var maxspeciesorigin = game == GameVersion.GSC ? MaxSpeciesID_2 : MaxSpeciesID_1;
DexLevel[] vs = getValidPreEvolutions(pkm, maxspeciesorigin: maxspeciesorigin).ToArray();
DexLevel[] vs = GetValidPreEvolutions(pkm, maxspeciesorigin: maxspeciesorigin).ToArray();
HashSet<int> species = new HashSet<int>(vs.Select(p => p.Species).ToList());
var deferred = new List<IEncounterable>();
foreach (var t in getValidEncounterTrade(pkm, game))
foreach (var t in GetValidEncounterTrades(pkm, game))
{
yield return new GBEncounterData(pkm, gen, t, game);
}
foreach (var s in getValidStaticEncounter(pkm, game))
foreach (var s in GetValidStaticEncounter(pkm, game))
{
// Valid stadium and non-stadium encounters, return only non-stadium encounters, they are less restrictive
if (!species.Contains(s.Species))
@ -108,7 +108,7 @@ namespace PKHeX.Core
}
yield return new GBEncounterData(pkm, gen, s, game);
}
foreach (var e in getValidWildEncounters(pkm, game))
foreach (var e in GetValidWildEncounters(pkm, game))
{
if (!species.Contains(e.Species))
continue;
@ -117,7 +117,7 @@ namespace PKHeX.Core
if (game == GameVersion.GSC || game == GameVersion.C)
{
bool WasEgg = !pkm.Gen1_NotTradeback && getWasEgg23(pkm) && !NoHatchFromEgg.Contains(pkm.Species);
bool WasEgg = !pkm.Gen1_NotTradeback && GetWasEgg23(pkm) && !NoHatchFromEgg.Contains(pkm.Species);
if (WasEgg)
{
// Further Filtering
@ -129,7 +129,7 @@ namespace PKHeX.Core
}
if (WasEgg)
{
int eggspec = getBaseEggSpecies(pkm);
int eggspec = GetBaseEggSpecies(pkm);
if (AllowGen2Crystal)
yield return new GBEncounterData(eggspec, GameVersion.C); // gen2 egg
yield return new GBEncounterData(eggspec, GameVersion.GS); // gen2 egg
@ -159,7 +159,7 @@ namespace PKHeX.Core
move = g2i;
var obj = move.Peek();
if (obj.Generation == 1 && obj.Encounter is EncounterTrade && !getEncounterTrade1Valid(pkm))
if (obj.Generation == 1 && obj.Encounter is EncounterTrade && !IsEncounterTrade1Valid(pkm))
deferred.Add(obj);
else
yield return obj;
@ -187,34 +187,34 @@ namespace PKHeX.Core
int ctr = 0;
if (pkm.WasLink)
{
foreach (var z in getValidLinkGifts(pkm))
foreach (var z in GetValidLinkGifts(pkm))
{ yield return z; ++ctr; }
if (ctr != 0) yield break;
}
if (pkm.WasEvent || pkm.WasEventEgg)
{
foreach (var z in getValidGifts(pkm))
foreach (var z in GetValidGifts(pkm))
{ yield return z; ++ctr; }
if (ctr != 0) yield break;
}
if (pkm.WasEgg)
{
foreach (var z in generateEggs(pkm))
foreach (var z in GenerateEggs(pkm))
yield return z;
}
foreach (var z in getValidStaticEncounter(pkm))
foreach (var z in GetValidStaticEncounter(pkm))
{ yield return z; ++ctr; }
if (ctr != 0) yield break;
foreach (var z in getValidFriendSafari(pkm))
foreach (var z in GetValidFriendSafari(pkm))
{ yield return z; ++ctr; }
if (ctr != 0) yield break;
foreach (var z in getValidWildEncounters(pkm))
foreach (var z in GetValidWildEncounters(pkm))
{ yield return z; ++ctr; }
if (ctr != 0) yield break;
foreach (var z in getValidEncounterTrade(pkm))
foreach (var z in GetValidEncounterTrades(pkm))
{ yield return z; ++ctr; }
// if (ctr != 0) yield break;
}
@ -224,61 +224,61 @@ namespace PKHeX.Core
bool wasEvent = pkm.WasEvent || pkm.WasEventEgg; // egg events?
if (wasEvent)
{
foreach (var z in getValidGifts(pkm))
foreach (var z in GetValidGifts(pkm))
{ yield return z; ++ctr; }
if (ctr != 0) yield break;
}
if (pkm.WasEgg)
{
foreach (var z in generateEggs(pkm))
foreach (var z in GenerateEggs(pkm))
{ yield return z; ++ctr; }
}
bool safariSport = pkm.Ball == 0x05 || pkm.Ball == 0x18; // never static encounters
if (!safariSport)
foreach (var z in getValidStaticEncounter(pkm))
foreach (var z in GetValidStaticEncounter(pkm))
{ yield return z; ++ctr; }
if (ctr != 0) yield break;
foreach (var z in getValidFriendSafari(pkm))
foreach (var z in GetValidFriendSafari(pkm))
{ yield return z; ++ctr; }
if (ctr != 0) yield break;
foreach (var z in getValidWildEncounters(pkm))
foreach (var z in GetValidWildEncounters(pkm))
{ yield return z; ++ctr; }
if (ctr != 0) yield break;
foreach (var z in getValidEncounterTrade(pkm))
foreach (var z in GetValidEncounterTrades(pkm))
{ yield return z; ++ctr; }
if (ctr != 0) yield break;
// do static encounters if they were deferred to end, spit out any possible encounters for invalid pkm
if (safariSport)
foreach (var z in getValidStaticEncounter(pkm))
foreach (var z in GetValidStaticEncounter(pkm))
yield return z;
}
private static IEnumerable<IEncounterable> GenerateRawEncounters3(PKM pkm)
{
foreach (var z in getValidGifts(pkm))
foreach (var z in GetValidGifts(pkm))
yield return z;
bool safari = pkm.Ball == 0x05; // never static encounters
if (!safari)
foreach (var z in getValidStaticEncounter(pkm))
foreach (var z in GetValidStaticEncounter(pkm))
yield return z;
foreach (var z in getValidFriendSafari(pkm))
foreach (var z in GetValidFriendSafari(pkm))
yield return z;
foreach (var z in getValidWildEncounters(pkm))
foreach (var z in GetValidWildEncounters(pkm))
yield return z;
foreach (var z in getValidEncounterTrade(pkm))
foreach (var z in GetValidEncounterTrades(pkm))
yield return z;
// do static encounters if they were deferred to end, spit out any possible encounters for invalid pkm
if (safari)
foreach (var z in getValidStaticEncounter(pkm))
foreach (var z in GetValidStaticEncounter(pkm))
yield return z;
if (pkm.Version == 15)
yield break; // no eggs in C/XD
foreach (var z in generateEggs(pkm))
foreach (var z in GenerateEggs(pkm))
yield return z;
}
@ -288,20 +288,20 @@ namespace PKHeX.Core
return type == 0 && !(e is EncounterStaticTyped)
|| e is EncounterStaticTyped t && t.TypeEncounter.Contains(type);
}
private static IEnumerable<EncounterStatic> getValidStaticEncounter(PKM pkm, GameVersion gameSource = GameVersion.Any)
private static IEnumerable<EncounterStatic> GetValidStaticEncounter(PKM pkm, GameVersion gameSource = GameVersion.Any)
{
if (gameSource == GameVersion.Any)
gameSource = (GameVersion)pkm.Version;
// Get possible encounters
IEnumerable<EncounterStatic> poss = getStaticEncounters(pkm, gameSource: gameSource);
IEnumerable<EncounterStatic> poss = GetStaticEncounters(pkm, gameSource: gameSource);
int lvl = getMinLevelEncounter(pkm);
int lvl = GetMinLevelEncounter(pkm);
if (lvl <= 0)
yield break;
// Back Check against pkm
var enc = getMatchingStaticEncounters(pkm, poss, lvl).ToList();
var enc = GetMatchingStaticEncounters(pkm, poss, lvl).ToList();
// Filter for encounter types; type is cleared on 6->7 transfer
if (!pkm.Gen4 || pkm.Format >= 7)
@ -327,7 +327,7 @@ namespace PKHeX.Core
foreach (var e in pass)
yield return e;
}
private static IEnumerable<EncounterStatic> getMatchingStaticEncounters(PKM pkm, IEnumerable<EncounterStatic> poss, int lvl)
private static IEnumerable<EncounterStatic> GetMatchingStaticEncounters(PKM pkm, IEnumerable<EncounterStatic> poss, int lvl)
{
foreach (EncounterStatic e in poss)
{
@ -393,7 +393,7 @@ namespace PKHeX.Core
continue;
if (e.Gender != -1 && e.Gender != pkm.Gender)
continue;
if (e.Form != pkm.AltForm && !e.SkipFormCheck && !getCanFormChange(pkm, e.Species))
if (e.Form != pkm.AltForm && !e.SkipFormCheck && !IsFormChangeable(pkm, e.Species))
continue;
if (e.EggLocation == 60002 && e.Relearn[0] == 0 && pkm.RelearnMoves.Any(z => z != 0)) // gen7 eevee edge case
continue;
@ -435,39 +435,39 @@ namespace PKHeX.Core
yield return e;
}
}
private static IEnumerable<EncounterStatic> getStaticEncounters(PKM pkm, int lvl = -1, GameVersion gameSource = GameVersion.Any)
private static IEnumerable<EncounterStatic> GetStaticEncounters(PKM pkm, int lvl = -1, GameVersion gameSource = GameVersion.Any)
{
if (gameSource == GameVersion.Any)
gameSource = (GameVersion)pkm.Version;
var table = getEncounterStaticTable(pkm, gameSource);
var table = GetEncounterStaticTable(pkm, gameSource);
switch (pkm.GenNumber)
{
case 1:
return getStatic(pkm, table, maxspeciesorigin: MaxSpeciesID_1, lvl: lvl);
return GetStatic(pkm, table, maxspeciesorigin: MaxSpeciesID_1, lvl: lvl);
case 2:
return getStatic(pkm, table, maxspeciesorigin: MaxSpeciesID_2, lvl: lvl);
return GetStatic(pkm, table, maxspeciesorigin: MaxSpeciesID_2, lvl: lvl);
default:
return getStatic(pkm, table, lvl);
return GetStatic(pkm, table, lvl);
}
}
private static IEnumerable<EncounterStatic> getStatic(PKM pkm, IEnumerable<EncounterStatic> table, int maxspeciesorigin = -1, int lvl = -1)
private static IEnumerable<EncounterStatic> GetStatic(PKM pkm, IEnumerable<EncounterStatic> table, int maxspeciesorigin = -1, int lvl = -1)
{
IEnumerable<DexLevel> dl = getValidPreEvolutions(pkm, maxspeciesorigin: maxspeciesorigin, lvl: lvl);
IEnumerable<DexLevel> dl = GetValidPreEvolutions(pkm, maxspeciesorigin: maxspeciesorigin, lvl: lvl);
return table.Where(e => dl.Any(d => d.Species == e.Species));
}
// EncounterSlot
private static IEnumerable<EncounterSlot> getRawEncounterSlots(PKM pkm, GameVersion gameSource = GameVersion.Any)
private static IEnumerable<EncounterSlot> GetRawEncounterSlots(PKM pkm, GameVersion gameSource = GameVersion.Any)
{
return getEncounterAreas(pkm, gameSource).SelectMany(area => getValidEncounterSlots(pkm, area, DexNav: pkm.AO, gameSource: gameSource));
return GetEncounterAreas(pkm, gameSource).SelectMany(area => GetValidEncounterSlots(pkm, area, DexNav: pkm.AO, gameSource: gameSource));
}
private static IEnumerable<EncounterSlot> getValidWildEncounters(PKM pkm, GameVersion gameSource = GameVersion.Any)
private static IEnumerable<EncounterSlot> GetValidWildEncounters(PKM pkm, GameVersion gameSource = GameVersion.Any)
{
if (gameSource == GameVersion.Any)
gameSource = (GameVersion)pkm.Version;
var s = getRawEncounterSlots(pkm, gameSource);
var s = GetRawEncounterSlots(pkm, gameSource);
bool IsSafariBall = pkm.Ball == 5;
bool IsSportsBall = pkm.Ball == 0x18;
bool IsHidden = pkm.AbilityNumber == 4; // hidden Ability
@ -478,7 +478,7 @@ namespace PKHeX.Core
var deferred = new List<EncounterSlot>();
foreach (EncounterSlot slot in s)
{
if (slot.Species == 265 && species != 265 && !getWurmpleEvoValid(pkm)) { } // bad wurmple evolution
if (slot.Species == 265 && species != 265 && !IsWurmpleEvoValid(pkm)) { } // bad wurmple evolution
else if (IsHidden ^ IsHiddenAbilitySlot(slot)) { } // ability mismatch
else if (IsSafariBall ^ IsSafariSlot(slot.Type)) { } // Safari Zone only ball
else if (IsSportsBall ^ slot.Type == SlotType.BugContest) { } // BCC only ball
@ -493,7 +493,7 @@ namespace PKHeX.Core
foreach (var d in deferred)
yield return d;
}
private static IEnumerable<EncounterSlot> getValidFriendSafari(PKM pkm)
private static IEnumerable<EncounterSlot> GetValidFriendSafari(PKM pkm)
{
if (!pkm.XY)
yield break;
@ -502,7 +502,7 @@ namespace PKHeX.Core
if (pkm.Met_Level != 30)
yield break;
IEnumerable<DexLevel> vs = getValidPreEvolutions(pkm);
IEnumerable<DexLevel> vs = GetValidPreEvolutions(pkm);
foreach (DexLevel d in vs.Where(d => FriendSafari.Contains(d.Species) && d.Level >= 30))
{
yield return new EncounterSlot
@ -515,7 +515,7 @@ namespace PKHeX.Core
};
}
}
private static IEnumerable<EncounterSlot> getValidEncounterSlots(PKM pkm, EncounterArea loc, bool DexNav, bool ignoreLevel = false, GameVersion gameSource = GameVersion.Any)
private static IEnumerable<EncounterSlot> GetValidEncounterSlots(PKM pkm, EncounterArea loc, bool DexNav, bool ignoreLevel = false, GameVersion gameSource = GameVersion.Any)
{
int fluteBoost = pkm.Format < 3 ? 0 : 4;
const int dexnavBoost = 30;
@ -529,7 +529,7 @@ namespace PKHeX.Core
if (GameVersion.GSC.Contains(gameSource)) maxspeciesorigin = MaxSpeciesID_2;
// Get Valid levels
IEnumerable<DexLevel> vs = getValidPreEvolutions(pkm, maxspeciesorigin: maxspeciesorigin, lvl: ignoreLevel ? 100 : -1, skipChecks: ignoreLevel);
IEnumerable<DexLevel> vs = GetValidPreEvolutions(pkm, maxspeciesorigin: maxspeciesorigin, lvl: ignoreLevel ? 100 : -1, skipChecks: ignoreLevel);
bool IsRGBKadabra = false;
if (pkm.Format == 1 && pkm.Gen1_NotTradeback)
@ -555,7 +555,7 @@ namespace PKHeX.Core
bool ignoreSlotLevel = ignoreLevel;
IEnumerable<EncounterSlot> slots = loc.Slots.Where(slot => vs.Any(evo => evo.Species == slot.Species && (ignoreSlotLevel || evo.Level >= slot.LevelMin - df)));
int lvl = getMinLevelEncounter(pkm);
int lvl = GetMinLevelEncounter(pkm);
if (lvl <= 0)
return slotdata;
int gen = pkm.GenNumber;
@ -564,7 +564,7 @@ namespace PKHeX.Core
if (ignoreLevel)
encounterSlots = slots.ToList();
else if (pkm.HasOriginalMetLocation)
encounterSlots = slots.Where(slot => slot.LevelMin - df <= lvl && lvl <= slot.LevelMax + (slot.AllowDexNav ? dn : df)).ToList();
encounterSlots = slots.Where(slot => slot.LevelMin - df <= lvl && lvl <= slot.LevelMax + (slot.Permissions.AllowDexNav ? dn : df)).ToList();
else // check for any less than current level
encounterSlots = slots.Where(slot => slot.LevelMin <= lvl).ToList();
@ -588,7 +588,7 @@ namespace PKHeX.Core
if (slotMax != null)
{
slotMax = slotMax.Clone();
slotMax.Pressure = true;
slotMax.Permissions.Pressure = true;
slotMax.Form = pkm.AltForm;
}
@ -613,40 +613,40 @@ namespace PKHeX.Core
eslots.Add(slotMax);
foreach (EncounterSlot s in eslots)
{
bool nav = s.AllowDexNav && (pkm.RelearnMove1 != 0 || pkm.AbilityNumber == 4);
bool nav = s.Permissions.AllowDexNav && (pkm.RelearnMove1 != 0 || pkm.AbilityNumber == 4);
EncounterSlot slot = s.Clone();
slot.DexNav = nav;
slot.Permissions.DexNav = nav;
if (slot.LevelMin > lvl)
slot.WhiteFlute = true;
slot.Permissions.WhiteFlute = true;
if (slot.LevelMax + 1 <= lvl && lvl <= slot.LevelMax + fluteBoost)
slot.BlackFlute = true;
if (slot.LevelMax != lvl && slot.AllowDexNav)
slot.DexNav = true;
slot.Permissions.BlackFlute = true;
if (slot.LevelMax != lvl && slot.Permissions.AllowDexNav)
slot.Permissions.DexNav = true;
slotdata.Add(slot);
}
return slotdata;
}
private static IEnumerable<EncounterArea> getEncounterSlots(PKM pkm, int lvl = -1, GameVersion gameSource = GameVersion.Any)
private static IEnumerable<EncounterArea> GetEncounterSlots(PKM pkm, int lvl = -1, GameVersion gameSource = GameVersion.Any)
{
if (gameSource == GameVersion.Any)
gameSource = (GameVersion)pkm.Version;
return getSlots(pkm, getEncounterTable(pkm, gameSource), lvl);
return GetSlots(pkm, GetEncounterTable(pkm, gameSource), lvl);
}
private static IEnumerable<EncounterArea> getEncounterAreas(PKM pkm, GameVersion gameSource = GameVersion.Any)
private static IEnumerable<EncounterArea> GetEncounterAreas(PKM pkm, GameVersion gameSource = GameVersion.Any)
{
if (gameSource == GameVersion.Any)
gameSource = (GameVersion)pkm.Version;
var slots = getEncounterSlots(pkm, gameSource: gameSource);
var slots = GetEncounterSlots(pkm, gameSource: gameSource);
bool noMet = !pkm.HasOriginalMetLocation || pkm.Format == 2 && gameSource != GameVersion.C;
return noMet ? slots : slots.Where(area => area.Location == pkm.Met_Location);
}
private static IEnumerable<EncounterArea> getSlots(PKM pkm, IEnumerable<EncounterArea> tables, int lvl = -1)
private static IEnumerable<EncounterArea> GetSlots(PKM pkm, IEnumerable<EncounterArea> tables, int lvl = -1)
{
IEnumerable<DexLevel> vs = getValidPreEvolutions(pkm, lvl: lvl);
IEnumerable<DexLevel> vs = GetValidPreEvolutions(pkm, lvl: lvl);
foreach (var loc in tables)
{
IEnumerable<EncounterSlot> slots = loc.Slots.Where(slot => vs.Any(evo => evo.Species == slot.Species));
@ -658,7 +658,7 @@ namespace PKHeX.Core
}
// EncounterLink
private static IEnumerable<EncounterLink> getValidLinkGifts(PKM pkm)
private static IEnumerable<EncounterLink> GetValidLinkGifts(PKM pkm)
{
switch (pkm.GenNumber)
{
@ -670,7 +670,7 @@ namespace PKHeX.Core
}
// EncounterTrade
private static EncounterTrade[] getEncounterTradeTable(PKM pkm)
private static EncounterTrade[] GetEncounterTradeTable(PKM pkm)
{
switch (pkm.GenNumber)
{
@ -687,26 +687,26 @@ namespace PKHeX.Core
}
return null;
}
private static IEnumerable<EncounterTrade> getValidEncounterTradeVC(PKM pkm, GameVersion gameSource)
private static IEnumerable<EncounterTrade> GetValidEncounterTradesVC(PKM pkm, GameVersion gameSource)
{
var p = getValidPreEvolutions(pkm).ToArray();
var p = GetValidPreEvolutions(pkm).ToArray();
switch (gameSource)
{
case GameVersion.RBY:
var table = !AllowGen1Tradeback ? TradeGift_RBY_NoTradeback : TradeGift_RBY_Tradeback;
return getValidEncounterTradeVC1(pkm, p, table);
return GetValidEncounterTradesVC1(pkm, p, table);
case GameVersion.GSC:
case GameVersion.C:
return getValidEncounterTradeVC2(pkm, p);
return GetValidEncounterTradesVC2(pkm, p);
default:
return null;
}
}
private static IEnumerable<EncounterTrade> getValidEncounterTradeVC2(PKM pkm, DexLevel[] p)
private static IEnumerable<EncounterTrade> GetValidEncounterTradesVC2(PKM pkm, DexLevel[] p)
{
// Check GSC trades. Reuse generic table fetch-match
var possible = getValidEncounterTradeVC1(pkm, p, TradeGift_GSC);
var possible = GetValidEncounterTradesVC1(pkm, p, TradeGift_GSC);
foreach (var z in possible)
{
@ -727,7 +727,7 @@ namespace PKHeX.Core
yield return z;
}
}
private static IEnumerable<EncounterTrade> getValidEncounterTradeVC1(PKM pkm, DexLevel[] p, IEnumerable<EncounterTrade> table)
private static IEnumerable<EncounterTrade> GetValidEncounterTradesVC1(PKM pkm, DexLevel[] p, IEnumerable<EncounterTrade> table)
{
var possible = table.Where(f => p.Any(r => r.Species == f.Species));
foreach (var z in possible)
@ -749,14 +749,14 @@ namespace PKHeX.Core
yield return z;
}
}
private static IEnumerable<EncounterTrade> getValidEncounterTrade(PKM pkm, GameVersion gameSource = GameVersion.Any)
private static IEnumerable<EncounterTrade> GetValidEncounterTrades(PKM pkm, GameVersion gameSource = GameVersion.Any)
{
if (gameSource == GameVersion.Any)
gameSource = (GameVersion)pkm.Version;
if (pkm.VC || pkm.Format <= 2)
{
foreach (var z in getValidEncounterTradeVC(pkm, gameSource))
foreach (var z in GetValidEncounterTradesVC(pkm, gameSource))
yield return z;
yield break;
}
@ -765,25 +765,25 @@ namespace PKHeX.Core
if (lang == 0 || lang == 6)
yield break;
int lvl = getMinLevelEncounter(pkm);
int lvl = GetMinLevelEncounter(pkm);
if (lvl <= 0)
yield break;
// Get valid pre-evolutions
IEnumerable<DexLevel> p = getValidPreEvolutions(pkm);
IEnumerable<DexLevel> p = GetValidPreEvolutions(pkm);
EncounterTrade[] table = getEncounterTradeTable(pkm);
EncounterTrade[] table = GetEncounterTradeTable(pkm);
if (table == null)
yield break;
var poss = table.Where(f => p.Any(r => r.Species == f.Species) && f.Version.Contains((GameVersion)pkm.Version));
foreach (var z in poss)
{
if (getEncounterTradeValid(pkm, z, lvl))
if (IsEncounterTradeValid(pkm, z, lvl))
yield return z;
}
}
private static bool getEncounterTradeValid(PKM pkm, EncounterTrade z, int lvl)
private static bool IsEncounterTradeValid(PKM pkm, EncounterTrade z, int lvl)
{
for (int i = 0; i < 6; i++)
if (z.IVs[i] != -1 && z.IVs[i] != pkm.IVs[i])
@ -824,31 +824,31 @@ namespace PKHeX.Core
}
// MysteryGift
private static IEnumerable<MysteryGift> getValidGifts(PKM pkm)
private static IEnumerable<MysteryGift> GetValidGifts(PKM pkm)
{
switch (pkm.GenNumber)
{
case 3:
return getMatchingWC3(pkm, MGDB_G3);
return GetMatchingWC3(pkm, MGDB_G3);
case 4:
return getMatchingPCD(pkm, MGDB_G4);
return GetMatchingPCD(pkm, MGDB_G4);
case 5:
return getMatchingPGF(pkm, MGDB_G5);
return GetMatchingPGF(pkm, MGDB_G5);
case 6:
return getMatchingWC6(pkm, MGDB_G6);
return GetMatchingWC6(pkm, MGDB_G6);
case 7:
return getMatchingWC7(pkm, MGDB_G7);
return GetMatchingWC7(pkm, MGDB_G7);
default:
return new List<MysteryGift>();
}
}
private static IEnumerable<MysteryGift> getMatchingWC3(PKM pkm, IEnumerable<MysteryGift> DB)
private static IEnumerable<MysteryGift> GetMatchingWC3(PKM pkm, IEnumerable<MysteryGift> DB)
{
if (DB == null)
yield break;
var validWC3 = new List<MysteryGift>();
var vs = getValidPreEvolutions(pkm, MaxSpeciesID_3).ToArray();
var vs = GetValidPreEvolutions(pkm, MaxSpeciesID_3).ToArray();
foreach (WC3 wc in DB.OfType<WC3>().Where(wc => vs.Any(dl => dl.Species == wc.Species)))
{
// Gen3 Version MUST match.
@ -896,7 +896,7 @@ namespace PKHeX.Core
foreach (var z in validWC3)
yield return z;
}
private static IEnumerable<MysteryGift> getMatchingPCD(PKM pkm, IEnumerable<MysteryGift> DB)
private static IEnumerable<MysteryGift> GetMatchingPCD(PKM pkm, IEnumerable<MysteryGift> DB)
{
if (DB == null)
yield break;
@ -912,7 +912,7 @@ namespace PKHeX.Core
}
var validPCD = new List<MysteryGift>();
var vs = getValidPreEvolutions(pkm).ToArray();
var vs = GetValidPreEvolutions(pkm).ToArray();
foreach (PCD mg in DB.OfType<PCD>().Where(wc => vs.Any(dl => dl.Species == wc.Species)))
{
var wc = mg.Gift.PK;
@ -925,7 +925,7 @@ namespace PKHeX.Core
if (wc.Version != 0 && wc.Version != pkm.Version) continue;
if (wc.Language != 0 && wc.Language != pkm.Language) continue;
}
if (wc.AltForm != pkm.AltForm && vs.All(dl => !getCanFormChange(pkm, dl.Species))) continue;
if (wc.AltForm != pkm.AltForm && vs.All(dl => !IsFormChangeable(pkm, dl.Species))) continue;
if (wc.IsEgg)
{
@ -974,13 +974,13 @@ namespace PKHeX.Core
foreach (var z in validPCD)
yield return z;
}
private static IEnumerable<MysteryGift> getMatchingPGF(PKM pkm, IEnumerable<MysteryGift> DB)
private static IEnumerable<MysteryGift> GetMatchingPGF(PKM pkm, IEnumerable<MysteryGift> DB)
{
if (DB == null)
yield break;
var validPGF = new List<MysteryGift>();
var vs = getValidPreEvolutions(pkm).ToArray();
var vs = GetValidPreEvolutions(pkm).ToArray();
foreach (PGF wc in DB.OfType<PGF>().Where(wc => vs.Any(dl => dl.Species == wc.Species)))
{
if (pkm.Egg_Location == 0) // Not Egg
@ -994,7 +994,7 @@ namespace PKHeX.Core
if (wc.OriginGame != 0 && wc.OriginGame != pkm.Version) continue;
if (wc.Language != 0 && wc.Language != pkm.Language) continue;
}
if (wc.Form != pkm.AltForm && vs.All(dl => !getCanFormChange(pkm, dl.Species))) continue;
if (wc.Form != pkm.AltForm && vs.All(dl => !IsFormChangeable(pkm, dl.Species))) continue;
if (wc.IsEgg)
{
@ -1034,12 +1034,12 @@ namespace PKHeX.Core
foreach (var z in validPGF)
yield return z;
}
private static IEnumerable<MysteryGift> getMatchingWC6(PKM pkm, IEnumerable<MysteryGift> DB)
private static IEnumerable<MysteryGift> GetMatchingWC6(PKM pkm, IEnumerable<MysteryGift> DB)
{
if (DB == null)
yield break;
List<MysteryGift> validWC6 = new List<MysteryGift>();
var vs = getValidPreEvolutions(pkm).ToArray();
var vs = GetValidPreEvolutions(pkm).ToArray();
foreach (WC6 wc in DB.OfType<WC6>().Where(wc => vs.Any(dl => dl.Species == wc.Species)))
{
if (pkm.Egg_Location == 0) // Not Egg
@ -1055,7 +1055,7 @@ namespace PKHeX.Core
if (wc.EncryptionConstant != 0 && wc.EncryptionConstant != pkm.EncryptionConstant) continue;
if (wc.Language != 0 && wc.Language != pkm.Language) continue;
}
if (wc.Form != pkm.AltForm && vs.All(dl => !getCanFormChange(pkm, dl.Species))) continue;
if (wc.Form != pkm.AltForm && vs.All(dl => !IsFormChangeable(pkm, dl.Species))) continue;
if (wc.IsEgg)
{
@ -1098,12 +1098,12 @@ namespace PKHeX.Core
foreach (var z in validWC6)
yield return z;
}
private static IEnumerable<MysteryGift> getMatchingWC7(PKM pkm, IEnumerable<MysteryGift> DB)
private static IEnumerable<MysteryGift> GetMatchingWC7(PKM pkm, IEnumerable<MysteryGift> DB)
{
if (DB == null)
yield break;
List<MysteryGift> validWC7 = new List<MysteryGift>();
var vs = getValidPreEvolutions(pkm).ToArray();
var vs = GetValidPreEvolutions(pkm).ToArray();
foreach (WC7 wc in DB.OfType<WC7>().Where(wc => vs.Any(dl => dl.Species == wc.Species)))
{
if (pkm.Egg_Location == 0) // Not Egg
@ -1119,7 +1119,7 @@ namespace PKHeX.Core
if (wc.EncryptionConstant != 0 && wc.EncryptionConstant != pkm.EncryptionConstant) continue;
if (wc.Language != 0 && wc.Language != pkm.Language) continue;
}
if (wc.Form != pkm.AltForm && vs.All(dl => !getCanFormChange(pkm, dl.Species))) continue;
if (wc.Form != pkm.AltForm && vs.All(dl => !IsFormChangeable(pkm, dl.Species))) continue;
if (wc.IsEgg)
{
@ -1175,23 +1175,23 @@ namespace PKHeX.Core
}
// EncounterEgg
private static IEnumerable<EncounterEgg> generateEggs(PKM pkm)
private static IEnumerable<EncounterEgg> GenerateEggs(PKM pkm)
{
if (NoHatchFromEgg.Contains(pkm.Species))
yield break;
int lvl = pkm.GenNumber < 4 ? 5 : 1;
var ver = (GameVersion) pkm.Version; // version is a true indicator for all generation 3+ origins
yield return new EncounterEgg { Game = (GameVersion)pkm.Version, Level = lvl, Species = getBaseSpecies(pkm, 0) };
yield return new EncounterEgg { Game = (GameVersion)pkm.Version, Level = lvl, Species = GetBaseSpecies(pkm, 0) };
if (getSplitBreedGeneration(pkm).Contains(pkm.Species))
yield return new EncounterEgg { Game = ver, Level = lvl, Species = getBaseSpecies(pkm, 1), SplitBreed = true };
if (GetSplitBreedGeneration(pkm).Contains(pkm.Species))
yield return new EncounterEgg { Game = ver, Level = lvl, Species = GetBaseSpecies(pkm, 1), SplitBreed = true };
}
// Utility
internal static bool IsHiddenAbilitySlot(EncounterSlot slot)
private static bool IsHiddenAbilitySlot(EncounterSlot slot)
{
return slot.DexNav || slot.Type == SlotType.FriendSafari || slot.Type == SlotType.Horde || slot.Type == SlotType.SOS;
return slot.Permissions.DexNav || slot.Type == SlotType.FriendSafari || slot.Type == SlotType.Horde || slot.Type == SlotType.SOS;
}
internal static bool IsSafariSlot(SlotType t)
{
@ -1199,18 +1199,18 @@ namespace PKHeX.Core
t == SlotType.Rock_Smash_Safari || t == SlotType.Pokeradar_Safari ||
t == SlotType.Old_Rod_Safari || t == SlotType.Good_Rod_Safari || t == SlotType.Super_Rod_Safari;
}
internal static bool getDexNavValid(PKM pkm)
internal static bool IsDexNavValid(PKM pkm)
{
if (!pkm.AO || !pkm.InhabitedGeneration(6))
return false;
IEnumerable<EncounterArea> locs = getDexNavAreas(pkm);
return locs.Select(loc => getValidEncounterSlots(pkm, loc, DexNav: true)).Any(slots => slots.Any(slot => slot.AllowDexNav && slot.DexNav));
IEnumerable<EncounterArea> locs = GetDexNavAreas(pkm);
return locs.Select(loc => GetValidEncounterSlots(pkm, loc, DexNav: true)).Any(slots => slots.Any(slot => slot.Permissions.AllowDexNav && slot.Permissions.DexNav));
}
internal static EncounterArea getCaptureLocation(PKM pkm)
internal static EncounterArea GetCaptureLocation(PKM pkm)
{
return (from area in getEncounterSlots(pkm, 100)
let slots = getValidEncounterSlots(pkm, area, pkm.AO, ignoreLevel: true).ToArray()
return (from area in GetEncounterSlots(pkm, 100)
let slots = GetValidEncounterSlots(pkm, area, pkm.AO, ignoreLevel: true).ToArray()
where slots.Any()
select new EncounterArea
{
@ -1218,17 +1218,17 @@ namespace PKHeX.Core
Slots = slots,
}).OrderBy(area => area.Slots.Min(x => x.LevelMin)).FirstOrDefault();
}
internal static EncounterStatic getStaticLocation(PKM pkm, int species = -1)
internal static EncounterStatic GetStaticLocation(PKM pkm, int species = -1)
{
switch (pkm.GenNumber)
{
case 1:
return getRBYStaticTransfer(species);
return GetRBYStaticTransfer(species);
default:
return getStaticEncounters(pkm, 100).OrderBy(s => s.Level).FirstOrDefault();
return GetStaticEncounters(pkm, 100).OrderBy(s => s.Level).FirstOrDefault();
}
}
internal static EncounterStatic getRBYStaticTransfer(int species)
internal static EncounterStatic GetRBYStaticTransfer(int species)
{
return new EncounterStatic
{
@ -1243,7 +1243,7 @@ namespace PKHeX.Core
Version = GameVersion.RBY
};
}
internal static EncounterStatic getGSStaticTransfer(int species)
internal static EncounterStatic GetGSStaticTransfer(int species)
{
return new EncounterStatic
{
@ -1258,15 +1258,15 @@ namespace PKHeX.Core
Version = GameVersion.GS
};
}
internal static bool getEncounterTrade1Valid(PKM pkm)
internal static bool IsEncounterTrade1Valid(PKM pkm)
{
string ot = pkm.OT_Name;
string tr = pkm.Format <= 2 ? "TRAINER" : "Trainer"; // decaps on transfer
return ot == "トレーナー" || ot == tr;
}
private static bool getWurmpleEvoValid(PKM pkm)
private static bool IsWurmpleEvoValid(PKM pkm)
{
uint evoVal = PKX.getWurmpleEvoVal(pkm.GenNumber, pkm.EncryptionConstant);
uint evoVal = PKX.GetWurmpleEvoVal(pkm.GenNumber, pkm.EncryptionConstant);
int wIndex = Array.IndexOf(WurmpleEvolutions, pkm.Species) / 2;
return evoVal == wIndex;
}

View file

@ -3,16 +3,18 @@
public class EncounterInvalid : IEncounterable
{
public int Species { get; }
public int LevelMin { get; }
public int LevelMax { get; }
public bool EggEncounter { get; }
public string Name => "Invalid";
public bool EggEncounter => false;
public int LevelMin => Level;
public int LevelMax => Level;
public readonly int Level;
public EncounterInvalid(PKM pkm)
{
Species = pkm.Species;
Level = pkm.CurrentLevel;
LevelMin = pkm.Met_Level;
LevelMax = pkm.CurrentLevel;
EggEncounter = pkm.WasEgg;
}
}
}

View file

@ -3,48 +3,48 @@ using static PKHeX.Core.LegalityCheckStrings;
namespace PKHeX.Core
{
public static class VerifyEncounter
public static class EncounterVerifier
{
public static CheckResult verifyEncounter(PKM pkm, IEncounterable encounter)
public static CheckResult VerifyEncounter(PKM pkm, IEncounterable encounter)
{
if (encounter is EncounterEgg e)
{
pkm.WasEgg = true;
return verifyEncounterEgg(pkm, e);
return VerifyEncounterEgg(pkm, e);
}
if (encounter is EncounterLink l)
return verifyEncounterLink(pkm, l);
return VerifyEncounterLink(pkm, l);
if (encounter is EncounterTrade t)
return verifyEncounterTrade(pkm, t);
return VerifyEncounterTrade(pkm, t);
if (encounter is EncounterSlot w)
return verifyEncounterWild(pkm, w);
return VerifyEncounterWild(pkm, w);
if (encounter is EncounterStatic s)
return verifyEncounterStatic(pkm, s, null);
return VerifyEncounterStatic(pkm, s, null);
if (encounter is MysteryGift g)
return verifyEncounterEvent(pkm, g);
return VerifyEncounterEvent(pkm, g);
return new CheckResult(Severity.Invalid, V80, CheckIdentifier.Encounter);
}
public static CheckResult verifyEncounterG12(PKM pkm, IEncounterable encounter)
public static CheckResult VerifyEncounterG12(PKM pkm, IEncounterable encounter)
{
var EncounterMatch = encounter is GBEncounterData g ? g.Encounter : encounter;
if (encounter.EggEncounter)
{
pkm.WasEgg = true;
return verifyEncounterEgg(pkm, EncounterMatch);
return VerifyEncounterEgg(pkm, EncounterMatch);
}
if (EncounterMatch is EncounterSlot)
return new CheckResult(Severity.Valid, V68, CheckIdentifier.Encounter);
if (EncounterMatch is EncounterStatic s)
return verifyEncounterStatic(pkm, s, null);
return VerifyEncounterStatic(pkm, s, null);
if (EncounterMatch is EncounterTrade t)
return verifyEncounterTrade(pkm, t);
return VerifyEncounterTrade(pkm, t);
return new CheckResult(Severity.Invalid, V80, CheckIdentifier.Encounter);
}
// Eggs
private static CheckResult verifyEncounterEgg(PKM pkm, IEncounterable egg)
private static CheckResult VerifyEncounterEgg(PKM pkm, IEncounterable egg)
{
// Check Species
if (Legal.NoHatchFromEgg.Contains(pkm.Species))
@ -53,21 +53,21 @@ namespace PKHeX.Core
{
case 1:
case 2: return new CheckResult(CheckIdentifier.Encounter); // no met location info
case 3: return pkm.Format != 3 ? verifyEncounterEgg3Transfer(pkm) : verifyEncounterEgg3(pkm);
case 4: return pkm.IsEgg ? verifyUnhatchedEgg(pkm, 02002) : verifyEncounterEgg4(pkm);
case 5: return pkm.IsEgg ? verifyUnhatchedEgg(pkm, 30002) : verifyEncounterEgg5(pkm);
case 6: return pkm.IsEgg ? verifyUnhatchedEgg(pkm, 30002) : verifyEncounterEgg6(pkm);
case 7: return pkm.IsEgg ? verifyUnhatchedEgg(pkm, 30002) : verifyEncounterEgg7(pkm);
case 3: return pkm.Format != 3 ? VerifyEncounterEgg3Transfer(pkm) : VerifyEncounterEgg3(pkm);
case 4: return pkm.IsEgg ? VerifyUnhatchedEgg(pkm, 02002) : VerifyEncounterEgg4(pkm);
case 5: return pkm.IsEgg ? VerifyUnhatchedEgg(pkm, 30002) : VerifyEncounterEgg5(pkm);
case 6: return pkm.IsEgg ? VerifyUnhatchedEgg(pkm, 30002) : VerifyEncounterEgg6(pkm);
case 7: return pkm.IsEgg ? VerifyUnhatchedEgg(pkm, 30002) : VerifyEncounterEgg7(pkm);
default: // none of the above
return new CheckResult(Severity.Invalid, V51, CheckIdentifier.Encounter);
}
}
private static CheckResult verifyEncounterEgg3(PKM pkm)
private static CheckResult VerifyEncounterEgg3(PKM pkm)
{
return pkm.Format == 3 ? verifyEncounterEgg3Native(pkm) : verifyEncounterEgg3Transfer(pkm);
return pkm.Format == 3 ? VerifyEncounterEgg3Native(pkm) : VerifyEncounterEgg3Transfer(pkm);
}
private static CheckResult verifyEncounterEgg3Native(PKM pkm)
private static CheckResult VerifyEncounterEgg3Native(PKM pkm)
{
if (pkm.Met_Level != 0)
return new CheckResult(Severity.Invalid, string.Format(V52, 0), CheckIdentifier.Encounter);
@ -88,7 +88,7 @@ namespace PKHeX.Core
}
return new CheckResult(Severity.Valid, V53, CheckIdentifier.Encounter);
}
private static CheckResult verifyEncounterEgg3Transfer(PKM pkm)
private static CheckResult VerifyEncounterEgg3Transfer(PKM pkm)
{
if (pkm.IsEgg)
return new CheckResult(Severity.Invalid, V57, CheckIdentifier.Encounter);
@ -103,10 +103,10 @@ namespace PKHeX.Core
return new CheckResult(Severity.Valid, V53, CheckIdentifier.Encounter);
}
private static CheckResult verifyEncounterEgg4(PKM pkm)
private static CheckResult VerifyEncounterEgg4(PKM pkm)
{
if (pkm.Format == 4)
return verifyEncounterEggLevelLoc(pkm, 0, pkm.HGSS ? Legal.ValidMet_HGSS : pkm.Pt ? Legal.ValidMet_Pt : Legal.ValidMet_DP);
return VerifyEncounterEggLevelLoc(pkm, 0, pkm.HGSS ? Legal.ValidMet_HGSS : pkm.Pt ? Legal.ValidMet_Pt : Legal.ValidMet_DP);
if (pkm.IsEgg)
return new CheckResult(Severity.Invalid, V57, CheckIdentifier.Encounter);
// transferred
@ -117,29 +117,29 @@ namespace PKHeX.Core
return new CheckResult(Severity.Invalid, V61, CheckIdentifier.Encounter);
return new CheckResult(Severity.Valid, V53, CheckIdentifier.Encounter);
}
private static CheckResult verifyEncounterEgg5(PKM pkm)
private static CheckResult VerifyEncounterEgg5(PKM pkm)
{
return verifyEncounterEggLevelLoc(pkm, 1, pkm.B2W2 ? Legal.ValidMet_B2W2 : Legal.ValidMet_BW);
return VerifyEncounterEggLevelLoc(pkm, 1, pkm.B2W2 ? Legal.ValidMet_B2W2 : Legal.ValidMet_BW);
}
private static CheckResult verifyEncounterEgg6(PKM pkm)
private static CheckResult VerifyEncounterEgg6(PKM pkm)
{
if (pkm.AO)
return verifyEncounterEggLevelLoc(pkm, 1, Legal.ValidMet_AO);
return VerifyEncounterEggLevelLoc(pkm, 1, Legal.ValidMet_AO);
if (pkm.Egg_Location == 318)
return new CheckResult(Severity.Invalid, V55, CheckIdentifier.Encounter);
return verifyEncounterEggLevelLoc(pkm, 1, Legal.ValidMet_XY);
return VerifyEncounterEggLevelLoc(pkm, 1, Legal.ValidMet_XY);
}
private static CheckResult verifyEncounterEgg7(PKM pkm)
private static CheckResult VerifyEncounterEgg7(PKM pkm)
{
if (pkm.SM)
return verifyEncounterEggLevelLoc(pkm, 1, Legal.ValidMet_SM);
return VerifyEncounterEggLevelLoc(pkm, 1, Legal.ValidMet_SM);
// no other games
return new CheckResult(Severity.Invalid, V51, CheckIdentifier.Encounter);
}
private static CheckResult verifyEncounterEggLevelLoc(PKM pkm, int eggLevel, int[] MetLocations)
private static CheckResult VerifyEncounterEggLevelLoc(PKM pkm, int eggLevel, int[] MetLocations)
{
if (pkm.Met_Level != eggLevel)
return new CheckResult(Severity.Invalid, string.Format(V52, eggLevel), CheckIdentifier.Encounter);
@ -147,7 +147,7 @@ namespace PKHeX.Core
? new CheckResult(Severity.Valid, V53, CheckIdentifier.Encounter)
: new CheckResult(Severity.Invalid, V54, CheckIdentifier.Encounter);
}
private static CheckResult verifyUnhatchedEgg(PKM pkm, int tradeLoc)
private static CheckResult VerifyUnhatchedEgg(PKM pkm, int tradeLoc)
{
if (pkm.Egg_Location == tradeLoc)
return new CheckResult(Severity.Invalid, V62, CheckIdentifier.Encounter);
@ -160,7 +160,7 @@ namespace PKHeX.Core
}
// Etc
private static CheckResult verifyEncounterWild(PKM pkm, EncounterSlot slot)
private static CheckResult VerifyEncounterWild(PKM pkm, EncounterSlot slot)
{
// Check for Unreleased Encounters / Collisions
switch (pkm.GenNumber)
@ -174,29 +174,29 @@ namespace PKHeX.Core
break;
}
if (slot.Normal)
return slot.Pressure
if (slot.Permissions.IsNormalLead)
return slot.Permissions.Pressure
? new CheckResult(Severity.Valid, V67, CheckIdentifier.Encounter)
: new CheckResult(Severity.Valid, V68, CheckIdentifier.Encounter);
// Decreased Level Encounters
if (slot.WhiteFlute)
return slot.Pressure
if (slot.Permissions.WhiteFlute)
return slot.Permissions.Pressure
? new CheckResult(Severity.Valid, V69, CheckIdentifier.Encounter)
: new CheckResult(Severity.Valid, V70, CheckIdentifier.Encounter);
// Increased Level Encounters
if (slot.BlackFlute)
return slot.Pressure
if (slot.Permissions.BlackFlute)
return slot.Permissions.Pressure
? new CheckResult(Severity.Valid, V71, CheckIdentifier.Encounter)
: new CheckResult(Severity.Valid, V72, CheckIdentifier.Encounter);
if (slot.Pressure)
if (slot.Permissions.Pressure)
return new CheckResult(Severity.Valid, V67, CheckIdentifier.Encounter);
return new CheckResult(Severity.Valid, V73, CheckIdentifier.Encounter);
}
private static CheckResult verifyEncounterStatic(PKM pkm, EncounterStatic s, CheckResult[] vRelearn)
private static CheckResult VerifyEncounterStatic(PKM pkm, EncounterStatic s, CheckResult[] vRelearn)
{
// Check for Unreleased Encounters / Collisions
switch (pkm.GenNumber)
@ -225,20 +225,20 @@ namespace PKHeX.Core
return new CheckResult(Severity.Valid, V75, CheckIdentifier.Encounter);
}
private static CheckResult verifyEncounterTrade(PKM pkm, EncounterTrade trade)
private static CheckResult VerifyEncounterTrade(PKM pkm, EncounterTrade trade)
{
if (trade.Species == pkm.Species && trade.EvolveOnTrade)
{
// Pokemon that evolve on trade can not be in the phase evolution after the trade
// If the trade holds an everstone EvolveOnTrade will be false for the encounter
var species = LegalityAnalysis.specieslist;
var species = LegalityAnalysis.SpeciesStrings;
var unevolved = species[pkm.Species];
var evolved = species[pkm.Species + 1];
return new CheckResult(Severity.Invalid, string.Format(V401, unevolved, evolved), CheckIdentifier.Encounter);
}
return new CheckResult(Severity.Valid, V76, CheckIdentifier.Encounter);
}
private static CheckResult verifyEncounterLink(PKM pkm, EncounterLink enc)
private static CheckResult VerifyEncounterLink(PKM pkm, EncounterLink enc)
{
// Should NOT be Fateful, and should be in Database
if (enc == null)
@ -256,10 +256,10 @@ namespace PKHeX.Core
? new CheckResult(Severity.Invalid, V48, CheckIdentifier.Encounter)
: new CheckResult(Severity.Valid, V49, CheckIdentifier.Encounter);
}
private static CheckResult verifyEncounterEvent(PKM pkm, MysteryGift MatchedGift)
private static CheckResult VerifyEncounterEvent(PKM pkm, MysteryGift MatchedGift)
{
// Strict matching already performed by EncounterGenerator. May be worth moving some checks here to better flag invalid gifts.
return new CheckResult(Severity.Valid, string.Format(V21, MatchedGift.getCardHeader(), ""), CheckIdentifier.Encounter);
return new CheckResult(Severity.Valid, string.Format(V21, MatchedGift.CardHeader, ""), CheckIdentifier.Encounter);
}
}
}

View file

@ -3,28 +3,28 @@ using static PKHeX.Core.LegalityCheckStrings;
namespace PKHeX.Core
{
public static class VerifyEvolution
public static class EvolutionVerifier
{
// Evolutions
public static CheckResult verifyEvolution(PKM pkm, LegalInfo info)
public static CheckResult VerifyEvolution(PKM pkm, LegalInfo info)
{
return isValidEvolution(pkm, info)
return IsValidEvolution(pkm, info)
? new CheckResult(CheckIdentifier.Evolution)
: new CheckResult(Severity.Invalid, V86, CheckIdentifier.Evolution);
}
private static bool isValidEvolution(PKM pkm, LegalInfo info)
private static bool IsValidEvolution(PKM pkm, LegalInfo info)
{
int species = pkm.Species;
if (info.EncounterMatch.Species == species)
return true;
if (info.EncounterMatch.EggEncounter && species == 350 && pkm.Format >= 5) // Prism Scale
return true;
if (!Legal.getEvolutionValid(pkm, info.EncounterMatch.Species))
if (!Legal.IsEvolutionValid(pkm, info.EncounterMatch.Species))
return false;
// If current species evolved with a move evolution and encounter species is not current species check if the evolution by move is valid
// Only the evolution by move is checked, if there is another evolution before the evolution by move is covered in getEvolutionValid
// Only the evolution by move is checked, if there is another evolution before the evolution by move is covered in IsEvolutionValid
if (Legal.SpeciesEvolutionWithMove.Contains(pkm.Species))
return Legal.getEvolutionWithMoveValid(pkm, info);
return Legal.IsEvolutionValidWithMove(pkm, info);
return true;
}
}

View file

@ -8,7 +8,7 @@ namespace PKHeX.Core
private readonly PKM pkm;
/// <summary>The generation of games the PKM originated from.</summary>
public int Generation;
public int Generation { get; set; }
/// <summary> The Game the PPKM originated from.</summary>
public GameVersion Game { get; set; }
@ -26,20 +26,20 @@ namespace PKHeX.Core
}
}
public int[] RelearnBase;
public int[] RelearnBase { get; set; }
public readonly List<CheckResult> Parse = new List<CheckResult>();
public CheckResult[] vRelearn = new CheckResult[4];
public CheckMoveResult[] vMoves = new CheckMoveResult[4];
public CheckResult[] Relearn { get; set; } = new CheckResult[4];
public CheckMoveResult[] Moves { get; set; } = new CheckMoveResult[4];
public DexLevel[][] EvoChainsAllGens => _evochains ?? (_evochains = Legal.getEvolutionChainsAllGens(pkm, EncounterMatch));
public DexLevel[][] EvoChainsAllGens => _evochains ?? (_evochains = Legal.GetEvolutionChainsAllGens(pkm, EncounterMatch));
public ValidEncounterMoves EncounterMoves { get; set; }
private DexLevel[][] _evochains;
private IEncounterable _match;
public PIDIV PIDIV;
public bool PIDIVMatches = true;
public PIDIV PIDIV { get; set; }
public bool PIDIVMatches { get; set; } = true;
public LegalInfo(PKM pk)
{

View file

@ -33,29 +33,27 @@ namespace PKHeX.Core
public PeekEnumerator(IEnumerator<T> enumerator) => Enumerator = enumerator ?? throw new ArgumentNullException(nameof(enumerator));
private void TryFetchPeek()
private bool TryFetchPeek()
{
if (!didPeek && (didPeek = Enumerator.MoveNext()))
peek = Enumerator.Current;
return didPeek;
}
public T Peek()
{
TryFetchPeek();
if (!didPeek)
if (!TryFetchPeek())
throw new InvalidOperationException("Enumeration already finished.");
return peek;
}
public T PeekOrDefault()
{
TryFetchPeek();
return !didPeek ? default(T) : peek;
return !TryFetchPeek() ? default(T) : peek;
}
public bool PeekIsNext()
{
TryFetchPeek();
return didPeek;
return TryFetchPeek();
}
}
}

View file

@ -8,124 +8,144 @@ namespace PKHeX.Core
{
public static class VerifyCurrentMoves
{
public static CheckMoveResult[] verifyMoves(PKM pkm, LegalInfo info, GameVersion game = GameVersion.Any)
public static CheckMoveResult[] VerifyMoves(PKM pkm, LegalInfo info, GameVersion game = GameVersion.Any)
{
int[] Moves = pkm.Moves;
var res = parseMovesForEncounters(pkm, info, game, Moves);
var res = ParseMovesForEncounters(pkm, info, game, Moves);
// Duplicate Moves Check
verifyNoEmptyDuplicates(Moves, res);
VerifyNoEmptyDuplicates(Moves, res);
if (Moves[0] == 0) // Can't have an empty moveslot for the first move.
res[0] = new CheckMoveResult(res[0], Severity.Invalid, V167, CheckIdentifier.Move);
return res;
}
private static CheckMoveResult[] parseMovesForEncounters(PKM pkm, LegalInfo info, GameVersion game, int[] Moves)
private static CheckMoveResult[] ParseMovesForEncounters(PKM pkm, LegalInfo info, GameVersion game, int[] Moves)
{
if (pkm.Species == 235) // special handling for Smeargle
return parseMovesForSmeargle(pkm, Moves, info); // Smeargle can have any moves except a few
return ParseMovesForSmeargle(pkm, Moves, info); // Smeargle can have any moves except a few
// Iterate over encounters
bool pre3DS = pkm.GenNumber < 6;
// gather valid moves for encounter species
info.EncounterMoves = getEncounterValidMoves(pkm, info);
info.EncounterMoves = GetEncounterValidMoves(pkm, info);
if (pkm.GenNumber <= 3)
pkm.WasEgg = info.EncounterMatch.EggEncounter;
var EncounterMatchGen = info.EncounterMatch as IGeneration;
var defaultG1LevelMoves = info.EncounterMoves.validLevelUpMoves[1];
var defaultG2LevelMoves = pkm.InhabitedGeneration(2) ? info.EncounterMoves.validLevelUpMoves[2] : null;
var defaultG1LevelMoves = info.EncounterMoves.LevelUpMoves[1];
var defaultG2LevelMoves = pkm.InhabitedGeneration(2) ? info.EncounterMoves.LevelUpMoves[2] : null;
var defaultTradeback = pkm.TradebackStatus;
if (EncounterMatchGen != null)
{
// Generation 1 can have different minimum level in different encounter of the same species; update valid level moves
UptateGen1LevelUpMoves(pkm, info.EncounterMoves, info.EncounterMoves.minLvlG1, EncounterMatchGen.Generation, info);
UptateGen1LevelUpMoves(pkm, info.EncounterMoves, info.EncounterMoves.MinimumLevelGen1, EncounterMatchGen.Generation, info);
if(!Legal.AllowGen2MoveReminder && pkm.InhabitedGeneration(2))
// The same for Generation 2 if move reminder from Stadium 2 is not allowed
UptateGen2LevelUpMoves(pkm, info.EncounterMoves, info.EncounterMoves.minLvlG2, EncounterMatchGen.Generation, info);
UptateGen2LevelUpMoves(pkm, info.EncounterMoves, info.EncounterMoves.MinimumLevelGen2, EncounterMatchGen.Generation, info);
}
var res = pre3DS
? parseMovesPre3DS(pkm, Moves, info)
: parseMoves3DS(pkm, game, Moves, info);
? ParseMovesPre3DS(pkm, Moves, info)
: ParseMoves3DS(pkm, game, Moves, info);
if (res.All(x => x.Valid))
return res;
if (EncounterMatchGen?.Generation == 1 || EncounterMatchGen?.Generation == 2) // not valid, restore generation 1 and 2 moves
{
info.EncounterMoves.validLevelUpMoves[1] = defaultG1LevelMoves;
info.EncounterMoves.LevelUpMoves[1] = defaultG1LevelMoves;
if (pkm.InhabitedGeneration(2))
info.EncounterMoves.validLevelUpMoves[2] = defaultG2LevelMoves;
info.EncounterMoves.LevelUpMoves[2] = defaultG2LevelMoves;
}
pkm.TradebackStatus = defaultTradeback;
return res;
}
private static CheckMoveResult[] parseMovesForSmeargle(PKM pkm, int[] Moves, LegalInfo info)
private static CheckMoveResult[] ParseMovesForSmeargle(PKM pkm, int[] Moves, LegalInfo info)
{
if (!pkm.IsEgg)
return parseMovesSketch(pkm, Moves);
return ParseMovesSketch(pkm, Moves);
// can only know sketch as egg
info.EncounterMoves = new ValidEncounterMoves
{
validLevelUpMoves = Legal.getValidMovesAllGens(pkm, info.EvoChainsAllGens, minLvLG1: 1, Tutor: false, Machine: false, RemoveTransferHM: false)
LevelUpMoves = Legal.GetValidMovesAllGens(pkm, info.EvoChainsAllGens, minLvLG1: 1, Tutor: false, Machine: false, RemoveTransferHM: false)
};
return parseMoves(pkm, pkm.Moves, new int[0], new int[0], new int[0], new int[0], new int[0], new int[0], false, info);
return ParseMoves(pkm, pkm.Moves, new int[0], new int[0], new int[0], new int[0], new int[0], new int[0], info);
}
private static CheckMoveResult[] parseMovesIsEggPreRelearn(PKM pkm, int[] Moves, int[] SpecialMoves, bool allowinherited, EncounterEgg e)
private class MoveInfoSet
{
public List<int> SpecialMoves { get; set; }
public List<int> EggMoves { get; set; }
public List<int> BaseMoves { get; set; }
public bool AllowInherited { get; set; }
public List<int> TutorMoves { get; set; }
public List<int> TMHMMoves { get; set; }
public List<int> LvlMoves { get; set; }
}
private static CheckMoveResult[] ParseMovesIsEggPreRelearn(PKM pkm, int[] Moves, int[] SpecialMoves, bool allowinherited, EncounterEgg e)
{
CheckMoveResult[] res = new CheckMoveResult[4];
var ValidSpecialMoves = SpecialMoves.Where(m => m != 0).ToList();
var baseEggMoves = Legal.getBaseEggMoves(pkm, e.Species, e.Game, pkm.GenNumber < 4 ? 5 : 1)?.ToList() ?? new List<int>();
// Level up moves could not be inherited if Ditto is parent,
// that means genderless species and male only species except Nidoran and Volbet (they breed with female nidoran and illumise) could not have level up moves as an egg
var AllowLvlMoves = pkm.PersonalInfo.Gender > 0 && pkm.PersonalInfo.Gender < 255 || Legal.MixedGenderBreeding.Contains(e.Species);
var InheritedLvlMoves = !AllowLvlMoves? new List<int>() : Legal.getBaseEggMoves(pkm, e.Species, e.Game, 100)?.ToList() ?? new List<int>();
var EggMoves = Legal.getEggMoves(pkm, e.Species, pkm.AltForm)?.ToList() ?? new List<int>();
var InheritedTutorMoves = e.Game == GameVersion.C ? Legal.getTutorMoves(pkm, pkm.Species, pkm.AltForm, false, 2)?.ToList() : new List<int>();
// Only TM Hm moves from the source game of the egg, not any other games from the same generation
var InheritedTMHMMoves = Legal.getTMHM(pkm, pkm.Species, pkm.AltForm, pkm.GenNumber, e.Game, false)?.ToList();
var baseEggMoves = Legal.GetBaseEggMoves(pkm, e.Species, e.Game, pkm.GenNumber < 4 ? 5 : 1)?.ToList() ?? new List<int>();
// Level up moves cannot be inherited if Ditto is parent, thus genderless/single gender species cannot have level up moves as an egg
bool AllowLvlMoves = pkm.PersonalInfo.Gender > 0 && pkm.PersonalInfo.Gender < 255 || Legal.MixedGenderBreeding.Contains(e.Species);
var InheritedLvlMoves = !AllowLvlMoves? new List<int>() : Legal.GetBaseEggMoves(pkm, e.Species, e.Game, 100)?.ToList() ?? new List<int>();
InheritedLvlMoves.RemoveAll(x => baseEggMoves.Contains(x));
var infoset = new MoveInfoSet
{
EggMoves = Legal.GetEggMoves(pkm, e.Species, pkm.AltForm)?.ToList() ?? new List<int>(),
TutorMoves = e.Game == GameVersion.C ? Legal.GetTutorMoves(pkm, pkm.Species, pkm.AltForm, false, 2)?.ToList() : new List<int>(),
TMHMMoves = Legal.GetTMHM(pkm, pkm.Species, pkm.AltForm, pkm.GenNumber, e.Game, false)?.ToList(),
LvlMoves = InheritedLvlMoves,
BaseMoves = baseEggMoves,
SpecialMoves = SpecialMoves.Where(m => m != 0).ToList(),
AllowInherited = allowinherited
};
// Only TM Hm moves from the source game of the egg, not any other games from the same generation
if (pkm.Format > 2 || SpecialMoves.Any())
{
// For gen 2 is not possible to difference normal eggs from event eggs
// If there is no special moves assume normal egg
res = verifyPreRelearnEggBase(pkm, Moves, baseEggMoves, EggMoves, InheritedLvlMoves, InheritedTMHMMoves, InheritedTutorMoves, ValidSpecialMoves, allowinherited, e.Game);
res = VerifyPreRelearnEggBase(pkm, Moves, infoset, e.Game);
}
else if (pkm.Format == 2)
{
res = verifyPreRelearnEggBase(pkm, Moves, baseEggMoves, EggMoves, InheritedLvlMoves, InheritedTMHMMoves, InheritedTutorMoves, new List<int>(), true, e.Game);
infoset.SpecialMoves.Clear();
infoset.AllowInherited = true;
res = VerifyPreRelearnEggBase(pkm, Moves, infoset, e.Game);
}
return res;
}
private static CheckMoveResult[] parseMovesWasEggPreRelearn(PKM pkm, int[] Moves, LegalInfo info, EncounterEgg e)
private static CheckMoveResult[] ParseMovesWasEggPreRelearn(PKM pkm, int[] Moves, LegalInfo info, EncounterEgg e)
{
var EventEggMoves = (info.EncounterMatch as IMoveset)?.Moves ?? new int[0];
// Level up moves could not be inherited if Ditto is parent,
// that means genderless species and male only species except Nidoran and Volbet (they breed with female nidoran and illumise) could not have level up moves as an egg
var inheritLvlMoves = pkm.PersonalInfo.Gender > 0 && pkm.PersonalInfo.Gender < 255 || Legal.MixedGenderBreeding.Contains(e.Species);
int BaseLvlMoves = inheritLvlMoves ? 100 : pkm.GenNumber <= 3 ? 5 : 1;
var LvlupEggMoves = Legal.getBaseEggMoves(pkm, e.Species, e.Game, BaseLvlMoves);
var LvlupEggMoves = Legal.GetBaseEggMoves(pkm, e.Species, e.Game, BaseLvlMoves);
var TradebackPreevo = pkm.Format == 2 && info.EncounterMatch.Species > 151;
var NonTradebackLvlMoves = new int[0];
if (TradebackPreevo)
NonTradebackLvlMoves = Legal.getExclusivePreEvolutionMoves(pkm, info.EncounterMatch.Species, info.EvoChainsAllGens[2], 2, e.Game).Where(m => m > Legal.MaxMoveID_1).ToArray();
var EggMoves = Legal.getEggMoves(pkm, e.Species, pkm.AltForm);
NonTradebackLvlMoves = Legal.GetExclusivePreEvolutionMoves(pkm, info.EncounterMatch.Species, info.EvoChainsAllGens[2], 2, e.Game).Where(m => m > Legal.MaxMoveID_1).ToArray();
var EggMoves = Legal.GetEggMoves(pkm, e.Species, pkm.AltForm);
bool volt = (pkm.GenNumber > 3 || e.Game == GameVersion.E) && Legal.LightBall.Contains(pkm.Species);
var SpecialMoves = volt && EventEggMoves.Length == 0 ? new[] { 344 } : new int[0]; // Volt Tackle for bred Pichu line
return parseMoves(pkm, Moves, SpecialMoves, LvlupEggMoves, EggMoves, NonTradebackLvlMoves, EventEggMoves, new int[0], e.SplitBreed, info);
return ParseMoves(pkm, Moves, SpecialMoves, LvlupEggMoves, EggMoves, NonTradebackLvlMoves, EventEggMoves, new int[0], info);
}
private static CheckMoveResult[] parseMovesSketch(PKM pkm, int[] Moves)
private static CheckMoveResult[] ParseMovesSketch(PKM pkm, int[] Moves)
{
CheckMoveResult[] res = new CheckMoveResult[4];
for (int i = 0; i < 4; i++)
@ -134,75 +154,74 @@ namespace PKHeX.Core
: new CheckMoveResult(MoveSource.Sketch, pkm.Format, CheckIdentifier.Move);
return res;
}
private static CheckMoveResult[] parseMoves3DS(PKM pkm, GameVersion game, int[] Moves, LegalInfo info)
private static CheckMoveResult[] ParseMoves3DS(PKM pkm, GameVersion game, int[] Moves, LegalInfo info)
{
info.EncounterMoves.Relearn = pkm.GenNumber >= 6 ? pkm.RelearnMoves : new int[0];
if (info.EncounterMatch is IMoveset)
return parseMovesSpecialMoveset(pkm, Moves, info);
return ParseMovesSpecialMoveset(pkm, Moves, info);
// Everything else
return parseMovesRelearn(pkm, Moves, info);
return ParseMovesRelearn(pkm, Moves, info);
}
private static CheckMoveResult[] parseMovesPre3DS(PKM pkm, int[] Moves, LegalInfo info)
private static CheckMoveResult[] ParseMovesPre3DS(PKM pkm, int[] Moves, LegalInfo info)
{
if (pkm.IsEgg && info.EncounterMatch is EncounterEgg egg)
{
int[] SpecialMoves = (info.EncounterMatch as IMoveset)?.Moves;
// Gift do not have special moves but also should not have normal egg moves
var allowinherited = SpecialMoves == null && !pkm.WasGiftEgg && pkm.Species != 489 && pkm.Species != 490;
return parseMovesIsEggPreRelearn(pkm, Moves, SpecialMoves ?? new int[0], allowinherited, egg);
return ParseMovesIsEggPreRelearn(pkm, Moves, SpecialMoves ?? new int[0], allowinherited, egg);
}
var NoMoveReminder = (info.EncounterMatch as IGeneration)?.Generation == 1 || (info.EncounterMatch as IGeneration)?.Generation == 2 && !Legal.AllowGen2MoveReminder;
if (pkm.GenNumber <= 2 && NoMoveReminder)
return parseMovesGenGB(pkm, Moves, info);
return ParseMovesGenGB(pkm, Moves, info);
if (info.EncounterMatch is EncounterEgg e)
return parseMovesWasEggPreRelearn(pkm, Moves, info, e);
return ParseMovesWasEggPreRelearn(pkm, Moves, info, e);
return parseMovesSpecialMoveset(pkm, Moves, info);
return ParseMovesSpecialMoveset(pkm, Moves, info);
}
private static CheckMoveResult[] parseMovesGenGB(PKM pkm, int[] Moves, LegalInfo info)
private static CheckMoveResult[] ParseMovesGenGB(PKM pkm, int[] Moves, LegalInfo info)
{
GameVersion[] games = (info.EncounterMatch as IGeneration)?.Generation == 1 ? Legal.getGen1GameEncounter(pkm) : Legal.getGen2GameEncounter(pkm);
GameVersion[] games = (info.EncounterMatch as IGeneration)?.Generation == 1 ? Legal.GetGen1GameEncounter(pkm) : Legal.GetGen2GameEncounter(pkm);
CheckMoveResult[] res = new CheckMoveResult[4];
var G1Encounter = info.EncounterMatch;
if (G1Encounter == null)
return parseMovesSpecialMoveset(pkm, Moves, info);
return ParseMovesSpecialMoveset(pkm, Moves, info);
var InitialMoves = new int[0];
int[] SpecialMoves = (info.EncounterMatch as IMoveset)?.Moves ?? new int[0];
var emptyegg = new int[0];
foreach (GameVersion ver in games)
{
var VerInitialMoves = Legal.getInitialMovesGBEncounter(G1Encounter.Species, G1Encounter.LevelMin, ver).ToArray();
var VerInitialMoves = Legal.GetInitialMovesGBEncounter(G1Encounter.Species, G1Encounter.LevelMin, ver).ToArray();
if (VerInitialMoves.SequenceEqual(InitialMoves))
return res;
res = parseMoves(pkm, Moves, SpecialMoves, emptyegg, emptyegg, emptyegg, new int[0], VerInitialMoves, false, info);
res = ParseMoves(pkm, Moves, SpecialMoves, emptyegg, emptyegg, emptyegg, new int[0], VerInitialMoves, info);
if (res.All(r => r.Valid))
return res;
InitialMoves = VerInitialMoves;
}
return res;
}
private static CheckMoveResult[] parseMovesSpecialMoveset(PKM pkm, int[] Moves, LegalInfo info)
private static CheckMoveResult[] ParseMovesSpecialMoveset(PKM pkm, int[] Moves, LegalInfo info)
{
var mg = info.EncounterMatch as IMoveset;
int[] SpecialMoves = mg?.Moves ?? new int[0];
var emptyegg = new int[0];
return parseMoves(pkm, Moves, SpecialMoves, emptyegg, emptyegg, emptyegg, new int[0], new int[0], false, info);
return ParseMoves(pkm, Moves, SpecialMoves, emptyegg, emptyegg, emptyegg, new int[0], new int[0], info);
}
private static CheckMoveResult[] parseMovesRelearn(PKM pkm, int[] Moves, LegalInfo info)
private static CheckMoveResult[] ParseMovesRelearn(PKM pkm, int[] Moves, LegalInfo info)
{
var emptyegg = new int[0];
var issplitbreed = pkm.WasEgg && Legal.SplitBreed.Contains(pkm.Species);
var e = info.EncounterMatch as EncounterEgg;
var EggMoves = e != null ? Legal.getEggMoves(pkm, e.Species, pkm.AltForm, e.Game) : emptyegg;
var EggMoves = e != null ? Legal.GetEggMoves(pkm, e.Species, pkm.AltForm, e.Game) : emptyegg;
var TradebackPreevo = pkm.Format == 2 && info.EncounterMatch.Species > 151 && pkm.InhabitedGeneration(1);
var NonTradebackLvlMoves = TradebackPreevo ? Legal.getExclusivePreEvolutionMoves(pkm, info.EncounterMatch.Species, info.EvoChainsAllGens[2], 2, e.Game).Where(m => m > Legal.MaxMoveID_1).ToArray() : new int[0];
var NonTradebackLvlMoves = TradebackPreevo ? Legal.GetExclusivePreEvolutionMoves(pkm, info.EncounterMatch.Species, info.EvoChainsAllGens[2], 2, e.Game).Where(m => m > Legal.MaxMoveID_1).ToArray() : new int[0];
int[] RelearnMoves = pkm.RelearnMoves;
int[] SpecialMoves = (info.EncounterMatch as IMoveset)?.Moves ?? new int[0];
CheckMoveResult[] res = parseMoves(pkm, Moves, SpecialMoves, new int[0], EggMoves, NonTradebackLvlMoves, new int[0], new int[0], issplitbreed, info);
CheckMoveResult[] res = ParseMoves(pkm, Moves, SpecialMoves, new int[0], EggMoves, NonTradebackLvlMoves, new int[0], new int[0], info);
for (int i = 0; i < 4; i++)
if ((pkm.IsEgg || res[i].Flag) && !RelearnMoves.Contains(Moves[i]))
@ -210,17 +229,10 @@ namespace PKHeX.Core
return res;
}
private static CheckMoveResult[] parseMoves(PKM pkm, int[] moves, int[] special, int[] lvlupegg, int[] egg, int[] NonTradebackLvlMoves, int[] eventegg, int[] initialmoves, bool issplitbreed, LegalInfo info)
private static CheckMoveResult[] ParseMoves(PKM pkm, int[] moves, int[] special, int[] lvlupegg, int[] egg, int[] NonTradebackLvlMoves, int[] eventegg, int[] initialmoves, LegalInfo info)
{
CheckMoveResult[] res = new CheckMoveResult[4];
var Gen1MovesLearned = new List<int>();
var Gen2PreevoMovesLearned = new List<int>();
var EggMovesLearned = new List<int>();
var LvlupEggMovesLearned = new List<int>();
var EventEggMovesLearned = new List<int>();
var IsGen2Pkm = pkm.Format == 2 || pkm.VC2;
var required = Legal.getRequiredMoveCount(pkm, moves, info, initialmoves);
var IncenseMovesLearned = new List<int>();
var required = Legal.GetRequiredMoveCount(pkm, moves, info, initialmoves);
// Check none moves and relearn moves before generation moves
for (int m = 0; m < 4; m++)
@ -235,8 +247,15 @@ namespace PKHeX.Core
return res;
bool MixedGen1NonTradebackGen2 = false;
var Gen1MovesLearned = new List<int>();
var Gen2PreevoMovesLearned = new List<int>();
var EggMovesLearned = new List<int>();
var LvlupEggMovesLearned = new List<int>();
var EventEggMovesLearned = new List<int>();
var IsGen2Pkm = pkm.Format == 2 || pkm.VC2;
var IncenseMovesLearned = new List<int>();
// Check moves going backwards, marking the move valid in the most current generation when it can be learned
int[] generations = getGenMovesCheckOrder(pkm);
int[] generations = GetGenMovesCheckOrder(pkm);
foreach (var gen in generations)
{
if (!pkm.InhabitedGeneration(gen))
@ -265,11 +284,11 @@ namespace PKHeX.Core
if (gen == 1 && initialmoves.Contains(moves[m]))
res[m] = new CheckMoveResult(MoveSource.Initial, gen, Severity.Valid, native ? V361 : string.Format(V362, gen), CheckIdentifier.Move);
else if (info.EncounterMoves.validLevelUpMoves[gen].Contains(moves[m]))
else if (info.EncounterMoves.LevelUpMoves[gen].Contains(moves[m]))
res[m] = new CheckMoveResult(MoveSource.LevelUp, gen, Severity.Valid, native ? V177 : string.Format(V330, gen), CheckIdentifier.Move);
else if (info.EncounterMoves.validTMHMMoves[gen].Contains(moves[m]))
else if (info.EncounterMoves.TMHMMoves[gen].Contains(moves[m]))
res[m] = new CheckMoveResult(MoveSource.TMHM, gen, Severity.Valid, native ? V173 : string.Format(V331, gen), CheckIdentifier.Move);
else if (info.EncounterMoves.validTutorMoves[gen].Contains(moves[m]))
else if (info.EncounterMoves.TutorMoves[gen].Contains(moves[m]))
res[m] = new CheckMoveResult(MoveSource.Tutor, gen, Severity.Valid, native ? V174 : string.Format(V332, gen), CheckIdentifier.Move);
else if (gen == pkm.GenNumber && special.Contains(moves[m]))
res[m] = new CheckMoveResult(MoveSource.Special, gen, Severity.Valid, V175, CheckIdentifier.Move);
@ -425,9 +444,9 @@ namespace PKHeX.Core
{
// Check moves learned at the same level in red/blue and yellow, illegal because there is no move reminder
// Only two incompatibilites and only there are no illegal combination if generation 2 or 7 are included in the analysis
ParseRedYellowIncompatibleMoves(pkm, moves, ref res);
ParseRedYellowIncompatibleMoves(pkm, res, moves);
ParseEvolutionsIncompatibleMoves(pkm, moves, info.EncounterMoves.validTMHMMoves[1], ref res);
ParseEvolutionsIncompatibleMoves(pkm, res, moves, info.EncounterMoves.TMHMMoves[1]);
}
if (Legal.SpeciesEvolutionWithMove.Contains(pkm.Species))
@ -435,7 +454,7 @@ namespace PKHeX.Core
// Pokemon that evolved by leveling up while learning a specific move
// This pokemon could only have 3 moves from preevolutions that are not the move used to evolved
// including special and eggs moves before realearn generations
ParseEvolutionLevelupMove(pkm, moves, IncenseMovesLearned, ref res, info);
ParseEvolutionLevelupMove(pkm, res, moves, IncenseMovesLearned, info);
}
if (res.All(r => r != null))
@ -447,7 +466,7 @@ namespace PKHeX.Core
// Ignore Shedinja if the Encounter was also a Shedinja, assume null Encounter as a Nincada egg
// Check Shedinja evolved moves from Ninjask after egg moves
// Those moves could also be inherited egg moves
ParseShedinjaEvolveMoves(pkm, moves, ref res);
ParseShedinjaEvolveMoves(pkm, res, moves);
}
for (int m = 0; m < 4; m++)
@ -458,7 +477,7 @@ namespace PKHeX.Core
return res;
}
private static void ParseRedYellowIncompatibleMoves(PKM pkm, int[] moves, ref CheckMoveResult[] res)
private static void ParseRedYellowIncompatibleMoves(PKM pkm, IList<CheckMoveResult> res, int[] moves)
{
var incompatible = new List<int>();
if (pkm.Species == 134 && pkm.CurrentLevel < 47 && moves.Contains(151))
@ -485,9 +504,9 @@ namespace PKHeX.Core
res[m] = new CheckMoveResult(res[m], Severity.Invalid, V363, CheckIdentifier.Move);
}
}
private static void ParseEvolutionsIncompatibleMoves(PKM pkm, int[] moves, List<int> tmhm, ref CheckMoveResult[] res)
private static void ParseEvolutionsIncompatibleMoves(PKM pkm, IList<CheckMoveResult> res, int[] moves, List<int> tmhm)
{
var species = specieslist;
var species = SpeciesStrings;
var currentspecies = species[pkm.Species];
var previousspecies = string.Empty;
var incompatible_previous = new List<int>();
@ -512,9 +531,9 @@ namespace PKHeX.Core
if (134 <= pkm.Species && pkm.Species <= 136)
{
previousspecies = species[133];
var ExclusiveMoves = Legal.getExclusiveMoves(133, pkm.Species, 1, tmhm, moves);
var EeveeLevels = Legal.getMinLevelLearnMove(133, 1, ExclusiveMoves[0]);
var EvoLevels = Legal.getMaxLevelLearnMove(pkm.Species, 1, ExclusiveMoves[1]);
var ExclusiveMoves = Legal.GetExclusiveMoves(133, pkm.Species, 1, tmhm, moves);
var EeveeLevels = Legal.GetMinLevelLearnMove(133, 1, ExclusiveMoves[0]);
var EvoLevels = Legal.GetMaxLevelLearnMove(pkm.Species, 1, ExclusiveMoves[1]);
for (int i = 0; i < ExclusiveMoves[0].Count; i++)
{
@ -538,9 +557,9 @@ namespace PKHeX.Core
res[m] = new CheckMoveResult(res[m], Severity.Invalid, string.Format(V366, currentspecies, previousspecies), CheckIdentifier.Move);
}
}
private static void ParseShedinjaEvolveMoves(PKM pkm, int[] moves, ref CheckMoveResult[] res)
private static void ParseShedinjaEvolveMoves(PKM pkm, IList<CheckMoveResult> res, int[] moves)
{
List<int>[] ShedinjaEvoMoves = Legal.getShedinjaEvolveMoves(pkm);
List<int>[] ShedinjaEvoMoves = Legal.GetShedinjaEvolveMoves(pkm);
var ShedinjaEvoMovesLearned = new List<int>();
for (int gen = Math.Min(pkm.Format, 4); gen >= 3; gen--)
{
@ -564,7 +583,7 @@ namespace PKHeX.Core
foreach (int m in ShedinjaEvoMovesLearned)
res[m] = new CheckMoveResult(res[m], Severity.Invalid, V357, CheckIdentifier.Move);
}
private static void ParseEvolutionLevelupMove(PKM pkm, int[] moves, List<int> IncenseMovesLearned, ref CheckMoveResult[] res, LegalInfo info)
private static void ParseEvolutionLevelupMove(PKM pkm, IList<CheckMoveResult> res, int[] moves, List<int> IncenseMovesLearned, LegalInfo info)
{
// Ignore if there is an invalid move or an empty move, this validation is only for 4 non-empty moves that are all valid, but invalid as a 4 combination
// Ignore Mr. Mime and Sudowodoo from generations 1 to 3, they cant be evolved from Bonsly or Munchlax
@ -574,7 +593,7 @@ namespace PKHeX.Core
info.EncounterMatch.Species == pkm.Species)
return;
var ValidMoves = Legal.getValidPostEvolutionMoves(pkm, pkm.Species, info.EvoChainsAllGens, GameVersion.Any);
var ValidMoves = Legal.GetValidPostEvolutionMoves(pkm, pkm.Species, info.EvoChainsAllGens, GameVersion.Any);
// Add the evolution moves to valid moves in case some of this moves could not be learned after evolving
switch (pkm.Species)
{
@ -606,89 +625,90 @@ namespace PKHeX.Core
return;
for (int m = 0; m < 4; m++)
res[m] = new CheckMoveResult(res[m], Severity.Invalid, string.Format(V385, specieslist[pkm.Species]), CheckIdentifier.Move);
res[m] = new CheckMoveResult(res[m], Severity.Invalid, string.Format(V385, SpeciesStrings[pkm.Species]), CheckIdentifier.Move);
}
/* Similar to verifyRelearnEgg but in pre relearn generation is the moves what should match the expected order but only if the pokemon is inside an egg */
private static CheckMoveResult[] verifyPreRelearnEggBase(PKM pkm, int[] Moves, List<int> baseMoves, List<int> eggmoves, List<int> lvlmoves, List<int> tmhmmoves, List<int> tutormoves, List<int> specialmoves, bool AllowInherited, GameVersion ver)
private static CheckMoveResult[] VerifyPreRelearnEggBase(PKM pkm, int[] Moves, MoveInfoSet infoset, GameVersion ver)
{
CheckMoveResult[] res = new CheckMoveResult[4];
var gen = pkm.GenNumber;
// Obtain level1 moves
int baseCt = baseMoves.Count;
int baseCt = infoset.BaseMoves.Count;
if (baseCt > 4) baseCt = 4;
// Obtain Inherited moves
var inherited = Moves.Where(m => m != 0 && (!baseMoves.Contains(m) || specialmoves.Contains(m) || eggmoves.Contains(m) || lvlmoves.Contains(m) || tmhmmoves.Contains(m) || tutormoves.Contains(m))).ToList();
var inherited = Moves.Where(m => m != 0 && (!infoset.BaseMoves.Contains(m) || infoset.SpecialMoves.Contains(m) || infoset.EggMoves.Contains(m) || infoset.LvlMoves.Contains(m) || infoset.TMHMMoves.Contains(m) || infoset.TutorMoves.Contains(m))).ToList();
int inheritCt = inherited.Count;
// Get required amount of base moves
int unique = baseMoves.Concat(inherited).Distinct().Count();
int unique = infoset.BaseMoves.Concat(inherited).Distinct().Count();
int reqBase = inheritCt == 4 || baseCt + inheritCt > 4 ? 4 - inheritCt : baseCt;
if (Moves.Where(m => m != 0).Count() < Math.Min(4, baseMoves.Count))
if (Moves.Where(m => m != 0).Count() < Math.Min(4, infoset.BaseMoves.Count))
reqBase = Math.Min(4, unique);
var em = string.Empty;
var moveoffset = 0;
// Check if the required amount of Base Egg Moves are present.
for (int i = moveoffset; i < reqBase; i++)
for (int i = 0; i < reqBase; i++)
{
if (baseMoves.Contains(Moves[i]))
res[i] = new CheckMoveResult(MoveSource.Initial, gen, Severity.Valid, V179, CheckIdentifier.Move);
else
if (infoset.BaseMoves.Contains(Moves[i]))
{
// mark remaining base egg moves missing
for (int z = i; z < reqBase; z++)
res[z] = new CheckMoveResult(MoveSource.Initial, gen, Severity.Invalid, V180, CheckIdentifier.Move);
// provide the list of suggested base moves for the last required slot
em = string.Join(", ", baseMoves.Select(m => m >= movelist.Length ? V190 : movelist[m]));
break;
res[i] = new CheckMoveResult(MoveSource.Initial, gen, Severity.Valid, V179, CheckIdentifier.Move);
continue;
}
// mark remaining base egg moves missing
for (int z = i; z < reqBase; z++)
res[z] = new CheckMoveResult(MoveSource.Initial, gen, Severity.Invalid, V180, CheckIdentifier.Move);
// provide the list of suggested base moves for the last required slot
em = string.Join(", ", infoset.BaseMoves.Select(m => m >= MoveStrings.Length ? V190 : MoveStrings[m]));
break;
}
moveoffset += reqBase;
int moveoffset = reqBase;
int endSpecial = moveoffset + infoset.SpecialMoves.Count;
// Check also if the required amount of Special Egg Moves are present, ir are after base moves
for (int i = moveoffset; i < moveoffset + specialmoves.Count; i++)
for (int i = moveoffset; i < endSpecial; i++)
{
if (specialmoves.Contains(Moves[i]))
res[i] = new CheckMoveResult(MoveSource.SpecialEgg, gen, Severity.Valid, V333, CheckIdentifier.Move);
else
if (infoset.SpecialMoves.Contains(Moves[i]))
{
// mark remaining special egg moves missing
for (int z = i; z < moveoffset + specialmoves.Count; z++)
res[z] = new CheckMoveResult(MoveSource.SpecialEgg, gen, Severity.Invalid, V342, CheckIdentifier.Move);
// provide the list of suggested base moves and species moves for the last required slot
if (!string.IsNullOrEmpty(em)) em += ", ";
else
em = string.Join(", ", baseMoves.Select(m => m >= movelist.Length ? V190 : movelist[m])) + ", ";
em += string.Join(", ", specialmoves.Select(m => m >= movelist.Length ? V190 : movelist[m]));
break;
res[i] = new CheckMoveResult(MoveSource.SpecialEgg, gen, Severity.Valid, V333, CheckIdentifier.Move);
continue;
}
// Not in special moves, mark remaining special egg moves missing
for (int z = i; z < endSpecial; z++)
res[z] = new CheckMoveResult(MoveSource.SpecialEgg, gen, Severity.Invalid, V342, CheckIdentifier.Move);
// provide the list of suggested base moves and species moves for the last required slot
if (!string.IsNullOrEmpty(em)) em += ", ";
else
em = string.Join(", ", infoset.BaseMoves.Select(m => m >= MoveStrings.Length ? V190 : MoveStrings[m])) + ", ";
em += string.Join(", ", infoset.SpecialMoves.Select(m => m >= MoveStrings.Length ? V190 : MoveStrings[m]));
break;
}
if (!string.IsNullOrEmpty(em))
res[reqBase > 0 ? reqBase - 1 : 0].Comment = string.Format(Environment.NewLine + V343, em);
// Non-Base moves that can magically appear in the regular movepool
if (pkm.GenNumber >= 3 && Legal.LightBall.Contains(pkm.Species))
eggmoves.Add(344);
infoset.EggMoves.Add(344);
// Inherited moves appear after the required base moves.
var AllowInheritedSeverity = AllowInherited ? Severity.Valid : Severity.Invalid;
for (int i = reqBase + specialmoves.Count; i < 4; i++)
var AllowInheritedSeverity = infoset.AllowInherited ? Severity.Valid : Severity.Invalid;
for (int i = reqBase + infoset.SpecialMoves.Count; i < 4; i++)
{
if (Moves[i] == 0) // empty
res[i] = new CheckMoveResult(MoveSource.None, gen, Severity.Valid, V167, CheckIdentifier.Move);
else if (eggmoves.Contains(Moves[i])) // inherited egg move
res[i] = new CheckMoveResult(MoveSource.EggMove, gen, AllowInheritedSeverity, AllowInherited ? V344 : V341, CheckIdentifier.Move);
else if (lvlmoves.Contains(Moves[i])) // inherited lvl moves
res[i] = new CheckMoveResult(MoveSource.InheritLevelUp, gen, AllowInheritedSeverity, AllowInherited ? V345 : V347, CheckIdentifier.Move);
else if (tmhmmoves.Contains(Moves[i])) // inherited TMHM moves
res[i] = new CheckMoveResult(MoveSource.TMHM, gen, AllowInheritedSeverity, AllowInherited ? V349 : V350, CheckIdentifier.Move);
else if (tutormoves.Contains(Moves[i])) // inherited tutor moves
res[i] = new CheckMoveResult(MoveSource.Tutor, gen, AllowInheritedSeverity, AllowInherited ? V346 : V348, CheckIdentifier.Move);
else if (infoset.EggMoves.Contains(Moves[i])) // inherited egg move
res[i] = new CheckMoveResult(MoveSource.EggMove, gen, AllowInheritedSeverity, infoset.AllowInherited ? V344 : V341, CheckIdentifier.Move);
else if (infoset.LvlMoves.Contains(Moves[i])) // inherited lvl moves
res[i] = new CheckMoveResult(MoveSource.InheritLevelUp, gen, AllowInheritedSeverity, infoset.AllowInherited ? V345 : V347, CheckIdentifier.Move);
else if (infoset.TMHMMoves.Contains(Moves[i])) // inherited TMHM moves
res[i] = new CheckMoveResult(MoveSource.TMHM, gen, AllowInheritedSeverity, infoset.AllowInherited ? V349 : V350, CheckIdentifier.Move);
else if (infoset.TutorMoves.Contains(Moves[i])) // inherited tutor moves
res[i] = new CheckMoveResult(MoveSource.Tutor, gen, AllowInheritedSeverity, infoset.AllowInherited ? V346 : V348, CheckIdentifier.Move);
else // not inheritable, flag
res[i] = new CheckMoveResult(MoveSource.Unknown, gen, Severity.Invalid, V340, CheckIdentifier.Move);
}
@ -696,7 +716,7 @@ namespace PKHeX.Core
return res;
}
private static void verifyNoEmptyDuplicates(int[] Moves, CheckMoveResult[] res)
private static void VerifyNoEmptyDuplicates(int[] Moves, CheckMoveResult[] res)
{
bool emptySlot = false;
for (int i = 0; i < 4; i++)
@ -717,7 +737,7 @@ namespace PKHeX.Core
case 2:
var lvlG1 = info.EncounterMatch?.LevelMin + 1 ?? 6;
if (lvlG1 != defaultLvlG1)
EncounterMoves.validLevelUpMoves[1] = Legal.getValidMoves(pkm, info.EvoChainsAllGens[1], generation: 1, minLvLG1: lvlG1, LVL: true, Tutor: false, Machine: false, MoveReminder: false).ToList();
EncounterMoves.LevelUpMoves[1] = Legal.GetValidMoves(pkm, info.EvoChainsAllGens[1], generation: 1, minLvLG1: lvlG1, LVL: true, Tutor: false, Machine: false, MoveReminder: false).ToList();
break;
}
}
@ -729,11 +749,11 @@ namespace PKHeX.Core
case 2:
var lvlG2 = info.EncounterMatch?.LevelMin + 1 ?? 6;
if (lvlG2 != defaultLvlG2)
EncounterMoves.validLevelUpMoves[2] = Legal.getValidMoves(pkm, info.EvoChainsAllGens[2], generation: 2, minLvLG2: defaultLvlG2, LVL: true, Tutor: false, Machine: false, MoveReminder: false).ToList();
EncounterMoves.LevelUpMoves[2] = Legal.GetValidMoves(pkm, info.EvoChainsAllGens[2], generation: 2, minLvLG2: defaultLvlG2, LVL: true, Tutor: false, Machine: false, MoveReminder: false).ToList();
break;
}
}
private static int[] getGenMovesCheckOrder(PKM pkm)
private static int[] GetGenMovesCheckOrder(PKM pkm)
{
if (pkm.Format == 1)
return new[] { 1, 2 };
@ -749,25 +769,25 @@ namespace PKHeX.Core
order[i] = pkm.Format - i;
return order;
}
private static ValidEncounterMoves getEncounterValidMoves(PKM pkm, LegalInfo info)
private static ValidEncounterMoves GetEncounterValidMoves(PKM pkm, LegalInfo info)
{
var minLvLG1 = pkm.GenNumber <= 2 ? info.EncounterMatch.LevelMin + 1 : 0;
var minLvlG2 = Legal.AllowGen2MoveReminder ? 1 : info.EncounterMatch.LevelMin + 1;
var encounterspecies = info.EncounterMatch.Species;
var EvoChainsAllGens = info.EvoChainsAllGens;
// If encounter species is the same species from the first match, the one in variable EncounterMatch, its evolution chains is already in EvoChainsAllGens
var LevelMoves = Legal.getValidMovesAllGens(pkm, EvoChainsAllGens, minLvLG1: minLvLG1, minLvLG2: minLvlG2, Tutor: false, Machine: false, RemoveTransferHM: false);
var TMHMMoves = Legal.getValidMovesAllGens(pkm, EvoChainsAllGens, LVL: false, Tutor: false, MoveReminder: false, RemoveTransferHM: false);
var TutorMoves = Legal.getValidMovesAllGens(pkm, EvoChainsAllGens, LVL: false, Machine: false, MoveReminder: false, RemoveTransferHM: false);
var LevelMoves = Legal.GetValidMovesAllGens(pkm, EvoChainsAllGens, minLvLG1: minLvLG1, minLvLG2: minLvlG2, Tutor: false, Machine: false, RemoveTransferHM: false);
var TMHMMoves = Legal.GetValidMovesAllGens(pkm, EvoChainsAllGens, LVL: false, Tutor: false, MoveReminder: false, RemoveTransferHM: false);
var TutorMoves = Legal.GetValidMovesAllGens(pkm, EvoChainsAllGens, LVL: false, Machine: false, MoveReminder: false, RemoveTransferHM: false);
return new ValidEncounterMoves
{
EncounterSpecies = encounterspecies,
validLevelUpMoves = LevelMoves,
validTMHMMoves = TMHMMoves,
validTutorMoves = TutorMoves,
LevelUpMoves = LevelMoves,
TMHMMoves = TMHMMoves,
TutorMoves = TutorMoves,
EvolutionChains = EvoChainsAllGens,
minLvlG1 = minLvLG1,
minLvlG2 = minLvlG2
MinimumLevelGen1 = minLvLG1,
MinimumLevelGen2 = minLvlG2
};
}
}

View file

@ -8,28 +8,28 @@ namespace PKHeX.Core
{
public static class VerifyRelearnMoves
{
public static CheckResult[] verifyRelearn(PKM pkm, LegalInfo info)
public static CheckResult[] VerifyRelearn(PKM pkm, LegalInfo info)
{
if (pkm.GenNumber < 6 || pkm.VC1)
return verifyRelearnNone(pkm, info);
return VerifyRelearnNone(pkm, info);
if (info.EncounterMatch is EncounterLink l)
return verifyRelearnSpecifiedMoveset(pkm, info, l.RelearnMoves);
return VerifyRelearnSpecifiedMoveset(pkm, info, l.RelearnMoves);
if (info.EncounterMatch is MysteryGift g)
return verifyRelearnSpecifiedMoveset(pkm, info, g.RelearnMoves);
return VerifyRelearnSpecifiedMoveset(pkm, info, g.RelearnMoves);
if (info.EncounterMatch is EncounterStatic s)
return verifyRelearnSpecifiedMoveset(pkm, info, s.Relearn);
return VerifyRelearnSpecifiedMoveset(pkm, info, s.Relearn);
if (info.EncounterMatch is EncounterEgg e)
return verifyRelearnEggBase(pkm, info, e);
return VerifyRelearnEggBase(pkm, info, e);
if (pkm.RelearnMove1 != 0 && info.EncounterMatch is EncounterSlot z && z.DexNav && EncounterGenerator.getDexNavValid(pkm))
return verifyRelearnDexNav(pkm, info);
if (pkm.RelearnMove1 != 0 && info.EncounterMatch is EncounterSlot z && z.Permissions.DexNav && EncounterGenerator.IsDexNavValid(pkm))
return VerifyRelearnDexNav(pkm, info);
return verifyRelearnNone(pkm, info);
return VerifyRelearnNone(pkm, info);
}
private static CheckResult[] verifyRelearnSpecifiedMoveset(PKM pkm, LegalInfo info, int[] moves)
private static CheckResult[] VerifyRelearnSpecifiedMoveset(PKM pkm, LegalInfo info, int[] moves)
{
CheckResult[] res = new CheckResult[4];
int[] RelearnMoves = pkm.RelearnMoves;
@ -37,19 +37,19 @@ namespace PKHeX.Core
for (int i = 0; i < 4; i++)
res[i] = moves[i] != RelearnMoves[i]
? new CheckResult(Severity.Invalid, string.Format(V178, movelist[moves[i]]), CheckIdentifier.RelearnMove)
? new CheckResult(Severity.Invalid, string.Format(V178, MoveStrings[moves[i]]), CheckIdentifier.RelearnMove)
: new CheckResult(CheckIdentifier.RelearnMove);
info.RelearnBase = moves;
return res;
}
private static CheckResult[] verifyRelearnDexNav(PKM pkm, LegalInfo info)
private static CheckResult[] VerifyRelearnDexNav(PKM pkm, LegalInfo info)
{
CheckResult[] res = new CheckResult[4];
int[] RelearnMoves = pkm.RelearnMoves;
// DexNav Pokémon can have 1 random egg move as a relearn move.
res[0] = !Legal.getValidRelearn(pkm, Legal.getBaseEggSpecies(pkm),true).Contains(RelearnMoves[0])
res[0] = !Legal.GetValidRelearn(pkm, Legal.GetBaseEggSpecies(pkm),true).Contains(RelearnMoves[0])
? new CheckResult(Severity.Invalid, V183, CheckIdentifier.RelearnMove)
: new CheckResult(CheckIdentifier.RelearnMove);
@ -66,7 +66,7 @@ namespace PKHeX.Core
return res;
}
private static CheckResult[] verifyRelearnNone(PKM pkm, LegalInfo info)
private static CheckResult[] VerifyRelearnNone(PKM pkm, LegalInfo info)
{
CheckResult[] res = new CheckResult[4];
int[] RelearnMoves = pkm.RelearnMoves;
@ -80,7 +80,7 @@ namespace PKHeX.Core
return res;
}
private static CheckResult[] verifyRelearnEggBase(PKM pkm, LegalInfo info, EncounterEgg e)
private static CheckResult[] VerifyRelearnEggBase(PKM pkm, LegalInfo info, EncounterEgg e)
{
int[] RelearnMoves = pkm.RelearnMoves;
info.RelearnBase = new int[4];
@ -90,12 +90,12 @@ namespace PKHeX.Core
var inheritLvlMoves = pkm.PersonalInfo.Gender > 0 && pkm.PersonalInfo.Gender < 255 || Legal.MixedGenderBreeding.Contains(e.Species);
// Obtain level1 moves
List<int> baseMoves = new List<int>(Legal.getBaseEggMoves(pkm, e.Species, e.Game, 1));
List<int> baseMoves = new List<int>(Legal.GetBaseEggMoves(pkm, e.Species, e.Game, 1));
int baseCt = baseMoves.Count;
if (baseCt > 4) baseCt = 4;
// Obtain Inherited moves
var inheritMoves = Legal.getValidRelearn(pkm, e.Species, inheritLvlMoves).ToList();
var inheritMoves = Legal.GetValidRelearn(pkm, e.Species, inheritLvlMoves).ToList();
var inherited = RelearnMoves.Where(m => m != 0 && (!baseMoves.Contains(m) || inheritMoves.Contains(m))).ToList();
int inheritCt = inherited.Count;
@ -118,7 +118,7 @@ namespace PKHeX.Core
res[z] = new CheckResult(Severity.Invalid, V180, CheckIdentifier.RelearnMove);
// provide the list of suggested base moves for the last required slot
string em = string.Join(", ", baseMoves.Select(m => m >= movelist.Length ? V190 : movelist[m]));
string em = string.Join(", ", baseMoves.Select(m => m >= MoveStrings.Length ? V190 : MoveStrings[m]));
res[reqBase - 1].Comment += string.Format(Environment.NewLine + V181, em);
break;
}
@ -132,7 +132,7 @@ namespace PKHeX.Core
// If any splitbreed moves are invalid, flag accordingly
var splitInvalid = false;
var splitMoves = e.SplitBreed ? Legal.getValidRelearn(pkm, Legal.getBaseEggSpecies(pkm), inheritLvlMoves).ToList() : new List<int>();
var splitMoves = e.SplitBreed ? Legal.GetValidRelearn(pkm, Legal.GetBaseEggSpecies(pkm), inheritLvlMoves).ToList() : new List<int>();
// Inherited moves appear after the required base moves.
for (int i = reqBase; i < 4; i++)
@ -149,13 +149,13 @@ namespace PKHeX.Core
if (splitInvalid)
{
var splitSpecies = Legal.getBaseEggSpecies(pkm);
var splitSpecies = Legal.GetBaseEggSpecies(pkm);
for (int i = reqBase; i < 4; i++)
{
if (inheritMoves.Contains(RelearnMoves[i]) && !splitMoves.Contains(RelearnMoves[i]))
res[i] = new CheckResult(Severity.Invalid, string.Format(V379, specieslist[splitSpecies], specieslist[e.Species]), CheckIdentifier.RelearnMove);
res[i] = new CheckResult(Severity.Invalid, string.Format(V379, SpeciesStrings[splitSpecies], SpeciesStrings[e.Species]), CheckIdentifier.RelearnMove);
if (!inheritMoves.Contains(RelearnMoves[i]) && splitMoves.Contains(RelearnMoves[i]))
res[i] = new CheckResult(Severity.Invalid, string.Format(V379, specieslist[e.Species], specieslist[splitSpecies]), CheckIdentifier.RelearnMove);
res[i] = new CheckResult(Severity.Invalid, string.Format(V379, SpeciesStrings[e.Species], SpeciesStrings[splitSpecies]), CheckIdentifier.RelearnMove);
}
}

View file

@ -1,4 +1,6 @@
namespace PKHeX.Core
using static PKHeX.Core.LegalityCheckStrings;
namespace PKHeX.Core
{
public enum Severity
{
@ -8,4 +10,25 @@
Valid = 1,
NotImplemented = 2,
}
public static partial class Extensions
{
/// <summary>
/// Converts a Check result Severity determination (Valid/Invalid/etc) to the localized string.
/// </summary>
/// <param name="s"><see cref="Severity"/> value to convert to string.</param>
/// <returns>Localized <see cref="string"/>.</returns>
public static string Description(this Severity s)
{
switch (s)
{
case Severity.Indeterminate: return V500;
case Severity.Invalid: return V501;
case Severity.Fishy: return V502;
case Severity.Valid: return V503;
default: return V504;
}
}
}
}

View file

@ -10,7 +10,7 @@
public uint ESV { get; set; }
public int EncounterSlot(SlotType t) => SlotRange.GetSlot(t, ESV, FrameType);
public void setOriginSeed(int Offset) => OriginSeed = RNG.Reverse(Seed, Offset);
public void SetOriginSeed(int Offset) => OriginSeed = RNG.Reverse(Seed, Offset);
public bool LevelSlotModified => Lead > LeadRequired.SynchronizeFail;
public uint OriginSeed;

View file

@ -10,7 +10,7 @@ namespace PKHeX.Core
/// <param name="pidiv">Matched <see cref="PIDIV"/> containing <see cref="PIDIV.RNG"/> info and <see cref="PIDIV.OriginSeed"/>.</param>
/// <param name="pk"><see cref="PKM"/> object containing various accessible information required for the encounter.</param>
/// <returns><see cref="IEnumerable{Frame}"/> to yield possible encounter details for further filtering</returns>
public static IEnumerable<Frame> getFrames(PIDIV pidiv, PKM pk)
public static IEnumerable<Frame> GetFrames(PIDIV pidiv, PKM pk)
{
FrameGenerator info = new FrameGenerator(pidiv, pk);
if (info.FrameType == FrameType.None)
@ -19,25 +19,25 @@ namespace PKHeX.Core
info.Nature = pk.EncryptionConstant % 25;
// gather possible nature determination seeds until a same-nature PID breaks the unrolling
IEnumerable<SeedInfo> seeds = SeedInfo.getSeedsUntilNature(pidiv, info);
IEnumerable<SeedInfo> seeds = SeedInfo.GetSeedsUntilNature(pidiv, info);
var frames = pidiv.Type == PIDType.CuteCharm
? filterCuteCharm(seeds, pidiv, info)
: filterNatureSync(seeds, pidiv, info);
? FilterCuteCharm(seeds, pidiv, info)
: FilterNatureSync(seeds, pidiv, info);
var refined = refineFrames(frames, info);
var refined = RefineFrames(frames, info);
foreach (var z in refined)
yield return z;
}
private static IEnumerable<Frame> refineFrames(IEnumerable<Frame> frames, FrameGenerator info)
private static IEnumerable<Frame> RefineFrames(IEnumerable<Frame> frames, FrameGenerator info)
{
return info.FrameType == FrameType.MethodH
? refineFrames3(frames, info)
: refineFrames4(frames, info);
? RefineFrames3(frames, info)
: RefineFrames4(frames, info);
}
private static IEnumerable<Frame> refineFrames3(IEnumerable<Frame> frames, FrameGenerator info)
private static IEnumerable<Frame> RefineFrames3(IEnumerable<Frame> frames, FrameGenerator info)
{
var list = new List<Frame>();
foreach (var f in frames)
@ -76,7 +76,7 @@ namespace PKHeX.Core
yield return info.GetFrame(prev, LeadRequired.MagnetPull, rand);
}
}
private static IEnumerable<Frame> refineFrames4(IEnumerable<Frame> frames, FrameGenerator info)
private static IEnumerable<Frame> RefineFrames4(IEnumerable<Frame> frames, FrameGenerator info)
{
var list = new List<Frame>();
foreach (var f in frames)
@ -121,7 +121,7 @@ namespace PKHeX.Core
/// <param name="pidiv">PIDIV Info for the frame</param>
/// <param name="info">Search Info for the frame</param>
/// <returns>Possible matches to the Nature Lock frame generation pattern</returns>
private static IEnumerable<Frame> filterNatureSync(IEnumerable<SeedInfo> seeds, PIDIV pidiv, FrameGenerator info)
private static IEnumerable<Frame> FilterNatureSync(IEnumerable<SeedInfo> seeds, PIDIV pidiv, FrameGenerator info)
{
foreach (var seed in seeds)
{
@ -158,7 +158,7 @@ namespace PKHeX.Core
/// <param name="pidiv">PIDIV Info for the frame</param>
/// <param name="info">Search Info for the frame</param>
/// <returns>Possible matches to the Cute Charm frame generation pattern</returns>
private static IEnumerable<Frame> filterCuteCharm(IEnumerable<SeedInfo> seeds, PIDIV pidiv, FrameGenerator info)
private static IEnumerable<Frame> FilterCuteCharm(IEnumerable<SeedInfo> seeds, PIDIV pidiv, FrameGenerator info)
{
foreach (var seed in seeds)
{

View file

@ -47,8 +47,8 @@
var gr = pk.PersonalInfo.Gender;
Gendered = true;
GenderLow = getGenderMinMax(gender, gr, false);
GenderHigh = getGenderMinMax(gender, gr, true);
GenderLow = GetGenderMinMax(gender, gr, false);
GenderHigh = GetGenderMinMax(gender, gr, true);
return;
// Method J
@ -79,7 +79,7 @@
/// <param name="ratio">Gender Ratio</param>
/// <param name="max">Return Max (or Min)</param>
/// <returns>Returns the maximum or minimum gender value that corresponds to the input gender ratio.</returns>
private static int getGenderMinMax(int gender, int ratio, bool max)
private static int GetGenderMinMax(int gender, int ratio, bool max)
{
if (ratio == 0 || ratio == 0xFE || ratio == 0xFF)
gender = 2;

View file

@ -2,11 +2,12 @@
namespace PKHeX.Core
{
public class SeedInfo
public struct SeedInfo
{
public uint Seed;
public bool Charm3;
public static IEnumerable<SeedInfo> getSeedsUntilNature(PIDIV pidiv, FrameGenerator info)
public static IEnumerable<SeedInfo> GetSeedsUntilNature(PIDIV pidiv, FrameGenerator info)
{
bool reverse = pidiv.Type.IsReversedPID();
bool charm3 = false;
@ -24,7 +25,7 @@ namespace PKHeX.Core
var pid = reverse ? a << 16 | b : b << 16 | a;
// Process Conditions
switch (verifyPIDCriteria(pid, info))
switch (VerifyPIDCriteria(pid, info))
{
case LockInfo.Pass:
yield break;
@ -39,8 +40,7 @@ namespace PKHeX.Core
yield return new SeedInfo { Seed = s1, Charm3 = charm3 };
}
}
private static LockInfo verifyPIDCriteria(uint pid, FrameGenerator info)
private static LockInfo VerifyPIDCriteria(uint pid, FrameGenerator info)
{
// Nature locks are always a given
var nval = pid % 25;

View file

@ -2,15 +2,15 @@
{
public static class SlotRange
{
private static readonly Range[] H_OldRod = getRanges(70, 30);
private static readonly Range[] H_GoodRod = getRanges(60, 20, 20);
private static readonly Range[] H_SuperRod = getRanges(40, 30, 15, 10, 5);
private static readonly Range[] H_Surf = getRanges(60, 30, 5, 4, 1);
private static readonly Range[] H_Regular = getRanges(20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1);
private static readonly Range[] H_OldRod = GetRanges(70, 30);
private static readonly Range[] H_GoodRod = GetRanges(60, 20, 20);
private static readonly Range[] H_SuperRod = GetRanges(40, 30, 15, 10, 5);
private static readonly Range[] H_Surf = GetRanges(60, 30, 5, 4, 1);
private static readonly Range[] H_Regular = GetRanges(20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1);
private static readonly Range[] J_SuperRod = getRanges(40, 40, 15, 4, 1);
private static readonly Range[] J_SuperRod = GetRanges(40, 40, 15, 4, 1);
private static readonly Range[] K_BCC = Reverse(H_Regular);
private static readonly Range[] K_Headbutt = getRanges(50, 15, 15, 10, 5, 5);
private static readonly Range[] K_Headbutt = GetRanges(50, 15, 15, 10, 5, 5);
public static int GetSlot(SlotType type, uint rand, FrameType t)
{
@ -86,19 +86,19 @@
}
}
private class Range
private struct Range
{
public Range(uint min, uint max)
internal Range(uint min, uint max)
{
Min = min;
Max = max;
}
public uint Min { get; }
public uint Max { get; }
internal uint Min { get; }
internal uint Max { get; }
}
private static Range[] getRanges(params uint[] rates)
private static Range[] GetRanges(params uint[] rates)
{
var len = rates.Length;
var arr = new Range[len];

View file

@ -12,7 +12,7 @@ namespace PKHeX.Core
public static class LockFinder
{
// Message Passing
private class SeedPID
private sealed class SeedPID
{
public uint PID;
public uint Seed;

View file

@ -28,41 +28,41 @@ namespace PKHeX.Core
IVs[i] = (uint)iIVs[i];
PIDIV pidiv;
if (getLCRNGMatch(top, bot, IVs, out pidiv))
if (GetLCRNGMatch(top, bot, IVs, out pidiv))
return pidiv;
if (pk.Species == 201 && getLCRNGUnownMatch(top, bot, IVs, out pidiv)) // frlg only
if (pk.Species == 201 && GetLCRNGUnownMatch(top, bot, IVs, out pidiv)) // frlg only
return pidiv;
if (getXDRNGMatch(top, bot, IVs, out pidiv))
if (GetXDRNGMatch(top, bot, IVs, out pidiv))
return pidiv;
// Special cases
if (getLCRNGRoamerMatch(top, bot, IVs, out pidiv))
if (GetLCRNGRoamerMatch(top, bot, IVs, out pidiv))
return pidiv;
if (getChannelMatch(top, bot, IVs, out pidiv))
if (GetChannelMatch(top, bot, IVs, out pidiv))
return pidiv;
if (getMG4Match(pid, IVs, out pidiv))
if (GetMG4Match(pid, IVs, out pidiv))
return pidiv;
if (pk.IsShiny)
{
if (getChainShinyMatch(pk, pid, IVs, out pidiv))
if (GetChainShinyMatch(pk, pid, IVs, out pidiv))
return pidiv;
if (getModifiedPID(pk, pid, out pidiv))
if (GetModifiedPID(pk, pid, out pidiv))
return pidiv;
}
if (pid <= 0xFF && getCuteCharmMatch(pk, pid, out pidiv))
if (pid <= 0xFF && GetCuteCharmMatch(pk, pid, out pidiv))
return pidiv;
if (getBACDMatch(pk, pid, IVs, out pidiv))
if (GetBACDMatch(pk, pid, IVs, out pidiv))
return pidiv;
return new PIDIV {Type=PIDType.None, NoSeed=true}; // no match
}
private static bool getLCRNGMatch(uint top, uint bot, uint[] IVs, out PIDIV pidiv)
private static bool GetLCRNGMatch(uint top, uint bot, uint[] IVs, out PIDIV pidiv)
{
var reg = getSeedsFromPID(RNG.LCRNG, top, bot);
var iv1 = getIVChunk(IVs, 0);
var iv2 = getIVChunk(IVs, 3);
var reg = GetSeedsFromPID(RNG.LCRNG, top, bot);
var iv1 = GetIVChunk(IVs, 0);
var iv2 = GetIVChunk(IVs, 3);
foreach (var seed in reg)
{
// A and B are already used by PID
@ -108,12 +108,12 @@ namespace PKHeX.Core
pidiv = null;
return false;
}
private static bool getLCRNGUnownMatch(uint top, uint bot, uint[] IVs, out PIDIV pidiv)
private static bool GetLCRNGUnownMatch(uint top, uint bot, uint[] IVs, out PIDIV pidiv)
{
// this is an exact copy of LCRNG 1,2,4 matching, except the PID has its halves switched (BACD, BADE, BACE)
var reg = getSeedsFromPID(RNG.LCRNG, bot, top); // reversed!
var iv1 = getIVChunk(IVs, 0);
var iv2 = getIVChunk(IVs, 3);
var reg = GetSeedsFromPID(RNG.LCRNG, bot, top); // reversed!
var iv1 = GetIVChunk(IVs, 0);
var iv2 = GetIVChunk(IVs, 3);
foreach (var seed in reg)
{
// A and B are already used by PID
@ -159,15 +159,15 @@ namespace PKHeX.Core
pidiv = null;
return false;
}
private static bool getLCRNGRoamerMatch(uint top, uint bot, uint[] IVs, out PIDIV pidiv)
private static bool GetLCRNGRoamerMatch(uint top, uint bot, uint[] IVs, out PIDIV pidiv)
{
if (IVs.Skip(2).Any(iv => iv != 0) || IVs[1] > 7)
{
pidiv = null;
return false;
}
var iv1 = getIVChunk(IVs, 0);
var reg = getSeedsFromPID(RNG.LCRNG, top, bot);
var iv1 = GetIVChunk(IVs, 0);
var reg = GetSeedsFromPID(RNG.LCRNG, top, bot);
foreach (var seed in reg)
{
// Only the first 8 bits are kept
@ -181,15 +181,15 @@ namespace PKHeX.Core
pidiv = null;
return false;
}
private static bool getXDRNGMatch(uint top, uint bot, uint[] IVs, out PIDIV pidiv)
private static bool GetXDRNGMatch(uint top, uint bot, uint[] IVs, out PIDIV pidiv)
{
var xdc = getSeedsFromPID(RNG.XDRNG, bot, top);
var xdc = GetSeedsFromPID(RNG.XDRNG, bot, top);
foreach (var seed in xdc)
{
var B = RNG.XDRNG.Prev(seed);
var A = RNG.XDRNG.Prev(B);
if (!getIVs(A >> 16, B >> 16).SequenceEqual(IVs))
if (!GetIVs(A >> 16, B >> 16).SequenceEqual(IVs))
continue;
pidiv = new PIDIV {OriginSeed = RNG.XDRNG.Prev(A), RNG = RNG.XDRNG, Type = PIDType.CXD};
@ -198,13 +198,13 @@ namespace PKHeX.Core
pidiv = null;
return false;
}
private static bool getChannelMatch(uint top, uint bot, uint[] IVs, out PIDIV pidiv)
private static bool GetChannelMatch(uint top, uint bot, uint[] IVs, out PIDIV pidiv)
{
var channel = getSeedsFromPID(RNG.XDRNG, bot, top ^ 0x8000);
var channel = GetSeedsFromPID(RNG.XDRNG, bot, top ^ 0x8000);
foreach (var seed in channel)
{
var E = RNG.XDRNG.Advance(seed, 5);
if (!getIVs(RNG.XDRNG, E).SequenceEqual(IVs))
if (!GetIVs(RNG.XDRNG, E).SequenceEqual(IVs))
continue;
pidiv = new PIDIV {OriginSeed = RNG.XDRNG.Prev(seed), RNG = RNG.XDRNG, Type = PIDType.Channel};
@ -213,16 +213,16 @@ namespace PKHeX.Core
pidiv = null;
return false;
}
private static bool getMG4Match(uint pid, uint[] IVs, out PIDIV pidiv)
private static bool GetMG4Match(uint pid, uint[] IVs, out PIDIV pidiv)
{
uint mg4Rev = RNG.ARNG.Prev(pid);
var mg4 = getSeedsFromPID(RNG.LCRNG, mg4Rev >> 16, mg4Rev & 0xFFFF);
var mg4 = GetSeedsFromPID(RNG.LCRNG, mg4Rev >> 16, mg4Rev & 0xFFFF);
foreach (var seed in mg4)
{
var B = RNG.LCRNG.Advance(seed, 2);
var C = RNG.LCRNG.Next(B);
var D = RNG.LCRNG.Next(C);
if (!getIVs(C >> 16, D >> 16).SequenceEqual(IVs))
if (!GetIVs(C >> 16, D >> 16).SequenceEqual(IVs))
continue;
pidiv = new PIDIV {OriginSeed = seed, RNG = RNG.LCRNG, Type = PIDType.G4MGAntiShiny};
@ -231,7 +231,7 @@ namespace PKHeX.Core
pidiv = null;
return false;
}
private static bool getModifiedPID(PKM pk, uint pid, out PIDIV pidiv)
private static bool GetModifiedPID(PKM pk, uint pid, out PIDIV pidiv)
{
var low = pid & 0xFFFF;
// generation 5 shiny PIDs
@ -248,7 +248,7 @@ namespace PKHeX.Core
pidiv = null;
return false;
}
private static bool getCuteCharmMatch(PKM pk, uint pid, out PIDIV pidiv)
private static bool GetCuteCharmMatch(PKM pk, uint pid, out PIDIV pidiv)
{
int genderValue = pk.Gender;
switch (genderValue)
@ -277,15 +277,15 @@ namespace PKHeX.Core
pidiv = null;
return false;
}
private static bool getChainShinyMatch(PKM pk, uint pid, uint[] IVs, out PIDIV pidiv)
private static bool GetChainShinyMatch(PKM pk, uint pid, uint[] IVs, out PIDIV pidiv)
{
// 13 shiny bits
// PIDH & 7
// PIDL & 7
// IVs
var bot = getIVChunk(IVs, 0);
var top = getIVChunk(IVs, 3);
var reg = getSeedsFromIVs(RNG.LCRNG, top, bot);
var bot = GetIVChunk(IVs, 0);
var top = GetIVChunk(IVs, 3);
var reg = GetSeedsFromIVs(RNG.LCRNG, top, bot);
foreach (var seed in reg)
{
// check the individual bits
@ -322,11 +322,11 @@ namespace PKHeX.Core
pidiv = null;
return false;
}
private static bool getBACDMatch(PKM pk, uint pid, uint[] IVs, out PIDIV pidiv)
private static bool GetBACDMatch(PKM pk, uint pid, uint[] IVs, out PIDIV pidiv)
{
var bot = getIVChunk(IVs, 0);
var top = getIVChunk(IVs, 3);
var reg = getSeedsFromIVs(RNG.LCRNG, top, bot);
var bot = GetIVChunk(IVs, 0);
var top = GetIVChunk(IVs, 3);
var reg = GetSeedsFromIVs(RNG.LCRNG, top, bot);
foreach (var seed in reg)
{
var B = seed;
@ -392,7 +392,7 @@ namespace PKHeX.Core
return null;
}
private static IEnumerable<uint> getSeedsFromPID(RNG method, uint a, uint b)
private static IEnumerable<uint> GetSeedsFromPID(RNG method, uint a, uint b)
{
uint cmp = a << 16;
uint x = b << 16;
@ -403,7 +403,7 @@ namespace PKHeX.Core
yield return method.Prev(seed);
}
}
private static IEnumerable<uint> getSeedsFromIVs(RNG method, uint a, uint b)
private static IEnumerable<uint> GetSeedsFromIVs(RNG method, uint a, uint b)
{
uint cmp = a << 16 & 0x7FFF0000;
uint x = b << 16 & 0x7FFF0000;
@ -429,7 +429,7 @@ namespace PKHeX.Core
/// <param name="r1">First rand frame</param>
/// <param name="r2">Second rand frame</param>
/// <returns>Array of 6 IVs</returns>
private static uint[] getIVs(uint r1, uint r2)
private static uint[] GetIVs(uint r1, uint r2)
{
return new[]
{
@ -447,7 +447,7 @@ namespace PKHeX.Core
/// <param name="method">RNG advancement method</param>
/// <param name="seed">RNG seed</param>
/// <returns>Array of 6 IVs</returns>
private static uint[] getIVs(RNG method, uint seed)
private static uint[] GetIVs(RNG method, uint seed)
{
uint[] ivs = new uint[6];
for (int i = 0; i < 6; i++)
@ -457,7 +457,7 @@ namespace PKHeX.Core
}
return ivs;
}
private static uint getIVChunk(uint[] IVs, int start)
private static uint GetIVChunk(uint[] IVs, int start)
{
uint val = 0;
for (int i = 0; i < 3; i++)
@ -465,7 +465,7 @@ namespace PKHeX.Core
return val;
}
public static IEnumerable<PIDIV> getPokeSpotSeeds(PKM pkm, int slot)
public static IEnumerable<PIDIV> GetPokeSpotSeeds(PKM pkm, int slot)
{
// Activate (rand % 3)
// Munchlax / Bonsly (10%/30%)
@ -473,7 +473,7 @@ namespace PKHeX.Core
var pid = pkm.PID;
var top = pid >> 16;
var bot = pid & 0xFFFF;
var seeds = getSeedsFromPID(RNG.XDRNG, bot, top);
var seeds = GetSeedsFromPID(RNG.XDRNG, bot, top);
foreach (var seed in seeds)
{
// check for valid encounter slot info

View file

@ -2,24 +2,11 @@
{
public class DexLevel
{
public int Species;
public int Level;
public int MinLevel;
public bool RequiresLvlUp;
public int Form = -1;
public int Flag = -1;
public DexLevel Copy(int lvl)
{
return new DexLevel {Species = Species, Level = lvl, MinLevel = MinLevel, RequiresLvlUp = RequiresLvlUp, Form = Form, Flag = -1};
}
public bool Matches(int species, int form)
{
if (species != Species)
return false;
if (Form > -1)
return form == Form;
return true;
}
public int Species { get; set; }
public int Level { get; set; }
public int MinLevel { get; set; }
public bool RequiresLvlUp { get; set; }
public int Form { get; set; } = -1;
public int Flag { get; set; } = -1;
}
}

View file

@ -17,7 +17,7 @@ namespace PKHeX.Core
Count = data.Length;
Moves = data.Select(i => (int) i).ToArray();
}
public static EggMoves[] getArray(byte[] data, int count)
public static EggMoves[] GetArray(byte[] data, int count)
{
int[] ptrs = new int[count+1];
int baseOffset = (data[1] << 8 | data[0]) - count * 2;
@ -45,7 +45,7 @@ namespace PKHeX.Core
Moves[i] = br.ReadUInt16();
}
}
public static EggMoves[] getArray(byte[][] entries)
public static EggMoves[] GetArray(byte[][] entries)
{
EggMoves[] data = new EggMoves[entries.Length];
for (int i = 0; i < data.Length; i++)
@ -68,7 +68,7 @@ namespace PKHeX.Core
Moves[i] = br.ReadUInt16();
}
}
public static EggMoves[] getArray(byte[][] entries)
public static EggMoves[] GetArray(byte[][] entries)
{
EggMoves[] data = new EggMoves[entries.Length];
for (int i = 0; i < data.Length; i++)

View file

@ -49,24 +49,24 @@ namespace PKHeX.Core
return Areas;
}
private static EncounterSlot1[] getSlots1_GW(byte[] data, ref int ofs, SlotType t)
private static EncounterSlot1[] GetSlots1_GW(byte[] data, ref int ofs, SlotType t)
{
int rate = data[ofs++];
return rate == 0 ? new EncounterSlot1[0] : readSlots(data, ref ofs, 10, t, rate);
return rate == 0 ? new EncounterSlot1[0] : ReadSlots(data, ref ofs, 10, t, rate);
}
private static EncounterSlot1[] getSlots1_F(byte[] data, ref int ofs)
private static EncounterSlot1[] GetSlots1_F(byte[] data, ref int ofs)
{
int count = data[ofs++];
return readSlots(data, ref ofs, count, SlotType.Super_Rod, -1);
return ReadSlots(data, ref ofs, count, SlotType.Super_Rod, -1);
}
private static EncounterSlot1[] getSlots2_GW(byte[] data, ref int ofs, SlotType t, int slotSets, int slotCount)
private static EncounterSlot1[] GetSlots2_GW(byte[] data, ref int ofs, SlotType t, int slotSets, int slotCount)
{
byte[] rates = new byte[slotSets];
for (int i = 0; i < rates.Length; i++)
rates[i] = data[ofs++];
var slots = readSlots(data, ref ofs, slotSets * slotCount, t, rates[0]);
var slots = ReadSlots(data, ref ofs, slotSets * slotCount, t, rates[0]);
for (int r = 1; r < slotSets; r++)
{
for (int i = 0; i < slotCount; i++)
@ -80,7 +80,7 @@ namespace PKHeX.Core
return slots;
}
private static EncounterSlot1[] getSlots2_F(byte[] data, ref int ofs, SlotType t)
private static EncounterSlot1[] GetSlots2_F(byte[] data, ref int ofs, SlotType t)
{
// slot set ends in 0xFF 0x** 0x**
var slots = new List<EncounterSlot1>();
@ -106,7 +106,7 @@ namespace PKHeX.Core
}
return slots.ToArray();
}
private static EncounterSlot1[] getSlots2_H(byte[] data, ref int ofs, SlotType t)
private static EncounterSlot1[] GetSlots2_H(byte[] data, ref int ofs, SlotType t)
{
// slot set ends in 0xFF
var slots = new List<EncounterSlot1>();
@ -135,7 +135,7 @@ namespace PKHeX.Core
return slots.ToArray();
}
private static IEnumerable<EncounterArea> getAreas2(byte[] data, ref int ofs, SlotType t, int slotSets, int slotCount)
private static IEnumerable<EncounterArea> GetAreas2(byte[] data, ref int ofs, SlotType t, int slotSets, int slotCount)
{
var areas = new List<EncounterArea>();
while (data[ofs] != 0xFF) // end
@ -143,22 +143,22 @@ namespace PKHeX.Core
areas.Add(new EncounterArea
{
Location = data[ofs++] << 8 | data[ofs++],
Slots = getSlots2_GW(data, ref ofs, t, slotSets, slotCount),
Slots = GetSlots2_GW(data, ref ofs, t, slotSets, slotCount),
});
}
ofs++;
return areas;
}
private static List<EncounterArea> getAreas2_F(byte[] data, ref int ofs)
private static List<EncounterArea> GetAreas2_F(byte[] data, ref int ofs)
{
var areas = new List<EncounterArea>();
var types = new[] {SlotType.Old_Rod, SlotType.Good_Rod, SlotType.Super_Rod};
while (ofs != 0x18C)
{
areas.Add(new EncounterArea {
Slots = getSlots2_F(data, ref ofs, types[0])
.Concat(getSlots2_F(data, ref ofs, types[1]))
.Concat(getSlots2_F(data, ref ofs, types[2])).ToArray() });
Slots = GetSlots2_F(data, ref ofs, types[0])
.Concat(GetSlots2_F(data, ref ofs, types[1]))
.Concat(GetSlots2_F(data, ref ofs, types[2])).ToArray() });
}
// Read TimeFishGroups
@ -193,7 +193,7 @@ namespace PKHeX.Core
}
return areas;
}
private static IEnumerable<EncounterArea> getAreas2_H(byte[] data, ref int ofs)
private static IEnumerable<EncounterArea> GetAreas2_H(byte[] data, ref int ofs)
{
// Read Location Table
var head = new List<EncounterArea>();
@ -234,18 +234,18 @@ namespace PKHeX.Core
for (int i = 0; i < head.Count; i++)
{
int o = ptr[headID[i]] - baseOffset;
head[i].Slots = getSlots2_H(data, ref o, SlotType.Headbutt);
head[i].Slots = GetSlots2_H(data, ref o, SlotType.Headbutt);
}
for (int i = 0; i < rock.Count; i++)
{
int o = ptr[rockID[i]] - baseOffset;
rock[i].Slots = getSlots2_H(data, ref o, SlotType.Rock_Smash);
rock[i].Slots = GetSlots2_H(data, ref o, SlotType.Rock_Smash);
}
return head.Concat(rock);
}
private static IEnumerable<EncounterSlot> getSlots3(byte[] data, ref int ofs, int numslots, SlotType t)
private static IEnumerable<EncounterSlot> GetSlots3(byte[] data, ref int ofs, int numslots, SlotType t)
{
var slots = new List<EncounterSlot>();
int Ratio = data[ofs];
@ -271,7 +271,7 @@ namespace PKHeX.Core
ofs += 2 + numslots * 4;
return slots;
}
private static IEnumerable<EncounterSlot> getSlots3_F(byte[] data, ref int ofs, int numslots)
private static IEnumerable<EncounterSlot> GetSlots3_F(byte[] data, ref int ofs, int numslots)
{
var slots = new List<EncounterSlot>();
int Ratio = data[ofs];
@ -312,7 +312,7 @@ namespace PKHeX.Core
return slots;
}
private static EncounterSlot[] getSlots4_DPPt_G(byte[] data, int ofs, int numslots, SlotType t)
private static EncounterSlot[] GetSlots4_DPPt_G(byte[] data, int ofs, int numslots, SlotType t)
{
var slots = new EncounterSlot[numslots];
@ -331,7 +331,7 @@ namespace PKHeX.Core
}
return slots;
}
private static EncounterSlot[] getSlots4_HGSS_G(byte[] data, int ofs, int numslots, SlotType t)
private static EncounterSlot[] GetSlots4_HGSS_G(byte[] data, int ofs, int numslots, SlotType t)
{
var slots = new EncounterSlot[numslots * 3];
// First 36 slots are morning, day and night grass slots
@ -358,7 +358,7 @@ namespace PKHeX.Core
return slots;
}
private static IEnumerable<EncounterSlot> getSlots4_G_Replace(byte[] data, int ofs, int slotSize, EncounterSlot[] ReplacedSlots, int[] slotnums, SlotType t = SlotType.Grass)
private static IEnumerable<EncounterSlot> GetSlots4_G_Replace(byte[] data, int ofs, int slotSize, EncounterSlot[] ReplacedSlots, int[] slotnums, SlotType t = SlotType.Grass)
{
//Special slots like GBA Dual Slot. Those slot only contain the info of species id, the level is copied from one of the first grass slots
//for dppt slotSize = 4, for hgss slotSize = 2
@ -382,7 +382,7 @@ namespace PKHeX.Core
}
return slots;
}
private static IEnumerable<EncounterSlot> getSlots4DPPt_WFR(byte[] data, int ofs, int numslots, SlotType t)
private static IEnumerable<EncounterSlot> GetSlots4DPPt_WFR(byte[] data, int ofs, int numslots, SlotType t)
{
var slots = new List<EncounterSlot>();
for (int i = 0; i < numslots; i++)
@ -403,7 +403,7 @@ namespace PKHeX.Core
}
return slots;
}
private static IEnumerable<EncounterSlot> getSlots4HGSS_WFR(byte[] data, int ofs, int numslots, SlotType t)
private static IEnumerable<EncounterSlot> GetSlots4HGSS_WFR(byte[] data, int ofs, int numslots, SlotType t)
{
var slots = new List<EncounterSlot>();
for (int i = 0; i < numslots; i++)
@ -426,7 +426,7 @@ namespace PKHeX.Core
return slots;
}
private static EncounterArea getArea3(byte[] data)
private static EncounterArea GetArea3(byte[] data)
{
EncounterArea Area3 = new EncounterArea();
@ -442,18 +442,18 @@ namespace PKHeX.Core
int offset = 5;
var slots = new List<EncounterSlot>();
if (HaveGrassSlots)
slots.AddRange(getSlots3(data, ref offset, 12, SlotType.Grass));
slots.AddRange(GetSlots3(data, ref offset, 12, SlotType.Grass));
if (HaveSurfSlots)
slots.AddRange(getSlots3(data, ref offset, 5, SlotType.Surf));
slots.AddRange(GetSlots3(data, ref offset, 5, SlotType.Surf));
if (HaveRockSmashSlots)
slots.AddRange(getSlots3(data, ref offset, 5, SlotType.Rock_Smash));
slots.AddRange(GetSlots3(data, ref offset, 5, SlotType.Rock_Smash));
if (HaveFishingSlots)
slots.AddRange(getSlots3_F(data, ref offset, 10));
slots.AddRange(GetSlots3_F(data, ref offset, 10));
Area3.Slots = slots.ToArray();
return Area3;
}
private static EncounterArea getArea4DPPt(byte[] data)
private static EncounterArea GetArea4DPPt(byte[] data)
{
EncounterArea Area4 = new EncounterArea();
if (data.Length != 0x1AA) // 426 Bytes
@ -465,48 +465,48 @@ namespace PKHeX.Core
var GrassRatio = BitConverter.ToInt32(data, 0x02);
if (GrassRatio > 0)
{
EncounterSlot[] GrassSlots = getSlots4_DPPt_G(data, 0x06, 12, SlotType.Grass);
EncounterSlot[] GrassSlots = GetSlots4_DPPt_G(data, 0x06, 12, SlotType.Grass);
Slots.AddRange(GrassSlots);
//Swarming slots replace slots 0 and 1
Slots.AddRange(getSlots4_G_Replace(data, 0x66, 4, GrassSlots, Legal.Slot4_Swarm, SlotType.Swarm));
Slots.AddRange(GetSlots4_G_Replace(data, 0x66, 4, GrassSlots, Legal.Slot4_Swarm, SlotType.Swarm));
//Morning and Night slots replace slots 2 and 3
Slots.AddRange(getSlots4_G_Replace(data, 0x6E, 4, GrassSlots, Legal.Slot4_Time)); // Morning
Slots.AddRange(getSlots4_G_Replace(data, 0x76, 4, GrassSlots, Legal.Slot4_Time)); // Night
Slots.AddRange(GetSlots4_G_Replace(data, 0x6E, 4, GrassSlots, Legal.Slot4_Time)); // Morning
Slots.AddRange(GetSlots4_G_Replace(data, 0x76, 4, GrassSlots, Legal.Slot4_Time)); // Night
//Pokéradar slots replace slots 4,5,10 and 11
//Pokéradar is marked with different slot type because it have different PID-IV generationn
Slots.AddRange(getSlots4_G_Replace(data, 0x7E, 4, GrassSlots, Legal.Slot4_Radar, SlotType.Pokeradar));
Slots.AddRange(GetSlots4_G_Replace(data, 0x7E, 4, GrassSlots, Legal.Slot4_Radar, SlotType.Pokeradar));
//24 bytes padding
//Dual Slots replace slots 8 and 9
Slots.AddRange(getSlots4_G_Replace(data, 0xA6, 4, GrassSlots, Legal.Slot4_Dual)); // Ruby
Slots.AddRange(getSlots4_G_Replace(data, 0xAE, 4, GrassSlots, Legal.Slot4_Dual)); // Sapphire
Slots.AddRange(getSlots4_G_Replace(data, 0xB6, 4, GrassSlots, Legal.Slot4_Dual)); // Emerald
Slots.AddRange(getSlots4_G_Replace(data, 0xBE, 4, GrassSlots, Legal.Slot4_Dual)); // FireRed
Slots.AddRange(getSlots4_G_Replace(data, 0xC6, 4, GrassSlots, Legal.Slot4_Dual)); // LeafGreen
Slots.AddRange(GetSlots4_G_Replace(data, 0xA6, 4, GrassSlots, Legal.Slot4_Dual)); // Ruby
Slots.AddRange(GetSlots4_G_Replace(data, 0xAE, 4, GrassSlots, Legal.Slot4_Dual)); // Sapphire
Slots.AddRange(GetSlots4_G_Replace(data, 0xB6, 4, GrassSlots, Legal.Slot4_Dual)); // Emerald
Slots.AddRange(GetSlots4_G_Replace(data, 0xBE, 4, GrassSlots, Legal.Slot4_Dual)); // FireRed
Slots.AddRange(GetSlots4_G_Replace(data, 0xC6, 4, GrassSlots, Legal.Slot4_Dual)); // LeafGreen
}
var SurfRatio = BitConverter.ToInt32(data, 0xCE);
if (SurfRatio > 0)
Slots.AddRange(getSlots4DPPt_WFR(data, 0xD2, 5, SlotType.Surf));
Slots.AddRange(GetSlots4DPPt_WFR(data, 0xD2, 5, SlotType.Surf));
//44 bytes padding
var OldRodRatio = BitConverter.ToInt32(data, 0x126);
if (OldRodRatio > 0)
Slots.AddRange(getSlots4DPPt_WFR(data, 0x12A, 5, SlotType.Old_Rod));
Slots.AddRange(GetSlots4DPPt_WFR(data, 0x12A, 5, SlotType.Old_Rod));
var GoodRodRatio = BitConverter.ToInt32(data, 0x152);
if (GoodRodRatio > 0)
Slots.AddRange(getSlots4DPPt_WFR(data, 0x156, 5, SlotType.Good_Rod));
Slots.AddRange(GetSlots4DPPt_WFR(data, 0x156, 5, SlotType.Good_Rod));
var SuperRodRatio = BitConverter.ToInt32(data, 0x17E);
if (SuperRodRatio > 0)
Slots.AddRange(getSlots4DPPt_WFR(data, 0x182, 5, SlotType.Super_Rod));
Slots.AddRange(GetSlots4DPPt_WFR(data, 0x182, 5, SlotType.Super_Rod));
Area4.Slots = Slots.ToArray();
return Area4;
}
private static EncounterArea getArea4HGSS(byte[] data)
private static EncounterArea GetArea4HGSS(byte[] data)
{
EncounterArea Area4 = new EncounterArea();
if (data.Length != 0xC6)
@ -527,29 +527,29 @@ namespace PKHeX.Core
{
// First 36 slots are morning, day and night grass slots
// The order is 12 level values, 12 morning species, 12 day species and 12 night species
var GrassSlots = getSlots4_HGSS_G(data, 0x0A, 12, SlotType.Grass);
var GrassSlots = GetSlots4_HGSS_G(data, 0x0A, 12, SlotType.Grass);
//Grass slots with species = 0 are added too, it is needed for the swarm encounters, it will be deleted after add swarms
Slots.AddRange(GrassSlots);
// Hoenn Sound and Sinnoh Sound replace slots 4 and 5
Slots.AddRange(getSlots4_G_Replace(data, 0x5E, 2, GrassSlots, Legal.Slot4_Sound)); // Hoenn
Slots.AddRange(getSlots4_G_Replace(data, 0x62, 2, GrassSlots, Legal.Slot4_Sound)); // Sinnoh
Slots.AddRange(GetSlots4_G_Replace(data, 0x5E, 2, GrassSlots, Legal.Slot4_Sound)); // Hoenn
Slots.AddRange(GetSlots4_G_Replace(data, 0x62, 2, GrassSlots, Legal.Slot4_Sound)); // Sinnoh
}
if (SurfRatio > 0)
Slots.AddRange(getSlots4HGSS_WFR(data, 0x66, 5, SlotType.Surf));
Slots.AddRange(GetSlots4HGSS_WFR(data, 0x66, 5, SlotType.Surf));
if (RockSmashRatio > 0)
Slots.AddRange(getSlots4HGSS_WFR(data, 0x7A, 2, SlotType.Rock_Smash));
Slots.AddRange(GetSlots4HGSS_WFR(data, 0x7A, 2, SlotType.Rock_Smash));
if (OldRodRatio > 0)
Slots.AddRange(getSlots4HGSS_WFR(data, 0x82, 5, SlotType.Old_Rod));
Slots.AddRange(GetSlots4HGSS_WFR(data, 0x82, 5, SlotType.Old_Rod));
if (GoodRodRatio > 0)
Slots.AddRange(getSlots4HGSS_WFR(data, 0x96, 5, SlotType.Good_Rod));
Slots.AddRange(GetSlots4HGSS_WFR(data, 0x96, 5, SlotType.Good_Rod));
if (SuperRodRatio > 0)
Slots.AddRange(getSlots4HGSS_WFR(data, 0xAA, 5, SlotType.Super_Rod));
Slots.AddRange(GetSlots4HGSS_WFR(data, 0xAA, 5, SlotType.Super_Rod));
// Last 6 bytes only have species ID info
if (data[0xC2] == 120) // Location = 182, 127, 130, 132, 167, 188, 210
@ -564,7 +564,7 @@ namespace PKHeX.Core
new EncounterSlot { Species = 120, LevelMin = 40, LevelMax = 40, Type = SlotType.Super_Rod },
};
private static EncounterArea getArea4HGSS_Headbutt(byte[] data)
private static EncounterArea GetArea4HGSS_Headbutt(byte[] data)
{
if (data.Length < 78)
return new EncounterArea(); // bad data
@ -605,7 +605,7 @@ namespace PKHeX.Core
/// <param name="t">Type of encounter slot.</param>
/// <param name="rate">Slot type encounter rate.</param>
/// <returns>Array of encounter slots.</returns>
private static EncounterSlot1[] readSlots(byte[] data, ref int ofs, int count, SlotType t, int rate)
private static EncounterSlot1[] ReadSlots(byte[] data, ref int ofs, int count, SlotType t, int rate)
{
EncounterSlot1[] slots = new EncounterSlot1[count];
for (int i = 0; i < count; i++)
@ -626,7 +626,7 @@ namespace PKHeX.Core
return slots;
}
private static EncounterSlot1[] readSlots_FY(byte[] data, ref int ofs, int count, SlotType t, int rate)
private static EncounterSlot1[] ReadSlots_FY(byte[] data, ref int ofs, int count, SlotType t, int rate)
{
// Convert byte to actual number
int[] Levelbytelist = { 0xFF, 0x15, 0x67, 0x1D, 0x3B, 0x5C, 0x72, 0x16, 0x71, 0x18, 0x00, 0x6D, 0x80, };
@ -657,7 +657,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="data">Input raw data.</param>
/// <returns>Array of encounter areas.</returns>
public static EncounterArea[] getArray1_GW(byte[] data)
public static EncounterArea[] GetArray1_GW(byte[] data)
{
// RBY Format
var ptr = new int[255];
@ -675,8 +675,8 @@ namespace PKHeX.Core
EncounterArea[] areas = new EncounterArea[count];
for (int i = 0; i < areas.Length; i++)
{
var grass = getSlots1_GW(data, ref ptr[i], SlotType.Grass);
var water = getSlots1_GW(data, ref ptr[i], SlotType.Surf);
var grass = GetSlots1_GW(data, ref ptr[i], SlotType.Grass);
var water = GetSlots1_GW(data, ref ptr[i], SlotType.Surf);
areas[i] = new EncounterArea
{
Location = i,
@ -690,7 +690,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="data">Input raw data.</param>
/// <returns>Array of encounter areas.</returns>
public static EncounterArea[] getArray1_FY(byte[] data)
public static EncounterArea[] GetArray1_FY(byte[] data)
{
const int size = 9;
int count = data.Length/size;
@ -701,7 +701,7 @@ namespace PKHeX.Core
areas[i] = new EncounterArea
{
Location = data[i*size + 0],
Slots = readSlots_FY(data, ref ofs, 4, SlotType.Super_Rod, -1)
Slots = ReadSlots_FY(data, ref ofs, 4, SlotType.Super_Rod, -1)
};
}
return areas;
@ -711,7 +711,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="data">Input raw data.</param>
/// <returns>Array of encounter areas.</returns>
public static EncounterArea[] getArray1_F(byte[] data)
public static EncounterArea[] GetArray1_F(byte[] data)
{
var ptr = new int[255];
var map = new int[255];
@ -733,7 +733,7 @@ namespace PKHeX.Core
areas[i] = new EncounterArea
{
Location = map[i],
Slots = getSlots1_F(data, ref ptr[i])
Slots = GetSlots1_F(data, ref ptr[i])
};
}
return areas;
@ -744,16 +744,16 @@ namespace PKHeX.Core
/// </summary>
/// <param name="data">Input raw data.</param>
/// <returns>Array of encounter areas.</returns>
public static EncounterArea[] getArray2_GW(byte[] data)
public static EncounterArea[] GetArray2_GW(byte[] data)
{
int ofs = 0;
var areas = new List<EncounterArea>();
areas.AddRange(getAreas2(data, ref ofs, SlotType.Grass, 3, 7)); // Johto Grass
areas.AddRange(getAreas2(data, ref ofs, SlotType.Surf, 1, 3)); // Johto Water
areas.AddRange(getAreas2(data, ref ofs, SlotType.Grass, 3, 7)); // Kanto Grass
areas.AddRange(getAreas2(data, ref ofs, SlotType.Surf, 1, 3)); // Kanto Water
areas.AddRange(getAreas2(data, ref ofs, SlotType.Swarm, 3, 7)); // Swarm
areas.AddRange(getAreas2(data, ref ofs, SlotType.Special, 1, 3)); // Union Cave
areas.AddRange(GetAreas2(data, ref ofs, SlotType.Grass, 3, 7)); // Johto Grass
areas.AddRange(GetAreas2(data, ref ofs, SlotType.Surf, 1, 3)); // Johto Water
areas.AddRange(GetAreas2(data, ref ofs, SlotType.Grass, 3, 7)); // Kanto Grass
areas.AddRange(GetAreas2(data, ref ofs, SlotType.Surf, 1, 3)); // Kanto Water
areas.AddRange(GetAreas2(data, ref ofs, SlotType.Swarm, 3, 7)); // Swarm
areas.AddRange(GetAreas2(data, ref ofs, SlotType.Special, 1, 3)); // Union Cave
return areas.ToArray();
}
@ -762,10 +762,10 @@ namespace PKHeX.Core
/// </summary>
/// <param name="data">Input raw data.</param>
/// <returns>Array of encounter areas.</returns>
public static EncounterArea[] getArray2_F(byte[] data)
public static EncounterArea[] GetArray2_F(byte[] data)
{
int ofs = 0;
var f = getAreas2_F(data, ref ofs);
var f = GetAreas2_F(data, ref ofs);
// Fishing Tables are not associated to a single map; a map picks a table to use.
// For all maps that use a table, create a new EncounterArea with reference to the table's slots.
@ -794,10 +794,10 @@ namespace PKHeX.Core
areas.Add(new EncounterArea { Location = 0x2E, Slots = f[3].Slots }); // Silver Cave (2: Inside, 3: Outside)
return areas.ToArray();
}
public static EncounterArea[] getArray2_H(byte[] data)
public static EncounterArea[] GetArray2_H(byte[] data)
{
int ofs = 0;
return getAreas2_H(data, ref ofs).ToArray();
return GetAreas2_H(data, ref ofs).ToArray();
}
/// <summary>
@ -805,7 +805,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="entries">Raw data, one byte array per encounter area</param>
/// <returns>Array of encounter areas.</returns>
public static EncounterArea[] getArray3(byte[][] entries)
public static EncounterArea[] GetArray3(byte[][] entries)
{
if (entries == null)
return null;
@ -813,7 +813,7 @@ namespace PKHeX.Core
var Areas = new List<EncounterArea>();
foreach (byte[] t in entries)
{
EncounterArea Area = getArea3(t);
EncounterArea Area = GetArea3(t);
if (Area.Slots.Any())
Areas.Add(Area);
}
@ -825,9 +825,9 @@ namespace PKHeX.Core
/// </summary>
/// <param name="entries">Raw data, one byte array per encounter area</param>
/// <returns>Array of encounter areas.</returns>
public static EncounterArea[] getArray4DPPt(byte[][] entries)
public static EncounterArea[] GetArray4DPPt(byte[][] entries)
{
return entries?.Select(getArea4DPPt).Where(Area => Area.Slots.Any()).ToArray();
return entries?.Select(GetArea4DPPt).Where(Area => Area.Slots.Any()).ToArray();
}
/// <summary>
@ -835,9 +835,9 @@ namespace PKHeX.Core
/// </summary>
/// <param name="entries">Raw data, one byte array per encounter area</param>
/// <returns>Array of encounter areas.</returns>
public static EncounterArea[] getArray4HGSS(byte[][] entries)
public static EncounterArea[] GetArray4HGSS(byte[][] entries)
{
return entries?.Select(getArea4HGSS).Where(Area => Area.Slots.Any()).ToArray();
return entries?.Select(GetArea4HGSS).Where(Area => Area.Slots.Any()).ToArray();
}
/// <summary>
@ -845,9 +845,9 @@ namespace PKHeX.Core
/// </summary>
/// <param name="entries">Raw data, one byte array per encounter area</param>
/// <returns>Array of encounter areas.</returns>
public static EncounterArea[] getArray4HGSS_Headbutt(byte[][] entries)
public static EncounterArea[] GetArray4HGSS_Headbutt(byte[][] entries)
{
return entries?.Select(getArea4HGSS_Headbutt).Where(Area => Area.Slots.Any()).ToArray();
return entries?.Select(GetArea4HGSS_Headbutt).Where(Area => Area.Slots.Any()).ToArray();
}
/// <summary>
@ -856,7 +856,7 @@ namespace PKHeX.Core
/// <param name="species">List of special species that can exist in the garden.</param>
/// <param name="lvls">Levels of the two encounter slots they can replace. <see cref="GameVersion.DP"/> differs from <see cref="GameVersion.Pt"/></param>
/// <returns></returns>
public static EncounterArea[] getTrophyArea(IEnumerable<int> species, int[] lvls)
public static EncounterArea[] GetTrophyArea(IEnumerable<int> species, int[] lvls)
{
int[] slotnums = {6, 7};
var l = new List<EncounterSlot>();
@ -885,7 +885,7 @@ namespace PKHeX.Core
/// <param name="location">Location index of the encounter area.</param>
/// <param name="t">Encounter slot type of the encounter area.</param>
/// <returns></returns>
public static EncounterArea[] getSimpleEncounterArea(IEnumerable<int> species, int[] lvls, int location, SlotType t)
public static EncounterArea[] GetSimpleEncounterArea(IEnumerable<int> species, int[] lvls, int location, SlotType t)
{
var l = new List<EncounterSlot>();
// levels data not paired
@ -908,7 +908,7 @@ namespace PKHeX.Core
return new[] { new EncounterArea { Location = location, Slots = l.ToArray() } };
}
public static EncounterArea[] getArray(byte[][] entries)
public static EncounterArea[] GetArray(byte[][] entries)
{
if (entries == null)
return null;

View file

@ -3,24 +3,21 @@
public class EncounterLink : IEncounterable
{
public int Species { get; set; }
public int Level;
public int LevelMin { get { return Level; } }
public int LevelMax { get { return Level; } }
public int Location = 30011;
public int Ability = 1;
public int Ball = 4; // Pokéball
public Nature Nature = Nature.Random;
public int[] IVs = { -1, -1, -1, -1, -1, -1 };
public int FlawlessIVs = 0;
public bool Classic = true;
public bool Fateful = false;
public int Level { get; set; }
public int LevelMin => Level;
public int LevelMax => Level;
public int Location { get; set; } = 30011;
public int Ability { get; set; } = 1;
public int Ball { get; set; } = 4; // Pokéball
public bool Classic { get; set; } = true;
public bool Fateful { get; set; } = false;
public int[] RelearnMoves = new int[4];
public bool? Shiny = false;
public bool OT = true; // Receiver is OT?
public bool? Shiny { get; set; } = false;
public bool OT { get; set; } = true; // Receiver is OT?
public bool EggEncounter => false;
public bool XY = false;
public bool ORAS = false;
public bool XY { get; set; }
public bool ORAS { get; set; }
public string Name => "Pokémon Link Gift";
}

View file

@ -3,8 +3,8 @@
// Gender Locking
public class EncounterLock
{
public int Species;
public int Nature = -1;
public int Gender = -1;
public int Species { get; set; }
public int Nature { get; set; } = -1;
public int Gender { get; set; } = -1;
}
}

View file

@ -1,39 +1,42 @@
namespace PKHeX.Core
{
public class EncounterSlot : IEncounterable, IGeneration
public class EncounterSlotPermissions
{
public int Species { get; set; }
public int Form;
public int LevelMin { get; set; }
public int LevelMax { get; set; }
public SlotType Type = SlotType.Any;
public EncounterType TypeEncounter = EncounterType.None;
public bool AllowDexNav;
public bool Pressure;
public bool DexNav;
public bool WhiteFlute;
public bool BlackFlute;
public bool Normal => !(WhiteFlute || BlackFlute || DexNav);
public int SlotNumber;
public bool EggEncounter => false;
public int Generation { get; set; } = -1;
public bool Static;
public bool MagnetPull;
public int StaticCount;
public int MagnetPullCount;
public bool AllowDexNav { get; set; }
public bool Pressure { get; set; }
public bool DexNav { get; set; }
public bool WhiteFlute { get; set; }
public bool BlackFlute { get; set; }
public bool IsNormalLead => !(WhiteFlute || BlackFlute || DexNav);
}
public class EncounterSlot : IEncounterable, IGeneration
{
public int Species { get; set; }
public int Form { get; set; }
public int LevelMin { get; set; }
public int LevelMax { get; set; }
public SlotType Type { get; set; } = SlotType.Any;
public EncounterType TypeEncounter { get; set; } = EncounterType.None;
public int SlotNumber { get; set; }
public bool EggEncounter => false;
public int Generation { get; set; } = -1;
internal EncounterSlotPermissions _perm;
public EncounterSlotPermissions Permissions => _perm ?? (_perm = new EncounterSlotPermissions());
public virtual EncounterSlot Clone()
{
return new EncounterSlot
{
Species = Species,
AllowDexNav = AllowDexNav,
LevelMax = LevelMax,
LevelMin = LevelMin,
Type = Type,
Pressure = Pressure,
SlotNumber = SlotNumber,
_perm = _perm
};
}
@ -59,8 +62,9 @@
LevelMax = LevelMax,
LevelMin = LevelMin,
Type = Type,
Rate = Rate,
SlotNumber = SlotNumber,
_perm = _perm,
Rate = Rate
};
}
}

View file

@ -4,33 +4,33 @@
{
public int Species { get; set; }
public int[] Moves { get; set; }
public int Level;
public int Level { get; set; }
public int LevelMin => Level;
public int LevelMax => Level;
public int Generation { get; set; } = -1;
public int Location;
public int Ability;
public int Form;
public bool? Shiny; // false = never, true = always, null = possible
public int[] Relearn = new int[4];
public int Gender = -1;
public int EggLocation;
public Nature Nature = Nature.Random;
public bool Gift;
public int Ball = 4; // Gift Only
public int Location { get; set; }
public int Ability { get; set; }
public int Form { get; set; }
public bool? Shiny { get; set; } // false = never, true = always, null = possible
public int[] Relearn { get; set; } = new int[4];
public int Gender { get; set; } = -1;
public int EggLocation { get; set; }
public Nature Nature { get; set; } = Nature.Random;
public bool Gift { get; set; }
public int Ball { get; set; } = 4; // Only checked when is Gift
public GameVersion Version = GameVersion.Any;
public int[] IVs = { -1, -1, -1, -1, -1, -1 };
public bool IV3;
public int[] Contest = { 0, 0, 0, 0, 0, 0 };
public int[] IVs { get; set; } = { -1, -1, -1, -1, -1, -1 };
public bool IV3 { get; set; }
public int[] Contest { get; set; } = { 0, 0, 0, 0, 0, 0 };
public int HeldItem { get; set; }
public int EggCycles;
public int EggCycles { get; set; }
public bool Fateful;
public bool RibbonWishing;
public bool SkipFormCheck;
public bool NSparkle;
public bool Roaming;
public bool Fateful { get; set; }
public bool RibbonWishing { get; set; }
public bool SkipFormCheck { get; set; }
public bool NSparkle { get; set; }
public bool Roaming { get; set; }
public bool EggEncounter => EggLocation > 0;
public EncounterStatic[] Clone(int[] locations)
@ -162,13 +162,13 @@
public class EncounterStaticShadow : EncounterStatic
{
public EncounterLock[] Locks = new EncounterLock[0];
public EncounterLock[][] Locks = new EncounterLock[0][];
public int Gauge;
public bool EReader = false;
public override EncounterStatic Clone(int location)
{
throw new System.Exception();
throw new System.NotImplementedException();
}
}
}

View file

@ -4,26 +4,26 @@
{
public int Species { get; set; }
public int[] Moves { get; set; }
public int Level;
public int Level { get; set; }
public int LevelMin => Level;
public int LevelMax => 100;
public int Generation { get; set; } = -1;
public int Location = -1;
public int Ability = 0;
public int Location { get; set; } = -1;
public int Ability { get; set; }
public Nature Nature = Nature.Random;
public int TID;
public int SID = 0;
public GameVersion Version = GameVersion.Any;
public int[] IVs = { -1, -1, -1, -1, -1, -1 };
public int[] Contest = { 0, 0, 0, 0, 0, 0 };
public int Form = 0;
public bool Shiny = false;
public int Gender = -1;
public int OTGender = -1;
public int TID { get; set; }
public int SID { get; set; }
public GameVersion Version { get; set; } = GameVersion.Any;
public int[] IVs { get; set; } = { -1, -1, -1, -1, -1, -1 };
public int[] Contest { get; set; } = { 0, 0, 0, 0, 0, 0 };
public int Form { get; set; }
public bool Shiny { get; set; } = false;
public int Gender { get; set; } = -1;
public int OTGender { get; set; } = -1;
public bool EggEncounter => false;
public bool EvolveOnTrade = false;
public int Ball = 4;
public bool EvolveOnTrade { get; set; }
public int Ball { get; set; } = 4;
public string Name => "In-game Trade";

View file

@ -26,18 +26,21 @@
{
return g1.Contains((EncounterType)g2);
}
public static bool Contains(this EncounterType g1, EncounterType g2)
private static bool Contains(this EncounterType g1, EncounterType g2)
{
if (g1 == EncounterType.Headbutt_Grass)
return g2 == EncounterType.None || g2 == EncounterType.TallGrass;
if (g1 == EncounterType.Headbutt_Surf)
return g2 == EncounterType.None || g2 == EncounterType.Surfing_Fishing;
if (g1 == EncounterType.Headbutt_GrassSurf)
return EncounterType.Headbutt_Grass.Contains(g2) || g2 == EncounterType.Surfing_Fishing;
if (g1 == EncounterType.Headbutt_CitySurf)
return g2 == EncounterType.Building_EnigmaStone || g2 == EncounterType.Surfing_Fishing;
if (g1 == EncounterType.Headbutt_CaveSurf)
return g2 == EncounterType.Cave_HallOfOrigin || g2 == EncounterType.Surfing_Fishing;
switch (g1)
{
case EncounterType.Headbutt_Grass:
return g2 == EncounterType.None || g2 == EncounterType.TallGrass;
case EncounterType.Headbutt_Surf:
return g2 == EncounterType.None || g2 == EncounterType.Surfing_Fishing;
case EncounterType.Headbutt_GrassSurf:
return EncounterType.Headbutt_Grass.Contains(g2) || g2 == EncounterType.Surfing_Fishing;
case EncounterType.Headbutt_CitySurf:
return g2 == EncounterType.Building_EnigmaStone || g2 == EncounterType.Surfing_Fishing;
case EncounterType.Headbutt_CaveSurf:
return g2 == EncounterType.Cave_HallOfOrigin || g2 == EncounterType.Surfing_Fishing;
}
return g1 == g2;
}

View file

@ -20,19 +20,19 @@ namespace PKHeX.Core
switch (game)
{
case GameVersion.RBY:
Entries = EvolutionSet1.getArray(data[0], maxSpeciesTree);
Entries = EvolutionSet1.GetArray(data[0], maxSpeciesTree);
break;
case GameVersion.GSC:
Entries = EvolutionSet2.getArray(data[0], maxSpeciesTree);
Entries = EvolutionSet2.GetArray(data[0], maxSpeciesTree);
break;
case GameVersion.RS:
Entries = EvolutionSet3.getArray(data[0]);
Entries = EvolutionSet3.GetArray(data[0]);
break;
case GameVersion.DP:
Entries = EvolutionSet4.getArray(data[0]);
Entries = EvolutionSet4.GetArray(data[0]);
break;
case GameVersion.BW:
Entries = EvolutionSet5.getArray(data[0]);
Entries = EvolutionSet5.GetArray(data[0]);
break;
case GameVersion.ORAS:
Entries.AddRange(data.Select(d => new EvolutionSet6(d)));
@ -56,7 +56,7 @@ namespace PKHeX.Core
var s = Entries[i];
foreach (EvolutionMethod evo in s.PossibleEvolutions)
{
int index = getIndex(evo);
int index = GetIndex(evo);
if (index < 0)
continue;
@ -72,7 +72,7 @@ namespace PKHeX.Core
// Add it to the corresponding parent chains
foreach (EvolutionMethod mid in Entries[index].PossibleEvolutions)
{
int newIndex = getIndex(mid);
int newIndex = GetIndex(mid);
if (newIndex < 0)
continue;
@ -80,67 +80,67 @@ namespace PKHeX.Core
}
}
}
fixEvoTreeManually();
FixEvoTreeManually();
}
// There's always oddballs.
private void fixEvoTreeManually()
private void FixEvoTreeManually()
{
if (Game == GameVersion.SM)
fixEvoTreeSM();
FixEvoTreeSM();
}
private void fixEvoTreeSM()
private void FixEvoTreeSM()
{
// Wormadam -- Copy Burmy 0 to Wormadam-1/2
Lineage[Personal.getFormeIndex(413, 1)].Chain.Insert(0, Lineage[413].Chain[0]);
Lineage[Personal.getFormeIndex(413, 2)].Chain.Insert(0, Lineage[413].Chain[0]);
Lineage[Personal.GetFormeIndex(413, 1)].Chain.Insert(0, Lineage[413].Chain[0]);
Lineage[Personal.GetFormeIndex(413, 2)].Chain.Insert(0, Lineage[413].Chain[0]);
// Shellos -- Move Shellos-1 evo from Gastrodon-0 to Gastrodon-1
Lineage[Personal.getFormeIndex(422 + 1, 1)].Chain.Insert(0, Lineage[422 + 1].Chain[0]);
Lineage[Personal.GetFormeIndex(422 + 1, 1)].Chain.Insert(0, Lineage[422 + 1].Chain[0]);
Lineage[422+1].Chain.RemoveAt(0);
// Meowstic -- Meowstic-1 (F) should point back to Espurr, copy Meowstic-0 (M)
Lineage[Personal.getFormeIndex(678, 1)].Chain.Insert(0, Lineage[678].Chain[0]);
Lineage[Personal.GetFormeIndex(678, 1)].Chain.Insert(0, Lineage[678].Chain[0]);
// Floette doesn't contain evo info for forms 1-4, copy. Florges points to form 0, no fix needed.
var fbb = Lineage[669+1].Chain[0];
for (int i = 1; i <= 4; i++) // NOT AZ
Lineage[Personal.getFormeIndex(669+1, i)].Chain.Insert(0, fbb);
Lineage[Personal.GetFormeIndex(669+1, i)].Chain.Insert(0, fbb);
// Clear forme chains from Florges
Lineage[671].Chain.RemoveRange(0, Lineage[671].Chain.Count - 2);
// Gourgeist -- Sizes are still relevant. Formes are in reverse order.
for (int i = 1; i <= 3; i++)
{
Lineage[Personal.getFormeIndex(711, i)].Chain.Clear();
Lineage[Personal.getFormeIndex(711, i)].Chain.Add(Lineage[711].Chain[3-i]);
Lineage[Personal.GetFormeIndex(711, i)].Chain.Clear();
Lineage[Personal.GetFormeIndex(711, i)].Chain.Add(Lineage[711].Chain[3-i]);
}
Lineage[711].Chain.RemoveRange(0, 3);
// Add past gen evolutions for other Marowak and Exeggutor
var raichu1 = Lineage[Personal.getFormeIndex(26, 1)];
var raichu1 = Lineage[Personal.GetFormeIndex(26, 1)];
var evo1 = raichu1.Chain[0].StageEntryMethods[0].Copy();
Lineage[26].Chain.Add(new EvolutionStage { StageEntryMethods = new List<EvolutionMethod> { evo1 } });
var evo2 = raichu1.Chain[1].StageEntryMethods[0].Copy();
evo2.Form = -1; evo2.Banlist = new[] { GameVersion.SN, GameVersion.MN };
Lineage[26].Chain.Add(new EvolutionStage { StageEntryMethods = new List<EvolutionMethod> { evo2 } });
var exegg = Lineage[Personal.getFormeIndex(103, 1)].Chain[0].StageEntryMethods[0].Copy();
var exegg = Lineage[Personal.GetFormeIndex(103, 1)].Chain[0].StageEntryMethods[0].Copy();
exegg.Form = -1; exegg.Banlist = new[] { GameVersion.SN, GameVersion.MN }; exegg.Method = 8; // No night required (doesn't matter)
Lineage[103].Chain.Add(new EvolutionStage { StageEntryMethods = new List<EvolutionMethod> { exegg } });
var marowak = Lineage[Personal.getFormeIndex(105, 1)].Chain[0].StageEntryMethods[0].Copy();
var marowak = Lineage[Personal.GetFormeIndex(105, 1)].Chain[0].StageEntryMethods[0].Copy();
marowak.Form = -1; marowak.Banlist = new[] {GameVersion.SN, GameVersion.MN};
Lineage[105].Chain.Add(new EvolutionStage { StageEntryMethods = new List<EvolutionMethod> { marowak } });
}
private int getIndex(PKM pkm)
private int GetIndex(PKM pkm)
{
if (pkm.Format < 7)
return pkm.Species;
return Personal.getFormeIndex(pkm.Species, pkm.AltForm);
return Personal.GetFormeIndex(pkm.Species, pkm.AltForm);
}
private int getIndex(EvolutionMethod evo)
private int GetIndex(EvolutionMethod evo)
{
int evolvesToSpecies = evo.Species;
if (evolvesToSpecies == 0)
@ -153,14 +153,14 @@ namespace PKHeX.Core
if (evolvesToForm < 0)
evolvesToForm = 0;
return Personal.getFormeIndex(evolvesToSpecies, evolvesToForm);
return Personal.GetFormeIndex(evolvesToSpecies, evolvesToForm);
}
public IEnumerable<DexLevel> getValidPreEvolutions(PKM pkm, int lvl, int maxSpeciesOrigin = -1, bool skipChecks = false)
public IEnumerable<DexLevel> GetValidPreEvolutions(PKM pkm, int lvl, int maxSpeciesOrigin = -1, bool skipChecks = false)
{
int index = getIndex(pkm);
int index = GetIndex(pkm);
if (maxSpeciesOrigin <= 0)
maxSpeciesOrigin = Legal.getMaxSpeciesOrigin(pkm);
return Lineage[index].getExplicitLineage(pkm, lvl, skipChecks, MaxSpeciesTree, maxSpeciesOrigin);
maxSpeciesOrigin = Legal.GetMaxSpeciesOrigin(pkm);
return Lineage[index].GetExplicitLineage(pkm, lvl, skipChecks, MaxSpeciesTree, maxSpeciesOrigin);
}
}
@ -170,7 +170,7 @@ namespace PKHeX.Core
}
public class EvolutionSet1 : EvolutionSet
{
private static EvolutionMethod getMethod(byte[] data, ref int offset)
private static EvolutionMethod GetMethod(byte[] data, ref int offset)
{
switch (data[offset])
{
@ -205,7 +205,7 @@ namespace PKHeX.Core
}
return null;
}
public static List<EvolutionSet> getArray(byte[] data, int maxSpecies)
public static List<EvolutionSet> GetArray(byte[] data, int maxSpecies)
{
var evos = new List<EvolutionSet>();
int offset = 0;
@ -213,7 +213,7 @@ namespace PKHeX.Core
{
var m = new List<EvolutionMethod>();
while (data[offset] != 0)
m.Add(getMethod(data, ref offset));
m.Add(GetMethod(data, ref offset));
++offset;
evos.Add(new EvolutionSet1 { PossibleEvolutions = m.ToArray() });
}
@ -222,7 +222,7 @@ namespace PKHeX.Core
}
public class EvolutionSet2 : EvolutionSet
{
private static EvolutionMethod getMethod(byte[] data, ref int offset)
private static EvolutionMethod GetMethod(byte[] data, ref int offset)
{
int method = data[offset];
int arg = data[offset + 1];
@ -241,7 +241,7 @@ namespace PKHeX.Core
}
return null;
}
public static List<EvolutionSet> getArray(byte[] data, int maxSpecies)
public static List<EvolutionSet> GetArray(byte[] data, int maxSpecies)
{
var evos = new List<EvolutionSet>();
int offset = 0;
@ -249,7 +249,7 @@ namespace PKHeX.Core
{
var m = new List<EvolutionMethod>();
while (data[offset] != 0)
m.Add(getMethod(data, ref offset));
m.Add(GetMethod(data, ref offset));
++offset;
evos.Add(new EvolutionSet2 { PossibleEvolutions = m.ToArray() });
}
@ -258,11 +258,11 @@ namespace PKHeX.Core
}
public class EvolutionSet3 : EvolutionSet
{
private static EvolutionMethod getMethod(byte[] data, int offset)
private static EvolutionMethod GetMethod(byte[] data, int offset)
{
int method = BitConverter.ToUInt16(data, offset + 0);
int arg = BitConverter.ToUInt16(data, offset + 2);
int species = PKX.getG4Species(BitConverter.ToUInt16(data, offset + 4));
int species = PKX.GetG4Species(BitConverter.ToUInt16(data, offset + 4));
//2 bytes padding
switch (method)
@ -289,13 +289,13 @@ namespace PKHeX.Core
}
return null;
}
public static List<EvolutionSet> getArray(byte[] data)
public static List<EvolutionSet> GetArray(byte[] data)
{
EvolutionSet[] evos = new EvolutionSet[Legal.MaxSpeciesID_3 + 1];
evos[0] = new EvolutionSet3 { PossibleEvolutions = new EvolutionMethod[0] };
for (int i = 0; i <= Legal.MaxSpeciesIndex_3; i++)
{
int g4species = PKX.getG4Species(i);
int g4species = PKX.GetG4Species(i);
if (g4species == 0)
continue;
@ -303,7 +303,7 @@ namespace PKHeX.Core
var m_list = new List<EvolutionMethod>();
for (int j = 0; j < 5; j++)
{
EvolutionMethod m = getMethod(data, offset);
EvolutionMethod m = GetMethod(data, offset);
if (m != null)
m_list.Add(m);
else
@ -317,7 +317,7 @@ namespace PKHeX.Core
}
public class EvolutionSet4 : EvolutionSet
{
private static EvolutionMethod getMethod(byte[] data, int offset)
private static EvolutionMethod GetMethod(byte[] data, int offset)
{
int[] argEvos = { 6, 8, 16, 17, 18, 19, 20, 21, 22 };
int method = BitConverter.ToUInt16(data, offset + 0);
@ -343,7 +343,7 @@ namespace PKHeX.Core
evo.Level = 0;
return evo;
}
public static List<EvolutionSet> getArray(byte[] data)
public static List<EvolutionSet> GetArray(byte[] data)
{
var evos = new List<EvolutionSet>();
for (int i = 0; i <= Legal.MaxSpeciesIndex_4_HGSSPt; i++)
@ -355,7 +355,7 @@ namespace PKHeX.Core
var m_list = new List<EvolutionMethod>();
for (int j = 0; j < 7; j++)
{
EvolutionMethod m = getMethod(data, offset);
EvolutionMethod m = GetMethod(data, offset);
if (m != null)
m_list.Add(m);
else
@ -369,7 +369,7 @@ namespace PKHeX.Core
}
public class EvolutionSet5 : EvolutionSet
{
private static EvolutionMethod getMethod(byte[] data, int offset)
private static EvolutionMethod GetMethod(byte[] data, int offset)
{
int[] argEvos = { 6, 8, 16, 17, 18, 19, 20, 21, 22 };
int method = BitConverter.ToUInt16(data, offset + 0);
@ -391,7 +391,7 @@ namespace PKHeX.Core
evo.Level = 0;
return evo;
}
public static List<EvolutionSet> getArray(byte[] data)
public static List<EvolutionSet> GetArray(byte[] data)
{
var evos = new List<EvolutionSet>();
for (int i = 0; i <= Legal.MaxSpeciesIndex_5_B2W2; i++)
@ -402,7 +402,7 @@ namespace PKHeX.Core
var m_list = new List<EvolutionMethod>();
for (int j = 0; j < 7; j++)
{
EvolutionMethod m = getMethod(data, offset);
EvolutionMethod m = GetMethod(data, offset);
if (m != null)
m_list.Add(m);
else
@ -601,7 +601,7 @@ namespace PKHeX.Core
Chain.Insert(0, evo);
}
public IEnumerable<DexLevel> getExplicitLineage(PKM pkm, int lvl, bool skipChecks, int maxSpeciesTree, int maxSpeciesOrigin)
public IEnumerable<DexLevel> GetExplicitLineage(PKM pkm, int lvl, bool skipChecks, int maxSpeciesTree, int maxSpeciesOrigin)
{
List<DexLevel> dl = new List<DexLevel> { new DexLevel { Species = pkm.Species, Level = lvl, Form = pkm.AltForm } };
for (int i = Chain.Count - 1; i >= 0; i--) // reverse evolution!
@ -613,7 +613,7 @@ namespace PKHeX.Core
continue;
oneValid = true;
updateMinValues(dl, evo);
UpdateMinValues(dl, evo);
int species = evo.Species;
// Gen7 Personal Formes -- unmap the forme personal entry ID to the actual species ID since species are consecutive
@ -638,7 +638,7 @@ namespace PKHeX.Core
dl.Last().RequiresLvlUp = false;
return dl;
}
private static void updateMinValues(IReadOnlyCollection<DexLevel> dl, EvolutionMethod evo)
private static void UpdateMinValues(IReadOnlyCollection<DexLevel> dl, EvolutionMethod evo)
{
var last = dl.Last();
if (evo.Level == 0) // Evolutions like elemental stones, trade, etc
@ -671,7 +671,7 @@ namespace PKHeX.Core
last.RequiresLvlUp = evo.RequiresLevelUp;
}
}
public class EvolutionStage
public struct EvolutionStage
{
public List<EvolutionMethod> StageEntryMethods;
}

View file

@ -15,8 +15,7 @@ namespace PKHeX.Core
public class GBEncounterData : IEncounterable
{
public readonly int Level;
public int MoveLevel;
public GameVersion Game;
public readonly GameVersion Game;
public readonly int Generation;
public readonly GBEncounterType Type;
public readonly IEncounterable Encounter;
@ -64,7 +63,6 @@ namespace PKHeX.Core
: slot.LevelMin;
Type = GBEncounterType.WildEncounter;
}
MoveLevel = Level;
}
}
}

View file

@ -2,6 +2,6 @@
{
internal interface IGeneration
{
int Generation { get; set; }
int Generation { get; }
}
}

View file

@ -24,12 +24,12 @@
internal static class RibbonSetHelper
{
public static readonly string[] RibbonNames1 =
private static readonly string[] RibbonNames1 =
{
nameof(IRibbonSet1.RibbonEarth), nameof(IRibbonSet1.RibbonNational), nameof(IRibbonSet1.RibbonCountry),
nameof(IRibbonSet1.RibbonChampionBattle), nameof(IRibbonSet1.RibbonChampionRegional), nameof(IRibbonSet1.RibbonChampionNational)
};
public static bool[] getRibbonBits(IRibbonSet1 set)
internal static bool[] GetRibbonBits(IRibbonSet1 set)
{
if (set == null)
return new bool[6];
@ -43,13 +43,13 @@
set.RibbonChampionNational,
};
}
public static readonly string[] RibbonNames2 =
private static readonly string[] RibbonNames2 =
{
nameof(IRibbonSet2.RibbonClassic), nameof(IRibbonSet2.RibbonWishing), nameof(IRibbonSet2.RibbonPremier),
nameof(IRibbonSet2.RibbonEvent), nameof(IRibbonSet2.RibbonBirthday), nameof(IRibbonSet2.RibbonSpecial),
nameof(IRibbonSet2.RibbonWorld), nameof(IRibbonSet2.RibbonChampionWorld), nameof(IRibbonSet2.RibbonSouvenir)
};
public static bool[] getRibbonBits(IRibbonSet2 set)
internal static bool[] GetRibbonBits(IRibbonSet2 set)
{
if (set == null)
return new bool[9];
@ -66,10 +66,7 @@
set.RibbonSouvenir,
};
}
public static string getRibbonNames(IRibbonSet1 set, int index) => RibbonNames1[index];
public static string getRibbonNames(IRibbonSet2 set, int index) => RibbonNames2[index];
public static string[] getRibbonNames(IRibbonSet1 set) => RibbonNames1;
public static string[] getRibbonNames(IRibbonSet2 set) => RibbonNames2;
internal static string[] GetRibbonNames(IRibbonSet1 set) => RibbonNames1;
internal static string[] GetRibbonNames(IRibbonSet2 set) => RibbonNames2;
}
}

View file

@ -16,7 +16,7 @@ namespace PKHeX.Core
/// <param name="maxLevel">Maximum level</param>
/// <param name="minLevel">Minimum level</param>
/// <returns>Array of Move IDs</returns>
public int[] getMoves(int maxLevel, int minLevel = 0)
public int[] GetMoves(int maxLevel, int minLevel = 0)
{
if (minLevel <= 1 && maxLevel >= 100)
return Moves;
@ -35,7 +35,7 @@ namespace PKHeX.Core
/// <param name="level">The level the Pokémon was encountered at.</param>
/// <param name="count">The amount of move slots to return.</param>
/// <returns>Array of Move IDs</returns>
public int[] getEncounterMoves(int level, int count = 4)
public int[] GetEncounterMoves(int level, int count = 4)
{
if (count == 0 || Moves.Length == 0)
return new int[0];
@ -53,7 +53,7 @@ namespace PKHeX.Core
/// <remarks>Helps determine the minimum level an encounter can be at.</remarks>
/// <param name="level">The level the Pokémon was encountered at.</param>
/// <returns>Array of Move IDs</returns>
public int getMinMoveLevel(int level)
public int GetMinMoveLevel(int level)
{
if (Levels.Length == 0)
return 1;
@ -65,7 +65,7 @@ namespace PKHeX.Core
/// <summary>Returns the level that a Pokémon can learn the specified move.</summary>
/// <param name="move">Move ID</param>
/// <returns>Level the move is learned at. If the result is below 0, it cannot be learned by levelup.</returns>
public int getLevelLearnMove(int move)
public int GetLevelLearnMove(int move)
{
int index = Array.IndexOf(Moves, move);
return index < 0 ? 0 : Levels[index];
@ -89,7 +89,7 @@ namespace PKHeX.Core
Levels = levels.ToArray();
Count = Moves.Length;
}
public static Learnset[] getArray(byte[] input, int maxSpecies)
public static Learnset[] GetArray(byte[] input, int maxSpecies)
{
var data = new Learnset[maxSpecies + 1];
@ -116,7 +116,7 @@ namespace PKHeX.Core
Levels[i] = br.ReadInt16();
}
}
public static Learnset[] getArray(byte[][] entries)
public static Learnset[] GetArray(byte[][] entries)
{
Learnset[] data = new Learnset[entries.Length];
for (int i = 0; i < data.Length; i++)
@ -140,7 +140,7 @@ namespace PKHeX.Core
Levels[i] = br.ReadInt16();
}
}
public static Learnset[] getArray(byte[][] entries)
public static Learnset[] GetArray(byte[][] entries)
{
Learnset[] data = new Learnset[entries.Length];
for (int i = 0; i < data.Length; i++)

View file

@ -7,14 +7,14 @@ namespace PKHeX.Core
{
public int EncounterSpecies { get; set; }
public DexLevel[][] EvolutionChains { get; set; }
public List<int>[] validLevelUpMoves { get; set; } = Empty;
public List<int>[] validTMHMMoves { get; set; } = Empty;
public List<int>[] validTutorMoves { get; set; } = Empty;
public List<int>[] LevelUpMoves { get; set; } = Empty;
public List<int>[] TMHMMoves { get; set; } = Empty;
public List<int>[] TutorMoves { get; set; } = Empty;
public int[] Relearn = new int[0];
public int minLvlG1 { get; set; }
public int minLvlG2 { get; set; }
public int MinimumLevelGen1 { get; set; }
public int MinimumLevelGen2 { get; set; }
private const int EmptyCount = 7;
public static readonly List<int>[] Empty = new int[EmptyCount].Select(z => new List<int>()).ToArray();
private static readonly List<int>[] Empty = new int[EmptyCount].Select(z => new List<int>()).ToArray();
}
}

View file

@ -1231,7 +1231,7 @@ namespace PKHeX.Core
183,194,195,298,399,400, // Pre-National Pokédex
046,102,115,193,285,316,452,454 // Post-National Pokédex
};
private static readonly EncounterArea[] DP_GreatMarshAlt = EncounterArea.getSimpleEncounterArea(DP_GreatMarshAlt_Species, new[] { 22, 22, 24, 24, 26, 26 }, 52, SlotType.Grass_Safari);
private static readonly EncounterArea[] DP_GreatMarshAlt = EncounterArea.GetSimpleEncounterArea(DP_GreatMarshAlt_Species, new[] { 22, 22, 24, 24, 26, 26 }, 52, SlotType.Grass_Safari);
private static readonly int[] Pt_GreatMarshAlt_Species =
{
@ -1239,7 +1239,7 @@ namespace PKHeX.Core
194, // Pre-National Pokédex
046,102,115,285,316,352,452,454 // Post-National Pokédex
};
private static readonly EncounterArea[] Pt_GreatMarshAlt = EncounterArea.getSimpleEncounterArea(Pt_GreatMarshAlt_Species, new[] { 27, 30 }, 52, SlotType.Grass_Safari);
private static readonly EncounterArea[] Pt_GreatMarshAlt = EncounterArea.GetSimpleEncounterArea(Pt_GreatMarshAlt_Species, new[] { 27, 30 }, 52, SlotType.Grass_Safari);
private static readonly int[] Shellos_EastSeaLocation_DP =
{

View file

@ -690,8 +690,8 @@ namespace PKHeX.Core
{
194,270,283,341,
};
private static readonly EncounterArea[] WhiteForestSlot = EncounterArea.getSimpleEncounterArea(WhiteForest_GrassSpecies, new[] { 5, 5 }, 51, SlotType.Grass).Concat(
EncounterArea.getSimpleEncounterArea(WhiteForest_SurfSpecies, new[] { 5, 5 }, 51, SlotType.Surf)).ToArray();
private static readonly EncounterArea[] WhiteForestSlot = EncounterArea.GetSimpleEncounterArea(WhiteForest_GrassSpecies, new[] { 5, 5 }, 51, SlotType.Grass).Concat(
EncounterArea.GetSimpleEncounterArea(WhiteForest_SurfSpecies, new[] { 5, 5 }, 51, SlotType.Surf)).ToArray();
private static readonly EncounterArea[] SlotsBW_Swarm =
{
//level range and Slottype will be marked later

View file

@ -269,26 +269,26 @@ namespace PKHeX.Core
internal static readonly string[][] TradeXY =
{
new string[0], // 0 - None
Util.getStringList("tradexy", "ja"), // 1
Util.getStringList("tradexy", "en"), // 2
Util.getStringList("tradexy", "fr"), // 3
Util.getStringList("tradexy", "it"), // 4
Util.getStringList("tradexy", "de"), // 5
Util.GetStringList("tradexy", "ja"), // 1
Util.GetStringList("tradexy", "en"), // 2
Util.GetStringList("tradexy", "fr"), // 3
Util.GetStringList("tradexy", "it"), // 4
Util.GetStringList("tradexy", "de"), // 5
new string[0], // 6 - None
Util.getStringList("tradexy", "es"), // 7
Util.getStringList("tradexy", "ko"), // 8
Util.GetStringList("tradexy", "es"), // 7
Util.GetStringList("tradexy", "ko"), // 8
};
internal static readonly string[][] TradeAO =
{
new string[0], // 0 - None
Util.getStringList("tradeao", "ja"), // 1
Util.getStringList("tradeao", "en"), // 2
Util.getStringList("tradeao", "fr"), // 3
Util.getStringList("tradeao", "it"), // 4
Util.getStringList("tradeao", "de"), // 5
Util.GetStringList("tradeao", "ja"), // 1
Util.GetStringList("tradeao", "en"), // 2
Util.GetStringList("tradeao", "fr"), // 3
Util.GetStringList("tradeao", "it"), // 4
Util.GetStringList("tradeao", "de"), // 5
new string[0], // 6 - None
Util.getStringList("tradeao", "es"), // 7
Util.getStringList("tradeao", "ko"), // 8
Util.GetStringList("tradeao", "es"), // 7
Util.GetStringList("tradeao", "ko"), // 8
};
#region XY Alt Slots

View file

@ -4,13 +4,13 @@ namespace PKHeX.Core
{
public static partial class Legal
{
private class CountryTable
private struct CountryTable
{
public byte countryID;
public byte mainform;
public FormSubregionTable[] otherforms;
}
private class FormSubregionTable
private struct FormSubregionTable
{
public byte form;
public int[] region;

View file

@ -11,7 +11,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="len">Length, in bytes, of the data of which to determine validity.</param>
/// <returns>A boolean indicating whether or not the given length is valid for a mystery gift.</returns>
public static bool getIsMysteryGift(long len)
public static bool IsMysteryGift(long len)
{
return new[] { WC6.SizeFull, WC6.Size, PGF.Size, PGT.Size, PCD.Size }.Contains((int)len);
}
@ -22,8 +22,8 @@ namespace PKHeX.Core
/// <param name="data">Raw data of the mystery gift.</param>
/// <param name="ext">Extension of the file from which the <paramref name="data"/> was retrieved.</param>
/// <returns>An instance of <see cref="MysteryGift"/> representing the given data, or null if <paramref name="data"/> or <paramref name="ext"/> is invalid.</returns>
/// <remarks>This overload differs from <see cref="getMysteryGift(byte[])"/> by checking the <paramref name="data"/>/<paramref name="ext"/> combo for validity. If either is invalid, a null reference is returned.</remarks>
public static MysteryGift getMysteryGift(byte[] data, string ext)
/// <remarks>This overload differs from <see cref="GetMysteryGift(byte[])"/> by checking the <paramref name="data"/>/<paramref name="ext"/> combo for validity. If either is invalid, a null reference is returned.</remarks>
public static MysteryGift GetMysteryGift(byte[] data, string ext)
{
// Generation 7
if (data.Length == WC7.SizeFull && ext == ".wc7full")
@ -55,7 +55,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="data">Raw data of the mystery gift.</param>
/// <returns>An instance of <see cref="MysteryGift"/> representing the given data, or null if <paramref name="data"/> is invalid.</returns>
public static MysteryGift getMysteryGift(byte[] data)
public static MysteryGift GetMysteryGift(byte[] data)
{
switch (data.Length)
{
@ -81,15 +81,15 @@ namespace PKHeX.Core
}
public string Extension => GetType().Name.ToLower();
public string FileName => getCardHeader() + "." + Extension;
public string FileName => CardHeader + "." + Extension;
public byte[] Data { get; set; }
public abstract PKM convertToPKM(SaveFile SAV);
public abstract PKM ConvertToPKM(SaveFile SAV);
public abstract int Format { get; }
public MysteryGift Clone()
{
byte[] data = (byte[])Data.Clone();
return getMysteryGift(data);
return GetMysteryGift(data);
}
public string Type => GetType().Name;
public string Name => $"Event Gift ({Type})";
@ -101,7 +101,7 @@ namespace PKHeX.Core
public abstract int CardID { get; set; }
public abstract bool IsItem { get; set; }
public abstract int Item { get; set; }
public abstract int ItemID { get; set; }
public abstract bool IsPokémon { get; set; }
public virtual int Quantity { get => 1; set { } }
@ -113,7 +113,7 @@ namespace PKHeX.Core
public virtual int Bean { get => 0; set { } }
public virtual int BeanCount { get => 0; set { } }
public virtual string getCardHeader() => (CardID > 0 ? $"Card #: {CardID:0000}" : "N/A") + $" - {CardTitle.Replace('\u3000',' ').Trim()}";
public virtual string CardHeader => (CardID > 0 ? $"Card #: {CardID:0000}" : "N/A") + $" - {CardTitle.Replace('\u3000',' ').Trim()}";
public override int GetHashCode()
{

View file

@ -88,7 +88,7 @@ namespace PKHeX.Core
}
// Card Attributes
public override int Item { get => BitConverter.ToUInt16(Data, 0x00); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x00); }
public override int ItemID { get => BitConverter.ToUInt16(Data, 0x00); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x00); }
private ushort Year { get => BitConverter.ToUInt16(Data, 0xAE); set => BitConverter.GetBytes(value).CopyTo(Data, 0xAE); }
private byte Month { get => Data[0xAD]; set => Data[0xAD] = value; }
@ -148,7 +148,7 @@ namespace PKHeX.Core
public override bool IsItem { get => CardType == 2; set { if (value) CardType = 2; } }
public bool IsPower { get => CardType == 3; set { if (value) CardType = 3; } }
public override PKM convertToPKM(SaveFile SAV)
public override PKM ConvertToPKM(SaveFile SAV)
{
if (!IsPokémon)
return null;
@ -160,17 +160,17 @@ namespace PKHeX.Core
Month = (byte)dt.Month;
Year = (byte)dt.Year;
}
int currentLevel = Level > 0 ? Level : (int)(Util.rnd32() % 100 + 1);
var pi = PersonalTable.B2W2.getFormeEntry(Species, Form);
int currentLevel = Level > 0 ? Level : (int)(Util.Rand32() % 100 + 1);
var pi = PersonalTable.B2W2.GetFormeEntry(Species, Form);
PK5 pk = new PK5
{
Species = Species,
HeldItem = HeldItem,
Met_Level = currentLevel,
Nature = Nature != 0xFF ? Nature : (int)(Util.rnd32() % 25),
Nature = Nature != 0xFF ? Nature : (int)(Util.Rand32() % 25),
Gender = pi.Gender == 255 ? 2 : (Gender != 2 ? Gender : pi.RandomGender),
AltForm = Form,
Version = OriginGame == 0 ? new[] {20, 21, 22, 23}[Util.rnd32() & 0x3] : OriginGame,
Version = OriginGame == 0 ? new[] {20, 21, 22, 23}[Util.Rand32() & 0x3] : OriginGame,
Language = Language == 0 ? SAV.Language : Language,
Ball = Ball,
Move1 = Move1,
@ -187,7 +187,7 @@ namespace PKHeX.Core
CNT_Tough = CNT_Tough,
CNT_Sheen = CNT_Sheen,
EXP = PKX.getEXP(Level, Species),
EXP = PKX.GetEXP(Level, Species),
// Ribbons
RibbonCountry = RibbonCountry,
@ -210,10 +210,10 @@ namespace PKHeX.Core
FatefulEncounter = true,
};
pk.CurrentFriendship = pk.IsEgg ? pi.HatchCycles : pi.BaseFriendship;
pk.Move1_PP = pk.getMovePP(Move1, 0);
pk.Move2_PP = pk.getMovePP(Move2, 0);
pk.Move3_PP = pk.getMovePP(Move3, 0);
pk.Move4_PP = pk.getMovePP(Move4, 0);
pk.Move1_PP = pk.GetMovePP(Move1, 0);
pk.Move2_PP = pk.GetMovePP(Move2, 0);
pk.Move3_PP = pk.GetMovePP(Move3, 0);
pk.Move4_PP = pk.GetMovePP(Move4, 0);
if (OTGender == 3) // User's
{
pk.TID = SAV.TID;
@ -229,14 +229,14 @@ namespace PKHeX.Core
pk.OT_Gender = OTGender % 2; // %2 just in case?
}
pk.IsNicknamed = IsNicknamed;
pk.Nickname = IsNicknamed ? Nickname : PKX.getSpeciesName(Species, pk.Language);
pk.Nickname = IsNicknamed ? Nickname : PKX.GetSpeciesName(Species, pk.Language);
// More 'complex' logic to determine final values
// Dumb way to generate random IVs.
int[] finalIVs = new int[6];
for (int i = 0; i < IVs.Length; i++)
finalIVs[i] = IVs[i] == 0xFF ? (int)(Util.rnd32() & 0x1F) : IVs[i];
finalIVs[i] = IVs[i] == 0xFF ? (int)(Util.Rand32() & 0x1F) : IVs[i];
pk.IVs = finalIVs;
int av = 0;
@ -249,7 +249,7 @@ namespace PKHeX.Core
break;
case 03: // 0/1
case 04: // 0/1/H
av = (int)(Util.rnd32() % (AbilityType - 1));
av = (int)(Util.Rand32() % (AbilityType - 1));
break;
}
pk.HiddenAbility = av == 2;
@ -259,10 +259,10 @@ namespace PKHeX.Core
pk.PID = PID;
else
{
pk.PID = Util.rnd32();
pk.PID = Util.Rand32();
// Force Gender
do { pk.PID = (pk.PID & 0xFFFFFF00) | Util.rnd32() & 0xFF; } while (!pk.getGenderIsValid());
do { pk.PID = (pk.PID & 0xFFFFFF00) | Util.Rand32() & 0xFF; } while (!pk.IsGenderValid());
// Force Ability
if (av == 1) pk.PID |= 0x10000; else pk.PID &= 0xFFFEFFFF;

View file

@ -52,7 +52,7 @@ namespace PKHeX.Core
public override bool GiftUsed { get => Gift.GiftUsed; set => Gift.GiftUsed = value; }
public override bool IsPokémon { get => Gift.IsPokémon; set => Gift.IsPokémon = value; }
public override bool IsItem { get => Gift.IsItem; set => Gift.IsItem = value; }
public override int Item { get => Gift.Item; set => Gift.Item = value; }
public override int ItemID { get => Gift.ItemID; set => Gift.ItemID = value; }
public override int CardID
{
get => BitConverter.ToUInt16(Data, 0x150);
@ -60,10 +60,10 @@ namespace PKHeX.Core
}
public override string CardTitle
{
get => PKX.getString4(Data, 0x104, 0x48);
get => PKX.GetString4(Data, 0x104, 0x48);
set
{
byte[] data = PKX.setString4(value, 0x48/2-1, 0x48/2, 0xFFFF);
byte[] data = PKX.SetString4(value, 0x48/2-1, 0x48/2, 0xFFFF);
int len = data.Length;
Array.Resize(ref data, 0x48);
for (int i = 0; i < len; i++)
@ -95,9 +95,9 @@ namespace PKHeX.Core
return true;
}
public override PKM convertToPKM(SaveFile SAV)
public override PKM ConvertToPKM(SaveFile SAV)
{
return Gift.convertToPKM(SAV);
return Gift.ConvertToPKM(SAV);
}
}
public sealed class PGT : MysteryGift
@ -146,7 +146,7 @@ namespace PKHeX.Core
// Unused 0x01
public byte Slot { get => Data[2]; set => Data[2] = value; }
public byte Detail { get => Data[3]; set => Data[3] = value; }
public override int Item { get => BitConverter.ToUInt16(Data, 0x4); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x4); }
public override int ItemID { get => BitConverter.ToUInt16(Data, 0x4); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x4); }
public PK4 PK
{
@ -155,7 +155,7 @@ namespace PKHeX.Core
byte[] ekdata = new byte[PKX.SIZE_4PARTY];
Array.Copy(Data, 8, ekdata, 0, ekdata.Length);
bool empty = ekdata.SequenceEqual(new byte[ekdata.Length]);
return new PK4(empty ? ekdata : PKX.decryptArray45(ekdata));
return new PK4(empty ? ekdata : PKX.DecryptArray45(ekdata));
}
set
{
@ -164,27 +164,11 @@ namespace PKHeX.Core
var pkdata = value.Data.SequenceEqual(new byte[value.Data.Length])
? value.Data
: PKX.encryptArray45(value.Data);
: PKX.EncryptArray45(value.Data);
pkdata.CopyTo(Data, 8);
}
}
private byte[] Unknown
{
get
{
var data = new byte[0x10];
Array.Copy(Data, 0xF4, data, 0, 0x10);
return data;
}
set
{
if (value == null || value.Length != 10)
return;
value.CopyTo(Data, 0xF4);
}
}
private GiftType PGTGiftType { get => (GiftType)Data[0]; set => Data[0] = (byte)value; }
public bool IsHatched => PGTGiftType == GiftType.Pokémon;
public override bool IsEgg { get => PGTGiftType == GiftType.PokémonEgg; set { if (value) { PGTGiftType = GiftType.PokémonEgg; PK.IsEgg = true; } } }
@ -198,13 +182,13 @@ namespace PKHeX.Core
public override int HeldItem { get => PK.HeldItem; set => PK.HeldItem = value; }
public override bool IsShiny => PK.IsShiny;
public override PKM convertToPKM(SaveFile SAV)
public override PKM ConvertToPKM(SaveFile SAV)
{
if (!IsPokémon)
return null;
PK4 pk4 = new PK4(PK.Data);
var pi = PersonalTable.HGSS.getFormeEntry(Species, PK.AltForm);
var pi = PersonalTable.HGSS.GetFormeEntry(Species, PK.AltForm);
if (!IsHatched && Detail == 0)
{
pk4.OT_Name = SAV.OT;
@ -232,7 +216,7 @@ namespace PKHeX.Core
pk4.CurrentFriendship = pk4.IsEgg ? pi.HatchCycles : pi.BaseFriendship;
// Generate IV
uint seed = Util.rnd32();
uint seed = Util.Rand32();
if (pk4.PID == 1) // Create Nonshiny
{
uint pid1 = PKX.LCRNG(ref seed) >> 16;
@ -251,7 +235,7 @@ namespace PKHeX.Core
pk4.PID = pid1 | (pid2 << 16);
}
if (!IsManaphyEgg)
seed = Util.rnd32(); // reseed, do not have method 1 correlation
seed = Util.Rand32(); // reseed, do not have method 1 correlation
// Generate IVs
if (pk4.IV32 == 0)
@ -277,7 +261,7 @@ namespace PKHeX.Core
pk4.Met_Location = pk4.Egg_Location + 3000;
pk4.Egg_Location = 0;
pk4.IsNicknamed = true;
pk4.Nickname = PKX.getSpeciesName(0, pk4.Language).ToUpper();
pk4.Nickname = PKX.GetSpeciesName(0, pk4.Language).ToUpper();
pk4.MetDate = DateTime.Now;
}
else
@ -289,7 +273,7 @@ namespace PKHeX.Core
}
}
if (pk4.Species == 201) // Never will be true; Unown was never distributed.
pk4.AltForm = PKX.getUnownForm(pk4.PID);
pk4.AltForm = PKX.GetUnownForm(pk4.PID);
pk4.RefreshChecksum();
return pk4;

View file

@ -11,19 +11,19 @@ namespace PKHeX.Core
/// </summary>
public PIDType Method;
public string OT_Name;
public int OT_Gender = 3;
public int TID;
public int SID;
public int Met_Location = 255;
public int Version;
public int Language;
public string OT_Name { get; set; }
public int OT_Gender { get; set; } = 3;
public int TID { get; set; }
public int SID { get; set; }
public int Met_Location { get; internal set; } = 255;
public int Version { get; set; }
public int Language { get; set; }
public override int Species { get; set; }
public override bool IsEgg { get; set; }
public override int[] Moves { get; set; }
public bool NotDistributed = false;
public bool? Shiny = null; // null = allow, false = never, true = always
public bool Fateful = false; // Obedience Flag
public bool NotDistributed { get; set; }
public bool? Shiny { get; set; } // null = allow, false = never, true = always
public bool Fateful { get; set; } // Obedience Flag
// Mystery Gift Properties
public override int Format => 3;
@ -32,16 +32,16 @@ namespace PKHeX.Core
// Description
public override string CardTitle { get; set; } = "Generation 3 Event";
public override string getCardHeader() => CardTitle;
public override string CardHeader => CardTitle;
// Unused
public override bool GiftUsed { get; set; }
public override int CardID { get; set; }
public override bool IsItem { get; set; }
public override int Item { get; set; }
public override int ItemID { get; set; }
public override bool IsPokémon { get; set; }
public override PKM convertToPKM(SaveFile SAV)
public override PKM ConvertToPKM(SaveFile SAV)
{
throw new NotImplementedException();
}

View file

@ -89,7 +89,7 @@ namespace PKHeX.Core
// Item Properties
public override bool IsItem { get => CardType == 1; set { if (value) CardType = 1; } }
public override int Item {
public override int ItemID {
get => BitConverter.ToUInt16(Data, 0x68);
set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x68); }
public override int Quantity {
@ -272,13 +272,13 @@ namespace PKHeX.Core
}
}
public override PKM convertToPKM(SaveFile SAV)
public override PKM ConvertToPKM(SaveFile SAV)
{
if (!IsPokémon)
return null;
int currentLevel = Level > 0 ? Level : (int)(Util.rnd32()%100 + 1);
var pi = PersonalTable.AO.getFormeEntry(Species, Form);
int currentLevel = Level > 0 ? Level : (int)(Util.Rand32()%100 + 1);
var pi = PersonalTable.AO.GetFormeEntry(Species, Form);
PK6 pk = new PK6
{
Species = Species,
@ -286,10 +286,10 @@ namespace PKHeX.Core
TID = TID,
SID = SID,
Met_Level = currentLevel,
Nature = Nature != 0xFF ? Nature : (int)(Util.rnd32() % 25),
Nature = Nature != 0xFF ? Nature : (int)(Util.Rand32() % 25),
Gender = Gender != 3 ? Gender : pi.RandomGender,
AltForm = Form,
EncryptionConstant = EncryptionConstant != 0 ? EncryptionConstant : Util.rnd32(),
EncryptionConstant = EncryptionConstant != 0 ? EncryptionConstant : Util.Rand32(),
Version = OriginGame != 0 ? OriginGame : SAV.Game,
Language = Language != 0 ? Language : SAV.Language,
Ball = Ball,
@ -314,7 +314,7 @@ namespace PKHeX.Core
HT_Gender = OT.Length > 0 ? SAV.Gender : 0,
CurrentHandler = OT.Length > 0 ? 1 : 0,
EXP = PKX.getEXP(Level, Species),
EXP = PKX.GetEXP(Level, Species),
// Ribbons
RibbonCountry = RibbonCountry,
@ -345,10 +345,10 @@ namespace PKHeX.Core
EVs = EVs,
};
pk.CurrentFriendship = pk.IsEgg ? pi.HatchCycles : pi.BaseFriendship;
pk.Move1_PP = pk.getMovePP(Move1, 0);
pk.Move2_PP = pk.getMovePP(Move2, 0);
pk.Move3_PP = pk.getMovePP(Move3, 0);
pk.Move4_PP = pk.getMovePP(Move4, 0);
pk.Move1_PP = pk.GetMovePP(Move1, 0);
pk.Move2_PP = pk.GetMovePP(Move2, 0);
pk.Move3_PP = pk.GetMovePP(Move3, 0);
pk.Move4_PP = pk.GetMovePP(Move4, 0);
pk.MetDate = Date ?? DateTime.Now;
@ -362,18 +362,18 @@ namespace PKHeX.Core
pk.OT_Memory = 3;
pk.OT_TextVar = 9;
pk.OT_Intensity = 1;
pk.OT_Feeling = Util.rand.Next(0, 9);
pk.OT_Feeling = Util.Rand.Next(0, 9);
}
else
{
pk.HT_Memory = 3;
pk.HT_TextVar = 9;
pk.HT_Intensity = 1;
pk.HT_Feeling = Util.rand.Next(0, 9);
pk.HT_Feeling = Util.Rand.Next(0, 9);
pk.HT_Friendship = pk.OT_Friendship;
}
pk.IsNicknamed = IsNicknamed;
pk.Nickname = IsNicknamed ? Nickname : PKX.getSpeciesName(Species, pk.Language);
pk.Nickname = IsNicknamed ? Nickname : PKX.GetSpeciesName(Species, pk.Language);
// More 'complex' logic to determine final values
@ -384,18 +384,18 @@ namespace PKHeX.Core
case 0xFE:
do { // 3 Perfect IVs
for (int i = 0; i < 6; i++)
finalIVs[i] = IVs[i] > 31 ? (int)(Util.rnd32() & 0x1F) : IVs[i];
finalIVs[i] = IVs[i] > 31 ? (int)(Util.Rand32() & 0x1F) : IVs[i];
} while (finalIVs.Count(r => r == 31) < 3); // 3*31
break;
case 0xFD:
do { // 2 other 31s
for (int i = 0; i < 6; i++)
finalIVs[i] = IVs[i] > 31 ? (int)(Util.rnd32() & 0x1F) : IVs[i];
finalIVs[i] = IVs[i] > 31 ? (int)(Util.Rand32() & 0x1F) : IVs[i];
} while (finalIVs.Count(r => r == 31) < 2); // 2*31
break;
default: // Random IVs
for (int i = 0; i < 6; i++)
finalIVs[i] = IVs[i] > 31 ? (int)(Util.rnd32() & 0x1F) : IVs[i];
finalIVs[i] = IVs[i] > 31 ? (int)(Util.Rand32() & 0x1F) : IVs[i];
break;
}
pk.IVs = finalIVs;
@ -410,7 +410,7 @@ namespace PKHeX.Core
break;
case 03: // 0/1
case 04: // 0/1/H
av = (int)(Util.rnd32()%(AbilityType - 1));
av = (int)(Util.Rand32()%(AbilityType - 1));
break;
}
pk.Ability = pi.Abilities[av];
@ -422,14 +422,14 @@ namespace PKHeX.Core
pk.PID = PID;
break;
case 01: // Random
pk.PID = Util.rnd32();
pk.PID = Util.Rand32();
break;
case 02: // Random Shiny
pk.PID = Util.rnd32();
pk.PID = Util.Rand32();
pk.PID = (uint)(((TID ^ SID ^ (pk.PID & 0xFFFF)) << 16) + (pk.PID & 0xFFFF));
break;
case 03: // Random Nonshiny
pk.PID = Util.rnd32();
pk.PID = Util.Rand32();
if ((uint)(((TID ^ SID ^ (pk.PID & 0xFFFF)) << 16) + (pk.PID & 0xFFFF)) < 16) pk.PID ^= 0x10000000;
break;
}

View file

@ -91,21 +91,21 @@ namespace PKHeX.Core
public override bool IsBP { get => CardType == 3; set { if (value) CardType = 3; } }
public override int BP
{
get => Item;
set => Item = value;
get => ItemID;
set => ItemID = value;
}
// Bean (Mame) Properties
public override bool IsBean { get => CardType == 2; set { if (value) CardType = 2; } }
public override int Bean
{
get => Item;
set => Item = value;
get => ItemID;
set => ItemID = value;
}
// Item Properties
public override bool IsItem { get => CardType == 1; set { if (value) CardType = 1; } }
public override int Item {
public override int ItemID {
get => BitConverter.ToUInt16(Data, 0x68);
set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x68); }
@ -296,14 +296,14 @@ namespace PKHeX.Core
}
}
public override PKM convertToPKM(SaveFile SAV)
public override PKM ConvertToPKM(SaveFile SAV)
{
if (!IsPokémon)
return null;
int currentLevel = Level > 0 ? Level : (int)(Util.rnd32()%100 + 1);
int currentLevel = Level > 0 ? Level : (int)(Util.Rand32()%100 + 1);
int metLevel = MetLevel > 0 ? MetLevel : currentLevel;
var pi = PersonalTable.SM.getFormeEntry(Species, Form);
var pi = PersonalTable.SM.GetFormeEntry(Species, Form);
PK7 pk = new PK7
{
Species = Species,
@ -311,10 +311,10 @@ namespace PKHeX.Core
TID = TID,
SID = SID,
Met_Level = metLevel,
Nature = Nature != 0xFF ? Nature : (int)(Util.rnd32() % 25),
Nature = Nature != 0xFF ? Nature : (int)(Util.Rand32() % 25),
Gender = Gender != 3 ? Gender : pi.RandomGender,
AltForm = Form,
EncryptionConstant = EncryptionConstant != 0 ? EncryptionConstant : Util.rnd32(),
EncryptionConstant = EncryptionConstant != 0 ? EncryptionConstant : Util.Rand32(),
Version = OriginGame != 0 ? OriginGame : SAV.Game,
Language = Language != 0 ? Language : SAV.Language,
Ball = Ball,
@ -339,7 +339,7 @@ namespace PKHeX.Core
HT_Gender = OT.Length > 0 ? SAV.Gender : 0,
CurrentHandler = OT.Length > 0 ? 1 : 0,
EXP = PKX.getEXP(currentLevel, Species),
EXP = PKX.GetEXP(currentLevel, Species),
// Ribbons
RibbonCountry = RibbonCountry,
@ -370,10 +370,10 @@ namespace PKHeX.Core
EVs = EVs,
};
pk.CurrentFriendship = pk.IsEgg ? pi.HatchCycles : pi.BaseFriendship;
pk.Move1_PP = pk.getMovePP(Move1, 0);
pk.Move2_PP = pk.getMovePP(Move2, 0);
pk.Move3_PP = pk.getMovePP(Move3, 0);
pk.Move4_PP = pk.getMovePP(Move4, 0);
pk.Move1_PP = pk.GetMovePP(Move1, 0);
pk.Move2_PP = pk.GetMovePP(Move2, 0);
pk.Move3_PP = pk.GetMovePP(Move3, 0);
pk.Move4_PP = pk.GetMovePP(Move4, 0);
if (OTGender == 3)
{
@ -384,7 +384,7 @@ namespace PKHeX.Core
pk.MetDate = Date ?? DateTime.Now;
pk.IsNicknamed = IsNicknamed;
pk.Nickname = IsNicknamed ? Nickname : PKX.getSpeciesName(Species, pk.Language);
pk.Nickname = IsNicknamed ? Nickname : PKX.GetSpeciesName(Species, pk.Language);
// More 'complex' logic to determine final values
@ -395,18 +395,18 @@ namespace PKHeX.Core
case 0xFE:
do { // 3 Perfect IVs
for (int i = 0; i < 6; i++)
finalIVs[i] = IVs[i] > 31 ? (int)(Util.rnd32() & 0x1F) : IVs[i];
finalIVs[i] = IVs[i] > 31 ? (int)(Util.Rand32() & 0x1F) : IVs[i];
} while (finalIVs.Count(r => r == 31) < 3); // 3*31
break;
case 0xFD:
do { // 2 other 31s
for (int i = 0; i < 6; i++)
finalIVs[i] = IVs[i] > 31 ? (int)(Util.rnd32() & 0x1F) : IVs[i];
finalIVs[i] = IVs[i] > 31 ? (int)(Util.Rand32() & 0x1F) : IVs[i];
} while (finalIVs.Count(r => r == 31) < 2); // 2*31
break;
default: // Random IVs
for (int i = 0; i < 6; i++)
finalIVs[i] = IVs[i] > 31 ? (int)(Util.rnd32() & 0x1F) : IVs[i];
finalIVs[i] = IVs[i] > 31 ? (int)(Util.Rand32() & 0x1F) : IVs[i];
break;
}
pk.IVs = finalIVs;
@ -421,7 +421,7 @@ namespace PKHeX.Core
break;
case 03: // 0/1
case 04: // 0/1/H
av = (int)(Util.rnd32()%(AbilityType - 1));
av = (int)(Util.Rand32()%(AbilityType - 1));
break;
}
pk.Ability = pi.Abilities[av];
@ -433,14 +433,14 @@ namespace PKHeX.Core
pk.PID = PID;
break;
case 01: // Random
pk.PID = Util.rnd32();
pk.PID = Util.Rand32();
break;
case 02: // Random Shiny
pk.PID = Util.rnd32();
pk.PID = Util.Rand32();
pk.PID = (uint)(((TID ^ SID ^ (pk.PID & 0xFFFF)) << 16) + (pk.PID & 0xFFFF));
break;
case 03: // Random Nonshiny
pk.PID = Util.rnd32();
pk.PID = Util.Rand32();
if ((uint)(((TID ^ SID ^ (pk.PID & 0xFFFF)) << 16) + (pk.PID & 0xFFFF)) < 16) pk.PID ^= 0x10000000;
break;
}
@ -449,7 +449,7 @@ namespace PKHeX.Core
{
pk.IsEgg = true;
pk.EggMetDate = Date;
pk.Nickname = PKX.getSpeciesName(0, pk.Language);
pk.Nickname = PKX.GetSpeciesName(0, pk.Language);
}
pk.RefreshChecksum();

View file

@ -12,7 +12,7 @@ namespace PKHeX.Core
{
Data = (byte[])(decryptedData ?? new byte[SIZE_PARTY]).Clone();
uint sv = ((PID & 0x3E000) >> 0xD) % 24;
Data = PKX.shuffleArray45(Data, sv);
Data = PKX.ShuffleArray45(Data, sv);
Identifier = ident;
if (Sanity != 0 && Species <= MaxSpeciesID && !ChecksumValid) // We can only hope
RefreshChecksum();
@ -23,12 +23,12 @@ namespace PKHeX.Core
}
public override PKM Clone() { return new BK4(Encrypt()); }
public override string getString(int Offset, int Count) => PKX.getBEString4(Data, Offset, Count);
public override byte[] setString(string value, int maxLength) => PKX.setBEString4(value, maxLength);
public override string GetString(int Offset, int Count) => PKX.GetBEString4(Data, Offset, Count);
public override byte[] SetString(string value, int maxLength) => PKX.SetBEString4(value, maxLength);
// Trash Bytes
public override byte[] Nickname_Trash { get => getData(0x48, 24); set { if (value?.Length == 24) value.CopyTo(Data, 0x48); } }
public override byte[] OT_Trash { get => getData(0x68, 16); set { if (value?.Length == 16) value.CopyTo(Data, 0x68); } }
public override byte[] Nickname_Trash { get => GetData(0x48, 24); set { if (value?.Length == 24) value.CopyTo(Data, 0x48); } }
public override byte[] OT_Trash { get => GetData(0x68, 16); set { if (value?.Length == 16) value.CopyTo(Data, 0x68); } }
// Structure
public override uint PID { get => BigEndian.ToUInt32(Data, 0x00); set => BigEndian.GetBytes(value).CopyTo(Data, 0x00); }
@ -138,7 +138,7 @@ namespace PKHeX.Core
#endregion
#region Block C
public override string Nickname { get => getString(0x48, 24); set => setString(value, 11).CopyTo(Data, 0x48); }
public override string Nickname { get => GetString(0x48, 24); set => SetString(value, 11).CopyTo(Data, 0x48); }
// 0x5E unused
public override int Version { get => Data[0x5F]; set => Data[0x5F] = (byte)value; }
private byte RIB8 { get => Data[0x60]; set => Data[0x60] = value; } // Sinnoh 3
@ -180,7 +180,7 @@ namespace PKHeX.Core
#endregion
#region Block D
public override string OT_Name { get => getString(0x68, 16); set => setString(value, 7).CopyTo(Data, 0x68); }
public override string OT_Name { get => GetString(0x68, 16); set => SetString(value, 7).CopyTo(Data, 0x68); }
public override int Egg_Location
{
@ -262,13 +262,13 @@ namespace PKHeX.Core
return chk;
}
public override byte[] Encrypt()
protected override byte[] Encrypt()
{
RefreshChecksum();
return PKX.shuffleArray45(Data, PKX.blockPositionInvert[((PID & 0x3E000) >> 0xD)%24]);
return PKX.ShuffleArray45(Data, PKX.blockPositionInvert[((PID & 0x3E000) >> 0xD)%24]);
}
public PK4 convertToPK4()
public PK4 ConvertToPK4()
{
PK4 pk4 = new PK4();
TransferPropertiesWithReflection(this, pk4);

View file

@ -20,54 +20,54 @@ namespace PKHeX.Core
public CK3(byte[] decryptedData = null, string ident = null)
{
Data = (byte[])(decryptedData ?? new byte[SIZE_PARTY]).Clone();
PKMConverter.checkEncrypted(ref Data);
PKMConverter.CheckEncrypted(ref Data);
Identifier = ident;
if (Data.Length != SIZE_PARTY)
Array.Resize(ref Data, SIZE_PARTY);
}
public override PKM Clone() { return new CK3(Data); }
public override string getString(int Offset, int Count) => PKX.getBEString3(Data, Offset, Count);
public override byte[] setString(string value, int maxLength) => PKX.setBEString3(value, maxLength);
public override string GetString(int Offset, int Count) => PKX.GetBEString3(Data, Offset, Count);
public override byte[] SetString(string value, int maxLength) => PKX.SetBEString3(value, maxLength);
// Trash Bytes
public override byte[] Nickname_Trash { get => getData(0x2E, 20); set { if (value?.Length == 20) value.CopyTo(Data, 0x2E); } }
public override byte[] OT_Trash { get => getData(0x18, 20); set { if (value?.Length == 20) value.CopyTo(Data, 0x18); } }
public override byte[] Nickname_Trash { get => GetData(0x2E, 20); set { if (value?.Length == 20) value.CopyTo(Data, 0x2E); } }
public override byte[] OT_Trash { get => GetData(0x18, 20); set { if (value?.Length == 20) value.CopyTo(Data, 0x18); } }
// Future Attributes
public override uint EncryptionConstant { get => PID; set { } }
public override int Nature { get => (int)(PID % 25); set { } }
public override int AltForm { get => Species == 201 ? PKX.getUnownForm(PID) : 0; set { } }
public override int AltForm { get => Species == 201 ? PKX.GetUnownForm(PID) : 0; set { } }
public override bool IsNicknamed { get => PKX.getIsNicknamedAnyLanguage(Species, Nickname, Format); set { } }
public override int Gender { get => PKX.getGender(Species, PID); set { } }
public override bool IsNicknamed { get => PKX.IsNicknamedAnyLanguage(Species, Nickname, Format); set { } }
public override int Gender { get => PKX.GetGender(Species, PID); set { } }
public override int Characteristic => -1;
public override int CurrentFriendship { get => OT_Friendship; set => OT_Friendship = value; }
public override int Ability { get { int[] abils = PersonalTable.RS.getAbilities(Species, 0); return abils[abils[1] == 0 ? 0 : AbilityNumber >> 1]; } set { } }
public override int Ability { get { int[] abils = PersonalTable.RS.GetAbilities(Species, 0); return abils[abils[1] == 0 ? 0 : AbilityNumber >> 1]; } set { } }
public override int CurrentHandler { get => 0; set { } }
public override int Egg_Location { get => 0; set { } }
// Silly Attributes
public override ushort Sanity { get => 0; set { } } // valid flag set in pkm structure.
public override ushort Checksum { get => SaveUtil.ccitt16(Data); set { } } // totally false, just a way to get a 'random' ident for the pkm.
public override ushort Checksum { get => SaveUtil.CRC16_CCITT(Data); set { } } // totally false, just a way to get a 'random' ident for the pkm.
public override bool ChecksumValid => Valid;
public override int Species { get => PKX.getG4Species(BigEndian.ToUInt16(Data, 0x00)); set => BigEndian.GetBytes((ushort)PKX.getG3Species(value)).CopyTo(Data, 0x00); }
public override int Species { get => PKX.GetG4Species(BigEndian.ToUInt16(Data, 0x00)); set => BigEndian.GetBytes((ushort)PKX.GetG3Species(value)).CopyTo(Data, 0x00); }
// 02-04 unused
public override uint PID { get => BigEndian.ToUInt32(Data, 0x04); set => BigEndian.GetBytes(value).CopyTo(Data, 0x04); }
public override int Version { get => SaveUtil.getG3VersionID(Data[0x08]); set => Data[0x08] = (byte)SaveUtil.getCXDVersionID(value); }
public override int Version { get => SaveUtil.GetG3VersionID(Data[0x08]); set => Data[0x08] = (byte)SaveUtil.GetCXDVersionID(value); }
public int CurrentRegion { get => Data[0x09]; set => Data[0x09] = (byte)value; }
public int OriginalRegion { get => Data[0x0A]; set => Data[0x0A] = (byte)value; }
public override int Language { get => PKX.getMainLangIDfromGC(Data[0x0B]); set => Data[0x0B] = PKX.getGCLangIDfromMain((byte)value); }
public override int Language { get => PKX.GetMainLangIDfromGC(Data[0x0B]); set => Data[0x0B] = PKX.GetGCLangIDfromMain((byte)value); }
public override int Met_Location { get => BigEndian.ToUInt16(Data, 0x0C); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x0C); }
public override int Met_Level { get => Data[0x0E]; set => Data[0x0E] = (byte)value; }
public override int Ball { get => Data[0x0F]; set => Data[0x0F] = (byte)value; }
public override int OT_Gender { get => Data[0x10]; set => Data[0x10] = (byte)value; }
public override int SID { get => BigEndian.ToUInt16(Data, 0x14); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x14); }
public override int TID { get => BigEndian.ToUInt16(Data, 0x16); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x16); }
public override string OT_Name { get => getString(0x18, 20); set => setString(value, 10).CopyTo(Data, 0x18); } // +2 terminator
public override string Nickname { get => getString(0x2E, 20); set { setString(value, 10).CopyTo(Data, 0x2E); Nickname2 = value; } } // +2 terminator
private string Nickname2 { get => getString(0x44, 20); set => setString(value, 10).CopyTo(Data, 0x44); } // +2 terminator
public override string OT_Name { get => GetString(0x18, 20); set => SetString(value, 10).CopyTo(Data, 0x18); } // +2 terminator
public override string Nickname { get => GetString(0x2E, 20); set { SetString(value, 10).CopyTo(Data, 0x2E); Nickname2 = value; } } // +2 terminator
private string Nickname2 { get => GetString(0x44, 20); set => SetString(value, 10).CopyTo(Data, 0x44); } // +2 terminator
public override uint EXP { get => BigEndian.ToUInt32(Data, 0x5C); set => BigEndian.GetBytes(value).CopyTo(Data, 0x5C); }
public override int Stat_Level { get => Data[0x60]; set => Data[0x60] = (byte)value; }
@ -88,7 +88,7 @@ namespace PKHeX.Core
public override int Move4_PP { get => Data[0x86]; set => Data[0x86] = (byte)value; }
public override int Move4_PPUps { get => Data[0x87]; set => Data[0x87] = (byte)value; }
public override int SpriteItem => PKX.getG4Item((ushort)HeldItem);
public override int SpriteItem => PKX.GetG4Item((ushort)HeldItem);
public override int HeldItem { get => BigEndian.ToUInt16(Data, 0x88); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x88); }
// More party stats
@ -191,7 +191,7 @@ namespace PKHeX.Core
public override int TSV => (TID ^ SID) >> 3;
public bool Japanese => Language == 1;
public override byte[] Encrypt()
protected override byte[] Encrypt()
{
return (byte[])Data.Clone();
}

View file

@ -20,8 +20,8 @@ namespace PKHeX.Core
internal const int STRLEN_U = 11;
private int StringLength => Japanese ? STRLEN_J : STRLEN_U;
public override string getString(int Offset, int Count) => PKX.getString1(Data, Offset, Count, Japanese);
public override byte[] setString(string value, int maxLength) => PKX.setString1(value, maxLength, Japanese);
public override string GetString(int Offset, int Count) => PKX.GetString1(Data, Offset, Count, Japanese);
public override byte[] SetString(string value, int maxLength) => PKX.SetString1(value, maxLength, Japanese);
// Trash Bytes
public override byte[] Nickname_Trash { get => nick; set { if (value?.Length == nick.Length) nick = value; } }
@ -31,7 +31,7 @@ namespace PKHeX.Core
public bool Japanese => otname.Length == STRLEN_J;
public override string FileName => $"{Species:000} - {Nickname} - {SaveUtil.ccitt16(Encrypt()):X4}.{Extension}";
public override string FileName => $"{Species:000} - {Nickname} - {SaveUtil.CRC16_CCITT(Encrypt()):X4}.{Extension}";
public PK1(byte[] decryptedData = null, string ident = null, bool jp = false)
{
@ -53,10 +53,10 @@ namespace PKHeX.Core
}
public override string Nickname
{
get => PKX.getString1(nick, 0, nick.Length, Japanese);
get => PKX.GetString1(nick, 0, nick.Length, Japanese);
set
{
byte[] strdata = setString(value, StringLength);
byte[] strdata = SetString(value, StringLength);
if (nick.Any(b => b == 0) && nick[StringLength - 1] == 0x50 && Array.FindIndex(nick, b => b == 0) == strdata.Length - 1) // Handle JP Mew event with grace
{
int firstInd = Array.FindIndex(nick, b => b == 0);
@ -71,10 +71,10 @@ namespace PKHeX.Core
public override string OT_Name
{
get => PKX.getString1(otname, 0, otname.Length, Japanese);
get => PKX.GetString1(otname, 0, otname.Length, Japanese);
set
{
byte[] strdata = setString(value, StringLength);
byte[] strdata = SetString(value, StringLength);
if (otname.Any(b => b == 0) && otname[StringLength - 1] == 0x50 && Array.FindIndex(otname, b => b == 0) == strdata.Length - 1) // Handle JP Mew event with grace
{
int firstInd = Array.FindIndex(otname, b => b == 0);
@ -87,7 +87,7 @@ namespace PKHeX.Core
}
}
public override byte[] Encrypt() => new PokemonList1(this).GetBytes();
protected override byte[] Encrypt() => new PokemonList1(this).GetBytes();
public override byte[] EncryptedPartyData => Encrypt().ToArray();
public override byte[] EncryptedBoxData => Encrypt().ToArray();
public override byte[] DecryptedBoxData => Encrypt().ToArray();
@ -97,15 +97,15 @@ namespace PKHeX.Core
{
get
{
string spName = PKX.getSpeciesNameGeneration(Species, Japanese ? 1 : 2, Format);
return !nick.SequenceEqual(setString(spName, StringLength)
string spName = PKX.GetSpeciesNameGeneration(Species, Japanese ? 1 : 2, Format);
return !nick.SequenceEqual(SetString(spName, StringLength)
.Concat(Enumerable.Repeat((byte) 0x50, StringLength - spName.Length - 1))
.Select(b => (byte)(b == 0xF2 ? 0xE8 : b)));
}
set
{
if (!value)
setNotNicknamed();
SetNotNicknamed();
}
}
@ -113,15 +113,15 @@ namespace PKHeX.Core
{
get
{
var spName = PKX.getSpeciesNameGeneration(Species, Japanese ? 1 : 2, Format);
var spName = PKX.GetSpeciesNameGeneration(Species, Japanese ? 1 : 2, Format);
return Nickname != spName;
}
}
public void setNotNicknamed()
public void SetNotNicknamed()
{
string spName = PKX.getSpeciesNameGeneration(Species, Japanese ? 1 : 2, Format);
nick = setString(spName, StringLength)
string spName = PKX.GetSpeciesNameGeneration(Species, Japanese ? 1 : 2, Format);
nick = SetString(spName, StringLength)
.Concat(Enumerable.Repeat((byte)0x50, StringLength - spName.Length - 1))
.Select(b => (byte)(b == 0xF2 ? 0xE8 : b)) // Decimal point<->period fix
.ToArray();
@ -131,15 +131,15 @@ namespace PKHeX.Core
#region Stored Attributes
public override int Species
{
get => PKX.getG1Species(Data[0]);
get => PKX.GetG1Species(Data[0]);
set
{
Data[0] = (byte)PKX.setG1Species(value);
Data[0] = (byte)PKX.SetG1Species(value);
// Before updating catch rate, check if non-standard
if (!CatchRateIsItem)
{
int baseSpecies = Legal.getBaseSpecies(this);
int baseSpecies = Legal.GetBaseSpecies(this);
int Rate = Catch_Rate;
if (Enumerable.Range(baseSpecies, value).All(z => Rate != PersonalTable.RB[z].CatchRate))
Catch_Rate = PersonalTable.RB[value].CatchRate;
@ -205,8 +205,8 @@ namespace PKHeX.Core
public override int Stat_SPD { get => Stat_SPC; set { } }
#endregion
public override int getMovePP(int move, int ppup) => Math.Min(61, base.getMovePP(move, ppup));
public override ushort[] getStats(PersonalInfo p)
public override int GetMovePP(int move, int ppup) => Math.Min(61, base.GetMovePP(move, ppup));
public override ushort[] GetStats(PersonalInfo p)
{
ushort[] Stats = new ushort[6];
for (int i = 0; i < Stats.Length; i++)
@ -224,7 +224,7 @@ namespace PKHeX.Core
}
#region Future, Unused Attributes
public override bool getGenderIsValid()
public override bool IsGenderValid()
{
return true;
}
@ -280,7 +280,7 @@ namespace PKHeX.Core
public override int OTLength => Japanese ? 5 : 7;
public override int NickLength => Japanese ? 5 : 10;
public PK2 convertToPK2()
public PK2 ConvertToPK2()
{
PK2 pk2 = new PK2(null, Identifier, Japanese) {Species = Species};
Array.Copy(Data, 0x7, pk2.Data, 0x1, 0x1A);
@ -312,25 +312,25 @@ namespace PKHeX.Core
pk2.CurrentFriendship = pk2.PersonalInfo.BaseFriendship;
// Pokerus = 0
// Caught Data = 0
pk2.Stat_Level = PKX.getLevel(Species, EXP);
pk2.Stat_Level = PKX.GetLevel(Species, EXP);
Array.Copy(otname, 0, pk2.otname, 0, otname.Length);
Array.Copy(nick, 0, pk2.nick, 0, nick.Length);
return pk2;
}
public PK7 convertToPK7()
public PK7 ConvertToPK7()
{
var pk7 = new PK7
{
EncryptionConstant = Util.rnd32(),
EncryptionConstant = Util.Rand32(),
Species = Species,
TID = TID,
CurrentLevel = CurrentLevel,
EXP = EXP,
Met_Level = CurrentLevel,
Nature = (int) (EXP%25),
PID = Util.rnd32(),
PID = Util.Rand32(),
Ball = 4,
MetDate = DateTime.Now,
Version = (int)GameVersion.RD, // Default to red, for now?
@ -348,7 +348,7 @@ namespace PKHeX.Core
Move4_PP = Move4_PP,
Met_Location = 30013, // "Kanto region", hardcoded.
Gender = PersonalTable.SM[Species].RandomGender,
OT_Name = PKX.getG1ConvertedString(otname, Japanese),
OT_Name = PKX.GetG1ConvertedString(otname, Japanese),
IsNicknamed = false,
Country = PKMConverter.Country,
@ -361,10 +361,10 @@ namespace PKHeX.Core
Geo1_Country = PKMConverter.Country,
Geo1_Region = PKMConverter.Region
};
pk7.Nickname = PKX.getSpeciesNameGeneration(pk7.Species, pk7.Language, pk7.Format);
pk7.Nickname = PKX.GetSpeciesNameGeneration(pk7.Species, pk7.Language, pk7.Format);
if (otname[0] == 0x5D) // Ingame Trade
{
var s = PKX.getG1Char(0x5D, Japanese);
var s = PKX.GetG1Char(0x5D, Japanese);
pk7.OT_Name = s.Substring(0, 1) + s.Substring(1).ToLower();
}
pk7.OT_Friendship = pk7.HT_Friendship = PersonalTable.SM[Species].BaseFriendship;
@ -372,14 +372,14 @@ namespace PKHeX.Core
// IVs
var new_ivs = new int[6];
int flawless = Species == 151 ? 5 : 3;
for (var i = 0; i < new_ivs.Length; i++) new_ivs[i] = (int)(Util.rnd32() & 31);
for (var i = 0; i < new_ivs.Length; i++) new_ivs[i] = (int)(Util.Rand32() & 31);
for (var i = 0; i < flawless; i++) new_ivs[i] = 31;
Util.Shuffle(new_ivs);
pk7.IVs = new_ivs;
// Really? :(
if (IsShiny)
pk7.setShinyPID();
pk7.SetShinyPID();
int abil = 2; // Hidden
if (Legal.TransferSpeciesDefaultAbility_1.Contains(Species))
@ -391,7 +391,7 @@ namespace PKHeX.Core
else if (IsNicknamedBank)
{
pk7.IsNicknamed = true;
pk7.Nickname = PKX.getG1ConvertedString(nick, Japanese);
pk7.Nickname = PKX.GetG1ConvertedString(nick, Japanese);
}
pk7.TradeMemory(Bank:true); // oh no, memories on gen7 pkm
@ -433,23 +433,23 @@ namespace PKHeX.Core
Single
}
private static int getEntrySize(CapacityType c) => c == CapacityType.Single || c == CapacityType.Party
private static int GetEntrySize(CapacityType c) => c == CapacityType.Single || c == CapacityType.Party
? PKX.SIZE_1PARTY
: PKX.SIZE_1STORED;
private static byte getCapacity(CapacityType c) => c == CapacityType.Single ? (byte)1 : (byte)c;
private static byte GetCapacity(CapacityType c) => c == CapacityType.Single ? (byte)1 : (byte)c;
private static byte[] getEmptyList(CapacityType c, bool is_JP = false)
private static byte[] GetEmptyList(CapacityType c, bool is_JP = false)
{
int cap = getCapacity(c);
return new[] { (byte)0 }.Concat(Enumerable.Repeat((byte)0xFF, cap + 1)).Concat(Enumerable.Repeat((byte)0, getEntrySize(c) * cap)).Concat(Enumerable.Repeat((byte)0x50, (is_JP ? PK1.STRLEN_J : PK1.STRLEN_U) * 2 * cap)).ToArray();
int cap = GetCapacity(c);
return new[] { (byte)0 }.Concat(Enumerable.Repeat((byte)0xFF, cap + 1)).Concat(Enumerable.Repeat((byte)0, GetEntrySize(c) * cap)).Concat(Enumerable.Repeat((byte)0x50, (is_JP ? PK1.STRLEN_J : PK1.STRLEN_U) * 2 * cap)).ToArray();
}
public PokemonList1(byte[] d, CapacityType c = CapacityType.Single, bool jp = false)
{
Japanese = jp;
Data = d ?? getEmptyList(c, Japanese);
Capacity = getCapacity(c);
Entry_Size = getEntrySize(c);
Data = d ?? GetEmptyList(c, Japanese);
Capacity = GetCapacity(c);
Entry_Size = GetEntrySize(c);
if (Data.Length != DataSize)
Array.Resize(ref Data, DataSize);
@ -494,7 +494,7 @@ namespace PKHeX.Core
{
get
{
if (i > Capacity || i < 0) throw new IndexOutOfRangeException($"Invalid PokemonList Access: {i}");
if (i > Capacity || i < 0) throw new ArgumentOutOfRangeException($"Invalid PokemonList Access: {i}");
return Pokemon[i];
}
set
@ -512,7 +512,7 @@ namespace PKHeX.Core
Count = Capacity;
for (int i = 0; i < Count; i++)
{
Data[1 + i] = (byte)PKX.setG1Species(Pokemon[i].Species);
Data[1 + i] = (byte)PKX.SetG1Species(Pokemon[i].Species);
Array.Copy(Pokemon[i].Data, 0, Data, 2 + Capacity + Entry_Size * i, Entry_Size);
Array.Copy(Pokemon[i].OT_Name_Raw, 0, Data, 2 + Capacity + Capacity * Entry_Size + StringLength * i, StringLength);
Array.Copy(Pokemon[i].Nickname_Raw, 0, Data, 2 + Capacity + Capacity * Entry_Size + StringLength * Capacity + StringLength * i, StringLength);
@ -527,6 +527,6 @@ namespace PKHeX.Core
}
private int DataSize => Capacity * (Entry_Size + 1 + 2 * StringLength) + 2;
public static int GetDataLength(CapacityType c, bool jp = false) => getCapacity(c) * (getEntrySize(c) + 1 + 2 * (jp ? PK1.STRLEN_J : PK1.STRLEN_U)) + 2;
public static int GetDataLength(CapacityType c, bool jp = false) => GetCapacity(c) * (GetEntrySize(c) + 1 + 2 * (jp ? PK1.STRLEN_J : PK1.STRLEN_U)) + 2;
}
}

View file

@ -20,8 +20,8 @@ namespace PKHeX.Core
internal const int STRLEN_U = 11;
private int StringLength => Japanese ? STRLEN_J : STRLEN_U;
public override string getString(int Offset, int Count) => PKX.getString1(Data, Offset, Count, Japanese);
public override byte[] setString(string value, int maxLength) => PKX.setString1(value, maxLength, Japanese);
public override string GetString(int Offset, int Count) => PKX.GetString1(Data, Offset, Count, Japanese);
public override byte[] SetString(string value, int maxLength) => PKX.SetString1(value, maxLength, Japanese);
// Trash Bytes
public override byte[] Nickname_Trash { get => nick; set { if (value?.Length == nick.Length) nick = value; } }
@ -36,7 +36,7 @@ namespace PKHeX.Core
{
string form = AltForm > 0 ? $"-{AltForm:00}" : "";
string star = IsShiny ? " ★" : "";
return $"{Species:000}{form}{star} - {Nickname} - {SaveUtil.ccitt16(Encrypt()):X4}.{Extension}";
return $"{Species:000}{form}{star} - {Nickname} - {SaveUtil.CRC16_CCITT(Encrypt()):X4}.{Extension}";
}
}
@ -63,10 +63,10 @@ namespace PKHeX.Core
}
public override string Nickname
{
get => PKX.getString1(nick, 0, nick.Length, Japanese);
get => PKX.GetString1(nick, 0, nick.Length, Japanese);
set
{
byte[] strdata = setString(value, StringLength);
byte[] strdata = SetString(value, StringLength);
if (nick.Any(b => b == 0) && nick[StringLength - 1] == 0x50 && Array.FindIndex(nick, b => b == 0) == strdata.Length - 1) // Handle JP Mew event with grace
{
int firstInd = Array.FindIndex(nick, b => b == 0);
@ -81,10 +81,10 @@ namespace PKHeX.Core
public override string OT_Name
{
get => PKX.getString1(otname, 0, otname.Length, Japanese);
get => PKX.GetString1(otname, 0, otname.Length, Japanese);
set
{
byte[] strdata = setString(value, StringLength);
byte[] strdata = SetString(value, StringLength);
if (otname.Any(b => b == 0) && otname[StringLength - 1] == 0x50 && Array.FindIndex(otname, b => b == 0) == strdata.Length - 1) // Handle JP Mew event with grace
{
int firstInd = Array.FindIndex(otname, b => b == 0);
@ -97,7 +97,7 @@ namespace PKHeX.Core
}
}
public override byte[] Encrypt() => new PokemonList2(this).GetBytes();
protected override byte[] Encrypt() => new PokemonList2(this).GetBytes();
public override byte[] EncryptedPartyData => Encrypt().ToArray();
public override byte[] EncryptedBoxData => Encrypt().ToArray();
public override byte[] DecryptedBoxData => Encrypt().ToArray();
@ -107,21 +107,21 @@ namespace PKHeX.Core
{
get
{
string spName = PKX.getSpeciesNameGeneration(Species, Japanese ? 1 : 2, Format);
return !nick.SequenceEqual(setString(spName, StringLength)
string spName = PKX.GetSpeciesNameGeneration(Species, Japanese ? 1 : 2, Format);
return !nick.SequenceEqual(SetString(spName, StringLength)
.Concat(Enumerable.Repeat((byte) 0x50, StringLength - spName.Length - 1))
.Select(b => (byte)(b == 0xF2 ? 0xE8 : b)));
}
set
{
if (!value)
setNotNicknamed();
SetNotNicknamed();
}
}
public void setNotNicknamed()
public void SetNotNicknamed()
{
string spName = PKX.getSpeciesNameGeneration(Species, Japanese ? 1 : 2, Format);
nick = setString(spName, StringLength)
string spName = PKX.GetSpeciesNameGeneration(Species, Japanese ? 1 : 2, Format);
nick = SetString(spName, StringLength)
.Concat(Enumerable.Repeat((byte)0x50, StringLength - spName.Length - 1))
.Select(b => (byte)(b == 0xF2 ? 0xE8 : b)) // Decimal point<->period fix
.ToArray();
@ -133,7 +133,7 @@ namespace PKHeX.Core
get => Data[0];
set => Data[0] = (byte)value;
}
public override int SpriteItem => PKX.getG4Item((byte)HeldItem);
public override int SpriteItem => PKX.GetG4Item((byte)HeldItem);
public override int HeldItem { get => Data[0x1]; set => Data[0x1] = (byte)value; }
public override int Move1 { get => Data[2]; set => Data[2] = (byte)value; }
public override int Move2 { get => Data[3]; set => Data[3] = (byte)value; }
@ -199,8 +199,8 @@ namespace PKHeX.Core
public override int Stat_SPD { get => BigEndian.ToUInt16(Data, 0x2E); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x2E); }
#endregion
public override int getMovePP(int move, int ppup) => Math.Min(61, base.getMovePP(move, ppup));
public override ushort[] getStats(PersonalInfo p)
public override int GetMovePP(int move, int ppup) => Math.Min(61, base.GetMovePP(move, ppup));
public override ushort[] GetStats(PersonalInfo p)
{
ushort[] Stats = new ushort[6];
for (int i = 0; i < Stats.Length; i++)
@ -217,7 +217,7 @@ namespace PKHeX.Core
return Stats;
}
public override bool getGenderIsValid()
public override bool IsGenderValid()
{
int gv = PersonalInfo.Gender;
@ -298,7 +298,7 @@ namespace PKHeX.Core
set{ }
}
private int HPVal => getHiddenPowerBitVal(new[] {IV_SPC, IV_SPE, IV_DEF, IV_ATK});
private int HPVal => GetHiddenPowerBitVal(new[] {IV_SPC, IV_SPE, IV_DEF, IV_ATK});
public override int HPPower => (5 * HPVal + IV_SPC % 4) / 2 + 31;
public override int HPType
{
@ -345,7 +345,7 @@ namespace PKHeX.Core
public override int OTLength => Japanese ? 5 : 7;
public override int NickLength => Japanese ? 5 : 10;
public PK1 convertToPK1()
public PK1 ConvertToPK1()
{
PK1 pk1 = new PK1(null, Identifier, Japanese);
Array.Copy(Data, 0x1, pk1.Data, 0x7, 0x1A);
@ -366,18 +366,18 @@ namespace PKHeX.Core
return pk1;
}
public PK7 convertToPK7()
public PK7 ConvertToPK7()
{
var pk7 = new PK7
{
EncryptionConstant = Util.rnd32(),
EncryptionConstant = Util.Rand32(),
Species = Species,
TID = TID,
CurrentLevel = CurrentLevel,
EXP = EXP,
Met_Level = CurrentLevel,
Nature = (int)(EXP % 25),
PID = Util.rnd32(),
PID = Util.Rand32(),
Ball = 4,
MetDate = DateTime.Now,
Version = (int)GameVersion.S,
@ -395,7 +395,7 @@ namespace PKHeX.Core
Move4_PP = Move4_PP,
Met_Location = 30004,
Gender = PersonalTable.SM[Species].RandomGender,
OT_Name = PKX.getG1ConvertedString(otname, Japanese),
OT_Name = PKX.GetG1ConvertedString(otname, Japanese),
IsNicknamed = false,
Country = PKMConverter.Country,
@ -408,10 +408,10 @@ namespace PKHeX.Core
Geo1_Country = PKMConverter.Country,
Geo1_Region = PKMConverter.Region
};
pk7.Nickname = PKX.getSpeciesNameGeneration(pk7.Species, pk7.Language, pk7.Format);
pk7.Nickname = PKX.GetSpeciesNameGeneration(pk7.Species, pk7.Language, pk7.Format);
if (otname[0] == 0x5D) // Ingame Trade
{
var s = PKX.getG1Char(0x5D, Japanese);
var s = PKX.GetG1Char(0x5D, Japanese);
pk7.OT_Name = s.Substring(0, 1) + s.Substring(1).ToLower();
}
pk7.OT_Friendship = pk7.HT_Friendship = PersonalTable.SM[Species].BaseFriendship;
@ -420,14 +420,14 @@ namespace PKHeX.Core
var special = Species == 151 || Species == 251;
var new_ivs = new int[6];
int flawless = special ? 5 : 3;
for (var i = 0; i < new_ivs.Length; i++) new_ivs[i] = (int)(Util.rnd32() & 31);
for (var i = 0; i < new_ivs.Length; i++) new_ivs[i] = (int)(Util.Rand32() & 31);
for (var i = 0; i < flawless; i++) new_ivs[i] = 31;
Util.Shuffle(new_ivs);
pk7.IVs = new_ivs;
// Really? :(
if (IsShiny)
pk7.setShinyPID();
pk7.SetShinyPID();
int abil = 2; // Hidden
if (Legal.TransferSpeciesDefaultAbility_2.Contains(Species))
@ -439,7 +439,7 @@ namespace PKHeX.Core
else if (IsNicknamed)
{
pk7.IsNicknamed = true;
pk7.Nickname = PKX.getG1ConvertedString(nick, Japanese);
pk7.Nickname = PKX.GetG1ConvertedString(nick, Japanese);
}
pk7.TradeMemory(Bank: true); // oh no, memories on gen7 pkm
@ -469,24 +469,24 @@ namespace PKHeX.Core
Single
}
private static int getEntrySize(CapacityType c) => c == CapacityType.Single || c == CapacityType.Party
private static int GetEntrySize(CapacityType c) => c == CapacityType.Single || c == CapacityType.Party
? PKX.SIZE_2PARTY
: PKX.SIZE_2STORED;
private static byte getCapacity(CapacityType c) => c == CapacityType.Single ? (byte)1 : (byte)c;
private static byte GetCapacity(CapacityType c) => c == CapacityType.Single ? (byte)1 : (byte)c;
private byte[] getEmptyList(CapacityType c, bool is_JP = false)
private static byte[] GetEmptyList(CapacityType c, bool is_JP = false)
{
int cap = getCapacity(c);
return new[] { (byte)0 }.Concat(Enumerable.Repeat((byte)0xFF, cap + 1)).Concat(Enumerable.Repeat((byte)0, getEntrySize(c) * cap)).Concat(Enumerable.Repeat((byte)0x50, (is_JP ? PK2.STRLEN_J : PK2.STRLEN_U) * 2 * cap)).ToArray();
int cap = GetCapacity(c);
return new[] { (byte)0 }.Concat(Enumerable.Repeat((byte)0xFF, cap + 1)).Concat(Enumerable.Repeat((byte)0, GetEntrySize(c) * cap)).Concat(Enumerable.Repeat((byte)0x50, (is_JP ? PK2.STRLEN_J : PK2.STRLEN_U) * 2 * cap)).ToArray();
}
public PokemonList2(byte[] d, CapacityType c = CapacityType.Single, bool jp = false)
{
Japanese = jp;
Data = d ?? getEmptyList(c, Japanese);
Capacity = getCapacity(c);
Entry_Size = getEntrySize(c);
Data = d ?? GetEmptyList(c, Japanese);
Capacity = GetCapacity(c);
Entry_Size = GetEntrySize(c);
if (Data.Length != DataSize)
{
@ -534,7 +534,7 @@ namespace PKHeX.Core
{
get
{
if (i > Capacity || i < 0) throw new IndexOutOfRangeException($"Invalid PokemonList Access: {i}");
if (i > Capacity || i < 0) throw new ArgumentOutOfRangeException($"Invalid PokemonList Access: {i}");
return Pokemon[i];
}
set
@ -567,6 +567,6 @@ namespace PKHeX.Core
}
private int DataSize => Capacity * (Entry_Size + 1 + 2 * StringLength) + 2;
public static int GetDataLength(CapacityType c, bool jp = false) => getCapacity(c) * (getEntrySize(c) + 1 + 2 * (jp ? PK2.STRLEN_J : PK2.STRLEN_U)) + 2;
public static int GetDataLength(CapacityType c, bool jp = false) => GetCapacity(c) * (GetEntrySize(c) + 1 + 2 * (jp ? PK2.STRLEN_J : PK2.STRLEN_U)) + 2;
}
}

View file

@ -17,27 +17,27 @@ namespace PKHeX.Core
public PK3(byte[] decryptedData = null, string ident = null)
{
Data = (byte[])(decryptedData ?? new byte[SIZE_PARTY]).Clone();
PKMConverter.checkEncrypted(ref Data);
PKMConverter.CheckEncrypted(ref Data);
Identifier = ident;
if (Data.Length != SIZE_PARTY)
Array.Resize(ref Data, SIZE_PARTY);
}
public override PKM Clone() { return new PK3(Data); }
public override string getString(int Offset, int Count) => PKX.getString3(Data, Offset, Count, Japanese);
public override byte[] setString(string value, int maxLength) => PKX.setString3(value, maxLength, Japanese);
public override string GetString(int Offset, int Count) => PKX.GetString3(Data, Offset, Count, Japanese);
public override byte[] SetString(string value, int maxLength) => PKX.SetString3(value, maxLength, Japanese);
// Trash Bytes
public override byte[] Nickname_Trash { get => getData(0x08, 10); set { if (value?.Length == 10) value.CopyTo(Data, 0x08); } }
public override byte[] OT_Trash { get => getData(0x14, 7); set { if (value?.Length == 7) value.CopyTo(Data, 0x14); } }
public override byte[] Nickname_Trash { get => GetData(0x08, 10); set { if (value?.Length == 10) value.CopyTo(Data, 0x08); } }
public override byte[] OT_Trash { get => GetData(0x14, 7); set { if (value?.Length == 7) value.CopyTo(Data, 0x14); } }
// Future Attributes
public override uint EncryptionConstant { get => PID; set { } }
public override int Nature { get => (int)(PID % 25); set { } }
public override int AltForm { get => Species == 201 ? PKX.getUnownForm(PID) : 0; set { } }
public override int AltForm { get => Species == 201 ? PKX.GetUnownForm(PID) : 0; set { } }
public override bool IsNicknamed { get => PKX.getIsNicknamedAnyLanguage(Species, Nickname, Format); set { } }
public override int Gender { get => PKX.getGender(Species, PID); set { } }
public override bool IsNicknamed { get => PKX.IsNicknamedAnyLanguage(Species, Nickname, Format); set { } }
public override int Gender { get => PKX.GetGender(Species, PID); set { } }
public override int Characteristic => -1;
public override int CurrentFriendship { get => OT_Friendship; set => OT_Friendship = value; }
public override int Ability { get { int[] abils = PersonalInfo.Abilities; return abils[AbilityBit && abils[1] != 0 ? 1 : 0]; } set { } }
@ -48,16 +48,16 @@ namespace PKHeX.Core
public override uint PID { get => BitConverter.ToUInt32(Data, 0x00); set => BitConverter.GetBytes(value).CopyTo(Data, 0x00); }
public override int TID { get => BitConverter.ToUInt16(Data, 0x04); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x04); }
public override int SID { get => BitConverter.ToUInt16(Data, 0x06); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x06); }
public override string Nickname { get => getString(0x08, 10); set => setString(IsEgg ? "タマゴ" : value, 10).CopyTo(Data, 0x08); }
public override string Nickname { get => GetString(0x08, 10); set => SetString(IsEgg ? "タマゴ" : value, 10).CopyTo(Data, 0x08); }
public override int Language { get => BitConverter.ToUInt16(Data, 0x12) & 0xFF; set => BitConverter.GetBytes((ushort)(IsEgg ? 0x601 : value | 0x200)).CopyTo(Data, 0x12); }
public override string OT_Name { get => getString(0x14, 7); set => setString(value, 7).CopyTo(Data, 0x14); }
public override string OT_Name { get => GetString(0x14, 7); set => SetString(value, 7).CopyTo(Data, 0x14); }
public override int MarkValue { get => Data[0x1B]; protected set => Data[0x1B] = (byte)value; }
public override ushort Checksum { get => BitConverter.ToUInt16(Data, 0x1C); set => BitConverter.GetBytes(value).CopyTo(Data, 0x1C); }
public override ushort Sanity { get => BitConverter.ToUInt16(Data, 0x1E); set => BitConverter.GetBytes(value).CopyTo(Data, 0x1E); }
#region Block A
public override int Species { get => PKX.getG4Species(BitConverter.ToUInt16(Data, 0x20)); set => BitConverter.GetBytes((ushort)PKX.getG3Species(value)).CopyTo(Data, 0x20); }
public override int SpriteItem => PKX.getG4Item((ushort)HeldItem);
public override int Species { get => PKX.GetG4Species(BitConverter.ToUInt16(Data, 0x20)); set => BitConverter.GetBytes((ushort)PKX.GetG3Species(value)).CopyTo(Data, 0x20); }
public override int SpriteItem => PKX.GetG4Item((ushort)HeldItem);
public override int HeldItem { get => BitConverter.ToUInt16(Data, 0x22); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x22); }
public override uint EXP { get => BitConverter.ToUInt32(Data, 0x24); set => BitConverter.GetBytes(value).CopyTo(Data, 0x24); }
@ -175,12 +175,12 @@ namespace PKHeX.Core
public override int OTLength => 7;
public override int NickLength => 10;
public override byte[] Encrypt()
protected override byte[] Encrypt()
{
RefreshChecksum();
return PKX.encryptArray3(Data);
return PKX.EncryptArray3(Data);
}
public PK4 convertToPK4()
public PK4 ConvertToPK4()
{
DateTime moment = DateTime.Now;
PK4 pk4 = new PK4 // Convert away!
@ -189,7 +189,7 @@ namespace PKHeX.Core
Species = Species,
TID = TID,
SID = SID,
EXP = IsEgg ? PKX.getEXP(5, Species) : EXP,
EXP = IsEgg ? PKX.GetEXP(5, Species) : EXP,
IsEgg = false,
OT_Friendship = 70,
Markings = Markings,
@ -244,10 +244,10 @@ namespace PKHeX.Core
};
// Fix PP
pk4.Move1_PP = pk4.getMovePP(pk4.Move1, pk4.Move1_PPUps);
pk4.Move2_PP = pk4.getMovePP(pk4.Move2, pk4.Move2_PPUps);
pk4.Move3_PP = pk4.getMovePP(pk4.Move3, pk4.Move3_PPUps);
pk4.Move4_PP = pk4.getMovePP(pk4.Move4, pk4.Move4_PPUps);
pk4.Move1_PP = pk4.GetMovePP(pk4.Move1, pk4.Move1_PPUps);
pk4.Move2_PP = pk4.GetMovePP(pk4.Move2, pk4.Move2_PPUps);
pk4.Move3_PP = pk4.GetMovePP(pk4.Move3, pk4.Move3_PPUps);
pk4.Move4_PP = pk4.GetMovePP(pk4.Move4, pk4.Move4_PPUps);
pk4.FatefulEncounter = FatefulEncounter; // obedience flag
@ -275,13 +275,13 @@ namespace PKHeX.Core
// Yay for reusing string buffers!
PKX.G4TransferTrashBytes[pk4.Language].CopyTo(pk4.Data, 0x48 + 4);
pk4.Nickname = IsEgg ? PKX.getSpeciesName(pk4.Species, pk4.Language) : Nickname;
pk4.Nickname = IsEgg ? PKX.GetSpeciesName(pk4.Species, pk4.Language) : Nickname;
Array.Copy(pk4.Data, 0x48, pk4.Data, 0x68, 0x10);
pk4.OT_Name = OT_Name;
// Set Final Data
pk4.Met_Level = PKX.getLevel(pk4.Species, pk4.EXP);
pk4.Gender = PKX.getGender(pk4.Species, pk4.PID);
pk4.Met_Level = PKX.GetLevel(pk4.Species, pk4.EXP);
pk4.Gender = PKX.GetGender(pk4.Species, pk4.PID);
pk4.IsNicknamed = IsNicknamed;
// Unown Form
@ -289,8 +289,8 @@ namespace PKHeX.Core
if (HeldItem > 0)
{
ushort item = PKX.getG4Item((ushort)HeldItem);
if (PKX.isTransferrable34(item))
ushort item = PKX.GetG4Item((ushort)HeldItem);
if (PKX.IsItemTransferrable34(item))
pk4.HeldItem = item;
}

View file

@ -12,24 +12,24 @@ namespace PKHeX.Core
public sealed override int SIZE_PARTY => PKX.SIZE_4PARTY;
public override int SIZE_STORED => PKX.SIZE_4STORED;
public override int Format => 4;
public override PersonalInfo PersonalInfo => PersonalTable.HGSS.getFormeEntry(Species, AltForm);
public override PersonalInfo PersonalInfo => PersonalTable.HGSS.GetFormeEntry(Species, AltForm);
public PK4(byte[] decryptedData = null, string ident = null)
{
Data = (byte[])(decryptedData ?? new byte[SIZE_PARTY]).Clone();
PKMConverter.checkEncrypted(ref Data);
PKMConverter.CheckEncrypted(ref Data);
Identifier = ident;
if (Data.Length != SIZE_PARTY)
Array.Resize(ref Data, SIZE_PARTY);
}
public override PKM Clone() { return new PK4(Data); }
public override string getString(int Offset, int Count) => PKX.getString4(Data, Offset, Count);
public override byte[] setString(string value, int maxLength) => PKX.setString4(value, maxLength);
public override string GetString(int Offset, int Count) => PKX.GetString4(Data, Offset, Count);
public override byte[] SetString(string value, int maxLength) => PKX.SetString4(value, maxLength);
// Trash Bytes
public override byte[] Nickname_Trash { get => getData(0x48, 22); set { if (value?.Length == 22) value.CopyTo(Data, 0x48); } }
public override byte[] OT_Trash { get => getData(0x68, 16); set { if (value?.Length == 16) value.CopyTo(Data, 0x68); } }
public override byte[] Nickname_Trash { get => GetData(0x48, 22); set { if (value?.Length == 22) value.CopyTo(Data, 0x48); } }
public override byte[] OT_Trash { get => GetData(0x68, 16); set { if (value?.Length == 16) value.CopyTo(Data, 0x68); } }
// Future Attributes
public override uint EncryptionConstant { get => PID; set { } }
@ -171,7 +171,7 @@ namespace PKHeX.Core
#endregion
#region Block C
public override string Nickname { get => getString(0x48, 22); set => setString(value, 11).CopyTo(Data, 0x48); }
public override string Nickname { get => GetString(0x48, 22); set => SetString(value, 11).CopyTo(Data, 0x48); }
// 0x5E unused
public override int Version { get => Data[0x5F]; set => Data[0x5F] = (byte)value; }
private byte RIB8 { get => Data[0x60]; set => Data[0x60] = value; } // Sinnoh 3
@ -214,7 +214,7 @@ namespace PKHeX.Core
#endregion
#region Block D
public override string OT_Name { get => getString(0x68, 16); set => setString(value, 7).CopyTo(Data, 0x68); }
public override string OT_Name { get => GetString(0x68, 16); set => SetString(value, 7).CopyTo(Data, 0x68); }
public override int Egg_Year { get => Data[0x78]; set => Data[0x78] = (byte)value; }
public override int Egg_Month { get => Data[0x79]; set => Data[0x79] = (byte)value; }
public override int Egg_Day { get => Data[0x7A]; set => Data[0x7A] = (byte)value; }
@ -361,13 +361,13 @@ namespace PKHeX.Core
public override int NickLength => 10;
// Methods
public override byte[] Encrypt()
protected override byte[] Encrypt()
{
RefreshChecksum();
return PKX.encryptArray45(Data);
return PKX.EncryptArray45(Data);
}
public BK4 convertToBK4()
public BK4 ConvertToBK4()
{
BK4 bk4 = new BK4();
TransferPropertiesWithReflection(this, bk4);
@ -389,7 +389,7 @@ namespace PKHeX.Core
return bk4;
}
public PK5 convertToPK5()
public PK5 ConvertToPK5()
{
// Double Check Location Data to see if we're already a PK5
if (Data[0x5F] < 0x10 && BitConverter.ToUInt16(Data, 0x80) > 0x4000)
@ -416,10 +416,10 @@ namespace PKHeX.Core
}
// Fix PP
pk5.Move1_PP = pk5.getMovePP(pk5.Move1, pk5.Move1_PPUps);
pk5.Move2_PP = pk5.getMovePP(pk5.Move2, pk5.Move2_PPUps);
pk5.Move3_PP = pk5.getMovePP(pk5.Move3, pk5.Move3_PPUps);
pk5.Move4_PP = pk5.getMovePP(pk5.Move4, pk5.Move4_PPUps);
pk5.Move1_PP = pk5.GetMovePP(pk5.Move1, pk5.Move1_PPUps);
pk5.Move2_PP = pk5.GetMovePP(pk5.Move2, pk5.Move2_PPUps);
pk5.Move3_PP = pk5.GetMovePP(pk5.Move3, pk5.Move3_PPUps);
pk5.Move4_PP = pk5.GetMovePP(pk5.Move4, pk5.Move4_PPUps);
// Disassociate Nature and PID, pk4 getter does PID%25
pk5.Nature = Nature;
@ -441,7 +441,7 @@ namespace PKHeX.Core
pk5.OT_Name = OT_Name;
// Fix Level
pk5.Met_Level = PKX.getLevel(pk5.Species, pk5.EXP);
pk5.Met_Level = PKX.GetLevel(pk5.Species, pk5.EXP);
// Remove HM moves; Defog should be kept if both are learned.
int[] banned = Moves.Contains(250) && Moves.Contains(432) // Whirlpool & Defog

View file

@ -12,24 +12,24 @@ namespace PKHeX.Core
public sealed override int SIZE_PARTY => PKX.SIZE_5PARTY;
public override int SIZE_STORED => PKX.SIZE_5STORED;
public override int Format => 5;
public override PersonalInfo PersonalInfo => PersonalTable.B2W2.getFormeEntry(Species, AltForm);
public override PersonalInfo PersonalInfo => PersonalTable.B2W2.GetFormeEntry(Species, AltForm);
public PK5(byte[] decryptedData = null, string ident = null)
{
Data = (byte[])(decryptedData ?? new byte[SIZE_PARTY]).Clone();
PKMConverter.checkEncrypted(ref Data);
PKMConverter.CheckEncrypted(ref Data);
Identifier = ident;
if (Data.Length != SIZE_PARTY)
Array.Resize(ref Data, SIZE_PARTY);
}
public override PKM Clone() { return new PK5(Data); }
public override string getString(int Offset, int Count) => PKX.getString5(Data, Offset, Count);
public override byte[] setString(string value, int maxLength) => PKX.setString5(value, maxLength);
public override string GetString(int Offset, int Count) => PKX.GetString5(Data, Offset, Count);
public override byte[] SetString(string value, int maxLength) => PKX.SetString5(value, maxLength);
// Trash Bytes
public override byte[] Nickname_Trash { get => getData(0x48, 22); set { if (value?.Length == 22) value.CopyTo(Data, 0x48); } }
public override byte[] OT_Trash { get => getData(0x68, 16); set { if (value?.Length == 16) value.CopyTo(Data, 0x68); } }
public override byte[] Nickname_Trash { get => GetData(0x48, 22); set { if (value?.Length == 22) value.CopyTo(Data, 0x48); } }
public override byte[] OT_Trash { get => GetData(0x68, 16); set { if (value?.Length == 16) value.CopyTo(Data, 0x68); } }
// Future Attributes
public override uint EncryptionConstant { get => PID; set { } }
@ -173,7 +173,7 @@ namespace PKHeX.Core
#endregion
#region Block C
public override string Nickname { get => getString(0x48, 22); set => setString(value, 11).CopyTo(Data, 0x48); }
public override string Nickname { get => GetString(0x48, 22); set => SetString(value, 11).CopyTo(Data, 0x48); }
// 0x5E unused
public override int Version { get => Data[0x5F]; set => Data[0x5F] = (byte)value; }
private byte RIB8 { get => Data[0x60]; set => Data[0x60] = value; } // Sinnoh 3
@ -216,7 +216,7 @@ namespace PKHeX.Core
#endregion
#region Block D
public override string OT_Name { get => getString(0x68, 0x16); set => setString(value, 7).CopyTo(Data, 0x68); }
public override string OT_Name { get => GetString(0x68, 0x16); set => SetString(value, 7).CopyTo(Data, 0x68); }
public override int Egg_Year { get => Data[0x78]; set => Data[0x78] = (byte)value; }
public override int Egg_Month { get => Data[0x79]; set => Data[0x79] = (byte)value; }
public override int Egg_Day { get => Data[0x7A]; set => Data[0x7A] = (byte)value; }
@ -282,13 +282,13 @@ namespace PKHeX.Core
public override int NickLength => 10;
// Methods
public override byte[] Encrypt()
protected override byte[] Encrypt()
{
RefreshChecksum();
return PKX.encryptArray45(Data);
return PKX.EncryptArray45(Data);
}
public PK6 convertToPK6()
public PK6 ConvertToPK6()
{
PK6 pk6 = new PK6 // Convert away!
{
@ -341,10 +341,10 @@ namespace PKHeX.Core
pk6.Move4_PPUps = Move4_PPUps;
// Fix PP
pk6.Move1_PP = pk6.getMovePP(pk6.Move1, pk6.Move1_PPUps);
pk6.Move2_PP = pk6.getMovePP(pk6.Move2, pk6.Move2_PPUps);
pk6.Move3_PP = pk6.getMovePP(pk6.Move3, pk6.Move3_PPUps);
pk6.Move4_PP = pk6.getMovePP(pk6.Move4, pk6.Move4_PPUps);
pk6.Move1_PP = pk6.GetMovePP(pk6.Move1, pk6.Move1_PPUps);
pk6.Move2_PP = pk6.GetMovePP(pk6.Move2, pk6.Move2_PPUps);
pk6.Move3_PP = pk6.GetMovePP(pk6.Move3, pk6.Move3_PPUps);
pk6.Move4_PP = pk6.GetMovePP(pk6.Move4, pk6.Move4_PPUps);
pk6.IV_HP = IV_HP;
pk6.IV_ATK = IV_ATK;
@ -361,8 +361,8 @@ namespace PKHeX.Core
pk6.Nature = Nature;
// Apply trash bytes for species name of current app language -- default to PKM's language if no match
int curLang = PKX.getSpeciesNameLanguage(Species, Nickname, Format);
pk6.Nickname = PKX.getSpeciesName(Species, curLang < 0 ? Language : curLang);
int curLang = PKX.GetSpeciesNameLanguage(Species, Nickname, Format);
pk6.Nickname = PKX.GetSpeciesName(Species, curLang < 0 ? Language : curLang);
if (IsNicknamed)
pk6.Nickname = Nickname;
@ -483,7 +483,7 @@ namespace PKHeX.Core
pk6.Geo1_Country = PKMConverter.Country;
pk6.HT_Intensity = 1;
pk6.HT_Memory = 4;
pk6.HT_Feeling = (int)(Util.rnd32() % 10);
pk6.HT_Feeling = (int)(Util.Rand32() % 10);
// When transferred, friendship gets reset.
pk6.OT_Friendship = pk6.HT_Friendship = PersonalInfo.BaseFriendship;

View file

@ -13,25 +13,25 @@ namespace PKHeX.Core
public sealed override int SIZE_PARTY => PKX.SIZE_6PARTY;
public override int SIZE_STORED => PKX.SIZE_6STORED;
public override int Format => 6;
public override PersonalInfo PersonalInfo => PersonalTable.AO.getFormeEntry(Species, AltForm);
public override PersonalInfo PersonalInfo => PersonalTable.AO.GetFormeEntry(Species, AltForm);
public PK6(byte[] decryptedData = null, string ident = null)
{
Data = (byte[])(decryptedData ?? new byte[SIZE_PARTY]).Clone();
PKMConverter.checkEncrypted(ref Data);
PKMConverter.CheckEncrypted(ref Data);
Identifier = ident;
if (Data.Length != SIZE_PARTY)
Array.Resize(ref Data, SIZE_PARTY);
}
public override PKM Clone() { return new PK6(Data); }
public override string getString(int Offset, int Count) => PKX.getString6(Data, Offset, Count);
public override byte[] setString(string value, int maxLength) => PKX.setString6(value, maxLength);
public override string GetString(int Offset, int Count) => PKX.GetString6(Data, Offset, Count);
public override byte[] SetString(string value, int maxLength) => PKX.SetString6(value, maxLength);
// Trash Bytes
public override byte[] Nickname_Trash { get => getData(0x40, 24); set { if (value?.Length == 24) value.CopyTo(Data, 0x40); } }
public override byte[] HT_Trash { get => getData(0x78, 24); set { if (value?.Length == 24) value.CopyTo(Data, 0x78); } }
public override byte[] OT_Trash { get => getData(0xB0, 24); set { if (value?.Length == 24) value.CopyTo(Data, 0xB0); } }
public override byte[] Nickname_Trash { get => GetData(0x40, 24); set { if (value?.Length == 24) value.CopyTo(Data, 0x40); } }
public override byte[] HT_Trash { get => GetData(0x78, 24); set { if (value?.Length == 24) value.CopyTo(Data, 0x78); } }
public override byte[] OT_Trash { get => GetData(0xB0, 24); set { if (value?.Length == 24) value.CopyTo(Data, 0xB0); } }
// Structure
#region Block A
@ -210,7 +210,7 @@ namespace PKHeX.Core
public uint FormDuration { get => BitConverter.ToUInt32(Data, 0x3C); set => BitConverter.GetBytes(value).CopyTo(Data, 0x3C); }
#endregion
#region Block B
public override string Nickname { get => getString(0x40, 24); set => setString(value, 12).CopyTo(Data, 0x40); }
public override string Nickname { get => GetString(0x40, 24); set => SetString(value, 12).CopyTo(Data, 0x40); }
public override int Move1
{
get => BitConverter.ToUInt16(Data, 0x5A);
@ -273,7 +273,7 @@ namespace PKHeX.Core
public override bool IsNicknamed { get => ((IV32 >> 31) & 1) == 1; set => IV32 = (IV32 & 0x7FFFFFFF) | (value ? 0x80000000 : 0); }
#endregion
#region Block C
public override string HT_Name { get => getString(0x78, 24); set => setString(value, 12).CopyTo(Data, 0x78); }
public override string HT_Name { get => GetString(0x78, 24); set => SetString(value, 12).CopyTo(Data, 0x78); }
public override int HT_Gender { get => Data[0x92]; set => Data[0x92] = (byte)value; }
public override int CurrentHandler { get => Data[0x93]; set => Data[0x93] = (byte)value; }
public override int Geo1_Region { get => Data[0x94]; set => Data[0x94] = (byte)value; }
@ -305,7 +305,7 @@ namespace PKHeX.Core
public override byte Enjoyment { get => Data[0xAF]; set => Data[0xAF] = value; }
#endregion
#region Block D
public override string OT_Name { get => getString(0xB0, 24); set => setString(value, 12).CopyTo(Data, 0xB0); }
public override string OT_Name { get => GetString(0xB0, 24); set => SetString(value, 12).CopyTo(Data, 0xB0); }
public override int OT_Friendship { get => Data[0xCA]; set => Data[0xCA] = (byte)value; }
public override int OT_Affection { get => Data[0xCB]; set => Data[0xCB] = (byte)value; }
public override int OT_Intensity { get => Data[0xCC]; set => Data[0xCC] = (byte)value; }
@ -377,10 +377,10 @@ namespace PKHeX.Core
}
// Methods
public override byte[] Encrypt()
protected override byte[] Encrypt()
{
RefreshChecksum();
return PKX.encryptArray(Data);
return PKX.EncryptArray(Data);
}
// General User-error Fixes
@ -550,7 +550,7 @@ namespace PKHeX.Core
HT_Memory = 4; // Link trade to [VAR: General Location]
HT_TextVar = Bank ? 0 : 9; // Somewhere (Bank) : Pokécenter (Trade)
HT_Intensity = 1;
HT_Feeling = Util.rand.Next(0, Bank ? 9 : 19); // 0-9 Bank, 0-19 Trade
HT_Feeling = Util.Rand.Next(0, Bank ? 9 : 19); // 0-9 Bank, 0-19 Trade
}
// Legality Properties
@ -573,7 +573,7 @@ namespace PKHeX.Core
public override int OTLength => 12;
public override int NickLength => 12;
public PK7 convertToPK7()
public PK7 ConvertToPK7()
{
PK7 pk7 = new PK7(Data)
{

View file

@ -14,25 +14,25 @@ namespace PKHeX.Core
public sealed override int SIZE_PARTY => PKX.SIZE_6PARTY;
public override int SIZE_STORED => PKX.SIZE_6STORED;
public override int Format => 7;
public override PersonalInfo PersonalInfo => PersonalTable.SM.getFormeEntry(Species, AltForm);
public override PersonalInfo PersonalInfo => PersonalTable.SM.GetFormeEntry(Species, AltForm);
public PK7(byte[] decryptedData = null, string ident = null)
{
Data = (byte[])(decryptedData ?? new byte[SIZE_PARTY]).Clone();
PKMConverter.checkEncrypted(ref Data);
PKMConverter.CheckEncrypted(ref Data);
Identifier = ident;
if (Data.Length != SIZE_PARTY)
Array.Resize(ref Data, SIZE_PARTY);
}
public override PKM Clone() { return new PK7(Data); }
public override string getString(int Offset, int Count) => PKX.getString7(Data, Offset, Count);
public override byte[] setString(string value, int maxLength) => PKX.setString7(value, maxLength, Language);
public override string GetString(int Offset, int Count) => PKX.GetString7(Data, Offset, Count);
public override byte[] SetString(string value, int maxLength) => PKX.SetString7(value, maxLength, Language);
// Trash Bytes
public override byte[] Nickname_Trash { get => getData(0x40, 24); set { if (value?.Length == 24) value.CopyTo(Data, 0x40); } }
public override byte[] HT_Trash { get => getData(0x78, 24); set { if (value?.Length == 24) value.CopyTo(Data, 0x78); } }
public override byte[] OT_Trash { get => getData(0xB0, 24); set { if (value?.Length == 24) value.CopyTo(Data, 0xB0); } }
public override byte[] Nickname_Trash { get => GetData(0x40, 24); set { if (value?.Length == 24) value.CopyTo(Data, 0x40); } }
public override byte[] HT_Trash { get => GetData(0x78, 24); set { if (value?.Length == 24) value.CopyTo(Data, 0x78); } }
public override byte[] OT_Trash { get => GetData(0xB0, 24); set { if (value?.Length == 24) value.CopyTo(Data, 0xB0); } }
// Structure
#region Block A
@ -218,7 +218,7 @@ namespace PKHeX.Core
public uint FormDuration { get => BitConverter.ToUInt32(Data, 0x3C); set => BitConverter.GetBytes(value).CopyTo(Data, 0x3C); }
#endregion
#region Block B
public override string Nickname { get => getString(0x40, 24); set => setString(value, 12).CopyTo(Data, 0x40); }
public override string Nickname { get => GetString(0x40, 24); set => SetString(value, 12).CopyTo(Data, 0x40); }
public override int Move1
{
get => BitConverter.ToUInt16(Data, 0x5A);
@ -281,7 +281,7 @@ namespace PKHeX.Core
public override bool IsNicknamed { get => ((IV32 >> 31) & 1) == 1; set => IV32 = (IV32 & 0x7FFFFFFF) | (value ? 0x80000000 : 0); }
#endregion
#region Block C
public override string HT_Name { get => getString(0x78, 24); set => setString(value, 12).CopyTo(Data, 0x78); }
public override string HT_Name { get => GetString(0x78, 24); set => SetString(value, 12).CopyTo(Data, 0x78); }
public override int HT_Gender { get => Data[0x92]; set => Data[0x92] = (byte)value; }
public override int CurrentHandler { get => Data[0x93]; set => Data[0x93] = (byte)value; }
public override int Geo1_Region { get => Data[0x94]; set => Data[0x94] = (byte)value; }
@ -313,7 +313,7 @@ namespace PKHeX.Core
public override byte Enjoyment { get => Data[0xAF]; set => Data[0xAF] = value; }
#endregion
#region Block D
public override string OT_Name { get => getString(0xB0, 24); set => setString(value, 12).CopyTo(Data, 0xB0); }
public override string OT_Name { get => GetString(0xB0, 24); set => SetString(value, 12).CopyTo(Data, 0xB0); }
public override int OT_Friendship { get => Data[0xCA]; set => Data[0xCA] = (byte)value; }
public override int OT_Affection { get => Data[0xCB]; set => Data[0xCB] = (byte)value; }
public override int OT_Intensity { get => Data[0xCC]; set => Data[0xCC] = (byte)value; }
@ -411,10 +411,10 @@ namespace PKHeX.Core
}
// Methods
public override byte[] Encrypt()
protected override byte[] Encrypt()
{
RefreshChecksum();
return PKX.encryptArray(Data);
return PKX.EncryptArray(Data);
}
// General User-error Fixes
@ -585,7 +585,7 @@ namespace PKHeX.Core
HT_Memory = 4; // Link trade to [VAR: General Location]
HT_TextVar = 0; // Somewhere (Bank)
HT_Intensity = 1;
HT_Feeling = Util.rand.Next(0, 9); // 0-9 Bank
HT_Feeling = Util.Rand.Next(0, 9); // 0-9 Bank
}
// Legality Properties

View file

@ -5,7 +5,7 @@ namespace PKHeX.Core
{
public abstract class PKM
{
public static readonly string[] Extensions = PKX.getPKMExtensions();
public static readonly string[] Extensions = PKX.GetPKMExtensions();
public abstract int SIZE_PARTY { get; }
public abstract int SIZE_STORED { get; }
public string Extension => GetType().Name.ToLower();
@ -23,14 +23,14 @@ namespace PKHeX.Core
public virtual byte[] DecryptedBoxData => Write().Take(SIZE_STORED).ToArray();
public virtual bool Valid { get => ChecksumValid && Sanity == 0; set { if (!value) return; Sanity = 0; RefreshChecksum(); } }
public abstract string getString(int Offset, int Length);
public abstract byte[] setString(string value, int maxLength);
public abstract string GetString(int Offset, int Length);
public abstract byte[] SetString(string value, int maxLength);
// Trash Bytes
public abstract byte[] Nickname_Trash { get; set; }
public abstract byte[] OT_Trash { get; set; }
public virtual byte[] HT_Trash { get; set; }
public byte[] getData(int Offset, int Length)
protected byte[] GetData(int Offset, int Length)
{
if (Offset + Length > Data.Length)
return null;
@ -55,9 +55,9 @@ namespace PKHeX.Core
return chk;
}
}
public abstract byte[] Encrypt();
protected abstract byte[] Encrypt();
public abstract int Format { get; }
public byte[] Write()
private byte[] Write()
{
RefreshChecksum();
return Data;
@ -325,15 +325,15 @@ namespace PKHeX.Core
public bool PKRS_Infected => PKRS_Strain > 0;
public bool PKRS_Cured => PKRS_Days == 0 && PKRS_Strain > 0;
public virtual bool ChecksumValid => Checksum == CalculateChecksum();
public int CurrentLevel { get => PKX.getLevel(Species, EXP); set => EXP = PKX.getEXP(value, Species); }
public int CurrentLevel { get => PKX.GetLevel(Species, EXP); set => EXP = PKX.GetEXP(value, Species); }
public int MarkCircle { get => Markings[0]; set { var marks = Markings; marks[0] = value; Markings = marks; } }
public int MarkTriangle { get => Markings[1]; set { var marks = Markings; marks[1] = value; Markings = marks; } }
public int MarkSquare { get => Markings[2]; set { var marks = Markings; marks[2] = value; Markings = marks; } }
public int MarkHeart { get => Markings[3]; set { var marks = Markings; marks[3] = value; Markings = marks; } }
public int MarkStar { get => Markings[4]; set { var marks = Markings; marks[4] = value; Markings = marks; } }
public int MarkDiamond { get => Markings[5]; set { var marks = Markings; marks[5] = value; Markings = marks; } }
public string ShowdownText => ShowdownSet.getShowdownText(this);
public string[] QRText => this.getQRText();
public string ShowdownText => ShowdownSet.GetShowdownText(this);
public string[] QRText => this.GetQRLines();
public virtual string FileName
{
@ -419,14 +419,14 @@ namespace PKHeX.Core
set { if (value?.Length != 6) return; CNT_Cool = value[0]; CNT_Beauty = value[1]; CNT_Cute = value[2]; CNT_Smart = value[3]; CNT_Tough = value[4]; CNT_Sheen = value[5]; }
}
protected static int getHiddenPowerBitVal(int[] ivs)
protected static int GetHiddenPowerBitVal(int[] ivs)
{
int sum = 0;
for (int i = 0; i < ivs.Length; i++)
sum |= (ivs[i] & 1) << i;
return sum;
}
private int HPVal => getHiddenPowerBitVal(new[] {IV_HP, IV_ATK, IV_DEF, IV_SPE, IV_SPA, IV_SPD});
private int HPVal => GetHiddenPowerBitVal(new[] {IV_HP, IV_ATK, IV_DEF, IV_SPE, IV_SPA, IV_SPD});
public virtual int HPPower => Format < 6 ? 40*HPVal/63 + 30 : 60;
public virtual int HPType
{
@ -484,7 +484,7 @@ namespace PKHeX.Core
public virtual bool WasIngameTrade => Met_Location == 30001 || GenNumber == 4 && Egg_Location == 2001;
public virtual bool IsUntraded => Format >= 6 && string.IsNullOrWhiteSpace(HT_Name) && GenNumber == Format;
public virtual bool IsNative => GenNumber == Format;
public virtual bool IsOriginValid => Species <= Legal.getMaxSpeciesOrigin(Format);
public virtual bool IsOriginValid => Species <= Legal.GetMaxSpeciesOrigin(Format);
public virtual bool SecretSuperTrainingUnlocked { get => false; set { } }
public virtual bool SecretSuperTrainingComplete { get => false; set { } }
@ -532,7 +532,7 @@ namespace PKHeX.Core
return false;
// Sanity Check Species ID
if (Legal.getMaxSpeciesOrigin(GenNumber) < species && !Legal.getFutureGenEvolutions(GenNumber).Contains(species))
if (Legal.GetMaxSpeciesOrigin(GenNumber) < species && !Legal.GetFutureGenEvolutions(GenNumber).Contains(species))
return false;
// Trade generation 1 -> 2
@ -571,7 +571,7 @@ namespace PKHeX.Core
/// Checks if the current <see cref="Gender"/> is valid.
/// </summary>
/// <returns>True if valid, False if invalid.</returns>
public virtual bool getGenderIsValid()
public virtual bool IsGenderValid()
{
int gender = Gender;
int gv = PersonalInfo.Gender;
@ -585,7 +585,7 @@ namespace PKHeX.Core
if (GenNumber >= 6)
return true;
return gender == PKX.getGender(PID, gv);
return gender == PKX.GetGender(PID, gv);
}
/// <summary>
@ -670,7 +670,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="p"><see cref="PersonalInfo"/> entry containing Base Stat Info</param>
/// <returns>Battle Stats (H/A/B/S/C/D)</returns>
public virtual ushort[] getStats(PersonalInfo p)
public virtual ushort[] GetStats(PersonalInfo p)
{
int level = CurrentLevel;
ushort[] Stats = new ushort[6];
@ -693,7 +693,7 @@ namespace PKHeX.Core
/// Applies the specified stats to the <see cref="PKM"/>.
/// </summary>
/// <param name="Stats">Battle Stats (H/A/B/S/C/D)</param>
public void setStats(ushort[] Stats)
public void SetStats(ushort[] Stats)
{
Stat_HPMax = Stat_HPCurrent = Stats[0];
Stat_ATK = Stats[1];
@ -725,9 +725,9 @@ namespace PKHeX.Core
/// <param name="move">Move ID</param>
/// <param name="ppup">PP Ups count</param>
/// <returns>Current PP for the move.</returns>
public virtual int getMovePP(int move, int ppup)
public virtual int GetMovePP(int move, int ppup)
{
return getBasePP(move) * (5 + ppup) / 5;
return GetBasePP(move) * (5 + ppup) / 5;
}
/// <summary>
@ -735,7 +735,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="move">Move ID</param>
/// <returns>Amount of PP the move has by default (no PP Ups).</returns>
protected int getBasePP(int move)
protected int GetBasePP(int move)
{
int[] pptable;
switch (Format)
@ -760,20 +760,20 @@ namespace PKHeX.Core
/// <remarks>
/// If a <see cref="PKM"/> originated in a generation prior to Generation 6, the <see cref="EncryptionConstant"/> is updated.
/// </remarks>
public void setShinyPID()
public void SetShinyPID()
{
do PID = PKX.getRandomPID(Species, Gender, Version, Nature, AltForm, PID); while (!IsShiny);
do PID = PKX.GetRandomPID(Species, Gender, Version, Nature, AltForm, PID); while (!IsShiny);
if (GenNumber < 6)
EncryptionConstant = PID;
}
/// <summary>
/// Applies a shiny SID to the <see cref="PKM"/>.
/// </summary>
public void setShinySID()
public void SetShinySID()
{
if (IsShiny) return;
var xor = TID ^ (PID >> 16) ^ (PID & 0xFFFF);
SID = (int)((xor & 0xFFF8) | (Util.rnd32() & 7));
SID = (int)((xor & 0xFFF8) | (Util.Rand32() & 7));
}
/// <summary>
/// Applies a PID to the <see cref="PKM"/> according to the specified <see cref="Gender"/>.
@ -781,9 +781,9 @@ namespace PKHeX.Core
/// <remarks>
/// If a <see cref="PKM"/> originated in a generation prior to Generation 6, the <see cref="EncryptionConstant"/> is updated.
/// </remarks>
public void setPIDGender(int gender)
public void SetPIDGender(int gender)
{
do PID = PKX.getRandomPID(Species, gender, Version, Nature, AltForm, PID); while (IsShiny);
do PID = PKX.GetRandomPID(Species, gender, Version, Nature, AltForm, PID); while (IsShiny);
if (GenNumber < 6)
EncryptionConstant = PID;
}
@ -793,9 +793,9 @@ namespace PKHeX.Core
/// <remarks>
/// If a <see cref="PKM"/> originated in a generation prior to Generation 6, the <see cref="EncryptionConstant"/> is updated.
/// </remarks>
public void setPIDNature(int nature)
public void SetPIDNature(int nature)
{
do PID = PKX.getRandomPID(Species, Gender, Version, nature, AltForm, PID); while (IsShiny);
do PID = PKX.GetRandomPID(Species, Gender, Version, nature, AltForm, PID); while (IsShiny);
if (GenNumber < 6)
EncryptionConstant = PID;
}
@ -806,20 +806,20 @@ namespace PKHeX.Core
/// This method should only be used for Unown originating in Generation 3 games.
/// If a <see cref="PKM"/> originated in a generation prior to Generation 6, the <see cref="EncryptionConstant"/> is updated.
/// </remarks>
public void setPIDUnown3(int form)
public void SetPIDUnown3(int form)
{
do PID = Util.rnd32(); while (PKX.getUnownForm(PID) != form);
do PID = Util.Rand32(); while (PKX.GetUnownForm(PID) != form);
}
/// <summary>
/// Randomizes the IVs within game constraints.
/// </summary>
/// <returns>Randomized IVs if desired.</returns>
public int[] randomizeIVs()
public int[] SetRandomIVs()
{
int[] ivs = new int[6];
for (int i = 0; i < 6; i++)
ivs[i] = (int)(Util.rnd32() & MaxIV);
ivs[i] = (int)(Util.Rand32() & MaxIV);
bool IV3 = GenNumber >= 6 && (Legal.Legends.Contains(Species) || Legal.SubLegends.Contains(Species));
if (IV3)
@ -836,7 +836,7 @@ namespace PKHeX.Core
/// Converts a <see cref="XK3"/> or <see cref="PK3"/> to <see cref="CK3"/>.
/// </summary>
/// <returns><see cref="CK3"/> format <see cref="PKM"/></returns>
public PKM convertToCK3()
public PKM ConvertToCK3()
{
if (Format != 3)
return null;
@ -844,14 +844,14 @@ namespace PKHeX.Core
return this;
var pk = new CK3();
TransferPropertiesWithReflection(this, pk);
pk.setStats(getStats(PersonalTable.RS[pk.Species]));
pk.SetStats(GetStats(PersonalTable.RS[pk.Species]));
return pk;
}
/// <summary>
/// Converts a <see cref="PK3"/> or <see cref="CK3"/> to <see cref="XK3"/>.
/// </summary>
/// <returns><see cref="XK3"/> format <see cref="PKM"/></returns>
public PKM convertToXK3()
public PKM ConvertToXK3()
{
if (Format != 3)
return null;
@ -859,14 +859,14 @@ namespace PKHeX.Core
return this;
var pk = new XK3();
TransferPropertiesWithReflection(this, pk);
pk.setStats(getStats(PersonalTable.RS[pk.Species]));
pk.SetStats(GetStats(PersonalTable.RS[pk.Species]));
return pk;
}
/// <summary>
/// Converts a <see cref="CK3"/> or <see cref="XK3"/> to <see cref="PK3"/>.
/// </summary>
/// <returns><see cref="PK3"/> format <see cref="PKM"/></returns>
public PKM convertToPK3()
public PKM ConvertToPK3()
{
if (Format != 3)
return null;
@ -886,8 +886,8 @@ namespace PKHeX.Core
public void TransferPropertiesWithReflection(PKM Source, PKM Destination)
{
// Only transfer declared properties not defined in PKM.cs but in the actual type
var SourceProperties = ReflectUtil.getPropertiesCanWritePublicDeclared(Source.GetType());
var DestinationProperties = ReflectUtil.getPropertiesCanWritePublicDeclared(Destination.GetType());
var SourceProperties = ReflectUtil.GetPropertiesCanWritePublicDeclared(Source.GetType());
var DestinationProperties = ReflectUtil.GetPropertiesCanWritePublicDeclared(Destination.GetType());
foreach (string property in SourceProperties.Intersect(DestinationProperties))
{
var prop = ReflectUtil.GetValue(this, property);
@ -916,7 +916,7 @@ namespace PKHeX.Core
if (invalid == 4) // no moves remain
{
moves[0] = 1; // Pound
Move1_PP = getMovePP(1, Move1_PPUps);
Move1_PP = GetMovePP(1, Move1_PPUps);
}
Moves = moves;

View file

@ -13,7 +13,7 @@ namespace PKHeX.Core
public static int OT_Gender; // Male
public static int Language = 1; // en
public static void updateConfig(int SUBREGION, int COUNTRY, int _3DSREGION, string TRAINERNAME, int TRAINERGENDER, int LANGUAGE)
public static void UpdateConfig(int SUBREGION, int COUNTRY, int _3DSREGION, string TRAINERNAME, int TRAINERGENDER, int LANGUAGE)
{
Region = SUBREGION;
Country = COUNTRY;
@ -28,9 +28,9 @@ namespace PKHeX.Core
/// </summary>
/// <param name="data">Raw data representing a Pokemon.</param>
/// <returns>An integer indicating the generation of the PKM file, or -1 if the data is invalid.</returns>
public static int getPKMDataFormat(byte[] data)
public static int GetPKMDataFormat(byte[] data)
{
if (!PKX.getIsPKM(data.Length))
if (!PKX.IsPKM(data.Length))
return -1;
switch (data.Length)
@ -57,7 +57,7 @@ namespace PKHeX.Core
case PKX.SIZE_6PARTY: // collision with PGT, same size.
if (BitConverter.ToUInt16(data, 0x4) != 0) // Bad Sanity?
return -1;
if (BitConverter.ToUInt32(data, 0x06) == PKX.getCHK(data))
if (BitConverter.ToUInt32(data, 0x06) == PKX.GetCHK(data))
return 6;
if (BitConverter.ToUInt16(data, 0x58) != 0) // Encrypted?
{
@ -78,10 +78,10 @@ namespace PKHeX.Core
/// <param name="ident">Optional identifier for the Pokemon. Usually the full path of the source file.</param>
/// <param name="prefer">Optional identifier for the preferred generation. Usually the generation of the destination save file.</param>
/// <returns>An instance of <see cref="PKM"/> created from the given <paramref name="data"/>, or null if <paramref name="data"/> is invalid.</returns>
public static PKM getPKMfromBytes(byte[] data, string ident = null, int prefer = 7)
public static PKM GetPKMfromBytes(byte[] data, string ident = null, int prefer = 7)
{
checkEncrypted(ref data);
switch (getPKMDataFormat(data))
CheckEncrypted(ref data);
switch (GetPKMDataFormat(data))
{
case 1:
var PL1 = new PokemonList1(data, PokemonList1.CapacityType.Single, data.Length == PKX.SIZE_1JLIST);
@ -112,7 +112,7 @@ namespace PKHeX.Core
return new PK5(data, ident);
case 6:
var pkx = new PK6(data, ident);
return checkPKMFormat7(pkx, prefer);
return CheckPKMFormat7(pkx, prefer);
default:
return null;
}
@ -124,14 +124,14 @@ namespace PKHeX.Core
/// <param name="pk">PKM to check</param>
/// <param name="prefer">Prefer a certain generation over another</param>
/// <returns>Updated PKM if actually PK7</returns>
private static PKM checkPKMFormat7(PK6 pk, int prefer) => checkPK6is7(pk, prefer) ? new PK7(pk.Data, pk.Identifier) : (PKM)pk;
private static PKM CheckPKMFormat7(PK6 pk, int prefer) => IsPK6FormatReallyPK7(pk, prefer) ? new PK7(pk.Data, pk.Identifier) : (PKM)pk;
/// <summary>
/// Checks if the input PK6 file is really a PK7.
/// </summary>
/// <param name="pk">PK6 to check</param>
/// <param name="prefer">Prefer a certain generation over another</param>
/// <returns>Boolean is a PK7</returns>
private static bool checkPK6is7(PK6 pk, int prefer)
private static bool IsPK6FormatReallyPK7(PK6 pk, int prefer)
{
if (pk.Version > Legal.MaxGameID_6)
return true;
@ -172,7 +172,21 @@ namespace PKHeX.Core
return prefer > 6;
}
public static PKM convertToFormat(PKM pk, Type PKMType, out string comment)
/// <summary>
/// Checks if the input <see cref="PKM"/> file is capable of being converted to the desired format.
/// </summary>
/// <param name="pk"></param>
/// <param name="format"></param>
/// <returns></returns>
public static bool IsConvertibleToFormat(PKM pk, int format)
{
if (pk.Format >= 3 && pk.Format > format)
return false; // pk3->upward can't go backwards
if (pk.Format <= 2 && format > 2 && format < 7)
return false; // pk1/2->upward has to be 7 or greater
return true;
}
public static PKM ConvertToType(PKM pk, Type PKMType, out string comment)
{
if (pk == null || pk.Species == 0)
{
@ -212,21 +226,21 @@ namespace PKHeX.Core
case nameof(PK1):
if (toFormat == 2)
{
pkm = PKMType == typeof (PK2) ? ((PK1) pk).convertToPK2() : null;
pkm = PKMType == typeof (PK2) ? ((PK1) pk).ConvertToPK2() : null;
break;
}
if (toFormat == 7)
pkm = ((PK1) pk).convertToPK7();
pkm = ((PK1) pk).ConvertToPK7();
break;
case nameof(PK2):
if (PKMType == typeof (PK1))
{
if (pk.Species > 151)
{
comment = $"Cannot convert a {PKX.getSpeciesName(pkm.Species, ((PK2)pkm).Japanese ? 1 : 2)} to {PKMType.Name}";
comment = $"Cannot convert a {PKX.GetSpeciesName(pkm.Species, ((PK2)pkm).Japanese ? 1 : 2)} to {PKMType.Name}";
return null;
}
pkm = ((PK2) pk).convertToPK1();
pkm = ((PK2) pk).ConvertToPK1();
pkm.ClearInvalidMoves();
}
else
@ -236,36 +250,36 @@ namespace PKHeX.Core
case nameof(XK3):
// interconverting C/XD needs to visit main series format
// ends up stripping purification/shadow etc stats
pkm = pkm.convertToPK3();
pkm = pkm.ConvertToPK3();
goto case nameof(PK3); // fall through
case nameof(PK3):
if (toFormat == 3) // Gen3 Inter-trading
{
switch (PKMType.Name)
{
case nameof(CK3): pkm = pkm.convertToCK3(); break;
case nameof(XK3): pkm = pkm.convertToXK3(); break;
case nameof(PK3): pkm = pkm.convertToPK3(); break; // already converted, instantly returns
case nameof(CK3): pkm = pkm.ConvertToCK3(); break;
case nameof(XK3): pkm = pkm.ConvertToXK3(); break;
case nameof(PK3): pkm = pkm.ConvertToPK3(); break; // already converted, instantly returns
default: throw new FormatException();
}
break;
}
if (fromType.Name != nameof(PK3))
pkm = pkm.convertToPK3();
pkm = pkm.ConvertToPK3();
pkm = ((PK3)pkm).convertToPK4();
pkm = ((PK3)pkm).ConvertToPK4();
if (toFormat == 4)
break;
goto case nameof(PK4);
case nameof(BK4):
pkm = ((BK4)pkm).convertToPK4();
pkm = ((BK4)pkm).ConvertToPK4();
if (toFormat == 4)
break;
goto case nameof(PK4);
case nameof(PK4):
if (PKMType == typeof(BK4))
{
pkm = ((PK4)pkm).convertToBK4();
pkm = ((PK4)pkm).ConvertToBK4();
break;
}
if (pkm.Species == 172 && pkm.AltForm != 0)
@ -273,12 +287,12 @@ namespace PKHeX.Core
comment = "Cannot transfer Spiky-Eared Pichu forward.";
return null;
}
pkm = ((PK4)pkm).convertToPK5();
pkm = ((PK4)pkm).ConvertToPK5();
if (toFormat == 5)
break;
goto case nameof(PK5);
case nameof(PK5):
pkm = ((PK5)pkm).convertToPK6();
pkm = ((PK5)pkm).ConvertToPK6();
if (toFormat == 6)
break;
goto case nameof(PK6);
@ -288,7 +302,7 @@ namespace PKHeX.Core
comment = "Cannot transfer Cosplay Pikachu forward.";
return null;
}
pkm = ((PK6)pkm).convertToPK7();
pkm = ((PK6)pkm).ConvertToPK7();
if (toFormat == 7)
break;
goto case nameof(PK7);
@ -303,9 +317,9 @@ namespace PKHeX.Core
return pkm;
}
public static void checkEncrypted(ref byte[] pkm)
public static void CheckEncrypted(ref byte[] pkm)
{
int format = getPKMDataFormat(pkm);
int format = GetPKMDataFormat(pkm);
switch (format)
{
case 1:
@ -318,19 +332,19 @@ namespace PKHeX.Core
for (int i = 0x20; i < PKX.SIZE_3STORED; i += 2)
chk += BitConverter.ToUInt16(pkm, i);
if (chk != BitConverter.ToUInt16(pkm, 0x1C))
pkm = PKX.decryptArray3(pkm);
pkm = PKX.DecryptArray3(pkm);
return;
case 4:
case 5:
if (BitConverter.ToUInt16(pkm, 4) != 0) // BK4
return;
if (BitConverter.ToUInt32(pkm, 0x64) != 0)
pkm = PKX.decryptArray45(pkm);
pkm = PKX.DecryptArray45(pkm);
return;
case 6:
case 7:
if (BitConverter.ToUInt16(pkm, 0xC8) != 0 && BitConverter.ToUInt16(pkm, 0x58) != 0)
pkm = PKX.decryptArray(pkm);
pkm = PKX.DecryptArray(pkm);
return;
default:
return; // bad!
@ -342,9 +356,9 @@ namespace PKHeX.Core
/// </summary>
/// <param name="t">Type of <see cref="PKM"/> instance desired.</param>
/// <returns>New instance of a blank <see cref="PKM"/> object.</returns>
public static PKM getBlank(Type t) => (PKM)Activator.CreateInstance(t, Enumerable.Repeat(null as PKM, t.GetTypeInfo().DeclaredConstructors.First().GetParameters().Length).ToArray());
public static PKM GetBlank(Type t) => (PKM)Activator.CreateInstance(t, Enumerable.Repeat(null as PKM, t.GetTypeInfo().DeclaredConstructors.First().GetParameters().Length).ToArray());
public static void transferProperties(PKM source, PKM dest)
public static void TransferProperties(PKM source, PKM dest)
{
source.TransferPropertiesWithReflection(source, dest);
}

View file

@ -46,7 +46,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="len">Data length of the file/array.</param>
/// <returns>A <see cref="bool"/> indicating whether or not the length is valid for a <see cref="PKM"/>.</returns>
public static bool getIsPKM(long len)
public static bool IsPKM(long len)
{
return new[]
{
@ -171,17 +171,17 @@ namespace PKHeX.Core
public static readonly string[][] SpeciesLang =
{
Util.getSpeciesList("ja"), // none
Util.getSpeciesList("ja"), // 1
Util.getSpeciesList("en"), // 2
Util.getSpeciesList("fr"), // 3
Util.getSpeciesList("it"), // 4
Util.getSpeciesList("de"), // 5
Util.getSpeciesList("es"), // none
Util.getSpeciesList("es"), // 7
Util.getSpeciesList("ko"), // 8
Util.getSpeciesList("zh"), // 9 Simplified
Util.getSpeciesList("zh2"), // 10 Traditional
Util.GetSpeciesList("ja"), // none
Util.GetSpeciesList("ja"), // 1
Util.GetSpeciesList("en"), // 2
Util.GetSpeciesList("fr"), // 3
Util.GetSpeciesList("it"), // 4
Util.GetSpeciesList("de"), // 5
Util.GetSpeciesList("es"), // none
Util.GetSpeciesList("es"), // 7
Util.GetSpeciesList("ko"), // 8
Util.GetSpeciesList("zh"), // 9 Simplified
Util.GetSpeciesList("zh2"), // 10 Traditional
};
/// <summary>
@ -190,7 +190,7 @@ namespace PKHeX.Core
/// <param name="species">National Dex number of the Pokémon. Should be 0 if an egg.</param>
/// <param name="lang">Language ID of the Pokémon</param>
/// <returns>The Species name if within expected range, else an empty string.</returns>
public static string getSpeciesName(int species, int lang)
public static string GetSpeciesName(int species, int lang)
{
if (lang < 0 || SpeciesLang.Length <= lang)
return "";
@ -207,9 +207,9 @@ namespace PKHeX.Core
/// <param name="lang">Language ID of the Pokémon</param>
/// <param name="generation">Generation specific formatting option</param>
/// <returns>Generation specific default species name</returns>
public static string getSpeciesNameGeneration(int species, int lang, int generation)
public static string GetSpeciesNameGeneration(int species, int lang, int generation)
{
string nick = getSpeciesName(species, lang);
string nick = GetSpeciesName(species, lang);
if (generation < 5 && (generation != 4 || species != 0)) // All caps GenIV and previous, except GenIV eggs.
nick = nick.ToUpper();
@ -225,7 +225,7 @@ namespace PKHeX.Core
/// <param name="nick">Current name</param>
/// <param name="generation">Generation specific formatting option</param>
/// <returns>True if it does not match any language name, False if not nicknamed</returns>
public static bool getIsNicknamedAnyLanguage(int species, string nick, int generation)
public static bool IsNicknamedAnyLanguage(int species, string nick, int generation)
{
int len = SpeciesLang.Length;
if (generation < 3)
@ -234,7 +234,7 @@ namespace PKHeX.Core
len = 8;
for (int i = 0; i < len; i++)
if (getSpeciesNameGeneration(species, i, generation) == nick)
if (GetSpeciesNameGeneration(species, i, generation) == nick)
return false;
return true;
}
@ -246,7 +246,7 @@ namespace PKHeX.Core
/// <param name="nick">Current name</param>
/// <param name="generation">Generation specific formatting option</param>
/// <returns>Language ID if it does not match any language name, -1 if no matches</returns>
public static int getSpeciesNameLanguage(int species, string nick, int generation)
public static int GetSpeciesNameLanguage(int species, string nick, int generation)
{
int len = SpeciesLang.Length;
if (generation < 3)
@ -255,7 +255,7 @@ namespace PKHeX.Core
len = 8;
for (int i = 0; i < len; i++)
if (getSpeciesNameGeneration(species, i, generation) == nick)
if (GetSpeciesNameGeneration(species, i, generation) == nick)
return i;
return -1;
}
@ -265,18 +265,18 @@ namespace PKHeX.Core
/// </summary>
/// <param name="generation">Generation specific formatting option</param>
/// <returns>Array containing randomized EVs (H/A/B/S/C/D)</returns>
public static uint[] getRandomEVs(int generation = Generation)
public static uint[] GetRandomEVs(int generation = Generation)
{
if (generation > 2)
{
uint[] evs = new uint[6];
do
{
evs[0] = (byte)Math.Min(Util.rnd32() % 300, 252); // bias two to get maybe 252
evs[1] = (byte)Math.Min(Util.rnd32() % 300, 252);
evs[2] = (byte)Math.Min(Util.rnd32() % (510 - evs[0] - evs[1]), 252);
evs[3] = (byte)Math.Min(Util.rnd32() % (510 - evs[0] - evs[1] - evs[2]), 252);
evs[4] = (byte)Math.Min(Util.rnd32() % (510 - evs[0] - evs[1] - evs[2] - evs[3]), 252);
evs[0] = (byte)Math.Min(Util.Rand32() % 300, 252); // bias two to get maybe 252
evs[1] = (byte)Math.Min(Util.Rand32() % 300, 252);
evs[2] = (byte)Math.Min(Util.Rand32() % (510 - evs[0] - evs[1]), 252);
evs[3] = (byte)Math.Min(Util.Rand32() % (510 - evs[0] - evs[1] - evs[2]), 252);
evs[4] = (byte)Math.Min(Util.Rand32() % (510 - evs[0] - evs[1] - evs[2] - evs[3]), 252);
evs[5] = (byte)Math.Min(510 - evs[0] - evs[1] - evs[2] - evs[3] - evs[4], 252);
} while (evs.Sum(b => b) > 510); // recalculate random EVs...
Util.Shuffle(evs);
@ -286,7 +286,7 @@ namespace PKHeX.Core
{
uint[] evs = new uint[6];
for (int i = 0; i < evs.Length; i++)
evs[i] = Util.rnd32() & ushort.MaxValue;
evs[i] = Util.Rand32() & ushort.MaxValue;
return evs;
}
}
@ -297,7 +297,7 @@ namespace PKHeX.Core
/// <param name="species">National Dex number of the Pokémon.</param>
/// <param name="exp">Experience points</param>
/// <returns>Current level of the species.</returns>
public static int getLevel(int species, uint exp)
public static int GetLevel(int species, uint exp)
{
int growth = Personal[species].EXPGrowth;
int tl = 1; // Initial Level. Iterate upwards to find the level
@ -312,7 +312,7 @@ namespace PKHeX.Core
/// <param name="level">Current level</param>
/// <param name="species">National Dex number of the Pokémon.</param>
/// <returns>Experience points needed to have specified level.</returns>
public static uint getEXP(int level, int species)
public static uint GetEXP(int level, int species)
{
if (level <= 1) return 0;
if (level > 100) level = 100;
@ -324,7 +324,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="s">Gender string</param>
/// <returns>Gender integer</returns>
public static int getGender(string s)
public static int GetGender(string s)
{
if (s == null)
return -1;
@ -338,7 +338,7 @@ namespace PKHeX.Core
/// <summary>
/// Positions for shuffling.
/// </summary>
public static readonly byte[][] blockPosition =
private static readonly byte[][] blockPosition =
{
new byte[] {0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 2, 3, 1, 1, 2, 3, 2, 3, 1, 1, 2, 3, 2, 3},
new byte[] {1, 1, 2, 3, 2, 3, 0, 0, 0, 0, 0, 0, 2, 3, 1, 1, 3, 2, 2, 3, 1, 1, 3, 2},
@ -349,7 +349,7 @@ namespace PKHeX.Core
/// <summary>
/// Positions for unshuffling.
/// </summary>
public static readonly byte[] blockPositionInvert =
internal static readonly byte[] blockPositionInvert =
{
0, 1, 2, 4, 3, 5, 6, 7, 12, 18, 13, 19, 8, 10, 14, 20, 16, 22, 9, 11, 15, 21, 17, 23
};
@ -361,7 +361,7 @@ namespace PKHeX.Core
/// <param name="data">Data to shuffle</param>
/// <param name="sv">Block Shuffle order</param>
/// <returns>Shuffled byte array</returns>
public static byte[] shuffleArray(byte[] data, uint sv)
public static byte[] ShuffleArray(byte[] data, uint sv)
{
byte[] sdata = new byte[data.Length];
Array.Copy(data, sdata, 8); // Copy unshuffled bytes
@ -383,7 +383,7 @@ namespace PKHeX.Core
/// <param name="ekx">Encrypted <see cref="PKM"/> data.</param>
/// <returns>Decrypted <see cref="PKM"/> data.</returns>
/// <returns>Encrypted <see cref="PKM"/> data.</returns>
public static byte[] decryptArray(byte[] ekx)
public static byte[] DecryptArray(byte[] ekx)
{
byte[] pkx = (byte[])ekx.Clone();
@ -397,7 +397,7 @@ namespace PKHeX.Core
BitConverter.GetBytes((ushort)(BitConverter.ToUInt16(pkx, i) ^ LCRNG(ref seed) >> 16)).CopyTo(pkx, i);
// Deshuffle
pkx = shuffleArray(pkx, sv);
pkx = ShuffleArray(pkx, sv);
// Decrypt the Party Stats
seed = pv;
@ -412,7 +412,7 @@ namespace PKHeX.Core
/// Encrypts a 232 byte + party stat byte array.
/// </summary>
/// <param name="pkx">Decrypted <see cref="PKM"/> data.</param>
public static byte[] encryptArray(byte[] pkx)
public static byte[] EncryptArray(byte[] pkx)
{
// Shuffle
uint pv = BitConverter.ToUInt32(pkx, 0);
@ -420,7 +420,7 @@ namespace PKHeX.Core
byte[] ekx = (byte[])pkx.Clone();
ekx = shuffleArray(ekx, blockPositionInvert[sv]);
ekx = ShuffleArray(ekx, blockPositionInvert[sv]);
uint seed = pv;
@ -445,7 +445,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="data">Decrypted <see cref="PKM"/> data.</param>
/// <returns></returns>
public static ushort getCHK(byte[] data)
public static ushort GetCHK(byte[] data)
{
ushort chk = 0;
for (int i = 8; i < 232; i += 2) // Loop through the entire PKX
@ -460,7 +460,7 @@ namespace PKHeX.Core
/// <param name="gen">Origin Generation</param>
/// <param name="EC">Encryption Constant</param>
/// <returns>Wurmple Evolution Value</returns>
public static uint getWurmpleEvoVal(int gen, uint EC)
public static uint GetWurmpleEvoVal(int gen, uint EC)
{
uint evoVal;
switch (gen)
@ -483,17 +483,17 @@ namespace PKHeX.Core
/// <param name="OLDPID">Current PID</param>
/// <remarks>Used to retain ability bits.</remarks>
/// <returns>Rerolled PID.</returns>
public static uint getRandomPID(int species, int cg, int origin, int nature, int form, uint OLDPID)
public static uint GetRandomPID(int species, int cg, int origin, int nature, int form, uint OLDPID)
{
uint bits = OLDPID & 0x00010001;
int gt = Personal[species].Gender;
if (origin >= 24)
return Util.rnd32();
return Util.Rand32();
bool g3unown = origin <= 5 && species == 201;
while (true) // Loop until we find a suitable PID
{
uint pid = Util.rnd32();
uint pid = Util.Rand32();
// Gen 3/4: Nature derived from PID
if (origin <= 15 && pid%25 != nature)
@ -513,14 +513,14 @@ namespace PKHeX.Core
return pid; // PID can be anything
// Gen 3/4/5: Gender derived from PID
if (cg == getGender(pid, gt))
if (cg == GetGender(pid, gt))
return pid;
}
}
// Data Requests
public static string getBallString(int ball) => "_ball" + ball;
public static string getSpriteString(int species, int form, int gender, int generation)
public static string GetResourceStringBall(int ball) => "_ball" + ball;
public static string GetResourceStringSprite(int species, int form, int gender, int generation)
{
if (new[] { 778, 664, 665, 414, 493, 773 }.Contains(species)) // Species who show their default sprite regardless of Form
form = 0;
@ -546,7 +546,7 @@ namespace PKHeX.Core
/// <param name="g">List of gender names</param>
/// <param name="generation">Generation number for exclusive formes</param>
/// <returns>A list of strings corresponding to the formes that a Pokémon can have.</returns>
public static string[] getFormList(int species, string[] t, string[] f, string[] g, int generation = Generation)
public static string[] GetFormList(int species, string[] t, string[] f, string[] g, int generation = Generation)
{
// Mega List
if (Array.IndexOf(new[]
@ -1039,7 +1039,7 @@ namespace PKHeX.Core
/// <param name="type">Hidden Power Type</param>
/// <param name="ivs">Individual Values (H/A/B/S/C/D)</param>
/// <returns>Hidden Power Type</returns>
public static int[] setHPIVs(int type, int[] ivs)
public static int[] SetHPIVs(int type, int[] ivs)
{
for (int i = 0; i < 6; i++)
ivs[i] = (ivs[i] & 0x1E) + hpivs[type, i];
@ -1121,7 +1121,7 @@ namespace PKHeX.Core
/// <param name="data">Data to shuffle</param>
/// <param name="sv">Block Shuffle order</param>
/// <returns>Shuffled byte array</returns>
public static byte[] shuffleArray45(byte[] data, uint sv)
public static byte[] ShuffleArray45(byte[] data, uint sv)
{
byte[] sdata = new byte[data.Length];
Array.Copy(data, sdata, 8); // Copy unshuffled bytes
@ -1142,7 +1142,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="ekm">Encrypted <see cref="PKM"/> data.</param>
/// <returns>Decrypted <see cref="PKM"/> data.</returns>
public static byte[] decryptArray45(byte[] ekm)
public static byte[] DecryptArray45(byte[] ekm)
{
byte[] pkm = (byte[])ekm.Clone();
@ -1157,7 +1157,7 @@ namespace PKHeX.Core
BitConverter.GetBytes((ushort)(BitConverter.ToUInt16(pkm, i) ^ LCRNG(ref seed) >> 16)).CopyTo(pkm, i);
// Deshuffle
pkm = shuffleArray45(pkm, sv);
pkm = ShuffleArray45(pkm, sv);
// Decrypt the Party Stats
seed = pv;
@ -1173,7 +1173,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="pkm">Decrypted <see cref="PKM"/> data.</param>
/// <returns>Encrypted <see cref="PKM"/> data.</returns>
public static byte[] encryptArray45(byte[] pkm)
public static byte[] EncryptArray45(byte[] pkm)
{
uint pv = BitConverter.ToUInt32(pkm, 0);
uint sv = ((pv & 0x3E000) >> 0xD) % 24;
@ -1181,7 +1181,7 @@ namespace PKHeX.Core
uint chk = BitConverter.ToUInt16(pkm, 6);
byte[] ekm = (byte[])pkm.Clone();
ekm = shuffleArray45(ekm, blockPositionInvert[sv]);
ekm = ShuffleArray45(ekm, blockPositionInvert[sv]);
uint seed = chk;
@ -1207,7 +1207,7 @@ namespace PKHeX.Core
/// <param name="PID">Personality ID</param>
/// <remarks>Should only be used for 3rd Generation origin specimens.</remarks>
/// <returns></returns>
public static int getUnownForm(uint PID)
public static int GetUnownForm(uint PID)
{
byte[] data = BitConverter.GetBytes(PID);
return (((data[3] & 3) << 6) + ((data[2] & 3) << 4) + ((data[1] & 3) << 2) + ((data[0] & 3) << 0)) % 28;
@ -1219,7 +1219,7 @@ namespace PKHeX.Core
/// <param name="inputstr">Unicode string.</param>
/// <param name="cht">Pkm language is Traditional Chinese.</param>
/// <returns>In-game chinese string.</returns>
public static string str2binG7_zh(string inputstr, bool cht = false)
private static string ConvertString2BinG7_zh(string inputstr, bool cht = false)
{
string resultstr = "";
bool IsCHT = inputstr.Any(chr => Gen7_CHT.Contains(chr) && !Gen7_CHS.Contains(chr));
@ -1238,7 +1238,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="inputstr">In-game chinese string.</param>
/// <returns>Unicode string.</returns>
public static string bin2strG7_zh(string inputstr)
private static string ConvertBin2StringG7_zh(string inputstr)
{
string resultstr = "";
foreach (var val in inputstr)
@ -1257,7 +1257,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="val">Encoded value.</param>
/// <returns>Decoded value (unicode).</returns>
public static ushort val2charG4(ushort val)
private static ushort ConvertValue2CharG4(ushort val)
{
int index = Array.IndexOf(G4Values, val);
return index > -1 ? G4Chars[index] : (ushort)0xFFFF;
@ -1268,7 +1268,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="chr">Decoded value (unicode).</param>
/// <returns>Encoded value.</returns>
public static ushort char2valG4(ushort chr)
private static ushort ConvertChar2ValueG4(ushort chr)
{
int index = Array.IndexOf(G4Chars, chr);
return index > -1 ? G4Values[index] : (ushort)0xFFFF;
@ -1281,14 +1281,14 @@ namespace PKHeX.Core
/// <param name="offset">Offset to read from</param>
/// <param name="count">Length of data to read.</param>
/// <returns>Converted string.</returns>
public static string getBEString4(byte[] strdata, int offset, int count)
public static string GetBEString4(byte[] strdata, int offset, int count)
{
string s = "";
for (int i = 0; i < count; i += 2)
{
ushort val = BigEndian.ToUInt16(strdata, offset + i);
if (val == 0xFFFF) break;
ushort chr = val2charG4(val);
ushort chr = ConvertValue2CharG4(val);
if (chr == 0xFFFF) break;
s += (char)chr;
}
@ -1303,7 +1303,7 @@ namespace PKHeX.Core
/// <param name="padTo">Pad to given length</param>
/// <param name="padWith">Pad with value</param>
/// <returns>Byte array containing encoded character data</returns>
public static byte[] setBEString4(string value, int maxLength, int padTo = 0, ushort padWith = 0)
public static byte[] SetBEString4(string value, int maxLength, int padTo = 0, ushort padWith = 0)
{
if (value.Length > maxLength)
value = value.Substring(0, maxLength); // Hard cap
@ -1311,7 +1311,7 @@ namespace PKHeX.Core
for (int i = 0; i < value.Length; i++)
{
ushort chr = value[i];
ushort val = char2valG4(chr);
ushort val = ConvertChar2ValueG4(chr);
if (val == 0xFFFF || chr == 0xFFFF)
{ Array.Resize(ref strdata, i * 2 + 2); break; }
BigEndian.GetBytes(val).CopyTo(strdata, i * 2);
@ -1333,7 +1333,7 @@ namespace PKHeX.Core
/// <param name="val">Generation 3 encoded value.</param>
/// <param name="jp">Value source is Japanese font.</param>
/// <returns>Generation 4 encoded value.</returns>
public static ushort getG4Val(byte val, bool jp) => jp ? G34_4J[val] : G34_4E[val];
private static ushort GetG4Val(byte val, bool jp) => jp ? G34_4J[val] : G34_4E[val];
/// <summary>
/// Converts a Generation 3 encoded value to corresponding Generation 4 decoded character.
@ -1341,7 +1341,7 @@ namespace PKHeX.Core
/// <param name="val">Generation 3 encoded value.</param>
/// <param name="jp">Value source is Japanese font.</param>
/// <returns>Decoded value.</returns>
public static ushort getG3Char(byte val, bool jp) => val2charG4(getG4Val(val, jp));
private static ushort GetG3Char(byte val, bool jp) => ConvertValue2CharG4(GetG4Val(val, jp));
/// <summary>
/// Converts a Generation 4 decoded character to Generation 3 encoded value.
@ -1349,9 +1349,9 @@ namespace PKHeX.Core
/// <param name="chr">Generation 4 decoded character.</param>
/// <param name="jp">Character destination is Japanese font.</param>
/// <returns>Generation 3 encoded value.</returns>
public static byte setG3Char(ushort chr, bool jp)
private static byte SetG3Char(ushort chr, bool jp)
{
int index = Array.IndexOf(jp ? G34_4J : G34_4E, char2valG4(chr));
int index = Array.IndexOf(jp ? G34_4J : G34_4E, ConvertChar2ValueG4(chr));
return (byte)(index > -1 ? index : 0xFF);
}
@ -1363,7 +1363,7 @@ namespace PKHeX.Core
/// <param name="count">Length of data to read.</param>
/// <param name="jp">Value source is Japanese font.</param>
/// <returns>Decoded string.</returns>
public static string getString3(byte[] strdata, int offset, int count, bool jp)
public static string GetString3(byte[] strdata, int offset, int count, bool jp)
{
StringBuilder s = new StringBuilder();
for (int i = 0; i < count; i++)
@ -1371,7 +1371,7 @@ namespace PKHeX.Core
byte val = strdata[offset + i];
if (val >= 247) // Take valid values
break;
var c = getG3Char(val, jp); // Convert to Unicode
var c = GetG3Char(val, jp); // Convert to Unicode
if (c == 0xFF) // Stop if Terminator
break;
s.Append((char)c);
@ -1388,7 +1388,7 @@ namespace PKHeX.Core
/// <param name="padTo">Pad to given length</param>
/// <param name="padWith">Pad with value</param>
/// <returns></returns>
public static byte[] setString3(string value, int maxLength, bool jp, int padTo = 0, ushort padWith = 0)
public static byte[] SetString3(string value, int maxLength, bool jp, int padTo = 0, ushort padWith = 0)
{
if (value.Length > maxLength)
value = value.Substring(0, maxLength); // Hard cap
@ -1396,7 +1396,7 @@ namespace PKHeX.Core
for (int i = 0; i < value.Length; i++)
{
ushort chr = value[i];
byte val = setG3Char(chr, jp);
byte val = SetG3Char(chr, jp);
if (val == 0xFF || chr == 0xFF)
{ Array.Resize(ref strdata, i); break; }
strdata[i] = val;
@ -1420,7 +1420,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="g3index">Generation 3 species ID.</param>
/// <returns>National Dex ID.</returns>
public static int getG4Species(int g3index)
public static int GetG4Species(int g3index)
{
int index = Array.IndexOf(oldindex, g3index);
return newindex[index > -1 ? index : 0];
@ -1431,7 +1431,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="g4index">National Dex ID</param>
/// <returns>Generation 3 species ID.</returns>
public static int getG3Species(int g4index)
public static int GetG3Species(int g4index)
{
int index = Array.IndexOf(newindex, g4index);
return oldindex[index > -1 ? index : 0];
@ -1444,12 +1444,12 @@ namespace PKHeX.Core
/// <param name="PID">Personality ID.</param>
/// <returns>Gender ID (0/1/2)</returns>
/// <remarks>This method should only be used for Generations 3-5 origin.</remarks>
public static int getGender(int species, uint PID)
public static int GetGender(int species, uint PID)
{
int genderratio = Personal[species].Gender;
return getGender(PID, genderratio);
return GetGender(PID, genderratio);
}
public static int getGender(uint PID, int gr)
public static int GetGender(uint PID, int gr)
{
switch (gr)
{
@ -1506,7 +1506,7 @@ namespace PKHeX.Core
#endregion
#region Gen 3/4 Character Tables (Val->Unicode)
public static readonly ushort[] G4Values =
private static readonly ushort[] G4Values =
{
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
@ -1665,7 +1665,7 @@ namespace PKHeX.Core
3429, 65535
};
public static readonly ushort[] G4Chars =
private static readonly ushort[] G4Chars =
{
12288, 12353, 12354, 12355, 12356, 12357, 12358, 12359, 12360, 12361, 12362, 12363,
12364, 12365, 12366, 12367, 12368, 12369, 12370, 12371, 12372, 12373, 12374, 12375, 12376, 12377, 12378,
@ -1856,7 +1856,7 @@ namespace PKHeX.Core
4467, 4469, 47252, 49968, 50108, 50388, 52012, 65535
};
public static readonly ushort[] G34_4E =
private static readonly ushort[] G34_4E =
{
478, 351, 352, 353, 358, 359, 360, 361, 362, 363, 020, 365, 366, 369, 370, 371, // 0
415, 376, 377, 378, 368, 382, 383, 384, 046, 358, 359, 392, 393, 394, 395, 396, // 1
@ -1876,7 +1876,7 @@ namespace PKHeX.Core
452, 355, 373, 379, 387, 405, 411 // F
};
public static readonly ushort[] G34_4J =
private static readonly ushort[] G34_4J =
{
001, 003, 005, 007, 009, 011, 012, 014, 016, 018, 020, 022, 024, 026, 028, 030, // 0
032, 034, 037, 039, 041, 043, 044, 045, 046, 047, 048, 051, 054, 057, 060, 063, // 1
@ -1897,10 +1897,10 @@ namespace PKHeX.Core
};
#endregion
#region Gen7 Chinese Character Tables
public static readonly char[] Gen7_CHS = Util.getStringList("Char", "zh")[0].ToCharArray();
public const ushort Gen7_CHS_Ofs = 0xE800;
public static readonly char[] Gen7_CHT = Util.getStringList("Char", "zh2")[0].ToCharArray();
public const ushort Gen7_CHT_Ofs = 0xEB0F;
private static readonly char[] Gen7_CHS = Util.GetStringList("Char", "zh")[0].ToCharArray();
private const ushort Gen7_CHS_Ofs = 0xE800;
private static readonly char[] Gen7_CHT = Util.GetStringList("Char", "zh2")[0].ToCharArray();
private const ushort Gen7_CHT_Ofs = 0xEB0F;
#endregion
/// <summary>
/// Trash Bytes for Generation 3->4
@ -1922,7 +1922,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="ekm">Encrypted data.</param>
/// <returns>Decrypted data.</returns>
public static byte[] decryptArray3(byte[] ekm)
public static byte[] DecryptArray3(byte[] ekm)
{
if (ekm.Length != SIZE_3PARTY && ekm.Length != SIZE_3STORED)
return null;
@ -1934,7 +1934,7 @@ namespace PKHeX.Core
byte[] xorkey = BitConverter.GetBytes(seed);
for (int i = 32; i < 80; i++)
ekm[i] ^= xorkey[i % 4];
return shuffleArray3(ekm, PID%24);
return ShuffleArray3(ekm, PID%24);
}
/// <summary>
@ -1943,7 +1943,7 @@ namespace PKHeX.Core
/// <param name="data">Unshuffled data.</param>
/// <param name="sv">Block order shuffle value</param>
/// <returns></returns>
public static byte[] shuffleArray3(byte[] data, uint sv)
private static byte[] ShuffleArray3(byte[] data, uint sv)
{
byte[] sdata = new byte[data.Length];
Array.Copy(data, sdata, 32); // Copy unshuffled bytes
@ -1964,7 +1964,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="pkm">Decrypted data.</param>
/// <returns>Encrypted data.</returns>
public static byte[] encryptArray3(byte[] pkm)
public static byte[] EncryptArray3(byte[] pkm)
{
if (pkm.Length != SIZE_3PARTY && pkm.Length != SIZE_3STORED)
return null;
@ -1973,7 +1973,7 @@ namespace PKHeX.Core
uint OID = BitConverter.ToUInt32(pkm, 4);
uint seed = PID ^ OID;
byte[] ekm = shuffleArray3(pkm, blockPositionInvert[PID%24]);
byte[] ekm = ShuffleArray3(pkm, blockPositionInvert[PID%24]);
byte[] xorkey = BitConverter.GetBytes(seed);
for (int i = 32; i < 80; i++)
ekm[i] ^= xorkey[i % 4];
@ -1988,7 +1988,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="g2val">Generation 2 Item ID.</param>
/// <returns>Generation 4+ Item ID.</returns>
public static ushort getG4Item(byte g2val)
public static ushort GetG4Item(byte g2val)
{
ushort[] arr =
{
@ -2029,7 +2029,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="g3val">Generation 3 Item ID.</param>
/// <returns>Generation 4+ Item ID.</returns>
public static ushort getG4Item(ushort g3val)
public static ushort GetG4Item(ushort g3val)
{
ushort[] arr =
{
@ -2079,10 +2079,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="item">Generation 3 Item ID.</param>
/// <returns>True if transferrable, False if not transferrable.</returns>
public static bool isTransferrable34(ushort item)
{
return item != ITEM_UNK && item > 0;
}
public static bool IsItemTransferrable34(ushort item) => item != ITEM_UNK && item > 0;
#region Gen 1 Character Tables
private static Dictionary<byte, string> RBY2U_U => new Dictionary<byte, string>{
@ -2599,7 +2596,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="raw_id">Generation 1 species ID.</param>
/// <returns>National Dex ID.</returns>
public static int getG1Species(int raw_id)
public static int GetG1Species(int raw_id)
{
int[] table = { 0x00, 0x70, 0x73, 0x20, 0x23, 0x15, 0x64, 0x22, 0x50, 0x02, 0x67, 0x6C, 0x66, 0x58, 0x5E, 0x1D, 0x1F, 0x68, 0x6F, 0x83, 0x3B, 0x97, 0x82, 0x5A, 0x48, 0x5C, 0x7B, 0x78, 0x09, 0x7F, 0x72, 0x00, 0x00, 0x3A, 0x5F, 0x16, 0x10, 0x4F, 0x40, 0x4B, 0x71, 0x43, 0x7A, 0x6A, 0x6B, 0x18, 0x2F, 0x36, 0x60, 0x4C, 0x00, 0x7E, 0x00, 0x7D, 0x52, 0x6D, 0x00, 0x38, 0x56, 0x32, 0x80, 0x00, 0x00, 0x00, 0x53, 0x30, 0x95, 0x00, 0x00, 0x00, 0x54, 0x3C, 0x7C, 0x92, 0x90, 0x91, 0x84, 0x34, 0x62, 0x00, 0x00, 0x00, 0x25, 0x26, 0x19, 0x1A, 0x00, 0x00, 0x93, 0x94, 0x8C, 0x8D, 0x74, 0x75, 0x00, 0x00, 0x1B, 0x1C, 0x8A, 0x8B, 0x27, 0x28, 0x85, 0x88, 0x87, 0x86, 0x42, 0x29, 0x17, 0x2E, 0x3D, 0x3E, 0x0D, 0x0E, 0x0F, 0x00, 0x55, 0x39, 0x33, 0x31, 0x57, 0x00, 0x00, 0x0A, 0x0B, 0x0C, 0x44, 0x00, 0x37, 0x61, 0x2A, 0x96, 0x8F, 0x81, 0x00, 0x00, 0x59, 0x00, 0x63, 0x5B, 0x00, 0x65, 0x24, 0x6E, 0x35, 0x69, 0x00, 0x5D, 0x3F, 0x41, 0x11, 0x12, 0x79, 0x01, 0x03, 0x49, 0x00, 0x76, 0x77, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x4E, 0x13, 0x14, 0x21, 0x1E, 0x4A, 0x89, 0x8E, 0x00, 0x51, 0x00, 0x00, 0x04, 0x07, 0x05, 0x08, 0x06, 0x00, 0x00, 0x00, 0x00, 0x2B, 0x2C, 0x2D, 0x45, 0x46, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
return table[raw_id];
@ -2610,7 +2607,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="dex_id">National Dex ID.</param>
/// <returns>Generation 1 species ID.</returns>
public static int setG1Species(int dex_id)
public static int SetG1Species(int dex_id)
{
int[] table = { 0x00, 0x99, 0x09, 0x9A, 0xB0, 0xB2, 0xB4, 0xB1, 0xB3, 0x1C, 0x7B, 0x7C, 0x7D, 0x70, 0x71, 0x72, 0x24, 0x96, 0x97, 0xA5, 0xA6, 0x05, 0x23, 0x6C, 0x2D, 0x54, 0x55, 0x60, 0x61, 0x0F, 0xA8, 0x10, 0x03, 0xA7, 0x07, 0x04, 0x8E, 0x52, 0x53, 0x64, 0x65, 0x6B, 0x82, 0xB9, 0xBA, 0xBB, 0x6D, 0x2E, 0x41, 0x77, 0x3B, 0x76, 0x4D, 0x90, 0x2F, 0x80, 0x39, 0x75, 0x21, 0x14, 0x47, 0x6E, 0x6F, 0x94, 0x26, 0x95, 0x6A, 0x29, 0x7E, 0xBC, 0xBD, 0xBE, 0x18, 0x9B, 0xA9, 0x27, 0x31, 0xA3, 0xA4, 0x25, 0x08, 0xAD, 0x36, 0x40, 0x46, 0x74, 0x3A, 0x78, 0x0D, 0x88, 0x17, 0x8B, 0x19, 0x93, 0x0E, 0x22, 0x30, 0x81, 0x4E, 0x8A, 0x06, 0x8D, 0x0C, 0x0A, 0x11, 0x91, 0x2B, 0x2C, 0x0B, 0x37, 0x8F, 0x12, 0x01, 0x28, 0x1E, 0x02, 0x5C, 0x5D, 0x9D, 0x9E, 0x1B, 0x98, 0x2A, 0x1A, 0x48, 0x35, 0x33, 0x1D, 0x3C, 0x85, 0x16, 0x13, 0x4C, 0x66, 0x69, 0x68, 0x67, 0xAA, 0x62, 0x63, 0x5A, 0x5B, 0xAB, 0x84, 0x4A, 0x4B, 0x49, 0x58, 0x59, 0x42, 0x83, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
return table[dex_id];
@ -2624,7 +2621,7 @@ namespace PKHeX.Core
/// <param name="count"></param>
/// <param name="jp">Data source is Japanese.</param>
/// <returns>Decoded string.</returns>
public static string getString1(byte[] strdata, int offset, int count, bool jp)
public static string GetString1(byte[] strdata, int offset, int count, bool jp)
{
Dictionary<byte, string> dict = jp ? RBY2U_J : RBY2U_U;
@ -2648,7 +2645,7 @@ namespace PKHeX.Core
/// <param name="key">Encoded character.</param>
/// <param name="jp">Data source is Japanese.</param>
/// <returns>Decoded string.</returns>
public static string getG1Char(byte key, bool jp)
public static string GetG1Char(byte key, bool jp)
{
Dictionary<byte, string> dict = jp ? RBY2U_J : RBY2U_U;
return dict.ContainsKey(key) ? dict[key] : "";
@ -2660,7 +2657,7 @@ namespace PKHeX.Core
/// <param name="strdata">Generation 1 encoded data.</param>
/// <param name="jp">Data source is Japanese.</param>
/// <returns>Decoded string.</returns>
public static string getG1ConvertedString(byte[] strdata, bool jp)
public static string GetG1ConvertedString(byte[] strdata, bool jp)
{
var us_table = new ushort[] { 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0000, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x0028, 0x0029, 0x003A, 0x003B, 0x0028, 0x0029, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007A, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x00C4, 0x00D6, 0x00DC, 0x00E4, 0x00F6, 0x00FC, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0050, 0x004D, 0x002D, 0x0020, 0x0020, 0x003F, 0x0021, 0x002D, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0xE08E, 0x0020, 0x0078, 0x002E, 0x002F, 0x002C, 0xE08F, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020 };
var jp_table = new ushort[] { 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x30AC, 0x30AE, 0x30B0, 0x30B2, 0x30B4, 0x30B6, 0x30B8, 0x30BA, 0x30BC, 0x30BE, 0x30C0, 0x30C2, 0x30C5, 0x30C7, 0x30C9, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x30D0, 0x30D3, 0x30D6, 0x30DC, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x304C, 0x304E, 0x3050, 0x3052, 0x3054, 0x3056, 0x3058, 0x305A, 0x305C, 0x305E, 0x3060, 0x3062, 0x3065, 0x3067, 0x3069, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3070, 0x3073, 0x3076, 0x30D9, 0x307C, 0x3000, 0x30D1, 0x30D4, 0x30D7, 0x30DD, 0x3071, 0x3074, 0x3077, 0x30DA, 0x307D, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x0000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x30A2, 0x30A4, 0x30A6, 0x30A8, 0x30AA, 0x30AB, 0x30AD, 0x30AF, 0x30B1, 0x30B3, 0x30B5, 0x30B7, 0x30B9, 0x30BB, 0x30BD, 0x30BF, 0x30C1, 0x30C4, 0x30C6, 0x30C8, 0x30CA, 0x30CB, 0x30CC, 0x30CD, 0x30CE, 0x30CF, 0x30D2, 0x30D5, 0x30DB, 0x30DE, 0x30DF, 0x30E0, 0x30E1, 0x30E2, 0x30E4, 0x30E6, 0x30E8, 0x30E9, 0x30EB, 0x30EC, 0x30ED, 0x30EF, 0x30F2, 0x30F3, 0x30C3, 0x30E3, 0x30E5, 0x30E7, 0x30A3, 0x3042, 0x3044, 0x3046, 0x3048, 0x304A, 0x304B, 0x304D, 0x304F, 0x3051, 0x3053, 0x3055, 0x3057, 0x3059, 0x305B, 0x305D, 0x305F, 0x3061, 0x3064, 0x3066, 0x3068, 0x306A, 0x306B, 0x306C, 0x306D, 0x306E, 0x306F, 0x3072, 0x3075, 0x30D8, 0x307B, 0x307E, 0x307F, 0x3080, 0x3081, 0x3082, 0x3084, 0x3086, 0x3088, 0x3089, 0x30EA, 0x308B, 0x308C, 0x308D, 0x308F, 0x3092, 0x3093, 0x3063, 0x3083, 0x3085, 0x3087, 0x30FC, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x30A1, 0x30A5, 0x30A7, 0x3000, 0x3000, 0x3000, 0x2642, 0x3000, 0x3000, 0x3000, 0x3000, 0x30A9, 0x2640, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000 };
@ -2677,7 +2674,7 @@ namespace PKHeX.Core
/// <param name="padTo">Pad to given length</param>
/// <param name="padWith">Pad with value</param>
/// <returns>Encoded data.</returns>
public static byte[] setString1(string value, int maxLength, bool jp, int padTo = 0, ushort padWith = 0)
public static byte[] SetString1(string value, int maxLength, bool jp, int padTo = 0, ushort padWith = 0)
{
if (value.Length > maxLength)
value = value.Substring(0, maxLength); // Hard cap
@ -2689,8 +2686,7 @@ namespace PKHeX.Core
List<byte> arr = new List<byte>();
foreach (char c in value)
{
byte val;
if (!dict.TryGetValue(c.ToString(), out val))
if (!dict.TryGetValue(c.ToString(), out byte val))
break;
arr.Add(val);
}
@ -2706,7 +2702,7 @@ namespace PKHeX.Core
/// <param name="offset">Offset to read from</param>
/// <param name="count">Length of data to read.</param>
/// <returns>Decoded string.</returns>
public static string getBEString3(byte[] data, int offset, int count)
public static string GetBEString3(byte[] data, int offset, int count)
{
return Util.TrimFromZero(Encoding.BigEndianUnicode.GetString(data, offset, count));
}
@ -2717,7 +2713,7 @@ namespace PKHeX.Core
/// <param name="padTo">Pad to given length</param>
/// <param name="padWith">Pad with value</param>
/// <returns>Encoded data.</returns>
public static byte[] setBEString3(string value, int maxLength, int padTo = 0, ushort padWith = 0)
public static byte[] SetBEString3(string value, int maxLength, int padTo = 0, ushort padWith = 0)
{
if (value.Length > maxLength)
value = value.Substring(0, maxLength); // Hard cap
@ -2732,14 +2728,14 @@ namespace PKHeX.Core
/// <param name="offset">Offset to read from</param>
/// <param name="count">Length of data to read.</param>
/// <returns>Decoded string.</returns>
public static string getString4(byte[] data, int offset, int count)
public static string GetString4(byte[] data, int offset, int count)
{
StringBuilder s = new StringBuilder();
for (int i = 0; i < count; i += 2)
{
ushort val = BitConverter.ToUInt16(data, offset + i);
if (val == 0xFFFF) break;
ushort chr = val2charG4(val);
ushort chr = ConvertValue2CharG4(val);
if (chr == 0xFFFF) break;
s.Append((char)chr);
}
@ -2752,7 +2748,7 @@ namespace PKHeX.Core
/// <param name="padTo">Pad to given length</param>
/// <param name="padWith">Pad with value</param>
/// <returns>Encoded data.</returns>
public static byte[] setString4(string value, int maxLength, int padTo = 0, ushort padWith = 0)
public static byte[] SetString4(string value, int maxLength, int padTo = 0, ushort padWith = 0)
{
if (value.Length > maxLength)
value = value.Substring(0, maxLength); // Hard cap
@ -2764,7 +2760,7 @@ namespace PKHeX.Core
for (int i = 0; i < temp.Length; i++)
{
ushort chr = temp[i];
ushort val = char2valG4(chr);
ushort val = ConvertChar2ValueG4(chr);
BitConverter.GetBytes(val).CopyTo(strdata, i * 2);
}
return strdata;
@ -2775,7 +2771,7 @@ namespace PKHeX.Core
/// <param name="offset">Offset to read from</param>
/// <param name="count">Length of data to read.</param>
/// <returns>Decoded string.</returns>
public static string getString5(byte[] data, int offset, int count)
public static string GetString5(byte[] data, int offset, int count)
{
return SanitizeString(TrimFromFFFF(Encoding.Unicode.GetString(data, offset, count)));
}
@ -2786,7 +2782,7 @@ namespace PKHeX.Core
/// <param name="padTo">Pad to given length</param>
/// <param name="padWith">Pad with value</param>
/// <returns>Encoded data.</returns>
public static byte[] setString5(string value, int maxLength, int padTo = 0, ushort padWith = 0)
public static byte[] SetString5(string value, int maxLength, int padTo = 0, ushort padWith = 0)
{
if (value.Length > maxLength)
value = value.Substring(0, maxLength); // Hard cap
@ -2801,7 +2797,7 @@ namespace PKHeX.Core
/// <param name="offset">Offset to read from</param>
/// <param name="count">Length of data to read.</param>
/// <returns>Decoded string.</returns>
public static string getString6(byte[] data, int offset, int count)
public static string GetString6(byte[] data, int offset, int count)
{
return SanitizeString(Util.TrimFromZero(Encoding.Unicode.GetString(data, offset, count)));
}
@ -2812,7 +2808,7 @@ namespace PKHeX.Core
/// <param name="padTo">Pad to given length</param>
/// <param name="padWith">Pad with value</param>
/// <returns>Encoded data.</returns>
public static byte[] setString6(string value, int maxLength, int padTo = 0, ushort padWith = 0)
public static byte[] SetString6(string value, int maxLength, int padTo = 0, ushort padWith = 0)
{
if (value.Length > maxLength)
value = value.Substring(0, maxLength); // Hard cap
@ -2827,9 +2823,9 @@ namespace PKHeX.Core
/// <param name="offset">Offset to read from</param>
/// <param name="count">Length of data to read.</param>
/// <returns>Decoded string.</returns>
public static string getString7(byte[] data, int offset, int count)
public static string GetString7(byte[] data, int offset, int count)
{
return bin2strG7_zh(SanitizeString(Util.TrimFromZero(Encoding.Unicode.GetString(data, offset, count))));
return ConvertBin2StringG7_zh(SanitizeString(Util.TrimFromZero(Encoding.Unicode.GetString(data, offset, count))));
}
/// <summary>Gets the bytes for a Generation 7 string.</summary>
@ -2839,11 +2835,11 @@ namespace PKHeX.Core
/// <param name="padTo">Pad to given length</param>
/// <param name="padWith">Pad with value</param>
/// <returns>Encoded data.</returns>
public static byte[] setString7(string value, int maxLength, int language, int padTo = 0, ushort padWith = 0)
public static byte[] SetString7(string value, int maxLength, int language, int padTo = 0, ushort padWith = 0)
{
if (value.Length > maxLength)
value = value.Substring(0, 12); // Hard cap
string temp = str2binG7_zh(UnSanitizeString(value), language == 10)
string temp = ConvertString2BinG7_zh(UnSanitizeString(value), language == 10)
.PadRight(value.Length + 1, '\0') // Null Terminator
.PadRight(padTo, (char)padWith);
return Encoding.Unicode.GetBytes(temp);
@ -2859,20 +2855,20 @@ namespace PKHeX.Core
/// <param name="offset">Offset to read from</param>
/// <param name="count">Length of data to read.</param>
/// <returns>Decoded string.</returns>
public static string getString(byte[] data, int generation, bool jp, bool bigendian, int count, int offset = 0)
public static string GetString(byte[] data, int generation, bool jp, bool bigendian, int count, int offset = 0)
{
if (bigendian)
return generation == 3 ? getBEString3(data, offset, count) : getBEString4(data, offset, count);
return generation == 3 ? GetBEString3(data, offset, count) : GetBEString4(data, offset, count);
switch (generation)
{
case 1:
case 2: return getString1(data, offset, count, jp);
case 3: return getString3(data, offset, count, jp);
case 4: return getString4(data, offset, count);
case 5: return getString5(data, offset, count);
case 6: return getString6(data, offset, count);
default: return getString7(data, offset, count);
case 2: return GetString1(data, offset, count, jp);
case 3: return GetString3(data, offset, count, jp);
case 4: return GetString4(data, offset, count);
case 5: return GetString5(data, offset, count);
case 6: return GetString6(data, offset, count);
default: return GetString7(data, offset, count);
}
}
@ -2888,20 +2884,20 @@ namespace PKHeX.Core
/// <param name="padTo">Pad to given length</param>
/// <param name="padWith">Pad with value</param>
/// <returns>Encoded data.</returns>
public static byte[] setString(string value, int generation, bool jp, bool bigendian, int maxLength, int language = 0, int padTo = 0, ushort padWith = 0)
public static byte[] SetString(string value, int generation, bool jp, bool bigendian, int maxLength, int language = 0, int padTo = 0, ushort padWith = 0)
{
if (bigendian)
return generation == 3 ? setBEString3(value, maxLength, padTo, padWith) : setBEString4(value, maxLength, padTo, padWith);
return generation == 3 ? SetBEString3(value, maxLength, padTo, padWith) : SetBEString4(value, maxLength, padTo, padWith);
switch (generation)
{
case 1:
case 2: return setString1(value, maxLength, jp, padTo, padWith);
case 3: return setString3(value, maxLength, jp, padTo, padWith);
case 4: return setString4(value, maxLength, padTo, padWith);
case 5: return setString5(value, maxLength, padTo, padWith);
case 6: return setString6(value, maxLength, padTo, padWith);
default: return setString7(value, maxLength, language, padTo, padWith);
case 2: return SetString1(value, maxLength, jp, padTo, padWith);
case 3: return SetString3(value, maxLength, jp, padTo, padWith);
case 4: return SetString4(value, maxLength, padTo, padWith);
case 5: return SetString5(value, maxLength, padTo, padWith);
case 6: return SetString6(value, maxLength, padTo, padWith);
default: return SetString7(value, maxLength, language, padTo, padWith);
}
}
@ -2910,20 +2906,20 @@ namespace PKHeX.Core
/// </summary>
/// <param name="value">GameCube (C/XD) language ID.</param>
/// <returns>Main Series language ID.</returns>
public static byte getMainLangIDfromGC(byte value) => value == 6 ? (byte)7 : value;
public static byte GetMainLangIDfromGC(byte value) => value == 6 ? (byte)7 : value;
/// <summary>
/// Gets the GameCube (C/XD) language ID from a Main Series language ID. Re-maps Spanish 7->6.
/// </summary>
/// <param name="value">Main Series language ID.</param>
/// <returns>GameCube (C/XD) language ID.</returns>
public static byte getGCLangIDfromMain(byte value) => value == 7 ? (byte)6 : value;
public static byte GetGCLangIDfromMain(byte value) => value == 7 ? (byte)6 : value;
/// <summary>
/// Gets an array of valid <see cref="PKM"/> file extensions.
/// </summary>
/// <returns>Valid <see cref="PKM"/> file extensions.</returns>
public static string[] getPKMExtensions(int MaxGeneration = Generation)
public static string[] GetPKMExtensions(int MaxGeneration = Generation)
{
var result = new List<string>();
result.AddRange(new [] {"ck3", "xk3", "bk4"}); // Special Cases
@ -2933,7 +2929,7 @@ namespace PKHeX.Core
}
// Extensions
public static string getLocation(this PKM pk, bool eggmet)
public static string GetLocationString(this PKM pk, bool eggmet)
{
if (pk.Format < 2)
return "";
@ -2969,12 +2965,12 @@ namespace PKHeX.Core
locval -= 1;
}
var bank = GameInfo.getLocationNames(gen, bankID);
var bank = GameInfo.GetLocationNames(gen, bankID);
if (bank == null || bank.Length <= locval)
return "";
return bank[locval];
}
public static string[] getQRText(this PKM pkm)
public static string[] GetQRLines(this PKM pkm)
{
var s = GameInfo.Strings;
// Summarize

View file

@ -2,9 +2,9 @@
namespace PKHeX.Core
{
public class QRPK7
public struct QRPK7
{
public byte[] Data;
private readonly byte[] Data;
public uint EncryptionConstant => BitConverter.ToUInt32(Data, 0);
public int HT_Flags => Data[4];

View file

@ -8,13 +8,14 @@ namespace PKHeX.Core
{
// String to Values
private static readonly string[] StatNames = { "HP", "Atk", "Def", "SpA", "SpD", "Spe" };
private static readonly string[] types = Util.getTypesList("en");
private static readonly string[] forms = Util.getFormsList("en");
private static readonly string[] species = Util.getSpeciesList("en");
private static readonly string[] items = Util.getItemsList("en");
private static readonly string[] natures = Util.getNaturesList("en");
private static readonly string[] moves = Util.getMovesList("en");
private static readonly string[] abilities = Util.getAbilitiesList("en");
private const string Language = "en";
private static readonly string[] types = Util.GetTypesList(Language);
private static readonly string[] forms = Util.GetFormsList(Language);
private static readonly string[] species = Util.GetSpeciesList(Language);
private static readonly string[] items = Util.GetItemsList(Language);
private static readonly string[] natures = Util.GetNaturesList(Language);
private static readonly string[] moves = Util.GetMovesList(Language);
private static readonly string[] abilities = Util.GetAbilitiesList(Language);
private static readonly string[] hptypes = types.Skip(1).ToArray();
private const int MAX_SPECIES = 802;
@ -23,7 +24,7 @@ namespace PKHeX.Core
public int Species { get; private set; } = -1;
public string Form { get; private set; }
public string Gender { get; private set; }
public int Item { get; private set; }
public int HeldItem { get; private set; }
public int Ability { get; private set; }
public int Level { get; private set; } = 100;
public bool Shiny { get; private set; }
@ -59,7 +60,7 @@ namespace PKHeX.Core
lines = lines.Skip(start).Take(lines.Length - start).ToArray();
else // Has no Item -- try parsing the first line anyway.
{
parseFirstLine(lines[0]);
ParseFirstLine(lines[0]);
if (Species < -1)
return; // Abort if no text is found
@ -71,7 +72,7 @@ namespace PKHeX.Core
{
if (line.StartsWith("-"))
{
string moveString = parseLineMove(line);
string moveString = ParseLineMove(line);
int move = Array.IndexOf(moves, moveString);
if (move < 0)
InvalidLines.Add($"Unknown Move: {moveString}");
@ -95,9 +96,9 @@ namespace PKHeX.Core
case "Happiness": { Friendship = Util.ToInt32(brokenline[1].Trim()); break; }
case "Nature": { Nature = Array.IndexOf(natures, brokenline[1].Trim()); break; }
case "EV":
case "EVs": { parseLineEVs(brokenline[1].Trim()); break; }
case "EVs": { ParseLineEVs(brokenline[1].Trim()); break; }
case "IV":
case "IVs": { parseLineIVs(brokenline[1].Trim()); break; }
case "IVs": { ParseLineIVs(brokenline[1].Trim()); break; }
case "Type": { brokenline = new[] {line}; goto default; } // Type: Null edge case
default:
{
@ -110,9 +111,9 @@ namespace PKHeX.Core
if (item < 0)
InvalidLines.Add($"Unknown Item: {itemstr}");
else
Item = item;
HeldItem = item;
parseFirstLine(pieces[0]);
ParseFirstLine(pieces[0]);
}
else if (brokenline[0].Contains("Nature"))
{
@ -160,7 +161,9 @@ namespace PKHeX.Core
break;
}
}
public string getText()
public string Text => GetText();
private string GetText()
{
if (Species == 0 || Species > MAX_SPECIES)
return "";
@ -200,8 +203,8 @@ namespace PKHeX.Core
string result = Nickname != null && species[Species] != Nickname ? $"{Nickname} ({specForm})" : $"{specForm}";
if (!string.IsNullOrEmpty(Gender))
result += $" ({Gender})";
if (Item > 0 && Item < items.Length)
result += " @ " + items[Item];
if (HeldItem > 0 && HeldItem < items.Length)
result += " @ " + items[HeldItem];
result += Environment.NewLine;
// IVs
@ -257,16 +260,16 @@ namespace PKHeX.Core
return result;
}
public static string getShowdownText(PKM pkm)
public static string GetShowdownText(PKM pkm)
{
if (pkm.Species == 0) return "";
string[] Forms = PKX.getFormList(pkm.Species, types, forms, new[] {"", "F", ""}, pkm.Format);
string[] Forms = PKX.GetFormList(pkm.Species, types, forms, new[] {"", "F", ""}, pkm.Format);
ShowdownSet Set = new ShowdownSet
{
Nickname = pkm.Nickname,
Species = pkm.Species,
Item = pkm.HeldItem,
HeldItem = pkm.HeldItem,
Ability = pkm.Ability,
EVs = pkm.EVs,
IVs = pkm.IVs,
@ -274,7 +277,7 @@ namespace PKHeX.Core
Nature = pkm.Nature,
Gender = new[] { "M", "F", "" }[pkm.Gender < 2 ? pkm.Gender : 2],
Friendship = pkm.CurrentFriendship,
Level = PKX.getLevel(pkm.Species, pkm.EXP),
Level = PKX.GetLevel(pkm.Species, pkm.EXP),
Shiny = pkm.IsShiny,
Form = pkm.AltForm > 0 && pkm.AltForm < Forms.Length ? Forms[pkm.AltForm] : "",
};
@ -283,10 +286,10 @@ namespace PKHeX.Core
else if (Set.Species == 676) Set.Form = ""; // Furfrou
else if (Set.Species == 666 && Set.Form == "Poké Ball") Set.Form = "Pokeball"; // Vivillon
return Set.getText();
return Set.GetText();
}
private void parseFirstLine(string line)
private void ParseFirstLine(string line)
{
// Gender Detection
string last3 = line.Substring(line.Length - 3);
@ -299,7 +302,7 @@ namespace PKHeX.Core
// Nickname Detection
string spec = line;
if (spec.Contains("(") && spec.Contains(")"))
parseSpeciesNickname(ref spec);
ParseSpeciesNickname(ref spec);
spec = spec.Trim();
if ((Species = Array.IndexOf(species, spec)) >= 0) // success, nothing else!
@ -314,7 +317,7 @@ namespace PKHeX.Core
if (tmp.Length > 2)
Form += " " + tmp[2];
}
private void parseSpeciesNickname(ref string line)
private void ParseSpeciesNickname(ref string line)
{
int index = line.LastIndexOf("(", StringComparison.Ordinal);
string n1, n2;
@ -322,7 +325,7 @@ namespace PKHeX.Core
{
n1 = line.Substring(0, index - 1);
n2 = line.Substring(index).Trim();
replaceAll(ref n2, "", "[", "]", "(", ")"); // Trim out excess data
ReplaceAll(ref n2, "", "[", "]", "(", ")"); // Trim out excess data
}
else // nickname first (manually created set, incorrect)
{
@ -335,7 +338,7 @@ namespace PKHeX.Core
line = inverted ? n2 : n1;
Nickname = inverted ? n1 : n2;
}
private string parseLineMove(string line)
private string ParseLineMove(string line)
{
string moveString = line.Substring(line[1] == ' ' ? 2 : 1);
if (!moveString.Contains("Hidden Power"))
@ -345,25 +348,24 @@ namespace PKHeX.Core
if (moveString.Length > 13)
{
string type = moveString.Remove(0, 13);
replaceAll(ref type, "", "[", "]", "(", ")"); // Trim out excess data
ReplaceAll(ref type, "", "[", "]", "(", ")"); // Trim out excess data
int hpVal = Array.IndexOf(hptypes, type); // Get HP Type
if (hpVal >= 0)
IVs = PKX.setHPIVs(hpVal, IVs); // Get IVs
IVs = PKX.SetHPIVs(hpVal, IVs); // Get IVs
else
InvalidLines.Add($"Invalid Hidden Power Type: {type}");
}
moveString = "Hidden Power";
return moveString;
}
private void parseLineEVs(string line)
private void ParseLineEVs(string line)
{
string[] evlist = splitLineStats(line);
string[] evlist = SplitLineStats(line);
if (evlist.Length == 1)
InvalidLines.Add("Unknown EV input.");
for (int i = 0; i < evlist.Length / 2; i++)
{
ushort EV;
ushort.TryParse(evlist[i * 2 + 0], out EV);
ushort.TryParse(evlist[i * 2 + 0], out ushort EV);
int index = Array.IndexOf(StatNames, evlist[i * 2 + 1]);
if (index > -1)
EVs[index] = EV;
@ -371,15 +373,14 @@ namespace PKHeX.Core
InvalidLines.Add($"Unknown EV Type input: {evlist[i * 2]}");
}
}
private void parseLineIVs(string line)
private void ParseLineIVs(string line)
{
string[] ivlist = splitLineStats(line);
string[] ivlist = SplitLineStats(line);
if (ivlist.Length == 1)
InvalidLines.Add("Unknown IV input.");
for (int i = 0; i < ivlist.Length / 2; i++)
{
byte IV;
byte.TryParse(ivlist[i * 2 + 0], out IV);
byte.TryParse(ivlist[i * 2 + 0], out byte IV);
int index = Array.IndexOf(StatNames, ivlist[i * 2 + 1]);
if (index > -1)
IVs[index] = IV;
@ -388,7 +389,7 @@ namespace PKHeX.Core
}
}
private static string[] splitLineStats(string line)
private static string[] SplitLineStats(string line)
{
// Because people think they can type sets out...
return line
@ -396,7 +397,7 @@ namespace PKHeX.Core
.Replace("SDef", "SpD").Replace("Sp Def", "SpD")
.Replace("Spd", "Spe").Replace("Speed", "Spe").Split(new[] { " / ", " " }, StringSplitOptions.None);
}
private static void replaceAll(ref string rv, string o, params string[] i)
private static void ReplaceAll(ref string rv, string o, params string[] i)
{
rv = i.Aggregate(rv, (current, v) => current.Replace(v, o));
}

View file

@ -18,40 +18,40 @@ namespace PKHeX.Core
public XK3(byte[] decryptedData = null, string ident = null)
{
Data = (byte[])(decryptedData ?? new byte[SIZE_PARTY]).Clone();
PKMConverter.checkEncrypted(ref Data);
PKMConverter.CheckEncrypted(ref Data);
Identifier = ident;
if (Data.Length != SIZE_PARTY)
Array.Resize(ref Data, SIZE_PARTY);
}
public override PKM Clone() { return new XK3(Data) {Purification = Purification}; }
public override string getString(int Offset, int Count) => PKX.getBEString3(Data, Offset, Count);
public override byte[] setString(string value, int maxLength) => PKX.setBEString3(value, maxLength);
public override string GetString(int Offset, int Count) => PKX.GetBEString3(Data, Offset, Count);
public override byte[] SetString(string value, int maxLength) => PKX.SetBEString3(value, maxLength);
// Trash Bytes
public override byte[] Nickname_Trash { get => getData(0x4E, 20); set { if (value?.Length == 20) value.CopyTo(Data, 0x4E); } }
public override byte[] OT_Trash { get => getData(0x38, 20); set { if (value?.Length == 20) value.CopyTo(Data, 0x38); } }
public override byte[] Nickname_Trash { get => GetData(0x4E, 20); set { if (value?.Length == 20) value.CopyTo(Data, 0x4E); } }
public override byte[] OT_Trash { get => GetData(0x38, 20); set { if (value?.Length == 20) value.CopyTo(Data, 0x38); } }
// Future Attributes
public override uint EncryptionConstant { get => PID; set { } }
public override int Nature { get => (int)(PID % 25); set { } }
public override int AltForm { get => Species == 201 ? PKX.getUnownForm(PID) : 0; set { } }
public override int AltForm { get => Species == 201 ? PKX.GetUnownForm(PID) : 0; set { } }
public override bool IsNicknamed { get => PKX.getIsNicknamedAnyLanguage(Species, Nickname, Format); set { } }
public override int Gender { get => PKX.getGender(Species, PID); set { } }
public override bool IsNicknamed { get => PKX.IsNicknamedAnyLanguage(Species, Nickname, Format); set { } }
public override int Gender { get => PKX.GetGender(Species, PID); set { } }
public override int Characteristic => -1;
public override int CurrentFriendship { get => OT_Friendship; set => OT_Friendship = value; }
public override int Ability { get { int[] abils = PersonalTable.RS.getAbilities(Species, 0); return abils[abils[1] == 0 ? 0 : AbilityNumber >> 1]; } set { } }
public override int Ability { get { int[] abils = PersonalTable.RS.GetAbilities(Species, 0); return abils[abils[1] == 0 ? 0 : AbilityNumber >> 1]; } set { } }
public override int CurrentHandler { get => 0; set { } }
public override int Egg_Location { get => 0; set { } }
// Silly Attributes
public override ushort Sanity { get => 0; set { } } // valid flag set in pkm structure.
public override ushort Checksum { get => SaveUtil.ccitt16(Data); set { } } // totally false, just a way to get a 'random' ident for the pkm.
public override ushort Checksum { get => SaveUtil.CRC16_CCITT(Data); set { } } // totally false, just a way to get a 'random' ident for the pkm.
public override bool ChecksumValid => Valid;
public override int Species { get => PKX.getG4Species(BigEndian.ToUInt16(Data, 0x00)); set => BigEndian.GetBytes((ushort)PKX.getG3Species(value)).CopyTo(Data, 0x00); }
public override int SpriteItem => PKX.getG4Item((ushort)HeldItem);
public override int Species { get => PKX.GetG4Species(BigEndian.ToUInt16(Data, 0x00)); set => BigEndian.GetBytes((ushort)PKX.GetG3Species(value)).CopyTo(Data, 0x00); }
public override int SpriteItem => PKX.GetG4Item((ushort)HeldItem);
public override int HeldItem { get => BigEndian.ToUInt16(Data, 0x02); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x02); }
public override int Stat_HPCurrent { get => BigEndian.ToUInt16(Data, 0x04); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x04); }
public override int OT_Friendship { get => Data[0x06]; set => Data[0x06] = (byte)value; }
@ -86,13 +86,13 @@ namespace PKHeX.Core
public override bool FatefulEncounter { get => Data[0x30] == 1; set => Data[0x30] = (byte)(value ? 1 : 0); }
// 0x31-0x32 Unknown
public new int EncounterType { get => Data[0x33]; set => Data[0x33] = (byte)value; }
public override int Version { get => SaveUtil.getG3VersionID(Data[0x34]); set => Data[0x34] = (byte)SaveUtil.getCXDVersionID(value); }
public override int Version { get => SaveUtil.GetG3VersionID(Data[0x34]); set => Data[0x34] = (byte)SaveUtil.GetCXDVersionID(value); }
public int CurrentRegion { get => Data[0x35]; set => Data[0x35] = (byte)value; }
public int OriginalRegion { get => Data[0x36]; set => Data[0x36] = (byte)value; }
public override int Language { get => PKX.getMainLangIDfromGC(Data[0x37]); set => Data[0x37] = PKX.getGCLangIDfromMain((byte)value); }
public override string OT_Name { get => getString(0x38, 20); set => setString(value, 10).CopyTo(Data, 0x38); } // +2 terminator
public override string Nickname { get => getString(0x4E, 20); set { setString(value, 10).CopyTo(Data, 0x4E); Nickname2 = value; } } // +2 terminator
private string Nickname2 { get => getString(0x64, 20); set => setString(value, 10).CopyTo(Data, 0x64); } // +2 terminator
public override int Language { get => PKX.GetMainLangIDfromGC(Data[0x37]); set => Data[0x37] = PKX.GetGCLangIDfromMain((byte)value); }
public override string OT_Name { get => GetString(0x38, 20); set => SetString(value, 10).CopyTo(Data, 0x38); } // +2 terminator
public override string Nickname { get => GetString(0x4E, 20); set { SetString(value, 10).CopyTo(Data, 0x4E); Nickname2 = value; } } // +2 terminator
private string Nickname2 { get => GetString(0x64, 20); set => SetString(value, 10).CopyTo(Data, 0x64); } // +2 terminator
// 0x7A-0x7B Unknown
private ushort RIB0 { get => BigEndian.ToUInt16(Data, 0x7C); set => BigEndian.GetBytes(value).CopyTo(Data, 0x7C); }
public bool RibbonChampionG3Hoenn { get => (RIB0 & (1 << 15)) == 1 << 15; set => RIB0 = (ushort)(RIB0 & ~(1 << 15) | (ushort)(value ? 1 << 15 : 0)); }
@ -197,7 +197,7 @@ namespace PKHeX.Core
public override int TSV => (TID ^ SID) >> 3;
public bool Japanese => Language == 1;
public override byte[] Encrypt()
protected override byte[] Encrypt()
{
return (byte[])Data.Clone();
}

View file

@ -44,14 +44,14 @@
public bool[] TypeTutors { get; protected set; }
public bool[][] SpecialTutors { get; protected set; } = new bool[0][];
protected static bool[] getBits(byte[] data)
protected static bool[] GetBits(byte[] data)
{
bool[] r = new bool[data.Length<<3];
for (int i = 0; i < r.Length; i++)
r[i] = (data[i>>3] >> (i&7) & 0x1) == 1;
return r;
}
protected static byte[] setBits(bool[] bits)
protected static byte[] SetBits(bool[] bits)
{
byte[] data = new byte[bits.Length>>3];
for (int i = 0; i < bits.Length; i++)
@ -59,8 +59,8 @@
return data;
}
public void AddTMHM(byte[] data) => TMHM = getBits(data);
public void AddTypeTutors(byte[] data) => TypeTutors = getBits(data);
public void AddTMHM(byte[] data) => TMHM = GetBits(data);
public void AddTypeTutors(byte[] data) => TypeTutors = GetBits(data);
// Data Manipulation
public int FormeIndex(int species, int forme)
@ -87,7 +87,7 @@
case 0: // Male
return 0;
default:
return (int)(Util.rnd32() % 2);
return (int)(Util.Rand32() % 2);
}
}
}

View file

@ -12,25 +12,25 @@ namespace PKHeX.Core
Data = data;
// Unpack TMHM & Tutors
TMHM = getBits(Data.Skip(0x28).Take(0x10).ToArray());
TypeTutors = getBits(Data.Skip(0x38).Take(0x4).ToArray());
TMHM = GetBits(Data.Skip(0x28).Take(0x10).ToArray());
TypeTutors = GetBits(Data.Skip(0x38).Take(0x4).ToArray());
SpecialTutors = new[]
{
getBits(Data.Skip(0x3C).Take(0x04).ToArray()),
getBits(Data.Skip(0x40).Take(0x04).ToArray()),
getBits(Data.Skip(0x44).Take(0x04).ToArray()),
getBits(Data.Skip(0x48).Take(0x04).ToArray()),
GetBits(Data.Skip(0x3C).Take(0x04).ToArray()),
GetBits(Data.Skip(0x40).Take(0x04).ToArray()),
GetBits(Data.Skip(0x44).Take(0x04).ToArray()),
GetBits(Data.Skip(0x48).Take(0x04).ToArray()),
};
}
public override byte[] Write()
{
setBits(TMHM).CopyTo(Data, 0x28);
setBits(TypeTutors).CopyTo(Data, 0x38);
setBits(SpecialTutors[0]).CopyTo(Data, 0x3C);
setBits(SpecialTutors[1]).CopyTo(Data, 0x40);
setBits(SpecialTutors[2]).CopyTo(Data, 0x44);
setBits(SpecialTutors[3]).CopyTo(Data, 0x48);
SetBits(TMHM).CopyTo(Data, 0x28);
SetBits(TypeTutors).CopyTo(Data, 0x38);
SetBits(SpecialTutors[0]).CopyTo(Data, 0x3C);
SetBits(SpecialTutors[1]).CopyTo(Data, 0x40);
SetBits(SpecialTutors[2]).CopyTo(Data, 0x44);
SetBits(SpecialTutors[3]).CopyTo(Data, 0x48);
return Data;
}
}

View file

@ -14,13 +14,13 @@ namespace PKHeX.Core
Data = data;
// Unpack TMHM & Tutors
TMHM = getBits(Data.Skip(0x28).Take(0x10).ToArray());
TypeTutors = getBits(Data.Skip(0x38).Take(0x4).ToArray());
TMHM = GetBits(Data.Skip(0x28).Take(0x10).ToArray());
TypeTutors = GetBits(Data.Skip(0x38).Take(0x4).ToArray());
}
public override byte[] Write()
{
setBits(TMHM).CopyTo(Data, 0x28);
setBits(TypeTutors).CopyTo(Data, 0x38);
SetBits(TMHM).CopyTo(Data, 0x28);
SetBits(TypeTutors).CopyTo(Data, 0x38);
return Data;
}

View file

@ -12,11 +12,11 @@ namespace PKHeX.Core
return;
Data = data;
TMHM = getBits(Data.Skip(0x14).Take(0x8).ToArray());
TMHM = GetBits(Data.Skip(0x14).Take(0x8).ToArray());
}
public override byte[] Write()
{
setBits(TMHM).CopyTo(Data, 0x14);
SetBits(TMHM).CopyTo(Data, 0x14);
return Data;
}
@ -51,7 +51,7 @@ namespace PKHeX.Core
public override int EV_ATK { get => ATK; set { } }
public override int EV_DEF { get => DEF; set { } }
public override int EV_SPE { get => SPE; set { } }
public int EV_SPC { get => SPC; set { } }
public int EV_SPC => SPC;
public override int EV_SPA { get => EV_SPC; set { } }
public override int EV_SPD { get => EV_SPC; set { } }

View file

@ -12,11 +12,11 @@ namespace PKHeX.Core
return;
Data = data;
TMHM = getBits(Data.Skip(0x18).Take(0x8).ToArray());
TMHM = GetBits(Data.Skip(0x18).Take(0x8).ToArray());
}
public override byte[] Write()
{
setBits(TMHM).CopyTo(Data, 0x18);
SetBits(TMHM).CopyTo(Data, 0x18);
return Data;
}

View file

@ -13,12 +13,12 @@ namespace PKHeX.Core
Data = data;
// Unpack TMHM & Tutors
TMHM = getBits(Data.Skip(0x1C).Take(0x0D).ToArray());
TMHM = GetBits(Data.Skip(0x1C).Take(0x0D).ToArray());
TypeTutors = new bool[0]; // not stored in personal
}
public override byte[] Write()
{
setBits(TMHM).CopyTo(Data, 0x28);
SetBits(TMHM).CopyTo(Data, 0x28);
// setBits(TypeTutors).CopyTo(Data, 0x38);
return Data;
}

View file

@ -12,25 +12,25 @@ namespace PKHeX.Core
Data = data;
// Unpack TMHM & Tutors
TMHM = getBits(Data.Skip(0x28).Take(0x10).ToArray());
TypeTutors = getBits(Data.Skip(0x38).Take(0x4).ToArray());
TMHM = GetBits(Data.Skip(0x28).Take(0x10).ToArray());
TypeTutors = GetBits(Data.Skip(0x38).Take(0x4).ToArray());
// 0x3C-0x40 unknown
SpecialTutors = new[]
{
getBits(Data.Skip(0x40).Take(0x04).ToArray()),
getBits(Data.Skip(0x44).Take(0x04).ToArray()),
getBits(Data.Skip(0x48).Take(0x04).ToArray()),
getBits(Data.Skip(0x4C).Take(0x04).ToArray()),
GetBits(Data.Skip(0x40).Take(0x04).ToArray()),
GetBits(Data.Skip(0x44).Take(0x04).ToArray()),
GetBits(Data.Skip(0x48).Take(0x04).ToArray()),
GetBits(Data.Skip(0x4C).Take(0x04).ToArray()),
};
}
public override byte[] Write()
{
setBits(TMHM).CopyTo(Data, 0x28);
setBits(TypeTutors).CopyTo(Data, 0x38);
setBits(SpecialTutors[0]).CopyTo(Data, 0x40);
setBits(SpecialTutors[1]).CopyTo(Data, 0x44);
setBits(SpecialTutors[2]).CopyTo(Data, 0x48);
setBits(SpecialTutors[3]).CopyTo(Data, 0x4C);
SetBits(TMHM).CopyTo(Data, 0x28);
SetBits(TypeTutors).CopyTo(Data, 0x38);
SetBits(SpecialTutors[0]).CopyTo(Data, 0x40);
SetBits(SpecialTutors[1]).CopyTo(Data, 0x44);
SetBits(SpecialTutors[2]).CopyTo(Data, 0x48);
SetBits(SpecialTutors[3]).CopyTo(Data, 0x4C);
return Data;
}
}

View file

@ -12,8 +12,8 @@ namespace PKHeX.Core
return;
Data = data;
TMHM = getBits(Data.Skip(0x28).Take(0x10).ToArray()); // 36-39
TypeTutors = getBits(Data.Skip(0x38).Take(0x4).ToArray()); // 40
TMHM = GetBits(Data.Skip(0x28).Take(0x10).ToArray()); // 36-39
TypeTutors = GetBits(Data.Skip(0x38).Take(0x4).ToArray()); // 40
}
public override byte[] Write()
{

View file

@ -13,14 +13,14 @@ namespace PKHeX.Core
Data = data;
// Unpack TMHM & Tutors
TMHM = getBits(Data.Skip(0x28).Take(0x10).ToArray());
TypeTutors = getBits(Data.Skip(0x38).Take(0x4).ToArray());
TMHM = GetBits(Data.Skip(0x28).Take(0x10).ToArray());
TypeTutors = GetBits(Data.Skip(0x38).Take(0x4).ToArray());
// 0x3C-0x40 unknown
}
public override byte[] Write()
{
setBits(TMHM).CopyTo(Data, 0x28);
setBits(TypeTutors).CopyTo(Data, 0x38);
SetBits(TMHM).CopyTo(Data, 0x28);
SetBits(TypeTutors).CopyTo(Data, 0x38);
return Data;
}
}

View file

@ -5,24 +5,24 @@ namespace PKHeX.Core
{
public class PersonalTable
{
public static readonly PersonalTable SM = new PersonalTable(Util.getBinaryResource("personal_sm"), GameVersion.SM);
public static readonly PersonalTable AO = new PersonalTable(Util.getBinaryResource("personal_ao"), GameVersion.ORAS);
public static readonly PersonalTable XY = new PersonalTable(Util.getBinaryResource("personal_xy"), GameVersion.XY);
public static readonly PersonalTable B2W2 = new PersonalTable(Util.getBinaryResource("personal_b2w2"), GameVersion.B2W2);
public static readonly PersonalTable BW = new PersonalTable(Util.getBinaryResource("personal_bw"), GameVersion.BW);
public static readonly PersonalTable HGSS = new PersonalTable(Util.getBinaryResource("personal_hgss"), GameVersion.HGSS);
public static readonly PersonalTable Pt = new PersonalTable(Util.getBinaryResource("personal_pt"), GameVersion.Pt);
public static readonly PersonalTable DP = new PersonalTable(Util.getBinaryResource("personal_dp"), GameVersion.DP);
public static readonly PersonalTable LG = new PersonalTable(Util.getBinaryResource("personal_lg"), GameVersion.LG);
public static readonly PersonalTable FR = new PersonalTable(Util.getBinaryResource("personal_fr"), GameVersion.FR);
public static readonly PersonalTable E = new PersonalTable(Util.getBinaryResource("personal_e"), GameVersion.E);
public static readonly PersonalTable RS = new PersonalTable(Util.getBinaryResource("personal_rs"), GameVersion.RS);
public static readonly PersonalTable C = new PersonalTable(Util.getBinaryResource("personal_c"), GameVersion.C);
public static readonly PersonalTable GS = new PersonalTable(Util.getBinaryResource("personal_c"), GameVersion.GS);
public static readonly PersonalTable RB = new PersonalTable(Util.getBinaryResource("personal_rb"), GameVersion.RBY);
public static readonly PersonalTable Y = new PersonalTable(Util.getBinaryResource("personal_y"), GameVersion.RBY);
public static readonly PersonalTable SM = new PersonalTable(Util.GetBinaryResource("personal_sm"), GameVersion.SM);
public static readonly PersonalTable AO = new PersonalTable(Util.GetBinaryResource("personal_ao"), GameVersion.ORAS);
public static readonly PersonalTable XY = new PersonalTable(Util.GetBinaryResource("personal_xy"), GameVersion.XY);
public static readonly PersonalTable B2W2 = new PersonalTable(Util.GetBinaryResource("personal_b2w2"), GameVersion.B2W2);
public static readonly PersonalTable BW = new PersonalTable(Util.GetBinaryResource("personal_bw"), GameVersion.BW);
public static readonly PersonalTable HGSS = new PersonalTable(Util.GetBinaryResource("personal_hgss"), GameVersion.HGSS);
public static readonly PersonalTable Pt = new PersonalTable(Util.GetBinaryResource("personal_pt"), GameVersion.Pt);
public static readonly PersonalTable DP = new PersonalTable(Util.GetBinaryResource("personal_dp"), GameVersion.DP);
public static readonly PersonalTable LG = new PersonalTable(Util.GetBinaryResource("personal_lg"), GameVersion.LG);
public static readonly PersonalTable FR = new PersonalTable(Util.GetBinaryResource("personal_fr"), GameVersion.FR);
public static readonly PersonalTable E = new PersonalTable(Util.GetBinaryResource("personal_e"), GameVersion.E);
public static readonly PersonalTable RS = new PersonalTable(Util.GetBinaryResource("personal_rs"), GameVersion.RS);
public static readonly PersonalTable C = new PersonalTable(Util.GetBinaryResource("personal_c"), GameVersion.C);
public static readonly PersonalTable GS = new PersonalTable(Util.GetBinaryResource("personal_c"), GameVersion.GS);
public static readonly PersonalTable RB = new PersonalTable(Util.GetBinaryResource("personal_rb"), GameVersion.RBY);
public static readonly PersonalTable Y = new PersonalTable(Util.GetBinaryResource("personal_y"), GameVersion.RBY);
private static byte[][] splitBytes(byte[] data, int size)
private static byte[][] SplitBytes(byte[] data, int size)
{
byte[][] r = new byte[data.Length / size][];
for (int i = 0; i < data.Length; i += size)
@ -57,7 +57,7 @@ namespace PKHeX.Core
if (size == 0)
{ Table = null; return; }
byte[][] entries = splitBytes(data, size);
byte[][] entries = SplitBytes(data, size);
PersonalInfo[] d = new PersonalInfo[data.Length / size];
switch (format)
@ -125,25 +125,25 @@ namespace PKHeX.Core
}
}
public int[] getAbilities(int species, int forme)
public int[] GetAbilities(int species, int forme)
{
if (species >= Table.Length)
{ species = 0; Console.WriteLine("Requested out of bounds SpeciesID"); }
return this[getFormeIndex(species, forme)].Abilities;
return this[GetFormeIndex(species, forme)].Abilities;
}
public int getFormeIndex(int species, int forme)
public int GetFormeIndex(int species, int forme)
{
if (species >= Table.Length)
{ species = 0; Console.WriteLine("Requested out of bounds SpeciesID"); }
return this[species].FormeIndex(species, forme);
}
public PersonalInfo getFormeEntry(int species, int forme)
public PersonalInfo GetFormeEntry(int species, int forme)
{
return this[getFormeIndex(species, forme)];
return this[GetFormeIndex(species, forme)];
}
public int TableLength => Table.Length;
public string[][] getFormList(string[] species, int MaxSpecies)
public string[][] GetFormList(string[] species, int MaxSpecies)
{
string[][] FormList = new string[MaxSpecies+1][];
for (int i = 0; i <= MaxSpecies; i++) //Hardcode 721 species + null
@ -160,7 +160,7 @@ namespace PKHeX.Core
return FormList;
}
public string[] getPersonalEntryList(string[][] AltForms, string[] species, int MaxSpecies, out int[] baseForm, out int[] formVal)
public string[] GetPersonalEntryList(string[][] AltForms, string[] species, int MaxSpecies, out int[] baseForm, out int[] formVal)
{
string[] result = new string[Table.Length];
baseForm = new int[result.Length];

View file

@ -24,15 +24,15 @@ namespace PKHeX.Core
Version = GameVersion.RBY;
else if (versionOverride != GameVersion.Any)
Version = versionOverride;
else Version = SaveUtil.getIsG1SAV(Data);
else Version = SaveUtil.GetIsG1SAV(Data);
if (Version == GameVersion.Invalid)
return;
Box = Data.Length;
Array.Resize(ref Data, Data.Length + SIZE_RESERVED);
Party = getPartyOffset(0);
Party = GetPartyOffset(0);
Japanese = SaveUtil.getIsG1SAVJ(Data);
Japanese = SaveUtil.GetIsG1SAVJ(Data);
Personal = PersonalTable.Y;
// Stash boxes after the save file's end.
@ -83,12 +83,12 @@ namespace PKHeX.Core
if (i < partyList.Count)
{
byte[] pkDat = new PokemonList1(partyList[i]).GetBytes();
pkDat.CopyTo(Data, getPartyOffset(i));
pkDat.CopyTo(Data, GetPartyOffset(i));
}
else
{
byte[] pkDat = new byte[PokemonList1.GetDataLength(PokemonList1.CapacityType.Single, Japanese)];
pkDat.CopyTo(Data, getPartyOffset(i));
pkDat.CopyTo(Data, GetPartyOffset(i));
}
}
@ -100,18 +100,19 @@ namespace PKHeX.Core
Array.Copy(rawDC, 1 + StringLength, TempDaycare, 2 + 1 + PKX.SIZE_1PARTY, StringLength);
Array.Copy(rawDC, 1 + 2 * StringLength, TempDaycare, 2 + 1, PKX.SIZE_1STORED);
PokemonList1 daycareList = new PokemonList1(TempDaycare, PokemonList1.CapacityType.Single, Japanese);
daycareList.GetBytes().CopyTo(Data, getPartyOffset(7));
Daycare = getPartyOffset(7);
daycareList.GetBytes().CopyTo(Data, GetPartyOffset(7));
Daycare = GetPartyOffset(7);
// Enable Pokedex editing
PokeDex = 0;
if (!Exportable)
resetBoxes();
ClearBoxes();
}
private const int SIZE_RESERVED = 0x8000; // unpacked box data
public override byte[] Write(bool DSV)
protected override byte[] Write(bool DSV)
{
for (int i = 0; i < BoxCount; i++)
{
@ -119,7 +120,7 @@ namespace PKHeX.Core
int slot = 0;
for (int j = 0; j < boxPL.Pokemon.Length; j++)
{
PK1 boxPK = (PK1) getPKM(getData(getBoxOffset(i) + j*SIZE_STORED, SIZE_STORED));
PK1 boxPK = (PK1) GetPKM(GetData(GetBoxOffset(i) + j*SIZE_STORED, SIZE_STORED));
if (boxPK.Species > 0)
boxPL[slot++] = boxPK;
}
@ -135,14 +136,14 @@ namespace PKHeX.Core
int pSlot = 0;
for (int i = 0; i < 6; i++)
{
PK1 partyPK = (PK1)getPKM(getData(getPartyOffset(i), SIZE_STORED));
PK1 partyPK = (PK1)GetPKM(GetData(GetPartyOffset(i), SIZE_STORED));
if (partyPK.Species > 0)
partyPL[pSlot++] = partyPK;
}
partyPL.GetBytes().CopyTo(Data, Japanese ? 0x2ED5 : 0x2F2C);
// Daycare is read-only, but in case it ever becomes editable, copy it back in.
byte[] rawDC = getData(getDaycareSlotOffset(loc: 0, slot: 0), SIZE_STORED);
byte[] rawDC = GetData(GetDaycareSlotOffset(loc: 0, slot: 0), SIZE_STORED);
byte[] dc = new byte[1 + 2*StringLength + PKX.SIZE_1STORED];
dc[0] = rawDC[0];
Array.Copy(rawDC, 2 + 1 + PKX.SIZE_1PARTY + StringLength, dc, 1, StringLength);
@ -150,7 +151,7 @@ namespace PKHeX.Core
Array.Copy(rawDC, 2 + 1, dc, 1 + 2*StringLength, PKX.SIZE_1STORED);
dc.CopyTo(Data, Japanese ? 0x2CA7 : 0x2CF4);
setChecksums();
SetChecksums();
byte[] outData = new byte[Data.Length - SIZE_RESERVED];
Array.Copy(Data, outData, outData.Length);
return outData;
@ -161,7 +162,7 @@ namespace PKHeX.Core
public override SaveFile Clone() { return new SAV1(Write(DSV: false)); }
public override int SIZE_STORED => Japanese ? PKX.SIZE_1JLIST : PKX.SIZE_1ULIST;
public override int SIZE_PARTY => Japanese ? PKX.SIZE_1JLIST : PKX.SIZE_1ULIST;
protected override int SIZE_PARTY => Japanese ? PKX.SIZE_1JLIST : PKX.SIZE_1ULIST;
private int SIZE_BOX => BoxSlotCount*SIZE_STORED;
private int SIZE_STOREDBOX => PokemonList1.GetDataLength(Japanese ? PokemonList1.CapacityType.StoredJP : PokemonList1.CapacityType.Stored, Japanese);
@ -190,7 +191,7 @@ namespace PKHeX.Core
private int StringLength => Japanese ? PK1.STRLEN_J : PK1.STRLEN_U;
// Checksums
protected override void setChecksums()
protected override void SetChecksums()
{
int CHECKSUM_OFS = Japanese ? 0x3594 : 0x3523;
Data[CHECKSUM_OFS] = 0;
@ -211,7 +212,7 @@ namespace PKHeX.Core
{
int CHECKSUM_OFS = Japanese ? 0x3594 : 0x3523;
byte temp = Data[CHECKSUM_OFS]; // cache current chk
setChecksums(); // chksum is recalculated (after being set to 0 to perform check)
SetChecksums(); // chksum is recalculated (after being set to 0 to perform check)
byte chk = Data[CHECKSUM_OFS]; // correct checksum
Data[CHECKSUM_OFS] = temp; // restore old chk
return temp == chk;
@ -224,8 +225,8 @@ namespace PKHeX.Core
public override string OT
{
get => getString(0x2598, OTLength);
set => setString(value, OTLength).CopyTo(Data, 0x2598);
get => GetString(0x2598, OTLength);
set => SetString(value, OTLength).CopyTo(Data, 0x2598);
}
public override int Gender
{
@ -342,7 +343,7 @@ namespace PKHeX.Core
};
foreach (var p in pouch)
{
p.getPouchG1(ref Data);
p.GetPouchG1(ref Data);
}
return pouch;
}
@ -359,27 +360,27 @@ namespace PKHeX.Core
}
while (ofs < p.Items.Length)
p.Items[ofs++] = new InventoryItem { Count = 0, Index = 0 };
p.setPouchG1(ref Data);
p.SetPouchG1(ref Data);
}
}
}
public override int getDaycareSlotOffset(int loc, int slot)
public override int GetDaycareSlotOffset(int loc, int slot)
{
return Daycare;
}
public override uint? getDaycareEXP(int loc, int slot)
public override uint? GetDaycareEXP(int loc, int slot)
{
return null;
}
public override bool? getDaycareOccupied(int loc, int slot)
public override bool? IsDaycareOccupied(int loc, int slot)
{
return null;
}
public override void setDaycareEXP(int loc, int slot, uint EXP)
public override void SetDaycareEXP(int loc, int slot, uint EXP)
{
}
public override void setDaycareOccupied(int loc, int slot, bool occupied)
public override void SetDaycareOccupied(int loc, int slot, bool occupied)
{
}
@ -390,11 +391,11 @@ namespace PKHeX.Core
get => Data[Japanese ? 0x2ED5 : 0x2F2C];
protected set => Data[Japanese ? 0x2ED5 : 0x2F2C] = (byte)value;
}
public override int getBoxOffset(int box)
public override int GetBoxOffset(int box)
{
return Data.Length - SIZE_RESERVED + box * SIZE_BOX;
}
public override int getPartyOffset(int slot)
public override int GetPartyOffset(int slot)
{
return Data.Length - SIZE_RESERVED + BoxCount * SIZE_BOX + slot * SIZE_STORED;
}
@ -403,22 +404,22 @@ namespace PKHeX.Core
get => Data[Japanese ? 0x2842 : 0x284C] & 0x7F;
set => Data[Japanese ? 0x2842 : 0x284C] = (byte)((Data[Japanese ? 0x2842 : 0x284C] & 0x80) | (value & 0x7F));
}
public override string getBoxName(int box)
public override string GetBoxName(int box)
{
return $"BOX {box + 1}";
}
public override void setBoxName(int box, string value)
public override void SetBoxName(int box, string value)
{
// Don't allow for custom box names
}
public override PKM getPKM(byte[] data)
public override PKM GetPKM(byte[] data)
{
if (data.Length == SIZE_STORED)
return new PokemonList1(data, PokemonList1.CapacityType.Single, Japanese)[0];
return new PK1(data);
}
public override byte[] decryptPKM(byte[] data)
public override byte[] DecryptPKM(byte[] data)
{
return data;
}
@ -426,16 +427,16 @@ namespace PKHeX.Core
// Pokédex
private int PokedexSeenOffset => Japanese ? 0x25B1 : 0x25B6;
private int PokedexCaughtOffset => Japanese ? 0x259E : 0x25A3;
protected override void setDex(PKM pkm)
protected override void SetDex(PKM pkm)
{
int species = pkm.Species;
if (!canSetDex(species))
if (!CanSetDex(species))
return;
setCaught(pkm.Species, true);
setSeen(pkm.Species, true);
SetCaught(pkm.Species, true);
SetSeen(pkm.Species, true);
}
private bool canSetDex(int species)
private bool CanSetDex(int species)
{
if (species <= 0)
return false;
@ -445,7 +446,7 @@ namespace PKHeX.Core
return false;
return true;
}
public override void setSeen(int species, bool seen)
public override void SetSeen(int species, bool seen)
{
int bit = species - 1;
int ofs = bit >> 3;
@ -456,7 +457,7 @@ namespace PKHeX.Core
else
Data[PokedexSeenOffset + ofs] &= (byte)~bitval;
}
public override void setCaught(int species, bool caught)
public override void SetCaught(int species, bool caught)
{
int bit = species - 1;
int ofs = bit >> 3;
@ -467,14 +468,14 @@ namespace PKHeX.Core
else
Data[PokedexCaughtOffset + ofs] &= (byte)~bitval;
}
public override bool getSeen(int species)
public override bool GetSeen(int species)
{
int bit = species - 1;
int ofs = bit >> 3;
byte bitval = (byte)(1 << (bit & 7));
return (Data[PokedexSeenOffset + ofs] & bitval) != 0;
}
public override bool getCaught(int species)
public override bool GetCaught(int species)
{
int bit = species - 1;
int ofs = bit >> 3;
@ -482,12 +483,12 @@ namespace PKHeX.Core
return (Data[PokedexCaughtOffset + ofs] & bitval) != 0;
}
public override string getString(int Offset, int Count) => PKX.getString1(Data, Offset, Count, Japanese);
public override byte[] setString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
public override string GetString(int Offset, int Count) => PKX.GetString1(Data, Offset, Count, Japanese);
public override byte[] SetString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
{
if (PadToSize == 0)
PadToSize = maxLength + 1;
return PKX.setString1(value, maxLength, Japanese, PadToSize, PadWith);
return PKX.SetString1(value, maxLength, Japanese, PadToSize, PadWith);
}
}
}

View file

@ -25,22 +25,22 @@ namespace PKHeX.Core
else if (versionOverride != GameVersion.Any)
Version = versionOverride;
else
Version = SaveUtil.getIsG2SAV(Data);
Version = SaveUtil.GetIsG2SAV(Data);
if (Version == GameVersion.Invalid)
return;
Japanese = SaveUtil.getIsG2SAVJ(Data) != GameVersion.Invalid;
Japanese = SaveUtil.GetIsG2SAVJ(Data) != GameVersion.Invalid;
if (Japanese && Data.Length < SaveUtil.SIZE_G2RAW_J)
Array.Resize(ref Data, SaveUtil.SIZE_G2RAW_J);
Box = Data.Length;
Array.Resize(ref Data, Data.Length + SIZE_RESERVED);
Party = getPartyOffset(0);
Party = GetPartyOffset(0);
Personal = Version == GameVersion.GS ? PersonalTable.GS : PersonalTable.C;
getSAVOffsets();
GetSAVOffsets();
LegalItems = Legal.Pouch_Items_GSC;
LegalBalls = Legal.Pouch_Ball_GSC;
@ -96,12 +96,12 @@ namespace PKHeX.Core
if (i < partyList.Count)
{
byte[] pkDat = new PokemonList2(partyList[i]).GetBytes();
pkDat.CopyTo(Data, getPartyOffset(i));
pkDat.CopyTo(Data, GetPartyOffset(i));
}
else
{
byte[] pkDat = new byte[PokemonList2.GetDataLength(PokemonList2.CapacityType.Single, Japanese)];
pkDat.CopyTo(Data, getPartyOffset(i));
pkDat.CopyTo(Data, GetPartyOffset(i));
}
}
@ -111,11 +111,12 @@ namespace PKHeX.Core
PokeDex = 0;
if (!Exportable)
resetBoxes();
ClearBoxes();
}
private const int SIZE_RESERVED = 0x8000; // unpacked box data
public override byte[] Write(bool DSV)
protected override byte[] Write(bool DSV)
{
for (int i = 0; i < BoxCount; i++)
{
@ -123,7 +124,7 @@ namespace PKHeX.Core
int slot = 0;
for (int j = 0; j < boxPL.Pokemon.Length; j++)
{
PK2 boxPK = (PK2) getPKM(getData(getBoxOffset(i) + j*SIZE_STORED, SIZE_STORED));
PK2 boxPK = (PK2) GetPKM(GetData(GetBoxOffset(i) + j*SIZE_STORED, SIZE_STORED));
if (boxPK.Species > 0)
boxPL[slot++] = boxPK;
}
@ -139,13 +140,13 @@ namespace PKHeX.Core
int pSlot = 0;
for (int i = 0; i < 6; i++)
{
PK2 partyPK = (PK2)getPKM(getData(getPartyOffset(i), SIZE_STORED));
PK2 partyPK = (PK2)GetPKM(GetData(GetPartyOffset(i), SIZE_STORED));
if (partyPK.Species > 0)
partyPL[pSlot++] = partyPK;
}
partyPL.GetBytes().CopyTo(Data, PartyOffset);
setChecksums();
SetChecksums();
if (Version == GameVersion.C && !Japanese)
{
Array.Copy(Data, 0x2009, Data, 0x1209, 0xB7A);
@ -171,7 +172,7 @@ namespace PKHeX.Core
return outData;
}
private void getSAVOffsets()
private void GetSAVOffsets()
{
OptionsOffset = 0x2000;
Trainer1 = 0x2009;
@ -212,7 +213,7 @@ namespace PKHeX.Core
public override SaveFile Clone() { return new SAV2(Write(DSV: false)); }
public override int SIZE_STORED => Japanese ? PKX.SIZE_2JLIST : PKX.SIZE_2ULIST;
public override int SIZE_PARTY => Japanese ? PKX.SIZE_2JLIST : PKX.SIZE_2ULIST;
protected override int SIZE_PARTY => Japanese ? PKX.SIZE_2JLIST : PKX.SIZE_2ULIST;
public override PKM BlankPKM => new PK2(null, null, Japanese);
public override Type PKMType => typeof(PK2);
@ -255,7 +256,7 @@ namespace PKHeX.Core
private int GenderOffset { get; set; } = int.MinValue;
// Checksums
private ushort getChecksum()
private ushort GetChecksum()
{
int end;
switch (Version)
@ -269,9 +270,9 @@ namespace PKHeX.Core
}
return (ushort)Data.Skip(0x2009).Take(end - 0x2009 + 1).Sum(a => a);
}
protected override void setChecksums()
protected override void SetChecksums()
{
ushort accum = getChecksum();
ushort accum = GetChecksum();
if (Version == GameVersion.GS && !Japanese)
{
BitConverter.GetBytes(accum).CopyTo(Data, 0x2D69);
@ -287,7 +288,7 @@ namespace PKHeX.Core
{
get
{
ushort accum = getChecksum();
ushort accum = GetChecksum();
if (Version == GameVersion.GS && !Japanese)
return accum == BitConverter.ToUInt16(Data, 0x2D69); // US Gold/Silver
return accum == BitConverter.ToUInt16(Data, 0x2D0D); // Japanese Crystal
@ -301,8 +302,8 @@ namespace PKHeX.Core
public override string OT
{
get => getString(0x200B, OTLength);
set => setString(value, OTLength).CopyTo(Data, 0x200B);
get => GetString(0x200B, OTLength);
set => SetString(value, OTLength).CopyTo(Data, 0x200B);
}
public override int Gender
{
@ -434,7 +435,7 @@ namespace PKHeX.Core
}
foreach (var p in pouch)
{
p.getPouchG1(ref Data);
p.GetPouchG1(ref Data);
}
return pouch;
}
@ -451,27 +452,27 @@ namespace PKHeX.Core
}
while (ofs < p.Items.Length)
p.Items[ofs++] = new InventoryItem { Count = 0, Index = 0 };
p.setPouchG1(ref Data);
p.SetPouchG1(ref Data);
}
}
}
public override int getDaycareSlotOffset(int loc, int slot)
public override int GetDaycareSlotOffset(int loc, int slot)
{
return Daycare;
}
public override uint? getDaycareEXP(int loc, int slot)
public override uint? GetDaycareEXP(int loc, int slot)
{
return null;
}
public override bool? getDaycareOccupied(int loc, int slot)
public override bool? IsDaycareOccupied(int loc, int slot)
{
return null;
}
public override void setDaycareEXP(int loc, int slot, uint EXP)
public override void SetDaycareEXP(int loc, int slot, uint EXP)
{
}
public override void setDaycareOccupied(int loc, int slot, bool occupied)
public override void SetDaycareOccupied(int loc, int slot, bool occupied)
{
}
@ -481,11 +482,11 @@ namespace PKHeX.Core
{
get => Data[PartyOffset]; protected set => Data[PartyOffset] = (byte)value;
}
public override int getBoxOffset(int box)
public override int GetBoxOffset(int box)
{
return Data.Length - SIZE_RESERVED + box * SIZE_BOX;
}
public override int getPartyOffset(int slot)
public override int GetPartyOffset(int slot)
{
return Data.Length - SIZE_RESERVED + BoxCount * SIZE_BOX + slot * SIZE_STORED;
}
@ -493,37 +494,37 @@ namespace PKHeX.Core
{
get => Data[CurrentBoxIndexOffset] & 0x7F; set => Data[CurrentBoxIndexOffset] = (byte)((Data[Japanese ? 0x2842 : 0x284C] & 0x80) | (value & 0x7F));
}
public override string getBoxName(int box)
public override string GetBoxName(int box)
{
return PKX.getString1(Data, BoxNamesOffset + box*9, 9, Japanese);
return PKX.GetString1(Data, BoxNamesOffset + box*9, 9, Japanese);
}
public override void setBoxName(int box, string value)
public override void SetBoxName(int box, string value)
{
// Don't allow for custom box names
}
public override PKM getPKM(byte[] data)
public override PKM GetPKM(byte[] data)
{
if (data.Length == SIZE_STORED)
return new PokemonList2(data, PokemonList2.CapacityType.Single, Japanese)[0];
return new PK2(data);
}
public override byte[] decryptPKM(byte[] data)
public override byte[] DecryptPKM(byte[] data)
{
return data;
}
// Pokédex
protected override void setDex(PKM pkm)
protected override void SetDex(PKM pkm)
{
int species = pkm.Species;
if (!canSetDex(species))
if (!CanSetDex(species))
return;
setCaught(pkm.Species, true);
setSeen(pkm.Species, true);
SetCaught(pkm.Species, true);
SetSeen(pkm.Species, true);
}
private bool canSetDex(int species)
private bool CanSetDex(int species)
{
if (species <= 0)
return false;
@ -533,7 +534,7 @@ namespace PKHeX.Core
return false;
return true;
}
public override void setSeen(int species, bool seen)
public override void SetSeen(int species, bool seen)
{
int bit = species - 1;
int ofs = bit >> 3;
@ -544,7 +545,7 @@ namespace PKHeX.Core
else
Data[PokedexSeenOffset + ofs] &= (byte)~bitval;
}
public override void setCaught(int species, bool caught)
public override void SetCaught(int species, bool caught)
{
int bit = species - 1;
int ofs = bit >> 3;
@ -566,7 +567,7 @@ namespace PKHeX.Core
for (int i = 1; i <= 26; i++)
Data[PokedexSeenOffset + 0x1F + i] = (byte) i;
}
public override bool getSeen(int species)
public override bool GetSeen(int species)
{
int bit = species - 1;
int ofs = bit >> 3;
@ -574,7 +575,7 @@ namespace PKHeX.Core
// Get the Seen Flag
return (Data[PokedexSeenOffset + ofs] & bitval) != 0;
}
public override bool getCaught(int species)
public override bool GetCaught(int species)
{
int bit = species - 1;
int ofs = bit >> 3;
@ -583,7 +584,7 @@ namespace PKHeX.Core
return (Data[PokedexCaughtOffset + ofs] & bitval) != 0;
}
public override string getString(int Offset, int Count) => PKX.getString1(Data, Offset, Count, Japanese);
public override byte[] setString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0) => PKX.setString1(value, maxLength, Japanese);
public override string GetString(int Offset, int Count) => PKX.GetString1(Data, Offset, Count, Japanese);
public override byte[] SetString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0) => PKX.SetString1(value, maxLength, Japanese);
}
}

View file

@ -46,7 +46,7 @@ namespace PKHeX.Core
Version = GameVersion.FRLG;
else if (versionOverride != GameVersion.Any)
Version = versionOverride;
else Version = SaveUtil.getIsG3SAV(Data);
else Version = SaveUtil.GetIsG3SAV(Data);
if (Version == GameVersion.Invalid)
return;
@ -151,10 +151,10 @@ namespace PKHeX.Core
SeenFlagOffsets = SeenFlagOffsets?.Where(z => z >= 0).ToArray();
if (!Exportable)
resetBoxes();
ClearBoxes();
}
public override byte[] Write(bool DSV)
protected override byte[] Write(bool DSV)
{
// Copy Box data back
for (int i = 5; i < BLOCK_COUNT; i++)
@ -165,7 +165,7 @@ namespace PKHeX.Core
Array.Copy(Data, Box + (i - 5) * 0xF80, Data, blockIndex * SIZE_BLOCK + ABO, chunkLength[i]);
}
setChecksums();
SetChecksums();
return Data.Take(Data.Length - SIZE_RESERVED).ToArray();
}
@ -173,7 +173,7 @@ namespace PKHeX.Core
private int ABO => ActiveSAV*SIZE_BLOCK*0xE;
private readonly int[] BlockOrder;
private readonly int[] BlockOfs;
public int getBlockOffset(int block) => BlockOfs[block];
public int GetBlockOffset(int block) => BlockOfs[block];
// Configuration
public override SaveFile Clone() { return new SAV3(Write(DSV:false), Version) {Japanese = Japanese}; }
@ -181,7 +181,7 @@ namespace PKHeX.Core
public override bool IndeterminateSubVersion => Version == GameVersion.FRLG;
public override int SIZE_STORED => PKX.SIZE_3STORED;
public override int SIZE_PARTY => PKX.SIZE_3PARTY;
protected override int SIZE_PARTY => PKX.SIZE_3PARTY;
public override PKM BlankPKM => new PK3();
public override Type PKMType => typeof(PK3);
@ -203,12 +203,12 @@ namespace PKHeX.Core
public override bool HasParty => true;
// Checksums
protected override void setChecksums()
protected override void SetChecksums()
{
for (int i = 0; i < BLOCK_COUNT; i++)
{
byte[] chunk = Data.Skip(ABO + i*SIZE_BLOCK).Take(chunkLength[BlockOrder[i]]).ToArray();
ushort chk = SaveUtil.check32(chunk);
ushort chk = SaveUtil.CRC32(chunk);
BitConverter.GetBytes(chk).CopyTo(Data, ABO + i*SIZE_BLOCK + 0xFF6);
}
}
@ -219,7 +219,7 @@ namespace PKHeX.Core
for (int i = 0; i < BLOCK_COUNT; i++)
{
byte[] chunk = Data.Skip(ABO + i * SIZE_BLOCK).Take(chunkLength[BlockOrder[i]]).ToArray();
ushort chk = SaveUtil.check32(chunk);
ushort chk = SaveUtil.CRC32(chunk);
if (chk != BitConverter.ToUInt16(Data, ABO + i*SIZE_BLOCK + 0xFF6))
return false;
}
@ -234,7 +234,7 @@ namespace PKHeX.Core
for (int i = 0; i < BLOCK_COUNT; i++)
{
byte[] chunk = Data.Skip(ABO + i * SIZE_BLOCK).Take(chunkLength[BlockOrder[i]]).ToArray();
ushort chk = SaveUtil.check32(chunk);
ushort chk = SaveUtil.CRC32(chunk);
ushort old = BitConverter.ToUInt16(Data, ABO + i*SIZE_BLOCK + 0xFF6);
if (chk != old)
r += $"Block {BlockOrder[i]:00} @ {i*SIZE_BLOCK:X5} invalid." + Environment.NewLine;
@ -260,8 +260,8 @@ namespace PKHeX.Core
}
public override string OT
{
get => getString(BlockOfs[0], 0x10);
set => setString(value, 7).CopyTo(Data, BlockOfs[0]);
get => GetString(BlockOfs[0], 0x10);
set => SetString(value, 7).CopyTo(Data, BlockOfs[0]);
}
public override int Gender
{
@ -398,36 +398,36 @@ namespace PKHeX.Core
{
if (p.Type != InventoryType.PCItems)
p.SecurityKey = SecurityKey;
p.getPouch(ref Data);
p.GetPouch(ref Data);
}
return pouch;
}
set
{
foreach (var p in value)
p.setPouch(ref Data);
p.SetPouch(ref Data);
}
}
public override int getDaycareSlotOffset(int loc, int slot)
public override int GetDaycareSlotOffset(int loc, int slot)
{
return Daycare + slot * SIZE_PARTY;
}
public override uint? getDaycareEXP(int loc, int slot)
public override uint? GetDaycareEXP(int loc, int slot)
{
int ofs = Daycare + (slot + 1) * SIZE_PARTY - 4;
return BitConverter.ToUInt32(Data, ofs);
}
public override bool? getDaycareOccupied(int loc, int slot)
public override bool? IsDaycareOccupied(int loc, int slot)
{
return null;
}
public override void setDaycareEXP(int loc, int slot, uint EXP)
public override void SetDaycareEXP(int loc, int slot, uint EXP)
{
int ofs = Daycare + (slot + 1) * SIZE_PARTY - 4;
BitConverter.GetBytes(EXP).CopyTo(Data, ofs);
}
public override void setDaycareOccupied(int loc, int slot, bool occupied)
public override void SetDaycareOccupied(int loc, int slot, bool occupied)
{
}
@ -451,11 +451,11 @@ namespace PKHeX.Core
Data[BlockOfs[1] + ofs] = (byte)value;
}
}
public override int getBoxOffset(int box)
public override int GetBoxOffset(int box)
{
return Box + 4 + SIZE_STORED * box * 30;
}
public override int getPartyOffset(int slot)
public override int GetPartyOffset(int slot)
{
int ofs = 0x38;
if (GameVersion.FRLG != Version)
@ -467,44 +467,44 @@ namespace PKHeX.Core
get => Data[Box];
set => Data[Box] = (byte)value;
}
protected override int getBoxWallpaperOffset(int box)
protected override int GetBoxWallpaperOffset(int box)
{
int offset = getBoxOffset(BoxCount);
int offset = GetBoxOffset(BoxCount);
offset += BoxCount * 0x9 + box;
return offset;
}
public override string getBoxName(int box)
public override string GetBoxName(int box)
{
int offset = getBoxOffset(BoxCount);
return PKX.getString3(Data, offset + box * 9, 9, Japanese);
int offset = GetBoxOffset(BoxCount);
return PKX.GetString3(Data, offset + box * 9, 9, Japanese);
}
public override void setBoxName(int box, string value)
public override void SetBoxName(int box, string value)
{
int offset = getBoxOffset(BoxCount);
setString(value, 8).CopyTo(Data, offset + box * 9);
int offset = GetBoxOffset(BoxCount);
SetString(value, 8).CopyTo(Data, offset + box * 9);
}
public override PKM getPKM(byte[] data)
public override PKM GetPKM(byte[] data)
{
return new PK3(data);
}
public override byte[] decryptPKM(byte[] data)
public override byte[] DecryptPKM(byte[] data)
{
return PKX.decryptArray3(data);
return PKX.DecryptArray3(data);
}
// Pokédex
private readonly int[] SeenFlagOffsets;
public override bool HasPokeDex => true;
protected override void setDex(PKM pkm)
protected override void SetDex(PKM pkm)
{
int species = pkm.Species;
if (!canSetDex(species))
if (!CanSetDex(species))
return;
setCaught(pkm.Species, true);
setSeen(pkm.Species, true);
SetCaught(pkm.Species, true);
SetSeen(pkm.Species, true);
}
private bool canSetDex(int species)
private bool CanSetDex(int species)
{
if (species <= 0)
return false;
@ -517,7 +517,7 @@ namespace PKHeX.Core
return true;
}
public override bool getCaught(int species)
public override bool GetCaught(int species)
{
int bit = species - 1;
int ofs = bit >> 3;
@ -527,7 +527,7 @@ namespace PKHeX.Core
return (Data[caughtOffset] & bitval) != 0;
}
public override void setCaught(int species, bool caught)
public override void SetCaught(int species, bool caught)
{
int bit = species - 1;
int ofs = bit / 8;
@ -540,7 +540,7 @@ namespace PKHeX.Core
Data[caughtOffset] &= (byte)~bitval;
}
public override bool getSeen(int species)
public override bool GetSeen(int species)
{
int bit = species - 1;
int ofs = bit >> 3;
@ -549,7 +549,7 @@ namespace PKHeX.Core
int seenOffset = BlockOfs[0] + 0x5C + ofs;
return (Data[seenOffset] & bitval) != 0;
}
public override void setSeen(int species, bool seen)
public override void SetSeen(int species, bool seen)
{
int bit = species - 1;
int ofs = bit / 8;
@ -610,12 +610,12 @@ namespace PKHeX.Core
}
}
}
public override string getString(int Offset, int Count) => PKX.getString3(Data, Offset, Count, Japanese);
public override byte[] setString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
public override string GetString(int Offset, int Count) => PKX.GetString3(Data, Offset, Count, Japanese);
public override byte[] SetString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
{
if (PadToSize == 0)
PadToSize = maxLength + 1;
return PKX.setString3(value, maxLength, Japanese, PadToSize, PadWith);
return PKX.SetString3(value, maxLength, Japanese, PadToSize, PadWith);
}
#region eBerry
@ -624,32 +624,32 @@ namespace PKHeX.Core
private const int SIZE_EBERRY = 0x530;
private const int OFFSET_EBERRY = 0x2E0;
private uint eBerryChecksum => BitConverter.ToUInt32(Data, BlockOfs[4] + OFFSET_EBERRY + SIZE_EBERRY - 4);
private bool eBerryChecksumValid { get; set; }
private uint EBerryChecksum => BitConverter.ToUInt32(Data, BlockOfs[4] + OFFSET_EBERRY + SIZE_EBERRY - 4);
private bool IsEBerryChecksumValid { get; set; }
public override string eBerryName
public override string EBerryName
{
get
{
if (!GameVersion.RS.Contains(Version) || !eBerryChecksumValid)
if (!GameVersion.RS.Contains(Version) || !IsEBerryChecksumValid)
return string.Empty;
return PKX.getString3(Data, BlockOfs[4] + OFFSET_EBERRY, 7, Japanese).Trim();
return PKX.GetString3(Data, BlockOfs[4] + OFFSET_EBERRY, 7, Japanese).Trim();
}
}
public override bool eBerryIsEnigma => string.IsNullOrEmpty(eBerryName.Trim());
public override bool IsEBerryIsEnigma => string.IsNullOrEmpty(EBerryName.Trim());
private void LoadEReaderBerryData()
{
if (!GameVersion.RS.Contains(Version))
return;
byte[] data = getData(BlockOfs[4] + OFFSET_EBERRY, SIZE_EBERRY - 4);
byte[] data = GetData(BlockOfs[4] + OFFSET_EBERRY, SIZE_EBERRY - 4);
// 8 bytes are 0x00 for chk calculation
for (int i = 0; i < 8; i++)
data[0xC + i] = 0x00;
uint chk = (uint)data.Sum(z => z);
eBerryChecksumValid = eBerryChecksum == chk;
IsEBerryChecksumValid = EBerryChecksum == chk;
}
#endregion
@ -676,15 +676,15 @@ namespace PKHeX.Core
{
if (FRLG)
return null;
int block0 = getBlockOffset(0);
return new RTC3(getData(block0 + 0x98, 8));
int block0 = GetBlockOffset(0);
return new RTC3(GetData(block0 + 0x98, 8));
}
set
{
if (value?.Data == null || FRLG)
return;
int block0 = getBlockOffset(0);
setData(value.Data, block0 + 0x98);
int block0 = GetBlockOffset(0);
SetData(value.Data, block0 + 0x98);
}
}
public RTC3 ClockElapsed
@ -693,15 +693,15 @@ namespace PKHeX.Core
{
if (FRLG)
return null;
int block0 = getBlockOffset(0);
return new RTC3(getData(block0 + 0xA0, 8));
int block0 = GetBlockOffset(0);
return new RTC3(GetData(block0 + 0xA0, 8));
}
set
{
if (value?.Data == null || FRLG)
return;
int block0 = getBlockOffset(0);
setData(value.Data, block0 + 0xA0);
int block0 = GetBlockOffset(0);
SetData(value.Data, block0 + 0xA0);
}
}
}

View file

@ -39,7 +39,7 @@ namespace PKHeX.Core
private readonly ushort[] LegalItems, LegalKeyItems, LegalBalls, LegalTMHMs, LegalBerries, LegalCologne;
private readonly int OFS_PouchCologne;
private readonly SAV3GCMemoryCard MC;
public override bool IsMemoryCardSave => MC != null;
private bool IsMemoryCardSave => MC != null;
public SAV3Colosseum(byte[] data, SAV3GCMemoryCard MC) : this(data) { this.MC = MC; BAK = MC.Data; }
public SAV3Colosseum(byte[] data = null)
{
@ -47,7 +47,7 @@ namespace PKHeX.Core
BAK = (byte[])Data.Clone();
Exportable = !Data.SequenceEqual(new byte[Data.Length]);
if (SaveUtil.getIsG3COLOSAV(Data) != GameVersion.COLO)
if (SaveUtil.GetIsG3COLOSAV(Data) != GameVersion.COLO)
return;
OriginalData = (byte[])Data.Clone();
@ -101,12 +101,12 @@ namespace PKHeX.Core
HeldItems = Legal.HeldItems_COLO;
if (!Exportable)
resetBoxes();
ClearBoxes();
// Since PartyCount is not stored in the save file,
// Count up how many party slots are active.
for (int i = 0; i < 6; i++)
if (getPartySlot(getPartyOffset(i)).Species != 0)
if (GetPartySlot(GetPartyOffset(i)).Species != 0)
PartyCount++;
}
@ -114,7 +114,7 @@ namespace PKHeX.Core
public override byte[] Write(bool DSV, bool GCI)
{
StrategyMemo.FinalData.CopyTo(Data, Memo);
setChecksums();
SetChecksums();
// Get updated save slot data
byte[] digest = Data.Skip(Data.Length - 20).Take(20).ToArray();
@ -136,12 +136,11 @@ namespace PKHeX.Core
public override SaveFile Clone()
{
byte[] data = Write(DSV: false, GCI: true).Skip(Header.Length).ToArray();
var sav = new SAV3Colosseum(data) { Header = (byte[])Header.Clone() };
return sav;
return new SAV3Colosseum(data) { Header = (byte[])Header.Clone() };
}
public override int SIZE_STORED => PKX.SIZE_3CSTORED;
public override int SIZE_PARTY => PKX.SIZE_3CSTORED; // unused
protected override int SIZE_PARTY => PKX.SIZE_3CSTORED; // unused
public override PKM BlankPKM => new CK3();
public override Type PKMType => typeof(CK3);
@ -163,7 +162,7 @@ namespace PKHeX.Core
// Checksums
private readonly SHA1 sha1 = SHA1.Create();
public void Dispose() => sha1.Dispose();
public void Dispose() => sha1?.Dispose();
private byte[] EncryptColosseum(byte[] input, byte[] digest)
{
if (input.Length != SLOT_SIZE)
@ -205,7 +204,7 @@ namespace PKHeX.Core
}
return d;
}
protected override void setChecksums()
protected override void SetChecksums()
{
// Clear Header Checksum
BitConverter.GetBytes(0).CopyTo(Data, 12);
@ -272,32 +271,32 @@ namespace PKHeX.Core
public override GameVersion Version { get => GameVersion.COLO; protected set { } }
// Storage
public override int getPartyOffset(int slot)
public override int GetPartyOffset(int slot)
{
return Party + SIZE_STORED * slot;
}
public override int getBoxOffset(int box)
public override int GetBoxOffset(int box)
{
return Box + (30 * SIZE_STORED + 0x14)*box + 0x14;
}
public override string getBoxName(int box)
public override string GetBoxName(int box)
{
return getString(Box + 0x24A4*box, 16);
return GetString(Box + 0x24A4*box, 16);
}
public override void setBoxName(int box, string value)
public override void SetBoxName(int box, string value)
{
setString(value, 8).CopyTo(Data, Box + 0x24A4*box);
SetString(value, 8).CopyTo(Data, Box + 0x24A4*box);
}
public override PKM getPKM(byte[] data)
public override PKM GetPKM(byte[] data)
{
return new CK3(data.Take(SIZE_STORED).ToArray());
}
public override byte[] decryptPKM(byte[] data)
public override byte[] DecryptPKM(byte[] data)
{
return data;
}
protected override void setPKM(PKM pkm)
protected override void SetPKM(PKM pkm)
{
var pk = pkm as CK3;
if (pk == null)
@ -308,7 +307,7 @@ namespace PKHeX.Core
if (pk.OriginalRegion == 0)
pk.OriginalRegion = 2; // NTSC-U
}
protected override void setDex(PKM pkm)
protected override void SetDex(PKM pkm)
{
// Dex Related
var entry = StrategyMemo.GetEntry(pkm.Species);
@ -349,15 +348,15 @@ namespace PKHeX.Core
}
// Trainer Info (offset 0x78, length 0xB18, end @ 0xB90)
public override string OT { get => getString(0x78, 20); set { setString(value, 10).CopyTo(Data, 0x78); OT2 = value; } }
private string OT2 { get => getString(0x8C, 20); set => setString(value, 10).CopyTo(Data, 0x8C); }
public override string OT { get => GetString(0x78, 20); set { SetString(value, 10).CopyTo(Data, 0x78); OT2 = value; } }
private string OT2 { get => GetString(0x8C, 20); set => SetString(value, 10).CopyTo(Data, 0x8C); }
public override ushort SID { get => BigEndian.ToUInt16(Data, 0xA4); set => BigEndian.GetBytes(value).CopyTo(Data, 0xA4); }
public override ushort TID { get => BigEndian.ToUInt16(Data, 0xA6); set => BigEndian.GetBytes(value).CopyTo(Data, 0xA6); }
public override int Gender { get => Data[0xAF8]; set => Data[0xAF8] = (byte)value; }
public override uint Money { get => BigEndian.ToUInt32(Data, 0xAFC); set => BigEndian.GetBytes(value).CopyTo(Data, 0xAFC); }
public uint Coupons { get => BigEndian.ToUInt32(Data, 0xB00); set => BigEndian.GetBytes(value).CopyTo(Data, 0xB00); }
public string RUI_Name { get => getString(0xB3A, 20); set => setString(value, 10).CopyTo(Data, 0xB3A); }
public string RUI_Name { get => GetString(0xB3A, 20); set => SetString(value, 10).CopyTo(Data, 0xB3A); }
public override InventoryPouch[] Inventory
{
@ -373,13 +372,13 @@ namespace PKHeX.Core
new InventoryPouch(InventoryType.Medicine, LegalCologne, 999, OFS_PouchCologne, 3), // Cologne
};
foreach (var p in pouch)
p.getPouchBigEndian(ref Data);
p.GetPouchBigEndian(ref Data);
return pouch;
}
set
{
foreach (var p in value)
p.setPouchBigEndian(ref Data);
p.SetPouchBigEndian(ref Data);
}
}
@ -388,18 +387,18 @@ namespace PKHeX.Core
// 0x01 -- Deposited Level
// 0x02-0x03 -- unused?
// 0x04-0x07 -- Initial EXP
public override int getDaycareSlotOffset(int loc, int slot) { return Daycare + 8; }
public override uint? getDaycareEXP(int loc, int slot) { return null; }
public override bool? getDaycareOccupied(int loc, int slot) { return null; }
public override void setDaycareEXP(int loc, int slot, uint EXP) { }
public override void setDaycareOccupied(int loc, int slot, bool occupied) { }
public override int GetDaycareSlotOffset(int loc, int slot) { return Daycare + 8; }
public override uint? GetDaycareEXP(int loc, int slot) { return null; }
public override bool? IsDaycareOccupied(int loc, int slot) { return null; }
public override void SetDaycareEXP(int loc, int slot, uint EXP) { }
public override void SetDaycareOccupied(int loc, int slot, bool occupied) { }
public override string getString(int Offset, int Count) => PKX.getBEString3(Data, Offset, Count);
public override byte[] setString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
public override string GetString(int Offset, int Count) => PKX.GetBEString3(Data, Offset, Count);
public override byte[] SetString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
{
if (PadToSize == 0)
PadToSize = maxLength + 1;
return PKX.setBEString3(value, maxLength, PadToSize, PadWith);
return PKX.SetBEString3(value, maxLength, PadToSize, PadWith);
}
}
}

View file

@ -58,7 +58,7 @@ namespace PKHeX.Core
private static int BlockAllocBAK => BLOCK_SIZE * BlockAlloc_Block;
// Checksums
private void getChecksum(int block, int offset, int length, out ushort csum, out ushort inv_csum)
private void GetChecksum(int block, int offset, int length, out ushort csum, out ushort inv_csum)
{
csum = inv_csum = 0;
var ofs = block * BLOCK_SIZE + offset;
@ -74,28 +74,27 @@ namespace PKHeX.Core
if (inv_csum == 0xffff)
inv_csum = 0;
}
private uint verifyChecksums()
private uint VerifyChecksums()
{
ushort csum, csum_inv;
uint results = 0;
getChecksum(Header_Block, 0, 0xFE, out csum, out csum_inv);
GetChecksum(Header_Block, 0, 0xFE, out ushort csum, out ushort csum_inv);
if (Header_Checksum != csum || (Header_Checksum_Inv != csum_inv))
results |= 1;
getChecksum(Directory_Block, 0, 0xFFE, out csum, out csum_inv);
GetChecksum(Directory_Block, 0, 0xFFE, out csum, out csum_inv);
if (Directory_Checksum != csum || (Directory_Checksum_Inv != csum_inv))
results |= 2;
getChecksum(DirectoryBackup_Block, 0, 0xFFE, out csum, out csum_inv);
GetChecksum(DirectoryBackup_Block, 0, 0xFFE, out csum, out csum_inv);
if (DirectoryBAK_Checksum != csum || (DirectoryBAK_Checksum_Inv != csum_inv))
results |= 4;
getChecksum(BlockAlloc_Block, 4, 0xFFE, out csum, out csum_inv);
GetChecksum(BlockAlloc_Block, 4, 0xFFE, out csum, out csum_inv);
if (BlockAlloc_Checksum != csum || (BlockAlloc_Checksum_Inv != csum_inv))
results |= 8;
getChecksum(BlockAllocBackup_Block, 4, 0xFFE, out csum, out csum_inv);
GetChecksum(BlockAllocBackup_Block, 4, 0xFFE, out csum, out csum_inv);
if ((BlockAllocBAK_Checksum != csum) || BlockAllocBAK_Checksum_Inv != csum_inv)
results |= 16;
@ -140,7 +139,7 @@ namespace PKHeX.Core
private bool IsCorruptedMemoryCard()
{
uint csums = verifyChecksums();
uint csums = VerifyChecksums();
if ((csums & 0x1) == 1) // Header checksum failed
return true;
@ -150,8 +149,8 @@ namespace PKHeX.Core
if ((csums & 0x4) == 1) // backup is also wrong
return true; // Directory checksum and directory backup checksum failed
restoreBackup(); // backup is correct, restore
csums = verifyChecksums(); // update checksums
RestoreBackup(); // backup is correct, restore
csums = VerifyChecksums(); // update checksums
}
if ((csums & 0x8) != 1)
@ -160,10 +159,10 @@ namespace PKHeX.Core
return true;
// backup is correct, restore
restoreBackup();
RestoreBackup();
return false;
}
private void restoreBackup()
private void RestoreBackup()
{
Array.Copy(Data, DirectoryBackup_Block*BLOCK_SIZE, Data, Directory_Block*BLOCK_SIZE, BLOCK_SIZE);
Array.Copy(Data, BlockAllocBackup_Block*BLOCK_SIZE, Data, BlockAlloc_Block*BLOCK_SIZE, BLOCK_SIZE);
@ -270,11 +269,11 @@ namespace PKHeX.Core
}
}
public string GCISaveName => getGCISaveGameName();
public string GCISaveName => GCISaveGameName();
public byte[] SelectedSaveData { get => ReadSaveGameData(); set => WriteSaveGameData(value); }
public byte[] Data { get; private set; }
private string getGCISaveGameName()
private string GCISaveGameName()
{
int offset = DirectoryBlock_Used*BLOCK_SIZE + EntrySelected*DENTRY_SIZE;
string GameCode = EncodingType.GetString(Data, offset, 4);

View file

@ -17,7 +17,7 @@ namespace PKHeX.Core
}
public override string Extension => IsMemoryCardSave ? ".raw" : ".gci";
private readonly SAV3GCMemoryCard MC;
public override bool IsMemoryCardSave => MC != null;
private bool IsMemoryCardSave => MC != null;
public SAV3RSBox(byte[] data, SAV3GCMemoryCard MC) : this(data) { this.MC = MC; BAK = MC.Data; }
public SAV3RSBox(byte[] data = null)
{
@ -25,14 +25,14 @@ namespace PKHeX.Core
BAK = (byte[])Data.Clone();
Exportable = !Data.SequenceEqual(new byte[Data.Length]);
if (SaveUtil.getIsG3BOXSAV(Data) != GameVersion.RSBOX)
if (SaveUtil.GetIsG3BOXSAV(Data) != GameVersion.RSBOX)
return;
Blocks = new RSBOX_Block[2*BLOCK_COUNT];
for (int i = 0; i < Blocks.Length; i++)
{
int offset = BLOCK_SIZE + i* BLOCK_SIZE;
Blocks[i] = new RSBOX_Block(getData(offset, BLOCK_SIZE), offset);
Blocks[i] = new RSBOX_Block(GetData(offset, BLOCK_SIZE), offset);
}
// Detect active save
@ -53,7 +53,7 @@ namespace PKHeX.Core
HeldItems = Legal.HeldItems_RS;
if (!Exportable)
resetBoxes();
ClearBoxes();
}
private readonly RSBOX_Block[] Blocks;
@ -67,12 +67,12 @@ namespace PKHeX.Core
foreach (RSBOX_Block b in Blocks)
Array.Copy(Data, (int)(Box + b.BlockNumber * (BLOCK_SIZE - 0x10)), b.Data, 0xC, b.Data.Length - 0x10);
setChecksums();
SetChecksums();
// Set Data Back
foreach (RSBOX_Block b in Blocks)
b.Data.CopyTo(Data, b.Offset);
byte[] newFile = getData(0, Data.Length - SIZE_RESERVED);
byte[] newFile = GetData(0, Data.Length - SIZE_RESERVED);
// Return the gci if Memory Card is not being exported
if (!IsMemoryCardSave || GCI)
@ -91,7 +91,7 @@ namespace PKHeX.Core
}
public override int SIZE_STORED => PKX.SIZE_3STORED + 4;
public override int SIZE_PARTY => PKX.SIZE_3PARTY; // unused
protected override int SIZE_PARTY => PKX.SIZE_3PARTY; // unused
public override PKM BlankPKM => new PK3();
public override Type PKMType => typeof(PK3);
@ -114,7 +114,7 @@ namespace PKHeX.Core
public override bool HasParty => false;
// Checksums
protected override void setChecksums()
protected override void SetChecksums()
{
foreach (RSBOX_Block b in Blocks)
b.SetChecksums();
@ -136,20 +136,20 @@ namespace PKHeX.Core
public override GameVersion Version { get => GameVersion.RSBOX; protected set { } }
// Storage
public override int getPartyOffset(int slot) => -1;
public override int getBoxOffset(int box) => Box + 8 + SIZE_STORED * box * 30;
public override int GetPartyOffset(int slot) => -1;
public override int GetBoxOffset(int box) => Box + 8 + SIZE_STORED * box * 30;
public override int CurrentBox
{
get => Data[Box + 4] * 2;
set => Data[Box + 4] = (byte)(value / 2);
}
protected override int getBoxWallpaperOffset(int box)
protected override int GetBoxWallpaperOffset(int box)
{
// Box Wallpaper is directly after the Box Names
int offset = Box + 0x1ED19 + box/2;
return offset;
}
public override string getBoxName(int box)
public override string GetBoxName(int box)
{
// Tweaked for the 1-30/31-60 box showing
int lo = 30*(box%2) + 1;
@ -160,54 +160,54 @@ namespace PKHeX.Core
int offset = Box + 0x1EC38 + 9 * box;
if (Data[offset] == 0 || Data[offset] == 0xFF)
boxName += $"BOX {box + 1}";
boxName += getString(offset, 9);
boxName += GetString(offset, 9);
return boxName;
}
public override void setBoxName(int box, string value)
public override void SetBoxName(int box, string value)
{
int offset = Box + 0x1EC38 + 9 * box;
byte[] data = value == $"BOX {box + 1}" ? new byte[9] : setString(value, 8);
setData(data, offset);
byte[] data = value == $"BOX {box + 1}" ? new byte[9] : SetString(value, 8);
SetData(data, offset);
}
public override PKM getPKM(byte[] data)
public override PKM GetPKM(byte[] data)
{
if (data.Length != PKX.SIZE_3STORED)
Array.Resize(ref data, PKX.SIZE_3STORED);
return new PK3(data);
}
public override byte[] decryptPKM(byte[] data)
public override byte[] DecryptPKM(byte[] data)
{
if (data.Length != PKX.SIZE_3STORED)
Array.Resize(ref data, PKX.SIZE_3STORED);
return PKX.decryptArray3(data);
return PKX.DecryptArray3(data);
}
protected override void setDex(PKM pkm) { }
protected override void SetDex(PKM pkm) { }
public override void setStoredSlot(PKM pkm, int offset, bool? trade = null, bool? dex = null)
public override void SetStoredSlot(PKM pkm, int offset, bool? trade = null, bool? dex = null)
{
if (pkm == null) return;
if (pkm.GetType() != PKMType)
throw new InvalidCastException($"PKM Format needs to be {PKMType} when setting to a Gen{Generation} Save File.");
if (trade ?? SetUpdatePKM)
setPKM(pkm);
SetPKM(pkm);
if (dex ?? SetUpdateDex)
setDex(pkm);
SetDex(pkm);
byte[] data = pkm.EncryptedBoxData;
setData(data, offset);
SetData(data, offset);
BitConverter.GetBytes((ushort)pkm.TID).CopyTo(Data, offset + data.Length + 0);
BitConverter.GetBytes((ushort)pkm.SID).CopyTo(Data, offset + data.Length + 2);
Edited = true;
}
public override string getString(int Offset, int Count) => PKX.getString3(Data, Offset, Count, Japanese);
public override byte[] setString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
public override string GetString(int Offset, int Count) => PKX.GetString3(Data, Offset, Count, Japanese);
public override byte[] SetString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
{
if (PadToSize == 0)
PadToSize = maxLength + 1;
return PKX.setString3(value, maxLength, Japanese, PadToSize, PadWith);
return PKX.SetString3(value, maxLength, Japanese, PadToSize, PadWith);
}
}
}

View file

@ -31,7 +31,7 @@ namespace PKHeX.Core
private readonly int OFS_PouchCologne, OFS_PouchDisc;
private readonly int[] subOffsets = new int[16];
private readonly SAV3GCMemoryCard MC;
public override bool IsMemoryCardSave => MC != null;
private bool IsMemoryCardSave => MC != null;
public SAV3XD(byte[] data, SAV3GCMemoryCard MC) : this(data) { this.MC = MC; BAK = MC.Data; }
public SAV3XD(byte[] data = null)
{
@ -39,7 +39,7 @@ namespace PKHeX.Core
BAK = (byte[])Data.Clone();
Exportable = !Data.SequenceEqual(new byte[Data.Length]);
if (SaveUtil.getIsG3XDSAV(Data) != GameVersion.XD)
if (SaveUtil.GetIsG3XDSAV(Data) != GameVersion.XD)
return;
OriginalData = (byte[])Data.Clone();
@ -109,12 +109,12 @@ namespace PKHeX.Core
HeldItems = Legal.HeldItems_XD;
if (!Exportable)
resetBoxes();
ClearBoxes();
// Since PartyCount is not stored in the save file,
// Count up how many party slots are active.
for (int i = 0; i < 6; i++)
if (getPartySlot(getPartyOffset(i)).Species != 0)
if (GetPartySlot(GetPartyOffset(i)).Species != 0)
PartyCount++;
}
@ -124,7 +124,7 @@ namespace PKHeX.Core
// Set Memo Back
StrategyMemo.FinalData.CopyTo(Data, Memo);
ShadowInfo.FinalData.CopyTo(Data, Shadow);
setChecksums();
SetChecksums();
// Get updated save slot data
ushort[] keys = new ushort[4];
@ -153,7 +153,7 @@ namespace PKHeX.Core
}
public override int SIZE_STORED => PKX.SIZE_3XSTORED;
public override int SIZE_PARTY => PKX.SIZE_3XSTORED; // unused
protected override int SIZE_PARTY => PKX.SIZE_3XSTORED; // unused
public override PKM BlankPKM => new XK3();
public override Type PKMType => typeof(XK3);
@ -174,16 +174,16 @@ namespace PKHeX.Core
public override int BoxCount => 8;
// Checksums
protected override void setChecksums()
protected override void SetChecksums()
{
Data = setXDChecksums(Data, subOffsets[0]);
Data = SetChecksums(Data, subOffsets[0]);
}
public override bool ChecksumsValid => !ChecksumInfo.Contains("Invalid");
public override string ChecksumInfo
{
get
{
byte[] data = setXDChecksums(Data, subOffsets[0]);
byte[] data = SetChecksums(Data, subOffsets[0]);
const int start = 0xA8; // 0x88 + 0x20
int oldHC = BigEndian.ToInt32(Data, start + subOffsets[0] + 0x38);
@ -196,7 +196,7 @@ namespace PKHeX.Core
return $"Header Checksum {(header ? "V" : "Inv")}alid, Body Checksum {(body ? "V" : "Inv")}alid.";
}
}
private static byte[] setXDChecksums(byte[] input, int subOffset0)
private static byte[] SetChecksums(byte[] input, int subOffset0)
{
if (input.Length != 0x28000)
throw new ArgumentException("Input should be a slot, not the entire save binary.");
@ -234,7 +234,7 @@ namespace PKHeX.Core
}
// Trainer Info
public override GameVersion Version { get => GameVersion.XD; protected set { } }
public override string OT { get => getString(Trainer1 + 0x00, 20); set => setString(value, 10).CopyTo(Data, Trainer1 + 0x00); }
public override string OT { get => GetString(Trainer1 + 0x00, 20); set => SetString(value, 10).CopyTo(Data, Trainer1 + 0x00); }
public override ushort SID { get => BigEndian.ToUInt16(Data, Trainer1 + 0x2C); set => BigEndian.GetBytes(value).CopyTo(Data, Trainer1 + 0x2C); }
public override ushort TID { get => BigEndian.ToUInt16(Data, Trainer1 + 0x2E); set => BigEndian.GetBytes(value).CopyTo(Data, Trainer1 + 0x2E); }
@ -243,46 +243,46 @@ namespace PKHeX.Core
public uint Coupons { get => BigEndian.ToUInt32(Data, Trainer1 + 0x8E8); set => BigEndian.GetBytes(value).CopyTo(Data, Trainer1 + 0x8E8); }
// Storage
public override int getPartyOffset(int slot)
public override int GetPartyOffset(int slot)
{
return Party + SIZE_STORED * slot;
}
public override int getBoxOffset(int box)
public override int GetBoxOffset(int box)
{
return Box + (30 * SIZE_STORED + 0x14)*box + 0x14;
}
public override string getBoxName(int box)
public override string GetBoxName(int box)
{
return getString(Box + (30 * SIZE_STORED + 0x14)*box, 16);
return GetString(Box + (30 * SIZE_STORED + 0x14)*box, 16);
}
public override void setBoxName(int box, string value)
public override void SetBoxName(int box, string value)
{
if (value.Length > 8)
value = value.Substring(0, 8); // Hard cap
setString(value, 8).CopyTo(Data, Box + 0x24A4*box);
SetString(value, 8).CopyTo(Data, Box + 0x24A4*box);
}
public override PKM getPKM(byte[] data)
public override PKM GetPKM(byte[] data)
{
return new XK3(data.Take(SIZE_STORED).ToArray());
}
public override byte[] decryptPKM(byte[] data)
public override byte[] DecryptPKM(byte[] data)
{
return data;
}
public override PKM getPartySlot(int offset)
public override PKM GetPartySlot(int offset)
{
return getStoredSlot(offset);
return GetStoredSlot(offset);
}
public override PKM getStoredSlot(int offset)
public override PKM GetStoredSlot(int offset)
{
// Get Shadow Data
var pk = getPKM(decryptPKM(getData(offset, SIZE_STORED))) as XK3;
var pk = GetPKM(DecryptPKM(GetData(offset, SIZE_STORED))) as XK3;
if (pk?.ShadowID > 0 && pk.ShadowID < ShadowInfo.Count)
pk.Purification = ShadowInfo[pk.ShadowID - 1].Purification;
return pk;
}
protected override void setPKM(PKM pkm)
protected override void SetPKM(PKM pkm)
{
XK3 pk = pkm as XK3;
if (pk == null)
@ -304,7 +304,7 @@ namespace PKHeX.Core
entry.IsPurified = pk.Purification == 0;
}
protected override void setDex(PKM pkm)
protected override void SetDex(PKM pkm)
{
// Dex Related
var entry = StrategyMemo.GetEntry(pkm.Species);
@ -338,13 +338,13 @@ namespace PKHeX.Core
new InventoryPouch(InventoryType.BattleItems, LegalDisc, 999, OFS_PouchDisc, 60)
};
foreach (var p in pouch)
p.getPouchBigEndian(ref Data);
p.GetPouchBigEndian(ref Data);
return pouch;
}
set
{
foreach (var p in value)
p.setPouchBigEndian(ref Data);
p.SetPouchBigEndian(ref Data);
}
}
@ -353,18 +353,18 @@ namespace PKHeX.Core
// 0x01 -- Deposited Level
// 0x02-0x03 -- unused?
// 0x04-0x07 -- Initial EXP
public override int getDaycareSlotOffset(int loc, int slot) { return Daycare + 8; }
public override uint? getDaycareEXP(int loc, int slot) { return null; }
public override bool? getDaycareOccupied(int loc, int slot) { return null; }
public override void setDaycareEXP(int loc, int slot, uint EXP) { }
public override void setDaycareOccupied(int loc, int slot, bool occupied) { }
public override int GetDaycareSlotOffset(int loc, int slot) { return Daycare + 8; }
public override uint? GetDaycareEXP(int loc, int slot) { return null; }
public override bool? IsDaycareOccupied(int loc, int slot) { return null; }
public override void SetDaycareEXP(int loc, int slot, uint EXP) { }
public override void SetDaycareOccupied(int loc, int slot, bool occupied) { }
public override string getString(int Offset, int Count) => PKX.getBEString3(Data, Offset, Count);
public override byte[] setString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
public override string GetString(int Offset, int Count) => PKX.GetBEString3(Data, Offset, Count);
public override byte[] SetString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
{
if (PadToSize == 0)
PadToSize = maxLength + 1;
return PKX.setBEString3(value, maxLength, PadToSize, PadWith);
return PKX.SetBEString3(value, maxLength, PadToSize, PadWith);
}
}
}

View file

@ -19,13 +19,13 @@ namespace PKHeX.Core
Version = GameVersion.HGSS;
else if (versionOverride != GameVersion.Any)
Version = versionOverride;
else Version = SaveUtil.getIsG4SAV(Data);
else Version = SaveUtil.GetIsG4SAV(Data);
if (Version == GameVersion.Invalid)
return;
getActiveGeneralBlock();
getActiveStorageBlock();
getSAVOffsets();
GetActiveGeneralBlock();
GetActiveStorageBlock();
GetSAVOffsets();
switch (Version)
{
@ -35,14 +35,14 @@ namespace PKHeX.Core
}
if (!Exportable)
resetBoxes();
ClearBoxes();
}
// Configuration
public override SaveFile Clone() { return new SAV4(Data, Version); }
public override int SIZE_STORED => PKX.SIZE_4STORED;
public override int SIZE_PARTY => PKX.SIZE_4PARTY;
protected override int SIZE_PARTY => PKX.SIZE_4PARTY;
public override PKM BlankPKM => new PK4();
public override Type PKMType => typeof(PK4);
@ -64,7 +64,7 @@ namespace PKHeX.Core
public override int MaxGameID => 15; // Colo/XD
// Checksums
private static int[][] getCHKOffsets(GameVersion g)
private static int[][] GetChecksumOffsets(GameVersion g)
{
// start, end, chkoffset
switch (g)
@ -80,26 +80,26 @@ namespace PKHeX.Core
return null;
}
}
protected override void setChecksums()
protected override void SetChecksums()
{
int[][] c = getCHKOffsets(Version);
int[][] c = GetChecksumOffsets(Version);
if (c == null)
return;
BitConverter.GetBytes(SaveUtil.ccitt16(Data, c[0][0] + GBO, c[0][1] - c[0][0])).CopyTo(Data, c[0][2] + GBO);
BitConverter.GetBytes(SaveUtil.ccitt16(Data, c[1][0] + SBO, c[1][1] - c[1][0])).CopyTo(Data, c[1][2] + SBO);
BitConverter.GetBytes(SaveUtil.CRC16_CCITT(Data, c[0][0] + GBO, c[0][1] - c[0][0])).CopyTo(Data, c[0][2] + GBO);
BitConverter.GetBytes(SaveUtil.CRC16_CCITT(Data, c[1][0] + SBO, c[1][1] - c[1][0])).CopyTo(Data, c[1][2] + SBO);
}
public override bool ChecksumsValid
{
get
{
int[][] c = getCHKOffsets(Version);
int[][] c = GetChecksumOffsets(Version);
if (c == null)
return false;
if (SaveUtil.ccitt16(Data, c[0][0] + GBO, c[0][1] - c[0][0]) != BitConverter.ToUInt16(Data, c[0][2] + GBO))
if (SaveUtil.CRC16_CCITT(Data, c[0][0] + GBO, c[0][1] - c[0][0]) != BitConverter.ToUInt16(Data, c[0][2] + GBO))
return false; // Small Fail
if (SaveUtil.ccitt16(Data, c[1][0] + SBO, c[1][1] - c[1][0]) != BitConverter.ToUInt16(Data, c[1][2] + SBO))
if (SaveUtil.CRC16_CCITT(Data, c[1][0] + SBO, c[1][1] - c[1][0]) != BitConverter.ToUInt16(Data, c[1][2] + SBO))
return false; // Large Fail
return true;
@ -109,14 +109,14 @@ namespace PKHeX.Core
{
get
{
int[][] c = getCHKOffsets(Version);
int[][] c = GetChecksumOffsets(Version);
if (c == null)
return "Unable to check Save File.";
string r = "";
if (SaveUtil.ccitt16(Data, c[0][0] + GBO, c[0][1] - c[0][0]) != BitConverter.ToUInt16(Data, c[0][2] + GBO))
if (SaveUtil.CRC16_CCITT(Data, c[0][0] + GBO, c[0][1] - c[0][0]) != BitConverter.ToUInt16(Data, c[0][2] + GBO))
r += "Small block checksum is invalid" + Environment.NewLine;
if (SaveUtil.ccitt16(Data, c[1][0] + SBO, c[1][1] - c[1][0]) != BitConverter.ToUInt16(Data, c[1][2] + SBO))
if (SaveUtil.CRC16_CCITT(Data, c[1][0] + SBO, c[1][1] - c[1][0]) != BitConverter.ToUInt16(Data, c[1][2] + SBO))
r += "Large block checksum is invalid" + Environment.NewLine;
return r.Length == 0 ? "Checksums valid." : r.TrimEnd();
@ -130,8 +130,8 @@ namespace PKHeX.Core
private int SBO => 0x40000 * storageBlock;
private int GBO => 0x40000 * generalBlock;
private int HBO => 0x40000 * hofBlock;
public int getGBO => GBO;
private void getActiveGeneralBlock()
public int GetGBO => GBO;
private void GetActiveGeneralBlock()
{
if (Version < 0)
return;
@ -139,9 +139,9 @@ namespace PKHeX.Core
// Check to see if the save is initialized completely
// if the block is not initialized, fall back to the other save.
if (getData(0x00000, 10).SequenceEqual(Enumerable.Repeat((byte)0xFF, 10)))
if (GetData(0x00000, 10).SequenceEqual(Enumerable.Repeat((byte)0xFF, 10)))
{ generalBlock = 1; return; }
if (getData(0x40000, 10).SequenceEqual(Enumerable.Repeat((byte)0xFF, 10)))
if (GetData(0x40000, 10).SequenceEqual(Enumerable.Repeat((byte)0xFF, 10)))
{ generalBlock = 0; return; }
// Check SaveCount for current save
@ -150,7 +150,7 @@ namespace PKHeX.Core
else if (Version == GameVersion.HGSS) ofs = 0xF618; // HGSS
generalBlock = BitConverter.ToUInt16(Data, ofs) >= BitConverter.ToUInt16(Data, ofs + 0x40000) ? 0 : 1;
}
private void getActiveStorageBlock()
private void GetActiveStorageBlock()
{
if (Version < 0)
return;
@ -163,14 +163,14 @@ namespace PKHeX.Core
// Check to see if the save is initialized completely
// if the block is not initialized, fall back to the other save.
if (getData(ofs + 0x00000, 10).SequenceEqual(Enumerable.Repeat((byte)0xFF, 10)))
if (GetData(ofs + 0x00000, 10).SequenceEqual(Enumerable.Repeat((byte)0xFF, 10)))
{ storageBlock = 1; return; }
if (getData(ofs + 0x40000, 10).SequenceEqual(Enumerable.Repeat((byte)0xFF, 10)))
if (GetData(ofs + 0x40000, 10).SequenceEqual(Enumerable.Repeat((byte)0xFF, 10)))
{ storageBlock = 0; return; }
storageBlock = BitConverter.ToUInt16(Data, ofs) >= BitConverter.ToUInt16(Data, ofs + 0x40000) ? 0 : 1;
}
private void getSAVOffsets()
private void GetSAVOffsets()
{
if (Version < 0)
return;
@ -296,13 +296,13 @@ namespace PKHeX.Core
new InventoryPouch(InventoryType.MailItems, LegalMailItems, 999, OFS_MailItems),
};
foreach (var p in pouch)
p.getPouch(ref Data);
p.GetPouch(ref Data);
return pouch;
}
set
{
foreach (var p in value)
p.setPouch(ref Data);
p.SetPouch(ref Data);
}
}
@ -312,11 +312,11 @@ namespace PKHeX.Core
get => Data[Party - 4];
protected set => Data[Party - 4] = (byte)value;
}
public override int getBoxOffset(int box)
public override int GetBoxOffset(int box)
{
return Box + SIZE_STORED*box*30 + (Version == GameVersion.HGSS ? box * 0x10 : 0);
}
public override int getPartyOffset(int slot)
public override int GetPartyOffset(int slot)
{
return Party + SIZE_PARTY*slot;
}
@ -324,8 +324,8 @@ namespace PKHeX.Core
// Trainer Info
public override string OT
{
get => getString(Trainer1, 16);
set => setString(value, OTLength).CopyTo(Data, Trainer1);
get => GetString(Trainer1, 16);
set => SetString(value, OTLength).CopyTo(Data, Trainer1);
}
public override ushort TID
{
@ -510,8 +510,8 @@ namespace PKHeX.Core
// Storage
public override int CurrentBox
{
get => Data[Version == GameVersion.HGSS ? getBoxOffset(BoxCount) : Box - 4];
set => Data[Version == GameVersion.HGSS ? getBoxOffset(BoxCount) : Box - 4] = (byte)value;
get => Data[Version == GameVersion.HGSS ? GetBoxOffset(BoxCount) : Box - 4];
set => Data[Version == GameVersion.HGSS ? GetBoxOffset(BoxCount) : Box - 4] = (byte)value;
}
private static int InvertHGSSBoxWallpaperAlias(int value)
{
@ -520,75 +520,75 @@ namespace PKHeX.Core
return value ^ 0x30;
return value;
}
public override int getBoxWallpaper(int box)
public override int GetBoxWallpaper(int box)
{
int value = base.getBoxWallpaper(box);
int value = base.GetBoxWallpaper(box);
return Version == GameVersion.HGSS ? InvertHGSSBoxWallpaperAlias(value) : value;
}
public override void setBoxWallpaper(int box, int value)
public override void SetBoxWallpaper(int box, int value)
{
if (Version == GameVersion.HGSS)
value = InvertHGSSBoxWallpaperAlias(value);
base.setBoxWallpaper(box, value);
base.SetBoxWallpaper(box, value);
}
protected override int getBoxWallpaperOffset(int box)
protected override int GetBoxWallpaperOffset(int box)
{
// Box Wallpaper is directly after the Box Names
int offset = getBoxOffset(BoxCount);
int offset = GetBoxOffset(BoxCount);
if (Version == GameVersion.HGSS) offset += 0x8;
offset += BoxCount*0x28 + box;
return offset;
}
public override string getBoxName(int box)
public override string GetBoxName(int box)
{
int offset = getBoxOffset(BoxCount);
int offset = GetBoxOffset(BoxCount);
if (Version == GameVersion.HGSS) offset += 0x8;
return getString(offset + box*0x28, 0x28);
return GetString(offset + box*0x28, 0x28);
}
public override void setBoxName(int box, string value)
public override void SetBoxName(int box, string value)
{
if (value.Length > 13)
value = value.Substring(0, 13); // Hard cap
int offset = getBoxOffset(BoxCount);
int offset = GetBoxOffset(BoxCount);
if (Version == GameVersion.HGSS) offset += 0x8;
setData(setString(value, 13), offset + box*0x28);
SetData(SetString(value, 13), offset + box*0x28);
}
public override PKM getPKM(byte[] data)
public override PKM GetPKM(byte[] data)
{
return new PK4(data);
}
public override byte[] decryptPKM(byte[] data)
public override byte[] DecryptPKM(byte[] data)
{
return PKX.decryptArray45(data);
return PKX.DecryptArray45(data);
}
// Daycare
public override int getDaycareSlotOffset(int loc, int slot)
public override int GetDaycareSlotOffset(int loc, int slot)
{
return Daycare + slot * SIZE_PARTY;
}
public override uint? getDaycareEXP(int loc, int slot)
public override uint? GetDaycareEXP(int loc, int slot)
{
int ofs = Daycare + (slot+1)*SIZE_PARTY - 4;
return BitConverter.ToUInt32(Data, ofs);
}
public override bool? getDaycareOccupied(int loc, int slot)
public override bool? IsDaycareOccupied(int loc, int slot)
{
return null;
}
public override void setDaycareEXP(int loc, int slot, uint EXP)
public override void SetDaycareEXP(int loc, int slot, uint EXP)
{
int ofs = Daycare + (slot+1)*SIZE_PARTY - 4;
BitConverter.GetBytes(EXP).CopyTo(Data, ofs);
}
public override void setDaycareOccupied(int loc, int slot, bool occupied)
public override void SetDaycareOccupied(int loc, int slot, bool occupied)
{
}
// Mystery Gift
public bool MysteryGiftActive { get => (Data[GBO + 72] & 1) == 1; set => Data[GBO + 72] = (byte)((Data[GBO + 72] & 0xFE) | (value ? 1 : 0)); }
private static bool getIsMysteryGiftAvailable(MysteryGift[] value)
private bool MysteryGiftActive { get => (Data[GBO + 72] & 1) == 1; set => Data[GBO + 72] = (byte)((Data[GBO + 72] & 0xFE) | (value ? 1 : 0)); }
private static bool IsMysteryGiftAvailable(MysteryGift[] value)
{
if (value == null)
return false;
@ -601,7 +601,7 @@ namespace PKHeX.Core
return false;
}
private static int[] matchMysteryGifts(MysteryGift[] value)
private static int[] MatchMysteryGifts(MysteryGift[] value)
{
if (value == null)
return null;
@ -650,7 +650,7 @@ namespace PKHeX.Core
}
set
{
bool available = getIsMysteryGiftAvailable(value.Gifts);
bool available = IsMysteryGiftAvailable(value.Gifts);
MysteryGiftActive |= available;
value.Flags[2047] = available;
@ -719,7 +719,7 @@ namespace PKHeX.Core
for (int i = 0; i < value.Length; i++)
{
byte[] magic = BitConverter.GetBytes(value[i] ? MysteryGiftDPSlotActive : 0); // 4 bytes
setData(magic, ofs + 4*i);
SetData(magic, ofs + 4*i);
}
}
}
@ -730,9 +730,9 @@ namespace PKHeX.Core
{
MysteryGift[] cards = new MysteryGift[8 + 3];
for (int i = 0; i < 8; i++) // 8 PGT
cards[i] = new PGT(getData(WondercardData + i * PGT.Size, PGT.Size));
cards[i] = new PGT(GetData(WondercardData + i * PGT.Size, PGT.Size));
for (int i = 8; i < 11; i++) // 3 PCD
cards[i] = new PCD(getData(WondercardData + 8 * PGT.Size + (i-8) * PCD.Size, PCD.Size));
cards[i] = new PCD(GetData(WondercardData + 8 * PGT.Size + (i-8) * PCD.Size, PCD.Size));
return cards;
}
set
@ -740,20 +740,20 @@ namespace PKHeX.Core
if (value == null)
return;
var Matches = matchMysteryGifts(value); // automatically applied
var Matches = MatchMysteryGifts(value); // automatically applied
if (Matches == null)
return;
for (int i = 0; i < 8; i++) // 8 PGT
if (value[i] is PGT)
setData(value[i].Data, WondercardData + i*PGT.Size);
SetData(value[i].Data, WondercardData + i*PGT.Size);
for (int i = 8; i < 11; i++) // 3 PCD
if (value[i] is PCD)
setData(value[i].Data, WondercardData + 8*PGT.Size + (i - 8)*PCD.Size);
SetData(value[i].Data, WondercardData + 8*PGT.Size + (i - 8)*PCD.Size);
}
}
protected override void setDex(PKM pkm)
protected override void SetDex(PKM pkm)
{
if (pkm.Species == 0)
return;
@ -814,7 +814,7 @@ namespace PKHeX.Core
}
int FormOffset1 = PokeDex + 4 + brSize * 4 + 4;
var forms = getForms(pkm.Species);
var forms = GetForms(pkm.Species);
if (forms != null)
{
if (pkm.Species == 201) // Unown
@ -833,8 +833,8 @@ namespace PKHeX.Core
}
else
{
checkInsertForm(ref forms, pkm.AltForm);
setForms(pkm.Species, forms);
CheckInsertForm(ref forms, pkm.AltForm);
SetForms(pkm.Species, forms);
}
}
@ -851,7 +851,7 @@ namespace PKHeX.Core
Data[PokeDexLanguageFlags + (DP ? dpl : pkm.Species)] |= (byte)(1 << lang);
}
public override bool getCaught(int species)
public override bool GetCaught(int species)
{
int bit = species - 1;
int bd = bit >> 3; // div8
@ -860,7 +860,7 @@ namespace PKHeX.Core
+ 0x4; // Magic
return (1 << bm & Data[ofs + bd]) != 0;
}
public override bool getSeen(int species)
public override bool GetSeen(int species)
{
const int brSize = 0x40;
@ -873,28 +873,28 @@ namespace PKHeX.Core
return (1 << bm & Data[ofs + bd + brSize*1]) != 0;
}
public int[] getForms(int species)
public int[] GetForms(int species)
{
const int brSize = 0x40;
if (species == 386)
{
uint val = (uint) (Data[PokeDex + 0x4 + 1*brSize - 1] | Data[PokeDex + 0x4 + 2*brSize - 1] << 8);
return getDexFormValues(val, 4, 4);
return GetDexFormValues(val, 4, 4);
}
int FormOffset1 = PokeDex + 4 + 4*brSize + 4;
switch (species)
{
case 422: // Shellos
return getDexFormValues(Data[FormOffset1 + 0], 1, 2);
return GetDexFormValues(Data[FormOffset1 + 0], 1, 2);
case 423: // Gastrodon
return getDexFormValues(Data[FormOffset1 + 1], 1, 2);
return GetDexFormValues(Data[FormOffset1 + 1], 1, 2);
case 412: // Burmy
return getDexFormValues(Data[FormOffset1 + 2], 2, 3);
return GetDexFormValues(Data[FormOffset1 + 2], 2, 3);
case 413: // Wormadam
return getDexFormValues(Data[FormOffset1 + 3], 2, 3);
return GetDexFormValues(Data[FormOffset1 + 3], 2, 3);
case 201: // Unown
return getData(FormOffset1 + 4, 0x1C).Select(i => (int)i).ToArray();
return GetData(FormOffset1 + 4, 0x1C).Select(i => (int)i).ToArray();
}
if (DP)
return null;
@ -904,26 +904,26 @@ namespace PKHeX.Core
switch (species)
{
case 479: // Rotom
return getDexFormValues(BitConverter.ToUInt32(Data, FormOffset2), 3, 6);
return GetDexFormValues(BitConverter.ToUInt32(Data, FormOffset2), 3, 6);
case 492: // Shaymin
return getDexFormValues(Data[FormOffset2 + 4], 1, 2);
return GetDexFormValues(Data[FormOffset2 + 4], 1, 2);
case 487: // Giratina
return getDexFormValues(Data[FormOffset2 + 5], 1, 2);
return GetDexFormValues(Data[FormOffset2 + 5], 1, 2);
case 172:
if (!HGSS)
return null;
return getDexFormValues(Data[FormOffset2 + 6], 2, 3);
return GetDexFormValues(Data[FormOffset2 + 6], 2, 3);
}
return null;
}
public void setForms(int spec, int[] forms)
public void SetForms(int spec, int[] forms)
{
const int brSize = 0x40;
switch (spec)
{
case 386: // Deoxys
uint newval = setDexFormValues(forms, 4, 4);
uint newval = SetDexFormValues(forms, 4, 4);
Data[PokeDex + 0x4 + 1*brSize - 1] = (byte) (newval & 0xFF);
Data[PokeDex + 0x4 + 2*brSize - 1] = (byte) ((newval >> 8) & 0xFF);
break;
@ -933,16 +933,16 @@ namespace PKHeX.Core
switch (spec)
{
case 422: // Shellos
Data[FormOffset1 + 0] = (byte)setDexFormValues(forms, 1, 2);
Data[FormOffset1 + 0] = (byte)SetDexFormValues(forms, 1, 2);
return;
case 423: // Gastrodon
Data[FormOffset1 + 1] = (byte)setDexFormValues(forms, 1, 2);
Data[FormOffset1 + 1] = (byte)SetDexFormValues(forms, 1, 2);
return;
case 412: // Burmy
Data[FormOffset1 + 2] = (byte)setDexFormValues(forms, 2, 3);
Data[FormOffset1 + 2] = (byte)SetDexFormValues(forms, 2, 3);
return;
case 413: // Wormadam
Data[FormOffset1 + 3] = (byte)setDexFormValues(forms, 2, 3);
Data[FormOffset1 + 3] = (byte)SetDexFormValues(forms, 2, 3);
return;
case 201: // Unown
int ofs = FormOffset1 + 4;
@ -962,23 +962,23 @@ namespace PKHeX.Core
switch (spec)
{
case 479: // Rotom
BitConverter.GetBytes(setDexFormValues(forms, 3, 6)).CopyTo(Data, FormOffset2);
BitConverter.GetBytes(SetDexFormValues(forms, 3, 6)).CopyTo(Data, FormOffset2);
return;
case 492: // Shaymin
Data[FormOffset2 + 4] = (byte)setDexFormValues(forms, 1, 2);
Data[FormOffset2 + 4] = (byte)SetDexFormValues(forms, 1, 2);
return;
case 487: // Giratina
Data[FormOffset2 + 5] = (byte)setDexFormValues(forms, 1, 2);
Data[FormOffset2 + 5] = (byte)SetDexFormValues(forms, 1, 2);
return;
case 172: // Pichu
if (!HGSS)
return;
Data[FormOffset2 + 6] = (byte)setDexFormValues(forms, 2, 3);
Data[FormOffset2 + 6] = (byte)SetDexFormValues(forms, 2, 3);
return;
}
}
private static int[] getDexFormValues(uint Value, int BitsPerForm, int readCt)
private static int[] GetDexFormValues(uint Value, int BitsPerForm, int readCt)
{
int[] Forms = new int[readCt];
int n1 = 0xFF >> (8 - BitsPerForm);
@ -992,7 +992,7 @@ namespace PKHeX.Core
}
return Forms;
}
private static uint setDexFormValues(int[] Forms, int BitsPerForm, int readCt)
private static uint SetDexFormValues(int[] Forms, int BitsPerForm, int readCt)
{
int n1 = 0xFF >> (8 - BitsPerForm);
uint Value = 0xFFFFFFFF << (Forms.Length*BitsPerForm);
@ -1006,7 +1006,7 @@ namespace PKHeX.Core
}
return Value;
}
private static bool checkInsertForm(ref int[] Forms, int FormNum)
private static bool CheckInsertForm(ref int[] Forms, int FormNum)
{
if (Forms.Any(num => num == FormNum))
{
@ -1082,16 +1082,16 @@ namespace PKHeX.Core
// Honey Trees
private int OFS_HONEY = int.MinValue;
private const int HONEY_SIZE = 8;
public HoneyTree getHoneyTree(int index)
public HoneyTree GetHoneyTree(int index)
{
if (index <= 21 && OFS_HONEY > 0)
return new HoneyTree(getData(OFS_HONEY + HONEY_SIZE * index, HONEY_SIZE));
else return null;
if (OFS_HONEY <= 0 || index > 21)
return null;
return new HoneyTree(GetData(OFS_HONEY + HONEY_SIZE * index, HONEY_SIZE));
}
public void setHoneyTree(HoneyTree tree, int index)
public void SetHoneyTree(HoneyTree tree, int index)
{
if (index <= 21 && OFS_HONEY > 0)
setData(tree.Data, OFS_HONEY + HONEY_SIZE * index);
SetData(tree.Data, OFS_HONEY + HONEY_SIZE * index);
}
public int[] MunchlaxTrees
{
@ -1113,12 +1113,12 @@ namespace PKHeX.Core
}
}
public override string getString(int Offset, int Count) => PKX.getString4(Data, Offset, Count);
public override byte[] setString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
public override string GetString(int Offset, int Count) => PKX.GetString4(Data, Offset, Count);
public override byte[] SetString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
{
if (PadToSize == 0)
PadToSize = maxLength + 1;
return PKX.setString4(value, maxLength, PadToSize, PadWith);
return PKX.SetString4(value, maxLength, PadToSize, PadWith);
}
}
}

View file

@ -18,7 +18,7 @@ namespace PKHeX.Core
BAK = (byte[])Data.Clone();
Exportable = !Data.SequenceEqual(new byte[Data.Length]);
if (SaveUtil.getIsG4BRSAV(Data) != GameVersion.BATREV)
if (SaveUtil.GetIsG4BRSAV(Data) != GameVersion.BATREV)
return;
Data = DecryptPBRSaveData(data);
@ -50,13 +50,14 @@ namespace PKHeX.Core
HeldItems = Legal.HeldItems_DP;
if (!Exportable)
resetBoxes();
ClearBoxes();
}
private readonly uint SaveCount;
public override byte[] Write(bool DSV)
protected override byte[] Write(bool DSV)
{
setChecksums();
SetChecksums();
return EncryptPBRSaveData(Data);
}
@ -72,7 +73,7 @@ namespace PKHeX.Core
}
public override int SIZE_STORED => PKX.SIZE_4STORED;
public override int SIZE_PARTY => PKX.SIZE_4PARTY - 0x10; // PBR has a party
protected override int SIZE_PARTY => PKX.SIZE_4PARTY - 0x10; // PBR has a party
public override PKM BlankPKM => new BK4();
public override Type PKMType => typeof(BK4);
@ -94,7 +95,7 @@ namespace PKHeX.Core
public override bool HasParty => false;
// Checksums
protected override void setChecksums()
protected override void SetChecksums()
{
SetChecksum(Data, 0, 0x100, 8);
SetChecksum(Data, 0, 0x1C0000, 0x1BFF80);
@ -117,31 +118,31 @@ namespace PKHeX.Core
public override GameVersion Version { get => GameVersion.BATREV; protected set { } }
// Storage
public override int getPartyOffset(int slot) // TODO
public override int GetPartyOffset(int slot) // TODO
{
return -1;
}
public override int getBoxOffset(int box)
public override int GetBoxOffset(int box)
{
return Box + SIZE_STORED * box * 30;
}
// Save file does not have Box Name / Wallpaper info
public override string getBoxName(int box) { return $"BOX {box + 1}"; }
public override void setBoxName(int box, string value) { }
public override string GetBoxName(int box) { return $"BOX {box + 1}"; }
public override void SetBoxName(int box, string value) { }
public override PKM getPKM(byte[] data)
public override PKM GetPKM(byte[] data)
{
byte[] pkm = data.Take(SIZE_STORED).ToArray();
PKM bk = new BK4(pkm);
return bk;
}
public override byte[] decryptPKM(byte[] data)
public override byte[] DecryptPKM(byte[] data)
{
return data;
}
protected override void setDex(PKM pkm) { }
protected override void SetDex(PKM pkm) { }
public static byte[] DecryptPBRSaveData(byte[] input)
{
@ -221,7 +222,7 @@ namespace PKHeX.Core
return checksums.SequenceEqual(storedChecksums);
}
public static void SetChecksum(byte[] input, int offset, int len, int checksum_offset)
private static void SetChecksum(byte[] input, int offset, int len, int checksum_offset)
{
uint[] storedChecksums = new uint[16];
for (int i = 0; i < storedChecksums.Length; i++)
@ -247,12 +248,12 @@ namespace PKHeX.Core
}
}
public override string getString(int Offset, int Count) => PKX.getBEString4(Data, Offset, Count);
public override byte[] setString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
public override string GetString(int Offset, int Count) => PKX.GetBEString4(Data, Offset, Count);
public override byte[] SetString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
{
if (PadToSize == 0)
PadToSize = maxLength + 1;
return PKX.setBEString4(value, maxLength, PadToSize, PadWith);
return PKX.SetBEString4(value, maxLength, PadToSize, PadWith);
}
}
}

View file

@ -21,7 +21,7 @@ namespace PKHeX.Core
Version = GameVersion.B2W2;
else if (versionOverride != GameVersion.Any)
Version = versionOverride;
else Version = SaveUtil.getIsG5SAV(Data);
else Version = SaveUtil.GetIsG5SAV(Data);
if (Version == GameVersion.Invalid)
return;
@ -88,17 +88,17 @@ namespace PKHeX.Core
break;
}
HeldItems = Legal.HeldItems_BW;
getBlockInfo();
GetBlockInfo();
if (!Exportable)
resetBoxes();
ClearBoxes();
}
// Configuration
public override SaveFile Clone() { return new SAV5(Data, Version); }
public override int SIZE_STORED => PKX.SIZE_5STORED;
public override int SIZE_PARTY => PKX.SIZE_5PARTY;
protected override int SIZE_PARTY => PKX.SIZE_5PARTY;
public override PKM BlankPKM => new PK5();
public override Type PKMType => typeof(PK5);
@ -120,184 +120,184 @@ namespace PKHeX.Core
// Blocks & Offsets
private BlockInfo[] Blocks;
private void getBlockInfo()
private void GetBlockInfo()
{
// Can be slick with just a list of block lengths, but oh well, precomputed.
if (Version == GameVersion.BW)
switch (Version)
{
Blocks = new[]
{
new BlockInfo(0x00000, 0x03E0, 0x003E2, 0x23F00), // Box Names
new BlockInfo(0x00400, 0x0FF0, 0x013F2, 0x23F02), // Box 1
new BlockInfo(0x01400, 0x0FF0, 0x023F2, 0x23F04), // Box 2
new BlockInfo(0x02400, 0x0FF0, 0x033F2, 0x23F06), // Box 3
new BlockInfo(0x03400, 0x0FF0, 0x043F2, 0x23F08), // Box 4
new BlockInfo(0x04400, 0x0FF0, 0x053F2, 0x23F0A), // Box 5
new BlockInfo(0x05400, 0x0FF0, 0x063F2, 0x23F0C), // Box 6
new BlockInfo(0x06400, 0x0FF0, 0x073F2, 0x23F0E), // Box 7
new BlockInfo(0x07400, 0x0FF0, 0x083F2, 0x23F10), // Box 8
new BlockInfo(0x08400, 0x0FF0, 0x093F2, 0x23F12), // Box 9
new BlockInfo(0x09400, 0x0FF0, 0x0A3F2, 0x23F14), // Box 10
new BlockInfo(0x0A400, 0x0FF0, 0x0B3F2, 0x23F16), // Box 11
new BlockInfo(0x0B400, 0x0FF0, 0x0C3F2, 0x23F18), // Box 12
new BlockInfo(0x0C400, 0x0FF0, 0x0D3F2, 0x23F1A), // Box 13
new BlockInfo(0x0D400, 0x0FF0, 0x0E3F2, 0x23F1C), // Box 14
new BlockInfo(0x0E400, 0x0FF0, 0x0F3F2, 0x23F1E), // Box 15
new BlockInfo(0x0F400, 0x0FF0, 0x103F2, 0x23F20), // Box 16
new BlockInfo(0x10400, 0x0FF0, 0x113F2, 0x23F22), // Box 17
new BlockInfo(0x11400, 0x0FF0, 0x123F2, 0x23F24), // Box 18
new BlockInfo(0x12400, 0x0FF0, 0x133F2, 0x23F26), // Box 19
new BlockInfo(0x13400, 0x0FF0, 0x143F2, 0x23F28), // Box 20
new BlockInfo(0x14400, 0x0FF0, 0x153F2, 0x23F2A), // Box 21
new BlockInfo(0x15400, 0x0FF0, 0x163F2, 0x23F2C), // Box 22
new BlockInfo(0x16400, 0x0FF0, 0x173F2, 0x23F2E), // Box 23
new BlockInfo(0x17400, 0x0FF0, 0x183F2, 0x23F30), // Box 24
new BlockInfo(0x18400, 0x09C0, 0x18DC2, 0x23F32), // Inventory
new BlockInfo(0x18E00, 0x0534, 0x19336, 0x23F34), // Party Pokemon
new BlockInfo(0x19400, 0x0068, 0x1946A, 0x23F36), // Trainer Data
new BlockInfo(0x19500, 0x009C, 0x1959E, 0x23F38), // Trainer Position
new BlockInfo(0x19600, 0x1338, 0x1A93A, 0x23F3A), // Unity Tower and survey stuff
new BlockInfo(0x1AA00, 0x07C4, 0x1B1C6, 0x23F3C), // Pal Pad Player Data
new BlockInfo(0x1B200, 0x0D54, 0x1BF56, 0x23F3E), // Pal Pad Friend Data
new BlockInfo(0x1C000, 0x002C, 0x1C02E, 0x23F40), // Skin Info
new BlockInfo(0x1C100, 0x0658, 0x1C75A, 0x23F42), // ??? Gym badge data
new BlockInfo(0x1C800, 0x0A94, 0x1D296, 0x23F44), // Mystery Gift
new BlockInfo(0x1D300, 0x01AC, 0x1D4AE, 0x23F46), // Dream World Stuff (Catalog)
new BlockInfo(0x1D500, 0x03EC, 0x1D8EE, 0x23F48), // Chatter
new BlockInfo(0x1D900, 0x005C, 0x1D95E, 0x23F4A), // Adventure Info
new BlockInfo(0x1DA00, 0x01E0, 0x1DBE2, 0x23F4C), // Trainer Card Records
new BlockInfo(0x1DC00, 0x00A8, 0x1DCAA, 0x23F4E), // ???
new BlockInfo(0x1DD00, 0x0460, 0x1E162, 0x23F50), // (40d)
new BlockInfo(0x1E200, 0x1400, 0x1F602, 0x23F52), // ???
new BlockInfo(0x1F700, 0x02A4, 0x1F9A6, 0x23F54), // Contains flags and references for downloaded data (Musical)
new BlockInfo(0x1FA00, 0x02DC, 0x1FCDE, 0x23F56), // ???
new BlockInfo(0x1FD00, 0x034C, 0x2004E, 0x23F58), // ???
new BlockInfo(0x20100, 0x03EC, 0x204EE, 0x23F5A), // ???
new BlockInfo(0x20500, 0x00F8, 0x205FA, 0x23F5C), // ???
new BlockInfo(0x20600, 0x02FC, 0x208FE, 0x23F5E), // Tournament Block
new BlockInfo(0x20900, 0x0094, 0x20996, 0x23F60), // ???
new BlockInfo(0x20A00, 0x035C, 0x20D5E, 0x23F62), // Battle Box Block
new BlockInfo(0x20E00, 0x01CC, 0x20FCE, 0x23F64), // Daycare Block
new BlockInfo(0x21000, 0x0168, 0x2116A, 0x23F66), // Strength Boulder Status Block
new BlockInfo(0x21200, 0x00EC, 0x212EE, 0x23F68), // Badge Flags, Money, Trainer Sayings
new BlockInfo(0x21300, 0x01B0, 0x214B2, 0x23F6A), // Entralink (Level & Powers etc)
new BlockInfo(0x21500, 0x001C, 0x2151E, 0x23F6C), // ???
new BlockInfo(0x21600, 0x04D4, 0x21AD6, 0x23F6E), // Pokedex
new BlockInfo(0x21B00, 0x0034, 0x21B36, 0x23F70), // Swarm and other overworld info - 2C - swarm, 2D - repel steps, 2E repel type
new BlockInfo(0x21C00, 0x003C, 0x21C3E, 0x23F72), // ???
new BlockInfo(0x21D00, 0x01AC, 0x21EAE, 0x23F74), // ???
new BlockInfo(0x21F00, 0x0B90, 0x22A92, 0x23F76), // ???
new BlockInfo(0x22B00, 0x009C, 0x22B9E, 0x23F78), // Online Records
new BlockInfo(0x22C00, 0x0850, 0x23452, 0x23F7A), // Entralink Forest pokémon data
new BlockInfo(0x23500, 0x0028, 0x2352A, 0x23F7C), // ???
new BlockInfo(0x23600, 0x0284, 0x23886, 0x23F7E), // ???
new BlockInfo(0x23900, 0x0010, 0x23912, 0x23F80), // ???
new BlockInfo(0x23A00, 0x005C, 0x23A5E, 0x23F82), // ???
new BlockInfo(0x23B00, 0x016C, 0x23C6E, 0x23F84), // ???
new BlockInfo(0x23D00, 0x0040, 0x23D42, 0x23F86), // ???
new BlockInfo(0x23E00, 0x00FC, 0x23EFE, 0x23F88), // ???
new BlockInfo(0x23F00, 0x008C, 0x23F9A, 0x23F9A), // Checksums */
};
}
else if (Version == GameVersion.B2W2)
{
Blocks = new[]
{
// Offset, Length, CHKOfst, ChkMirror
new BlockInfo(0x00000, 0x03e0, 0x003E2, 0x25F00), // Box Names
new BlockInfo(0x00400, 0x0ff0, 0x013F2, 0x25F02), // Box 1
new BlockInfo(0x01400, 0x0ff0, 0x023F2, 0x25F04), // Box 2
new BlockInfo(0x02400, 0x0ff0, 0x033F2, 0x25F06), // Box 3
new BlockInfo(0x03400, 0x0ff0, 0x043F2, 0x25F08), // Box 4
new BlockInfo(0x04400, 0x0ff0, 0x053F2, 0x25F0A), // Box 5
new BlockInfo(0x05400, 0x0ff0, 0x063F2, 0x25F0C), // Box 6
new BlockInfo(0x06400, 0x0ff0, 0x073F2, 0x25F0E), // Box 7
new BlockInfo(0x07400, 0x0ff0, 0x083F2, 0x25F10), // Box 8
new BlockInfo(0x08400, 0x0ff0, 0x093F2, 0x25F12), // Box 9
new BlockInfo(0x09400, 0x0ff0, 0x0A3F2, 0x25F14), // Box 10
new BlockInfo(0x0A400, 0x0ff0, 0x0B3F2, 0x25F16), // Box 11
new BlockInfo(0x0B400, 0x0ff0, 0x0C3F2, 0x25F18), // Box 12
new BlockInfo(0x0C400, 0x0ff0, 0x0D3F2, 0x25F1A), // Box 13
new BlockInfo(0x0D400, 0x0ff0, 0x0E3F2, 0x25F1C), // Box 14
new BlockInfo(0x0E400, 0x0ff0, 0x0F3F2, 0x25F1E), // Box 15
new BlockInfo(0x0F400, 0x0ff0, 0x103F2, 0x25F20), // Box 16
new BlockInfo(0x10400, 0x0ff0, 0x113F2, 0x25F22), // Box 17
new BlockInfo(0x11400, 0x0ff0, 0x123F2, 0x25F24), // Box 18
new BlockInfo(0x12400, 0x0ff0, 0x133F2, 0x25F26), // Box 19
new BlockInfo(0x13400, 0x0ff0, 0x143F2, 0x25F28), // Box 20
new BlockInfo(0x14400, 0x0ff0, 0x153F2, 0x25F2A), // Box 21
new BlockInfo(0x15400, 0x0ff0, 0x163F2, 0x25F2C), // Box 22
new BlockInfo(0x16400, 0x0ff0, 0x173F2, 0x25F2E), // Box 23
new BlockInfo(0x17400, 0x0ff0, 0x183F2, 0x25F30), // Box 24
new BlockInfo(0x18400, 0x09ec, 0x18DEE, 0x25F32), // Inventory
new BlockInfo(0x18E00, 0x0534, 0x19336, 0x25F34), // Party Pokemon
new BlockInfo(0x19400, 0x00b0, 0x194B2, 0x25F36), // Trainer Data
new BlockInfo(0x19500, 0x00a8, 0x195AA, 0x25F38), // Trainer Position
new BlockInfo(0x19600, 0x1338, 0x1A93A, 0x25F3A), // Unity Tower and survey stuff
new BlockInfo(0x1AA00, 0x07c4, 0x1B1C6, 0x25F3C), // Pal Pad Player Data (30d)
new BlockInfo(0x1B200, 0x0d54, 0x1BF56, 0x25F3E), // Pal Pad Friend Data
new BlockInfo(0x1C000, 0x0094, 0x1C096, 0x25F40), // Skin Info
new BlockInfo(0x1C100, 0x0658, 0x1C75A, 0x25F42), // Card Signature Block & ????
new BlockInfo(0x1C800, 0x0a94, 0x1D296, 0x25F44), // Mystery Gift
new BlockInfo(0x1D300, 0x01ac, 0x1D4AE, 0x25F46), // Dream World Stuff (Catalog)
new BlockInfo(0x1D500, 0x03ec, 0x1D8EE, 0x25F48), // Chatter
new BlockInfo(0x1D900, 0x005c, 0x1D95E, 0x25F4A), // Adventure data
new BlockInfo(0x1DA00, 0x01e0, 0x1DBE2, 0x25F4C), // Trainer Card Records
new BlockInfo(0x1DC00, 0x00a8, 0x1DCAA, 0x25F4E), // ???
new BlockInfo(0x1DD00, 0x0460, 0x1E162, 0x25F50), // (40d)
new BlockInfo(0x1E200, 0x1400, 0x1F602, 0x25F52), // ???
new BlockInfo(0x1F700, 0x02a4, 0x1F9A6, 0x25F54), // Contains flags and references for downloaded data (Musical)
new BlockInfo(0x1FA00, 0x00e0, 0x1FAE2, 0x25F56), // Fused Reshiram/Zekrom Storage
new BlockInfo(0x1FB00, 0x034c, 0x1FE4E, 0x25F58), // ???
new BlockInfo(0x1FF00, 0x04e0, 0x203E2, 0x25F5A), // Const Data Block and Event Flag Block (0x35E is the split)
new BlockInfo(0x20400, 0x00f8, 0x204FA, 0x25F5C), // ???
new BlockInfo(0x20500, 0x02fc, 0x207FE, 0x25F5E), // Tournament Block
new BlockInfo(0x20800, 0x0094, 0x20896, 0x25F60), // ???
new BlockInfo(0x20900, 0x035c, 0x20C5E, 0x25F62), // Battle Box Block
new BlockInfo(0x20D00, 0x01d4, 0x20ED6, 0x25F64), // Daycare Block (50d)
new BlockInfo(0x20F00, 0x01e0, 0x210E2, 0x25F66), // Strength Boulder Status Block
new BlockInfo(0x21100, 0x00f0, 0x211F2, 0x25F68), // Badge Flags, Money, Trainer Sayings
new BlockInfo(0x21200, 0x01b4, 0x213B6, 0x25F6A), // Entralink (Level & Powers etc)
new BlockInfo(0x21400, 0x04dc, 0x218DE, 0x25F6C), // Pokedex
new BlockInfo(0x21900, 0x0034, 0x21936, 0x25F6E), // Swarm and other overworld info - 2C - swarm, 2D - repel steps, 2E repel type
new BlockInfo(0x21A00, 0x003c, 0x21A3E, 0x25F70), // ???
new BlockInfo(0x21B00, 0x01ac, 0x21CAE, 0x25F72), // ???
new BlockInfo(0x21D00, 0x0b90, 0x22892, 0x25F74), // ???
new BlockInfo(0x22900, 0x00ac, 0x229AE, 0x25F76), // Online Records
new BlockInfo(0x22A00, 0x0850, 0x23252, 0x25F78), // Entralink Forest pokémon data (60d)
new BlockInfo(0x23300, 0x0284, 0x23586, 0x25F7A), // ???
new BlockInfo(0x23600, 0x0010, 0x23612, 0x25F7C), // ???
new BlockInfo(0x23700, 0x00a8, 0x237AA, 0x25F7E), // ???
new BlockInfo(0x23800, 0x016c, 0x2396E, 0x25F80), // ???
new BlockInfo(0x23A00, 0x0080, 0x23A82, 0x25F82), // ???
new BlockInfo(0x23B00, 0x00fc, 0x23BFE, 0x25F84), // Hollow/Rival Block
new BlockInfo(0x23C00, 0x16a8, 0x252AA, 0x25F86), // Join Avenue Block
new BlockInfo(0x25300, 0x0498, 0x2579A, 0x25F88), // Medal data
new BlockInfo(0x25800, 0x0060, 0x25862, 0x25F8A), // Key-related data
new BlockInfo(0x25900, 0x00fc, 0x259FE, 0x25F8C), // (70d)
new BlockInfo(0x25A00, 0x03e4, 0x25DE6, 0x25F8E), // ???
new BlockInfo(0x25E00, 0x00f0, 0x25EF2, 0x25F90), // ???
new BlockInfo(0x25F00, 0x0094, 0x25FA2, 0x25FA2), // Checksum Block (73d)
};
}
else
{
Blocks = new BlockInfo[] { };
case GameVersion.BW:
Blocks = new[]
{
new BlockInfo(0x00000, 0x03E0, 0x003E2, 0x23F00), // Box Names
new BlockInfo(0x00400, 0x0FF0, 0x013F2, 0x23F02), // Box 1
new BlockInfo(0x01400, 0x0FF0, 0x023F2, 0x23F04), // Box 2
new BlockInfo(0x02400, 0x0FF0, 0x033F2, 0x23F06), // Box 3
new BlockInfo(0x03400, 0x0FF0, 0x043F2, 0x23F08), // Box 4
new BlockInfo(0x04400, 0x0FF0, 0x053F2, 0x23F0A), // Box 5
new BlockInfo(0x05400, 0x0FF0, 0x063F2, 0x23F0C), // Box 6
new BlockInfo(0x06400, 0x0FF0, 0x073F2, 0x23F0E), // Box 7
new BlockInfo(0x07400, 0x0FF0, 0x083F2, 0x23F10), // Box 8
new BlockInfo(0x08400, 0x0FF0, 0x093F2, 0x23F12), // Box 9
new BlockInfo(0x09400, 0x0FF0, 0x0A3F2, 0x23F14), // Box 10
new BlockInfo(0x0A400, 0x0FF0, 0x0B3F2, 0x23F16), // Box 11
new BlockInfo(0x0B400, 0x0FF0, 0x0C3F2, 0x23F18), // Box 12
new BlockInfo(0x0C400, 0x0FF0, 0x0D3F2, 0x23F1A), // Box 13
new BlockInfo(0x0D400, 0x0FF0, 0x0E3F2, 0x23F1C), // Box 14
new BlockInfo(0x0E400, 0x0FF0, 0x0F3F2, 0x23F1E), // Box 15
new BlockInfo(0x0F400, 0x0FF0, 0x103F2, 0x23F20), // Box 16
new BlockInfo(0x10400, 0x0FF0, 0x113F2, 0x23F22), // Box 17
new BlockInfo(0x11400, 0x0FF0, 0x123F2, 0x23F24), // Box 18
new BlockInfo(0x12400, 0x0FF0, 0x133F2, 0x23F26), // Box 19
new BlockInfo(0x13400, 0x0FF0, 0x143F2, 0x23F28), // Box 20
new BlockInfo(0x14400, 0x0FF0, 0x153F2, 0x23F2A), // Box 21
new BlockInfo(0x15400, 0x0FF0, 0x163F2, 0x23F2C), // Box 22
new BlockInfo(0x16400, 0x0FF0, 0x173F2, 0x23F2E), // Box 23
new BlockInfo(0x17400, 0x0FF0, 0x183F2, 0x23F30), // Box 24
new BlockInfo(0x18400, 0x09C0, 0x18DC2, 0x23F32), // Inventory
new BlockInfo(0x18E00, 0x0534, 0x19336, 0x23F34), // Party Pokemon
new BlockInfo(0x19400, 0x0068, 0x1946A, 0x23F36), // Trainer Data
new BlockInfo(0x19500, 0x009C, 0x1959E, 0x23F38), // Trainer Position
new BlockInfo(0x19600, 0x1338, 0x1A93A, 0x23F3A), // Unity Tower and survey stuff
new BlockInfo(0x1AA00, 0x07C4, 0x1B1C6, 0x23F3C), // Pal Pad Player Data
new BlockInfo(0x1B200, 0x0D54, 0x1BF56, 0x23F3E), // Pal Pad Friend Data
new BlockInfo(0x1C000, 0x002C, 0x1C02E, 0x23F40), // Skin Info
new BlockInfo(0x1C100, 0x0658, 0x1C75A, 0x23F42), // ??? Gym badge data
new BlockInfo(0x1C800, 0x0A94, 0x1D296, 0x23F44), // Mystery Gift
new BlockInfo(0x1D300, 0x01AC, 0x1D4AE, 0x23F46), // Dream World Stuff (Catalog)
new BlockInfo(0x1D500, 0x03EC, 0x1D8EE, 0x23F48), // Chatter
new BlockInfo(0x1D900, 0x005C, 0x1D95E, 0x23F4A), // Adventure Info
new BlockInfo(0x1DA00, 0x01E0, 0x1DBE2, 0x23F4C), // Trainer Card Records
new BlockInfo(0x1DC00, 0x00A8, 0x1DCAA, 0x23F4E), // ???
new BlockInfo(0x1DD00, 0x0460, 0x1E162, 0x23F50), // (40d)
new BlockInfo(0x1E200, 0x1400, 0x1F602, 0x23F52), // ???
new BlockInfo(0x1F700, 0x02A4, 0x1F9A6, 0x23F54), // Contains flags and references for downloaded data (Musical)
new BlockInfo(0x1FA00, 0x02DC, 0x1FCDE, 0x23F56), // ???
new BlockInfo(0x1FD00, 0x034C, 0x2004E, 0x23F58), // ???
new BlockInfo(0x20100, 0x03EC, 0x204EE, 0x23F5A), // ???
new BlockInfo(0x20500, 0x00F8, 0x205FA, 0x23F5C), // ???
new BlockInfo(0x20600, 0x02FC, 0x208FE, 0x23F5E), // Tournament Block
new BlockInfo(0x20900, 0x0094, 0x20996, 0x23F60), // ???
new BlockInfo(0x20A00, 0x035C, 0x20D5E, 0x23F62), // Battle Box Block
new BlockInfo(0x20E00, 0x01CC, 0x20FCE, 0x23F64), // Daycare Block
new BlockInfo(0x21000, 0x0168, 0x2116A, 0x23F66), // Strength Boulder Status Block
new BlockInfo(0x21200, 0x00EC, 0x212EE, 0x23F68), // Badge Flags, Money, Trainer Sayings
new BlockInfo(0x21300, 0x01B0, 0x214B2, 0x23F6A), // Entralink (Level & Powers etc)
new BlockInfo(0x21500, 0x001C, 0x2151E, 0x23F6C), // ???
new BlockInfo(0x21600, 0x04D4, 0x21AD6, 0x23F6E), // Pokedex
new BlockInfo(0x21B00, 0x0034, 0x21B36, 0x23F70), // Swarm and other overworld info - 2C - swarm, 2D - repel steps, 2E repel type
new BlockInfo(0x21C00, 0x003C, 0x21C3E, 0x23F72), // ???
new BlockInfo(0x21D00, 0x01AC, 0x21EAE, 0x23F74), // ???
new BlockInfo(0x21F00, 0x0B90, 0x22A92, 0x23F76), // ???
new BlockInfo(0x22B00, 0x009C, 0x22B9E, 0x23F78), // Online Records
new BlockInfo(0x22C00, 0x0850, 0x23452, 0x23F7A), // Entralink Forest pokémon data
new BlockInfo(0x23500, 0x0028, 0x2352A, 0x23F7C), // ???
new BlockInfo(0x23600, 0x0284, 0x23886, 0x23F7E), // ???
new BlockInfo(0x23900, 0x0010, 0x23912, 0x23F80), // ???
new BlockInfo(0x23A00, 0x005C, 0x23A5E, 0x23F82), // ???
new BlockInfo(0x23B00, 0x016C, 0x23C6E, 0x23F84), // ???
new BlockInfo(0x23D00, 0x0040, 0x23D42, 0x23F86), // ???
new BlockInfo(0x23E00, 0x00FC, 0x23EFE, 0x23F88), // ???
new BlockInfo(0x23F00, 0x008C, 0x23F9A, 0x23F9A), // Checksums */
};
break;
case GameVersion.B2W2:
Blocks = new[]
{
// Offset, Length, CHKOfst, ChkMirror
new BlockInfo(0x00000, 0x03e0, 0x003E2, 0x25F00), // Box Names
new BlockInfo(0x00400, 0x0ff0, 0x013F2, 0x25F02), // Box 1
new BlockInfo(0x01400, 0x0ff0, 0x023F2, 0x25F04), // Box 2
new BlockInfo(0x02400, 0x0ff0, 0x033F2, 0x25F06), // Box 3
new BlockInfo(0x03400, 0x0ff0, 0x043F2, 0x25F08), // Box 4
new BlockInfo(0x04400, 0x0ff0, 0x053F2, 0x25F0A), // Box 5
new BlockInfo(0x05400, 0x0ff0, 0x063F2, 0x25F0C), // Box 6
new BlockInfo(0x06400, 0x0ff0, 0x073F2, 0x25F0E), // Box 7
new BlockInfo(0x07400, 0x0ff0, 0x083F2, 0x25F10), // Box 8
new BlockInfo(0x08400, 0x0ff0, 0x093F2, 0x25F12), // Box 9
new BlockInfo(0x09400, 0x0ff0, 0x0A3F2, 0x25F14), // Box 10
new BlockInfo(0x0A400, 0x0ff0, 0x0B3F2, 0x25F16), // Box 11
new BlockInfo(0x0B400, 0x0ff0, 0x0C3F2, 0x25F18), // Box 12
new BlockInfo(0x0C400, 0x0ff0, 0x0D3F2, 0x25F1A), // Box 13
new BlockInfo(0x0D400, 0x0ff0, 0x0E3F2, 0x25F1C), // Box 14
new BlockInfo(0x0E400, 0x0ff0, 0x0F3F2, 0x25F1E), // Box 15
new BlockInfo(0x0F400, 0x0ff0, 0x103F2, 0x25F20), // Box 16
new BlockInfo(0x10400, 0x0ff0, 0x113F2, 0x25F22), // Box 17
new BlockInfo(0x11400, 0x0ff0, 0x123F2, 0x25F24), // Box 18
new BlockInfo(0x12400, 0x0ff0, 0x133F2, 0x25F26), // Box 19
new BlockInfo(0x13400, 0x0ff0, 0x143F2, 0x25F28), // Box 20
new BlockInfo(0x14400, 0x0ff0, 0x153F2, 0x25F2A), // Box 21
new BlockInfo(0x15400, 0x0ff0, 0x163F2, 0x25F2C), // Box 22
new BlockInfo(0x16400, 0x0ff0, 0x173F2, 0x25F2E), // Box 23
new BlockInfo(0x17400, 0x0ff0, 0x183F2, 0x25F30), // Box 24
new BlockInfo(0x18400, 0x09ec, 0x18DEE, 0x25F32), // Inventory
new BlockInfo(0x18E00, 0x0534, 0x19336, 0x25F34), // Party Pokemon
new BlockInfo(0x19400, 0x00b0, 0x194B2, 0x25F36), // Trainer Data
new BlockInfo(0x19500, 0x00a8, 0x195AA, 0x25F38), // Trainer Position
new BlockInfo(0x19600, 0x1338, 0x1A93A, 0x25F3A), // Unity Tower and survey stuff
new BlockInfo(0x1AA00, 0x07c4, 0x1B1C6, 0x25F3C), // Pal Pad Player Data (30d)
new BlockInfo(0x1B200, 0x0d54, 0x1BF56, 0x25F3E), // Pal Pad Friend Data
new BlockInfo(0x1C000, 0x0094, 0x1C096, 0x25F40), // Skin Info
new BlockInfo(0x1C100, 0x0658, 0x1C75A, 0x25F42), // Card Signature Block & ????
new BlockInfo(0x1C800, 0x0a94, 0x1D296, 0x25F44), // Mystery Gift
new BlockInfo(0x1D300, 0x01ac, 0x1D4AE, 0x25F46), // Dream World Stuff (Catalog)
new BlockInfo(0x1D500, 0x03ec, 0x1D8EE, 0x25F48), // Chatter
new BlockInfo(0x1D900, 0x005c, 0x1D95E, 0x25F4A), // Adventure data
new BlockInfo(0x1DA00, 0x01e0, 0x1DBE2, 0x25F4C), // Trainer Card Records
new BlockInfo(0x1DC00, 0x00a8, 0x1DCAA, 0x25F4E), // ???
new BlockInfo(0x1DD00, 0x0460, 0x1E162, 0x25F50), // (40d)
new BlockInfo(0x1E200, 0x1400, 0x1F602, 0x25F52), // ???
new BlockInfo(0x1F700, 0x02a4, 0x1F9A6, 0x25F54), // Contains flags and references for downloaded data (Musical)
new BlockInfo(0x1FA00, 0x00e0, 0x1FAE2, 0x25F56), // Fused Reshiram/Zekrom Storage
new BlockInfo(0x1FB00, 0x034c, 0x1FE4E, 0x25F58), // ???
new BlockInfo(0x1FF00, 0x04e0, 0x203E2, 0x25F5A), // Const Data Block and Event Flag Block (0x35E is the split)
new BlockInfo(0x20400, 0x00f8, 0x204FA, 0x25F5C), // ???
new BlockInfo(0x20500, 0x02fc, 0x207FE, 0x25F5E), // Tournament Block
new BlockInfo(0x20800, 0x0094, 0x20896, 0x25F60), // ???
new BlockInfo(0x20900, 0x035c, 0x20C5E, 0x25F62), // Battle Box Block
new BlockInfo(0x20D00, 0x01d4, 0x20ED6, 0x25F64), // Daycare Block (50d)
new BlockInfo(0x20F00, 0x01e0, 0x210E2, 0x25F66), // Strength Boulder Status Block
new BlockInfo(0x21100, 0x00f0, 0x211F2, 0x25F68), // Badge Flags, Money, Trainer Sayings
new BlockInfo(0x21200, 0x01b4, 0x213B6, 0x25F6A), // Entralink (Level & Powers etc)
new BlockInfo(0x21400, 0x04dc, 0x218DE, 0x25F6C), // Pokedex
new BlockInfo(0x21900, 0x0034, 0x21936, 0x25F6E), // Swarm and other overworld info - 2C - swarm, 2D - repel steps, 2E repel type
new BlockInfo(0x21A00, 0x003c, 0x21A3E, 0x25F70), // ???
new BlockInfo(0x21B00, 0x01ac, 0x21CAE, 0x25F72), // ???
new BlockInfo(0x21D00, 0x0b90, 0x22892, 0x25F74), // ???
new BlockInfo(0x22900, 0x00ac, 0x229AE, 0x25F76), // Online Records
new BlockInfo(0x22A00, 0x0850, 0x23252, 0x25F78), // Entralink Forest pokémon data (60d)
new BlockInfo(0x23300, 0x0284, 0x23586, 0x25F7A), // ???
new BlockInfo(0x23600, 0x0010, 0x23612, 0x25F7C), // ???
new BlockInfo(0x23700, 0x00a8, 0x237AA, 0x25F7E), // ???
new BlockInfo(0x23800, 0x016c, 0x2396E, 0x25F80), // ???
new BlockInfo(0x23A00, 0x0080, 0x23A82, 0x25F82), // ???
new BlockInfo(0x23B00, 0x00fc, 0x23BFE, 0x25F84), // Hollow/Rival Block
new BlockInfo(0x23C00, 0x16a8, 0x252AA, 0x25F86), // Join Avenue Block
new BlockInfo(0x25300, 0x0498, 0x2579A, 0x25F88), // Medal data
new BlockInfo(0x25800, 0x0060, 0x25862, 0x25F8A), // Key-related data
new BlockInfo(0x25900, 0x00fc, 0x259FE, 0x25F8C), // (70d)
new BlockInfo(0x25A00, 0x03e4, 0x25DE6, 0x25F8E), // ???
new BlockInfo(0x25E00, 0x00f0, 0x25EF2, 0x25F90), // ???
new BlockInfo(0x25F00, 0x0094, 0x25FA2, 0x25FA2), // Checksum Block (73d)
};
break;
default:
Blocks = new BlockInfo[] { };
break;
}
}
protected override void setChecksums()
protected override void SetChecksums()
{
// Check for invalid block lengths
if (Blocks.Length < 3) // arbitrary...
{
Console.WriteLine("Not enough blocks ({0}), aborting setChecksums", Blocks.Length);
Console.WriteLine("Not enough blocks ({0}), aborting SetChecksums", Blocks.Length);
return;
}
// Apply checksums
foreach (BlockInfo b in Blocks)
{
byte[] array = Data.Skip(b.Offset).Take(b.Length).ToArray();
ushort chk = SaveUtil.ccitt16(array);
ushort chk = SaveUtil.CRC16_CCITT(array);
BitConverter.GetBytes(chk).CopyTo(Data, b.ChecksumOffset);
BitConverter.GetBytes(chk).CopyTo(Data, b.ChecksumMirror);
}
@ -309,14 +309,14 @@ namespace PKHeX.Core
// Check for invalid block lengths
if (Blocks.Length < 3) // arbitrary...
{
Console.WriteLine("Not enough blocks ({0}), aborting setChecksums", Blocks.Length);
Console.WriteLine("Not enough blocks ({0}), aborting SetChecksums", Blocks.Length);
return false;
}
foreach (BlockInfo b in Blocks)
{
byte[] array = Data.Skip(b.Offset).Take(b.Length).ToArray();
ushort chk = SaveUtil.ccitt16(array);
ushort chk = SaveUtil.CRC16_CCITT(array);
if (chk != BitConverter.ToUInt16(Data, b.ChecksumOffset))
return false;
if (chk != BitConverter.ToUInt16(Data, b.ChecksumMirror))
@ -332,7 +332,7 @@ namespace PKHeX.Core
// Check for invalid block lengths
if (Blocks.Length < 3) // arbitrary...
{
Console.WriteLine("Not enough blocks ({0}), aborting setChecksums", Blocks.Length);
Console.WriteLine("Not enough blocks ({0}), aborting SetChecksums", Blocks.Length);
return "Not a valid save to check.";
}
string r = "";
@ -341,7 +341,7 @@ namespace PKHeX.Core
{
BlockInfo b = Blocks[i];
byte[] array = Data.Skip(b.Offset).Take(b.Length).ToArray();
ushort chk = SaveUtil.ccitt16(array);
ushort chk = SaveUtil.CRC16_CCITT(array);
if (chk != BitConverter.ToUInt16(Data, b.ChecksumOffset))
{
r += $"Block {i} has been modified." + Environment.NewLine;
@ -367,34 +367,34 @@ namespace PKHeX.Core
// Daycare
public override int DaycareSeedSize => 16;
public override int getDaycareSlotOffset(int loc, int slot)
public override int GetDaycareSlotOffset(int loc, int slot)
{
return Daycare + 4 + 0xE4 * slot;
}
public override string getDaycareRNGSeed(int loc)
public override string GetDaycareRNGSeed(int loc)
{
if (Version != GameVersion.B2W2)
return null;
var data = Data.Skip(Daycare + 0x1CC).Take(DaycareSeedSize/2).Reverse().ToArray();
return BitConverter.ToString(data).Replace("-", "");
}
public override uint? getDaycareEXP(int loc, int slot)
public override uint? GetDaycareEXP(int loc, int slot)
{
return BitConverter.ToUInt32(Data, Daycare + 4 + 0xDC + slot * 0xE4);
}
public override bool? getDaycareOccupied(int loc, int slot)
public override bool? IsDaycareOccupied(int loc, int slot)
{
return BitConverter.ToUInt32(Data, Daycare + 0xE4*slot) == 1;
}
public override void setDaycareEXP(int loc, int slot, uint EXP)
public override void SetDaycareEXP(int loc, int slot, uint EXP)
{
BitConverter.GetBytes(EXP).CopyTo(Data, Daycare + 4 + 0xDC + slot * 0xE4);
}
public override void setDaycareOccupied(int loc, int slot, bool occupied)
public override void SetDaycareOccupied(int loc, int slot, bool occupied)
{
BitConverter.GetBytes((uint)(occupied ? 1 : 0)).CopyTo(Data, Daycare + 0x1CC);
}
public override void setDaycareRNGSeed(int loc, string seed)
public override void SetDaycareRNGSeed(int loc, string seed)
{
if (Version != GameVersion.B2W2)
return;
@ -419,13 +419,13 @@ namespace PKHeX.Core
new InventoryPouch(InventoryType.Berries, LegalBerries, 999, OFS_PouchBerry),
};
foreach (var p in pouch)
p.getPouch(ref Data);
p.GetPouch(ref Data);
return pouch;
}
set
{
foreach (var p in value)
p.setPouch(ref Data);
p.SetPouch(ref Data);
}
}
@ -435,21 +435,21 @@ namespace PKHeX.Core
get => Data[Party + 4];
protected set => Data[Party + 4] = (byte)value;
}
public override int getBoxOffset(int box)
public override int GetBoxOffset(int box)
{
return Box + SIZE_STORED * box * 30 + box * 0x10;
}
public override int getPartyOffset(int slot)
public override int GetPartyOffset(int slot)
{
return Party + 8 + SIZE_PARTY*slot;
}
public override string getBoxName(int box)
public override string GetBoxName(int box)
{
if (box >= BoxCount)
return "";
return PKX.TrimFromFFFF(Encoding.Unicode.GetString(Data, PCLayout + 0x28 * box + 4, 0x28));
}
public override void setBoxName(int box, string val)
public override void SetBoxName(int box, string val)
{
if (val.Length > 38)
return;
@ -457,7 +457,7 @@ namespace PKHeX.Core
Encoding.Unicode.GetBytes(val.PadRight(0x14, '\0')).CopyTo(Data, PCLayout + 0x28 * box + 4);
Edited = true;
}
protected override int getBoxWallpaperOffset(int box)
protected override int GetBoxWallpaperOffset(int box)
{
return PCLayout + 0x3C4 + box;
}
@ -471,13 +471,13 @@ namespace PKHeX.Core
get => BattleBox >= 0 && Data[BattleBox + 0x358] != 0; // wifi/live
set { }
}
public override PKM getPKM(byte[] data)
public override PKM GetPKM(byte[] data)
{
return new PK5(data);
}
public override byte[] decryptPKM(byte[] data)
public override byte[] DecryptPKM(byte[] data)
{
return PKX.decryptArray45(data);
return PKX.DecryptArray45(data);
}
// Mystery Gift
@ -529,8 +529,8 @@ namespace PKHeX.Core
// Trainer Info
public override string OT
{
get => getString(Trainer1 + 0x4, 16);
set => setString(value, OTLength).CopyTo(Data, Trainer1 + 0x4);
get => GetString(Trainer1 + 0x4, 16);
set => SetString(value, OTLength).CopyTo(Data, Trainer1 + 0x4);
}
public override ushort TID
{
@ -606,7 +606,7 @@ namespace PKHeX.Core
public override int SecondsToStart { get => BitConverter.ToInt32(Data, AdventureInfo + 0x34); set => BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x34); }
public override int SecondsToFame { get => BitConverter.ToInt32(Data, AdventureInfo + 0x3C); set => BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x3C); }
protected override void setDex(PKM pkm)
protected override void SetDex(PKM pkm)
{
if (pkm.Species == 0)
return;
@ -647,7 +647,7 @@ namespace PKHeX.Core
// Formes
int fc = Personal[pkm.Species].FormeCount;
int f = B2W2 ? SaveUtil.getDexFormIndexB2W2(pkm.Species, fc) : SaveUtil.getDexFormIndexBW(pkm.Species, fc);
int f = B2W2 ? SaveUtil.GetDexFormIndexB2W2(pkm.Species, fc) : SaveUtil.GetDexFormIndexBW(pkm.Species, fc);
if (f < 0) return;
int FormLen = B2W2 ? 0xB : 0x9;
@ -670,7 +670,7 @@ namespace PKHeX.Core
Data[FormDex + FormLen * (2 + shiny) + (bit>>3)] |= (byte)(1 << (bit&7));
}
public override bool getCaught(int species)
public override bool GetCaught(int species)
{
int bit = species - 1;
int bd = bit >> 3; // div8
@ -679,7 +679,7 @@ namespace PKHeX.Core
+ 0x08; // Magic + Flags
return (1 << bm & Data[ofs + bd]) != 0;
}
public override bool getSeen(int species)
public override bool GetSeen(int species)
{
const int brSize = 0x54;
@ -695,12 +695,12 @@ namespace PKHeX.Core
return false;
}
public override string getString(int Offset, int Count) => PKX.getString5(Data, Offset, Count);
public override byte[] setString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
public override string GetString(int Offset, int Count) => PKX.GetString5(Data, Offset, Count);
public override byte[] SetString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
{
if (PadToSize == 0)
PadToSize = maxLength + 1;
return PKX.setString5(value, maxLength, PadToSize, PadWith);
return PKX.SetString5(value, maxLength, PadToSize, PadWith);
}
}
}

View file

@ -17,20 +17,20 @@ namespace PKHeX.Core
Exportable = !Data.SequenceEqual(new byte[Data.Length]);
// Load Info
getBlockInfo();
getSAVOffsets();
GetBlockInfo();
GetSAVOffsets();
HeldItems = ORAS ? Legal.HeldItem_AO : Legal.HeldItem_XY;
Personal = ORAS ? PersonalTable.AO : PersonalTable.XY;
if (!Exportable)
resetBoxes();
ClearBoxes();
}
// Configuration
public override SaveFile Clone() { return new SAV6(Data); }
public override int SIZE_STORED => PKX.SIZE_6STORED;
public override int SIZE_PARTY => PKX.SIZE_6PARTY;
protected override int SIZE_PARTY => PKX.SIZE_6PARTY;
public override PKM BlankPKM => new PK6();
public override Type PKMType => typeof(PK6);
@ -57,7 +57,7 @@ namespace PKHeX.Core
// Blocks & Offsets
private int BlockInfoOffset;
private BlockInfo[] Blocks;
private void getBlockInfo()
private void GetBlockInfo()
{
BlockInfoOffset = Data.Length - 0x200 + 0x10;
if (BitConverter.ToUInt32(Data, BlockInfoOffset) != SaveUtil.BEEF)
@ -87,12 +87,12 @@ namespace PKHeX.Core
// Fix Final Array Lengths
Array.Resize(ref Blocks, count);
}
protected override void setChecksums()
protected override void SetChecksums()
{
// Check for invalid block lengths
if (Blocks.Length < 3) // arbitrary...
{
Console.WriteLine("Not enough blocks ({0}), aborting setChecksums", Blocks.Length);
Console.WriteLine("Not enough blocks ({0}), aborting SetChecksums", Blocks.Length);
return;
}
// Apply checksums
@ -102,7 +102,7 @@ namespace PKHeX.Core
{ Console.WriteLine("Block {0} has invalid offset/length value.", i); return; }
byte[] array = new byte[Blocks[i].Length];
Array.Copy(Data, Blocks[i].Offset, array, 0, array.Length);
BitConverter.GetBytes(SaveUtil.ccitt16(array)).CopyTo(Data, BlockInfoOffset + 6 + i * 8);
BitConverter.GetBytes(SaveUtil.CRC16_CCITT(array)).CopyTo(Data, BlockInfoOffset + 6 + i * 8);
}
}
public override bool ChecksumsValid
@ -115,7 +115,7 @@ namespace PKHeX.Core
return false;
byte[] array = new byte[Blocks[i].Length];
Array.Copy(Data, Blocks[i].Offset, array, 0, array.Length);
if (SaveUtil.ccitt16(array) != BitConverter.ToUInt16(Data, BlockInfoOffset + 6 + i * 8))
if (SaveUtil.CRC16_CCITT(array) != BitConverter.ToUInt16(Data, BlockInfoOffset + 6 + i * 8))
return false;
}
return true;
@ -133,7 +133,7 @@ namespace PKHeX.Core
return $"Block {i} Invalid Offset/Length.";
byte[] array = new byte[Blocks[i].Length];
Array.Copy(Data, Blocks[i].Offset, array, 0, array.Length);
if (SaveUtil.ccitt16(array) == BitConverter.ToUInt16(Data, BlockInfoOffset + 6 + i * 8))
if (SaveUtil.CRC16_CCITT(array) == BitConverter.ToUInt16(Data, BlockInfoOffset + 6 + i * 8))
continue;
invalid++;
@ -155,11 +155,11 @@ namespace PKHeX.Core
set => BitConverter.GetBytes(value ?? 0).CopyTo(Data, BlockInfoOffset - 0xC);
}
private void getSAVOffsets()
private void GetSAVOffsets()
{
if (ORASDEMO)
{
/* 00: */ Item = 0x00000;
/* 00: */ Bag = 0x00000;
/* 01: */ ItemInfo = 0x00C00; // Select Bound Items
/* 02: */ AdventureInfo = 0x00E00;
/* 03: */ Trainer1 = 0x01000;
@ -176,16 +176,16 @@ namespace PKHeX.Core
/* 14: */ SUBE = 0x05000;
/* 15: */ PSSStats = 0x05400;
OFS_PouchHeldItem = Item + 0;
OFS_PouchKeyItem = Item + 0x640;
OFS_PouchTMHM = Item + 0x7C0;
OFS_PouchMedicine = Item + 0x970;
OFS_PouchBerry = Item + 0xA70;
OFS_PouchHeldItem = Bag + 0;
OFS_PouchKeyItem = Bag + 0x640;
OFS_PouchTMHM = Bag + 0x7C0;
OFS_PouchMedicine = Bag + 0x970;
OFS_PouchBerry = Bag + 0xA70;
}
else if (XY)
{
Puff = 0x00000;
Item = 0x00400;
Bag = 0x00400;
ItemInfo = 0x1000;
AdventureInfo = 0x01200;
Trainer1 = 0x1400;
@ -222,16 +222,16 @@ namespace PKHeX.Core
Spinda = PokeDex + 0x648;
WondercardData = WondercardFlags + 0x100;
OFS_PouchHeldItem = Item + 0;
OFS_PouchKeyItem = Item + 0x640;
OFS_PouchTMHM = Item + 0x7C0;
OFS_PouchMedicine = Item + 0x968;
OFS_PouchBerry = Item + 0xA68;
OFS_PouchHeldItem = Bag + 0;
OFS_PouchKeyItem = Bag + 0x640;
OFS_PouchTMHM = Bag + 0x7C0;
OFS_PouchMedicine = Bag + 0x968;
OFS_PouchBerry = Bag + 0xA68;
}
else if (ORAS)
{
Puff = 0x00000;
Item = 0x00400;
Bag = 0x00400;
ItemInfo = 0x1000;
AdventureInfo = 0x01200;
Trainer1 = 0x01400;
@ -273,11 +273,11 @@ namespace PKHeX.Core
WondercardData = WondercardFlags + 0x100;
Daycare2 = Daycare + 0x1F0;
OFS_PouchHeldItem = Item + 0;
OFS_PouchKeyItem = Item + 0x640;
OFS_PouchTMHM = Item + 0x7C0;
OFS_PouchMedicine = Item + 0x970;
OFS_PouchBerry = Item + 0xA70;
OFS_PouchHeldItem = Bag + 0;
OFS_PouchKeyItem = Bag + 0x640;
OFS_PouchTMHM = Bag + 0x7C0;
OFS_PouchMedicine = Bag + 0x970;
OFS_PouchBerry = Bag + 0xA70;
}
else // Empty input
{
@ -287,7 +287,7 @@ namespace PKHeX.Core
}
// Private Only
private int Item { get; set; } = int.MinValue;
private int Bag { get; set; } = int.MinValue;
private int AdventureInfo { get; set; } = int.MinValue;
private int Trainer2 { get; set; } = int.MinValue;
private int LastViewedBox { get; set; } = int.MinValue;
@ -395,8 +395,8 @@ namespace PKHeX.Core
}
public override string OT
{
get => getString(TrainerCard + 0x48, 0x1A);
set => setString(value, OTLength).CopyTo(Data, TrainerCard + 0x48);
get => GetString(TrainerCard + 0x48, 0x1A);
set => SetString(value, OTLength).CopyTo(Data, TrainerCard + 0x48);
}
public string OT_Nick
{
@ -555,38 +555,38 @@ namespace PKHeX.Core
public override int SecondsToStart { get => BitConverter.ToInt32(Data, AdventureInfo + 0x18); set => BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x18); }
public override int SecondsToFame { get => BitConverter.ToInt32(Data, AdventureInfo + 0x20); set => BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x20); }
public uint getPSSStat(int index) { return BitConverter.ToUInt32(Data, PSSStats + 4*index); }
public void setPSSStat(int index, uint value) { BitConverter.GetBytes(value).CopyTo(Data, PSSStats + 4*index); }
public ushort getMaisonStat(int index) { return BitConverter.ToUInt16(Data, MaisonStats + 2 * index); }
public void setMaisonStat(int index, ushort value) { BitConverter.GetBytes(value).CopyTo(Data, MaisonStats + 2*index); }
public uint getEncounterCount(int index) { return BitConverter.ToUInt16(Data, EncounterCount + 2*index); }
public void setEncounterCount(int index, ushort value) { BitConverter.GetBytes(value).CopyTo(Data, EncounterCount + 2*index); }
public uint GetPSSStat(int index) { return BitConverter.ToUInt32(Data, PSSStats + 4*index); }
public void SetPSSStat(int index, uint value) { BitConverter.GetBytes(value).CopyTo(Data, PSSStats + 4*index); }
public ushort GetMaisonStat(int index) { return BitConverter.ToUInt16(Data, MaisonStats + 2 * index); }
public void SetMaisonStat(int index, ushort value) { BitConverter.GetBytes(value).CopyTo(Data, MaisonStats + 2*index); }
public uint GetEncounterCount(int index) { return BitConverter.ToUInt16(Data, EncounterCount + 2*index); }
public void SetEncounterCount(int index, ushort value) { BitConverter.GetBytes(value).CopyTo(Data, EncounterCount + 2*index); }
// Daycare
public override int DaycareSeedSize => 16;
public override bool HasTwoDaycares => ORAS;
public override int getDaycareSlotOffset(int loc, int slot)
public override int GetDaycareSlotOffset(int loc, int slot)
{
int ofs = loc == 0 ? Daycare : Daycare2;
if (ofs < 0)
return -1;
return ofs + 8 + slot*(SIZE_STORED + 8);
}
public override uint? getDaycareEXP(int loc, int slot)
public override uint? GetDaycareEXP(int loc, int slot)
{
int ofs = loc == 0 ? Daycare : Daycare2;
if (ofs > -1)
return BitConverter.ToUInt32(Data, ofs + (SIZE_STORED + 8)*slot + 4);
return null;
}
public override bool? getDaycareOccupied(int loc, int slot)
public override bool? IsDaycareOccupied(int loc, int slot)
{
int ofs = loc == 0 ? Daycare : Daycare2;
if (ofs > -1)
return Data[ofs + (SIZE_STORED + 8) * slot] == 1;
return null;
}
public override string getDaycareRNGSeed(int loc)
public override string GetDaycareRNGSeed(int loc)
{
int ofs = loc == 0 ? Daycare : Daycare2;
if (ofs <= 0)
@ -595,26 +595,26 @@ namespace PKHeX.Core
var data = Data.Skip(ofs + 0x1E8).Take(DaycareSeedSize/2).Reverse().ToArray();
return BitConverter.ToString(data).Replace("-", "");
}
public override bool? getDaycareHasEgg(int loc)
public override bool? IsDaycareHasEgg(int loc)
{
int ofs = loc == 0 ? Daycare : Daycare2;
if (ofs > -1)
return Data[ofs + 0x1E0] == 1;
return null;
}
public override void setDaycareEXP(int loc, int slot, uint EXP)
public override void SetDaycareEXP(int loc, int slot, uint EXP)
{
int ofs = loc == 0 ? Daycare : Daycare2;
if (ofs > -1)
BitConverter.GetBytes(EXP).CopyTo(Data, ofs + (SIZE_STORED + 8)*slot + 4);
}
public override void setDaycareOccupied(int loc, int slot, bool occupied)
public override void SetDaycareOccupied(int loc, int slot, bool occupied)
{
int ofs = loc == 0 ? Daycare : Daycare2;
if (ofs > -1)
Data[ofs + (SIZE_STORED + 8)*slot] = (byte) (occupied ? 1 : 0);
}
public override void setDaycareRNGSeed(int loc, string seed)
public override void SetDaycareRNGSeed(int loc, string seed)
{
if (loc != 0)
return;
@ -630,14 +630,14 @@ namespace PKHeX.Core
.Select(x => Convert.ToByte(seed.Substring(x, 2), 16))
.Reverse().ToArray().CopyTo(Data, Daycare + 0x1E8);
}
public override void setDaycareHasEgg(int loc, bool hasEgg)
public override void SetDaycareHasEgg(int loc, bool hasEgg)
{
int ofs = loc == 0 ? Daycare : Daycare2;
if (ofs > -1)
Data[ofs + 0x1E0] = (byte)(hasEgg ? 1 : 0);
}
public byte[] Puffs { get => getData(Puff, 100); set => value.CopyTo(Data, Puff); }
public byte[] Puffs { get => GetData(Puff, 100); set => value.CopyTo(Data, Puff); }
public int PuffCount { get => BitConverter.ToInt32(Data, Puff + 100); set => BitConverter.GetBytes(value).CopyTo(Data, Puff + 100); }
public int[] SelectItems
@ -678,7 +678,7 @@ namespace PKHeX.Core
}
public override string JPEGTitle => JPEG < 0 ? null : Util.TrimFromZero(Encoding.Unicode.GetString(Data, JPEG, 0x1A));
public override byte[] JPEGData => JPEG < 0 || Data[JPEG + 0x54] != 0xFF ? null : getData(JPEG + 0x54, 0xE004);
public override byte[] JPEGData => JPEG < 0 || Data[JPEG + 0x54] != 0xFF ? null : GetData(JPEG + 0x54, 0xE004);
// Inventory
public override InventoryPouch[] Inventory
@ -698,49 +698,49 @@ namespace PKHeX.Core
new InventoryPouch(InventoryType.Berries, Legal.Pouch_Berry_XY, 999, OFS_PouchBerry),
};
foreach (var p in pouch)
p.getPouch(ref Data);
p.GetPouch(ref Data);
return pouch;
}
set
{
foreach (var p in value)
p.setPouch(ref Data);
p.SetPouch(ref Data);
}
}
// Storage
public override int CurrentBox { get => Data[LastViewedBox]; set => Data[LastViewedBox] = (byte)value; }
public override int getPartyOffset(int slot)
public override int GetPartyOffset(int slot)
{
return Party + SIZE_PARTY * slot;
}
public override int getBoxOffset(int box)
public override int GetBoxOffset(int box)
{
return Box + SIZE_STORED*box*30;
}
protected override int getBoxWallpaperOffset(int box)
protected override int GetBoxWallpaperOffset(int box)
{
int ofs = PCBackgrounds > 0 && PCBackgrounds < Data.Length ? PCBackgrounds : -1;
if (ofs > -1)
return ofs + box;
return ofs;
}
public override string getBoxName(int box)
public override string GetBoxName(int box)
{
if (PCLayout < 0)
return "B" + (box + 1);
return Util.TrimFromZero(Encoding.Unicode.GetString(Data, PCLayout + 0x22*box, 0x22));
}
public override void setBoxName(int box, string val)
public override void SetBoxName(int box, string val)
{
Encoding.Unicode.GetBytes(val.PadRight(0x11, '\0')).CopyTo(Data, PCLayout + 0x22*box);
Edited = true;
}
public override PKM getPKM(byte[] data)
public override PKM GetPKM(byte[] data)
{
return new PK6(data);
}
protected override void setPKM(PKM pkm)
protected override void SetPKM(PKM pkm)
{
PK6 pk6 = pkm as PK6;
// Apply to this Save File
@ -757,7 +757,7 @@ namespace PKHeX.Core
}
pkm.RefreshChecksum();
}
protected override void setDex(PKM pkm)
protected override void SetDex(PKM pkm)
{
if (PokeDex < 0)
return;
@ -803,12 +803,12 @@ namespace PKHeX.Core
Data[PokeDexLanguageFlags + (bit * 7 + lang) / 8] |= (byte)(1 << ((bit * 7 + lang) % 8));
// Set DexNav count (only if not encountered previously)
if (ORAS && getEncounterCount(pkm.Species - 1) == 0)
setEncounterCount(pkm.Species - 1, 1);
if (ORAS && GetEncounterCount(pkm.Species - 1) == 0)
SetEncounterCount(pkm.Species - 1, 1);
// Set Form flags
int fc = Personal[pkm.Species].FormeCount;
int f = ORAS ? SaveUtil.getDexFormIndexORAS(pkm.Species, fc) : SaveUtil.getDexFormIndexXY(pkm.Species, fc);
int f = ORAS ? SaveUtil.GetDexFormIndexORAS(pkm.Species, fc) : SaveUtil.GetDexFormIndexXY(pkm.Species, fc);
if (f < 0) return;
int FormLen = ORAS ? 0x26 : 0x18;
@ -830,7 +830,7 @@ namespace PKHeX.Core
bit = f + pkm.AltForm;
Data[FormDex + FormLen * (2 + shiny) + bit / 8] |= (byte)(1 << (bit % 8));
}
protected override void setPartyValues(PKM pkm, bool isParty)
protected override void SetPartyValues(PKM pkm, bool isParty)
{
uint duration = 0;
if (isParty && pkm.AltForm != 0)
@ -847,7 +847,7 @@ namespace PKHeX.Core
((PK6)pkm).FormDuration = duration;
}
public override bool getCaught(int species)
public override bool GetCaught(int species)
{
int bit = species - 1;
int bd = bit >> 3; // div8
@ -863,7 +863,7 @@ namespace PKHeX.Core
return (1 << bm & Data[ofs + bd + 0x644]) != 0;
}
public override bool getSeen(int species)
public override bool GetSeen(int species)
{
const int brSize = 0x60;
@ -879,9 +879,9 @@ namespace PKHeX.Core
return true;
return false;
}
public override byte[] decryptPKM(byte[] data)
public override byte[] DecryptPKM(byte[] data)
{
return PKX.decryptArray(data);
return PKX.DecryptArray(data);
}
public override int PartyCount
{
@ -942,7 +942,7 @@ namespace PKHeX.Core
return null;
MysteryGift[] cards = new MysteryGift[GiftCountMax];
for (int i = 0; i < cards.Length; i++)
cards[i] = getWC6(i);
cards[i] = GetWC6(i);
return cards;
}
@ -954,9 +954,9 @@ namespace PKHeX.Core
Array.Resize(ref value, GiftCountMax);
for (int i = 0; i < value.Length; i++)
setWC6(value[i], i);
SetWC6(value[i], i);
for (int i = value.Length; i < GiftCountMax; i++)
setWC6(new WC6(), i);
SetWC6(new WC6(), i);
}
}
@ -966,7 +966,7 @@ namespace PKHeX.Core
{
if (LinkInfo < 0)
return null;
return getData(LinkInfo, 0xC48);
return GetData(LinkInfo, 0xC48);
}
set
{
@ -978,16 +978,16 @@ namespace PKHeX.Core
}
}
private MysteryGift getWC6(int index)
private MysteryGift GetWC6(int index)
{
if (WondercardData < 0)
return null;
if (index < 0 || index > GiftCountMax)
return null;
return new WC6(getData(WondercardData + index * WC6.Size, WC6.Size));
return new WC6(GetData(WondercardData + index * WC6.Size, WC6.Size));
}
private void setWC6(MysteryGift wc6, int index)
private void SetWC6(MysteryGift wc6, int index)
{
if (WondercardData < 0)
return;
@ -1027,12 +1027,12 @@ namespace PKHeX.Core
$"{b.ID:00}: {b.Offset:X5}-{b.Offset + b.Length:X5}, {b.Length:X5}{Environment.NewLine}");
}
public override string getString(int Offset, int Count) => PKX.getString6(Data, Offset, Count);
public override byte[] setString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
public override string GetString(int Offset, int Count) => PKX.GetString6(Data, Offset, Count);
public override byte[] SetString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
{
if (PadToSize == 0)
PadToSize = maxLength + 1;
return PKX.setString6(value, maxLength, PadToSize, PadWith);
return PKX.SetString6(value, maxLength, PadToSize, PadWith);
}
}
}

View file

@ -23,13 +23,13 @@ namespace PKHeX.Core
Exportable = !Data.SequenceEqual(new byte[Data.Length]);
// Load Info
getBlockInfo();
getSAVOffsets();
GetBlockInfo();
GetSAVOffsets();
HeldItems = Legal.HeldItems_SM;
Personal = PersonalTable.SM;
if (!Exportable)
resetBoxes();
ClearBoxes();
var demo = new byte[0x4C4].SequenceEqual(Data.Skip(PCLayout).Take(0x4C4)); // up to Battle Box values
if (demo || !Exportable)
@ -66,7 +66,7 @@ namespace PKHeX.Core
public override SaveFile Clone() { return new SAV7(Data); }
public override int SIZE_STORED => PKX.SIZE_6STORED;
public override int SIZE_PARTY => PKX.SIZE_6PARTY;
protected override int SIZE_PARTY => PKX.SIZE_6PARTY;
public override PKM BlankPKM => new PK7();
public override Type PKMType => typeof(PK7);
@ -95,7 +95,7 @@ namespace PKHeX.Core
// Blocks & Offsets
private int BlockInfoOffset;
private BlockInfo[] Blocks;
private void getBlockInfo()
private void GetBlockInfo()
{
BlockInfoOffset = Data.Length - 0x200 + 0x10;
if (BitConverter.ToUInt32(Data, BlockInfoOffset) != SaveUtil.BEEF)
@ -125,12 +125,12 @@ namespace PKHeX.Core
// Fix Final Array Lengths
Array.Resize(ref Blocks, count);
}
protected override void setChecksums()
protected override void SetChecksums()
{
// Check for invalid block lengths
if (Blocks.Length < 3) // arbitrary...
{
Console.WriteLine("Not enough blocks ({0}), aborting setChecksums", Blocks.Length);
Console.WriteLine("Not enough blocks ({0}), aborting SetChecksums", Blocks.Length);
return;
}
// Apply checksums
@ -140,7 +140,7 @@ namespace PKHeX.Core
{ Console.WriteLine("Block {0} has invalid offset/length value.", i); return; }
byte[] array = new byte[Blocks[i].Length];
Array.Copy(Data, Blocks[i].Offset, array, 0, array.Length);
BitConverter.GetBytes(SaveUtil.check16(array, Blocks[i].ID)).CopyTo(Data, BlockInfoOffset + 6 + i * 8);
BitConverter.GetBytes(SaveUtil.CRC16_7(array, Blocks[i].ID)).CopyTo(Data, BlockInfoOffset + 6 + i * 8);
}
Data = SaveUtil.Resign7(Data);
@ -155,7 +155,7 @@ namespace PKHeX.Core
return false;
byte[] array = new byte[Blocks[i].Length];
Array.Copy(Data, Blocks[i].Offset, array, 0, array.Length);
if (SaveUtil.check16(array, Blocks[i].ID) != BitConverter.ToUInt16(Data, BlockInfoOffset + 6 + i * 8))
if (SaveUtil.CRC16_7(array, Blocks[i].ID) != BitConverter.ToUInt16(Data, BlockInfoOffset + 6 + i * 8))
return false;
}
return true;
@ -173,7 +173,7 @@ namespace PKHeX.Core
return $"Block {i} Invalid Offset/Length.";
byte[] array = new byte[Blocks[i].Length];
Array.Copy(Data, Blocks[i].Offset, array, 0, array.Length);
if (SaveUtil.check16(array, Blocks[i].ID) == BitConverter.ToUInt16(Data, BlockInfoOffset + 6 + i * 8))
if (SaveUtil.CRC16_7(array, Blocks[i].ID) == BitConverter.ToUInt16(Data, BlockInfoOffset + 6 + i * 8))
continue;
invalid++;
@ -195,11 +195,11 @@ namespace PKHeX.Core
set => BitConverter.GetBytes(value ?? 0).CopyTo(Data, BlockInfoOffset - 0xC);
}
private void getSAVOffsets()
private void GetSAVOffsets()
{
if (SM)
{
/* 00 */ Item = 0x00000; // [DE0] MyItem
/* 00 */ Bag = 0x00000; // [DE0] MyItem
/* 01 */ Trainer1 = 0x00E00; // [07C] Situation
/* 02 */ // = 0x01000; // [014] RandomGroup
/* 03 */ TrainerCard = 0x01200; // [0C0] MyStatus
@ -239,12 +239,12 @@ namespace PKHeX.Core
EventFlag = EventConst + 0x7D0;
OFS_PouchHeldItem = Item + 0; // 430 (Case 0)
OFS_PouchKeyItem = Item + 0x6B8; // 184 (Case 4)
OFS_PouchTMHM = Item + 0x998; // 108 (Case 2)
OFS_PouchMedicine = Item + 0xB48; // 64 (Case 1)
OFS_PouchBerry = Item + 0xC48; // 72 (Case 3)
OFS_PouchZCrystals = Item + 0xD68; // 30 (Case 5)
OFS_PouchHeldItem = Bag + 0; // 430 (Case 0)
OFS_PouchKeyItem = Bag + 0x6B8; // 184 (Case 4)
OFS_PouchTMHM = Bag + 0x998; // 108 (Case 2)
OFS_PouchMedicine = Bag + 0xB48; // 64 (Case 1)
OFS_PouchBerry = Bag + 0xC48; // 72 (Case 3)
OFS_PouchZCrystals = Bag + 0xD68; // 30 (Case 5)
PokeDexLanguageFlags = PokeDex + 0x550;
WondercardData = WondercardFlags + 0x100;
@ -270,7 +270,7 @@ namespace PKHeX.Core
}
// Private Only
private int Item { get; set; } = int.MinValue;
private int Bag { get; set; } = int.MinValue;
private int AdventureInfo { get; set; } = int.MinValue;
private int Trainer2 { get; set; } = int.MinValue;
private int Misc { get; set; } = int.MinValue;
@ -286,18 +286,18 @@ namespace PKHeX.Core
private int TeamCount { get; set; } = int.MinValue;
// Accessible as SAV7
public int TrainerCard { get; private set; } = 0x14000;
public int Resort { get; set; }
public int PCFlags { get; private set; } = int.MinValue;
private int TrainerCard { get; set; } = 0x14000;
private int Resort { get; set; }
private int PCFlags { get; set; } = int.MinValue;
public int PSSStats { get; private set; } = int.MinValue;
public int MaisonStats { get; private set; } = int.MinValue;
public int PCBackgrounds { get; private set; } = int.MinValue;
private int PCBackgrounds { get; set; } = int.MinValue;
public int Contest { get; private set; } = int.MinValue;
public int Accessories { get; private set; } = int.MinValue;
public int PokeDexLanguageFlags { get; private set; } = int.MinValue;
public int Fashion { get; set; } = int.MinValue;
public int FashionLength { get; set; } = int.MinValue;
public int Record { get; set; } = int.MinValue;
private int Record { get; set; } = int.MinValue;
private const int ResortCount = 93;
public PKM[] ResortPKM
@ -307,7 +307,7 @@ namespace PKHeX.Core
PKM[] data = new PKM[ResortCount];
for (int i = 0; i < data.Length; i++)
{
data[i] = getPKM(getData(Resort + 0x12 + i * SIZE_STORED, SIZE_STORED));
data[i] = GetPKM(GetData(Resort + 0x12 + i * SIZE_STORED, SIZE_STORED));
data[i].Identifier = $"Resort Slot {i}";
}
return data;
@ -318,7 +318,7 @@ namespace PKHeX.Core
throw new ArgumentException();
for (int i = 0; i < value.Length; i++)
setStoredSlot(value[i], Resort + 0x12 + i*SIZE_STORED);
SetStoredSlot(value[i], Resort + 0x12 + i*SIZE_STORED);
}
}
@ -378,7 +378,7 @@ namespace PKHeX.Core
.ToArray().CopyTo(Data, TrainerCard + 0x10);
}
}
public int NexUniqueIDSize => 32; // 128 bits
private const int NexUniqueIDSize = 32; // 128 bits
public string NexUniqueID
{
get
@ -422,8 +422,8 @@ namespace PKHeX.Core
}
public override string OT
{
get => getString(TrainerCard + 0x38, 0x1A);
set => setString(value, OTLength).CopyTo(Data, TrainerCard + 0x38);
get => GetString(TrainerCard + 0x38, 0x1A);
set => SetString(value, OTLength).CopyTo(Data, TrainerCard + 0x38);
}
public int DressUpSkinColor
{
@ -554,7 +554,7 @@ namespace PKHeX.Core
Encoding.Unicode.GetBytes(value.PadRight(value.Length + 1, '\0')).CopyTo(Data, JoinFestaData + 0x510);
}
}
public struct FashionItem
public sealed class FashionItem
{
public bool IsOwned;
public bool IsNew;
@ -563,14 +563,14 @@ namespace PKHeX.Core
{
get
{
var data = getData(Fashion, 0x5A8);
var data = GetData(Fashion, 0x5A8);
return data.Select(b => new FashionItem {IsOwned = (b & 1) != 0, IsNew = (b & 2) != 0}).ToArray();
}
set
{
if (value.Length != 0x5A8)
throw new ArgumentOutOfRangeException($"Unexpected size: 0x{value.Length:X}");
setData(value.Select(t => (byte) ((t.IsOwned ? 1 : 0) | (t.IsNew ? 2 : 0))).ToArray(), Fashion);
SetData(value.Select(t => (byte) ((t.IsOwned ? 1 : 0) | (t.IsNew ? 2 : 0))).ToArray(), Fashion);
}
}
@ -637,19 +637,19 @@ namespace PKHeX.Core
public ulong AlolaTime { get => BitConverter.ToUInt64(Data, AdventureInfo + 0x48); set => BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x48); }
// Stat Records
public int getRecord(int recordID)
public int GetRecord(int recordID)
{
int ofs = getRecordOffset(recordID);
int ofs = GetRecordOffset(recordID);
if (recordID < 100)
return BitConverter.ToInt32(Data, ofs);
if (recordID < 200)
return BitConverter.ToInt16(Data, ofs);
return 0;
}
public void setRecord(int recordID, int value)
public void SetRecord(int recordID, int value)
{
int ofs = getRecordOffset(recordID);
int max = getRecordMax(recordID);
int ofs = GetRecordOffset(recordID);
int max = GetRecordMax(recordID);
if (value > max)
value = max;
if (recordID < 100)
@ -657,7 +657,7 @@ namespace PKHeX.Core
if (recordID < 200)
BitConverter.GetBytes((ushort)value).CopyTo(Data, ofs);
}
public int getRecordOffset(int recordID)
public int GetRecordOffset(int recordID)
{
if (recordID < 100)
return Record + recordID*4;
@ -666,7 +666,7 @@ namespace PKHeX.Core
return -1;
}
public int getRecordMax(int recordID) => recordID < 200 ? RecordMax[RecordMaxType[recordID]] : 0;
public static int GetRecordMax(int recordID) => recordID < 200 ? RecordMax[RecordMaxType[recordID]] : 0;
private static readonly int[] RecordMax = {999999999, 9999999, 999999, 99999, 65535, 9999, 999};
private static readonly int[] RecordMaxType =
{
@ -752,18 +752,18 @@ namespace PKHeX.Core
new InventoryPouch(InventoryType.ZCrystals, Legal.Pouch_ZCrystal_SM, 1, OFS_PouchZCrystals),
};
foreach (var p in pouch)
p.getPouch7(ref Data);
p.GetPouch7(ref Data);
return pouch;
}
set
{
foreach (var p in value)
p.setPouch7(ref Data);
p.SetPouch7(ref Data);
}
}
// Battle Tree
public int getTreeStreak(int battletype, bool super, bool max)
public int GetTreeStreak(int battletype, bool super, bool max)
{
if (battletype > 3)
throw new ArgumentException();
@ -776,7 +776,7 @@ namespace PKHeX.Core
return BitConverter.ToUInt16(Data, BattleTree + offset);
}
public void setTreeStreak(int value, int battletype, bool super, bool max)
public void SetTreeStreak(int value, int battletype, bool super, bool max)
{
if (battletype > 3)
throw new ArgumentException();
@ -813,44 +813,44 @@ namespace PKHeX.Core
// Storage
public override int CurrentBox { get => Data[LastViewedBox]; set => Data[LastViewedBox] = (byte)value; }
public override int getPartyOffset(int slot)
public override int GetPartyOffset(int slot)
{
return Party + SIZE_PARTY * slot;
}
public override int getBoxOffset(int box)
public override int GetBoxOffset(int box)
{
return Box + SIZE_STORED*box*30;
}
protected override int getBoxWallpaperOffset(int box)
protected override int GetBoxWallpaperOffset(int box)
{
int ofs = PCBackgrounds > 0 && PCBackgrounds < Data.Length ? PCBackgrounds : -1;
if (ofs > -1)
return ofs + box;
return ofs;
}
public override void setBoxWallpaper(int box, int value)
public override void SetBoxWallpaper(int box, int value)
{
if (PCBackgrounds < 0)
return;
int ofs = PCBackgrounds > 0 && PCBackgrounds < Data.Length ? PCBackgrounds : 0;
Data[ofs + box] = (byte)value;
}
public override string getBoxName(int box)
public override string GetBoxName(int box)
{
if (PCLayout < 0)
return "B" + (box + 1);
return Util.TrimFromZero(Encoding.Unicode.GetString(Data, PCLayout + 0x22*box, 0x22));
}
public override void setBoxName(int box, string val)
public override void SetBoxName(int box, string val)
{
Encoding.Unicode.GetBytes(val.PadRight(0x11, '\0')).CopyTo(Data, PCLayout + 0x22*box);
Edited = true;
}
public override PKM getPKM(byte[] data)
public override PKM GetPKM(byte[] data)
{
return new PK7(data);
}
protected override void setPKM(PKM pkm)
protected override void SetPKM(PKM pkm)
{
PK7 pk7 = pkm as PK7;
// Apply to this Save File
@ -867,7 +867,7 @@ namespace PKHeX.Core
}
pkm.RefreshChecksum();
}
protected override void setDex(PKM pkm)
protected override void SetDex(PKM pkm)
{
if (PokeDex < 0 || Version == GameVersion.Unknown) // sanity
return;
@ -907,8 +907,7 @@ namespace PKHeX.Core
int formstart = pkm.AltForm;
int formend = pkm.AltForm;
int fs, fe;
bool reset = sanitizeFormsToIterate(pkm.Species, out fs, out fe, formstart);
bool reset = SanitizeFormsToIterate(pkm.Species, out int fs, out int fe, formstart);
if (reset)
{
formstart = fs;
@ -923,12 +922,12 @@ namespace PKHeX.Core
int fc = Personal[pkm.Species].FormeCount;
if (fc > 1) // actually has forms
{
int f = SaveUtil.getDexFormIndexSM(pkm.Species, fc, MaxSpeciesID - 1);
int f = SaveUtil.GetDexFormIndexSM(pkm.Species, fc, MaxSpeciesID - 1);
if (f >= 0) // bit index valid
bitIndex = f + form;
}
}
setDexFlags(bitIndex, gender, shiny, pkm.Species - 1);
SetDexFlags(bitIndex, gender, shiny, pkm.Species - 1);
}
// Set the Language
@ -945,7 +944,7 @@ namespace PKHeX.Core
Data[PokeDexLanguageFlags + (lbit >> 3)] |= (byte)(1 << (lbit & 7));
}
}
protected override void setPartyValues(PKM pkm, bool isParty)
protected override void SetPartyValues(PKM pkm, bool isParty)
{
uint duration = 0;
if (isParty && pkm.AltForm != 0)
@ -961,7 +960,7 @@ namespace PKHeX.Core
((PK7)pkm).FormDuration = duration;
}
private static bool sanitizeFormsToIterate(int species, out int formStart, out int formEnd, int formIn)
private static bool SanitizeFormsToIterate(int species, out int formStart, out int formEnd, int formIn)
{
// 004AA370 in Moon
// Simplified in terms of usage -- only overrides to give all the battle forms for a pkm
@ -1001,7 +1000,7 @@ namespace PKHeX.Core
return false;
}
}
private void setDexFlags(int index, int gender, int shiny, int baseSpecies)
private void SetDexFlags(int index, int gender, int shiny, int baseSpecies)
{
const int brSize = 0x8C;
int shift = gender | (shiny << 1);
@ -1042,7 +1041,7 @@ namespace PKHeX.Core
Data[ofs + (4 + shift) * brSize + bd] |= (byte)(1 << bm);
}
public override bool getCaught(int species)
public override bool GetCaught(int species)
{
int bit = species - 1;
int bd = bit >> 3; // div8
@ -1052,7 +1051,7 @@ namespace PKHeX.Core
+ 0x80; // Misc Data (1024 bits)
return (1 << bm & Data[ofs + bd]) != 0;
}
public override bool getSeen(int species)
public override bool GetSeen(int species)
{
const int brSize = 0x8C;
@ -1069,9 +1068,9 @@ namespace PKHeX.Core
return true;
return false;
}
public override byte[] decryptPKM(byte[] data)
public override byte[] DecryptPKM(byte[] data)
{
return PKX.decryptArray(data);
return PKX.DecryptArray(data);
}
public override int PartyCount
{
@ -1079,7 +1078,7 @@ namespace PKHeX.Core
protected set => Data[Party + 6 * SIZE_PARTY] = (byte)value;
}
public override int BoxesUnlocked { get => Data[PCFlags + 1]; set => Data[PCFlags + 1] = (byte)value; }
public override bool getIsSlotLocked(int box, int slot)
public override bool IsSlotLocked(int box, int slot)
{
if (slot >= 30 || box >= BoxCount)
return false;
@ -1087,7 +1086,7 @@ namespace PKHeX.Core
int slotIndex = slot + BoxSlotCount*box;
return LockedSlots.Any(s => s == slotIndex);
}
public override bool getIsTeamSet(int box, int slot)
public override bool IsSlotInBattleTeam(int box, int slot)
{
if (slot >= 30 || box >= BoxCount)
return false;
@ -1097,7 +1096,7 @@ namespace PKHeX.Core
}
public override int DaycareSeedSize => 32; // 128 bits
public override int getDaycareSlotOffset(int loc, int slot)
public override int GetDaycareSlotOffset(int loc, int slot)
{
if (loc != 0)
return -1;
@ -1105,7 +1104,7 @@ namespace PKHeX.Core
return -1;
return Daycare + 1 + slot * (SIZE_STORED + 1);
}
public override bool? getDaycareOccupied(int loc, int slot)
public override bool? IsDaycareOccupied(int loc, int slot)
{
if (loc != 0)
return null;
@ -1114,7 +1113,7 @@ namespace PKHeX.Core
return Data[Daycare + (SIZE_STORED + 1) * slot] != 0;
}
public override string getDaycareRNGSeed(int loc)
public override string GetDaycareRNGSeed(int loc)
{
if (loc != 0)
return null;
@ -1124,7 +1123,7 @@ namespace PKHeX.Core
var data = Data.Skip(Daycare + 0x1DC).Take(DaycareSeedSize / 2).Reverse().ToArray();
return BitConverter.ToString(data).Replace("-", "");
}
public override bool? getDaycareHasEgg(int loc)
public override bool? IsDaycareHasEgg(int loc)
{
if (loc != 0)
return null;
@ -1133,7 +1132,7 @@ namespace PKHeX.Core
return Data[Daycare + 0x1D8] == 1;
}
public override void setDaycareOccupied(int loc, int slot, bool occupied)
public override void SetDaycareOccupied(int loc, int slot, bool occupied)
{
if (loc != 0)
return;
@ -1142,7 +1141,7 @@ namespace PKHeX.Core
Data[Daycare + (SIZE_STORED + 1) * slot] = (byte)(occupied ? 1 : 0);
}
public override void setDaycareRNGSeed(int loc, string seed)
public override void SetDaycareRNGSeed(int loc, string seed)
{
if (loc != 0)
return;
@ -1159,7 +1158,7 @@ namespace PKHeX.Core
.Select(x => Convert.ToByte(seed.Substring(x, 2), 16))
.ToArray().CopyTo(Data, Daycare + 0x1DC);
}
public override void setDaycareHasEgg(int loc, bool hasEgg)
public override void SetDaycareHasEgg(int loc, bool hasEgg)
{
if (loc != 0)
return;
@ -1206,7 +1205,7 @@ namespace PKHeX.Core
return null;
MysteryGift[] cards = new MysteryGift[GiftCountMax];
for (int i = 0; i < cards.Length; i++)
cards[i] = getWC7(i);
cards[i] = GetWC7(i);
return cards;
}
@ -1218,22 +1217,22 @@ namespace PKHeX.Core
Array.Resize(ref value, GiftCountMax);
for (int i = 0; i < value.Length; i++)
setWC7(value[i], i);
SetWC7(value[i], i);
for (int i = value.Length; i < GiftCountMax; i++)
setWC7(new WC7(), i);
SetWC7(new WC7(), i);
}
}
private WC7 getWC7(int index)
private WC7 GetWC7(int index)
{
if (WondercardData < 0)
return null;
if (index < 0 || index > GiftCountMax)
return null;
return new WC7(getData(WondercardData + index * WC7.Size, WC7.Size));
return new WC7(GetData(WondercardData + index * WC7.Size, WC7.Size));
}
private void setWC7(MysteryGift wc7, int index)
private void SetWC7(MysteryGift wc7, int index)
{
if (WondercardData < 0)
return;
@ -1312,12 +1311,12 @@ namespace PKHeX.Core
public override bool RequiresMemeCrypto => true;
public override string getString(int Offset, int Count) => PKX.getString7(Data, Offset, Count);
public override byte[] setString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
public override string GetString(int Offset, int Count) => PKX.GetString7(Data, Offset, Count);
public override byte[] SetString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
{
if (PadToSize == 0)
PadToSize = maxLength + 1;
return PKX.setString7(value, maxLength, PadToSize, PadWith);
return PKX.SetString7(value, maxLength, PadToSize, PadWith);
}
}
}

View file

@ -20,8 +20,8 @@ namespace PKHeX.Core
public abstract string Filter { get; }
public byte[] Footer { protected get; set; } = new byte[0]; // .dsv
public byte[] Header { protected get; set; } = new byte[0]; // .gci
public bool Japanese { get; set; }
public string PlayTimeString => $"{PlayedHours}ː{PlayedMinutes:00}ː{PlayedSeconds:00}"; // not :
public bool Japanese { get; protected set; }
protected string PlayTimeString => $"{PlayedHours}ː{PlayedMinutes:00}ː{PlayedSeconds:00}"; // not :
public virtual bool IndeterminateGame => false;
public virtual bool IndeterminateSubVersion => false;
public abstract string Extension { get; }
@ -30,14 +30,14 @@ namespace PKHeX.Core
int gen = f.Last() - 0x30;
return 3 <= gen && gen <= Generation;
}).ToArray();
public virtual bool IsMemoryCardSave => false;
// General PKM Properties
public abstract Type PKMType { get; }
public abstract PKM getPKM(byte[] data);
public abstract PKM GetPKM(byte[] data);
public abstract PKM BlankPKM { get; }
public abstract byte[] decryptPKM(byte[] data);
public abstract byte[] DecryptPKM(byte[] data);
public abstract int SIZE_STORED { get; }
public abstract int SIZE_PARTY { get; }
protected abstract int SIZE_PARTY { get; }
public abstract int MaxEV { get; }
public virtual int MaxIV => 31;
public ushort[] HeldItems { get; protected set; }
@ -47,9 +47,9 @@ namespace PKHeX.Core
{
return Write(DSV);
}
public virtual byte[] Write(bool DSV)
protected virtual byte[] Write(bool DSV)
{
setChecksums();
SetChecksums();
if (Footer.Length > 0 && DSV)
return Data.Concat(Footer).ToArray();
if (Header.Length > 0)
@ -80,12 +80,12 @@ namespace PKHeX.Core
public bool RBY => Version == GameVersion.RBY;
public bool GameCube => new[] { GameVersion.COLO, GameVersion.XD, GameVersion.RSBOX }.Contains(Version);
public virtual int MaxMoveID => int.MaxValue;
public virtual int MaxSpeciesID => int.MaxValue;
public virtual int MaxAbilityID => int.MaxValue;
public virtual int MaxItemID => int.MaxValue;
public virtual int MaxBallID => int.MaxValue;
public virtual int MaxGameID => int.MaxValue;
public abstract int MaxMoveID { get; }
public abstract int MaxSpeciesID { get; }
public abstract int MaxAbilityID { get; }
public abstract int MaxItemID { get; }
public abstract int MaxBallID { get; }
public abstract int MaxGameID { get; }
// Flags
public bool HasWondercards => WondercardData > -1;
@ -104,7 +104,7 @@ namespace PKHeX.Core
public bool HasGTS => GTS > -1;
public bool HasDaycare => Daycare > -1;
public virtual bool HasPokeDex => PokeDex > -1;
public virtual bool HasBoxWallpapers => getBoxWallpaperOffset(0) > -1;
public virtual bool HasBoxWallpapers => GetBoxWallpaperOffset(0) > -1;
public virtual bool HasSUBE => SUBE > -1 && !ORAS;
public virtual bool HasGeolocation => false;
public bool HasPokeBlock => ORAS && !ORASDEMO;
@ -154,11 +154,11 @@ namespace PKHeX.Core
PKM[] data = new PKM[BoxCount*BoxSlotCount];
for (int i = 0; i < data.Length; i++)
{
data[i] = getStoredSlot(getBoxOffset(i/BoxSlotCount) + SIZE_STORED*(i%BoxSlotCount));
data[i].Identifier = $"{getBoxName(i/BoxSlotCount)}:{i%BoxSlotCount + 1:00}";
data[i] = GetStoredSlot(GetBoxOffset(i/BoxSlotCount) + SIZE_STORED*(i%BoxSlotCount));
data[i].Identifier = $"{GetBoxName(i/BoxSlotCount)}:{i%BoxSlotCount + 1:00}";
data[i].Box = i/BoxSlotCount + 1;
data[i].Slot = i%BoxSlotCount + 1;
data[i].Locked = getIsSlotLocked(data[i].Box, data[i].Slot);
data[i].Locked = IsSlotLocked(data[i].Box, data[i].Slot);
}
return data;
}
@ -172,7 +172,7 @@ namespace PKHeX.Core
throw new ArgumentException($"Not {PKMType} array.");
for (int i = 0; i < value.Length; i++)
setStoredSlot(value[i], getBoxOffset(i/BoxSlotCount) + SIZE_STORED*(i%BoxSlotCount));
SetStoredSlot(value[i], GetBoxOffset(i/BoxSlotCount) + SIZE_STORED*(i%BoxSlotCount));
}
}
public PKM[] PartyData
@ -181,7 +181,7 @@ namespace PKHeX.Core
{
PKM[] data = new PKM[PartyCount];
for (int i = 0; i < data.Length; i++)
data[i] = getPartySlot(getPartyOffset(i));
data[i] = GetPartySlot(GetPartyOffset(i));
return data;
}
set
@ -202,7 +202,7 @@ namespace PKHeX.Core
for (int i = PartyCount; i < newParty.Length; i++)
newParty[i] = BlankPKM;
for (int i = 0; i < newParty.Length; i++)
setPartySlot(newParty[i], getPartyOffset(i));
SetPartySlot(newParty[i], GetPartyOffset(i));
}
}
public PKM[] BattleBoxData
@ -215,7 +215,7 @@ namespace PKHeX.Core
PKM[] data = new PKM[6];
for (int i = 0; i < data.Length; i++)
{
data[i] = getStoredSlot(BattleBox + SIZE_STORED * i);
data[i] = GetStoredSlot(BattleBox + SIZE_STORED * i);
data[i].Locked = BattleBoxLocked;
if (data[i].Species == 0)
return data.Take(i).ToArray();
@ -332,11 +332,11 @@ namespace PKHeX.Core
public virtual int MultiplayerSpriteID { get => 0; set { } }
// Varied Methods
protected abstract void setChecksums();
public abstract int getBoxOffset(int box);
public abstract int getPartyOffset(int slot);
public abstract string getBoxName(int box);
public abstract void setBoxName(int box, string val);
protected abstract void SetChecksums();
public abstract int GetBoxOffset(int box);
public abstract int GetPartyOffset(int slot);
public abstract string GetBoxName(int box);
public abstract void SetBoxName(int box, string val);
public virtual int GameSyncIDSize { get; } = 8;
public virtual string GameSyncID { get => null; set { } }
public virtual ulong? Secure1 { get => null; set { } }
@ -345,16 +345,16 @@ namespace PKHeX.Core
// Daycare
public int DaycareIndex = 0;
public virtual bool HasTwoDaycares => false;
public virtual int getDaycareSlotOffset(int loc, int slot) { return -1; }
public virtual uint? getDaycareEXP(int loc, int slot) { return null; }
public virtual string getDaycareRNGSeed(int loc) { return null; }
public virtual bool? getDaycareHasEgg(int loc) { return null; }
public virtual bool? getDaycareOccupied(int loc, int slot) { return null; }
public virtual int GetDaycareSlotOffset(int loc, int slot) { return -1; }
public virtual uint? GetDaycareEXP(int loc, int slot) { return null; }
public virtual string GetDaycareRNGSeed(int loc) { return null; }
public virtual bool? IsDaycareHasEgg(int loc) { return null; }
public virtual bool? IsDaycareOccupied(int loc, int slot) { return null; }
public virtual void setDaycareEXP(int loc, int slot, uint EXP) { }
public virtual void setDaycareRNGSeed(int loc, string seed) { }
public virtual void setDaycareHasEgg(int loc, bool hasEgg) { }
public virtual void setDaycareOccupied(int loc, int slot, bool occupied) { }
public virtual void SetDaycareEXP(int loc, int slot, uint EXP) { }
public virtual void SetDaycareRNGSeed(int loc, string seed) { }
public virtual void SetDaycareHasEgg(int loc, bool hasEgg) { }
public virtual void SetDaycareOccupied(int loc, int slot, bool occupied) { }
// Storage
public virtual int BoxSlotCount => 30;
@ -378,9 +378,9 @@ namespace PKHeX.Core
return false;
int len = BoxSlotCount*SIZE_STORED;
byte[] boxdata = getData(getBoxOffset(0), len*BoxCount); // get all boxes
string[] boxNames = new int[BoxCount].Select((x, i) => getBoxName(i)).ToArray();
int[] boxWallpapers = new int[BoxCount].Select((x, i) => getBoxWallpaper(i)).ToArray();
byte[] boxdata = GetData(GetBoxOffset(0), len*BoxCount); // get all boxes
string[] boxNames = new int[BoxCount].Select((x, i) => GetBoxName(i)).ToArray();
int[] boxWallpapers = new int[BoxCount].Select((x, i) => GetBoxWallpaper(i)).ToArray();
min /= BoxSlotCount;
max /= BoxSlotCount;
@ -395,9 +395,9 @@ namespace PKHeX.Core
++ctr;
b = ctr++;
}
Array.Copy(boxdata, len*i, Data, getBoxOffset(b), len);
setBoxName(b, boxNames[i]);
setBoxWallpaper(b, boxWallpapers[i]);
Array.Copy(boxdata, len*i, Data, GetBoxOffset(b), len);
SetBoxName(b, boxNames[i]);
SetBoxWallpaper(b, boxWallpapers[i]);
}
return true;
}
@ -423,8 +423,8 @@ namespace PKHeX.Core
return false;
// Data
int b1o = getBoxOffset(box1);
int b2o = getBoxOffset(box2);
int b1o = GetBoxOffset(box1);
int b2o = GetBoxOffset(box2);
int len = BoxSlotCount*SIZE_STORED;
byte[] b1 = new byte[len];
Array.Copy(Data, b1o, b1, 0, len);
@ -432,54 +432,54 @@ namespace PKHeX.Core
Array.Copy(b1, 0, Data, b2o, len);
// Name
string b1n = getBoxName(box1);
setBoxName(box1, getBoxName(box2));
setBoxName(box2, b1n);
string b1n = GetBoxName(box1);
SetBoxName(box1, GetBoxName(box2));
SetBoxName(box2, b1n);
// Wallpaper
int b1w = getBoxWallpaper(box1);
setBoxWallpaper(box1, getBoxWallpaper(box2));
setBoxWallpaper(box2, b1w);
int b1w = GetBoxWallpaper(box1);
SetBoxWallpaper(box1, GetBoxWallpaper(box2));
SetBoxWallpaper(box2, b1w);
return true;
}
protected virtual int getBoxWallpaperOffset(int box) { return -1; }
public virtual int getBoxWallpaper(int box)
protected virtual int GetBoxWallpaperOffset(int box) { return -1; }
public virtual int GetBoxWallpaper(int box)
{
int offset = getBoxWallpaperOffset(box);
int offset = GetBoxWallpaperOffset(box);
if (offset < 0 || box > BoxCount)
return box;
return Data[offset];
}
public virtual void setBoxWallpaper(int box, int val)
public virtual void SetBoxWallpaper(int box, int val)
{
int offset = getBoxWallpaperOffset(box);
int offset = GetBoxWallpaperOffset(box);
if (offset < 0 || box > BoxCount)
return;
Data[offset] = (byte)val;
}
public virtual PKM getPartySlot(int offset)
public virtual PKM GetPartySlot(int offset)
{
return getPKM(decryptPKM(getData(offset, SIZE_PARTY)));
return GetPKM(DecryptPKM(GetData(offset, SIZE_PARTY)));
}
public virtual PKM getStoredSlot(int offset)
public virtual PKM GetStoredSlot(int offset)
{
return getPKM(decryptPKM(getData(offset, SIZE_STORED)));
return GetPKM(DecryptPKM(GetData(offset, SIZE_STORED)));
}
public void setPartySlot(PKM pkm, int offset, bool? trade = null, bool? dex = null)
public void SetPartySlot(PKM pkm, int offset, bool? trade = null, bool? dex = null)
{
if (pkm == null) return;
if (pkm.GetType() != PKMType)
throw new ArgumentException($"PKM Format needs to be {PKMType} when setting to this Save File.");
if (trade ?? SetUpdatePKM)
setPKM(pkm);
SetPKM(pkm);
if (dex ?? SetUpdateDex)
setDex(pkm);
setPartyValues(pkm, isParty: true);
SetDex(pkm);
SetPartyValues(pkm, isParty: true);
for (int i = 0; i < 6; i++)
if (getPartyOffset(i) == offset)
if (GetPartyOffset(i) == offset)
{
if (pkm.Species != 0)
{
@ -491,44 +491,44 @@ namespace PKHeX.Core
break;
}
setData(pkm.EncryptedPartyData, offset);
SetData(pkm.EncryptedPartyData, offset);
Edited = true;
}
public virtual void setStoredSlot(PKM pkm, int offset, bool? trade = null, bool? dex = null)
public virtual void SetStoredSlot(PKM pkm, int offset, bool? trade = null, bool? dex = null)
{
if (pkm == null) return;
if (pkm.GetType() != PKMType)
throw new ArgumentException($"PKM Format needs to be {PKMType} when setting to this Save File.");
if (trade ?? SetUpdatePKM)
setPKM(pkm);
SetPKM(pkm);
if (dex ?? SetUpdateDex)
setDex(pkm);
setPartyValues(pkm, isParty: false);
setData(pkm.EncryptedBoxData, offset);
SetDex(pkm);
SetPartyValues(pkm, isParty: false);
SetData(pkm.EncryptedBoxData, offset);
Edited = true;
}
public void deletePartySlot(int slot)
public void DeletePartySlot(int slot)
{
if (PartyCount <= slot) // beyond party range (or empty data already present)
return;
// Move all party slots down one
for (int i = slot + 1; i < 6; i++) // Slide slots down
{
int slotTo = getPartyOffset(i - 1);
int slotFrom = getPartyOffset(i);
setData(getData(slotFrom, SIZE_PARTY), slotTo);
int slotTo = GetPartyOffset(i - 1);
int slotFrom = GetPartyOffset(i);
SetData(GetData(slotFrom, SIZE_PARTY), slotTo);
}
setStoredSlot(BlankPKM, getPartyOffset(5), false, false);
SetStoredSlot(BlankPKM, GetPartyOffset(5), false, false);
PartyCount -= 1;
}
public virtual bool getIsSlotLocked(int box, int slot) { return false; }
public bool getBoxHasLockedSlot(int BoxStart, int BoxEnd)
public virtual bool IsSlotLocked(int box, int slot) { return false; }
public bool IsAnySlotLockedInBox(int BoxStart, int BoxEnd)
{
return LockedSlots.Any(slot => BoxStart*BoxSlotCount <= slot && slot < (BoxEnd + 1)*BoxSlotCount);
}
public virtual bool getIsTeamSet(int box, int slot) { return false; }
public virtual bool IsSlotInBattleTeam(int box, int slot) { return false; }
public void sortBoxes(int BoxStart = 0, int BoxEnd = -1)
public void SortBoxes(int BoxStart = 0, int BoxEnd = -1)
{
PKM[] BD = BoxData;
var Section = BD.Skip(BoxStart*BoxSlotCount);
@ -546,7 +546,7 @@ namespace PKHeX.Core
Array.Copy(Sorted, 0, BD, BoxStart*BoxSlotCount, Sorted.Length);
BoxData = BD;
}
public void resetBoxes(int BoxStart = 0, int BoxEnd = -1)
public void ClearBoxes(int BoxStart = 0, int BoxEnd = -1)
{
if (BoxEnd < 0)
BoxEnd = BoxCount;
@ -557,19 +557,19 @@ namespace PKHeX.Core
for (int i = BoxStart; i < BoxEnd; i++)
{
int offset = getBoxOffset(i);
int offset = GetBoxOffset(i);
for (int p = 0; p < BoxSlotCount; p++)
setData(blank, offset + SIZE_STORED * p);
SetData(blank, offset + SIZE_STORED * p);
}
}
public byte[] getPCBin() { return BoxData.SelectMany(pk => pk.EncryptedBoxData).ToArray(); }
public byte[] getBoxBin(int box) { return BoxData.Skip(box*BoxSlotCount).Take(BoxSlotCount).SelectMany(pk => pk.EncryptedBoxData).ToArray(); }
public bool setPCBin(byte[] data)
public byte[] PCBinary => BoxData.SelectMany(pk => pk.EncryptedBoxData).ToArray();
public byte[] GetBoxBinary(int box) => BoxData.Skip(box*BoxSlotCount).Take(BoxSlotCount).SelectMany(pk => pk.EncryptedBoxData).ToArray();
public bool SetPCBinary(byte[] data)
{
if (LockedSlots.Any())
return false;
if (data.Length != getPCBin().Length)
if (data.Length != PCBinary.Length)
return false;
int len = BlankPKM.EncryptedBoxData.Length;
@ -584,15 +584,15 @@ namespace PKHeX.Core
PKM[] pkms = BoxData;
for (int i = 0; i < pkms.Length; i++)
pkms[i] = getPKM(decryptPKM(pkdata[i]));
pkms[i] = GetPKM(DecryptPKM(pkdata[i]));
BoxData = pkms;
return true;
}
public bool setBoxBin(byte[] data, int box)
public bool SetBoxBinary(byte[] data, int box)
{
if (LockedSlots.Any(slot => box * BoxSlotCount <= slot && slot < (box + 1) * BoxSlotCount))
return false;
if (data.Length != getBoxBin(box).Length)
if (data.Length != GetBoxBinary(box).Length)
return false;
int len = BlankPKM.EncryptedBoxData.Length;
@ -607,22 +607,22 @@ namespace PKHeX.Core
PKM[] pkms = BoxData;
for (int i = 0; i < BoxSlotCount; i++)
pkms[box*BoxSlotCount + i] = getPKM(decryptPKM(pkdata[i]));
pkms[box*BoxSlotCount + i] = GetPKM(DecryptPKM(pkdata[i]));
BoxData = pkms;
return true;
}
protected virtual void setPartyValues(PKM pkm, bool isParty) { }
protected virtual void setPKM(PKM pkm) { }
protected virtual void setDex(PKM pkm) { }
public virtual bool getSeen(int species) => false;
public virtual void setSeen(int species, bool seen) { }
public virtual bool getCaught(int species) => false;
public virtual void setCaught(int species, bool caught) { }
public int SeenCount => HasPokeDex ? new bool[MaxSpeciesID].Where((b, i) => getSeen(i+1)).Count() : 0;
public int CaughtCount => HasPokeDex ? new bool[MaxSpeciesID].Where((b, i) => getCaught(i+1)).Count() : 0;
protected virtual void SetPartyValues(PKM pkm, bool isParty) { }
protected virtual void SetPKM(PKM pkm) { }
protected virtual void SetDex(PKM pkm) { }
public virtual bool GetSeen(int species) => false;
public virtual void SetSeen(int species, bool seen) { }
public virtual bool GetCaught(int species) => false;
public virtual void SetCaught(int species, bool caught) { }
public int SeenCount => HasPokeDex ? new bool[MaxSpeciesID].Where((b, i) => GetSeen(i+1)).Count() : 0;
public int CaughtCount => HasPokeDex ? new bool[MaxSpeciesID].Where((b, i) => GetCaught(i+1)).Count() : 0;
public byte[] getData(int Offset, int Length)
public byte[] GetData(int Offset, int Length)
{
if (Offset + Length > Data.Length)
return null;
@ -631,18 +631,18 @@ namespace PKHeX.Core
Array.Copy(Data, Offset, data, 0, Length);
return data;
}
public void setData(byte[] input, int Offset)
public void SetData(byte[] input, int Offset)
{
input.CopyTo(Data, Offset);
Edited = true;
}
public abstract string getString(int Offset, int Length);
public abstract byte[] setString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0);
public abstract string GetString(int Offset, int Length);
public abstract byte[] SetString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0);
public virtual bool RequiresMemeCrypto => false;
public virtual string eBerryName => string.Empty;
public virtual bool eBerryIsEnigma => true;
public virtual string EBerryName => string.Empty;
public virtual bool IsEBerryIsEnigma => true;
}
}

View file

@ -44,30 +44,30 @@ namespace PKHeX.Core
/// <summary>Determines the generation of the given save data.</summary>
/// <param name="data">Save data of which to determine the generation</param>
/// <returns>Version Identifier or Invalid if type cannot be determined.</returns>
public static GameVersion getSAVGeneration(byte[] data)
private static GameVersion GetSAVGeneration(byte[] data)
{
if (getIsG1SAV(data) != GameVersion.Invalid)
if (GetIsG1SAV(data) != GameVersion.Invalid)
return GameVersion.Gen1;
if (getIsG2SAV(data) != GameVersion.Invalid)
if (GetIsG2SAV(data) != GameVersion.Invalid)
return GameVersion.Gen2;
if (getIsG3SAV(data) != GameVersion.Invalid)
if (GetIsG3SAV(data) != GameVersion.Invalid)
return GameVersion.Gen3;
if (getIsG4SAV(data) != GameVersion.Invalid)
if (GetIsG4SAV(data) != GameVersion.Invalid)
return GameVersion.Gen4;
if (getIsG5SAV(data) != GameVersion.Invalid)
if (GetIsG5SAV(data) != GameVersion.Invalid)
return GameVersion.Gen5;
if (getIsG6SAV(data) != GameVersion.Invalid)
if (GetIsG6SAV(data) != GameVersion.Invalid)
return GameVersion.Gen6;
if (getIsG7SAV(data) != GameVersion.Invalid)
if (GetIsG7SAV(data) != GameVersion.Invalid)
return GameVersion.Gen7;
if (getIsG3COLOSAV(data) != GameVersion.Invalid)
if (GetIsG3COLOSAV(data) != GameVersion.Invalid)
return GameVersion.COLO;
if (getIsG3XDSAV(data) != GameVersion.Invalid)
if (GetIsG3XDSAV(data) != GameVersion.Invalid)
return GameVersion.XD;
if (getIsG3BOXSAV(data) != GameVersion.Invalid)
if (GetIsG3BOXSAV(data) != GameVersion.Invalid)
return GameVersion.RSBOX;
if (getIsG4BRSAV(data) != GameVersion.Invalid)
if (GetIsG4BRSAV(data) != GameVersion.Invalid)
return GameVersion.BATREV;
return GameVersion.Invalid;
@ -75,13 +75,13 @@ namespace PKHeX.Core
/// <summary>Determines the type of 1st gen save</summary>
/// <param name="data">Save data of which to determine the type</param>
/// <returns>Version Identifier or Invalid if type cannot be determined.</returns>
public static GameVersion getIsG1SAV(byte[] data)
internal static GameVersion GetIsG1SAV(byte[] data)
{
if (data.Length != SIZE_G1RAW && data.Length != SIZE_G1BAT)
return GameVersion.Invalid;
// Check if it's not an american save or a japanese save
if (!(getIsG1SAVU(data) || getIsG1SAVJ(data)))
if (!(GetIsG1SAVU(data) || GetIsG1SAVJ(data)))
return GameVersion.Invalid;
// I can't actually detect which game version, because it's not stored anywhere.
// If you can think of anything to do here, please implement :)
@ -90,7 +90,7 @@ namespace PKHeX.Core
/// <summary>Determines if 1st gen save is non-japanese</summary>
/// <param name="data">Save data of which to determine the region</param>
/// <returns>True if a valid non-japanese save, False otherwise.</returns>
public static bool getIsG1SAVU(byte[] data)
private static bool GetIsG1SAVU(byte[] data)
{
foreach (int ofs in new[] { 0x2F2C, 0x30C0 })
{
@ -103,7 +103,7 @@ namespace PKHeX.Core
/// <summary>Determines if 1st gen save is japanese</summary>
/// <param name="data">Save data of which to determine the region</param>
/// <returns>True if a valid japanese save, False otherwise.</returns>
public static bool getIsG1SAVJ(byte[] data)
internal static bool GetIsG1SAVJ(byte[] data)
{
foreach (int ofs in new[] { 0x2ED5, 0x302D })
{
@ -116,22 +116,22 @@ namespace PKHeX.Core
/// <summary>Determines the type of 2nd gen save</summary>
/// <param name="data">Save data of which to determine the type</param>
/// <returns>Version Identifier or Invalid if type cannot be determined.</returns>
public static GameVersion getIsG2SAV(byte[] data)
internal static GameVersion GetIsG2SAV(byte[] data)
{
if (!new[] {SIZE_G2RAW_J, SIZE_G2RAW_U, SIZE_G2BAT_J, SIZE_G2BAT_U, SIZE_G2EMU, SIZE_G2VC}.Contains(data.Length))
return GameVersion.Invalid;
// Check if it's not an american save or a japanese save
if (getIsG2SAVU(data) != GameVersion.Invalid)
return getIsG2SAVU(data);
if (getIsG2SAVJ(data) != GameVersion.Invalid)
return getIsG2SAVJ(data);
if (GetIsG2SAVU(data) != GameVersion.Invalid)
return GetIsG2SAVU(data);
if (GetIsG2SAVJ(data) != GameVersion.Invalid)
return GetIsG2SAVJ(data);
return GameVersion.Invalid;
}
/// <summary>Determines if 2nd gen save is non-japanese</summary>
/// <param name="data">Save data of which to determine the region</param>
/// <returns>True if a valid non-japanese save, False otherwise.</returns>
public static GameVersion getIsG2SAVU(byte[] data)
private static GameVersion GetIsG2SAVU(byte[] data)
{
bool gs = true;
bool c = true;
@ -156,7 +156,7 @@ namespace PKHeX.Core
/// <summary>Determines if 2nd gen save is japanese</summary>
/// <param name="data">Save data of which to determine the region</param>
/// <returns>True if a valid japanese save, False otherwise.</returns>
public static GameVersion getIsG2SAVJ(byte[] data)
internal static GameVersion GetIsG2SAVJ(byte[] data)
{
bool gs = true;
bool c = true;
@ -181,7 +181,7 @@ namespace PKHeX.Core
/// <summary>Determines the type of 3rd gen save</summary>
/// <param name="data">Save data of which to determine the type</param>
/// <returns>Version Identifier or Invalid if type cannot be determined.</returns>
public static GameVersion getIsG3SAV(byte[] data)
internal static GameVersion GetIsG3SAV(byte[] data)
{
if (data.Length != SIZE_G3RAW && data.Length != SIZE_G3RAWHALF)
return GameVersion.Invalid;
@ -224,7 +224,7 @@ namespace PKHeX.Core
/// <summary>Determines the type of 3rd gen Box RS</summary>
/// <param name="data">Save data of which to determine the type</param>
/// <returns>Version Identifier or Invalid if type cannot be determined.</returns>
public static GameVersion getIsG3BOXSAV(byte[] data)
internal static GameVersion GetIsG3BOXSAV(byte[] data)
{
if (!new[] { SIZE_G3BOX, SIZE_G3BOXGCI }.Contains(data.Length))
return GameVersion.Invalid;
@ -250,7 +250,7 @@ namespace PKHeX.Core
/// <summary>Determines the type of 3rd gen Colosseum</summary>
/// <param name="data">Save data of which to determine the type</param>
/// <returns>Version Identifier or Invalid if type cannot be determined.</returns>
public static GameVersion getIsG3COLOSAV(byte[] data)
internal static GameVersion GetIsG3COLOSAV(byte[] data)
{
if (!new[] { SIZE_G3COLO, SIZE_G3COLOGCI }.Contains(data.Length))
return GameVersion.Invalid;
@ -269,7 +269,7 @@ namespace PKHeX.Core
/// <summary>Determines the type of 3rd gen XD</summary>
/// <param name="data">Save data of which to determine the type</param>
/// <returns>Version Identifier or Invalid if type cannot be determined.</returns>
public static GameVersion getIsG3XDSAV(byte[] data)
internal static GameVersion GetIsG3XDSAV(byte[] data)
{
if (!new[] { SIZE_G3XD, SIZE_G3XDGCI }.Contains(data.Length))
return GameVersion.Invalid;
@ -290,17 +290,17 @@ namespace PKHeX.Core
/// <summary>Determines the type of 4th gen save</summary>
/// <param name="data">Save data of which to determine the type</param>
/// <returns>Version Identifier or Invalid if type cannot be determined.</returns>
public static GameVersion getIsG4SAV(byte[] data)
internal static GameVersion GetIsG4SAV(byte[] data)
{
if (data.Length != SIZE_G4RAW)
return GameVersion.Invalid;
// General Block Checksum
if (BitConverter.ToUInt16(data, 0xC0FE) == ccitt16(data, 0, 0xC0EC))
if (BitConverter.ToUInt16(data, 0xC0FE) == CRC16_CCITT(data, 0, 0xC0EC))
return GameVersion.DP;
if (BitConverter.ToUInt16(data, 0xCF2A) == ccitt16(data, 0, 0xCF18))
if (BitConverter.ToUInt16(data, 0xCF2A) == CRC16_CCITT(data, 0, 0xCF18))
return GameVersion.Pt;
if (BitConverter.ToUInt16(data, 0xF626) == ccitt16(data, 0, 0xF618))
if (BitConverter.ToUInt16(data, 0xF626) == CRC16_CCITT(data, 0, 0xF618))
return GameVersion.HGSS;
// General Block Checksum is invalid, check for block identifiers
@ -324,7 +324,7 @@ namespace PKHeX.Core
/// <summary>Determines the type of 4th gen Battle Revolution</summary>
/// <param name="data">Save data of which to determine the type</param>
/// <returns>Version Identifier or Invalid if type cannot be determined.</returns>
public static GameVersion getIsG4BRSAV(byte[] data)
internal static GameVersion GetIsG4BRSAV(byte[] data)
{
if (data.Length != SIZE_G4BR)
return GameVersion.Invalid;
@ -341,17 +341,17 @@ namespace PKHeX.Core
/// <summary>Determines the type of 5th gen save</summary>
/// <param name="data">Save data of which to determine the type</param>
/// <returns>Version Identifier or Invalid if type cannot be determined.</returns>
public static GameVersion getIsG5SAV(byte[] data)
internal static GameVersion GetIsG5SAV(byte[] data)
{
if (data.Length != SIZE_G5RAW)
return GameVersion.Invalid;
ushort chk1 = BitConverter.ToUInt16(data, SIZE_G5BW - 0x100 + 0x8C + 0xE);
ushort actual1 = ccitt16(data, SIZE_G5BW - 0x100, 0x8C);
ushort actual1 = CRC16_CCITT(data, SIZE_G5BW - 0x100, 0x8C);
if (chk1 == actual1)
return GameVersion.BW;
ushort chk2 = BitConverter.ToUInt16(data, SIZE_G5B2W2 - 0x100 + 0x94 + 0xE);
ushort actual2 = ccitt16(data, SIZE_G5B2W2 - 0x100, 0x94);
ushort actual2 = CRC16_CCITT(data, SIZE_G5B2W2 - 0x100, 0x94);
if (chk2 == actual2)
return GameVersion.B2W2;
return GameVersion.Invalid;
@ -359,7 +359,7 @@ namespace PKHeX.Core
/// <summary>Determines the type of 6th gen save</summary>
/// <param name="data">Save data of which to determine the type</param>
/// <returns>Version Identifier or Invalid if type cannot be determined.</returns>
public static GameVersion getIsG6SAV(byte[] data)
private static GameVersion GetIsG6SAV(byte[] data)
{
if (!new []{SIZE_G6XY, SIZE_G6ORAS, SIZE_G6ORASDEMO}.Contains(data.Length))
return GameVersion.Invalid;
@ -381,7 +381,7 @@ namespace PKHeX.Core
/// <summary>Determines the type of 7th gen save</summary>
/// <param name="data">Save data of which to determine the type</param>
/// <returns>Version Identifier or Invalid if type cannot be determined.</returns>
public static GameVersion getIsG7SAV(byte[] data)
private static GameVersion GetIsG7SAV(byte[] data)
{
if (!new [] {SIZE_G7SM}.Contains(data.Length))
return GameVersion.Invalid;
@ -392,14 +392,14 @@ namespace PKHeX.Core
/// <summary>Creates an instance of a SaveFile using the given save data.</summary>
/// <param name="data">Save data from which to create a SaveFile.</param>
/// <returns>An appropriate type of save file for the given data, or null if the save data is invalid.</returns>
public static SaveFile getVariantSAV(byte[] data)
public static SaveFile GetVariantSAV(byte[] data)
{
// Pre-check for header/footer signatures
SaveFile sav;
byte[] header = new byte[0], footer = new byte[0];
CheckHeaderFooter(ref data, ref header, ref footer);
switch (getSAVGeneration(data))
switch (GetSAVGeneration(data))
{
// Main Games
case GameVersion.Gen1: sav = new SAV1(data); break;
@ -423,7 +423,7 @@ namespace PKHeX.Core
sav.Footer = footer;
return sav;
}
public static SaveFile getVariantSAV(SAV3GCMemoryCard MC)
public static SaveFile GetVariantSAV(SAV3GCMemoryCard MC)
{
// Pre-check for header/footer signatures
SaveFile sav;
@ -452,9 +452,9 @@ namespace PKHeX.Core
/// <param name="Game">Version to create the save file for.</param>
/// <param name="OT">Trainer Name</param>
/// <returns></returns>
public static SaveFile getBlankSAV(GameVersion Game, string OT)
public static SaveFile GetBlankSAV(GameVersion Game, string OT)
{
var SAV = getBlankSAV(Game);
var SAV = GetBlankSAV(Game);
if (SAV == null)
return null;
@ -476,7 +476,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="Game">Version to create the save file for.</param>
/// <returns></returns>
private static SaveFile getBlankSAV(GameVersion Game)
private static SaveFile GetBlankSAV(GameVersion Game)
{
switch (Game)
{
@ -528,10 +528,10 @@ namespace PKHeX.Core
/// <param name="generation">Generation of the Save File.</param>
/// <param name="OT">Trainer Name</param>
/// <returns>Save File for that generation.</returns>
public static SaveFile getBlankSAV(int generation, string OT)
public static SaveFile GetBlankSAV(int generation, string OT)
{
var ver = GameUtil.getVersion(generation);
return getBlankSAV(ver, OT);
var ver = GameUtil.GetVersion(generation);
return GetBlankSAV(ver, OT);
}
/// <summary>
@ -541,7 +541,7 @@ namespace PKHeX.Core
/// <param name="deep">Search all subfolders</param>
/// <param name="result">Full path of all save files that match criteria.</param>
/// <returns>Boolean indicating whether or not operation was successful.</returns>
public static bool getSavesFromFolder(string folderPath, bool deep, out IEnumerable<string> result)
public static bool GetSavesFromFolder(string folderPath, bool deep, out IEnumerable<string> result)
{
if (!Directory.Exists(folderPath))
{
@ -552,7 +552,7 @@ namespace PKHeX.Core
{
var searchOption = deep ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
var files = Directory.GetFiles(folderPath, "*", searchOption);
result = files.Where(f => SizeValidSAV((int)new FileInfo(f).Length));
result = files.Where(f => IsSizeValid((int)new FileInfo(f).Length));
return true;
}
catch (ArgumentException)
@ -568,7 +568,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="size">Size in bytes of the save data</param>
/// <returns>A boolean indicating whether or not the save data size is valid.</returns>
public static bool SizeValidSAV(int size)
private static bool IsSizeValid(int size)
{
switch (size)
{
@ -594,7 +594,7 @@ namespace PKHeX.Core
/// <param name="start">Starting point for checksum</param>
/// <param name="length"></param>
/// <returns>Checksum</returns>
public static ushort ccitt16(byte[] data, int start, int length)
public static ushort CRC16_CCITT(byte[] data, int start, int length)
{
const ushort init = 0xFFFF;
const ushort poly = 0x1021;
@ -619,7 +619,7 @@ namespace PKHeX.Core
/// <summary>Calculates the CRC16-CCITT checksum over an input byte array.</summary>
/// <param name="data">Input byte array</param>
/// <returns>Checksum</returns>
public static ushort ccitt16(byte[] data) => ccitt16(data, 0, data.Length);
public static ushort CRC16_CCITT(byte[] data) => CRC16_CCITT(data, 0, data.Length);
private static readonly ushort[] crc16 =
{
@ -662,7 +662,7 @@ namespace PKHeX.Core
/// <param name="blockID">Block ID to checksum</param>
/// <param name="initial">Initial value for checksum</param>
/// <returns>Checksum</returns>
public static ushort check16(byte[] data, int blockID, ushort initial = 0)
public static ushort CRC16_7(byte[] data, int blockID, ushort initial = 0)
{
if (blockID == 36)
new byte[0x80].CopyTo(data, 0x100);
@ -680,14 +680,14 @@ namespace PKHeX.Core
/// <summary>Calculates the 32bit checksum over an input byte array. Used in GBA save files.</summary>
/// <param name="data">Input byte array</param>
/// <returns>Checksum</returns>
public static ushort check32(byte[] data)
public static ushort CRC32(byte[] data)
{
uint val = 0;
for (int i = 0; i < data.Length; i += 4)
val += BitConverter.ToUInt32(data, i);
return (ushort)((val & 0xFFFF) + (val >> 16));
}
public static void CheckHeaderFooter(ref byte[] input, ref byte[] header, ref byte[] footer)
private static void CheckHeaderFooter(ref byte[] input, ref byte[] header, ref byte[] footer)
{
if (input.Length > SIZE_G4RAW) // DeSmuME Gen4/5 DSV
{
@ -727,7 +727,7 @@ namespace PKHeX.Core
}
}
public static int getDexFormIndexBW(int species, int formct)
public static int GetDexFormIndexBW(int species, int formct)
{
if (formct < 1 || species < 0)
return -1; // invalid
@ -752,7 +752,7 @@ namespace PKHeX.Core
default: return -1;
}
}
public static int getDexFormIndexB2W2(int species, int formct)
public static int GetDexFormIndexB2W2(int species, int formct)
{
if (formct < 1 || species < 0)
return -1; // invalid
@ -763,10 +763,10 @@ namespace PKHeX.Core
case 642: return 077; // 2 Thundurus
case 641: return 079; // 2 Tornadus
case 645: return 081; // 2 Landorus
default: return getDexFormIndexBW(species, formct);
default: return GetDexFormIndexBW(species, formct);
}
}
public static int getDexFormIndexXY(int species, int formct)
public static int GetDexFormIndexXY(int species, int formct)
{
if (formct < 1 || species < 0)
return -1; // invalid
@ -808,10 +808,10 @@ namespace PKHeX.Core
case 445: return 183; // 2 Garchomp
case 448: return 185; // 2 Lucario
case 460: return 187; // 2 Abomasnow
default: return getDexFormIndexB2W2(species, formct);
default: return GetDexFormIndexB2W2(species, formct);
}
}
public static int getDexFormIndexORAS(int species, int formct)
public static int GetDexFormIndexORAS(int species, int formct)
{
if (formct < 1 || species < 0)
return -1; // invalid
@ -842,10 +842,10 @@ namespace PKHeX.Core
case 493: return 238; // 18 Arceus
case 649: return 256; // 5 Genesect
case 676: return 261; // 10 Furfrou
default: return getDexFormIndexXY(species, formct);
default: return GetDexFormIndexXY(species, formct);
}
}
public static int getDexFormIndexSM(int species, int formct, int start)
public static int GetDexFormIndexSM(int species, int formct, int start)
{
ushort[] formtable = // u16 species, u16 formcount
{
@ -895,7 +895,7 @@ namespace PKHeX.Core
return formindex;
}
public static int getCXDVersionID(int gen3version)
public static int GetCXDVersionID(int gen3version)
{
switch ((GameVersion)gen3version)
{
@ -908,7 +908,7 @@ namespace PKHeX.Core
default: return 0;
}
}
public static int getG3VersionID(int CXDversion)
public static int GetG3VersionID(int CXDversion)
{
switch (CXDversion)
{
@ -976,7 +976,7 @@ namespace PKHeX.Core
/// <param name="G7TID">Desired G7TID</param>
/// <param name="minimizeSID">Optional param to yield minimum SID.</param>
/// <returns>16bit TID/SID tuple</returns>
public static Tuple<uint, uint> getTIDSID(uint G7TID, bool minimizeSID = false)
public static Tuple<uint, uint> GetTIDSID(uint G7TID, bool minimizeSID = false)
{
// 32 bit number = 4294 967295
// lowest 6 digits G7TID
@ -988,7 +988,7 @@ namespace PKHeX.Core
uint s7 = 4294;
if (val > 967295)
s7 -= 1;
s7 = (uint)Util.rand.Next(0, (int)s7);
s7 = (uint)Util.Rand.Next(0, (int)s7);
val += s7 * 1000000;
}
uint TID = val & 0xFFFF;
@ -1003,7 +1003,7 @@ namespace PKHeX.Core
/// <param name="input">Encrypted byte array of savedata to decrypt.</param>
/// <param name="XORpads">Array of possible paths to check for xorpad compatibility.</param>
/// <returns>Returns a <see cref="SaveFile"/> if decryption was successful, else null.</returns>
public static SaveFile getSAVfromXORpads(byte[] input, string[] XORpads)
public static SaveFile GetSAVfromXORpads(byte[] input, string[] XORpads)
{
byte[] savID = new byte[0x10];
Array.Copy(input, 0x10, savID, 0, 0x10);
@ -1056,7 +1056,7 @@ namespace PKHeX.Core
continue;
// Save file is now decrypted!
var SAV = getVariantSAV(decryptedPS);
var SAV = GetVariantSAV(decryptedPS);
if (SAV == null)
continue;
@ -1074,7 +1074,7 @@ namespace PKHeX.Core
/// <param name="SAV">Save File target that the PKM will be injected.</param>
/// <param name="pk">PKM input that is to be injected into the Save File.</param>
/// <returns>Indication whether or not the PKM is compatible.</returns>
public static bool checkCompatible(SaveFile SAV, PKM pk)
public static bool IsPKMCompatibleWithModifications(SaveFile SAV, PKM pk)
{
if (pk.Species > SAV.MaxSpeciesID)
return false;

View file

@ -7,7 +7,7 @@ namespace PKHeX.Core
public class BV6 : BattleVideo
{
internal const int SIZE = 0x2E60;
internal new static bool getIsValid(byte[] data)
internal new static bool IsValid(byte[] data)
{
if (data.Length != SIZE)
return false;

View file

@ -5,7 +5,7 @@ namespace PKHeX.Core
public class BV7 : BattleVideo
{
internal const int SIZE = 0x2BC0;
internal new static bool getIsValid(byte[] data)
internal new static bool IsValid(byte[] data)
{
return data.Length == SIZE;
}

View file

@ -5,20 +5,20 @@
public abstract PKM[] BattlePKMs { get; }
public abstract int Generation { get; }
public static BattleVideo getVariantBattleVideo(byte[] data)
public static BattleVideo GetVariantBattleVideo(byte[] data)
{
if (BV6.getIsValid(data))
if (BV6.IsValid(data))
return new BV6(data);
if (BV7.getIsValid(data))
if (BV7.IsValid(data))
return new BV7(data);
return null;
}
public static bool getIsValid(byte[] data)
public static bool IsValid(byte[] data)
{
if (BV6.getIsValid(data))
if (BV6.IsValid(data))
return true;
if (BV7.getIsValid(data))
if (BV7.IsValid(data))
return true;
return false;
}

View file

@ -49,13 +49,13 @@
{
get
{
ushort[] chks = getCHK(Data);
ushort[] chks = GetChecksum(Data);
return chks[0] == CHK_0 && chks[1] == CHK_1;
}
}
public void SetChecksums()
{
ushort[] chks = getCHK(Data);
ushort[] chks = GetChecksum(Data);
CHK_0 = chks[0];
CHK_1 = chks[1];
Data[0] = (byte)(CHK_0 >> 8);
@ -64,7 +64,7 @@
Data[3] = (byte)(CHK_1 & 0xFF);
}
private static ushort[] getCHK(byte[] data)
private static ushort[] GetChecksum(byte[] data)
{
int chk = 0; // initial value
for (int j = 0x4; j < 0x1FFC; j += 2)

View file

@ -2,7 +2,7 @@
{
public static class BoxWallpaper
{
public static string getWallpaper(SaveFile SAV, int index)
public static string GetWallpaper(SaveFile SAV, int index)
{
index++;
string s = "box_wp" + index.ToString("00");
@ -33,14 +33,14 @@
}
return s;
}
public static bool getWallpaperRed(SaveFile SAV, int box)
public static bool IsWallpaperRed(SaveFile SAV, int box)
{
switch (SAV.Generation)
{
case 3:
if (SAV.GameCube)
return box == 7 && SAV is SAV3XD; // flame pattern in XD
switch (SAV.getBoxWallpaper(box))
switch (SAV.GetBoxWallpaper(box))
{
case 5: // Volcano
return true;
@ -49,7 +49,7 @@
}
break;
case 4:
switch (SAV.getBoxWallpaper(box))
switch (SAV.GetBoxWallpaper(box))
{
case 5: // Volcano
case 12: // Checks
@ -59,7 +59,7 @@
}
break;
case 5:
switch (SAV.getBoxWallpaper(box))
switch (SAV.GetBoxWallpaper(box))
{
case 5: // Volcano
case 12: // Checks
@ -74,7 +74,7 @@
break;
case 6:
case 7:
switch (SAV.getBoxWallpaper(box))
switch (SAV.GetBoxWallpaper(box))
{
case 5: // Volcano
case 12: // PokéCenter

View file

@ -60,7 +60,7 @@ namespace PKHeX.Core
PouchDataSize = size > -1 ? size : legal.Length;
}
public void getPouch(ref byte[] Data)
public void GetPouch(ref byte[] Data)
{
InventoryItem[] items = new InventoryItem[PouchDataSize];
for (int i = 0; i < items.Length; i++)
@ -73,7 +73,7 @@ namespace PKHeX.Core
}
Items = items;
}
public void setPouch(ref byte[] Data)
public void SetPouch(ref byte[] Data)
{
if (Items.Length != PouchDataSize)
throw new ArgumentException("Item array length does not match original pouch size.");
@ -84,7 +84,7 @@ namespace PKHeX.Core
BitConverter.GetBytes((ushort)((ushort)Items[i].Count ^ (ushort)SecurityKey)).CopyTo(Data, Offset + i*4 + 2);
}
}
public void getPouch7(ref byte[] Data)
public void GetPouch7(ref byte[] Data)
{
InventoryItem[] items = new InventoryItem[PouchDataSize];
for (int i = 0; i < items.Length; i++)
@ -104,7 +104,7 @@ namespace PKHeX.Core
Items = items;
OriginalItems = Items.Select(i => i.Clone()).ToArray();
}
public void setPouch7(ref byte[] Data, bool setNEW = false)
public void SetPouch7(ref byte[] Data, bool setNEW = false)
{
if (Items.Length != PouchDataSize)
throw new ArgumentException("Item array length does not match original pouch size.");
@ -125,7 +125,7 @@ namespace PKHeX.Core
}
}
public void getPouchBigEndian(ref byte[] Data)
public void GetPouchBigEndian(ref byte[] Data)
{
InventoryItem[] items = new InventoryItem[PouchDataSize];
for (int i = 0; i < items.Length; i++)
@ -138,7 +138,7 @@ namespace PKHeX.Core
}
Items = items;
}
public void setPouchBigEndian(ref byte[] Data)
public void SetPouchBigEndian(ref byte[] Data)
{
if (Items.Length != PouchDataSize)
throw new ArgumentException("Item array length does not match original pouch size.");
@ -150,7 +150,7 @@ namespace PKHeX.Core
}
}
public void getPouchG1(ref byte[] Data)
public void GetPouchG1(ref byte[] Data)
{
InventoryItem[] items = new InventoryItem[PouchDataSize];
if (Type == InventoryType.TMHMs)
@ -209,40 +209,42 @@ namespace PKHeX.Core
Items = items;
}
public void setPouchG1(ref byte[] Data)
public void SetPouchG1(ref byte[] Data)
{
if (Items.Length != PouchDataSize)
throw new ArgumentException("Item array length does not match original pouch size.");
if (Type == InventoryType.TMHMs)
switch (Type)
{
for (int i = 0; i < Items.Length; i++)
{
if (LegalItems.Any(it => it == Items[i].Index))
Data[Offset + Array.FindIndex(LegalItems, it => Items[i].Index == it)] = (byte) Items[i].Count;
}
}
else if (Type == InventoryType.KeyItems)
{
for (int i = 0; i < Items.Length; i++)
{
Data[Offset + i + 1] = (byte)Items[i].Index;
}
Data[Offset] = (byte)Count;
Data[Offset + 1 + Count] = 0xFF;
}
else
{
for (int i = 0; i < Items.Length; i++)
{
Data[Offset + i * 2 + 1] = (byte)Items[i].Index;
Data[Offset + i * 2 + 2] = (byte)Items[i].Count;
}
Data[Offset] = (byte)Count;
Data[Offset + 1 + 2 * Count] = 0xFF;
case InventoryType.TMHMs:
foreach (InventoryItem t in Items)
{
if (!LegalItems.Any(it => it == t.Index))
continue;
int index = Offset + Array.FindIndex(LegalItems, it => t.Index == it);
Data[index] = (byte)t.Count;
}
break;
case InventoryType.KeyItems:
for (int i = 0; i < Items.Length; i++)
{
Data[Offset + i + 1] = (byte)Items[i].Index;
}
Data[Offset] = (byte)Count;
Data[Offset + 1 + Count] = 0xFF;
break;
default:
for (int i = 0; i < Items.Length; i++)
{
Data[Offset + i * 2 + 1] = (byte)Items[i].Index;
Data[Offset + i * 2 + 2] = (byte)Items[i].Count;
}
Data[Offset] = (byte)Count;
Data[Offset + 1 + 2 * Count] = 0xFF;
break;
}
}
public void sortCount(bool reverse = false)
public void SortByCount(bool reverse = false)
{
if (reverse)
Items = Items.Where(item => item.Index != 0).OrderBy(item => item.Count)
@ -251,7 +253,7 @@ namespace PKHeX.Core
Items = Items.Where(item => item.Index != 0).OrderByDescending(item => item.Count)
.Concat(Items.Where(item => item.Index == 0)).ToArray();
}
public void sortName(string[] names, bool reverse = false)
public void SortByName(string[] names, bool reverse = false)
{
if (reverse)
Items = Items.Where(item => item.Index != 0 && item.Index < names.Length).OrderByDescending(item => names[item.Index])
@ -261,7 +263,7 @@ namespace PKHeX.Core
.Concat(Items.Where(item => item.Index == 0 || item.Index >= names.Length)).ToArray();
}
public void sanitizePouch(bool HaX, int MaxItemID)
public void Sanitize(bool HaX, int MaxItemID)
{
var x = Items.Where(item => item.Valid(LegalItems, HaX, MaxItemID)).ToArray();
Items = x.Concat(new byte[PouchDataSize - x.Length].Select(i => new InventoryItem())).ToArray();

View file

@ -354,10 +354,14 @@ namespace PKHeX.Core
public class MemeKey
{
public byte[] D; // Private Exponent
public byte[] DER; // DER.
public byte[] E; // Public Exponent
public byte[] N; // Modulus
/// <summary> Private Exponent </summary>
public readonly byte[] D;
/// <summary> Distinguished Encoding Rules </summary>
public readonly byte[] DER;
/// <summary> Public Exponent </summary>
public readonly byte[] E;
/// <summary> Modulus </summary>
public readonly byte[] N;
public MemeKey(byte[] der, byte[] d = null)
{

View file

@ -17,7 +17,7 @@ namespace PKHeX.Core
public static class QR7
{
private static bool hasGenderDifferences(int species)
private static bool HasGenderDifferences(int species)
{
var gendered = new[]
{
@ -52,7 +52,7 @@ namespace PKHeX.Core
basedata[0x2B] = 2;
break;
default:
basedata[0x2D] = (byte)(hasGenderDifferences(species) ? 0 : 1);
basedata[0x2D] = (byte)(HasGenderDifferences(species) ? 0 : 1);
basedata[0x2B] = (byte)gender;
break;
}
@ -80,7 +80,7 @@ namespace PKHeX.Core
pk7.EncryptedPartyData.CopyTo(data, 0x30); // Copy in pokemon data
GetRawQR(pk7.Species, pk7.AltForm, pk7.IsShiny, pk7.Gender).CopyTo(data, 0x140);
BitConverter.GetBytes((ushort) SaveUtil.check16(data.Take(0x1A0).ToArray(), 0)).CopyTo(data, 0x1A0);
BitConverter.GetBytes(SaveUtil.CRC16_7(data.Take(0x1A0).ToArray(), 0)).CopyTo(data, 0x1A0);
return data;
}
}

View file

@ -54,11 +54,11 @@ namespace PKHeX.Core
get
{
int val = BigEndian.ToUInt16(Data, 0) & 0x1FF;
return PKX.getG4Species(val);
return PKX.GetG4Species(val);
}
set
{
value = PKX.getG3Species(value);
value = PKX.GetG3Species(value);
int cval = BigEndian.ToUInt16(Data, 0);
cval &= 0xE00; value &= 0x1FF; cval |= value;
BigEndian.GetBytes((ushort)cval).CopyTo(Data, 0);

View file

@ -16,9 +16,9 @@ namespace PKHeX.Core
/// </summary>
/// <param name="language">Language of the Pokémon species names to select (e.g. "en", "fr", "jp", etc.)</param>
/// <returns>An array of strings whose indexes correspond to the IDs of each Pokémon species name.</returns>
public static string[] getSpeciesList(string language)
public static string[] GetSpeciesList(string language)
{
return getStringList("species", language);
return GetStringList("species", language);
}
/// <summary>
@ -26,9 +26,9 @@ namespace PKHeX.Core
/// </summary>
/// <param name="language">Language of the move names to select (e.g. "en", "fr", "jp", etc.)</param>
/// <returns>An array of strings whose indexes correspond to the IDs of each move name.</returns>
public static string[] getMovesList(string language)
public static string[] GetMovesList(string language)
{
return getStringList("moves", language);
return GetStringList("moves", language);
}
/// <summary>
@ -36,9 +36,9 @@ namespace PKHeX.Core
/// </summary>
/// <param name="language">Language of the Pokémon ability names to select (e.g. "en", "fr", "jp", etc.)</param>
/// <returns>An array of strings whose indexes correspond to the IDs of each Pokémon ability name.</returns>
public static string[] getAbilitiesList(string language)
public static string[] GetAbilitiesList(string language)
{
return getStringList("abilities", language);
return GetStringList("abilities", language);
}
/// <summary>
@ -46,9 +46,9 @@ namespace PKHeX.Core
/// </summary>
/// <param name="language">Language of the Pokémon nature names to select (e.g. "en", "fr", "jp", etc.)</param>
/// <returns>An array of strings whose indexes correspond to the IDs of each Pokémon nature name.</returns>
public static string[] getNaturesList(string language)
public static string[] GetNaturesList(string language)
{
return getStringList("natures", language);
return GetStringList("natures", language);
}
/// <summary>
@ -56,9 +56,9 @@ namespace PKHeX.Core
/// </summary>
/// <param name="language">Language of the Pokémon form names to select (e.g. "en", "fr", "jp", etc.)</param>
/// <returns>An array of strings whose indexes correspond to the IDs of each Pokémon form name.</returns>
public static string[] getFormsList(string language)
public static string[] GetFormsList(string language)
{
return getStringList("forms", language);
return GetStringList("forms", language);
}
/// <summary>
@ -66,9 +66,9 @@ namespace PKHeX.Core
/// </summary>
/// <param name="language">Language of the Pokémon type names to select (e.g. "en", "fr", "jp", etc.)</param>
/// <returns>An array of strings whose indexes correspond to the IDs of each Pokémon type name.</returns>
public static string[] getTypesList(string language)
public static string[] GetTypesList(string language)
{
return getStringList("types", language);
return GetStringList("types", language);
}
/// <summary>
@ -76,9 +76,9 @@ namespace PKHeX.Core
/// </summary>
/// <param name="language">Language of the Pokémon characteristic to select (e.g. "en", "fr", "jp", etc.)</param>
/// <returns>An array of strings whose indexes correspond to the IDs of each Pokémon characteristic.</returns>
public static string[] getCharacteristicsList(string language)
public static string[] GetCharacteristicsList(string language)
{
return getStringList("character", language);
return GetStringList("character", language);
}
/// <summary>
@ -86,14 +86,14 @@ namespace PKHeX.Core
/// </summary>
/// <param name="language">Language of the items to select (e.g. "en", "fr", "jp", etc.)</param>
/// <returns>An array of strings whose indexes correspond to the IDs of each item.</returns>
public static string[] getItemsList(string language)
public static string[] GetItemsList(string language)
{
return getStringList("items", language);
return GetStringList("items", language);
}
#endregion
public static string[] getStringList(string f)
public static string[] GetStringList(string f)
{
var txt = Properties.Resources.ResourceManager.GetString(f); // Fetch File, \n to list.
if (txt == null) return new string[0];
@ -102,7 +102,7 @@ namespace PKHeX.Core
rawlist[i] = rawlist[i].Trim();
return rawlist;
}
public static string[] getStringList(string f, string l)
public static string[] GetStringList(string f, string l)
{
var txt = Properties.Resources.ResourceManager.GetString("text_" + f + "_" + l); // Fetch File, \n to list.
if (txt == null) return new string[0];
@ -111,14 +111,14 @@ namespace PKHeX.Core
rawlist[i] = rawlist[i].Trim();
return rawlist;
}
public static string[] getStringListFallback(string f, string l, string fallback)
public static string[] GetStringListFallback(string f, string l, string fallback)
{
string[] text = getStringList(f, l);
string[] text = GetStringList(f, l);
if (text.Length == 0)
text = getStringList(f, fallback);
text = GetStringList(f, fallback);
return text;
}
public static string[] getNulledStringArray(string[] SimpleStringList)
public static string[] GetNulledStringArray(string[] SimpleStringList)
{
try
{
@ -130,7 +130,7 @@ namespace PKHeX.Core
catch { return null; }
}
public static byte[] getBinaryResource(string name)
public static byte[] GetBinaryResource(string name)
{
using (var resource = typeof(Util).GetTypeInfo().Assembly.GetManifestResourceStream("PKHeX.Core.Resources.byte." + name))
{
@ -146,26 +146,26 @@ namespace PKHeX.Core
/// </summary>
/// <param name="input">Enumerable of translation definitions in the form "Property = Value".</param>
/// <returns></returns>
private static string[] getProps(IEnumerable<string> input)
private static string[] GetProperties(IEnumerable<string> input)
{
return input.Select(l => l.Substring(0, l.IndexOf(TranslationSplitter, StringComparison.Ordinal))).ToArray();
}
private static IEnumerable<string> DumpStrings(Type t)
{
var props = ReflectUtil.getPropertiesStartWithPrefix(t, "V");
var props = ReflectUtil.GetPropertiesStartWithPrefix(t, "V");
return props.Select(p => $"{p}{TranslationSplitter}{ReflectUtil.GetValue(t, p).ToString()}");
}
/// <summary>
/// Gets the current localization in a static class containing language-specific strings
/// </summary>
public static string[] getLocalization(Type t, string[] existingLines = null)
public static string[] GetLocalization(Type t, string[] existingLines = null)
{
existingLines = existingLines ?? new string[0];
var currentLines = DumpStrings(t).ToArray();
var existing = getProps(existingLines);
var current = getProps(currentLines);
var existing = GetProperties(existingLines);
var current = GetProperties(currentLines);
var result = new string[currentLines.Length];
for (int i = 0; i < current.Length; i++)
@ -181,7 +181,7 @@ namespace PKHeX.Core
/// </summary>
/// <param name="t">Type of the static class containing the desired strings.</param>
/// <param name="lines">Lines containing the localized strings</param>
private static void setLocalization(Type t, IEnumerable<string> lines)
private static void SetLocalization(Type t, IEnumerable<string> lines)
{
if (lines == null)
return;
@ -210,9 +210,9 @@ namespace PKHeX.Core
/// <param name="t">Type of the static class containing the desired strings.</param>
/// <param name="languageFilePrefix">Prefix of the language file to use. Example: if the target is legality_en.txt, <paramref name="languageFilePrefix"/> should be "legality".</param>
/// <param name="currentCultureCode">Culture information</param>
private static void setLocalization(Type t, string languageFilePrefix, string currentCultureCode)
private static void SetLocalization(Type t, string languageFilePrefix, string currentCultureCode)
{
setLocalization(t, getStringList($"{languageFilePrefix}_{currentCultureCode}"));
SetLocalization(t, GetStringList($"{languageFilePrefix}_{currentCultureCode}"));
}
/// <summary>
@ -221,18 +221,18 @@ namespace PKHeX.Core
/// <param name="t">Type of the static class containing the desired strings.</param>
/// <remarks>The values used to translate the given static class are retrieved from [TypeName]_[CurrentLangCode2].txt in the resource manager of PKHeX.Core.</remarks>
/// <param name="currentCultureCode">Culture information</param>
public static void setLocalization(Type t, string currentCultureCode)
public static void SetLocalization(Type t, string currentCultureCode)
{
setLocalization(t, t.Name, currentCultureCode);
SetLocalization(t, t.Name, currentCultureCode);
}
#endregion
#region DataSource Providing
public static List<ComboItem> getCBList(string textfile, string lang)
public static List<ComboItem> GetCBList(string textfile, string lang)
{
// Set up
string[] inputCSV = getStringList(textfile);
string[] inputCSV = GetStringList(textfile);
// Get Language we're fetching for
int index = Array.IndexOf(new[] { "ja", "en", "fr", "de", "it", "es", "ko", "zh", }, lang);
@ -261,7 +261,7 @@ namespace PKHeX.Core
Value = indexes[Array.IndexOf(unsortedList, s)]
}).ToList();
}
public static List<ComboItem> getCBList(string[] inStrings, params int[][] allowed)
public static List<ComboItem> GetCBList(string[] inStrings, params int[][] allowed)
{
List<ComboItem> cbList = new List<ComboItem>();
if (allowed?.First() == null)
@ -287,7 +287,7 @@ namespace PKHeX.Core
}
return cbList;
}
public static List<ComboItem> getOffsetCBList(List<ComboItem> cbList, string[] inStrings, int offset, int[] allowed)
public static List<ComboItem> GetOffsetCBList(List<ComboItem> cbList, string[] inStrings, int offset, int[] allowed)
{
if (allowed == null)
allowed = Enumerable.Range(0, inStrings.Length).ToArray();
@ -324,7 +324,7 @@ namespace PKHeX.Core
return cbList;
}
public static List<ComboItem> getVariedCBList(string[] inStrings, int[] stringNum, int[] stringVal)
public static List<ComboItem> GetVariedCBList(string[] inStrings, int[] stringNum, int[] stringVal)
{
// Set up
List<ComboItem> newlist = new List<ComboItem>();
@ -357,11 +357,11 @@ namespace PKHeX.Core
}));
return newlist;
}
public static List<ComboItem> getUnsortedCBList(string textfile)
public static List<ComboItem> GetUnsortedCBList(string textfile)
{
// Set up
List<ComboItem> cbList = new List<ComboItem>();
string[] inputCSV = getStringList(textfile);
string[] inputCSV = GetStringList(textfile);
// Gather our data from the input file
for (int i = 1; i < inputCSV.Length; i++)

View file

@ -5,7 +5,6 @@ namespace PKHeX.Core
{
public partial class Util
{
public static string CleanFileName(string fileName)
{
return Path.GetInvalidFileNameChars().Aggregate(fileName, (current, c) => current.Replace(c.ToString(), string.Empty));

Some files were not shown because too many files have changed in this diff Show more