//
// EditorUI::createPrefab from 0x1003f2244 to 0x1003f2574 (816 bytes)
//
// 2 xrefs:
// > SetupSmartBlockLayer::onCreateAll @ 0x100070198
// > BrowseSmartTemplateLayer::createPrefab @ 0x1000727b4
//
// 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, __int64 a2, __int64 a3, int a4)
{
cocos2d::CCDirector *v7; // x0
cocos2d::CCNode *m_objectLayer; // x23
__n128 v9; // q0
__n128 v10; // q1
std::string::size_type i; // x23
std::string::reference v12; // x0
SmartBlockType v13; // w24
_BOOL4 v14; // w8
bool v15; // w9
char v16; // w10
bool v17; // w8
int v18; // w25
SmartGameObject *Object; // x25
__int64 PrefabWithID; // x0
__int64 v21; // x20
cocos2d::CCArray *v22; // x20
std::string __dst; // [xsp+10h] [xbp-C0h] BYREF
void *__p[2]; // [xsp+30h] [xbp-A0h] BYREF
__int64 v26; // [xsp+40h] [xbp-90h]
float32x2_t v27; // [xsp+48h] [xbp-88h] BYREF
float32x2_t v28; // [xsp+50h] [xbp-80h] BYREF
float32x2_t v29; // [xsp+58h] [xbp-78h] BYREF
float32x2_t v30; // [xsp+60h] [xbp-70h] BYREF
float v31; // [xsp+68h] [xbp-68h]
float v32; // [xsp+6Ch] [xbp-64h]
cocos2d::CCPoint v33; // 0:s0.4,4:s1.4
cocos2d::CCPoint v34; // 0:s0.4,4:s1.4
cocos2d::CCPoint v35; // 0:s0.4,4:s1.4
v7 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getWinSize(v7);
m_objectLayer = a1->m_editorLayer->m_objectLayer;
v9.n128_f32[0] = v31 * 0.5;
v10.n128_f32[0] = (float)(v32 * 0.5) + (float)(a1->m_toolbarHeight * 0.5);
sub_100022980(v9, v10, &v29);
cocos2d::CCNode::convertToNodeSpace(m_objectLayer, (const cocos2d::CCPoint *)&v29);
v30.f32[0] = v30.f32[0] + (float)((float)(4 * *(_DWORD *)(a2 + 196)) * 30.0);
v33.x = sub_1000229B8((__int64 *)&v28, (__int64 *)&v30);
EditorUI::getGridSnappedPos(a1, v33);
sub_1000229D0(&v30, (double *)&v29);
++*(_DWORD *)(a2 + 196);
sub_1000229B8((__int64 *)&v29, (__int64 *)&dword_10086E8B0);
for ( i = 0; i != 9; ++i )
{
v12 = std::string::at((std::string *)a3, i);
v13 = *v12;
if ( v13 != 48 )
{
GJSmartTemplate::offsetForType((SmartBlockType)*v12);
if ( i )
{
v14 = i == 5;
if ( (unsigned int)i <= 6 && ((1 << i) & 0x62) != 0 )
v28.f32[1] = v28.f32[1] + 30.0;
v15 = i == 8;
if ( (unsigned int)i <= 8 && ((1 << i) & 0x184) != 0 )
v28.f32[1] = v28.f32[1] + -30.0;
v16 = i;
}
else
{
sub_1000229D0(&v29, (double *)&v28);
v16 = 0;
v15 = 0;
v14 = 0;
}
if ( (v16 & 0xB) == 3 || v14 )
v28.f32[0] = v28.f32[0] + -30.0;
v17 = !v15;
if ( (v16 & 0xD) == 4 )
v17 = 0;
if ( !v17 )
v28.f32[0] = v28.f32[0] + 30.0;
v18 = GJSmartTemplate::smartTypeToObjectKey(v13);
v34.x = sub_1000229DC(&v30, &v28, &v27).f32[0];
Object = (SmartGameObject *)EditorUI::createObject(a1, v18, v34);
GJSmartTemplate::applyTransformationsForType(v13, Object);
if ( i )
{
Object->m_referenceOnly = 1;
SmartGameObject::updateSmartFrame(Object);
}
}
}
if ( a4 > 0 )
{
if ( *(char *)(a3 + 23) < 0 )
{
sub_1000097D0(__p, *(void **)a3, *(_QWORD *)(a3 + 8));
}
else
{
*(_OWORD *)__p = *(_OWORD *)a3;
v26 = *(_QWORD *)(a3 + 16);
}
PrefabWithID = GJSmartTemplate::getPrefabWithID(a2, (__int64)__p, a4);
v21 = PrefabWithID;
if ( SHIBYTE(v26) < 0 )
{
operator delete(__p[0]);
if ( !v21 )
return;
}
else if ( !PrefabWithID )
{
return;
}
if ( *(char *)(v21 + 103) < 0 )
sub_1000097D0(&__dst, *(void **)(v21 + 80), *(_QWORD *)(v21 + 88));
else
__dst = *(std::string *)(v21 + 80);
v22 = EditorUI::pasteObjects((__int64)a1, &__dst, 0, 0);
if ( SHIBYTE(__dst.__r_.__value_.__r.__words[2]) < 0 )
operator delete(__dst.__r_.__value_.__l.__data_);
v35.x = sub_1000229DC(&v30, &v29, &v28).f32[0];
EditorUI::repositionObjectsToCenter(a1, v22, v35, (bool)&v28);
EditorUI::deleteSmartBlocksFromObjects(a1, v22);
}
}