//
// cocos2d::CCTextFieldTTF::insertText from 0xb2ffa8 to 0xb30298 (752 bytes)
//
// 3 xrefs:
// > `non-virtual thunk to'cocos2d::CCTextFieldTTF::insertText @ 0xb3029c
// > ??> @ 0x91398
// > ??> @ 0x121a078
//
// 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
//
void cocos2d::CCTextFieldTTF::insertText(cocos2d::CCTextFieldTTF *a1, const char *a2, int a3, cocos2d::enumKeyCodes a4)
{
int v4; // w25
long double v7; // q0
int v8; // w0
int v9; // w20
unsigned __int64 v10; // x3
cocos2d::CCTextFieldDelegate *m_pDelegate; // x0
const unsigned __int8 *v12; // x20
unsigned __int8 *v13; // x23
const unsigned __int8 *v14; // x1
int v15; // w2
int v16; // w0
int v17; // w3
int v18; // t1
int m_uCursorPos; // w1
unsigned __int8 *v20; // x0
cocos2d::CCTextFieldDelegate *v21; // x0
unsigned int *v22; // x20
int v23; // w0
unsigned int *v24; // x20
unsigned int *v25; // x1
int v26; // w2
const unsigned __int8 *v27; // [xsp+58h] [xbp+58h] BYREF
const unsigned __int8 *v28; // [xsp+60h] [xbp+60h] BYREF
v4 = a3;
sub_D1527C(&v27, a2, a3, &v28);
v8 = sub_D16674(&v27, 10, 0, v7);
v9 = v8;
if ( v8 == -1 )
{
if ( v4 <= 0 )
goto LABEL_6;
LABEL_4:
m_pDelegate = a1->m_pDelegate;
if ( m_pDelegate && m_pDelegate->onTextFieldInsertText(m_pDelegate, a1, v27, v4, a4) )
goto LABEL_6;
v14 = v27;
v15 = 0;
LOBYTE(v16) = *v27;
if ( *v27 )
{
do
{
v17 = v16 & 0xC0;
v18 = *++v14;
v16 = v18;
if ( v17 != 128 )
++v15;
}
while ( v16 );
}
a1->m_nCharCount += v15;
sub_D18D28(&v28);
m_uCursorPos = a1->m_uCursorPos;
if ( m_uCursorPos < 0 || m_uCursorPos >= a1->m_nCharCount )
{
sub_D15E14(&v28, &v27);
}
else
{
sub_D17B90(&v28, m_uCursorPos, v27, *((_QWORD *)v27 - 3));
++a1->m_uCursorPos;
}
a1->setString(a1, v28);
v20 = (unsigned __int8 *)(v28 - 24);
if ( v28 - 24 != (const unsigned __int8 *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v25 = (unsigned int *)(v28 - 8);
do
v26 = __ldaxr(v25);
while ( __stlxr(v26 - 1, v25) );
}
else
{
v26 = *((_DWORD *)v28 - 2);
*((_DWORD *)v28 - 2) = v26 - 1;
}
if ( v26 <= 0 )
operator delete(v20);
}
if ( v9 == -1 )
goto LABEL_6;
goto LABEL_17;
}
v10 = *((_QWORD *)v27 - 3);
if ( v8 > v10 )
sub_D13C5C("%s: __pos (which is %zu) > this->size() (which is %zu)", "basic_string::erase", v8, v10);
v4 = v8;
sub_D174B8(&v27, v8, v10 - v8, 0);
if ( v9 > 0 )
goto LABEL_4;
LABEL_17:
v21 = a1->m_pDelegate;
if ( !v21 || !v21->onTextFieldInsertText(v21, a1, (const unsigned __int8 *)&byte_F1AB78, 1, a4) )
{
a1->detachWithIME(a1);
v12 = v27;
v13 = (unsigned __int8 *)(v27 - 24);
if ( v27 - 24 == (const unsigned __int8 *)&qword_124B6B0 )
return;
if ( &pthread_create )
{
v22 = (unsigned int *)(v27 - 8);
do
v23 = __ldaxr(v22);
while ( __stlxr(v23 - 1, v22) );
goto LABEL_31;
}
goto LABEL_38;
}
LABEL_6:
v12 = v27;
v13 = (unsigned __int8 *)(v27 - 24);
if ( v27 - 24 == (const unsigned __int8 *)&qword_124B6B0 )
return;
if ( &pthread_create )
{
v24 = (unsigned int *)(v27 - 8);
do
v23 = __ldaxr(v24);
while ( __stlxr(v23 - 1, v24) );
goto LABEL_31;
}
LABEL_38:
v23 = *((_DWORD *)v12 - 2);
*((_DWORD *)v12 - 2) = v23 - 1;
LABEL_31:
if ( v23 <= 0 )
operator delete(v13);
}