//
// GJShopLayer::onSelectItem from 0x1402abcb0 to 0x1402abebb (523 bytes)
//
// 2 xrefs:
// > GJShopLayer::init @ 0x1402ab27d
// > ??> @ 0x1406d2240
//
// 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=4
void GJShopLayer::onSelectItem(GJShopLayer *a1, cocos2d::CCObject *a2)
{
__int64 v3; // rbx
GameStatsManager *v4; // rcx
__int64 v5; // rcx
struct cocos2d::CCObject *v6; // rbx
__int16 *v7; // rdx
size_t v8; // r8
void **v9; // rbp
GameStatsManager *v10; // rcx
int v11; // edi
int Stat; // ebp
void *v13; // rcx
PurchaseItemPopup *v14; // rax
void *v15; // [rsp+20h] [rbp-48h]
void *v16; // [rsp+20h] [rbp-48h]
void *v17; // [rsp+20h] [rbp-48h]
void *Block[2]; // [rsp+28h] [rbp-40h] BYREF
__int64 v19; // [rsp+38h] [rbp-30h]
unsigned __int64 v20; // [rsp+40h] [rbp-28h]
if ( !a1->m_closing )
{
v3 = a2->getTag(a2);
v4 = (GameStatsManager *)qword_1406C2EE8;
if ( !qword_1406C2EE8 )
{
v15 = operator new(0x3E0u);
qword_1406C2EE8 = sub_1401D0AE0((__int64)v15);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EE8 + 72LL))(qword_1406C2EE8);
v4 = (GameStatsManager *)qword_1406C2EE8;
}
if ( !GameStatsManager::isStoreItemUnlocked(v4, v3) )
{
v5 = qword_1406C2EE8;
if ( !qword_1406C2EE8 )
{
v16 = operator new(0x3E0u);
qword_1406C2EE8 = sub_1401D0AE0((__int64)v16);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EE8 + 72LL))(qword_1406C2EE8);
v5 = qword_1406C2EE8;
}
v6 = cocos2d::CCDictionary::objectForKey(*(cocos2d::CCDictionary **)(v5 + 344), v3);
v7 = (__int16 *)"14";
if ( v6[6].m_uIndexInArray == 4 )
v7 = &word_14055A524;
*(_OWORD *)Block = 0;
v19 = 0;
v20 = 0;
v8 = -1;
do
++v8;
while ( *((_BYTE *)v7 + v8) );
sub_14003A930(Block, v7, v8);
v9 = Block;
if ( v20 > 0xF )
v9 = (void **)Block[0];
v10 = (GameStatsManager *)qword_1406C2EE8;
if ( !qword_1406C2EE8 )
{
v17 = operator new(0x3E0u);
qword_1406C2EE8 = sub_1401D0AE0((__int64)v17);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EE8 + 72LL))(qword_1406C2EE8);
v10 = (GameStatsManager *)qword_1406C2EE8;
}
v11 = v6[6].m_uReference - v6[6].m_uAutoReleaseCount;
Stat = GameStatsManager::getStat(v10, (const char *)v9);
if ( v20 > 0xF )
{
v13 = Block[0];
if ( v20 + 1 >= 0x1000 )
{
v13 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v13 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v13);
}
if ( v11 <= Stat )
{
v14 = PurchaseItemPopup::create((GJStoreItem *)v6);
v14->m_delegate = &a1->GJPurchaseDelegate;
v14->show(v14);
}
else
{
GJShopLayer::showCantAffordMessage(a1, (GJStoreItem *)v6);
}
}
}
}