//
// PlayLayer::resetLevel from 0x5e5158 to 0x5e5c50 (2808 bytes)
//
// 2 xrefs:
// > ??> @ 0x30918
// > ??> @ 0x1148b38
//
// 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)
{
float *v1; // x25
int m_freezeStartCamera; // w0
bool m_ignoreDamage; // w1
int v5; // w0
__suseconds_t m_replayRandSeed; // x0
UILayer *m_uiLayer; // x0
EndPortalObject *m_endPortal; // x1
EndPortalObject_vtbl *v9; // x2
void (__fastcall *setScaleX)(GameObject *__hidden, float); // x2
EndPortalObject *v11; // x19
float m_endXPosition; // s0
void (__fastcall *setStartPos)(GameObject *__hidden, cocos2d::CCPoint); // x21
UILayer *v14; // x0
double m_attemptTime; // d0
PlayLayer_vtbl *v16; // x2
unsigned int v17; // w21
void (__fastcall *toggleGlitter)(PlayLayer *__hidden, bool); // x2
GameObject *v19; // x19
int m_outerSectionIndex; // w2
double m_positionX; // d0
int v22; // w0
double m_positionY; // d0
int v24; // w1
int v25; // w0
int m_middleSectionIndex; // w0
GameObject_vtbl *v27; // x2
CheckpointObject *LastCheckpoint; // x21
void *v29; // x0
int v30; // w0
PlayerObject *m_player1; // x19
const cocos2d::CCPoint *v32; // x0
float v33; // s0
float v34; // s1
PlayerObject *m_player2; // x19
const cocos2d::CCPoint *v36; // x0
float v37; // s0
float v38; // s1
__int64 m_respawnID; // x1
__int64 m_uniqueID; // x4
void (__fastcall *spawnGroup)(GJBaseGameLayer *__hidden, int, bool, double, const std::vector *, int, int); // x6
GameStatsManager *v42; // x0
GJGameLevel *m_level; // x22
int v44; // w19
int v45; // w1
int v46; // w23
int v47; // w24
clock_t v48; // x0
cocos2d::CCArray *m_batchNodes; // x1
cocos2d::ccArray *data; // x1
cocos2d::CCNode **arr; // x19
cocos2d::CCNode **v52; // x22
cocos2d::CCNode *v53; // x0
float v54; // s0
float v55; // s1
float v56; // s0
float v57; // s1
float v58; // s0
float v59; // s1
FMODAudioEngine *v60; // x0
PlayerObject *v61; // x22
float v62; // s0
float v63; // s1
FMODAudioEngine *v64; // x0
PlayerObject *v65; // x19
const cocos2d::CCPoint *v66; // x0
PlayerObject *v67; // x19
const cocos2d::CCPoint *v68; // x0
StartPosObject *m_startPosObject; // x0
CheckpointObject *m_currentCheckpoint; // x1
cocos2d::CCSequence *v71; // x19
cocos2d::CCFiniteTimeAction *v72; // x0
cocos2d::CCAction *v73; // x0
LevelSettingsObject *m_startSettings; // x1
unsigned int *v75; // x2
int v76; // w1
float v77; // [xsp+90h] [xbp+90h]
float v78; // [xsp+94h] [xbp+94h]
float v79; // [xsp+98h] [xbp+98h]
struct timeval p; // [xsp+A0h] [xbp+A0h] BYREF
__int64 v81; // [xsp+B0h] [xbp+B0h]
v1 = &a1->m_varianceValues.__elems_[1975];
m_freezeStartCamera = a1->m_freezeStartCamera;
if ( m_freezeStartCamera || !*((_BYTE *)v1 + 270) && !*((_BYTE *)v1 + 592) )
{
if ( *((_BYTE *)v1 + 2102) )
{
m_ignoreDamage = a1->m_ignoreDamage;
if ( !m_ignoreDamage )
{
*((_BYTE *)v1 + 2102) = 0;
PlayLayer::toggleIgnoreDamage(a1, 0);
m_freezeStartCamera = *((unsigned __int8 *)v1 + 657);
goto LABEL_7;
}
}
else
{
m_ignoreDamage = a1->m_ignoreDamage;
}
*((_BYTE *)v1 + 2102) = m_ignoreDamage;
LABEL_7:
if ( m_freezeStartCamera )
goto LABEL_8;
}
v60 = FMODAudioEngine::sharedEngine();
FMODAudioEngine::stopAllEffects(v60);
if ( !*((_BYTE *)v1 + 592) || *((_BYTE *)v1 + 593) )
{
if ( *((_BYTE *)v1 + 270) )
{
v64 = FMODAudioEngine::sharedEngine();
FMODAudioEngine::pauseAllMusic(v64, 0);
}
else
{
GJBaseGameLayer::pauseAudio(a1);
}
}
LABEL_8:
GJBaseGameLayer::preResumeGame(a1);
dwTickStartp = clock();
GJBaseGameLayer::resetLevelVariables(a1);
if ( *((_BYTE *)v1 + 1890) && !PlayLayer::shouldDebugDraw(a1) )
PlayLayer::toggleDebugDraw(a1);
a1->m_gameState.m_commandIndex = 0;
a1->m_gameState.m_currentProgress = 0;
a1->m_currentStep = 0;
*((_BYTE *)v1 + 481) = 1;
a1->m_activatedCheckpoint = nullptr;
*((_BYTE *)v1 + 2620) = 0;
v5 = *((unsigned __int8 *)v1 + 496);
a1->m_unk32ec = 0;
a1->m_unk32d0 = 0;
if ( v5 && (m_replayRandSeed = a1->m_replayRandSeed) != 0 )
{
a1->m_randomSeed = m_replayRandSeed;
}
else
{
gettimeofday(&p, nullptr);
m_replayRandSeed = p.tv_usec * p.tv_sec;
a1->m_randomSeed = p.tv_usec * p.tv_sec;
}
GameToolbox::fast_srand(m_replayRandSeed);
a1->m_activeObjectsCount = 0;
*((_BYTE *)v1 + 1950) = 0;
m_uiLayer = a1->m_uiLayer;
a1->m_unk36c8 = 0;
UILayer::toggleMenuVisibility(m_uiLayer, 1);
m_endPortal = a1->m_endPortal;
*((_BYTE *)v1 + 2390) = 0;
*((_BYTE *)v1 + 2389) = 0;
*((_BYTE *)v1 + 1392) = 0;
if ( m_endPortal )
{
v9 = m_endPortal->GameObject::CCSpritePlus::cocos2d::CCSprite::cocos2d::CCNodeRGBA::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
*((_BYTE *)v1 + 2136) = 0;
m_endPortal->m_flippedX = 0;
setScaleX = v9->setScaleX;
m_endPortal->m_startPosHeightRelated = 0;
setScaleX(m_endPortal, 1.0);
v11 = a1->m_endPortal;
m_endXPosition = a1->m_endXPosition;
setStartPos = v11->setStartPos;
a1->m_levelLength = m_endXPosition;
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)&p, m_endXPosition, 225.0);
((void (__fastcall *)(EndPortalObject *, struct timeval *))setStartPos)(v11, &p);
GJBaseGameLayer::reorderObjectSection(a1, a1->m_endPortal);
a1->m_endPortal->deactivateObject(a1->m_endPortal, 1);
}
*((_BYTE *)v1 + 2396) = 0;
a1->m_orbs = 0;
a1->m_diamonds = 0;
*((_BYTE *)v1 + 2408) = 0;
*((_BYTE *)v1 + 2380) = 0;
sub_D1798C(v1 + 196, &byte_F288A0, 0);
a1->m_activeGravityEffects = 0;
v14 = a1->m_uiLayer;
a1->m_unk3900 = 0.0;
UILayer::enableMenu(v14);
GJBaseGameLayer::resetActiveEnterEffects(a1);
m_attemptTime = a1->m_attemptTime;
if ( m_attemptTime > a1->m_bestAttemptTime )
a1->m_bestAttemptTime = m_attemptTime;
v16 = a1->GJBaseGameLayer::cocos2d::CCLayer::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
a1->m_clicks = 0;
v17 = 0;
toggleGlitter = v16->toggleGlitter;
a1->m_attemptTime = 0.0;
a1->m_currentTime = 0.0;
a1->m_pauseDelta = 0.0;
toggleGlitter(a1, 0);
if ( (unsigned int)cocos2d::CCArray::count(a1->m_objects) )
{
while ( 1 )
{
v19 = (GameObject *)cocos2d::CCArray::objectAtIndex(a1->m_objects, v17);
v19->getRealPosition(v19);
v19->resetObject(v19);
m_outerSectionIndex = v19->m_outerSectionIndex;
if ( m_outerSectionIndex < 0 )
goto LABEL_30;
m_positionX = v19->m_positionX;
if ( m_positionX <= 0.0 )
break;
if ( m_positionX >= 10000000.0 )
{
v22 = (int)(float)(a1->m_sectionXFactor * 10000000.0);
goto LABEL_21;
}
v22 = (int)(m_positionX * a1->m_sectionXFactor);
m_positionY = v19->m_positionY;
if ( m_positionY <= 0.0 )
{
LABEL_80:
v24 = 0;
LABEL_24:
if ( v22 != m_outerSectionIndex )
goto LABEL_25;
goto LABEL_77;
}
LABEL_22:
if ( m_positionY >= 10000000.0 )
{
v24 = (int)(float)(a1->m_sectionYFactor * 10000000.0);
goto LABEL_24;
}
v24 = (int)(m_positionY * a1->m_sectionYFactor);
if ( v22 != m_outerSectionIndex )
goto LABEL_25;
LABEL_77:
if ( v24 != v19->m_middleSectionIndex )
{
LABEL_25:
GJBaseGameLayer::reorderObjectSection(a1, v19);
v25 = v19->m_outerSectionIndex;
if ( v25 > a1->m_rightSectionIndex
|| v25 < a1->m_leftSectionIndex
|| (m_middleSectionIndex = v19->m_middleSectionIndex, m_middleSectionIndex > a1->m_topSectionIndex)
|| m_middleSectionIndex < a1->m_bottomSectionIndex )
{
v19->deactivateObject(v19, 1);
}
}
LABEL_30:
v19->getRealPosition(v19);
if ( v77 == v79 && (v19->getRealPosition(v19), v78 == *((float *)&p.tv_sec + 1)) )
{
++v17;
}
else
{
v27 = v19->CCSpritePlus::cocos2d::CCSprite::cocos2d::CCNodeRGBA::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
v19->m_isDirty = 1;
++v17;
v27->setObjectRectDirty(v19, 1);
v19->setOrientedRectDirty(v19, 1);
}
if ( v17 >= (unsigned int)cocos2d::CCArray::count(a1->m_objects) )
goto LABEL_33;
}
v22 = 0;
LABEL_21:
m_positionY = v19->m_positionY;
if ( m_positionY <= 0.0 )
goto LABEL_80;
goto LABEL_22;
}
LABEL_33:
AudioEffectsLayer::resetAudioVars(a1->m_audioEffectsLayer);
PlayLayer::loadDefaultColors(a1);
LastCheckpoint = PlayLayer::loadLastCheckpoint(a1);
if ( !*((_BYTE *)v1 + 496) )
{
GJEffectManager::getPersistentStateString(a1->m_effectManager);
sub_D18EA8(v1 + 272, &p);
v29 = (void *)(p.tv_sec - 24);
if ( (__int64 *)(p.tv_sec - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v75 = (unsigned int *)(p.tv_sec - 8);
do
v76 = __ldaxr(v75);
while ( __stlxr(v76 - 1, v75) );
}
else
{
v76 = *(_DWORD *)(p.tv_sec - 8);
*(_DWORD *)(p.tv_sec - 8) = v76 - 1;
}
if ( v76 <= 0 )
operator delete(v29);
}
}
GJEffectManager::resetUsedItemState(a1->m_effectManager);
if ( LastCheckpoint )
{
v30 = *((unsigned __int8 *)v1 + 496);
*((_BYTE *)v1 + 697) = 0;
if ( !v30 )
GJBaseGameLayer::resetRecord(a1, a1->m_gameState.m_unkUint4, 0);
}
else
{
a1->m_tickIndex = 0;
a1->m_clickIndex = 0;
a1->m_timePlayed = 0.0;
GJBaseGameLayer::resetRecord(a1, 0, 0);
m_startPosObject = a1->m_startPosObject;
a1->m_unk32e0 = a1->m_randomSeed;
if ( m_startPosObject )
{
m_currentCheckpoint = a1->m_currentCheckpoint;
if ( m_currentCheckpoint )
{
PlayLayer::loadFromCheckpoint(a1, m_currentCheckpoint);
goto LABEL_38;
}
m_startSettings = m_startPosObject->m_startSettings;
}
else
{
m_startSettings = a1->m_levelSettings;
}
GJBaseGameLayer::setupLevelStart(a1, m_startSettings);
}
LABEL_38:
m_player1 = a1->m_player1;
v32 = m_player1->getPosition(m_player1);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)&p, v32);
cocos2d::CCPoint::operator=(&m_player1->m_position, v33, v34);
if ( a1->m_gameState.m_isDualMode )
{
m_player2 = a1->m_player2;
v36 = m_player2->getPosition(m_player2);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)&p, v36);
cocos2d::CCPoint::operator=(&m_player2->m_position, v37, v38);
}
else
{
a1->m_player2->setPosition(a1->m_player2, &stru_1241EB0);
v61 = a1->m_player2;
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)&p, &stru_1241EB0);
cocos2d::CCPoint::operator=(&v61->m_position, v62, v63);
}
if ( !LastCheckpoint )
{
v65 = a1->m_player1;
v66 = v65->getPosition(v65);
GameObject::setLastPosition(v65, v66);
v67 = a1->m_player2;
v68 = v67->getPosition(v67);
GameObject::setLastPosition(v67, v68);
if ( a1->m_startPosObject )
{
if ( !a1->m_currentCheckpoint )
GJBaseGameLayer::loadStartPosObject(a1);
}
}
GJBaseGameLayer::updatePlayerCollisionBlocks(a1);
if ( !*((_BYTE *)v1 + 658) )
{
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_44;
LABEL_100:
GJBaseGameLayer::updateProximityVolumeEffects(a1);
GJBaseGameLayer::updateLevelColors(a1);
GJBaseGameLayer::updateCamera(a1, 0.0);
a1->updateVisibility(a1, 0.0);
GJBaseGameLayer::updateGradientLayers(a1);
GJBaseGameLayer::updateShaderLayer(a1, 0.0);
PlayLayer::updateAttempts(a1);
a1->m_savedAttempts = a1->m_attempts;
sub_D18EA8(v1 + 274, v1 + 272);
goto LABEL_48;
}
if ( !LastCheckpoint )
{
a1->m_startingFromBeginning = 1;
GJBaseGameLayer::checkSpawnObjects(a1);
goto LABEL_100;
}
LABEL_44:
m_respawnID = (unsigned int)LastCheckpoint->m_respawnID;
if ( (int)m_respawnID > 0 )
{
m_uniqueID = (unsigned int)LastCheckpoint->m_uniqueID;
spawnGroup = a1->spawnGroup;
p.tv_sec = 0;
p.tv_usec = 0;
v81 = 0;
((void (__fastcall *)(PlayLayer *, __int64, _QWORD, struct timeval *, __int64, _QWORD, double))spawnGroup)(
a1,
m_respawnID,
0,
&p,
m_uniqueID,
0,
0.0);
if ( p.tv_sec )
operator delete((void *)p.tv_sec);
}
GJBaseGameLayer::gameEventTriggered(a1, CheckpointRespawn, 0, 0);
GJBaseGameLayer::updateProximityVolumeEffects(a1);
GJBaseGameLayer::updateLevelColors(a1);
GJBaseGameLayer::updateCamera(a1, 0.0);
a1->updateVisibility(a1, 0.0);
GJBaseGameLayer::updateGradientLayers(a1);
GJBaseGameLayer::updateShaderLayer(a1, 0.0);
PlayLayer::updateAttempts(a1);
LABEL_48:
v42 = GameStatsManager::sharedState();
GameStatsManager::incrementStat(v42, &byte_F78BA8);
m_level = a1->m_level;
v44 = m_level->m_attempts.random - m_level->m_attempts.seed + 1;
m_level->m_attempts.value = v44;
v45 = (int)(float)((float)((float)rand() * 4.6566e-10) * 1000.0);
m_level->m_attempts.seed = v45;
m_level->m_attempts.random = v44 + v45;
PlayLayer::updateProgressbar(a1);
GJBaseGameLayer::refreshCounterLabels(a1);
v46 = *((unsigned __int8 *)v1 + 696);
if ( *((_BYTE *)v1 + 270) )
{
*((_BYTE *)v1 + 696) = 0;
v47 = LastCheckpoint == nullptr;
}
else
{
v47 = LastCheckpoint == nullptr;
if ( (v47 & v46) != 0 )
{
v47 &= v46;
if ( !a1->m_startPosObject )
PlayLayer::startMusic(a1);
}
}
if ( GameManager::sharedState()->m_recordGameplay && !*((_BYTE *)v1 + 592) && !*((_BYTE *)v1 + 656) )
{
PlayLayer::tryStartRecord(a1);
GJBaseGameLayer::removeReleasedButtons(a1);
if ( UILayer::isJumpButtonPressed(a1->m_uiLayer) )
goto LABEL_54;
LABEL_85:
GJBaseGameLayer::queueButton(a1, 1, 0, 0, 0.0);
goto LABEL_55;
}
GJBaseGameLayer::removeReleasedButtons(a1);
if ( !UILayer::isJumpButtonPressed(a1->m_uiLayer) )
goto LABEL_85;
LABEL_54:
GJBaseGameLayer::queueButton(a1, 1, 1, 0, 0.0);
LABEL_55:
if ( !*((_BYTE *)v1 + 592) && !*((_BYTE *)v1 + 2102) )
*((_BYTE *)v1 + 1952) = 0;
*((_BYTE *)v1 + 657) = 0;
*((_BYTE *)v1 + 645) = 0;
GJBaseGameLayer::syncBGTextures(a1);
v48 = clock();
m_batchNodes = a1->m_batchNodes;
dwTickEndp = v48;
dwDurationp = v48 - dwTickStartp;
if ( m_batchNodes )
{
data = m_batchNodes->data;
if ( data->num )
{
arr = (cocos2d::CCNode **)data->arr;
v52 = &arr[data->num - 1];
while ( v52 >= arr )
{
v53 = *arr;
if ( !*arr )
break;
++arr;
cocos2d::CCNode::qsortAllChildrenWithIndex(v53);
}
}
}
GJBaseGameLayer::sortSectionVector(a1);
if ( *((_BYTE *)v1 + 270) && (v46 || *((_BYTE *)v1 + 2100)) )
{
*((_BYTE *)v1 + 2100) = 0;
if ( v47 )
{
v71 = (cocos2d::CCSequence *)cocos2d::CCDelayTime::create(0.2);
v72 = (cocos2d::CCFiniteTimeAction *)cocos2d::CCCallFunc::create(a1, PlayLayer::startGameDelayed, 0);
v73 = (cocos2d::CCAction *)cocos2d::CCSequence::create(v71, v72, 0);
cocos2d::CCNode::runAction(a1, v73);
a1->m_startingFromBeginning = 0;
*((_BYTE *)v1 + 1862) = 1;
return;
}
*((_BYTE *)v1 + 696) = 1;
a1->m_startingFromBeginning = 0;
*((_BYTE *)v1 + 1862) = 1;
}
else
{
a1->m_startingFromBeginning = 0;
*((_BYTE *)v1 + 1862) = 1;
if ( !LastCheckpoint )
return;
}
cocos2d::CCPoint::operator=(&a1->m_gameState.m_cameraPosition2, v54, v55);
cocos2d::CCPoint::operator=(&a1->m_gameState.m_cameraStepDiff, v56, v57);
cocos2d::CCPoint::operator=(&a1->m_gameState.m_unkPoint4, v58, v59);
}