//
// GJSmartTemplate::getTemplateState from 0x9daa84 to 0x9db1f4 (1904 bytes)
//
// 2 xrefs:
// > BrowseSmartTemplateLayer::init @ 0x9df9b4
// > ??> @ 0xc1d28
//
// 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 GJSmartTemplate::getTemplateState(GJSmartTemplate *a1, std::vector *a2)
{
cocos2d::CCDictionary *v3; // x20
cocos2d::CCNode *v4; // x0
unsigned int v5; // w22
cocos2d::CCString *v6; // x0
char *CString; // x0
void *v8; // x0
cocos2d::CCArray *v9; // x26
int v10; // w2
bool isUnrequired; // w0
unsigned __int8 *v12; // x2
SmartPrefabResult *m_finish; // x25
bool v14; // w0
bool v15; // w1
bool v16; // w2
int v17; // w3
bool v18; // w4
void *v19; // x0
void *v20; // x0
char *v21; // x0
void *v22; // x0
unsigned int *v23; // x1
int v24; // w2
void *v25; // x0
void *v26; // x0
char *v27; // x0
unsigned int *v28; // x1
int v29; // w2
unsigned int *v30; // x1
int v31; // w0
unsigned int *v32; // x1
int v33; // w2
unsigned int *v34; // x1
int v35; // w2
unsigned int *v36; // x1
int v37; // w2
unsigned int *v38; // x1
int v39; // w2
unsigned int *v40; // x1
int v41; // w2
unsigned int *v42; // x1
int v43; // w2
cocos2d::CCArray *v44; // [xsp+68h] [xbp+68h]
__int64 v46; // [xsp+90h] [xbp+90h] BYREF
std::string v47; // [xsp+98h] [xbp+98h] BYREF
__int64 v48; // [xsp+A0h] [xbp+A0h] BYREF
unsigned __int8 *v49; // [xsp+A8h] [xbp+A8h] BYREF
_DWORD *v50; // [xsp+B0h] [xbp+B0h] BYREF
int v51[8]; // [xsp+B8h] [xbp+B8h] BYREF
GJSmartPrefab *v52; // [xsp+D8h] [xbp+D8h] BYREF
__int64 v53; // [xsp+E0h] [xbp+E0h] BYREF
__int64 v54; // [xsp+E8h] [xbp+E8h] BYREF
int v55; // [xsp+F0h] [xbp+F0h]
bool v56; // [xsp+F4h] [xbp+F4h]
int v57; // [xsp+F8h] [xbp+F8h]
bool v58; // [xsp+FCh] [xbp+FCh]
bool v59; // [xsp+FDh] [xbp+FDh]
bool v60; // [xsp+FEh] [xbp+FEh]
GJSmartPrefab *v61; // [xsp+100h] [xbp+100h] BYREF
__int64 v62; // [xsp+108h] [xbp+108h] BYREF
__int64 v63; // [xsp+110h] [xbp+110h] BYREF
int v64; // [xsp+118h] [xbp+118h]
bool v65; // [xsp+11Ch] [xbp+11Ch]
int v66; // [xsp+120h] [xbp+120h]
bool v67; // [xsp+124h] [xbp+124h]
bool v68; // [xsp+125h] [xbp+125h]
bool v69; // [xsp+126h] [xbp+126h]
v3 = cocos2d::CCDictionary::create();
v4 = cocos2d::CCNode::create();
v5 = 0;
generateAllBinaryStrings(8, v51, 0, v3, v4);
v44 = cocos2d::CCDictionary::allKeys(v3);
if ( (unsigned int)cocos2d::CCArray::count(v44) )
{
do
{
v6 = cocos2d::CCArray::stringAtIndex(v44, v5);
CString = (char *)cocos2d::CCString::getCString(v6);
sub_D153B8((int)&v46, CString);
sub_D18D28(&v48);
prefabKeyFromBinary((__int64)&v48, (__int64)&v47);
v8 = (void *)(v48 - 24);
if ( (__int64 *)(v48 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v32 = (unsigned int *)(v48 - 8);
do
v33 = __ldaxr(v32);
while ( __stlxr(v33 - 1, v32) );
}
else
{
v33 = *(_DWORD *)(v48 - 8);
*(_DWORD *)(v48 - 8) = v33 - 1;
}
if ( v33 <= 0 )
operator delete(v8);
}
v9 = (cocos2d::CCArray *)cocos2d::CCDictionary::objectForKey(a1->m_prefabArrays, &v47);
v52 = nullptr;
sub_D153B8((int)&v53, &byte_F288A0);
sub_D153B8((int)&v54, &byte_F288A0);
v55 = 0;
v56 = 0;
v57 = 0;
v58 = 0;
v59 = 0;
v60 = 0;
sub_D18EA8(&v53, &v47);
sub_D18EA8(&v54, &v47);
if ( v9 )
v10 = cocos2d::CCArray::count(v9);
else
v10 = 0;
v55 = v10;
sub_D18D28(&v49);
isUnrequired = GJSmartTemplate::isUnrequired((__int64)a1, &v49);
v12 = v49 - 24;
v56 = isUnrequired;
if ( v49 - 24 != (unsigned __int8 *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v30 = (unsigned int *)(v49 - 8);
do
v31 = __ldaxr(v30);
while ( __stlxr(v31 - 1, v30) );
}
else
{
v31 = *((_DWORD *)v49 - 2);
*((_DWORD *)v49 - 2) = v31 - 1;
}
if ( v31 <= 0 )
operator delete(v12);
}
if ( v55 <= 0 && !v56 )
{
sub_D18D28(&v50);
GJSmartTemplate::scanForPrefab((__int64)a1, (const void **)&v50, (__int64)&v61);
v52 = v61;
sub_D163D4(&v53, &v62);
sub_D163D4(&v54, &v63);
v25 = (void *)(v63 - 24);
v55 = v64;
v56 = v65;
v57 = v66;
v58 = v67;
v59 = v68;
v60 = v69;
if ( (__int64 *)(v63 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v42 = (unsigned int *)(v63 - 8);
do
v43 = __ldaxr(v42);
while ( __stlxr(v43 - 1, v42) );
}
else
{
v43 = *(_DWORD *)(v63 - 8);
*(_DWORD *)(v63 - 8) = v43 - 1;
}
if ( v43 <= 0 )
operator delete(v25);
}
v26 = (void *)(v62 - 24);
if ( (__int64 *)(v62 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v40 = (unsigned int *)(v62 - 8);
do
v41 = __ldaxr(v40);
while ( __stlxr(v41 - 1, v40) );
}
else
{
v41 = *(_DWORD *)(v62 - 8);
*(_DWORD *)(v62 - 8) = v41 - 1;
}
if ( v41 <= 0 )
operator delete(v26);
}
v27 = (char *)(v50 - 6);
if ( v50 - 6 != (_DWORD *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v28 = v50 - 2;
do
v29 = __ldaxr(v28);
while ( __stlxr(v29 - 1, v28) );
}
else
{
v29 = *(v50 - 2);
*(v50 - 2) = v29 - 1;
}
if ( v29 <= 0 )
operator delete(v27);
}
}
m_finish = a2->m_finish;
if ( m_finish == a2->m_reserveEnd )
{
std::vector::_M_emplace_back_aux((__int64 *)a2, (__int64)&v52);
}
else
{
if ( m_finish )
{
m_finish->m_smartPrefab = v52;
sub_D18D28(&m_finish->m_binaryKey);
sub_D18D28(&m_finish->m_prefabKey);
v14 = v60;
v15 = v59;
v16 = v58;
v17 = v57;
v18 = v56;
m_finish->m_prefabCount = v55;
m_finish->m_unrequired = v18;
m_finish->m_rotation = v17;
m_finish->m_flipX = v16;
m_finish->m_flipY = v15;
m_finish->m_ignoreCorners = v14;
m_finish = a2->m_finish;
}
a2->m_finish = m_finish + 1;
}
v19 = (void *)(v54 - 24);
if ( (__int64 *)(v54 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v38 = (unsigned int *)(v54 - 8);
do
v39 = __ldaxr(v38);
while ( __stlxr(v39 - 1, v38) );
}
else
{
v39 = *(_DWORD *)(v54 - 8);
*(_DWORD *)(v54 - 8) = v39 - 1;
}
if ( v39 <= 0 )
operator delete(v19);
}
v20 = (void *)(v53 - 24);
if ( (__int64 *)(v53 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v36 = (unsigned int *)(v53 - 8);
do
v37 = __ldaxr(v36);
while ( __stlxr(v37 - 1, v36) );
}
else
{
v37 = *(_DWORD *)(v53 - 8);
*(_DWORD *)(v53 - 8) = v37 - 1;
}
if ( v37 <= 0 )
operator delete(v20);
}
v21 = (char *)v47.m_data.m_data - 24;
if ( (__int64 *)v47.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v34 = (unsigned int *)((char *)v47.m_data.m_data - 8);
do
v35 = __ldaxr(v34);
while ( __stlxr(v35 - 1, v34) );
}
else
{
v35 = *((_DWORD *)v47.m_data.m_data - 2);
*((_DWORD *)v47.m_data.m_data - 2) = v35 - 1;
}
if ( v35 <= 0 )
operator delete(v21);
}
v22 = (void *)(v46 - 24);
if ( (__int64 *)(v46 - 24) == &qword_124B6B0 )
goto LABEL_15;
if ( &pthread_create )
{
v23 = (unsigned int *)(v46 - 8);
do
v24 = __ldaxr(v23);
while ( __stlxr(v24 - 1, v23) );
}
else
{
v24 = *(_DWORD *)(v46 - 8);
*(_DWORD *)(v46 - 8) = v24 - 1;
}
if ( v24 > 0 )
{
LABEL_15:
++v5;
}
else
{
++v5;
operator delete(v22);
}
}
while ( v5 < (unsigned int)cocos2d::CCArray::count(v44) );
}
}