Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1824,6 +1824,8 @@ file(GLOB MAIN_SOURCES
Source/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.h
Source/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp
Source/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h
Source/PokemonSV/Programs/Farming/PokemonSV_ClaimMysteryGift.cpp
Source/PokemonSV/Programs/Farming/PokemonSV_ClaimMysteryGift.h
Source/PokemonSV/Programs/Farming/PokemonSV_ESPTraining.cpp
Source/PokemonSV/Programs/Farming/PokemonSV_ESPTraining.h
Source/PokemonSV/Programs/Farming/PokemonSV_FlyingTrialFarmer.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
#include "PokemonHome/Inference/PokemonHome_BallReader.h"
#include "PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_PathSide.h"
#include "PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_PathMap.h"
#include "NintendoSwitch/Inference/NintendoSwitch_SelectedSettingDetector.h"

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



#if 0
bool switch2 = true;
ImageFloatBox key1_box;
ImageFloatBox other_setting1;
ImageFloatBox other_setting2;

if (!switch2){
key1_box = {0.037322, 0.451172, 0.009879, 0.113281};
other_setting1 = {0.01, 0.451172, 0.009879, 0.113281};
other_setting2 = {0.02, 0.451172, 0.009879, 0.113281};
}else if (switch2){
key1_box = {0.062706, 0.510763, 0.009901, 0.097847};
other_setting1 = {0.02, 0.510763, 0.009901, 0.097847};
other_setting2 = {0.04, 0.510763, 0.009901, 0.097847};
}

SelectedSettingWatcher key1_selected(key1_box, other_setting1, other_setting2, other_setting1);
int ret = wait_until(
console, context,
Milliseconds(5000),
{key1_selected}
);
if (ret < 0){ // failed to detect Key 1 being highlighted. Reset game and re-try
console.log("claim_mystery_gift: Failed to detect the Mystery Gift window. Reset game and re-try.", COLOR_YELLOW);
reset_game(env.program_info(), console, context);
}

#endif

#if 0
auto screenshot = feed.snapshot();

Expand Down Expand Up @@ -342,7 +373,7 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
#endif


#if 1
#if 0
auto screenshot = feed.snapshot();

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

#if 1
#if 0
auto duration = 15ms;
for (size_t c = 0; c < 65536; c += 1){
context->issue_gyro_accel_x(&scope, 0s, duration, 0s, (uint16_t)(688 + 0*c % 2));
Expand Down Expand Up @@ -655,7 +686,7 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
#if 0
// ImageRGB32 image(IMAGE_PATH);
auto image = feed.snapshot();
#if 1
#if 0
ImageRGB32 image(IMAGE_PATH);
// auto image = feed.snapshot();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "CommonFramework/ImageTools/ImageStats.h"
#include "NintendoSwitch_ConsoleTypeDetector.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h"
#include "CommonFramework/VideoPipeline/VideoFeed.h"

//#include <iostream>
//using std::cout;
Expand Down Expand Up @@ -83,6 +86,17 @@ void ConsoleTypeDetector_StartGameUserSelect::commit_to_cache(){
m_console.state().set_console_type(m_console, m_last);
}

ConsoleType detect_console_type_from_in_game(ConsoleHandle& console, ProControllerContext& context){
go_home(console, context);

ConsoleTypeDetector_Home detector(console);
ConsoleType console_type = detector.detect_only(console.video().snapshot());
detector.commit_to_cache();

resume_game_from_home(console, context);

return console_type;
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ConsoleTypeDetector_StartGameUserSelect{
ConsoleType m_last;
};


ConsoleType detect_console_type_from_in_game(ConsoleHandle& console, ProControllerContext& context);



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include "NintendoSwitch_SelectedSettingDetector.h"

//
//#include <iostream>
//using std::cout;
//using std::endl;
// #include <iostream>
// using std::cout;
// using std::endl;

namespace PokemonAutomation{
namespace NintendoSwitch{
Expand All @@ -21,24 +21,26 @@ SelectedSettingWatcher::~SelectedSettingWatcher() = default;
SelectedSettingWatcher::SelectedSettingWatcher(
ImageFloatBox selected_box,
ImageFloatBox not_selected_box1,
ImageFloatBox not_selected_box2
ImageFloatBox not_selected_box2,
ImageFloatBox representative_background
)
: VisualInferenceCallback("SelectedSettingWatcher")
, m_selected_box(selected_box)
, m_not_selected_box1(not_selected_box1)
, m_not_selected_box2(not_selected_box2)
, m_representative_background(representative_background)
{}

void SelectedSettingWatcher::make_overlays(VideoOverlaySet& items) const{
items.add(COLOR_RED, m_selected_box);
items.add(COLOR_BLUE, m_not_selected_box1);
items.add(COLOR_BLUE, m_not_selected_box2);
items.add(COLOR_GREEN, m_representative_background);
}

bool is_white_theme(const ImageViewRGB32& screen){
ImageFloatBox window_top(0.60, 0.02, 0.35, 0.05);
ImageStats stats_window_top = image_stats(extract_box_reference(screen, window_top));
bool white_theme = stats_window_top.average.sum() > 500;
bool SelectedSettingWatcher::is_white_theme(const ImageViewRGB32& screen){
ImageStats stats_window_background = image_stats(extract_box_reference(screen, m_representative_background));
bool white_theme = stats_window_background.average.sum() > 500;
return white_theme;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ class SelectedSettingWatcher : public VisualInferenceCallback{
SelectedSettingWatcher(
ImageFloatBox selected_box,
ImageFloatBox not_selected_box1,
ImageFloatBox not_selected_box2
ImageFloatBox not_selected_box2,
ImageFloatBox representative_background = {0.60, 0.02, 0.35, 0.05}
);
virtual ~SelectedSettingWatcher();

virtual void make_overlays(VideoOverlaySet& items) const override;

bool is_white_theme(const ImageViewRGB32& screen);

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

Expand All @@ -38,6 +42,7 @@ class SelectedSettingWatcher : public VisualInferenceCallback{
ImageFloatBox m_selected_box;
ImageFloatBox m_not_selected_box1;
ImageFloatBox m_not_selected_box2;
ImageFloatBox m_representative_background;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "NintendoSwitch/NintendoSwitch_Settings.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
#include "NintendoSwitch/Options/NintendoSwitch_CodeEntrySettingsOption.h"
#include "NintendoSwitch/Inference/NintendoSwitch_ConsoleTypeDetector.h"
#include "NintendoSwitch_CodeEntryTools.h"
#include "NintendoSwitch_KeyboardCodeEntry.h"

Expand Down Expand Up @@ -285,6 +286,11 @@ void keyboard_enter_code(


ConsoleType console_type = console.state().console_type();

if (console_type == ConsoleType::Unknown){
console.log("Unknown Switch type. Try to detect.");
console_type = detect_console_type_from_in_game(console, context);
}
bool switch2;
if (is_switch1(console_type)){
switch2 = false;
Expand Down
2 changes: 2 additions & 0 deletions SerialPrograms/Source/PokemonSV/PokemonSV_Panels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "Programs/ShinyHunting/PokemonSV_ShinyHunt-Scatterbug.h"

#include "Programs/AutoStory/PokemonSV_AutoStory.h"
#include "Programs/Farming/PokemonSV_ClaimMysteryGift.h"

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

ret.emplace_back("---- Public Betas ----");
ret.emplace_back(make_single_switch_program<AutoStory_Descriptor, AutoStory>());
ret.emplace_back(make_single_switch_program<ClaimMysteryGift_Descriptor, ClaimMysteryGift>());

ret.emplace_back("---- Deprecated Programs ----");
ret.emplace_back(make_single_switch_program<AutoItemPrinter_Descriptor, AutoItemPrinter>());
Expand Down
Loading