diff --git a/Legality/Analysis.cs b/Legality/Analysis.cs new file mode 100644 index 000000000..be0f49160 --- /dev/null +++ b/Legality/Analysis.cs @@ -0,0 +1,96 @@ +using System.Linq; + +namespace PKHeX +{ + public enum Severity + { + Indeterminate = -2, + Invalid = -1, + Fishy = 0, + Valid = 1, + NotImplemented = 2, + } + public class LegalityCheck + { + public Severity Judgement = Severity.Invalid; + public string Comment; + public bool Valid => Judgement >= Severity.Fishy; + + public LegalityCheck() { } + public LegalityCheck(Severity s, string c) + { + Judgement = s; + Comment = c; + } + } + public class LegalityAnalysis + { + public bool Valid = false; + public int[] ValidMoves => Legal.getValidMoves(pk6.Species, pk6.CurrentLevel); + public int[] ValidRelearnMoves => Legal.getValidRelearn(pk6.Species); + public string Report => getLegalityReport(); + + private readonly PK6 pk6; + public LegalityAnalysis(PK6 pk) + { + pk6 = pk; + } + + public bool[] getMoveValidity(int[] Moves, int[] RelearnMoves) + { + if (Moves.Length != 4) + return null; + + if (!pk6.Gen6) + return new[] {true, true, true, true}; + + bool[] res = new bool[4]; + if (pk6.Species == 235) + { + for (int i = 0; i < 4; i++) + res[i] = !Legal.InvalidSketch.Contains(Moves[i]); + } + else + { + for (int i = 0; i < 4; i++) + res[i] = Moves[i] != Legal.Struggle && ValidMoves.Concat(RelearnMoves).Contains(Moves[i]); + } + if (Moves[0] == 0) + res[0] = false; + + return res; + } + + public bool[] getRelearnValidity(int[] Moves) + { + bool[] res = new bool[4]; + if (Moves.Length != 4) + return res; + + if (pk6.Egg_Location == 0) // Never Egg + { + if (pk6.Met_Location > 40000) // Event + { + // Not Implemented + } + else + { + // Check for DexNav + // Not Implemented + } + } + else + { + // Check Bred Moves + } + + return new[] { true, true, true, true }; + } + + public LegalityCheck EC, Nickname, PID, IDs, IVs, EVs; + private string getLegalityReport() + { + return null; + } + } +} diff --git a/Legality/Core.cs b/Legality/Core.cs new file mode 100644 index 000000000..d97b78308 --- /dev/null +++ b/Legality/Core.cs @@ -0,0 +1,87 @@ +using System.Collections.Generic; +using System.Linq; + +namespace PKHeX +{ + public static partial class Legal + { + // PKHeX master personal.dat + internal static readonly PersonalInfo[] PersonalAO = PersonalInfo.getPersonalArray(Properties.Resources.personal_ao, PersonalInfo.SizeAO); + + private static readonly PersonalInfo[] PersonalXY = PersonalInfo.getPersonalArray(Properties.Resources.personal_xy, PersonalInfo.SizeXY); + private static readonly EggMoves[] EggMoveXY = EggMoves.getArray(Util.unpackMini(Properties.Resources.eggmove_xy, "xy")); + private static readonly Learnset[] LevelUpXY = Learnset.getArray(Util.unpackMini(Properties.Resources.lvlmove_xy, "xy")); + private static readonly EggMoves[] EggMoveAO = EggMoves.getArray(Util.unpackMini(Properties.Resources.eggmove_ao, "ao")); + private static readonly Learnset[] LevelUpAO = Learnset.getArray(Util.unpackMini(Properties.Resources.lvlmove_ao, "ao")); + private static readonly Evolutions[] Evolves = Evolutions.getArray(Util.unpackMini(Properties.Resources.evos_ao, "ao")); + + internal static int[] getValidMoves(int species, int level) + { + int[] r = new int[1]; + + // r = r.Concat(getEggMoves(species)).ToArray(); + r = r.Concat(getLVLMoves(species, level)).ToArray(); + r = r.Concat(getTutorMoves(species)).ToArray(); + r = r.Concat(getMachineMoves(species)).ToArray(); + Evolutions e = Evolves[species]; + int dec = 0; + for (int i = 0; i < e.Species.Length; i++) + { + if (e.Level[i] == 1) // In order to level up evolve, the list of available moves is for one level previous. + dec++; + r = r.Concat(getLVLMoves(e.Species[i], level - dec)).ToArray(); + r = r.Concat(getTutorMoves(e.Species[i])).ToArray(); + r = r.Concat(getMachineMoves(e.Species[i])).ToArray(); + } + return r.Distinct().ToArray(); + } + internal static int[] getValidRelearn(int species) + { + int[] moves = new int[0]; + foreach (int spec in Evolves[species].Species) + { + moves = moves.Concat(getLVLMoves(spec, 1)).ToArray(); + moves = moves.Concat(getEggMoves(spec)).ToArray(); + moves = moves.Concat(getLVLMoves(spec, 100)).ToArray(); + } + moves = moves.Concat(getLVLMoves(species, 1)).ToArray(); + moves = moves.Concat(getEggMoves(species)).ToArray(); + moves = moves.Concat(getLVLMoves(species, 100)).ToArray(); + return moves.Concat(new int[1]).Distinct().ToArray(); + // Not implemented: DexNav exclusive moves, Wonder Cards + } + + private static int[] getEggMoves(int species) + { + return EggMoveAO[species].Moves.Concat(EggMoveXY[species].Moves).ToArray(); + } + private static int[] getLVLMoves(int species, int lvl) + { + return LevelUpXY[species].getMoves(lvl).Concat(LevelUpAO[species].getMoves(lvl)).ToArray(); + } + private static int[] getTutorMoves(int species) + { + PersonalInfo pkAO = PersonalAO[species]; + + // Type Tutor + List moves = TypeTutor.Where((t, i) => pkAO.Tutors[i]).ToList(); + + // Varied Tutors + for (int i = 0; i < Tutors_AO.Length; i++) + for (int b = 0; b < Tutors_AO[i].Length; b++) + if (pkAO.ORASTutors[i][b]) + moves.Add(Tutors_AO[i][b]); + + return moves.ToArray(); + } + private static int[] getMachineMoves(int species) + { + PersonalInfo pkXY = PersonalXY[species]; + PersonalInfo pkAO = PersonalAO[species]; + List moves = new List(); + moves.AddRange(TMHM_XY.Where((t, i) => pkXY.TMHM[i])); + moves.AddRange(TMHM_AO.Where((t, i) => pkAO.TMHM[i])); + return moves.ToArray(); + } + } +} diff --git a/Legality/Data.cs b/Legality/Data.cs new file mode 100644 index 000000000..f12593192 --- /dev/null +++ b/Legality/Data.cs @@ -0,0 +1,214 @@ +using System; +using System.IO; +using System.Linq; + +namespace PKHeX +{ + public class Learnset + { + public readonly int Count; + public readonly int[] Moves, Levels; + + public Learnset(byte[] data) + { + if (data.Length < 4 || data.Length % 4 != 0) + { Count = 0; Levels = new int[0]; Moves = new int[0]; return; } + Count = data.Length / 4 - 1; + Moves = new int[Count]; + Levels = new int[Count]; + using (BinaryReader br = new BinaryReader(new MemoryStream(data))) + for (int i = 0; i < Count; i++) + { + Moves[i] = br.ReadInt16(); + Levels[i] = br.ReadInt16(); + } + } + + public static Learnset[] getArray(byte[][] entries) + { + Learnset[] data = new Learnset[entries.Length]; + for (int i = 0; i < data.Length; i++) + data[i] = new Learnset(entries[i]); + return data; + } + + public int[] getMoves(int level) + { + for (int i = 0; i > Levels.Length; i++) + if (Levels[i] > level) + return Moves.Take(i).ToArray(); + return Moves; + } + } + public class EggMoves + { + public readonly int Count; + public readonly int[] Moves; + + public EggMoves(byte[] data) + { + if (data.Length < 2 || data.Length % 2 != 0) + { Count = 0; Moves = new int[0]; return; } + using (BinaryReader br = new BinaryReader(new MemoryStream(data))) + { + Moves = new int[Count = br.ReadUInt16()]; + for (int i = 0; i < Count; i++) + Moves[i] = br.ReadUInt16(); + } + } + + public static EggMoves[] getArray(byte[][] entries) + { + EggMoves[] data = new EggMoves[entries.Length]; + for (int i = 0; i < data.Length; i++) + data[i] = new EggMoves(entries[i]); + return data; + } + } + public class Evolutions + { + public readonly int[] Species, Level; + + public Evolutions(byte[] data) + { + int Count = data.Length / 4; + Level = new int[Count]; + Species = new int[Count]; + if (data.Length < 4 || data.Length % 4 != 0) return; + for (int i = 0; i < data.Length; i += 4) + { + Species[i / 4] = BitConverter.ToUInt16(data, i); + Level[i / 4] = BitConverter.ToUInt16(data, i + 2); + } + } + + public static Evolutions[] getArray(byte[][] entries) + { + Evolutions[] data = new Evolutions[entries.Length]; + for (int i = 0; i < data.Length; i++) + data[i] = new Evolutions(entries[i]); + return data; + } + } + public class PersonalInfo + { + internal static int SizeAO = 0x50; + internal static int SizeXY = 0x40; + public byte HP, ATK, DEF, SPE, SPA, SPD; + public int BST; + public int EV_HP, EV_ATK, EV_DEF, EV_SPE, EV_SPA, EV_SPD; + public byte[] Types = new byte[2]; + public byte CatchRate, EvoStage; + public ushort[] Items = new ushort[3]; + public byte Gender, HatchCycles, BaseFriendship, EXPGrowth; + public byte[] EggGroups = new byte[2]; + public byte[] Abilities = new byte[3]; + public ushort FormStats, FormeSprite, BaseEXP; + public byte FormeCount, Color; + public float Height, Weight; + public bool[] TMHM; + public bool[] Tutors; + public bool[][] ORASTutors = new bool[4][]; + public byte EscapeRate; + + public PersonalInfo(byte[] data) + { + using (BinaryReader br = new BinaryReader(new MemoryStream(data))) + { + HP = br.ReadByte(); ATK = br.ReadByte(); DEF = br.ReadByte(); + SPE = br.ReadByte(); SPA = br.ReadByte(); SPD = br.ReadByte(); + BST = HP + ATK + DEF + SPE + SPA + SPD; + + Types = new[] { br.ReadByte(), br.ReadByte() }; + CatchRate = br.ReadByte(); + EvoStage = br.ReadByte(); + + ushort EVs = br.ReadUInt16(); + EV_HP = EVs >> 0 & 0x3; + EV_ATK = EVs >> 2 & 0x3; + EV_DEF = EVs >> 4 & 0x3; + EV_SPE = EVs >> 6 & 0x3; + EV_SPA = EVs >> 8 & 0x3; + EV_SPD = EVs >> 10 & 0x3; + + Items = new[] { br.ReadUInt16(), br.ReadUInt16(), br.ReadUInt16() }; + Gender = br.ReadByte(); + HatchCycles = br.ReadByte(); + BaseFriendship = br.ReadByte(); + + EXPGrowth = br.ReadByte(); + EggGroups = new[] { br.ReadByte(), br.ReadByte() }; + Abilities = new[] { br.ReadByte(), br.ReadByte(), br.ReadByte() }; + EscapeRate = br.ReadByte(); + FormStats = br.ReadUInt16(); + + FormeSprite = br.ReadUInt16(); + FormeCount = br.ReadByte(); + Color = br.ReadByte(); + BaseEXP = br.ReadUInt16(); + + Height = br.ReadUInt16(); + Weight = br.ReadUInt16(); + + byte[] TMHMData = br.ReadBytes(0x10); + TMHM = new bool[8 * TMHMData.Length]; + for (int j = 0; j < TMHM.Length; j++) + TMHM[j] = (TMHMData[j / 8] >> (j % 8) & 0x1) == 1; //Bitflags for TMHM + + byte[] TutorData = br.ReadBytes(8); + Tutors = new bool[8 * TutorData.Length]; + for (int j = 0; j < Tutors.Length; j++) + Tutors[j] = (TutorData[j / 8] >> (j % 8) & 0x1) == 1; //Bitflags for Tutors + + if (br.BaseStream.Length - br.BaseStream.Position == 0x10) // ORAS + { + byte[][] ORASTutorData = + { + br.ReadBytes(4), // 15 + br.ReadBytes(4), // 17 + br.ReadBytes(4), // 16 + br.ReadBytes(4), // 15 + }; + for (int i = 0; i < 4; i++) + { + ORASTutors[i] = new bool[8 * ORASTutorData[i].Length]; + for (int b = 0; b < 8 * ORASTutorData[i].Length; b++) + ORASTutors[i][b] = (ORASTutorData[i][b / 8] >> b % 8 & 0x1) == 1; + } + } + } + } + + // Data Manipulation + public int FormeIndex(int species, int forme) + { + return forme == 0 || FormStats == 0 ? species : FormStats + forme - 1; + } + public int RandomGender + { + get + { + switch (Gender) + { + case 255: // Genderless + return 2; + case 254: // Female + return 1; + case 0: // Male + return 0; + default: + return (int)(Util.rnd32() % 2); + } + } + } + public bool HasFormes => FormeCount > 1; + + internal static PersonalInfo[] getPersonalArray(byte[] data, int size) + { + PersonalInfo[] d = new PersonalInfo[data.Length / size]; + for (int i = 0; i < d.Length; i++) + d[i] = new PersonalInfo(data.Skip(i * size).Take(size).ToArray()); + return d; + } + } +} diff --git a/Misc/Legal.cs b/Legality/Tables.cs similarity index 97% rename from Misc/Legal.cs rename to Legality/Tables.cs index 8fc859301..80b952f1c 100644 --- a/Misc/Legal.cs +++ b/Legality/Tables.cs @@ -1,6 +1,6 @@ namespace PKHeX { - internal static class Legal + public static partial class Legal { // PKHeX Valid Array Storage #region Items @@ -166,7 +166,7 @@ internal static class Legal }; #endregion #region TMHM - internal static readonly int[] AO_TMHM = + internal static readonly int[] TMHM_AO = { 468, 337, 473, 347, 046, 092, 258, 339, 474, 237, 241, 269, 058, 059, 063, 113, 182, 240, 355, 219, @@ -181,7 +181,7 @@ internal static class Legal 15, 19, 57, 70, 127, 249, 291, }; - internal static readonly int[] XY_TMHM = + internal static readonly int[] TMHM_XY = { 468, 337, 473, 347, 046, 092, 258, 339, 474, 237, 241, 269, 058, 059, 063, 113, 182, 240, 355, 219, @@ -196,8 +196,8 @@ internal static class Legal 15, 19, 57, 70, 127, }; - internal static readonly int[] AO_TypeTutor = { 338, 307, 308, 520, 519, 518, 434, 620 }; - internal static readonly int[][] AO_Tutors = + internal static readonly int[] TypeTutor = { 338, 307, 308, 520, 519, 518, 434, 620 }; + internal static readonly int[][] Tutors_AO = { new[] {450, 343, 162, 530, 324, 442, 402, 529, 340, 67, 441, 253, 9, 7, 8}, new[] {277, 335, 414, 492, 356, 393, 334, 387, 276, 527, 196, 401, 399, 428, 406, 304, 231}, @@ -205,5 +205,9 @@ internal static class Legal new[] {380, 388, 180, 495, 270, 271, 478, 472, 283, 200, 278, 289, 446, 214, 285}, }; #endregion + + internal static readonly int Struggle = 165; + internal static readonly int Chatter = 448; + internal static readonly int[] InvalidSketch = {Struggle, Chatter}; } } diff --git a/Misc/Legality.cs b/Misc/Legality.cs deleted file mode 100644 index d68cc9ddc..000000000 --- a/Misc/Legality.cs +++ /dev/null @@ -1,178 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace PKHeX -{ - public class LegalityChecker - { - private readonly EggMoves[] EggMoveXY = EggMoves.getArray(Util.unpackMini(Properties.Resources.eggmove_xy, "xy")); - private readonly Learnset[] LevelUpXY = Learnset.getArray(Util.unpackMini(Properties.Resources.lvlmove_xy, "xy")); - private readonly EggMoves[] EggMoveAO = EggMoves.getArray(Util.unpackMini(Properties.Resources.eggmove_ao, "ao")); - private readonly Learnset[] LevelUpAO = Learnset.getArray(Util.unpackMini(Properties.Resources.lvlmove_ao, "ao")); - private readonly Evolutions[] Evolves = Evolutions.getArray(Util.unpackMini(Properties.Resources.evos_ao, "ao")); - private readonly PKX.PersonalInfo[] PersonalAO = PKX.getPersonalArray(Properties.Resources.personal_ao, PKX.PersonalInfo.SizeAO); - private readonly PKX.PersonalInfo[] PersonalXY = PKX.getPersonalArray(Properties.Resources.personal_xy, PKX.PersonalInfo.SizeXY); - - public LegalityChecker() - { - Console.WriteLine("Initializing Legality Checker..."); - } - public int[] getValidMoves(int species, int level) - { - int[] r = new int[1]; - - // r = r.Concat(getEggMoves(species)).ToArray(); - r = r.Concat(getLVLMoves(species, level)).ToArray(); - r = r.Concat(getTutorMoves(species)).ToArray(); - r = r.Concat(getMachineMoves(species)).ToArray(); - Evolutions e = Evolves[species]; - int dec = 0; - for (int i = 0; i < e.Species.Length; i++) - { - if (e.Level[i] == 1) // In order to level up evolve, the list of available moves is for one level previous. - dec++; - r = r.Concat(getLVLMoves(e.Species[i], level - dec)).ToArray(); - r = r.Concat(getTutorMoves(e.Species[i])).ToArray(); - r = r.Concat(getMachineMoves(e.Species[i])).ToArray(); - } - return r.Distinct().ToArray(); - } - - public int[] getValidRelearn(int species) - { - int[] moves = new int[0]; - foreach (int spec in Evolves[species].Species) - { - moves = moves.Concat(getLVLMoves(spec, 1)).ToArray(); - moves = moves.Concat(getEggMoves(spec)).ToArray(); - moves = moves.Concat(getLVLMoves(spec, 100)).ToArray(); - } - moves = moves.Concat(getLVLMoves(species, 1)).ToArray(); - moves = moves.Concat(getEggMoves(species)).ToArray(); - moves = moves.Concat(getLVLMoves(species, 100)).ToArray(); - return moves.Concat(new int[1]).Distinct().ToArray(); - // Not implemented: DexNav exclusive moves, Wonder Cards - } - private int[] getEggMoves(int species) - { - return EggMoveAO[species].Moves.Concat(EggMoveXY[species].Moves).ToArray(); - } - private int[] getLVLMoves(int species, int lvl) - { - return LevelUpXY[species].getMoves(lvl).Concat(LevelUpAO[species].getMoves(lvl)).ToArray(); - } - private int[] getTutorMoves(int species) - { - PKX.PersonalInfo pkAO = PersonalAO[species]; - - // Type Tutor - List moves = Legal.AO_TypeTutor.Where((t, i) => pkAO.Tutors[i]).ToList(); - - // Varied Tutors - for (int i = 0; i < Legal.AO_Tutors.Length; i++) - for (int b = 0; b < Legal.AO_Tutors[i].Length; b++) - if (pkAO.ORASTutors[i][b]) - moves.Add(Legal.AO_Tutors[i][b]); - - return moves.ToArray(); - } - private int[] getMachineMoves(int species) - { - PKX.PersonalInfo pkXY = PersonalXY[species]; - PKX.PersonalInfo pkAO = PersonalAO[species]; - List moves = new List(); - moves.AddRange(Legal.XY_TMHM.Where((t, i) => pkXY.TMHM[i])); - moves.AddRange(Legal.AO_TMHM.Where((t, i) => pkAO.TMHM[i])); - return moves.ToArray(); - } - } - - public class Learnset - { - public readonly int Count; - public readonly int[] Moves, Levels; - - public Learnset(byte[] data) - { - if (data.Length < 4 || data.Length % 4 != 0) - { Count = 0; Levels = new int[0]; Moves = new int[0]; return; } - Count = data.Length / 4 - 1; - Moves = new int[Count]; - Levels = new int[Count]; - using (BinaryReader br = new BinaryReader(new MemoryStream(data))) - for (int i = 0; i < Count; i++) - { - Moves[i] = br.ReadInt16(); - Levels[i] = br.ReadInt16(); - } - } - - public static Learnset[] getArray(byte[][] entries) - { - Learnset[] data = new Learnset[entries.Length]; - for (int i = 0; i < data.Length; i++) - data[i] = new Learnset(entries[i]); - return data; - } - - public int[] getMoves(int level) - { - for (int i = 0; i > Levels.Length; i++) - if (Levels[i] > level) - return Moves.Take(i).ToArray(); - return Moves; - } - } - public class EggMoves - { - public readonly int Count; - public readonly int[] Moves; - - public EggMoves(byte[] data) - { - if (data.Length < 2 || data.Length%2 != 0) - { Count = 0; Moves = new int[0]; return; } - using (BinaryReader br = new BinaryReader(new MemoryStream(data))) - { - Moves = new int[Count = br.ReadUInt16()]; - for (int i = 0; i < Count; i++) - Moves[i] = br.ReadUInt16(); - } - } - - public static EggMoves[] getArray(byte[][] entries) - { - EggMoves[] data = new EggMoves[entries.Length]; - for (int i = 0; i < data.Length; i++) - data[i] = new EggMoves(entries[i]); - return data; - } - } - public class Evolutions - { - public readonly int[] Species, Level; - - public Evolutions(byte[] data) - { - int Count = data.Length / 4; - Level = new int[Count]; - Species = new int[Count]; - if (data.Length < 4 || data.Length % 4 != 0) return; - for (int i = 0; i < data.Length; i+=4) - { - Species[i/4] = BitConverter.ToUInt16(data, i); - Level[i/4] = BitConverter.ToUInt16(data, i+2); - } - } - - public static Evolutions[] getArray(byte[][] entries) - { - Evolutions[] data = new Evolutions[entries.Length]; - for (int i = 0; i < data.Length; i++) - data[i] = new Evolutions(entries[i]); - return data; - } - } -} diff --git a/Misc/PK6.cs b/Misc/PK6.cs index edff87129..43c037e2b 100644 --- a/Misc/PK6.cs +++ b/Misc/PK6.cs @@ -441,6 +441,7 @@ public int[] Moves if (value.Length > 3) Move4 = value[3]; } } + public int CurrentLevel => getLevel(Species, EXP); // Complex Generated Attributes public Image Sprite => getSprite(this); diff --git a/Misc/PKX.cs b/Misc/PKX.cs index 52b40cc39..5cae656db 100644 --- a/Misc/PKX.cs +++ b/Misc/PKX.cs @@ -1,7 +1,6 @@ using System; using System.Drawing; using System.Drawing.Text; -using System.IO; using System.Linq; namespace PKHeX @@ -153,14 +152,7 @@ internal static string getSpeciesName(int species, int lang) try { return SpeciesLang[lang][species]; } catch { return ""; } } - internal static readonly PersonalInfo[] Personal = getPersonalArray(Properties.Resources.personal_ao, PersonalInfo.SizeAO); - internal static PersonalInfo[] getPersonalArray(byte[] data, int size) - { - PersonalInfo[] d = new PersonalInfo[data.Length / size]; - for (int i = 0; i < d.Length; i++) - d[i] = new PersonalInfo(data.Skip(i*size).Take(size).ToArray()); - return d; - } + internal static readonly PersonalInfo[] Personal = Legal.PersonalAO; // Stat Fetching internal static int getMovePP(int move, int ppup) @@ -1521,119 +1513,5 @@ internal static string getShowdownText(PK6 pk6) if (Set.Form == "F") Set.Gender = ""; return Set.getText(); } - - public class PersonalInfo - { - internal static int SizeAO = 0x50; - internal static int SizeXY = 0x40; - public byte HP, ATK, DEF, SPE, SPA, SPD; - public int BST; - public int EV_HP, EV_ATK, EV_DEF, EV_SPE, EV_SPA, EV_SPD; - public byte[] Types = new byte[2]; - public byte CatchRate, EvoStage; - public ushort[] Items = new ushort[3]; - public byte Gender, HatchCycles, BaseFriendship, EXPGrowth; - public byte[] EggGroups = new byte[2]; - public byte[] Abilities = new byte[3]; - public ushort FormStats, FormeSprite, BaseEXP; - public byte FormeCount, Color; - public float Height, Weight; - public bool[] TMHM; - public bool[] Tutors; - public bool[][] ORASTutors = new bool[4][]; - public byte EscapeRate; - - public PersonalInfo(byte[] data) - { - using (BinaryReader br = new BinaryReader(new MemoryStream(data))) - { - HP = br.ReadByte(); ATK = br.ReadByte(); DEF = br.ReadByte(); - SPE = br.ReadByte(); SPA = br.ReadByte(); SPD = br.ReadByte(); - BST = HP + ATK + DEF + SPE + SPA + SPD; - - Types = new[] { br.ReadByte(), br.ReadByte() }; - CatchRate = br.ReadByte(); - EvoStage = br.ReadByte(); - - ushort EVs = br.ReadUInt16(); - EV_HP = EVs >> 0 & 0x3; - EV_ATK = EVs >> 2 & 0x3; - EV_DEF = EVs >> 4 & 0x3; - EV_SPE = EVs >> 6 & 0x3; - EV_SPA = EVs >> 8 & 0x3; - EV_SPD = EVs >> 10 & 0x3; - - Items = new[] { br.ReadUInt16(), br.ReadUInt16(), br.ReadUInt16() }; - Gender = br.ReadByte(); - HatchCycles = br.ReadByte(); - BaseFriendship = br.ReadByte(); - - EXPGrowth = br.ReadByte(); - EggGroups = new[] { br.ReadByte(), br.ReadByte() }; - Abilities = new[] { br.ReadByte(), br.ReadByte(), br.ReadByte() }; - EscapeRate = br.ReadByte(); - FormStats = br.ReadUInt16(); - - FormeSprite = br.ReadUInt16(); - FormeCount = br.ReadByte(); - Color = br.ReadByte(); - BaseEXP = br.ReadUInt16(); - - Height = br.ReadUInt16(); - Weight = br.ReadUInt16(); - - byte[] TMHMData = br.ReadBytes(0x10); - TMHM = new bool[8 * TMHMData.Length]; - for (int j = 0; j < TMHM.Length; j++) - TMHM[j] = (TMHMData[j / 8] >> (j % 8) & 0x1) == 1; //Bitflags for TMHM - - byte[] TutorData = br.ReadBytes(8); - Tutors = new bool[8 * TutorData.Length]; - for (int j = 0; j < Tutors.Length; j++) - Tutors[j] = (TutorData[j / 8] >> (j % 8) & 0x1) == 1; //Bitflags for Tutors - - if (br.BaseStream.Length - br.BaseStream.Position == 0x10) // ORAS - { - byte[][] ORASTutorData = - { - br.ReadBytes(4), // 15 - br.ReadBytes(4), // 17 - br.ReadBytes(4), // 16 - br.ReadBytes(4), // 15 - }; - for (int i = 0; i < 4; i++) - { - ORASTutors[i] = new bool[8 * ORASTutorData[i].Length]; - for (int b = 0; b < 8 * ORASTutorData[i].Length; b++) - ORASTutors[i][b] = (ORASTutorData[i][b / 8] >> b % 8 & 0x1) == 1; - } - } - } - } - - // Data Manipulation - public int FormeIndex(int species, int forme) - { - return forme == 0 || FormStats == 0 ? species : FormStats + forme - 1; - } - public int RandomGender - { - get - { - switch (Gender) - { - case 255: // Genderless - return 2; - case 254: // Female - return 1; - case 0: // Male - return 0; - default: - return (int)(Util.rnd32()%2); - } - } - } - public bool HasFormes => FormeCount > 1; - } } } diff --git a/PKHeX.csproj b/PKHeX.csproj index 4a0ce46d6..56b3cc93e 100644 --- a/PKHeX.csproj +++ b/PKHeX.csproj @@ -68,11 +68,13 @@ - + + + - + diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index be73d28f1..2d95640ce 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -153,8 +153,7 @@ public Main() private static string pathSDF; private static string path3DS; private static bool HaX; - private int[] validMoves = new int[0]; - private readonly LegalityChecker LC = new LegalityChecker(); + private LegalityAnalysis Legality = new LegalityAnalysis(new PK6()); private static readonly Image mixedHighlight = Util.ChangeOpacity(Properties.Resources.slotSet, 0.5); private static readonly string BackupPath = "bak"; private static readonly string[] lang_val = { "en", "ja", "fr", "it", "de", "es", "ko", "zh", "pt" }; @@ -2062,14 +2061,23 @@ private void validateMove(object sender, EventArgs e) bool gen6 = Version >= 24 && Version <= 29; int species = Util.getIndex(CB_Species); int index = Array.IndexOf(new[] { CB_Move1, CB_Move2, CB_Move3, CB_Move4 }, sender); + int[] moves = + { + Util.getIndex(CB_Move1), Util.getIndex(CB_Move2), + Util.getIndex(CB_Move3), Util.getIndex(CB_Move4) + }; + int[] relearnMoves = + { + Util.getIndex(CB_RelearnMove1), Util.getIndex(CB_RelearnMove2), + Util.getIndex(CB_RelearnMove3), Util.getIndex(CB_RelearnMove4) + }; if (index > -1) // Move { updatePP(sender, e); - int[] moves = validMoves.Concat(new[] { - Util.getIndex(CB_RelearnMove1), Util.getIndex(CB_RelearnMove2), Util.getIndex(CB_RelearnMove3), Util.getIndex(CB_RelearnMove4) - }).ToArray(); - - new[] {PB_WarnMove1, PB_WarnMove2, PB_WarnMove3, PB_WarnMove4}[index].Visible = gen6 && !moves.Contains(Util.getIndex(sender as ComboBox)) && species != 235; // smeargle + PictureBox[] moveCB = {PB_WarnMove1, PB_WarnMove2, PB_WarnMove3, PB_WarnMove4}; + bool[] x = Legality.getMoveValidity(moves, relearnMoves); + for (int i = 0; i < 4; i++) + moveCB[i].Visible = !x[i]; } else { @@ -2084,8 +2092,7 @@ private void validateMove(object sender, EventArgs e) } else if (egg && gen6) { - int[] moves = LC.getValidRelearn(Util.getIndex(CB_Species)); - pb.Visible = !moves.Contains(Util.getIndex(cb)); + pb.Visible = !Legality.ValidRelearnMoves.Contains(relearnMoves[index]); } else { @@ -2103,7 +2110,8 @@ private void updateValidMoves() { if (!fieldsLoaded) return; - validMoves = LC.getValidMoves(Util.getIndex(CB_Species), Util.ToInt32(MT_Level.Enabled ? MT_Level.Text : TB_Level.Text)); + + Legality = new LegalityAnalysis(pk6); // refresh foreach (ComboBox cb in new[] {CB_RelearnMove1, CB_RelearnMove2, CB_RelearnMove3, CB_RelearnMove4})