//
// EditorUI::createSmartObjectsFromTemplate from 0x6c1d64 to 0x6c2880 (2844 bytes)
//
// 3 xrefs:
// > SetupSmartBlockLayer::onCreate @ 0x9dc034
// > SetupSmartBlockLayer::onPasteTemplate @ 0x9dc494
// > ??> @ 0x61818
//
// 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 EditorUI::createSmartObjectsFromTemplate(
EditorUI *a1,
GJSmartTemplate *a2,
cocos2d::CCArray *a3,
bool a4,
bool a5,
bool a6,
bool a7)
{
unsigned int v10; // w20
cocos2d::CCArray *v11; // x0
_BOOL4 v12; // w22
GameObject *v13; // x0
SmartGameObject *v14; // x19
unsigned int v15; // w25
EditorUI *v16; // x23
__int64 v17; // x0
SmartGameObject *v18; // x20
__int64 v19; // x24
SmartGameObject *v20; // x27
SmartGameObject *v21; // x24
void *v22; // x0
void *v23; // x0
__int64 v24; // x1
void *v25; // x0
cocos2d::CCSize size; // x1
void *v27; // x0
void *v28; // x0
cocos2d::CCDictElement *m_pElements; // x0
cocos2d::CCDictElement *i; // x20
cocos2d::CCObject *m_pObject; // x19
unsigned int v32; // w19
cocos2d::CCArray *v33; // x22
unsigned int v34; // w1
SmartGameObject *v35; // x0
UndoObject *v36; // x0
__int64 v37; // x28
LevelEditorLayer *data; // x19
cocos2d::CCArray *v39; // x0
cocos2d::CCArray *v40; // x28
unsigned int v41; // w19
__int64 v42; // x23
unsigned int *v43; // x20
int v44; // w1
void *v45; // x0
const cocos2d::CCPoint *v46; // x0
float v47; // s8
cocos2d::CCArray *v48; // x27
unsigned int *v49; // x1
int v50; // w2
unsigned int *v51; // x1
int v52; // w2
cocos2d::CCPoint *v53; // x27
cocos2d::CCPoint v54; // x1
__int64 *v55; // x0
unsigned int *v56; // x1
int v57; // w2
unsigned int *v58; // x1
int v59; // w2
unsigned int *v60; // x1
int v61; // w2
unsigned int *v62; // x1
int v63; // w2
cocos2d::CCArray *v64; // x20
unsigned int v65; // w19
UndoObject *v66; // x0
unsigned int v67; // w1
GameObject *v68; // x0
_QWORD v69[2]; // [xsp+10h] [xbp+0h] BYREF
_BOOL4 v70; // [xsp+88h] [xbp+78h]
_BOOL4 v71; // [xsp+8Ch] [xbp+7Ch]
cocos2d::CCArray *v72; // [xsp+90h] [xbp+80h]
cocos2d::CCArray *v73; // [xsp+98h] [xbp+88h]
cocos2d::CCPoint *v74; // [xsp+A0h] [xbp+90h]
__int64 *v75; // [xsp+A8h] [xbp+98h]
cocos2d::CCArray *v76; // [xsp+B0h] [xbp+A0h]
_BOOL4 v77; // [xsp+B8h] [xbp+A8h]
_BOOL4 v78; // [xsp+BCh] [xbp+ACh]
cocos2d::CCDictionary *v79; // [xsp+C0h] [xbp+B0h]
GJSmartTemplate *v80; // [xsp+C8h] [xbp+B8h]
SmartGameObject *SmartNeighbor; // [xsp+D0h] [xbp+C0h]
SmartGameObject *v82; // [xsp+D8h] [xbp+C8h]
SmartGameObject *v83; // [xsp+E0h] [xbp+D0h]
SmartGameObject *v84; // [xsp+E8h] [xbp+D8h]
SmartGameObject *v85; // [xsp+F0h] [xbp+E0h]
cocos2d::CCArray *v86; // [xsp+F8h] [xbp+E8h]
cocos2d::CCPoint v87; // [xsp+108h] [xbp+F8h] BYREF
__int64 v88; // [xsp+110h] [xbp+100h] BYREF
__int64 v89; // [xsp+118h] [xbp+108h] BYREF
__int64 v90; // [xsp+120h] [xbp+110h] BYREF
cocos2d::CCPoint v91; // [xsp+128h] [xbp+118h] BYREF
cocos2d::CCRect v92; // [xsp+130h] [xbp+120h] BYREF
cocos2d::CCRect v93; // [xsp+140h] [xbp+130h] BYREF
__int64 v94; // [xsp+150h] [xbp+140h] BYREF
int v95; // [xsp+160h] [xbp+150h]
char v96; // [xsp+164h] [xbp+154h]
char v97; // [xsp+165h] [xbp+155h]
cocos2d::CCPoint v98; // 0:s0.4,4:s1.4
cocos2d::CCPoint v99; // 0:s0.4,4:s1.4
cocos2d::CCPoint v100; // 0:s0.4,4:s1.4
cocos2d::CCPoint v101; // 0:s0.4,4:s1.4
cocos2d::CCPoint v102; // 0:s0.4,4:s1.4
cocos2d::CCPoint v103; // 0:s0.4,4:s1.4
cocos2d::CCPoint v104; // 0:s0.4,4:s1.4
cocos2d::CCPoint v105; // 0:s0.4,4:s1.4
cocos2d::CCPoint v106; // 0:s0.4,4:s1.4
cocos2d::CCPoint v107; // 0:s0.4,4:s1.4
cocos2d::CCPoint v108; // 0:s0.4,4:s1.4
cocos2d::CCPoint v109; // 0:s1.4,4:s2.4
cocos2d::CCRect v110; // 0:s0.4,4:s1.4,8:s2.4,12:s3.4
v77 = a4;
v70 = a5;
v80 = a2;
v71 = a6;
v78 = a7;
if ( a3 && (unsigned int)cocos2d::CCArray::count(a3) && a2 )
{
v10 = 0;
GJSmartTemplate::resetScannedPrefabs(v80);
EditorUI::deselectAll(a1);
v72 = (cocos2d::CCArray *)cocos2d::CCArray::create(v11);
v73 = (cocos2d::CCArray *)cocos2d::CCArray::create(v72);
v76 = (cocos2d::CCArray *)cocos2d::CCArray::create(v73);
v79 = cocos2d::CCDictionary::create();
v86 = (cocos2d::CCArray *)a1;
v12 = v77;
if ( (unsigned int)cocos2d::CCArray::count(a3) )
{
do
{
v13 = (GameObject *)cocos2d::CCArray::objectAtIndex(a3, v10);
v14 = (SmartGameObject *)v13;
if ( (unsigned int)(v13->m_objectID - 2896) <= 1 )
{
GameObject::determineSlopeDirection(v13);
if ( v12 )
{
LABEL_32:
v37 = (__int64)v14->getPosition(v14);
GJSmartTemplate::offsetForObject(v14);
cocos2d::CCPoint::operator+(&v91, v37, &v93);
cocos2d::CCRect::CCRect(&v92, v91.x - 37.5, v91.y - 37.5, 75.0, 75.0);
data = (LevelEditorLayer *)v86[19].data;
cocos2d::CCRect::CCRect(&v93, &v92);
v39 = LevelEditorLayer::objectsInRect(data, v110, (unsigned __int8)v69 + 48);
v40 = v39;
if ( v39 && (unsigned int)cocos2d::CCArray::count(v39) )
{
v41 = 0;
while ( v41 < (unsigned int)cocos2d::CCArray::count(v40) )
{
v42 = cocos2d::CCArray::objectAtIndex(v40, v41);
if ( *(_DWORD *)(v42 + 1232) != 5
|| (unsigned __int8)cocos2d::CCArray::containsObject(a3, (cocos2d::CCObject *)v42) )
{
++v41;
}
else
{
++v41;
cocos2d::CCArray::addObject(a3, (cocos2d::CCObject *)v42);
cocos2d::CCDictionary::setObject(v79, (cocos2d::CCObject *)v42, *(unsigned int *)(v42 + 900));
(*(void (__fastcall **)(__int64, _QWORD))(*(_QWORD *)v42 + 72LL))(
v42,
*(unsigned __int8 *)(v42 + 1331));
*(_BYTE *)(v42 + 1331) = 1;
}
}
}
}
}
else if ( v12 )
{
goto LABEL_32;
}
++v10;
}
while ( v10 < (unsigned int)cocos2d::CCArray::count(a3) );
}
v74 = (cocos2d::CCPoint *)&v92;
v75 = &v94;
v15 = 0;
v16 = (EditorUI *)v86;
if ( (unsigned int)cocos2d::CCArray::count(a3) )
{
while ( 1 )
{
v17 = cocos2d::CCArray::objectAtIndex(a3, v15);
v18 = (SmartGameObject *)v17;
if ( *(_BYTE *)(v17 + 1331) )
{
if ( !cocos2d::CCDictionary::objectForKey(v79, *(unsigned int *)(v17 + 900)) )
{
++v15;
cocos2d::CCArray::addObject(v73, v18);
goto LABEL_18;
}
goto LABEL_17;
}
v19 = (*(__int64 (__fastcall **)(__int64))(*(_QWORD *)v17 + 192LL))(v17);
GJSmartTemplate::offsetForObject(v18);
cocos2d::CCPoint::operator+(&v87, v19, &v93);
cocos2d::CCPoint::CCPoint(&v93.origin, &v87);
SmartNeighbor = EditorUI::getSmartNeighbor(
v16,
v18,
v98,
(GJSmartDirection)((unsigned int)v69 + 304),
(cocos2d::CCArray *)((char *)&dword_0 + 1));
cocos2d::CCPoint::CCPoint(&v93.origin, &v87);
v20 = EditorUI::getSmartNeighbor(
v16,
v18,
v99,
(GJSmartDirection)((unsigned int)v69 + 304),
(cocos2d::CCArray *)((char *)&dword_0 + 2));
cocos2d::CCPoint::CCPoint(&v93.origin, &v87);
v21 = EditorUI::getSmartNeighbor(
v16,
v18,
v100,
(GJSmartDirection)((unsigned int)v69 + 304),
(cocos2d::CCArray *)((char *)&dword_0 + 3));
cocos2d::CCPoint::CCPoint(&v93.origin, &v87);
v82 = EditorUI::getSmartNeighbor(
v16,
v18,
v101,
(GJSmartDirection)((unsigned int)v69 + 304),
(cocos2d::CCArray *)&byte_4);
cocos2d::CCPoint::CCPoint(&v93.origin, &v87);
v83 = EditorUI::getSmartNeighbor(
v16,
v18,
v102,
(GJSmartDirection)((unsigned int)v69 + 304),
(cocos2d::CCArray *)&byte_5);
cocos2d::CCPoint::CCPoint(&v93.origin, &v87);
v84 = EditorUI::getSmartNeighbor(
v16,
v18,
v103,
(GJSmartDirection)((unsigned int)v69 + 304),
(cocos2d::CCArray *)&byte_6);
cocos2d::CCPoint::CCPoint(&v93.origin, &v87);
v85 = EditorUI::getSmartNeighbor(
v16,
v18,
v104,
(GJSmartDirection)((unsigned int)v69 + 304),
(cocos2d::CCArray *)&byte_7);
cocos2d::CCPoint::CCPoint(&v93.origin, &v87);
v86 = (cocos2d::CCArray *)EditorUI::getSmartNeighbor(
v16,
v18,
v105,
(GJSmartDirection)((unsigned int)v69 + 304),
(cocos2d::CCArray *)byte_8);
cocos2d::CCPoint::CCPoint(&v93.origin, &v87);
GJSmartTemplate::keyFromNeighbors(
(GJSmartTemplate *)&v93,
v106,
v18,
SmartNeighbor,
v20,
v21,
v82,
v83,
v84,
v85,
(SmartGameObject *)v86);
sub_D18D28(&v89, &v88);
GJSmartTemplate::scanForPrefab(v80, (std::string)&v89);
v22 = (void *)(v89 - 24);
if ( (__int64 *)(v89 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v58 = (unsigned int *)(v89 - 8);
do
v59 = __ldaxr(v58);
while ( __stlxr(v59 - 1, v58) );
}
else
{
v59 = *(_DWORD *)(v89 - 8);
*(_DWORD *)(v89 - 8) = v59 - 1;
}
if ( v59 <= 0 )
operator delete(v22);
}
if ( !*(_QWORD *)&v93.origin )
break;
cocos2d::CCArray::addObject(v76, v18);
sub_D18D28(&v90, v75);
sub_D18EA8(&v18->m_baseFrame, &v90);
v23 = (void *)(v90 - 24);
if ( (__int64 *)(v90 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v60 = (unsigned int *)(v90 - 8);
do
v61 = __ldaxr(v60);
while ( __stlxr(v61 - 1, v60) );
}
else
{
v61 = *(_DWORD *)(v90 - 8);
*(_DWORD *)(v90 - 8) = v61 - 1;
}
if ( v61 <= 0 )
operator delete(v23);
}
if ( v78 )
goto LABEL_14;
sub_D18D28(&v91, *(_QWORD *)&v93.origin + 64LL);
v86 = EditorUI::pasteObjects(v16, (const void **)&v91, 0, 1u);
v45 = (void *)(*(_QWORD *)&v91 - 24LL);
if ( (__int64 *)(*(_QWORD *)&v91 - 24LL) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v62 = (unsigned int *)(*(_QWORD *)&v91 - 8LL);
do
v63 = __ldaxr(v62);
while ( __stlxr(v63 - 1, v62) );
}
else
{
v63 = *(_DWORD *)(*(_QWORD *)&v91 - 8LL);
*(_DWORD *)(*(_QWORD *)&v91 - 8LL) = v63 - 1;
}
if ( v63 <= 0 )
operator delete(v45);
}
if ( !v86 || !(unsigned int)cocos2d::CCArray::count(v86) )
goto LABEL_14;
v46 = v18->getPosition(v18);
cocos2d::CCPoint::CCPoint(&v91, v46);
cocos2d::CCPoint::CCPoint(v74, &v91);
EditorUI::repositionObjectsToCenter(v16, v86, v107, (bool)v74);
if ( v97 )
EditorUI::flipObjectsY(v16, v86);
if ( v96 )
EditorUI::flipObjectsX(v16, v86);
if ( v95 > 0 )
{
v47 = (float)-v95;
cocos2d::CCPoint::CCPoint(v74, (const cocos2d::CCPoint *)&dword_1242110);
EditorUI::rotateObjects(v16, v86, v47, v109);
}
cocos2d::CCPoint::CCPoint(v74, &v91);
v48 = v86;
EditorUI::repositionObjectsToCenter(v16, v86, v108, (bool)v74);
EditorUI::deleteSmartBlocksFromObjects(v16, v48);
cocos2d::CCArray::addObjectsFromArray(v72, v48);
cocos2d::CCArray::addObject(v73, v18);
v24 = v94;
v25 = (void *)(v94 - 24);
if ( (__int64 *)(v94 - 24) == &qword_124B6B0 )
{
LABEL_15:
size = v93.size;
v27 = (void *)(*(_QWORD *)&v93.size - 24LL);
if ( (__int64 *)(*(_QWORD *)&v93.size - 24LL) == &qword_124B6B0 )
goto LABEL_16;
goto LABEL_64;
}
LABEL_59:
if ( &pthread_create )
{
v49 = (unsigned int *)(v24 - 8);
do
v50 = __ldaxr(v49);
while ( __stlxr(v50 - 1, v49) );
}
else
{
v50 = *(_DWORD *)(v24 - 8);
*(_DWORD *)(v24 - 8) = v50 - 1;
}
if ( v50 > 0 )
goto LABEL_15;
operator delete(v25);
size = v93.size;
v27 = (void *)(*(_QWORD *)&v93.size - 24LL);
if ( (__int64 *)(*(_QWORD *)&v93.size - 24LL) == &qword_124B6B0 )
goto LABEL_16;
LABEL_64:
if ( &pthread_create )
{
v51 = (unsigned int *)(*(_QWORD *)&size - 8LL);
do
v52 = __ldaxr(v51);
while ( __stlxr(v52 - 1, v51) );
}
else
{
v52 = *(_DWORD *)(*(_QWORD *)&size - 8LL);
*(_DWORD *)(*(_QWORD *)&size - 8LL) = v52 - 1;
}
if ( v52 <= 0 )
operator delete(v27);
LABEL_16:
v28 = (void *)(v88 - 24);
if ( (__int64 *)(v88 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v43 = (unsigned int *)(v88 - 8);
do
v44 = __ldaxr(v43);
while ( __stlxr(v44 - 1, v43) );
}
else
{
v44 = *(_DWORD *)(v88 - 8);
*(_DWORD *)(v88 - 8) = v44 - 1;
}
if ( v44 <= 0 )
{
++v15;
operator delete(v28);
goto LABEL_18;
}
}
LABEL_17:
++v15;
LABEL_18:
if ( v15 >= (unsigned int)cocos2d::CCArray::count(a3) )
goto LABEL_19;
}
v53 = v74;
sub_D153B8((int)v74, &byte_F288A0);
sub_D18EA8(&v18->m_baseFrame, v53);
v54 = *v53;
v55 = (__int64 *)(*(_QWORD *)v53 - 24LL);
if ( v55 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v56 = (unsigned int *)(*(_QWORD *)&v54 - 8LL);
do
v57 = __ldaxr(v56);
while ( __stlxr(v57 - 1, v56) );
}
else
{
v57 = *(_DWORD *)(*(_QWORD *)&v54 - 8LL);
*(_DWORD *)(*(_QWORD *)&v54 - 8LL) = v57 - 1;
}
if ( v57 <= 0 )
operator delete(v55);
}
LABEL_14:
v24 = v94;
v25 = (void *)(v94 - 24);
if ( (__int64 *)(v94 - 24) == &qword_124B6B0 )
goto LABEL_15;
goto LABEL_59;
}
LABEL_19:
if ( v79 )
{
if ( v77 )
{
m_pElements = v79->m_pElements;
if ( m_pElements )
{
for ( i = (cocos2d::CCDictElement *)m_pElements->hh.next; ; i = (cocos2d::CCDictElement *)i->hh.next )
{
m_pObject = m_pElements->m_pObject;
HIBYTE(m_pObject[23].m_unknown2) = m_pObject->getTag(m_pObject) != 0;
if ( !i )
break;
m_pElements = i;
}
}
}
}
EditorUI::deselectAll(v16);
if ( v71 )
{
v32 = 0;
v33 = v76;
while ( v32 < (unsigned int)cocos2d::CCArray::count(v33) )
{
v34 = v32++;
v35 = (SmartGameObject *)cocos2d::CCArray::objectAtIndex(v33, v34);
v35->m_referenceOnly = 1;
SmartGameObject::updateSmartFrame(v35);
}
}
else if ( !v70 )
{
v64 = v73;
v65 = 0;
v66 = UndoObject::createWithArray(v73, DeleteMulti);
LevelEditorLayer::addToUndoList(v16->m_editorLayer, v66, 0);
while ( v65 < (unsigned int)cocos2d::CCArray::count(v64) )
{
v67 = v65++;
v68 = (GameObject *)cocos2d::CCArray::objectAtIndex(v64, v67);
EditorUI::deleteObject(v16, v68, 1);
}
EditorUI::selectObjects(v16, v72, 1);
goto LABEL_30;
}
EditorUI::selectObjects(v16, a3, 1);
LABEL_30:
v36 = UndoObject::createWithArray(v72, Paste);
LevelEditorLayer::addToUndoList(v16->m_editorLayer, v36, 0);
EditorUI::updateButtons(v16);
EditorUI::updateSpecialUIElements(v16);
}
}