//
// GameStatsManager::getTotalCollectedDiamonds from 0x1401e4150 to 0x1401e444b (763 bytes)
//
// 2 xrefs:
// > GameStatsManager::recountSpecialStats @ 0x1401e4553
// > ??> @ 0x1406cc5d0
//
// 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
int GameStatsManager::getTotalCollectedDiamonds(GameStatsManager *a1)
{
int v2; // esi
cocos2d::CCDictionary *m_challengeDiamonds; // rcx
cocos2d::CCDictElement *m_pElements; // rcx
cocos2d::CCDictElement *i; // rbx
cocos2d::CCDictionary *m_completedLists; // rcx
cocos2d::CCDictElement *v7; // rcx
cocos2d::CCDictElement *j; // rbx
int k; // r12d
cocos2d::CCDictionary *m_timelyDiamondScores; // r13
cocos2d::CCDictionary *m_timelyStars; // rbx
cocos2d::CCArray *v12; // rbp
unsigned int m; // edi
cocos2d::CCString *v14; // rax
const char *CString; // rax
size_t v16; // r8
cocos2d::CCString *v17; // rax
int v18; // r14d
__int128 *v19; // rdx
size_t v20; // r8
cocos2d::CCString *v21; // rax
int v22; // ebx
void *v23; // rcx
int v24; // eax
void *v25; // rcx
cocos2d::CCDictionary *v27; // [rsp+20h] [rbp-88h]
__int128 v28; // [rsp+28h] [rbp-80h] BYREF
__int64 v29; // [rsp+38h] [rbp-70h]
unsigned __int64 v30; // [rsp+40h] [rbp-68h]
__int128 v31; // [rsp+48h] [rbp-60h] BYREF
__int64 v32; // [rsp+58h] [rbp-50h]
unsigned __int64 v33; // [rsp+60h] [rbp-48h]
v2 = 0;
m_challengeDiamonds = a1->m_challengeDiamonds;
if ( m_challengeDiamonds )
{
m_pElements = m_challengeDiamonds->m_pElements;
if ( m_pElements )
{
for ( i = (cocos2d::CCDictElement *)m_pElements->hh.next; ; i = (cocos2d::CCDictElement *)i->hh.next )
{
v2 += cocos2d::CCString::intValue((cocos2d::CCString *)m_pElements->m_pObject);
m_pElements = i;
if ( !i )
break;
}
}
}
m_completedLists = a1->m_completedLists;
if ( m_completedLists )
{
v7 = m_completedLists->m_pElements;
if ( v7 )
{
for ( j = (cocos2d::CCDictElement *)v7->hh.next; ; j = (cocos2d::CCDictElement *)j->hh.next )
{
v2 += cocos2d::CCString::intValue((cocos2d::CCString *)v7->m_pObject);
v7 = j;
if ( !j )
break;
}
}
}
for ( k = 0; k < 2; ++k )
{
if ( k )
{
m_timelyDiamondScores = a1->m_timelyDiamondScores;
m_timelyStars = a1->m_timelyStars;
}
else
{
m_timelyDiamondScores = a1->m_gauntletDiamondScores;
m_timelyStars = a1->m_onlineStars;
}
v27 = m_timelyStars;
v12 = cocos2d::CCDictionary::allKeys(m_timelyDiamondScores);
for ( m = 0; m < cocos2d::CCArray::count(v12); m_timelyStars = v27 )
{
v14 = cocos2d::CCArray::stringAtIndex(v12, m);
CString = cocos2d::CCString::getCString(v14);
v28 = 0;
v29 = 0;
v30 = 0;
v16 = -1;
do
++v16;
while ( CString[v16] );
sub_14003A930(&v28, CString, v16);
v17 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(m_timelyDiamondScores, &v28);
v18 = cocos2d::CCString::intValue(v17);
v19 = &v28;
if ( v30 > 0xF )
v19 = (__int128 *)v28;
v31 = 0;
v32 = 0;
v33 = 0;
v20 = -1;
do
++v20;
while ( *((_BYTE *)v19 + v20) );
sub_14003A930(&v31, v19, v20);
v21 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(m_timelyStars, &v31);
v22 = cocos2d::CCString::intValue(v21);
if ( v33 > 0xF )
{
v23 = (void *)v31;
if ( v33 + 1 >= 0x1000 )
{
v23 = *(void **)(v31 - 8);
if ( (unsigned __int64)(v31 - (_QWORD)v23 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v23);
}
if ( (unsigned int)(v22 - 2) > 8 )
v24 = 0;
else
v24 = v22 + 2;
v2 = (int)(float)(floorf((float)((float)v18 / 100.0) * (float)v24) + (float)v2);
if ( v30 > 0xF )
{
v25 = (void *)v28;
if ( v30 + 1 >= 0x1000 )
{
v25 = *(void **)(v28 - 8);
if ( (unsigned __int64)(v28 - (_QWORD)v25 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v25);
}
++m;
}
}
return v2;
}