//
// GameLevelManager::limitSavedLevels from 0x1000ae3a4 to 0x1000ae624 (640 bytes)
//
// 2 xrefs:
// > GameLevelManager::encodeDataTo @ 0x1000b112c
// > GameLevelManager::dataLoaded @ 0x1000b204c
//
// 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 10:58:37 +0000
//
__int64 __fastcall GameLevelManager::limitSavedLevels(__int64 a1)
{
__int64 SavedLevels; // x20
__int64 v3; // x21
__int64 v4; // x0
char v5; // w8
__int64 v6; // x22
__int64 v7; // x23
__int64 v8; // x0
char *CString; // x0
__int64 v10; // x23
int v11; // w8
__int64 v12; // x9
unsigned int v13; // w0
__int64 v14; // x0
__int64 GameVariable; // x0
int v16; // w21
__int64 v17; // x0
int v18; // w23
__int64 v19; // x0
__int64 i; // x21
__int64 v21; // x0
__int64 result; // x0
__int64 v23; // x20
unsigned int v24; // w24
int v25; // w25
int v26; // w0
__int64 v27; // x0
char *v28; // x0
__int64 v29; // x22
__int64 v30; // x22
char v31; // [xsp+4h] [xbp-6Ch]
void *__p[2]; // [xsp+8h] [xbp-68h] BYREF
char v33; // [xsp+1Fh] [xbp-51h]
SavedLevels = GameLevelManager::getSavedLevels(a1, 0, 0);
v3 = cocos2d::CCDictionary::allKeys(*(_QWORD *)(a1 + 848));
v4 = sub_1002E757C(v3);
if ( (_DWORD)v4 )
{
v5 = 0;
v6 = 0;
LABEL_3:
v31 = v5;
do
{
v7 = *(_QWORD *)(a1 + 848);
v8 = sub_1002E75A0(v3, v6);
CString = (char *)cocos2d::CCString::getCString(v8);
sub_100009900(__p, CString);
v10 = cocos2d::CCDictionary::objectForKey(v7, __p);
if ( v33 < 0 )
operator delete(__p[0]);
if ( (*(_BYTE *)(v10 + 1105) & 1) == 0 )
{
v11 = *(_DWORD *)(v10 + 920) - *(_DWORD *)(v10 + 924);
if ( v11 >= 1 )
{
if ( (unsigned int)v11 <= 0x186A0 )
v12 = 864;
else
v12 = 876;
if ( (unsigned int)v11 > 0x30D40 )
v12 = 888;
if ( v11 != *(_DWORD *)(a1 + v12) )
{
sub_1002E74E0(SavedLevels, v10);
v6 = (unsigned int)(v6 + 1);
v13 = sub_1002E757C(v3);
v5 = 1;
if ( (unsigned int)v6 < v13 )
goto LABEL_3;
goto LABEL_19;
}
}
}
v6 = (unsigned int)(v6 + 1);
v4 = sub_1002E757C(v3);
}
while ( (unsigned int)v6 < (unsigned int)v4 );
if ( (v31 & 1) == 0 )
goto LABEL_20;
LABEL_19:
qsort(
*(void **)(*(_QWORD *)(SavedLevels + 56) + 16LL),
**(unsigned int **)(SavedLevels + 56),
8u,
(int (__cdecl *)(const void *, const void *))sub_100090E9C);
}
LABEL_20:
v14 = GameManager::sharedState(v4);
GameVariable = GameManager::getGameVariable(v14, "0042");
if ( (_DWORD)GameVariable )
v16 = 100;
else
v16 = 10;
v17 = GameManager::sharedState(GameVariable);
if ( (unsigned int)GameManager::getGameVariable(v17, "0119") )
v18 = -1;
else
v18 = v16;
v19 = sub_1002E757C(SavedLevels);
for ( i = 0; (unsigned int)i < (unsigned int)v19; v19 = sub_1002E757C(SavedLevels) )
{
*(_BYTE *)(sub_1002E75A0(SavedLevels, i) + 1104) = (int)i > v18;
i = (unsigned int)(i + 1);
}
v21 = GameManager::sharedState(v19);
result = GameManager::getGameVariable(v21, "0127");
if ( (result & 1) == 0 )
{
v23 = cocos2d::CCDictionary::allKeys(*(_QWORD *)(a1 + 936));
result = sub_1002E757C(v23);
if ( (_DWORD)result )
{
v24 = 0;
v25 = -1;
do
{
v26 = sub_1002E757C(v23);
v27 = sub_1002E75A0(v23, (unsigned int)(v26 + v25));
v28 = (char *)cocos2d::CCString::getCString(v27);
v29 = *(_QWORD *)(a1 + 936);
sub_100009900(__p, v28);
v30 = cocos2d::CCDictionary::objectForKey(v29, __p);
if ( v33 < 0 )
operator delete(__p[0]);
*(_BYTE *)(v30 + 1104) = (int)(i + v24++) > v18;
result = sub_1002E757C(v23);
--v25;
}
while ( v24 < (unsigned int)result );
}
}
return result;
}