//
// SecretRewardsLayer::onSelectItem from 0xb9ec90 to 0xb9efb0 (800 bytes)
//
// 3 xrefs:
// > ??> @ 0xa3de0
// > SecretRewardsLayer::generateChestItems @ 0xba1260
// > ??> @ 0x15448e8
//
// This function is hookable on this platform (idp: arm, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 13:02:45 +0000
//
__int64 __fastcall SecretRewardsLayer::onSelectItem(GameStatsManager ***this, cocos2d::CCObject *a2)
{
GameStatsManager *v4; // x0
int Stat; // w22
unsigned int v6; // w25
__int64 v7; // x0
GameStatsManager *v8; // x0
int v9; // w26
GameStatsManager *v10; // x0
GameStatsManager *v11; // x0
int v12; // w23
int v13; // w22
cocos2d::CCString *v14; // x0
char *v15; // x0
int v16; // w19
DialogLayer *v17; // x0
DialogLayer *v18; // x19
GameStatsManager *v20; // x0
int *v21; // x22
RewardsPage *v22; // x2
RewardUnlockLayer *v23; // x19
GameStatsManager **v24; // x19
void (__fastcall *v25)(GameStatsManager **, __int64); // x22
GameStatsManager *v26; // x0
unsigned int v27; // w0
cocos2d::CCString *v28; // x0
__int64 CString; // x0
__int64 v30; // [xsp+50h] [xbp+50h] BYREF
size_t v31; // [xsp+58h] [xbp+58h]
void *v32; // [xsp+60h] [xbp+60h]
__int64 v33[2]; // [xsp+68h] [xbp+68h] BYREF
void *v34; // [xsp+78h] [xbp+78h]
__int64 v35; // [xsp+80h] [xbp+80h] BYREF
size_t v36; // [xsp+88h] [xbp+88h]
void *v37; // [xsp+90h] [xbp+90h]
v4 = (GameStatsManager *)GameStatsManager::sharedState(_stack_chk_guard);
Stat = GameStatsManager::getStat(v4, "21");
v6 = (*(__int64 (__fastcall **)(cocos2d::CCObject *))(*(_QWORD *)a2 + 64LL))(a2);
v7 = (*(__int64 (__fastcall **)(cocos2d::CCObject *))(*(_QWORD *)a2 + 1072LL))(a2);
v8 = (GameStatsManager *)(*(__int64 (__fastcall **)(__int64))(*(_QWORD *)v7 + 64LL))(v7);
v9 = (int)v8;
v10 = (GameStatsManager *)GameStatsManager::sharedState(v8);
v11 = (GameStatsManager *)GameStatsManager::keyCostForSecretChest(v10, v6);
v12 = (int)v11;
if ( Stat >= (int)v11 )
{
v20 = (GameStatsManager *)GameStatsManager::sharedState(v11);
v21 = GameStatsManager::unlockSecretChest(v20, (const char *)v6);
if ( v21 )
{
v21[14] = v9;
SecretRewardsLayer::switchToOpenedState((SecretRewardsLayer *)this, a2);
v23 = (RewardUnlockLayer *)RewardUnlockLayer::create((RewardUnlockLayer *)(unsigned int)v21[16], nullptr, v22);
((void (__fastcall *)(GameStatsManager ***, RewardUnlockLayer *, __int64))(*this)[58])(this, v23, 100);
RewardUnlockLayer::showCollectReward(v23, (GJRewardItem *)v21);
v24 = *(this + 59);
v25 = *((void (__fastcall **)(GameStatsManager **, __int64))*v24 + 116);
v26 = (GameStatsManager *)GameStatsManager::sharedState(*v24);
v27 = GameStatsManager::getStat(v26, "21");
v28 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat((cocos2d::CCString *)"%i", (const char *)v27);
CString = cocos2d::CCString::getCString(v28);
v25(v24, CString);
SecretRewardsLayer::updateUnlockedLabel((SecretRewardsLayer *)this);
}
}
else
{
v30 = 0;
v31 = 0;
v13 = (_DWORD)v11 - Stat;
v32 = nullptr;
std::string::__init(&v30, &byte_11B8890, 0);
if ( v12 == 1 )
{
std::string::assign(&v30, "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",
(const char *)(unsigned int)v13);
v15 = (char *)cocos2d::CCString::getCString(v14);
std::string::assign(&v30, v15);
}
v16 = 18;
if ( v13 <= 50 )
{
v16 = 17;
if ( v13 <= 25 )
{
if ( v13 >= 11 )
v16 = 4;
else
v16 = 2;
}
}
v33[0] = 0;
v33[1] = 0;
v34 = nullptr;
std::string::__init(v33, "The Keymaster", 0xDu);
v35 = 0;
v36 = 0;
v37 = nullptr;
if ( (v30 & 1) != 0 )
{
std::string::__init(&v35, v32, v31);
}
else
{
v35 = v30;
v36 = v31;
v37 = v32;
}
v17 = (DialogLayer *)DialogObject::create((char *)v33, (char *)&v35, v16, 0, 0xFFFFFF, 1.0);
v18 = (DialogLayer *)DialogLayer::create(v17, (DialogObject *)((char *)&dword_0 + 2));
if ( (v35 & 1) != 0 )
operator delete(v37);
if ( (v33[0] & 1) != 0 )
operator delete(v34);
DialogLayer::addToMainScene(v18);
DialogLayer::updateChatPlacement((__int64)v18, 0);
DialogLayer::animateInRandomSide(v18);
if ( (v30 & 1) != 0 )
operator delete(v32);
}
return _stack_chk_guard;
}