//
// GameLevelManager::limitSavedLevels from 0x14014a190 to 0x14014a428 (664 bytes)
//
// 3 xrefs:
// > GameLevelManager::encodeDataTo @ 0x14014af34
// > GameLevelManager::dataLoaded @ 0x14014c4fc
// > ??> @ 0x1406ca728
//
// 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
//
// Hidden C++ exception states: #wind=4
void GameLevelManager::limitSavedLevels(GameLevelManager *a1)
{
cocos2d::CCArray *SavedLevels; // rsi
GameManager *v3; // rcx
int v4; // ebp
GameManager *v5; // rcx
int v6; // ebx
unsigned int i; // edi
GameManager *v8; // rcx
cocos2d::CCArray *v9; // r14
unsigned int j; // edi
unsigned int v11; // eax
cocos2d::CCString *v12; // rax
const char *CString; // rax
size_t v14; // r8
__int64 v15; // rsi
void *v16; // rcx
void *v17; // [rsp+20h] [rbp-58h]
void *v18; // [rsp+20h] [rbp-58h]
void *v19; // [rsp+20h] [rbp-58h]
__int128 v20; // [rsp+28h] [rbp-50h] BYREF
__int64 v21; // [rsp+38h] [rbp-40h]
unsigned __int64 v22; // [rsp+40h] [rbp-38h]
SavedLevels = GameLevelManager::getSavedLevels(a1, 0, 0);
v3 = (GameManager *)qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v17 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00(v17);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v3 = (GameManager *)qword_1406C2ED8;
}
v4 = 10;
if ( GameManager::getGameVariable(v3, "0042") )
v4 = 100;
v5 = (GameManager *)qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v18 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00(v18);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v5 = (GameManager *)qword_1406C2ED8;
}
if ( GameManager::getGameVariable(v5, "0119") )
v4 = -1;
v6 = 0;
for ( i = 0; i < cocos2d::CCArray::count(SavedLevels); ++i )
LOBYTE(cocos2d::CCArray::objectAtIndex(SavedLevels, i)[19].m_uID) = v6++ > v4;
v8 = (GameManager *)qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v19 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00(v19);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v8 = (GameManager *)qword_1406C2ED8;
}
if ( !GameManager::getGameVariable(v8, "0127") )
{
v9 = cocos2d::CCDictionary::allKeys(a1->m_gauntletLevels);
for ( j = 0; j < cocos2d::CCArray::count(v9); ++j )
{
v11 = cocos2d::CCArray::count(v9);
v12 = (cocos2d::CCString *)cocos2d::CCArray::objectAtIndex(v9, v11 + -1 - j);
CString = cocos2d::CCString::getCString(v12);
v20 = 0;
v21 = 0;
v22 = 0;
v14 = -1;
do
++v14;
while ( CString[v14] );
sub_14003A930(&v20, CString, v14);
v15 = cocos2d::CCDictionary::objectForKey(a1->m_gauntletLevels, &v20);
if ( v22 > 0xF )
{
v16 = (void *)v20;
if ( v22 + 1 >= 0x1000 )
{
v16 = *(void **)(v20 - 8);
if ( (unsigned __int64)(v20 - (_QWORD)v16 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v16);
}
*(_BYTE *)(v15 + 1072) = v6++ > v4;
}
}
}