using System; namespace PKHeX.Core; /// /// table (array). /// /// /// Serves as the main object that is accessed for stat data in a particular generation/game format. /// public static class PersonalTable { /// /// Personal Table used in . /// public static readonly PersonalTable8LA LA = new(GetTable("la")); /// /// Personal Table used in . /// public static readonly PersonalTable8BDSP BDSP = new(GetTable("bdsp")); /// /// Personal Table used in . /// public static readonly PersonalTable8SWSH SWSH = new(GetTable("swsh")); /// /// Personal Table used in . /// public static readonly PersonalTable7GG GG = new(GetTable("gg")); /// /// Personal Table used in . /// public static readonly PersonalTable7 USUM = new(GetTable("uu"), Legal.MaxSpeciesID_7_USUM); /// /// Personal Table used in . /// public static readonly PersonalTable7 SM = new(GetTable("sm"), Legal.MaxSpeciesID_7); /// /// Personal Table used in . /// public static readonly PersonalTable6AO AO = new(GetTable("ao")); /// /// Personal Table used in . /// public static readonly PersonalTable6XY XY = new(GetTable("xy")); /// /// Personal Table used in . /// public static readonly PersonalTable5B2W2 B2W2 = new(GetTable("b2w2")); /// /// Personal Table used in . /// public static readonly PersonalTable5BW BW = new(GetTable("bw")); /// /// Personal Table used in . /// public static readonly PersonalTable4 HGSS = new(GetTable("hgss")); /// /// Personal Table used in . /// public static readonly PersonalTable4 Pt = new(GetTable("pt")); /// /// Personal Table used in . /// public static readonly PersonalTable4 DP = new(GetTable("dp")); /// /// Personal Table used in . /// public static readonly PersonalTable3 LG = new(GetTable("lg")); /// /// Personal Table used in . /// public static readonly PersonalTable3 FR = new(GetTable("fr")); /// /// Personal Table used in . /// public static readonly PersonalTable3 E = new(GetTable("e")); /// /// Personal Table used in . /// public static readonly PersonalTable3 RS = new(GetTable("rs")); /// /// Personal Table used in . /// public static readonly PersonalTable2 C = new(GetTable("c")); /// /// Personal Table used in . /// public static readonly PersonalTable2 GS = new(GetTable("gs")); /// /// Personal Table used in . /// public static readonly PersonalTable1 RB = new(GetTable("rb")); /// /// Personal Table used in . /// public static readonly PersonalTable1 Y = new(GetTable("y")); private static ReadOnlySpan GetTable(string game) => Util.GetBinaryResource($"personal_{game}"); static PersonalTable() // Finish Setup { FixPersonalTableG1(); PopulateGen3Tutors(); PopulateGen4Tutors(); CopyDexitGenders(); } private static void FixPersonalTableG1() { var gs = GS.Table; RB.LoadValuesFrom(gs); Y.LoadValuesFrom(gs); } private static void PopulateGen3Tutors() { // Update Gen3 data with Emerald's data, FR/LG is a subset of Emerald's compatibility. var machine = BinLinkerAccessor.Get(Util.GetBinaryResource("hmtm_g3.pkl"), "g3"); var tutors = BinLinkerAccessor.Get(Util.GetBinaryResource("tutors_g3.pkl"), "g3"); var table = E.Table; for (ushort i = Legal.MaxSpeciesID_3; i >= 1; i--) { var entry = table[i]; entry.AddTMHM(machine[i]); entry.AddTypeTutors(tutors[i]); // Copy to other tables RS.Table[i].TMHM = FR.Table[i].TMHM = LG.Table[i].TMHM = entry.TMHM; RS.Table[i].TypeTutors = FR.Table[i].TypeTutors = LG.Table[i].TypeTutors = entry.TypeTutors; } } private static void PopulateGen4Tutors() { var tutors = BinLinkerAccessor.Get(Util.GetBinaryResource("tutors_g4.pkl"), "g4"); var table = HGSS.Table; var count = tutors.Length; for (ushort i = 1; i < count; i++) table[i].AddTypeTutors(tutors[i]); } /// /// Sword/Shield do not contain personal data (stubbed) for all species that are not allowed to visit the game. /// Copy all the genders from 's table for all past species, since we need it for gender lookups for all generations. /// private static void CopyDexitGenders() { var swsh = SWSH.Table; var usum = USUM.Table; for (ushort i = 1; i <= Legal.MaxSpeciesID_7_USUM; i++) { var ss = swsh[i]; if (ss.HP == 0) ss.Gender = usum[i].Gender; } var la = LA; for (ushort i = 1; i <= Legal.MaxSpeciesID_8_R2; i++) { var e = la.Table[i]; var fc = e.FormCount; for (int f = 0; f < fc; f++) { var l = la.GetFormEntry(i, f); if (l.HP != 0) continue; var s = SWSH.GetFormEntry(i, f); l.Ability1 = s.Ability1; l.Ability2 = s.Ability2; l.AbilityH = s.AbilityH; l.Gender = s.Gender; l.EXPGrowth = s.EXPGrowth; } } } }