//
// EditorUI::createPrefab from 0x3a40c0 to 0x3a42e6 (550 bytes)
//
// 2 xrefs:
// > SetupSmartBlockLayer::onCreateAll @ 0x53d2e4
// > BrowseSmartTemplateLayer::createPrefab @ 0x53f186
//
// 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::createPrefab(EditorUI *a1, GJSmartTemplate *a2, int a3, int a4)
{
cocos2d::CCDirector *v8; // r0
cocos2d::CCNode *m_objectLayer; // r6
int v10; // r11
cocos2d::CCPoint v11; // r2
int v12; // r2
bool v13; // r3
SmartBlockType v14; // r8
int v15; // r2
bool v16; // r3
cocos2d::CCPoint v17; // r2
int PrefabWithID; // r6
cocos2d::CCArray *v19; // r6
bool v20; // [sp+0h] [bp-44h]
SmartGameObject *v21; // [sp+Ch] [bp-38h]
SmartGameObject *Object; // [sp+Ch] [bp-38h]
cocos2d::CCSize v23; // [sp+14h] [bp-30h] BYREF
cocos2d::CCPoint v24; // [sp+1Ch] [bp-28h] BYREF
cocos2d::CCPoint v25; // [sp+24h] [bp-20h] BYREF
cocos2d::CCPoint v26; // [sp+2Ch] [bp-18h] BYREF
cocos2d::CCPoint v27; // [sp+34h] [bp-10h] BYREF
v8 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getWinSize(&v23, v8);
m_objectLayer = a1->m_editorLayer->m_objectLayer;
cocos2d::CCPoint::CCPoint(&v27, v23.width * 0.5, (float)(a1->m_toolbarHeight * 0.5) + (float)(v23.height * 0.5));
cocos2d::CCNode::convertToNodeSpace(&v24, m_objectLayer, &v27);
v10 = 0;
v24.x = v24.x + (float)((float)(4 * a2->m_prefabIndex) * 30.0);
cocos2d::CCPoint::CCPoint(&v26, &v24);
LODWORD(v11.x) = &v26;
EditorUI::getGridSnappedPos(&v27, a1, v11);
cocos2d::CCPoint::operator=((PlayerObject *)&v24, COERCE_FLOAT(&v27), v12, v13);
++a2->m_prefabIndex;
cocos2d::CCPoint::CCPoint(&v25, (const cocos2d::CCPoint *)&flt_AC5D38);
do
{
v14 = *(unsigned __int8 *)sub_7757BC(a3, v10);
if ( v14 == 48 )
goto LABEL_19;
GJSmartTemplate::offsetForType(&v26, v14);
if ( !v10 )
{
cocos2d::CCPoint::operator=((PlayerObject *)&v25, COERCE_FLOAT(&v26), v15, v16);
LABEL_9:
if ( (unsigned int)(v10 - 7) > 1 )
goto LABEL_11;
goto LABEL_10;
}
if ( v10 == 1 || (unsigned int)(v10 - 5) <= 1 )
v26.y = v26.y + 30.0;
if ( v10 != 2 )
goto LABEL_9;
LABEL_10:
v26.y = v26.y - 30.0;
LABEL_11:
if ( (v10 & 0xFFFFFFFB) == 3 || v10 == 5 )
v26.x = v26.x - 30.0;
if ( (v10 & 0xFFFFFFFD) == 4 || v10 == 8 )
v26.x = v26.x + 30.0;
v21 = (SmartGameObject *)GJSmartTemplate::smartTypeToObjectKey(v14);
cocos2d::CCPoint::operator+(&v27, &v24, &v26);
LODWORD(v17.x) = &v27;
Object = (SmartGameObject *)EditorUI::createObject(a1, (int)v21, v17);
GJSmartTemplate::applyTransformationsForType(v14, Object);
if ( v10 )
{
Object->m_referenceOnly = 1;
SmartGameObject::updateSmartFrame(Object);
}
LABEL_19:
++v10;
}
while ( v10 != 9 );
if ( a4 > 0 )
{
sub_775C20(&v27, a3);
PrefabWithID = GJSmartTemplate::getPrefabWithID(a2, (std::string)&v27, a4);
sub_774008(&v27);
if ( PrefabWithID )
{
sub_775C20(&v27, PrefabWithID + 56);
v19 = EditorUI::pasteObjects(a1, &v27, 0, 0);
sub_774008(&v27);
cocos2d::CCPoint::operator+(&v27, &v24, &v25);
EditorUI::repositionObjectsToCenter(a1, v19, (cocos2d::CCPoint)(unsigned int)&v27, v20);
EditorUI::deleteSmartBlocksFromObjects(a1, v19);
}
}
}