//
// cocos2d::CCTextFieldTTF::insertText from 0x10027c480 to 0x10027c6f3 (627 bytes)
//
// 2 xrefs:
// > sub_10027C740 @ 0x10027c74c
// > ??> @ 0x1008f0840
//
// 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 __fastcall cocos2d::CCTextFieldTTF::insertText(
cocos2d::CCTextFieldTTF *a1,
const char *a2,
int a3,
cocos2d::enumKeyCodes a4)
{
double v4; // xmm0_8
cocos2d::enumKeyCodes v5; // r14d
int v6; // r12d
cocos2d::CCTextFieldTTF *v7; // rbx
std::string::size_type v8; // r15
char *data; // r13
size_t v11; // r14
int v12; // eax
int v13; // r15d
cocos2d::CCTextFieldDelegate *m_pDelegate; // rdi
std::string::__long::$5C0822F47C3855276CFDD0C01D0AA610 *v15; // rdx
const std::string::value_type *v16; // r12
std::string::pointer v17; // rax
char v18; // dl
char *v19; // rax
int v20; // ecx
std::string *m_pInputText; // rax
signed __int64 m_uCursorPos; // rsi
std::string::__short::$7162EEB0FEF29CC674EFA33D0008C7E0 v23; // al
std::string::pointer v24; // rdi
std::string::size_type v25; // rcx
std::string::size_type size; // rdx
std::string::pointer v27; // rsi
cocos2d::CCTextFieldDelegate *v28; // rdi
std::string v29; // [rsp+10h] [rbp-60h] BYREF
std::string __dst[2]; // [rsp+30h] [rbp-40h] BYREF
if ( (unsigned int)a3 >= 0xFFFFFFF8 )
sub_100006BF0(v4);
v5 = a4;
v6 = a3;
v7 = a1;
v8 = a3;
if ( (unsigned int)a3 >= 0x17 )
{
v11 = 26;
if ( (a3 | 7LL) != 0x17 )
v11 = (a3 | 7LL) + 1;
data = (char *)operator new(v11);
__dst[0].__r_.__value_.__r.__words[2] = (std::string::size_type)data;
__dst[0].__r_.__value_.__r.__words[0] = v11 + 1;
v5 = a4;
v7 = a1;
__dst[0].__r_.__value_.__l.__size_ = v8;
goto LABEL_8;
}
__dst[0].__r_.__value_.__s.0 = (std::string::__short::$7162EEB0FEF29CC674EFA33D0008C7E0)(2 * a3);
data = __dst[0].__r_.__value_.__s.__data_;
if ( a3 )
LABEL_8:
memcpy(data, a2, v8);
data[v8] = 0;
v12 = std::string::find(__dst, 10, 0);
v13 = v12;
if ( v12 != -1 )
{
std::string::erase(__dst, v12, 0xFFFFFFFFFFFFFFFFLL);
v6 = v13;
}
if ( v6 <= 0 )
goto LABEL_41;
m_pDelegate = v7->m_pDelegate;
if ( m_pDelegate )
{
v15 = (*(_BYTE *)&__dst[0].__r_.__value_.__s.0 & 1) != 0
? (std::string::__long::$5C0822F47C3855276CFDD0C01D0AA610 *)__dst[0].__r_.__value_.__r.__words[2]
: (std::string::__long::$5C0822F47C3855276CFDD0C01D0AA610 *)((char *)&__dst[0].__r_.__value_.__l.0 + 1);
if ( ((unsigned __int8 (__fastcall *)(cocos2d::CCTextFieldDelegate *, cocos2d::CCTextFieldTTF *, std::string::__long::$5C0822F47C3855276CFDD0C01D0AA610 *, _QWORD, _QWORD))m_pDelegate->onTextFieldInsertText)(
m_pDelegate,
v7,
v15,
(unsigned int)v6,
(unsigned int)v5) )
{
goto LABEL_45;
}
}
v16 = __dst[0].__r_.__value_.__s.__data_;
v17 = __dst[0].__r_.__value_.__s.__data_;
if ( (*(_BYTE *)&__dst[0].__r_.__value_.__s.0 & 1) != 0 )
v17 = __dst[0].__r_.__value_.__l.__data_;
v18 = *v17;
if ( *v17 )
{
v19 = v17 + 1;
v20 = 0;
do
{
v20 += !__OFSUB__(-(v18 & 0xC0), 1);
v18 = *v19++;
}
while ( v18 );
v7->m_nCharCount += v20;
m_pInputText = (std::string *)v7->m_pInputText;
if ( (*(_BYTE *)&m_pInputText->__r_.__value_.__s.0 & 1) == 0 )
goto LABEL_23;
}
else
{
v7->m_nCharCount = v7->m_nCharCount;
m_pInputText = (std::string *)v7->m_pInputText;
if ( (*(_BYTE *)&m_pInputText->__r_.__value_.__s.0 & 1) == 0 )
{
LABEL_23:
v29 = *m_pInputText;
goto LABEL_26;
}
}
sub_100006B70(&v29, m_pInputText->__r_.__value_.__l.__data_, m_pInputText->__r_.__value_.__l.__size_, v4);
LABEL_26:
m_uCursorPos = v7->m_uCursorPos;
if ( m_uCursorPos < 0 )
{
v23 = __dst[0].__r_.__value_.__s.0;
v24 = __dst[0].__r_.__value_.__l.__data_;
LABEL_31:
if ( (*(_BYTE *)&v23 & 1) != 0 )
{
size = __dst[0].__r_.__value_.__l.__size_;
v16 = v24;
}
else
{
size = *(unsigned __int8 *)&v23 >> 1;
}
std::string::append(&v29, v16, size);
if ( (*(_BYTE *)&v29.__r_.__value_.__s.0 & 1) == 0 )
goto LABEL_38;
LABEL_35:
v27 = v29.__r_.__value_.__l.__data_;
goto LABEL_39;
}
v23 = __dst[0].__r_.__value_.__s.0;
v24 = __dst[0].__r_.__value_.__l.__data_;
if ( (int)m_uCursorPos >= v7->m_nCharCount )
goto LABEL_31;
if ( (*(_BYTE *)&__dst[0].__r_.__value_.__s.0 & 1) != 0 )
{
v16 = __dst[0].__r_.__value_.__l.__data_;
v25 = __dst[0].__r_.__value_.__l.__size_;
}
else
{
v25 = *(_BYTE *)&__dst[0].__r_.__value_.__l.0 >> 1;
}
std::string::insert(&v29, m_uCursorPos, v16, v25);
++v7->m_uCursorPos;
if ( (*(_BYTE *)&v29.__r_.__value_.__s.0 & 1) != 0 )
goto LABEL_35;
LABEL_38:
v27 = v29.__r_.__value_.__s.__data_;
LABEL_39:
((void (__fastcall *)(cocos2d::CCTextFieldTTF *, std::string::pointer))v7->setString)(v7, v27);
if ( (*(_BYTE *)&v29.__r_.__value_.__s.0 & 1) != 0 )
operator delete(v29.__r_.__value_.__l.__data_);
LABEL_41:
if ( v13 != -1 )
{
v28 = v7->m_pDelegate;
if ( !v28
|| !((unsigned __int8 (__fastcall *)(cocos2d::CCTextFieldDelegate *, cocos2d::CCTextFieldTTF *, const std::string::value_type *, __int64, _QWORD))v28->onTextFieldInsertText)(
v28,
v7,
"\n",
1,
(unsigned int)v5) )
{
((void (__fastcall *)(cocos2d::CCTextFieldTTF *))v7->detachWithIME)(v7);
}
}
LABEL_45:
if ( (*(_BYTE *)&__dst[0].__r_.__value_.__s.0 & 1) != 0 )
operator delete(__dst[0].__r_.__value_.__l.__data_);
}