//
// SecretRewardsLayer::generateChestItems from 0x14056b170 to 0x14056bb74 (2564 bytes)
//
// 2 xrefs:
// > SecretRewardsLayer::createSecondaryLayer @ 0x14056b04a
// > ??> @ 0x14092c648
//
// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 11:34:19 +0000
//
// Hidden C++ exception states: #wind=11
cocos2d::CCArray *__fastcall SecretRewardsLayer::generateChestItems(__int64 a1, int a2)
{
__int64 v3; // rax
float v4; // xmm14_4
__int64 v5; // rax
__int64 v6; // r15
_QWORD *v7; // rax
__int64 v8; // rcx
int v9; // esi
int v10; // edx
int v11; // r13d
int v12; // r12d
int i; // 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
_QWORD *v26; // rdx
__int64 *v27; // rax
int v28; // edi
__int64 v29; // rax
__int64 v30; // rcx
_DWORD *v31; // rax
cocos2d::CCArray *v32; // rdi
__int64 v33; // rcx
cocos2d::CCArray *v34; // r14
int v35; // r12d
int v36; // r15d
unsigned int v37; // r13d
__int64 v38; // r8
struct cocos2d::CCObject *v39; // rbx
__int64 v40; // rcx
struct cocos2d::CCObject *v41; // rsi
int v42; // edi
_QWORD *v43; // rbx
__int64 *v44; // rax
_QWORD *v45; // rdx
__int64 *v46; // rcx
_QWORD *v47; // rcx
_DWORD *v48; // rax
unsigned int v49; // r15d
__int64 v50; // rbx
float v51; // xmm1_4
float v52; // xmm0_4
int v53; // r9d
__int64 v54; // rdx
unsigned int *v55; // rcx
__int64 v56; // rcx
cocos2d::CCSprite *v57; // r14
void **v58; // rsi
void (__fastcall **v59)(void **, _QWORD); // rbx
__int64 v60; // rax
__int64 v61; // rbx
float v62; // xmm6_4
float *v63; // rax
__int64 v64; // rax
float v65; // xmm0_4
__int64 v66; // rax
__int64 v67; // rbx
__int64 v68; // rax
__int64 v69; // rcx
bool isSecretChestUnlocked; // [rsp+38h] [rbp-D0h]
int j; // [rsp+3Ch] [rbp-CCh] BYREF
_QWORD *v73; // [rsp+40h] [rbp-C8h] BYREF
__int64 v74; // [rsp+48h] [rbp-C0h]
int v75; // [rsp+50h] [rbp-B8h]
int v76; // [rsp+54h] [rbp-B4h]
__int128 v77; // [rsp+58h] [rbp-B0h] BYREF
__int64 v78; // [rsp+68h] [rbp-A0h]
__int64 v79; // [rsp+70h] [rbp-98h]
struct cocos2d::CCObject *v80; // [rsp+78h] [rbp-90h]
char Src[15]; // [rsp+80h] [rbp-88h] BYREF
char v82; // [rsp+8Fh] [rbp-79h]
__int64 v83; // [rsp+90h] [rbp-78h]
__int64 v84; // [rsp+98h] [rbp-70h]
float v85[2]; // [rsp+A0h] [rbp-68h] BYREF
cocos2d::CCArray *v86; // [rsp+A8h] [rbp-60h]
cocos2d::CCArray *v87; // [rsp+B0h] [rbp-58h]
__int64 v88; // [rsp+C0h] [rbp-48h]
char v89[8]; // [rsp+C8h] [rbp-40h] BYREF
char v90[8]; // [rsp+D0h] [rbp-38h] BYREF
__int128 v91; // [rsp+D8h] [rbp-30h] BYREF
_QWORD **v92; // [rsp+E8h] [rbp-20h] BYREF
__int64 v93; // [rsp+F0h] [rbp-18h]
void *v94; // [rsp+F8h] [rbp-10h]
void *v95; // [rsp+100h] [rbp-8h]
char v96[8]; // [rsp+108h] [rbp+0h] BYREF
char v97[8]; // [rsp+110h] [rbp+8h] BYREF
char v98[16]; // [rsp+118h] [rbp+10h] BYREF
__int128 v99; // [rsp+128h] [rbp+20h] BYREF
__int64 v100; // [rsp+138h] [rbp+30h]
__int64 v101; // [rsp+140h] [rbp+38h]
__int128 v102; // [rsp+148h] [rbp+40h] BYREF
__int64 v103; // [rsp+158h] [rbp+50h]
unsigned __int64 v104; // [rsp+160h] [rbp+58h]
_BYTE v105[528]; // [rsp+168h] [rbp+60h] BYREF
LODWORD(v79) = a2;
v88 = a1;
v3 = cocos2d::CCDirector::sharedDirector(a1);
cocos2d::CCDirector::getWinSize(v3, v85);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)v89, v85[0] * 0.5, (float)(v85[1] * 0.5) + 80.0);
v4 = floorf(2.0) - 0.5;
v5 = qword_14090BFE0;
if ( !qword_14090BFE0 )
{
v87 = (cocos2d::CCArray *)operator new(0x3E8u);
qword_14090BFE0 = sub_1402D6480((__int64)v87);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFE0 + 72LL))(qword_14090BFE0);
v5 = qword_14090BFE0;
}
v6 = *(_QWORD *)(v5 + 864);
v77 = 0;
v78 = 0;
v74 = 0;
v7 = operator new(0x28u);
*v7 = v7;
v7[1] = v7;
v7[2] = v7;
*((_WORD *)v7 + 12) = 257;
v73 = v7;
v9 = 0;
v10 = 0;
switch ( a2 )
{
case 3:
v9 = 400;
v10 = 0;
break;
case 4:
v9 = 100;
v10 = 1000;
break;
case 5:
v9 = 60;
v10 = 2000;
break;
case 6:
v9 = 24;
v10 = 3000;
break;
case 7:
v9 = 12;
v10 = 4000;
break;
case 8:
v9 = 8;
v10 = 5000;
break;
default:
break;
}
v11 = v10 + 1;
v75 = v10 + 1;
v12 = v10 + v9;
v76 = v10 + v9;
for ( i = v10 + 1; i <= v12; ++i )
{
j = i;
fmt::BasicWriter::BasicWriter(v105);
fmt::BasicWriter::operator<<(v105, (unsigned int)i);
v14 = (_BYTE *)fmt::BasicWriter::c_str(v105);
v102 = 0;
v103 = 0;
v104 = 0;
v15 = -1;
do
++v15;
while ( v14[v15] );
sub_14003D230(&v102, v14, v15);
v16 = &v102;
if ( v104 > 0xF )
v16 = (__int128 *)v102;
v99 = 0;
v100 = 0;
v101 = 0;
v17 = -1;
do
++v17;
while ( *((_BYTE *)v16 + v17) );
sub_14003D230(&v99, v16, v17);
v18 = cocos2d::CCDictionary::objectForKey(v6, &v99);
sub_14003D310((__int64)&v99);
if ( v18 )
{
v19 = *(_DWORD *)(v18 + 56);
if ( v19 > v9 || v19 < 0 )
{
*(_DWORD *)(v18 + 56) = 1;
v19 = 1;
}
v20 = v73;
v21 = (__int64 *)v73[1];
v22 = v73;
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 ( v9 )
{
while ( 1 )
{
v26 = v73;
v27 = (__int64 *)v73[1];
if ( !v24 )
{
do
{
if ( *((_DWORD *)v27 + 7) >= v25 )
{
v26 = v27;
v27 = (__int64 *)*v27;
}
else
{
v27 = (__int64 *)v27[2];
}
}
while ( !*((_BYTE *)v27 + 25) );
}
if ( *((_BYTE *)v26 + 25) || v25 < *((_DWORD *)v26 + 7) )
break;
if ( ++v25 > v9 )
goto LABEL_39;
}
*(_DWORD *)(v18 + 56) = v25;
v20 = v73;
}
}
LABEL_39:
v28 = *(_DWORD *)(v18 + 56);
v29 = v20[1];
*(_QWORD *)&v99 = v29;
DWORD2(v99) = 0;
v30 = (__int64)v20;
while ( !*(_BYTE *)(v29 + 25) )
{
*(_QWORD *)&v99 = v29;
if ( *(_DWORD *)(v29 + 28) >= v28 )
{
DWORD2(v99) = 1;
v30 = v29;
v29 = *(_QWORD *)v29;
}
else
{
DWORD2(v99) = 0;
v29 = *(_QWORD *)(v29 + 16);
}
}
if ( *(_BYTE *)(v30 + 25) || v28 < *(_DWORD *)(v30 + 28) )
{
if ( v74 == 0x666666666666666LL )
sub_14005BD90(v30, 0, v21);
v92 = &v73;
v93 = 0;
v31 = operator new(0x28u);
v31[7] = v28;
v31[8] = 0;
*(_QWORD *)v31 = v20;
*((_QWORD *)v31 + 1) = v20;
*((_QWORD *)v31 + 2) = v20;
*((_WORD *)v31 + 12) = 0;
v93 = 0;
v30 = sub_14006A770(&v73, (__int64)&v99, (__int64)v31);
}
*(_DWORD *)(v30 + 32) = i;
}
else if ( *((_QWORD *)&v77 + 1) == v78 )
{
sub_140069B30((const void **)&v77, *((_BYTE **)&v77 + 1), &j);
}
else
{
**((_DWORD **)&v77 + 1) = i;
*((_QWORD *)&v77 + 1) += 4LL;
}
sub_14003D310((__int64)&v102);
fmt::BasicWriter::~BasicWriter(v105);
}
v32 = (cocos2d::CCArray *)cocos2d::CCArray::create(v8);
v86 = v32;
v34 = (cocos2d::CCArray *)cocos2d::CCArray::create(v33);
v87 = v34;
v35 = 0;
if ( v11 <= v76 )
{
v36 = 1 - v11;
for ( j = 1 - v11; ; v36 = j )
{
v37 = (int)floorf((float)v35 / 12.0);
if ( cocos2d::CCArray::count(v32) <= v37 )
{
v39 = (struct cocos2d::CCObject *)cocos2d::CCLayer::create();
v41 = (struct cocos2d::CCObject *)cocos2d::CCMenu::create(v40);
v80 = v41;
(*(void (__fastcall **)(struct cocos2d::CCObject *, struct cocos2d::CCObject *))(*(_QWORD *)v39 + 464LL))(
v39,
v41);
cocos2d::CCArray::addObject(v32, v39);
cocos2d::CCArray::addObject(v34, v41);
}
else
{
cocos2d::CCArray::objectAtIndex(v32, v37);
v80 = cocos2d::CCArray::objectAtIndex(v34, v37);
}
v42 = v75 + v36 + v35;
v43 = v73;
v44 = (__int64 *)v73[1];
v45 = v73;
v46 = v44;
while ( !*((_BYTE *)v46 + 25) )
{
if ( *((_DWORD *)v46 + 7) >= v42 )
{
v45 = v46;
v46 = (__int64 *)*v46;
}
else
{
v46 = (__int64 *)v46[2];
}
}
if ( *((_BYTE *)v45 + 25) || v42 < *((_DWORD *)v45 + 7) )
{
v50 = (__int64)(*((_QWORD *)&v77 + 1) - v77) >> 2;
if ( v50 )
{
v51 = (float)rand() / 32767.0;
if ( v50 < 0 )
v52 = (float)(v50 & 1 | (unsigned int)((unsigned __int64)v50 >> 1))
+ (float)(v50 & 1 | (unsigned int)((unsigned __int64)v50 >> 1));
else
v52 = (float)(int)v50;
v53 = (int)floorf(v51 * v52);
v54 = (__int64)(*((_QWORD *)&v77 + 1) - v77) >> 2;
if ( v54 - 1 < (unsigned __int64)v53 )
v53 = v54 - 1;
v55 = (unsigned int *)(v77 + 4LL * v53);
v49 = *v55;
memmove(v55, v55 + 1, *((_QWORD *)&v77 + 1) - (_QWORD)(v55 + 1));
*((_QWORD *)&v77 + 1) -= 4LL;
}
else
{
v49 = 0;
}
}
else
{
*(_QWORD *)&v102 = v73[1];
DWORD2(v102) = 0;
v47 = v73;
while ( !*((_BYTE *)v44 + 25) )
{
*(_QWORD *)&v102 = v44;
if ( *((_DWORD *)v44 + 7) >= v42 )
{
DWORD2(v102) = 1;
v47 = v44;
v44 = (__int64 *)*v44;
}
else
{
DWORD2(v102) = 0;
v44 = (__int64 *)v44[2];
}
}
if ( *((_BYTE *)v47 + 25) || v42 < *((_DWORD *)v47 + 7) )
{
if ( v74 == 0x666666666666666LL )
sub_14005BD90(v47, v45, v38);
*(_QWORD *)&v99 = &v73;
*((_QWORD *)&v99 + 1) = 0;
v48 = operator new(0x28u);
v48[7] = v42;
v48[8] = 0;
*(_QWORD *)v48 = v43;
*((_QWORD *)v48 + 1) = v43;
*((_QWORD *)v48 + 2) = v43;
*((_WORD *)v48 + 12) = 0;
*((_QWORD *)&v99 + 1) = 0;
v91 = v102;
v47 = (_QWORD *)sub_14006A770(&v73, (__int64)&v91, (__int64)v48);
}
v49 = *((_DWORD *)v47 + 8);
}
v56 = qword_14090BFE0;
if ( !qword_14090BFE0 )
{
v94 = operator new(0x3E8u);
qword_14090BFE0 = sub_1402D6480((__int64)v94);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFE0 + 72LL))(qword_14090BFE0);
v56 = qword_14090BFE0;
}
isSecretChestUnlocked = GameStatsManager::isSecretChestUnlocked(v56);
v57 = GJChestSprite::create(v79);
GJChestSprite::switchToState(v57, 2, 0);
(*(void (__fastcall **)(cocos2d::CCSprite *))(*(_QWORD *)v57 + 160LL))(v57);
v95 = operator new(0x208u);
v58 = (void **)CCMenuItemSpriteExtra::CCMenuItemSpriteExtra((__int64)v95);
if ( v58 )
{
if ( CCMenuItemSpriteExtra::init(
(__int64 *)v58,
(__int64 *)v57,
0,
v88,
(__int64)SecretRewardsLayer::onSelectItem) )
{
cocos2d::CCObject::autorelease((cocos2d::CCObject *)v58);
goto LABEL_90;
}
(*((void (__fastcall **)(void **, __int64))*v58 + 1))(v58, 1);
}
v58 = nullptr;
LABEL_90:
v82 = 0;
v83 = 14;
v84 = 15;
strcpy(Src, "chestClick.ogg");
*(_QWORD *)&v91 = Src;
if ( v58 + 56 != (void **)Src )
sub_1400405A0(v58 + 56, Src, 0xEu);
sub_14003D310((__int64)Src);
v59 = (void (__fastcall **)(void **, _QWORD))*v58;
cocos2d::CCSize::CCSize((cocos2d::CCSize *)v96, 55.0, 44.0);
v59[39](v58, v60);
v61 = *(_QWORD *)v57;
v62 = *(float *)((*((__int64 (__fastcall **)(void **))*v58 + 40))(v58) + 4) * 0.5;
v63 = (float *)(*((__int64 (__fastcall **)(void **))*v58 + 40))(v58);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)v97, *v63 * 0.5, v62);
(*(void (__fastcall **)(cocos2d::CCSprite *, __int64))(v61 + 184))(v57, v64);
(*(void (__fastcall **)(struct cocos2d::CCObject *, void **))(*(_QWORD *)v80 + 464LL))(v80, v58);
(*((void (__fastcall **)(void **, _QWORD))*v58 + 8))(v58, v49);
(*(void (__fastcall **)(cocos2d::CCSprite *, _QWORD))(*(_QWORD *)v57 + 64LL))(v57, (unsigned int)v42);
v65 = floorf((float)((int)(v35 - 12 * v37) / 4));
cocos2d::CCPoint::CCPoint(
(cocos2d::CCPoint *)v98,
(float)((float)((int)(v35 - 12 * v37) % 4) - v4) * 90.0,
(float)-(int)v65 * 80.0);
v67 = v66;
cocos2d::CCNode::convertToNodeSpace(v80, &v92, v89);
cocos2d::CCPoint::operator+(v68, v90, v67);
(*((void (__fastcall **)(void **, char *))*v58 + 23))(v58, v90);
if ( isSecretChestUnlocked )
SecretRewardsLayer::switchToOpenedState(v69, v58);
++v35;
v32 = v86;
if ( v35 + v75 > v76 )
break;
v34 = v87;
}
}
sub_140080450((void **)&v73);
sub_140069730((__int64)&v77);
return v32;
}