diff --git a/SerialPrograms/Source/Pokemon/Pokemon_AdvRng.cpp b/SerialPrograms/Source/Pokemon/Pokemon_AdvRng.cpp index 4f888bd9d1..dbd7388e3d 100644 --- a/SerialPrograms/Source/Pokemon/Pokemon_AdvRng.cpp +++ b/SerialPrograms/Source/Pokemon/Pokemon_AdvRng.cpp @@ -90,6 +90,25 @@ AdvAbility ability_from_pid(uint32_t pid){ return AdvAbility (pid % 2); } +AdvAbility ability_slot_from_ability( + const std::string& observed_ability, + const std::vector& species_abilities +){ + if (observed_ability.empty() + || species_abilities.size() < 2 + || species_abilities[0] == species_abilities[1] + ){ + return AdvAbility::Any; + } + if (observed_ability == species_abilities[0]){ + return AdvAbility::Zero; + } + if (observed_ability == species_abilities[1]){ + return AdvAbility::One; + } + return AdvAbility::Any; +} + uint8_t unown_form_from_pid(uint32_t pid){ return (((pid & 0x3000000) >> 18) | ((pid & 0x30000) >> 12) | ((pid & 0x300) >> 6) | (pid & 0x3)) % 0x1c; // return ( diff --git a/SerialPrograms/Source/Pokemon/Pokemon_AdvRng.h b/SerialPrograms/Source/Pokemon/Pokemon_AdvRng.h index 616063c46d..ec156e6770 100644 --- a/SerialPrograms/Source/Pokemon/Pokemon_AdvRng.h +++ b/SerialPrograms/Source/Pokemon/Pokemon_AdvRng.h @@ -214,6 +214,13 @@ std::string gender_to_string(const AdvGender& gender); AdvGender gender_from_gender_value(uint8_t gender_value, int16_t threshold); +// Returns the ability slot of an observed ability, based on the species +// Returns AdvAbility::Any if the slot can't be determined +AdvAbility ability_slot_from_ability( + const std::string& observed_ability, + const std::vector& species_abilities +); + // returns search filters that correspond with observed stats AdvRngFilters observation_to_filters(const AdvObservedPokemon& observation, const BaseStats& basestats, AdvRngMethod method = AdvRngMethod::Method1); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.cpp index a05d693683..015a60a635 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.cpp @@ -270,7 +270,7 @@ EggRng::EggRng() }) { PA_ADD_OPTION(m_calibration_displays); - PA_ADD_OPTION(RNG_TARGET); + PA_ADD_STATIC(RNG_TARGET); PA_ADD_OPTION(RNG_FILTERS); PA_ADD_OPTION(HELD_CALIBRATION); PA_ADD_OPTION(PICKUP_CALIBRATION); @@ -356,7 +356,6 @@ bool EggRng::reset_and_check_seed( const bool& previously_hit_held_frame, Milliseconds& launch_delay, const std::set& SPECIES_LIST, - const RngStatsDatabase& STATS_DATA, bool pickup_frame ){ RngCalibrations& calibrations = hist.calibrations; @@ -443,13 +442,13 @@ bool EggRng::reset_and_check_seed( // Step 3: Catch a wild encounter and use it to determine the current seed AdvObservedPokemon pokemon; - RngStats species_stats; + const RngStats* species_stats = nullptr; AdvRngFilters filters; uint64_t wild_advances_estimate; WildCatchOutcome catch_outcome = catch_wild_for_seed_id( env, context, stats.errors, NOTIFICATION_ERROR_RECOVERABLE, LANGUAGE, timestamp, advances, pickup_frame ? 2 : 0, - balls_left, SPECIES_LIST, STATS_DATA, + balls_left, SPECIES_LIST, pokemon, species_stats, filters, wild_advances_estimate, [&](const AdvRngFilters& f){ RNG_FILTERS.set(f); } ); @@ -464,12 +463,12 @@ bool EggRng::reset_and_check_seed( // For the wild step we only need to confirm the correct seed was hit; advance timing is // irrelevant and wild_history is largely unused, so result_determined just checks same_seeds. std::vector search_hits = refine_calibration_with_rare_candy( - env, context, LANGUAGE, pokemon, filters, species_stats.base_stats, + env, context, LANGUAGE, pokemon, filters, species_stats->base_stats, wild_uncertain_history, wild_history, calibrations, MAX_HISTORY_LENGTH, candies_left, AdvRngMethod::Any, false, stats.errors, NOTIFICATION_ERROR_RECOVERABLE, [&](AdvRngFilters& f){ - return get_wild_search_results(env.console, wild_searcher, f, SEED_VALUES, wild_advances_estimate, WILD_ADVANCES_RADIUS, species_stats.gender_threshold); + return get_wild_search_results(env.console, wild_searcher, f, SEED_VALUES, wild_advances_estimate, WILD_ADVANCES_RADIUS, species_stats->gender_threshold); }, [&](const std::vector& h){ if (pickup_frame){ PICKUP_CALIBRATION.set_hits(h); }else{ HELD_CALIBRATION.set_hits(h); } @@ -727,21 +726,15 @@ void EggRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext& home_black_border_check(env.console, context); - // prepare database of base stats and gender thresholds - RngStatsDatabase STATS_DATA("PokemonFRLG/BaseStats.json"); - - RngStats EGG_STATS; - try{ - EGG_STATS = STATS_DATA.get_throw(EGG_SPECIES.slug()); - }catch (const InternalProgramError& err){ - env.log(err.message()); - env.log(EGG_SPECIES.slug()); + const RngStats* egg_stats = RngStatsDatabase::instance().get_nothrow(EGG_SPECIES.slug()); + if (egg_stats == nullptr){ OperationFailedExceptionWithScreenshot::fire( ErrorReportMode::SEND_ERROR_REPORT, - err.message(), + "Egg species not found in base stats database: " + EGG_SPECIES.slug(), env.console - ); + ); } + const RngStats& EGG_STATS = *egg_stats; // get the relevant encounter slots EncountersDatabase encounters_data(GAME_VERSION == GameVersion::firered ? "PokemonFRLG/EncounterSlotsFR.json" : "PokemonFRLG/EncounterSlotsLG.json"); @@ -801,8 +794,8 @@ void EggRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext& AdvIVs PARENT_B = { rowB.hp, rowB.atk, rowB.def, rowB.spa, rowB.spd, rowB.spe }; AdvPokemonResult target_result = egg_searcher.generate_pokemon(PARENT_A, PARENT_B); - RNG_TARGET.set_target(target_result, EGG_STATS.gender_threshold); - log_target_pokemon(env.console, target_result, true); + RNG_TARGET.set_target(target_result, EGG_SPECIES.slug(), 5); + log_target_pokemon(env.console, target_result, EGG_SPECIES.slug(), 5, true); Milliseconds launch_delay = INITIAL_LAUNCH_DELAY; @@ -935,7 +928,7 @@ void EggRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext& temp_balls_left, temp_candies_left, failed_searches, times_not_held, shiny_found, previously_hit_held_frame, launch_delay, - SPECIES_LIST, STATS_DATA, + SPECIES_LIST, false ); @@ -980,7 +973,7 @@ void EggRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext& temp_balls_left, temp_candies_left, failed_searches, times_not_held, shiny_found, previously_hit_held_frame, launch_delay, - SPECIES_LIST, STATS_DATA, + SPECIES_LIST, true ); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h index 5462ee2eac..e473a38461 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h @@ -101,7 +101,6 @@ class EggRng : public SingleSwitchProgramInstance, public ConfigOption::Listener const bool& previously_hit_held_frame, Milliseconds& launch_delay, const std::set& SPECIES_LIST, - const RngStatsDatabase& STATS_DATA, bool pickup_frame ); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.cpp index 3341d8cef2..32b30f5f66 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.cpp @@ -15,6 +15,7 @@ #include "Pokemon/Pokemon_Strings.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" #include "PokemonFRLG_RngNavigation.h" +#include "PokemonFRLG_RngStatsDatabase.h" #include "PokemonFRLG_HardReset.h" #include "PokemonFRLG_RngCalibration.h" #include "PokemonFRLG_RngLoopRoutines.h" @@ -194,7 +195,7 @@ GiftRng::GiftRng() }) { PA_ADD_OPTION(m_calibration_displays); - PA_ADD_OPTION(RNG_TARGET); + PA_ADD_STATIC(RNG_TARGET); PA_ADD_OPTION(RNG_FILTERS); PA_ADD_OPTION(RNG_CALIBRATION); PA_ADD_OPTION(m_game_info); @@ -253,86 +254,73 @@ void GiftRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext& env.log("Seed delay: " + std::to_string(SEED_DELAY) + "ms, button mode: " + seed_match.button_mode + ", column: " + seed_match.column_name); - BaseStats BASE_STATS; - int16_t GENDER_THRESHOLD = -1; + std::string SPECIES; uint8_t LEVEL = 0; switch (TARGET){ case PokemonFRLG_RngTarget::magikarp: - BASE_STATS = { 20, 10, 55, 15, 20, 80 }; - GENDER_THRESHOLD = 126; + SPECIES = "magikarp"; LEVEL = 5; break; case PokemonFRLG_RngTarget::hitmonchan: - BASE_STATS = { 50, 105, 79, 35, 110, 76 }; - GENDER_THRESHOLD = -1; + SPECIES = "hitmonchan"; LEVEL = 25; break; case PokemonFRLG_RngTarget::hitmonlee: - BASE_STATS = { 50, 120, 53, 35, 110, 87 }; - GENDER_THRESHOLD = -1; + SPECIES = "hitmonlee"; LEVEL = 25; break; case PokemonFRLG_RngTarget::eevee: - BASE_STATS = { 55, 55, 50, 45, 65, 55 }; - GENDER_THRESHOLD = 30; + SPECIES = "eevee"; LEVEL = 25; break; case PokemonFRLG_RngTarget::lapras: - BASE_STATS = { 130, 85, 80, 85, 95, 60 }; - GENDER_THRESHOLD = 126; + SPECIES = "lapras"; LEVEL = 25; break; case PokemonFRLG_RngTarget::omanyte: - BASE_STATS = { 35, 40, 100, 90, 55, 35 }; - GENDER_THRESHOLD = 30; + SPECIES = "omanyte"; LEVEL = 5; break; case PokemonFRLG_RngTarget::kabuto: - BASE_STATS = { 30, 80, 90, 55, 45, 55 }; - GENDER_THRESHOLD = 30; + SPECIES = "kabuto"; LEVEL = 5; break; case PokemonFRLG_RngTarget::aerodactyl: - BASE_STATS = { 80, 105, 65, 60, 75, 130 }; - GENDER_THRESHOLD = 30; + SPECIES = "aerodactyl"; LEVEL = 5; break; case PokemonFRLG_RngTarget::gamecornerabra: - BASE_STATS = { 25, 20, 15, 105, 55, 90 }; - GENDER_THRESHOLD = 63; + SPECIES = "abra"; break; case PokemonFRLG_RngTarget::gamecornerclefairy: - BASE_STATS = { 70, 45, 48, 60, 65, 35 }; - GENDER_THRESHOLD = 190; + SPECIES = "clefairy"; break; case PokemonFRLG_RngTarget::gamecornerdratinifr: case PokemonFRLG_RngTarget::gamecornerdratinilg: - BASE_STATS = { 41, 64, 45, 50, 50, 50 }; - GENDER_THRESHOLD = 126; + SPECIES = "dratini"; break; case PokemonFRLG_RngTarget::gamecornerscyther: - BASE_STATS = { 70, 110, 80, 55, 80, 105 }; - GENDER_THRESHOLD = 126; + SPECIES = "scyther"; LEVEL = 25; break; case PokemonFRLG_RngTarget::gamecornerpinsir: - BASE_STATS = { 65, 125, 100, 55, 70, 85 }; - GENDER_THRESHOLD = 126; + SPECIES = "pinsir"; LEVEL = 18; break; case PokemonFRLG_RngTarget::gamecornerporygon: - BASE_STATS = { 65, 60, 70, 85, 75, 40 }; - GENDER_THRESHOLD = -1; + SPECIES = "porygon"; break; case PokemonFRLG_RngTarget::togepi: case PokemonFRLG_RngTarget::togepifast: - BASE_STATS = { 35, 20, 65, 40, 65, 20 }; - GENDER_THRESHOLD = 30; + SPECIES = "togepi"; LEVEL = 5; break; default: break; } + const RngStats& STATS = RngStatsDatabase::instance().get_throw(SPECIES); + const int16_t GENDER_THRESHOLD = STATS.gender_threshold; + const BaseStats& BASE_STATS = STATS.base_stats; static const int64_t FIXED_SEED_OFFSET = -845; // milliseconds, approximate @@ -355,8 +343,8 @@ void GiftRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext& AdvRngSearcher searcher(TARGET_SEED, ADVANCES, AdvRngMethod::Method1); AdvPokemonResult target_result = searcher.generate_pokemon(); - RNG_TARGET.set_target(target_result, GENDER_THRESHOLD); - log_target_pokemon(env.console, target_result); + RNG_TARGET.set_target(target_result, SPECIES, LEVEL); + log_target_pokemon(env.console, target_result, SPECIES, LEVEL); RngCalibrations calibrations = { RNG_CALIBRATION.seed_calibration / FRLG_FRAME_DURATION, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngCalibration.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngCalibration.cpp index b367685af3..9e7555b74f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngCalibration.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngCalibration.cpp @@ -10,6 +10,7 @@ #include #include #include "PokemonFRLG_BlindNavigation.h" +#include "PokemonFRLG_RngStatsDatabase.h" #include "PokemonFRLG_RngCalibration.h" namespace PokemonAutomation{ @@ -95,9 +96,22 @@ void apply_seed_bump(RngCalibrations& calibrations, const RngUncertainHistory& u calibrations.seed_offset += seed_bump; } -void log_target_pokemon(ConsoleHandle& console, const AdvPokemonResult& result, bool normal_method_note){ +void log_target_pokemon( + ConsoleHandle& console, + const AdvPokemonResult& result, + const std::string& species, + uint8_t level, + bool normal_method_note +){ + const RngStats* stats = RngStatsDatabase::instance().get_nothrow(species); + console.log("Target Species: " + species); + if (level > 0){ + console.log("Target Level: " + std::to_string(level)); + } console.log("Target PID: " + to_hex_string(result.pid)); + console.log("Target Gender: " + gender_name(stats, result.gender)); console.log("Target Nature: " + nature_to_string(result.nature)); + console.log("Target Ability: " + ability_name(stats, result.ability)); console.log(normal_method_note ? "Target IVs (assuming Normal method):" : "Target IVs:"); console.log(" HP: " + std::to_string(result.ivs.hp)); console.log(" Atk: " + std::to_string(result.ivs.attack)); @@ -106,6 +120,11 @@ void log_target_pokemon(ConsoleHandle& console, const AdvPokemonResult& result, console.log(" SpD: " + std::to_string(result.ivs.spdef)); console.log(" Spe: " + std::to_string(result.ivs.speed)); } +void log_target_pokemon(ConsoleHandle& console, const AdvWildPokemonResult& result){ + console.log("Target Encounter Slot: " + std::to_string(result.slot)); + AdvPokemonResult pokemon = { result.pid, result.gender, result.nature, result.ability, result.ivs }; + log_target_pokemon(console, pokemon, result.species, result.level); +} void log_calibrations(ConsoleHandle& console, const RngCalibrations& calibrations, bool initial){ std::string prefix = initial ? "Initial " : ""; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngCalibration.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngCalibration.h index 4951b58ee7..2774e8a2ad 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngCalibration.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngCalibration.h @@ -74,8 +74,17 @@ void update_failed_searches(uint16_t& failed_searches, const std::vector #include #include "Pokemon/Resources/Pokemon_PokemonNames.h" +#include "PokemonFRLG_RngStatsDatabase.h" #include "PokemonFRLG_RngDisplays.h" namespace PokemonAutomation{ @@ -29,8 +30,17 @@ std::string species_display_name(const std::string& slug){ return get_pokemon_name(slug).display_name(); } +std::string ivs_to_string(const AdvIVs& ivs){ + return std::to_string(ivs.hp) + "/" + + std::to_string(ivs.attack) + "/" + + std::to_string(ivs.defense) + "/" + + std::to_string(ivs.spatk) + "/" + + std::to_string(ivs.spdef) + "/" + + std::to_string(ivs.speed); } +} // namespace + SidHelperDisplay::SidHelperDisplay() : GroupOption("TID/SID Results", LockMode::READ_ONLY) , tid(false, "Trainer ID:", LockMode::READ_ONLY, "-", "") @@ -52,40 +62,26 @@ void SidHelperDisplay::set(uint16_t trainerId, const std::vector 0){ + out += "Lv" + std::to_string(level) + " "; + } + out += gender_name(stats, pokemon.gender) + " "; out += nature_to_string(pokemon.nature) + " "; - out += std::to_string(pokemon.ivs.hp) + "/" + - std::to_string(pokemon.ivs.attack) + "/" + - std::to_string(pokemon.ivs.defense) + "/" + - std::to_string(pokemon.ivs.spatk) + "/" + - std::to_string(pokemon.ivs.spdef) + "/" + - std::to_string(pokemon.ivs.speed) + " "; + out += ability_name(stats, pokemon.ability) + " "; + out += ivs_to_string(pokemon.ivs); return out; -} +} -void RngTargetDisplay::set_target(const AdvPokemonResult& pokemon, const int16_t& gender_threshold){ - set(result_to_string(pokemon, gender_threshold)); +void RngTargetDisplay::set_target(const AdvPokemonResult& pokemon, const std::string& species, uint8_t level){ + set(result_to_string(pokemon, species, level)); } -void RngTargetDisplay::set_target(const AdvWildPokemonResult& pokemon, const int16_t& gender_threshold){ - set(result_to_string(pokemon, gender_threshold)); +void RngTargetDisplay::set_target(const AdvWildPokemonResult& pokemon){ + AdvPokemonResult result = { pokemon.pid, pokemon.gender, pokemon.nature, pokemon.ability, pokemon.ivs }; + set_target(result, pokemon.species, pokemon.level); } @@ -94,6 +90,7 @@ RngFilterDisplay::RngFilterDisplay() , species(false, "Species:", LockMode::READ_ONLY, "-", "") , gender(false, "Gender:", LockMode::READ_ONLY, "-", "") , nature(false, "Nature:", LockMode::READ_ONLY, "-", "") + , ability(false, "Ability:", LockMode::READ_ONLY, "-", "") , level(false, "Level:", LockMode::READ_ONLY, "-", "") , hp(false, "HP IV:", LockMode::READ_ONLY, "-", "") , atk(false, "Attack IV:", LockMode::READ_ONLY, "-", "") @@ -105,6 +102,7 @@ RngFilterDisplay::RngFilterDisplay() PA_ADD_STATIC(species); PA_ADD_STATIC(gender); PA_ADD_STATIC(nature); + PA_ADD_STATIC(ability); PA_ADD_STATIC(level); PA_ADD_STATIC(hp); PA_ADD_STATIC(atk); @@ -127,6 +125,7 @@ void RngFilterDisplay::set(const AdvRngFilters& filter){ species.set(species_display_name(filter.species)); gender.set(gender_to_string(filter.gender)); nature.set(nature_to_string(filter.nature)); + ability.set(ability_name(RngStatsDatabase::instance().get_nothrow(filter.species), filter.ability)); level.set(std::to_string(filter.level)); hp.set(get_range_string(filter.ivs.hp)); atk.set(get_range_string(filter.ivs.attack)); @@ -140,6 +139,7 @@ void RngFilterDisplay::reset(){ species.set("-"); gender.set("-"); nature.set("-"); + ability.set("-"); level.set("-"); hp.set("-"); atk.set("-"); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngDisplays.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngDisplays.h index 2f8182f7a5..858b13e392 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngDisplays.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngDisplays.h @@ -49,12 +49,11 @@ class RngTargetDisplay : public StringOption{ ) {} - void set_target(const AdvPokemonResult& pokemon, const int16_t& gender_threshold); - void set_target(const AdvWildPokemonResult& pokemon, const int16_t& gender_threshold); + void set_target(const AdvPokemonResult& pokemon, const std::string& species, uint8_t level); + void set_target(const AdvWildPokemonResult& pokemon); private: - std::string result_to_string(const AdvPokemonResult& pokemon, const int16_t& gender_threshold); - std::string result_to_string(const AdvWildPokemonResult& pokemon, const int16_t& gender_threshold); + std::string result_to_string(const AdvPokemonResult& pokemon, const std::string& species, uint8_t level); }; class RngFilterDisplay : public GroupOption{ @@ -71,6 +70,7 @@ class RngFilterDisplay : public GroupOption{ StringOption species; StringOption gender; StringOption nature; + StringOption ability; StringOption level; StringOption hp; StringOption atk; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngLoopRoutines.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngLoopRoutines.cpp index e1e30bf6d4..d35869b2a1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngLoopRoutines.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngLoopRoutines.cpp @@ -98,9 +98,8 @@ WildCatchOutcome catch_wild_for_seed_id( int sweet_scent_from_last, uint64_t& balls_left, const std::set& species_list, - const RngStatsDatabase& stats_data, AdvObservedPokemon& pokemon, - RngStats& species_stats, + const RngStats*& species_stats, AdvRngFilters& filters, uint64_t& wild_advances_estimate, const std::function& publish_filters @@ -144,15 +143,13 @@ WildCatchOutcome catch_wild_for_seed_id( go_to_summary(env.console, context); pokemon = read_summary(env.console, context, language, species_list); - try{ - species_stats = stats_data.get_throw(pokemon.species); - }catch (const InternalProgramError& err){ - env.log(err.message()); - env.log("Failed to load base stats."); + species_stats = RngStatsDatabase::instance().get_nothrow(pokemon.species); + if (species_stats == nullptr){ + env.log("Failed to load base stats for species: \"" + pokemon.species + "\""); return WildCatchOutcome::failed; } - filters = observation_to_filters(pokemon, species_stats.base_stats, AdvRngMethod::Any); + filters = observation_to_filters(pokemon, species_stats->base_stats, AdvRngMethod::Any); publish_filters(filters); return WildCatchOutcome::caught; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngLoopRoutines.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngLoopRoutines.h index 18c0ef90a1..5813c7a196 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngLoopRoutines.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngLoopRoutines.h @@ -99,9 +99,8 @@ WildCatchOutcome catch_wild_for_seed_id( int sweet_scent_from_last, uint64_t& balls_left, const std::set& species_list, - const RngStatsDatabase& stats_data, AdvObservedPokemon& pokemon, - RngStats& species_stats, + const RngStats*& species_stats, AdvRngFilters& filters, uint64_t& wild_advances_estimate, const std::function& publish_filters diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngNavigation.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngNavigation.cpp index b2842126f8..ff0efdac06 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngNavigation.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngNavigation.cpp @@ -24,6 +24,7 @@ #include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" #include "PokemonFRLG_BlindNavigation.h" #include "PokemonFRLG_RngCalibration.h" +#include "PokemonFRLG_RngStatsDatabase.h" #include "PokemonFRLG_RngNavigation.h" namespace PokemonAutomation{ @@ -100,10 +101,31 @@ AdvObservedPokemon read_summary( ); } - console.log("Reading Page 2 (Stats)..."); + console.log("Reading Page 2 (Stats, Ability)..."); VideoSnapshot screen2 = console.video().snapshot(); reader.read_page2(console.logger(), language, screen2, stats); + // Match the ability read against the species' abilities to get its slot. + std::vector species_abilities; + if (!stats.name.empty()){ + const RngStats* species_stats = RngStatsDatabase::instance().get_nothrow(stats.name); + if (species_stats != nullptr){ + species_abilities = species_stats->abilities; + } + } + AdvAbility ability = ability_slot_from_ability(stats.ability, species_abilities); + switch (ability){ + case AdvAbility::Zero: + console.log("Ability slot: 0 (" + stats.ability + ")"); + break; + case AdvAbility::One: + console.log("Ability slot: 1 (" + stats.ability + ")"); + break; + default: + console.log("Ability slot: unknown"); + break; + } + StatReads statreads = { static_cast(stats.hp.value_or(0)), static_cast(stats.attack.value_or(0)), @@ -151,7 +173,7 @@ AdvObservedPokemon read_summary( stats.name, gender, string_to_nature(stats.nature), - AdvAbility::Any, + ability, { uint8_t(stats.level.value_or(5)) }, { statreads }, { {0,0,0,0,0,0} }, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngStatsDatabase.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngStatsDatabase.cpp index bb35deccdc..ead0e9dd39 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngStatsDatabase.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngStatsDatabase.cpp @@ -36,7 +36,18 @@ RngStatsDatabase::RngStatsDatabase(const char* json_path){ int16_t gender_threshold = int16_t(obj.get_integer_throw("genderThreshold", path)); - RngStats rng_stats = { base_stats, gender_threshold }; + std::vector abilities; + const JsonArray* abilities_arr = obj.get_array("abilities"); + if (abilities_arr != nullptr){ + for (const auto& ability : *abilities_arr){ + abilities.emplace_back(ability.to_string_throw(path)); + } + if (abilities.size() > 2){ + throw FileException(nullptr, PA_CURRENT_FUNCTION, "Too many abilities for " + slug + ".", path); + } + } + + RngStats rng_stats = { base_stats, gender_threshold, std::move(abilities) }; m_database.emplace( slug, @@ -45,6 +56,11 @@ RngStatsDatabase::RngStatsDatabase(const char* json_path){ } } +const RngStatsDatabase& RngStatsDatabase::instance(){ + static const RngStatsDatabase database("PokemonFRLG/BaseStats.json"); + return database; +} + const RngStats& RngStatsDatabase::get_throw(const std::string& slug) const{ std::string sl = slug; if (slug.find("unown") != std::string::npos){ @@ -68,6 +84,32 @@ const RngStats* RngStatsDatabase::get_nothrow(const std::string& slug) const{ return &iter->second; } +std::string ability_name(const RngStats* stats, AdvAbility ability){ + size_t slot; + switch (ability){ + case AdvAbility::Zero: + slot = 0; + break; + case AdvAbility::One: + slot = 1; + break; + default: + return "-"; + } + if (stats == nullptr || stats->abilities.empty()){ + return "-"; + } + // Species with only one ability use it regardless of the PID's ability bit. + return stats->abilities[slot < stats->abilities.size() ? slot : 0]; +} + +std::string gender_name(const RngStats* stats, uint8_t gender_value){ + if (stats == nullptr){ + return "-"; + } + return gender_to_string(gender_from_gender_value(gender_value, stats->gender_threshold)); +} + } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngStatsDatabase.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngStatsDatabase.h index c4b93139fe..84fe050e9e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngStatsDatabase.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngStatsDatabase.h @@ -19,12 +19,15 @@ using namespace Pokemon; struct RngStats{ BaseStats base_stats; int16_t gender_threshold; - // std::vector abilities; + std::vector abilities; }; class RngStatsDatabase{ public: RngStatsDatabase(const char* json_path); + + static const RngStatsDatabase& instance(); + const RngStats& get_throw(const std::string& slug) const; const RngStats* get_nothrow(const std::string& slug) const; @@ -43,6 +46,12 @@ class RngStatsDatabase{ std::map m_database; }; +// Returns the name of the ability in the given slot +std::string ability_name(const RngStats* stats, AdvAbility ability); + +// Returns the gender implied by a PID's gender value +std::string gender_name(const RngStats* stats, uint8_t gender_value); + } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.cpp index fe284e8a2c..29b2a1dad7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.cpp @@ -15,6 +15,7 @@ #include "Pokemon/Pokemon_Strings.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" #include "PokemonFRLG_RngNavigation.h" +#include "PokemonFRLG_RngStatsDatabase.h" #include "PokemonFRLG_HardReset.h" #include "PokemonFRLG_RngCalibration.h" #include "PokemonFRLG_RngLoopRoutines.h" @@ -188,7 +189,7 @@ RoamingLegendaryRng::RoamingLegendaryRng() }) { PA_ADD_OPTION(m_calibration_displays); - PA_ADD_OPTION(RNG_TARGET); + PA_ADD_STATIC(RNG_TARGET); PA_ADD_OPTION(RNG_FILTERS); PA_ADD_OPTION(RNG_CALIBRATION); PA_ADD_OPTION(m_game_info); @@ -248,24 +249,23 @@ void RoamingLegendaryRng::program(SingleSwitchProgramEnvironment& env, ProContro env.log("Seed delay: " + std::to_string(SEED_DELAY) + "ms, button mode: " + seed_match.button_mode + ", column: " + seed_match.column_name); - BaseStats BASE_STATS; - int16_t GENDER_THRESHOLD = -1; + std::string SPECIES; switch (TARGET){ case PokemonFRLG_RngTarget::raikou: - BASE_STATS = { 90, 85, 75, 115, 100, 115 }; - GENDER_THRESHOLD = -1; + SPECIES = "raikou"; break; case PokemonFRLG_RngTarget::entei: - BASE_STATS = { 115, 115, 85, 90, 75, 100 }; - GENDER_THRESHOLD = -1; + SPECIES = "entei"; break; case PokemonFRLG_RngTarget::suicune: - BASE_STATS = { 100, 75, 115, 90, 115, 85 }; - GENDER_THRESHOLD = -1; + SPECIES = "suicune"; break; default: break; } + const RngStats& STATS = RngStatsDatabase::instance().get_throw(SPECIES); + const int16_t GENDER_THRESHOLD = STATS.gender_threshold; + const BaseStats& BASE_STATS = STATS.base_stats; static const int64_t FIXED_SEED_OFFSET = -845; // milliseconds, approximate @@ -281,8 +281,8 @@ void RoamingLegendaryRng::program(SingleSwitchProgramEnvironment& env, ProContro AdvRngSearcher searcher(TARGET_SEED, ADVANCES, AdvRngMethod::Method1, true); AdvPokemonResult target_result = searcher.generate_pokemon(); - RNG_TARGET.set_target(target_result, GENDER_THRESHOLD); - log_target_pokemon(env.console, target_result); + RNG_TARGET.set_target(target_result, SPECIES, 50); + log_target_pokemon(env.console, target_result, SPECIES, 50); RngCalibrations calibrations = { RNG_CALIBRATION.seed_calibration / FRLG_FRAME_DURATION, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.cpp index 5b22bee42f..44b0b8542b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.cpp @@ -20,6 +20,7 @@ #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleLevelUpReader.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" #include "PokemonFRLG_RngNavigation.h" +#include "PokemonFRLG_RngStatsDatabase.h" #include "PokemonFRLG_HardReset.h" #include "PokemonFRLG_SeedsDatabase.h" #include "PokemonFRLG_StarterRng.h" @@ -181,7 +182,7 @@ StarterRng::StarterRng() }) { PA_ADD_OPTION(m_calibration_displays); - PA_ADD_OPTION(RNG_TARGET); + PA_ADD_STATIC(RNG_TARGET); PA_ADD_OPTION(RNG_FILTERS); PA_ADD_OPTION(RNG_CALIBRATION); PA_ADD_OPTION(m_game_info); @@ -580,20 +581,23 @@ void StarterRng::program(SingleSwitchProgramEnvironment& env, ProControllerConte env.log("Seed delay: " + std::to_string(SEED_DELAY) + "ms, button mode: " + seed_match.button_mode + ", column: " + seed_match.column_name); - BaseStats BASE_STATS; + std::string SPECIES; switch (STARTER){ case Starter::bulbasaur: - BASE_STATS = { 45, 49, 49, 65, 65, 45 }; + SPECIES = "bulbasaur"; break; case Starter::squirtle: - BASE_STATS = { 44, 48, 65, 50, 64, 43 }; + SPECIES = "squirtle"; break; case Starter::charmander: - BASE_STATS = { 39, 52, 43, 60, 50, 65 }; + SPECIES = "charmander"; break; default: break; } + const RngStats& STATS = RngStatsDatabase::instance().get_throw(SPECIES); + const int16_t GENDER_THRESHOLD = STATS.gender_threshold; + const BaseStats& BASE_STATS = STATS.base_stats; static const int64_t FIXED_SEED_OFFSET = -845; // milliseconds, approximate @@ -603,8 +607,6 @@ void StarterRng::program(SingleSwitchProgramEnvironment& env, ProControllerConte static const uint8_t MAX_HISTORY_LENGTH = 10; - static const int16_t GENDER_THRESHOLD = 30; - static const std::set SPECIES_LIST = { "bulbasaur", "squirtle", "charmander" }; env.log("RNG Target: " + std::to_string(STARTER.current_value())); @@ -613,8 +615,8 @@ void StarterRng::program(SingleSwitchProgramEnvironment& env, ProControllerConte AdvRngSearcher searcher(TARGET_SEED, ADVANCES, AdvRngMethod::Method1); AdvPokemonResult target_result = searcher.generate_pokemon(); - RNG_TARGET.set_target(target_result, GENDER_THRESHOLD); - log_target_pokemon(env.console, target_result); + RNG_TARGET.set_target(target_result, SPECIES, 5); + log_target_pokemon(env.console, target_result, SPECIES, 5); RngCalibrations calibrations = { RNG_CALIBRATION.seed_calibration / FRLG_FRAME_DURATION, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.cpp index 30bdaaea7a..91d3890642 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.cpp @@ -4,6 +4,7 @@ * */ +#include #include "Common/Cpp/Strings/StringTools.h" #include "CommonFramework/ProgramStats/StatsTracking.h" #include "CommonFramework/Notifications/ProgramNotifications.h" @@ -14,6 +15,7 @@ #include "Pokemon/Pokemon_Strings.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" #include "PokemonFRLG_RngNavigation.h" +#include "PokemonFRLG_RngStatsDatabase.h" #include "PokemonFRLG_HardReset.h" #include "PokemonFRLG_RngCalibration.h" #include "PokemonFRLG_RngLoopRoutines.h" @@ -194,7 +196,7 @@ StaticRng::StaticRng() }) { PA_ADD_OPTION(m_calibration_displays); - PA_ADD_OPTION(RNG_TARGET); + PA_ADD_STATIC(RNG_TARGET); PA_ADD_OPTION(RNG_FILTERS); PA_ADD_OPTION(RNG_CALIBRATION); PA_ADD_OPTION(m_game_info); @@ -254,68 +256,62 @@ void StaticRng::program(SingleSwitchProgramEnvironment& env, ProControllerContex env.log("Seed delay: " + std::to_string(SEED_DELAY) + "ms, button mode: " + seed_match.button_mode + ", column: " + seed_match.column_name); - BaseStats BASE_STATS; - int16_t GENDER_THRESHOLD = -1; + std::string SPECIES; + std::optional FORM_BASE_STATS; uint8_t LEVEL = 30; switch (TARGET){ case PokemonFRLG_RngTarget::electrode: - BASE_STATS = { 60, 50, 70, 80, 80, 140 }; - GENDER_THRESHOLD = -1; + SPECIES = "electrode"; LEVEL = 34; break; case PokemonFRLG_RngTarget::snorlax: - BASE_STATS = { 160, 110, 65, 65, 110, 30 }; - GENDER_THRESHOLD = 30; + SPECIES = "snorlax"; LEVEL = 30; break; case PokemonFRLG_RngTarget::articuno: - BASE_STATS = { 90, 85, 100, 95, 125, 85 }; - GENDER_THRESHOLD = -1; + SPECIES = "articuno"; LEVEL = 50; break; case PokemonFRLG_RngTarget::zapdos: - BASE_STATS = { 90, 90, 85, 125, 90, 100 }; - GENDER_THRESHOLD = -1; + SPECIES = "zapdos"; LEVEL = 50; break; case PokemonFRLG_RngTarget::moltres: - BASE_STATS = { 90, 100, 90, 125, 85, 90 }; - GENDER_THRESHOLD = -1; + SPECIES = "moltres"; LEVEL = 50; break; case PokemonFRLG_RngTarget::mewtwo: - BASE_STATS = { 106, 110, 90, 154, 90, 130 }; - GENDER_THRESHOLD = -1; + SPECIES = "mewtwo"; LEVEL = 70; break; case PokemonFRLG_RngTarget::hypno: - BASE_STATS = { 85, 73, 70, 73, 115, 67 }; - GENDER_THRESHOLD = 126; + SPECIES = "hypno"; LEVEL = 30; break; case PokemonFRLG_RngTarget::hooh: - BASE_STATS = { 106, 130, 90, 110, 154, 90 }; - GENDER_THRESHOLD = -1; + SPECIES = "ho-oh"; LEVEL = 70; break; case PokemonFRLG_RngTarget::lugia: - BASE_STATS = { 106, 90, 130, 90, 154, 110 }; - GENDER_THRESHOLD = -1; + SPECIES = "lugia"; LEVEL = 70; break; case PokemonFRLG_RngTarget::deoxys_attack: - BASE_STATS = { 50, 180, 20, 180, 20, 150 }; - GENDER_THRESHOLD = -1; + SPECIES = "deoxys"; + FORM_BASE_STATS = BaseStats{ 50, 180, 20, 180, 20, 150 }; LEVEL = 30; break; case PokemonFRLG_RngTarget::deoxys_defense: - BASE_STATS = { 50, 70, 160, 70, 160, 90 }; - GENDER_THRESHOLD = -1; + SPECIES = "deoxys"; + FORM_BASE_STATS = BaseStats{ 50, 70, 160, 70, 160, 90 }; LEVEL = 30; break; default: break; } + const RngStats& STATS = RngStatsDatabase::instance().get_throw(SPECIES); + const int16_t GENDER_THRESHOLD = STATS.gender_threshold; + const BaseStats BASE_STATS = FORM_BASE_STATS.value_or(STATS.base_stats); static const int64_t FIXED_SEED_OFFSET = -845; // milliseconds, approximate @@ -337,8 +333,8 @@ void StaticRng::program(SingleSwitchProgramEnvironment& env, ProControllerContex AdvRngSearcher searcher(TARGET_SEED, ADVANCES, AdvRngMethod::Method1); AdvPokemonResult target_result = searcher.generate_pokemon(); - RNG_TARGET.set_target(target_result, GENDER_THRESHOLD); - log_target_pokemon(env.console, target_result); + RNG_TARGET.set_target(target_result, SPECIES, LEVEL); + log_target_pokemon(env.console, target_result, SPECIES, LEVEL); RngCalibrations calibrations = { RNG_CALIBRATION.seed_calibration / FRLG_FRAME_DURATION, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.cpp index 9aeb97fb45..2a0b1231f2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.cpp @@ -224,7 +224,7 @@ WildRng::WildRng() }) { PA_ADD_OPTION(m_calibration_displays); - PA_ADD_OPTION(RNG_TARGET); + PA_ADD_STATIC(RNG_TARGET); PA_ADD_OPTION(RNG_FILTERS); PA_ADD_OPTION(RNG_CALIBRATION); PA_ADD_OPTION(m_game_info); @@ -285,9 +285,6 @@ void WildRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext& RNG_FILTERS.reset(); RNG_CALIBRATION.reset_hits(); - // prepare database of base stats and gender thresholds - RngStatsDatabase STATS_DATA("PokemonFRLG/BaseStats.json"); - // get the relevant encounter slots EncountersDatabase encounters_data(GAME_VERSION == GameVersion::firered ? "PokemonFRLG/EncounterSlotsFR.json" : "PokemonFRLG/EncounterSlotsLG.json"); @@ -392,19 +389,8 @@ void WildRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext& AdvRngWildSearcher searcher(TARGET_SEED, ADVANCES, ENCOUNTER_SLOTS, RNG_METHOD); AdvWildPokemonResult target_result = searcher.generate_pokemon(SUPER_ROD); - RNG_TARGET.set_target(target_result, STATS_DATA.get_nothrow(target_result.species)->gender_threshold); - env.log("Target Species: " + target_result.species); - env.log("Target Level: " + std::to_string(target_result.level)); - env.log("Target Encounter Slot: " + std::to_string(target_result.slot)); - env.log("Target PID: " + to_hex_string(target_result.pid)); - env.log("Target Nature: " + nature_to_string(target_result.nature)); - env.log("Target IVs:"); - env.log(" HP: " + std::to_string(target_result.ivs.hp)); - env.log(" Atk: " + std::to_string(target_result.ivs.attack)); - env.log(" Def: " + std::to_string(target_result.ivs.defense)); - env.log(" SpA: " + std::to_string(target_result.ivs.spatk)); - env.log(" SpD: " + std::to_string(target_result.ivs.spdef)); - env.log(" Spe: " + std::to_string(target_result.ivs.speed)); + RNG_TARGET.set_target(target_result); + log_target_pokemon(env.console, target_result); const RngCalibrations initial_calibrations = { RNG_CALIBRATION.seed_calibration / FRLG_FRAME_DURATION, @@ -573,16 +559,13 @@ void WildRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext& go_to_summary(env.console, context, 0, safari_zone ? StartMenuContext::SAFARI_ZONE : StartMenuContext::STANDARD); AdvObservedPokemon pokemon = read_summary(env.console, context, LANGUAGE, SPECIES_LIST); - RngStats species_stats; - try{ - species_stats = STATS_DATA.get_throw(pokemon.species); - }catch (const InternalProgramError& err){ - env.log(err.message()); - env.log("Failed to load base stats.", COLOR_RED); + const RngStats* species_stats = RngStatsDatabase::instance().get_nothrow(pokemon.species); + if (species_stats == nullptr){ + env.log("Failed to load base stats for species: \"" + pokemon.species + "\"", COLOR_RED); continue; } - BaseStats base_stats = species_stats.base_stats; - int16_t gender_threshold = species_stats.gender_threshold; + const BaseStats& base_stats = species_stats->base_stats; + const int16_t gender_threshold = species_stats->gender_threshold; AdvRngFilters filters = observation_to_filters(pokemon, base_stats, AdvRngMethod::Any); bool valid_stats = validate_level(filters, pokemon, ENCOUNTER_SLOTS, base_stats);