//
// EditorUI::createSmartObjectsFromTemplate from 0x3a4eb4 to 0x3a540c (1368 bytes)
//
// 2 xrefs:
// > SetupSmartBlockLayer::onPasteTemplate @ 0x53d4c8
// > SetupSmartBlockLayer::onCreate @ 0x53d590
//
// 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)
{
cocos2d::CCArray *v9; // r0
unsigned int v10; // r5
GameObject *v11; // r0
SmartGameObject *v12; // r8
int v13; // r9
LevelEditorLayer *m_editorLayer; // r9
cocos2d::CCArray *v15; // r0
cocos2d::CCArray *v16; // r9
unsigned int i; // r8
int v18; // r11
unsigned int j; // r11
SmartGameObject *v20; // r0
SmartGameObject *v21; // r6
int v22; // r9
cocos2d::CCPoint v23; // r2
SmartGameObject *SmartNeighbor; // r9
cocos2d::CCPoint v25; // r2
cocos2d::CCPoint v26; // r2
cocos2d::CCPoint v27; // r2
cocos2d::CCPoint v28; // r2
cocos2d::CCPoint v29; // r2
SmartGameObject *v30; // r10
cocos2d::CCPoint v31; // r2
cocos2d::CCPoint v32; // r2
cocos2d::CCPoint v33; // r1
cocos2d::CCArray *v34; // r8
unsigned int k; // r5
cocos2d::CCDictElement *m_pElements; // r3
cocos2d::CCDictElement *next; // r5
cocos2d::CCObject *m_pObject; // r6
cocos2d::CCDictElement *v39; // r2
SmartGameObject *v40; // r0
EditorUI *v41; // r0
cocos2d::CCArray *v42; // r1
UndoObject *v43; // r0
unsigned int m; // r7
GameObject *v45; // r0
UndoObject *v46; // r0
const cocos2d::CCPoint *v47; // r0
float v48; // s16
bool v49; // [sp+0h] [bp-BCh]
cocos2d::CCArray *v50; // [sp+4h] [bp-B8h]
cocos2d::CCArray *v51; // [sp+4h] [bp-B8h]
cocos2d::CCArray *v52; // [sp+4h] [bp-B8h]
cocos2d::CCArray *v53; // [sp+4h] [bp-B8h]
cocos2d::CCArray *v54; // [sp+4h] [bp-B8h]
cocos2d::CCArray *v55; // [sp+4h] [bp-B8h]
cocos2d::CCArray *v56; // [sp+4h] [bp-B8h]
cocos2d::CCArray *v57; // [sp+4h] [bp-B8h]
SmartGameObject *v58; // [sp+1Ch] [bp-A0h]
cocos2d::CCArray *v59; // [sp+24h] [bp-98h]
cocos2d::CCDictionary *v60; // [sp+28h] [bp-94h]
cocos2d::CCArray *v61; // [sp+2Ch] [bp-90h]
cocos2d::CCArray *v62; // [sp+30h] [bp-8Ch]
_BOOL4 v64; // [sp+3Ch] [bp-80h]
SmartGameObject *v65; // [sp+40h] [bp-7Ch]
SmartGameObject *v66; // [sp+44h] [bp-78h]
SmartGameObject *v67; // [sp+48h] [bp-74h]
SmartGameObject *v68; // [sp+4Ch] [bp-70h]
SmartGameObject *v69; // [sp+50h] [bp-6Ch]
SmartGameObject *v70; // [sp+64h] [bp-58h]
int v71; // [sp+6Ch] [bp-50h] BYREF
char v72[4]; // [sp+70h] [bp-4Ch] BYREF
char v73[4]; // [sp+74h] [bp-48h] BYREF
cocos2d::CCPoint v74; // [sp+78h] [bp-44h] BYREF
cocos2d::CCPoint v75; // [sp+80h] [bp-3Ch] BYREF
cocos2d::CCRect v76; // [sp+88h] [bp-34h] BYREF
cocos2d::CCRect v77; // [sp+98h] [bp-24h] BYREF
int v78; // [sp+ACh] [bp-10h]
char v79; // [sp+B0h] [bp-Ch]
char v80; // [sp+B1h] [bp-Bh]
cocos2d::CCPoint v81; // 0:r3.4,4:^0.4
cocos2d::CCRect v82; // 0:r1.12,12:^0.4
v64 = a4;
if ( a3 && cocos2d::CCArray::count(a3) && a2 )
{
GJSmartTemplate::resetScannedPrefabs(a2);
EditorUI::deselectAll(a1);
v10 = 0;
v61 = (cocos2d::CCArray *)cocos2d::CCArray::create(v9);
v59 = (cocos2d::CCArray *)cocos2d::CCArray::create(v61);
v62 = (cocos2d::CCArray *)cocos2d::CCArray::create(v59);
v60 = cocos2d::CCDictionary::create();
while ( v10 < cocos2d::CCArray::count(a3) )
{
v11 = (GameObject *)cocos2d::CCArray::objectAtIndex(a3, v10);
v12 = (SmartGameObject *)v11;
if ( (unsigned int)(v11->m_objectID - 2896) <= 1 )
GameObject::determineSlopeDirection(v11);
if ( v64 )
{
v13 = (int)v12->getPosition(v12);
GJSmartTemplate::offsetForObject(&v77.origin, v12);
cocos2d::CCPoint::operator+(&v75, v13, &v77);
cocos2d::CCRect::CCRect(&v76, v75.x - 37.5, v75.y - 37.5, 75.0, 75.0);
m_editorLayer = a1->m_editorLayer;
cocos2d::CCRect::CCRect(&v77, &v76);
LODWORD(v82.origin.x) = &v77;
LODWORD(v82.origin.y) = 1;
v15 = LevelEditorLayer::objectsInRect(m_editorLayer, v82, (bool)v50);
v16 = v15;
if ( v15 )
{
if ( cocos2d::CCArray::count(v15) )
{
for ( i = 0; i < cocos2d::CCArray::count(v16); ++i )
{
v18 = cocos2d::CCArray::objectAtIndex(v16, i);
if ( *(_DWORD *)(v18 + 1076) == 5 && !cocos2d::CCArray::containsObject(a3, (cocos2d::CCObject *)v18) )
{
cocos2d::CCArray::addObject(a3, (cocos2d::CCObject *)v18);
cocos2d::CCDictionary::setObject(v60, (cocos2d::CCObject *)v18, *(_DWORD *)(v18 + 772));
(*(void (__fastcall **)(int, _DWORD))(*(_DWORD *)v18 + 36))(v18, *(unsigned __int8 *)(v18 + 1159));
*(_BYTE *)(v18 + 1159) = 1;
}
}
}
}
}
++v10;
}
for ( j = 0; j < cocos2d::CCArray::count(a3); ++j )
{
v20 = (SmartGameObject *)cocos2d::CCArray::objectAtIndex(a3, j);
v21 = v20;
if ( v20->m_referenceOnly )
{
if ( !cocos2d::CCDictionary::objectForKey(v60, v20->m_uniqueID) )
cocos2d::CCArray::addObject(v59, v21);
}
else
{
v22 = (int)v20->getPosition(v20);
GJSmartTemplate::offsetForObject(&v77.origin, v21);
cocos2d::CCPoint::operator+(&v74, v22, &v77);
cocos2d::CCPoint::CCPoint(&v77.origin, &v74);
LODWORD(v23.x) = &v77;
LODWORD(v23.y) = 1;
SmartNeighbor = EditorUI::getSmartNeighbor(a1, v21, v23, (GJSmartDirection)a3, v50);
cocos2d::CCPoint::CCPoint(&v77.origin, &v74);
LODWORD(v25.x) = &v77;
LODWORD(v25.y) = 2;
v65 = EditorUI::getSmartNeighbor(a1, v21, v25, (GJSmartDirection)a3, v51);
cocos2d::CCPoint::CCPoint(&v77.origin, &v74);
LODWORD(v26.x) = &v77;
LODWORD(v26.y) = 3;
v66 = EditorUI::getSmartNeighbor(a1, v21, v26, (GJSmartDirection)a3, v52);
cocos2d::CCPoint::CCPoint(&v77.origin, &v74);
LODWORD(v27.x) = &v77;
LODWORD(v27.y) = 4;
v67 = EditorUI::getSmartNeighbor(a1, v21, v27, (GJSmartDirection)a3, v53);
cocos2d::CCPoint::CCPoint(&v77.origin, &v74);
LODWORD(v28.x) = &v77;
LODWORD(v28.y) = 5;
v68 = EditorUI::getSmartNeighbor(a1, v21, v28, (GJSmartDirection)a3, v54);
cocos2d::CCPoint::CCPoint(&v77.origin, &v74);
LODWORD(v29.x) = &v77;
LODWORD(v29.y) = 6;
v30 = EditorUI::getSmartNeighbor(a1, v21, v29, (GJSmartDirection)a3, v55);
cocos2d::CCPoint::CCPoint(&v77.origin, &v74);
LODWORD(v31.x) = &v77;
LODWORD(v31.y) = 7;
v69 = EditorUI::getSmartNeighbor(a1, v21, v31, (GJSmartDirection)a3, v56);
cocos2d::CCPoint::CCPoint(&v77.origin, &v74);
LODWORD(v32.x) = &v77;
LODWORD(v32.y) = 8;
v70 = EditorUI::getSmartNeighbor(a1, v21, v32, (GJSmartDirection)a3, v57);
cocos2d::CCPoint::CCPoint(&v77.origin, &v74);
LODWORD(v33.x) = &v77;
LODWORD(v33.y) = v21;
GJSmartTemplate::keyFromNeighbors(
(GJSmartTemplate *)&v71,
v33,
SmartNeighbor,
v65,
v66,
v67,
v68,
v30,
v69,
v70,
v58);
sub_775C20(v72, &v71);
GJSmartTemplate::scanForPrefab((GJSmartTemplate *)&v77, (std::string)a2);
sub_774008(v72);
if ( LODWORD(v77.origin.x) )
{
cocos2d::CCArray::addObject(v62, v21);
sub_775C20(v73, &v77.size);
sub_775D40(&v21->m_baseFrame, v73);
sub_774008(v73);
if ( !a7 )
{
sub_775C20(&v75, LODWORD(v77.origin.x) + 56);
v34 = EditorUI::pasteObjects(a1, &v75, 0, 1);
sub_774008(&v75);
if ( v34 )
{
if ( cocos2d::CCArray::count(v34) )
{
v47 = v21->getPosition(v21);
cocos2d::CCPoint::CCPoint(&v75, v47);
cocos2d::CCPoint::CCPoint(&v76.origin, &v75);
EditorUI::repositionObjectsToCenter(a1, v34, (cocos2d::CCPoint)(unsigned int)&v76, v49);
if ( v80 )
EditorUI::flipObjectsY(a1, v34);
if ( v79 )
EditorUI::flipObjectsX(a1, v34);
if ( v78 > 0 )
{
v48 = (float)-v78;
cocos2d::CCPoint::CCPoint(&v76.origin, (const cocos2d::CCPoint *)&flt_AC5D38);
LODWORD(v81.x) = &v76;
EditorUI::rotateObjects(a1, v34, v48, v81);
}
cocos2d::CCPoint::CCPoint(&v76.origin, &v75);
EditorUI::repositionObjectsToCenter(a1, v34, (cocos2d::CCPoint)(unsigned int)&v76, SLOBYTE(v81.y));
EditorUI::deleteSmartBlocksFromObjects(a1, v34);
cocos2d::CCArray::addObjectsFromArray(v61, v34);
cocos2d::CCArray::addObject(v59, v21);
}
}
}
}
else
{
sub_776584((int)&v76, (char *)&unk_939830);
sub_775D40(&v21->m_baseFrame, &v76);
sub_774008(&v76);
}
sub_774008(&v77.size);
sub_774008(&v77.origin.y);
sub_774008(&v71);
}
}
if ( v64 && v60 )
{
m_pElements = v60->m_pElements;
if ( m_pElements )
next = (cocos2d::CCDictElement *)m_pElements->hh.next;
else
next = nullptr;
while ( m_pElements )
{
m_pObject = m_pElements->m_pObject;
HIBYTE(m_pObject[22].m_nTag) = m_pObject->getTag(m_pObject) != 0;
if ( next )
v39 = (cocos2d::CCDictElement *)next->hh.next;
else
v39 = nullptr;
m_pElements = next;
next = v39;
}
}
EditorUI::deselectAll(a1);
if ( a6 )
{
for ( k = 0; k < cocos2d::CCArray::count(v62); ++k )
{
v40 = (SmartGameObject *)cocos2d::CCArray::objectAtIndex(v62, k);
v40->m_referenceOnly = 1;
SmartGameObject::updateSmartFrame(v40);
}
}
else if ( !a5 )
{
v43 = UndoObject::createWithArray(v59, DeleteMulti);
LevelEditorLayer::addToUndoList(a1->m_editorLayer, v43, 0);
for ( m = 0; m < cocos2d::CCArray::count(v59); ++m )
{
v45 = (GameObject *)cocos2d::CCArray::objectAtIndex(v59, m);
EditorUI::deleteObject(a1, v45, 1);
}
v42 = v61;
v41 = a1;
goto LABEL_52;
}
v41 = a1;
v42 = a3;
LABEL_52:
EditorUI::selectObjects(v41, v42, 1);
v46 = UndoObject::createWithArray(v61, Paste);
LevelEditorLayer::addToUndoList(a1->m_editorLayer, v46, 0);
EditorUI::updateButtons(a1);
EditorUI::updateSpecialUIElements(a1);
}
}