Skip to content

Commit a4990e2

Browse files
authored
Merge pull request #666 from jw098/mysterygift
Claim Mystery Gift
2 parents 98c9dab + dddbfb1 commit a4990e2

File tree

64 files changed

+972
-428
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+972
-428
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,8 @@ file(GLOB MAIN_SOURCES
18241824
Source/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.h
18251825
Source/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp
18261826
Source/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h
1827+
Source/PokemonSV/Programs/Farming/PokemonSV_ClaimMysteryGift.cpp
1828+
Source/PokemonSV/Programs/Farming/PokemonSV_ClaimMysteryGift.h
18271829
Source/PokemonSV/Programs/Farming/PokemonSV_ESPTraining.cpp
18281830
Source/PokemonSV/Programs/Farming/PokemonSV_ESPTraining.h
18291831
Source/PokemonSV/Programs/Farming/PokemonSV_FlyingTrialFarmer.cpp

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
#include "PokemonHome/Inference/PokemonHome_BallReader.h"
139139
#include "PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_PathSide.h"
140140
#include "PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_PathMap.h"
141+
#include "NintendoSwitch/Inference/NintendoSwitch_SelectedSettingDetector.h"
141142

142143
#include <QPixmap>
143144
#include <QVideoFrame>
@@ -256,6 +257,36 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
256257
VideoOverlaySet overlays(overlay);
257258

258259

260+
261+
#if 0
262+
bool switch2 = true;
263+
ImageFloatBox key1_box;
264+
ImageFloatBox other_setting1;
265+
ImageFloatBox other_setting2;
266+
267+
if (!switch2){
268+
key1_box = {0.037322, 0.451172, 0.009879, 0.113281};
269+
other_setting1 = {0.01, 0.451172, 0.009879, 0.113281};
270+
other_setting2 = {0.02, 0.451172, 0.009879, 0.113281};
271+
}else if (switch2){
272+
key1_box = {0.062706, 0.510763, 0.009901, 0.097847};
273+
other_setting1 = {0.02, 0.510763, 0.009901, 0.097847};
274+
other_setting2 = {0.04, 0.510763, 0.009901, 0.097847};
275+
}
276+
277+
SelectedSettingWatcher key1_selected(key1_box, other_setting1, other_setting2, other_setting1);
278+
int ret = wait_until(
279+
console, context,
280+
Milliseconds(5000),
281+
{key1_selected}
282+
);
283+
if (ret < 0){ // failed to detect Key 1 being highlighted. Reset game and re-try
284+
console.log("claim_mystery_gift: Failed to detect the Mystery Gift window. Reset game and re-try.", COLOR_YELLOW);
285+
reset_game(env.program_info(), console, context);
286+
}
287+
288+
#endif
289+
259290
#if 0
260291
auto screenshot = feed.snapshot();
261292

@@ -342,7 +373,7 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
342373
#endif
343374

344375

345-
#if 1
376+
#if 0
346377
auto screenshot = feed.snapshot();
347378

348379
PokemonHome::BallReader reader(console);
@@ -607,7 +638,7 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
607638
// context->issue_gyro_rotate_x(&scope, duration, duration, 0s, 0x1000);
608639
// context->issue_nop(&scope, 60h);
609640

610-
#if 1
641+
#if 0
611642
auto duration = 15ms;
612643
for (size_t c = 0; c < 65536; c += 1){
613644
context->issue_gyro_accel_x(&scope, 0s, duration, 0s, (uint16_t)(688 + 0*c % 2));
@@ -655,7 +686,7 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
655686
#if 0
656687
// ImageRGB32 image(IMAGE_PATH);
657688
auto image = feed.snapshot();
658-
#if 1
689+
#if 0
659690
ImageRGB32 image(IMAGE_PATH);
660691
// auto image = feed.snapshot();
661692

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_ConsoleTypeDetector.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
88
#include "CommonFramework/ImageTools/ImageStats.h"
99
#include "NintendoSwitch_ConsoleTypeDetector.h"
10+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
11+
#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h"
12+
#include "CommonFramework/VideoPipeline/VideoFeed.h"
1013

1114
//#include <iostream>
1215
//using std::cout;
@@ -83,6 +86,17 @@ void ConsoleTypeDetector_StartGameUserSelect::commit_to_cache(){
8386
m_console.state().set_console_type(m_console, m_last);
8487
}
8588

89+
ConsoleType detect_console_type_from_in_game(ConsoleHandle& console, ProControllerContext& context){
90+
go_home(console, context);
91+
92+
ConsoleTypeDetector_Home detector(console);
93+
ConsoleType console_type = detector.detect_only(console.video().snapshot());
94+
detector.commit_to_cache();
95+
96+
resume_game_from_home(console, context);
97+
98+
return console_type;
99+
}
86100

87101

88102

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_ConsoleTypeDetector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ConsoleTypeDetector_StartGameUserSelect{
4949
ConsoleType m_last;
5050
};
5151

52-
52+
ConsoleType detect_console_type_from_in_game(ConsoleHandle& console, ProControllerContext& context);
5353

5454

5555

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_SelectedSettingDetector.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
#include "NintendoSwitch_SelectedSettingDetector.h"
1010

1111
//
12-
//#include <iostream>
13-
//using std::cout;
14-
//using std::endl;
12+
// #include <iostream>
13+
// using std::cout;
14+
// using std::endl;
1515

1616
namespace PokemonAutomation{
1717
namespace NintendoSwitch{
@@ -21,24 +21,26 @@ SelectedSettingWatcher::~SelectedSettingWatcher() = default;
2121
SelectedSettingWatcher::SelectedSettingWatcher(
2222
ImageFloatBox selected_box,
2323
ImageFloatBox not_selected_box1,
24-
ImageFloatBox not_selected_box2
24+
ImageFloatBox not_selected_box2,
25+
ImageFloatBox representative_background
2526
)
2627
: VisualInferenceCallback("SelectedSettingWatcher")
2728
, m_selected_box(selected_box)
2829
, m_not_selected_box1(not_selected_box1)
2930
, m_not_selected_box2(not_selected_box2)
31+
, m_representative_background(representative_background)
3032
{}
3133

3234
void SelectedSettingWatcher::make_overlays(VideoOverlaySet& items) const{
3335
items.add(COLOR_RED, m_selected_box);
3436
items.add(COLOR_BLUE, m_not_selected_box1);
3537
items.add(COLOR_BLUE, m_not_selected_box2);
38+
items.add(COLOR_GREEN, m_representative_background);
3639
}
3740

38-
bool is_white_theme(const ImageViewRGB32& screen){
39-
ImageFloatBox window_top(0.60, 0.02, 0.35, 0.05);
40-
ImageStats stats_window_top = image_stats(extract_box_reference(screen, window_top));
41-
bool white_theme = stats_window_top.average.sum() > 500;
41+
bool SelectedSettingWatcher::is_white_theme(const ImageViewRGB32& screen){
42+
ImageStats stats_window_background = image_stats(extract_box_reference(screen, m_representative_background));
43+
bool white_theme = stats_window_background.average.sum() > 500;
4244
return white_theme;
4345
}
4446

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_SelectedSettingDetector.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,20 @@ class SelectedSettingWatcher : public VisualInferenceCallback{
2020
SelectedSettingWatcher(
2121
ImageFloatBox selected_box,
2222
ImageFloatBox not_selected_box1,
23-
ImageFloatBox not_selected_box2
23+
ImageFloatBox not_selected_box2,
24+
ImageFloatBox representative_background = {0.60, 0.02, 0.35, 0.05}
2425
);
2526
virtual ~SelectedSettingWatcher();
2627

2728
virtual void make_overlays(VideoOverlaySet& items) const override;
2829

30+
bool is_white_theme(const ImageViewRGB32& screen);
31+
2932
// return true if the area within the selected_box is highlighted, compared with the area within unselected_box
3033
// This compares the brightness of the selected_box with the unselected_box.
3134
// selected_box: the box where we expect the screen should be highlighted
3235
// not_selected_box 1 and 2: the boxes where we expect the screen should NOT be highlighted. These acts as the control, for comparison.
36+
// representative_background: box around an area that would represent the background. for determining whether this is white or dark mode.
3337
// the average sum of selected_box should be greater than the absolute difference of average sum between unselected_box 1 and 2.
3438
virtual bool process_frame(const ImageViewRGB32& screen, WallClock timestamp) override;
3539

@@ -38,6 +42,7 @@ class SelectedSettingWatcher : public VisualInferenceCallback{
3842
ImageFloatBox m_selected_box;
3943
ImageFloatBox m_not_selected_box1;
4044
ImageFloatBox m_not_selected_box2;
45+
ImageFloatBox m_representative_background;
4146
};
4247

4348

SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardCodeEntry.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "NintendoSwitch/NintendoSwitch_Settings.h"
1111
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
1212
#include "NintendoSwitch/Options/NintendoSwitch_CodeEntrySettingsOption.h"
13+
#include "NintendoSwitch/Inference/NintendoSwitch_ConsoleTypeDetector.h"
1314
#include "NintendoSwitch_CodeEntryTools.h"
1415
#include "NintendoSwitch_KeyboardCodeEntry.h"
1516

@@ -285,6 +286,11 @@ void keyboard_enter_code(
285286

286287

287288
ConsoleType console_type = console.state().console_type();
289+
290+
if (console_type == ConsoleType::Unknown){
291+
console.log("Unknown Switch type. Try to detect.");
292+
console_type = detect_console_type_from_in_game(console, context);
293+
}
288294
bool switch2;
289295
if (is_switch1(console_type)){
290296
switch2 = false;

SerialPrograms/Source/PokemonSV/PokemonSV_Panels.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "Programs/ShinyHunting/PokemonSV_ShinyHunt-Scatterbug.h"
5454

5555
#include "Programs/AutoStory/PokemonSV_AutoStory.h"
56+
#include "Programs/Farming/PokemonSV_ClaimMysteryGift.h"
5657

5758
#include "Programs/Glitches/PokemonSV_WildItemFarmer.h"
5859
#include "Programs/Glitches/PokemonSV_RideCloner-1.0.1.h"
@@ -146,6 +147,7 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
146147

147148
ret.emplace_back("---- Public Betas ----");
148149
ret.emplace_back(make_single_switch_program<AutoStory_Descriptor, AutoStory>());
150+
ret.emplace_back(make_single_switch_program<ClaimMysteryGift_Descriptor, ClaimMysteryGift>());
149151

150152
ret.emplace_back("---- Deprecated Programs ----");
151153
ret.emplace_back(make_single_switch_program<AutoItemPrinter_Descriptor, AutoItemPrinter>());

0 commit comments

Comments
 (0)