Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1319,8 +1319,14 @@ file(GLOB MAIN_SOURCES
Source/PokemonRSE/Inference/Sounds/PokemonRSE_ShinySoundDetector.h
Source/PokemonRSE/Inference/PokemonRSE_ShinyNumberDetector.cpp
Source/PokemonRSE/Inference/PokemonRSE_ShinyNumberDetector.h
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_AudioStarterReset.cpp
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_AudioStarterReset.h
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_StarterReset.cpp
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_StarterReset.h
Source/PokemonRSE/Programs/TestPrograms/PokemonRSE_SoundListener.cpp
Source/PokemonRSE/Programs/TestPrograms/PokemonRSE_SoundListener.h
Source/PokemonRSE/PokemonRSE_Navigation.cpp
Source/PokemonRSE/PokemonRSE_Navigation.h
Source/PokemonRSE/PokemonRSE_Panels.cpp
Source/PokemonRSE/PokemonRSE_Panels.h
Source/PokemonRSE/PokemonRSE_Settings.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "NintendoSwitch/Controllers/NintendoSwitch_Controller.h"
#include "NintendoSwitch_SingleSwitchProgramOption.h"
#include "NintendoSwitch_SingleSwitchProgramSession.h"
#include "Pokemon/Pokemon_Strings.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
Expand Down Expand Up @@ -61,7 +62,10 @@ void SingleSwitchProgramSession::run_program_instance(SingleSwitchProgramEnviron
// Startup Checks
m_option.instance().start_program_controller_check(scope, m_system.controller_session());
m_option.instance().start_program_feedback_check(scope, env.console, m_option.descriptor().feedback());
m_option.instance().start_program_border_check(scope, env.console);
if (m_option.descriptor().category() != Pokemon::STRING_POKEMON + " RSE"
&& m_option.descriptor().category() != Pokemon::STRING_POKEMON + " FRLG"){
m_option.instance().start_program_border_check(scope, env.console);
}

m_scope.store(&scope, std::memory_order_release);

Expand Down
54 changes: 54 additions & 0 deletions SerialPrograms/Source/PokemonRSE/PokemonRSE_Navigation.cpp
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);
Copy link
Collaborator

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.


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();
}


}
}
}
29 changes: 29 additions & 0 deletions SerialPrograms/Source/PokemonRSE/PokemonRSE_Navigation.h
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
8 changes: 4 additions & 4 deletions SerialPrograms/Source/PokemonRSE/PokemonRSE_Panels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#include "PokemonRSE_Settings.h"

//#include "Programs/ShinyHunting/PokemonRSE_AudioStarterReset.h"
//#include "Programs/ShinyHunting/PokemonRSE_StarterReset.h"
#include "Programs/ShinyHunting/PokemonRSE_AudioStarterReset.h"
#include "Programs/ShinyHunting/PokemonRSE_StarterReset.h"
#include "Programs/TestPrograms/PokemonRSE_SoundListener.h"

namespace PokemonAutomation{
Expand All @@ -33,12 +33,12 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
//ret.emplace_back("---- General ----");

ret.emplace_back("---- Shiny Hunting ----");
//ret.emplace_back(make_single_switch_program<AudioStarterReset_Descriptor, AudioStarterReset>());
ret.emplace_back(make_single_switch_program<AudioStarterReset_Descriptor, AudioStarterReset>());


if (PreloadSettings::instance().DEVELOPER_MODE){
ret.emplace_back("---- Test ----");
//ret.emplace_back(make_single_switch_program<StarterReset_Descriptor, StarterReset>()); //outdated early test program
ret.emplace_back(make_single_switch_program<StarterReset_Descriptor, StarterReset>()); //outdated early test program

ret.emplace_back("---- Developer Tools ----");
ret.emplace_back(make_single_switch_program<SoundListener_Descriptor, SoundListener>());
Expand Down
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);
}

}
}
}

Loading