From 27f15d2f20ddd64b1e9abcbbedca1384fa2d79a3 Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 31 Jul 2020 11:17:31 -0700 Subject: [PATCH] Split Country/Region/ConsoleRegion to interface --- PKHeX.Core/Editing/PKM/EditPKMUtil.cs | 8 ++++---- PKHeX.Core/Editing/PKM/PKMSummary.cs | 3 --- PKHeX.Core/Legality/Analysis.cs | 4 +++- .../Verifiers/MysteryGiftVerifier.cs | 9 ++++++--- .../Legality/Restrictions/VivillonTables.cs | 2 +- .../Legality/Structures/ITrainerInfo.cs | 8 ++++---- .../Verifiers/ConsoleRegionVerifier.cs | 19 ++++++------------- PKHeX.Core/Legality/Verifiers/FormVerifier.cs | 8 ++++++-- PKHeX.Core/MysteryGifts/WB7.cs | 3 --- PKHeX.Core/PKM/PK6.cs | 6 +++--- PKHeX.Core/PKM/PK7.cs | 6 +++--- PKHeX.Core/PKM/PKM.cs | 3 --- PKHeX.Core/PKM/Shared/IGeoTrack.cs | 4 ++++ PKHeX.Core/PKM/Util/PKMConverter.cs | 2 +- .../Controls/PKM Editor/LoadSave.cs | 12 +++++++----- .../Controls/PKM Editor/PKMEditor.cs | 2 +- 16 files changed, 49 insertions(+), 50 deletions(-) diff --git a/PKHeX.Core/Editing/PKM/EditPKMUtil.cs b/PKHeX.Core/Editing/PKM/EditPKMUtil.cs index 51965ac4f..cc5d771ff 100644 --- a/PKHeX.Core/Editing/PKM/EditPKMUtil.cs +++ b/PKHeX.Core/Editing/PKM/EditPKMUtil.cs @@ -55,11 +55,11 @@ namespace PKHeX.Core pk.OT_Gender = tr.Gender; pk.TID = tr.TID; pk.SID = tr.SID; - if (tr.ConsoleRegion >= 0) + if (tr.ConsoleRegion >= 0 && pk is IGeoTrack gt) { - pk.ConsoleRegion = tr.ConsoleRegion; - pk.Country = tr.Country; - pk.Region = tr.SubRegion; + gt.ConsoleRegion = tr.ConsoleRegion; + gt.Country = tr.Country; + gt.Region = tr.SubRegion; } // Copy OT trash bytes for sensitive games (Gen1/2) diff --git a/PKHeX.Core/Editing/PKM/PKMSummary.cs b/PKHeX.Core/Editing/PKM/PKMSummary.cs index 46e90d15a..73b9ff067 100644 --- a/PKHeX.Core/Editing/PKM/PKMSummary.cs +++ b/PKHeX.Core/Editing/PKM/PKMSummary.cs @@ -39,9 +39,6 @@ namespace PKHeX.Core public string Version => Get(Strings.gamelist, pkm.Version); public string OTLang => Get(GameDataSource.Languages, pkm.Language); public string Legal { get { var la = new LegalityAnalysis(pkm); return la.Parsed ? la.Valid.ToString() : "-"; } } - public string CountryID => pkm.Format > 5 ? pkm.Country.ToString() : "N/A"; - public string RegionID => pkm.Format > 5 ? pkm.Region.ToString() : "N/A"; - public string DSRegionID => pkm.Format > 5 ? pkm.ConsoleRegion.ToString() : "N/A"; #region Extraneous public string EC => pkm.EncryptionConstant.ToString("X8"); diff --git a/PKHeX.Core/Legality/Analysis.cs b/PKHeX.Core/Legality/Analysis.cs index a1b6ad206..6632e062c 100644 --- a/PKHeX.Core/Legality/Analysis.cs +++ b/PKHeX.Core/Legality/Analysis.cs @@ -323,7 +323,9 @@ namespace PKHeX.Core if (pkm.Format < 6) return; - ConsoleRegion.Verify(this); + if (pkm.Format < 8) + ConsoleRegion.Verify(this); // Gen 7->8 transfer deletes geolocation tracking data + History.Verify(this); Memory.Verify(this); if (pkm is ISuperTrain) diff --git a/PKHeX.Core/Legality/Encounters/Verifiers/MysteryGiftVerifier.cs b/PKHeX.Core/Legality/Encounters/Verifiers/MysteryGiftVerifier.cs index fb49f73fc..ce0b51633 100644 --- a/PKHeX.Core/Legality/Encounters/Verifiers/MysteryGiftVerifier.cs +++ b/PKHeX.Core/Legality/Encounters/Verifiers/MysteryGiftVerifier.cs @@ -46,9 +46,12 @@ namespace PKHeX.Core if (lang != 0 && !lang.HasFlagFast((MysteryGiftRestriction) (1 << pk.Language))) return new CheckResult(Severity.Invalid, string.Format(LOTLanguage, lang.GetSuggestedLanguage(), pk.Language), CheckIdentifier.GameOrigin); - var region = val & MysteryGiftRestriction.RegionRestrict; - if (region != 0 && !region.HasFlagFast((MysteryGiftRestriction)((int)MysteryGiftRestriction.RegionBase << pk.ConsoleRegion))) - return new CheckResult(Severity.Invalid, LGeoHardwareRange, CheckIdentifier.GameOrigin); + if (pk is IGeoTrack tr) + { + var region = val & MysteryGiftRestriction.RegionRestrict; + if (region != 0 && !region.HasFlagFast((MysteryGiftRestriction)((int)MysteryGiftRestriction.RegionBase << tr.ConsoleRegion))) + return new CheckResult(Severity.Invalid, LGeoHardwareRange, CheckIdentifier.GameOrigin); + } return new CheckResult(CheckIdentifier.GameOrigin); } diff --git a/PKHeX.Core/Legality/Restrictions/VivillonTables.cs b/PKHeX.Core/Legality/Restrictions/VivillonTables.cs index 19c7128a3..a96a604f7 100644 --- a/PKHeX.Core/Legality/Restrictions/VivillonTables.cs +++ b/PKHeX.Core/Legality/Restrictions/VivillonTables.cs @@ -193,7 +193,7 @@ namespace PKHeX.Core } /// - /// Compares the and to determine if the country is available within that region. + /// Compares the and to determine if the country is available within that region. /// /// Console region. /// Country of nationality diff --git a/PKHeX.Core/Legality/Structures/ITrainerInfo.cs b/PKHeX.Core/Legality/Structures/ITrainerInfo.cs index 56ed8dab2..4b6f44775 100644 --- a/PKHeX.Core/Legality/Structures/ITrainerInfo.cs +++ b/PKHeX.Core/Legality/Structures/ITrainerInfo.cs @@ -28,11 +28,11 @@ namespace PKHeX.Core pk.Language = info.Language; pk.Version = info.Game; - if (pk.Format >= 8 || pk is PB7) + if (!(pk is IGeoTrack tr)) return; - pk.Country = info.Country; - pk.Region = info.SubRegion; - pk.ConsoleRegion = info.ConsoleRegion; + tr.Country = info.Country; + tr.Region = info.SubRegion; + tr.ConsoleRegion = info.ConsoleRegion; } public static void ApplyHandlingTrainerInfo(this ITrainerInfo sav, PKM pk, bool force = false) diff --git a/PKHeX.Core/Legality/Verifiers/ConsoleRegionVerifier.cs b/PKHeX.Core/Legality/Verifiers/ConsoleRegionVerifier.cs index 6b425225e..175a9d5ee 100644 --- a/PKHeX.Core/Legality/Verifiers/ConsoleRegionVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/ConsoleRegionVerifier.cs @@ -3,7 +3,7 @@ namespace PKHeX.Core { /// - /// Verifies the and of origin values. + /// Verifies the and of origin values. /// public sealed class ConsoleRegionVerifier : Verifier { @@ -11,33 +11,26 @@ namespace PKHeX.Core public override void Verify(LegalityAnalysis data) { - var result = VerifyConsoleRegion(data.pkm, data.Info.Generation); + if (!(data.pkm is IGeoTrack tr)) + return; + var result = VerifyConsoleRegion(tr); data.AddLine(result); } - private CheckResult VerifyConsoleRegion(PKM pkm, int gen) + private CheckResult VerifyConsoleRegion(IGeoTrack pkm) { int consoleRegion = pkm.ConsoleRegion; if (consoleRegion >= 7) return GetInvalid(LGeoHardwareRange); - if (gen >= 8 || pkm.Format >= 8 || pkm.GG) - return VerifyNoDataPresent(pkm, consoleRegion); return Verify3DSDataPresent(pkm, consoleRegion); } - private CheckResult Verify3DSDataPresent(PKM pkm, int consoleRegion) + private CheckResult Verify3DSDataPresent(IGeoTrack pkm, int consoleRegion) { if (!Legal.IsConsoleRegionCountryValid(consoleRegion, pkm.Country)) return GetInvalid(LGeoHardwareInvalid); return GetValid(LGeoHardwareValid); } - - private CheckResult VerifyNoDataPresent(PKM pkm, int consoleRegion) - { - if (consoleRegion != 0 || pkm.Country != 0 || pkm.Region != 0) - return GetInvalid(LGeoHardwareInvalid); - return GetValid(LGeoHardwareValid); - } } } diff --git a/PKHeX.Core/Legality/Verifiers/FormVerifier.cs b/PKHeX.Core/Legality/Verifiers/FormVerifier.cs index d3bd507f6..cd38d763e 100644 --- a/PKHeX.Core/Legality/Verifiers/FormVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/FormVerifier.cs @@ -117,7 +117,9 @@ namespace PKHeX.Core case (int)Species.Spewpa: if (form > 17) // Fancy & Pokéball return GetInvalid(LFormVivillonEventPre); - if (!Legal.CheckVivillonPattern(form, (byte)pkm.Country, (byte)pkm.Region)) + if (!(pkm is IGeoTrack tr)) + break; + if (!Legal.CheckVivillonPattern(form, (byte)tr.Country, (byte)tr.Region)) data.AddLine(Get(LFormVivillonInvalid, Severity.Fishy)); break; case (int)Species.Vivillon: @@ -127,7 +129,9 @@ namespace PKHeX.Core return GetInvalid(LFormVivillonInvalid); return GetValid(LFormVivillon); } - if (!Legal.CheckVivillonPattern(form, (byte)pkm.Country, (byte)pkm.Region)) + if (!(pkm is IGeoTrack trv)) + break; + if (!Legal.CheckVivillonPattern(form, (byte)trv.Country, (byte)trv.Region)) data.AddLine(Get(LFormVivillonInvalid, Severity.Fishy)); break; diff --git a/PKHeX.Core/MysteryGifts/WB7.cs b/PKHeX.Core/MysteryGifts/WB7.cs index 605ed2384..b8cbe0776 100644 --- a/PKHeX.Core/MysteryGifts/WB7.cs +++ b/PKHeX.Core/MysteryGifts/WB7.cs @@ -317,9 +317,6 @@ namespace PKHeX.Core Version = OriginGame != 0 ? OriginGame : sav.Game, Language = sav.Language, Ball = Ball, - Country = sav.Country, - Region = sav.SubRegion, - ConsoleRegion = sav.ConsoleRegion, Move1 = Move1, Move2 = Move2, Move3 = Move3, diff --git a/PKHeX.Core/PKM/PK6.cs b/PKHeX.Core/PKM/PK6.cs index 3a0e7f338..ed4af902b 100644 --- a/PKHeX.Core/PKM/PK6.cs +++ b/PKHeX.Core/PKM/PK6.cs @@ -345,9 +345,9 @@ namespace PKHeX.Core public override int OT_Gender { get => Data[0xDD] >> 7; set => Data[0xDD] = (byte)((Data[0xDD] & ~0x80) | (value << 7)); } public override int EncounterType { get => Data[0xDE]; set => Data[0xDE] = (byte)value; } public override int Version { get => Data[0xDF]; set => Data[0xDF] = (byte)value; } - public override int Country { get => Data[0xE0]; set => Data[0xE0] = (byte)value; } - public override int Region { get => Data[0xE1]; set => Data[0xE1] = (byte)value; } - public override int ConsoleRegion { get => Data[0xE2]; set => Data[0xE2] = (byte)value; } + public int Country { get => Data[0xE0]; set => Data[0xE0] = (byte)value; } + public int Region { get => Data[0xE1]; set => Data[0xE1] = (byte)value; } + public int ConsoleRegion { get => Data[0xE2]; set => Data[0xE2] = (byte)value; } public override int Language { get => Data[0xE3]; set => Data[0xE3] = (byte)value; } #endregion #region Battle Stats diff --git a/PKHeX.Core/PKM/PK7.cs b/PKHeX.Core/PKM/PK7.cs index aa6036956..61dde69ee 100644 --- a/PKHeX.Core/PKM/PK7.cs +++ b/PKHeX.Core/PKM/PK7.cs @@ -377,9 +377,9 @@ namespace PKHeX.Core public bool HT_SPD { get => ((HyperTrainFlags >> 4) & 1) == 1; set => HyperTrainFlags = (HyperTrainFlags & ~(1 << 4)) | ((value ? 1 : 0) << 4); } public bool HT_SPE { get => ((HyperTrainFlags >> 5) & 1) == 1; set => HyperTrainFlags = (HyperTrainFlags & ~(1 << 5)) | ((value ? 1 : 0) << 5); } public override int Version { get => Data[0xDF]; set => Data[0xDF] = (byte)value; } - public override int Country { get => Data[0xE0]; set => Data[0xE0] = (byte)value; } - public override int Region { get => Data[0xE1]; set => Data[0xE1] = (byte)value; } - public override int ConsoleRegion { get => Data[0xE2]; set => Data[0xE2] = (byte)value; } + public int Country { get => Data[0xE0]; set => Data[0xE0] = (byte)value; } + public int Region { get => Data[0xE1]; set => Data[0xE1] = (byte)value; } + public int ConsoleRegion { get => Data[0xE2]; set => Data[0xE2] = (byte)value; } public override int Language { get => Data[0xE3]; set => Data[0xE3] = (byte)value; } #endregion #region Battle Stats diff --git a/PKHeX.Core/PKM/PKM.cs b/PKHeX.Core/PKM/PKM.cs index f62d49551..47314a91f 100644 --- a/PKHeX.Core/PKM/PKM.cs +++ b/PKHeX.Core/PKM/PKM.cs @@ -159,9 +159,6 @@ namespace PKHeX.Core public virtual byte Enjoyment { get; set; } public virtual byte Fullness { get; set; } public virtual int AbilityNumber { get; set; } - public virtual int Country { get; set; } - public virtual int Region { get; set; } - public virtual int ConsoleRegion { get; set; } /// /// The date the Pokémon was met. diff --git a/PKHeX.Core/PKM/Shared/IGeoTrack.cs b/PKHeX.Core/PKM/Shared/IGeoTrack.cs index a4afa140f..df8ea2851 100644 --- a/PKHeX.Core/PKM/Shared/IGeoTrack.cs +++ b/PKHeX.Core/PKM/Shared/IGeoTrack.cs @@ -5,6 +5,10 @@ /// public interface IGeoTrack { + int ConsoleRegion { get; set; } + int Country { get; set; } + int Region { get; set; } + int Geo1_Region { get; set; } int Geo2_Region { get; set; } int Geo3_Region { get; set; } diff --git a/PKHeX.Core/PKM/Util/PKMConverter.cs b/PKHeX.Core/PKM/Util/PKMConverter.cs index 9d1b09af3..dae8cf715 100644 --- a/PKHeX.Core/PKM/Util/PKMConverter.cs +++ b/PKHeX.Core/PKM/Util/PKMConverter.cs @@ -28,7 +28,7 @@ namespace PKHeX.Core public static int Game => Trainer.Game; public static bool AllowIncompatibleConversion { private get; set; } - public static void SetConsoleRegionData3DS(PKM pkm) + public static void SetConsoleRegionData3DS(IGeoTrack pkm) { var trainer = Trainer.ConsoleRegion != 0 ? Trainer : Trainer67; pkm.ConsoleRegion = trainer.ConsoleRegion; diff --git a/PKHeX.WinForms/Controls/PKM Editor/LoadSave.cs b/PKHeX.WinForms/Controls/PKM Editor/LoadSave.cs index cf74c2ac9..0e08990ac 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/LoadSave.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/LoadSave.cs @@ -283,7 +283,9 @@ namespace PKHeX.WinForms.Controls LoadRelearnMoves(pk); LoadHandlingTrainer(pk); - LoadGeolocation(pk); + + if (pk is IGeoTrack tr) + LoadGeolocation(tr); } private void SaveMisc6(PKM pk) @@ -294,18 +296,18 @@ namespace PKHeX.WinForms.Controls SaveRelearnMoves(pk); SaveHandlingTrainer(pk); - if (pk.Format <= 7 && !(pk is PB7)) - SaveGeolocation(pk); + if (pk is IGeoTrack tr) + SaveGeolocation(tr); } - private void LoadGeolocation(PKM pk) + private void LoadGeolocation(IGeoTrack pk) { CB_Country.SelectedValue = pk.Country; CB_SubRegion.SelectedValue = pk.Region; CB_3DSReg.SelectedValue = pk.ConsoleRegion; } - private void SaveGeolocation(PKM pk) + private void SaveGeolocation(IGeoTrack pk) { pk.Country = WinFormsUtil.GetIndex(CB_Country); pk.Region = WinFormsUtil.GetIndex(CB_SubRegion); diff --git a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs index 4b8388671..2b63b90bb 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs @@ -1743,7 +1743,7 @@ namespace PKHeX.WinForms.Controls BTN_History.Visible = gen >= 6 && !pb7; BTN_Ribbons.Visible = gen >= 3 && !pb7; BTN_Medals.Visible = gen >= 6 && gen <= 7 && !pb7; - FLP_Country.Visible = FLP_SubRegion.Visible = FLP_3DSRegion.Visible = gen >= 6 && gen <= 7 && !pb7; + FLP_Country.Visible = FLP_SubRegion.Visible = FLP_3DSRegion.Visible = t is IGeoTrack; FLP_OriginalNature.Visible = gen >= 8; B_Records.Visible = gen >= 8; CB_HTLanguage.Visible = gen >= 8;