//
// PlayLayer::init from 0x1000ac1b0 to 0x1000acc11 (2657 bytes)
//
// 2 xrefs:
// > PlayLayer::scene @ 0x1000ac0e3
// > PlayLayer::create @ 0x1000ac171
//
// 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 __fastcall PlayLayer::init(PlayLayer *a1, GJGameLevel *a2, bool a3, bool a4)
{
_BOOL4 v4; // r15d
bool v7; // bl
cocos2d::CCDirector *v8; // rax
GameManager *v9; // rax
GameManager *v10; // rax
bool GameVariable; // al
GameManager *v12; // rax
GameManager *v13; // rax
GameManager *v14; // rax
GameManager *v15; // rax
__int64 v16; // rsi
GameManager *v17; // r15
bool m_performanceMode; // al
GJLevelType m_levelType; // eax
bool v20; // al
cocos2d::CCArray *v21; // rax
cocos2d::CCArray *v22; // rdi
int v23; // ebx
GravityEffectSprite *v24; // r13
cocos2d::CCArray *m_gravityEffects; // r12
cocos2d::CCArray *v26; // rax
cocos2d::CCDictionary *v27; // rax
cocos2d::CCDirector *v28; // rsi
cocos2d::CCArray *v29; // rax
cocos2d::CCArray *v30; // rdi
cocos2d::CCArray *v31; // rax
cocos2d::CCArray *v32; // rdi
cocos2d::CCArray *v33; // rax
cocos2d::CCArray *v34; // rdi
cocos2d::CCArray *v35; // rax
int v36; // eax
__m128 v37; // xmm1
cocos2d::CCParticleSystemQuad *v38; // rax
cocos2d::CCParticleSystemQuad *m_glitterParticles; // r12
cocos2d::CCDirector *v40; // rax
cocos2d::CCDirector *v41; // rax
__m128 v42; // xmm0
cocos2d::CCDrawNode *v43; // rax
GameManager *v44; // rax
cocos2d::CCLabelBMFont *v45; // rax
cocos2d::CCLabelBMFont *m_statusLabel; // rbx
cocos2d::CCLabelBMFont *v47; // rbx
cocos2d::CCDirector *v48; // rax
double v49; // xmm0_8
float v50; // xmm1_4
GameManager *v51; // rax
bool v52; // al
cocos2d::CCLabelBMFont *v53; // rdi
bool m_isTestMode; // al
const char *v55; // rsi
GJGameLevel *m_level; // rax
std::string *p_m_levelString; // rax
const char *v58; // r12
size_t v59; // rax
size_t v60; // r13
char *v61; // r15
size_t v62; // rbx
bool v63; // r15
GJGameLevel *v64; // rax
GJLevelType v65; // ecx
std::string::size_type size; // rax
cocos2d::CCLabelBMFont *v67; // r12
__int64 v69; // [rsp+8h] [rbp-B8h] BYREF
__int128 v70; // [rsp+10h] [rbp-B0h] BYREF
void *data; // [rsp+20h] [rbp-A0h]
float v72[2]; // [rsp+28h] [rbp-98h] BYREF
char __s[16]; // [rsp+30h] [rbp-90h] BYREF
void *longStorage; // [rsp+40h] [rbp-80h]
_BOOL4 v75; // [rsp+54h] [rbp-6Ch]
_QWORD __dst[2]; // [rsp+58h] [rbp-68h] BYREF
void *__p; // [rsp+68h] [rbp-58h]
double v78; // [rsp+70h] [rbp-50h]
std::string v79; // [rsp+78h] [rbp-48h] BYREF
bool v80; // [rsp+97h] [rbp-29h]
v4 = a4;
v7 = GJBaseGameLayer::init(a1);
if ( !v7 )
return v7;
a1->m_level = a2;
cocos2d::CCObject::retain(a2);
v8 = cocos2d::CCDirector::sharedDirector();
*(_BYTE *)(((__int64 (__fastcall *)(cocos2d::CCDirector *))v8->getKeyboardDispatcher)(v8) + 92) = 1;
v9 = GameManager::sharedState();
if ( GameManager::getGameVariable(v9, "0128") )
{
PlatformToolbox::toggleLockCursor(1);
}
else
{
v10 = GameManager::sharedState();
if ( !GameManager::getGameVariable(v10, "0024") )
PlatformToolbox::hideCursor();
}
v75 = v4;
v80 = v7;
((void (__fastcall *)(PlayLayer *))a1->toggleMusicInPractice)(a1);
GameManager::sharedState()->m_somethingInMenuLayer = 1;
a1->m_damageVerified = 0;
a1->m_nextColorKey = 1;
a1->m_unk376d = 0;
GameVariable = 1;
if ( !a1->m_level->m_disableShakeToggled )
{
v12 = GameManager::sharedState();
GameVariable = GameManager::getGameVariable(v12, "0172");
}
a1->m_skipCameraShake = GameVariable;
v13 = GameManager::sharedState();
a1->m_doNot = GameManager::getGameVariable(v13, "0095");
v14 = GameManager::sharedState();
a1->m_showLeaderboardPercentage = GameManager::getGameVariable(v14, "0099");
v15 = GameManager::sharedState();
v16 = (__int64)"0126";
a1->m_decimalPercentage = GameManager::getGameVariable(v15, "0126");
a1->m_lowDetailMode = a2->m_lowDetailModeToggled;
v17 = GameManager::sharedState();
if ( !a1->m_lowDetailMode || (m_performanceMode = 1, !a1->m_extraLDM) )
m_performanceMode = GameManager::sharedState()->m_performanceMode;
v17->m_addGlow = m_performanceMode;
GameManager::sharedState()->m_unkBool6 = 1;
if ( GameManager::sharedState()->m_showedMenu )
{
ftime((timeb *)&v79);
v78 = (double)(LOWORD(v79.__r_.__value_.__r.__words[1]) + 1000 * (*(_DWORD *)&v79.__r_.__value_.__l.0 & 0xFFFFF))
/ 1000.0
+ -180.0
+ 180.0;
GameManager::sharedState()->m_adTimer = v78;
GameManager::sharedState()->m_showedMenu = 0;
if ( !GameManager::sharedState()->m_recordGameplay )
{
LABEL_13:
a1->m_isTestMode = 0;
m_levelType = a2->m_levelType;
if ( m_levelType != Main )
goto LABEL_14;
LABEL_18:
v20 = 0;
goto LABEL_20;
}
}
else if ( !GameManager::sharedState()->m_recordGameplay )
{
goto LABEL_13;
}
v16 = 31;
cocos2d::CCNode::stopActionByTag(a1, 31);
a1->m_isTestMode = 0;
m_levelType = a2->m_levelType;
if ( m_levelType == Main )
goto LABEL_18;
LABEL_14:
v20 = m_levelType == Editor || a2->m_demon.random - a2->m_demon.seed == 1;
LABEL_20:
a1->m_recordInputs = v20;
a1->m_attempts = 0;
GJBaseGameLayer::resetActiveEnterEffects(a1);
a1->m_maxObjectX = 0.0;
a1->m_jumps = 0;
a1->m_levelEndAnimationStarted = 0;
*(_OWORD *)&a1->m_gameState.m_totalTime = 0;
a1->m_gameState.m_unkDouble3 = 0.0;
a1->m_skipArtReload = 1;
a1->m_gameState.m_isDualMode = 0;
a1->m_totalGravityEffects = 4;
if ( AppDelegate::get()->m_unk0eb || AppDelegate::get()->m_unk0ec )
a1->m_totalGravityEffects = 2;
v21 = (cocos2d::CCArray *)sub_10071F9E0(a1, v16);
a1->m_gravityEffects = v21;
v22 = v21;
cocos2d::CCObject::retain(v21);
if ( a1->m_totalGravityEffects > 0 )
{
v23 = 0;
do
{
m_gravityEffects = a1->m_gravityEffects;
v24 = (GravityEffectSprite *)operator new(0x258u);
__bzero(v24, 600);
cocos2d::CCSprite::CCSprite(v24);
v24->cocos2d::CCSprite::cocos2d::CCNodeRGBA::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable = (GravityEffectSprite_vtbl *)off_1008B7DA8;
v24->cocos2d::CCSprite::cocos2d::CCNodeRGBA::cocos2d::CCRGBAProtocol::__vftable = (cocos2d::CCRGBAProtocol_vtbl *)off_1008B8280;
v24->cocos2d::CCSprite::cocos2d::CCTextureProtocol::cocos2d::CCBlendProtocol::__vftable = (cocos2d::CCTextureProtocol_vtbl *)off_1008B8300;
if ( GravityEffectSprite::init(v24) )
{
cocos2d::CCObject::autorelease(v24);
}
else
{
((void (__fastcall *)(GravityEffectSprite *))v24->~GravityEffectSprite_0)(v24);
v24 = nullptr;
}
v22 = m_gravityEffects;
v16 = (__int64)v24;
sub_10071FCD0(m_gravityEffects, v24);
++v23;
}
while ( v23 < a1->m_totalGravityEffects );
}
v26 = (cocos2d::CCArray *)sub_10071F9E0(v22, v16);
a1->m_collectibles = v26;
cocos2d::CCObject::retain(v26);
GameManager::sharedState()->m_editorEnabled = 0;
GameManager::sharedState()->m_playLayer = a1;
GameManager::sharedState()->m_isParticleObject = 0;
v27 = cocos2d::CCDictionary::create();
a1->m_colorKeyDict = v27;
cocos2d::CCObject::retain(v27);
v28 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getWinSize((cocos2d::CCDirector *)v72);
v29 = (cocos2d::CCArray *)sub_10071F9E0(v72, v28);
a1->m_checkpointArray = v29;
v30 = v29;
cocos2d::CCObject::retain(v29);
v31 = (cocos2d::CCArray *)sub_10071F9E0(v30, v28);
a1->m_speedObjects = v31;
v32 = v31;
cocos2d::CCObject::retain(v31);
v33 = (cocos2d::CCArray *)sub_10071F9E0(v32, v28);
a1->m_circleWaveArray = v33;
v34 = v33;
cocos2d::CCObject::retain(v33);
v35 = (cocos2d::CCArray *)sub_10071F9E0(v34, v28);
a1->m_unk37c0 = v35;
cocos2d::CCObject::retain(v35);
GJBaseGameLayer::setupLayers(a1);
v36 = rand();
v42 = 0;
v42.f32[0] = (float)((float)v36 * 4.6566129e-10) + (float)((float)v36 * 4.6566129e-10);
v37 = _mm_or_ps(_mm_and_ps((__m128)xmmword_1008150B0, v42), (__m128)xmmword_1008150C0);
v37.f32[0] = v37.f32[0] + v42.f32[0];
a1->m_pulseRodIndex = (int)(float)(_mm_round_ss((__m128)0LL, v37, 11).f32[0] + 1.0);
v38 = cocos2d::CCParticleSystemQuad::create("glitterEffect.plist", 0);
a1->m_glitterParticles = v38;
((void (__fastcall *)(cocos2d::CCParticleSystemQuad *, __int64))v38->setPositionType)(v38, 1);
((void (__fastcall *)(cocos2d::CCLayer *, cocos2d::CCParticleSystemQuad *, _QWORD))a1->m_objectLayer->addChild_0)(
a1->m_objectLayer,
a1->m_glitterParticles,
0);
m_glitterParticles = a1->m_glitterParticles;
v40 = cocos2d::CCDirector::sharedDirector();
*(float *)&v78 = (float)(sub_100484D60(v40) * 480.0) / 1.8;
v41 = cocos2d::CCDirector::sharedDirector();
*(double *)v42.i64 = sub_100484D50(v41);
v37.f32[0] = (float)(v42.f32[0] * 320.0) * 0.5;
v42.i64[0] = LODWORD(v78);
sub_10028CBE0(&v79, *(float *)&v78, v37.f32[0]);
((void (__fastcall *)(cocos2d::CCParticleSystemQuad *, std::string *))m_glitterParticles->setPosVar)(
m_glitterParticles,
&v79);
cocos2d::CCParticleSystem::stopSystem(a1->m_glitterParticles);
v43 = cocos2d::CCDrawNode::create();
a1->m_debugDrawNode = v43;
v69 = 0x30300000302LL;
cocos2d::CCDrawNode::setBlendFunc(v43, (const cocos2d::ccBlendFunc *)&v69);
((void (__fastcall *)(cocos2d::CCDrawNode *, __int64))a1->m_debugDrawNode->setTag)(a1->m_debugDrawNode, 4294957297LL);
((void (__fastcall *)(cocos2d::CCLayer *, cocos2d::CCDrawNode *, __int64))a1->m_aboveShaderObjectLayer->addChild_0)(
a1->m_aboveShaderObjectLayer,
a1->m_debugDrawNode,
1401);
PlayLayer::updateDebugDrawSettings(a1);
GJBaseGameLayer::createPlayer(a1);
if ( a1->m_level->m_levelType == Editor )
{
v44 = GameManager::sharedState();
if ( !GameManager::getGameVariable(v44, "0174") )
{
v45 = cocos2d::CCLabelBMFont::create_3("Ignore Damage", "bigFont.fnt");
a1->m_statusLabel = v45;
((void (__fastcall *)(cocos2d::CCLabelBMFont *, __int64))v45->setOpacity)(v45, 50);
((void (__fastcall *)(cocos2d::CCLabelBMFont *, float))a1->m_statusLabel->setScale)(a1->m_statusLabel, 0.40000001);
((void (__fastcall *)(PlayLayer *, cocos2d::CCLabelBMFont *, __int64))a1->addChild_0)(a1, a1->m_statusLabel, 1000);
m_statusLabel = a1->m_statusLabel;
sub_10028CBE0(&v79, 0.0, 1.0);
((void (__fastcall *)(cocos2d::CCLabelBMFont *, std::string *))m_statusLabel->setAnchorPoint)(m_statusLabel, &v79);
v47 = a1->m_statusLabel;
v48 = cocos2d::CCDirector::sharedDirector();
v49 = sub_100484D70(v48);
v50 = (float)(*(float *)&v49 + -5.0) + 1.0;
v42.i64[0] = 1084227584;
sub_10028CBE0(&v79, 5.0, v50);
((void (__fastcall *)(cocos2d::CCLabelBMFont *, std::string *))v47->setPosition)(v47, &v79);
((void (__fastcall *)(cocos2d::CCLabelBMFont *, _QWORD))a1->m_statusLabel->setVisible)(a1->m_statusLabel, 0);
}
v51 = GameManager::sharedState();
v52 = GameManager::getGameVariable(v51, "0173");
a1->m_ignoreDamage = v52;
if ( v52 )
a1->m_isIgnoreDamageEnabled = v52;
a1->m_player1->m_maybeCanRunIntoBlocks = v52;
a1->m_player2->m_maybeCanRunIntoBlocks = v52;
v53 = a1->m_statusLabel;
if ( v53 )
{
m_isTestMode = 1;
if ( !a1->m_isIgnoreDamageEnabled )
m_isTestMode = a1->m_isTestMode;
((void (__fastcall *)(cocos2d::CCLabelBMFont *, bool))v53->setVisible)(v53, m_isTestMode);
if ( a1->m_ignoreDamage )
{
v55 = "Ignore Damage";
}
else if ( a1->m_isIgnoreDamageEnabled )
{
v55 = "Used Ignore Damage";
}
else
{
if ( !a1->m_isTestMode )
goto LABEL_44;
v55 = "Testmode";
}
((void (__fastcall *)(cocos2d::CCLabelBMFont *, const char *))a1->m_statusLabel->setString)(
a1->m_statusLabel,
v55);
}
}
LABEL_44:
a1->m_passedIntegrity = 1;
m_level = a1->m_level;
if ( (m_level->m_levelString.m_data.m_short.sizex2 & 1) != 0 )
{
sub_100006B70(
__s,
m_level->m_levelString.m_data.m_long.longStorage,
m_level->m_levelString.m_data.m_long.size,
*(double *)v42.i64);
if ( (__s[0] & 1) == 0 )
goto LABEL_46;
}
else
{
p_m_levelString = &m_level->m_levelString;
longStorage = p_m_levelString->m_data.m_long.longStorage;
v42 = *(__m128 *)&p_m_levelString->m_data.m_short.sizex2;
*(_OWORD *)__s = *(_OWORD *)&p_m_levelString->m_data.m_short.sizex2;
if ( (__s[0] & 1) == 0 )
{
LABEL_46:
v58 = &__s[1];
goto LABEL_49;
}
}
v58 = (const char *)longStorage;
LABEL_49:
v59 = strlen(v58);
if ( v59 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100006BF0(*(double *)v42.i64);
v60 = v59;
if ( v59 >= 0x17 )
{
v62 = 26;
if ( (v59 | 7) != 0x17 )
v62 = (v59 | 7) + 1;
v61 = (char *)operator new(v62);
__p = v61;
__dst[0] = v62 | 1;
__dst[1] = v60;
goto LABEL_56;
}
LOBYTE(__dst[0]) = 2 * v59;
v61 = (char *)__dst + 1;
if ( v59 )
LABEL_56:
memmove(v61, v58, v60);
v61[v60] = 0;
cocos2d::ZipUtils::decompressString(&v79);
v7 = v80;
v63 = v75;
if ( (__dst[0] & 1) != 0 )
{
operator delete(__p);
if ( (__s[0] & 1) == 0 )
{
LABEL_59:
v64 = a1->m_level;
v65 = v64->m_levelType;
if ( v65 != Editor )
goto LABEL_60;
goto LABEL_65;
}
}
else if ( (__s[0] & 1) == 0 )
{
goto LABEL_59;
}
operator delete(longStorage);
v64 = a1->m_level;
v65 = v64->m_levelType;
if ( v65 != Editor )
{
LABEL_60:
if ( v65 == Main )
{
if ( (*(_BYTE *)&v79.__r_.__value_.__s.0 & 1) != 0 )
{
sub_100006B70(&v70, v79.__r_.__value_.__l.__data_, v79.__r_.__value_.__l.__size_, *(double *)v42.i64);
v64 = a1->m_level;
}
else
{
data = v79.__r_.__value_.__l.__data_;
v70 = *(_OWORD *)&v79.__r_.__value_.__l.0;
}
a1->m_passedIntegrity = LevelTools::verifyLevelIntegrity(
&v70,
(unsigned int)(v64->m_levelID.random - v64->m_levelID.seed));
if ( (v70 & 1) != 0 )
operator delete(data);
goto LABEL_73;
}
goto LABEL_66;
}
LABEL_65:
if ( v64->m_stars.random > v64->m_stars.seed )
{
LABEL_66:
if ( (*(_BYTE *)&v79.__r_.__value_.__s.0 & 1) != 0 )
size = v79.__r_.__value_.__l.__size_;
else
size = *(_BYTE *)&v79.__r_.__value_.__l.0 >> 1;
a1->m_passedIntegrity = size != 0;
}
LABEL_73:
if ( !a1->m_passedIntegrity )
{
v67 = cocos2d::CCLabelBMFont::create_3("Load Failed!", "bigFont.fnt");
((void (__fastcall *)(PlayLayer *, cocos2d::CCLabelBMFont *, __int64))a1->addChild_0)(a1, v67, 100);
sub_10028CBE0(__dst, v72[0] * 0.5, 0.5 * v72[1]);
((void (__fastcall *)(cocos2d::CCLabelBMFont *, _QWORD *))v67->setPosition)(v67, __dst);
}
PlayLayer::prepareCreateObjectsFromSetup(a1, &v79);
if ( !v63 )
{
while ( a1->m_loadingProgress < 1.0 )
PlayLayer::processCreateObjectsFromSetup(a1);
}
if ( (*(_BYTE *)&v79.__r_.__value_.__s.0 & 1) != 0 )
operator delete(v79.__r_.__value_.__l.__data_);
return v7;
}