//
// GameLevelManager::saveLevel from 0x100098c3c to 0x100099114 (1240 bytes)
//
// 7 xrefs:
// > LevelInfoLayer::downloadLevel @ 0x100026d1c
// > GameLevelManager::gotoLevelPage @ 0x100099220
// > GameLevelManager::processOnDownloadLevelCompleted @ 0x1000a046c
// > GameLevelManager::processOnDownloadLevelCompleted @ 0x1000a0518
// > GameLevelManager::processOnDownloadLevelCompleted @ 0x1000a0560
// > GameLevelManager::processOnDownloadLevelCompleted @ 0x1000a05b0
// > GameLevelManager::processOnDownloadLevelCompleted @ 0x1000a0600
//
// 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 GameLevelManager::saveLevel(GameLevelManager *a1, GJGameLevel *a2)
{
int random; // w24
int seed; // w25
_BOOL4 m_gauntletLevel; // w23
GJGameLevel *SavedLevel_1; // x0
GJGameLevel *v8; // x21
int v10; // w22
float v11; // s0
int v12; // w22
float v13; // s0
int v14; // w22
float v15; // s0
int v16; // w22
float v17; // s0
int v18; // w27
float v19; // s0
int v20; // w27
float v21; // s0
int v22; // w27
int v23; // w8
int m_levelIndex; // w8
int m_levelFolder; // w8
_BOOL4 v26; // w22
int v27; // w21
float v28; // s0
cocos2d::CCDictionary *m_dailyLevels; // x20
cocos2d::CCString *v30; // x0
char *CString; // x0
cocos2d::CCDictionary *m_gauntletLevels; // x20
cocos2d::CCString *v33; // x0
char *v34; // x0
std::string m_creatorName; // [xsp+10h] [xbp-D0h] BYREF
void *__p[2]; // [xsp+28h] [xbp-B8h] BYREF
char v37; // [xsp+3Fh] [xbp-A1h]
void *__dst[2]; // [xsp+40h] [xbp-A0h] BYREF
char *longStorage; // [xsp+50h] [xbp-90h]
std::string __str; // [xsp+60h] [xbp-80h] BYREF
random = a2->m_dailyID.random;
seed = a2->m_dailyID.seed;
m_gauntletLevel = a2->m_gauntletLevel;
SavedLevel_1 = GameLevelManager::getSavedLevel_1(a1, a2);
v8 = SavedLevel_1;
if ( random <= seed )
{
if ( !m_gauntletLevel || SavedLevel_1 == nullptr )
{
if ( !SavedLevel_1 )
goto LABEL_46;
goto LABEL_12;
}
}
else if ( !SavedLevel_1 )
{
goto LABEL_45;
}
if ( SavedLevel_1->m_levelID.random - SavedLevel_1->m_levelID.seed != a2->m_levelID.random - a2->m_levelID.seed )
goto LABEL_44;
LABEL_12:
v10 = SavedLevel_1->m_attempts.random - SavedLevel_1->m_attempts.seed;
a2->m_attempts.value = v10;
v11 = vcvts_n_f32_s32(rand(), 0x1Fu) * 1000.0;
a2->m_attempts.seed = (int)v11;
a2->m_attempts.random = v10 + (int)v11;
v12 = v8->m_jumps.random - v8->m_jumps.seed;
a2->m_jumps.value = v12;
v13 = vcvts_n_f32_s32(rand(), 0x1Fu) * 1000.0;
a2->m_jumps.seed = (int)v13;
a2->m_jumps.random = v12 + (int)v13;
v14 = v8->m_clicks.random - v8->m_clicks.seed;
a2->m_clicks.value = v14;
v15 = vcvts_n_f32_s32(rand(), 0x1Fu) * 1000.0;
a2->m_clicks.seed = (int)v15;
a2->m_clicks.random = v14 + (int)v15;
v16 = v8->m_attemptTime.random - v8->m_attemptTime.seed;
a2->m_attemptTime.value = v16;
v17 = vcvts_n_f32_s32(rand(), 0x1Fu) * 1000.0;
a2->m_attemptTime.seed = (int)v17;
a2->m_attemptTime.random = v16 + (int)v17;
a2->m_isChkValid = v8->m_isChkValid;
a2->m_chk = v8->m_chk;
if ( v8->m_personalBests.m_data.m_short.shortStorage.__elems_[22] < 0 )
sub_1000097D0(&__str, (void *)v8->m_personalBests.m_data.m_long.capacitym1, v8->m_personalBests.m_data.m_long.size);
else
__str = (std::string)v8->m_personalBests;
std::string::operator=((std::string *)&a2->m_personalBests, &__str);
if ( SHIBYTE(__str.__r_.__value_.__r.__words[2]) < 0 )
operator delete(__str.__r_.__value_.__l.__data_);
v18 = v8->m_normalPercent.random - v8->m_normalPercent.seed;
a2->m_normalPercent.value = v18;
v19 = vcvts_n_f32_s32(rand(), 0x1Fu) * 1000.0;
a2->m_normalPercent.seed = (int)v19;
a2->m_normalPercent.random = v18 + (int)v19;
a2->m_practicePercent = v8->m_practicePercent;
v20 = v8->m_orbCompletion.random - v8->m_orbCompletion.seed;
a2->m_orbCompletion.value = v20;
v21 = vcvts_n_f32_s32(rand(), 0x1Fu) * 1000.0;
a2->m_orbCompletion.seed = (int)v21;
a2->m_orbCompletion.random = v20 + (int)v21;
v22 = v8->m_newNormalPercent2.random - v8->m_newNormalPercent2.seed;
a2->m_newNormalPercent2.value = v22;
v23 = (int)(float)(vcvts_n_f32_s32(rand(), 0x1Fu) * 1000.0);
a2->m_newNormalPercent2.seed = v23;
a2->m_newNormalPercent2.random = v22 + v23;
*(_OWORD *)&a2->m_bestTime = *(_OWORD *)&v8->m_bestTime;
std::string::operator=((std::string *)&a2->m_inputsTime, (const std::string *)&v8->m_inputsTime);
*(_OWORD *)&a2->m_bestPoints = *(_OWORD *)&v8->m_bestPoints;
std::string::operator=((std::string *)&a2->m_inputsPoints, (const std::string *)&v8->m_inputsPoints);
a2->m_platformerSeed = v8->m_platformerSeed;
*(_WORD *)&a2->m_savedTime = *(_WORD *)&v8->m_savedTime;
a2->m_cbsOverride = v8->m_cbsOverride;
if ( v8->m_lowDetailModeToggled || v8->m_normalPercent.random > v8->m_normalPercent.seed )
a2->m_lowDetailModeToggled = v8->m_lowDetailModeToggled;
m_levelIndex = v8->m_levelIndex;
if ( m_levelIndex > a2->m_levelIndex )
a2->m_levelIndex = m_levelIndex;
if ( v8->m_levelFavorited )
a2->m_levelFavorited = 1;
m_levelFolder = v8->m_levelFolder;
if ( m_levelFolder >= 1 )
a2->m_levelFolder = m_levelFolder;
if ( v8->m_gauntletLevel2 )
a2->m_gauntletLevel2 = 1;
if ( a2->m_creatorName.m_data.m_short.shortStorage.__elems_[22] < 0 )
{
sub_1000097D0(__dst, (void *)a2->m_creatorName.m_data.m_long.capacitym1, a2->m_creatorName.m_data.m_long.size);
}
else
{
*(_OWORD *)__dst = *(_OWORD *)&a2->m_creatorName.m_data.m_short.sizex2;
longStorage = a2->m_creatorName.m_data.m_long.longStorage;
}
sub_100009900(__p, "-");
v26 = sub_1000045BC(__dst, __p);
if ( v37 < 0 )
operator delete(__p[0]);
if ( SHIBYTE(longStorage) < 0 )
{
operator delete(__dst[0]);
if ( !v26 )
goto LABEL_42;
LABEL_37:
if ( v8->m_creatorName.m_data.m_short.shortStorage.__elems_[22] < 0 )
sub_1000097D0(
&m_creatorName,
(void *)v8->m_creatorName.m_data.m_long.capacitym1,
v8->m_creatorName.m_data.m_long.size);
else
m_creatorName = (std::string)v8->m_creatorName;
std::string::operator=((std::string *)&a2->m_creatorName, &m_creatorName);
if ( SHIBYTE(m_creatorName.__r_.__value_.__r.__words[2]) < 0 )
operator delete(m_creatorName.__r_.__value_.__l.__data_);
goto LABEL_42;
}
if ( v26 )
goto LABEL_37;
LABEL_42:
if ( a2->m_accountID.random == a2->m_accountID.seed )
{
v27 = v8->m_accountID.random - v8->m_accountID.seed;
a2->m_accountID.value = v27;
v28 = vcvts_n_f32_s32(rand(), 0x1Fu) * 1000.0;
a2->m_accountID.seed = (int)v28;
a2->m_accountID.random = v27 + (int)v28;
}
LABEL_44:
if ( random > seed )
{
LABEL_45:
m_dailyLevels = a1->m_dailyLevels;
v30 = (cocos2d::CCString *)sub_100268F4C("%i", a2->m_dailyID.random - a2->m_dailyID.seed);
CString = (char *)cocos2d::CCString::getCString(v30);
sub_100009900(__dst, CString);
cocos2d::CCDictionary::setObject_1(m_dailyLevels, a2, __dst);
goto LABEL_50;
}
LABEL_46:
if ( m_gauntletLevel )
m_gauntletLevels = a1->m_gauntletLevels;
else
m_gauntletLevels = a1->m_onlineLevels;
v33 = (cocos2d::CCString *)sub_100268F4C("%i", a2->m_levelID.random - a2->m_levelID.seed);
v34 = (char *)cocos2d::CCString::getCString(v33);
sub_100009900(__dst, v34);
cocos2d::CCDictionary::setObject_1(m_gauntletLevels, a2, __dst);
LABEL_50:
if ( SHIBYTE(longStorage) < 0 )
operator delete(__dst[0]);
}