Skip to content

Commit 61dd75d

Browse files
committed
Fix SV auto-host date correction.
1 parent c9269bb commit 61dd75d

File tree

3 files changed

+8
-103
lines changed

3 files changed

+8
-103
lines changed

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_DateReader.cpp

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -247,99 +247,6 @@ bool DateReader::detect(const ImageViewRGB32& screen){
247247
}
248248

249249

250-
void DateReader::set_hours(
251-
const ProgramInfo& info, VideoStream& stream, ProControllerContext& context,
252-
uint8_t hour
253-
){
254-
context.wait_for_all_requests();
255-
{
256-
auto snapshot = stream.video().snapshot();
257-
if (!detect(snapshot)){
258-
throw_and_log<FatalProgramException>(
259-
stream.logger(), ErrorReport::SEND_ERROR_REPORT,
260-
"Expected date change menu.",
261-
stream
262-
);
263-
}
264-
}
265-
266-
for (size_t attempts = 0; attempts < 10; attempts++){
267-
// Move cursor out of the way.
268-
for (size_t c = 0; c < 7; c++){
269-
ssf_issue_scroll_ptv(context, DPAD_LEFT);
270-
}
271-
context.wait_for_all_requests();
272-
context.wait_for(std::chrono::milliseconds(250));
273-
274-
// Read the hour.
275-
VideoSnapshot snapshot = stream.video().snapshot();
276-
// int8_t current_hour = read_hours(stream, snapshot);
277-
int8_t current_hour = read_date(stream.logger(), snapshot).second.hour;
278-
279-
if (current_hour < 0){
280-
throw_and_log<FatalProgramException>(
281-
stream.logger(), ErrorReport::SEND_ERROR_REPORT,
282-
"Unable to read the hour.",
283-
stream
284-
);
285-
}
286-
287-
// We're done.
288-
if (current_hour == hour){
289-
for (size_t c = 0; c < 7; c++){
290-
ssf_issue_scroll_ptv(context, DPAD_RIGHT);
291-
}
292-
return;
293-
}
294-
295-
// Move the cursor to the hour.
296-
ssf_issue_scroll_ptv(context, DPAD_RIGHT);
297-
ssf_issue_scroll_ptv(context, DPAD_RIGHT);
298-
ssf_issue_scroll_ptv(context, DPAD_RIGHT);
299-
300-
ImageViewRGB32 us_hours = extract_box_reference(snapshot, m_us_hour);
301-
ImageStats stats_us_hours = image_stats(us_hours);
302-
double stddev = stats_us_hours.stddev.sum();
303-
bool format_us = stddev > 30;
304-
if (format_us){
305-
uint8_t diff = (24 + (uint8_t)hour - (uint8_t)current_hour) % 12;
306-
if (diff < 6){
307-
for (size_t c = 0; c < diff; c++){
308-
ssf_issue_scroll_ptv(context, DPAD_UP);
309-
}
310-
}else{
311-
for (size_t c = diff; c < 12; c++){
312-
ssf_issue_scroll_ptv(context, DPAD_DOWN);
313-
}
314-
}
315-
if ((hour < 12) != (current_hour < 12)){
316-
ssf_issue_scroll_ptv(context, DPAD_RIGHT);
317-
ssf_issue_scroll_ptv(context, DPAD_RIGHT);
318-
ssf_issue_scroll_ptv(context, DPAD_DOWN);
319-
}
320-
}else{
321-
uint8_t diff = (24 + (uint8_t)hour - (uint8_t)current_hour) % 24;
322-
if (diff < 12){
323-
for (size_t c = 0; c < diff; c++){
324-
ssf_issue_scroll_ptv(context, DPAD_UP);
325-
}
326-
}else{
327-
for (size_t c = diff; c < 24; c++){
328-
ssf_issue_scroll_ptv(context, DPAD_DOWN);
329-
}
330-
}
331-
}
332-
}
333-
334-
// auto snapshot = console.video().snapshot();
335-
throw_and_log<FatalProgramException>(
336-
stream.logger(), ErrorReport::SEND_ERROR_REPORT,
337-
"Failed to set the hour after 10 attempts.",
338-
stream
339-
);
340-
}
341-
342-
343250
std::pair<DateFormat, DateTime> DateReader::read_date(Logger& logger, std::shared_ptr<const ImageRGB32> screen){
344251
if (!detect(*screen)){
345252
throw_and_log<OperationFailedException>(

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_DateReader.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,6 @@ class DateReader : public StaticScreenDetector{
7272
// Returns true if we are on the date change window.
7373
virtual bool detect(const ImageViewRGB32& screen) override;
7474

75-
// Read the hours (0 - 23) while on the date change window.
76-
// Returns -1 if unable to read.
77-
// int8_t read_hours(Logger& logger, std::shared_ptr<const ImageRGB32> screen) const;
78-
79-
void set_hours(
80-
const ProgramInfo& info, VideoStream& stream, ProControllerContext& context,
81-
uint8_t hour // 0 - 23
82-
);
83-
8475

8576
std::pair<DateFormat, DateTime> read_date(Logger& logger, std::shared_ptr<const ImageRGB32> screen);
8677
void set_date(

SerialPrograms/Source/PokemonSV/Programs/PokemonSV_MenuNavigation.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ void set_time_to_12am_from_home(const ProgramInfo& info, ConsoleHandle& console,
3636
// pbf_press_button(context, BUTTON_HOME, 10, GameSettings::instance().GAME_TO_HOME_DELAY);
3737
home_to_date_time(console, context, true);
3838
pbf_press_button(context, BUTTON_A, 20, 50);
39-
reader.set_hours(info, console, context, 0);
39+
40+
context.wait_for_all_requests();
41+
42+
DateTime time = reader.read_date(console, console.video().snapshot()).second;
43+
time.hour = 0;
44+
reader.set_date(info, console, context, time);
45+
// reader.set_hours(info, console, context, 0);
46+
4047
pbf_press_button(context, BUTTON_A, 20, 30);
4148
pbf_press_button(context, BUTTON_HOME, 160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0);
4249
// resume_game_from_home(console, context);

0 commit comments

Comments
 (0)