//
// BrowseSmartTemplateLayer::init from 0x140459de0 to 0x14045a444 (1636 bytes)
//
// 3 xrefs:
// > SetupSmartTemplateLayer::onClick @ 0x1404596f1
// > BrowseSmartKeyLayer::onBack @ 0x14045c5c3
// > ??> @ 0x1406daafc
//
// 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
//
// Hidden C++ exception states: #wind=7
bool BrowseSmartTemplateLayer::init(BrowseSmartTemplateLayer *a1, GJSmartTemplate *a2, SmartBrowseFilter a3)
{
bool result; // al
__int64 v6; // rcx
cocos2d::CCDirector *v7; // rax
int v8; // esi
char *v9; // rdi
float v10; // xmm0_4
__int64 v11; // rbx
struct cocos2d::CCPoint v12; // rax
int v13; // r14d
cocos2d::CCDictionary *m_prefabArrays; // rbx
cocos2d::CCArray *v15; // rdi
unsigned int v16; // r12d
cocos2d::CCString *v17; // rax
const char *CString; // rax
size_t v19; // r8
cocos2d::CCArray *v20; // rbx
void **v21; // rdx
void **v22; // rdx
__int64 v23; // rdx
__int64 v24; // rcx
__int64 v25; // r8
__int64 v26; // r9
void **v27; // r15
size_t v28; // rdi
size_t v29; // rbx
void *v30; // rcx
std::_Vector_val>::pointer Mylast; // rdi
std::_Vector_val>::pointer Myfirst; // r15
unsigned __int64 v33; // r12
int *p_m_prefabCount; // rdi
__int64 p_m_binaryKey; // rbx
std::_Vector_val>::pointer v36; // rax
cocos2d::CCDictionary *v37; // [rsp+20h] [rbp-E0h]
__int128 v38; // [rsp+28h] [rbp-D8h] BYREF
size_t v39; // [rsp+38h] [rbp-C8h]
__int64 v40; // [rsp+40h] [rbp-C0h]
float v41; // [rsp+48h] [rbp-B8h]
cocos2d::CCArray *v42; // [rsp+50h] [rbp-B0h] BYREF
SmartPrefabResult *v43; // [rsp+58h] [rbp-A8h]
std::vector Block; // [rsp+60h] [rbp-A0h] BYREF
SmartPrefabResult v45; // [rsp+78h] [rbp-88h] BYREF
void *Src[2]; // [rsp+D0h] [rbp-30h] BYREF
size_t Size; // [rsp+E0h] [rbp-20h]
unsigned __int64 v48; // [rsp+E8h] [rbp-18h]
GJSmartPrefab *v49; // [rsp+F0h] [rbp-10h]
__int128 v50; // [rsp+F8h] [rbp-8h] BYREF
__int64 v51; // [rsp+108h] [rbp+8h]
__int64 v52; // [rsp+110h] [rbp+10h]
__int128 v53; // [rsp+118h] [rbp+18h] BYREF
__int64 v54; // [rsp+128h] [rbp+28h]
__int64 v55; // [rsp+130h] [rbp+30h]
int v56; // [rsp+138h] [rbp+38h]
bool isUnrequired; // [rsp+13Ch] [rbp+3Ch]
int v58; // [rsp+140h] [rbp+40h]
__int16 v59; // [rsp+144h] [rbp+44h]
bool v60; // [rsp+146h] [rbp+46h]
result = FLAlertLayer::init_1(a1, 150);
if ( result )
{
BrowseSmartTemplateLayer::baseSetup(a1);
v7 = (cocos2d::CCDirector *)cocos2d::CCDirector::sharedDirector(v6);
cocos2d::CCDirector::getWinSize(v7);
if ( a2 )
{
a1->m_template = a2;
cocos2d::CCObject::retain(a2);
}
v38 = 0;
v8 = 0;
v39 = 0;
v40 = 15;
*(_QWORD *)&v38 = sub_14003AA10(0x100u);
v39 = 243;
v40 = 255;
strcpy(
(char *)v38,
"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.");
*(_OWORD *)Src = 0;
Size = 4;
v48 = 15;
strcpy((char *)Src, "Help");
v9 = InfoAlertButton::create((__int64)Src, (__int64)&v38);
v10 = ((float (__fastcall *)(cocos2d::CCMenu *, char *))a1->m_buttonMenu->addChild_1)(a1->m_buttonMenu, v9);
v11 = *(_QWORD *)v9;
cocos2d::CCPoint::CCPoint(v10, (float)((float)(v41 * 0.5) + 225.0) - 18.0);
v12 = cocos2d::CCNode::convertToNodeSpace(a1->m_buttonMenu, (const struct cocos2d::CCPoint *)&v42);
(*(void (__fastcall **)(char *, struct cocos2d::CCPoint))(v11 + 184))(v9, v12);
if ( a1->m_template )
{
v13 = 0;
m_prefabArrays = a2->m_prefabArrays;
v37 = m_prefabArrays;
v15 = cocos2d::CCDictionary::allKeys(m_prefabArrays);
v42 = v15;
v16 = 0;
if ( cocos2d::CCArray::count(v15) )
{
while ( 1 )
{
v17 = cocos2d::CCArray::stringAtIndex(v15, v16);
CString = cocos2d::CCString::getCString(v17);
*(_OWORD *)Src = 0;
Size = 0;
v48 = 0;
v19 = -1;
do
++v19;
while ( CString[v19] );
sub_14003A930(Src, CString, v19);
v20 = (cocos2d::CCArray *)cocos2d::CCDictionary::objectForKey(m_prefabArrays, Src);
if ( cocos2d::CCArray::count(v20) )
{
v49 = nullptr;
v50 = 0;
v51 = 0;
v52 = 15;
LOBYTE(v50) = 0;
v53 = 0;
v54 = 0;
v55 = 15;
LOBYTE(v53) = 0;
v56 = 0;
isUnrequired = 0;
v58 = 0;
v59 = 0;
v60 = 0;
v21 = Src;
if ( v48 > 0xF )
v21 = (void **)Src[0];
sub_14003CCE0((void **)&v50, v21, Size);
v22 = Src;
if ( v48 > 0xF )
v22 = (void **)Src[0];
sub_14003CCE0((void **)&v53, v22, Size);
v56 = cocos2d::CCArray::count(v20);
v38 = 0;
v39 = 0;
v40 = 0;
v27 = Src;
if ( v48 > 0xF )
v27 = (void **)Src[0];
v28 = Size;
if ( Size > 0x7FFFFFFFFFFFFFFFLL )
sub_140007B50(v24, v23, v25, v26);
v40 = 15;
if ( Size > 0xF )
{
v29 = Size | 0xF;
if ( (Size | 0xF) <= 0x7FFFFFFFFFFFFFFFLL )
{
if ( v29 < 0x16 )
v29 = 22;
}
else
{
v29 = 0x7FFFFFFFFFFFFFFFLL;
}
*(_QWORD *)&v38 = sub_14003AA10(v29 + 1);
v39 = v28;
v40 = v29;
memcpy((void *)v38, v27, v28 + 1);
}
else
{
v39 = Size;
v38 = *(_OWORD *)v27;
}
isUnrequired = GJSmartTemplate::isUnrequired(v24, &v38);
v43 = &v45;
v45.m_smartPrefab = v49;
sub_14003BDB0((__int64)&v45.m_binaryKey, (__int64)&v50);
sub_14003BDB0((__int64)&v45.m_prefabKey, (__int64)&v53);
v45.m_prefabCount = v56;
v45.m_unrequired = isUnrequired;
v45.m_rotation = v58;
*(_WORD *)&v45.m_flipX = v59;
v45.m_ignoreCorners = v60;
BrowseSmartTemplateLayer::addPrefabMenuItem(a1, &v45, v13++);
sub_14003A830((__int64)&v53);
sub_14003A830((__int64)&v50);
v15 = v42;
}
if ( v48 > 0xF )
{
v30 = Src[0];
if ( v48 + 1 >= 0x1000 )
{
v30 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v30 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v30);
}
if ( ++v16 >= cocos2d::CCArray::count(v15) )
break;
m_prefabArrays = v37;
}
}
memset(&Block, 0, sizeof(Block));
GJSmartTemplate::getTemplateState(a1->m_template, &Block);
Mylast = Block._Mypair._Myval2._Mylast;
Myfirst = Block._Mypair._Myval2._Myfirst;
v33 = Block._Mypair._Myval2._Mylast - Block._Mypair._Myval2._Myfirst;
if ( v33 )
{
p_m_prefabCount = &Block._Mypair._Myval2._Myfirst->m_prefabCount;
do
{
if ( !*p_m_prefabCount && !*((_BYTE *)p_m_prefabCount + 4) )
{
v43 = &v45;
v45.m_smartPrefab = *((GJSmartPrefab **)p_m_prefabCount - 9);
sub_14003BDB0((__int64)&v45.m_binaryKey, (__int64)(p_m_prefabCount - 16));
sub_14003BDB0((__int64)&v45.m_prefabKey, (__int64)(p_m_prefabCount - 8));
v45.m_prefabCount = *p_m_prefabCount;
v45.m_unrequired = *((_BYTE *)p_m_prefabCount + 4);
v45.m_rotation = p_m_prefabCount[2];
*(_WORD *)&v45.m_flipX = *((_WORD *)p_m_prefabCount + 6);
v45.m_ignoreCorners = *((_BYTE *)p_m_prefabCount + 14);
BrowseSmartTemplateLayer::addPrefabMenuItem(a1, &v45, v13++);
}
++v8;
p_m_prefabCount += 22;
}
while ( v8 < v33 );
Mylast = Block._Mypair._Myval2._Mylast;
}
BrowseSmartTemplateLayer::goToPage(a1, 0);
if ( Myfirst )
{
if ( Myfirst != Mylast )
{
p_m_binaryKey = (__int64)&Myfirst->m_binaryKey;
do
{
sub_14003A830(p_m_binaryKey + 32);
sub_14003A830(p_m_binaryKey);
p_m_binaryKey += 88;
}
while ( (std::_Vector_val>::pointer)(p_m_binaryKey - 8) != Mylast );
}
v36 = Myfirst;
if ( (unsigned __int64)(88 * (Block._Mypair._Myval2._Myend - Myfirst)) >= 0x1000 )
{
Myfirst = *(std::_Vector_val>::pointer *)&Myfirst[-1].m_rotation;
if ( (unsigned __int64)((char *)v36 - (char *)Myfirst - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(Myfirst);
}
}
return 1;
}
return result;
}