//
// GameLevelManager::limitSavedLevels from 0x808338 to 0x8085f0 (696 bytes)
//
// 3 xrefs:
// > GameLevelManager::encodeDataTo @ 0x808b98
// > GameLevelManager::dataLoaded @ 0x860ca4
// > ??> @ 0xfcc58
//
// This function is hookable on this platform (idp: arm, 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 12:54:46 +0000
//
__int64 __fastcall GameLevelManager::limitSavedLevels(cocos2d::CCDictionary **this)
{
unsigned int v2; // w20
int v3; // w26
cocos2d::CCArray *SavedLevels; // x25
cocos2d::CCArray *v5; // x22
GameManager *v6; // x0
__int64 v7; // x21
cocos2d::CCString *v8; // x0
const char *CString; // x0
size_t v10; // x0
cocos2d::CCObject *v11; // x21
GameManager *v12; // x0
unsigned int v13; // w19
char *v14; // x26
GameManager *v15; // x0
__int64 v16; // x0
bool v18; // w1
GameManager *v19; // x0
GameManager *v20; // x0
unsigned int v22; // w21
cocos2d::CCArray *v23; // x25
unsigned int v24; // w22
int v25; // w0
cocos2d::CCString *v26; // x0
const char *v27; // x0
size_t v28; // x0
__int64 v29; // x27
__int64 v30; // x27
char *v31; // [xsp+68h] [xbp+68h]
char *v32; // [xsp+68h] [xbp+68h]
__int64 v33; // [xsp+70h] [xbp+70h] BYREF
__int64 v34; // [xsp+78h] [xbp+78h]
void *v35; // [xsp+80h] [xbp+80h]
v2 = 0;
v3 = 0;
SavedLevels = GameLevelManager::getSavedLevels(this, 0, 0);
v5 = (cocos2d::CCArray *)cocos2d::CCDictionary::allKeys(*(this + 106));
v6 = (GameManager *)cocos2d::CCArray::count(v5);
if ( (_DWORD)v6 )
{
do
{
v7 = (__int64)*(this + 106);
v8 = (cocos2d::CCString *)cocos2d::CCArray::objectAtIndex(v5, v2);
CString = (const char *)cocos2d::CCString::getCString(v8);
v33 = 0;
v34 = 0;
v35 = nullptr;
v31 = (char *)CString;
v10 = strlen(CString);
std::string::__init(&v33, v31, v10);
v11 = (cocos2d::CCObject *)cocos2d::CCDictionary::objectForKey(v7, &v33);
if ( (v33 & 1) != 0 )
operator delete(v35);
if ( *((_BYTE *)v11 + 1105) || !GameLevelManager::isPastDailyCopy((GameLevelManager *)this, v11) )
{
++v2;
}
else
{
v3 = 1;
++v2;
cocos2d::CCArray::addObject(SavedLevels, v11);
}
v6 = (GameManager *)cocos2d::CCArray::count(v5);
}
while ( v2 < (unsigned int)v6 );
}
if ( v3 )
qsort(
*(void **)(*((_QWORD *)SavedLevels + 7) + 16LL),
**((unsigned int **)SavedLevels + 7),
8u,
(int (*)(const void *, const void *))savedLevelCompare);
v12 = (GameManager *)GameManager::sharedState(v6);
v13 = 0;
if ( (unsigned __int8)GameManager::getGameVariable(v12, "0042") )
LODWORD(v14) = 100;
else
v14 = &byte_9[1];
v15 = (GameManager *)GameManager::sharedState((GameManager *)&byte_9[1]);
if ( (unsigned __int8)GameManager::getGameVariable(v15, "0119") )
LODWORD(v14) = -1;
while ( 1 )
{
v19 = (GameManager *)cocos2d::CCArray::count(SavedLevels);
if ( v13 >= (unsigned int)v19 )
break;
v16 = cocos2d::CCArray::objectAtIndex(SavedLevels, v13);
v18 = (int)v13++ > (int)v14;
*(_BYTE *)(v16 + 1104) = v18;
}
v20 = (GameManager *)GameManager::sharedState(v19);
if ( !(unsigned __int8)GameManager::getGameVariable(v20, "0127") )
{
v22 = 0;
v23 = (cocos2d::CCArray *)cocos2d::CCDictionary::allKeys(*(this + 117));
while ( 1 )
{
v24 = v22;
if ( (unsigned int)cocos2d::CCArray::count(v23) <= v22 )
break;
v25 = cocos2d::CCArray::count(v23);
v26 = (cocos2d::CCString *)cocos2d::CCArray::objectAtIndex(v23, v25 + ~v22);
v27 = (const char *)cocos2d::CCString::getCString(v26);
v33 = 0;
v34 = 0;
v35 = nullptr;
v32 = (char *)v27;
v28 = strlen(v27);
v29 = (__int64)*(this + 117);
std::string::__init(&v33, v32, v28);
v30 = cocos2d::CCDictionary::objectForKey(v29, &v33);
if ( (v33 & 1) != 0 )
operator delete(v35);
++v22;
*(_BYTE *)(v30 + 1104) = (int)(v13 + v24) > (int)v14;
}
}
return _stack_chk_guard;
}