//
// SecretLayer2::onDoor from 0x1403e4910 to 0x1403e5264 (2388 bytes)
//
// 2 xrefs:
// > SecretLayer2::init @ 0x1403e31e3
// > ??> @ 0x1406d7f64
//
// 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=4
void SecretLayer2::onDoor(SecretLayer2 *a1, cocos2d::CCObject *a2)
{
GameManager *v3; // rcx
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9
struct cocos2d::CCScene *v7; // rdi
__int64 v8; // rcx
SecretLayer3 *v9; // rbx
struct cocos2d::CCTransitionFade *v10; // rbx
__int64 v11; // rcx
cocos2d::CCDirector *v12; // rax
unsigned __int64 v13; // rsi
int m_doorDialogIndex; // eax
int v15; // eax
int v16; // eax
int v17; // eax
int *p_m_doorDialogIndex; // rdx
__int64 v19; // rcx
__int64 v20; // rdi
char *v21; // rax
char *v22; // rax
char *v23; // rax
char *v24; // rax
char *v25; // rax
char *v26; // rax
char *v27; // rax
char *v28; // rax
char *v29; // rax
char *v30; // rax
char *v31; // rax
void **v32; // rbx
char *v33; // rax
DialogLayer *DialogLayer; // rdi
__int64 v35; // rcx
cocos2d::CCDirector *v36; // rax
cocos2d::CCLayer_vtbl *v37; // rbx
const cocos2d::CCPoint *v38; // rax
void *v39; // rcx
__int16 v40; // [rsp+38h] [rbp-69h] BYREF
char v41; // [rsp+3Ah] [rbp-67h]
SecretLayer3 *v42; // [rsp+48h] [rbp-59h]
__int128 v43; // [rsp+50h] [rbp-51h] BYREF
unsigned __int64 v44; // [rsp+60h] [rbp-41h]
__int64 v45; // [rsp+68h] [rbp-39h]
_WORD v46[8]; // [rsp+70h] [rbp-31h] BYREF
__int64 v47; // [rsp+80h] [rbp-21h]
__int64 v48; // [rsp+88h] [rbp-19h]
void *Src[2]; // [rsp+98h] [rbp-9h] BYREF
unsigned __int64 v50; // [rsp+A8h] [rbp+7h]
__int64 v51; // [rsp+B0h] [rbp+Fh]
v3 = (GameManager *)qword_1406C2ED8;
if ( !qword_1406C2ED8 )
{
v42 = (SecretLayer3 *)operator new(0x668u);
qword_1406C2ED8 = sub_14017AB00((__int64)v42);
(*(void (__fastcall **)(__int64))(*(_QWORD *)qword_1406C2ED8 + 72LL))(qword_1406C2ED8);
v3 = (GameManager *)qword_1406C2ED8;
}
if ( GameManager::getUGV(v3, (const char *)&word_140531E94) )
{
v7 = (struct cocos2d::CCScene *)cocos2d::CCScene::create(v4);
*(_QWORD *)(cocos2d::CCApplication::sharedApplication(v8) + 224) = v7;
v9 = (SecretLayer3 *)operator new(0x1D0u);
v42 = v9;
cocos2d::CCLayer::CCLayer(v9);
v9->cocos2d::CCLayer::cocos2d::CCNode::cocos2d::CCObject::cocos2d::CCCopying::__vftable = (SecretLayer3_vtbl *)&SecretLayer3::`vftable';
v9->cocos2d::CCLayer::cocos2d::CCTouchDelegate::__vftable = (cocos2d::CCTouchDelegate_vtbl *)&SecretLayer3::`vftable';
v9->cocos2d::CCLayer::cocos2d::CCAccelerometerDelegate::__vftable = (cocos2d::CCAccelerometerDelegate_vtbl *)&SecretLayer3::`vftable';
v9->cocos2d::CCLayer::cocos2d::CCKeypadDelegate::__vftable = (cocos2d::CCKeypadDelegate_vtbl *)&SecretLayer3::`vftable';
v9->cocos2d::CCLayer::cocos2d::CCKeyboardDelegate::__vftable = (cocos2d::CCKeyboardDelegate_vtbl *)&SecretLayer3::`vftable';
v9->cocos2d::CCLayer::cocos2d::CCMouseDelegate::__vftable = (cocos2d::CCMouseDelegate_vtbl *)&SecretLayer3::`vftable';
v9->DialogDelegate::__vftable = (DialogDelegate_vtbl *)&SecretLayer3::`vftable';
v9->m_lockInput = 0;
v9->m_locksArray = nullptr;
v9->m_demonEyes = nullptr;
v9->m_demonBody = nullptr;
v9->m_secretChest = nullptr;
if ( SecretLayer3::init(v9) )
{
cocos2d::CCObject::autorelease(v9);
}
else
{
((void (__fastcall *)(SecretLayer3 *, __int64))v9->~SecretLayer3)(v9, 1);
v9 = nullptr;
}
v7->addChild_1(v7, v9);
v10 = cocos2d::CCTransitionFade::create(0.5, v7);
v12 = (cocos2d::CCDirector *)cocos2d::CCDirector::sharedDirector(v11);
cocos2d::CCDirector::replaceScene(v12, v10);
}
else
{
v50 = 11;
v13 = 15;
v51 = 15;
Src[0] = (void *)0x6F6C6C6120746F4ELL;
Src[1] = (void *)6579575;
m_doorDialogIndex = a1->m_doorDialogIndex;
if ( m_doorDialogIndex >= 0 )
{
v16 = m_doorDialogIndex + 1;
}
else if ( (float)((float)((float)rand() / 32767.0) * 10.0) < 0.0 )
{
v17 = rand();
v16 = (int)ceilf((float)((float)((float)v17 / 32767.0) * 10.0) - 0.5);
}
else
{
v15 = rand();
v16 = (int)floorf((float)((float)((float)v15 / 32767.0) * 10.0) + 0.5);
}
p_m_doorDialogIndex = &a1->m_doorDialogIndex;
v19 = (unsigned int)v16;
a1->m_doorDialogIndex = v16;
v20 = 0x7FFFFFFFFFFFFFFFLL;
if ( v16 <= 10 )
{
if ( (unsigned int)v16 <= 0xA )
{
switch ( v16 )
{
case 0:
goto LABEL_17;
case 1:
v13 = 47;
v22 = (char *)sub_14003AA10(0x30u);
v50 = 34;
strcpy(v22, "Its too dangerous, just stay here.");
v19 = 11877;
Src[0] = v22;
goto LABEL_28;
case 2:
v13 = 31;
v23 = (char *)sub_14003AA10(0x20u);
v50 = 19;
strcpy(v23, "Leave that alone...");
v19 = 46;
Src[0] = v23;
goto LABEL_28;
case 3:
v13 = 31;
v24 = (char *)sub_14003AA10(0x20u);
v50 = 24;
strcpy(v24, "That area is off limits.");
Src[0] = v24;
goto LABEL_28;
case 4:
v25 = (char *)sub_14003AA10(0x30u);
v50 = 47;
v13 = 47;
v51 = 47;
strcpy(v25, "I keep that door locked.\nRubRub's orders.");
Src[0] = v25;
break;
case 5:
v13 = 63;
v26 = (char *)sub_14003AA10(0x40u);
v50 = 56;
strcpy(v26, "I've only been down there once. Its pretty creepy.");
Src[0] = v26;
goto LABEL_28;
case 6:
v13 = 31;
v27 = (char *)sub_14003AA10(0x20u);
v50 = 21;
strcpy(v27, "Just forget about it.");
v19 = 46;
Src[0] = v27;
goto LABEL_28;
case 7:
v13 = 47;
v28 = (char *)sub_14003AA10(0x30u);
v50 = 32;
strcpy(v28, "Some things are best left alone.");
Src[0] = v28;
goto LABEL_28;
case 8:
v13 = 47;
v29 = (char *)sub_14003AA10(0x30u);
v50 = 34;
strcpy(v29, "Even I dont want to go down there.");
v19 = 11877;
Src[0] = v29;
goto LABEL_28;
case 9:
v13 = 31;
v30 = (char *)sub_14003AA10(0x20u);
v50 = 19;
strcpy(v30, "Off. Limits.");
v19 = 46;
Src[0] = v30;
goto LABEL_28;
case 10:
v13 = 47;
v31 = (char *)sub_14003AA10(0x30u);
v50 = 41;
strcpy(v31, "Does the word locked mean nothing to you?");
Src[0] = v31;
goto LABEL_28;
}
}
}
else
{
a1->m_doorDialogIndex = 0;
LABEL_17:
v13 = 47;
v21 = (char *)sub_14003AA10(0x30u);
v50 = 32;
strcpy(v21, "Sorry, I can't let you in.");
Src[0] = v21;
LABEL_28:
v51 = v13;
}
v42 = (SecretLayer3 *)&v43;
v40 = -1;
v41 = -1;
v43 = 0;
v44 = 0;
v45 = 0;
v32 = Src;
if ( v13 > 0xF )
v32 = (void **)Src[0];
if ( v50 > 0x7FFFFFFFFFFFFFFFLL )
sub_140007B50(v19, p_m_doorDialogIndex, v5, v6);
v45 = 15;
if ( v50 > 0xF )
{
if ( (v50 | 0xF) <= 0x7FFFFFFFFFFFFFFFLL )
{
v20 = v50 | 0xF;
if ( (v50 | 0xF) < 0x16 )
v20 = 22;
}
*(_QWORD *)&v43 = sub_14003AA10(v20 + 1);
v44 = v50;
v45 = v20;
memcpy((void *)v43, v32, v50 + 1);
}
else
{
v44 = v50;
v43 = *(_OWORD *)v32;
}
v46[7] = 0;
v47 = 13;
v48 = 15;
strcpy((char *)v46, "The Keymaster");
v33 = DialogObject::create((__int64)v46, (__int64)&v43, 2, 1.0, 0, (__int64)&v40);
DialogLayer = DialogLayer::createDialogLayer((DialogObject *)v33, nullptr, 2);
a1->addChild_0(a1, DialogLayer, 100);
v36 = (cocos2d::CCDirector *)cocos2d::CCDirector::sharedDirector(v35);
cocos2d::CCDirector::getWinSize(v36);
v37 = DialogLayer->m_mainLayer->__vftable;
cocos2d::CCPoint::CCPoint(1.9431574e-19, *(float *)&v42 * 0.5);
v37->setPosition_0(DialogLayer->m_mainLayer, v38);
DialogLayer::animateInRandomSide(DialogLayer);
if ( v13 > 0xF )
{
v39 = Src[0];
if ( v13 + 1 >= 0x1000 )
{
v39 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v39 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free(v39);
}
}
}