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
79 changes: 46 additions & 33 deletions SerialPrograms/Source/PokemonFRLG/PokemonFRLG_Navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "CommonTools/Async/InferenceRoutines.h"
#include "CommonTools/VisualDetectors/BlackScreenDetector.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h"
#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h"
#include "PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h"
Expand All @@ -26,7 +25,7 @@ namespace NintendoSwitch{
namespace PokemonFRLG{


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

Expand Down Expand Up @@ -58,12 +57,8 @@ void soft_reset(ConsoleHandle& console, ProControllerContext& context){
}else if (ls == 1) {
console.log("Entered load menu. (LoadMenu)");
}else{
console.log("Unable to enter load menu.", COLOR_RED);
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"soft_reset(): Unable to enter load menu.",
console
);
console.log("soft_reset(): Unable to enter load menu.", COLOR_RED);
return false;
}
//Let the animation finish
pbf_wait(context, 500ms);
Expand All @@ -82,12 +77,8 @@ void soft_reset(ConsoleHandle& console, ProControllerContext& context){
if (ret == 0){
console.log("Entered game!");
}else{
console.log("Timed out waiting to enter game.", COLOR_RED);
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"soft_reset(): Timed out waiting to enter game.",
console
);
console.log("soft_reset(): Timed out waiting to enter game.", COLOR_RED);
return false;
}

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

console.log("Soft reset completed.");
return true;
}

void open_slot_six(ConsoleHandle& console, ProControllerContext& context){
uint64_t soft_reset(ConsoleHandle& console, ProControllerContext& context){
uint64_t errors = 0;
for (; errors < 5; errors++){
if (try_soft_reset(console, context)){
console.log("Soft reset completed.");
return errors;
}
}
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"soft_reset(): Failed to reset after 5 attempts.",
console
);
}

bool try_open_slot_six(ConsoleHandle& console, ProControllerContext& context){
//Attempt to exit any dialog and open the start menu
StartMenuWatcher start_menu(COLOR_RED);

Expand All @@ -123,11 +129,8 @@ void open_slot_six(ConsoleHandle& console, ProControllerContext& context){
);
context.wait_for_all_requests();
if (ret < 0){
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"open_slot_six(): Unable to open Start menu.",
console
);
console.log("open_slot_six(): Unable to open Start menu.", COLOR_RED);
return false;
}

console.log("Navigating to party menu.");
Expand All @@ -150,12 +153,8 @@ void open_slot_six(ConsoleHandle& console, ProControllerContext& context){
if (pm == 0){
console.log("Entered party menu.");
}else{
console.log("Unable to enter Party menu.", COLOR_RED);
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"open_slot_six(): Unable to enter Party menu.",
console
);
console.log("open_slot_six(): Unable to enter Party menu.", COLOR_RED);
return false;
}
context.wait_for_all_requests();

Expand All @@ -178,15 +177,29 @@ void open_slot_six(ConsoleHandle& console, ProControllerContext& context){
if (sm == 0){
console.log("Entered summary.");
}else{
console.log("Unable to enter summary.", COLOR_RED);
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"open_slot_six(): Unable to enter summary.",
console
);
console.log("open_slot_six(): Unable to enter summary.", COLOR_RED);
return false;
}
pbf_wait(context, 1000ms);
context.wait_for_all_requests();
return true;
}

uint64_t open_slot_six(ConsoleHandle& console, ProControllerContext& context){
uint64_t errors = 0;
for (; errors < 5; errors++){
if (try_open_slot_six(console, context)){
return errors;
}else{
console.log("Mashing B to return to overworld and retry...");
pbf_mash_button(context, BUTTON_B, 10000ms);
}
}
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"open_slot_six(): Failed to open party summary after 5 attempts.",
console
);
}

bool handle_encounter(ConsoleHandle& console, ProControllerContext& context, bool send_out_lead){
Expand Down
4 changes: 2 additions & 2 deletions SerialPrograms/Source/PokemonFRLG/PokemonFRLG_Navigation.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ namespace PokemonFRLG{
// There are two random waits, one before pressing start and another after loading in the game.
// This is to prevent repeatedly getting the same pokemon, due to FRLG's RNG
// For now this assumes no dry battery.
void soft_reset(ConsoleHandle& console, ProControllerContext &context);
uint64_t soft_reset(ConsoleHandle& console, ProControllerContext &context);

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

// After press A/walking up to enter a battle, run this handle the battle start and to check if opponent is shiny.
// Set send_out_lead to true and then use flee_battle() after if for run away resets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,7 @@ void GiftReset::obtain_lapras(SingleSwitchProgramEnvironment& env, ProController
}

//After declining to nickname, clear rival pickup and open your starter's summary
void GiftReset::open_summary(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
GiftReset_Descriptor::Stats& stats = env.current_stats<GiftReset_Descriptor::Stats>();

bool GiftReset::try_open_summary(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
//From no to nickname to overworld
StartMenuWatcher start_menu(COLOR_RED);

Expand All @@ -227,13 +225,9 @@ void GiftReset::open_summary(SingleSwitchProgramEnvironment& env, ProControllerC
);
context.wait_for_all_requests();
if (ret < 0){
stats.errors++;
env.update_stats();
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"open_summary(): Unable to open Start menu after 10 attempts.",
env.console
);
env.log("open_summary(): Unable to open Start menu after 10 attempts.", COLOR_RED);
return false;
}

if (TARGET != Target::starters){
Expand Down Expand Up @@ -261,12 +255,8 @@ void GiftReset::open_summary(SingleSwitchProgramEnvironment& env, ProControllerC
if (pm == 0){
env.log("Entered party menu.");
}else{
env.log("Unable to enter party menu.", COLOR_RED);
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"open_summary(): Unable to enter Party menu.",
env.console
);
env.log("open_summary(): Unable to enter party menu.", COLOR_RED);
return false;
}

//Press up twice to get to the last slot
Expand All @@ -290,16 +280,28 @@ void GiftReset::open_summary(SingleSwitchProgramEnvironment& env, ProControllerC
if (sm == 0){
env.log("Entered summary.");
}else{
env.log("Unable to enter summary.", COLOR_RED);
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"open_summary(): Unable to enter summary.",
env.console
);
env.log("open_summary(): Unable to enter summary.", COLOR_RED);
return false;
}
pbf_wait(context, 1000ms);
context.wait_for_all_requests();

return true;
}
uint64_t GiftReset::open_summary(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
uint64_t errors = 0;
for (; errors < 5; errors++){
if (try_open_summary(env, context)){
return errors;
}else{
env.log("Mashing B to return to overworld and retry...");
pbf_mash_button(context, BUTTON_B, 10000ms);
}
}
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"open_summary(): Failed to open party summary after 5 attempts.",
env.console
);
}


Expand All @@ -325,7 +327,7 @@ void GiftReset::program(SingleSwitchProgramEnvironment& env, ProControllerContex
}else{
obtain_lapras(env, context);
}
open_summary(env, context);
stats.errors += open_summary(env, context);

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

Expand All @@ -335,7 +337,15 @@ void GiftReset::program(SingleSwitchProgramEnvironment& env, ProControllerContex
if (shiny_starter){
env.log("Shiny found!");
stats.shinies++;
send_program_notification(env, NOTIFICATION_SHINY, COLOR_YELLOW, "Shiny found!", {}, "", screen, true);
send_program_notification(
env,
NOTIFICATION_SHINY,
COLOR_YELLOW,
"Shiny found!",
{}, "",
screen,
true
);
break;
}else{
env.log("Pokemon is not shiny.");
Expand All @@ -344,7 +354,7 @@ void GiftReset::program(SingleSwitchProgramEnvironment& env, ProControllerContex
env, NOTIFICATION_STATUS_UPDATE,
"Soft resetting."
);
soft_reset(env.console, context);
stats.errors += soft_reset(env.console, context);
stats.resets++;
env.update_stats();
context.wait_for_all_requests();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class GiftReset : public SingleSwitchProgramInstance{
private:
void obtain_pokemon(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
void obtain_lapras(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
void open_summary(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
bool try_open_summary(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
uint64_t open_summary(SingleSwitchProgramEnvironment& env, ProControllerContext& context);

enum class Target{
starters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,15 @@ void LegendaryReset::program(SingleSwitchProgramEnvironment& env, ProControllerC
if (legendary_shiny){
stats.shinies++;
env.update_stats();
send_program_notification(env, NOTIFICATION_SHINY, COLOR_YELLOW, "Shiny found!", {}, "", env.console.video().snapshot(), true);
send_program_notification(
env,
NOTIFICATION_SHINY,
COLOR_YELLOW,
"Shiny found!",
{}, "",
env.console.video().snapshot(),
true
);
break;
}

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

soft_reset(env.console, context);
stats.errors += soft_reset(env.console, context);
stats.resets++;
env.update_stats();
context.wait_for_all_requests();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void PrizeCornerReset::program(SingleSwitchProgramEnvironment& env, ProControlle

while (!shiny_found){
obtain_prize(env, context);
open_slot_six(env.console, context);
stats.errors += open_slot_six(env.console, context);

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

Expand All @@ -156,7 +156,15 @@ void PrizeCornerReset::program(SingleSwitchProgramEnvironment& env, ProControlle
if (shiny_found){
env.log("Shiny found!");
stats.shinies++;
send_program_notification(env, NOTIFICATION_SHINY, COLOR_YELLOW, "Shiny found!", {}, "", screen, true);
send_program_notification(
env,
NOTIFICATION_SHINY,
COLOR_YELLOW,
"Shiny found!",
{}, "",
screen,
true
);
break;
}else{
env.log("Prize is not shiny.");
Expand All @@ -165,7 +173,7 @@ void PrizeCornerReset::program(SingleSwitchProgramEnvironment& env, ProControlle
env, NOTIFICATION_STATUS_UPDATE,
"Soft resetting."
);
soft_reset(env.console, context);
stats.errors += soft_reset(env.console, context);
stats.resets++;
context.wait_for_all_requests();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,15 @@ void AudioStarterReset::program(SingleSwitchProgramEnvironment& env, ProControll
env.log("Shiny starter detected!");
stats.shinystarter++;
env.update_stats();
send_program_notification(env, NOTIFICATION_SHINY_STARTER, COLOR_YELLOW, "Shiny starter found!", {}, "", env.console.video().snapshot(), true);
send_program_notification(
env,
NOTIFICATION_SHINY_STARTER,
COLOR_YELLOW,
"Shiny starter found!",
{}, "",
env.console.video().snapshot(),
true
);
shiny_starter = true;
}
else {
Expand Down