//
// GameLevelManager::cleanupDailyLevels from 0x100539cb0 to 0x100539f3d (653 bytes)
//
// 1 xrefs:
// > GameLevelManager::encodeDataTo @ 0x10053af90
//
// 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::cleanupDailyLevels(GameLevelManager *a1)
{
double v1; // xmm0_8
GameLevelManager *v2; // r14
cocos2d::CCArray *v3; // rbx
int v4; // r15d
unsigned int v5; // r12d
int v6; // r15d
unsigned int v7; // r12d
int v8; // eax
cocos2d::CCString *v9; // rax
const char *CString; // r12
__int64 m_dailyLevels; // r13
size_t v12; // rax
size_t v13; // r15
char *v14; // rbx
__int64 v15; // rax
size_t v16; // r14
__int64 v17; // r15
int v18; // eax
__int64 v19; // r13
size_t v20; // rax
size_t v21; // r15
char *v22; // rbx
__int64 v23; // rax
size_t v24; // r14
int v25; // [rsp+Ch] [rbp-64h]
int v26; // [rsp+10h] [rbp-60h]
int v27; // [rsp+14h] [rbp-5Ch]
int v28; // [rsp+18h] [rbp-58h]
cocos2d::CCArray *v29; // [rsp+20h] [rbp-50h]
size_t __dst; // [rsp+28h] [rbp-48h] BYREF
size_t v31; // [rsp+30h] [rbp-40h]
void *__p; // [rsp+38h] [rbp-38h]
unsigned int v33; // [rsp+44h] [rbp-2Ch]
v2 = a1;
v3 = cocos2d::CCDictionary::allKeys(a1->m_dailyLevels);
if ( (unsigned int)sub_100720070(v3) )
{
v25 = 0;
v4 = -1;
v26 = 0;
v5 = 0;
v27 = 0;
v29 = v3;
while ( 1 )
{
v33 = v5;
v8 = sub_100720070(v3);
v28 = v4;
v9 = (cocos2d::CCString *)sub_1007200C0(v3, (unsigned int)(v8 + v4));
CString = cocos2d::CCString::getCString(v9);
m_dailyLevels = (__int64)v2->m_dailyLevels;
v12 = strlen(CString);
if ( v12 >= 0xFFFFFFFFFFFFFFF8LL )
LABEL_36:
sub_100006BF0(v1);
v13 = v12;
if ( v12 >= 0x17 )
break;
LOBYTE(__dst) = 2 * v12;
v14 = (char *)&__dst + 1;
if ( v12 )
goto LABEL_13;
LABEL_14:
v14[v13] = 0;
v17 = cocos2d::CCDictionary::objectForKey_1(m_dailyLevels, (char *)&__dst);
if ( (__dst & 1) != 0 )
operator delete(__p);
v18 = *(_DWORD *)(v17 + 804) - *(_DWORD *)(v17 + 808);
if ( v18 > 100000 )
{
if ( (unsigned int)v18 > 0x30D40 )
{
if ( v18 >= v27 )
{
v27 = *(_DWORD *)(v17 + 804) - *(_DWORD *)(v17 + 808);
goto LABEL_4;
}
}
else if ( v18 >= v26 )
{
v26 = *(_DWORD *)(v17 + 804) - *(_DWORD *)(v17 + 808);
goto LABEL_4;
}
}
else if ( v18 >= v25 )
{
v25 = *(_DWORD *)(v17 + 804) - *(_DWORD *)(v17 + 808);
goto LABEL_4;
}
*(_WORD *)(v17 + 992) = 257;
if ( *(_DWORD *)(v17 + 748) <= *(_DWORD *)(v17 + 752) )
{
v19 = (__int64)v2->m_dailyLevels;
v20 = strlen(CString);
if ( v20 >= 0xFFFFFFFFFFFFFFF8LL )
goto LABEL_36;
v21 = v20;
if ( v20 >= 0x17 )
{
v23 = v20 | 7;
v24 = 26;
if ( (v21 | 7) != 0x17 )
v24 = v23 + 1;
v22 = (char *)operator new(v24);
__p = v22;
__dst = v24 + 1;
v31 = v21;
v2 = a1;
}
else
{
LOBYTE(__dst) = 2 * v20;
v22 = (char *)&__dst + 1;
if ( !v20 )
{
LABEL_33:
v22[v21] = 0;
cocos2d::CCDictionary::removeObjectForKey_1(v19, (char *)&__dst);
v3 = v29;
v6 = v28;
v7 = v33;
if ( (__dst & 1) != 0 )
operator delete(__p);
goto LABEL_5;
}
}
memmove(v22, CString, v21);
goto LABEL_33;
}
LABEL_4:
v3 = v29;
v6 = v28;
v7 = v33;
LABEL_5:
v5 = v7 + 1;
v4 = v6 - 1;
if ( v5 >= (unsigned int)sub_100720070(v3) )
return;
}
v15 = v12 | 7;
v16 = 26;
if ( (v13 | 7) != 0x17 )
v16 = v15 + 1;
v14 = (char *)operator new(v16);
__p = v14;
__dst = v16 + 1;
v31 = v13;
v2 = a1;
LABEL_13:
memmove(v14, CString, v13);
goto LABEL_14;
}
}