//
// GameStatsManager::awardCurrencyForLevel from 0x1401e0960 to 0x1401e0f01 (1441 bytes)
//
// 4 xrefs:
// > GameLevelManager::updateLevelRewards @ 0x1401466b8
// > PlayLayer::levelComplete @ 0x1403a84c3
// > PlayLayer::destroyPlayer @ 0x1403b3eda
// > ??> @ 0x1406cc4ec
//
// 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
//
// Hidden C++ exception states: #wind=3
void GameStatsManager::awardCurrencyForLevel(GameStatsManager *a1, GJGameLevel *a2)
{
int v4; // edx
int v5; // r14d
int v6; // eax
cocos2d::CCDictionary *m_mainCurrencyScores; // r15
cocos2d::CCString *v8; // rax
const char *CString; // rax
size_t v10; // rbx
size_t v11; // r8
cocos2d::CCString *v12; // rax
void **v13; // rdx
size_t v14; // r8
cocos2d::CCString *v15; // rax
int v16; // edi
void *v17; // rcx
float BaseCurrencyForLevel; // xmm7_4
int v19; // r12d
int v20; // edi
int v21; // edi
void **v22; // rdx
size_t v23; // r8
struct cocos2d::CCString *v24; // rax
void *v25; // rcx
cocos2d::CCDictionary *m_onlineStars; // r14
cocos2d::CCString *v27; // rax
const char *v28; // rax
size_t v29; // r8
cocos2d::CCString *v30; // rax
void **v31; // rdx
size_t v32; // r8
cocos2d::CCString *v33; // rax
int v34; // esi
void *v35; // rcx
void **v36; // rdx
struct cocos2d::CCString *v37; // rax
void *v38; // rcx
void *v39; // rcx
void *v40; // rcx
int v41; // [rsp+20h] [rbp-69h]
GJLevelType m_levelType; // [rsp+24h] [rbp-65h]
int v43; // [rsp+28h] [rbp-61h]
void *Block[2]; // [rsp+30h] [rbp-59h] BYREF
__int128 v45; // [rsp+40h] [rbp-49h]
void *v46[2]; // [rsp+50h] [rbp-39h] BYREF
__int128 v47; // [rsp+60h] [rbp-29h]
void *v48[2]; // [rsp+70h] [rbp-19h] BYREF
__int128 v49; // [rsp+80h] [rbp-9h]
v4 = a2->m_stars.random - a2->m_stars.seed;
v41 = v4;
v5 = a2->m_orbCompletion.random - a2->m_orbCompletion.seed;
m_levelType = a2->m_levelType;
v6 = a2->m_dailyID.random - a2->m_dailyID.seed;
v43 = v6;
if ( v6 <= 0 )
{
if ( a2->m_levelType == Main )
{
m_mainCurrencyScores = a1->m_mainCurrencyScores;
}
else if ( a2->m_gauntletLevel )
{
m_mainCurrencyScores = a1->m_gauntletCurrencyScores;
}
else
{
m_mainCurrencyScores = a1->m_onlineCurrencyScores;
}
}
else
{
m_mainCurrencyScores = a1->m_timelyCurrencyScores;
}
if ( v4 > 0 && v5 > 0 )
{
if ( v5 > 100 )
v5 = 100;
if ( v6 <= 0 )
{
v12 = cocos2d::CCString::createWithFormat("%i", a2->m_levelID.random - a2->m_levelID.seed);
CString = cocos2d::CCString::getCString(v12);
*(_OWORD *)v46 = 0;
v47 = 0;
v10 = -1;
v11 = -1;
do
++v11;
while ( CString[v11] );
}
else
{
v8 = cocos2d::CCString::createWithFormat("%i", v6);
CString = cocos2d::CCString::getCString(v8);
*(_OWORD *)v46 = 0;
v47 = 0;
v10 = -1;
v11 = -1;
do
++v11;
while ( CString[v11] );
}
sub_14003A930(v46, CString, v11);
v13 = v46;
if ( *((_QWORD *)&v47 + 1) > 0xFu )
v13 = (void **)v46[0];
*(_OWORD *)Block = 0;
v45 = 0;
v14 = -1;
do
++v14;
while ( *((_BYTE *)v13 + v14) );
sub_14003A930(Block, v13, v14);
v15 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(m_mainCurrencyScores, Block);
v16 = cocos2d::CCString::intValue(v15);
if ( *((_QWORD *)&v45 + 1) > 0xFu )
{
v17 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v45 + 1) + 1LL) >= 0x1000 )
{
v17 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v17 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v17);
}
if ( v16 < v5 )
{
BaseCurrencyForLevel = (float)GameStatsManager::getBaseCurrencyForLevel(a1, a2);
v19 = (int)floorf((float)((float)v16 / 100.0) * BaseCurrencyForLevel);
v20 = (int)floorf((float)((float)v5 / 100.0) * BaseCurrencyForLevel);
if ( v5 == 100 )
v20 = (int)(float)((float)(BaseCurrencyForLevel * 0.25) + (float)v20);
v21 = v20 - v19;
if ( v21 > 0 )
{
v22 = v46;
if ( *((_QWORD *)&v47 + 1) > 0xFu )
v22 = (void **)v46[0];
*(_OWORD *)Block = 0;
v45 = 0;
v23 = -1;
do
++v23;
while ( *((_BYTE *)v22 + v23) );
sub_14003A930(Block, v22, v23);
v24 = cocos2d::CCString::createWithFormat("%i", v5);
cocos2d::CCDictionary::setObject(m_mainCurrencyScores, v24, Block);
if ( *((_QWORD *)&v45 + 1) > 0xFu )
{
v25 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v45 + 1) + 1LL) >= 0x1000 )
{
v25 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v25 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v25);
}
if ( m_levelType != Main )
{
if ( v43 <= 0 )
m_onlineStars = a1->m_onlineStars;
else
m_onlineStars = a1->m_timelyStars;
if ( a2->m_dailyID.random - a2->m_dailyID.seed <= 0 )
{
v30 = cocos2d::CCString::createWithFormat("%i", a2->m_levelID.random - a2->m_levelID.seed);
v28 = cocos2d::CCString::getCString(v30);
*(_OWORD *)Block = 0;
v45 = 0;
v29 = -1;
do
++v29;
while ( v28[v29] );
}
else
{
v27 = cocos2d::CCString::createWithFormat("%i", a2->m_dailyID.random - a2->m_dailyID.seed);
v28 = cocos2d::CCString::getCString(v27);
*(_OWORD *)Block = 0;
v45 = 0;
v29 = -1;
do
++v29;
while ( v28[v29] );
}
sub_14003A930(Block, v28, v29);
v31 = Block;
if ( *((_QWORD *)&v45 + 1) > 0xFu )
v31 = (void **)Block[0];
*(_OWORD *)v48 = 0;
v49 = 0;
v32 = -1;
do
++v32;
while ( *((_BYTE *)v31 + v32) );
sub_14003A930(v48, v31, v32);
v33 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(m_onlineStars, v48);
v34 = cocos2d::CCString::intValue(v33);
if ( *((_QWORD *)&v49 + 1) > 0xFu )
{
v35 = v48[0];
if ( (unsigned __int64)(*((_QWORD *)&v49 + 1) + 1LL) >= 0x1000 )
{
v35 = *((void **)v48[0] - 1);
if ( (unsigned __int64)((char *)v48[0] - (char *)v35 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v35);
}
if ( v34 < v41 )
{
v36 = Block;
if ( *((_QWORD *)&v45 + 1) > 0xFu )
v36 = (void **)Block[0];
*(_OWORD *)v48 = 0;
v49 = 0;
do
++v10;
while ( *((_BYTE *)v36 + v10) );
sub_14003A930(v48, v36, v10);
v37 = cocos2d::CCString::createWithFormat("%i", v41);
cocos2d::CCDictionary::setObject(m_onlineStars, v37, v48);
if ( *((_QWORD *)&v49 + 1) > 0xFu )
{
v38 = v48[0];
if ( (unsigned __int64)(*((_QWORD *)&v49 + 1) + 1LL) >= 0x1000 )
{
v38 = *((void **)v48[0] - 1);
if ( (unsigned __int64)((char *)v48[0] - (char *)v38 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v38);
}
}
if ( *((_QWORD *)&v45 + 1) > 0xFu )
{
v39 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v45 + 1) + 1LL) >= 0x1000 )
{
v39 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v39 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v39);
}
}
GameStatsManager::incrementStat(a1, "14", v21);
}
}
if ( *((_QWORD *)&v47 + 1) > 0xFu )
{
v40 = v46[0];
if ( (unsigned __int64)(*((_QWORD *)&v47 + 1) + 1LL) >= 0x1000 )
{
v40 = *((void **)v46[0] - 1);
if ( (unsigned __int64)((char *)v46[0] - (char *)v40 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v40);
}
}
}