//
// cocos2d::extension::WebSocket::init from 0xd20210 to 0xd2086c (1628 bytes)
//
// 1 xrefs:
// > ??> @ 0xbbc78
//
// This function is hookable on this platform (idp: arm, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 13:07:11 +0000
//
bool __fastcall cocos2d::extension::WebSocket::init(__int64 a1, __int64 a2, char *a3, __int64 *a4)
{
char v7; // w0
__int64 v8; // x0
size_t v9; // x1
unsigned __int8 v10; // w1
int v11; // w19
char *v12; // x25
size_t v13; // x0
char *v14; // x23
__int64 v15; // x0
char *v16; // x25
size_t v17; // x0
char *v18; // x23
__int64 v19; // x0
int v20; // w25
size_t v21; // x23
char *v22; // x26
__int64 v23; // x23
__int64 v24; // x0
int v25; // w26
size_t v26; // x3
char *v27; // x19
int v28; // w23
size_t v29; // x0
int v30; // w19
size_t v31; // x1
char *v32; // x28
char *v33; // x19
__int64 v34; // x0
int v35; // w19
size_t v36; // x3
size_t v37; // x2
char *v38; // x1
char *v39; // x27
size_t v40; // x0
char *v41; // x19
__int64 v42; // x0
unsigned __int64 v43; // x2
__int64 *v44; // x0
__int64 *v45; // x0
unsigned __int64 v46; // x19
unsigned __int64 v47; // x0
unsigned __int64 v48; // x19
void *v49; // x0
__int64 v50; // x19
__int64 i; // x20
__int64 v52; // x0
char *v53; // x2
const char *v54; // x1
__int64 v55; // x0
cocos2d::extension::WsThreadHelper *v56; // x19
_BOOL4 Thread; // w19
char *v59; // x0
__int64 v60; // [xsp+68h] [xbp+68h] BYREF
size_t v61; // [xsp+70h] [xbp+70h]
void *v62; // [xsp+78h] [xbp+78h]
__int64 v63[2]; // [xsp+80h] [xbp+80h] BYREF
char *v64; // [xsp+90h] [xbp+90h]
__int64 v65; // [xsp+98h] [xbp+98h] BYREF
size_t v66; // [xsp+A0h] [xbp+A0h]
void *v67; // [xsp+A8h] [xbp+A8h]
__int64 v68[2]; // [xsp+B0h] [xbp+B0h] BYREF
void *v69; // [xsp+C0h] [xbp+C0h]
v60 = 0;
v61 = 0;
v7 = *a3;
v62 = nullptr;
if ( (v7 & 1) != 0 )
{
std::string::__init(&v60, *((void **)a3 + 2), *((_QWORD *)a3 + 1));
}
else
{
v8 = *(_QWORD *)a3;
v9 = *((_QWORD *)a3 + 1);
v62 = *((void **)a3 + 2);
v60 = v8;
v61 = v9;
}
v10 = v60;
*(_QWORD *)(a1 + 96) = a2;
v11 = v10 & 1;
if ( (v10 & 1) != 0 )
{
v12 = (char *)v62;
v13 = v61;
}
else
{
v13 = v10 >> 1;
v12 = (char *)&v60 + 1;
}
if ( v13 > 4 )
{
v14 = &v12[v13];
v15 = std::__search(
(__int64)v12,
(__int64)&v12[v13],
"ws://",
(unsigned __int8 *)"",
(unsigned __int8 (__fastcall *)(__int64, _QWORD))std::char_traits::eq);
if ( v14 != (char *)v15 && (_DWORD)v15 == (_DWORD)v12 )
std::string::erase((char *)&v60, 0, 5u);
v10 = v60;
v11 = v60 & 1;
}
if ( v11 )
{
v16 = (char *)v62;
v17 = v61;
}
else
{
v17 = v10 >> 1;
v16 = (char *)&v60 + 1;
}
if ( v17 <= 5 )
{
LABEL_30:
v20 = 0;
if ( v11 )
goto LABEL_17;
goto LABEL_31;
}
v18 = &v16[v17];
v19 = std::__search(
(__int64)v16,
(__int64)&v16[v17],
"wss://",
(unsigned __int8 *)"",
(unsigned __int8 (__fastcall *)(__int64, _QWORD))std::char_traits::eq);
if ( v18 == (char *)v19 )
{
v10 = v60;
v11 = v60 & 1;
goto LABEL_30;
}
if ( (_DWORD)v19 == (_DWORD)v16 )
{
std::string::erase((char *)&v60, 0, 6u);
v10 = v60;
v20 = 1;
}
else
{
v10 = v60;
v20 = 0;
}
v11 = v60 & 1;
if ( (v60 & 1) != 0 )
{
LABEL_17:
v21 = v61;
v22 = (char *)v62;
if ( !v61 )
goto LABEL_32;
goto LABEL_18;
}
LABEL_31:
v21 = v10 >> 1;
v22 = (char *)&v60 + 1;
if ( !(v10 >> 1) )
goto LABEL_32;
LABEL_18:
v23 = (__int64)&v22[v21];
v24 = std::__search(
(__int64)v22,
v23,
(unsigned __int8 *)":",
(unsigned __int8 *)"",
(unsigned __int8 (__fastcall *)(__int64, _QWORD))std::char_traits::eq);
if ( v23 == v24 )
{
v10 = v60;
v11 = v60 & 1;
LABEL_32:
v29 = -1;
v28 = 80;
if ( v11 )
goto LABEL_26;
goto LABEL_33;
}
v25 = v24 - (_DWORD)v22;
if ( v25 < 0 )
{
v10 = v60;
v29 = v25;
v28 = 80;
v30 = v60 & 1;
}
else
{
v26 = (unsigned __int8)v60 >> 1;
if ( (v60 & 1) != 0 )
v26 = v61;
std::string::basic_string(v63, (__int64)&v60, v25 + 1, v26);
if ( (v63[0] & 1) != 0 )
{
v27 = v64;
v28 = atoi(v64);
operator delete(v27);
}
else
{
v28 = atoi((const char *)v63 + 1);
}
v10 = v60;
v29 = v25;
v30 = v60 & 1;
}
if ( v30 )
{
LABEL_26:
v31 = v61;
v32 = (char *)v62;
if ( v29 >= v61 )
goto LABEL_34;
goto LABEL_27;
}
LABEL_33:
v31 = v10 >> 1;
v32 = (char *)&v60 + 1;
if ( v29 >= v31 )
goto LABEL_34;
LABEL_27:
v33 = &v32[v31];
v34 = std::__search(
(__int64)&v32[v29],
(__int64)&v32[v31],
(unsigned __int8 *)&word_11BA098,
(unsigned __int8 *)&word_11BA098 + 1,
(unsigned __int8 (__fastcall *)(__int64, _QWORD))std::char_traits::eq);
if ( v33 != (char *)v34 )
{
v35 = v34 - (_DWORD)v32;
goto LABEL_35;
}
LABEL_34:
v35 = -1;
LABEL_35:
v65 = 0;
v66 = 0;
v67 = nullptr;
std::string::__init(&v65, &word_11BA098, 1u);
if ( (v35 & 0x80000000) == 0 )
{
v36 = (unsigned __int8)v60 >> 1;
if ( (v60 & 1) != 0 )
v36 = v61;
std::string::basic_string(v68, (__int64)&v60, v35 + 1, v36);
if ( (v68[0] & 1) != 0 )
{
v38 = (char *)v69;
v37 = v68[1];
}
else
{
v37 = LOBYTE(v68[0]) >> 1;
v38 = (char *)v68 + 1;
}
std::string::append((__int64)&v65, v38, v37);
if ( (v68[0] & 1) != 0 )
operator delete(v69);
}
if ( (v60 & 1) != 0 )
{
v39 = (char *)v62;
v40 = v61;
}
else
{
v40 = (unsigned __int8)v60 >> 1;
v39 = (char *)&v60 + 1;
}
if ( v40 )
{
v41 = &v39[v40];
v42 = std::__search(
(__int64)v39,
(__int64)&v39[v40],
(unsigned __int8 *)":",
(unsigned __int8 *)"",
(unsigned __int8 (__fastcall *)(__int64, _QWORD))std::char_traits::eq);
if ( v41 != (char *)v42 && (((_DWORD)v42 - (_DWORD)v39) & 0x80000000) == 0 )
{
v43 = (unsigned __int8)v60 >> 1;
if ( (v60 & 1) != 0 )
v43 = v61;
std::string::erase((char *)&v60, (int)v42 - (int)v39, v43);
}
}
v44 = (__int64 *)(a1 + 16);
if ( (__int64 *)(a1 + 16) != &v60 )
{
if ( (v60 & 1) != 0 )
std::string::assign(v44, v62, v61);
else
std::string::assign(v44, (char *)&v60 + 1, (unsigned __int8)v60 >> 1);
}
v45 = (__int64 *)(a1 + 48);
*(_DWORD *)(a1 + 40) = v28;
if ( (__int64 *)(a1 + 48) != &v65 )
{
if ( (v65 & 1) != 0 )
std::string::assign(v45, v67, v66);
else
std::string::assign(v45, (char *)&v65 + 1, (unsigned __int8)v65 >> 1);
}
*(_DWORD *)(a1 + 104) = v20;
if ( a4 && (v46 = 0xAAAAAAAAAAAAAAABLL * ((a4[1] - *a4) >> 3)) != 0 )
{
v47 = -1;
v48 = (int)v46 + 1;
if ( v48 <= 0x2A8000000000000LL )
v47 = 48 * v48;
}
else
{
v47 = 96;
v48 = 2;
}
v49 = (void *)operator new[](v47);
*(_QWORD *)(a1 + 112) = v49;
memset(v49, 0, 48 * v48);
if ( a4 )
{
v50 = *a4;
for ( i = 0; a4[1] != v50; *(_QWORD *)(v55 + 8) = cocos2d::extension::WebSocketCallbackWrapper::onSocketCallback )
{
v52 = *(_BYTE *)v50 >> 1;
if ( (*(_BYTE *)v50 & 1) != 0 )
v52 = *(_QWORD *)(v50 + 8);
v53 = (char *)operator new[](v52 + 1);
v54 = (const char *)(v50 + 1);
if ( (*(_BYTE *)v50 & 1) != 0 )
v54 = *(const char **)(v50 + 16);
v50 += 24;
*(_QWORD *)(*(_QWORD *)(a1 + 112) + i) = strcpy(v53, v54);
v55 = *(_QWORD *)(a1 + 112) + i;
i += 48;
}
}
else
{
v59 = (char *)operator new[](0x14u);
strcpy(v59, "default-protocol");
**(_QWORD **)(a1 + 112) = v59;
*(_QWORD *)(*(_QWORD *)(a1 + 112) + 8LL) = cocos2d::extension::WebSocketCallbackWrapper::onSocketCallback;
}
v56 = (cocos2d::extension::WsThreadHelper *)operator new(0xB0u);
cocos2d::extension::WsThreadHelper::WsThreadHelper(v56);
*(_QWORD *)(a1 + 72) = v56;
Thread = cocos2d::extension::WsThreadHelper::createThread(v56, (const cocos2d::extension::WebSocket *)a1);
if ( (v65 & 1) != 0 )
operator delete(v67);
if ( (v60 & 1) != 0 )
operator delete(v62);
return Thread;
}