//
// GameLevelManager::limitSavedLevels from 0x100539770 to 0x100539995 (549 bytes)
//
// 2 xrefs:
// > GameLevelManager::encodeDataTo @ 0x10053af5a
// > GameLevelManager::dataLoaded @ 0x10053c8e3
//
// 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 __fastcall GameLevelManager::limitSavedLevels(GameLevelManager *a1)
{
double v1; // xmm0_8
unsigned int v2; // r14d
cocos2d::CCArray *SavedLevels; // r15
GameManager *v4; // rax
int v5; // ebx
GameManager *v6; // rax
int v7; // r12d
GameManager *v8; // rax
cocos2d::CCArray *v9; // r15
int v10; // r13d
int v11; // ebx
int v12; // eax
cocos2d::CCString *v13; // rax
const char *CString; // rbx
cocos2d::CCDictionary *m_gauntletLevels; // r13
size_t v16; // rax
size_t v17; // r12
char *v18; // r15
__int64 v19; // rax
size_t v20; // r13
__int64 v21; // rbx
int v22; // r12d
int v23; // [rsp+0h] [rbp-70h]
int v24; // [rsp+8h] [rbp-68h]
cocos2d::CCArray *v25; // [rsp+10h] [rbp-60h]
cocos2d::CCDictionary *v26; // [rsp+18h] [rbp-58h]
_QWORD __dst[2]; // [rsp+28h] [rbp-48h] BYREF
void *__p; // [rsp+38h] [rbp-38h]
int v29; // [rsp+44h] [rbp-2Ch]
v2 = 0;
SavedLevels = GameLevelManager::getSavedLevels(a1, 0, 0);
v4 = GameManager::sharedState();
v5 = 10;
if ( GameManager::getGameVariable(v4, "0042") )
v5 = 100;
v6 = GameManager::sharedState();
v7 = -1;
if ( !GameManager::getGameVariable(v6, "0119") )
v7 = v5;
if ( (unsigned int)sub_100720070(SavedLevels) )
{
v2 = 0;
do
{
*(_BYTE *)(sub_1007200C0(SavedLevels, v2) + 992) = (int)v2 > v7;
++v2;
}
while ( v2 < (unsigned int)sub_100720070(SavedLevels) );
}
v8 = GameManager::sharedState();
if ( !GameManager::getGameVariable(v8, "0127") )
{
v9 = cocos2d::CCDictionary::allKeys(a1->m_gauntletLevels);
if ( (unsigned int)sub_100720070(v9) )
{
v10 = 0;
v11 = -1;
v25 = v9;
v29 = v7;
do
{
v23 = v10;
v12 = sub_100720070(v9);
v24 = v11;
v13 = (cocos2d::CCString *)sub_1007200C0(v9, (unsigned int)(v12 + v11));
CString = cocos2d::CCString::getCString(v13);
m_gauntletLevels = a1->m_gauntletLevels;
v16 = strlen(CString);
if ( v16 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100006BF0(v1);
v17 = v16;
if ( v16 >= 0x17 )
{
v26 = a1->m_gauntletLevels;
v19 = v16 | 7;
v20 = 26;
if ( (v17 | 7) != 0x17 )
v20 = v19 + 1;
v18 = (char *)operator new(v20);
__p = v18;
__dst[0] = v20 + 1;
__dst[1] = v17;
m_gauntletLevels = v26;
}
else
{
LOBYTE(__dst[0]) = 2 * v16;
v18 = (char *)__dst + 1;
if ( !v16 )
goto LABEL_20;
}
memmove(v18, CString, v17);
LABEL_20:
v18[v17] = 0;
v21 = cocos2d::CCDictionary::objectForKey_1((__int64)m_gauntletLevels, (char *)__dst);
v22 = v29;
v9 = v25;
if ( (__dst[0] & 1) != 0 )
operator delete(__p);
*(_BYTE *)(v21 + 992) = (int)(v2 + v23) > v22;
v10 = v23 + 1;
v11 = v24 - 1;
}
while ( v23 + 1 < (unsigned int)sub_100720070(v25) );
}
}
}