//
// SecretRewardsLayer::onSelectItem from 0x100634820 to 0x100634b0d (749 bytes)
//
// 1 xrefs:
// > SecretRewardsLayer::generateChestItems @ 0x10063446b
//
// 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::onSelectItem(SecretRewardsLayer *a1, cocos2d::CCObject *a2)
{
double v2; // xmm0_8
GameStatsManager *v4; // rax
int Stat; // ebx
int v6; // r12d
__int64 v7; // rax
int v8; // r13d
GameStatsManager *v9; // rax
int v10; // eax
int v11; // r15d
GameStatsManager *v12; // rax
GJRewardItem *v13; // rax
GJChestSprite *v14; // rbx
__int64 v15; // rax
unsigned int *v16; // rax
_QWORD *v17; // r13
_QWORD *v18; // r15
__int64 v19; // r12
RewardUnlockLayer *v20; // rbx
cocos2d::CCLabelBMFont *m_keysLabel; // rbx
GameStatsManager *v22; // rax
cocos2d::CCString *v23; // rax
const char *CString; // rax
cocos2d::CCString *v25; // rax
const char *v26; // rax
int v27; // ebx
char *v28; // rax
DialogLayer *v29; // rbx
GJRewardItem *v30; // [rsp+8h] [rbp-78h]
std::string v31; // [rsp+10h] [rbp-70h] BYREF
__int128 v32; // [rsp+28h] [rbp-58h] BYREF
void *v33; // [rsp+38h] [rbp-48h]
std::string v34; // [rsp+40h] [rbp-40h] BYREF
v4 = GameStatsManager::sharedState();
Stat = GameStatsManager::getStat(v4, "21");
v6 = ((__int64 (__fastcall *)(cocos2d::CCObject *))a2->getTag)(a2);
v7 = ((__int64 (__fastcall *)(cocos2d::CCObject *))a2->__vftable[13].~CCObject_0)(a2);
v8 = (*(__int64 (__fastcall **)(__int64))(*(_QWORD *)v7 + 64LL))(v7);
v9 = GameStatsManager::sharedState();
v10 = GameStatsManager::keyCostForSecretChest(v9, v6);
v11 = v10 - Stat;
if ( v10 <= Stat )
{
v12 = GameStatsManager::sharedState();
v13 = GameStatsManager::unlockSecretChest(v12, v6);
if ( v13 )
{
v30 = v13;
v13->m_chestID = v8;
v14 = (GJChestSprite *)((__int64 (__fastcall *)(cocos2d::CCObject *))a2->__vftable[13].~CCObject_0)(a2);
GJChestSprite::switchToState(v14, Opened, 1);
v15 = ((__int64 (__fastcall *)(GJChestSprite *))v14->getChildren)(v14);
if ( v15 )
{
v16 = *(unsigned int **)(v15 + 56);
if ( *v16 )
{
v17 = *((_QWORD **)v16 + 2);
v18 = &v17[*v16 - 1];
do
{
v19 = *v17;
if ( !*v17 )
break;
(*(void (__fastcall **)(_QWORD, __int64))(*(_QWORD *)v19 + 896LL))(*v17, 100);
v34.__r_.__value_.__s.__data_[1] = -106;
*(_WORD *)&v34.__r_.__value_.__l.0 = -26986;
(*(void (__fastcall **)(__int64, std::string *))(*(_QWORD *)v19 + 944LL))(v19, &v34);
++v17;
}
while ( v17 <= v18 );
}
}
((void (__fastcall *)(cocos2d::CCObject *, _QWORD))a2->__vftable[13].copyWithZone)(a2, 0);
v20 = RewardUnlockLayer::create(v30->m_rewardType, nullptr);
((void (__fastcall *)(SecretRewardsLayer *, RewardUnlockLayer *, __int64))a1->addChild_0)(a1, v20, 100);
RewardUnlockLayer::showCollectReward(v20, v30);
m_keysLabel = a1->m_keysLabel;
v22 = GameStatsManager::sharedState();
GameStatsManager::getStat(v22, "21");
v23 = (cocos2d::CCString *)sub_1007AB580("%i", (char)a1);
CString = cocos2d::CCString::getCString(v23);
((void (__fastcall *)(cocos2d::CCLabelBMFont *, const char *))m_keysLabel->setString)(m_keysLabel, CString);
SecretRewardsLayer::updateUnlockedLabel(a1);
}
}
else
{
*(_WORD *)&v34.__r_.__value_.__l.0 = 0;
if ( v10 == 1 )
{
std::string::assign(&v34, "You need a key to unlock this chest.");
}
else
{
v25 = (cocos2d::CCString *)sub_1007AB580(
"You need %i more keys to unlock this chest",
(char)a1);
v26 = cocos2d::CCString::getCString(v25);
std::string::assign(&v34, v26);
}
v27 = 18;
if ( v11 <= 50 )
{
v27 = 17;
if ( v11 <= 25 )
v27 = 2 * (v11 >= 11) + 2;
}
LOBYTE(v32) = 26;
strcpy((char *)&v32 + 1, "The Keymaster");
if ( (*(_BYTE *)&v34.__r_.__value_.__s.0 & 1) != 0 )
sub_100006B70(&v31, v34.__r_.__value_.__l.__data_, v34.__r_.__value_.__l.__size_, v2);
else
v31 = v34;
v28 = DialogObject::create(&v32, &v31, v27, 0, 0xFFFFFF, 1.0);
v29 = DialogLayer::create((DialogObject *)v28, 2);
if ( (*(_BYTE *)&v31.__r_.__value_.__s.0 & 1) != 0 )
operator delete(v31.__r_.__value_.__l.__data_);
if ( (v32 & 1) != 0 )
operator delete(v33);
DialogLayer::addToMainScene(v29);
DialogLayer::updateChatPlacement(v29, Center);
DialogLayer::animateInRandomSide(v29);
if ( (*(_BYTE *)&v34.__r_.__value_.__s.0 & 1) != 0 )
operator delete(v34.__r_.__value_.__l.__data_);
}
}