//
// SecretRewardsLayer::generateChestItems from 0x1403d5730 to 0x1403d613c (2572 bytes)
//
// 2 xrefs:
// > SecretRewardsLayer::createSecondaryLayer @ 0x1403d560a
// > ??> @ 0x1406d7d30
//
// 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=11
cocos2d::CCArray *SecretRewardsLayer::generateChestItems(SecretRewardsLayer *a1, int a2)
{
float v2; // xmm0_4
cocos2d::CCDirector *v4; // rax
float v5; // xmm14_4
__int64 v6; // rax
__int64 v7; // r13
__int64 v8; // r15
_QWORD *v9; // rax
int v10; // esi
int v11; // edx
__int64 v12; // rcx
unsigned int v13; // r14d
_BYTE *v14; // rax
size_t v15; // r8
__int128 *v16; // rdx
size_t v17; // r8
__int64 v18; // rdi
int v19; // ecx
_QWORD *v20; // rbx
__int64 *v21; // r8
_QWORD *v22; // rdx
__int64 *v23; // rax
char v24; // r9
int v25; // ecx
__int64 *v26; // rax
int v27; // edi
__int64 v28; // rax
__int64 v29; // rcx
_DWORD *v30; // rax
__int64 v31; // r12
__int64 v32; // r12
__int64 v33; // rcx
cocos2d::CCArray *v34; // rdi
__int64 v35; // rcx
cocos2d::CCArray *v36; // rsi
int v37; // r15d
int v38; // r13d
unsigned int v39; // ebx
__int64 v40; // r8
struct cocos2d::CCObject *v41; // rbx
__int64 v42; // rcx
cocos2d::CCNode *v43; // r14
int v44; // r15d
_QWORD *v45; // rbx
__int64 *v46; // rax
_QWORD *v47; // rdx
__int64 *v48; // rcx
_QWORD *v50; // rcx
_DWORD *v51; // rax
unsigned int v52; // r13d
__int64 v53; // r14
__int64 v54; // rbx
float v55; // xmm1_4
float v56; // xmm0_4
int v57; // edx
unsigned int *v58; // rcx
GameStatsManager *v59; // rcx
GJChestSprite *v60; // r12
CCMenuItemSpriteExtra *v61; // r14
CCMenuItemSpriteExtra_vtbl *v62; // rbx
double v63; // xmm0_8
const cocos2d::CCSize *v64; // rax
GJChestSprite_vtbl *v65; // rbx
float *v66; // rax
const cocos2d::CCPoint *v67; // rax
int v68; // r15d
float v69; // xmm0_4
struct cocos2d::CCPoint v70; // rax
SecretRewardsLayer *v71; // rcx
__int64 v72; // rcx
bool isSecretChestUnlocked; // [rsp+38h] [rbp-D0h]
int v75; // [rsp+3Ch] [rbp-CCh] BYREF
__int64 v76; // [rsp+40h] [rbp-C8h]
_QWORD *v77; // [rsp+48h] [rbp-C0h] BYREF
__int64 v78; // [rsp+50h] [rbp-B8h]
int v79; // [rsp+58h] [rbp-B0h]
int i; // [rsp+5Ch] [rbp-ACh]
int v81; // [rsp+60h] [rbp-A8h]
unsigned int v82; // [rsp+64h] [rbp-A4h]
cocos2d::CCNode *v83; // [rsp+68h] [rbp-A0h]
__int128 v84; // [rsp+70h] [rbp-98h] BYREF
__int64 v85; // [rsp+80h] [rbp-88h]
char Src[15]; // [rsp+88h] [rbp-80h] BYREF
char v87; // [rsp+97h] [rbp-71h]
__int64 v88; // [rsp+98h] [rbp-70h]
__int64 v89; // [rsp+A0h] [rbp-68h]
float v90; // [rsp+A8h] [rbp-60h]
void *v91; // [rsp+B0h] [rbp-58h] BYREF
_QWORD **v92; // [rsp+B8h] [rbp-50h] BYREF
__int64 v93; // [rsp+C0h] [rbp-48h]
SecretRewardsLayer *v94; // [rsp+D0h] [rbp-38h]
void *v95; // [rsp+E0h] [rbp-28h]
CCMenuItemSpriteExtra *v96; // [rsp+E8h] [rbp-20h]
cocos2d::CCSize v97; // [rsp+F0h] [rbp-18h] BYREF
__int128 v98; // [rsp+108h] [rbp+0h] BYREF
__int64 v99; // [rsp+118h] [rbp+10h]
unsigned __int64 v100; // [rsp+120h] [rbp+18h]
__int128 v101; // [rsp+128h] [rbp+20h] BYREF
__int64 v102; // [rsp+138h] [rbp+30h]
__int64 v103; // [rsp+140h] [rbp+38h]
_BYTE v104[528]; // [rsp+148h] [rbp+40h] BYREF
v81 = a2;
v94 = a1;
v4 = (cocos2d::CCDirector *)cocos2d::CCDirector::sharedDirector(a1);
cocos2d::CCDirector::getWinSize(v4);
cocos2d::CCPoint::CCPoint(v2, v90 * 0.5);
v5 = floorf(2.0) + -0.5;
v6 = qword_1406C2EE8;
if ( !qword_1406C2EE8 )
{
v91 = operator new(0x3E0u);
qword_1406C2EE8 = sub_1401D0AE0((__int64)v91);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EE8 + 72LL))(qword_1406C2EE8);
v6 = qword_1406C2EE8;
}
v7 = *(_QWORD *)(v6 + 856);
v84 = 0;
v8 = 0;
v85 = 0;
v78 = 0;
v9 = operator new(0x28u);
*v9 = v9;
v9[1] = v9;
v9[2] = v9;
*((_WORD *)v9 + 12) = 257;
v77 = v9;
v10 = 0;
v11 = 0;
switch ( a2 )
{
case 3:
v10 = 400;
v11 = 0;
break;
case 4:
v10 = 100;
v11 = 1000;
break;
case 5:
v10 = 60;
v11 = 2000;
break;
case 6:
v10 = 24;
v11 = 3000;
break;
case 7:
v10 = 12;
v11 = 4000;
break;
case 8:
v10 = 8;
v11 = 5000;
break;
default:
break;
}
LODWORD(v76) = v11 + 1;
v12 = (unsigned int)(v11 + v10);
v79 = v12;
v13 = v11 + 1;
if ( v11 + 1 <= (int)v12 )
{
while ( 1 )
{
v75 = v13;
fmt::BasicWriter::BasicWriter(v104);
fmt::BasicWriter::operator<<(v104, v13);
v14 = (_BYTE *)fmt::BasicWriter::c_str(v104);
v98 = 0;
v99 = 0;
v100 = 0;
v15 = -1;
do
++v15;
while ( v14[v15] );
sub_14003A930(&v98, v14, v15);
v16 = &v98;
if ( v100 > 0xF )
v16 = (__int128 *)v98;
v101 = 0;
v102 = 0;
v103 = 0;
v17 = -1;
do
++v17;
while ( *((_BYTE *)v16 + v17) );
sub_14003A930(&v101, v16, v17);
v18 = cocos2d::CCDictionary::objectForKey(v7, &v101);
sub_14003A830((__int64)&v101);
if ( v18 )
break;
v31 = *((_QWORD *)&v84 + 1);
if ( *((_QWORD *)&v84 + 1) == v8 )
{
sub_140063270((const void **)&v84, *((_BYTE **)&v84 + 1), &v75);
v8 = v85;
LABEL_52:
v32 = *((_QWORD *)&v84 + 1);
goto LABEL_53;
}
**((_DWORD **)&v84 + 1) = v13;
v32 = v31 + 4;
*((_QWORD *)&v84 + 1) = v32;
LABEL_53:
sub_14003A830((__int64)&v98);
fmt::BasicWriter::~BasicWriter(v104);
if ( (int)++v13 > v79 )
{
v34 = (cocos2d::CCArray *)cocos2d::CCArray::create(v33);
v36 = (cocos2d::CCArray *)cocos2d::CCArray::create(v35);
v37 = 0;
v75 = 0;
v38 = 1 - v76;
for ( i = 1 - v76; ; v38 = i )
{
v39 = (int)floorf((float)v37 / 12.0);
v82 = v39;
if ( cocos2d::CCArray::count(v34) <= v39 )
{
v41 = (struct cocos2d::CCObject *)cocos2d::CCLayer::create();
v43 = (cocos2d::CCNode *)cocos2d::CCMenu::create(v42);
v83 = v43;
v41->__vftable[6].isEqual(v41, v43);
cocos2d::CCArray::addObject(v34, v41);
cocos2d::CCArray::addObject(v36, v43);
}
else
{
cocos2d::CCArray::objectAtIndex(v34, v39);
v83 = (cocos2d::CCNode *)cocos2d::CCArray::objectAtIndex(v36, v39);
}
v44 = v76 + v38 + v37;
v45 = v77;
v46 = (__int64 *)v77[1];
v47 = v77;
v48 = v46;
while ( !*((_BYTE *)v48 + 25) )
{
if ( *((_DWORD *)v48 + 7) >= v44 )
{
v47 = v48;
v48 = (__int64 *)*v48;
}
else
{
v48 = (__int64 *)v48[2];
}
}
if ( !*((_BYTE *)v47 + 25) && v44 >= *((_DWORD *)v47 + 7) )
{
*(_QWORD *)&v98 = v77[1];
DWORD2(v98) = 0;
v50 = v77;
while ( !*((_BYTE *)v46 + 25) )
{
*(_QWORD *)&v98 = v46;
if ( *((_DWORD *)v46 + 7) >= v44 )
{
DWORD2(v98) = 1;
v50 = v46;
v46 = (__int64 *)*v46;
}
else
{
DWORD2(v98) = 0;
v46 = (__int64 *)v46[2];
}
}
if ( *((_BYTE *)v50 + 25) || v44 < *((_DWORD *)v50 + 7) )
{
if ( v78 == 0x666666666666666LL )
sub_140052E40(v50, v47, v40);
*(_QWORD *)&v101 = &v77;
*((_QWORD *)&v101 + 1) = 0;
v51 = operator new(0x28u);
v51[7] = v44;
v51[8] = 0;
*(_QWORD *)v51 = v45;
*((_QWORD *)v51 + 1) = v45;
*((_QWORD *)v51 + 2) = v45;
*((_WORD *)v51 + 12) = 0;
*((_QWORD *)&v101 + 1) = 0;
v50 = (_QWORD *)sub_1400636D0(&v77, (__int64)&v98, (__int64)v51);
}
v52 = *((_DWORD *)v50 + 8);
}
else
{
v53 = v84;
v54 = (v32 - (__int64)v84) >> 2;
if ( v54 )
{
v55 = (float)rand() / 32767.0;
if ( v54 < 0 )
v56 = (float)(v54 & 1 | (unsigned int)((unsigned __int64)v54 >> 1))
+ (float)(v54 & 1 | (unsigned int)((unsigned __int64)v54 >> 1));
else
v56 = (float)(int)v54;
v57 = (int)floorf(v55 * v56);
if ( v54 - 1 < (unsigned __int64)v57 )
v57 = v54 - 1;
v58 = (unsigned int *)(v53 + 4LL * v57);
v52 = *v58;
memmove(v58, v58 + 1, v32 - (_QWORD)(v58 + 1));
*((_QWORD *)&v84 + 1) = v32 - 4;
}
else
{
v52 = 0;
}
}
v59 = (GameStatsManager *)qword_1406C2EE8;
if ( !qword_1406C2EE8 )
{
v95 = operator new(0x3E0u);
qword_1406C2EE8 = sub_1401D0AE0((__int64)v95);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EE8 + 72LL))(qword_1406C2EE8);
v59 = (GameStatsManager *)qword_1406C2EE8;
}
isSecretChestUnlocked = GameStatsManager::isSecretChestUnlocked(v59, v52);
v60 = GJChestSprite::create(v81);
GJChestSprite::switchToState(v60, Closed, 0);
((void (__fastcall *)(GJChestSprite *))v60->setScale_0)(v60);
v96 = (CCMenuItemSpriteExtra *)operator new(0x208u);
v61 = CCMenuItemSpriteExtra::CCMenuItemSpriteExtra(v96);
if ( v61 )
{
if ( CCMenuItemSpriteExtra::init(
v61,
v60,
nullptr,
v94,
(cocos2d::SEL_MenuHandler *)SecretRewardsLayer::onSelectItem) )
{
cocos2d::CCObject::autorelease(v61);
goto LABEL_93;
}
((void (__fastcall *)(CCMenuItemSpriteExtra *, __int64))v61->~CCMenuItemSpriteExtra)(v61, 1);
}
v61 = nullptr;
LABEL_93:
v87 = 0;
v88 = 14;
v89 = 15;
strcpy(Src, "chestClick.ogg");
*(_QWORD *)&v98 = Src;
if ( &v61->m_activateSound.m_data.m_capacity != (std::size_t *)Src )
sub_14003CCE0((void **)&v61->m_activateSound.m_data.m_capacity, Src, 0xEu);
sub_14003A830((__int64)Src);
v62 = v61->cocos2d::CCMenuItemSprite::cocos2d::CCMenuItem::cocos2d::CCNodeRGBA::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
v63 = cocos2d::CCSize::CCSize(&v97, 55.0, 44.0);
v62->setContentSize(v61, v64);
v65 = v60->cocos2d::CCSprite::cocos2d::CCNodeRGBA::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
v61->getContentSize(v61);
v66 = (float *)v61->getContentSize(v61);
cocos2d::CCPoint::CCPoint(*(float *)&v63, *v66 * 0.5);
v65->setPosition_0(v60, v67);
v83->addChild_1(v83, v61);
v61->setTag(v61, v52);
v60->setTag(v60, v44);
v68 = v75;
LODWORD(v65) = (int)(v75 - 12 * v82) % 4;
v69 = floorf((float)((int)(v75 - 12 * v82) / 4));
cocos2d::CCPoint::CCPoint(v69, (float)((float)(int)v65 - v5) * 90.0);
v70 = cocos2d::CCNode::convertToNodeSpace(v83, (const struct cocos2d::CCPoint *)&v92);
((void (__fastcall *)(_QWORD, _QWORD))cocos2d::CCPoint::operator+)(v70, &v91);
v61->setPosition_0(v61, (const cocos2d::CCPoint *)&v91);
if ( isSecretChestUnlocked )
SecretRewardsLayer::switchToOpenedState(v71, v61);
v37 = v68 + 1;
v75 = v37;
if ( v37 + (int)v76 > v79 )
goto LABEL_100;
v32 = *((_QWORD *)&v84 + 1);
}
}
}
v19 = *(_DWORD *)(v18 + 56);
if ( v19 > v10 || v19 < 0 )
{
*(_DWORD *)(v18 + 56) = 1;
v19 = 1;
}
v20 = v77;
v21 = (__int64 *)v77[1];
v22 = v77;
v23 = v21;
v24 = *((_BYTE *)v21 + 25);
if ( !v24 )
{
do
{
if ( *((_DWORD *)v23 + 7) >= v19 )
{
v22 = v23;
v23 = (__int64 *)*v23;
}
else
{
v23 = (__int64 *)v23[2];
}
}
while ( !*((_BYTE *)v23 + 25) );
}
if ( !*((_BYTE *)v22 + 25) && v19 >= *((_DWORD *)v22 + 7) )
{
v25 = 1;
if ( v10 )
{
while ( 1 )
{
v22 = v77;
v26 = (__int64 *)v77[1];
if ( !v24 )
{
do
{
if ( *((_DWORD *)v26 + 7) >= v25 )
{
v22 = v26;
v26 = (__int64 *)*v26;
}
else
{
v26 = (__int64 *)v26[2];
}
}
while ( !*((_BYTE *)v26 + 25) );
}
if ( *((_BYTE *)v22 + 25) || v25 < *((_DWORD *)v22 + 7) )
break;
if ( ++v25 > v10 )
goto LABEL_39;
}
*(_DWORD *)(v18 + 56) = v25;
v20 = v77;
}
}
LABEL_39:
v27 = *(_DWORD *)(v18 + 56);
v28 = v20[1];
*(_QWORD *)&v101 = v28;
DWORD2(v101) = 0;
v29 = (__int64)v20;
while ( !*(_BYTE *)(v28 + 25) )
{
*(_QWORD *)&v101 = v28;
if ( *(_DWORD *)(v28 + 28) >= v27 )
{
DWORD2(v101) = 1;
v29 = v28;
v28 = *(_QWORD *)v28;
}
else
{
DWORD2(v101) = 0;
v28 = *(_QWORD *)(v28 + 16);
}
}
if ( *(_BYTE *)(v29 + 25) || v27 < *(_DWORD *)(v29 + 28) )
{
if ( v78 == 0x666666666666666LL )
sub_140052E40(v29, v22, v21);
v92 = &v77;
v93 = 0;
v30 = operator new(0x28u);
v30[7] = v27;
v30[8] = 0;
*(_QWORD *)v30 = v20;
*((_QWORD *)v30 + 1) = v20;
*((_QWORD *)v30 + 2) = v20;
*((_WORD *)v30 + 12) = 0;
v93 = 0;
v29 = sub_1400636D0(&v77, (__int64)&v101, (__int64)v30);
}
*(_DWORD *)(v29 + 32) = v13;
goto LABEL_52;
}
v34 = (cocos2d::CCArray *)cocos2d::CCArray::create(v12);
cocos2d::CCArray::create(v72);
LABEL_100:
sub_140093D70((void **)&v77);
sub_14005E430((__int64)&v84);
return v34;
}