Skip to content

Commit f0c539c

Browse files
authored
Even more RngHelper fixes (#1182)
* more fixes * add profile option and fix starter summary check
1 parent 652b17a commit f0c539c

2 files changed

Lines changed: 57 additions & 12 deletions

File tree

SerialPrograms/Source/PokemonFRLG/Programs/ShinyHunting/PokemonFRLG_RngHelper.cpp

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "PokemonFRLG/Inference/PokemonFRLG_SelectionArrowDetector.h"
2626
#include "PokemonFRLG/Inference/PokemonFRLG_ShinySymbolDetector.h"
2727
#include "PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h"
28+
#include "PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryDetector.h"
2829
#include "PokemonFRLG/Programs/PokemonFRLG_StartMenuNavigation.h"
2930
#include "PokemonFRLG/PokemonFRLG_Navigation.h"
3031
#include "PokemonFRLG_RngHelper.h"
@@ -64,8 +65,15 @@ std::unique_ptr<StatsTracker> RngHelper_Descriptor::make_stats() const{
6465
}
6566

6667
RngHelper::RngHelper()
67-
: TARGET(
68-
"<b>Target:</b><br>",
68+
: PROFILE(
69+
"<b>User Profile Position:</b><br>"
70+
"The position, from left to right, of the Switch profile with the FRLG save you'd like to use.<br>"
71+
"If this is set to 0, Switch 1 defaults to the last-used profile, while Switch 2 defaults to the first profile (position 1)",
72+
LockMode::LOCK_WHILE_RUNNING,
73+
0, 0, 8 // default, min, max
74+
)
75+
, TARGET(
76+
"<b>Target:</b>",
6977
{
7078
{Target::starters, "starters", "Bulbasaur / Squirtle / Charmander"},
7179
{Target::magikarp, "magikarp", "Magikarp"},
@@ -98,7 +106,8 @@ RngHelper::RngHelper()
98106
Target::starters
99107
)
100108
, NUM_RESETS(
101-
"<b>Max Resets:</b><br>",
109+
"<b>Max Resets:</b><br>"
110+
"This program requires manual calibration, so this should usually be set to 1 while calibrating.",
102111
LockMode::UNLOCK_WHILE_RUNNING,
103112
1, 0 // default, min
104113
)
@@ -186,6 +195,7 @@ RngHelper::RngHelper()
186195
&NOTIFICATION_PROGRAM_FINISH,
187196
})
188197
{
198+
PA_ADD_OPTION(PROFILE);
189199
PA_ADD_OPTION(TARGET);
190200
PA_ADD_OPTION(NUM_RESETS);
191201
PA_ADD_OPTION(SEED_BUTTON);
@@ -385,9 +395,26 @@ void use_registered_fishing_rod(ProControllerContext& context, const uint64_t& I
385395

386396
void go_to_starter_summary(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
387397
// Navigate to summary (1st party slot)
388-
open_party_menu_from_overworld(env.console, context);
389-
pbf_press_button(context, BUTTON_A, 200ms, 1000ms);
390-
pbf_press_button(context, BUTTON_A, 200ms, 2300ms);
398+
open_start_menu(env.console, context); // Don't have a Pokedex yet, so arrow will already by over POKeMON
399+
400+
SummaryWatcher summary_open(COLOR_RED);
401+
context.wait_for_all_requests();
402+
int ret = run_until<ProControllerContext>(
403+
env.console, context,
404+
[](ProControllerContext& context) {
405+
pbf_press_button(context, BUTTON_A, 200ms, 1000ms);
406+
for (int i=0; i<3; i++){
407+
pbf_press_button(context, BUTTON_A, 200ms, 2800ms);
408+
}
409+
},
410+
{ summary_open }
411+
);
412+
413+
if (ret < 0){
414+
env.log("go_to_starter_summary(): failed to open the summary.");
415+
}else{
416+
env.log("Summary opened.");
417+
}
391418
}
392419

393420
bool shiny_check_starter_summary(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
@@ -399,13 +426,30 @@ bool shiny_check_starter_summary(SingleSwitchProgramEnvironment& env, ProControl
399426
}
400427

401428
void go_to_last_summary(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
402-
// navigate to summary (last party slot)
429+
// navigate to the last occupied party slot
403430
open_party_menu_from_overworld(env.console, context);
404431
pbf_move_left_joystick(context, {0, +1}, 200ms, 300ms);
405432
pbf_move_left_joystick(context, {0, +1}, 200ms, 300ms);
433+
406434
// open summary
407-
pbf_press_button(context, BUTTON_A, 200ms, 1000ms);
408-
pbf_press_button(context, BUTTON_A, 200ms, 2300ms);
435+
SummaryWatcher summary_open(COLOR_RED);
436+
context.wait_for_all_requests();
437+
int ret = run_until<ProControllerContext>(
438+
env.console, context,
439+
[](ProControllerContext& context) {
440+
pbf_press_button(context, BUTTON_A, 200ms, 1000ms);
441+
for (int i=0; i<3; i++){
442+
pbf_press_button(context, BUTTON_A, 200ms, 2800ms);
443+
}
444+
},
445+
{ summary_open }
446+
);
447+
448+
if (ret < 0){
449+
env.log("go_to_last_summary(): failed to open the summary.");
450+
} else {
451+
env.log("Summary opened.");
452+
}
409453
}
410454

411455
bool shiny_check_summary(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
@@ -953,7 +997,7 @@ void RngHelper::reset_and_perform_blind_sequence(
953997
go_home(env.console, context);
954998
close_game_from_home(env.console, context);
955999
// start the game and quickly go back home
956-
start_game_from_home(env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST, uint8_t(0), uint8_t(0)); // TODO: add option for user slot if needed
1000+
start_game_from_home(env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST, uint8_t(0), PROFILE);
9571001
pbf_wait(context, 200ms); // wait a moment to ensure the game doesn't fail to launch
9581002
go_home(env.console, context);
9591003

@@ -1004,7 +1048,7 @@ void RngHelper::reset_and_perform_blind_sequence(
10041048
void RngHelper::reset_and_detect_copyright_text(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
10051049
go_home(env.console, context);
10061050
close_game_from_home(env.console, context);
1007-
start_game_from_home(env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST, uint8_t(0), uint8_t(0)); // TODO: add option for user slot if needed
1051+
start_game_from_home(env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST, uint8_t(0), PROFILE);
10081052
pbf_wait(context, 200ms); // add an extra delay to try to ensure the game doesn't fail to launch
10091053
go_home(env.console, context);
10101054

SerialPrograms/Source/PokemonFRLG/Programs/ShinyHunting/PokemonFRLG_RngHelper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ class RngHelper : public SingleSwitchProgramInstance{
102102
void reset_and_detect_copyright_text(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
103103
bool check_for_shiny(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
104104

105-
EnumDropdownOption<Target> TARGET;
105+
SimpleIntegerOption<uint8_t> PROFILE;
106106

107+
EnumDropdownOption<Target> TARGET;
107108
SimpleIntegerOption<uint64_t> NUM_RESETS;
108109

109110
EnumDropdownOption<SeedButton> SEED_BUTTON;

0 commit comments

Comments
 (0)