//
// GameStatsManager::awardDiamondsForLevel from 0x1401e1140 to 0x1401e15f0 (1200 bytes)
//
// 3 xrefs:
// > PlayLayer::levelComplete @ 0x1403a8530
// > PlayLayer::destroyPlayer @ 0x1403b3f3c
// > ??> @ 0x1406cc504
//
// 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=2
void GameStatsManager::awardDiamondsForLevel(GameStatsManager *a1, GJGameLevel *a2)
{
int v4; // edx
int v5; // r13d
int v6; // r15d
int v7; // r14d
cocos2d::CCString *v8; // rax
const char *CString; // rax
size_t v10; // rdi
size_t v11; // r8
cocos2d::CCString *v12; // rax
cocos2d::CCDictionary *m_gauntletDiamondScores; // r12
void **v14; // rdx
size_t v15; // r8
cocos2d::CCString *v16; // rax
int v17; // ebx
void *v18; // rcx
int v19; // ebx
int v20; // r15d
void **v21; // rdx
size_t v22; // r8
struct cocos2d::CCString *v23; // rax
void *v24; // rcx
cocos2d::CCDictionary *m_onlineStars; // rbx
void **v26; // rdx
size_t v27; // r8
cocos2d::CCString *v28; // rax
int v29; // esi
void *v30; // rcx
void **v31; // rdx
struct cocos2d::CCString *v32; // rax
void *v33; // rcx
void *v34; // rcx
void *Block[2]; // [rsp+30h] [rbp-39h] BYREF
__int128 v37; // [rsp+40h] [rbp-29h]
void *v38[2]; // [rsp+50h] [rbp-19h] BYREF
__int128 v39; // [rsp+60h] [rbp-9h]
v4 = a2->m_dailyID.random - a2->m_dailyID.seed;
if ( v4 > 0 || a2->m_gauntletLevel )
{
v5 = a2->m_stars.random - a2->m_stars.seed;
if ( (unsigned int)(v5 - 2) <= 8 )
{
v6 = v5 + 2;
v7 = a2->m_orbCompletion.random - a2->m_orbCompletion.seed;
if ( v5 + 2 > 0 && v7 > 0 )
{
if ( v7 > 100 )
v7 = 100;
if ( v4 <= 0 )
{
v12 = cocos2d::CCString::createWithFormat("%i", a2->m_levelID.random - a2->m_levelID.seed);
CString = cocos2d::CCString::getCString(v12);
*(_OWORD *)v38 = 0;
v39 = 0;
v10 = -1;
v11 = -1;
do
++v11;
while ( CString[v11] );
}
else
{
v8 = cocos2d::CCString::createWithFormat("%i", v4);
CString = cocos2d::CCString::getCString(v8);
*(_OWORD *)v38 = 0;
v39 = 0;
v10 = -1;
v11 = -1;
do
++v11;
while ( CString[v11] );
}
sub_14003A930(v38, CString, v11);
if ( a2->m_dailyID.random - a2->m_dailyID.seed <= 0 )
m_gauntletDiamondScores = a1->m_gauntletDiamondScores;
else
m_gauntletDiamondScores = a1->m_timelyDiamondScores;
v14 = v38;
if ( *((_QWORD *)&v39 + 1) > 0xFu )
v14 = (void **)v38[0];
*(_OWORD *)Block = 0;
v37 = 0;
v15 = -1;
do
++v15;
while ( *((_BYTE *)v14 + v15) );
sub_14003A930(Block, v14, v15);
v16 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(m_gauntletDiamondScores, Block);
v17 = cocos2d::CCString::intValue(v16);
if ( *((_QWORD *)&v37 + 1) > 0xFu )
{
v18 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v37 + 1) + 1LL) >= 0x1000 )
{
v18 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v18 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v18);
}
if ( v17 < v7 )
{
v19 = (int)floorf((float)((float)v17 / 100.0) * (float)v6);
v20 = (int)floorf((float)((float)v7 / 100.0) * (float)v6) - v19;
if ( v20 > 0 )
{
v21 = v38;
if ( *((_QWORD *)&v39 + 1) > 0xFu )
v21 = (void **)v38[0];
*(_OWORD *)Block = 0;
v37 = 0;
v22 = -1;
do
++v22;
while ( *((_BYTE *)v21 + v22) );
sub_14003A930(Block, v21, v22);
v23 = cocos2d::CCString::createWithFormat("%i", v7);
cocos2d::CCDictionary::setObject(m_gauntletDiamondScores, v23, Block);
if ( *((_QWORD *)&v37 + 1) > 0xFu )
{
v24 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v37 + 1) + 1LL) >= 0x1000 )
{
v24 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v24 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v24);
}
if ( a2->m_dailyID.random - a2->m_dailyID.seed <= 0 )
m_onlineStars = a1->m_onlineStars;
else
m_onlineStars = a1->m_timelyStars;
v26 = v38;
if ( *((_QWORD *)&v39 + 1) > 0xFu )
v26 = (void **)v38[0];
*(_OWORD *)Block = 0;
v37 = 0;
v27 = -1;
do
++v27;
while ( *((_BYTE *)v26 + v27) );
sub_14003A930(Block, v26, v27);
v28 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(m_onlineStars, Block);
v29 = cocos2d::CCString::intValue(v28);
if ( *((_QWORD *)&v37 + 1) > 0xFu )
{
v30 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v37 + 1) + 1LL) >= 0x1000 )
{
v30 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v30 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v30);
}
if ( v29 < v5 )
{
v31 = v38;
if ( *((_QWORD *)&v39 + 1) > 0xFu )
v31 = (void **)v38[0];
*(_OWORD *)Block = 0;
v37 = 0;
do
++v10;
while ( *((_BYTE *)v31 + v10) );
sub_14003A930(Block, v31, v10);
v32 = cocos2d::CCString::createWithFormat("%i", v5);
cocos2d::CCDictionary::setObject(m_onlineStars, v32, Block);
if ( *((_QWORD *)&v37 + 1) > 0xFu )
{
v33 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v37 + 1) + 1LL) >= 0x1000 )
{
v33 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v33 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v33);
}
}
GameStatsManager::incrementStat(a1, "13", v20);
}
}
if ( *((_QWORD *)&v39 + 1) > 0xFu )
{
v34 = v38[0];
if ( (unsigned __int64)(*((_QWORD *)&v39 + 1) + 1LL) >= 0x1000 )
{
v34 = *((void **)v38[0] - 1);
if ( (unsigned __int64)((char *)v38[0] - (char *)v34 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v34);
}
}
}
}
}