//
// GJLevelList::addLevelToList from 0x736540 to 0x7366e8 (424 bytes)
//
// 3 xrefs:
// > LevelInfoLayer::cellPerformedAction @ 0x6d6670
// > GJLevelList::duplicateListLevels @ 0x736720
// > ??> @ 0x9f1b0
//
// 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 GJLevelList::addLevelToList(GJLevelList *a1, GJGameLevel *a2)
{
int *m_start; // x0
int *m_finish; // x2
int random; // w3
int seed; // w4
int v8; // w3
int *i; // x0
int v10; // t1
int *m_reserveEnd; // x1
cocos2d::CCDictionary *m_levelsDict; // x23
void *v13; // x0
unsigned int *v14; // x2
int v15; // w1
GJGameLevel *ListSnapshot; // [xsp+48h] [xbp+48h]
__int64 v17; // [xsp+60h] [xbp+60h] BYREF
m_start = a1->m_levels.m_start;
m_finish = a1->m_levels.m_finish;
random = a2->m_levelID.random;
seed = a2->m_levelID.seed;
if ( m_finish == m_start )
{
v8 = random - seed;
}
else
{
v8 = random - seed;
if ( *m_start == v8 )
return;
for ( i = m_start + 1; m_finish != i; ++i )
{
v10 = *i;
if ( v10 == v8 )
return;
}
}
m_reserveEnd = a1->m_levels.m_reserveEnd;
LODWORD(v17) = v8;
if ( m_finish == m_reserveEnd )
{
std::vector::_M_emplace_back_aux((__int64)&a1->m_levels, &v17);
}
else
{
if ( m_finish )
*m_finish = v8;
a1->m_levels.m_finish = m_finish + 1;
}
GJLevelList::updateLevelsString(a1);
m_levelsDict = a1->m_levelsDict;
ListSnapshot = GJGameLevel::getListSnapshot(a2);
GameToolbox::intToString(&v17, (GameToolbox *)(unsigned int)(a2->m_levelID.random - a2->m_levelID.seed));
cocos2d::CCDictionary::setObject((int)m_levelsDict, ListSnapshot);
v13 = (void *)(v17 - 24);
if ( (__int64 *)(v17 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v14 = (unsigned int *)(v17 - 8);
do
v15 = __ldaxr(v14);
while ( __stlxr(v15 - 1, v14) );
}
else
{
v15 = *(_DWORD *)(v17 - 8);
*(_DWORD *)(v17 - 8) = v15 - 1;
}
if ( v15 <= 0 )
operator delete(v13);
}
a1->m_modified = 1;
}