//
// EditorUI::createPrefab from 0x1401179a0 to 0x140117da4 (1028 bytes)
//
// 4 xrefs:
// > SetupSmartBlockLayer::onCreateAll @ 0x14045834e
// > BrowseSmartTemplateLayer::createPrefab @ 0x14045b097
// > ??> @ 0x1406c92e8
// > ??> @ 0x1406c92f4
//
// 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
//
// Hidden C++ exception states: #wind=1
void __fastcall EditorUI::createPrefab(EditorUI *a1, __int64 a2, _QWORD *a3, int a4)
{
cocos2d::CCDirector *v8; // rax
cocos2d::CCNode *m_objectLayer; // rbx
float m_gridSize; // xmm8_4
float *v11; // rax
float v12; // xmm6_4
float v13; // xmm7_4
float v14; // xmm0_4
__int64 v15; // rcx
__int64 i; // rbx
_QWORD *v17; // rax
SmartBlockType v18; // edi
float v19; // xmm0_4
float v20; // xmm0_4
int v21; // edx
SmartGameObject *Object; // r14
__int64 v23; // rax
__int64 PrefabWithID; // rax
__int64 *v25; // rax
cocos2d::CCArray *v26; // rbx
float v27; // [rsp+28h] [rbp-B9h] BYREF
float v28; // [rsp+2Ch] [rbp-B5h]
struct cocos2d::CCPoint v29; // [rsp+30h] [rbp-B1h] BYREF
cocos2d::CCPoint v30; // [rsp+38h] [rbp-A9h] BYREF
float v31; // [rsp+40h] [rbp-A1h]
float v32; // [rsp+44h] [rbp-9Dh]
cocos2d::CCPoint v33; // [rsp+48h] [rbp-99h] BYREF
cocos2d::CCPoint v34; // [rsp+50h] [rbp-91h] BYREF
_BYTE v35[32]; // [rsp+58h] [rbp-89h] BYREF
_BYTE v36[32]; // [rsp+78h] [rbp-69h] BYREF
_QWORD *v37; // [rsp+98h] [rbp-49h]
v37 = a3;
v8 = (cocos2d::CCDirector *)cocos2d::CCDirector::sharedDirector(a1);
cocos2d::CCDirector::getWinSize(v8);
m_objectLayer = a1->m_editorLayer->m_objectLayer;
cocos2d::CCPoint::CCPoint(&v30, v31 * 0.5, (float)(a1->m_toolbarHeight * 0.5) + (float)(v32 * 0.5));
cocos2d::CCNode::convertToNodeSpace(m_objectLayer, &v29);
v29.x = v29.x + (float)((float)(4 * *(_DWORD *)(a2 + 204)) * 30.0);
cocos2d::CCPoint::CCPoint(&v30, &v29);
m_gridSize = a1->m_editorLayer->m_drawGridLayer->m_gridSize;
v12 = v11[1] / m_gridSize;
v13 = (float)(floorf(*v11 / m_gridSize) + 0.5) * m_gridSize;
v14 = (float)(floorf(v12) + 0.5) * m_gridSize;
cocos2d::CCPoint::CCPoint(&v34, v13, v14);
EditorUI::getLimitedPosition(a1, (cocos2d::CCPoint)&v27);
cocos2d::CCPoint::operator=(&v29, &v27);
++*(_DWORD *)(a2 + 204);
cocos2d::CCPoint::CCPoint(&v33, (const struct cocos2d::CCPoint *)&dword_1406C1AA8);
for ( i = 0; i < 9; ++i )
{
if ( a3[2] <= (unsigned __int64)i )
sub_14003BCC0(v15);
v17 = a3;
if ( a3[3] > 0xFu )
v17 = (_QWORD *)*a3;
v18 = *((char *)v17 + i);
if ( v18 != 48 )
{
GJSmartTemplate::offsetForType((SmartBlockType)&v27);
if ( i )
{
if ( ((i - 1) & 0xFFFFFFFFFFFFFFFAuLL) != 0 || i == 2 )
{
v19 = v28;
}
else
{
v19 = v28 + 30.0;
v28 = v28 + 30.0;
}
if ( i == 2 || (unsigned __int64)(i - 7) <= 1 )
v28 = v19 + -30.0;
if ( ((i - 3) & 0xFFFFFFFFFFFFFFF9uLL) != 0 )
{
v20 = v27;
}
else
{
v20 = v27 + -30.0;
v27 = v27 + -30.0;
}
if ( ((i - 4) & 0xFFFFFFFFFFFFFFF9uLL) == 0 )
v27 = v20 + 30.0;
}
else
{
cocos2d::CCPoint::operator=(&v33, &v27);
}
cocos2d::CCPoint::operator+(&v29, &v30);
switch ( v18 )
{
case NormalSlope1:
case NormalSlope2:
case NormalSlope3:
case NormalSlope4:
v21 = 2896;
break;
case WideSlope1:
case WideSlope2:
case WideSlope3:
case WideSlope4:
case WideSlope5:
case WideSlope6:
case WideSlope7:
case WideSlope8:
case WideSlope9:
case WideSlope10:
case WideSlope11:
case WideSlope12:
case WideSlope13:
case WideSlope14:
case WideSlope15:
case WideSlope16:
v21 = 2897;
break;
default:
v21 = 2895;
break;
}
Object = (SmartGameObject *)EditorUI::createObject(a1, v21, (cocos2d::CCPoint)&v30);
GJSmartTemplate::applyTransformationsForType(v18, Object);
if ( i )
{
Object->m_referenceOnly = 1;
SmartGameObject::updateSmartFrame(Object);
}
}
}
if ( a4 > 0 )
{
v23 = sub_14003BDB0((__int64)v35, (__int64)a3);
PrefabWithID = GJSmartTemplate::getPrefabWithID(a2, v23, (unsigned int)a4);
if ( PrefabWithID )
{
v25 = (__int64 *)sub_14003BDB0((__int64)v36, PrefabWithID + 88);
v26 = EditorUI::pasteObjects(a1, v25, nullptr, 0);
cocos2d::CCPoint::operator+(&v29, &v30);
EditorUI::repositionObjectsToCenter(a1, v26, (cocos2d::CCPoint)&v30, 0);
EditorUI::deleteSmartBlocksFromObjects(a1, v26);
}
}
sub_14003A830((__int64)a3);
}