//
// SetupSmartBlockLayer::onPasteTemplate from 0x9dc2f4 to 0x9dc548 (596 bytes)
//
// 3 xrefs:
// > ??> @ 0x38d90
// > SetupSmartBlockLayer::init @ 0x9dd088
// > ??> @ 0x1229c20
//
// 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 SetupSmartBlockLayer::onPasteTemplate(SetupSmartBlockLayer *a1, cocos2d::CCObject *a2)
{
EditorUI *m_editorUI; // x22
cocos2d::CCArray *v4; // x22
void *v5; // x0
cocos2d::CCDirector *v6; // x0
GameManager *v7; // x0
float v8; // s9
__int128 v9; // q0
cocos2d::CCNode *m_objectLayer; // x25
GameManager *v11; // x0
EditorUI *v12; // x25
EditorUI *v13; // x21
GameLevelManager *v14; // x0
GJSmartTemplate *ActiveSmartTemplate; // x0
GameManager *v16; // x0
unsigned int *v17; // x2
int v18; // w1
__int64 v19; // [xsp+0h] [xbp+0h] BYREF
GJSmartTemplate *v20[2]; // [xsp+60h] [xbp+60h]
float v21; // [xsp+78h] [xbp+78h]
float v22; // [xsp+7Ch] [xbp+7Ch]
cocos2d::CCPoint v23; // [xsp+80h] [xbp+80h] BYREF
cocos2d::CCPoint v24; // [xsp+88h] [xbp+88h] BYREF
cocos2d::CCPoint v25; // [xsp+90h] [xbp+90h] BYREF
cocos2d::CCPoint GridSnappedPos; // 0:kr10_8.8
cocos2d::CCPoint v27; // 0:s0.4,4:s1.4
cocos2d::CCPoint v28; // 0:s0.4,4:s1.4
if ( GameManager::sharedState()->m_levelEditorLayer )
{
m_editorUI = GameManager::sharedState()->m_levelEditorLayer->m_editorUI;
sub_D153B8((int)&v25, a12895236453195);
v4 = EditorUI::pasteObjects(m_editorUI, (const void **)&v25, 0, 0);
v5 = (void *)(*(_QWORD *)&v25 - 24LL);
if ( (__int64 *)(*(_QWORD *)&v25 - 24LL) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v17 = (unsigned int *)(*(_QWORD *)&v25 - 8LL);
do
v18 = __ldaxr(v17);
while ( __stlxr(v18 - 1, v17) );
}
else
{
v18 = *(_DWORD *)(*(_QWORD *)&v25 - 8LL);
*(_DWORD *)(*(_QWORD *)&v25 - 8LL) = v18 - 1;
}
if ( v18 <= 0 )
operator delete(v5);
}
if ( v4 )
{
if ( (unsigned int)cocos2d::CCArray::count(v4) )
{
v6 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getWinSize(v6);
v7 = GameManager::sharedState();
v8 = v22;
*(float *)&v9 = v21 * 0.5;
m_objectLayer = v7->m_levelEditorLayer->m_objectLayer;
*(_OWORD *)v20 = v9;
v11 = GameManager::sharedState();
cocos2d::CCPoint::CCPoint(
&v25,
*(float *)v20,
(float)(v11->m_levelEditorLayer->m_editorUI->m_toolbarHeight * 0.5) + (float)(v8 * 0.5));
cocos2d::CCNode::convertToNodeSpace(m_objectLayer, &v25);
v12 = GameManager::sharedState()->m_levelEditorLayer->m_editorUI;
cocos2d::CCPoint::CCPoint(&v24, &v23);
GridSnappedPos = EditorUI::getGridSnappedPos(v12, v27);
cocos2d::CCPoint::operator=(&v23, GridSnappedPos.x, GridSnappedPos.y);
v13 = GameManager::sharedState()->m_levelEditorLayer->m_editorUI;
cocos2d::CCPoint::CCPoint(&v25, &v23);
EditorUI::repositionObjectsToCenter(v13, v4, v28, (unsigned __int8)&v19 - 112);
v14 = GameLevelManager::sharedState();
ActiveSmartTemplate = GameLevelManager::getActiveSmartTemplate(v14);
if ( ActiveSmartTemplate )
{
v20[0] = ActiveSmartTemplate;
v16 = GameManager::sharedState();
EditorUI::createSmartObjectsFromTemplate(v16->m_levelEditorLayer->m_editorUI, v20[0], v4, 0, 1, 1, 0);
}
}
}
}
SetupSmartBlockLayer::onClose(a1, nullptr);
}