//
// sub_6C2C04 from 0x6c2c04 to 0x6c3010 (1036 bytes)
//
// 2 xrefs:
// > CCTextInputNode::insertAtCursor @ 0x6c4c34
// > CCTextInputNode::onTextFieldInsertText @ 0x6c52dc
//
// 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 12:51:19 +0000
//
__int64 *__usercall sub_6C2C04@(
unsigned __int8 *a1@,
unsigned __int8 a2@,
__int64 a3@,
unsigned __int8 a4@,
__int64 *a5@)
{
int v6; // w19
int v9; // w26
unsigned __int8 v10; // w0
unsigned __int64 v11; // x1
int v12; // w28
unsigned __int64 v13; // x20
char v14; // w27
unsigned __int64 v15; // x0
unsigned int v16; // w19
unsigned __int64 v17; // x24
int v18; // w1
unsigned __int64 v19; // x25
int v20; // w2
unsigned __int8 *v21; // x0
unsigned __int8 v22; // w0
unsigned __int8 *v23; // x4
unsigned __int8 v24; // w0
unsigned __int8 *v25; // x0
unsigned __int8 v26; // w0
unsigned __int64 v27; // x28
unsigned __int8 *v28; // x1
size_t v29; // x2
unsigned __int8 *v30; // x1
cocos2d::CCObject *v31; // x0
int v32; // w19
__int64 v34; // x24
unsigned __int8 *v35; // x19
__int64 v36; // x21
unsigned __int8 *i; // x21
__int64 v38; // x22
char v39; // w0
_BYTE *v40; // x22
int v41; // w20
int v42; // w22
__int64 v43; // x0
BitmapFontCache *v44; // x0
*a5 = 0;
a5[1] = 0;
v6 = a2;
a5[2] = 0;
v9 = a4;
v10 = *a1;
v11 = v10 >> 1;
if ( (v10 & 1) != 0 )
v11 = *((_QWORD *)a1 + 1);
std::string::reserve(a5, v11);
if ( v6 )
{
v12 = *a1;
v13 = 0;
v14 = v12 & 1;
while ( 1 )
{
if ( v14 )
{
v15 = *((_QWORD *)a1 + 1);
if ( v13 >= v15 )
return a5;
v16 = *(unsigned __int8 *)(*((_QWORD *)a1 + 2) + v13);
if ( (v16 & 0x80) == 0 )
goto LABEL_8;
if ( (v16 & 0xE0) == 0xC0 )
{
v19 = 2;
v17 = v13 + 2;
v18 = 2;
goto LABEL_18;
}
}
else
{
v20 = v12 >> 1;
v15 = v12 >> 1;
if ( v13 >= v15 )
return a5;
v16 = a1[v13 + 1];
if ( (v16 & 0x80) == 0 )
{
LABEL_8:
v17 = v13 + 1;
v18 = 1;
v19 = 1;
goto LABEL_18;
}
if ( (v16 & 0xE0) == 0xC0 )
{
v19 = 2;
v17 = v13 + 2;
v18 = 2;
LABEL_51:
v15 = v20;
goto LABEL_18;
}
}
if ( (v16 & 0xF0) == 0xE0 )
{
v19 = 3;
v18 = 3;
}
else
{
if ( (v16 & 0xF8) != 0xF0 )
goto LABEL_14;
v19 = 4;
v18 = 4;
}
v17 = v19 + v13;
v20 = v12 >> 1;
if ( !v14 )
goto LABEL_51;
v15 = *((_QWORD *)a1 + 1);
LABEL_18:
if ( v17 > v15 )
{
LABEL_14:
++v13;
}
else
{
switch ( v18 )
{
case 2:
v32 = v16 & 0x1F;
goto LABEL_23;
case 3:
v32 = v16 & 0xF;
goto LABEL_23;
case 4:
v32 = v16 & 7;
LABEL_23:
v21 = a1 + 1;
if ( v14 )
v21 = *((unsigned __int8 **)a1 + 2);
v22 = v21[v13 + 1];
if ( (v22 & 0xC0) == 0x80 )
{
v16 = v22 & 0x3F | (v32 << 6);
if ( v18 <= 2 )
goto LABEL_35;
v23 = a1 + 1;
if ( v14 )
v23 = *((unsigned __int8 **)a1 + 2);
v24 = v23[v13 + 2];
if ( (v24 & 0xC0) == 0x80 )
{
v16 = v24 & 0x3F | (v16 << 6);
if ( v18 == 3 )
goto LABEL_35;
v25 = a1 + 1;
if ( v14 )
v25 = *((unsigned __int8 **)a1 + 2);
v26 = v25[v13 + 3];
if ( (v26 & 0xC0) == 0x80 )
{
v16 = v26 & 0x3F | (v16 << 6);
goto LABEL_35;
}
}
}
++v13;
break;
default:
LABEL_35:
if ( (unsigned __int8)sub_6B7A78(v16, v9) )
goto LABEL_44;
if ( v16 > 0x7F )
{
v31 = (cocos2d::CCObject *)qword_155C0F8;
if ( !qword_155C0F8 )
{
v44 = (BitmapFontCache *)BitmapFontCache::sharedFontCache(nullptr);
v31 = BitmapFontCache::fontWithConfigFile(v44, "chatFont.fnt", 1.0);
qword_155C0F8 = (__int64)v31;
if ( !v31 )
goto LABEL_43;
}
if ( !FontObject::hasGlyph(v31, v16) )
goto LABEL_43;
LOBYTE(v12) = *a1;
if ( (*a1 & 1) == 0 )
{
LABEL_48:
v27 = (unsigned __int8)v12 >> 1;
if ( v13 > v27 )
LABEL_84:
sub_62B8E4();
v28 = a1 + 1;
goto LABEL_40;
}
}
else if ( !v14 )
{
goto LABEL_48;
}
v27 = *((_QWORD *)a1 + 1);
if ( v13 > v27 )
goto LABEL_84;
v28 = *((unsigned __int8 **)a1 + 2);
LABEL_40:
v29 = v27 - v13;
v30 = &v28[v13];
if ( v27 - v13 > v19 )
v29 = v19;
std::string::append((__int64)a5, v30, v29);
LABEL_43:
v12 = *a1;
v14 = v12 & 1;
LABEL_44:
v13 = v17;
break;
}
}
}
}
v34 = *(_BYTE *)a3 >> 1;
if ( (*(_BYTE *)a3 & 1) != 0 )
v34 = *(_QWORD *)(a3 + 8);
if ( (*a1 & 1) != 0 )
{
v35 = *((unsigned __int8 **)a1 + 2);
v36 = *((_QWORD *)a1 + 1);
}
else
{
v35 = a1 + 1;
v36 = *a1 >> 1;
}
for ( i = &v35[v36]; i != v35; ++v35 )
{
v41 = *v35;
if ( v34 && (v41 != 10 || !v9) && std::string::find(a3, v41, 0) == -1 )
continue;
v42 = *(unsigned __int8 *)a5;
if ( (v42 & 1) != 0 )
{
v38 = a5[1];
if ( (*a5 & 0xFFFFFFFFFFFFFFFELL) - 1 != v38 )
goto LABEL_75;
}
else
{
v38 = v42 >> 1;
if ( (_DWORD)v38 != 22 )
goto LABEL_67;
v38 = 22;
}
std::string::__grow_by((__int64)a5, v38, 1u, v38, v38, 0, 0);
if ( (*(_BYTE *)a5 & 1) != 0 )
{
LABEL_75:
v43 = a5[2];
a5[1] = v38 + 1;
v40 = (_BYTE *)(v43 + v38);
goto LABEL_68;
}
LABEL_67:
v39 = v38 + 1;
v40 = (char *)a5 + v38 + 1;
*(_BYTE *)a5 = 2 * v39;
LABEL_68:
*v40 = v41;
v40[1] = 0;
}
return a5;
}