//
// LocalLevelManager::tryLoadMainLevelString from 0x7ea310 to 0x7ea590 (640 bytes)
//
// 2 xrefs:
// > LocalLevelManager::getMainLevelString @ 0x7ea5bc
// > ??> @ 0xb14f8
//
// 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 LocalLevelManager::tryLoadMainLevelString(LocalLevelManager *a1, int a2)
{
char **p_m_mainLevels; // x20
cocos2d::CCFileUtils *v3; // x21
cocos2d::CCString *v4; // x0
char *CString; // x0
cocos2d::CCString *v6; // x0
char *v7; // x0
__int64 v8; // x1
void *v9; // x0
int *p_m_unknown2; // x0
void *v11; // x0
unsigned int *v12; // x1
int v13; // w2
char *v14; // x0
unsigned int *v15; // x1
int v16; // w2
unsigned int *p_m_sString; // x1
int m_data; // w2
char *v19; // [xsp+3Ch] [xbp+3Ch] BYREF
__int64 v20; // [xsp+50h] [xbp+50h] BYREF
cocos2d::CCString *v21; // [xsp+58h] [xbp+58h] BYREF
__int64 v22; // [xsp+60h] [xbp+60h] BYREF
p_m_mainLevels = (char **)&a1->m_mainLevels;
LODWORD(v19) = a2;
if ( !sub_7E8504(&a1->m_mainLevels._M_h._M_buckets, a2) )
{
v3 = cocos2d::CCFileUtils::sharedFileUtils();
v4 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"levels/%i.txt",
(const char *)(unsigned int)v19);
CString = (char *)cocos2d::CCString::getCString(v4);
sub_D153B8((int)&v20, CString);
((void (__fastcall *)(cocos2d::CCString **__return_ptr, cocos2d::CCFileUtils *, __int64, _QWORD))v3->createCCArrayWithContentsOfFile)(
&v21,
v3,
v20,
0);
v6 = cocos2d::CCString::createWithContentsOfFile((const char *)v21);
if ( v6 )
{
v7 = (char *)cocos2d::CCString::getCString(v6);
sub_D153B8((int)&v22, v7);
v8 = v22;
if ( *(_QWORD *)(v22 - 24) )
{
v14 = std::__detail::_Map_base,std::allocator>,std::__detail::_Select1st,std::equal_to,std::hash,std::__detail::_Mod_range_hashing,std::__detail::_Default_ranged_hash,std::__detail::_Prime_rehash_policy,std::__detail::_Hashtable_traits,true>::operator[](
p_m_mainLevels,
(int *)&v19);
sub_D18EA8(v14, &v22);
v8 = v22;
}
v9 = (void *)(v8 - 24);
if ( (__int64 *)(v8 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v15 = (unsigned int *)(v8 - 8);
do
v16 = __ldaxr(v15);
while ( __stlxr(v16 - 1, v15) );
}
else
{
v16 = *(_DWORD *)(v8 - 8);
*(_DWORD *)(v8 - 8) = v16 - 1;
}
if ( v16 <= 0 )
operator delete(v9);
}
}
p_m_unknown2 = &v21[-1].m_unknown2;
if ( &v21[-1].m_unknown2 != (int *)&qword_124B6B0 )
{
if ( &pthread_create )
{
p_m_sString = (unsigned int *)&v21[-1].m_sString;
do
m_data = __ldaxr(p_m_sString);
while ( __stlxr(m_data - 1, p_m_sString) );
}
else
{
m_data = (int)v21[-1].m_sString.m_data.m_data;
LODWORD(v21[-1].m_sString.m_data.m_data) = m_data - 1;
}
if ( m_data <= 0 )
operator delete(p_m_unknown2);
}
v11 = (void *)(v20 - 24);
if ( (__int64 *)(v20 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v12 = (unsigned int *)(v20 - 8);
do
v13 = __ldaxr(v12);
while ( __stlxr(v13 - 1, v12) );
}
else
{
v13 = *(_DWORD *)(v20 - 8);
*(_DWORD *)(v20 - 8) = v13 - 1;
}
if ( v13 <= 0 )
operator delete(v11);
}
}
}