Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions SerialPrograms/Source/Pokemon/Pokemon_AdvRng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,20 +414,6 @@ bool check_for_match(AdvWildPokemonResult res, AdvRngFilters target, int16_t gen
&& ((target.ivs.speed.low <= res.ivs.speed) && (target.ivs.speed.high >= res.ivs.speed));
}

// bool check_for_match(AdvEggResult res, AdvRngFilters target, int16_t gender_threshold, AdvIVs parentA_ivs, AdvIVs parentB_ivs, uint16_t tid_xor_sid){
// AdvIVs final_ivs = apply_inherited_ivs(res.ivs, res.inherited_ivs, parentA_ivs, parentB_ivs);
// return (target.nature == AdvNature::Any || (res.nature == target.nature))
// && (target.ability == AdvAbility::Any || (res.ability == target.ability))
// && (target.gender == AdvGender::Any || (gender_from_gender_value(res.gender, gender_threshold) == target.gender))
// && (target.shiny == AdvShinyType::Any || (shiny_type_from_pid(res.pid, tid_xor_sid) == target.shiny))
// && ((target.ivs.hp.low <= final_ivs.hp) && (target.ivs.hp.high >= final_ivs.hp))
// && ((target.ivs.attack.low <= final_ivs.attack) && (target.ivs.attack.high >= final_ivs.attack))
// && ((target.ivs.defense.low <= final_ivs.defense) && (target.ivs.defense.high >= final_ivs.defense))
// && ((target.ivs.spatk.low <= final_ivs.spatk) && (target.ivs.spatk.high >= final_ivs.spatk))
// && ((target.ivs.spdef.low <= final_ivs.spdef) && (target.ivs.spdef.high >= final_ivs.spdef))
// && ((target.ivs.speed.low <= final_ivs.speed) && (target.ivs.speed.high >= final_ivs.speed));
// }

Pokemon::NatureAdjustments nature_to_adjustment(AdvNature nature){
NatureAdjustments ret;
ret.attack = NatureAdjustment::NEUTRAL;
Expand Down Expand Up @@ -664,11 +650,11 @@ AdvRngFilters observation_to_filters(const AdvObservedPokemon& observation, cons
std::string gender_to_string(const AdvGender& gender){
switch (gender){
case AdvGender::Male:
return "Male";
return "\u2642";
case AdvGender::Female:
return "Female";
return "\u2640";
default:
return "Any";
return "-";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ void PickupFarmer::program(SingleSwitchProgramEnvironment& env, ProControllerCon
default:
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"Option not yet implemented.",
"Travel option not recognized. Please report this as a bug.",
env.console
);
}
Expand All @@ -257,7 +257,7 @@ void PickupFarmer::program(SingleSwitchProgramEnvironment& env, ProControllerCon
default:
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"Option not yet implemented.",
"Game location not recognized. Please report this as a bug.",
env.console
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ void check_timings(
default:
OperationFailedException::fire(
ErrorReport::NO_ERROR_REPORT,
"Option not yet implemented.",
"RNG target not recognized. Please report this as a bug.",
console
);
}
Expand Down Expand Up @@ -779,6 +779,7 @@ void perform_blind_sequence(
modified_ingame_delay = timings.ingame_delay - 51430;
walk_to_safarizonewest(context);
use_sweet_scent(context, modified_ingame_delay, true);
return;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

case PokemonFRLG_RngTarget::safarizonesurf:
modified_ingame_delay = timings.ingame_delay - 30300;
walk_to_safarizonesurf(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ std::unique_ptr<StatsTracker> GiftRng_Descriptor::make_stats() const{
}

GiftRng::GiftRng()
: LANGUAGE(
: m_calibration_displays(
"<font size=4><b>Calibration Displays</b></font> — These will update automatically as the program runs"
)
, m_game_info(
"<font size=4><b>Game Information</b></font>"
)
, LANGUAGE(
"<b>Game Language:</b>",
{
Language::English,
Expand All @@ -73,8 +79,11 @@ GiftRng::GiftRng()
LockMode::LOCK_WHILE_RUNNING,
true
)
, m_target_settings(
"<font size=4><b>Target Settings</b></font> — Get these from an RNG search tool"
)
, TARGET(
"<b>Target:</b><br>",
"<b>Target:</b>",
{
{PokemonFRLG_RngTarget::magikarp, "magikarp", "Magikarp"},
{PokemonFRLG_RngTarget::hitmonchan, "hitmonchan", "Hitmonchan"},
Expand All @@ -96,18 +105,6 @@ GiftRng::GiftRng()
LockMode::LOCK_WHILE_RUNNING,
PokemonFRLG_RngTarget::magikarp
)
, MAX_RESETS(
"<b>Max Resets:</b><br>",
LockMode::UNLOCK_WHILE_RUNNING,
50, 0 // default, min
)
, MAX_RARE_CANDIES(
"<b>Max Rare Candies:</b><br>"
"The number of rare candies in your bag. Make sure these are at the top position of the bag.<br>"
"Rare candies used during calibration will be restored after resetting.",
LockMode::UNLOCK_WHILE_RUNNING,
0, 0, 999 // default, min, max
)
, SEED(
false,
"<b>Target Seed:</b>",
Expand All @@ -124,7 +121,7 @@ GiftRng::GiftRng()
true
)
, SEED_BUTTON(
"<b>Seed Button:</b><br>",
"<b>Seed Button:</b>",
{
{SeedButton::A, "A", "A"},
{SeedButton::Start, "Start", "Start"},
Expand Down Expand Up @@ -156,18 +153,28 @@ GiftRng::GiftRng()
LockMode::LOCK_WHILE_RUNNING,
10000, 520, 1000000000 // default, min, max
)
// , CONTINUE_SCREEN_FRAMES(
// "<b>Continue Screen Frames:</b><br>The number of RNG advances to pass on the continue screen.<br>This should be less than the total number of advances above.",
// LockMode::LOCK_WHILE_RUNNING,
// 1000, 192 // default, min
// )
, m_program_settings(
"<font size=4><b>Program Settings</b></font>"
)
, USE_TEACHY_TV(
"<b>Use Teachy TV:</b>"
"<br>Opens the Teachy TV to quickly advance the RNG at 313x speed.<br>"
"<i>Warning: can result in larger misses.</i>",
LockMode::LOCK_WHILE_RUNNING,
false // default
)
, MAX_RESETS(
"<b>Max Resets:</b>",
LockMode::UNLOCK_WHILE_RUNNING,
50, 0 // default, min
)
, MAX_RARE_CANDIES(
"<b>Max Rare Candies:</b><br>"
"The number of rare candies in your bag. Make sure these are at the top position of the bag.<br>"
"Rare candies used during calibration will be restored after resetting.",
LockMode::UNLOCK_WHILE_RUNNING,
0, 0, 999 // default, min, max
)
, PROFILE(
"<b>User Profile Position:</b><br>"
"The position, from left to right, of the Switch profile with the FRLG save you'd like to use.<br>"
Expand All @@ -193,20 +200,24 @@ GiftRng::GiftRng()
&NOTIFICATION_PROGRAM_FINISH,
})
{
PA_ADD_OPTION(m_calibration_displays);
PA_ADD_OPTION(RNG_TARGET);
PA_ADD_OPTION(RNG_FILTERS);
PA_ADD_OPTION(RNG_CALIBRATION);
PA_ADD_OPTION(m_game_info);
PA_ADD_OPTION(LANGUAGE);
PA_ADD_OPTION(m_target_settings);
PA_ADD_OPTION(TARGET);
PA_ADD_OPTION(MAX_RESETS);
PA_ADD_OPTION(MAX_RARE_CANDIES);
PA_ADD_OPTION(SEED);
PA_ADD_OPTION(SEED_LIST);
PA_ADD_OPTION(SEED_BUTTON);
PA_ADD_OPTION(EXTRA_BUTTON);
PA_ADD_OPTION(SEED_DELAY);
PA_ADD_OPTION(ADVANCES);
// PA_ADD_OPTION(CONTINUE_SCREEN_FRAMES);
PA_ADD_OPTION(m_program_settings);
PA_ADD_OPTION(USE_TEACHY_TV);
PA_ADD_OPTION(MAX_RESETS);
PA_ADD_OPTION(MAX_RARE_CANDIES);
PA_ADD_OPTION(PROFILE);
PA_ADD_OPTION(TAKE_VIDEO);
PA_ADD_OPTION(GO_HOME_WHEN_DONE);
Expand All @@ -229,21 +240,17 @@ void GiftRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext&
home_black_border_check(env.console, context);

RNG_FILTERS.reset();
RNG_CALIBRATION.reset();
RNG_CALIBRATION.reset_hits();

const uint16_t TARGET_SEED = parse_seed(env.console, SEED);
const std::vector<uint16_t> SEED_VALUES = parse_seed_list(env.console, SEED_LIST);
const int16_t SEED_POSITION = seed_position_in_list(TARGET_SEED, SEED_VALUES);

if (SEED_POSITION == -1){
OperationFailedException::fire(
ErrorReport::NO_ERROR_REPORT,
"GiftRng(): Target Seed is missing from the list of nearby seeds.",
env.console
);
throw UserSetupError(env.console, "The target Seed is missing from the list of nearby seeds.");
}

env.log("Target Seed Value (base10): " + std::to_string(TARGET_SEED));
env.log("Target Seed Value: " + to_hex_string(TARGET_SEED));

BaseStats BASE_STATS;
int16_t GENDER_THRESHOLD = -1;
Expand Down Expand Up @@ -324,16 +331,21 @@ void GiftRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext&

const uint8_t MAX_HISTORY_LENGTH = USE_TEACHY_TV ? 2 : 10;


RngCalibrations calibrations = {
RNG_CALIBRATION.seed_calibration / FRLG_FRAME_DURATION,
RNG_CALIBRATION.csf_calibration,
RNG_CALIBRATION.advances_calibration
static const std::set<std::string> SPECIES_LIST = {
"magikarp", "hitmonchan", "hitmonlee", "eevee", "lapras",
"omanyte", "kabuto", "aerodactyl",
"abra", "clefairy", "dratini", "scyther", "pinsir", "porygon",
"togepi"
};

env.log("RNG Target: " + std::to_string(TARGET.current_value()));
env.log("Target Seed: " + to_hex_string(TARGET_SEED));
env.log("Target Advances: " + std::to_string(ADVANCES));

AdvRngSearcher searcher(TARGET_SEED, ADVANCES, AdvRngMethod::Method1);
AdvPokemonResult target_result = searcher.generate_pokemon();
env.log("Target PID (base 10): " + std::to_string(target_result.pid));
RNG_TARGET.set_target(target_result, GENDER_THRESHOLD);
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));
Expand All @@ -343,6 +355,15 @@ void GiftRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext&
env.log(" SpD: " + std::to_string(target_result.ivs.spdef));
env.log(" Spe: " + std::to_string(target_result.ivs.speed));

RngCalibrations calibrations = {
RNG_CALIBRATION.seed_calibration / FRLG_FRAME_DURATION,
RNG_CALIBRATION.csf_calibration,
RNG_CALIBRATION.advances_calibration
};
env.log("Initial Seed calibration (frames): " + std::to_string(calibrations.seed_offset));
env.log("Initial CSF calibration (frames): " + std::to_string(calibrations.csf_offset));
env.log("Initial In-game calibration (frames x2): " + std::to_string(calibrations.ingame_offset));

RngAdvanceHistory advance_history;
RngCalibrationHistory calibration_history;

Expand Down Expand Up @@ -409,13 +430,15 @@ void GiftRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext&
stats.resets++;

RNG_FILTERS.reset();
RNG_CALIBRATION.reset();
RNG_CALIBRATION.set_calibrations(calibrations);
RNG_CALIBRATION.reset_hits();

bool shiny_found = check_for_shiny(env.console, context, TARGET);

if (shiny_found){
env.log("Shiny found!");
stats.shinies++;
RNG_CALIBRATION.hits.set("Shiny!");
send_program_notification(
env,
NOTIFICATION_SHINY,
Expand All @@ -431,17 +454,12 @@ void GiftRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext&
break;
}

AdvObservedPokemon pokemon = read_summary(env.console, context, LANGUAGE);
AdvObservedPokemon pokemon = read_summary(env.console, context, LANGUAGE, SPECIES_LIST);
AdvRngFilters filters = observation_to_filters(pokemon, BASE_STATS);
RNG_FILTERS.set(filters);

std::vector<AdvRngState> search_hits = get_search_results(env.console, searcher, filters, SEED_VALUES, ADVANCES, advances_radius, GENDER_THRESHOLD);
RNG_CALIBRATION.set(
calibrations.seed_offset * FRLG_FRAME_DURATION,
calibrations.csf_offset,
calibrations.ingame_offset,
search_hits
);
RNG_CALIBRATION.set_hits(search_hits);
bool finished = update_history(
env.console, advance_history, calibration_history, MAX_HISTORY_LENGTH,
calibrations, search_hits, 1
Expand All @@ -463,12 +481,7 @@ void GiftRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext&
RNG_FILTERS.set(filters);

search_hits = get_search_results(env.console, searcher, filters, SEED_VALUES, ADVANCES, advances_radius, GENDER_THRESHOLD);
RNG_CALIBRATION.set(
calibrations.seed_offset * FRLG_FRAME_DURATION,
calibrations.csf_offset,
calibrations.ingame_offset,
search_hits
);
RNG_CALIBRATION.set_hits(search_hits);

bool force_finish = failed || (i == (MAX_RARE_CANDIES - 1));
finished = update_history(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "Common/Cpp/Options/SimpleIntegerOption.h"
#include "Common/Cpp/Options/FloatingPointOption.h"
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
#include "Common/Cpp/Options/StaticTextOption.h"
#include "Common/Cpp/Options/TextEditOption.h"
#include "CommonFramework/Notifications/EventNotificationsTable.h"
#include "CommonTools/Options/LanguageOCROption.h"
Expand Down Expand Up @@ -45,26 +46,27 @@ class GiftRng : public SingleSwitchProgramInstance{

bool have_hit_target(SingleSwitchProgramEnvironment& env, const uint32_t& TARGET_SEED, const AdvRngState& hit);

OCR::LanguageOCROption LANGUAGE;

EnumDropdownOption<PokemonFRLG_RngTarget> TARGET;

SimpleIntegerOption<uint64_t> MAX_RESETS;
SimpleIntegerOption<uint64_t> MAX_RARE_CANDIES;

SectionDividerOption m_calibration_displays;
RngTargetDisplay RNG_TARGET;
RngFilterDisplay RNG_FILTERS;
RngCalibrationDisplay RNG_CALIBRATION;

SectionDividerOption m_game_info;
OCR::LanguageOCROption LANGUAGE;

SectionDividerOption m_target_settings;
EnumDropdownOption<PokemonFRLG_RngTarget> TARGET;
StringOption SEED;
TextEditOption SEED_LIST;
EnumDropdownOption<SeedButton> SEED_BUTTON;
EnumDropdownOption<BlackoutButton> EXTRA_BUTTON;
SimpleIntegerOption<uint64_t> SEED_DELAY;

SimpleIntegerOption<uint64_t>ADVANCES;

SectionDividerOption m_program_settings;
BooleanCheckBoxOption USE_TEACHY_TV;

SimpleIntegerOption<uint64_t> MAX_RESETS;
SimpleIntegerOption<uint64_t> MAX_RARE_CANDIES;
SimpleIntegerOption<uint8_t> PROFILE;

BooleanCheckBoxOption TAKE_VIDEO;
Expand Down
Loading
Loading