//
// GameStatsManager::awardDiamondsForLevel from 0x1402e4b40 to 0x1402e504c (1292 bytes)
//
// 3 xrefs:
// > PlayLayer::levelComplete @ 0x140506d14
// > PlayLayer::destroyPlayer @ 0x140512d80
// > ??> @ 0x14091df6c
//
// 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:49 +0000
//
// Hidden C++ exception states: #wind=2
__int64 __fastcall GameStatsManager::awardDiamondsForLevel(__int64 a1, __int64 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
__int64 *v13; // rax
__int64 v14; // rbx
void **v15; // rdx
size_t v16; // r8
cocos2d::CCString *v17; // rax
int v18; // ebx
void *v19; // r8
int v20; // ebx
signed int v21; // r15d
void **v22; // rdx
size_t v23; // r8
struct cocos2d::CCString *v24; // rax
void *v25; // rcx
__int64 *v26; // rax
__int64 v27; // rsi
void **v28; // rdx
size_t v29; // r8
cocos2d::CCString *v30; // rax
int v31; // ebx
void *v32; // r8
void **v33; // rdx
struct cocos2d::CCString *v34; // rax
void *v35; // rcx
void *v36; // rcx
__int64 v38; // [rsp+30h] [rbp-39h]
void *Block[2]; // [rsp+38h] [rbp-31h] BYREF
__int128 v40; // [rsp+48h] [rbp-21h]
void *v41[2]; // [rsp+58h] [rbp-11h] BYREF
__int128 v42; // [rsp+68h] [rbp-1h]
v4 = *(_DWORD *)(a2 + 992) - *(_DWORD *)(a2 + 996);
if ( v4 <= 0 && !*(_BYTE *)(a2 + 721) )
return 0;
v5 = *(_DWORD *)(a2 + 1020) - *(_DWORD *)(a2 + 1024);
if ( (unsigned int)(v5 - 2) > 8 )
return 0;
v6 = v5 + 2;
v7 = *(_DWORD *)(a2 + 936) - *(_DWORD *)(a2 + 940);
if ( v5 + 2 <= 0 || v7 <= 0 )
return 0;
if ( v7 > 100 )
v7 = 100;
if ( v4 <= 0 )
{
v12 = cocos2d::CCString::createWithFormat(
(const char *)&word_1406ED6F8,
(unsigned int)(*(_DWORD *)(a2 + 328) - *(_DWORD *)(a2 + 332)));
CString = cocos2d::CCString::getCString(v12);
*(_OWORD *)v41 = 0;
v42 = 0;
v10 = -1;
v11 = -1;
do
++v11;
while ( CString[v11] );
}
else
{
v8 = cocos2d::CCString::createWithFormat((const char *)&word_1406ED6F8);
CString = cocos2d::CCString::getCString(v8);
*(_OWORD *)v41 = 0;
v42 = 0;
v10 = -1;
v11 = -1;
do
++v11;
while ( CString[v11] );
}
sub_14003D230(v41, CString, v11);
v13 = (__int64 *)(a1 + 800);
if ( *(_DWORD *)(a2 + 992) - *(_DWORD *)(a2 + 996) <= 0 )
v13 = (__int64 *)(a1 + 792);
v14 = *v13;
v38 = *v13;
v15 = v41;
if ( *((_QWORD *)&v42 + 1) > 0xFu )
v15 = (void **)v41[0];
*(_OWORD *)Block = 0;
v40 = 0;
v16 = -1;
do
++v16;
while ( *((_BYTE *)v15 + v16) );
sub_14003D230(Block, v15, v16);
v17 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(v14, Block);
v18 = cocos2d::CCString::intValue(v17);
if ( *((_QWORD *)&v40 + 1) > 0xFu )
{
v19 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v40 + 1) + 1LL) >= 0x1000 )
{
v19 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v19 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v19);
}
if ( v18 >= v7
|| (v20 = (int)floorf((float)((float)v18 / 100.0) * (float)v6),
v21 = (int)floorf((float)((float)v7 / 100.0) * (float)v6) - v20,
v21 <= 0) )
{
v21 = 0;
}
else
{
v22 = v41;
if ( *((_QWORD *)&v42 + 1) > 0xFu )
v22 = (void **)v41[0];
*(_OWORD *)Block = 0;
v40 = 0;
v23 = -1;
do
++v23;
while ( *((_BYTE *)v22 + v23) );
sub_14003D230(Block, v22, v23);
v24 = cocos2d::CCString::createWithFormat((const char *)&word_1406ED6F8, (unsigned int)v7);
cocos2d::CCDictionary::setObject(v38, v24, Block);
if ( *((_QWORD *)&v40 + 1) > 0xFu )
{
v25 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v40 + 1) + 1LL) >= 0x1000 )
{
v25 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v25 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v25);
}
v26 = (__int64 *)(a1 + 784);
if ( *(_DWORD *)(a2 + 992) - *(_DWORD *)(a2 + 996) <= 0 )
v26 = (__int64 *)(a1 + 776);
v27 = *v26;
v28 = v41;
if ( *((_QWORD *)&v42 + 1) > 0xFu )
v28 = (void **)v41[0];
*(_OWORD *)Block = 0;
v40 = 0;
v29 = -1;
do
++v29;
while ( *((_BYTE *)v28 + v29) );
sub_14003D230(Block, v28, v29);
v30 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(v27, Block);
v31 = cocos2d::CCString::intValue(v30);
if ( *((_QWORD *)&v40 + 1) > 0xFu )
{
v32 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v40 + 1) + 1LL) >= 0x1000 )
{
v32 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v32 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v32);
}
if ( v31 < v5 )
{
v33 = v41;
if ( *((_QWORD *)&v42 + 1) > 0xFu )
v33 = (void **)v41[0];
*(_OWORD *)Block = 0;
v40 = 0;
do
++v10;
while ( *((_BYTE *)v33 + v10) );
sub_14003D230(Block, v33, v10);
v34 = cocos2d::CCString::createWithFormat((const char *)&word_1406ED6F8, (unsigned int)v5);
cocos2d::CCDictionary::setObject(v27, v34, Block);
if ( *((_QWORD *)&v40 + 1) > 0xFu )
{
v35 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v40 + 1) + 1LL) >= 0x1000 )
{
v35 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v35 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v35);
}
}
GameStatsManager::incrementStat(a1, "13", v21);
}
if ( *((_QWORD *)&v42 + 1) > 0xFu )
{
v36 = v41[0];
if ( (unsigned __int64)(*((_QWORD *)&v42 + 1) + 1LL) >= 0x1000 )
{
v36 = *((void **)v41[0] - 1);
if ( (unsigned __int64)((char *)v41[0] - (char *)v36 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v36);
}
return (unsigned int)v21;
}