Skip to content
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

ruby/sapphire starter reset #525

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
20 changes: 20 additions & 0 deletions SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ file(GLOB MAIN_SOURCES
Source/CommonFramework/Inference/AudioTemplateCache.h
Source/CommonFramework/Inference/BlackBorderDetector.cpp
Source/CommonFramework/Inference/BlackBorderDetector.h
Source/CommonFramework/Inference/BlackBorderGBADetector.cpp
Source/CommonFramework/Inference/BlackBorderGBADetector.h
Source/CommonFramework/Inference/BlackScreenDetector.cpp
Source/CommonFramework/Inference/BlackScreenDetector.h
Source/CommonFramework/Inference/DetectionDebouncer.h
Expand Down Expand Up @@ -1291,6 +1293,24 @@ file(GLOB MAIN_SOURCES
Source/PokemonLA/Resources/PokemonLA_PokemonSprites.h
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.cpp
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.h
Source/PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.cpp
Source/PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.h
Source/PokemonRSE/Inference/Sounds/PokemonRSE_ShinySoundDetector.cpp
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
Source/PokemonRSE/PokemonRSE_Settings.h
Source/PokemonSV/Inference/Battles/PokemonSV_BattleBallReader.cpp
Source/PokemonSV/Inference/Battles/PokemonSV_BattleBallReader.h
Source/PokemonSV/Inference/Battles/PokemonSV_EncounterWatcher.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const std::set<std::string> TOKENS{
"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08", // jw's token.
"e8d168bc482e96553ea9f9ecaea5a817474dbccc2a6a228a6bde67f2b2aa2889", // James' token.
"7555b7c63481cad42306718c67e7f9def5bfd1da8f6cd299ccd3d7dc95f307ae", // Kuro's token.
"3d475b46d121fc24559d100de2426feaa53cd6578aac2817c4857a610ccde2dd", // kichi's token.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to pull this out into a separate PR so it can go in earlier.

};


Expand Down
1 change: 1 addition & 0 deletions SerialPrograms/Source/CommonFramework/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ enum class FeedbackType{
OPTIONAL_, // Naming conflict with macro.
REQUIRED,
VIDEO_AUDIO,
VIDEO_AUDIO_GBA,
};


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* Black Border Detector
*
* From: https://github.com/PokemonAutomation/Arduino-Source
*
*/

#include "CommonFramework/ImageTools/ImageStats.h"
#include "CommonFramework/ImageTools/SolidColorTest.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "BlackBorderGBADetector.h"

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

namespace PokemonAutomation{


BlackBorderGBADetector::BlackBorderGBADetector()
: m_top(0.126, 0.055, 0.748, 0.006)
, m_bottom(0.124, 0.940, 0.751, 0.004)
, m_left(0.126, 0.055, 0.002, 0.888)
, m_right(0.871, 0.055, 0.003, 0.888)
// , m_body(0.100, 0.100, 0.800, 0.800)
{}

void BlackBorderGBADetector::make_overlays(VideoOverlaySet& items) const{
items.add(COLOR_RED, m_top);
items.add(COLOR_RED, m_bottom);
items.add(COLOR_RED, m_left);
items.add(COLOR_RED, m_right);
// items.add(COLOR_RED, m_body);
}
bool BlackBorderGBADetector::detect(const ImageViewRGB32& screen) const{
const double MAX_SUM = 50;
const double MAX_STDDEV = 20;

ImageStats top = image_stats(extract_box_reference(screen, m_top));
// cout << "top = " << top.average << top.stddev << endl;
// extract_box(screen, m_top).save("top.png");
if (!is_black(top, MAX_SUM, MAX_STDDEV)){
return false;
}
ImageStats bottom = image_stats(extract_box_reference(screen, m_bottom));
// cout << "bottom = " << bottom.average << bottom.stddev << endl;
if (!is_black(bottom, MAX_SUM, MAX_STDDEV)){
return false;
}
ImageStats left = image_stats(extract_box_reference(screen, m_left));
// cout << "left = " << left.average << left.stddev << endl;
if (!is_black(left, MAX_SUM, MAX_STDDEV)){
return false;
}
ImageStats right = image_stats(extract_box_reference(screen, m_right));
// cout << "right = " << right.average << right.stddev << endl;
if (!is_black(right, MAX_SUM, MAX_STDDEV)){
return false;
}
// ImageStats body = image_stats(extract_box_reference(screen, m_body));
// cout << "body = " << body.average << body.stddev << endl;
// if (is_black(right, 30, 30)){
// return false;
// }


// for (int c = 0; c < screen.width(); c++){
// QRgb pixel = screen.pixel(c, 0);
// cout << "(" << qRed(pixel) << "," << qGreen(pixel) << "," << qBlue(pixel) << ")";
// }

return true;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* Black Screen Detector
*
* From: https://github.com/PokemonAutomation/Arduino-Source
*
*/

#ifndef PokemonAutomation_CommonFramework_BlackBorderGBADetector_H
#define PokemonAutomation_CommonFramework_BlackBorderGBADetector_H

#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "CommonFramework/Inference/VisualDetector.h"

namespace PokemonAutomation{


class BlackBorderGBADetector : public StaticScreenDetector{
public:
BlackBorderGBADetector();

virtual void make_overlays(VideoOverlaySet& items) const override;
virtual bool detect(const ImageViewRGB32& screen) const override;

private:
ImageFloatBox m_top;
ImageFloatBox m_bottom;
ImageFloatBox m_left;
ImageFloatBox m_right;
// ImageFloatBox m_body;
};



}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ CollapsibleGroupBox* make_panel_header(
);
break;
case FeedbackType::VIDEO_AUDIO:
case FeedbackType::VIDEO_AUDIO_GBA:
text = new QLabel(
"<font color=\"green\">(This program requires video and audio feedback. Please make sure you choose the correct capture device, as well as the correct audio device.)</font>",
header
Expand Down
24 changes: 18 additions & 6 deletions SerialPrograms/Source/CommonFramework/Tools/BlackBorderCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "CommonFramework/Tools/ConsoleHandle.h"
#include "CommonFramework/Inference/BlackBorderDetector.h"
#include "CommonFramework/Inference/BlackBorderGBADetector.h"
#include "BlackBorderCheck.h"

namespace PokemonAutomation{
Expand All @@ -23,18 +24,29 @@ void start_program_video_check(ConsoleHandle& console, FeedbackType feedback){
VideoSnapshot screen = console.video().snapshot();

if (!screen){
if (feedback == FeedbackType::REQUIRED || feedback == FeedbackType::VIDEO_AUDIO){
if (feedback == FeedbackType::REQUIRED || feedback == FeedbackType::VIDEO_AUDIO || feedback == FeedbackType::VIDEO_AUDIO_GBA){
throw UserSetupError(console, "This program requires video feedback. Please make sure the video is working.");
}
return;
}

BlackBorderDetector detector;
VideoOverlaySet set(console);
detector.make_overlays(set);
if (feedback != FeedbackType::VIDEO_AUDIO_GBA) { //GB, GBC in fullscreen will reach the top and bottom of the screen
BlackBorderDetector detector;
VideoOverlaySet set(console);
detector.make_overlays(set);

if (detector.detect(screen)){
throw UserSetupError(console, "Black border detected! Please set your screen size to 100% in the TV Settings on your Nintendo Switch.");
if (detector.detect(screen)) {
throw UserSetupError(console, "Black border detected! Please set your screen size to 100% in the TV Settings on your Nintendo Switch.");
}
}
else {
BlackBorderGBADetector detector;
VideoOverlaySet set(console);
detector.make_overlays(set);

if (detector.detect(screen)) {
throw UserSetupError(console, "Black border detected! Please set your screen size to 100% in the TV Settings on your Nintendo Switch.");
}
}
}
void start_program_video_check(FixedLimitVector<ConsoleHandle>& consoles, FeedbackType feedback){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ Color pick_color(FeedbackType feedback, PABotBaseLevel size){
case PABotBaseLevel::PABOTBASE_12KB:
if (feedback == FeedbackType::REQUIRED){
return COLOR_DARKGREEN;
}else if (feedback == FeedbackType::VIDEO_AUDIO){
}else if (feedback == FeedbackType::VIDEO_AUDIO || feedback == FeedbackType::VIDEO_AUDIO_GBA){
return COLOR_GREEN2;
}else{
return COLOR_BLUE;
}
case PABotBaseLevel::PABOTBASE_31KB:
return (feedback == FeedbackType::REQUIRED || feedback == FeedbackType::VIDEO_AUDIO) ? COLOR_PURPLE : COLOR_RED;
return (feedback == FeedbackType::REQUIRED || feedback == FeedbackType::VIDEO_AUDIO || feedback == FeedbackType::VIDEO_AUDIO_GBA) ? COLOR_PURPLE : COLOR_RED;
}
return Color();
}
Expand Down
5 changes: 5 additions & 0 deletions SerialPrograms/Source/PanelLists.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
#include "CommonFramework/PersistentSettings.h"
#include "CommonFramework/Windows/DpiScaler.h"
#include "CommonFramework/Panels/UI/PanelListWidget.h"
#include "CommonFramework/GlobalSettingsPanel.h"
#include "NintendoSwitch/NintendoSwitch_Panels.h"
#include "PokemonSwSh/PokemonSwSh_Panels.h"
#include "PokemonHome/PokemonHome_Panels.h"
#include "PokemonBDSP/PokemonBDSP_Panels.h"
#include "PokemonLA/PokemonLA_Panels.h"
#include "PokemonRSE/PokemonRSE_Panels.h"
#include "PokemonSV/PokemonSV_Panels.h"
#include "ZeldaTotK/ZeldaTotK_Panels.h"
#include "PanelLists.h"
Expand Down Expand Up @@ -47,6 +49,9 @@ ProgramSelect::ProgramSelect(QWidget& parent, PanelHolder& holder)
add(std::make_unique<NintendoSwitch::PokemonBDSP::PanelListFactory>());
add(std::make_unique<NintendoSwitch::PokemonLA::PanelListFactory>());
add(std::make_unique<NintendoSwitch::PokemonSV::PanelListFactory>());
if (PreloadSettings::instance().DEVELOPER_MODE) {
add(std::make_unique<NintendoSwitch::PokemonRSE::PanelListFactory>());
}
add(std::make_unique<NintendoSwitch::ZeldaTotK::PanelListFactory>());


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/* Dialog Detector
*
* From: https://github.com/PokemonAutomation/Arduino-Source
*
*/

#include "CommonFramework/ImageTools/SolidColorTest.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "CommonFramework/ImageTools/ImageFilter.h"
#include "CommonFramework/ImageTypes/ImageRGB32.h"
#include "CommonFramework/ImageTools/ImageStats.h"
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "PokemonRSE_DialogDetector.h"

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

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonRSE{

/*
DialogDetector::DialogDetector(Color color)
: m_left_box(0.155, 0.727, 0.015, 0.168)
, m_right_box(0.837, 0.729, 0.008, 0.161)
{}
void DialogDetector::make_overlays(VideoOverlaySet& items) const{
items.add(COLOR_RED, m_left_box);
items.add(COLOR_RED, m_right_box);
}
bool DialogDetector::detect(const ImageViewRGB32& screen) const{
ImageViewRGB32 left_image = extract_box_reference(screen, m_left_box);
ImageViewRGB32 right_image = extract_box_reference(screen, m_right_box);
if (is_solid(left_image, { 0.335, 0.331, 0.332 }) && is_solid(right_image, { 0.335, 0.331, 0.332 })){
return true;
}
return false;
}
*/

BattleDialogDetector::BattleDialogDetector(Color color)
: m_left_box(0.158, 0.725, 0.011, 0.176)
, m_right_box(0.827, 0.722, 0.013, 0.178)
{}
void BattleDialogDetector::make_overlays(VideoOverlaySet& items) const{
items.add(COLOR_RED, m_left_box);
items.add(COLOR_RED, m_right_box);
}
bool BattleDialogDetector::detect(const ImageViewRGB32& screen) const{
ImageViewRGB32 left_image = extract_box_reference(screen, m_left_box);
ImageViewRGB32 right_image = extract_box_reference(screen, m_right_box);
if (is_solid(left_image, { 0.335, 0.331, 0.332 }) && is_solid(right_image, { 0.335, 0.331, 0.332 })){
return true;
}
return false;
}


BattleMenuDetector::BattleMenuDetector(Color color)
: m_left_box(0.439, 0.717, 0.021, 0.192)
, m_right_box(0.821, 0.725, 0.030, 0.181)
{}
void BattleMenuDetector::make_overlays(VideoOverlaySet& items) const{
items.add(COLOR_RED, m_left_box);
items.add(COLOR_RED, m_right_box);
}
bool BattleMenuDetector::detect(const ImageViewRGB32& screen) const{
ImageViewRGB32 left_image = extract_box_reference(screen, m_left_box);
ImageViewRGB32 right_image = extract_box_reference(screen, m_right_box);
if (is_solid(left_image, { 0.335, 0.331, 0.332 }) && is_solid(right_image, { 0.25, 0.38, 0.369 })){
return true;
}
return false;
}


AdvanceDialogDetector::AdvanceDialogDetector(Color color)
: m_dialog_box(0.156, 0.715, 0.686, 0.193)
{}
void AdvanceDialogDetector::make_overlays(VideoOverlaySet& items) const{
items.add(COLOR_RED, m_dialog_box);
}
bool AdvanceDialogDetector::detect(const ImageViewRGB32& screen) const{
const bool replace_color_within_range = false;

//Filter out background
ImageRGB32 filtered_region = filter_rgb32_range(
extract_box_reference(screen, m_dialog_box),
combine_rgb(185, 0, 1), combine_rgb(255, 32, 33), Color(0), replace_color_within_range
);
ImageStats stats = image_stats(filtered_region);

/*
filtered_region.save("./filtered_only.png");
cout << stats.average.r << endl;
cout << stats.average.g << endl;
cout << stats.average.b << endl;
*/

if ((stats.average.r > stats.average.b + 200) && (stats.average.r > stats.average.g + 200)){
return true;
}
return false;
}



}
}
}
Loading