//
// SecretRewardsLayer::onSpecialItem from 0x100632c50 to 0x100632fe0 (912 bytes)
//
// 1 xrefs:
// > SecretRewardsLayer::onChestType @ 0x100632175
//
// 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; // eax
__m128 v5; // xmm0
signed int v6; // r15d
const std::string::value_type *v7; // rsi
cocos2d::CCDictionary *m_treasureRoomChests; // rdi
cocos2d::CCArray *v9; // r14
cocos2d::CCString *v10; // rax
const char *CString; // r15
size_t v12; // rax
std::string::size_type v13; // r12
char *data; // r13
GameStatsManager *v15; // r15
GJRewardItem *v16; // r15
GJChestSprite *v17; // r12
__int64 v18; // rax
unsigned int *v19; // rax
_QWORD *v20; // rbx
unsigned __int64 v21; // r15
__int64 v22; // r13
SecretRewardsLayer *v23; // rbx
RewardUnlockLayer *v24; // r14
size_t v25; // rbx
char *v26; // rax
SecretRewardsLayer *v27; // rbx
DialogLayer *v28; // r14
char v29; // [rsp+0h] [rbp-B0h]
GJRewardItem *v30; // [rsp+8h] [rbp-A8h]
__int128 v31; // [rsp+10h] [rbp-A0h] BYREF
void *__p; // [rsp+20h] [rbp-90h]
__int128 v33; // [rsp+28h] [rbp-88h] BYREF
void *v34; // [rsp+38h] [rbp-78h]
std::string __dst; // [rsp+40h] [rbp-70h] BYREF
SecretRewardsLayer *v36; // [rsp+58h] [rbp-58h]
std::string v37; // [rsp+60h] [rbp-50h] BYREF
__int16 v38; // [rsp+84h] [rbp-2Ch] BYREF
char v39; // [rsp+86h] [rbp-2Ah]
v4 = ((__int64 (__fastcall *)(cocos2d::CCObject *))a2->getTag)(a2);
v5 = 0;
memset(&v37, 0, sizeof(v37));
switch ( v4 )
{
case 8:
v6 = 200;
v7 = "0006";
std::string::assign(&v37, "0006");
break;
case 7:
v6 = 100;
v7 = "0005";
std::string::assign(&v37, "0005");
break;
case 6:
v6 = 50;
v7 = "0004";
std::string::assign(&v37, "0004");
break;
default:
goto LABEL_33;
}
m_treasureRoomChests = GameStatsManager::sharedState()->m_treasureRoomChests;
if ( v6 > (int)cocos2d::CCDictionary::count(m_treasureRoomChests) )
{
v36 = a1;
v9 = (cocos2d::CCArray *)sub_10071F9E0(m_treasureRoomChests, v7);
LOBYTE(v33) = 26;
strcpy((char *)&v33 + 1, "The Keymaster");
v10 = (cocos2d::CCString *)sub_1007AB580("Unlock %i more %s, and you can collect this bonus.", v29);
CString = cocos2d::CCString::getCString(v10);
v12 = strlen(CString);
if ( v12 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100006BF0(0.0);
v13 = v12;
if ( v12 >= 0x17 )
{
v25 = 26;
if ( (v12 | 7) != 0x17 )
v25 = (v12 | 7) + 1;
data = (char *)operator new(v25);
__dst.__r_.__value_.__r.__words[2] = (std::string::size_type)data;
__dst.__r_.__value_.__r.__words[0] = v25 | 1;
__dst.__r_.__value_.__l.__size_ = v13;
}
else
{
__dst.__r_.__value_.__s.0 = (std::string::__short::$7162EEB0FEF29CC674EFA33D0008C7E0)(2 * v12);
data = __dst.__r_.__value_.__s.__data_;
if ( !v12 )
goto LABEL_28;
}
memmove(data, CString, v13);
LABEL_28:
data[v13] = 0;
v26 = DialogObject::create(&v33, &__dst, 2, 0, 0xFFFFFF, 1.0);
sub_10071FCD0(v9, v26);
v27 = v36;
if ( (*(_BYTE *)&__dst.__r_.__value_.__s.0 & 1) != 0 )
operator delete(__dst.__r_.__value_.__l.__data_);
if ( (v33 & 1) != 0 )
operator delete(v34);
v28 = DialogLayer::createWithObjects(v9, 2);
((void (__fastcall *)(SecretRewardsLayer *, DialogLayer *, __int64))v27->addChild_0)(v27, v28, 100);
DialogLayer::updateChatPlacement(v28, Center);
DialogLayer::animateInRandomSide(v28);
goto LABEL_33;
}
v15 = GameStatsManager::sharedState();
if ( (*(_BYTE *)&v37.__r_.__value_.__s.0 & 1) != 0 )
{
sub_100006B70(&v31, v37.__r_.__value_.__l.__data_, v37.__r_.__value_.__l.__size_, 0.0);
}
else
{
__p = v37.__r_.__value_.__l.__data_;
v5 = *(__m128 *)&v37.__r_.__value_.__l.0;
v31 = *(_OWORD *)&v37.__r_.__value_.__l.0;
}
v16 = GameStatsManager::unlockSpecialChest(v15, (__int64)&v31, v5);
if ( (v31 & 1) != 0 )
operator delete(__p);
if ( v16 )
{
v30 = v16;
v17 = (GJChestSprite *)((__int64 (__fastcall *)(cocos2d::CCObject *))a2->__vftable[13].~CCObject_0)(a2);
GJChestSprite::switchToState(v17, Opened, 1);
v18 = ((__int64 (__fastcall *)(GJChestSprite *))v17->getChildren)(v17);
v36 = a1;
if ( v18 )
{
v19 = *(unsigned int **)(v18 + 56);
if ( *v19 )
{
v20 = *((_QWORD **)v19 + 2);
v21 = (unsigned __int64)&v20[*v19 - 1];
do
{
v22 = *v20;
if ( !*v20 )
break;
(*(void (__fastcall **)(_QWORD, __int64))(*(_QWORD *)v22 + 896LL))(*v20, 100);
v39 = -106;
v38 = -26986;
(*(void (__fastcall **)(__int64, __int16 *))(*(_QWORD *)v22 + 944LL))(v22, &v38);
++v20;
}
while ( (unsigned __int64)v20 <= v21 );
}
}
((void (__fastcall *)(cocos2d::CCObject *, _QWORD))a2->__vftable[13].copyWithZone)(a2, 0);
v23 = v36;
v24 = RewardUnlockLayer::create(v30->m_rewardType, nullptr);
((void (__fastcall *)(SecretRewardsLayer *, RewardUnlockLayer *, __int64))v23->addChild_0)(v23, v24, 100);
RewardUnlockLayer::showCollectReward(v24, v30);
}
LABEL_33:
if ( (*(_BYTE *)&v37.__r_.__value_.__s.0 & 1) != 0 )
operator delete(v37.__r_.__value_.__l.__data_);
}