//
// GJSmartTemplate::savePrefab from 0x9d5b18 to 0x9d5d10 (504 bytes)
//
// 2 xrefs:
// > EditorUI::addObjectsToSmartTemplate @ 0x6b44ac
// > ??> @ 0x33930
//
// 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
//
__int64 __fastcall GJSmartTemplate::savePrefab(cocos2d::CCDictionary **a1, const std::string *a2, const void **a3)
{
cocos2d::CCArray *v6; // x21
unsigned int v7; // w20
const void *v8; // x2
const void *v9; // x0
unsigned __int64 v10; // x19
unsigned __int64 v11; // x28
size_t v12; // x2
unsigned __int64 v13; // x19
GJSmartPrefab *v14; // x20
void *v15; // x0
unsigned int *v17; // x2
int v18; // w1
__int64 v19; // [xsp+70h] [xbp+70h] BYREF
sub_D1798C(a1 + 22, &byte_F288A0, 0);
v6 = (cocos2d::CCArray *)cocos2d::CCDictionary::objectForKey(a1[7], a2);
if ( !v6 )
{
v6 = (cocos2d::CCArray *)cocos2d::CCArray::create(nullptr);
cocos2d::CCDictionary::setObject((int)a1[7], v6);
}
v7 = 0;
if ( (unsigned int)cocos2d::CCArray::count(v6) )
{
while ( 1 )
{
v8 = *(const void **)(cocos2d::CCArray::objectAtIndex(v6, v7) + 64);
v9 = v8;
v10 = *((_QWORD *)v8 - 3);
v11 = *((_QWORD *)*a3 - 3);
v12 = v11 > v10 ? *((_QWORD *)v8 - 3) : *((_QWORD *)*a3 - 3);
if ( !memcmp(v9, *a3, v12) )
{
v13 = v10 - v11;
if ( v13 + 0x80000000 <= 0xFFFFFFFF && !(_DWORD)v13 )
break;
}
if ( ++v7 >= (unsigned int)cocos2d::CCArray::count(v6) )
goto LABEL_11;
}
}
else
{
LABEL_11:
v14 = GJSmartPrefab::create();
sub_D18EA8(&v14->m_prefabData, a3);
sub_D18EA8(&v14->m_prefabKey, a2);
cocos2d::CCArray::addObject(v6, v14);
sub_D18D28(&v19);
GJSmartTemplate::saveRemap(a1);
v15 = (void *)(v19 - 24);
if ( (__int64 *)(v19 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v17 = (unsigned int *)(v19 - 8);
do
v18 = __ldaxr(v17);
while ( __stlxr(v18 - 1, v17) );
}
else
{
v18 = *(_DWORD *)(v19 - 8);
*(_DWORD *)(v19 - 8) = v18 - 1;
}
if ( v18 <= 0 )
operator delete(v15);
}
}
return _stack_chk_guard;
}