|
| 1 | +/* RS Starter Reset |
| 2 | + * |
| 3 | + * From: https://github.com/PokemonAutomation/Arduino-Source |
| 4 | + * |
| 5 | + */ |
| 6 | + |
| 7 | +#include "CommonFramework/Exceptions/OperationFailedException.h" |
| 8 | +#include "CommonFramework/ProgramStats/StatsTracking.h" |
| 9 | +#include "CommonTools/Async/InferenceRoutines.h" |
| 10 | +#include "CommonTools/VisualDetectors/BlackScreenDetector.h" |
| 11 | +#include "CommonFramework/Notifications/ProgramNotifications.h" |
| 12 | +#include "CommonFramework/ProgramStats/StatsTracking.h" |
| 13 | +#include "CommonFramework/VideoPipeline/VideoFeed.h" |
| 14 | +#include "Pokemon/Pokemon_Strings.h" |
| 15 | +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" |
| 16 | +#include "PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.h" |
| 17 | +#include "PokemonRSE/Inference/PokemonRSE_ShinyNumberDetector.h" |
| 18 | +#include "PokemonRSE/PokemonRSE_Navigation.h" |
| 19 | +#include "PokemonRSE_StarterReset.h" |
| 20 | + |
| 21 | +namespace PokemonAutomation{ |
| 22 | +namespace NintendoSwitch{ |
| 23 | +namespace PokemonRSE{ |
| 24 | + |
| 25 | +StarterReset_Descriptor::StarterReset_Descriptor() |
| 26 | + : SingleSwitchProgramDescriptor( |
| 27 | + "PokemonRSE:StarterReset", |
| 28 | + Pokemon::STRING_POKEMON + " RSE", "[RS]Starter Reset - Video", |
| 29 | + "ComputerControl/blob/master/Wiki/Programs/PokemonRSE/StarterReset.md", |
| 30 | + "Soft reset for a shiny starter. Ruby and Sapphire only.", |
| 31 | + FeedbackType::REQUIRED, |
| 32 | + AllowCommandsWhenRunning::DISABLE_COMMANDS, |
| 33 | + {SerialPABotBase::OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS} |
| 34 | + ) |
| 35 | +{} |
| 36 | + |
| 37 | +struct StarterReset_Descriptor::Stats : public StatsTracker{ |
| 38 | + Stats() |
| 39 | + : resets(m_stats["Resets"]) |
| 40 | + , shinystarter(m_stats["Shiny Starter"]) |
| 41 | + { |
| 42 | + m_display_order.emplace_back("Resets"); |
| 43 | + m_display_order.emplace_back("Shiny Starter"); |
| 44 | + } |
| 45 | + std::atomic<uint64_t>& resets; |
| 46 | + std::atomic<uint64_t>& shinystarter; |
| 47 | +}; |
| 48 | +std::unique_ptr<StatsTracker> StarterReset_Descriptor::make_stats() const{ |
| 49 | + return std::unique_ptr<StatsTracker>(new Stats()); |
| 50 | +} |
| 51 | + |
| 52 | +StarterReset::StarterReset() |
| 53 | + : TARGET( |
| 54 | + "<b>Starter:</b><br>", |
| 55 | + { |
| 56 | + {Target::treecko, "treecko", "Treecko"}, |
| 57 | + {Target::torchic, "torchic", "Torchic"}, |
| 58 | + {Target::mudkip, "mudkip", "Mudkip"}, |
| 59 | + }, |
| 60 | + LockMode::LOCK_WHILE_RUNNING, |
| 61 | + Target::treecko |
| 62 | + ) |
| 63 | + , STARTER_WAIT( |
| 64 | + "<b>Send out starter wait:</b><br>After pressing A to send out your selected starter, wait this long for the animation. Make sure to add extra time in case it is shiny.", |
| 65 | + LockMode::LOCK_WHILE_RUNNING, |
| 66 | + TICKS_PER_SECOND, |
| 67 | + "6 * TICKS_PER_SECOND" |
| 68 | + ) |
| 69 | + , NOTIFICATION_SHINY_STARTER( |
| 70 | + "Shiny Starter", |
| 71 | + true, true, ImageAttachmentMode::JPG, |
| 72 | + {"Notifs", "Showcase"} |
| 73 | + ) |
| 74 | + , NOTIFICATION_STATUS_UPDATE("Status Update", true, false, std::chrono::seconds(3600)) |
| 75 | + , NOTIFICATIONS({ |
| 76 | + &NOTIFICATION_SHINY_STARTER, |
| 77 | + &NOTIFICATION_STATUS_UPDATE, |
| 78 | + &NOTIFICATION_PROGRAM_FINISH, |
| 79 | + }) |
| 80 | +{ |
| 81 | + PA_ADD_OPTION(TARGET); |
| 82 | + PA_ADD_OPTION(NOTIFICATIONS); |
| 83 | +} |
| 84 | + |
| 85 | +void StarterReset::program(SingleSwitchProgramEnvironment& env, SwitchControllerContext& context){ |
| 86 | + StarterReset_Descriptor::Stats& stats = env.current_stats<StarterReset_Descriptor::Stats>(); |
| 87 | + |
| 88 | + /* |
| 89 | + * Settings: Text Speed fast. |
| 90 | + * Full screen, no filter? The device I'm using to test has similar looking output, but I don't have switch online+. |
| 91 | + * If on a retro handheld, make sure the screen matches that of NSO+. |
| 92 | + * |
| 93 | + * Setup: Stand in front of the Professor's bag and save the game. |
| 94 | + * |
| 95 | + * Required to fight, so have to do the SR method instead of run away |
| 96 | + * Soft reset programs are only for Ruby/Sapphire, as Emerald has the 0 seed issue. |
| 97 | + * |
| 98 | + * This also assumes no dry battery. |
| 99 | + * |
| 100 | + * WARNING: Timings in Emerald for the battle menu are slightly different. This won't work with Emerald at all. |
| 101 | + */ |
| 102 | + |
| 103 | + bool shiny_starter = false; |
| 104 | + while (!shiny_starter) { |
| 105 | + env.log("Opening bag and selecting starter."); |
| 106 | + pbf_press_button(context, BUTTON_A, 40, 180); |
| 107 | + |
| 108 | + switch (TARGET) { |
| 109 | + case Target::treecko: |
| 110 | + pbf_press_dpad(context, DPAD_LEFT, 40, 100); |
| 111 | + break; |
| 112 | + case Target::torchic: |
| 113 | + //Default cursor position, do nothing. |
| 114 | + break; |
| 115 | + case Target::mudkip: |
| 116 | + pbf_press_dpad(context, DPAD_RIGHT, 40, 100); |
| 117 | + break; |
| 118 | + default: |
| 119 | + OperationFailedException::fire( |
| 120 | + ErrorReport::SEND_ERROR_REPORT, |
| 121 | + "StarterReset: Invalid target.", |
| 122 | + env.console |
| 123 | + ); |
| 124 | + break; |
| 125 | + } |
| 126 | + pbf_mash_button(context, BUTTON_A, 540); |
| 127 | + context.wait_for_all_requests(); |
| 128 | + |
| 129 | + env.log("Starting battle."); |
| 130 | + |
| 131 | + //Now mash B until the battle menu appears |
| 132 | + BattleMenuWatcher battle_menu(COLOR_RED); |
| 133 | + int ret = run_until<SwitchControllerContext>( |
| 134 | + env.console, context, |
| 135 | + [](SwitchControllerContext& context){ |
| 136 | + pbf_mash_button(context, BUTTON_B, 1000); |
| 137 | + }, |
| 138 | + {battle_menu} |
| 139 | + ); |
| 140 | + context.wait_for_all_requests(); |
| 141 | + if (ret != 0){ |
| 142 | + env.console.log("Failed to detect battle menu.", COLOR_RED); |
| 143 | + } |
| 144 | + else { |
| 145 | + env.log("Battle menu detected."); |
| 146 | + } |
| 147 | + |
| 148 | + //Open the summary and check the color of the number |
| 149 | + pbf_press_dpad(context, DPAD_DOWN, 40, 80); |
| 150 | + pbf_press_button(context, BUTTON_A, 40, 80); |
| 151 | + |
| 152 | + BlackScreenOverWatcher detector(COLOR_RED, {0.282, 0.064, 0.448, 0.871}); |
| 153 | + int ret2 = wait_until( |
| 154 | + env.console, context, |
| 155 | + std::chrono::milliseconds(3000), |
| 156 | + {{detector}} |
| 157 | + ); |
| 158 | + if (ret2 == 0){ |
| 159 | + env.log("Entered party menu."); |
| 160 | + }else{ |
| 161 | + env.log("Timed out waiting to enter party menu.", COLOR_RED); |
| 162 | + OperationFailedException::fire( |
| 163 | + ErrorReport::SEND_ERROR_REPORT, |
| 164 | + "StarterReset: Timed out waiting to enter party menu.", |
| 165 | + env.console |
| 166 | + ); |
| 167 | + } |
| 168 | + |
| 169 | + pbf_press_button(context, BUTTON_A, 20, 180); |
| 170 | + pbf_press_dpad(context, DPAD_DOWN, 40, 80); |
| 171 | + pbf_press_button(context, BUTTON_A, 40, 80); |
| 172 | + |
| 173 | + //Check second party member - used for testing with hacked in shiny starter |
| 174 | + //pbf_press_dpad(context, DPAD_DOWN, 40, 80); |
| 175 | + |
| 176 | + pbf_wait(context, 125); |
| 177 | + context.wait_for_all_requests(); |
| 178 | + |
| 179 | + VideoSnapshot screen = env.console.video().snapshot(); |
| 180 | + ShinyNumberDetector shiny_checker(COLOR_YELLOW); |
| 181 | + shiny_starter = shiny_checker.read(env.console.logger(), screen); |
| 182 | + |
| 183 | + if (shiny_starter) { |
| 184 | + env.log("Shiny starter detected!"); |
| 185 | + stats.shinystarter++; |
| 186 | + send_program_status_notification(env, NOTIFICATION_SHINY_STARTER, "Shiny starter found!", screen, true); |
| 187 | + } |
| 188 | + else { |
| 189 | + env.log("Starter is not shiny."); |
| 190 | + env.log("Soft resetting."); |
| 191 | + send_program_status_notification( |
| 192 | + env, NOTIFICATION_STATUS_UPDATE, |
| 193 | + "Soft resetting." |
| 194 | + ); |
| 195 | + soft_reset(env.program_info(), env.console, context); |
| 196 | + stats.resets++; |
| 197 | + } |
| 198 | + } |
| 199 | + |
| 200 | + //if system set to nintendo switch, have go home when done option? |
| 201 | + |
| 202 | + send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH); |
| 203 | +} |
| 204 | + |
| 205 | +} |
| 206 | +} |
| 207 | +} |
| 208 | + |
0 commit comments