//
// GameStatsManager::unlockSecretChest from 0x10008c0e0 to 0x10008c28a (426 bytes)
//
// 1 xrefs:
// > SecretRewardsLayer::onSelectItem @ 0x1006348b9
//
// 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::unlockSecretChest(GameStatsManager *a1, int a2)
{
double v2; // xmm0_8
cocos2d::CCObject *v3; // rax
GJRewardItem *v4; // rbx
int Stat; // eax
int m_chestID; // ecx
int v7; // edx
bool v8; // cc
int v9; // eax
cocos2d::CCDictionary *m_treasureRoomChests; // r15
cocos2d::CCString *v12; // rax
const char *CString; // r12
size_t v14; // rax
size_t v15; // r14
char *v16; // r13
size_t v17; // r15
char v18; // [rsp+0h] [rbp-50h]
cocos2d::CCDictionary *v19; // [rsp+8h] [rbp-48h]
_QWORD __dst[2]; // [rsp+10h] [rbp-40h] BYREF
void *__p; // [rsp+20h] [rbp-30h]
if ( GameStatsManager::isSecretChestUnlocked(a1, a2) )
return nullptr;
v3 = cocos2d::CCDictionary::objectForKey(a1->m_allTreasureRoomChests, a2);
if ( !v3 )
return nullptr;
v4 = (GJRewardItem *)v3;
Stat = GameStatsManager::getStat(a1, "21");
m_chestID = v4->m_chestID;
v7 = 1;
if ( m_chestID <= 6000 )
{
v7 = 100;
if ( m_chestID <= 5000 )
{
v7 = 50;
if ( m_chestID <= 4000 )
{
v7 = 25;
if ( m_chestID <= 3000 )
{
v7 = 10;
if ( m_chestID <= 2000 )
v7 = 4 * (m_chestID >= 1001) + 1;
}
}
}
}
v8 = Stat < v7;
v9 = Stat - v7;
if ( v8 )
return nullptr;
GameStatsManager::setStat(a1, "21", v9);
GameStatsManager::preProcessReward(a1, v4);
GameStatsManager::registerRewardsFromItem(a1, v4);
m_treasureRoomChests = a1->m_treasureRoomChests;
v12 = (cocos2d::CCString *)sub_1007AB580("%i", v18);
CString = cocos2d::CCString::getCString(v12);
v14 = strlen(CString);
if ( v14 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100006BF0(v2);
v15 = v14;
if ( v14 >= 0x17 )
{
v19 = m_treasureRoomChests;
v17 = 26;
if ( (v14 | 7) != 0x17 )
v17 = (v14 | 7) + 1;
v16 = (char *)operator new(v17);
__p = v16;
__dst[0] = v17 + 1;
m_treasureRoomChests = v19;
__dst[1] = v15;
goto LABEL_19;
}
LOBYTE(__dst[0]) = 2 * v14;
v16 = (char *)__dst + 1;
if ( v14 )
LABEL_19:
memmove(v16, CString, v15);
v16[v15] = 0;
cocos2d::CCDictionary::setObject_1(m_treasureRoomChests, v4, __dst);
if ( (__dst[0] & 1) != 0 )
operator delete(__p);
return v4;
}