//
// SetupSmartBlockLayer::onPasteTemplate from 0x1405ed6a0 to 0x1405edaab (1035 bytes)
//
// 2 xrefs:
// > SetupSmartBlockLayer::init @ 0x1405ec9a3
// > ??> @ 0x14092f0b4
//
// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 11:35:04 +0000
//
// Hidden C++ exception states: #wind=10
__int64 __fastcall SetupSmartBlockLayer::onPasteTemplate(__int64 a1)
{
__int64 v2; // rax
int v3; // edi
_BYTE *v4; // rbx
__int64 v5; // rcx
cocos2d::CCArray *v6; // rsi
__int64 v7; // rcx
__int64 v8; // rcx
int v9; // r8d
int v10; // eax
__int64 v11; // rcx
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rbx
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // rbx
float *v19; // rax
__int64 GridSnappedPos; // rax
__int64 v21; // rax
__int64 v22; // rbx
__int64 v23; // rax
__int64 v24; // rax
__int64 v25; // rbx
__int64 v26; // rcx
void *v28; // [rsp+40h] [rbp-40h] BYREF
void *v29; // [rsp+48h] [rbp-38h]
_BYTE v30[8]; // [rsp+50h] [rbp-30h] BYREF
void *v31; // [rsp+58h] [rbp-28h] BYREF
__int128 v32; // [rsp+60h] [rbp-20h] BYREF
__int64 v33; // [rsp+70h] [rbp-10h]
__int64 v34; // [rsp+78h] [rbp-8h]
__int128 *v35; // [rsp+B0h] [rbp+30h] BYREF
void *v36; // [rsp+B8h] [rbp+38h] BYREF
v2 = qword_14090BFD0;
if ( !qword_14090BFD0 )
{
v35 = (__int128 *)operator new(0x6E8u);
qword_14090BFD0 = GameManager::GameManager((__int64)v35);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFD0 + 72LL))(qword_14090BFD0);
v2 = qword_14090BFD0;
}
if ( *(_QWORD *)(v2 + 568) )
{
v35 = &v32;
v32 = 0;
v3 = 0;
v33 = 0;
v34 = 0;
v4 = sub_14003D460(0x1760u);
*(_QWORD *)&v32 = v4;
v33 = 5983;
v34 = 5983;
memcpy(v4, a12895236453195, 0x175Fu);
v4[5983] = 0;
v5 = qword_14090BFD0;
if ( !qword_14090BFD0 )
{
v36 = operator new(0x6E8u);
qword_14090BFD0 = GameManager::GameManager((__int64)v36);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFD0 + 72LL))(qword_14090BFD0);
v5 = qword_14090BFD0;
}
v6 = EditorUI::pasteObjects(*(_QWORD *)(*(_QWORD *)(v5 + 568) + 14904LL), (__int64 *)&v32, 0, 0);
v7 = qword_14090BFD0;
if ( !qword_14090BFD0 )
{
v35 = (__int128 *)operator new(0x6E8u);
qword_14090BFD0 = GameManager::GameManager((__int64)v35);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFD0 + 72LL))(qword_14090BFD0);
v7 = qword_14090BFD0;
}
v8 = *(_QWORD *)(v7 + 568);
v9 = *(_DWORD *)(v8 + 15504);
if ( v9 >= 0 )
{
v10 = *(_DWORD *)(v8 + 15440) - v9;
if ( v10 > 1 )
{
do
{
if ( v3 >= 7 )
break;
v10 = (unsigned int)v10 >> 1;
++v3;
}
while ( (unsigned int)v10 > 1 );
}
++*(_DWORD *)(v8 + 4LL * v3 + 15472);
}
*(_DWORD *)(v8 + 15504) = *(_DWORD *)(v8 + 15440);
if ( v6 && cocos2d::CCArray::count(v6) )
{
v12 = cocos2d::CCDirector::sharedDirector(v11);
cocos2d::CCDirector::getWinSize(v12, &v36);
v13 = qword_14090BFD0;
if ( !qword_14090BFD0 )
{
v28 = operator new(0x6E8u);
qword_14090BFD0 = GameManager::GameManager((__int64)v28);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFD0 + 72LL))(qword_14090BFD0);
v13 = qword_14090BFD0;
}
v14 = *(_QWORD *)(v13 + 568);
v15 = *(_QWORD *)(v14 + 4296);
cocos2d::CCPoint::CCPoint(
(cocos2d::CCPoint *)&v28,
*(float *)&v36 * 0.5,
(float)(*(float *)(*(_QWORD *)(v14 + 14904) + 904LL) * 0.5) + (float)(*((float *)&v36 + 1) * 0.5));
cocos2d::CCNode::convertToNodeSpace(v15, &v35, v16);
v17 = qword_14090BFD0;
if ( !qword_14090BFD0 )
{
v29 = operator new(0x6E8u);
qword_14090BFD0 = GameManager::GameManager((__int64)v29);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFD0 + 72LL))(qword_14090BFD0);
v17 = qword_14090BFD0;
}
v18 = *(_QWORD *)(*(_QWORD *)(v17 + 568) + 14904LL);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)v30, (const struct cocos2d::CCPoint *)&v35);
GridSnappedPos = EditorUI::getGridSnappedPos(v18, (__int64)&v31, v19);
cocos2d::CCPoint::operator=(&v35, GridSnappedPos);
v21 = qword_14090BFD0;
if ( !qword_14090BFD0 )
{
v29 = operator new(0x6E8u);
qword_14090BFD0 = GameManager::GameManager((__int64)v29);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFD0 + 72LL))(qword_14090BFD0);
v21 = qword_14090BFD0;
}
v22 = *(_QWORD *)(*(_QWORD *)(v21 + 568) + 14904LL);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)&v28, (const struct cocos2d::CCPoint *)&v35);
EditorUI::repositionObjectsToCenter(v22, v6, v23, 0);
v24 = *(_QWORD *)&qword_14090BFB0;
if ( !*(_QWORD *)&qword_14090BFB0 )
{
v31 = operator new(0x690u);
*(_QWORD *)&qword_14090BFB0 = GameLevelManager::GameLevelManager((__int64)v31);
(*(void (__fastcall **)(_QWORD))(**(_QWORD **)&qword_14090BFB0 + 72LL))(*(_QWORD *)&qword_14090BFB0);
v24 = *(_QWORD *)&qword_14090BFB0;
}
v25 = *(_QWORD *)(v24 + 1664);
if ( v25 )
{
v26 = qword_14090BFD0;
if ( !qword_14090BFD0 )
{
v31 = operator new(0x6E8u);
qword_14090BFD0 = GameManager::GameManager((__int64)v31);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFD0 + 72LL))(qword_14090BFD0);
v26 = qword_14090BFD0;
}
EditorUI::createSmartObjectsFromTemplate(*(_QWORD *)(*(_QWORD *)(v26 + 568) + 14904LL), v25, v6, 0, 1, 1);
}
}
}
return SetupSmartBlockLayer::onClose(a1, 0);
}