//
// cocos2d::cc_utf16_to_utf8 from 0x180094e30 to 0x180095028 (504 bytes)
//
// 2 xrefs:
// > ??> @ 0x1801438a8
// > ??> @ 0x1801b6798
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
// Hidden C++ exception states: #wind=2
char *__fastcall cocos2d::cc_utf16_to_utf8(cocos2d *this, unsigned __int16 *a2, int *a3)
{
unsigned __int64 v6; // rcx
unsigned __int64 v7; // rdx
cocos2d *v8; // rax
int i; // edi
__int64 v10; // rbx
__int16 v11; // r9
void **v12; // rax
_BYTE *v13; // rbx
size_t v14; // rcx
_BYTE *v15; // rax
void **v16; // rdx
void *v17; // rcx
void *v18; // rcx
void *Src[2]; // [rsp+20h] [rbp-50h] BYREF
size_t Size; // [rsp+30h] [rbp-40h]
unsigned __int64 v21; // [rsp+38h] [rbp-38h]
void *Block[2]; // [rsp+40h] [rbp-30h] BYREF
unsigned __int64 v23; // [rsp+50h] [rbp-20h]
unsigned __int64 v24; // [rsp+58h] [rbp-18h]
if ( !this )
return nullptr;
*(_OWORD *)Block = 0;
v6 = 0;
v23 = 0;
v7 = 7;
v24 = 7;
LOWORD(Block[0]) = 0;
v8 = this;
for ( i = 0; *(_WORD *)v8; ++i )
v8 = (cocos2d *)((char *)v8 + 2);
if ( i > 0 )
{
v10 = 0;
while ( 1 )
{
v11 = *((_WORD *)this + v10);
if ( v6 >= v7 )
{
sub_180094960(Block, 1u, 0, v11);
}
else
{
v23 = v6 + 1;
v12 = Block;
if ( v7 > 7 )
v12 = (void **)Block[0];
*((_WORD *)v12 + v6) = v11;
*((_WORD *)v12 + v6 + 1) = 0;
}
if ( ++v10 >= i )
break;
v7 = v24;
v6 = v23;
}
}
v13 = nullptr;
*(_OWORD *)Src = 0;
v14 = 0;
Size = 0;
v21 = 15;
LOBYTE(Src[0]) = 0;
if ( !i )
goto LABEL_17;
if ( (unsigned __int8)sub_1800954A0(Block, Src, a3) )
{
v14 = Size;
LABEL_17:
v15 = operator new(v14 + 1);
v13 = v15;
v15[Size] = 0;
if ( i > 0 )
{
v16 = Src;
if ( v21 > 0xF )
v16 = (void **)Src[0];
memcpy(v15, v16, Size);
}
if ( a2 )
*(_DWORD *)a2 = Size;
}
if ( v21 > 0xF )
{
v17 = Src[0];
if ( v21 + 1 >= 0x1000 )
{
v17 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v17 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free_0(v17);
}
Size = 0;
v21 = 15;
LOBYTE(Src[0]) = 0;
if ( v24 > 7 )
{
v18 = Block[0];
if ( 2 * v24 + 2 >= 0x1000 )
{
v18 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v18 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free_0(v18);
}
return v13;
}