//
// EditorUI::createPrefab from 0x6c05dc to 0x6c0a20 (1092 bytes)
//
// 3 xrefs:
// > SetupSmartBlockLayer::onCreateAll @ 0x9dc654
// > BrowseSmartTemplateLayer::createPrefab @ 0x9e0544
// > ??> @ 0x92880
//
// 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
//
__int64 __fastcall EditorUI::createPrefab(EditorUI *a1, GJSmartTemplate *a2, __int64 *a3, int a4)
{
cocos2d::CCDirector *v7; // x0
unsigned __int64 v8; // x19
int v9; // w27
float v10; // s2
__int64 v11; // x0
unsigned __int64 v12; // x2
SmartBlockType v13; // w25
_BOOL4 v14; // w2
int v15; // w0
int v16; // w28
SmartGameObject *Object; // x28
__int64 PrefabWithID; // x21
void *v19; // x0
cocos2d::CCArray *v20; // x21
void *v21; // x0
unsigned int *v23; // x1
int v24; // w2
unsigned int *v25; // x1
int v26; // w2
__int64 v27; // [xsp+0h] [xbp+0h] BYREF
cocos2d::CCPoint *v28; // [xsp+78h] [xbp+78h]
cocos2d::CCNode *m_objectLayer; // [xsp+80h] [xbp+80h]
int v30; // [xsp+8Ch] [xbp+8Ch]
float v31; // [xsp+90h] [xbp+90h]
float v32; // [xsp+94h] [xbp+94h]
cocos2d::CCPoint v33; // [xsp+98h] [xbp+98h] BYREF
cocos2d::CCPoint v34; // [xsp+A0h] [xbp+A0h] BYREF
cocos2d::CCPoint v35; // [xsp+A8h] [xbp+A8h] BYREF
cocos2d::CCPoint v36; // [xsp+B0h] [xbp+B0h] BYREF
cocos2d::CCPoint GridSnappedPos; // 0:kr10_8.8
cocos2d::CCPoint v38; // 0:kr18_8.8
cocos2d::CCPoint v39; // 0:s0.4,4:s1.4
cocos2d::CCPoint v40; // 0:s0.4,4:s1.4
cocos2d::CCPoint v41; // 0:s0.4,4:s1.4
v30 = a4;
v28 = &v34;
v7 = cocos2d::CCDirector::sharedDirector();
v8 = 0;
v9 = 0;
cocos2d::CCDirector::getWinSize(v7);
v10 = a1->m_toolbarHeight * 0.5;
m_objectLayer = a1->m_editorLayer->m_objectLayer;
cocos2d::CCPoint::CCPoint(&v36, v31 * 0.5, v10 + (float)(v32 * 0.5));
cocos2d::CCNode::convertToNodeSpace(m_objectLayer, &v36);
v33.x = v33.x + (float)((float)(4 * a2->m_prefabIndex) * 30.0);
cocos2d::CCPoint::CCPoint(&v35, &v33);
GridSnappedPos = EditorUI::getGridSnappedPos(a1, v39);
cocos2d::CCPoint::operator=(&v33, GridSnappedPos.x, GridSnappedPos.y);
++a2->m_prefabIndex;
cocos2d::CCPoint::CCPoint(&v34, (const cocos2d::CCPoint *)&dword_1242110);
do
{
v11 = *a3;
v12 = *(_QWORD *)(*a3 - 24);
if ( v8 >= v12 )
sub_D13C5C("basic_string::at: __n (which is %zu) >= this->size() (which is %zu)", v8, v12);
if ( (*(_DWORD *)(v11 - 8) & 0x80000000) == 0 )
{
sub_D176A8(a3);
v11 = *a3;
}
v13 = *(unsigned __int8 *)(v11 + v8);
if ( v13 != 48 )
{
v38 = GJSmartTemplate::offsetForType(v13);
if ( v9 )
{
v14 = v9 == 6;
if ( (unsigned int)(v9 - 5) <= 1 || v9 == 1 )
v35.y = v35.y + 30.0;
v15 = v9;
if ( (unsigned int)(v9 - 7) <= 1 || v9 == 2 )
v35.y = v35.y - 30.0;
if ( v9 == 5 )
{
LABEL_24:
v35.x = v35.x - 30.0;
LABEL_13:
if ( v14 || ((v15 - 4) & 0xFFFFFFFB) == 0 )
v35.x = v35.x + 30.0;
v16 = GJSmartTemplate::smartTypeToObjectKey(v13);
cocos2d::CCPoint::operator+(&v36, &v33, &v35);
Object = (SmartGameObject *)EditorUI::createObject(a1, v16, v40);
GJSmartTemplate::applyTransformationsForType(v13, Object);
if ( v9 )
{
Object->m_referenceOnly = 1;
SmartGameObject::updateSmartFrame(Object);
}
goto LABEL_17;
}
}
else
{
cocos2d::CCPoint::operator=(v28, v38.x, v38.y);
v15 = 0;
v14 = 0;
}
if ( (v9 & 0xFFFFFFFB) != 3 )
goto LABEL_13;
goto LABEL_24;
}
LABEL_17:
++v9;
++v8;
}
while ( v9 != 9 );
if ( v30 > 0 )
{
sub_D18D28(&v36, a3);
PrefabWithID = GJSmartTemplate::getPrefabWithID(a2, (std::string)&v36, v30);
v19 = (void *)(*(_QWORD *)&v36 - 24LL);
if ( (__int64 *)(*(_QWORD *)&v36 - 24LL) == &qword_124B6B0 )
goto LABEL_20;
if ( &pthread_create )
{
v23 = (unsigned int *)(*(_QWORD *)&v36 - 8LL);
do
v24 = __ldaxr(v23);
while ( __stlxr(v24 - 1, v23) );
}
else
{
v24 = *(_DWORD *)(*(_QWORD *)&v36 - 8LL);
*(_DWORD *)(*(_QWORD *)&v36 - 8LL) = v24 - 1;
}
if ( v24 > 0 )
{
LABEL_20:
if ( PrefabWithID )
goto LABEL_21;
}
else
{
operator delete(v19);
if ( !PrefabWithID )
return _stack_chk_guard;
LABEL_21:
sub_D18D28(&v36, PrefabWithID + 64);
v20 = EditorUI::pasteObjects(a1, (const void **)&v36, 0, 0);
v21 = (void *)(*(_QWORD *)&v36 - 24LL);
if ( (__int64 *)(*(_QWORD *)&v36 - 24LL) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v25 = (unsigned int *)(*(_QWORD *)&v36 - 8LL);
do
v26 = __ldaxr(v25);
while ( __stlxr(v26 - 1, v25) );
}
else
{
v26 = *(_DWORD *)(*(_QWORD *)&v36 - 8LL);
*(_DWORD *)(*(_QWORD *)&v36 - 8LL) = v26 - 1;
}
if ( v26 <= 0 )
operator delete(v21);
}
cocos2d::CCPoint::operator+(&v36, &v33, v28);
EditorUI::repositionObjectsToCenter(a1, v20, v41, (unsigned __int8)&v27 - 80);
EditorUI::deleteSmartBlocksFromObjects(a1, v20);
}
}
return _stack_chk_guard;
}