mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 04:23:12 +00:00
Minor tweaks
no functional change
This commit is contained in:
parent
7c697a519e
commit
de94876822
5 changed files with 66 additions and 14 deletions
|
@ -11,12 +11,6 @@ namespace PKHeX.Core
|
|||
private readonly GameVersion Version;
|
||||
private readonly string LocationName;
|
||||
|
||||
private EncounterSummary(IEncounterTemplate z, string type)
|
||||
{
|
||||
Version = z.Version;
|
||||
LocationName = GetLocationName(z) + $"({type}) ";
|
||||
}
|
||||
|
||||
private EncounterSummary(IEncounterTemplate z)
|
||||
{
|
||||
Version = z.Version;
|
||||
|
|
|
@ -40,9 +40,8 @@ namespace PKHeX.Core
|
|||
int format = pkm.Format;
|
||||
if (format >= 6)
|
||||
{
|
||||
// Check AbilityNumber is a single set bit
|
||||
var num = pkm.AbilityNumber;
|
||||
if (!(num != 0 && (num & (num - 1)) == 0)) // not [!zero, and power of 2]
|
||||
if (!IsValidAbilityBits(num))
|
||||
return INVALID;
|
||||
|
||||
// Check AbilityNumber points to ability
|
||||
|
@ -90,6 +89,8 @@ namespace PKHeX.Core
|
|||
return VerifyAbility(data, abilities, abilIndex);
|
||||
}
|
||||
|
||||
public static bool IsValidAbilityBits(int num) => num is 1 or 2 or 4;
|
||||
|
||||
private static bool GetWasDual(IReadOnlyList<EvoCriteria> evos, PersonalTable pt, ISpeciesForm pk)
|
||||
{
|
||||
foreach (var evo in evos)
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace PKHeX.Core
|
|||
|
||||
// Capture / Inherit cases -- can be one of many balls
|
||||
var pkm = data.pkm;
|
||||
if (pkm.Species == (int)Species.Shedinja && data.EncounterMatch.Species != (int)Species.Shedinja) // Shedinja. For gen3, copy the ball from Nincada
|
||||
if (pkm.Species == (int)Species.Shedinja && enc.Species != (int)Species.Shedinja) // Shedinja. For gen3, copy the ball from Nincada
|
||||
{
|
||||
// Only Gen3 origin Shedinja can copy the wild ball.
|
||||
// Evolution chains will indicate if it could have existed as Shedinja in Gen3.
|
||||
|
|
|
@ -148,6 +148,56 @@ namespace PKHeX.Core
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the expected <see cref="PKM.PID"/> for a Gen3-5 transfer to Gen6.
|
||||
/// </summary>
|
||||
/// <param name="pk">Entity to check</param>
|
||||
/// <param name="pid">PID result</param>
|
||||
/// <returns>True if the <see cref="pid"/> is appropriate to use.</returns>
|
||||
public static bool GetTransferPID(PKM pk, out uint pid)
|
||||
{
|
||||
var ver = pk.Version;
|
||||
if (ver is 0 or >= (int) GameVersion.X) // Gen6+ ignored
|
||||
{
|
||||
pid = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
var _ = GetExpectedTransferPID(pk, out pid);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the expected <see cref="PKM.EncryptionConstant"/> for a Gen3-5 transfer to Gen6.
|
||||
/// </summary>
|
||||
/// <param name="pk">Entity to check</param>
|
||||
/// <param name="ec">Encryption constant result</param>
|
||||
/// <returns>True if the <see cref="ec"/> is appropriate to use.</returns>
|
||||
public static bool GetTransferEC(PKM pk, out uint ec)
|
||||
{
|
||||
var ver = pk.Version;
|
||||
if (ver is 0 or >= (int)GameVersion.X) // Gen6+ ignored
|
||||
{
|
||||
ec = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
uint pid = pk.PID;
|
||||
uint LID = pid & 0xFFFF;
|
||||
uint HID = pid >> 16;
|
||||
uint XOR = (uint)(pk.TID ^ LID ^ pk.SID ^ HID);
|
||||
|
||||
// Ensure we don't have a shiny.
|
||||
if (XOR >> 3 == 1) // Illegal, fix. (not 16<XOR>=8)
|
||||
ec = pid ^ 0x80000000; // Keep as shiny, so we have to mod the EC
|
||||
else if ((XOR ^ 0x8000) >> 3 == 1 && pid != pk.EncryptionConstant)
|
||||
ec = pid ^ 0x80000000; // Already anti-shiny, ensure the anti-shiny relationship is present.
|
||||
else
|
||||
ec = pid; // Ensure the copy correlation is present.
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void VerifyTransferEC(LegalityAnalysis data)
|
||||
{
|
||||
var pkm = data.pkm;
|
||||
|
@ -156,14 +206,21 @@ namespace PKHeX.Core
|
|||
// If the PID is nonshiny->shiny, the top bit is flipped.
|
||||
|
||||
// Check to see if the PID and EC are properly configured.
|
||||
var ec = pkm.EncryptionConstant; // should be original PID
|
||||
bool xorPID = ((pkm.TID ^ pkm.SID ^ (int)(ec & 0xFFFF) ^ (int)(ec >> 16)) & ~0x7) == 8;
|
||||
bool valid = pkm.PID == (xorPID ? (ec ^ 0x80000000) : ec);
|
||||
var bitFlipProc = GetExpectedTransferPID(pkm, out var expect);
|
||||
bool valid = pkm.PID == expect;
|
||||
if (valid)
|
||||
return;
|
||||
|
||||
var msg = xorPID ? LTransferPIDECBitFlip : LTransferPIDECEquals;
|
||||
var msg = bitFlipProc ? LTransferPIDECBitFlip : LTransferPIDECEquals;
|
||||
data.AddLine(GetInvalid(msg, CheckIdentifier.EC));
|
||||
}
|
||||
|
||||
private static bool GetExpectedTransferPID(PKM pkm, out uint expect)
|
||||
{
|
||||
var ec = pkm.EncryptionConstant; // should be original PID
|
||||
bool xorPID = ((pkm.TID ^ pkm.SID ^ (int) (ec & 0xFFFF) ^ (int) (ec >> 16)) & ~0x7) == 8;
|
||||
expect = (xorPID ? (ec ^ 0x80000000) : ec);
|
||||
return xorPID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -323,7 +323,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
|
||||
public int DebutGeneration => Legal.GetDebutGeneration(Species);
|
||||
public bool PKRS_Infected { get => PKRS_Strain > 0; set => PKRS_Strain = value ? Math.Max(PKRS_Strain, 1) : 0; }
|
||||
public bool PKRS_Infected { get => PKRS_Strain != 0; set => PKRS_Strain = value ? Math.Max(PKRS_Strain, 1) : 0; }
|
||||
|
||||
public bool PKRS_Cured
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue