//
// SecretRewardsLayer::onSpecialItem from 0x1002ea378 to 0x1002ea5b0 (568 bytes)
//
// 1 xrefs:
// > SecretRewardsLayer::onChestType @ 0x1002e9a54
//
// 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 __fastcall SecretRewardsLayer::onSpecialItem(SecretRewardsLayer *a1, cocos2d::CCObject *a2)
{
int v4; // w0
int v5; // w21
GameStatsManager *v6; // x0
unsigned int v7; // w0
bool v8; // vf
int v9; // w21
cocos2d::CCArray *v10; // x20
const char *v11; // x8
cocos2d::CCString *v12; // x0
char *CString; // x0
DialogLayer *v14; // x20
GameStatsManager *v15; // x21
SecretRewardsLayer *v16; // x0
SecretRewardsLayer *v17; // x21
RewardUnlockLayer *v18; // x20
std::string __dst; // [xsp+10h] [xbp-80h] BYREF
void *__p[2]; // [xsp+28h] [xbp-68h] BYREF
char v21; // [xsp+3Fh] [xbp-51h]
void *v22[2]; // [xsp+40h] [xbp-50h] BYREF
char v23; // [xsp+57h] [xbp-39h]
std::string v24; // [xsp+58h] [xbp-38h] BYREF
v4 = ((__int64 (__fastcall *)(cocos2d::CCObject *))a2->getTag)(a2);
memset(&v24, 0, sizeof(v24));
switch ( v4 )
{
case 8:
std::string::assign(&v24, "0006");
v5 = 200;
break;
case 7:
std::string::assign(&v24, "0005");
v5 = 100;
break;
case 6:
std::string::assign(&v24, "0004");
v5 = 50;
break;
default:
goto LABEL_23;
}
v6 = GameStatsManager::sharedState();
v7 = cocos2d::CCDictionary::count(v6->m_treasureRoomChests);
v8 = __OFSUB__(v5, v7);
v9 = v5 - v7;
if ( (v9 < 0) ^ v8 | (v9 == 0) )
{
v15 = GameStatsManager::sharedState();
if ( SHIBYTE(v24.__r_.__value_.__r.__words[2]) < 0 )
sub_1000097D0(&__dst, v24.__r_.__value_.__l.__data_, v24.__r_.__value_.__l.__size_);
else
__dst = v24;
v16 = (SecretRewardsLayer *)GameStatsManager::unlockSpecialChest(v15, &__dst);
v17 = v16;
if ( SHIBYTE(__dst.__r_.__value_.__r.__words[2]) < 0 )
{
operator delete(__dst.__r_.__value_.__l.__data_);
if ( !v17 )
goto LABEL_23;
}
else if ( !v16 )
{
goto LABEL_23;
}
SecretRewardsLayer::switchToOpenedState(v16, (CCMenuItemSpriteExtra *)a2);
v18 = RewardUnlockLayer::create(LODWORD(v17->m_fScaleX), nullptr);
((void (__fastcall *)(SecretRewardsLayer *, RewardUnlockLayer *, __int64))a1->addChild_0)(a1, v18, 100);
RewardUnlockLayer::showCollectReward(v18, (GJRewardItem *)v17);
goto LABEL_23;
}
v10 = (cocos2d::CCArray *)sub_10024A15C();
sub_100009900(v22, "The Keymaster");
v11 = "Chests";
if ( v9 == 1 )
v11 = "Chest";
v12 = (cocos2d::CCString *)sub_100268F4C(
"Unlock %i more %s, and you can collect this bonus.",
v9,
v11);
CString = (char *)cocos2d::CCString::getCString(v12);
sub_100009900(__p, CString);
DialogObject::create((__int64)v22, (__int64)__p, 2, 0, 0xFFFFFF, 1.0);
sub_10024A2D0((__int64)v10);
if ( v21 < 0 )
operator delete(__p[0]);
if ( v23 < 0 )
operator delete(v22[0]);
v14 = DialogLayer::createWithObjects(v10, 2);
((void (__fastcall *)(SecretRewardsLayer *, DialogLayer *, __int64))a1->addChild_0)(a1, v14, 100);
DialogLayer::updateChatPlacement(v14, Center);
DialogLayer::animateInRandomSide(v14);
LABEL_23:
if ( SHIBYTE(v24.__r_.__value_.__r.__words[2]) < 0 )
operator delete(v24.__r_.__value_.__l.__data_);
}