//
// BrowseSmartTemplateLayer::init from 0x53fdd0 to 0x540066 (662 bytes)
//
// 1 xrefs:
// > BrowseSmartTemplateLayer::create @ 0x540100
//
// 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
//
bool BrowseSmartTemplateLayer::init(BrowseSmartTemplateLayer *a1, GJSmartTemplate *a2, SmartBrowseFilter a3)
{
cocos2d::CCDirector *v5; // r0
CCMenuItemSpriteExtra *v6; // r7
cocos2d::CCMenu *m_buttonMenu; // r10
void (__fastcall *setPosition)(cocos2d::CCNode *__hidden, const cocos2d::CCPoint *); // r8
unsigned int v9; // r8
stl::StringData::Internal *v10; // r6
cocos2d::CCArray *v11; // r11
cocos2d::CCString *v12; // r0
char *CString; // r0
SmartPrefabResult v14; // kr00_28
GJSmartTemplate *m_template; // r0
unsigned int i; // r7
const SmartPrefabResult *v17; // r1
SmartPrefabResult v18; // kr24_28
stl::StringData::Internal *v20; // r3
stl::StringData::Internal *v21; // r3
int v22; // [sp+0h] [bp-74h]
int v23; // [sp+4h] [bp-70h]
cocos2d::CCDictionary *m_prefabArrays; // [sp+8h] [bp-6Ch]
cocos2d::CCArray *v25; // [sp+Ch] [bp-68h]
void *v26; // [sp+10h] [bp-64h]
std::string v27; // [sp+24h] [bp-50h] BYREF
_BYTE v28[4]; // [sp+28h] [bp-4Ch] BYREF
cocos2d::CCSize v29; // [sp+2Ch] [bp-48h] BYREF
SmartPrefabResult v30; // [sp+34h] [bp-40h] BYREF
SmartPrefabResult v31; // [sp+50h] [bp-24h] BYREF
v26 = &_stack_chk_guard;
v23 = FLAlertLayer::init(a1, (cocos2d::_ccColor4B)150);
if ( v23 )
{
BrowseSmartTemplateLayer::baseSetup(a1);
v5 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getWinSize(&v29, v5);
if ( a2 )
{
a1->m_template = a2;
cocos2d::CCObject::retain(a2);
}
sub_776584((int)&v30, "Help");
sub_776584(
(int)&v31,
"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 = InfoAlertButton::create((int)&v30, (int)&v31, 1065353216);
sub_774008(&v31);
sub_774008(&v30);
a1->m_buttonMenu->addChild(a1->m_buttonMenu, v6);
m_buttonMenu = a1->m_buttonMenu;
setPosition = v6->setPosition;
cocos2d::CCPoint::CCPoint(
(cocos2d::CCPoint *)&v30,
(float)((float)(v29.width * 0.5) + 225.0) - 18.0,
(float)((float)(v29.height * 0.5) + 140.0) - 18.0);
cocos2d::CCNode::convertToNodeSpace((cocos2d::CCPoint *)&v31, m_buttonMenu, (const cocos2d::CCPoint *)&v30);
setPosition(v6, (const cocos2d::CCPoint *)&v31);
if ( a1->m_template )
{
v9 = 0;
v10 = nullptr;
m_prefabArrays = a2->m_prefabArrays;
v11 = cocos2d::CCDictionary::allKeys(m_prefabArrays);
while ( v9 < cocos2d::CCArray::count(v11) )
{
v12 = cocos2d::CCArray::stringAtIndex(v11, v9);
CString = (char *)cocos2d::CCString::getCString(v12);
sub_776584((int)&v27, CString);
v25 = (cocos2d::CCArray *)cocos2d::CCDictionary::objectForKey(m_prefabArrays, &v27);
if ( cocos2d::CCArray::count(v25) )
{
v30.m_smartPrefab = nullptr;
sub_776584((int)&v30.m_binaryKey, (char *)&unk_939830);
sub_776584((int)&v30.m_prefabKey, (char *)&unk_939830);
v30.m_prefabCount = 0;
v30.m_unrequired = 0;
v30.m_rotation = 0;
v30.m_flipX = 0;
v30.m_flipY = 0;
v30.m_ignoreCorners = 0;
sub_775D40(&v30.m_binaryKey, &v27);
sub_775D40(&v30.m_prefabKey, &v27);
v30.m_prefabCount = cocos2d::CCArray::count(v25);
sub_775C20(v28);
v30.m_unrequired = GJSmartTemplate::isUnrequired((int)a2, (int)v28);
sub_774008(v28);
SmartPrefabResult::SmartPrefabResult(&v31, &v30);
v14.m_smartPrefab = (GJSmartPrefab *)&v31;
v14.m_binaryKey.m_data.m_data = v10;
v14.m_prefabKey.m_data.m_data = v20;
v14.m_prefabCount = v22;
v14.m_unrequired = v23;
v14.m_rotation = (int)m_prefabArrays;
v14.m_flipX = (char)v25;
v14.m_flipY = BYTE1(v25);
v14.m_ignoreCorners = BYTE2(v25);
BrowseSmartTemplateLayer::addPrefabMenuItem(a1, v14, (int)v26);
v10 = (stl::StringData::Internal *)((char *)v10 + 1);
SmartPrefabResult::~SmartPrefabResult(&v31);
SmartPrefabResult::~SmartPrefabResult(&v30);
}
++v9;
sub_774008(&v27);
}
m_template = a1->m_template;
memset(&v30, 0, 12);
GJSmartTemplate::getTemplateState(m_template, (std::vector *)&v30);
for ( i = 0;
i < -1227133513
* ((v30.m_binaryKey.m_data.m_data - (stl::StringData::Internal *)v30.m_smartPrefab) >> 2);
++i )
{
v17 = (const SmartPrefabResult *)((char *)v30.m_smartPrefab + 28 * i);
if ( !v17->m_prefabCount && !v17->m_unrequired )
{
SmartPrefabResult::SmartPrefabResult(&v31, v17);
v18.m_smartPrefab = (GJSmartPrefab *)&v31;
v18.m_binaryKey.m_data.m_data = v10;
v18.m_prefabKey.m_data.m_data = v21;
v18.m_prefabCount = v22;
v18.m_unrequired = v23;
v18.m_rotation = (int)m_prefabArrays;
v18.m_flipX = (char)v25;
v18.m_flipY = BYTE1(v25);
v18.m_ignoreCorners = BYTE2(v25);
BrowseSmartTemplateLayer::addPrefabMenuItem(a1, v18, (int)v26);
v10 = (stl::StringData::Internal *)((char *)v10 + 1);
SmartPrefabResult::~SmartPrefabResult(&v31);
}
}
BrowseSmartTemplateLayer::goToPage(a1, 0);
std::vector::~vector((SmartPrefabResult **)&v30);
}
}
return v23;
}