//
// GameStatsManager::unlockSecretChest from 0x1401ea930 to 0x1401eaae5 (437 bytes)
//
// 2 xrefs:
// > SecretRewardsLayer::onSelectItem @ 0x1403d6552
// > ??> @ 0x1406cc69c
//
// 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
//
// Hidden C++ exception states: #wind=1
GJRewardItem *GameStatsManager::unlockSecretChest(GameStatsManager *a1, int a2)
{
__int64 v2; // rsi
GJRewardItem *v4; // rbx
int Stat; // eax
int m_chestID; // edx
int v7; // ecx
cocos2d::CCString *v8; // rax
const char *CString; // rax
size_t v10; // r8
void *v11; // rcx
void *Block[2]; // [rsp+20h] [rbp-38h] BYREF
__int128 v14; // [rsp+30h] [rbp-28h]
v2 = a2;
if ( GameStatsManager::isSecretChestUnlocked(a1, a2) )
return nullptr;
v4 = (GJRewardItem *)cocos2d::CCDictionary::objectForKey(a1->m_allTreasureRoomChests, v2);
if ( !v4 )
return nullptr;
Stat = GameStatsManager::getStat(a1, (const char *)&word_140543238);
m_chestID = v4->m_chestID;
if ( m_chestID <= 6000 )
{
if ( m_chestID <= 5000 )
{
if ( m_chestID <= 4000 )
{
if ( m_chestID <= 3000 )
{
if ( m_chestID <= 2000 )
{
v7 = 1;
if ( m_chestID > 1000 )
v7 = 5;
}
else
{
v7 = 10;
}
}
else
{
v7 = 25;
}
}
else
{
v7 = 50;
}
}
else
{
v7 = 100;
}
}
else
{
v7 = 1;
}
if ( Stat < v7 )
return nullptr;
GameStatsManager::setStat(a1, (const char *)&word_140543238, Stat - v7);
GameStatsManager::preProcessReward(a1, v4);
GameStatsManager::registerRewardsFromItem(a1, v4);
v8 = cocos2d::CCString::createWithFormat("%i", v2);
CString = cocos2d::CCString::getCString(v8);
*(_OWORD *)Block = 0;
v14 = 0;
v10 = -1;
do
++v10;
while ( CString[v10] );
sub_14003A930(Block, CString, v10);
cocos2d::CCDictionary::setObject(a1->m_treasureRoomChests, v4, Block);
if ( *((_QWORD *)&v14 + 1) > 0xFu )
{
v11 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v14 + 1) + 1LL) >= 0x1000 )
{
v11 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v11 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v11);
}
return v4;
}