From c9421f3c5b7c87f82ec0aa71e04d75850a8b356f Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 11 Feb 2017 15:20:44 -0800 Subject: [PATCH] Add gen1 learnset/evo information Still need encounter info for all 3 games. --- PKHeX/Legality/Core.cs | 41 +++++++----- PKHeX/Legality/Structures/EvolutionTree.cs | 69 +++++++++++++++++++-- PKHeX/Legality/Structures/Learnset.cs | 32 +++++++++- PKHeX/PKHeX.Core.csproj | 2 + PKHeX/Properties/Resources.Designer.cs | 42 ++++++++++--- PKHeX/Properties/Resources.resx | 6 ++ PKHeX/Resources/byte/evos_rby.pkl | Bin 0 -> 384 bytes PKHeX/Resources/byte/lvlmove_rby.pkl | Bin 0 -> 1662 bytes 8 files changed, 159 insertions(+), 33 deletions(-) create mode 100644 PKHeX/Resources/byte/evos_rby.pkl create mode 100644 PKHeX/Resources/byte/lvlmove_rby.pkl diff --git a/PKHeX/Legality/Core.cs b/PKHeX/Legality/Core.cs index ebbf3b879..eab18325b 100644 --- a/PKHeX/Legality/Core.cs +++ b/PKHeX/Legality/Core.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using PKHeX.Core.Properties; namespace PKHeX.Core { @@ -9,18 +10,22 @@ public static partial class Legal // Event Database(s) public static MysteryGift[] MGDB_G6, MGDB_G7 = new MysteryGift[0]; + // Gen 1 + private static readonly Learnset[] LevelUpRB = Learnset1.getArray(Resources.lvlmove_rby); + private static readonly EvolutionTree Evolves1; + // Gen 6 - private static readonly EggMoves[] EggMovesXY = EggMoves6.getArray(Data.unpackMini(Properties.Resources.eggmove_xy, "xy")); - private static readonly Learnset[] LevelUpXY = Learnset6.getArray(Data.unpackMini(Properties.Resources.lvlmove_xy, "xy")); - private static readonly EggMoves[] EggMovesAO = EggMoves6.getArray(Data.unpackMini(Properties.Resources.eggmove_ao, "ao")); - private static readonly Learnset[] LevelUpAO = Learnset6.getArray(Data.unpackMini(Properties.Resources.lvlmove_ao, "ao")); + private static readonly EggMoves[] EggMovesXY = EggMoves6.getArray(Data.unpackMini(Resources.eggmove_xy, "xy")); + private static readonly Learnset[] LevelUpXY = Learnset6.getArray(Data.unpackMini(Resources.lvlmove_xy, "xy")); + private static readonly EggMoves[] EggMovesAO = EggMoves6.getArray(Data.unpackMini(Resources.eggmove_ao, "ao")); + private static readonly Learnset[] LevelUpAO = Learnset6.getArray(Data.unpackMini(Resources.lvlmove_ao, "ao")); private static readonly EvolutionTree Evolves6; private static readonly EncounterArea[] SlotsX, SlotsY, SlotsA, SlotsO; private static readonly EncounterStatic[] StaticX, StaticY, StaticA, StaticO; // Gen 7 - private static readonly EggMoves[] EggMovesSM = EggMoves7.getArray(Data.unpackMini(Properties.Resources.eggmove_sm, "sm")); - private static readonly Learnset[] LevelUpSM = Learnset7.getArray(Data.unpackMini(Properties.Resources.lvlmove_sm, "sm")); + private static readonly EggMoves[] EggMovesSM = EggMoves7.getArray(Data.unpackMini(Resources.eggmove_sm, "sm")); + private static readonly Learnset[] LevelUpSM = Learnset7.getArray(Data.unpackMini(Resources.lvlmove_sm, "sm")); private static readonly EvolutionTree Evolves7; private static readonly EncounterArea[] SlotsSN, SlotsMN; private static readonly EncounterStatic[] StaticSN, StaticMN; @@ -56,27 +61,27 @@ private static EncounterArea[] getEncounterTables(GameVersion Game) { case GameVersion.X: ident = "xy"; - tables = Properties.Resources.encounter_x; + tables = Resources.encounter_x; break; case GameVersion.Y: ident = "xy"; - tables = Properties.Resources.encounter_y; + tables = Resources.encounter_y; break; case GameVersion.AS: ident = "ao"; - tables = Properties.Resources.encounter_a; + tables = Resources.encounter_a; break; case GameVersion.OR: ident = "ao"; - tables = Properties.Resources.encounter_o; + tables = Resources.encounter_o; break; case GameVersion.SN: ident = "sm"; - tables = Properties.Resources.encounter_sn; + tables = Resources.encounter_sn; break; case GameVersion.MN: ident = "sm"; - tables = Properties.Resources.encounter_mn; + tables = Resources.encounter_mn; break; } if (ident == null) @@ -128,6 +133,10 @@ private static void MarkG7SMSlots(ref EncounterArea[] Areas) static Legal() // Setup { + // Gen 1 + { + Evolves1 = new EvolutionTree(new[] { Resources.evos_rby }, GameVersion.RBY, PersonalTable.RBY, MaxSpeciesID_1); + } // Gen 6 { StaticX = getStaticEncounters(GameVersion.X); @@ -147,7 +156,7 @@ private static void MarkG7SMSlots(ref EncounterArea[] Areas) MarkG6AOSlots(ref SlotsA); MarkG6AOSlots(ref SlotsO); - Evolves6 = new EvolutionTree(Data.unpackMini(Properties.Resources.evos_ao, "ao"), GameVersion.ORAS, PersonalTable.AO, 721); + Evolves6 = new EvolutionTree(Data.unpackMini(Resources.evos_ao, "ao"), GameVersion.ORAS, PersonalTable.AO, MaxSpeciesID_6); } // Gen 7 { @@ -155,14 +164,14 @@ private static void MarkG7SMSlots(ref EncounterArea[] Areas) StaticMN = getStaticEncounters(GameVersion.MN); var REG_SN = getEncounterTables(GameVersion.SN); var REG_MN = getEncounterTables(GameVersion.MN); - var SOS_SN = getEncounterTables(Properties.Resources.encounter_sn_sos, "sm"); - var SOS_MN = getEncounterTables(Properties.Resources.encounter_mn_sos, "sm"); + var SOS_SN = getEncounterTables(Resources.encounter_sn_sos, "sm"); + var SOS_MN = getEncounterTables(Resources.encounter_mn_sos, "sm"); MarkG7SMSlots(ref SOS_SN); MarkG7SMSlots(ref SOS_MN); SlotsSN = addExtraTableSlots(REG_SN, SOS_SN).Concat(Encounter_Pelago_SM).Concat(Encounter_Pelago_SN).ToArray(); SlotsMN = addExtraTableSlots(REG_MN, SOS_MN).Concat(Encounter_Pelago_SM).Concat(Encounter_Pelago_MN).ToArray(); - Evolves7 = new EvolutionTree(Data.unpackMini(Properties.Resources.evos_sm, "sm"), GameVersion.SM, PersonalTable.SM, 802); + Evolves7 = new EvolutionTree(Data.unpackMini(Resources.evos_sm, "sm"), GameVersion.SM, PersonalTable.SM, MaxSpeciesID_7); } } diff --git a/PKHeX/Legality/Structures/EvolutionTree.cs b/PKHeX/Legality/Structures/EvolutionTree.cs index a035817c4..1371a2525 100644 --- a/PKHeX/Legality/Structures/EvolutionTree.cs +++ b/PKHeX/Legality/Structures/EvolutionTree.cs @@ -19,12 +19,15 @@ public EvolutionTree(byte[][] data, GameVersion game, PersonalTable personal, in MaxSpeciesTree = maxSpeciesTree; switch (game) { - case GameVersion.SM: - Entries.AddRange(data.Select(d => new EvolutionSet7(d))); + case GameVersion.RBY: + Entries = EvolutionSet1.getArray(data[0]); break; case GameVersion.ORAS: Entries.AddRange(data.Select(d => new EvolutionSet6(d))); break; + case GameVersion.SM: + Entries.AddRange(data.Select(d => new EvolutionSet7(d))); + break; } // Create Lineages @@ -32,7 +35,7 @@ public EvolutionTree(byte[][] data, GameVersion game, PersonalTable personal, in for (int i = 0; i < Entries.Count; i++) Lineage[i] = new EvolutionLineage(); if (Game == GameVersion.ORAS) - Array.Resize(ref Lineage, maxSpeciesTree + 1); + Array.Resize(ref Lineage, MaxSpeciesTree + 1); // Populate Lineages for (int i = 1; i < Lineage.Length; i++) @@ -162,6 +165,58 @@ public abstract class EvolutionSet { public EvolutionMethod[] PossibleEvolutions; } + public class EvolutionSet1 : EvolutionSet + { + private static EvolutionMethod getMethod(byte[] data, ref int offset) + { + switch (data[offset]) + { + case 1: // Level + var m1 = new EvolutionMethod + { + Method = 1, // Use Item + Level = data[offset + 1], + Species = data[offset + 2] + }; + offset += 3; + return m1; + case 2: // Use Item + var m2 = new EvolutionMethod + { + Method = 8, // Use Item + Argument = data[offset + 1], + // 1 + Species = data[offset + 3], + }; + offset += 4; + return m2; + case 3: // Trade + var m3 = new EvolutionMethod + { + Method = 5, // Trade + // 1 + Species = data[offset + 2] + }; + offset += 3; + return m3; + } + return null; + } + public static List getArray(byte[] data) + { + var evos = new List(); + int offset = 0; + for (int i = 0; i <= Legal.MaxSpeciesID_1; i++) + { + var m = new List(); + while (data[offset] != 0) + m.Add(getMethod(data, ref offset)); + ++offset; + evos.Add(new EvolutionSet1 { PossibleEvolutions = m.ToArray() }); + } + return evos; + } + } public class EvolutionSet6 : EvolutionSet { private const int SIZE = 6; @@ -172,7 +227,7 @@ public EvolutionSet6(byte[] data) PossibleEvolutions = new EvolutionMethod[data.Length / SIZE]; for (int i = 0; i < data.Length; i += SIZE) { - PossibleEvolutions[i/SIZE] = new EvolutionMethod + var evo = new EvolutionMethod { Method = BitConverter.ToUInt16(data, i + 0), Argument = BitConverter.ToUInt16(data, i + 2), @@ -183,8 +238,10 @@ public EvolutionSet6(byte[] data) }; // Argument is used by both Level argument and Item/Move/etc. Clear if appropriate. - if (argEvos.Contains(PossibleEvolutions[i/SIZE].Method)) - PossibleEvolutions[i/SIZE].Level = 0; + if (argEvos.Contains(evo.Method)) + evo.Level = 0; + + PossibleEvolutions[i/SIZE] = evo; } } } diff --git a/PKHeX/Legality/Structures/Learnset.cs b/PKHeX/Legality/Structures/Learnset.cs index c8c48f995..e2979151e 100644 --- a/PKHeX/Legality/Structures/Learnset.cs +++ b/PKHeX/Legality/Structures/Learnset.cs @@ -1,4 +1,5 @@ -using System.IO; +using System.Collections.Generic; +using System.IO; using System.Linq; namespace PKHeX.Core @@ -17,6 +18,35 @@ public int[] getMoves(int level) return Moves; } } + + public class Learnset1 : Learnset + { + private Learnset1(byte[] data, ref int offset) + { + var moves = new List(); + var levels = new List(); + while (data[offset] != 0) + { + levels.Add(data[offset++]); + moves.Add(data[offset++]); + } + ++offset; + + Moves = moves.ToArray(); + Levels = levels.ToArray(); + Count = Moves.Length; + } + public static Learnset[] getArray(byte[] input) + { + var data = new Learnset[Legal.MaxSpeciesID_1 + 1]; + + int offset = 0; + for (int s = 0; s < data.Length; s++) + data[s] = new Learnset1(input, ref offset); + + return data; + } + } public class Learnset6 : Learnset { private Learnset6(byte[] data) diff --git a/PKHeX/PKHeX.Core.csproj b/PKHeX/PKHeX.Core.csproj index 937ed2610..e9e4ba201 100644 --- a/PKHeX/PKHeX.Core.csproj +++ b/PKHeX/PKHeX.Core.csproj @@ -265,11 +265,13 @@ + + diff --git a/PKHeX/Properties/Resources.Designer.cs b/PKHeX/Properties/Resources.Designer.cs index 31bb89b02..294b925a1 100644 --- a/PKHeX/Properties/Resources.Designer.cs +++ b/PKHeX/Properties/Resources.Designer.cs @@ -12324,12 +12324,14 @@ public class Resources { /// Looks up a localized string similar to PKHeX - By Kaphotics ///http://projectpokemon.org/pkhex /// - ///17/01/30 - New Update: - /// - Added: Control right-clicking a PKM slot (box, party, etc) now allows direct legality checking. - /// - Added: 6/7 detection preferential treatment & other detection methods. Thanks sora10pls! - /// - Added: Remove All medals button now clears Unlocked/Complete flags even if not visible. - /// - Fixed: Badly constructed ShowdownSets throw less exceptions (hopefully none). Thanks Sonic Blader! - /// - Fixed: Cloning to all slots in a Gen1/2 [rest of string was truncated]";. + ///17/02/07 - New Update: + /// - Legality: + /// - - Added: Legality indication for exported QR images (if legality check is available for origin). + /// - - Added: Legality indication for Box/Party pkm slots (^ + opt-in via Options->Set to SAV). + /// - - Fixed: More edge cases for legality checks. + /// - Added: More Generation 7 trainer stat record labels. Thanks skywalker25 & Holla! + /// - Added: G7TID -> TID/SID generator for Generation 7 Trainer Editor. Thanks RoC! + /// - [rest of string was truncated]";. /// public static string changelog { get { @@ -12539,6 +12541,16 @@ public class Resources { } } + /// + /// Looks up a localized resource of type System.Byte[]. + /// + public static byte[] evos_rby { + get { + object obj = ResourceManager.GetObject("evos_rby", resourceCulture); + return ((byte[])(obj)); + } + } + /// /// Looks up a localized resource of type System.Byte[]. /// @@ -17761,6 +17773,16 @@ public class Resources { } } + /// + /// Looks up a localized resource of type System.Byte[]. + /// + public static byte[] lvlmove_rby { + get { + object obj = ResourceManager.GetObject("lvlmove_rby", resourceCulture); + return ((byte[])(obj)); + } + } + /// /// Looks up a localized resource of type System.Byte[]. /// @@ -17992,7 +18014,7 @@ public class Resources { } /// - /// Looks up a localized string similar to 20170130. + /// Looks up a localized string similar to 20170207. /// public static string ProgramVersion { get { @@ -19071,7 +19093,7 @@ public class Resources { ///// Main Window /// ///CTRL-O: Open - ///CTRL-S: Export PK6 + ///CTRL-S: Export PKM ///CTRL-E: Export SAV ///CTRL-B: Export BAK ///CTRL-Q: Quit @@ -28889,7 +28911,7 @@ public class Resources { } /// - /// Looks up a localized string similar to Ningún objeto + /// Looks up a localized string similar to Ninguno ///Master Ball ///Ultra Ball ///Super Ball @@ -28930,7 +28952,7 @@ public class Resources { ///Éter ///Éter Máximo ///Elixir - ///Elixir M [rest of string was truncated]";. + ///Elixir Máximo /// [rest of string was truncated]";. /// public static string text_items_es { get { diff --git a/PKHeX/Properties/Resources.resx b/PKHeX/Properties/Resources.resx index f8de0c5c6..d9e9428d3 100644 --- a/PKHeX/Properties/Resources.resx +++ b/PKHeX/Properties/Resources.resx @@ -7384,4 +7384,10 @@ ..\Resources\byte\fashion_m_sm_illegal;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + ..\Resources\byte\evos_rby.pkl;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\byte\lvlmove_rby.pkl;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/PKHeX/Resources/byte/evos_rby.pkl b/PKHeX/Resources/byte/evos_rby.pkl new file mode 100644 index 0000000000000000000000000000000000000000..07d3767e0ce6c535cd534f38352b7f888a766516 GIT binary patch literal 384 zcmXAl-zx-B6vxk*4Qq(8&2Br>G{5X_(?*k|O(G%^NlKC^N%Eq7k-U09$s7N#&$(Vc z_jAto+*9|82A*i%5Yb>lv^QzeM5d9c8Bu@MWDc1}S_?!iBn%B5(CLbJg~p}{2vYHU z&CCk3lGxWC%yrxBOEH3p5jjox#u{gd3$sI`ViEDkZ`jLop u@d*sa|3&^xQM|Yvudd~0!Z$m3=_gIKMwPVMx=lE>Lab6rjL|0gcXq$vl)>2IgxcMP8Z7D4g ztp*b-tkM`lY~u%LL6ac+L+7|D9s9-i`F!t@?#{l)5V{^o5;bN~T*x-;B^YS3#x1G~ zR-=5bc)@MVEx~v(ij!@wua>OkKm}o|7Q}t*gZc}k~TC4&)EmV!fk>Tr#k>*w*@XbPH>htfz@(jMCTq+q zt}a#825!Nrs8!r>S`al8KhiAU*Vcw8^>b?wHewg(j&Nf1hp3zs`oJRIk(>C$|9}HT zP5b0h1;(#Nza~$Zo-mITv-4TmwlZ%Gf_Ra_oQyoDeT(gWOaDloY-eVaU(>GEsx@leuTc@6(hIFz9z6D?!e_TWr% zvg<+INv0W7aJ3`5^;wkr#*y0sGM~DYwxyNqVXiY2b;UX?cOc~7S!#;+P#*}B=D9h! zt$j4Sp`f<;vEZ*`N|&_{rtDk{(D>lU6(3&;o5~ZtYj@nYLovIhPW3JLo%IWM8DYQP zc@E4S>32xqQHPHxk+_{|3ncDB*oigiboyncrQ98g@KR~vyFg5)!W<>N)4BnQl>RQ? zg;+j$klvLK{g-lz+M#m{sfXOm;;SoB=nd+wDcUV~knqaP_lbM=aM-7woTVclFkvy8k)?bj=qA}+xo_`Nd zG3)u)I$_fs$16|GOxYU>dTI|O<|ez$M&?l2)OY>A8AO}ZE1Rr%Tqv7ERwL% zF31oSfG|=wGdNo*&cbw#D5pezTfJ!ci;l6=CbiBPa!;2B;s$bA-_y&vxBmA1=$0SR zvaYY>yyEI0C