//
// GameStatsManager::purchaseItem from 0x7b42c4 to 0x7b44f0 (556 bytes)
//
// 2 xrefs:
// > PurchaseItemPopup::onPurchase @ 0x92a6a0
// > ??> @ 0x76188
//
// 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
//
bool GameStatsManager::purchaseItem(GameStatsManager *a1, int a2)
{
char isStoreItemUnlocked; // w20
GJStoreItem *StoreItem; // x0
GJStoreItem *v6; // x23
int Stat; // w3
int v8; // w2
char *v9; // x0
unsigned int *v10; // x1
int v11; // w2
int random; // w2
int seed; // w1
cocos2d::CCDictionary *m_purchasedItems; // x23
cocos2d::CCObject *v16; // x22
cocos2d::CCString *v17; // x0
char *CString; // x0
void *v19; // x0
unsigned int *v20; // x1
int v21; // w2
char *v22; // [xsp+58h] [xbp+58h] BYREF
__int64 v23; // [xsp+60h] [xbp+60h] BYREF
if ( a2 <= 0 )
return 0;
isStoreItemUnlocked = GameStatsManager::isStoreItemUnlocked(a1, a2);
if ( isStoreItemUnlocked )
return 0;
StoreItem = (GJStoreItem *)GameStatsManager::getStoreItem(a1, a2);
v6 = StoreItem;
if ( StoreItem )
{
GJStoreItem::getCurrencyKey(StoreItem, (__int64)&v22);
Stat = GameStatsManager::getStat(a1, v22);
v8 = v6->m_price.random - v6->m_price.seed;
if ( Stat >= v8 )
{
GameStatsManager::setStat(a1, v22, Stat - v8);
random = v6->m_price.random;
seed = v6->m_price.seed;
m_purchasedItems = a1->m_purchasedItems;
v16 = (cocos2d::CCObject *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"%i",
(const char *)(unsigned int)(random - seed));
v17 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"%i",
(const char *)(unsigned int)a2);
CString = (char *)cocos2d::CCString::getCString(v17);
sub_D153B8((int)&v23, CString);
cocos2d::CCDictionary::setObject((int)m_purchasedItems, v16);
v19 = (void *)(v23 - 24);
if ( (__int64 *)(v23 - 24) == &qword_124B6B0 )
goto LABEL_14;
if ( &pthread_create )
{
v20 = (unsigned int *)(v23 - 8);
do
v21 = __ldaxr(v20);
while ( __stlxr(v21 - 1, v20) );
}
else
{
v21 = *(_DWORD *)(v23 - 8);
*(_DWORD *)(v23 - 8) = v21 - 1;
}
if ( v21 > 0 )
{
LABEL_14:
isStoreItemUnlocked = 1;
}
else
{
isStoreItemUnlocked = 1;
operator delete(v19);
}
}
v9 = v22 - 24;
if ( v22 - 24 != (char *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v10 = (unsigned int *)(v22 - 8);
do
v11 = __ldaxr(v10);
while ( __stlxr(v11 - 1, v10) );
}
else
{
v11 = *((_DWORD *)v22 - 2);
*((_DWORD *)v22 - 2) = v11 - 1;
}
if ( v11 <= 0 )
operator delete(v9);
}
}
return isStoreItemUnlocked;
}