diff --git a/Common/Cpp/Time.cpp b/Common/Cpp/Time.cpp index a506d214d..b97dd5379 100644 --- a/Common/Cpp/Time.cpp +++ b/Common/Cpp/Time.cpp @@ -4,10 +4,36 @@ * */ +#include #include "Time.h" namespace PokemonAutomation{ +uint16_t current_year(){ +#if 0 + // This requires C++20. (https://stackoverflow.com/a/58152002) + return (uint16_t)std::atoi( + std::format("{:%Y}", std::chrono::system_clock::now()) + ); +#endif + +#if 1 + // This is not thread-safe. (https://stackoverflow.com/a/58153628) + // (Thread-safe on Windows because it uses TLS, but unclear on other platforms.) + std::time_t t = std::time(nullptr); + std::tm* info = std::localtime(&t); + return (uint16_t)(info->tm_year + 1900); +#endif + +#if 0 + // This is wrong. (https://stackoverflow.com/a/67459754) + time_t current_time = time(nullptr); + return (uint16_t)(1970 + current_time / 31537970); +#endif +} + + + } diff --git a/Common/Cpp/Time.h b/Common/Cpp/Time.h index e029abe52..9926e43c0 100644 --- a/Common/Cpp/Time.h +++ b/Common/Cpp/Time.h @@ -23,6 +23,8 @@ inline WallClock current_time(){ } +uint16_t current_year(); + } #endif diff --git a/SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Routines.cpp b/SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Routines.cpp index 7f8c75f48..1e8894049 100644 --- a/SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Routines.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Routines.cpp @@ -6,23 +6,31 @@ #include #include "ClientSource/Libraries/MessageConverter.h" -#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" -#include "NintendoSwitch/NintendoSwitch_Settings.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h" #include "NintendoSwitch_Commands_Routines.h" -#include "NintendoSwitch_Messages_Routines.h" +//#include "NintendoSwitch_Messages_Routines.h" namespace PokemonAutomation{ namespace NintendoSwitch{ void close_game(BotBaseContext& context){ +#if 0 context.issue_request( DeviceRequest_close_game() ); +#else + // Use mashing to ensure that the X press succeeds. If it fails, the SR + // will fail and can kill a den for the autohosts. + ssf_mash1_button(context, BUTTON_X, 100); // Close game + ssf_mash2_button(context, BUTTON_X, BUTTON_A, 50); // Confirm close game + ssf_mash1_button(context, BUTTON_X, 50); + ssf_mash1_button(context, BUTTON_B, 350); +#endif } - +#if 0 int register_message_converters_routines(){ register_message_converter( PABB_MSG_COMMAND_CLOSE_GAME, @@ -38,6 +46,7 @@ int register_message_converters_routines(){ return 0; } int init_NintendoSwitchRoutines = register_message_converters_routines(); +#endif } diff --git a/SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Messages_Routines.h b/SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Messages_Routines (disabled).h similarity index 100% rename from SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Messages_Routines.h rename to SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Messages_Routines (disabled).h diff --git a/SerialPrograms/Source/PokemonSwSh/Programs/DenHunting/PokemonSwSh_DaySkipperEU.cpp b/SerialPrograms/Source/PokemonSwSh/Programs/DenHunting/PokemonSwSh_DaySkipperEU.cpp index 14c86bcdc..4db565dad 100644 --- a/SerialPrograms/Source/PokemonSwSh/Programs/DenHunting/PokemonSwSh_DaySkipperEU.cpp +++ b/SerialPrograms/Source/PokemonSwSh/Programs/DenHunting/PokemonSwSh_DaySkipperEU.cpp @@ -44,10 +44,7 @@ DaySkipperEU::DaySkipperEU() , REAL_LIFE_YEAR( "Real Life Year:", LockMode::LOCK_WHILE_RUNNING, - std::min( - (uint16_t)std::atoi(std::format("{:%Y}", current_time()).c_str()), - (uint16_t)2060 - ), + std::min(current_year(), (uint16_t)2060), 2000, 2060 ) , NOTIFICATION_PROGRESS_UPDATE("Progress Update", true, false, std::chrono::seconds(3600)) diff --git a/SerialPrograms/Source/PokemonSwSh/Programs/DenHunting/PokemonSwSh_DaySkipperUS.cpp b/SerialPrograms/Source/PokemonSwSh/Programs/DenHunting/PokemonSwSh_DaySkipperUS.cpp index b05d02cea..c1891043c 100644 --- a/SerialPrograms/Source/PokemonSwSh/Programs/DenHunting/PokemonSwSh_DaySkipperUS.cpp +++ b/SerialPrograms/Source/PokemonSwSh/Programs/DenHunting/PokemonSwSh_DaySkipperUS.cpp @@ -44,10 +44,7 @@ DaySkipperUS::DaySkipperUS() , REAL_LIFE_YEAR( "Real Life Year:", LockMode::LOCK_WHILE_RUNNING, - std::min( - (uint16_t)std::atoi(std::format("{:%Y}", current_time()).c_str()), - (uint16_t)2060 - ), + std::min(current_year(), (uint16_t)2060), 2000, 2060 ) , NOTIFICATION_PROGRESS_UPDATE("Progress Update", true, false, std::chrono::seconds(3600))