//
// GauntletLayer::init from 0x1401f6140 to 0x1401f6927 (2023 bytes)
//
// 2 xrefs:
// > GauntletLayer::scene @ 0x1401f5ecd
// > ??> @ 0x1406cc8d0
//
// 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
//
// Hidden C++ exception states: #wind=8
bool GauntletLayer::init(GauntletLayer *a1, GauntletType a2)
{
bool result; // al
_BOOL8 v5; // rdx
_BOOL8 v6; // rdx
__int64 v7; // rcx
cocos2d::CCDirector *v8; // rax
int v9; // ebx
GameManager *v10; // rcx
int v11; // eax
int v12; // ebx
cocos2d::CCString *v13; // rax
const char *CString; // rax
struct cocos2d::CCSprite *v15; // rax
cocos2d::CCTexture2D *v16; // rax
size_t v17; // r15
float v18; // xmm0_4
cocos2d::CCSprite_vtbl *v19; // rbx
const cocos2d::CCPoint *v20; // rax
__int64 v21; // rdx
__int64 v22; // rcx
__int64 v23; // rcx
cocos2d::CCDirector *v24; // rax
float v25; // xmm0_4
cocos2d::CCSprite_vtbl *v26; // rbx
const cocos2d::CCPoint *v27; // rax
const char *v28; // rcx
struct cocos2d::CCLabelBMFont *v29; // rsi
float v30; // xmm0_4
cocos2d::CCLabelBMFont_vtbl *v31; // rbx
const cocos2d::CCPoint *v32; // rax
const char *v33; // rcx
struct cocos2d::CCLabelBMFont *v34; // rdi
float v35; // xmm0_4
__int64 v36; // rax
__int64 v37; // rdx
struct cocos2d::CCSprite *v38; // rax
CCMenuItemSpriteExtra *v39; // rsi
struct cocos2d::CCMenu *v40; // rdi
cocos2d::CCMenu_vtbl *v41; // rbx
__int64 v42; // rcx
cocos2d::CCDirector *v43; // rax
__int64 v44; // rcx
cocos2d::CCDirector *v45; // rax
float v46; // xmm0_4
const cocos2d::CCPoint *v47; // rax
__int64 v48; // rdx
__int64 v49; // rcx
LoadingCircle *v50; // rax
cocos2d::CCRGBAProtocol *v51; // rcx
const struct cocos2d::CCPoint *v52; // rax
char *v53; // rax
__int64 v54; // rbx
__int64 v55; // rax
cocos2d::CCString *v56; // rax
const char *v57; // rax
void **v58; // rbx
GameLevelManager *v59; // rcx
cocos2d::CCArray *StoredOnlineLevels; // rax
_BOOL8 v61; // rdx
GameLevelManager *v62; // rcx
void *v63; // rcx
void *v64; // [rsp+48h] [rbp-89h] BYREF
__int128 *v65; // [rsp+50h] [rbp-81h]
float v66; // [rsp+58h] [rbp-79h]
__int128 v67; // [rsp+60h] [rbp-71h] BYREF
__int64 v68; // [rsp+70h] [rbp-61h]
__int64 v69; // [rsp+78h] [rbp-59h]
struct cocos2d::_ccTexParams v70; // [rsp+80h] [rbp-51h] BYREF
void *Block[2]; // [rsp+90h] [rbp-41h] BYREF
__int64 v72; // [rsp+A0h] [rbp-31h]
unsigned __int64 v73; // [rsp+A8h] [rbp-29h]
_QWORD Src[3]; // [rsp+B0h] [rbp-21h] BYREF
unsigned __int64 v75; // [rsp+C8h] [rbp-9h]
result = cocos2d::CCLayer::init(a1);
if ( result )
{
a1->m_gauntletType = a2;
LOBYTE(v5) = 1;
a1->setKeypadEnabled(a1, v5);
LOBYTE(v6) = 1;
a1->setKeyboardEnabled(a1, v6);
v8 = (cocos2d::CCDirector *)cocos2d::CCDirector::sharedDirector(v7);
cocos2d::CCDirector::getWinSize(v8);
v9 = sub_1401F5F20(a1->m_gauntletType);
v10 = (GameManager *)qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v64 = operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v64);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v10 = (GameManager *)qword_1406C2ED8;
}
v11 = 59;
if ( v9 < 59 )
v11 = v9;
v12 = 1;
if ( v11 > 1 )
v12 = v11;
GameManager::loadBackground(v10, v12);
v13 = cocos2d::CCString::createWithFormat("game_bg_%02d_001.png", v12);
CString = cocos2d::CCString::getCString(v13);
v15 = cocos2d::CCSprite::create(CString);
a1->m_backgroundSprite = v15;
v70.minFilter = 9729;
v70.magFilter = 9729;
v70.wrapS = 10497;
v70.wrapT = 10497;
v16 = v15->getTexture(&v15->cocos2d::CCTextureProtocol);
cocos2d::CCTexture2D::setTexParameters(v16, &v70);
v17 = -1;
v18 = ((float (__fastcall *)(GauntletLayer *, cocos2d::CCSprite *, __int64))a1->addChild_0)(
a1,
a1->m_backgroundSprite,
0xFFFFFFFFLL);
v19 = a1->m_backgroundSprite->__vftable;
cocos2d::CCPoint::CCPoint(v18, 0.0);
v19->setAnchorPoint(a1->m_backgroundSprite, v20);
cocos2d::CCApplication::sharedApplication(v22, v21);
v24 = (cocos2d::CCDirector *)cocos2d::CCDirector::sharedDirector(v23);
cocos2d::CCDirector::getScreenScaleFactorMax(v24);
((void (__fastcall *)(cocos2d::CCSprite *))a1->m_backgroundSprite->setScale_0)(a1->m_backgroundSprite);
memset(&v64, 76, 3);
v25 = ((float (__fastcall *)(cocos2d::CCRGBAProtocol *, void **))a1->m_backgroundSprite->setColor)(
&a1->m_backgroundSprite->cocos2d::CCRGBAProtocol,
&v64);
v26 = a1->m_backgroundSprite->__vftable;
cocos2d::CCPoint::CCPoint(v25, 0.0);
v26->setPosition_0(a1->m_backgroundSprite, v27);
GauntletNode::nameForType(Src, (unsigned int)a2);
sub_140041270(Src, " Gauntlet", 9u);
v28 = (const char *)Src;
if ( v75 > 0xF )
v28 = (const char *)Src[0];
v29 = cocos2d::CCLabelBMFont::create(v28, "goldFont.fnt");
v30 = ((float (__fastcall *)(GauntletLayer *, struct cocos2d::CCLabelBMFont *, __int64))a1->addChild_0)(a1, v29, 2);
v31 = v29->cocos2d::CCSpriteBatchNode::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
cocos2d::CCPoint::CCPoint(v30, v66 * 0.5);
v31->setPosition_0(v29, v32);
((void (__fastcall *)(struct cocos2d::CCLabelBMFont *))v29->setScale_0)(v29);
LOWORD(v64) = -1;
BYTE2(v64) = 0;
v29->setColor(&v29->cocos2d::CCRGBAProtocol, (const cocos2d::ccColor3B *)&v64);
v33 = (const char *)Src;
if ( v75 > 0xF )
v33 = (const char *)Src[0];
v34 = cocos2d::CCLabelBMFont::create(v33, "goldFont.fnt");
v35 = ((float (__fastcall *)(GauntletLayer *, struct cocos2d::CCLabelBMFont *, _QWORD))a1->addChild_0)(a1, v34, 0);
cocos2d::CCPoint::CCPoint(v35, 2.0);
v36 = (__int64)v29->getPosition_0(v29);
cocos2d::CCPoint::operator+(v36, &v64);
v34->setPosition_0(v34, (const cocos2d::CCPoint *)&v64);
((void (__fastcall *)(struct cocos2d::CCLabelBMFont *))v34->setScale_0)(v34);
v34->setColor(&v34->cocos2d::CCRGBAProtocol, &stru_140529A84);
LOBYTE(v37) = 100;
v34->setOpacity(&v34->cocos2d::CCRGBAProtocol, v37);
v38 = cocos2d::CCSprite::createWithSpriteFrameName("GJ_arrow_01_001.png");
v39 = CCMenuItemSpriteExtra::create(v38, nullptr, a1, (cocos2d::SEL_MenuHandler *)GauntletLayer::onBack);
HIDWORD(v39->m_pfnSelector.adj) = 1070386381;
v40 = cocos2d::CCMenu::create(v39, 0);
a1->addChild_0(a1, v40, 2);
v41 = v40->cocos2d::CCLayerRGBA::cocos2d::CCLayer::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable;
v43 = (cocos2d::CCDirector *)cocos2d::CCDirector::sharedDirector(v42);
cocos2d::CCDirector::getScreenTop(v43);
v45 = (cocos2d::CCDirector *)cocos2d::CCDirector::sharedDirector(v44);
v46 = cocos2d::CCDirector::getScreenLeft(v45) + 25.0;
cocos2d::CCPoint::CCPoint(v46, v46);
v41->setPosition_0(v40, v47);
if ( *(_BYTE *)(cocos2d::CCApplication::sharedApplication(v49, v48) + 197) )
GameToolbox::addBackButton(a1, v39);
v50 = LoadingCircle::create();
a1->m_loadingCircle = v50;
v50->m_parentLayer = a1;
a1->m_loadingCircle->m_fade = 0;
cocos2d::CCObject::retain(a1->m_loadingCircle);
LoadingCircle::show(a1->m_loadingCircle);
a1->m_loadingCircle->setVisible(a1->m_loadingCircle, 0);
memset(&v64, 100, 3);
v51 = &a1->m_loadingCircle->m_sprite->cocos2d::CCRGBAProtocol;
v51->setColor(v51, (const cocos2d::ccColor3B *)&v64);
v65 = &v67;
v67 = 0;
v68 = 0;
v69 = 15;
*(_QWORD *)&v67 = sub_14003AA10(0x30u);
v68 = 43;
v69 = 47;
strcpy((char *)v67, "Something went wrong\nplease try again later");
cocos2d::CCPoint::CCPoint(1.7031031e25, 0.5);
v53 = TextArea::create((__int64)&v67, &qword_14052A4D8, 1.0, 600.0, v52, 1101004800, 0);
a1->m_tryAgainText = (TextArea *)v53;
v54 = *(_QWORD *)v53;
cocos2d::CCPoint::CCPoint(20.0, v66 * 0.5);
(*(void (__fastcall **)(TextArea *, __int64))(v54 + 184))(a1->m_tryAgainText, v55);
((void (__fastcall *)(TextArea *))a1->m_tryAgainText->setScale_0)(a1->m_tryAgainText);
a1->addChild_0(a1, a1->m_tryAgainText, 10);
a1->m_tryAgainText->setVisible(a1->m_tryAgainText, 0);
if ( !qword_1406C2EC0 )
{
v65 = (__int128 *)operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280((__int64)v65);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
}
v56 = cocos2d::CCString::createWithFormat("gauntlet_%i", a1->m_gauntletType);
v57 = cocos2d::CCString::getCString(v56);
*(_OWORD *)Block = 0;
v72 = 0;
v73 = 0;
do
++v17;
while ( v57[v17] );
sub_14003A930(Block, v57, v17);
v58 = Block;
if ( v73 > 0xF )
v58 = (void **)Block[0];
v59 = (GameLevelManager *)qword_1406C2EC0;
if ( !qword_1406C2EC0 )
{
v65 = (__int128 *)operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280((__int64)v65);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
v59 = (GameLevelManager *)qword_1406C2EC0;
}
StoredOnlineLevels = GameLevelManager::getStoredOnlineLevels(v59, (const char *)v58);
if ( StoredOnlineLevels )
{
GauntletLayer::setupGauntlet(a1, StoredOnlineLevels);
}
else
{
LOBYTE(v61) = 1;
a1->m_loadingCircle->setVisible(a1->m_loadingCircle, v61);
v62 = (GameLevelManager *)qword_1406C2EC0;
if ( !qword_1406C2EC0 )
{
v65 = (__int128 *)operator new(0x3D0u);
qword_1406C2EC0 = sub_140141280((__int64)v65);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2EC0 + 72LL))(qword_1406C2EC0);
v62 = (GameLevelManager *)qword_1406C2EC0;
}
v62->m_levelManagerDelegate = &a1->LevelManagerDelegate;
GameLevelManager::getGauntletLevels(v62, a1->m_gauntletType);
}
if ( v73 > 0xF )
{
v63 = Block[0];
if ( v73 + 1 >= 0x1000 )
{
v63 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v63 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v63);
}
sub_14003A830((__int64)Src);
return 1;
}
return result;
}