//
// BrowseSmartTemplateLayer::init from 0x9df744 to 0x9e021c (2776 bytes)
//
// 2 xrefs:
// > BrowseSmartTemplateLayer::create @ 0x9e02f4
// > ??> @ 0x35d18
//
// 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
//
// local variable allocation has failed, the output may be wrong!
bool BrowseSmartTemplateLayer::init(BrowseSmartTemplateLayer *a1, GJSmartTemplate *a2, SmartBrowseFilter a3)
{
cocos2d::CCDirector *v4; // x0
cocos2d::CCObject *v5; // x0
cocos2d::CCNode *v6; // x21
std::string *p_m_prefabKey; // x0
std::string *v8; // x0
BrowseSmartTemplateLayer *v9; // x26
cocos2d::CCNode *m_buttonMenu; // x25
void (__fastcall *setPosition)(cocos2d::CCNode *__hidden, const cocos2d::CCPoint *); // x24
unsigned int v12; // w21
cocos2d::CCDictionary *v13; // x28
int v14; // w25
cocos2d::CCArray *v15; // x24
cocos2d::CCString *v16; // x0
char *CString; // x0
cocos2d::CCArray *v18; // x26
char *v19; // x0
SmartPrefabResult *m_start; // x1
SmartPrefabResult *m_finish; // x3
__int64 v22; // x21
unsigned __int64 v23; // x22
SmartPrefabResult *v24; // x20
int m_prefabCount; // w3
int v26; // w3
char *v27; // x0
char *v28; // x0
SmartPrefabResult *v29; // x20
SmartPrefabResult *v30; // x21
stl::StringData::Internal *v31; // x1
char *v32; // x0
stl::StringData::Internal *m_data; // x1
char *v34; // x0
unsigned int *v35; // x1
int v36; // w2
unsigned int *v37; // x1
int v38; // w2
bool isUnrequired; // w0
unsigned __int8 *v40; // x2
char *v41; // x0
char *v42; // x0
std::string *v43; // x0
std::string *v44; // x0
unsigned int *v45; // x1
int v46; // w2
unsigned int *v47; // x1
int v48; // w2
unsigned int *v49; // x1
int v50; // w2
unsigned int *v51; // x1
int v52; // w2
unsigned int *v53; // x1
int v54; // w0
unsigned int *v55; // x1
int v56; // w2
unsigned int *v57; // x1
int v58; // w2
unsigned int *v59; // x1
int v60; // w2
unsigned int *p_m_rotation; // x1
int m_rotation; // w2
unsigned int *p_m_prefabID; // x1
int m_prefabID; // w2
_QWORD v65[2]; // [xsp+0h] [xbp+0h] BYREF
char v66; // [xsp+6Fh] [xbp+6Fh]
std::string *p_m_binaryKey; // [xsp+70h] [xbp+70h]
char *v68; // [xsp+78h] [xbp+78h]
cocos2d::CCObject *v69; // [xsp+80h] [xbp+80h]
char *v70; // [xsp+88h] [xbp+88h]
BrowseSmartTemplateLayer *v71; // [xsp+90h] [xbp+90h]
int v72[2]; // [xsp+98h] [xbp+98h]
int v73[2]; // [xsp+A0h] [xbp+A0h]
__int64 v74; // [xsp+A8h] [xbp+A8h]
char v75; // [xsp+B8h] [xbp+B8h] BYREF
float v76; // [xsp+C0h] [xbp+C0h]
float v77; // [xsp+C4h] [xbp+C4h]
std::string v78; // [xsp+C8h] [xbp+C8h] BYREF
unsigned __int8 *v79; // [xsp+D0h] [xbp+D0h] BYREF
std::vector v80; // [xsp+D8h] [xbp+D8h] BYREF
int v81; // [xsp+F0h] [xbp+F0h]
bool v82; // [xsp+F4h] [xbp+F4h]
int v83; // [xsp+F8h] [xbp+F8h]
bool v84; // [xsp+FCh] [xbp+FCh]
bool v85; // [xsp+FDh] [xbp+FDh]
bool v86; // [xsp+FEh] [xbp+FEh]
SmartPrefabResult v87; // [xsp+100h] [xbp+100h] BYREF
cocos2d::CCPoint v88; // 0:kr08_8.8
v74 = *(_QWORD *)&a3;
v69 = a2;
v71 = a1;
v66 = FLAlertLayer::init(a1, 0x96u);
if ( v66 )
{
BrowseSmartTemplateLayer::baseSetup(v71);
v4 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getWinSize(v4);
v5 = v69;
if ( v69 )
{
v71->m_template = (GJSmartTemplate *)v69;
cocos2d::CCObject::retain(v5);
}
v68 = &v75;
sub_D153B8((int)&v80, "Help");
sub_D153B8(
(unsigned int)v65 + 256,
"Shows the auto-build designs in the current template.\n"
"These will be used when the template is pasted.\n"
"Click on an empty design to paste it into editor.\n"
"Click an added design to change the chance of different variations.");
v6 = (cocos2d::CCNode *)InfoAlertButton::create(1.0);
p_m_prefabKey = &v87.m_smartPrefab[-1].m_prefabKey;
if ( (__int64 *)&v87.m_smartPrefab[-1].m_prefabKey != &qword_124B6B0 )
{
if ( &pthread_create )
{
p_m_prefabID = (unsigned int *)&v87.m_smartPrefab[-1].m_prefabID;
do
m_prefabID = __ldaxr(p_m_prefabID);
while ( __stlxr(m_prefabID - 1, p_m_prefabID) );
}
else
{
m_prefabID = v87.m_smartPrefab[-1].m_prefabID;
v87.m_smartPrefab[-1].m_prefabID = m_prefabID - 1;
}
if ( m_prefabID <= 0 )
operator delete(p_m_prefabKey);
}
v8 = &v80.m_start[-1].m_prefabKey;
if ( (__int64 *)&v80.m_start[-1].m_prefabKey != &qword_124B6B0 )
{
if ( &pthread_create )
{
p_m_rotation = (unsigned int *)&v80.m_start[-1].m_rotation;
do
m_rotation = __ldaxr(p_m_rotation);
while ( __stlxr(m_rotation - 1, p_m_rotation) );
}
else
{
m_rotation = v80.m_start[-1].m_rotation;
v80.m_start[-1].m_rotation = m_rotation - 1;
}
if ( m_rotation <= 0 )
operator delete(v8);
}
v9 = v71;
v71->m_buttonMenu->addChild(v71->m_buttonMenu, v6);
m_buttonMenu = v9->m_buttonMenu;
setPosition = v6->setPosition;
cocos2d::CCPoint::CCPoint(
(cocos2d::CCPoint *)&v80,
(float)((float)(v76 * 0.5) + 225.0) - 18.0,
(float)((float)(v77 * 0.5) + 140.0) - 18.0);
v88 = cocos2d::CCNode::convertToNodeSpace(m_buttonMenu, (const cocos2d::CCPoint *)&v80);
((void (__fastcall *)(cocos2d::CCNode *, SmartPrefabResult *, float, float))setPosition)(v6, &v87, v88.x, v88.y);
if ( v9->m_template )
{
*(_QWORD *)v72 = &v80.m_reserveEnd;
p_m_binaryKey = &v87.m_binaryKey;
v12 = 0;
v13 = (cocos2d::CCDictionary *)v69[1].__vftable;
*(_QWORD *)v73 = &v80.m_finish;
v14 = 0;
v15 = cocos2d::CCDictionary::allKeys(v13);
v70 = &byte_F288A0;
if ( (unsigned int)cocos2d::CCArray::count(v15) )
{
do
{
v16 = cocos2d::CCArray::stringAtIndex(v15, v12);
CString = (char *)cocos2d::CCString::getCString(v16);
sub_D153B8((unsigned int)v65 + 200, CString);
v18 = (cocos2d::CCArray *)cocos2d::CCDictionary::objectForKey(v13, &v78);
if ( (unsigned int)cocos2d::CCArray::count(v18) )
{
v80.m_start = nullptr;
sub_D153B8(v73[0], v70);
sub_D153B8(v72[0], v70);
v81 = 0;
v82 = 0;
v83 = 0;
v84 = 0;
v85 = 0;
v86 = 0;
sub_D18EA8(*(_QWORD *)v73, &v78);
sub_D18EA8(*(_QWORD *)v72, &v78);
v81 = cocos2d::CCArray::count(v18);
sub_D18D28(&v79);
isUnrequired = GJSmartTemplate::isUnrequired((__int64)v69, &v79);
v40 = v79 - 24;
v82 = isUnrequired;
if ( v79 - 24 != (unsigned __int8 *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v53 = (unsigned int *)(v79 - 8);
do
v54 = __ldaxr(v53);
while ( __stlxr(v54 - 1, v53) );
}
else
{
v54 = *((_DWORD *)v79 - 2);
*((_DWORD *)v79 - 2) = v54 - 1;
}
if ( v54 <= 0 )
operator delete(v40);
}
v87.m_smartPrefab = (GJSmartPrefab *)v80.m_start;
sub_D18D28(p_m_binaryKey);
sub_D18D28(&v87.m_prefabKey);
v87.m_prefabCount = v81;
v87.m_unrequired = v82;
v87.m_rotation = v83;
v87.m_flipX = v84;
v87.m_flipY = v85;
v87.m_ignoreCorners = v86;
BrowseSmartTemplateLayer::addPrefabMenuItem(v71, &v87, v14);
v41 = (char *)v87.m_prefabKey.m_data.m_data - 24;
if ( (__int64 *)v87.m_prefabKey.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v49 = (unsigned int *)((char *)v87.m_prefabKey.m_data.m_data - 8);
do
v50 = __ldaxr(v49);
while ( __stlxr(v50 - 1, v49) );
}
else
{
v50 = *((_DWORD *)v87.m_prefabKey.m_data.m_data - 2);
*((_DWORD *)v87.m_prefabKey.m_data.m_data - 2) = v50 - 1;
}
if ( v50 <= 0 )
operator delete(v41);
}
v42 = (char *)v87.m_binaryKey.m_data.m_data - 24;
if ( (__int64 *)v87.m_binaryKey.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v47 = (unsigned int *)((char *)v87.m_binaryKey.m_data.m_data - 8);
do
v48 = __ldaxr(v47);
while ( __stlxr(v48 - 1, v47) );
}
else
{
v48 = *((_DWORD *)v87.m_binaryKey.m_data.m_data - 2);
*((_DWORD *)v87.m_binaryKey.m_data.m_data - 2) = v48 - 1;
}
if ( v48 <= 0 )
operator delete(v42);
}
++v14;
v43 = &v80.m_reserveEnd[-1].m_prefabKey;
if ( (__int64 *)&v80.m_reserveEnd[-1].m_prefabKey != &qword_124B6B0 )
{
if ( &pthread_create )
{
v51 = (unsigned int *)&v80.m_reserveEnd[-1].m_rotation;
do
v52 = __ldaxr(v51);
while ( __stlxr(v52 - 1, v51) );
}
else
{
v52 = v80.m_reserveEnd[-1].m_rotation;
v80.m_reserveEnd[-1].m_rotation = v52 - 1;
}
if ( v52 <= 0 )
operator delete(v43);
}
v44 = &v80.m_finish[-1].m_prefabKey;
if ( (__int64 *)&v80.m_finish[-1].m_prefabKey != &qword_124B6B0 )
{
if ( &pthread_create )
{
v45 = (unsigned int *)&v80.m_finish[-1].m_rotation;
do
v46 = __ldaxr(v45);
while ( __stlxr(v46 - 1, v45) );
}
else
{
v46 = v80.m_finish[-1].m_rotation;
v80.m_finish[-1].m_rotation = v46 - 1;
}
if ( v46 <= 0 )
operator delete(v44);
}
}
v19 = (char *)v78.m_data.m_data - 24;
if ( (__int64 *)v78.m_data.m_data - 3 == &qword_124B6B0 )
goto LABEL_11;
if ( &pthread_create )
{
v37 = (unsigned int *)((char *)v78.m_data.m_data - 8);
do
v38 = __ldaxr(v37);
while ( __stlxr(v38 - 1, v37) );
}
else
{
v38 = *((_DWORD *)v78.m_data.m_data - 2);
*((_DWORD *)v78.m_data.m_data - 2) = v38 - 1;
}
if ( v38 > 0 )
{
LABEL_11:
++v12;
}
else
{
++v12;
operator delete(v19);
}
}
while ( v12 < (unsigned int)cocos2d::CCArray::count(v15) );
}
memset(&v80, 0, sizeof(v80));
GJSmartTemplate::getTemplateState(v71->m_template, &v80);
m_start = v80.m_start;
m_finish = v80.m_finish;
v22 = 0;
v23 = 1;
if ( 0xCCCCCCCCCCCCCCCDLL * (((char *)v80.m_finish - (char *)v80.m_start) >> 3) )
{
while ( 1 )
{
v24 = &m_start[v22];
if ( !m_start[v22].m_prefabCount && !v24->m_unrequired )
{
v87.m_smartPrefab = v24->m_smartPrefab;
sub_D18D28(&v87.m_binaryKey);
sub_D18D28(&v87.m_prefabKey);
m_prefabCount = v24->m_prefabCount;
v87.m_unrequired = v24->m_unrequired;
v87.m_prefabCount = m_prefabCount;
v26 = v24->m_rotation;
v87.m_flipX = v24->m_flipX;
v87.m_rotation = v26;
v87.m_flipY = v24->m_flipY;
v87.m_ignoreCorners = v24->m_ignoreCorners;
BrowseSmartTemplateLayer::addPrefabMenuItem(v71, &v87, v14);
v27 = (char *)v87.m_prefabKey.m_data.m_data - 24;
if ( (__int64 *)v87.m_prefabKey.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v59 = (unsigned int *)((char *)v87.m_prefabKey.m_data.m_data - 8);
do
v60 = __ldaxr(v59);
while ( __stlxr(v60 - 1, v59) );
}
else
{
v60 = *((_DWORD *)v87.m_prefabKey.m_data.m_data - 2);
*((_DWORD *)v87.m_prefabKey.m_data.m_data - 2) = v60 - 1;
}
if ( v60 <= 0 )
operator delete(v27);
}
v28 = (char *)v87.m_binaryKey.m_data.m_data - 24;
if ( (__int64 *)v87.m_binaryKey.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v57 = (unsigned int *)((char *)v87.m_binaryKey.m_data.m_data - 8);
do
v58 = __ldaxr(v57);
while ( __stlxr(v58 - 1, v57) );
}
else
{
v58 = *((_DWORD *)v87.m_binaryKey.m_data.m_data - 2);
*((_DWORD *)v87.m_binaryKey.m_data.m_data - 2) = v58 - 1;
}
if ( v58 <= 0 )
operator delete(v28);
}
m_start = v80.m_start;
++v14;
m_finish = v80.m_finish;
}
++v22;
if ( 0xCCCCCCCCCCCCCCCDLL * (((char *)m_finish - (char *)m_start) >> 3) <= v23 )
break;
++v23;
}
}
BrowseSmartTemplateLayer::goToPage(v71, 0);
v29 = v80.m_start;
v30 = v80.m_finish;
if ( v80.m_start != v80.m_finish )
{
do
{
m_data = v29->m_prefabKey.m_data.m_data;
v34 = (char *)m_data - 24;
if ( (__int64 *)((char *)m_data - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v35 = (unsigned int *)((char *)m_data - 8);
do
v36 = __ldaxr(v35);
while ( __stlxr(v36 - 1, v35) );
}
else
{
v36 = *((_DWORD *)m_data - 2);
*((_DWORD *)m_data - 2) = v36 - 1;
}
if ( v36 <= 0 )
operator delete(v34);
}
v31 = v29->m_binaryKey.m_data.m_data;
v32 = (char *)v31 - 24;
if ( (__int64 *)((char *)v31 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v55 = (unsigned int *)((char *)v31 - 8);
do
v56 = __ldaxr(v55);
while ( __stlxr(v56 - 1, v55) );
}
else
{
v56 = *((_DWORD *)v31 - 2);
*((_DWORD *)v31 - 2) = v56 - 1;
}
if ( v56 <= 0 )
operator delete(v32);
}
++v29;
}
while ( v30 != v29 );
v30 = v80.m_start;
}
if ( v30 )
operator delete(v30);
}
}
return v66;
}