mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-10 06:34:19 +00:00
Better guard against bad gender requests
Can infinite loop gen3/4 generators by requesting from an invalid gender (eg Male Blissey) in Gen5+
This commit is contained in:
parent
a2f36760e6
commit
5f4cf2af29
1 changed files with 11 additions and 1 deletions
|
@ -101,7 +101,7 @@ public sealed record EncounterCriteria : IFixedNature, IFixedAbilityNumber, IShi
|
|||
/// <returns>Initialized criteria data to be passed to generators.</returns>
|
||||
public static EncounterCriteria GetCriteria(IBattleTemplate s, IPersonalInfo pi) => new()
|
||||
{
|
||||
Gender = s.Gender < 2 ? s.Gender : default,
|
||||
Gender = GetGenderPermissions(s.Gender, pi),
|
||||
IV_HP = s.IVs[0],
|
||||
IV_ATK = s.IVs[1],
|
||||
IV_DEF = s.IVs[2],
|
||||
|
@ -116,6 +116,16 @@ public sealed record EncounterCriteria : IFixedNature, IFixedAbilityNumber, IShi
|
|||
TeraType = (sbyte)s.TeraType,
|
||||
};
|
||||
|
||||
private static byte? GetGenderPermissions(byte? gender, IGenderDetail pi)
|
||||
{
|
||||
if (gender is not <= 1)
|
||||
return default;
|
||||
if (pi.IsDualGender)
|
||||
return gender;
|
||||
var g = pi.FixedGender();
|
||||
return g <= 1 ? g : default;
|
||||
}
|
||||
|
||||
private static AbilityPermission GetAbilityPermissions(int ability, IPersonalAbility pi)
|
||||
{
|
||||
var count = pi.AbilityCount;
|
||||
|
|
Loading…
Reference in a new issue