//
// SecretRewardsLayer::onSelectItem from 0x1002eb434 to 0x1002eb69c (616 bytes)
//
// 1 xrefs:
// > SecretRewardsLayer::generateChestItems @ 0x1002eb154
//
// 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)
{
GameStatsManager *v4; // x0
int Stat; // w24
int v6; // w21
__int64 v7; // x0
int v8; // w22
GameStatsManager *v9; // x0
int v10; // w0
bool v11; // vf
int v12; // w24
int v13; // w23
GameStatsManager *v14; // x0
GJRewardItem *v15; // x0
GJRewardItem *v16; // x21
RewardUnlockLayer *v17; // x20
cocos2d::CCLabelBMFont *m_keysLabel; // x20
GameStatsManager *v19; // x0
int v20; // w0
cocos2d::CCString *v21; // x0
const char *CString; // x0
cocos2d::CCString *v23; // x0
const char *v24; // x0
int v25; // w19
int v26; // w9
char *v27; // x0
DialogLayer *v28; // x19
std::string __p; // [xsp+10h] [xbp-80h] BYREF
void *v30[2]; // [xsp+30h] [xbp-60h] BYREF
char v31; // [xsp+47h] [xbp-49h]
std::string v32; // [xsp+48h] [xbp-48h] 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 = __OFSUB__(v10, Stat);
v12 = v10 - Stat;
if ( (v12 < 0) ^ v11 | (v12 == 0) )
{
v14 = GameStatsManager::sharedState();
v15 = GameStatsManager::unlockSecretChest(v14, v6);
if ( v15 )
{
v16 = v15;
v15->m_chestID = v8;
SecretRewardsLayer::switchToOpenedState((SecretRewardsLayer *)v15, (CCMenuItemSpriteExtra *)a2);
v17 = RewardUnlockLayer::create(v16->m_rewardType, nullptr);
((void (__fastcall *)(SecretRewardsLayer *, RewardUnlockLayer *, __int64))a1->addChild_0)(a1, v17, 100);
RewardUnlockLayer::showCollectReward(v17, v16);
m_keysLabel = a1->m_keysLabel;
v19 = GameStatsManager::sharedState();
v20 = GameStatsManager::getStat(v19, "21");
v21 = (cocos2d::CCString *)sub_100268F4C("%i", v20);
CString = cocos2d::CCString::getCString(v21);
((void (__fastcall *)(cocos2d::CCLabelBMFont *, const char *))m_keysLabel->setString)(m_keysLabel, CString);
SecretRewardsLayer::updateUnlockedLabel(a1);
}
}
else
{
v13 = v10;
sub_100009900(&v32, "");
if ( v13 == 1 )
{
std::string::assign(&v32, "You need a key to unlock this chest.");
}
else
{
v23 = (cocos2d::CCString *)sub_100268F4C(
"You need %i more keys to unlock this chest",
v12);
v24 = cocos2d::CCString::getCString(v23);
std::string::assign(&v32, v24);
}
if ( v12 <= 50 )
{
if ( v12 <= 10 )
v26 = 2;
else
v26 = 4;
if ( v12 <= 25 )
v25 = v26;
else
v25 = 17;
}
else
{
v25 = 18;
}
sub_100009900(v30, "The Keymaster");
if ( SHIBYTE(v32.__r_.__value_.__r.__words[2]) < 0 )
sub_1000097D0(&__p, v32.__r_.__value_.__l.__data_, v32.__r_.__value_.__l.__size_);
else
__p = v32;
v27 = DialogObject::create((__int64)v30, (__int64)&__p, v25, 0, 0xFFFFFF, 1.0);
v28 = DialogLayer::create((DialogObject *)v27, 2);
if ( SHIBYTE(__p.__r_.__value_.__r.__words[2]) < 0 )
operator delete(__p.__r_.__value_.__l.__data_);
if ( v31 < 0 )
operator delete(v30[0]);
DialogLayer::addToMainScene(v28);
DialogLayer::updateChatPlacement(v28, Center);
DialogLayer::animateInRandomSide(v28);
if ( SHIBYTE(v32.__r_.__value_.__r.__words[2]) < 0 )
operator delete(v32.__r_.__value_.__l.__data_);
}
}