//
// EditorUI::addObjectsToSmartTemplate from 0x1003f0a84 to 0x1003f1520 (2716 bytes)
//
// 1 xrefs:
// > SetupSmartBlockLayer::onCreateTemplate @ 0x10006fe7c
//
// 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 EditorUI::addObjectsToSmartTemplate(EditorUI *a1, GJSmartTemplate *a2, cocos2d::CCArray *a3)
{
cocos2d::CCDictionary *v5; // x23
__int64 v6; // x19
__int64 v7; // x0
cocos2d::CCObject *v8; // x21
intptr_t m_uIndexInArray; // x2
unsigned int v10; // w25
__int64 v11; // x0
SmartGameObject *v12; // x21
SmartBlockType v13; // w0
float32x2_t *v14; // x0
__n128 v15; // q0
_BOOL4 v16; // w8
SmartGameObject *v17; // x19
float32x2_t *v18; // x20
int v19; // w8
int v20; // w28
__int64 *v21; // x1
EditorUI *v22; // x0
SmartGameObject *SmartNeighbor; // x26
EditorUI *v24; // x0
EditorUI *v25; // x0
SmartGameObject *v26; // x23
EditorUI *v27; // x0
SmartGameObject *v28; // x25
EditorUI *v29; // x0
SmartGameObject *v30; // x22
EditorUI *v31; // x0
SmartGameObject *v32; // x24
EditorUI *v33; // x0
SmartGameObject *v34; // x21
EditorUI *v35; // x0
SmartGameObject *v36; // x0
SmartGameObject *v37; // x27
bool v38; // w20
bool v39; // w23
LevelEditorLayer *m_editorLayer; // x20
double v41; // d0
cocos2d::CCArray *v42; // x0
__int64 v43; // x0
SmartGameObject *v44; // x27
int m_linkedGroup; // w1
cocos2d::CCArray *StickyGroup; // x19
unsigned int i; // w21
__int64 v48; // x0
__int64 j; // x26
__int64 v50; // x0
cocos2d::CCObject *v51; // x19
__int64 *v52; // x0
float v53; // s8
intptr_t v54; // x1
int m_objectID; // w19
GameObject *Object; // x19
__int64 v57; // x0
__int64 v58; // x0
float v59; // s1
float v60; // s2
float v61; // s3
cocos2d::CCDictionary *v63; // [xsp+20h] [xbp-1C0h]
cocos2d::CCDictionary *v64; // [xsp+28h] [xbp-1B8h]
_BOOL4 v65; // [xsp+34h] [xbp-1ACh]
unsigned int v66; // [xsp+38h] [xbp-1A8h]
bool v67; // [xsp+3Ch] [xbp-1A4h]
bool v68; // [xsp+40h] [xbp-1A0h]
bool v69; // [xsp+44h] [xbp-19Ch]
bool v70; // [xsp+48h] [xbp-198h]
bool v71; // [xsp+4Ch] [xbp-194h]
bool v72; // [xsp+50h] [xbp-190h]
bool v73; // [xsp+54h] [xbp-18Ch]
bool v74; // [xsp+58h] [xbp-188h]
int v75; // [xsp+5Ch] [xbp-184h]
EditorUI *v76; // [xsp+60h] [xbp-180h]
SmartGameObject *v77; // [xsp+68h] [xbp-178h]
bool v78; // [xsp+70h] [xbp-170h]
bool v79; // [xsp+74h] [xbp-16Ch]
bool v80; // [xsp+78h] [xbp-168h]
bool v81; // [xsp+7Ch] [xbp-164h]
cocos2d::CCArray *v82; // [xsp+80h] [xbp-160h]
bool v83; // [xsp+8Ch] [xbp-154h]
bool v84; // [xsp+90h] [xbp-150h]
bool v85; // [xsp+94h] [xbp-14Ch]
SmartGameObject *v86; // [xsp+98h] [xbp-148h]
cocos2d::CCArray *v87; // [xsp+A0h] [xbp-140h]
void *v88; // [xsp+A8h] [xbp-138h] BYREF
char v89; // [xsp+BFh] [xbp-121h]
std::string __p; // [xsp+C0h] [xbp-120h] BYREF
std::string __dst; // [xsp+E0h] [xbp-100h] BYREF
__int64 v92; // [xsp+F8h] [xbp-E8h] BYREF
std::string v93; // [xsp+100h] [xbp-E0h] BYREF
float32x2_t v94; // [xsp+118h] [xbp-C8h] BYREF
float v95; // [xsp+120h] [xbp-C0h]
float v96; // [xsp+124h] [xbp-BCh]
float32x2_t v97; // [xsp+128h] [xbp-B8h] BYREF
std::string v98; // [xsp+130h] [xbp-B0h] BYREF
cocos2d::CCPoint v99; // [xsp+148h] [xbp-98h] BYREF
float32x2_t v100; // [xsp+150h] [xbp-90h] BYREF
float32x2_t v101; // [xsp+158h] [xbp-88h] BYREF
cocos2d::CCPoint v102; // 0:kr00_8.8
cocos2d::CCRect v103; // 0:kr50_16.16
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:s0.4,4:s1.4
cocos2d::CCPoint v110; // 0:s0.4,4:s1.4
cocos2d::CCPoint v111; // 0:s0.4,4:s1.4
cocos2d::CCPoint v112; // 0:s0.4,4:s1.4
cocos2d::CCPoint v113; // 0:s0.4,4:s1.4
if ( a2 )
{
v5 = cocos2d::CCDictionary::create();
v63 = cocos2d::CCDictionary::create();
if ( (unsigned int)sub_10024A36C((__int64)a3) )
{
v6 = 0;
do
{
v7 = sub_10024A388((__int64)a3, v6);
if ( *(_DWORD *)(v7 + 1248) == 5 )
{
v8 = (cocos2d::CCObject *)v7;
if ( (*(_DWORD *)(v7 + 1028) & 0xFFFFFFFE) == 0xB50 )
GameObject::determineSlopeDirection((GameObject *)v7);
m_uIndexInArray = (unsigned int)v8[15].m_uIndexInArray;
if ( (int)m_uIndexInArray >= 1 )
cocos2d::CCDictionary::setObject(v63, v8, m_uIndexInArray);
v6 = (unsigned int)(v6 + 1);
}
else
{
sub_10024A44C((__int64)a3, v6, 1);
}
}
while ( (unsigned int)v6 < (unsigned int)sub_10024A36C((__int64)a3) );
}
if ( (unsigned int)sub_10024A36C((__int64)a3) )
{
v10 = 0;
v87 = a3;
v76 = a1;
v64 = v5;
LABEL_14:
v11 = sub_10024A388((__int64)a3, v10);
if ( (*(_BYTE *)(v11 + 1347) & 1) != 0 )
goto LABEL_115;
v12 = (SmartGameObject *)v11;
v104.x = sub_1000229B8((__int64 *)&v98, (__int64 *)&dword_10086E8B0);
v13 = GJSmartTemplate::smartObjectToType(v12, v104);
v102 = GJSmartTemplate::offsetForType(v13);
v14 = (float32x2_t *)((__int64 (__fastcall *)(SmartGameObject *, float, float))v12->getPosition)(
v12,
v102.x,
v102.y);
sub_1000229DC(v14, &v101, &v100);
sub_1000229B0(&v99);
v15.n128_u32[0] = v101.i32[0];
v16 = v101.f32[0] != *(float *)&dword_10086E8B0;
if ( v101.f32[1] != *(float *)&dword_10086E8B4 )
v16 = 1;
v65 = v16;
v66 = v10;
v17 = v12;
if ( v16 )
{
v18 = (float32x2_t *)((__int64 (__fastcall *)(SmartGameObject *, __n128))v12->getPosition)(v12, v15);
sub_100022A04(&v101, (float32x2_t *)&v93);
sub_1000229DC(v18, (float32x2_t *)&v93, (float32x2_t *)&v98);
sub_1000229D0(&v99, (double *)&v98);
v19 = 2;
}
else
{
v19 = 1;
}
v75 = v19;
sub_100009900(&v98, "");
v82 = nullptr;
v20 = 0;
while ( 1 )
{
if ( v20 )
v21 = (__int64 *)&v99;
else
v21 = (__int64 *)&v100;
sub_1000229B8((__int64 *)&v97, v21);
v105.x = sub_1000229B8((__int64 *)&v93, (__int64 *)&v97);
SmartNeighbor = EditorUI::getSmartNeighbor(v22, v17, v105, (GJSmartDirection)&v93, (cocos2d::CCArray *)1);
v106.x = sub_1000229B8((__int64 *)&v93, (__int64 *)&v97);
v86 = EditorUI::getSmartNeighbor(v24, v17, v106, (GJSmartDirection)&v93, (cocos2d::CCArray *)2);
v107.x = sub_1000229B8((__int64 *)&v93, (__int64 *)&v97);
v26 = EditorUI::getSmartNeighbor(v25, v17, v107, (GJSmartDirection)&v93, (cocos2d::CCArray *)3);
v108.x = sub_1000229B8((__int64 *)&v93, (__int64 *)&v97);
v28 = EditorUI::getSmartNeighbor(v27, v17, v108, (GJSmartDirection)&v93, (cocos2d::CCArray *)4);
v109.x = sub_1000229B8((__int64 *)&v93, (__int64 *)&v97);
v30 = EditorUI::getSmartNeighbor(v29, v17, v109, (GJSmartDirection)&v93, (cocos2d::CCArray *)5);
v110.x = sub_1000229B8((__int64 *)&v93, (__int64 *)&v97);
v32 = EditorUI::getSmartNeighbor(v31, v17, v110, (GJSmartDirection)&v93, (cocos2d::CCArray *)6);
v111.x = sub_1000229B8((__int64 *)&v93, (__int64 *)&v97);
v34 = EditorUI::getSmartNeighbor(v33, v17, v111, (GJSmartDirection)&v93, (cocos2d::CCArray *)7);
v112.x = sub_1000229B8((__int64 *)&v93, (__int64 *)&v97);
v36 = EditorUI::getSmartNeighbor(v35, v17, v112, (GJSmartDirection)&v93, (cocos2d::CCArray *)8);
v37 = v36;
if ( SmartNeighbor )
v85 = !SmartNeighbor->m_referenceOnly;
else
v85 = 0;
if ( v86 )
{
v38 = !v86->m_referenceOnly;
if ( v26 )
goto LABEL_29;
}
else
{
v38 = 0;
if ( v26 )
{
LABEL_29:
v84 = !v26->m_referenceOnly;
if ( v28 )
goto LABEL_30;
goto LABEL_37;
}
}
v84 = 0;
if ( v28 )
{
LABEL_30:
v83 = !v28->m_referenceOnly;
if ( v30 )
goto LABEL_31;
goto LABEL_38;
}
LABEL_37:
v83 = 0;
if ( v30 )
{
LABEL_31:
v81 = !v30->m_referenceOnly;
if ( v32 )
goto LABEL_32;
goto LABEL_39;
}
LABEL_38:
v81 = 0;
if ( v32 )
{
LABEL_32:
v80 = !v32->m_referenceOnly;
if ( v34 )
goto LABEL_33;
goto LABEL_40;
}
LABEL_39:
v80 = 0;
if ( v34 )
{
LABEL_33:
v79 = !v34->m_referenceOnly;
if ( v36 )
goto LABEL_34;
goto LABEL_41;
}
LABEL_40:
v79 = 0;
if ( v36 )
{
LABEL_34:
v78 = !v36->m_referenceOnly;
goto LABEL_42;
}
LABEL_41:
v78 = 0;
LABEL_42:
sub_100022990((float *)&v94, v97.f32[0] + -14.0, v97.f32[1] + -14.0, 28.0, 28.0);
if ( !v85 )
v96 = v96 + 14.0;
if ( !v38 )
{
v96 = v96 + 14.0;
v94.f32[1] = v94.f32[1] + -14.0;
}
v77 = v26;
if ( !v84 )
{
v95 = v95 + 14.0;
v94.f32[0] = v94.f32[0] + -14.0;
}
v39 = v38;
if ( !v83 )
v95 = v95 + 14.0;
m_editorLayer = v76->m_editorLayer;
v41 = sub_100022B98(&v93, (__int64)&v94);
v103.origin.x = *(float *)&v41;
v103.origin.y = v59;
v103.size.width = v60;
v103.size.height = v61;
v42 = LevelEditorLayer::objectsInRect(m_editorLayer, v103, (bool)&v93);
if ( v82 )
{
if ( v42 )
sub_10024A360((__int64)v82, (__int64)v42);
if ( v20 )
goto LABEL_59;
LABEL_56:
sub_1000229B8(&v92, (__int64 *)&v97);
GJSmartTemplate::keyFromNeighbors(v43, v17, SmartNeighbor, v86, v77, v28, v30, v32, &v93, v34, v37);
if ( SHIBYTE(v98.__r_.__value_.__r.__words[2]) < 0 )
operator delete(v98.__r_.__value_.__l.__data_);
v98 = v93;
v67 = v78;
v68 = v79;
v69 = v80;
v70 = v81;
v71 = v83;
v72 = v84;
v73 = v39;
v74 = v85;
goto LABEL_59;
}
v82 = v42;
if ( !v20 )
goto LABEL_56;
LABEL_59:
if ( v75 == ++v20 )
{
v44 = v17;
m_linkedGroup = v17->m_linkedGroup;
a3 = v87;
v10 = v66;
if ( m_linkedGroup > 0 )
{
StickyGroup = GJBaseGameLayer::getStickyGroup(v76->m_editorLayer, m_linkedGroup);
if ( StickyGroup )
{
for ( i = 0; i < (unsigned int)sub_10024A36C((__int64)StickyGroup); ++i )
{
v48 = sub_10024A388((__int64)StickyGroup, i);
if ( (sub_10024A420((__int64)v82, v48) & 1) == 0 )
sub_10024A2D0((__int64)v82);
}
}
}
if ( v82 )
{
for ( j = 0; ; j = (unsigned int)(j + 1) )
{
while ( 1 )
{
if ( (unsigned int)j >= (unsigned int)sub_10024A36C((__int64)v82) )
{
if ( (unsigned int)sub_10024A36C((__int64)v82) )
{
m_objectID = v44->m_objectID;
((void (__fastcall *)(std::string *__return_ptr, SmartGameObject *))v44->getRealPosition)(&v93, v44);
Object = EditorUI::createObject(v76, m_objectID, v113);
sub_10024A2D0((__int64)v82);
((void (__fastcall *)(SmartGameObject *))v44->getRotation)(v44);
((void (__fastcall *)(GameObject *))Object->setRotation)(Object);
v57 = ((__int64 (__fastcall *)(SmartGameObject *))v44->isFlipX)(v44);
((void (__fastcall *)(GameObject *, __int64))Object->setFlipX)(Object, v57);
v58 = ((__int64 (__fastcall *)(SmartGameObject *))v44->isFlipY)(v44);
((void (__fastcall *)(GameObject *, __int64))Object->setFlipY)(Object, v58);
Object->m_hasGroupParent = 1;
qsort(
v82->data->arr,
v82->data->num,
8u,
(int (__cdecl *)(const void *, const void *))sub_1003C4B40);
EditorUI::copyObjectsDetailed((__int64)v76, v82, &v93);
Object->m_hasGroupParent = 0;
EditorUI::deleteObject(v76, Object, 1);
if ( SHIBYTE(v98.__r_.__value_.__r.__words[2]) < 0 )
sub_1000097D0(&__dst, v98.__r_.__value_.__l.__data_, v98.__r_.__value_.__l.__size_);
else
__dst = v98;
if ( SHIBYTE(v93.__r_.__value_.__r.__words[2]) < 0 )
sub_1000097D0(&__p, v93.__r_.__value_.__l.__data_, v93.__r_.__value_.__l.__size_);
else
__p = v93;
GJSmartTemplate::savePrefab((std::string *)a2, (__int64)&__dst, &__p);
if ( SHIBYTE(__p.__r_.__value_.__r.__words[2]) < 0 )
operator delete(__p.__r_.__value_.__l.__data_);
if ( SHIBYTE(__dst.__r_.__value_.__r.__words[2]) < 0 )
operator delete(__dst.__r_.__value_.__l.__data_);
if ( SHIBYTE(v93.__r_.__value_.__r.__words[2]) < 0 )
operator delete(v93.__r_.__value_.__l.__data_);
}
goto LABEL_113;
}
v50 = sub_10024A388((__int64)v82, j);
v51 = (cocos2d::CCObject *)v50;
if ( *(_DWORD *)(v50 + 1248) != 5
&& !cocos2d::CCDictionary::objectForKey(v64, *(unsigned int *)(v50 + 916)) )
{
break;
}
LABEL_72:
sub_10024A44C((__int64)v82, j, 1);
}
v52 = (__int64 *)((__int64 (__fastcall *)(cocos2d::CCObject *))v51->__vftable[2].acceptVisitor)(v51);
sub_1000229B8((__int64 *)&v93, v52);
v53 = cocos2d::ccpDistance((const cocos2d::CCPoint *)&v100, (const cocos2d::CCPoint *)&v93);
if ( v65 && v53 > cocos2d::ccpDistance(&v99, (const cocos2d::CCPoint *)&v93) )
v53 = cocos2d::ccpDistance(&v99, (const cocos2d::CCPoint *)&v93);
v54 = (unsigned int)v51[15].m_uIndexInArray;
if ( (int)v54 >= 1 )
{
if ( (_DWORD)v54 == v44->m_linkedGroup )
goto LABEL_82;
if ( cocos2d::CCDictionary::objectForKey(v63, v54) )
goto LABEL_72;
LODWORD(v54) = v51[15].m_uIndexInArray;
}
if ( !(_DWORD)v54 || (_DWORD)v54 != v44->m_linkedGroup )
{
if ( v74 )
{
GJSmartTemplate::offsetForDir((GJSmartDirection)1, 0);
sub_1000229DC(&v100, &v97, &v94);
if ( cocos2d::ccpDistance((const cocos2d::CCPoint *)&v93, (const cocos2d::CCPoint *)&v94) < v53 )
goto LABEL_72;
}
if ( v73 )
{
GJSmartTemplate::offsetForDir((GJSmartDirection)2, 0);
sub_1000229DC(&v100, &v97, &v94);
if ( cocos2d::ccpDistance((const cocos2d::CCPoint *)&v93, (const cocos2d::CCPoint *)&v94) < v53 )
goto LABEL_72;
}
if ( v72 )
{
GJSmartTemplate::offsetForDir((GJSmartDirection)3, 0);
sub_1000229DC(&v100, &v97, &v94);
if ( cocos2d::ccpDistance((const cocos2d::CCPoint *)&v93, (const cocos2d::CCPoint *)&v94) < v53 )
goto LABEL_72;
}
if ( v71 )
{
GJSmartTemplate::offsetForDir((GJSmartDirection)4, 0);
sub_1000229DC(&v100, &v97, &v94);
if ( cocos2d::ccpDistance((const cocos2d::CCPoint *)&v93, (const cocos2d::CCPoint *)&v94) < v53 )
goto LABEL_72;
}
if ( v70 )
{
GJSmartTemplate::offsetForDir(TopLeft, 0);
sub_1000229DC(&v100, &v97, &v94);
if ( cocos2d::ccpDistance((const cocos2d::CCPoint *)&v93, (const cocos2d::CCPoint *)&v94) < v53 )
goto LABEL_72;
}
if ( v69 )
{
GJSmartTemplate::offsetForDir(TopRight, 0);
sub_1000229DC(&v100, &v97, &v94);
if ( cocos2d::ccpDistance((const cocos2d::CCPoint *)&v93, (const cocos2d::CCPoint *)&v94) < v53 )
goto LABEL_72;
}
if ( v68 )
{
GJSmartTemplate::offsetForDir(BottomLeft, 0);
sub_1000229DC(&v100, &v97, &v94);
if ( cocos2d::ccpDistance((const cocos2d::CCPoint *)&v93, (const cocos2d::CCPoint *)&v94) < v53 )
goto LABEL_72;
}
if ( v67 )
{
GJSmartTemplate::offsetForDir(BottomRight, 0);
sub_1000229DC(&v100, &v97, &v94);
if ( cocos2d::ccpDistance((const cocos2d::CCPoint *)&v93, (const cocos2d::CCPoint *)&v94) < v53 )
goto LABEL_72;
}
}
LABEL_82:
cocos2d::CCDictionary::setObject(v64, v51, v51[16].m_uReference);
}
}
LABEL_113:
if ( SHIBYTE(v98.__r_.__value_.__r.__words[2]) < 0 )
operator delete(v98.__r_.__value_.__l.__data_);
LABEL_115:
if ( ++v10 >= (unsigned int)sub_10024A36C((__int64)a3) )
break;
goto LABEL_14;
}
}
}
GJSmartTemplate::logTemplateStatus((__int64)a2, (int)&v88);
if ( v89 < 0 )
operator delete(v88);
}
}