//
// PlayLayer::init from 0x5e5fd0 to 0x5e6920 (2384 bytes)
//
// 2 xrefs:
// > PlayLayer::create @ 0x5e76ac
// > ??> @ 0x4f4b8
//
// 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
//
bool PlayLayer::init(PlayLayer *a1, GJGameLevel *a2, bool a3, bool a4)
{
_BOOL4 v6; // w26
bool v7; // w20
bool v8; // w24
cocos2d::CCDirector *v10; // x0
GameManager *v11; // x0
GameManager *v12; // x0
GameManager *v13; // x0
GJGameLevel *m_level; // x1
int m_cbsOverride; // w0
bool GameVariable; // w0
GameManager *v17; // x0
GameManager *v18; // x0
GameManager *v19; // x0
bool v20; // w0
bool m_lowDetailModeToggled; // w1
GameManager *v22; // x25
bool m_performanceMode; // w0
GJLevelType m_levelType; // w0
cocos2d::CCArray *v25; // x0
cocos2d::CCArray *v26; // x0
int v27; // w20
cocos2d::CCArray *m_totalGravityEffects; // x0
cocos2d::CCArray *m_gravityEffects; // x21
GravityEffectSprite *v30; // x0
cocos2d::CCArray *v31; // x0
cocos2d::CCDictionary *v32; // x0
cocos2d::CCDirector *v33; // x0
cocos2d::CCArray *v34; // x0
cocos2d::CCArray *v35; // x0
cocos2d::CCArray *v36; // x0
cocos2d::CCArray *v37; // x0
cocos2d::CCArray *v38; // x0
cocos2d::CCArray *v39; // x0
cocos2d::CCArray *v40; // x0
cocos2d::CCArray *v41; // x0
int v42; // w0
int v43; // w2
cocos2d::CCParticleSystemQuad *v44; // x0
cocos2d::CCParticleSystemQuad_vtbl *v45; // x2
cocos2d::CCParticleSystemQuad *m_glitterParticles; // x20
void (__fastcall *setPosVar)(cocos2d::CCParticleSystem *__hidden, const cocos2d::CCPoint *); // x21
cocos2d::CCDirector *v48; // x0
float v49; // s0
float v50; // s8
cocos2d::CCDirector *v51; // x0
float v52; // s0
cocos2d::CCDrawNode *v53; // x0
GJGameLevel *v54; // x1
int v55; // w3
int *p_m_leaderboardLevelPoints; // x0
char *v57; // x0
GJGameLevel *v58; // x1
GJLevelType v59; // w0
int m_passedIntegrity; // w1
cocos2d::CCLabelBMFont *v61; // x22
void (__fastcall *v62)(cocos2d::CCNode *__hidden, const cocos2d::CCPoint *); // x28
char *v63; // x22
unsigned int *v64; // x19
int v65; // w0
GameManager *v66; // x27
GameManager *v67; // x0
unsigned __int8 v68; // w0
int *v69; // x0
unsigned int *v70; // x3
int v71; // w1
GameManager *v72; // x0
GameManager *v73; // x0
bool v74; // w0
cocos2d::CCLabelBMFont *v75; // x0
cocos2d::CCLabelBMFont_vtbl *v76; // x2
cocos2d::CCLabelBMFont *m_statusLabel; // x20
void (__fastcall *setAnchorPoint)(cocos2d::CCLabelBMFont *__hidden, const cocos2d::CCPoint *); // x21
cocos2d::CCLabelBMFont *v79; // x20
void (__fastcall *setPosition)(cocos2d::CCNode *__hidden, const cocos2d::CCPoint *); // x21
cocos2d::CCDirector *v81; // x0
float v82; // s0
unsigned int *v83; // x1
int v84; // w2
unsigned int *p_m_practiceOpacity; // x1
int m_practiceOpacity_low; // w2
float v87; // [xsp+88h] [xbp+88h]
float v88; // [xsp+8Ch] [xbp+8Ch]
cocos2d::ccBlendFunc v89; // [xsp+90h] [xbp+90h] BYREF
_QWORD *v90; // [xsp+98h] [xbp+98h] BYREF
char *v91; // [xsp+A0h] [xbp+A0h] BYREF
GameManager *v92[2]; // [xsp+A8h] [xbp+A8h] BYREF
v6 = a4;
v7 = GJBaseGameLayer::init(a1);
v8 = v7;
if ( !v7 )
return v8;
a1->m_level = a2;
cocos2d::CCObject::retain(a2);
v10 = cocos2d::CCDirector::sharedDirector();
v10->getKeyboardDispatcher(v10)->m_bBlockRepeat = 1;
v11 = GameManager::sharedState();
if ( GameManager::getGameVariable(v11, "0128") )
{
PlatformToolbox::toggleLockCursor(1);
}
else
{
v12 = GameManager::sharedState();
if ( !GameManager::getGameVariable(v12, "0024") )
PlatformToolbox::hideCursor();
}
a1->toggleMusicInPractice(a1);
v13 = GameManager::sharedState();
m_level = a1->m_level;
v13->m_somethingInMenuLayer = 1;
m_cbsOverride = m_level->m_cbsOverride;
if ( m_cbsOverride )
{
if ( m_cbsOverride == 1 )
{
a1->m_clickBetweenSteps = 1;
}
else if ( m_cbsOverride == 2 )
{
a1->m_clickBetweenSteps = 0;
}
}
a1->m_damageVerified = 0;
a1->m_nextColorKey = 1;
GameVariable = v7;
a1->m_unk376d = 0;
if ( !m_level->m_disableShakeToggled )
{
v67 = GameManager::sharedState();
GameVariable = GameManager::getGameVariable(v67, "0172");
}
a1->m_skipCameraShake = GameVariable;
v17 = GameManager::sharedState();
a1->m_doNot = GameManager::getGameVariable(v17, "0095");
v18 = GameManager::sharedState();
a1->m_showLeaderboardPercentage = GameManager::getGameVariable(v18, "0099");
v19 = GameManager::sharedState();
v20 = GameManager::getGameVariable(v19, "0126");
m_lowDetailModeToggled = a2->m_lowDetailModeToggled;
a1->m_decimalPercentage = v20;
a1->m_lowDetailMode = m_lowDetailModeToggled;
v22 = GameManager::sharedState();
if ( !a1->m_lowDetailMode || !(m_performanceMode = a1->m_extraLDM) )
m_performanceMode = GameManager::sharedState()->m_performanceMode;
v22->m_addGlow = m_performanceMode;
GameManager::sharedState()->m_unkBool6 = 1;
if ( GameManager::sharedState()->m_showedMenu )
{
v66 = GameManager::sharedState();
clock_gettime(0, (struct timespec *)v92);
v66->m_adTimer = (double)(__int64)v92[0] + (double)(__int64)v92[1] / 1000000000.0 - 180.0 + 180.0;
GameManager::sharedState()->m_showedMenu = 0;
}
if ( !GameManager::sharedState()->m_recordGameplay )
{
m_levelType = a2->m_levelType;
a1->m_isTestMode = 0;
if ( m_levelType != Main )
goto LABEL_19;
LABEL_47:
v7 = 0;
goto LABEL_21;
}
PlayLayer::stopRecording(a1);
m_levelType = a2->m_levelType;
a1->m_isTestMode = 0;
if ( m_levelType == Main )
goto LABEL_47;
LABEL_19:
if ( m_levelType != Editor )
v7 = a2->m_demon.random - a2->m_demon.seed == 1;
LABEL_21:
a1->m_recordInputs = v7;
a1->m_attempts = 0;
GJBaseGameLayer::resetActiveEnterEffects(a1);
a1->m_jumps = 0;
a1->m_gameState.m_totalTime = 0.0;
a1->m_maxObjectX = 0.0;
a1->m_gameState.m_unkDouble3 = 0.0;
a1->m_gameState.m_levelTime = 0.0;
a1->m_skipArtReload = 1;
a1->m_levelEndAnimationStarted = 0;
a1->m_gameState.m_isDualMode = 0;
a1->m_totalGravityEffects = (unsigned int)&byte_4;
if ( *(&AppDelegate::get()->m_gamePaused + 2)
|| (v25 = (cocos2d::CCArray *)*((unsigned __int8 *)&AppDelegate::get()->m_gamePaused + 3), (_DWORD)v25) )
{
v25 = (cocos2d::CCArray *)((char *)&dword_0 + 2);
a1->m_totalGravityEffects = (unsigned int)&dword_0 + 2;
}
v26 = (cocos2d::CCArray *)cocos2d::CCArray::create(v25);
a1->m_gravityEffects = v26;
v27 = 0;
cocos2d::CCObject::retain(v26);
m_totalGravityEffects = (cocos2d::CCArray *)(unsigned int)a1->m_totalGravityEffects;
if ( (int)m_totalGravityEffects > 0 )
{
do
{
m_gravityEffects = a1->m_gravityEffects;
v30 = GravityEffectSprite::create();
++v27;
cocos2d::CCArray::addObject(m_gravityEffects, v30);
m_totalGravityEffects = (cocos2d::CCArray *)(unsigned int)a1->m_totalGravityEffects;
}
while ( (int)m_totalGravityEffects > v27 );
}
v31 = (cocos2d::CCArray *)cocos2d::CCArray::create(m_totalGravityEffects);
a1->m_collectibles = v31;
cocos2d::CCObject::retain(v31);
GameManager::sharedState()->m_editorEnabled = 0;
GameManager::sharedState()->m_playLayer = a1;
GameManager::sharedState()->m_isParticleObject = 0;
v32 = cocos2d::CCDictionary::create();
a1->m_colorKeyDict = v32;
cocos2d::CCObject::retain(v32);
v33 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getWinSize(v33);
v35 = (cocos2d::CCArray *)cocos2d::CCArray::create(v34);
a1->m_checkpointArray = v35;
cocos2d::CCObject::retain(v35);
v37 = (cocos2d::CCArray *)cocos2d::CCArray::create(v36);
a1->m_speedObjects = v37;
cocos2d::CCObject::retain(v37);
v39 = (cocos2d::CCArray *)cocos2d::CCArray::create(v38);
a1->m_circleWaveArray = v39;
cocos2d::CCObject::retain(v39);
v41 = (cocos2d::CCArray *)cocos2d::CCArray::create(v40);
a1->m_unk37c0 = v41;
cocos2d::CCObject::retain(v41);
GJBaseGameLayer::setupLayers(a1);
v42 = rand();
v43 = (int)(float)(roundf((float)((float)v42 * 4.6566e-10) + (float)((float)v42 * 4.6566e-10)) + 1.0);
a1->m_pulseRodIndex = v43;
v44 = (cocos2d::CCParticleSystemQuad *)cocos2d::CCParticleSystemQuad::create(
(cocos2d::CCParticleSystemQuad *)"glitterEffect.plist",
nullptr,
v43);
v45 = v44->cocos2d::CCParticleSystem::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
a1->m_glitterParticles = v44;
v45->setPositionType(v44, kCCPositionTypeRelative);
a1->m_objectLayer->addChild_0(a1->m_objectLayer, a1->m_glitterParticles, 0);
m_glitterParticles = a1->m_glitterParticles;
setPosVar = m_glitterParticles->setPosVar;
v48 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getScreenScaleFactorW(v48);
v50 = v49;
v51 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getScreenScaleFactorH(v51);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)v92, (float)(v50 * 480.0) / 1.8, (float)(v52 * 320.0) * 0.5);
setPosVar(m_glitterParticles, (const cocos2d::CCPoint *)v92);
cocos2d::CCParticleSystem::stopSystem(a1->m_glitterParticles);
v53 = cocos2d::CCDrawNode::create();
a1->m_debugDrawNode = v53;
v89.src = 770;
v89.dst = 771;
cocos2d::CCDrawNode::setBlendFunc(v53, &v89);
a1->m_debugDrawNode->setTag(a1->m_debugDrawNode, -9999);
a1->m_aboveShaderObjectLayer->addChild_0(a1->m_aboveShaderObjectLayer, a1->m_debugDrawNode, 1401);
PlayLayer::updateDebugDrawSettings(a1);
GJBaseGameLayer::createPlayer(a1);
v54 = a1->m_level;
if ( v54->m_levelType == Editor )
{
v72 = GameManager::sharedState();
if ( !GameManager::getGameVariable(v72, "0174") )
{
v75 = cocos2d::CCLabelBMFont::create();
v76 = v75->cocos2d::CCSpriteBatchNode::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
a1->m_statusLabel = v75;
v76->setOpacity(v75, 50);
a1->m_statusLabel->setScale(a1->m_statusLabel, 0.4);
a1->addChild_0(a1, a1->m_statusLabel, 1000);
m_statusLabel = a1->m_statusLabel;
setAnchorPoint = m_statusLabel->setAnchorPoint;
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)v92, 0.0, 1.0);
setAnchorPoint(m_statusLabel, (const cocos2d::CCPoint *)v92);
v79 = a1->m_statusLabel;
setPosition = v79->setPosition;
v81 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getScreenTop(v81);
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)v92, 5.0, (float)(v82 - 5.0) + 1.0);
setPosition(v79, (const cocos2d::CCPoint *)v92);
a1->m_statusLabel->setVisible(a1->m_statusLabel, 0);
}
v73 = GameManager::sharedState();
v74 = GameManager::getGameVariable(v73, "0173");
PlayLayer::toggleIgnoreDamage(a1, v74);
v54 = a1->m_level;
}
a1->m_passedIntegrity = 1;
sub_D18D28(&v91, &v54->m_levelString);
sub_D153B8((int)v92, v91);
cocos2d::ZipUtils::decompressString((cocos2d::ZipUtils *)v92, nullptr, 11, v55);
p_m_leaderboardLevelPoints = &v92[0][-1].m_leaderboardLevelPoints;
if ( (__int64 *)&v92[0][-1].m_leaderboardLevelPoints != &qword_124B6B0 )
{
if ( &pthread_create )
{
p_m_practiceOpacity = (unsigned int *)&v92[0][-1].m_practiceOpacity;
do
m_practiceOpacity_low = __ldaxr(p_m_practiceOpacity);
while ( __stlxr(m_practiceOpacity_low - 1, p_m_practiceOpacity) );
}
else
{
m_practiceOpacity_low = LODWORD(v92[0][-1].m_practiceOpacity);
LODWORD(v92[0][-1].m_practiceOpacity) = m_practiceOpacity_low - 1;
}
if ( m_practiceOpacity_low <= 0 )
operator delete(p_m_leaderboardLevelPoints);
}
v57 = v91 - 24;
if ( v91 - 24 != (char *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v83 = (unsigned int *)(v91 - 8);
do
v84 = __ldaxr(v83);
while ( __stlxr(v84 - 1, v83) );
}
else
{
v84 = *((_DWORD *)v91 - 2);
*((_DWORD *)v91 - 2) = v84 - 1;
}
if ( v84 <= 0 )
operator delete(v57);
}
v58 = a1->m_level;
v59 = v58->m_levelType;
if ( v59 == Main )
{
sub_D18D28(v92, &v90);
v68 = LevelTools::verifyLevelIntegrity(
(LevelTools *)v92,
(std::string)(unsigned int)(a1->m_level->m_levelID.random - a1->m_level->m_levelID.seed),
(int)a1->m_level);
a1->m_passedIntegrity = v68;
m_passedIntegrity = v68;
v69 = &v92[0][-1].m_leaderboardLevelPoints;
if ( (__int64 *)&v92[0][-1].m_leaderboardLevelPoints == &qword_124B6B0 )
goto LABEL_31;
v70 = (unsigned int *)&v92[0][-1].m_practiceOpacity;
if ( &pthread_create )
{
do
v71 = __ldaxr(v70);
while ( __stlxr(v71 - 1, v70) );
}
else
{
v71 = LODWORD(v92[0][-1].m_practiceOpacity);
LODWORD(v92[0][-1].m_practiceOpacity) = v71 - 1;
}
if ( v71 <= 0 )
{
operator delete(v69);
m_passedIntegrity = a1->m_passedIntegrity;
goto LABEL_31;
}
goto LABEL_49;
}
if ( v59 == Editor && v58->m_stars.random - v58->m_stars.seed <= 0 )
{
LABEL_49:
m_passedIntegrity = a1->m_passedIntegrity;
goto LABEL_31;
}
m_passedIntegrity = *(v90 - 3) != 0;
a1->m_passedIntegrity = m_passedIntegrity;
LABEL_31:
if ( !m_passedIntegrity )
{
v61 = cocos2d::CCLabelBMFont::create();
a1->addChild_0(a1, v61, 100);
v62 = v61->setPosition;
cocos2d::CCPoint::CCPoint((cocos2d::CCPoint *)v92, v87 * 0.5, v88 * 0.5);
v62(v61, (const cocos2d::CCPoint *)v92);
}
PlayLayer::prepareCreateObjectsFromSetup((__int64)a1, (const void **)&v90);
if ( !v6 )
{
while ( a1->m_loadingProgress < 1.0 )
PlayLayer::processCreateObjectsFromSetup(a1);
}
v63 = (char *)(v90 - 3);
if ( v90 - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v64 = (unsigned int *)(v90 - 1);
do
v65 = __ldaxr(v64);
while ( __stlxr(v65 - 1, v64) );
}
else
{
v65 = *((_DWORD *)v90 - 2);
*((_DWORD *)v90 - 2) = v65 - 1;
}
if ( v65 <= 0 )
operator delete(v63);
}
return v8;
}