//
// GameStatsManager::getTotalCollectedDiamonds from 0x1402e7be0 to 0x1402e7eec (780 bytes)
//
// 2 xrefs:
// > GameStatsManager::recountSpecialStats @ 0x1402e7ff8
// > ??> @ 0x14091e05c
//
// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 11:29:50 +0000
//
// Hidden C++ exception states: #wind=2
__int64 __fastcall GameStatsManager::getTotalCollectedDiamonds(__int64 a1)
{
__int64 v1; // rdi
int v2; // esi
__int64 v3; // rcx
__int64 v4; // rcx
__int64 i; // rbx
__int64 v6; // rcx
__int64 v7; // rcx
__int64 j; // rbx
int v9; // r15d
__int64 v10; // rax
cocos2d::CCDictionary *v11; // r13
__int64 v12; // rax
__int64 v13; // r12
cocos2d::CCArray *v14; // r14
unsigned int k; // edi
cocos2d::CCString *v16; // rax
const char *CString; // rax
size_t v18; // r8
cocos2d::CCString *v19; // rax
int v20; // ebp
__int128 *v21; // rdx
size_t v22; // r8
cocos2d::CCString *v23; // rax
int v24; // ebx
void *v25; // rcx
int v26; // eax
void *v27; // rcx
__int128 v30; // [rsp+38h] [rbp-80h] BYREF
__int128 v31; // [rsp+48h] [rbp-70h]
__int128 v32; // [rsp+58h] [rbp-60h] BYREF
__int128 v33; // [rsp+68h] [rbp-50h]
v1 = a1;
v2 = 0;
v3 = *(_QWORD *)(a1 + 816);
if ( v3 )
{
v4 = *(_QWORD *)(v3 + 56);
if ( v4 )
{
for ( i = *(_QWORD *)(v4 + 288); ; i = *(_QWORD *)(i + 288) )
{
v2 += cocos2d::CCString::intValue(*(cocos2d::CCString **)(v4 + 264));
v4 = i;
if ( !i )
break;
}
}
}
v6 = *(_QWORD *)(v1 + 832);
if ( v6 )
{
v7 = *(_QWORD *)(v6 + 56);
if ( v7 )
{
for ( j = *(_QWORD *)(v7 + 288); ; j = *(_QWORD *)(j + 288) )
{
v2 += cocos2d::CCString::intValue(*(cocos2d::CCString **)(v7 + 264));
v7 = j;
if ( !j )
break;
}
}
}
v9 = 0;
while ( 1 )
{
v10 = 792;
if ( v9 )
v10 = 800;
v11 = *(cocos2d::CCDictionary **)(v10 + v1);
v12 = 776;
if ( v9 )
v12 = 784;
v13 = *(_QWORD *)(v12 + v1);
v14 = cocos2d::CCDictionary::allKeys(v11);
for ( k = 0; k < cocos2d::CCArray::count(v14); ++k )
{
v16 = cocos2d::CCArray::stringAtIndex(v14, k);
CString = cocos2d::CCString::getCString(v16);
v30 = 0;
v31 = 0;
v18 = -1;
do
++v18;
while ( CString[v18] );
sub_14003D230(&v30, CString, v18);
v19 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(v11, &v30);
v20 = cocos2d::CCString::intValue(v19);
v21 = &v30;
if ( *((_QWORD *)&v31 + 1) > 0xFu )
v21 = (__int128 *)v30;
v32 = 0;
v33 = 0;
v22 = -1;
do
++v22;
while ( *((_BYTE *)v21 + v22) );
sub_14003D230(&v32, v21, v22);
v23 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(v13, &v32);
v24 = cocos2d::CCString::intValue(v23);
if ( *((_QWORD *)&v33 + 1) > 0xFu )
{
v25 = (void *)v32;
if ( (unsigned __int64)(*((_QWORD *)&v33 + 1) + 1LL) >= 0x1000 )
{
v25 = *(void **)(v32 - 8);
if ( (unsigned __int64)(v32 - (_QWORD)v25 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v25);
}
if ( (unsigned int)(v24 - 2) > 8 )
v26 = 0;
else
v26 = v24 + 2;
v2 = (int)(float)(floorf((float)((float)v20 / 100.0) * (float)v26) + (float)v2);
if ( *((_QWORD *)&v31 + 1) > 0xFu )
{
v27 = (void *)v30;
if ( (unsigned __int64)(*((_QWORD *)&v31 + 1) + 1LL) >= 0x1000 )
{
v27 = *(void **)(v30 - 8);
if ( (unsigned __int64)(v30 - (_QWORD)v27 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v27);
}
}
if ( ++v9 >= 2 )
break;
v1 = a1;
}
return (unsigned int)v2;
}