//
// ChallengesPage::claimItem from 0x140086a20 to 0x140086d0a (746 bytes)
//
// 2 xrefs:
// > ChallengeNode::onClaimReward @ 0x140087dc1
// > ??> @ 0x1406c6c9c
//
// 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=3
void ChallengesPage::claimItem(ChallengesPage *a1, ChallengeNode *a2, GJChallengeItem *a3, cocos2d::CCPoint a4)
{
int m_position; // ebp
GameStatsManager *v8; // rbx
int v9; // edi
cocos2d::CCString *v10; // rax
const char *CString; // rax
size_t v12; // r8
struct cocos2d::CCString *v13; // rax
void *v14; // rcx
int v15; // edi
CurrencyRewardLayer *m_currencyRewardLayer; // rbx
const struct cocos2d::CCPoint *v17; // rax
cocos2d::CCPoint v18; // rax
int v19; // ebx
cocos2d::CCPoint v20; // rax
CurrencyRewardLayer *v21; // rax
GameStatsManager *v22; // rcx
cocos2d::CCPoint v23; // [rsp+60h] [rbp-88h] BYREF
cocos2d::CCPoint v24; // [rsp+68h] [rbp-80h] BYREF
void *Block[2]; // [rsp+70h] [rbp-78h] BYREF
__int64 v26; // [rsp+80h] [rbp-68h]
unsigned __int64 v27; // [rsp+88h] [rbp-60h]
m_position = a3->m_position;
v8 = (GameStatsManager *)qword_1406C2EE8;
if ( !qword_1406C2EE8 )
{
v23 = (cocos2d::CCPoint)operator new(0x3E0u);
qword_1406C2EE8 = ((__int64 (__fastcall *)(_QWORD))sub_1401D0AE0)(v23);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EE8 + 72LL))(qword_1406C2EE8);
v8 = (GameStatsManager *)qword_1406C2EE8;
}
if ( a3->m_canClaim && !GameStatsManager::hasCompletedChallenge(v8, a3) )
{
v9 = a3->m_reward.random - a3->m_reward.seed;
v10 = cocos2d::CCString::createWithFormat("c%i%i", a3->m_position, a3->m_timeLeft);
CString = cocos2d::CCString::getCString(v10);
*(_OWORD *)Block = 0;
v26 = 0;
v27 = 0;
v12 = -1;
do
++v12;
while ( CString[v12] );
sub_14003A930(Block, CString, v12);
v13 = cocos2d::CCString::createWithFormat("%i", v9);
cocos2d::CCDictionary::setObject(v8->m_challengeDiamonds, v13, Block);
if ( v27 > 0xF )
{
v14 = Block[0];
if ( v27 + 1 >= 0x1000 )
{
v14 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v14 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v14);
}
GameStatsManager::incrementStat(v8, "13", v9);
}
if ( a1->m_currencyRewardLayer )
{
v15 = a3->m_reward.random - a3->m_reward.seed;
cocos2d::CCPoint::CCPoint(&v23, *(const struct cocos2d::CCPoint **)&a4);
m_currencyRewardLayer = a1->m_currencyRewardLayer;
cocos2d::CCPoint::CCPoint(&v24, v17);
CurrencyRewardLayer::createObjectsFull(m_currencyRewardLayer, Star|Orb, v15, nullptr, v18, 0.0);
}
else
{
v19 = a3->m_reward.random - a3->m_reward.seed;
cocos2d::CCPoint::CCPoint(&v24, *(const struct cocos2d::CCPoint **)&a4);
v21 = CurrencyRewardLayer::create(0, 0, 0, v19, Icon, 0, Icon, 0, v20, (CurrencyRewardType)0, 0.0, 1.0);
a1->m_currencyRewardLayer = v21;
v21->m_delegate = &a1->CurrencyRewardDelegate;
a1->addChild_0(a1, a1->m_currencyRewardLayer, 14);
}
ChallengesPage::exitNodeAtSlot(a1, m_position, 0.0);
v22 = (GameStatsManager *)qword_1406C2EE8;
if ( !qword_1406C2EE8 )
{
v24 = (cocos2d::CCPoint)operator new(0x3E0u);
qword_1406C2EE8 = ((__int64 (__fastcall *)(_QWORD))sub_1401D0AE0)(v24);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EE8 + 72LL))(qword_1406C2EE8);
v22 = (GameStatsManager *)qword_1406C2EE8;
}
GameStatsManager::processChallengeQueue(v22, m_position);
ChallengesPage::createChallengeNode(a1, m_position, 0, 0.5, 1);
ChallengesPage::updateTimers(a1, 0.0);
ChallengesPage::updateDots(a1);
}