Fix 6->7 ~ memories

Yay for pokebank giving gen7 format files memories (including gen7
origin pkm)
Add in a geolocation validity check; PKHeX doesn't screw this up but may
catch other editors down the road.

Legality checks updated accordingly.
This commit is contained in:
Kurt 2017-01-27 05:59:08 -08:00
parent 16203b36b9
commit 1589fc733e
3 changed files with 84 additions and 24 deletions

View file

@ -1213,8 +1213,28 @@ namespace PKHeX.Core
pkm.Geo1_Country, pkm.Geo2_Country, pkm.Geo3_Country, pkm.Geo4_Country, pkm.Geo5_Country,
pkm.Geo1_Region, pkm.Geo2_Region, pkm.Geo3_Region, pkm.Geo4_Region, pkm.Geo5_Region,
};
if (geo.Any(d => d != 0) && !pkm.VC1)
return new CheckResult(Severity.Invalid, "Geolocation Memories should not be present.", CheckIdentifier.History);
// Check sequential order (no zero gaps)
bool geoEnd = false;
for (int i = 0; i < 5; i++)
{
if (geoEnd && geo[i] != 0)
return new CheckResult(Severity.Invalid, "Geolocation Memories invalid.", CheckIdentifier.History);
if (geo[i] != 0)
continue;
if (geo[i + 5] != 0)
return new CheckResult(Severity.Invalid, "Geolocation Region without Country.", CheckIdentifier.History);
geoEnd = true;
}
if (pkm.VC1 || pkm.GenNumber < 7)
{
var hasGeo = geo.Any(d => d != 0);
if (!hasGeo)
return new CheckResult(Severity.Invalid, "Geolocation Memories should be present.", CheckIdentifier.History);
}
if (pkm.GenNumber >= 7 && pkm.CNTs.Any(stat => stat > 0))
return new CheckResult(Severity.Invalid, "Untraded -- Contest stats on SM origin should be zero.", CheckIdentifier.History);
@ -1449,24 +1469,25 @@ namespace PKHeX.Core
if (pkm.GenNumber == 7)
{
bool hasMemory = pkm.VC1; // SM do not
string prefix = hasMemory ? "Should " : "Should not ";
bool check = pkm.VC1 || pkm.HT_Memory != 0;
if (!check)
return;
if (hasMemory ^ pkm.HT_Memory != 0)
AddLine(Severity.Invalid, prefix + "have a HT Memory.", CheckIdentifier.Memory);
if (hasMemory ^ pkm.HT_Intensity != 0)
AddLine(Severity.Invalid, prefix + "have a HT Memory Intensity value.", CheckIdentifier.Memory);
if (pkm.HT_Memory != 4)
AddLine(Severity.Invalid, "Should have a Link Trade HT Memory.", CheckIdentifier.Memory);
if (pkm.HT_TextVar != 0)
AddLine(Severity.Invalid, "Should not have a HT Memory TextVar value.", CheckIdentifier.Memory);
if (hasMemory ^ pkm.HT_Feeling != 0)
AddLine(Severity.Invalid, prefix + "have a HT Memory Feeling value.", CheckIdentifier.Memory);
AddLine(Severity.Invalid, "Should have a HT Memory TextVar value (somewhere).", CheckIdentifier.Memory);
if (pkm.HT_Intensity != 1)
AddLine(Severity.Invalid, "Should have a HT Memory Intensity value (1st).", CheckIdentifier.Memory);
if (pkm.HT_Feeling > 10)
AddLine(Severity.Invalid, "Should have a HT Memory Feeling value 0-9.", CheckIdentifier.Memory);
return;
}
switch (pkm.HT_Memory)
{
case 0:
if (pkm.Format != 6 || string.IsNullOrEmpty(pkm.HT_Name))
if (string.IsNullOrEmpty(pkm.HT_Name))
return;
AddLine(Severity.Invalid, "HT Memory is missing.", CheckIdentifier.Memory); return;
case 1: // {0} met {1} at... {2}. {1} threw a Poké Ball at it, and they started to travel together. {4} that {3}.

View file

@ -626,6 +626,8 @@ namespace PKHeX.Core
pk7.Data[0x72] &= 0xFC; /* Clear lower two bits of Super training flags. */
pk7.Data[0xDE] = 0; /* Gen IV encounter type. */
pk7.TradeMemory(Bank: true); // oh no, memories on gen7 pkm
// Fix Checksum
pk7.RefreshChecksum();

View file

@ -487,16 +487,10 @@ namespace PKHeX.Core
{
Enjoyment = Fullness = 0;
if (!VC1)
Geo1_Region = Geo1_Country = 0;
Geo2_Region = Geo2_Country =
Geo3_Region = Geo3_Country =
Geo4_Region = Geo4_Country =
Geo5_Region = Geo5_Country = 0;
if (IsEgg) // No memories if is egg.
{
Geo1_Country = Geo2_Country = Geo3_Country = Geo4_Country = Geo5_Country =
Geo1_Region = Geo2_Region = Geo3_Region = Geo4_Region = Geo5_Region =
HT_Friendship = HT_Affection = HT_TextVar = HT_Memory = HT_Intensity = HT_Feeling =
/* OT_Friendship */ OT_Affection = OT_TextVar = OT_Memory = OT_Intensity = OT_Feeling = 0;
@ -509,10 +503,53 @@ namespace PKHeX.Core
HT_Friendship = HT_Affection = HT_TextVar = HT_Memory = HT_Intensity = HT_Feeling = 0;
if (GenNumber < 6)
OT_Affection = OT_TextVar = OT_Memory = OT_Intensity = OT_Feeling = 0;
if (GenNumber >= 7 && !VC1)
Geo1_Region = Geo1_Country > 0 ? Geo1_Region : 0;
Geo2_Region = Geo2_Country > 0 ? Geo2_Region : 0;
Geo3_Region = Geo3_Country > 0 ? Geo3_Region : 0;
Geo4_Region = Geo4_Country > 0 ? Geo4_Region : 0;
Geo5_Region = Geo5_Country > 0 ? Geo5_Region : 0;
while (true)
{
HT_TextVar = HT_Memory = HT_Intensity = HT_Feeling =
OT_TextVar = OT_Memory = OT_Intensity = OT_Feeling = 0;
if (Geo5_Country != 0 && Geo4_Country == 0)
{
Geo4_Country = Geo5_Country;
Geo4_Region = Geo5_Region;
Geo5_Country = Geo5_Region = 0;
}
if (Geo4_Country != 0 && Geo3_Country == 0)
{
Geo3_Country = Geo4_Country;
Geo3_Region = Geo4_Region;
Geo4_Country = Geo4_Region = 0;
continue;
}
if (Geo3_Country != 0 && Geo2_Country == 0)
{
Geo2_Country = Geo3_Country;
Geo2_Region = Geo3_Region;
Geo3_Country = Geo3_Region = 0;
continue;
}
if (Geo2_Country != 0 && Geo1_Country == 0)
{
Geo1_Country = Geo2_Country;
Geo1_Region = Geo2_Region;
Geo2_Country = Geo2_Region = 0;
continue;
}
break;
}
if (GenNumber < 7) // must be transferred via bank, and must have memories
{
TradeMemory(Bank: true);
if (Geo1_Country == 0)
{
Geo1_Country = Country;
Geo1_Region = Region;
}
}
}
@ -566,7 +603,7 @@ namespace PKHeX.Core
}
private void TradeGeoLocation(int GeoCountry, int GeoRegion)
{
return; // No geolocations are set, ever!
return; // No geolocations are set, ever! -- except for bank. Don't set them anyway.
//// Allow the method to abort if the values are invalid
//if (GeoCountry < 0 || GeoRegion < 0)
// return;