//
// GameLevelManager::saveLevel from 0x3c6e70 to 0x3c7174 (772 bytes)
//
// 7 xrefs:
// > LevelInfoLayer::downloadLevel @ 0x3b1924
// > GameLevelManager::gotoLevelPage @ 0x3c7242
// > GameLevelManager::processOnDownloadLevelCompleted @ 0x3c76fe
// > GameLevelManager::processOnDownloadLevelCompleted @ 0x3c774a
// > GameLevelManager::processOnDownloadLevelCompleted @ 0x3c776c
// > GameLevelManager::processOnDownloadLevelCompleted @ 0x3c778e
// > GameLevelManager::processOnDownloadLevelCompleted @ 0x3c77c4
//
// 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 GameLevelManager::saveLevel(GameLevelManager *a1, GJGameLevel *a2)
{
_BOOL4 m_gauntletLevel; // r10
_BOOL4 v5; // r8
GJGameLevel *SavedLevel; // r0
GJGameLevel *v7; // r5
int NormalPercent; // r0
int m_levelIndex; // r3
int m_levelFolder; // r3
cocos2d::CCDictionary *m_dailyLevels; // r5
cocos2d::CCString *v12; // r0
char *v13; // r0
cocos2d::CCDictionary *m_gauntletLevels; // r5
cocos2d::CCString *v15; // r0
char *CString; // r0
cocos2d::CCDictionary *m_onlineLevels; // r5
char *LevelKey; // r0
_BOOL4 v19; // [sp+4h] [bp-8h]
int v20; // [sp+Ch] [bp+0h] BYREF
_BYTE v21[4]; // [sp+10h] [bp+4h] BYREF
m_gauntletLevel = a2->m_gauntletLevel;
v5 = a2->m_dailyID.random - a2->m_dailyID.seed > 0;
SavedLevel = GameLevelManager::getSavedLevel(a1, a2);
v7 = SavedLevel;
if ( v5 || m_gauntletLevel )
{
if ( !SavedLevel
|| SavedLevel->m_levelID.random - SavedLevel->m_levelID.seed != a2->m_levelID.random - a2->m_levelID.seed )
{
goto LABEL_21;
}
}
else if ( !SavedLevel )
{
goto LABEL_25;
}
GJGameLevel::setAttempts(a2, SavedLevel->m_attempts.random - SavedLevel->m_attempts.seed);
GJGameLevel::setJumps(a2, v7->m_jumps.random - v7->m_jumps.seed);
GJGameLevel::setClicks(a2, v7->m_clicks.random - v7->m_clicks.seed);
GJGameLevel::setAttemptTime(a2, v7->m_attemptTime.random - v7->m_attemptTime.seed);
a2->m_isChkValid = v7->m_isChkValid;
a2->m_chk = v7->m_chk;
sub_775C20(v21, &v7->m_personalBests);
sub_775D40(&a2->m_personalBests, v21);
sub_774008(v21);
NormalPercent = GJGameLevel::getNormalPercent(v7);
GJGameLevel::setNormalPercent(a2, NormalPercent);
a2->m_practicePercent = v7->m_practicePercent;
GJGameLevel::setNewNormalPercent(a2, v7->m_orbCompletion.random - v7->m_orbCompletion.seed);
GJGameLevel::setNewNormalPercent2(a2, v7->m_newNormalPercent2.random - v7->m_newNormalPercent2.seed);
a2->m_bestTime = v7->m_bestTime;
a2->m_ticksTime = v7->m_ticksTime;
a2->m_clicksTime = v7->m_clicksTime;
a2->m_coinsTime = v7->m_coinsTime;
sub_775D40(&a2->m_inputsTime, &v7->m_inputsTime);
a2->m_bestPoints = v7->m_bestPoints;
a2->m_ticksPoints = v7->m_ticksPoints;
a2->m_clicksPoints = v7->m_clicksPoints;
a2->m_coinsPoints = v7->m_coinsPoints;
sub_775D40(&a2->m_inputsPoints, &v7->m_inputsPoints);
a2->m_platformerSeed = v7->m_platformerSeed;
a2->m_savedTime = v7->m_savedTime;
a2->m_savedPoints = v7->m_savedPoints;
a2->m_cbsOverride = v7->m_cbsOverride;
if ( v7->m_lowDetailModeToggled || GJGameLevel::getNormalPercent(v7) > 0 )
a2->m_lowDetailModeToggled = v7->m_lowDetailModeToggled;
m_levelIndex = v7->m_levelIndex;
if ( m_levelIndex > a2->m_levelIndex )
a2->m_levelIndex = m_levelIndex;
if ( v7->m_levelFavorited )
a2->m_levelFavorited = 1;
m_levelFolder = v7->m_levelFolder;
if ( m_levelFolder > 0 )
a2->m_levelFolder = m_levelFolder;
if ( v7->m_gauntletLevel2 )
a2->m_gauntletLevel2 = 1;
sub_775C20(&v20, &a2->m_creatorName);
sub_776584((int)v21, "-");
v19 = sub_3BE0D8((int)&v20, (int)v21);
sub_774008(v21);
sub_774008(&v20);
if ( v19 )
{
sub_775C20(v21, &v7->m_creatorName);
sub_775D40(&a2->m_creatorName, v21);
sub_774008(v21);
}
if ( a2->m_accountID.random == a2->m_accountID.seed )
GJGameLevel::setAccountID(a2, v7->m_accountID.random - v7->m_accountID.seed);
LABEL_21:
if ( !v5 )
{
if ( m_gauntletLevel )
{
m_gauntletLevels = a1->m_gauntletLevels;
v15 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"%i",
(const char *)(a2->m_levelID.random - a2->m_levelID.seed));
CString = (char *)cocos2d::CCString::getCString(v15);
sub_776584((int)v21, CString);
cocos2d::CCDictionary::setObject((int)m_gauntletLevels, a2);
goto LABEL_26;
}
LABEL_25:
m_onlineLevels = a1->m_onlineLevels;
LevelKey = (char *)GameLevelManager::getLevelKey(a1, a2->m_levelID.random - a2->m_levelID.seed);
sub_776584((int)v21, LevelKey);
cocos2d::CCDictionary::setObject((int)m_onlineLevels, a2);
goto LABEL_26;
}
m_dailyLevels = a1->m_dailyLevels;
v12 = (cocos2d::CCString *)cocos2d::CCString::createWithFormat(
(cocos2d::CCString *)"%i",
(const char *)(a2->m_dailyID.random - a2->m_dailyID.seed));
v13 = (char *)cocos2d::CCString::getCString(v12);
sub_776584((int)v21, v13);
cocos2d::CCDictionary::setObject((int)m_dailyLevels, a2);
LABEL_26:
sub_774008(v21);
}