//
// CCTextInputNode::insertAtCursor from 0x6c4bac to 0x6c4ed8 (812 bytes)
//
// 4 xrefs:
// > CCTextInputNode::pasteText @ 0x6c4f10
// > CCTextInputNode::onTextFieldInsertText @ 0x6c54e4
// > EmotePickerPopup::onPickEmote @ 0xcba5b8
// > ??> @ 0x59ff8
//
// 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:20 +0000
//
__int64 __fastcall CCTextInputNode::insertAtCursor(__int64 a1, __int64 a2)
{
size_t v4; // x1
size_t v6; // x0
int v7; // w1
int v8; // w23
int v9; // w0
int v10; // w2
int v11; // w1
int v12; // w0
unsigned __int8 v13; // w3
size_t v14; // x1
char *v15; // x2
size_t v16; // x3
int v17; // w22
int v18; // w0
__int64 v19; // x22
int v20; // w1
char *v21; // [xsp+48h] [xbp+48h]
__int64 v22; // [xsp+50h] [xbp+50h] BYREF
size_t v23; // [xsp+58h] [xbp+58h]
void *v24; // [xsp+60h] [xbp+60h]
__int64 v25; // [xsp+68h] [xbp+68h] BYREF
size_t v26; // [xsp+70h] [xbp+70h]
void *v27; // [xsp+78h] [xbp+78h]
__int64 v28; // [xsp+80h] [xbp+80h] BYREF
size_t v29; // [xsp+88h] [xbp+88h]
void *v30; // [xsp+90h] [xbp+90h]
if ( *(int *)(a1 + 504) > 0 )
{
EmoteSprite::translateUnicodeEmoji(&v28, a2);
if ( (*(_BYTE *)a2 & 1) != 0 )
{
**(_BYTE **)(a2 + 16) = 0;
*(_QWORD *)(a2 + 8) = 0;
}
else
{
*(_BYTE *)(a2 + 1) = 0;
*(_BYTE *)a2 = 0;
}
std::string::reserve((__int64 *)a2, 0);
*(_QWORD *)(a2 + 16) = v30;
v4 = v29;
*(_QWORD *)a2 = v28;
*(_QWORD *)(a2 + 8) = v4;
}
sub_6C2C04((unsigned __int8 *)a2, *(_BYTE *)(a1 + 625), a1 + 472, *(_BYTE *)(a1 + 624), &v22);
if ( (v22 & 1) != 0 )
{
if ( !v23 )
{
LABEL_7:
operator delete(v24);
return _stack_chk_guard;
}
}
else if ( !((int)(unsigned __int8)v22 >> 1) )
{
return _stack_chk_guard;
}
v21 = (char *)(*(__int64 (__fastcall **)(_QWORD))(**(_QWORD **)(a1 + 576) + 1248LL))(*(_QWORD *)(a1 + 576));
v25 = 0;
v26 = 0;
v27 = nullptr;
v6 = strlen(v21);
std::string::__init(&v25, v21, v6);
v7 = *(_DWORD *)(*(_QWORD *)(a1 + 576) + 752LL);
if ( v7 < 0 )
{
v9 = (unsigned __int8)v25;
v10 = v25 & 1;
v8 = (unsigned __int8)v25 >> 1;
if ( v10 )
{
v8 = v26;
LABEL_13:
v11 = v26;
if ( v8 <= (int)v26 )
goto LABEL_14;
goto LABEL_36;
}
}
else
{
v8 = sub_6B7D64((__int64)&v25, v7);
v9 = (unsigned __int8)v25;
v10 = v25 & 1;
}
if ( v10 )
goto LABEL_13;
v11 = v9 >> 1;
if ( v8 <= v9 >> 1 )
{
LABEL_14:
if ( v8 > 0 )
goto LABEL_15;
LABEL_37:
v13 = v22;
v14 = 0;
v8 = 0;
if ( (v22 & 1) != 0 )
goto LABEL_18;
LABEL_38:
v16 = v13 >> 1;
v15 = (char *)&v22 + 1;
goto LABEL_19;
}
LABEL_36:
if ( v11 <= 0 )
goto LABEL_37;
LABEL_15:
if ( v10 )
{
v12 = v26;
if ( v8 <= (int)v26 )
goto LABEL_17;
}
else
{
v12 = v9 >> 1;
if ( v8 <= v12 )
goto LABEL_17;
}
v8 = v12;
LABEL_17:
v13 = v22;
v14 = v8;
if ( (v22 & 1) == 0 )
goto LABEL_38;
LABEL_18:
v15 = (char *)v24;
v16 = v23;
LABEL_19:
std::string::insert(&v25, v14, v15, v16);
v17 = *(_DWORD *)(a1 + 592);
if ( v17 > 0 && v17 < (int)sub_6B7CD0((__int64)&v25) )
{
v18 = sub_6B7D64((__int64)&v25, v17);
std::string::resize((unsigned __int8 *)&v25, v18, 0);
}
v28 = 0;
v29 = 0;
v30 = nullptr;
if ( (v25 & 1) != 0 )
{
std::string::__init(&v28, v27, v26);
}
else
{
v30 = v27;
v28 = v25;
v29 = v26;
}
CCTextInputNode::setString((_QWORD *)a1, (char *)&v28);
if ( (v28 & 1) != 0 )
operator delete(v30);
v19 = *(_QWORD *)(a1 + 576);
if ( (*(_DWORD *)(v19 + 752) & 0x80000000) == 0 )
{
v20 = (unsigned __int8)v22 >> 1;
if ( (v22 & 1) != 0 )
v20 = v23;
*(_DWORD *)(v19 + 752) = sub_6B75E4((__int64)&v25, v8 + v20);
CCTextInputNode::updateBlinkLabel((CCTextInputNode *)a1);
}
if ( (v25 & 1) != 0 )
operator delete(v27);
if ( (v22 & 1) != 0 )
goto LABEL_7;
return _stack_chk_guard;
}