//
// GameStatsManager::purchaseItem from 0x1401d42b0 to 0x1401d44c3 (531 bytes)
//
// 2 xrefs:
// > PurchaseItemPopup::onPurchase @ 0x1402afb8e
// > ??> @ 0x1406cc348
//
// 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=2
bool GameStatsManager::purchaseItem(GameStatsManager *a1, int a2)
{
__int64 v2; // rdi
struct cocos2d::CCObject *v4; // rsi
__int16 *v5; // rdx
size_t v6; // rbx
size_t v7; // r8
void **v8; // rdx
int Stat; // eax
unsigned int m_uAutoReleaseCount; // edx
bool v11; // bl
int v12; // r8d
void **v13; // rdx
cocos2d::CCString *v14; // rax
const char *CString; // rax
struct cocos2d::CCString *v16; // rax
void *v17; // rcx
void *v18; // rcx
void *v20[2]; // [rsp+28h] [rbp-60h] BYREF
__int128 v21; // [rsp+38h] [rbp-50h]
void *Block[2]; // [rsp+48h] [rbp-40h] BYREF
__int128 v23; // [rsp+58h] [rbp-30h]
v2 = a2;
if ( a2 <= 0 )
return 0;
if ( GameStatsManager::isStoreItemUnlocked(a1, a2) )
return 0;
v4 = cocos2d::CCDictionary::objectForKey(a1->m_storeItems, v2);
if ( !v4 )
return 0;
v5 = (__int16 *)"14";
if ( v4[6].m_uIndexInArray == 4 )
v5 = &word_14055A524;
*(_OWORD *)v20 = 0;
v21 = 0;
v6 = -1;
v7 = -1;
do
++v7;
while ( *((_BYTE *)v5 + v7) );
sub_14003A930(v20, v5, v7);
v8 = v20;
if ( *((_QWORD *)&v21 + 1) > 0xFu )
v8 = (void **)v20[0];
Stat = GameStatsManager::getStat(a1, (const char *)v8);
m_uAutoReleaseCount = v4[6].m_uAutoReleaseCount;
if ( Stat >= (int)(v4[6].m_uReference - m_uAutoReleaseCount) )
{
v12 = m_uAutoReleaseCount - v4[6].m_uReference + Stat;
v13 = v20;
if ( *((_QWORD *)&v21 + 1) > 0xFu )
v13 = (void **)v20[0];
GameStatsManager::setStat(a1, (const char *)v13, v12);
v14 = cocos2d::CCString::createWithFormat("%i", v2);
CString = cocos2d::CCString::getCString(v14);
*(_OWORD *)Block = 0;
v23 = 0;
do
++v6;
while ( CString[v6] );
sub_14003A930(Block, CString, v6);
v16 = cocos2d::CCString::createWithFormat("%i", v4[6].m_uReference - v4[6].m_uAutoReleaseCount);
cocos2d::CCDictionary::setObject(a1->m_purchasedItems, v16, Block);
if ( *((_QWORD *)&v23 + 1) > 0xFu )
{
v17 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v23 + 1) + 1LL) >= 0x1000 )
{
v17 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v17 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v17);
}
v11 = 1;
}
else
{
v11 = 0;
}
if ( *((_QWORD *)&v21 + 1) > 0xFu )
{
v18 = v20[0];
if ( (unsigned __int64)(*((_QWORD *)&v21 + 1) + 1LL) >= 0x1000 )
{
v18 = *((void **)v20[0] - 1);
if ( (unsigned __int64)((char *)v20[0] - (char *)v18 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v18);
}
return v11;
}