//
// SecretRewardsLayer::onGoldChest from 0x58732c to 0x5874a6 (378 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::onGoldChest(SecretRewardsLayer *a1, cocos2d::CCObject *a2)
{
GameStatsManager *v3; // r0
int Stat; // r5
GameStatsManager *v5; // r0
int NextGoldChestID; // r0
int v7; // r8
int v8; // r5
char *v9; // r1
std::string v10; // r8
DialogObject *v11; // r0
DialogLayer *v12; // r8
GameStatsManager *v13; // r0
GJRewardItem *v14; // r0
GJRewardItem *v15; // r5
RewardUnlockLayer *v16; // r8
cocos2d::CCLabelBMFont *m_goldKeysLabel; // r5
void (__fastcall *setString)(cocos2d::CCLabelBMFont *__hidden, const unsigned __int8 *); // r8
GameStatsManager *v19; // r0
const char *v20; // r0
cocos2d::CCString *v21; // r0
const char *CString; // r0
int v23; // [sp+4h] [bp-1Ch]
_BYTE v24[4]; // [sp+10h] [bp-10h] BYREF
char v25; // [sp+14h] [bp-Ch] BYREF
_BYTE v26[4]; // [sp+18h] [bp-8h] BYREF
v3 = GameStatsManager::sharedState();
Stat = GameStatsManager::getStat(v3, "43");
v5 = GameStatsManager::sharedState();
NextGoldChestID = GameStatsManager::getNextGoldChestID(v5);
v7 = NextGoldChestID;
if ( Stat > 0 && NextGoldChestID )
{
v13 = GameStatsManager::sharedState();
v14 = GameStatsManager::unlockGoldChest(v13, v7);
v15 = v14;
if ( v14 )
{
v16 = RewardUnlockLayer::create(v14->m_rewardType, nullptr);
a1->addChild_0(a1, v16, 100);
RewardUnlockLayer::showCollectReward(v16, v15);
m_goldKeysLabel = a1->m_goldKeysLabel;
setString = m_goldKeysLabel->setString;
v19 = GameStatsManager::sharedState();
v20 = (const char *)GameStatsManager::getStat(v19, "43");
v21 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat((cocos2d::CCString *)"%i", v20);
CString = cocos2d::CCString::getCString(v21);
setString(m_goldKeysLabel, (const unsigned __int8 *)CString);
SecretRewardsLayer::updateUnlockedGoldLabel(a1);
SecretRewardsLayer::fadeInOutMusic(a1);
}
}
else
{
v8 = 1 - Stat;
sub_776584((int)v24, (char *)&unk_939830);
if ( v7 )
v9 = "You need a Gold Key to unlock this chest.";
else
v9 = "All out of Gold Chests right now. Come back later.";
sub_7753D4((int)v24, v9);
if ( v8 > 50 )
{
v10.m_data.m_data = (stl::StringData::Internal *)&word_12;
}
else if ( v8 > 25 )
{
v10.m_data.m_data = (stl::StringData::Internal *)(&word_10 + 1);
}
else if ( v8 >= 11 )
{
v10.m_data.m_data = (stl::StringData::Internal *)byte_4;
}
else
{
v10.m_data.m_data = (stl::StringData::Internal *)(&dword_0 + 2);
}
sub_776584((int)&v25, "The Keymaster");
sub_775C20(v26);
LOWORD(v23) = -1;
BYTE2(v23) = -1;
v11 = (DialogObject *)DialogObject::create((DialogObject *)&v25, (std::string)v26, v10, 1065353216, 0.0, v23);
v12 = DialogLayer::create(v11, (int)&dword_0 + 2);
sub_774008(v26);
sub_774008(&v25);
DialogLayer::addToMainScene(v12);
DialogLayer::updateChatPlacement(v12, Center);
DialogLayer::animateInRandomSide(v12);
sub_774008(v24);
}
}