//
// BrowseSmartKeyLayer::init from 0x14045b470 to 0x14045be42 (2514 bytes)
//
// 2 xrefs:
// > BrowseSmartTemplateLayer::onTemplateObject @ 0x14045b260
// > ??> @ 0x1406dabd4
//
// 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=9
char __fastcall BrowseSmartKeyLayer::init(__int64 a1, cocos2d::CCObject *a2, void **a3)
{
void **v3; // r12
void *v7; // rdx
__int64 v8; // rcx
cocos2d::CCDirector *v9; // rax
char *v10; // rdi
float v11; // xmm0_4
__int64 v12; // rbx
double v13; // xmm0_8
struct cocos2d::CCPoint v14; // rax
__int64 v15; // rbx
cocos2d::CCArray *v16; // rsi
__int64 v17; // rax
unsigned int v18; // eax
signed int v19; // r13d
int v20; // r12d
__int64 v21; // rax
GJSmartBlockPreview *v22; // rbx
int v23; // edi
struct cocos2d::CCObject *v24; // rdi
__int128 *v25; // rax
__int64 v26; // rsi
__int64 v27; // rax
__int64 v28; // r9
unsigned int m_uID; // eax
__int128 *v30; // rax
CCMenuItemSpriteExtra *v31; // rsi
int v32; // edi
int v33; // ebx
float v34; // xmm0_4
ButtonSprite *v35; // rbx
CCMenuItemSpriteExtra *v36; // r15
ButtonSprite *v37; // rbx
CCMenuItemSpriteExtra *v38; // rsi
ButtonSprite *v39; // rbx
CCMenuItemSpriteExtra *v40; // rdi
ButtonSprite *v41; // rbx
CCMenuItemSpriteExtra *v42; // rbx
float v43; // xmm0_4
double v44; // xmm0_8
float v45; // xmm0_4
float v46; // xmm0_4
float v47; // xmm0_4
void **v48; // [rsp+58h] [rbp-B0h] BYREF
ButtonSprite *v49; // [rsp+60h] [rbp-A8h]
__int64 v50; // [rsp+68h] [rbp-A0h]
cocos2d::CCArray *v51; // [rsp+70h] [rbp-98h]
float v52; // [rsp+78h] [rbp-90h]
struct cocos2d::CCPoint v53; // [rsp+80h] [rbp-88h] BYREF
signed int v54; // [rsp+88h] [rbp-80h]
struct cocos2d::CCPoint v55; // [rsp+90h] [rbp-78h] BYREF
__int128 v56; // [rsp+98h] [rbp-70h] BYREF
__int64 v57; // [rsp+A8h] [rbp-60h]
__int64 v58; // [rsp+B0h] [rbp-58h]
__int128 v59; // [rsp+B8h] [rbp-50h] BYREF
__int64 v60; // [rsp+C8h] [rbp-40h]
__int64 v61; // [rsp+D0h] [rbp-38h]
struct cocos2d::CCPoint v62[3]; // [rsp+D8h] [rbp-30h] BYREF
void *v63; // [rsp+F0h] [rbp-18h]
_BYTE v64[32]; // [rsp+F8h] [rbp-10h] BYREF
_BYTE v65[32]; // [rsp+118h] [rbp+10h] BYREF
void **v66; // [rsp+138h] [rbp+30h]
v3 = a3;
v48 = a3;
v66 = a3;
if ( FLAlertLayer::init_1((FLAlertLayer *)a1, 150) )
{
if ( (void **)(a1 + 680) != v3 )
{
v7 = v3;
if ( (unsigned __int64)v3[3] > 0xF )
v7 = *v3;
sub_14003CCE0((void **)(a1 + 680), v7, (size_t)v3[2]);
}
BrowseSmartTemplateLayer::baseSetup((BrowseSmartTemplateLayer *)a1);
v9 = (cocos2d::CCDirector *)cocos2d::CCDirector::sharedDirector(v8);
cocos2d::CCDirector::getWinSize(v9);
if ( a2 )
{
*(_QWORD *)(a1 + 632) = a2;
cocos2d::CCObject::retain(a2);
}
v51 = (cocos2d::CCArray *)&v56;
v56 = 0;
v57 = 0;
v58 = 15;
*(_QWORD *)&v56 = sub_14003AA10(0xA0u);
v57 = 151;
v58 = 159;
strcpy(
(char *)v56,
"Use Add to give chance to the selected variation(s).\n"
"Click Zero to reset the chance.\n"
"Use Create to create a specific variation.");
v59 = 0;
v60 = 4;
v61 = 15;
strcpy((char *)&v59, "Help");
v10 = InfoAlertButton::create((__int64)&v59, (__int64)&v56);
v11 = (*(float (__fastcall **)(_QWORD, char *))(**(_QWORD **)(a1 + 544) + 448LL))(*(_QWORD *)(a1 + 544), v10);
v12 = *(_QWORD *)v10;
v13 = cocos2d::CCPoint::CCPoint(v11, (float)((float)(v52 * 0.5) + 225.0) - 18.0);
v14 = cocos2d::CCNode::convertToNodeSpace(*(cocos2d::CCNode **)(a1 + 544), &v55);
(*(void (__fastcall **)(char *, struct cocos2d::CCPoint))(v12 + 184))(v10, v14);
if ( *(_QWORD *)(a1 + 632) )
{
cocos2d::CCPoint::CCPoint(*(float *)&v13, v52 * 0.5);
cocos2d::CCNode::convertToNodeSpace(*(cocos2d::CCNode **)(a1 + 544), v62);
v15 = sub_14003BDB0((__int64)&v59, a1 + 680);
v51 = (cocos2d::CCArray *)v15;
v16 = (cocos2d::CCArray *)cocos2d::CCDictionary::objectForKey(*(_QWORD *)(*(_QWORD *)(a1 + 632) + 56LL), v15);
v51 = v16;
sub_14003A830(v15);
v17 = sub_14003BDB0((__int64)&v56, a1 + 680);
LODWORD(v50) = GJSmartTemplate::getTotalChanceForPrefab(*(_QWORD *)(a1 + 632), v17);
v18 = 0;
if ( v16 )
v18 = cocos2d::CCArray::count(v16);
v19 = 0;
v54 = v18 + 1;
if ( (int)(v18 + 1) > 0 )
{
v20 = v50;
do
{
v21 = sub_14003BDB0((__int64)&v56, a1 + 680);
v22 = (GJSmartBlockPreview *)GJSmartBlockPreview::create(v21);
v23 = 0;
if ( v19 )
{
v24 = cocos2d::CCArray::objectAtIndex(v16, v19 - 1);
v25 = (__int128 *)sub_14003BDB0((__int64)v64, a1 + 680);
GJSmartBlockPreview::addTemplateGuide(v22, v25, 1);
v62[2] = (struct cocos2d::CCPoint)v64;
v62[1] = (struct cocos2d::CCPoint)v65;
v26 = sub_14003BDB0((__int64)v64, (__int64)&v24[1].m_uIndexInArray);
v27 = sub_14003BDB0((__int64)v65, a1 + 680);
v50 = v27;
v28 = qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v63 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v63);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v28 = qword_1406C2ED8;
v27 = v50;
}
GJSmartBlockPreview::addPreview((__int64)v22, v27, v26, *(_QWORD *)(v28 + 528));
m_uID = v24[2].m_uID;
LODWORD(v50) = m_uID;
if ( v20 <= 0 )
{
v23 = m_uID;
}
else
{
GJSmartBlockPreview::addChance(v22, v24[2].m_nLuaID, v20);
v23 = v50;
}
}
else
{
v30 = (__int128 *)sub_14003BDB0((__int64)v65, a1 + 680);
GJSmartBlockPreview::addTemplateGuide(v22, v30, 2);
}
((void (__fastcall *)(GJSmartBlockPreview *))v22->setScale_0)(v22);
v31 = CCMenuItemSpriteExtra::create(
v22,
nullptr,
(cocos2d::CCObject *)a1,
(cocos2d::SEL_MenuHandler *)BrowseSmartKeyLayer::onPrefabObject);
(*(void (__fastcall **)(_QWORD, CCMenuItemSpriteExtra *))(**(_QWORD **)(a1 + 544) + 448LL))(
*(_QWORD *)(a1 + 544),
v31);
v22->setTag(v22, v23);
v31->setTag(v31, v23);
v32 = (int)floorf((float)(v19 / 0x1Cu));
v33 = v19 - 28 * v32;
v34 = floorf((float)(v33 / 7)) * -60.0;
cocos2d::CCPoint::CCPoint(v34, (float)((float)((float)(v33 % 7) * 60.0) - 210.0) + 30.0);
cocos2d::CCPoint::operator+(v62, &v55);
v31->setPosition_0(v31, &v55);
BrowseSmartTemplateLayer::addObjectToPage((BrowseSmartTemplateLayer *)a1, v31, v32);
++v19;
v16 = v51;
}
while ( v19 < v54 );
v3 = v48;
}
BrowseSmartTemplateLayer::goToPage((BrowseSmartTemplateLayer *)a1, 0);
v49 = (ButtonSprite *)operator new(0x2C0u);
v35 = ButtonSprite::ButtonSprite(v49);
if ( v35 )
{
if ( ButtonSprite::init_1(v35, "Create", 25, 0, 0.5, 1, "goldFont.fnt", "GJ_button_01.png", 30.0) )
{
cocos2d::CCObject::autorelease(v35);
}
else
{
((void (__fastcall *)(ButtonSprite *, __int64))v35->~ButtonSprite)(v35, 1);
v35 = nullptr;
}
}
v36 = CCMenuItemSpriteExtra::create(
v35,
nullptr,
(cocos2d::CCObject *)a1,
(cocos2d::SEL_MenuHandler *)BrowseSmartKeyLayer::onButton);
v36->setTag(v36, 1);
(*(void (__fastcall **)(_QWORD, CCMenuItemSpriteExtra *))(**(_QWORD **)(a1 + 544) + 448LL))(
*(_QWORD *)(a1 + 544),
v36);
v49 = (ButtonSprite *)operator new(0x2C0u);
v37 = ButtonSprite::ButtonSprite(v49);
if ( v37 )
{
if ( ButtonSprite::init_1(v37, "Delete", 25, 0, 0.5, 1, "goldFont.fnt", "GJ_button_05.png", 30.0) )
{
cocos2d::CCObject::autorelease(v37);
}
else
{
((void (__fastcall *)(ButtonSprite *, __int64))v37->~ButtonSprite)(v37, 1);
v37 = nullptr;
}
}
v38 = CCMenuItemSpriteExtra::create(
v37,
nullptr,
(cocos2d::CCObject *)a1,
(cocos2d::SEL_MenuHandler *)BrowseSmartKeyLayer::onButton);
v38->setTag(v38, 2);
(*(void (__fastcall **)(_QWORD, CCMenuItemSpriteExtra *))(**(_QWORD **)(a1 + 544) + 448LL))(
*(_QWORD *)(a1 + 544),
v38);
v49 = (ButtonSprite *)operator new(0x2C0u);
v39 = ButtonSprite::ButtonSprite(v49);
if ( v39 )
{
if ( ButtonSprite::init_1(v39, "Zero", 25, 0, 0.5, 1, "goldFont.fnt", "GJ_button_02.png", 30.0) )
{
cocos2d::CCObject::autorelease(v39);
}
else
{
((void (__fastcall *)(ButtonSprite *, __int64))v39->~ButtonSprite)(v39, 1);
v39 = nullptr;
}
}
v40 = CCMenuItemSpriteExtra::create(
v39,
nullptr,
(cocos2d::CCObject *)a1,
(cocos2d::SEL_MenuHandler *)BrowseSmartKeyLayer::onButton);
v40->setTag(v40, 3);
(*(void (__fastcall **)(_QWORD, CCMenuItemSpriteExtra *))(**(_QWORD **)(a1 + 544) + 448LL))(
*(_QWORD *)(a1 + 544),
v40);
v49 = (ButtonSprite *)operator new(0x2C0u);
v41 = ButtonSprite::ButtonSprite(v49);
if ( v41 )
{
if ( ButtonSprite::init_1(v41, "Add", 25, 0, 0.5, 1, "goldFont.fnt", "GJ_button_02.png", 30.0) )
{
cocos2d::CCObject::autorelease(v41);
}
else
{
((void (__fastcall *)(ButtonSprite *, __int64))v41->~ButtonSprite)(v41, 1);
v41 = nullptr;
}
}
v42 = CCMenuItemSpriteExtra::create(
v41,
nullptr,
(cocos2d::CCObject *)a1,
(cocos2d::SEL_MenuHandler *)BrowseSmartKeyLayer::onButton);
v42->setTag(v42, 4);
v43 = (*(float (__fastcall **)(_QWORD, CCMenuItemSpriteExtra *))(**(_QWORD **)(a1 + 544) + 448LL))(
*(_QWORD *)(a1 + 544),
v42);
v44 = cocos2d::CCPoint::CCPoint(v43, v52 * 0.5);
cocos2d::CCNode::convertToNodeSpace(*(cocos2d::CCNode **)(a1 + 544), &v53);
cocos2d::CCPoint::CCPoint(*(float *)&v44, -100.0);
cocos2d::CCPoint::operator+(&v53, &v48);
v45 = ((float (__fastcall *)(CCMenuItemSpriteExtra *, void ***))v36->setPosition_0)(v36, &v48);
cocos2d::CCPoint::CCPoint(v45, -50.0);
cocos2d::CCPoint::operator+(&v53, &v48);
v46 = ((float (__fastcall *)(CCMenuItemSpriteExtra *, void ***))v38->setPosition_0)(v38, &v48);
cocos2d::CCPoint::CCPoint(v46, 50.0);
cocos2d::CCPoint::operator+(&v53, &v48);
v47 = ((float (__fastcall *)(CCMenuItemSpriteExtra *, void ***))v40->setPosition_0)(v40, &v48);
cocos2d::CCPoint::CCPoint(v47, 100.0);
cocos2d::CCPoint::operator+(&v53, &v48);
v42->setPosition_0(v42, (const cocos2d::CCPoint *)&v48);
}
sub_14003A830((__int64)v3);
return 1;
}
else
{
sub_14003A830((__int64)v3);
return 0;
}
}