//
// SecretRewardsLayer::onSpecialItem from 0xa61708 to 0xa61b9c (1172 bytes)
//
// 2 xrefs:
// > SecretRewardsLayer::onChestType @ 0xa6b09c
// > ??> @ 0x9cbb8
//
// 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
//
void SecretRewardsLayer::onSpecialItem(SecretRewardsLayer *a1, cocos2d::CCObject *a2)
{
int v4; // w0
char *v5; // x1
char *v6; // x0
int v7; // w22
GameStatsManager *v8; // x0
cocos2d::CCArray *v9; // x0
int v10; // w25
cocos2d::CCArray *v11; // x21
unsigned int v12; // w22
char *v13; // x2
cocos2d::CCString *v14; // x0
char *CString; // x0
cocos2d::CCObject *v16; // x0
void *v17; // x0
void *v18; // x0
DialogLayer *v19; // x21
GameStatsManager *v20; // x22
GJRewardItem *v21; // x22
void *v22; // x0
RewardUnlockLayer *v23; // x21
unsigned int *v24; // x1
int v25; // w2
unsigned int *v26; // x1
int v27; // w2
unsigned int *v28; // x1
int v29; // w2
unsigned int *v30; // x1
int v31; // w2
unsigned int *v32; // x1
int v33; // w2
char *v34; // [xsp+68h] [xbp+68h] BYREF
__int64 v35; // [xsp+70h] [xbp+70h] BYREF
__int64 v36; // [xsp+78h] [xbp+78h] BYREF
__int64 v37; // [xsp+80h] [xbp+80h] BYREF
v4 = ((__int64 (__fastcall *)(cocos2d::CCObject *))a2->getTag)(a2) - 5;
v5 = &byte_124B6C8;
v34 = &byte_124B6C8;
switch ( v4 )
{
case 2:
sub_D1798C(&v34, "0005", 4);
v7 = 100;
break;
case 3:
sub_D1798C(&v34, "0006", 4);
v7 = 200;
break;
case 1:
sub_D1798C(&v34, "0004", 4);
v7 = 50;
break;
default:
goto LABEL_4;
}
v8 = GameStatsManager::sharedState();
v9 = (cocos2d::CCArray *)cocos2d::CCDictionary::count(v8->m_treasureRoomChests);
v10 = (int)v9;
if ( v7 <= (int)v9 )
{
v20 = GameStatsManager::sharedState();
sub_D18D28(&v37);
v21 = GameStatsManager::unlockSpecialChest(v20);
v22 = (void *)(v37 - 24);
if ( (__int64 *)(v37 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v28 = (unsigned int *)(v37 - 8);
do
v29 = __ldaxr(v28);
while ( __stlxr(v29 - 1, v28) );
}
else
{
v29 = *(_DWORD *)(v37 - 8);
*(_DWORD *)(v37 - 8) = v29 - 1;
}
if ( v29 <= 0 )
operator delete(v22);
}
if ( v21 )
{
SecretRewardsLayer::switchToOpenedState(a1, (CCMenuItemSpriteExtra *)a2);
v23 = RewardUnlockLayer::create(v21->m_rewardType, nullptr);
a1->addChild_0(a1, v23, 100);
RewardUnlockLayer::showCollectReward(v23, v21);
v6 = v34 - 24;
if ( v34 - 24 != (char *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v24 = (unsigned int *)(v34 - 8);
do
v25 = __ldaxr(v24);
while ( __stlxr(v25 - 1, v24) );
}
else
{
v25 = *((_DWORD *)v34 - 2);
*((_DWORD *)v34 - 2) = v25 - 1;
}
if ( v25 <= 0 )
goto LABEL_21;
}
return;
}
}
else
{
v11 = (cocos2d::CCArray *)cocos2d::CCArray::create(v9);
v12 = v7 - v10;
sub_D153B8((int)&v35, "The Keymaster");
if ( v12 == 1 )
v13 = "Chest";
else
v13 = "Chests";
v14 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"Unlock %i more %s, and you can collect this bonus.",
(const char *)v12,
v13);
CString = (char *)cocos2d::CCString::getCString(v14);
sub_D153B8((int)&v36, CString);
v16 = (cocos2d::CCObject *)DialogObject::create(1.0, (__int64)&v35, (__int64)&v36, 2, 0, (int)&unk_FFFFFF);
cocos2d::CCArray::addObject(v11, v16);
v17 = (void *)(v36 - 24);
if ( (__int64 *)(v36 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v32 = (unsigned int *)(v36 - 8);
do
v33 = __ldaxr(v32);
while ( __stlxr(v33 - 1, v32) );
}
else
{
v33 = *(_DWORD *)(v36 - 8);
*(_DWORD *)(v36 - 8) = v33 - 1;
}
if ( v33 <= 0 )
operator delete(v17);
}
v18 = (void *)(v35 - 24);
if ( (__int64 *)(v35 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v30 = (unsigned int *)(v35 - 8);
do
v31 = __ldaxr(v30);
while ( __stlxr(v31 - 1, v30) );
}
else
{
v31 = *(_DWORD *)(v35 - 8);
*(_DWORD *)(v35 - 8) = v31 - 1;
}
if ( v31 <= 0 )
operator delete(v18);
}
v19 = DialogLayer::createWithObjects(v11, (int)&dword_0 + 2);
a1->addChild_0(a1, v19, 100);
DialogLayer::updateChatPlacement(v19, Center);
DialogLayer::animateInRandomSide(v19);
}
v5 = v34;
LABEL_4:
v6 = v5 - 24;
if ( v5 - 24 != (char *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v26 = (unsigned int *)(v5 - 8);
do
v27 = __ldaxr(v26);
while ( __stlxr(v27 - 1, v26) );
}
else
{
v27 = *((_DWORD *)v5 - 2);
*((_DWORD *)v5 - 2) = v27 - 1;
}
if ( v27 <= 0 )
LABEL_21:
operator delete(v6);
}
}