Created
September 20, 2017 20:47
-
-
Save shuffle2/5c986313c9c45e952f80af79dde7f435 to your computer and use it in GitHub Desktop.
joycon command handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned __int8 *__fastcall process_cmd(struct_a1 *a1, int a2, int a3, unsigned __int8 *pkt, signed int pkt_len) | |
{ | |
unsigned __int8 *pkt_; // r0@1 MAPDST | |
int v10; // r0@2 | |
int v11; // r12@8 | |
unsigned __int8 v12; // r0@13 | |
signed int b0; // r0@15 | |
int v14; // r0@38 | |
unsigned __int8 v15; // r1@46 | |
unsigned int v16; // r2@51 | |
unsigned __int8 *v17; // r1@51 | |
unsigned __int8 *v18; // r0@51 | |
unsigned __int8 v19[308]; // [sp+0h] [bp-168h]@49 | |
struct_a1 *v20; // [sp+134h] [bp-34h]@1 | |
int v21; // [sp+138h] [bp-30h]@1 | |
int v22; // [sp+13Ch] [bp-2Ch]@1 | |
unsigned __int8 *v23; // [sp+140h] [bp-28h]@1 | |
v20 = a1; | |
v21 = a2; | |
v22 = a3; | |
v23 = pkt; | |
pkt_ = (unsigned __int8 *)nullsub_17(pkt_len); | |
if ( pkt_ ) | |
{ | |
memcpy(pkt_, pkt, pkt_len); | |
v10 = a1->dword1D4; | |
if ( v10 == v21 && *(_BYTE *)(v10 + 4) == 2 ) | |
{ | |
if ( a3 != 2 ) | |
goto LABEL_59; | |
if ( *pkt == 0x92 ) | |
{ | |
crc8(a1, pkt, 6u); | |
if ( pkt_len ) | |
crc8(a1, (unsigned __int8 *)(v11 + 7), pkt_len - 7); | |
a1->byte127E = 1; | |
memcpy(pkt_, pkt + 7, pkt_len - 7); // just remove the prefix hdr | |
a1->dword268 = dword_6FBC8(); | |
} | |
} | |
else if ( a3 != 2 ) | |
{ | |
goto LABEL_59; | |
} | |
if ( a1->dword44 == v21 && byte_DB2B2 ) | |
{ | |
v12 = pkt_[1]; | |
BYTE1(dword_2207B4) = v12 & 0xF; | |
if ( (v12 & 0xF) == BYTE2(dword_2207B4) ) | |
goto LABEL_59; | |
BYTE2(dword_2207B4) = v12 & 0xF; | |
} | |
b0 = *pkt_; | |
if ( b0 != 0x14 ) | |
{ | |
if ( b0 > 0x14 ) | |
{ | |
if ( b0 == 0x91 ) | |
{ | |
wiredCmdProcess(a1, pkt_); | |
} | |
else if ( b0 > 0x91 ) | |
{ | |
if ( b0 == 0x93 ) | |
{ | |
memset(byte_220FCB, 0, 0x187u); | |
memcpy(&byte_220FCB[7], pkt_ + 7, (unsigned __int16)(pkt_len - 7)); | |
byte_220E44[0] = 0x93u; | |
*(_WORD *)&byte_220E44[2] = 0x26; | |
sub_21CB94(1, byte_220E44, 0x2D); | |
} | |
else if ( b0 == 0xA5 ) | |
{ | |
handle_cmd_a5(a1, pkt_); | |
} | |
} | |
else if ( b0 != 0x1F && (b0 == 0x43 || b0 == 0x53) ) | |
{ | |
sub_21FA6C(a1, pkt_, (unsigned __int16)pkt_len); | |
} | |
} | |
else if ( b0 == 0x11 ) | |
{ | |
if ( hid_device_type != 1 ) | |
{ | |
memset(byte_221318, 0, 0x200u); | |
memset(byte_221518, 0, 0x200u); | |
if ( a1->uart_active? ) | |
{ | |
memcpy(byte_221318, pkt_ + 10, 1u); | |
byte_221318[1] = 1; | |
memcpy(&byte_221318[2], pkt_ + 2, 8u); | |
v16 = 37; | |
v17 = pkt_ + 11; | |
v18 = &byte_221318[10]; | |
goto LABEL_58; | |
} | |
} | |
} | |
else if ( b0 > 0x11 ) | |
{ | |
if ( b0 == 0x12 ) | |
{ | |
memset(byte_220E44, 0, 0x187u); | |
memcpy(&byte_220E44[7], pkt_ + 10, 0x26u); | |
} | |
} | |
else if ( b0 == 1 ) | |
{ | |
if ( a1->uart_active? ) | |
{ | |
memset(byte_221318, 0, 0x200u); | |
memset(byte_221518, 0, 0x200u); | |
byte_221318[0] = 5; | |
if ( pkt_[10] == 0x48 ) | |
{ | |
if ( pkt_[11] == 1 ) | |
v15 = 0x48; | |
else | |
v15 = 0x49; | |
byte_221318[1] = v15; | |
} | |
else | |
{ | |
byte_221318[1] = 1; | |
} | |
memcpy(&byte_221318[2], pkt_ + 2, 8u); | |
v14 = pkt_[10]; | |
if ( v14 != 0x20 && v14 != 0x21 && v14 != 0x22 ) | |
unknown_xfer_cmd(0x139, byte_221318, byte_221518); | |
} | |
handle_cmd_01(a1, pkt_); | |
if ( a1->uart_active? ) | |
goto LABEL_43; | |
} | |
else | |
{ | |
if ( b0 == 3 ) | |
{ | |
memset(v19, 0, 0x134u); | |
memcpy(v19, pkt_ + 10, 0x134u); | |
sub_21FB8A(v19); | |
goto LABEL_59; | |
} | |
if ( b0 == 0x10 && a1->uart_active? ) | |
{ | |
memset(byte_221318, 0, 0x200u); | |
memset(byte_221518, 0, 0x200u); | |
byte_221318[0] = 5; | |
byte_221318[1] = 1; | |
v16 = 8; | |
v17 = pkt_ + 2; | |
v18 = &byte_221318[2]; | |
LABEL_58: | |
memcpy(v18, v17, v16); | |
unknown_xfer_cmd(0x139, byte_221318, byte_221518); | |
LABEL_43: | |
byte_2207BA = byte_221518[0]; | |
goto LABEL_59; | |
} | |
} | |
} | |
LABEL_59: | |
JUMPOUT(dword_724B4); | |
} | |
return pkt_; | |
} | |
void __fastcall wiredCmdProcess(struct_a1 *bt, unsigned __int8 *pkt) | |
{ | |
signed int cmd; // r9@1 | |
unsigned int len; // r5@1 | |
signed int b4; // r7@1 | |
unsigned __int8 *pkt_data; // r6@1 | |
unsigned __int8 *v9; // r7@23 | |
unsigned __int8 v10; // r0@28 | |
int v11; // r1@29 | |
signed int v12; // r0@29 | |
int v13; // r2@30 | |
struct_a1 *v14; // r0@31 | |
int v15; // r2@39 | |
unsigned __int8 *v16; // r1@39 | |
char v17; // r0@50 | |
int v18; // r0@51 | |
char v19; // r0@56 | |
char *v20; // r4@57 | |
char v21; // r0@57 | |
char v22; // r1@68 | |
unsigned __int8 *v23; // r1@69 | |
void (*v24)(void); // r2@81 | |
char v25; // t1@86 | |
unsigned __int8 *v26; // r1@93 | |
int v27; // r0@94 | |
int v28; // r1@99 | |
char v29; // r0@105 | |
char *v30; // r5@111 | |
void *v31; // r12@113 | |
signed int v32; // r0@113 | |
int v33; // r1@113 | |
unsigned int v34; // r2@122 | |
char *v35; // r0@123 | |
signed int v36; // r1@123 | |
char v37; // t1@124 | |
void *v38; // r0@125 | |
char v39; // r7@126 | |
unsigned int v40; // r0@127 | |
char *v41; // r2@128 | |
char v42; // t1@128 | |
signed int v43; // r0@129 | |
char *v44; // r2@130 | |
char v45; // t1@130 | |
int v46; // r1@131 | |
signed int v47; // r0@131 | |
int v48; // r2@132 | |
unsigned int v49; // r0@133 | |
unsigned __int8 v50; // r2@134 | |
unsigned int v51; // r0@136 | |
int *v52; // r0@141 | |
char v53; // r1@142 | |
char v54; // r1@144 | |
char v55; // r1@146 | |
char v56; // r0@147 | |
unsigned int v57; // r0@138 | |
signed int v58; // r0@149 | |
int v59; // r2@150 | |
char v60; // r7@139 | |
int v61; // r3@139 | |
signed int i; // r0@163 | |
char v63; // t1@164 | |
char v64[399]; // [sp+0h] [bp-1D8h]@1 | |
unsigned __int8 v65[15]; // [sp+190h] [bp-48h]@1 | |
char v66[16]; // [sp+1A0h] [bp-38h]@138 | |
unsigned __int8 v67[4]; // [sp+1B0h] [bp-28h]@111 | |
memset(&v64[8], 0, 0x187u); | |
memset(v65, 0, 0xFu); | |
cmd = pkt[1]; | |
len = (unsigned __int16)(pkt[2] + (pkt[3] << 8)); | |
b4 = pkt[4]; | |
pkt_data = pkt + 7; | |
crc8(bt, pkt, 6u); | |
if ( len ) | |
crc8(bt, pkt_data, len); | |
if ( bt->field_27B != 3 ) | |
{ | |
printf_disabled("wiredCmdProcess got wrong packet\n"); | |
return; | |
} | |
if ( cmd == 0x10 ) | |
{ | |
if ( b4 | len || *(_BYTE *)(bt->dword1D4 + 4) == 2 ) | |
{ | |
v64[8] = 0x94u; | |
v64[9] = 16; | |
goto LABEL_92; | |
} | |
(*(void (**)(void))(*(_DWORD *)bt->dword44 + 24))(); | |
v64[8] = 0x94u; | |
v64[9] = 16; | |
v64[12] = 0; | |
*(_WORD *)&v64[10] = 0; | |
v64[13] = 0; | |
v64[14] = crc8(bt, (unsigned __int8 *)&v64[8], 6u); | |
sub_21CB94(1, (unsigned __int8 *)&v64[8], *(unsigned __int16 *)&v64[10] + 7); | |
bt->dword268 = dword_6FBC8(); | |
(*(void (**)(void))(*(_DWORD *)bt->dword1D4 + 20))(); | |
bt->dword268 = dword_6FBC8(); | |
if ( v64[12] ) | |
return; | |
v24 = *(void (**)(void))(*(_DWORD *)bt->dword1D4 + 8); | |
LABEL_100: | |
v24(); | |
return; | |
} | |
if ( cmd <= 0x10 ) | |
{ | |
switch ( cmd ) | |
{ | |
case 0: | |
return; | |
case 1: | |
if ( b4 || len && len > 0x14 ) | |
{ | |
v65[4] = 0xF; | |
} | |
else | |
{ | |
v9 = &v65[8]; | |
if ( strncmp_or_memcmp(hid_device_name, "Joy-Con (L)", 11) ) | |
{ | |
if ( strncmp_or_memcmp(hid_device_name, "Pro Controller", 14) ) | |
{ | |
if ( strncmp_or_memcmp(hid_device_name, "Joy-Con Charging Grip", 21) ) | |
{ | |
if ( strncmp_or_memcmp(hid_device_name, "Joy-Con (R)", 11) | |
&& strncmp_or_memcmp(hid_device_name, "Joy-Con (R)", 11) ) | |
{ | |
v10 = -1; | |
} | |
else | |
{ | |
v10 = 2; | |
} | |
} | |
else | |
{ | |
v10 = 0x11; | |
} | |
} | |
else | |
{ | |
v10 = 3; | |
} | |
} | |
else | |
{ | |
v10 = 1; | |
} | |
v65[7] = v10; | |
v65[4] = 0; | |
v11 = ((int (__fastcall *)(_DWORD))word_50D22)(bt->dword44); | |
v12 = 0; | |
do | |
{ | |
v13 = 5 - v12++; | |
*v9++ = *(_BYTE *)(v11 + v13); | |
} | |
while ( v12 < 6 ); | |
v14 = bt + 1; | |
if ( len ) | |
memcpy(v14, pkt_data, len); | |
else | |
memset(v14, 0, 0x14u); | |
} | |
v65[0] = 0x94u; | |
v65[1] = 1; | |
*(_WORD *)&v65[2] = 8; | |
v65[5] = crc8(bt, &v65[7], 8u); | |
v65[6] = crc8(bt, v65, 6u); | |
v15 = 15; | |
v16 = v65; | |
goto LABEL_52; | |
case 2: | |
if ( b4 || len != 4 ) | |
{ | |
v64[12] = 0xF; | |
} | |
else | |
{ | |
v18 = *pkt_data; | |
bt->field_1E4 = v18; | |
nullsub_4(1, 7, (v18 << 29 >> 31) + 1); | |
nullsub_4(1, 15, ((unsigned int)(unsigned __int8)bt->field_1E4 >> 4) & 1); | |
sub_21C578(bt->field_1E4); | |
v64[12] = 0; | |
} | |
v64[8] = 0x94u; | |
v64[9] = 2; | |
v17 = 0; | |
*(_WORD *)&v64[10] = 0; | |
goto LABEL_104; | |
case 3: | |
if ( b4 | len ) | |
{ | |
*(_WORD *)&v64[10] = 4; | |
v64[12] = 0xF; | |
memset(&v64[15], 0, 4u); | |
} | |
else | |
{ | |
bt->field_1E4 = 0; | |
bt->field_1E4 |= ((int (__fastcall *)(_DWORD, signed int))word_6EB1A)(0, 4) == 0; | |
bt->field_1E4 |= 2 * (((int (__fastcall *)(signed int))word_6EB1A)(2) == 0); | |
v20 = &bt->field_1E4; | |
*v20 |= 4 * (((int (__fastcall *)(signed int, signed int))dword_6EB08[0])(1, 7) == 0); | |
*v20 |= 16 * ((unsigned __int8 (__fastcall *)(signed int, signed int))dword_6EB08[0])(1, 15); | |
*(_WORD *)&v64[10] = 4; | |
v64[12] = 0; | |
v21 = *v20; | |
v64[16] = 0; | |
v64[17] = 0; | |
bt = (struct_a1 *)(v20 - 484); | |
v64[15] = v21; | |
v64[18] = 0; | |
} | |
v64[8] = 0x94u; | |
v19 = 3; | |
break; | |
case 4: | |
if ( b4 || len != 4 ) | |
{ | |
v64[12] = 0xF; | |
} | |
else | |
{ | |
bt->field_1E5 = *pkt_data; | |
v64[12] = 0; | |
} | |
v64[8] = 0x94u; | |
v64[9] = 4; | |
*(_WORD *)&v64[10] = 0; | |
goto LABEL_93; | |
case 5: | |
if ( b4 | len ) | |
{ | |
*(_WORD *)&v64[10] = 4; | |
v64[12] = 0xF; | |
memset(&v64[15], 0, 4u); | |
} | |
else | |
{ | |
*(_WORD *)&v64[10] = 4; | |
v64[12] = 0; | |
v22 = bt->field_1E5; | |
v64[16] = 0; | |
v64[17] = 0; | |
v64[15] = v22; | |
v64[18] = 0; | |
} | |
v64[8] = 0x94u; | |
v19 = 5; | |
break; | |
case 6: | |
if ( b4 | len ) | |
{ | |
*(_WORD *)&v64[10] = 4; | |
v64[12] = 0xF; | |
memset(&v64[15], 0, 4u); | |
} | |
else | |
{ | |
v64[12] = 0; | |
*(_WORD *)&v64[15] = word_220C18; | |
v64[17] = 0; | |
*(_WORD *)&v64[10] = 4; | |
v64[18] = 0; | |
} | |
v64[8] = 0x94u; | |
v19 = 6; | |
break; | |
case 7: | |
if ( b4 | len ) | |
{ | |
*(_WORD *)&v64[10] = 4; | |
v64[12] = 0xF; | |
memset(&v64[15], 0, 4u); | |
} | |
else | |
{ | |
*(_WORD *)&v64[10] = 4; | |
v64[12] = 0; | |
v64[15] = bt->field_1E8; | |
v64[16] = (unsigned __int16)bt->field_1E8 >> 8; | |
v64[17] = 0; | |
v64[18] = 0; | |
bt->field_1E8 = 0; | |
} | |
v64[8] = 0x94u; | |
v19 = 7; | |
break; | |
} | |
v64[9] = v19; | |
LABEL_166: | |
v34 = *(unsigned __int16 *)&v64[10]; | |
goto LABEL_69; | |
} | |
if ( cmd != 24 ) | |
{ | |
if ( cmd > 24 ) | |
{ | |
if ( cmd == 0x20 ) | |
{ | |
if ( !b4 && len == 8 ) | |
{ | |
*(_DWORD *)v64 = 0; | |
*(_DWORD *)&v64[4] = 0; | |
memcpy(&v64[2], pkt_data, 4u); | |
bt->field_1EC = *pkt_data + (pkt_data[1] << 8) + (pkt_data[2] << 16) + (pkt_data[3] << 24); | |
v64[8] = 0x94u; | |
v64[9] = 0x20; | |
v64[12] = 0; | |
*(_WORD *)&v64[10] = 0; | |
v64[13] = 0; | |
v64[14] = crc8(bt, (unsigned __int8 *)&v64[8], 6u); | |
sub_21CB94(1, (unsigned __int8 *)&v64[8], *(unsigned __int16 *)&v64[10] + 7); | |
sub_21C70A((unsigned __int8 *)v64); | |
((void (__fastcall *)(_DWORD))dword_52648[0])(*(_DWORD *)&bt->gap21E[26]); | |
((void (__fastcall *)(_DWORD, signed int))dword_52620[0])(*(_DWORD *)&bt->gap21E[26], 2000); | |
return; | |
} | |
v64[8] = 0x94u; | |
v64[9] = 32; | |
v64[12] = 0xF; | |
*(_WORD *)&v64[10] = 0; | |
v64[13] = 0; | |
v23 = (unsigned __int8 *)&v64[8]; | |
goto LABEL_157; | |
} | |
if ( cmd != 64 ) | |
return; | |
if ( b4 || !len ) | |
{ | |
v64[8] = 0x94u; | |
v64[9] = 64; | |
v34 = 0; | |
*(_WORD *)&v64[10] = 0; | |
v64[12] = 0xF; | |
goto LABEL_69; | |
} | |
v64[8] = 0x94u; | |
v64[9] = 64; | |
*(_WORD *)&v64[10] = len; | |
v64[12] = 0; | |
if ( len > 0x180 ) | |
len = 384; | |
for ( i = 0; i < (signed int)len; ++i ) | |
{ | |
v63 = *pkt_data++; | |
v64[i + 15] = v63; | |
} | |
goto LABEL_166; | |
} | |
if ( cmd == 0x11 ) | |
{ | |
if ( !(b4 | len) && *(_BYTE *)(bt->dword1D4 + 4) == 2 ) | |
{ | |
v64[8] = 0x94u; | |
v64[9] = 17; | |
v64[12] = 0; | |
*(_WORD *)&v64[10] = 0; | |
v64[13] = 0; | |
v64[14] = crc8(bt, (unsigned __int8 *)&v64[8], 6u); | |
*(_DWORD *)v64 = 1; | |
*(_DWORD *)&v64[4] = 0; | |
(*(void (__cdecl **)(_DWORD, char *))(*(_DWORD *)bt->dword1D4 + 36))(bt->dword1D4, &v64[8]); | |
delay(50000); | |
(*(void (**)(void))(*(_DWORD *)bt->dword1D4 + 24))(); | |
v25 = bt->gap27C[0]; | |
sub_219500(bt, 1000000u); | |
return; | |
} | |
v64[8] = 0x94u; | |
v64[9] = 17; | |
goto LABEL_92; | |
} | |
if ( cmd != 18 ) | |
{ | |
if ( cmd != 19 ) | |
return; | |
if ( !(b4 | len) && *(_BYTE *)(bt->dword1D4 + 4) == 2 ) | |
{ | |
v64[8] = 0x94u; | |
v64[9] = 19; | |
*(_WORD *)&v64[10] = 4; | |
v64[12] = 0; | |
v29 = *((_BYTE *)&bt->field_1E8 + 2); | |
v64[16] = 0; | |
v64[15] = v29; | |
v64[17] = 0; | |
v64[18] = 0; | |
v64[13] = crc8(bt, (unsigned __int8 *)&v64[15], 4u); | |
v64[14] = crc8(bt, (unsigned __int8 *)&v64[8], 6u); | |
*(_DWORD *)v64 = 1; | |
*(_DWORD *)&v64[4] = 0; | |
(*(void (__cdecl **)(_DWORD, char *))(*(_DWORD *)bt->dword1D4 + 36))(bt->dword1D4, &v64[8]); | |
return; | |
} | |
v64[8] = 0x94u; | |
v64[9] = 19; | |
*(_WORD *)&v64[10] = 4; | |
v64[12] = 0xF; | |
memset(&v64[15], 0, 4u); | |
v17 = crc8(bt, (unsigned __int8 *)&v64[15], 4u); | |
LABEL_104: | |
v64[13] = v17; | |
v26 = (unsigned __int8 *)&v64[8]; | |
goto LABEL_63; | |
} | |
if ( b4 || len != 4 || *(_BYTE *)(bt->dword1D4 + 4) != 2 ) | |
{ | |
v64[8] = 0x94u; | |
v64[9] = 0x12; | |
LABEL_92: | |
*(_WORD *)&v64[10] = 0; | |
v64[12] = 0xF; | |
LABEL_93: | |
v64[13] = 0; | |
v26 = (unsigned __int8 *)&v64[8]; | |
LABEL_63: | |
v64[14] = crc8(bt, v26, 6u); | |
v15 = 7; | |
goto LABEL_158; | |
} | |
v27 = *pkt_data; | |
*((_BYTE *)&bt->field_1E8 + 2) = v27; | |
v64[12] = v27 != 5 && v27 != 10 && v27 != 15; | |
v64[8] = 0x94u; | |
v64[9] = 0x12; | |
*(_WORD *)&v64[10] = 0; | |
v64[13] = 0; | |
v64[14] = crc8(bt, (unsigned __int8 *)&v64[8], 6u); | |
*(_DWORD *)v64 = 1; | |
*(_DWORD *)&v64[4] = 0; | |
(*(void (__cdecl **)(_DWORD, char *))(*(_DWORD *)bt->dword1D4 + 36))(bt->dword1D4, &v64[8]); | |
if ( v64[12] ) | |
return; | |
v28 = 1000 * *((unsigned __int8 *)&bt->field_1E8 + 2); | |
v24 = *(void (**)(void))(*(_DWORD *)bt->dword1D4 + 8); | |
goto LABEL_100; | |
} | |
if ( len != 0x20 || b4 != 1 && b4 != 2 && b4 != 3 && b4 != 4 ) | |
goto LABEL_121; | |
v30 = &v64[15]; | |
*(_DWORD *)v67 = 0x82500; | |
memset(&v64[15], 0, 0x20u); | |
*(_DWORD *)&v64[4] = (char *)bt + 496; | |
if ( b4 == 4 ) | |
{ | |
if ( !((int (__fastcall *)(_DWORD))word_4E602)(*(_DWORD *)(bt->dword44 + 24)) ) | |
goto LABEL_170; | |
v31 = (void *)(*(int (**)(void))(**(_DWORD **)(bt->dword44 + 24) + 52))(); | |
v32 = 6; | |
v33 = 0; | |
do | |
{ | |
*((_BYTE *)&bt->field_1EC + v32 + 3) = pkt_data[v33]; | |
v32 = (unsigned __int8)(v32 - 1); | |
v33 = (unsigned __int8)(v33 + 1); | |
} | |
while ( v32 ); | |
if ( strncmp_or_memcmp(*(void **)&v64[4], v31, 6) ) | |
LABEL_170: | |
b4 = 1; | |
} | |
if ( b4 == 1 ) | |
{ | |
v35 = &bt->bdaddr[5]; | |
v36 = 0; | |
do | |
{ | |
v37 = *pkt_data++; | |
++v36; | |
*v35-- = v37; | |
} | |
while ( v36 < 6 ); | |
v38 = (void *)(*(int (**)(void))(**(_DWORD **)(bt->dword44 + 24) + 52))(); | |
if ( !strncmp_or_memcmp(*(void **)&v64[4], v38, 6) ) | |
{ | |
v39 = sflash_available; | |
sflash_available = 0; | |
(*(void (**)(void))(*(_DWORD *)bt->dword44 + 160))(); | |
sflash_available = v39; | |
} | |
v40 = 0; | |
do | |
{ | |
v41 = &bt->gap0[v40]; | |
v42 = *pkt_data++; | |
++v40; | |
v41[518] = v42; | |
} | |
while ( v40 < 3 ); | |
memset(bt->field_209, 0, 0x14u); | |
v43 = 0; | |
do | |
{ | |
v44 = &bt->gap0[v43]; | |
v45 = *pkt_data++; | |
++v43; | |
v44[521] = v45; | |
} | |
while ( v43 < 20 ); | |
bt->field_209[20] = *pkt_data; | |
v46 = ((int (__fastcall *)(_DWORD))word_50D22)(bt->dword44); | |
v47 = 0; | |
do | |
{ | |
v48 = 5 - v47++; | |
*v30++ = *(_BYTE *)(v46 + v48); | |
} | |
while ( v47 < 6 ); | |
v49 = 0; | |
do | |
{ | |
v50 = v67[v49++]; | |
*v30++ = v50; | |
} | |
while ( v49 < 3 ); | |
if ( hid_device_type == 1 ) | |
{ | |
v52 = &dword_0; | |
do | |
{ | |
v53 = *((_BYTE *)v52 + (_DWORD)"Joy-Con (L)"); | |
v52 = (int *)((char *)v52 + 1); | |
*v30++ = v53; | |
} | |
while ( (unsigned int)v52 < 0xC ); | |
} | |
else | |
{ | |
v51 = (unsigned int)&dword_0; | |
if ( hid_device_type == 3 ) | |
{ | |
do | |
{ | |
v55 = aProControlle_1[v51++]; | |
*v30++ = v55; | |
} | |
while ( v51 < 0xF ); | |
} | |
else | |
{ | |
do | |
{ | |
v54 = aJoyConR_1[v51++]; | |
*v30++ = v54; | |
} | |
while ( v51 < 0xC ); | |
} | |
} | |
v30[8] = 0x68; | |
v56 = 1; | |
goto LABEL_152; | |
} | |
*(_DWORD *)v64 = (char *)bt + 502; | |
switch ( b4 ) | |
{ | |
case 2: | |
memset(bt->field_1F6, 0, 0x10u); | |
sub_DAC68(*(unsigned __int8 **)v64); | |
memcpy(v66, *(void **)v64, 0x10u); | |
v57 = 0; | |
do | |
{ | |
v66[v57] ^= 0xAAu; | |
v57 = (unsigned __int8)(v57 + 1); | |
} | |
while ( v57 < 0x10 ); | |
v58 = 0; | |
do | |
{ | |
v59 = 15 - v58++; | |
*v30++ = v66[v59]; | |
} | |
while ( v58 < 16 ); | |
v56 = 2; | |
goto LABEL_152; | |
case 3: | |
v60 = sflash_available; | |
sflash_available = 0; | |
v61 = (unsigned __int8)bt->field_209[20]; | |
(*(void (**)(void))(**(_DWORD **)(bt->dword44 + 24) + 20))(); | |
sflash_available = v60; | |
LABEL_153: | |
v56 = 3; | |
LABEL_152: | |
v64[12] = v56; | |
goto LABEL_122; | |
case 4: | |
goto LABEL_153; | |
} | |
LABEL_121: | |
v64[12] = 0xF; | |
memset(&v64[15], 0, 0x20u); | |
LABEL_122: | |
v64[8] = 0x94u; | |
v64[9] = 0x18; | |
v34 = 0x20; | |
*(_WORD *)&v64[10] = 0x20; | |
LABEL_69: | |
v64[13] = crc8(bt, (unsigned __int8 *)&v64[15], v34); | |
v23 = (unsigned __int8 *)&v64[8]; | |
LABEL_157: | |
v64[14] = crc8(bt, v23, 6u); | |
v15 = *(unsigned __int16 *)&v64[10] + 7; | |
LABEL_158: | |
v16 = (unsigned __int8 *)&v64[8]; | |
LABEL_52: | |
sub_21CB94(1, v16, v15); | |
} | |
void __fastcall handle_cmd_01(struct_a1 *bt, unsigned __int8 *buf) | |
{ | |
unsigned __int8 v2; // r3@1 | |
signed int subcmd; // r2@2 | |
unsigned __int8 v4; // r0@12 | |
v2 = 3; | |
if ( !byte_22122C[0] ) | |
{ | |
byte_22122C[0] = 0x21; | |
byte_22122C[14] = buf[10]; | |
subcmd = buf[10]; | |
if ( subcmd == 0x28 ) | |
{ | |
v4 = handle_cmd_01_28(bt, buf); | |
goto LABEL_43; | |
} | |
if ( subcmd > 0x28 ) | |
{ | |
if ( subcmd == 0x41 ) | |
{ | |
v4 = handle_cmd_01_41(bt, buf); | |
goto LABEL_43; | |
} | |
if ( subcmd <= 0x41 ) | |
{ | |
if ( subcmd == 0x30 ) | |
{ | |
v4 = handle_cmd_01_30(bt, buf); | |
goto LABEL_43; | |
} | |
if ( subcmd <= 0x30 ) | |
{ | |
switch ( subcmd ) | |
{ | |
case 0x29: | |
handle_cmd_01_29(); | |
return; | |
case 0x2A: | |
handle_cmd_01_2a(bt, buf); | |
return; | |
case 0x2B: | |
handle_cmd_01_2b(); | |
return; | |
} | |
goto def_21D858; | |
} | |
switch ( subcmd ) | |
{ | |
case 0x31: | |
handle_cmd_01_31(bt); | |
return; | |
case 0x38: | |
v4 = handle_cmd_01_38(bt, buf); | |
goto LABEL_43; | |
case 0x40: | |
v4 = handle_cmd_01_40(bt, buf); | |
goto LABEL_43; | |
} | |
def_21D858: | |
byte_22122C[13] = (unsigned int)&dword_64[7]; | |
byte_22122C[15] = v2; | |
return; | |
} | |
if ( subcmd == 0x50 ) | |
{ | |
handle_cmd_01_50(); | |
return; | |
} | |
if ( subcmd > 0x50 ) | |
{ | |
if ( subcmd != 0x51 ) | |
{ | |
if ( subcmd == 0x52 ) | |
{ | |
handle_cmd_01_52(); | |
return; | |
} | |
goto def_21D858; | |
} | |
v4 = handle_cmd_01_51(bt, buf); | |
goto LABEL_43; | |
} | |
if ( subcmd == 0x42 ) | |
{ | |
v4 = handle_cmd_01_42(bt, buf); | |
goto LABEL_43; | |
} | |
if ( subcmd == 0x43 ) | |
{ | |
handle_cmd_01_43(bt, buf); | |
return; | |
} | |
if ( subcmd != 0x48 ) | |
goto def_21D858; | |
} | |
else | |
{ | |
if ( subcmd == 8 ) | |
{ | |
sflash_set_5000(bt, buf); | |
goto LABEL_43; | |
} | |
if ( subcmd <= 8 ) | |
{ | |
switch ( subcmd ) | |
{ | |
case 1: | |
handle_cmd_01_01(bt, buf); | |
return; | |
case 2: | |
handle_cmd_01_02(bt); | |
return; | |
case 3: | |
byte_220BF9 = buf[11]; | |
goto LABEL_49; | |
case 4: | |
handle_cmd_01_04(bt); | |
return; | |
case 5: | |
v4 = handle_cmd_01_05((int)bt); | |
goto LABEL_43; | |
case 6: | |
v4 = handle_cmd_01_06(bt, buf); | |
goto LABEL_43; | |
case 7: | |
v4 = sflash_erase_2000(bt); | |
goto LABEL_43; | |
default: | |
goto def_21D858; | |
} | |
goto def_21D858; | |
} | |
if ( subcmd != 0x20 ) | |
{ | |
if ( subcmd > 0x20 ) | |
{ | |
if ( subcmd == 0x21 ) | |
{ | |
handle_cmd_01_21(bt, buf); | |
return; | |
} | |
if ( subcmd != 0x22 ) | |
goto def_21D858; | |
v4 = handle_cmd_01_22(bt, buf); | |
goto LABEL_43; | |
} | |
switch ( subcmd ) | |
{ | |
case 0x10: | |
handle_sflash_read(bt, buf); | |
return; | |
case 0x11: | |
v4 = handle_sflash_write(bt, buf); | |
goto LABEL_43; | |
case 0x12: | |
v4 = handle_sflash_erase(bt, buf); | |
LABEL_43: | |
v2 = v4; | |
goto def_21D858; | |
} | |
goto def_21D858; | |
} | |
sub_21E63A(); | |
} | |
LABEL_49: | |
v2 = 0; | |
goto def_21D858; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If I upload this code to my joy-con, what is happening?