//
// EditorUI::onNewCustomItem from 0x1400e4030 to 0x1400e451f (1263 bytes)
//
// 2 xrefs:
// > EditorUI::createCustomItems @ 0x1400e4b2b
// > ??> @ 0x1406c8c58
//
// 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
//
// Hidden C++ exception states: #wind=7
void EditorUI::onNewCustomItem(EditorUI *a1, cocos2d::CCObject *a2)
{
cocos2d::CCArray *m_selectedObjects; // rcx
cocos2d::CCString *v4; // rax
const char *CString; // rax
size_t v6; // rbx
size_t v7; // r8
__int128 *v8; // rdx
__int64 v9; // rax
FLAlertLayer *v10; // rbx
void *v11; // rcx
__int64 v12; // rcx
cocos2d::CCString *v13; // rax
const char *v14; // rax
size_t v15; // rbx
size_t v16; // r8
__int128 *v17; // rdx
__int64 v18; // rax
FLAlertLayer *v19; // rbx
GameObject *m_selectedObject; // rax
__int64 v21; // rcx
cocos2d::CCArray *v22; // rdi
__int64 v23; // rdx
__int64 v24; // rcx
__int64 v25; // r8
__int64 v26; // r9
void **v27; // r15
unsigned __int64 v28; // r14
__int64 v29; // rsi
__int64 v30; // rcx
void *v31; // [rsp+50h] [rbp-59h]
void *v32; // [rsp+58h] [rbp-51h]
__int128 v33; // [rsp+60h] [rbp-49h] BYREF
__int64 v34; // [rsp+70h] [rbp-39h]
__int64 v35; // [rsp+78h] [rbp-31h]
_BYTE v36[32]; // [rsp+80h] [rbp-29h] BYREF
__int128 v37; // [rsp+A0h] [rbp-9h] BYREF
unsigned __int64 v38; // [rsp+B0h] [rbp+7h]
unsigned __int64 v39; // [rsp+B8h] [rbp+Fh]
void *Src[2]; // [rsp+C0h] [rbp+17h] BYREF
unsigned __int64 v41; // [rsp+D0h] [rbp+27h]
unsigned __int64 v42; // [rsp+D8h] [rbp+2Fh]
m_selectedObjects = a1->m_selectedObjects;
if ( m_selectedObjects && cocos2d::CCArray::count(m_selectedObjects) > 0x3E8 )
{
v4 = cocos2d::CCString::createWithFormat("A custom object cannot contain more than %i objects.", 1000);
CString = cocos2d::CCString::getCString(v4);
v37 = 0;
v38 = 0;
v39 = 0;
v6 = -1;
v7 = -1;
do
++v7;
while ( CString[v7] );
sub_14003A930(&v37, CString, v7);
v8 = &v37;
if ( v39 > 0xF )
v8 = (__int128 *)v37;
v33 = 0;
v34 = 0;
v35 = 0;
do
++v6;
while ( *((_BYTE *)v8 + v6) );
sub_14003A930(&v33, v8, v6);
v9 = sub_14003BDB0((__int64)v36, (__int64)&v33);
v10 = FLAlertLayer::create(0, (int)"Max Limit", v9, (__int64)"OK", 0, 1135214592, 0, 0, 1065353216);
sub_14003A830((__int64)&v33);
v10->show(v10);
if ( v39 > 0xF )
{
v11 = (void *)v37;
if ( v39 + 1 < 0x1000 || (v11 = *(void **)(v37 - 8), (unsigned __int64)(v37 - (_QWORD)v11 - 8) <= 0x1F) )
{
LABEL_12:
j_j_free(v11);
return;
}
LABEL_25:
invalid_parameter_noinfo_noreturn();
}
}
else
{
v12 = qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v31 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00(v31);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v12 = qword_1406C2ED8;
}
if ( cocos2d::CCDictionary::count(*(cocos2d::CCDictionary **)(v12 + 424)) < 0xC8 )
{
if ( a1->m_selectedObject || cocos2d::CCArray::count(a1->m_selectedObjects) )
{
m_selectedObject = a1->m_selectedObject;
if ( !m_selectedObject || m_selectedObject->m_objectID != 749 )
{
if ( cocos2d::CCArray::count(a1->m_selectedObjects) )
{
v22 = a1->m_selectedObjects;
}
else
{
v22 = (cocos2d::CCArray *)cocos2d::CCArray::create(v21);
cocos2d::CCArray::addObject(v22, a1->m_selectedObject);
}
EditorUI::copyObjects(a1, Src, v22, 0, 0);
if ( v41 && cocos2d::CCArray::count(a1->m_selectedObjects) <= 0x3E8 )
{
v37 = 0;
v38 = 0;
v39 = 0;
v27 = Src;
if ( v42 > 0xF )
v27 = (void **)Src[0];
v28 = v41;
v29 = 0x7FFFFFFFFFFFFFFFLL;
if ( v41 > 0x7FFFFFFFFFFFFFFFLL )
sub_140007B50(v24, v23, v25, v26);
v39 = 15;
if ( v41 > 0xF )
{
if ( (v41 | 0xF) <= 0x7FFFFFFFFFFFFFFFLL )
{
v29 = v41 | 0xF;
if ( (v41 | 0xF) < 0x16 )
v29 = 22;
}
*(_QWORD *)&v37 = sub_14003AA10(v29 + 1);
v38 = v28;
v39 = v29;
memcpy((void *)v37, v27, v28 + 1);
}
else
{
v38 = v41;
v37 = *(_OWORD *)v27;
}
v30 = qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v32 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00(v32);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v30 = qword_1406C2ED8;
}
GameManager::addNewCustomObject(v30, &v37);
a1->m_selectedObjectIndex = 0;
EditorUI::reloadCustomItems(a1);
}
sub_14003A830((__int64)Src);
}
}
}
else
{
v13 = cocos2d::CCString::createWithFormat("You cannot create more than %i custom objects.", 200);
v14 = cocos2d::CCString::getCString(v13);
v37 = 0;
v38 = 0;
v39 = 0;
v15 = -1;
v16 = -1;
do
++v16;
while ( v14[v16] );
sub_14003A930(&v37, v14, v16);
v17 = &v37;
if ( v39 > 0xF )
v17 = (__int128 *)v37;
v33 = 0;
v34 = 0;
v35 = 0;
do
++v15;
while ( *((_BYTE *)v17 + v15) );
sub_14003A930(&v33, v17, v15);
v18 = sub_14003BDB0((__int64)v36, (__int64)&v33);
v19 = FLAlertLayer::create(0, (int)"Max Custom Objects", v18, (__int64)"OK", 0, 1135214592, 0, 0, 1065353216);
sub_14003A830((__int64)&v33);
v19->show(v19);
if ( v39 > 0xF )
{
v11 = (void *)v37;
if ( v39 + 1 < 0x1000 )
goto LABEL_12;
v11 = *(void **)(v37 - 8);
if ( (unsigned __int64)(v37 - (_QWORD)v11 - 8) <= 0x1F )
goto LABEL_12;
goto LABEL_25;
}
}
}
}