FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
SysBot.Remote/SysBot.cs at master · CodeHedge/SysBot.Remote · GitHub
CodeHedge
/
SysBot.Remote
Public
Notifications
You must be signed in to change notification settings
Fork
6
Star
10
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
SysBot.Remote
/
SysBot.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
257 lines (216 loc) · 8.76 KB
Breadcrumbs
SysBot.Remote
/
SysBot.cs
Copy path
File metadata and controls
257 lines (216 loc) · 8.76 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
using
SysBot
.
Base
;
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
Linq
;
using
System
.
Net
.
Sockets
;
using
System
.
Text
;
using
System
.
Threading
;
using
System
.
Threading
.
Tasks
;
namespace
SysbotMacro
{
public
class
Bot
:
SwitchSocket
{
public
IWirelessConnectionConfig
Config
{
get
;
private
set
;
}
public
Bot
(
IWirelessConnectionConfig
config
)
:
base
(
config
)
{
this
.
Config
=
config
;
}
public
override
void
Connect
(
)
{
Connection
.
Connect
(
Info
.
IP
,
Info
.
Port
)
;
}
public
override
void
Disconnect
(
)
{
Connection
.
Disconnect
(
false
)
;
}
public
override
void
Reset
(
)
{
Disconnect
(
)
;
Connect
(
)
;
}
public
async
Task
PressHomeButton
(
)
{
var
command
=
SwitchCommand
.
Click
(
SwitchButton
.
HOME
)
;
await
Connection
.
SendAsync
(
new
ArraySegment
<
byte
>
(
command
)
,
SocketFlags
.
None
)
;
}
public
async
Task
PressAButton
(
)
{
var
command
=
SwitchCommand
.
Click
(
SwitchButton
.
A
)
;
await
Connection
.
SendAsync
(
new
ArraySegment
<
byte
>
(
command
)
,
SocketFlags
.
None
)
;
}
public
async
Task
PressBButton
(
)
{
var
command
=
SwitchCommand
.
Click
(
SwitchButton
.
B
)
;
await
Connection
.
SendAsync
(
new
ArraySegment
<
byte
>
(
command
)
,
SocketFlags
.
None
)
;
}
public
async
Task
PressXButton
(
)
{
var
command
=
SwitchCommand
.
Click
(
SwitchButton
.
X
)
;
await
Connection
.
SendAsync
(
new
ArraySegment
<
byte
>
(
command
)
,
SocketFlags
.
None
)
;
}
public
async
Task
PressYButton
(
)
{
var
command
=
SwitchCommand
.
Click
(
SwitchButton
.
Y
)
;
await
Connection
.
SendAsync
(
new
ArraySegment
<
byte
>
(
command
)
,
SocketFlags
.
None
)
;
}
public
async
Task
PressLButton
(
)
{
var
command
=
SwitchCommand
.
Click
(
SwitchButton
.
L
)
;
await
Connection
.
SendAsync
(
new
ArraySegment
<
byte
>
(
command
)
,
SocketFlags
.
None
)
;
}
public
async
Task
PressRButton
(
)
{
var
command
=
SwitchCommand
.
Click
(
SwitchButton
.
R
)
;
await
Connection
.
SendAsync
(
new
ArraySegment
<
byte
>
(
command
)
,
SocketFlags
.
None
)
;
}
public
async
Task
PressZLButton
(
)
{
var
command
=
SwitchCommand
.
Click
(
SwitchButton
.
ZL
)
;
await
Connection
.
SendAsync
(
new
ArraySegment
<
byte
>
(
command
)
,
SocketFlags
.
None
)
;
}
public
async
Task
PressZRButton
(
)
{
var
command
=
SwitchCommand
.
Click
(
SwitchButton
.
ZR
)
;
await
Connection
.
SendAsync
(
new
ArraySegment
<
byte
>
(
command
)
,
SocketFlags
.
None
)
;
}
public
async
Task
PressPlusButton
(
)
{
var
command
=
SwitchCommand
.
Click
(
SwitchButton
.
PLUS
)
;
await
Connection
.
SendAsync
(
new
ArraySegment
<
byte
>
(
command
)
,
SocketFlags
.
None
)
;
}
public
async
Task
PressMinusButton
(
)
{
var
command
=
SwitchCommand
.
Click
(
SwitchButton
.
MINUS
)
;
await
Connection
.
SendAsync
(
new
ArraySegment
<
byte
>
(
command
)
,
SocketFlags
.
None
)
;
}
public
async
Task
PressLeftStickButton
(
)
{
var
command
=
SwitchCommand
.
Click
(
SwitchButton
.
LSTICK
)
;
await
Connection
.
SendAsync
(
new
ArraySegment
<
byte
>
(
command
)
,
SocketFlags
.
None
)
;
}
public
async
Task
PressRightStickButton
(
)
{
var
command
=
SwitchCommand
.
Click
(
SwitchButton
.
RSTICK
)
;
await
Connection
.
SendAsync
(
new
ArraySegment
<
byte
>
(
command
)
,
SocketFlags
.
None
)
;
}
public
async
Task
PressCaptureButton
(
)
{
var
command
=
SwitchCommand
.
Click
(
SwitchButton
.
CAPTURE
)
;
await
Connection
.
SendAsync
(
new
ArraySegment
<
byte
>
(
command
)
,
SocketFlags
.
None
)
;
}
public
async
Task
PressDPadUp
(
)
{
var
command
=
SwitchCommand
.
Click
(
SwitchButton
.
DUP
)
;
await
Connection
.
SendAsync
(
new
ArraySegment
<
byte
>
(
command
)
,
SocketFlags
.
None
)
;
}
public
async
Task
PressDPadDown
(
)
{
var
command
=
SwitchCommand
.
Click
(
SwitchButton
.
DDOWN
)
;
await
Connection
.
SendAsync
(
new
ArraySegment
<
byte
>
(
command
)
,
SocketFlags
.
None
)
;
}
public
async
Task
PressDPadLeft
(
)
{
var
command
=
SwitchCommand
.
Click
(
SwitchButton
.
DLEFT
)
;
await
Connection
.
SendAsync
(
new
ArraySegment
<
byte
>
(
command
)
,
SocketFlags
.
None
)
;
}
public
async
Task
PressDPadRight
(
)
{
var
command
=
SwitchCommand
.
Click
(
SwitchButton
.
DRIGHT
)
;
await
Connection
.
SendAsync
(
new
ArraySegment
<
byte
>
(
command
)
,
SocketFlags
.
None
)
;
}
public
byte
[
]
PixelPeek
(
)
{
// Original data in hexadecimal format
byte
[
]
hexData
=
SwitchCommand
.
PixelPeek
(
)
;
Console
.
WriteLine
(
$
"Received
{
hexData
.
Length
}
bytes."
)
;
// Convert the byte array to a hexadecimal string
string
hexString
=
Encoding
.
UTF8
.
GetString
(
hexData
)
;
Console
.
WriteLine
(
$
"Hex string length:
{
hexString
.
Length
}
"
)
;
Console
.
WriteLine
(
$
"Hex string:
{
hexString
}
"
)
;
// Convert the hexadecimal string back to a byte array
try
{
byte
[
]
actualImageBytes
=
Enumerable
.
Range
(
0
,
hexString
.
Length
)
.
Where
(
x
=>
x
%
2
==
0
)
.
Select
(
x
=>
Convert
.
ToByte
(
hexString
.
Substring
(
x
,
2
)
,
16
)
)
.
ToArray
(
)
;
return
actualImageBytes
;
}
catch
(
FormatException
e
)
{
Console
.
WriteLine
(
$
"FormatException caught:
{
e
.
Message
}
"
)
;
return
null
;
}
}
private
Dictionary
<
string
,
SwitchButton
>
buttonMap
=
new
Dictionary
<
string
,
SwitchButton
>
{
{
"A"
,
SwitchButton
.
A
}
,
{
"B"
,
SwitchButton
.
B
}
,
{
"X"
,
SwitchButton
.
X
}
,
{
"Y"
,
SwitchButton
.
Y
}
,
{
"L"
,
SwitchButton
.
L
}
,
{
"R"
,
SwitchButton
.
R
}
,
{
"ZL"
,
SwitchButton
.
ZL
}
,
{
"ZR"
,
SwitchButton
.
ZR
}
,
{
"+"
,
SwitchButton
.
PLUS
}
,
{
"-"
,
SwitchButton
.
MINUS
}
,
{
"LTS"
,
SwitchButton
.
LSTICK
}
,
{
"RTS"
,
SwitchButton
.
RSTICK
}
,
{
"H"
,
SwitchButton
.
HOME
}
,
{
"SS"
,
SwitchButton
.
CAPTURE
}
,
{
"UP"
,
SwitchButton
.
DUP
}
,
{
"DOWN"
,
SwitchButton
.
DDOWN
}
,
{
"LEFT"
,
SwitchButton
.
DLEFT
}
,
{
"RIGHT"
,
SwitchButton
.
DRIGHT
}
,
}
;
public
async
Task
ExecuteCommands
(
string
commands
,
Func
<
bool
>
loopFunc
,
CancellationToken
cancellationToken
)
{
var
splitCommands
=
commands
.
TrimEnd
(
)
.
Split
(
' '
)
;
int
defaultDelay
=
100
;
// Default delay after each command
for
(
int
i
=
0
;
i
<
splitCommands
.
Length
;
i
++
)
{
if
(
cancellationToken
.
IsCancellationRequested
)
{
break
;
}
var
command
=
splitCommands
[
i
]
;
// If the command is followed by a "d" and a number, interpret it as a delay
if
(
i
<
splitCommands
.
Length
-
2
&&
splitCommands
[
i
+
1
]
.
StartsWith
(
"d"
)
&&
int
.
TryParse
(
splitCommands
[
i
+
1
]
.
Substring
(
1
)
,
out
var
delay
)
)
{
await
PressButton
(
command
)
;
await
Task
.
Delay
(
delay
)
;
defaultDelay
=
delay
;
// Update the default delay
i
++
;
// Skip the next item in the loop, since we've already processed it
}
else
{
await
PressButton
(
command
)
;
await
Task
.
Delay
(
defaultDelay
)
;
// Wait for the default delay
}
}
if
(
loopFunc
(
)
&&
!
cancellationToken
.
IsCancellationRequested
)
{
await
ExecuteCommands
(
commands
,
loopFunc
,
cancellationToken
)
;
}
}
private
async
Task
PressButton
(
string
button
)
{
if
(
!
buttonMap
.
TryGetValue
(
button
.
ToUpper
(
)
,
out
var
switchButton
)
)
{
// The button is not in the dictionary, so we skip it
return
;
}
var
command
=
SwitchCommand
.
Click
(
switchButton
)
;
await
Connection
.
SendAsync
(
new
ArraySegment
<
byte
>
(
command
)
,
SocketFlags
.
None
)
;
}
private
async
Task
HoldButton
(
string
button
,
int
duration
)
{
var
switchButton
=
buttonMap
[
button
.
ToUpper
(
)
]
;
var
holdCommand
=
SwitchCommand
.
Hold
(
switchButton
)
;
var
releaseCommand
=
SwitchCommand
.
Release
(
switchButton
)
;
await
Connection
.
SendAsync
(
new
ArraySegment
<
byte
>
(
holdCommand
)
,
SocketFlags
.
None
)
;
await
Task
.
Delay
(
duration
)
;
await
Connection
.
SendAsync
(
new
ArraySegment
<
byte
>
(
releaseCommand
)
,
SocketFlags
.
None
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL