//
// EditorPauseLayer::saveLevel from 0x10039e2b0 to 0x10039e644 (916 bytes)
//
// 3 xrefs:
// > EditorPauseLayer::onSaveAndPlay @ 0x10039db34
// > EditorPauseLayer::onSaveAndExit @ 0x10039dbb4
// > EditorPauseLayer::FLAlert_Clicked @ 0x10039e8b0
//
// 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 EditorPauseLayer::saveLevel(EditorPauseLayer *a1)
{
LevelEditorLayer *m_editorLayer; // x0
GJGameLevel *m_level; // x19
LevelEditorLayer *v4; // x8
std::string *p_m_levelString; // x8
std::string::size_type size; // x8
__int64 v7; // x23
size_t v8; // x12
void *v9; // x21
__int128 *p_dst; // x0
std::string *v11; // x1
size_t v12; // x2
bool v13; // w22
LevelEditorLayer *v14; // x0
__n128 v15; // q0
DrawGridLayer *m_drawGridLayer; // x21
__n128 v17; // q1
float v18; // s0
LevelEditorLayer *v19; // x8
int m_timestamp; // w9
int v21; // w21
float v22; // s0
LevelEditorLayer *v23; // x0
float m_sessionTime; // s0
void **p_m_songIDs; // x21
void **p_m_sfxIDs; // x20
LocalLevelManager *v27; // x0
bool v28; // [xsp+7h] [xbp-A9h] BYREF
std::string v29; // [xsp+8h] [xbp-A8h] BYREF
std::string v30; // [xsp+20h] [xbp-90h] BYREF
std::string __str; // [xsp+38h] [xbp-78h] BYREF
__int128 __dst; // [xsp+50h] [xbp-60h] BYREF
char *longStorage; // [xsp+60h] [xbp-50h]
std::string v34; // [xsp+68h] [xbp-48h] BYREF
cocos2d::CCPoint v35; // 0:s0.4,4:s1.4
m_editorLayer = a1->m_editorLayer;
m_level = m_editorLayer->m_level;
LevelEditorLayer::getLevelString((__int64)m_editorLayer, &v34);
v4 = a1->m_editorLayer;
if ( v4->m_levelString.m_data.m_short.shortStorage.__elems_[22] < 0 )
{
sub_1000097D0(&__dst, (void *)v4->m_levelString.m_data.m_long.capacitym1, v4->m_levelString.m_data.m_long.size);
}
else
{
p_m_levelString = &v4->m_levelString;
__dst = *(_OWORD *)&p_m_levelString->m_data.m_short.sizex2;
longStorage = p_m_levelString->m_data.m_long.longStorage;
}
size = HIBYTE(v34.__r_.__value_.__r.__words[2]);
v7 = SHIBYTE(longStorage);
v8 = *((_QWORD *)&__dst + 1);
v9 = (void *)__dst;
if ( SHIBYTE(longStorage) < 0 )
{
p_dst = (__int128 *)__dst;
}
else
{
v8 = SHIBYTE(longStorage);
p_dst = &__dst;
}
if ( (v34.__r_.__value_.__r.__words[2] & 0x8000000000000000LL) == 0LL )
{
v11 = &v34;
}
else
{
size = v34.__r_.__value_.__l.__size_;
v11 = (std::string *)v34.__r_.__value_.__r.__words[0];
}
if ( size >= v8 )
v12 = v8;
else
v12 = size;
v13 = size == v8;
if ( memcmp(p_dst, v11, v12) )
v13 = 0;
if ( v7 < 0 )
{
operator delete(v9);
if ( v13 )
goto LABEL_20;
goto LABEL_19;
}
if ( !v13 )
LABEL_19:
GJGameLevel::levelWasAltered(m_level);
LABEL_20:
cocos2d::ZipUtils::compressString((__int64 *)&v34, 0, 11, (__int64)&__str);
std::string::operator=((std::string *)&m_level->m_levelString, &__str);
if ( SHIBYTE(__str.__r_.__value_.__r.__words[2]) < 0 )
operator delete(__str.__r_.__value_.__l.__data_);
if ( SHIBYTE(v34.__r_.__value_.__r.__words[2]) < 0 )
{
*v34.__r_.__value_.__l.__data_ = 0;
v34.__r_.__value_.__l.__size_ = 0;
}
else
{
v34.__r_.__value_.__s.__data_[0] = 0;
*((_BYTE *)&v34.__r_.__value_.__s + 23) = 0;
}
v14 = a1->m_editorLayer;
m_level->m_audioTrack = v14->m_level->m_audioTrack;
m_level->m_twoPlayerMode = v14->m_levelSettings->m_twoPlayerMode;
v15.n128_f32[0] = LevelEditorLayer::getLastObjectX(v14) + 340.0;
m_drawGridLayer = a1->m_editorLayer->m_drawGridLayer;
v17.n128_u32[0] = 0;
sub_100022980(v15, v17, &__dst);
v18 = DrawGridLayer::timeForPos(m_drawGridLayer, v35, (int)&__dst, 0, 0, 0, 0, 0);
v19 = a1->m_editorLayer;
m_timestamp = v19->m_level->GJBaseGameLayer::m_timestamp;
if ( m_timestamp >= 1 && (float)((float)(unsigned int)m_timestamp / 240.0) > v18 )
v18 = (float)(unsigned int)m_timestamp / 240.0;
m_level->m_levelLength = GJGameLevel::getLengthKey((int)v18, v19->m_levelSettings->m_platformerMode);
v21 = a1->m_editorLayer->m_objectCount.random - a1->m_editorLayer->m_objectCount.seed;
m_level->m_objectCount.value = v21;
v22 = vcvts_n_f32_s32(rand(), 0x1Fu) * 1000.0;
m_level->m_objectCount.seed = (int)v22;
m_level->m_objectCount.random = v21 + (int)v22;
v23 = a1->m_editorLayer;
m_level->m_coins = v23->m_coinCount.random - v23->m_coinCount.seed;
m_level->m_lowDetailMode = v23->m_hasHighDetail;
if ( v21 > 40000 )
{
if ( (unsigned int)v21 > 0x13880 )
goto LABEL_32;
}
else
{
m_level->m_highObjectsEnabled = 0;
}
m_level->m_unlimitedObjectsEnabled = 0;
LABEL_32:
m_sessionTime = v23->m_sessionTime;
m_level->m_workingTime += vcvtms_s32_f32(m_sessionTime);
LevelEditorLayer::getLockedLayers((__int64)v23, &v30);
std::string::operator=((std::string *)&m_level->m_lockedEditorLayers, &v30);
if ( SHIBYTE(v30.__r_.__value_.__r.__words[2]) < 0 )
operator delete(v30.__r_.__value_.__l.__data_);
LevelEditorLayer::getSavedEditorPositions((__int64)a1->m_editorLayer, &v29);
std::string::operator=((std::string *)&m_level->m_savedCameraPositions, &v29);
if ( SHIBYTE(v29.__r_.__value_.__r.__words[2]) < 0 )
operator delete(v29.__r_.__value_.__l.__data_);
sub_1000229B8((__int64 *)&__dst, (__int64 *)&a1->m_editorLayer->m_previewPosition);
sub_1000229D0(&m_level->m_previewLock, (double *)&__dst);
v28 = 0;
LevelEditorLayer::getSongIDs((__int64)a1->m_editorLayer, &v28, &__dst);
p_m_songIDs = (void **)&m_level->m_songIDs;
if ( m_level->m_songIDs.m_data.m_short.shortStorage.__elems_[22] < 0 )
operator delete(*p_m_songIDs);
*(_OWORD *)p_m_songIDs = __dst;
m_level->m_songIDs.m_data.m_long.longStorage = longStorage;
LevelEditorLayer::getSFXIDs((__int64)a1->m_editorLayer, &__dst);
p_m_sfxIDs = (void **)&m_level->m_sfxIDs;
if ( m_level->m_sfxIDs.m_data.m_short.shortStorage.__elems_[22] < 0 )
operator delete(*p_m_sfxIDs);
*(_OWORD *)p_m_sfxIDs = __dst;
m_level->m_sfxIDs.m_data.m_long.longStorage = longStorage;
if ( (m_level->m_sfxIDs.m_data.m_short.shortStorage.__elems_[22] & 0x8000000000000000LL) != 0 )
{
if ( m_level->m_sfxIDs.m_data.m_long.size )
goto LABEL_46;
}
else if ( m_level->m_sfxIDs.m_data.m_short.shortStorage.__elems_[22] )
{
goto LABEL_46;
}
if ( !v28 )
std::string::assign((std::string *)&m_level->m_songIDs, "");
LABEL_46:
v27 = LocalLevelManager::sharedState();
GManager::save(v27);
if ( SHIBYTE(v34.__r_.__value_.__r.__words[2]) < 0 )
operator delete(v34.__r_.__value_.__l.__data_);
}