//
// GameLevelManager::onGetGJChallengesCompleted from 0x3c3c98 to 0x3c40d6 (1086 bytes)
//
// 1 xrefs:
// > GameLevelManager::handleIt @ 0x3d7542
//
// 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
//
int __fastcall GameLevelManager::onGetGJChallengesCompleted(GameLevelManager *a1, cocos2d::CCArray *a2)
{
_BOOL4 v4; // r6
cocos2d::CCArray *v5; // r4
int result; // r0
cocos2d::CCString *v7; // r0
char *CString; // r0
cocos2d::CCString *v9; // r0
char *v10; // r0
GJChallengeDelegate *m_GJChallengeDelegate; // r0
cocos2d::CCString *v12; // r0
char *v13; // r0
const void *v14; // r0
unsigned __int8 *v15; // r3
char *v16; // r2
_BOOL4 v17; // r6
GJChallengeDelegate *v18; // r0
cocos2d::CCArray *v19; // r4
void *v20; // r0
cocos2d::CCString *v21; // r0
int v22; // r6
GameManager *v23; // r0
cocos2d::CCString *v24; // r0
int v25; // r6
GameManager *v26; // r0
cocos2d::CCString *v27; // r0
char *v28; // r0
GameManager *v29; // r0
cocos2d::CCString *v30; // r0
int v31; // r11
GJAccountManager *v32; // r0
GJRewardDelegate *m_GJRewardDelegate; // r0
cocos2d::CCString *v34; // r0
cocos2d::CCString *v35; // r0
char *v36; // r0
cocos2d::CCString *v37; // r0
char *v38; // r0
cocos2d::CCString *v39; // r0
char *v40; // r0
int i; // r4
GameStatsManager *v42; // r0
GJChallengeItem *Challenge; // r11
GameStatsManager *v44; // r0
GameStatsManager *v45; // r0
void *p_m_uReference; // r1
std::string v47; // r1
GJChallengeItem *v48; // r6
GameStatsManager *v49; // r0
GameStatsManager *v50; // r0
GJChallengeDelegate *v51; // r0
GameStatsManager *v52; // r0
GameStatsManager *v53; // r0
_BOOL4 v54; // [sp+18h] [bp-48h]
GJChallengeItem *QueuedChallenge; // [sp+18h] [bp-48h]
GJChallengeItem *SecondaryQueuedChallenge; // [sp+1Ch] [bp-44h]
int v57; // [sp+28h] [bp-38h]
std::string v58; // [sp+30h] [bp-30h] BYREF
_BYTE v59[4]; // [sp+34h] [bp-2Ch] BYREF
_BYTE v60[4]; // [sp+38h] [bp-28h] BYREF
char *v61; // [sp+3Ch] [bp-24h] BYREF
_BYTE v62[4]; // [sp+40h] [bp-20h] BYREF
cocos2d::CCArray v63; // [sp+44h] [bp-1Ch] BYREF
GameLevelManager::removeDLFromActive(a1, "get_chal");
sub_776584((int)&v63.m_uIndexInArray, "-1");
v4 = sub_3BE0D8((int)a2, (int)&v63.m_uIndexInArray);
sub_774008(&v63.m_uIndexInArray);
if ( !v4 )
{
v5 = sub_3BE530(a2, "|");
if ( cocos2d::CCArray::count(v5) > 1u )
{
v7 = cocos2d::CCArray::stringAtIndex(v5, 0);
CString = (char *)cocos2d::CCString::getCString(v7);
sub_776584((int)&v58, CString);
v9 = cocos2d::CCArray::stringAtIndex(v5, 1u);
v10 = (char *)cocos2d::CCString::getCString(v9);
sub_776584((int)v59, v10);
if ( *((_DWORD *)v58.m_data.m_data - 3) <= 4u )
{
m_GJChallengeDelegate = a1->m_GJChallengeDelegate;
if ( m_GJChallengeDelegate )
m_GJChallengeDelegate->challengeStatusFailed(m_GJChallengeDelegate);
goto LABEL_36;
}
sub_776158(v60, &v58, 5, -1);
sub_774794(&v58, v60);
sub_774008(v60);
sub_775C20(&v61, &v58);
v12 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"%c%s%s%c%c%s",
(const char *)&dword_6C + 3,
"C36",
"fpYa",
80,
116,
"dg");
v13 = (char *)cocos2d::CCString::getCString(v12);
sub_774544((int)&v61, v13);
v14 = (const void *)strlen(v61);
rtsha1::calc((rtsha1 *)v61, v14, (int)&v63.m_uUnknown, v15);
rtsha1::toHexString((rtsha1 *)&v63.m_uUnknown, (const unsigned __int8 *)&v63.data, v16);
sub_776584((int)v62, (char *)&v63.data);
v17 = sub_3BE0D8((int)v62, (int)v59);
sub_774008(v62);
if ( !v17 )
{
v18 = a1->m_GJChallengeDelegate;
if ( v18 )
v18->challengeStatusFailed(v18);
goto LABEL_35;
}
sub_776584((int)&v63.m_uID, "19847");
cocos2d::ZipUtils::base64DecodeEnc((cocos2d::ZipUtils *)&v63, &v58, (std::string)&v63.m_uID);
sub_774008(&v63.m_uID);
v19 = sub_3BE530(&v63, ":");
if ( cocos2d::CCArray::count(v19) > 8u )
{
v21 = cocos2d::CCArray::stringAtIndex(v19, 1u);
v22 = cocos2d::CCString::intValue(v21);
if ( v22 > 0 )
{
v23 = GameManager::sharedState();
GameManager::setPlayerUserID(v23, v22);
v24 = cocos2d::CCArray::stringAtIndex(v19, 2u);
v25 = cocos2d::CCString::intValue(v24);
v26 = GameManager::sharedState();
if ( v25 == v26->m_chk.random - v26->m_chk.seed )
{
v27 = cocos2d::CCArray::stringAtIndex(v19, 3u);
v28 = (char *)cocos2d::CCString::getCString(v27);
sub_776584((int)&v63.m_nLuaID, v28);
v29 = GameManager::sharedState();
sub_775C20(&v63.m_nTag, &v29->m_playerUDID);
v54 = sub_3BE0D8((int)&v63.m_nLuaID, (int)&v63.m_nTag);
sub_774008(&v63.m_nTag);
if ( v54 )
{
v30 = cocos2d::CCArray::stringAtIndex(v19, 4u);
v31 = cocos2d::CCString::intValue(v30);
v32 = GJAccountManager::sharedState();
if ( v31 == v32->m_accountID - v32->m_unkInt1 )
{
v34 = cocos2d::CCArray::stringAtIndex(v19, 5u);
v57 = cocos2d::CCString::intValue(v34);
v35 = cocos2d::CCArray::stringAtIndex(v19, 6u);
v36 = (char *)cocos2d::CCString::getCString(v35);
sub_776584((int)&v63.m_uReference, v36);
v37 = cocos2d::CCArray::stringAtIndex(v19, 7u);
v38 = (char *)cocos2d::CCString::getCString(v37);
sub_776584((int)&v63.m_uAutoReleaseCount, v38);
v39 = cocos2d::CCArray::stringAtIndex(v19, 8u);
v40 = (char *)cocos2d::CCString::getCString(v39);
sub_776584((int)&v63.m_eObjType, v40);
for ( i = 1; i != 4; ++i )
{
v42 = GameStatsManager::sharedState();
Challenge = GameStatsManager::getChallenge(v42, i);
v44 = GameStatsManager::sharedState();
QueuedChallenge = GameStatsManager::getQueuedChallenge(v44, i);
v45 = GameStatsManager::sharedState();
SecondaryQueuedChallenge = GameStatsManager::getSecondaryQueuedChallenge(v45, i);
if ( i == 1 )
{
p_m_uReference = &v63.m_uReference;
}
else if ( i == 2 )
{
p_m_uReference = &v63.m_uAutoReleaseCount;
}
else
{
p_m_uReference = &v63.m_eObjType;
}
sub_775C20(&v63.m_uIndexInArray, p_m_uReference);
v48 = (GJChallengeItem *)GJChallengeItem::createFromString(
(GJChallengeItem *)&v63.m_uIndexInArray,
v47);
sub_774008(&v63.m_uIndexInArray);
v48->m_position = i;
v49 = GameStatsManager::sharedState();
if ( !GameStatsManager::hasCompletedChallenge(v49, v48)
&& (!Challenge || Challenge->m_timeLeft < v48->m_timeLeft)
&& (!QueuedChallenge || QueuedChallenge->m_timeLeft < v48->m_timeLeft)
&& (!SecondaryQueuedChallenge || SecondaryQueuedChallenge->m_timeLeft < v48->m_timeLeft) )
{
if ( (!Challenge || Challenge->m_canClaim) && QueuedChallenge )
{
v52 = GameStatsManager::sharedState();
GameStatsManager::storeSecondaryQueuedChallenge(v52, i, v48);
}
else
{
v53 = GameStatsManager::sharedState();
GameStatsManager::storeQueuedChallenge(v53, i, v48);
}
}
}
v50 = GameStatsManager::sharedState();
GameStatsManager::storeChallengeTime(v50, v57);
v51 = a1->m_GJChallengeDelegate;
if ( v51 )
v51->challengeStatusFinished(v51);
sub_774008(&v63.m_eObjType);
sub_774008(&v63.m_uAutoReleaseCount);
sub_774008(&v63.m_uReference);
sub_774008(&v63.m_nLuaID);
sub_774008(&v63);
sub_774008(&v61);
sub_774008(v59);
return sub_774008(&v58);
}
}
m_GJRewardDelegate = a1->m_GJRewardDelegate;
if ( m_GJRewardDelegate )
m_GJRewardDelegate->rewardsStatusFailed(m_GJRewardDelegate);
sub_774008(&v63.m_nLuaID);
goto LABEL_34;
}
}
v20 = a1->m_GJRewardDelegate;
}
else
{
v20 = a1->m_GJChallengeDelegate;
}
if ( v20 )
(*(void (__fastcall **)(void *))(*(_DWORD *)v20 + 4))(v20);
LABEL_34:
sub_774008(&v63);
LABEL_35:
sub_774008(&v61);
LABEL_36:
sub_774008(v59);
return sub_774008(&v58);
}
}
result = (int)a1->m_GJChallengeDelegate;
if ( result )
return (*(int (__fastcall **)(int))(*(_DWORD *)result + 4))(result);
return result;
}