//
// SecretRewardsLayer::onSelectItem from 0x585ba8 to 0x585d54 (428 bytes)
//
// 0 xrefs:
//
// 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::onSelectItem(SecretRewardsLayer *a1, cocos2d::CCObject *a2)
{
GameStatsManager *v4; // r0
int Stat; // r4
int v6; // r11
int v7; // r0
int v8; // r10
GameStatsManager *v9; // r0
int v10; // r0
int v11; // r8
const char *v12; // r4
char *v13; // r1
cocos2d::CCString *v14; // r0
std::string v15; // r8
DialogObject *v16; // r0
DialogLayer *v17; // r8
GameStatsManager *v18; // r0
GJRewardItem *v19; // r0
GJRewardItem *v20; // r4
RewardUnlockLayer *v21; // r7
cocos2d::CCLabelBMFont *m_keysLabel; // r4
void (__fastcall *setString)(cocos2d::CCLabelBMFont *__hidden, const unsigned __int8 *); // r7
GameStatsManager *v24; // r0
const char *v25; // r0
cocos2d::CCString *v26; // r0
const char *CString; // r0
int v28; // [sp+4h] [bp-20h]
_BYTE v29[4]; // [sp+10h] [bp-14h] BYREF
char v30; // [sp+14h] [bp-10h] BYREF
_BYTE v31[4]; // [sp+18h] [bp-Ch] BYREF
v4 = GameStatsManager::sharedState();
Stat = GameStatsManager::getStat(v4, "21");
v6 = a2->getTag(a2);
v7 = ((int (__fastcall *)(cocos2d::CCObject *))a2->__vftable[13].~CCObject_0)(a2);
v8 = (*(int (__fastcall **)(int))(*(_DWORD *)v7 + 32))(v7);
v9 = GameStatsManager::sharedState();
v10 = GameStatsManager::keyCostForSecretChest(v9, v6);
v11 = v10;
if ( Stat >= v10 )
{
v18 = GameStatsManager::sharedState();
v19 = GameStatsManager::unlockSecretChest(v18, v6);
v20 = v19;
if ( v19 )
{
v19->m_chestID = v8;
SecretRewardsLayer::switchToOpenedState(a1, (CCMenuItemSpriteExtra *)a2);
v21 = RewardUnlockLayer::create(v20->m_rewardType, nullptr);
a1->addChild_0(a1, v21, 100);
RewardUnlockLayer::showCollectReward(v21, v20);
m_keysLabel = a1->m_keysLabel;
setString = m_keysLabel->setString;
v24 = GameStatsManager::sharedState();
v25 = (const char *)GameStatsManager::getStat(v24, "21");
v26 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat((cocos2d::CCString *)"%i", v25);
CString = cocos2d::CCString::getCString(v26);
setString(m_keysLabel, (const unsigned __int8 *)CString);
SecretRewardsLayer::updateUnlockedLabel(a1);
}
}
else
{
v12 = (const char *)(v10 - Stat);
sub_776584((int)v29, (char *)&unk_939830);
if ( v11 == 1 )
{
v13 = "You need a key to unlock this chest.";
}
else
{
v14 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"You need %i more keys to unlock this chest",
v12);
v13 = (char *)cocos2d::CCString::getCString(v14);
}
sub_7753D4((int)v29, v13);
if ( (int)v12 > 50 )
{
v15.m_data.m_data = (stl::StringData::Internal *)&word_12;
}
else if ( (int)v12 > 25 )
{
v15.m_data.m_data = (stl::StringData::Internal *)(&word_10 + 1);
}
else if ( (int)v12 >= 11 )
{
v15.m_data.m_data = (stl::StringData::Internal *)byte_4;
}
else
{
v15.m_data.m_data = (stl::StringData::Internal *)(&dword_0 + 2);
}
sub_776584((int)&v30, "The Keymaster");
sub_775C20(v31);
LOWORD(v28) = -1;
BYTE2(v28) = -1;
v16 = (DialogObject *)DialogObject::create((DialogObject *)&v30, (std::string)v31, v15, 1065353216, 0.0, v28);
v17 = DialogLayer::create(v16, (int)&dword_0 + 2);
sub_774008(v31);
sub_774008(&v30);
DialogLayer::addToMainScene(v17);
DialogLayer::updateChatPlacement(v17, Center);
DialogLayer::animateInRandomSide(v17);
sub_774008(v29);
}
}