Skip to content

Commit b4911d9

Browse files
authored
Retry failed SRs and enter summary. (#1111)
* Retry FRLG SRs. * try again * Recover from failing to enter summary as well. * Fix error case.
1 parent de39f79 commit b4911d9

7 files changed

Lines changed: 115 additions & 67 deletions

File tree

SerialPrograms/Source/PokemonFRLG/PokemonFRLG_Navigation.cpp

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "CommonTools/Async/InferenceRoutines.h"
1212
#include "CommonTools/VisualDetectors/BlackScreenDetector.h"
1313
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
14-
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
1514
#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h"
1615
#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h"
1716
#include "PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h"
@@ -26,7 +25,7 @@ namespace NintendoSwitch{
2625
namespace PokemonFRLG{
2726

2827

29-
void soft_reset(ConsoleHandle& console, ProControllerContext& context){
28+
bool try_soft_reset(ConsoleHandle& console, ProControllerContext& context){
3029
// A + B + Select + Start
3130
pbf_press_button(context, BUTTON_B | BUTTON_A | BUTTON_MINUS | BUTTON_PLUS, 360ms, 1440ms);
3231

@@ -58,12 +57,8 @@ void soft_reset(ConsoleHandle& console, ProControllerContext& context){
5857
}else if (ls == 1) {
5958
console.log("Entered load menu. (LoadMenu)");
6059
}else{
61-
console.log("Unable to enter load menu.", COLOR_RED);
62-
OperationFailedException::fire(
63-
ErrorReport::SEND_ERROR_REPORT,
64-
"soft_reset(): Unable to enter load menu.",
65-
console
66-
);
60+
console.log("soft_reset(): Unable to enter load menu.", COLOR_RED);
61+
return false;
6762
}
6863
//Let the animation finish
6964
pbf_wait(context, 500ms);
@@ -82,12 +77,8 @@ void soft_reset(ConsoleHandle& console, ProControllerContext& context){
8277
if (ret == 0){
8378
console.log("Entered game!");
8479
}else{
85-
console.log("Timed out waiting to enter game.", COLOR_RED);
86-
OperationFailedException::fire(
87-
ErrorReport::SEND_ERROR_REPORT,
88-
"soft_reset(): Timed out waiting to enter game.",
89-
console
90-
);
80+
console.log("soft_reset(): Timed out waiting to enter game.", COLOR_RED);
81+
return false;
9182
}
9283

9384
//Mash past "previously on..."
@@ -100,10 +91,25 @@ void soft_reset(ConsoleHandle& console, ProControllerContext& context){
10091
pbf_wait(context, rng_wait2);
10192
context.wait_for_all_requests();
10293

103-
console.log("Soft reset completed.");
94+
return true;
10495
}
10596

106-
void open_slot_six(ConsoleHandle& console, ProControllerContext& context){
97+
uint64_t soft_reset(ConsoleHandle& console, ProControllerContext& context){
98+
uint64_t errors = 0;
99+
for (; errors < 5; errors++){
100+
if (try_soft_reset(console, context)){
101+
console.log("Soft reset completed.");
102+
return errors;
103+
}
104+
}
105+
OperationFailedException::fire(
106+
ErrorReport::SEND_ERROR_REPORT,
107+
"soft_reset(): Failed to reset after 5 attempts.",
108+
console
109+
);
110+
}
111+
112+
bool try_open_slot_six(ConsoleHandle& console, ProControllerContext& context){
107113
//Attempt to exit any dialog and open the start menu
108114
StartMenuWatcher start_menu(COLOR_RED);
109115

@@ -123,11 +129,8 @@ void open_slot_six(ConsoleHandle& console, ProControllerContext& context){
123129
);
124130
context.wait_for_all_requests();
125131
if (ret < 0){
126-
OperationFailedException::fire(
127-
ErrorReport::SEND_ERROR_REPORT,
128-
"open_slot_six(): Unable to open Start menu.",
129-
console
130-
);
132+
console.log("open_slot_six(): Unable to open Start menu.", COLOR_RED);
133+
return false;
131134
}
132135

133136
console.log("Navigating to party menu.");
@@ -150,12 +153,8 @@ void open_slot_six(ConsoleHandle& console, ProControllerContext& context){
150153
if (pm == 0){
151154
console.log("Entered party menu.");
152155
}else{
153-
console.log("Unable to enter Party menu.", COLOR_RED);
154-
OperationFailedException::fire(
155-
ErrorReport::SEND_ERROR_REPORT,
156-
"open_slot_six(): Unable to enter Party menu.",
157-
console
158-
);
156+
console.log("open_slot_six(): Unable to enter Party menu.", COLOR_RED);
157+
return false;
159158
}
160159
context.wait_for_all_requests();
161160

@@ -178,15 +177,29 @@ void open_slot_six(ConsoleHandle& console, ProControllerContext& context){
178177
if (sm == 0){
179178
console.log("Entered summary.");
180179
}else{
181-
console.log("Unable to enter summary.", COLOR_RED);
182-
OperationFailedException::fire(
183-
ErrorReport::SEND_ERROR_REPORT,
184-
"open_slot_six(): Unable to enter summary.",
185-
console
186-
);
180+
console.log("open_slot_six(): Unable to enter summary.", COLOR_RED);
181+
return false;
187182
}
188183
pbf_wait(context, 1000ms);
189184
context.wait_for_all_requests();
185+
return true;
186+
}
187+
188+
uint64_t open_slot_six(ConsoleHandle& console, ProControllerContext& context){
189+
uint64_t errors = 0;
190+
for (; errors < 5; errors++){
191+
if (try_open_slot_six(console, context)){
192+
return errors;
193+
}else{
194+
console.log("Mashing B to return to overworld and retry...");
195+
pbf_mash_button(context, BUTTON_B, 10000ms);
196+
}
197+
}
198+
OperationFailedException::fire(
199+
ErrorReport::SEND_ERROR_REPORT,
200+
"open_slot_six(): Failed to open party summary after 5 attempts.",
201+
console
202+
);
190203
}
191204

192205
bool handle_encounter(ConsoleHandle& console, ProControllerContext& context, bool send_out_lead){

SerialPrograms/Source/PokemonFRLG/PokemonFRLG_Navigation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ namespace PokemonFRLG{
2323
// There are two random waits, one before pressing start and another after loading in the game.
2424
// This is to prevent repeatedly getting the same pokemon, due to FRLG's RNG
2525
// For now this assumes no dry battery.
26-
void soft_reset(ConsoleHandle& console, ProControllerContext &context);
26+
uint64_t soft_reset(ConsoleHandle& console, ProControllerContext &context);
2727

2828
// From the overworld, open the summary of the Pokemon in slot 6. This assumes the menu cursor is in the top slot (POKEDEX)
29-
void open_slot_six(ConsoleHandle& console, ProControllerContext& context);
29+
uint64_t open_slot_six(ConsoleHandle& console, ProControllerContext& context);
3030

3131
// After press A/walking up to enter a battle, run this handle the battle start and to check if opponent is shiny.
3232
// Set send_out_lead to true and then use flee_battle() after if for run away resets

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

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,7 @@ void GiftReset::obtain_lapras(SingleSwitchProgramEnvironment& env, ProController
205205
}
206206

207207
//After declining to nickname, clear rival pickup and open your starter's summary
208-
void GiftReset::open_summary(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
209-
GiftReset_Descriptor::Stats& stats = env.current_stats<GiftReset_Descriptor::Stats>();
210-
208+
bool GiftReset::try_open_summary(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
211209
//From no to nickname to overworld
212210
StartMenuWatcher start_menu(COLOR_RED);
213211

@@ -227,13 +225,9 @@ void GiftReset::open_summary(SingleSwitchProgramEnvironment& env, ProControllerC
227225
);
228226
context.wait_for_all_requests();
229227
if (ret < 0){
230-
stats.errors++;
231228
env.update_stats();
232-
OperationFailedException::fire(
233-
ErrorReport::SEND_ERROR_REPORT,
234-
"open_summary(): Unable to open Start menu after 10 attempts.",
235-
env.console
236-
);
229+
env.log("open_summary(): Unable to open Start menu after 10 attempts.", COLOR_RED);
230+
return false;
237231
}
238232

239233
if (TARGET != Target::starters){
@@ -261,12 +255,8 @@ void GiftReset::open_summary(SingleSwitchProgramEnvironment& env, ProControllerC
261255
if (pm == 0){
262256
env.log("Entered party menu.");
263257
}else{
264-
env.log("Unable to enter party menu.", COLOR_RED);
265-
OperationFailedException::fire(
266-
ErrorReport::SEND_ERROR_REPORT,
267-
"open_summary(): Unable to enter Party menu.",
268-
env.console
269-
);
258+
env.log("open_summary(): Unable to enter party menu.", COLOR_RED);
259+
return false;
270260
}
271261

272262
//Press up twice to get to the last slot
@@ -290,16 +280,28 @@ void GiftReset::open_summary(SingleSwitchProgramEnvironment& env, ProControllerC
290280
if (sm == 0){
291281
env.log("Entered summary.");
292282
}else{
293-
env.log("Unable to enter summary.", COLOR_RED);
294-
OperationFailedException::fire(
295-
ErrorReport::SEND_ERROR_REPORT,
296-
"open_summary(): Unable to enter summary.",
297-
env.console
298-
);
283+
env.log("open_summary(): Unable to enter summary.", COLOR_RED);
284+
return false;
299285
}
300286
pbf_wait(context, 1000ms);
301287
context.wait_for_all_requests();
302-
288+
return true;
289+
}
290+
uint64_t GiftReset::open_summary(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
291+
uint64_t errors = 0;
292+
for (; errors < 5; errors++){
293+
if (try_open_summary(env, context)){
294+
return errors;
295+
}else{
296+
env.log("Mashing B to return to overworld and retry...");
297+
pbf_mash_button(context, BUTTON_B, 10000ms);
298+
}
299+
}
300+
OperationFailedException::fire(
301+
ErrorReport::SEND_ERROR_REPORT,
302+
"open_summary(): Failed to open party summary after 5 attempts.",
303+
env.console
304+
);
303305
}
304306

305307

@@ -325,7 +327,7 @@ void GiftReset::program(SingleSwitchProgramEnvironment& env, ProControllerContex
325327
}else{
326328
obtain_lapras(env, context);
327329
}
328-
open_summary(env, context);
330+
stats.errors += open_summary(env, context);
329331

330332
VideoSnapshot screen = env.console.video().snapshot();
331333

@@ -335,7 +337,15 @@ void GiftReset::program(SingleSwitchProgramEnvironment& env, ProControllerContex
335337
if (shiny_starter){
336338
env.log("Shiny found!");
337339
stats.shinies++;
338-
send_program_notification(env, NOTIFICATION_SHINY, COLOR_YELLOW, "Shiny found!", {}, "", screen, true);
340+
send_program_notification(
341+
env,
342+
NOTIFICATION_SHINY,
343+
COLOR_YELLOW,
344+
"Shiny found!",
345+
{}, "",
346+
screen,
347+
true
348+
);
339349
break;
340350
}else{
341351
env.log("Pokemon is not shiny.");
@@ -344,7 +354,7 @@ void GiftReset::program(SingleSwitchProgramEnvironment& env, ProControllerContex
344354
env, NOTIFICATION_STATUS_UPDATE,
345355
"Soft resetting."
346356
);
347-
soft_reset(env.console, context);
357+
stats.errors += soft_reset(env.console, context);
348358
stats.resets++;
349359
env.update_stats();
350360
context.wait_for_all_requests();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class GiftReset : public SingleSwitchProgramInstance{
3535
private:
3636
void obtain_pokemon(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
3737
void obtain_lapras(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
38-
void open_summary(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
38+
bool try_open_summary(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
39+
uint64_t open_summary(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
3940

4041
enum class Target{
4142
starters,

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,15 @@ void LegendaryReset::program(SingleSwitchProgramEnvironment& env, ProControllerC
129129
if (legendary_shiny){
130130
stats.shinies++;
131131
env.update_stats();
132-
send_program_notification(env, NOTIFICATION_SHINY, COLOR_YELLOW, "Shiny found!", {}, "", env.console.video().snapshot(), true);
132+
send_program_notification(
133+
env,
134+
NOTIFICATION_SHINY,
135+
COLOR_YELLOW,
136+
"Shiny found!",
137+
{}, "",
138+
env.console.video().snapshot(),
139+
true
140+
);
133141
break;
134142
}
135143

@@ -140,7 +148,7 @@ void LegendaryReset::program(SingleSwitchProgramEnvironment& env, ProControllerC
140148
"Soft resetting."
141149
);
142150

143-
soft_reset(env.console, context);
151+
stats.errors += soft_reset(env.console, context);
144152
stats.resets++;
145153
env.update_stats();
146154
context.wait_for_all_requests();

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ void PrizeCornerReset::program(SingleSwitchProgramEnvironment& env, ProControlle
146146

147147
while (!shiny_found){
148148
obtain_prize(env, context);
149-
open_slot_six(env.console, context);
149+
stats.errors += open_slot_six(env.console, context);
150150

151151
VideoSnapshot screen = env.console.video().snapshot();
152152

@@ -156,7 +156,15 @@ void PrizeCornerReset::program(SingleSwitchProgramEnvironment& env, ProControlle
156156
if (shiny_found){
157157
env.log("Shiny found!");
158158
stats.shinies++;
159-
send_program_notification(env, NOTIFICATION_SHINY, COLOR_YELLOW, "Shiny found!", {}, "", screen, true);
159+
send_program_notification(
160+
env,
161+
NOTIFICATION_SHINY,
162+
COLOR_YELLOW,
163+
"Shiny found!",
164+
{}, "",
165+
screen,
166+
true
167+
);
160168
break;
161169
}else{
162170
env.log("Prize is not shiny.");
@@ -165,7 +173,7 @@ void PrizeCornerReset::program(SingleSwitchProgramEnvironment& env, ProControlle
165173
env, NOTIFICATION_STATUS_UPDATE,
166174
"Soft resetting."
167175
);
168-
soft_reset(env.console, context);
176+
stats.errors += soft_reset(env.console, context);
169177
stats.resets++;
170178
context.wait_for_all_requests();
171179
}

SerialPrograms/Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_AudioStarterReset.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,15 @@ void AudioStarterReset::program(SingleSwitchProgramEnvironment& env, ProControll
197197
env.log("Shiny starter detected!");
198198
stats.shinystarter++;
199199
env.update_stats();
200-
send_program_notification(env, NOTIFICATION_SHINY_STARTER, COLOR_YELLOW, "Shiny starter found!", {}, "", env.console.video().snapshot(), true);
200+
send_program_notification(
201+
env,
202+
NOTIFICATION_SHINY_STARTER,
203+
COLOR_YELLOW,
204+
"Shiny starter found!",
205+
{}, "",
206+
env.console.video().snapshot(),
207+
true
208+
);
201209
shiny_starter = true;
202210
}
203211
else {

0 commit comments

Comments
 (0)