//
// PlayLayer::resetLevel from 0x31f700 to 0x31ff54 (2132 bytes)
//
// 0 xrefs:
//
// 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 PlayLayer::resetLevel(PlayLayer *a1)
{
double v1; // d5
_BOOL4 m_ignoreDamage; // r1
int m_isIgnoreDamageEnabled; // r3
FMODAudioEngine *v5; // r0
FMODAudioEngine *v6; // r0
std::uint64_t *p_m_randomSeed; // r7
std::uint64_t m_replayRandSeed; // r2
UILayer **p_m_uiLayer; // r9
EndPortalObject *m_endPortal; // r0
EndPortalObject_vtbl *v11; // r3
EndPortalObject *v12; // r11
float m_endXPosition; // r1
void (__fastcall *setStartPos)(GameObject *__hidden, cocos2d::CCPoint); // r10
UILayer *v15; // r0
double m_attemptTime; // d7
double m_bestAttemptTime; // d6
unsigned int v18; // r8
GameObject *v19; // r5
int m_outerSectionIndex; // r2
double m_positionX; // d7
float *p_m_sectionXFactor; // r3
bool v23; // cc
int v24; // s12
double m_positionY; // d7
float *p_m_sectionYFactor; // r3
bool v27; // cc
int v28; // s14
int v29; // r3
int m_middleSectionIndex; // r2
float v31; // s20
float v32; // s20
GameObject_vtbl *v33; // r2
CheckpointObject *LastCheckpoint; // r5
StartPosObject *m_startPosObject; // r3
CheckpointObject *m_currentCheckpoint; // r1
LevelSettingsObject *m_startSettings; // r1
PlayerObject *m_player1; // r7
const cocos2d::CCPoint *v39; // r0
PlayerObject *m_player2; // r11
const cocos2d::CCPoint *v41; // r0
cocos2d::CCPoint *p_m_position; // r0
PlayerObject *v43; // r7
PlayerObject *v44; // r7
const cocos2d::CCPoint *v45; // r0
PlayerObject *v46; // r7
const cocos2d::CCPoint *v47; // r0
void (__fastcall *spawnGroup)(GJBaseGameLayer *__hidden, int, bool, double, const std::vector *, int, int); // r3
GameStatsManager *v49; // r0
GJGameLevel *m_level; // r7
int v51; // r8
int v52; // s15
_BOOL4 m_started; // r7
bool *p_m_isPracticeMode; // r11
_BOOL4 isJumpButtonPressed; // r2
cocos2d::CCArray *m_batchNodes; // r3
cocos2d::ccArray *data; // r2
unsigned int num; // r3
cocos2d::CCObject **arr; // r2
unsigned int v60; // r8
cocos2d::CCNode **v61; // r9
cocos2d::CCNode *v62; // r0
cocos2d::CCNode *v63; // t1
cocos2d::CCDelayTime *v64; // r0
cocos2d::CCSequence *v65; // r7
cocos2d::CCFiniteTimeAction *v66; // r0
cocos2d::CCAction *v67; // r0
float v68[2]; // [sp+28h] [bp-24h] BYREF
cocos2d::CCPoint v69; // [sp+30h] [bp-1Ch] BYREF
struct timeval tv; // [sp+38h] [bp-14h] BYREF
int v71; // [sp+40h] [bp-Ch]
if ( a1->m_freezeStartCamera || !a1->m_isPlatformer && !a1->m_isPracticeMode )
{
m_ignoreDamage = a1->m_ignoreDamage;
m_isIgnoreDamageEnabled = a1->m_isIgnoreDamageEnabled;
if ( a1->m_isIgnoreDamageEnabled )
m_isIgnoreDamageEnabled = !m_ignoreDamage;
a1->m_isIgnoreDamageEnabled = m_ignoreDamage;
if ( m_isIgnoreDamageEnabled )
PlayLayer::toggleIgnoreDamage(a1, 0);
}
if ( !a1->m_freezeStartCamera )
{
v5 = FMODAudioEngine::sharedEngine();
FMODAudioEngine::stopAllEffects(v5);
if ( !a1->m_isPracticeMode || a1->m_practiceMusicSync )
{
if ( a1->m_isPlatformer )
{
v6 = FMODAudioEngine::sharedEngine();
FMODAudioEngine::pauseAllMusic(v6, 0);
}
else
{
GJBaseGameLayer::pauseAudio(a1);
}
}
}
GJBaseGameLayer::preResumeGame(a1);
dwTickStartp = clock();
GJBaseGameLayer::resetLevelVariables(a1);
if ( a1->m_hitboxesOnDeath && !PlayLayer::shouldDebugDraw(a1) )
PlayLayer::toggleDebugDraw(a1);
a1->m_gameState.m_commandIndex = 0;
a1->m_gameState.m_currentProgress = 0;
a1->m_currentStep = 0;
a1->m_areaObjectsUpdated = 1;
a1->m_activatedCheckpoint = nullptr;
a1->m_tryPlaceCheckpoint = 0;
p_m_randomSeed = &a1->m_randomSeed;
a1->m_unk32ec = 0;
a1->m_unk32d0 = 0;
if ( !a1->m_useReplay || (m_replayRandSeed = a1->m_replayRandSeed) == 0 )
{
gettimeofday(&tv, nullptr);
m_replayRandSeed = tv.tv_sec * tv.tv_usec;
}
*p_m_randomSeed = m_replayRandSeed;
p_m_uiLayer = &a1->m_uiLayer;
GameToolbox::fast_srand(*p_m_randomSeed);
a1->m_activeObjectsCount = 0;
a1->m_unk36ce = 0;
a1->m_unk36c8 = 0;
UILayer::toggleMenuVisibility(a1->m_uiLayer, 1);
m_endPortal = a1->m_endPortal;
a1->m_inResetDelay = 0;
a1->m_hasCompletedLevel = 0;
a1->m_levelEndAnimationStarted = 0;
if ( m_endPortal )
{
a1->m_endChecked = 0;
v11 = m_endPortal->GameObject::CCSpritePlus::cocos2d::CCSprite::cocos2d::CCNodeRGBA::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
m_endPortal->m_flippedX = 0;
m_endPortal->m_startPosHeightRelated = 0;
((void (__fastcall *)(EndPortalObject *, int))v11->setScaleX)(m_endPortal, 1065353216);
v12 = a1->m_endPortal;
m_endXPosition = a1->m_endXPosition;
a1->m_levelLength = m_endXPosition;
setStartPos = v12->setStartPos;
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)&tv, m_endXPosition, 225.0);
((void (__fastcall *)(EndPortalObject *, struct timeval *))setStartPos)(v12, &tv);
GJBaseGameLayer::reorderObjectSection(a1, a1->m_endPortal);
a1->m_endPortal->deactivateObject(a1->m_endPortal, 1);
}
a1->m_endLayerStars = 0;
a1->m_orbs = 0;
a1->m_diamonds = 0;
a1->m_secretKey = 0;
a1->m_hasJumped = 0;
sub_7753D4((int)&a1->m_recordString, (char *)&unk_939830);
v15 = *p_m_uiLayer;
a1->m_unk3900 = 0.0;
a1->m_activeGravityEffects = 0;
UILayer::enableMenu(v15);
GJBaseGameLayer::resetActiveEnterEffects(a1);
m_attemptTime = a1->m_attemptTime;
m_bestAttemptTime = a1->m_bestAttemptTime;
if ( m_attemptTime > m_bestAttemptTime )
a1->m_bestAttemptTime = m_attemptTime;
a1->m_clicks = 0;
v18 = 0;
a1->m_attemptTime = 0.0;
a1->m_currentTime = 0.0;
a1->m_pauseDelta = 0.0;
a1->toggleGlitter(a1, 0);
while ( v18 < cocos2d::CCArray::count(a1->m_objects) )
{
v19 = (GameObject *)cocos2d::CCArray::objectAtIndex(a1->m_objects, v18);
v19->getRealPosition((cocos2d::CCPoint *)v68, v19);
v19->resetObject(v19);
m_outerSectionIndex = v19->m_outerSectionIndex;
if ( m_outerSectionIndex >= 0 )
{
m_positionX = v19->m_positionX;
if ( m_positionX <= 0.0 )
{
v24 = 0;
}
else
{
p_m_sectionXFactor = &a1->m_sectionXFactor;
v23 = m_positionX < 10000000.0;
if ( m_positionX >= 10000000.0 )
LODWORD(m_bestAttemptTime) = 1259902592;
else
*(float *)&m_bestAttemptTime = *p_m_sectionXFactor;
if ( m_positionX >= 10000000.0 )
*((float *)&m_positionX + 1) = *p_m_sectionXFactor;
else
m_bestAttemptTime = *(float *)&m_bestAttemptTime;
if ( v23 )
m_bestAttemptTime = m_positionX * m_bestAttemptTime;
else
*(float *)&m_bestAttemptTime = *((float *)&m_positionX + 1) * *(float *)&m_bestAttemptTime;
v24 = v23 ? (int)m_bestAttemptTime : (int)*(float *)&m_bestAttemptTime;
}
m_positionY = v19->m_positionY;
if ( m_positionY <= 0.0 )
{
v28 = 0;
}
else
{
p_m_sectionYFactor = &a1->m_sectionYFactor;
v27 = m_positionY < 10000000.0;
if ( m_positionY >= 10000000.0 )
*(float *)&m_positionY = *p_m_sectionYFactor;
else
*(float *)&v1 = *p_m_sectionYFactor;
if ( v27 )
v1 = *(float *)&v1;
else
HIDWORD(m_positionY) = 1259902592;
if ( v27 )
m_positionY = m_positionY * v1;
else
*(float *)&m_positionY = *(float *)&m_positionY * *((float *)&m_positionY + 1);
v28 = v27 ? (int)m_positionY : (int)*(float *)&m_positionY;
}
if ( v24 != m_outerSectionIndex || v28 != v19->m_middleSectionIndex )
{
GJBaseGameLayer::reorderObjectSection(a1, v19);
v29 = v19->m_outerSectionIndex;
if ( v29 > a1->m_rightSectionIndex
|| v29 < a1->m_leftSectionIndex
|| (m_middleSectionIndex = v19->m_middleSectionIndex, m_middleSectionIndex > a1->m_topSectionIndex)
|| m_middleSectionIndex < a1->m_bottomSectionIndex )
{
v19->deactivateObject(v19, 1);
}
}
}
v31 = v68[0];
v19->getRealPosition(&v69, v19);
if ( v31 != v69.x
|| (v32 = v68[1], v19->getRealPosition((cocos2d::CCPoint *)&tv, v19), v32 != *(float *)&tv.tv_usec) )
{
v33 = v19->CCSpritePlus::cocos2d::CCSprite::cocos2d::CCNodeRGBA::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
v19->m_isDirty = 1;
v33->setObjectRectDirty(v19, 1);
v19->setOrientedRectDirty(v19, 1);
}
++v18;
}
AudioEffectsLayer::resetAudioVars(a1->m_audioEffectsLayer);
PlayLayer::loadDefaultColors(a1);
LastCheckpoint = PlayLayer::loadLastCheckpoint(a1);
if ( !a1->m_useReplay )
{
GJEffectManager::getPersistentStateString((GJEffectManager *)&tv);
sub_775D40(&a1->m_persistentStateString, &tv);
sub_774008(&tv);
}
GJEffectManager::resetUsedItemState(a1->m_effectManager);
if ( LastCheckpoint )
{
a1->m_unk3251 = 0;
if ( !a1->m_useReplay )
GJBaseGameLayer::resetRecord(a1, a1->m_gameState.m_unkUint4, 0);
}
else
{
a1->m_timePlayed = 0.0;
a1->m_tickIndex = 0;
a1->m_clickIndex = 0;
GJBaseGameLayer::resetRecord(a1, 0, 0);
a1->m_unk32e0 = *p_m_randomSeed;
m_startPosObject = a1->m_startPosObject;
if ( m_startPosObject )
{
m_currentCheckpoint = a1->m_currentCheckpoint;
if ( m_currentCheckpoint )
{
PlayLayer::loadFromCheckpoint(a1, m_currentCheckpoint);
goto LABEL_76;
}
m_startSettings = m_startPosObject->m_startSettings;
}
else
{
m_startSettings = a1->m_levelSettings;
}
GJBaseGameLayer::setupLevelStart(a1, m_startSettings);
}
LABEL_76:
m_player1 = a1->m_player1;
v39 = m_player1->getPosition(m_player1);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)&tv, v39);
cocos2d::CCPoint::operator=(&m_player1->m_position, &tv);
m_player2 = a1->m_player2;
if ( a1->m_gameState.m_isDualMode )
{
v41 = m_player2->getPosition(a1->m_player2);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)&tv, v41);
p_m_position = &m_player2->m_position;
}
else
{
m_player2->setPosition(a1->m_player2, &stru_AC5B14);
v43 = a1->m_player2;
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)&tv, &stru_AC5B14);
p_m_position = &v43->m_position;
}
cocos2d::CCPoint::operator=(p_m_position, &tv);
if ( !LastCheckpoint )
{
v44 = a1->m_player1;
v45 = v44->getPosition(v44);
GameObject::setLastPosition(v44, v45);
v46 = a1->m_player2;
v47 = v46->getPosition(v46);
GameObject::setLastPosition(v46, v47);
if ( a1->m_startPosObject )
{
if ( !a1->m_currentCheckpoint )
GJBaseGameLayer::loadStartPosObject(a1);
}
}
GJBaseGameLayer::updatePlayerCollisionBlocks(a1);
if ( !a1->m_unk322a )
{
PlayerObject::playSpawnEffect(a1->m_player1);
if ( a1->m_gameState.m_isDualMode )
PlayerObject::playSpawnEffect(a1->m_player2);
}
GJBaseGameLayer::stopCameraShake(a1);
if ( a1->m_startPosObject )
{
if ( !LastCheckpoint )
goto LABEL_93;
}
else if ( !LastCheckpoint )
{
a1->m_startingFromBeginning = 1;
GJBaseGameLayer::checkSpawnObjects(a1);
goto LABEL_93;
}
if ( LastCheckpoint->m_respawnID > 0 )
{
spawnGroup = a1->spawnGroup;
tv.tv_sec = 0;
tv.tv_usec = 0;
v71 = 0;
((void (__fastcall *)(PlayLayer *))spawnGroup)(a1);
std::_Vector_base::~_Vector_base((void **)&tv);
}
GJBaseGameLayer::gameEventTriggered(a1, CheckpointRespawn, 0, 0);
LABEL_93:
GJBaseGameLayer::updateProximityVolumeEffects(a1);
GJBaseGameLayer::updateLevelColors(a1);
GJBaseGameLayer::updateCamera(a1, 0.0);
((void (__fastcall *)(PlayLayer *, _DWORD))a1->updateVisibility)(a1, 0);
GJBaseGameLayer::updateGradientLayers(a1);
GJBaseGameLayer::updateShaderLayer(a1, 0.0);
PlayLayer::updateAttempts(a1);
if ( !LastCheckpoint )
{
a1->m_savedAttempts = a1->m_attempts;
sub_775D40(&a1->m_savedPersistentStateString, &a1->m_persistentStateString);
}
v49 = GameStatsManager::sharedState();
GameStatsManager::incrementStat(v49, (const char *)&aO1i2r3e45s7t89[3]);
m_level = a1->m_level;
v51 = m_level->m_attempts.random - m_level->m_attempts.seed + 1;
m_level->m_attempts.value = v51;
v52 = (int)(float)(vcvts_n_f32_s32(rand(), 0x1Fu) * 1000.0);
m_level->m_attempts.seed = v52;
m_level->m_attempts.random = v52 + v51;
PlayLayer::updateProgressbar(a1);
GJBaseGameLayer::refreshCounterLabels(a1);
m_started = a1->m_started;
if ( a1->m_isPlatformer )
a1->m_started = 0;
if ( a1->m_started && !LastCheckpoint && !a1->m_startPosObject )
PlayLayer::startMusic(a1);
p_m_isPracticeMode = &a1->m_isPracticeMode;
if ( GameManager::sharedState()->m_recordGameplay && !*p_m_isPracticeMode && !a1->m_isTestMode )
PlayLayer::tryStartRecord(a1);
GJBaseGameLayer::removeReleasedButtons(a1);
isJumpButtonPressed = UILayer::isJumpButtonPressed(*p_m_uiLayer);
if ( isJumpButtonPressed )
LOBYTE(isJumpButtonPressed) = 1;
GJBaseGameLayer::queueButton(a1, 1, isJumpButtonPressed, 0, 0.0);
if ( !*p_m_isPracticeMode && !a1->m_isIgnoreDamageEnabled )
a1->m_damageVerified = 0;
a1->m_freezeStartCamera = 0;
a1->m_skipArtReload = 0;
GJBaseGameLayer::syncBGTextures(a1);
dwTickEndp = clock();
dwDurationp = dwTickEndp - dwTickStartp;
m_batchNodes = a1->m_batchNodes;
if ( m_batchNodes )
{
data = m_batchNodes->data;
num = data->num;
if ( data->num )
{
arr = data->arr;
v60 = (unsigned int)(&arr[num] + 0x3FFFFFFF);
v61 = (cocos2d::CCNode **)arr;
while ( (unsigned int)v61 <= v60 )
{
v63 = *v61++;
v62 = v63;
if ( !v63 )
break;
cocos2d::CCNode::qsortAllChildrenWithIndex(v62);
}
}
}
GJBaseGameLayer::sortSectionVector(a1);
if ( a1->m_isPlatformer && (m_started || a1->m_platformerRestart) )
{
a1->m_platformerRestart = 0;
if ( LastCheckpoint )
{
a1->m_started = 1;
}
else
{
v64 = cocos2d::CCDelayTime::create(0.2);
tv.tv_usec = 0;
tv.tv_sec = (__time_t)PlayLayer::startGameDelayed;
v65 = (cocos2d::CCSequence *)v64;
v66 = (cocos2d::CCFiniteTimeAction *)cocos2d::CCCallFunc::create(a1, PlayLayer::startGameDelayed, 0);
v67 = (cocos2d::CCAction *)cocos2d::CCSequence::create(v65, v66, 0);
cocos2d::CCNode::runAction(a1, v67);
}
}
a1->m_startingFromBeginning = 0;
a1->m_audioPaused = 1;
if ( LastCheckpoint )
{
cocos2d::CCPoint::operator=(&a1->m_gameState.m_cameraPosition2, &LastCheckpoint->m_gameState.m_cameraPosition2);
cocos2d::CCPoint::operator=(&a1->m_gameState.m_cameraStepDiff, &LastCheckpoint->m_gameState.m_cameraStepDiff);
cocos2d::CCPoint::operator=(&a1->m_gameState.m_unkPoint4, &LastCheckpoint->m_gameState.m_unkPoint4);
}
}