//
// GameStatsManager::unlockSpecialChest from 0x7bbb18 to 0x7bbce0 (456 bytes)
//
// 12 xrefs:
// > GameManager::rewardedVideoHidden @ 0x5e849c
// > GameStatsManager::unlockGauntletChest @ 0x7bbd30
// > GameStatsManager::unlockPathChest @ 0x7bbec4
// > GameStatsManager::unlockOnlineChest @ 0x7c593c
// > SupportLayer::onGetReward @ 0x7db4f0
// > GJShopLayer::dialogClosed @ 0x92c0c0
// > SecretLayer3::onChest01 @ 0x93ac6c
// > SecretLayer3::onChest02 @ 0x93ade0
// > SecretLayer4::onChest01 @ 0x94688c
// > FollowRewardPage::onSpecialItem @ 0x965298
// > SecretRewardsLayer::onSpecialItem @ 0xa618f8
// > ??> @ 0xc4a28
//
// 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::unlockSpecialChest(GameStatsManager *a1)
{
int isSpecialChestUnlocked; // w24
char *v3; // x0
GJRewardItem *RewardForSpecialChest; // x19
char *v5; // x0
unsigned int *v7; // x1
int v8; // w2
unsigned int *v9; // x1
int v10; // w2
std::string v11; // [xsp+50h] [xbp+50h] BYREF
sub_D18D28(&v11);
isSpecialChestUnlocked = (unsigned __int8)GameStatsManager::isSpecialChestUnlocked((__int64)a1, (char **)&v11);
v3 = (char *)v11.m_data.m_data - 24;
if ( (__int64 *)v11.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v7 = (unsigned int *)((char *)v11.m_data.m_data - 8);
do
v8 = __ldaxr(v7);
while ( __stlxr(v8 - 1, v7) );
}
else
{
v8 = *((_DWORD *)v11.m_data.m_data - 2);
*((_DWORD *)v11.m_data.m_data - 2) = v8 - 1;
}
if ( v8 <= 0 )
operator delete(v3);
}
if ( isSpecialChestUnlocked )
return nullptr;
sub_D18D28(&v11);
RewardForSpecialChest = (GJRewardItem *)GameStatsManager::getRewardForSpecialChest((__int64)a1, &v11);
v5 = (char *)v11.m_data.m_data - 24;
if ( (__int64 *)v11.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v9 = (unsigned int *)((char *)v11.m_data.m_data - 8);
do
v10 = __ldaxr(v9);
while ( __stlxr(v10 - 1, v9) );
}
else
{
v10 = *((_DWORD *)v11.m_data.m_data - 2);
*((_DWORD *)v11.m_data.m_data - 2) = v10 - 1;
}
if ( v10 <= 0 )
operator delete(v5);
}
if ( !RewardForSpecialChest )
return nullptr;
GameStatsManager::preProcessReward(a1, RewardForSpecialChest);
GameStatsManager::registerRewardsFromItem(a1, RewardForSpecialChest);
cocos2d::CCDictionary::setObject((int)a1->m_miscChests, RewardForSpecialChest);
return RewardForSpecialChest;
}