//
// cocos2d::CCTextFieldTTF::setString from 0x10027cc30 to 0x10027ce93 (611 bytes)
//
// 2 xrefs:
// > sub_10027CEC0 @ 0x10027cecc
// > ??> @ 0x1008f07e0
//
// 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::setString(cocos2d::CCTextFieldTTF *a1, const char *a2)
{
const char *v2; // r14
std::string *m_pInputText; // r15
std::string *v4; // r15
size_t v5; // rax
size_t v6; // r12
char *elems; // r13
std::string *v8; // rax
size_t v9; // r14
std::string *v10; // rax
unsigned int sizex2; // r12d
std::size_t size; // r12
std::string *v13; // rcx
unsigned int v14; // eax
const char *data; // rsi
std::string *m_pPlaceHolder; // rsi
std::string *v17; // rax
std::array *longStorage; // rax
char v19; // dl
char *v20; // rax
int v21; // ecx
cocos2d::CCTextFieldDelegate *m_pDelegate; // rdi
std::string v23; // [rsp+10h] [rbp-40h] BYREF
v2 = a2;
memset(&v23, 0, sizeof(v23));
m_pInputText = a1->m_pInputText;
if ( m_pInputText )
{
if ( (m_pInputText->m_data.m_short.sizex2 & 1) != 0 )
operator delete(m_pInputText->m_data.m_long.longStorage);
operator delete(m_pInputText);
a1->m_pInputText = nullptr;
}
if ( !a2 )
{
v8 = (std::string *)operator new(0x18u);
*(_OWORD *)&v8->m_data.m_short.sizex2 = 0;
v8->m_data.m_long.longStorage = nullptr;
a1->m_pInputText = v8;
goto LABEL_21;
}
v4 = (std::string *)operator new(0x18u);
v5 = strlen(a2);
if ( v5 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100006BF0(0.0);
v6 = v5;
if ( v5 >= 0x17 )
{
v9 = 26;
if ( (v5 | 7) != 0x17 )
v9 = (v5 | 7) + 1;
elems = (char *)operator new(v9);
v4->m_data.m_long.longStorage = elems;
v4->m_data.m_long.capacitym1 = v9 | 1;
v4->m_data.m_long.size = v6;
v2 = a2;
goto LABEL_14;
}
v4->m_data.m_short.sizex2 = 2 * v5;
elems = v4->m_data.m_short.shortStorage.__elems_;
if ( v5 )
LABEL_14:
memcpy(elems, v2, v6);
elems[v6] = 0;
a1->m_pInputText = v4;
std::string::operator=(&v23, (const std::string *)v4);
if ( !a1->m_bSecureTextEntry )
goto LABEL_21;
std::string::assign(&v23, "");
v10 = a1->m_pInputText;
sizex2 = v10->m_data.m_short.sizex2;
if ( (sizex2 & 1) != 0 )
{
size = v10->m_data.m_long.size;
if ( !(_DWORD)size )
goto LABEL_21;
}
else
{
LODWORD(size) = sizex2 >> 1;
if ( !(_DWORD)size )
goto LABEL_21;
}
do
{
std::string::append(&v23, &byte_10099C6BC);
LODWORD(size) = size - 1;
}
while ( (_DWORD)size );
LABEL_21:
v13 = a1->m_pInputText;
v14 = v13->m_data.m_short.sizex2;
if ( (v14 & 1) != 0 )
{
if ( v13->m_data.m_long.size )
{
LABEL_23:
if ( (*(_BYTE *)&v23.__r_.__value_.__s.0 & 1) != 0 )
data = v23.__r_.__value_.__l.__data_;
else
data = v23.__r_.__value_.__s.__data_;
goto LABEL_30;
}
}
else if ( v14 >> 1 )
{
goto LABEL_23;
}
m_pPlaceHolder = a1->m_pPlaceHolder;
if ( (m_pPlaceHolder->m_data.m_short.sizex2 & 1) != 0 )
data = m_pPlaceHolder->m_data.m_long.longStorage;
else
data = m_pPlaceHolder->m_data.m_short.shortStorage.__elems_;
LABEL_30:
cocos2d::CCLabelTTF::setString(a1, data);
v17 = a1->m_pInputText;
if ( (v17->m_data.m_short.sizex2 & 1) != 0 )
{
longStorage = (std::array *)v17->m_data.m_long.longStorage;
v19 = longStorage->__elems_[0];
if ( longStorage->__elems_[0] )
goto LABEL_32;
LABEL_37:
a1->m_nCharCount = 0;
m_pDelegate = a1->m_pDelegate;
if ( !m_pDelegate )
goto LABEL_39;
goto LABEL_38;
}
longStorage = &v17->m_data.m_short.shortStorage;
v19 = longStorage->__elems_[0];
if ( !longStorage->__elems_[0] )
goto LABEL_37;
LABEL_32:
v20 = &longStorage->__elems_[1];
v21 = 0;
do
{
v21 += !__OFSUB__(-(v19 & 0xC0), 1);
v19 = *v20++;
}
while ( v19 );
a1->m_nCharCount = v21;
m_pDelegate = a1->m_pDelegate;
if ( !m_pDelegate )
goto LABEL_39;
LABEL_38:
((void (__fastcall *)(cocos2d::CCTextFieldDelegate *))m_pDelegate->textChanged)(m_pDelegate);
LABEL_39:
if ( (*(_BYTE *)&v23.__r_.__value_.__s.0 & 1) != 0 )
operator delete(v23.__r_.__value_.__l.__data_);
}