//
// SecretRewardsLayer::updateUnlockedLabel from 0xa61b9c to 0xa61db0 (532 bytes)
//
// 4 xrefs:
// > SecretRewardsLayer::onSelectItem @ 0xa62020
// > SecretRewardsLayer::init @ 0xa640c8
// > SecretRewardsLayer::createSecondaryLayer @ 0xa6adec
// > ??> @ 0xc6978
//
// 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::updateUnlockedLabel(SecretRewardsLayer *a1)
{
GameStatsManager *v2; // x0
unsigned int v3; // w23
GameStatsManager *v4; // x0
unsigned int v5; // w0
cocos2d::CCLabelBMFont *m_chestLabel; // x22
const char *v7; // x1
void (__fastcall *setString)(cocos2d::CCLabelBMFont *__hidden, const unsigned __int8 *); // x23
cocos2d::CCString *v9; // x0
const char *CString; // x0
GameStatsManager *v11; // x0
int v12; // w22
GameStatsManager *v13; // x0
int v14; // w23
cocos2d::CCString *v15; // x0
char *v16; // x0
cocos2d::CCLabelBMFont *m_chestCounter; // x0
cocos2d::CCObject *v18; // x0
cocos2d::CCObject *v19; // x21
cocos2d::CCLabelBMFont *v20; // x0
void (__fastcall *setColor)(cocos2d::CCLabelBMFont *__hidden, const cocos2d::ccColor3B *); // x3
void (__fastcall *v22)(cocos2d::CCObject *__hidden); // x3
unsigned __int8 *v23; // x0
unsigned int *v24; // x2
int v25; // w1
char v26; // [xsp+48h] [xbp+48h] BYREF
char v27; // [xsp+49h] [xbp+49h]
char v28; // [xsp+4Ah] [xbp+4Ah]
unsigned __int8 *v29; // [xsp+50h] [xbp+50h] BYREF
v2 = GameStatsManager::sharedState();
v3 = GameStatsManager::countUnlockedSecretChests(v2, (GJRewardType)0);
v4 = GameStatsManager::sharedState();
v5 = GameStatsManager::countSecretChests(v4, (GJRewardType)0);
m_chestLabel = a1->m_chestLabel;
v7 = (const char *)v3;
setString = m_chestLabel->setString;
v9 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat((cocos2d::CCString *)"%i/%i", v7, v5);
CString = cocos2d::CCString::getCString(v9);
setString(m_chestLabel, (const unsigned __int8 *)CString);
if ( !a1->m_inMainLayer )
{
v11 = GameStatsManager::sharedState();
v12 = GameStatsManager::countUnlockedSecretChests(v11, a1->m_rewardType);
v13 = GameStatsManager::sharedState();
v14 = GameStatsManager::countSecretChests(v13, a1->m_rewardType);
v15 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"%i/%i",
(const char *)(unsigned int)v12,
(unsigned int)v14);
v16 = (char *)cocos2d::CCString::getCString(v15);
sub_D153B8((int)&v29, v16);
m_chestCounter = a1->m_chestCounter;
if ( m_chestCounter )
m_chestCounter->setString(m_chestCounter, v29);
v18 = cocos2d::CCDictionary::objectForKey(a1->m_chestCounters, a1->m_rewardType);
v19 = v18;
if ( v18 )
v18->__vftable[11].acceptVisitor(v18, (cocos2d::CCDataVisitor *)v29);
if ( v12 >= v14 )
{
v20 = a1->m_chestCounter;
if ( v20 )
{
setColor = v20->setColor;
v26 = 0;
v27 = -1;
v28 = -1;
setColor(v20, (const cocos2d::ccColor3B *)&v26);
}
if ( v19 )
{
v22 = v19->__vftable[13].~CCObject_0;
v26 = 50;
v27 = -1;
v28 = 50;
((void (__fastcall *)(cocos2d::CCObject *, char *))v22)(v19, &v26);
}
}
v23 = v29 - 24;
if ( v29 - 24 != (unsigned __int8 *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v24 = (unsigned int *)(v29 - 8);
do
v25 = __ldaxr(v24);
while ( __stlxr(v25 - 1, v24) );
}
else
{
v25 = *((_DWORD *)v29 - 2);
*((_DWORD *)v29 - 2) = v25 - 1;
}
if ( v25 <= 0 )
operator delete(v23);
}
}
}