//
// LocalLevelManager::tryLoadMainLevelString from 0x140330010 to 0x140330283 (627 bytes)
//
// 2 xrefs:
// > LocalLevelManager::getMainLevelString @ 0x1403302af
// > ??> @ 0x1406d4ff4
//
// 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=3
void LocalLevelManager::tryLoadMainLevelString(LocalLevelManager *a1, int a2)
{
_QWORD *v3; // rcx
__int64 v4; // rax
__int64 v5; // rdi
cocos2d::CCString *v6; // rax
const char *CString; // rax
size_t v8; // rbx
size_t v9; // r8
void **v10; // r8
const char *v11; // rcx
cocos2d::CCString *v12; // rax
const char *v13; // rax
size_t v14; // rbx
void **v15; // rcx
void **v16; // rdx
void *v17; // rcx
void *v18; // rcx
int v19; // [rsp+20h] [rbp-39h] BYREF
_BYTE v20[16]; // [rsp+28h] [rbp-31h] BYREF
void *Block[2]; // [rsp+38h] [rbp-21h] BYREF
size_t Size; // [rsp+48h] [rbp-11h]
unsigned __int64 v23; // [rsp+50h] [rbp-9h]
void *v24[2]; // [rsp+58h] [rbp-1h] BYREF
__int128 v25; // [rsp+68h] [rbp+Fh]
_QWORD v26[4]; // [rsp+78h] [rbp+1Fh] BYREF
v19 = a2;
v3 = (_QWORD *)((char *)a1->m_mainLevels._Vec._Mypair._Myval2._Myfirst
+ 16
* ((0x100000001B3LL
* (HIBYTE(a2)
^ (0x100000001B3LL
* (BYTE2(a2)
^ (0x100000001B3LL * (BYTE1(a2) ^ (0x100000001B3LL * ((unsigned __int8)a2 ^ 0xCBF29CE484222325uLL))))))))
& a1->m_mainLevels._Mask));
v4 = v3[1];
if ( (std::_List_val>>::_Nodeptr)v4 != a1->m_mainLevels._List._Mypair._Myval2._Myhead )
{
v3 = (_QWORD *)*v3;
if ( a2 == *(_DWORD *)(v4 + 16) )
goto LABEL_7;
while ( (_QWORD *)v4 != v3 )
{
v4 = *(_QWORD *)(v4 + 8);
if ( a2 == *(_DWORD *)(v4 + 16) )
goto LABEL_7;
}
}
v4 = 0;
LABEL_7:
if ( !v4 )
{
v5 = cocos2d::CCFileUtils::sharedFileUtils(v3);
v6 = cocos2d::CCString::createWithFormat("levels/%i.txt", v19);
CString = cocos2d::CCString::getCString(v6);
*(_OWORD *)v24 = 0;
v25 = 0;
v8 = -1;
v9 = -1;
do
++v9;
while ( CString[v9] );
sub_14003A930(v24, CString, v9);
v10 = v24;
if ( *((_QWORD *)&v25 + 1) > 0xFu )
v10 = (void **)v24[0];
(*(void (__fastcall **)(__int64, _QWORD *, void **, _QWORD))(*(_QWORD *)v5 + 40LL))(v5, v26, v10, 0);
v11 = (const char *)v26;
if ( v26[3] > 0xFu )
v11 = (const char *)v26[0];
v12 = cocos2d::CCString::createWithContentsOfFile(v11);
if ( v12 )
{
v13 = cocos2d::CCString::getCString(v12);
*(_OWORD *)Block = 0;
Size = 0;
v23 = 0;
do
++v8;
while ( v13[v8] );
sub_14003A930(Block, v13, v8);
v14 = Size;
if ( Size )
{
v15 = (void **)(*(_QWORD *)sub_1400608D0((__int64)&a1->m_mainLevels, (__int64)v20, (unsigned __int8 *)&v19)
+ 24LL);
if ( v15 != Block )
{
v16 = Block;
if ( v23 > 0xF )
v16 = (void **)Block[0];
sub_14003CCE0(v15, v16, v14);
}
}
if ( v23 > 0xF )
{
v17 = Block[0];
if ( v23 + 1 >= 0x1000 )
{
v17 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v17 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v17);
}
}
sub_14003A830((__int64)v26);
if ( *((_QWORD *)&v25 + 1) > 0xFu )
{
v18 = v24[0];
if ( (unsigned __int64)(*((_QWORD *)&v25 + 1) + 1LL) >= 0x1000 )
{
v18 = *((void **)v24[0] - 1);
if ( (unsigned __int64)((char *)v24[0] - (char *)v18 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v18);
}
}
}