//
// GameLevelManager::purgeUnusedLevels from 0x708778 to 0x708a74 (764 bytes)
//
// 3 xrefs:
// > GameLevelManager::encodeDataTo @ 0x708aac
// > GameLevelManager::dataLoaded @ 0x73a558
// > ??> @ 0x387a8
//
// 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 GameLevelManager::purgeUnusedLevels(GameLevelManager *a1)
{
unsigned int v2; // w19
cocos2d::CCArray *v3; // x21
int v4; // w0
cocos2d::CCString *v5; // x0
char *CString; // x28
cocos2d::CCDictionary *m_onlineLevels; // x27
GJGameLevel *v8; // x27
char *v9; // x0
unsigned int *v10; // x1
int v11; // w3
cocos2d::CCDictionary *v12; // x27
char *v13; // x0
unsigned int *v14; // x1
int v15; // w2
std::string v16; // [xsp+80h] [xbp+80h] BYREF
v2 = 0;
v3 = cocos2d::CCDictionary::allKeys(a1->m_onlineLevels);
if ( (unsigned int)cocos2d::CCArray::count(v3) )
{
while ( 1 )
{
v4 = cocos2d::CCArray::count(v3);
v5 = (cocos2d::CCString *)cocos2d::CCArray::objectAtIndex(v3, v4 + ~v2);
CString = (char *)cocos2d::CCString::getCString(v5);
m_onlineLevels = a1->m_onlineLevels;
sub_D153B8((int)&v16, CString);
v8 = (GJGameLevel *)cocos2d::CCDictionary::objectForKey(m_onlineLevels, &v16);
v9 = (char *)v16.m_data.m_data - 24;
if ( (__int64 *)v16.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v10 = (unsigned int *)((char *)v16.m_data.m_data - 8);
do
v11 = __ldaxr(v10);
while ( __stlxr(v11 - 1, v10) );
}
else
{
v11 = *((_DWORD *)v16.m_data.m_data - 2);
*((_DWORD *)v16.m_data.m_data - 2) = v11 - 1;
}
if ( v11 <= 0 )
operator delete(v9);
}
if ( v8->m_levelNotDownloaded && v8->m_levelFolder <= 0 )
{
if ( GJGameLevel::getNormalPercent(v8) <= 0
&& v8->m_practicePercent <= 0
&& !v8->m_bestTime
&& !v8->m_bestPoints
&& !v8->m_isCompletionLegitimate )
{
goto LABEL_29;
}
if ( v8->m_stars.random - v8->m_stars.seed <= 0 )
{
if ( GJGameLevel::getNormalPercent(v8) <= 9
&& v8->m_attempts.random - v8->m_attempts.seed <= 4
&& !v8->m_bestTime
&& !v8->m_bestPoints )
{
goto LABEL_29;
}
if ( v8->m_stars.random - v8->m_stars.seed <= 0
&& v8->m_levelLength <= 1
&& GJGameLevel::getNormalPercent(v8) <= 99
&& v8->m_attempts.random - v8->m_attempts.seed <= 9
&& !v8->m_bestTime )
{
break;
}
}
}
LABEL_5:
++v2;
LABEL_6:
if ( v2 >= (unsigned int)cocos2d::CCArray::count(v3) )
return;
}
if ( v8->m_bestPoints )
{
++v2;
goto LABEL_6;
}
LABEL_29:
v12 = a1->m_onlineLevels;
sub_D153B8((int)&v16, CString);
cocos2d::CCDictionary::removeObjectForKey(v12, &v16);
v13 = (char *)v16.m_data.m_data - 24;
if ( (__int64 *)v16.m_data.m_data - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v14 = (unsigned int *)((char *)v16.m_data.m_data - 8);
do
v15 = __ldaxr(v14);
while ( __stlxr(v15 - 1, v14) );
}
else
{
v15 = *((_DWORD *)v16.m_data.m_data - 2);
*((_DWORD *)v16.m_data.m_data - 2) = v15 - 1;
}
if ( v15 <= 0 )
{
++v2;
operator delete(v13);
goto LABEL_6;
}
}
goto LABEL_5;
}
}