//
// GameStatsManager::createReward from 0x7aecd0 to 0x7aef08 (568 bytes)
//
// 3 xrefs:
// > GameLevelManager::onGetGJSecretRewardCompleted @ 0x6fce9c
// > GameLevelManager::onGetGJDailyLevelStateCompleted @ 0x6ff1e4
// > ??> @ 0xb5b48
//
// 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::createReward(int a1, GJRewardType a2, int a3, _QWORD *a4)
{
cocos2d::CCArray *v6; // x0
__int64 v7; // x0
const char **v8; // x20
cocos2d::CCArray *v9; // x23
_BYTE *v10; // x22
__int64 v11; // x21
unsigned __int64 v12; // x19
SpecialRewardItem v13; // w27
int v14; // w1
GJRewardObject *ItemUnlock; // x0
GJRewardItem *v16; // x22
__int64 *v17; // x19
__int64 *v18; // x20
__int64 v19; // x1
__int64 *v20; // x0
unsigned int *v21; // x1
int v22; // w2
void *v24; // [xsp+70h] [xbp+70h] BYREF
void *p; // [xsp+78h] [xbp+78h]
__int64 v26; // [xsp+80h] [xbp+80h]
v24 = nullptr;
p = nullptr;
v26 = 0;
v6 = (cocos2d::CCArray *)sub_7AEA8C(a4, &byte_F804F8, (__int64)&v24);
v7 = cocos2d::CCArray::create(v6);
v8 = (const char **)v24;
v9 = (cocos2d::CCArray *)v7;
v10 = p;
v11 = 1;
v12 = 0;
if ( ((_BYTE *)p - (_BYTE *)v24) >> 3 != 1 )
{
do
{
while ( 1 )
{
v13 = atoi(v8[v12]);
v14 = atoi(v8[v11]);
if ( v13 <= 1000 )
break;
ItemUnlock = GJRewardObject::createItemUnlock((UnlockType)(v13 - 1000), v14);
LABEL_8:
if ( ItemUnlock )
cocos2d::CCArray::addObject(v9, ItemUnlock);
v8 = (const char **)v24;
v12 += 2LL;
v10 = p;
v11 += 2;
if ( (((_BYTE *)p - (_BYTE *)v24) >> 3) - 1 <= v12 )
goto LABEL_11;
}
if ( (unsigned int)(v13 - 1) <= 0xE && v13 != CustomItem )
{
ItemUnlock = GJRewardObject::create(v13, v14, 0);
goto LABEL_8;
}
v12 += 2LL;
v11 += 2;
}
while ( ((v10 - (_BYTE *)v8) >> 3) - 1 > v12 );
}
LABEL_11:
if ( (unsigned int)cocos2d::CCArray::count(v9) )
{
v16 = GJRewardItem::createWithObjects(a2, v9);
v16->m_chestID = a3;
}
else
{
v16 = nullptr;
}
v17 = (__int64 *)v24;
v18 = (__int64 *)p;
if ( v24 != p )
{
do
{
while ( 1 )
{
v19 = *v17;
v20 = (__int64 *)(*v17 - 24);
if ( v20 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v21 = (unsigned int *)(v19 - 8);
do
v22 = __ldaxr(v21);
while ( __stlxr(v22 - 1, v21) );
}
else
{
v22 = *(_DWORD *)(v19 - 8);
*(_DWORD *)(v19 - 8) = v22 - 1;
}
if ( v22 <= 0 )
break;
}
if ( v18 == ++v17 )
goto LABEL_22;
}
++v17;
operator delete(v20);
}
while ( v18 != v17 );
LABEL_22:
v18 = (__int64 *)v24;
}
if ( v18 )
operator delete(v18);
return v16;
}