//
// GameStatsManager::awardCurrencyForLevel from 0x7ba9a8 to 0x7baef4 (1356 bytes)
//
// 5 xrefs:
// > PlayLayer::levelComplete @ 0x5d11c4
// > PlayLayer::destroyPlayer @ 0x5d1f48
// > GameLevelManager::updateLevelRewards @ 0x704ee0
// > GameStatsManager::awardOldSpecialStats @ 0x7bafa8
// > ??> @ 0xad130
//
// 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 GameStatsManager::awardCurrencyForLevel(GameStatsManager *a1, GJGameLevel *a2)
{
_BOOL4 v4; // w25
int v5; // w22
int v6; // w0
_BOOL4 m_gauntletLevel; // w1
cocos2d::CCDictionary *m_timelyCurrencyScores; // x28
int v9; // w26
cocos2d::CCString *v10; // x0
int v11; // w24
char *v12; // x0
char *v13; // x0
float BaseCurrencyForLevel; // s2
unsigned int v15; // w1
int v16; // w24
int v17; // w24
char *v18; // x0
bool v19; // zf
cocos2d::CCDictionary *m_timelyStars; // x25
cocos2d::CCString *v21; // x0
int v22; // w19
char *v23; // x0
char *v24; // x0
unsigned int *v25; // x19
int v26; // w1
unsigned int *v27; // x1
int v28; // w2
cocos2d::CCObject *v29; // x22
unsigned int *v30; // x1
int v31; // w2
unsigned int *v32; // x1
int v33; // w2
unsigned int *v34; // x1
int v35; // w2
cocos2d::CCObject *v36; // [xsp+68h] [xbp+68h]
_BOOL4 v37; // [xsp+7Ch] [xbp+7Ch]
char *v38; // [xsp+90h] [xbp+90h] BYREF
std::string v39; // [xsp+98h] [xbp+98h] BYREF
char *v40; // [xsp+A0h] [xbp+A0h] BYREF
std::string v41; // [xsp+A8h] [xbp+A8h] BYREF
__int64 v42; // [xsp+B0h] [xbp+B0h] BYREF
v4 = a2->m_dailyID.random - a2->m_dailyID.seed > 0;
v5 = a2->m_stars.random - a2->m_stars.seed;
v37 = a2->m_levelType == Main;
v6 = a2->m_orbCompletion.random - a2->m_orbCompletion.seed;
m_gauntletLevel = a2->m_gauntletLevel;
if ( v4 )
{
m_timelyCurrencyScores = a1->m_timelyCurrencyScores;
}
else
{
if ( v37 )
{
m_timelyCurrencyScores = a1->m_mainCurrencyScores;
if ( v6 <= 0 )
return;
goto LABEL_4;
}
if ( m_gauntletLevel )
m_timelyCurrencyScores = a1->m_gauntletCurrencyScores;
else
m_timelyCurrencyScores = a1->m_onlineCurrencyScores;
}
if ( v6 <= 0 )
return;
LABEL_4:
if ( v5 > 0 )
{
v9 = 100;
if ( v6 <= 99 )
v9 = a2->m_orbCompletion.random - a2->m_orbCompletion.seed;
GameStatsManager::getCurrencyKey(a1, a2, (__int64)&v38);
sub_D153B8((int)&v39, v38);
v10 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(m_timelyCurrencyScores, &v39);
v11 = cocos2d::CCString::intValue(v10);
v12 = (char *)v39.m_data.m_data - 24;
if ( (__int64 *)v39.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v27 = (unsigned int *)((char *)v39.m_data.m_data - 8);
do
v28 = __ldaxr(v27);
while ( __stlxr(v28 - 1, v27) );
}
else
{
v28 = *((_DWORD *)v39.m_data.m_data - 2);
*((_DWORD *)v39.m_data.m_data - 2) = v28 - 1;
}
if ( v28 <= 0 )
operator delete(v12);
}
if ( v9 > v11 )
{
BaseCurrencyForLevel = (float)GameStatsManager::getBaseCurrencyForLevel(a1, a2);
v15 = vcvtms_s32_f32(BaseCurrencyForLevel * (float)((float)v11 / 100.0));
v16 = vcvtms_s32_f32(BaseCurrencyForLevel * (float)((float)v9 / 100.0));
if ( v9 == 100 )
v16 = (int)(float)((float)v16 + (float)(BaseCurrencyForLevel * 0.25));
v17 = v16 - v15;
if ( v17 > 0 )
{
v36 = (cocos2d::CCObject *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"%i",
(const char *)(unsigned int)v9);
sub_D153B8((int)&v40, v38);
cocos2d::CCDictionary::setObject((int)m_timelyCurrencyScores, v36);
v18 = v40 - 24;
if ( v40 - 24 != (char *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v30 = (unsigned int *)(v40 - 8);
do
v31 = __ldaxr(v30);
while ( __stlxr(v31 - 1, v30) );
}
else
{
v31 = *((_DWORD *)v40 - 2);
*((_DWORD *)v40 - 2) = v31 - 1;
}
if ( v31 <= 0 )
operator delete(v18);
}
if ( !v37 )
{
v19 = !v4;
m_timelyStars = a1->m_timelyStars;
if ( v19 )
m_timelyStars = a1->m_onlineStars;
GameStatsManager::getCurrencyKey(a1, a2, (__int64)&v40);
sub_D153B8((int)&v41, v40);
v21 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(m_timelyStars, &v41);
v22 = cocos2d::CCString::intValue(v21);
v23 = (char *)v41.m_data.m_data - 24;
if ( (__int64 *)v41.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v32 = (unsigned int *)((char *)v41.m_data.m_data - 8);
do
v33 = __ldaxr(v32);
while ( __stlxr(v33 - 1, v32) );
}
else
{
v33 = *((_DWORD *)v41.m_data.m_data - 2);
*((_DWORD *)v41.m_data.m_data - 2) = v33 - 1;
}
if ( v33 <= 0 )
operator delete(v23);
}
if ( v22 < v5 )
{
v29 = (cocos2d::CCObject *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"%i",
(const char *)(unsigned int)v5);
sub_D153B8((int)&v42, v40);
cocos2d::CCDictionary::setObject((int)m_timelyStars, v29);
if ( (__int64 *)(v42 - 24) != &qword_124B6B0 )
sub_7A1200((void *)(v42 - 24));
}
v24 = v40 - 24;
if ( v40 - 24 != (char *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v34 = (unsigned int *)(v40 - 8);
do
v35 = __ldaxr(v34);
while ( __stlxr(v35 - 1, v34) );
}
else
{
v35 = *((_DWORD *)v40 - 2);
*((_DWORD *)v40 - 2) = v35 - 1;
}
if ( v35 <= 0 )
operator delete(v24);
}
}
GameStatsManager::incrementStat(a1, "14", v17);
}
}
v13 = v38 - 24;
if ( v38 - 24 != (char *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v25 = (unsigned int *)(v38 - 8);
do
v26 = __ldaxr(v25);
while ( __stlxr(v26 - 1, v25) );
}
else
{
v26 = *((_DWORD *)v38 - 2);
*((_DWORD *)v38 - 2) = v26 - 1;
}
if ( v26 <= 0 )
operator delete(v13);
}
}
}