//
// GJLevelList::addLevelToList from 0x100562660 to 0x100562814 (436 bytes)
//
// 2 xrefs:
// > LevelInfoLayer::cellPerformedAction @ 0x1002c2ae4
// > GJLevelList::duplicateListLevels @ 0x100561fc1
//
// 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 GJLevelList::addLevelToList(GJLevelList *a1, GJGameLevel *a2)
{
double v2; // xmm0_8
std::__vector_base::pointer begin; // rsi
std::__vector_base::pointer end; // r12
int v7; // r14d
std::__vector_base::pointer v8; // rax
int *value; // rax
int *v10; // r14
signed __int64 v11; // r12
__int64 v12; // rdi
__int64 v13; // rax
unsigned __int64 v14; // r15
_DWORD *v15; // r13
void *v16; // r15
cocos2d::CCDictionary *m_levelsDict; // r15
GJGameLevel *ListSnapshot; // r12
size_t v19[3]; // [rsp+8h] [rbp-58h] BYREF
void *__src; // [rsp+20h] [rbp-40h]
GJGameLevel *v21; // [rsp+28h] [rbp-38h]
__int64 v22; // [rsp+30h] [rbp-30h]
begin = a1->m_levels.__begin_;
end = a1->m_levels.__end_;
v7 = a2->m_levelID.random - a2->m_levelID.seed;
if ( begin == end )
{
LABEL_5:
value = a1->m_levels.__end_cap_.__value_;
if ( end >= value )
{
v11 = (char *)end - (char *)begin;
v12 = v11 >> 2;
if ( (unsigned __int64)((v11 >> 2) + 1) >> 62 )
sub_1000C40D0();
v13 = (char *)value - (char *)begin;
v14 = v13 >> 1;
if ( v13 >> 1 <= (unsigned __int64)((v11 >> 2) + 1) )
v14 = (v11 >> 2) + 1;
if ( (unsigned __int64)v13 >= 0x7FFFFFFFFFFFFFFCLL )
v14 = 0x3FFFFFFFFFFFFFFFLL;
v21 = a2;
__src = begin;
if ( v14 )
{
v22 = v11 >> 2;
if ( v14 > 0x3FFFFFFFFFFFFFFFLL )
sub_100054850();
v15 = operator new(4 * v14);
v12 = v22;
}
else
{
v15 = nullptr;
}
v22 = (__int64)&v15[v14];
v15[v12] = v7;
v10 = &v15[v12 + 1];
v16 = __src;
memcpy(v15, __src, v11);
a1->m_levels.__begin_ = v15;
a1->m_levels.__end_ = v10;
a1->m_levels.__end_cap_.__value_ = (int *)v22;
if ( v16 )
operator delete(v16);
a2 = v21;
}
else
{
*end = v7;
v10 = end + 1;
}
a1->m_levels.__end_ = v10;
GJLevelList::updateLevelsString(a1);
m_levelsDict = a1->m_levelsDict;
ListSnapshot = GJGameLevel::getListSnapshot(a2);
GameToolbox::intToString(v19, a2->m_levelID.random - a2->m_levelID.seed, v2);
cocos2d::CCDictionary::setObject_1((__int64)m_levelsDict, ListSnapshot, (char *)v19);
if ( (v19[0] & 1) != 0 )
operator delete((void *)v19[2]);
a1->m_modified = 1;
}
else
{
v8 = a1->m_levels.__begin_;
while ( *v8 != v7 )
{
if ( ++v8 == end )
goto LABEL_5;
}
}
}