Skip to content

Commit f27f31e

Browse files
committed
nav and outdated test reset program
1 parent 28dfc83 commit f27f31e

File tree

4 files changed

+343
-0
lines changed

4 files changed

+343
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* Pokemon RSE Navigation
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
* Soft reset, menus, etc.
6+
*
7+
*/
8+
9+
#include "CommonFramework/Exceptions/OperationFailedException.h"
10+
#include "CommonTools/Async/InferenceRoutines.h"
11+
#include "CommonTools/VisualDetectors/BlackScreenDetector.h"
12+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
13+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
14+
#include "PokemonRSE/PokemonRSE_Settings.h"
15+
#include "PokemonRSE_Navigation.h"
16+
17+
namespace PokemonAutomation{
18+
namespace NintendoSwitch{
19+
namespace PokemonRSE{
20+
21+
22+
void soft_reset(const ProgramInfo& info, VideoStream& stream, SwitchControllerContext& context){
23+
// A + B + Select + Start
24+
pbf_press_button(context, BUTTON_B | BUTTON_Y | BUTTON_MINUS | BUTTON_PLUS, 10, 180);
25+
26+
pbf_mash_button(context, BUTTON_PLUS, GameSettings::instance().START_BUTTON_MASH);
27+
context.wait_for_all_requests();
28+
29+
pbf_press_button(context, BUTTON_A, 20, 40);
30+
31+
//Wait for game to load in
32+
BlackScreenOverWatcher detector(COLOR_RED, {0.282, 0.064, 0.448, 0.871});
33+
int ret = wait_until(
34+
stream, context,
35+
std::chrono::milliseconds(GameSettings::instance().ENTER_GAME_WAIT * (1000 / TICKS_PER_SECOND)),
36+
{{detector}}
37+
);
38+
if (ret == 0){
39+
stream.log("Entered game!");
40+
}else{
41+
stream.log("Timed out waiting to enter game.", COLOR_RED);
42+
OperationFailedException::fire(
43+
ErrorReport::SEND_ERROR_REPORT,
44+
"soft_reset(): Timed out waiting to enter game.",
45+
stream
46+
);
47+
}
48+
context.wait_for_all_requests();
49+
}
50+
51+
52+
}
53+
}
54+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* Pokemon RSE Navigation
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
* Soft reset, menus, etc.
6+
*
7+
*/
8+
9+
#ifndef PokemonAutomation_PokemonRSE_Navigation_H
10+
#define PokemonAutomation_PokemonRSE_Navigation_H
11+
12+
#include "CommonFramework/Tools/VideoStream.h"
13+
#include "Common/NintendoSwitch/NintendoSwitch_ControllerDefs.h"
14+
#include "NintendoSwitch/Controllers/NintendoSwitch_Controller.h"
15+
16+
namespace PokemonAutomation{
17+
struct ProgramInfo;
18+
namespace NintendoSwitch{
19+
namespace PokemonRSE{
20+
21+
// Press A+B+Select+Start at the same time to soft reset, then re-enters the game.
22+
// For now this assumes no dry battery.
23+
void soft_reset(const ProgramInfo& info, VideoStream& stream, SwitchControllerContext &context);
24+
25+
26+
}
27+
}
28+
}
29+
#endif
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
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+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/* RS Starter Reset
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonRSE_StarterReset_H
8+
#define PokemonAutomation_PokemonRSE_StarterReset_H
9+
10+
#include "Common/Cpp/Options/SimpleIntegerOption.h"
11+
#include "Common/Cpp/Options/TimeExpressionOption.h"
12+
#include "CommonFramework/Notifications/EventNotificationsTable.h"
13+
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
14+
15+
namespace PokemonAutomation{
16+
namespace NintendoSwitch{
17+
namespace PokemonRSE{
18+
19+
class StarterReset_Descriptor : public SingleSwitchProgramDescriptor{
20+
public:
21+
StarterReset_Descriptor();
22+
struct Stats;
23+
virtual std::unique_ptr<StatsTracker> make_stats() const override;
24+
};
25+
26+
class StarterReset : public SingleSwitchProgramInstance{
27+
public:
28+
StarterReset();
29+
virtual void program(SingleSwitchProgramEnvironment& env, SwitchControllerContext &context) override;
30+
31+
private:
32+
enum class Target{
33+
treecko,
34+
torchic,
35+
mudkip,
36+
};
37+
EnumDropdownOption<Target> TARGET;
38+
39+
TimeExpressionOption<uint16_t> STARTER_WAIT;
40+
41+
EventNotificationOption NOTIFICATION_SHINY_STARTER;
42+
EventNotificationOption NOTIFICATION_STATUS_UPDATE;
43+
EventNotificationsOption NOTIFICATIONS;
44+
};
45+
46+
}
47+
}
48+
}
49+
#endif
50+
51+
52+

0 commit comments

Comments
 (0)