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:
Kurt 2024-03-30 17:44:21 -05:00
parent a2f36760e6
commit 5f4cf2af29

View file

@ -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;