Skip to content

Commit 7b3bb17

Browse files
committed
Early PZA stuff.
1 parent 1e1c354 commit 7b3bb17

15 files changed

+802
-27
lines changed

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@
144144
#include "CommonTools/Images/SolidColorTest.h"
145145
#include "CommonTools/Async/InterruptableCommands.h"
146146
#include "PokemonLGPE/Inference/Battles/PokemonLGPE_BattleArrowDetector.h"
147+
#include "PokemonLZA/Inference/PokemonLZA_DialogDetector.h"
148+
#include "PokemonLZA/Programs/PokemonLZA_GameEntry.h"
147149

148150

149151

@@ -241,8 +243,24 @@ void TestProgram::on_press(){
241243

242244

243245

246+
#if 0
247+
class TealDialogMatcher : public ImageMatch::WaterfillTemplateMatcher{
248+
public:
249+
TealDialogMatcher() : WaterfillTemplateMatcher(
250+
"PokemonLZA/DialogBox/DialogBoxTitleGreenLine-Template.png", Color(180,200,70), Color(200, 220, 115), 50
251+
) {
252+
m_aspect_ratio_lower = 0.9;
253+
m_aspect_ratio_upper = 1.1;
254+
m_area_ratio_lower = 0.8;
255+
m_area_ratio_upper = 1.1;
256+
}
244257

245-
258+
static const ImageMatch::WaterfillTemplateMatcher& instance() {
259+
static DialogTitleGreenLineMatcher matcher;
260+
return matcher;
261+
}
262+
};
263+
#endif
246264

247265

248266

@@ -266,13 +284,61 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
266284
VideoOverlaySet overlays(overlay);
267285

268286

287+
#if 0
288+
ImageRGB32 image("Screenshots/screenshot-20251012-174842583706.png");
289+
290+
PokemonLZA::BlueDialogDetector detector(COLOR_RED, &overlay);
291+
292+
cout << detector.detect(image) << endl;
293+
#endif
269294

270-
// reset_game_to_gamemenu(console, context);
271295

272296
#if 0
297+
ImageRGB32 image("Screenshots/screenshot-20251012-174842583706.png");
298+
299+
ImageFloatBox box(0.724479, 0.869141, 0.039517, 0.070312);
300+
// ImageFloatBox box(0.712404, 0.589844, 0.043908, 0.085938);
301+
302+
overlays.add(COLOR_RED, box);
303+
304+
ImageViewRGB32 cropped = extract_box_reference(image, box);
305+
306+
PackedBinaryMatrix matrix = compress_rgb32_to_binary_range(
307+
cropped,
308+
0xffc0c0c0, 0xffffffff
309+
);
310+
311+
cout << matrix.dump() << endl;
312+
313+
ImageRGB32 tmp = cropped.copy();
314+
filter_by_mask(matrix, tmp, Color(0x00000000), true);
315+
316+
#if 1
317+
auto session = Waterfill::make_WaterfillSession(matrix);
318+
auto iter = session->make_iterator(10);
319+
WaterfillObject object;
320+
while (iter->find_next(object, false)){
321+
322+
323+
}
324+
cout << "area = " << object.area << endl;
325+
326+
tmp.save("DialogBoxWhiteArrow-Template.png");
327+
// extract_box_reference(tmp, object).save("SelectionArrow.png");
328+
329+
330+
331+
332+
#endif
333+
#endif
334+
335+
336+
// reset_game_to_gamemenu(console, context);
337+
338+
#if 1
273339
while (true){
274340
go_home(console, context);
275-
PokemonLA::reset_game_from_home(env, console, context);
341+
PokemonLZA::reset_game_from_home(env, console, context, true);
276342
}
277343

278344

SerialPrograms/Source/PokemonLA/Programs/PokemonLA_GameEntry.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "CommonTools/Async/InferenceRoutines.h"
1010
#include "CommonTools/VisualDetectors/BlackScreenDetector.h"
1111
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
12+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
1213
#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h"
1314
#include "PokemonLA/PokemonLA_Settings.h"
1415
#include "PokemonLA_GameEntry.h"
@@ -23,10 +24,9 @@ namespace PokemonLA{
2324

2425

2526
bool reset_game_to_gamemenu(
26-
ConsoleHandle& console, ProControllerContext& context,
27-
bool tolerate_update_menu
27+
ConsoleHandle& console, ProControllerContext& context
2828
){
29-
from_home_close_and_reopen_game(console, context, tolerate_update_menu);
29+
from_home_close_and_reopen_game(console, context, true);
3030

3131
// Now the game has opened:
3232
return openedgame_to_gamemenu(console, context, GameSettings::instance().START_GAME_WAIT1);
@@ -60,12 +60,21 @@ bool gamemenu_to_ingame(
6060
bool reset_game_from_home(
6161
ProgramEnvironment& env,
6262
ConsoleHandle& console, ProControllerContext& context,
63+
bool backup_save,
6364
Milliseconds enter_game_mash,
6465
Milliseconds enter_game_timeout,
6566
Milliseconds post_wait_time
6667
){
6768
bool ok = true;
68-
ok &= reset_game_to_gamemenu(console, context, true);
69+
ok &= reset_game_to_gamemenu(console, context);
70+
71+
if (backup_save){
72+
console.log("Loading backup save!");
73+
pbf_wait(context, 1000ms);
74+
ssf_press_dpad(context, DPAD_UP, 0ms, 200ms);
75+
ssf_press_button(context, BUTTON_B | BUTTON_X, 1000ms, 200ms);
76+
}
77+
6978
ok &= gamemenu_to_ingame(
7079
console, context,
7180
enter_game_mash,
@@ -82,10 +91,12 @@ bool reset_game_from_home(
8291
bool reset_game_from_home(
8392
ProgramEnvironment& env,
8493
ConsoleHandle& console, ProControllerContext& context,
94+
bool backup_save,
8595
Milliseconds post_wait_time
8696
){
8797
return reset_game_from_home(
8898
env, console, context,
99+
backup_save,
89100
GameSettings::instance().ENTER_GAME_MASH0,
90101
GameSettings::instance().ENTER_GAME_WAIT0,
91102
post_wait_time

SerialPrograms/Source/PokemonLA/Programs/PokemonLA_GameEntry.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ using namespace std::chrono_literals;
2121
// From Switch Home menu, reset game and wait until the game menu screen (where
2222
// "Press A" is displayed to enter the game) is shown.
2323
bool reset_game_to_gamemenu(
24-
ConsoleHandle& console, ProControllerContext& context,
25-
bool tolerate_update_menu
24+
ConsoleHandle& console, ProControllerContext& context
2625
);
2726

2827
// From Switch Home menu, start game and wait until the player character
@@ -32,13 +31,15 @@ bool reset_game_to_gamemenu(
3231
bool reset_game_from_home(
3332
ProgramEnvironment& env,
3433
ConsoleHandle& console, ProControllerContext& context,
34+
bool backup_save,
3535
Milliseconds enter_game_mash,
3636
Milliseconds enter_game_timeout,
3737
Milliseconds post_wait_time
3838
);
3939
bool reset_game_from_home(
4040
ProgramEnvironment& env,
4141
ConsoleHandle& console, ProControllerContext& context,
42+
bool backup_save = false,
4243
Milliseconds post_wait_time = 1000ms
4344
);
4445

0 commit comments

Comments
 (0)