//
// GameStatsManager::awardDiamondsForLevel from 0x52a504 to 0x52a776 (626 bytes)
//
// 2 xrefs:
// > PlayLayer::destroyPlayer @ 0x405e36
// > PlayLayer::levelComplete @ 0x4080da
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// 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:51:59 +0000
//
int __fastcall GameStatsManager::awardDiamondsForLevel(GameStatsManager *this, GJGameLevel *a2)
{
char *v2; // r11
int v5; // r5
char *v6; // r7
int BaseDiamonds; // r0
int v8; // r3
int v9; // r2
int v10; // s16
int v11; // r8
const char *v12; // r8
char *v13; // r9
size_t v14; // r0
cocos2d::CCString *v15; // r0
int v16; // r11
float v17; // s16
int v18; // r5
cocos2d::CCObject *v19; // r11
char *v20; // r1
size_t v21; // r0
int v22; // r8
size_t v23; // r0
cocos2d::CCString *v24; // r0
int v25; // r9
cocos2d::CCObject *v27; // r9
size_t v28; // r0
char *v29; // [sp+4h] [bp-48h]
unsigned __int8 v30; // [sp+8h] [bp-44h] BYREF
_BYTE v31[7]; // [sp+9h] [bp-43h] BYREF
char *v32; // [sp+10h] [bp-3Ch]
int v33[3]; // [sp+14h] [bp-38h] BYREF
int v34[3]; // [sp+20h] [bp-2Ch] BYREF
int v35[3]; // [sp+2Ch] [bp-20h] BYREF
int v36[3]; // [sp+38h] [bp-14h] BYREF
if ( *((_DWORD *)a2 + 186) - *((_DWORD *)a2 + 187) <= 0 && !*((_BYTE *)a2 + 477) )
return 0;
v6 = (char *)(*((_DWORD *)a2 + 193) - *((_DWORD *)a2 + 194));
BaseDiamonds = GameStatsManager::getBaseDiamonds(this, (int)v6);
v8 = *((_DWORD *)a2 + 172);
v9 = *((_DWORD *)a2 + 173);
v10 = BaseDiamonds;
if ( BaseDiamonds <= 0 )
return 0;
v11 = v8 - v9;
if ( v8 - v9 <= 0 )
return 0;
if ( v11 > 99 )
v12 = (const char *)&dword_64;
else
v12 = (const char *)(v11 & ~(v11 >> 31));
GameStatsManager::getCurrencyKey((GameStatsManager *)&v30, this, a2);
v13 = *((char **)this + 114);
if ( *((_DWORD *)a2 + 186) - *((_DWORD *)a2 + 187) <= 0 )
v13 = *((char **)this + 113);
if ( (v30 & 1) == 0 )
v2 = v31;
v33[0] = 0;
if ( (v30 & 1) != 0 )
v2 = v32;
v33[1] = 0;
v33[2] = 0;
v14 = strlen(v2);
std::string::__init(v33, v2, v14);
v15 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(v13, v33);
v16 = cocos2d::CCString::intValue(v15);
std::string::~string((int)v33);
if ( v16 >= (int)v12
|| (v17 = (float)v10,
v18 = (int)floorf(v17 * (float)((float)v16 / 100.0)),
v5 = (int)floorf(v17 * (float)((float)(int)v12 / 100.0)) - v18,
v5 <= 0) )
{
v5 = 0;
}
else
{
v19 = (cocos2d::CCObject *)cocos2d::CCString::createWithFormat((cocos2d::CCString *)"%i", v12);
v20 = (char *)(v30 << 31);
if ( (v30 & 1) == 0 )
v20 = v31;
v34[0] = 0;
if ( (v30 & 1) != 0 )
v20 = v32;
v34[1] = 0;
v34[2] = 0;
v29 = v20;
v21 = strlen(v20);
std::string::__init(v34, v29, v21);
cocos2d::CCDictionary::setObject((int)v13, v19);
std::string::~string((int)v34);
v22 = *((_DWORD *)this + 112);
if ( *((_DWORD *)a2 + 186) - *((_DWORD *)a2 + 187) <= 0 )
v22 = *((_DWORD *)this + 111);
if ( (v30 & 1) == 0 )
v13 = v31;
v35[0] = 0;
if ( (v30 & 1) != 0 )
v13 = v32;
v35[1] = 0;
v35[2] = 0;
v23 = strlen(v13);
std::string::__init(v35, v13, v23);
v24 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(v22, v35);
v25 = cocos2d::CCString::intValue(v24);
std::string::~string((int)v35);
if ( v25 < (int)v6 )
{
v27 = (cocos2d::CCObject *)cocos2d::CCString::createWithFormat((cocos2d::CCString *)"%i", v6);
if ( (v30 & 1) == 0 )
v6 = v31;
v36[0] = 0;
if ( (v30 & 1) != 0 )
v6 = v32;
v36[1] = 0;
v36[2] = 0;
v28 = strlen(v6);
std::string::__init(v36, v6, v28);
cocos2d::CCDictionary::setObject(v22, v27);
std::string::~string((int)v36);
}
GameStatsManager::incrementStat(this, "13", v5);
}
std::string::~string((int)&v30);
return v5;
}