//
// PlayLayer::levelComplete from 0x5d0b5c to 0x5d1700 (2980 bytes)
//
// 5 xrefs:
// > PlayLayer::playPlatformerEndAnimationToPos @ 0x5d1820
// > ??> @ 0x90cd8
// > PlayLayer::playEndAnimationToPos @ 0x5cc3d0
// > PlayLayer::playPlatformerEndAnimationToPos @ 0x5d198c
// > ??> @ 0x122cf20
//
// 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
//
void PlayLayer::levelComplete(PlayLayer *a1)
{
EndTriggerGameObject *m_platformerEndTrigger; // x0
_BOOL4 m_noEffects; // w23
float *v4; // x20
bool m_instant; // w21
double m_attemptTime; // d0
GJGameLevel *m_level; // x0
PlayLayer_vtbl *v8; // x1
int v9; // w0
unsigned int v10; // w24
cocos2d::CCArray *v11; // x27
cocos2d::CCString *v12; // x0
char *CString; // x0
cocos2d::CCDictionary *m_collectedItems; // x21
_DWORD *v15; // x25
char *v16; // x0
GJGameLevel *v17; // x0
int v18; // w21
float v19; // s0
cocos2d::CCSequence *v20; // x23
cocos2d::CCFiniteTimeAction *v21; // x0
cocos2d::CCAction *v22; // x0
CCCircleWave *v23; // x21
PlayerObject *m_player1; // x2
CCCircleWave_vtbl *v25; // x3
GLubyte r; // w5
GLubyte g; // w4
void (__fastcall *setPosition)(CCCircleWave *__hidden, const cocos2d::CCPoint *); // x23
cocos2d::CCSequence *v29; // x20
cocos2d::CCFiniteTimeAction *v30; // x0
cocos2d::CCAction *v31; // x0
GJGameLevel *v32; // x0
GameLevelManager *v33; // x0
GJGameLevel *v34; // x0
GJGameLevel *v35; // x21
int v36; // w0
int v37; // w2
int v38; // w0
std::string *p_m_recordString; // x21
GJGameLevel *v40; // x21
char *v41; // x0
void *v42; // x0
int v43; // w0
GJGameLevel *v44; // x21
int v45; // w0
LevelSettingsObject *m_levelSettings; // x1
int v47; // w0
double TempMilliTime; // d0
GameManager *v49; // x0
GJGameLevel *v50; // x0
GameStatsManager *v51; // x0
GameStatsManager *v52; // x0
int v53; // w0
GJGameLevel *v54; // x2
int m_orbs; // w1
GameStatsManager *v56; // x0
int v57; // w0
GameStatsManager *v58; // x0
GameStatsManager *v59; // x0
GameStatsManager *v60; // x0
unsigned int *v61; // x1
int v62; // w2
GJGameLevel *v63; // x21
int v64; // w0
GJGameLevel *v65; // x21
int v66; // w0
GameLevelManager *v67; // x0
int v68; // w24
int PlayTimerMilli; // w25
GameManager *v70; // x0
_BOOL4 m_unkBool32; // w1
int m_points; // w26
GJGameLevel *v73; // x28
int v74; // w27
char *v75; // x0
void *v76; // x0
unsigned int *v77; // x1
int v78; // w2
unsigned int *v79; // x1
int v80; // w2
int v81; // w28
int v82; // w27
unsigned int *v83; // x1
int v84; // w2
int m_clickIndex; // [xsp+90h] [xbp+90h]
int m_tickIndex; // [xsp+94h] [xbp+94h]
GJGameLevel *v87; // [xsp+98h] [xbp+98h]
int v88; // [xsp+98h] [xbp+98h]
__int64 v89; // [xsp+A8h] [xbp+A8h] BYREF
__int64 v90; // [xsp+B0h] [xbp+B0h] BYREF
__int64 v91; // [xsp+B8h] [xbp+B8h] BYREF
std::string v92; // [xsp+C0h] [xbp+C0h] BYREF
cocos2d::CCPoint EndPosition; // 0:kr00_8.8
m_platformerEndTrigger = a1->m_platformerEndTrigger;
if ( m_platformerEndTrigger )
{
m_noEffects = m_platformerEndTrigger->m_noEffects;
v4 = &a1->m_varianceValues.__elems_[1975];
m_instant = m_platformerEndTrigger->m_instant;
}
else
{
v4 = &a1->m_varianceValues.__elems_[1975];
m_noEffects = 0;
if ( !a1->m_isPlatformer )
goto LABEL_4;
m_instant = 0;
}
PlayerObject::playCompleteEffect(a1->m_player1, m_noEffects, m_instant);
PlayerObject::playCompleteEffect(a1->m_player2, m_noEffects, m_instant);
LABEL_4:
m_attemptTime = a1->m_attemptTime;
if ( m_attemptTime > a1->m_bestAttemptTime )
a1->m_bestAttemptTime = m_attemptTime;
m_level = a1->m_level;
if ( m_level->m_levelType != Main
&& !*((_BYTE *)v4 + 592)
&& !*((_BYTE *)v4 + 656)
&& !*((_BYTE *)v4 + 2102)
&& m_level->m_stars.random - m_level->m_stars.seed > 0
&& (!*((_BYTE *)v4 + 270) || a1->m_timePlayed < 10.0)
&& a1->m_bestAttemptTime < 10.0 )
{
*((_BYTE *)v4 + 1949) = 1;
}
v8 = a1->GJBaseGameLayer::cocos2d::CCLayer::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
*((_BYTE *)v4 + 1392) = 1;
v8->updateTimeWarp(a1, 1.0);
v9 = *((unsigned __int8 *)v4 + 656);
if ( *((_BYTE *)v4 + 656) )
{
if ( *((_BYTE *)v4 + 1949) )
goto LABEL_51;
goto LABEL_19;
}
if ( *((_BYTE *)v4 + 2102) )
{
if ( *((_BYTE *)v4 + 1949) )
goto LABEL_51;
goto LABEL_37;
}
if ( a1->m_level->m_levelType == Editor )
{
GJBaseGameLayer::getCapacityString(&v91, a1);
v40 = a1->m_level;
sub_D18D28(&v92, &v91);
sub_D18EA8(&v40->m_capacityString, &v92);
v41 = (char *)v92.m_data.m_data - 24;
if ( (__int64 *)v92.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v77 = (unsigned int *)((char *)v92.m_data.m_data - 8);
do
v78 = __ldaxr(v77);
while ( __stlxr(v78 - 1, v77) );
}
else
{
v78 = *((_DWORD *)v92.m_data.m_data - 2);
*((_DWORD *)v92.m_data.m_data - 2) = v78 - 1;
}
if ( v78 <= 0 )
operator delete(v41);
}
if ( !*((_BYTE *)v4 + 592) )
{
m_levelSettings = a1->m_levelSettings;
v47 = (signed int)a1->m_gameState.m_commandIndex / 2;
if ( m_levelSettings )
m_levelSettings->m_propertykA44 = v47;
a1->m_level->GJBaseGameLayer::m_timestamp = v47;
}
v42 = (void *)(v91 - 24);
if ( (__int64 *)(v91 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v79 = (unsigned int *)(v91 - 8);
do
v80 = __ldaxr(v79);
while ( __stlxr(v80 - 1, v79) );
}
else
{
v80 = *(_DWORD *)(v91 - 8);
*(_DWORD *)(v91 - 8) = v80 - 1;
}
if ( v80 <= 0 )
operator delete(v42);
}
if ( *((_BYTE *)v4 + 1949) )
{
LABEL_51:
PlayLayer::onQuit(a1);
return;
}
if ( *((_BYTE *)v4 + 656) )
goto LABEL_21;
if ( *((_BYTE *)v4 + 2102) )
{
v9 = *((unsigned __int8 *)v4 + 656);
goto LABEL_19;
}
}
else if ( *((_BYTE *)v4 + 1949) )
{
goto LABEL_51;
}
if ( *((_BYTE *)v4 + 592) )
goto LABEL_37;
v10 = 0;
v11 = cocos2d::CCDictionary::allKeys(a1->m_collectedItems);
while ( v10 < (unsigned int)cocos2d::CCArray::count(v11) )
{
v12 = (cocos2d::CCString *)cocos2d::CCArray::objectAtIndex(v11, v10);
CString = (char *)cocos2d::CCString::getCString(v12);
m_collectedItems = a1->m_collectedItems;
sub_D153B8((int)&v92, CString);
v15 = (_DWORD *)cocos2d::CCDictionary::objectForKey(m_collectedItems, &v92);
v16 = (char *)v92.m_data.m_data - 24;
if ( (__int64 *)v92.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v61 = (unsigned int *)((char *)v92.m_data.m_data - 8);
do
v62 = __ldaxr(v61);
while ( __stlxr(v62 - 1, v61) );
}
else
{
v62 = *((_DWORD *)v92.m_data.m_data - 2);
*((_DWORD *)v92.m_data.m_data - 2) = v62 - 1;
}
if ( v62 <= 0 )
operator delete(v16);
}
if ( (*(unsigned int (__fastcall **)(_DWORD *))(*(_QWORD *)v15 + 1784LL))(v15) == 31 )
{
v43 = v15[444];
switch ( v43 )
{
case 2:
v65 = a1->m_level;
++v10;
v65->m_secondCoinVerified.value = 1;
v66 = (int)(float)((float)((float)rand() * 4.6566e-10) * 1000.0);
v65->m_secondCoinVerified.seed = v66;
v65->m_secondCoinVerified.random = v66 + 1;
break;
case 3:
v63 = a1->m_level;
++v10;
v63->m_thirdCoinVerified.value = 1;
v64 = (int)(float)((float)((float)rand() * 4.6566e-10) * 1000.0);
v63->m_thirdCoinVerified.seed = v64;
v63->m_thirdCoinVerified.random = v64 + 1;
break;
case 1:
v44 = a1->m_level;
++v10;
v44->m_firstCoinVerified.value = 1;
v45 = (int)(float)((float)((float)rand() * 4.6566e-10) * 1000.0);
v44->m_firstCoinVerified.seed = v45;
v44->m_firstCoinVerified.random = v45 + 1;
break;
default:
goto LABEL_17;
}
}
else
{
LABEL_17:
++v10;
}
}
v34 = a1->m_level;
if ( v34->m_levelType == Editor && GJGameLevel::areCoinsVerified(v34) )
{
v35 = a1->m_level;
v35->m_isVerifiedRaw = 1;
v36 = rand();
v37 = *((unsigned __int8 *)v4 + 776);
v38 = (int)(float)((float)((float)v36 * 4.6566e-10) * 1000.0);
v35->m_isVerified.seed = v38;
v35->m_isVerified.random = v38 + 1;
if ( v37 )
{
p_m_recordString = &a1->m_level->GJBaseGameLayer::m_recordString;
GJBaseGameLayer::getRecordString((__int64 *)&v92, a1, 1);
sub_D163D4(p_m_recordString, &v92);
if ( (__int64 *)v92.m_data.m_data - 3 != &qword_124B6B0 )
sub_5C93B8((char *)v92.m_data.m_data - 24);
}
}
if ( *((_BYTE *)v4 + 1949) )
goto LABEL_51;
LABEL_37:
v9 = *((unsigned __int8 *)v4 + 656);
LABEL_19:
if ( !v9 && !*((_BYTE *)v4 + 2102) )
{
TempMilliTime = PlayLayer::getTempMilliTime(a1);
GJGameLevel::savePercentage(
a1->m_level,
100,
*((_BYTE *)v4 + 592),
a1->m_clicks,
(int)(TempMilliTime - a1->m_currentTime - a1->m_pauseDelta),
*((_BYTE *)v4 + 1952));
if ( *((_BYTE *)v4 + 592) )
{
if ( a1->m_level->m_levelType != Main )
goto LABEL_21;
LABEL_71:
v49 = GameManager::sharedState();
GameManager::reportPercentageForLevel(
v49,
a1->m_level->m_levelID.random - a1->m_level->m_levelID.seed,
100,
*((_BYTE *)v4 + 592));
LABEL_72:
if ( !*((_BYTE *)v4 + 592) )
{
v50 = a1->m_level;
if ( v50->m_levelType == Editor )
goto LABEL_83;
if ( v50->m_stars.random - v50->m_stars.seed > 0 )
{
v51 = GameStatsManager::sharedState();
if ( !GameStatsManager::hasCompletedStarLevel(v51, a1->m_level) )
*((_BYTE *)v4 + 2396) = (unsigned __int8)&dword_0 + 1;
v52 = GameStatsManager::sharedState();
GameStatsManager::awardCurrencyForLevel(v52, a1->m_level);
a1->m_orbs = v53;
v54 = a1->m_level;
m_orbs = v53;
if ( v54->m_dailyID.random - v54->m_dailyID.seed > 0 || v54->m_gauntletLevel )
{
v56 = GameStatsManager::sharedState();
GameStatsManager::awardDiamondsForLevel(v56, a1->m_level);
a1->m_diamonds = v57;
m_orbs = a1->m_orbs;
}
if ( m_orbs > 0 )
{
v58 = GameStatsManager::sharedState();
*((_BYTE *)v4 + 2408) = GameStatsManager::awardSecretKey(v58);
}
}
GJBaseGameLayer::processItems(a1);
v59 = GameStatsManager::sharedState();
GameStatsManager::completedLevel(v59, a1->m_level);
v60 = GameStatsManager::sharedState();
GameStatsManager::checkCoinAchievement(v60, a1->m_level);
if ( !*((_BYTE *)v4 + 592) )
{
v50 = a1->m_level;
if ( v50->m_levelType == Editor )
LABEL_83:
v50->m_autoLevel = *((_BYTE *)v4 + 2380) ^ 1;
}
}
goto LABEL_21;
}
GJBaseGameLayer::getRecordString(&v89, a1, 1);
v68 = GJBaseGameLayer::countCollectedUserCoins(a1);
PlayTimerMilli = GJBaseGameLayer::getPlayTimerMilli(a1);
if ( *((_BYTE *)v4 + 270) )
{
GameManager::sharedState()->m_leaderboardLevelID = a1->m_level->m_M_ID;
v70 = GameManager::sharedState();
m_unkBool32 = a1->m_gameState.m_unkBool32;
v70->m_leaderboardLevelTime = PlayTimerMilli;
if ( m_unkBool32 )
{
m_points = a1->m_gameState.m_points;
if ( !a1->m_levelSettings->m_noTimePenalty )
{
m_points -= PlayTimerMilli;
a1->m_gameState.m_points = m_points;
}
v87 = a1->m_level;
m_tickIndex = a1->m_tickIndex;
m_clickIndex = a1->m_clickIndex;
sub_D18D28(&v90, &v89);
GJGameLevel::saveNewScore(v87, m_points, 1, m_tickIndex, m_clickIndex, v68);
if ( (__int64 *)(v90 - 24) != &qword_124B6B0 )
sub_5C93B8((void *)(v90 - 24));
GameManager::sharedState()->m_leaderboardLevelPoints = a1->m_gameState.m_points;
}
else
{
GameManager::sharedState()->m_leaderboardLevelPoints = 0;
}
v73 = a1->m_level;
v74 = a1->m_tickIndex;
v88 = a1->m_clickIndex;
sub_D18D28(&v91, &v89);
GJGameLevel::saveNewScore(v73, PlayTimerMilli, 0, v74, v88, v68);
v75 = (char *)(v91 - 24);
if ( (__int64 *)(v91 - 24) == &qword_124B6B0 )
{
LABEL_100:
v76 = (void *)(v89 - 24);
if ( (__int64 *)(v89 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v83 = (unsigned int *)(v89 - 8);
do
v84 = __ldaxr(v83);
while ( __stlxr(v84 - 1, v83) );
}
else
{
v84 = *(_DWORD *)(v89 - 8);
*(_DWORD *)(v89 - 8) = v84 - 1;
}
if ( v84 <= 0 )
operator delete(v76);
}
if ( a1->m_level->m_levelType != Main )
goto LABEL_72;
goto LABEL_71;
}
}
else
{
v81 = a1->m_tickIndex;
v82 = a1->m_clickIndex;
sub_D18D28(&v92, &v89);
GJGameLevel::saveNewScore(a1->m_level, PlayTimerMilli, 0, v81, v82, v68);
v75 = (char *)v92.m_data.m_data - 24;
if ( (__int64 *)v92.m_data.m_data - 3 == &qword_124B6B0 )
goto LABEL_100;
}
sub_5C93B8(v75);
goto LABEL_100;
}
LABEL_21:
PlayLayer::commitJumps(a1);
v17 = a1->m_level;
if ( (v17->m_savedTime || v17->m_savedPoints)
&& v17->m_levelType != Editor
&& v17->m_demon.random - v17->m_demon.seed == 1
&& PlatformToolbox::isNetworkAvailable() )
{
v32 = a1->m_level;
if ( v32->m_savedTime )
{
v67 = GameLevelManager::sharedState();
GameLevelManager::getLevelLeaderboard(v67, a1->m_level, (LevelLeaderboardType)4, Time);
v32 = a1->m_level;
}
if ( v32->m_savedPoints )
{
v33 = GameLevelManager::sharedState();
GameLevelManager::getLevelLeaderboard(v33, a1->m_level, (LevelLeaderboardType)4, Points);
}
}
if ( !m_noEffects )
{
v18 = 0;
do
{
v19 = (float)v18++;
v20 = (cocos2d::CCSequence *)cocos2d::CCDelayTime::create(v19 * 0.05);
v21 = (cocos2d::CCFiniteTimeAction *)cocos2d::CCCallFunc::create(a1, PlayLayer::spawnCircle, 0);
v22 = (cocos2d::CCAction *)cocos2d::CCSequence::create(v20, v21, 0);
cocos2d::CCNode::runAction(a1, v22);
}
while ( v18 != 5 );
v23 = CCCircleWave::create(10.0, 250.0, 0.5, 0);
m_player1 = a1->m_player1;
v23->m_lineWidth = 4;
v25 = v23->__vftable;
r = m_player1->m_playerColor1.r;
g = m_player1->m_playerColor1.g;
v23->m_color.b = m_player1->m_playerColor1.b;
v23->m_color.r = r;
v23->m_color.g = g;
setPosition = v25->setPosition;
EndPosition = PlayLayer::getEndPosition(a1);
((void (__fastcall *)(CCCircleWave *, std::string *, float, float))setPosition)(
v23,
&v92,
EndPosition.x,
EndPosition.y);
a1->m_objectLayer->addChild_0(a1->m_objectLayer, v23, 0);
}
if ( *((_BYTE *)v4 + 592) )
{
v29 = (cocos2d::CCSequence *)cocos2d::CCDelayTime::create(0.1);
v30 = (cocos2d::CCFiniteTimeAction *)cocos2d::CCCallFunc::create(a1, PlayLayer::showCompleteText, 0);
v31 = (cocos2d::CCAction *)cocos2d::CCSequence::create(v29, v30, 0);
cocos2d::CCNode::runAction(a1, v31);
}
else
{
PlayLayer::showCompleteEffect(a1);
}
}