//
// GJGarageLayer::onToggleItem from 0x140277810 to 0x1402779f5 (485 bytes)
//
// 4 xrefs:
// > GJGarageLayer::setupSpecialPage @ 0x140276e34
// > GJGarageLayer::setupSpecialPage @ 0x140276f87
// > GJGarageLayer::setupSpecialPage @ 0x140277112
// > ??> @ 0x1406d0fb0
//
// 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 GJGarageLayer::onToggleItem(GJGarageLayer *a1, cocos2d::CCObject *a2)
{
GameManager *v4; // rcx
int v5; // edi
IconType m_uID; // ebx
UnlockType v7; // esi
GameManager *v8; // r9
GameStatsManager *v9; // rcx
__int64 v10; // rbx
__int64 v11; // rcx
bool v12; // bl
cocos2d::CCString *v13; // rax
bool v14; // bl
GameStatsManager *v15; // rcx
GJItemIcon *v16; // rax
void *v17; // [rsp+20h] [rbp-48h]
void *v18; // [rsp+20h] [rbp-48h]
void *v19; // [rsp+20h] [rbp-48h]
void *v20; // [rsp+20h] [rbp-48h]
_QWORD v21[4]; // [rsp+28h] [rbp-40h] BYREF
v5 = a2->getTag(a2);
m_uID = a2[9].m_uID;
if ( !qword_1406C2ED8 )
{
v17 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v17);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
}
v7 = GameManager::iconTypeToUnlockType(v4, m_uID);
if ( !v8 )
{
v18 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v18);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v8 = (GameManager *)qword_1406C2ED8;
}
if ( GameManager::isIconUnlocked(v8, v5, m_uID) )
{
v10 = qword_1406C2EE8;
if ( !qword_1406C2EE8 )
{
v19 = operator new(0x3E0u);
qword_1406C2EE8 = sub_1401D0AE0((__int64)v19);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EE8 + 72LL))(qword_1406C2EE8);
v10 = qword_1406C2EE8;
}
if ( GameStatsManager::isItemUnlocked(v9, v7, v5) )
{
GameStatsManager::getItemKey(v11, v21, v5, v7);
v13 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(*(_QWORD *)(v10 + 888), v21);
v12 = cocos2d::CCString::boolValue(v13);
sub_14003A830((__int64)v21);
}
else
{
v12 = 0;
}
v14 = !v12;
v15 = (GameStatsManager *)qword_1406C2EE8;
if ( !qword_1406C2EE8 )
{
v20 = operator new(0x3E0u);
qword_1406C2EE8 = sub_1401D0AE0((__int64)v20);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EE8 + 72LL))(qword_1406C2EE8);
v15 = (GameStatsManager *)qword_1406C2EE8;
}
GameStatsManager::toggleEnableItem(v15, v7, v5, v14);
v16 = (GJItemIcon *)((__int64 (__fastcall *)(cocos2d::CCObject *))a2->__vftable[13].copyWithZone)(a2);
GJItemIcon::toggleEnabledState(v16, v14);
}
else
{
a1->showUnlockPopup(&a1->CharacterColorDelegate, v5, v7);
}
}