-
Notifications
You must be signed in to change notification settings - Fork 81
Rse starter resets #530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Mysticial
merged 4 commits into
PokemonAutomation:main
from
kichithewolf:rse-starter-resets
Jan 30, 2025
Merged
Rse starter resets #530
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
SerialPrograms/Source/PokemonRSE/PokemonRSE_Navigation.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* Pokemon RSE Navigation | ||
| * | ||
| * From: https://github.com/PokemonAutomation/Arduino-Source | ||
| * | ||
| * Soft reset, menus, etc. | ||
| * | ||
| */ | ||
|
|
||
| #include "CommonFramework/Exceptions/OperationFailedException.h" | ||
| #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 "PokemonRSE/PokemonRSE_Settings.h" | ||
| #include "PokemonRSE_Navigation.h" | ||
|
|
||
| namespace PokemonAutomation{ | ||
| namespace NintendoSwitch{ | ||
| namespace PokemonRSE{ | ||
|
|
||
|
|
||
| void soft_reset(const ProgramInfo& info, VideoStream& stream, SwitchControllerContext& context){ | ||
| // A + B + Select + Start | ||
| pbf_press_button(context, BUTTON_B | BUTTON_Y | BUTTON_MINUS | BUTTON_PLUS, 10, 180); | ||
|
|
||
| pbf_mash_button(context, BUTTON_PLUS, GameSettings::instance().START_BUTTON_MASH); | ||
| context.wait_for_all_requests(); | ||
|
|
||
| pbf_press_button(context, BUTTON_A, 20, 40); | ||
|
|
||
| //Wait for game to load in | ||
| BlackScreenOverWatcher detector(COLOR_RED, {0.282, 0.064, 0.448, 0.871}); | ||
| int ret = wait_until( | ||
| stream, context, | ||
| std::chrono::milliseconds(GameSettings::instance().ENTER_GAME_WAIT * (1000 / TICKS_PER_SECOND)), | ||
| {{detector}} | ||
| ); | ||
| if (ret == 0){ | ||
| stream.log("Entered game!"); | ||
| }else{ | ||
| stream.log("Timed out waiting to enter game.", COLOR_RED); | ||
| OperationFailedException::fire( | ||
| ErrorReport::SEND_ERROR_REPORT, | ||
| "soft_reset(): Timed out waiting to enter game.", | ||
| stream | ||
| ); | ||
| } | ||
| context.wait_for_all_requests(); | ||
| } | ||
|
|
||
|
|
||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* Pokemon RSE Navigation | ||
| * | ||
| * From: https://github.com/PokemonAutomation/Arduino-Source | ||
| * | ||
| * Soft reset, menus, etc. | ||
| * | ||
| */ | ||
|
|
||
| #ifndef PokemonAutomation_PokemonRSE_Navigation_H | ||
| #define PokemonAutomation_PokemonRSE_Navigation_H | ||
|
|
||
| #include "CommonFramework/Tools/VideoStream.h" | ||
| #include "Common/NintendoSwitch/NintendoSwitch_ControllerDefs.h" | ||
| #include "NintendoSwitch/Controllers/NintendoSwitch_Controller.h" | ||
|
|
||
| namespace PokemonAutomation{ | ||
| struct ProgramInfo; | ||
| namespace NintendoSwitch{ | ||
| namespace PokemonRSE{ | ||
|
|
||
| // Press A+B+Select+Start at the same time to soft reset, then re-enters the game. | ||
| // For now this assumes no dry battery. | ||
| void soft_reset(const ProgramInfo& info, VideoStream& stream, SwitchControllerContext &context); | ||
|
|
||
|
|
||
| } | ||
| } | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
221 changes: 221 additions & 0 deletions
221
SerialPrograms/Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_AudioStarterReset.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,221 @@ | ||
| /* RS Starter Reset | ||
| * | ||
| * From: https://github.com/PokemonAutomation/Arduino-Source | ||
| * | ||
| */ | ||
|
|
||
| #include "CommonFramework/Exceptions/OperationFailedException.h" | ||
| #include "CommonFramework/ProgramStats/StatsTracking.h" | ||
| #include "CommonFramework/VideoPipeline/VideoFeed.h" | ||
| #include "CommonTools/Async/InferenceRoutines.h" | ||
| #include "CommonFramework/Notifications/ProgramNotifications.h" | ||
| #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" | ||
| #include "Pokemon/Pokemon_Strings.h" | ||
| #include "PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.h" | ||
| #include "PokemonRSE/Inference/Sounds/PokemonRSE_ShinySoundDetector.h" | ||
| #include "PokemonRSE/PokemonRSE_Navigation.h" | ||
| #include "PokemonRSE_AudioStarterReset.h" | ||
|
|
||
| namespace PokemonAutomation{ | ||
| namespace NintendoSwitch{ | ||
| namespace PokemonRSE{ | ||
|
|
||
| AudioStarterReset_Descriptor::AudioStarterReset_Descriptor() | ||
| : SingleSwitchProgramDescriptor( | ||
| "PokemonRSE:AudioStarterReset", | ||
| Pokemon::STRING_POKEMON + " RSE", "Starter Reset (Ruby/Sapphire)", | ||
| "ComputerControl/blob/master/Wiki/Programs/PokemonRSE/AudioStarterReset.md", | ||
| "Soft reset for a shiny starter. Ruby and Sapphire only.", | ||
| FeedbackType::VIDEO_AUDIO, | ||
| AllowCommandsWhenRunning::DISABLE_COMMANDS, | ||
| {SerialPABotBase::OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS} | ||
| ) | ||
| {} | ||
|
|
||
| struct AudioStarterReset_Descriptor::Stats : public StatsTracker{ | ||
| Stats() | ||
| : resets(m_stats["Resets"]) | ||
| , poochyena(m_stats["Shiny Poochyena"]) | ||
| , shinystarter(m_stats["Shiny Starter"]) | ||
| { | ||
| m_display_order.emplace_back("Resets"); | ||
| m_display_order.emplace_back("Shiny Poochyena"); | ||
| m_display_order.emplace_back("Shiny Starter"); | ||
| } | ||
| std::atomic<uint64_t>& resets; | ||
| std::atomic<uint64_t>& poochyena; | ||
| std::atomic<uint64_t>& shinystarter; | ||
| }; | ||
| std::unique_ptr<StatsTracker> AudioStarterReset_Descriptor::make_stats() const{ | ||
| return std::unique_ptr<StatsTracker>(new Stats()); | ||
| } | ||
|
|
||
| AudioStarterReset::AudioStarterReset() | ||
| : TARGET( | ||
| "<b>Starter:</b><br>", | ||
| { | ||
| {Target::treecko, "treecko", "Treecko"}, | ||
| {Target::torchic, "torchic", "Torchic"}, | ||
| {Target::mudkip, "mudkip", "Mudkip"}, | ||
| }, | ||
| LockMode::LOCK_WHILE_RUNNING, | ||
| Target::treecko | ||
| ) | ||
| , NOTIFICATION_SHINY_POOCH( | ||
| "Shiny Poochyena", | ||
| false, false, ImageAttachmentMode::JPG, | ||
| {"Notifs"} | ||
| ) | ||
| , NOTIFICATION_SHINY_STARTER( | ||
| "Shiny Starter", | ||
| true, true, ImageAttachmentMode::JPG, | ||
| {"Notifs", "Showcase"} | ||
| ) | ||
| , NOTIFICATION_STATUS_UPDATE("Status Update", true, false, std::chrono::seconds(3600)) | ||
| , NOTIFICATIONS({ | ||
| &NOTIFICATION_SHINY_POOCH, | ||
| &NOTIFICATION_SHINY_STARTER, | ||
| &NOTIFICATION_STATUS_UPDATE, | ||
| &NOTIFICATION_PROGRAM_FINISH, | ||
| }) | ||
| { | ||
| PA_ADD_OPTION(TARGET); | ||
| PA_ADD_OPTION(NOTIFICATIONS); | ||
| } | ||
|
|
||
| void AudioStarterReset::program(SingleSwitchProgramEnvironment& env, SwitchControllerContext& context){ | ||
| AudioStarterReset_Descriptor::Stats& stats = env.current_stats<AudioStarterReset_Descriptor::Stats>(); | ||
|
|
||
| /* | ||
| * Settings: Text Speed fast. | ||
| * Full screen, no filter? The device I'm using to test has similar looking output, but I don't have switch online+. | ||
| * If on a retro handheld, make sure the screen matches that of NSO+. | ||
| * | ||
| * Setup: Stand in front of the Professor's bag and save the game. | ||
| * | ||
| * Required to fight, so have to do the SR method instead of run away | ||
| * Soft reset programs are only for Ruby/Sapphire, as Emerald has the 0 seed issue. | ||
| * | ||
| * This also assumes no dry battery. | ||
| */ | ||
|
|
||
| bool shiny_starter = false; | ||
| while (!shiny_starter) { | ||
| float shiny_coefficient = 1.0; | ||
| ShinySoundDetector pooch_detector(env.console, [&](float error_coefficient) -> bool{ | ||
| shiny_coefficient = error_coefficient; | ||
| return true; | ||
| }); | ||
|
|
||
| env.log("Opening bag and selecting starter."); | ||
| pbf_press_button(context, BUTTON_A, 40, 180); | ||
|
|
||
| switch (TARGET) { | ||
| case Target::treecko: | ||
| pbf_press_dpad(context, DPAD_LEFT, 40, 100); | ||
| break; | ||
| case Target::torchic: | ||
| //Default cursor position, do nothing. | ||
| break; | ||
| case Target::mudkip: | ||
| pbf_press_dpad(context, DPAD_RIGHT, 40, 100); | ||
| break; | ||
| default: | ||
| OperationFailedException::fire( | ||
| ErrorReport::SEND_ERROR_REPORT, | ||
| "AudioStarterReset: Invalid target.", | ||
| env.console | ||
| ); | ||
| break; | ||
| } | ||
| pbf_mash_button(context, BUTTON_A, 540); | ||
| context.wait_for_all_requests(); | ||
|
|
||
| env.log("Starter selected. Checking for shiny Poochyena."); | ||
| AdvanceBattleDialogWatcher pooch_appeared(COLOR_YELLOW); | ||
|
|
||
| int res = run_until<SwitchControllerContext>( | ||
| env.console, context, | ||
| [&](SwitchControllerContext& context) { | ||
| int ret = wait_until( | ||
| env.console, context, | ||
| std::chrono::seconds(20), | ||
| {{pooch_appeared}} | ||
| ); | ||
| if (ret == 0) { | ||
| env.log("Advance arrow detected."); | ||
| } | ||
| pbf_wait(context, 125); | ||
| context.wait_for_all_requests(); | ||
| }, | ||
| {{pooch_detector}} | ||
| ); | ||
| pooch_detector.throw_if_no_sound(); | ||
| if (res == 0){ | ||
| env.log("Shiny Poochyena detected!"); | ||
| stats.poochyena++; | ||
| env.update_stats(); | ||
| send_program_notification(env, NOTIFICATION_SHINY_POOCH, COLOR_YELLOW, "Shiny Poochyena found", {}, "", env.console.video().snapshot(), true); | ||
| } | ||
| else { | ||
| env.log("Poochyena is not shiny."); | ||
| } | ||
| context.wait_for_all_requests(); | ||
|
|
||
| float shiny_coefficient2 = 1.0; | ||
| ShinySoundDetector starter_detector(env.console, [&](float error_coefficient) -> bool{ | ||
| shiny_coefficient2 = error_coefficient; | ||
| return true; | ||
| }); | ||
|
|
||
| BattleMenuWatcher battle_menu(COLOR_RED); | ||
| int res2 = run_until<SwitchControllerContext>( | ||
| env.console, context, | ||
| [&](SwitchControllerContext& context) { | ||
| env.log("Sending out selected starter."); | ||
| pbf_press_button(context, BUTTON_A, 40, 40); | ||
|
|
||
| int ret = wait_until( | ||
| env.console, context, | ||
| std::chrono::seconds(20), | ||
| {{battle_menu}} | ||
| ); | ||
| if (ret == 0) { | ||
| env.log("Battle menu detecteed!"); | ||
| } | ||
| pbf_wait(context, 125); | ||
| context.wait_for_all_requests(); | ||
| }, | ||
| {{starter_detector}} | ||
| ); | ||
| starter_detector.throw_if_no_sound(); | ||
| context.wait_for_all_requests(); | ||
| if (res2 == 0){ | ||
| 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); | ||
| shiny_starter = true; | ||
| } | ||
| else { | ||
| env.log("Starter is not shiny."); | ||
| env.log("Soft resetting."); | ||
| send_program_status_notification( | ||
| env, NOTIFICATION_STATUS_UPDATE, | ||
| "Soft resetting." | ||
| ); | ||
| stats.resets++; | ||
| env.update_stats(); | ||
| soft_reset(env.program_info(), env.console, context); | ||
| } | ||
| } | ||
|
|
||
| //if system set to nintendo switch, have go home when done option? | ||
|
|
||
| send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH); | ||
| } | ||
|
|
||
| } | ||
| } | ||
| } | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these are tabs here? We use spaces for this project.