//
// GameStatsManager::purchaseItem from 0x1402da220 to 0x1402da45b (571 bytes)
//
// 2 xrefs:
// > PurchaseItemPopup::onPurchase @ 0x1403b5f51
// > ??> @ 0x14091ddb0
//
// 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:29:46 +0000
//
// Hidden C++ exception states: #wind=2
char __fastcall GameStatsManager::purchaseItem(__int64 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
int v10; // ecx
char v11; // bl
unsigned int v12; // eax
void **v13; // rdx
cocos2d::CCString *v14; // rax
const char *CString; // rax
__int64 v16; // rbx
struct cocos2d::CCString *v17; // rax
void *v18; // rcx
void *v19; // rcx
void *v21[2]; // [rsp+38h] [rbp-60h] BYREF
__int128 v22; // [rsp+48h] [rbp-50h]
void *Block[2]; // [rsp+58h] [rbp-40h] BYREF
__int128 v24; // [rsp+68h] [rbp-30h]
v2 = a2;
if ( a2 <= 0 )
return 0;
if ( GameStatsManager::isStoreItemUnlocked(a1) )
return 0;
v4 = cocos2d::CCDictionary::objectForKey(*(cocos2d::CCDictionary **)(a1 + 344), v2);
if ( !v4 )
return 0;
v5 = &word_140737D98;
if ( *((_DWORD *)v4 + 92) == 4 )
v5 = &word_14075A858;
*(_OWORD *)v21 = 0;
v22 = 0;
v6 = -1;
v7 = -1;
do
++v7;
while ( *((_BYTE *)v5 + v7) );
sub_14003D230(v21, v5, v7);
v8 = v21;
if ( *((_QWORD *)&v22 + 1) > 0xFu )
v8 = (void **)v21[0];
Stat = GameStatsManager::getStat(a1, v8);
v10 = *((_DWORD *)v4 + 89) - *((_DWORD *)v4 + 90);
if ( Stat >= v10 )
{
v12 = Stat - v10;
v13 = v21;
if ( *((_QWORD *)&v22 + 1) > 0xFu )
v13 = (void **)v21[0];
GameStatsManager::setStat(a1, v13, v12);
v14 = cocos2d::CCString::createWithFormat((const char *)&word_1406ED6F8, (unsigned int)v2);
CString = cocos2d::CCString::getCString(v14);
*(_OWORD *)Block = 0;
v24 = 0;
do
++v6;
while ( CString[v6] );
sub_14003D230(Block, CString, v6);
v16 = *(_QWORD *)(a1 + 736);
v17 = cocos2d::CCString::createWithFormat(
(const char *)&word_1406ED6F8,
(unsigned int)(*((_DWORD *)v4 + 89) - *((_DWORD *)v4 + 90)));
cocos2d::CCDictionary::setObject(v16, v17, Block);
if ( *((_QWORD *)&v24 + 1) > 0xFu )
{
v18 = Block[0];
if ( (unsigned __int64)(*((_QWORD *)&v24 + 1) + 1LL) >= 0x1000 )
{
v18 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v18 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v18);
}
v11 = 1;
}
else
{
v11 = 0;
}
if ( *((_QWORD *)&v22 + 1) > 0xFu )
{
v19 = v21[0];
if ( (unsigned __int64)(*((_QWORD *)&v22 + 1) + 1LL) >= 0x1000 )
{
v19 = *((void **)v21[0] - 1);
if ( (unsigned __int64)((char *)v21[0] - (char *)v19 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v19);
}
return v11;
}