//
// GameLevelManager::purgeUnusedLevels from 0x140222670 to 0x1402229b9 (841 bytes)
//
// 3 xrefs:
// > GameLevelManager::encodeDataTo @ 0x140224b9c
// > GameLevelManager::dataLoaded @ 0x140226434
// > ??> @ 0x14091bc50
//
// This function is hookable on this platform (idp: pc, 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 11:28:25 +0000
//
// Hidden C++ exception states: #wind=2
unsigned int __fastcall GameLevelManager::purgeUnusedLevels(__int64 a1)
{
cocos2d::CCArray *v2; // rbp
unsigned int v3; // esi
unsigned int result; // eax
__m128i si128; // xmm6
unsigned int v6; // eax
cocos2d::CCString *v7; // rax
const char *CString; // rax
const char *v9; // rdi
size_t v10; // r8
__int64 v11; // rcx
__int64 v12; // rbx
void *v13; // rcx
__int64 v14; // rax
int v15; // r8d
int v16; // ecx
size_t v17; // r8
void *v18; // rcx
__int128 v19; // [rsp+30h] [rbp-78h] BYREF
__m128i v20; // [rsp+40h] [rbp-68h]
__int128 v21; // [rsp+50h] [rbp-58h] BYREF
__int128 v22; // [rsp+60h] [rbp-48h]
v2 = cocos2d::CCDictionary::allKeys(*(cocos2d::CCDictionary **)(a1 + 856));
v3 = 0;
result = cocos2d::CCArray::count(v2);
if ( result )
{
si128 = _mm_load_si128((const __m128i *)&Size);
do
{
v6 = cocos2d::CCArray::count(v2);
v7 = cocos2d::CCArray::objectAtIndex(v2, v6 + ~v3);
CString = cocos2d::CCString::getCString(v7);
v9 = CString;
v19 = 0;
v20 = 0;
v10 = -1;
do
++v10;
while ( CString[v10] );
sub_14003D230(&v19, CString, v10);
v12 = cocos2d::CCDictionary::objectForKey(*(_QWORD *)(a1 + 856), &v19);
if ( v20.m128i_i64[1] > 0xFuLL )
{
v13 = (void *)v19;
if ( (unsigned __int64)(v20.m128i_i64[1] + 1) >= 0x1000 )
{
v13 = *(void **)(v19 - 8);
if ( (unsigned __int64)(v19 - (_QWORD)v13 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v13);
}
v20 = si128;
LOBYTE(v19) = 0;
if ( *(_BYTE *)(v12 + 1185) )
{
if ( *(int *)(v12 + 988) <= 0 && !*(_QWORD *)(v12 + 1648) )
{
if ( !*(_BYTE *)(v12 + 1976)
|| (v14 = GJAccountManager::sharedState(v11), *(_DWORD *)(v14 + 360) - *(_DWORD *)(v14 + 364) <= 0)
|| (v15 = *(_DWORD *)(v12 + 1980), v15 <= 0)
|| v15 < 1000
&& (int)((*(_DWORD *)(v12 + 328)
- 1640531535 * (*(_DWORD *)(v14 + 360) - *(_DWORD *)(v14 + 364))
- *(_DWORD *)(v12 + 332))
% 0x3E8u) >= v15 )
{
if ( (v16 = *(_DWORD *)(v12 + 932) - *(_DWORD *)(v12 + 928), v16 <= 0)
&& *(int *)(v12 + 960) <= 0
&& !*(_DWORD *)(v12 + 1416)
&& !*(_DWORD *)(v12 + 1464)
&& !*(_BYTE *)(v12 + 921)
|| *(_DWORD *)(v12 + 1020) - *(_DWORD *)(v12 + 1024) <= 0
&& (v16 < 10
&& *(_DWORD *)(v12 + 868) - *(_DWORD *)(v12 + 872) < 5
&& !*(_DWORD *)(v12 + 1416)
&& !*(_DWORD *)(v12 + 1464)
|| *(int *)(v12 + 972) <= 1
&& v16 < 100
&& *(_DWORD *)(v12 + 868) - *(_DWORD *)(v12 + 872) < 10
&& !*(_DWORD *)(v12 + 1416)
&& !*(_DWORD *)(v12 + 1464)) )
{
v21 = 0;
v22 = 0;
v17 = -1;
do
++v17;
while ( v9[v17] );
sub_14003D230(&v21, v9, v17);
cocos2d::CCDictionary::removeObjectForKey(*(_QWORD *)(a1 + 856), &v21);
if ( *((_QWORD *)&v22 + 1) > 0xFu )
{
v18 = (void *)v21;
if ( (unsigned __int64)(*((_QWORD *)&v22 + 1) + 1LL) >= 0x1000 )
{
v18 = *(void **)(v21 - 8);
if ( (unsigned __int64)(v21 - (_QWORD)v18 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v18);
}
}
}
}
}
++v3;
result = cocos2d::CCArray::count(v2);
}
while ( v3 < result );
}
return result;
}