//
// GameStatsManager::getTotalCollectedDiamonds from 0x7a51e4 to 0x7a54dc (760 bytes)
//
// 2 xrefs:
// > GameStatsManager::recountSpecialStats @ 0x7bd628
// > ??> @ 0xbc448
//
// 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
//
int GameStatsManager::getTotalCollectedDiamonds(GameStatsManager *a1)
{
cocos2d::CCDictionary *m_challengeDiamonds; // x0
cocos2d::CCDictElement *m_pElements; // x0
cocos2d::CCDictElement *next; // x20
int v5; // w19
cocos2d::CCDictionary *m_completedLists; // x0
cocos2d::CCDictElement *v7; // x0
cocos2d::CCDictElement *i; // x20
cocos2d::CCDictionary *m_gauntletDiamondScores; // x28
cocos2d::CCDictionary *m_onlineStars; // x0
unsigned int v11; // w21
cocos2d::CCArray *v12; // x25
cocos2d::CCString *v13; // x0
char *CString; // x0
cocos2d::CCString *v15; // x0
int v16; // w20
cocos2d::CCString *v17; // x0
__int64 v18; // x2
char *v19; // x0
float BaseDiamonds; // s1
char *v21; // x0
unsigned int *v23; // x1
int v24; // w2
unsigned int *v25; // x1
int v26; // w3
_QWORD v27[16]; // [xsp+0h] [xbp+0h] BYREF
__int64 v28; // [xsp+80h] [xbp+80h]
int v29; // [xsp+8Ch] [xbp+8Ch]
char *v30; // [xsp+90h] [xbp+90h]
cocos2d::CCDictionary *j; // [xsp+98h] [xbp+98h]
char v32; // [xsp+A8h] [xbp+A8h] BYREF
char v33; // [xsp+B0h] [xbp+B0h] BYREF
std::string v34; // [xsp+B8h] [xbp+B8h] BYREF
std::string v35; // [xsp+C0h] [xbp+C0h] BYREF
m_challengeDiamonds = a1->m_challengeDiamonds;
if ( m_challengeDiamonds && (m_pElements = m_challengeDiamonds->m_pElements) != nullptr )
{
next = (cocos2d::CCDictElement *)m_pElements->hh.next;
v5 = 0;
while ( 1 )
{
v5 += cocos2d::CCString::intValue((cocos2d::CCString *)m_pElements->m_pObject);
if ( !next )
break;
m_pElements = next;
next = (cocos2d::CCDictElement *)next->hh.next;
}
}
else
{
v5 = 0;
}
m_completedLists = a1->m_completedLists;
if ( m_completedLists )
{
v7 = m_completedLists->m_pElements;
if ( v7 )
{
for ( i = (cocos2d::CCDictElement *)v7->hh.next; ; i = (cocos2d::CCDictElement *)i->hh.next )
{
v5 += cocos2d::CCString::intValue((cocos2d::CCString *)v7->m_pObject);
if ( !i )
break;
v7 = i;
}
}
}
v30 = &v32;
m_gauntletDiamondScores = a1->m_gauntletDiamondScores;
v27[15] = &v33;
m_onlineStars = a1->m_onlineStars;
v29 = 0;
for ( j = m_onlineStars; ; j = a1->m_timelyStars )
{
v11 = 0;
v12 = cocos2d::CCDictionary::allKeys(m_gauntletDiamondScores);
if ( (unsigned int)cocos2d::CCArray::count(v12) )
{
do
{
v13 = cocos2d::CCArray::stringAtIndex(v12, v11);
CString = (char *)cocos2d::CCString::getCString(v13);
sub_D153B8((unsigned int)v27 + 184, CString);
v15 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(m_gauntletDiamondScores, &v34);
v16 = cocos2d::CCString::intValue(v15);
sub_D153B8((int)&v35, (char *)v34.m_data.m_data);
v17 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(j, &v35);
v18 = (unsigned int)cocos2d::CCString::intValue(v17);
v19 = (char *)v35.m_data.m_data - 24;
if ( (__int64 *)v35.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v25 = (unsigned int *)((char *)v35.m_data.m_data - 8);
do
v26 = __ldaxr(v25);
while ( __stlxr(v26 - 1, v25) );
}
else
{
v26 = *((_DWORD *)v35.m_data.m_data - 2);
*((_DWORD *)v35.m_data.m_data - 2) = v26 - 1;
}
if ( v26 <= 0 )
{
v28 = v18;
operator delete(v19);
LODWORD(v18) = v28;
}
}
BaseDiamonds = (float)GameStatsManager::getBaseDiamonds(a1, v18);
v21 = (char *)v34.m_data.m_data - 24;
v5 = (int)(float)((float)v5 + floorf(BaseDiamonds * (float)((float)v16 / 100.0)));
if ( (__int64 *)v34.m_data.m_data - 3 == &qword_124B6B0 )
goto LABEL_15;
if ( &pthread_create )
{
v23 = (unsigned int *)((char *)v34.m_data.m_data - 8);
do
v24 = __ldaxr(v23);
while ( __stlxr(v24 - 1, v23) );
}
else
{
v24 = *((_DWORD *)v34.m_data.m_data - 2);
*((_DWORD *)v34.m_data.m_data - 2) = v24 - 1;
}
if ( v24 > 0 )
{
LABEL_15:
++v11;
}
else
{
++v11;
operator delete(v21);
}
}
while ( v11 < (unsigned int)cocos2d::CCArray::count(v12) );
}
if ( v29 )
break;
v29 = 1;
m_gauntletDiamondScores = a1->m_timelyDiamondScores;
}
return v5;
}