From 402bb0b22793f078a62ce37ba1ecf9c951848a0c Mon Sep 17 00:00:00 2001 From: Mysticial Date: Thu, 5 Oct 2023 12:30:36 -0700 Subject: [PATCH] Report error with screenshot when failing to read stats. --- .../Exceptions/ScreenshotException.cpp | 3 +++ .../Exceptions/ScreenshotException.h | 2 ++ .../DevPrograms/TestProgramComputer.cpp | 13 ++++++++++--- .../Inference/PokemonSV_StatHexagonReader.cpp | 12 ++++++++++-- .../General/PokemonSV_StatsResetBloodmoon.cpp | 19 +++++++++++++++---- 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/SerialPrograms/Source/CommonFramework/Exceptions/ScreenshotException.cpp b/SerialPrograms/Source/CommonFramework/Exceptions/ScreenshotException.cpp index 721da84e7..56fd10ff9 100644 --- a/SerialPrograms/Source/CommonFramework/Exceptions/ScreenshotException.cpp +++ b/SerialPrograms/Source/CommonFramework/Exceptions/ScreenshotException.cpp @@ -32,6 +32,9 @@ ScreenshotException::ScreenshotException(ErrorReport error_report, ConsoleHandle } } } +void ScreenshotException::attach_screenshot(std::shared_ptr screenshot){ + m_screenshot = std::move(screenshot); +} ImageViewRGB32 ScreenshotException::screenshot() const{ if (m_screenshot){ return *m_screenshot; diff --git a/SerialPrograms/Source/CommonFramework/Exceptions/ScreenshotException.h b/SerialPrograms/Source/CommonFramework/Exceptions/ScreenshotException.h index 815bd65bf..37f7697e8 100644 --- a/SerialPrograms/Source/CommonFramework/Exceptions/ScreenshotException.h +++ b/SerialPrograms/Source/CommonFramework/Exceptions/ScreenshotException.h @@ -35,6 +35,8 @@ class ScreenshotException : public Exception{ explicit ScreenshotException(ErrorReport error_report, std::string message, std::shared_ptr screenshot); explicit ScreenshotException(ErrorReport error_report, ConsoleHandle& console, std::string message, bool take_screenshot); + void attach_screenshot(std::shared_ptr screenshot); + public: // virtual const char* name() const override{ return "ScreenshotException"; } virtual std::string message() const override{ return m_message; } diff --git a/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramComputer.cpp b/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramComputer.cpp index 7a920e815..2c6bd44aa 100644 --- a/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramComputer.cpp +++ b/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramComputer.cpp @@ -125,6 +125,7 @@ #include "PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.h" #include "PokemonSV/Inference/PokemonSV_PokemonSummaryReader.h" #include "Pokemon/Pokemon_StatsCalculation.h" +#include "PokemonSV/Inference/PokemonSV_StatHexagonReader.h" #ifdef PA_ARCH_x86 //#include "Kernels/Kernels_x64_SSE41.h" @@ -237,10 +238,16 @@ void TestProgramComputer::program(ProgramEnvironment& env, CancellableScope& sco - ImageRGB32 image("screenshot-20231003-202430049819.png"); - PokemonSummaryDetector detector; - cout << detector.detect(image) << endl; + ImageRGB32 image("screenshot-20231005-203932147068.png"); + SummaryStatsReader reader; +// cout << detector.detect(image) << endl; + auto nature = reader.read_nature(env.logger(), image); + cout << (int)nature.attack << endl; + cout << (int)nature.defense << endl; + cout << (int)nature.spatk << endl; + cout << (int)nature.spdef << endl; + cout << (int)nature.speed << endl; diff --git a/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_StatHexagonReader.cpp b/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_StatHexagonReader.cpp index 418e16a1a..a546b0ef0 100644 --- a/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_StatHexagonReader.cpp +++ b/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_StatHexagonReader.cpp @@ -139,7 +139,11 @@ NatureAdjustments StatHexagonReader::read_nature(Logger& logger, const ImageView return ret; } if (non_neutral.size() != 2){ - throw OperationFailedException(ErrorReport::SEND_ERROR_REPORT, logger, "Unable to read nature."); + throw OperationFailedException( + ErrorReport::SEND_ERROR_REPORT, + logger, + "Unable to read nature." + ); } if (*non_neutral[0].first != *non_neutral[1].first){ @@ -163,7 +167,11 @@ NatureAdjustments StatHexagonReader::read_nature(Logger& logger, const ImageView return ret; } - throw OperationFailedException(ErrorReport::SEND_ERROR_REPORT, logger, "Unable to read nature."); + throw OperationFailedException( + ErrorReport::SEND_ERROR_REPORT, + logger, + "Unable to read nature." + ); } diff --git a/SerialPrograms/Source/PokemonSV/Programs/General/PokemonSV_StatsResetBloodmoon.cpp b/SerialPrograms/Source/PokemonSV/Programs/General/PokemonSV_StatsResetBloodmoon.cpp index 04d8de9ac..a95b13106 100644 --- a/SerialPrograms/Source/PokemonSV/Programs/General/PokemonSV_StatsResetBloodmoon.cpp +++ b/SerialPrograms/Source/PokemonSV/Programs/General/PokemonSV_StatsResetBloodmoon.cpp @@ -144,8 +144,9 @@ StatsResetBloodmoon::StatsResetBloodmoon() , NOTIFICATION_STATUS_UPDATE("Status Update", true, false, std::chrono::seconds(3600)) , NOTIFICATIONS({ &NOTIFICATION_STATUS_UPDATE, - & NOTIFICATION_PROGRAM_FINISH, - & NOTIFICATION_ERROR_FATAL, + &NOTIFICATION_PROGRAM_FINISH, + &NOTIFICATION_ERROR_RECOVERABLE, + &NOTIFICATION_ERROR_FATAL, }) { #if 0 @@ -499,7 +500,17 @@ bool StatsResetBloodmoon::check_stats_after_win(SingleSwitchProgramEnvironment& context.wait_for_all_requests(); auto snapshot = env.console.video().snapshot(); - IvRanges ivs = reader.calc_ivs(env.logger(), snapshot, {113, 70, 120, 135, 65, 52}); + IvRanges ivs; + try{ + ivs = reader.calc_ivs(env.logger(), snapshot, {113, 70, 120, 135, 65, 52}); + }catch (OperationFailedException& e){ + send_program_recoverable_error_notification( + env, NOTIFICATION_ERROR_RECOVERABLE, + e.message(), + snapshot + ); + return false; + } CALCULATED_IVS.set(ivs); @@ -578,7 +589,7 @@ void StatsResetBloodmoon::program(SingleSwitchProgramEnvironment& env, BotBaseCo true ); } - + } } }