//
// EditorUI::addObjectsToSmartTemplate from 0x39bef8 to 0x39c752 (2138 bytes)
//
// 1 xrefs:
// > SetupSmartBlockLayer::onCreateTemplate @ 0x53d5de
//
// 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::addObjectsToSmartTemplate(EditorUI *a1, GJSmartTemplate *a2, cocos2d::CCArray *a3)
{
unsigned int v4; // r4
int v5; // r0
cocos2d::CCObject *v6; // r5
intptr_t m_uID; // r2
SmartGameObject *v8; // r0
int m_referenceOnly; // r6
SmartGameObject *v10; // r5
cocos2d::CCPoint v11; // r1
SmartBlockType v12; // r0
int v13; // r0
int v14; // r3
int v15; // r8
const cocos2d::CCPoint *p_m_uReference; // r1
cocos2d::CCArray *v17; // r11
cocos2d::CCPoint v18; // r2
SmartGameObject *SmartNeighbor; // r9
cocos2d::CCPoint v20; // r2
cocos2d::CCPoint v21; // r2
cocos2d::CCPoint v22; // r2
cocos2d::CCPoint v23; // r2
cocos2d::CCPoint v24; // r2
cocos2d::CCPoint v25; // r2
cocos2d::CCPoint v26; // r2
int v27; // r3
int v28; // r3
int v29; // r3
int v30; // r3
int v31; // r3
int v32; // r3
int v33; // r3
LevelEditorLayer *m_editorLayer; // r7
cocos2d::CCArray *v35; // r0
cocos2d::CCPoint v36; // r1
int m_linkedGroup; // r1
unsigned int v38; // r7
cocos2d::CCArray *StickyGroup; // r7
unsigned int j; // r6
cocos2d::CCObject *v41; // r8
cocos2d::CCObject *v42; // r6
const cocos2d::CCPoint *v43; // r0
float v44; // r0
float v45; // s16
intptr_t v46; // r1
unsigned int v47; // r3
int m_objectID; // r6
cocos2d::CCPoint v49; // r2
GameObject *Object; // r6
void (__fastcall *setRotation)(GameObject *__hidden, float); // r7
int v52; // r0
void (__fastcall *setFlipX)(GameObject *__hidden, bool); // r7
int v54; // r0
void (__fastcall *setFlipY)(GameObject *__hidden, bool); // r7
int v56; // r0
int v57; // r7
int v58; // r2
bool v59; // r3
cocos2d::CCArray *v60; // [sp+4h] [bp-168h]
cocos2d::CCArray *v61; // [sp+4h] [bp-168h]
cocos2d::CCArray *v62; // [sp+4h] [bp-168h]
cocos2d::CCArray *v63; // [sp+4h] [bp-168h]
cocos2d::CCArray *v64; // [sp+4h] [bp-168h]
cocos2d::CCArray *v65; // [sp+4h] [bp-168h]
cocos2d::CCArray *v66; // [sp+4h] [bp-168h]
cocos2d::CCArray *v67; // [sp+4h] [bp-168h]
bool v68; // [sp+4h] [bp-168h]
SmartGameObject *v69; // [sp+1Ch] [bp-150h]
unsigned int i; // [sp+28h] [bp-144h]
SmartGameObject *v72; // [sp+2Ch] [bp-140h]
SmartGameObject *v73; // [sp+30h] [bp-13Ch]
SmartGameObject *v74; // [sp+34h] [bp-138h]
SmartGameObject *v75; // [sp+38h] [bp-134h]
SmartGameObject *v76; // [sp+3Ch] [bp-130h]
SmartGameObject *v77; // [sp+40h] [bp-12Ch]
SmartGameObject *v78; // [sp+44h] [bp-128h]
int v79; // [sp+48h] [bp-124h]
int v80; // [sp+4Ch] [bp-120h]
int v81; // [sp+50h] [bp-11Ch]
int v82; // [sp+54h] [bp-118h]
int v84; // [sp+60h] [bp-10Ch]
int v85; // [sp+64h] [bp-108h]
int v86; // [sp+68h] [bp-104h]
int v87; // [sp+6Ch] [bp-100h]
int v88; // [sp+70h] [bp-FCh]
cocos2d::CCDictionary *v89; // [sp+74h] [bp-F8h]
cocos2d::CCDictionary *v90; // [sp+78h] [bp-F4h]
int v91; // [sp+7Ch] [bp-F0h]
int v92; // [sp+80h] [bp-ECh]
int v93; // [sp+84h] [bp-E8h]
int v94; // [sp+88h] [bp-E4h]
int v95; // [sp+8Ch] [bp-E0h]
int v96; // [sp+90h] [bp-DCh]
int v97; // [sp+94h] [bp-D8h]
int v98; // [sp+98h] [bp-D4h]
int v99; // [sp+9Ch] [bp-D0h]
char v100[4]; // [sp+A8h] [bp-C4h] BYREF
GJSmartTemplate v101; // [sp+ACh] [bp-C0h] BYREF
cocos2d::CCPoint v102; // [sp+12Ch] [bp-40h] BYREF
cocos2d::CCPoint v103; // [sp+134h] [bp-38h] BYREF
cocos2d::CCPoint v104; // [sp+13Ch] [bp-30h] BYREF
cocos2d::CCRect v105; // [sp+144h] [bp-28h] BYREF
cocos2d::CCRect v106; // [sp+154h] [bp-18h] BYREF
cocos2d::CCRect v107; // 0:r1.12,12:^0.4
if ( a2 )
{
v4 = 0;
v89 = cocos2d::CCDictionary::create();
v90 = cocos2d::CCDictionary::create();
while ( v4 < cocos2d::CCArray::count(a3) )
{
v5 = cocos2d::CCArray::objectAtIndex(a3, v4);
v6 = (cocos2d::CCObject *)v5;
if ( *(_DWORD *)(v5 + 1076) == 5 )
{
if ( (unsigned int)(*(_DWORD *)(v5 + 884) - 2896) <= 1 )
GameObject::determineSlopeDirection((GameObject *)v5);
m_uID = v6[14].m_uID;
if ( m_uID > 0 )
cocos2d::CCDictionary::setObject(v90, v6, m_uID);
++v4;
}
else
{
cocos2d::CCArray::removeObjectAtIndex(a3, v4, 1);
}
}
for ( i = 0; i < cocos2d::CCArray::count(a3); ++i )
{
v8 = (SmartGameObject *)cocos2d::CCArray::objectAtIndex(a3, i);
m_referenceOnly = v8->m_referenceOnly;
v10 = v8;
if ( !v8->m_referenceOnly )
{
cocos2d::CCPoint::CCPoint(&v106.origin, (const cocos2d::CCPoint *)&flt_AC5D38);
LODWORD(v11.x) = &v106;
v12 = GJSmartTemplate::smartObjectToType(v10, v11);
GJSmartTemplate::offsetForType((cocos2d::CCPoint *)&v101.m_nLuaID, v12);
v13 = (int)v10->getPosition(v10);
cocos2d::CCPoint::operator+(&v101.m_uReference, v13, &v101.m_nLuaID);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)&v101.m_eObjType);
if ( *(float *)&v101.m_nLuaID == flt_AC5D38 && *(float *)&v101.m_nTag == flt_AC5D3C )
{
v14 = 1;
v91 = m_referenceOnly;
}
else
{
v57 = (int)v10->getPosition(v10);
cocos2d::CCPoint::operator-(&v105, &v101.m_nLuaID);
cocos2d::CCPoint::operator+(&v106, v57, &v105);
cocos2d::CCPoint::operator=((PlayerObject *)&v101.m_eObjType, COERCE_FLOAT(&v106), v58, v59);
v91 = 1;
v14 = 2;
}
v84 = v14;
v15 = 0;
sub_776584((int)v100, (char *)&unk_939830);
p_m_uReference = (const cocos2d::CCPoint *)&v101.m_uReference;
v17 = nullptr;
while ( 1 )
{
cocos2d::CCPoint::CCPoint(&v104, p_m_uReference);
cocos2d::CCPoint::CCPoint(&v106.origin, &v104);
LODWORD(v18.x) = &v106;
LODWORD(v18.y) = 1;
SmartNeighbor = EditorUI::getSmartNeighbor(a1, v10, v18, (GJSmartDirection)a3, v60);
cocos2d::CCPoint::CCPoint(&v106.origin, &v104);
LODWORD(v20.x) = &v106;
LODWORD(v20.y) = 2;
v72 = EditorUI::getSmartNeighbor(a1, v10, v20, (GJSmartDirection)a3, v61);
cocos2d::CCPoint::CCPoint(&v106.origin, &v104);
LODWORD(v21.x) = &v106;
LODWORD(v21.y) = 3;
v73 = EditorUI::getSmartNeighbor(a1, v10, v21, (GJSmartDirection)a3, v62);
cocos2d::CCPoint::CCPoint(&v106.origin, &v104);
LODWORD(v22.x) = &v106;
LODWORD(v22.y) = 4;
v74 = EditorUI::getSmartNeighbor(a1, v10, v22, (GJSmartDirection)a3, v63);
cocos2d::CCPoint::CCPoint(&v106.origin, &v104);
LODWORD(v23.x) = &v106;
LODWORD(v23.y) = 5;
v75 = EditorUI::getSmartNeighbor(a1, v10, v23, (GJSmartDirection)a3, v64);
cocos2d::CCPoint::CCPoint(&v106.origin, &v104);
LODWORD(v24.x) = &v106;
LODWORD(v24.y) = 6;
v76 = EditorUI::getSmartNeighbor(a1, v10, v24, (GJSmartDirection)a3, v65);
cocos2d::CCPoint::CCPoint(&v106.origin, &v104);
LODWORD(v25.x) = &v106;
LODWORD(v25.y) = 7;
v77 = EditorUI::getSmartNeighbor(a1, v10, v25, (GJSmartDirection)a3, v66);
cocos2d::CCPoint::CCPoint(&v106.origin, &v104);
LODWORD(v26.x) = &v106;
LODWORD(v26.y) = 8;
v78 = EditorUI::getSmartNeighbor(a1, v10, v26, (GJSmartDirection)a3, v67);
if ( SmartNeighbor )
v79 = !SmartNeighbor->m_referenceOnly;
else
v79 = 0;
if ( v72 )
v27 = !v72->m_referenceOnly;
else
v27 = 0;
v80 = v27;
if ( v73 )
v28 = !v73->m_referenceOnly;
else
v28 = 0;
v81 = v28;
if ( v74 )
v29 = !v74->m_referenceOnly;
else
v29 = 0;
v82 = v29;
if ( v75 )
v30 = !v75->m_referenceOnly;
else
v30 = 0;
v85 = v30;
if ( v76 )
v31 = !v76->m_referenceOnly;
else
v31 = 0;
v86 = v31;
if ( v77 )
v32 = !v77->m_referenceOnly;
else
v32 = 0;
v87 = v32;
if ( v78 )
v33 = !v78->m_referenceOnly;
else
v33 = 0;
v88 = v33;
cocos2d::CCRect::CCRect(&v105, v104.x - 14.0, v104.y - 14.0, 28.0, 28.0);
if ( !v79 )
v105.size.height = v105.size.height + 14.0;
if ( !v80 )
{
v105.size.height = v105.size.height + 14.0;
v105.origin.y = v105.origin.y - 14.0;
}
if ( !v81 )
{
v105.size.width = v105.size.width + 14.0;
v105.origin.x = v105.origin.x - 14.0;
}
if ( !v82 )
v105.size.width = v105.size.width + 14.0;
m_editorLayer = a1->m_editorLayer;
cocos2d::CCRect::CCRect(&v106, &v105);
LODWORD(v107.origin.x) = &v106;
LODWORD(v107.origin.y) = 1;
v35 = LevelEditorLayer::objectsInRect(m_editorLayer, v107, v68);
if ( v17 )
{
if ( v35 )
cocos2d::CCArray::addObjectsFromArray(v17, v35);
}
else
{
v17 = v35;
}
if ( !v15 )
{
cocos2d::CCPoint::CCPoint(&v106.origin, &v104);
LODWORD(v36.x) = &v106;
LODWORD(v36.y) = v10;
GJSmartTemplate::keyFromNeighbors(&v101, v36, SmartNeighbor, v72, v73, v74, v75, v76, v77, v78, v69);
sub_774794(v100, &v101);
sub_774008(&v101);
v99 = v88;
v98 = v87;
v97 = v86;
v96 = v85;
v95 = v82;
v94 = v81;
v93 = v80;
v92 = v79;
}
if ( ++v15 == v84 )
break;
if ( v15 )
p_m_uReference = (const cocos2d::CCPoint *)&v101.m_eObjType;
else
p_m_uReference = (const cocos2d::CCPoint *)&v101.m_uReference;
}
m_linkedGroup = v10->m_linkedGroup;
if ( m_linkedGroup > 0 )
{
StickyGroup = GJBaseGameLayer::getStickyGroup(a1->m_editorLayer, m_linkedGroup);
if ( StickyGroup )
{
for ( j = 0; j < cocos2d::CCArray::count(StickyGroup); ++j )
{
v41 = (cocos2d::CCObject *)cocos2d::CCArray::objectAtIndex(StickyGroup, j);
if ( !cocos2d::CCArray::containsObject(v17, v41) )
cocos2d::CCArray::addObject(v17, v41);
}
}
}
if ( v17 )
{
v38 = 0;
while ( v38 < cocos2d::CCArray::count(v17) )
{
v42 = (cocos2d::CCObject *)cocos2d::CCArray::objectAtIndex(v17, v38);
if ( v42[20].m_unknown2 == 5 || cocos2d::CCDictionary::objectForKey(v89, v42[14].m_uOrderOfArrival) )
goto LABEL_106;
v43 = (const cocos2d::CCPoint *)((int (__fastcall *)(cocos2d::CCObject *))v42->__vftable[2].acceptVisitor)(v42);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)&v101.m_uUnknown, v43);
v44 = cocos2d::ccpDistance(
(const cocos2d::CCPoint *)&v101.m_uReference,
(const cocos2d::CCPoint *)&v101.m_uUnknown);
v45 = v44;
if ( v91
&& v44 > cocos2d::ccpDistance(
(const cocos2d::CCPoint *)&v101.m_eObjType,
(const cocos2d::CCPoint *)&v101.m_uUnknown) )
{
v45 = cocos2d::ccpDistance(
(const cocos2d::CCPoint *)&v101.m_eObjType,
(const cocos2d::CCPoint *)&v101.m_uUnknown);
}
v46 = v42[14].m_uID;
if ( v46 > 0 && v46 != v10->m_linkedGroup && cocos2d::CCDictionary::objectForKey(v90, v46) )
goto LABEL_106;
v47 = v42[14].m_uID;
if ( v47 && v47 == v10->m_linkedGroup )
goto LABEL_76;
if ( v92 )
{
GJSmartTemplate::offsetForDir((cocos2d::CCPoint *)&v101.m_nZOrder, (GJSmartDirection)1, 0);
cocos2d::CCPoint::operator+(&v101.m_unknown5, &v101.m_uReference, &v101.m_nZOrder);
if ( cocos2d::ccpDistance(
(const cocos2d::CCPoint *)&v101.m_uUnknown,
(const cocos2d::CCPoint *)&v101.m_unknown5) < v45 )
goto LABEL_106;
}
if ( v93 )
{
GJSmartTemplate::offsetForDir((cocos2d::CCPoint *)&v101.m_remapDict1, (GJSmartDirection)2, 0);
cocos2d::CCPoint::operator+(&v101.m_remapDict3, &v101.m_uReference, &v101.m_remapDict1);
if ( cocos2d::ccpDistance(
(const cocos2d::CCPoint *)&v101.m_uUnknown,
(const cocos2d::CCPoint *)&v101.m_remapDict3) < v45 )
goto LABEL_106;
}
if ( v94 )
{
GJSmartTemplate::offsetForDir((cocos2d::CCPoint *)&v101.m_remapDict5, (GJSmartDirection)3, 0);
cocos2d::CCPoint::operator+(&v101.m_prefabResults, &v101.m_uReference, &v101.m_remapDict5);
if ( cocos2d::ccpDistance(
(const cocos2d::CCPoint *)&v101.m_uUnknown,
(const cocos2d::CCPoint *)&v101.m_prefabResults) < v45 )
goto LABEL_106;
}
if ( v95 )
{
GJSmartTemplate::offsetForDir(
(cocos2d::CCPoint *)&v101.m_prefabResults.m_header.m_parent,
(GJSmartDirection)4,
0);
cocos2d::CCPoint::operator+(
&v101.m_prefabResults.m_header.m_right,
&v101.m_uReference,
&v101.m_prefabResults.m_header.m_parent);
if ( cocos2d::ccpDistance(
(const cocos2d::CCPoint *)&v101.m_uUnknown,
(const cocos2d::CCPoint *)&v101.m_prefabResults.m_header.m_right) < v45 )
goto LABEL_106;
}
if ( v96 )
{
GJSmartTemplate::offsetForDir((cocos2d::CCPoint *)&v101.m_allowFlipX, TopLeft, 0);
cocos2d::CCPoint::operator+(&v101.m_unk0a8, &v101.m_uReference, &v101.m_allowFlipX);
if ( cocos2d::ccpDistance(
(const cocos2d::CCPoint *)&v101.m_uUnknown,
(const cocos2d::CCPoint *)&v101.m_unk0a8) < v45 )
goto LABEL_106;
}
if ( v97
&& (GJSmartTemplate::offsetForDir((cocos2d::CCPoint *)&v101.m_prefabIndex, TopRight, 0),
cocos2d::CCPoint::operator+(&v102, &v101.m_uReference, &v101.m_prefabIndex),
cocos2d::ccpDistance((const cocos2d::CCPoint *)&v101.m_uUnknown, &v102) < v45)
|| v98
&& (GJSmartTemplate::offsetForDir(&v103, BottomLeft, 0),
cocos2d::CCPoint::operator+(&v104, &v101.m_uReference, &v103),
cocos2d::ccpDistance((const cocos2d::CCPoint *)&v101.m_uUnknown, &v104) < v45)
|| v99
&& (GJSmartTemplate::offsetForDir(&v105.origin, BottomRight, 0),
cocos2d::CCPoint::operator+(&v106, &v101.m_uReference, &v105),
cocos2d::ccpDistance((const cocos2d::CCPoint *)&v101.m_uUnknown, &v106.origin) < v45) )
{
LABEL_106:
cocos2d::CCArray::removeObjectAtIndex(v17, v38, 1);
}
else
{
LABEL_76:
cocos2d::CCDictionary::setObject(v89, v42, v42[14].m_uOrderOfArrival);
++v38;
}
}
if ( cocos2d::CCArray::count(v17) )
{
m_objectID = v10->m_objectID;
v10->getRealPosition(&v106.origin, v10);
LODWORD(v49.x) = &v106;
Object = EditorUI::createObject(a1, m_objectID, v49);
cocos2d::CCArray::addObject(v17, Object);
setRotation = Object->setRotation;
v52 = ((int (__fastcall *)(SmartGameObject *))v10->getRotation)(v10);
((void (__fastcall *)(GameObject *, int))setRotation)(Object, v52);
setFlipX = Object->setFlipX;
v54 = ((int (__fastcall *)(SmartGameObject *))v10->isFlipX)(v10);
setFlipX(Object, v54);
setFlipY = Object->setFlipY;
v56 = ((int (__fastcall *)(SmartGameObject *))v10->isFlipY)(v10);
setFlipY(Object, v56);
Object->m_hasGroupParent = 1;
qsort(v17->data->arr, v17->data->num, 4u, (int (*)(const void *, const void *))smartPrefabSort);
EditorUI::copyObjectsDetailed((EditorUI *)&v106, a1, v17);
Object->m_hasGroupParent = 0;
EditorUI::deleteObject(a1, Object, 1);
sub_775C20(&v101.m_uID, v100);
sub_775C20(&v101.m_uUnknown, &v106);
GJSmartTemplate::savePrefab(a2, (std::string)&v101.m_uID, (std::string)&v101.m_uUnknown);
sub_774008(&v101.m_uUnknown);
sub_774008(&v101.m_uID);
sub_774008(&v106);
}
}
sub_774008(v100);
}
}
GJSmartTemplate::logTemplateStatus((GJSmartTemplate *)&v106, (bool)a2);
sub_774008(&v106);
}
}