//
// GameStatsManager::unlockGoldChest from 0x10008c2d0 to 0x10008c426 (342 bytes)
//
// 1 xrefs:
// > SecretRewardsLayer::onGoldChest @ 0x100632576
//
// 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::unlockGoldChest(GameStatsManager *a1, int a2)
{
double v2; // xmm0_8
cocos2d::CCObject *v3; // rax
GJRewardItem *v4; // rbx
int Stat; // eax
cocos2d::CCDictionary *m_treasureRoomChests; // r14
cocos2d::CCString *v7; // rax
const char *CString; // r12
size_t v9; // rax
size_t v10; // r15
char *v11; // r13
size_t v13; // r14
char v14; // [rsp+0h] [rbp-50h]
cocos2d::CCDictionary *v15; // [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, "43");
if ( Stat <= 0 )
return nullptr;
GameStatsManager::setStat(a1, "43", Stat - 1);
GameStatsManager::preProcessReward(a1, v4);
GameStatsManager::registerRewardsFromItem(a1, v4);
m_treasureRoomChests = a1->m_treasureRoomChests;
v7 = (cocos2d::CCString *)sub_1007AB580("%i", v14);
CString = cocos2d::CCString::getCString(v7);
v9 = strlen(CString);
if ( v9 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100006BF0(v2);
v10 = v9;
if ( v9 >= 0x17 )
{
v15 = m_treasureRoomChests;
v13 = 26;
if ( (v9 | 7) != 0x17 )
v13 = (v9 | 7) + 1;
v11 = (char *)operator new(v13);
__p = v11;
__dst[0] = v13 + 1;
m_treasureRoomChests = v15;
__dst[1] = v10;
goto LABEL_13;
}
LOBYTE(__dst[0]) = 2 * v9;
v11 = (char *)__dst + 1;
if ( v9 )
LABEL_13:
memmove(v11, CString, v10);
v11[v10] = 0;
cocos2d::CCDictionary::setObject_1(m_treasureRoomChests, v4, __dst);
if ( (__dst[0] & 1) != 0 )
operator delete(__p);
return v4;
}