//
// EditorPauseLayer::saveLevel from 0x78e1a0 to 0x78e830 (1680 bytes)
//
// 4 xrefs:
// > EditorPauseLayer::onSaveAndPlay @ 0x78e880
// > EditorPauseLayer::onSaveAndExit @ 0x78e940
// > EditorPauseLayer::FLAlert_Clicked @ 0x78ea04
// > ??> @ 0x8c928
//
// 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 EditorPauseLayer::saveLevel(EditorPauseLayer *a1)
{
LevelEditorLayer *m_editorLayer; // x0
GJGameLevel *m_level; // x19
_DWORD *v4; // x24
__int64 *v5; // x27
unsigned __int64 v6; // x26
unsigned __int64 v7; // x20
size_t v8; // x2
int v9; // w3
signed __int64 v10; // x22
unsigned int v11; // w0
void *v12; // x0
LevelEditorLayer *v13; // x0
int m_audioTrack; // w2
float LastObjectX; // s0
DrawGridLayer *m_drawGridLayer; // x24
float v17; // s0
LevelEditorLayer *v18; // x0
int m_timestamp; // w1
int LengthKey; // w0
LevelEditorLayer *v21; // x1
int v22; // w24
int v23; // w0
LevelEditorLayer *v24; // x1
bool m_hasHighDetail; // w3
float v26; // s0
int random; // w0
int seed; // w2
float m_sessionTime; // s0
void *v30; // x0
void *v31; // x0
float v32; // s0
float v33; // s1
LevelEditorLayer *v34; // x0
void *v35; // x0
void *v36; // x0
LocalLevelManager *v37; // x0
void *v38; // x0
unsigned int *v39; // x24
int v40; // w0
unsigned int *v41; // x1
int v42; // w2
unsigned int *v43; // x1
int v44; // w2
unsigned int *v45; // x1
int v46; // w2
unsigned int *v47; // x1
int v48; // w2
unsigned int *v49; // x1
int v50; // w2
unsigned int *v51; // x19
int v52; // w1
bool v53[9]; // [xsp+6Fh] [xbp+6Fh] BYREF
void *v54; // [xsp+78h] [xbp+78h] BYREF
__int64 v55; // [xsp+80h] [xbp+80h] BYREF
__int64 v56; // [xsp+88h] [xbp+88h] BYREF
__int64 v57; // [xsp+90h] [xbp+90h] BYREF
__int64 v58; // [xsp+98h] [xbp+98h] BYREF
cocos2d::CCPoint v59; // [xsp+A0h] [xbp+A0h] BYREF
cocos2d::CCPoint v60; // 0:s0.4,4:s1.4
m_editorLayer = a1->m_editorLayer;
m_level = m_editorLayer->m_level;
LevelEditorLayer::getLevelString(m_editorLayer, (__int64)&v53[1]);
sub_D18D28(&v54);
v4 = v54;
v5 = (__int64 *)((char *)v54 - 24);
v6 = *((_QWORD *)v54 - 3);
v7 = *(_QWORD *)(*(_QWORD *)&v53[1] - 24LL);
if ( v7 > v6 )
v8 = *((_QWORD *)v54 - 3);
else
v8 = *(_QWORD *)(*(_QWORD *)&v53[1] - 24LL);
LODWORD(v10) = memcmp(v54, *(const void **)&v53[1], v8);
if ( (_DWORD)v10 )
{
LABEL_7:
if ( v5 == &qword_124B6B0 )
goto LABEL_8;
goto LABEL_31;
}
v10 = v6 - v7;
v11 = 0x7FFFFFFF;
if ( (__int64)(v6 - v7) > 0x7FFFFFFF || (v11 = 0x80000000, v10 < (__int64)0xFFFFFFFF80000000LL) )
{
LODWORD(v10) = v11;
goto LABEL_7;
}
if ( v5 == &qword_124B6B0 )
goto LABEL_29;
LABEL_31:
if ( &pthread_create )
{
v39 = v4 - 2;
do
v40 = __ldaxr(v39);
while ( __stlxr(v40 - 1, v39) );
}
else
{
v40 = *(v4 - 2);
*(v4 - 2) = v40 - 1;
}
if ( v40 > 0 )
{
LABEL_29:
if ( !(_DWORD)v10 )
goto LABEL_9;
goto LABEL_8;
}
operator delete(v5);
if ( !(_DWORD)v10 )
goto LABEL_9;
LABEL_8:
GJGameLevel::levelWasAltered(m_level);
LABEL_9:
cocos2d::ZipUtils::compressString((cocos2d::ZipUtils *)&v53[1], nullptr, 11, v9);
sub_D18EA8(&m_level->m_levelString, &v55);
v12 = (void *)(v55 - 24);
if ( (__int64 *)(v55 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v49 = (unsigned int *)(v55 - 8);
do
v50 = __ldaxr(v49);
while ( __stlxr(v50 - 1, v49) );
}
else
{
v50 = *(_DWORD *)(v55 - 8);
*(_DWORD *)(v55 - 8) = v50 - 1;
}
if ( v50 <= 0 )
operator delete(v12);
}
sub_D174B8(&v53[1], 0, *(_QWORD *)(*(_QWORD *)&v53[1] - 24LL), 0);
v13 = a1->m_editorLayer;
m_audioTrack = v13->m_level->m_audioTrack;
m_level->m_twoPlayerMode = v13->m_levelSettings->m_twoPlayerMode;
m_level->m_audioTrack = m_audioTrack;
LastObjectX = LevelEditorLayer::getLastObjectX(v13);
m_drawGridLayer = a1->m_editorLayer->m_drawGridLayer;
cocos2d::CCPoint::CCPoint(&v59, LastObjectX + 340.0, 0.0);
v17 = DrawGridLayer::timeForPos(m_drawGridLayer, v60, (int)&v59, 0, 0, 0, 0, 0);
v18 = a1->m_editorLayer;
m_timestamp = v18->m_level->GJBaseGameLayer::m_timestamp;
if ( m_timestamp > 0 && v17 < (float)((float)m_timestamp / 240.0) )
v17 = (float)m_timestamp / 240.0;
LengthKey = GJGameLevel::getLengthKey((int)v17, v18->m_levelSettings->m_platformerMode);
v21 = a1->m_editorLayer;
m_level->m_levelLength = LengthKey;
v22 = v21->m_objectCount.random - v21->m_objectCount.seed;
m_level->m_objectCount.value = v22;
v23 = rand();
v24 = a1->m_editorLayer;
m_hasHighDetail = v24->m_hasHighDetail;
v26 = (float)((float)v23 * 4.6566e-10) * 1000.0;
m_level->m_objectCount.seed = (int)v26;
m_level->m_objectCount.random = v22 + (int)v26;
random = v24->m_coinCount.random;
seed = v24->m_coinCount.seed;
m_level->m_lowDetailMode = m_hasHighDetail;
m_level->m_coins = random - seed;
if ( v22 > 40000 )
{
if ( v22 > 80000 )
goto LABEL_16;
}
else
{
m_level->m_highObjectsEnabled = 0;
}
m_level->m_unlimitedObjectsEnabled = 0;
LABEL_16:
m_sessionTime = v24->m_sessionTime;
m_level->m_workingTime += vcvtms_s32_f32(m_sessionTime);
LevelEditorLayer::getLockedLayers(v24, (__int64)&v56);
sub_D18EA8(&m_level->m_lockedEditorLayers, &v56);
v30 = (void *)(v56 - 24);
if ( (__int64 *)(v56 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v41 = (unsigned int *)(v56 - 8);
do
v42 = __ldaxr(v41);
while ( __stlxr(v42 - 1, v41) );
}
else
{
v42 = *(_DWORD *)(v56 - 8);
*(_DWORD *)(v56 - 8) = v42 - 1;
}
if ( v42 <= 0 )
operator delete(v30);
}
LevelEditorLayer::getSavedEditorPositions(a1->m_editorLayer, (__int64)&v57);
sub_D18EA8(&m_level->m_savedCameraPositions, &v57);
v31 = (void *)(v57 - 24);
if ( (__int64 *)(v57 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v43 = (unsigned int *)(v57 - 8);
do
v44 = __ldaxr(v43);
while ( __stlxr(v44 - 1, v43) );
}
else
{
v44 = *(_DWORD *)(v57 - 8);
*(_DWORD *)(v57 - 8) = v44 - 1;
}
if ( v44 <= 0 )
operator delete(v31);
}
cocos2d::CCPoint::CCPoint(&v59, &a1->m_editorLayer->m_previewPosition);
cocos2d::CCPoint::operator=(&m_level->m_previewLock, v32, v33);
v34 = a1->m_editorLayer;
v53[0] = 0;
LevelEditorLayer::getSongIDs(v34, v53, (__int64)&v58);
sub_D163D4(&m_level->m_songIDs, &v58);
v35 = (void *)(v58 - 24);
if ( (__int64 *)(v58 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v45 = (unsigned int *)(v58 - 8);
do
v46 = __ldaxr(v45);
while ( __stlxr(v46 - 1, v45) );
}
else
{
v46 = *(_DWORD *)(v58 - 8);
*(_DWORD *)(v58 - 8) = v46 - 1;
}
if ( v46 <= 0 )
operator delete(v35);
}
LevelEditorLayer::getSFXIDs(a1->m_editorLayer, (__int64)&v59);
sub_D163D4(&m_level->m_sfxIDs, &v59);
v36 = (void *)(*(_QWORD *)&v59 - 24LL);
if ( (__int64 *)(*(_QWORD *)&v59 - 24LL) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v47 = (unsigned int *)(*(_QWORD *)&v59 - 8LL);
do
v48 = __ldaxr(v47);
while ( __stlxr(v48 - 1, v47) );
}
else
{
v48 = *(_DWORD *)(*(_QWORD *)&v59 - 8LL);
*(_DWORD *)(*(_QWORD *)&v59 - 8LL) = v48 - 1;
}
if ( v48 <= 0 )
operator delete(v36);
}
if ( !*((_QWORD *)m_level->m_sfxIDs.m_data.m_data - 3) && !v53[0] )
sub_D1798C(&m_level->m_songIDs, &byte_F288A0, 0);
v37 = LocalLevelManager::sharedState();
GManager::save(v37);
v38 = (void *)(*(_QWORD *)&v53[1] - 24LL);
if ( (__int64 *)(*(_QWORD *)&v53[1] - 24LL) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v51 = (unsigned int *)(*(_QWORD *)&v53[1] - 8LL);
do
v52 = __ldaxr(v51);
while ( __stlxr(v52 - 1, v51) );
}
else
{
v52 = *(_DWORD *)(*(_QWORD *)&v53[1] - 8LL);
*(_DWORD *)(*(_QWORD *)&v53[1] - 8LL) = v52 - 1;
}
if ( v52 <= 0 )
operator delete(v38);
}
}