//
// MapSelectLayer::init from 0x980490 to 0x980b3c (1708 bytes)
//
// 2 xrefs:
// > ??> @ 0x6bcb8
// > ??> @ 0x11c3760
//
// 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 MapSelectLayer::init(MapSelectLayer *a1)
{
_BOOL8 v2; // x0
bool v3; // w24
cocos2d::CCArray *v5; // x0
cocos2d::CCSprite *v6; // x0
CCMenuItemSpriteExtra *v7; // x19
cocos2d::CCNode *v8; // x19
void (__fastcall *setPosition)(cocos2d::CCNode *__hidden, const cocos2d::CCPoint *); // x22
cocos2d::CCDirector *v10; // x0
float v11; // s0
float v12; // s8
cocos2d::CCDirector *v13; // x0
float v14; // s0
GJBigSprite *v15; // x19
void (__fastcall *v16)(cocos2d::CCNode *__hidden, const cocos2d::CCPoint *); // x22
cocos2d::CCNode *v17; // x0
GJBigSprite *m_bigSprite; // x3
GameManager *v19; // x0
SimplePlayer *v20; // x0
SimplePlayer_vtbl *v21; // x1
GJMapObject *v22; // x19
float v23; // s2
SimplePlayer *m_player; // x26
GameManager *v25; // x0
SimplePlayer *v26; // x22
GameManager *v27; // x26
GameManager *v28; // x0
GameManager *v29; // x26
GameManager *v30; // x0
GameManager *v31; // x0
SimplePlayer *v32; // x22
GameManager *v33; // x26
GameManager *v34; // x0
int v35; // w22
GJMapObject *Monster; // x26
int v37; // w19
int v38; // w0
float v39; // s2
GJMapObject *v40; // x19
float v41; // s2
GameLevelManager *v42; // x19
GJGameLevel *LocalLevelByName; // x19
void *v44; // x0
LevelEditorLayer *v45; // x0
LevelEditorLayer *m_editorLayer; // x0
LevelEditorLayer *v47; // x0
GameLevelManager *v48; // x0
void *v49; // x0
unsigned int *v50; // x21
int v51; // w1
unsigned int *v52; // x1
int v53; // w2
_QWORD v54[2]; // [xsp+0h] [xbp+0h] BYREF
cocos2d::ccColor3B v55; // [xsp+98h] [xbp+98h] BYREF
cocos2d::CCPoint v56; // [xsp+A0h] [xbp+A0h] BYREF
cocos2d::SEL_MenuHandler v57; // 0:x2.16
cocos2d::CCPoint v58; // 0:s0.4,4:s1.4
cocos2d::CCPoint v59; // 0:s0.4,4:s1.4
cocos2d::CCPoint v60; // 0:s0.4,4:s1.4
v2 = cocos2d::CCLayer::init(a1);
v3 = v2;
if ( v2 )
{
v5 = (cocos2d::CCArray *)cocos2d::CCArray::create((cocos2d::CCArray *)v2);
a1->m_monsters = v5;
cocos2d::CCObject::retain(v5);
v6 = cocos2d::CCSprite::createWithSpriteFrameName("GJ_arrow_01_001.png");
v57.ptr = (void (__cdecl *)(cocos2d::CCObject *))a1;
v57.adj = (size_t)MapSelectLayer::onBack;
v7 = CCMenuItemSpriteExtra::create(v6, nullptr, v57);
CCMenuItemSpriteExtra::setSizeMult(v7, 1.6);
v8 = (cocos2d::CCNode *)cocos2d::CCMenu::create((cocos2d::CCMenu *)v7, nullptr);
a1->addChild_0(a1, v8, 1);
setPosition = v8->setPosition;
v10 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getScreenLeft(v10);
v12 = v11;
v13 = cocos2d::CCDirector::sharedDirector();
cocos2d::CCDirector::getScreenTop(v13);
cocos2d::CCPoint::CCPoint(&v56, v12 + 25.0, v14 - 22.0);
setPosition(v8, &v56);
GameManager::sharedState()->m_somethingInMenuLayer = 0;
v15 = GJBigSprite::create();
a1->m_bigSprite = v15;
v16 = v15->setPosition;
cocos2d::CCPoint::CCPoint(&v56, -165.0, -800.0);
v16(v15, &v56);
GJBigSprite::updateSpriteVisibility(a1->m_bigSprite);
a1->m_bigSprite->m_loadSprites = 1;
v17 = cocos2d::CCNode::create();
m_bigSprite = a1->m_bigSprite;
a1->m_mainLayer = v17;
m_bigSprite->addChild_0(m_bigSprite, v17, 20);
v19 = GameManager::sharedState();
v20 = SimplePlayer::create(v19->m_playerFrame.random - v19->m_playerFrame.seed);
v21 = v20->cocos2d::CCSprite::cocos2d::CCNodeRGBA::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
a1->m_player = v20;
((void (__fastcall *)(float))v21->setScale)(0.5);
v22 = GJMapObject::create(a1->m_player);
a1->m_mainLayer->addChild_0(a1->m_mainLayer, v22, 0);
cocos2d::CCPoint::CCPoint(&v56, 462.0, 950.0);
v58.x = 0.0;
GJMapObject::setObjectOrigin(v22, v58, v23);
m_player = a1->m_player;
v25 = GameManager::sharedState();
v26 = a1->m_player;
m_player->m_hasGlowOutline = v25->m_playerGlow;
v27 = GameManager::sharedState();
v28 = GameManager::sharedState();
v55 = GameManager::colorForIdx(v27, v28->m_playerColor.random - v28->m_playerColor.seed);
v29 = GameManager::sharedState();
v30 = GameManager::sharedState();
*(cocos2d::ccColor3B *)&v56.x = GameManager::colorForIdx(v29, v30->m_playerColor2.random - v30->m_playerColor2.seed);
SimplePlayer::setColors(v26, &v55, (const cocos2d::ccColor3B *)&v56);
v31 = GameManager::sharedState();
if ( v31->m_playerGlowColor.random - v31->m_playerGlowColor.seed < 0 )
{
SimplePlayer::disableCustomGlowColor(a1->m_player);
}
else
{
v32 = a1->m_player;
v33 = GameManager::sharedState();
v34 = GameManager::sharedState();
*(cocos2d::ccColor3B *)&v56.x = GameManager::colorForIdx(
v33,
v34->m_playerGlowColor.random - v34->m_playerGlowColor.seed);
SimplePlayer::enableCustomGlowColor(v32, (const cocos2d::ccColor3B *)&v56);
}
v35 = 10;
SimplePlayer::updateColors(a1->m_player);
GJMapObject::startPlayerJumpLoop(v22);
do
{
Monster = GJMapObject::createMonster((int)&elf_hash_bucket[103] + 2);
a1->m_mainLayer->addChild_0(a1->m_mainLayer, Monster, 0);
v37 = rand();
v38 = rand();
cocos2d::CCPoint::CCPoint(
&v56,
(float)((float)((float)((float)((float)v37 * 4.6566e-10) * 2.0) + -1.0) * 100.0) + 600.0,
(float)((float)((float)((float)((float)v38 * 4.6566e-10) * 2.0) + -1.0) * 100.0) + 600.0);
v59.x = 50.0;
GJMapObject::setObjectOrigin(Monster, v59, v39);
cocos2d::CCArray::addObject(a1->m_monsters, Monster);
--v35;
}
while ( v35 );
v40 = GJMapObject::createMonster((int)&elf_hash_bucket[205] + 3);
a1->m_mainLayer->addChild_0(a1->m_mainLayer, v40, 0);
cocos2d::CCPoint::CCPoint(&v56, 436.0, 776.0);
v60.x = 50.0;
GJMapObject::setObjectOrigin(v40, v60, v41);
v40->m_shadowSprite->setVisible(v40->m_shadowSprite, 0);
cocos2d::CCArray::addObject(a1->m_monsters, v40);
a1->m_editMode = 0;
v42 = GameLevelManager::sharedState();
sub_D153B8((unsigned int)v54 + 160, "gamemap");
LocalLevelByName = (GJGameLevel *)GameLevelManager::getLocalLevelByName((__int64)v42, (const void **)&v56);
v44 = (void *)(*(_QWORD *)&v56 - 24LL);
if ( (__int64 *)(*(_QWORD *)&v56 - 24LL) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v52 = (unsigned int *)(*(_QWORD *)&v56 - 8LL);
do
v53 = __ldaxr(v52);
while ( __stlxr(v53 - 1, v52) );
}
else
{
v53 = *(_DWORD *)(*(_QWORD *)&v56 - 8LL);
*(_DWORD *)(*(_QWORD *)&v56 - 8LL) = v53 - 1;
}
if ( v53 <= 0 )
operator delete(v44);
}
if ( !LocalLevelByName )
{
v48 = GameLevelManager::sharedState();
LocalLevelByName = GameLevelManager::createNewLevel(v48);
sub_D153B8((unsigned int)v54 + 160, "gamemap");
sub_D18EA8(&LocalLevelByName->m_levelName, &v56);
v49 = (void *)(*(_QWORD *)&v56 - 24LL);
if ( (__int64 *)(*(_QWORD *)&v56 - 24LL) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v50 = (unsigned int *)(*(_QWORD *)&v56 - 8LL);
do
v51 = __ldaxr(v50);
while ( __stlxr(v51 - 1, v50) );
}
else
{
v51 = *(_DWORD *)(*(_QWORD *)&v56 - 8LL);
*(_DWORD *)(*(_QWORD *)&v56 - 8LL) = v51 - 1;
}
if ( v51 <= 0 )
operator delete(v49);
}
}
v45 = LevelEditorLayer::create(LocalLevelByName, !a1->m_editMode);
a1->m_editorLayer = v45;
LevelEditorLayer::toggleBackground(v45, 0);
LevelEditorLayer::toggleGround(a1->m_editorLayer, 0);
if ( a1->m_editMode )
{
a1->addChild(a1, a1->m_editorLayer);
a1->m_editorLayer->addChild_0(a1->m_editorLayer, a1->m_bigSprite, -100);
}
else
{
m_editorLayer = a1->m_editorLayer;
m_editorLayer->m_alwaysHideParticleIcons = 1;
LevelEditorLayer::updatePreviewParticles(m_editorLayer);
v47 = a1->m_editorLayer;
v47->m_alwaysPreviewMode = 1;
LevelEditorLayer::updateEditorMode(v47);
a1->addChild(a1, a1->m_bigSprite);
a1->m_mainLayer->addChild_0(a1->m_mainLayer, a1->m_editorLayer, 100);
a1->setKeypadEnabled(a1, 1);
a1->setKeyboardEnabled(a1, 1);
a1->setTouchEnabled(a1, 1);
a1->setMouseEnabled(a1, 1);
}
cocos2d::CCNode::scheduleUpdate(a1);
}
return v3;
}