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
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* Load Menu Detector
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "CommonTools/Images/SolidColorTest.h"
#include "CommonTools/Images/ImageFilter.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "CommonFramework/ImageTypes/ImageRGB32.h"
#include "CommonFramework/ImageTools/ImageStats.h"
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "CommonTools/Images/SolidColorTest.h"
#include "CommonTools/Images/WaterfillUtilities.h"
#include "CommonTools/ImageMatch/WaterfillTemplateMatcher.h"
#include "CommonFramework/VideoPipeline/VideoOverlay.h"
#include "PokemonFRLG_LoadMenuDetector.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{

LoadMenuDetector::LoadMenuDetector(Color color)
: m_right_box(0.859, 0.023, 0.042, 0.925)
, m_left_box(0.099, 0.022, 0.046, 0.926)
, m_save_box(0.773, 0.062, 0.047, 0.072)
{}
void LoadMenuDetector::make_overlays(VideoOverlaySet& items) const{
items.add(COLOR_BLUE, m_right_box);
items.add(COLOR_BLUE, m_left_box);
items.add(COLOR_BLUE, m_save_box);
}
bool LoadMenuDetector::detect(const ImageViewRGB32& screen){
ImageViewRGB32 right_image = extract_box_reference(screen, m_right_box);
ImageViewRGB32 left_image = extract_box_reference(screen, m_left_box);
ImageViewRGB32 save_image = extract_box_reference(screen, m_save_box);

if (is_solid(right_image, { 0.244, 0.282, 0.474 }) //blue
&& is_solid(left_image, { 0.244, 0.282, 0.474 }) //blue
&& is_solid(save_image, { 0.25, 0.38, 0.369 }) //white
){
return true;
}
return false;
}


}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* Load Menu Detector
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonFRLG_LoadMenuDetector_H
#define PokemonAutomation_PokemonFRLG_LoadMenuDetector_H

#include <chrono>
#include <atomic>
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "Common/Cpp/Color.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "CommonTools/VisualDetector.h"
#include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h"

namespace PokemonAutomation{
class CancellableScope;
class VideoFeed;
namespace NintendoSwitch{
namespace PokemonFRLG{

// Detect save load menu by looking for the blue on the sides and the white of the save file
// Untested on new game, assumes there's a save.
class LoadMenuDetector : public StaticScreenDetector{
public:
LoadMenuDetector(Color color);

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

private:
ImageFloatBox m_right_box;
ImageFloatBox m_left_box;
ImageFloatBox m_save_box;
};
class LoadMenuWatcher : public DetectorToFinder<LoadMenuDetector>{
public:
LoadMenuWatcher(Color color)
: DetectorToFinder("LoadMenuWatcher", std::chrono::milliseconds(250), color)
{}
};


}
}
}

#endif
10 changes: 7 additions & 3 deletions SerialPrograms/Source/PokemonFRLG/PokemonFRLG_Navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h"
#include "PokemonFRLG/Inference/Sounds/PokemonFRLG_ShinySoundDetector.h"
#include "PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.h"
#include "PokemonFRLG/Inference/Menus/PokemonFRLG_LoadMenuDetector.h"
#include "PokemonFRLG/PokemonFRLG_Settings.h"
#include "PokemonFRLG_Navigation.h"

Expand All @@ -40,6 +41,7 @@ void soft_reset(ConsoleHandle& console, ProControllerContext& context){

//Mash A until white screen to game load menu
WhiteScreenOverWatcher whitescreen(COLOR_RED, {0.282, 0.064, 0.448, 0.871});
LoadMenuWatcher load_menu(COLOR_BLUE);

int ls = run_until<ProControllerContext>(
console, context,
Expand All @@ -48,11 +50,13 @@ void soft_reset(ConsoleHandle& console, ProControllerContext& context){
pbf_wait(context, 5000ms);
context.wait_for_all_requests();
},
{ whitescreen }
{ whitescreen, load_menu }
);
context.wait_for_all_requests();
if (ls == 0){
console.log("Entered load menu.");
if (ls == 0) {
console.log("Entered load menu. (WhiteScreenOver)");
}else if (ls == 1) {
console.log("Entered load menu. (LoadMenu)");
}else{
console.log("Unable to enter load menu.", COLOR_RED);
OperationFailedException::fire(
Expand Down
2 changes: 2 additions & 0 deletions SerialPrograms/cmake/SourceFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,8 @@ file(GLOB LIBRARY_SOURCES
Source/PokemonFRLG/Inference/Dialogs/PokemonFRLG_PrizeSelectDetector.h
Source/PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.cpp
Source/PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.h
Source/PokemonFRLG/Inference/Menus/PokemonFRLG_LoadMenuDetector.cpp
Source/PokemonFRLG/Inference/Menus/PokemonFRLG_LoadMenuDetector.h
Source/PokemonFRLG/Inference/Sounds/PokemonFRLG_ShinySoundDetector.cpp
Source/PokemonFRLG/Inference/Sounds/PokemonFRLG_ShinySoundDetector.h
Source/PokemonFRLG/Inference/PokemonFRLG_ShinySymbolDetector.cpp
Expand Down
Loading