//
// GameStatsManager::unlockOnlineChest from 0x7c58f8 to 0x7c5ab8 (448 bytes)
//
// 3 xrefs:
// > GameStatsManager::completedDailyLevel @ 0x7c5ce8
// > SecretLayer5::claimOnlineReward @ 0xa92648
// > ??> @ 0x355e0
//
// 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
//
GJRewardItem *__fastcall GameStatsManager::unlockOnlineChest(GameStatsManager *a1)
{
GJRewardItem *v2; // x22
void *v3; // x0
cocos2d::CCDictionary *m_wraithChests; // x25
cocos2d::CCObject *v5; // x0
void *v6; // x0
unsigned int *v8; // x1
int v9; // w2
unsigned int *v10; // x20
int v11; // w1
__int64 v12; // [xsp+60h] [xbp+60h] BYREF
sub_D18D28(&v12);
v2 = GameStatsManager::unlockSpecialChest(a1);
v3 = (void *)(v12 - 24);
if ( (__int64 *)(v12 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v8 = (unsigned int *)(v12 - 8);
do
v9 = __ldaxr(v8);
while ( __stlxr(v9 - 1, v8) );
}
else
{
v9 = *(_DWORD *)(v12 - 8);
*(_DWORD *)(v12 - 8) = v9 - 1;
}
if ( v9 <= 0 )
operator delete(v3);
}
if ( v2 )
{
m_wraithChests = a1->m_wraithChests;
v5 = (cocos2d::CCObject *)cocos2d::CCString::createWithFormat((cocos2d::CCString *)"%i", (const char *)&dword_0 + 1);
cocos2d::CCDictionary::setObject((int)m_wraithChests, v5);
sub_D18D28(&v12);
GameStatsManager::linkSpecialChestUnlocks(a1, (__int64)v2, (cocos2d::CCString *)&v12);
v6 = (void *)(v12 - 24);
if ( (__int64 *)(v12 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v10 = (unsigned int *)(v12 - 8);
do
v11 = __ldaxr(v10);
while ( __stlxr(v11 - 1, v10) );
}
else
{
v11 = *(_DWORD *)(v12 - 8);
*(_DWORD *)(v12 - 8) = v11 - 1;
}
if ( v11 <= 0 )
operator delete(v6);
}
}
return v2;
}