Skip to content

Commit 419eeab

Browse files
committed
Fix FCE for real this time? Also fix the Friend Code Adder.
1 parent 808e732 commit 419eeab

20 files changed

+405
-337
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,18 +1007,20 @@ file(GLOB MAIN_SOURCES
10071007
Source/NintendoSwitch/Programs/DateSpam/NintendoSwitch_RollDateBackwardN.h
10081008
Source/NintendoSwitch/Programs/DateSpam/NintendoSwitch_RollDateForward1.cpp
10091009
Source/NintendoSwitch/Programs/DateSpam/NintendoSwitch_RollDateForward1.h
1010+
Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_CodeEntryTools.cpp
1011+
Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_CodeEntryTools.h
1012+
Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardCodeEntry.cpp
1013+
Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardCodeEntry.h
1014+
Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_NumberCodeEntry.cpp
1015+
Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_NumberCodeEntry.h
10101016
Source/NintendoSwitch/Programs/NintendoSwitch_FriendCodeAdder.cpp
10111017
Source/NintendoSwitch/Programs/NintendoSwitch_FriendCodeAdder.h
10121018
Source/NintendoSwitch/Programs/NintendoSwitch_FriendDelete.cpp
10131019
Source/NintendoSwitch/Programs/NintendoSwitch_FriendDelete.h
10141020
Source/NintendoSwitch/Programs/NintendoSwitch_GameEntry.cpp
10151021
Source/NintendoSwitch/Programs/NintendoSwitch_GameEntry.h
1016-
Source/NintendoSwitch/Programs/NintendoSwitch_KeyboardCodeEntry.cpp
1017-
Source/NintendoSwitch/Programs/NintendoSwitch_KeyboardCodeEntry.h
10181022
Source/NintendoSwitch/Programs/NintendoSwitch_MenuStabilityTester.cpp
10191023
Source/NintendoSwitch/Programs/NintendoSwitch_MenuStabilityTester.h
1020-
Source/NintendoSwitch/Programs/NintendoSwitch_NumberCodeEntry.cpp
1021-
Source/NintendoSwitch/Programs/NintendoSwitch_NumberCodeEntry.h
10221024
Source/NintendoSwitch/Programs/NintendoSwitch_PreventSleep.cpp
10231025
Source/NintendoSwitch/Programs/NintendoSwitch_PreventSleep.h
10241026
Source/NintendoSwitch/Programs/NintendoSwitch_PushJoySticks.cpp

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_ProController.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#define PokemonAutomation_NintendoSwitch_Controller_H
1111

1212
#include "Common/Cpp/Containers/Pimpl.h"
13-
#include "ClientSource/Connection/BotBaseMessage.h"
1413
#include "NintendoSwitch_ControllerState.h"
1514
#include "Controllers/Controller.h"
1615

SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase3_ProController.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
*/
66

7+
#include "Common/Cpp/Exceptions.h"
78
//#include "Common/Cpp/Concurrency/ReverseLockGuard.h"
89
#include "CommonFramework/GlobalSettingsPanel.h"
910
#include "Controllers/JoystickTools.h"

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
4848
#include "NintendoSwitch/NintendoSwitch_Settings.h"
4949
#include "NintendoSwitch/Programs/DateManip/NintendoSwitch_DateManip.h"
50-
#include "NintendoSwitch/Programs/NintendoSwitch_KeyboardCodeEntry.h"
50+
#include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardCodeEntry.h"
5151
#include "PokemonSV/PokemonSV_Settings.h"
5252
#include "PokemonLA/Programs/PokemonLA_GameEntry.h"
5353
#include "PokemonSV/Programs/PokemonSV_GameEntry.h"
@@ -115,7 +115,7 @@
115115
#include "PokemonBDSP/Inference/PokemonBDSP_SelectionArrow.h"
116116
#include "PokemonSV/Programs/Farming/PokemonSV_MaterialFarmerTools.h"
117117
#include "PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer.h"
118-
#include "NintendoSwitch/Programs/NintendoSwitch_NumberCodeEntry.h"
118+
#include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_NumberCodeEntry.h"
119119
#include "PokemonSV/Inference/ItemPrinter/PokemonSV_ItemPrinterMenuDetector.h"
120120
#include "PokemonSV/Inference/Picnics/PokemonSV_SandwichHandDetector.h"
121121
#include "PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_PokemonSwapMenu.h"
@@ -326,6 +326,8 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
326326
VideoOverlaySet overlays(overlay);
327327

328328

329+
// ssf_issue_scroll(context, DPAD_LEFT, 48ms, 48ms, 24ms);
330+
ssf_press_button(context, BUTTON_A, 96ms, 48ms, 24ms);
329331
ssf_press_button(context, BUTTON_L, 0ms, 48ms, 24ms);
330332
ssf_issue_scroll(context, DPAD_LEFT, 48ms, 48ms, 24ms);
331333

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/* Code Entry Tools
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
8+
#include "NintendoSwitch_CodeEntryTools.h"
9+
10+
namespace PokemonAutomation{
11+
namespace NintendoSwitch{
12+
namespace FastCodeEntry{
13+
14+
15+
16+
17+
void codeboard_populate_delays(
18+
bool switch2,
19+
std::vector<CodeEntryActionWithDelay>& path_with_delays,
20+
const std::vector<CodeEntryAction>& path,
21+
const CodeEntryDelays& delays,
22+
bool optimize
23+
){
24+
// Populate and assign default delays first.
25+
path_with_delays.resize(path.size());
26+
for (size_t c = 0; c < path_with_delays.size(); c++){
27+
CodeEntryAction action = path[c];
28+
Milliseconds delay;
29+
if (action == CodeEntryAction::ENTER_CHAR){
30+
delay = delays.press_delay;
31+
}else if (action == CodeEntryAction::SCROLL_LEFT){
32+
delay = delays.scroll_delay;
33+
}else{
34+
delay = delays.move_delay;
35+
}
36+
37+
// If we are wrapping and the previous action is a move, then we can't
38+
// overlap.
39+
if (is_wrap(action) && c != 0){
40+
CodeEntryActionWithDelay& previous = path_with_delays[c - 1];
41+
if (is_move(previous.action)){
42+
previous.delay = delays.hold;
43+
}
44+
}
45+
46+
path_with_delays[c].action = action;
47+
path_with_delays[c].delay = delay;
48+
}
49+
50+
51+
// Pad out the stalls.
52+
Milliseconds A_to_A_delay = std::max(delays.press_delay, delays.hold + delays.cool);
53+
Milliseconds last_A_time = -1000ms;
54+
Milliseconds current_time = 0ms;
55+
for (size_t c = 1; c < path_with_delays.size(); c++){
56+
CodeEntryActionWithDelay& previous = path_with_delays[c - 1];
57+
CodeEntryActionWithDelay& current = path_with_delays[c];
58+
59+
// The Switch doesn't like overlapping the scroll with the A press.
60+
// So we treat the left-scroll like an A press for timing purposes.
61+
62+
if (current.action == CodeEntryAction::ENTER_CHAR ||
63+
(switch2 && current.action == CodeEntryAction::SCROLL_LEFT)
64+
){
65+
Milliseconds time_since_last_A = current_time - last_A_time;
66+
if (time_since_last_A < A_to_A_delay){
67+
Milliseconds stall = A_to_A_delay - time_since_last_A;
68+
previous.delay += stall;
69+
current_time += stall;
70+
}
71+
last_A_time = current_time;
72+
}
73+
74+
current_time += current.delay;
75+
}
76+
77+
78+
// Optimize
79+
80+
if (!optimize || path_with_delays.empty() || switch2){
81+
return;
82+
}
83+
84+
// These only work on the Switch 1.
85+
for (size_t c = 1; c < path_with_delays.size(); c++){
86+
// Zero the delay for any L press.
87+
CodeEntryActionWithDelay& current = path_with_delays[c];
88+
if (current.action == CodeEntryAction::SCROLL_LEFT){
89+
current.delay = 0ms;
90+
continue;
91+
}
92+
93+
// Zero the delay for any scroll immediately preceding an A press.
94+
CodeEntryActionWithDelay& previous = path_with_delays[c - 1];
95+
if (current.action == CodeEntryAction::ENTER_CHAR &&
96+
previous.action != CodeEntryAction::ENTER_CHAR &&
97+
previous.action != CodeEntryAction::SCROLL_LEFT
98+
){
99+
previous.delay = 0ms;
100+
}
101+
}
102+
}
103+
104+
105+
106+
107+
void codeboard_execute_path(
108+
ProControllerContext& context,
109+
const CodeEntryDelays& delays,
110+
const std::vector<CodeEntryActionWithDelay>& path
111+
){
112+
for (const CodeEntryActionWithDelay& action : path){
113+
switch (action.action){
114+
case CodeEntryAction::ENTER_CHAR:
115+
ssf_press_button(context, BUTTON_A, action.delay, delays.hold, delays.cool);
116+
break;
117+
case CodeEntryAction::SCROLL_LEFT:
118+
ssf_press_button(context, BUTTON_L, action.delay, delays.hold, delays.cool);
119+
break;
120+
default:
121+
ssf_issue_scroll(
122+
context,
123+
(DpadPosition)((uint8_t)action.action & 0x7f),
124+
action.delay, delays.hold, delays.cool
125+
);
126+
break;
127+
}
128+
}
129+
}
130+
131+
132+
133+
134+
135+
136+
}
137+
}
138+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/* Code Entry Tools
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_NintendoSwitch_CodeEntryTools_H
8+
#define PokemonAutomation_NintendoSwitch_CodeEntryTools_H
9+
10+
#include <stdint.h>
11+
#include <vector>
12+
#include "Common/Cpp/Time.h"
13+
#include "NintendoSwitch/Controllers/NintendoSwitch_ControllerState.h"
14+
#include "NintendoSwitch/Controllers/NintendoSwitch_ProController.h"
15+
16+
namespace PokemonAutomation{
17+
namespace NintendoSwitch{
18+
namespace FastCodeEntry{
19+
20+
21+
22+
23+
enum class CodeEntryAction : uint8_t{
24+
ENTER_CHAR = 0xf0,
25+
SCROLL_LEFT = 0xf1,
26+
NORM_MOVE_UP = (uint8_t)DpadPosition::DPAD_UP,
27+
NORM_MOVE_RIGHT = (uint8_t)DpadPosition::DPAD_RIGHT,
28+
NORM_MOVE_DOWN = (uint8_t)DpadPosition::DPAD_DOWN,
29+
NORM_MOVE_LEFT = (uint8_t)DpadPosition::DPAD_LEFT,
30+
WRAP_MOVE_UP = 0x80 | (uint8_t)DpadPosition::DPAD_UP,
31+
WRAP_MOVE_RIGHT = 0x80 | (uint8_t)DpadPosition::DPAD_RIGHT,
32+
WRAP_MOVE_DOWN = 0x80 | (uint8_t)DpadPosition::DPAD_DOWN,
33+
WRAP_MOVE_LEFT = 0x80 | (uint8_t)DpadPosition::DPAD_LEFT,
34+
};
35+
inline bool is_button_press(CodeEntryAction action){
36+
switch (action){
37+
case CodeEntryAction::ENTER_CHAR:
38+
case CodeEntryAction::SCROLL_LEFT:
39+
return true;
40+
default:
41+
return false;
42+
}
43+
}
44+
inline bool is_move(CodeEntryAction action){
45+
switch (action){
46+
case CodeEntryAction::NORM_MOVE_UP:
47+
case CodeEntryAction::NORM_MOVE_RIGHT:
48+
case CodeEntryAction::NORM_MOVE_DOWN:
49+
case CodeEntryAction::NORM_MOVE_LEFT:
50+
case CodeEntryAction::WRAP_MOVE_UP:
51+
case CodeEntryAction::WRAP_MOVE_RIGHT:
52+
case CodeEntryAction::WRAP_MOVE_DOWN:
53+
case CodeEntryAction::WRAP_MOVE_LEFT:
54+
return true;
55+
default:
56+
return false;
57+
}
58+
}
59+
inline bool is_wrap(CodeEntryAction action){
60+
switch (action){
61+
case CodeEntryAction::WRAP_MOVE_UP:
62+
case CodeEntryAction::WRAP_MOVE_RIGHT:
63+
case CodeEntryAction::WRAP_MOVE_DOWN:
64+
case CodeEntryAction::WRAP_MOVE_LEFT:
65+
return true;
66+
default:
67+
return false;
68+
}
69+
}
70+
71+
72+
struct CodeEntryDelays{
73+
Milliseconds hold;
74+
Milliseconds cool;
75+
Milliseconds press_delay;
76+
Milliseconds move_delay;
77+
Milliseconds scroll_delay;
78+
Milliseconds wrap_delay;
79+
};
80+
81+
82+
struct CodeEntryActionWithDelay{
83+
CodeEntryAction action;
84+
Milliseconds delay;
85+
};
86+
87+
88+
89+
90+
// Given a path, optimize it and fully populate the delays.
91+
void codeboard_populate_delays(
92+
bool switch2,
93+
std::vector<CodeEntryActionWithDelay>& path_with_delays,
94+
const std::vector<CodeEntryAction>& path,
95+
const CodeEntryDelays& delays,
96+
bool optimize
97+
);
98+
99+
100+
101+
102+
103+
//inline Milliseconds calculate_path_delay(const std::vector<CodeEntryActionWithDelay>& path){
104+
105+
//}
106+
107+
108+
109+
// Actually execute a path and enter it into the Switch.
110+
void codeboard_execute_path(
111+
ProControllerContext& context,
112+
const CodeEntryDelays& delays,
113+
const std::vector<CodeEntryActionWithDelay>& path
114+
);
115+
116+
117+
118+
119+
120+
121+
122+
123+
124+
125+
126+
127+
128+
129+
130+
131+
}
132+
}
133+
}
134+
#endif

0 commit comments

Comments
 (0)