//
// GJGarageLayer::onToggleItem from 0x140380210 to 0x1403803fa (490 bytes)
//
// 4 xrefs:
// > GJGarageLayer::setupSpecialPage @ 0x14037f82b
// > GJGarageLayer::setupSpecialPage @ 0x14037f98f
// > GJGarageLayer::setupSpecialPage @ 0x14037fb09
// > ??> @ 0x1409228c8
//
// 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:31:05 +0000
//
// Hidden C++ exception states: #wind=5
__int64 __fastcall GJGarageLayer::onToggleItem(__int64 a1, _DWORD *a2)
{
__int64 v4; // rcx
unsigned int v5; // edi
unsigned int v6; // ebx
unsigned int v7; // esi
__int64 v8; // r9
__int64 v9; // rcx
__int64 v11; // rbx
__int64 v12; // rcx
bool v13; // bl
cocos2d::CCString *v14; // rax
unsigned __int8 v15; // bl
__int64 v16; // rcx
__int64 v17; // rax
void *v18; // [rsp+20h] [rbp-48h]
void *v19; // [rsp+20h] [rbp-48h]
void *v20; // [rsp+20h] [rbp-48h]
void *v21; // [rsp+20h] [rbp-48h]
_QWORD v22[4]; // [rsp+28h] [rbp-40h] BYREF
v5 = (*(__int64 (__fastcall **)(_DWORD *))(*(_QWORD *)a2 + 56LL))(a2);
v6 = a2[128];
if ( !qword_14090BFD0 )
{
v18 = operator new(0x6E8u);
qword_14090BFD0 = GameManager::GameManager((__int64)v18);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFD0 + 72LL))(qword_14090BFD0);
}
v7 = GameManager::iconTypeToUnlockType(v4, v6);
if ( !v8 )
{
v19 = operator new(0x6E8u);
qword_14090BFD0 = GameManager::GameManager((__int64)v19);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFD0 + 72LL))(qword_14090BFD0);
v8 = qword_14090BFD0;
}
if ( !GameManager::isIconUnlocked(v8, v5, v6) )
return (*(__int64 (__fastcall **)(__int64, _QWORD, _QWORD))(*(_QWORD *)(a1 + 448) + 8LL))(a1 + 448, v5, v7);
v11 = qword_14090BFE0;
if ( !qword_14090BFE0 )
{
v20 = operator new(0x3E8u);
qword_14090BFE0 = sub_1402D6480((__int64)v20);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFE0 + 72LL))(qword_14090BFE0);
v11 = qword_14090BFE0;
}
if ( (unsigned __int8)GameStatsManager::isItemUnlocked(v9, v7, v5) )
{
GameStatsManager::getItemKey(v12, v22, v5, v7);
v14 = (cocos2d::CCString *)cocos2d::CCDictionary::valueForKey(*(_QWORD *)(v11 + 896), v22);
v13 = cocos2d::CCString::boolValue(v14);
sub_14003D310((__int64)v22);
}
else
{
v13 = 0;
}
v15 = !v13;
v16 = qword_14090BFE0;
if ( !qword_14090BFE0 )
{
v21 = operator new(0x3E8u);
qword_14090BFE0 = sub_1402D6480((__int64)v21);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_14090BFE0 + 72LL))(qword_14090BFE0);
v16 = qword_14090BFE0;
}
GameStatsManager::toggleEnableItem(v16, v7, v5, v15);
v17 = (*(__int64 (__fastcall **)(_DWORD *))(*(_QWORD *)a2 + 952LL))(a2);
return GJItemIcon::toggleEnabledState(v17, v15);
}