//
// SecretRewardsLayer::onSpecialItem from 0x1403d6ad0 to 0x1403d6ee7 (1047 bytes)
//
// 2 xrefs:
// > SecretRewardsLayer::onChestType @ 0x1403d507e
// > ??> @ 0x1406d7d60
//
// 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=5
void SecretRewardsLayer::onSpecialItem(SecretRewardsLayer *a1, cocos2d::CCObject *a2)
{
int v4; // eax
int v5; // eax
int v6; // eax
int v7; // eax
int v8; // edi
__int64 v9; // rcx
__int64 v10; // rcx
signed int v11; // esi
cocos2d::CCArray *v12; // rbx
int v13; // edi
const char *v14; // r8
cocos2d::CCString *v15; // rax
const char *CString; // rax
size_t v17; // r8
char *v18; // rax
DialogLayer *DialogLayer; // rdi
__int64 v20; // rcx
cocos2d::CCDirector *v21; // rax
cocos2d::CCLayer_vtbl *v22; // rbx
const cocos2d::CCPoint *v23; // rax
GameStatsManager *v24; // rcx
SecretRewardsLayer *v25; // rcx
GJRewardItem *v26; // rdi
RewardUnlockLayer *v27; // rbx
cocos2d::CCObject *m_rewardItem; // rcx
__int16 v29; // [rsp+30h] [rbp-69h] BYREF
char v30; // [rsp+32h] [rbp-67h]
__int128 *v31; // [rsp+40h] [rbp-59h]
__int128 v32; // [rsp+48h] [rbp-51h] BYREF
__int64 v33; // [rsp+58h] [rbp-41h]
__int64 v34; // [rsp+60h] [rbp-39h]
__int128 *v35; // [rsp+68h] [rbp-31h]
__int128 v36; // [rsp+70h] [rbp-29h] BYREF
__int64 v37; // [rsp+80h] [rbp-19h]
__int64 v38; // [rsp+88h] [rbp-11h]
__int128 Src; // [rsp+90h] [rbp-9h]
__int64 v40; // [rsp+A0h] [rbp+7h]
__int64 v41; // [rsp+A8h] [rbp+Fh]
v4 = a2->getTag(a2);
Src = 0;
v40 = 0;
v41 = 15;
LOBYTE(Src) = 0;
v5 = v4 - 6;
if ( v5 )
{
v6 = v5 - 1;
if ( v6 )
{
if ( v6 != 1 )
return;
v7 = *(_DWORD *)"0006";
v8 = 200;
}
else
{
v7 = *(_DWORD *)"0005";
v8 = 100;
}
}
else
{
v7 = *(_DWORD *)"0004";
v8 = 50;
}
v40 = 4;
LODWORD(Src) = v7;
BYTE4(Src) = 0;
v9 = qword_1406C2EE8;
if ( !qword_1406C2EE8 )
{
v31 = (__int128 *)operator new(0x3E0u);
qword_1406C2EE8 = sub_1401D0AE0((__int64)v31);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EE8 + 72LL))(qword_1406C2EE8);
v9 = qword_1406C2EE8;
}
v11 = cocos2d::CCDictionary::count(*(cocos2d::CCDictionary **)(v9 + 856));
if ( v11 >= v8 )
{
v35 = &v32;
v34 = 15;
v33 = 4;
v32 = Src;
v24 = (GameStatsManager *)qword_1406C2EE8;
if ( !qword_1406C2EE8 )
{
v31 = (__int128 *)operator new(0x3E0u);
qword_1406C2EE8 = sub_1401D0AE0((__int64)v31);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EE8 + 72LL))(qword_1406C2EE8);
v24 = (GameStatsManager *)qword_1406C2EE8;
}
v26 = GameStatsManager::unlockSpecialChest(v24, (__int64)&v32);
if ( v26 )
{
SecretRewardsLayer::switchToOpenedState(v25, (CCMenuItemSpriteExtra *)a2);
v27 = RewardUnlockLayer::create(v26->m_rewardType, nullptr);
a1->addChild_0(a1, v27, 100);
m_rewardItem = v27->m_rewardItem;
if ( m_rewardItem )
cocos2d::CCObject::release(m_rewardItem);
v27->m_rewardItem = v26;
cocos2d::CCObject::retain(v26);
if ( !v26->m_unk || v26->m_rewardType == v27->m_chestType )
{
v27->m_closeBtn->setVisible(v27->m_closeBtn, 0);
v27->m_closeBtn->setEnabled(v27->m_closeBtn, 0);
v27->m_wrongLabel->setVisible(v27->m_wrongLabel, 0);
v27->m_rewardCollected = 1;
if ( v27->m_animationPlayed )
RewardUnlockLayer::playRewardEffect(v27);
}
}
}
else
{
v12 = (cocos2d::CCArray *)cocos2d::CCArray::create(v10);
v13 = v8 - v11;
v31 = &v36;
v29 = -1;
v30 = -1;
v14 = "Chests";
if ( v13 == 1 )
v14 = "Chest";
v15 = cocos2d::CCString::createWithFormat(
"Unlock %i more %s, and you can collect this bonus.",
v13,
v14);
CString = cocos2d::CCString::getCString(v15);
v36 = 0;
v37 = 0;
v38 = 0;
v17 = -1;
do
++v17;
while ( CString[v17] );
sub_14003A930(&v36, CString, v17);
v33 = 13;
v34 = 15;
strcpy((char *)&v32, "The Keymaster");
HIWORD(v32) = 0;
v18 = DialogObject::create((__int64)&v32, (__int64)&v36, 2, 1.0, 0, (__int64)&v29);
cocos2d::CCArray::addObject(v12, (struct cocos2d::CCObject *)v18);
DialogLayer = DialogLayer::createDialogLayer(nullptr, v12, 2);
a1->addChild_0(a1, DialogLayer, 100);
v21 = (cocos2d::CCDirector *)cocos2d::CCDirector::sharedDirector(v20);
cocos2d::CCDirector::getWinSize(v21);
v22 = DialogLayer->m_mainLayer->__vftable;
cocos2d::CCPoint::CCPoint(1.9431574e-19, *(float *)&v31 * 0.5);
v22->setPosition_0(DialogLayer->m_mainLayer, v23);
DialogLayer::animateInRandomSide(DialogLayer);
}
}