//
// SecretRewardsLayer::onGoldChest from 0x14056ce20 to 0x14056d519 (1785 bytes)
//
// 2 xrefs:
// > SecretRewardsLayer::init @ 0x14056952b
// > ??> @ 0x14092c6cc
//
// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 11:34:20 +0000
//
// Hidden C++ exception states: #wind=8
void __fastcall SecretRewardsLayer::onGoldChest(cocos2d::CCNode *a1)
{
__int64 v2; // rcx
int Stat; // esi
__int64 v4; // rdi
int v5; // ebx
__int64 v6; // rsi
struct cocos2d::CCObject *v7; // rdi
int v8; // eax
cocos2d::CCString *v9; // rax
const char *CString; // rax
size_t v11; // r8
void *v12; // rcx
_QWORD *v13; // rbx
cocos2d::CCObject *v14; // rcx
__int64 v15; // rcx
void (__fastcall **v16)(__int64, const char *); // rdi
__int64 v17; // rbx
unsigned int v18; // eax
cocos2d::CCString *v19; // rax
const char *v20; // rax
__int64 v21; // rcx
__int64 v22; // rbx
struct cocos2d::CCFiniteTimeAction *v23; // rax
struct cocos2d::CCAction *v24; // rax
int v25; // edi
char *v26; // rax
int v27; // esi
char *v28; // r14
__int64 v29; // rdi
__int64 v30; // rbx
void **v31; // rax
cocos2d::CCLayerColor *DialogLayer; // rsi
__int64 v33; // rcx
__int64 v34; // rax
__int64 v35; // rdi
__int64 v36; // rbx
__int64 v37; // rax
void *v38; // rcx
__int128 *v39; // [rsp+30h] [rbp-49h] BYREF
__int16 v40; // [rsp+40h] [rbp-39h] BYREF
char v41; // [rsp+42h] [rbp-37h]
__int128 v42; // [rsp+50h] [rbp-29h] BYREF
__int64 v43; // [rsp+60h] [rbp-19h]
__int64 v44; // [rsp+68h] [rbp-11h]
char v45[8]; // [rsp+70h] [rbp-9h] BYREF
void *Block[2]; // [rsp+78h] [rbp-1h] BYREF
__int64 v47; // [rsp+88h] [rbp+Fh]
unsigned __int64 v48; // [rsp+90h] [rbp+17h]
void *v49[2]; // [rsp+98h] [rbp+1Fh]
__int64 v50; // [rsp+A8h] [rbp+2Fh]
unsigned __int64 v51; // [rsp+B0h] [rbp+37h]
v2 = qword_14090BFE0;
if ( !qword_14090BFE0 )
{
v39 = (__int128 *)operator new(0x3E8u);
qword_14090BFE0 = sub_1402D6480((__int64)v39);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFE0 + 72LL))(qword_14090BFE0);
v2 = qword_14090BFE0;
}
Stat = GameStatsManager::getStat(v2, &word_1407380E4);
v4 = qword_14090BFE0;
if ( !qword_14090BFE0 )
{
v39 = (__int128 *)operator new(0x3E8u);
qword_14090BFE0 = sub_1402D6480((__int64)v39);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFE0 + 72LL))(qword_14090BFE0);
v4 = qword_14090BFE0;
}
v5 = 6001;
while ( GameStatsManager::isSecretChestUnlocked(v4) )
{
if ( ++v5 - 6001 >= 30 )
{
v5 = 0;
break;
}
}
if ( Stat >= 1 && v5 )
{
v6 = qword_14090BFE0;
if ( !qword_14090BFE0 )
{
v39 = (__int128 *)operator new(0x3E8u);
qword_14090BFE0 = sub_1402D6480((__int64)v39);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFE0 + 72LL))(qword_14090BFE0);
v6 = qword_14090BFE0;
}
if ( !GameStatsManager::isSecretChestUnlocked(v6) )
{
v7 = cocos2d::CCDictionary::objectForKey(*(cocos2d::CCDictionary **)(v6 + 352), v5);
if ( v7 )
{
v8 = GameStatsManager::getStat(v6, &word_1407380E4);
if ( v8 >= 1 )
{
GameStatsManager::setStat(v6, &word_1407380E4, v8 - 1);
GameStatsManager::preProcessReward(v6, (__int64)v7);
GameStatsManager::registerRewardsFromItem(v6, (__int64)v7);
v9 = cocos2d::CCString::createWithFormat((const char *)&word_1406ED6F8, (unsigned int)v5);
CString = cocos2d::CCString::getCString(v9);
*(_OWORD *)Block = 0;
v47 = 0;
v48 = 0;
v11 = -1;
do
++v11;
while ( CString[v11] );
sub_14003D230(Block, CString, v11);
cocos2d::CCDictionary::setObject(*(_QWORD *)(v6 + 864), v7, Block);
if ( v48 > 0xF )
{
v12 = Block[0];
if ( v48 + 1 >= 0x1000 )
{
v12 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v12 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v12);
}
v13 = RewardUnlockLayer::create(*((_DWORD *)v7 + 16), 0);
(*(void (__fastcall **)(cocos2d::CCNode *, _QWORD *, __int64))(*(_QWORD *)a1 + 456LL))(a1, v13, 100);
v14 = (cocos2d::CCObject *)v13[88];
if ( v14 )
cocos2d::CCObject::release(v14);
v13[88] = v7;
cocos2d::CCObject::retain(v7);
if ( !*((_BYTE *)v7 + 80) || *((_DWORD *)v7 + 16) == *((_DWORD *)v13 + 174) )
{
(*(void (__fastcall **)(_QWORD, _QWORD))(*(_QWORD *)v13[90] + 336LL))(v13[90], 0);
(*(void (__fastcall **)(_QWORD, _QWORD))(*(_QWORD *)v13[90] + 936LL))(v13[90], 0);
(*(void (__fastcall **)(_QWORD, _QWORD))(*(_QWORD *)v13[89] + 336LL))(v13[89], 0);
*((_BYTE *)v13 + 700) = 1;
if ( *((_BYTE *)v13 + 701) )
RewardUnlockLayer::playRewardEffect((cocos2d::CCNode *)v13);
}
v15 = qword_14090BFE0;
if ( !qword_14090BFE0 )
{
v39 = (__int128 *)operator new(0x3E8u);
qword_14090BFE0 = sub_1402D6480((__int64)v39);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFE0 + 72LL))(qword_14090BFE0);
v15 = qword_14090BFE0;
}
v16 = *(void (__fastcall ***)(__int64, const char *))(*((_QWORD *)a1 + 60) + 360LL);
v17 = *((_QWORD *)a1 + 60);
v18 = GameStatsManager::getStat(v15, &word_1407380E4);
v19 = cocos2d::CCString::createWithFormat((const char *)&word_1406ED6F8, v18);
v20 = cocos2d::CCString::getCString(v19);
(*v16)(v17 + 360, v20);
SecretRewardsLayer::updateUnlockedGoldLabel(a1);
v21 = qword_14090BF60;
if ( !qword_14090BF60 )
{
v39 = (__int128 *)operator new(0x8A8u);
qword_14090BF60 = FMODAudioEngine::FMODAudioEngine((__int64)v39);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BF60 + 72LL))(qword_14090BF60);
v21 = qword_14090BF60;
}
FMODAudioEngine::fadeMusic(v21, 1.0);
v22 = cocos2d::CCCallFunc::create(a1, SecretRewardsLayer::fadeInOutMusic);
v23 = cocos2d::CCDelayTime::create(3.2);
v24 = cocos2d::CCSequence::create(v23, v22, 0);
cocos2d::CCNode::runAction(a1, v24);
}
}
}
}
else
{
v25 = 1 - Stat;
*(_OWORD *)v49 = 0;
v50 = 0;
LOBYTE(v49[0]) = 0;
v26 = (char *)sub_14003D460(0x40u);
v51 = 63;
if ( v5 )
{
v50 = 57;
strcpy(v26, "You need a Gold Key to unlock this chest.");
}
else
{
v50 = 58;
strcpy(v26, "All out of Gold Chests right now. Come back later.");
}
v49[0] = v26;
if ( v25 <= 50 )
{
if ( v25 <= 25 )
{
v27 = 2;
if ( v25 > 10 )
v27 = 4;
}
else
{
v27 = 17;
}
}
else
{
v27 = 18;
}
v39 = &v42;
v40 = -1;
v41 = -1;
v42 = 0;
v43 = 0;
v44 = 0;
v28 = v26;
v29 = v50;
v30 = 0x7FFFFFFFFFFFFFFFLL;
if ( (v50 | 0xFuLL) <= 0x7FFFFFFFFFFFFFFFLL )
{
v30 = v50 | 0xF;
if ( (v50 | 0xFuLL) < 0x16 )
v30 = 22;
}
*(_QWORD *)&v42 = sub_14003D460(v30 + 1);
v43 = v29;
v44 = v30;
memcpy((void *)v42, v28, v29 + 1);
v47 = 13;
v48 = 15;
strcpy((char *)Block, "The Keymaster");
HIWORD(Block[1]) = 0;
v31 = DialogObject::create((__int64)Block, (__int64)&v42, v27, 1.0, 0, (__int64)&v40);
DialogLayer = DialogLayer::createDialogLayer((__int64)v31, 0, 2u);
DialogLayer::addToMainScene((__int64)DialogLayer);
v34 = cocos2d::CCDirector::sharedDirector(v33);
cocos2d::CCDirector::getWinSize(v34, &v39);
v35 = **((_QWORD **)DialogLayer + 70);
v36 = *((_QWORD *)DialogLayer + 70);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)v45, *(float *)&v39 * 0.5, *((float *)&v39 + 1) * 0.5);
(*(void (__fastcall **)(__int64, __int64))(v35 + 184))(v36, v37);
DialogLayer::animateInRandomSide(DialogLayer);
if ( v51 > 0xF )
{
v38 = v49[0];
if ( v51 + 1 >= 0x1000 )
{
v38 = *((void **)v49[0] - 1);
if ( (unsigned __int64)((char *)v49[0] - (char *)v38 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v38);
}
}
}