//
// SetupSmartBlockLayer::onPasteTemplate from 0x140457d20 to 0x14045811e (1022 bytes)
//
// 2 xrefs:
// > SetupSmartBlockLayer::init @ 0x14045705f
// > ??> @ 0x1406daa18
//
// 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=9
void SetupSmartBlockLayer::onPasteTemplate(SetupSmartBlockLayer *a1, cocos2d::CCObject *a2)
{
__int64 v3; // rax
_BYTE *v4; // rbx
__int64 v5; // rcx
cocos2d::CCArray *v6; // rax
cocos2d::CCArray *v7; // rdi
__int64 v8; // rcx
cocos2d::CCDirector *v9; // rax
__int64 v10; // rax
cocos2d::CCNode *v11; // rbx
__int64 v12; // rax
EditorUI *v13; // rbx
float m_gridSize; // xmm8_4
float *v15; // rax
float v16; // xmm6_4
float v17; // xmm7_4
float v18; // xmm0_4
__int64 v19; // rax
EditorUI *v20; // rbx
cocos2d::CCPoint v21; // rax
__int64 v22; // rax
GJSmartTemplate *v23; // rbx
__int64 v24; // rcx
bool v25; // [rsp+38h] [rbp-59h]
void *v26; // [rsp+48h] [rbp-49h] BYREF
void *v27; // [rsp+50h] [rbp-41h]
void *v28; // [rsp+58h] [rbp-39h]
cocos2d::CCPoint v29; // [rsp+60h] [rbp-31h] BYREF
cocos2d::CCPoint v30; // [rsp+68h] [rbp-29h] BYREF
__int128 v31; // [rsp+70h] [rbp-21h] BYREF
__int64 v32; // [rsp+80h] [rbp-11h]
__int64 v33; // [rsp+88h] [rbp-9h]
__int128 *v34; // [rsp+108h] [rbp+77h] BYREF
void *v35; // [rsp+110h] [rbp+7Fh]
v3 = qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v34 = (__int128 *)operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v34);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v3 = qword_1406C2ED8;
}
if ( *(_QWORD *)(v3 + 528) )
{
v34 = &v31;
v31 = 0;
v32 = 0;
v33 = 15;
v4 = sub_14003AA10(0x1760u);
*(_QWORD *)&v31 = v4;
v32 = 5983;
v33 = 5983;
memcpy(v4, a12895236453195, 0x175Fu);
v4[5983] = 0;
v5 = qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v35 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v35);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v5 = qword_1406C2ED8;
}
v6 = EditorUI::pasteObjects(*(EditorUI **)(*(_QWORD *)(v5 + 528) + 14496LL), (__int64 *)&v31, nullptr, 0);
v7 = v6;
if ( v6 && cocos2d::CCArray::count(v6) )
{
v9 = (cocos2d::CCDirector *)cocos2d::CCDirector::sharedDirector(v8);
cocos2d::CCDirector::getWinSize(v9);
v10 = qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v26 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v26);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v10 = qword_1406C2ED8;
}
v11 = *(cocos2d::CCNode **)(*(_QWORD *)(v10 + 528) + 4072LL);
cocos2d::CCPoint::CCPoint(*((float *)&v35 + 1) * 0.5, *(float *)&v35 * 0.5);
cocos2d::CCNode::convertToNodeSpace(v11, (const struct cocos2d::CCPoint *)&v34);
v12 = qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v28 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v28);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v12 = qword_1406C2ED8;
}
v13 = *(EditorUI **)(*(_QWORD *)(v12 + 528) + 14496LL);
cocos2d::CCPoint::CCPoint(&v29);
m_gridSize = v13->m_editorLayer->m_drawGridLayer->m_gridSize;
v16 = v15[1] / m_gridSize;
v17 = (float)(floorf(*v15 / m_gridSize) + 0.5) * m_gridSize;
v18 = (float)(floorf(v16) + 0.5) * m_gridSize;
cocos2d::CCPoint::CCPoint(v18, v17);
EditorUI::getLimitedPosition(v13, (cocos2d::CCPoint)&v26);
cocos2d::CCPoint::operator=(&v34, &v26);
v19 = qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v27 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v27);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v19 = qword_1406C2ED8;
}
v20 = *(EditorUI **)(*(_QWORD *)(v19 + 528) + 14496LL);
cocos2d::CCPoint::CCPoint(&v30);
EditorUI::repositionObjectsToCenter(v20, v7, v21, 0);
v22 = qword_1406C2EC0;
if ( !qword_1406C2EC0 )
{
v29 = (cocos2d::CCPoint)operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280(*(_QWORD *)&v29);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
v22 = qword_1406C2EC0;
}
v23 = *(GJSmartTemplate **)(v22 + 960);
if ( v23 )
{
v24 = qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v29 = (cocos2d::CCPoint)operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00(*(_QWORD *)&v29);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v24 = qword_1406C2ED8;
}
EditorUI::createSmartObjectsFromTemplate(
*(EditorUI **)(*(_QWORD *)(v24 + 528) + 14496LL),
v23,
v7,
0,
1,
1,
v25);
}
}
}
SetupSmartBlockLayer::onClose(a1, nullptr);
}